usergroups.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  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' => 'index.php', 'name' => get_lang('PlatformAdmin'));
  15. $action = isset($_GET['action']) ? Security::remove_XSS($_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 ($action == 'add') {
  29. $tool = 'Add';
  30. $interbreadcrumb[] = array('url' => api_get_self(), 'name' => get_lang('Group'));
  31. }
  32. if ($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('name'=>'actions', 'index'=>'actions', 'width'=>'20', 'align'=>'center', 'sortable'=>'false', 'formatter'=>'action_formatter'),
  55. );
  56. //Autowidth
  57. $extra_params['autowidth'] = 'true';
  58. //height auto
  59. $extra_params['height'] = 'auto';
  60. $extra_params['sortname'] = 'name';
  61. $extra_params['sortorder'] = 'desc';
  62. //With this function we can add actions to the jgrid
  63. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  64. return \''
  65. .' <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>'
  66. .' <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>'
  67. .' <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>'
  68. .' <a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), null, ICON_SIZE_SMALL).'</a>'
  69. .' <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>\';
  70. }';
  71. ?>
  72. <script>
  73. $(function() {
  74. <?php
  75. // grid definition see the $usergroup>display() function
  76. echo Display::grid_js(
  77. 'usergroups',
  78. $url,
  79. $columns,
  80. $column_model,
  81. $extra_params,
  82. array(),
  83. $action_links,
  84. true
  85. );
  86. ?>
  87. });
  88. </script>
  89. <?php
  90. $usergroup = new UserGroup();
  91. $usergroup->showGroupTypeSetting = true;
  92. // Action handling: Adding a note
  93. if ($action == 'add') {
  94. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  95. api_not_allowed();
  96. }
  97. $form = new FormValidator(
  98. 'usergroup',
  99. 'post',
  100. api_get_self().'?action='.$action
  101. );
  102. $usergroup->setForm($form, 'add');
  103. // Setting the defaults
  104. $form->setDefaults(['visibility' => 2]);
  105. // The validation or display
  106. if ($form->validate()) {
  107. $values = $form->exportValues();
  108. $res = $usergroup->save($values);
  109. if ($res) {
  110. echo Display::return_message(get_lang('ItemAdded'), 'confirmation');
  111. } else {
  112. echo Display::return_message(
  113. Security::remove_XSS($values['name']).': '.
  114. get_lang('AlreadyExists'),
  115. 'warning'
  116. );
  117. }
  118. $usergroup->display();
  119. } else {
  120. echo '<div class="actions">';
  121. echo '<a href="'.api_get_self().'">'.
  122. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  123. echo '</div>';
  124. $token = Security::get_token();
  125. $form->addElement('hidden', 'sec_token');
  126. $form->setConstants(array('sec_token' => $token));
  127. $form->display();
  128. }
  129. } elseif ($action == 'edit' && is_numeric($_GET['id'])) {
  130. $id = intval($_GET['id']);
  131. $form = new FormValidator(
  132. 'usergroup',
  133. 'post',
  134. api_get_self().'?action='.$action.'&id='.$id
  135. );
  136. $defaults = $usergroup->get($id);
  137. $usergroup->setForm($form, 'edit', $defaults);
  138. // Setting the form elements
  139. $form->addElement('hidden', 'id', $id);
  140. // Setting the defaults
  141. $form->setDefaults($defaults);
  142. // The validation or display.
  143. if ($form->validate()) {
  144. $values = $form->getSubmitValues();
  145. $res = $usergroup->update($values);
  146. if ($res) {
  147. echo Display::return_message(get_lang('Updated'), 'confirmation');
  148. } else {
  149. echo Display::return_message(
  150. Security::remove_XSS($values['name']).': '.
  151. get_lang('AlreadyExists'),
  152. 'warning'
  153. );
  154. }
  155. $usergroup->display();
  156. } else {
  157. echo '<div class="actions">';
  158. echo '<a href="'.api_get_self().'">'.Display::return_icon(
  159. 'back.png',
  160. get_lang('Back'),
  161. '',
  162. ICON_SIZE_MEDIUM
  163. ).'</a>';
  164. echo '</div>';
  165. $form->display();
  166. }
  167. } elseif ($action == 'delete' && is_numeric($_GET['id'])) {
  168. $res = $usergroup->delete($_GET['id']);
  169. if ($res) {
  170. echo Display::return_message(get_lang('Deleted'), 'confirmation');
  171. }
  172. $usergroup->display();
  173. } else {
  174. $usergroup->display();
  175. }
  176. Display :: display_footer();