grade_models.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * @package chamilo.admin
  5. */
  6. $cidReset = true;
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. if (api_get_setting('gradebook_enable_grade_model') != 'true') {
  11. api_not_allowed(true);
  12. }
  13. //Add the JS needed to use the jqgrid
  14. $htmlHeadXtra[] = api_get_jqgrid_js();
  15. // setting breadcrumbs
  16. $interbreadcrumb[] = ['url' => 'index.php', 'name' => get_lang('PlatformAdmin')];
  17. $action = isset($_GET['action']) ? $_GET['action'] : null;
  18. $check = Security::check_token('request');
  19. $token = Security::get_token();
  20. if ($action === 'add') {
  21. $interbreadcrumb[] = ['url' => 'grade_models.php', 'name' => get_lang('GradeModel')];
  22. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Add')];
  23. } elseif ($action == 'edit') {
  24. $interbreadcrumb[] = ['url' => 'grade_models.php', 'name' => get_lang('GradeModel')];
  25. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Edit')];
  26. } else {
  27. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('GradeModel')];
  28. }
  29. $htmlHeadXtra[] = '<script>
  30. function plusItem(item) {
  31. if (item != 1) {
  32. document.getElementById(item).style.display = "inline";
  33. document.getElementById("plus-"+item).style.display = "none";
  34. document.getElementById("min-"+(item-1)).style.display = "none";
  35. document.getElementById("min-"+(item)).style.display = "inline";
  36. document.getElementById("plus-"+(item+1)).style.display = "inline";
  37. //document.getElementById("txta-"+(item)).value = "100";
  38. //document.getElementById("txta-"+(item-1)).value = "";
  39. $("input").removeClass("form-control");
  40. }
  41. }
  42. function minItem(item) {
  43. if (item != 1) {
  44. document.getElementById(item).style.display = "none";
  45. //document.getElementById("txta-"+item).value = "";
  46. //document.getElementById("txtb-"+item).value = "";
  47. document.getElementById("plus-"+item).style.display = "inline";
  48. document.getElementById("min-"+(item-1)).style.display = "inline";
  49. //document.getElementById("txta-"+(item-1)).value = "100";
  50. $("input").removeClass("form-control");
  51. }
  52. if (item = 1) {
  53. document.getElementById("min-"+(item)).style.display = "none";
  54. $("input").removeClass("form-control");
  55. }
  56. }
  57. </script>';
  58. Display::display_header();
  59. //jqgrid will use this URL to do the selects
  60. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_grade_models';
  61. //The order is important you need to check the the $column variable in the model.ajax.php file
  62. $columns = [
  63. get_lang('Name'),
  64. get_lang('Description'),
  65. get_lang('Actions'),
  66. ];
  67. //Column config
  68. $column_model = [
  69. [
  70. 'name' => 'name',
  71. 'index' => 'name',
  72. 'width' => '80',
  73. 'align' => 'left',
  74. ],
  75. [
  76. 'name' => 'description',
  77. 'index' => 'description',
  78. 'width' => '500',
  79. 'align' => 'left',
  80. 'sortable' => 'false',
  81. ],
  82. [
  83. 'name' => 'actions',
  84. 'index' => 'actions',
  85. 'width' => '100',
  86. 'align' => 'left',
  87. 'formatter' => 'action_formatter',
  88. 'sortable' => 'false',
  89. ],
  90. ];
  91. //Autowidth
  92. $extra_params['autowidth'] = 'true';
  93. //height auto
  94. $extra_params['height'] = 'auto';
  95. //With this function we can add actions to the jgrid (edit, delete, etc)
  96. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  97. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png', get_lang('Edit'), '', ICON_SIZE_SMALL).'</a>'.
  98. '&nbsp;<a onclick="javascript:if(!confirm('."\'".addslashes(api_htmlentities(get_lang("ConfirmYourChoice"), ENT_QUOTES))."\'".')) return false;" href="?sec_token='.$token.'&action=delete&id=\'+options.rowId+\'">'.Display::return_icon('delete.png', get_lang('Delete'), '', ICON_SIZE_SMALL).'</a>'.
  99. '\';
  100. }';
  101. ?>
  102. <script>
  103. $(function() {
  104. <?php
  105. // grid definition see the $obj->display() function
  106. echo Display::grid_js(
  107. 'grade_model',
  108. $url,
  109. $columns,
  110. $column_model,
  111. $extra_params,
  112. [],
  113. $action_links,
  114. true
  115. );
  116. ?>
  117. });
  118. </script>
  119. <?php
  120. $obj = new GradeModel();
  121. // Action handling: Add
  122. switch ($action) {
  123. case 'add':
  124. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  125. api_not_allowed();
  126. }
  127. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  128. $form = $obj->return_form($url, 'add');
  129. // The validation or display
  130. if ($form->validate()) {
  131. if ($check) {
  132. $values = $form->exportValues();
  133. $res = $obj->save($values);
  134. if ($res) {
  135. echo Display::return_message(get_lang('ItemAdded'), 'confirm');
  136. }
  137. }
  138. $obj->display();
  139. } else {
  140. echo '<div class="actions">';
  141. echo '<a href="'.api_get_self().'">'.
  142. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).
  143. '</a>';
  144. echo '</div>';
  145. $form->addElement('hidden', 'sec_token');
  146. $form->setConstants(['sec_token' => $token]);
  147. $form->display();
  148. }
  149. break;
  150. case 'edit':
  151. // Action handling: Editing
  152. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  153. $form = $obj->return_form($url, 'edit');
  154. // The validation or display
  155. if ($form->validate()) {
  156. if ($check) {
  157. $values = $form->exportValues();
  158. $res = $obj->update($values);
  159. echo Display::return_message(get_lang('ItemUpdated'), 'confirm', false);
  160. }
  161. $obj->display();
  162. } else {
  163. echo '<div class="actions">';
  164. echo '<a href="'.api_get_self().'">'.
  165. Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).
  166. '</a>';
  167. echo '</div>';
  168. $form->addElement('hidden', 'sec_token');
  169. $form->setConstants(['sec_token' => $token]);
  170. $form->display();
  171. }
  172. break;
  173. case 'delete':
  174. // Action handling: delete
  175. if ($check) {
  176. $res = $obj->delete($_GET['id']);
  177. if ($res) {
  178. echo Display::return_message(get_lang('ItemDeleted'), 'confirm');
  179. }
  180. }
  181. $obj->display();
  182. break;
  183. default:
  184. $obj->display();
  185. break;
  186. }
  187. echo '<script> $(document).ready(function(){ $("input").removeClass("form-control"); }); </script>';
  188. Display::display_footer();