class.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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('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. Display :: display_header($tool_name, "User");
  32. $usergroup = new UserGroup();
  33. if (api_is_allowed_to_edit()) {
  34. echo '<div class="actions">';
  35. if ($type == 'registered') {
  36. echo '<a href="class.php?'.api_get_cidreq().'&type=not_registered">'.
  37. Display::return_icon('add.png', get_lang("AddClassesToACourse"), array(), ICON_SIZE_MEDIUM).'</a>';
  38. } else {
  39. echo '<a href="class.php?'.api_get_cidreq().'&type=registered">'.
  40. Display::return_icon('empty_evaluation.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. $form->display();
  50. }
  51. echo '</div>';
  52. }
  53. echo UserManager::getUserSubscriptionTab(4);
  54. if (api_is_allowed_to_edit()) {
  55. $action = isset($_GET['action']) ? $_GET['action'] : null;
  56. switch ($action) {
  57. case 'add_class_to_course':
  58. $id = $_GET['id'];
  59. if (!empty($id)) {
  60. $usergroup->subscribe_courses_to_usergroup(
  61. $id,
  62. array(api_get_course_int_id()),
  63. false
  64. );
  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. }
  75. break;
  76. }
  77. }
  78. //jqgrid will use this URL to do the selects
  79. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups_teacher&type='.$type.'&group_filter='.$groupFilter;
  80. //The order is important you need to check the the $column variable in the model.ajax.php file
  81. $columns = array(
  82. get_lang('Name'),
  83. get_lang('Users'),
  84. get_lang('Status'),
  85. get_lang('Type'),
  86. get_lang('Actions'),
  87. );
  88. //Column config
  89. $column_model = array(
  90. array('name'=>'name',
  91. 'index' => 'name',
  92. 'width' => '35',
  93. 'align' => 'left',
  94. ),
  95. array(
  96. 'name' => 'users',
  97. 'index' => 'users',
  98. 'width' => '15',
  99. 'align' => 'left',
  100. ),
  101. array(
  102. 'name' => 'status',
  103. 'index' => 'status',
  104. 'width' => '15',
  105. 'align' => 'left',
  106. ),
  107. array(
  108. 'name' => 'group_type',
  109. 'index' => 'group_type',
  110. 'width' => '15',
  111. 'align' => 'left',
  112. ),
  113. array(
  114. 'name' => 'actions',
  115. 'index' => 'actions',
  116. 'width' => '20',
  117. 'align' => 'left',
  118. 'sortable' => 'false',
  119. ),
  120. );
  121. // Autowidth
  122. $extra_params['autowidth'] = 'true';
  123. // height auto
  124. $extra_params['height'] = 'auto';
  125. // With this function we can add actions to the jgrid
  126. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  127. return \''
  128. .' <a href="class.php?action=add_class&id=\'+options.rowId+\'"><img src="../img/icons/22/user_to_class.png" title="'.get_lang('SubscribeUsersToClass').'"></a>'
  129. .' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'"><img title="'.get_lang('Delete').'" src="../img/delete.png"></a>\';
  130. }';
  131. ?>
  132. <script>
  133. $(function() {
  134. <?php
  135. // grid definition see the $usergroup>display() function
  136. echo Display::grid_js('usergroups', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  137. ?>
  138. });
  139. </script>
  140. <?php
  141. $usergroup->display_teacher_view();
  142. Display :: display_footer();