user_list.php 39 KB

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