lp_stats.php 44 KB

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