grade_models.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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[] = array('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[] = array('url' => 'grade_models.php', 'name' => get_lang('GradeModel'));
  22. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Add'));
  23. } elseif ($action == 'edit') {
  24. $interbreadcrumb[] = array('url' => 'grade_models.php', 'name' => get_lang('GradeModel'));
  25. $interbreadcrumb[] = array('url' => '#', 'name' => get_lang('Edit'));
  26. } else {
  27. $interbreadcrumb[] = array('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 = array(
  63. get_lang('Name'),
  64. get_lang('Description'),
  65. get_lang('Actions'),
  66. );
  67. //Column config
  68. $column_model = array(
  69. array(
  70. 'name' => 'name',
  71. 'index' => 'name',
  72. 'width' => '80',
  73. 'align' => 'left'
  74. ),
  75. array(
  76. 'name' => 'description',
  77. 'index' => 'description',
  78. 'width' => '500',
  79. 'align' => 'left',
  80. 'sortable' => 'false'
  81. ),
  82. array(
  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. array(),
  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. Display::display_confirmation_message(get_lang('ItemAdded'));
  136. }
  137. }
  138. $obj->display();
  139. } else {
  140. echo '<div class="actions">';
  141. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  142. echo '</div>';
  143. $form->addElement('hidden', 'sec_token');
  144. $form->setConstants(array('sec_token' => $token));
  145. $form->display();
  146. }
  147. break;
  148. case 'edit':
  149. // Action handling: Editing
  150. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  151. $form = $obj->return_form($url, 'edit');
  152. // The validation or display
  153. if ($form->validate()) {
  154. if ($check) {
  155. $values = $form->exportValues();
  156. $res = $obj->update($values);
  157. Display::display_confirmation_message(get_lang('ItemUpdated'), false);
  158. }
  159. $obj->display();
  160. } else {
  161. echo '<div class="actions">';
  162. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png', get_lang('Back'), '', ICON_SIZE_MEDIUM).'</a>';
  163. echo '</div>';
  164. $form->addElement('hidden', 'sec_token');
  165. $form->setConstants(array('sec_token' => $token));
  166. $form->display();
  167. }
  168. break;
  169. case 'delete':
  170. // Action handling: delete
  171. if ($check) {
  172. $res = $obj->delete($_GET['id']);
  173. if ($res) {
  174. Display::display_confirmation_message(get_lang('ItemDeleted'));
  175. }
  176. }
  177. $obj->display();
  178. break;
  179. default:
  180. $obj->display();
  181. break;
  182. }
  183. echo '<script> $(document).ready(function(){ $("input").removeClass("form-control"); }); </script>';
  184. Display :: display_footer();