grade_models.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use Chamilo\CoreBundle\Framework\Container;
  4. /**
  5. * @package chamilo.admin
  6. */
  7. $cidReset = true;
  8. $this_section = SECTION_PLATFORM_ADMIN;
  9. api_protect_admin_script();
  10. if (api_get_setting('gradebook.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' => Container::getRouter()->generate('administration'),'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. // The header.
  59. Display::display_header($tool_name);
  60. //jqgrid will use this URL to do the selects
  61. $url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_grade_models';
  62. //The order is important you need to check the the $column variable in the model.ajax.php file
  63. $columns = array(
  64. get_lang('Name'),
  65. get_lang('Description'),
  66. get_lang('Actions'),
  67. );
  68. //Column config
  69. $column_model = array(
  70. array(
  71. 'name' => 'name',
  72. 'index' => 'name',
  73. 'width' => '80',
  74. 'align' => 'left'
  75. ),
  76. array(
  77. 'name' => 'description',
  78. 'index' => 'description',
  79. 'width' => '500',
  80. 'align' => 'left',
  81. 'sortable' => 'false'
  82. ),
  83. array(
  84. 'name' => 'actions',
  85. 'index' => 'actions',
  86. 'width' => '100',
  87. 'align' => 'left',
  88. 'formatter' => 'action_formatter',
  89. 'sortable' => 'false'
  90. )
  91. );
  92. //Autowidth
  93. $extra_params['autowidth'] = 'true';
  94. //height auto
  95. $extra_params['height'] = 'auto';
  96. //With this function we can add actions to the jgrid (edit, delete, etc)
  97. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  98. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  99. '&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>'.
  100. '\';
  101. }';
  102. ?>
  103. <script>
  104. $(function() {
  105. <?php
  106. // grid definition see the $obj->display() function
  107. echo Display::grid_js(
  108. 'grade_model',
  109. $url,
  110. $columns,
  111. $column_model,
  112. $extra_params,
  113. array(),
  114. $action_links,
  115. true
  116. );
  117. ?>
  118. });
  119. </script>
  120. <?php
  121. $obj = new GradeModel();
  122. // Action handling: Add
  123. switch ($action) {
  124. case 'add':
  125. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  126. api_not_allowed();
  127. }
  128. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  129. $form = $obj->return_form($url, 'add');
  130. // The validation or display
  131. if ($form->validate()) {
  132. if ($check) {
  133. $values = $form->exportValues();
  134. $res = $obj->save($values);
  135. if ($res) {
  136. Display::display_confirmation_message(get_lang('ItemAdded'));
  137. }
  138. }
  139. $obj->display();
  140. } else {
  141. echo '<div class="actions">';
  142. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  143. echo '</div>';
  144. $form->addElement('hidden', 'sec_token');
  145. $form->setConstants(array('sec_token' => $token));
  146. $form->display();
  147. }
  148. break;
  149. case 'edit':
  150. // Action handling: Editing
  151. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  152. $form = $obj->return_form($url, 'edit');
  153. // The validation or display
  154. if ($form->validate()) {
  155. if ($check) {
  156. $values = $form->exportValues();
  157. $res = $obj->update($values);
  158. Display::display_confirmation_message(get_lang('ItemUpdated'), false);
  159. }
  160. $obj->display();
  161. } else {
  162. echo '<div class="actions">';
  163. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  164. echo '</div>';
  165. $form->addElement('hidden', 'sec_token');
  166. $form->setConstants(array('sec_token' => $token));
  167. $form->display();
  168. }
  169. break;
  170. case 'delete':
  171. // Action handling: delete
  172. if ($check) {
  173. $res = $obj->delete($_GET['id']);
  174. if ($res) {
  175. Display::display_confirmation_message(get_lang('ItemDeleted'));
  176. }
  177. }
  178. $obj->display();
  179. break;
  180. default:
  181. $obj->display();
  182. break;
  183. }
  184. echo '<script> $(document).ready(function(){ $("input").removeClass("form-control"); }); </script>';
  185. Display :: display_footer();