group.php 11 KB

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