settings.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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?'.api_get_cidreq(), '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(), $current_group['iid']);
  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('group.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. } else {
  43. $form->addHidden('category_id', 0);
  44. }
  45. // Members per group
  46. $group = array(
  47. $form->createElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT),
  48. $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, array('id' => 'max_member_selected')),
  49. $form->createElement('text', 'max_member', null, array('class' => 'span1', 'id' => 'max_member')),
  50. $form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis'))
  51. );
  52. $form->addGroup($group, 'max_member_group', get_lang('GroupLimit'), null, false);
  53. $form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
  54. $form->addElement('html', '</div>');
  55. $form->addElement('html', '<div class="col-md-6">');
  56. // Description
  57. $form->addElement('textarea', 'description', get_lang('Description'));
  58. $form->addElement('html', '</div>');
  59. $form->addElement('html', '<div class="col-md-12">');
  60. $form->addElement('header', get_lang('DefaultSettingsForNewGroups'));
  61. $form->addElement('html', '</div>');
  62. $form->addElement('html', '<div class="col-md-6">');
  63. // Self registration
  64. $group = array(
  65. $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1),
  66. $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1)
  67. );
  68. $form->addGroup(
  69. $group,
  70. '',
  71. Display::return_icon('user.png', get_lang('GroupSelfRegistration')) . '<span>' . get_lang('GroupSelfRegistration') . '</span>',
  72. null,
  73. false
  74. );
  75. // Documents settings
  76. $group = array(
  77. $form->createElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  78. $form->createElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  79. $form->createElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  80. );
  81. $form->addGroup(
  82. $group,
  83. '',
  84. Display::return_icon('folder.png', get_lang('GroupDocument')) . '<span>' . get_lang('GroupDocument') . '</span>',
  85. null,
  86. false
  87. );
  88. // Work settings
  89. $group = array(
  90. $form->createElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  91. $form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  92. $form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  93. );
  94. $form->addGroup(
  95. $group,
  96. '',
  97. Display::return_icon('works.png', get_lang('GroupWork')) . '<span>' . get_lang('GroupWork') . '</span>',
  98. null,
  99. false
  100. );
  101. // Calendar settings
  102. $group = array(
  103. $form->createElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  104. $form->createElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  105. $form->createElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  106. );
  107. $form->addGroup(
  108. $group,
  109. '',
  110. Display::return_icon('agenda.png', get_lang('GroupCalendar')) . '<span>' . get_lang('GroupCalendar') . '</span>',
  111. null,
  112. false
  113. );
  114. $form->addElement('html', '</div>');
  115. $form->addElement('html', '<div class="col-md-6">');
  116. // Announcements settings
  117. $group = array(
  118. $form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  119. $form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  120. $form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  121. );
  122. $form->addGroup(
  123. $group,
  124. '',
  125. Display::return_icon('announce.png', get_lang('GroupAnnouncements')) . '<span>' . get_lang('GroupAnnouncements') . '</span>',
  126. null,
  127. false
  128. );
  129. // Forum settings
  130. $group = array(
  131. $form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  132. $form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  133. $form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  134. );
  135. $form->addGroup(
  136. $group,
  137. '',
  138. Display::return_icon('forum.png', get_lang('GroupForum')) . '<span>' . get_lang('GroupForum') . '</span>',
  139. null,
  140. false
  141. );
  142. // Wiki settings
  143. $group = array(
  144. $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  145. $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  146. $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  147. );
  148. $form->addGroup(
  149. $group,
  150. '',
  151. Display::return_icon('wiki.png', get_lang('GroupWiki')).'<span>'.get_lang('GroupWiki').'</span>', '',
  152. false
  153. );
  154. // Chat settings
  155. $group = array(
  156. $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  157. $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  158. $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  159. );
  160. $form->addGroup(
  161. $group,
  162. '',
  163. Display::return_icon('chat.png', get_lang('Chat')) . '<span>' . get_lang('Chat') . '</span>',
  164. null,
  165. false
  166. );
  167. $form->addElement('html', '</div>');
  168. $form->addElement('html', '<div class="col-md-12">');
  169. // Submit button
  170. $form->addButtonSave(get_lang('SaveSettings'));
  171. $form->addElement('html', '</div>');
  172. if ($form->validate()) {
  173. $values = $form->exportValues();
  174. if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  175. $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  176. } else {
  177. $max_member = $values['max_member'];
  178. }
  179. $self_registration_allowed = isset($values['self_registration_allowed']) ? 1 : 0;
  180. $self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0;
  181. $categoryId = isset($values['category_id']) ? $values['category_id'] : null;
  182. GroupManager::set_group_properties(
  183. $current_group['id'],
  184. $values['name'],
  185. $values['description'],
  186. $max_member,
  187. $values['doc_state'],
  188. $values['work_state'],
  189. $values['calendar_state'],
  190. $values['announcements_state'],
  191. $values['forum_state'],
  192. $values['wiki_state'],
  193. $values['chat_state'],
  194. $self_registration_allowed,
  195. $self_unregistration_allowed,
  196. $categoryId
  197. );
  198. if (isset($_POST['group_members']) &&
  199. count($_POST['group_members']) > $max_member &&
  200. $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
  201. ) {
  202. Display::addFlash(Display::return_message(get_lang('GroupTooMuchMembers'), 'warning'));
  203. header('Location: group.php?'.api_get_cidreq(true, false));
  204. } else {
  205. Display::addFlash(Display::return_message(get_lang('GroupSettingsModified'), 'success'));
  206. header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$cat['id']);
  207. }
  208. exit;
  209. }
  210. $defaults = $current_group;
  211. $category = GroupManager::get_category_from_group($current_group['iid']);
  212. if (!empty($category)) {
  213. $defaults['category_id'] = $category['id'];
  214. }
  215. $action = isset($_GET['action']) ? $_GET['action'] : '';
  216. $defaults['action'] = $action;
  217. if ($defaults['maximum_number_of_students'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  218. $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  219. } else {
  220. $defaults['max_member_no_limit'] = 1;
  221. $defaults['max_member'] = $defaults['maximum_number_of_students'];
  222. }
  223. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  224. $keyword_name = Security::remove_XSS($_GET['keyword']);
  225. echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  226. }
  227. Display :: display_header($nameTools, 'Group');
  228. $form->setDefaults($defaults);
  229. echo GroupManager::getSettingBar('settings');
  230. echo '<div class="row">';
  231. $form->display();
  232. echo '</div>';
  233. Display :: display_footer();