group.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <?php
  2. /*
  3. ===============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 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 address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  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. // name of the language file that needs to be included
  40. $language_file = "group";
  41. include ('../inc/global.inc.php');
  42. $this_section=SECTION_COURSES;
  43. // notice for unauthorized people.
  44. api_protect_course_script(true);
  45. $nameTools = get_lang("GroupManagement");
  46. /*
  47. -----------------------------------------------------------
  48. Libraries
  49. -----------------------------------------------------------
  50. */
  51. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  52. require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  53. require_once (api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  54. //Create default category if it doesn't exist when group categories aren't allowed
  55. if( api_get_setting('allow_group_categories') == 'false')
  56. {
  57. $cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY);
  58. $sql = "SELECT * FROM $cat_table WHERE id = '".DEFAULT_GROUP_CATEGORY."'";
  59. $res = api_sql_query($sql,__FILE__,__LINE__);
  60. $num = mysql_num_rows($res);
  61. if($num == 0)
  62. {
  63. 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');");
  64. }
  65. }
  66. /*
  67. -----------------------------------------------------------
  68. Header
  69. -----------------------------------------------------------
  70. */
  71. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath')
  72. { //so we are not in learnpath tool
  73. event_access_tool(TOOL_GROUP);
  74. if (! $is_allowed_in_course) api_not_allowed(true);
  75. }
  76. Display::display_header(get_lang("Groups"));
  77. /*
  78. -----------------------------------------------------------
  79. Introduction section
  80. (editable by course admins)
  81. -----------------------------------------------------------
  82. */
  83. Display::display_introduction_section(TOOL_GROUP);
  84. /*
  85. * Self-registration and unregistration
  86. */
  87. if (isset ($_GET['action']))
  88. {
  89. switch ($_GET['action'])
  90. {
  91. case 'self_reg' :
  92. if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $_GET['group_id']))
  93. {
  94. GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $_GET['group_id']);
  95. Display :: display_normal_message(get_lang('GroupNowMember'));
  96. }
  97. break;
  98. case 'self_unreg' :
  99. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $_GET['group_id']))
  100. {
  101. GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $_GET['group_id']);
  102. Display :: display_normal_message(get_lang('StudentDeletesHimself'));
  103. }
  104. break;
  105. case 'show_msg' :
  106. Display :: display_normal_message($_GET['msg']);
  107. break;
  108. }
  109. }
  110. /*
  111. * Group-admin functions
  112. */
  113. if (api_is_allowed_to_edit())
  114. {
  115. // Post-actions
  116. if (isset ($_POST['action']))
  117. {
  118. switch ($_POST['action'])
  119. {
  120. case 'delete_selected' :
  121. if( is_array($_POST['group']))
  122. {
  123. GroupManager :: delete_groups($_POST['group']);
  124. Display :: display_normal_message(get_lang("SelectedGroupsDeleted"));
  125. }
  126. break;
  127. case 'empty_selected' :
  128. if( is_array($_POST['group']))
  129. {
  130. GroupManager :: unsubscribe_all_users($_POST['group']);
  131. Display :: display_normal_message(get_lang("SelectedGroupsEmptied"));
  132. }
  133. break;
  134. case 'fill_selected' :
  135. if( is_array($_POST['group']))
  136. {
  137. GroupManager :: fill_groups($_POST['group']);
  138. Display :: display_normal_message(get_lang("SelectedGroupsFilled"));
  139. }
  140. break;
  141. }
  142. }
  143. // Get-actions
  144. if (isset ($_GET['action']))
  145. {
  146. switch ($_GET['action'])
  147. {
  148. case 'swap_cat_order' :
  149. GroupManager :: swap_category_order($_GET['id1'], $_GET['id2']);
  150. Display :: display_normal_message(get_lang("CategoryOrderChanged"));
  151. break;
  152. case 'delete_one' :
  153. GroupManager :: delete_groups($_GET['id']);
  154. Display :: display_normal_message(get_lang("GroupDel"));
  155. break;
  156. case 'empty_one' :
  157. GroupManager :: unsubscribe_all_users($_GET['id']);
  158. Display :: display_normal_message(get_lang("GroupEmptied"));
  159. break;
  160. case 'fill_one' :
  161. GroupManager :: fill_groups($_GET['id']);
  162. Display :: display_normal_message(get_lang("GroupFilledGroups"));
  163. break;
  164. case 'delete_category' :
  165. GroupManager :: delete_category($_GET['id']);
  166. Display :: display_normal_message(get_lang('CategoryDeleted'));
  167. break;
  168. }
  169. }
  170. // Show admin-panel
  171. echo "<div id=\"actions\">\n";
  172. echo "<ul id=\"groupItems\">";
  173. if (get_setting('allow_group_categories') == 'true')
  174. {
  175. echo '<li><a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.get_lang("AddCategory").'</a>&nbsp;</li>';
  176. }
  177. else
  178. {
  179. //echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('edit_group.gif').'&nbsp;'.get_lang('PropModify').'</a>&nbsp;';
  180. echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.get_lang('PropModify').'</a>&nbsp;';
  181. }
  182. //echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('group_add_big.gif').'&nbsp;'.get_lang("NewGroupCreate").'</a>&nbsp;';
  183. echo '<li><a href="group_creation.php?'.api_get_cidreq().'">'.get_lang("NewGroupCreate").'</a>&nbsp;</li>';
  184. if( Database::count_rows(Database::get_course_table(TABLE_GROUP)) > 0)
  185. {
  186. //echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group_view.gif').'&nbsp;'.get_lang('GroupOverview').'</a>&nbsp;';
  187. echo '<li><a href="group_overview.php?'.api_get_cidreq().'">'.get_lang('GroupOverview').'</a>&nbsp;</li>';
  188. }
  189. }
  190. $group_cats = GroupManager :: get_categories();
  191. if (get_setting('allow_group_categories') == 'true' && count($group_cats) > 1)
  192. {
  193. //echo '<p><a href="?'.api_get_cidreq().'&show_all=1">'.get_lang('ShowAll').'</a></p>';
  194. echo '<li><a href="?'.api_get_cidreq().'&show_all=1">'.get_lang('ShowAll').'</a></li>';
  195. }
  196. echo "</ul>";
  197. /*
  198. * List all categories
  199. */
  200. foreach ($group_cats as $index => $category)
  201. {
  202. $group_list = array ();
  203. $in_category = false;
  204. if (get_setting('allow_group_categories') == 'true')
  205. {
  206. if (isset ($_GET['show_all']) || (isset ($_GET['category']) && $_GET['category'] == $category['id']))
  207. {
  208. echo '<img src="../img/opendir.gif" alt=""/>';
  209. echo ' <a href="group.php?'.api_get_cidreq().'&origin='.$_GET['origin'].'">'.$category['title'].'</a>';
  210. $in_category = true;
  211. }
  212. else
  213. {
  214. echo '<img src="../img/file.gif" alt=""/>';
  215. echo ' <a href="group.php?'.api_get_cidreq().'&origin='.$_GET['origin'].'&amp;category='.$category['id'].'">'.$category['title'].'</a>';
  216. }
  217. $group_list = GroupManager :: get_group_list($category['id']);
  218. echo ' ('.count($group_list).' '.get_lang("ExistingGroups").')';
  219. if (api_is_allowed_to_edit())
  220. {
  221. echo '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'" title="'.get_lang('Edit').'"><img src="../img/edit.gif" alt="'.get_lang('Edit').'"/></a> ';
  222. echo '<a href="group.php?'.api_get_cidreq().'&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> ';
  223. if ($index != 0)
  224. {
  225. echo ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index -1]['id'].'"><img src="../img/up.gif" alt=""/></a>';
  226. }
  227. if ($index != count($group_cats) - 1)
  228. {
  229. echo ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'"><img src="../img/down.gif" alt=""/></a>';
  230. }
  231. }
  232. echo '<p style="margin: 0px;margin-left: 50px;">'.$category['description'].'</p><p/>';
  233. }
  234. else
  235. {
  236. $group_list = GroupManager :: get_group_list();
  237. $in_category = true;
  238. }
  239. echo '<div style="margin: 0px;margin-left: 50px;">';
  240. //if (count($group_list) > 0 && $in_category)
  241. if ($in_category)
  242. {
  243. $totalRegistered = 0;
  244. // Determine wether current user is tutor for this course
  245. $user_is_tutor = GroupManager :: is_tutor($_user['user_id']);
  246. $group_data = array ();
  247. foreach ($group_list as $index => $this_group)
  248. {
  249. // all the tutors of this group
  250. $tutorsids_of_group=GroupManager::get_subscribed_tutors($this_group['id'],true);
  251. // create a new table-row
  252. $row = array ();
  253. // checkbox
  254. if (api_is_allowed_to_edit() && count($group_list) > 1)
  255. {
  256. $row[] = $this_group['id'];
  257. }
  258. // group name
  259. if (api_is_allowed_to_edit() ||
  260. in_array($_user['user_id'],$tutorsids_of_group) ||
  261. $this_group['is_member'] ||
  262. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_DOCUMENTS) ||
  263. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_CALENDAR) ||
  264. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_ANNOUNCEMENT) ||
  265. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_WORK))
  266. {
  267. $group_name = '<a href="group_space.php?'.api_get_cidreq().'&amp;origin='.$origin.'&amp;gidReq='.$this_group['id'].'">'.stripslashes($this_group['name']).'</a>';
  268. if ($_SESSION['_user']['user_id'] && $_SESSION['_user']['user_id'] == $this_group['id_tutor'])
  269. {
  270. $group_name .= ' ('.get_lang('OneMyGroups').')';
  271. }
  272. elseif ($this_group['is_member'])
  273. {
  274. $group_name .= ' ('.get_lang("MyGroup").')';
  275. }
  276. $row[] = $group_name.'<br/>'.stripslashes(trim($this_group['description']));
  277. }
  278. else
  279. {
  280. $row[] = $this_group['name'].'<br/>'.stripslashes(trim($this_group['description']));
  281. }
  282. // self-registration / unregistration
  283. if (!api_is_allowed_to_edit())
  284. {
  285. if (GroupManager :: is_self_registration_allowed($_user['user_id'], $this_group['id']))
  286. {
  287. $row[] = '<a href="group.php?'.api_get_cidreq().'&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>';
  288. }
  289. elseif (GroupManager :: is_self_unregistration_allowed($_user['user_id'], $this_group['id']))
  290. {
  291. $row[] = '<a href="group.php?'.api_get_cidreq().'&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>';
  292. }
  293. else
  294. {
  295. $row[] = '-';
  296. }
  297. }
  298. // number of members in group
  299. $row[] = $this_group['number_of_members'];
  300. // max number of members in group
  301. $row[] = ($this_group['maximum_number_of_members'] == MEMBER_PER_GROUP_NO_LIMIT ? '-' : $this_group['maximum_number_of_members']);
  302. // tutor name
  303. $tutor_info = '';
  304. if(count($tutorsids_of_group)>0)
  305. {
  306. foreach($tutorsids_of_group as $tutor_id){
  307. $tutor = api_get_user_info($tutor_id);
  308. $tutor_info .= Display::encrypted_mailto_link($tutor['mail'],$tutor['firstName'].' '.$tutor['lastName']).', ';
  309. }
  310. }
  311. $tutor_info = substr($tutor_info,0,strlen($tutor_info)-2);
  312. $row[] = $tutor_info;
  313. // edit-links
  314. if (api_is_allowed_to_edit())
  315. {
  316. $edit_actions = '<a href="group_edit.php?'.api_get_cidreq().'&gidReq='.$this_group['id'].'" title="'.get_lang('Edit').'"><img src="../img/edit.gif" alt="'.get_lang("Edit").'"/></a>&nbsp;';
  317. $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&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>&nbsp;';
  318. $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&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/group_delete.gif" alt="'.get_lang("EmptyGroup").'"/></a>&nbsp;';
  319. $edit_actions .= '<a href="'.api_get_self().'?'.api_get_cidreq().'&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/add_user.gif" alt="'.get_lang("FillGroup").'"/></a>';
  320. $row[] = $edit_actions;
  321. }
  322. $totalRegistered = $totalRegistered + $this_group['nbMember'];
  323. $group_data[] = $row;
  324. } // while loop
  325. if (isset ($_GET['show_all']))
  326. {
  327. $paging_options = array ('per_page' => count($group_data));
  328. }
  329. else
  330. {
  331. $paging_options = array ();
  332. }
  333. $table = new SortableTableFromArray($group_data, 1);
  334. $table->set_additional_parameters(array('category'=>$_GET['category']));
  335. $column = 0;
  336. if (api_is_allowed_to_edit() and count($group_list) > 1)
  337. {
  338. $table->set_header($column++,'', false);
  339. }
  340. $table->set_header($column++,get_lang("ExistingGroups"));
  341. if (!api_is_allowed_to_edit()) // If self-registration allowed
  342. {
  343. $table->set_header($column++,get_lang("GroupSelfRegistration"));
  344. }
  345. $table->set_header($column++,get_lang("Registered"));
  346. $table->set_header($column++,get_lang("Max"));
  347. $table->set_header($column++,get_lang('GroupTutor'));
  348. if (api_is_allowed_to_edit()) // only for course administrator
  349. {
  350. $table->set_header($column++,get_lang("Modify"), false);
  351. $form_actions = array();
  352. $form_actions['delete_selected'] = get_lang('Delete');
  353. $form_actions['fill_selected'] = get_lang('FillGroup');
  354. $form_actions['empty_selected'] = get_lang('EmptyGroup');
  355. if (count($group_list) > 1)
  356. {
  357. $table->set_form_actions($form_actions,'group');
  358. }
  359. }
  360. $table->display();
  361. }
  362. /*
  363. elseif ($in_category)
  364. {
  365. echo get_lang('NoGroupsAvailable');
  366. }
  367. */
  368. echo '</div>';
  369. }
  370. /*
  371. ==============================================================================
  372. FOOTER
  373. ==============================================================================
  374. */
  375. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath')
  376. {
  377. Display::display_footer();
  378. }
  379. ?>