user_list.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php // $Id: user_list.php 14848 2008-04-11 13:21:04Z elixir_inter $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Olivier Brouckaert
  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, rue du Corbeau, 108, B-1030 Brussels, Belgium, info@dokeos.com
  17. ==============================================================================
  18. */
  19. /**
  20. ==============================================================================
  21. @author Bart Mollet
  22. * @package dokeos.admin
  23. ==============================================================================
  24. */
  25. // name of the language file that needs to be included
  26. $language_file = array ('registration','admin');
  27. $cidReset = true;
  28. require ('../inc/global.inc.php');
  29. require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  30. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  31. require_once (api_get_path(LIBRARY_PATH).'security.lib.php');
  32. require_once(api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php');
  33. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  34. // xajax
  35. $xajax = new xajax();
  36. $xajax->registerFunction('courses_of_user');
  37. //$xajax->registerFunction('empty_courses_of_user');
  38. $xajax->processRequests();
  39. function courses_of_user($arg)
  40. {
  41. // do some stuff based on $arg like query data from a database and
  42. // put it into a variable like $newContent
  43. //$newContent = 'werkt het? en met een beetje meer text, wordt dat goed opgelost? ';
  44. $personal_course_list = UserManager::get_personal_session_course_list($arg);
  45. $newContent = '';
  46. if(count($personal_course_list)>0)
  47. {
  48. foreach ($personal_course_list as $key=>$course)
  49. {
  50. $newContent .= $course['i'].'<br />';
  51. }
  52. }
  53. else
  54. {
  55. $newContent .= '- '.get_lang('None').' -<br />';
  56. }
  57. // Instantiate the xajaxResponse object
  58. $objResponse = new xajaxResponse();
  59. // add a command to the response to assign the innerHTML attribute of
  60. // the element with id="SomeElementId" to whatever the new content is
  61. $objResponse->addAssign("user".$arg,"innerHTML", $newContent);
  62. $objResponse->addReplace("coursesofuser".$arg,"alt", $newContent);
  63. $objResponse->addReplace("coursesofuser".$arg,"title", $newContent);
  64. //return the xajaxResponse object
  65. return $objResponse;
  66. }
  67. function empty_courses_of_user($arg)
  68. {
  69. // do some stuff based on $arg like query data from a database and
  70. // put it into a variable like $newContent
  71. $newContent = '';
  72. // Instantiate the xajaxResponse object
  73. $objResponse = new xajaxResponse();
  74. // add a command to the response to assign the innerHTML attribute of
  75. // the element with id="SomeElementId" to whatever the new content is
  76. $objResponse->addAssign("user".$arg,"innerHTML", $newContent);
  77. //return the xajaxResponse object
  78. return $objResponse;
  79. }
  80. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  81. $htmlHeadXtra[] = ' <style>
  82. .tooltipLinkInner {
  83. color:blue;
  84. text-decoration:none;
  85. }
  86. #tooltip .toolbox a:hover span {
  87. display: block! important;
  88. color: black;
  89. position: absolute;
  90. }
  91. .tooltipInner {
  92. margin:7px;
  93. font-size:8pt;
  94. float:right;
  95. }
  96. </style>';
  97. $this_section = SECTION_PLATFORM_ADMIN;
  98. api_protect_admin_script();
  99. /**
  100. * Make sure this function is protected
  101. * because it does NOT check password!
  102. *
  103. * This function defines globals.
  104. * @author Roan Embrechts
  105. */
  106. function login_user($user_id)
  107. {
  108. //init ---------------------------------------------------------------------
  109. global $uidReset, $loginFailed, $_configuration;
  110. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  111. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  112. $track_e_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  113. //logic --------------------------------------------------------------------
  114. //unset($_user['user_id']); // uid not in session ? prevent any hacking
  115. if (!isset ($user_id))
  116. {
  117. $uidReset = true;
  118. return;
  119. }
  120. $sql_query = "SELECT * FROM $main_user_table WHERE user_id='$user_id'";
  121. $sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
  122. $result = Database :: fetch_array($sql_result);
  123. $firstname = $result["firstname"];
  124. $lastname = $result["lastname"];
  125. $user_id = $result["user_id"];
  126. $message = "Attempting to login as ".$firstname." ".$lastname." (id ".$user_id.")";
  127. $loginFailed = false;
  128. $uidReset = false;
  129. if ($user_id) // a uid is given (log in succeeded)
  130. {
  131. if ($_configuration['tracking_enabled'])
  132. {
  133. $sql_query = "SELECT user.*, a.user_id is_admin,
  134. UNIX_TIMESTAMP(login.login_date) login_date
  135. FROM $main_user_table
  136. LEFT JOIN $main_admin_table a
  137. ON user.user_id = a.user_id
  138. LEFT JOIN $track_e_login_table login
  139. ON user.user_id = login.login_user_id
  140. WHERE user.user_id = '".$user_id."'
  141. ORDER BY login.login_date DESC LIMIT 1";
  142. }
  143. else
  144. {
  145. $sql_query = "SELECT user.*, a.user_id is_admin
  146. FROM $main_user_table
  147. LEFT JOIN $main_admin_table a
  148. ON user.user_id = a.user_id
  149. WHERE user.user_id = '".$user_id."'";
  150. }
  151. $sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
  152. if (Database::num_rows($sql_result) > 0)
  153. {
  154. // Extracting the user data
  155. $user_data = Database::fetch_array($sql_result);
  156. //Delog the current user
  157. LoginDelete($_SESSION["_user"]["user_id"], $_configuration['statistics_database']);
  158. // Cleaning session variables
  159. unset($_SESSION['_user']);
  160. unset($_SESSION['is_platformAdmin']);
  161. unset($_SESSION['is_allowedCreateCourse']);
  162. unset($_SESSION['_uid']);
  163. $_user['firstName'] = $user_data['firstname'];
  164. $_user['lastName'] = $user_data['lastname'];
  165. $_user['mail'] = $user_data['email'];
  166. $_user['lastLogin'] = $user_data['login_date'];
  167. $_user['official_code'] = $user_data['official_code'];
  168. $_user['picture_uri'] = $user_data['picture_uri'];
  169. $_user['user_id'] = $user_data['user_id'];
  170. $is_platformAdmin = (bool) (!is_null($user_data['is_admin']));
  171. $is_allowedCreateCourse = (bool) ($user_data['status'] == 1);
  172. // Filling session variables with new data
  173. $_SESSION['_uid'] = $user_id;
  174. $_SESSION['_user'] = $_user;
  175. $_SESSION['is_platformAdmin'] = $is_platformAdmin;
  176. $_SESSION['is_allowedCreateCourse'] = $is_allowedCreateCourse;
  177. $_SESSION['login_as'] = true; // will be usefull later to know if the user is actually an admin or not (example reporting)s
  178. $target_url = api_get_path(WEB_PATH)."user_portal.php";
  179. $message .= "<br/>Login successful. Go to <a href=\"$target_url\">$target_url</a>";
  180. Display :: display_header(get_lang('UserList'));
  181. Display :: display_normal_message($message,false);
  182. Display :: display_footer();
  183. exit;
  184. }
  185. else
  186. {
  187. exit ("<br/>WARNING UNDEFINED UID !! ");
  188. }
  189. }
  190. }
  191. /**
  192. * Get the total number of users on the platform
  193. * @see SortableTable#get_total_number_of_items()
  194. */
  195. function get_number_of_users()
  196. {
  197. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  198. $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
  199. if (isset ($_GET['keyword']))
  200. {
  201. $keyword = Database::escape_string($_GET['keyword']);
  202. $sql .= " WHERE u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%'";
  203. }
  204. elseif (isset ($_GET['keyword_firstname']))
  205. {
  206. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  207. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  208. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  209. $keyword_email = Database::escape_string($_GET['keyword_email']);
  210. $keyword_username = Database::escape_string($_GET['keyword_username']);
  211. $keyword_status = Database::escape_string($_GET['keyword_status']);
  212. $query_admin_table = '';
  213. $keyword_admin = '';
  214. if($keyword_status == 10)
  215. {
  216. $keyword_status = '%';
  217. $query_admin_table = " , $admin_table a ";
  218. $keyword_admin = ' AND a.user_id = u.user_id ';
  219. }
  220. $keyword_active = isset($_GET['keyword_active']);
  221. $keyword_inactive = isset($_GET['keyword_inactive']);
  222. $sql .= $query_admin_table .
  223. " WHERE u.firstname LIKE '%".$keyword_firstname."%' " .
  224. "AND u.lastname LIKE '%".$keyword_lastname."%' " .
  225. "AND u.username LIKE '%".$keyword_username."%' " .
  226. "AND u.email LIKE '%".$keyword_email."%' " .
  227. //"AND u.official_code LIKE '%".$keyword_officialcode."%' " .
  228. "AND u.status LIKE '".$keyword_status."'" .
  229. $keyword_admin;
  230. if($keyword_active && !$keyword_inactive)
  231. {
  232. $sql .= " AND u.active='1'";
  233. }
  234. elseif($keyword_inactive && !$keyword_active)
  235. {
  236. $sql .= " AND u.active='0'";
  237. }
  238. }
  239. $res = api_sql_query($sql, __FILE__, __LINE__);
  240. $obj = Database::fetch_object($res);
  241. return $obj->total_number_of_items;
  242. }
  243. /**
  244. * Get the users to display on the current page.
  245. * @see SortableTable#get_table_data($from)
  246. */
  247. function get_user_data($from, $number_of_items, $column, $direction)
  248. {
  249. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  250. $sql = "SELECT
  251. u.user_id AS col0,
  252. u.official_code AS col1,
  253. u.lastname AS col2,
  254. u.firstname AS col3,
  255. u.username AS col4,
  256. u.email AS col5,
  257. u.status AS col6,
  258. u.active AS col7,
  259. u.user_id AS col8
  260. FROM
  261. $user_table u";
  262. if (isset ($_GET['keyword']))
  263. {
  264. $keyword = Database::escape_string($_GET['keyword']);
  265. $sql .= " WHERE u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%'";
  266. }
  267. elseif (isset ($_GET['keyword_firstname']))
  268. {
  269. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  270. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  271. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  272. $keyword_email = Database::escape_string($_GET['keyword_email']);
  273. $keyword_username = Database::escape_string($_GET['keyword_username']);
  274. $keyword_status = Database::escape_string($_GET['keyword_status']);
  275. $query_admin_table = '';
  276. $keyword_admin = '';
  277. if($keyword_status == 10)
  278. {
  279. $keyword_status = '%';
  280. $query_admin_table = " , $admin_table a ";
  281. $keyword_admin = ' AND a.user_id = u.user_id ';
  282. }
  283. $keyword_active = isset($_GET['keyword_active']);
  284. $keyword_inactive = isset($_GET['keyword_inactive']);
  285. $sql .= $query_admin_table." WHERE u.firstname LIKE '%".$keyword_firstname."%' " .
  286. "AND u.lastname LIKE '%".$keyword_lastname."%' " .
  287. "AND u.username LIKE '%".$keyword_username."%' " .
  288. "AND u.email LIKE '%".$keyword_email."%' " .
  289. //"AND u.official_code LIKE '%".$keyword_officialcode."%' " .
  290. "AND u.status LIKE '".$keyword_status."'" .
  291. $keyword_admin;
  292. if($keyword_active && !$keyword_inactive)
  293. {
  294. $sql .= " AND u.active='1'";
  295. }
  296. elseif($keyword_inactive && !$keyword_active)
  297. {
  298. $sql .= " AND u.active='0'";
  299. }
  300. }
  301. $sql .= " ORDER BY col$column $direction ";
  302. $sql .= " LIMIT $from,$number_of_items";
  303. $res = api_sql_query($sql, __FILE__, __LINE__);
  304. $users = array ();
  305. while ($user = Database::fetch_row($res))
  306. {
  307. $users[] = $user;
  308. }
  309. return $users;
  310. }
  311. /**
  312. * Returns a mailto-link
  313. * @param string $email An email-address
  314. * @return string HTML-code with a mailto-link
  315. */
  316. function email_filter($email)
  317. {
  318. return Display :: encrypted_mailto_link($email, $email);
  319. }
  320. /**
  321. * Build the modify-column of the table
  322. * @param int $user_id The user id
  323. * @param string $url_params
  324. * @return string Some HTML-code with modify-buttons
  325. */
  326. function modify_filter($user_id,$url_params,$row)
  327. {
  328. global $charset;
  329. $result .= '<span id="tooltip">
  330. <span class="toolbox">
  331. <a style="position: relative;" class="tooltipLinkInner" href="#">
  332. <img src="../img/courses.gif" id="coursesofuser'.$user_id.'" onmouseover="xajax_courses_of_user('.$user_id.');" style="vertical-align:middle;"/>
  333. <span id="user'.$user_id.'" style="margin-left: -100px; border:1px solid black; width: 200px; background-color:white; z-index:99; padding: 3px; display: none; margin-right:inherit;">
  334. <div style="text-align:center;"><img src="../img/anim-loader.gif" height="20" /></div>
  335. </span></a></span></span>';
  336. $result .= '<a href="user_information.php?user_id='.$user_id.'"><img src="../img/synthese_view.gif" border="0" style="vertical-align: middle;" title="'.get_lang('Info').'" alt="'.get_lang('Info').'"/></a>&nbsp;';
  337. $result .= '<a href="user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.$_SESSION['sec_token'].'"><img src="../img/login_as.gif" border="0" style="vertical-align: middle;" alt="'.get_lang('LoginAs').'" title="'.get_lang('LoginAs').'"/></a>&nbsp;';
  338. $statusname = api_get_status_langvars();
  339. if ($row['6'] != $statusname[STUDENT])
  340. {
  341. $result .= '<div style="display:inline;margin-left:25px"></div>';
  342. }
  343. else
  344. {
  345. $result .= '<a href="../mySpace/myStudents.php?student='.$user_id.'"><img src="../img/statistics.gif" border="0" style="vertical-align: middle;" title="'.get_lang('Reporting').'" alt="'.get_lang('Reporting').'"/></a>&nbsp;';
  346. }
  347. $result .= '<a href="user_edit.php?user_id='.$user_id.'"><img src="../img/edit.gif" border="0" style="vertical-align: middle;" title="'.get_lang('Edit').'" alt="'.get_lang('Edit').'"/></a>&nbsp;';
  348. $result .= '<a href="user_list.php?action=delete_user&amp;user_id='.$user_id.'&amp;'.$url_params.'&amp;sec_token='.$_SESSION['sec_token'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;"><img src="../img/delete.gif" border="0" style="vertical-align: middle;" title="'.get_lang('Delete').'" alt="'.get_lang('Delete').'"/></a>';
  349. return $result;
  350. }
  351. /**
  352. * Build the active-column of the table to lock or unlock a certain user
  353. * lock = the user can no longer use this account
  354. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  355. * @param int $active the current state of the account
  356. * @param int $user_id The user id
  357. * @param string $url_params
  358. * @return string Some HTML-code with the lock/unlock button
  359. */
  360. function active_filter($active, $url_params, $row)
  361. {
  362. global $_user;
  363. if ($active=='1')
  364. {
  365. $action='lock';
  366. $image='right';
  367. }
  368. if ($active=='0')
  369. {
  370. $action='unlock';
  371. $image='wrong';
  372. }
  373. 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.
  374. {
  375. $result = '<a href="user_list.php?action='.$action.'&amp;user_id='.$row['0'].'&amp;'.$url_params.'&amp;sec_token='.$_SESSION['sec_token'].'"><img src="../img/'.$image.'.gif" border="0" style="vertical-align: middle;" alt="'.get_lang(ucfirst($action)).'" title="'.get_lang(ucfirst($action)).'"/></a>';
  376. }
  377. return $result;
  378. }
  379. /**
  380. * lock or unlock a user
  381. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  382. * @param int $status, do we want to lock the user ($status=lock) or unlock it ($status=unlock)
  383. * @param int $user_id The user id
  384. * @return language variable
  385. */
  386. function lock_unlock_user($status,$user_id)
  387. {
  388. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  389. if ($status=='lock')
  390. {
  391. $status_db='0';
  392. $return_message=get_lang('UserLocked');
  393. }
  394. if ($status=='unlock')
  395. {
  396. $status_db='1';
  397. $return_message=get_lang('UserUnlocked');
  398. }
  399. if(($status_db=='1' OR $status_db=='0') AND is_numeric($user_id))
  400. {
  401. $sql="UPDATE $user_table SET active='".Database::escape_string($status_db)."' WHERE user_id='".Database::escape_string($user_id)."'";
  402. $result = api_sql_query($sql, __FILE__, __LINE__);
  403. }
  404. if ($result)
  405. {
  406. return $return_message;
  407. }
  408. }
  409. /**
  410. * instead of displaying the integer of the status, we give a translation for the status
  411. *
  412. * @param integer $status
  413. * @return string translation
  414. *
  415. * @version march 2008
  416. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  417. */
  418. function status_filter($status)
  419. {
  420. $statusname = api_get_status_langvars();
  421. return $statusname[$status];
  422. }
  423. /**
  424. ==============================================================================
  425. INIT SECTION
  426. ==============================================================================
  427. */
  428. $action = $_GET["action"];
  429. $login_as_user_id = $_GET["user_id"];
  430. // Login as ...
  431. if ($_GET['action'] == "login_as" && isset ($login_as_user_id))
  432. {
  433. login_user($login_as_user_id);
  434. }
  435. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  436. {
  437. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  438. $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
  439. $tool_name = get_lang('SearchAUser');
  440. Display :: display_header($tool_name);
  441. //api_display_tool_title($tool_name);
  442. $form = new FormValidator('advanced_search','get');
  443. $form->add_textfield('keyword_firstname',get_lang('FirstName'),false);
  444. $form->add_textfield('keyword_lastname',get_lang('LastName'),false);
  445. $form->add_textfield('keyword_username',get_lang('LoginName'),false);
  446. $form->add_textfield('keyword_email',get_lang('Email'),false);
  447. $form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false);
  448. $status_options = array();
  449. $status_options['%'] = get_lang('All');
  450. $status_options[STUDENT] = get_lang('Student');
  451. $status_options[COURSEMANAGER] = get_lang('Teacher');
  452. $status_options[10] = get_lang('Administrator');
  453. $form->addElement('select','keyword_status',get_lang('Status'),$status_options);
  454. $active_group = array();
  455. $active_group[] = $form->createElement('checkbox','keyword_active','',get_lang('Active'));
  456. $active_group[] = $form->createElement('checkbox','keyword_inactive','',get_lang('Inactive'));
  457. $form->addGroup($active_group,'',get_lang('ActiveAccount'),'<br/>',false);
  458. $form->addElement('submit','submit',get_lang('Ok'));
  459. $defaults['keyword_active'] = 1;
  460. $defaults['keyword_inactive'] = 1;
  461. $form->setDefaults($defaults);
  462. $form->display();
  463. }
  464. else
  465. {
  466. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  467. $tool_name = get_lang('UserList');
  468. Display :: display_header($tool_name, "");
  469. //api_display_tool_title($tool_name);
  470. if (isset ($_GET['action']))
  471. {
  472. $check = Security::check_token('get');
  473. if($check)
  474. {
  475. switch ($_GET['action'])
  476. {
  477. case 'show_message' :
  478. Display :: display_normal_message(stripslashes($_GET['message']));
  479. break;
  480. case 'delete_user' :
  481. if ($user_id != $_user['user_id'] && UserManager :: delete_user($_GET['user_id']))
  482. {
  483. Display :: display_normal_message(get_lang('UserDeleted'));
  484. }
  485. else
  486. {
  487. Display :: display_error_message(get_lang('CannotDeleteUser'));
  488. }
  489. break;
  490. case 'lock' :
  491. $message=lock_unlock_user('lock',$_GET['user_id']);
  492. Display :: display_normal_message($message);
  493. break;
  494. case 'unlock';
  495. $message=lock_unlock_user('unlock',$_GET['user_id']);
  496. Display :: display_normal_message($message);
  497. break;
  498. }
  499. Security::clear_token();
  500. }
  501. }
  502. if (isset ($_POST['action']))
  503. {
  504. $check = Security::check_token('get');
  505. if($check)
  506. {
  507. switch ($_POST['action'])
  508. {
  509. case 'delete' :
  510. $number_of_selected_users = count($_POST['id']);
  511. $number_of_deleted_users = 0;
  512. foreach ($_POST['id'] as $index => $user_id)
  513. {
  514. if($user_id != $_user['user_id'])
  515. {
  516. if(UserManager :: delete_user($user_id))
  517. {
  518. $number_of_deleted_users++;
  519. }
  520. }
  521. }
  522. if($number_of_selected_users == $number_of_deleted_users)
  523. {
  524. Display :: display_normal_message(get_lang('SelectedUsersDeleted'));
  525. }
  526. else
  527. {
  528. Display :: display_error_message(get_lang('SomeUsersNotDeleted'));
  529. }
  530. break;
  531. }
  532. Security::clear_token();
  533. }
  534. }
  535. // Create a search-box
  536. $form = new FormValidator('search_simple','get','','',null,false);
  537. $renderer =& $form->defaultRenderer();
  538. $renderer->setElementTemplate('<span>{element}</span> ');
  539. $form->addElement('text','keyword',get_lang('keyword'));
  540. $form->addElement('submit','submit',get_lang('Search'));
  541. $form->addElement('static','search_advanced_link',null,'<a href="user_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  542. $form->display();
  543. if (isset ($_GET['keyword']))
  544. {
  545. $parameters = array ('keyword' => $_GET['keyword']);
  546. }
  547. elseif (isset ($_GET['keyword_firstname']))
  548. {
  549. $parameters['keyword_firstname'] = $_GET['keyword_firstname'];
  550. $parameters['keyword_lastname'] = $_GET['keyword_lastname'];
  551. $parameters['keyword_email'] = $_GET['keyword_email'];
  552. $parameters['keyword_officialcode'] = $_GET['keyword_officialcode'];
  553. $parameters['keyword_status'] = $_GET['keyword_status'];
  554. $parameters['keyword_active'] = $_GET['keyword_active'];
  555. $parameters['keyword_inactive'] = $_GET['keyword_inactive'];
  556. }
  557. // Create a sortable table with user-data
  558. $parameters['sec_token'] = Security::get_token();
  559. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data',2);
  560. $table->set_additional_parameters($parameters);
  561. $table->set_header(0, '', false);
  562. $table->set_header(1, get_lang('OfficialCode'));
  563. $table->set_header(2, get_lang('LastName'));
  564. $table->set_header(3, get_lang('FirstName'));
  565. $table->set_header(4, get_lang('LoginName'));
  566. $table->set_header(5, get_lang('Email'));
  567. $table->set_header(6, get_lang('Status'));
  568. $table->set_header(7, get_lang('Active'));
  569. $table->set_header(8, get_lang('Modify'));
  570. $table->set_column_filter(5, 'email_filter');
  571. $table->set_column_filter(6, 'status_filter');
  572. $table->set_column_filter(7, 'active_filter');
  573. $table->set_column_filter(8, 'modify_filter');
  574. $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
  575. $table->display();
  576. }
  577. /*
  578. ==============================================================================
  579. FOOTER
  580. ==============================================================================
  581. */
  582. Display :: display_footer();
  583. ?>