course_log_tools.php 15 KB

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