settings.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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. *
  9. * @package chamilo.group
  10. *
  11. * @todo course admin functionality to create groups based on who is in which course (or class).
  12. */
  13. require_once __DIR__.'/../inc/global.inc.php';
  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[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
  22. $interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']];
  23. $is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
  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="col-md-12">');
  31. $form->addElement('header', $nameTools);
  32. $form->addElement('html', '</div>');
  33. $form->addElement('html', '<div class="col-md-6">');
  34. // Group name
  35. $form->addElement('text', 'name', get_lang('GroupName'));
  36. if (api_get_setting('allow_group_categories') == 'true') {
  37. $groupCategories = GroupManager::get_categories();
  38. $categoryList = [];
  39. //$categoryList[] = null;
  40. foreach ($groupCategories as $category) {
  41. $categoryList[$category['id']] = $category['title'];
  42. }
  43. $form->addElement('select', 'category_id', get_lang('Category'), $categoryList);
  44. } else {
  45. $form->addHidden('category_id', 0);
  46. }
  47. $form->addElement('html', '</div>');
  48. $form->addElement('html', '<div class="col-md-6">');
  49. $form->addElement('textarea', 'description', get_lang('Description'));
  50. $form->addElement('html', '</div>');
  51. $form->addElement('html', '<div class="col-md-12">');
  52. $form->addElement('header', '');
  53. $form->addElement('html', '</div>');
  54. $form->addElement('html', '<div class="col-md-6">');
  55. // Members per group
  56. $group = [
  57. $form->createElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT),
  58. $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, ['id' => 'max_member_selected']),
  59. $form->createElement('text', 'max_member', null, ['class' => 'span1', 'id' => 'max_member']),
  60. $form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis')),
  61. ];
  62. $form->addGroup($group, 'max_member_group', get_lang('GroupLimit'), null, false);
  63. $form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
  64. $form->addElement('html', '</div>');
  65. $form->addElement('html', '<div class="col-md-6">');
  66. // Self registration
  67. $group = [
  68. $form->createElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1),
  69. $form->createElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1),
  70. ];
  71. $form->addGroup(
  72. $group,
  73. '',
  74. Display::return_icon('user.png', get_lang('GroupSelfRegistration')).'<span>'.get_lang('GroupSelfRegistration').'</span>',
  75. null,
  76. false
  77. );
  78. $form->addElement('html', '</div>');
  79. $form->addElement('html', '<div class="col-md-12">');
  80. $form->addElement('header', get_lang('DefaultSettingsForNewGroups'));
  81. $form->addElement('html', '</div>');
  82. $form->addElement('html', '<div class="col-md-6">');
  83. // Documents settings
  84. $group = [
  85. $form->createElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  86. $form->createElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  87. $form->createElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
  88. ];
  89. $form->addGroup(
  90. $group,
  91. '',
  92. Display::return_icon('folder.png', get_lang('GroupDocument')).'<span>'.get_lang('GroupDocument').'</span>',
  93. null,
  94. false
  95. );
  96. $allowDocumentGroupAccess = api_get_configuration_value('group_document_access');
  97. if ($allowDocumentGroupAccess) {
  98. $form->addElement('html', '</div>');
  99. $form->addElement('html', '<div class="col-md-6">');
  100. $group = [
  101. $form->createElement(
  102. 'radio',
  103. 'document_access',
  104. null,
  105. get_lang('DocumentGroupShareMode'),
  106. GroupManager::DOCUMENT_MODE_SHARE
  107. ),
  108. $form->createElement(
  109. 'radio',
  110. 'document_access',
  111. get_lang('GroupDocument'),
  112. get_lang('DocumentGroupCollaborationMode'),
  113. GroupManager::DOCUMENT_MODE_COLLABORATION
  114. ),
  115. $form->createElement(
  116. 'radio',
  117. 'document_access',
  118. null,
  119. get_lang('DocumentGroupReadOnlyMode'),
  120. GroupManager::DOCUMENT_MODE_READ_ONLY
  121. ),
  122. ];
  123. $form->addGroup(
  124. $group,
  125. '',
  126. Display::return_icon(
  127. 'folder.png',
  128. get_lang('GroupDocumentAccess')
  129. ).'<span>'.get_lang('GroupDocumentAccess').'</span>',
  130. null,
  131. false
  132. );
  133. $form->addElement('html', '</div>');
  134. $form->addElement('html', '<div class="col-md-12">');
  135. $form->addElement('header', '');
  136. $form->addElement('html', '</div>');
  137. $form->addElement('html', '<div class="col-md-6">');
  138. }
  139. // Work settings
  140. $group = [
  141. $form->createElement(
  142. 'radio',
  143. 'work_state',
  144. get_lang('GroupWork'),
  145. get_lang('NotAvailable'),
  146. GroupManager::TOOL_NOT_AVAILABLE
  147. ),
  148. $form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  149. $form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
  150. ];
  151. $form->addElement('html', '</div>');
  152. $form->addElement('html', '<div class="col-md-12">');
  153. $form->addElement('html', '</div>');
  154. $form->addElement('html', '<div class="col-md-6">');
  155. $form->addGroup(
  156. $group,
  157. '',
  158. Display::return_icon('works.png', get_lang('GroupWork')).'<span>'.get_lang('GroupWork').'</span>',
  159. null,
  160. false
  161. );
  162. // Calendar settings
  163. $group = [
  164. $form->createElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  165. $form->createElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  166. $form->createElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
  167. ];
  168. $form->addElement('html', '</div>');
  169. $form->addElement('html', '<div class="col-md-6">');
  170. $form->addGroup(
  171. $group,
  172. '',
  173. Display::return_icon('agenda.png', get_lang('GroupCalendar')).'<span>'.get_lang('GroupCalendar').'</span>',
  174. null,
  175. false
  176. );
  177. $form->addElement('html', '</div>');
  178. $form->addElement('html', '<div class="col-md-12">');
  179. $form->addElement('header', '');
  180. $form->addElement('html', '</div>');
  181. $form->addElement('html', '<div class="col-md-6">');
  182. // Announcements settings
  183. $group = [
  184. $form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  185. $form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  186. $form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
  187. ];
  188. $form->addGroup(
  189. $group,
  190. '',
  191. Display::return_icon('announce.png', get_lang('GroupAnnouncements')).'<span>'.get_lang('GroupAnnouncements').'</span>',
  192. null,
  193. false
  194. );
  195. $form->addElement('html', '</div>');
  196. $form->addElement('html', '<div class="col-md-6">');
  197. // Forum settings
  198. $group = [
  199. $form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  200. $form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  201. $form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
  202. ];
  203. $form->addGroup(
  204. $group,
  205. '',
  206. Display::return_icon('forum.png', get_lang('GroupForum')).'<span>'.get_lang('GroupForum').'</span>',
  207. null,
  208. false
  209. );
  210. $form->addElement('html', '</div>');
  211. $form->addElement('html', '<div class="col-md-12">');
  212. $form->addElement('header', '');
  213. $form->addElement('html', '</div>');
  214. $form->addElement('html', '<div class="col-md-6">');
  215. // Wiki settings
  216. $group = [
  217. $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  218. $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  219. $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
  220. ];
  221. $form->addGroup(
  222. $group,
  223. '',
  224. Display::return_icon('wiki.png', get_lang('GroupWiki')).'<span>'.get_lang('GroupWiki').'</span>',
  225. '',
  226. false
  227. );
  228. $form->addElement('html', '</div>');
  229. $form->addElement('html', '<div class="col-md-6">');
  230. // Chat settings
  231. $group = [
  232. $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  233. $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  234. $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE),
  235. ];
  236. $form->addGroup(
  237. $group,
  238. '',
  239. Display::return_icon('chat.png', get_lang('Chat')).'<span>'.get_lang('Chat').'</span>',
  240. null,
  241. false
  242. );
  243. $form->addElement('html', '</div>');
  244. $form->addElement('html', '<div class="col-md-12">');
  245. // Submit button
  246. $form->addButtonSave(get_lang('SaveSettings'));
  247. $form->addElement('html', '</div>');
  248. if ($form->validate()) {
  249. $values = $form->exportValues();
  250. if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  251. $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  252. } else {
  253. $max_member = $values['max_member'];
  254. }
  255. $self_registration_allowed = isset($values['self_registration_allowed']) ? 1 : 0;
  256. $self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0;
  257. $categoryId = isset($values['category_id']) ? $values['category_id'] : null;
  258. GroupManager::set_group_properties(
  259. $current_group['id'],
  260. $values['name'],
  261. $values['description'],
  262. $max_member,
  263. $values['doc_state'],
  264. $values['work_state'],
  265. $values['calendar_state'],
  266. $values['announcements_state'],
  267. $values['forum_state'],
  268. $values['wiki_state'],
  269. $values['chat_state'],
  270. $self_registration_allowed,
  271. $self_unregistration_allowed,
  272. $categoryId,
  273. isset($values['document_access']) ? $values['document_access'] : 0
  274. );
  275. if (isset($_POST['group_members']) &&
  276. count($_POST['group_members']) > $max_member &&
  277. $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
  278. ) {
  279. Display::addFlash(Display::return_message(get_lang('GroupTooMuchMembers'), 'warning'));
  280. header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$categoryId);
  281. } else {
  282. Display::addFlash(Display::return_message(get_lang('GroupSettingsModified'), 'success'));
  283. header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$categoryId);
  284. }
  285. exit;
  286. }
  287. $defaults = $current_group;
  288. $category = GroupManager::get_category_from_group($current_group['iid']);
  289. if (!empty($category)) {
  290. $defaults['category_id'] = $category['id'];
  291. }
  292. $action = isset($_GET['action']) ? $_GET['action'] : '';
  293. $defaults['action'] = $action;
  294. if ($defaults['maximum_number_of_students'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  295. $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  296. } else {
  297. $defaults['max_member_no_limit'] = 1;
  298. $defaults['max_member'] = $defaults['maximum_number_of_students'];
  299. }
  300. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  301. $keyword_name = Security::remove_XSS($_GET['keyword']);
  302. echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  303. }
  304. Display::display_header($nameTools, 'Group');
  305. $form->setDefaults($defaults);
  306. echo GroupManager::getSettingBar('settings');
  307. echo '<div class="row">';
  308. $form->display();
  309. echo '</div>';
  310. Display :: display_footer();