usergroups.php 8.1 KB

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