Exemple #1
0
 $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']);
         }
         $oScorm->set_proximity($proximity);
         $oScorm->set_maker($maker);
         $oScorm->set_jslib('scorm_api.php');
         break;
     case 'aicc':
         require_once 'aicc.class.php';
Exemple #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';
    }
}
    $courses_dir = $upd_course_path.$courses_dir_list[$my_course_code];
    $sco_path_temp = ($my_path == '/') ? '' : $my_path;
    $sco_middle_path = (empty($sco_path_temp) ? '' : (substr($sco_path_temp, 0, 1) == '/') ? substr($sco_path_temp, 1).'/' : $sco_path_temp.'/'); //same thing as sco_path_temp but with reversed slashes
    $ims = $courses_dir.'/scorm'.$sco_path_temp.'/imsmanifest.xml';

    if (is_file($ims)){
        //echo "Path $ims exists, importing...(line ".__LINE__.")<br />";
        $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 ($loglevel > 1) { Log::notice("Found imsmanifest ($ims), importing..."); }
        if (!empty($sco_middle_path)) { $oScorm->subdir = $sco_middle_path; } //this sets the subdir for the scorm package inside the scorm dir
        // Parse manifest file
        $manifest = $oScorm->parse_manifest($ims);
        // The title is already escaped in the method
        $oScorm->import_manifest($my_course_code);
        //TODO: Add code to update the path in that new lp created, as it probably uses / where
        // $sco_path_temp should be used...
        $lp_ids[$my_content_id] = $oScorm->lp_id; // Contains the old LP ID => the new LP ID
        if ($loglevel > 1) { Log::notice(" @@@ Created scorm lp ".$oScorm->lp_id." from imsmanifest [".$ims."] in course $my_course_code"); }
        $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++;

        /*
         * QUERY SCORM ITEMS FROM SCORM_SCO_DATA
         * The danger here is that we might have several users for the same data, and so
         * we have to avoid entering the same elements twice
         */
        $sql_items = "SELECT * FROM $scorm_item WHERE contentId = '".$my_content_id."' ORDER BY scoId";
        //echo "$sql_items<br />\n";
Exemple #4
0
 //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 = '';
         if (!empty($_REQUEST['content_maker'])) {
             $maker = $mysql->escape_string($_REQUEST['content_maker']);
         }
         $oScorm->set_proximity($proximity);
         $oScorm->set_maker($maker);