group.php 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. $this_section = SECTION_COURSES;
  21. $current_course_tool = TOOL_GROUP;
  22. // Notice for unauthorized people.
  23. api_protect_course_script(true);
  24. $htmlHeadXtra[] = '<script>
  25. $(document).ready( function() {
  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. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
  49. // So we are not in learnpath tool
  50. event_access_tool(TOOL_GROUP);
  51. if (!$is_allowed_in_course) {
  52. api_not_allowed(true);
  53. }
  54. }
  55. Display::display_header(get_lang('Groups'));
  56. // Tool introduction
  57. Display::display_introduction_section(TOOL_GROUP);
  58. /*
  59. * Self-registration and unregistration
  60. */
  61. $my_group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
  62. $my_msg = isset($_GET['msg']) ? Security::remove_XSS($_GET['msg']) : null;
  63. $my_group = isset($_REQUEST['group']) ? Security::remove_XSS($_REQUEST['group']) : null;
  64. $my_get_id1 = isset($_GET['id1']) ? Security::remove_XSS($_GET['id1']) : null;
  65. $my_get_id2 = isset($_GET['id2']) ? Security::remove_XSS($_GET['id2']) : null;
  66. $my_get_id = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
  67. if (isset($_GET['action'])) {
  68. switch ($_GET['action']) {
  69. case 'self_reg' :
  70. if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $my_group_id)) {
  71. GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $my_group_id);
  72. Display :: display_confirmation_message(get_lang('GroupNowMember'));
  73. }
  74. break;
  75. case 'self_unreg' :
  76. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $my_group_id)) {
  77. GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $my_group_id);
  78. Display :: display_confirmation_message(get_lang('StudentDeletesHimself'));
  79. }
  80. break;
  81. case 'show_msg' :
  82. Display :: display_confirmation_message($my_msg);
  83. break;
  84. case 'warning_message' :
  85. Display :: display_warning_message($my_msg);
  86. break;
  87. case 'success_message' :
  88. Display :: display_confirmation_message($my_msg);
  89. break;
  90. }
  91. }
  92. /*
  93. * Group-admin functions
  94. */
  95. if (api_is_allowed_to_edit(false, true)) {
  96. // Post-actions
  97. if (isset($_POST['action'])) {
  98. switch ($_POST['action']) {
  99. case 'delete_selected' :
  100. if (is_array($_POST['group'])) {
  101. GroupManager :: delete_groups($my_group);
  102. Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted'));
  103. }
  104. break;
  105. case 'empty_selected' :
  106. if (is_array($_POST['group'])) {
  107. GroupManager :: unsubscribe_all_users($my_group);
  108. Display :: display_confirmation_message(get_lang('SelectedGroupsEmptied'));
  109. }
  110. break;
  111. case 'fill_selected' :
  112. if (is_array($_POST['group'])) {
  113. GroupManager :: fill_groups($my_group);
  114. Display :: display_confirmation_message(get_lang('SelectedGroupsFilled'));
  115. }
  116. break;
  117. }
  118. }
  119. // Get-actions
  120. if (isset($_GET['action'])) {
  121. switch ($_GET['action']) {
  122. case 'swap_cat_order':
  123. GroupManager :: swap_category_order($my_get_id1, $my_get_id2);
  124. Display :: display_confirmation_message(get_lang('CategoryOrderChanged'));
  125. break;
  126. case 'delete_one':
  127. GroupManager :: delete_groups($my_get_id);
  128. Display :: display_confirmation_message(get_lang('GroupDel'));
  129. break;
  130. case 'empty_one':
  131. GroupManager :: unsubscribe_all_users($my_get_id);
  132. Display :: display_confirmation_message(get_lang('GroupEmptied'));
  133. break;
  134. case 'fill_one':
  135. GroupManager :: fill_groups($my_get_id);
  136. Display :: display_confirmation_message(get_lang('GroupFilledGroups'));
  137. break;
  138. case 'delete_category':
  139. GroupManager :: delete_category($my_get_id);
  140. Display :: display_confirmation_message(get_lang('CategoryDeleted'));
  141. break;
  142. }
  143. }
  144. }
  145. echo '<div class="actions">';
  146. if (api_is_allowed_to_edit(false, true)) {
  147. echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('new_group.png', get_lang('NewGroupCreate'),'',ICON_SIZE_MEDIUM).'</a>';
  148. if (CourseManager::count_rows_course_table(Database::get_course_table(TABLE_GROUP),api_get_session_id(), api_get_course_int_id()) > 0) {
  149. echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group_summary.png', get_lang('GroupOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  150. }
  151. if (api_get_setting('allow_group_categories') == 'true') {
  152. echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.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">'.Display::return_icon('settings.png', get_lang('PropModify'),'',ICON_SIZE_MEDIUM).'</a>';
  155. }
  156. echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a>';
  157. echo '<a href="../user/user.php?'.api_get_cidreq().'">'.Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'),'',ICON_SIZE_MEDIUM).'</a>';
  158. }
  159. $group_cats = GroupManager :: get_categories(api_get_course_id());
  160. if (api_get_setting('allow_group_categories') == 'true' && count($group_cats) > 1) {
  161. echo ' <a href="?'.api_get_cidreq().'&show_all=1">'.Display::return_icon('group.png',get_lang('ShowAll'),'',ICON_SIZE_MEDIUM).'</a>';
  162. }
  163. echo '</div>';
  164. /*
  165. * List all categories
  166. */
  167. if (api_get_setting('allow_group_categories') == 'true') {
  168. foreach ($group_cats as $index => $category) {
  169. if (isset ($_GET['show_all']) || (isset ($_GET['category']) && $_GET['category'] == $category['id'])) {
  170. //echo '<img src="../img/folder_group_category.gif" alt=""/>';
  171. //echo '<a href="group.php?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'">'.$category['title'].'</a>';
  172. } else {
  173. //echo '<img src="../img/folder_document.gif" alt=""/>';
  174. //echo '<a href="group.php?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&amp;category='.$category['id'].'">'.$category['title'].'</a>';
  175. //echo Display::page_header($category['title']);
  176. }
  177. $group_list = GroupManager :: get_group_list($category['id']);
  178. $label = Display::label(count($group_list).' '.get_lang('ExistingGroups'), 'info');
  179. $actions = null;
  180. if (api_is_allowed_to_edit(false, true)) {
  181. $actions .= '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'" title="'.get_lang('Edit').'">'.Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
  182. $actions .= '<a href="group.php?'.api_get_cidreq().'&action=delete_category&amp;id='.$category['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES))."'".')) return false;" title="'.get_lang('Delete').'">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  183. if ($index != 0) {
  184. $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index -1]['id'].'">'.Display::return_icon('up.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
  185. }
  186. if ($index != count($group_cats) - 1) {
  187. $actions .= ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'">'.Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
  188. }
  189. }
  190. echo Display::page_header($category['title'].' '. $label.' '.$actions);
  191. echo '<p style="margin: 0px;margin-left: 50px;">'.$category['description'].'</p><p/>';
  192. GroupManager ::process_groups($group_list, $category['id']);
  193. }
  194. } else {
  195. $group_list = GroupManager :: get_group_list();
  196. GroupManager ::process_groups($group_list);
  197. }
  198. /* FOOTER */
  199. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
  200. Display::display_footer();
  201. }
  202. $_SESSION['_gid'] = 0;