user.php 25 KB

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