usergroups.php 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 \''
  59. .' <a href="add_users_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/user_to_class.png" title="'.get_lang('SubscribeUsersToClass').'"></a>'
  60. .' <a href="add_courses_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/course_to_class.png" title="'.get_lang('SubscribeClassToCourses').'"></a>'
  61. .' <a href="add_sessions_to_usergroup.php?id=\'+options.rowId+\'"><img src="../img/icons/22/sessions_to_class.png" title="'.get_lang('SubscribeClassToSessions').'"></a>'
  62. .' <a href="?action=edit&id=\'+options.rowId+\'"><img width="20px" src="../img/edit.png" title="'.get_lang('Edit').'" ></a>'
  63. .' <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>\';
  64. }';
  65. ?>
  66. <script>
  67. $(function() {
  68. <?php
  69. // grid definition see the $usergroup>display() function
  70. echo Display::grid_js('usergroups', $url,$columns,$column_model,$extra_params, array(), $action_links,true);
  71. ?>
  72. });
  73. </script>
  74. <?php
  75. // Tool introduction
  76. Display::display_introduction_section(get_lang('Classes'));
  77. $usergroup = new UserGroup();
  78. // Action handling: Adding a note
  79. if (isset($_GET['action']) && $_GET['action'] == 'add') {
  80. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  81. api_not_allowed();
  82. }
  83. $_SESSION['notebook_view'] = 'creation_date';
  84. //@todo move this in the career.lib.php
  85. // Initiate the object
  86. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  87. // Settting the form elements
  88. $form->addElement('header', '', get_lang('Add'));
  89. $form->addElement('text', 'name', get_lang('name'), array('size' => '70', 'id' => 'name'));
  90. //$form->applyFilter('note_title', 'html_filter');
  91. $form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
  92. $form->addElement('style_submit_button', 'submit', get_lang('Add'), 'class="add"');
  93. // Setting the rules
  94. $form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  95. // The validation or display
  96. if ($form->validate()) {
  97. $check = Security::check_token('post');
  98. if ($check) {
  99. $values = $form->exportValues();
  100. $res = $usergroup->save($values);
  101. if ($res) {
  102. Display::display_confirmation_message(get_lang('Added'));
  103. }
  104. }
  105. Security::clear_token();
  106. $usergroup->display();
  107. } else {
  108. echo '<div class="actions">';
  109. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'','32').'</a>';
  110. echo '</div>';
  111. $token = Security::get_token();
  112. $form->addElement('hidden', 'sec_token');
  113. $form->setConstants(array('sec_token' => $token));
  114. $form->display();
  115. }
  116. }// Action handling: Editing a note
  117. elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
  118. // Initialize the object
  119. $form = new FormValidator('career', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
  120. // Settting the form elements
  121. $form->addElement('header', '', get_lang('Modify'));
  122. $form->addElement('hidden', 'id',intval($_GET['id']));
  123. $form->addElement('text', 'name', get_lang('Name'), array('size' => '70'));
  124. $form->add_html_editor('description', get_lang('Description'), false, false, array('Width' => '95%', 'Height' => '250'));
  125. $form->addElement('style_submit_button', 'submit', get_lang('Modify'), 'class="save"');
  126. // Setting the defaults
  127. $defaults = $usergroup->get($_GET['id']);
  128. $form->setDefaults($defaults);
  129. // Setting the rules
  130. $form->addRule('name', '<div class="required">'.get_lang('ThisFieldIsRequired'), 'required');
  131. // The validation or display
  132. if ($form->validate()) {
  133. $check = Security::check_token('post');
  134. if ($check) {
  135. $values = $form->exportValues();
  136. $res = $usergroup->update($values);
  137. if ($res) {
  138. Display::display_confirmation_message(get_lang('Updated'));
  139. }
  140. }
  141. Security::clear_token();
  142. $usergroup->display();
  143. } else {
  144. echo '<div class="actions">';
  145. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'','32').'</a>';
  146. echo '</div>';
  147. $token = Security::get_token();
  148. $form->addElement('hidden', 'sec_token');
  149. $form->setConstants(array('sec_token' => $token));
  150. $form->display();
  151. }
  152. }
  153. // Action handling: deleting a note
  154. elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  155. $res = $usergroup->delete(Security::remove_XSS($_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();