courseLog.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, 44 rue des palais, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * @author Thomas Depraetere
  22. * @author Hugues Peeters
  23. * @author Christophe Gesche
  24. * @author Sebastien Piraux
  25. * @author Toon Keppens (Vi-Host.net)
  26. *
  27. * @package dokeos.tracking
  28. ==============================================================================
  29. */
  30. /*
  31. ==============================================================================
  32. INIT SECTION
  33. ==============================================================================
  34. */
  35. $pathopen = isset($_REQUEST['pathopen']) ? $_REQUEST['pathopen'] : null;
  36. // name of the language file that needs to be included
  37. $language_file[] = 'tracking';
  38. $language_file[] = 'scorm';
  39. include('../inc/global.inc.php');
  40. $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin;
  41. if(!$is_allowedToTrack)
  42. {
  43. Display :: display_header();
  44. api_not_allowed();
  45. Display :: display_footer();
  46. }
  47. //includes for SCORM and LP
  48. require_once('../newscorm/learnpath.class.php');
  49. require_once('../newscorm/learnpathItem.class.php');
  50. require_once('../newscorm/learnpathList.class.php');
  51. require_once('../newscorm/scorm.class.php');
  52. require_once('../newscorm/scormItem.class.php');
  53. require_once(api_get_path(LIBRARY_PATH).'tracking.lib.php');
  54. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  55. require_once(api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  56. require_once (api_get_path(LIBRARY_PATH).'export.lib.inc.php');
  57. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  58. if($export_csv)
  59. {
  60. ob_start();
  61. }
  62. $csv_content = array();
  63. // charset determination
  64. if ($_GET['scormcontopen'])
  65. {
  66. $tbl_lp = Database::get_course_table('lp');
  67. $contopen = (int) $_GET['scormcontopen'];
  68. $sql = "SELECT default_encoding FROM $tbl_lp WHERE id = ".$contopen;
  69. $res = api_sql_query($sql,__FILE__,__LINE__);
  70. $row = Database::fetch_array($res);
  71. $lp_charset = $row['default_encoding'];
  72. //header('Content-Type: text/html; charset='. $row['default_encoding']);
  73. }
  74. $htmlHeadXtra[] = "<style type='text/css'>
  75. /*<![CDATA[*/
  76. .secLine {background-color : #E6E6E6;}
  77. .content {padding-left : 15px;padding-right : 15px; }
  78. .specialLink{color : #0000FF;}
  79. /*]]>*/
  80. </style>
  81. <style media='print' type='text/css'>
  82. </style>";
  83. /*
  84. -----------------------------------------------------------
  85. Constants and variables
  86. -----------------------------------------------------------
  87. */
  88. // regroup table names for maintenance purpose
  89. $TABLETRACK_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  90. $TABLETRACK_LINKS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  91. $TABLETRACK_DOWNLOADS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  92. $TABLETRACK_ACCESS_2 = Database::get_statistic_table("track_e_access");
  93. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  94. $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
  95. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  96. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  97. //$table_scormdata = Database::get_scorm_table(TABLE_SCORM_SCO_DATA);
  98. //$table_scormmain = Database::get_scorm_table(TABLE_SCORM_MAIN);
  99. //$tbl_learnpath_main = Database::get_course_table(TABLE_LEARNPATH_MAIN);
  100. //$tbl_learnpath_item = Database::get_course_table(TABLE_LEARNPATH_ITEM);
  101. //$tbl_learnpath_chapter = Database::get_course_table(TABLE_LEARNPATH_CHAPTER);
  102. $tbl_learnpath_main = Database::get_course_table('lp');
  103. $tbl_learnpath_item = Database::get_course_table('lp_item');
  104. $tbl_learnpath_view = Database::get_course_table('lp_view');
  105. $tbl_learnpath_item_view = Database::get_course_table('lp_item_view');
  106. $view = $_REQUEST['view'];
  107. $nameTools = get_lang('Tracking');
  108. Display::display_header($nameTools, "Tracking");
  109. include(api_get_path(LIBRARY_PATH)."statsUtils.lib.inc.php");
  110. include("../resourcelinker/resourcelinker.inc.php");
  111. $a_students = CourseManager :: get_student_list_from_course_code($_course['id'], true);
  112. $nbStudents = count($a_students);
  113. /**
  114. * count the number of students in this course (used for SortableTable)
  115. */
  116. function count_student_in_course()
  117. {
  118. global $nbStudents;
  119. return $nbStudents;
  120. }
  121. /*
  122. ==============================================================================
  123. MAIN CODE
  124. ==============================================================================
  125. */
  126. if($_GET['studentlist'] == 'false')
  127. {
  128. echo '<div style="float:left; clear:left">
  129. <a href="courseLog.php?studentlist=true">'.get_lang('StudentsTracking').'</a>&nbsp;|
  130. '.get_lang('CourseTracking').'
  131. </div>';
  132. }
  133. else
  134. {
  135. echo '<div style="float:left; clear:left">
  136. '.get_lang('StudentsTracking').' |
  137. <a href="courseLog.php?studentlist=false">'.get_lang('CourseTracking').'</a>&nbsp;
  138. </div>';
  139. }
  140. echo '<div style="float:right; clear:right">
  141. <a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>';
  142. if($_GET['studentlist'] == 'false'){
  143. echo '<a href="'.$_SERVER['PHP_SELF'].'?export=csv&studentlist=false"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a></div>';
  144. }
  145. else{
  146. echo '<a href="'.$_SERVER['PHP_SELF'].'?export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a></div>';
  147. }
  148. echo '<div class="clear"></div>';
  149. if($_GET['studentlist'] == 'false')
  150. {
  151. echo'<br /><br />';
  152. /**********************
  153. * TOOLS
  154. **********************/
  155. echo "<div class='admin_section'>
  156. <h4>
  157. <img src='../img/acces_tool.gif' align='absbottom'>&nbsp;".get_lang('ToolsMostUsed')."
  158. </h4>
  159. <table class='data_table'>";
  160. $sql = "SELECT `access_tool`, COUNT(DISTINCT `access_user_id`),count( `access_tool` ) as count_access_tool
  161. FROM $TABLETRACK_ACCESS
  162. WHERE `access_tool` IS NOT NULL
  163. AND `access_cours_code` = '$_cid'
  164. GROUP BY `access_tool`
  165. ORDER BY count_access_tool DESC
  166. LIMIT 0, 3";
  167. $rs = api_sql_query($sql, __FILE__, __LINE__);
  168. if($export_csv){
  169. $temp=array(get_lang('ToolsMostUsed'),'');
  170. $csv_content[] = $temp;
  171. }
  172. while ($row = mysql_fetch_array($rs))
  173. {
  174. echo ' <tr>
  175. <td>'.get_lang(ucfirst($row['access_tool'])).'</td>
  176. <td align="right">'.$row['count_access_tool'].' '.get_lang('Clicks').'</td>
  177. </tr>';
  178. if($export_csv){
  179. $temp=array(get_lang(ucfirst($row['access_tool'])),$row['count_access_tool'].' '.get_lang('Clicks'));
  180. $csv_content[] = $temp;
  181. }
  182. }
  183. echo '</table></div>';
  184. echo '<div class="clear"></div>';
  185. /***************************
  186. * LINKS
  187. ***************************/
  188. echo "<div class='admin_section'>
  189. <h4>
  190. <img src='../img/link.gif' align='absbottom'>&nbsp;".get_lang('LinksMostClicked')."
  191. </h4>
  192. <table class='data_table'>";
  193. $sql = "SELECT `cl`.`title`, `cl`.`url`,count(DISTINCT `sl`.`links_user_id`), count(`cl`.`title`) as count_visits
  194. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  195. WHERE `sl`.`links_link_id` = `cl`.`id`
  196. AND `sl`.`links_cours_id` = '$_cid'
  197. GROUP BY `cl`.`title`, `cl`.`url`
  198. ORDER BY count_visits DESC
  199. LIMIT 0, 3";
  200. $rs = api_sql_query($sql, __FILE__, __LINE__);
  201. if($export_csv){
  202. $temp=array(get_lang('LinksMostClicked'),'');
  203. $csv_content[] = array('','');
  204. $csv_content[] = $temp;
  205. }
  206. if(mysql_num_rows($rs)>0)
  207. {
  208. while($row = mysql_fetch_array($rs))
  209. {
  210. echo ' <tr>
  211. <td>'.$row['title'].'</td>
  212. <td align="right">'.$row['count_visits'].' '.get_lang('Clicks').'</td>
  213. </tr>';
  214. if($export_csv){
  215. $temp=array($row['title'],$row['count_visits'].' '.get_lang('Clicks'));
  216. $csv_content[] = $temp;
  217. }
  218. }
  219. }
  220. else
  221. {
  222. echo '<tr><td>'.get_lang('NoLinkVisited').'</td></tr>';
  223. if($export_csv){
  224. $temp=array(get_lang('NoLinkVisited'),'');
  225. $csv_content[] = $temp;
  226. }
  227. }
  228. echo '</table></div>';
  229. echo '<div class="clear"></div>';
  230. /***************************
  231. * DOCUMENTS
  232. ***************************/
  233. echo "<div class='admin_section'>
  234. <h4>
  235. <img src='../img/documents.gif' align='absbottom'>&nbsp;".get_lang('DocumentsMostDownloaded')."
  236. </h4>
  237. <table class='data_table'>";
  238. $sql = "SELECT `down_doc_path`, COUNT(DISTINCT `down_user_id`), COUNT(`down_doc_path`) as count_down
  239. FROM $TABLETRACK_DOWNLOADS
  240. WHERE `down_cours_id` = '$_cid'
  241. GROUP BY `down_doc_path`
  242. ORDER BY count_down DESC
  243. LIMIT 0, 3";
  244. $rs = api_sql_query($sql, __FILE__, __LINE__);
  245. if($export_csv){
  246. $temp=array(get_lang('DocumentsMostDownloaded'),'');
  247. $csv_content[] = array('','');
  248. $csv_content[] = $temp;
  249. }
  250. if(mysql_num_rows($rs)>0)
  251. {
  252. while($row = mysql_fetch_array($rs))
  253. {
  254. echo ' <tr>
  255. <td>'.$row['down_doc_path'].'</td>
  256. <td align="right">'.$row['count_down'].' '.get_lang('Clicks').'</td>
  257. </tr>';
  258. if($export_csv){
  259. $temp=array($row['down_doc_path'],$row['count_down'].' '.get_lang('Clicks'));
  260. $csv_content[] = $temp;
  261. }
  262. }
  263. }
  264. else
  265. {
  266. echo '<tr><td>'.get_lang('NoDocumentDownloaded').'</td></tr>';
  267. if($export_csv){
  268. $temp=array(get_lang('NoDocumentDownloaded'),'');
  269. $csv_content[] = $temp;
  270. }
  271. }
  272. echo '</table></div>';
  273. echo '<div class="clear"></div>';
  274. /***************************
  275. * LEARNING PATHS
  276. ***************************/
  277. echo "<div class='admin_section'>
  278. <h4>
  279. <img src='../img/scormbuilder.gif' align='absbottom'>&nbsp;".get_lang('AverageProgressInLearnpath')."
  280. </h4>
  281. <table class='data_table'>";
  282. $list = new LearnpathList($student);
  283. $flat_list = $list->get_flat_list();
  284. if($export_csv){
  285. $temp=array(get_lang('AverageProgressInLearnpath'),'');
  286. $csv_content[] = array('','');
  287. $csv_content[] = $temp;
  288. }
  289. if(count($flat_list)>0)
  290. {
  291. foreach($flat_list as $lp_id => $lp)
  292. {
  293. $lp_avg_progress = 0;
  294. foreach($a_students as $student)
  295. {
  296. // get the progress in learning pathes
  297. $lp_avg_progress += learnpath::get_db_progress($lp_id,$student);
  298. }
  299. if($nbStudents > 0)
  300. {
  301. $lp_avg_progress = $lp_avg_progress / $nbStudents;
  302. }
  303. echo '<tr><td>'.$lp['lp_name'].'</td><td align="right">'.round($lp_avg_progress,1).' %</td></tr>';
  304. if($export_csv){
  305. $temp=array($lp['lp_name'],$lp_avg_progress);
  306. $csv_content[] = $temp;
  307. }
  308. }
  309. }
  310. else
  311. {
  312. echo '<tr><td>'.get_lang('NoLearningPath').'</td></tr>';
  313. if($export_csv){
  314. $temp=array(get_lang('NoLearningPath'),'');
  315. $csv_content[] = $temp;
  316. }
  317. }
  318. echo '</table></div>';
  319. echo '<div class="clear"></div>';
  320. /***************************
  321. * EXERCICES
  322. ***************************/
  323. echo "<div class='admin_section'>
  324. <h4>
  325. <img src='../img/quiz.gif' align='absbottom'>&nbsp;".get_lang('AverageResultsToTheExercices')."
  326. </h4>
  327. <table class='data_table'>";
  328. $sql = "SELECT id, title
  329. FROM ".Database :: get_course_table(TABLE_QUIZ_TEST);
  330. $rs = api_sql_query($sql, __FILE__, __LINE__);
  331. if($export_csv){
  332. $temp=array(get_lang('AverageProgressInLearnpath'),'');
  333. $csv_content[] = array('','');
  334. $csv_content[] = $temp;
  335. }
  336. if(mysql_num_rows($rs)>0)
  337. {
  338. while($quiz = mysql_fetch_array($rs))
  339. {
  340. $quiz_avg_score = 0;
  341. // get the progress in learning pathes
  342. $sql = 'SELECT exe_result , exe_weighting
  343. FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES).'
  344. WHERE exe_exo_id = '.$quiz['id'].'
  345. ORDER BY exe_date DESC
  346. LIMIT 0, 1';
  347. $rsAttempt = api_sql_query($sql, __FILE__, __LINE__);
  348. $nb_attempts = 0;
  349. while($attempt = mysql_fetch_array($rsAttempt))
  350. {
  351. $nb_attempts++;
  352. $quiz_avg_score += $attempt['exe_result']/$attempt['exe_weighting']*100;
  353. }
  354. if($nb_attempts>0)
  355. $quiz_avg_score = $quiz_avg_score / $nb_attempts;
  356. echo '<tr><td>'.$quiz['title'].'</td><td align="right">'.round($quiz_avg_score,1).' %</td></tr>';
  357. if($export_csv){
  358. $temp=array($quiz['title'],$quiz_avg_score);
  359. $csv_content[] = $temp;
  360. }
  361. }
  362. }
  363. else
  364. {
  365. echo '<tr><td>'.get_lang('NoExercises').'</td></tr>';
  366. if($export_csv){
  367. $temp=array(get_lang('NoExercises'),'');
  368. $csv_content[] = $temp;
  369. }
  370. }
  371. echo '</table></div>';
  372. // send the csv file if asked
  373. if($export_csv)
  374. {
  375. ob_end_clean();
  376. Export :: export_table_csv($csv_content, 'reporting_course_tracking');
  377. }
  378. }
  379. // else display student list with all the informations
  380. else {
  381. $tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : 0;
  382. $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : DESC;
  383. if(count($a_students)>0)
  384. {
  385. $table = new SortableTable('tracking', 'count_student_in_course');
  386. $table -> set_header(0, get_lang('LastName'));
  387. $table -> set_header(1, get_lang('FirstName'));
  388. $table -> set_header(2, get_lang('Time'),false);
  389. $table -> set_header(3, get_lang('Progress'),false);
  390. $table -> set_header(4, get_lang('Score'),false);
  391. $table -> set_header(5, get_lang('Student_publication'),false);
  392. $table -> set_header(6, get_lang('Messages'),false);
  393. $table -> set_header(7, get_lang('LatestLogin'));
  394. $table -> set_header(8, get_lang('Details'),false);
  395. if($export_csv)
  396. {
  397. $csv_content[] = array (
  398. get_lang('LastName'),
  399. get_lang('FirstName'),
  400. get_lang('Time'),
  401. get_lang('Progress'),
  402. get_lang('Score'),
  403. get_lang('Student_publication'),
  404. get_lang('Messages'),
  405. get_lang('LatestLogin')
  406. );
  407. }
  408. $all_datas = array();
  409. $course_code = $_course['id'];
  410. foreach($a_students as $student_id)
  411. {
  412. $student_datas = UserManager :: get_user_info_by_id($student_id);
  413. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0 ;
  414. $nb_courses_student = 0;
  415. $avg_time_spent = Tracking :: get_time_spent_on_the_course($student_id, $course_code);
  416. $avg_student_score = Tracking :: get_avg_student_score($student_id, $course_code);
  417. $avg_student_progress = Tracking :: get_avg_student_progress($student_id, $course_code);
  418. $total_assignments = Tracking :: count_student_assignments($student_id, $course_code);
  419. $total_messages = Tracking :: count_student_messages($student_id, $course_code);
  420. $row = array();
  421. $row[] = $student_datas['lastname'];
  422. $row[] = $student_datas['firstname'];
  423. $row[] = api_time_to_hms($avg_time_spent);
  424. $row[] = $avg_student_progress.' %';
  425. $row[] = $avg_student_score.' %';
  426. $row[] = $total_assignments;
  427. $row[] = $total_messages;
  428. $row[] = Tracking :: get_last_connection_date_on_the_course($student_id, $course_code);
  429. if($export_csv)
  430. {
  431. $csv_content[] = $row;
  432. }
  433. $row[] = '<a href="../mySpace/myStudents.php?student='.$student_id.'&details=true&course='.$course_code.'&origin=tracking_course"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  434. $all_datas[] = $row;
  435. }
  436. usort($all_datas, 'sort_users');
  437. if($tracking_direction == 'ASC')
  438. rsort($all_datas);
  439. if($export_csv)
  440. {
  441. usort($csv_content, 'sort_users');
  442. }
  443. foreach($all_datas as $row)
  444. {
  445. $table -> addRow($row,'align="right"');
  446. }
  447. $table -> setColAttributes(8,array('align'=>'center'));
  448. $table -> display();
  449. }
  450. else
  451. {
  452. echo get_lang('NoUsersInCourse');
  453. }
  454. // send the csv file if asked
  455. if($export_csv)
  456. {
  457. ob_end_clean();
  458. Export :: export_table_csv($csv_content, 'reporting_student_list');
  459. }
  460. }
  461. ?>
  462. </table>
  463. <?php
  464. Display::display_footer();
  465. ?>