user_list.php 39 KB

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