course_log_tools.php 16 KB

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