user.php 24 KB

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