lp_stats.php 35 KB

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