group_list.php 16 KB

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