grade_models.php 6.3 KB

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