usergroups.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. //Add the JS needed to use the jqgrid
  13. $htmlHeadXtra[] = api_get_jqgrid_js();
  14. // setting breadcrumbs
  15. $interbreadcrumb[] = array('url' => 'index.php','name' => get_lang('PlatformAdmin'));
  16. $action = isset($_GET['action']) ? $_GET['action'] : null;
  17. if ($action == 'add') {
  18. $interbreadcrumb[] = array('url' => 'usergroups.php','name' => get_lang('Classes'));
  19. $interbreadcrumb[] = array('url' => '#','name' => get_lang('Add'));
  20. } elseif ($action == 'edit') {
  21. $interbreadcrumb[] = array('url' => 'usergroups.php','name' => get_lang('Classes'));
  22. $interbreadcrumb[] = array('url' => '#','name' => get_lang('Edit'));
  23. } else {
  24. $interbreadcrumb[] = array('url' => '#','name' => get_lang('Classes'));
  25. }
  26. // The header.
  27. Display::display_header();
  28. // Tool name
  29. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  30. $tool = 'Add';
  31. $interbreadcrumb[] = array('url' => api_get_self(), 'name' => get_lang('Group'));
  32. }
  33. if (isset($_GET['action']) && $_GET['action'] == 'editnote') {
  34. $tool = 'Modify';
  35. $interbreadcrumb[] = array('url' => api_get_self(), 'name' => get_lang('Group'));
  36. }
  37. // jqgrid will use this URL to do the selects
  38. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_usergroups';
  39. //The order is important you need to check the the $column variable in the model.ajax.php file
  40. $columns = array(
  41. get_lang('Id'), get_lang('Name'), get_lang('Users'), get_lang('Courses'), get_lang('Sessions'), get_lang('Actions')
  42. );
  43. //Column config
  44. $column_model = array(
  45. array('name'=>'id', 'index'=>'id', 'width'=>'5', 'align'=>'left'),
  46. array('name'=>'name', 'index'=>'name', 'width'=>'35', 'align'=>'left'),
  47. array('name'=>'users', 'index'=>'users', 'width'=>'15', 'align'=>'left'),
  48. array('name'=>'courses', 'index'=>'courses', 'width'=>'15', 'align'=>'left'),
  49. array('name'=>'sessions', 'index'=>'sessions', 'width'=>'15', 'align'=>'left'),
  50. array('name'=>'actions', 'index'=>'actions', 'width'=>'20', 'align'=>'left', 'sortable'=>'false','formatter'=>'action_formatter'),
  51. );
  52. //Autowidth
  53. $extra_params['autowidth'] = 'true';
  54. //height auto
  55. $extra_params['height'] = 'auto';
  56. $extra_params['sortname'] = 'name';
  57. $extra_params['sortorder'] = 'desc';
  58. //With this function we can add actions to the jgrid
  59. $action_links = 'function action_formatter (cellvalue, options, rowObject) {
  60. return \''
  61. .' <a href="add_users_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/user_to_class.png" title="'.get_lang('SubscribeUsersToClass').'"></a>'
  62. .' <a href="add_courses_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/course_to_class.png" title="'.get_lang('SubscribeClassToCourses').'"></a>'
  63. .' <a href="add_sessions_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/sessions_to_class.png" title="'.get_lang('SubscribeClassToSessions').'"></a>'
  64. .' <a href="?action=edit&id=\'+options.rowId+\'"><img width="20px" src="../img/edit.png" title="'.get_lang('Edit').'" ></a>'
  65. .' <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>\';
  66. }';
  67. ?>
  68. <script>
  69. $(function() {
  70. <?php
  71. // grid definition see the $usergroup>display() function
  72. echo Display::grid_js('usergroups', $url, $columns, $column_model, $extra_params, array(), $action_links, true);
  73. ?>
  74. });
  75. </script>
  76. <?php
  77. // Tool introduction
  78. Display::display_introduction_section(get_lang('Classes'));
  79. $usergroup = new UserGroup();
  80. // Action handling: Adding a note
  81. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  82. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  83. api_not_allowed();
  84. }
  85. $_SESSION['notebook_view'] = 'creation_date';
  86. //@todo move this in the career.lib.php
  87. // Initiate the object
  88. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  89. // Setting the form elements
  90. $form->addElement('header', get_lang('Add'));
  91. $form->addElement('text', 'name', get_lang('name'), array('size' => '70', 'id' => 'name'));
  92. //$form->applyFilter('note_title', 'html_filter');
  93. $form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
  94. $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="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->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
  132. $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="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('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  158. echo '</div>';
  159. $token = Security::get_token();
  160. $form->addElement('hidden', 'sec_token');
  161. $form->setConstants(array('sec_token' => $token));
  162. $form->display();
  163. }
  164. } elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  165. $res = $usergroup->delete(Security::remove_XSS($_GET['id']));
  166. if ($res) {
  167. Display::display_confirmation_message(get_lang('Deleted'));
  168. }
  169. $usergroup->display();
  170. } else {
  171. $usergroup->display();
  172. }
  173. Display :: display_footer();