group_category.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. // $Id: group_category.php 14826 2008-04-10 08:10:19Z pcool $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004 Dokeos S.A.
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) various contributors
  10. Copyright (c) Bart Mollet, Hogeschool Gent
  11. For a full list of contributors, see "credits.txt".
  12. The full license can be read in "license.txt".
  13. This program is free software; you can redistribute it and/or
  14. modify it under the terms of the GNU General Public License
  15. as published by the Free Software Foundation; either version 2
  16. of the License, or (at your option) any later version.
  17. See the GNU General Public License for more details.
  18. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. ==============================================================================
  23. * @package dokeos.group
  24. ==============================================================================
  25. */
  26. /*
  27. ==============================================================================
  28. INIT SECTION
  29. ==============================================================================
  30. */
  31. // name of the language file that needs to be included
  32. $language_file = "group";
  33. require_once ('../inc/global.inc.php');
  34. $this_section = SECTION_COURSES;
  35. require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  36. require_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  37. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  38. if (!api_is_allowed_to_edit() || !(isset ($_GET['id']) || isset ($_POST['id']) || isset ($_GET['action']) || isset ($_POST['action'])))
  39. {
  40. api_not_allowed();
  41. }
  42. /**
  43. * Function to check the given max number of members per group
  44. */
  45. function check_max_number_of_members($value)
  46. {
  47. $max_member_no_limit = $value['max_member_no_limit'];
  48. if( $max_member_no_limit == MEMBER_PER_GROUP_NO_LIMIT)
  49. {
  50. return true;
  51. }
  52. $max_member = $value['max_member'];
  53. return is_numeric($max_member);
  54. }
  55. /**
  56. * Function to check the number of groups per user
  57. */
  58. function check_groups_per_user($value)
  59. {
  60. $groups_per_user = $value['groups_per_user'];
  61. if(isset ($_POST['id']) && intval($groups_per_user) != GROUP_PER_MEMBER_NO_LIMIT && GroupManager :: get_current_max_groups_per_user($_POST['id']) > intval($groups_per_user))
  62. {
  63. return false;
  64. }
  65. return true;
  66. }
  67. if (get_setting('allow_group_categories') == 'true')
  68. {
  69. if (isset ($_GET['id']))
  70. {
  71. $category = GroupManager :: get_category($_GET['id']);
  72. $nameTools = get_lang('Edit').' '.$category['title'];
  73. }
  74. else
  75. {
  76. $nameTools = get_lang('AddCategory');
  77. // default values for new category
  78. $category = array ('groups_per_user' => 1, 'doc_state' => TOOL_PRIVATE, 'work_state' => TOOL_PRIVATE, 'calendar_state' => TOOL_PRIVATE, 'announcements_state' => TOOL_PRIVATE, 'max_student' => 0);
  79. }
  80. }
  81. else
  82. {
  83. $category = GroupManager :: get_category($_GET['id']);
  84. $nameTools = get_lang('PropModify');
  85. }
  86. $interbreadcrumb[] = array ("url" => "group.php", "name" => get_lang('GroupManagement'));
  87. // Build the form
  88. if (isset ($_GET['id']))
  89. {
  90. // Update settings of existing category
  91. $action = 'update_settings';
  92. $form = new FormValidator('group_category', 'post', '?id='.$category['id']);
  93. $form->addElement('hidden', 'id');
  94. }
  95. else
  96. {
  97. // Create a new category
  98. $action = 'add_category';
  99. $form = new FormValidator('group_category');
  100. }
  101. // If categories allowed, show title & description field
  102. if (get_setting('allow_group_categories') == 'true')
  103. {
  104. $form->add_textfield('title', get_lang('Title'));
  105. $form->addElement('textarea', 'description', get_lang('Description'),array('cols'=>50,'rows'=>6));
  106. }
  107. else
  108. {
  109. $form->addElement('hidden','title');
  110. $form->addElement('hidden','description');
  111. }
  112. // Action
  113. $form->addElement('hidden', 'action');
  114. // Groups per user
  115. $group = array ();
  116. $group[] = & $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'));
  117. $possible_values = array ();
  118. for ($i = 1; $i <= 10; $i ++)
  119. {
  120. $possible_values[$i] = $i;
  121. }
  122. $possible_values[GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All');
  123. $group[] = & $form->createElement('select', 'groups_per_user', null, $possible_values);
  124. $group[] = & $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber'));
  125. $form->addGroup($group, 'limit_group', get_lang('GroupLimit'), ' ', false);
  126. $form->addRule('limit_group',get_lang('MaxGroupsPerUserInvalid'),'callback','check_groups_per_user');
  127. // Default settings for new groups
  128. $form->addElement('header', null, get_lang('DefaultSettingsForNewGroups'));
  129. // Members per group
  130. $form->addElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'),MEMBER_PER_GROUP_NO_LIMIT);
  131. $group = array ();
  132. $group[] = & $form->createElement('radio', 'max_member_no_limit',null,get_lang('Max'),1);
  133. $group[] = & $form->createElement('text', 'max_member', null, array ('size' => 2));
  134. $group[] = & $form->createElement('static', null, null, get_lang('GroupPlacesThis'));
  135. $form->addGroup($group, 'max_member_group', null, '',false);
  136. $form->addRule('max_member_group',get_lang('InvalidMaxNumberOfMembers'),'callback','check_max_number_of_members');
  137. // Self registration
  138. $form->addElement('checkbox', 'self_reg_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1);
  139. $form->addElement('checkbox', 'self_unreg_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1);
  140. // Documents settings
  141. $form->addElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  142. $form->addElement('radio', 'doc_state', null, get_lang('Public'), TOOL_PUBLIC);
  143. $form->addElement('radio', 'doc_state', null, get_lang('Private'), TOOL_PRIVATE);
  144. // Work settings
  145. $form->addElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  146. $form->addElement('radio', 'work_state', null, get_lang('Public'), TOOL_PUBLIC);
  147. $form->addElement('radio', 'work_state', null, get_lang('Private'), TOOL_PRIVATE);
  148. // Calendar settings
  149. $form->addElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  150. $form->addElement('radio', 'calendar_state', null, get_lang('Public'), TOOL_PUBLIC);
  151. $form->addElement('radio', 'calendar_state', null, get_lang('Private'), TOOL_PRIVATE);
  152. // Announcements settings
  153. $form->addElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  154. $form->addElement('radio', 'announcements_state', null, get_lang('Public'), TOOL_PUBLIC);
  155. $form->addElement('radio', 'announcements_state', null, get_lang('Private'), TOOL_PRIVATE);
  156. //Forum settings
  157. $form->addElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  158. $form->addElement('radio', 'forum_state', null, get_lang('Public'), TOOL_PUBLIC);
  159. $form->addElement('radio', 'forum_state', null, get_lang('Private'), TOOL_PRIVATE);
  160. // Submit
  161. $form->addElement('submit', 'submit', get_lang('Ok'));
  162. // If form validates -> save data
  163. if ($form->validate())
  164. {
  165. $values = $form->exportValues();
  166. if ($values['max_member_no_limit'] == MEMBER_PER_GROUP_NO_LIMIT)
  167. {
  168. $max_member = MEMBER_PER_GROUP_NO_LIMIT;
  169. }
  170. else
  171. {
  172. $max_member = $values['max_member'];
  173. }
  174. $self_reg_allowed = isset ($values['self_reg_allowed']) ? $values['self_reg_allowed'] : 0;
  175. $self_unreg_allowed = isset ($values['self_unreg_allowed']) ? $values['self_unreg_allowed'] : 0;
  176. switch ($values['action'])
  177. {
  178. case 'update_settings' :
  179. GroupManager :: update_category($values['id'], $values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $values['forum_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']);
  180. $msg = urlencode(get_lang("GroupPropertiesModified"));
  181. header('Location: group.php?action=show_msg&msg='.$msg.'&category='.$values['id']);
  182. break;
  183. case 'add_category' :
  184. GroupManager :: create_category($values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $values['forum_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']);
  185. $msg = urlencode(get_lang("CategoryCreated"));
  186. header('Location: group.php?action=show_msg&msg='.$msg);
  187. break;
  188. }
  189. }
  190. // Else display the form
  191. Display :: display_header($nameTools, "Group");
  192. api_display_tool_title($nameTools);
  193. $defaults = $category;
  194. $defaults['action'] = $action;
  195. if( $defaults['max_student'] == MEMBER_PER_GROUP_NO_LIMIT)
  196. {
  197. $defaults['max_member_no_limit'] = MEMBER_PER_GROUP_NO_LIMIT;
  198. }
  199. else
  200. {
  201. $defaults['max_member_no_limit'] = 1;
  202. $defaults['max_member'] = $defaults['max_student'];
  203. }
  204. $form->setDefaults($defaults);
  205. $form->display();
  206. Display :: display_footer();
  207. ?>