user.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. <?php
  2. /* For licensing terms, see /dokeos_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, __FILE__, __LINE__);
  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.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, __FILE__, __LINE__);
  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. case 'xls' :
  122. Export::export_table_xls($a_users);
  123. }
  124. }
  125. }
  126. } // end if allowed to edit
  127. if (api_is_allowed_to_edit()) {
  128. // Unregister user from course
  129. if ($_REQUEST['unregister']) {
  130. if (isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $_GET['user_id'] != $_user['user_id']) {
  131. $user_id = Database::escape_string($_GET['user_id']);
  132. $tbl_user = Database::get_main_table(TABLE_MAIN_USER);
  133. $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE);
  134. $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER);
  135. $sql = 'SELECT '.$tbl_user.'.user_id
  136. FROM '.$tbl_user.' user
  137. INNER JOIN '.$tbl_session_rel_user.' reluser
  138. ON user.user_id = reluser.id_user
  139. INNER JOIN '.$tbl_session_rel_course.' rel_course
  140. ON rel_course.id_session = reluser.id_session
  141. WHERE user.user_id = "'.$user_id.'"
  142. AND rel_course.course_code = "'.$currentCourseID.'"';
  143. $result = Database::query($sql, __FILE__ ,__LINE__);
  144. $row = Database::fetch_array($result, 'ASSOC');
  145. if ($row['user_id'] == $user_id || $row['user_id'] == "") {
  146. CourseManager::unsubscribe_user($_GET['user_id'], $_SESSION['_course']['sysCode']);
  147. $message = get_lang('UserUnsubscribed');
  148. } else {
  149. $message = get_lang('ThisStudentIsSubscribeThroughASession');
  150. }
  151. }
  152. }
  153. } // end if allowed to edit
  154. /*
  155. ==============================================================================
  156. FUNCTIONS
  157. ==============================================================================
  158. */
  159. function display_user_search_form() {
  160. echo '<form method="get" action="user.php">';
  161. echo get_lang("SearchForUser") . "&nbsp;&nbsp;";
  162. echo '<input type="text" name="keyword" value="'.$_GET['keyword'].'"/>';
  163. echo '<input type="submit" value="'.get_lang('SearchButton').'"/>';
  164. echo '</form>';
  165. }
  166. /**
  167. * This function displays a list if users for each virtual course linked to the current
  168. * real course.
  169. *
  170. * defines globals
  171. *
  172. * @version 1.0
  173. * @author Roan Embrechts
  174. * @todo users from virtual courses always show "-" for the group related output. Edit and statistics columns are disabled * for these users, for now.
  175. */
  176. function show_users_in_virtual_courses() {
  177. global $_course, $_user, $origin;
  178. $real_course_code = $_course['sysCode'];
  179. $real_course_info = Database::get_course_info($real_course_code);
  180. $user_subscribed_virtual_course_list = CourseManager::get_list_of_virtual_courses_for_specific_user_and_real_course($_user['user_id'], $real_course_code);
  181. $number_of_virtual_courses = count($user_subscribed_virtual_course_list);
  182. $row = 0;
  183. $column_header[$row++] = "ID";
  184. $column_header[$row++] = get_lang("FullUserName");
  185. $column_header[$row++] = get_lang("Role");
  186. $column_header[$row++] = get_lang("Group");
  187. if (api_is_allowed_to_edit()) {
  188. $column_header[$row++] = get_lang("Tutor");
  189. }
  190. if (api_is_allowed_to_edit()) {
  191. $column_header[$row++] = get_lang("CourseManager");
  192. }
  193. if (!is_array($user_subscribed_virtual_course_list)) {
  194. return;
  195. }
  196. foreach ($user_subscribed_virtual_course_list as $virtual_course) {
  197. $virtual_course_code = $virtual_course["code"];
  198. $virtual_course_user_list = CourseManager::get_user_list_from_course_code($virtual_course_code);
  199. $message = get_lang("RegisteredInVirtualCourse")." ".$virtual_course["title"]."&nbsp;&nbsp;(".$virtual_course["code"].")";
  200. echo "<br/>";
  201. echo "<h4>".$message."</h4>";
  202. $properties["width"] = "100%";
  203. $properties["cellspacing"] = "1";
  204. Display::display_complex_table_header($properties, $column_header);
  205. foreach ($virtual_course_user_list as $this_user) {
  206. $user_id = $this_user["user_id"];
  207. $loginname = $this_user["username"];
  208. $lastname = $this_user["lastname"];
  209. $firstname = $this_user["firstname"];
  210. $status = $this_user["status"];
  211. $role = $this_user["role"];
  212. if ($status == "1") {
  213. $status = get_lang("CourseManager");
  214. } else {
  215. $status = " - ";
  216. }
  217. $full_name = api_get_person_name($firstname, $lastname);
  218. if ($lastname == '' || $firstname == '') {
  219. $full_name = $loginname;
  220. }
  221. $user_info_hyperlink = "<a href=\"userInfo.php?".api_get_cidreq()."&origin=".$origin."&uInfo=".$user_id."&virtual_course=".$virtual_course["code"]."\">".$full_name."</a>";
  222. $row = 0;
  223. $table_row[$row++] = $user_id;
  224. $table_row[$row++] = $user_info_hyperlink; //Full name
  225. $table_row[$row++] = $role; //Description
  226. $table_row[$row++] = " - "; //Group, for the moment groups don't work for students in virtual courses
  227. if (api_is_allowed_to_edit()) {
  228. $table_row[$row ++] = " - "; //Tutor column
  229. $table_row[$row ++] = $status; //Course Manager column
  230. }
  231. Display::display_table_row(null, $table_row, true);
  232. }
  233. Display::display_table_footer();
  234. }
  235. }
  236. if (!$is_allowed_in_course) {
  237. api_not_allowed(true);
  238. }
  239. /*
  240. -----------------------------------------------------------
  241. Header
  242. -----------------------------------------------------------
  243. */
  244. if ($origin != 'learnpath') {
  245. if (isset($_GET['keyword'])) {
  246. $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("Users"));
  247. $tool_name = get_lang('SearchResults');
  248. } else {
  249. $tool_name = get_lang('Users');
  250. }
  251. Display::display_header($tool_name, "User");
  252. } else {
  253. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH); ?>css/default.css" /> <?php
  254. }
  255. if (isset($message)) {
  256. Display::display_normal_message($message);
  257. }
  258. /*
  259. ==============================================================================
  260. MAIN CODE
  261. ==============================================================================
  262. */
  263. //statistics
  264. event_access_tool(TOOL_USER);
  265. /*
  266. --------------------------------------
  267. Setting the permissions for this page
  268. --------------------------------------
  269. */
  270. $is_allowed_to_track = ($is_courseAdmin || $is_courseTutor) && $_configuration['tracking_enabled'];
  271. // Tool introduction
  272. Display::display_introduction_section(TOOL_USER, 'left');
  273. if ( api_is_allowed_to_edit()) {
  274. echo "<div class=\"actions\">";
  275. // the action links
  276. $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> ';
  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'], true);
  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, '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) {
  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('users', 'get_number_of_users', 'get_user_data', $default_column);
  514. $parameters['keyword'] = $_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('Modify'), 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 (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\" 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. }