settings.php 10 KB

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