group.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Main page for the group module.
  5. * This script displays the general group settings,
  6. * and a list of groups with buttons to view, edit...
  7. *
  8. * @author Thomas Depraetere, Hugues Peeters, Christophe Gesche: initial versions
  9. * @author Bert Vanderkimpen, improved self-unsubscribe for cvs
  10. * @author Patrick Cool, show group comment under the group name
  11. * @author Roan Embrechts, initial self-unsubscribe code, code cleaning, virtual course support
  12. * @author Bart Mollet, code cleaning, use of Display-library, list of courseAdmin-tools, use of GroupManager
  13. * @author Isaac Flores, code cleaning and improvements
  14. * @package chamilo.group
  15. */
  16. /* INIT SECTION */
  17. // Name of the language file that needs to be included
  18. $language_file = 'group';
  19. require_once '../inc/global.inc.php';
  20. $this_section = SECTION_COURSES;
  21. // Notice for unauthorized people.
  22. api_protect_course_script(true);
  23. $htmlHeadXtra[] = '<script type="text/javascript">
  24. $(document).ready( function() {
  25. for (i=0;i<$(".actions").length;i++) {
  26. if ($(".actions:eq("+i+")").html()=="<table border=\"0\"></table>" || $(".actions:eq("+i+")").html()=="" || $(".actions:eq("+i+")").html()==null) {
  27. $(".actions:eq("+i+")").hide();
  28. }
  29. }
  30. } );
  31. </script>';
  32. $nameTools = get_lang('GroupManagement');
  33. /* Libraries */
  34. require_once api_get_path(LIBRARY_PATH).'groupmanager.lib.php';
  35. $course_id = api_get_course_int_id();
  36. // Create default category if it doesn't exist when group categories aren't allowed
  37. if (api_get_setting('allow_group_categories') == 'false') {
  38. $cat_table = Database::get_course_table(TABLE_GROUP_CATEGORY);
  39. $sql = "SELECT * FROM $cat_table WHERE c_id = $course_id AND id = '".DEFAULT_GROUP_CATEGORY."'";
  40. $res = Database::query($sql);
  41. $num = Database::num_rows($res);
  42. if ($num == 0) {
  43. $sql = "INSERT INTO ".$cat_table." ( c_id, id , title , description , forum_state, wiki_state, max_student, self_reg_allowed, self_unreg_allowed, groups_per_user, display_order)
  44. VALUES ($course_id, '2', '".lang2db($DefaultGroupCategory)."', '', '1', '1', '8', '0', '0', '0', '0');";
  45. Database::query ($sql);
  46. }
  47. }
  48. /* Header */
  49. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
  50. // So we are not in learnpath tool
  51. event_access_tool(TOOL_GROUP);
  52. if (!$is_allowed_in_course) {
  53. api_not_allowed(true);
  54. }
  55. }
  56. Display::display_header(get_lang('Groups'));
  57. // Tool introduction
  58. Display::display_introduction_section(TOOL_GROUP);
  59. /*
  60. * Self-registration and unregistration
  61. */
  62. $my_group_id = isset($_GET['group_id']) ? intval($_GET['group_id']) : null;
  63. $my_msg = isset($_GET['msg']) ? Security::remove_XSS($_GET['msg']) : null;
  64. $my_group = isset($_GET['group']) ? Security::remove_XSS($_POST['group']) : null;
  65. $my_get_id1 = isset($_GET['id1']) ? Security::remove_XSS($_GET['id1']) : null;
  66. $my_get_id2 = isset($_GET['id2']) ? Security::remove_XSS($_GET['id2']) : null;
  67. $my_get_id = isset($_GET['id']) ? Security::remove_XSS($_GET['id']) : null;
  68. if (isset($_GET['action'])) {
  69. switch ($_GET['action']) {
  70. case 'self_reg' :
  71. if (GroupManager :: is_self_registration_allowed($_SESSION['_user']['user_id'], $my_group_id)) {
  72. GroupManager :: subscribe_users($_SESSION['_user']['user_id'], $my_group_id);
  73. Display :: display_confirmation_message(get_lang('GroupNowMember'));
  74. }
  75. break;
  76. case 'self_unreg' :
  77. if (GroupManager :: is_self_unregistration_allowed($_SESSION['_user']['user_id'], $my_group_id)) {
  78. GroupManager :: unsubscribe_users($_SESSION['_user']['user_id'], $my_group_id);
  79. Display :: display_confirmation_message(get_lang('StudentDeletesHimself'));
  80. }
  81. break;
  82. case 'show_msg' :
  83. Display :: display_confirmation_message($my_msg);
  84. break;
  85. }
  86. }
  87. /*
  88. * Group-admin functions
  89. */
  90. if (api_is_allowed_to_edit(false, true)) {
  91. // Post-actions
  92. if (isset($_POST['action'])) {
  93. switch ($_POST['action']) {
  94. case 'delete_selected' :
  95. if (is_array($_POST['group'])) {
  96. GroupManager :: delete_groups($my_group);
  97. Display :: display_confirmation_message(get_lang('SelectedGroupsDeleted'));
  98. }
  99. break;
  100. case 'empty_selected' :
  101. if (is_array($_POST['group'])) {
  102. GroupManager :: unsubscribe_all_users($my_group);
  103. Display :: display_confirmation_message(get_lang('SelectedGroupsEmptied'));
  104. }
  105. break;
  106. case 'fill_selected' :
  107. if (is_array($_POST['group'])) {
  108. GroupManager :: fill_groups($my_group);
  109. Display :: display_confirmation_message(get_lang('SelectedGroupsFilled'));
  110. }
  111. break;
  112. }
  113. }
  114. // Get-actions
  115. if (isset($_GET['action'])) {
  116. switch ($_GET['action']) {
  117. case 'swap_cat_order':
  118. GroupManager :: swap_category_order($my_get_id1, $my_get_id2);
  119. Display :: display_confirmation_message(get_lang('CategoryOrderChanged'));
  120. break;
  121. case 'delete_one':
  122. GroupManager :: delete_groups($my_get_id);
  123. Display :: display_confirmation_message(get_lang('GroupDel'));
  124. break;
  125. case 'empty_one':
  126. GroupManager :: unsubscribe_all_users($my_get_id);
  127. Display :: display_confirmation_message(get_lang('GroupEmptied'));
  128. break;
  129. case 'fill_one':
  130. GroupManager :: fill_groups($my_get_id);
  131. Display :: display_confirmation_message(get_lang('GroupFilledGroups'));
  132. break;
  133. case 'delete_category':
  134. GroupManager :: delete_category($my_get_id);
  135. Display :: display_confirmation_message(get_lang('CategoryDeleted'));
  136. break;
  137. }
  138. }
  139. }
  140. echo '<div class="actions">';
  141. if (api_is_allowed_to_edit(false, true)) {
  142. echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('new_group.png', get_lang('NewGroupCreate'),'',ICON_SIZE_MEDIUM).'</a>';
  143. if (CourseManager::count_rows_course_table(Database::get_course_table(TABLE_GROUP),api_get_session_id(), api_get_course_int_id()) > 0) {
  144. //echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group_view.gif').'&nbsp;'.get_lang('GroupOverview').'</a>&nbsp;';
  145. echo '<a href="group_overview.php?'.api_get_cidreq().'">'.Display::return_icon('group_summary.png', get_lang('GroupOverview'),'',ICON_SIZE_MEDIUM).'</a>';
  146. }
  147. if (api_get_setting('allow_group_categories') == 'true') {
  148. echo '<a href="group_category.php?'.api_get_cidreq().'&action=add_category">'.Display::return_icon('new_folder.png', get_lang('AddCategory'),'',ICON_SIZE_MEDIUM).'</a>';
  149. } else {
  150. //echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('edit_group.gif').'&nbsp;'.get_lang('PropModify').'</a>&nbsp;';
  151. echo '<a href="group_category.php?'.api_get_cidreq().'&id=2">'.Display::return_icon('settings.png', get_lang('PropModify'),'',ICON_SIZE_MEDIUM).'</a>';
  152. }
  153. //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> ';
  154. echo '<a href="group_overview.php?'.api_get_cidreq().'&action=export&type=xls">'.Display::return_icon('export_excel.png', get_lang('ExportAsXLS'),'',ICON_SIZE_MEDIUM).'</a>';
  155. //echo '<a href="group_creation.php?'.api_get_cidreq().'">'.Display::return_icon('group_add_big.gif').'&nbsp;'.get_lang('NewGroupCreate').'</a>&nbsp;';
  156. echo '<a href="../user/user.php?'.api_get_cidreq().'">'.Display::return_icon('user.png', get_lang('GoTo').' '.get_lang('Users'),'',ICON_SIZE_MEDIUM).'</a>';
  157. }
  158. $group_cats = GroupManager :: get_categories();
  159. if (api_get_setting('allow_group_categories') == 'true' && count($group_cats) > 1) {
  160. echo ' <a href="?'.api_get_cidreq().'&show_all=1">'.Display::return_icon('group.png',get_lang('ShowAll'),'',ICON_SIZE_MEDIUM).'</a>';
  161. }
  162. echo '</div>';
  163. /*
  164. * List all categories
  165. */
  166. foreach ($group_cats as $index => $category) {
  167. $group_list = array ();
  168. $in_category = false;
  169. if (api_get_setting('allow_group_categories') == 'true') {
  170. if (isset ($_GET['show_all']) || (isset ($_GET['category']) && $_GET['category'] == $category['id'])) {
  171. echo '<img src="../img/folder_group_category.gif" alt=""/>';
  172. echo '<a href="group.php?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'">'.$category['title'].'</a>';
  173. $in_category = true;
  174. } else {
  175. echo '<img src="../img/folder_document.gif" alt=""/>';
  176. echo '<a href="group.php?'.api_get_cidreq().'&origin='.Security::remove_XSS($_GET['origin']).'&amp;category='.$category['id'].'">'.$category['title'].'</a>';
  177. }
  178. $group_list = GroupManager :: get_group_list($category['id']);
  179. echo ' ('.count($group_list).' '.get_lang('ExistingGroups').')';
  180. if (api_is_allowed_to_edit(false, true)) {
  181. echo '<a href="group_category.php?'.api_get_cidreq().'&id='.$category['id'].'" title="'.get_lang('Edit').'">'.Display::return_icon('settings.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>';
  182. 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))."'".')) return false;" title="'.get_lang('Delete').'">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>';
  183. if ($index != 0) {
  184. echo ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index -1]['id'].'">'.Display::return_icon('up.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
  185. }
  186. if ($index != count($group_cats) - 1) {
  187. echo ' <a href="group.php?'.api_get_cidreq().'&action=swap_cat_order&amp;id1='.$category['id'].'&amp;id2='.$group_cats[$index +1]['id'].'">'.Display::return_icon('down.png','&nbsp;','',ICON_SIZE_SMALL).'</a>';
  188. }
  189. }
  190. echo '<p style="margin: 0px;margin-left: 50px;">'.$category['description'].'</p><p/>';
  191. } else {
  192. $group_list = GroupManager :: get_group_list();
  193. $in_category = true;
  194. }
  195. //if (count($group_list) > 0 && $in_category)
  196. if ($in_category) {
  197. $totalRegistered = 0;
  198. $group_data = array();
  199. foreach ($group_list as $index => $this_group) {
  200. // Validacion when belongs to a session
  201. $session_img = api_get_session_image($this_group['session_id'], $_user['status']);
  202. // All the tutors of this group
  203. $tutorsids_of_group = GroupManager::get_subscribed_tutors($this_group['id'], true);
  204. // Create a new table-row
  205. $row = array ();
  206. // Checkbox
  207. if (api_is_allowed_to_edit(false,true) && count($group_list) > 1) {
  208. $row[] = $this_group['id'];
  209. }
  210. // Group name
  211. if ((api_is_allowed_to_edit(false, true) ||
  212. in_array($_user['user_id'], $tutorsids_of_group) ||
  213. $this_group['is_member'] ||
  214. GroupManager::user_has_access($_user['user_id'], $this_group['id'], GROUP_TOOL_FORUM) ||
  215. GroupManager::user_has_access($_user['user_id'], $this_group['id'], GROUP_TOOL_DOCUMENTS) ||
  216. GroupManager::user_has_access($_user['user_id'], $this_group['id'], GROUP_TOOL_CALENDAR) ||
  217. GroupManager::user_has_access($_user['user_id'], $this_group['id'], GROUP_TOOL_ANNOUNCEMENT) ||
  218. GroupManager::user_has_access($_user['user_id'], $this_group['id'], GROUP_TOOL_WORK) ||
  219. GroupManager::user_has_access($_user['user_id'], $this_group['id'], GROUP_TOOL_WIKI))
  220. && !(api_is_course_coach() && intval($this_group['session_id']) != intval($_SESSION['id_session']))) {
  221. $orig = isset($origin) ? $origin : null;
  222. $group_name = '<a href="group_space.php?'.api_get_cidreq().'&amp;origin='.$orig.'&amp;gidReq='.$this_group['id'].'">'.stripslashes($this_group['name']).'</a>';
  223. if (!empty($_SESSION['_user']['user_id']) && !empty($this_group['id_tutor']) && $_SESSION['_user']['user_id'] == $this_group['id_tutor']) {
  224. $group_name .= ' ('.get_lang('OneMyGroups').')';
  225. } elseif ($this_group['is_member']) {
  226. $group_name .= ' ('.get_lang('MyGroup').')';
  227. }
  228. if (api_is_allowed_to_edit() && !empty($this_group['session_name'])) {
  229. $group_name .= ' ('.$this_group['session_name'].')';
  230. }
  231. $group_name .= $session_img;
  232. $row[] = $group_name.'<br />'.stripslashes(trim($this_group['description']));
  233. } else {
  234. $row[] = $this_group['name'].'<br />'.stripslashes(trim($this_group['description']));
  235. }
  236. // Tutor name
  237. $tutor_info = '';
  238. if (count($tutorsids_of_group) > 0) {
  239. foreach ($tutorsids_of_group as $tutor_id) {
  240. $tutor = api_get_user_info($tutor_id);
  241. $username = api_htmlentities(sprintf(get_lang('LoginX'), $tutor['username']), ENT_QUOTES);
  242. if (api_get_setting('show_email_addresses') == 'true') {
  243. $tutor_info .= Display::tag('span', Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])), array('title'=>$username)).', ';
  244. } else {
  245. if (api_is_allowed_to_edit()) {
  246. $tutor_info .= Display::tag('span', Display::encrypted_mailto_link($tutor['mail'], api_get_person_name($tutor['firstName'], $tutor['lastName'])), array('title'=>$username)).', ';
  247. } else {
  248. $tutor_info .= Display::tag('span', api_get_person_name($tutor['firstName'], $tutor['lastName']), array('title'=>$username)).', ';
  249. }
  250. }
  251. }
  252. }
  253. $tutor_info = api_substr($tutor_info, 0, api_strlen($tutor_info) - 2);
  254. $row[] = $tutor_info;
  255. // Max number of members in group
  256. $max_members = ($this_group['maximum_number_of_members'] == MEMBER_PER_GROUP_NO_LIMIT ? ' ' : ' / '.$this_group['maximum_number_of_members']);
  257. // Number of members in group
  258. $row[] = $this_group['number_of_members'].$max_members;
  259. // Self-registration / unregistration
  260. if (!api_is_allowed_to_edit(false, true)) {
  261. if (GroupManager :: is_self_registration_allowed($_user['user_id'], $this_group['id'])) {
  262. $row[] = '<a class = "a_button gray small" 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>';
  263. } elseif (GroupManager :: is_self_unregistration_allowed($_user['user_id'], $this_group['id'])) {
  264. $row[] = '<a class = "a_button gray small" 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>';
  265. } else {
  266. $row[] = '-';
  267. }
  268. }
  269. // Edit-links
  270. if (api_is_allowed_to_edit(false, true) && !(api_is_course_coach() && intval($this_group['session_id']) != intval($_SESSION['id_session']))) {
  271. $edit_actions = '<a href="group_edit.php?'.api_get_cidreq().'&gidReq='.$this_group['id'].'" title="'.get_lang('Edit').'">'.Display::return_icon('edit.png', get_lang('EditGroup'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  272. $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))."'".')) return false;" title="'.get_lang('EmptyGroup').'">'.Display::return_icon('clean.png',get_lang('EmptyGroup'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  273. $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))."'".')) return false;" title="'.get_lang('FillGroup').'">'.Display::return_icon('fill.png',get_lang('FillGroup'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  274. $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))."'".')) return false;" title="'.get_lang('Delete').'">'.Display::return_icon('delete.png', get_lang('Delete'),'',ICON_SIZE_SMALL).'</a>&nbsp;';
  275. $row[] = $edit_actions;
  276. }
  277. if (!empty($this_group['nbMember'])) {
  278. $totalRegistered = $totalRegistered + $this_group['nbMember'];
  279. }
  280. $group_data[] = $row;
  281. } // while loop
  282. if (isset ($_GET['show_all'])) {
  283. $paging_options = array('per_page' => count($group_data));
  284. } else {
  285. $paging_options = array ();
  286. }
  287. $table = new SortableTableFromArrayConfig($group_data, 1);
  288. $my_cat = isset($_GET['category']) ? Security::remove_XSS($_GET['category']) : null;
  289. $table->set_additional_parameters(array('category' => $my_cat));
  290. $column = 0;
  291. if (api_is_allowed_to_edit(false, true) and count($group_list) > 1) {
  292. $table->set_header($column++, '', false);
  293. }
  294. $table->set_header($column++, get_lang('Groups'));
  295. $table->set_header($column++, get_lang('GroupTutor'));
  296. $table->set_header($column++, get_lang('Registered'), false);
  297. if (!api_is_allowed_to_edit(false, true)) { // If self-registration allowed
  298. $table->set_header($column++, get_lang('GroupSelfRegistration'), false);
  299. }
  300. //$table->set_header($column++, get_lang('MaximumOfParticipants'));
  301. if (api_is_allowed_to_edit(false, true)) { // Only for course administrator
  302. $table->set_header($column++, get_lang('Modify'), false);
  303. $form_actions = array();
  304. $form_actions['delete_selected'] = get_lang('Delete');
  305. $form_actions['fill_selected'] = get_lang('FillGroup');
  306. $form_actions['empty_selected'] = get_lang('EmptyGroup');
  307. if (count($group_list) > 1) {
  308. $table->set_form_actions($form_actions, 'group');
  309. }
  310. }
  311. $table->display();
  312. }
  313. /*
  314. elseif ($in_category) {
  315. echo get_lang('NoGroupsAvailable');
  316. }
  317. */
  318. }
  319. /* FOOTER */
  320. if (!isset ($_GET['origin']) || $_GET['origin'] != 'learnpath') {
  321. Display::display_footer();
  322. }