gradebook_scoring_system.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. require_once '../inc/global.inc.php';
  8. api_block_anonymous_users();
  9. if (api_get_setting('teachers_can_change_score_settings') != 'true') {
  10. api_not_allowed();
  11. }
  12. $htmlHeadXtra[]= '<script>
  13. function plusItem(item) {
  14. document.getElementById(item).style.display = "inline";
  15. document.getElementById("plus-"+item).style.display = "none";
  16. document.getElementById("min-"+(item-1)).style.display = "none";
  17. document.getElementById("min-"+(item)).style.display = "inline";
  18. document.getElementById("plus-"+(item+1)).style.display = "inline";
  19. //document.getElementById("txta-"+(item)).value = "100";
  20. //document.getElementById("txta-"+(item-1)).value = "";
  21. }
  22. function minItem(item) {
  23. if (item != 1) {
  24. document.getElementById(item).style.display = "none";
  25. document.getElementById("txta-"+item).value = "";
  26. document.getElementById("txtb-"+item).value = "";
  27. document.getElementById("plus-"+item).style.display = "inline";
  28. document.getElementById("min-"+(item-1)).style.display = "inline";
  29. document.getElementById("txta-"+(item-1)).value = "100";
  30. }
  31. if (item = 1) {
  32. document.getElementById("min-"+(item)).style.display = "none";
  33. }
  34. }
  35. </script>';
  36. $interbreadcrumb[] = array(
  37. 'url' => $_SESSION['gradebook_dest'].'?selectcat=1',
  38. 'name' => get_lang('ToolGradebook')
  39. );
  40. $select_cat = intval($_GET['selectcat']);
  41. $displayscore= ScoreDisplay :: instance();
  42. $customdisplays = $displayscore->get_custom_score_display_settings();
  43. $nr_items = (count($customdisplays) != '0' )? count($customdisplays) : '1';
  44. $scoreform = new ScoreDisplayForm(
  45. 'scoring_system_form',
  46. api_get_self().'?selectcat='.$select_cat.'&'.api_get_cidreq()
  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=' . $select_cat.'&'.api_get_cidreq());
  74. exit;
  75. }
  76. $scorecolpercent = 0;
  77. if ($displayscore->is_coloring_enabled()) {
  78. $scorecolpercent = $values['scorecolpercent'];
  79. }
  80. if ($displayscore->is_custom() && !empty($scoringdisplay)) {
  81. $displayscore->update_custom_score_display_settings($scoringdisplay, $scorecolpercent);
  82. }
  83. header('Location:'.api_get_self().'?scoringupdated=&selectcat='.$select_cat.'&'.api_get_cidreq());
  84. exit;
  85. }
  86. $this_section = SECTION_COURSES;
  87. Display :: display_header(get_lang('ScoreEdit'));
  88. if (((isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') ||
  89. (isset($_GET['selectcat']) && ($_SESSION['studentview']=='teacherview')))
  90. ) {
  91. if (isset ($_GET['scoringupdated'])) {
  92. Display::display_confirmation_message(get_lang('ScoringUpdated'), false);
  93. }
  94. if (isset ($_GET['nouniqueranges'])) {
  95. Display::display_error_message(get_lang('NoUniqueScoreRanges'), false);
  96. }
  97. $scoreform->display();
  98. }
  99. Display::display_footer();