usergroups.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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'=>'left'),
  54. array('name'=>'actions', 'index'=>'actions', 'width'=>'20', 'align'=>'left', '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+\'"><img src="../img/icons/22/user_to_class.png" title="'.get_lang('SubscribeUsersToClass').'"></a>'
  66. .' <a href="add_courses_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/course_to_class.png" title="'.get_lang('SubscribeClassToCourses').'"></a>'
  67. .' <a href="add_sessions_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/sessions_to_class.png" title="'.get_lang('SubscribeClassToSessions').'"></a>'
  68. .' <a href="?action=edit&id=\'+options.rowId+\'"><img width="22px" src="../img/edit.png" title="'.get_lang('Edit').'" ></a>'
  69. .' <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>\';
  70. }';
  71. ?>
  72. <script>
  73. $(function() {
  74. <?php
  75. // grid definition see the $usergroup>display() function
  76. echo Display::grid_js('usergroups', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  77. ?>
  78. });
  79. </script>
  80. <?php
  81. // Tool introduction
  82. Display::display_introduction_section(get_lang('Classes'));
  83. $usergroup = new UserGroup();
  84. $usergroup->showGroupTypeSetting = true;
  85. // Action handling: Adding a note
  86. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  87. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  88. api_not_allowed();
  89. }
  90. $form = new FormValidator(
  91. 'usergroup',
  92. 'post',
  93. api_get_self().'?action='.Security::remove_XSS($_GET['action'])
  94. );
  95. $usergroup->setForm($form, 'add');
  96. // Setting the defaults
  97. $form->setDefaults(['visibility' => 2]);
  98. // The validation or display
  99. if ($form->validate()) {
  100. $values = $form->exportValues();
  101. $res = $usergroup->save($values);
  102. if ($res) {
  103. Display::display_confirmation_message(get_lang('ItemAdded'));
  104. } else {
  105. Display::display_warning_message(
  106. Security::remove_XSS($values['name']).': '.
  107. get_lang('AlreadyExists')
  108. );
  109. }
  110. $usergroup->display();
  111. } else {
  112. echo '<div class="actions">';
  113. echo '<a href="'.api_get_self().'">'.
  114. Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  115. echo '</div>';
  116. $token = Security::get_token();
  117. $form->addElement('hidden', 'sec_token');
  118. $form->setConstants(array('sec_token' => $token));
  119. $form->display();
  120. }
  121. } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
  122. $id = intval($_GET['id']);
  123. $form = new FormValidator('usergroup', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.$id);
  124. $defaults = $usergroup->get($id);
  125. $usergroup->setForm($form, 'edit', $defaults);
  126. // Setting the form elements
  127. $form->addElement('hidden', 'id', $id);
  128. // Setting the defaults
  129. $form->setDefaults($defaults);
  130. // The validation or display.
  131. if ($form->validate()) {
  132. $values = $form->getSubmitValues();
  133. $res = $usergroup->update($values);
  134. if ($res) {
  135. Display::display_confirmation_message(get_lang('Updated'));
  136. } else {
  137. Display::display_warning_message(
  138. Security::remove_XSS($values['name']).': '.
  139. get_lang('AlreadyExists')
  140. );
  141. }
  142. $usergroup->display();
  143. } else {
  144. echo '<div class="actions">';
  145. echo '<a href="'.api_get_self().'">'.Display::return_icon(
  146. 'back.png',
  147. get_lang('Back'),
  148. '',
  149. ICON_SIZE_MEDIUM
  150. ).'</a>';
  151. echo '</div>';
  152. $form->display();
  153. }
  154. } elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  155. $res = $usergroup->delete($_GET['id']);
  156. if ($res) {
  157. Display::display_confirmation_message(get_lang('Deleted'));
  158. }
  159. $usergroup->display();
  160. } else {
  161. $usergroup->display();
  162. }
  163. Display :: display_footer();