user_list.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. <?php // $Id: user_list.php 15137 2008-04-26 01:34:17Z yannoo $
  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. $message = sprintf(get_lang('AttemptingToLoginAs'),$firstname,$lastname,$user_id);
  128. $loginFailed = false;
  129. $uidReset = false;
  130. if ($user_id) // a uid is given (log in succeeded)
  131. {
  132. if ($_configuration['tracking_enabled'])
  133. {
  134. $sql_query = "SELECT user.*, a.user_id is_admin,
  135. UNIX_TIMESTAMP(login.login_date) login_date
  136. FROM $main_user_table
  137. LEFT JOIN $main_admin_table a
  138. ON user.user_id = a.user_id
  139. LEFT JOIN $track_e_login_table login
  140. ON user.user_id = login.login_user_id
  141. WHERE user.user_id = '".$user_id."'
  142. ORDER BY login.login_date DESC LIMIT 1";
  143. }
  144. else
  145. {
  146. $sql_query = "SELECT user.*, a.user_id is_admin
  147. FROM $main_user_table
  148. LEFT JOIN $main_admin_table a
  149. ON user.user_id = a.user_id
  150. WHERE user.user_id = '".$user_id."'";
  151. }
  152. $sql_result = api_sql_query($sql_query, __FILE__, __LINE__);
  153. if (Database::num_rows($sql_result) > 0)
  154. {
  155. // Extracting the user data
  156. $user_data = Database::fetch_array($sql_result);
  157. //Delog the current user
  158. LoginDelete($_SESSION["_user"]["user_id"], $_configuration['statistics_database']);
  159. // Cleaning session variables
  160. unset($_SESSION['_user']);
  161. unset($_SESSION['is_platformAdmin']);
  162. unset($_SESSION['is_allowedCreateCourse']);
  163. unset($_SESSION['_uid']);
  164. $_user['firstName'] = $user_data['firstname'];
  165. $_user['lastName'] = $user_data['lastname'];
  166. $_user['mail'] = $user_data['email'];
  167. $_user['lastLogin'] = $user_data['login_date'];
  168. $_user['official_code'] = $user_data['official_code'];
  169. $_user['picture_uri'] = $user_data['picture_uri'];
  170. $_user['user_id'] = $user_data['user_id'];
  171. $is_platformAdmin = (bool) (!is_null($user_data['is_admin']));
  172. $is_allowedCreateCourse = (bool) ($user_data['status'] == 1);
  173. // Filling session variables with new data
  174. $_SESSION['_uid'] = $user_id;
  175. $_SESSION['_user'] = $_user;
  176. $_SESSION['is_platformAdmin'] = $is_platformAdmin;
  177. $_SESSION['is_allowedCreateCourse'] = $is_allowedCreateCourse;
  178. $_SESSION['login_as'] = true; // will be usefull later to know if the user is actually an admin or not (example reporting)s
  179. $target_url = api_get_path(WEB_PATH)."user_portal.php";
  180. //$message .= "<br/>Login successful. Go to <a href=\"$target_url\">$target_url</a>";
  181. $message .= '<br />'.sprintf(get_lang('LoginSuccessfulGoToX'),'<a href="'.$target_url.'">'.$target_url.'</a>');
  182. Display :: display_header(get_lang('UserList'));
  183. Display :: display_normal_message($message,false);
  184. Display :: display_footer();
  185. exit;
  186. }
  187. else
  188. {
  189. exit ("<br/>WARNING UNDEFINED UID !! ");
  190. }
  191. }
  192. }
  193. /**
  194. * Get the total number of users on the platform
  195. * @see SortableTable#get_total_number_of_items()
  196. */
  197. function get_number_of_users()
  198. {
  199. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  200. $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
  201. if (isset ($_GET['keyword']))
  202. {
  203. $keyword = Database::escape_string($_GET['keyword']);
  204. $sql .= " WHERE u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%'";
  205. }
  206. elseif (isset ($_GET['keyword_firstname']))
  207. {
  208. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  209. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  210. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  211. $keyword_email = Database::escape_string($_GET['keyword_email']);
  212. $keyword_username = Database::escape_string($_GET['keyword_username']);
  213. $keyword_status = Database::escape_string($_GET['keyword_status']);
  214. $query_admin_table = '';
  215. $keyword_admin = '';
  216. if($keyword_status == 10)
  217. {
  218. $keyword_status = '%';
  219. $query_admin_table = " , $admin_table a ";
  220. $keyword_admin = ' AND a.user_id = u.user_id ';
  221. }
  222. $keyword_active = isset($_GET['keyword_active']);
  223. $keyword_inactive = isset($_GET['keyword_inactive']);
  224. $sql .= $query_admin_table .
  225. " WHERE u.firstname LIKE '%".$keyword_firstname."%' " .
  226. "AND u.lastname LIKE '%".$keyword_lastname."%' " .
  227. "AND u.username LIKE '%".$keyword_username."%' " .
  228. "AND u.email LIKE '%".$keyword_email."%' " .
  229. //"AND u.official_code LIKE '%".$keyword_officialcode."%' " .
  230. "AND u.status LIKE '".$keyword_status."'" .
  231. $keyword_admin;
  232. if($keyword_active && !$keyword_inactive)
  233. {
  234. $sql .= " AND u.active='1'";
  235. }
  236. elseif($keyword_inactive && !$keyword_active)
  237. {
  238. $sql .= " AND u.active='0'";
  239. }
  240. }
  241. $res = api_sql_query($sql, __FILE__, __LINE__);
  242. $obj = Database::fetch_object($res);
  243. return $obj->total_number_of_items;
  244. }
  245. /**
  246. * Get the users to display on the current page.
  247. * @see SortableTable#get_table_data($from)
  248. */
  249. function get_user_data($from, $number_of_items, $column, $direction)
  250. {
  251. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  252. $sql = "SELECT
  253. u.user_id AS col0,
  254. u.official_code AS col1,
  255. u.lastname AS col2,
  256. u.firstname AS col3,
  257. u.username AS col4,
  258. u.email AS col5,
  259. u.status AS col6,
  260. u.active AS col7,
  261. u.user_id AS col8
  262. FROM
  263. $user_table u";
  264. if (isset ($_GET['keyword']))
  265. {
  266. $keyword = Database::escape_string($_GET['keyword']);
  267. $sql .= " WHERE u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%'";
  268. }
  269. elseif (isset ($_GET['keyword_firstname']))
  270. {
  271. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  272. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  273. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  274. $keyword_email = Database::escape_string($_GET['keyword_email']);
  275. $keyword_username = Database::escape_string($_GET['keyword_username']);
  276. $keyword_status = Database::escape_string($_GET['keyword_status']);
  277. $query_admin_table = '';
  278. $keyword_admin = '';
  279. if($keyword_status == 10)
  280. {
  281. $keyword_status = '%';
  282. $query_admin_table = " , $admin_table a ";
  283. $keyword_admin = ' AND a.user_id = u.user_id ';
  284. }
  285. $keyword_active = isset($_GET['keyword_active']);
  286. $keyword_inactive = isset($_GET['keyword_inactive']);
  287. $sql .= $query_admin_table." WHERE u.firstname LIKE '%".$keyword_firstname."%' " .
  288. "AND u.lastname LIKE '%".$keyword_lastname."%' " .
  289. "AND u.username LIKE '%".$keyword_username."%' " .
  290. "AND u.email LIKE '%".$keyword_email."%' " .
  291. //"AND u.official_code LIKE '%".$keyword_officialcode."%' " .
  292. "AND u.status LIKE '".$keyword_status."'" .
  293. $keyword_admin;
  294. if($keyword_active && !$keyword_inactive)
  295. {
  296. $sql .= " AND u.active='1'";
  297. }
  298. elseif($keyword_inactive && !$keyword_active)
  299. {
  300. $sql .= " AND u.active='0'";
  301. }
  302. }
  303. $sql .= " ORDER BY col$column $direction ";
  304. $sql .= " LIMIT $from,$number_of_items";
  305. $res = api_sql_query($sql, __FILE__, __LINE__);
  306. $users = array ();
  307. while ($user = Database::fetch_row($res))
  308. {
  309. $users[] = $user;
  310. }
  311. return $users;
  312. }
  313. /**
  314. * Returns a mailto-link
  315. * @param string $email An email-address
  316. * @return string HTML-code with a mailto-link
  317. */
  318. function email_filter($email)
  319. {
  320. return Display :: encrypted_mailto_link($email, $email);
  321. }
  322. /**
  323. * Build the modify-column of the table
  324. * @param int $user_id The user id
  325. * @param string $url_params
  326. * @return string Some HTML-code with modify-buttons
  327. */
  328. function modify_filter($user_id,$url_params,$row)
  329. {
  330. global $charset;
  331. $result .= '<span id="tooltip">
  332. <span class="toolbox">
  333. <a style="position: relative;" class="tooltipLinkInner" href="#">
  334. <img src="../img/courses.gif" id="coursesofuser'.$user_id.'" onmouseover="xajax_courses_of_user('.$user_id.');" style="vertical-align:middle;"/>
  335. <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;">
  336. <div style="text-align:center;"><img src="../img/anim-loader.gif" height="20" /></div>
  337. </span></a></span></span>';
  338. $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;';
  339. $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;';
  340. $statusname = api_get_status_langvars();
  341. if ($row['6'] != $statusname[STUDENT])
  342. {
  343. $result .= '<img src="../img/statistics_na.gif" border="0" style="vertical-align: middle;" title="'.get_lang('Reporting').'" alt="'.get_lang('Reporting').'"/>&nbsp;';
  344. }
  345. else
  346. {
  347. $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;';
  348. }
  349. $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;';
  350. $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>';
  351. return $result;
  352. }
  353. /**
  354. * Build the active-column of the table to lock or unlock a certain user
  355. * lock = the user can no longer use this account
  356. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  357. * @param int $active the current state of the account
  358. * @param int $user_id The user id
  359. * @param string $url_params
  360. * @return string Some HTML-code with the lock/unlock button
  361. */
  362. function active_filter($active, $url_params, $row)
  363. {
  364. global $_user;
  365. if ($active=='1')
  366. {
  367. $action='lock';
  368. $image='right';
  369. }
  370. if ($active=='0')
  371. {
  372. $action='unlock';
  373. $image='wrong';
  374. }
  375. 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.
  376. {
  377. $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>';
  378. }
  379. return $result;
  380. }
  381. /**
  382. * lock or unlock a user
  383. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  384. * @param int $status, do we want to lock the user ($status=lock) or unlock it ($status=unlock)
  385. * @param int $user_id The user id
  386. * @return language variable
  387. */
  388. function lock_unlock_user($status,$user_id)
  389. {
  390. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  391. if ($status=='lock')
  392. {
  393. $status_db='0';
  394. $return_message=get_lang('UserLocked');
  395. }
  396. if ($status=='unlock')
  397. {
  398. $status_db='1';
  399. $return_message=get_lang('UserUnlocked');
  400. }
  401. if(($status_db=='1' OR $status_db=='0') AND is_numeric($user_id))
  402. {
  403. $sql="UPDATE $user_table SET active='".Database::escape_string($status_db)."' WHERE user_id='".Database::escape_string($user_id)."'";
  404. $result = api_sql_query($sql, __FILE__, __LINE__);
  405. }
  406. if ($result)
  407. {
  408. return $return_message;
  409. }
  410. }
  411. /**
  412. * instead of displaying the integer of the status, we give a translation for the status
  413. *
  414. * @param integer $status
  415. * @return string translation
  416. *
  417. * @version march 2008
  418. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  419. */
  420. function status_filter($status)
  421. {
  422. $statusname = api_get_status_langvars();
  423. return $statusname[$status];
  424. }
  425. /**
  426. ==============================================================================
  427. INIT SECTION
  428. ==============================================================================
  429. */
  430. $action = $_GET["action"];
  431. $login_as_user_id = $_GET["user_id"];
  432. // Login as ...
  433. if ($_GET['action'] == "login_as" && isset ($login_as_user_id))
  434. {
  435. login_user($login_as_user_id);
  436. }
  437. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  438. {
  439. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  440. $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
  441. $tool_name = get_lang('SearchAUser');
  442. Display :: display_header($tool_name);
  443. //api_display_tool_title($tool_name);
  444. $form = new FormValidator('advanced_search','get');
  445. $form->add_textfield('keyword_firstname',get_lang('FirstName'),false);
  446. $form->add_textfield('keyword_lastname',get_lang('LastName'),false);
  447. $form->add_textfield('keyword_username',get_lang('LoginName'),false);
  448. $form->add_textfield('keyword_email',get_lang('Email'),false);
  449. $form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false);
  450. $status_options = array();
  451. $status_options['%'] = get_lang('All');
  452. $status_options[STUDENT] = get_lang('Student');
  453. $status_options[COURSEMANAGER] = get_lang('Teacher');
  454. $status_options[10] = get_lang('Administrator');
  455. $form->addElement('select','keyword_status',get_lang('Status'),$status_options);
  456. $active_group = array();
  457. $active_group[] = $form->createElement('checkbox','keyword_active','',get_lang('Active'));
  458. $active_group[] = $form->createElement('checkbox','keyword_inactive','',get_lang('Inactive'));
  459. $form->addGroup($active_group,'',get_lang('ActiveAccount'),'<br/>',false);
  460. $form->addElement('submit','submit',get_lang('Ok'));
  461. $defaults['keyword_active'] = 1;
  462. $defaults['keyword_inactive'] = 1;
  463. $form->setDefaults($defaults);
  464. $form->display();
  465. }
  466. else
  467. {
  468. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  469. $tool_name = get_lang('UserList');
  470. Display :: display_header($tool_name, "");
  471. //api_display_tool_title($tool_name);
  472. if (isset ($_GET['action']))
  473. {
  474. $check = Security::check_token('get');
  475. if($check)
  476. {
  477. switch ($_GET['action'])
  478. {
  479. case 'show_message' :
  480. Display :: display_normal_message(stripslashes($_GET['message']));
  481. break;
  482. case 'delete_user' :
  483. if ($user_id != $_user['user_id'] && UserManager :: delete_user($_GET['user_id']))
  484. {
  485. Display :: display_normal_message(get_lang('UserDeleted'));
  486. }
  487. else
  488. {
  489. Display :: display_error_message(get_lang('CannotDeleteUser'));
  490. }
  491. break;
  492. case 'lock' :
  493. $message=lock_unlock_user('lock',$_GET['user_id']);
  494. Display :: display_normal_message($message);
  495. break;
  496. case 'unlock';
  497. $message=lock_unlock_user('unlock',$_GET['user_id']);
  498. Display :: display_normal_message($message);
  499. break;
  500. }
  501. Security::clear_token();
  502. }
  503. }
  504. if (isset ($_POST['action']))
  505. {
  506. $check = Security::check_token('get');
  507. if($check)
  508. {
  509. switch ($_POST['action'])
  510. {
  511. case 'delete' :
  512. $number_of_selected_users = count($_POST['id']);
  513. $number_of_deleted_users = 0;
  514. foreach ($_POST['id'] as $index => $user_id)
  515. {
  516. if($user_id != $_user['user_id'])
  517. {
  518. if(UserManager :: delete_user($user_id))
  519. {
  520. $number_of_deleted_users++;
  521. }
  522. }
  523. }
  524. if($number_of_selected_users == $number_of_deleted_users)
  525. {
  526. Display :: display_normal_message(get_lang('SelectedUsersDeleted'));
  527. }
  528. else
  529. {
  530. Display :: display_error_message(get_lang('SomeUsersNotDeleted'));
  531. }
  532. break;
  533. }
  534. Security::clear_token();
  535. }
  536. }
  537. // Create a search-box
  538. $form = new FormValidator('search_simple','get','','',null,false);
  539. $renderer =& $form->defaultRenderer();
  540. $renderer->setElementTemplate('<span>{element}</span> ');
  541. $form->addElement('text','keyword',get_lang('keyword'));
  542. $form->addElement('submit','submit',get_lang('Search'));
  543. $form->addElement('static','search_advanced_link',null,'<a href="user_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  544. $form->display();
  545. if (isset ($_GET['keyword']))
  546. {
  547. $parameters = array ('keyword' => $_GET['keyword']);
  548. }
  549. elseif (isset ($_GET['keyword_firstname']))
  550. {
  551. $parameters['keyword_firstname'] = $_GET['keyword_firstname'];
  552. $parameters['keyword_lastname'] = $_GET['keyword_lastname'];
  553. $parameters['keyword_email'] = $_GET['keyword_email'];
  554. $parameters['keyword_officialcode'] = $_GET['keyword_officialcode'];
  555. $parameters['keyword_status'] = $_GET['keyword_status'];
  556. $parameters['keyword_active'] = $_GET['keyword_active'];
  557. $parameters['keyword_inactive'] = $_GET['keyword_inactive'];
  558. }
  559. // Create a sortable table with user-data
  560. $parameters['sec_token'] = Security::get_token();
  561. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data',2);
  562. $table->set_additional_parameters($parameters);
  563. $table->set_header(0, '', false);
  564. $table->set_header(1, get_lang('OfficialCode'));
  565. $table->set_header(2, get_lang('LastName'));
  566. $table->set_header(3, get_lang('FirstName'));
  567. $table->set_header(4, get_lang('LoginName'));
  568. $table->set_header(5, get_lang('Email'));
  569. $table->set_header(6, get_lang('Status'));
  570. $table->set_header(7, get_lang('Active'));
  571. $table->set_header(8, get_lang('Modify'));
  572. $table->set_column_filter(5, 'email_filter');
  573. $table->set_column_filter(6, 'status_filter');
  574. $table->set_column_filter(7, 'active_filter');
  575. $table->set_column_filter(8, 'modify_filter');
  576. $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
  577. $table->display();
  578. }
  579. /*
  580. ==============================================================================
  581. FOOTER
  582. ==============================================================================
  583. */
  584. Display :: display_footer();
  585. ?>