teachers.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Teachers report
  5. * @package chamilo.reporting
  6. */
  7. /**
  8. * Code
  9. */
  10. ob_start();
  11. // names of the language file that needs to be included
  12. $language_file = array ('registration', 'index', 'trad4all', 'tracking', 'admin');
  13. $cidReset = true;
  14. //require_once '../inc/global.inc.php';
  15. require_once 'myspace.lib.php';
  16. $this_section = SECTION_TRACKING;
  17. $nameTools = get_lang('Teachers');
  18. api_block_anonymous_users();
  19. $interbreadcrumb[] = array ("url" => "index.php", "name" => get_lang('MySpace'));
  20. Display :: display_header($nameTools);
  21. $formateurs = array();
  22. if (api_is_drh() || api_is_platform_admin()) {
  23. // followed teachers by drh
  24. $formateurs = UserManager::get_users_followed_by_drh($_user['user_id'], COURSEMANAGER);
  25. $menu_items = array();
  26. $menu_items[] = Display::url(Display::return_icon('stats.png', get_lang('MyStats'),'',ICON_SIZE_MEDIUM),api_get_path(WEB_CODE_PATH)."auth/my_progress.php" );
  27. $menu_items[] = Display::url(Display::return_icon('user.png', get_lang('Students'), array(), 32), "index.php?view=drh_students&amp;display=yourstudents");
  28. $menu_items[] = Display::return_icon('teacher_na.png', get_lang('Trainers'), array(), 32);
  29. $menu_items[] = Display::url(Display::return_icon('course.png', get_lang('Courses'), array(), 32), 'course.php');
  30. $menu_items[] = Display::url(Display::return_icon('session.png', get_lang('Sessions'), array(), 32), 'session.php');
  31. echo '<div class="actions">';
  32. $nb_menu_items = count($menu_items);
  33. if ($nb_menu_items > 1) {
  34. foreach ($menu_items as $key => $item) {
  35. echo $item;
  36. }
  37. }
  38. if (count($formateurs) > 0) {
  39. echo '<span style="float:right">';
  40. echo Display::url(Display::return_icon('printer.png', get_lang('Print'), array(), 32), 'javascript: void(0);', array('onclick'=>'javascript: window.print();'));
  41. echo Display::url(Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), array(), 32), api_get_self().'?export=xls');
  42. echo '</span>';
  43. }
  44. echo '</div>';
  45. echo Display::page_subheader(get_lang('YourTeachers'));
  46. }
  47. if (!api_is_drh()) {
  48. api_display_tool_title($nameTools);
  49. }
  50. /**
  51. * MAIN PART
  52. */
  53. if (isset($_POST['export'])) {
  54. $is_western_name_order = api_is_western_name_order(PERSON_NAME_DATA_EXPORT);
  55. } else {
  56. $is_western_name_order = api_is_western_name_order();
  57. }
  58. $sort_by_first_name = api_sort_by_first_name();
  59. if (!api_is_drh() && !api_is_platform_admin()) {
  60. $order_clause = $sort_by_first_name ? ' ORDER BY firstname, lastname' : ' ORDER BY lastname, firstname';
  61. if (isset($_GET["teacher_id"]) && $_GET["teacher_id"] != 0) {
  62. $teacher_id = intval($_GET["teacher_id"]);
  63. $sql_formateurs = "SELECT user_id,lastname,firstname,email
  64. FROM $tbl_user
  65. WHERE user_id='$teacher_id'".$order_clause;
  66. } else {
  67. $sql_formateurs = "SELECT user_id,lastname,firstname,email
  68. FROM $tbl_user
  69. WHERE status = 1".$order_clause;
  70. }
  71. $result_formateurs = Database::query($sql_formateurs);
  72. if (Database::num_rows($result_formateurs) > 0) {
  73. while ($row_formateurs = Database::fetch_array($result_formateurs)) {
  74. $formateurs[] = $row_formateurs;
  75. }
  76. }
  77. }
  78. $time_filter = 'last_7_days';
  79. $time_label = sprintf(get_lang('TimeSpentLastXDays'), 7);
  80. $form = new FormValidator('time_filter');
  81. $form->addElement('datepickerdate', 'start_date', get_lang('StartDate'), array('form_name'=>'exercise_admin'));
  82. $form->addElement('datepickerdate', 'end_date', get_lang('EndDate'), array('form_name'=>'exercise_admin'));
  83. $form->addRule('start_date', get_lang('InvalidDate'), 'date');
  84. $form->addRule('end_date', get_lang('InvalidDate'), 'date');
  85. $form->addRule(array ('start_date', 'end_date'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
  86. $defaults = array();
  87. $defaults['start_date'] = date('Y-m-d 12:00:00', strtotime("-7 days"));
  88. $defaults['end_date'] = date('Y-m-d 12:00:00',time());
  89. $start_date = $end_date = null;
  90. if ($form->validate()) {
  91. $values = $form->exportValues();
  92. $start_date = $defaults['start_date'] = $values['start_date'];
  93. $end_date = $defaults['end_date'] = $values['end_date'];
  94. $time_filter = 'custom';
  95. $time_label = sprintf(get_lang('TimeSpentBetweenXAndY'), $start_date, $end_date);
  96. }
  97. $form->setDefaults($defaults);
  98. $form->addelement('style_submit_button', 'submit', get_lang('Filter'));
  99. $form->display();
  100. if ($is_western_name_order) {
  101. echo '<table class="data_table"><tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.$time_label.'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
  102. } else {
  103. echo '<table class="data_table"><tr><th>'.get_lang('LastName').'</th><th>'.get_lang('FirstName').'</th><th>'.$time_label.'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
  104. }
  105. if ($is_western_name_order) {
  106. $header[] = get_lang('FirstName');
  107. $header[] = get_lang('LastName');
  108. } else {
  109. $header[] = get_lang('LastName');
  110. $header[] = get_lang('FirstName');
  111. }
  112. $header[] = $time_label;
  113. $header[] = get_lang('Email');
  114. $data = array();
  115. if (count($formateurs) > 0) {
  116. $i = 1;
  117. foreach ($formateurs as $formateur) {
  118. $user_id = $formateur["user_id"];
  119. $lastname = $formateur["lastname"];
  120. $firstname = $formateur["firstname"];
  121. $email = $formateur["email"];
  122. if ($i % 2 == 0) {
  123. $css_class = "row_odd";
  124. if ($i % 20 == 0 && $i != 0) {
  125. if ($is_western_name_order) {
  126. echo '<tr><th>'.get_lang('FirstName').'</th><th>'.get_lang('LastName').'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
  127. } else {
  128. echo '<tr><th>'.get_lang('LastName').'</th><th>'.get_lang('FirstName').'</th><th>'.get_lang('Email').'</th><th>'.get_lang('AdminCourses').'</th><th>'.get_lang('Students').'</th></tr>';
  129. }
  130. }
  131. } else {
  132. $css_class = "row_even";
  133. }
  134. $i++;
  135. if ($is_western_name_order) {
  136. $data[$user_id]["firstname"] = $firstname;
  137. $data[$user_id]["lastname"] = $lastname;
  138. } else {
  139. $data[$user_id]["lastname"] = $lastname;
  140. $data[$user_id]["firstname"] = $firstname;
  141. }
  142. $time_on_platform = api_time_to_hms(Tracking :: get_time_spent_on_the_platform($user_id, $time_filter, $start_date, $end_date));
  143. $data[$user_id]["timespentlastweek"] = $time_on_platform;
  144. $data[$user_id]["email"] = $email;
  145. if ($is_western_name_order) {
  146. echo '<tr class="'.$css_class.'"><td>'.$firstname.'</td><td>'.$lastname.'</td><td align="right">'.$time_on_platform.'</td><td align="right"><a href="mailto:'.$email.'">'.$email.'</a></td><td align="right"><a href="course.php?user_id='.$user_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td><td align="right"><a href="student.php?user_id='.$user_id.'&amp;display=yourstudents"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td></tr>';
  147. } else {
  148. echo '<tr class="'.$css_class.'"><td>'.$lastname.'</td><td>'.$firstname.'</td><td align="right">'.$time_on_platform.'</td><td align="right"><a href="mailto:'.$email.'">'.$email.'</a></td><td align="right"><a href="course.php?user_id='.$user_id.'"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td><td align="right"><a href="student.php?user_id='.$user_id.'&amp;display=yourstudents"><img src="'.api_get_path(WEB_IMG_PATH).'2rightarrow.gif" border="0" /></a></td></tr>';
  149. }
  150. }
  151. } else {
  152. // No results
  153. echo '<tr><td colspan="6">'.get_lang("NoResults").'</td></tr>';
  154. }
  155. echo '</table>';
  156. if (isset($_POST['export']) || (api_is_drh() && isset($_GET['export']))) {
  157. MySpace::export_csv($header, $data, 'teachers.csv');
  158. }
  159. if (!api_is_drh()) {
  160. echo "<form method='post' action='teachers.php'>
  161. <input type='submit' class='btn' name='export' value='".get_lang('exportExcel')."'/>
  162. <form>";
  163. }
  164. Display::display_footer();