diff --git a/dokeos_license.txt b/dokeos_license.txt index 8c9d4d38ce..40f804e941 100644 --- a/dokeos_license.txt +++ b/dokeos_license.txt @@ -7,6 +7,7 @@ Copyright (c) 2001 Universite catholique de Louvain (UCL) Copyright (c) 2003-2008 Vrije Universiteit Brussel (VUB) Copyright (c) 2004-2008 Hoogeschool Gent (HoGent) + Copyright (c) Denes Nagy (darkden@freemail.hu) For a full list of contributors detaining copyrights over parts of the Dokeos software, see "documentation/credits.html". The full license can be read in "documentation/license.html". diff --git a/main/inc/lib/tracking.lib.php b/main/inc/lib/tracking.lib.php index 355089c77d..2d289f67a3 100644 --- a/main/inc/lib/tracking.lib.php +++ b/main/inc/lib/tracking.lib.php @@ -92,31 +92,20 @@ class Tracking { function get_time_spent_on_the_course($user_id, $course_code) { // protect datas $user_id = intval($user_id); - $course_code = addslashes($course_code); - + $course_code = addslashes($course_code); $tbl_track_course = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); - - $sql = 'SELECT login_course_date, logout_course_date FROM ' . $tbl_track_course . ' - WHERE user_id = ' . $user_id . ' - AND course_code="' . $course_code . '"'; - + $condition_user = ""; + if (is_array($user_id)) { + $condition_user = " AND user_id IN (".implode(',',$user_id).") "; + } else { + $condition_user = " AND user_id = '$user_id' "; + } + $sql = " SELECT SUM(UNIX_TIMESTAMP(logout_course_date)-UNIX_TIMESTAMP(login_course_date)) as nb_seconds + FROM $tbl_track_course + WHERE course_code='$course_code' $condition_user"; $rs = Database::query($sql,__FILE__,__LINE__); - - $nb_seconds = 0; - - while ($a_connections = Database::fetch_array($rs)) { - - $s_login_date = $a_connections["login_course_date"]; - $s_logout_date = $a_connections["logout_course_date"]; - - $i_timestamp_login_date = strtotime($s_login_date); - $i_timestamp_logout_date = strtotime($s_logout_date); - - $nb_seconds += ($i_timestamp_logout_date - $i_timestamp_login_date); - - } - - return $nb_seconds; + $row = Database::fetch_array($rs); + return $row['nb_seconds']; } function get_first_connection_date($student_id) { @@ -243,120 +232,83 @@ class Tracking { /** * This function gets the score average from all tests in a course by student - * @param int $student_id - User id + * @param int $student_id - or array for multiples User id (array(0=>1,1=>2)) * @param string $course_code - Course id * @return string value (number %) Which represents a round integer about the score average. */ function get_avg_student_exercise_score($student_id, $course_code) { // protect datas - $student_id = Database::escape_string($student_id); $course_code = Database::escape_string($course_code); - // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - - if(!empty($a_course['db_name'])) - { + if(!empty($a_course['db_name'])) { // table definition $tbl_course_quiz = Database::get_course_table(TABLE_QUIZ_TEST,$a_course['db_name']); - $tbl_stats_exercise = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - - //get the list of exercises - $sql = "SELECT id, title FROM $tbl_course_quiz WHERE active <> -1"; - $rs = Database::query($sql, __FILE__, __LINE__); - $count_exe = Database::num_rows($rs); - - if ($count_exe > 0) { - $quiz_avg_total_score = 0; - while($quiz = Database::fetch_array($rs)) { - - // get the score and max score from track_e_exercise - $sql = 'SELECT exe_result , exe_weighting - FROM '.$tbl_stats_exercise.' - WHERE exe_exo_id = '.(int)$quiz['id'].' - AND exe_user_id = '.(int)$student_id.' - AND orig_lp_id = 0 - AND exe_cours_id = "'.Database::escape_string($course_code).'" - AND orig_lp_item_id = 0 - ORDER BY exe_date DESC'; - - $rsAttempt = Database::query($sql, __FILE__, __LINE__); - $nb_attempts = 0; - - $quiz_avg_score = 0; - while ($attempt = Database::fetch_array($rsAttempt)) { - $nb_attempts++; - $exe_weight=$attempt['exe_weighting']; - if ($exe_weight >0) { - $quiz_avg_score += round(($attempt['exe_result']/$exe_weight*100),2); - } - } - if($nb_attempts>0) { - $quiz_avg_score = $quiz_avg_score / $nb_attempts; - } - - $quiz_avg_total_score += $quiz_avg_score; + $tbl_stats_exercise = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $count_quiz = Database::fetch_row(Database::query("SELECT count(id) FROM $tbl_course_quiz WHERE active <> -1",__FILE__,__LINE__)); + $quiz_avg_total_score = 0; + if (!empty($count_quiz[0]) && !empty($student_id)) { + $condition_user = ""; + if (is_array($student_id)) { + $condition_user = " AND exe_user_id IN (".implode(',',$student_id).") "; + } else { + $condition_user = " AND exe_user_id = '$student_id' "; } - return $quiz_avg_total_score/$count_exe; - } - } - else - { - return null; - } - + $sql = "SELECT SUM(exe_result/exe_weighting*100) as avg_score + FROM $tbl_stats_exercise + WHERE exe_exo_id IN (SELECT id FROM $tbl_course_quiz WHERE active <> -1) + $condition_user + AND orig_lp_id = 0 + AND exe_cours_id = '$course_code' + AND orig_lp_item_id = 0 + ORDER BY exe_date DESC"; + $res = Database::query($sql, __FILE__, __LINE__); + $row = Database::fetch_array($res); + $quiz_avg_score = 0; + if (!empty($row['avg_score'])) { + $quiz_avg_score = round($row['avg_score'],2); + } + $count_attempt = Database::fetch_row(Database::query("SELECT count(*) FROM $tbl_stats_exercise WHERE exe_exo_id IN (SELECT id FROM $tbl_course_quiz WHERE active <> -1) $condition_user AND orig_lp_id = 0 AND exe_cours_id = '$course_code' AND orig_lp_item_id = 0 ORDER BY exe_date DESC",__FILE__,__LINE__)); + if(!empty($count_attempt[0])) { + $quiz_avg_score = $quiz_avg_score / $count_attempt[0]; + } + $quiz_avg_total_score = $quiz_avg_score; + return $quiz_avg_total_score/$count_quiz[0]; + } + } + return null; } - - function get_avg_student_progress($student_id, $course_code) { - require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php'); - + function get_avg_student_progress($student_id, $course_code) { // protect datas - $student_id = intval($student_id); $course_code = addslashes($course_code); - // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - - if(!empty($a_course['db_name'])) - { + if (!empty($a_course['db_name'])) { // table definition - $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $a_course['db_name']); - $tbl_course_lp_view_item = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $a_course['db_name']); - $tbl_course_lp_item = Database :: get_course_table(TABLE_LP_ITEM, $a_course['db_name']); - $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $a_course['db_name']); - - //get the list of learning paths - $sql = 'SELECT id FROM ' . $tbl_course_lp; - $rs = Database::query($sql, __FILE__, __LINE__); - $nb_lp = Database::num_rows($rs); + $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $a_course['db_name']); + $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $a_course['db_name']); + $count_lp = Database::fetch_row(Database::query("SELECT count(id) FROM $tbl_course_lp",__FILE__,__LINE__)); $avg_progress = 0; - - if ($nb_lp > 0) { - while ($lp = Database :: fetch_array($rs)) { - // get the progress in learning pathes - $sqlProgress = "SELECT progress - FROM " . $tbl_course_lp_view . " AS lp_view - WHERE lp_view.user_id = " . $student_id . " - AND lp_view.lp_id = " . $lp['id'] . " - "; - $resultItem = Database::query($sqlProgress, __FILE__, __LINE__); - if(Database::num_rows($resultItem)>0) - { - $avg_progress += Database::result($resultItem, 0, 0); - } - } - $avg_progress = round($avg_progress / $nb_lp, 1); - } - - return $avg_progress; - } - else - { - return null; + if (!empty($count_lp[0]) && !empty($student_id)) { + $condition_user = ""; + if (is_array($student_id)) { + $condition_user = " lp_view.user_id IN (".implode(',',$student_id).") AND "; + } else { + $condition_user = " lp_view.user_id = '$student_id' AND "; + } + $sqlProgress = "SELECT SUM(progress) FROM $tbl_course_lp_view AS lp_view WHERE $condition_user lp_view.lp_id IN (SELECT id FROM $tbl_course_lp)"; + $resultItem = Database::query($sqlProgress, __FILE__, __LINE__); + $rowItem = Database::fetch_row($resultItem); + $avg_progress = round($rowItem[0] / $count_lp[0], 1); + return $avg_progress; + } } + return null; } + + /** * This function gets: * 1. The score average from all SCORM Test items in all LP in a course-> All the answers / All the max score. @@ -377,65 +329,71 @@ class Tracking { $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT); $course = CourseManager :: get_course_information($course_code); + if (!empty($course['db_name'])) { - + $tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION,$course['db_name']); $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course['db_name']); $lp_item_table = Database :: get_course_table(TABLE_LP_ITEM,$course['db_name']); $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course['db_name']); $lp_item_view_table = Database :: get_course_table(TABLE_LP_ITEM_VIEW,$course['db_name']); - - $sql_course_lp = 'SELECT id FROM '.$lp_table; - if(count($lp_ids)!=0) { - $sql_course_lp.=' WHERE id IN ('.implode(',',$lp_ids).')'; + + $condition_lp = ""; + if(count($lp_ids) > 0) { + $condition_lp =" WHERE id IN(".implode(',',$lp_ids).") "; } - - $sql_result_lp = Database::query($sql_course_lp, __FILE__, __LINE__); + + $count_row_lp = Database::fetch_row(Database::query("SELECT count(*) FROM $lp_table $condition_lp",__FILE__,__LINE__)); + $lp_scorm_score_total = 0; $lp_scorm_weighting_total = 0; $lp_scorm_result_score_total = 0; $lp_scorm_loop=0; $lp_count = 0; $progress = 0; - - if(Database::num_rows($sql_result_lp)>0){ - //Scorm test - while($a_learnpath = Database::fetch_array($sql_result_lp)) { - - //We get the last view id of this LP (with the higher id) - $sql='SELECT max(id) as id FROM '.$lp_view_table.' - WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"'; - $rs_last_lp_view_id = Database::query($sql, __FILE__, __LINE__); - $lp_view_id = Database::result($rs_last_lp_view_id,0,'id'); // THE view - - if ($lp_view_id != '') { + + if (!empty($count_row_lp[0]) && !empty($student_id)) { + + $condition_user1 = ""; + if (is_array($student_id)) { + $condition_user1 =" AND user_id IN (".implode(',',$student_id).") "; + } else { + $condition_user1 =" AND user_id = '$student_id' "; + } + + $sql = "SELECT max(id) as id, lp_id, user_id FROM $lp_view_table WHERE lp_id IN (SELECT id FROM $lp_table $condition_lp) $condition_user1 GROUP BY lp_id,user_id"; + $rs_last_lp_view_id = Database::query($sql, __FILE__, __LINE__); + + $score_of_scorm_calculate = 0; + if (Database::num_rows($rs_last_lp_view_id) > 0) { + while ($row_lp_view = Database::fetch_array($rs_last_lp_view_id)) { + + $lp_view_id = $row_lp_view['id']; // we get the progress $sql='SELECT progress FROM '.$lp_view_table.' WHERE id="'.$lp_view_id.'"'; + $rs = Database::query($sql, __FILE__, __LINE__); $progress = Database::result($rs,0,'progress'); - + // item's list of an scorm $sql_max_score='SELECT lp_iv.score as score,lp_i.max_score FROM '.$lp_item_view_table.' as lp_iv INNER JOIN '.$lp_item_table.' as lp_i ON lp_i.id = lp_iv.lp_item_id AND lp_i.item_type="sco" - WHERE lp_view_id="'.$lp_view_id.'"'; + WHERE lp_view_id="'.$lp_view_id.'"'; - //$rs = Database::query($sql, __FILE__, __LINE__); - //$sql_max_score='SELECT max_score FROM '.$lp_item_view_table.' WHERE lp_view_id="'.$lp_view_id.'" '; $res_max_score=Database::query($sql_max_score,__FILE__,__LINE__); $count_total_loop=0; $num_rows_max_score=Database::num_rows($res_max_score); - + if ($num_rows_max_score==1) { while ($row_max_score=Database::fetch_array($res_max_score)) { - //echo $row_max_score['score'].' - '.$row_max_score['max_score']; if ($row_max_score['max_score']==0) { //when there's no max score, we assume 100 as the max score, as the SCORM 1.2 says that the value should always be between 0 and 100. $lp_scorm_result_score_total+=($row_max_score['score']/100); $current_value = $row_max_score['score']/100; - + } else { $lp_scorm_result_score_total+=($row_max_score['score']/$row_max_score['max_score']); $current_value = $row_max_score['score']/$row_max_score['max_score']; @@ -443,10 +401,7 @@ class Tracking { $count_total_loop++; } } elseif ($num_rows_max_score > 1) { - //echo ' ----
'; while ($row_max_score=Database::fetch_array($res_max_score)) { - //echo $row_max_score['score'].' - '.$row_max_score['max_score']; - //echo '
'; if ($row_max_score['max_score']==0) { $lp_scorm_result_score_total+=($row_max_score['score']/100); $current_value = $row_max_score['score']/100; @@ -458,126 +413,90 @@ class Tracking { $count_total_loop++; } } - + if ($num_rows_max_score > 0 && ($progress > 0 || $current_value > 0 )) { $lp_count++; } - + if ($count_total_loop==0) { $count_total_loop=1; } $score_of_scorm_calculate=round((($lp_scorm_result_score_total/$count_total_loop)*100),2); - - } else { - $score_of_scorm_calculate = 0; + } - } - - //The next call to a MySQL fetch function, such as mysql_fetch_assoc(), would return that row. - mysql_data_seek($sql_result_lp,0); - - if ($lp_count==0) { - $lp_count=1; - } - + } + if(count($lp_ids)==0 ) { - $score_of_scorm_calculate=round((($score_of_scorm_calculate/$lp_count)),2); + $score_of_scorm_calculate=round((($score_of_scorm_calculate/$count_row_lp[0])),2); } - + $lp_scorm_score_total = $score_of_scorm_calculate; - - //Quizz in a LP - while($a_learnpath = Database::fetch_array($sql_result_lp)) { - //we got the maxscore this is wrong - /* - echo $sql = 'SELECT id as item_id, max_score - FROM '.$lp_item_table.' AS lp_item - WHERE lp_id='.$a_learnpath['id'].' - AND item_type="quiz"'; - */ - - //Path is the exercise id - $sql = 'SELECT path, id as item_id, max_score - FROM '.$lp_item_table.' AS lp_item - WHERE lp_id='.$a_learnpath['id'].' - AND item_type="quiz"'; - - $rsItems = Database::query($sql, __FILE__, __LINE__); - - //We get the last view id of this LP - $sql = "SELECT id FROM $lp_view_table WHERE user_id = '".intval($student_id)."' and lp_id='".intval($a_learnpath['id'])."'"; - //$sql='SELECT max(id) as id FROM '.$lp_view_table.' WHERE lp_id='.$a_learnpath['id'].' AND user_id="'.intval($student_id).'"'; - $rs_last_lp_view_id = Database::query($sql, __FILE__, __LINE__); - $lp_view_id = intval(Database::result($rs_last_lp_view_id,0,'id')); - - $total_score = $total_weighting = 0; - if ($lp_view_id!=0) { - while ($item = Database :: fetch_array($rsItems, 'ASSOC')) { - - // we take the score from a LP because we have lp_view_id - $sql = "SELECT score FROM $lp_item_view_table WHERE lp_item_id = '".(int)$item['item_id']."' and lp_view_id = '".(int)$lp_view_id."' - ORDER BY view_count DESC limit 1"; - - /*$sql = 'SELECT score as student_score - FROM '.$lp_item_view_table.' as lp_view_item - WHERE lp_view_item.lp_item_id = '.$item['item_id'].' - AND lp_view_id = "'.$lp_view_id.'" ';*/ - $rsScores = Database::query($sql, __FILE__, __LINE__); - - // Real max score - this was implemented because of the random exercises - $sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' . - 'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$a_learnpath['id'].'" AND orig_lp_item_id = "'.$item['item_id'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1'; - - $resultLastAttempt = Database::query($sql_last_attempt, __FILE__, __LINE__); - $num = Database :: num_rows($resultLastAttempt); - if ($num > 0){ - if ($num > 1){ - while ($rowLA = Database :: fetch_row($resultLastAttempt)) { - $id_last_attempt = $rowLA[0]; - } - } else { - $id_last_attempt = Database :: result($resultLastAttempt, 0, 0); + + $condition_user2 = ""; + if (is_array($student_id)) { + $condition_user2 =" lp_view.user_id IN (".implode(',',$student_id).") AND "; + } else { + $condition_user2 =" lp_view.user_id = '$student_id' AND "; + } + + //Path is the exercise id + $sql = "SELECT lp_view.id as lp_view_id, lp_view.lp_id as lp_id, lp_item.path, lp_item.id as item_id, lp_item.max_score, lp_view.user_id as user_id + FROM $lp_view_table lp_view + INNER JOIN $lp_item_table lp_item ON lp_item.lp_id = lp_view.lp_id AND item_type='".TOOL_QUIZ."' + WHERE $condition_user2 lp_view.lp_id IN (SELECT id FROM $lp_table $condition_lp)";; + + $rsItems = Database::query($sql, __FILE__, __LINE__); + + $total_score = $total_weighting = 0; + if (Database::num_rows($rsItems) > 0) { + while ($item = Database::fetch_array($rsItems)) { + + $lp_view_id = $item['lp_view_id']; + $lp_item_id = $item['item_id']; + $lp_id = $item['lp_id']; + $user_id = $item['user_id']; + + // we take the score from a LP because we have lp_view_id + $sql = "SELECT score FROM $lp_item_view_table WHERE lp_item_id = '$lp_item_id' and lp_view_id = '$lp_view_id' + ORDER BY view_count DESC limit 1"; + + $rsScores = Database::query($sql, __FILE__, __LINE__); + // Real max score - this was implemented because of the random exercises + $sql_last_attempt = 'SELECT exe_id FROM '. $tbl_stats_exercices. ' ' . + 'WHERE exe_exo_id="' .$item['path']. '" AND exe_user_id="' . $user_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$lp_item_id.'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1'; + + $resultLastAttempt = Database::query($sql_last_attempt, __FILE__, __LINE__); + $num = Database :: num_rows($resultLastAttempt); + if ($num > 0){ + if ($num > 1){ + while ($rowLA = Database :: fetch_row($resultLastAttempt)) { + $id_last_attempt = $rowLA[0]; } + } else { + $id_last_attempt = Database :: result($resultLastAttempt, 0, 0); } + } - $sql = "SELECT SUM(t.ponderation) as maxscore from ( 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) where exe_id ='$id_last_attempt' ) as t"; - - $result = Database::query($sql, __FILE__, __LINE__); - $row_max_score = Database :: fetch_array($result); - $maxscore = $row_max_score['maxscore']; - if ($maxscore=='') { - $maxscore = $item['max_score']; + $sql = "SELECT SUM(t.ponderation) as maxscore from ( 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) where exe_id ='$id_last_attempt' ) as t"; + + $result = Database::query($sql, __FILE__, __LINE__); + $row_max_score = Database :: fetch_array($result); + $maxscore = $row_max_score['maxscore']; + if ($maxscore=='') { + $maxscore = $item['max_score']; + } + if(Database::num_rows($rsScores)>0) { + $total_score = Database::result($rsScores, 0, 0); + $total_weighting += $maxscore; + if($total_weighting>0 && $maxscore>0) { + $lp_scorm_score_total += ($total_score/$maxscore)*100; + $lp_scorm_weighting_total+=100; } - // not right! - /*if(Database::num_rows($rsScores)>0) { - $total_score += Database::result($rsScores, 0, 0); - //echo $total_weighting += $item['max_score']; - $total_weighting += $maxscore; - - if($total_weighting>0) { - //echo ($total_score/$total_weighting)*100; - $lp_scorm_score_total += ($total_score/$total_weighting)*100; - $lp_scorm_weighting_total+=100; - } - }*/ - - if(Database::num_rows($rsScores)>0) { - $total_score = Database::result($rsScores, 0, 0); - //echo $total_weighting += $item['max_score']; - $total_weighting += $maxscore; - if($total_weighting>0 && $maxscore>0) { - //echo $total_score.' - '.$maxscore; echo '
'; - //echo $lp_scorm_score_total += ($total_score/$total_weighting)*100; - $lp_scorm_score_total += ($total_score/$maxscore)*100; - $lp_scorm_weighting_total+=100; - } - } - } + } } - } - } - + } + } $totalScore = $lp_scorm_score_total; $pourcentageScore = 0; if($lp_scorm_weighting_total>0) { @@ -589,11 +508,10 @@ class Tracking { return $score_of_scorm_calculate; } else { return null; - } - } else { - return null; - } + } + } } + /** * gets the list of students followed by coach @@ -619,7 +537,7 @@ class Tracking { if ($_configuration['multiple_access_urls']==true) { $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); - if ($access_url_id != -1){ + if ($access_url_id != -1) { $sql = 'SELECT scu.id_session, scu.course_code FROM ' . $tbl_session_course_user . ' scu INNER JOIN '.$tbl_session_rel_access_url.' sru ON (scu.id_session=sru.session_id) @@ -974,56 +892,49 @@ class Tracking { function count_student_assignments($student_id, $course_code) { require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php'); - // protect datas - $student_id = intval($student_id); - $course_code = addslashes($course_code); - + // protect datas + $course_code = Database::escape_string($course_code); // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - - if(!empty($a_course['db_name'])) - { + if (!empty($a_course['db_name'])) { // table definition - $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']); - $sql = 'SELECT 1 - FROM ' . $tbl_item_property . ' - WHERE insert_user_id=' . $student_id . ' - AND tool="work"'; - + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $a_course['db_name']); + $condition_user = ""; + if (is_array($student_id)) { + $condition_user = " AND insert_user_id IN (".implode(',',$student_id).") "; + } else { + $condition_user = " AND insert_user_id = '$student_id' "; + } + $sql = "SELECT count(tool) FROM $tbl_item_property WHERE tool='work' $condition_user "; $rs = Database::query($sql, __LINE__, __FILE__); - return Database::num_rows($rs); - } - else - { - return null; + $row = Database::fetch_row($rs); + return $row[0]; } + return null; } function count_student_messages($student_id, $course_code) { require_once (api_get_path(LIBRARY_PATH) . 'course.lib.php'); // protect datas - $student_id = intval($student_id); $course_code = addslashes($course_code); - // get the informations of the course $a_course = CourseManager :: get_course_information($course_code); - - if(!empty($a_course['db_name'])) - { + if (!empty($a_course['db_name'])) { // table definition - $tbl_messages = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']); - $sql = 'SELECT 1 - FROM ' . $tbl_messages . ' - WHERE poster_id=' . $student_id; - + $tbl_messages = Database :: get_course_table(TABLE_FORUM_POST, $a_course['db_name']); + $condition_user = ""; + if (is_array($student_id)) { + $condition_user = " WHERE poster_id IN (".implode(',',$student_id).") "; + } else { + $condition_user = " WHERE poster_id = '$student_id' "; + } + $sql = "SELECT count(post_id) FROM $tbl_messages $condition_user "; $rs = Database::query($sql, __LINE__, __FILE__); - return Database::num_rows($rs); - } - else - { - return null; - } + $row = Database::fetch_row($rs); + return $row[0]; + } + return null; } /** @@ -1297,8 +1208,8 @@ class Tracking { * @param string the course id */ function get_average_test_scorm_and_lp ($user_id,$course_id) { - //the score inside the Reporting table - + + //the score inside the Reporting table $course_info=api_get_course_info($course_id); $lp_table = Database :: get_course_table(TABLE_LP_MAIN,$course_info['dbName']); $lp_view_table = Database :: get_course_table(TABLE_LP_VIEW,$course_info['dbName']); @@ -1358,12 +1269,11 @@ class Tracking { $average_data1=0; $count_loop++; } - if ((int)$count_loop > 0) { $avg_student_score = round(($average_data_sum / $count_loop * 100), 2); } - return $avg_student_score; } + } ?> diff --git a/main/mySpace/index.php b/main/mySpace/index.php index f6c856e8d1..3d25bd2e0f 100755 --- a/main/mySpace/index.php +++ b/main/mySpace/index.php @@ -48,7 +48,8 @@ $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE); $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER); $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER); $tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN); - +$tbl_track_cours_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + /******************** * FUNCTIONS @@ -435,16 +436,14 @@ if ($view == 'coach') { '; } } - echo '
 
'; if (api_is_allowed_to_create_course() && $view == 'teacher') { + if ($nb_teacher_courses) { - - $table = new SortableTable('tracking_list_course', 'count_teacher_courses'); + $table = new SortableTable('courses', 'get_number_of_courses' ,'get_course_data'); $parameters['view'] = 'teacher'; $parameters['class'] = 'data_table'; - $table->set_additional_parameters($parameters); $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"'); $table -> set_header(1, get_lang('NbStudents'), false); @@ -465,98 +464,8 @@ if (api_is_allowed_to_create_course() && $view == 'teacher') { get_lang('AvgExercisesScore', ''), get_lang('AvgMessages', ''), get_lang('AvgAssignments', '') - ); - - $a_course_students = array(); - - foreach ($courses as $course) { - $course_code = $course['course_code']; - $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0; - - // students directly subscribed to the course - $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code'"; - $rs = Database::query($sql, __FILE__, __LINE__); - while ($row = Database::fetch_array($rs)) { - $nb_students_in_course++; - - // tracking datas - $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code); - $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code); - $avg_score_in_exercise += Tracking :: get_avg_student_exercise_score ($row['user_id'], $course_code); - $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code); - $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code); - $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code); - $a_course_students[] = $row['user_id']; - } - - // students subscribed to the course through a session - if (api_get_setting('use_session_mode') == 'true') { - $sql = 'SELECT id_user as user_id - FROM '.$tbl_session_course_user.' - WHERE course_code="'.addslashes($course_code).'" ORDER BY course_code'; - $rs = Database::query($sql, __FILE__, __LINE__); - while ($row = Database::fetch_array($rs)) { - if (!in_array($row['user_id'], $a_course_students)) { - $nb_students_in_course++; - - // tracking datas - $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code); - $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code); - $avg_score_in_exercise += Tracking :: get_avg_student_exercise_score ($row['user_id'], $course_code); - $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code); - $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code); - $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code); - $a_course_students[] = $row['user_id']; - } - } - } - - if ($nb_students_in_course > 0) { - $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course); - $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2); - $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2); - $avg_score_in_exercise = round($avg_score_in_exercise / $nb_students_in_course, 2); - $avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course, 2); - $avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course, 2); - } else { - $avg_time_spent_in_course = null; - $avg_progress_in_course = null; - $avg_score_in_course = null; - $avg_score_in_exercise = null; - $avg_messages_in_course = null; - $avg_assignments_in_course = null; - } - - $table_row = array(); - $table_row[] = $course['title']; - $table_row[] = $nb_students_in_course; - $table_row[] = $avg_time_spent_in_course; - $table_row[] = is_null($avg_progress_in_course) ? '' : $avg_progress_in_course.'%'; - $table_row[] = is_null($avg_score_in_course) ? '' : $avg_score_in_course.'%'; - $table_row[] = is_null($avg_score_in_exercise) ? '' : $avg_score_in_exercise.'%'; - $table_row[] = $avg_messages_in_course; - $table_row[] = $avg_assignments_in_course; - //set the "from" value to know if I access the Reporting by the Dokeos tab or the course link - $table_row[] = '
'; - - $csv_content[] = array( - api_html_entity_decode($course['title'], ENT_QUOTES, $charset), - $nb_students_in_course, - $avg_time_spent_in_course, - is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%', - is_null($avg_score_in_course) ? null : $avg_score_in_course.'%', - is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%', - $avg_messages_in_course, - $avg_assignments_in_course, - ); - - $table -> addRow($table_row, 'align="right"'); - - $a_course_students = array(); - } - $table -> updateColAttributes(0, array('align' => 'left')); - $table -> updateColAttributes(7, array('align' => 'center')); - $table -> display(); + ); + $table->display(); } } @@ -566,7 +475,6 @@ if ($is_platform_admin && $view == 'admin') { if ($_GET['display'] == 'useroverview') { echo ' | '.get_lang('ExportUserOverviewOptions').''; } - if ($_GET['display'] === 'useroverview') { display_tracking_user_overview(); } else { @@ -584,7 +492,6 @@ if ($is_platform_admin && $view == 'admin') { } else { $order = array(0 => 'lastname', 1 => 'firstname', 2 => ($sort_by_first_name ? 'firstname' : 'lastname'), 3 => 'login_date', 4 => ($sort_by_first_name ? 'firstname' : 'lastname'), 5 => ($sort_by_first_name ? 'firstname' : 'lastname')); } - $table = new SortableTable('tracking_list_coaches', 'count_coaches', null, ($is_western_name_order xor $sort_by_first_name) ? 1 : 0); $parameters['view'] = 'admin'; $table->set_additional_parameters($parameters); @@ -629,9 +536,8 @@ if ($is_platform_admin && $view == 'admin') { $sqlCoachs = "SELECT DISTINCT scu.id_user as id_coach, user_id, lastname, firstname, MAX(login_date) as login_date FROM $tbl_user, $tbl_session_course_user scu, $tbl_track_login WHERE scu.id_user=user_id AND scu.status=2 AND login_user_id=user_id - GROUP BY user_id "; - // ORDER BY login_date ".$tracking_direction; - + GROUP BY user_id "; + if ($_configuration['multiple_access_urls'] == true) { $tbl_session_rel_access_url = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); $access_url_id = api_get_current_access_url_id(); @@ -642,14 +548,12 @@ if ($is_platform_admin && $view == 'admin') { GROUP BY user_id "; } } - if (!empty($order[$tracking_column])) { $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction; } $result_coaches = Database::query($sqlCoachs, __FILE__, __LINE__); $total_no_coaches = Database::num_rows($result_coaches); - $global_coaches = array(); while ($coach = Database::fetch_array($result_coaches)) { $global_coaches[$coach['user_id']] = $coach; @@ -1206,3 +1110,104 @@ function get_user_overview_export_extra_fields($user_id) { $extra_data = UserManager::get_extra_user_data($user_id, true); return $extra_data; } +/** + * Get number of courses for sortable with pagination + * @return int + */ +function get_number_of_courses() { + global $courses; + return count($courses); +} +/** + * Get data for courses list in sortable with pagination + * @return array + */ +function get_course_data($from, $number_of_items, $column, $direction) { + + global $courses, $csv_content, $charset ; + global $tbl_course, $tbl_course_user, $tbl_track_cours_access, $tbl_session_course_user; + + $a_course_students = array(); + $course_data = array(); + $arr_course = $courses; + foreach ($arr_course as &$cours) { + $cours = "'{$cours[course_code]}'"; + } + + // get all courses with limit + $sql = "SELECT course.code as col1, course.title as col2 + FROM $tbl_course course + WHERE course.code IN (".implode(',',$arr_course).")"; + if (!in_array($direction, array('ASC','DESC'))) $direction = 'ASC'; + + $column = intval($column); + $from = intval($from); + $number_of_items = intval($number_of_items); + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + + $res = Database::query($sql, __FILE__, __LINE__); + while ($row_course = Database::fetch_row($res)) { + + $course_code = $row_course[0]; + $course_info = api_get_course_info($course_code); + $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = $avg_score_in_exercise = 0; + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_info['dbName']); + $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST, $course_info['dbName']); + $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $course_info['dbName']); + $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $course_info['dbName']); + + // students directly subscribed to the course + $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code' + UNION DISTINCT SELECT id_user as user_id FROM $tbl_session_course_user srcu WHERE srcu. course_code='$course_code'"; + $rs = Database::query($sql, __FILE__, __LINE__); + $users = array(); + while ($row = Database::fetch_array($rs)) { + $users[] = $row['user_id']; + } + if (count($users) > 0) { + $nb_students_in_course = count($users); + $avg_assignments_in_course = Tracking::count_student_assignments($users, $course_code); + $avg_messages_in_course = Tracking::count_student_messages($users, $course_code); + $avg_time_spent_in_course = Tracking::get_time_spent_on_the_course($users, $course_code); + $avg_progress_in_course = Tracking::get_avg_student_progress($users, $course_code); + $avg_score_in_course = Tracking :: get_avg_student_score($users, $course_code); + $avg_score_in_exercise = Tracking::get_avg_student_exercise_score($users, $course_code); + + $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course); + $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course, 2); + $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course, 2); + $avg_score_in_exercise = round($avg_score_in_exercise / $nb_students_in_course, 2); + } else { + $avg_time_spent_in_course = null; + $avg_progress_in_course = null; + $avg_score_in_course = null; + $avg_score_in_exercise = null; + $avg_messages_in_course = null; + $avg_assignments_in_course = null; + } + $table_row = array(); + $table_row[] = $row_course[1]; + $table_row[] = $nb_students_in_course; + $table_row[] = $avg_time_spent_in_course; + $table_row[] = is_null($avg_progress_in_course) ? '' : $avg_progress_in_course.'%'; + $table_row[] = is_null($avg_score_in_course) ? '' : $avg_score_in_course.'%'; + $table_row[] = is_null($avg_score_in_exercise) ? '' : $avg_score_in_exercise.'%'; + $table_row[] = $avg_messages_in_course; + $table_row[] = $avg_assignments_in_course; + //set the "from" value to know if I access the Reporting by the Dokeos tab or the course link + $table_row[] = '
'; + $csv_content[] = array( + api_html_entity_decode($row_course[1], ENT_QUOTES, $charset), + $nb_students_in_course, + $avg_time_spent_in_course, + is_null($avg_progress_in_course) ? null : $avg_progress_in_course.'%', + is_null($avg_score_in_course) ? null : $avg_score_in_course.'%', + is_null($avg_score_in_exercise) ? null : $avg_score_in_exercise.'%', + $avg_messages_in_course, + $avg_assignments_in_course, + ); + $course_data[] = $table_row; + } + return $course_data; +} \ No newline at end of file diff --git a/main/newscorm/learnpath.class.php b/main/newscorm/learnpath.class.php index 2c059279f5..e199209f94 100644 --- a/main/newscorm/learnpath.class.php +++ b/main/newscorm/learnpath.class.php @@ -1786,9 +1786,9 @@ class learnpath { ' ' . "\n" . - ' ' . "\n" . + ' ' . "\n" . - ' ' . "\n" . + ' ' . "\n" . //' '."\n" . @@ -1814,9 +1814,9 @@ class learnpath { ' ' . "\n" . - ' ' . "\n" . + ' ' . "\n" . - ' ' . "\n" . + ' ' . "\n" . // ' '."\n" . @@ -2648,6 +2648,28 @@ 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 + * @return string A JS array vairiable construction + */ + function get_items_details_as_js($varname='olms.lms_item_types') { + if ($this->debug > 0) { + error_log('New LP - In learnpath::get_items_details_as_js()', 0); + } + $toc = $varname.' = new Array();'; + //echo "
".print_r($this->items,true)."
"; + foreach ($this->ordered_items as $item_id) { + if ($this->debug > 2) { + error_log('New LP - learnpath::get_items_details_as_js(): getting info for item ' . $item_id, 0); + } + $toc.= $varname."['i$item_id'] = '".$this->items[$item_id]->get_type()."';"; + } + if ($this->debug > 2) { + error_log('New LP - In learnpath::get_items_details_as_js() - TOC array: ' . print_r($toc, true), 0); + } + return $toc; + } /** * Gets the learning path type * @param boolean Return the name? If false, return the ID. Default is false. @@ -2714,70 +2736,6 @@ class learnpath { } return $list; } - /** - * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display - * @return string HTML TOC ready to display - */ - /*function get_html_toc() - { - if($this->debug>0){error_log('New LP - In learnpath::get_html_toc()',0);} - $list = $this->get_toc(); - //echo $this->current; - //$parent = $this->items[$this->current]->get_parent(); - //if(empty($parent)){$parent = $this->ordered_items[$this->items[$this->current]->get_previous_index()];} - $html = '
'."\n" ; - // " onchange=\"javascript:document.getElementById('toc_$parent').focus();\">\n"; - require_once('resourcelinker.inc.php'); - - //temp variables - $mycurrentitemid = $this->get_current_item_id(); - - foreach($list as $item) - { - if($this->debug>2){error_log('New LP - learnpath::get_html_toc(): using item '.$item['id'],0);} - //TODO complete this - $icon_name = array('not attempted' => '../img/notattempted.gif', - 'incomplete' => '../img/incomplete.gif', - 'failed' => '../img/failed.gif', - 'completed' => '../img/completed.gif', - 'passed' => '../img/passed.gif', - 'succeeded' => '../img/succeeded.gif', - 'browsed' => '../img/completed.gif'); - - $style = 'scorm_item'; - if($item['id'] == $this->current){ - $style = 'scorm_item_highlight'; - } - //the anchor will let us center the TOC on the currently viewed item &^D - $html .= '
' . - ''.substr($item['status'],0,1).''; - - //$title = htmlspecialchars($item['title'],ENT_QUOTES,$this->encoding); - $title = $item['title']; - if(empty($title)){ - $title = rl_get_resource_name(api_get_course_id(),$this->get_id(),$item['id']); - $title = htmlspecialchars($title,ENT_QUOTES,$this->encoding); - } - if(empty($title))$title = '-'; - - if($item['type']!='dokeos_chapter' and $item['type']!='dir'){ - //$html .= "".$title."" ; - $url = $this->get_link('http',$item['id']); - //$html .= ''.$title.'' ; - //$html .= ''.$title.'' ; - $html .= ''.$title.'' ; - }else{ - $html .= $title; - } - $html .= "
\n"; - } - $html .= "
\n"; - return $html; - }*/ - /** * Uses the table generated by get_toc() and returns an HTML-formatted string ready to display * @return string HTML TOC ready to display @@ -2880,7 +2838,7 @@ class learnpath { //$html .= ''.$title.'' ; // background:#aaa; - $html .= '' . stripslashes($title) . ''; diff --git a/main/newscorm/lp_ajax_initialize.php b/main/newscorm/lp_ajax_initialize.php new file mode 100644 index 0000000000..d7b1bbb0dc --- /dev/null +++ b/main/newscorm/lp_ajax_initialize.php @@ -0,0 +1,173 @@ + + */ +/** + * Script + */ +//flag to allow for anonymous user - needs to be set before global.inc.php +$use_anonymous = true; +// name of the language file that needs to be included +$language_file[] = 'learnpath'; +require_once('back_compat.inc.php'); +/** + * 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) +{ + $debug=0; + $return = ''; + if($debug>0){error_log('In initialize_item('.$lp_id.','.$user_id.','.$view_id.','.$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; + } + } + $mylp->set_current_item($next_item); + if ($debug>1) {error_log('In {default} - item is '.$new_item_id,0);} + $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[$next_item])) { + $mylpi = & $mylp->items[$next_item]; + } else { + if($debug>1){error_log('In switch_item_details - generating new item object',0);} + $mylpi =& new learnpathItem($next_item,$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); + } + $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';" ; + /* + * 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);} + //$_SESSION['scorm_item_id'] = $new_item_id;//Save the new item ID for the exercise tool to use + //$_SESSION['lpobject'] = serialize($mylp); + return $return; +} +echo initialize_item($_POST['lid'],$_POST['uid'],$_POST['vid'],$_POST['iid']); \ No newline at end of file diff --git a/main/newscorm/lp_ajax_save_item.php b/main/newscorm/lp_ajax_save_item.php index 22ca9c1007..58b6b4ff04 100755 --- a/main/newscorm/lp_ajax_save_item.php +++ b/main/newscorm/lp_ajax_save_item.php @@ -141,7 +141,7 @@ function save_item($lp_id,$user_id,$view_id,$item_id,$score=-1,$max=-1,$min=-1,$ if($mylpi->get_type()!='sco') { //if this object's JS status has not been updated by the SCORM API, update now //$objResponse->addScript("lesson_status='".$mystatus."';"); - $return .= "lesson_status='".$mystatus."';"; + $return .= "olms.lesson_status='".$mystatus."';"; } //$objResponse->addScript("update_toc('".$mystatus."','".$item_id."');"); $return .= "update_toc('".$mystatus."','".$item_id."');"; diff --git a/main/newscorm/lp_ajax_start_timer.php b/main/newscorm/lp_ajax_start_timer.php old mode 100755 new mode 100644 index 4a2dabca9c..d8ddb1c41a --- a/main/newscorm/lp_ajax_start_timer.php +++ b/main/newscorm/lp_ajax_start_timer.php @@ -16,6 +16,6 @@ function start_timer() $time = time(); //$objResponse->addScript("asset_timer='$time';asset_timer_total=0;"); //return $objResponse; - return "asset_timer='$time';asset_timer_total=0;"; + return "olms.asset_timer='$time';olms.asset_timer_total=0;"; } echo start_timer(); \ No newline at end of file diff --git a/main/newscorm/lp_ajax_switch_item.php b/main/newscorm/lp_ajax_switch_item.php index 6326ad0290..9433c02026 100644 --- a/main/newscorm/lp_ajax_switch_item.php +++ b/main/newscorm/lp_ajax_switch_item.php @@ -140,35 +140,38 @@ function switch_item_details($lp_id,$user_id,$view_id,$current_item,$next_item) if (!empty($myistring)) { $myistring = substr($myistring,1); } - //$objResponse->addScript( + /* + * 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 dokeos learning path tracking. + */ $return .= - "score=".$myscore.";" . - "max=".$mymax.";" . - "min=".$mymin.";" . - "lesson_status='".$mylesson_status."';" . - "lesson_location='".$mylesson_location."';" . - "session_time='".$mysession_time."';" . - "suspend_data='".$mysuspend_data."';" . - "total_time = '".$mytotal_time."';" . - "mastery_score = '".$mymastery_score."';" . - "max_time_allowed = '".$mymax_time_allowed."';" . - "launch_data = '".$mylaunch_data."';" . - "interactions = new Array(".$myistring.");" . - "item_objectives = new Array();" . - "G_lastError = 0;" . - "G_LastErrorMessage = 'No error';"; - //); + "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';" ; /* * 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 @@ -187,48 +190,41 @@ function switch_item_details($lp_id,$user_id,$view_id,$current_item,$next_item) $myobjectives_count = $mylpi->get_objectives_count(); $mycore_exit = $mylpi->get_core_exit(); - //$objResponse->addScript( $return .= - "saved_lesson_status='not attempted';" . - "lms_lp_id=".$lp_id.";" . - "lms_item_id=".$new_item_id.";" . - "lms_old_item_id=0;" . - "lms_been_synchronized=0;" . - "lms_initialized=0;" . - "lms_total_lessons=".$mytotal.";" . - "lms_complete_lessons=".$mycomplete.";" . - "lms_progress_bar_mod='".$myprogress_mode."';" . - "lms_view_id=".$view_id.";" . - "lms_user_id=".$user_id.";" . - "next_item=".$new_item_id.";" . //this one is very important to replace possible literal strings - "lms_next_item=".$mynext.";" . - "lms_previous_item=".$myprevious.";" . - "lms_item_type = '".$myitemtype."';" . - "lms_item_credit = '".$mycredit."';" . - "lms_item_lesson_mode = '".$mylesson_mode."';" . - "lms_item_launch_data = '".$mylaunch_data."';" . - "lms_item_interactions_count = '".$myinteractions_count."';" . - "lms_item_objectives_count = '".$myinteractions_count."';" . - "lms_item_core_exit = '".$mycore_exit."';" . - "asset_timer = 0;"; + //"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;"; //); - //$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');"); $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');"; + "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);} - //$objResponse->addScript("update_message_frame('".str_replace("'","\'",htmlentities($mylp->error))."');"); - $return .= "update_message_frame('".str_replace("'","\'",api_htmlentities($mylp->error, ENT_QUOTES, api_get_system_encoding()))."');"; $_SESSION['scorm_item_id'] = $new_item_id;//Save the new item ID for the exercise tool to use $_SESSION['lpobject'] = serialize($mylp); return $return; //return $objResponse; } -echo switch_item_details($_GET['lid'],$_GET['uid'],$_GET['vid'],$_GET['iid'],$_GET['next']); +echo switch_item_details($_POST['lid'],$_POST['uid'],$_POST['vid'],$_POST['iid'],$_POST['next']); \ No newline at end of file diff --git a/main/newscorm/lp_ajax_switch_item_toc.php b/main/newscorm/lp_ajax_switch_item_toc.php new file mode 100644 index 0000000000..2f22ee076c --- /dev/null +++ b/main/newscorm/lp_ajax_switch_item_toc.php @@ -0,0 +1,186 @@ + + */ +/** + * Script + */ +//flag to allow for anonymous user - needs to be set before global.inc.php +$use_anonymous = true; +// name of the language file that needs to be included +$language_file[] = 'learnpath'; +require_once('back_compat.inc.php'); +/** + * 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(); + } + //$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(); + 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, Dokeos 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; + //return $objResponse; + } +echo switch_item_toc($_POST['lid'],$_POST['uid'],$_POST['vid'],$_POST['iid'],$_POST['next']); \ No newline at end of file diff --git a/main/newscorm/lp_view.php b/main/newscorm/lp_view.php index 1e672ac228..9fd484ba5c 100644 --- a/main/newscorm/lp_view.php +++ b/main/newscorm/lp_view.php @@ -71,16 +71,14 @@ $my_style=$platform_theme; Header ----------------------------------------------------------- */ -//$htmlHeadXtra[] = ''; -//$htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/')."\n"; $htmlHeadXtra[] = ''; //jQuery -$htmlHeadXtra[] = ''; $htmlHeadXtra[] = ' - + initialLeftZoneHeight = document.getElementById('learning_path_toc').offsetHeight; + initialRightZoneHeight = document.getElementById('learning_path_right_zone').offsetHeight; + docHeight = document.body.clientHeight; + leftZoneHeightOccupied = docHeight - initialLeftZoneHeight; + rightZoneHeightOccupied = docHeight - initialRightZoneHeight; + document.body.style.overflow = 'hidden'; + updateContentHeight(); +} +window.onresize = updateContentHeight; +--> + + - - - - -
- -
+?> + +
+
- -
- - + +
+
-
-
get_preview_image()!=''): ?> - + get_preview_image()!='') { $picture = getimagesize(api_get_path(SYS_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image()); - if($picture['1'] < 96) $style = ' style="padding-top:'.((94 -$picture['1'])/2).'px;" '; + if($picture['1'] < 96) { $style = ' style="padding-top:'.((94 -$picture['1'])/2).'px;" '; } $size = ($picture['0'] > 104 && $picture['1'] > 96 )? ' width="104" height="96" ': $style; - $flie = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image(); - echo ''; - ?> -
-
+ $my_path = api_get_path(WEB_COURSE_PATH).api_get_course_path().'/upload/learning_path/images/'.$_SESSION['oLP']->get_preview_image(); + echo ''; + } else { + echo Display :: display_icon('unknown_250_100.jpg', ' '); + } + ?> + +
+
+
+ +
+ get_author() ?>
-
- -
- get_author() ?> -
- - - -
> - -
- - - -
-
get_html_toc(); ?> - - -
-
-
.
+ + +
> +
- + + + +
+
get_html_toc(); ?> + + scorm_debug)) { //only show log ?> + +
+
+
.
+
+ + +
- -
- - - +
- + - -
+ +
- - +
+ + initialLeftZoneHeight = document.getElementById('learning_path_toc').offsetHeight; + initialRightZoneHeight = document.getElementById('learning_path_right_zone').offsetHeight; + docHeight = document.body.clientHeight; + leftZoneHeightOccupied = docHeight - initialLeftZoneHeight; + rightZoneHeightOccupied = docHeight - initialRightZoneHeight; + document.body.style.overflow = 'hidden'; + updateContentHeight(); +} +window.onresize = updateContentHeight; +--> + + +$_setting['show_navigation_menu'] = $save_setting; \ No newline at end of file diff --git a/main/newscorm/scorm_api.php b/main/newscorm/scorm_api.php index ec6c36468a..bb390e2f12 100755 --- a/main/newscorm/scorm_api.php +++ b/main/newscorm/scorm_api.php @@ -1,26 +1,6 @@ @@ -28,7 +8,6 @@ * @version v 1.0 * @access public * @package dokeos.learnpath.scorm -============================================================================== */ /** * This script is divided into three sections. @@ -38,9 +17,7 @@ * and frames refresh */ /* -============================================================================== INIT SECTION -============================================================================== */ // if you open the imsmanifest.xml via local machine (f.ex.: file://c:/...), then the Apiwrapper.js @@ -61,21 +38,20 @@ require_once('scorm.class.php'); $file = (empty($_SESSION['file'])?'':$_SESSION['file']); $oLP = unserialize($_SESSION['lpobject']); $oItem = $oLP->items[$oLP->current]; -if(!is_object($oItem)){ +if (!is_object($oItem)) { error_log('New LP - scorm_api - Could not load oItem item',0); exit; } $autocomplete_when_80pct = 0; /* -============================================================================== - JavaScript Functions -============================================================================== -*/ -?>var scorm_logs='scorm_debug) or !api_is_course_admin())?'0':'3');?>'; //debug log level for SCORM. 0 = none, 1=light, 2=a lot, 3=all - displays logs in log frame + * JavaScript Functions + */ +?>var scorm_logs=scorm_debug) or !api_is_course_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 //logit_lms('scormfunctions.php included',0); +// API Object initialization (eases access later on) function APIobject() { this.LMSInitialize=LMSInitialize; //for Scorm 1.2 this.Initialize=LMSInitialize; //for Scorm 1.3 @@ -94,23 +70,22 @@ function APIobject() { this.LMSGetDiagnostic=LMSGetDiagnostic; this.GetDiagnostic=LMSGetDiagnostic; this.Terminate=Terminate; //only in Scorm 1.3 - this.save_asset = dokeos_save_asset; + this.save_asset = lms_save_asset; this.void_save_asset = dokeos_void_save_asset; } -//it is not sure that the scos use the above declarations - -API = new APIobject(); //for scorm 1.2 -api = API; -//api = new APIobject(); //for scorm 1.2 -API_1484_11 = new APIobject(); //for scorm 1.3 -api_1484_11 = API_1484_11; -//api_1484_11 = new APIobject(); //for scorm 1.3 +// it is not sure that the scos use the above declarations. The following +// multiple declarations are to make sure we have an API object for each type of +// SCORM +var API = new APIobject(); //for scorm 1.2 +var api = API; +var API_1484_11 = new APIobject(); //for scorm 1.3 +var api_1484_11 = API_1484_11; -// Error codes +// SCORM-specific Error codes var G_NoError = 0; var G_GeneralException = 101; -var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document +var G_ServerBusy = 102; // this is not in the Scorm1.2_Runtime document var G_InvalidArgumentError = 201; var G_ElementCannotHaveChildren = 202; var G_ElementIsNotAnArray = 203; @@ -121,122 +96,136 @@ var G_ElementIsReadOnly = 403; var G_ElementIsWriteOnly = 404; var G_IncorrectDataType = 405; -// Error messages -var G_NoErrorMessage = ''; -var G_GeneralExceptionMessage = 'General Exception'; -var G_ServerBusyMessage = 'Server busy'; // this is not in the Scorm1.2_Runtime document -var G_InvalidArgumentErrorMessage = 'Invalid argument error'; -var G_ElementCannotHaveChildrenMessage = 'Element cannot have children'; -var G_ElementIsNotAnArrayMessage = 'Element not an array. Cannot have count'; -var G_NotInitializedMessage = 'Not initialized'; -var G_NotImplementedErrorMessage = 'Not implemented error'; -var G_InvalidSetValueMessage = 'Invalid set value, element is a keyword'; -var G_ElementIsReadOnlyMessage = 'Element is read only'; -var G_ElementIsWriteOnlyMessage = 'Element is write only'; -var G_IncorrectDataTypeMessage = 'Incorrect Data Type'; - -var G_LastError = G_NoError ; -var G_LastErrorMessage = 'No error'; -//this is not necessary and is only provided to make bad Articulate contents shut up (and not trigger useless JS messages) -var G_LastErrorString = 'No error'; -status_info=new Array(); -var commit = false ; - -var variables_scorm = new Array('cmi.core.score.raw','cmi.core.score.max','cmi.core.score.min','cmi.core.lesson_location', -'cmi.core.lesson_status','cmi.completion_status','cmi.core.session_time','cmi.score.scaled','cmi.success_status', -'cmi.suspend_data','cmi.core.exit','interactions'); - -var variable_to_send=new Array(); -var updatetable_to_list=new Array(); -var info_of_variable_to_send=new Array(); - -//Strictly scorm variables -var score=get_score();?>; -var max='get_max();?>'; -var min='get_min();?>'; -var lesson_status='get_status();?>'; -var session_time='get_scorm_time('js');?>'; -var suspend_data = 'get_suspend_data();?>'; -var lesson_location = 'get_lesson_location();?>'; -var total_time = 'get_scorm_time('js');?>'; -var mastery_score = 'get_mastery_score();?>'; -var launch_data = 'get_launch_data();?>'; -var max_time_allowed = 'get_max_time_allowed();?>'; -var interactions = new Array(get_interactions_js_array();?>); -item_objectives = new Array(); -info_lms_item=new Array(); -$(document).ready( function() { - info_lms_item[0]='get_id();?>'; - info_lms_item[1]='get_id();?>'; +// SCORM-specific Error messages +var G_NoErrorMessage = ''; +var G_GeneralExceptionMessage = 'General Exception'; +var G_ServerBusyMessage = 'Server busy'; // this is not in the Scorm1.2_Runtime document +var G_InvalidArgumentErrorMessage = 'Invalid argument error'; +var G_ElementCannotHaveChildrenMessage = 'Element cannot have children'; +var G_ElementIsNotAnArrayMessage = 'Element not an array. Cannot have count'; +var G_NotInitializedMessage = 'Not initialized'; +var G_NotImplementedErrorMessage = 'Not implemented error'; +var G_InvalidSetValueMessage = 'Invalid set value, element is a keyword'; +var G_ElementIsReadOnlyMessage = 'Element is read only'; +var G_ElementIsWriteOnlyMessage = 'Element is write only'; +var G_IncorrectDataTypeMessage = 'Incorrect Data Type'; + +var olms = new Object(); + +//the last recorded error message was: +olms.G_LastError = G_NoError ; +olms.G_LastErrorMessage = 'No error'; - $("#current_item_id").attr("value",get_id();?>); - $("#old_item").attr("value",get_id();?>); +//this is not necessary and is only provided to make bad Articulate contents shut up (and not trigger useless JS messages) +olms.G_LastErrorString = 'No error'; + +//these variables are provided for better control of the current status in the +// SCORM exchange +olms.commit = false; + +// informative array helping to select variables to save, later on +olms.scorm_variables = new Array( + 'cmi.core.score.raw', + 'cmi.core.score.max', + 'cmi.core.score.min', + 'cmi.core.lesson_location', + 'cmi.core.lesson_status', + 'cmi.completion_status', + 'cmi.core.session_time', + 'cmi.score.scaled', + 'cmi.success_status', + 'cmi.suspend_data', + 'cmi.core.exit', + 'interactions' +); + +// 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(); + +// Strictly scorm variables +olms.score=get_score();?>; +olms.max='get_max();?>'; +olms.min='get_min();?>'; +olms.lesson_status='get_status();?>'; +olms.session_time='get_scorm_time('js');?>'; +olms.suspend_data = 'get_suspend_data();?>'; +olms.lesson_location = 'get_lesson_location();?>'; +olms.total_time = 'get_scorm_time('js');?>'; +olms.mastery_score = 'get_mastery_score();?>'; +olms.launch_data = 'get_launch_data();?>'; +olms.max_time_allowed = 'get_max_time_allowed();?>'; +olms.interactions = new Array(get_interactions_js_array();?>); +olms.item_objectives = new Array(); +olms.info_lms_item=new Array(); + +// Dokeos internal variables (not SCORM) +// olms.saved_lesson_status = 'not attempted'; +olms.lms_lp_id = get_id();?>; +olms.lms_item_id = get_id();?>; +olms.lms_initialized = 0; +//olms.lms_total_lessons = get_total_items_count(); ?>; +//olms.lms_complete_lessons = get_complete_items_count();?>; +//olms.lms_progress_bar_mode = 'progress_bar_mode;?>'; +//if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';} +olms.lms_view_id = 'get_view();?>'; +if(olms.lms_view_id == ''){ olms.lms_view_id = 1;} +olms.lms_user_id = ''; +olms.lms_next_item = 'get_next_item_id();?>'; +olms.lms_previous_item = 'get_previous_item_id();?>'; +olms.lms_lp_type = 'get_type();?>'; +olms.lms_item_type = 'get_type();?>'; +olms.lms_item_credit = 'get_credit();?>'; +olms.lms_item_lesson_mode = 'get_lesson_mode();?>'; +olms.lms_item_launch_data = 'get_launch_data();?>'; +olms.lms_item_core_exit = 'get_core_exit();?>'; +get_items_details_as_js('olms.lms_item_types')?> + +olms.asset_timer = 0; - //var myiframe=document.getElementById('content_id'); - //myiframe.Events.AttachEvent("onclick", update_lp_item_id); - //myiframe.contentWindow.document.addEventListener("click", update_lp_item_id, false); +//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() { - $("iframe#content_id").load( function(){ - //alert("Document title: " + $("iframe#content_id").attr('src')); - info_lms_item[0]=info_lms_item[1]; - info_lms_item[1]= info_lms_item[1]; - - if (lms_lp_type == 2) { //Only scorm - attach_glossary_into_scorm(); - } - - - }); + // + olms.info_lms_item[0]='get_id();?>'; + olms.info_lms_item[1]='get_id();?>'; + + $("#content_id").load( function(){ + olms.info_lms_item[0]=olms.info_lms_item[1]; + + if (olms.lms_lp_type == 2) { //Only scorm + attach_glossary_into_scorm(); + } + + if (olms.lms_item_types['i'+olms.info_lms_item[1]] != 'sco') { + LMSInitialize(); + } + }); }); -//Dokeos internal variables -var saved_lesson_status = 'not attempted'; -var lms_lp_id = get_id();?>; -var lms_item_id = get_id();?>; -//var lms_new_item_id = 0; //temporary value (only there between a load_item() and a LMSInitialize()) -var lms_been_synchronized = 0; -var lms_initialized = 0; -var lms_total_lessons = get_total_items_count(); ?>; -var lms_complete_lessons = get_complete_items_count();?>; -var lms_progress_bar_mode = 'progress_bar_mode;?>'; -if(lms_progress_bar_mode == ''){lms_progress_bar_mode='%';} -var lms_view_id = 'get_view();?>'; -if(lms_view_id == ''){ lms_view_id = 1;} -var lms_user_id = ''; -var lms_next_item = 'get_next_item_id();?>'; -var lms_previous_item = 'get_previous_item_id();?>'; -var lms_lp_type = 'get_type();?>'; -var lms_item_type = 'get_type();?>'; -var lms_item_credit = 'get_credit();?>'; -var lms_item_lesson_mode = 'get_lesson_mode();?>'; -var lms_item_launch_data = 'get_launch_data();?>'; -var lms_item_core_exit = 'get_core_exit();?>'; -var asset_timer = 0; - -//Backup for old values -var old_score = 0; -var old_max = 0; -var old_min = 0; -var old_lesson_status = ''; -var old_session_time = ''; -var old_suspend_data = ''; -var lms_old_item_id = 0; - -var execute_stats='false'; - - - /** - * Function called mandatorily by the SCORM content to start the SCORM communication + * The following section represents a set of mandatory functions for SCORM + */ +/** + * Function called mandatorily by the SCORM content to start the SCORM comm + * @return string 'true' or 'false'. Returning a string is mandatory (SCORM). */ function LMSInitialize() { //this is the initialize function of all APIobjects @@ -246,42 +235,83 @@ function LMSInitialize() { //this is the initialize function of all APIobjects * and that kind of stuff, so when the content loads in the content frame * it will have all the correct variables set */ - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - //reinit to list - reinit_update_table_list () + olms.G_LastError = G_NoError ; + olms.G_LastErrorMessage = 'No error'; + - lms_initialized=0; + olms.lms_initialized=0; // if there are more parameters than "" if (arguments.length>1) { - G_LastError = G_InvalidArgumentError; - G_LastErrorMessage = G_InvalidArgumentErrorMessage; + olms.G_LastError = G_InvalidArgumentError; + olms.G_LastErrorMessage = G_InvalidArgumentErrorMessage; logit_scorm('Error '+ G_InvalidArgumentError + G_InvalidArgumentErrorMessage, 0); return('false'); } else { - logit_scorm('LMSInitialise()',0); - lms_initialized=1; - return('true'); + //reinit the list of modified variables + reinit_updatable_vars_list(); + // Get LMS values for this item + params = { + 'lid': olms.lms_lp_id, + 'uid': olms.lms_user_id, + 'vid': olms.lms_view_id, + 'iid': olms.lms_item_id + }; + $.ajax({ + type: "POST", + url: "lp_ajax_initialize.php", + data: params, + dataType: 'script', + async: false + }); + // log a more complete object dump when initializing, so we know what data hasn't been cleaned + var log = '
item : '+ olms.lms_item_id + + '
item_type : '+ olms.lms_item_type + + '
score : '+ olms.score + + '
max : '+ olms.max + + '
min : '+ olms.min + + '
lesson_status : '+ olms.lesson_status + + '
session_time : '+ olms.session_time + + '
lesson_location : '+ olms.lesson_location + + '
suspend_data : '+ olms.suspend_data + + '
total_time : '+ olms.total_time + + '
mastery_score : '+ olms.mastery_score + + '
max_time_allowed: '+ olms.max_time_allowed + + '
lms_lp_id : '+olms.lms_lp_id + + '
lms_user_id: '+olms.lms_user_id + + '
lms_view_id: '+olms.lms_view_id + ; + + logit_scorm('LMSInitialize()'+log,0); + olms.lms_initialized=1; + return('true'); } } +/** + * Twin sister of LMSInitialize(). Only provided for backwards compatibility. + */ function Initialize() { //this is the initialize function of all APIobjects return LMSInitialize(); } +/** + * Gets a value in the current SCORM context and returns it to the calling SCO + * @param string The name of the value we want + * @return string All return values must be string (see SCORM) + */ function LMSGetValue(param) { //logit_scorm("LMSGetValue('"+param+"')",1); - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; + olms.G_LastError = G_NoError ; + olms.G_LastErrorMessage = 'No error'; var result=''; // the LMSInitialize is missing - if (lms_initialized == 0) { - G_LastError = G_NotInitialized; - G_LastErrorMessage = G_NotInitializedMessage; - logit_scorm('Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0); + if (olms.lms_initialized == 0) { + olms.G_LastError = G_NotInitialized; + olms.G_LastErrorMessage = G_NotInitializedMessage; + logit_scorm('LMSGetValue('+param+'):
=> Error '+ G_NotInitialized + ' ' +G_NotInitializedMessage, 0); return ''; } @@ -296,8 +326,8 @@ function LMSGetValue(param) param == 'cmi.comments' || param == 'cmi.comments_from_lms' ) { // the value is not supported - G_lastError = G_NotImplementedError ; - G_lastErrorString = G_NotImplementedErrorMessage; + olms.G_LastError = G_NotImplementedError ; + olms.G_LastErrorString = G_NotImplementedErrorMessage; logit_scorm("LMSGetValue ('"+param+"') Error '"+G_NotImplementedErrorMessage+"'",1); result = ''; return result; @@ -308,9 +338,9 @@ function LMSGetValue(param) result='entry, exit, lesson_status, student_id, student_name, lesson_location, total_time, credit, lesson_mode, score, session_time'; }else if(param == 'cmi.core.entry'){ // ---- cmi.core.entry - if(lms_item_core_exit=='none') { + if(olms.lms_item_core_exit=='none') { result='ab-initio'; - } else if(lms_item_core_exit=='suspend') { + } else if(olms.lms_item_core_exit=='suspend') { result='resume'; } else { result=''; @@ -318,14 +348,14 @@ function LMSGetValue(param) }else if(param == 'cmi.core.exit'){ // ---- cmi.core.exit result=''; - G_LastError = G_ElementIsWriteOnly; + olms.G_LastError = G_ElementIsWriteOnly; }else if(param == 'cmi.core.session_time'){ result=''; - G_LastError = G_ElementIsWriteOnly; + olms.G_LastError = G_ElementIsWriteOnly; }else if(param == 'cmi.core.lesson_status'){ // ---- cmi.core.lesson_status - if(lesson_status != '') { - result=lesson_status; + if(olms.lesson_status != '') { + result=olms.lesson_status; } else { //result='not attempted'; } @@ -340,51 +370,51 @@ function LMSGetValue(param) ?> }else if(param == 'cmi.core.lesson_location'){ // ---- cmi.core.lesson_location - result=lesson_location; + result=olms.lesson_location; }else if(param == 'cmi.core.total_time'){ // ---- cmi.core.total_time - result=total_time; + result=olms.total_time; }else if(param == 'cmi.core.score._children'){ // ---- cmi.core.score._children result='raw,min,max'; }else if(param == 'cmi.core.score.raw'){ // ---- cmi.core.score.raw - result=score; + result=olms.score; }else if(param == 'cmi.core.score.max'){ // ---- cmi.core.score.max - result=max; + result=olms.max; }else if(param == 'cmi.core.score.min'){ // ---- cmi.core.score.min - result=min; + result=olms.min; }else if(param == 'cmi.core.score'){ // ---- cmi.core.score -- non-standard item, provided as cmi.core.score.raw just in case - result=score; + result=olms.score; }else if(param == 'cmi.core.credit'){ // ---- cmi.core.credit - result = lms_item_credit; + result = olms.lms_item_credit; }else if(param == 'cmi.core.lesson_mode'){ // ---- cmi.core.lesson_mode - result = lms_item_lesson_mode; + result = olms.lms_item_lesson_mode; }else if(param == 'cmi.suspend_data'){ // ---- cmi.suspend_data - result = suspend_data; + result = olms.suspend_data; }else if(param == 'cmi.launch_data'){ // ---- cmi.launch_data - result = lms_item_launch_data; + result = olms.lms_item_launch_data; }else if(param == 'cmi.objectives._children'){ // ---- cmi.objectives._children result = 'id,score,status'; }else if(param == 'cmi.objectives._count'){ // ---- cmi.objectives._count //result='get_view_count();?>'; - result = item_objectives.length; + result = olms.item_objectives.length; }else if(param.substring(0,15)== 'cmi.objectives.'){ var myres = ''; if(myres = param.match(/cmi.objectives.(\d+).(id|score|status|_children)(.*)/)) { var obj_id = myres[1]; var req_type = myres[2]; - if(item_objectives[obj_id]==null) + if(olms.item_objectives[obj_id]==null) { if(req_type == 'id') { @@ -395,8 +425,8 @@ function LMSGetValue(param) if(myres[3]==null) { result = ''; - G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + olms.G_LastError = G_NotImplementedError; + olms.G_LastErrorString = 'Not implemented yet'; }else if (myres[3] == '._children'){ result = 'raw,min,max'; //non-standard, added for NetG }else if (myres[3] == '.raw'){ @@ -407,8 +437,8 @@ function LMSGetValue(param) result = ''; }else{ result = ''; - G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + olms.G_LastError = G_NotImplementedError; + olms.G_LastErrorString = 'Not implemented yet'; } }else if(req_type == 'status'){ result = 'not attempted'; @@ -419,47 +449,47 @@ function LMSGetValue(param) //the object is not null if(req_type == 'id') { - result = item_objectives[obj_id][0]; + result = olms.item_objectives[obj_id][0]; }else if(req_type == '_children'){ result = 'id,score,status'; }else if(req_type == 'score'){ if(myres[3]==null) { result = ''; - G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + olms.G_LastError = G_NotImplementedError; + olms.G_LastErrorString = 'Not implemented yet'; }else if (myres[3] == '._children'){ result = 'raw,min,max'; //non-standard, added for NetG }else if (myres[3] == '.raw'){ - if(item_objectives[obj_id][2] != null) + if(olms.item_objectives[obj_id][2] != null) { - result = item_objectives[obj_id][2]; + result = olms.item_objectives[obj_id][2]; }else{ result = ''; } }else if (myres[3] == '.max'){ - if(item_objectives[obj_id][3] != null) + if(olms.item_objectives[obj_id][3] != null) { - result = item_objectives[obj_id][3]; + result = olms.item_objectives[obj_id][3]; }else{ result = ''; } }else if (myres[3] == '.min'){ - if(item_objectives[obj_id][4] != null) + if(olms.item_objectives[obj_id][4] != null) { - result = item_objectives[obj_id][4]; + result = olms.item_objectives[obj_id][4]; }else{ result = ''; } }else{ result = ''; - G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + olms.G_LastError = G_NotImplementedError; + olms.G_LastErrorString = 'Not implemented yet'; } }else if(req_type == 'status'){ - if(item_objectives[obj_id][1] != null) + if(olms.item_objectives[obj_id][1] != null) { - result = item_objectives[obj_id][1]; + result = olms.item_objectives[obj_id][1]; }else{ result = 'not attempted'; } @@ -471,21 +501,21 @@ function LMSGetValue(param) result = 'mastery_score,max_time_allowed'; }else if(param == 'cmi.student_data.mastery_score'){ // ---- cmi.student_data.mastery_score - result = mastery_score; + result = olms.mastery_score; }else if(param == 'cmi.student_data.max_time_allowed'){ // ---- cmi.student_data.max_time_allowed - result = max_time_allowed; + result = olms.max_time_allowed; }else if(param == 'cmi.interactions._count'){ // ---- cmi.interactions._count - result = interactions.length; + result = olms.interactions.length; }else if(param == 'cmi.interactions._children'){ // ---- cmi.interactions._children result = 'id,time,type,correct_responses,weighting,student_response,result,latency'; }else{ // ---- anything else // Invalid argument error - G_lastError = G_InvalidArgumentError ; - G_lastErrorString = G_InvalidArgumentErrorMessage; + olms.G_LastError = G_InvalidArgumentError ; + olms.G_LastErrorString = G_InvalidArgumentErrorMessage; logit_scorm("LMSGetValue ('"+param+"') Error '"+G_InvalidArgumentErrorMessage+"'",1); result = ''; return result; @@ -493,167 +523,173 @@ 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 + * @param string The SCORM variable's new value + * @param string 'true','false' or an error code + */ function LMSSetValue(param, val) { logit_scorm("LMSSetValue\n\t('"+param+"','"+val+"')",0); - commit = true; //value has changed, need to re-commit - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; + olms.commit = true; //value has changed, need to re-commit + olms.G_LastError = G_NoError ; + olms.G_LastErrorMessage = 'No error'; return_value = 'false'; if( param == "cmi.core.score.raw" ) { - score= val; - updatetable_to_list['cmi.core.score.raw']='true'; + olms.score= val; + olms.updatable_vars_list['cmi.core.score.raw']=true; return_value='true'; } else if ( param == "cmi.core.score.max" ) { - max = val; - updatetable_to_list['cmi.core.score.max']='true'; + olms.max = val; + olms.updatable_vars_list['cmi.core.score.max']=true; return_value='true'; } else if ( param == "cmi.core.score.min" ) { - min = val; - updatetable_to_list['cmi.core.score.min']='true'; + olms.min = val; + olms.updatable_vars_list['cmi.core.score.min']=true; return_value='true'; } else if ( param == "cmi.core.lesson_location" ) { - lesson_location = val; - updatetable_to_list['cmi.core.lesson_location']='true'; + olms.lesson_location = val; + olms.updatable_vars_list['cmi.core.lesson_location']=true; return_value='true'; } else if ( param == "cmi.core.lesson_status" ) { - saved_lesson_status = lesson_status; - lesson_status = val; - updatetable_to_list['cmi.core.lesson_status']='true'; + olms.lesson_status = val; + olms.updatable_vars_list['cmi.core.lesson_status']=true; return_value='true'; } else if ( param == "cmi.completion_status" ) { - lesson_status = val; - updatetable_to_list['cmi.completion_status']='true'; + olms.lesson_status = val; + olms.updatable_vars_list['cmi.completion_status']=true; return_value='true'; //1.3 } else if ( param == "cmi.core.session_time" ) { - session_time = val; - updatetable_to_list['cmi.core.session_time']='true'; + olms.session_time = val; + olms.updatable_vars_list['cmi.core.session_time']=true; return_value='true'; } else if ( param == "cmi.score.scaled") { //1.3 if(val<=1 && val>=-1) { - score = val ; - updatetable_to_list['cmi.score.scaled']='true'; + olms.score = val ; + olms.updatable_vars_list['cmi.score.scaled']=true; return_value='true'; } else { return_value='false'; } } else if ( param == "cmi.success_status" ) { success_status = val; - updatetable_to_list['cmi.success_status']='true'; + olms.updatable_vars_list['cmi.success_status']=true; return_value='true'; //1.3 } else if ( param == "cmi.suspend_data" ) { - suspend_data = val; - updatetable_to_list['cmi.suspend_data']='true'; + olms.suspend_data = val; + olms.updatable_vars_list['cmi.suspend_data']=true; return_value='true'; } else if ( param == "cmi.core.exit" ) { - lms_item_core_exit = val; - updatetable_to_list['cmi.core.exit']='true'; + olms.lms_item_core_exit = val; + olms.updatable_vars_list['cmi.core.exit']=true; return_value='true'; } else if ( param == "cmi.core.student_id" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.student_name" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.credit" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.entry" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.total_time" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.core.lesson_mode" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.comments_from_lms" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_data.time_limit_action" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_data.mastery_score" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_data.max_time_allowed" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.student_preference._children" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else if ( param == "cmi.launch_data" ) { - G_LastError = G_ElementIsReadOnly; + olms.G_LastError = G_ElementIsReadOnly; } else { var myres = new Array(); if(myres = param.match(/cmi.interactions.(\d+).(id|time|type|correct_responses|weighting|student_response|result|latency)(.*)/)) { - updatetable_to_list['interactions']='true'; + olms.updatable_vars_list['interactions']=true; elem_id = myres[1]; - if(elem_id > interactions.length) //interactions setting should start at 0 + if(elem_id > olms.interactions.length) //interactions setting should start at 0 { /* - G_LastError = G_InvalidArgumentError; - G_LastErrorString = 'Invalid argument (interactions)'; + olms.G_LastError = G_InvalidArgumentError; + olms.G_LastErrorString = 'Invalid argument (interactions)'; return_value = false; */ - interactions[0] = ['0','','','','','','','']; + olms.interactions[0] = ['0','','','','','','','']; } - if(interactions[elem_id] == null){ - interactions[elem_id] = ['','','','','','','','']; + if(olms.interactions[elem_id] == null){ + olms.interactions[elem_id] = ['','','','','','','','']; //id(0), type(1), time(2), weighting(3),correct_responses(4),student_response(5),result(6),latency(7) - interactions[elem_id][4] = new Array(); + olms.interactions[elem_id][4] = new Array(); } elem_attrib = myres[2]; switch(elem_attrib) { case "id": - interactions[elem_id][0] = val; + olms.interactions[elem_id][0] = val; logit_scorm("Interaction "+elem_id+"'s id updated",2); return_value='true'; break; case "time": - interactions[elem_id][2] = val; + olms.interactions[elem_id][2] = val; logit_scorm("Interaction "+elem_id+"'s time updated",2); return_value='true'; break; case "type": - interactions[elem_id][1] = val; + olms.interactions[elem_id][1] = val; logit_scorm("Interaction "+elem_id+"'s type updated",2); return_value='true'; break; case "correct_responses": //do nothing yet - interactions[elem_id][4].push(val); + olms.interactions[elem_id][4].push(val); logit_scorm("Interaction "+elem_id+"'s correct_responses not updated",2); return_value='true'; break; case "weighting": - interactions[elem_id][3] = val; + olms.interactions[elem_id][3] = val; logit_scorm("Interaction "+elem_id+"'s weighting updated",2); return_value='true'; break; case "student_response": - interactions[elem_id][5] = ''+val; + olms.interactions[elem_id][5] = ''+val; logit_scorm("Interaction "+elem_id+"'s student_response updated",2); return_value='true'; break; case "result": - interactions[elem_id][6] = val; + olms.interactions[elem_id][6] = val; logit_scorm("Interaction "+elem_id+"'s result updated",2); return_value='true'; break; case "latency": - interactions[elem_id][7] = val; + olms.interactions[elem_id][7] = val; logit_scorm("Interaction "+elem_id+"'s latency updated",2); return_value='true'; break; default: - G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + olms.G_LastError = G_NotImplementedError; + olms.G_LastErrorString = 'Not implemented yet'; } }else if(param.substring(0,15)== 'cmi.objectives.'){ var myres = ''; - updatetable_to_list['objectives']='true'; + olms.updatable_vars_list['objectives']=true; if(myres = param.match(/cmi.objectives.(\d+).(id|score|status)(.*)/)) { obj_id = myres[1]; - if(obj_id > item_objectives.length) //objectives setting should start at 0 + if(obj_id > olms.item_objectives.length) //objectives setting should start at 0 { - G_LastError = G_InvalidArgumentError; - G_LastErrorString = 'Invalid argument (objectives)'; + olms.G_LastError = G_InvalidArgumentError; + olms.G_LastErrorString = 'Invalid argument (objectives)'; return_value = false; } else @@ -665,51 +701,51 @@ function LMSSetValue(param, val) { } else { - if(item_objectives[obj_id]==null) + if(olms.item_objectives[obj_id]==null) { - item_objectives[obj_id] = ['','','','','']; + olms.item_objectives[obj_id] = ['','','','','']; } if( req_type == "id" ) { - //item_objectives[obj_id][0] = val.substring(51,57); - item_objectives[obj_id][0] = val; + //olms.item_objectives[obj_id][0] = val.substring(51,57); + olms.item_objectives[obj_id][0] = val; logit_scorm("Objective "+obj_id+"'s id updated",2); return_value = 'true'; } else if ( req_type == "score" ) { if (myres[3] == '._children'){ return_value = ''; - G_lastError = G_InvalidSetValue; - G_lastErrorString = 'Invalid set value, element is a keyword'; + olms.G_LastError = G_InvalidSetValue; + olms.G_LastErrorString = 'Invalid set value, element is a keyword'; }else if (myres[3] == '.raw'){ - item_objectives[obj_id][2] = val; + olms.item_objectives[obj_id][2] = val; logit_scorm("Objective "+obj_id+"'s score raw updated",2); return_value = 'true'; }else if (myres[3] == '.max'){ - item_objectives[obj_id][3] = val; + olms.item_objectives[obj_id][3] = val; logit_scorm("Objective "+obj_id+"'s score max updated",2); return_value = 'true'; }else if (myres[3] == '.min'){ - item_objectives[obj_id][4] = val; + olms.item_objectives[obj_id][4] = val; logit_scorm("Objective "+obj_id+"'s score min updated",2); return_value = 'true'; }else{ return_value = ''; - G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + olms.G_LastError = G_NotImplementedError; + olms.G_LastErrorString = 'Not implemented yet'; } } else if ( req_type == "status" ) { - item_objectives[obj_id][1] = val; + olms.item_objectives[obj_id][1] = val; logit_scorm("Objective "+obj_id+"'s status updated",2); return_value = 'true'; } else { - G_lastError = G_NotImplementedError; - G_lastErrorString = 'Not implemented yet'; + olms.G_LastError = G_NotImplementedError; + olms.G_LastErrorString = 'Not implemented yet'; } } } } }else{ - G_lastError = G_NotImplementedError; - G_lastErrorString = G_NotImplementedErrorMessage; + olms.G_LastError = G_NotImplementedError; + olms.G_LastErrorString = G_NotImplementedErrorMessage; } } return(return_value); } - +/** + * Twin sister of LMSSetValue(). Only provided for backwards compatibility. + */ function SetValue(param, val) { return LMSSetValue(param, val); } - -function ProcessValueScorm () { - - for (i=0;i=0) && (score >= mastery_score)) { - lesson_status = 'passed'; - updatetable_to_list['cmi.core.lesson_status']='true'; - } else if( (mastery_score < 0) && (lms_lp_type != '2') && ( lesson_status == 'incomplete') && (score >= (0.8*max) ) ) { + //origin can be 'commit', 'finish' or 'terminate' (depending on the calling function) + if ((olms.lesson_status != 'completed') && (olms.lesson_status != 'passed') && (olms.mastery_score >=0) && (olms.score >= olms.mastery_score)) { + olms.lesson_status = 'passed'; + olms.updatable_vars_list['cmi.core.lesson_status']=true; + } else if( (olms.mastery_score < 0) && (olms.lms_lp_type != '2') && ( olms.lesson_status == 'incomplete') && (olms.score >= (0.8*olms.max) ) ) { //the status cannot be modified automatically by the LMS under SCORM 1.2's rules - lesson_status = 'completed'; - updatetable_to_list['cmi.core.lesson_status']='true'; + olms.lesson_status = 'completed'; + olms.updatable_vars_list['cmi.core.lesson_status']=true; ; } else { - /* + /* DEPRECATED * See notes in switch_item for why this has been disabled - if ((origin== 'finish' || origin == 'unload') && lesson_status != 'completed' && lesson_status != 'passed' && lesson_status != 'browsed' && lesson_status != 'failed' && lesson_status != 'incomplete') { + if ((origin== 'finish' || origin == 'unload') && olms.lesson_status != 'completed' && olms.lesson_status != 'passed' && olms.lesson_status != 'browsed' && olms.lesson_status != 'failed' && olms.lesson_status != 'incomplete') { // The SCORM1.2 Runtime object document says for the "cmi.core.lesson_status" variable: // Upon receiving the LMSFinish() call or the user navigates away, // the LMS should set the cmi.core.lesson_status for the SCO to 'completed' - logit_lms('the LMS did saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1); - if (mastery_score && mastery_score!= '' && score && score != '') { - if (score >= mastery_score) { - lesson_status = 'passed'; + logit_lms('the LMS did saving data (status='+olms.lesson_status+' - interactions: '+ olms.interactions.length +')',1); + if (olms.mastery_score && olms.mastery_score!= '' && olms.score && olms.score != '') { + if (olms.score >= olms.mastery_score) { + olms.lesson_status = 'passed'; } else { - lesson_status = 'failed'; + olms.lesson_status = 'failed'; } - updatetable_to_list['cmi.core.lesson_status']='true'; - } else if (mastery_score && mastery_score!= '') { - lesson_status = 'completed'; - updatetable_to_list['cmi.core.lesson_status']='true'; + olms.updatable_vars_list['cmi.core.lesson_status']=true; + } else if (olms.mastery_score && olms.mastery_score!= '') { + olms.lesson_status = 'completed'; + olms.updatable_vars_list['cmi.core.lesson_status']=true; } } */ } - my_get_value_scorm=new Array(); - my_get_value_scorm=ProcessValueScorm(); - - logit_lms('saving data (status='+lesson_status+' - interactions: '+ interactions.length +')',1); + logit_lms('saving data (status='+olms.lesson_status+' - interactions: '+ olms.interactions.length +')',1); - old_item_id=info_lms_item[0]; - // xajax_save_item is replaced to xajax_save_item_scorm for scorm LP's - //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); + old_item_id=olms.info_lms_item[0]; - xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, old_item_id,my_get_value_scorm); - //info_lms_item[0] is old_item_id and info_lms_item[1] is current_item_id - info_lms_item[0]=info_lms_item[0]; - info_lms_item[1]=lms_item_id; + xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, old_item_id); + //olms.info_lms_item[0] is old_item_id and olms.info_lms_item[1] is current_item_id + olms.info_lms_item[1]=olms.lms_item_id; - if(item_objectives.length>0) { - xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,old_item_id,item_objectives); + if(olms.item_objectives.length>0) { + xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,old_item_id,olms.item_objectives); } - execute_stats='false'; + olms.execute_stats=false; //clean array - variable_to_send=new Array(); - my_get_value_scorm=new Array(); -} -/* - * See notes in switch_item for why this has been disabled -function savedata_onunload() { - savedata('unload'); + olms.variable_to_send=new Array(); } -*/ - +/** + * Send the Commit signal to the LMS (save the data for this element without + * closing the current process) + * From SCORM 1.2 RTE: If the API Adapter is caching values received from the + * SCO via an LMSSetValue(), this call requires that any values not yet + * persisted by the LMS be persisted. + * @param string Must be empty string for conformance with SCORM 1.2 + */ function LMSCommit(val) { logit_scorm('LMSCommit()',0); - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - - savedata('commit'); - reinit_update_table_list(); - //commit = 'false' ; //now changes have been commited, no need to update until next SetValue() + olms.G_LastError = G_NoError ; + olms.G_LastErrorMessage = 'No error'; + savedata('commit'); + reinit_updatable_vars_list(); + //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 + * longer needs to communicate with the LMS, if it successfully called + * LMSInitialize at any previous point. This call signifies two things: + * 1.The SCO can be assured that any data set using LMSSetValue() calls has been persisted by the LMS. + * 2.The SCO has finished communicating with the LMS. + * @param string + */ function LMSFinish(val) { - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - // why commit==false? - if (( commit == false )) { - logit_scorm('LMSFinish() (no LMSCommit())',1); + olms.G_LastError = G_NoError ; + olms.G_LastErrorMessage = 'No error'; + // if olms.commit == false, then the SCORM didn't ask for a commit, so we + // should at least report that + if (( olms.commit == false )) { + logit_scorm('LMSFinish() (no LMSCommit())',1); - } + } - //if ( commit == true ) { - logit_scorm('LMSFinish() called',1); - savedata('finish'); - commit = 'false' ; - //} + //if ( olms.commit == true ) { + logit_scorm('LMSFinish() called',1); + savedata('finish'); + olms.commit = false; + //} - //reinit to list - reinit_update_table_list() - return('true'); + //reinit the list of modified variables + reinit_updatable_vars_list() + return('true'); } - +/** + * Twin sister of LMSFinish(). Only provided for backwards compatibility. + */ function Finish(val) { - return LMSFinish(val); + return LMSFinish(val); } - +/** + * Returns the last error code as a string + * @return string Error code + */ function LMSGetLastError() { logit_scorm('LMSGetLastError()',1); - return(G_LastError.toString()); + 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 + * @return string Last error + */ function LMSGetErrorString(errCode){ logit_scorm('LMSGetErrorString()',1); - return(G_LastErrorString); + 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 + * @return string Diagnostic + */ 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() { - if (lms_initialized == 0) { - G_LastError = G_NotInitialized; - G_LastErrorMessage = G_NotInitializedMessage; + if (olms.lms_initialized == 0) { + olms.G_LastError = G_NotInitialized; + olms.G_LastErrorMessage = G_NotInitializedMessage; logit_scorm('Error '+ G_NotInitialized + G_NotInitializedMessage, 0); return('false'); } else { logit_scorm('Terminate()',0); - G_LastError = G_NoError ; - G_LastErrorMessage = 'No error'; - commit = true; + olms.G_LastError = G_NoError ; + olms.G_LastErrorMessage = 'No error'; + olms.commit = true; savedata('terminate'); - return (true); + return ('true'); } } - /** * Defining the AJAX-object class to be made available from other frames */ @@ -916,7 +958,9 @@ function XAJAXobject() { this.xajax_save_item = xajax_save_item; } -//it is not sure that the scos use the above declarations +/** + * It is not sure that the SCOs use the above declarations + */ oXAJAX = new XAJAXobject(); oxajax = new XAJAXobject(); @@ -943,6 +987,7 @@ function addEvent(elm, evType, fn, useCapture){ * the current context as it acts on objects that should exist * on the page * possibly deprecated + * @todo Try to use $(document).unload(lms_save_asset()) instead of the addEvent() method */ function addListeners(){ //exit if the browser doesn't support ID or tag retrieval @@ -956,84 +1001,50 @@ function addListeners(){ return; } //assign event handlers to objects - if(lms_lp_type==1 || lms_item_type=='asset'){ + if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){ logit_lms('Dokeos LP or asset',2); //if this path is a Dokeos learnpath, then start manual save //when something is loaded in there - addEvent(window,'unload',dokeos_save_asset,false); + addEvent(window,'unload',lms_save_asset,false); logit_lms('Added event listener on content_id for unload',2); } - /* See notes in switch_item() for why this has been disabled - if (lms_lp_type==2) { - addEvent(window,'unload',savedata_onunload,false); - } - */ logit_lms('Quitting addListeners()',2); } -/** - * Load an item into the content frame: - * - making sure the previous item status have been saved - * - first updating the current item ID (to save the right item) - * - updating the frame src - * possibly deprecated - */ -function load_item(item_id,url){ - if(document.getElementById('content_id')) { - logit_lms('Loading item '+item_id,2); - var cont_f = document.getElementById('content_id'); - if(cont_f.src){ - lms_old_item_id = lms_item_id; - var lms_new_item_id = item_id; - //load new content page into content frame - if(lms_lp_type==1 || lms_item_type=='asset'){ - dokeos_save_asset(); - } - cont_f.src = url; - - update_toc('unhighlight',lms_old_item_id); - update_toc('highlight',lms_old_item_id); - return true; - } - logit_lms('cont_f.src has no properties',0); - } - logit_lms('content_id has no properties',0); - return false; -} /** * Save a Dokeos learnpath item's time and mark as completed upon * leaving it */ -function dokeos_save_asset(){ +function lms_save_asset(){ // only for dokeos lps - if (execute_stats=='true') { - execute_stats='false'; + if (olms.execute_stats==true) { + olms.execute_stats=false; } else { - execute_stats='true'; + olms.execute_stats=true; } - if(lms_lp_type==1 || lms_item_type=='asset'){ - logit_lms('dokeos_save_asset',2); - 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); - if(item_objectives.length>0) + 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); + if(olms.item_objectives.length>0) { - xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives); + xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives); } } } /** * Save a Dokeos learnpath item's time and mark as completed upon leaving it. - * Same function as dokeos_save_asset() but saves it with empty params + * Same function as lms_save_asset() but saves it with empty params * to use values set from another side in the database. Only used by Dokeos quizzes. * 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 dokeos_void_save_asset(myscore,mymax) { - logit_lms('dokeos_save_asset',2); - score = myscore; + 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(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, myscore, mymax); + xajax_save_item(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id, myscore, mymax); } /** @@ -1050,7 +1061,6 @@ function logit_scorm(message,priority){ } } - /** * Logs information about LMS activity into the log frame * @param string Message to log @@ -1063,9 +1073,8 @@ function logit_lms(message,priority){ } } } - /** - * update the Table Of Contents frame, by changing CSS styles, mostly + * Update the Table Of Contents frame, by changing CSS styles, mostly * @param string Action to be taken * @param integer Item id to update */ @@ -1094,8 +1103,8 @@ function update_toc(update_action,update_id,change_ids) break; case 'highlight': if (change_ids=='yes') { - lms_next_item = update_id; - lms_previous_item = update_id; + olms.lms_next_item = update_id; + olms.lms_previous_item = update_id; } myelem.attr('class',"scorm_item_highlight"); break; @@ -1143,8 +1152,11 @@ function update_toc(update_action,update_id,change_ids) return true; } +/** + * Update the stats frame using a reload of the frame to avoid unsynched data + */ function update_stats() { - if (execute_stats=='true') { + if (olms.execute_stats==true) { try { cont_f = document.getElementById('content_id'); cont_f.src="lp_controller.php?action=stats"; @@ -1153,8 +1165,27 @@ function update_stats() { return false; } } - execute_stats='false'; + olms.execute_stats=false; +} + +/** + * Update the stats frame using a reload of the frame to avoid unsynched data + */ +function update_stats_page() +{ + var myframe = document.getElementById('content_id'); + var mysrc = myframe.location.href; + if(mysrc == 'lp_controller.php?action=stats'){ + if(myframe && myframe.src){ + var mysrc = myframe.src; + myframe.src = mysrc; + } + // = mysrc; //refresh 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 @@ -1164,7 +1195,7 @@ function update_stats() { function update_progress_bar(nbr_complete, nbr_total, mode) { logit_lms('update_progress_bar('+nbr_complete+','+nbr_total+','+mode+')',2); - logit_lms('could update with data: '+lms_lp_id+','+lms_view_id+','+lms_user_id,2); + logit_lms('could update with data: '+olms.lms_lp_id+','+olms.lms_view_id+','+olms.lms_user_id,2); if(mode == ''){mode='%';} if(nbr_total == 0){nbr_total=1;} @@ -1192,32 +1223,35 @@ function update_progress_bar(nbr_complete, nbr_total, mode) return true; } +/** + * Analyses the variables that have been modified through this SCO's life and + * put them into an array for later shipping to lp_ajax_save_item.php + * @return array Array of SCO variables + */ +function process_scorm_values () { -function update_stats_page() -{ - var myframe = document.getElementById('content_id'); - var mysrc = myframe.location.href; - if(mysrc == 'lp_controller.php?action=stats'){ - if(myframe && myframe.src){ - var mysrc = myframe.src; - myframe.src = mysrc; - } - // = mysrc; //refresh page - } - return true; + for (i=0;i0) { + xajax_save_objectives(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,olms.item_objectives); + } + } + +/* //(1) save the current item - logit_lms('Called switch_item with params '+lms_item_id+' and '+next_item+'',0); - if(lms_lp_type==1 || lms_item_type=='asset' || session_time == '0' || session_time == '0:00:00'){ - if (lms_lp_type==1) { - xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score, max, min, lesson_status, asset_timer, suspend_data, lesson_location,interactions, lms_item_core_exit); + if (olms.lms_lp_type==1 || olms.lms_item_type=='asset' || olms.session_time == '0' || olms.session_time == '0:00:00') { + if (olms.lms_lp_type==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); } else { - my_get_value_scorm=new Array(); - my_get_value_scorm=ProcessValueScorm(); - xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,my_get_value_scorm); + xajax_save_item_scorm(olms.lms_lp_id, olms.lms_user_id, olms.lms_view_id, olms.lms_item_id); } - if(item_objectives.length>0) { - xajax_save_objectives(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,item_objectives); - } + 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); + } }else{ +*/ /** * Because of SCORM 1.2's special rule about unsent commits and the fact * that a SCO should be SET TO 'completed' IF NO STATUS WAS SENT (and @@ -1269,113 +1352,117 @@ function switch_item(current_item, next_item){ * savedata(unload) (and then the status cannot be "incompleted" * anymore) */ - //if (lms_item_type=='sco' && lesson_status != 'completed' && lesson_status != 'passed' && lesson_status != 'browsed' && lesson_status != 'incomplete' && lesson_status != 'failed') { - /** - * savedata('finish') treats the special condition and saves the - * new status to the database, so switch_item_details() enjoys the - * new status - */ - //savedata('finish'); - //} - // 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); + /* + if (olms.lms_item_type=='sco' && olms.lesson_status != 'completed' && olms.lesson_status != 'passed' && olms.lesson_status != 'browsed' && olms.lesson_status != 'incomplete' && olms.lesson_status != 'failed') { + // savedata('finish') treats the special condition and saves the + // new status to the database, so switch_item_details() enjoys the + // new status + savedata('finish'); + } + 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); + */ +/* } - execute_stats=false; //(2) Refresh all the values inside this SCORM API object - use AJAX - xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id,next_item); - - status_info.push(lesson_status); - - //current item - - //old item - //info_lms_item[0]=next_item; + xajax_switch_item_details(olms.lms_lp_id,olms.lms_user_id,olms.lms_view_id,olms.lms_item_id,next_item); +*/ - if (info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') { - info_lms_item[0]=next_item; - info_lms_item[1]=next_item; + olms.execute_stats=false; + + // Considering info_lms_item[0] is initially the oldest and info_lms_item[1] + // is the newest item, and considering we are done switching the items now, + // we need to update these markers so that the new item is loaded when + // changing the document in the content frame + if (olms.info_lms_item[1]==next_item && next_item!='next' && next_item!='previous') { + olms.info_lms_item[0]=next_item; + olms.info_lms_item[1]=next_item; } else { if (next_item!='next' && next_item!='previous') { - info_lms_item[0]=info_lms_item[1]; - info_lms_item[1]=next_item; + olms.info_lms_item[0]=olms.info_lms_item[1]; + olms.info_lms_item[1]=next_item; } } - if (info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') { - info_lms_item[0]=next_item; - info_lms_item[1]=next_item; + if (olms.info_lms_item[0]==next_item && next_item!='next' && next_item!='previous') { + olms.info_lms_item[0]=next_item; + olms.info_lms_item[1]=next_item; } else { if (next_item!='next' && next_item!='previous') { - info_lms_item[0]=info_lms_item[0]; - info_lms_item[1]=next_item; + olms.info_lms_item[0]=olms.info_lms_item[0]; + olms.info_lms_item[1]=next_item; } } //(3) open the new item in the content_id frame switch(next_item){ case 'next': - next_item = lms_next_item; - info_lms_item[0]=info_lms_item[1]; - info_lms_item[1]=lms_next_item; + 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; break; case 'previous': - next_item = lms_previous_item; - info_lms_item[0]=info_lms_item[1]; - info_lms_item[1]=lms_previous_item; + 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; break; default: break; } - var mysrc = 'lp_controller.php?action=content&lp_id='+lms_lp_id+'&item_id='+next_item; + var mysrc = 'lp_controller.php?action=content&lp_id='+olms.lms_lp_id+'&item_id='+next_item; var cont_f = $("#content_id"); mode == 'fullscreen'){ ?> cont_f = window.open(''+mysrc,'content_id','toolbar=0,location=0,status=0,scrollbars=1,resizable=1'); cont_f.onload=function(){ - info_lms_item[0]=info_lms_item[1]; - info_lms_item[1]= info_lms_item[1]; + olms.info_lms_item[0]=olms.info_lms_item[1]; } cont_f.onunload=function(){ - info_lms_item[0]=info_lms_item[1]; - info_lms_item[1]= info_lms_item[1]; + olms.info_lms_item[0]=olms.info_lms_item[1]; } cont_f.attr("src",mysrc); - if(lms_lp_type==1 || lms_item_type=='asset'){ + if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){ xajax_start_timer(); } //(4) refresh the audio player if needed $.ajax({ - type: "GET", + type: "POST", url: "lp_nav.php", data: "", success: function(tmp_data) { $("#media").html(tmp_data); } }); -/* - if ( lms_lp_type==2 && (orig_lesson_status == 'not attempted' || orig_lesson_status == '') && orig_current_item != orig_next_item) { - params = 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+orig_current_item; - $.ajax({ - type:"GET", - data: params, - url: "lp_ajax_last_update_status.php", - dataType: "script" - }); - } -*/ return true; } /** * Save a specific item (with its interactions, if any) into the LMS through - * an AJAX call. Originally, we used the xajax library. Now we use jQuery. + * an AJAX call to lp_ajax_save_item.php. * Because of the need to pass an array, we have to build the parameters - * manually into GET[] + * manually into GET[]. + * This function has a twin sister for SCO elements (xajax_save_item_scorm) + * which takes into account the interactions. + * @param int ID of the learning path (for the LMS) + * @param int ID of the user + * @param int ID of the view of this learning path + * @param int ID of the item currently looked at + * @param float Score + * @param float Max score + * @param float Min score + * @param string Lesson status + * @param string Current session time (in 'xxxx:xx:xx.xx' format) + * @param string Suspend data (maximum 255 chars) + * @param string Lesson location (which page we've reached in the SCO) + * @param array Interactions + * @param string Core exit value (up to 4096 chars) + * @return void + * @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=''; @@ -1384,35 +1471,7 @@ function xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score params += '&status='+lesson_status+'&t='+session_time; params += '&suspend='+suspend_data+'&loc='+lesson_location; params += '&core_exit='+lms_item_core_exit; - interact_string = ''; - for (i in interactions){ - interact_string += '&interact['+i+']='; - interact_temp = '['; - for (j in interactions[i]) { - interact_temp += interactions[i][j]+','; - } - interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']'; - interact_string += encodeURIComponent(interact_temp); - } - //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1))); - params += interact_string; - /*params = { - 'lid': lms_lp_id, - 'uid': lms_user_id, - 'vid': lms_view_id, - 'iid': lms_item_id, - 's': score, - 'max': max, - 'min': min, - 'status': lesson_status, - 't': session_time, - 'suspend': suspend_data, - 'loc': lesson_location, - 'interact': interac_string, - 'core_exit': lms_item_core_exit - } - */ - if ( lms_lp_type==1) { + if ( olms.lms_lp_type==1) { $.ajax({ type:"GET", data: params, @@ -1423,43 +1482,52 @@ function xajax_save_item(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, score ); } } - -function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id,info_get_lms) { - -// var variables_scorm = new Array('cmi.core.score.raw','cmi.core.score.max','cmi.core.score.min','cmi.core.lesson_location', -//'cmi.core.lesson_status','cmi.completion_status','cmi.core.session_time','cmi.score.scaled','cmi.success_status', -//'cmi.suspend_data','cmi.core.exit','interactions'); +/** + * Save a SCORM item's variables, getting its SCORM values from + * updatable_vars_list. Takes interactions into account and considers whether + * variables have been modified or not. + * @param int ID of the learning path + * @param int ID of the user + * @param int ID of the view + * @param int ID of the item + * @return void + * @uses olms.updatable_vars_list + * @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=''; params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id+'&iid='+lms_item_id; - - for (k=0;k= 0){ @@ -1484,48 +1551,31 @@ function xajax_save_item_scorm(lms_lp_id, lms_user_id, lms_view_id, lms_item_id, interact_temp +=temp+','; } interact_temp = interact_temp.substr(0,(interact_temp.length-2)) + ']'; - // interact_string += encodeURIComponent(interact_temp); + // interact_string += encodeURIComponent(interact_temp); - interact_string += interact_temp; + interact_string += interact_temp; } //interact_string = encodeURIComponent(interact_string.substr(0,(interact_string.length-1))); params += interact_string; is_interactions='false'; - } - - //alert("parameters : "+params); - /*params = { - 'lid': lms_lp_id, - 'uid': lms_user_id, - 'vid': lms_view_id, - 'iid': lms_item_id, - 's': score, - 'max': max, - 'min': min, - 'status': lesson_status, - 't': session_time, - 'suspend': suspend_data, - 'loc': lesson_location, - 'interact': interac_string, - 'core_exit': lms_item_core_exit - }*/ - $.ajax({ - type:"GET", - data: params, - url: "lp_ajax_save_item.php", - dataType: "script", - async: false - } - ); - - params=''; - + } + $.ajax({ + type:"GET", + data: params, + url: "lp_ajax_save_item.php", + dataType: "script", + async: false + }); + params=''; + my_scorm_values = null; } /** * Starts the timer with the server clock time. - * Originally, we used the xajax library. Now we use jQuery + * @return void + * @todo check the timer stuff really works + * @uses lp_ajax_start_timer.php */ function xajax_start_timer() { $.ajax({ @@ -1536,35 +1586,45 @@ function xajax_start_timer() { }); } /** - * Save a specific item's objectives into the LMS through - * an AJAX call. Originally, we used the xajax library. Now we use jQuery + * Save a specific item's objectives into the LMS through an Synch JAX call + * @param int ID of the learning path + * @param int ID of the user + * @param int ID of the view + * @param int ID of the item + * @param array SCO's recorded objectives + * @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=''; - params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id; - params += '&iid='+lms_item_id; - obj_string = ''; - for (i in item_objectives){ - obj_string += '&objectives['+i+']='; - obj_temp = '['; - for (j in item_objectives[i]) { - obj_temp += item_objectives[i][j]+','; - } - obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']'; - obj_string += encodeURIComponent(obj_temp); + params=''; + params += 'lid='+lms_lp_id+'&uid='+lms_user_id+'&vid='+lms_view_id; + params += '&iid='+lms_item_id; + obj_string = ''; + for (i in item_objectives){ + obj_string += '&objectives['+i+']='; + obj_temp = '['; + for (j in item_objectives[i]) { + obj_temp += item_objectives[i][j]+','; } - params += obj_string; - $.ajax({ - type: "GET", - data: params, - url: "lp_ajax_save_objectives.php", - dataType: "script", - async: false - }); + obj_temp = obj_temp.substr(0,(obj_temp.length-2)) + ']'; + obj_string += encodeURIComponent(obj_temp); + } + params += obj_string; + $.ajax({ + type: "GET", + data: params, + url: "lp_ajax_save_objectives.php", + dataType: "script", + async: false + }); } /** - * Switch between two items through - * an AJAX call. Originally, we used the xajax library. Now we use jQuery + * Switch between two items through an AJAX call. + * @param int ID of the learning path + * @param int ID of the user + * @param int ID of the view + * @param int ID of the item + * @param int ID of the next item + * @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 = { @@ -1573,42 +1633,70 @@ function xajax_switch_item_details(lms_lp_id,lms_user_id,lms_view_id,lms_item_id 'vid': lms_view_id, 'iid': lms_item_id, 'next': next_item - } + }; $.ajax({ - type: "GET", + type: "POST", data: params, url: "lp_ajax_switch_item.php", dataType: "script", async: false }); } - - +/** + * Switch between two items through an AJAX call, but only update the TOC and + * progress bar. + * @param int ID of the learning path + * @param int ID of the user + * @param int ID of the view + * @param int ID of the item + * @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) { + params = { + 'lid': lms_lp_id, + 'uid': lms_user_id, + 'vid': lms_view_id, + 'iid': lms_item_id, + 'next': next_item + }; + $.ajax({ + type: "POST", + data: params, + url: "lp_ajax_switch_item_toc.php", + dataType: "script", + async: true + }); +} +/** + * Add the "addListeners" function to the "onload" event of the window and + * start the timer if necessary (asset) + */ addEvent(window,'load',addListeners,false); -if(lms_lp_type==1 || lms_item_type=='asset'){ +if(olms.lms_lp_type==1 || olms.lms_item_type=='asset'){ xajax_start_timer(); } - /** -*Allow attach the glossary terms into html document of scorm -*Added by Isaac flores -*/ + * 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. + * Added by Isaac flores + */ function attach_glossary_into_scorm() { - var f = $('#content_id')[0]; + var f = $('#content_id')[0]; - var doc = f.contentWindow ? f.contentWindow.document : - f.contentDocument ? f.contentDocument : f.document; + var doc = f.contentWindow ? f.contentWindow.document : + f.contentDocument ? f.contentDocument : f.document; - var $frame_content = $('body',doc); - var my_text=$frame_content.html(); + var $frame_content = $('body',doc); + var my_text=$frame_content.html(); - my_protocol = location.protocol; - my_pathname=location.pathname; - work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/')); + my_protocol = location.protocol; + my_pathname=location.pathname; + work_path = my_pathname.substr(0,my_pathname.indexOf('/courses/')); - $.ajax({ + $.ajax({ contentType: "application/x-www-form-urlencoded", - beforeSend: function(objeto) { + beforeSend: function(object) { }, type: "POST", url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php", @@ -1617,55 +1705,53 @@ function attach_glossary_into_scorm() { if (datos.length==0) { return false; } - data_terms=datos.split("[|.|_|.|-|.|]"); - for(i=0;i
 
"); - $("iframe").contents().find('body').find("div#"+div_show_id).attr("style","display:inline;float:left;position:absolute;background-color:#F5F6CE;border-bottom: 1px dashed #dddddd;border-right: 1px dashed #dddddd;border-left: 1px dashed #dddddd;border-top: 1px dashed #dddddd;color:#305582;margin-left:5px;margin-right:5px;"); - $("iframe").contents().find('body').find("div#"+div_content_id).attr("style","background-color:#F5F6CE;color:#305582;margin-left:8px;margin-right:8px;margin-top:5px;margin-bottom:5px;"); - notebook_id=$(this).attr("name"); - data_notebook=notebook_id.split("link"); - my_glossary_id=data_notebook[1]; - $.ajax({ - contentType: "application/x-www-form-urlencoded", - beforeSend: function(objeto) { - $("iframe").contents().find('body').find("div#"+div_content_id).html(""); }, - type: "POST", - url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php", - data: "glossary_id="+my_glossary_id, - success: function(datos) { - $("iframe").contents().find('body').find("div#"+div_content_id).html(datos); - } - }); + $("iframe").contents().find('body').find('.glossary-ajax').mouseover(function() { + random_id=Math.round(Math.random()*100); + div_show_id="div_show_id"+random_id; + div_content_id="div_content_id"+random_id; + $(this).append("
 
"); + $("iframe").contents().find('body').find("div#"+div_show_id).attr("style","display:inline;float:left;position:absolute;background-color:#F5F6CE;border-bottom: 1px dashed #dddddd;border-right: 1px dashed #dddddd;border-left: 1px dashed #dddddd;border-top: 1px dashed #dddddd;color:#305582;margin-left:5px;margin-right:5px;"); + $("iframe").contents().find('body').find("div#"+div_content_id).attr("style","background-color:#F5F6CE;color:#305582;margin-left:8px;margin-right:8px;margin-top:5px;margin-bottom:5px;"); + notebook_id=$(this).attr("name"); + data_notebook=notebook_id.split("link"); + my_glossary_id=data_notebook[1]; + $.ajax({ + contentType: "application/x-www-form-urlencoded", + beforeSend: function(object) { + $("iframe").contents().find('body').find("div#"+div_content_id).html(""); + }, + type: "POST", + url: my_protocol+"//"+location.host+work_path+"/main/glossary/glossary_ajax_request.php", + data: "glossary_id="+my_glossary_id, + success: function(datos) { + $("iframe").contents().find('body').find("div#"+div_content_id).html(datos); + } + }); }); // mouse out event $("iframe").contents().find('body').find('.glossary-ajax').mouseout(function(){ var current_element, current_element=$(this); div_show_id=current_element.find("div").attr("id"); - $("iframe").contents().find('body').find("div#"+div_show_id).remove(); + $("iframe").contents().find('body').find("div#"+div_show_id).remove(); }); //Callback Helper function replace_complete_char(m) { - var complete_term_pattern = new RegExp(real_term,"i"); - var tag = m.replace(complete_term_pattern," $&"); - return tag; + var complete_term_pattern = new RegExp(real_term,"i"); + var tag = m.replace(complete_term_pattern," $&"); + return tag; } - } - - }); - + }); } \ No newline at end of file diff --git a/main/tracking/courseLog.php b/main/tracking/courseLog.php index db322d5304..c8ac695a9c 100644 --- a/main/tracking/courseLog.php +++ b/main/tracking/courseLog.php @@ -647,7 +647,23 @@ if ($_GET['studentlist'] == 'false') { $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : 'DESC'; if (count($a_students) > 0) { - $table = new SortableTable('tracking', 'count_student_in_course', null, ($is_western_name_order xor $sort_by_first_name) ? 2 : 1); + + if ($export_csv) { + $csv_content[] = array (); + } + + $all_datas = array(); + $course_code = $_course['id']; + + $user_ids = array_keys($a_students); + $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2); + + $parameters['cidReq'] = Security::remove_XSS($_GET['cidReq']); + $parameters['studentlist'] = Security::remove_XSS($_GET['studentlist']); + $parameters['from'] = Security::remove_XSS($_GET['myspace']); + + $table->set_additional_parameters($parameters); + $table -> set_header(0, get_lang('OfficialCode'), false, 'align="center"'); if ($is_western_name_order) { $table -> set_header(1, get_lang('FirstName'), false, 'align="center"'); @@ -663,86 +679,15 @@ if ($_GET['studentlist'] == 'false') { $table -> set_header(7, get_lang('Messages'),false); $table -> set_header(8, get_lang('FirstLogin'), false, 'align="center"'); $table -> set_header(9, get_lang('LatestLogin'), false, 'align="center"'); - if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) { - $table -> set_header(10, get_lang('AdditionalProfileField'),false); - $table -> set_header(11, get_lang('Details'),false); - } else { - $table -> set_header(10, get_lang('Details'),false); - } - if ($export_csv) { - $csv_content[] = array (); - } - - $all_datas = array(); - $course_code = $_course['id']; - foreach ($a_students as $student_id => $student) { - $student_datas = UserManager :: get_user_info_by_id($student_id); - - $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0; - $nb_courses_student = 0; - $avg_time_spent = Tracking :: get_time_spent_on_the_course($student_id, $course_code); - $avg_student_score = Tracking :: get_average_test_scorm_and_lp($student_id, $course_code); - $avg_student_progress = Tracking :: get_avg_student_progress($student_id, $course_code); - $total_assignments = Tracking :: count_student_assignments($student_id, $course_code); - $total_messages = Tracking :: count_student_messages($student_id, $course_code); - - $row = array(); - $row[] = $student_datas['official_code']; - if ($is_western_name_order) { - $row[] = $student_datas['firstname']; - $row[] = $student_datas['lastname']; - } else { - $row[] = $student_datas['lastname']; - $row[] = $student_datas['firstname']; - } - $row[] = api_time_to_hms($avg_time_spent); - if (is_null($avg_student_score)) {$avg_student_score=0;} - if (is_null($avg_student_progress)) {$avg_student_progress=0;} - $row[] = $avg_student_progress.'%'; - $row[] = $avg_student_score.'%'; - $row[] = $total_assignments; - $row[] = $total_messages; - $row[] = Tracking :: get_first_connection_date_on_the_course($student_id, $course_code); - $row[] = Tracking :: get_last_connection_date_on_the_course($student_id, $course_code); - - // we need to display an additional profile field - if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) { - if (is_array($additional_user_profile_info[$student_id])) { - $row[]=implode(', ', $additional_user_profile_info[$student_id]); - } else { - $row[]=' '; - } - } - $row[] = '
'; - if ($export_csv) { - $row[8] = strip_tags($row[8]); - $row[9] = strip_tags($row[9]); - unset($row[10]); - $csv_content[] = $row; - } - $all_datas[] = $row; - } - $clean_order = array('ASC','DESC'); - if(in_array($_GET['tracking_direction'],$clean_order) && $_GET['tracking_direction'] == 'ASC'){ - usort($all_datas, 'sort_users'); - } else if (in_array($_GET['tracking_direction'],$clean_order) && $_GET['tracking_direction'] == 'DESC') { - usort($all_datas, 'sort_users_desc'); - } - $page = $table->get_pager()->getCurrentPageID(); - $all_datas = array_slice($all_datas, ($page-1)*$table -> per_page, $table -> per_page); - // if ($export_csv) { usort($csv_content, 'sort_users'); } + //if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) { + $table -> set_header(10, get_lang('AdditionalProfileField'),false); + /*} else { + $table -> set_header(10, ,false); + }*/ + $table -> set_header(11, get_lang('Details'),false); + $table->display(); + - foreach ($all_datas as $row) { - $table -> addRow($row,'align="right"'); - } - $table -> setColAttributes(0, array('align' => 'left')); - $table -> setColAttributes(1, array('align' => 'left')); - $table -> setColAttributes(2, array('align' => 'left')); - $table -> setColAttributes(7, array('align' => 'right')); - $table -> setColAttributes(8, array('align' => 'center')); - $table -> setColAttributes(9, array('align' => 'center')); - $table -> display(); - } else { echo get_lang('NoUsersInCourseTracking'); } @@ -904,7 +849,7 @@ function get_addtional_profile_information_of_field($field_id){ * @since Nov 2009 * @version 1.8.6.2 */ -function get_addtional_profile_information_of_field_by_user($field_id, $users){ +function get_addtional_profile_information_of_field_by_user($field_id, $users) { // Database table definition $table_user = Database::get_main_table(TABLE_MAIN_USER); $table_user_field_values = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES); @@ -952,7 +897,6 @@ function get_addtional_profile_information_of_field_by_user($field_id, $users){ return $return; } - /** * count the number of students in this course (used for SortableTable) */ @@ -968,3 +912,98 @@ function sort_users($a, $b) { function sort_users_desc($a, $b) { return strcmp( trim(api_strtolower($b[$_SESSION['tracking_column']])), trim(api_strtolower($a[$_SESSION['tracking_column']]))); } + +/** + * Get number of users for sortable with pagination + * @return int + */ +function get_number_of_users() { + global $user_ids; + return count($user_ids); +} +/** + * Get data for users list in sortable with pagination + * @return array + */ +function get_user_data($from, $number_of_items, $column, $direction) { + + global $user_ids, $course_code, $additional_user_profile_info, $export_csv, $is_western_name_order, $csv_content; + + $course_code = Database::escape_string($course_code); + $course_info = CourseManager :: get_course_information($course_code); + $tbl_track_cours_access = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_COURSE_ACCESS); + $tbl_user = Database :: get_main_table(TABLE_MAIN_USER); + $tbl_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY, $course_info['db_name']); + $tbl_forum_post = Database :: get_course_table(TABLE_FORUM_POST, $course_info['db_name']); + $tbl_course_lp_view = Database :: get_course_table(TABLE_LP_VIEW, $course_info['db_name']); + $tbl_course_lp = Database :: get_course_table(TABLE_LP_MAIN, $course_info['db_name']); + + // get all users data from a course for sortable with limit + $condition_user = ""; + if (is_array($user_ids)) { + $condition_user = " WHERE user.user_id IN (".implode(',',$user_ids).") "; + } else { + $condition_user = " WHERE user.user_id = '$user_ids' "; + } + $sql = "SELECT user.user_id as col0, + user.official_code as col1, + user.lastname as col2, + user.firstname as col3 + FROM $tbl_user as user + $condition_user "; + + if (!in_array($direction, array('ASC','DESC'))) { + $direction = 'ASC'; + } + $column = intval($column); + $from = intval($from); + $number_of_items = intval($number_of_items); + $sql .= " ORDER BY col$column $direction "; + $sql .= " LIMIT $from,$number_of_items"; + $res = Database::query($sql, __FILE__, __LINE__); + $users = array (); + $t = time(); + $row = array(); + while ($user = Database::fetch_row($res)) { + + $row[0] = $user[1]; + if ($is_western_name_order) { + $row[1] = $user[3]; + $row[2] = $user[2]; + } else { + $row[1] = $user[2]; + $row[2] = $user[3]; + } + $row[3] = api_time_to_hms(Tracking::get_time_spent_on_the_course($user[0], $course_code)); + $avg_student_score = Tracking::get_average_test_scorm_and_lp($user[0], $course_code); + $avg_student_progress = Tracking::get_avg_student_progress($user[0], $course_code); + if (empty($avg_student_score)) {$avg_student_score=0;} + if (empty($avg_student_progress)) {$avg_student_progress=0;} + $row[4] = $avg_student_progress.'%'; + $row[5] = $avg_student_score.'%'; + $row[6] = Tracking::count_student_assignments($user[0], $course_code);$user[4]; + $row[7] = Tracking::count_student_messages($user[0], $course_code);//$user[5]; + $row[8] = Tracking::get_first_connection_date_on_the_course($user[0], $course_code); + $row[9] = Tracking::get_last_connection_date_on_the_course($user[0], $course_code); + + // we need to display an additional profile field + if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) { + if (is_array($additional_user_profile_info[$user[0]])) { + $row[10]=implode(', ', $additional_user_profile_info[$user[0]]); + } else { + $row[10]=' '; + } + } + $row[11] = '
'; + if ($export_csv) { + $row[8] = strip_tags($row[8]); + $row[9] = strip_tags($row[9]); + unset($row[10]); + unset($row[11]); + $csv_content[] = $row; + } + // store columns in array $users + $users[] = array($row[0],$row[1],$row[2],$row[3],$row[4],$row[5],$row[6],$row[7],$row[8],$row[9],$row[10],$row[11]); + } + return $users; +} \ No newline at end of file