user_list.php 34 KB

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