user.php 27 KB

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