group_category.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <?php
  2. // $Id: group_category.php 20293 2009-05-04 19:28:21Z iflorespaz $
  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(false,true) || !(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('EditGroupCategory').': '.$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, 'wiki_state' => TOOL_PRIVATE, 'calendar_state' => TOOL_PRIVATE, 'announcements_state'=> TOOL_PRIVATE, 'forum_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('Groups'));
  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. //Checks if the field was created in the table Category. It creates it if is neccesary
  98. $table_category = Database :: get_course_table(GROUP_CATEGORY_TABLE);
  99. if (Database::query("SELECT wiki_state FROM $table_category",__FILE__,__LINE__) == FALSE) {
  100. Database::query("ALTER TABLE $table_category ADD `wiki_state` tinyint(3) UNSIGNED NOT NULL default '1';",__FILE__,__LINE__);
  101. }
  102. // Create a new category
  103. $action = 'add_category';
  104. $form = new FormValidator('group_category');
  105. }
  106. $form->addElement('html', '<div class="sectiontitle" >'.$nameTools);
  107. $form->addElement('html', '</div>');
  108. // If categories allowed, show title & description field
  109. if (get_setting('allow_group_categories') == 'true')
  110. {
  111. $form->add_textfield('title', get_lang('Title'));
  112. $form->addElement('textarea', 'description', get_lang('Description'),array('cols'=>50,'rows'=>6));
  113. }
  114. else
  115. {
  116. $form->addElement('hidden','title');
  117. $form->addElement('hidden','description');
  118. }
  119. // Action
  120. $form->addElement('hidden', 'action');
  121. // Groups per user
  122. $group = array ();
  123. $group[] = & $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartBeforeNumber'));
  124. $possible_values = array ();
  125. for ($i = 1; $i <= 10; $i ++)
  126. {
  127. $possible_values[$i] = $i;
  128. }
  129. $possible_values[GROUP_PER_MEMBER_NO_LIMIT] = get_lang('All');
  130. $group[] = & $form->createElement('select', 'groups_per_user', null, $possible_values);
  131. $group[] = & $form->createElement('static', null, null, get_lang('QtyOfUserCanSubscribe_PartAfterNumber'));
  132. $form->addGroup($group, 'limit_group', get_lang('GroupLimit'), ' ', false);
  133. $form->addRule('limit_group',get_lang('MaxGroupsPerUserInvalid'),'callback','check_groups_per_user');
  134. // Default settings for new groups
  135. //$form->addElement('static', null, '<b>'.get_lang('DefaultSettingsForNewGroups').'</b>');
  136. $form->addElement('html', '<br/><br/><div class="sectiontitle" >'.get_lang('DefaultSettingsForNewGroups'));
  137. $form->addElement('html', '</div>');
  138. // Members per group
  139. $form->addElement('radio', 'max_member_no_limit', get_lang('GroupLimit'), get_lang('NoLimit'),MEMBER_PER_GROUP_NO_LIMIT);
  140. $group = array ();
  141. $group[] = & $form->createElement('radio', 'max_member_no_limit',null,get_lang('Max'),1);
  142. $group[] = & $form->createElement('text', 'max_member', null, array ('size' => 2));
  143. $group[] = & $form->createElement('static', null, null, get_lang('GroupPlacesThis'));
  144. $form->addGroup($group, 'max_member_group', null, '',false);
  145. $form->addRule('max_member_group',get_lang('InvalidMaxNumberOfMembers'),'callback','check_max_number_of_members');
  146. // Self registration
  147. $form->addElement('checkbox', 'self_reg_allowed', get_lang('GroupSelfRegistration'), get_lang('GroupAllowStudentRegistration'), 1);
  148. $form->addElement('checkbox', 'self_unreg_allowed', null, get_lang('GroupAllowStudentUnregistration'), 1);
  149. // Documents settings
  150. $form->addElement('radio', 'doc_state', get_lang('GroupDocument'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  151. $form->addElement('radio', 'doc_state', null, get_lang('Public'), TOOL_PUBLIC);
  152. $form->addElement('radio', 'doc_state', null, get_lang('Private'), TOOL_PRIVATE);
  153. // Work settings
  154. $form->addElement('radio', 'work_state', get_lang('GroupWork'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  155. $form->addElement('radio', 'work_state', null, get_lang('Public'), TOOL_PUBLIC);
  156. $form->addElement('radio', 'work_state', null, get_lang('Private'), TOOL_PRIVATE);
  157. // Calendar settings
  158. $form->addElement('radio', 'calendar_state', get_lang('GroupCalendar'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  159. $form->addElement('radio', 'calendar_state', null, get_lang('Public'), TOOL_PUBLIC);
  160. $form->addElement('radio', 'calendar_state', null, get_lang('Private'), TOOL_PRIVATE);
  161. // Announcements settings
  162. $form->addElement('radio', 'announcements_state', get_lang('GroupAnnouncements'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  163. $form->addElement('radio', 'announcements_state', null, get_lang('Public'), TOOL_PUBLIC);
  164. $form->addElement('radio', 'announcements_state', null, get_lang('Private'), TOOL_PRIVATE);
  165. //Forum settings
  166. $form->addElement('radio', 'forum_state', get_lang('GroupForum'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  167. $form->addElement('radio', 'forum_state', null, get_lang('Public'), TOOL_PUBLIC);
  168. $form->addElement('radio', 'forum_state', null, get_lang('Private'), TOOL_PRIVATE);
  169. // Wiki Settings
  170. $form->addElement('radio', 'wiki_state', get_lang('GroupWiki'), get_lang('NotAvailable'), TOOL_NOT_AVAILABLE);
  171. $form->addElement('radio', 'wiki_state', null, get_lang('Public'), TOOL_PUBLIC);
  172. $form->addElement('radio', 'wiki_state', null, get_lang('Private'), TOOL_PRIVATE);
  173. // Submit
  174. $form->addElement('style_submit_button', 'submit', get_lang('PropModify'), 'class="save"');
  175. // If form validates -> save data
  176. if ($form->validate())
  177. {
  178. $values = $form->exportValues();
  179. if ($values['max_member_no_limit'] == MEMBER_PER_GROUP_NO_LIMIT)
  180. {
  181. $max_member = MEMBER_PER_GROUP_NO_LIMIT;
  182. }
  183. else
  184. {
  185. $max_member = $values['max_member'];
  186. }
  187. $self_reg_allowed = isset ($values['self_reg_allowed']) ? $values['self_reg_allowed'] : 0;
  188. $self_unreg_allowed = isset ($values['self_unreg_allowed']) ? $values['self_unreg_allowed'] : 0;
  189. switch ($values['action'])
  190. {
  191. case 'update_settings' :
  192. 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'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']);
  193. $msg = urlencode(get_lang("GroupPropertiesModified"));
  194. header('Location: group.php?action=show_msg&msg='.$msg.'&category='.$values['id']);
  195. break;
  196. case 'add_category' :
  197. 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'], $self_reg_allowed, $self_unreg_allowed, $max_member, $values['groups_per_user']);
  198. $msg = urlencode(get_lang("CategoryCreated"));
  199. header('Location: group.php?action=show_msg&msg='.$msg);
  200. break;
  201. }
  202. }
  203. // Else display the form
  204. Display :: display_header($nameTools, "Group");
  205. $defaults = $category;
  206. $defaults['action'] = $action;
  207. if( $defaults['max_student'] == MEMBER_PER_GROUP_NO_LIMIT)
  208. {
  209. $defaults['max_member_no_limit'] = MEMBER_PER_GROUP_NO_LIMIT;
  210. }
  211. else
  212. {
  213. $defaults['max_member_no_limit'] = 1;
  214. $defaults['max_member'] = $defaults['max_student'];
  215. }
  216. $form->setDefaults($defaults);
  217. $form->display();
  218. Display :: display_footer();
  219. ?>