class.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.user
  5. */
  6. require_once __DIR__.'/../inc/global.inc.php';
  7. $this_section = SECTION_COURSES;
  8. api_protect_course_script(true, false, 'user');
  9. if (api_get_setting('allow_user_course_subscription_by_course_admin') == 'false') {
  10. if (!api_is_platform_admin()) {
  11. api_not_allowed(true);
  12. }
  13. }
  14. $tool_name = get_lang('Classes');
  15. $htmlHeadXtra[] = api_get_jqgrid_js();
  16. // Extra entries in breadcrumb
  17. $interbreadcrumb[] = [
  18. 'url' => 'user.php?'.api_get_cidreq(),
  19. 'name' => get_lang('Users'),
  20. ];
  21. $type = isset($_GET['type']) ? Security::remove_XSS($_GET['type']) : 'registered';
  22. $groupFilter = isset($_GET['group_filter']) ? (int) $_GET['group_filter'] : 0;
  23. $keyword = isset($_GET['keyword']) ? Security::remove_XSS($_GET['keyword']) : '';
  24. $htmlHeadXtra[] = '
  25. <script>
  26. $(function() {
  27. $("#group_filter").change(function() {
  28. window.location = "class.php?'.api_get_cidreq().'&type='.$type.'" +"&group_filter=" + $(this).val();
  29. });
  30. });
  31. </script>';
  32. $actionsLeft = '';
  33. $actionsRight = '';
  34. $usergroup = new UserGroup();
  35. $actions = '';
  36. if (api_is_allowed_to_edit()) {
  37. if ($type === 'registered') {
  38. $actionsLeft .= '<a href="class.php?'.api_get_cidreq().'&type=not_registered">'.
  39. Display::return_icon('add-class.png', get_lang('Add classes to a course'), [], ICON_SIZE_MEDIUM).'</a>';
  40. } else {
  41. $actionsLeft .= '<a href="class.php?'.api_get_cidreq().'&type=registered">'.
  42. Display::return_icon('back.png', get_lang('Classes'), [], ICON_SIZE_MEDIUM).'</a>';
  43. $form = new FormValidator(
  44. 'groups',
  45. 'get',
  46. api_get_self().'?type='.$type,
  47. '',
  48. [],
  49. FormValidator::LAYOUT_INLINE
  50. );
  51. $options = [
  52. -1 => get_lang('All'),
  53. 1 => get_lang('Social groups'),
  54. 0 => get_lang('Classes'),
  55. ];
  56. $form->addSelect(
  57. 'group_filter',
  58. get_lang('Groups'),
  59. $options,
  60. ['id' => 'group_filter', 'disable_js' => 'disable_js']
  61. );
  62. $form->addHidden('type', $type);
  63. $form->addText('keyword', '', false);
  64. $form->setDefaults(['group_filter' => $groupFilter]);
  65. $form->addCourseHiddenParams();
  66. $form->addButtonSearch(get_lang('Search'));
  67. $actionsRight .= $form->returnForm();
  68. }
  69. $actions = Display::toolbarAction('actions-class', [$actionsLeft, $actionsRight]);
  70. $action = isset($_GET['action']) ? $_GET['action'] : null;
  71. switch ($action) {
  72. case 'add_class_to_course':
  73. $id = $_GET['id'];
  74. if (!empty($id)) {
  75. $usergroup->subscribe_courses_to_usergroup(
  76. $id,
  77. [api_get_course_int_id()],
  78. false
  79. );
  80. Display::addFlash(Display::return_message(get_lang('Added')));
  81. header('Location: class.php?'.api_get_cidreq().'&type=registered');
  82. exit;
  83. }
  84. break;
  85. case 'remove_class_from_course':
  86. $id = $_GET['id'];
  87. if (!empty($id)) {
  88. $usergroup->unsubscribe_courses_from_usergroup(
  89. $id,
  90. [api_get_course_int_id()]
  91. );
  92. Display::addFlash(Display::return_message(get_lang('Deleted')));
  93. }
  94. break;
  95. }
  96. }
  97. // jqgrid will use this URL to do the selects
  98. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type.'&group_filter='.$groupFilter.'&keyword='.$keyword;
  99. // The order is important you need to check the the $column variable in the model.ajax.php file
  100. $columns = [
  101. get_lang('Name'),
  102. get_lang('Users'),
  103. get_lang('Status'),
  104. get_lang('Type'),
  105. get_lang('Detail'),
  106. ];
  107. // Column config
  108. $columnModel = [
  109. ['name' => 'name',
  110. 'index' => 'name',
  111. 'width' => '35',
  112. 'align' => 'left',
  113. ],
  114. [
  115. 'name' => 'users',
  116. 'index' => 'users',
  117. 'width' => '15',
  118. 'align' => 'left',
  119. ],
  120. [
  121. 'name' => 'status',
  122. 'index' => 'status',
  123. 'width' => '15',
  124. 'align' => 'left',
  125. ],
  126. [
  127. 'name' => 'group_type',
  128. 'index' => 'group_type',
  129. 'width' => '15',
  130. 'align' => 'center',
  131. ],
  132. [
  133. 'name' => 'actions',
  134. 'index' => 'actions',
  135. 'width' => '10',
  136. 'align' => 'center',
  137. 'sortable' => 'false',
  138. ],
  139. ];
  140. // Autowidth
  141. $extraParams['autowidth'] = 'true';
  142. // height auto
  143. $extraParams['height'] = 'auto';
  144. Display::display_header($tool_name, 'User');
  145. ?>
  146. <script>
  147. $(function() {
  148. <?php
  149. // grid definition see the $usergroup>display() function
  150. echo Display::grid_js(
  151. 'usergroups',
  152. $url,
  153. $columns,
  154. $columnModel,
  155. $extraParams,
  156. [],
  157. '',
  158. true
  159. );
  160. ?>
  161. });
  162. </script>
  163. <?php
  164. echo $actions;
  165. echo UserManager::getUserSubscriptionTab(4);
  166. echo Display::return_message(get_lang('Information: The list of classes below contains the list of classes you have already registered in your course. If this list is empty, use the + green above to add classes.'));
  167. $usergroup->display_teacher_view();
  168. Display::display_footer();