user.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <?php
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. * This script displays a list of the users of the current course.
  22. * Course admins can change user perimssions, subscribe and unsubscribe users...
  23. *
  24. * EXPERIMENTAL: support for virtual courses
  25. * - show users registered in virtual and real courses;
  26. * - only show the users of a virtual course if the current user;
  27. * is registered in that virtual course.
  28. *
  29. * Exceptions: platform admin and the course admin will see all virtual courses.
  30. * This is a new feature, there may be bugs.
  31. *
  32. * @todo possibility to edit user-course rights and view statistics for users in virtual courses
  33. * @todo convert normal table display to display function (refactor virtual course display function)
  34. * @todo display table functions need support for align and valign (e.g. to center text in cells) (this is now possible)
  35. * @author Roan Embrechts, refactoring + virtual courses support
  36. * @package dokeos.user
  37. ==============================================================================
  38. */
  39. /*
  40. ==============================================================================
  41. INIT SECTION
  42. ==============================================================================
  43. */
  44. // name of the language file that needs to be included
  45. $language_file = array('registration','admin');
  46. require_once ("../inc/global.inc.php");
  47. $this_section = SECTION_COURSES;
  48. /*
  49. -----------------------------------------------------------
  50. Libraries
  51. -----------------------------------------------------------
  52. */
  53. require_once (api_get_path(LIBRARY_PATH)."debug.lib.inc.php");
  54. require_once (api_get_path(LIBRARY_PATH)."events.lib.inc.php");
  55. require_once (api_get_path(LIBRARY_PATH)."export.lib.inc.php");
  56. require_once (api_get_path(LIBRARY_PATH)."course.lib.php");
  57. require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  58. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  59. //CHECK KEYS
  60. if( !isset ($_cid))
  61. {
  62. header("location: ".$_configuration['root_web']);
  63. }
  64. /*
  65. -----------------------------------------------------------
  66. Constants and variables
  67. -----------------------------------------------------------
  68. */
  69. $currentCourseID = $_course['sysCode'];
  70. /*--------------------------------------
  71. Unregistering a user section
  72. --------------------------------------
  73. */
  74. if(api_is_allowed_to_edit())
  75. {
  76. if(isset($_POST['action']))
  77. {
  78. switch($_POST['action'])
  79. {
  80. case 'unsubscribe' :
  81. // Make sure we don't unsubscribe current user from the course
  82. $user_ids = array_diff($_POST['user'],array($_user['user_id']));
  83. if(count($user_ids) > 0)
  84. {
  85. CourseManager::unsubscribe_user($user_ids, $_SESSION['_course']['sysCode']);
  86. $message = get_lang('UsersUnsubscribed');
  87. }
  88. break;
  89. }
  90. }
  91. }
  92. if(api_is_allowed_to_edit())
  93. {
  94. if( isset ($_GET['action']))
  95. {
  96. switch ($_GET['action'])
  97. {
  98. case 'export' :
  99. if(api_get_setting('use_session_mode')!="true"){
  100. $table_user = Database::get_main_table(TABLE_MAIN_USER);
  101. $table_course_user = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  102. $course = api_get_course_info();
  103. $sql = "SELECT official_code,firstname,lastname,email FROM $table_user u, $table_course_user cu WHERE cu.user_id = u.user_id AND cu.course_code = '".$course['sysCode']."' ORDER BY lastname ASC";
  104. }
  105. else
  106. {
  107. $sql = "SELECT `user`.`user_id`, `user`.`lastname`, `user`.`firstname`,
  108. `user`.`email`, `user`.`official_code`, session.name
  109. FROM ".Database::get_main_table(TABLE_MAIN_USER)." `user`, ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." cu, ".Database::get_main_table(TABLE_MAIN_SESSION)." session
  110. WHERE `user`.`user_id`= cu.`id_user`
  111. AND cu.`course_code`='".$currentCourseID."'
  112. AND session.id=cu.id_session
  113. AND session.id='".$_SESSION['id_session']."'";
  114. }
  115. $users = api_sql_query($sql, __FILE__, __LINE__);
  116. while ($user = mysql_fetch_array($users, MYSQL_ASSOC))
  117. {
  118. $data[] = $user;
  119. }
  120. switch ($_GET['type'])
  121. {
  122. case 'csv' :
  123. Export::export_table_csv($data);
  124. case 'xls' :
  125. Export::export_table_xls($data);
  126. }
  127. }
  128. }
  129. } // end if allowed to edit
  130. if(api_is_allowed_to_edit())
  131. {
  132. // Unregister user from course
  133. if($_GET['unregister'])
  134. {
  135. if(isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $_GET['user_id'] != $_user['user_id'])
  136. {
  137. CourseManager::unsubscribe_user($_GET['user_id'],$_SESSION['_course']['sysCode']);
  138. $message = get_lang('UserUnsubscribed');
  139. }
  140. }
  141. } // end if allowed to edit
  142. /*
  143. ==============================================================================
  144. FUNCTIONS
  145. ==============================================================================
  146. */
  147. function display_user_search_form()
  148. {
  149. echo '<form method="get" action="user.php">';
  150. echo get_lang("SearchForUser") . "&nbsp;&nbsp;";
  151. echo '<input type="text" name="keyword" value="'.$_GET['keyword'].'"/>';
  152. echo '<input type="submit" value="'.get_lang('SearchButton').'"/>';
  153. echo '</form>';
  154. }
  155. /**
  156. * This function displays a list if users for each virtual course linked to the current
  157. * real course.
  158. *
  159. * defines globals
  160. *
  161. * @version 1.0
  162. * @author Roan Embrechts
  163. * @todo users from virtual courses always show "-" for the group related output. Edit and statistics columns are disabled * for these users, for now.
  164. */
  165. function show_users_in_virtual_courses()
  166. {
  167. global $_course, $_user;
  168. $real_course_code = $_course['sysCode'];
  169. $real_course_info = Database::get_course_info($real_course_code);
  170. $user_subscribed_virtual_course_list = CourseManager::get_list_of_virtual_courses_for_specific_user_and_real_course($_user['user_id'], $real_course_code);
  171. $number_of_virtual_courses = count($user_subscribed_virtual_course_list);
  172. $row = 0;
  173. $column_header[$row ++] = "ID";
  174. $column_header[$row ++] = get_lang("FullUserName");
  175. $column_header[$row ++] = get_lang("Role");
  176. $column_header[$row ++] = get_lang("Group");
  177. if( api_is_allowed_to_edit())
  178. {
  179. $column_header[$row ++] = get_lang("Tutor");
  180. }
  181. if( api_is_allowed_to_edit())
  182. {
  183. $column_header[$row ++] = get_lang("CourseManager");
  184. }
  185. //$column_header[$row++] = get_lang("Edit");
  186. //$column_header[$row++] = get_lang("Unreg");
  187. //$column_header[$row++] = get_lang("Tracking");
  188. if( !is_array($user_subscribed_virtual_course_list))
  189. return;
  190. foreach ($user_subscribed_virtual_course_list as $virtual_course)
  191. {
  192. $virtual_course_code = $virtual_course["code"];
  193. $virtual_course_user_list = CourseManager::get_user_list_from_course_code($virtual_course_code);
  194. $message = get_lang("RegisteredInVirtualCourse")." ".$virtual_course["title"]."&nbsp;&nbsp;(".$virtual_course["code"].")";
  195. echo "<br/>";
  196. echo "<h4>".$message."</h4>";
  197. $properties["width"] = "100%";
  198. $properties["cellspacing"] = "1";
  199. Display::display_complex_table_header($properties, $column_header);
  200. foreach ($virtual_course_user_list as $this_user)
  201. {
  202. $user_id = $this_user["user_id"];
  203. $loginname = $this_user["username"];
  204. $lastname = $this_user["lastname"];
  205. $firstname = $this_user["firstname"];
  206. $status = $this_user["status"];
  207. $role = $this_user["role"];
  208. if( $status == "1")
  209. $status = get_lang("CourseManager");
  210. else
  211. $status = " - ";
  212. //if(xxx['tutor'] == '0') $tutor = " - ";
  213. //else $tutor = get_lang("Tutor");
  214. $full_name = $lastname.", ".$firstname;
  215. if( $lastname == "" || $firstname == '')
  216. $full_name = $loginname;
  217. $user_info_hyperlink = "<a href=\"userInfo.php?".api_get_cidreq()."&origin=".$origin."&uInfo=".$user_id."&virtual_course=".$virtual_course["code"]."\">".$full_name."</a>";
  218. $row = 0;
  219. $table_row[$row ++] = $user_id;
  220. $table_row[$row ++] = $user_info_hyperlink; //Full name
  221. $table_row[$row ++] = $role; //Description
  222. $table_row[$row ++] = " - "; //Group, for the moment groups don't work for students in virtual courses
  223. if( api_is_allowed_to_edit())
  224. $table_row[$row ++] = " - "; //Tutor column
  225. if( api_is_allowed_to_edit())
  226. $table_row[$row ++] = $status; //Course Manager column
  227. Display::display_table_row($bgcolor, $table_row, true);
  228. }
  229. Display::display_table_footer();
  230. }
  231. }
  232. /*
  233. -----------------------------------------------------------
  234. Header
  235. -----------------------------------------------------------
  236. */
  237. if( $origin != 'learnpath')
  238. {
  239. if (isset($_GET['keyword']))
  240. {
  241. $interbreadcrumb[] = array ("url" => "user.php", "name" => get_lang("Users"));
  242. $tool_name = get_lang('SearchResults');
  243. }
  244. else
  245. {
  246. $tool_name = get_lang('Users');
  247. }
  248. Display::display_header($tool_name, "User");
  249. }
  250. else
  251. {
  252. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH); ?>css/default.css" /> <?php
  253. }
  254. if( isset($message))
  255. {
  256. Display::display_normal_message($message);
  257. }
  258. /*
  259. ==============================================================================
  260. MAIN CODE
  261. ==============================================================================
  262. */
  263. if(!$is_allowed_in_course){
  264. api_not_allowed();
  265. }
  266. //statistics
  267. event_access_tool(TOOL_USER);
  268. /*
  269. --------------------------------------
  270. Setting the permissions for this page
  271. --------------------------------------
  272. */
  273. $is_allowed_to_track = ($is_courseAdmin || $is_courseTutor) && $_configuration['tracking_enabled'];
  274. /*
  275. /*
  276. -----------------------------------------------------------
  277. Introduction section
  278. (editable by course admins)
  279. -----------------------------------------------------------
  280. */
  281. Display::display_introduction_section(TOOL_USER, $is_allowed);
  282. if( api_is_allowed_to_edit())
  283. {
  284. echo "<div align=\"right\">";
  285. echo '<a href="user.php?action=export&type=csv"><img align="absbottom" src="../img/excel.gif">&nbsp;'.get_lang('ExportAsCSV').'</a> | ';
  286. echo "<a href=\"subscribe_user.php\"><img align='absbottom' src='../img/add_user_big.gif'>&nbsp;".get_lang("SubscribeUserToCourse")."</a> | ";
  287. echo "<a href=\"../group/group.php?".api_get_cidreq()."\"><img align='absbottom' src='../img/edit_group.gif'>&nbsp;".get_lang("GroupUserManagement")."</a>";
  288. if(api_get_setting('use_session_mode')=='false')
  289. {
  290. echo ' | <a href="class.php">'.get_lang('Classes').'</a>';
  291. }
  292. echo "</div>";
  293. }
  294. /*
  295. --------------------------------------
  296. DISPLAY USERS LIST
  297. --------------------------------------
  298. Also shows a "next page" button if there are
  299. more than 50 users.
  300. There's a bug in here somewhere - some users count as more than one if they are in more than one group
  301. --> code for > 50 users should take this into account
  302. (Roan, Feb 2004)
  303. */
  304. if( CourseManager::has_virtual_courses_from_code($course_id, $user_id))
  305. {
  306. $real_course_code = $_course['sysCode'];
  307. $real_course_info = Database::get_course_info($real_course_code);
  308. $message = get_lang("RegisteredInRealCourse")." ".$real_course_info["title"]."&nbsp;&nbsp;(".$real_course_info["official_code"].")";
  309. echo "<h4>".$message."</h4>";
  310. }
  311. /*
  312. ==============================================================================
  313. DISPLAY LIST OF USERS
  314. ==============================================================================
  315. */
  316. /**
  317. * * Get the users to display on the current page.
  318. */
  319. function get_number_of_users()
  320. {
  321. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  322. $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  323. if(api_get_setting('use_session_mode')!="true"){
  324. $sql = "SELECT COUNT(u.user_id) AS number_of_users FROM $user_table u,$course_user_table cu WHERE u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'";
  325. }
  326. else{
  327. if(!empty($_SESSION['id_session'])){
  328. $session_course_user_table = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  329. $sql = "SELECT COUNT(DISTINCT id_user) AS number_of_users
  330. FROM $user_table u, $session_course_user_table
  331. WHERE course_code= '".$_SESSION['_course']['id']."'
  332. AND id_session='".$_SESSION['id_session']."'";
  333. }
  334. else{
  335. $sql = "SELECT COUNT(u.user_id) AS number_of_users FROM $user_table u,$course_user_table cu WHERE u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'";
  336. }
  337. }
  338. if( isset ($_GET['keyword']))
  339. {
  340. $keyword = mysql_real_escape_string($_GET['keyword']);
  341. $sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
  342. }
  343. $res = api_sql_query($sql, __FILE__, __LINE__);
  344. $result = mysql_fetch_object($res);
  345. return $result->number_of_users;
  346. }
  347. /**
  348. * Get the users to display on the current page.
  349. */
  350. function get_user_data($from, $number_of_items, $column, $direction)
  351. {
  352. global $is_allowed_to_track;
  353. //It's a teacher in the current course; We display all the students of the course (as if the course belong to no sessions)
  354. if($_SESSION["is_courseAdmin"] || $_SESSION["is_platformAdmin"]){
  355. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  356. $course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  357. $columns[] = 'u.user_id';
  358. $columns[] = 'u.official_code';
  359. $columns[] = 'u.firstname';
  360. $columns[] = 'u.lastname';
  361. $columns[] = 'cu.role';
  362. $columns[] = "''"; //placeholder for group-data
  363. $columns[] = "IF(cu.tutor_id = 1,'".get_lang('Tutor')."','')";
  364. $columns[] = "IF(cu.status = 1,'".get_lang('CourseManager')."','')";
  365. $columns[] = 'u.user_id';
  366. $sql = "SELECT ";
  367. foreach( $columns as $index => $sqlcolumn)
  368. {
  369. $columns[$index] = ' '.$sqlcolumn.' AS col'.$index.' ';
  370. }
  371. $sql .= implode(" , ", $columns);
  372. $sql .= "FROM $user_table u,$course_user_table cu WHERE u.user_id = cu.user_id and course_code='".$_SESSION['_course']['id']."'";
  373. if( isset ($_GET['keyword']))
  374. {
  375. $keyword = mysql_real_escape_string($_GET['keyword']);
  376. $sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
  377. }
  378. $sql .= " ORDER BY col$column $direction ";
  379. $sql .= " LIMIT $from, $number_of_items";
  380. $res = api_sql_query($sql, __FILE__, __LINE__);
  381. $users = array();
  382. $user_ids = array();
  383. while($user = mysql_fetch_row($res))
  384. {
  385. $users[''.$user[0]] = $user;
  386. $user_ids[] = $user[0];
  387. }
  388. $sql = "
  389. SELECT
  390. ug.user_id,
  391. ug.group_id group_id,
  392. sg.name
  393. FROM " . Database::get_course_table(TABLE_GROUP_USER) . " ug
  394. LEFT JOIN " . Database::get_course_table(TABLE_GROUP) . " sg ON ug.group_id = sg.id
  395. WHERE ug.user_id IN ('".implode("','", $user_ids)."')";
  396. $res = api_sql_query($sql,__FILE__,__LINE__);
  397. while($group = mysql_fetch_object($res))
  398. {
  399. $users[''.$group->user_id][5] .= $group->name.'<br />';
  400. }
  401. //Sessions
  402. $columns=array();
  403. $columns[] = 'u.user_id';
  404. $columns[] = 'u.official_code';
  405. $columns[] = 'u.firstname';
  406. $columns[] = 'u.lastname';
  407. $columns[] = "''";
  408. $columns[] = "''"; //placeholder for group-data
  409. $columns[] = "''";
  410. $columns[] = "''";
  411. $columns[] = 'u.user_id';
  412. $sql = "SELECT ".implode(',',$columns)."
  413. FROM ".Database::get_main_table(TABLE_MAIN_USER)." `u`, ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." c
  414. WHERE `u`.`user_id`= c.`id_user`
  415. AND c.`course_code`='".$_SESSION['_course']['id']."'
  416. ";
  417. if( isset ($_GET['keyword']))
  418. {
  419. $keyword = mysql_real_escape_string($_GET['keyword']);
  420. $sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
  421. }
  422. $res = api_sql_query($sql, __FILE__, __LINE__);
  423. while ($user = mysql_fetch_row($res))
  424. {
  425. $users[''.$user[0]] = $user;
  426. $user_ids[] = $user[0];
  427. }
  428. }
  429. //Sudent or coach
  430. else
  431. {
  432. //We are coach
  433. if($_SESSION["is_courseTutor"]){
  434. $columns = array();
  435. if(api_is_allowed_to_edit())
  436. {
  437. $columns[] = 'u.user_id';
  438. }
  439. $columns[] = 'u.official_code';
  440. $columns[] = 'u.firstname';
  441. $columns[] = 'u.lastname';
  442. $columns[] = '""';
  443. $columns[] = "''"; //placeholder for group-data
  444. if(api_is_allowed_to_edit())
  445. {
  446. $columns[] = "''";
  447. $columns[] = "''";
  448. }
  449. $columns[] = 'u.user_id';
  450. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  451. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  452. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  453. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  454. $sql="SELECT ".implode(',',$columns)."
  455. FROM $tbl_session_course_user as srcru, $tbl_user as u
  456. WHERE srcru.course_code='".$_SESSION['_course']['id']."' AND srcru.id_user=u.user_id
  457. ";
  458. $res = api_sql_query($sql, __FILE__, __LINE__);
  459. while ($user = mysql_fetch_array($res))
  460. {
  461. $users[''.$user["user_id"]] = $user;
  462. $user_ids[] = $user["user_id"];
  463. }
  464. }
  465. else
  466. {
  467. $columns = array();
  468. if(api_is_allowed_to_edit())
  469. {
  470. $columns[] = 'u.user_id';
  471. }
  472. $columns[] = 'u.official_code';
  473. $columns[] = 'u.firstname';
  474. $columns[] = 'u.lastname';
  475. $columns[] = '""';
  476. $columns[] = "''"; //placeholder for group-data
  477. if(api_is_allowed_to_edit())
  478. {
  479. $columns[] = "''";
  480. $columns[] = "''";
  481. }
  482. $columns[] = 'u.user_id';
  483. $tbl_session_course_user = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE_USER);
  484. $tbl_course_user = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  485. $tbl_user = Database :: get_main_table(TABLE_MAIN_USER);
  486. $tbl_session_course = Database :: get_main_table(TABLE_MAIN_SESSION_COURSE);
  487. if(empty($_SESSION["id_session"]))
  488. {
  489. $sql="SELECT ";
  490. foreach( $columns as $index => $sqlcolumn)
  491. {
  492. $columns[$index] = ' '.$sqlcolumn.' AS col'.$index.' ';
  493. }
  494. $sql .= implode(" , ", $columns);
  495. $sql .= "FROM $tbl_course_user as cu, $tbl_user as u
  496. WHERE cu.course_code='".$_SESSION['_course']['id']."' AND cu.user_id=u.user_id
  497. ";
  498. }
  499. else
  500. {
  501. $sql="SELECT ";
  502. foreach( $columns as $index => $sqlcolumn)
  503. {
  504. $columns[$index] = ' '.$sqlcolumn.' AS col'.$index.' ';
  505. }
  506. $sql .= implode(" , ", $columns);
  507. $sql .= "FROM $tbl_session_course_user as srcru, $tbl_user as u
  508. WHERE srcru.course_code='".$_SESSION['_course']['id']."' AND srcru.id_user=u.user_id";
  509. }
  510. if( isset ($_GET['keyword']))
  511. {
  512. $keyword = mysql_real_escape_string($_GET['keyword']);
  513. $sql .= " AND (firstname LIKE '%".$keyword."%' OR lastname LIKE '%".$keyword."%' OR username LIKE '%".$keyword."%' OR official_code LIKE '%".$keyword."%')";
  514. }
  515. $sql .= " ORDER BY col$column $direction ";
  516. $sql .= " LIMIT $from, $number_of_items";
  517. $res = api_sql_query($sql, __FILE__, __LINE__);
  518. while ($user = mysql_fetch_array($res))
  519. {
  520. $users[''.$user[0]] = $user;
  521. $user_ids[] = $user["user_id"];
  522. }
  523. }
  524. }
  525. return $users;
  526. }
  527. /**
  528. * Build the modify-column of the table
  529. * @param int $user_id The user id
  530. * @return string Some HTML-code
  531. */
  532. function modify_filter($user_id)
  533. {
  534. global $origin,$_user,$is_allowed_to_track;
  535. $result="<div style='text-align: center'>";
  536. // info
  537. $result .= '<a href="userInfo.php?origin='.$origin.'&amp;uInfo='.$user_id.'"><img border="0" alt="'.get_lang('Info').'" src="../img/user_info.gif" /></a>&nbsp;';
  538. if($is_allowed_to_track)
  539. {
  540. $result .= '<a href="../tracking/userLog.php?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;uInfo='.$user_id.'"><img border="0" alt="'.get_lang('Tracking').'" src="../img/statistics.gif" /></a>&nbsp;';
  541. }
  542. if(api_is_allowed_to_edit())
  543. {
  544. // edit
  545. $result .= '<a href="userInfo.php?origin='.$origin.'&amp;editMainUserInfo='.$user_id.'"><img border="0" alt="'.get_lang('Edit').'" src="../img/edit.gif" /></a>&nbsp;';
  546. // unregister
  547. if( $user_id != $_user['user_id'])
  548. {
  549. $result .= '<a href="'.$_SERVER['PHP_SELF'].'?unregister=yes&amp;user_id='.$user_id.'&amp;'.$sort_params.'" onclick="javascript:if(!confirm(\''.addslashes(htmlentities(get_lang('ConfirmYourChoice'))).'\')) return false;"><img border="0" alt="'.get_lang("Unreg").'" src="../img/delete.gif"/></a>';
  550. }
  551. }
  552. $result.="</div>";
  553. return $result;
  554. }
  555. $default_column = api_is_allowed_to_edit() ? 2 : 1;
  556. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data',$default_column);
  557. $parameters['keyword'] = $_GET['keyword'];
  558. $table->set_additional_parameters($parameters);
  559. $header_nr = 0;
  560. if( api_is_allowed_to_edit())
  561. {
  562. $table->set_header($header_nr++, '', false);
  563. }
  564. $table->set_header($header_nr++, get_lang('OfficialCode'));
  565. $table->set_header($header_nr++, get_lang('FirstName'));
  566. $table->set_header($header_nr++, get_lang('LastName'));
  567. $table->set_header($header_nr++, get_lang('Role'));
  568. $table->set_header($header_nr++, get_lang('Group'),false);
  569. if( api_is_allowed_to_edit())
  570. {
  571. $table->set_header($header_nr++, get_lang('Tutor'));
  572. $table->set_header($header_nr++, get_lang('CourseManager'));
  573. }
  574. //actions column
  575. $table->set_header($header_nr++, '', false);
  576. $table->set_column_filter($header_nr-1,'modify_filter');
  577. if( api_is_allowed_to_edit())
  578. {
  579. $table->set_form_actions(array ('unsubscribe' => get_lang('Unreg')), 'user');
  580. }
  581. // Build search-form
  582. $form = new FormValidator('search_user', 'get','','',null,false);
  583. $renderer = & $form->defaultRenderer();
  584. $renderer->setElementTemplate('<span>{element}</span> ');
  585. $form->add_textfield('keyword', '', false);
  586. $form->addElement('submit', 'submit', get_lang('SearchButton'));
  587. $form->display();
  588. echo '<br />';
  589. $table->display();
  590. if( get_setting('allow_user_headings') == 'true' && $is_courseAdmin && api_is_allowed_to_edit() && $origin != 'learnpath') // only course administrators see this line
  591. {
  592. 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";
  593. }
  594. //User list of the virtual courses linked to this course.
  595. //show_users_in_virtual_courses($is_allowed_to_track);
  596. /*
  597. ==============================================================================
  598. FOOTER
  599. ==============================================================================
  600. */
  601. if( $origin != 'learnpath')
  602. {
  603. Display::display_footer();
  604. }
  605. ?>