user_list.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. <?php // $Id: user_list.php 22292 2009-07-22 18:32:32Z herodoto $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. ==============================================================================
  5. @author Bart Mollet
  6. * @package dokeos.admin
  7. ==============================================================================
  8. */
  9. // name of the language file that needs to be included
  10. $language_file = array ('registration','admin');
  11. $cidReset = true;
  12. require ('../inc/global.inc.php');
  13. require_once (api_get_path(LIBRARY_PATH).'sortabletable.class.php');
  14. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  15. require_once (api_get_path(LIBRARY_PATH).'security.lib.php');
  16. require_once(api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php');
  17. require_once (api_get_path(LIBRARY_PATH).'usermanager.lib.php');
  18. $htmlHeadXtra[] = '<script src="../inc/lib/javascript/jquery.js" type="text/javascript" language="javascript"></script>';
  19. $htmlHeadXtra[] = '<script type="text/javascript">
  20. function load_course_list (div_course,my_user_id) {
  21. $.ajax({
  22. contentType: "application/x-www-form-urlencoded",
  23. beforeSend: function(objeto) {
  24. $("div#"+div_course).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  25. type: "POST",
  26. url: "course_user_list.php",
  27. data: "user_id="+my_user_id,
  28. success: function(datos) {
  29. $("div#"+div_course).html(datos);
  30. $("div#div_"+my_user_id).attr("class","blackboard_show");
  31. $("div#div_"+my_user_id).attr("style","");
  32. }
  33. });
  34. }
  35. function clear_course_list (div_course) {
  36. $("div#"+div_course).html("&nbsp;");
  37. $("div#"+div_course).hide("");
  38. }
  39. </script>';
  40. $htmlHeadXtra[] = '<style type="text/css" media="screen, projection">
  41. .blackboard_show {
  42. float:left;
  43. position:absolute;
  44. border:1px solid black;
  45. width: 200px;
  46. background-color:white;
  47. z-index:99; padding: 3px;
  48. display: inline;
  49. }
  50. .blackboard_hide {
  51. display: none;
  52. }
  53. ';
  54. // xajax
  55. $xajax = new xajax();
  56. $xajax->registerFunction('courses_of_user');
  57. //$xajax->registerFunction('empty_courses_of_user');
  58. $xajax->processRequests();
  59. /**
  60. * Get a formatted list of courses for given user
  61. * @param int User ID
  62. * @return resource XAJAX response
  63. */
  64. function courses_of_user($arg)
  65. {
  66. // do some stuff based on $arg like query data from a database and
  67. // put it into a variable like $newContent
  68. //$newContent = 'werkt het? en met een beetje meer text, wordt dat goed opgelost? ';
  69. $personal_course_list = UserManager::get_personal_session_course_list($arg);
  70. $newContent = '';
  71. if(count($personal_course_list)>0)
  72. {
  73. foreach ($personal_course_list as $key=>$course)
  74. {
  75. $newContent .= $course['i'].'<br />';
  76. }
  77. }
  78. else
  79. {
  80. $newContent .= '- '.get_lang('None').' -<br />';
  81. }
  82. $newContent = api_convert_encoding($newContent,'utf-8',api_get_setting('platform_charset'));
  83. // Instantiate the xajaxResponse object
  84. $objResponse = new xajaxResponse();
  85. // add a command to the response to assign the innerHTML attribute of
  86. // the element with id="SomeElementId" to whatever the new content is
  87. $objResponse->addAssign("user".$arg,"innerHTML", $newContent);
  88. $objResponse->addReplace("coursesofuser".$arg,"alt", $newContent);
  89. $objResponse->addReplace("coursesofuser".$arg,"title", $newContent);
  90. $objResponse->addAssign("user".$arg,"style.display", "block");
  91. //return the xajaxResponse object
  92. return $objResponse;
  93. }
  94. /**
  95. * Empties the XAJAX object representing the courses list
  96. * @param int User ID
  97. * @return resource XAJAX object
  98. */
  99. function empty_courses_of_user($arg)
  100. {
  101. // do some stuff based on $arg like query data from a database and
  102. // put it into a variable like $newContent
  103. $newContent = '';
  104. // Instantiate the xajaxResponse object
  105. $objResponse = new xajaxResponse();
  106. // add a command to the response to assign the innerHTML attribute of
  107. // the element with id="SomeElementId" to whatever the new content is
  108. $objResponse->addAssign("user".$arg,"innerHTML", $newContent);
  109. //return the xajaxResponse object
  110. return $objResponse;
  111. }
  112. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  113. $htmlHeadXtra[] = '<style>
  114. .tooltipLinkInner {
  115. position:relative;
  116. float:left;
  117. color:blue;
  118. text-decoration:none;
  119. }
  120. </style>';
  121. $this_section = SECTION_PLATFORM_ADMIN;
  122. api_protect_admin_script(true);
  123. /**
  124. * Make sure this function is protected because it does NOT check password!
  125. *
  126. * This function defines globals.
  127. * @param int User ID
  128. * @return bool False on failure, redirection on success
  129. * @author Evie Embrechts
  130. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  131. */
  132. function login_user($user_id) {
  133. //init ---------------------------------------------------------------------
  134. //Load $_user to be sure we clean it before logging in
  135. global $uidReset, $loginFailed, $_configuration, $_user;
  136. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  137. $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  138. $track_e_login_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  139. //logic --------------------------------------------------------------------
  140. unset($_user['user_id']); // uid not in session ? prevent any hacking
  141. if (!isset ($user_id)) {
  142. $uidReset = true;
  143. return;
  144. }
  145. if ($user_id != strval(intval($user_id))) {
  146. return false;
  147. }
  148. $sql_query = "SELECT * FROM $main_user_table WHERE user_id='$user_id'";
  149. $sql_result = Database::query($sql_query, __FILE__, __LINE__);
  150. $result = Database :: fetch_array($sql_result);
  151. // check if the user is allowed to 'login_as'
  152. $can_login_as = (api_is_platform_admin() OR (api_is_session_admin() && $result['status'] == 5 ));
  153. if (!$can_login_as) { return false; }
  154. $firstname = $result['firstname'];
  155. $lastname = $result['lastname'];
  156. $user_id = $result['user_id'];
  157. //$message = "Attempting to login as ".api_get_person_name($firstname, $lastname)." (id ".$user_id.")";
  158. if (api_is_western_name_order()) {
  159. $message = sprintf(get_lang('AttemptingToLoginAs'),$firstname,$lastname,$user_id);
  160. } else {
  161. $message = sprintf(get_lang('AttemptingToLoginAs'), $lastname, $firstname, $user_id);
  162. }
  163. $loginFailed = false;
  164. $uidReset = false;
  165. if ($user_id) { // a uid is given (log in succeeded)
  166. if ($_configuration['tracking_enabled']) {
  167. $sql_query = "SELECT user.*, a.user_id is_admin,
  168. UNIX_TIMESTAMP(login.login_date) login_date
  169. FROM $main_user_table
  170. LEFT JOIN $main_admin_table a
  171. ON user.user_id = a.user_id
  172. LEFT JOIN $track_e_login_table login
  173. ON user.user_id = login.login_user_id
  174. WHERE user.user_id = '".$user_id."'
  175. ORDER BY login.login_date DESC LIMIT 1";
  176. } else {
  177. $sql_query = "SELECT user.*, a.user_id is_admin
  178. FROM $main_user_table
  179. LEFT JOIN $main_admin_table a
  180. ON user.user_id = a.user_id
  181. WHERE user.user_id = '".$user_id."'";
  182. }
  183. $sql_result = Database::query($sql_query, __FILE__, __LINE__);
  184. if (Database::num_rows($sql_result) > 0) {
  185. // Extracting the user data
  186. $user_data = Database::fetch_array($sql_result);
  187. //Delog the current user
  188. LoginDelete($_SESSION["_user"]["user_id"]);
  189. // Cleaning session variables
  190. unset($_SESSION['_user']);
  191. unset($_SESSION['is_platformAdmin']);
  192. unset($_SESSION['is_allowedCreateCourse']);
  193. unset($_SESSION['_uid']);
  194. $_user['firstName'] = $user_data['firstname'];
  195. $_user['lastName'] = $user_data['lastname'];
  196. $_user['mail'] = $user_data['email'];
  197. $_user['lastLogin'] = $user_data['login_date'];
  198. $_user['official_code'] = $user_data['official_code'];
  199. $_user['picture_uri'] = $user_data['picture_uri'];
  200. $_user['user_id'] = $user_data['user_id'];
  201. $_user['status'] = $user_data['status'];
  202. $is_platformAdmin = (bool) (!is_null($user_data['is_admin']));
  203. $is_allowedCreateCourse = (bool) ($user_data['status'] == 1);
  204. // Filling session variables with new data
  205. $_SESSION['_uid'] = $user_id;
  206. $_SESSION['_user'] = $_user;
  207. $_SESSION['is_platformAdmin'] = $is_platformAdmin;
  208. $_SESSION['is_allowedCreateCourse'] = $is_allowedCreateCourse;
  209. $_SESSION['login_as'] = true; // will be usefull later to know if the user is actually an admin or not (example reporting)s
  210. $target_url = api_get_path(WEB_PATH)."user_portal.php";
  211. //$message .= "<br/>Login successful. Go to <a href=\"$target_url\">$target_url</a>";
  212. $message .= '<br />'.sprintf(get_lang('LoginSuccessfulGoToX'),'<a href="'.$target_url.'">'.$target_url.'</a>');
  213. Display :: display_header(get_lang('UserList'));
  214. Display :: display_normal_message($message,false);
  215. Display :: display_footer();
  216. exit;
  217. } else {
  218. exit ("<br />WARNING UNDEFINED UID !! ");
  219. }
  220. }
  221. }
  222. /**
  223. * Get the total number of users on the platform
  224. * @see SortableTable#get_total_number_of_items()
  225. */
  226. function get_number_of_users()
  227. {
  228. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  229. $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
  230. // adding the filter to see the user's only of the current access_url
  231. global $_configuration;
  232. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  233. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  234. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  235. }
  236. if ( isset ($_GET['keyword'])) {
  237. $keyword = Database::escape_string($_GET['keyword']);
  238. $sql .= " WHERE (u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%') ";
  239. } elseif (isset ($_GET['keyword_firstname'])) {
  240. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  241. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  242. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  243. $keyword_email = Database::escape_string($_GET['keyword_email']);
  244. $keyword_officialcode = Database::escape_string($_GET['keyword_officialcode']);
  245. $keyword_username = Database::escape_string($_GET['keyword_username']);
  246. $keyword_status = Database::escape_string($_GET['keyword_status']);
  247. $query_admin_table = '';
  248. $keyword_admin = '';
  249. if ($keyword_status == SESSIONADMIN) {
  250. $keyword_status = '%';
  251. $query_admin_table = " , $admin_table a ";
  252. $keyword_admin = ' AND a.user_id = u.user_id ';
  253. }
  254. $keyword_active = isset($_GET['keyword_active']);
  255. $keyword_inactive = isset($_GET['keyword_inactive']);
  256. $sql .= $query_admin_table .
  257. " WHERE (u.firstname LIKE '%".$keyword_firstname."%' " .
  258. "AND u.lastname LIKE '%".$keyword_lastname."%' " .
  259. "AND u.username LIKE '%".$keyword_username."%' " .
  260. "AND u.email LIKE '%".$keyword_email."%' " .
  261. "AND u.official_code LIKE '%".$keyword_officialcode."%' " .
  262. "AND u.status LIKE '".$keyword_status."'" .
  263. $keyword_admin;
  264. if($keyword_active && !$keyword_inactive) {
  265. $sql .= " AND u.active='1'";
  266. } elseif($keyword_inactive && !$keyword_active) {
  267. $sql .= " AND u.active='0'";
  268. }
  269. $sql .= " ) ";
  270. }
  271. // adding the filter to see the user's only of the current access_url
  272. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  273. $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  274. }
  275. $res = Database::query($sql, __FILE__, __LINE__);
  276. $obj = Database::fetch_object($res);
  277. return $obj->total_number_of_items;
  278. }
  279. /**
  280. * Get the users to display on the current page (fill the sortable-table)
  281. * @param int offset of first user to recover
  282. * @param int Number of users to get
  283. * @param int Column to sort on
  284. * @param string Order (ASC,DESC)
  285. * @see SortableTable#get_table_data($from)
  286. */
  287. function get_user_data($from, $number_of_items, $column, $direction)
  288. {
  289. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  290. $sql = "SELECT
  291. u.user_id AS col0,
  292. u.official_code AS col1,
  293. ".(api_is_western_name_order()
  294. ? "u.firstname AS col2,
  295. u.lastname AS col3,"
  296. : "u.lastname AS col2,
  297. u.firstname AS col3,")."
  298. u.username AS col4,
  299. u.email AS col5,
  300. u.status AS col6,
  301. u.active AS col7,
  302. u.user_id AS col8 ".
  303. ", u.expiration_date AS exp ".
  304. " FROM $user_table u ";
  305. // adding the filter to see the user's only of the current access_url
  306. global $_configuration;
  307. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  308. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  309. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  310. }
  311. if (isset ($_GET['keyword'])) {
  312. $keyword = Database::escape_string($_GET['keyword']);
  313. $sql .= " WHERE (u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' )";
  314. } elseif (isset ($_GET['keyword_firstname'])) {
  315. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  316. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  317. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  318. $keyword_email = Database::escape_string($_GET['keyword_email']);
  319. $keyword_officialcode = Database::escape_string($_GET['keyword_officialcode']);
  320. $keyword_username = Database::escape_string($_GET['keyword_username']);
  321. $keyword_status = Database::escape_string($_GET['keyword_status']);
  322. $query_admin_table = '';
  323. $keyword_admin = '';
  324. if ($keyword_status == SESSIONADMIN) {
  325. $keyword_status = '%';
  326. $query_admin_table = " , $admin_table a ";
  327. $keyword_admin = ' AND a.user_id = u.user_id ';
  328. }
  329. $keyword_active = isset($_GET['keyword_active']);
  330. $keyword_inactive = isset($_GET['keyword_inactive']);
  331. $sql .= $query_admin_table." WHERE (u.firstname LIKE '%".$keyword_firstname."%' " .
  332. "AND u.lastname LIKE '%".$keyword_lastname."%' " .
  333. "AND u.username LIKE '%".$keyword_username."%' " .
  334. "AND u.email LIKE '%".$keyword_email."%' " .
  335. "AND u.official_code LIKE '%".$keyword_officialcode."%' " .
  336. "AND u.status LIKE '".$keyword_status."'" .
  337. $keyword_admin;
  338. if ($keyword_active && !$keyword_inactive) {
  339. $sql .= " AND u.active='1'";
  340. } elseif($keyword_inactive && !$keyword_active) {
  341. $sql .= " AND u.active='0'";
  342. }
  343. $sql .= " ) ";
  344. }
  345. // adding the filter to see the user's only of the current access_url
  346. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  347. $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  348. }
  349. if (!in_array($direction, array('ASC','DESC'))) {
  350. $direction = 'ASC';
  351. }
  352. $column = intval($column);
  353. $from = intval($from);
  354. $number_of_items = intval($number_of_items);
  355. $sql .= " ORDER BY col$column $direction ";
  356. $sql .= " LIMIT $from,$number_of_items";
  357. $res = Database::query($sql, __FILE__, __LINE__);
  358. $users = array ();
  359. $t = time();
  360. while ($user = Database::fetch_row($res)) {
  361. if ($user[7] == 1 && $user[9] != '0000-00-00 00:00:00') {
  362. // check expiration date
  363. $expiration_time = convert_mysql_date($user[9]);
  364. // if expiration date is passed, store a special value for active field
  365. if ($expiration_time < $t) {
  366. $user[7] = '-1';
  367. }
  368. }
  369. // forget about the expiration date field
  370. $users[] = array($user[0],$user[1],$user[2],$user[3],$user[4],$user[5],$user[6],$user[7],$user[8]);
  371. }
  372. return $users;
  373. }
  374. /**
  375. * Returns a mailto-link
  376. * @param string $email An email-address
  377. * @return string HTML-code with a mailto-link
  378. */
  379. function email_filter($email)
  380. {
  381. return Display :: encrypted_mailto_link($email, $email);
  382. }
  383. /**
  384. * Build the modify-column of the table
  385. * @param int The user id
  386. * @param string URL params to add to table links
  387. * @param array Row of elements to alter
  388. * @return string Some HTML-code with modify-buttons
  389. */
  390. function modify_filter($user_id,$url_params,$row)
  391. {
  392. global $charset;
  393. global $_user;
  394. $statusname = api_get_status_langvars();
  395. $user_is_anonymous = false;
  396. if ($row['6'] == $statusname[ANONYMOUS]) {
  397. $user_is_anonymous =true;
  398. }
  399. if (!$user_is_anonymous) {
  400. $result .= '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')">
  401. <img onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" onmouseout="clear_course_list (\'div_'.$user_id.'\')" src="../img/course.gif" title="'.get_lang('Courses').'" alt="'.get_lang('Courses').'"/>
  402. <div class="blackboard_hide" id="div_'.$user_id.'">&nbsp;&nbsp;</div>
  403. </a>&nbsp;&nbsp;';
  404. } else {
  405. $result .= Display::return_icon('course_na.gif',get_lang('Courses')).'&nbsp;&nbsp;';
  406. }
  407. if (api_is_platform_admin()) {
  408. if (!$user_is_anonymous) {
  409. $result .= '<a href="user_information.php?user_id='.$user_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;&nbsp;';
  410. } else {
  411. $result .= Display::return_icon('synthese_view_na.gif', get_lang('Info')).'&nbsp;&nbsp;';
  412. }
  413. }
  414. //only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
  415. if (api_is_platform_admin() || (api_is_session_admin() && $row['6'] == $statusname[STUDENT])) {
  416. if (!$user_is_anonymous) {
  417. $result .= '<a href="user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
  418. } else {
  419. $result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).'&nbsp;&nbsp;';
  420. }
  421. } else {
  422. $result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).'&nbsp;&nbsp;';
  423. }
  424. if ($row['6'] != $statusname[STUDENT]) {
  425. $result .= Display::return_icon('statistics_na.gif', get_lang('Reporting')).'&nbsp;&nbsp;';
  426. } else {
  427. $result .= '<a href="../mySpace/myStudents.php?student='.$user_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;&nbsp;';
  428. }
  429. if (api_is_platform_admin()) {
  430. if (!$user_is_anonymous) {
  431. $result .= '<a href="user_edit.php?user_id='.$user_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>&nbsp;&nbsp;';
  432. } else {
  433. $result .= Display::return_icon('edit_na.gif', get_lang('Edit')).'</a>&nbsp;&nbsp;';
  434. }
  435. if ($row[0]<>$_user['user_id'] && $user_is_anonymous == false) {
  436. // 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.
  437. $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(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.Display::return_icon('delete.gif', get_lang('Delete')).'</a>';
  438. } else {
  439. $result .= Display::return_icon('delete_na.gif', get_lang('Delete'));
  440. }
  441. }
  442. return $result;
  443. }
  444. /**
  445. * Build the active-column of the table to lock or unlock a certain user
  446. * lock = the user can no longer use this account
  447. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  448. * @param int $active the current state of the account
  449. * @param int $user_id The user id
  450. * @param string $url_params
  451. * @return string Some HTML-code with the lock/unlock button
  452. */
  453. function active_filter($active, $url_params, $row) {
  454. global $_user;
  455. if ($active=='1') {
  456. $action='lock';
  457. $image='right';
  458. } elseif ($active=='-1') {
  459. $action='edit';
  460. $image='expired';
  461. } elseif ($active=='0') {
  462. $action='unlock';
  463. $image='wrong';
  464. }
  465. if ($action=='edit') {
  466. $result = Display::return_icon($image.'.gif', get_lang('AccountExpired'));
  467. }elseif ($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.
  468. $result = '<a href="user_list.php?action='.$action.'&amp;user_id='.$row['0'].'&amp;'.$url_params.'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon($image.'.gif', get_lang(ucfirst($action))).'</a>';
  469. }
  470. return $result;
  471. }
  472. /**
  473. * Lock or unlock a user
  474. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  475. * @param int $status, do we want to lock the user ($status=lock) or unlock it ($status=unlock)
  476. * @param int $user_id The user id
  477. * @return language variable
  478. */
  479. function lock_unlock_user($status,$user_id)
  480. {
  481. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  482. if ($status=='lock')
  483. {
  484. $status_db='0';
  485. $return_message=get_lang('UserLocked');
  486. }
  487. if ($status=='unlock')
  488. {
  489. $status_db='1';
  490. $return_message=get_lang('UserUnlocked');
  491. }
  492. if(($status_db=='1' OR $status_db=='0') AND is_numeric($user_id))
  493. {
  494. $sql="UPDATE $user_table SET active='".Database::escape_string($status_db)."' WHERE user_id='".Database::escape_string($user_id)."'";
  495. $result = Database::query($sql, __FILE__, __LINE__);
  496. }
  497. if ($result)
  498. {
  499. return $return_message;
  500. }
  501. }
  502. /**
  503. * Instead of displaying the integer of the status, we give a translation for the status
  504. *
  505. * @param integer $status
  506. * @return string translation
  507. *
  508. * @version march 2008
  509. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  510. */
  511. function status_filter($status)
  512. {
  513. $statusname = api_get_status_langvars();
  514. return $statusname[$status];
  515. }
  516. /**
  517. ==============================================================================
  518. INIT SECTION
  519. ==============================================================================
  520. */
  521. $action = $_GET["action"];
  522. $login_as_user_id = $_GET["user_id"];
  523. // Login as ...
  524. if ($_GET['action'] == "login_as" && isset ($login_as_user_id))
  525. {
  526. login_user($login_as_user_id);
  527. }
  528. if (isset ($_GET['search']) && $_GET['search'] == 'advanced')
  529. {
  530. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  531. $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
  532. $tool_name = get_lang('SearchAUser');
  533. Display :: display_header($tool_name);
  534. //api_display_tool_title($tool_name);
  535. $form = new FormValidator('advanced_search','get');
  536. $form->addElement('header', '', $tool_name);
  537. $form->add_textfield('keyword_firstname',get_lang('FirstName'),false);
  538. $form->add_textfield('keyword_lastname',get_lang('LastName'),false);
  539. $form->add_textfield('keyword_username',get_lang('LoginName'),false);
  540. $form->add_textfield('keyword_email',get_lang('Email'),false);
  541. $form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false);
  542. $status_options = array();
  543. $status_options['%'] = get_lang('All');
  544. $status_options[STUDENT] = get_lang('Student');
  545. $status_options[COURSEMANAGER] = get_lang('Teacher');
  546. $status_options[SESSIONADMIN] = get_lang('Administrator');//
  547. $form->addElement('select','keyword_status',get_lang('Status'),$status_options);
  548. $active_group = array();
  549. $active_group[] = $form->createElement('checkbox','keyword_active','',get_lang('Active'));
  550. $active_group[] = $form->createElement('checkbox','keyword_inactive','',get_lang('Inactive'));
  551. $form->addGroup($active_group,'',get_lang('ActiveAccount'),'<br/>',false);
  552. $form->addElement('style_submit_button', 'submit',get_lang('SearchUsers'),'class="search"');
  553. $defaults['keyword_active'] = 1;
  554. $defaults['keyword_inactive'] = 1;
  555. $form->setDefaults($defaults);
  556. $form->display();
  557. }
  558. else
  559. {
  560. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  561. $tool_name = get_lang('UserList');
  562. Display :: display_header($tool_name, "");
  563. //api_display_tool_title($tool_name);
  564. if (isset ($_GET['action'])) {
  565. $check = Security::check_token('get');
  566. if($check) {
  567. switch ($_GET['action']) {
  568. case 'show_message' :
  569. if (!empty($_GET['warn'])) {
  570. Display::display_warning_message(urldecode($_GET['warn']),false);
  571. }
  572. if (!empty($_GET['message'])) {
  573. Display :: display_confirmation_message(stripslashes($_GET['message']));
  574. }
  575. break;
  576. case 'delete_user' :
  577. if (api_is_platform_admin()) {
  578. if ($user_id != $_user['user_id'] && UserManager :: delete_user($_GET['user_id'])) {
  579. Display :: display_normal_message(get_lang('UserDeleted'));
  580. } else {
  581. Display :: display_error_message(get_lang('CannotDeleteUserBecauseOwnsCourse'));
  582. }
  583. }
  584. break;
  585. case 'lock' :
  586. $message=lock_unlock_user('lock',$_GET['user_id']);
  587. Display :: display_normal_message($message);
  588. break;
  589. case 'unlock';
  590. $message=lock_unlock_user('unlock',$_GET['user_id']);
  591. Display :: display_normal_message($message);
  592. break;
  593. }
  594. Security::clear_token();
  595. }
  596. }
  597. if (isset ($_POST['action']))
  598. {
  599. $check = Security::check_token('get');
  600. if($check)
  601. {
  602. switch ($_POST['action'])
  603. {
  604. case 'delete' :
  605. if (api_is_platform_admin()) {
  606. $number_of_selected_users = count($_POST['id']);
  607. $number_of_deleted_users = 0;
  608. if (is_array($_POST['id'])) {
  609. foreach ($_POST['id'] as $index => $user_id)
  610. {
  611. if($user_id != $_user['user_id'])
  612. {
  613. if(UserManager :: delete_user($user_id))
  614. {
  615. $number_of_deleted_users++;
  616. }
  617. }
  618. }
  619. }
  620. if($number_of_selected_users == $number_of_deleted_users)
  621. {
  622. Display :: display_normal_message(get_lang('SelectedUsersDeleted'));
  623. }
  624. else
  625. {
  626. Display :: display_error_message(get_lang('SomeUsersNotDeleted'));
  627. }
  628. }
  629. break;
  630. }
  631. Security::clear_token();
  632. }
  633. }
  634. // Create a search-box
  635. $form = new FormValidator('search_simple','get','','',null,false);
  636. $renderer =& $form->defaultRenderer();
  637. $renderer->setElementTemplate('<span>{element}</span> ');
  638. $form->addElement('text','keyword',get_lang('keyword'));
  639. $form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"');
  640. $form->addElement('static','search_advanced_link',null,'<a href="user_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  641. echo '<div class="actions" style="width:100%;">';
  642. if (api_is_platform_admin()) {
  643. echo '<span style="float:right; padding-top:7px;">'.
  644. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_add.php">'.Display::return_icon('add_user_big.gif',get_lang('AddUsers')).get_lang('AddUsers').'</a>'.
  645. '</span>';
  646. }
  647. $form->display();
  648. echo '</div>';
  649. if (isset ($_GET['keyword'])) {
  650. $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
  651. } elseif (isset ($_GET['keyword_firstname'])) {
  652. $parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
  653. $parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
  654. $parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
  655. $parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
  656. $parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
  657. $parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
  658. $parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
  659. }
  660. // Create a sortable table with user-data
  661. $parameters['sec_token'] = Security::get_token();
  662. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
  663. $table->set_additional_parameters($parameters);
  664. $table->set_header(0, '', false);
  665. $table->set_header(1, get_lang('OfficialCode'));
  666. if (api_is_western_name_order()) {
  667. $table->set_header(2, get_lang('FirstName'));
  668. $table->set_header(3, get_lang('LastName'));
  669. } else {
  670. $table->set_header(2, get_lang('LastName'));
  671. $table->set_header(3, get_lang('FirstName'));
  672. }
  673. $table->set_header(4, get_lang('LoginName'));
  674. $table->set_header(5, get_lang('Email'));
  675. $table->set_header(6, get_lang('Status'));
  676. $table->set_header(7, get_lang('Active'));
  677. $table->set_header(8, get_lang('Modify'));
  678. $table->set_column_filter(5, 'email_filter');
  679. $table->set_column_filter(6, 'status_filter');
  680. $table->set_column_filter(7, 'active_filter');
  681. $table->set_column_filter(8, 'modify_filter');
  682. if (api_is_platform_admin())
  683. $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
  684. $table->display();
  685. }
  686. /*
  687. ==============================================================================
  688. FOOTER
  689. ==============================================================================
  690. */
  691. Display :: display_footer();
  692. ?>