group_list.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. require_once api_get_path(LIBRARY_PATH).'group_portal_manager.lib.php';
  19. $this_section = SECTION_PLATFORM_ADMIN;
  20. api_protect_admin_script(true);
  21. /**
  22. * Get the total number of users on the platform
  23. * @see SortableTable#get_total_number_of_items()
  24. */
  25. function get_number_of_groups()
  26. {
  27. $group_table = Database :: get_main_table(TABLE_MAIN_GROUP);
  28. $sql = "SELECT COUNT(g.id) AS total_number_of_items FROM $group_table g";
  29. // adding the filter to see the user's only of the current access_url
  30. /*
  31. global $_configuration;
  32. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  33. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  34. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  35. }
  36. */
  37. if ( isset ($_GET['keyword'])) {
  38. $keyword = Database::escape_string(trim($_GET['keyword']));
  39. $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )";
  40. }
  41. // adding the filter to see the user's only of the current access_url
  42. /*
  43. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  44. $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  45. }*/
  46. $res = Database::query($sql, __FILE__, __LINE__);
  47. $obj = Database::fetch_object($res);
  48. return $obj->total_number_of_items;
  49. }
  50. /**
  51. * Get the users to display on the current page (fill the sortable-table)
  52. * @param int offset of first user to recover
  53. * @param int Number of users to get
  54. * @param int Column to sort on
  55. * @param string Order (ASC,DESC)
  56. * @see SortableTable#get_table_data($from)
  57. */
  58. function get_group_data($from, $number_of_items, $column, $direction)
  59. {
  60. $group_table = Database :: get_main_table(TABLE_MAIN_GROUP);
  61. $sql = "SELECT
  62. g.id AS col0,
  63. g.name AS col1,
  64. g.description AS col2,
  65. g.visibility AS col3,
  66. g.id AS col4
  67. FROM $group_table g ";
  68. // adding the filter to see the user's only of the current access_url
  69. /*global $_configuration;
  70. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  71. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  72. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  73. }*/
  74. if (isset ($_GET['keyword'])) {
  75. $keyword = Database::escape_string(trim($_GET['keyword']));
  76. $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )";
  77. }
  78. /*
  79. // adding the filter to see the user's only of the current access_url
  80. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  81. $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  82. }*/
  83. if (!in_array($direction, array('ASC','DESC'))) {
  84. $direction = 'ASC';
  85. }
  86. $column = intval($column);
  87. $from = intval($from);
  88. $number_of_items = intval($number_of_items);
  89. $sql .= " ORDER BY col$column $direction ";
  90. $sql .= " LIMIT $from,$number_of_items";
  91. $res = Database::query($sql, __FILE__, __LINE__);
  92. $users = array ();
  93. $t = time();
  94. // Status
  95. $status = array();
  96. $status[GROUP_PERMISSION_OPEN] = get_lang('Open');
  97. $status[GROUP_PERMISSION_CLOSED] = get_lang('Closed');
  98. while ($group = Database::fetch_row($res)) {
  99. $group[3] = $status[$group[3]];
  100. $group['1'] = '<a href="'.api_get_path(WEB_CODE_PATH).'social/groups.php?id='.$group['0'].'">'.$group['1'].'</a>';
  101. $groups[] = $group;
  102. }
  103. return $groups;
  104. }
  105. function get_recent_group_data($from =0 , $number_of_items = 5, $column, $direction)
  106. {
  107. $group_table = Database :: get_main_table(TABLE_MAIN_GROUP);
  108. $sql = "SELECT
  109. g.id AS col0,
  110. g.name AS col1,
  111. g.description AS col2,
  112. g.visibility AS col3,
  113. g.id AS col4
  114. FROM $group_table g ";
  115. // adding the filter to see the user's only of the current access_url
  116. /*global $_configuration;
  117. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  118. $access_url_rel_user_table= Database :: get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  119. $sql.= " INNER JOIN $access_url_rel_user_table url_rel_user ON (u.user_id=url_rel_user.user_id)";
  120. }*/
  121. if (isset ($_GET['keyword'])) {
  122. $keyword = Database::escape_string(trim($_GET['keyword']));
  123. $sql .= " WHERE (g.name LIKE '%".$keyword."%' OR g.description LIKE '%".$keyword."%' OR g.url LIKE '%".$keyword."%' )";
  124. }
  125. /*
  126. // adding the filter to see the user's only of the current access_url
  127. if ((api_is_platform_admin() || api_is_session_admin()) && $_configuration['multiple_access_urls']==true && api_get_current_access_url_id()!=-1) {
  128. $sql.= " AND url_rel_user.access_url_id=".api_get_current_access_url_id();
  129. }*/
  130. if (!in_array($direction, array('ASC','DESC'))) {
  131. $direction = 'ASC';
  132. }
  133. $column = intval($column);
  134. $from = intval($from);
  135. $number_of_items = intval($number_of_items);
  136. $sql .= " ORDER BY col$column $direction ";
  137. $sql .= " LIMIT $from,$number_of_items";
  138. $res = Database::query($sql, __FILE__, __LINE__);
  139. $users = array ();
  140. $t = time();
  141. while ($group = Database::fetch_row($res)) {
  142. // forget about the expiration date field
  143. $groups[] = $group;
  144. }
  145. return $groups;
  146. }
  147. /**
  148. * Build the modify-column of the table
  149. * @param int The user id
  150. * @param string URL params to add to table links
  151. * @param array Row of elements to alter
  152. * @return string Some HTML-code with modify-buttons
  153. */
  154. function modify_filter($group_id,$url_params,$row)
  155. {
  156. global $charset;
  157. global $_user;
  158. global $_admins_list;
  159. if (api_is_platform_admin()) {
  160. $result .= '<a href="'.api_get_path(WEB_CODE_PATH).'admin/add_users_to_group.php?id='.$group_id.'">'.Display::return_icon('add_user_big.gif',get_lang('AddUsersToGroup')).'</a>';
  161. $result .= '<a href="group_edit.php?id='.$group_id.'">'.Display::return_icon('edit.gif', get_lang('Edit')).'</a>&nbsp;&nbsp;';
  162. $result .= '<a href="group_list.php?action=delete_group&amp;group_id='.$group_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>';
  163. }
  164. return $result;
  165. }
  166. /**
  167. * Build the active-column of the table to lock or unlock a certain user
  168. * lock = the user can no longer use this account
  169. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  170. * @param int $active the current state of the account
  171. * @param int $user_id The user id
  172. * @param string $url_params
  173. * @return string Some HTML-code with the lock/unlock button
  174. */
  175. function active_filter($active, $url_params, $row) {
  176. global $_user;
  177. if ($active=='1') {
  178. $action='lock';
  179. $image='right';
  180. } elseif ($active=='-1') {
  181. $action='edit';
  182. $image='expired';
  183. } elseif ($active=='0') {
  184. $action='unlock';
  185. $image='wrong';
  186. }
  187. if ($action=='edit') {
  188. $result = Display::return_icon($image.'.gif', get_lang('AccountExpired'));
  189. }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.
  190. $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>';
  191. }
  192. return $result;
  193. }
  194. /**
  195. * Lock or unlock a user
  196. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University
  197. * @param int $status, do we want to lock the user ($status=lock) or unlock it ($status=unlock)
  198. * @param int $user_id The user id
  199. * @return language variable
  200. */
  201. function lock_unlock_user($status,$user_id)
  202. {
  203. $user_table = Database :: get_main_table(TABLE_MAIN_USER);
  204. if ($status=='lock')
  205. {
  206. $status_db='0';
  207. $return_message=get_lang('UserLocked');
  208. }
  209. if ($status=='unlock')
  210. {
  211. $status_db='1';
  212. $return_message=get_lang('UserUnlocked');
  213. }
  214. if(($status_db=='1' OR $status_db=='0') AND is_numeric($user_id))
  215. {
  216. $sql="UPDATE $user_table SET active='".Database::escape_string($status_db)."' WHERE user_id='".Database::escape_string($user_id)."'";
  217. $result = Database::query($sql, __FILE__, __LINE__);
  218. }
  219. if ($result)
  220. {
  221. return $return_message;
  222. }
  223. }
  224. /**
  225. * Instead of displaying the integer of the status, we give a translation for the status
  226. *
  227. * @param integer $status
  228. * @return string translation
  229. *
  230. * @version march 2008
  231. * @author Patrick Cool <patrick.cool@UGent.be>, Ghent University, Belgium
  232. */
  233. function status_filter($status)
  234. {
  235. $statusname = api_get_status_langvars();
  236. return $statusname[$status];
  237. }
  238. /**
  239. ==============================================================================
  240. INIT SECTION
  241. ==============================================================================
  242. */
  243. $action = $_GET["action"];
  244. if (isset ($_GET['search']) && $_GET['search'] == 'advanced') {
  245. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  246. $interbreadcrumb[] = array ("url" => 'group_list.php', "name" => get_lang('GroupList'));
  247. $tool_name = get_lang('SearchAUser');
  248. Display :: display_header($tool_name);
  249. //api_display_tool_title($tool_name);
  250. $form = new FormValidator('advanced_search','get');
  251. $form->addElement('header', '', $tool_name);
  252. $form->add_textfield('keyword_firstname',get_lang('FirstName'),false);
  253. $form->add_textfield('keyword_lastname',get_lang('LastName'),false);
  254. $form->add_textfield('keyword_username',get_lang('LoginName'),false);
  255. $form->add_textfield('keyword_email',get_lang('Email'),false);
  256. $form->add_textfield('keyword_officialcode',get_lang('OfficialCode'),false);
  257. $status_options = array();
  258. $status_options['%'] = get_lang('All');
  259. $status_options[STUDENT] = get_lang('Student');
  260. $status_options[COURSEMANAGER] = get_lang('Teacher');
  261. $status_options[SESSIONADMIN] = get_lang('Administrator');//
  262. $form->addElement('select','keyword_status',get_lang('Status'),$status_options);
  263. $active_group = array();
  264. $active_group[] = $form->createElement('checkbox','keyword_active','',get_lang('Active'));
  265. $active_group[] = $form->createElement('checkbox','keyword_inactive','',get_lang('Inactive'));
  266. $form->addGroup($active_group,'',get_lang('ActiveAccount'),'<br/>',false);
  267. $form->addElement('style_submit_button', 'submit',get_lang('SearchUsers'),'class="search"');
  268. $defaults['keyword_active'] = 1;
  269. $defaults['keyword_inactive'] = 1;
  270. $form->setDefaults($defaults);
  271. $form->display();
  272. }
  273. else
  274. {
  275. $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
  276. $tool_name = get_lang('GroupList');
  277. Display :: display_header($tool_name, "");
  278. //api_display_tool_title($tool_name);
  279. if (isset ($_GET['action'])) {
  280. $check = Security::check_token('get');
  281. if($check) {
  282. switch ($_GET['action']) {
  283. case 'show_message' :
  284. if (!empty($_GET['warn'])) {
  285. // to prevent too long messages
  286. if ($_GET['warn'] == 'session_message'){
  287. $_GET['warn'] = $_SESSION['session_message_import_users'];
  288. }
  289. Display::display_warning_message(urldecode($_GET['warn']),false);
  290. }
  291. if (!empty($_GET['message'])) {
  292. Display :: display_confirmation_message(stripslashes($_GET['message']));
  293. }
  294. break;
  295. case 'delete_group' :
  296. if (api_is_platform_admin()) {
  297. if (GroupPortalManager :: delete($_GET['group_id'])) {
  298. Display :: display_confirmation_message(get_lang('GroupDeleted'));
  299. } else {
  300. Display :: display_error_message(get_lang('CannotDeleteGroup'));
  301. }
  302. }
  303. break;
  304. case 'lock' :
  305. $message=lock_unlock_user('lock',$_GET['user_id']);
  306. Display :: display_normal_message($message);
  307. break;
  308. case 'unlock';
  309. $message=lock_unlock_user('unlock',$_GET['user_id']);
  310. Display :: display_normal_message($message);
  311. break;
  312. }
  313. Security::clear_token();
  314. }
  315. }
  316. if (isset ($_POST['action'])) {
  317. $check = Security::check_token('get');
  318. if ($check) {
  319. switch ($_POST['action']) {
  320. case 'delete' :
  321. if (api_is_platform_admin()) {
  322. $number_of_selected_groups = count($_POST['id']);
  323. $number_of_deleted_groups = 0;
  324. foreach ($_POST['id'] as $index => $group_id) {
  325. if (GroupPortalManager :: delete($group_id)) {
  326. $number_of_deleted_groups++;
  327. }
  328. }
  329. }
  330. if ($number_of_selected_groups == $number_of_deleted_groups) {
  331. Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted'));
  332. } else {
  333. Display :: display_error_message(get_lang('SomeGroupsNotDeleted'));
  334. }
  335. break;
  336. }
  337. Security::clear_token();
  338. }
  339. }
  340. // Create a search-box
  341. $form = new FormValidator('search_simple','get','','',null,false);
  342. $renderer =& $form->defaultRenderer();
  343. $renderer->setElementTemplate('<span>{element}</span> ');
  344. $form->addElement('text','keyword',get_lang('keyword'));
  345. $form->addElement('style_submit_button', 'submit',get_lang('Search'),'class="search"');
  346. //$form->addElement('static','search_advanced_link',null,'<a href="user_list.php?search=advanced">'.get_lang('AdvancedSearch').'</a>');
  347. echo '<div class="actions" style="width:100%;">';
  348. if (api_is_platform_admin()) {
  349. echo '<span style="float:right; padding-top:7px;">'.
  350. '<a href="'.api_get_path(WEB_CODE_PATH).'admin/group_add.php">'.Display::return_icon('groupadd.gif',get_lang('AddGroups')).get_lang('AddGroups').'</a>'.
  351. '</span>';
  352. }
  353. $form->display();
  354. echo '</div>';
  355. if (isset ($_GET['keyword'])) {
  356. $parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
  357. }
  358. // Create a sortable table with user-data
  359. $parameters['sec_token'] = Security::get_token();
  360. // get the list of all admins to mark them in the users list
  361. $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  362. $sql_admin = "SELECT user_id FROM $admin_table";
  363. $res_admin = Database::query($sql_admin);
  364. $_admins_list = array();
  365. while ($row_admin = Database::fetch_row($res_admin)) {
  366. $_admins_list[] = $row_admin[0];
  367. }
  368. $table = new SortableTable('group_list', 'get_number_of_groups', 'get_group_data', 2);
  369. $table->set_additional_parameters($parameters);
  370. $table->set_header(0, '', false);
  371. $table->set_header(1, get_lang('Name'));
  372. $table->set_header(2, get_lang('Description'));
  373. $table->set_header(3, get_lang('Visibility'));
  374. $table->set_header(4, '', false);
  375. $table->set_column_filter(4, 'modify_filter');
  376. //$table->set_column_filter(6, 'status_filter');
  377. //$table->set_column_filter(7, 'active_filter');
  378. //$table->set_column_filter(8, 'modify_filter');
  379. if (api_is_platform_admin())
  380. $table->set_form_actions(array ('delete' => get_lang('DeleteFromPlatform')));
  381. $table->display();
  382. }
  383. /*
  384. ==============================================================================
  385. FOOTER
  386. ==============================================================================
  387. */
  388. Display :: display_footer();
  389. ?>