course_log_tools.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.tracking
  5. */
  6. /* INIT SECTION */
  7. // Language files that need to be included.
  8. $language_file = array('admin', 'tracking', 'scorm', 'exercice');
  9. // Including the global initialization file
  10. require_once '../inc/global.inc.php';
  11. $current_course_tool = TOOL_TRACKING;
  12. $course_info = api_get_course_info(api_get_course_id());
  13. $from_myspace = false;
  14. $from = isset($_GET['from']) ? $_GET['from'] : null;
  15. if ($from == 'myspace') {
  16. $from_myspace = true;
  17. $this_section = "session_my_space";
  18. } else {
  19. $this_section = SECTION_COURSES;
  20. }
  21. // Access restrictions.
  22. $is_allowedToTrack = api_is_platform_admin() || api_is_allowed_to_create_course() || api_is_session_admin() || api_is_drh() || api_is_course_tutor();
  23. if (!$is_allowedToTrack) {
  24. api_not_allowed(true);
  25. exit;
  26. }
  27. // Including additional libraries.
  28. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  29. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
  30. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathList.class.php';
  31. require_once api_get_path(SYS_CODE_PATH).'newscorm/scorm.class.php';
  32. require_once api_get_path(SYS_CODE_PATH).'newscorm/scormItem.class.php';
  33. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  34. require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
  35. require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
  36. require_once api_get_path(SYS_CODE_PATH).'survey/survey.lib.php';
  37. require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.lib.php';
  38. $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
  39. // Starting the output buffering when we are exporting the information.
  40. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  41. $session_id = intval($_REQUEST['id_session']);
  42. if ($export_csv) {
  43. if (!empty($session_id)) {
  44. $_SESSION['id_session'] = $session_id;
  45. }
  46. ob_start();
  47. }
  48. $group_id = api_get_group_id();
  49. $csv_content = array();
  50. // Breadcrumbs.
  51. if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  52. $interbreadcrumb[] = array('url' => '../session/index.php','name' => get_lang('PlatformAdmin'));
  53. $interbreadcrumb[] = array('url' => '../session/session_list.php','name' => get_lang('SessionList'));
  54. $interbreadcrumb[] = array('url' => '../session/resume_session.php?id_session='.api_get_session_id(), 'name' => get_lang('SessionOverview'));
  55. }
  56. $view = (isset($_REQUEST['view']) ? $_REQUEST['view'] : '');
  57. $nameTools = get_lang('Tracking');
  58. // Display the header.
  59. Display::display_header($nameTools, 'Tracking');
  60. // getting all the students of the course
  61. if (empty($session_id)) {
  62. // Registered students in a course outside session.
  63. $a_students = CourseManager :: get_student_list_from_course_code(api_get_course_id(), false, 0, api_get_group_id());
  64. } else {
  65. // Registered students in session.
  66. $a_students = CourseManager :: get_student_list_from_course_code(api_get_course_id(), true, api_get_session_id());
  67. }
  68. $nbStudents = count($a_students);
  69. /* MAIN CODE */
  70. echo '<div class="actions">';
  71. echo Display::url(Display::return_icon('user.png', get_lang('StudentsTracking'), array(), 32), 'courseLog.php?'.api_get_cidreq());
  72. if (empty($group_id)) {
  73. echo Display::url(Display::return_icon('group.png', get_lang('GroupReporting'), array(), 32), 'course_log_groups.php?'.api_get_cidreq());
  74. echo Display::url(Display::return_icon('course_na.png', get_lang('CourseTracking'), array(), 32), '#');
  75. } else {
  76. echo Display::url(Display::return_icon('group_na.png', get_lang('GroupReporting'), array(), 32), '#');
  77. echo Display::url(Display::return_icon('course.png', get_lang('CourseTracking'), array(), 32), 'course_log_tools.php?'.api_get_cidreq(true, false).'&gidReq=0');
  78. }
  79. echo Display::url(Display::return_icon('tools.png', get_lang('ResourcesTracking'), array(), 32), 'course_log_resources.php?'.api_get_cidreq());
  80. echo '<span style="float:right; padding-top:0px;">';
  81. echo '<a href="javascript: void(0);" onclick="javascript: window.print();">'.Display::return_icon('printer.png', get_lang('Print'),'',ICON_SIZE_MEDIUM).'</a>';
  82. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&id_session='.api_get_session_id().'&export=csv">
  83. '.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a>';
  84. echo '</span>';
  85. echo '</div>';
  86. $course_code = api_get_course_id();
  87. $list = new LearnpathList(null, $course_code, $session_id);
  88. $flat_list = $list->get_flat_list();
  89. if (count($flat_list) > 0) {
  90. $group_name = null;
  91. if ($group_id) {
  92. $group_info = GroupManager::get_group_properties($group_id);
  93. $group_name = " - ".get_lang('Group').": ".$group_info['name'];
  94. }
  95. echo Display::page_subheader2(get_lang('Course').": ".$course_info['title'].$group_name);
  96. // learning path tracking
  97. echo '<div class="report_section">
  98. '.Display::page_subheader2(Display::return_icon('scorms.gif',get_lang('AverageProgressInLearnpath')).get_lang('AverageProgressInLearnpath')).'
  99. <table class="data_table">';
  100. if ($export_csv) {
  101. $temp = array(get_lang('AverageProgressInLearnpath', ''), '');
  102. $csv_content[] = array('', '');
  103. $csv_content[] = $temp;
  104. }
  105. foreach ($flat_list as $lp_id => $lp) {
  106. $lp_avg_progress = 0;
  107. foreach ($a_students as $student_id => $student) {
  108. // get the progress in learning pathes
  109. $lp_avg_progress += Tracking::get_avg_student_progress($student_id, $course_code, array($lp_id), $session_id);
  110. }
  111. if ($nbStudents > 0) {
  112. $lp_avg_progress = $lp_avg_progress / $nbStudents;
  113. } else {
  114. $lp_avg_progress = null;
  115. }
  116. // Separated presentation logic.
  117. if (is_null($lp_avg_progress)) {
  118. $lp_avg_progress = '0%';
  119. } else {
  120. $lp_avg_progress = round($lp_avg_progress, 1).'%';
  121. }
  122. echo '<tr><td>'.$lp['lp_name'].'</td><td align="right">'.$lp_avg_progress.'</td></tr>';
  123. if ($export_csv) {
  124. $temp = array($lp['lp_name'], $lp_avg_progress);
  125. $csv_content[] = $temp;
  126. }
  127. }
  128. echo '</table></div>';
  129. } else {
  130. if ($export_csv) {
  131. $temp = array(get_lang('NoLearningPath', ''), '');
  132. $csv_content[] = $temp;
  133. }
  134. }
  135. // Exercices tracking.
  136. echo '<div class="report_section">
  137. '.Display::page_subheader2(Display::return_icon('quiz.gif',get_lang('AverageResultsToTheExercices')).get_lang('AverageResultsToTheExercices')).'
  138. <table class="data_table">';
  139. $course_id = api_get_course_int_id();
  140. //@todo user $exercise = new Exercise($course_id);
  141. $sql = "SELECT id, title FROM $TABLEQUIZ
  142. WHERE c_id = $course_id AND active <> -1 AND session_id = $session_id";
  143. $rs = Database::query($sql);
  144. if ($export_csv) {
  145. $temp = array(get_lang('AverageProgressInLearnpath'), '');
  146. $csv_content[] = array('', '');
  147. $csv_content[] = $temp;
  148. }
  149. $course_path_params = '&cidReq='.$course_code.'&id_session='.$session_id;
  150. if (Database::num_rows($rs) > 0) {
  151. $student_ids = array_keys($a_students);
  152. $count_students = count($student_ids);
  153. while ($quiz = Database::fetch_array($rs)) {
  154. $quiz_avg_score = 0;
  155. if ($count_students > 0) {
  156. foreach ($student_ids as $student_id) {
  157. $avg_student_score = Tracking::get_avg_student_exercise_score($student_id, $course_code, $quiz['id'], $session_id);
  158. $quiz_avg_score += $avg_student_score;
  159. }
  160. }
  161. $count_students = ($count_students == 0 || is_null($count_students) || $count_students == '') ? 1 : $count_students;
  162. $quiz_avg_score = round(($quiz_avg_score / $count_students), 2).'%';
  163. $url = api_get_path(WEB_CODE_PATH).'exercice/overview.php?exerciseId='.$quiz['id'].$course_path_params;
  164. echo '<tr><td>'.Display::url($quiz['title'], $url).'</td><td align="right">'.$quiz_avg_score.'</td></tr>';
  165. if ($export_csv) {
  166. $temp = array($quiz['title'], $quiz_avg_score);
  167. $csv_content[] = $temp;
  168. }
  169. }
  170. } else {
  171. echo '<tr><td>'.get_lang('NoExercises').'</td></tr>';
  172. if ($export_csv) {
  173. $temp = array(get_lang('NoExercises', ''), '');
  174. $csv_content[] = $temp;
  175. }
  176. }
  177. echo '</table></div>';
  178. echo '<div class="clear"></div>';
  179. // Forums tracking.
  180. echo '<div class="report_section">
  181. '.Display::page_subheader2(Display::return_icon('forum.gif', get_lang('Forum')).get_lang('Forum').'&nbsp;-&nbsp;<a href="../forum/index.php?cidReq='.$_course['id'].'">'.get_lang('SeeDetail').'</a>').
  182. '<table class="data_table">';
  183. $filter_by_users = array();
  184. if (!empty($group_id)) {
  185. $filter_by_users = $student_ids;
  186. }
  187. $count_number_of_posts_by_course = Tracking :: count_number_of_posts_by_course($course_code, $session_id, $filter_by_users);
  188. $count_number_of_forums_by_course = 0;
  189. if (empty($group_id)) {
  190. $count_number_of_forums_by_course = Tracking :: count_number_of_forums_by_course($course_code, $session_id, $filter_by_users);
  191. }
  192. $count_number_of_threads_by_course = Tracking :: count_number_of_threads_by_course($course_code, $session_id, $filter_by_users);
  193. if ($export_csv) {
  194. $csv_content[] = array(get_lang('Forum'), '');
  195. if (empty($group_id)) {
  196. $csv_content[] = array(get_lang('ForumForumsNumber', ''), $count_number_of_forums_by_course);
  197. }
  198. $csv_content[] = array(get_lang('ForumThreadsNumber', ''), $count_number_of_threads_by_course);
  199. $csv_content[] = array(get_lang('ForumPostsNumber', ''), $count_number_of_posts_by_course);
  200. }
  201. if (empty($group_id)) {
  202. echo '<tr><td>'.get_lang('ForumForumsNumber').'</td><td align="right">'.$count_number_of_forums_by_course.'</td></tr>';
  203. }
  204. echo '<tr><td>'.get_lang('ForumThreadsNumber').'</td><td align="right">'.$count_number_of_threads_by_course.'</td></tr>';
  205. echo '<tr><td>'.get_lang('ForumPostsNumber').'</td><td align="right">'.$count_number_of_posts_by_course.'</td></tr>';
  206. echo '</table></div>';
  207. echo '<div class="clear"></div>';
  208. // Chat tracking.
  209. echo '<div class="report_section">
  210. '.Display::page_subheader2(Display::return_icon('chat.gif',get_lang('Chat')).get_lang('Chat')).'
  211. <table class="data_table">';
  212. $chat_connections_during_last_x_days_by_course = Tracking::chat_connections_during_last_x_days_by_course($course_code, 7, $session_id, $filter_by_users);
  213. if ($export_csv) {
  214. $csv_content[] = array(get_lang('Chat', ''), '');
  215. $csv_content[] = array(sprintf(get_lang('ChatConnectionsDuringLastXDays', ''), '7'), $chat_connections_during_last_x_days_by_course);
  216. }
  217. echo '<tr><td>'.sprintf(get_lang('ChatConnectionsDuringLastXDays'), '7').'</td><td align="right">'.$chat_connections_during_last_x_days_by_course.'</td></tr>';
  218. echo '</table></div>';
  219. echo '<div class="clear"></div>';
  220. // Tools tracking.
  221. echo '<div class="report_section">
  222. '.Display::page_subheader2(Display::return_icon('acces_tool.gif', get_lang('ToolsMostUsed')).get_lang('ToolsMostUsed')).'
  223. <table class="data_table">';
  224. $tools_most_used = Tracking::get_tools_most_used_by_course($course_code, $session_id, $filter_by_users);
  225. if ($export_csv) {
  226. $temp = array(get_lang('ToolsMostUsed'), '');
  227. $csv_content[] = $temp;
  228. }
  229. if (!empty($tools_most_used)) {
  230. foreach ($tools_most_used as $row) {
  231. echo ' <tr>
  232. <td>'.get_lang(ucfirst($row['access_tool'])).'</td>
  233. <td align="right">'.$row['count_access_tool'].' '.get_lang('Clicks').'</td>
  234. </tr>';
  235. if ($export_csv) {
  236. $temp = array(get_lang(ucfirst($row['access_tool']), ''), $row['count_access_tool'].' '.get_lang('Clicks', ''));
  237. $csv_content[] = $temp;
  238. }
  239. }
  240. }
  241. echo '</table></div>';
  242. echo '<div class="clear"></div>';
  243. // Documents tracking.
  244. if (!isset($_GET['num']) || empty($_GET['num'])) {
  245. $num = 3;
  246. $link = '&nbsp;-&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&num=1#documents_tracking">'.get_lang('SeeDetail').'</a>';
  247. } else {
  248. $num = 1000;
  249. $link = '&nbsp;-&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&num=0#documents_tracking">'.get_lang('ViewMinus').'</a>';
  250. }
  251. echo '<a name="documents_tracking" id="a"></a><div class="report_section">
  252. '.Display::page_subheader2(Display::return_icon('documents.gif',get_lang('DocumentsMostDownloaded')).'&nbsp;'.get_lang('DocumentsMostDownloaded').$link).'
  253. <table class="data_table">';
  254. //No group id
  255. $documents_most_downloaded = Tracking::get_documents_most_downloaded_by_course($course_code, $session_id, $num, $filter_by_users);
  256. if ($export_csv) {
  257. $temp = array(get_lang('DocumentsMostDownloaded', ''), '');
  258. $csv_content[] = array('', '');
  259. $csv_content[] = $temp;
  260. }
  261. if (!empty($documents_most_downloaded)) {
  262. foreach ($documents_most_downloaded as $row) {
  263. echo '<tr>
  264. <td>'.Display::url($row['down_doc_path'], api_get_path(WEB_CODE_PATH).'document/show_content.php?file='.$row['down_doc_path'].$course_path_params).'</td>
  265. <td align="right">'.$row['count_down'].' '.get_lang('Clicks').'</td>
  266. </tr>';
  267. if ($export_csv) {
  268. $temp = array($row['down_doc_path'], $row['count_down'].' '.get_lang('Clicks', ''));
  269. $csv_content[] = $temp;
  270. }
  271. }
  272. } else {
  273. echo '<tr><td>'.get_lang('NoDocumentDownloaded').'</td></tr>';
  274. if ($export_csv) {
  275. $temp = array(get_lang('NoDocumentDownloaded', ''), '');
  276. $csv_content[] = $temp;
  277. }
  278. }
  279. echo '</table></div>';
  280. echo '<div class="clear"></div>';
  281. // links tracking
  282. echo '<div class="report_section">
  283. '.Display::page_subheader2(Display::return_icon('link.gif',get_lang('LinksMostClicked')).'&nbsp;'.get_lang('LinksMostClicked')).'
  284. <table class="data_table">';
  285. $links_most_visited = Tracking::get_links_most_visited_by_course($course_code, $session_id, $filter_by_users);
  286. if ($export_csv) {
  287. $temp = array(get_lang('LinksMostClicked'), '');
  288. $csv_content[] = array('', '');
  289. $csv_content[] = $temp;
  290. }
  291. if (!empty($links_most_visited)) {
  292. foreach ($links_most_visited as $row) {
  293. echo ' <tr>
  294. <td>'.Display::url($row['title'].' ('.$row['url'].')', $row['url']).'</td>
  295. <td align="right">'.$row['count_visits'].' '.get_lang('Clicks').'</td>
  296. </tr>';
  297. if ($export_csv){
  298. $temp = array($row['title'], $row['count_visits'].' '.get_lang('Clicks', ''));
  299. $csv_content[] = $temp;
  300. }
  301. }
  302. } else {
  303. echo '<tr><td>'.get_lang('NoLinkVisited').'</td></tr>';
  304. if ($export_csv) {
  305. $temp = array(get_lang('NoLinkVisited'), '');
  306. $csv_content[] = $temp;
  307. }
  308. }
  309. echo '</table></div>';
  310. echo '<div class="clear"></div>';
  311. // send the csv file if asked
  312. if ($export_csv) {
  313. ob_end_clean();
  314. Export :: export_table_csv($csv_content, 'reporting_course_tools');
  315. exit;
  316. }
  317. Display::display_footer();