lp_stats.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. //$id:$
  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. /**
  11. * Script
  12. */
  13. require_once('learnpath.class.php');
  14. //require_once('scorm.class.php');
  15. require_once ('resourcelinker.inc.php');
  16. //The two following variables have to be declared by the includer script
  17. //$lp_id = $_SESSION['oLP']->get_id();
  18. //$list = $_SESSION['oLP']->get_flat_ordered_items_list($lp_id);
  19. //$user_id = $_user['user_id'];
  20. //$stats_charset = $_SESSION['oLP']->encoding
  21. if(!isset($origin))
  22. $origin = '';
  23. if($origin != 'tracking')
  24. {
  25. if (!empty ($stats_charset)) {
  26. $charset_lang = $stats_charset;
  27. } else {
  28. $charset_lang = 'ISO-8859-1';
  29. }
  30. $dokeos_charset = 'ISO-8859-1';
  31. $charset = $charset_lang;
  32. $w = $tablewidth -20;
  33. $htmlHeadXtra[] = ''.'<style type="text/css" media="screen, projection">
  34. /*<![CDATA[*/
  35. @import "../css/default/scorm.css";
  36. /*]]>*/
  37. </style>';
  38. include_once ('../inc/reduced_header.inc.php');
  39. echo '<body>';
  40. }
  41. //if display in fullscreen required
  42. if (strcmp($_GET["fs"], "true") == 0) {
  43. $output .= "<table align='center'>";
  44. } else {
  45. $output .= "<table class='margin_table'>";
  46. }
  47. //check if the user asked for the "extend all" option
  48. $extend_all_link = '';
  49. $extend_all = 0;
  50. if($origin == 'tracking')
  51. {
  52. $url_suffix = '&course='.$_GET['course'].'&student_id='.$_GET['student_id'].'&lp_id='.$_GET['lp_id'];
  53. }
  54. else
  55. {
  56. $url_suffix = '';
  57. }
  58. if (!empty ($_GET['extend_all'])) {
  59. $extend_all_link = '<a href="'.api_get_self().'?action=stats'.$url_suffix.'"><img src="../img/view_less_stats.gif" alt="fold_view" border="0"></a>';
  60. $extend_all = 1;
  61. } else {
  62. $extend_all_link = '<a href="'.api_get_self().'?action=stats&extend_all=1'.$url_suffix.'"><img src="../img/view_more_stats.gif" alt="extend_view" border="0"></a>';
  63. }
  64. $output .= "<tr><td><div class='title'>".htmlentities(get_lang('ScormMystatus'), ENT_QUOTES, $dokeos_charset)."</div></td></tr>"."<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">'.htmlentities(get_lang('ScormLessonTitle'), ENT_QUOTES, $dokeos_charset)."</div></td>\n".'<td colspan="2" class="title"><div class="mystatusfirstrow">'.htmlentities(get_lang('ScormStatus'), ENT_QUOTES, $dokeos_charset)."</div></td>\n".'<td colspan="2" class="title"><div class="mystatusfirstrow">'.htmlentities(get_lang('ScormScore'), ENT_QUOTES, $dokeos_charset)."</div></td>\n".'<td colspan="2" class="title"><div class="mystatusfirstrow">'.htmlentities(get_lang('ScormTime'), ENT_QUOTES, $dokeos_charset)."</div></td></tr>\n";
  65. //going through the items using the $items[] array instead of the database order ensures
  66. // we get them in the same order as in the imsmanifest file, which is rather random when using
  67. // the database table
  68. $TBL_LP_ITEM = Database :: get_course_table('lp_item');
  69. $TBL_LP_ITEM_VIEW = Database :: get_course_table('lp_item_view');
  70. $TBL_LP_VIEW = Database :: get_course_table('lp_view');
  71. $sql = "SELECT max(view_count) FROM $TBL_LP_VIEW WHERE lp_id = $lp_id AND user_id = '".$user_id."'";
  72. $res = api_sql_query($sql, __FILE__, __LINE__);
  73. $view = '';
  74. if (Database :: num_rows($res) > 0) {
  75. $myrow = Database :: fetch_array($res);
  76. $view = $myrow[0];
  77. }
  78. $counter = 0;
  79. //error_log('New LP - Querying views for latest attempt: '.$sql,0);
  80. $total_score = 0;
  81. $total_max_score = 0;
  82. $total_time = 0;
  83. $h = get_lang('h');
  84. foreach ($list as $my_item_id) {
  85. $extend_this = 0;
  86. $qry_order = 'DESC';
  87. if ((!empty ($_GET['extend_id']) and $_GET['extend_id'] == $my_item_id) OR $extend_all) {
  88. $extend_this = 1;
  89. $qry_order = 'ASC';
  90. }
  91. if (!empty ($view)) {
  92. $sql = "SELECT iv.status as mystatus, v.view_count as mycount, iv.score as myscore, iv.total_time as mytime, i.id as myid, i.title as mytitle, i.max_score as mymaxscore, i.item_type as item_type, iv.view_count as iv_view_count, iv.id as iv_id "." FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v "." WHERE i.id = iv.lp_item_id "." AND i.id = $my_item_id "." AND iv.lp_view_id = v.id "." AND i.lp_id = $lp_id "." AND v.user_id = ".$user_id.""." AND v.view_count = $view "." ORDER BY iv.view_count $qry_order ";
  93. } else {
  94. $sql = "SELECT iv.status as mystatus, v.view_count as mycount, iv.score as myscore, iv.total_time as mytime, i.id as myid, i.title as mytitle, i.max_score as mymaxscore, i.item_type as item_type, iv.view_count as iv_view_count, iv.id as iv_id "." FROM $TBL_LP_ITEM as i, $TBL_LP_ITEM_VIEW as iv, $TBL_LP_VIEW as v "." WHERE i.id = iv.lp_item_id "." AND i.id = $my_item_id "." AND iv.lp_view_id = v.id "." AND i.lp_id = $lp_id "." AND v.user_id = ".$user_id." "." ORDER BY iv.view_count $qry_order ";
  95. }
  96. $result = api_sql_query($sql, __FILE__, __LINE__);
  97. $num = Database :: num_rows($result);
  98. $time_for_total = 'NaN';
  99. if (($extend_this OR $extend_all) && $num > 0) {
  100. $row = Database :: fetch_array($result);
  101. //if there are several attempts, and the link to extend has been clicked...
  102. if (($counter % 2) == 0) {
  103. $oddclass = "row_odd";
  104. } else {
  105. $oddclass = "row_even";
  106. }
  107. if ($inter_num)
  108. $extend_link = '<a href="lp_controller.php?action=stats&fold_id='.$my_item_id.'"><img src="../img/visible.gif" alt="fold_view" border="0"></a>'."\n";
  109. $title = $row['mytitle'];
  110. $title = stripslashes($title);
  111. if (empty ($title)) {
  112. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  113. }
  114. if ($row['item_type'] != 'dokeos_chapter') {
  115. $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>'."\n"."</tr>\n";
  116. }
  117. $counter ++;
  118. do {
  119. //check if there are interactions below
  120. $extend_attempt_link = '';
  121. $extend_this_attempt = 0;
  122. if (learnpath :: get_interactions_count_from_db($row['iv_id']) > 0 && !$extend_all) {
  123. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  124. //the extend button for this attempt has been clicked
  125. $extend_this_attempt = 1;
  126. $extend_attempt_link = '<a href="lp_controller.php?action=stats&extend_id='.$my_item_id.'&fold_attempt_id='.$row['iv_id'].'"><img src="../img/visible.gif" alt="fold_attempt_view" border="0"></a>'."\n";
  127. } else { //same case if fold_attempt_id is set, so not implemented explicitly
  128. //the extend button for this attempt has not been clicked
  129. $extend_attempt_link = '<a href="lp_controller.php?action=stats&extend_id='.$my_item_id.'&extend_attempt_id='.$row['iv_id'].'"><img src="../img/invisible.gif" alt="extend_attempt_view" border="0"></a>'."\n";
  130. }
  131. }
  132. if (($counter % 2) == 0) {
  133. $oddclass = "row_odd";
  134. } else {
  135. $oddclass = "row_even";
  136. }
  137. $lesson_status = $row['mystatus'];
  138. $score = $row['myscore'];
  139. $time_for_total = $row['mytime'];
  140. $time = learnpathItem :: get_scorm_time('php', $row['mytime']);
  141. $type;
  142. $scoIdentifier = $row['myid'];
  143. if ($score == 0) {
  144. $maxscore = 0;
  145. } else {
  146. $maxscore = $row['mymaxscore'];
  147. }
  148. //Remove "NaN" if any (@todo: locate the source of these NaN)
  149. $time = str_replace('NaN', '00'.$h.'00\'00"', $time);
  150. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  151. $color = 'green';
  152. } else {
  153. $color = 'black';
  154. }
  155. $mylanglist = array ('completed' => 'ScormCompstatus', 'incomplete' => 'ScormIncomplete', 'failed' => 'ScormFailed', 'passed' => 'ScormPassed', 'browsed' => 'ScormBrowsed', 'not attempted' => 'ScormNotAttempted',);
  156. $my_lesson_status = htmlentities(get_lang($mylanglist[$lesson_status]), ENT_QUOTES, $dokeos_charset);
  157. //$my_lesson_status = get_lang($mylanglist[$lesson_status]);
  158. if ($row['item_type'] != 'dokeos_chapter') {
  159. $output .= "<tr class='$oddclass'>\n"."<td></td>\n"."<td>$extend_attempt_link</td>\n".'<td colspan="3">Attempt '.$row['iv_view_count']."</td>\n"
  160. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  161. .'<td colspan="2"><font color="'.$color.'"><div class="mystatus">'.$my_lesson_status."</div></font></td>\n".'<td colspan="2"><div class="mystatus" align="center">'. ($score == 0 ? '-' : $score.'/'.$maxscore)."</div></td>\n".'<td colspan="2"><div class="mystatus">'.$time."</div></td>\n"."</tr>\n";
  162. }
  163. $counter ++;
  164. if ($extend_this_attempt OR $extend_all) {
  165. $list = learnpath :: get_iv_interactions_array($row['iv_id']);
  166. foreach ($list as $id => $interaction) {
  167. if (($counter % 2) == 0) {
  168. $oddclass = "row_odd";
  169. } else {
  170. $oddclass = "row_even";
  171. }
  172. $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"
  173. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  174. .'<td colspan="2">'.$interaction['type']."</td>\n"
  175. //.'<td>'.$interaction['correct_responses']."</td>\n"
  176. .'<td>'.$interaction['student_response']."</td>\n".'<td>'.$interaction['result']."</td>\n".'<td>'.$interaction['latency']."</td>\n".'<td>'.$interaction['time']."</td>\n"."</tr>\n";
  177. $counter ++;
  178. }
  179. }
  180. } while ($row = Database :: fetch_array($result));
  181. } else {
  182. $row = Database :: fetch_array($result);
  183. //check if there are interactions below
  184. $extend_attempt_link = '';
  185. $extend_this_attempt = 0;
  186. $inter_num = learnpath :: get_interactions_count_from_db($row['iv_id']);
  187. if ($inter_num > 0 && !$extend_all) {
  188. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  189. //the extend button for this attempt has been clicked
  190. $extend_this_attempt = 1;
  191. $extend_attempt_link = '<a href="lp_controller.php?action=stats&extend_id='.$my_item_id.'&fold_attempt_id='.$row['iv_id'].'"><img src="../img/visible.gif" alt="fold_attempt_view" border="0"></a>'."\n";
  192. } else { //same case if fold_attempt_id is set, so not implemented explicitly
  193. //the extend button for this attempt has not been clicked
  194. $extend_attempt_link = '<a href="lp_controller.php?action=stats&extend_id='.$my_item_id.'&extend_attempt_id='.$row['iv_id'].'"><img src="../img/invisible.gif" alt="extend_attempt_view" border="0"></a>'."\n";
  195. }
  196. }
  197. if (($counter % 2) == 0) {
  198. $oddclass = "row_odd";
  199. } else {
  200. $oddclass = "row_even";
  201. }
  202. //$extend_link = '<img src="../img/invisible.gif" alt="extend_disabled">';
  203. $extend_link = '';
  204. if ($inter_num > 1) {
  205. $extend_link = '<a href="lp_controller.php?action=stats&extend_id='.$my_item_id.'&extend_attempt_id='.$row['iv_id'].'"><img src="../img/invisible.gif" alt="extend_view" border="0"></a>';
  206. }
  207. if (($counter % 2) == 0) {
  208. $oddclass = "row_odd";
  209. } else {
  210. $oddclass = "row_even";
  211. }
  212. $lesson_status = $row['mystatus'];
  213. $score = $row['myscore'];
  214. $subtotal_time = $row['mytime'];
  215. //if($row['mytime']==0){
  216. while ($tmp_row = Database :: fetch_array($result)) {
  217. $subtotal_time += $tmp_row['mytime'];
  218. }
  219. //}
  220. $time_for_total = $subtotal_time;
  221. $time = learnpathItem :: get_scorm_time('php', $subtotal_time);
  222. $scoIdentifier = $row['myid'];
  223. $title = $row['mytitle'];
  224. $title = stripslashes($title);
  225. if ($score == 0) {
  226. $maxscore = 0;
  227. } else {
  228. $maxscore = $row['mymaxscore'];
  229. }
  230. if (empty ($title)) {
  231. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  232. }
  233. //Remove "NaN" if any (@todo: locate the source of these NaN)
  234. $time = str_replace('NaN', '00'.$h.'00\'00"', $time);
  235. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  236. $color = 'green';
  237. } else {
  238. $color = 'black';
  239. }
  240. $mylanglist = array ('completed' => 'ScormCompstatus', 'incomplete' => 'ScormIncomplete', 'failed' => 'ScormFailed', 'passed' => 'ScormPassed', 'browsed' => 'ScormBrowsed', 'not attempted' => 'ScormNotAttempted',);
  241. $my_lesson_status = htmlentities(get_lang($mylanglist[$lesson_status]), ENT_QUOTES, $dokeos_charset);
  242. if ($row['item_type'] != 'dokeos_chapter') {
  243. $output .= "<tr class='$oddclass'>\n"."<td>$extend_link</td>\n".'<td colspan="4"><div class="mystatus">'.$title.'</div></td>'."\n"
  244. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  245. .'<td colspan="2"><font color="'.$color.'"><div class="mystatus">'.$my_lesson_status."</div></font></td>\n".'<td colspan="2"><div class="mystatus" align="center">'. ($score == 0 ? '-' : $score.'/'.$maxscore)."</div></td>\n".'<td colspan="2"><div class="mystatus">'.$time."</div></td>\n"."</tr>\n";
  246. }
  247. $counter ++;
  248. if ($extend_this_attempt OR $extend_all) {
  249. $list = learnpath :: get_iv_interactions_array($row['iv_id']);
  250. foreach ($list as $id => $interaction) {
  251. if (($counter % 2) == 0) {
  252. $oddclass = "row_odd";
  253. } else {
  254. $oddclass = "row_even";
  255. }
  256. $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"
  257. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  258. .'<td colspan="2">'.$interaction['type']."</td>\n"
  259. //.'<td>'.$interaction['correct_responses']."</td>\n"
  260. .'<td>'.$interaction['student_response']."</td>\n".'<td>'.$interaction['result']."</td>\n".'<td>'.$interaction['latency']."</td>\n".'<td>'.$interaction['time']."</td>\n"."</tr>\n";
  261. $counter ++;
  262. }
  263. }
  264. }
  265. //only sum up the latest attempt each time
  266. $total_max_score += $maxscore;
  267. $total_score += $score;
  268. $total_time += $time_for_total;
  269. }
  270. $total_time = learnpathItem :: get_scorm_time('php', $total_time);
  271. //$total_time = str_replace('NaN','00:00:00',$total_time);
  272. $total_time = str_replace('NaN', '00'.$h.'00\'00"', $total_time);
  273. if ($total_max_score == 0) {
  274. $total_max_score = 1;
  275. }
  276. $total_percent = number_format((((float) $total_score / (float) $total_max_score) * 100), 1, '.', '');
  277. if (($counter % 2) == 0) {
  278. $oddclass = "row_odd";
  279. } else {
  280. $oddclass = "row_even";
  281. }
  282. $output .= "<tr class='$oddclass'>\n"."<td></td>\n".'<td colspan="4"><div class="mystatus"><i>'.htmlentities(get_lang('AccomplishedStepsTotal'), ENT_QUOTES, $dokeos_charset)."</i></div></td>\n"
  283. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  284. .'<td colspan="2"></td>'."\n".'<td colspan="2"><div class="mystatus" align="center">'. ($total_score == 0 ? '-' : $total_percent.'%')."</div></td>\n".'<td colspan="2"><div class="mystatus">'.$total_time.'</div></td>'."\n"."</tr>\n";
  285. $output .= "</table></td></tr></table>";
  286. if($origin != 'tracking')
  287. {
  288. $output .= "</body></html>";
  289. }
  290. echo $output;
  291. ?>