class.php 4.7 KB

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