usergroups.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script(true);
  10. api_protect_limit_for_session_admin();
  11. //Add the JS needed to use the jqgrid
  12. $htmlHeadXtra[] = api_get_jqgrid_js();
  13. // setting breadcrumbs
  14. $interbreadcrumb[] = array('url' => Container::getRouter()->generate('administration'),'name' => get_lang('PlatformAdmin'));
  15. $action = isset($_GET['action']) ? $_GET['action'] : null;
  16. if ($action == 'add') {
  17. $interbreadcrumb[] = array('url' => 'usergroups.php','name' => get_lang('Classes'));
  18. $interbreadcrumb[] = array('url' => '#','name' => get_lang('Add'));
  19. } elseif ($action == 'edit') {
  20. $interbreadcrumb[] = array('url' => 'usergroups.php','name' => get_lang('Classes'));
  21. $interbreadcrumb[] = array('url' => '#','name' => get_lang('Edit'));
  22. } else {
  23. $interbreadcrumb[] = array('url' => '#','name' => get_lang('Classes'));
  24. }
  25. // The header.
  26. Display::display_header();
  27. // Tool name
  28. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  29. $tool = 'Add';
  30. $interbreadcrumb[] = array('url' => api_get_self(), 'name' => get_lang('Group'));
  31. }
  32. if (isset($_GET['action']) && $_GET['action'] == 'edit') {
  33. $tool = 'Modify';
  34. $interbreadcrumb[] = array('url' => api_get_self(), 'name' => get_lang('Group'));
  35. }
  36. // jqgrid will use this URL to do the selects
  37. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups';
  38. //The order is important you need to check the the $column variable in the model.ajax.php file
  39. $columns = array(
  40. get_lang('Name'),
  41. get_lang('Users'),
  42. get_lang('Courses'),
  43. get_lang('Sessions'),
  44. get_lang('Type'),
  45. get_lang('Actions'),
  46. );
  47. // Column config
  48. $column_model = array(
  49. array('name' => 'name', 'index' => 'name', 'width' => '35', 'align' => 'left'),
  50. array('name' => 'users', 'index' => 'users', 'width' => '15', 'align' => 'left'),
  51. array('name' => 'courses', 'index' => 'courses', 'width' => '15', 'align' => 'left'),
  52. array('name' => 'sessions', 'index' => 'sessions', 'width' => '15', 'align' => 'left'),
  53. array('name' => 'group_type', 'index' => 'group_type', 'width' => '15', 'align' => 'center'),
  54. array(
  55. 'name' => 'actions',
  56. 'index' => 'actions',
  57. 'width' => '20',
  58. 'align' => 'center',
  59. 'sortable' => 'false',
  60. 'formatter' => 'action_formatter',
  61. ),
  62. );
  63. //Autowidth
  64. $extra_params['autowidth'] = 'true';
  65. //height auto
  66. $extra_params['height'] = 'auto';
  67. $extra_params['sortname'] = 'name';
  68. $extra_params['sortorder'] = 'desc';
  69. //With this function we can add actions to the jgrid
  70. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  71. return \''
  72. .' <a href="add_users_to_usergroup.php?id=\'+options.rowId+\'">' . Display::return_icon('user_to_class.png', get_lang('SubscribeUsersToClass'), null, ICON_SIZE_MEDIUM) . '</a>'
  73. .' <a href="add_courses_to_usergroup.php?id=\'+options.rowId+\'">' . Display::return_icon('course_to_class.png', get_lang('SubscribeClassToCourses'), null, ICON_SIZE_MEDIUM) . '</a>'
  74. .' <a href="add_sessions_to_usergroup.php?id=\'+options.rowId+\'">' . Display::return_icon('sessions_to_class.png', get_lang('SubscribeClassToSessions'), null, ICON_SIZE_MEDIUM) . '</a>'
  75. .' <a href="?action=edit&id=\'+options.rowId+\'">' . Display::return_icon('edit.png', get_lang('Edit'), null, ICON_SIZE_SMALL) . '</a>'
  76. .' <a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"),ENT_QUOTES))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'">' . Display::return_icon('delete.png', get_lang('Delete'), null, ICON_SIZE_SMALL) . '</a>\';
  77. }';
  78. ?>
  79. <script>
  80. $(function() {
  81. <?php
  82. // grid definition see the $usergroup>display() function
  83. echo Display::grid_js(
  84. 'usergroups',
  85. $url,
  86. $columns,
  87. $column_model,
  88. $extra_params,
  89. array(),
  90. $action_links,
  91. true
  92. );
  93. ?>
  94. });
  95. </script>
  96. <?php
  97. $usergroup = new UserGroup();
  98. $usergroup->showGroupTypeSetting = true;
  99. // Action handling: Adding a note
  100. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  101. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  102. api_not_allowed();
  103. }
  104. $form = new FormValidator(
  105. 'usergroup',
  106. 'post',
  107. api_get_self().'?action='.Security::remove_XSS($_GET['action'])
  108. );
  109. $usergroup->setForm($form, 'add');
  110. // Setting the defaults
  111. $form->setDefaults(['visibility' => 2]);
  112. // The validation or display
  113. if ($form->validate()) {
  114. $values = $form->exportValues();
  115. $res = $usergroup->save($values);
  116. if ($res) {
  117. Display::display_confirmation_message(get_lang('ItemAdded'));
  118. } else {
  119. Display::display_warning_message(
  120. Security::remove_XSS($values['name']).': '.
  121. get_lang('AlreadyExists')
  122. );
  123. }
  124. $usergroup->display();
  125. } else {
  126. echo '<div class="actions">';
  127. echo '<a href="'.api_get_self().'">'.
  128. Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  129. echo '</div>';
  130. $token = Security::get_token();
  131. $form->addElement('hidden', 'sec_token');
  132. $form->setConstants(array('sec_token' => $token));
  133. $form->display();
  134. }
  135. } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
  136. $id = intval($_GET['id']);
  137. $form = new FormValidator('usergroup', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.$id);
  138. $defaults = $usergroup->get($id);
  139. $usergroup->setForm($form, 'edit', $defaults);
  140. // Setting the form elements
  141. $form->addElement('hidden', 'id', $id);
  142. // Setting the defaults
  143. $form->setDefaults($defaults);
  144. // The validation or display.
  145. if ($form->validate()) {
  146. $values = $form->getSubmitValues();
  147. $res = $usergroup->update($values);
  148. if ($res) {
  149. Display::display_confirmation_message(get_lang('Updated'));
  150. } else {
  151. Display::display_warning_message(
  152. Security::remove_XSS($values['name']).': '.
  153. get_lang('AlreadyExists')
  154. );
  155. }
  156. $usergroup->display();
  157. } else {
  158. echo '<div class="actions">';
  159. echo '<a href="'.api_get_self().'">'.Display::return_icon(
  160. 'back.png',
  161. get_lang('Back'),
  162. '',
  163. ICON_SIZE_MEDIUM
  164. ).'</a>';
  165. echo '</div>';
  166. $form->display();
  167. }
  168. } elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  169. $res = $usergroup->delete($_GET['id']);
  170. if ($res) {
  171. Display::display_confirmation_message(get_lang('Deleted'));
  172. }
  173. $usergroup->display();
  174. } else {
  175. $usergroup->display();
  176. }
  177. Display :: display_footer();