course_log_tools.php 16 KB

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