lp_stats.php 38 KB

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