gradebook_scoring_system.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php // $Id: $
  2. /*
  3. ==============================================================================
  4. Dokeos - elearning and course management software
  5. Copyright (c) 2008 Dokeos Latinoamerica SAC
  6. Copyright (c) 2006 Dokeos SPRL
  7. Copyright (c) 2006 Ghent University (UGent)
  8. Copyright (c) various contributors
  9. For a full list of contributors, see "credits.txt".
  10. The full license can be read in "license.txt".
  11. This program is free software; you can redistribute it and/or
  12. modify it under the terms of the GNU General Public License
  13. as published by the Free Software Foundation; either version 2
  14. of the License, or (at your option) any later version.
  15. See the GNU General Public License for more details.
  16. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  17. Mail: info@dokeos.com
  18. ==============================================================================
  19. */
  20. $language_file= 'gradebook';
  21. //$cidReset= true;
  22. require_once ('../inc/global.inc.php');
  23. require_once ('lib/be.inc.php');
  24. require_once ('lib/gradebook_functions.inc.php');
  25. require_once ('lib/fe/scoredisplayform.class.php');
  26. require_once ('lib/scoredisplay.class.php');
  27. api_block_anonymous_users();
  28. //api_protect_admin_script();
  29. $htmlHeadXtra[]= '
  30. <script language="JavaScript">
  31. function plusItem(item)
  32. {
  33. document.getElementById(item).style.display = "inline";
  34. document.getElementById("plus-"+item).style.display = "none";
  35. document.getElementById("min-"+(item-1)).style.display = "none";
  36. document.getElementById("min-"+(item)).style.display = "inline";
  37. document.getElementById("plus-"+(item+1)).style.display = "inline";
  38. document.getElementById("txta-"+(item)).value = "100";
  39. document.getElementById("txta-"+(item-1)).value = "";
  40. }
  41. function minItem(item)
  42. {
  43. if (item != 1)
  44. {
  45. document.getElementById(item).style.display = "none";
  46. document.getElementById("txta-"+item).value = "";
  47. document.getElementById("txtb-"+item).value = "";
  48. document.getElementById("plus-"+item).style.display = "inline";
  49. document.getElementById("min-"+(item-1)).style.display = "inline";
  50. document.getElementById("txta-"+(item-1)).value = "100";
  51. }
  52. if (item = 1)
  53. {
  54. document.getElementById("min-"+(item)).style.display = "none";
  55. }
  56. }
  57. </script>';
  58. $interbreadcrumb[]= array (
  59. 'url' => $_SESSION['gradebook_dest'],
  60. 'name' => get_lang('Gradebook'
  61. ));
  62. $displayscore= ScoreDisplay :: instance();
  63. $customdisplays = $displayscore->get_custom_score_display_settings();
  64. $nr_items =(count($customdisplays)!='0')?count($customdisplays):'1';
  65. $scoreform= new ScoreDisplayForm('scoring_system_form',
  66. api_get_self() . '?selectcat=' . $_GET['selectcat']
  67. );
  68. if ($scoreform->validate()) {
  69. $value_export='';
  70. $value_export=$scoreform->exportValues();
  71. $value_export=isset($value_export) ? $scoreform->exportValues(): '';
  72. $values= $value_export;
  73. // create new array of custom display settings
  74. // this loop also checks if all score ranges are unique
  75. $scoringdisplay= array ();
  76. $ranges_ok = true;
  77. $endscore= isset($values['endscore']) ? $values['endscore'] : null;
  78. $displaytext=isset($values['displaytext']) ? $values['displaytext'] : null;
  79. for ($counter= 1; $ranges_ok && $counter <= 20; $counter++) {
  80. $setting= array ();
  81. $setting['score']= $endscore[$counter];
  82. $setting['display']= $displaytext[$counter];
  83. if (!empty($setting['score'])) {
  84. foreach ($scoringdisplay as $passed_entry) {
  85. if ($passed_entry['score'] == $setting['score']) {
  86. $ranges_ok = false;
  87. }
  88. }
  89. $scoringdisplay[]= $setting;
  90. }
  91. }
  92. if (!$ranges_ok) {
  93. header('Location: ' . api_get_self() . '?nouniqueranges=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  94. exit;
  95. }
  96. // update color settings
  97. $val_enablescorecolor=isset($values['enablescorecolor']) ? $values['enablescorecolor'] : null;
  98. $displayscore->set_coloring_enabled(($val_enablescorecolor == '1') ? true : false);
  99. if ($displayscore->is_coloring_enabled()) {
  100. $displayscore->set_color_split_value($values['scorecolpercent']);
  101. }
  102. // update custom display settings
  103. $val_enablescore=isset($values['enablescore']) ? $values['enablescore'] : null;
  104. $val_includeupperlimit=isset($values['includeupperlimit']) ? $values['includeupperlimit'] : null;
  105. $displayscore->set_custom(($val_enablescore == '1') ? true : false);
  106. $displayscore->set_upperlimit_included(($val_includeupperlimit == '1') ? true : false);
  107. if ($displayscore->is_custom() && !empty($scoringdisplay)) {
  108. $displayscore->update_custom_score_display_settings($scoringdisplay);
  109. }
  110. header('Location: ' . api_get_self() . '?scoringupdated=&selectcat=' . Security::remove_XSS($_GET['selectcat']));
  111. exit;
  112. }
  113. Display :: display_header(get_lang('ScoreEdit'));
  114. if (((isset($_GET['isStudentView']) && $_GET['isStudentView']=='false') || (isset($_GET['selectcat']) && ($_SESSION['studentview']=='teacherview')))) {
  115. if (isset ($_GET['scoringupdated'])) {
  116. Display :: display_confirmation_message(get_lang('ScoringUpdated'),false);
  117. }
  118. if (isset ($_GET['nouniqueranges'])) {
  119. Display :: display_error_message(get_lang('NoUniqueScoreRanges'),false);
  120. }
  121. echo '<div class="maincontent">';
  122. $scoreform->display();
  123. echo '</div>';
  124. }
  125. Display :: display_footer();