/**
 * Writes an item's new values into the database and returns the operation result
 * @param   integer Learnpath ID
 * @param   integer User ID
 * @param   integer View ID
 * @param   integer Item ID
 * @param   array   Objectives array
 */
function save_objectives($lp_id, $user_id, $view_id, $item_id, $objectives = array())
{
    $debug = 0;
    $return = '';
    if ($debug > 0) {
        error_log('In xajax_save_objectives(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $item_id . ',"' . (count($objectives) > 0 ? count($objectives) : '') . '")', 0);
    }
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    $mylpi =& $mylp->items[$item_id];
    if (is_array($objectives) && count($objectives) > 0) {
        foreach ($objectives as $index => $objective) {
            $mylpi->add_objective($index, $objectives[$index]);
        }
        $mylpi->write_objectives_to_db();
    }
    return $return;
}
/**
 * Get one item's details
 * @param   integer LP ID
 * @param   integer user ID
 * @param   integer View ID
 * @param   integer Current item ID
 * @param   integer New item ID
 */
function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_item)
{
    $debug = 0;
    $return = '';
    if ($debug > 0) {
        error_log('In xajax_switch_item_details(' . $lp_id . ',' . $user_id . ',' . $view_id . ',' . $current_item . ',' . $next_item . ')', 0);
    }
    //$objResponse = new xajaxResponse();
    /*$item_id may be one of:
     * -'next'
     * -'previous'
     * -'first'
     * -'last'
     * - a real item ID
     */
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    $new_item_id = 0;
    switch ($next_item) {
        case 'next':
            $mylp->set_current_item($current_item);
            $mylp->next();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {next} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'previous':
            $mylp->set_current_item($current_item);
            $mylp->previous();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {previous} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'first':
            $mylp->set_current_item($current_item);
            $mylp->first();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) {
                error_log('In {first} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked.
            if ($next_item == $current_item) {
                // If we're opening the same item again.
                $mylp->items[$current_item]->restart();
            }
            $new_item_id = $next_item;
            $mylp->set_current_item($new_item_id);
            if ($debug > 1) {
                error_log('In {default} - next item is ' . $new_item_id . '(current: ' . $current_item . ')', 0);
            }
            break;
    }
    $mylp->start_current_item(true);
    if ($mylp->force_commit) {
        $mylp->save_current();
    }
    if (is_object($mylp->items[$new_item_id])) {
        $mylpi = $mylp->items[$new_item_id];
    } else {
        if ($debug > 1) {
            error_log('In switch_item_details - generating new item object', 0);
        }
        $mylpi = new learnpathItem($new_item_id, $user_id);
        $mylpi->set_lp_view($view_id);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    if ($mymax === '') {
        $mymax = "''";
    }
    $mymin = $mylpi->get_min();
    $mylesson_status = $mylpi->get_status();
    $mylesson_location = $mylpi->get_lesson_location();
    $mytotal_time = $mylpi->get_scorm_time('js');
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    /*
    if ($mylpi->get_type() == 'asset') {
        // Temporary measure to save completion of an asset. Later on, Chamilo should trigger something on unload, maybe... (even though that would mean the last item cannot be completed)
        $mylesson_status = 'completed';
        $mylpi->set_status('completed');
        $mylpi->save();
    }
    */
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $myic = $mylpi->get_interactions_count();
    $myistring = '';
    for ($i = 0; $i < $myic; $i++) {
        $myistring .= ",[" . $i . ",'','','','','','','']";
    }
    if (!empty($myistring)) {
        $myistring = substr($myistring, 1);
    }
    /*
     * The following lines should reinitialize the values for the SCO
     * However, due to many complications, we are now relying more on the
     * LMSInitialize() call and its underlying lp_ajax_initialize.php call
     * so this code is technically deprecated (but the change of item_id should
     * remain). However, due to numerous technical issues with SCORM, we prefer
     * leaving it as a double-lock security. If removing, please test carefully
     * with both SCORM and proper learning path tracking.
     */
    $return .= "olms.score=" . $myscore . ";" . "olms.max=" . $mymax . ";" . "olms.min=" . $mymin . ";" . "olms.lesson_status='" . $mylesson_status . "';" . "olms.lesson_location='" . $mylesson_location . "';" . "olms.session_time='" . $mysession_time . "';" . "olms.suspend_data='" . $mysuspend_data . "';" . "olms.total_time = '" . $mytotal_time . "';" . "olms.mastery_score = '" . $mymastery_score . "';" . "olms.max_time_allowed = '" . $mymax_time_allowed . "';" . "olms.launch_data = '" . $mylaunch_data . "';" . "olms.interactions = new Array(" . $myistring . ");" . "olms.item_objectives = new Array();" . "olms.G_lastError = 0;" . "olms.G_LastErrorMessage = 'No error';" . "olms.finishSignalReceived = 0;";
    /*
     * and re-initialise the rest
     * -lms_lp_id
     * -lms_item_id
     * -lms_old_item_id
     * -lms_new_item_id
     * -lms_initialized
     * -lms_progress_bar_mode
     * -lms_view_id
     * -lms_user_id
     */
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = $myprogress_mode == '' ? '%' : $myprogress_mode;
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();
    $return .= "olms.lms_lp_id=" . $lp_id . ";" . "olms.lms_item_id=" . $new_item_id . ";" . "olms.lms_old_item_id=0;" . "olms.lms_initialized=0;" . "olms.lms_view_id=" . $view_id . ";" . "olms.lms_user_id=" . $user_id . ";" . "olms.next_item=" . $new_item_id . ";" . "olms.lms_next_item=" . $mynext . ";" . "olms.lms_previous_item=" . $myprevious . ";" . "olms.lms_item_type = '" . $myitemtype . "';" . "olms.lms_item_credit = '" . $mycredit . "';" . "olms.lms_item_lesson_mode = '" . $mylesson_mode . "';" . "olms.lms_item_launch_data = '" . $mylaunch_data . "';" . "olms.lms_item_interactions_count = '" . $myinteractions_count . "';" . "olms.lms_item_objectives_count = '" . $myinteractions_count . "';" . "olms.lms_item_core_exit = '" . $mycore_exit . "';" . "olms.asset_timer = 0;";
    $return .= "update_toc('unhighlight','" . $current_item . "');" . "update_toc('highlight','" . $new_item_id . "');" . "update_toc('{$mylesson_status}','" . $new_item_id . "');" . "update_progress_bar('{$mycomplete}','{$mytotal}','{$myprogress_mode}');";
    $return .= 'updateGamificationValues(); ';
    $mylp->set_error_msg('');
    $mylp->prerequisites_match();
    // Check the prerequisites are all complete.
    if ($debug > 1) {
        error_log('Prereq_match() returned ' . htmlentities($mylp->error), 0);
    }
    // Save the new item ID for the exercise tool to use.
    Session::write('scorm_item_id', $new_item_id);
    Session::write('lpobject', serialize($mylp));
    return $return;
}
/**
 * Writes an item's new values into the database and returns the operation result
 * @param   integer Learnpath ID
 * @param   integer User ID
 * @param   integer View ID
 * @param   integer Item ID
 * @return  string  JavaScript operations to execute as soon as returned
 */
function last_update_status($lp_id, $user_id, $view_id, $item_id) {
    error_log(__LINE__);
    global $_configuration;
    $debug = 0;
    $return = '';
    if ($debug > 0) { error_log('In last_update_status('.$lp_id.','.$user_id.','.$view_id.','.$item_id.')', 0); }
    require_once 'learnpath.class.php';
    require_once 'scorm.class.php';
    require_once 'learnpathItem.class.php';
    require_once 'scormItem.class.php';
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);

    // This function should only be used for SCORM paths.
    if ($mylp->get_type() != 2) {
        return;
    }
    $prereq_check = $mylp->prerequisites_match($item_id);
    $mystatus = '';
    if ($prereq_check === true) {
        error_log(__LINE__);
        // Launch the prerequisites check and set error if needed.
        $mylpi =& $mylp->items[$item_id];

        $mystatus_in_db = $mylpi->get_status(true);
        error_log($mystatus_in_db);
        if ($mystatus_in_db == 'not attempted' or $mystatus_in_db == '') {
        error_log(__LINE__);
            $mystatus = 'completed';
            $mastery_score = $mylpi->get_mastery_score();
            if ($mastery_score != -1) {
        error_log(__LINE__);
                $score = $mylpi->get_score();
                if ($score != 0 && $score >= $mastery_score) {
        error_log(__LINE__);
                    $mystatus = 'passed';
                } else {
        error_log(__LINE__);
                    $mystatus = 'failed';
                }
            }
            error_log(__LINE__);
            $mylpi->set_status($mystatus);
            $mylp->save_item($item_id, false);
        } else {
            error_log(__LINE__);
            return $return;
        }
    } else {
        error_log(__LINE__);
        return $return;
    }
    error_log(__LINE__);
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = ($myprogress_mode==''?'%':$myprogress_mode);
    $return .= "update_toc('".$mystatus."','".$item_id."','no');";
    error_log('Return is now '.$return);
    $update_list = $mylp->get_update_queue();
    foreach ($update_list as $my_upd_id => $my_upd_status) {
        if ($my_upd_id != $item_id) { // Only update the status from other items (i.e. parents and brothers), do not update current as we just did it already.
            $return .= "update_toc('".$my_upd_status."','".$my_upd_id."','no');";
        }
    }
    $return .= "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";
    $return .="update_stats();";
    return $return;
    //return $objResponse;
}
/**
 * Get one item's details
 * @param   integer LP ID
 * @param   integer user ID
 * @param   integer View ID
 * @param   integer Current item ID
 * @param   integer New item ID
 */
function initialize_item($lp_id, $user_id, $view_id, $next_item) {
    global $debug;
    $return = '';
    if ($debug > 0) { error_log('In initialize_item('.$lp_id.','.$user_id.','.$view_id.','.$next_item.')', 0); }
    /*$item_id may be one of:
     * -'next'
     * -'previous'
     * -'first'
     * -'last'
     * - a real item ID
     */
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    $mylp->set_current_item($next_item);
    if ($debug > 1) { error_log('In initialize_item() - new item is '.$next_item, 0); }
    $mylp->start_current_item(true);

    if (is_object($mylp->items[$next_item])) {
        if ($debug > 1) { error_log('In initialize_item - recovering existing item object '.$next_item, 0); }
        $mylpi = $mylp->items[$next_item];
    } else {
        if ($debug > 1) { error_log('In initialize_item - generating new item object '.$next_item, 0); }
        $mylpi = new learnpathItem($next_item, $user_id);
    }

    if ($mylpi) {
        $mylpi->set_lp_view($view_id);
    }

    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    if ($mymax === '') { $mymax = "''"; }
    $mymin = $mylpi->get_min();

    $mylesson_status = $mylpi->get_status();
    $mytotal_time = $mylpi->get_scorm_time('js', null, true);
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $myic = $mylpi->get_interactions_count();
    $myistring = '';
    for ($i = 0; $i < $myic; $i++) {
        $myistring .= ",[".$i.",'','','','','','','']";
    }
    if (!empty($myistring)) {
        $myistring = substr($myistring, 1);
    }
	// Obtention des donnees d'objectifs

	$mycoursedb = Database::get_course_table(TABLE_LP_IV_OBJECTIVE);
    $course_id = api_get_course_int_id();
	$mylp_iv_id = $mylpi->db_item_view_id;

    $phpobjectives = array();

    if (!empty($mylp_iv_id)) {
        $sql = "SELECT objective_id, status, score_raw, score_max, score_min
            FROM $mycoursedb
            WHERE lp_iv_id = $mylp_iv_id AND c_id = $course_id
            ORDER BY id ASC;";
        $res = Database::query($sql);
        while ($row = Database::fetch_row($res)) {
            $phpobjectives[] = $row;
        }
    }
	$myobjectives = json_encode($phpobjectives);

    $return .=
            "olms.score=".$myscore.";" .
            "olms.max=".$mymax.";" .
            "olms.min=".$mymin.";" .
            "olms.lesson_status='".$mylesson_status."';" .
            "olms.lesson_location='".$mylesson_location."';" .
            "olms.session_time='".$mysession_time."';" .
            "olms.suspend_data='".$mysuspend_data."';" .
            "olms.total_time = '".$mytotal_time."';" .
            "olms.mastery_score = '".$mymastery_score."';" .
            "olms.max_time_allowed = '".$mymax_time_allowed."';" .
            "olms.launch_data = '".$mylaunch_data."';" .
            "olms.interactions = new Array(".$myistring.");" .
            //"olms.item_objectives = new Array();" .
            "olms.item_objectives = ".$myobjectives.";" .
            "olms.G_lastError = 0;" .
            "olms.G_LastErrorMessage = 'No error';".
            "olms.finishSignalReceived = 0;";
    /*
     * and re-initialise the rest (proper to the LMS)
     * -lms_lp_id
     * -lms_item_id
     * -lms_old_item_id
     * -lms_new_item_id
     * -lms_initialized
     * -lms_progress_bar_mode
     * -lms_view_id
     * -lms_user_id
     */
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode);
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();

    $return .=
            "olms.lms_lp_id=".$lp_id.";" .
            "olms.lms_item_id=".$next_item.";" .
            "olms.lms_old_item_id=0;" .
            "olms.lms_initialized=0;" .
            "olms.lms_view_id=".$view_id.";" .
            "olms.lms_user_id=".$user_id.";" .
            "olms.next_item=".$next_item.";" . // This one is very important to replace possible literal strings.
            "olms.lms_next_item=".$mynext.";" .
            "olms.lms_previous_item=".$myprevious.";" .
            "olms.lms_item_type = '".$myitemtype."';" .
            "olms.lms_item_credit = '".$mycredit."';" .
            "olms.lms_item_lesson_mode = '".$mylesson_mode."';" .
            "olms.lms_item_launch_data = '".$mylaunch_data."';" .
            "olms.lms_item_interactions_count = '".$myinteractions_count."';" .
            "olms.lms_item_objectives_count = '".$myinteractions_count."';" .
            "olms.lms_item_core_exit = '".$mycore_exit."';" .
            "olms.asset_timer = 0;";

    $mylp->set_error_msg('');
    $mylp->prerequisites_match(); // Check the prerequisites are all complete.
    if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); }
    if ($debug > 1) { error_log("return = $return "); }
    return $return;
}
예제 #5
0
/**
 * Writes an item's new values into the database and returns the operation result
 * @param   int $lp_id Learnpath ID
 * @param   int $user_id User ID
 * @param   int $view_id View ID
 * @param   int $item_id Item ID
 * @param   float  $score Current score
 * @param   float  $max Maximum score
 * @param   float  $min Minimum score
 * @param   string  $status Lesson status
 * @param   int  $time Session time
 * @param   string  $suspend Suspend data
 * @param   string  $location Lesson location
 * @param   array   $interactions Interactions array
 * @param   string  $core_exit Core exit SCORM string
 * @param   int     $sessionId Session ID
 * @param   int     $courseId Course ID
 * @param   int     $lmsFinish Whether the call was issued from SCORM's LMSFinish()
 * @param   int     $userNavigatesAway Whether the user is moving to another item
 * @param   int     $statusSignalReceived Whether the SCO called SetValue(lesson_status)
 * @return bool|null|string The resulting JS string
 */
function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1.0, $max = -1.0, $min = -1.0, $status = '', $time = 0, $suspend = '', $location = '', $interactions = array(), $core_exit = 'none', $sessionId = null, $courseId = null, $lmsFinish = 0, $userNavigatesAway = 0, $statusSignalReceived = 0)
{
    //global $debug;
    $debug = 0;
    $return = null;
    if ($debug > 0) {
        error_log('lp_ajax_save_item.php : save_item() params: ');
        error_log("item_id: {$item_id}");
        error_log("lp_id: {$lp_id} - user_id: - {$user_id} - view_id: {$view_id} - item_id: {$item_id}");
        error_log("score: {$score} - max:{$max} - min: {$min} - status:{$status}");
        error_log("time:{$time} - suspend: {$suspend} - location: {$location} - core_exit: {$core_exit}");
        error_log("finish: {$lmsFinish} - navigatesAway: {$userNavigatesAway}");
    }
    $myLP = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    if (!is_a($myLP, 'learnpath')) {
        if ($debug) {
            error_log("mylp variable is not an learnpath object");
        }
        return null;
    }
    $prerequisitesCheck = $myLP->prerequisites_match($item_id);
    /** @var learnpathItem $myLPI */
    $myLPI = isset($myLP->items[$item_id]) ? $myLP->items[$item_id] : '';
    if (empty($myLPI)) {
        if ($debug > 0) {
            error_log("item #{$item_id} not found in the items array: " . print_r($myLP->items, 1));
        }
        return false;
    }
    // This functions sets the $this->db_item_view_id variable needed in get_status() see BT#5069
    $myLPI->set_lp_view($view_id);
    // Launch the prerequisites check and set error if needed
    if ($prerequisitesCheck !== true) {
        // If prerequisites were not matched, don't update any item info
        if ($debug) {
            error_log("prereq_check: " . intval($prerequisitesCheck));
        }
        return $return;
    } else {
        if ($debug > 1) {
            error_log('Prerequisites are OK');
        }
        if (isset($max) && $max != -1) {
            $myLPI->max_score = $max;
            $myLPI->set_max_score($max);
            if ($debug > 1) {
                error_log("Setting max_score: {$max}");
            }
        }
        if (isset($min) && $min != -1 && $min != 'undefined') {
            $myLPI->min_score = $min;
            if ($debug > 1) {
                error_log("Setting min_score: {$min}");
            }
        }
        // set_score function used to save the status, but this is not the case anymore
        if (isset($score) && $score != -1) {
            if ($debug > 1) {
                error_log('Calling set_score(' . $score . ')', 0);
                error_log('set_score changes the status to failed/passed if mastery score is provided', 0);
            }
            $myLPI->set_score($score);
            if ($debug > 1) {
                error_log('Done calling set_score ' . $myLPI->get_score(), 0);
            }
        } else {
            if ($debug > 1) {
                error_log("Score not updated");
            }
        }
        $statusIsSet = false;
        // Default behaviour.
        if (isset($status) && $status != '' && $status != 'undefined') {
            if ($debug > 1) {
                error_log('Calling set_status(' . $status . ')', 0);
            }
            $myLPI->set_status($status);
            $statusIsSet = true;
            if ($debug > 1) {
                error_log('Done calling set_status: checking from memory: ' . $myLPI->get_status(false), 0);
            }
        } else {
            if ($debug > 1) {
                error_log("Status not updated");
            }
        }
        $my_type = $myLPI->get_type();
        // Set status to completed for hotpotatoes if score > 80%.
        if ($my_type == 'hotpotatoes') {
            if ((empty($status) || $status == 'undefined' || $status == 'not attempted') && $max > 0) {
                if ($score / $max > 0.8) {
                    $myStatus = 'completed';
                    if ($debug > 1) {
                        error_log('Calling set_status(' . $myStatus . ') for hotpotatoes', 0);
                    }
                    $myLPI->set_status($myStatus);
                    $statusIsSet = true;
                    if ($debug > 1) {
                        error_log('Done calling set_status for hotpotatoes - now ' . $myLPI->get_status(false), 0);
                    }
                }
            } elseif ($status == 'completed' && $max > 0 && $score / $max < 0.8) {
                $myStatus = 'failed';
                if ($debug > 1) {
                    error_log('Calling set_status(' . $myStatus . ') for hotpotatoes', 0);
                }
                $myLPI->set_status($myStatus);
                $statusIsSet = true;
                if ($debug > 1) {
                    error_log('Done calling set_status for hotpotatoes - now ' . $myLPI->get_status(false), 0);
                }
            }
        } elseif ($my_type == 'sco') {
            /*
             * This is a specific implementation for SCORM 1.2, matching page 26 of SCORM 1.2's RTE
             * "Normally the SCO determines its own status and passes it to the LMS.
             * 1) If cmi.core.credit is set to "credit" and there is a mastery
             *    score in the manifest (adlcp:masteryscore), the LMS can change
             *    the status to either passed or failed depending on the
             *    student's score compared to the mastery score.
             * 2) If there is no mastery score in the manifest
             *    (adlcp:masteryscore), the LMS cannot override SCO
             *    determined status.
             * 3) If the student is taking the SCO for no-credit, there is no
             *    change to the lesson_status, with one exception.  If the
             *    lesson_mode is "browse", the lesson_status may change to
             *    "browsed" even if the cmi.core.credit is set to no-credit.
             * "
             * Additionally, the LMS behaviour should be:
             * If a SCO sets the cmi.core.lesson_status then there is no problem.
             * However, the SCORM does not force the SCO to set the cmi.core.lesson_status.
             * There is some additional requirements that must be adhered to
             * successfully handle these cases:
             * Upon initial launch
             *   the LMS should set the cmi.core.lesson_status to "not attempted".
             * Upon receiving the LMSFinish() call or the user navigates away,
             *   the LMS should set the cmi.core.lesson_status for the SCO to "completed".
             * After setting the cmi.core.lesson_status to "completed",
             *   the LMS should now check to see if a Mastery Score has been
             *   specified in the cmi.student_data.mastery_score, if supported,
             *   or the manifest that the SCO is a member of.
             *   If a Mastery Score is provided and the SCO did set the
             *   cmi.core.score.raw, the LMS shall compare the cmi.core.score.raw
             *   to the Mastery Score and set the cmi.core.lesson_status to
             *   either "passed" or "failed".  If no Mastery Score is provided,
             *   the LMS will leave the cmi.core.lesson_status as "completed"
             */
            $masteryScore = $myLPI->get_mastery_score();
            if ($masteryScore == -1 || empty($masteryScore)) {
                $masteryScore = false;
            }
            $credit = $myLPI->get_credit();
            /**
             * 1) If cmi.core.credit is set to "credit" and there is a mastery
             *    score in the manifest (adlcp:masteryscore), the LMS can change
             *    the status to either passed or failed depending on the
             *    student's score compared to the mastery score.
             */
            if ($credit == 'credit' && $masteryScore && (isset($score) && $score != -1) && !$statusIsSet && !$statusSignalReceived) {
                if ($score >= $masteryScore) {
                    $myLPI->set_status('passed');
                } else {
                    $myLPI->set_status('failed');
                }
                $statusIsSet = true;
            }
            /**
             *  2) If there is no mastery score in the manifest
             *    (adlcp:masteryscore), the LMS cannot override SCO
             *    determined status.
             */
            if (!$statusIsSet && !$masteryScore && !$statusSignalReceived) {
                if (!empty($status)) {
                    $myLPI->set_status($status);
                    $statusIsSet = true;
                }
                //if no status was set directly, we keep the previous one
            }
            /**
             * 3) If the student is taking the SCO for no-credit, there is no
             *    change to the lesson_status, with one exception. If the
             *    lesson_mode is "browse", the lesson_status may change to
             *    "browsed" even if the cmi.core.credit is set to no-credit.
             */
            if (!$statusIsSet && $credit == 'no-credit' && !$statusSignalReceived) {
                $mode = $myLPI->get_lesson_mode();
                if ($mode == 'browse' && $status == 'browsed') {
                    $myLPI->set_status($status);
                    $statusIsSet = true;
                }
                //if no status was set directly, we keep the previous one
            }
            /**
             * If a SCO sets the cmi.core.lesson_status then there is no problem.
             * However, the SCORM does not force the SCO to set the
             * cmi.core.lesson_status.  There is some additional requirements
             * that must be adhered to successfully handle these cases:
             */
            if (!$statusIsSet && empty($status) && !$statusSignalReceived) {
                /**
                 * Upon initial launch the LMS should set the
                 * cmi.core.lesson_status to "not attempted".
                 */
                // this case should be handled by LMSInitialize() and xajax_switch_item()
                /**
                 * Upon receiving the LMSFinish() call or the user navigates
                 * away, the LMS should set the cmi.core.lesson_status for the
                 * SCO to "completed".
                 */
                if ($lmsFinish || $userNavigatesAway) {
                    $myStatus = 'completed';
                    /**
                     * After setting the cmi.core.lesson_status to "completed",
                     *   the LMS should now check to see if a Mastery Score has been
                     *   specified in the cmi.student_data.mastery_score, if supported,
                     *   or the manifest that the SCO is a member of.
                     *   If a Mastery Score is provided and the SCO did set the
                     *   cmi.core.score.raw, the LMS shall compare the cmi.core.score.raw
                     *   to the Mastery Score and set the cmi.core.lesson_status to
                     *   either "passed" or "failed".  If no Mastery Score is provided,
                     *   the LMS will leave the cmi.core.lesson_status as "completed”
                     */
                    if ($masteryScore && (isset($score) && $score != -1)) {
                        if ($score >= $masteryScore) {
                            $myStatus = 'passed';
                        } else {
                            $myStatus = 'failed';
                        }
                    }
                    $myLPI->set_status($myStatus);
                    $statusIsSet = true;
                }
            }
            // End of type=='sco'
        }
        // If no previous condition changed the SCO status, proceed with a
        // generic behaviour
        if (!$statusIsSet && !$statusSignalReceived) {
            // Default behaviour
            if (isset($status) && $status != '' && $status != 'undefined') {
                if ($debug > 1) {
                    error_log('Calling set_status(' . $status . ')', 0);
                }
                $myLPI->set_status($status);
                if ($debug > 1) {
                    error_log('Done calling set_status: checking from memory: ' . $myLPI->get_status(false), 0);
                }
            } else {
                if ($debug > 1) {
                    error_log("Status not updated");
                }
            }
        }
        if (isset($time) && $time != '' && $time != 'undefined') {
            // If big integer, then it's a timestamp, otherwise it's normal scorm time.
            if ($debug > 1) {
                error_log('Calling set_time(' . $time . ') ', 0);
            }
            if ($time == intval(strval($time)) && $time > 1000000) {
                if ($debug > 1) {
                    error_log("Time is INT");
                }
                $real_time = time() - $time;
                if ($debug > 1) {
                    error_log('Calling $real_time ' . $real_time . ' ', 0);
                }
                $myLPI->set_time($real_time, 'int');
            } else {
                if ($debug > 1) {
                    error_log("Time is in SCORM format");
                }
                if ($debug > 1) {
                    error_log('Calling $time ' . $time . ' ', 0);
                }
                $myLPI->set_time($time, 'scorm');
            }
        }
        if (isset($suspend) && $suspend != '' && $suspend != 'undefined') {
            $myLPI->current_data = $suspend;
        }
        if (isset($location) && $location != '' && $location != 'undefined') {
            $myLPI->set_lesson_location($location);
        }
        // Deal with interactions provided in arrays in the following format:
        // id(0), type(1), time(2), weighting(3), correct_responses(4), student_response(5), result(6), latency(7)
        if (is_array($interactions) && count($interactions) > 0) {
            foreach ($interactions as $index => $interaction) {
                //$mylpi->add_interaction($index,$interactions[$index]);
                //fix DT#4444
                $clean_interaction = str_replace('@.|@', ',', $interactions[$index]);
                $myLPI->add_interaction($index, $clean_interaction);
            }
        }
        if ($core_exit != 'undefined') {
            $myLPI->set_core_exit($core_exit);
        }
        $myLP->save_item($item_id, false);
    }
    $myStatusInDB = $myLPI->get_status(true);
    if ($debug) {
        error_log("Status in DB: {$myStatusInDB}");
    }
    if ($myStatusInDB != 'completed' && $myStatusInDB != 'passed' && $myStatusInDB != 'browsed' && $myStatusInDB != 'failed') {
        $myStatusInMemory = $myLPI->get_status(false);
        if ($myStatusInMemory != $myStatusInDB) {
            $myStatus = $myStatusInMemory;
        } else {
            $myStatus = $myStatusInDB;
        }
    } else {
        $myStatus = $myStatusInDB;
    }
    $myTotal = $myLP->get_total_items_count_without_chapters();
    $myComplete = $myLP->get_complete_items_count();
    $myProgressMode = $myLP->get_progress_bar_mode();
    $myProgressMode = $myProgressMode == '' ? '%' : $myProgressMode;
    if ($debug > 1) {
        error_log("mystatus: {$myStatus}", 0);
        error_log("myprogress_mode: {$myProgressMode}", 0);
        error_log("progress: {$myComplete} / {$myTotal}", 0);
    }
    if ($myLPI->get_type() != 'sco') {
        // If this object's JS status has not been updated by the SCORM API, update now.
        $return .= "olms.lesson_status='" . $myStatus . "';";
    }
    $return .= "update_toc('" . $myStatus . "','" . $item_id . "');";
    $update_list = $myLP->get_update_queue();
    foreach ($update_list as $my_upd_id => $my_upd_status) {
        if ($my_upd_id != $item_id) {
            /* Only update the status from other items (i.e. parents and brothers),
               do not update current as we just did it already. */
            $return .= "update_toc('" . $my_upd_status . "','" . $my_upd_id . "');";
        }
    }
    $return .= "update_progress_bar('{$myComplete}', '{$myTotal}', '{$myProgressMode}');";
    $isLoginAs = Container::getAuthorizationChecker()->isGranted('ROLE_PREVIOUS_ADMIN');
    if (!$isLoginAs) {
        $tbl_track_login = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LOGIN);
        $sql = "SELECT login_id, login_date\n                FROM {$tbl_track_login}\n                WHERE login_user_id= " . api_get_user_id() . "\n                ORDER BY login_date DESC\n                LIMIT 0,1";
        $q_last_connection = Database::query($sql);
        if (Database::num_rows($q_last_connection) > 0) {
            $current_time = api_get_utc_datetime();
            $row = Database::fetch_array($q_last_connection);
            $i_id_last_connection = $row['login_id'];
            $sql = "UPDATE {$tbl_track_login}\n                    SET logout_date='" . $current_time . "'\n                    WHERE login_id = {$i_id_last_connection}";
            Database::query($sql);
        }
    }
    if ($myLP->get_type() == 2) {
        $return .= "update_stats();";
    }
    // To be sure progress is updated.
    $myLP->save_last();
    Session::write('lpobject', serialize($myLP));
    if ($debug > 0) {
        error_log('---------------- lp_ajax_save_item.php : save_item end ----- ');
    }
    return $return;
}
/**
 * Get one item's details
 * @param   integer LP ID
 * @param   integer user ID
 * @param   integer View ID
 * @param   integer Current item ID
 * @param   integer New item ID
 */
function switch_item_toc($lp_id, $user_id, $view_id, $current_item, $next_item) {
    $debug = 0;
    $return = '';
    if ($debug > 0) { error_log('In xajax_switch_item_toc('.$lp_id.','.$user_id.','.$view_id.','.$current_item.','.$next_item.')', 0); }
    require_once 'learnpath.class.php';
    require_once 'scorm.class.php';
    require_once 'aicc.class.php';
    require_once 'learnpathItem.class.php';
    require_once 'scormItem.class.php';
    require_once 'aiccItem.class.php';
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    $new_item_id = 0;
    switch ($next_item) {
        case 'next':
            $mylp->set_current_item($current_item);
            $mylp->next();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {next} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'previous':
            $mylp->set_current_item($current_item);
            $mylp->previous();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {previous} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'first':
            $mylp->set_current_item($current_item);
            $mylp->first();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {first} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked
            if($next_item == $current_item){
                // If we're opening the same item again.
                $mylp->items[$current_item]->restart();
            }
            $new_item_id = $next_item;
            $mylp->set_current_item($new_item_id);
            if ($debug > 1) { error_log('In {default} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
    }
    $mylp->start_current_item(true);
    if ($mylp->force_commit) {
        $mylp->save_current();
    }
    if (is_object($mylp->items[$new_item_id])) {
        $mylpi = $mylp->items[$new_item_id];
    } else {
        if ($debug > 1) { error_log('In switch_item_details - generating new item object', 0); }
        $mylpi = new learnpathItem($new_item_id, $user_id);
        $mylpi->set_lp_view($view_id);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    if ($mymax === '') { $mymax = "''"; }
    $mymin = $mylpi->get_min();
    $mylesson_status = $mylpi->get_status();
    $mylesson_location = $mylpi->get_lesson_location();
    $mytotal_time = $mylpi->get_scorm_time('js');
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    /*
    if ($mylpi->get_type() == 'asset') {
        // Temporary measure to save completion of an asset. Later on, Chamilo should trigger something on unload, maybe... (even though that would mean the last item cannot be completed)
        $mylesson_status = 'completed';
        $mylpi->set_status('completed');
        $mylpi->save();
    }
    */
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $myic = $mylpi->get_interactions_count();
    $myistring = '';
    for ($i = 0; $i < $myic; $i++) {
        $myistring .= ",[".$i.",'','','','','','','']";
    }
    if (!empty($myistring)) {
        $myistring = substr($myistring, 1);
    }
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode);
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();

    $return .=
        //"saved_lesson_status='not attempted';" .
        "olms.lms_lp_id=".$lp_id.";" .
        "olms.lms_item_id=".$new_item_id.";" .
        "olms.lms_old_item_id=0;" .
        //"lms_been_synchronized=0;" .
        "olms.lms_initialized=0;" .
        //"lms_total_lessons=".$mytotal.";" .
        //"lms_complete_lessons=".$mycomplete.";" .
        //"lms_progress_bar_mode='".$myprogress_mode."';" .
        "olms.lms_view_id=".$view_id.";" .
        "olms.lms_user_id=".$user_id.";" .
        "olms.next_item=".$new_item_id.";" . // This one is very important to replace possible literal strings.
        "olms.lms_next_item=".$mynext.";" .
        "olms.lms_previous_item=".$myprevious.";" .
        "olms.lms_item_type = '".$myitemtype."';" .
        "olms.lms_item_credit = '".$mycredit."';" .
        "olms.lms_item_lesson_mode = '".$mylesson_mode."';" .
        "olms.lms_item_launch_data = '".$mylaunch_data."';" .
        "olms.lms_item_interactions_count = '".$myinteractions_count."';" .
        "olms.lms_item_objectives_count = '".$myinteractions_count."';" .
        "olms.lms_item_core_exit = '".$mycore_exit."';" .
        "olms.asset_timer = 0;";

    $return .= "update_toc('unhighlight','".$current_item."');".
        "update_toc('highlight','".$new_item_id."');".
        "update_toc('$mylesson_status','".$new_item_id."');".
        "update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');";

    $mylp->set_error_msg('');
    $mylp->prerequisites_match(); // Check the prerequisites are all complete.
    if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); }
    $_SESSION['scorm_item_id'] = $new_item_id; // Save the new item ID for the exercise tool to use.
    $_SESSION['lpobject'] = serialize($mylp);
    return $return;
}
/**
 * Get one item's details
 * @param   integer $lpId LP ID
 * @param   integer $userId user ID
 * @param   integer $viewId View ID
 * @param   integer $currentItem Current item ID
 * @param   integer $nextItem New item ID
 * @return  string  JavaScript commands to be executed in scorm_api.php
 */
function switch_item_toc($lpId, $userId, $viewId, $currentItem, $nextItem)
{
    $debug = 0;
    $return = '';
    if ($debug > 0) {
        error_log('In switch_item_toc(' . $lpId . ',' . $userId . ',' . $viewId . ',' . $currentItem . ',' . $nextItem . ')', 0);
    }
    $myLP = learnpath::getLpFromSession(api_get_course_id(), $lpId, $userId);
    $newItemId = 0;
    $oldItemId = 0;
    switch ($nextItem) {
        case 'next':
            $myLP->set_current_item($currentItem);
            $myLP->next();
            $newItemId = $myLP->get_current_item_id();
            if ($debug > 1) {
                error_log('In {next} - next item is ' . $newItemId . '(current: ' . $currentItem . ')', 0);
            }
            break;
        case 'previous':
            $myLP->set_current_item($currentItem);
            $myLP->previous();
            $newItemId = $myLP->get_current_item_id();
            if ($debug > 1) {
                error_log('In {previous} - next item is ' . $newItemId . '(current: ' . $currentItem . ')', 0);
            }
            break;
        case 'first':
            $myLP->set_current_item($currentItem);
            $myLP->first();
            $newItemId = $myLP->get_current_item_id();
            if ($debug > 1) {
                error_log('In {first} - next item is ' . $newItemId . '(current: ' . $currentItem . ')', 0);
            }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked
            if ($nextItem == $currentItem) {
                // If we're opening the same item again.
                $myLP->items[$currentItem]->restart();
            } else {
                $oldItemId = $currentItem;
            }
            $newItemId = $nextItem;
            $myLP->set_current_item($newItemId);
            if ($debug > 1) {
                error_log('In {default} - next item is ' . $newItemId . '(current: ' . $currentItem . ')', 0);
            }
            break;
    }
    $myLP->start_current_item(true);
    if ($myLP->force_commit) {
        $myLP->save_current();
    }
    if (is_object($myLP->items[$newItemId])) {
        $myLPI = $myLP->items[$newItemId];
    } else {
        if ($debug > 1) {
            error_log('In switch_item_details - generating new item object', 0);
        }
        $myLPI = new learnpathItem($newItemId, $userId);
        $myLPI->set_lp_view($viewId);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $lessonStatus = $myLPI->get_status();
    $interactionsCount = $myLPI->get_interactions_count();
    /**
     * Interactions are not returned by switch_item at the moment, but please
     * leave commented code to allow for the addition of these in the future
     */
    /*
    $interactionsString = '';
    for ($i = 0; $i < $interactionsCount; $i++) {
        $interactionsString .= ",[".$i.",'','','','','','','']";
    }
    if (!empty($interactionsString)) {
        $interactionsString = substr($interactionsString, 1);
    }
    */
    $totalItems = $myLP->get_total_items_count_without_chapters();
    $completedItems = $myLP->get_complete_items_count();
    $progressMode = $myLP->get_progress_bar_mode();
    $progressMode = $progressMode == '' ? '%' : $progressMode;
    $nextItemId = $myLP->get_next_item_id();
    $previousItemId = $myLP->get_previous_item_id();
    $itemType = $myLPI->get_type();
    $lessonMode = $myLPI->get_lesson_mode();
    $credit = $myLPI->get_credit();
    $launchData = $myLPI->get_launch_data();
    $objectivesCount = $myLPI->get_objectives_count();
    $coreExit = $myLPI->get_core_exit();
    $return .= "olms.lms_lp_id=" . $lpId . ";" . "olms.lms_item_id=" . $newItemId . ";" . "olms.lms_old_item_id=" . $oldItemId . ";" . "olms.lms_initialized=0;" . "olms.lms_view_id=" . $viewId . ";" . "olms.lms_user_id=" . $userId . ";" . "olms.next_item=" . $newItemId . ";" . "olms.lms_next_item=" . $nextItemId . ";" . "olms.lms_previous_item=" . $previousItemId . ";" . "olms.lms_item_type = '" . $itemType . "';" . "olms.lms_item_credit = '" . $credit . "';" . "olms.lms_item_lesson_mode = '" . $lessonMode . "';" . "olms.lms_item_launch_data = '" . $launchData . "';" . "olms.lms_item_interactions_count = '" . $interactionsCount . "';" . "olms.lms_item_objectives_count = '" . $objectivesCount . "';" . "olms.lms_item_core_exit = '" . $coreExit . "';" . "olms.asset_timer = 0;";
    $return .= "update_toc('unhighlight','" . $currentItem . "');" . "update_toc('highlight','" . $newItemId . "');" . "update_toc('{$lessonStatus}','" . $newItemId . "');" . "update_progress_bar('{$completedItems}','{$totalItems}','{$progressMode}');";
    $myLP->set_error_msg('');
    $myLP->prerequisites_match();
    // Check the prerequisites are all complete.
    if ($debug > 1) {
        error_log('prerequisites_match() returned ' . htmlentities($myLP->error), 0);
    }
    $_SESSION['scorm_item_id'] = $newItemId;
    // Save the new item ID for the exercise tool to use.
    $_SESSION['lpobject'] = serialize($myLP);
    return $return;
}
예제 #8
0
/**
 * Get one item's details
 * @param	integer	LP ID
 * @param	integer	user ID
 * @param	integer	View ID
 * @param	integer	Current item ID
 * @param	integer New item ID
 */
function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_item) {
    global $charset;

    $debug = 0;
    if ($debug > 0) { error_log('In xajax_switch_item_details('.$lp_id.','.$user_id.','.$view_id.','.$current_item.','.$next_item.')', 0); }
    $objResponse = new xajaxResponse();
    /*$item_id may be one of:
     * -'next'
     * -'previous'
     * -'first'
     * -'last'
     * - a real item ID
     */
    require_once 'learnpath.class.php';
    require_once 'scorm.class.php';
    require_once 'aicc.class.php';
    require_once 'learnpathItem.class.php';
    require_once 'scormItem.class.php';
    require_once 'aiccItem.class.php';
    $mylp = learnpath::getLpFromSession(api_get_course_id(), $lp_id, $user_id);
    $new_item_id = 0;
    switch ($next_item) {
        case 'next':
            $mylp->set_current_item($current_item);
            $mylp->next();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {next} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'previous':
            $mylp->set_current_item($current_item);
            $mylp->previous();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {previous} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'first':
            $mylp->set_current_item($current_item);
            $mylp->first();
            $new_item_id = $mylp->get_current_item_id();
            if ($debug > 1) { error_log('In {first} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
        case 'last':
            break;
        default:
            // Should be filtered to check it's not hacked.
            if($next_item == $current_item){
                // If we're opening the same item again.
                $mylp->items[$current_item]->restart();
            }
            $new_item_id = $next_item;
            $mylp->set_current_item($new_item_id);
            if ($debug > 1) { error_log('In {default} - next item is '.$new_item_id.'(current: '.$current_item.')', 0); }
            break;
    }
    $mylp->start_current_item(true);
    if ($mylp->force_commit){
        $mylp->save_current();
    }
    //$objResponse->addAlert(api_get_path(REL_CODE_PATH).'newscorm/learnpathItem.class.php');
    if (is_object($mylp->items[$new_item_id])) {
        $mylpi = $mylp->items[$new_item_id];
    } else {
        if ($debug > 1) { error_log('In switch_item_details - generating new item object', 0); }
        $mylpi = new learnpathItem($new_item_id, $user_id);
        $mylpi->set_lp_view($view_id);
    }
    /*
     * now get what's needed by the SCORM API:
     * -score
     * -max
     * -min
     * -lesson_status
     * -session_time
     * -suspend_data
     */
    $myscore = $mylpi->get_score();
    $mymax = $mylpi->get_max();
    $mymin = $mylpi->get_min();
    $mylesson_status = $mylpi->get_status();
    $mylesson_location = $mylpi->get_lesson_location();
    $mytotal_time = $mylpi->get_scorm_time('js');
    $mymastery_score = $mylpi->get_mastery_score();
    $mymax_time_allowed = $mylpi->get_max_time_allowed();
    $mylaunch_data = $mylpi->get_launch_data();
    /*
    if ($mylpi->get_type() == 'asset') {
        // Temporary measure to save completion of an asset. Later on, Chamilo should trigger something on unload, maybe... (even though that would mean the last item cannot be completed)
        $mylesson_status = 'completed';
        $mylpi->set_status('completed');
        $mylpi->save();
    }
    */
    $mysession_time = $mylpi->get_total_time();
    $mysuspend_data = $mylpi->get_suspend_data();
    $mylesson_location = $mylpi->get_lesson_location();
    $objResponse->addScript(
            "score=".$myscore.";" .
            "max=".$mymax.";" .
            "min=".$mymin.";" .
            "lesson_status='".$mylesson_status."';" .
            "lesson_location='".$mylesson_location."';" .
            "session_time='".$mysession_time."';" .
            "suspend_data='".$mysuspend_data."';" .
            "lesson_location='".$mylesson_location."';" .
            "total_time = '".$mytotal_time."';" .
            "mastery_score = '".$mymastery_score."';" .
            "max_time_allowed = '".$mymax_time_allowed."';" .
            "launch_data = '".$mylaunch_data."';" .
            "interactions = new Array();" .
            "item_objectives = new Array();" .
            "G_lastError = 0;" .
            "G_LastErrorMessage = 'No error';");
    /*
     * and re-initialise the rest
     * -saved_lesson_status = 'not attempted'
     * -lms_lp_id
     * -lms_item_id
     * -lms_old_item_id
     * -lms_new_item_id
     * -lms_been_synchronized
     * -lms_initialized
     * -lms_total_lessons
     * -lms_complete_lessons
     * -lms_progress_bar_mode
     * -lms_view_id
     * -lms_user_id
     */
    $mytotal = $mylp->get_total_items_count_without_chapters();
    $mycomplete = $mylp->get_complete_items_count();
    $myprogress_mode = $mylp->get_progress_bar_mode();
    $myprogress_mode = ($myprogress_mode == '' ? '%' : $myprogress_mode);
    $mynext = $mylp->get_next_item_id();
    $myprevious = $mylp->get_previous_item_id();
    $myitemtype = $mylpi->get_type();
    $mylesson_mode = $mylpi->get_lesson_mode();
    $mycredit = $mylpi->get_credit();
    $mylaunch_data = $mylpi->get_launch_data();
    $myinteractions_count = $mylpi->get_interactions_count();
    $myobjectives_count = $mylpi->get_objectives_count();
    $mycore_exit = $mylpi->get_core_exit();
    $objResponse->addScript(
            "saved_lesson_status='not attempted';" .
            "lms_lp_id=".$lp_id.";" .
            "lms_item_id=".$new_item_id.";" .
            "lms_old_item_id=0;" .
            "lms_been_synchronized=0;" .
            "lms_initialized=0;" .
            "lms_total_lessons=".$mytotal.";" .
            "lms_complete_lessons=".$mycomplete.";" .
            "lms_progress_bar_mod='".$myprogress_mode."';" .
            "lms_view_id=".$view_id.";" .
            "lms_user_id=".$user_id.";" .
            "next_item=".$new_item_id.";" . // This one is very important to replace possible literal strings.
            "lms_next_item=".$mynext.";" .
            "lms_previous_item=".$myprevious.";" .
            "lms_item_type = '".$myitemtype."';" .
            "lms_item_credit = '".$mycredit."';" .
            "lms_item_lesson_mode = '".$mylesson_mode."';" .
            "lms_item_launch_data = '".$mylaunch_data."';" .
            "lms_item_interactions_count = '".$myinteractions_count."';" .
            "lms_item_objectives_count = '".$myinteractions_count."';" .
            "lms_item_core_exit = '".$mycore_exit."';" .
            "asset_timer = 0;"
            );
    $objResponse->addScript("update_toc('unhighlight','".$current_item."');");
    $objResponse->addScript("update_toc('highlight','".$new_item_id."');");
    $objResponse->addScript("update_toc('$mylesson_status','".$new_item_id."');");
    $objResponse->addScript("update_progress_bar('$mycomplete','$mytotal','$myprogress_mode');");

    $mylp->set_error_msg('');
    $mylp->prerequisites_match(); // Check the prerequisites are all complete.
    if ($debug > 1) { error_log('Prereq_match() returned '.api_htmlentities($mylp->error, ENT_QUOTES, $charset), 0); }
    $objResponse->addScript("update_message_frame('".str_replace("'", "\'", api_htmlentities($mylp->error, ENT_QUOTES, $charset))."');");
    $_SESSION['scorm_item_id'] = $new_item_id; // Save the new item ID for the exercise tool to use.
    $_SESSION['lpobject'] = serialize($mylp);
    return $objResponse;
}