group_list.php 15 KB

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