group.php 10 KB

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