grade_models.php 6.6 KB

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