tutor_settings.php 7.4 KB

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