Example #1
0
 $s = api_get_path(SYS_ARCHIVE_PATH) . basename($_POST['file_name']);
 // Get name of the zip file without the extension
 $info = pathinfo($s);
 $filename = $info['basename'];
 $extension = $info['extension'];
 $file_base_name = str_replace('.' . $extension, '', $filename);
 $new_dir = api_replace_dangerous_char(trim($file_base_name));
 $result = learnpath::verify_document_size($s);
 if ($result == true) {
     throw new \Exception(get_lang('UplFileTooBig'));
 }
 $type = learnpath::get_package_type($s, basename($s));
 switch ($type) {
     case 'scorm':
         require_once 'scorm.class.php';
         $oScorm = new scorm();
         $manifest = $oScorm->import_local_package($s, $current_dir);
         if ($manifest === false) {
             throw new \Exception('Error import local package');
         }
         if (!empty($manifest)) {
             $oScorm->parse_manifest($manifest);
             $oScorm->import_manifest(api_get_course_id(), $_REQUEST['use_max_score']);
         }
         $proximity = '';
         if (!empty($_REQUEST['content_proximity'])) {
             $proximity = Database::escape_string($_REQUEST['content_proximity']);
         }
         $maker = '';
         if (!empty($_REQUEST['content_maker'])) {
             $maker = Database::escape_string($_REQUEST['content_maker']);
Example #2
0
/**
 * @param array $params
 * @return int|string
 */
function WSImportLP($params)
{
    global $debug;
    if (!WSHelperVerifyKey($params)) {
        return return_error(WS_ERROR_SECRET_KEY);
    }
    if ($debug) {
        error_log('WSImportLP');
    }
    $courseIdName = $params['course_id_name'];
    $courseIdValue = $params['course_id_value'];
    $sessionIdName = isset($params['session_id_name']) ? $params['session_id_name'] : null;
    $sessionIdValue = isset($params['session_id_value']) ? $params['session_id_value'] : null;
    $lpName = $params['lp_name'];
    $courseInfo = CourseManager::getCourseInfoFromOriginalId($courseIdValue, $courseIdName);
    $courseId = $courseInfo['real_id'];
    if (empty($courseInfo)) {
        if ($debug) {
            error_log('Course not found');
        }
        return 'Course not found';
    }
    $sessionId = 0;
    if (!empty($sessionIdName) && !empty($sessionIdValue)) {
        $sessionId = SessionManager::get_session_id_from_original_id($sessionIdValue, $sessionIdName);
        if (empty($sessionId)) {
            if ($debug) {
                error_log('Session not found');
            }
            return 'Session not found';
        }
    }
    $proximity = 'local';
    $maker = 'Scorm';
    $maxScore = '';
    //$_REQUEST['use_max_score']
    $oScorm = new scorm($courseInfo['code']);
    $fileData = base64_decode($params['file_data']);
    $uniqueFile = uniqid();
    $userId = 1;
    // admin
    $filePath = api_get_path(SYS_ARCHIVE_PATH) . $uniqueFile;
    file_put_contents($filePath, $fileData);
    $fileName = $params['filename'];
    $fileInfo = array('tmp_name' => $filePath, 'name' => $fileName);
    $manifest = $oScorm->import_package($fileInfo, '', $courseInfo);
    if (!$manifest) {
        if ($debug) {
            error_log('manifest.xml file not found');
        }
        //if api_set_failure
        return 'manifest.xml file not found';
    }
    $manifestData = $oScorm->parse_manifest($manifest);
    if (!empty($manifestData)) {
        $oScorm->import_manifest($courseInfo['code'], $maxScore, $sessionId, $userId);
        $oScorm->set_name($lpName);
        $oScorm->set_proximity($proximity, $courseId);
        $oScorm->set_maker($maker, $courseId);
        //$oScorm->set_jslib('scorm_api.php');
        if ($debug) {
            error_log('scorm was added');
        }
        return 1;
    } else {
        if ($debug) {
            error_log('manifest data empty');
        }
        return 'manifest data empty';
    }
}
        if (!$in_id) die('Could not insert scorm lp: '.$sql_ins);
        //echo "&nbsp;&nbsp;Inserted item $in_id<br />\n";
        $lp_ids[$my_content_id] = $in_id; //contains the old LP ID => the new LP ID
        $lp_course[$my_content_id] = $courses_id_list[$my_course_code]; // Contains the old learnpath ID => the course DB name
        $lp_course_code[$my_content_id] = $my_course_code;
        $max_dsp_lp++;

        // Setup the ims path (path to the imsmanifest.xml file)
        //echo "Looking for course with code ".$lp_course_code[$my_content_id]." (using $my_content_id)<br />\n";
        $courses_dir = $sys_course_path.$courses_dir_list[$lp_course_code[$my_content_id]];
        //$scorm_lp_paths[$my_content_id]['path'] = str_replace(' ', '\\ ', $scorm_lp_paths[$my_content_id]['path']);
        $sco_path_temp = ($scorm_lp_paths[$my_content_id]['path'] == '/') ? '' : $scorm_lp_paths[$my_content_id]['path'];
        $scorm_lp_paths[$my_content_id]['ims'] = $courses_dir.'/scorm'.$sco_path_temp.'/imsmanifest.xml';

        // Generate an imsmanifest object to get more info about the learnpath from the file
        $oScorm = new scorm();
        // Check whether imsmanifest.xml exists at this location. If not, ignore the imsmanifest.
        // That should have been done before already, now.
        if (!is_file($scorm_lp_paths[$my_content_id]['ims'])) {
            if ($loglevel > 1) { Log::notice("!!! imsmanifest file not found at ".$scorm_lp_paths[$my_content_id]['ims'].' for old lp '.$my_content_id.' and new '.$lp_ids[$my_content_id]); }
            $manifest = false;
        } else {
            //echo "Parsing ".$scorm_lp_paths[$my_content_id]['ims']."<br />\n";
            // Parse manifest file
            $manifest = $oScorm->parse_manifest($scorm_lp_paths[$my_content_id]['ims']);
            // The title is already escaped in the method
            //$my_lp_title = api_convert_encoding($oScorm->get_title(),'ISO-8859-1',$oScorm->manifest_encoding);
            $my_lp_title = api_convert_encoding($oScorm->get_title(), 'ISO-8859-1', 'UTF-8');  // TODO: This "magic" conversion to be checked.
            if (!empty($my_lp_title)) {
                $my_new_lp = $db_name.$new_lp;
                $my_sql = "UPDATE $my_new_lp " .
Example #4
0
 $filename = date("YmdHis-") . rand(1000, 9999) . "." . $extension;
 $file_base_name = str_replace('.' . $extension, '', $filename);
 //$file_base_name = replace_dangerous_char(trim($file_base_name),'strict');
 //move_uploaded_file($srcfile,$course_dir.iconv("GBK","UTF-8",$s));
 move_uploaded_file($srcfile, $course_dir . $filename);
 //die("insert into attachment(title,size,type,path,time,unzip) values ('$title','$size','$extension','".$course_dir.$filename."','$time','1')");
 $mysql->query("insert into attachment(title,size,type,path,time,unzip) values ('{$title}','{$size}','{$extension}','" . $course_dir . $filename . "','{$time}','1')");
 $attachmentId = $mysql->insert_id();
 $unzip = new unzip();
 $unzip->extract_zip($course_dir . $filename, $course_dir . $file_base_name . "/");
 $type = learnpath::get_package_type($course_dir . $filename, $filename);
 switch ($type) {
     case 'scorm':
         require_once 'scorm.class.php';
         //require_once api_get_path(LIBRARY_PATH).'searchengine.lib.php';
         $oScorm = new scorm();
         //$manifest = $oScorm->import_package($_FILES['file'],$current_dir);
         $manifest = $course_dir . $file_base_name . "/imsmanifest.xml";
         if (!empty($manifest)) {
             $oScorm->parse_manifest($manifest);
             $oScorm->import_manifest($parentDir);
         } else {
             //show error message stored in $oScrom->error_msg
             //logger("error: lp_upload->switch(scorm)->empty(manifest)");
             die("不是符合标准的scorm课程包。");
         }
         $proximity = '';
         if (!empty($_REQUEST['content_proximity'])) {
             $proximity = $mysql->escape_string($_REQUEST['content_proximity']);
         }
         $maker = '';