usergroups.php 7.8 KB

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