group.php 9.6 KB

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