settings.php 10 KB

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