group_list.php 17 KB

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