lp_stats.php 41 KB

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