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[] = array(
  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. $(document).ready( 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"), array(), 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"), array(), 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. array(api_get_course_int_id()),
  74. false
  75. );
  76. Display::addFlash(Display::return_message(get_lang('Added')));
  77. }
  78. break;
  79. case 'remove_class_from_course':
  80. $id = $_GET['id'];
  81. if (!empty($id)) {
  82. $usergroup->unsubscribe_courses_from_usergroup(
  83. $id,
  84. array(api_get_course_int_id())
  85. );
  86. Display::addFlash(Display::return_message(get_lang('Deleted')));
  87. }
  88. break;
  89. }
  90. }
  91. //jqgrid will use this URL to do the selects
  92. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type.'&group_filter='.$groupFilter;
  93. //The order is important you need to check the the $column variable in the model.ajax.php file
  94. $columns = array(
  95. get_lang('Name'),
  96. get_lang('Users'),
  97. get_lang('Status'),
  98. get_lang('Type'),
  99. get_lang('Actions'),
  100. );
  101. // Column config
  102. $columnModel = array(
  103. array('name'=>'name',
  104. 'index' => 'name',
  105. 'width' => '35',
  106. 'align' => 'left',
  107. ),
  108. array(
  109. 'name' => 'users',
  110. 'index' => 'users',
  111. 'width' => '15',
  112. 'align' => 'left',
  113. ),
  114. array(
  115. 'name' => 'status',
  116. 'index' => 'status',
  117. 'width' => '15',
  118. 'align' => 'left',
  119. ),
  120. array(
  121. 'name' => 'group_type',
  122. 'index' => 'group_type',
  123. 'width' => '15',
  124. 'align' => 'center',
  125. ),
  126. array(
  127. 'name' => 'actions',
  128. 'index' => 'actions',
  129. 'width' => '10',
  130. 'align' => 'center',
  131. 'sortable' => 'false',
  132. ),
  133. );
  134. // Autowidth
  135. $extraParams['autowidth'] = 'true';
  136. // height auto
  137. $extraParams['height'] = 'auto';
  138. Display :: display_header($tool_name, "User");
  139. ?>
  140. <script>
  141. $(function() {
  142. <?php
  143. // grid definition see the $usergroup>display() function
  144. echo Display::grid_js(
  145. 'usergroups',
  146. $url,
  147. $columns,
  148. $columnModel,
  149. $extraParams,
  150. array(),
  151. '',
  152. true
  153. );
  154. ?>
  155. });
  156. </script>
  157. <?php
  158. echo $actions;
  159. echo UserManager::getUserSubscriptionTab(4);
  160. $usergroup->display_teacher_view();
  161. Display :: display_footer();