group_list.php 17 KB

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