user_list.php 32 KB

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