user.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722
  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. if ($_GET['type'] == 'pdf') {
  92. if ($is_western_name_order) {
  93. $a_users[0] = array('#', get_lang('OfficialCode'), get_lang('FirstName').', '.get_lang('LastName'));
  94. } else {
  95. $a_users[0] = array('#', get_lang('OfficialCode'), get_lang('LastName').', '.get_lang('FirstName'));
  96. }
  97. }
  98. $a_users[0] = array_merge($a_users[0], $extra_fields);
  99. // users subscribed to the course through a session
  100. if (api_get_setting('use_session_mode') == 'true') {
  101. if (api_get_session_id()) {
  102. $table_session_course_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  103. $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
  104. FROM $table_session_course_user as session_course_user, $table_users as user ";
  105. if ($_configuration['multiple_access_urls']) {
  106. $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
  107. }
  108. $sql_query .=" WHERE course_code = '$currentCourseID' AND session_course_user.id_user = user.user_id ";
  109. $sql_query .= ' AND id_session = '.$session_id;
  110. if ($_configuration['multiple_access_urls']) {
  111. $sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
  112. }
  113. //only users no coaches/teachers
  114. $sql_query .= " AND session_course_user.status = 0 ";
  115. $sql_query .= $sort_by_first_name ? ' ORDER BY user.firstname, user.lastname' : ' ORDER BY user.lastname, user.firstname';
  116. $rs = Database::query($sql_query);
  117. $counter = 1;
  118. while ($user = Database:: fetch_array($rs, 'ASSOC')) {
  119. $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true);
  120. if (!empty($extra_fields)) {
  121. foreach($extra_fields as $key => $extra_value) {
  122. $user[$key] = $extra_value;
  123. }
  124. }
  125. $data[] = $user;
  126. if ($_GET['type'] == 'pdf') {
  127. if ($is_western_name_order) {
  128. $user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
  129. } else {
  130. $user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
  131. }
  132. $a_users[] = $user_pdf;
  133. } else {
  134. $a_users[] = $user;
  135. }
  136. $counter++;
  137. }
  138. }
  139. }
  140. if ($session_id == 0) {
  141. // users directly subscribed to the course
  142. $table_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  143. $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
  144. FROM $table_course_user as course_user, $table_users as user ";
  145. if ($_configuration['multiple_access_urls']) {
  146. $sql_query .= ' , '.Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER).' au ';
  147. }
  148. $sql_query .= " WHERE course_code = '$currentCourseID' AND course_user.relation_type<>".COURSE_RELATION_TYPE_RRHH." AND course_user.user_id = user.user_id ";
  149. if ($_configuration['multiple_access_urls']) {
  150. $sql_query .= " AND user.user_id = au.user_id AND access_url_id = $current_access_url_id ";
  151. }
  152. //only users no teachers/coaches
  153. $sql_query .= " AND course_user.status = 5 ";
  154. $sql_query .= ($sort_by_first_name ? " ORDER BY user.firstname, user.lastname" : " ORDER BY user.lastname, user.firstname");
  155. $rs = Database::query($sql_query);
  156. $counter = 1;
  157. while ($user = Database::fetch_array($rs, 'ASSOC')) {
  158. $extra_fields = UserManager::get_extra_user_data($user['user_id'], false, false, false, true);
  159. if (!empty($extra_fields)) {
  160. foreach($extra_fields as $key => $extra_value) {
  161. $user[$key] = $extra_value;
  162. }
  163. }
  164. if ($_GET['type'] == 'pdf') {
  165. if ($is_western_name_order) {
  166. $user_pdf = array($counter, $user['official_code'], $user['firstname'].', '.$user['lastname'] );
  167. } else {
  168. $user_pdf = array($counter, $user['official_code'], $user['lastname'].', '.$user['firstname'] );
  169. }
  170. $a_users[] = $user_pdf;
  171. } else {
  172. $a_users[] = $user;
  173. }
  174. $data[] = $user;
  175. $counter++;
  176. }
  177. }
  178. switch ($_GET['type']) {
  179. case 'csv' :
  180. Export::export_table_csv($a_users);
  181. exit;
  182. case 'xls' :
  183. Export::export_table_xls($a_users);
  184. exit;
  185. case 'pdf' :
  186. $header = get_lang('StudentList');
  187. $description = '<table class="data_table_no_border">';
  188. if (api_get_session_id()) {
  189. $description .= '<tr><td>'.get_lang('Session').': </td><td class="highlight">'.api_get_session_name(api_get_session_id()).'</td>';
  190. }
  191. $description .= '<tr><td>'.get_lang('Course').': </td><td class="highlight">'.$course_info['name'].'</td>';
  192. $teachers = CourseManager::get_teacher_list_from_course_code_to_string($course_info['code']);
  193. if (!empty($teachers)) {
  194. $description .= '<tr><td>'.get_lang('Teachers').': </td><td class="highlight">'.$teachers.'</td>';
  195. }
  196. $description .= '<tr><td>'.get_lang('Date').': </td><td class="highlight">'.api_convert_and_format_date(time(), DATE_TIME_FORMAT_LONG).'</td>';
  197. $description .= '</table>';
  198. $params = array();
  199. //$params = array('top'=>'50');
  200. Export::export_table_pdf($a_users, get_lang('UserList'), $header, $description, $params);
  201. exit;
  202. }
  203. }
  204. }
  205. } // end if allowed to edit
  206. if (api_is_allowed_to_edit(null, true)) {
  207. // Unregister user from course
  208. if ($_REQUEST['unregister']) {
  209. if (isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $_GET['user_id'] != $_user['user_id']) {
  210. $user_id = Database::escape_string($_GET['user_id']);
  211. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  212. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  213. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  214. $sql = 'SELECT '.$tbl_user.'.user_id
  215. FROM '.$tbl_user.' user
  216. INNER JOIN '.$tbl_session_rel_user.' reluser
  217. ON user.user_id = reluser.id_user AND reluser.relation_type<>'.SESSION_RELATION_TYPE_RRHH.'
  218. INNER JOIN '.$tbl_session_rel_course.' rel_course
  219. ON rel_course.id_session = reluser.id_session
  220. WHERE user.user_id = "'.$user_id.'"
  221. AND rel_course.course_code = "'.$currentCourseID.'"';
  222. $result = Database::query($sql);
  223. $row = Database::fetch_array($result, 'ASSOC');
  224. if ($row['user_id'] == $user_id || $row['user_id'] == "") {
  225. CourseManager::unsubscribe_user($_GET['user_id'], $_SESSION['_course']['sysCode']);
  226. $message = get_lang('UserUnsubscribed');
  227. } else {
  228. $message = get_lang('ThisStudentIsSubscribeThroughASession');
  229. }
  230. }
  231. }
  232. } // end if allowed to edit
  233. /* FUNCTIONS */
  234. function display_user_search_form() {
  235. echo '<form method="get" action="user.php">';
  236. echo get_lang("SearchForUser") . "&nbsp;&nbsp;";
  237. echo '<input type="text" name="keyword" value="'.Security::remove_XSS($_GET['keyword']).'"/>';
  238. echo '<input type="submit" value="'.get_lang('SearchButton').'"/>';
  239. echo '</form>';
  240. }
  241. /**
  242. * This function displays a list if users for each virtual course linked to the current
  243. * real course.
  244. *
  245. * defines globals
  246. *
  247. * @version 1.0
  248. * @author Roan Embrechts
  249. * @todo users from virtual courses always show "-" for the group related output. Edit and statistics columns are disabled * for these users, for now.
  250. */
  251. /*
  252. function show_users_in_virtual_courses() {
  253. global $_course, $_user, $origin;
  254. $real_course_code = $_course['sysCode'];
  255. $real_course_info = Database::get_course_info($real_course_code);
  256. $user_subscribed_virtual_course_list = CourseManager::get_list_of_virtual_courses_for_specific_user_and_real_course($_user['user_id'], $real_course_code);
  257. $number_of_virtual_courses = count($user_subscribed_virtual_course_list);
  258. $row = 0;
  259. $column_header[$row++] = "ID";
  260. $column_header[$row++] = get_lang("FullUserName");
  261. $column_header[$row++] = get_lang("Role");
  262. $column_header[$row++] = get_lang("Group");
  263. if (api_is_allowed_to_edit()) {
  264. $column_header[$row++] = get_lang("Tutor");
  265. }
  266. if (api_is_allowed_to_edit()) {
  267. $column_header[$row++] = get_lang("CourseManager");
  268. }
  269. if (!is_array($user_subscribed_virtual_course_list)) {
  270. return;
  271. }
  272. foreach ($user_subscribed_virtual_course_list as $virtual_course) {
  273. $virtual_course_code = $virtual_course["code"];
  274. $virtual_course_user_list = CourseManager::get_user_list_from_course_code($virtual_course_code);
  275. $message = get_lang("RegisteredInVirtualCourse")." ".$virtual_course["title"]."&nbsp;&nbsp;(".$virtual_course["code"].")";
  276. echo "<br/>";
  277. echo "<h4>".$message."</h4>";
  278. $properties["width"] = "100%";
  279. $properties["cellspacing"] = "1";
  280. Display::display_complex_table_header($properties, $column_header);
  281. foreach ($virtual_course_user_list as $this_user) {
  282. $user_id = $this_user["user_id"];
  283. $loginname = $this_user["username"];
  284. $lastname = $this_user["lastname"];
  285. $firstname = $this_user["firstname"];
  286. $status = $this_user["status"];
  287. $role = $this_user["role"];
  288. if ($status == "1") {
  289. $status = get_lang("CourseManager");
  290. } else {
  291. $status = " - ";
  292. }
  293. $full_name = api_get_person_name($firstname, $lastname);
  294. if ($lastname == '' || $firstname == '') {
  295. $full_name = $loginname;
  296. }
  297. $user_info_hyperlink = "<a href=\"userInfo.php?".api_get_cidreq()."&origin=".$origin."&uInfo=".$user_id."&virtual_course=".$virtual_course["code"]."\">".$full_name."</a>";
  298. $row = 0;
  299. $table_row[$row++] = $user_id;
  300. $table_row[$row++] = $user_info_hyperlink; //Full name
  301. $table_row[$row++] = $role; //Description
  302. $table_row[$row++] = " - "; //Group, for the moment groups don't work for students in virtual courses
  303. if (api_is_allowed_to_edit()) {
  304. $table_row[$row ++] = " - "; //Tutor column
  305. $table_row[$row ++] = $status; //Course Manager column
  306. }
  307. Display::display_table_row(null, $table_row, true);
  308. }
  309. echo '</tbody></table>';
  310. }
  311. }*/
  312. if (!$is_allowed_in_course) {
  313. api_not_allowed(true);
  314. }
  315. /* Header */
  316. if ($origin != 'learnpath') {
  317. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  318. $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("Users"));
  319. $tool_name = get_lang('SearchResults');
  320. } else {
  321. $tool_name = get_lang('Users');
  322. $origin = 'users';
  323. }
  324. Display::display_header($tool_name, "User");
  325. } else {
  326. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH); ?>css/default.css" /> <?php
  327. }
  328. if (isset($message)) {
  329. Display::display_confirmation_message($message);
  330. }
  331. /* MAIN CODE*/
  332. //statistics
  333. event_access_tool(TOOL_USER);
  334. /* Setting the permissions for this page */
  335. $is_allowed_to_track = ($is_courseAdmin || $is_courseTutor);
  336. // Tool introduction
  337. Display::display_introduction_section(TOOL_USER, 'left');
  338. $actions = '';
  339. if ( api_is_allowed_to_edit(null, true)) {
  340. echo '<div class="actions">';
  341. // the action links
  342. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
  343. $actions .= '<a href="subscribe_user.php?'.api_get_cidreq().'">'.Display::return_icon('user_subscribe_course.png',get_lang("SubscribeUserToCourse"),'','32').'</a> ';
  344. $actions .= "<a href=\"subscribe_user.php?".api_get_cidreq()."&type=teacher\">".Display::return_icon('teacher_subscribe_course.png', get_lang("SubscribeUserToCourseAsTeacher"),'','32')."</a> ";
  345. }
  346. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=csv">'.Display::return_icon('export_csv.png', get_lang('ExportAsCSV'),'','32').'</a> ';
  347. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&amp;type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'','32').'</a> ';
  348. if (!api_get_session_id()) {
  349. $actions .= '<a href="user_import.php?'.api_get_cidreq().'&action=import">'.Display::return_icon('import_csv.png', get_lang('ImportUsersToACourse'),'','32').'</a> ';
  350. }
  351. $actions .= '<a href="user.php?'.api_get_cidreq().'&action=export&type=pdf">'.Display::return_icon('pdf.png', get_lang('ExportToPDF'),'','32').'</a> ';
  352. $actions .= "<a href=\"../group/group.php?".api_get_cidreq()."\">".Display::return_icon('group.png', get_lang("GroupUserManagement"),'','32')."</a>";
  353. if (api_get_setting('use_session_mode') == 'false') {
  354. $actions .= ' <a href="class.php?'.api_get_cidreq().'">'.get_lang('Classes').'</a>';
  355. }
  356. // Build search-form
  357. $form = new FormValidator('search_user', 'get', '', '', null, false);
  358. $renderer = & $form->defaultRenderer();
  359. $renderer->setElementTemplate('<span>{element}</span> ');
  360. $form->add_textfield('keyword', '', false);
  361. $form->addElement('style_submit_button', 'submit', get_lang('SearchButton'), 'class="search"');
  362. $form->addElement('static', 'additionalactions', null, $actions);
  363. $form->display();
  364. echo '</div>';
  365. }
  366. /*
  367. if (1) // platform setting api_get_setting('subscribe_user_by_coach') {
  368. if (!api_is_allowed_to_edit() && $is_courseTutor) {
  369. echo "<div align=\"right\">";
  370. echo '<a href="subscribe_user.php?'.api_get_cidreq().'">'.Display::return_icon('add_user_big.gif',get_lang("SubscribeUserToCourse")).'&nbsp;'.get_lang("SubscribeUserToCourse").'</a>';
  371. echo "</div>";
  372. }
  373. }*/
  374. /*
  375. DISPLAY USERS LIST
  376. Also shows a "next page" button if there are
  377. more than 50 users.
  378. There's a bug in here somewhere - some users count as more than one if they are in more than one group
  379. --> code for > 50 users should take this into account
  380. (Roan, Feb 2004)
  381. */
  382. /*
  383. * @todo seems not to affect anything in the code
  384. if (CourseManager::has_virtual_courses_from_code($course_id, $user_id)) {
  385. $real_course_code = $_course['sysCode'];
  386. $real_course_info = Database::get_course_info($real_course_code);
  387. $message = get_lang("RegisteredInRealCourse")." ".$real_course_info["title"]."&nbsp;&nbsp;(".$real_course_info["official_code"].")";
  388. echo "<h4>".$message."</h4>";
  389. }*/
  390. /*
  391. DISPLAY LIST OF USERS
  392. */
  393. /**
  394. * * Get the users to display on the current page.
  395. */
  396. function get_number_of_users() {
  397. $counter = 0;
  398. if (!empty($_SESSION["id_session"])){
  399. $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], true, $_SESSION['id_session']);
  400. } else {
  401. $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], false);
  402. }
  403. foreach ($a_course_users as $user_id => $o_course_user) {
  404. 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'])) {
  405. $counter++;
  406. }
  407. }
  408. return $counter;
  409. }
  410. function search_keyword($firstname, $lastname, $username, $official_code, $keyword) {
  411. if (api_strripos($firstname, $keyword) !== false || api_strripos($lastname, $keyword) !== false || api_strripos($username, $keyword) !== false || api_strripos($official_code, $keyword) !== false) {
  412. return true;
  413. } else {
  414. return false;
  415. }
  416. }
  417. /**
  418. * Get the users to display on the current page.
  419. */
  420. function get_user_data($from, $number_of_items, $column, $direction) {
  421. global $origin;
  422. global $is_western_name_order;
  423. global $sort_by_first_name;
  424. $a_users = array();
  425. // limit
  426. if (!isset($_GET['keyword']) || empty($_GET['keyword'])) {
  427. $limit = 'LIMIT '.intval($from).','.intval($number_of_items);
  428. }
  429. if (!in_array($direction, array('ASC', 'DESC'))) {
  430. $direction = 'ASC';
  431. }
  432. // order by
  433. if (api_is_allowed_to_edit()) {
  434. $column--;
  435. }
  436. switch ($column) {
  437. case 1:
  438. if ($is_western_name_order) {
  439. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  440. } else {
  441. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  442. }
  443. break;
  444. case 2:
  445. if ($is_western_name_order) {
  446. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  447. } else {
  448. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  449. }
  450. break;
  451. case 5:
  452. $order_by = 'ORDER BY user.official_code '.$direction;
  453. break;
  454. default:
  455. if ($sort_by_first_name) {
  456. $order_by = 'ORDER BY user.firstname '.$direction.', user.lastname '.$direction;
  457. } else {
  458. $order_by = 'ORDER BY user.lastname '.$direction.', user.firstname '.$direction;
  459. }
  460. break;
  461. }
  462. if (!empty($_SESSION["id_session"])) {
  463. $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], true, $_SESSION['id_session'], $limit, $order_by);
  464. } else {
  465. $a_course_users = CourseManager :: get_user_list_from_course_code($_SESSION['_course']['id'], false, 0, $limit, $order_by);
  466. }
  467. foreach ($a_course_users as $user_id => $o_course_user) {
  468. 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'])) {
  469. $groups_name = GroupManager :: get_user_group_name($user_id);
  470. $temp = array();
  471. if (api_is_allowed_to_edit(null, true)) {
  472. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  473. $temp[] = $user_id;
  474. }
  475. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
  476. $user_profile = UserManager::get_picture_user($user_id, $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
  477. if (!api_is_anonymous()) {
  478. $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>';
  479. } else {
  480. $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>';
  481. }
  482. $temp[] = $photo;
  483. $temp[] = $o_course_user['official_code'];
  484. if ($is_western_name_order) {
  485. $temp[] = $o_course_user['firstname'];
  486. $temp[] = $o_course_user['lastname'];
  487. } else {
  488. $temp[] = $o_course_user['lastname'];
  489. $temp[] = $o_course_user['firstname'];
  490. }
  491. $temp[] = $o_course_user['username']; //
  492. $temp[] = isset($o_course_user['role']) ? $o_course_user['role'] : null;
  493. $temp[] = implode(', ', $groups_name); //Group
  494. // deprecated feature
  495. 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)) {
  496. $temp[] = get_lang('CourseManager');
  497. } elseif (isset($o_course_user['tutor_id']) && $o_course_user['tutor_id'] == 1) {
  498. $temp[] = get_lang('Tutor');
  499. } else {
  500. $temp[] = '-';
  501. }
  502. $temp[] = $o_course_user['active'];
  503. $temp[] = $user_id;
  504. } else {
  505. $image_path = UserManager::get_user_picture_path_by_id($user_id, 'web', false, true);
  506. $image_repository = $image_path['dir'];
  507. $existing_image = $image_path['file'];
  508. if (!api_is_anonymous()) {
  509. $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>';
  510. } else {
  511. $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>';
  512. }
  513. $temp[] = $photo;
  514. if ($is_western_name_order) {
  515. $temp[] = $o_course_user['firstname'];
  516. $temp[] = $o_course_user['lastname'];
  517. } else {
  518. $temp[] = $o_course_user['lastname'];
  519. $temp[] = $o_course_user['firstname'];
  520. }
  521. $temp[] = $o_course_user['role'];
  522. $temp[] = implode(', ', $groups_name);//Group
  523. $temp[] = $o_course_user['official_code'];
  524. }
  525. $a_users[$user_id] = $temp;
  526. }
  527. }
  528. return $a_users;
  529. }
  530. /**
  531. * Build the active-column of the table to lock or unlock a certain user
  532. * lock = the user can no longer use this account
  533. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  534. * @param int $active the current state of the account
  535. * @param int $user_id The user id
  536. * @param string $url_params
  537. * @return string Some HTML-code with the lock/unlock button
  538. */
  539. function active_filter($active, $url_params, $row) {
  540. global $_user;
  541. if ($active=='1') {
  542. $action='AccountActive';
  543. $image='accept';
  544. }
  545. if ($active=='0') {
  546. $action='AccountInactive';
  547. $image='error';
  548. }
  549. $result = '';
  550. 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.
  551. $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>';
  552. }
  553. return $result;
  554. }
  555. /**
  556. * Build the modify-column of the table
  557. * @param int $user_id The user id
  558. * @return string Some HTML-code
  559. */
  560. function modify_filter($user_id) {
  561. global $origin, $_user, $_course, $is_allowed_to_track, $charset;
  562. $result="<div style='text-align: center'>";
  563. if ($is_allowed_to_track) {
  564. $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>';
  565. }
  566. if (api_is_allowed_to_edit(null, true)) {
  567. // edit
  568. $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'),'','22').'</a>&nbsp;';
  569. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true' or api_is_platform_admin()) {
  570. // unregister
  571. if ($user_id != $_user['user_id']) {
  572. $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'),'','22').'</a>&nbsp;';
  573. } else {
  574. $result .= Display::return_icon('unsubscribe_course_na.png', get_lang('Unreg'),'','22').'</a>&nbsp;';
  575. }
  576. }
  577. }
  578. $result .= "</div>";
  579. return $result;
  580. }
  581. $default_column = ($is_western_name_order xor $sort_by_first_name) ? 3 : 2;
  582. $default_column = api_is_allowed_to_edit() ? 2 : 1;
  583. $table = new SortableTable('user_list', 'get_number_of_users', 'get_user_data', $default_column);
  584. $parameters['keyword'] = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : null;
  585. $table->set_additional_parameters($parameters);
  586. $header_nr = 0;
  587. if (api_is_allowed_to_edit(null, true)) {
  588. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  589. $table->set_header($header_nr++, '', false);
  590. }
  591. }
  592. $table->set_header($header_nr++, get_lang('Photo'), false);
  593. $table->set_header($header_nr++, get_lang('OfficialCode'));
  594. if ($is_western_name_order) {
  595. $table->set_header($header_nr++, get_lang('FirstName'));
  596. $table->set_header($header_nr++, get_lang('LastName'));
  597. } else {
  598. $table->set_header($header_nr++, get_lang('LastName'));
  599. $table->set_header($header_nr++, get_lang('FirstName'));
  600. }
  601. $table->set_header($header_nr++, get_lang('LoginName')); //
  602. $table->set_header($header_nr++, get_lang('Description'), false);
  603. $table->set_header($header_nr++, get_lang('GroupSingle'), false);
  604. if (api_is_allowed_to_edit(null, true)) {
  605. // deprecated feature
  606. //$table->set_header($header_nr++, get_lang('Tutor'), false);
  607. $table->set_header($header_nr++, get_lang('Status'), false);
  608. $table->set_header($header_nr++, get_lang('Active'), false);
  609. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  610. $table->set_column_filter(9, 'active_filter');
  611. } else {
  612. $table->set_column_filter(8, 'active_filter');
  613. }
  614. //actions column
  615. $table->set_header($header_nr++, get_lang('Action'), false);
  616. $table->set_column_filter($header_nr-1, 'modify_filter');
  617. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'true') {
  618. $table->set_form_actions(array('unsubscribe' => get_lang('Unreg')), 'user');
  619. }
  620. }
  621. $table->display();
  622. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  623. $keyword_name = Security::remove_XSS($_GET['keyword']);
  624. echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  625. }
  626. if (api_get_setting('allow_user_headings') == 'true' && $is_courseAdmin && api_is_allowed_to_edit() && $origin != 'learnpath') { // only course administrators see this line
  627. 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";
  628. }
  629. if ($origin != 'learnpath') {
  630. Display::display_footer();
  631. }