grade_models.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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();
  10. if (api_get_setting('gradebook_enable_grade_model') != 'true') {
  11. api_not_allowed();
  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(get_lang('Name'), get_lang('Description'), get_lang('Actions'));
  61. //Column config
  62. $column_model = array(
  63. array('name'=>'name', 'index'=>'name', 'width'=>'80', 'align'=>'left'),
  64. array('name'=>'description', 'index'=>'description', 'width'=>'500', 'align'=>'left','sortable'=>'false'),
  65. array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left','formatter'=>'action_formatter','sortable'=>'false')
  66. );
  67. //Autowidth
  68. $extra_params['autowidth'] = 'true';
  69. //height auto
  70. $extra_params['height'] = 'auto';
  71. //With this function we can add actions to the jgrid (edit, delete, etc)
  72. $action_links = 'function action_formatter(cellvalue, options, rowObject) {
  73. return \'<a href="?action=edit&id=\'+options.rowId+\'">'.Display::return_icon('edit.png',get_lang('Edit'),'',ICON_SIZE_SMALL).'</a>'.
  74. '&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>'.
  75. '\';
  76. }';
  77. ?>
  78. <script>
  79. $(function() {
  80. <?php
  81. // grid definition see the $obj->display() function
  82. echo Display::grid_js('grade_model', $url, $columns, $column_model, $extra_params, array(), $action_links,true);
  83. ?>
  84. });
  85. </script>
  86. <?php
  87. $obj = new GradeModel();
  88. // Action handling: Add
  89. switch ($action) {
  90. case 'add':
  91. if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) {
  92. api_not_allowed();
  93. }
  94. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']);
  95. $form = $obj->return_form($url, 'add');
  96. // The validation or display
  97. if ($form->validate()) {
  98. if ($check) {
  99. $values = $form->exportValues();
  100. $res = $obj->save($values);
  101. if ($res) {
  102. Display::display_confirmation_message(get_lang('ItemAdded'));
  103. }
  104. }
  105. $obj->display();
  106. } else {
  107. echo '<div class="actions">';
  108. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  109. echo '</div>';
  110. $form->addElement('hidden', 'sec_token');
  111. $form->setConstants(array('sec_token' => $token));
  112. $form->display();
  113. }
  114. break;
  115. case 'edit':
  116. // Action handling: Editing
  117. $url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']);
  118. $form = $obj->return_form($url, 'edit');
  119. // The validation or display
  120. if ($form->validate()) {
  121. if ($check) {
  122. $values = $form->exportValues();
  123. $res = $obj->update($values);
  124. Display::display_confirmation_message(get_lang('ItemUpdated'), false);
  125. }
  126. $obj->display();
  127. } else {
  128. echo '<div class="actions">';
  129. echo '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  130. echo '</div>';
  131. $form->addElement('hidden', 'sec_token');
  132. $form->setConstants(array('sec_token' => $token));
  133. $form->display();
  134. }
  135. break;
  136. case 'delete':
  137. // Action handling: delete
  138. if ($check) {
  139. $res = $obj->delete($_GET['id']);
  140. if ($res) {
  141. Display::display_confirmation_message(get_lang('ItemDeleted'));
  142. }
  143. }
  144. $obj->display();
  145. break;
  146. default:
  147. $obj->display();
  148. break;
  149. }
  150. Display :: display_footer();