course_log_tools.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * @package chamilo.tracking
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $current_course_tool = TOOL_TRACKING;
  9. $course_info = api_get_course_info();
  10. $groupId = isset($_REQUEST['gidReq']) ? intval($_REQUEST['gidReq']) : 0;
  11. $from_myspace = false;
  12. $from = isset($_GET['from']) ? $_GET['from'] : null;
  13. $this_section = SECTION_COURSES;
  14. if ($from == 'myspace') {
  15. $from_myspace = true;
  16. $this_section = 'session_my_space';
  17. }
  18. // Access restrictions.
  19. $is_allowedToTrack = Tracking::isAllowToTrack($session_id);
  20. if (!$is_allowedToTrack) {
  21. api_not_allowed(true);
  22. exit;
  23. }
  24. $showChatReporting = true;
  25. $showTrackingReporting = true;
  26. $documentReporting = true;
  27. $linkReporting = true;
  28. $exerciseReporting = true;
  29. $lpReporting = true;
  30. if (!empty($groupId)) {
  31. $showChatReporting = false;
  32. $showTrackingReporting = false;
  33. $documentReporting = false;
  34. $linkReporting = false;
  35. $exerciseReporting = false;
  36. $lpReporting = false;
  37. }
  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::write('id_session', $session_id);
  45. }
  46. ob_start();
  47. }
  48. $csv_content = [];
  49. // Breadcrumbs.
  50. if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  51. $interbreadcrumb[] = ['url' => '../admin/index.php', 'name' => get_lang('PlatformAdmin')];
  52. $interbreadcrumb[] = ['url' => '../session/session_list.php', 'name' => get_lang('SessionList')];
  53. $interbreadcrumb[] = [
  54. 'url' => '../session/resume_session.php?id_session='.api_get_session_id(),
  55. 'name' => get_lang('SessionOverview'),
  56. ];
  57. }
  58. $view = isset($_REQUEST['view']) ? $_REQUEST['view'] : '';
  59. $nameTools = get_lang('Tracking');
  60. // Display the header.
  61. Display::display_header($nameTools, 'Tracking');
  62. // getting all the students of the course
  63. if (empty($session_id)) {
  64. // Registered students in a course outside session.
  65. $a_students = CourseManager:: get_student_list_from_course_code(
  66. api_get_course_id(),
  67. false,
  68. 0,
  69. null,
  70. null,
  71. true,
  72. api_get_group_id()
  73. );
  74. } else {
  75. // Registered students in session.
  76. $a_students = CourseManager:: get_student_list_from_course_code(
  77. api_get_course_id(),
  78. true,
  79. api_get_session_id()
  80. );
  81. }
  82. $nbStudents = count($a_students);
  83. $student_ids = array_keys($a_students);
  84. $studentCount = count($student_ids);
  85. /* MAIN CODE */
  86. echo '<div class="actions">';
  87. echo TrackingCourseLog::actionsLeft('courses', api_get_session_id());
  88. echo '<span style="float:right; padding-top:0px;">';
  89. echo '<a href="javascript: void(0);" onclick="javascript: window.print();">'.
  90. Display::return_icon('printer.png', get_lang('Print'), '', ICON_SIZE_MEDIUM).'</a>';
  91. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&id_session='.api_get_session_id().'&export=csv">
  92. '.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
  93. echo '</span>';
  94. echo '</div>';
  95. $course_code = api_get_course_id();
  96. $course_id = api_get_course_int_id();
  97. if ($lpReporting) {
  98. $list = new LearnpathList(null, $course_code, $session_id);
  99. $flat_list = $list->get_flat_list();
  100. if (count($flat_list) > 0) {
  101. // learning path tracking
  102. echo '<div class="report_section">';
  103. echo Display::page_subheader(
  104. Display::return_icon(
  105. 'scorms.gif',
  106. get_lang('AverageProgressInLearnpath')
  107. ).' '.get_lang('AverageProgressInLearnpath')
  108. );
  109. echo '<table class="data_table">';
  110. if ($export_csv) {
  111. $temp = [get_lang('AverageProgressInLearnpath', ''), ''];
  112. $csv_content[] = ['', ''];
  113. $csv_content[] = $temp;
  114. }
  115. foreach ($flat_list as $lp_id => $lp) {
  116. $lp_avg_progress = 0;
  117. foreach ($a_students as $student_id => $student) {
  118. // get the progress in learning pathes
  119. $lp_avg_progress += Tracking::get_avg_student_progress(
  120. $student_id,
  121. $course_code,
  122. [$lp_id],
  123. $session_id
  124. );
  125. }
  126. $lp_avg_progress = null;
  127. if ($studentCount > 0) {
  128. $lp_avg_progress = $lp_avg_progress / $studentCount;
  129. }
  130. // Separated presentation logic.
  131. if (is_null($lp_avg_progress)) {
  132. $lp_avg_progress = '0%';
  133. } else {
  134. $lp_avg_progress = round($lp_avg_progress, 1).'%';
  135. }
  136. echo '<tr><td>'.$lp['lp_name'].'</td><td align="right">'.$lp_avg_progress.'</td></tr>';
  137. if ($export_csv) {
  138. $temp = [$lp['lp_name'], $lp_avg_progress];
  139. $csv_content[] = $temp;
  140. }
  141. }
  142. echo '</table></div>';
  143. } else {
  144. if ($export_csv) {
  145. $temp = [get_lang('NoLearningPath', ''), ''];
  146. $csv_content[] = $temp;
  147. }
  148. }
  149. }
  150. if ($exerciseReporting) {
  151. // Exercises tracking.
  152. echo '<div class="report_section">';
  153. echo Display::page_subheader(
  154. Display::return_icon(
  155. 'quiz.png',
  156. get_lang('AverageResultsToTheExercices')
  157. ).' '.get_lang('AverageResultsToTheExercices')
  158. );
  159. echo '<table class="data_table">';
  160. $course_id = api_get_course_int_id();
  161. $sql = "SELECT id, title FROM $TABLEQUIZ
  162. WHERE c_id = $course_id AND active <> -1 AND session_id = $session_id";
  163. $rs = Database::query($sql);
  164. if ($export_csv) {
  165. $temp = [get_lang('AverageProgressInLearnpath'), ''];
  166. $csv_content[] = ['', ''];
  167. $csv_content[] = $temp;
  168. }
  169. $course_path_params = '&cidReq='.$course_code.'&id_session='.$session_id;
  170. if (Database::num_rows($rs) > 0) {
  171. while ($quiz = Database::fetch_array($rs)) {
  172. $quiz_avg_score = 0;
  173. if ($studentCount > 0) {
  174. foreach ($student_ids as $student_id) {
  175. $avg_student_score = Tracking::get_avg_student_exercise_score(
  176. $student_id,
  177. $course_code,
  178. $quiz['id'],
  179. $session_id
  180. );
  181. $quiz_avg_score += $avg_student_score;
  182. }
  183. }
  184. $studentCount = ($studentCount == 0 || is_null($studentCount) || $studentCount == '') ? 1 : $studentCount;
  185. $quiz_avg_score = round(($quiz_avg_score / $studentCount), 2).'%';
  186. $url = api_get_path(WEB_CODE_PATH).'exercise/overview.php?exerciseId='.$quiz['id'].$course_path_params;
  187. echo '<tr><td>';
  188. echo Display::url(
  189. $quiz['title'],
  190. $url
  191. );
  192. echo '</td><td align="right">'.$quiz_avg_score.'</td></tr>';
  193. if ($export_csv) {
  194. $temp = [$quiz['title'], $quiz_avg_score];
  195. $csv_content[] = $temp;
  196. }
  197. }
  198. } else {
  199. echo '<tr><td>'.get_lang('NoExercises').'</td></tr>';
  200. if ($export_csv) {
  201. $temp = [get_lang('NoExercises', ''), ''];
  202. $csv_content[] = $temp;
  203. }
  204. }
  205. echo '</table></div>';
  206. echo '<div class="clear"></div>';
  207. }
  208. $filterByUsers = [];
  209. if (!empty($groupId)) {
  210. $filterByUsers = $student_ids;
  211. }
  212. $count_number_of_forums_by_course = Tracking:: count_number_of_forums_by_course(
  213. $course_code,
  214. $session_id,
  215. $groupId
  216. );
  217. $count_number_of_threads_by_course = Tracking:: count_number_of_threads_by_course(
  218. $course_code,
  219. $session_id,
  220. $groupId
  221. );
  222. $count_number_of_posts_by_course = Tracking:: count_number_of_posts_by_course(
  223. $course_code,
  224. $session_id,
  225. $groupId
  226. );
  227. if ($export_csv) {
  228. $csv_content[] = [get_lang('Forum')];
  229. $csv_content[] = [get_lang('ForumForumsNumber'), $count_number_of_forums_by_course];
  230. $csv_content[] = [get_lang('ForumThreadsNumber'), $count_number_of_threads_by_course];
  231. $csv_content[] = [get_lang('ForumPostsNumber'), $count_number_of_posts_by_course];
  232. }
  233. // Forums tracking.
  234. echo '<div class="report_section">';
  235. echo Display::page_subheader(
  236. Display::return_icon('forum.gif', get_lang('Forum')).' '.
  237. get_lang('Forum').'&nbsp;-&nbsp;<a href="../forum/index.php?'.api_get_cidreq().'">'.
  238. get_lang('SeeDetail').'</a>'
  239. );
  240. echo '<table class="data_table">';
  241. echo '<tr><td>'.get_lang('ForumForumsNumber').'</td><td align="right">'.$count_number_of_forums_by_course.'</td></tr>';
  242. echo '<tr><td>'.get_lang('ForumThreadsNumber').'</td><td align="right">'.$count_number_of_threads_by_course.'</td></tr>';
  243. echo '<tr><td>'.get_lang('ForumPostsNumber').'</td><td align="right">'.$count_number_of_posts_by_course.'</td></tr>';
  244. echo '</table></div>';
  245. echo '<div class="clear"></div>';
  246. // Chat tracking.
  247. if ($showChatReporting) {
  248. echo '<div class="report_section">';
  249. echo Display::page_subheader(
  250. Display::return_icon('chat.gif', get_lang('Chat')).' '.get_lang('Chat')
  251. );
  252. echo '<table class="data_table">';
  253. $chat_connections_during_last_x_days_by_course = Tracking::chat_connections_during_last_x_days_by_course(
  254. $course_code,
  255. 7,
  256. $session_id
  257. );
  258. if ($export_csv) {
  259. $csv_content[] = [get_lang('Chat', ''), ''];
  260. $csv_content[] = [
  261. sprintf(
  262. get_lang('ChatConnectionsDuringLastXDays', ''),
  263. '7'
  264. ),
  265. $chat_connections_during_last_x_days_by_course,
  266. ];
  267. }
  268. echo '<tr><td>';
  269. echo sprintf(
  270. get_lang('ChatConnectionsDuringLastXDays'),
  271. '7'
  272. );
  273. echo '</td><td align="right">'.$chat_connections_during_last_x_days_by_course.'</td></tr>';
  274. echo '</table></div>';
  275. echo '<div class="clear"></div>';
  276. }
  277. // Tools tracking.
  278. if ($showTrackingReporting) {
  279. echo '<div class="report_section">';
  280. echo Display::page_subheader(
  281. Display::return_icon(
  282. 'acces_tool.gif',
  283. get_lang('ToolsMostUsed')
  284. ).' '.get_lang('ToolsMostUsed')
  285. );
  286. echo '<table class="data_table">';
  287. $tools_most_used = Tracking::get_tools_most_used_by_course(
  288. $course_id,
  289. $session_id
  290. );
  291. if ($export_csv) {
  292. $temp = [get_lang('ToolsMostUsed'), ''];
  293. $csv_content[] = $temp;
  294. }
  295. if (!empty($tools_most_used)) {
  296. foreach ($tools_most_used as $row) {
  297. echo '<tr>
  298. <td>'.get_lang(ucfirst($row['access_tool'])).'</td>
  299. <td align="right">'.$row['count_access_tool'].' '.get_lang('Clicks').'</td>
  300. </tr>';
  301. if ($export_csv) {
  302. $temp = [
  303. get_lang(ucfirst($row['access_tool']), ''),
  304. $row['count_access_tool'].' '.get_lang('Clicks', ''),
  305. ];
  306. $csv_content[] = $temp;
  307. }
  308. }
  309. }
  310. echo '</table></div>';
  311. echo '<div class="clear"></div>';
  312. }
  313. if ($documentReporting) {
  314. // Documents tracking.
  315. if (!isset($_GET['num']) || empty($_GET['num'])) {
  316. $num = 3;
  317. $link = '&nbsp;-&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&num=1#documents_tracking">'.get_lang('SeeDetail').'</a>';
  318. } else {
  319. $num = 1000;
  320. $link = '&nbsp;-&nbsp;<a href="'.api_get_self().'?'.api_get_cidreq().'&num=0#documents_tracking">'.get_lang('ViewMinus').'</a>';
  321. }
  322. echo '<a name="documents_tracking" id="a"></a><div class="report_section">';
  323. echo Display::page_subheader(
  324. Display::return_icon(
  325. 'documents.gif',
  326. get_lang('DocumentsMostDownloaded')
  327. ).'&nbsp;'.get_lang('DocumentsMostDownloaded').$link
  328. );
  329. echo '<table class="data_table">';
  330. $documents_most_downloaded = Tracking::get_documents_most_downloaded_by_course(
  331. $course_code,
  332. $session_id,
  333. $num
  334. );
  335. if ($export_csv) {
  336. $temp = [get_lang('DocumentsMostDownloaded', ''), ''];
  337. $csv_content[] = ['', ''];
  338. $csv_content[] = $temp;
  339. }
  340. if (!empty($documents_most_downloaded)) {
  341. foreach ($documents_most_downloaded as $row) {
  342. echo '<tr>
  343. <td>';
  344. echo Display::url(
  345. $row['down_doc_path'],
  346. api_get_path(
  347. WEB_CODE_PATH
  348. ).'document/show_content.php?file='.$row['down_doc_path'].$course_path_params
  349. );
  350. echo '</td>
  351. <td align="right">'.$row['count_down'].' '.get_lang('Clicks').'</td>
  352. </tr>';
  353. if ($export_csv) {
  354. $temp = [
  355. $row['down_doc_path'],
  356. $row['count_down'].' '.get_lang('Clicks', ''),
  357. ];
  358. $csv_content[] = $temp;
  359. }
  360. }
  361. } else {
  362. echo '<tr><td>'.get_lang('NoDocumentDownloaded').'</td></tr>';
  363. if ($export_csv) {
  364. $temp = [get_lang('NoDocumentDownloaded', ''), ''];
  365. $csv_content[] = $temp;
  366. }
  367. }
  368. echo '</table></div>';
  369. echo '<div class="clear"></div>';
  370. }
  371. if ($linkReporting) {
  372. // links tracking
  373. echo '<div class="report_section">';
  374. echo Display::page_subheader(
  375. Display::return_icon(
  376. 'link.gif',
  377. get_lang('LinksMostClicked')
  378. ).'&nbsp;'.get_lang('LinksMostClicked')
  379. );
  380. echo '<table class="data_table">';
  381. $links_most_visited = Tracking::get_links_most_visited_by_course(
  382. $course_code,
  383. $session_id
  384. );
  385. if ($export_csv) {
  386. $temp = [get_lang('LinksMostClicked'), ''];
  387. $csv_content[] = ['', ''];
  388. $csv_content[] = $temp;
  389. }
  390. if (!empty($links_most_visited)) {
  391. foreach ($links_most_visited as $row) {
  392. echo '<tr><td>';
  393. echo Display::url(
  394. $row['title'].' ('.$row['url'].')',
  395. $row['url']
  396. );
  397. echo '</td><td align="right">'.$row['count_visits'].' '.get_lang('Clicks').'</td></tr>';
  398. if ($export_csv) {
  399. $temp = [
  400. $row['title'],
  401. $row['count_visits'].' '.get_lang('Clicks', ''),
  402. ];
  403. $csv_content[] = $temp;
  404. }
  405. }
  406. } else {
  407. echo '<tr><td>'.get_lang('NoLinkVisited').'</td></tr>';
  408. if ($export_csv) {
  409. $temp = [get_lang('NoLinkVisited'), ''];
  410. $csv_content[] = $temp;
  411. }
  412. }
  413. echo '</table></div>';
  414. echo '<div class="clear"></div>';
  415. }
  416. // send the csv file if asked
  417. if ($export_csv) {
  418. ob_end_clean();
  419. Export:: arrayToCsv($csv_content, 'reporting_course_tools');
  420. exit;
  421. }
  422. Display::display_footer();