user.php 25 KB

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