user_list.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. @author Bart Mollet
  5. @author Julio Montoya <gugli100@gmail.com> BeezNest 2011
  6. * @package chamilo.admin
  7. */
  8. // name of the language file that needs to be included
  9. $language_file = array ('registration','admin');
  10. $cidReset = true;
  11. require_once '../inc/global.inc.php';
  12. global $_configuration;
  13. $current_access_url_id = api_get_current_access_url_id();
  14. $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : null;
  15. // Blocks the possibility to delete a user
  16. $delete_user_available = true;
  17. if (isset($_configuration['deny_delete_users']) && $_configuration['deny_delete_users']) {
  18. $delete_user_available = false;
  19. }
  20. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=get_user_courses';
  21. $urlSession = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=get_user_sessions';
  22. $htmlHeadXtra[] = '<script>
  23. function load_course_list (div_course,my_user_id) {
  24. $.ajax({
  25. contentType: "application/x-www-form-urlencoded",
  26. beforeSend: function(objeto) {
  27. $("div#"+div_course).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  28. type: "POST",
  29. url: "'.$url.'",
  30. data: "user_id="+my_user_id,
  31. success: function(datos) {
  32. $("div#"+div_course).html(datos);
  33. $("div#div_"+my_user_id).attr("class","blackboard_show");
  34. $("div#div_"+my_user_id).attr("style","");
  35. }
  36. });
  37. }
  38. function load_session_list (div_session,my_user_id) {
  39. $.ajax({
  40. contentType: "application/x-www-form-urlencoded",
  41. beforeSend: function(objeto) {
  42. $("div#"+div_session).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  43. type: "POST",
  44. url: "'.$urlSession.'",
  45. data: "user_id="+my_user_id,
  46. success: function(datos) {
  47. $("div#"+div_session).html(datos);
  48. $("div#div_s_"+my_user_id).attr("class","blackboard_show");
  49. $("div#div_s_"+my_user_id).attr("style","");
  50. }
  51. });
  52. }
  53. function active_user(element_div) {
  54. id_image=$(element_div).attr("id");
  55. image_clicked=$(element_div).attr("src");
  56. image_clicked_info = image_clicked.split("/");
  57. image_real_clicked = image_clicked_info[image_clicked_info.length-1];
  58. var status = 1;
  59. if (image_real_clicked == "accept.png") {
  60. status = 0;
  61. }
  62. user_id=id_image.split("_");
  63. ident="#img_"+user_id[1];
  64. if (confirm("'.get_lang('AreYouSureToEditTheUserStatus', '').'")) {
  65. $.ajax({
  66. contentType: "application/x-www-form-urlencoded",
  67. beforeSend: function(objeto) {
  68. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'loading1.gif'.'"); }, //candy eye stuff
  69. type: "GET",
  70. url: "'.api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=active_user",
  71. data: "user_id="+user_id[1]+"&status="+status,
  72. success: function(data) {
  73. if (data == 1) {
  74. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/accept.png'.'");
  75. $(ident).attr("title","'.get_lang('Lock').'");
  76. }
  77. if (data == 0) {
  78. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/error.png'.'");
  79. $(ident).attr("title","'.get_lang('Unlock').'");
  80. }
  81. if (data == -1) {
  82. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/warning.png'.'");
  83. $(ident).attr("title","'.get_lang('ActionNotAllowed').'");
  84. }
  85. }
  86. });
  87. }
  88. }
  89. function clear_course_list(div_course) {
  90. $("div#"+div_course).html("&nbsp;");
  91. $("div#"+div_course).hide("");
  92. }
  93. function clear_session_list(div_session) {
  94. $("div#"+div_session).html("&nbsp;");
  95. $("div#"+div_session).hide("");
  96. }
  97. function display_advanced_search_form () {
  98. if ($("#advanced_search_form").css("display") == "none") {
  99. $("#advanced_search_form").css("display","block");
  100. $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedSearch').'\');
  101. } else {
  102. $("#advanced_search_form").css("display","none");
  103. $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedSearch').'\');
  104. }
  105. }
  106. $(document).ready(function() {
  107. var select_val = $("#input_select_extra_data").val();
  108. if ( document.getElementById(\'extra_data_text\')) {
  109. if (select_val != 0) {
  110. document.getElementById(\'extra_data_text\').style.display="block";
  111. if (document.getElementById(\'input_extra_text\'))
  112. document.getElementById(\'input_extra_text\').value = "";
  113. } else {
  114. document.getElementById(\'extra_data_text\').style.display="none";
  115. }
  116. }
  117. $(".agenda_opener").live("click", function() {
  118. var url = this.href;
  119. var dialog = $("#dialog");
  120. if ($("#dialog").length == 0) {
  121. dialog = $(\'<div id="dialog" style="display:hidden"></div> \').appendTo(\'body\');
  122. }
  123. // load remote content
  124. dialog.load(
  125. url,
  126. {},
  127. function(responseText, textStatus, XMLHttpRequest) {
  128. dialog.dialog({width:720, height:550, modal:true});
  129. }
  130. );
  131. //prevent the browser to follow the link
  132. return false;
  133. });
  134. });
  135. //Load user calendar
  136. function load_calendar(user_id, month, year) {
  137. var url = "'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&user_id=" +user_id + "&month="+month+"&year="+year;
  138. $("#dialog").load(url);
  139. }
  140. </script>';
  141. $this_section = SECTION_PLATFORM_ADMIN;
  142. if ($action == 'login_as') {
  143. $check = Security::check_token('get');
  144. if (isset($_GET['user_id']) && api_can_login_as($_GET['user_id']) && $check) {
  145. login_user($_GET['user_id']);
  146. } else {
  147. api_not_allowed(true);
  148. }
  149. Security::clear_token();
  150. }
  151. api_protect_admin_script(true);
  152. /**
  153. * Prepares the shared SQL query for the user table.
  154. * See get_user_data() and get_number_of_users().
  155. *
  156. * @param boolean $is_count Whether to count, or get data
  157. * @return string SQL query
  158. */
  159. function prepare_user_sql_query($is_count) {
  160. $sql = "";
  161. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  162. $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  163. if ($is_count) {
  164. $sql .= "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
  165. } else {
  166. $sql .= "SELECT u.user_id AS col0, u.official_code AS col2, ";
  167. if (api_is_western_name_order()) {
  168. $sql .= "u.firstname AS col3, u.lastname AS col4, ";
  169. } else {
  170. $sql .= "u.lastname AS col3, u.firstname AS col4, ";
  171. }
  172. $sql .= " u.username AS col5,
  173. u.email AS col6,
  174. u.status AS col7,
  175. u.active AS col8,
  176. u.user_id AS col9,
  177. u.registration_date AS col10,
  178. u.expiration_date AS exp,
  179. u.password
  180. FROM $user_table u";
  181. }
  182. // adding the filter to see the user's only of the current access_url
  183. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  184. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  185. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  186. }
  187. $keywordList = array(
  188. 'keyword_firstname',
  189. 'keyword_lastname',
  190. 'keyword_username',
  191. 'keyword_email',
  192. 'keyword_officialcode',
  193. 'keyword_status',
  194. 'keyword_active',
  195. 'check_easy_passwords'
  196. );
  197. $keywordListValues = array();
  198. $atLeastOne = false;
  199. foreach ($keywordList as $keyword) {
  200. $keywordListValues[$keyword] = null;
  201. if (isset($_GET[$keyword]) && !empty($_GET[$keyword])) {
  202. $keywordListValues[$keyword] = $_GET[$keyword];
  203. $atLeastOne = true;
  204. }
  205. }
  206. if ($atLeastOne == false) {
  207. $keywordListValues = array();
  208. }
  209. if (isset($keyword_extra_data) && !empty($keyword_extra_data)) {
  210. $extra_info = UserManager::get_extra_field_information_by_name($keyword_extra_data);
  211. $field_id = $extra_info['id'];
  212. $sql.= " INNER JOIN user_field_values ufv ON u.user_id=ufv.user_id AND ufv.field_id=$field_id ";
  213. }
  214. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  215. $keywordFiltered = Database::escape_string("%". $_GET['keyword'] ."%");
  216. $sql .= " WHERE (
  217. u.firstname LIKE '$keywordFiltered' OR
  218. u.lastname LIKE '$keywordFiltered' OR
  219. concat(u.firstname, ' ', u.lastname) LIKE '$keywordFiltered' OR
  220. concat(u.lastname,' ',u.firstname) LIKE '$keywordFiltered' OR
  221. u.username LIKE '$keywordFiltered' OR
  222. u.official_code LIKE '$keywordFiltered' OR
  223. u.email LIKE '$keywordFiltered'
  224. )
  225. ";
  226. } elseif (isset($keywordListValues) && !empty($keywordListValues)) {
  227. $query_admin_table = '';
  228. $keyword_admin = '';
  229. if (isset($keywordListValues['keyword_status']) &&
  230. $keywordListValues['keyword_status'] == PLATFORM_ADMIN
  231. ) {
  232. $query_admin_table = " , $admin_table a ";
  233. $keyword_admin = ' AND a.user_id = u.user_id ';
  234. $keywordListValues['keyword_status'] = '%';
  235. }
  236. $keyword_extra_value = '';
  237. if (isset($keyword_extra_data) && !empty($keyword_extra_data) &&
  238. !empty($keyword_extra_data_text)) {
  239. $keyword_extra_value = " AND ufv.field_value LIKE '%".trim($keyword_extra_data_text)."%' ";
  240. }
  241. $sql .= " $query_admin_table
  242. WHERE (
  243. u.firstname LIKE '". Database::escape_string("%".$keywordListValues['keyword_firstname']."%")."' AND
  244. u.lastname LIKE '". Database::escape_string("%".$keywordListValues['keyword_lastname']."%")."' AND
  245. u.username LIKE '". Database::escape_string("%".$keywordListValues['keyword_username']."%")."' AND
  246. u.email LIKE '". Database::escape_string("%".$keywordListValues['keyword_email']."%")."' AND
  247. u.official_code LIKE '". Database::escape_string("%".$keywordListValues['keyword_officialcode']."%")."' AND
  248. u.status LIKE '".Database::escape_string($keywordListValues['keyword_status'])."'
  249. $keyword_admin
  250. $keyword_extra_value
  251. ";
  252. if (isset($keyword_active) && !isset($keyword_inactive)) {
  253. $sql .= " AND u.active='1'";
  254. } elseif(isset($keyword_inactive) && !isset($keyword_active)) {
  255. $sql .= " AND u.active='0'";
  256. }
  257. $sql .= " ) ";
  258. }
  259. // adding the filter to see the user's only of the current access_url
  260. if ((api_is_platform_admin() || api_is_session_admin())
  261. && api_get_multiple_access_url()
  262. ) {
  263. $sql .= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  264. }
  265. return $sql;
  266. }
  267. /**
  268. * Make sure this function is protected because it does NOT check password!
  269. *
  270. * This function defines globals.
  271. * @param int User ID
  272. * @return bool False on failure, redirection on success
  273. * @author Evie Embrechts
  274. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  275. */
  276. function login_user($user_id) {
  277. $user_id = intval($user_id);
  278. $user_info = api_get_user_info($user_id);
  279. // Check if the user is allowed to 'login_as'
  280. $can_login_as = api_can_login_as($user_id);
  281. if (!$can_login_as) {
  282. return false;
  283. }
  284. //Load $_user to be sure we clean it before logging in
  285. global $uidReset, $loginFailed, $_user;
  286. $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
  287. $main_admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  288. $track_e_login_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  289. unset($_user['user_id']); // uid not in session ? prevent any hacking
  290. $firstname = $user_info['firstname'];
  291. $lastname = $user_info['lastname'];
  292. $user_id = $user_info['user_id'];
  293. //$message = "Attempting to login as ".api_get_person_name($firstname, $lastname)." (id ".$user_id.")";
  294. if (api_is_western_name_order()) {
  295. $message = sprintf(get_lang('AttemptingToLoginAs'),$firstname,$lastname,$user_id);
  296. } else {
  297. $message = sprintf(get_lang('AttemptingToLoginAs'), $lastname, $firstname, $user_id);
  298. }
  299. $loginFailed = false;
  300. $uidReset = false;
  301. if ($user_id) { // a uid is given (log in succeeded)
  302. $sql_query = "SELECT user.*, a.user_id is_admin,
  303. UNIX_TIMESTAMP(login.login_date) login_date
  304. FROM $main_user_table
  305. LEFT JOIN $main_admin_table a
  306. ON user.user_id = a.user_id
  307. LEFT JOIN $track_e_login_table login
  308. ON user.user_id = login.login_user_id
  309. WHERE user.user_id = '".$user_id."'
  310. ORDER BY login.login_date DESC LIMIT 1";
  311. $sql_result = Database::query($sql_query);
  312. if (Database::num_rows($sql_result) > 0) {
  313. // Extracting the user data
  314. $user_data = Database::fetch_array($sql_result);
  315. //Delog the current user
  316. LoginDelete($_SESSION["_user"]["user_id"]);
  317. // Cleaning session variables
  318. unset($_SESSION['_user']);
  319. unset($_SESSION['is_platformAdmin']);
  320. unset($_SESSION['is_allowedCreateCourse']);
  321. unset($_SESSION['_uid']);
  322. $_user['firstName'] = $user_data['firstname'];
  323. $_user['lastName'] = $user_data['lastname'];
  324. $_user['mail'] = $user_data['email'];
  325. $_user['lastLogin'] = $user_data['login_date'];
  326. $_user['official_code'] = $user_data['official_code'];
  327. $_user['picture_uri'] = $user_data['picture_uri'];
  328. $_user['user_id'] = $user_data['user_id'];
  329. $_user['status'] = $user_data['status'];
  330. $is_platformAdmin = (bool) (!is_null($user_data['is_admin']));
  331. $is_allowedCreateCourse = (bool) ($user_data['status'] == 1);
  332. // Filling session variables with new data
  333. $_SESSION['_uid'] = $user_id;
  334. $_SESSION['_user'] = $_user;
  335. $_SESSION['is_platformAdmin'] = $is_platformAdmin;
  336. $_SESSION['is_allowedCreateCourse'] = $is_allowedCreateCourse;
  337. $_SESSION['login_as'] = true; // will be useful later to know if the user is actually an admin or not (example reporting)s
  338. $target_url = api_get_path(WEB_PATH)."user_portal.php";
  339. $message .= '<br />'.sprintf(get_lang('LoginSuccessfulGoToX'),'<a href="'.$target_url.'">'.$target_url.'</a>');
  340. Display :: display_header(get_lang('UserList'));
  341. Display :: display_normal_message($message,false);
  342. Display :: display_footer();
  343. exit;
  344. } else {
  345. exit ("<br />WARNING UNDEFINED UID !! ");
  346. }
  347. }
  348. }
  349. /**
  350. * Get the total number of users on the platform
  351. * @see SortableTable#get_total_number_of_items()
  352. */
  353. function get_number_of_users() {
  354. $sql = prepare_user_sql_query(true);
  355. $res = Database::query($sql);
  356. $obj = Database::fetch_object($res);
  357. return $obj->total_number_of_items;
  358. }
  359. /**
  360. * Get the users to display on the current page (fill the sortable-table)
  361. * @param int offset of first user to recover
  362. * @param int Number of users to get
  363. * @param int Column to sort on
  364. * @param string Order (ASC,DESC)
  365. * @see SortableTable#get_table_data($from)
  366. */
  367. function get_user_data($from, $number_of_items, $column, $direction) {
  368. $sql = prepare_user_sql_query(false);
  369. $checkPassStrength = isset($_GET['check_easy_passwords']) && $_GET['check_easy_passwords'] == 1 ? true : false;
  370. if ($checkPassStrength) {
  371. $easyPasswordList = api_get_easy_password_list();
  372. $easyPasswordList = array_map('api_get_encrypted_password', $easyPasswordList);
  373. $easyPasswordList = array_map(array('Database', 'escape_string'), $easyPasswordList);
  374. $easyPassword = implode("' OR password LIKE '", $easyPasswordList);
  375. $sql .= "AND password LIKE '$easyPassword' ";
  376. }
  377. if (!in_array($direction, array('ASC','DESC'))) {
  378. $direction = 'ASC';
  379. }
  380. $column = intval($column);
  381. $from = intval($from);
  382. $number_of_items = intval($number_of_items);
  383. global $_configuration;
  384. if (api_is_session_admin()
  385. && isset($_configuration['prevent_session_admins_to_manage_all_users'])
  386. && $_configuration['prevent_session_admins_to_manage_all_users'] == 'true'
  387. ) {
  388. $sql .= " WHERE u.creator_id = " . api_get_user_id();
  389. }
  390. $sql .= " ORDER BY col$column $direction ";
  391. $sql .= " LIMIT $from,$number_of_items";
  392. $res = Database::query($sql);
  393. $users = array ();
  394. $t = time();
  395. while ($user = Database::fetch_row($res)) {
  396. $image_path = UserManager::get_user_picture_path_by_id($user[0], 'web', false, true);
  397. $user_profile = UserManager::get_picture_user($user[0], $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
  398. if (!api_is_anonymous()) {
  399. $photo = '<center><a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$user[0].'" title="'.get_lang('Info').'">
  400. <img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($user[2],$user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" /></a></center>';
  401. } else {
  402. $photo = '<center><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.api_get_person_name($user[2], $user[3]).'" title="'.api_get_person_name($user[2], $user[3]).'" /></center>';
  403. }
  404. if ($user[7] == 1 && $user[10] != '0000-00-00 00:00:00') {
  405. // check expiration date
  406. $expiration_time = convert_sql_date($user[10]);
  407. // if expiration date is passed, store a special value for active field
  408. if ($expiration_time < $t) {
  409. $user[7] = '-1';
  410. }
  411. }
  412. // forget about the expiration date field
  413. $users[] = array($user[0], $photo, $user[1],$user[2], $user[3], $user[4], $user[5], $user[6], $user[7], api_get_local_time($user[9]), $user[0]);
  414. }
  415. return $users;
  416. }
  417. /**
  418. * Returns a mailto-link
  419. * @param string $email An email-address
  420. * @return string HTML-code with a mailto-link
  421. */
  422. function email_filter($email) {
  423. return Display :: encrypted_mailto_link($email, $email);
  424. }
  425. /**
  426. * Returns a mailto-link
  427. * @param string $email An email-address
  428. * @return string HTML-code with a mailto-link
  429. */
  430. function user_filter($name, $params, $row) {
  431. return '<a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$row[0].'">'.$name.'</a>';
  432. }
  433. /**
  434. * Build the modify-column of the table
  435. * @param int The user id
  436. * @param string URL params to add to table links
  437. * @param array Row of elements to alter
  438. * @return string Some HTML-code with modify-buttons
  439. */
  440. function modify_filter($user_id, $url_params, $row) {
  441. global $charset, $_admins_list, $delete_user_available;
  442. $is_admin = in_array($user_id,$_admins_list);
  443. $statusname = api_get_status_langvars();
  444. $user_is_anonymous = false;
  445. $current_user_status_label = $row['7'];
  446. if ($current_user_status_label == $statusname[ANONYMOUS]) {
  447. $user_is_anonymous =true;
  448. }
  449. $result = '';
  450. if (!$user_is_anonymous) {
  451. $icon = Display::return_icon('course.png', get_lang('Courses'), array('onmouseout' => 'clear_course_list (\'div_'.$user_id.'\')'));
  452. $result .= '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" >
  453. '.$icon.'
  454. <div class="blackboard_hide" id="div_'.$user_id.'">&nbsp;&nbsp;</div>
  455. </a>';
  456. $icon = Display::return_icon('session.png', get_lang('Sessions'), array('onmouseout' => 'clear_session_list (\'div_s_'.$user_id.'\')'));
  457. $result .= '<a href="javascript:void(0)" onclick="load_session_list(\'div_s_'.$user_id.'\','.$user_id.')" >
  458. '.$icon.'
  459. <div class="blackboard_hide" id="div_s_'.$user_id.'">&nbsp;&nbsp;</div>
  460. </a>';
  461. } else {
  462. $result .= Display::return_icon('course_na.png',get_lang('Courses')).'&nbsp;&nbsp;';
  463. $result .= Display::return_icon('course_na.png',get_lang('Sessions')).'&nbsp;&nbsp;';
  464. }
  465. if (api_is_platform_admin()) {
  466. if (!$user_is_anonymous) {
  467. $result .= '<a href="user_information.php?user_id='.$user_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;&nbsp;';
  468. } else {
  469. $result .= Display::return_icon('synthese_view_na.gif', get_lang('Info')).'&nbsp;&nbsp;';
  470. }
  471. }
  472. //only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
  473. if (api_is_platform_admin() || (api_is_session_admin() && $current_user_status_label == $statusname[STUDENT])) {
  474. if (!$user_is_anonymous) {
  475. if (api_global_admin_can_edit_admin($user_id)) {
  476. $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.png', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
  477. } else {
  478. $result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;&nbsp;';
  479. }
  480. } else {
  481. $result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;&nbsp;';
  482. }
  483. } else {
  484. $result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;&nbsp;';
  485. }
  486. if ($current_user_status_label != $statusname[STUDENT]) {
  487. $result .= Display::return_icon('statistics_na.gif', get_lang('Reporting')).'&nbsp;&nbsp;';
  488. } else {
  489. $result .= '<a href="../mySpace/myStudents.php?student='.$user_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;&nbsp;';
  490. }
  491. if (api_is_platform_admin(true)) {
  492. if (!$user_is_anonymous && api_global_admin_can_edit_admin($user_id, null, true)) {
  493. $result .= '<a href="user_edit.php?user_id='.$user_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
  494. } else {
  495. $result .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
  496. }
  497. }
  498. if ($is_admin) {
  499. $result .= Display::return_icon('admin_star.png', get_lang('IsAdministrator'),array('width'=> ICON_SIZE_SMALL, 'heigth'=> ICON_SIZE_SMALL));
  500. } else {
  501. $result .= Display::return_icon('admin_star_na.png', get_lang('IsNotAdministrator'));
  502. }
  503. // actions for assigning sessions, courses or users
  504. if (api_is_session_admin()) {
  505. /*if ($row[0] == api_get_user_id()) {
  506. $result .= '<a href="dashboard_add_sessions_to_user.php?user='.$user_id.'">'.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')).'</a>&nbsp;&nbsp;';
  507. }*/
  508. } else {
  509. if ($current_user_status_label == $statusname[DRH] || UserManager::is_admin($user_id)) {
  510. $result .= '<a href="dashboard_add_users_to_user.php?user='.$user_id.'">'.Display::return_icon('user_subscribe_course.png', get_lang('AssignUsers'),'',ICON_SIZE_SMALL).'</a>';
  511. $result .= '<a href="dashboard_add_courses_to_user.php?user='.$user_id.'">'.Display::return_icon('course_add.gif', get_lang('AssignCourses')).'</a>&nbsp;&nbsp;';
  512. $result .= '<a href="dashboard_add_sessions_to_user.php?user='.$user_id.'">'.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')).'</a>&nbsp;&nbsp;';
  513. } else if ($current_user_status_label == $statusname[SESSIONADMIN]) {
  514. $result .= '<a href="dashboard_add_sessions_to_user.php?user='.$user_id.'">'.Display::return_icon('view_more_stats.gif', get_lang('AssignSessions')).'</a>&nbsp;&nbsp;';
  515. }
  516. }
  517. if (api_is_platform_admin()) {
  518. $result .= ' <a href="'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&amp;user_id='.$user_id.'" class="agenda_opener">'.Display::return_icon('month.png', get_lang('FreeBusyCalendar'), array(), ICON_SIZE_SMALL).'</a>';
  519. if ($delete_user_available) {
  520. if ($user_id != api_get_user_id() && !$user_is_anonymous && api_global_admin_can_edit_admin($user_id)) {
  521. // 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.
  522. $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.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  523. } else {
  524. $result .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), ICON_SIZE_SMALL);
  525. }
  526. }
  527. }
  528. return $result;
  529. }
  530. /**
  531. * Build the active-column of the table to lock or unlock a certain user
  532. * lock = the user can no longer use this account
  533. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  534. * @param int $active the current state of the account
  535. * @param int $user_id The user id
  536. * @param string $url_params
  537. * @return string Some HTML-code with the lock/unlock button
  538. */
  539. function active_filter($active, $url_params, $row) {
  540. global $_user;
  541. if ($active=='1') {
  542. $action='Lock';
  543. $image='accept';
  544. } elseif ($active=='-1') {
  545. $action='edit';
  546. $image='warning';
  547. } elseif ($active=='0') {
  548. $action='Unlock';
  549. $image='error';
  550. }
  551. $result = '';
  552. if ($action=='edit') {
  553. $result = Display::return_icon($image.'.png', get_lang('AccountExpired'), array(), 16);
  554. } elseif ($row['0']<>$_user['user_id']) {
  555. // 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.
  556. $result = Display::return_icon($image.'.png', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0']), 16).'</a>';
  557. }
  558. return $result;
  559. }
  560. /**
  561. * Instead of displaying the integer of the status, we give a translation for the status
  562. *
  563. * @param integer $status
  564. * @return string translation
  565. *
  566. * @version march 2008
  567. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  568. */
  569. function status_filter($status) {
  570. $statusname = api_get_status_langvars();
  571. return $statusname[$status];
  572. }
  573. if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
  574. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  575. $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
  576. $tool_name = get_lang('SearchUsers');
  577. } else {
  578. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  579. $tool_name = get_lang('UserList');
  580. }
  581. $message = '';
  582. if (!empty($action)) {
  583. $check = Security::check_token('get');
  584. if ($check) {
  585. switch ($action) {
  586. case 'add_user_to_my_url':
  587. $user_id = $_REQUEST["user_id"];
  588. $result = UrlManager::add_user_to_url($user_id, $current_access_url_id);
  589. if ($result ) {
  590. $user_info = api_get_user_info($user_id);
  591. $message = get_lang('UserAdded').' '.$user_info['firstname'].' '.$user_info['lastname'].' ('.$user_info['username'].')';
  592. $message = Display::return_message($message, 'confirmation');
  593. }
  594. break;
  595. case 'show_message' :
  596. if (!empty($_GET['warn'])) {
  597. // to prevent too long messages
  598. if ($_GET['warn'] == 'session_message') {
  599. $_GET['warn'] = $_SESSION['session_message_import_users'];
  600. }
  601. if (isset($_GET['warn']) && !empty($_GET['warn'])) {
  602. $message .= Display::return_message(
  603. Security::remove_XSS($_GET['warn']),
  604. 'warning',
  605. false
  606. );
  607. }
  608. }
  609. if (!empty($_GET['message'])) {
  610. $message .= Display::return_message(stripslashes($_GET['message']), 'confirmation');
  611. }
  612. break;
  613. case 'delete_user' :
  614. if (api_is_platform_admin()) {
  615. $user_to_delete = $_GET['user_id'];
  616. $current_user_id = api_get_user_id();
  617. if ($delete_user_available && api_global_admin_can_edit_admin($_GET['user_id'])) {
  618. if ($user_to_delete != $current_user_id && UserManager :: delete_user($_GET['user_id'])) {
  619. $message = Display :: return_message(get_lang('UserDeleted'), 'confirmation');
  620. } else {
  621. $message = Display :: return_message(get_lang('CannotDeleteUserBecauseOwnsCourse'), 'error');
  622. }
  623. } else {
  624. $message = Display :: return_message(get_lang('CannotDeleteUser'),'error');
  625. }
  626. }
  627. break;
  628. case 'delete' :
  629. if (api_is_platform_admin()) {
  630. $number_of_selected_users = count($_POST['id']);
  631. $number_of_deleted_users = 0;
  632. if (is_array($_POST['id'])) {
  633. foreach ($_POST['id'] as $index => $user_id) {
  634. if($user_id != $_user['user_id']) {
  635. if(UserManager :: delete_user($user_id)) {
  636. $number_of_deleted_users++;
  637. }
  638. }
  639. }
  640. }
  641. if ($number_of_selected_users == $number_of_deleted_users) {
  642. $message = Display :: return_message(get_lang('SelectedUsersDeleted'), 'confirmation');
  643. } else {
  644. $message = Display :: return_message(get_lang('SomeUsersNotDeleted'), 'error');
  645. }
  646. }
  647. break;
  648. }
  649. Security::clear_token();
  650. }
  651. }
  652. // Create a search-box
  653. $form = new FormValidator('search_simple', 'get', '', '', array('class' => 'form-search'), false);
  654. $renderer = & $form->defaultRenderer();
  655. $renderer->setElementTemplate('<span>{element}</span> ');
  656. $form->addElement('text','keyword', get_lang('keyword'), 'size="25"');
  657. $form->addElement('style_submit_button', 'submit', get_lang('Search'),'class="btn"');
  658. $form->addElement(
  659. 'static',
  660. 'search_advanced_link',
  661. null,
  662. '<a href="javascript://" class = "advanced_parameters" onclick="display_advanced_search_form();">
  663. <span id="img_plus_and_minus">&nbsp;'.
  664. Display::return_icon('div_show.gif', get_lang('Show'), array('style'=>'vertical-align:middle')).' '.get_lang('AdvancedSearch').'
  665. </span>
  666. </a>'
  667. );
  668. $actions = '';
  669. if (api_is_platform_admin()) {
  670. $actions .= '<span style="float:right;">'.
  671. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_add.php">'.
  672. Display::return_icon('new_user.png',get_lang('AddUsers'),'',ICON_SIZE_MEDIUM).'</a>'.
  673. '</span>';
  674. }
  675. $actions .= $form->return_form();
  676. if (isset ($_GET['keyword'])) {
  677. $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
  678. } elseif (isset ($_GET['keyword_firstname'])) {
  679. $parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
  680. $parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
  681. $parameters['keyword_username'] = Security::remove_XSS($_GET['keyword_username']);
  682. $parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
  683. $parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
  684. $parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
  685. $parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
  686. $parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
  687. }
  688. // Create a sortable table with user-data
  689. $parameters['sec_token'] = Security::get_token();
  690. // get the list of all admins to mark them in the users list
  691. $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  692. $sql_admin = "SELECT user_id FROM $admin_table";
  693. $res_admin = Database::query($sql_admin);
  694. $_admins_list = array();
  695. while ($row_admin = Database::fetch_row($res_admin)) {
  696. $_admins_list[] = $row_admin[0];
  697. }
  698. // Display Advanced search form.
  699. $form = new FormValidator('advanced_search', 'get');
  700. $form->addElement('html','<div id="advanced_search_form" style="display:none;">');
  701. $form->addElement('header', get_lang('AdvancedSearch'));
  702. $form->addElement('html', '<table>');
  703. $form->addElement('html', '<tr><td>');
  704. $form->add_textfield('keyword_firstname',get_lang('FirstName'),false,array('style'=>'margin-left:17px'));
  705. $form->addElement('html', '</td><td width="200px;">');
  706. $form->add_textfield('keyword_lastname',get_lang('LastName'),false,array('style'=>'margin-left:17px'));
  707. $form->addElement('html', '</td></tr>');
  708. $form->addElement('html', '<tr><td>');
  709. $form->add_textfield('keyword_username',get_lang('LoginName'),false,array('style'=>'margin-left:17px'));
  710. $form->addElement('html', '</td>');
  711. $form->addElement('html', '<td>');
  712. $form->add_textfield('keyword_email',get_lang('Email'),false,array('style'=>'margin-left:17px'));
  713. $form->addElement('html', '</td></tr>');
  714. $form->addElement('html', '<tr><td>');
  715. $form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false,array('style'=>'margin-left:17px'));
  716. $form->addElement('html', '</td><td>');
  717. $status_options = array();
  718. $status_options['%'] = get_lang('All');
  719. $status_options[STUDENT] = get_lang('Student');
  720. $status_options[COURSEMANAGER] = get_lang('Teacher');
  721. $status_options[DRH] = get_lang('Drh');
  722. $status_options[SESSIONADMIN] = get_lang('SessionsAdmin');
  723. $status_options[PLATFORM_ADMIN] = get_lang('Administrator');
  724. $form->addElement('select','keyword_status',get_lang('Profile'), $status_options, array('style'=>'margin-left:17px'));
  725. $form->addElement('html', '</td></tr>');
  726. $form->addElement('html', '<tr><td>');
  727. $active_group = array();
  728. $active_group[] = $form->createElement('checkbox','keyword_active','', get_lang('Active'));
  729. $active_group[] = $form->createElement('checkbox','keyword_inactive','', get_lang('Inactive'));
  730. $form->addGroup($active_group,'',get_lang('ActiveAccount'),'<br/>',false);
  731. $form->addElement('html', '</td><td>');
  732. $form->addElement('checkbox', 'check_easy_passwords', null, get_lang('CheckEasyPasswords'));
  733. /*
  734. * @todo fix this code
  735. $extra_data = UserManager::get_extra_fields( 0,10,5, 'ASC', true, 1);
  736. var_dump($extra_data);
  737. $extra_options = array();
  738. if (!empty($extra_data)) {
  739. $extra_options[0] = get_lang('All');
  740. // get information about extra data for adding to input select
  741. foreach ($extra_data as $field_variable => $field_value) {
  742. $extra = UserManager::get_extra_field_information_by_name($field_variable);
  743. $extra_options[$field_variable] = $extra['field_display_text'];
  744. }
  745. $form->addElement('select', 'keyword_extra_data', get_lang('ExtraData'), $extra_options, array('id'=>'input_select_extra_data', 'style'=>'margin-left:17px', 'onchange'=>'if(this.value!=0){document.getElementById(\'extra_data_text\').style.display=\'block\';document.getElementById(\'input_extra_text\').value = "";}else{document.getElementById(\'extra_data_text\').style.display=\'none\';}'));
  746. $form->addElement('html', '<div id="extra_data_text" style="display:none;">');
  747. $form->add_textfield('keyword_extra_data_text', '', false, array('style'=>'margin-left:17px', 'id'=>'input_extra_text'));
  748. $form->addElement('html', '</div>');
  749. } else {
  750. $form->addElement('html', '<div id="extra_data_text" style="display:none;">');
  751. }*/
  752. $form->addElement('html', '</td></tr>');
  753. $form->addElement('html', '<tr><td>');
  754. $form->addElement('button', 'submit',get_lang('SearchUsers'));
  755. $form->addElement('html', '</td></tr>');
  756. $form->addElement('html', '</table>');
  757. $defaults = array();
  758. $defaults['keyword_active'] = 1;
  759. $defaults['keyword_inactive'] = 1;
  760. $form->setDefaults($defaults);
  761. $form->addElement('html','</div>');
  762. $form = $form->return_form();
  763. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
  764. $table->set_additional_parameters($parameters);
  765. $table->set_header(0, '', false, 'width="18px"');
  766. $table->set_header(1, get_lang('Photo'), false);
  767. $table->set_header(2, get_lang('OfficialCode'));
  768. if (api_is_western_name_order()) {
  769. $table->set_header(3, get_lang('FirstName'));
  770. $table->set_header(4, get_lang('LastName'));
  771. } else {
  772. $table->set_header(3, get_lang('LastName'));
  773. $table->set_header(4, get_lang('FirstName'));
  774. }
  775. $table->set_header(5, get_lang('LoginName'));
  776. $table->set_header(6, get_lang('Email'));
  777. $table->set_header(7, get_lang('Profile'));
  778. $table->set_header(8, get_lang('Active'), true, 'width="15px"');
  779. $table->set_header(9, get_lang('RegistrationDate'), true, 'width="90px"');
  780. $table->set_header(10, get_lang('Action'), false, 'width="220px"');
  781. $table->set_column_filter(3, 'user_filter');
  782. $table->set_column_filter(4, 'user_filter');
  783. $table->set_column_filter(6, 'email_filter');
  784. $table->set_column_filter(7, 'status_filter');
  785. $table->set_column_filter(8, 'active_filter');
  786. $table->set_column_filter(10, 'modify_filter');
  787. // Only show empty actions bar if delete users has been blocked
  788. if (api_is_platform_admin() && !(isset($_configuration['deny_delete_users']) && $_configuration['deny_delete_users'])) {
  789. $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
  790. } else {
  791. $table->set_form_actions(array ('none' => get_lang('NoActionAvailable')));
  792. }
  793. $table_result = $table->return_table();
  794. $extra_search_options = '';
  795. //Try to search the user everywhere
  796. if ($table->get_total_number_of_items() == 0) {
  797. if (api_get_multiple_access_url() && isset($_REQUEST['keyword'])) {
  798. $keyword = Database::escape_string($_REQUEST['keyword']);
  799. $conditions = array('username' => $keyword);
  800. $user_list = UserManager::get_user_list($conditions, array(), false, ' OR ');
  801. if (!empty($user_list)) {
  802. $extra_search_options = Display::page_subheader(get_lang('UsersFoundInOtherPortals'));
  803. $table = new HTML_Table(array('class' => 'data_table'));
  804. $column = 0;
  805. $row = 0;
  806. $headers = array(get_lang('User'), 'URL', get_lang('Actions'));
  807. foreach ($headers as $header) {
  808. $table->setHeaderContents($row, $column, $header);
  809. $column++;
  810. }
  811. $row++;
  812. foreach ($user_list as $user) {
  813. $column = 0;
  814. $access_info = UrlManager::get_access_url_from_user($user['user_id']);
  815. $access_info_to_string = '';
  816. $add_user = true;
  817. if (!empty($access_info)) {
  818. foreach ($access_info as $url_info) {
  819. if ($current_access_url_id == $url_info['access_url_id']) {
  820. $add_user = false;
  821. }
  822. $access_info_to_string .= $url_info['url'].'<br />';
  823. }
  824. }
  825. if ($add_user) {
  826. $row_table = array();
  827. $row_table[] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
  828. $row_table[] = $access_info_to_string;
  829. $url = api_get_self().'?action=add_user_to_my_url&user_id='.$user['user_id'].'&sec_token='.$_SESSION['sec_token'];
  830. $row_table[] = Display::url(get_lang('AddUserToMyURL'), $url, array('class' => 'btn'));
  831. foreach ($row_table as $cell) {
  832. $table->setCellContents($row, $column, $cell);
  833. $table->updateCellAttributes($row, $column, 'align="center"');
  834. $column++;
  835. }
  836. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  837. $row++;
  838. }
  839. }
  840. $extra_search_options .= $table->toHtml();
  841. $table_result = '';
  842. }
  843. }
  844. }
  845. $tpl = new Template($tool_name);
  846. $tpl->assign('actions', $actions);
  847. $tpl->assign('message', $message);
  848. $tpl->assign('content', $form.$table_result.$extra_search_options);
  849. $tpl->display_one_col_template();