group.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Main page for the group module.
  5. * This script displays the general group settings,
  6. * and a list of groups with buttons to view, edit...
  7. *
  8. * @author Thomas Depraetere, Hugues Peeters, Christophe Gesche: initial versions
  9. * @author Bert Vanderkimpen, improved self-unsubscribe for cvs
  10. * @author Patrick Cool, show group comment under the group name
  11. * @author Roan Embrechts, initial self-unsubscribe code, code cleaning, virtual course support
  12. * @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
  13. * @author Isaac Flores, code cleaning and improvements
  14. * @package chamilo.group
  15. */
  16. require_once '../inc/global.inc.php';
  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_msg = isset($_GET['msg']) ? Security::remove_XSS($_GET['msg']) : 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. 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, $my_group_id)) {
  65. GroupManager::subscribe_users($userId, $my_group_id);
  66. Display::addFlash(Display::return_message(get_lang('GroupNowMember')));
  67. header("Location: $currentUrl");
  68. exit;
  69. }
  70. break;
  71. case 'self_unreg':
  72. if (GroupManager::is_self_unregistration_allowed($userId, $my_group_id)) {
  73. GroupManager::unsubscribe_users($userId, $my_group_id);
  74. Display::addFlash(Display::return_message(get_lang('StudentDeletesHimself')));
  75. header("Location: $currentUrl");
  76. exit;
  77. }
  78. break;
  79. }
  80. }
  81. /*
  82. * Group-admin functions
  83. */
  84. if (api_is_allowed_to_edit(false, true)) {
  85. // Post-actions
  86. if (isset($_POST['action'])) {
  87. switch ($_POST['action']) {
  88. case 'delete_selected':
  89. if (is_array($_POST['group'])) {
  90. GroupManager::delete_groups($my_group);
  91. Display::addFlash(Display::return_message(get_lang('SelectedGroupsDeleted')));
  92. header("Location: $currentUrl");
  93. exit;
  94. }
  95. break;
  96. case 'empty_selected':
  97. if (is_array($_POST['group'])) {
  98. GroupManager :: unsubscribe_all_users($my_group);
  99. Display::addFlash(Display::return_message(get_lang('SelectedGroupsEmptied')));
  100. header("Location: $currentUrl");
  101. exit;
  102. }
  103. break;
  104. case 'fill_selected':
  105. if (is_array($_POST['group'])) {
  106. GroupManager :: fill_groups($my_group);
  107. Display::addFlash(Display::return_message(get_lang('SelectedGroupsFilled')));
  108. header("Location: $currentUrl");
  109. exit;
  110. }
  111. break;
  112. }
  113. }
  114. // Get-actions
  115. if (isset($_GET['action'])) {
  116. switch ($_GET['action']) {
  117. case 'swap_cat_order':
  118. GroupManager :: swap_category_order($my_get_id1, $my_get_id2);
  119. Display::addFlash(Display::return_message(get_lang('CategoryOrderChanged')));
  120. header("Location: $currentUrl");
  121. exit;
  122. break;
  123. case 'delete_one':
  124. GroupManager :: delete_groups($my_get_id);
  125. Display::addFlash(Display::return_message(get_lang('GroupDel')));
  126. header("Location: $currentUrl");
  127. exit;
  128. break;
  129. case 'fill_one':
  130. GroupManager :: fill_groups($my_get_id);
  131. Display::addFlash(Display::return_message(get_lang('GroupFilledGroups')));
  132. header("Location: $currentUrl");
  133. exit;
  134. break;
  135. case 'delete_category':
  136. GroupManager :: delete_category($my_get_id);
  137. Display::addFlash(Display::return_message(get_lang('CategoryDeleted')));
  138. header("Location: $currentUrl");
  139. exit;
  140. break;
  141. }
  142. }
  143. }
  144. /* Header */
  145. Display::display_header(get_lang('Groups'));
  146. // Tool introduction
  147. Display::display_introduction_section(TOOL_GROUP);
  148. $actionsLeft = '';
  149. if (api_is_allowed_to_edit(false, true)) {
  150. $actionsLeft .= '<a href="group_creation.php?'.api_get_cidreq().'">'.
  151. Display::return_icon('add.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
  152. if (api_get_setting('allow_group_categories') == 'true') {
  153. $actionsLeft .= '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.
  154. Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>';
  155. } else {
  156. $actionsLeft .= '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
  157. Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
  158. }
  159. $actionsLeft .= '<a href="import.php?'.api_get_cidreq().'&action=import">'.
  160. Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
  161. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
  162. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
  163. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=xls">'.
  164. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
  165. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
  166. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  167. $actionsLeft .= '<a href="group_overview.php?'.api_get_cidreq().'">'.
  168. Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  169. }
  170. $actionsRight = GroupManager::getSearchForm();
  171. $toolbar = Display::toolbarAction('toolbar-groups', $content = array( 0 => $actionsLeft, 1 => $actionsRight ));
  172. $group_cats = GroupManager::get_categories(api_get_course_id());
  173. echo '</div>';
  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['_gid'] = 0;