courseLog.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  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, $_SESSION['id_session']);
  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. function sort_users($a, $b)
  122. {
  123. global $tracking_column;
  124. if($a[$tracking_column] > $b[$tracking_column])
  125. return 1;
  126. else
  127. return -1;
  128. }
  129. /*
  130. ==============================================================================
  131. MAIN CODE
  132. ==============================================================================
  133. */
  134. if($_GET['studentlist'] == 'false')
  135. {
  136. echo '<div style="float:left; clear:left">
  137. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a>&nbsp;|
  138. '.get_lang('CourseTracking').'
  139. </div>';
  140. }
  141. else
  142. {
  143. echo '<div style="float:left; clear:left">
  144. '.get_lang('StudentsTracking').' |
  145. <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a>&nbsp;
  146. </div>';
  147. }
  148. echo '<div style="float:right; clear:right">
  149. <a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>';
  150. if($_GET['studentlist'] == 'false'){
  151. echo '<a href="'.$_SERVER['PHP_SELF'].'?'.api_get_cidreq().'&export=csv&studentlist=false"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a></div>';
  152. }
  153. else{
  154. echo '<a href="'.$_SERVER['PHP_SELF'].'?'.api_get_cidreq().'&export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a></div>';
  155. }
  156. echo '<div class="clear"></div>';
  157. if($_GET['studentlist'] == 'false')
  158. {
  159. echo'<br /><br />';
  160. /**********************
  161. * TOOLS
  162. **********************/
  163. echo "<div class='admin_section'>
  164. <h4>
  165. <img src='../img/acces_tool.gif' align='absbottom'>&nbsp;".get_lang('ToolsMostUsed')."
  166. </h4>
  167. <table class='data_table'>";
  168. $sql = "SELECT `access_tool`, COUNT(DISTINCT `access_user_id`),count( `access_tool` ) as count_access_tool
  169. FROM $TABLETRACK_ACCESS
  170. WHERE `access_tool` IS NOT NULL
  171. AND `access_cours_code` = '$_cid'
  172. GROUP BY `access_tool`
  173. ORDER BY count_access_tool DESC
  174. LIMIT 0, 3";
  175. $rs = api_sql_query($sql, __FILE__, __LINE__);
  176. if($export_csv){
  177. $temp=array(get_lang('ToolsMostUsed'),'');
  178. $csv_content[] = $temp;
  179. }
  180. while ($row = mysql_fetch_array($rs))
  181. {
  182. echo ' <tr>
  183. <td>'.get_lang(ucfirst($row['access_tool'])).'</td>
  184. <td align="right">'.$row['count_access_tool'].' '.get_lang('Clicks').'</td>
  185. </tr>';
  186. if($export_csv){
  187. $temp=array(get_lang(ucfirst($row['access_tool'])),$row['count_access_tool'].' '.get_lang('Clicks'));
  188. $csv_content[] = $temp;
  189. }
  190. }
  191. echo '</table></div>';
  192. echo '<div class="clear"></div>';
  193. /***************************
  194. * LINKS
  195. ***************************/
  196. echo "<div class='admin_section'>
  197. <h4>
  198. <img src='../img/link.gif' align='absbottom'>&nbsp;".get_lang('LinksMostClicked')."
  199. </h4>
  200. <table class='data_table'>";
  201. $sql = "SELECT `cl`.`title`, `cl`.`url`,count(DISTINCT `sl`.`links_user_id`), count(`cl`.`title`) as count_visits
  202. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  203. WHERE `sl`.`links_link_id` = `cl`.`id`
  204. AND `sl`.`links_cours_id` = '$_cid'
  205. GROUP BY `cl`.`title`, `cl`.`url`
  206. ORDER BY count_visits DESC
  207. LIMIT 0, 3";
  208. $rs = api_sql_query($sql, __FILE__, __LINE__);
  209. if($export_csv){
  210. $temp=array(get_lang('LinksMostClicked'),'');
  211. $csv_content[] = array('','');
  212. $csv_content[] = $temp;
  213. }
  214. if(mysql_num_rows($rs)>0)
  215. {
  216. while($row = mysql_fetch_array($rs))
  217. {
  218. echo ' <tr>
  219. <td>'.$row['title'].'</td>
  220. <td align="right">'.$row['count_visits'].' '.get_lang('Clicks').'</td>
  221. </tr>';
  222. if($export_csv){
  223. $temp=array($row['title'],$row['count_visits'].' '.get_lang('Clicks'));
  224. $csv_content[] = $temp;
  225. }
  226. }
  227. }
  228. else
  229. {
  230. echo '<tr><td>'.get_lang('NoLinkVisited').'</td></tr>';
  231. if($export_csv){
  232. $temp=array(get_lang('NoLinkVisited'),'');
  233. $csv_content[] = $temp;
  234. }
  235. }
  236. echo '</table></div>';
  237. echo '<div class="clear"></div>';
  238. /***************************
  239. * DOCUMENTS
  240. ***************************/
  241. echo "<div class='admin_section'>
  242. <h4>
  243. <img src='../img/documents.gif' align='absbottom'>&nbsp;".get_lang('DocumentsMostDownloaded')."
  244. </h4>
  245. <table class='data_table'>";
  246. $sql = "SELECT `down_doc_path`, COUNT(DISTINCT `down_user_id`), COUNT(`down_doc_path`) as count_down
  247. FROM $TABLETRACK_DOWNLOADS
  248. WHERE `down_cours_id` = '$_cid'
  249. GROUP BY `down_doc_path`
  250. ORDER BY count_down DESC
  251. LIMIT 0, 3";
  252. $rs = api_sql_query($sql, __FILE__, __LINE__);
  253. if($export_csv){
  254. $temp=array(get_lang('DocumentsMostDownloaded'),'');
  255. $csv_content[] = array('','');
  256. $csv_content[] = $temp;
  257. }
  258. if(mysql_num_rows($rs)>0)
  259. {
  260. while($row = mysql_fetch_array($rs))
  261. {
  262. echo ' <tr>
  263. <td>'.$row['down_doc_path'].'</td>
  264. <td align="right">'.$row['count_down'].' '.get_lang('Clicks').'</td>
  265. </tr>';
  266. if($export_csv){
  267. $temp=array($row['down_doc_path'],$row['count_down'].' '.get_lang('Clicks'));
  268. $csv_content[] = $temp;
  269. }
  270. }
  271. }
  272. else
  273. {
  274. echo '<tr><td>'.get_lang('NoDocumentDownloaded').'</td></tr>';
  275. if($export_csv){
  276. $temp=array(get_lang('NoDocumentDownloaded'),'');
  277. $csv_content[] = $temp;
  278. }
  279. }
  280. echo '</table></div>';
  281. echo '<div class="clear"></div>';
  282. /***************************
  283. * LEARNING PATHS
  284. ***************************/
  285. echo "<div class='admin_section'>
  286. <h4>
  287. <img src='../img/scormbuilder.gif' align='absbottom'>&nbsp;".get_lang('AverageProgressInLearnpath')."
  288. </h4>
  289. <table class='data_table'>";
  290. $list = new LearnpathList($student);
  291. $flat_list = $list->get_flat_list();
  292. if($export_csv){
  293. $temp=array(get_lang('AverageProgressInLearnpath'),'');
  294. $csv_content[] = array('','');
  295. $csv_content[] = $temp;
  296. }
  297. if(count($flat_list)>0)
  298. {
  299. foreach($flat_list as $lp_id => $lp)
  300. {
  301. $lp_avg_progress = 0;
  302. foreach($a_students as $student_id => $student)
  303. {
  304. // get the progress in learning pathes
  305. $lp_avg_progress += learnpath::get_db_progress($lp_id,$student_id);
  306. }
  307. if($nbStudents > 0)
  308. {
  309. $lp_avg_progress = $lp_avg_progress / $nbStudents;
  310. }
  311. echo '<tr><td>'.$lp['lp_name'].'</td><td align="right">'.round($lp_avg_progress,1).' %</td></tr>';
  312. if($export_csv){
  313. $temp=array($lp['lp_name'],$lp_avg_progress);
  314. $csv_content[] = $temp;
  315. }
  316. }
  317. }
  318. else
  319. {
  320. echo '<tr><td>'.get_lang('NoLearningPath').'</td></tr>';
  321. if($export_csv){
  322. $temp=array(get_lang('NoLearningPath'),'');
  323. $csv_content[] = $temp;
  324. }
  325. }
  326. echo '</table></div>';
  327. echo '<div class="clear"></div>';
  328. /***************************
  329. * EXERCICES
  330. ***************************/
  331. echo "<div class='admin_section'>
  332. <h4>
  333. <img src='../img/quiz.gif' align='absbottom'>&nbsp;".get_lang('AverageResultsToTheExercices')."
  334. </h4>
  335. <table class='data_table'>";
  336. $sql = "SELECT id, title
  337. FROM ".Database :: get_course_table(TABLE_QUIZ_TEST);
  338. $rs = api_sql_query($sql, __FILE__, __LINE__);
  339. if($export_csv){
  340. $temp=array(get_lang('AverageProgressInLearnpath'),'');
  341. $csv_content[] = array('','');
  342. $csv_content[] = $temp;
  343. }
  344. if(mysql_num_rows($rs)>0)
  345. {
  346. while($quiz = mysql_fetch_array($rs))
  347. {
  348. $quiz_avg_score = 0;
  349. // get the progress in learning pathes
  350. $sql = 'SELECT exe_result , exe_weighting
  351. FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES).'
  352. WHERE exe_exo_id = '.$quiz['id'].'
  353. ORDER BY exe_date DESC
  354. LIMIT 0, 1';
  355. $rsAttempt = api_sql_query($sql, __FILE__, __LINE__);
  356. $nb_attempts = 0;
  357. while($attempt = mysql_fetch_array($rsAttempt))
  358. {
  359. $nb_attempts++;
  360. $quiz_avg_score += $attempt['exe_result']/$attempt['exe_weighting']*100;
  361. }
  362. if($nb_attempts>0)
  363. $quiz_avg_score = $quiz_avg_score / $nb_attempts;
  364. echo '<tr><td>'.$quiz['title'].'</td><td align="right">'.round($quiz_avg_score,1).' %</td></tr>';
  365. if($export_csv){
  366. $temp=array($quiz['title'],$quiz_avg_score);
  367. $csv_content[] = $temp;
  368. }
  369. }
  370. }
  371. else
  372. {
  373. echo '<tr><td>'.get_lang('NoExercises').'</td></tr>';
  374. if($export_csv){
  375. $temp=array(get_lang('NoExercises'),'');
  376. $csv_content[] = $temp;
  377. }
  378. }
  379. echo '</table></div>';
  380. // send the csv file if asked
  381. if($export_csv)
  382. {
  383. ob_end_clean();
  384. Export :: export_table_csv($csv_content, 'reporting_course_tracking');
  385. }
  386. }
  387. // else display student list with all the informations
  388. else {
  389. $tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : 0;
  390. $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : DESC;
  391. if(count($a_students)>0)
  392. {
  393. $table = new SortableTable('tracking', 'count_student_in_course');
  394. $table -> set_header(0, get_lang('LastName'), true, 'align="center"');
  395. $table -> set_header(1, get_lang('FirstName'), true, 'align="center"');
  396. $table -> set_header(2, get_lang('Time'),false);
  397. $table -> set_header(3, get_lang('Progress'),false);
  398. $table -> set_header(4, get_lang('Score'),false);
  399. $table -> set_header(5, get_lang('Student_publication'),false);
  400. $table -> set_header(6, get_lang('Messages'),false);
  401. $table -> set_header(7, get_lang('LatestLogin'), true, 'align="center"');
  402. $table -> set_header(8, get_lang('Details'),false);
  403. if($export_csv)
  404. {
  405. $csv_content[] = array (
  406. get_lang('LastName'),
  407. get_lang('FirstName'),
  408. get_lang('Time'),
  409. get_lang('Progress'),
  410. get_lang('Score'),
  411. get_lang('Student_publication'),
  412. get_lang('Messages'),
  413. get_lang('LatestLogin')
  414. );
  415. }
  416. $all_datas = array();
  417. $course_code = $_course['id'];
  418. foreach($a_students as $student_id => $student)
  419. {
  420. $student_datas = UserManager :: get_user_info_by_id($student_id);
  421. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0 ;
  422. $nb_courses_student = 0;
  423. $avg_time_spent = Tracking :: get_time_spent_on_the_course($student_id, $course_code);
  424. $avg_student_score = Tracking :: get_avg_student_score($student_id, $course_code);
  425. $avg_student_progress = Tracking :: get_avg_student_progress($student_id, $course_code);
  426. $total_assignments = Tracking :: count_student_assignments($student_id, $course_code);
  427. $total_messages = Tracking :: count_student_messages($student_id, $course_code);
  428. $row = array();
  429. $row[] = $student_datas['lastname'];
  430. $row[] = $student_datas['firstname'];
  431. $row[] = api_time_to_hms($avg_time_spent);
  432. $row[] = $avg_student_progress.' %';
  433. $row[] = $avg_student_score.' %';
  434. $row[] = $total_assignments;
  435. $row[] = $total_messages;
  436. $row[] = Tracking :: get_last_connection_date_on_the_course($student_id, $course_code);
  437. if($export_csv)
  438. {
  439. $csv_content[] = $row;
  440. }
  441. $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>';
  442. $all_datas[] = $row;
  443. }
  444. usort($all_datas, 'sort_users');
  445. if($tracking_direction == 'ASC')
  446. rsort($all_datas);
  447. if($export_csv)
  448. {
  449. usort($csv_content, 'sort_users');
  450. }
  451. foreach($all_datas as $row)
  452. {
  453. $table -> addRow($row,'align="right"');
  454. }
  455. $table -> setColAttributes(0,array('align'=>'left'));
  456. $table -> setColAttributes(1,array('align'=>'left'));
  457. $table -> setColAttributes(7,array('align'=>'left'));
  458. $table -> setColAttributes(8,array('align'=>'center'));
  459. $table -> display();
  460. }
  461. else
  462. {
  463. echo get_lang('NoUsersInCourse');
  464. }
  465. // send the csv file if asked
  466. if($export_csv)
  467. {
  468. ob_end_clean();
  469. Export :: export_table_csv($csv_content, 'reporting_student_list');
  470. }
  471. }
  472. ?>
  473. </table>
  474. <?php
  475. Display::display_footer();
  476. ?>