class.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.user
  5. */
  6. //require_once '../inc/global.inc.php';
  7. $this_section = SECTION_COURSES;
  8. api_protect_course_script(true);
  9. if (api_get_setting('course.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. $actions = '';
  32. $usergroup = new UserGroup();
  33. if (api_is_allowed_to_edit()) {
  34. $actions .= '<div class="actions">';
  35. if ($type == 'registered') {
  36. $actions .= '<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. $actions .= '<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('groups', 'post', api_get_self(), '', '', FormValidator::LAYOUT_INLINE);
  42. $options = [
  43. -1 => get_lang('All'),
  44. 1 => get_lang('SocialGroups'),
  45. 0 => get_lang('Classes'),
  46. ];
  47. $form->addSelect('group_filter', get_lang('Groups'), $options, ['id' => 'group_filter']);
  48. $form->setDefaults(['group_filter' => $groupFilter]);
  49. $actions .= $form->returnForm();
  50. }
  51. $actions .= '</div>';
  52. }
  53. if (api_is_allowed_to_edit()) {
  54. $action = isset($_GET['action']) ? $_GET['action'] : null;
  55. switch ($action) {
  56. case 'add_class_to_course':
  57. $id = $_GET['id'];
  58. if (!empty($id)) {
  59. $usergroup->subscribe_courses_to_usergroup(
  60. $id,
  61. array(api_get_course_int_id()),
  62. false
  63. );
  64. Display::addFlash(Display::return_message(get_lang('Added')));
  65. }
  66. break;
  67. case 'remove_class_from_course':
  68. $id = $_GET['id'];
  69. if (!empty($id)) {
  70. $usergroup->unsubscribe_courses_from_usergroup(
  71. $id,
  72. array(api_get_course_int_id())
  73. );
  74. Display::addFlash(Display::return_message(get_lang('Deleted')));
  75. }
  76. break;
  77. }
  78. }
  79. //jqgrid will use this URL to do the selects
  80. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type.'&group_filter='.$groupFilter;
  81. //The order is important you need to check the the $column variable in the model.ajax.php file
  82. $columns = array(
  83. get_lang('Name'),
  84. get_lang('Users'),
  85. get_lang('Status'),
  86. get_lang('Type'),
  87. get_lang('Actions'),
  88. );
  89. // Column config
  90. $columnModel = array(
  91. array('name'=>'name',
  92. 'index' => 'name',
  93. 'width' => '35',
  94. 'align' => 'left',
  95. ),
  96. array(
  97. 'name' => 'users',
  98. 'index' => 'users',
  99. 'width' => '15',
  100. 'align' => 'left',
  101. ),
  102. array(
  103. 'name' => 'status',
  104. 'index' => 'status',
  105. 'width' => '15',
  106. 'align' => 'left',
  107. ),
  108. array(
  109. 'name' => 'group_type',
  110. 'index' => 'group_type',
  111. 'width' => '15',
  112. 'align' => 'center',
  113. ),
  114. array(
  115. 'name' => 'actions',
  116. 'index' => 'actions',
  117. 'width' => '10',
  118. 'align' => 'center',
  119. 'sortable' => 'false',
  120. ),
  121. );
  122. // Autowidth
  123. $extraParams['autowidth'] = 'true';
  124. // height auto
  125. $extraParams['height'] = 'auto';
  126. Display :: display_header($tool_name, "User");
  127. ?>
  128. <script>
  129. $(function() {
  130. <?php
  131. // grid definition see the $usergroup>display() function
  132. echo Display::grid_js('usergroups', $url, $columns, $columnModel, $extraParams, array(), '', true);
  133. ?>
  134. });
  135. </script>
  136. <?php
  137. echo $actions;
  138. echo UserManager::getUserSubscriptionTab(4);
  139. $usergroup->display_teacher_view();
  140. Display :: display_footer();