courseLog.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.tracking
  5. */
  6. /* INIT SECTION */
  7. $pathopen = isset($_REQUEST['pathopen']) ? $_REQUEST['pathopen'] : null;
  8. // Language files that need to be included.
  9. $language_file = array('admin', 'tracking', 'scorm', 'exercice');
  10. // Including the global initialization file
  11. //require_once '../inc/global.inc.php';
  12. $current_course_tool = TOOL_TRACKING;
  13. $courseCode = isset($_REQUEST['cidReq']) ? $_REQUEST['cidReq'] : null;
  14. $course_info = api_get_course_info($courseCode);
  15. if (!empty($course_info)) {
  16. //api_protect_course_script();
  17. }
  18. $from_myspace = false;
  19. $from = isset($_GET['from']) ? $_GET['from'] : null;
  20. if ($from == 'myspace') {
  21. $from_myspace = true;
  22. $this_section = "session_my_space";
  23. } else {
  24. $this_section = SECTION_COURSES;
  25. }
  26. // Access restrictions.
  27. $is_allowedToTrack = api_is_platform_admin() || api_is_allowed_to_create_course() || api_is_session_admin() || api_is_drh() || api_is_course_tutor();
  28. if (!$is_allowedToTrack) {
  29. api_not_allowed();
  30. exit;
  31. }
  32. // Including additional libraries.
  33. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpath.class.php';
  34. require_once api_get_path(SYS_CODE_PATH).'newscorm/learnpathItem.class.php';
  35. require_once api_get_path(SYS_CODE_PATH).'newscorm/scorm.class.php';
  36. require_once api_get_path(SYS_CODE_PATH).'newscorm/scormItem.class.php';
  37. require_once api_get_path(LIBRARY_PATH).'statsUtils.lib.inc.php';
  38. require_once api_get_path(SYS_CODE_PATH).'resourcelinker/resourcelinker.inc.php';
  39. require_once api_get_path(SYS_CODE_PATH).'survey/survey.lib.php';
  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 = isset($_REQUEST['id_session']) ? intval($_REQUEST['id_session']) : api_get_session_id();
  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. // Scripts for reporting array hide / unhide columns
  51. $js = "<script>
  52. // hide column and display the button to unhide it
  53. function foldup(in_id) {
  54. $('#reporting_table .data_table tr td:nth-child('+in_id+')').fadeToggle();
  55. $('#reporting_table .data_table tr th:nth-child('+in_id+')').fadeToggle();
  56. $('div#unhideButtons span:nth-child('+in_id+')').fadeToggle();
  57. }
  58. // add the red cross on top of each column
  59. function init_hide() {
  60. $('div#reporting_table table tr th').each(
  61. function(index) {
  62. num_index = index + 1;
  63. // $(this).prepend('<div style=\"cursor:pointer\" onclick=\"foldup('+num_index+')\">".Display :: return_icon('visible.png', get_lang('HideColumn'), array('align' => 'absmiddle', 'hspace' => '3px'), 22)."</div>');
  64. }
  65. );
  66. }
  67. // hide some column at startup
  68. // be sure that these columns always exists
  69. // see tab_table_header = array(); // tab of header texts
  70. $(document).ready( function() {
  71. //init_hide();
  72. foldup(1);
  73. foldup(9);
  74. foldup(10);
  75. foldup(11);
  76. foldup(12);
  77. })
  78. </script>";
  79. $htmlHeadXtra[] = "<style type='text/css'>
  80. .secLine {background-color : #E6E6E6;}
  81. .content {padding-left : 15px;padding-right : 15px; }
  82. .specialLink{color : #0000FF;}
  83. /* Style for reporting array hide / unhide columns */
  84. .unhide_button {
  85. cursor : pointer;
  86. border:1px solid black;
  87. background-color: #FAFAFA;
  88. padding: 5px;
  89. border-radius : 3px;
  90. margin-right:3px;
  91. }
  92. div#reporting_table table th {
  93. vertical-align:top;
  94. }
  95. </style>";
  96. $htmlHeadXtra[] .= $js;
  97. // Database table definitions.
  98. //@todo remove this calls
  99. $TABLETRACK_ACCESS = Database::get_main_table(TABLE_STATISTIC_TRACK_E_LASTACCESS);
  100. $TABLETRACK_ACCESS_2 = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ACCESS);
  101. $TABLETRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  102. $TABLECOURSUSER = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  103. $TABLECOURSE = Database::get_main_table(TABLE_MAIN_COURSE);
  104. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  105. $TABLEQUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
  106. // Breadcrumbs.
  107. if (isset($_GET['origin']) && $_GET['origin'] == 'resume_session') {
  108. $interbreadcrumb[] = array('url' => '../session/index.php','name' => get_lang('PlatformAdmin'));
  109. $interbreadcrumb[] = array('url' => '../session/session_list.php','name' => get_lang('SessionList'));
  110. $interbreadcrumb[] = array('url' => '../session/resume_session.php?id_session='.api_get_session_id(), 'name' => get_lang('SessionOverview'));
  111. }
  112. $view = (isset($_REQUEST['view']) ? $_REQUEST['view'] : '');
  113. $nameTools = get_lang('Tracking');
  114. // Display the header.
  115. Display::display_header($nameTools, 'Tracking');
  116. // getting all the students of the course
  117. if (empty($session_id)) {
  118. // Registered students in a course outside session.
  119. $a_students = CourseManager :: get_student_list_from_course_code($course_info['real_id']);
  120. } else {
  121. // Registered students in session.
  122. $a_students = CourseManager :: get_student_list_from_course_code($course_info['real_id'], true, $session_id);
  123. }
  124. $nbStudents = count($a_students);
  125. // Gettting all the additional information of an additional profile field.
  126. if (isset($_GET['additional_profile_field']) && is_numeric($_GET['additional_profile_field'])) {
  127. $user_array = array();
  128. foreach ($a_students as $key=>$item) {
  129. $user_array[] = $key;
  130. }
  131. // Fetching only the user that are loaded NOT ALL user in the portal.
  132. $additional_user_profile_info = TrackingCourseLog::get_addtional_profile_information_of_field_by_user($_GET['additional_profile_field'],$user_array);
  133. $extra_info = UserManager::get_extra_field_information($_GET['additional_profile_field']);
  134. }
  135. /* MAIN CODE */
  136. echo '<div class="actions">';
  137. echo Display::url(Display::return_icon('user_na.png', get_lang('StudentsTracking'), array(), 32), '#');
  138. echo Display::url(Display::return_icon('group.png', get_lang('GroupReporting'), array(), 32), 'course_log_groups.php?'.api_get_cidreq());
  139. echo Display::url(Display::return_icon('course.png', get_lang('CourseTracking'), array(), 32), 'course_log_tools.php?'.api_get_cidreq(true, false));
  140. echo Display::url(Display::return_icon('tools.png', get_lang('ResourcesTracking'), array(), 32), 'course_log_resources.php?'.api_get_cidreq());
  141. echo Display::url(Display::return_icon('quiz.png', get_lang('ExamTracking'), array(), 32), api_get_path(WEB_CODE_PATH).'tracking/exams.php?'.api_get_cidreq());
  142. echo '<span style="float:right; padding-top:0px;">';
  143. echo '<a href="javascript: void(0);" onclick="javascript: window.print();">'.Display::return_icon('printer.png', get_lang('Print'),'',ICON_SIZE_MEDIUM).'</a>';
  144. $addional_param = '';
  145. if (isset($_GET['additional_profile_field'])) {
  146. $addional_param ='additional_profile_field='.intval($_GET['additional_profile_field']);
  147. }
  148. $users_tracking_per_page = '';
  149. if (isset($_GET['users_tracking_per_page'])) {
  150. $users_tracking_per_page= '&users_tracking_per_page='.intval($_GET['users_tracking_per_page']);
  151. }
  152. echo '<a href="'.api_get_self().'?'.api_get_cidreq().'&export=csv&'.$addional_param.$users_tracking_per_page.'">
  153. '.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a>';
  154. echo '</span>';
  155. echo '</div>';
  156. echo '<div class="actions">';
  157. // Create a search-box.
  158. $form_search = new FormValidator('search_simple', 'GET', api_get_path(WEB_CODE_PATH).'tracking/courseLog.php?'.api_get_cidreq(), '', array('class' => 'form-search'), false);
  159. $renderer = $form_search->defaultRenderer();
  160. $renderer->setElementTemplate('<span>{element}</span>');
  161. $form_search->addElement('hidden', 'from', Security::remove_XSS($from));
  162. $form_search->addElement('hidden', 'session_id', api_get_session_id());
  163. $form_search->addElement('text', 'user_keyword');
  164. $form_search->addElement('style_submit_button', 'submit', get_lang('SearchUsers'), 'class="search"');
  165. $form_search->display();
  166. echo '</div>';
  167. // BEGIN : form to remind inactives susers
  168. if (count($a_students) > 0) {
  169. $form = new FormValidator('reminder_form', 'get', api_get_path(REL_CODE_PATH).'announcements/announcements.php');
  170. $renderer = $form->defaultRenderer();
  171. $renderer->setElementTemplate('<span>{label} {element}</span>&nbsp;<button class="save" type="submit">'.get_lang('SendNotification').'</button>','since');
  172. $options = array (
  173. 2 => '2 '.get_lang('Days'),
  174. 3 => '3 '.get_lang('Days'),
  175. 4 => '4 '.get_lang('Days'),
  176. 5 => '5 '.get_lang('Days'),
  177. 6 => '6 '.get_lang('Days'),
  178. 7 => '7 '.get_lang('Days'),
  179. 15 => '15 '.get_lang('Days'),
  180. 30 => '30 '.get_lang('Days'),
  181. 'never' => get_lang('Never')
  182. );
  183. $el = $form -> addElement('select', 'since', '<img width="ICON_SIZE_SMALL" align="middle" src="'.api_get_path(WEB_IMG_PATH).'messagebox_warning.gif" border="0" />'.get_lang('RemindInactivesLearnersSince'), $options);
  184. $el -> setSelected(7);
  185. $form -> addElement('hidden', 'action', 'add');
  186. $form -> addElement('hidden', 'remindallinactives', 'true');
  187. $course_name = get_lang('Course').' '.$course_info['name'];
  188. if ($session_id) {
  189. echo Display::page_subheader(Display::return_icon('session.png', get_lang('Session'), array(), ICON_SIZE_SMALL).' '.api_get_session_name($session_id).' '.
  190. Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$course_name);
  191. } else {
  192. echo Display::page_subheader(Display::return_icon('course.png', get_lang('Course'), array(), ICON_SIZE_SMALL).' '.$course_info['name']);
  193. }
  194. $extra_field_select = TrackingCourseLog::display_additional_profile_fields();
  195. if (!empty($extra_field_select)) {
  196. echo $extra_field_select;
  197. }
  198. $form->display();
  199. //PERSON_NAME_DATA_EXPORT is buggy
  200. $is_western_name_order = api_is_western_name_order();
  201. if ($export_csv) {
  202. $csv_content = array();
  203. //override the SortableTable "per page" limit if CSV
  204. $_GET['users_tracking_per_page'] = 1000000;
  205. }
  206. $all_datas = array();
  207. $course_code = $_course['id'];
  208. $user_ids = array_keys($a_students);
  209. $table = new SortableTable('users_tracking', array('TrackingCourseLog', 'get_number_of_users'), array('TrackingCourseLog', 'get_user_data'), (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
  210. $parameters['cidReq'] = Security::remove_XSS($_GET['cidReq']);
  211. $parameters['id_session'] = $session_id;
  212. $parameters['from'] = isset($_GET['myspace']) ? Security::remove_XSS($_GET['myspace']) : null;
  213. $table->set_additional_parameters($parameters);
  214. $tab_table_header = array(); // tab of header texts
  215. $table->set_header(0, get_lang('OfficialCode'), true);
  216. $tab_table_header[] = get_lang('OfficialCode');
  217. if ($is_western_name_order) {
  218. $table->set_header(1, get_lang('FirstName'), true);
  219. $tab_table_header[] = get_lang('FirstName');
  220. $table->set_header(2, get_lang('LastName'), true);
  221. $tab_table_header[] = get_lang('LastName');
  222. } else {
  223. $table->set_header(1, get_lang('LastName'), true);
  224. $tab_table_header[] = get_lang('LastName');
  225. $table->set_header(2, get_lang('FirstName'), true);
  226. $tab_table_header[] = get_lang('FirstName');
  227. }
  228. $table->set_header(3, get_lang('Login'), false);
  229. $tab_table_header[] = get_lang('Login');
  230. $table->set_header(4, get_lang('TrainingTime'), false);
  231. $tab_table_header[] = get_lang('TrainingTime');
  232. $table->set_header(5, get_lang('CourseProgress').'&nbsp;'.Display::return_icon('info3.gif', get_lang('ScormAndLPProgressTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
  233. $tab_table_header[] = get_lang('CourseProgress');
  234. $table->set_header(6, get_lang('ExerciseProgress'), false);
  235. $tab_table_header[] = get_lang('ExerciseProgress');
  236. $table->set_header(7, get_lang('ExerciseAverage'), false);
  237. $tab_table_header[] = get_lang('ExerciseAverage');
  238. $table->set_header(8, get_lang('Score').'&nbsp;'.Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')), false, array('style' => 'width:110px;'));
  239. $tab_table_header[] = get_lang('Score');
  240. $table->set_header(9, get_lang('Student_publication'), false);
  241. $tab_table_header[] = get_lang('Student_publication');
  242. $table->set_header(10, get_lang('Messages'), false);
  243. $tab_table_header[] = get_lang('Messages');
  244. if (empty($session_id)) {
  245. $table->set_header(11, get_lang('Survey'), false);
  246. $tab_table_header[] = get_lang('Survey');
  247. $table->set_header(12, get_lang('FirstLogin'), false);
  248. $tab_table_header[] = get_lang('FirstLogin');
  249. $table->set_header(13, get_lang('LatestLogin'), false);
  250. $tab_table_header[] = get_lang('LatestLogin');
  251. if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
  252. $table->set_header(14, $extra_info['field_display_text'], false);
  253. $tab_table_header[] = $extra_info['field_display_text'];
  254. $table->set_header(15, get_lang('Details'), false);
  255. $tab_table_header[] = get_lang('Details');
  256. } else {
  257. $table->set_header(14, get_lang('Details'), false);
  258. $tab_table_header[] = get_lang('Details');
  259. }
  260. } else {
  261. $table->set_header(11, get_lang('FirstLogin'), false);
  262. $tab_table_header[] = get_lang('FirstLogin');
  263. $table->set_header(12, get_lang('LatestLogin'), false);
  264. $tab_table_header[] = get_lang('LatestLogin');
  265. if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
  266. $table->set_header(13, $extra_info['field_display_text'], false);
  267. $tab_table_header[] = $extra_info['field_display_text'];
  268. $table->set_header(14, get_lang('Details'), false);
  269. $tab_table_header[] = get_lang('Details');
  270. } else {
  271. $table->set_header(13, get_lang('Details'), false);
  272. $tab_table_header[] = get_lang('Details');
  273. }
  274. }
  275. // display buttons to unhide hidden columns
  276. echo "<br/><br/><div id='unhideButtons'>";
  277. for ($i=0; $i < count($tab_table_header); $i++) {
  278. $index = $i + 1;
  279. echo "<span title='".get_lang('DisplayColumn')." ".$tab_table_header[$i]."' class='unhide_button hide' onclick='foldup($index)'>".Display :: return_icon('move.png', get_lang('DisplayColumn'), array('align'=>'absmiddle', 'hspace'=>'3px'), 16)." ".$tab_table_header[$i]."</span>";
  280. }
  281. echo "</div>";
  282. // display the table
  283. echo "<div id='reporting_table'>";
  284. $table->display();
  285. echo "</div>";
  286. } else {
  287. echo Display::display_warning_message(get_lang('NoUsersInCourse'));
  288. }
  289. // Send the csv file if asked.
  290. if ($export_csv) {
  291. $csv_headers = array();
  292. $csv_headers[] = get_lang('OfficialCode', '');
  293. if ($is_western_name_order) {
  294. $csv_headers[] = get_lang('FirstName', '');
  295. $csv_headers[] = get_lang('LastName', '');
  296. } else {
  297. $csv_headers[] = get_lang('LastName', '');
  298. $csv_headers[] = get_lang('FirstName', '');
  299. }
  300. $csv_headers[] = get_lang('Login', ''); //
  301. $csv_headers[] = get_lang('TrainingTime', '');
  302. $csv_headers[] = get_lang('CourseProgress', '');
  303. $csv_headers[] = get_lang('ExerciseProgress','');
  304. $csv_headers[] = get_lang('ExerciseAverage','');
  305. $csv_headers[] = get_lang('Score', '');
  306. $csv_headers[] = get_lang('Student_publication', '');
  307. $csv_headers[] = get_lang('Messages', '');
  308. if (empty($session_id)) {
  309. $csv_headers[] = get_lang('Survey');
  310. }
  311. $csv_headers[] = get_lang('FirstLogin', '');
  312. $csv_headers[] = get_lang('LatestLogin', '');
  313. if (isset($_GET['additional_profile_field']) AND is_numeric($_GET['additional_profile_field'])) {
  314. $csv_headers[] = $extra_info['field_display_text'];
  315. }
  316. ob_end_clean();
  317. array_unshift($csv_content, $csv_headers); // Adding headers before the content.
  318. Export::export_table_csv($csv_content, 'reporting_student_list');
  319. exit;
  320. }
  321. Display::display_footer();