diff --git a/main/exercice/savescores.php b/main/exercice/savescores.php index 618ec788e2..d4a152b26a 100644 --- a/main/exercice/savescores.php +++ b/main/exercice/savescores.php @@ -25,19 +25,19 @@ if (isset($_GET['origin']) && $_GET['origin'] == 'learnpath') { require_once '../inc/global.inc.php'; $this_section = SECTION_COURSES; +$_cid = api_get_course_id(); +$test = $_REQUEST['test']; +$score = $_REQUEST['score']; +$origin = $_REQUEST['origin']; + $documentPath = api_get_path(SYS_COURSE_PATH).$_course['path']."/document"; $full_file_path = $documentPath.$test; FileManager::my_delete($full_file_path.$_user['user_id'].".t.html"); $TABLETRACK_HOTPOTATOES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES); -$tbl_learnpath_user = Database::get_course_table(TABLE_LEARNPATH_USER); $TABLE_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW); -$_cid = api_get_course_id(); -$test = $_REQUEST['test']; -$score = $_REQUEST['score']; -$origin = $_REQUEST['origin']; $jscript2run = ''; /** @@ -51,9 +51,7 @@ $jscript2run = ''; */ function save_scores($file, $score) { - global $origin, $_user, $_cid, - $TABLETRACK_HOTPOTATOES; - // if tracking is disabled record nothing + global $origin, $_user, $TABLETRACK_HOTPOTATOES; $weighting = 100; // 100% $date = api_get_utc_datetime(); @@ -67,7 +65,7 @@ function save_scores($file, $score) '".Database::escape_string($file)."', '".Database::escape_string($user_id)."', '".Database::escape_string($date)."', - '".Database::escape_string($_cid)."', + '".Database::escape_string(api_get_course_id())."', '".Database::escape_string($score)."', '".Database::escape_string($weighting)."')"; @@ -103,4 +101,4 @@ if ($origin != 'learnpath') { Display::display_reduced_header(); Display::display_confirmation_message(get_lang('HotPotatoesFinished')); Display::display_footer(); -} +} \ No newline at end of file diff --git a/main/exercice/showinframes.php b/main/exercice/showinframes.php index 469ea9a93a..9fe18b3c11 100644 --- a/main/exercice/showinframes.php +++ b/main/exercice/showinframes.php @@ -8,7 +8,8 @@ /** * Included libraries */ -require '../inc/global.inc.php'; +require_once '../inc/global.inc.php'; + require_once api_get_path(SYS_CODE_PATH).'exercice/hotpotatoes.lib.php'; $time = time(); @@ -19,7 +20,7 @@ $document_web_path = api_get_path(WEB_COURSE_PATH).$_course['path'].'/document'; $origin = $_REQUEST['origin']; $learnpath_id = $_REQUEST['learnpath_id']; $learnpath_item_id = $_REQUEST['learnpath_item_id']; -$time = $_REQUEST['time']; +$time = isset($_REQUEST['time']) ? $_REQUEST['time'] : null ; $user_id = api_get_user_id(); $full_file_path = $document_path.$doc_url; @@ -27,32 +28,28 @@ FileManager::my_delete($full_file_path.$user_id.'.t.html'); $content = ReadFileCont($full_file_path.$user_id.'.t.html'); if ($content == '') { + $url = api_get_path(WEB_PATH)."main/exercice/savescores.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS($time)."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score"; + $content = ReadFileCont($full_file_path); $mit = "function Finish(){"; $js_content = " //Code added - start + var SaveScoreVariable = 0; function mySaveScore() { if (SaveScoreVariable==0) { SaveScoreVariable = 1; - if (C.ie) { - document.location.href = '".api_get_path( - WEB_PATH - )."main/exercice/savescores.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS( - $time - )."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score; - //window.alert(Score); - } else { - window.location.href = '".api_get_path( - WEB_PATH - )."main/exercice/savescores.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&time=".Security::remove_XSS( - $time - )."&test=".$doc_url."&uid=".$user_id."&cid=".$cid."&score='+Score; - } - } - } - function Finish(){ - mySaveScore(); + if (C.ie) { + document.location.href = '".$url."; + //window.alert(Score); + } else { + window.location.href = '".$url."; + } + } + } + function Finish() { + mySaveScore(); + //Code added - end "; @@ -68,7 +65,6 @@ if ($content == '') { $newcontent = $content; } - WriteFileCont($full_file_path.$user_id.'.t.html', $newcontent); $doc_url = GetFolderPath($doc_url).urlencode(basename($doc_url)); @@ -77,6 +73,7 @@ $my_file = Security::remove_XSS($_GET['file']); $my_file = str_replace(array('../', '\\..', '\\0', '..\\'), array('', '', '', ''), urldecode($my_file)); $title = GetQuizName($my_file, $documentPath); + if ($title == '') { $title = basename($my_file); } @@ -109,4 +106,5 @@ if ($origin == 'learnpath') { $url = $document_web_path.$doc_url.$user_id.'.t.html?time='.Security::remove_XSS($time); echo ''; echo ''; -exit; +Display::display_footer(); +exit; \ No newline at end of file diff --git a/main/newscorm/learnpathItem.class.php b/main/newscorm/learnpathItem.class.php index 49f8015d3c..a6616e6311 100644 --- a/main/newscorm/learnpathItem.class.php +++ b/main/newscorm/learnpathItem.class.php @@ -1242,8 +1242,7 @@ class learnpathItem } if (!empty($this->db_item_view_id)) { $table = Database::get_course_table(TABLE_LP_ITEM_VIEW); - $sql = "SELECT status FROM $table WHERE c_id = $course_id AND id = '".$this->db_item_view_id."' AND view_count = '".$this->get_attempt_id( - )."'"; + $sql = "SELECT status FROM $table WHERE c_id = $course_id AND id = '".$this->db_item_view_id."' AND view_count = '".$this->get_attempt_id()."'"; if (self::debug > 2) { error_log('learnpathItem::get_status() - Checking DB: '.$sql, 0); } @@ -1303,14 +1302,12 @@ class learnpathItem */ public function get_scorm_time($origin = 'php', $given_time = null, $query_db = false) { + $time = 0; $h = get_lang('h'); $course_id = api_get_course_int_id(); if (!isset($given_time)) { if (self::debug > 2) { - error_log( - 'learnpathItem::get_scorm_time(): given time empty, current_start_time = '.$this->current_start_time, - 0 - ); + error_log('learnpathItem::get_scorm_time(): given time empty, current_start_time = '.$this->current_start_time, 0); } if (is_object($this)) { if ($query_db === true) { @@ -1395,21 +1392,24 @@ class learnpathItem */ public function get_total_time() { - if (self::debug > 0) { + $debug = self::debug; + if ($debug > 0) { error_log( 'learnpathItem::get_total_time() for item '.$this->db_id.' - Initially, current_start_time = '.$this->current_start_time.' and current_stop_time = '.$this->current_stop_time, 0 ); } - if ($this->current_start_time == 0) { // Shouldn't be necessary thanks to the open() method. - if (self::debug > 2) { + + // Shouldn't be necessary thanks to the open() method + if ($this->current_start_time == 0) { + if ($debug > 2) { error_log('learnpathItem::get_total_time() - Current start time was empty', 0); } $this->current_start_time = time(); } - //$this->current_stop_time=time(); + if (time() < $this->current_stop_time or $this->current_stop_time == 0) { - if (self::debug > 2) { + if ($debug > 2) { error_log( 'learnpathItem::get_total_time() - Current stop time was greater than the current time or was empty', 0 @@ -1421,19 +1421,18 @@ class learnpathItem } $time = $this->current_stop_time - $this->current_start_time; if ($time < 0) { - if (self::debug > 2) { + if ($debug > 2) { error_log('learnpathItem::get_total_time() - Time smaller than 0. Returning 0', 0); } return 0; } else { - if (self::debug > 2) { + if ($debug > 2) { error_log( 'learnpathItem::get_total_time() - Current start time = '.$this->current_start_time.', current stop time = '.$this->current_stop_time.' Returning '.$time."-----------\n", 0 ); } - return $time; } } diff --git a/main/newscorm/lp_ajax_save_item.php b/main/newscorm/lp_ajax_save_item.php index 4f363565d1..c57979100b 100644 --- a/main/newscorm/lp_ajax_save_item.php +++ b/main/newscorm/lp_ajax_save_item.php @@ -171,11 +171,13 @@ function save_item($lp_id, $user_id, $view_id, $item_id, $score = -1, $max = -1, } //if ($debug > 1) { error_log('Done calling set_time - now '.$mylpi->get_total_time(), 0); } } else { + //Fixes time when loading hotpotatoes see #3343 $time = $mylpi->get_total_time(); + $mylpi->set_time($time, 'int'); } if (isset($suspend) && $suspend != '' && $suspend != 'undefined') { - $mylpi->current_data = $suspend; //escapetxt($suspend); + $mylpi->current_data = $suspend; } if (isset($location) && $location != '' && $location!='undefined') { diff --git a/main/newscorm/lp_ajax_switch_item.php b/main/newscorm/lp_ajax_switch_item.php index a260dc1830..00c5497676 100644 --- a/main/newscorm/lp_ajax_switch_item.php +++ b/main/newscorm/lp_ajax_switch_item.php @@ -19,6 +19,13 @@ $language_file[] = 'learnpath'; require_once '../inc/global.inc.php'; +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'; + /** * Get one item's details * @param integer LP ID @@ -42,12 +49,7 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it * -'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) { @@ -70,6 +72,10 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it } $mylp = $oLP; } + } else { + if ($debug > 1) { + error_log('$_SESSION[lpobject] is NOT set', 0); + } } $check_attempts = $mylp->check_item_attempts($next_item); @@ -132,6 +138,7 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it $mylpi = new learnpathItem($new_item_id, $user_id); $mylpi->set_lp_view($view_id); } + /* * now get what's needed by the SCORM API: * -score @@ -155,7 +162,6 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it $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++) { @@ -247,6 +253,7 @@ function switch_item_details($lp_id, $user_id, $view_id, $current_item, $next_it $mylp->prerequisites_match(); // Check the prerequisites are all complete. if ($debug > 1) { error_log('Prereq_match() returned '.htmlentities($mylp->error), 0); + error_log($return); } $_SESSION['scorm_item_id'] = $new_item_id; // Save the new item ID for the exercise tool to use. $_SESSION['lpobject'] = serialize($mylp); diff --git a/main/newscorm/lp_stats.php b/main/newscorm/lp_stats.php index 35c22f442c..93839237e5 100644 --- a/main/newscorm/lp_stats.php +++ b/main/newscorm/lp_stats.php @@ -943,3 +943,5 @@ if ($origin != 'tracking') { if (empty($export_csv)) { echo $output; } + +Display::display_footer(); diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index 1284ca2c01..79acc318b5 100644 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -45,9 +45,8 @@ if (!is_object($oItem)) { $autocomplete_when_80pct = 0; $user = api_get_user_info(); header('Content-type: text/javascript'); - -?>var scorm_logs=scorm_debug) or (!api_is_course_admin() && !api_is_platform_admin()) )?'0':'3');?>; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame -var lms_logs=0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all +?>var scorm_logs = scorm_debug) or (!api_is_course_admin() && !api_is_platform_admin()) )?'0':'3');?>; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame +var lms_logs = 0; //debug log level for LMS actions. 0=none, 1=light, 2=a lot, 3=all // API Object initialization (eases access later on) function APIobject() { @@ -203,7 +202,7 @@ $(document).ready(function() { olms.info_lms_item[1] = 'get_id();?>'; $("#content_id").load(function() { - logit_lms('#content_id on load executing: '); + logit_lms('#content_id on load executed'); olms.info_lms_item[0] = olms.info_lms_item[1]; if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') { @@ -1041,6 +1040,7 @@ function addListeners(){ * leaving it */ function lms_save_asset() { + logit_lms('lms_save_asset called'); // only for Chamilo lps if (olms.execute_stats) { olms.execute_stats = false; @@ -1058,7 +1058,6 @@ function lms_save_asset() { } if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset') { - logit_lms('lms_save_asset'); logit_lms('execute_stats :'+ olms.execute_stats); xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, olms.score, olms.max, olms.min, olms.lesson_status, olms.session_time, olms.suspend_data, olms.lesson_location, olms.interactions, olms.lms_item_core_exit); if (olms.item_objectives.length>0) {