group.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Main page for the group module.
  6. * This script displays the general group settings,
  7. * and a list of groups with buttons to view, edit...
  8. *
  9. * @author Thomas Depraetere, Hugues Peeters, Christophe Gesche: initial versions
  10. * @author Bert Vanderkimpen, improved self-unsubscribe for cvs
  11. * @author Patrick Cool, show group comment under the group name
  12. * @author Roan Embrechts, initial self-unsubscribe code, code cleaning, virtual course support
  13. * @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
  14. * @author Isaac Flores, code cleaning and improvements
  15. * @package chamilo.group
  16. */
  17. require_once __DIR__.'/../inc/global.inc.php';
  18. $is_allowed_in_course = api_is_allowed_in_course();
  19. $userId = api_get_user_id();
  20. $this_section = SECTION_COURSES;
  21. $current_course_tool = TOOL_GROUP;
  22. $course_id = api_get_course_int_id();
  23. $sessionId = api_get_session_id();
  24. // Notice for unauthorized people.
  25. api_protect_course_script(true);
  26. $htmlHeadXtra[] = '<script>
  27. $(document).ready( function() {
  28. var i;
  29. for (i=0; i<$(".actions").length; i++) {
  30. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
  31. $(".actions:eq("+i+")").hide();
  32. }
  33. }
  34. });
  35. </script>';
  36. $nameTools = get_lang('GroupManagement');
  37. /*
  38. * Self-registration and un-registration
  39. */
  40. $my_group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
  41. $my_group = isset($_REQUEST['group']) ? Security::remove_XSS($_REQUEST['group']) : null;
  42. $my_get_id1 = isset($_GET['id1']) ? Security::remove_XSS($_GET['id1']) : null;
  43. $my_get_id2 = isset($_GET['id2']) ? Security::remove_XSS($_GET['id2']) : null;
  44. $my_get_id = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
  45. $currentUrl = api_get_path(WEB_CODE_PATH).'group/group.php?'.api_get_cidreq();
  46. $groupInfo = GroupManager::get_group_properties($my_group_id);
  47. if (isset($_GET['action']) && $is_allowed_in_course) {
  48. switch ($_GET['action']) {
  49. case 'set_visible':
  50. if (api_is_allowed_to_edit()) {
  51. GroupManager::setVisible($my_get_id);
  52. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  53. header("Location: $currentUrl");
  54. exit;
  55. }
  56. break;
  57. case 'set_invisible':
  58. if (api_is_allowed_to_edit()) {
  59. GroupManager::setInvisible($my_get_id);
  60. Display::addFlash(Display::return_message(get_lang('ItemUpdated')));
  61. header("Location: $currentUrl");
  62. exit;
  63. }
  64. break;
  65. case 'self_reg':
  66. if (GroupManager::is_self_registration_allowed($userId, $groupInfo)) {
  67. GroupManager::subscribe_users($userId, $groupInfo);
  68. Display::addFlash(Display::return_message(get_lang('GroupNowMember')));
  69. header("Location: $currentUrl");
  70. exit;
  71. } else {
  72. Display::addFlash(Display::return_message(get_lang('Error')));
  73. header("Location: $currentUrl");
  74. exit;
  75. }
  76. break;
  77. case 'self_unreg':
  78. if (GroupManager::is_self_unregistration_allowed($userId, $groupInfo)) {
  79. GroupManager::unsubscribe_users($userId, $groupInfo);
  80. Display::addFlash(Display::return_message(get_lang('StudentDeletesHimself')));
  81. header("Location: $currentUrl");
  82. exit;
  83. }
  84. break;
  85. }
  86. }
  87. /*
  88. * Group-admin functions
  89. */
  90. if (api_is_allowed_to_edit(false, true)) {
  91. // Post-actions
  92. if (isset($_POST['action'])) {
  93. switch ($_POST['action']) {
  94. case 'delete_selected':
  95. if (is_array($_POST['group'])) {
  96. foreach ($_POST['group'] as $myGroupId) {
  97. $groupInfo = GroupManager::get_group_properties($myGroupId);
  98. GroupManager::delete_groups($groupInfo);
  99. }
  100. Display::addFlash(Display::return_message(get_lang('SelectedGroupsDeleted')));
  101. header("Location: $currentUrl");
  102. exit;
  103. }
  104. break;
  105. case 'empty_selected':
  106. if (is_array($_POST['group'])) {
  107. foreach ($_POST['group'] as $myGroupId) {
  108. $groupInfo = GroupManager::get_group_properties($myGroupId);
  109. GroupManager :: unsubscribe_all_users($groupInfo);
  110. }
  111. Display::addFlash(Display::return_message(get_lang('SelectedGroupsEmptied')));
  112. header("Location: $currentUrl");
  113. exit;
  114. }
  115. break;
  116. case 'fill_selected':
  117. if (is_array($_POST['group'])) {
  118. foreach ($_POST['group'] as $myGroupId) {
  119. $groupInfo = GroupManager::get_group_properties($myGroupId);
  120. GroupManager:: fill_groups($groupInfo);
  121. }
  122. Display::addFlash(Display::return_message(get_lang('SelectedGroupsFilled')));
  123. header("Location: $currentUrl");
  124. exit;
  125. }
  126. break;
  127. }
  128. }
  129. // Get-actions
  130. if (isset($_GET['action'])) {
  131. switch ($_GET['action']) {
  132. case 'swap_cat_order':
  133. GroupManager :: swap_category_order($my_get_id1, $my_get_id2);
  134. Display::addFlash(Display::return_message(get_lang('CategoryOrderChanged')));
  135. header("Location: $currentUrl");
  136. exit;
  137. break;
  138. case 'delete_one':
  139. $groupInfo = GroupManager::get_group_properties($my_get_id);
  140. GroupManager :: delete_groups($groupInfo);
  141. Display::addFlash(Display::return_message(get_lang('GroupDel')));
  142. header("Location: $currentUrl");
  143. exit;
  144. break;
  145. case 'fill_one':
  146. $groupInfo = GroupManager::get_group_properties($my_get_id);
  147. GroupManager :: fill_groups($groupInfo);
  148. Display::addFlash(Display::return_message(get_lang('GroupFilledGroups')));
  149. header("Location: $currentUrl");
  150. exit;
  151. break;
  152. case 'delete_category':
  153. if (empty($sessionId)) {
  154. GroupManager::delete_category($my_get_id);
  155. Display::addFlash(
  156. Display::return_message(get_lang('CategoryDeleted'))
  157. );
  158. header("Location: $currentUrl");
  159. exit;
  160. }
  161. break;
  162. }
  163. }
  164. }
  165. /* Header */
  166. Display::display_header(get_lang('Groups'));
  167. // Tool introduction
  168. Display::display_introduction_section(TOOL_GROUP);
  169. $actionsLeft = '';
  170. if (api_is_allowed_to_edit(false, true)) {
  171. $actionsLeft .= '<a href="group_creation.php?'.api_get_cidreq().'">'.
  172. Display::return_icon('add-groups.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
  173. if (api_get_setting('allow_group_categories') === 'true' && empty($sessionId)) {
  174. $actionsLeft .= '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.
  175. Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>';
  176. } else {
  177. $actionsLeft .= '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
  178. Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
  179. }
  180. $actionsLeft .= '<a href="import.php?'.api_get_cidreq().'&action=import">'.
  181. Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
  182. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
  183. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
  184. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=xls">'.
  185. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
  186. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
  187. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  188. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'">'.
  189. Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  190. }
  191. $actionsRight = GroupManager::getSearchForm();
  192. $toolbar = Display::toolbarAction('toolbar-groups', array($actionsLeft, $actionsRight));
  193. $group_cats = GroupManager::get_categories(api_get_course_id());
  194. echo $toolbar;
  195. echo UserManager::getUserSubscriptionTab(3);
  196. /* List all categories */
  197. if (api_get_setting('allow_group_categories') === 'true') {
  198. $defaultCategory = [
  199. 'id' => 0,
  200. 'iid' => 0,
  201. 'description' => '',
  202. 'title' => get_lang('DefaultGroupCategory')
  203. ];
  204. $group_cats = array_merge([$defaultCategory], $group_cats);
  205. foreach ($group_cats as $index => $category) {
  206. $categoryId = $category['id'];
  207. $group_list = GroupManager::get_group_list($categoryId);
  208. $groupToShow = GroupManager::process_groups($group_list, $categoryId);
  209. if (empty($groupToShow)) {
  210. continue;
  211. }
  212. $label = Display::label(count($group_list).' '.get_lang('ExistingGroups'), 'info');
  213. $actions = null;
  214. if (api_is_allowed_to_edit(false, true) && !empty($categoryId) && empty($sessionId)) {
  215. // Edit
  216. $actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$categoryId.'" title="'.get_lang('Edit').'">'.
  217. Display::return_icon('edit.png', get_lang('EditGroup'), '', ICON_SIZE_SMALL).'</a>';
  218. // Delete
  219. $actions .= Display::url(
  220. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL),
  221. 'group.php?'.api_get_cidreq().'&action=delete_category&id='.$categoryId,
  222. array(
  223. 'onclick' => 'javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;'
  224. )
  225. );
  226. // Move
  227. if ($index != 0) {
  228. $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$categoryId.'&id2='.$group_cats[$index - 1]['id'].'">'.
  229. Display::return_icon('up.png', '&nbsp;', '', ICON_SIZE_SMALL).'</a>';
  230. }
  231. if ($index != count($group_cats) - 1) {
  232. $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$categoryId.'&id2='.$group_cats[$index + 1]['id'].'">'.
  233. Display::return_icon('down.png', '&nbsp;', '', ICON_SIZE_SMALL).'</a>';
  234. }
  235. }
  236. echo Display::page_header(
  237. Security::remove_XSS($category['title'].' '.$label.' ').$actions,
  238. null,
  239. 'h4',
  240. false
  241. );
  242. echo $category['description'];
  243. echo $groupToShow;
  244. }
  245. } else {
  246. $group_list = GroupManager::get_group_list();
  247. echo GroupManager::process_groups($group_list);
  248. }
  249. if (!isset($_GET['origin']) || $_GET['origin'] != 'learnpath') {
  250. Display::display_footer();
  251. }
  252. Session::write('_gid', 0);