usergroups.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @todo use a controller
  5. * @package chamilo.admin
  6. */
  7. // Language files that need to be included.
  8. $language_file = array('admin');
  9. $cidReset = true;
  10. require_once '../inc/global.inc.php';
  11. $this_section = SECTION_PLATFORM_ADMIN;
  12. api_protect_admin_script(true);
  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(get_lang('Name'), get_lang('Users'), get_lang('Courses'), get_lang('Sessions'), get_lang('Type'), get_lang('Actions'));
  42. //Column config
  43. $column_model = array(
  44. array('name'=>'name', 'index'=>'name', 'width'=>'35', 'align'=>'left'),
  45. //array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left'),
  46. array('name'=>'users', 'index'=>'users', 'width'=>'15', 'align'=>'left'),
  47. array('name'=>'courses', 'index'=>'courses', 'width'=>'15', 'align'=>'left'),
  48. array('name'=>'sessions', 'index'=>'sessions', 'width'=>'15', 'align'=>'left'),
  49. array('name'=>'group_type', 'index'=>'group_type', '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+\'">'.Display::return_icon('user_to_class.png', get_lang('SubscribeUsersToClass')).'</a>'
  60. .' <a href="add_courses_to_usergroup.php?id=\'+options.rowId+\'">'.Display::return_icon('course_to_class.png', get_lang('SubscribeClassToCourses')).'</a>'
  61. .' <a href="add_sessions_to_usergroup.php?id=\'+options.rowId+\'">'.Display::return_icon('sessions_to_class.png', get_lang('SubscribeClassToSessions')).'</a>'
  62. .' <a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit')).'</a>'
  63. .' <a onclick="javascript:if(!confirm('."\'".addslashes(get_lang("ConfirmYourChoice"))."\'".')) return false;" href="?action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete')).'</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. //@todo move this in the .lib.php
  84. // Initiate the object
  85. $form = new FormValidator('note', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']));
  86. $usergroup->setForm($form, 'add');
  87. // The validation or display
  88. if ($form->validate()) {
  89. $check = Security::check_token('post');
  90. if ($check) {
  91. $values = $form->exportValues();
  92. $res = $usergroup->save($values);
  93. if ($res) {
  94. Display::display_confirmation_message(get_lang('ItemAdded'));
  95. }
  96. }
  97. Security::clear_token();
  98. $usergroup->display();
  99. } else {
  100. echo '<div class="actions">';
  101. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  102. echo '</div>';
  103. $token = Security::get_token();
  104. $form->addElement('hidden', 'sec_token');
  105. $form->setConstants(array('sec_token' => $token));
  106. $form->display();
  107. }
  108. }// Action handling: Edition
  109. elseif (isset($_GET['action']) && $_GET['action'] == 'edit' && is_numeric($_GET['id'])) {
  110. // Initialize the object
  111. $form = new FormValidator('usergroup', 'post', api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.Security::remove_XSS($_GET['id']));
  112. $defaults = $usergroup->get($_GET['id']);
  113. $usergroup->setForm($form, 'edit', $defaults);
  114. // Setting the form elements
  115. $form->addElement('hidden', 'id', intval($_GET['id']));
  116. // Setting the defaults
  117. $form->setDefaults($defaults);
  118. // The validation or display
  119. if ($form->validate()) {
  120. $check = Security::check_token('post');
  121. if ($check) {
  122. $values = $form->exportValues();
  123. $res = $usergroup->update($values);
  124. if ($res) {
  125. Display::display_confirmation_message(get_lang('Updated'));
  126. }
  127. }
  128. Security::clear_token();
  129. $usergroup->display();
  130. } else {
  131. echo '<div class="actions">';
  132. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  133. echo '</div>';
  134. $token = Security::get_token();
  135. $form->addElement('hidden', 'sec_token');
  136. $form->setConstants(array('sec_token' => $token));
  137. $form->display();
  138. }
  139. }
  140. // Action handling: deleting a note
  141. elseif (isset($_GET['action']) && $_GET['action'] == 'delete' && is_numeric($_GET['id'])) {
  142. $res = $usergroup->delete(Security::remove_XSS($_GET['id']));
  143. if ($res) {
  144. Display::display_confirmation_message(get_lang('Deleted'));
  145. }
  146. $usergroup->display();
  147. } else {
  148. $usergroup->display();
  149. }
  150. Display :: display_footer();