group.php 12 KB

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