settings.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays an area where teachers can edit the group properties and member list.
  5. *
  6. * @author various contributors
  7. * @author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
  8. * @package chamilo.group
  9. * @todo course admin functionality to create groups based on who is in which course (or class).
  10. */
  11. require_once '../inc/global.inc.php';
  12. $this_section = SECTION_COURSES;
  13. $current_course_tool = TOOL_GROUP;
  14. // Notice for unauthorized people.
  15. api_protect_course_script(true);
  16. $group_id = api_get_group_id();
  17. $current_group = GroupManager::get_group_properties($group_id);
  18. $nameTools = get_lang('EditGroup');
  19. $interbreadcrumb[] = array('url' => 'group.php', 'name' => get_lang('Groups'));
  20. $interbreadcrumb[] = array('url' => 'group_space.php?'.api_get_cidReq(), 'name' => $current_group['name']);
  21. $is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $group_id);
  22. if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
  23. api_not_allowed(true);
  24. }
  25. // Build form
  26. $form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
  27. $form->addElement('hidden', 'action');
  28. $form->addElement('html', '<div class="col-md-12">');
  29. $form->addElement('header', $nameTools);
  30. $form->addElement('html', '</div>');
  31. $form->addElement('html', '<div class="col-md-6">');
  32. // Group name
  33. $form->addElement('text', 'name', get_lang('GroupName'));
  34. if (api_get_setting('allow_group_categories') == 'true') {
  35. $groupCategories = GroupManager::get_categories();
  36. $categoryList = array();
  37. //$categoryList[] = null;
  38. foreach ($groupCategories as $category) {
  39. $categoryList[$category['id']] = $category['title'];
  40. }
  41. $form->addElement('select', 'category_id', get_lang('Category'), $categoryList);
  42. }
  43. // Members per group
  44. $group = array(
  45. $form->createElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT),
  46. $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, array('id' => 'max_member_selected')),
  47. $form->createElement('text', 'max_member', null, array('class' => 'span1', 'id' => 'max_member')),
  48. $form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis'))
  49. );
  50. $form->addGroup($group, 'max_member_group', get_lang('GroupLimit'), '', false);
  51. $form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
  52. $form->addElement('html', '</div>');
  53. $form->addElement('html', '<div class="col-md-6">');
  54. // Description
  55. $form->addElement('textarea', 'description', get_lang('Description'));
  56. $form->addElement('html', '</div>');
  57. $form->addElement('html', '<div class="col-md-12">');
  58. $form->addElement('header', get_lang('DefaultSettingsForNewGroups'));
  59. $form->addElement('html', '</div>');
  60. $form->addElement('html', '<div class="col-md-6">');
  61. // Self registration
  62. $group = array(
  63. $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1),
  64. $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1)
  65. );
  66. $form->addGroup($group, '', Display::return_icon('user.png', get_lang('GroupSelfRegistration'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupSelfRegistration'), '', false);
  67. // Documents settings
  68. $group = array(
  69. $form->createElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  70. $form->createElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  71. $form->createElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  72. );
  73. $form->addGroup($group, '', Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupDocument'), '', false);
  74. // Work settings
  75. $group = array(
  76. $form->createElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  77. $form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  78. $form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  79. );
  80. $form->addGroup($group, '', Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupWork'), '', false);
  81. // Calendar settings
  82. $group = array(
  83. $form->createElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  84. $form->createElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  85. $form->createElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  86. );
  87. $form->addGroup($group, '', Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupCalendar'), '', false);
  88. $form->addElement('html', '</div>');
  89. $form->addElement('html', '<div class="col-md-6">');
  90. // Announcements settings
  91. $group = array(
  92. $form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  93. $form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  94. $form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  95. );
  96. $form->addGroup($group, '', Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupAnnouncements'), '', false);
  97. // Forum settings
  98. $group = array(
  99. $form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  100. $form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  101. $form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  102. );
  103. $form->addGroup($group, '', Display::return_icon('forum.png', get_lang('GroupForum'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupForum'), '', false);
  104. // Wiki settings
  105. $group = array(
  106. $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  107. $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  108. $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  109. );
  110. $form->addGroup($group, '', Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupWiki'), '', false);
  111. // Chat settings
  112. $group = array(
  113. $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  114. $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  115. $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  116. );
  117. $form->addGroup($group, '', Display::return_icon('chat.png', get_lang('Chat'), array(), ICON_SIZE_SMALL).' '.get_lang('Chat'), '', false);
  118. $form->addElement('html', '</div>');
  119. $form->addElement('html', '<div class="col-md-12">');
  120. // Submit button
  121. $form->addButtonSave(get_lang('SaveSettings'));
  122. $form->addElement('html', '</div>');
  123. if ($form->validate()) {
  124. $values = $form->exportValues();
  125. if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  126. $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  127. } else {
  128. $max_member = $values['max_member'];
  129. }
  130. $self_registration_allowed = isset($values['self_registration_allowed']) ? 1 : 0;
  131. $self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0;
  132. $categoryId = isset($values['category_id']) ? $values['category_id'] : null;
  133. GroupManager::set_group_properties(
  134. $current_group['id'],
  135. $values['name'],
  136. $values['description'],
  137. $max_member,
  138. $values['doc_state'],
  139. $values['work_state'],
  140. $values['calendar_state'],
  141. $values['announcements_state'],
  142. $values['forum_state'],
  143. $values['wiki_state'],
  144. $values['chat_state'],
  145. $self_registration_allowed,
  146. $self_unregistration_allowed,
  147. $categoryId
  148. );
  149. if (isset($_POST['group_members']) &&
  150. count($_POST['group_members']) > $max_member &&
  151. $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
  152. ) {
  153. Display::addFlash(Display::return_message(get_lang('GroupTooMuchMembers'), 'warning'));
  154. header('Location: group.php?'.api_get_cidreq(true, false));
  155. } else {
  156. Display::addFlash(Display::return_message(get_lang('GroupSettingsModified'), 'success'));
  157. header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$cat['id']);
  158. }
  159. exit;
  160. }
  161. $defaults = $current_group;
  162. $category = GroupManager::get_category_from_group($group_id);
  163. if (!empty($category)) {
  164. $defaults['category_id'] = $category['id'];
  165. }
  166. $action = isset($_GET['action']) ? $_GET['action'] : '';
  167. $defaults['action'] = $action;
  168. if ($defaults['maximum_number_of_students'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  169. $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  170. } else {
  171. $defaults['max_member_no_limit'] = 1;
  172. $defaults['max_member'] = $defaults['maximum_number_of_students'];
  173. }
  174. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  175. $keyword_name = Security::remove_XSS($_GET['keyword']);
  176. echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  177. }
  178. Display :: display_header($nameTools, 'Group');
  179. $form->setDefaults($defaults);
  180. echo GroupManager::getSettingBar('settings');
  181. echo '<div class="row">';
  182. $form->display();
  183. echo '</div>';
  184. Display :: display_footer();