usergroups.php 8.1 KB

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