lp_stats.php 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  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, __FILE__, __LINE__);
  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, __FILE__, __LINE__);
  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,__FILE__,__LINE__);
  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. }
  130. }
  131. $TBL_QUIZ = Database :: get_course_table(TABLE_QUIZ_TEST);
  132. if (is_array($list) && count($list) > 0){
  133. foreach ($list as $my_item_id) {
  134. $extend_this = 0;
  135. $qry_order = 'DESC';
  136. if ((!empty ($_GET['extend_id']) and $_GET['extend_id'] == $my_item_id) OR $extend_all) {
  137. $extend_this = 1;
  138. $qry_order = 'ASC';
  139. }
  140. //prepare statement to go through each attempt
  141. if (!empty ($view)) {
  142. $sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
  143. "iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, iv.lp_view_id as mylpviewid, " .
  144. "i.title as mytitle, i.max_score as mymaxscore, " .
  145. "iv.max_score as myviewmaxscore, " .
  146. "i.item_type as item_type, iv.view_count as iv_view_count, " .
  147. "iv.id as iv_id, path as path" .
  148. " FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v" .
  149. " WHERE i.id = iv.lp_item_id " .
  150. " AND i.id = $my_item_id " .
  151. " AND iv.lp_view_id = v.id " .
  152. " AND i.lp_id = $lp_id " .
  153. " AND v.user_id = " . $user_id . " " .
  154. " AND v.view_count = $view " .
  155. " ORDER BY iv.view_count $qry_order ";
  156. } else {
  157. $sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
  158. "iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, iv.lp_view_id as mylpviewid, " .
  159. "i.title as mytitle, i.max_score as mymaxscore, " .
  160. "iv.max_score as myviewmaxscore, " .
  161. "i.item_type as item_type, iv.view_count as iv_view_count, " .
  162. "iv.id as iv_id, path as path " .
  163. " FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v " .
  164. " WHERE i.id = iv.lp_item_id " .
  165. " AND i.id = $my_item_id " .
  166. " AND iv.lp_view_id = v.id " .
  167. " AND i.lp_id = $lp_id " .
  168. " AND v.user_id = " . $user_id . " " .
  169. " ORDER BY iv.view_count $qry_order ";
  170. }
  171. $result = Database::query($sql, __FILE__, __LINE__);
  172. $num = Database :: num_rows($result);
  173. $time_for_total = 'NaN';
  174. if (($extend_this || $extend_all) && $num > 0) {
  175. $row = Database :: fetch_array($result);
  176. $result_disabled_ext_all = false;
  177. if($row['item_type'] == 'quiz') {
  178. //check results_disabled in quiz table
  179. $my_path = Database::escape_string($row['path']);
  180. $sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE id ='".(int)$my_path."'";
  181. $res_result_disabled = Database::query($sql,__FILE__,__LINE__);
  182. $row_result_disabled = Database::fetch_row($res_result_disabled);
  183. if (Database::num_rows($res_result_disabled) > 0 && (int)$row_result_disabled[0]===1) {
  184. $result_disabled_ext_all = true;
  185. }
  186. }
  187. //echo '<br><pre>'; print_r($row); echo '</pre><br>';
  188. //if there are several attempts, and the link to extend has been clicked, show each attempt...
  189. if (($counter % 2) == 0) {
  190. $oddclass = "row_odd";
  191. } else {
  192. $oddclass = "row_even";
  193. }
  194. $extend_link='';
  195. if (!empty($inter_num)) {
  196. $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";
  197. }
  198. $title = $row['mytitle'];
  199. if (empty ($title)) {
  200. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  201. }
  202. if ($row['item_type'] != 'dokeos_chapter') {
  203. $correct_test_link = '-';
  204. //api_convert_encoding($title, $lp_charset, $lp_charset)
  205. $title = Security::remove_XSS($title);
  206. $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";
  207. }
  208. $counter++;
  209. do {
  210. //check if there are interactions below
  211. $extend_attempt_link = '';
  212. $extend_this_attempt = 0;
  213. if ((learnpath :: get_interactions_count_from_db($row['iv_id']) > 0 || learnpath :: get_objectives_count_from_db($row['iv_id']) > 0) && !$extend_all) {
  214. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  215. //the extend button for this attempt has been clicked
  216. $extend_this_attempt = 1;
  217. $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";
  218. } else { //same case if fold_attempt_id is set, so not implemented explicitly
  219. //the extend button for this attempt has not been clicked
  220. $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";
  221. }
  222. }
  223. if (($counter % 2) == 0) {
  224. $oddclass = "row_odd";
  225. } else {
  226. $oddclass = "row_even";
  227. }
  228. $lesson_status = $row['mystatus'];
  229. $score = $row['myscore'];
  230. $time_for_total = $row['mytime'];
  231. $time = learnpathItem :: get_scorm_time('js', $row['mytime']);
  232. $type;
  233. $scoIdentifier = $row['myid'];
  234. if ($score == 0) {
  235. $maxscore = $row['mymaxscore'];
  236. } else {
  237. if ($row['item_type'] == 'sco') {
  238. if (!empty ($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) {
  239. $maxscore = $row['myviewmaxscore'];
  240. }
  241. elseif ($row['myviewmaxscore'] === '') {
  242. $maxscore = 0;
  243. } else {
  244. $maxscore = $row['mymaxscore'];
  245. }
  246. }
  247. else
  248. {
  249. $maxscore = $row['mymaxscore'];
  250. }
  251. }
  252. //Remove "NaN" if any (@todo: locate the source of these NaN)
  253. $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
  254. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  255. $color = 'green';
  256. } else {
  257. $color = 'black';
  258. }
  259. $mylanglist = array (
  260. 'completed' => 'ScormCompstatus',
  261. 'incomplete' => 'ScormIncomplete',
  262. 'failed' => 'ScormFailed',
  263. 'passed' => 'ScormPassed',
  264. 'browsed' => 'ScormBrowsed',
  265. 'not attempted' => 'ScormNotAttempted',
  266. );
  267. $my_lesson_status = api_convert_encoding(get_lang($mylanglist[$lesson_status]), $lp_charset, $dokeos_charset);
  268. $is_allowed_to_edit = api_is_allowed_to_edit(null,true);
  269. if ($row['item_type'] != 'dokeos_chapter') {
  270. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  271. $view_score = '/';
  272. } else {
  273. $view_score = ($score == 0 ? '/' : ($maxscore === 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  274. }
  275. $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"
  276. //."<td><font color='$color'><div class='mystatus'>".api_htmlentities($array_status[$lesson_status],ENT_QUOTES,$lp_charset)."</div></font></td>\n"
  277. . '<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>';
  278. if (!empty($export_csv)) {
  279. $temp = array ();
  280. $temp[] = $title = Security::remove_XSS($title);
  281. $temp[] = Security::remove_XSS($my_lesson_status);
  282. if ($row['item_type'] == 'quiz') {
  283. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  284. $temp[] = '/';
  285. } else {
  286. $temp[] = ($score == 0 ? '0/'.$maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  287. }
  288. } else {
  289. $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  290. }
  291. $temp[] = $time;
  292. $csv_content[] = $temp;
  293. }
  294. }
  295. $counter++;
  296. if ($extend_this_attempt OR $extend_all) {
  297. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  298. foreach ($list1 as $id => $interaction) {
  299. if (($counter % 2) == 0) {
  300. $oddclass = "row_odd";
  301. } else {
  302. $oddclass = "row_even";
  303. }
  304. $student_response=urldecode($interaction['student_response']);//code added by isaac flores
  305. $content_student_response=array();
  306. $content_student_response=explode('__|',$student_response);
  307. if (count($content_student_response)>0) {
  308. if (count($content_student_response)>=3) {
  309. $new_content_student_response=array_pop($content_student_response);//Pop the element off the end of array
  310. }
  311. $student_response=implode(',',$content_student_response);
  312. }
  313. $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"
  314. //."<td><font color='$color'><div class='mystatus'>".api_convert_encoding($array_status[$lesson_status],$lp_charset,$lp_charset)."</div></font></td>\n"
  315. . '<td colspan="2">' . $interaction['type'] . "</td>\n"
  316. //.'<td>'.$interaction['correct_responses']."</td>\n"
  317. . '<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";
  318. $counter++;
  319. }
  320. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  321. foreach ($list2 as $id => $interaction) {
  322. if (($counter % 2) == 0) {
  323. $oddclass = "row_odd";
  324. } else {
  325. $oddclass = "row_even";
  326. }
  327. $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" .
  328. '<td colspan="2">' . $interaction['status'] . "</td>\n" .
  329. '<td>' . $interaction['score_raw'] . "</td>\n" . '<td>' . $interaction['score_max'] . "</td>\n" . '<td>' . $interaction['score_min'] . "</td>\n<td></td>\n</tr>\n";
  330. $counter++;
  331. }
  332. }
  333. } while ($row = Database :: fetch_array($result));
  334. }
  335. elseif ($num > 0) {
  336. $row = Database :: fetch_array($result);
  337. $my_id = $row['myid'];
  338. $my_lp_id = $row['mylpid'];
  339. $my_lp_view_id = $row['mylpviewid'];
  340. $my_path = $row['path'];
  341. $result_disabled_ext_all = false;
  342. if($row['item_type'] == 'quiz') {
  343. //check results_disabled in quiz table
  344. $my_path = Database::escape_string($my_path);
  345. $sql = "SELECT results_disabled FROM $TBL_QUIZ WHERE id ='".(int)$my_path."'";
  346. $res_result_disabled = Database::query($sql,__FILE__,__LINE__);
  347. $row_result_disabled = Database::fetch_row($res_result_disabled);
  348. if (Database::num_rows($res_result_disabled) > 0 && (int)$row_result_disabled[0]===1) {
  349. $result_disabled_ext_all = true;
  350. }
  351. }
  352. //check if there are interactions below
  353. $extend_attempt_link = '';
  354. $extend_this_attempt = 0;
  355. $inter_num = learnpath :: get_interactions_count_from_db($row['iv_id']);
  356. $objec_num = learnpath :: get_objectives_count_from_db($row['iv_id']);
  357. if (($inter_num > 0 || $objec_num > 0) && !$extend_all) {
  358. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  359. //the extend button for this attempt has been clicked
  360. $extend_this_attempt = 1;
  361. $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";
  362. } else { //same case if fold_attempt_id is set, so not implemented explicitly
  363. //the extend button for this attempt has not been clicked
  364. $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";
  365. }
  366. }
  367. if (($counter % 2) == 0) {
  368. $oddclass = "row_odd";
  369. } else {
  370. $oddclass = "row_even";
  371. }
  372. //$extend_link = '<img src="../img/invisible.gif" alt="extend_disabled">';
  373. $extend_link = '';
  374. if ($inter_num > 1) {
  375. $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>';
  376. }
  377. if (($counter % 2) == 0) {
  378. $oddclass = "row_odd";
  379. } else {
  380. $oddclass = "row_even";
  381. }
  382. $lesson_status = $row['mystatus'];
  383. $score = $row['myscore'];
  384. $subtotal_time = $row['mytime'];
  385. //if($row['mytime']==0){
  386. while ($tmp_row = Database :: fetch_array($result)) {
  387. $subtotal_time += $tmp_row['mytime'];
  388. }
  389. //}
  390. //$time_for_total = $subtotal_time;
  391. //$time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  392. $scoIdentifier = $row['myid'];
  393. $title = $row['mytitle'];
  394. // selecting the exe_id from stats attempts tables in order to look the max score value
  395. if ($origin != 'tracking') {
  396. $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';
  397. } else {
  398. $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';
  399. }
  400. $resultLastAttempt = Database::query($sql_last_attempt, __FILE__, __LINE__);
  401. $num = Database :: num_rows($resultLastAttempt);
  402. if ($num > 0) {
  403. while ($rowLA = Database :: fetch_array($resultLastAttempt)) {
  404. $id_last_attempt = $rowLA['exe_id'];
  405. }
  406. }
  407. if ($score == 0)
  408. {
  409. $maxscore = $row['mymaxscore'];
  410. }
  411. else
  412. {
  413. if ($row['item_type'] == 'sco')
  414. {
  415. if (!empty ($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) {
  416. $maxscore = $row['myviewmaxscore'];
  417. }
  418. elseif ($row['myviewmaxscore'] === '') {
  419. $maxscore = 0;
  420. } else {
  421. $maxscore = $row['mymaxscore'];
  422. }
  423. }
  424. else
  425. {
  426. if ($row['item_type'] == 'quiz')
  427. {
  428. // get score and total time from last attempt of a exercise en lp
  429. $sql = "SELECT score FROM $TBL_LP_ITEM_VIEW WHERE lp_item_id = '".(int)$my_id."' and lp_view_id = '".(int)$my_lp_view_id."'
  430. ORDER BY view_count DESC limit 1";
  431. $res_score = Database::query($sql,__FILE__,__LINE__);
  432. $row_score = Database::fetch_array($res_score);
  433. $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."'";
  434. $res_time = Database::query($sql,__FILE__,__LINE__);
  435. $row_time = Database::fetch_array($res_time);
  436. if (Database::num_rows($res_score) > 0 && Database::num_rows($res_time) > 0) {
  437. $score = (float)$row_score['score'];
  438. $subtotal_time = (int)$row_time['total_time'];
  439. } else {
  440. $score = 0;
  441. $subtotal_time = 0;
  442. }
  443. //$time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  444. // selecting the max score from an attempt
  445. $sql = "SELECT SUM(t.ponderation) as maxscore from ( SELECT distinct question_id, marks,ponderation FROM $tbl_stats_attempts as at " .
  446. "INNER JOIN $tbl_quiz_questions as q on(q.id = at.question_id) where exe_id ='$id_last_attempt' ) as t";
  447. $result = Database::query($sql, __FILE__, __LINE__);
  448. $row_max_score = Database :: fetch_array($result);
  449. $maxscore = $row_max_score['maxscore'];
  450. }
  451. else
  452. {
  453. $maxscore = $row['mymaxscore'];
  454. }
  455. }
  456. }
  457. $time_for_total = $subtotal_time;
  458. $time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  459. if (empty ($title)) {
  460. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  461. }
  462. //Remove "NaN" if any (@todo: locate the source of these NaN)
  463. //$time = str_replace('NaN', '00'.$h.'00\'00"', $time);
  464. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  465. $color = 'green';
  466. } else {
  467. $color = 'black';
  468. }
  469. $mylanglist = array (
  470. 'completed' => 'ScormCompstatus',
  471. 'incomplete' => 'ScormIncomplete',
  472. 'failed' => 'ScormFailed',
  473. 'passed' => 'ScormPassed',
  474. 'browsed' => 'ScormBrowsed',
  475. 'not attempted' => 'ScormNotAttempted',
  476. );
  477. $my_lesson_status = api_convert_encoding(get_lang($mylanglist[$lesson_status]), $lp_charset, $dokeos_charset);
  478. if ($row['item_type'] != 'dokeos_chapter') {
  479. if ($row['item_type'] == 'quiz') {
  480. $correct_test_link = '';
  481. $my_url_suffix ='';
  482. if ($origin != 'tracking' && $origin != 'tracking_course') {
  483. $my_url_suffix = '&course=' . api_get_course_id() . '&student_id=' . api_get_user_id() . '&lp_id=' . Security::remove_XSS($row['mylpid']);
  484. $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 ';
  485. } else {
  486. $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);
  487. $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 ';
  488. }
  489. $resultLastAttempt = Database::query($sql_last_attempt, __FILE__, __LINE__);
  490. $num = Database :: num_rows($resultLastAttempt);
  491. if ($num > 0) {
  492. 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) ) {
  493. $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>';
  494. $extend_attempt = 1;
  495. } else {
  496. $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>';
  497. }
  498. } else {
  499. $correct_test_link = '-';
  500. }
  501. } else {
  502. $correct_test_link = '-';
  503. }
  504. //."<td><font color='$color'><div class='mystatus'>".api_htmlentities($array_status[$lesson_status],ENT_QUOTES,$lp_charset)."</div></font></td>\n"
  505. $title = Security::remove_XSS($title);
  506. if ( (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id ) && (isset($_GET['my_lp_id']) && $_GET['my_lp_id'] == $my_id)) {
  507. $output .= "<tr class='$oddclass' >\n" . "<td>$extend_link</td>\n" . '<td colspan="4"><div class="mystatus">' .$title. '</div></td>' . "\n";
  508. $output .= '<td colspan="2">&nbsp;</td><td colspan="2">&nbsp;</td><td colspan="2">&nbsp;</td><td>'.$correct_test_link.'</td></tr>';
  509. $output .= "</tr>\n";
  510. } else {
  511. if ( (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id ) && (isset($_GET['my_ext_lp_id']) && $_GET['my_ext_lp_id'] == $my_id)) {
  512. $output .= "<tr class='$oddclass' >\n";
  513. } else {
  514. $output .= "<tr class='$oddclass'>\n";
  515. }
  516. $output .= "<td>$extend_link</td>\n" . '<td colspan="4"><div class="mystatus">' .$title. '</div></td>' . "\n";
  517. $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">';
  518. if ($row['item_type'] == 'quiz') {
  519. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  520. $output .= '/';
  521. } else {
  522. $output .= ($score == 0 ? '0/'.float_format($maxscore, 1) : ($maxscore == 0 ? $score : float_format($score, 1) . '/' . float_format($maxscore, 1)));
  523. }
  524. } else {
  525. $output .= ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
  526. }
  527. $output .= "</div></td>\n" . '<td colspan="2"><div class="mystatus">' . $time . "</div></td><td>$correct_test_link</td>\n";
  528. $output .= "</tr>\n";
  529. }
  530. if (!empty($export_csv)) {
  531. $temp = array ();
  532. $temp[] = api_html_entity_decode($title, ENT_QUOTES, $lp_charset);
  533. $temp[] = api_html_entity_decode($my_lesson_status, ENT_QUOTES, $lp_charset);
  534. if ($row['item_type'] == 'quiz') {
  535. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  536. $temp[] = '/';
  537. } else {
  538. $temp[] = ($score == 0 ? '0/'.$maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  539. }
  540. } else {
  541. $temp[] = ($score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1)));
  542. }
  543. $temp[] = $time;
  544. $csv_content[] = $temp;
  545. }
  546. }
  547. $counter++;
  548. if ($extend_this_attempt OR $extend_all) {
  549. $list1 = learnpath :: get_iv_interactions_array($row['iv_id']);
  550. foreach ($list1 as $id => $interaction) {
  551. if (($counter % 2) == 0) {
  552. $oddclass = "row_odd";
  553. } else {
  554. $oddclass = "row_even";
  555. }
  556. $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"
  557. //."<td><font color='$color'><div class='mystatus'>"api_convert_encoding($array_status[$lesson_status],$lp_charset,$lp_charset)."</div></font></td>\n"
  558. . '<td colspan="2">' . $interaction['type'] . "</td>\n"
  559. //.'<td>'.$interaction['correct_responses']."</td>\n"
  560. . '<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";
  561. $counter++;
  562. }
  563. $list2 = learnpath :: get_iv_objectives_array($row['iv_id']);
  564. foreach ($list2 as $id => $interaction) {
  565. if (($counter % 2) == 0) {
  566. $oddclass = "row_odd";
  567. } else {
  568. $oddclass = "row_even";
  569. }
  570. $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" .
  571. '<td colspan="2">' . $interaction['status'] . "</td>\n" .
  572. '<td>' . $interaction['score_raw'] . "</td>\n" . '<td>' . $interaction['score_max'] . "</td>\n" . '<td>' . $interaction['score_min'] . "</td>\n<td></td>\n</tr>\n";
  573. $counter++;
  574. }
  575. }
  576. // attempts list by exercise
  577. if ( (isset($_GET['lp_id']) && $_GET['lp_id'] == $my_lp_id ) && (isset($_GET['my_lp_id']) && $_GET['my_lp_id'] == $my_id)) {
  578. $res_attempts = Database::query($sql_attempts,__FILE__,__LINE__);
  579. $num_attempts = Database :: num_rows($res_attempts);
  580. if ($row['item_type'] === 'quiz') {
  581. if ($num_attempts > 0) {
  582. $n=1;
  583. while ($row_attempts = Database :: fetch_array($res_attempts)) {
  584. $my_score = $row_attempts['exe_result'];
  585. $my_maxscore = $row_attempts['exe_weighting'];
  586. $my_exe_id = $row_attempts['exe_id'];
  587. $my_orig_lp = $row_attempts['orig_lp_id'];
  588. $my_orig_lp_item = $row_attempts['orig_lp_item_id'];
  589. $my_exo_exe_id=$row_attempts['exe_exo_id'];
  590. $mktime_start_date = convert_mysql_date($row_attempts['start_date']);
  591. $mktime_exe_date = convert_mysql_date($row_attempts['exe_date']);
  592. $mytime = ((int)$mktime_exe_date-(int)$mktime_start_date);
  593. $time_attemp = learnpathItem :: get_scorm_time('js', $mytime);
  594. $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
  595. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  596. $view_score = '-';
  597. } else {
  598. //show only float when need it
  599. $my_score = float_format( $my_score, 1);
  600. $my_maxscore =float_format($my_maxscore, 1);
  601. if ($my_score == 0 ){
  602. $view_score = '0/'.$my_maxscore;
  603. } else {
  604. if ($my_maxscore==0)
  605. $view_score = $my_score;
  606. else
  607. $view_score = $my_score . '/' . $my_maxscore;
  608. }
  609. //$view_score = ($my_score == 0 ? '0.00/'.$my_maxscore : ($my_maxscore == 0 ? $my_score : $my_score . '/' . $my_maxscore));
  610. }
  611. $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>'
  612. . '<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>';
  613. if ($origin != 'tracking') {
  614. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  615. $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>';
  616. } else {
  617. $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>';
  618. }
  619. } else {
  620. if (!$is_allowed_to_edit && $result_disabled_ext_all) {
  621. $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>';
  622. } else {
  623. $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>';
  624. }
  625. }
  626. $output .= '</tr>';
  627. $n++;
  628. }
  629. }
  630. $output .= '<tr><td colspan="12">&nbsp;</td></tr>';
  631. }
  632. }
  633. }
  634. $total_time += $time_for_total;
  635. //QUIZZ IN LP
  636. $a_my_id = array();
  637. if (!empty($my_lp_id)) {
  638. $a_my_id[] = $my_lp_id;
  639. }
  640. }
  641. }
  642. if (!empty($a_my_id)) {
  643. $my_studen_id = 0;
  644. $my_course_id = '';
  645. if ($origin == 'tracking') {
  646. $my_studen_id = $student_id;
  647. $my_course_id = Database::escape_string($_GET['course']);
  648. } else {
  649. $my_studen_id = intval(api_get_user_id());
  650. $my_course_id = Database::escape_string(api_get_course_id());
  651. }
  652. $total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id);
  653. } else {
  654. $total_score = 0;
  655. }
  656. $total_time = learnpathItem :: get_scorm_time('js', $total_time);
  657. //$total_time = str_replace('NaN','00:00:00',$total_time);
  658. $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
  659. $lp_type = learnpath :: get_type_static($lp_id);
  660. $total_percent = 0;
  661. $final_score = $total_score.'%';
  662. if (($counter % 2) == 0) {
  663. $oddclass = "row_odd";
  664. } else {
  665. $oddclass = "row_even";
  666. }
  667. if (empty($extend_all)) {
  668. $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"
  669. . '<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";
  670. }
  671. $output .= "</table></td></tr></table>";
  672. if (!empty($export_csv)) {
  673. $temp = array (
  674. '',
  675. '',
  676. '',
  677. ''
  678. );
  679. $csv_content[] = $temp;
  680. $temp = array (
  681. api_convert_encoding(get_lang('AccomplishedStepsTotal') , $lp_charset, $dokeos_charset),
  682. '',
  683. $final_score,
  684. $total_time
  685. );
  686. $csv_content[] = $temp;
  687. ob_end_clean();
  688. Export :: export_table_csv($csv_content, 'reporting_learning_path_details');
  689. }
  690. if ($origin != 'tracking') {
  691. $output .= "</body></html>";
  692. }
  693. if (empty($export_csv)) {
  694. echo $output;
  695. }