user_list.php 31 KB

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