grade_models.php 6.4 KB

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