class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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);
  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('ToolUser'),
  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. if (api_is_allowed_to_edit()) {
  36. if ($type === 'registered') {
  37. $actionsLeft .= '<a href="class.php?'.api_get_cidreq().'&type=not_registered">'.
  38. Display::return_icon('add-class.png', get_lang('AddClassesToACourse'), [], ICON_SIZE_MEDIUM).'</a>';
  39. } else {
  40. $actionsLeft .= '<a href="class.php?'.api_get_cidreq().'&type=registered">'.
  41. Display::return_icon('back.png', get_lang('Classes'), [], ICON_SIZE_MEDIUM).'</a>';
  42. $form = new FormValidator(
  43. 'groups',
  44. 'get',
  45. api_get_self().'?type='.$type,
  46. '',
  47. [],
  48. FormValidator::LAYOUT_INLINE
  49. );
  50. $options = [
  51. -1 => get_lang('All'),
  52. 1 => get_lang('SocialGroups'),
  53. 0 => get_lang('Classes'),
  54. ];
  55. $form->addSelect(
  56. 'group_filter',
  57. get_lang('Groups'),
  58. $options,
  59. ['id' => 'group_filter', 'disable_js' => 'disable_js']
  60. );
  61. $form->addHidden('type', $type);
  62. $form->addText('keyword', '', false);
  63. $form->setDefaults(['group_filter' => $groupFilter]);
  64. $form->addCourseHiddenParams();
  65. $form->addButtonSearch(get_lang('SearchButton'));
  66. $actionsRight .= $form->returnForm();
  67. }
  68. $actions = Display::toolbarAction('actions-class', [$actionsLeft, $actionsRight]);
  69. $action = isset($_GET['action']) ? $_GET['action'] : null;
  70. switch ($action) {
  71. case 'add_class_to_course':
  72. $id = $_GET['id'];
  73. if (!empty($id)) {
  74. $usergroup->subscribe_courses_to_usergroup(
  75. $id,
  76. [api_get_course_int_id()],
  77. false
  78. );
  79. Display::addFlash(Display::return_message(get_lang('Added')));
  80. header('Location: class.php?'.api_get_cidreq().'&type=registered');
  81. exit;
  82. }
  83. break;
  84. case 'remove_class_from_course':
  85. $id = $_GET['id'];
  86. if (!empty($id)) {
  87. $usergroup->unsubscribe_courses_from_usergroup(
  88. $id,
  89. [api_get_course_int_id()]
  90. );
  91. Display::addFlash(Display::return_message(get_lang('Deleted')));
  92. }
  93. break;
  94. }
  95. }
  96. // jqgrid will use this URL to do the selects
  97. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type.'&group_filter='.$groupFilter.'&keyword='.$keyword;
  98. // The order is important you need to check the the $column variable in the model.ajax.php file
  99. $columns = [
  100. get_lang('Name'),
  101. get_lang('Users'),
  102. get_lang('Status'),
  103. get_lang('Type'),
  104. get_lang('Actions'),
  105. ];
  106. // Column config
  107. $columnModel = [
  108. ['name' => 'name',
  109. 'index' => 'name',
  110. 'width' => '35',
  111. 'align' => 'left',
  112. ],
  113. [
  114. 'name' => 'users',
  115. 'index' => 'users',
  116. 'width' => '15',
  117. 'align' => 'left',
  118. ],
  119. [
  120. 'name' => 'status',
  121. 'index' => 'status',
  122. 'width' => '15',
  123. 'align' => 'left',
  124. ],
  125. [
  126. 'name' => 'group_type',
  127. 'index' => 'group_type',
  128. 'width' => '15',
  129. 'align' => 'center',
  130. ],
  131. [
  132. 'name' => 'actions',
  133. 'index' => 'actions',
  134. 'width' => '10',
  135. 'align' => 'center',
  136. 'sortable' => 'false',
  137. ],
  138. ];
  139. // Autowidth
  140. $extraParams['autowidth'] = 'true';
  141. // height auto
  142. $extraParams['height'] = 'auto';
  143. Display::display_header($tool_name, 'User');
  144. ?>
  145. <script>
  146. $(function() {
  147. <?php
  148. // grid definition see the $usergroup>display() function
  149. echo Display::grid_js(
  150. 'usergroups',
  151. $url,
  152. $columns,
  153. $columnModel,
  154. $extraParams,
  155. [],
  156. '',
  157. true
  158. );
  159. ?>
  160. });
  161. </script>
  162. <?php
  163. echo $actions;
  164. echo UserManager::getUserSubscriptionTab(4);
  165. echo Display::return_message(get_lang('UserClassExplanation'));
  166. $usergroup->display_teacher_view();
  167. Display::display_footer();