scoredisplayform.class.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Script
  5. * @package chamilo.gradebook
  6. */
  7. /**
  8. * Init
  9. */
  10. require_once dirname(__FILE__).'/../../../inc/global.inc.php';
  11. require_once dirname(__FILE__).'/../gradebook_functions.inc.php';
  12. /**
  13. * Form for the score display dialog
  14. * @author Stijn Konings
  15. * @author Bert Steppé
  16. * @package chamilo.gradebook
  17. */
  18. class ScoreDisplayForm extends FormValidator
  19. {
  20. function ScoreDisplayForm($form_name, $action= null) {
  21. parent :: __construct($form_name, 'post', $action);
  22. $displayscore = ScoreDisplay :: instance();
  23. $customdisplays = $displayscore->get_custom_score_display_settings();
  24. $nr_items = (count($customdisplays)!='0') ? count($customdisplays) : '1';
  25. $this->setDefaults(array (
  26. 'scorecolpercent' => $displayscore->get_color_split_value()
  27. ));
  28. $this->addElement('hidden', 'maxvalue', '100');
  29. $this->addElement('hidden', 'minvalue', '0');
  30. $counter= 1;
  31. //setting the default values
  32. if(is_array($customdisplays)) {
  33. foreach ($customdisplays as $customdisplay) {
  34. $this->setDefaults(array (
  35. 'endscore[' . $counter . ']' => $customdisplay['score'],
  36. 'displaytext[' . $counter . ']' => $customdisplay['display']
  37. ));
  38. $counter++;
  39. }
  40. }
  41. $scorecol = array();
  42. //settings for the colored score
  43. $this->addElement('header', get_lang('ScoreEdit'));
  44. if ($displayscore->is_coloring_enabled()) {
  45. $this->addElement('html', '<b>' . get_lang('ScoreColor') . '</b>');
  46. $this->addElement('text', 'scorecolpercent', array(get_lang('Below'), get_lang('WillColorRed'), '%'), array (
  47. 'size' => 5,
  48. 'maxlength' => 5,
  49. 'class'=>'span1',
  50. ));
  51. if (api_get_setting('teachers_can_change_score_settings') != 'true') {
  52. $this->freeze('scorecolpercent');
  53. }
  54. $this->addRule('scorecolpercent', get_lang('OnlyNumbers'), 'numeric');
  55. $this->addRule(array('scorecolpercent','maxvalue'), get_lang('Over100'), 'compare', '<=');
  56. $this->addRule(array('scorecolpercent','minvalue'), get_lang('UnderMin'), 'compare', '>');
  57. }
  58. //Settings for the scoring system
  59. if ($displayscore->is_custom()) {
  60. $this->addElement('html', '<br /><b>' . get_lang('ScoringSystem') . '</b>');
  61. $this->addElement('static', null, null, get_lang('ScoreInfo'));
  62. $scorenull[]= & $this->CreateElement('static', null, null, get_lang('Between'));
  63. $this->setDefaults(array (
  64. 'beginscore' => '0'
  65. ));
  66. $scorenull[]= & $this->CreateElement('text', 'beginscore', null, array (
  67. 'size' => 5,
  68. 'maxlength' => 5,
  69. 'disabled' => 'disabled'
  70. ));
  71. $scorenull[]= & $this->CreateElement('static', null, null, ' %');
  72. $this->addGroup($scorenull, '', '', ' ');
  73. for ($counter= 1; $counter <= 20; $counter++) {
  74. $renderer =& $this->defaultRenderer();
  75. $elementTemplateTwoLabel =
  76. '<div id=' . $counter . ' style="display: '.(($counter<=$nr_items)?'inline':'none').';" class="control-group">
  77. <p><!-- BEGIN required --><span class="form_required">*</span> <!-- END required -->
  78. <label class="control-label">{label}</label>
  79. <div class="controls"><!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error --> <br/>&nbsp<b>'.get_lang('And').'</b>&nbsp&nbsp&nbsp&nbsp&nbsp{element}&nbsp%&nbsp&nbsp=';
  80. $elementTemplateTwoLabel2 =
  81. '<!-- BEGIN error --><span class="form_error">{error}</span><br /><!-- END error -->&nbsp{element}
  82. <a href="javascript:plusItem(' . ($counter+1) . ')"><img style="display: '.(($counter>=$nr_items)?'inline':'none').';" id="plus-' . ($counter+1) . '" src="../img/icons/22/add.png" alt="'.get_lang('Add').'" title="'.get_lang('Add').'"></img></a>
  83. <a href="javascript:minItem(' . ($counter) . ')"><img style="display: '.(($counter>=$nr_items && $counter!=1)?'inline':'none').';" id="min-' . $counter . '" src="../img/delete.png" alt="'.get_lang('Delete').'" title="'.get_lang('Delete').'"></img></a>
  84. </div></p></div>';
  85. $scorebetw= array ();
  86. $this->addElement('text', 'endscore[' . $counter . ']', null, array (
  87. 'size' => 5,
  88. 'maxlength' => 5,
  89. 'id' => 'txta-'.$counter,
  90. 'class' => 'span1',
  91. ));
  92. $this->addElement('text', 'displaytext[' . $counter . ']', null,array (
  93. 'size' => 40,
  94. 'maxlength' => 40,
  95. 'id' => 'txtb-'.$counter,
  96. 'class' => 'span',
  97. ));
  98. $renderer->setElementTemplate($elementTemplateTwoLabel,'endscore[' . $counter . ']');
  99. $renderer->setElementTemplate($elementTemplateTwoLabel2,'displaytext[' . $counter . ']');
  100. $this->addRule('endscore[' . $counter . ']', get_lang('OnlyNumbers'), 'numeric');
  101. $this->addRule(array ('endscore[' . $counter . ']', 'maxvalue'), get_lang('Over100'), 'compare', '<=');
  102. $this->addRule(array ('endscore[' . $counter . ']', 'minvalue'), get_lang('UnderMin'), 'compare', '>');
  103. }
  104. }
  105. if ($displayscore->is_custom())
  106. $this->addElement('style_submit_button', 'submit', get_lang('Ok'),'class="save"');
  107. }
  108. function validate() {
  109. return parent :: validate();
  110. }
  111. }