tutor_settings.php 7.2 KB

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