gradebook_scoring_system.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <?php // $Id: $
  2. /* For licensing terms, see /license.txt */
  3. $language_file= 'gradebook';
  4. //$cidReset= true;
  5. require_once ('../inc/global.inc.php');
  6. require_once ('lib/be.inc.php');
  7. require_once ('lib/gradebook_functions.inc.php');
  8. require_once ('lib/fe/scoredisplayform.class.php');
  9. require_once ('lib/scoredisplay.class.php');
  10. api_block_anonymous_users();
  11. //api_protect_admin_script();
  12. $htmlHeadXtra[]= '
  13. <script language="JavaScript">
  14. function plusItem(item)
  15. {
  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. {
  26. if (item != 1)
  27. {
  28. document.getElementById(item).style.display = "none";
  29. document.getElementById("txta-"+item).value = "";
  30. document.getElementById("txtb-"+item).value = "";
  31. document.getElementById("plus-"+item).style.display = "inline";
  32. document.getElementById("min-"+(item-1)).style.display = "inline";
  33. document.getElementById("txta-"+(item-1)).value = "100";
  34. }
  35. if (item = 1)
  36. {
  37. document.getElementById("min-"+(item)).style.display = "none";
  38. }
  39. }
  40. </script>';
  41. $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('ToolGradebook'));
  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('scoring_system_form',
  46. api_get_self() . '?selectcat=' . $_GET['selectcat']
  47. );
  48. if ($scoreform->validate()) {
  49. $value_export='';
  50. $value_export=$scoreform->exportValues();
  51. $value_export=isset($value_export) ? $scoreform->exportValues(): '';
  52. $values= $value_export;
  53. // create new array of custom display settings
  54. // this loop also checks if all score ranges are unique
  55. $scoringdisplay= array ();
  56. $ranges_ok = true;
  57. $endscore= isset($values['endscore']) ? $values['endscore'] : null;
  58. $displaytext=isset($values['displaytext']) ? $values['displaytext'] : null;
  59. for ($counter= 1; $ranges_ok && $counter <= 20; $counter++) {
  60. $setting= array ();
  61. $setting['score']= $endscore[$counter];
  62. $setting['display']= $displaytext[$counter];
  63. if (!empty($setting['score'])) {
  64. foreach ($scoringdisplay as $passed_entry) {
  65. if ($passed_entry['score'] == $setting['score']) {
  66. $ranges_ok = false;
  67. }
  68. }
  69. $scoringdisplay[]= $setting;
  70. }
  71. }
  72. if (!$ranges_ok) {
  73. header('Location: ' . api_get_self() . '?nouniqueranges=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  74. exit;
  75. }
  76. // update color settings
  77. $val_enablescorecolor=isset($values['enablescorecolor']) ? $values['enablescorecolor'] : null;
  78. $displayscore->set_coloring_enabled(($val_enablescorecolor == '1') ? true : false);
  79. if ($displayscore->is_coloring_enabled()) {
  80. $displayscore->set_color_split_value($values['scorecolpercent']);
  81. }
  82. // update custom display settings
  83. $val_enablescore=isset($values['enablescore']) ? $values['enablescore'] : null;
  84. $val_includeupperlimit=isset($values['includeupperlimit']) ? $values['includeupperlimit'] : null;
  85. $displayscore->set_custom(($val_enablescore == '1') ? true : false);
  86. $displayscore->set_upperlimit_included(($val_includeupperlimit == '1') ? true : false);
  87. if ($displayscore->is_custom() && !empty($scoringdisplay)) {
  88. $displayscore->update_custom_score_display_settings($scoringdisplay);
  89. }
  90. header('Location: ' . api_get_self() . '?scoringupdated=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  91. exit;
  92. }
  93. Display :: display_header(get_lang('ScoreEdit'));
  94. if (((isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') || (isset($_GET['selectcat']) && ($_SESSION['studentview']=='teacherview')))) {
  95. if (isset ($_GET['scoringupdated'])) {
  96. Display :: display_confirmation_message(get_lang('ScoringUpdated'),false);
  97. }
  98. if (isset ($_GET['nouniqueranges'])) {
  99. Display :: display_error_message(get_lang('NoUniqueScoreRanges'),false);
  100. }
  101. echo '<div class="maincontent">';
  102. $scoreform->display();
  103. echo '</div>';
  104. }
  105. Display :: display_footer();