lp_stats.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos SPRL
  6. For a full list of contributors, see "credits.txt".
  7. The full license can be read in "license.txt".
  8. This program is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU General Public License
  10. as published by the Free Software Foundation; either version 2
  11. of the License, or (at your option) any later version.
  12. See the GNU General Public License for more details.
  13. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  14. Mail: info@dokeos.com
  15. ==============================================================================
  16. */
  17. /**
  18. * This script displays statistics on the current learning path (scorm)
  19. *
  20. * This script must be included by lp_controller.php to get basic initialisation
  21. * @package dokeos.learnpath
  22. * @author Yannick Warnier <ywarnier@beeznest.org>
  23. */
  24. require_once('learnpath.class.php');
  25. //require_once('scorm.class.php');
  26. require_once ('resourcelinker.inc.php');
  27. if(empty($_SESSION['_course']['id']) && isset($_GET['course']))
  28. {
  29. $course_code = Database :: escape_string($_GET['course']);
  30. }
  31. else
  32. {
  33. $course_code = $_SESSION['_course']['id'];
  34. }
  35. //The two following variables have to be declared by the includer script
  36. //$lp_id = $_SESSION['oLP']->get_id();
  37. //$list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  38. //$user_id = $_user['user_id'];
  39. //$stats_charset = $_SESSION['oLP']->encoding
  40. if(!isset($origin))
  41. $origin = '';
  42. if($origin != 'tracking')
  43. {
  44. if (!empty ($stats_charset)) {
  45. $lp_charset = $stats_charset;
  46. } else {
  47. $lp_charset = api_get_setting('platform_charset');
  48. }
  49. $charset = $lp_charset;
  50. $w = $tablewidth -20;
  51. $htmlHeadXtra[] = ''.'<style type="text/css" media="screen, projection">
  52. /*<![CDATA[*/
  53. @import "../css/public_admin/scorm.css";
  54. /*]]>*/
  55. </style>';
  56. include_once ('../inc/reduced_header.inc.php');
  57. echo '<body>';
  58. }
  59. else
  60. {
  61. //Get learning path's encoding
  62. $TBL_LP = Database :: get_course_table(TABLE_LP_MAIN);
  63. $sql = "SELECT default_encoding FROM $TBL_LP " .
  64. "WHERE id = '".(int)$_GET['lp_id']."'";
  65. $res = api_sql_query($sql, __FILE__, __LINE__);
  66. if (Database :: num_rows($res) > 0)
  67. {
  68. $row = Database::fetch_array($res);
  69. $lp_charset = $row['default_encoding'];
  70. }
  71. }
  72. // The dokeos interface's encoding
  73. $dokeos_charset = api_get_setting('platform_charset');
  74. //if display in fullscreen required
  75. if (strcmp($_GET["fs"], "true") == 0)
  76. {
  77. $output .= '<table width="100%" align="center">';
  78. }
  79. else
  80. {
  81. $output .= '<table width="100%">';
  82. }
  83. //check if the user asked for the "extend all" option
  84. $extend_all_link = '';
  85. $extend_all = 0;
  86. if ($origin == 'tracking') {
  87. $url_suffix = '&course=' . $_GET['course'] . '&student_id=' . $_GET['student_id'] . '&lp_id=' . $_GET['lp_id'] . '&origin=' . $_GET['origin'];
  88. } else {
  89. $url_suffix = '';
  90. }
  91. if (!empty ($_GET['extend_all'])) {
  92. $extend_all_link = '<a href="' . api_get_self() . '?action=stats' . $url_suffix . '"><img src="../img/view_less_stats.gif" alt="fold_view" border="0"></a>';
  93. $extend_all = 1;
  94. } else {
  95. $extend_all_link = '<a href="' . api_get_self() . '?action=stats&extend_all=1' . $url_suffix . '"><img src="../img/view_more_stats.gif" alt="extend_view" border="0"></a>';
  96. }
  97. if ($origin != 'tracking') {
  98. $output .= "<tr><td><div class='title'>" . htmlentities(get_lang('ScormMystatus'), ENT_QUOTES, $dokeos_charset) . "</div></td></tr>";
  99. }
  100. $output .= "<tr><td>&nbsp;</td></tr>" . "<tr><td>" . "<table border='0' class='data_table'><tr>\n" . '<td width="16">' . $extend_all_link . '</td>' . '<td colspan="4" class="title"><div class="mystatusfirstrow">' . htmlentities(get_lang('ScormLessonTitle'), ENT_QUOTES, $dokeos_charset) . "</div></td>\n" . '<td colspan="2" class="title"><div class="mystatusfirstrow">' . htmlentities(get_lang('ScormStatus'), ENT_QUOTES, $dokeos_charset) . "</div></td>\n" . '<td colspan="2" class="title"><div class="mystatusfirstrow">' . htmlentities(get_lang('ScormScore'), ENT_QUOTES, $dokeos_charset) . "</div></td>\n" . '<td colspan="2" class="title"><div class="mystatusfirstrow">' . htmlentities(get_lang('ScormTime'), ENT_QUOTES, $dokeos_charset) . "</div></td><td class='title'><div class='mystatusfirstrow'>" . htmlentities(get_lang('Actions'), ENT_QUOTES, $dokeos_charset) . "</div></td></tr>\n";
  101. //going through the items using the $items[] array instead of the database order ensures
  102. // we get them in the same order as in the imsmanifest file, which is rather random when using
  103. // the database table
  104. $TBL_LP_ITEM = Database :: get_course_table('lp_item');
  105. $TBL_LP_ITEM_VIEW = Database :: get_course_table('lp_item_view');
  106. $TBL_LP_VIEW = Database :: get_course_table('lp_view');
  107. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  108. $tbl_stats_attempts= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  109. $tbl_quiz_questions= Database :: get_course_table(TABLE_QUIZ_QUESTION);
  110. $sql = "SELECT max(view_count) FROM $TBL_LP_VIEW " .
  111. "WHERE lp_id = $lp_id AND user_id = '" . $user_id . "'";
  112. $res = api_sql_query($sql, __FILE__, __LINE__);
  113. $view = '';
  114. if (Database :: num_rows($res) > 0) {
  115. $myrow = Database :: fetch_array($res);
  116. $view = $myrow[0];
  117. }
  118. $counter = 0;
  119. //error_log('New LP - Querying views for latest attempt: '.$sql,0);
  120. $total_score = 0;
  121. $total_max_score = 0;
  122. $total_time = 0;
  123. $h = get_lang('h');
  124. if ($export_csv) {
  125. $csv_content[] = array (
  126. get_lang('ScormLessonTitle'),
  127. get_lang('ScormStatus'),
  128. get_lang('ScormScore'),
  129. get_lang('ScormTime')
  130. );
  131. }
  132. $TBL_QUIZ = Database :: get_course_table('quiz');
  133. foreach ($list as $my_item_id) {
  134. $extend_this = 0;
  135. $qry_order = 'DESC';
  136. if ((!empty ($_GET['extend_id']) and $_GET['extend_id'] == $my_item_id) OR $extend_all) {
  137. $extend_this = 1;
  138. $qry_order = 'ASC';
  139. }
  140. //prepare statement to go through each attempt
  141. if (!empty ($view)) {
  142. $sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
  143. "iv.score as myscore, iv.total_time as mytime, i.id as myid, " .
  144. "i.title as mytitle, i.max_score as mymaxscore, " .
  145. "iv.max_score as myviewmaxscore, " .
  146. "i.item_type as item_type, iv.view_count as iv_view_count, " .
  147. "iv.id as iv_id, path as path" .
  148. " FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v" .
  149. " WHERE i.id = iv.lp_item_id " .
  150. " AND i.id = $my_item_id " .
  151. " AND iv.lp_view_id = v.id " .
  152. " AND i.lp_id = $lp_id " .
  153. " AND v.user_id = " . $user_id . " " .
  154. " AND v.view_count = $view " .
  155. " ORDER BY iv.view_count $qry_order ";
  156. } else {
  157. $sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
  158. "iv.score as myscore, iv.total_time as mytime, i.id as myid, " .
  159. "i.title as mytitle, i.max_score as mymaxscore, " .
  160. "iv.max_score as myviewmaxscore, " .
  161. "i.item_type as item_type, iv.view_count as iv_view_count, " .
  162. "iv.id as iv_id, path as path " .
  163. " FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v " .
  164. " WHERE i.id = iv.lp_item_id " .
  165. " AND i.id = $my_item_id " .
  166. " AND iv.lp_view_id = v.id " .
  167. " AND i.lp_id = $lp_id " .
  168. " AND v.user_id = " . $user_id . " " .
  169. " ORDER BY iv.view_count $qry_order ";
  170. }
  171. $result = api_sql_query($sql, __FILE__, __LINE__);
  172. $num = Database :: num_rows($result);
  173. $time_for_total = 'NaN';
  174. if (($extend_this || $extend_all) && $num > 0) {
  175. $row = Database :: fetch_array($result);
  176. //echo '<br><pre>'; print_r($row); echo '</pre><br>';
  177. //if there are several attempts, and the link to extend has been clicked, show each attempt...
  178. if (($counter % 2) == 0) {
  179. $oddclass = "row_odd";
  180. } else {
  181. $oddclass = "row_even";
  182. }
  183. if ($inter_num) {
  184. $extend_link = '<a href="' . api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix . '"><img src="../img/visible.gif" alt="fold_view" border="0"></a>' . "\n";
  185. }
  186. $title = $row['mytitle'];
  187. $title = stripslashes(html_entity_decode($title, ENT_QUOTES, $dokeos_charset));
  188. if (empty ($title)) {
  189. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  190. }
  191. if ($row['item_type'] != 'dokeos_chapter') {
  192. $correct_test_link = array ();
  193. if ($row['item_type'] == 'quiz')
  194. {
  195. if ($origin != 'tracking') {
  196. $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
  197. } else {
  198. $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $_GET['student_id'] . '" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
  199. }
  200. $resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
  201. $num = Database :: num_rows($resultLastAttempt);
  202. if ($num > 0) {
  203. if ($num > 1) {
  204. while ($rowLA = Database :: fetch_row($resultLastAttempt)) {
  205. $id_last_attempt = $rowLA[0];
  206. if ($origin != 'tracking') {
  207. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=student_progress&id=' . $id_last_attempt . '&cidReq=' . $course_code . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
  208. } else {
  209. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&id=' . $id_last_attempt . '&cidReq=' . $course_code . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
  210. }
  211. }
  212. } else {
  213. $id_last_attempt = Database :: result($resultLastAttempt, 0, 0);
  214. if ($origin != 'tracking') {
  215. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=student_progress&id=' . $id_last_attempt . '&cidReq=' . $course_code . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
  216. } else {
  217. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&id=' . $id_last_attempt . '&cidReq=' . $course_code . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
  218. }
  219. }
  220. }
  221. } else {
  222. $correct_test_link = '-';
  223. }
  224. //new attempt
  225. $output .= "<tr class='$oddclass'>\n" . "<td>$extend_link</td>\n" . '<td colspan="4" class="content"><div class="mystatus">' . htmlentities($title, ENT_QUOTES, $lp_charset) . "</div></td>\n" . '<td colspan="2" class="content"></td>' . "\n" . '<td colspan="2" class="content"></td>' . "\n" . '<td colspan="2" class="content"></td><td class="content"></td>' . "\n" . "</tr>\n";
  226. }
  227. $counter++;
  228. do {
  229. //check if there are interactions below
  230. $extend_attempt_link = '';
  231. $extend_this_attempt = 0;
  232. if ((learnpath :: get_interactions_count_from_db($row['iv_id']) > 0 || learnpath :: get_objectives_count_from_db($row['iv_id']) > 0) && !$extend_all) {
  233. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  234. //the extend button for this attempt has been clicked
  235. $extend_this_attempt = 1;
  236. $extend_attempt_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix . '"><img src="../img/visible.gif" alt="fold_attempt_view" border="0"></a>' . "\n";
  237. } else { //same case if fold_attempt_id is set, so not implemented explicitly
  238. //the extend button for this attempt has not been clicked
  239. $extend_attempt_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix . '"><img src="../img/invisible.gif" alt="extend_attempt_view" border="0"></a>' . "\n";
  240. }
  241. }
  242. if (($counter % 2) == 0) {
  243. $oddclass = "row_odd";
  244. } else {
  245. $oddclass = "row_even";
  246. }
  247. $lesson_status = $row['mystatus'];
  248. $score = $row['myscore'];
  249. $time_for_total = $row['mytime'];
  250. $time = learnpathItem :: get_scorm_time('js', $row['mytime']);
  251. $type;
  252. $scoIdentifier = $row['myid'];
  253. if ($score == 0) {
  254. $maxscore = 0;
  255. } else {
  256. if ($row['item_type'] == 'sco') {
  257. if (!empty ($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) {
  258. $maxscore = $row['myviewmaxscore'];
  259. }
  260. elseif ($row['myviewmaxscore'] === '') {
  261. $maxscore = 0;
  262. } else {
  263. $maxscore = $row['mymaxscore'];
  264. }
  265. }
  266. else
  267. {
  268. if ($row['item_type'] == 'quiz')
  269. {
  270. $myid= $row['myid'];
  271. // selecting the max score from an attempt
  272. $sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " .
  273. "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t";
  274. $result = api_sql_query($sql, __FILE__, __LINE__);
  275. $row_max_score = Database :: fetch_array($result);
  276. $maxscore = $row_max_score['maxscore'];
  277. } else {
  278. $maxscore = $row['mymaxscore'];
  279. }
  280. }
  281. }
  282. //Remove "NaN" if any (@todo: locate the source of these NaN)
  283. $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
  284. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  285. $color = 'green';
  286. } else {
  287. $color = 'black';
  288. }
  289. $mylanglist = array (
  290. 'completed' => 'ScormCompstatus',
  291. 'incomplete' => 'ScormIncomplete',
  292. 'failed' => 'ScormFailed',
  293. 'passed' => 'ScormPassed',
  294. 'browsed' => 'ScormBrowsed',
  295. 'not attempted' => 'ScormNotAttempted',
  296. );
  297. $my_lesson_status = htmlentities(get_lang($mylanglist[$lesson_status]), ENT_QUOTES, $dokeos_charset);
  298. //$my_lesson_status = get_lang($mylanglist[$lesson_status]);
  299. if ($row['item_type'] != 'dokeos_chapter') {
  300. $output .= "<tr class='$oddclass'>\n" . "<td></td>\n" . "<td>$extend_attempt_link</td>\n" . '<td colspan="3">' . htmlentities(get_lang('Attempt'), ENT_QUOTES, $dokeos_charset) . ' ' . $row['iv_view_count'] . "</td>\n"
  301. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$lp_charset)."</div></font></td>\n"
  302. . '<td colspan="2"><font color="' . $color . '"><div class="mystatus">' . $my_lesson_status . "</div></font></td>\n" . '<td colspan="2"><div class="mystatus" align="center">' . ($score == 0 ? '-' : ($maxscore == 0 ? $score : $score . '/' . $maxscore)) . "</div></td>\n" . '<td colspan="2"><div class="mystatus">' . $time . "</div></td><td></td>\n" . "</tr>\n";
  303. }
  304. $counter++;
  305. if ($extend_this_attempt OR $extend_all) {
  306. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  307. foreach ($list1 as $id => $interaction) {
  308. if (($counter % 2) == 0) {
  309. $oddclass = "row_odd";
  310. } else {
  311. $oddclass = "row_even";
  312. }
  313. $output .= "<tr class='$oddclass'>\n" . '<td></td>' . "\n" . '<td></td>' . "\n" . '<td>&nbsp;</td>' . "\n" . '<td>' . $interaction['order_id'] . '</td>' . "\n" . '<td>' . $interaction['id'] . '</td>' . "\n"
  314. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$lp_charset)."</div></font></td>\n"
  315. . '<td colspan="2">' . $interaction['type'] . "</td>\n"
  316. //.'<td>'.$interaction['correct_responses']."</td>\n"
  317. . '<td>' . urldecode($interaction['student_response']) . "</td>\n" . '<td>' . $interaction['result'] . "</td>\n" . '<td>' . $interaction['latency'] . "</td>\n" . '<td>' . $interaction['time'] . "</td>\n<td></td>\n</tr>\n";
  318. $counter++;
  319. }
  320. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  321. foreach ($list2 as $id => $interaction) {
  322. if (($counter % 2) == 0) {
  323. $oddclass = "row_odd";
  324. } else {
  325. $oddclass = "row_even";
  326. }
  327. $output .= "<tr class='$oddclass'>\n" . '<td></td>' . "\n" . '<td></td>' . "\n" . '<td>&nbsp;</td>' . "\n" . '<td>' . $interaction['order_id'] . '</td>' . "\n" . '<td colspan="2">' . $interaction['objective_id'] . '</td>' . "\n" .
  328. '<td colspan="2">' . $interaction['status'] . "</td>\n" .
  329. '<td>' . $interaction['score_raw'] . "</td>\n" . '<td>' . $interaction['score_max'] . "</td>\n" . '<td>' . $interaction['score_min'] . "</td>\n<td></td>\n</tr>\n";
  330. $counter++;
  331. }
  332. }
  333. } while ($row = Database :: fetch_array($result));
  334. }
  335. elseif ($num > 0) {
  336. $row = Database :: fetch_array($result);
  337. //check if there are interactions below
  338. $extend_attempt_link = '';
  339. $extend_this_attempt = 0;
  340. $inter_num = learnpath :: get_interactions_count_from_db($row['iv_id']);
  341. $objec_num = learnpath :: get_objectives_count_from_db($row['iv_id']);
  342. if (($inter_num > 0 || $objec_num > 0) && !$extend_all) {
  343. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  344. //the extend button for this attempt has been clicked
  345. $extend_this_attempt = 1;
  346. $extend_attempt_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix . '"><img src="../img/visible.gif" alt="fold_attempt_view" border="0"></a>' . "\n";
  347. } else { //same case if fold_attempt_id is set, so not implemented explicitly
  348. //the extend button for this attempt has not been clicked
  349. $extend_attempt_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix . '"><img src="../img/invisible.gif" alt="extend_attempt_view" border="0"></a>' . "\n";
  350. }
  351. }
  352. if (($counter % 2) == 0) {
  353. $oddclass = "row_odd";
  354. } else {
  355. $oddclass = "row_even";
  356. }
  357. //$extend_link = '<img src="../img/invisible.gif" alt="extend_disabled">';
  358. $extend_link = '';
  359. if ($inter_num > 1) {
  360. $extend_link = '<a href="' . api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix . '"><img src="../img/invisible.gif" alt="extend_view" border="0"></a>';
  361. }
  362. if (($counter % 2) == 0) {
  363. $oddclass = "row_odd";
  364. } else {
  365. $oddclass = "row_even";
  366. }
  367. $lesson_status = $row['mystatus'];
  368. $score = $row['myscore'];
  369. $subtotal_time = $row['mytime'];
  370. //if($row['mytime']==0){
  371. while ($tmp_row = Database :: fetch_array($result)) {
  372. $subtotal_time += $tmp_row['mytime'];
  373. }
  374. //}
  375. $time_for_total = $subtotal_time;
  376. $time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  377. $scoIdentifier = $row['myid'];
  378. $title = $row['mytitle'];
  379. $title = stripslashes(html_entity_decode($title, ENT_QUOTES, $dokeos_charset));
  380. // selecting the exe_id from stats attempts tables in order to look the max score value
  381. if ($origin != 'tracking') {
  382. $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
  383. } else {
  384. $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $_GET['student_id'] . '" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
  385. }
  386. $resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
  387. $num = Database :: num_rows($resultLastAttempt);
  388. if ($num > 0) {
  389. if ($num > 1) {
  390. while ($rowLA = Database :: fetch_row($resultLastAttempt)) {
  391. $id_last_attempt = $rowLA[0];
  392. }
  393. } else {
  394. $id_last_attempt = Database :: result($resultLastAttempt, 0, 0);
  395. }
  396. }
  397. if ($score == 0)
  398. {
  399. $maxscore = 0;
  400. }
  401. else
  402. {
  403. if ($row['item_type'] == 'sco')
  404. {
  405. if (!empty ($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) {
  406. $maxscore = $row['myviewmaxscore'];
  407. }
  408. elseif ($row['myviewmaxscore'] === '') {
  409. $maxscore = 0;
  410. } else {
  411. $maxscore = $row['mymaxscore'];
  412. }
  413. }
  414. else
  415. {
  416. if ($row['item_type'] == 'quiz')
  417. {
  418. $myid= $row['myid'];
  419. // selecting the max score from an attempt
  420. $sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " .
  421. "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t";
  422. $result = api_sql_query($sql, __FILE__, __LINE__);
  423. $row_max_score = Database :: fetch_array($result);
  424. $maxscore = $row_max_score['maxscore'];
  425. }
  426. else
  427. {
  428. $maxscore = $row['mymaxscore'];
  429. }
  430. }
  431. }
  432. if (empty ($title)) {
  433. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  434. }
  435. //Remove "NaN" if any (@todo: locate the source of these NaN)
  436. //$time = str_replace('NaN', '00'.$h.'00\'00"', $time);
  437. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  438. $color = 'green';
  439. } else {
  440. $color = 'black';
  441. }
  442. $mylanglist = array (
  443. 'completed' => 'ScormCompstatus',
  444. 'incomplete' => 'ScormIncomplete',
  445. 'failed' => 'ScormFailed',
  446. 'passed' => 'ScormPassed',
  447. 'browsed' => 'ScormBrowsed',
  448. 'not attempted' => 'ScormNotAttempted',
  449. );
  450. $my_lesson_status = htmlentities(get_lang($mylanglist[$lesson_status]), ENT_QUOTES, $dokeos_charset);
  451. if ($row['item_type'] != 'dokeos_chapter') {
  452. if ($row['item_type'] == 'quiz') {
  453. $correct_test_link = '';
  454. if ($origin != 'tracking' && $origin != 'tracking_course') {
  455. $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date ASC';
  456. } else {
  457. $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . Database :: escape_string($_GET['student_id']) . '" AND exe_cours_id="' . Database :: escape_string($_GET['course']) . '" ORDER BY exe_date';
  458. }
  459. $resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
  460. $num = Database :: num_rows($resultLastAttempt);
  461. if ($num > 0) {
  462. if ($num > 1) {
  463. $i = 1;
  464. while ($rowLA = Database :: fetch_array($resultLastAttempt)) {
  465. $laid = $rowLA['exe_id'];
  466. if ($origin != 'tracking') {
  467. $correct_test_link .= '<a href="../exercice/exercise_show.php?origin=student_progress&id=' . $laid . '&cidReq=' . $course_code . '" target="_parent" title="' . get_lang('Attempt') . ' ' . $i . '"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a> ';
  468. } else {
  469. $correct_test_link .= '<a href="../exercice/exercise_show.php?origin=tracking_course&id=' . $laid . '&cidReq=' . Security :: remove_XSS(Database :: escape_string($_GET['course'])) . '&student=' . $_GET['student_id'] . '" target="_parent" title="' . get_lang('Attempt') . ' ' . $i . '"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a> ';
  470. }
  471. $i++;
  472. }
  473. $correct_test_link = substr($correct_test_link, 0, -1);
  474. } else {
  475. $id_last_attempt = Database :: result($resultLastAttempt, 0, 0);
  476. if ($origin != 'tracking') {
  477. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=student_progress&id=' . $id_last_attempt . '&cidReq=' . $course_code . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
  478. } else {
  479. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&id=' . $id_last_attempt . '&cidReq=' . Security :: remove_XSS(Database :: escape_string($_GET['course'])) . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
  480. }
  481. }
  482. } else {
  483. $correct_test_link = '-';
  484. }
  485. } else {
  486. $correct_test_link = '-';
  487. }
  488. $output .= "<tr class='$oddclass'>\n" . "<td>$extend_link</td>\n" . '<td colspan="4"><div class="mystatus">' . htmlentities($title, ENT_QUOTES, $lp_charset) . '</div></td>' . "\n"
  489. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$lp_charset)."</div></font></td>\n"
  490. . '<td colspan="2"><font color="' . $color . '"><div class="mystatus">' . $my_lesson_status . "</div></font></td>\n" . '<td colspan="2"><div class="mystatus" align="center">' . ($score == 0 ? '-' : ($maxscore == 0 ? $score : $score . '/' . $maxscore)) . "</div></td>\n" . '<td colspan="2"><div class="mystatus">' . $time . "</div></td><td>$correct_test_link</td>\n" . "</tr>\n";
  491. if ($export_csv) {
  492. $temp = array ();
  493. $temp[] = $title;
  494. $temp[] = html_entity_decode($my_lesson_status);
  495. $temp[] = ($score == 0 ? '-' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
  496. $temp[] = $time;
  497. $csv_content[] = $temp;
  498. }
  499. }
  500. $counter++;
  501. if ($extend_this_attempt OR $extend_all) {
  502. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  503. foreach ($list1 as $id => $interaction) {
  504. if (($counter % 2) == 0) {
  505. $oddclass = "row_odd";
  506. } else {
  507. $oddclass = "row_even";
  508. }
  509. $output .= "<tr class='$oddclass'>\n" . '<td></td>' . "\n" . '<td></td>' . "\n" . '<td>&nbsp;</td>' . "\n" . '<td>' . $interaction['order_id'] . '</td>' . "\n" . '<td>' . $interaction['id'] . '</td>' . "\n"
  510. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$lp_charset)."</div></font></td>\n"
  511. . '<td colspan="2">' . $interaction['type'] . "</td>\n"
  512. //.'<td>'.$interaction['correct_responses']."</td>\n"
  513. . '<td>' . urldecode($interaction['student_response']) . "</td>\n" . '<td>' . $interaction['result'] . "</td>\n" . '<td>' . $interaction['latency'] . "</td>\n" . '<td>' . $interaction['time'] . "</td>\n<td></td>\n</tr>\n";
  514. $counter++;
  515. }
  516. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  517. foreach ($list2 as $id => $interaction) {
  518. if (($counter % 2) == 0) {
  519. $oddclass = "row_odd";
  520. } else {
  521. $oddclass = "row_even";
  522. }
  523. $output .= "<tr class='$oddclass'>\n" . '<td></td>' . "\n" . '<td></td>' . "\n" . '<td>&nbsp;</td>' . "\n" . '<td>' . $interaction['order_id'] . '</td>' . "\n" . '<td colspan="2">' . $interaction['objective_id'] . '</td>' . "\n" .
  524. '<td colspan="2">' . $interaction['status'] . "</td>\n" .
  525. '<td>' . $interaction['score_raw'] . "</td>\n" . '<td>' . $interaction['score_max'] . "</td>\n" . '<td>' . $interaction['score_min'] . "</td>\n<td></td>\n</tr>\n";
  526. $counter++;
  527. }
  528. }
  529. }
  530. //only sum up the latest attempt each time
  531. $total_max_score += $maxscore;
  532. $total_score += $score;
  533. $total_time += $time_for_total;
  534. }
  535. $total_time = learnpathItem :: get_scorm_time('js', $total_time);
  536. //$total_time = str_replace('NaN','00:00:00',$total_time);
  537. $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
  538. $lp_type = learnpath :: get_type_static($lp_id);
  539. $total_percent = 0;
  540. $final_score = '0%';
  541. if ($lp_type == 2) //if scorm
  542. {
  543. if ($total_max_score == 0) {
  544. $total_percent = number_format((float) $total_score, 1, '.', '');
  545. $final_score = ($total_score == 0 ? '-' : $total_percent);
  546. } else {
  547. $total_percent = number_format((((float) $total_score / (float) $total_max_score) * 100), 1, '.', '');
  548. $final_score = ($total_score == 0 ? '-' : $total_percent . '%');
  549. }
  550. } else {
  551. if ($total_max_score == 0) {
  552. $total_max_score = 1;
  553. }
  554. $total_percent = number_format((((float) $total_score / (float) $total_max_score) * 100), 1, '.', '');
  555. $final_score = ($total_score == 0 ? '-' : $total_percent . '%');
  556. }
  557. if (($counter % 2) == 0) {
  558. $oddclass = "row_odd";
  559. } else {
  560. $oddclass = "row_even";
  561. }
  562. $output .= "<tr class='$oddclass'>\n" . "<td></td>\n" . '<td colspan="4"><div class="mystatus"><i>' . htmlentities(get_lang('AccomplishedStepsTotal'), ENT_QUOTES, $dokeos_charset) . "</i></div></td>\n"
  563. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$lp_charset)."</div></font></td>\n"
  564. . '<td colspan="2"></td>' . "\n" . '<td colspan="2"><div class="mystatus" align="center">' . $final_score . "</div></td>\n" . '<td colspan="2"><div class="mystatus">' . $total_time . '</div></td><td></td>' . "\n" . "</tr>\n";
  565. $output .= "</table></td></tr></table>";
  566. if ($export_csv) {
  567. $temp = array (
  568. '',
  569. '',
  570. '',
  571. ''
  572. );
  573. $csv_content[] = $temp;
  574. $temp = array (
  575. get_lang('AccomplishedStepsTotal'),
  576. '',
  577. $final_score,
  578. $total_time
  579. );
  580. $csv_content[] = $temp;
  581. ob_end_clean();
  582. Export :: export_table_csv($csv_content, 'reporting_learning_path_details');
  583. }
  584. if ($origin != 'tracking') {
  585. $output .= "</body></html>";
  586. }
  587. if (!$export_csv) {
  588. echo $output;
  589. }
  590. ?>