group.php 9.8 KB

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