group_category.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. // Action
  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('GroupLimit'), ' ', 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. // Members per group
  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. // Work settings
  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. // Calendar 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. // Announcements 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. // Forum 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. // Wiki Settings
  161. $form->addElement('html', '</div>');
  162. $form->addElement('html', '<div class="span6">');
  163. // Chat Settings
  164. // Announcements settings
  165. $group = array(
  166. $form->createElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  167. $form->createElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  168. $form->createElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  169. );
  170. $form->addGroup($group, '', Display::return_icon('announce.png', get_lang('GroupAnnouncements'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupAnnouncements'), '', false);
  171. // Forum settings
  172. $group = array(
  173. $form->createElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  174. $form->createElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  175. $form->createElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  176. );
  177. $form->addGroup($group, '', Display::return_icon('forum.png', get_lang('GroupForum'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupForum'), '', false);
  178. // Wiki settings
  179. $group = array(
  180. $form->createElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  181. $form->createElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  182. $form->createElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  183. );
  184. $form->addGroup($group, '', Display::return_icon('wiki.png', get_lang('GroupWiki'), array(), ICON_SIZE_SMALL).' '.get_lang('GroupWiki'), '', false);
  185. // Chat settings
  186. $group = array(
  187. $form->createElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE),
  188. $form->createElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC),
  189. $form->createElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE)
  190. );
  191. $form->addGroup($group, '', Display::return_icon('chat.png', get_lang('Chat'), array(), ICON_SIZE_SMALL).' '.get_lang('Chat'), '', false);
  192. $form->addElement('html', '</div>');
  193. $form->addElement('html', '<div class="span12">');
  194. // Submit
  195. $form->addElement('style_submit_button', 'submit', get_lang('PropModify'), 'class="save"');
  196. // If form validates -> save data
  197. if ($form->validate()) {
  198. $values = $form->exportValues();
  199. if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  200. $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  201. } else {
  202. $max_member = $values['max_member'];
  203. }
  204. $self_reg_allowed = isset($values['self_reg_allowed']) ? $values['self_reg_allowed'] : 0;
  205. $self_unreg_allowed = isset($values['self_unreg_allowed']) ? $values['self_unreg_allowed'] : 0;
  206. switch ($values['action']) {
  207. case 'update_settings':
  208. GroupManager::update_category(
  209. $values['id'],
  210. $values['title'],
  211. $values['description'],
  212. $values['doc_state'],
  213. $values['work_state'],
  214. $values['calendar_state'],
  215. $values['announcements_state'],
  216. $values['forum_state'],
  217. $values['wiki_state'],
  218. $values['chat_state'],
  219. $self_reg_allowed,
  220. $self_unreg_allowed,
  221. $max_member,
  222. $values['groups_per_user']
  223. );
  224. $msg = urlencode(get_lang('GroupPropertiesModified'));
  225. header('Location: group.php?action=show_msg&msg='.$msg.'&category='.$values['id']);
  226. break;
  227. case 'add_category':
  228. GroupManager :: create_category(
  229. $values['title'],
  230. $values['description'],
  231. $values['doc_state'],
  232. $values['work_state'],
  233. $values['calendar_state'],
  234. $values['announcements_state'],
  235. $values['forum_state'],
  236. $values['wiki_state'],
  237. $values['chat_state'],
  238. $self_reg_allowed,
  239. $self_unreg_allowed,
  240. $max_member,
  241. $values['groups_per_user']
  242. );
  243. $msg = urlencode(get_lang('CategoryCreated'));
  244. header('Location: group.php?action=show_msg&msg='.$msg);
  245. break;
  246. }
  247. }
  248. // Else display the form
  249. Display :: display_header($nameTools, 'Group');
  250. // actions bar
  251. echo '<div class="actions">';
  252. echo '<a href="group.php">'.Display::return_icon('back.png', get_lang('BackToGroupList'),'',ICON_SIZE_MEDIUM).'</a>';
  253. echo '</div>';
  254. $defaults = $category;
  255. $defaults['action'] = $action;
  256. if ($defaults['max_student'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  257. $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  258. } else {
  259. $defaults['max_member_no_limit'] = 1;
  260. $defaults['max_member'] = $defaults['max_student'];
  261. }
  262. $form->setDefaults($defaults);
  263. $form->display();
  264. Display :: display_footer();