lp_stats.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947
  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. require_once '../exercice/exercise.lib.php';
  16. $course_code = api_get_course_id();
  17. if (empty($user_id)) {
  18. $user_id = api_get_user_id();
  19. }
  20. // Declare variables to be used in lp_stats.php
  21. //When checking the reporting myspace/lp_tracking.php
  22. //isset($_GET['lp_id']) &&
  23. if (isset($lp_id) && !empty($lp_id)) {
  24. $lp_id = intval($lp_id);
  25. if (!isset($list)) {
  26. $list = learnpath::get_flat_ordered_items_list($lp_id);
  27. }
  28. } else {
  29. if (isset($_SESSION['oLP'])) {
  30. $lp_id = $_SESSION['oLP']->get_id();
  31. $list = learnpath::get_flat_ordered_items_list($lp_id);
  32. }
  33. }
  34. $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
  35. if (isset($_GET['course'])) {
  36. $course_code = Security::remove_XSS($_GET['course']);
  37. }
  38. $course_info = api_get_course_info($course_code);
  39. $course_id = $course_info['real_id'];
  40. if (isset($_GET['student_id'])) {
  41. $student_id = intval($_GET['student_id']);
  42. }
  43. $session_id = api_get_session_id();
  44. $session_condition = api_get_session_condition($session_id);
  45. //When origin is not set that means that the lp_stats are viewed from the "man running" icon
  46. if (!isset($origin)) {
  47. $origin = 'learnpath';
  48. }
  49. //Origin = tracking means that teachers see that info in the Reporting tool
  50. if ($origin != 'tracking') {
  51. Display::display_reduced_header();
  52. }
  53. $output = '';
  54. //Extend all button
  55. $extend_all_link = '';
  56. $extend_all = 0;
  57. if ($origin == 'tracking') {
  58. $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;
  59. } else {
  60. $url_suffix = '&lp_id=' . $lp_id;
  61. }
  62. if (!empty($_GET['extend_all'])) {
  63. $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>';
  64. $extend_all = 1;
  65. } else {
  66. $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>';
  67. }
  68. if ($origin != 'tracking') {
  69. $output .= Display::page_header(get_lang('ScormMystatus'));
  70. }
  71. $output .= '<table class="data_table">
  72. <tr>
  73. <th width="16">' . $extend_all_link . '</th>
  74. <th colspan="4">
  75. ' . get_lang('ScormLessonTitle') .'
  76. </th>
  77. <th colspan="2">
  78. ' . get_lang('ScormStatus') . '
  79. </th>
  80. <th colspan="2">
  81. ' . get_lang('ScormScore') . '
  82. </th>
  83. <th colspan="2">
  84. ' . get_lang('ScormTime') . '
  85. </th>
  86. <th>
  87. ' . get_lang('Actions') . '
  88. </th>
  89. </tr>';
  90. // Going through the items using the $items[] array instead of the database order ensures
  91. // we get them in the same order as in the imsmanifest file, which is rather random when using
  92. // the database table.
  93. $TBL_LP_ITEM = Database :: get_course_table(TABLE_LP_ITEM);
  94. $TBL_LP_ITEM_VIEW = Database :: get_course_table(TABLE_LP_ITEM_VIEW);
  95. $TBL_LP_VIEW = Database :: get_course_table(TABLE_LP_VIEW);
  96. $tbl_quiz_questions = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  97. $TBL_QUIZ = Database :: get_course_table(TABLE_QUIZ_TEST);
  98. $tbl_stats_exercices = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  99. $tbl_stats_attempts = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  100. $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";
  101. $res = Database::query($sql);
  102. $view = '';
  103. $num = 0;
  104. if (Database :: num_rows($res) > 0) {
  105. $myrow = Database :: fetch_array($res);
  106. $view = $myrow[0];
  107. }
  108. $counter = 0;
  109. $total_score = 0;
  110. $total_time = 0;
  111. $h = get_lang('h');
  112. if (!empty($export_csv)) {
  113. $csv_content[] = array(
  114. get_lang('ScormLessonTitle'),
  115. get_lang('ScormStatus'),
  116. get_lang('ScormScore'),
  117. get_lang('ScormTime')
  118. );
  119. }
  120. // Get attempts of a exercise.
  121. if (isset($_GET['lp_id']) && isset($_GET['lp_item_id'])) {
  122. $clean_lp_item_id = Database::escape_string($_GET['lp_item_id']);
  123. $clean_lp_id = Database::escape_string($_GET['lp_id']);
  124. $clean_course_code = Database :: escape_string($course_code);
  125. $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'";
  126. $res_path = Database::query($sql_path);
  127. $row_path = Database::fetch_array($res_path);
  128. if (Database::num_rows($res_path) > 0) {
  129. if ($origin != 'tracking') {
  130. $sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . '
  131. WHERE exe_exo_id="' . (int) $row_path['path'] . '" AND
  132. status <> "incomplete" AND
  133. exe_user_id="' . api_get_user_id() . '" AND
  134. orig_lp_id = "' . (int) $clean_lp_id . '" AND
  135. orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND
  136. exe_cours_id="' . $clean_course_code . '" AND
  137. session_id = ' . $session_id . '
  138. ORDER BY exe_date';
  139. } else {
  140. $sql_attempts = 'SELECT * FROM ' . $tbl_stats_exercices . '
  141. WHERE exe_exo_id="' . (int) $row_path['path'] . '" AND
  142. status <> "incomplete" AND
  143. exe_user_id="' . $student_id . '" AND
  144. orig_lp_id = "' . (int) $clean_lp_id . '" AND
  145. orig_lp_item_id = "' . (int) $clean_lp_item_id . '" AND
  146. exe_cours_id="' . $clean_course_code . '" AND
  147. session_id = ' . $session_id . '
  148. ORDER BY exe_date';
  149. }
  150. }
  151. //var_dump($sql_attempts);
  152. }
  153. //Show lp items
  154. if (is_array($list) && count($list) > 0) {
  155. foreach ($list as $my_item_id) {
  156. $extend_this = 0;
  157. $qry_order = 'DESC';
  158. if ((!empty($_GET['extend_id']) && $_GET['extend_id'] == $my_item_id) || $extend_all) {
  159. $extend_this = 1;
  160. $qry_order = 'ASC';
  161. }
  162. // Prepare statement to go through each attempt.
  163. if (!empty($view)) {
  164. $sql = "SELECT iv.status as mystatus,
  165. v.view_count as mycount,
  166. iv.score as myscore,
  167. iv.total_time as mytime,
  168. i.id as myid,
  169. i.lp_id as mylpid,
  170. iv.lp_view_id as mylpviewid,
  171. i.title as mytitle,
  172. i.max_score as mymaxscore,
  173. iv.max_score as myviewmaxscore,
  174. i.item_type as item_type,
  175. iv.view_count as iv_view_count,
  176. iv.id as iv_id,
  177. path
  178. FROM $TBL_LP_ITEM as i
  179. 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)
  180. INNER JOIN $TBL_LP_VIEW as v ON (iv.lp_view_id = v.id AND v.c_id = $course_id)
  181. WHERE
  182. i.id = $my_item_id AND
  183. i.lp_id = $lp_id AND
  184. v.user_id = $user_id AND
  185. v.view_count = $view AND
  186. v.session_id = $session_id
  187. ORDER BY iv.view_count $qry_order ";
  188. //var_dump($sql);
  189. } else {
  190. $sql = "SELECT iv.status as mystatus,
  191. v.view_count as mycount,
  192. iv.score as myscore,
  193. iv.total_time as mytime,
  194. i.id as myid,
  195. i.lp_id as mylpid,
  196. iv.lp_view_id as mylpviewid,
  197. i.title as mytitle,
  198. i.max_score as mymaxscore,
  199. iv.max_score as myviewmaxscore,
  200. i.item_type as item_type,
  201. iv.view_count as iv_view_count,
  202. iv.id as iv_id,
  203. path
  204. FROM $TBL_LP_ITEM as i
  205. 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)
  206. INNER JOIN $TBL_LP_VIEW as v ON (iv.lp_view_id = v.id AND v.c_id = $course_id)
  207. WHERE
  208. i.id = $my_item_id AND
  209. i.lp_id = $lp_id AND
  210. v.user_id = $user_id AND
  211. v.session_id = $session_id
  212. ORDER BY iv.view_count $qry_order ";
  213. }
  214. $result = Database::query($sql);
  215. $num = Database :: num_rows($result);
  216. $time_for_total = 'NaN';
  217. //Extend all + extend scorm?
  218. if (($extend_this || $extend_all) && $num > 0) {
  219. $row = Database :: fetch_array($result);
  220. $result_disabled_ext_all = false;
  221. if ($row['item_type'] == 'quiz') {
  222. // Check results_disabled in quiz table.
  223. $my_path = Database::escape_string($row['path']);
  224. $sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE c_id = $course_id AND id ='" . $my_path . "'";
  225. $res_result_disabled = Database::query($sql);
  226. $row_result_disabled = Database::fetch_row($res_result_disabled);
  227. if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) {
  228. $result_disabled_ext_all = true;
  229. }
  230. }
  231. // If there are several attempts, and the link to extend has been clicked, show each attempt...
  232. if (($counter % 2) == 0) {
  233. $oddclass = 'row_odd';
  234. } else {
  235. $oddclass = 'row_even';
  236. }
  237. $extend_link = '';
  238. if (!empty($inter_num)) {
  239. $extend_link = '<a href="' . api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix . '">
  240. <img src="../img/visible.gif" alt="' . get_lang('HideAttemptView') . '" title="' . get_lang('HideAttemptView') . '" border="0"></a>';
  241. }
  242. $title = $row['mytitle'];
  243. if (empty($title)) {
  244. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  245. }
  246. if ($row['item_type'] != 'dokeos_chapter') {
  247. $correct_test_link = '-';
  248. $title = Security::remove_XSS($title);
  249. $output .= '<tr class="'.$oddclass.'">
  250. <td>'.$extend_link.'</td>
  251. <td colspan="4">
  252. '.$title.'
  253. </td>
  254. <td colspan="2"></td>
  255. <td colspan="2"></td>
  256. <td colspan="2"></td>
  257. <td></td>
  258. </tr>';
  259. }
  260. $counter++;
  261. do {
  262. // Check if there are interactions below.
  263. $extend_attempt_link = '';
  264. $extend_this_attempt = 0;
  265. 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) {
  266. if (!empty($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  267. // The extend button for this attempt has been clicked.
  268. $extend_this_attempt = 1;
  269. $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>';
  270. } else { // Same case if fold_attempt_id is set, so not implemented explicitly.
  271. // The extend button for this attempt has not been clicked.
  272. $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>';
  273. }
  274. }
  275. if (($counter % 2) == 0) {
  276. $oddclass = 'row_odd';
  277. } else {
  278. $oddclass = 'row_even';
  279. }
  280. $lesson_status = $row['mystatus'];
  281. $score = $row['myscore'];
  282. $time_for_total = $row['mytime'];
  283. $time = learnpathItem :: get_scorm_time('js', $row['mytime']);
  284. $scoIdentifier = $row['myid'];
  285. if ($score == 0) {
  286. $maxscore = $row['mymaxscore'];
  287. } else {
  288. if ($row['item_type'] == 'sco') {
  289. if (!empty($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) {
  290. $maxscore = $row['myviewmaxscore'];
  291. } elseif ($row['myviewmaxscore'] === '') {
  292. $maxscore = 0;
  293. } else {
  294. $maxscore = $row['mymaxscore'];
  295. }
  296. } else {
  297. $maxscore = $row['mymaxscore'];
  298. }
  299. }
  300. // Remove "NaN" if any (@todo: locate the source of these NaN)
  301. $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
  302. if ($row['item_type'] != 'dokeos_chapter') {
  303. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  304. $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  305. } else {
  306. switch ($row['item_type']) {
  307. case 'sco':
  308. if ($maxscore == 0) {
  309. $view_score = $score;
  310. } else {
  311. $view_score = show_score($score, $maxscore, false);
  312. }
  313. break;
  314. case 'document':
  315. $view_score = ($score == 0 ? '/' : show_score($score, $maxscore, false));
  316. break;
  317. default:
  318. $view_score = show_score($score, $maxscore, false);
  319. break;
  320. }
  321. }
  322. $output .= '<tr class="' . $oddclass . '">
  323. <td></td>
  324. <td>' . $extend_attempt_link . '</td>
  325. <td colspan="3">' . get_lang('Attempt') . ' ' . $row['iv_view_count'] . '</td>
  326. <td colspan="2">' . learnpathItem::humanize_status($lesson_status) . '</td>
  327. <td colspan="2">' . $view_score . '</td>
  328. <td colspan="2">' . $time . '</td>
  329. <td></td>
  330. </tr>';
  331. if (!empty($export_csv)) {
  332. $temp = array();
  333. $temp[] = $title = Security::remove_XSS($title);
  334. $temp[] = Security::remove_XSS(learnpathItem::humanize_status($lesson_status, false));
  335. if ($row['item_type'] == 'quiz') {
  336. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  337. $temp[] = '/';
  338. } else {
  339. $temp[] = ($score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . Text::float_format($maxscore, 1)));
  340. }
  341. } else {
  342. $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . Text::float_format($maxscore, 1)));
  343. }
  344. $temp[] = $time;
  345. $csv_content[] = $temp;
  346. }
  347. }
  348. $counter++;
  349. if ($extend_this_attempt OR $extend_all) {
  350. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  351. foreach ($list1 as $id => $interaction) {
  352. if (($counter % 2) == 0) {
  353. $oddclass = 'row_odd';
  354. } else {
  355. $oddclass = 'row_even';
  356. }
  357. $student_response = urldecode($interaction['student_response']); // Code added by Isaac Flores.
  358. $content_student_response = array();
  359. $content_student_response = explode('__|', $student_response);
  360. if (count($content_student_response) > 0) {
  361. if (count($content_student_response) >= 3) {
  362. $new_content_student_response = array_pop($content_student_response); // Pop the element off the end of array.
  363. }
  364. $student_response = implode(',', $content_student_response);
  365. }
  366. $output .= '<tr class="'.$oddclass.'">
  367. <td></td>
  368. <td></td>
  369. <td></td>
  370. <td>'.$interaction['order_id'] . '</td>
  371. <td>'.$interaction['id'] . '</td>
  372. <td colspan="2">' . $interaction['type'].'</td>
  373. <td>'.$student_response . '</td>
  374. <td>'.$interaction['result'] . '</td>
  375. <td>'.$interaction['latency'] . '</td>
  376. <td>'.$interaction['time'] . '</td>
  377. <td></td>
  378. </tr>';
  379. $counter++;
  380. }
  381. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  382. foreach ($list2 as $id => $interaction) {
  383. if (($counter % 2) == 0) {
  384. $oddclass = 'row_odd';
  385. } else {
  386. $oddclass = 'row_even';
  387. }
  388. $output .= '<tr class="'.$oddclass.'">
  389. <td></td>
  390. <td></td>
  391. <td></td>
  392. <td>' . $interaction['order_id'] . '</td>
  393. <td colspan="2">' . $interaction['objective_id'] . '</td>
  394. <td colspan="2">' . $interaction['status'] .'</td>
  395. <td>' . $interaction['score_raw'] . '</td>
  396. <td>' . $interaction['score_max'] . '</td>
  397. <td>' . $interaction['score_min'] . '</td>
  398. <td></td>
  399. </tr>';
  400. $counter++;
  401. }
  402. }
  403. } while ($row = Database :: fetch_array($result));
  404. } elseif ($num > 0) {
  405. //Not extended
  406. $row = Database :: fetch_array($result, 'ASSOC');
  407. $my_id = $row['myid'];
  408. $my_lp_id = $row['mylpid'];
  409. $my_lp_view_id = $row['mylpviewid'];
  410. $my_path = $row['path'];
  411. $result_disabled_ext_all = false;
  412. if ($row['item_type'] == 'quiz') {
  413. // Check results_disabled in quiz table.
  414. $my_path = Database::escape_string($my_path);
  415. $sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE c_id = $course_id AND id ='" . (int) $my_path . "'";
  416. $res_result_disabled = Database::query($sql);
  417. $row_result_disabled = Database::fetch_row($res_result_disabled);
  418. if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) {
  419. $result_disabled_ext_all = true;
  420. }
  421. }
  422. // Check if there are interactions below
  423. $extend_this_attempt = 0;
  424. $inter_num = learnpath::get_interactions_count_from_db($row['iv_id'], $course_id);
  425. $objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id);
  426. $extend_attempt_link = '';
  427. if (($inter_num > 0 || $objec_num > 0)) {
  428. if (!empty($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  429. // The extend button for this attempt has been clicked.
  430. $extend_this_attempt = 1;
  431. $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";
  432. } else { // Same case if fold_attempt_id is set, so not implemented explicitly.
  433. // The extend button for this attempt has not been clicked.
  434. $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";
  435. }
  436. }
  437. if (($counter % 2) == 0) {
  438. $oddclass = 'row_odd';
  439. } else {
  440. $oddclass = 'row_even';
  441. }
  442. $extend_link = '';
  443. if ($inter_num > 1) {
  444. $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>';
  445. }
  446. $lesson_status = $row['mystatus'];
  447. $score = $row['myscore'];
  448. $subtotal_time = $row['mytime'];
  449. while ($tmp_row = Database :: fetch_array($result)) {
  450. $subtotal_time += $tmp_row['mytime'];
  451. }
  452. $scoIdentifier = $row['myid'];
  453. $title = $row['mytitle'];
  454. // Selecting the exe_id from stats attempts tables in order to look the max score value.
  455. if ($origin != 'tracking') {
  456. $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
  457. WHERE exe_exo_id="' . $row['path'] . '" AND
  458. exe_user_id="' . api_get_user_id() . '" AND
  459. orig_lp_id = "' . $lp_id . '" AND
  460. orig_lp_item_id = "' . $row['myid'] . '" AND
  461. exe_cours_id="' . $course_code . '" AND
  462. status <> "incomplete" AND
  463. session_id = ' . $session_id . '
  464. ORDER BY exe_date DESC limit 1';
  465. } else {
  466. $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
  467. WHERE exe_exo_id="' . $row['path'] . '" AND
  468. exe_user_id="' . $student_id . '" AND
  469. orig_lp_id = "' . $lp_id . '" AND
  470. orig_lp_item_id = "' . $row['myid'] . '" AND
  471. exe_cours_id="' . $course_code . '" AND
  472. status <> "incomplete" AND
  473. session_id = ' . $session_id . '
  474. ORDER BY exe_date DESC limit 1';
  475. }
  476. $resultLastAttempt = Database::query($sql_last_attempt);
  477. $num = Database :: num_rows($resultLastAttempt);
  478. if ($num > 0) {
  479. while ($rowLA = Database :: fetch_array($resultLastAttempt)) {
  480. $id_last_attempt = $rowLA['exe_id'];
  481. }
  482. }
  483. //var_dump($row['path'] .' '.$score);
  484. if ($score == 0) {
  485. $maxscore = $row['mymaxscore'];
  486. } else {
  487. if ($row['item_type'] == 'sco') {
  488. if (!empty($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) {
  489. $maxscore = $row['myviewmaxscore'];
  490. } elseif ($row['myviewmaxscore'] === '') {
  491. $maxscore = 0;
  492. } else {
  493. $maxscore = $row['mymaxscore'];
  494. }
  495. } else {
  496. if ($row['item_type'] == 'quiz') {
  497. // Get score and total time from last attempt of a exercise en lp.
  498. $sql = "SELECT score FROM $TBL_LP_ITEM_VIEW
  499. WHERE c_id = $course_id AND lp_item_id = '" . (int) $my_id . "' AND lp_view_id = '" . (int) $my_lp_view_id . "'
  500. ORDER BY view_count DESC limit 1";
  501. $res_score = Database::query($sql);
  502. $row_score = Database::fetch_array($res_score);
  503. $sql = "SELECT SUM(total_time) as total_time FROM $TBL_LP_ITEM_VIEW
  504. WHERE c_id = $course_id AND lp_item_id = '" . (int) $my_id . "' AND lp_view_id = '" . (int) $my_lp_view_id . "'";
  505. $res_time = Database::query($sql);
  506. $row_time = Database::fetch_array($res_time);
  507. if (Database::num_rows($res_score) > 0 && Database::num_rows($res_time) > 0) {
  508. $score = (float) $row_score['score'];
  509. $subtotal_time = (int) $row_time['total_time'];
  510. } else {
  511. $score = 0;
  512. $subtotal_time = 0;
  513. }
  514. //echo $subtotal_time ;
  515. //$time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  516. // Selecting the max score from an attempt.
  517. $sql = "SELECT SUM(t.ponderation) as maxscore
  518. FROM (
  519. SELECT distinct question_id, marks, ponderation
  520. FROM $tbl_stats_attempts as at INNER JOIN $tbl_quiz_questions as q
  521. ON (q.id = at.question_id AND q.c_id = $course_id
  522. )
  523. WHERE exe_id ='$id_last_attempt' ) as t";
  524. $result = Database::query($sql);
  525. $row_max_score = Database :: fetch_array($result);
  526. $maxscore = $row_max_score['maxscore'];
  527. } else {
  528. $maxscore = $row['mymaxscore'];
  529. }
  530. }
  531. }
  532. $time_for_total = $subtotal_time;
  533. $time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  534. if (empty($title)) {
  535. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  536. }
  537. // Remove "NaN" if any (@todo: locate the source of these NaN)
  538. //$time = str_replace('NaN', '00'.$h.'00\'00"', $time);
  539. if ($row['item_type'] != 'dokeos_chapter') {
  540. if ($row['item_type'] == 'quiz') {
  541. $correct_test_link = '';
  542. $my_url_suffix = '';
  543. if ($origin != 'tracking' && $origin != 'tracking_course') {
  544. $my_url_suffix = '&course=' . api_get_course_id() . '&student_id=' . api_get_user_id() . '&lp_id=' . Security::remove_XSS($row['mylpid']);
  545. $sql_last_attempt = 'SELECT * FROM ' . $tbl_stats_exercices . '
  546. WHERE exe_exo_id="' . $row['path'] . '" AND
  547. exe_user_id="' . api_get_user_id() . '" AND
  548. orig_lp_id = "' . $lp_id . '" AND
  549. orig_lp_item_id = "' . $row['myid'] . '" AND
  550. exe_cours_id="' . $course_code . '" AND
  551. status <> "incomplete" AND
  552. session_id = ' . $session_id . '
  553. ORDER BY exe_date DESC ';
  554. } else {
  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. exe_cours_id="' . Database :: escape_string($_GET['course']) . '" 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 .= 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 = show_score(0, $my_maxscore, false);
  715. } else {
  716. if ($my_maxscore == 0) {
  717. $view_score = $my_score;
  718. } else {
  719. $view_score = 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. //var_dump($my_studen_id, $my_course_id,$a_my_id);
  779. if (isset($_GET['extend_attempt'])) {
  780. //"Right green cross" extended
  781. $total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id, api_get_session_id(), false, false);
  782. } else {
  783. //"Left green cross" extended
  784. $total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id, api_get_session_id(), false, true);
  785. }
  786. } else {
  787. // Extend all "left green cross"
  788. if ($origin == 'tracking') {
  789. $my_course_id = Database::escape_string($_GET['course']);
  790. // var_dump($student_id, $my_course_id );
  791. if (!empty($student_id) && !empty($my_course_id)) {
  792. $total_score = Tracking::get_avg_student_score($student_id, $my_course_id, array(intval($_GET['lp_id'])), api_get_session_id(), false, false);
  793. } else {
  794. $total_score = 0;
  795. }
  796. } else {
  797. $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);
  798. }
  799. }
  800. $total_time = learnpathItem :: get_scorm_time('js', $total_time);
  801. //$total_time = str_replace('NaN', '00:00:00' ,$total_time);
  802. $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
  803. //$lp_type = learnpath :: get_type_static($lp_id);
  804. //$total_percent = 0;
  805. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  806. $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
  807. } else {
  808. if (is_numeric($total_score))
  809. $final_score = $total_score . '%';
  810. else
  811. $final_score = $total_score;
  812. }
  813. if (($counter % 2) == 0) {
  814. $oddclass = 'row_odd';
  815. } else {
  816. $oddclass = 'row_even';
  817. }
  818. //if (empty($extend_all)) {
  819. $output .= '<tr class="'.$oddclass.'">
  820. <td></td>
  821. <td colspan="4">
  822. <i>' . get_lang('AccomplishedStepsTotal') .'</i>
  823. </td>
  824. <td colspan="2"></td>
  825. <td colspan="2">
  826. ' . $final_score.'
  827. </td>
  828. <td colspan="2">' . $total_time . '</div><td></td>
  829. </tr>';
  830. //}
  831. $output .= "</table>";
  832. if (!empty($export_csv)) {
  833. $temp = array(
  834. '',
  835. '',
  836. '',
  837. ''
  838. );
  839. $csv_content[] = $temp;
  840. $temp = array(
  841. get_lang('AccomplishedStepsTotal'),
  842. '',
  843. $final_score,
  844. $total_time
  845. );
  846. $csv_content[] = $temp;
  847. ob_end_clean();
  848. Export :: export_table_csv($csv_content, 'reporting_learning_path_details');
  849. exit;
  850. }
  851. if ($origin != 'tracking') {
  852. $output .= "</body></html>";
  853. }
  854. if (empty($export_csv)) {
  855. echo $output;
  856. }
  857. Display::display_footer();