user_list.php 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005
  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. require_once '../inc/global.inc.php';
  12. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  13. require_once api_get_path(LIBRARY_PATH).'xajax/xajax.inc.php';
  14. global $_configuration;
  15. // Blocks the possibility to delete a user
  16. $delete_user_available = true;
  17. if (isset($_configuration['deny_delete_users']) && $_configuration['deny_delete_users']) {
  18. $delete_user_available = false;
  19. }
  20. $htmlHeadXtra[] = api_get_jquery_ui_js();
  21. $htmlHeadXtra[] = '<script type="text/javascript">
  22. function load_course_list (div_course,my_user_id) {
  23. $.ajax({
  24. contentType: "application/x-www-form-urlencoded",
  25. beforeSend: function(objeto) {
  26. $("div#"+div_course).html("<img src=\'../inc/lib/javascript/indicator.gif\' />"); },
  27. type: "POST",
  28. url: "course_user_list.php",
  29. data: "user_id="+my_user_id,
  30. success: function(datos) {
  31. $("div#"+div_course).html(datos);
  32. $("div#div_"+my_user_id).attr("class","blackboard_show");
  33. $("div#div_"+my_user_id).attr("style","");
  34. }
  35. });
  36. }
  37. function active_user(element_div) {
  38. id_image=$(element_div).attr("id");
  39. image_clicked=$(element_div).attr("src");
  40. image_clicked_info = image_clicked.split("/");
  41. image_real_clicked = image_clicked_info[image_clicked_info.length-1];
  42. var status = 1;
  43. if (image_real_clicked == "accept.png") {
  44. status = 0;
  45. }
  46. user_id=id_image.split("_");
  47. ident="#img_"+user_id[1];
  48. if (confirm("'.get_lang('AreYouSureToEditTheUserStatus', '').'")) {
  49. $.ajax({
  50. contentType: "application/x-www-form-urlencoded",
  51. beforeSend: function(objeto) {
  52. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'loading1.gif'.'"); }, //candy eye stuff
  53. type: "GET",
  54. url: "'.api_get_path(WEB_AJAX_PATH).'user_manager.ajax.php?a=active_user",
  55. data: "user_id="+user_id[1]+"&status="+status,
  56. success: function(datos) {
  57. if (status == 1) {
  58. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/accept.png'.'");
  59. $(ident).attr("title","'.get_lang('Lock').'");
  60. } else {
  61. $(ident).attr("src","'.api_get_path(WEB_IMG_PATH).'icons/16/error.png'.'");
  62. $(ident).attr("title","'.get_lang('Unlock').'");
  63. }
  64. }
  65. });
  66. }
  67. }
  68. function clear_course_list (div_course) {
  69. $("div#"+div_course).html("&nbsp;");
  70. $("div#"+div_course).hide("");
  71. }
  72. function display_advanced_search_form () {
  73. if ($("#advanced_search_form").css("display") == "none") {
  74. $("#advanced_search_form").css("display","block");
  75. $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_hide.gif',get_lang('Hide'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedSearch').'\');
  76. } else {
  77. $("#advanced_search_form").css("display","none");
  78. $("#img_plus_and_minus").html(\'&nbsp;'.Display::return_icon('div_show.gif',get_lang('Show'),array('style'=>'vertical-align:middle')).'&nbsp;'.get_lang('AdvancedSearch').'\');
  79. }
  80. }
  81. $(document).ready(function() {
  82. var select_val = $("#input_select_extra_data").val();
  83. if ( document.getElementById(\'extra_data_text\')) {
  84. if (select_val != 0) {
  85. document.getElementById(\'extra_data_text\').style.display="block";
  86. if (document.getElementById(\'input_extra_text\'))
  87. document.getElementById(\'input_extra_text\').value = "";
  88. } else {
  89. document.getElementById(\'extra_data_text\').style.display="none";
  90. }
  91. }
  92. $(".agenda_opener").live("click", function() {
  93. var url = this.href;
  94. var dialog = $("#dialog");
  95. if ($("#dialog").length == 0) {
  96. dialog = $(\'<div id="dialog" style="display:hidden"></div> \').appendTo(\'body\');
  97. }
  98. // load remote content
  99. dialog.load(
  100. url,
  101. {},
  102. function(responseText, textStatus, XMLHttpRequest) {
  103. dialog.dialog({width:720, height:550, modal:true});
  104. }
  105. );
  106. //prevent the browser to follow the link
  107. return false;
  108. });
  109. });
  110. //Load user calendar
  111. function load_calendar(user_id, month, year) {
  112. var url = "'.api_get_path(WEB_AJAX_PATH).'agenda.ajax.php?a=get_user_agenda&user_id=" +user_id + "&month="+month+"&year="+year;
  113. $("#dialog").load( url
  114. );
  115. }
  116. </script>';
  117. $htmlHeadXtra[] = '<style type="text/css" media="screen, projection">
  118. .blackboard_show {
  119. float:left;
  120. position:absolute;
  121. border:1px solid black;
  122. width: 200px;
  123. background-color:white;
  124. z-index:99; padding: 3px;
  125. display: inline;
  126. }
  127. .blackboard_hide {
  128. display: none;
  129. }
  130. </style>';
  131. // xajax
  132. $xajax = new xajax();
  133. $xajax->registerFunction('courses_of_user');
  134. //$xajax->registerFunction('empty_courses_of_user');
  135. $xajax->processRequests();
  136. /**
  137. * Get a formatted list of courses for given user
  138. * @param int User ID
  139. * @return resource XAJAX response
  140. */
  141. function courses_of_user($arg) {
  142. // do some stuff based on $arg like query data from a database and
  143. // put it into a variable like $newContent
  144. //$newContent = 'werkt het? en met een beetje meer text, wordt dat goed opgelost? ';
  145. $personal_course_list = UserManager::get_personal_session_course_list($arg);
  146. $newContent = '';
  147. if(count($personal_course_list)>0)
  148. {
  149. foreach ($personal_course_list as $key=>$course)
  150. {
  151. $newContent .= $course['i'].'<br />';
  152. }
  153. }
  154. else
  155. {
  156. $newContent .= '- '.get_lang('None').' -<br />';
  157. }
  158. $newContent = api_convert_encoding($newContent,'utf-8',api_get_system_encoding());
  159. // Instantiate the xajaxResponse object
  160. $objResponse = new xajaxResponse();
  161. // add a command to the response to assign the innerHTML attribute of
  162. // the element with id="SomeElementId" to whatever the new content is
  163. $objResponse->addAssign("user".$arg,"innerHTML", $newContent);
  164. $objResponse->addReplace("coursesofuser".$arg,"alt", $newContent);
  165. $objResponse->addReplace("coursesofuser".$arg,"title", $newContent);
  166. $objResponse->addAssign("user".$arg,"style.display", "block");
  167. //return the xajaxResponse object
  168. return $objResponse;
  169. }
  170. /**
  171. * Empties the XAJAX object representing the courses list
  172. * @param int User ID
  173. * @return resource XAJAX object
  174. */
  175. function empty_courses_of_user($arg)
  176. {
  177. // do some stuff based on $arg like query data from a database and
  178. // put it into a variable like $newContent
  179. $newContent = '';
  180. // Instantiate the xajaxResponse object
  181. $objResponse = new xajaxResponse();
  182. // add a command to the response to assign the innerHTML attribute of
  183. // the element with id="SomeElementId" to whatever the new content is
  184. $objResponse->addAssign("user".$arg,"innerHTML", $newContent);
  185. //return the xajaxResponse object
  186. return $objResponse;
  187. }
  188. $htmlHeadXtra[] = $xajax->getJavascript('../inc/lib/xajax/');
  189. $htmlHeadXtra[] = '<style>
  190. .tooltipLinkInner {
  191. position:relative;
  192. float:left;
  193. color:blue;
  194. text-decoration:none;
  195. }
  196. </style>';
  197. $this_section = SECTION_PLATFORM_ADMIN;
  198. api_protect_admin_script(true);
  199. /**
  200. * Make sure this function is protected because it does NOT check password!
  201. *
  202. * This function defines globals.
  203. * @param int User ID
  204. * @return bool False on failure, redirection on success
  205. * @author Evie Embrechts
  206. * @author Yannick Warnier <yannick.warnier@dokeos.com>
  207. */
  208. function login_user($user_id) {
  209. //init
  210. //Load $_user to be sure we clean it before logging in
  211. global $uidReset, $loginFailed, $_configuration, $_user;
  212. $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
  213. $main_admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  214. $track_e_login_table = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_LOGIN);
  215. //logic
  216. unset($_user['user_id']); // uid not in session ? prevent any hacking
  217. if (!isset ($user_id)) {
  218. $uidReset = true;
  219. return;
  220. }
  221. if ($user_id != strval(intval($user_id))) {
  222. return false;
  223. }
  224. $sql_query = "SELECT * FROM $main_user_table WHERE user_id='$user_id'";
  225. $sql_result = Database::query($sql_query);
  226. $result = Database :: fetch_array($sql_result);
  227. // check if the user is allowed to 'login_as'
  228. $can_login_as = (api_is_platform_admin() OR (api_is_session_admin() && $result['status'] == 5 ));
  229. if (!$can_login_as) { return false; }
  230. $firstname = $result['firstname'];
  231. $lastname = $result['lastname'];
  232. $user_id = $result['user_id'];
  233. //$message = "Attempting to login as ".api_get_person_name($firstname, $lastname)." (id ".$user_id.")";
  234. if (api_is_western_name_order()) {
  235. $message = sprintf(get_lang('AttemptingToLoginAs'),$firstname,$lastname,$user_id);
  236. } else {
  237. $message = sprintf(get_lang('AttemptingToLoginAs'), $lastname, $firstname, $user_id);
  238. }
  239. $loginFailed = false;
  240. $uidReset = false;
  241. if ($user_id) { // a uid is given (log in succeeded)
  242. $sql_query = "SELECT user.*, a.user_id is_admin,
  243. UNIX_TIMESTAMP(login.login_date) login_date
  244. FROM $main_user_table
  245. LEFT JOIN $main_admin_table a
  246. ON user.user_id = a.user_id
  247. LEFT JOIN $track_e_login_table login
  248. ON user.user_id = login.login_user_id
  249. WHERE user.user_id = '".$user_id."'
  250. ORDER BY login.login_date DESC LIMIT 1";
  251. $sql_result = Database::query($sql_query);
  252. if (Database::num_rows($sql_result) > 0) {
  253. // Extracting the user data
  254. $user_data = Database::fetch_array($sql_result);
  255. //Delog the current user
  256. LoginDelete($_SESSION["_user"]["user_id"]);
  257. // Cleaning session variables
  258. unset($_SESSION['_user']);
  259. unset($_SESSION['is_platformAdmin']);
  260. unset($_SESSION['is_allowedCreateCourse']);
  261. unset($_SESSION['_uid']);
  262. $_user['firstName'] = $user_data['firstname'];
  263. $_user['lastName'] = $user_data['lastname'];
  264. $_user['mail'] = $user_data['email'];
  265. $_user['lastLogin'] = $user_data['login_date'];
  266. $_user['official_code'] = $user_data['official_code'];
  267. $_user['picture_uri'] = $user_data['picture_uri'];
  268. $_user['user_id'] = $user_data['user_id'];
  269. $_user['status'] = $user_data['status'];
  270. $is_platformAdmin = (bool) (!is_null($user_data['is_admin']));
  271. $is_allowedCreateCourse = (bool) ($user_data['status'] == 1);
  272. // Filling session variables with new data
  273. $_SESSION['_uid'] = $user_id;
  274. $_SESSION['_user'] = $_user;
  275. $_SESSION['is_platformAdmin'] = $is_platformAdmin;
  276. $_SESSION['is_allowedCreateCourse'] = $is_allowedCreateCourse;
  277. $_SESSION['login_as'] = true; // will be usefull later to know if the user is actually an admin or not (example reporting)s
  278. $target_url = api_get_path(WEB_PATH)."user_portal.php";
  279. //$message .= "<br/>Login successful. Go to <a href=\"$target_url\">$target_url</a>";
  280. $message .= '<br />'.sprintf(get_lang('LoginSuccessfulGoToX'),'<a href="'.$target_url.'">'.$target_url.'</a>');
  281. Display :: display_header(get_lang('UserList'));
  282. Display :: display_normal_message($message,false);
  283. Display :: display_footer();
  284. exit;
  285. } else {
  286. exit ("<br />WARNING UNDEFINED UID !! ");
  287. }
  288. }
  289. }
  290. /**
  291. * Get the total number of users on the platform
  292. * @see SortableTable#get_total_number_of_items()
  293. */
  294. function get_number_of_users() {
  295. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  296. $sql = "SELECT COUNT(u.user_id) AS total_number_of_items FROM $user_table u";
  297. // adding the filter to see the user's only of the current access_url
  298. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  299. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  300. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  301. }
  302. if (isset($_GET['keyword_extra_data'])) {
  303. $keyword_extra_data = Database::escape_string($_GET['keyword_extra_data']);
  304. if (!empty($keyword_extra_data)) {
  305. $extra_info = UserManager::get_extra_field_information_by_name($keyword_extra_data);
  306. $field_id = $extra_info['id'];
  307. $sql.= " INNER JOIN user_field_values ufv ON u.user_id=ufv.user_id AND ufv.field_id=$field_id ";
  308. }
  309. }
  310. if ( isset ($_GET['keyword'])) {
  311. $keyword = Database::escape_string(trim($_GET['keyword']));
  312. $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.email LIKE '%".$keyword."%' OR u.official_code LIKE '%".$keyword."%') ";
  313. } elseif (isset ($_GET['keyword_firstname'])) {
  314. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  315. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  316. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  317. $keyword_email = Database::escape_string($_GET['keyword_email']);
  318. $keyword_officialcode = Database::escape_string($_GET['keyword_officialcode']);
  319. $keyword_username = Database::escape_string($_GET['keyword_username']);
  320. $keyword_status = Database::escape_string($_GET['keyword_status']);
  321. $query_admin_table = '';
  322. $keyword_admin = '';
  323. if ($keyword_status == SESSIONADMIN) {
  324. $keyword_status = '%';
  325. $query_admin_table = " , $admin_table a ";
  326. $keyword_admin = ' AND a.user_id = u.user_id ';
  327. }
  328. $keyword_extra_value = '';
  329. if (isset($_GET['keyword_extra_data'])) {
  330. if (!empty($_GET['keyword_extra_data']) && !empty($_GET['keyword_extra_data_text'])) {
  331. $keyword_extra_data_text = Database::escape_string($_GET['keyword_extra_data_text']);
  332. $keyword_extra_value = " AND ufv.field_value LIKE '%".trim($keyword_extra_data_text)."%' ";
  333. }
  334. }
  335. $keyword_active = isset($_GET['keyword_active']);
  336. $keyword_inactive = isset($_GET['keyword_inactive']);
  337. $sql .= $query_admin_table .
  338. " WHERE (u.firstname LIKE '%".$keyword_firstname."%' " .
  339. "AND u.lastname LIKE '%".$keyword_lastname."%' " .
  340. "AND u.username LIKE '%".$keyword_username."%' " .
  341. "AND u.email LIKE '%".$keyword_email."%' " .
  342. "AND u.official_code LIKE '%".$keyword_officialcode."%'" .
  343. "AND u.status LIKE '".$keyword_status."'" .
  344. $keyword_admin.$keyword_extra_value;
  345. if($keyword_active && !$keyword_inactive) {
  346. $sql .= " AND u.active='1'";
  347. } elseif($keyword_inactive && !$keyword_active) {
  348. $sql .= " AND u.active='0'";
  349. }
  350. $sql .= " ) ";
  351. }
  352. // adding the filter to see the user's only of the current access_url
  353. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  354. $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  355. }
  356. $res = Database::query($sql);
  357. $obj = Database::fetch_object($res);
  358. return $obj->total_number_of_items;
  359. }
  360. /**
  361. * Get the users to display on the current page (fill the sortable-table)
  362. * @param int offset of first user to recover
  363. * @param int Number of users to get
  364. * @param int Column to sort on
  365. * @param string Order (ASC,DESC)
  366. * @see SortableTable#get_table_data($from)
  367. */
  368. function get_user_data($from, $number_of_items, $column, $direction)
  369. {
  370. global $origin;
  371. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  372. $admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
  373. $sql = "SELECT
  374. u.user_id AS col0,
  375. u.official_code AS col2,
  376. ".(api_is_western_name_order()
  377. ? "u.firstname AS col3,
  378. u.lastname AS col4,"
  379. : "u.lastname AS col3,
  380. u.firstname AS col4,")."
  381. u.username AS col5,
  382. u.email AS col6,
  383. u.status AS col7,
  384. u.active AS col8,
  385. u.user_id AS col9 ".
  386. ", u.expiration_date AS exp ".
  387. " FROM $user_table u ";
  388. // adding the filter to see the user's only of the current access_url
  389. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  390. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  391. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  392. }
  393. if (isset($_GET['keyword_extra_data'])) {
  394. $keyword_extra_data = Database::escape_string($_GET['keyword_extra_data']);
  395. if (!empty($keyword_extra_data)) {
  396. $extra_info = UserManager::get_extra_field_information_by_name($keyword_extra_data);
  397. $field_id = $extra_info['id'];
  398. $sql.= " INNER JOIN user_field_values ufv ON u.user_id=ufv.user_id AND ufv.field_id=$field_id ";
  399. }
  400. }
  401. if (isset ($_GET['keyword'])) {
  402. $keyword = Database::escape_string(trim($_GET['keyword']));
  403. $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."%' )";
  404. } elseif (isset ($_GET['keyword_firstname'])) {
  405. $keyword_firstname = Database::escape_string($_GET['keyword_firstname']);
  406. $keyword_lastname = Database::escape_string($_GET['keyword_lastname']);
  407. $keyword_email = Database::escape_string($_GET['keyword_email']);
  408. $keyword_officialcode = Database::escape_string($_GET['keyword_officialcode']);
  409. $keyword_username = Database::escape_string($_GET['keyword_username']);
  410. $keyword_status = Database::escape_string($_GET['keyword_status']);
  411. $query_admin_table = '';
  412. $keyword_admin = '';
  413. if ($keyword_status == SESSIONADMIN) {
  414. $keyword_status = '%';
  415. $query_admin_table = " , $admin_table a ";
  416. $keyword_admin = ' AND a.user_id = u.user_id ';
  417. }
  418. $keyword_extra_value = '';
  419. if (isset($_GET['keyword_extra_data'])) {
  420. if (!empty($_GET['keyword_extra_data']) && !empty($_GET['keyword_extra_data_text'])) {
  421. $keyword_extra_data_text = Database::escape_string($_GET['keyword_extra_data_text']);
  422. $keyword_extra_value = " AND ufv.field_value LIKE '%".trim($keyword_extra_data_text)."%' ";
  423. }
  424. }
  425. $keyword_active = isset($_GET['keyword_active']);
  426. $keyword_inactive = isset($_GET['keyword_inactive']);
  427. $sql .= $query_admin_table." WHERE (u.firstname LIKE '%".$keyword_firstname."%' " .
  428. "AND u.lastname LIKE '%".$keyword_lastname."%' " .
  429. "AND u.username LIKE '%".$keyword_username."%' " .
  430. "AND u.email LIKE '%".$keyword_email."%' " .
  431. "AND u.official_code LIKE '%".$keyword_officialcode."%' " .
  432. "AND u.status LIKE '".$keyword_status."'" .
  433. $keyword_admin.$keyword_extra_value;
  434. if ($keyword_active && !$keyword_inactive) {
  435. $sql .= " AND u.active='1'";
  436. } elseif($keyword_inactive && !$keyword_active) {
  437. $sql .= " AND u.active='0'";
  438. }
  439. $sql .= " ) ";
  440. }
  441. // adding the filter to see the user's only of the current access_url
  442. if ((api_is_platform_admin() || api_is_session_admin()) && api_get_multiple_access_url()) {
  443. $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  444. }
  445. if (!in_array($direction, array('ASC','DESC'))) {
  446. $direction = 'ASC';
  447. }
  448. $column = intval($column);
  449. $from = intval($from);
  450. $number_of_items = intval($number_of_items);
  451. $sql .= " ORDER BY col$column $direction ";
  452. $sql .= " LIMIT $from,$number_of_items";
  453. $res = Database::query($sql);
  454. $users = array ();
  455. $t = time();
  456. while ($user = Database::fetch_row($res)) {
  457. $image_path = UserManager::get_user_picture_path_by_id($user[0], 'web', false, true);
  458. $user_profile = UserManager::get_picture_user($user[0], $image_path['file'], 22, USER_IMAGE_SIZE_SMALL, ' width="22" height="22" ');
  459. if (!api_is_anonymous()) {
  460. $photo = '<center><a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$user[0].'" title="'.get_lang('Info').'"><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>';
  461. } else {
  462. $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>';
  463. }
  464. if ($user[7] == 1 && $user[9] != '0000-00-00 00:00:00') {
  465. // check expiration date
  466. $expiration_time = convert_mysql_date($user[9]);
  467. // if expiration date is passed, store a special value for active field
  468. if ($expiration_time < $t) {
  469. $user[7] = '-1';
  470. }
  471. }
  472. // forget about the expiration date field
  473. $users[] = array($user[0],$photo,$user[1],$user[2],$user[3],$user[4],$user[5],$user[6],$user[7],$user[8]);
  474. }
  475. return $users;
  476. }
  477. /**
  478. * Returns a mailto-link
  479. * @param string $email An email-address
  480. * @return string HTML-code with a mailto-link
  481. */
  482. function email_filter($email)
  483. {
  484. return Display :: encrypted_mailto_link($email, $email);
  485. }
  486. /**
  487. * Returns a mailto-link
  488. * @param string $email An email-address
  489. * @return string HTML-code with a mailto-link
  490. */
  491. function user_filter($name, $params, $row) {
  492. return '<a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$row[0].'">'.$name.'</a>';
  493. }
  494. /**
  495. * Build the modify-column of the table
  496. * @param int The user id
  497. * @param string URL params to add to table links
  498. * @param array Row of elements to alter
  499. * @return string Some HTML-code with modify-buttons
  500. */
  501. function modify_filter($user_id,$url_params,$row) {
  502. global $charset, $_user, $_admins_list, $delete_user_available;
  503. $is_admin = in_array($user_id,$_admins_list);
  504. $statusname = api_get_status_langvars();
  505. $user_is_anonymous = false;
  506. if ($row['7'] == $statusname[ANONYMOUS]) {
  507. $user_is_anonymous =true;
  508. }
  509. $result = '';
  510. if (!$user_is_anonymous) {
  511. $result .= '<a href="javascript:void(0)" onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')">
  512. <img onclick="load_course_list(\'div_'.$user_id.'\','.$user_id.')" onmouseout="clear_course_list (\'div_'.$user_id.'\')" src="../img/course.gif" title="'.get_lang('Courses').'" alt="'.get_lang('Courses').'"/>
  513. <div class="blackboard_hide" id="div_'.$user_id.'">&nbsp;&nbsp;</div>
  514. </a>&nbsp;&nbsp;';
  515. } else {
  516. $result .= Display::return_icon('course_na.gif',get_lang('Courses')).'&nbsp;&nbsp;';
  517. }
  518. if (api_is_platform_admin()) {
  519. if (!$user_is_anonymous) {
  520. $result .= '<a href="user_information.php?user_id='.$user_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;&nbsp;';
  521. } else {
  522. $result .= Display::return_icon('synthese_view_na.gif', get_lang('Info')).'&nbsp;&nbsp;';
  523. }
  524. }
  525. //only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
  526. if (api_is_platform_admin() || (api_is_session_admin() && $row['7'] == $statusname[STUDENT])) {
  527. if (!$user_is_anonymous) {
  528. $result .= '<a href="user_list.php?action=login_as&amp;user_id='.$user_id.'&amp;sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('login_as.gif', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
  529. } else {
  530. $result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).'&nbsp;&nbsp;';
  531. }
  532. } else {
  533. $result .= Display::return_icon('login_as_na.gif', get_lang('LoginAs')).'&nbsp;&nbsp;';
  534. }
  535. if ($row['7'] != $statusname[STUDENT]) {
  536. $result .= Display::return_icon('statistics_na.gif', get_lang('Reporting')).'&nbsp;&nbsp;';
  537. } else {
  538. $result .= '<a href="../mySpace/myStudents.php?student='.$user_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;&nbsp;';
  539. }
  540. if (api_is_platform_admin()) {
  541. if (!$user_is_anonymous) {
  542. $result .= '<a href="user_edit.php?user_id='.$user_id.'">'.Display::return_icon('edit.png', get_lang('Edit'), array(), 22).'</a>&nbsp;';
  543. } else {
  544. $result .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), 22).'</a>&nbsp;';
  545. }
  546. }
  547. if ($is_admin) {
  548. $result .= Display::return_icon('admin_star.png', get_lang('IsAdministrator'),array('width'=> 22, 'heigth'=> 22));
  549. } else {
  550. $result .= Display::return_icon('admin_star_na.png', get_lang('IsNotAdministrator'));
  551. }
  552. // actions for assigning sessions, courses or users
  553. if (api_is_session_admin()) {
  554. /*if ($row[0] == api_get_user_id()) {
  555. $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;';
  556. }*/
  557. } else {
  558. if ($row['7'] == $statusname[DRH] || UserManager::is_admin($row[0])) {
  559. $result .= '<a href="dashboard_add_users_to_user.php?user='.$user_id.'">'.Display::return_icon('user_subscribe_course.png', get_lang('AssignUsers'),'','22').'</a>';
  560. $result .= '<a href="dashboard_add_courses_to_user.php?user='.$user_id.'">'.Display::return_icon('course_add.gif', get_lang('AssignCourses')).'</a>&nbsp;&nbsp;';
  561. $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;';
  562. } else if ($row['7'] == $statusname[SESSIONADMIN]) {
  563. $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;';
  564. }
  565. }
  566. if (api_is_platform_admin()) {
  567. $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(), 22).'</a>';
  568. if ($delete_user_available) {
  569. if ($row[0] != $_user['user_id'] && !$user_is_anonymous) {
  570. // 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.
  571. $result .= ' <a href="user_list.php?action=delete_user&amp;user_id='.$user_id.'&amp;'.$url_params.'&amp;sec_token='.$_SESSION['sec_token'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES,$charset))."'".')) return false;">'.Display::return_icon('delete.png', get_lang('Delete'), array(), 22).'</a>';
  572. } else {
  573. $result .= Display::return_icon('delete_na.png', get_lang('Delete'), array(), 22);
  574. }
  575. }
  576. }
  577. return $result;
  578. }
  579. /**
  580. * Build the active-column of the table to lock or unlock a certain user
  581. * lock = the user can no longer use this account
  582. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  583. * @param int $active the current state of the account
  584. * @param int $user_id The user id
  585. * @param string $url_params
  586. * @return string Some HTML-code with the lock/unlock button
  587. */
  588. function active_filter($active, $url_params, $row) {
  589. global $_user;
  590. if ($active=='1') {
  591. $action='Lock';
  592. $image='accept';
  593. } elseif ($active=='-1') {
  594. $action='edit';
  595. $image='warning';
  596. } elseif ($active=='0') {
  597. $action='Unlock';
  598. $image='error';
  599. }
  600. $result = '';
  601. if ($action=='edit') {
  602. $result = Display::return_icon($image.'.png', get_lang('AccountExpired'), array(), 16);
  603. } elseif ($row['0']<>$_user['user_id']) {
  604. // 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.
  605. $result = Display::return_icon($image.'.png', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0']), 16).'</a>';
  606. }
  607. return $result;
  608. }
  609. /**
  610. * Lock or unlock a user
  611. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  612. * @param int $status, do we want to lock the user ($status=lock) or unlock it ($status=unlock)
  613. * @param int $user_id The user id
  614. * @return language variable
  615. */
  616. function lock_unlock_user($status,$user_id)
  617. {
  618. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  619. if ($status=='lock')
  620. {
  621. $status_db='0';
  622. $return_message=get_lang('UserLocked');
  623. }
  624. if ($status=='unlock')
  625. {
  626. $status_db='1';
  627. $return_message=get_lang('UserUnlocked');
  628. }
  629. if(($status_db=='1' OR $status_db=='0') AND is_numeric($user_id))
  630. {
  631. $sql="UPDATE $user_table SET active='".Database::escape_string($status_db)."' WHERE user_id='".Database::escape_string($user_id)."'";
  632. $result = Database::query($sql);
  633. }
  634. if ($result)
  635. {
  636. return $return_message;
  637. }
  638. }
  639. /**
  640. * Instead of displaying the integer of the status, we give a translation for the status
  641. *
  642. * @param integer $status
  643. * @return string translation
  644. *
  645. * @version march 2008
  646. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  647. */
  648. function status_filter($status)
  649. {
  650. $statusname = api_get_status_langvars();
  651. return $statusname[$status];
  652. }
  653. /** INIT SECTION */
  654. $action = $_GET["action"];
  655. $login_as_user_id = $_GET["user_id"];
  656. // Login as ...
  657. if ($_GET['action'] == "login_as" && isset ($login_as_user_id)) {
  658. login_user($login_as_user_id);
  659. }
  660. if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
  661. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  662. $interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
  663. $tool_name = get_lang('SearchUsers');
  664. } else {
  665. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  666. $tool_name = get_lang('UserList');
  667. }
  668. Display :: display_header($tool_name, "");
  669. //api_display_tool_title($tool_name);
  670. if (isset ($_GET['action'])) {
  671. $check = Security::check_token('get');
  672. if ($check) {
  673. switch ($_GET['action']) {
  674. case 'show_message' :
  675. if (!empty($_GET['warn'])) {
  676. // to prevent too long messages
  677. if ($_GET['warn'] == 'session_message'){
  678. $_GET['warn'] = $_SESSION['session_message_import_users'];
  679. }
  680. Display::display_warning_message(urldecode($_GET['warn']),false);
  681. }
  682. if (!empty($_GET['message'])) {
  683. Display :: display_confirmation_message(stripslashes($_GET['message']));
  684. }
  685. break;
  686. case 'delete_user' :
  687. if (api_is_platform_admin()) {
  688. if ($delete_user_available) {
  689. if ($user_id != $_user['user_id'] && UserManager :: delete_user($_GET['user_id'])) {
  690. Display :: display_confirmation_message(get_lang('UserDeleted'));
  691. } else {
  692. Display :: display_error_message(get_lang('CannotDeleteUserBecauseOwnsCourse'));
  693. }
  694. } else {
  695. Display :: display_error_message(get_lang('CannotDeleteUser'));
  696. }
  697. }
  698. break;
  699. case 'lock' :
  700. $message=lock_unlock_user('lock',$_GET['user_id']);
  701. Display :: display_normal_message($message);
  702. break;
  703. case 'unlock';
  704. $message=lock_unlock_user('unlock',$_GET['user_id']);
  705. Display :: display_normal_message($message);
  706. break;
  707. }
  708. Security::clear_token();
  709. }
  710. }
  711. if (isset ($_POST['action'])) {
  712. $check = Security::check_token('get');
  713. if ($check) {
  714. switch ($_POST['action']) {
  715. case 'delete' :
  716. if (api_is_platform_admin()) {
  717. $number_of_selected_users = count($_POST['id']);
  718. $number_of_deleted_users = 0;
  719. if (is_array($_POST['id'])) {
  720. foreach ($_POST['id'] as $index => $user_id)
  721. {
  722. if($user_id != $_user['user_id'])
  723. {
  724. if(UserManager :: delete_user($user_id))
  725. {
  726. $number_of_deleted_users++;
  727. }
  728. }
  729. }
  730. }
  731. if($number_of_selected_users == $number_of_deleted_users)
  732. {
  733. Display :: display_confirmation_message(get_lang('SelectedUsersDeleted'));
  734. }
  735. else
  736. {
  737. Display :: display_error_message(get_lang('SomeUsersNotDeleted'));
  738. }
  739. }
  740. break;
  741. }
  742. Security::clear_token();
  743. }
  744. }
  745. // Create a search-box
  746. $form = new FormValidator('search_simple','get','','',null,false);
  747. $renderer =& $form->defaultRenderer();
  748. $renderer->setElementTemplate('<span>{element}</span> ');
  749. $form->addElement('text','keyword',get_lang('keyword'), 'size="25"');
  750. $form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"');
  751. //$form->addElement('static','search_advanced_link',null,'<a href="user_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  752. $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>');
  753. echo '<div class="actions" style="width:100%;">';
  754. if (api_is_platform_admin()) {
  755. echo '<span style="float:right;">'.
  756. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/user_add.php">'.Display::return_icon('new_user.png',get_lang('AddUsers'),'','32').'</a>'.
  757. '</span>';
  758. }
  759. $form->display();
  760. echo '</div>';
  761. if (isset ($_GET['keyword'])) {
  762. $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
  763. } elseif (isset ($_GET['keyword_firstname'])) {
  764. $parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
  765. $parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
  766. $parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
  767. $parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
  768. $parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
  769. $parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
  770. $parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
  771. }
  772. // Create a sortable table with user-data
  773. $parameters['sec_token'] = Security::get_token();
  774. // get the list of all admins to mark them in the users list
  775. $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  776. $sql_admin = "SELECT user_id FROM $admin_table";
  777. $res_admin = Database::query($sql_admin);
  778. $_admins_list = array();
  779. while ($row_admin = Database::fetch_row($res_admin)) {
  780. $_admins_list[] = $row_admin[0];
  781. }
  782. // display advaced search form
  783. $form = new FormValidator('advanced_search','get');
  784. $form->addElement('html','<div id="advanced_search_form" style="display:none;">');
  785. $form->addElement('header', '', get_lang('AdvancedSearch'));
  786. //$form->addElement('html', '<strong>'.get_lang('SearchAUser').'</strong>');
  787. $form->addElement('html', '<table>');
  788. $form->addElement('html', '<tr><td>');
  789. $form->add_textfield('keyword_firstname',get_lang('FirstName'),false,array('style'=>'margin-left:17px'));
  790. $form->addElement('html', '</td><td width="200px;">');
  791. $form->add_textfield('keyword_lastname',get_lang('LastName'),false,array('style'=>'margin-left:17px'));
  792. $form->addElement('html', '</td></tr>');
  793. $form->addElement('html', '<tr><td>');
  794. $form->add_textfield('keyword_username',get_lang('LoginName'),false,array('style'=>'margin-left:17px'));
  795. $form->addElement('html', '</td>');
  796. $form->addElement('html', '<td>');
  797. $form->add_textfield('keyword_email',get_lang('Email'),false,array('style'=>'margin-left:17px'));
  798. $form->addElement('html', '</td></tr>');
  799. $form->addElement('html', '<tr><td>');
  800. $form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false,array('style'=>'margin-left:17px'));
  801. $form->addElement('html', '</td><td>');
  802. $status_options = array();
  803. $status_options['%'] = get_lang('All');
  804. $status_options[STUDENT] = get_lang('Student');
  805. $status_options[COURSEMANAGER] = get_lang('Teacher');
  806. $status_options[DRH] = get_lang('Drh');
  807. $status_options[SESSIONADMIN] = get_lang('Administrator');
  808. $form->addElement('select','keyword_status',get_lang('Profile'),$status_options, array('style'=>'margin-left:17px'));
  809. $form->addElement('html', '</td></tr>');
  810. $form->addElement('html', '<tr><td>');
  811. $active_group = array();
  812. $active_group[] = $form->createElement('checkbox','keyword_active','',get_lang('Active'), array('style'=>'margin-left:17px'));
  813. $active_group[] = $form->createElement('checkbox','keyword_inactive','',get_lang('Inactive'),array('style'=>'margin-left:17px'));
  814. $form->addGroup($active_group,'',get_lang('ActiveAccount'),'<br/>',false);
  815. $form->addElement('html', '</td><td>');
  816. /*
  817. * @todo fix this code
  818. $extra_data = UserManager::get_extra_fields( 0,10,5, 'ASC', true, 1);
  819. var_dump($extra_data);
  820. $extra_options = array();
  821. if (!empty($extra_data)) {
  822. $extra_options[0] = get_lang('All');
  823. // get information about extra data for adding to input select
  824. foreach ($extra_data as $field_variable => $field_value) {
  825. $extra = UserManager::get_extra_field_information_by_name($field_variable);
  826. $extra_options[$field_variable] = $extra['field_display_text'];
  827. }
  828. $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\';}'));
  829. $form->addElement('html', '<div id="extra_data_text" style="display:none;">');
  830. $form->add_textfield('keyword_extra_data_text', '', false, array('style'=>'margin-left:17px', 'id'=>'input_extra_text'));
  831. $form->addElement('html', '</div>');
  832. } else {
  833. $form->addElement('html', '<div id="extra_data_text" style="display:none;">');
  834. }*/
  835. $form->addElement('html', '</td></tr>');
  836. $form->addElement('html', '<tr><td>');
  837. $form->addElement('style_submit_button', 'submit',get_lang('SearchUsers'),'class="search"');
  838. $form->addElement('html', '</td></tr>');
  839. $form->addElement('html', '</table>');
  840. $defaults['keyword_active'] = 1;
  841. $defaults['keyword_inactive'] = 1;
  842. $form->setDefaults($defaults);
  843. $form->addElement('html','</div>');
  844. $form->display();
  845. $table = new SortableTable('users', 'get_number_of_users', 'get_user_data', (api_is_western_name_order() xor api_sort_by_first_name()) ? 3 : 2);
  846. $table->set_additional_parameters($parameters);
  847. $table->set_header(0, '', false, 'width="18px"');
  848. $table->set_header(1, get_lang('Photo'), false);
  849. $table->set_header(2, get_lang('OfficialCode'));
  850. if (api_is_western_name_order()) {
  851. $table->set_header(3, get_lang('FirstName'));
  852. $table->set_header(4, get_lang('LastName'));
  853. } else {
  854. $table->set_header(3, get_lang('LastName'));
  855. $table->set_header(4, get_lang('FirstName'));
  856. }
  857. $table->set_header(5, get_lang('LoginName'));
  858. $table->set_header(6, get_lang('Email'));
  859. $table->set_header(7, get_lang('Profile'));
  860. $table->set_header(8, get_lang('Active'),true, 'width="15px"');
  861. $table->set_header(9, get_lang('Action'), false,'width="220px"');
  862. $table->set_column_filter(3, 'user_filter');
  863. $table->set_column_filter(4, 'user_filter');
  864. $table->set_column_filter(6, 'email_filter');
  865. $table->set_column_filter(7, 'status_filter');
  866. $table->set_column_filter(8, 'active_filter');
  867. $table->set_column_filter(9, 'modify_filter');
  868. if (api_is_platform_admin())
  869. $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
  870. $table->display();
  871. Display :: display_footer();