group.php 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <?php // $Id: group.php 22201 2009-07-17 19:57:03Z cfasanando $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2004-2008 Dokeos SPRL
  6. Copyright (c) 2003 Ghent University (UGent)
  7. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: 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. * @author Isaac Flores, code cleaning and improvements
  32. * @package dokeos.group
  33. ==============================================================================
  34. */
  35. /*
  36. ==============================================================================
  37. INIT SECTION
  38. ==============================================================================
  39. */
  40. // name of the language file that needs to be included
  41. $language_file = 'group';
  42. require_once '../inc/global.inc.php';
  43. $this_section=SECTION_COURSES;
  44. // notice for unauthorized people.
  45. api_protect_course_script(true);
  46. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
  47. $htmlHeadXtra[] = '<script type="text/javascript">
  48. $(document).ready( function() {
  49. for (i=0;i<$(".actions").length;i++) {
  50. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
  51. $(".actions:eq("+i+")").hide();
  52. }
  53. }
  54. } );
  55. </script>';
  56. $nameTools = get_lang('GroupManagement');
  57. /*
  58. -----------------------------------------------------------
  59. Libraries
  60. -----------------------------------------------------------
  61. */
  62. require_once (api_get_path(LIBRARY_PATH).'course.lib.php');
  63. require_once (api_get_path(LIBRARY_PATH).'groupmanager.lib.php');
  64. //Create default category if it doesn't exist when group categories aren't allowed
  65. if( api_get_setting('allow_group_categories') == 'false')
  66. {
  67. $cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY);
  68. $sql = "SELECT * FROM $cat_table WHERE id = '".DEFAULT_GROUP_CATEGORY."'";
  69. $res = Database::query($sql,__FILE__,__LINE__);
  70. $num = Database::num_rows($res);
  71. if($num == 0)
  72. {
  73. Database::query("INSERT INTO ".$cat_table." ( id , title , description , forum_state , wiki_state, max_student , self_reg_allowed , self_unreg_allowed , groups_per_user , display_order ) VALUES ('2', '".lang2db($DefaultGroupCategory)."', '', '1', '1', '8', '0', '0', '0', '0');");
  74. }
  75. }
  76. /*
  77. -----------------------------------------------------------
  78. Header
  79. -----------------------------------------------------------
  80. */
  81. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath')
  82. { //so we are not in learnpath tool
  83. event_access_tool(TOOL_GROUP);
  84. if (! $is_allowed_in_course) api_not_allowed(true);
  85. }
  86. Display::display_header(get_lang('Groups'));
  87. // Tool introduction
  88. Display::display_introduction_section(TOOL_GROUP);
  89. /*
  90. * Self-registration and unregistration
  91. */
  92. $my_group_id = Security::remove_XSS($_GET['group_id']);
  93. $my_msg = Security::remove_XSS($_GET['msg']);
  94. $my_group = $_POST['group'];
  95. $my_get_id1 = Security::remove_XSS($_GET['id1']);
  96. $my_get_id2 = Security::remove_XSS($_GET['id2']);
  97. $my_get_id = Security::remove_XSS($_GET['id']);
  98. if (isset ($_GET['action']))
  99. {
  100. switch ($_GET['action'])
  101. {
  102. case 'self_reg' :
  103. if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $my_group_id))
  104. {
  105. GroupManager :: subscribe_users($_SESSION['_user']['user_id'],$my_group_id);
  106. Display :: display_confirmation_message(get_lang('GroupNowMember'));
  107. }
  108. break;
  109. case 'self_unreg' :
  110. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $my_group_id))
  111. {
  112. GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'],$my_group_id);
  113. Display :: display_confirmation_message(get_lang('StudentDeletesHimself'));
  114. }
  115. break;
  116. case 'show_msg' :
  117. Display :: display_confirmation_message($my_msg);
  118. break;
  119. }
  120. }
  121. /*
  122. * Group-admin functions
  123. */
  124. if (api_is_allowed_to_edit(false,true))
  125. {
  126. // Post-actions
  127. if (isset ($_POST['action']))
  128. {
  129. switch ($_POST['action'])
  130. {
  131. case 'delete_selected' :
  132. if( is_array($_POST['group']))
  133. {
  134. GroupManager :: delete_groups($my_group);
  135. Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted'));
  136. }
  137. break;
  138. case 'empty_selected' :
  139. if( is_array($_POST['group']))
  140. {
  141. GroupManager :: unsubscribe_all_users($my_group);
  142. Display :: display_confirmation_message(get_lang('SelectedGroupsEmptied'));
  143. }
  144. break;
  145. case 'fill_selected' :
  146. if( is_array($_POST['group']))
  147. {
  148. GroupManager :: fill_groups($my_group);
  149. Display :: display_confirmation_message(get_lang('SelectedGroupsFilled'));
  150. }
  151. break;
  152. }
  153. }
  154. // Get-actions
  155. if (isset ($_GET['action']))
  156. {
  157. switch ($_GET['action'])
  158. {
  159. case 'swap_cat_order' :
  160. GroupManager :: swap_category_order($my_get_id1,$my_get_id2);
  161. Display :: display_confirmation_message(get_lang('CategoryOrderChanged'));
  162. break;
  163. case 'delete_one' :
  164. GroupManager :: delete_groups($my_get_id);
  165. Display :: display_confirmation_message(get_lang('GroupDel'));
  166. break;
  167. case 'empty_one' :
  168. GroupManager :: unsubscribe_all_users($my_get_id);
  169. Display :: display_confirmation_message(get_lang('GroupEmptied'));
  170. break;
  171. case 'fill_one' :
  172. GroupManager :: fill_groups($my_get_id);
  173. Display :: display_confirmation_message(get_lang('GroupFilledGroups'));
  174. break;
  175. case 'delete_category' :
  176. GroupManager :: delete_category($my_get_id);
  177. Display :: display_confirmation_message(get_lang('CategoryDeleted'));
  178. break;
  179. }
  180. }
  181. }
  182. echo '<div class="actions">';
  183. if (api_is_allowed_to_edit(false,true))
  184. {
  185. echo Display::return_icon('groupadd.gif', get_lang('NewGroupCreate')) . '<a href="group_creation.php?'.api_get_cidreq().'">'.get_lang('NewGroupCreate').'</a>&nbsp;';
  186. if( Database::count_rows(Database::get_course_table(TABLE_GROUP)) > 0) {
  187. //echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group_view.gif').'&nbsp;'.get_lang('GroupOverview').'</a>&nbsp;';
  188. echo Display::return_icon('group.gif', get_lang('GroupOverview')) .'<a href="group_overview.php?'.api_get_cidreq().'">'.get_lang('GroupOverview').'</a>&nbsp;';
  189. }
  190. if (api_get_setting('allow_group_categories') == 'true') {
  191. echo Display::return_icon('folder_new.gif', get_lang('AddCategory')) . '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.get_lang('AddCategory').'</a>&nbsp;';
  192. } else {
  193. //echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('edit_group.gif').'&nbsp;'.get_lang('PropModify').'</a>&nbsp;';
  194. echo Display::return_icon('settings.gif', get_lang('PropModify')) . '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.get_lang('PropModify').'</a>&nbsp;';
  195. }
  196. //echo Display::return_icon('csv.gif', get_lang('ExportAsCSV')).'<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=csv">'.get_lang('ExportAsCSV').'</a> ';
  197. echo Display::return_icon('excel.gif', get_lang('ExportAsXLS')).' <a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.get_lang('ExportAsXLS').'</a>';
  198. //echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('group_add_big.gif').'&nbsp;'.get_lang('NewGroupCreate').'</a>&nbsp;';
  199. }
  200. $group_cats = GroupManager :: get_categories();
  201. if (api_get_setting('allow_group_categories') == 'true' && count($group_cats) > 1)
  202. {
  203. //echo '<p><a href="?'.api_get_cidreq().'&show_all=1">'.get_lang('ShowAll').'</a></p>';
  204. echo Display::return_icon('group.gif').' <a href="?'.api_get_cidreq().'&show_all=1">'.get_lang('ShowAll').'</a>';
  205. }
  206. echo '</div>';
  207. /*
  208. * List all categories
  209. */
  210. foreach ($group_cats as $index => $category)
  211. {
  212. global $charset;
  213. $group_list = array ();
  214. $in_category = false;
  215. if (api_get_setting('allow_group_categories') == 'true')
  216. {
  217. if (isset ($_GET['show_all']) || (isset ($_GET['category']) && $_GET['category'] == $category['id']))
  218. {
  219. echo '<img src="../img/shared_folder.gif" alt=""/>';
  220. echo ' <a href="group.php?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'">'.$category['title'].'</a>';
  221. $in_category = true;
  222. }
  223. else
  224. {
  225. echo '<img src="../img/folder_document.gif" alt=""/>';
  226. echo ' <a href="group.php?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&amp;category='.$category['id'].'">'.$category['title'].'</a>';
  227. }
  228. $group_list = GroupManager :: get_group_list($category['id']);
  229. echo ' ('.count($group_list).' '.get_lang('ExistingGroups').')';
  230. if (api_is_allowed_to_edit(false,true))
  231. {
  232. 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> ';
  233. echo '<a href="group.php?'.api_get_cidreq().'&action=delete_category&amp;id='.$category['id'].'" onclick="javascript:if(!confirm('."'".addslashes(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;" title="'.get_lang('Delete').'"><img src="../img/delete.gif" alt="'.get_lang('Delete').'"/></a> ';
  234. if ($index != 0)
  235. {
  236. 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>';
  237. }
  238. if ($index != count($group_cats) - 1)
  239. {
  240. 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>';
  241. }
  242. }
  243. echo '<p style="margin: 0px;margin-left: 50px;">'.$category['description'].'</p><p/>';
  244. }
  245. else {
  246. $group_list = GroupManager :: get_group_list();
  247. $in_category = true;
  248. }
  249. //if (count($group_list) > 0 && $in_category)
  250. if ($in_category)
  251. {
  252. $totalRegistered = 0;
  253. // Determine wether current user is tutor for this course
  254. $user_is_tutor = GroupManager :: is_tutor($_user['user_id']);
  255. $group_data = array ();
  256. foreach ($group_list as $index => $this_group) {
  257. //validacion when belongs to a session
  258. $session_img = api_get_session_image($this_group['session_id'], $_user['status']);
  259. // all the tutors of this group
  260. $tutorsids_of_group=GroupManager::get_subscribed_tutors($this_group['id'],true);
  261. // create a new table-row
  262. $row = array ();
  263. // checkbox
  264. if (api_is_allowed_to_edit(false,true) && count($group_list) > 1)
  265. {
  266. $row[] = $this_group['id'];
  267. }
  268. // group name
  269. if ((api_is_allowed_to_edit(false,true) ||
  270. in_array($_user['user_id'],$tutorsids_of_group) ||
  271. $this_group['is_member'] ||
  272. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_FORUM) ||
  273. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_DOCUMENTS) ||
  274. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_CALENDAR) ||
  275. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_ANNOUNCEMENT) ||
  276. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_WORK) ||
  277. GroupManager::user_has_access($_user['user_id'],$this_group['id'],GROUP_TOOL_WIKI))
  278. && !(api_is_course_coach() && intval($this_group['session_id'])!=intval($_SESSION['id_session'])))
  279. {
  280. isset($origin)?$orig=$origin:$orig=null;
  281. $group_name = '<a href="group_space.php?'.api_get_cidreq().'&amp;origin='.$orig.'&amp;gidReq='.$this_group['id'].'">'.stripslashes($this_group['name']).'</a>';
  282. if (!empty($_SESSION['_user']['user_id']) && !empty($this_group['id_tutor']) && $_SESSION['_user']['user_id'] == $this_group['id_tutor'])
  283. {
  284. $group_name .= ' ('.get_lang('OneMyGroups').')';
  285. }
  286. elseif ($this_group['is_member'])
  287. {
  288. $group_name .= ' ('.get_lang('MyGroup').')';
  289. }
  290. if(api_is_allowed_to_edit() && !empty($this_group['session_name']))
  291. {
  292. $group_name .= ' ('.$this_group['session_name'].')';
  293. }
  294. $group_name .= $session_img;
  295. $row[] = $group_name.'<br/>'.stripslashes(trim($this_group['description']));
  296. }
  297. else
  298. {
  299. $row[] = $this_group['name'].'<br/>'.stripslashes(trim($this_group['description']));
  300. }
  301. // self-registration / unregistration
  302. if (!api_is_allowed_to_edit(false,true))
  303. {
  304. if (GroupManager :: is_self_registration_allowed($_user['user_id'], $this_group['id']))
  305. {
  306. $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(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfRegInf').'</a>';
  307. }
  308. elseif (GroupManager :: is_self_unregistration_allowed($_user['user_id'], $this_group['id']))
  309. {
  310. $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(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;">'.get_lang('GroupSelfUnRegInf').'</a>';
  311. }
  312. else
  313. {
  314. $row[] = '-';
  315. }
  316. }
  317. // number of members in group
  318. $row[] = $this_group['number_of_members'];
  319. // max number of members in group
  320. $row[] = ($this_group['maximum_number_of_members'] == MEMBER_PER_GROUP_NO_LIMIT ? '-' : $this_group['maximum_number_of_members']);
  321. // tutor name
  322. $tutor_info = '';
  323. if(count($tutorsids_of_group)>0)
  324. {
  325. foreach($tutorsids_of_group as $tutor_id){
  326. $tutor = api_get_user_info($tutor_id);
  327. if (api_get_setting("show_email_addresses") == "true")
  328. {
  329. $tutor_info .= Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])).', ';
  330. }
  331. else
  332. {
  333. if (api_is_allowed_to_edit()=='true')
  334. {
  335. $tutor_info .= Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])).', ';
  336. }
  337. else
  338. {
  339. $tutor_info .= api_get_person_name($tutor['firstName'], $tutor['lastName']).', ';
  340. }
  341. }
  342. }
  343. }
  344. $tutor_info = api_substr($tutor_info,0,api_strlen($tutor_info)-2);
  345. $row[] = $tutor_info;
  346. // edit-links
  347. if (api_is_allowed_to_edit(false,true) && !(api_is_course_coach() && intval($this_group['session_id'])!=intval($_SESSION['id_session'])))
  348. {
  349. $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;';
  350. $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(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;" title="'.get_lang('Delete').'"><img src="../img/delete.gif" alt="'.get_lang('Delete').'"/></a>&nbsp;';
  351. $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(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;" title="'.get_lang('EmptyGroup').'"><img src="../img/clean_group.gif" alt="'.get_lang('EmptyGroup').'"/></a>&nbsp;';
  352. $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(api_htmlentities(get_lang('ConfirmYourChoice'), ENT_QUOTES, $charset))."'".')) return false;" title="'.get_lang('FillGroup').'"><img src="../img/fill_group.gif" alt="'.get_lang('FillGroup').'"/></a>';
  353. $row[] = $edit_actions;
  354. }
  355. if (!empty($this_group['nbMember'])) {
  356. $totalRegistered = $totalRegistered + $this_group['nbMember'];
  357. }
  358. $group_data[] = $row;
  359. } // while loop
  360. if (isset ($_GET['show_all']))
  361. {
  362. $paging_options = array ('per_page' => count($group_data));
  363. }
  364. else
  365. {
  366. $paging_options = array ();
  367. }
  368. $table = new SortableTableFromArrayConfig($group_data, 1);
  369. isset($_GET['category'])?$my_cat = Security::remove_XSS($_GET['category']): $my_cat = null;
  370. $table->set_additional_parameters(array('category'=>$my_cat));
  371. $column = 0;
  372. if (api_is_allowed_to_edit(false,true) and count($group_list) > 1)
  373. {
  374. $table->set_header($column++,'', false);
  375. }
  376. $table->set_header($column++,get_lang('ExistingGroups'));
  377. if (!api_is_allowed_to_edit(false,true)) // If self-registration allowed
  378. {
  379. $table->set_header($column++,get_lang('GroupSelfRegistration'));
  380. }
  381. $table->set_header($column++,get_lang('Registered'));
  382. $table->set_header($column++,get_lang('Max'));
  383. $table->set_header($column++,get_lang('GroupTutor'));
  384. if (api_is_allowed_to_edit(false,true)) // only for course administrator
  385. {
  386. $table->set_header($column++,get_lang('Modify'), false);
  387. $form_actions = array();
  388. $form_actions['delete_selected'] = get_lang('Delete');
  389. $form_actions['fill_selected'] = get_lang('FillGroup');
  390. $form_actions['empty_selected'] = get_lang('EmptyGroup');
  391. if (count($group_list) > 1)
  392. {
  393. $table->set_form_actions($form_actions,'group');
  394. }
  395. }
  396. $table->display();
  397. }
  398. /*
  399. elseif ($in_category)
  400. {
  401. echo get_lang('NoGroupsAvailable');
  402. }
  403. */
  404. }
  405. /*
  406. ==============================================================================
  407. FOOTER
  408. ==============================================================================
  409. */
  410. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath')
  411. {
  412. Display::display_footer();
  413. }
  414. ?>