user_list.php 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * @author Bart Mollet
  6. * @author Julio Montoya <gugli100@gmail.com> BeezNest 2011
  7. * @package chamilo.admin
  8. */
  9. $cidReset = true;
  10. require_once __DIR__.'/../inc/global.inc.php';
  11. $urlId = api_get_current_access_url_id();
  12. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
  13. // Login as can be used by different roles
  14. if (isset($_GET['user_id']) && $action == 'login_as') {
  15. $check = Security::check_token('get');
  16. if ($check && api_can_login_as($_GET['user_id'])) {
  17. $result = UserManager::loginAsUser($_GET['user_id']);
  18. if ($result) {
  19. $userInfo = api_get_user_info();
  20. $firstname = $userInfo['firstname'];
  21. $lastname = $userInfo['lastname'];
  22. $userId = $userInfo['id'];
  23. if (api_is_western_name_order()) {
  24. $message = sprintf(
  25. get_lang('AttemptingToLoginAs'),
  26. $firstname,
  27. $lastname,
  28. $userId
  29. );
  30. } else {
  31. $message = sprintf(
  32. get_lang('AttemptingToLoginAs'),
  33. $lastname,
  34. $firstname,
  35. $userId
  36. );
  37. }
  38. $target_url = api_get_path(WEB_PATH)."user_portal.php";
  39. $message .= '<br />'.
  40. sprintf(get_lang('LoginSuccessfulGoToX'), '<a href="'.$target_url.'">'.$target_url.'</a>');
  41. Display::display_header(get_lang('UserList'));
  42. echo Display::return_message($message, 'normal', false);
  43. Display::display_footer();
  44. exit;
  45. } else {
  46. api_not_allowed(true);
  47. }
  48. }
  49. Security::clear_token();
  50. }
  51. api_protect_admin_script(true);
  52. // Blocks the possibility to delete a user
  53. $deleteUserAvailable = true;
  54. if (api_get_configuration_value('deny_delete_users')) {
  55. $deleteUserAvailable = false;
  56. }
  57. trimVariables();
  58. $url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=get_user_courses';
  59. $urlSession = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=get_user_sessions';
  60. $extraField = new ExtraField('user');
  61. $variables = $extraField->get_all_extra_field_by_type(ExtraField::FIELD_TYPE_TAG);
  62. $variablesSelect = $extraField->get_all_extra_field_by_type(ExtraField::FIELD_TYPE_SELECT);
  63. if (!empty($variablesSelect)) {
  64. $variables = array_merge($variables, $variablesSelect);
  65. }
  66. $variablesToShow = [];
  67. if ($variables) {
  68. foreach ($variables as $variableId) {
  69. $extraFieldInfo = $extraField->get($variableId);
  70. $variablesToShow[] = $extraFieldInfo['variable'];
  71. }
  72. }
  73. Session::write('variables_to_show', $variablesToShow);
  74. $htmlHeadXtra[] = '<script>
  75. function load_course_list (div_course,my_user_id) {
  76. $.ajax({
  77. contentType: "application/x-www-form-urlencoded",
  78. beforeSend: function(objeto) {
  79. $("div#"+div_course).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  80. type: "POST",
  81. url: "'.$url.'",
  82. data: "user_id="+my_user_id,
  83. success: function(datos) {
  84. $("div#"+div_course).html(datos);
  85. $("div#div_"+my_user_id).attr("class","blackboard_show");
  86. $("div#div_"+my_user_id).attr("style","");
  87. }
  88. });
  89. }
  90. function load_session_list(div_session, my_user_id) {
  91. $.ajax({
  92. contentType: "application/x-www-form-urlencoded",
  93. beforeSend: function(objeto) {
  94. $("div#"+div_session).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  95. type: "POST",
  96. url: "'.$urlSession.'",
  97. data: "user_id="+my_user_id,
  98. success: function(datos) {
  99. $("div#"+div_session).html(datos);
  100. $("div#div_s_"+my_user_id).attr("class","blackboard_show");
  101. $("div#div_s_"+my_user_id).attr("style","");
  102. }
  103. });
  104. }
  105. function active_user(element_div) {
  106. id_image=$(element_div).attr("id");
  107. image_clicked=$(element_div).attr("src");
  108. image_clicked_info = image_clicked.split("/");
  109. image_real_clicked = image_clicked_info[image_clicked_info.length-1];
  110. var status = 1;
  111. if (image_real_clicked == "accept.png") {
  112. status = 0;
  113. }
  114. user_id=id_image.split("_");
  115. ident="#img_"+user_id[1];
  116. if (confirm("'.get_lang('AreYouSureToEditTheUserStatus', '').'")) {
  117. $.ajax({
  118. contentType: "application/x-www-form-urlencoded",
  119. beforeSend: function(objeto) {
  120. $(ident).attr("src","'.Display::returnIconPath('loading1.gif').'"); }, //candy eye stuff
  121. type: "GET",
  122. url: "'.api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=active_user",
  123. data: "user_id="+user_id[1]+"&status="+status,
  124. success: function(data) {
  125. if (data == 1) {
  126. $(ident).attr("src", "'.Display::returnIconPath('accept.png', ICON_SIZE_TINY).'");
  127. $(ident).attr("title","'.get_lang('Lock').'");
  128. }
  129. if (data == 0) {
  130. $(ident).attr("src","'.Display::returnIconPath('error.png').'");
  131. $(ident).attr("title","'.get_lang('Unlock').'");
  132. }
  133. if (data == -1) {
  134. $(ident).attr("src", "'.Display::returnIconPath('warning.png').'");
  135. $(ident).attr("title","'.get_lang('ActionNotAllowed').'");
  136. }
  137. }
  138. });
  139. }
  140. }
  141. function clear_course_list(div_course) {
  142. $("div#"+div_course).html("&nbsp;");
  143. $("div#"+div_course).hide("");
  144. }
  145. function clear_session_list(div_session) {
  146. $("div#"+div_session).html("&nbsp;");
  147. $("div#"+div_session).hide("");
  148. }
  149. function display_advanced_search_form () {
  150. if ($("#advanced_search_form").css("display") == "none") {
  151. $("#advanced_search_form").css("display","block");
  152. $("#img_plus_and_minus").html(\'&nbsp;'. Display::returnFontAwesomeIcon('arrow-down').' '.get_lang('AdvancedSearch').'\');
  153. } else {
  154. $("#advanced_search_form").css("display","none");
  155. $("#img_plus_and_minus").html(\'&nbsp;'. Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('AdvancedSearch').'\');
  156. }
  157. }
  158. $(document).ready(function() {
  159. var select_val = $("#input_select_extra_data").val();
  160. if ( document.getElementById(\'extra_data_text\')) {
  161. if (select_val != 0) {
  162. document.getElementById(\'extra_data_text\').style.display="block";
  163. if (document.getElementById(\'input_extra_text\'))
  164. document.getElementById(\'input_extra_text\').value = "";
  165. } else {
  166. document.getElementById(\'extra_data_text\').style.display="none";
  167. }
  168. }
  169. });
  170. //Load user calendar
  171. function load_calendar(user_id, month, year) {
  172. var url = "'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&user_id=" +user_id + "&month="+month+"&year="+year;
  173. $(".modal-body").load(url);
  174. }
  175. </script>';
  176. $this_section = SECTION_PLATFORM_ADMIN;
  177. /**
  178. * Trim variable values to avoid trailing spaces
  179. */
  180. function trimVariables()
  181. {
  182. $filterVariables = [
  183. 'keyword',
  184. 'keyword_firstname',
  185. 'keyword_lastname',
  186. 'keyword_username',
  187. 'keyword_email',
  188. 'keyword_officialcode',
  189. ];
  190. foreach ($filterVariables as $variable) {
  191. if (isset($_GET[$variable])) {
  192. $_GET[$variable] = trim($_GET[$variable]);
  193. }
  194. }
  195. }
  196. /**
  197. * Prepares the shared SQL query for the user table.
  198. * See get_user_data() and get_number_of_users().
  199. *
  200. * @param boolean $is_count Whether to count, or get data
  201. * @return string SQL query
  202. */
  203. function prepare_user_sql_query($is_count)
  204. {
  205. $sql = '';
  206. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  207. $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  208. if ($is_count) {
  209. $sql .= "SELECT COUNT(u.id) AS total_number_of_items FROM $user_table u";
  210. } else {
  211. $sql .= "SELECT u.id AS col0, u.official_code AS col2, ";
  212. if (api_is_western_name_order()) {
  213. $sql .= "u.firstname AS col3, u.lastname AS col4, ";
  214. } else {
  215. $sql .= "u.lastname AS col3, u.firstname AS col4, ";
  216. }
  217. $sql .= " u.username AS col5,
  218. u.email AS col6,
  219. u.status AS col7,
  220. u.active AS col8,
  221. u.id AS col9,
  222. u.registration_date AS col10,
  223. u.expiration_date AS exp,
  224. u.password
  225. FROM $user_table u";
  226. }
  227. // adding the filter to see the user's only of the current access_url
  228. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  229. $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  230. $sql .= " INNER JOIN $access_url_rel_user_table url_rel_user
  231. ON (u.id=url_rel_user.user_id)";
  232. }
  233. $keywordList = array(
  234. 'keyword_firstname',
  235. 'keyword_lastname',
  236. 'keyword_username',
  237. 'keyword_email',
  238. 'keyword_officialcode',
  239. 'keyword_status',
  240. 'keyword_active',
  241. 'keyword_inactive',
  242. 'check_easy_passwords'
  243. );
  244. $keywordListValues = array();
  245. $atLeastOne = false;
  246. foreach ($keywordList as $keyword) {
  247. $keywordListValues[$keyword] = null;
  248. if (isset($_GET[$keyword]) && !empty($_GET[$keyword])) {
  249. $keywordListValues[$keyword] = $_GET[$keyword];
  250. $atLeastOne = true;
  251. }
  252. }
  253. if ($atLeastOne == false) {
  254. $keywordListValues = array();
  255. }
  256. /*
  257. // This block is never executed because $keyword_extra_data never exists
  258. if (isset($keyword_extra_data) && !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.id=ufv.user_id AND ufv.field_id=$field_id ";
  262. }
  263. */
  264. if (isset($_GET['keyword']) && !empty($_GET['keyword'])) {
  265. $keywordFiltered = Database::escape_string("%".$_GET['keyword']."%");
  266. $sql .= " WHERE (
  267. u.firstname LIKE '$keywordFiltered' OR
  268. u.lastname LIKE '$keywordFiltered' OR
  269. concat(u.firstname, ' ', u.lastname) LIKE '$keywordFiltered' OR
  270. concat(u.lastname,' ',u.firstname) LIKE '$keywordFiltered' OR
  271. u.username LIKE '$keywordFiltered' OR
  272. u.official_code LIKE '$keywordFiltered' OR
  273. u.email LIKE '$keywordFiltered'
  274. )
  275. ";
  276. } elseif (isset($keywordListValues) && !empty($keywordListValues)) {
  277. $query_admin_table = '';
  278. $keyword_admin = '';
  279. if (isset($keywordListValues['keyword_status']) &&
  280. $keywordListValues['keyword_status'] == PLATFORM_ADMIN
  281. ) {
  282. $query_admin_table = " , $admin_table a ";
  283. $keyword_admin = ' AND a.user_id = u.id ';
  284. $keywordListValues['keyword_status'] = '%';
  285. }
  286. $keyword_extra_value = '';
  287. // This block is never executed because $keyword_extra_data never exists
  288. /*
  289. if (isset($keyword_extra_data) && !empty($keyword_extra_data) &&
  290. !empty($keyword_extra_data_text)) {
  291. $keyword_extra_value = " AND ufv.field_value LIKE '%".trim($keyword_extra_data_text)."%' ";
  292. }
  293. */
  294. $sql .= " $query_admin_table
  295. WHERE (
  296. u.firstname LIKE '".Database::escape_string("%".$keywordListValues['keyword_firstname']."%")."' AND
  297. u.lastname LIKE '". Database::escape_string("%".$keywordListValues['keyword_lastname']."%")."' AND
  298. u.username LIKE '". Database::escape_string("%".$keywordListValues['keyword_username']."%")."' AND
  299. u.email LIKE '". Database::escape_string("%".$keywordListValues['keyword_email']."%")."' AND
  300. u.status LIKE '".Database::escape_string($keywordListValues['keyword_status'])."' ";
  301. if (!empty($keywordListValues['keyword_officialcode'])) {
  302. $sql .= " AND u.official_code LIKE '".Database::escape_string("%".$keywordListValues['keyword_officialcode']."%")."' ";
  303. }
  304. $sql .= "
  305. $keyword_admin
  306. $keyword_extra_value
  307. ";
  308. if (isset($keywordListValues['keyword_active']) &&
  309. !isset($keywordListValues['keyword_inactive'])
  310. ) {
  311. $sql .= " AND u.active = 1";
  312. } elseif (isset($keywordListValues['keyword_inactive']) &&
  313. !isset($keywordListValues['keyword_active'])
  314. ) {
  315. $sql .= " AND u.active = 0";
  316. }
  317. $sql .= " ) ";
  318. }
  319. $variables = Session::read('variables_to_show', []);
  320. if (!empty($variables)) {
  321. $extraField = new ExtraField('user');
  322. $extraFieldResult = [];
  323. $extraFieldHasData = [];
  324. foreach ($variables as $variable) {
  325. if (isset($_GET['extra_'.$variable])) {
  326. if (is_array($_GET['extra_'.$variable])) {
  327. $values = $_GET['extra_'.$variable];
  328. } else {
  329. $values = [$_GET['extra_'.$variable]];
  330. }
  331. if (empty($values)) {
  332. continue;
  333. }
  334. $info = $extraField->get_handler_field_info_by_field_variable(
  335. $variable
  336. );
  337. if (empty($info)) {
  338. continue;
  339. }
  340. foreach ($values as $value) {
  341. if (empty($value)) {
  342. continue;
  343. }
  344. if ($info['field_type'] == ExtraField::FIELD_TYPE_TAG) {
  345. $result = $extraField->getAllUserPerTag(
  346. $info['id'],
  347. $value
  348. );
  349. $result = empty($result) ? [] : array_column(
  350. $result,
  351. 'user_id'
  352. );
  353. } else {
  354. $result = UserManager::get_extra_user_data_by_value(
  355. $variable,
  356. $value
  357. );
  358. }
  359. $extraFieldHasData[] = true;
  360. if (!empty($result)) {
  361. $extraFieldResult = array_merge(
  362. $extraFieldResult,
  363. $result
  364. );
  365. }
  366. }
  367. }
  368. }
  369. if (!empty($extraFieldHasData)) {
  370. $sql .= " AND (u.id IN ('".implode("','", $extraFieldResult)."')) ";
  371. }
  372. }
  373. // adding the filter to see the user's only of the current access_url
  374. if ((api_is_platform_admin() || api_is_session_admin()) &&
  375. api_get_multiple_access_url()
  376. ) {
  377. $sql .= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  378. }
  379. return $sql;
  380. }
  381. /**
  382. * Get the total number of users on the platform
  383. * @see SortableTable#get_total_number_of_items()
  384. */
  385. function get_number_of_users()
  386. {
  387. $sql = prepare_user_sql_query(true);
  388. $res = Database::query($sql);
  389. $obj = Database::fetch_object($res);
  390. return $obj->total_number_of_items;
  391. }
  392. /**
  393. * Get the users to display on the current page (fill the sortable-table)
  394. * @param int offset of first user to recover
  395. * @param int Number of users to get
  396. * @param int Column to sort on
  397. * @param string Order (ASC,DESC)
  398. * @see SortableTable#get_table_data($from)
  399. */
  400. function get_user_data($from, $number_of_items, $column, $direction)
  401. {
  402. $sql = prepare_user_sql_query(false);
  403. if (!in_array($direction, array('ASC', 'DESC'))) {
  404. $direction = 'ASC';
  405. }
  406. $column = intval($column);
  407. $from = intval($from);
  408. $number_of_items = intval($number_of_items);
  409. $preventSessionAdminsToManageAllUsers = api_get_setting('prevent_session_admins_to_manage_all_users');
  410. if (api_is_session_admin() && $preventSessionAdminsToManageAllUsers === 'true') {
  411. $sql .= " WHERE u.creator_id = ".api_get_user_id();
  412. }
  413. $sql .= " ORDER BY col$column $direction ";
  414. $sql .= " LIMIT $from,$number_of_items";
  415. $res = Database::query($sql);
  416. $users = array();
  417. $t = time();
  418. while ($user = Database::fetch_row($res)) {
  419. $userPicture = UserManager::getUserPicture(
  420. $user[0],
  421. USER_IMAGE_SIZE_SMALL
  422. );
  423. $photo = '<img
  424. src="'.$userPicture.'" width="22" height="22"
  425. alt="'.api_get_person_name($user[2], $user[3]).'"
  426. title="'.api_get_person_name($user[2], $user[3]).'" />';
  427. if ($user[7] == 1 && !empty($user[10])) {
  428. // check expiration date
  429. $expiration_time = convert_sql_date($user[10]);
  430. // if expiration date is passed, store a special value for active field
  431. if ($expiration_time < $t) {
  432. $user[7] = '-1';
  433. }
  434. }
  435. // forget about the expiration date field
  436. $users[] = array(
  437. $user[0],
  438. $photo,
  439. $user[1],
  440. $user[2],
  441. $user[3],
  442. $user[4],
  443. $user[5],
  444. $user[6],
  445. $user[7],
  446. api_get_local_time($user[9]),
  447. $user[0]
  448. );
  449. }
  450. return $users;
  451. }
  452. /**
  453. * Returns a mailto-link
  454. * @param string $email An email-address
  455. * @return string HTML-code with a mailto-link
  456. */
  457. function email_filter($email)
  458. {
  459. return Display :: encrypted_mailto_link($email, $email);
  460. }
  461. /**
  462. * Returns a mailto-link
  463. * @param string $email An email-address
  464. * @return string HTML-code with a mailto-link
  465. */
  466. function user_filter($name, $params, $row)
  467. {
  468. return '<a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$row[0].'">'.$name.'</a>';
  469. }
  470. /**
  471. * Build the modify-column of the table
  472. * @param int The user id
  473. * @param string URL params to add to table links
  474. * @param array Row of elements to alter
  475. * @return string Some HTML-code with modify-buttons
  476. */
  477. function modify_filter($user_id, $url_params, $row)
  478. {
  479. $_admins_list = Session::read('admin_list', []);
  480. $is_admin = in_array($user_id, $_admins_list);
  481. $statusname = api_get_status_langvars();
  482. $user_is_anonymous = false;
  483. $current_user_status_label = $row['7'];
  484. if ($current_user_status_label == $statusname[ANONYMOUS]) {
  485. $user_is_anonymous = true;
  486. }
  487. $result = '';
  488. if (!$user_is_anonymous) {
  489. $icon = Display::return_icon(
  490. 'course.png',
  491. get_lang('Courses'),
  492. array('onmouseout' => 'clear_course_list (\'div_'.$user_id.'\')')
  493. );
  494. $result .= '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" >
  495. '.$icon.'
  496. <div class="blackboard_hide" id="div_'.$user_id.'">&nbsp;&nbsp;</div>
  497. </a>';
  498. $icon = Display::return_icon(
  499. 'session.png',
  500. get_lang('Sessions'),
  501. array('onmouseout' => 'clear_session_list (\'div_s_'.$user_id.'\')')
  502. );
  503. $result .= '<a href="javascript:void(0)" onclick="load_session_list(\'div_s_'.$user_id.'\','.$user_id.')" >
  504. '.$icon.'
  505. <div class="blackboard_hide" id="div_s_'.$user_id.'">&nbsp;&nbsp;</div>
  506. </a>';
  507. } else {
  508. $result .= Display::return_icon('course_na.png', get_lang('Courses')).'&nbsp;&nbsp;';
  509. $result .= Display::return_icon('course_na.png', get_lang('Sessions')).'&nbsp;&nbsp;';
  510. }
  511. if (api_is_platform_admin()) {
  512. if (!$user_is_anonymous) {
  513. $result .= '<a href="user_information.php?user_id='.$user_id.'">'.
  514. Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;&nbsp;';
  515. } else {
  516. $result .= Display::return_icon('synthese_view_na.gif', get_lang('Info')).'&nbsp;&nbsp;';
  517. }
  518. }
  519. //only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
  520. if (api_is_platform_admin() || (api_is_session_admin() && $current_user_status_label == $statusname[STUDENT])) {
  521. if (!$user_is_anonymous) {
  522. if (api_global_admin_can_edit_admin($user_id)) {
  523. $result .= '<a href="user_list.php?action=login_as&user_id='.$user_id.'&sec_token='.Security::getTokenFromSession().'">'.
  524. Display::return_icon('login_as.png', get_lang('LoginAs')).'</a>&nbsp;';
  525. } else {
  526. $result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;';
  527. }
  528. } else {
  529. $result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;';
  530. }
  531. } else {
  532. $result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;';
  533. }
  534. if ($current_user_status_label != $statusname[STUDENT]) {
  535. $result .= Display::return_icon(
  536. 'statistics_na.gif',
  537. get_lang('Reporting')
  538. ).'&nbsp;';
  539. } else {
  540. $result .= '<a href="../mySpace/myStudents.php?student='.$user_id.'">'.
  541. Display::return_icon('statistics.gif', get_lang('Reporting')).
  542. '</a>&nbsp;';
  543. }
  544. if (api_is_platform_admin(true)) {
  545. $editProfileUrl = Display::getProfileEditionLink($user_id, true);
  546. if (!$user_is_anonymous &&
  547. api_global_admin_can_edit_admin($user_id, null, true)
  548. ) {
  549. $result .= '<a href="'.$editProfileUrl.'">'.
  550. Display::return_icon(
  551. 'edit.png',
  552. get_lang('Edit'),
  553. array(),
  554. ICON_SIZE_SMALL
  555. ).
  556. '</a>&nbsp;';
  557. } else {
  558. $result .= Display::return_icon(
  559. 'edit_na.png',
  560. get_lang('Edit'),
  561. array(),
  562. ICON_SIZE_SMALL
  563. ).'</a>&nbsp;';
  564. }
  565. }
  566. $allowAssignSkill = api_is_platform_admin(false, true);
  567. if ($allowAssignSkill) {
  568. $result .= Display::url(
  569. Display::return_icon(
  570. 'skill-badges.png',
  571. get_lang('AssignSkill'),
  572. null,
  573. ICON_SIZE_SMALL
  574. ),
  575. api_get_path(WEB_CODE_PATH).'badge/assign.php?'.http_build_query(['user' => $user_id])
  576. );
  577. }
  578. if ($is_admin) {
  579. $result .= Display::return_icon(
  580. 'admin_star.png',
  581. get_lang('IsAdministrator'),
  582. array('width' => ICON_SIZE_SMALL, 'heigth' => ICON_SIZE_SMALL)
  583. );
  584. } else {
  585. $result .= Display::return_icon(
  586. 'admin_star_na.png',
  587. get_lang('IsNotAdministrator')
  588. );
  589. }
  590. // actions for assigning sessions, courses or users
  591. if (!api_is_session_admin()) {
  592. if ($current_user_status_label == $statusname[SESSIONADMIN]) {
  593. $result .= Display::url(
  594. Display::return_icon(
  595. 'view_more_stats.gif',
  596. get_lang('AssignSessions')
  597. ),
  598. "dashboard_add_sessions_to_user.php?user={$user_id}"
  599. );
  600. } else {
  601. if ($current_user_status_label == $statusname[DRH] ||
  602. UserManager::is_admin($user_id) ||
  603. $current_user_status_label == $statusname[STUDENT_BOSS]
  604. ) {
  605. $result .= Display::url(
  606. Display::return_icon(
  607. 'user_subscribe_course.png',
  608. get_lang('AssignUsers'),
  609. '',
  610. ICON_SIZE_SMALL
  611. ),
  612. "dashboard_add_users_to_user.php?user={$user_id}"
  613. );
  614. }
  615. if ($current_user_status_label == $statusname[DRH] || UserManager::is_admin($user_id)) {
  616. $result .= Display::url(
  617. Display::return_icon(
  618. 'course_add.gif',
  619. get_lang('AssignCourses')
  620. ),
  621. "dashboard_add_courses_to_user.php?user={$user_id}"
  622. );
  623. $result .= Display::url(
  624. Display::return_icon(
  625. 'view_more_stats.gif',
  626. get_lang('AssignSessions')
  627. ),
  628. "dashboard_add_sessions_to_user.php?user={$user_id}"
  629. );
  630. }
  631. }
  632. }
  633. $allowDelete = api_get_configuration_value('allow_delete_user_for_session_admin');
  634. if (api_is_session_admin() && $allowDelete) {
  635. if ($user_id != api_get_user_id() &&
  636. !$user_is_anonymous &&
  637. api_global_admin_can_edit_admin($user_id, null, true)
  638. ) {
  639. // 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.
  640. $result .= ' <a href="user_list.php?action=delete_user&user_id='.$user_id.'&'.$url_params.'&sec_token='.Security::getTokenFromSession().'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;">'.
  641. Display::return_icon(
  642. 'delete.png',
  643. get_lang('Delete'),
  644. array(),
  645. ICON_SIZE_SMALL
  646. ).
  647. '</a>';
  648. }
  649. }
  650. if (api_is_platform_admin()) {
  651. $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">'.
  652. Display::return_icon(
  653. 'calendar.png',
  654. get_lang('FreeBusyCalendar'),
  655. array(),
  656. ICON_SIZE_SMALL
  657. ).
  658. '</a>';
  659. $deleteAllowed = !api_get_configuration_value('deny_delete_users');
  660. if ($deleteAllowed) {
  661. if ($user_id != api_get_user_id() &&
  662. !$user_is_anonymous &&
  663. api_global_admin_can_edit_admin($user_id)
  664. ) {
  665. // you cannot lock yourself out otherwise you could disable all the accounts
  666. // including your own => everybody is locked out and nobody can change it anymore.
  667. $result .= ' <a href="user_list.php?action=delete_user&user_id='.$user_id.'&'.$url_params.'&sec_token='.Security::getTokenFromSession().'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;">'.
  668. Display::return_icon(
  669. 'delete.png',
  670. get_lang('Delete'),
  671. array(),
  672. ICON_SIZE_SMALL
  673. ).
  674. '</a>';
  675. } else {
  676. $result .= Display::return_icon(
  677. 'delete_na.png',
  678. get_lang('Delete'),
  679. array(),
  680. ICON_SIZE_SMALL
  681. );
  682. }
  683. }
  684. }
  685. return $result;
  686. }
  687. /**
  688. * Build the active-column of the table to lock or unlock a certain user
  689. * lock = the user can no longer use this account
  690. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  691. * @param int $active the current state of the account
  692. * @param string $params
  693. * @param array $row
  694. * @return string Some HTML-code with the lock/unlock button
  695. */
  696. function active_filter($active, $params, $row)
  697. {
  698. $_user = api_get_user_info();
  699. if ($active == '1') {
  700. $action = 'Lock';
  701. $image = 'accept';
  702. } elseif ($active == '-1') {
  703. $action = 'edit';
  704. $image = 'warning';
  705. } elseif ($active == '0') {
  706. $action = 'Unlock';
  707. $image = 'error';
  708. }
  709. $result = '';
  710. if ($action === 'edit') {
  711. $result = Display::return_icon(
  712. $image.'.png',
  713. get_lang('AccountExpired'),
  714. array(),
  715. 16
  716. );
  717. } elseif ($row['0'] <> $_user['user_id']) {
  718. // you cannot lock yourself out otherwise you could disable all the
  719. // accounts including your own => everybody is locked out and nobody
  720. // can change it anymore.
  721. $result = Display::return_icon(
  722. $image.'.png',
  723. get_lang(ucfirst($action)),
  724. array('onclick' => 'active_user(this);', 'id' => 'img_'.$row['0']),
  725. 16
  726. );
  727. }
  728. return $result;
  729. }
  730. /**
  731. * Instead of displaying the integer of the status, we give a translation for the status
  732. *
  733. * @param integer $status
  734. * @return string translation
  735. *
  736. * @version march 2008
  737. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  738. */
  739. function status_filter($status)
  740. {
  741. $statusname = api_get_status_langvars();
  742. return $statusname[$status];
  743. }
  744. if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
  745. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  746. $interbreadcrumb[] = array("url" => 'user_list.php', "name" => get_lang('UserList'));
  747. $tool_name = get_lang('SearchUsers');
  748. } else {
  749. $interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  750. $tool_name = get_lang('UserList');
  751. }
  752. $message = '';
  753. if (!empty($action)) {
  754. $check = Security::check_token('get');
  755. if ($check) {
  756. switch ($action) {
  757. case 'add_user_to_my_url':
  758. $user_id = $_REQUEST['user_id'];
  759. $result = UrlManager::add_user_to_url($user_id, $urlId);
  760. if ($result) {
  761. $user_info = api_get_user_info($user_id);
  762. $message = get_lang('UserAdded').' '.$user_info['complete_name_with_username'];
  763. $message = Display::return_message($message, 'confirmation');
  764. }
  765. break;
  766. case 'delete_user':
  767. $allowDelete = api_get_configuration_value('allow_delete_user_for_session_admin');
  768. if (api_is_platform_admin() ||
  769. ($allowDelete && api_is_session_admin())
  770. ) {
  771. $user_to_delete = $_GET['user_id'];
  772. $userToDeleteInfo = api_get_user_info($user_to_delete);
  773. $current_user_id = api_get_user_id();
  774. if ($userToDeleteInfo && $deleteUserAvailable &&
  775. api_global_admin_can_edit_admin($_GET['user_id'], null, $allowDelete)
  776. ) {
  777. if ($user_to_delete != $current_user_id &&
  778. UserManager::delete_user($_GET['user_id'])
  779. ) {
  780. $message = Display::return_message(
  781. get_lang('UserDeleted').': '.$userToDeleteInfo['complete_name_with_username'],
  782. 'confirmation'
  783. );
  784. } else {
  785. $message = Display::return_message(
  786. get_lang('CannotDeleteUserBecauseOwnsCourse'),
  787. 'error'
  788. );
  789. }
  790. } else {
  791. $message = Display::return_message(
  792. get_lang('CannotDeleteUser'),
  793. 'error'
  794. );
  795. }
  796. Display::addFlash($message);
  797. header('Location: '.api_get_self());
  798. exit;
  799. }
  800. break;
  801. case 'delete':
  802. if (api_is_platform_admin()) {
  803. $number_of_selected_users = count($_POST['id']);
  804. $number_of_deleted_users = 0;
  805. if (is_array($_POST['id'])) {
  806. foreach ($_POST['id'] as $index => $user_id) {
  807. if ($user_id != $_user['user_id']) {
  808. if (UserManager::delete_user($user_id)) {
  809. $number_of_deleted_users++;
  810. }
  811. }
  812. }
  813. }
  814. if ($number_of_selected_users == $number_of_deleted_users) {
  815. $message = Display::return_message(
  816. get_lang('SelectedUsersDeleted'),
  817. 'confirmation'
  818. );
  819. } else {
  820. $message = Display::return_message(
  821. get_lang('SomeUsersNotDeleted'),
  822. 'error'
  823. );
  824. }
  825. }
  826. break;
  827. }
  828. Security::clear_token();
  829. }
  830. }
  831. // Create a search-box
  832. $form = new FormValidator('search_simple', 'get', null, null, null, 'inline');
  833. $form->addText(
  834. 'keyword',
  835. get_lang('Search'),
  836. false,
  837. array(
  838. 'aria-label' => get_lang("SearchUsers")
  839. )
  840. );
  841. $form->addButtonSearch(get_lang('Search'));
  842. $searchAdvanced = '
  843. <a id="advanced_params" href="javascript://"
  844. class="btn btn-default advanced_options" onclick="display_advanced_search_form();">
  845. <span id="img_plus_and_minus">&nbsp;
  846. '. Display::returnFontAwesomeIcon('arrow-right').' '.get_lang('AdvancedSearch').'
  847. </span>
  848. </a>';
  849. $actionsLeft = '';
  850. $actionsCenter = '';
  851. $actionsRight = '';
  852. if (api_is_platform_admin()) {
  853. $actionsRight .= '<a class="pull-right" href="'.api_get_path(WEB_CODE_PATH).'admin/user_add.php">'.
  854. Display::return_icon('new_user.png', get_lang('AddUsers'), '', ICON_SIZE_MEDIUM).'</a>';
  855. }
  856. $actionsLeft .= $form->returnForm();
  857. $actionsCenter .= $searchAdvanced;
  858. if (isset($_GET['keyword'])) {
  859. $parameters = array('keyword' => Security::remove_XSS($_GET['keyword']));
  860. } elseif (isset($_GET['keyword_firstname'])) {
  861. $parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
  862. $parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
  863. $parameters['keyword_username'] = Security::remove_XSS($_GET['keyword_username']);
  864. $parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
  865. $parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
  866. $parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
  867. $parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
  868. $parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
  869. }
  870. // Create a sortable table with user-data
  871. $parameters['sec_token'] = Security::get_token();
  872. $_admins_list = array_keys(UserManager::get_all_administrators());
  873. Session::write('admin_list', $_admins_list);
  874. // Display Advanced search form.
  875. $form = new FormValidator(
  876. 'advanced_search',
  877. 'get',
  878. '',
  879. '',
  880. array(),
  881. FormValidator::LAYOUT_HORIZONTAL
  882. );
  883. $form->addElement('html', '<div id="advanced_search_form" style="display:none;">');
  884. $form->addElement('header', get_lang('AdvancedSearch'));
  885. $form->addText('keyword_firstname', get_lang('FirstName'), false);
  886. $form->addText('keyword_lastname', get_lang('LastName'), false);
  887. $form->addText('keyword_username', get_lang('LoginName'), false);
  888. $form->addText('keyword_email', get_lang('Email'), false);
  889. $form->addText('keyword_officialcode', get_lang('OfficialCode'), false);
  890. $status_options = array();
  891. $status_options['%'] = get_lang('All');
  892. $status_options[STUDENT] = get_lang('Student');
  893. $status_options[COURSEMANAGER] = get_lang('Teacher');
  894. $status_options[DRH] = get_lang('Drh');
  895. $status_options[SESSIONADMIN] = get_lang('SessionsAdmin');
  896. $status_options[PLATFORM_ADMIN] = get_lang('Administrator');
  897. $form->addElement(
  898. 'select',
  899. 'keyword_status',
  900. get_lang('Profile'),
  901. $status_options
  902. );
  903. $active_group = array();
  904. $active_group[] = $form->createElement('checkbox', 'keyword_active', '', get_lang('Active'));
  905. $active_group[] = $form->createElement('checkbox', 'keyword_inactive', '', get_lang('Inactive'));
  906. $form->addGroup($active_group, '', get_lang('ActiveAccount'), null, false);
  907. $form->addElement('checkbox', 'check_easy_passwords', null, get_lang('CheckEasyPasswords'));
  908. $data = $extraField->addElements($form, 0, [], true, false, $variablesToShow);
  909. $htmlHeadXtra[] = '
  910. <script>
  911. $(document).ready(function() {
  912. '.$data['jquery_ready_content'].'
  913. })
  914. </script>
  915. ';
  916. $form->addButtonSearch(get_lang('SearchUsers'));
  917. $defaults = array();
  918. $defaults['keyword_active'] = 1;
  919. $defaults['keyword_inactive'] = 1;
  920. $form->setDefaults($defaults);
  921. $form->addElement('html', '</div>');
  922. $form = $form->returnForm();
  923. $table = new SortableTable(
  924. 'users',
  925. 'get_number_of_users',
  926. 'get_user_data',
  927. (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2
  928. );
  929. $table->set_additional_parameters($parameters);
  930. $table->set_header(0, '', false, 'width="18px"');
  931. $table->set_header(1, get_lang('Photo'), false);
  932. $table->set_header(2, get_lang('OfficialCode'));
  933. if (api_is_western_name_order()) {
  934. $table->set_header(3, get_lang('FirstName'));
  935. $table->set_header(4, get_lang('LastName'));
  936. } else {
  937. $table->set_header(3, get_lang('LastName'));
  938. $table->set_header(4, get_lang('FirstName'));
  939. }
  940. $table->set_header(5, get_lang('LoginName'));
  941. $table->set_header(6, get_lang('Email'));
  942. $table->set_header(7, get_lang('Profile'));
  943. $table->set_header(8, get_lang('Active'), true, 'width="15px"');
  944. $table->set_header(9, get_lang('RegistrationDate'), true, 'width="90px"');
  945. $table->set_header(10, get_lang('Action'), false, 'width="220px"');
  946. $table->set_column_filter(3, 'user_filter');
  947. $table->set_column_filter(4, 'user_filter');
  948. $table->set_column_filter(6, 'email_filter');
  949. $table->set_column_filter(7, 'status_filter');
  950. $table->set_column_filter(8, 'active_filter');
  951. $table->set_column_filter(10, 'modify_filter');
  952. // Only show empty actions bar if delete users has been blocked
  953. if (api_is_platform_admin() &&
  954. !api_get_configuration_value('deny_delete_users')
  955. ) {
  956. $table->set_form_actions(array('delete' => get_lang('DeleteFromPlatform')));
  957. } else {
  958. $table->set_form_actions(array('none' => get_lang('NoActionAvailable')));
  959. }
  960. $table_result = $table->return_table();
  961. $extra_search_options = '';
  962. //Try to search the user everywhere
  963. if ($table->get_total_number_of_items() == 0) {
  964. if (api_get_multiple_access_url() && isset($_REQUEST['keyword'])) {
  965. $keyword = Database::escape_string($_REQUEST['keyword']);
  966. $conditions = array('username' => $keyword);
  967. $user_list = UserManager::get_user_list(
  968. $conditions,
  969. array(),
  970. false,
  971. ' OR '
  972. );
  973. if (!empty($user_list)) {
  974. $extra_search_options = Display::page_subheader(get_lang('UsersFoundInOtherPortals'));
  975. $table = new HTML_Table(array('class' => 'data_table'));
  976. $column = 0;
  977. $row = 0;
  978. $headers = array(get_lang('User'), 'URL', get_lang('Actions'));
  979. foreach ($headers as $header) {
  980. $table->setHeaderContents($row, $column, $header);
  981. $column++;
  982. }
  983. $row++;
  984. foreach ($user_list as $user) {
  985. $column = 0;
  986. $access_info = UrlManager::get_access_url_from_user($user['id']);
  987. $access_info_to_string = '';
  988. $add_user = true;
  989. if (!empty($access_info)) {
  990. foreach ($access_info as $url_info) {
  991. if ($urlId == $url_info['access_url_id']) {
  992. $add_user = false;
  993. }
  994. $access_info_to_string .= $url_info['url'].'<br />';
  995. }
  996. }
  997. if ($add_user) {
  998. $row_table = array();
  999. $row_table[] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
  1000. $row_table[] = $access_info_to_string;
  1001. $url = api_get_self().'?action=add_user_to_my_url&user_id='.$user['id'].'&sec_token='.Security::getTokenFromSession();
  1002. $row_table[] = Display::url(
  1003. get_lang('AddUserToMyURL'),
  1004. $url,
  1005. array('class' => 'btn')
  1006. );
  1007. foreach ($row_table as $cell) {
  1008. $table->setCellContents($row, $column, $cell);
  1009. $table->updateCellAttributes(
  1010. $row,
  1011. $column,
  1012. 'align="center"'
  1013. );
  1014. $column++;
  1015. }
  1016. $table->updateRowAttributes(
  1017. $row,
  1018. $row % 2 ? 'class="row_even"' : 'class="row_odd"',
  1019. true
  1020. );
  1021. $row++;
  1022. }
  1023. }
  1024. $extra_search_options .= $table->toHtml();
  1025. $table_result = '';
  1026. }
  1027. }
  1028. }
  1029. $toolbarActions = Display::toolbarAction(
  1030. 'toolbarUser',
  1031. [$actionsLeft, $actionsCenter, $actionsRight],
  1032. [4, 4, 4]
  1033. );
  1034. $tpl = new Template($tool_name);
  1035. $tpl->assign('actions', $toolbarActions);
  1036. $tpl->assign('message', $message);
  1037. $tpl->assign('content', $form.$table_result.$extra_search_options);
  1038. $tpl->display_one_col_template();