gradebook_scoring_system.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script.
  5. *
  6. * @package chamilo.gradebook
  7. */
  8. require_once __DIR__.'/../inc/global.inc.php';
  9. api_block_anonymous_users();
  10. GradebookUtils::block_students();
  11. if (api_get_setting('teachers_can_change_score_settings') != 'true') {
  12. api_not_allowed();
  13. }
  14. $htmlHeadXtra[] = '<script>
  15. function plusItem(item) {
  16. document.getElementById(item).style.display = "inline";
  17. document.getElementById("plus-"+item).style.display = "none";
  18. document.getElementById("min-"+(item-1)).style.display = "none";
  19. document.getElementById("min-"+(item)).style.display = "inline";
  20. document.getElementById("plus-"+(item+1)).style.display = "inline";
  21. //document.getElementById("txta-"+(item)).value = "100";
  22. //document.getElementById("txta-"+(item-1)).value = "";
  23. }
  24. function minItem(item) {
  25. if (item != 1) {
  26. document.getElementById(item).style.display = "none";
  27. document.getElementById("txta-"+item).value = "";
  28. document.getElementById("txtb-"+item).value = "";
  29. document.getElementById("plus-"+item).style.display = "inline";
  30. document.getElementById("min-"+(item-1)).style.display = "inline";
  31. document.getElementById("txta-"+(item-1)).value = "100";
  32. }
  33. if (item = 1) {
  34. document.getElementById("min-"+(item)).style.display = "none";
  35. }
  36. }
  37. </script>';
  38. $interbreadcrumb[] = [
  39. 'url' => Category::getUrl().'selectcat=1',
  40. 'name' => get_lang('ToolGradebook'),
  41. ];
  42. $select_cat = intval($_GET['selectcat']);
  43. $displayScore = ScoreDisplay :: instance();
  44. $customdisplays = $displayScore->get_custom_score_display_settings();
  45. $nr_items = count($customdisplays) != '0' ? count($customdisplays) : '1';
  46. $scoreform = new ScoreDisplayForm(
  47. 'scoring_system_form',
  48. api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq()
  49. );
  50. if ($scoreform->validate()) {
  51. $value_export = $scoreform->exportValues();
  52. $value_export = isset($value_export) ? $scoreform->exportValues() : '';
  53. $values = $value_export;
  54. // create new array of custom display settings
  55. // this loop also checks if all score ranges are unique
  56. $scoringDisplay = [];
  57. $ranges_ok = true;
  58. $endscore = isset($values['endscore']) ? $values['endscore'] : null;
  59. $displaytext = isset($values['displaytext']) ? $values['displaytext'] : null;
  60. for ($counter = 1; $ranges_ok && $counter <= 20; $counter++) {
  61. $setting = [];
  62. $setting['score'] = $endscore[$counter];
  63. $setting['display'] = $displaytext[$counter];
  64. if (!empty($setting['score'])) {
  65. foreach ($scoringDisplay as $passed_entry) {
  66. if ($passed_entry['score'] == $setting['score']) {
  67. $ranges_ok = false;
  68. }
  69. }
  70. $scoringDisplay[] = $setting;
  71. }
  72. }
  73. if (!$ranges_ok) {
  74. Display::addFlash(
  75. Display::return_message(
  76. get_lang('NoUniqueScoreRanges'),
  77. 'error',
  78. false
  79. )
  80. );
  81. header('Location: '.api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq());
  82. exit;
  83. }
  84. $scorecolpercent = 0;
  85. if ($displayScore->is_coloring_enabled()) {
  86. $scorecolpercent = $values['scorecolpercent'];
  87. }
  88. if ($displayScore->is_custom() && !empty($scoringDisplay)) {
  89. $displayScore->update_custom_score_display_settings(
  90. $scoringDisplay,
  91. $scorecolpercent
  92. );
  93. }
  94. Display::addFlash(
  95. Display::return_message(get_lang('ScoringUpdated'), 'confirm', false)
  96. );
  97. header('Location:'.api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq());
  98. exit;
  99. }
  100. $this_section = SECTION_COURSES;
  101. Display::display_header(get_lang('ScoreEdit'));
  102. $scoreform->display();
  103. Display::display_footer();