course_log_tools.php 16 KB

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