user_list.php 37 KB

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