group.php 9.8 KB

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