index.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212
  1. <?php // $Id: index.php 16620 2008-10-25 20:03:54Z yannoo $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2009 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) various contributors
  8. For a full list of contributors, see "credits.txt".
  9. The full license can be read in "license.txt".
  10. This program is free software; you can redistribute it and/or
  11. modify it under the terms of the GNU General Public License
  12. as published by the Free Software Foundation; either version 2
  13. of the License, or (at your option) any later version.
  14. See the GNU General Public License for more details.
  15. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  16. Mail: info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. * @todo use constant for $this_section
  21. */
  22. // name of the language file that needs to be included
  23. $language_file = array ('registration', 'index','tracking');
  24. $cidReset=true;
  25. require ('../inc/global.inc.php');
  26. require (api_get_path(LIBRARY_PATH).'tracking.lib.php');
  27. require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  28. require_once(api_get_path(LIBRARY_PATH).'export.lib.inc.php');
  29. ob_start();
  30. $export_csv = isset($_GET['export']) && $_GET['export'] == 'csv' ? true : false;
  31. $csv_content = array();
  32. $nameTools= get_lang("MySpace");
  33. $this_section = "session_my_space";
  34. // access control
  35. api_block_anonymous_users();
  36. if(!$export_csv)
  37. {
  38. Display :: display_header($nameTools);
  39. }
  40. else
  41. {
  42. if ($_GET['view'] == 'admin' AND $_GET['display'] == 'useroverview')
  43. {
  44. export_tracking_user_overview();
  45. exit;
  46. }
  47. }
  48. // Database table definitions
  49. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  50. $tbl_course = Database :: get_main_table(TABLE_MAIN_COURSE);
  51. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  52. $tbl_class = Database :: get_main_table(TABLE_MAIN_CLASS);
  53. $tbl_sessions = Database :: get_main_table(TABLE_MAIN_SESSION);
  54. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  55. $tbl_session_user = Database :: get_main_table(TABLE_MAIN_SESSION_USER);
  56. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  57. $tbl_admin = Database :: get_main_table(TABLE_MAIN_ADMIN);
  58. /********************
  59. * FUNCTIONS
  60. ********************/
  61. function count_teacher_courses()
  62. {
  63. global $nb_teacher_courses;
  64. return $nb_teacher_courses;
  65. }
  66. function count_coaches()
  67. {
  68. global $total_no_coachs;
  69. return $total_no_coachs;
  70. }
  71. function sort_users($a,$b){
  72. $a = trim(strtolower($a[$_SESSION['tracking_column']]));
  73. $b = trim(strtolower($b[$_SESSION['tracking_column']]));
  74. if($_SESSION['tracking_direction'] == 'DESC')
  75. return strcmp($b, $a);
  76. else
  77. return strcmp($a, $b);
  78. }
  79. /**************************
  80. * MAIN CODE
  81. ***************************/
  82. $isCoach = api_is_coach();
  83. $isPlatformAdmin = api_is_platform_admin();
  84. $view = isset($_GET['view']) ? $_GET['view'] : 'teacher';
  85. $menu_items = array();
  86. global $_configuration;
  87. if(api_is_allowed_to_create_course()) {
  88. $sqlNbCours = " SELECT course_rel_user.course_code, course.title
  89. FROM $tbl_course_user as course_rel_user
  90. INNER JOIN $tbl_course as course
  91. ON course.code = course_rel_user.course_code
  92. WHERE course_rel_user.user_id='".$_user['user_id']."' AND course_rel_user.status='1'
  93. ORDER BY course.title";
  94. if ($_configuration['multiple_access_urls']==true) {
  95. $tbl_course_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
  96. $access_url_id = api_get_current_access_url_id();
  97. if ($access_url_id != -1){
  98. $sqlNbCours = " SELECT course_rel_user.course_code, course.title
  99. FROM $tbl_course_user as course_rel_user
  100. INNER JOIN $tbl_course as course
  101. ON course.code = course_rel_user.course_code
  102. INNER JOIN $tbl_course_rel_access_url course_rel_url
  103. ON (course_rel_url.course_code= course.code)
  104. WHERE access_url_id = $access_url_id AND course_rel_user.user_id='".$_user['user_id']."' AND course_rel_user.status='1'
  105. ORDER BY course.title";
  106. }
  107. }
  108. $resultNbCours = api_sql_query($sqlNbCours, __FILE__, __LINE__);
  109. $a_courses = api_store_result($resultNbCours);
  110. $nb_teacher_courses = count($a_courses);
  111. if($nb_teacher_courses)
  112. {
  113. if(!$isCoach && !api_is_platform_admin())
  114. {
  115. $view = 'teacher';
  116. }
  117. if($view=='teacher')
  118. {
  119. $menu_items[] = get_lang('TeacherInterface');
  120. $title = get_lang('YourCourseList');
  121. }
  122. else
  123. {
  124. $menu_items[] = '<a href="'.api_get_self().'?view=teacher">'.get_lang('TeacherInterface').'</a>';
  125. }
  126. }
  127. }
  128. if($isCoach)
  129. {
  130. if($nb_teacher_courses==0 && !api_is_platform_admin())
  131. {
  132. $view = 'coach';
  133. }
  134. if($view=='coach')
  135. {
  136. $menu_items[] = get_lang('CoachInterface');
  137. $title = get_lang('YourStatistics');
  138. }
  139. else
  140. {
  141. $menu_items[] = '<a href="'.api_get_self().'?view=coach">'.get_lang('CoachInterface').'</a>';
  142. }
  143. }
  144. if(api_is_platform_admin())
  145. {
  146. if(!$isCoach && $nb_teacher_courses==0)
  147. {
  148. $view = 'admin';
  149. }
  150. if($view=='admin')
  151. {
  152. $menu_items[] = get_lang('AdminInterface');
  153. $title = get_lang('CoachList');
  154. }
  155. else
  156. {
  157. $menu_items[] = '<a href="'.api_get_self().'?view=admin">'.get_lang('AdminInterface').'</a>';
  158. }
  159. }
  160. if($_user['status']==DRH)
  161. {
  162. $view = 'drh';
  163. $title = get_lang('DrhInterface');
  164. $menu_items[] = '<a href="'.api_get_self().'?view=drh">'.get_lang('DrhInterface').'</a>';
  165. }
  166. echo '<div class="actions">';
  167. $nb_menu_items = count($menu_items);
  168. if($nb_menu_items>1)
  169. {
  170. foreach($menu_items as $key=> $item)
  171. {
  172. echo $item;
  173. if($key!=$nb_menu_items-1)
  174. {
  175. echo ' | ';
  176. }
  177. }
  178. }
  179. echo '
  180. <a href="#" onclick="window.print()"><img align="absbottom" src="../img/printmgr.gif">&nbsp;'.get_lang('Print').'</a>
  181. <a href="'.api_get_self().'?export=csv&view='.$view.'"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a>
  182. ';
  183. echo '</div>';
  184. echo '<h4>'.$title.'</h4>';
  185. if($_user['status']==DRH && $view=='drh')
  186. {
  187. $a_students = Tracking :: get_student_followed_by_drh($_user['user_id']);
  188. $courses_of_the_platform = CourseManager :: get_real_course_list();
  189. foreach($courses_of_the_platform as $course)
  190. $a_courses[$course['code']] = $course['code'];
  191. }
  192. if($isCoach && $view=='coach')
  193. {
  194. $a_students = Tracking :: get_student_followed_by_coach($_user['user_id']);
  195. $a_courses = Tracking :: get_courses_followed_by_coach($_user['user_id']);
  196. }
  197. if($view=='coach' || $view=='drh')
  198. {
  199. $nbStudents = count($a_students);
  200. $totalTimeSpent = 0;
  201. $totalCourses = 0;
  202. $avgTotalProgress = 0;
  203. $avgResultsToExercises = 0;
  204. $nb_inactive_students = 0;
  205. $nb_posts = $nb_assignments = 0;
  206. foreach($a_students as $student_id)
  207. {
  208. // inactive students
  209. $last_connection_date = Tracking :: get_last_connection_date($student_id,true,true);
  210. if($last_connection_date!=false)
  211. {
  212. /*
  213. list($last_connection_date, $last_connection_hour) = explode(' ',$last_connection_date);
  214. $last_connection_date = explode('-',$last_connection_date);
  215. $last_connection_hour = explode(':',$last_connection_hour);
  216. $last_connection_hour[0];
  217. $last_connection_time = mktime($last_connection_hour[0],$last_connection_hour[1],$last_connection_hour[2],$last_connection_date[1],$last_connection_date[2],$last_connection_date[0]);
  218. */
  219. if(time()-(3600*24*7) > $last_connection_time)
  220. {
  221. $nb_inactive_students++;
  222. }
  223. }
  224. else
  225. {
  226. $nb_inactive_students++;
  227. }
  228. $totalTimeSpent += Tracking :: get_time_spent_on_the_platform($student_id);
  229. $totalCourses += Tracking :: count_course_per_student($student_id);
  230. $avgStudentProgress = $avgStudentScore = 0;
  231. $nb_courses_student = 0;
  232. foreach($a_courses as $course_code)
  233. {
  234. if(CourseManager :: is_user_subscribed_in_course($student_id, $course_code, true))
  235. {
  236. $nb_courses_student++;
  237. $nb_posts += Tracking :: count_student_messages($student_id,$course_code);
  238. $nb_assignments += Tracking :: count_student_assignments($student_id,$course_code);
  239. $avgStudentProgress += Tracking :: get_avg_student_progress($student_id,$course_code);
  240. $avgStudentScore += Tracking :: get_avg_student_score($student_id,$course_code);
  241. if($nb_posts !== null && $nb_assignments !== null && $avgStudentProgress !== null && $avgStudentScore !== null)
  242. {
  243. //if one of these scores is null, it means that we had a problem connecting to the right database, so don't count it in
  244. $nb_courses_student++;
  245. }
  246. }
  247. }
  248. // average progress of the student
  249. $avgStudentProgress = $avgStudentProgress / $nb_courses_student;
  250. $avgTotalProgress += $avgStudentProgress;
  251. // average test results of the student
  252. $avgStudentScore = $avgStudentScore / $nb_courses_student;
  253. $avgResultsToExercises += $avgStudentScore;
  254. }
  255. // average progress
  256. $avgTotalProgress = $avgTotalProgress/$nbStudents;
  257. // average results to the tests
  258. $avgResultsToExercises = $avgResultsToExercises/$nbStudents;
  259. // average courses by student
  260. $avgCoursesPerStudent = round($totalCourses / $nbStudents,2);
  261. // average time spent on the platform
  262. $avgTimeSpent = $totalTimeSpent / $nbStudents;
  263. // average assignments
  264. $nb_assignments = $nb_assignments / $nbStudents;
  265. // average posts
  266. $nb_posts = $nb_posts / $nbStudents;
  267. //csv part
  268. if($export_csv)
  269. {
  270. $csv_content[] = array( get_lang('Probationers'));
  271. $csv_content[] = array( get_lang('InactivesStudents'),$nb_inactive_students );
  272. $csv_content[] = array( get_lang('AverageTimeSpentOnThePlatform'),$avgTimeSpent);
  273. $csv_content[] = array( get_lang('AverageCoursePerStudent'),$avgCoursesPerStudent);
  274. $csv_content[] = array( get_lang('AverageProgressInLearnpath'),$avgTotalProgress);
  275. $csv_content[] = array( get_lang('AverageResultsToTheExercices'),$avgResultsToExercises);
  276. $csv_content[] = array( get_lang('AveragePostsInForum'),$nb_posts);
  277. $csv_content[] = array( get_lang('AverageAssignments'),$nb_assignments);
  278. $csv_content[] = array();
  279. }
  280. // html part
  281. else
  282. {
  283. echo '
  284. <div class="admin_section">
  285. <h4>
  286. <a href="student.php"><img src="'.api_get_path(WEB_IMG_PATH).'students.gif">&nbsp;'.get_lang('Probationers').' ('.$nbStudents.')'.'</a>
  287. </h4>
  288. <table class="data_table">
  289. <tr>
  290. <td>
  291. '.get_lang('InactivesStudents').'
  292. </td>
  293. <td align="right">
  294. '.$nb_inactive_students.'
  295. </td>
  296. </tr>
  297. <tr>
  298. <td>
  299. '.get_lang('AverageTimeSpentOnThePlatform').'
  300. </td>
  301. <td align="right">
  302. '.api_time_to_hms($avgTimeSpent).'
  303. </td>
  304. </tr>
  305. <tr>
  306. <td>
  307. '.get_lang('AverageCoursePerStudent').'
  308. </td>
  309. <td align="right">
  310. '.$avgCoursesPerStudent.'
  311. </td>
  312. </tr>
  313. <tr>
  314. <td>
  315. '.get_lang('AverageProgressInLearnpath').'
  316. </td>
  317. <td align="right">
  318. '.round($avgTotalProgress,2).' %
  319. </td>
  320. </tr>
  321. <tr>
  322. <td>
  323. '.get_lang('AverageResultsToTheExercices').'
  324. </td>
  325. <td align="right">
  326. '.round($avgResultsToExercises,2).' %
  327. </td>
  328. </tr>
  329. <tr>
  330. <td>
  331. '.get_lang('AveragePostsInForum').'
  332. </td>
  333. <td align="right">
  334. '.round($nb_posts,2).'
  335. </td>
  336. </tr>
  337. <tr>
  338. <td>
  339. '.get_lang('AverageAssignments').'
  340. </td>
  341. <td align="right">
  342. '.round($nb_assignments,2).'
  343. </td>
  344. </tr>
  345. </table>
  346. <a href="student.php">'.get_lang('SeeStudentList').'</a>
  347. </div>';
  348. }
  349. }
  350. if($view == 'coach')
  351. {
  352. /****************************************
  353. * Infos about sessions of the coach
  354. ****************************************/
  355. $a_sessions = Tracking :: get_sessions_coached_by_user($_user['user_id']);
  356. $nbSessions = count($a_sessions);
  357. $nb_sessions_past = $nb_sessions_future = $nb_sessions_current = 0;
  358. $a_courses = array();
  359. foreach($a_sessions as $a_session)
  360. {
  361. if($a_session['date_start'] == '0000-00-00')
  362. {
  363. $nb_sessions_current ++;
  364. }
  365. else
  366. {
  367. $date_start = explode('-',$a_session['date_start']);
  368. $time_start = mktime(0,0,0,$date_start[1],$date_start[2],$date_start[0]);
  369. $date_end = explode('-',$a_session['date_end']);
  370. $time_end = mktime(0,0,0,$date_end[1],$date_end[2],$date_end[0]);
  371. if($time_start < time() && time() < $time_end)
  372. {
  373. $nb_sessions_current++;
  374. }
  375. else if(time() < $time_start)
  376. {
  377. $nb_sessions_future++;
  378. }
  379. else if(time() > $time_end)
  380. {
  381. $nb_sessions_past++;
  382. }
  383. }
  384. $a_courses = array_merge($a_courses, Tracking::get_courses_list_from_session($a_session['id']));
  385. }
  386. $nb_courses_per_session = round(count($a_courses)/$nbSessions,2);
  387. //csv part
  388. if($export_csv)
  389. {
  390. $csv_content[] = array( get_lang('Sessions'));
  391. $csv_content[] = array( get_lang('NbActiveSessions').';'.$nb_sessions_current);
  392. $csv_content[] = array( get_lang('NbPastSessions').';'.$nb_sessions_past);
  393. $csv_content[] = array( get_lang('NbFutureSessions').';'.$nb_sessions_future);
  394. $csv_content[] = array( get_lang('NbStudentPerSession').';'.round($nbStudents/$nbSessions,2));
  395. $csv_content[] = array( get_lang('NbCoursesPerSession').';'.$nb_courses_per_session);
  396. $csv_content[] = array();
  397. }
  398. // html part
  399. else
  400. {
  401. echo '
  402. <div class="admin_section">
  403. <h4>
  404. <a href="session.php"><img src="'.api_get_path(WEB_IMG_PATH).'sessions.gif">&nbsp;'.get_lang('Sessions').' ('.$nbSessions.')'.'</a>
  405. </h4>
  406. <table class="data_table">
  407. <tr>
  408. <td>
  409. '.get_lang('NbActiveSessions').'
  410. </td>
  411. <td align="right">
  412. '.$nb_sessions_current.'
  413. </td>
  414. </tr>
  415. <tr>
  416. <td>
  417. '.get_lang('NbPastSessions').'
  418. </td>
  419. <td align="right">
  420. '.$nb_sessions_past.'
  421. </td>
  422. </tr>
  423. <tr>
  424. <td>
  425. '.get_lang('NbFutureSessions').'
  426. </td>
  427. <td align="right">
  428. '.$nb_sessions_future.'
  429. </td>
  430. </tr>
  431. <tr>
  432. <td>
  433. '.get_lang('NbStudentPerSession').'
  434. </td>
  435. <td align="right">
  436. '.round($nbStudents/$nbSessions,2).'
  437. </td>
  438. </tr>
  439. <tr>
  440. <td>
  441. '.get_lang('NbCoursesPerSession').'
  442. </td>
  443. <td align="right">
  444. '.$nb_courses_per_session.'
  445. </td>
  446. </tr>
  447. </table>
  448. <a href="session.php">'.get_lang('SeeSessionList').'</a>
  449. </div>';
  450. }
  451. }
  452. echo '<div class="clear">&nbsp;</div>';
  453. if(api_is_allowed_to_create_course() && $view=='teacher')
  454. {
  455. if($nb_teacher_courses)
  456. {
  457. $table = new SortableTable('tracking_list_course', 'count_teacher_courses');
  458. $parameters['view'] = 'teacher';
  459. $table->set_additional_parameters($parameters);
  460. $table -> set_header(0, get_lang('CourseTitle'), false, 'align="center"');
  461. $table -> set_header(1, get_lang('NbStudents'), false);
  462. $table -> set_header(2, get_lang('AvgTimeSpentInTheCourse'), false);
  463. $table -> set_header(3, get_lang('AvgStudentsProgress'), false);
  464. $table -> set_header(4, get_lang('AvgStudentsScore'), false);
  465. $table -> set_header(5, get_lang('AvgMessages'), false);
  466. $table -> set_header(6, get_lang('AvgAssignments'), false);
  467. $table -> set_header(7, get_lang('Details'), false);
  468. $csv_content[] = array(
  469. get_lang('CourseTitle'),
  470. get_lang('NbStudents'),
  471. get_lang('AvgTimeSpentInTheCourse'),
  472. get_lang('AvgStudentsProgress'),
  473. get_lang('AvgStudentsScore'),
  474. get_lang('AvgMessages'),
  475. get_lang('AvgAssignments')
  476. );
  477. $a_course_students = array();
  478. foreach($a_courses as $course)
  479. {
  480. $course_code = $course['course_code'];
  481. $avg_assignments_in_course = $avg_messages_in_course = $nb_students_in_course = $avg_progress_in_course = $avg_score_in_course = $avg_time_spent_in_course = 0;
  482. // students directly subscribed to the course
  483. $sql = "SELECT user_id FROM $tbl_course_user as course_rel_user WHERE course_rel_user.status='5' AND course_rel_user.course_code='$course_code'";
  484. $rs = api_sql_query($sql, __FILE__, __LINE__);
  485. while($row = Database::fetch_array($rs))
  486. {
  487. $nb_students_in_course++;
  488. // tracking datas
  489. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  490. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  491. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  492. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  493. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  494. $a_course_students[] = $row['user_id'];
  495. }
  496. // students subscribed to the course through a session
  497. if(api_get_setting('use_session_mode') == 'true')
  498. {
  499. $sql = 'SELECT id_user as user_id
  500. FROM '.$tbl_session_course_user.'
  501. WHERE course_code="'.addslashes($course_code).'" ORDER BY course_code';
  502. $rs = api_sql_query($sql, __FILE__, __LINE__);
  503. while($row = Database::fetch_array($rs))
  504. {
  505. if(!in_array($row['user_id'], $a_course_students))
  506. {
  507. $nb_students_in_course++;
  508. // tracking datas
  509. $avg_progress_in_course += Tracking :: get_avg_student_progress ($row['user_id'], $course_code);
  510. $avg_score_in_course += Tracking :: get_avg_student_score ($row['user_id'], $course_code);
  511. $avg_time_spent_in_course += Tracking :: get_time_spent_on_the_course ($row['user_id'], $course_code);
  512. $avg_messages_in_course += Tracking :: count_student_messages ($row['user_id'], $course_code);
  513. $avg_assignments_in_course += Tracking :: count_student_assignments ($row['user_id'], $course_code);
  514. $a_course_students[] = $row['user_id'];
  515. }
  516. }
  517. }
  518. if($nb_students_in_course>0)
  519. {
  520. $avg_time_spent_in_course = api_time_to_hms($avg_time_spent_in_course / $nb_students_in_course);
  521. $avg_progress_in_course = round($avg_progress_in_course / $nb_students_in_course,2).' %';
  522. $avg_score_in_course = round($avg_score_in_course / $nb_students_in_course,2).' %';
  523. $avg_messages_in_course = round($avg_messages_in_course / $nb_students_in_course,2);
  524. $avg_assignments_in_course = round($avg_assignments_in_course / $nb_students_in_course,2);
  525. }
  526. $table_row = array();
  527. $table_row[] = $course['title'];
  528. $table_row[] = $nb_students_in_course;
  529. $table_row[] = $avg_time_spent_in_course;
  530. $table_row[] = $avg_progress_in_course;
  531. $table_row[] = $avg_score_in_course;
  532. $table_row[] = $avg_messages_in_course;
  533. $table_row[] = $avg_assignments_in_course;
  534. $table_row[] = '<a href="../tracking/courseLog.php?cidReq='.$course_code.'&studentlist=true"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  535. $csv_content[] = array(
  536. html_entity_decode($course['title']),
  537. $nb_students_in_course,
  538. $avg_time_spent_in_course,
  539. $avg_progress_in_course,
  540. $avg_score_in_course,
  541. $avg_messages_in_course,
  542. $avg_assignments_in_course,
  543. );
  544. $table -> addRow($table_row, 'align="right"');
  545. $a_course_students = array();
  546. }
  547. $table -> updateColAttributes(0,array('align'=>'left'));
  548. $table -> updateColAttributes(7,array('align'=>'center'));
  549. $table -> display();
  550. }
  551. }
  552. if(api_is_platform_admin() && $view=='admin')
  553. {
  554. echo '<a href="'.api_get_self().'?view=admin&amp;display=coaches">'.get_lang('DisplayCoaches').'</a> | ';
  555. echo '<a href="'.api_get_self().'?view=admin&amp;display=useroverview">'.get_lang('DisplayUserOverview').'</a>';
  556. if ($_GET['display'] == 'useroverview')
  557. {
  558. echo ' | <a href="'.api_get_self().'?view=admin&amp;display=useroverview&amp;export=options">'.get_lang('ExportUserOverviewOptions').'</a>';
  559. }
  560. if ($_GET['display'] === 'useroverview')
  561. {
  562. display_tracking_user_overview();
  563. }
  564. else
  565. {
  566. $tracking_column = isset($_GET['tracking_list_coaches_column']) ? $_GET['tracking_list_coaches_column'] : 0;
  567. $tracking_direction = (isset($_GET['tracking_list_coaches_direction']) && in_array(strtoupper($_GET['tracking_list_coaches_direction']),array('ASC','DESC','ASCENDING','DESCENDING','0','1'))) ? $_GET['tracking_list_coaches_direction'] : 'DESC';
  568. //prepare array for column order - when impossible, use lastname
  569. $order = array(0=>'firstname',1=>'lastname',2=>'lastname',3=>'login_date',4=>'lastname',5=>'lastname');
  570. $table = new SortableTable('tracking_list_coaches', 'count_coaches');
  571. $parameters['view'] = 'admin';
  572. $table->set_additional_parameters($parameters);
  573. $table -> set_header(0, get_lang('FirstName'), true, 'align="center"');
  574. $table -> set_header(1, get_lang('LastName'), true, 'align="center"');
  575. $table -> set_header(2, get_lang('TimeSpentOnThePlatform'), false);
  576. $table -> set_header(3, get_lang('LastConnexion'), true, 'align="center"');
  577. $table -> set_header(4, get_lang('NbStudents'), false);
  578. $table -> set_header(5, get_lang('CountCours'), false);
  579. $table -> set_header(6, get_lang('NumberOfSessions'), false);
  580. $table -> set_header(7, get_lang('Sessions'), false,'align="center"');
  581. $csv_content[] = array(
  582. get_lang('FirstName'),
  583. get_lang('LastName'),
  584. get_lang('TimeSpentOnThePlatform'),
  585. get_lang('LastConnexion'),
  586. get_lang('NbStudents'),
  587. get_lang('CountCours'),
  588. get_lang('NumberOfSessions')
  589. );
  590. $tbl_track_login = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  591. $sqlCoachs = " SELECT DISTINCT id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  592. FROM $tbl_user, $tbl_session_course, $tbl_track_login
  593. WHERE id_coach=user_id AND login_user_id=user_id
  594. GROUP BY user_id " ;
  595. // ORDER BY login_date ".$tracking_direction;
  596. if ($_configuration['multiple_access_urls']==true) {
  597. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  598. $access_url_id = api_get_current_access_url_id();
  599. if ($access_url_id != -1){
  600. $sqlCoachs = " SELECT DISTINCT id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  601. FROM $tbl_user, $tbl_session_course, $tbl_track_login , $tbl_session_rel_access_url session_rel_url
  602. WHERE id_coach=user_id AND login_user_id=user_id AND access_url_id = $access_url_id AND session_rel_url.session_id=id_session
  603. GROUP BY user_id " ;
  604. }
  605. }
  606. if(!empty($order[$tracking_column]))
  607. {
  608. $sqlCoachs .= "ORDER BY ".$order[$tracking_column]." ".$tracking_direction;
  609. }
  610. $result_coaches=api_sql_query($sqlCoachs, __FILE__, __LINE__);
  611. $total_no_coachs = Database::num_rows($result_coaches);
  612. $global_coachs=array();
  613. while($a_coach=Database::fetch_array($result_coaches)){
  614. $global_coachs[$a_coach['user_id']] = $a_coach;
  615. }
  616. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  617. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.'
  618. WHERE id_coach=user_id AND login_user_id=user_id
  619. GROUP BY user_id
  620. ORDER BY login_date '.$tracking_direction;
  621. if ($_configuration['multiple_access_urls']==true) {
  622. $tbl_session_rel_access_url= Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION);
  623. $access_url_id = api_get_current_access_url_id();
  624. if ($access_url_id != -1){
  625. $sql_session_coach = 'SELECT session.id_coach, user_id, lastname, firstname, MAX(login_date) as login_date
  626. FROM '.$tbl_user.','.$tbl_sessions.' as session,'.$tbl_track_login.' , '.$tbl_session_rel_access_url.' as session_rel_url
  627. WHERE id_coach=user_id AND login_user_id=user_id AND access_url_id = '.$access_url_id.' AND session_rel_url.session_id=session.id
  628. GROUP BY user_id
  629. ORDER BY login_date '.$tracking_direction;
  630. }
  631. }
  632. $result_sessions_coach=api_sql_query($sql_session_coach, __FILE__, __LINE__);
  633. $total_no_coachs += Database::num_rows($result_sessions_coach);
  634. while($a_coach=Database::fetch_array($result_sessions_coach)){
  635. $global_coachs[$a_coach['user_id']] = $a_coach;
  636. }
  637. $all_datas=array();
  638. foreach($global_coachs as $id_coach => $a_coachs){
  639. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($a_coachs['user_id']));
  640. $last_connection = Tracking :: get_last_connection_date($a_coachs['user_id']);
  641. $nb_students = count(Tracking :: get_student_followed_by_coach($a_coachs['user_id']));
  642. $nb_courses = count(Tracking :: get_courses_followed_by_coach($a_coachs['user_id']));
  643. $nb_sessions = count(Tracking :: get_sessions_coached_by_user($a_coachs['user_id']));
  644. $table_row = array();
  645. $table_row[] = $a_coachs['firstname'];
  646. $table_row[] = $a_coachs['lastname'];
  647. $table_row[] = $time_on_platform;
  648. $table_row[] = $last_connection;
  649. $table_row[] = $nb_students;
  650. $table_row[] = $nb_courses;
  651. $table_row[] = $nb_sessions;
  652. $table_row[] = '<a href="session.php?id_coach='.$a_coachs['user_id'].'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a>';
  653. $all_datas[] = $table_row;
  654. $csv_content[] = array(
  655. html_entity_decode($a_coachs['firstname']),
  656. html_entity_decode($a_coachs['lastname']),
  657. $time_on_platform,
  658. $last_connection,
  659. $nb_courses,
  660. $nb_sessions
  661. );
  662. }
  663. if($tracking_column != 3){
  664. usort($all_datas, 'sort_users');
  665. if($tracking_direction == 'DESC')
  666. rsort($all_datas);
  667. }
  668. if($export_csv && $tracking_column != 3)
  669. {
  670. usort($csv_content, 'sort_users');
  671. }
  672. foreach($all_datas as $row)
  673. {
  674. $table -> addRow($row,'align="right"');
  675. }
  676. $table -> updateColAttributes(0,array('align'=>'left'));
  677. $table -> updateColAttributes(1,array('align'=>'left'));
  678. $table -> updateColAttributes(3,array('align'=>'left'));
  679. $table -> updateColAttributes(7,array('align'=>'center'));
  680. $table -> display();
  681. }
  682. }
  683. // send the csv file if asked
  684. if($export_csv)
  685. {
  686. ob_end_clean();
  687. /*echo "<pre>";
  688. print_r($csv_content);
  689. echo "</pre>";*/
  690. Export :: export_table_csv($csv_content, 'reporting_index');
  691. }
  692. //footer
  693. if(!$export_csv)
  694. {
  695. Display::display_footer();
  696. }
  697. /**
  698. * This function exports the table that we see in display_tracking_user_overview()
  699. *
  700. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  701. * @version Dokeos 1.8.6
  702. * @since October 2008
  703. */
  704. function export_tracking_user_overview()
  705. {
  706. // database table definitions
  707. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  708. // the values of the sortable table
  709. if ($_GET['tracking_user_overview_page_nr'])
  710. {
  711. $from = $_GET['tracking_user_overview_page_nr'];
  712. }
  713. else
  714. {
  715. $from = 0;
  716. }
  717. if ($_GET['tracking_user_overview_column'])
  718. {
  719. $orderby = $_GET['tracking_user_overview_column'];
  720. }
  721. else
  722. {
  723. $orderby = 0;
  724. }
  725. if ($_GET['tracking_user_overview_direction'])
  726. {
  727. $direction = $_GET['tracking_user_overview_direction'];
  728. }
  729. else
  730. {
  731. $direction = 'ASC';
  732. }
  733. $user_data = get_user_data_tracking_overview($from, 1000 , $orderby, $direction);
  734. // the first line of the csv file with the column headers
  735. $csv_row = array();
  736. $csv_row[] = get_lang('OfficialCode');
  737. $csv_row[] = get_lang('LastName');
  738. $csv_row[] = get_lang('FirstName');
  739. $csv_row[] = get_lang('LoginName');
  740. $csv_row[] = get_lang('CourseCode');
  741. // the additional user defined fields (only those that were selected to be exported)
  742. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  743. $fields = UserManager::get_extra_fields(0,50,5,'ASC');
  744. foreach ($_SESSION['additional_export_fields'] as $key=>$extra_field_export)
  745. {
  746. $csv_row[] = $fields[$extra_field_export][3];
  747. $field_names_to_be_exported[] = 'extra_'.$fields[$extra_field_export][1];
  748. }
  749. $csv_row[] = get_lang('AvgTimeSpentInTheCourse');
  750. $csv_row[] = get_lang('AvgStudentsProgress');
  751. $csv_row[] = get_lang('AvgStudentsScore');
  752. $csv_row[] = get_lang('AvgMessages');
  753. $csv_row[] = get_lang('AvgAssignments');
  754. $csv_row[] = get_lang('TotalExercisesScoreObtained');
  755. $csv_row[] = get_lang('TotalExercisesScorePossible');
  756. $csv_row[] = get_lang('TotalExercisesAnswered');
  757. $csv_row[] = get_lang('TotalExercisesScorePercentage');
  758. $csv_row[] = get_lang('FirstLogin');
  759. $csv_row[] = get_lang('LatestLogin');
  760. $csv_content[] = $csv_row;
  761. // the other lines (the data)
  762. foreach($user_data as $key=>$user)
  763. {
  764. // getting all the courses of the user
  765. $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user[4])."'";
  766. $result = api_sql_query($sql, __FILE__, __LINE__);
  767. while ($row = Database::fetch_row($result))
  768. {
  769. $csv_row = array();
  770. // user official code
  771. $csv_row[] = $user[0];
  772. // user last name
  773. $csv_row[] = $user[1];
  774. // user first name
  775. $csv_row[] = $user[2];
  776. // user login name
  777. $csv_row[] = $user[3];
  778. // course code
  779. $csv_row[] = $row[0];
  780. // the additional defined user fields
  781. $extra_fields = get_user_overview_export_extra_fields($user[4]);
  782. foreach ($field_names_to_be_exported as $key=>$extra_field_export)
  783. {
  784. $csv_row[] = $extra_fields[$extra_field_export];
  785. }
  786. // time spent in the course
  787. $csv_row[] = api_time_to_hms(Tracking :: get_time_spent_on_the_course ($user[4], $row[0]));
  788. // student progress in course
  789. $csv_row[] = Tracking :: get_avg_student_progress ($user[4], $row[0]);
  790. // student score
  791. $csv_row[] = Tracking :: get_avg_student_score ($user[4], $row[0]);
  792. // student messages
  793. $csv_row[] = Tracking :: count_student_messages ($user[4], $row[0]);
  794. // student assignments
  795. $csv_row[] = Tracking :: count_student_assignments ($user[4], $row[0]);
  796. // student exercises results
  797. $exercises_results = exercises_results($user[4], $row[0]);
  798. $csv_row[] = $exercises_results['score_obtained'];
  799. $csv_row[] = $exercises_results['score_possible'];
  800. $csv_row[] = $exercises_results['questions_answered'];
  801. $csv_row[] = $exercises_results['percentage'];
  802. // first connection
  803. $csv_row[] = Tracking :: get_first_connection_date_on_the_course ($user[4], $row[0]);
  804. // last connection
  805. $csv_row[] = strip_tags(Tracking :: get_last_connection_date_on_the_course ($user[4], $row[0]));
  806. $csv_content[] = $csv_row;
  807. }
  808. }
  809. Export :: export_table_csv($csv_content, 'reporting_user_overview');
  810. }
  811. /**
  812. * Display a sortable table that contains an overview off all the reporting progress of all users and all courses the user is subscribed to
  813. *
  814. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  815. * @version Dokeos 1.8.6
  816. * @since October 2008
  817. */
  818. function display_tracking_user_overview()
  819. {
  820. display_user_overview_export_options();
  821. $table = new SortableTable('tracking_user_overview', 'get_number_of_users_tracking_overview', 'get_user_data_tracking_overview',1);
  822. $table->set_header(0, get_lang('OfficialCode'));
  823. $table->set_header(1, get_lang('LastName'));
  824. $table->set_header(2, get_lang('FirstName'));
  825. $table->set_header(3, get_lang('LoginName'));
  826. $table->set_header(4, get_lang('CourseInformation'), false);
  827. $table->set_column_filter(4, 'course_info_tracking_filter');
  828. $table -> display();
  829. }
  830. /**
  831. * get the numer of users of the platform
  832. *
  833. * @return integer
  834. *
  835. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  836. * @version Dokeos 1.8.6
  837. * @since October 2008
  838. */
  839. function get_number_of_users_tracking_overview()
  840. {
  841. // database table definition
  842. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  843. // query
  844. $sql = 'SELECT user_id FROM '.$main_user_table;
  845. $result = api_sql_query($sql, __FILE__, __LINE__);
  846. // return the number of results
  847. return Database::num_rows($result);
  848. }
  849. /**
  850. * get all the data for the sortable table of the reporting progress of all users and all the courses the user is subscribed to.
  851. *
  852. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  853. * @version Dokeos 1.8.6
  854. * @since October 2008
  855. */
  856. function get_user_data_tracking_overview($from, $number_of_items, $column, $direction)
  857. {
  858. // database table definition
  859. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  860. $sql = "SELECT
  861. official_code AS col0,
  862. lastname AS col1,
  863. firstname AS col2,
  864. username AS col3,
  865. user_id AS col4
  866. FROM
  867. $main_user_table
  868. ";
  869. $sql .= " ORDER BY col$column $direction ";
  870. $sql .= " LIMIT $from,$number_of_items";
  871. $result = api_sql_query($sql, __FILE__, __LINE__);
  872. $return = array ();
  873. while ($user = Database::fetch_row($result))
  874. {
  875. $return[] = $user;
  876. }
  877. return $return;
  878. }
  879. /**
  880. * Creates a small table in the last column of the table with the user overview
  881. *
  882. * @param integer $user_id the id of the user
  883. * @param array $url_params additonal url parameters
  884. * @param array $row the row information (the other columns)
  885. * @return html code
  886. *
  887. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  888. * @version Dokeos 1.8.6
  889. * @since October 2008
  890. */
  891. function course_info_tracking_filter($user_id,$url_params,$row)
  892. {
  893. // the table header
  894. $return .= '<table class="data_table">';
  895. $return .= ' <tr>';
  896. $return .= ' <th>'.get_lang('Course').'</th>';
  897. $return .= ' <th>'.get_lang('AvgTimeSpentInTheCourse').'</th>';
  898. $return .= ' <th>'.get_lang('AvgStudentsProgress').'</th>';
  899. $return .= ' <th>'.get_lang('AvgStudentsScore').'</th>';
  900. $return .= ' <th>'.get_lang('AvgMessages').'</th>';
  901. $return .= ' <th>'.get_lang('AvgAssignments').'</th>';
  902. $return .= ' <th>'.get_lang('TotalExercisesScoreObtained').'</th>';
  903. $return .= ' <th>'.get_lang('TotalExercisesScorePossible').'</th>';
  904. $return .= ' <th>'.get_lang('TotalExercisesAnswered').'</th>';
  905. $return .= ' <th>'.get_lang('TotalExercisesScorePercentage').'</th>';
  906. $return .= ' <th>'.get_lang('FirstLogin').'</th>';
  907. $return .= ' <th>'.get_lang('LatestLogin').'</th>';
  908. $return .= ' </tr>';
  909. // database table definition
  910. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  911. // getting all the courses of the user
  912. $sql = "SELECT * FROM $tbl_course_user WHERE user_id = '".Database::escape_string($user_id)."'";
  913. $result = api_sql_query($sql, __FILE__, __LINE__);
  914. while ($row = Database::fetch_row($result))
  915. {
  916. $return .= '<tr>';
  917. // course code
  918. $return .= ' <td>'.$row[0].'</td>';
  919. // time spent in the course
  920. $return .= ' <td>'.api_time_to_hms(Tracking :: get_time_spent_on_the_course ($user_id, $row[0])).'</td>';
  921. // student progress in course
  922. $return .= ' <td>'.Tracking :: get_avg_student_progress ($user_id, $row[0]).'</td>';
  923. // student score
  924. $return .= ' <td>'.Tracking :: get_avg_student_score ($user_id, $row[0]).'</td>';
  925. // student messages
  926. $return .= ' <td>'.Tracking :: count_student_messages ($user_id, $row[0]).'</td>';
  927. // student assignments
  928. $return .= ' <td>'.Tracking :: count_student_assignments ($user_id, $row[0]).'</td>';
  929. // student exercises results (obtained score, maximum score, number of exercises answered, score percentage)
  930. $exercises_results = exercises_results($user_id, $row[0]);
  931. $return .= ' <td>'.$exercises_results['score_obtained'].'</td>';
  932. $return .= ' <td>'.$exercises_results['score_possible'].'</td>';
  933. $return .= ' <td>'.$exercises_results['questions_answered'].'</td>';
  934. $return .= ' <td>'.$exercises_results['percentage'].'% </td>';
  935. // first connection
  936. $return .= ' <td>'.Tracking :: get_first_connection_date_on_the_course ($user_id, $row[0]).'</td>';
  937. // last connection
  938. $return .= ' <td>'.Tracking :: get_last_connection_date_on_the_course ($user_id, $row[0]).'</td>';
  939. $return .= '<tr>';
  940. }
  941. $return .= '</table>';
  942. return $return;
  943. }
  944. /**
  945. * Get general information about the exercise performance of the user
  946. * the total obtained score (all the score on all the questions)
  947. * the maximum score that could be obtained
  948. * the number of questions answered
  949. * the success percentage
  950. *
  951. * @param integer $user_id the id of the user
  952. * @param string $course_code the course code
  953. *
  954. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  955. * @version Dokeos 1.8.6
  956. * @since November 2008
  957. */
  958. function exercises_results($user_id, $course_code)
  959. {
  960. $questions_answered = 0;
  961. $sql = 'SELECT exe_result , exe_weighting
  962. FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES)."
  963. WHERE exe_cours_id = '".Database::escape_string($course_code)."'
  964. AND exe_user_id = '".Database::escape_string($user_id)."'";
  965. $result = api_sql_query($sql, __FILE__, __LINE__);
  966. $score_obtained = 0;
  967. $score_possible = 0;
  968. $questions_answered = 0;
  969. while ($row = Database::fetch_array($result))
  970. {
  971. $score_obtained += $row['exe_result'];
  972. $score_possible += $row['exe_weighting'];
  973. $questions_answered ++;
  974. }
  975. if ($score_possible !== 0) {
  976. $percentage = round(($score_obtained / $score_possible * 100),2);
  977. }
  978. return array('score_obtained' => $score_obtained, 'score_possible' => $score_possible, 'questions_answered' => $questions_answered, 'percentage' => $percentage);
  979. }
  980. /**
  981. * Displays a form with all the additionally defined user fields of the profile
  982. * and give you the opportunity to include these in the CSV export
  983. *
  984. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  985. * @version Dokeos 1.8.6
  986. * @since November 2008
  987. */
  988. function display_user_overview_export_options()
  989. {
  990. // include the user manager and formvalidator library
  991. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  992. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  993. if ($_GET['export'] == 'options')
  994. {
  995. // get all the defined extra fields
  996. $extrafields = UserManager::get_extra_fields(0,50,5,'ASC');
  997. // creating the form with all the defined extra fields
  998. $form = new FormValidator('exportextrafields', 'post', api_get_self()."?view=".Security::remove_XSS($_GET['view']).'&display='.Security::remove_XSS($_GET['display']).'&export='.Security::remove_XSS($_GET['export']));
  999. foreach ($extrafields as $key=>$extra)
  1000. {
  1001. $form->addElement('checkbox', 'extra_export_field'.$extra[0], '', $extra[3]);
  1002. }
  1003. $form->addElement('submit', null, get_lang('Ok'));
  1004. // setting the default values for the form that contains all the extra fields
  1005. if(is_array($_SESSION['additional_export_fields']))
  1006. foreach($_SESSION['additional_export_fields'] as $key => $value)
  1007. {
  1008. $defaults['extra_export_field'.$value]=1;
  1009. }
  1010. $form->setDefaults($defaults);
  1011. if ($form->validate())
  1012. {
  1013. // exporting the form values
  1014. $values = $form->exportValues();
  1015. // re-initialising the session that contains the additional fields that need to be exported
  1016. $_SESSION['additional_export_fields'] = array();
  1017. // adding the fields that are checked to the session
  1018. $message='';
  1019. foreach ($values as $field_ids => $value)
  1020. {
  1021. if ($value == 1 AND strstr($field_ids,'extra_export_field'))
  1022. {
  1023. $_SESSION['additional_export_fields'][] = str_replace('extra_export_field','',$field_ids);
  1024. }
  1025. }
  1026. // adding the fields that will be also exported to a message string
  1027. foreach ($_SESSION['additional_export_fields'] as $key=>$extra_field_export)
  1028. {
  1029. $message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
  1030. }
  1031. // Displaying a feedback message
  1032. if (!empty($_SESSION['additional_export_fields']))
  1033. {
  1034. Display::display_confirmation_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>',false);
  1035. }
  1036. else
  1037. {
  1038. Display::display_confirmation_message(get_lang('NoAdditionalFieldsWillBeExported'),false);
  1039. }
  1040. $message = '';
  1041. }
  1042. else
  1043. {
  1044. $form->display();
  1045. }
  1046. }
  1047. else
  1048. {
  1049. if (!empty($_SESSION['additional_export_fields']))
  1050. {
  1051. // get all the defined extra fields
  1052. $extrafields = UserManager::get_extra_fields(0,50,5,'ASC');
  1053. foreach ($_SESSION['additional_export_fields'] as $key=>$extra_field_export)
  1054. {
  1055. $message .= '<li>'.$extrafields[$extra_field_export][3].'</li>';
  1056. }
  1057. Display::display_normal_message(get_lang('FollowingFieldsWillAlsoBeExported').': <br /><ul>'.$message.'</ul>',false);
  1058. $message = '';
  1059. }
  1060. }
  1061. }
  1062. /**
  1063. * Get all information that the user with user_id = $user_data has
  1064. * entered in the additionally defined profile fields
  1065. *
  1066. * @param integer $user_id the id of the user
  1067. *
  1068. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  1069. * @version Dokeos 1.8.6
  1070. * @since November 2008
  1071. */
  1072. function get_user_overview_export_extra_fields($user_id)
  1073. {
  1074. // include the user manager
  1075. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  1076. $extra_data = UserManager::get_extra_user_data($user_id,true);
  1077. return $extra_data;
  1078. }
  1079. ?>