user_list.php 37 KB

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