lp_stats.php 47 KB

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