user_list.php 35 KB

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