123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- /* For licensing terms, see /license.txt */
- use ChamiloSession as Session;
- /**
- * This script contains the server part of the ajax interaction process. The client part is located
- * in lp_api.php or other api's.
- * This script updated the TOC of the SCORM without updating the SCO's attributes
- * @package chamilo.learnpath
- * @author Yannick Warnier <ywarnier@beeznest.org>
- */
- // Flag to allow for anonymous user - needs to be set before global.inc.php.
- $use_anonymous = true;
- //require_once '../inc/global.inc.php';
- /**
- * 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.";" . // This one is very important to replace possible literal strings.
- "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::write('lpobject', serialize($myLP));
- Session::write('scorm_item_id', $newItemId);
- return $return;
- }
- echo switch_item_toc(
- $_POST['lid'],
- $_POST['uid'],
- $_POST['vid'],
- $_POST['iid'],
- $_POST['next']
- );
|