group.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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 '../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_msg = isset($_GET['msg']) ? Security::remove_XSS($_GET['msg']) : 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. 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, $my_group_id)) {
  66. GroupManager::subscribe_users($userId, $my_group_id);
  67. Display::addFlash(Display::return_message(get_lang('GroupNowMember')));
  68. header("Location: $currentUrl");
  69. exit;
  70. }
  71. break;
  72. case 'self_unreg':
  73. if (GroupManager::is_self_unregistration_allowed($userId, $my_group_id)) {
  74. GroupManager::unsubscribe_users($userId, $my_group_id);
  75. Display::addFlash(Display::return_message(get_lang('StudentDeletesHimself')));
  76. header("Location: $currentUrl");
  77. exit;
  78. }
  79. break;
  80. }
  81. }
  82. /*
  83. * Group-admin functions
  84. */
  85. if (api_is_allowed_to_edit(false, true)) {
  86. // Post-actions
  87. if (isset($_POST['action'])) {
  88. switch ($_POST['action']) {
  89. case 'delete_selected':
  90. if (is_array($_POST['group'])) {
  91. GroupManager::delete_groups($my_group);
  92. Display::addFlash(Display::return_message(get_lang('SelectedGroupsDeleted')));
  93. header("Location: $currentUrl");
  94. exit;
  95. }
  96. break;
  97. case 'empty_selected':
  98. if (is_array($_POST['group'])) {
  99. GroupManager :: unsubscribe_all_users($my_group);
  100. Display::addFlash(Display::return_message(get_lang('SelectedGroupsEmptied')));
  101. header("Location: $currentUrl");
  102. exit;
  103. }
  104. break;
  105. case 'fill_selected':
  106. if (is_array($_POST['group'])) {
  107. GroupManager :: fill_groups($my_group);
  108. Display::addFlash(Display::return_message(get_lang('SelectedGroupsFilled')));
  109. header("Location: $currentUrl");
  110. exit;
  111. }
  112. break;
  113. }
  114. }
  115. // Get-actions
  116. if (isset($_GET['action'])) {
  117. switch ($_GET['action']) {
  118. case 'swap_cat_order':
  119. GroupManager :: swap_category_order($my_get_id1, $my_get_id2);
  120. Display::addFlash(Display::return_message(get_lang('CategoryOrderChanged')));
  121. header("Location: $currentUrl");
  122. exit;
  123. break;
  124. case 'delete_one':
  125. GroupManager :: delete_groups($my_get_id);
  126. Display::addFlash(Display::return_message(get_lang('GroupDel')));
  127. header("Location: $currentUrl");
  128. exit;
  129. break;
  130. case 'fill_one':
  131. GroupManager :: fill_groups($my_get_id);
  132. Display::addFlash(Display::return_message(get_lang('GroupFilledGroups')));
  133. header("Location: $currentUrl");
  134. exit;
  135. break;
  136. case 'delete_category':
  137. GroupManager :: delete_category($my_get_id);
  138. Display::addFlash(Display::return_message(get_lang('CategoryDeleted')));
  139. header("Location: $currentUrl");
  140. exit;
  141. break;
  142. }
  143. }
  144. }
  145. /* Header */
  146. Display::display_header(get_lang('Groups'));
  147. // Tool introduction
  148. Display::display_introduction_section(TOOL_GROUP);
  149. $actionsLeft = '';
  150. if (api_is_allowed_to_edit(false, true)) {
  151. $actionsLeft .= '<a href="group_creation.php?'.api_get_cidreq().'">'.
  152. Display::return_icon('add-groups.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
  153. if (api_get_setting('allow_group_categories') == 'true') {
  154. $actionsLeft .= '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.
  155. Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>';
  156. } else {
  157. $actionsLeft .= '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
  158. Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
  159. }
  160. $actionsLeft .= '<a href="import.php?'.api_get_cidreq().'&action=import">'.
  161. Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
  162. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
  163. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
  164. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=xls">'.
  165. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
  166. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
  167. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  168. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'">'.
  169. Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  170. }
  171. $actionsRight = GroupManager::getSearchForm();
  172. $toolbar = Display::toolbarAction('toolbar-groups', $content = array( 0 => $actionsLeft, 1 => $actionsRight ));
  173. $group_cats = GroupManager::get_categories(api_get_course_id());
  174. echo $toolbar;
  175. echo UserManager::getUserSubscriptionTab(3);
  176. /* List all categories */
  177. if (api_get_setting('allow_group_categories') == 'true') {
  178. $defaultCategory = [
  179. 'id' => 0,
  180. 'iid' => 0,
  181. 'description' => '',
  182. 'title' => get_lang('DefaultGroupCategory')
  183. ];
  184. $group_cats = array_merge([$defaultCategory], $group_cats);
  185. foreach ($group_cats as $index => $category) {
  186. $categoryId = $category['id'];
  187. $group_list = GroupManager::get_group_list($categoryId);
  188. $groupToShow = GroupManager::process_groups($group_list, $categoryId);
  189. if (empty($groupToShow)) {
  190. continue;
  191. }
  192. $label = Display::label(count($group_list).' '.get_lang('ExistingGroups'), 'info');
  193. $actions = null;
  194. if (api_is_allowed_to_edit(false, true) && !empty($categoryId)) {
  195. $actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$categoryId.'" title="'.get_lang('Edit').'">'.
  196. Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
  197. $actions .=
  198. Display::url(
  199. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL),
  200. 'group.php?'.api_get_cidreq().'&action=delete_category&id='.$categoryId,
  201. array(
  202. 'onclick' => 'javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;'
  203. )
  204. );
  205. if ($index != 0) {
  206. $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$categoryId.'&id2='.$group_cats[$index -1]['id'].'">'.
  207. Display::return_icon('up.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
  208. }
  209. if ($index != count($group_cats) - 1) {
  210. $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$categoryId.'&id2='.$group_cats[$index +1]['id'].'">'.
  211. Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
  212. }
  213. }
  214. echo Display::page_header(
  215. Security::remove_XSS($category['title'].' '. $label.' ').$actions,
  216. null,
  217. 'h4',
  218. false
  219. );
  220. echo $category['description'];
  221. echo $groupToShow;
  222. }
  223. } else {
  224. $group_list = GroupManager::get_group_list();
  225. echo GroupManager::process_groups($group_list);
  226. }
  227. if (!isset($_GET['origin']) || $_GET['origin'] != 'learnpath') {
  228. Display::display_footer();
  229. }
  230. Session::write('_gid', 0);