Ejemplo n.º 1
0
 $file_base_name = str_replace('.' . $extension, '', $filename);
 $new_dir = api_replace_dangerous_char(trim($file_base_name));
 $type = learnpath::get_package_type($_FILES['user_file']['tmp_name'], $_FILES['user_file']['name']);
 $proximity = 'local';
 if (!empty($_REQUEST['content_proximity'])) {
     $proximity = Database::escape_string($_REQUEST['content_proximity']);
 }
 $maker = 'Scorm';
 if (!empty($_REQUEST['content_maker'])) {
     $maker = Database::escape_string($_REQUEST['content_maker']);
 }
 switch ($type) {
     case 'scorm':
         require_once 'scorm.class.php';
         $oScorm = new scorm();
         $manifest = $oScorm->import_package($_FILES['user_file'], $current_dir);
         if (!$manifest) {
             throw new \Exception('error import package');
         }
         if (!empty($manifest)) {
             $oScorm->parse_manifest($manifest);
             $fixTemplate = api_get_configuration_value('learnpath_fix_xerte_template');
             $proxyPath = api_get_configuration_value('learnpath_proxy_url');
             if ($fixTemplate && !empty($proxyPath)) {
                 // Check organisations:
                 if (isset($oScorm->manifest['organizations'])) {
                     foreach ($oScorm->manifest['organizations'] as $data) {
                         if (strpos(strtolower($data), 'xerte') !== false) {
                             // Check if template.xml exists:
                             $templatePath = str_replace('imsmanifest.xml', 'template.xml', $manifest);
                             if (file_exists($templatePath) && is_file($templatePath)) {
Ejemplo n.º 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';
    }
}