lp_stats.php 49 KB

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