user.php 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays a list of the users of the current course.
  5. * Course admins can change user perimssions, subscribe and unsubscribe users...
  6. *
  7. * EXPERIMENTAL: support for virtual courses
  8. * - show users registered in virtual and real courses;
  9. * - only show the users of a virtual course if the current user;
  10. * is registered in that virtual course.
  11. *
  12. * Exceptions: platform admin and the course admin will see all virtual courses.
  13. * This is a new feature, there may be bugs.
  14. *
  15. * @todo possibility to edit user-course rights and view statistics for users in virtual courses
  16. * @todo convert normal table display to display function (refactor virtual course display function)
  17. * @todo display table functions need support for align and valign (e.g. to center text in cells) (this is now possible)
  18. * @author Roan Embrechts, refactoring + virtual courses support
  19. * @author Julio Montoya Armas, Several fixes
  20. * @package chamilo.user
  21. */
  22. /**
  23. * Code
  24. */
  25. // name of the language file that needs to be included
  26. $language_file = array('registration', 'admin', 'userInfo');
  27. $use_anonymous = true;
  28. require_once '../inc/global.inc.php';
  29. $this_section = SECTION_COURSES;
  30. // notice for unauthorized people.
  31. api_protect_course_script(true);
  32. /* Libraries */
  33. require_once api_get_path(LIBRARY_PATH).'export.lib.inc.php';
  34. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  35. global $_configuration;
  36. //CHECK KEYS
  37. if (!isset ($_cid)) {
  38. header('location: '.api_get_path(WEB_PATH));
  39. exit;
  40. }
  41. if (!api_is_platform_admin(true)) {
  42. if (!api_is_course_admin() && !api_is_coach()) {
  43. if (api_get_course_setting('allow_user_view_user_list') == 0) {
  44. api_not_allowed(true);
  45. }
  46. }
  47. }
  48. /*
  49. Constants and variables
  50. */
  51. $currentCourseID = Database::escape_string($_course['sysCode']);
  52. $is_western_name_order = api_is_western_name_order();
  53. $sort_by_first_name = api_sort_by_first_name();
  54. $course_info = api_get_course_info();
  55. /* Unregistering a user section */
  56. if (api_is_allowed_to_edit(null, true)) {
  57. if (isset($_POST['action'])) {
  58. switch ($_POST['action']) {
  59. case 'unsubscribe' :
  60. // Make sure we don't unsubscribe current user from the course
  61. if (is_array($_POST['user'])) {
  62. $user_ids = array_diff($_POST['user'], array($_user['user_id']));
  63. if (count($user_ids) > 0) {
  64. CourseManager::unsubscribe_user($user_ids, $_SESSION['_course']['sysCode']);
  65. $message = get_lang('UsersUnsubscribed');
  66. }
  67. }
  68. }
  69. }
  70. }
  71. if (api_is_allowed_to_edit(null, true)) {
  72. if ( isset ($_GET['action'])) {
  73. switch ($_GET['action']) {
  74. case 'export' :
  75. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  76. $table_users = Database::get_main_table(TABLE_MAIN_USER);
  77. $is_western_name_order = api_is_western_name_order();
  78. $data = array();
  79. $a_users = array();
  80. if ($_configuration['multiple_access_urls']) {
  81. $current_access_url_id = api_get_current_access_url_id();
  82. }
  83. $session_id = api_get_session_id();
  84. $extra_fields = UserManager::get_extra_user_data(api_get_user_id(), false, false, false, true);
  85. $extra_fields = array_keys($extra_fields);
  86. if ($sort_by_first_name) {
  87. $a_users[0] = array('id', get_lang('FirstName'), get_lang('LastName'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active'));
  88. } else {
  89. $a_users[0] = array('id', get_lang('LastName'), get_lang('FirstName'), get_lang('Email'), get_lang('Phone'), get_lang('OfficialCode'), get_lang('Active'));
  90. }
  91. $legal = '';
  92. if (isset($course_info['activate_legal']) AND $course_info['activate_legal'] == 1) {
  93. $legal = ', legal_agreement';
  94. $a_users[0][] = get_lang('Legal');
  95. }
  96. if ($_GET['type'] == 'pdf') {
  97. if ($is_western_name_order) {
  98. $a_users[0] = array('#', get_lang('OfficialCode'), get_lang('FirstName').', '.get_lang('LastName'));
  99. } else {
  100. $a_users[0] = array('#', get_lang('OfficialCode'), get_lang('LastName').', '.get_lang('FirstName'));
  101. }
  102. }
  103. $a_users[0] = array_merge($a_users[0], $extra_fields);
  104. // users subscribed to the course through a session
  105. if (api_get_setting('use_session_mode') == 'true') {
  106. if (api_get_session_id()) {
  107. $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  108. $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", user.email, phone, user.official_code, active $legal
  109. FROM $table_session_course_user as session_course_user, $table_users as user ";
  110. if ($_configuration['multiple_access_urls']) {
  111. $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
  112. }
  113. $sql_query .=" WHERE course_code = '$currentCourseID' AND session_course_user.id_user = user.user_id ";
  114. $sql_query .= ' AND id_session = '.$session_id;
  115. if ($_configuration['multiple_access_urls']) {
  116. $sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
  117. }
  118. //only users no coaches/teachers
  119. $sql_query .= " AND session_course_user.status = 0 ";
  120. $sql_query .= $sort_by_first_name ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname';
  121. $rs = Database::query($sql_query);
  122. $counter = 1;
  123. while ($user = Database:: fetch_array($rs, 'ASSOC')) {
  124. if (isset($user['legal_agreement'])) {
  125. if ($user['legal_agreement'] == 1) {
  126. $user['legal_agreement'] = get_lang('Yes');
  127. } else {
  128. $user['legal_agreement'] = get_lang('No');
  129. }
  130. }
  131. $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true);
  132. if (!empty($extra_fields)) {
  133. foreach($extra_fields as $key => $extra_value) {
  134. $user[$key] = $extra_value;
  135. }
  136. }
  137. $data[] = $user;
  138. if ($_GET['type'] == 'pdf') {
  139. if ($is_western_name_order) {
  140. $user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
  141. } else {
  142. $user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
  143. }
  144. $a_users[] = $user_pdf;
  145. } else {
  146. $a_users[] = $user;
  147. }
  148. $counter++;
  149. }
  150. }
  151. }
  152. if ($session_id == 0) {
  153. // users directly subscribed to the course
  154. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  155. $sql_query = "SELECT DISTINCT user.user_id, ".($is_western_name_order ? "user.firstname, user.lastname" : "user.lastname, user.firstname").", user.email, phone, user.official_code, active $legal
  156. FROM $table_course_user as course_user, $table_users as user ";
  157. if ($_configuration['multiple_access_urls']) {
  158. $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
  159. }
  160. $sql_query .= " WHERE course_code = '$currentCourseID' AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND course_user.user_id = user.user_id ";
  161. if ($_configuration['multiple_access_urls']) {
  162. $sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
  163. }
  164. //only users no teachers/coaches
  165. $sql_query .= " AND course_user.status = 5 ";
  166. $sql_query .= ($sort_by_first_name ? " ORDER BY user.firstname, user.lastname" : " ORDER BY user.lastname, user.firstname");
  167. $rs = Database::query($sql_query);
  168. $counter = 1;
  169. while ($user = Database::fetch_array($rs, 'ASSOC')) {
  170. if (isset($user['legal_agreement'])) {
  171. if ($user['legal_agreement'] == 1) {
  172. $user['legal_agreement'] = get_lang('Yes');
  173. } else {
  174. $user['legal_agreement'] = get_lang('No');
  175. }
  176. }
  177. $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true);
  178. if (!empty($extra_fields)) {
  179. foreach($extra_fields as $key => $extra_value) {
  180. $user[$key] = $extra_value;
  181. }
  182. }
  183. if ($_GET['type'] == 'pdf') {
  184. if ($is_western_name_order) {
  185. $user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
  186. } else {
  187. $user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
  188. }
  189. $a_users[] = $user_pdf;
  190. } else {
  191. $a_users[] = $user;
  192. }
  193. $data[] = $user;
  194. $counter++;
  195. }
  196. }
  197. switch ($_GET['type']) {
  198. case 'csv' :
  199. Export::export_table_csv($a_users);
  200. exit;
  201. case 'xls' :
  202. Export::export_table_xls($a_users);
  203. exit;
  204. case 'pdf' :
  205. $header = get_lang('StudentList');
  206. $description = '<table class="data_table_no_border">';
  207. if (api_get_session_id()) {
  208. $description .= '<tr><td>'.get_lang('Session').': </td><td class="highlight">'.api_get_session_name(api_get_session_id()).'</td>';
  209. }
  210. $description .= '<tr><td>'.get_lang('Course').': </td><td class="highlight">'.$course_info['name'].'</td>';
  211. $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']);
  212. $coaches = CourseManager::get_coach_list_from_course_code_to_string($course_info['code'], $session_id);
  213. if (!empty($teachers)) {
  214. $description .= '<tr><td>'.get_lang('Teachers').': </td><td class="highlight">'.$teachers.' </td>';
  215. }
  216. if (!empty($coaches)) {
  217. $description .= '<tr><td>'.get_lang('Coachs').': </td><td class="highlight">'.$coaches.' </td>';
  218. }
  219. $description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
  220. $description .= '</table>';
  221. $params = array();
  222. Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params);
  223. exit;
  224. }
  225. }
  226. }
  227. } // end if allowed to edit
  228. if (api_is_allowed_to_edit(null, true)) {
  229. // Unregister user from course
  230. if ($_REQUEST['unregister']) {
  231. if (isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $_GET['user_id'] != $_user['user_id']) {
  232. $user_id = Database::escape_string($_GET['user_id']);
  233. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  234. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  235. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  236. $sql = 'SELECT '.$tbl_user.'.user_id
  237. FROM '.$tbl_user.' user
  238. INNER JOIN '.$tbl_session_rel_user.' reluser
  239. ON user.user_id = reluser.id_user AND reluser.relation_type<>'.SESSION_RELATION_TYPE_RRHH.'
  240. INNER JOIN '.$tbl_session_rel_course.' rel_course
  241. ON rel_course.id_session = reluser.id_session
  242. WHERE user.user_id = "'.$user_id.'"
  243. AND rel_course.course_code = "'.$currentCourseID.'"';
  244. $result = Database::query($sql);
  245. $row = Database::fetch_array($result, 'ASSOC');
  246. if ($row['user_id'] == $user_id || $row['user_id'] == "") {
  247. CourseManager::unsubscribe_user($_GET['user_id'], $_SESSION['_course']['sysCode']);
  248. $message = get_lang('UserUnsubscribed');
  249. } else {
  250. $message = get_lang('ThisStudentIsSubscribeThroughASession');
  251. }
  252. }
  253. }
  254. } // end if allowed to edit
  255. /* FUNCTIONS */
  256. function display_user_search_form() {
  257. echo '<form method="get" action="user.php">';
  258. echo get_lang("SearchForUser") . "&nbsp;&nbsp;";
  259. echo '<input type="text" name="keyword" value="'.Security::remove_XSS($_GET['keyword']).'"/>';
  260. echo '<input type="submit" value="'.get_lang('SearchButton').'"/>';
  261. echo '</form>';
  262. }
  263. /**
  264. * This function displays a list if users for each virtual course linked to the current
  265. * real course.
  266. *
  267. * defines globals
  268. *
  269. * @version 1.0
  270. * @author Roan Embrechts
  271. * @todo users from virtual courses always show "-" for the group related output. Edit and statistics columns are disabled * for these users, for now.
  272. */
  273. /*
  274. function show_users_in_virtual_courses() {
  275. global $_course, $_user, $origin;
  276. $real_course_code = $_course['sysCode'];
  277. $real_course_info = Database::get_course_info($real_course_code);
  278. $user_subscribed_virtual_course_list = CourseManager::get_list_of_virtual_courses_for_specific_user_and_real_course($_user['user_id'], $real_course_code);
  279. $number_of_virtual_courses = count($user_subscribed_virtual_course_list);
  280. $row = 0;
  281. $column_header[$row++] = "ID";
  282. $column_header[$row++] = get_lang("FullUserName");
  283. $column_header[$row++] = get_lang("Role");
  284. $column_header[$row++] = get_lang("Group");
  285. if (api_is_allowed_to_edit()) {
  286. $column_header[$row++] = get_lang("Tutor");
  287. }
  288. if (api_is_allowed_to_edit()) {
  289. $column_header[$row++] = get_lang("CourseManager");
  290. }
  291. if (!is_array($user_subscribed_virtual_course_list)) {
  292. return;
  293. }
  294. foreach ($user_subscribed_virtual_course_list as $virtual_course) {
  295. $virtual_course_code = $virtual_course["code"];
  296. $virtual_course_user_list = CourseManager::get_user_list_from_course_code($virtual_course_code);
  297. $message = get_lang("RegisteredInVirtualCourse")." ".$virtual_course["title"]."&nbsp;&nbsp;(".$virtual_course["code"].")";
  298. echo "<br/>";
  299. echo "<h4>".$message."</h4>";
  300. $properties["width"] = "100%";
  301. $properties["cellspacing"] = "1";
  302. Display::display_complex_table_header($properties, $column_header);
  303. foreach ($virtual_course_user_list as $this_user) {
  304. $user_id = $this_user["user_id"];
  305. $loginname = $this_user["username"];
  306. $lastname = $this_user["lastname"];
  307. $firstname = $this_user["firstname"];
  308. $status = $this_user["status"];
  309. $role = $this_user["role"];
  310. if ($status == "1") {
  311. $status = get_lang("CourseManager");
  312. } else {
  313. $status = " - ";
  314. }
  315. $full_name = api_get_person_name($firstname, $lastname);
  316. if ($lastname == '' || $firstname == '') {
  317. $full_name = $loginname;
  318. }
  319. $user_info_hyperlink = "<a href=\"userInfo.php?".api_get_cidreq()."&origin=".$origin."&uInfo=".$user_id."&virtual_course=".$virtual_course["code"]."\">".$full_name."</a>";
  320. $row = 0;
  321. $table_row[$row++] = $user_id;
  322. $table_row[$row++] = $user_info_hyperlink; //Full name
  323. $table_row[$row++] = $role; //Description
  324. $table_row[$row++] = " - "; //Group, for the moment groups don't work for students in virtual courses
  325. if (api_is_allowed_to_edit()) {
  326. $table_row[$row ++] = " - "; //Tutor column
  327. $table_row[$row ++] = $status; //Course Manager column
  328. }
  329. Display::display_table_row(null, $table_row, true);
  330. }
  331. echo '</tbody></table>';
  332. }
  333. }*/
  334. if (!$is_allowed_in_course) {
  335. api_not_allowed(true);
  336. }
  337. /* Header */
  338. if ($origin != 'learnpath') {
  339. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  340. $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("Users"));
  341. $tool_name = get_lang('SearchResults');
  342. } else {
  343. $tool_name = get_lang('Users');
  344. $origin = 'users';
  345. }
  346. Display::display_header($tool_name, "User");
  347. } else {
  348. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH); ?>css/default.css" /> <?php
  349. }
  350. if (isset($message)) {
  351. Display::display_confirmation_message($message);
  352. }
  353. /* MAIN CODE*/
  354. //statistics
  355. event_access_tool(TOOL_USER);
  356. /* Setting the permissions for this page */
  357. $is_allowed_to_track = ($is_courseAdmin || $is_courseTutor);
  358. // Tool introduction
  359. Display::display_introduction_section(TOOL_USER, 'left');
  360. $actions = '';
  361. if ( api_is_allowed_to_edit(null, true)) {
  362. echo '<div class="actions">';
  363. // the action links
  364. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
  365. $actions .= '<a href="subscribe_user.php?'.api_get_cidreq().'">'.Display::return_icon('user_subscribe_course.png',get_lang("SubscribeUserToCourse"),'',ICON_SIZE_MEDIUM).'</a> ';
  366. $actions .= "<a href=\"subscribe_user.php?".api_get_cidreq()."&type=teacher\">".Display::return_icon('teacher_subscribe_course.png', get_lang("SubscribeUserToCourseAsTeacher"),'',ICON_SIZE_MEDIUM)."</a> ";
  367. }
  368. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=csv">'.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'',ICON_SIZE_MEDIUM).'</a> ';
  369. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a> ';
  370. if (!api_get_session_id()) {
  371. $actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import">'.Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'),'',ICON_SIZE_MEDIUM).'</a> ';
  372. }
  373. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&type=pdf">'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'',ICON_SIZE_MEDIUM).'</a> ';
  374. $actions .= "<a href=\"../group/group.php?".api_get_cidreq()."\">".Display::return_icon('group.png', get_lang("GroupUserManagement"),'',ICON_SIZE_MEDIUM)."</a>";
  375. if (api_get_setting('use_session_mode') == 'false') {
  376. $actions .= ' <a href="class.php?'.api_get_cidreq().'">'.get_lang('Classes').'</a>';
  377. }
  378. // Build search-form
  379. $form = new FormValidator('search_user', 'get', '', '', null, false);
  380. $renderer = & $form->defaultRenderer();
  381. $renderer->setElementTemplate('<span>{element}</span> ');
  382. $form->add_textfield('keyword', '', false);
  383. $form->addElement('style_submit_button', 'submit', get_lang('SearchButton'), 'class="search"');
  384. $form->addElement('static', 'additionalactions', null, $actions);
  385. $form->display();
  386. echo '</div>';
  387. }
  388. /*
  389. if (1) // platform setting api_get_setting('subscribe_user_by_coach') {
  390. if (!api_is_allowed_to_edit() && $is_courseTutor) {
  391. echo "<div align=\"right\">";
  392. echo '<a href="subscribe_user.php?'.api_get_cidreq().'">'.Display::return_icon('add_user_big.gif',get_lang("SubscribeUserToCourse")).'&nbsp;'.get_lang("SubscribeUserToCourse").'</a>';
  393. echo "</div>";
  394. }
  395. }*/
  396. /*
  397. DISPLAY USERS LIST
  398. Also shows a "next page" button if there are
  399. more than 50 users.
  400. There's a bug in here somewhere - some users count as more than one if they are in more than one group
  401. --> code for > 50 users should take this into account
  402. (Roan, Feb 2004)
  403. */
  404. /*
  405. * @todo seems not to affect anything in the code
  406. if (CourseManager::has_virtual_courses_from_code($course_id, $user_id)) {
  407. $real_course_code = $_course['sysCode'];
  408. $real_course_info = Database::get_course_info($real_course_code);
  409. $message = get_lang("RegisteredInRealCourse")." ".$real_course_info["title"]."&nbsp;&nbsp;(".$real_course_info["official_code"].")";
  410. echo "<h4>".$message."</h4>";
  411. }*/
  412. /*
  413. DISPLAY LIST OF USERS
  414. */
  415. /**
  416. * * Get the users to display on the current page.
  417. */
  418. function get_number_of_users() {
  419. $counter = 0;
  420. if (!empty($_SESSION["id_session"])){
  421. $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], $_SESSION['id_session']);
  422. } else {
  423. $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], 0);
  424. }
  425. foreach ($a_course_users as $user_id => $o_course_user) {
  426. if ((isset($_GET['keyword']) && search_keyword($o_course_user['firstname'], $o_course_user['lastname'], $o_course_user['username'], $o_course_user['official_code'], $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
  427. $counter++;
  428. }
  429. }
  430. return $counter;
  431. }
  432. function search_keyword($firstname, $lastname, $username, $official_code, $keyword) {
  433. if (api_strripos($firstname, $keyword) !== false || api_strripos($lastname, $keyword) !== false || api_strripos($username, $keyword) !== false || api_strripos($official_code, $keyword) !== false) {
  434. return true;
  435. } else {
  436. return false;
  437. }
  438. }
  439. /**
  440. * Get the users to display on the current page.
  441. */
  442. function get_user_data($from, $number_of_items, $column, $direction) {
  443. global $origin;
  444. global $is_western_name_order;
  445. global $sort_by_first_name;
  446. $a_users = array();
  447. // limit
  448. if (!isset($_GET['keyword']) || empty($_GET['keyword'])) {
  449. $limit = 'LIMIT '.intval($from).','.intval($number_of_items);
  450. }
  451. if (!in_array($direction, array('ASC', 'DESC'))) {
  452. $direction = 'ASC';
  453. }
  454. if (api_is_allowed_to_edit()) {
  455. $column--;
  456. }
  457. switch ($column) {
  458. case 1:
  459. $order_by = 'ORDER BY user.official_code '.$direction;
  460. break;
  461. case 2:
  462. if ($is_western_name_order) {
  463. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  464. } else {
  465. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  466. }
  467. break;
  468. case 3:
  469. if ($is_western_name_order) {
  470. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  471. } else {
  472. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  473. }
  474. break;
  475. case 4:
  476. $order_by = 'ORDER BY user.username '.$direction;
  477. break;
  478. default:
  479. if ($sort_by_first_name) {
  480. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  481. } else {
  482. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  483. }
  484. break;
  485. }
  486. if (!empty($_SESSION["id_session"])) {
  487. $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], $_SESSION['id_session'], $limit, $order_by);
  488. } else {
  489. $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], 0, $limit, $order_by);
  490. }
  491. foreach ($a_course_users as $user_id => $o_course_user) {
  492. if ((isset ($_GET['keyword']) && search_keyword($o_course_user['firstname'], $o_course_user['lastname'], $o_course_user['username'], $o_course_user['official_code'], $_GET['keyword'])) || !isset($_GET['keyword']) || empty($_GET['keyword'])) {
  493. $groups_name = GroupManager :: get_user_group_name($user_id);
  494. $temp = array();
  495. if (api_is_allowed_to_edit(null, true)) {
  496. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  497. $temp[] = $user_id;
  498. }
  499. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
  500. $user_profile = UserManager::get_picture_user($user_id, $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
  501. if (!api_is_anonymous()) {
  502. $photo = '<center><a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;uInfo='.$user_id.'" title="'.get_lang('Info').'" ><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" title="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" /></a></center>';
  503. } else {
  504. $photo = '<center><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" title="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" /></center>';
  505. }
  506. $temp[] = $photo;
  507. $temp[] = $o_course_user['official_code'];
  508. if ($is_western_name_order) {
  509. $temp[] = $o_course_user['firstname'];
  510. $temp[] = $o_course_user['lastname'];
  511. } else {
  512. $temp[] = $o_course_user['lastname'];
  513. $temp[] = $o_course_user['firstname'];
  514. }
  515. $temp[] = $o_course_user['username'];
  516. $temp[] = isset($o_course_user['role']) ? $o_course_user['role'] : null;
  517. $temp[] = implode(', ', $groups_name); //Group
  518. // deprecated feature
  519. if ((isset($o_course_user['status_rel']) && $o_course_user['status_rel'] == 1) || (isset($o_course_user['status_session']) && $o_course_user['status_session'] == 2)) {
  520. $temp[] = get_lang('CourseManager');
  521. } elseif (isset($o_course_user['tutor_id']) && $o_course_user['tutor_id'] == 1) {
  522. $temp[] = get_lang('Tutor');
  523. } else {
  524. $temp[] = '-';
  525. }
  526. $temp[] = $o_course_user['active'];
  527. $temp[] = $user_id;
  528. } else {
  529. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
  530. $image_repository = $image_path['dir'];
  531. $existing_image = $image_path['file'];
  532. if (!api_is_anonymous()) {
  533. $photo= '<center><a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;uInfo='.$user_id.'" title="'.get_lang('Info').'" ><img src="'.$image_repository.$existing_image.'" alt="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" width="22" height="22" title="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" /></a></center>';
  534. } else {
  535. $photo= '<center><img src="'.$image_repository.$existing_image.'" alt="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" width="22" height="22" title="'.api_get_person_name($o_course_user['firstname'], $o_course_user['lastname']).'" /></center>';
  536. }
  537. $temp[] = $photo;
  538. $temp[] = $o_course_user['official_code'];
  539. if ($is_western_name_order) {
  540. $temp[] = $o_course_user['firstname'];
  541. $temp[] = $o_course_user['lastname'];
  542. } else {
  543. $temp[] = $o_course_user['lastname'];
  544. $temp[] = $o_course_user['firstname'];
  545. }
  546. $temp[] = $o_course_user['username'];
  547. $temp[] = $o_course_user['role'];
  548. $temp[] = implode(', ', $groups_name);//Group
  549. //$temp[] = $o_course_user['official_code'];
  550. }
  551. $a_users[$user_id] = $temp;
  552. }
  553. }
  554. return $a_users;
  555. }
  556. /**
  557. * Build the active-column of the table to lock or unlock a certain user
  558. * lock = the user can no longer use this account
  559. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  560. * @param int $active the current state of the account
  561. * @param int $user_id The user id
  562. * @param string $url_params
  563. * @return string Some HTML-code with the lock/unlock button
  564. */
  565. function active_filter($active, $url_params, $row) {
  566. global $_user;
  567. if ($active=='1') {
  568. $action='AccountActive';
  569. $image='accept';
  570. }
  571. if ($active=='0') {
  572. $action='AccountInactive';
  573. $image='error';
  574. }
  575. $result = '';
  576. if ($row[count($row)-1]<>$_user['user_id']) { // you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore.
  577. $result = '<center><img src="../img/icons/16/'.$image.'.png" border="0" style="vertical-align: middle;" alt="'.get_lang(ucfirst($action)).'" title="'.get_lang(ucfirst($action)).'"/></center>';
  578. }
  579. return $result;
  580. }
  581. /**
  582. * Build the modify-column of the table
  583. * @param int $user_id The user id
  584. * @return string Some HTML-code
  585. */
  586. function modify_filter($user_id) {
  587. global $origin, $_user, $_course, $is_allowed_to_track, $charset;
  588. $result="<div style='text-align: center'>";
  589. if ($is_allowed_to_track) {
  590. $result .= '<a href="../mySpace/myStudents.php?'.api_get_cidreq().'&student='.$user_id.'&amp;details=true&amp;course='.$_course['id'].'&amp;origin=user_course&amp;id_session='.api_get_session_id().'" title="'.get_lang('Tracking').'" ><img border="0" alt="'.get_lang('Tracking').'" src="../img/icons/22/stats.png" /></a>';
  591. }
  592. if (api_is_allowed_to_edit(null, true)) {
  593. // edit
  594. $result .= '<a href="userInfo.php?'.api_get_cidreq().'&origin='.$origin.'&amp;editMainUserInfo='.$user_id.'" title="'.get_lang('Edit').'" >'.Display::return_icon('edit.png', get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  595. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
  596. // unregister
  597. if ($user_id != $_user['user_id']) {
  598. $result .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&unregister=yes&amp;user_id='.$user_id.'" title="'.get_lang('Unreg').' " onclick="javascript:if(!confirm(\''.addslashes(api_htmlentities(get_lang('ConfirmYourChoice'),ENT_QUOTES,$charset)).'\')) return false;">'.Display::return_icon('unsubscribe_course.png', get_lang('Unreg'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  599. } else {
  600. $result .= Display::return_icon('unsubscribe_course_na.png', get_lang('Unreg'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  601. }
  602. }
  603. }
  604. //if platform admin, show the login_as icon (this drastically shortens
  605. // time taken by support to test things out)
  606. if (api_is_platform_admin()) {
  607. $result .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
  608. }
  609. $result .= "</div>";
  610. return $result;
  611. }
  612. $default_column = ($is_western_name_order xor $sort_by_first_name) ? 3 : 2;
  613. $default_column = api_is_allowed_to_edit() ? 2 : 1;
  614. $table = new SortableTable('user_list', 'get_number_of_users', 'get_user_data', $default_column);
  615. $parameters['keyword'] = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  616. $table->set_additional_parameters($parameters);
  617. $header_nr = 0;
  618. if (api_is_allowed_to_edit(null, true)) {
  619. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  620. $table->set_header($header_nr++, '', false);
  621. }
  622. }
  623. $table->set_header($header_nr++, get_lang('Photo'), false);
  624. $table->set_header($header_nr++, get_lang('OfficialCode'));
  625. if ($is_western_name_order) {
  626. $table->set_header($header_nr++, get_lang('FirstName'));
  627. $table->set_header($header_nr++, get_lang('LastName'));
  628. } else {
  629. $table->set_header($header_nr++, get_lang('LastName'));
  630. $table->set_header($header_nr++, get_lang('FirstName'));
  631. }
  632. $table->set_header($header_nr++, get_lang('LoginName')); //
  633. $table->set_header($header_nr++, get_lang('Description'), false);
  634. $table->set_header($header_nr++, get_lang('GroupSingle'), false);
  635. if (api_is_allowed_to_edit(null, true)) {
  636. // deprecated feature
  637. //$table->set_header($header_nr++, get_lang('Tutor'), false);
  638. $table->set_header($header_nr++, get_lang('Status'), false);
  639. $table->set_header($header_nr++, get_lang('Active'), false);
  640. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  641. $table->set_column_filter(9, 'active_filter');
  642. } else {
  643. $table->set_column_filter(8, 'active_filter');
  644. }
  645. //actions column
  646. $table->set_header($header_nr++, get_lang('Action'), false);
  647. $table->set_column_filter($header_nr-1, 'modify_filter');
  648. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  649. $table->set_form_actions(array('unsubscribe' => get_lang('Unreg')), 'user');
  650. }
  651. }
  652. $table->display();
  653. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  654. $keyword_name = Security::remove_XSS($_GET['keyword']);
  655. echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  656. }
  657. if (api_get_setting('allow_user_headings') == 'true' && $is_courseAdmin && api_is_allowed_to_edit() && $origin != 'learnpath') { // only course administrators see this line
  658. echo "<div align=\"right\">", "<form method=\"post\" action=\"userInfo.php\">", get_lang("CourseAdministratorOnly"), " : ", "<input type=\"submit\" class=\"save\" name=\"viewDefList\" value=\"".get_lang("DefineHeadings")."\" />", "</form>", "</div>\n";
  659. }
  660. if ($origin != 'learnpath') {
  661. Display::display_footer();
  662. }