usergroups.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once '../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']) ? $_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('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_SMALL) . '</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_SMALL) . '</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_SMALL) . '</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. // Tool introduction
  91. Display::display_introduction_section(get_lang('Classes'));
  92. $usergroup = new UserGroup();
  93. $usergroup->showGroupTypeSetting = true;
  94. // Action handling: Adding a note
  95. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  96. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  97. api_not_allowed();
  98. }
  99. $form = new FormValidator(
  100. 'usergroup',
  101. 'post',
  102. api_get_self().'?action='.Security::remove_XSS($_GET['action'])
  103. );
  104. $usergroup->setForm($form, 'add');
  105. // Setting the defaults
  106. $form->setDefaults(['visibility' => 2]);
  107. // The validation or display
  108. if ($form->validate()) {
  109. $values = $form->exportValues();
  110. $res = $usergroup->save($values);
  111. if ($res) {
  112. Display::display_confirmation_message(get_lang('ItemAdded'));
  113. } else {
  114. Display::display_warning_message(
  115. Security::remove_XSS($values['name']).': '.
  116. get_lang('AlreadyExists')
  117. );
  118. }
  119. $usergroup->display();
  120. } else {
  121. echo '<div class="actions">';
  122. echo '<a href="'.api_get_self().'">'.
  123. Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  124. echo '</div>';
  125. $token = Security::get_token();
  126. $form->addElement('hidden', 'sec_token');
  127. $form->setConstants(array('sec_token' => $token));
  128. $form->display();
  129. }
  130. } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
  131. $id = intval($_GET['id']);
  132. $form = new FormValidator('usergroup', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.$id);
  133. $defaults = $usergroup->get($id);
  134. $usergroup->setForm($form, 'edit', $defaults);
  135. // Setting the form elements
  136. $form->addElement('hidden', 'id', $id);
  137. // Setting the defaults
  138. $form->setDefaults($defaults);
  139. // The validation or display.
  140. if ($form->validate()) {
  141. $values = $form->getSubmitValues();
  142. $res = $usergroup->update($values);
  143. if ($res) {
  144. Display::display_confirmation_message(get_lang('Updated'));
  145. } else {
  146. Display::display_warning_message(
  147. Security::remove_XSS($values['name']).': '.
  148. get_lang('AlreadyExists')
  149. );
  150. }
  151. $usergroup->display();
  152. } else {
  153. echo '<div class="actions">';
  154. echo '<a href="'.api_get_self().'">'.Display::return_icon(
  155. 'back.png',
  156. get_lang('Back'),
  157. '',
  158. ICON_SIZE_MEDIUM
  159. ).'</a>';
  160. echo '</div>';
  161. $form->display();
  162. }
  163. } elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  164. $res = $usergroup->delete($_GET['id']);
  165. if ($res) {
  166. Display::display_confirmation_message(get_lang('Deleted'));
  167. }
  168. $usergroup->display();
  169. } else {
  170. $usergroup->display();
  171. }
  172. Display :: display_footer();