user.php 26 KB

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