group_category.php 11 KB

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