group.php 11 KB

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