user_list.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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. // name of the language file that needs to be included
  9. $language_file = array ('registration','admin');
  10. $cidReset = true;
  11. global $_configuration;
  12. $current_access_url_id = api_get_current_access_url_id();
  13. // Blocks the possibility to delete a user
  14. $delete_user_available = true;
  15. if (isset($_configuration['deny_delete_users']) && $_configuration['deny_delete_users']) {
  16. $delete_user_available = 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. type: "POST",
  25. url: "'.$url.'",
  26. data: "user_id="+my_user_id,
  27. success: function(datos) {
  28. $("div#"+div_course).html(datos);
  29. $("div#div_"+my_user_id).attr("class","blackboard_show");
  30. $("div#div_"+my_user_id).attr("style","");
  31. }
  32. });
  33. }
  34. function load_session_list (div_session,my_user_id) {
  35. $.ajax({
  36. contentType: "application/x-www-form-urlencoded",
  37. type: "POST",
  38. url: "'.$urlSession.'",
  39. data: "user_id="+my_user_id,
  40. success: function(datos) {
  41. $("div#"+div_session).html(datos);
  42. $("div#div_s_"+my_user_id).attr("class","blackboard_show");
  43. $("div#div_s_"+my_user_id).attr("style","");
  44. }
  45. });
  46. }
  47. function active_user(element_div) {
  48. id_image=$(element_div).attr("id");
  49. image_clicked=$(element_div).attr("src");
  50. image_clicked_info = image_clicked.split("/");
  51. image_real_clicked = image_clicked_info[image_clicked_info.length-1];
  52. var status = 1;
  53. if (image_real_clicked == "accept.png") {
  54. status = 0;
  55. }
  56. user_id=id_image.split("_");
  57. ident="#img_"+user_id[1];
  58. if (confirm("'.get_lang('AreYouSureToEditTheUserStatus', '').'")) {
  59. $.ajax({
  60. contentType: "application/x-www-form-urlencoded",
  61. type: "GET",
  62. url: "'.api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=active_user",
  63. data: "user_id="+user_id[1]+"&status="+status,
  64. success: function(data) {
  65. if (data == 1) {
  66. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/accept.png'.'");
  67. $(ident).attr("title","'.get_lang('Lock').'");
  68. }
  69. if (data == 0) {
  70. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/error.png'.'");
  71. $(ident).attr("title","'.get_lang('Unlock').'");
  72. }
  73. if (data == -1) {
  74. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/warning.png'.'");
  75. $(ident).attr("title","'.get_lang('ActionNotAllowed').'");
  76. }
  77. }
  78. });
  79. }
  80. }
  81. function clear_course_list (div_course) {
  82. $("div#"+div_course).html("&nbsp;");
  83. $("div#"+div_course).hide("");
  84. }
  85. function clear_session_list (div_session) {
  86. $("div#"+div_session).html("&nbsp;");
  87. $("div#"+div_session).hide("");
  88. }
  89. $(document).ready(function() {
  90. var select_val = $("#input_select_extra_data").val();
  91. if ( document.getElementById(\'extra_data_text\')) {
  92. if (select_val != 0) {
  93. document.getElementById(\'extra_data_text\').style.display="block";
  94. if (document.getElementById(\'input_extra_text\'))
  95. document.getElementById(\'input_extra_text\').value = "";
  96. } else {
  97. document.getElementById(\'extra_data_text\').style.display="none";
  98. }
  99. }
  100. $(".agenda_opener").on("click", function() {
  101. var url = this.href;
  102. var dialog = $("#dialog");
  103. if ($("#dialog").length == 0) {
  104. dialog = $(\'<div id="dialog" style="display:hidden"></div> \').appendTo(\'body\');
  105. }
  106. // load remote content
  107. dialog.load(
  108. url,
  109. {},
  110. function(responseText, textStatus, XMLHttpRequest) {
  111. dialog.dialog({width:720, height:550, modal:true});
  112. }
  113. );
  114. //prevent the browser to follow the link
  115. return false;
  116. });
  117. });
  118. //Load user calendar
  119. function load_calendar(user_id, month, year) {
  120. var url = "'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&user_id=" +user_id + "&month="+month+"&year="+year;
  121. $("#dialog").load(url);
  122. }
  123. </script>';
  124. $this_section = SECTION_PLATFORM_ADMIN;
  125. api_protect_admin_script(true);
  126. /**
  127. * Get the total number of users on the platform
  128. * @see SortableTable#get_total_number_of_items()
  129. */
  130. function get_number_of_users()
  131. {
  132. $total_rows = get_user_data(null, null, null, null, true);
  133. return $total_rows;
  134. }
  135. /**
  136. * Get the users to display on the current page (fill the sortable-table)
  137. * @param int offset of first user to recover
  138. * @param int Number of users to get
  139. * @param int Column to sort on
  140. * @param string Order (ASC,DESC)
  141. * @param bool
  142. * @see SortableTable#get_table_data($from)
  143. */
  144. function get_user_data($from, $number_of_items, $column, $direction, $get_count = false)
  145. {
  146. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  147. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  148. $select = "SELECT
  149. u.user_id AS col0,
  150. u.official_code AS col2,
  151. ".(api_is_western_name_order()
  152. ? "u.firstname AS col3,
  153. u.lastname AS col4,"
  154. : "u.lastname AS col3,
  155. u.firstname AS col4,")."
  156. u.username AS col5,
  157. u.email AS col6,
  158. u.status AS col7,
  159. u.active AS col8,
  160. u.user_id AS col9,
  161. u.registration_date AS col10,
  162. u.expiration_date AS exp,
  163. u.password
  164. ";
  165. if ($get_count) {
  166. $select = "SELECT count(u.user_id) as total_rows";
  167. }
  168. $sql = "$select FROM $user_table u ";
  169. // adding the filter to see the user's only of the current access_url
  170. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  171. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  172. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  173. }
  174. if (isset($_GET['keyword_extra_data'])) {
  175. $keyword_extra_data = Database::escape_string($_GET['keyword_extra_data']);
  176. if (!empty($keyword_extra_data)) {
  177. $extra_info = UserManager::get_extra_field_information_by_name($keyword_extra_data);
  178. $field_id = $extra_info['id'];
  179. $sql.= " INNER JOIN user_field_values ufv ON u.user_id=ufv.user_id AND ufv.field_id=$field_id ";
  180. }
  181. }
  182. if (isset ($_GET['keyword'])) {
  183. $keyword = Database::escape_string(trim($_GET['keyword']));
  184. $sql .= " WHERE (u.firstname LIKE '%".$keyword."%' OR u.lastname LIKE '%".$keyword."%' OR concat(u.firstname,' ',u.lastname) LIKE '%".$keyword."%' OR concat(u.lastname,' ',u.firstname) LIKE '%".$keyword."%' OR u.username LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%' OR u.email LIKE '%".$keyword."%' )";
  185. } elseif (isset ($_GET['keyword_firstname'])) {
  186. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  187. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  188. $keyword_email = Database::escape_string($_GET['keyword_email']);
  189. $keyword_officialcode = Database::escape_string($_GET['keyword_officialcode']);
  190. $keyword_username = Database::escape_string($_GET['keyword_username']);
  191. $keyword_status = Database::escape_string($_GET['keyword_status']);
  192. $query_admin_table = '';
  193. $and_conditions = array();
  194. if ($keyword_status == SESSIONADMIN) {
  195. $keyword_status = '%';
  196. $query_admin_table = " , $admin_table a ";
  197. $and_conditions[] = ' a.user_id = u.user_id ';
  198. }
  199. if (isset($_GET['keyword_extra_data'])) {
  200. if (!empty($_GET['keyword_extra_data']) && !empty($_GET['keyword_extra_data_text'])) {
  201. $keyword_extra_data_text = Database::escape_string($_GET['keyword_extra_data_text']);
  202. $and_conditions[] = " ufv.field_value LIKE '%".trim($keyword_extra_data_text)."%' ";
  203. }
  204. }
  205. $keyword_active = isset($_GET['keyword_active']);
  206. $keyword_inactive = isset($_GET['keyword_inactive']);
  207. $sql .= $query_admin_table." WHERE ( ";
  208. if (!empty($keyword_firstname)) {
  209. $and_conditions[] = "u.firstname LIKE '%".$keyword_firstname."%' ";
  210. }
  211. if (!empty($keyword_lastname)) {
  212. $and_conditions[] = "u.lastname LIKE '%".$keyword_lastname."%' ";
  213. }
  214. if (!empty($keyword_username)) {
  215. $and_conditions[] = "u.username LIKE '%".$keyword_username."%' ";
  216. }
  217. if (!empty($keyword_email)) {
  218. $and_conditions[] = "u.email LIKE '%".$keyword_email."%' ";
  219. }
  220. if (!empty($keyword_officialcode)) {
  221. $and_conditions[] = "u.official_code LIKE '%".$keyword_officialcode."%' ";
  222. }
  223. if (!empty($keyword_status)) {
  224. $and_conditions[] = "u.status LIKE '".$keyword_status."' ";
  225. }
  226. if ($keyword_active && !$keyword_inactive) {
  227. $and_conditions[] = " u.active='1' ";
  228. } elseif($keyword_inactive && !$keyword_active) {
  229. $and_conditions[] = " u.active='0' ";
  230. }
  231. if (!empty($and_conditions)) {
  232. $sql .= implode(' AND ', $and_conditions);
  233. }
  234. $sql .= " ) ";
  235. }
  236. // adding the filter to see the user's only of the current access_url
  237. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  238. $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  239. }
  240. $checkPassStrength = isset($_GET['check_easy_passwords']) && $_GET['check_easy_passwords'] == 1 ? true : false;
  241. if ($checkPassStrength) {
  242. $easyPasswordList = api_get_easy_password_list();
  243. $easyPasswordList = array_map('api_get_encrypted_password', $easyPasswordList);
  244. $easyPasswordList = array_map(array('Database', 'escape_string'), $easyPasswordList);
  245. $easyPassword = implode("' OR password LIKE '", $easyPasswordList);
  246. $sql .= "AND password LIKE '$easyPassword' ";
  247. }
  248. if (!in_array($direction, array('ASC','DESC'))) {
  249. $direction = 'ASC';
  250. }
  251. $column = intval($column);
  252. $from = intval($from);
  253. $number_of_items = intval($number_of_items);
  254. // Returns counts and exits function.
  255. if ($get_count) {
  256. $res = Database::query($sql);
  257. $user = Database::fetch_array($res);
  258. return $user['total_rows'];
  259. }
  260. $sql .= " ORDER BY col$column $direction ";
  261. $sql .= " LIMIT $from,$number_of_items";
  262. $res = Database::query($sql);
  263. $users = array ();
  264. $t = time();
  265. while ($user = Database::fetch_row($res)) {
  266. $userInfo = api_get_user_info($user[0]);
  267. $image_path = UserManager::get_user_picture_path_by_id($user[0], 'web', false, true);
  268. $user_profile = UserManager::get_picture_user($user[0], $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
  269. if (!api_is_anonymous()) {
  270. $photo = '<center><a href="'.$userInfo['profile_url'].'" title="'.get_lang('Info').'">
  271. <img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.$userInfo['complete_name'].'" title="'.$userInfo['complete_name'].'" /></a></center>';
  272. } else {
  273. $photo = '<center><img src="'.$user_profile['file'].'" '.$user_profile['style'].' alt="'.$userInfo['complete_name'].'" title="'.$userInfo['complete_name'].'" /></center>';
  274. }
  275. if ($user[7] == 1 && $user[10] != '0000-00-00 00:00:00') {
  276. // check expiration date
  277. $expiration_time = api_convert_sql_date($user[10]);
  278. // if expiration date is passed, store a special value for active field
  279. if ($expiration_time < $t) {
  280. $user[7] = '-1';
  281. }
  282. }
  283. // forget about the expiration date field
  284. $users[] = array(
  285. $user[0],
  286. $photo,
  287. $user[1],
  288. Display::url($user[2], $userInfo['profile_url']),
  289. Display::url($user[3], $userInfo['profile_url']),
  290. $user[4],
  291. $user[5],
  292. $user[6],
  293. $user[7],
  294. api_get_local_time($user[9]),
  295. $user[0]);
  296. }
  297. return $users;
  298. }
  299. /**
  300. * Returns a mailto-link
  301. * @param string $email An email-address
  302. * @return string HTML-code with a mailto-link
  303. */
  304. function email_filter($email) {
  305. return Display :: encrypted_mailto_link($email, $email);
  306. }
  307. /**
  308. * Build the modify-column of the table
  309. * @param int The user id
  310. * @param string URL params to add to table links
  311. * @param array Row of elements to alter
  312. * @return string Some HTML-code with modify-buttons
  313. */
  314. function modify_filter($user_id, $url_params, $row) {
  315. global $_admins_list, $delete_user_available, $app;
  316. $is_admin = false;
  317. $userId = api_get_user_id();
  318. if (is_array($_admins_list)) {
  319. $is_admin = in_array($user_id,$_admins_list);
  320. }
  321. $statusname = api_get_status_langvars();
  322. $user_is_anonymous = false;
  323. $current_user_status_label = $row['7'];
  324. if ($current_user_status_label == $statusname[ANONYMOUS]) {
  325. $user_is_anonymous =true;
  326. }
  327. $result = '';
  328. if (!$user_is_anonymous) {
  329. $icon = Display::return_icon('course.png', get_lang('Courses'), array('onmouseout' => 'clear_course_list (\'div_'.$user_id.'\')'));
  330. $result .= '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" >
  331. '.$icon.'
  332. <div class="blackboard_hide" id="div_'.$user_id.'">&nbsp;&nbsp;</div>
  333. </a>';
  334. $icon = Display::return_icon('session.png', get_lang('Sessions'), array('onmouseout' => 'clear_session_list (\'div_s_'.$user_id.'\')'));
  335. $result .= '<a href="javascript:void(0)" onclick="load_session_list(\'div_s_'.$user_id.'\','.$user_id.')" >
  336. '.$icon.'
  337. <div class="blackboard_hide" id="div_s_'.$user_id.'">&nbsp;&nbsp;</div>
  338. </a>';
  339. } else {
  340. $result .= Display::return_icon('course_na.png',get_lang('Courses')).'&nbsp;&nbsp;';
  341. $result .= Display::return_icon('course_na.png',get_lang('Sessions')).'&nbsp;&nbsp;';
  342. }
  343. if (api_is_platform_admin()) {
  344. if (!$user_is_anonymous) {
  345. $result .= '<a href="user_information.php?user_id='.$user_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;&nbsp;';
  346. } else {
  347. $result .= Display::return_icon('synthese_view_na.gif', get_lang('Info')).'&nbsp;&nbsp;';
  348. }
  349. }
  350. //only allow platform admins to login_as, or session admins only for
  351. // students (not teachers nor other admins), and only if all options
  352. // match to say this user has the permission to do so
  353. // $_configuration['login_as_forbidden_globally'], defined in
  354. // configuration.php, is the master key to these conditions
  355. global $_configuration;
  356. if (empty($_configuration['login_as_forbidden_globally']) &&
  357. (api_is_global_platform_admin() ||
  358. (api_get_setting('login_as_allowed') === 'true' &&
  359. (api_is_platform_admin() ||
  360. (api_is_session_admin() &&
  361. $current_user_status_label == $statusname[STUDENT]
  362. )
  363. )
  364. )
  365. )
  366. ) {
  367. if (!$user_is_anonymous) {
  368. if ($app['security']->isGranted('ROLE_GLOBAL_ADMIN')) {
  369. // everything looks good, show "login as" link
  370. if ($user_id != $userId) {
  371. $result .= '<a href="'.api_get_path(WEB_PUBLIC_PATH).'?_switch_user='.$row[5].'">'.Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
  372. } else {
  373. $result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).'&nbsp;&nbsp;';
  374. }
  375. } else {
  376. // if this user in particular can't be edited, show disabled
  377. $result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).'&nbsp;&nbsp;';
  378. }
  379. } else {
  380. // if anonymous user but other users show the option, show disabled
  381. $result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).'&nbsp;&nbsp;';
  382. }
  383. } // Else don't show anything, because the option is not available at all
  384. //$result .= Display::url('<i class="icon-key icon-large"></i>', 'roles');
  385. if ($current_user_status_label != $statusname[STUDENT]) {
  386. $result .= Display::return_icon('statistics_na.gif', get_lang('Reporting')).'&nbsp;&nbsp;';
  387. } else {
  388. $result .= '<a href="../mySpace/myStudents.php?student='.$user_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;&nbsp;';
  389. }
  390. if (api_is_platform_admin(true)) {
  391. if (!$user_is_anonymous && api_global_admin_can_edit_admin($user_id, null, true)) {
  392. $result .= '<a href="user_edit.php?user_id='.$user_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
  393. } else {
  394. $result .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
  395. }
  396. }
  397. if ($is_admin) {
  398. $result .= Display::return_icon('admin_star.png', get_lang('IsAdministrator'),array('width'=> ICON_SIZE_SMALL, 'heigth'=> ICON_SIZE_SMALL));
  399. } else {
  400. $result .= Display::return_icon('admin_star_na.png', get_lang('IsNotAdministrator'));
  401. }
  402. // actions for assigning sessions, courses or users
  403. if (api_is_session_admin()) {
  404. /*if ($row[0] == api_get_user_id()) {
  405. $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;';
  406. }*/
  407. }
  408. if (api_is_platform_admin()) {
  409. if ($current_user_status_label == $statusname[DRH] || UserManager::is_admin($user_id)) {
  410. $result .= '<a href="dashboard_add_users_to_user.php?user='.$user_id.'">'.Display::return_icon('user_subscribe_course.png', get_lang('AssignUsers'),'',ICON_SIZE_SMALL).'</a>';
  411. $result .= '<a href="dashboard_add_courses_to_user.php?user='.$user_id.'">'.Display::return_icon('course_add.gif', get_lang('AssignCourses')).'</a>&nbsp;&nbsp;';
  412. $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;';
  413. } else if ($current_user_status_label == $statusname[SESSIONADMIN]) {
  414. $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;';
  415. }
  416. }
  417. if (api_is_platform_admin()) {
  418. $result .= ' <a href="'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&amp;user_id='.$user_id.'" class="agenda_opener">'.Display::return_icon('month.png', get_lang('FreeBusyCalendar'), array(), ICON_SIZE_SMALL).'</a>';
  419. if ($delete_user_available) {
  420. if ($user_id != api_get_user_id() && !$user_is_anonymous && api_global_admin_can_edit_admin($user_id)) {
  421. // 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.
  422. $result .= ' <a href="user_list.php?action=delete_user&amp;user_id='.$user_id.'&amp;'.$url_params.'&amp;sec_token='.Security::getCurrentToken().'" onclick="javascript:if(!confirm('."'".addslashes(get_lang("ConfirmYourChoice"))."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), array(), ICON_SIZE_SMALL).'</a>';
  423. } else {
  424. $result .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), ICON_SIZE_SMALL);
  425. }
  426. }
  427. }
  428. return $result;
  429. }
  430. /**
  431. * Build the active-column of the table to lock or unlock a certain user
  432. * lock = the user can no longer use this account
  433. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  434. * @param int $active the current state of the account
  435. * @param int $user_id The user id
  436. * @param string $url_params
  437. * @return string Some HTML-code with the lock/unlock button
  438. */
  439. function active_filter($active, $url_params, $row) {
  440. global $_user;
  441. if ($active=='1') {
  442. $action='Lock';
  443. $image='accept';
  444. } elseif ($active=='-1') {
  445. $action='edit';
  446. $image='warning';
  447. } elseif ($active=='0') {
  448. $action='Unlock';
  449. $image='error';
  450. }
  451. $result = '';
  452. if ($action=='edit') {
  453. $result = Display::return_icon($image.'.png', get_lang('AccountExpired'), array(), 16);
  454. } elseif ($row['0']<>$_user['user_id']) {
  455. // 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.
  456. $result = Display::return_icon($image.'.png', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0']), 16).'</a>';
  457. }
  458. return $result;
  459. }
  460. /**
  461. * Instead of displaying the integer of the status, we give a translation for the status
  462. *
  463. * @param integer $status
  464. * @return string translation
  465. *
  466. * @version march 2008
  467. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  468. */
  469. function status_filter($status) {
  470. $statusname = api_get_status_langvars();
  471. return $statusname[$status];
  472. }
  473. $action = isset($_REQUEST["action"]) ? $_REQUEST["action"] : null;
  474. if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
  475. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  476. $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
  477. $tool_name = get_lang('SearchUsers');
  478. } else {
  479. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  480. $tool_name = get_lang('UserList');
  481. }
  482. $message = '';
  483. if (!empty($action)) {
  484. $check = Security::check_token('get');
  485. if ($check) {
  486. switch ($action) {
  487. case 'add_user_to_my_url':
  488. $user_id = $_REQUEST["user_id"];
  489. $result = UrlManager::add_user_to_url($user_id, $current_access_url_id);
  490. if ($result ) {
  491. $user_info = api_get_user_info($user_id);
  492. $message = get_lang('UserAdded').' '.$user_info['firstname'].' '.$user_info['lastname'].' ('.$user_info['username'].')';
  493. $message = Display::return_message($message, 'confirmation');
  494. }
  495. break;
  496. case 'login_as':
  497. $login_as_user_id = $_GET["user_id"];
  498. if (isset ($login_as_user_id)) {
  499. login_user($login_as_user_id);
  500. }
  501. break;
  502. case 'show_message' :
  503. if (!empty($_GET['warn'])) {
  504. // to prevent too long messages
  505. if ($_GET['warn'] == 'session_message'){
  506. $_GET['warn'] = $_SESSION['session_message_import_users'];
  507. }
  508. $message = Display::return_message(urldecode($_GET['warn']),'warning', false);
  509. }
  510. if (!empty($_GET['message'])) {
  511. $message = Display :: return_message(stripslashes($_GET['message']), 'confirmation');
  512. }
  513. break;
  514. case 'delete_user' :
  515. if (api_is_platform_admin()) {
  516. $user_to_delete = $_GET['user_id'];
  517. $current_user_id = api_get_user_id();
  518. if ($delete_user_available && api_global_admin_can_edit_admin($_GET['user_id'])) {
  519. if ($user_to_delete != $current_user_id && UserManager :: delete_user($_GET['user_id'])) {
  520. $message = Display :: return_message(get_lang('UserDeleted'), 'confirmation');
  521. } else {
  522. $message = Display :: return_message(get_lang('CannotDeleteUserBecauseOwnsCourse'), 'error');
  523. }
  524. } else {
  525. $message = Display :: return_message(get_lang('CannotDeleteUser'),'error');
  526. }
  527. }
  528. break;
  529. case 'delete' :
  530. if (api_is_platform_admin()) {
  531. $number_of_selected_users = count($_POST['id']);
  532. $number_of_deleted_users = 0;
  533. if (is_array($_POST['id'])) {
  534. foreach ($_POST['id'] as $index => $user_id) {
  535. if($user_id != $_user['user_id']) {
  536. if(UserManager :: delete_user($user_id)) {
  537. $number_of_deleted_users++;
  538. }
  539. }
  540. }
  541. }
  542. if ($number_of_selected_users == $number_of_deleted_users) {
  543. $message = Display :: return_message(get_lang('SelectedUsersDeleted'), 'confirmation');
  544. } else {
  545. $message = Display :: return_message(get_lang('SomeUsersNotDeleted'), 'error');
  546. }
  547. }
  548. break;
  549. }
  550. Security::clear_token();
  551. }
  552. }
  553. // Create a search-box
  554. $form = new FormValidator('search_simple','get', '', '', array('class' => 'form-search'),false);
  555. /*$renderer =& $form->defaultRenderer();
  556. $renderer->setElementTemplate('<span>{element}</span> ');*/
  557. $form->addElement('text', 'keyword', get_lang('keyword'));
  558. $form->addElement('button', 'submit' ,get_lang('Search'));
  559. $form->addElement('advanced_settings', 'user_list_filter', get_lang('AdvancedSearch'));
  560. $actions = '';
  561. if (api_is_platform_admin()) {
  562. $actions .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_add.php">'.
  563. Display::return_icon('new_user.png',get_lang('AddUsers'),'',ICON_SIZE_MEDIUM).'</a>';
  564. }
  565. $actions .= $form->return_form();
  566. if (isset ($_GET['keyword'])) {
  567. $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
  568. } elseif (isset ($_GET['keyword_firstname'])) {
  569. $parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
  570. $parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
  571. $parameters['keyword_username'] = Security::remove_XSS($_GET['keyword_username']);
  572. $parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
  573. $parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
  574. $parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
  575. $parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
  576. $parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
  577. }
  578. // Create a sortable table with user-data
  579. $parameters['sec_token'] = Security::get_token();
  580. // get the list of all admins to mark them in the users list
  581. $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  582. $sql_admin = "SELECT user_id FROM $admin_table";
  583. $res_admin = Database::query($sql_admin);
  584. $_admins_list = array();
  585. while ($row_admin = Database::fetch_row($res_admin)) {
  586. $_admins_list[] = $row_admin[0];
  587. }
  588. // display advanced search form
  589. $form = new FormValidator('advanced_search','get');
  590. $form->addElement('html','<div id="user_list_filter_options" style="display:none;">');
  591. $form->addElement('header', get_lang('AdvancedSearch'));
  592. $form->addElement('html', '<table>');
  593. $form->addElement('html', '<tr><td>');
  594. $form->add_textfield('keyword_firstname',get_lang('FirstName'),false,array('style'=>'margin-left:17px'));
  595. $form->addElement('html', '</td><td width="200px;">');
  596. $form->add_textfield('keyword_lastname',get_lang('LastName'),false,array('style'=>'margin-left:17px'));
  597. $form->addElement('html', '</td></tr>');
  598. $form->addElement('html', '<tr><td>');
  599. $form->add_textfield('keyword_username',get_lang('LoginName'),false,array('style'=>'margin-left:17px'));
  600. $form->addElement('html', '</td>');
  601. $form->addElement('html', '<td>');
  602. $form->add_textfield('keyword_email',get_lang('Email'),false,array('style'=>'margin-left:17px'));
  603. $form->addElement('html', '</td></tr>');
  604. $form->addElement('html', '<tr><td>');
  605. $form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false,array('style'=>'margin-left:17px'));
  606. $form->addElement('html', '</td><td>');
  607. $status_options = array();
  608. $status_options['%'] = get_lang('All');
  609. $status_options[STUDENT] = get_lang('Student');
  610. $status_options[COURSEMANAGER] = get_lang('Teacher');
  611. $status_options[DRH] = get_lang('Drh');
  612. $status_options[SESSIONADMIN] = get_lang('Administrator');
  613. $form->addElement('select','keyword_status',get_lang('Profile'),$status_options, array('style'=>'margin-left:17px'));
  614. $form->addElement('html', '</td></tr>');
  615. $form->addElement('html', '<tr><td>');
  616. $active_group = array();
  617. $active_group[] = $form->createElement('checkbox','keyword_active','', get_lang('Active'));
  618. $active_group[] = $form->createElement('checkbox','keyword_inactive','', get_lang('Inactive'));
  619. $form->addGroup($active_group,'',get_lang('ActiveAccount'),'<br/>',false);
  620. $form->addElement('html', '</td><td>');
  621. $form->addElement('checkbox', 'check_easy_passwords', null, get_lang('CheckEasyPasswords'));
  622. $form->addElement('html', '</td></tr>');
  623. $form->addElement('html', '<tr><td>');
  624. $form->addElement('button', 'submit',get_lang('SearchUsers'));
  625. $form->addElement('html', '</td></tr>');
  626. $form->addElement('html', '</table>');
  627. $defaults = array();
  628. $defaults['keyword_active'] = 1;
  629. $defaults['keyword_inactive'] = 1;
  630. $form->setDefaults($defaults);
  631. $form->addElement('html','</div>');
  632. $form = $form->return_form();
  633. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
  634. $table->set_additional_parameters($parameters);
  635. $table->set_header(0, '', false);
  636. $table->set_header(1, get_lang('Photo'), false);
  637. $table->set_header(2, get_lang('OfficialCode'));
  638. if (api_is_western_name_order()) {
  639. $table->set_header(3, get_lang('FirstName'));
  640. $table->set_header(4, get_lang('LastName'));
  641. } else {
  642. $table->set_header(3, get_lang('LastName'));
  643. $table->set_header(4, get_lang('FirstName'));
  644. }
  645. $table->set_header(5, get_lang('LoginName'));
  646. $table->set_header(6, get_lang('Email'));
  647. $table->set_header(7, get_lang('Profile'));
  648. $table->set_header(8, get_lang('Active'), true);
  649. $table->set_header(9, get_lang('RegistrationDate'), true);
  650. $table->set_header(10, get_lang('Action'), false);
  651. $table->set_column_filter(6, 'email_filter');
  652. $table->set_column_filter(7, 'status_filter');
  653. $table->set_column_filter(8, 'active_filter');
  654. $table->set_column_filter(10, 'modify_filter');
  655. if (api_is_platform_admin()) {
  656. $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
  657. }
  658. $table_result = $table->return_table();
  659. $extra_search_options = '';
  660. //Try to search the user everywhere
  661. if ($table->get_total_number_of_items() == 0) {
  662. if (api_get_multiple_access_url() && isset($_REQUEST['keyword'])) {
  663. $keyword = Database::escape_string($_REQUEST['keyword']);
  664. //$conditions = array('firstname' => $keyword, 'lastname' => $keyword, 'username' => $keyword);
  665. $conditions = array('username' => $keyword);
  666. $user_list = UserManager::get_user_list($conditions, array(), false, ' OR ');
  667. if (!empty($user_list)) {
  668. $extra_search_options = Display::page_subheader(get_lang('UsersFoundInOtherPortals'));
  669. $table = new HTML_Table(array('class' => 'data_table'));
  670. $column = 0;
  671. $row = 0;
  672. $headers = array(get_lang('User'), 'URL', get_lang('Actions'));
  673. foreach ($headers as $header) {
  674. $table->setHeaderContents($row, $column, $header);
  675. $column++;
  676. }
  677. $row++;
  678. foreach ($user_list as $user) {
  679. $column = 0;
  680. $access_info = UrlManager::get_access_url_from_user($user['user_id']);
  681. $access_info_to_string = '';
  682. $add_user = true;
  683. if (!empty($access_info)) {
  684. foreach ($access_info as $url_info) {
  685. if ($current_access_url_id == $url_info['access_url_id']) {
  686. $add_user = false;
  687. }
  688. $access_info_to_string .= $url_info['url'].'<br />';
  689. }
  690. }
  691. if ($add_user) {
  692. $row_table = array();
  693. $row_table[] = api_get_person_name($user['firstname'], $user['lastname']).' ('.$user['username'].') ';
  694. $row_table[] = $access_info_to_string;
  695. $url = api_get_self().'?action=add_user_to_my_url&user_id='.$user['user_id'].'&sec_token='.Security::getCurrentToken();
  696. $row_table[] = Display::url(get_lang('AddUserToMyURL'), $url, array('class' => 'btn'));
  697. foreach ($row_table as $cell) {
  698. $table->setCellContents($row, $column, $cell);
  699. $table->updateCellAttributes($row, $column, 'align="center"');
  700. $column++;
  701. }
  702. $table->updateRowAttributes($row, $row % 2 ? 'class="row_even"' : 'class="row_odd"', true);
  703. $row++;
  704. }
  705. }
  706. $extra_search_options .= $table->toHtml();
  707. $table_result = '';
  708. }
  709. }
  710. }
  711. $app['title'] = $tool_name;
  712. $tpl = $app['template'];
  713. $tpl->assign('actions', $actions);
  714. $tpl->assign('message', $message);
  715. $tpl->assign('content', $form.$table_result.$extra_search_options);