lp_stats.php 47 KB

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