Browse Source

Updating from 1.9.x

Julio Montoya 12 years ago
parent
commit
b7e653d23d

+ 10 - 12
main/newscorm/learnpath.class.php

@@ -2591,19 +2591,18 @@ class learnpath {
      */
     public function get_toc() {
         if ($this->debug > 0) {
-            error_log('New LP - In learnpath::get_toc()', 0);
+            error_log('learnpath::get_toc()', 0);
         }
         $toc = array();
         //echo "<pre>".print_r($this->items,true)."</pre>";
         foreach ($this->ordered_items as $item_id) {
             if ($this->debug > 2) {
-                error_log('New LP - learnpath::get_toc(): getting info for item ' . $item_id, 0);
+                error_log('learnpath::get_toc(): getting info for item ' . $item_id, 0);
             }
             // TODO: Change this link generation and use new function instead.
             $toc[] = array (
                 'id'            => $item_id,
                 'title'         => $this->items[$item_id]->get_title(),
-                //'link' => get_addedresource_link_in_learnpath('document', $item_id, 1),
                 'status'        => $this->items[$item_id]->get_status(),
                 'level'         => $this->items[$item_id]->get_level(),
                 'type'          => $this->items[$item_id]->get_type(),
@@ -2617,7 +2616,6 @@ class learnpath {
         return $toc;
     }
 
-
     /**
      * Generate and return the table of contents for this learnpath. The JS
      * table returned is used inside of scorm_api.php
@@ -2720,12 +2718,12 @@ class learnpath {
         $is_allowed_to_edit = api_is_allowed_to_edit(null, true, false, false);
 
         if ($this->debug > 0) {
-            error_log('New LP - In learnpath::get_html_toc()', 0);
+            error_log('In learnpath::get_html_toc()', 0);
         }
         if (empty($toc_list)) {
             $toc_list = $this->get_toc();
         }
-        $html = '<div id="scorm_title" class="scorm_title">' . Security::remove_XSS($this->get_name()) . '</div>';
+        $html = '<div id="scorm_title" class="scorm_title">'.Security::remove_XSS($this->get_name()) . '</div>';
 
         $hide_teacher_icons_lp = isset($_configuration['hide_teacher_icons_lp']) ? $_configuration['hide_teacher_icons_lp'] : true;
 
@@ -2750,10 +2748,7 @@ class learnpath {
         $i = 0;
 
         foreach ($toc_list as $item) {
-            if ($this->debug > 2) {
-                //error_log('New LP - learnpath::get_html_toc(): using item ' . $item['id'], 0);
-            }
-            // TODO: Complete this.
+            // TODO: Complete this
             $icon_name = array (
                 'not attempted' => '../img/notattempted.gif',
                 'incomplete'    => '../img/incomplete.png',
@@ -2773,7 +2768,6 @@ class learnpath {
                 $style = 'scorm_item_highlight';
                 $scorm_color_background = 'scorm_item_highlight';
             } else {
-
                 if ($color_counter % 2 == 0) {
                     $scorm_color_background = 'scorm_item_1';
                 } else {
@@ -2829,8 +2823,12 @@ class learnpath {
             $result = Database::query($sql);
             $count = Database :: num_rows($result);*/
             if ($item['type'] == 'quiz') {
+                error_log("1-->>>>>>>>>>>>>>>>");
+                error_log($item['status']);
                 if ($item['status'] == 'completed') {
-                    $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14'  />";
+                    $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name[$item['status']] . "' alt='" . substr($item['status'], 0, 1) . "' width='14' />";
+                } else {
+                    $html .= "&nbsp;<img id='toc_img_" . $item['id'] . "' src='" . $icon_name['not attempted'] . "' alt='" . substr('not attempted', 0, 1) . "' width='14' />";
                 }
             } else {
                 if ($item['type'] != 'dokeos_chapter' && $item['type'] != 'dokeos_module' && $item['type'] != 'dir') {

+ 2 - 8
main/newscorm/lp_ajax_start_timer.php

@@ -2,9 +2,6 @@
 /* For licensing terms, see /license.txt */
 
 /**
- * This script contains the server part of the xajax interaction process. The client part is located
- * in lp_api.php or other api's.
- * This is a first attempt at using xajax and AJAX in general, so the code might be a bit unsettling.
  * @package chamilo.learnpath
  * @author Yannick Warnier <ywarnier@beeznest.org>
  */
@@ -15,10 +12,7 @@
  * @return string JavaScript time intializer
  */
 function start_timer() {
-    //$objResponse = new xajaxResponse();
     $time = time();
-    //$objResponse->addScript("asset_timer='$time';asset_timer_total=0;");
-    //return $objResponse;
-    return "olms.asset_timer='$time';olms.asset_timer_total=0;";
+    return $time; //"olms.asset_timer='$time'; olms.asset_timer_total = 0;";
 }
-echo start_timer();
+echo start_timer();

+ 4 - 3
main/newscorm/lp_list.php

@@ -211,7 +211,7 @@ if (!empty($flat_list)) {
         $url_start_lp = 'lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$id;
         $name = Security::remove_XSS($details['lp_name']);
         if ($is_allowed_to_edit) {
-        	//&nbsp;'.$details['lp_proximity'].'
+            $url_start_lp .= '&isStudentView=true';
             $dsp_desc = '<em>'.$details['lp_maker'].'</em>   '.(learnpath::is_lp_visible_for_student($id, api_get_user_id())?'':' - ('.get_lang('LPNotVisibleToStudent').')');
             $extra = '<div class ="lp_content_type_label">'.$dsp_desc .'</div>';
         }
@@ -223,10 +223,11 @@ if (!empty($flat_list)) {
         if ($details['lp_visibility'] == 0 ) {
             $my_title = Display::tag('font', $name, array('style'=>'color:grey'));
         }
+
         $dsp_line =	'<tr align="center" class="'.$oddclass.'">'.
-            		'<td align="left" valign="top">'.Display::return_icon('learnpath.png', get_lang('LPName'),'',ICON_SIZE_SMALL).'<a href="'.$url_start_lp.'">' . $my_title . '</a>' . $session_img .$extra."</td>";
+            		'<td align="left" valign="top">'.Display::return_icon('learnpath.png', get_lang('LPName'),'',ICON_SIZE_SMALL).'
+                     <a href="'.$url_start_lp.'">' . $my_title . '</a>' . $session_img .$extra."</td>";
 
-        //$dsp_desc='<td>'.$details['lp_desc'].'</td>'."\n";
         $dsp_desc = '';
         $dsp_export = '';
         $dsp_edit = '';

+ 102 - 106
main/newscorm/lp_stats.php

@@ -149,23 +149,23 @@ if (isset($_GET['lp_id']) && isset($_GET['lp_item_id'])) {
     if (Database::num_rows($res_path) > 0) {
         if ($origin != 'tracking') {
             $sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . '
-            				 WHERE  exe_exo_id="' . (int) $row_path['path'] . '" AND 
-                                    status <> "incomplete"  AND 
-                                    exe_user_id="' . api_get_user_id() . '" AND 
-                                    orig_lp_id = "' . (int) $clean_lp_id . '" AND 
-                                    orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND 
-                                    exe_cours_id="' . $clean_course_code . '"  AND 
-                                    session_id = ' . $session_id . ' 
+            				 WHERE  exe_exo_id="' . (int) $row_path['path'] . '" AND
+                                    status <> "incomplete"  AND
+                                    exe_user_id="' . api_get_user_id() . '" AND
+                                    orig_lp_id = "' . (int) $clean_lp_id . '" AND
+                                    orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND
+                                    exe_cours_id="' . $clean_course_code . '"  AND
+                                    session_id = ' . $session_id . '
                              ORDER BY exe_date';
         } else {
             $sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . '
-            				 WHERE  exe_exo_id="' . (int) $row_path['path'] . '" AND 
-                                    status <> "incomplete"  AND 
-                                    exe_user_id="' . $student_id . '" AND 
-                                    orig_lp_id = "' . (int) $clean_lp_id . '" AND 
-                                    orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND 
-                                    exe_cours_id="' . $clean_course_code . '"  AND 
-                                    session_id = ' . $session_id . ' 
+            				 WHERE  exe_exo_id="' . (int) $row_path['path'] . '" AND
+                                    status <> "incomplete"  AND
+                                    exe_user_id="' . $student_id . '" AND
+                                    orig_lp_id = "' . (int) $clean_lp_id . '" AND
+                                    orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND
+                                    exe_cours_id="' . $clean_course_code . '"  AND
+                                    session_id = ' . $session_id . '
                              ORDER BY exe_date';
         }
     }
@@ -184,54 +184,54 @@ if (is_array($list) && count($list) > 0) {
 
         // Prepare statement to go through each attempt.
         if (!empty($view)) {
-            $sql = "SELECT  iv.status as mystatus, 
-                            v.view_count as mycount, 
-                            iv.score as myscore, 
-                            iv.total_time as mytime, 
+            $sql = "SELECT  iv.status as mystatus,
+                            v.view_count as mycount,
+                            iv.score as myscore,
+                            iv.total_time as mytime,
                             i.id as myid,
-                            i.lp_id as mylpid, 
-                            iv.lp_view_id as mylpviewid, 
-                            i.title as mytitle, 
+                            i.lp_id as mylpid,
+                            iv.lp_view_id as mylpviewid,
+                            i.title as mytitle,
                             i.max_score as mymaxscore,
-                            iv.max_score as myviewmaxscore, 
-                            i.item_type as item_type, 
-                            iv.view_count as iv_view_count, 
-                            iv.id as iv_id, 
+                            iv.max_score as myviewmaxscore,
+                            i.item_type as item_type,
+                            iv.view_count as iv_view_count,
+                            iv.id as iv_id,
                             path
-                    FROM $TBL_LP_ITEM as i 
+                    FROM $TBL_LP_ITEM as i
                     INNER JOIN $TBL_LP_ITEM_VIEW as iv ON (i.id = iv.lp_item_id  AND i.c_id = $course_id AND iv.c_id = $course_id)
                     INNER JOIN $TBL_LP_VIEW as v ON (iv.lp_view_id = v.id AND v.c_id = $course_id)
             WHERE
                 i.id = $my_item_id AND
                 i.lp_id = $lp_id  AND
                 v.user_id = $user_id AND
-                v.view_count = $view AND 
+                v.view_count = $view AND
                 v.session_id = $session_id
             ORDER BY iv.view_count $qry_order ";
             //var_dump($sql);
         } else {
-            $sql = "SELECT  iv.status as mystatus, 
-                            v.view_count as mycount, 
-                            iv.score as myscore, 
-                            iv.total_time as mytime, 
-                            i.id as myid, 
-                            i.lp_id as mylpid, 
+            $sql = "SELECT  iv.status as mystatus,
+                            v.view_count as mycount,
+                            iv.score as myscore,
+                            iv.total_time as mytime,
+                            i.id as myid,
+                            i.lp_id as mylpid,
                             iv.lp_view_id as mylpviewid,
-                            i.title as mytitle, 
-                            i.max_score as mymaxscore, 
-                            iv.max_score as myviewmaxscore, 
-                            i.item_type as item_type, 
+                            i.title as mytitle,
+                            i.max_score as mymaxscore,
+                            iv.max_score as myviewmaxscore,
+                            i.item_type as item_type,
                             iv.view_count as iv_view_count,
-                            iv.id as iv_id, 
+                            iv.id as iv_id,
                             path
-                    FROM $TBL_LP_ITEM as i 
+                    FROM $TBL_LP_ITEM as i
                     INNER JOIN $TBL_LP_ITEM_VIEW as iv ON (i.id = iv.lp_item_id  AND i.c_id = $course_id AND iv.c_id = $course_id)
                     INNER JOIN $TBL_LP_VIEW as v ON (iv.lp_view_id = v.id AND v.c_id = $course_id)
-                    WHERE                        
-                        i.id = $my_item_id AND                        
-                        i.lp_id = $lp_id AND 
-                        v.user_id = $user_id AND 
-                        v.session_id = $session_id 
+                    WHERE
+                        i.id = $my_item_id AND
+                        i.lp_id = $lp_id AND
+                        v.user_id = $user_id AND
+                        v.session_id = $session_id
                    ORDER BY iv.view_count $qry_order ";
         }
         $result = Database::query($sql);
@@ -254,7 +254,7 @@ if (is_array($list) && count($list) > 0) {
                     $result_disabled_ext_all = true;
                 }
             }
-            
+
             // If there are several attempts, and the link to extend has been clicked, show each attempt...
             if (($counter % 2) == 0) {
                 $oddclass = 'row_odd';
@@ -274,7 +274,7 @@ if (is_array($list) && count($list) > 0) {
 
             if ($row['item_type'] != 'dokeos_chapter') {
                 $correct_test_link = '-';
-                $title = Security::remove_XSS($title);                
+                $title = Security::remove_XSS($title);
                 $output .= '<tr class="'.$oddclass.'">
                                 <td>'.$extend_link.'</td>
                                 <td colspan="4">
@@ -292,7 +292,7 @@ if (is_array($list) && count($list) > 0) {
                 // Check if there are interactions below.
                 $extend_attempt_link = '';
                 $extend_this_attempt = 0;
-                
+
                 if ((learnpath :: get_interactions_count_from_db($row['iv_id'], $course_id) > 0 || learnpath :: get_objectives_count_from_db($row['iv_id'], $course_id) > 0) && !$extend_all) {
                     if (!empty($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
                         // The extend button for this attempt has been clicked.
@@ -317,7 +317,7 @@ if (is_array($list) && count($list) > 0) {
 
                 $time = learnpathItem :: get_scorm_time('js', $row['mytime']);
                 $scoIdentifier = $row['myid'];
-                
+
                 if ($score == 0) {
                     $maxscore = $row['mymaxscore'];
                 } else {
@@ -335,7 +335,7 @@ if (is_array($list) && count($list) > 0) {
                 }
 
                 // Remove "NaN" if any (@todo: locate the source of these NaN)
-                $time = str_replace('NaN', '00' . $h . '00\'00"', $time);             
+                $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
 
                 if ($row['item_type'] != 'dokeos_chapter') {
                     if (!$is_allowed_to_edit && $result_disabled_ext_all) {
@@ -390,7 +390,7 @@ if (is_array($list) && count($list) > 0) {
 
                 if ($extend_this_attempt OR $extend_all) {
                     $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
-                                        
+
                     foreach ($list1 as $id => $interaction) {
                         if (($counter % 2) == 0) {
                             $oddclass = 'row_odd';
@@ -421,9 +421,9 @@ if (is_array($list) && count($list) > 0) {
                                         <td></td>
                                     </tr>';
                         $counter++;
-                    }                    
+                    }
                     $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
-                    
+
                     foreach ($list2 as $id => $interaction) {
                         if (($counter % 2) == 0) {
                             $oddclass = 'row_odd';
@@ -511,24 +511,24 @@ if (is_array($list) && count($list) > 0) {
 
             // Selecting the exe_id from stats attempts tables in order to look the max score value.
             if ($origin != 'tracking') {
-                $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' 
-                                     WHERE  exe_exo_id="' . $row['path'] . '" AND 
-                                            exe_user_id="' . api_get_user_id() . '" AND 
-                                            orig_lp_id = "' . $lp_id . '" AND 
-                                            orig_lp_item_id = "' . $row['myid'] . '" AND 
-                                            exe_cours_id="' . $course_code . '" AND 
-                                            status <> "incomplete" AND 
-                                            session_id = ' . $session_id . ' 
+                $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
+                                     WHERE  exe_exo_id="' . $row['path'] . '" AND
+                                            exe_user_id="' . api_get_user_id() . '" AND
+                                            orig_lp_id = "' . $lp_id . '" AND
+                                            orig_lp_item_id = "' . $row['myid'] . '" AND
+                                            exe_cours_id="' . $course_code . '" AND
+                                            status <> "incomplete" AND
+                                            session_id = ' . $session_id . '
                                      ORDER BY exe_date DESC limit 1';
             } else {
-                $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' 
-                                     WHERE  exe_exo_id="' . $row['path'] . '" AND 
-                                            exe_user_id="' . $student_id . '" AND 
-                                            orig_lp_id = "' . $lp_id . '" AND 
-                                            orig_lp_item_id = "' . $row['myid'] . '" AND 
-                                            exe_cours_id="' . $course_code . '" AND 
-                                            status <> "incomplete" AND 
-                                            session_id = ' . $session_id . ' 
+                $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
+                                     WHERE  exe_exo_id="' . $row['path'] . '" AND
+                                            exe_user_id="' . $student_id . '" AND
+                                            orig_lp_id = "' . $lp_id . '" AND
+                                            orig_lp_item_id = "' . $row['myid'] . '" AND
+                                            exe_cours_id="' . $course_code . '" AND
+                                            status <> "incomplete" AND
+                                            session_id = ' . $session_id . '
                                      ORDER BY exe_date DESC limit 1';
             }
 
@@ -576,11 +576,11 @@ if (is_array($list) && count($list) > 0) {
                         //echo $subtotal_time ;
                         //$time = learnpathItem :: get_scorm_time('js', $subtotal_time);
                         // Selecting the max score from an attempt.
-                        $sql = "SELECT SUM(t.ponderation) as maxscore 
+                        $sql = "SELECT SUM(t.ponderation) as maxscore
                                 FROM (
-                        			SELECT distinct question_id, marks, ponderation 
+                        			SELECT distinct question_id, marks, ponderation
                                     FROM $tbl_stats_attempts as at INNER JOIN  $tbl_quiz_questions as q
-                        			ON (q.id = at.question_id AND q.c_id = $course_id 
+                        			ON (q.id = at.question_id AND q.c_id = $course_id
                                     )
                                 WHERE exe_id ='$id_last_attempt' ) as t";
 
@@ -608,25 +608,25 @@ if (is_array($list) && count($list) > 0) {
 
                     if ($origin != 'tracking' && $origin != 'tracking_course') {
                         $my_url_suffix = '&course=' . api_get_course_id() . '&student_id=' . api_get_user_id() . '&lp_id=' . Security::remove_XSS($row['mylpid']);
-                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' 
-                                             WHERE  exe_exo_id="' . $row['path'] . '" AND 
-                                                    exe_user_id="' . api_get_user_id() . '" AND 
-                                                    orig_lp_id = "' . $lp_id . '" AND 
-                                                    orig_lp_item_id = "' . $row['myid'] . '" AND 
-                                                    exe_cours_id="' . $course_code . '" AND 
-                                                    status <> "incomplete" AND 
-                                                    session_id = ' . $session_id . ' 
+                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
+                                             WHERE  exe_exo_id="' . $row['path'] . '" AND
+                                                    exe_user_id="' . api_get_user_id() . '" AND
+                                                    orig_lp_id = "' . $lp_id . '" AND
+                                                    orig_lp_item_id = "' . $row['myid'] . '" AND
+                                                    exe_cours_id="' . $course_code . '" AND
+                                                    status <> "incomplete" AND
+                                                    session_id = ' . $session_id . '
                                             ORDER BY exe_date DESC ';
                     } else {
                         $my_url_suffix = '&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($row['mylpid']) . '&origin=' . Security::remove_XSS($_GET['origin'] . $from_link);
-                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' 
-                                             WHERE   exe_exo_id="' . $row['path'] . '" AND 
-                                                    exe_user_id="' . $student_id . '" AND 
-                                                    orig_lp_id = "' . $lp_id . '" AND 
-                                                    orig_lp_item_id = "' . $row['myid'] . '" AND 
-                                                    exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND 
-                                                    status <> "incomplete" AND 
-                                                    session_id = ' . $session_id . '  
+                        $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
+                                             WHERE   exe_exo_id="' . $row['path'] . '" AND
+                                                    exe_user_id="' . $student_id . '" AND
+                                                    orig_lp_id = "' . $lp_id . '" AND
+                                                    orig_lp_item_id = "' . $row['myid'] . '" AND
+                                                    exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND
+                                                    status <> "incomplete" AND
+                                                    session_id = ' . $session_id . '
                                              ORDER BY exe_date DESC ';
                     }
 
@@ -634,7 +634,7 @@ if (is_array($list) && count($list) > 0) {
                     $num = Database :: num_rows($resultLastAttempt);
                     if ($num > 0) {
                         if (isset($_GET['extend_attempt']) && $_GET['extend_attempt'] == 1 && (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id) && (isset($_GET['lp_item_id']) && $_GET['lp_item_id'] == $my_id)) {
-                            $correct_test_link = '<a href="' . api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . api_get_session_id() . '&lp_item_id=' . $my_id . '"><img src="../img/view_less_stats.gif" alt="fold_view" border="0" title="' . get_lang('HideAllAttempts') . '"></a>';                            
+                            $correct_test_link = '<a href="' . api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . api_get_session_id() . '&lp_item_id=' . $my_id . '"><img src="../img/view_less_stats.gif" alt="fold_view" border="0" title="' . get_lang('HideAllAttempts') . '"></a>';
                         } else {
                             $correct_test_link = '<a href="' . api_get_self() . '?action=stats&extend_attempt=1' . $my_url_suffix . '&session_id=' . api_get_session_id() . '&lp_item_id=' . $my_id . '"><img src="../img/view_more_stats.gif" alt="extend_view" border="0" title="' . get_lang('ShowAllAttemptsByExercise') . '"></a>';
                         }
@@ -648,7 +648,7 @@ if (is_array($list) && count($list) > 0) {
                 $title = Security::remove_XSS($title);
 
                 if ((isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id && false)) {
-                    
+
                     $output .= '<tr class =' . $oddclass . '>
                                     <td>' . $extend_link . '</td>
                                     <td colspan="4">' . $title . '</td>
@@ -664,15 +664,15 @@ if (is_array($list) && count($list) > 0) {
                     } else {
                         $output .= "<tr class='$oddclass'>";
                     }
-                    
-                    if (($is_allowed_to_edit || api_is_drh()) && isset($_GET['lp_id']) && isset($course_code)) {                        
-                        $lp = new learnpath($course_code, $_GET['lp_id'], api_get_user_id());                                         
+
+                    if (($is_allowed_to_edit || api_is_drh()) && isset($_GET['lp_id']) && isset($course_code)) {
+                        $lp = new learnpath($course_code, $_GET['lp_id'], api_get_user_id());
                         $lp->set_course_int_id($course_id);
-                        $item_path_url = $lp->get_link('http', $my_id, false);                    
+                        $item_path_url = $lp->get_link('http', $my_id, false);
                         $item_path_url .= "&width=600";
                         $title = Display::url($title, $item_path_url, array('class' => 'ajax'));
                     }
-                    
+
                     $output .= '<td>'.$extend_link.'</td>
                                 <td colspan="4">' . $title . '</td>
                                 <td colspan="2">' . learnpathitem::humanize_status($lesson_status) .'</td>
@@ -680,7 +680,7 @@ if (is_array($list) && count($list) > 0) {
                     if ($row['item_type'] == 'quiz') {
                         if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                             $output .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
-                        } else {                            
+                        } else {
                             $output .= show_score($score, $maxscore, false);
                         }
                     } else {
@@ -787,16 +787,16 @@ if (is_array($list) && count($list) > 0) {
                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                 $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
                             } else {
-                                // Show only float when need it                                
-                                if ($my_score == 0) {                                    
+                                // Show only float when need it
+                                if ($my_score == 0) {
                                     $view_score = show_score(0, $my_maxscore, false);
                                 } else {
                                     if ($my_maxscore == 0) {
                                         $view_score = $my_score;
-                                    } else {                                        
+                                    } else {
                                         $view_score = show_score($my_score, $my_maxscore, false);
                                     }
-                                }                                
+                                }
                             }
                             $my_lesson_status = $row_attempts['status'];
 
@@ -809,14 +809,10 @@ if (is_array($list) && count($list) > 0) {
                             $output .= '<tr class="' . $oddclass . '" >
                                             <td></td>
                                             <td>' . $extend_attempt_link . '</td>
-                                            <td colspan="3">' . get_lang('Attempt') . ' ' . $n . '</td>
+                                            <td colspan="3">' . get_lang('Attempt').' '. $n.'</td>
                                             <td colspan="2">' . $my_lesson_status . '</td>
-                                            <td colspan="2">
-                                                ' . $view_score . '
-                                            </td>
-                                            <td colspan="2">
-                                                ' . $time_attemp . '
-                                            </td>';
+                                            <td colspan="2">'.$view_score . '</td>
+                                            <td colspan="2">'.$time_attemp . '</td>';
                             if ($origin != 'tracking') {
                                 if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                     $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></td>';

+ 249 - 216
main/newscorm/scorm_api.php

@@ -144,8 +144,9 @@ olms.scorm_variables = new Array(
 
 // manage variables to save or not
 olms.variable_to_send=new Array();
+
 // temporary list of variables (gets set to true when set through LMSSetValue)
-olms.updatable_vars_list=new Array();
+olms.updatable_vars_list = new Array();
 
 // Strictly scorm variables
 olms.score=<?php echo $oItem->get_score();?>;
@@ -168,10 +169,12 @@ olms.info_lms_item=new Array();
 olms.lms_lp_id = <?php echo $oLP->get_id();?>;
 olms.lms_item_id = <?php echo $oItem->get_id();?>;
 olms.lms_initialized = 0;
+
 //olms.lms_total_lessons = <?php echo $oLP->get_total_items_count(); ?>;
 //olms.lms_complete_lessons = <?php echo $oLP->get_complete_items_count();?>;
 //olms.lms_progress_bar_mode = '<?php echo $oLP->progress_bar_mode;?>';
 //if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';}
+
 olms.lms_view_id = '<?php echo $oLP->get_view();?>';
 if(olms.lms_view_id == ''){ olms.lms_view_id = 1;}
 olms.lms_user_id = '<?php echo $_user['user_id'];?>';
@@ -189,41 +192,42 @@ olms.asset_timer = 0;
 olms.userfname = '<?php echo str_replace("'","\\'",$user['firstname']); ?>';
 olms.userlname = '<?php echo str_replace("'","\\'",$user['lastname']); ?>';
 
-//Backup for old values
-//var olms.old_score = 0;
-//var old_max = 0;
-//var old_min = 0;
-//var old_lesson_status = '';
-//var old_session_time = '';
-//var old_suspend_data = '';
-//var olms.lms_old_item_id = 0;
-
 olms.execute_stats = false;
 
-// Initialize stuff when the page is loaded
-$(document).ready( function() {
-
-  olms.info_lms_item[0]='<?php echo $oItem->get_id();?>';
-  olms.info_lms_item[1]='<?php echo $oItem->get_id();?>';
+/**
+ * Add the "addListeners" function to the "onload" event of the window and
+ * start the timer if necessary (asset)
+ */
+addEvent(window, 'load', addListeners, false);
 
-  $("#content_id").load( function() {
+// Initialize stuff when the page is loaded
+$(document).ready(function() {
+    logit_lms('document.ready start');
 
-    // Add a right margin see BT#1607
-    /*if (frames['content_name']) {
-        // See the task #2558: try-catch block has been added for suppressing "Access denied" error that may occur on IE.
-        try {
-            frames['content_name'].document.body.style.margin="0 12px 0px 5px";
-        } catch (ex) { }
-    }*/
+    olms.info_lms_item[0] = '<?php echo $oItem->get_id();?>';
+    olms.info_lms_item[1] = '<?php echo $oItem->get_id();?>';
 
-    olms.info_lms_item[0]=olms.info_lms_item[1];
+    $("#content_id").load(function() {
+        logit_lms('#content_id on load executing: ');
+        olms.info_lms_item[0] = olms.info_lms_item[1];
 
-    if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') {
-        LMSInitialize();
-    }
+        if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') {
+            LMSInitialize();
+        } else {
+            logit_lms('Cant execute LMSInitialize() ');
+        }
     });
 });
 
+//Seems that this objs are not used
+//oXAJAX = new XAJAXobject();
+//oxajax = new XAJAXobject();
+
+// This code was moved inside LMSInitialize()
+if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset') {
+    //xajax_start_timer();
+}
+
 /**
  * The following section represents a set of mandatory functions for SCORM
  */
@@ -239,10 +243,13 @@ function LMSInitialize() {
      * and that kind of stuff, so when the content loads in the content frame
      * it will have all the correct variables set
      */
+
+    logit_scorm('LMSInitialize()');
+
     olms.G_LastError = G_NoError ;
     olms.G_LastErrorMessage = 'No error';
 
-    olms.lms_initialized=0;
+    olms.lms_initialized = 0;
     // if there are more parameters than ""
     if (arguments.length > 1) {
         olms.G_LastError 		= G_InvalidArgumentError;
@@ -252,6 +259,7 @@ function LMSInitialize() {
     } else {
         //reinit the list of modified variables
         reinit_updatable_vars_list();
+
         // Get LMS values for this item
         var params = {
             'lid': olms.lms_lp_id,
@@ -259,6 +267,7 @@ function LMSInitialize() {
             'vid': olms.lms_view_id,
             'iid': olms.lms_item_id
         };
+
         $.ajax({
             type: "POST",
             url: "lp_ajax_initialize.php",
@@ -266,8 +275,11 @@ function LMSInitialize() {
             dataType: 'script',
             async: false
         });
-       // log a more complete object dump when initializing, so we know what data hasn't been cleaned
-       var log = '\nitem              : '+ olms.lms_item_id
+
+        olms.lms_initialized = 1;
+
+        // log a more complete object dump when initializing, so we know what data hasn't been cleaned
+        var log = '\nitem             : '+ olms.lms_item_id
                  + '\nitem_type       : '+ olms.lms_item_type
                  + '\nscore           : '+ olms.score
                  + '\nmax             : '+ olms.max
@@ -285,9 +297,15 @@ function LMSInitialize() {
                  + '\nlms_view_id     : '+ olms.lms_view_id
                 ;
 
-        logit_scorm('LMSInitialize()'+log,0);
+        logit_scorm('LMSInitialize() with params: '+log);
 
-        olms.lms_initialized = 1;
+        if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset') {
+            xajax_start_timer();
+        }
+
+        if (olms.lms_item_type == 'quiz') {
+            update_toc(olms.lesson_status, olms.lms_item_id);
+        }
 
         <?php if (api_get_setting('show_glossary_in_documents') == 'ismanual') { ?>
             if (olms.lms_item_type == 'sco') {
@@ -316,7 +334,6 @@ function Initialize() {
  * @return  string  All return values must be string (see SCORM)
  */
 function LMSGetValue(param) {
-    //logit_scorm("LMSGetValue('"+param+"')",1);
     olms.G_LastError = G_NoError ;
     olms.G_LastErrorMessage = 'No error';
     var result='';
@@ -452,8 +469,7 @@ function LMSGetValue(param) {
                 } else if(req_type == '_children'){
                     result = 'id,score,status';
                 } else if(req_type == 'score'){
-                    if(myres[3]==null)
-                    {
+                    if(myres[3]==null) {
                         result = '';
                         olms.G_LastError = G_NotImplementedError;
                         olms.G_LastErrorString = 'Not implemented yet';
@@ -475,62 +491,57 @@ function LMSGetValue(param) {
                 }
            } else {
                 //the object is not null
-                if(req_type == 'id')
-                {
+                if(req_type == 'id') {
                     result = olms.item_objectives[obj_id][0];
-                }else if(req_type == '_children'){
+                } else if(req_type == '_children'){
                     result = 'id,score,status';
-                }else if(req_type == 'score'){
-                    if(myres[3]==null)
-                    {
+                } else if(req_type == 'score'){
+                    if(myres[3]==null) {
                         result = '';
                         olms.G_LastError = G_NotImplementedError;
                         olms.G_LastErrorString = 'Not implemented yet';
-                    }else if (myres[3] == '._children'){
+                    } else if (myres[3] == '._children'){
                         result = 'raw,min,max'; //non-standard, added for NetG
-                    }else if (myres[3] == '.raw'){
+                    } else if (myres[3] == '.raw'){
                         if(olms.item_objectives[obj_id][2] != null)
                         {
                             result = olms.item_objectives[obj_id][2];
                         }else{
                             result = '';
                         }
-                    }else if (myres[3] == '.max'){
-                        if(olms.item_objectives[obj_id][3] != null)
-                        {
+                    } else if (myres[3] == '.max'){
+                        if(olms.item_objectives[obj_id][3] != null) {
                             result = olms.item_objectives[obj_id][3];
                         }else{
                             result = '';
                         }
-                    }else if (myres[3] == '.min'){
-                        if(olms.item_objectives[obj_id][4] != null)
-                        {
+                    } else if (myres[3] == '.min') {
+                        if(olms.item_objectives[obj_id][4] != null) {
                             result = olms.item_objectives[obj_id][4];
-                        }else{
+                        } else {
                             result = '';
                         }
-                    }else{
+                    } else{
                         result = '';
                         olms.G_LastError = G_NotImplementedError;
                         olms.G_LastErrorString = 'Not implemented yet';
                     }
-                }else if(req_type == 'status'){
-                    if(olms.item_objectives[obj_id][1] != null)
-                    {
+                } else if(req_type == 'status'){
+                    if(olms.item_objectives[obj_id][1] != null) {
                         result = olms.item_objectives[obj_id][1];
-                    }else{
+                    } else {
                         result = 'not attempted';
                     }
                 }
             }
         }
-    }else if(param == 'cmi.student_data._children'){
-    // ---- cmi.student_data._children
+    } else if(param == 'cmi.student_data._children'){
+        // ---- cmi.student_data._children
         result = 'mastery_score,max_time_allowed';
     } else if(param == 'cmi.student_data.mastery_score'){
         // ---- cmi.student_data.mastery_score
         result = olms.mastery_score;
-    }else if(param == 'cmi.student_data.max_time_allowed'){
+    } else if(param == 'cmi.student_data.max_time_allowed'){
         // ---- cmi.student_data.max_time_allowed
         result = olms.max_time_allowed;
     } else if(param == 'cmi.interactions._count'){
@@ -551,12 +562,14 @@ function LMSGetValue(param) {
     logit_scorm("LMSGetValue\n\t('"+param+"') returned '"+result+"'",1);
     return result;
 }
+
 /**
  * Twin sister of LMSGetValue(). Only provided for backwards compatibility.
  */
 function GetValue(param) {
     return LMSGetValue(param);
 }
+
 /**
  * Sets a SCORM variable's value through a call from the SCO.
  * @param   string  The SCORM variable's name
@@ -637,7 +650,7 @@ function LMSSetValue(param, val) {
     } else if ( param == "cmi.student_data.time_limit_action" ) {
         olms.G_LastError = G_ElementIsReadOnly;
     } else if ( param == "cmi.student_data.mastery_score" ) {
-        olms.G_LastError = G_ElementIsReadOnly;
+       olms.G_LastError = G_ElementIsReadOnly;
     } else if ( param == "cmi.student_data.max_time_allowed" ) {
         olms.G_LastError = G_ElementIsReadOnly;
     } else if ( param == "cmi.student_preference._children" ) {
@@ -649,8 +662,8 @@ function LMSSetValue(param, val) {
         if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) {
             olms.updatable_vars_list['interactions']=true;
             elem_id = myres[1];
-            if(elem_id > olms.interactions.length) //interactions setting should start at 0
-            {
+             //interactions setting should start at 0
+            if(elem_id > olms.interactions.length) {
                 /*
                 olms.G_LastError = G_InvalidArgumentError;
                 olms.G_LastErrorString = 'Invalid argument (interactions)';
@@ -839,7 +852,6 @@ function savedata(origin) {
  */
 function LMSCommit(val) {
     logit_scorm('LMSCommit() + val');
-    logit_scorm(val);
 
     olms.G_LastError = G_NoError ;
     olms.G_LastErrorMessage = 'No error';
@@ -849,12 +861,14 @@ function LMSCommit(val) {
     //commit = 'false' ; //now changes have been commited, no need to update until next SetValue()
     return('true');
 }
+
 /**
  * Twin sister of LMSCommit(). Only provided for backwards compatibility.
  */
 function Commit(val) {
     return LMSCommit(val);
 }
+
 /**
  * Send the closure signal to the LMS. This saves the data and closes the current SCO.
  * From SCORM 1.2 RTE: The SCO must call this when it has determined that it no
@@ -883,12 +897,14 @@ function LMSFinish(val) {
     reinit_updatable_vars_list();
     return('true');
 }
+
 /**
  * Twin sister of LMSFinish(). Only provided for backwards compatibility.
  */
 function Finish(val) {
     return LMSFinish(val);
 }
+
 /**
  * Returns the last error code as a string
  * @return  string  Error code
@@ -897,12 +913,14 @@ function LMSGetLastError() {
     logit_scorm('LMSGetLastError()',1);
     return(olms.G_LastError.toString());
 }
+
 /**
  * Twin sister of LMSGetLastError(). Only provided for backwards compatibility.
  */
 function GetLastError() {
     return LMSGetLastError();
 }
+
 /**
  * Returns the last error code literal for a given error code
  * @param   int     Error code
@@ -912,12 +930,14 @@ function LMSGetErrorString(errCode){
     logit_scorm('LMSGetErrorString()',1);
     return(olms.G_LastErrorString);
 }
+
 /**
  * Twin sister of LMSGetErrorString(). Only provided for backwards compatibility.
  */
 function GetErrorString(errCode){
     return LMSGetErrorString(errCode);
 }
+
 /**
  * Returns a more explanatory, full English, error message
  * @param   int     Error code
@@ -927,20 +947,21 @@ function LMSGetDiagnostic(errCode){
     logit_scorm('LMSGetDiagnostic()',1);
     return(API.LMSGetLastError());
 }
+
 /**
  * Twin sister of LMSGetDiagnostic(). Only provided for backwards compatibility.
  */
 function GetDiagnostic(errCode){
     return LMSGetDiagnostic(errCode);
 }
+
 /**
  * Acts as a "commit"
  * This function is not standard SCORM 1.2 and is probably deprecated in all
  * meanings of the term.
  * @return  string  'true' or 'false', depening on whether the LMS has initialized the SCORM process or not
  */
-function Terminate()
-{
+function Terminate() {
     if (olms.lms_initialized == 0) {
         olms.G_LastError 		= G_NotInitialized;
         olms.G_LastErrorMessage = G_NotInitializedMessage;
@@ -955,6 +976,7 @@ function Terminate()
         return ('true');
     }
 }
+
 /**
  * LMS-specific code that deals with event handling and inter-frames
  * messaging/refreshing.
@@ -966,19 +988,12 @@ function Terminate()
  * Defining the AJAX-object class to be made available from other frames
  */
 function XAJAXobject() {
-  this.xajax_switch_item_details=xajax_switch_item_details;
-  this.switch_item=switch_item;
-  this.xajax_save_objectives=xajax_save_objectives;
-  this.xajax_save_item = xajax_save_item;
+    this.xajax_switch_item_details = xajax_switch_item_details;
+    this.switch_item = switch_item;
+    this.xajax_save_objectives = xajax_save_objectives;
+    this.xajax_save_item = xajax_save_item;
 }
 
-/**
- * It is not sure that the SCOs use the above declarations
- */
-
-oXAJAX = new XAJAXobject();
-oxajax = new XAJAXobject();
-
 /**
  * Cross-browser event handling by Scott Andrew
  * @param	element	Element that needs an event attached
@@ -987,12 +1002,12 @@ oxajax = new XAJAXobject();
  * @param   string	used in addEventListener
  */
 function addEvent(elm, evType, fn, useCapture){
-    if(elm.addEventListener){
+    if (elm.addEventListener){
         elm.addEventListener(evType, fn, useCapture);
         return true;
-    }else if (elm.attachEvent){
+    } else if (elm.attachEvent) {
         var r = elm.attachEvent('on' + evType, fn);
-    }else{
+    } else{
         elm['on'+evType] = fn;
     }
 }
@@ -1007,21 +1022,21 @@ function addEvent(elm, evType, fn, useCapture){
 function addListeners(){
     //exit if the browser doesn't support ID or tag retrieval
     logit_lms('Entering addListeners()',2);
-    if(!document.getElementsByTagName){
+    if (!document.getElementsByTagName){
         logit_lms("getElementsByTagName not available",2);
         return;
     }
-    if(!document.getElementById){
+    if (!document.getElementById){
         logit_lms("getElementById not available",2);
         return;
     }
     //assign event handlers to objects
-    if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
+    if (olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
         logit_lms('Chamilo LP or asset',2);
         //if this path is a Chamilo learnpath, then start manual save
         //when something is loaded in there
-        addEvent(window,'unload',lms_save_asset,false);
-        logit_lms('Added event listener on content_id for unload',2);
+        addEvent(window, 'unload', lms_save_asset,false);
+        logit_lms('Added event listener lms_save_asset() on window unload',2);
     }
     logit_lms('Quitting addListeners()',2);
 }
@@ -1043,9 +1058,14 @@ function lms_save_asset() {
        olms.execute_stats = false;
     }
 
+    if (olms.lms_item_type == 'quiz') {
+        olms.execute_stats = true;
+    }
+
     if (olms.lms_lp_type == 1 || olms.lms_item_type == 'asset') {
-        logit_lms('lms_save_asset', 2);
-        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);
+        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) {
             xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives);
         }
@@ -1059,12 +1079,19 @@ function lms_save_asset() {
  * Also save the score locally because it hasn't been done through SetValue().
  * Saving the status will be dealt with by the XAJAX function.
  */
-function chamilo_void_save_asset(myscore,mymax)
-{
-    logit_lms('lms_save_asset',2);
-    olms.score = myscore;
-    if((mymax == null) || (mymax == '')){mymax = 100;} //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
-    xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, myscore, mymax);
+function chamilo_void_save_asset(score, max, min, status) {
+    logit_lms('chamilo_void_save_asset',2);
+    olms.score = score;
+    if ((max == null) || (max == '')){
+        max = 100;
+    }
+
+    if ((min == null) || (min == '')){
+        min = 0;
+    }
+
+    //assume a default of 100, otherwise the score will not get saved (see lpi->set_score())
+    xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, score, max, min, status);
 }
 
 /**
@@ -1113,7 +1140,7 @@ function update_toc(update_action, update_id, change_ids) {
     }
     var myelem = $("#toc_"+update_id);
     var myelemimg = $("#toc_img_"+update_id);
-    logit_lms('update_toc("'+update_action+'",'+update_id+')',2);
+    logit_lms('update_toc("'+update_action+'", '+update_id+')',2);
 
     if (update_id != 0) {
         switch (update_action) {
@@ -1179,6 +1206,7 @@ function update_toc(update_action, update_id, change_ids) {
  * Update the stats frame using a reload of the frame to avoid unsynched data
  */
 function update_stats() {
+    logit_lms('update_stats()');
     if (olms.execute_stats) {
         try {
             cont_f = document.getElementById('content_id');
@@ -1195,6 +1223,7 @@ function update_stats() {
  * Update the stats frame using a reload of the frame to avoid unsynched data
  */
 function update_stats_page() {
+    logit_lms('update_stats_page');
     var myframe = document.getElementById('content_id');
     var mysrc = myframe.location.href;
     if(mysrc == 'lp_controller.php?action=stats'){
@@ -1207,7 +1236,6 @@ function update_stats_page() {
     return true;
 }
 
-
 /**
  * Updates the progress bar with the new status. Prevents the need of a page refresh and flickering
  * @param	integer	Number of completed items
@@ -1215,7 +1243,7 @@ function update_stats_page() {
  * @param	string  Display mode (absolute 'abs' or percentage '%').Defaults to %
  */
 function update_progress_bar(nbr_complete, nbr_total, mode) {
-    logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2);
+    logit_lms('update_progress_bar('+nbr_complete+', '+nbr_total+', '+mode+')',2);
     logit_lms('update_progress_bar with params: lms_lp_id= '+olms.lms_lp_id+', lms_view_id= '+olms.lms_view_id+' lms_user_id= '+olms.lms_user_id,2);
 
     if (mode == '') {
@@ -1252,14 +1280,16 @@ function update_progress_bar(nbr_complete, nbr_total, mode) {
  * put them into an array for later shipping to lp_ajax_save_item.php
  * @return  array   Array of SCO variables
  */
-function process_scorm_values () {
-    for (i=0;i<olms.scorm_variables.length;i++) {
+function process_scorm_values() {
+    logit_scorm('process_scorm_values()');
+    for (i=0; i<olms.scorm_variables.length; i++) {
         if (olms.updatable_vars_list[olms.scorm_variables[i]]) {
             olms.variable_to_send.push(olms.scorm_variables[i]);
         }
     }
     return olms.variable_to_send;
 }
+
 /**
  * Reinitializes the SCO's modified variables to an empty list.
  * @return  void
@@ -1288,7 +1318,6 @@ function reinit_updatable_vars_list() {
  * @param	string		This parameter can be a string specifying the next
  *						item (like 'next', 'previous', 'first' or 'last') or the id to the next item
  */
-
 function switch_item(current_item, next_item){
     // backup these params
     var orig_current_item   = current_item;
@@ -1297,6 +1326,8 @@ function switch_item(current_item, next_item){
     var orig_item_type      = olms.lms_item_types['i'+current_item];
     var next_item_type      = olms.lms_item_types['i'+next_item];
 
+    logit_lms('switch_item() called with params '+olms.lms_item_id+' and '+next_item+'',0);
+
     /*
      There are four "cases" for switching items:
      (1) asset switching to asset
@@ -1315,14 +1346,12 @@ function switch_item(current_item, next_item){
      These cases, although clear here, are however very difficult to implement
     */
 
-    logit_lms('Called switch_item with params '+olms.lms_item_id+' and '+next_item+'',0);
-
     if (orig_item_type != 'sco') {
         if (next_item_type != 'sco' ) {
             //case 1
             logit_lms('Case 1');
             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.asset_timer, olms.suspend_data, olms.lesson_location,olms.interactions, olms.lms_item_core_exit);
-            xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item);
+            xajax_switch_item_details(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, next_item);
         } else {
             logit_lms('Case 2');
             //case 2
@@ -1406,17 +1435,18 @@ function switch_item(current_item, next_item){
     switch (next_item){
         case 'next':
             next_item = olms.lms_next_item;
-            olms.info_lms_item[0]=olms.info_lms_item[1];
-            olms.info_lms_item[1]=olms.lms_next_item;
+            olms.info_lms_item[0] = olms.info_lms_item[1];
+            olms.info_lms_item[1] = olms.lms_next_item;
             break;
         case 'previous':
             next_item = olms.lms_previous_item;
-            olms.info_lms_item[0]=olms.info_lms_item[1];
-            olms.info_lms_item[1]=olms.lms_previous_item;
+            olms.info_lms_item[0] = olms.info_lms_item[1];
+            olms.info_lms_item[1] = olms.lms_previous_item;
             break;
         default:
             break;
     }
+
     var mysrc = 'lp_controller.php?action=content&lp_id='+olms.lms_lp_id+'&item_id='+next_item;
     var cont_f = $("#content_id");
 
@@ -1433,7 +1463,7 @@ function switch_item(current_item, next_item){
             cont_f.attr("src",mysrc);
     <?php } ?>
 
-    if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
+    if (olms.lms_lp_type==1 || olms.lms_item_type == 'asset'){
         xajax_start_timer();
     }
 
@@ -1475,17 +1505,15 @@ function switch_item(current_item, next_item){
  * @uses lp_ajax_save_item.php through an AJAX call
  */
 function xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, session_time, suspend_data, lesson_location, interactions, lms_item_core_exit) {
-    params  = '';
+    var params = '';
     params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
     params += '&iid='+lms_item_id+'&s='+score+'&max='+max+'&min='+min;
     params += '&status='+lesson_status+'&t='+session_time;
     params += '&suspend='+suspend_data+'&loc='+lesson_location;
     params += '&core_exit='+lms_item_core_exit;
-
-    if ( olms.lms_lp_type == 1) {
-
+    //console.info(session_time);
+    if (olms.lms_lp_type == 1) {
         logit_lms('xajax_save_item with params:' + params);
-
         $.ajax({
             type:"POST",
             data: params,
@@ -1509,7 +1537,6 @@ function xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score
  * @uses lp_ajax_save_item.php through an AJAX call
  */
 function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id) {
-
     var is_interactions='false';
     var params = 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id;
     var my_scorm_values = new Array();
@@ -1530,17 +1557,13 @@ function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id)
         } else if (my_scorm_values[k]=='cmi.core.lesson_location') {
             params += '&loc='+olms.lesson_location;
         } else if (my_scorm_values[k]=='cmi.completion_status') {
-
         } else if (my_scorm_values[k]=='cmi.score.scaled') {
-
         } else if (my_scorm_values[k]=='cmi.suspend_data') {
             params += '&suspend='+olms.suspend_data;
         } else if (my_scorm_values[k]=='cmi.completion_status') {
-
         } else if (my_scorm_values[k]=='cmi.core.exit') {
             params += '&core_exit='+olms.lms_item_core_exit;
         }
-
         if (my_scorm_values[k]=='interactions') {
             is_interactions='true';
         } else {
@@ -1583,7 +1606,7 @@ function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id)
         dataType: "script",
         async: false
     });
-    params='';
+    params = '';
     my_scorm_values = null;
 }
 
@@ -1594,13 +1617,23 @@ function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id)
  * @uses    lp_ajax_start_timer.php
  */
 function xajax_start_timer() {
+    logit_lms('xajax_start_timer() called');
     $.ajax({
         type: "GET",
         url: "lp_ajax_start_timer.php",
         dataType: "script",
-        async: false
+        async: false,
+        success: function(time) {
+            olms.asset_timer = time;
+            olms.asset_timer_total = 0;
+            logit_lms('xajax_start_timer result: ' + time);
+
+            var date = new Date(time * 1000);
+            logit_lms('xajax_start_timer result: ' + date.toString());
+        }
     });
 }
+
 /**
  * Save a specific item's objectives into the LMS through an Synch JAX call
  * @param   int     ID of the learning path
@@ -1611,10 +1644,13 @@ function xajax_start_timer() {
  * @uses    lp_ajax_save_objectives.php
  */
 function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives) {
-    params='';
+    var params = '';
     params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id;
     params += '&iid='+lms_item_id;
     obj_string = '';
+
+    logit_lms('xajax_save_objectives with params:' + params);
+
     for (i in item_objectives){
         obj_string += '&objectives['+i+']=';
         obj_temp = '[';
@@ -1633,6 +1669,7 @@ function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,ite
         async: false
     });
 }
+
 /**
  * Switch between two items through an AJAX call.
  * @param   int     ID of the learning path
@@ -1643,13 +1680,16 @@ function xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,ite
  * @uses    lp_ajax_switch_item.php
  */
 function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
-    params = {
+    var params = {
         'lid': lms_lp_id,
         'uid': lms_user_id,
         'vid': lms_view_id,
         'iid': lms_item_id,
         'next': next_item
     };
+
+    logit_lms('xajax_switch_item_details with params:' + params);
+
     $.ajax({
         type: "POST",
         data: params,
@@ -1658,6 +1698,7 @@ function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id
         async: false
     });
 }
+
 /**
  * Switch between two items through an AJAX call, but only update the TOC and
  * progress bar.
@@ -1668,7 +1709,7 @@ function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id
  * @param   int     ID of the next item
  * @uses    lp_ajax_switch_toc.php
  */
-function xajax_switch_item_toc(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item) {
+function xajax_switch_item_toc(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, next_item) {
     var params = {
         'lid': lms_lp_id,
         'uid': lms_user_id,
@@ -1676,6 +1717,8 @@ function xajax_switch_item_toc(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,nex
         'iid': lms_item_id,
         'next': next_item
     };
+    logit_lms('xajax_switch_item_toc');
+
     $.ajax({
         type: "POST",
         data: params,
@@ -1684,21 +1727,14 @@ function xajax_switch_item_toc(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,nex
         async: false
     });
 }
-/**
- * Add the "addListeners" function to the "onload" event of the window and
- * start the timer if necessary (asset)
- */
-addEvent(window,'load',addListeners,false);
-if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){
-    xajax_start_timer();
-}
+
+
 /**
  * Allow attach the glossary terms into html document of scorm. This has
  * nothing to do with SCORM itself, and should not interfere w/ SCORM either.
   * @param   string     automatic or manual values are allowed
 */
 function attach_glossary_into_scorm(type) {
-
     var f = $('#content_id')[0];
     //Prevents "f is undefined" javascript error
     if (f == null) {
@@ -1719,107 +1755,105 @@ function attach_glossary_into_scorm(type) {
     work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/'));
 
     if (type == 'automatic') {
+        $.ajax({
+            contentType: "application/x-www-form-urlencoded",
+            beforeSend: function(object) {
+            },
+            type: "POST",
+            url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php",
+            data: "glossary_data=true",
+            success: function(datas) {
+                if (datas.length==0) {
+                    return false;
+                }
+                // glossary terms
+                data_terms=datas.split("[|.|_|.|-|.|]");
+                var complex_array = new Array();
+                var cp_complex_array = new Array();
+                for(i=0;i<data_terms.length;i++) {
+                    specific_terms= data_terms[i].split("__|__|");
+                    var real_term = specific_terms[1]; // glossary term
+                    var real_code = specific_terms[0]; // glossary id
+                    complex_array[real_code] = real_term;
+                    cp_complex_array[real_code] = real_term;
+                }
 
-            $.ajax({
-                contentType: "application/x-www-form-urlencoded",
-                beforeSend: function(object) {
-                },
-                type: "POST",
-                url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php",
-                data: "glossary_data=true",
-                success: function(datas) {
-                      if (datas.length==0) {
-                          return false;
-                      }
-                      // glossary terms
-                      data_terms=datas.split("[|.|_|.|-|.|]");
-                        var complex_array = new Array();
-                        var cp_complex_array = new Array();
-                        for(i=0;i<data_terms.length;i++) {
-                            specific_terms=data_terms[i].split("__|__|");
-                            var real_term = specific_terms[1]; // glossary term
-                            var real_code = specific_terms[0]; // glossary id
-                            complex_array[real_code] = real_term;
-                            cp_complex_array[real_code] = real_term;
-                        }
-
-                        complex_array.reverse();
+                complex_array.reverse();
 
-                        for (var my_index in complex_array) {
-                            n = complex_array[my_index];
-                            if (n == null) {
-                                n = '';
+                for (var my_index in complex_array) {
+                    n = complex_array[my_index];
+                    if (n == null) {
+                        n = '';
+                    } else {
+                        for (var cp_my_index in cp_complex_array) {
+                            cp_data = cp_complex_array[cp_my_index];
+                            if (cp_data == null) {
+                                cp_data = '';
                             } else {
-                                for (var cp_my_index in cp_complex_array) {
-                                    cp_data = cp_complex_array[cp_my_index];
-                                    if (cp_data == null) {
-                                        cp_data = '';
-                                    } else {
-                                        if (cp_data == n) {
-                                            my_index = cp_my_index;
-                                        }
-                                    }
+                                if (cp_data == n) {
+                                    my_index = cp_my_index;
                                 }
-                                //alert(n + ' ' + my_index);
-                                $("iframe").contents().find('body').removeHighlight().highlight(n,my_index)
-                                //logit_lms(n+ ' - '+my_index, 0);
                             }
                         }
+                        //alert(n + ' ' + my_index);
+                        $("iframe").contents().find('body').removeHighlight().highlight(n,my_index)
+                        //logit_lms(n+ ' - '+my_index, 0);
+                    }
+                }
 
-                      var complex_array = new Array();
+                var complex_array = new Array();
 
-                        //$("iframe").contents().find("body .glossary-ajax").on("click", ".glossary-ajax", function() {
-                        $("iframe").contents().find("body").on("click", ".glossary-ajax", function() {
+                //$("iframe").contents().find("body .glossary-ajax").on("click", ".glossary-ajax", function() {
+                $("iframe").contents().find("body").on("click", ".glossary-ajax", function() {
 
-                        div_show_id="div_show_id";
-                        div_content_id="div_content_id";
+                div_show_id="div_show_id";
+                div_content_id="div_content_id";
 
-                        $("iframe").contents().find("body").append('<div id="div_show_id"><div id="div_content_id">&nbsp;</div></div>');
+                $("iframe").contents().find("body").append('<div id="div_show_id"><div id="div_content_id">&nbsp;</div></div>');
 
-                            show_dialog = $("iframe").contents().find("div#"+div_show_id);
-                            show_description = $("iframe").contents().find("div#"+div_content_id);
+                    show_dialog = $("iframe").contents().find("div#"+div_show_id);
+                    show_description = $("iframe").contents().find("div#"+div_content_id);
 
-                            var $target = $(this);
+                    var $target = $(this);
 
-                            if ($("#learning_path_left_zone").is(':visible') ) {
-                                var extra_left = $("#learning_path_left_zone").width() + 20;
-                            } else {
-                                var extra_left = 0;
-                            }
+                    if ($("#learning_path_left_zone").is(':visible') ) {
+                        var extra_left = $("#learning_path_left_zone").width() + 20;
+                    } else {
+                        var extra_left = 0;
+                    }
 
-                            //$("#"+div_show_id).dialog("destroy");
-                            show_dialog.dialog({
-                                autoOpen: false,
-                                width: 600,
-                                height: 200,
-                                position:  { my: 'left top', at: 'right top', of: $target, offset: extra_left+", 0"},
-                                close: function(){
-                                     show_dialog.remove();
-                                     show_description.remove();
-                                }
-                            });
-                            notebook_id=$(this).attr("name");
-                            data_notebook=notebook_id.split("link");
-
-                            my_glossary_id=data_notebook[1];
-                            $.ajax({
-                                contentType: "application/x-www-form-urlencoded",
-                                type: "POST",
-                                url: "<?php echo api_get_path(WEB_PATH); ?>main/glossary/glossary_ajax_request.php",
-                                data: "glossary_id="+my_glossary_id,
-                                success: function(data) {
-                                        show_description.html(data);
-                                        show_dialog.dialog("open");
-                                }
-                            });
-                      });
-                }
-            });
+                    //$("#"+div_show_id).dialog("destroy");
+                    show_dialog.dialog({
+                        autoOpen: false,
+                        width: 600,
+                        height: 200,
+                        position:  { my: 'left top', at: 'right top', of: $target, offset: extra_left+", 0"},
+                        close: function(){
+                             show_dialog.remove();
+                             show_description.remove();
+                        }
+                    });
+                    notebook_id=$(this).attr("name");
+                    data_notebook=notebook_id.split("link");
+
+                    my_glossary_id=data_notebook[1];
+                    $.ajax({
+                        contentType: "application/x-www-form-urlencoded",
+                        type: "POST",
+                        url: "<?php echo api_get_path(WEB_PATH); ?>main/glossary/glossary_ajax_request.php",
+                        data: "glossary_id="+my_glossary_id,
+                        success: function(data) {
+                            show_description.html(data);
+                            show_dialog.dialog("open");
+                        }
+                    });
+                });
+            }
+        });
     } else {
-         if ('manual') {
-
+        if ('manual') {
             $("iframe").contents().find("body").on("click", ".glossary", function() {
-				is_glossary_name = $(this).html();
+                is_glossary_name = $(this).html();
 
                 div_show_id="div_show_id";
                 div_content_id="div_content_id";
@@ -1862,8 +1896,7 @@ function attach_glossary_into_scorm(type) {
                          show_dialog.dialog("open");
                     }
                 });
-
             });
         }
     }
-}
+}