gradebook_scoring_system.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php // $Id: $
  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. $htmlHeadXtra[]= '
  20. <script language="JavaScript">
  21. function plusItem(item)
  22. {
  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. {
  33. if (item != 1)
  34. {
  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. {
  44. document.getElementById("min-"+(item)).style.display = "none";
  45. }
  46. }
  47. </script>';
  48. $interbreadcrumb[] = array ('url' => $_SESSION['gradebook_dest'].'?selectcat=1', 'name' => get_lang('ToolGradebook'));
  49. $select_cat = intval($_GET['selectcat']);
  50. $displayscore= ScoreDisplay :: instance();
  51. $customdisplays = $displayscore->get_custom_score_display_settings();
  52. $nr_items =(count($customdisplays)!='0')?count($customdisplays):'1';
  53. $scoreform= new ScoreDisplayForm('scoring_system_form', api_get_self() . '?selectcat=' . $select_cat);
  54. if ($scoreform->validate()) {
  55. $value_export='';
  56. $value_export=$scoreform->exportValues();
  57. $value_export=isset($value_export) ? $scoreform->exportValues(): '';
  58. $values= $value_export;
  59. // create new array of custom display settings
  60. // this loop also checks if all score ranges are unique
  61. $scoringdisplay= array ();
  62. $ranges_ok = true;
  63. $endscore= isset($values['endscore']) ? $values['endscore'] : null;
  64. $displaytext=isset($values['displaytext']) ? $values['displaytext'] : null;
  65. for ($counter= 1; $ranges_ok && $counter <= 20; $counter++) {
  66. $setting= array ();
  67. $setting['score']= $endscore[$counter];
  68. $setting['display']= $displaytext[$counter];
  69. if (!empty($setting['score'])) {
  70. foreach ($scoringdisplay as $passed_entry) {
  71. if ($passed_entry['score'] == $setting['score']) {
  72. $ranges_ok = false;
  73. }
  74. }
  75. $scoringdisplay[]= $setting;
  76. }
  77. }
  78. if (!$ranges_ok) {
  79. header('Location: ' . api_get_self() . '?nouniqueranges=&selectcat=' . $select_cat);
  80. exit;
  81. }
  82. // update color settings
  83. $val_enablescorecolor=isset($values['enablescorecolor']) ? $values['enablescorecolor'] : null;
  84. $displayscore->set_coloring_enabled(($val_enablescorecolor == '1') ? true : false);
  85. $scorecolpercent = 0;
  86. if ($displayscore->is_coloring_enabled()) {
  87. //$displayscore->set_color_split_value($values['scorecolpercent']);
  88. $scorecolpercent = $values['scorecolpercent'];
  89. }
  90. // update custom display settings
  91. $val_enablescore=isset($values['enablescore']) ? $values['enablescore'] : null;
  92. $val_includeupperlimit=isset($values['includeupperlimit']) ? $values['includeupperlimit'] : null;
  93. $displayscore->set_custom(($val_enablescore == '1') ? true : false);
  94. $displayscore->set_upperlimit_included(($val_includeupperlimit == '1') ? true : false);
  95. if ($displayscore->is_custom() && !empty($scoringdisplay)) {
  96. $displayscore->update_custom_score_display_settings($scoringdisplay, $scorecolpercent);
  97. }
  98. header('Location: ' . api_get_self() . '?scoringupdated=&selectcat=' . $select_cat);
  99. exit;
  100. }
  101. $this_section = SECTION_COURSES;
  102. Display :: display_header(get_lang('ScoreEdit'));
  103. if (((isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') || (isset($_GET['selectcat']) && ($_SESSION['studentview']=='teacherview')))) {
  104. if (isset ($_GET['scoringupdated'])) {
  105. Display :: display_confirmation_message(get_lang('ScoringUpdated'),false);
  106. }
  107. if (isset ($_GET['nouniqueranges'])) {
  108. Display :: display_error_message(get_lang('NoUniqueScoreRanges'),false);
  109. }
  110. $scoreform->display();
  111. }
  112. Display :: display_footer();