group_category.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.group
  5. */
  6. // Name of the language file that needs to be included
  7. $language_file = 'group';
  8. require_once '../inc/global.inc.php';
  9. $this_section = SECTION_COURSES;
  10. $current_course_tool = TOOL_GROUP;
  11. // Notice for unauthorized people.
  12. api_protect_course_script(true);
  13. if (!api_is_allowed_to_edit(false,true) ||
  14. !(isset ($_GET['id']) ||
  15. isset ($_POST['id']) ||
  16. isset ($_GET['action']) ||
  17. isset ($_POST['action']))
  18. ) {
  19. api_not_allowed();
  20. }
  21. /**
  22. * Function to check the given max number of members per group
  23. */
  24. function check_max_number_of_members($value)
  25. {
  26. $max_member_no_limit = $value['max_member_no_limit'];
  27. if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  28. return true;
  29. }
  30. $max_member = $value['max_member'];
  31. return is_numeric($max_member);
  32. }
  33. /**
  34. * Function to check the number of groups per user
  35. */
  36. function check_groups_per_user($value)
  37. {
  38. $groups_per_user = $value['groups_per_user'];
  39. if (isset($_POST['id']) &&
  40. intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT &&
  41. GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) {
  42. return false;
  43. }
  44. return true;
  45. }
  46. if (api_get_setting('allow_group_categories') == 'true') {
  47. if (isset ($_GET['id'])) {
  48. $category = GroupManager::get_category($_GET['id']);
  49. $nameTools = get_lang('EditGroupCategory').': '.$category['title'];
  50. } else {
  51. $nameTools = get_lang('AddCategory');
  52. // Default values for new category
  53. $category = array(
  54. 'groups_per_user' => 1,
  55. 'doc_state' => GroupManager::TOOL_PRIVATE,
  56. 'work_state' => GroupManager::TOOL_PRIVATE,
  57. 'wiki_state' => GroupManager::TOOL_PRIVATE ,
  58. 'chat_state' => GroupManager::TOOL_PRIVATE,
  59. 'calendar_state' => GroupManager::TOOL_PRIVATE,
  60. 'announcements_state'=> GroupManager::TOOL_PRIVATE,
  61. 'forum_state' => GroupManager::TOOL_PRIVATE,
  62. 'max_student' => 0
  63. );
  64. }
  65. } else {
  66. $category = GroupManager::get_category($_GET['id']);
  67. $nameTools = get_lang('PropModify');
  68. }
  69. $htmlHeadXtra[] = '<script>
  70. $(document).ready( function() {
  71. $("#max_member").on("focus", function() {
  72. $("#max_member_selected").attr("checked", true);
  73. });
  74. });
  75. </script>';
  76. $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
  77. $course_id = api_get_course_int_id();
  78. // Build the form
  79. if (isset($_GET['id'])) {
  80. // Update settings of existing category
  81. $action = 'update_settings';
  82. $form = new FormValidator('group_category', 'post', '?id='.$category['id']);
  83. $form->addElement('hidden', 'id');
  84. } else {
  85. // Checks if the field was created in the table Category. It creates it if is neccesary
  86. $table_category = Database :: get_course_table(TABLE_GROUP_CATEGORY);
  87. if (!Database::query("SELECT wiki_state FROM $table_category WHERE c_id = $course_id")) {
  88. Database::query("ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1' WHERE c_id = $course_id");
  89. }
  90. // Create a new category
  91. $action = 'add_category';
  92. $form = new FormValidator('group_category');
  93. }
  94. // If categories allowed, show title & description field
  95. if (api_get_setting('allow_group_categories') == 'true') {
  96. $form->addElement('header', $nameTools);
  97. $form->addElement('html', '<div class="row"><div class="span6">');
  98. $form->add_textfield('title', get_lang('Title'));
  99. // Groups per user
  100. $possible_values = array();
  101. for ($i = 1; $i <= 10; $i ++) {
  102. $possible_values[$i] = $i;
  103. }
  104. $possible_values[GroupManager::GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All');
  105. $group = array(
  106. $form->createElement('select', 'groups_per_user', null, $possible_values),
  107. $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber'))
  108. );
  109. $form->addGroup($group, 'limit_group', get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'), ' ', false);
  110. $form->addRule('limit_group', get_lang('MaxGroupsPerUserInvalid'), 'callback', 'check_groups_per_user');
  111. // Members per group
  112. $group = array(
  113. $form->createElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT),
  114. $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, array('id' => 'max_member_selected')),
  115. $form->createElement('text', 'max_member', null, array('class' => 'span1', 'id' => 'max_member')),
  116. $form->createElement('static', null, null, ' '.get_lang('GroupPlacesThis'))
  117. );
  118. $form->addGroup($group, 'max_member_group', get_lang('GroupLimit'), '', false);
  119. $form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
  120. $form->addElement('html', '</div>');
  121. $form->addElement('html', '<div class="span6">');
  122. // Description
  123. $form->addElement('textarea', 'description', get_lang('Description'), array ('class' => 'span6', 'rows' => 6));
  124. $form->addElement('html', '</div>');
  125. $form->addElement('html', '</div>');
  126. } else {
  127. $form->addElement('hidden', 'title');
  128. $form->addElement('hidden', 'description');
  129. }
  130. $form->addElement('header', get_lang('DefaultSettingsForNewGroups'));
  131. $form->addElement('hidden', 'action');
  132. $form->addElement('html', '<div class="span6">');
  133. // Self registration
  134. $group = array(
  135. $form->createElement('checkbox', 'self_reg_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1),
  136. $form->createElement('checkbox', 'self_unreg_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1)
  137. );
  138. $form->addGroup($group, '', Display::return_icon('user.png', get_lang('GroupSelfRegistration'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupSelfRegistration'), '', false);
  139. // Documents settings.
  140. $group = array(
  141. $form->createElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  142. $form->createElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  143. $form->createElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  144. );
  145. $form->addGroup($group, '', Display::return_icon('folder.png', get_lang('GroupDocument'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupDocument'), '', false);
  146. // Work settings.
  147. $group = array(
  148. $form->createElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  149. $form->createElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  150. $form->createElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  151. );
  152. $form->addGroup($group, '', Display::return_icon('work.png', get_lang('GroupWork'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupWork'), '', false);
  153. // Calendar settings.
  154. $group = array(
  155. $form->createElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  156. $form->createElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  157. $form->createElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  158. );
  159. $form->addGroup($group, '', Display::return_icon('agenda.png', get_lang('GroupCalendar'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupCalendar'), '', false);
  160. $form->addElement('html', '</div>');
  161. $form->addElement('html', '<div class="span6">');
  162. // Announcements settings.
  163. $group = array(
  164. $form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  165. $form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  166. $form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  167. );
  168. $form->addGroup($group, '', Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupAnnouncements'), '', false);
  169. // Forum settings.
  170. $group = array(
  171. $form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  172. $form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  173. $form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  174. );
  175. $form->addGroup($group, '', Display::return_icon('forum.png', get_lang('GroupForum'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupForum'), '', false);
  176. // Wiki settings.
  177. $group = array(
  178. $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  179. $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  180. $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  181. );
  182. $form->addGroup($group, '', Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupWiki'), '', false);
  183. // Chat settings.
  184. $group = array(
  185. $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  186. $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  187. $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  188. );
  189. $form->addGroup($group, '', Display::return_icon('chat.png', get_lang('Chat'), array(), ICON_SIZE_SMALL).' '.get_lang('Chat'), '', false);
  190. $form->addElement('html', '</div>');
  191. $form->addElement('html', '<div class="span12">');
  192. // Submit
  193. $form->addElement('style_submit_button', 'submit', get_lang('PropModify'), 'class="save"');
  194. // If form validates -> save data
  195. if ($form->validate()) {
  196. $values = $form->exportValues();
  197. if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  198. $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  199. } else {
  200. $max_member = $values['max_member'];
  201. }
  202. $self_reg_allowed = isset($values['self_reg_allowed']) ? $values['self_reg_allowed'] : 0;
  203. $self_unreg_allowed = isset($values['self_unreg_allowed']) ? $values['self_unreg_allowed'] : 0;
  204. switch ($values['action']) {
  205. case 'update_settings':
  206. GroupManager::update_category(
  207. $values['id'],
  208. $values['title'],
  209. $values['description'],
  210. $values['doc_state'],
  211. $values['work_state'],
  212. $values['calendar_state'],
  213. $values['announcements_state'],
  214. $values['forum_state'],
  215. $values['wiki_state'],
  216. $values['chat_state'],
  217. $self_reg_allowed,
  218. $self_unreg_allowed,
  219. $max_member,
  220. $values['groups_per_user']
  221. );
  222. $msg = urlencode(get_lang('GroupPropertiesModified'));
  223. header('Location: group.php?action=show_msg&msg='.$msg.'&category='.$values['id']);
  224. break;
  225. case 'add_category':
  226. GroupManager :: create_category(
  227. $values['title'],
  228. $values['description'],
  229. $values['doc_state'],
  230. $values['work_state'],
  231. $values['calendar_state'],
  232. $values['announcements_state'],
  233. $values['forum_state'],
  234. $values['wiki_state'],
  235. $values['chat_state'],
  236. $self_reg_allowed,
  237. $self_unreg_allowed,
  238. $max_member,
  239. $values['groups_per_user']
  240. );
  241. $msg = urlencode(get_lang('CategoryCreated'));
  242. header('Location: group.php?action=show_msg&msg='.$msg);
  243. break;
  244. }
  245. }
  246. // Else display the form
  247. Display :: display_header($nameTools, 'Group');
  248. // actions bar
  249. echo '<div class="actions">';
  250. echo '<a href="group.php">'.Display::return_icon('back.png', get_lang('BackToGroupList'),'',ICON_SIZE_MEDIUM).'</a>';
  251. echo '</div>';
  252. $defaults = $category;
  253. $defaults['action'] = $action;
  254. if ($defaults['max_student'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  255. $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  256. } else {
  257. $defaults['max_member_no_limit'] = 1;
  258. $defaults['max_member'] = $defaults['max_student'];
  259. }
  260. $form->setDefaults($defaults);
  261. $form->display();
  262. Display :: display_footer();