gradebook_scoring_system.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once __DIR__.'/../inc/global.inc.php';
  8. api_block_anonymous_users();
  9. GradebookUtils::block_students();
  10. if (api_get_setting('teachers_can_change_score_settings') != 'true') {
  11. api_not_allowed();
  12. }
  13. $htmlHeadXtra[] = '<script>
  14. function plusItem(item) {
  15. document.getElementById(item).style.display = "inline";
  16. document.getElementById("plus-"+item).style.display = "none";
  17. document.getElementById("min-"+(item-1)).style.display = "none";
  18. document.getElementById("min-"+(item)).style.display = "inline";
  19. document.getElementById("plus-"+(item+1)).style.display = "inline";
  20. //document.getElementById("txta-"+(item)).value = "100";
  21. //document.getElementById("txta-"+(item-1)).value = "";
  22. }
  23. function minItem(item) {
  24. if (item != 1) {
  25. document.getElementById(item).style.display = "none";
  26. document.getElementById("txta-"+item).value = "";
  27. document.getElementById("txtb-"+item).value = "";
  28. document.getElementById("plus-"+item).style.display = "inline";
  29. document.getElementById("min-"+(item-1)).style.display = "inline";
  30. document.getElementById("txta-"+(item-1)).value = "100";
  31. }
  32. if (item = 1) {
  33. document.getElementById("min-"+(item)).style.display = "none";
  34. }
  35. }
  36. </script>';
  37. $interbreadcrumb[] = array(
  38. 'url' => Category::getUrl().'selectcat=1',
  39. 'name' => get_lang('ToolGradebook')
  40. );
  41. $select_cat = intval($_GET['selectcat']);
  42. $displayScore = ScoreDisplay :: instance();
  43. $customdisplays = $displayScore->get_custom_score_display_settings();
  44. $nr_items = count($customdisplays) != '0' ? count($customdisplays) : '1';
  45. $scoreform = new ScoreDisplayForm(
  46. 'scoring_system_form',
  47. api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq()
  48. );
  49. if ($scoreform->validate()) {
  50. $value_export = '';
  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 = array();
  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 = array();
  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();