group_category.php 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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) || !(isset ($_GET['id']) || isset ($_POST['id']) || isset ($_GET['action']) || isset ($_POST['action']))) {
  14. api_not_allowed();
  15. }
  16. /**
  17. * Function to check the given max number of members per group
  18. */
  19. function check_max_number_of_members($value) {
  20. $max_member_no_limit = $value['max_member_no_limit'];
  21. if ($max_member_no_limit == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  22. return true;
  23. }
  24. $max_member = $value['max_member'];
  25. return is_numeric($max_member);
  26. }
  27. /**
  28. * Function to check the number of groups per user
  29. */
  30. function check_groups_per_user($value) {
  31. $groups_per_user = $value['groups_per_user'];
  32. if (isset ($_POST['id']) && intval($groups_per_user) != GroupManager::GROUP_PER_MEMBER_NO_LIMIT && GroupManager::get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user)) {
  33. return false;
  34. }
  35. return true;
  36. }
  37. if (api_get_setting('allow_group_categories') == 'true') {
  38. if (isset ($_GET['id'])) {
  39. $category = GroupManager :: get_category($_GET['id']);
  40. $nameTools = get_lang('EditGroupCategory').': '.$category['title'];
  41. } else {
  42. $nameTools = get_lang('AddCategory');
  43. // Default values for new category
  44. $category = array(
  45. 'groups_per_user' => 1,
  46. 'doc_state' => GroupManager::TOOL_PRIVATE,
  47. 'work_state' => GroupManager::TOOL_PRIVATE,
  48. 'wiki_state' => GroupManager::TOOL_PRIVATE ,
  49. 'chat_state' => GroupManager::TOOL_PRIVATE,
  50. 'calendar_state' => GroupManager::TOOL_PRIVATE,
  51. 'announcements_state'=> GroupManager::TOOL_PRIVATE,
  52. 'forum_state' => GroupManager::TOOL_PRIVATE,
  53. 'max_student' => 0);
  54. }
  55. } else {
  56. $category = GroupManager :: get_category($_GET['id']);
  57. $nameTools = get_lang('PropModify');
  58. }
  59. $htmlHeadXtra[] = '<script>
  60. $(document).ready( function() {
  61. $("#max_member").on("focus", function() {
  62. $("#max_member_selected").attr("checked", true);
  63. });
  64. });
  65. </script>';
  66. $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
  67. $course_id = api_get_course_int_id();
  68. // Build the form
  69. if (isset ($_GET['id'])) {
  70. // Update settings of existing category
  71. $action = 'update_settings';
  72. $form = new FormValidator('group_category', 'post', '?id='.$category['id']);
  73. $form->addElement('header', $nameTools);
  74. $form->addElement('hidden', 'id');
  75. } else {
  76. // Checks if the field was created in the table Category. It creates it if is neccesary
  77. $table_category = Database :: get_course_table(TABLE_GROUP_CATEGORY);
  78. if (!Database::query("SELECT wiki_state FROM $table_category WHERE c_id = $course_id")) {
  79. Database::query("ALTER TABLE $table_category ADD wiki_state tinyint(3) UNSIGNED NOT NULL default '1' WHERE c_id = $course_id");
  80. }
  81. // Create a new category
  82. $action = 'add_category';
  83. $form = new FormValidator('group_category');
  84. }
  85. $form->addElement('html', '<div class="sectiontitle" >'.$nameTools);
  86. $form->addElement('html', '</div>');
  87. // If categories allowed, show title & description field
  88. if (api_get_setting('allow_group_categories') == 'true') {
  89. $form->add_textfield('title', get_lang('Title'));
  90. $form->addElement('textarea', 'description', get_lang('Description'), array('cols' => 50, 'rows' => 6));
  91. } else {
  92. $form->addElement('hidden', 'title');
  93. $form->addElement('hidden', 'description');
  94. }
  95. // Action
  96. $form->addElement('hidden', 'action');
  97. // Groups per user
  98. $group = array ();
  99. $group[] = $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'));
  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[] = $form->createElement('select', 'groups_per_user', null, $possible_values);
  106. $group[] = $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber'));
  107. $form->addGroup($group, 'limit_group', get_lang('GroupLimit'), ' ', false);
  108. $form->addRule('limit_group', get_lang('MaxGroupsPerUserInvalid'), 'callback', 'check_groups_per_user');
  109. // Default settings for new groups
  110. //$form->addElement('static', null, '<b>'.get_lang('DefaultSettingsForNewGroups').'</b>');
  111. $form->addElement('html', '<br /><br /><div class="sectiontitle" >'.get_lang('DefaultSettingsForNewGroups'));
  112. $form->addElement('html', '</div>');
  113. // Members per group
  114. $form->addElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'), GroupManager::MEMBER_PER_GROUP_NO_LIMIT);
  115. $group = array ();
  116. $group[] = $form->createElement('radio', 'max_member_no_limit', null, get_lang('MaximumOfParticipants'), 1, array('id' => 'max_member_selected'));
  117. $group[] = $form->createElement('text', 'max_member', null, array ('size' => 2, 'id' => 'max_member'));
  118. $group[] = $form->createElement('static', null, null, get_lang('GroupPlacesThis'));
  119. $form->addGroup($group, 'max_member_group', null, '', false);
  120. $form->addRule('max_member_group', get_lang('InvalidMaxNumberOfMembers'), 'callback', 'check_max_number_of_members');
  121. // Self registration
  122. $form->addElement('checkbox', 'self_reg_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1);
  123. $form->addElement('checkbox', 'self_unreg_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1);
  124. // Documents settings
  125. $form->addElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
  126. $form->addElement('radio', 'doc_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
  127. $form->addElement('radio', 'doc_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
  128. // Work settings
  129. $form->addElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
  130. $form->addElement('radio', 'work_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
  131. $form->addElement('radio', 'work_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
  132. // Calendar settings
  133. $form->addElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
  134. $form->addElement('radio', 'calendar_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
  135. $form->addElement('radio', 'calendar_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
  136. // Announcements settings
  137. $form->addElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
  138. $form->addElement('radio', 'announcements_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
  139. $form->addElement('radio', 'announcements_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
  140. // Forum settings
  141. $form->addElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
  142. $form->addElement('radio', 'forum_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
  143. $form->addElement('radio', 'forum_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
  144. // Wiki Settings
  145. $form->addElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
  146. $form->addElement('radio', 'wiki_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
  147. $form->addElement('radio', 'wiki_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
  148. // Chat Settings
  149. $form->addElement('radio', 'chat_state', get_lang('Chat'), get_lang('NotAvailable'), GroupManager::TOOL_NOT_AVAILABLE);
  150. $form->addElement('radio', 'chat_state', null, get_lang('Public'), GroupManager::TOOL_PUBLIC);
  151. $form->addElement('radio', 'chat_state', null, get_lang('Private'), GroupManager::TOOL_PRIVATE);
  152. // Submit
  153. $form->addElement('style_submit_button', 'submit', get_lang('PropModify'), 'class="save"');
  154. // If form validates -> save data
  155. if ($form->validate()) {
  156. $values = $form->exportValues();
  157. if ($values['max_member_no_limit'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  158. $max_member = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  159. } else {
  160. $max_member = $values['max_member'];
  161. }
  162. $self_reg_allowed = isset($values['self_reg_allowed']) ? $values['self_reg_allowed'] : 0;
  163. $self_unreg_allowed = isset($values['self_unreg_allowed']) ? $values['self_unreg_allowed'] : 0;
  164. switch ($values['action']) {
  165. case 'update_settings':
  166. GroupManager :: update_category($values['id'], $values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $values['forum_state'], $values['wiki_state'], $values['chat_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']);
  167. $msg = urlencode(get_lang('GroupPropertiesModified'));
  168. header('Location: group.php?action=show_msg&msg='.$msg.'&category='.$values['id']);
  169. break;
  170. case 'add_category':
  171. GroupManager :: create_category($values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $values['forum_state'], $values['wiki_state'], $values['chat_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']);
  172. $msg = urlencode(get_lang('CategoryCreated'));
  173. header('Location: group.php?action=show_msg&msg='.$msg);
  174. break;
  175. }
  176. }
  177. // Else display the form
  178. Display :: display_header($nameTools, 'Group');
  179. // actions bar
  180. echo '<div class="actions">';
  181. echo '<a href="group.php">'.Display::return_icon('back.png', get_lang('BackToGroupList'),'',ICON_SIZE_MEDIUM).'</a>';
  182. echo '</div>';
  183. $defaults = $category;
  184. $defaults['action'] = $action;
  185. if ($defaults['max_student'] == GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  186. $defaults['max_member_no_limit'] = GroupManager::MEMBER_PER_GROUP_NO_LIMIT;
  187. } else {
  188. $defaults['max_member_no_limit'] = 1;
  189. $defaults['max_member'] = $defaults['max_student'];
  190. }
  191. $form->setDefaults($defaults);
  192. $form->display();
  193. Display :: display_footer();