gradebook_scoring_system.php 4.0 KB

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