tutor_settings.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. require_once '../inc/global.inc.php';
  13. $this_section = SECTION_COURSES;
  14. $current_course_tool = TOOL_GROUP;
  15. // Notice for unauthorized people.
  16. api_protect_course_script(true);
  17. $group_id = api_get_group_id();
  18. $current_group = GroupManager :: get_group_properties($group_id);
  19. $nameTools = get_lang('EditGroup');
  20. $interbreadcrumb[] = array ('url' => 'group.php', 'name' => get_lang('Groups'));
  21. $interbreadcrumb[] = array ('url' => 'group_space.php?'.api_get_cidReq(), 'name' => $current_group['name']);
  22. $is_group_member = GroupManager :: is_tutor_of_group(api_get_user_id(), $group_id);
  23. if (!api_is_allowed_to_edit(false, true) && !$is_group_member) {
  24. api_not_allowed(true);
  25. }
  26. /* FUNCTIONS */
  27. /**
  28. * List all users registered to the course
  29. */
  30. function search_members_keyword($firstname, $lastname, $username, $official_code, $keyword)
  31. {
  32. if (api_strripos($firstname, $keyword) !== false ||
  33. api_strripos($lastname, $keyword) !== false ||
  34. api_strripos($username, $keyword) !== false ||
  35. api_strripos($official_code, $keyword) !== false
  36. ) {
  37. return true;
  38. } else {
  39. return false;
  40. }
  41. }
  42. /**
  43. * Function to sort users after getting the list in the DB.
  44. * Necessary because there are 2 or 3 queries. Called by usort()
  45. */
  46. function sort_users($user_a, $user_b)
  47. {
  48. global $_configuration;
  49. if (isset($_configuration['order_user_list_by_official_code']) &&
  50. $_configuration['order_user_list_by_official_code']
  51. ) {
  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. /* MAIN CODE */
  91. $htmlHeadXtra[] = '<script>
  92. $(document).ready( function() {
  93. $("#max_member").on("focus", function() {
  94. $("#max_member_selected").attr("checked", true);
  95. });
  96. });
  97. </script>';
  98. // Build form
  99. $form = new FormValidator('group_edit', 'post', api_get_self().'?'.api_get_cidreq());
  100. $form->addElement('hidden', 'action');
  101. // Group tutors
  102. $group_tutor_list = GroupManager :: get_subscribed_tutors($current_group['id']);
  103. $selected_tutors = array();
  104. foreach ($group_tutor_list as $index => $user) {
  105. $selected_tutors[] = $user['user_id'];
  106. }
  107. $complete_user_list = GroupManager :: fill_groups_list($current_group['id']);
  108. $possible_users = array();
  109. if (!empty($complete_user_list)) {
  110. usort($complete_user_list, 'sort_users');
  111. foreach ($complete_user_list as $index => $user) {
  112. $officialCode = !empty($user['official_code']) ? ' - '.$user['official_code'] : null;
  113. $name = api_get_person_name(
  114. $user['firstname'],
  115. $user['lastname']
  116. ).' ('.$user['username'].')'.$officialCode;
  117. global $_configuration;
  118. if (isset($_configuration['order_user_list_by_official_code']) &&
  119. $_configuration['order_user_list_by_official_code']
  120. ) {
  121. $officialCode = !empty($user['official_code']) ? $user['official_code']." - " : '? - ';
  122. $name = $officialCode." ".api_get_person_name(
  123. $user['firstname'],
  124. $user['lastname']
  125. ).' ('.$user['username'].')';
  126. }
  127. $possible_users[$user['user_id']] = $name;
  128. }
  129. }
  130. $group_tutors_element = $form->addElement('advmultiselect', 'group_tutors', get_lang('GroupTutors'), $possible_users, 'style="width: 280px;"');
  131. // submit button
  132. $form->addButtonSave(get_lang('SaveSettings'));
  133. if ($form->validate()) {
  134. $values = $form->exportValues();
  135. // Storing the tutors (we first remove all the tutors and then add only those who were selected)
  136. GroupManager :: unsubscribe_all_tutors($current_group['id']);
  137. if (isset ($_POST['group_tutors']) && count($_POST['group_tutors']) > 0) {
  138. GroupManager :: subscribe_tutors($values['group_tutors'], $current_group['id']);
  139. }
  140. // Returning to the group area (note: this is inconsistent with the rest of chamilo)
  141. $cat = GroupManager::get_category_from_group($current_group['id']);
  142. if (isset($_POST['group_members']) && count($_POST['group_members']) > $max_member && $max_member != GroupManager::MEMBER_PER_GROUP_NO_LIMIT) {
  143. header('Location: group.php?'.api_get_cidreq(true, false).'&action=warning_message&msg='.get_lang('GroupTooMuchMembers'));
  144. } else {
  145. header('Location: group.php?'.api_get_cidreq(true, false).'&action=success_message&msg='.get_lang('GroupSettingsModified').'&category='.$cat['id']);
  146. }
  147. exit;
  148. }
  149. $defaults = $current_group;
  150. $defaults['group_tutors'] = $selected_tutors;
  151. $action = isset($_GET['action']) ? $_GET['action'] : '';
  152. $defaults['action'] = $action;
  153. if (!empty($_GET['keyword']) && !empty($_GET['submit'])) {
  154. $keyword_name = Security::remove_XSS($_GET['keyword']);
  155. echo '<br/>'.get_lang('SearchResultsFor').' <span style="font-style: italic ;"> '.$keyword_name.' </span><br>';
  156. }
  157. Display :: display_header($nameTools, 'Group');
  158. //@todo fix this
  159. if (isset($_GET['show_message_warning'])) {
  160. echo Display::display_warning_message($_GET['show_message_warning']);
  161. }
  162. if (isset($_GET['show_message_sucess'])) {
  163. echo Display::display_normal_message($_GET['show_message_sucess']);
  164. }
  165. $form->setDefaults($defaults);
  166. echo GroupManager::getSettingBar('tutor');
  167. $form->display();
  168. Display :: display_footer();