user_list.php 35 KB

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