group.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. /*
  3. ===============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004 Dokeos S.A.
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) Roan Embrechts (Vrije Universiteit Brussel)
  9. Copyright (c) Bart Mollet
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact: Dokeos, 181 rue Royale, B-1000 Brussels, Belgium, info@dokeos.com
  18. ===============================================================================
  19. */
  20. /**
  21. ==============================================================================
  22. * Main page for the group module.
  23. * This script displays the general group settings,
  24. * and a list of groups with buttons to view, edit...
  25. *
  26. * @author Thomas Depraetere, Hugues Peeters, Christophe Gesche: initial versions
  27. * @author Bert Vanderkimpen, improved self-unsubscribe for cvs
  28. * @author Patrick Cool, show group comment under the group name
  29. * @author Roan Embrechts, initial self-unsubscribe code, code cleaning, virtual course support
  30. * @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
  31. * @package dokeos.group
  32. ==============================================================================
  33. */
  34. /*
  35. ==============================================================================
  36. INIT SECTION
  37. ==============================================================================
  38. */
  39. $langFile = "group";
  40. include ('../inc/global.inc.php');
  41. $this_section=SECTION_COURSES;
  42. $nameTools = get_lang("GroupManagement");
  43. /*
  44. -----------------------------------------------------------
  45. Libraries
  46. -----------------------------------------------------------
  47. */
  48. include_once (api_get_path(LIBRARY_PATH).'course.lib.php'); //necessary
  49. include_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  50. include_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php'); //necessary for statistics
  51. //Create default category if it doesn't exist when group categories aren't allowed
  52. if( api_get_setting('allow_group_categories') == 'false')
  53. {
  54. $cat_table = Database::get_course_table(GROUP_CATEGORY_TABLE);
  55. $sql = "SELECT * FROM $cat_table WHERE id = '".DEFAULT_GROUP_CATEGORY."'";
  56. $res = api_sql_query($sql,__FILE__,__LINE__);
  57. $num = mysql_num_rows($res);
  58. if($num == 0)
  59. {
  60. api_sql_query("INSERT INTO ".$cat_table." ( id , title , description , forum_state , max_student , self_reg_allowed , self_unreg_allowed , groups_per_user , display_order ) VALUES ('2', '".lang2db($DefaultGroupCategory)."', '', '1', '8', '0', '0', '0', '0');");
  61. }
  62. }
  63. /*
  64. -----------------------------------------------------------
  65. Header
  66. -----------------------------------------------------------
  67. */
  68. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath')
  69. { //so we are not in learnpath tool
  70. Display::display_header($nameTools,"Group");
  71. event_access_tool(TOOL_GROUP);
  72. //api_display_tool_title($nameTools);
  73. if (! $is_allowed_in_course) api_not_allowed();
  74. }
  75. else
  76. {
  77. ?> <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH); ?>css/default.css" /> <?php
  78. }
  79. /*
  80. -----------------------------------------------------------
  81. Introduction section
  82. (editable by course admins)
  83. -----------------------------------------------------------
  84. */
  85. Display::display_introduction_section(TOOL_GROUP);
  86. /*
  87. * Self-registration and unregistration
  88. */
  89. if (isset ($_GET['action']))
  90. {
  91. switch ($_GET['action'])
  92. {
  93. case 'self_reg' :
  94. if (GroupManager :: is_self_registration_allowed($_SESSION['_uid'], $_GET['group_id']))
  95. {
  96. GroupManager :: subscribe_users($_SESSION['_uid'], $_GET['group_id']);
  97. Display :: display_normal_message(get_lang('GroupNowMember'));
  98. }
  99. break;
  100. case 'self_unreg' :
  101. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_uid'], $_GET['group_id']))
  102. {
  103. GroupManager :: unsubscribe_users($_SESSION['_uid'], $_GET['group_id']);
  104. Display :: display_normal_message(get_lang('StudentDeletesHimself'));
  105. }
  106. break;
  107. case 'show_msg' :
  108. Display :: display_normal_message($_GET['msg']);
  109. break;
  110. }
  111. }
  112. /*
  113. * Group-admin functions
  114. */
  115. if (api_is_allowed_to_edit())
  116. {
  117. // Post-actions
  118. if (isset ($_POST['action']))
  119. {
  120. switch ($_POST['action'])
  121. {
  122. case 'delete_selected' :
  123. if( is_array($_POST['group']))
  124. {
  125. GroupManager :: delete_groups($_POST['group']);
  126. Display :: display_normal_message(get_lang("SelectedGroupsDeleted"));
  127. }
  128. break;
  129. case 'empty_selected' :
  130. if( is_array($_POST['group']))
  131. {
  132. GroupManager :: unsubscribe_all_users($_POST['group']);
  133. Display :: display_normal_message(get_lang("SelectedGroupsEmptied"));
  134. }
  135. break;
  136. case 'fill_selected' :
  137. if( is_array($_POST['group']))
  138. {
  139. GroupManager :: fill_groups($_POST['group']);
  140. Display :: display_normal_message(get_lang("SelectedGroupsFilled"));
  141. }
  142. break;
  143. }
  144. }
  145. // Get-actions
  146. if (isset ($_GET['action']))
  147. {
  148. switch ($_GET['action'])
  149. {
  150. case 'swap_cat_order' :
  151. GroupManager :: swap_category_order($_GET['id1'], $_GET['id2']);
  152. Display :: display_normal_message(get_lang("CategoryOrderChanged"));
  153. break;
  154. case 'delete_one' :
  155. GroupManager :: delete_groups($_GET['id']);
  156. Display :: display_normal_message(get_lang("GroupDel"));
  157. break;
  158. case 'empty_one' :
  159. GroupManager :: unsubscribe_all_users($_GET['id']);
  160. Display :: display_normal_message(get_lang("GroupEmptied"));
  161. break;
  162. case 'fill_one' :
  163. GroupManager :: fill_groups($_GET['id']);
  164. Display :: display_normal_message(get_lang("GroupFilledGroups"));
  165. break;
  166. case 'delete_category' :
  167. GroupManager :: delete_category($_GET['id']);
  168. Display :: display_normal_message(get_lang('CategoryDeleted'));
  169. break;
  170. }
  171. }
  172. // Show admin-panel
  173. echo '<ul>';
  174. echo '<li><a href="group_creation.php">'.get_lang("NewGroupCreate").'</a></li>';
  175. if (get_setting('allow_group_categories') == 'true')
  176. {
  177. echo '<li><a href="group_category.php?action=add_category">'.get_lang("AddCategory").'</a></li>';
  178. }
  179. else
  180. {
  181. echo '<li><a href="group_category.php?id=2">'.get_lang('PropModify').'</a></li>';
  182. }
  183. if( Database::count_rows(Database::get_course_table(GROUP_TABLE)) > 0)
  184. {
  185. echo '<li><a href="group_overview.php">'.get_lang('GroupOverview').'</a></li>';
  186. }
  187. echo '</ul>';
  188. }
  189. $group_cats = GroupManager :: get_categories();
  190. if (get_setting('allow_group_categories') == 'true' && count($group_cats) > 1)
  191. {
  192. echo '<p><a href="?show_all=1">'.get_lang('ShowAll').'</a></p>';
  193. }
  194. /*
  195. * List all categories
  196. */
  197. foreach ($group_cats as $index => $category)
  198. {
  199. $group_list = array ();
  200. $in_category = false;
  201. if (get_setting('allow_group_categories') == 'true')
  202. {
  203. if (isset ($_GET['show_all']) || (isset ($_GET['category']) && $_GET['category'] == $category['id']))
  204. {
  205. echo '<img src="../img/opendir.gif" alt=""/>';
  206. echo ' <a href="group.php?origin='.$_GET['origin'].'">'.$category['title'].'</a>';
  207. $in_category = true;
  208. }
  209. else
  210. {
  211. echo '<img src="../img/file.gif" alt=""/>';
  212. echo ' <a href="group.php?origin='.$_GET['origin'].'&amp;category='.$category['id'].'">'.$category['title'].'</a>';
  213. }
  214. $group_list = GroupManager :: get_group_list($category['id']);
  215. echo ' ('.count($group_list).' '.get_lang("ExistingGroups").')';
  216. if (api_is_allowed_to_edit())
  217. {
  218. echo '<a href="group_category.php?id='.$category['id'].'" title="'.get_lang('Edit').'"><img src="../img/edit.gif" alt="'.get_lang('Edit').'"/></a> ';
  219. echo '<a href="group.php?action=delete_category&amp;id='.$category['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;" title="'.get_lang('Delete').'"><img src="../img/delete.gif" alt="'.get_lang('Delete').'"/></a> ';
  220. if ($index != 0)
  221. {
  222. echo ' <a href="group.php?action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index -1]['id'].'"><img src="../img/up.gif" alt=""/></a>';
  223. }
  224. if ($index != count($group_cats) - 1)
  225. {
  226. echo ' <a href="group.php?action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'"><img src="../img/down.gif" alt=""/></a>';
  227. }
  228. }
  229. echo '<p style="margin: 0px;margin-left: 50px;">'.$category['description'].'</p>';
  230. }
  231. else
  232. {
  233. $group_list = GroupManager :: get_group_list();
  234. $in_category = true;
  235. }
  236. echo '<div style="margin: 0px;margin-left: 50px;">';
  237. if (count($group_list) > 0 && $in_category)
  238. {
  239. $totalRegistered = 0;
  240. // Determine wether current user is tutor for this course
  241. $user_is_tutor = GroupManager :: is_tutor($_uid);
  242. $group_data = array ();
  243. foreach ($group_list as $index => $this_group)
  244. {
  245. // all the tutors of this group
  246. $tutorsids_of_group=GroupManager::get_subscribed_tutors($this_group['id'],true);
  247. // create a new table-row
  248. $row = array ();
  249. // checkbox
  250. if (api_is_allowed_to_edit() && count($group_list) > 1)
  251. {
  252. $row[] = $this_group['id'];
  253. }
  254. // group name
  255. if (api_is_allowed_to_edit() || in_array($_uid,$tutorsids_of_group) || $this_group['is_member'] || GroupManager::user_has_access($_uid,$this_group['id'],GROUP_TOOL_FORUM) || GroupManager::user_has_access($_uid,$this_group['id'],GROUP_TOOL_DOCUMENTS))
  256. {
  257. $group_name = '<a href="group_space.php?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;gidReq='.$this_group['id'].'">'.$this_group['name'].'</a>';
  258. if ($_SESSION['_uid'] && $_SESSION['_uid'] == $this_group['id_tutor'])
  259. {
  260. $group_name .= ' ('.get_lang('OneMyGroups').')';
  261. }
  262. elseif ($this_group['is_member'])
  263. {
  264. $group_name .= ' ('.get_lang("MyGroup").')';
  265. }
  266. $row[] = $group_name.'<br/>'.trim($this_group['description']);
  267. }
  268. else
  269. {
  270. $row[] = $this_group['name'].'<br/>'.trim($this_group['description']);
  271. }
  272. // self-registration / unregistration
  273. if (!api_is_allowed_to_edit())
  274. {
  275. if (GroupManager :: is_self_registration_allowed($_uid, $this_group['id']))
  276. {
  277. $row[] = '<a href="group.php?category='.$category['id'].'&amp;action=self_reg&amp;group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;">'.get_lang("GroupSelfRegInf").'</a>';
  278. }
  279. elseif (GroupManager :: is_self_unregistration_allowed($_uid, $this_group['id']))
  280. {
  281. $row[] = '<a href="group.php?category='.$category['id'].'&amp;action=self_unreg&amp;group_id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;">'.get_lang("GroupSelfUnRegInf").'</a>';
  282. }
  283. else
  284. {
  285. $row[] = '-';
  286. }
  287. }
  288. // number of members in group
  289. $row[] = $this_group['number_of_members'];
  290. // max number of members in group
  291. $row[] = ($this_group['maximum_number_of_members'] == MEMBER_PER_GROUP_NO_LIMIT ? '-' : $this_group['maximum_number_of_members']);
  292. // tutor name
  293. $tutor_info = '';
  294. if($this_group['id_tutor'] != 0)
  295. {
  296. $tutor = api_get_user_info($this_group['id_tutor']);
  297. $tutor_info = Display::encrypted_mailto_link($tutor['mail'],$tutor['firstName'].' '.$tutor['lastName']);
  298. }
  299. $row[] = $tutor_info;
  300. // edit-links
  301. if (api_is_allowed_to_edit())
  302. {
  303. $edit_actions = '<a href="group_edit.php?gidReq='.$this_group['id'].'" title="'.get_lang('Edit').'"><img src="../img/edit.gif" alt="'.get_lang("Edit").'"/></a>';
  304. $edit_actions .= '<a href="'.$_SERVER['PHP_SELF'].'?category='.$category['id'].'&amp;action=delete_one&amp;id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;" title="'.get_lang('Delete').'"><img src="../img/delete.gif" alt="'.get_lang("Delete").'"/></a>';
  305. $edit_actions .= '<a href="'.$_SERVER['PHP_SELF'].'?category='.$category['id'].'&amp;action=empty_one&amp;id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;" title="'.get_lang('EmptyGroup').'"><img src="../img/deluser.gif" alt="'.get_lang("EmptyGroup").'"/></a>';
  306. $edit_actions .= '<a href="'.$_SERVER['PHP_SELF'].'?category='.$category['id'].'&amp;action=fill_one&amp;id='.$this_group['id'].'" onclick="javascript:if(!confirm('."'".addslashes(htmlentities(get_lang("ConfirmYourChoice")))."'".')) return false;" title="'.get_lang('FillGroup').'"><img src="../img/adduser.gif" alt="'.get_lang("FillGroup").'"/></a>';
  307. $row[] = $edit_actions;
  308. }
  309. $totalRegistered = $totalRegistered + $this_group[nbMember];
  310. $group_data[] = $row;
  311. } // while loop
  312. if (isset ($_GET['show_all']))
  313. {
  314. $paging_options = array ('per_page' => count($group_data));
  315. }
  316. else
  317. {
  318. $paging_options = array ();
  319. }
  320. $table = new SortableTableFromArray($group_data);
  321. $table->set_additional_parameters(array('category'=>$_GET['category']));
  322. $column = 0;
  323. if (api_is_allowed_to_edit() and count($group_list) > 1)
  324. {
  325. $table->set_header($column++,'', false);
  326. }
  327. $table->set_header($column++,get_lang("ExistingGroups"));
  328. if (!api_is_allowed_to_edit()) // If self-registration allowed
  329. {
  330. $table->set_header($column++,get_lang("GroupSelfRegistration"));
  331. }
  332. $table->set_header($column++,get_lang("Registered"));
  333. $table->set_header($column++,get_lang("Max"));
  334. $table->set_header($column++,get_lang('GroupTutor'));
  335. if (api_is_allowed_to_edit()) // only for course administrator
  336. {
  337. $table->set_header($column++,get_lang("Modify"), false);
  338. $form_actions = array();
  339. $form_actions['delete_selected'] = get_lang('Delete');
  340. $form_actions['fill_selected'] = get_lang('FillGroup');
  341. $form_actions['empty_selected'] = get_lang('EmptyGroup');
  342. if (count($group_list) > 1)
  343. {
  344. $table->set_form_actions($form_actions,'group');
  345. }
  346. }
  347. $table->display();
  348. }
  349. elseif ($in_category)
  350. {
  351. echo get_lang('NoGroupsAvailable');
  352. }
  353. echo '</div>';
  354. }
  355. /*
  356. ==============================================================================
  357. FOOTER
  358. ==============================================================================
  359. */
  360. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath')
  361. {
  362. Display::display_footer();
  363. }
  364. ?>