usergroups.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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'] == 'editnote') {
  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('Id'), get_lang('Name'), get_lang('Users'), get_lang('Courses'), get_lang('Sessions'), get_lang('Actions')
  41. );
  42. //Column config
  43. $column_model = array(
  44. array('name'=>'id', 'index'=>'id', 'width'=>'5', 'align'=>'left'),
  45. array('name'=>'name', 'index'=>'name', 'width'=>'35', 'align'=>'left'),
  46. array('name'=>'users', 'index'=>'users', 'width'=>'15', 'align'=>'left'),
  47. array('name'=>'courses', 'index'=>'courses', 'width'=>'15', 'align'=>'left'),
  48. array('name'=>'sessions', 'index'=>'sessions', 'width'=>'15', 'align'=>'left'),
  49. array('name'=>'actions', 'index'=>'actions', 'width'=>'20', 'align'=>'left', 'sortable'=>'false','formatter'=>'action_formatter'),
  50. );
  51. //Autowidth
  52. $extra_params['autowidth'] = 'true';
  53. //height auto
  54. $extra_params['height'] = 'auto';
  55. $extra_params['sortname'] = 'name';
  56. $extra_params['sortorder'] = 'desc';
  57. //With this function we can add actions to the jgrid
  58. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  59. return \''
  60. .' <a href="add_users_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/user_to_class.png" title="'.get_lang('SubscribeUsersToClass').'"></a>'
  61. .' <a href="add_courses_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/course_to_class.png" title="'.get_lang('SubscribeClassToCourses').'"></a>'
  62. .' <a href="add_sessions_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/sessions_to_class.png" title="'.get_lang('SubscribeClassToSessions').'"></a>'
  63. .' <a href="?action=edit&id=\'+options.rowId+\'"><img width="20px" src="../img/edit.png" title="'.get_lang('Edit').'" ></a>'
  64. .' <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>\';
  65. }';
  66. ?>
  67. <script>
  68. $(function() {
  69. <?php
  70. // grid definition see the $usergroup>display() function
  71. echo Display::grid_js('usergroups', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  72. ?>
  73. });
  74. </script>
  75. <?php
  76. // Tool introduction
  77. Display::display_introduction_section(get_lang('Classes'));
  78. $usergroup = new UserGroup();
  79. // Action handling: Adding a note
  80. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  81. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  82. api_not_allowed();
  83. }
  84. $_SESSION['notebook_view'] = 'creation_date';
  85. //@todo move this in the career.lib.php
  86. // Initiate the object
  87. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  88. // Setting the form elements
  89. $form->addElement('header', get_lang('Add'));
  90. $form->addElement('text', 'name', get_lang('Name'), array('size' => '70', 'id' => 'name'));
  91. //$form->applyFilter('note_title', 'html_filter');
  92. $form->addHtmlEditor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
  93. //$form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
  94. $form->addButtonCreate(get_lang('Add'));
  95. // Setting the rules
  96. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  97. // The validation or display
  98. if ($form->validate()) {
  99. $check = Security::check_token('post');
  100. if ($check) {
  101. $values = $form->exportValues();
  102. $res = $usergroup->save($values);
  103. if ($res) {
  104. Display::display_confirmation_message(get_lang('ItemAdded'));
  105. } else {
  106. Display::display_warning_message(
  107. Security::remove_XSS($values['name']).': '.
  108. get_lang('AlreadyExists')
  109. );
  110. }
  111. }
  112. Security::clear_token();
  113. $usergroup->display();
  114. } else {
  115. echo '<div class="actions">';
  116. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  117. echo '</div>';
  118. $token = Security::get_token();
  119. $form->addElement('hidden', 'sec_token');
  120. $form->setConstants(array('sec_token' => $token));
  121. $form->display();
  122. }
  123. } elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
  124. // Action handling: Editing a note
  125. // Initialize the object
  126. $form = new FormValidator('career', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
  127. // Setting the form elements
  128. $form->addElement('header', '', get_lang('Modify'));
  129. $form->addElement('hidden', 'id', intval($_GET['id']));
  130. $form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
  131. $form->addHtmlEditor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
  132. $form->addButtonSave(get_lang('Save'));
  133. // Setting the defaults
  134. $defaults = $usergroup->get($_GET['id']);
  135. $form->setDefaults($defaults);
  136. // Setting the rules.
  137. $form->addRule('name', get_lang('ThisFieldIsRequired'), 'required');
  138. // The validation or display.
  139. if ($form->validate()) {
  140. $check = Security::check_token('post');
  141. if ($check) {
  142. $values = $form->exportValues();
  143. $res = $usergroup->update($values);
  144. if ($res) {
  145. Display::display_confirmation_message(get_lang('Updated'));
  146. } else {
  147. Display::display_warning_message(
  148. Security::remove_XSS($values['name']).': '.
  149. get_lang('AlreadyExists')
  150. );
  151. }
  152. }
  153. Security::clear_token();
  154. $usergroup->display();
  155. } else {
  156. echo '<div class="actions">';
  157. echo '<a href="'.api_get_self().'">'.Display::return_icon(
  158. 'back.png',
  159. get_lang('Back'),
  160. '',
  161. ICON_SIZE_MEDIUM
  162. ).'</a>';
  163. echo '</div>';
  164. $token = Security::get_token();
  165. $form->addElement('hidden', 'sec_token');
  166. $form->setConstants(array('sec_token' => $token));
  167. $form->display();
  168. }
  169. } elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  170. $res = $usergroup->delete(Security::remove_XSS($_GET['id']));
  171. if ($res) {
  172. Display::display_confirmation_message(get_lang('Deleted'));
  173. }
  174. $usergroup->display();
  175. } else {
  176. $usergroup->display();
  177. }
  178. Display :: display_footer();