lp_stats.php 37 KB

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