user_list.php 34 KB

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