tutor_settings.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * This script displays an area where teachers can edit the group properties and member list.
  5. * Groups are also often called "teams" in the Dokeos code.
  6. *
  7. * @author various contributors
  8. * @author Roan Embrechts (VUB), partial code cleanup, initial virtual course support
  9. * @package chamilo.group
  10. * @todo course admin functionality to create groups based on who is in which course (or class).
  11. */
  12. $this_section = SECTION_COURSES;
  13. $current_course_tool = TOOL_GROUP;
  14. // Notice for unauthorized people.
  15. api_protect_course_script(true);
  16. $group_id = api_get_group_id();
  17. $current_group = GroupManager::get_group_properties($group_id);
  18. $nameTools = get_lang('EditGroup');
  19. $interbreadcrumb[] = array ('url' => 'group.php?'.api_get_cidreq(), 'name' => get_lang('Groups'));
  20. $interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidreq(), 'name' => $current_group['name']);
  21. $is_group_member = GroupManager::is_tutor_of_group(api_get_user_id(), $current_group['iid']);
  22. if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
  23. api_not_allowed(true);
  24. }
  25. /* FUNCTIONS */
  26. /**
  27. * List all users registered to the course
  28. */
  29. function search_members_keyword($firstname, $lastname, $username, $official_code, $keyword)
  30. {
  31. if (api_strripos($firstname, $keyword) !== false ||
  32. api_strripos($lastname, $keyword) !== false ||
  33. api_strripos($username, $keyword) !== false ||
  34. api_strripos($official_code, $keyword) !== false
  35. ) {
  36. return true;
  37. } else {
  38. return false;
  39. }
  40. }
  41. /**
  42. * Function to sort users after getting the list in the DB.
  43. * Necessary because there are 2 or 3 queries. Called by usort()
  44. */
  45. function sort_users($user_a, $user_b)
  46. {
  47. $orderListByOfficialCode = api_get_setting(
  48. 'platform.order_user_list_by_official_code'
  49. );
  50. if ($orderListByOfficialCode === 'true') {
  51. $cmp = api_strcmp($user_a['official_code'], $user_b['official_code']);
  52. if ($cmp !== 0) {
  53. return $cmp;
  54. } else {
  55. $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
  56. if ($cmp !== 0) {
  57. return $cmp;
  58. } else {
  59. return api_strcmp($user_a['username'], $user_b['username']);
  60. }
  61. }
  62. }
  63. if (api_sort_by_first_name()) {
  64. $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
  65. if ($cmp !== 0) {
  66. return $cmp;
  67. } else {
  68. $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
  69. if ($cmp !== 0) {
  70. return $cmp;
  71. } else {
  72. return api_strcmp($user_a['username'], $user_b['username']);
  73. }
  74. }
  75. } else {
  76. $cmp = api_strcmp($user_a['lastname'], $user_b['lastname']);
  77. if ($cmp !== 0) {
  78. return $cmp;
  79. } else {
  80. $cmp = api_strcmp($user_a['firstname'], $user_b['firstname']);
  81. if ($cmp !== 0) {
  82. return $cmp;
  83. } else {
  84. return api_strcmp($user_a['username'], $user_b['username']);
  85. }
  86. }
  87. }
  88. }
  89. $htmlHeadXtra[] = '<script>
  90. $(document).ready( function() {
  91. $("#max_member").on("focus", function() {
  92. $("#max_member_selected").attr("checked", true);
  93. });
  94. });
  95. </script>';
  96. // Build form
  97. $form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
  98. $form->addElement('hidden', 'action');
  99. // Group tutors
  100. $group_tutor_list = GroupManager :: get_subscribed_tutors($current_group['iid']);
  101. $selected_tutors = array();
  102. foreach ($group_tutor_list as $index => $user) {
  103. $selected_tutors[] = $user['user_id'];
  104. }
  105. $complete_user_list = GroupManager::fill_groups_list($current_group['iid']);
  106. $possible_users = array();
  107. $userGroup = new UserGroup();
  108. $subscribedUsers = GroupManager::get_subscribed_users($current_group['iid']);
  109. if ($subscribedUsers) {
  110. $subscribedUsers = array_column($subscribedUsers, 'user_id');
  111. }
  112. $orderUserListByOfficialCode = api_get_setting('order_user_list_by_official_code');
  113. if (!empty($complete_user_list)) {
  114. usort($complete_user_list, 'sort_users');
  115. foreach ($complete_user_list as $index => $user) {
  116. if (in_array($user['user_id'], $subscribedUsers)) {
  117. continue;
  118. }
  119. //prevent invitee users add to groups or tutors - see #8091
  120. if ($user['status'] != INVITEE) {
  121. $officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null;
  122. $groups = $userGroup->getUserGroupListByUser($user['user_id']);
  123. $groupNameListToString = '';
  124. if (!empty($groups)) {
  125. $groupNameList = array_column($groups, 'name');
  126. $groupNameListToString = ' - ['.implode(', ', $groupNameList).']';
  127. }
  128. $name = api_get_person_name(
  129. $user['firstname'],
  130. $user['lastname']
  131. ).' ('.$user['username'].')'.$officialCode;
  132. if ($orderUserListByOfficialCode === 'true') {
  133. $officialCode = !empty($user['official_code']) ? $user['official_code']." - " : '? - ';
  134. $name = $officialCode.' '.api_get_person_name(
  135. $user['firstname'],
  136. $user['lastname']
  137. ).' ('.$user['username'].')';
  138. }
  139. $possible_users[$user['user_id']] = $name.$groupNameListToString;
  140. }
  141. }
  142. }
  143. $group_tutors_element = $form->addElement(
  144. 'advmultiselect',
  145. 'group_tutors',
  146. get_lang('GroupTutors'),
  147. $possible_users,
  148. 'style="width: 280px;"'
  149. );
  150. // submit button
  151. $form->addButtonSave(get_lang('SaveSettings'));
  152. if ($form->validate()) {
  153. $values = $form->exportValues();
  154. // Storing the tutors (we first remove all the tutors and then add only those who were selected)
  155. GroupManager :: unsubscribe_all_tutors($current_group['iid']);
  156. if (isset($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
  157. GroupManager::subscribe_tutors($values['group_tutors'], $current_group['iid']);
  158. }
  159. // Returning to the group area (note: this is inconsistent with the rest of chamilo)
  160. $cat = GroupManager::get_category_from_group($current_group['iid']);
  161. if (isset($_POST['group_members']) &&
  162. count($_POST['group_members']) > $max_member &&
  163. $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT
  164. ) {
  165. Display::addFlash(Display::return_message(get_lang('GroupTooMuchMembers'), 'warning'));
  166. header('Location: group.php?'.api_get_cidreq(true, false));
  167. } else {
  168. Display::addFlash(Display::return_message(get_lang('GroupSettingsModified'), 'success'));
  169. header('Location: group.php?'.api_get_cidreq(true, false).'&category='.$cat['id']);
  170. }
  171. exit;
  172. }
  173. $defaults = $current_group;
  174. $defaults['group_tutors'] = $selected_tutors;
  175. $action = isset($_GET['action']) ? $_GET['action'] : '';
  176. $defaults['action'] = $action;
  177. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  178. $keyword_name = Security::remove_XSS($_GET['keyword']);
  179. echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  180. }
  181. Display :: display_header($nameTools, 'Group');
  182. $form->setDefaults($defaults);
  183. echo GroupManager::getSettingBar('tutor');
  184. $form->display();
  185. Display :: display_footer();