group.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  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. // Create default category if it doesn't exist when group categories aren't allowed
  36. if (api_get_setting('allow_group_categories') == 'false') {
  37. $cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY);
  38. $sql = "SELECT * FROM $cat_table WHERE c_id = $course_id AND id = '".GroupManager::DEFAULT_GROUP_CATEGORY."'";
  39. $res = Database::query($sql);
  40. $num = Database::num_rows($res);
  41. if ($num == 0) {
  42. $sql = "INSERT INTO $cat_table (c_id, id , title , description , forum_state, wiki_state, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)
  43. VALUES ($course_id, '2', '".Database::escape_string(get_lang('DefaultGroupCategory'))."', '', '1', '1', '8', '0', '0', '0', '0');";
  44. Database::query($sql);
  45. }
  46. }
  47. /* Header */
  48. Display::display_header(get_lang('Groups'));
  49. // Tool introduction
  50. Display::display_introduction_section(TOOL_GROUP);
  51. /*
  52. * Self-registration and un-registration
  53. */
  54. $my_group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
  55. $my_msg = isset($_GET['msg']) ? Security::remove_XSS($_GET['msg']) : null;
  56. $my_group = isset($_REQUEST['group']) ? Security::remove_XSS($_REQUEST['group']) : null;
  57. $my_get_id1 = isset($_GET['id1']) ? Security::remove_XSS($_GET['id1']) : null;
  58. $my_get_id2 = isset($_GET['id2']) ? Security::remove_XSS($_GET['id2']) : null;
  59. $my_get_id = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
  60. if (isset($_GET['action']) && $is_allowed_in_course) {
  61. switch ($_GET['action']) {
  62. case 'set_visible':
  63. if (api_is_allowed_to_edit()) {
  64. GroupManager::setVisible($my_get_id);
  65. Display:: display_confirmation_message(get_lang('ItemUpdated'));
  66. }
  67. break;
  68. case 'set_invisible':
  69. if (api_is_allowed_to_edit()) {
  70. GroupManager::setInvisible($my_get_id);
  71. Display:: display_confirmation_message(get_lang('ItemUpdated'));
  72. }
  73. break;
  74. case 'self_reg':
  75. if (GroupManager::is_self_registration_allowed($userId, $my_group_id)) {
  76. GroupManager::subscribe_users($userId, $my_group_id);
  77. Display :: display_confirmation_message(get_lang('GroupNowMember'));
  78. }
  79. break;
  80. case 'self_unreg':
  81. if (GroupManager::is_self_unregistration_allowed($userId, $my_group_id)) {
  82. GroupManager::unsubscribe_users($userId, $my_group_id);
  83. Display :: display_confirmation_message(get_lang('StudentDeletesHimself'));
  84. }
  85. break;
  86. case 'show_msg':
  87. Display::display_confirmation_message($my_msg);
  88. break;
  89. case 'warning_message':
  90. Display::display_warning_message($my_msg);
  91. break;
  92. case 'success_message':
  93. Display::display_confirmation_message($my_msg);
  94. break;
  95. }
  96. }
  97. /*
  98. * Group-admin functions
  99. */
  100. if (api_is_allowed_to_edit(false, true)) {
  101. // Post-actions
  102. if (isset($_POST['action'])) {
  103. switch ($_POST['action']) {
  104. case 'delete_selected':
  105. if (is_array($_POST['group'])) {
  106. GroupManager::delete_groups($my_group);
  107. Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted'));
  108. }
  109. break;
  110. case 'empty_selected':
  111. if (is_array($_POST['group'])) {
  112. GroupManager :: unsubscribe_all_users($my_group);
  113. Display :: display_confirmation_message(get_lang('SelectedGroupsEmptied'));
  114. }
  115. break;
  116. case 'fill_selected':
  117. if (is_array($_POST['group'])) {
  118. GroupManager :: fill_groups($my_group);
  119. Display :: display_confirmation_message(get_lang('SelectedGroupsFilled'));
  120. }
  121. break;
  122. }
  123. }
  124. // Get-actions
  125. if (isset($_GET['action'])) {
  126. switch ($_GET['action']) {
  127. case 'swap_cat_order':
  128. GroupManager :: swap_category_order($my_get_id1, $my_get_id2);
  129. Display :: display_confirmation_message(get_lang('CategoryOrderChanged'));
  130. break;
  131. case 'delete_one':
  132. GroupManager :: delete_groups($my_get_id);
  133. Display :: display_confirmation_message(get_lang('GroupDel'));
  134. break;
  135. case 'fill_one':
  136. GroupManager :: fill_groups($my_get_id);
  137. Display :: display_confirmation_message(get_lang('GroupFilledGroups'));
  138. break;
  139. case 'delete_category':
  140. GroupManager :: delete_category($my_get_id);
  141. Display :: display_confirmation_message(get_lang('CategoryDeleted'));
  142. break;
  143. }
  144. }
  145. }
  146. echo '<div class="actions">';
  147. if (api_is_allowed_to_edit(false, true)) {
  148. echo '<a href="group_creation.php?'.api_get_cidreq().'">'.
  149. Display::return_icon('new_group.png', get_lang('NewGroupCreate'), '', ICON_SIZE_MEDIUM).'</a>';
  150. if (api_get_setting('allow_group_categories') == 'true') {
  151. echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.
  152. Display::return_icon('new_folder.png', get_lang('AddCategory'), '', ICON_SIZE_MEDIUM).'</a>';
  153. } else {
  154. echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.
  155. Display::return_icon('settings.png', get_lang('PropModify'), '', ICON_SIZE_MEDIUM).'</a>';
  156. }
  157. echo '<a href="import.php?'.api_get_cidreq().'&action=import">'.
  158. Display::return_icon('import_csv.png', get_lang('Import'), '', ICON_SIZE_MEDIUM).'</a>';
  159. echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=csv">'.
  160. Display::return_icon('export_csv.png', get_lang('ExportAsCSV'), '', ICON_SIZE_MEDIUM).'</a>';
  161. echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_all&type=xls">'.
  162. Display::return_icon('export_excel.png', get_lang('ExportAsXLS'), '', ICON_SIZE_MEDIUM).'</a>';
  163. echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export_pdf">'.
  164. Display::return_icon('pdf.png', get_lang('ExportToPDF'), '', ICON_SIZE_MEDIUM).'</a>';
  165. echo '<a href="group_overview.php?'.api_get_cidreq().'">'.
  166. Display::return_icon('group_summary.png', get_lang('GroupOverview'), '', ICON_SIZE_MEDIUM).'</a>';
  167. echo '<a href="../user/user.php?'.api_get_cidreq().'">'.
  168. Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'), '', ICON_SIZE_MEDIUM).'</a>';
  169. echo GroupManager::getSearchForm();
  170. }
  171. $group_cats = GroupManager::get_categories(api_get_course_id());
  172. echo '</div>';
  173. /* List all categories */
  174. if (api_get_setting('allow_group_categories') == 'true') {
  175. foreach ($group_cats as $index => $category) {
  176. $group_list = GroupManager::get_group_list($category['id']);
  177. $label = Display::label(count($group_list).' '.get_lang('ExistingGroups'), 'info');
  178. $actions = null;
  179. if (api_is_allowed_to_edit(false, true)) {
  180. $actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'" title="'.get_lang('Edit').'">'.
  181. Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
  182. $actions .=
  183. Display::url(
  184. Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL),
  185. 'group.php?'.api_get_cidreq().'&action=delete_category&id='.$category['id'],
  186. array(
  187. 'onclick' => 'javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;'
  188. )
  189. );
  190. if ($index != 0) {
  191. $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$category['id'].'&id2='.$group_cats[$index -1]['id'].'">'.
  192. Display::return_icon('up.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
  193. }
  194. if ($index != count($group_cats) - 1) {
  195. $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&id1='.$category['id'].'&id2='.$group_cats[$index +1]['id'].'">'.
  196. Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
  197. }
  198. }
  199. echo Display::page_header(
  200. Security::remove_XSS($category['title'].' '. $label.' ').$actions,
  201. null,
  202. 'h2',
  203. false
  204. );
  205. echo $category['description'];
  206. GroupManager::process_groups($group_list, $category['id']);
  207. }
  208. } else {
  209. $group_list = GroupManager::get_group_list();
  210. GroupManager::process_groups($group_list);
  211. }
  212. if (!isset($_GET['origin']) || $_GET['origin'] != 'learnpath') {
  213. Display::display_footer();
  214. }
  215. $_SESSION['_gid'] = 0;