Ejemplo n.º 1
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)
{
    $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;
}
Ejemplo n.º 2
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 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;
}
/**
 * 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 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 = '';
    if (isset($_SESSION['lpobject'])) {
        if ($debug > 1) {
            error_log('$_SESSION[lpobject] is set', 0);
        }
        $oLP = unserialize($_SESSION['lpobject']);
        if (!is_object($oLP)) {
            if ($debug > 1) {
                error_log(print_r($oLP, true), 0);
            }
            if ($debug > 2) {
                error_log('Building new lp', 0);
            }
            unset($oLP);
            $code = api_get_course_id();
            $mylp = new learnpath($code, $lp_id, $user_id);
        } else {
            if ($debug > 1) {
                error_log('Reusing session lp', 0);
            }
            $mylp = $oLP;
        }
    }
    $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();
    $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 .= "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}');";
    $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;
}
Ejemplo n.º 5
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 = '';
    if (isset($_SESSION['lpobject'])) {
        if ($debug > 1) {
            error_log('$_SESSION[lpobject] is set', 0);
        }
        $oLP = unserialize($_SESSION['lpobject']);
        if (!is_object($oLP)) {
            if ($debug > 1) {
                error_log(print_r($oLP, true), 0);
            }
            if ($debug > 2) {
                error_log('Building new lp', 0);
            }
            unset($oLP);
            $code = api_get_course_id();
            $mylp = new learnpath($code, $lp_id, $user_id);
        } else {
            if ($debug > 1) {
                error_log('Reusing session lp', 0);
            }
            $mylp = $oLP;
        }
    }
    $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();
    $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 . ";" . "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;
}