group_category.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <?php
  2. // $Id: group_category.php 9246 2006-09-25 13:24:53Z bmol $
  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. $langFile = "group";
  32. require_once ('../inc/global.inc.php');
  33. $this_section = SECTION_COURSES;
  34. require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  35. require_once (api_get_path(LIBRARY_PATH).'debug.lib.inc.php');
  36. require_once (api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  37. if (!api_is_allowed_to_edit() || !(isset ($_GET['id']) || isset ($_POST['id']) || isset ($_GET['action']) || isset ($_POST['action'])))
  38. {
  39. api_not_allowed();
  40. }
  41. /**
  42. * Function to check the given max number of members per group
  43. */
  44. function check_max_number_of_members($value)
  45. {
  46. $max_member_no_limit = $value['max_member_no_limit'];
  47. if( $max_member_no_limit == MEMBER_PER_GROUP_NO_LIMIT)
  48. {
  49. return true;
  50. }
  51. $max_member = $value['max_member'];
  52. return is_numeric($max_member);
  53. }
  54. /**
  55. * Function to check the number of groups per user
  56. */
  57. function check_groups_per_user($value)
  58. {
  59. $groups_per_user = $value['groups_per_user'];
  60. 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))
  61. {
  62. return false;
  63. }
  64. return true;
  65. }
  66. if (get_setting('allow_group_categories') == 'true')
  67. {
  68. if (isset ($_GET['id']))
  69. {
  70. $category = GroupManager :: get_category($_GET['id']);
  71. $nameTools = get_lang('Edit').' '.$category['title'];
  72. }
  73. else
  74. {
  75. $nameTools = get_lang('AddCategory');
  76. // default values for new category
  77. $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);
  78. }
  79. }
  80. else
  81. {
  82. $category = GroupManager :: get_category($_GET['id']);
  83. $nameTools = get_lang('PropModify');
  84. }
  85. $interbreadcrumb[] = array ("url" => "group.php", "name" => get_lang('GroupManagement'));
  86. // Build the form
  87. if (isset ($_GET['id']))
  88. {
  89. // Update settings of existing category
  90. $action = 'update_settings';
  91. $form = new FormValidator('group_category', 'post', '?id='.$category['id']);
  92. $form->addElement('hidden', 'id');
  93. }
  94. else
  95. {
  96. // Create a new category
  97. $action = 'add_category';
  98. $form = new FormValidator('group_category');
  99. }
  100. // If categories allowed, show title & description field
  101. if (get_setting('allow_group_categories') == 'true')
  102. {
  103. $form->add_textfield('title', get_lang('Title'));
  104. $form->addElement('textarea', 'description', get_lang('Description'),array('cols'=>50,'rows'=>6));
  105. }
  106. else
  107. {
  108. $form->addElement('hidden','title');
  109. $form->addElement('hidden','description');
  110. }
  111. // Action
  112. $form->addElement('hidden', 'action');
  113. // Groups per user
  114. $group = array ();
  115. $group[] = & $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'));
  116. $possible_values = array ();
  117. for ($i = 1; $i <= 10; $i ++)
  118. {
  119. $possible_values[$i] = $i;
  120. }
  121. $possible_values[GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All');
  122. $group[] = & $form->createElement('select', 'groups_per_user', null, $possible_values);
  123. $group[] = & $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber'));
  124. $form->addGroup($group, 'limit_group', get_lang('GroupLimit'), ' ', false);
  125. $form->addRule('limit_group',get_lang('MaxGroupsPerUserInvalid'),'callback','check_groups_per_user');
  126. // Default settings for new groups
  127. $form->addElement('header', null, get_lang('DefaultSettingsForNewGroups'));
  128. // Members per group
  129. $form->addElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'),MEMBER_PER_GROUP_NO_LIMIT);
  130. $group = array ();
  131. $group[] = & $form->createElement('radio', 'max_member_no_limit',null,get_lang('Max'),1);
  132. $group[] = & $form->createElement('text', 'max_member', null, array ('size' => 2));
  133. $group[] = & $form->createElement('static', null, null, get_lang('GroupPlacesThis'));
  134. $form->addGroup($group, 'max_member_group', null, '',false);
  135. $form->addRule('max_member_group',get_lang('InvalidMaxNumberOfMembers'),'callback','check_max_number_of_members');
  136. // Self registration
  137. $form->addElement('checkbox', 'self_registration_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1);
  138. $form->addElement('checkbox', 'self_unregistration_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1);
  139. // Forum settings
  140. //$form->addElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  141. //$form->addElement('radio', 'forum_state', null, get_lang('Public'), TOOL_PUBLIC);
  142. //$form->addElement('radio', 'forum_state', null, get_lang('Private'), TOOL_PRIVATE);
  143. // Documents settings
  144. $form->addElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  145. $form->addElement('radio', 'doc_state', null, get_lang('Public'), TOOL_PUBLIC);
  146. $form->addElement('radio', 'doc_state', null, get_lang('Private'), TOOL_PRIVATE);
  147. // Work settings
  148. $form->addElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  149. $form->addElement('radio', 'work_state', null, get_lang('Public'), TOOL_PUBLIC);
  150. $form->addElement('radio', 'work_state', null, get_lang('Private'), TOOL_PRIVATE);
  151. // Calendar settings
  152. $form->addElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  153. $form->addElement('radio', 'calendar_state', null, get_lang('Public'), TOOL_PUBLIC);
  154. $form->addElement('radio', 'calendar_state', null, get_lang('Private'), TOOL_PRIVATE);
  155. // Announcements settings
  156. $form->addElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  157. $form->addElement('radio', 'announcements_state', null, get_lang('Public'), TOOL_PUBLIC);
  158. $form->addElement('radio', 'announcements_state', null, get_lang('Private'), TOOL_PRIVATE);
  159. // Submit
  160. $form->addElement('submit', 'submit', get_lang('Ok'));
  161. // If form validates -> save data
  162. if ($form->validate())
  163. {
  164. $values = $form->exportValues();
  165. if ($values['max_member_no_limit'] == MEMBER_PER_GROUP_NO_LIMIT)
  166. {
  167. $max_member = MEMBER_PER_GROUP_NO_LIMIT;
  168. }
  169. else
  170. {
  171. $max_member = $values['max_member'];
  172. }
  173. $self_reg_allowed = isset ($values['self_registration_allowed']) ? $values['self_registration_allowed'] : 0;
  174. $self_unreg_allowed = isset ($values['self_unregistration_allowed']) ? $values['self_unregistration_allowed'] : 0;
  175. switch ($values['action'])
  176. {
  177. case 'update_settings' :
  178. GroupManager :: update_category($values['id'], $values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']);
  179. $msg = urlencode(get_lang("GroupPropertiesModified"));
  180. header('Location: group.php?action=show_msg&msg='.$msg.'&category='.$values['id']);
  181. break;
  182. case 'add_category' :
  183. GroupManager :: create_category($values['title'], $values['description'], $values['doc_state'], $values['work_state'], $values['calendar_state'], $values['announcements_state'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']);
  184. $msg = urlencode(get_lang("CategoryCreated"));
  185. header('Location: group.php?action=show_msg&msg='.$msg);
  186. break;
  187. }
  188. }
  189. // Else display the form
  190. Display :: display_header($nameTools, "Group");
  191. api_display_tool_title($nameTools);
  192. $defaults = $category;
  193. $defaults['action'] = $action;
  194. if( $defaults['max_student'] == MEMBER_PER_GROUP_NO_LIMIT)
  195. {
  196. $defaults['max_member_no_limit'] = MEMBER_PER_GROUP_NO_LIMIT;
  197. }
  198. else
  199. {
  200. $defaults['max_member_no_limit'] = 1;
  201. $defaults['max_member'] = $defaults['max_student'];
  202. }
  203. $form->setDefaults($defaults);
  204. $form->display();
  205. Display :: display_footer();
  206. ?>