settings.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  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. if (empty($current_group)) {
  21. api_not_allowed(true);
  22. }
  23. $nameTools = get_lang('Edit this group');
  24. $interbreadcrumb[] = ['url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups')];
  25. $interbreadcrumb[] = ['url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']];
  26. $groupMember = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group);
  27. if (!$groupMember && !api_is_allowed_to_edit(false, true)) {
  28. api_not_allowed(true);
  29. }
  30. // Build form
  31. $form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
  32. $form->addElement('hidden', 'action');
  33. $form->addElement('html', '<div class="col-md-12">');
  34. $form->addElement('header', $nameTools);
  35. $form->addElement('html', '</div>');
  36. $form->addElement('html', '<div class="col-md-6">');
  37. // Group name
  38. $form->addElement('text', 'name', get_lang('Group name'));
  39. if (api_get_setting('allow_group_categories') == 'true') {
  40. $groupCategories = GroupManager::get_categories();
  41. $categoryList = [];
  42. //$categoryList[] = null;
  43. foreach ($groupCategories as $category) {
  44. $categoryList[$category['id']] = $category['title'];
  45. }
  46. $form->addElement('select', 'category_id', get_lang('Category'), $categoryList);
  47. } else {
  48. $form->addHidden('category_id', 0);
  49. }
  50. $form->addElement('html', '</div>');
  51. $form->addElement('html', '<div class="col-md-6">');
  52. $form->addElement('textarea', 'description', get_lang('Description'));
  53. $form->addElement('html', '</div>');
  54. $form->addElement('html', '<div class="col-md-12">');
  55. $form->addElement('header', '');
  56. $form->addElement('html', '</div>');
  57. $form->addElement('html', '<div class="col-md-6">');
  58. // Members per group
  59. $group = [
  60. $form->createElement(
  61. 'radio',
  62. 'max_member_no_limit',
  63. get_lang('Limit'),
  64. get_lang('No limitation'),
  65. GroupManager::MEMBER_PER_GROUP_NO_LIMIT
  66. ),
  67. $form->createElement(
  68. 'radio',
  69. 'max_member_no_limit',
  70. null,
  71. get_lang('Maximum number of members'),
  72. 1,
  73. ['id' => 'max_member_selected']
  74. ),
  75. $form->createElement('text', 'max_member', null, ['class' => 'span1', 'id' => 'max_member']),
  76. $form->createElement('static', null, null, ' '.get_lang('seats (optional)')),
  77. ];
  78. $form->addGroup($group, 'max_member_group', get_lang('Limit'), null, false);
  79. $form->addRule('max_member_group', get_lang('Please enter a valid number for the maximum number of members.'), 'callback', 'check_max_number_of_members');
  80. $form->addElement('html', '</div>');
  81. $form->addElement('html', '<div class="col-md-6">');
  82. // Self registration
  83. $group = [
  84. $form->createElement(
  85. 'checkbox',
  86. 'self_registration_allowed',
  87. get_lang('Registration'),
  88. get_lang('Learners are allowed to self-register in groups'),
  89. 1
  90. ),
  91. $form->createElement(
  92. 'checkbox',
  93. 'self_unregistration_allowed',
  94. null,
  95. get_lang('Learners are allowed to unregister themselves from groups'),
  96. 1
  97. ),
  98. ];
  99. $form->addGroup(
  100. $group,
  101. '',
  102. Display::return_icon('user.png', get_lang('Registration')).
  103. '<span>'.get_lang('Registration').'</span>',
  104. null,
  105. false
  106. );
  107. $form->addElement('html', '</div>');
  108. $form->addElement('html', '<div class="col-md-12">');
  109. $form->addElement('header', get_lang('Default settings for new groups'));
  110. $form->addElement('html', '</div>');
  111. $form->addElement('html', '<div class="col-md-6">');
  112. // Documents settings
  113. $group = [
  114. $form->createElement('radio', 'doc_state', get_lang('Documents'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
  115. $form->createElement('radio', 'doc_state', null, get_lang('Public access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
  116. $form->createElement('radio', 'doc_state', null, get_lang('Private access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
  117. ];
  118. $form->addGroup(
  119. $group,
  120. '',
  121. Display::return_icon('folder.png', get_lang('Documents')).'<span>'.get_lang('Documents').'</span>',
  122. null,
  123. false
  124. );
  125. $allowDocumentGroupAccess = api_get_configuration_value('group_document_access');
  126. if ($allowDocumentGroupAccess) {
  127. $form->addElement('html', '</div>');
  128. $form->addElement('html', '<div class="col-md-6">');
  129. $group = [
  130. $form->createElement(
  131. 'radio',
  132. 'document_access',
  133. null,
  134. get_lang('Share mode'),
  135. GroupManager::DOCUMENT_MODE_SHARE
  136. ),
  137. $form->createElement(
  138. 'radio',
  139. 'document_access',
  140. get_lang('Documents'),
  141. get_lang('Collaboration mode'),
  142. GroupManager::DOCUMENT_MODE_COLLABORATION
  143. ),
  144. $form->createElement(
  145. 'radio',
  146. 'document_access',
  147. null,
  148. get_lang('Read only mode'),
  149. GroupManager::DOCUMENT_MODE_READ_ONLY
  150. ),
  151. ];
  152. $form->addGroup(
  153. $group,
  154. '',
  155. Display::return_icon(
  156. 'folder.png',
  157. get_lang('DocumentsAccess')
  158. ).'<span>'.get_lang('DocumentsAccess').'</span>',
  159. null,
  160. false
  161. );
  162. $form->addElement('html', '</div>');
  163. $form->addElement('html', '<div class="col-md-12">');
  164. $form->addElement('header', '');
  165. $form->addElement('html', '</div>');
  166. $form->addElement('html', '<div class="col-md-6">');
  167. }
  168. // Work settings
  169. $group = [
  170. $form->createElement(
  171. 'radio',
  172. 'work_state',
  173. get_lang('Assignments'),
  174. get_lang('Not available'),
  175. GroupManager::TOOL_NOT_AVAILABLE
  176. ),
  177. $form->createElement('radio', 'work_state', null, get_lang('Public access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
  178. $form->createElement('radio', 'work_state', null, get_lang('Private access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
  179. ];
  180. $form->addElement('html', '</div>');
  181. $form->addElement('html', '<div class="col-md-12">');
  182. $form->addElement('html', '</div>');
  183. $form->addElement('html', '<div class="col-md-6">');
  184. $form->addGroup(
  185. $group,
  186. '',
  187. Display::return_icon('works.png', get_lang('Assignments')).'<span>'.get_lang('Assignments').'</span>',
  188. null,
  189. false
  190. );
  191. // Calendar settings
  192. $group = [
  193. $form->createElement('radio', 'calendar_state', get_lang('Agenda'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
  194. $form->createElement('radio', 'calendar_state', null, get_lang('Public access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
  195. $form->createElement('radio', 'calendar_state', null, get_lang('Private access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
  196. ];
  197. $form->addElement('html', '</div>');
  198. $form->addElement('html', '<div class="col-md-6">');
  199. $form->addGroup(
  200. $group,
  201. '',
  202. Display::return_icon('agenda.png', get_lang('Agenda')).'<span>'.get_lang('Agenda').'</span>',
  203. null,
  204. false
  205. );
  206. $form->addElement('html', '</div>');
  207. $form->addElement('html', '<div class="col-md-12">');
  208. $form->addElement('header', '');
  209. $form->addElement('html', '</div>');
  210. $form->addElement('html', '<div class="col-md-6">');
  211. // Announcements settings
  212. $group = [
  213. $form->createElement('radio', 'announcements_state', get_lang('Announcements'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
  214. $form->createElement('radio', 'announcements_state', null, get_lang('Public access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
  215. $form->createElement('radio', 'announcements_state', null, get_lang('Private access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
  216. $form->createElement('radio', 'announcements_state', null, get_lang('Private access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only)BetweenUsers'), GroupManager::TOOL_PRIVATE_BETWEEN_USERS),
  217. ];
  218. $form->addGroup(
  219. $group,
  220. '',
  221. Display::return_icon('announce.png', get_lang('Announcements')).'<span>'.get_lang('Announcements').'</span>',
  222. null,
  223. false
  224. );
  225. $form->addElement('html', '</div>');
  226. $form->addElement('html', '<div class="col-md-6">');
  227. // Forum settings
  228. $group = [
  229. $form->createElement('radio', 'forum_state', get_lang('Group Forum'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
  230. $form->createElement('radio', 'forum_state', null, get_lang('Public access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
  231. $form->createElement('radio', 'forum_state', null, get_lang('Private access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
  232. ];
  233. $form->addGroup(
  234. $group,
  235. '',
  236. Display::return_icon('forum.png', get_lang('Group Forum')).'<span>'.get_lang('Group Forum').'</span>',
  237. null,
  238. false
  239. );
  240. $form->addElement('html', '</div>');
  241. $form->addElement('html', '<div class="col-md-12">');
  242. $form->addElement('header', '');
  243. $form->addElement('html', '</div>');
  244. $form->addElement('html', '<div class="col-md-6">');
  245. // Wiki settings
  246. $group = [
  247. $form->createElement('radio', 'wiki_state', get_lang('Wiki'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
  248. $form->createElement('radio', 'wiki_state', null, get_lang('Public access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
  249. $form->createElement('radio', 'wiki_state', null, get_lang('Private access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
  250. ];
  251. $form->addGroup(
  252. $group,
  253. '',
  254. Display::return_icon('wiki.png', get_lang('Wiki')).'<span>'.get_lang('Wiki').'</span>',
  255. '',
  256. false
  257. );
  258. $form->addElement('html', '</div>');
  259. $form->addElement('html', '<div class="col-md-6">');
  260. // Chat settings
  261. $group = [
  262. $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('Not available'), GroupManager::TOOL_NOT_AVAILABLE),
  263. $form->createElement('radio', 'chat_state', null, get_lang('Public access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course) access (access authorized to any member of the course)'), GroupManager::TOOL_PUBLIC),
  264. $form->createElement('radio', 'chat_state', null, get_lang('Private access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only) access (access authorized to group members only)'), GroupManager::TOOL_PRIVATE),
  265. ];
  266. $form->addGroup(
  267. $group,
  268. '',
  269. Display::return_icon('chat.png', get_lang('Chat')).'<span>'.get_lang('Chat').'</span>',
  270. null,
  271. false
  272. );
  273. $form->addElement('html', '</div>');
  274. $form->addElement('html', '<div class="col-md-12">');
  275. // Submit button
  276. $form->addButtonSave(get_lang('Save settings'));
  277. $form->addElement('html', '</div>');
  278. if ($form->validate()) {
  279. $values = $form->exportValues();
  280. if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  281. $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  282. } else {
  283. $max_member = $values['max_member'];
  284. }
  285. $self_registration_allowed = isset($values['self_registration_allowed']) ? 1 : 0;
  286. $self_unregistration_allowed = isset($values['self_unregistration_allowed']) ? 1 : 0;
  287. $categoryId = isset($values['category_id']) ? $values['category_id'] : null;
  288. GroupManager::set_group_properties(
  289. $current_group['id'],
  290. $values['name'],
  291. $values['description'],
  292. $max_member,
  293. $values['doc_state'],
  294. $values['work_state'],
  295. $values['calendar_state'],
  296. $values['announcements_state'],
  297. $values['forum_state'],
  298. $values['wiki_state'],
  299. $values['chat_state'],
  300. $self_registration_allowed,
  301. $self_unregistration_allowed,
  302. $categoryId,
  303. isset($values['document_access']) ? $values['document_access'] : 0
  304. );
  305. if (isset($_POST['group_members']) &&
  306. count($_POST['group_members']) > $max_member &&
  307. $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
  308. ) {
  309. Display::addFlash(Display::return_message(get_lang('Number proposed exceeds max. that you allowed (you can modify in the group settings). Group composition has not been modified'), 'warning'));
  310. header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$categoryId);
  311. } else {
  312. Display::addFlash(Display::return_message(get_lang('Group settings modified'), 'success'));
  313. header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$categoryId);
  314. }
  315. exit;
  316. }
  317. $defaults = $current_group;
  318. $category = GroupManager::get_category_from_group($current_group['iid']);
  319. if (!empty($category)) {
  320. $defaults['category_id'] = $category['id'];
  321. }
  322. $action = isset($_GET['action']) ? $_GET['action'] : '';
  323. $defaults['action'] = $action;
  324. if ($defaults['maximum_number_of_students'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  325. $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  326. } else {
  327. $defaults['max_member_no_limit'] = 1;
  328. $defaults['max_member'] = $defaults['maximum_number_of_students'];
  329. }
  330. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  331. $keyword_name = Security::remove_XSS($_GET['keyword']);
  332. echo '<br/>'.get_lang('Search results for:').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  333. }
  334. Display::display_header($nameTools, 'Group');
  335. $form->setDefaults($defaults);
  336. echo GroupManager::getSettingBar('settings');
  337. echo '<div class="row">';
  338. $form->display();
  339. echo '</div>';
  340. Display :: display_footer();