lp_stats.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays statistics on the current learning path (scorm)
  5. *
  6. * This script must be included by lp_controller.php to get basic initialisation
  7. * @package chamilo.learnpath
  8. * @author Yannick Warnier <ywarnier@beeznest.org>
  9. * @todo clean this file like the exercise files J.M
  10. */
  11. require_once 'learnpath.class.php';
  12. require_once 'resourcelinker.inc.php';
  13. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  14. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  15. require_once '../exercice/exercise.lib.php';
  16. $course_id = api_get_course_id();
  17. if (empty($course_id ) && isset($_GET['course'])) {
  18. $course_code = Security::remove_XSS($_GET['course']);
  19. } else {
  20. $course_code = $course_id;
  21. }
  22. if (isset($_GET['student_id'])) {
  23. $student_id = intval($_GET['student_id']);
  24. }
  25. $session_id = api_get_session_id();
  26. $session_condition = api_get_session_condition($session_id);
  27. //When origin is not set that means that the lp_stats are viewed from the "man running" icon
  28. if (!isset($origin))
  29. $origin = '';
  30. //Origin = tracking means that teachers see that info in the Reporting tool
  31. if ($origin != 'tracking') {
  32. //$w = $tablewidth -20;
  33. $htmlHeadXtra[] = '<style type="text/css" media="screen, projection">
  34. /*<![CDATA[*/
  35. @import "../css/public_admin/scorm.css";
  36. /*]]>*/
  37. </style>';
  38. include_once api_get_path(INCLUDE_PATH).'reduced_header.inc.php';
  39. echo '<body dir="'.api_get_text_direction().'">';
  40. }
  41. $output = '';
  42. // if display in fullscreen required.
  43. if (!empty($_GET['fs']) && strcmp($_GET['fs'], 'true') == 0) {
  44. $output .= '<table width="100%" align="center">';
  45. } else {
  46. $output .= '<table width="100%">';
  47. }
  48. // Check if the user asked for the "extend all" option.
  49. $extend_all_link = '';
  50. $extend_all = 0;
  51. if ($origin == 'tracking') {
  52. $url_suffix = '&session_id='.$session_id.'&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($_GET['lp_id']) . '&origin=' . Security::remove_XSS($_GET['origin']).$from_link;
  53. } else {
  54. $url_suffix = '&lp_id=' . $lp_id;
  55. }
  56. if (!empty ($_GET['extend_all'])) {
  57. $extend_all_link = '<a href="' . api_get_self() . '?action=stats' . $url_suffix . '"><img src="../img/view_less_stats.gif" alt="fold_view" border="0" title="'.get_lang('HideAllAttempts').'"></a>';
  58. $extend_all = 1;
  59. } else {
  60. $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" title="'.get_lang('ShowAllAttempts').'"></a>';
  61. }
  62. if ($origin != 'tracking') {
  63. $output .= "<tr><td><h2>" . get_lang('ScormMystatus') . "</h2></td></tr>";
  64. }
  65. $output .= '<tr><td><table border="0" class="data_table"><tr>'.
  66. '<th width="16">' . $extend_all_link . '</td>' .
  67. '<th colspan="4" class="title"><div class="mystatusfirstrow">' . get_lang('ScormLessonTitle') . "</div></td>" .
  68. '<th colspan="2" class="title"><div class="mystatusfirstrow">' . get_lang('ScormStatus') . "</div></td>" .
  69. '<th colspan="2" class="title"><div class="mystatusfirstrow">' . get_lang('ScormScore') . "</div></td>" .
  70. '<th colspan="2" class="title"><div class="mystatusfirstrow">' . get_lang('ScormTime') . "</div></td>".
  71. '<th class="title"><div class="mystatusfirstrow">'.get_lang('Actions') . '</div></td></tr>';
  72. // Going through the items using the $items[] array instead of the database order ensures
  73. // we get them in the same order as in the imsmanifest file, which is rather random when using
  74. // the database table.
  75. $course_info = api_get_course_info($course_code);
  76. $TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM, $course_info['db_name']);
  77. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW, $course_info['db_name']);
  78. $TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW, $course_info['db_name']);
  79. $tbl_quiz_questions = Database :: get_course_table(TABLE_QUIZ_QUESTION, $course_info['db_name']);
  80. $TBL_QUIZ = Database :: get_course_table(TABLE_QUIZ_TEST, $course_info['db_name']);
  81. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  82. $tbl_stats_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  83. $sql = "SELECT max(view_count) FROM $TBL_LP_VIEW WHERE lp_id = $lp_id AND user_id = '" . $user_id . "' $session_condition";
  84. $res = Database::query($sql);
  85. $view = '';
  86. $num = 0;
  87. if (Database :: num_rows($res) > 0) {
  88. $myrow = Database :: fetch_array($res);
  89. $view = $myrow[0];
  90. }
  91. $counter = 0;
  92. //error_log('New LP - Querying views for latest attempt: '.$sql, 0);
  93. $total_score = 0;
  94. $total_max_score = 0;
  95. $total_time = 0;
  96. $h = get_lang('h');
  97. if (!empty($export_csv)) {
  98. $csv_content[] = array (
  99. get_lang('ScormLessonTitle'),
  100. get_lang('ScormStatus'),
  101. get_lang('ScormScore'),
  102. get_lang('ScormTime')
  103. );
  104. }
  105. // Get attempts of a exercise.
  106. if (isset($_GET['lp_id']) && isset($_GET['my_lp_id'])) {
  107. $clean_lp_item_id = Database::escape_string($_GET['my_lp_id']);
  108. $clean_lp_id = Database::escape_string($_GET['lp_id']);
  109. $clean_course_code = Database :: escape_string($course_code);
  110. $sql_path = "SELECT path FROM $TBL_LP_ITEM WHERE id = '$clean_lp_item_id' AND lp_id = '$clean_lp_id'";
  111. $res_path = Database::query($sql_path);
  112. $row_path = Database::fetch_array($res_path);
  113. if (Database::num_rows($res_path) > 0) {
  114. if ($origin != 'tracking') {
  115. $sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND status <> "incomplete" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND session_id = '.$session_id.' ORDER BY exe_date';
  116. } else {
  117. $sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . (int)$row_path['path'] . '" AND status <> "incomplete" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.(int)$clean_lp_id.'" AND orig_lp_item_id = "'.(int)$clean_lp_item_id.'" AND exe_cours_id="' . $clean_course_code. '" AND session_id = '.$session_id.' ORDER BY exe_date';
  118. }
  119. }
  120. }
  121. if (is_array($list) && count($list) > 0) {
  122. foreach ($list as $my_item_id) {
  123. $extend_this = 0;
  124. $qry_order = 'DESC';
  125. if ((!empty ($_GET['extend_id']) && $_GET['extend_id'] == $my_item_id) || $extend_all) {
  126. $extend_this = 1;
  127. $qry_order = 'ASC';
  128. }
  129. // Prepare statement to go through each attempt.
  130. if (!empty ($view)) {
  131. $sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
  132. " iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, iv.lp_view_id as mylpviewid, " .
  133. " i.title as mytitle, i.max_score as mymaxscore, " .
  134. " iv.max_score as myviewmaxscore, " .
  135. " i.item_type as item_type, iv.view_count as iv_view_count, " .
  136. " iv.id as iv_id, path as path" .
  137. " FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v" .
  138. " WHERE i.id = iv.lp_item_id " .
  139. " AND i.id = $my_item_id " .
  140. " AND iv.lp_view_id = v.id " .
  141. " AND i.lp_id = $lp_id " .
  142. " AND v.user_id = " . $user_id . " " .
  143. " AND v.view_count = $view " .
  144. " AND v.session_id = $session_id " .
  145. " ORDER BY iv.view_count $qry_order ";
  146. } else {
  147. $sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
  148. " iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, iv.lp_view_id as mylpviewid, " .
  149. " i.title as mytitle, i.max_score as mymaxscore, " .
  150. " iv.max_score as myviewmaxscore, " .
  151. " i.item_type as item_type, iv.view_count as iv_view_count, " .
  152. " iv.id as iv_id, path as path " .
  153. " FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v " .
  154. " WHERE i.id = iv.lp_item_id " .
  155. " AND i.id = $my_item_id " .
  156. " AND iv.lp_view_id = v.id " .
  157. " AND i.lp_id = $lp_id " .
  158. " AND v.user_id = " . $user_id . " " .
  159. " AND v.session_id = $session_id " .
  160. " ORDER BY iv.view_count $qry_order ";
  161. }
  162. //echo $sql.'<br />';
  163. $result = Database::query($sql);
  164. $num = Database :: num_rows($result);
  165. $time_for_total = 'NaN';
  166. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  167. if (($extend_this || $extend_all) && $num > 0) {
  168. $row = Database :: fetch_array($result);
  169. $result_disabled_ext_all = false;
  170. if ($row['item_type'] == 'quiz') {
  171. // Check results_disabled in quiz table.
  172. $my_path = Database::escape_string($row['path']);
  173. $sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE id ='".(int)$my_path."'";
  174. $res_result_disabled = Database::query($sql);
  175. $row_result_disabled = Database::fetch_row($res_result_disabled);
  176. if (Database::num_rows($res_result_disabled) > 0 && (int)$row_result_disabled[0] === 1) {
  177. $result_disabled_ext_all = true;
  178. }
  179. }
  180. //echo '<br /><pre>'; print_r($row); echo '</pre><br />';
  181. // If there are several attempts, and the link to extend has been clicked, show each attempt...
  182. if (($counter % 2) == 0) {
  183. $oddclass = 'row_odd';
  184. } else {
  185. $oddclass = 'row_even';
  186. }
  187. $extend_link = '';
  188. if (!empty($inter_num)) {
  189. $extend_link = '<a href="' . api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix . '"><img src="../img/visible.gif" alt="'.get_lang('HideAttemptView').'" title="'.get_lang('HideAttemptView').'" border="0"></a>' . "\n";
  190. }
  191. $title = $row['mytitle'];
  192. if (empty($title)) {
  193. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  194. }
  195. if ($row['item_type'] != 'dokeos_chapter') {
  196. $correct_test_link = '-';
  197. $title = Security::remove_XSS($title);
  198. $output .= "<tr class='$oddclass'>" . "<td>$extend_link</td>" . '<td colspan="4" class="content"><div class="mystatus">' . $title . "</div></td>" . '<td colspan="2" class="content"></td>'.'<td colspan="2" class="content"></td>'.'<td colspan="2" class="content"></td><td class="content"></td>' . "</tr>";
  199. }
  200. $counter++;
  201. do {
  202. $row['iv_view_count'];
  203. // Check if there are interactions below.
  204. $extend_attempt_link = '';
  205. $extend_this_attempt = 0;
  206. if ((learnpath :: get_interactions_count_from_db($row['iv_id']) > 0 || learnpath :: get_objectives_count_from_db($row['iv_id']) > 0) && !$extend_all) {
  207. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  208. // The extend button for this attempt has been clicked.
  209. $extend_this_attempt = 1;
  210. $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="'.get_lang('HideAttemptView').'" title="'.get_lang('HideAttemptView').'" border="0"></a>' . "\n";
  211. } else { // Same case if fold_attempt_id is set, so not implemented explicitly.
  212. // The extend button for this attempt has not been clicked.
  213. $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="'.get_lang('ExtendAttemptView').'" title="'.get_lang('ExtendAttemptView').'" border="0"></a>' . "\n";
  214. }
  215. }
  216. if (($counter % 2) == 0) {
  217. $oddclass = 'row_odd';
  218. } else {
  219. $oddclass = 'row_even';
  220. }
  221. $lesson_status = $row['mystatus'];
  222. $score = $row['myscore'];
  223. $time_for_total = $row['mytime'];
  224. $time = learnpathItem :: get_scorm_time('js', $row['mytime']);
  225. $type;
  226. $scoIdentifier = $row['myid'];
  227. if ($score == 0) {
  228. $maxscore = $row['mymaxscore'];
  229. } else {
  230. if ($row['item_type'] == 'sco') {
  231. if (!empty ($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) {
  232. $maxscore = $row['myviewmaxscore'];
  233. } elseif ($row['myviewmaxscore'] === '') {
  234. $maxscore = 0;
  235. } else {
  236. $maxscore = $row['mymaxscore'];
  237. }
  238. } else {
  239. $maxscore = $row['mymaxscore'];
  240. }
  241. }
  242. // Remove "NaN" if any (@todo: locate the source of these NaN)
  243. $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
  244. if (($lesson_status == 'completed') || ($lesson_status == 'passed')) {
  245. $color = 'green';
  246. } else {
  247. $color = 'black';
  248. }
  249. $mylanglist = array (
  250. 'completed' => 'ScormCompstatus',
  251. 'incomplete' => 'ScormIncomplete',
  252. 'failed' => 'ScormFailed',
  253. 'passed' => 'ScormPassed',
  254. 'browsed' => 'ScormBrowsed',
  255. 'not attempted' => 'ScormNotAttempted'
  256. );
  257. $my_lesson_status = get_lang($mylanglist[$lesson_status]);
  258. if ($row['item_type'] != 'dokeos_chapter') {
  259. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  260. $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  261. } else {
  262. //$view_score = ($score == 0 ? '/' : ($maxscore === 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  263. if ($row['item_type'] == 'sco') {
  264. if ($maxscore == 0 ) {
  265. $view_score = $score;
  266. } else {
  267. $view_score = show_score($score, $maxscore, false);
  268. }
  269. } else {
  270. $view_score = show_score($score, $maxscore, false);
  271. }
  272. }
  273. $output .= "<tr class='$oddclass'>" . "<td></td>" . "<td>$extend_attempt_link</td>" . '<td colspan="3">' . get_lang('Attempt') . ' ' . $row['iv_view_count'] . "</td>"
  274. . '<td colspan="2"><font color="' . $color . '"><div class="mystatus">' . $my_lesson_status . "</div></font></td>\n" . '<td colspan="2"><div class="mystatus" align="center">' . $view_score . "</div></td>" . '<td colspan="2"><div class="mystatus">'.$time.'</div></td><td></td></tr>';
  275. if (!empty($export_csv)) {
  276. $temp = array ();
  277. $temp[] = $title = Security::remove_XSS($title);
  278. $temp[] = Security::remove_XSS($my_lesson_status);
  279. if ($row['item_type'] == 'quiz') {
  280. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  281. $temp[] = '/';
  282. } else {
  283. $temp[] = ($score == 0 ? '0/'.$maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  284. }
  285. } else {
  286. $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  287. }
  288. $temp[] = $time;
  289. $csv_content[] = $temp;
  290. }
  291. }
  292. $counter++;
  293. if ($extend_this_attempt OR $extend_all) {
  294. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  295. foreach ($list1 as $id => $interaction) {
  296. if (($counter % 2) == 0) {
  297. $oddclass = 'row_odd';
  298. } else {
  299. $oddclass = 'row_even';
  300. }
  301. $student_response = urldecode($interaction['student_response']); // Code added by Isaac Flores.
  302. $content_student_response = array();
  303. $content_student_response = explode('__|',$student_response);
  304. if (count($content_student_response)>0) {
  305. if (count($content_student_response) >= 3) {
  306. $new_content_student_response = array_pop($content_student_response); // Pop the element off the end of array.
  307. }
  308. $student_response = implode(',',$content_student_response);
  309. }
  310. $output .= "<tr class='$oddclass'>" . '<td></td>' . '<td></td>' .'<td>&nbsp;</td>' . '<td>' . $interaction['order_id'] . '</td>' .'<td>' . $interaction['id'] . '</td>'
  311. . '<td colspan="2">' . $interaction['type'] . "</td>"
  312. . '<td>' . $student_response . "</td>" . '<td>' . $interaction['result'] . "</td>" . '<td>' . $interaction['latency'] . "</td>" . '<td>' . $interaction['time'] . "</td><td></td></tr>";
  313. $counter++;
  314. }
  315. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  316. foreach ($list2 as $id => $interaction) {
  317. if (($counter % 2) == 0) {
  318. $oddclass = 'row_odd';
  319. } else {
  320. $oddclass = 'row_even';
  321. }
  322. $output .= "<tr class='$oddclass'>" . '<td></td>' . '<td></td>'.'<td>&nbsp;</td>' .'<td>' . $interaction['order_id'] . '</td>'. '<td colspan="2">' . $interaction['objective_id'] . '</td>'.
  323. '<td colspan="2">' . $interaction['status'] . "</td>\n" .
  324. '<td>' . $interaction['score_raw'] . "</td>" . '<td>' . $interaction['score_max'] . "</td>" . '<td>' . $interaction['score_min'] . "</td><td></td></tr>";
  325. $counter++;
  326. }
  327. }
  328. } while ($row = Database :: fetch_array($result));
  329. } elseif ($num > 0) {
  330. $row = Database :: fetch_array($result);
  331. $my_id = $row['myid'];
  332. $my_lp_id = $row['mylpid'];
  333. $my_lp_view_id = $row['mylpviewid'];
  334. $my_path = $row['path'];
  335. $result_disabled_ext_all = false;
  336. if ($row['item_type'] == 'quiz') {
  337. // Check results_disabled in quiz table.
  338. $my_path = Database::escape_string($my_path);
  339. $sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE id ='".(int)$my_path."'";
  340. $res_result_disabled = Database::query($sql);
  341. $row_result_disabled = Database::fetch_row($res_result_disabled);
  342. if (Database::num_rows($res_result_disabled) > 0 && (int)$row_result_disabled[0] === 1) {
  343. $result_disabled_ext_all = true;
  344. }
  345. }
  346. // Check if there are interactions below.
  347. $extend_attempt_link = '';
  348. $extend_this_attempt = 0;
  349. $inter_num = learnpath::get_interactions_count_from_db($row['iv_id']);
  350. $objec_num = learnpath::get_objectives_count_from_db($row['iv_id']);
  351. if (($inter_num > 0 || $objec_num > 0) && !$extend_all) {
  352. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  353. // The extend button for this attempt has been clicked.
  354. $extend_this_attempt = 1;
  355. $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="'.get_lang('HideAttemptView').'" title="'.get_lang('HideAttemptView').'" border="0"></a>' . "\n";
  356. } else { // Same case if fold_attempt_id is set, so not implemented explicitly.
  357. // The extend button for this attempt has not been clicked.
  358. $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="'.get_lang('ExtendAttemptView').'" title="'.get_lang('ExtendAttemptView').'" border="0"></a>' . "\n";
  359. }
  360. }
  361. if (($counter % 2) == 0) {
  362. $oddclass = 'row_odd';
  363. } else {
  364. $oddclass = 'row_even';
  365. }
  366. //$extend_link = '<img src="../img/invisible.gif" alt="extend_disabled">';
  367. $extend_link = '';
  368. if ($inter_num > 1) {
  369. $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="'.get_lang('ExtendAttemptView').'" title="'.get_lang('ExtendAttemptView').'" border="0"></a>';
  370. }
  371. $lesson_status = $row['mystatus'];
  372. $score = $row['myscore'];
  373. $subtotal_time = $row['mytime'];
  374. //if ($row['mytime'] == 0) {
  375. while ($tmp_row = Database :: fetch_array($result)) {
  376. $subtotal_time += $tmp_row['mytime'];
  377. }
  378. //}
  379. //$time_for_total = $subtotal_time;
  380. //$time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  381. $scoIdentifier = $row['myid'];
  382. $title = $row['mytitle'];
  383. // Selecting the exe_id from stats attempts tables in order to look the max score value.
  384. if ($origin != 'tracking') {
  385. $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date DESC limit 1';
  386. } else {
  387. $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date DESC limit 1';
  388. }
  389. $resultLastAttempt = Database::query($sql_last_attempt);
  390. $num = Database :: num_rows($resultLastAttempt);
  391. if ($num > 0) {
  392. while ($rowLA = Database :: fetch_array($resultLastAttempt)) {
  393. $id_last_attempt = $rowLA['exe_id'];
  394. }
  395. }
  396. if ($score == 0) {
  397. $maxscore = $row['mymaxscore'];
  398. } else {
  399. if ($row['item_type'] == 'sco') {
  400. if (!empty ($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) {
  401. $maxscore = $row['myviewmaxscore'];
  402. }
  403. elseif ($row['myviewmaxscore'] === '') {
  404. $maxscore = 0;
  405. } else {
  406. $maxscore = $row['mymaxscore'];
  407. }
  408. } else {
  409. if ($row['item_type'] == 'quiz') {
  410. // Get score and total time from last attempt of a exercise en lp.
  411. $sql = "SELECT score FROM $TBL_LP_ITEM_VIEW WHERE lp_item_id = '".(int)$my_id."' and lp_view_id = '".(int)$my_lp_view_id."'
  412. ORDER BY view_count DESC limit 1";
  413. $res_score = Database::query($sql);
  414. $row_score = Database::fetch_array($res_score);
  415. $sql = "SELECT SUM(total_time) as total_time FROM $TBL_LP_ITEM_VIEW WHERE lp_item_id = '".(int)$my_id."' and lp_view_id = '".(int)$my_lp_view_id."'";
  416. $res_time = Database::query($sql);
  417. $row_time = Database::fetch_array($res_time);
  418. if (Database::num_rows($res_score) > 0 && Database::num_rows($res_time) > 0) {
  419. $score = (float)$row_score['score'];
  420. $subtotal_time = (int)$row_time['total_time'];
  421. } else {
  422. $score = 0;
  423. $subtotal_time = 0;
  424. }
  425. //echo $subtotal_time ;
  426. //$time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  427. // Selecting the max score from an attempt.
  428. $sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " .
  429. "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t";
  430. $result = Database::query($sql);
  431. $row_max_score = Database :: fetch_array($result);
  432. $maxscore = $row_max_score['maxscore'];
  433. } else {
  434. $maxscore = $row['mymaxscore'];
  435. }
  436. }
  437. }
  438. $time_for_total = $subtotal_time;
  439. $time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  440. if (empty ($title)) {
  441. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  442. }
  443. // Remove "NaN" if any (@todo: locate the source of these NaN)
  444. //$time = str_replace('NaN', '00'.$h.'00\'00"', $time);
  445. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  446. $color = 'green';
  447. } else {
  448. $color = 'black';
  449. }
  450. $mylanglist = array (
  451. 'completed' => 'ScormCompstatus',
  452. 'incomplete' => 'ScormIncomplete',
  453. 'failed' => 'ScormFailed',
  454. 'passed' => 'ScormPassed',
  455. 'browsed' => 'ScormBrowsed',
  456. 'not attempted' => 'ScormNotAttempted',
  457. );
  458. $my_lesson_status = get_lang($mylanglist[$lesson_status]);
  459. if ($row['item_type'] != 'dokeos_chapter') {
  460. if ($row['item_type'] == 'quiz') {
  461. $correct_test_link = '';
  462. $my_url_suffix ='';
  463. if ($origin != 'tracking' && $origin != 'tracking_course') {
  464. $my_url_suffix = '&course=' . api_get_course_id() . '&student_id=' . api_get_user_id() . '&lp_id=' . Security::remove_XSS($row['mylpid']);
  465. $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date DESC ';
  466. } else {
  467. $my_url_suffix = '&course=' . Security::remove_XSS($_GET['course']) . '&student_id=' . $student_id . '&lp_id=' . Security::remove_XSS($row['mylpid']).'&origin=' . Security::remove_XSS($_GET['origin'].$from_link);
  468. $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $student_id . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND status <> "incomplete" AND session_id = '.$session_id.' ORDER BY exe_date DESC ';
  469. }
  470. $resultLastAttempt = Database::query($sql_last_attempt);
  471. $num = Database :: num_rows($resultLastAttempt);
  472. if ($num > 0) {
  473. if (isset($_GET['extend_attempt']) && $_GET['extend_attempt'] == 1 && (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id) && (isset($_GET['my_lp_id']) && $_GET['my_lp_id'] == $my_id) ) {
  474. $correct_test_link = '<a href="' . api_get_self() . '?action=stats' . $my_url_suffix . '&session_id='.api_get_session_id().'&my_ext_lp_id='.$my_id.'"><img src="../img/view_less_stats.gif" alt="fold_view" border="0" title="'.get_lang('HideAllAttempts').'"></a>';
  475. $extend_attempt = 1;
  476. } else {
  477. $correct_test_link = '<a href="' . api_get_self() . '?action=stats&extend_attempt=1'.$my_url_suffix.'&session_id='.api_get_session_id().'&my_lp_id='.$my_id.'"><img src="../img/view_more_stats.gif" alt="extend_view" border="0" title="'.get_lang('ShowAllAttemptsByExercise').'"></a>';
  478. }
  479. } else {
  480. $correct_test_link = '-';
  481. }
  482. } else {
  483. $correct_test_link = '-';
  484. }
  485. $title = Security::remove_XSS($title);
  486. if ( (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id ) && (isset($_GET['my_lp_id']) && $_GET['my_lp_id'] == $my_id)) {
  487. $output .= "<tr class='$oddclass' >" . "<td>$extend_link</td>" . '<td colspan="4"><div class="mystatus">' .$title. '</div></td>';
  488. $output .= '<td colspan="2">&nbsp;</td><td colspan="2">&nbsp;</td><td colspan="2">&nbsp;</td><td>'.$correct_test_link.'</td></tr>';
  489. $output .= "</tr>";
  490. } else {
  491. if ( (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id ) && (isset($_GET['my_ext_lp_id']) && $_GET['my_ext_lp_id'] == $my_id)) {
  492. $output .= "<tr class='$oddclass'>";
  493. } else {
  494. $output .= "<tr class='$oddclass'>";
  495. }
  496. $output .= "<td>$extend_link</td>\n" . '<td colspan="4"><div class="mystatus">' .$title. '</div></td>';
  497. $output .= '<td colspan="2"><font color="' . $color . '"><div class="mystatus">' . $my_lesson_status . "</div></font></td>" . '<td colspan="2"><div class="mystatus" align="center">';
  498. if ($row['item_type'] == 'quiz') {
  499. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  500. $output .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  501. } else {
  502. // $output .= ($score == 0 ? '0/'.float_format($maxscore, 1) : ($maxscore == 0 ? $score : float_format($score, 1) . '/' . float_format($maxscore, 1)));
  503. $output .= show_score($score, $maxscore, false);
  504. }
  505. } else {
  506. $output .= ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
  507. }
  508. $output .= "</div></td>" . '<td colspan="2"><div class="mystatus">' . $time . "</div></td><td>$correct_test_link</td>";
  509. $output .= "</tr>";
  510. }
  511. if (!empty($export_csv)) {
  512. $temp = array ();
  513. $temp[] = api_html_entity_decode($title, ENT_QUOTES);
  514. $temp[] = api_html_entity_decode($my_lesson_status, ENT_QUOTES);
  515. if ($row['item_type'] == 'quiz') {
  516. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  517. $temp[] = '/';
  518. } else {
  519. $temp[] = ($score == 0 ? '0/'.$maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  520. }
  521. } else {
  522. $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  523. }
  524. $temp[] = $time;
  525. $csv_content[] = $temp;
  526. }
  527. }
  528. $counter++;
  529. if ($extend_this_attempt OR $extend_all) {
  530. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  531. foreach ($list1 as $id => $interaction) {
  532. if (($counter % 2) == 0) {
  533. $oddclass = 'row_odd';
  534. } else {
  535. $oddclass = 'row_even';
  536. }
  537. $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"
  538. . '<td colspan="2">' . $interaction['type'] . "</td>\n"
  539. . '<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";
  540. $counter++;
  541. }
  542. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  543. foreach ($list2 as $id => $interaction) {
  544. if (($counter % 2) == 0) {
  545. $oddclass = 'row_odd';
  546. } else {
  547. $oddclass = 'row_even';
  548. }
  549. $output .= "<tr class='$oddclass'>" . '<td></td>' . '<td></td>' . '<td>&nbsp;</td>' . '<td>' . $interaction['order_id'] . '</td>'.'<td colspan="2">' . $interaction['objective_id'] . '</td>'.
  550. '<td colspan="2">' . $interaction['status'] . "</td>" .
  551. '<td>' . $interaction['score_raw'] . "</td>" . '<td>' . $interaction['score_max'] . "</td>" . '<td>' . $interaction['score_min'] . "</td>\n<td></td>\n</tr>";
  552. $counter++;
  553. }
  554. }
  555. // Attempts listing by exercise.
  556. if ((isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id) && (isset($_GET['my_lp_id']) && $_GET['my_lp_id'] == $my_id)) {
  557. $res_attempts = Database::query($sql_attempts);
  558. $num_attempts = Database :: num_rows($res_attempts);
  559. if ($row['item_type'] === 'quiz') {
  560. if ($num_attempts > 0) {
  561. $n = 1;
  562. while ($row_attempts = Database :: fetch_array($res_attempts)) {
  563. $my_score = $row_attempts['exe_result'];
  564. $my_maxscore = $row_attempts['exe_weighting'];
  565. $my_exe_id = $row_attempts['exe_id'];
  566. $my_orig_lp = $row_attempts['orig_lp_id'];
  567. $my_orig_lp_item = $row_attempts['orig_lp_item_id'];
  568. $my_exo_exe_id = $row_attempts['exe_exo_id'];
  569. $mktime_start_date = api_strtotime($row_attempts['start_date'],'UTC');
  570. $mktime_exe_date = api_strtotime($row_attempts['exe_date'],'UTC');
  571. if ($mktime_start_date && $mktime_exe_date) {
  572. $mytime = ((int)$mktime_exe_date-(int)$mktime_start_date);
  573. $time_attemp = learnpathItem :: get_scorm_time('js', $mytime);
  574. $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
  575. } else {
  576. $time_attemp = ' - ';
  577. }
  578. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  579. $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  580. } else {
  581. // Show only float when need it.
  582. //$my_score = float_format( $my_score, 1);
  583. //$my_maxscore =float_format($my_maxscore, 1);
  584. if ($my_score == 0 ) {
  585. //$view_score = '0/'.$my_maxscore;
  586. $view_score = show_score(0, $my_maxscore, false);
  587. } else {
  588. if ($my_maxscore == 0) {
  589. $view_score = $my_score;
  590. } else {
  591. //$view_score = $my_score . '/' . $my_maxscore;
  592. $view_score = show_score($my_score, $my_maxscore, false);
  593. }
  594. }
  595. //$view_score = ($my_score == 0 ? '0.00/'.$my_maxscore : ($my_maxscore == 0 ? $my_score : $my_score . '/' . $my_maxscore));
  596. }
  597. $my_lesson_status = $row_attempts['status'];
  598. if ($my_lesson_status == '') {
  599. $my_lesson_status = get_lang($mylanglist['completed']);
  600. } elseif ($my_lesson_status == 'incomplete') {
  601. $my_lesson_status = get_lang($mylanglist['incomplete']);
  602. }
  603. $output .= '<tr class="'.$oddclass.'" ><td>&nbsp;</td><td>'.$extend_attempt_link.'</td><td colspan="3">' . get_lang('Attempt') . ' ' . $n . '</td>'
  604. . '<td colspan="2"><font color="' . $color . '"><div class="mystatus">' . $my_lesson_status . '</div></font></td><td colspan="2"><div class="mystatus" align="center">' . $view_score . '</div></td><td colspan="2"><div class="mystatus">' . $time_attemp . '</div></td>';
  605. if ($origin != 'tracking') {
  606. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  607. $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="'.get_lang('ShowAttempt').'" title="'.get_lang('ShowAttempt').'"></td>';
  608. } else {
  609. $output .= '<td><a href="../exercice/exercise_show.php?origin=student_progress&id=' . $my_exe_id . '&cidReq=' . $course_code . $from_link. '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="'.get_lang('ShowAttempt').'" title="'.get_lang('ShowAttempt').'"></a></td>';
  610. }
  611. } else {
  612. if (!$is_allowed_to_edit && $result_disabled_ext_all ) {
  613. $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="'.get_lang('ShowAndQualifyAttempt').'" title="'.get_lang('ShowAndQualifyAttempt').'"></td>';
  614. } else {
  615. $output .= '<td><a href="../exercice/exercise_show.php?origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="'.get_lang('ShowAndQualifyAttempt').'" title="'.get_lang('ShowAndQualifyAttempt').'"></a></td>';
  616. }
  617. }
  618. $output .= '</tr>';
  619. $n++;
  620. }
  621. }
  622. $output .= '<tr><td colspan="12">&nbsp;</td></tr>';
  623. }
  624. }
  625. }
  626. $total_time += $time_for_total;
  627. // QUIZZ IN LP
  628. $a_my_id = array();
  629. if (!empty($my_lp_id)) {
  630. $a_my_id[] = $my_lp_id;
  631. }
  632. }
  633. }
  634. //NOT Extend all "left green cross"
  635. if (!empty($a_my_id)) {
  636. $my_studen_id = 0;
  637. $my_course_id = '';
  638. if ($origin == 'tracking') {
  639. $my_studen_id = $student_id;
  640. $my_course_id = Database::escape_string($_GET['course']);
  641. } else {
  642. $my_studen_id = intval(api_get_user_id());
  643. $my_course_id = Database::escape_string(api_get_course_id());
  644. }
  645. //var_dump($my_studen_id, $my_course_id,$a_my_id);
  646. if (isset($_GET['extend_attempt'])) {
  647. //"Right green cross" extended
  648. $total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id, api_get_session_id(), false, false);
  649. } else {
  650. //"Left green cross" extended
  651. $total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id, api_get_session_id(), false, true);
  652. }
  653. } else {
  654. // Extend all "left green cross"
  655. if ($origin == 'tracking') {
  656. $my_course_id = Database::escape_string($_GET['course']);
  657. // var_dump($student_id, $my_course_id );
  658. if (!empty($student_id) && !empty($my_course_id)) {
  659. $total_score = Tracking::get_avg_student_score($student_id, $my_course_id, array(intval($_GET['lp_id'])), api_get_session_id(), false, false);
  660. } else {
  661. $total_score = 0;
  662. }
  663. } else {
  664. $total_score = Tracking::get_avg_student_score(api_get_user_id(), api_get_course_id(), array(intval($_GET['lp_id'])), api_get_session_id(), false, false);
  665. }
  666. }
  667. $total_time = learnpathItem :: get_scorm_time('js', $total_time);
  668. //$total_time = str_replace('NaN', '00:00:00' ,$total_time);
  669. $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
  670. $lp_type = learnpath :: get_type_static($lp_id);
  671. $total_percent = 0;
  672. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  673. $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  674. } else {
  675. if (is_numeric($total_score))
  676. $final_score = $total_score.'%';
  677. else
  678. $final_score = $total_score;
  679. }
  680. if (($counter % 2) == 0) {
  681. $oddclass = 'row_odd';
  682. } else {
  683. $oddclass = 'row_even';
  684. }
  685. //if (empty($extend_all)) {
  686. $output .= "<tr class='$oddclass'>\n" . "<td></td>\n" . '<td colspan="4"><div class="mystatus"><i>' . get_lang('AccomplishedStepsTotal') . "</i></div></td>\n"
  687. . '<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";
  688. //}
  689. $output .= "</table></td></tr></table>";
  690. if (!empty($export_csv)) {
  691. $temp = array (
  692. '',
  693. '',
  694. '',
  695. ''
  696. );
  697. $csv_content[] = $temp;
  698. $temp = array (
  699. get_lang('AccomplishedStepsTotal'),
  700. '',
  701. $final_score,
  702. $total_time
  703. );
  704. $csv_content[] = $temp;
  705. ob_end_clean();
  706. Export :: export_table_csv($csv_content, 'reporting_learning_path_details');
  707. exit;
  708. }
  709. if ($origin != 'tracking') {
  710. $output .= "</body></html>";
  711. }
  712. if (empty($export_csv)) {
  713. echo $output;
  714. }