示例#1
0
 if (has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE, $cm->id))) {
     foreach ($_POST as $element => $value) {
         $element = str_replace('__', '.', $element);
         if (substr($element, 0, 3) == 'cmi') {
             $netelement = preg_replace('/\\.N(\\d+)\\./', "\\.\$1\\.", $element);
             $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $netelement, $value) && $result;
         }
         if (substr($element, 0, 15) == 'adl.nav.request') {
             // SCORM 2004 Sequencing Request
             require_once 'datamodels/sequencinglib.php';
             $search = array('@continue@', '@previous@', '@\\{target=(\\S+)\\}choice@', '@exit@', '@exitAll@', '@abandon@', '@abandonAll@');
             $replace = array('continue_', 'previous_', '\\1', 'exit_', 'exitall_', 'abandon_', 'abandonall');
             $action = preg_replace($search, $replace, $value);
             if ($action != $value) {
                 // Evaluating navigation request
                 $valid = scorm_seq_overall($scoid, $USER->id, $action, $attempt);
                 $valid = 'true';
                 // Set valid request
                 $search = array('@continue@', '@previous@', '@\\{target=(\\S+)\\}choice@');
                 $replace = array('true', 'true', 'true');
                 $matched = preg_replace($search, $replace, $value);
                 if ($matched == 'true') {
                     $request = 'adl.nav.request_valid["' . $action . '"] = "' . $valid . '";';
                 }
             }
         }
     }
 }
 if ($result) {
     echo "true\n0";
 } else {
示例#2
0
function JLMS_DatamodelSCORM($option)
{
    global $JLMS_DB, $Itemid, $JLMS_CONFIG;
    $user = JLMSFactory::getUser();
    $user_id = $user->get('id');
    if (!$user_id) {
        $ssid = strval(mosGetParam($_REQUEST, 'ssid', ''));
        if ($ssid) {
            $ssid_parts = explode('_', $ssid);
            if (count($ssid_parts) == 2) {
                $pre_userid = isset($ssid_parts[0]) ? $ssid_parts[0] : 0;
                $pre_hash = isset($ssid_parts[1]) ? $ssid_parts[1] : 'xxxxx';
                $user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
                $hash_check = md5($pre_userid . '_' . $user_agent);
                if ($hash_check == $pre_hash) {
                    $user_id = $pre_userid;
                }
            }
        }
    }
    if (!$user_id) {
        $log_scorm_id = intval(mosGetParam($_REQUEST, 'id', 0)) ? intval(mosGetParam($_REQUEST, 'id', 0)) : intval(mosGetParam($_REQUEST, 'scorm_id', 0));
        $log_course_id = $JLMS_CONFIG->get('course_id') ? $JLMS_CONFIG->get('course_id') : intval(mosGetParam($_REQUEST, 'course_id', 0));
        JLMSErrorLog::writeSCORMLog('SCORM tracking error - user not logged in (session hash check failed)', $log_course_id, $log_scorm_id);
        exit;
    }
    $id = intval(mosGetParam($_REQUEST, 'id', 0));
    $skip_resume = intval(mosGetParam($_REQUEST, 'skip_resume', 0));
    if ($id) {
        $query = "SELECT * FROM #__lms_n_scorm WHERE id = {$id}";
        $JLMS_DB->SetQuery($query);
        $scorm = $JLMS_DB->LoadObject();
        if (is_object($scorm)) {
            $scoid = intval(mosGetParam($_REQUEST, 'scoid', 0));
            $attempt = intval(mosGetParam($_REQUEST, 'attempt', 0));
            if ($scoid) {
                $result = true;
                $request = null;
                // (DEN)
                //if (has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE,$cm->id))) {
                if (true) {
                    foreach ($_POST as $element => $val_post) {
                        $element = str_replace('__', '.', $element);
                        // (DEN) (i'm insert 'get_magic_quotes_gpc'). 15.03.2007
                        $value = get_magic_quotes_gpc() ? stripslashes($val_post) : $val_post;
                        if (substr($element, 0, 3) == 'cmi') {
                            $element = preg_replace('/N(\\d+)/', ".\$1", $element);
                            $result = scorm_insert_track($user_id, $scorm->id, $scoid, $attempt, $element, $value) && $result;
                        }
                        if (substr($element, 0, 15) == 'adl.nav.request') {
                            // SCORM 2004 Sequencing Request
                            require_once _JOOMLMS_FRONT_HOME . '/includes/n_scorm/datamodels/scorm_13lib.php';
                            $search = array('@continue@', '@previous@', '@\\{target=(\\S+)\\}choice@', '@exit@', '@exitAll@', '@abandon@', '@abandonAll@');
                            $replace = array('continue_', 'previous_', '\\1', 'exit_', 'exitall_', 'abandon_', 'abandonall');
                            $action = preg_replace($search, $replace, $value);
                            if ($action != $value) {
                                require_once _JOOMLMS_FRONT_HOME . '/includes/n_scorm/datamodels/sequencinglib.php';
                                // Evaluating navigation request
                                $valid = scorm_seq_overall($scoid, $user_id, $action);
                                // Set valid request
                                $search = array('@continue@', '@previous@', '@\\{target=(\\S+)\\}choice@');
                                $replace = array('true', 'true', 'true');
                                $matched = preg_replace($search, $replace, $value);
                                if ($matched == 'true') {
                                    $request = 'adl.nav.request_valid["' . $action . '"] = "' . $valid . '";';
                                }
                            }
                        }
                    }
                    /* 23 November 2007 (DEN) LMS resuming fix (for 'by the best attemp' tracking method */
                    global $JLMS_CONFIG;
                    $course_params = $JLMS_CONFIG->get('course_params');
                    $params = new JLMSParameters($course_params);
                    if ($params->get('track_type', 0) == 1 && !$skip_resume) {
                        //by the best attempt + skip_resume (24march2010)
                        if ($attempt > 1) {
                            $query = "SELECT * FROM #__lms_n_scorm_scoes_track WHERE userid = '{$user_id}' AND scormid = '{$scorm->id}' AND scoid = '{$scoid}' AND attempt = '" . ($attempt - 1) . "'";
                            $JLMS_DB->SetQuery($query);
                            $prev_tracks = $JLMS_DB->LoadObjectList();
                            foreach ($prev_tracks as $prev_track) {
                                $query = "SELECT count(*) FROM #__lms_n_scorm_scoes_track WHERE userid = '{$user_id}' AND scormid = '{$scorm->id}' AND scoid = '{$scoid}' AND attempt = '{$attempt}' AND element = '{$prev_track->element}'";
                                $JLMS_DB->SetQuery($query);
                                $ssss = $JLMS_DB->LoadResult();
                                if (!$ssss) {
                                    $track = new stdClass();
                                    $track->userid = $user_id;
                                    $track->scormid = $scorm->id;
                                    $track->scoid = $scoid;
                                    $track->attempt = $attempt;
                                    $track->element = $prev_track->element;
                                    $track->value = $prev_track->value;
                                    $track->timemodified = $prev_track->timemodified;
                                    $JLMS_DB->InsertObject('#__lms_n_scorm_scoes_track', $track, 'id');
                                }
                            }
                        }
                        //TODO: do not resume SCORM if it is played as LPath step and LPath was restarted !!!
                    }
                    /* End of LMS resuming fix */
                }
                if ($result) {
                    echo "true\n0";
                } else {
                    echo "false\n101";
                }
                if ($request != null) {
                    echo "\n" . $request;
                }
            }
        }
    }
    exit;
}
示例#3
0
 if (has_capability('mod/scorm:savetrack', get_context_instance(CONTEXT_MODULE, $cm->id))) {
     foreach (data_submitted() as $element => $value) {
         $element = str_replace('__', '.', $element);
         if (substr($element, 0, 3) == 'cmi') {
             $netelement = preg_replace('/\\.N(\\d+)\\./', "\\.\$1\\.", $element);
             $result = scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, $netelement, $value) && $result;
         }
         if (substr($element, 0, 15) == 'adl.nav.request') {
             // SCORM 2004 Sequencing Request
             require_once 'datamodels/sequencinglib.php';
             $search = array('@continue@', '@previous@', '@\\{target=(\\S+)\\}choice@', '@exit@', '@exitAll@', '@abandon@', '@abandonAll@');
             $replace = array('continue_', 'previous_', '\\1', 'exit_', 'exitall_', 'abandon_', 'abandonall');
             $action = preg_replace($search, $replace, $value);
             if ($action != $value) {
                 // Evaluating navigation request
                 $valid = scorm_seq_overall($scoid, $USER->id, $action);
                 $valid = 'true';
                 // Set valid request
                 $search = array('@continue@', '@previous@', '@\\{target=(\\S+)\\}choice@');
                 $replace = array('true', 'true', 'true');
                 $matched = preg_replace($search, $replace, $value);
                 if ($matched == 'true') {
                     $request = 'adl.nav.request_valid["' . $action . '"] = "' . $valid . '";';
                 }
             }
         }
         //                // Log every datamodel update requested
         //                if (substr($element,0,15) == 'adl.nav.request' || substr($element,0,3) == 'cmi') {
         //                    if (debugging('',DEBUG_DEVELOPER)) {
         //                        add_to_log($course->id, 'scorm', 'trk: '.trim($scorm->name).' at: '.$attempt, 'view.php?id='.$cm->id, "$element => $value", $cm->id);
         //                    }