lp_stats.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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'].'&origin='.$_GET['origin'];
  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. if($origin != 'tracking')
  65. {
  66. $output .= "<tr><td><div class='title'>".htmlentities(get_lang('ScormMystatus'), ENT_QUOTES, $dokeos_charset)."</div></td></tr>";
  67. }
  68. $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">'.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><td class='title'><div class='mystatusfirstrow'>".get_lang('Actions')."</div></td></tr>\n";
  69. //going through the items using the $items[] array instead of the database order ensures
  70. // we get them in the same order as in the imsmanifest file, which is rather random when using
  71. // the database table
  72. $TBL_LP_ITEM = Database :: get_course_table('lp_item');
  73. $TBL_LP_ITEM_VIEW = Database :: get_course_table('lp_item_view');
  74. $TBL_LP_VIEW = Database :: get_course_table('lp_view');
  75. $sql = "SELECT max(view_count) FROM $TBL_LP_VIEW WHERE lp_id = $lp_id AND user_id = '".$user_id."'";
  76. $res = api_sql_query($sql, __FILE__, __LINE__);
  77. $view = '';
  78. if (Database :: num_rows($res) > 0) {
  79. $myrow = Database :: fetch_array($res);
  80. $view = $myrow[0];
  81. }
  82. $counter = 0;
  83. //error_log('New LP - Querying views for latest attempt: '.$sql,0);
  84. $total_score = 0;
  85. $total_max_score = 0;
  86. $total_time = 0;
  87. $h = get_lang('h');
  88. if($export_csv)
  89. {
  90. $csv_content[] = array (
  91. get_lang('ScormLessonTitle'),
  92. get_lang('ScormStatus'),
  93. get_lang('ScormScore'),
  94. get_lang('ScormTime')
  95. );
  96. }
  97. foreach ($list as $my_item_id) {
  98. $extend_this = 0;
  99. $qry_order = 'DESC';
  100. if ((!empty ($_GET['extend_id']) and $_GET['extend_id'] == $my_item_id) OR $extend_all) {
  101. $extend_this = 1;
  102. $qry_order = 'ASC';
  103. }
  104. if (!empty ($view)) {
  105. $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, path as path "." 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 ";
  106. } else {
  107. $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, path as path "." 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 ";
  108. }
  109. $result = api_sql_query($sql, __FILE__, __LINE__);
  110. $num = Database :: num_rows($result);
  111. $time_for_total = 'NaN';
  112. if (($extend_this OR $extend_all) && $num > 0) {
  113. $row = Database :: fetch_array($result);
  114. //if there are several attempts, and the link to extend has been clicked...
  115. if (($counter % 2) == 0) {
  116. $oddclass = "row_odd";
  117. } else {
  118. $oddclass = "row_even";
  119. }
  120. if ($inter_num)
  121. $extend_link = '<a href="'.api_get_self().'?action=stats&fold_id='.$my_item_id.$url_suffix.'"><img src="../img/visible.gif" alt="fold_view" border="0"></a>'."\n";
  122. $title = $row['mytitle'];
  123. $title = stripslashes($title);
  124. if (empty ($title)) {
  125. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  126. }
  127. if ($row['item_type'] != 'dokeos_chapter') {
  128. if($row['item_type'] == 'quiz'){
  129. if($_SESSION['status'][$_course["id"]] == 5){
  130. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=student_progress&id='.$row['path'].'&cidReq='.$_SESSION['_course']['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'quiz.gif"></a>';
  131. }
  132. else{
  133. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&id='.$row['path'].'&cidReq='.$_SESSION['_course']['id'].'&student='.$_GET['student_id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'quiz.gif"></a>';
  134. }
  135. }
  136. else{
  137. $correct_test_link='-';
  138. }
  139. $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">'.$correct_test_link.'</td>'."\n"."</tr>\n";
  140. }
  141. $counter ++;
  142. do {
  143. //check if there are interactions below
  144. $extend_attempt_link = '';
  145. $extend_this_attempt = 0;
  146. if (learnpath :: get_interactions_count_from_db($row['iv_id']) > 0 && !$extend_all) {
  147. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  148. //the extend button for this attempt has been clicked
  149. $extend_this_attempt = 1;
  150. $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="fold_attempt_view" border="0"></a>'."\n";
  151. } else { //same case if fold_attempt_id is set, so not implemented explicitly
  152. //the extend button for this attempt has not been clicked
  153. $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="extend_attempt_view" border="0"></a>'."\n";
  154. }
  155. }
  156. if (($counter % 2) == 0) {
  157. $oddclass = "row_odd";
  158. } else {
  159. $oddclass = "row_even";
  160. }
  161. $lesson_status = $row['mystatus'];
  162. $score = $row['myscore'];
  163. $time_for_total = $row['mytime'];
  164. $time = learnpathItem :: get_scorm_time('js', $row['mytime']);
  165. $type;
  166. $scoIdentifier = $row['myid'];
  167. if ($score == 0) {
  168. $maxscore = 0;
  169. } else {
  170. $maxscore = $row['mymaxscore'];
  171. }
  172. //Remove "NaN" if any (@todo: locate the source of these NaN)
  173. $time = str_replace('NaN', '00'.$h.'00\'00"', $time);
  174. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  175. $color = 'green';
  176. } else {
  177. $color = 'black';
  178. }
  179. $mylanglist = array ('completed' => 'ScormCompstatus', 'incomplete' => 'ScormIncomplete', 'failed' => 'ScormFailed', 'passed' => 'ScormPassed', 'browsed' => 'ScormBrowsed', 'not attempted' => 'ScormNotAttempted',);
  180. $my_lesson_status = htmlentities(get_lang($mylanglist[$lesson_status]), ENT_QUOTES, $dokeos_charset);
  181. //$my_lesson_status = get_lang($mylanglist[$lesson_status]);
  182. if ($row['item_type'] != 'dokeos_chapter') {
  183. $output .= "<tr class='$oddclass'>\n"."<td></td>\n"."<td>$extend_attempt_link</td>\n".'<td colspan="3">'.htmlentities(get_lang('Attempt'), ENT_QUOTES, $dokeos_charset).' '.$row['iv_view_count']."</td>\n"
  184. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  185. .'<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><td></td>\n"."</tr>\n";
  186. }
  187. $counter ++;
  188. if ($extend_this_attempt OR $extend_all) {
  189. $list = learnpath :: get_iv_interactions_array($row['iv_id']);
  190. foreach ($list as $id => $interaction) {
  191. if (($counter % 2) == 0) {
  192. $oddclass = "row_odd";
  193. } else {
  194. $oddclass = "row_even";
  195. }
  196. $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"
  197. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  198. .'<td colspan="2">'.$interaction['type']."</td>\n"
  199. //.'<td>'.$interaction['correct_responses']."</td>\n"
  200. .'<td>'.urldecode($interaction['student_response'])."</td>\n".'<td>'.$interaction['result']."</td>\n".'<td>'.$interaction['latency']."</td>\n".'<td>'.$interaction['time']."</td>\n"."</tr>\n";
  201. $counter ++;
  202. }
  203. }
  204. } while ($row = Database :: fetch_array($result));
  205. } elseif($num>0) {
  206. $row = Database :: fetch_array($result);
  207. //check if there are interactions below
  208. $extend_attempt_link = '';
  209. $extend_this_attempt = 0;
  210. $inter_num = learnpath :: get_interactions_count_from_db($row['iv_id']);
  211. if ($inter_num > 0 && !$extend_all) {
  212. if (!empty ($_GET['extend_attempt_id']) && $_GET['extend_attempt_id'] == $row['iv_id']) {
  213. //the extend button for this attempt has been clicked
  214. $extend_this_attempt = 1;
  215. $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="fold_attempt_view" border="0"></a>'."\n";
  216. } else { //same case if fold_attempt_id is set, so not implemented explicitly
  217. //the extend button for this attempt has not been clicked
  218. $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="extend_attempt_view" border="0"></a>'."\n";
  219. }
  220. }
  221. if (($counter % 2) == 0) {
  222. $oddclass = "row_odd";
  223. } else {
  224. $oddclass = "row_even";
  225. }
  226. //$extend_link = '<img src="../img/invisible.gif" alt="extend_disabled">';
  227. $extend_link = '';
  228. if ($inter_num > 1) {
  229. $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="extend_view" border="0"></a>';
  230. }
  231. if (($counter % 2) == 0) {
  232. $oddclass = "row_odd";
  233. } else {
  234. $oddclass = "row_even";
  235. }
  236. $lesson_status = $row['mystatus'];
  237. $score = $row['myscore'];
  238. $subtotal_time = $row['mytime'];
  239. //if($row['mytime']==0){
  240. while ($tmp_row = Database :: fetch_array($result)) {
  241. $subtotal_time += $tmp_row['mytime'];
  242. }
  243. //}
  244. $time_for_total = $subtotal_time;
  245. $time = learnpathItem :: get_scorm_time('js', $subtotal_time);
  246. $scoIdentifier = $row['myid'];
  247. $title = $row['mytitle'];
  248. $title = stripslashes($title);
  249. if ($score == 0) {
  250. $maxscore = 0;
  251. } else {
  252. $maxscore = $row['mymaxscore'];
  253. }
  254. if (empty ($title)) {
  255. $title = rl_get_resource_name(api_get_course_id(), $lp_id, $row['myid']);
  256. }
  257. //Remove "NaN" if any (@todo: locate the source of these NaN)
  258. //$time = str_replace('NaN', '00'.$h.'00\'00"', $time);
  259. if (($lesson_status == 'completed') or ($lesson_status == 'passed')) {
  260. $color = 'green';
  261. } else {
  262. $color = 'black';
  263. }
  264. $mylanglist = array ('completed' => 'ScormCompstatus', 'incomplete' => 'ScormIncomplete', 'failed' => 'ScormFailed', 'passed' => 'ScormPassed', 'browsed' => 'ScormBrowsed', 'not attempted' => 'ScormNotAttempted',);
  265. $my_lesson_status = htmlentities(get_lang($mylanglist[$lesson_status]), ENT_QUOTES, $dokeos_charset);
  266. if ($row['item_type'] != 'dokeos_chapter') {
  267. if($row['item_type'] == 'quiz'){
  268. if($_SESSION['status'][$_course["id"]] == 5){
  269. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=student_progress&id='.$row['path'].'&cidReq='.$_SESSION['_course']['id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'quiz.gif"></a>';
  270. }
  271. else{
  272. $correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&id='.$row['path'].'&cidReq='.$_SESSION['_course']['id'].'&student='.$_GET['student_id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'quiz.gif"></a>';
  273. }
  274. }
  275. else{
  276. $correct_test_link='-';
  277. }
  278. $output .= "<tr class='$oddclass'>\n"."<td>$extend_link</td>\n".'<td colspan="4"><div class="mystatus">'.$title.'</div></td>'."\n"
  279. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  280. .'<td colspan="2"><font color="'.$color.'"><div class="mystatus">'.$my_lesson_status."</div></font></td>\n".'<td colspan="2"><div class="mystatus" align="center">'. ($score == 0 ? '-' : $score.'/'.$maxscore)."</div></td>\n".'<td colspan="2"><div class="mystatus">'.$time."</div></td><td>$correct_test_link</td>\n"."</tr>\n";
  281. if($export_csv)
  282. {
  283. $temp = array();
  284. $temp[] = $title;
  285. $temp[] = html_entity_decode($my_lesson_status);
  286. $temp[] = ($score == 0 ? '-' : $score.'/'.$maxscore);
  287. $temp[] = $time;
  288. $csv_content[] = $temp;
  289. }
  290. }
  291. $counter ++;
  292. if ($extend_this_attempt OR $extend_all) {
  293. $list = learnpath :: get_iv_interactions_array($row['iv_id']);
  294. foreach ($list as $id => $interaction) {
  295. if (($counter % 2) == 0) {
  296. $oddclass = "row_odd";
  297. } else {
  298. $oddclass = "row_even";
  299. }
  300. $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"
  301. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  302. .'<td colspan="2">'.$interaction['type']."</td>\n"
  303. //.'<td>'.$interaction['correct_responses']."</td>\n"
  304. .'<td>'.urldecode($interaction['student_response'])."</td>\n".'<td>'.$interaction['result']."</td>\n".'<td>'.$interaction['latency']."</td>\n".'<td>'.$interaction['time']."</td>\n"."</tr>\n";
  305. $counter ++;
  306. }
  307. }
  308. }
  309. //only sum up the latest attempt each time
  310. $total_max_score += $maxscore;
  311. $total_score += $score;
  312. $total_time += $time_for_total;
  313. }
  314. $total_time = learnpathItem :: get_scorm_time('js', $total_time);
  315. //$total_time = str_replace('NaN','00:00:00',$total_time);
  316. $total_time = str_replace('NaN', '00'.$h.'00\'00"', $total_time);
  317. if ($total_max_score == 0) {
  318. $total_max_score = 1;
  319. }
  320. $total_percent = number_format((((float) $total_score / (float) $total_max_score) * 100), 1, '.', '');
  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 colspan="4"><div class="mystatus"><i>'.htmlentities(get_lang('AccomplishedStepsTotal'), ENT_QUOTES, $dokeos_charset)."</i></div></td>\n"
  327. //."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$charset_lang)."</div></font></td>\n"
  328. .'<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><td></td>'."\n"."</tr>\n";
  329. $output .= "</table></td></tr></table>";
  330. if($export_csv)
  331. {
  332. $temp = array('','','','');
  333. $csv_content[] = $temp;
  334. $temp = array(get_lang('AccomplishedStepsTotal'),'',($total_score == 0 ? '-' : $total_percent.'%'),$total_time);
  335. $csv_content[] = $temp;
  336. ob_end_clean();
  337. Export :: export_table_csv($csv_content, 'reporting_learning_path_details');
  338. }
  339. if($origin != 'tracking')
  340. {
  341. $output .= "</body></html>";
  342. }
  343. echo $output;
  344. ?>