gradebook_scoring_system.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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. if (api_get_setting('teachers_can_change_score_settings') != 'true') {
  19. api_not_allowed();
  20. }
  21. $htmlHeadXtra[]= '<script>
  22. function plusItem(item) {
  23. document.getElementById(item).style.display = "inline";
  24. document.getElementById("plus-"+item).style.display = "none";
  25. document.getElementById("min-"+(item-1)).style.display = "none";
  26. document.getElementById("min-"+(item)).style.display = "inline";
  27. document.getElementById("plus-"+(item+1)).style.display = "inline";
  28. document.getElementById("txta-"+(item)).value = "100";
  29. document.getElementById("txta-"+(item-1)).value = "";
  30. }
  31. function minItem(item) {
  32. if (item != 1) {
  33. document.getElementById(item).style.display = "none";
  34. document.getElementById("txta-"+item).value = "";
  35. document.getElementById("txtb-"+item).value = "";
  36. document.getElementById("plus-"+item).style.display = "inline";
  37. document.getElementById("min-"+(item-1)).style.display = "inline";
  38. document.getElementById("txta-"+(item-1)).value = "100";
  39. }
  40. if (item = 1) {
  41. document.getElementById("min-"+(item)).style.display = "none";
  42. }
  43. }
  44. </script>';
  45. $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('ToolGradebook'));
  46. $select_cat = intval($_GET['selectcat']);
  47. $displayscore= ScoreDisplay :: instance();
  48. $customdisplays = $displayscore->get_custom_score_display_settings();
  49. $nr_items = (count($customdisplays) != '0' )? count($customdisplays) : '1';
  50. //Insert defaults
  51. if (empty($customdisplays)) {
  52. //$displayscore->insert_defaults($select_cat);
  53. }
  54. $scoreform= new ScoreDisplayForm('scoring_system_form', api_get_self() . '?selectcat=' . $select_cat);
  55. if ($scoreform->validate()) {
  56. $value_export='';
  57. $value_export=$scoreform->exportValues();
  58. $value_export=isset($value_export) ? $scoreform->exportValues(): '';
  59. $values= $value_export;
  60. // create new array of custom display settings
  61. // this loop also checks if all score ranges are unique
  62. $scoringdisplay= array ();
  63. $ranges_ok = true;
  64. $endscore= isset($values['endscore']) ? $values['endscore'] : null;
  65. $displaytext=isset($values['displaytext']) ? $values['displaytext'] : null;
  66. for ($counter= 1; $ranges_ok && $counter <= 20; $counter++) {
  67. $setting= array ();
  68. $setting['score']= $endscore[$counter];
  69. $setting['display']= $displaytext[$counter];
  70. if (!empty($setting['score'])) {
  71. foreach ($scoringdisplay as $passed_entry) {
  72. if ($passed_entry['score'] == $setting['score']) {
  73. $ranges_ok = false;
  74. }
  75. }
  76. $scoringdisplay[]= $setting;
  77. }
  78. }
  79. if (!$ranges_ok) {
  80. header('Location: ' . api_get_self() . '?nouniqueranges=&selectcat=' . $select_cat);
  81. exit;
  82. }
  83. $scorecolpercent = 0;
  84. if ($displayscore->is_coloring_enabled()) {
  85. $scorecolpercent = $values['scorecolpercent'];
  86. }
  87. if ($displayscore->is_custom() && !empty($scoringdisplay)) {
  88. $displayscore->update_custom_score_display_settings($scoringdisplay, $scorecolpercent);
  89. }
  90. header('Location: ' . api_get_self() . '?scoringupdated=&selectcat=' . $select_cat);
  91. exit;
  92. }
  93. $this_section = SECTION_COURSES;
  94. Display :: display_header(get_lang('ScoreEdit'));
  95. if (((isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') || (isset($_GET['selectcat']) && ($_SESSION['studentview']=='teacherview')))) {
  96. if (isset ($_GET['scoringupdated'])) {
  97. Display :: display_confirmation_message(get_lang('ScoringUpdated'),false);
  98. }
  99. if (isset ($_GET['nouniqueranges'])) {
  100. Display :: display_error_message(get_lang('NoUniqueScoreRanges'),false);
  101. }
  102. $scoreform->display();
  103. }
  104. Display :: display_footer();