courseLog.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. <?php //$id: $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. * @author Thomas Depraetere
  6. * @author Hugues Peeters
  7. * @author Christophe Gesche
  8. * @author Sebastien Piraux
  9. * @author Toon Keppens (Vi-Host.net)
  10. *
  11. * @package dokeos.tracking
  12. ==============================================================================
  13. */
  14. /**
  15. * INIT SECTION
  16. */
  17. $pathopen = isset($_REQUEST['pathopen']) ? $_REQUEST['pathopen'] : null;
  18. // name of the language file that needs to be included
  19. $language_file[] = 'admin';
  20. $language_file[] = 'tracking';
  21. $language_file[] = 'scorm';
  22. // including the global Dokeos file
  23. require '../inc/global.inc.php';
  24. // the section (for the tabs)
  25. //$this_section = "session_my_space";
  26. $from_myspace = false;
  27. if (isset($_GET['from']) && $_GET['from'] == 'myspace') {
  28. $from_myspace = true;
  29. $this_section = "session_my_space";
  30. } else {
  31. $this_section = SECTION_COURSES;
  32. }
  33. $is_allowedToTrack = $is_courseAdmin || $is_platformAdmin || $is_courseCoach || $is_sessionAdmin;
  34. if (!$is_allowedToTrack) {
  35. Display :: display_header(null);
  36. api_not_allowed();
  37. Display :: display_footer();
  38. exit;
  39. }
  40. // including additional libraries
  41. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  42. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
  43. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  44. require_once api_get_path(SYS_CODE_PATH).'newscorm/scorm.class.php';
  45. require_once api_get_path(SYS_CODE_PATH).'newscorm/scormItem.class.php';
  46. require_once api_get_path(LIBRARY_PATH).'tracking.lib.php';
  47. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  48. require_once api_get_path(LIBRARY_PATH).'usermanager.lib.php';
  49. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  50. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  51. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  52. if ($export_csv) {
  53. ob_start();
  54. }
  55. $csv_content = array();
  56. // charset determination
  57. if (!empty($_GET['scormcontopen'])) {
  58. $tbl_lp = Database::get_course_table(TABLE_LP_MAIN);
  59. $contopen = (int) $_GET['scormcontopen'];
  60. $sql = "SELECT default_encoding FROM $tbl_lp WHERE id = ".$contopen;
  61. $res = Database::query($sql,__FILE__,__LINE__);
  62. $row = Database::fetch_array($res);
  63. $lp_charset = $row['default_encoding'];
  64. }
  65. $htmlHeadXtra[] = "<style type='text/css'>
  66. /*<![CDATA[*/
  67. .secLine {background-color : #E6E6E6;}
  68. .content {padding-left : 15px;padding-right : 15px; }
  69. .specialLink{color : #0000FF;}
  70. /*]]>*/
  71. </style>
  72. <style media='print' type='text/css'>
  73. </style>";
  74. /*
  75. -----------------------------------------------------------
  76. Constants and variables
  77. -----------------------------------------------------------
  78. */
  79. // regroup table names for maintenance purpose
  80. $TABLETRACK_ACCESS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  81. $TABLETRACK_LINKS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LINKS);
  82. $TABLETRACK_DOWNLOADS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
  83. $TABLETRACK_ACCESS_2 = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  84. $TABLETRACK_EXERCISES = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  85. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  86. $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
  87. $TABLECOURSE_LINKS = Database::get_course_table(TABLE_LINK);
  88. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  89. $TABLEQUIZ = Database :: get_course_table(TABLE_QUIZ_TEST);
  90. //$table_scormdata = Database::get_scorm_table(TABLE_SCORM_SCO_DATA);
  91. //$table_scormmain = Database::get_scorm_table(TABLE_SCORM_MAIN);
  92. //$tbl_learnpath_main = Database::get_course_table(TABLE_LEARNPATH_MAIN);
  93. //$tbl_learnpath_item = Database::get_course_table(TABLE_LEARNPATH_ITEM);
  94. //$tbl_learnpath_chapter = Database::get_course_table(TABLE_LEARNPATH_CHAPTER);
  95. $tbl_learnpath_main = Database::get_course_table(TABLE_LP_MAIN);
  96. $tbl_learnpath_item = Database::get_course_table(TABLE_LP_ITEM);
  97. $tbl_learnpath_view = Database::get_course_table(TABLE_LP_VIEW);
  98. $tbl_learnpath_item_view = Database::get_course_table(TABLE_LP_ITEM_VIEW);
  99. if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  100. $interbreadcrumb[] = array('url' => '../admin/index.php','name' => get_lang('PlatformAdmin'));
  101. $interbreadcrumb[] = array('url' => '../admin/session_list.php','name' => get_lang('SessionList'));
  102. $interbreadcrumb[] = array('url' => '../admin/resume_session.php?id_session='.$_SESSION['id_session'], 'name' => get_lang('SessionOverview'));
  103. }
  104. $view = (isset($_REQUEST['view']) ? $_REQUEST['view'] : '');
  105. $nameTools = get_lang('Tracking');
  106. Display::display_header($nameTools, 'Tracking');
  107. require api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
  108. require api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
  109. $a_students = CourseManager :: get_student_list_from_course_code($_course['id'], true, (empty($_SESSION['id_session']) ? null : $_SESSION['id_session']));
  110. $nbStudents = count($a_students);
  111. /**
  112. * count the number of students in this course (used for SortableTable)
  113. */
  114. function count_student_in_course() {
  115. global $nbStudents;
  116. return $nbStudents;
  117. }
  118. function sort_users($a, $b) {
  119. return api_strcmp(trim(api_strtolower($a[$_SESSION['tracking_column']])), trim(api_strtolower($b[$_SESSION['tracking_column']])));
  120. }
  121. function count_item_resources() {
  122. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  123. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  124. $sql = "SELECT count(tool) AS total_number_of_items FROM $table_item_property track_resource, $table_user user" .
  125. " WHERE track_resource.insert_user_id = user.user_id";
  126. if (isset($_GET['keyword'])) {
  127. $keyword = Database::escape_string($_GET['keyword']);
  128. $sql .= " AND (user.username LIKE '%".$keyword."%' OR lastedit_type LIKE '%".$keyword."%' OR tool LIKE '%".$keyword."%')";
  129. }
  130. $sql .= " AND tool IN ('document', 'learnpath', 'quiz', 'glossary', 'link', 'course_description')";
  131. $res = Database::query($sql, __FILE__, __LINE__);
  132. $obj = Database::fetch_object($res);
  133. return $obj->total_number_of_items;
  134. }
  135. function get_item_resources_data($from, $number_of_items, $column, $direction) {
  136. global $dateTimeFormatLong;
  137. $table_item_property = Database :: get_course_table(TABLE_ITEM_PROPERTY);
  138. $table_user = Database :: get_main_table(TABLE_MAIN_USER);
  139. $table_session = Database :: get_main_table(TABLE_MAIN_SESSION);
  140. $sql = "SELECT
  141. tool as col0,
  142. lastedit_type as col1,
  143. ref as ref,
  144. user.username as col3,
  145. insert_date as col5,
  146. visibility as col6
  147. FROM $table_item_property track_resource, $table_user user
  148. WHERE track_resource.insert_user_id = user.user_id ";
  149. if (isset($_GET['keyword'])) {
  150. $keyword = Database::escape_string($_GET['keyword']);
  151. $sql .= " AND (user.username LIKE '%".$keyword."%' OR lastedit_type LIKE '%".$keyword."%' OR tool LIKE '%".$keyword."%') ";
  152. }
  153. $sql .= " AND tool IN ('document', 'learnpath', 'quiz', 'glossary', 'link', 'course_description')";
  154. if ($column == 0) { $column = '0'; }
  155. if ($column != '' && $direction != '') {
  156. if ($column != 2 && $column != 4) {
  157. $sql .= " ORDER BY col$column $direction";
  158. }
  159. } else {
  160. $sql .= " ORDER BY col5 DESC ";
  161. }
  162. $sql .= " LIMIT $from, $number_of_items ";
  163. $res = Database::query($sql, __FILE__, __LINE__) or die(mysql_error());
  164. $resources = array ();
  165. while ($row = Database::fetch_array($res)) {
  166. $ref = $row['ref'];
  167. $table_name = get_tool_name_table($row['col0']);
  168. $table_tool = Database :: get_course_table($table_name['table_name']);
  169. $id = $table_name['id_tool'];
  170. $query = "SELECT session.id, session.name, user.username FROM $table_tool tool, $table_session session, $table_user user" .
  171. " WHERE tool.session_id = session.id AND session.id_coach = user.user_id AND tool.$id = $ref";
  172. $recorset = Database::query($query, __FILE__, __LINE__);
  173. if (!empty($recorset)) {
  174. $obj = Database::fetch_object($recorset);
  175. $name_session = '';
  176. $coach_name = '';
  177. if (!empty($obj)) {
  178. $name_session = $obj->name;
  179. $coach_name = $obj->username;
  180. }
  181. $url_tool = api_get_path(WEB_CODE_PATH).$table_name['link_tool'];
  182. $row[0] = '';
  183. if ($row['col6'] != 2) {
  184. $row[0] = '<a href="'.$url_tool.'?'.api_get_cidreq().'&'.$obj->id.'">'.api_ucfirst($row['col0']).'</a>';
  185. } else {
  186. $row[0] = api_ucfirst($row['col0']);
  187. }
  188. $row[1] = get_lang($row[1]);
  189. $row[5] = api_ucfirst(format_locale_date($dateTimeFormatLong, strtotime($row['col5'])));
  190. $row[4] = '';
  191. if ($table_name['table_name'] == 'document') {
  192. $condition = 'tool.title as title';
  193. $query_document = "SELECT $condition FROM $table_tool tool" .
  194. " WHERE id = $ref";
  195. $rs_document = Database::query($query_document, __FILE__, __LINE__) or die(mysql_error());
  196. $obj_document = Database::fetch_object($rs_document);
  197. $row[4] = $obj_document->title;
  198. }
  199. $row2 = $name_session;
  200. if (!empty($coach_name)) {
  201. $row2 .= '<br />'.get_lang('Coach').': '.$coach_name;
  202. }
  203. $row[2] = $row2;
  204. $resources[] = $row;
  205. }
  206. }
  207. return $resources;
  208. }
  209. function get_tool_name_table($tool) {
  210. switch ($tool) {
  211. case 'document':
  212. $table_name = TABLE_DOCUMENT;
  213. $link_tool = 'document/document.php';
  214. $id_tool = 'id';
  215. break;
  216. case 'learnpath':
  217. $table_name = TABLE_LP_MAIN;
  218. $link_tool = 'newscorm/lp_controller.php';
  219. $id_tool = 'id';
  220. break;
  221. case 'quiz':
  222. $table_name = TABLE_QUIZ_TEST;
  223. $link_tool = 'exercice/exercice.php';
  224. $id_tool = 'id';
  225. break;
  226. case 'glossary':
  227. $table_name = TABLE_GLOSSARY;
  228. $link_tool = 'glossary/index.php';
  229. $id_tool = 'glossary_id';
  230. break;
  231. case 'link':
  232. $table_name = TABLE_LINK;
  233. $link_tool = 'link/link.php';
  234. $id_tool = 'id';
  235. break;
  236. case 'course_description':
  237. $table_name = TABLE_COURSE_DESCRIPTION;
  238. $link_tool = 'course_description/';
  239. $id_tool = 'id';
  240. break;
  241. default:
  242. $table_name = $tool;
  243. break;
  244. }
  245. return array('table_name' => $table_name,
  246. 'link_tool' => $link_tool,
  247. 'id_tool' => $id_tool);
  248. }
  249. /*
  250. ==============================================================================
  251. MAIN CODE
  252. ==============================================================================
  253. */
  254. echo '<div class="actions">';
  255. if ($_GET['studentlist'] == 'false') {
  256. echo '<a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a> | '.get_lang('CourseTracking').' | <a href="courseLog.php?'.api_get_cidreq().'&studentlist=resources">'.get_lang('ResourcesTracking');
  257. } elseif($_GET['studentlist'] == 'resources') {
  258. echo '<a href="courseLog.php?'.api_get_cidreq().'&studentlist=true">'.get_lang('StudentsTracking').'</a> | <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a> | '.get_lang('ResourcesTracking');
  259. } elseif($_GET['studentlist'] == '' || $_GET['studentlist'] == 'true') {
  260. echo get_lang('StudentsTracking').' | <a href="courseLog.php?'.api_get_cidreq().'&studentlist=false">'.get_lang('CourseTracking').'</a> | <a href="courseLog.php?'.api_get_cidreq().'&studentlist=resources">'.get_lang('ResourcesTracking').'</a>';
  261. }
  262. echo '&nbsp;<a href="javascript: void(0);" onclick="javascript: window.print();"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>';
  263. if($_GET['studentlist'] == 'false') {
  264. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&studentlist=false"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>';
  265. } elseif ($_GET['studentlist'] == '' || $_GET['studentlist'] == 'true') {
  266. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>';
  267. }
  268. echo '</div>';
  269. if ($_GET['studentlist'] == 'false') {
  270. echo'<br /><br />';
  271. /***************************
  272. * LEARNING PATHS
  273. ***************************/
  274. echo '<div class="report_section">
  275. <h4>
  276. <img src="../img/scormbuilder.gif" align="absbottom">&nbsp;'.get_lang('AverageProgressInLearnpath').'
  277. </h4>
  278. <table class="data_table">';
  279. $list = new LearnpathList($student);
  280. $flat_list = $list->get_flat_list();
  281. if ($export_csv) {
  282. $temp = array(get_lang('AverageProgressInLearnpath', ''), '');
  283. $csv_content[] = array('', '');
  284. $csv_content[] = $temp;
  285. }
  286. if (count($flat_list) > 0) {
  287. foreach ($flat_list as $lp_id => $lp) {
  288. $lp_avg_progress = 0;
  289. foreach ($a_students as $student_id => $student) {
  290. // get the progress in learning pathes
  291. $lp_avg_progress += learnpath::get_db_progress($lp_id, $student_id);
  292. }
  293. if ($nbStudents > 0) {
  294. $lp_avg_progress = $lp_avg_progress / $nbStudents;
  295. } else {
  296. $lp_avg_progress = null;
  297. }
  298. // Separated presentation logic.
  299. if (is_null($lp_avg_progress)) {
  300. $lp_avg_progress = '0%';
  301. } else {
  302. $lp_avg_progress = round($lp_avg_progress, 1).'%';
  303. }
  304. echo '<tr><td>'.$lp['lp_name'].'</td><td align="right">'.$lp_avg_progress.'</td></tr>';
  305. if ($export_csv) {
  306. $temp = array($lp['lp_name'], $lp_avg_progress);
  307. $csv_content[] = $temp;
  308. }
  309. }
  310. } else {
  311. echo '<tr><td>'.get_lang('NoLearningPath').'</td></tr>';
  312. if ($export_csv) {
  313. $temp = array(get_lang('NoLearningPath', ''), '');
  314. $csv_content[] = $temp;
  315. }
  316. }
  317. echo '</table></div>';
  318. echo '<div class="clear"></div>';
  319. /***************************
  320. * EXERCICES
  321. ***************************/
  322. echo '<div class="report_section">
  323. <h4>
  324. <img src="../img/quiz.gif" align="absbottom">&nbsp;'.get_lang('AverageResultsToTheExercices').' &nbsp;-&nbsp;<a href="../exercice/exercice.php?'.api_get_cidreq().'&show=result">'.get_lang('SeeDetail').'</a>
  325. </h4>
  326. <table class="data_table">';
  327. $sql = "SELECT id, title
  328. FROM $TABLEQUIZ WHERE active <> -1";
  329. $rs = Database::query($sql, __FILE__, __LINE__);
  330. if ($export_csv) {
  331. $temp = array(get_lang('AverageProgressInLearnpath'), '');
  332. $csv_content[] = array('', '');
  333. $csv_content[] = $temp;
  334. }
  335. if (Database::num_rows($rs) > 0) {
  336. // gets course actual administrators
  337. $sql = "SELECT user.user_id FROM $table_user user, $TABLECOURSUSER course_user
  338. WHERE course_user.user_id=user.user_id AND course_user.course_code='".api_get_course_id()."' AND course_user.status <> '1' ";
  339. $res = Database::query($sql, __FILE__, __LINE__);
  340. $student_ids = array();
  341. while($row = Database::fetch_row($res)) {
  342. $student_ids[] = $row[0];
  343. }
  344. $count_students = count($student_ids);
  345. while ($quiz = Database::fetch_array($rs)) {
  346. $quiz_avg_score = 0;
  347. if ($count_students > 0) {
  348. foreach ($student_ids as $student_id) {
  349. // get the scorn in exercises
  350. $sql = 'SELECT exe_result , exe_weighting
  351. FROM '.$TABLETRACK_EXERCISES.'
  352. WHERE exe_exo_id = '.$quiz['id'].'
  353. AND exe_user_id = '.(int)$student_id.'
  354. AND exe_cours_id = "'.api_get_course_id().'"
  355. AND orig_lp_id = 0
  356. AND orig_lp_item_id = 0
  357. ORDER BY exe_date DESC';
  358. $rsAttempt = Database::query($sql, __FILE__, __LINE__);
  359. $nb_attempts = 0;
  360. $avg_student_score = 0;
  361. while ($attempt = Database::fetch_array($rsAttempt)) {
  362. $nb_attempts++;
  363. $exe_weight = $attempt['exe_weighting'];
  364. if ($exe_weight > 0) {
  365. $avg_student_score += round(($attempt['exe_result'] / $exe_weight * 100), 2);
  366. }
  367. }
  368. if ($nb_attempts > 0) {
  369. $avg_student_score = $avg_student_score / $nb_attempts;
  370. }
  371. $quiz_avg_score += $avg_student_score;
  372. }
  373. }
  374. $count_students = ($count_students == 0 || is_null($count_students) || $count_students == '') ? 1 : $count_students;
  375. echo '<tr><td>'.$quiz['title'].'</td><td align="right">'.round(($quiz_avg_score / $count_students), 2).'%'.'</td></tr>';
  376. if ($export_csv) {
  377. $temp = array($quiz['title'], $quiz_avg_score);
  378. $csv_content[] = $temp;
  379. }
  380. }
  381. } else {
  382. echo '<tr><td>'.get_lang('NoExercises').'</td></tr>';
  383. if ($export_csv) {
  384. $temp = array(get_lang('NoExercises', ''), '');
  385. $csv_content[] = $temp;
  386. }
  387. }
  388. echo '</table></div>';
  389. echo '<div class="clear"></div>';
  390. /**********************
  391. * FORUMS
  392. **********************/
  393. echo '<div class="report_section">
  394. <h4>
  395. <img src="../img/forum.gif" align="absbottom">&nbsp;'.get_lang('Forum').'&nbsp;-&nbsp;<a href="../forum/index.php?cidReq='.$_course['id'].'">'.get_lang('SeeDetail').'</a>
  396. </h4>
  397. <table class="data_table">';
  398. $count_number_of_posts_by_course = Tracking :: count_number_of_posts_by_course($_course['id']);
  399. $count_number_of_forums_by_course = Tracking :: count_number_of_forums_by_course($_course['id']);
  400. $count_number_of_threads_by_course = Tracking :: count_number_of_threads_by_course($_course['id']);
  401. if ($export_csv) {
  402. $csv_content[] = array(get_lang('Forum'), '');
  403. $csv_content[] = array(get_lang('ForumForumsNumber', ''), $count_number_of_forums_by_course);
  404. $csv_content[] = array(get_lang('ForumThreadsNumber', ''), $count_number_of_threads_by_course);
  405. $csv_content[] = array(get_lang('ForumPostsNumber', ''), $count_number_of_posts_by_course);
  406. }
  407. echo '<tr><td>'.get_lang('ForumForumsNumber').'</td><td align="right">'.$count_number_of_forums_by_course.'</td></tr>';
  408. echo '<tr><td>'.get_lang('ForumThreadsNumber').'</td><td align="right">'.$count_number_of_threads_by_course.'</td></tr>';
  409. echo '<tr><td>'.get_lang('ForumPostsNumber').'</td><td align="right">'.$count_number_of_posts_by_course.'</td></tr>';
  410. echo '</table></div>';
  411. echo '<div class="clear"></div>';
  412. /**********************
  413. * CHAT
  414. **********************/
  415. echo '<div class="report_section">
  416. <h4>
  417. <img src="../img/chat.gif" align="absbottom">&nbsp;'.get_lang('Chat').'</a>
  418. </h4>
  419. <table class="data_table">';
  420. $chat_connections_during_last_x_days_by_course = Tracking :: chat_connections_during_last_x_days_by_course($_course['id'], 7);
  421. if ($export_csv) {
  422. $csv_content[] = array(get_lang('Chat', ''), '');
  423. $csv_content[] = array(sprintf(get_lang('ChatConnectionsDuringLastXDays', ''), '7'), $chat_connections_during_last_x_days_by_course);
  424. }
  425. echo '<tr><td>'.sprintf(get_lang('ChatConnectionsDuringLastXDays'), '7').'</td><td align="right">'.$chat_connections_during_last_x_days_by_course.'</td></tr>';
  426. echo '</table></div>';
  427. echo '<div class="clear"></div>';
  428. /**********************
  429. * TOOLS
  430. **********************/
  431. echo '<div class="report_section">
  432. <h4>
  433. <img src="../img/acces_tool.gif" align="absbottom">&nbsp;'.get_lang('ToolsMostUsed').'
  434. </h4>
  435. <table class="data_table">';
  436. $sql = "SELECT access_tool, COUNT(DISTINCT access_user_id),count( access_tool ) as count_access_tool
  437. FROM $TABLETRACK_ACCESS
  438. WHERE access_tool IS NOT NULL
  439. AND access_cours_code = '$_cid'
  440. GROUP BY access_tool
  441. ORDER BY count_access_tool DESC
  442. LIMIT 0, 3";
  443. $rs = Database::query($sql, __FILE__, __LINE__);
  444. if ($export_csv) {
  445. $temp = array(get_lang('ToolsMostUsed'), '');
  446. $csv_content[] = $temp;
  447. }
  448. while ($row = Database::fetch_array($rs)) {
  449. echo ' <tr>
  450. <td>'.get_lang(ucfirst($row['access_tool'])).'</td>
  451. <td align="right">'.$row['count_access_tool'].' '.get_lang('Clicks').'</td>
  452. </tr>';
  453. if ($export_csv) {
  454. $temp = array(get_lang(ucfirst($row['access_tool']), ''), $row['count_access_tool'].' '.get_lang('Clicks', ''));
  455. $csv_content[] = $temp;
  456. }
  457. }
  458. echo '</table></div>';
  459. echo '<div class="clear"></div>';
  460. /***************************
  461. * DOCUMENTS
  462. ***************************/
  463. if ($_GET['num'] == 0 or empty($_GET['num'])) {
  464. $num = 3;
  465. $link = '&nbsp;-&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&studentlist=false&num=1#ancle">'.get_lang('SeeDetail').'</a>';
  466. } else {
  467. $num = 1000;
  468. $link = '&nbsp;-&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&studentlist=false&num=0#ancle">'.get_lang('ViewMinus').'</a>';
  469. }
  470. echo '<a name="ancle" id="a"></a><div class="report_section">
  471. <h4>
  472. <img src="../img/documents.gif" align="absbottom">&nbsp;'.get_lang('DocumentsMostDownloaded').$link.'
  473. </h4>
  474. <table class="data_table">';
  475. $sql = "SELECT down_doc_path, COUNT(DISTINCT down_user_id), COUNT(down_doc_path) as count_down
  476. FROM $TABLETRACK_DOWNLOADS
  477. WHERE down_cours_id = '$_cid'
  478. GROUP BY down_doc_path
  479. ORDER BY count_down DESC
  480. LIMIT 0, $num";
  481. $rs = Database::query($sql, __FILE__, __LINE__);
  482. if ($export_csv) {
  483. $temp = array(get_lang('DocumentsMostDownloaded', ''), '');
  484. $csv_content[] = array('', '');
  485. $csv_content[] = $temp;
  486. }
  487. if (Database::num_rows($rs) > 0) {
  488. while($row = Database::fetch_array($rs)) {
  489. echo ' <tr>
  490. <td>'.$row['down_doc_path'].'</td>
  491. <td align="right">'.$row['count_down'].' '.get_lang('Clicks').'</td>
  492. </tr>';
  493. if ($export_csv) {
  494. $temp = array($row['down_doc_path'], $row['count_down'].' '.get_lang('Clicks', ''));
  495. $csv_content[] = $temp;
  496. }
  497. }
  498. } else {
  499. echo '<tr><td>'.get_lang('NoDocumentDownloaded').'</td></tr>';
  500. if ($export_csv) {
  501. $temp = array(get_lang('NoDocumentDownloaded', ''),'');
  502. $csv_content[] = $temp;
  503. }
  504. }
  505. echo '</table></div>';
  506. echo '<div class="clear"></div>';
  507. /***************************
  508. * LINKS
  509. ***************************/
  510. echo '<div class="report_section">
  511. <h4>
  512. <img src="../img/link.gif" align="absbottom">&nbsp;'.get_lang('LinksMostClicked').'
  513. </h4>
  514. <table class="data_table">';
  515. $sql = "SELECT cl.title, cl.url,count(DISTINCT sl.links_user_id), count(cl.title) as count_visits
  516. FROM $TABLETRACK_LINKS AS sl, $TABLECOURSE_LINKS AS cl
  517. WHERE sl.links_link_id = cl.id
  518. AND sl.links_cours_id = '$_cid'
  519. GROUP BY cl.title, cl.url
  520. ORDER BY count_visits DESC
  521. LIMIT 0, 3";
  522. $rs = Database::query($sql, __FILE__, __LINE__);
  523. if ($export_csv) {
  524. $temp = array(get_lang('LinksMostClicked'),'');
  525. $csv_content[] = array('','');
  526. $csv_content[] = $temp;
  527. }
  528. if (Database::num_rows($rs) > 0) {
  529. while ($row = Database::fetch_array($rs)) {
  530. echo ' <tr>
  531. <td>'.$row['title'].'</td>
  532. <td align="right">'.$row['count_visits'].' '.get_lang('Clicks').'</td>
  533. </tr>';
  534. if ($export_csv){
  535. $temp = array($row['title'],$row['count_visits'].' '.get_lang('Clicks', ''));
  536. $csv_content[] = $temp;
  537. }
  538. }
  539. } else {
  540. echo '<tr><td>'.get_lang('NoLinkVisited').'</td></tr>';
  541. if ($export_csv) {
  542. $temp = array(get_lang('NoLinkVisited'), '');
  543. $csv_content[] = $temp;
  544. }
  545. }
  546. echo '</table></div>';
  547. echo '<div class="clear"></div>';
  548. // send the csv file if asked
  549. if ($export_csv) {
  550. ob_end_clean();
  551. Export :: export_table_csv($csv_content, 'reporting_course_tracking');
  552. }
  553. } elseif($_GET['studentlist'] == 'true' or $_GET['studentlist'] == '') {
  554. // else display student list with all the informations
  555. // BEGIN : form to remind inactives susers
  556. $form = new FormValidator('reminder_form', 'get', api_get_path(REL_CODE_PATH).'announcements/announcements.php');
  557. $renderer = $form->defaultRenderer();
  558. $renderer->setElementTemplate('<span>{label} {element}</span>&nbsp;<button class="save" type="submit">'.get_lang('SendNotification').'</button>','since');
  559. $options = array (
  560. 2 => '2 '.get_lang('Days'),
  561. 3 => '3 '.get_lang('Days'),
  562. 4 => '4 '.get_lang('Days'),
  563. 5 => '5 '.get_lang('Days'),
  564. 6 => '6 '.get_lang('Days'),
  565. 7 => '7 '.get_lang('Days'),
  566. 15 => '15 '.get_lang('Days'),
  567. 30 => '30 '.get_lang('Days')
  568. );
  569. $el = $form -> addElement('select', 'since', '<img width="22" align="middle" src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" border="0" />'.get_lang('RemindInactivesLearnersSince'), $options);
  570. $el -> setSelected(7);
  571. $form -> addElement('hidden', 'action', 'add');
  572. $form -> addElement('hidden', 'remindallinactives', 'true');
  573. $form -> display();
  574. // END : form to remind inactives susers
  575. if ($export_csv) {
  576. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  577. } else {
  578. $is_western_name_order = api_is_western_name_order();
  579. }
  580. $sort_by_first_name = api_sort_by_first_name();
  581. $tracking_column = isset($_GET['tracking_column']) ? $_GET['tracking_column'] : ($is_western_name_order xor $sort_by_first_name) ? 2 : 1;
  582. $tracking_direction = isset($_GET['tracking_direction']) ? $_GET['tracking_direction'] : 'DESC';
  583. if (count($a_students) > 0) {
  584. $table = new SortableTable('tracking', 'count_student_in_course', null, ($is_western_name_order xor $sort_by_first_name) ? 2 : 1);
  585. $table -> set_header(0, get_lang('OfficialCode'), true, 'align="center"');
  586. if ($is_western_name_order) {
  587. $table -> set_header(1, get_lang('FirstName'), true, 'align="center"');
  588. $table -> set_header(2, get_lang('LastName'), true, 'align="center"');
  589. } else {
  590. $table -> set_header(1, get_lang('LastName'), true, 'align="center"');
  591. $table -> set_header(2, get_lang('FirstName'), true, 'align="center"');
  592. }
  593. $table -> set_header(3, get_lang('TrainingTime'), false);
  594. $table -> set_header(4, get_lang('CourseProgress'), false);
  595. $table -> set_header(5, get_lang('Score'), false);
  596. $table -> set_header(6, get_lang('Student_publication'), false);
  597. $table -> set_header(7, get_lang('Messages'), false);
  598. $table -> set_header(8, get_lang('FirstLogin'), false, 'align="center"');
  599. $table -> set_header(9, get_lang('LatestLogin'), false, 'align="center"');
  600. $table -> set_header(10, get_lang('Details'), false);
  601. $all_datas = array();
  602. $course_code = $_course['id'];
  603. foreach ($a_students as $student_id => $student) {
  604. $student_datas = UserManager :: get_user_info_by_id($student_id);
  605. $avg_time_spent = $avg_student_score = $avg_student_progress = $total_assignments = $total_messages = 0;
  606. $nb_courses_student = 0;
  607. $avg_time_spent = Tracking :: get_time_spent_on_the_course($student_id, $course_code);
  608. $avg_student_score = Tracking :: get_average_test_scorm_and_lp($student_id, $course_code);
  609. $avg_student_progress = Tracking :: get_avg_student_progress($student_id, $course_code);
  610. $total_assignments = Tracking :: count_student_assignments($student_id, $course_code);
  611. $total_messages = Tracking :: count_student_messages($student_id, $course_code);
  612. $row = array();
  613. $row[] = $student_datas['official_code'];
  614. if ($is_western_name_order) {
  615. $row[] = $student_datas['firstname'];
  616. $row[] = $student_datas['lastname'];
  617. } else {
  618. $row[] = $student_datas['lastname'];
  619. $row[] = $student_datas['firstname'];
  620. }
  621. $row[] = api_time_to_hms($avg_time_spent);
  622. if (is_null($avg_student_score)) {$avg_student_score=0;}
  623. if (is_null($avg_student_progress)) {$avg_student_progress=0;}
  624. $row[] = $avg_student_progress.'%';
  625. $row[] = $avg_student_score.'%';
  626. $row[] = $total_assignments;
  627. $row[] = $total_messages;
  628. $row[] = Tracking :: get_first_connection_date_on_the_course($student_id, $course_code);
  629. $row[] = Tracking :: get_last_connection_date_on_the_course($student_id, $course_code);
  630. if ($export_csv) {
  631. $row[8] = strip_tags($row[8]);
  632. $csv_content[] = $row;
  633. }
  634. $from = '';
  635. if ($from_myspace) {
  636. $from ='&from=myspace';
  637. }
  638. $row[] = '<center><a href="../mySpace/myStudents.php?student='.$student_id.'&details=true&course='.$course_code.'&origin=tracking_course'.$from.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></center>';
  639. $all_datas[] = $row;
  640. }
  641. usort($all_datas, 'sort_users');
  642. $page = $table->get_pager()->getCurrentPageID();
  643. $all_datas = array_slice($all_datas, ($page-1)*$table -> per_page, $table -> per_page);
  644. if ($export_csv) {
  645. usort($csv_content, 'sort_users');
  646. }
  647. foreach ($all_datas as $row) {
  648. $table -> addRow($row,'align="right"');
  649. }
  650. $table -> setColAttributes(0, array('align' => 'left'));
  651. $table -> setColAttributes(1, array('align' => 'left'));
  652. $table -> setColAttributes(2, array('align' => 'left'));
  653. $table -> setColAttributes(7, array('align' => 'right'));
  654. $table -> setColAttributes(8, array('align' => 'center'));
  655. $table -> setColAttributes(9, array('align' => 'center'));
  656. $table -> display();
  657. } else {
  658. echo get_lang('NoUsersInCourseTracking');
  659. }
  660. // send the csv file if asked
  661. if ($export_csv) {
  662. if ($is_western_name_order) {
  663. $csv_headers = array (
  664. get_lang('OfficialCode', ''),
  665. get_lang('FirstName', ''),
  666. get_lang('LastName', ''),
  667. get_lang('TrainingTime', ''),
  668. get_lang('CourseProgress', ''),
  669. get_lang('Score', ''),
  670. get_lang('Student_publication', ''),
  671. get_lang('Messages', ''),
  672. get_lang('FirstLogin', ''),
  673. get_lang('LatestLogin', '')
  674. );
  675. } else {
  676. $csv_headers = array (
  677. get_lang('OfficialCode', ''),
  678. get_lang('LastName', ''),
  679. get_lang('FirstName', ''),
  680. get_lang('TrainingTime', ''),
  681. get_lang('CourseProgress', ''),
  682. get_lang('Score', ''),
  683. get_lang('Student_publication', ''),
  684. get_lang('Messages', ''),
  685. get_lang('FirstLogin', ''),
  686. get_lang('LatestLogin', '')
  687. );
  688. }
  689. ob_end_clean();
  690. array_unshift($csv_content, $csv_headers); // adding headers before the content
  691. Export :: export_table_csv($csv_content, 'reporting_student_list');
  692. }
  693. } elseif($_GET['studentlist'] == 'resources') {
  694. // Create a search-box
  695. $form = new FormValidator('search_simple','get',api_get_path(WEB_CODE_PATH).'tracking/courseLog.php?'.api_get_cidreq().'&studentlist=resources','','width=200px',false);
  696. $renderer =& $form->defaultRenderer();
  697. $renderer->setElementTemplate('<span>{element}</span>');
  698. $form->addElement('hidden','studentlist','resources');
  699. $form->addElement('text','keyword',get_lang('keyword'));
  700. $form->addElement('style_submit_button', 'submit', get_lang('Search'),'class="search"');
  701. echo '<div class="actions">';
  702. $form->display();
  703. echo '</div>';
  704. $table = new SortableTable('resources', 'count_item_resources', 'get_item_resources_data', 5, 20, 'DESC');
  705. $parameters = array();
  706. if (isset($_GET['keyword'])) {
  707. $parameters['keyword'] = Security::remove_XSS($_GET['keyword']);
  708. }
  709. $parameters['studentlist'] = 'resources';
  710. $table->set_additional_parameters($parameters);
  711. $table->set_header(0, get_lang('Tool'));
  712. $table->set_header(1, get_lang('EventType'));
  713. $table->set_header(2, get_lang('Session'), false);
  714. $table->set_header(3, get_lang('UserName'));
  715. $table->set_header(4, get_lang('Document'), false);
  716. $table->set_header(5, get_lang('Date'));
  717. $table->display();
  718. }
  719. ?>
  720. </table>
  721. <?php
  722. Display::display_footer();