<?php
/**
 * @copyright (c) Kufer Software GmbH, Loisachstrasse 4, D-84453 Mühldorf
 */

  
  class FormVarInput extends FormVarBasic
  {
    
    public $formgrptxt;

    public $inpmaxlen; 
    public $inpwidth;  
    
    public $addinfobtn;
    // Verwendung von Plus- und Minus-Button hinter dem Eingabefeld. (Für ++ bzw. --)
    public $addplusminus;

    
    public function __construct($formvarna, $formname, $formtext, $formgrptxt, $inpmaxlen, $inpwidth, $addinfobtn = false, $addplusminus = false)
    {
      
      parent::__construct($formvarna, $formname, $formtext);
      $this->formgrptxt = $formgrptxt;
      $this->inpmaxlen = $inpmaxlen;
      $this->inpwidth = $inpwidth;
      $this->addinfobtn = $addinfobtn;
      $this->addplusminus = $addplusminus;
    }

    
    public function ausgabeFormElem()
    {
      
      FormVarBasic::ausgabeFormElem();
      echo "<tr><th class='form'></th>";
      echo      "<td class='formelemtext'><label for='" . CleanOperations::cleanStringForHtml($this->formname) . "' class='" . CleanOperations::cleanStringForHtml($this->formname) . "'>" . CleanOperations::cleanStringForHtml($this->formtext) . '</label></td>'
                . "<td class='formelement'>";
      if ($this->addplusminus) {
        echo $this->getInputFieldPlusMinus($this->formname, $this->formvarna, $this->inpmaxlen, $this->formname);
      } else {
        echo $this->getInputField($this->formname, $this->formvarna, $this->inpmaxlen, $this->formname);
      }
      if ($this->addinfobtn) {
        echo $this->getAddInfoButton();
      }
      echo '</td>' . '</tr>';
    }

    
    public function getInputField($pName, $pValue, $pMaxLength = -1, $pID = '')
    {
      $priv = 2;

      return
        HTMLOperations::CreateInputTextField($pName, $priv, $pID, $pValue, 'width:' . $this->inpwidth . 'em;', $pMaxLength);
    }

    
    public function getInputFieldPlusMinus($pName, $pValue, $pMaxLength = -1, $pID = '')
    {
      return
        HTMLOperations::CreateInputTagPlusMinus($pName, $pID, 'bigger-null', $pValue, 'style="width:' . $this->inpwidth . 'em;"', false, $pMaxLength);
    }

    
    public function getAddInfoButton()
    {
      return '<div class=\'infobutton\'><img src="layout/button_up.gif" alt="erh&ouml;hen" title="erh&ouml;hen"'
             . ' onclick="incOrDecInputById(\'' . CleanOperations::cleanStringForJs($this->formname) . '\', true)">' . BR_WT
             . '<img src="layout/button_down.gif" alt="erniedrigen" title="erniedrigen"'
             . ' onclick="incOrDecInputById(\'' . CleanOperations::cleanStringForJs($this->formname) . '\', false)"></div>';
    }
  }