Source for file DBMS_FIELD_FLOAT.phpclass

Documentation is available at DBMS_FIELD_FLOAT.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_FLOAT.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   real
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version pk-07-08-09
  13.   ***/
  14.  
  15. /**
  16.  * requirements
  17.  */
  18.     require_once dirname(__FILE__)._OCSP_DIRSEP_."DBMS_FIELD.phpclass";
  19.     
  20.  
  21. /**
  22.   * Class DBMS_FIELD_FLOAT
  23.   *
  24.   * @project    Open CSP-Management
  25.   * @package    dbms_field
  26.   * @category   real
  27.   *
  28.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  29.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  30.   *
  31.   *
  32.   * @version pk-05-11-04
  33.   * @version pk-05-11-09
  34.   *
  35.   ***/
  36. class DBMS_FIELD_FLOAT extends DBMS_FIELD {
  37.     /**
  38.       * source file of the class
  39.       *
  40.       * @var string $classSrcFile 
  41.       * @since pk-05-02-19
  42.       ***/
  43.     protected $classSrcFile=__FILE__;
  44.         
  45.     protected $className     = "Float";
  46.     
  47.     protected $defaultValue  = 0.0;
  48.  
  49.     /**
  50.       * @var string $unit 
  51.       * @since pk-05-11-04
  52.       ***/
  53.     protected $unit          = "";
  54.  
  55.     /**
  56.       * @var string $pMask printf mask
  57.       * @since pk-05-11-09
  58.       ***/
  59.     protected $pMask          ="%01.2f";
  60.  
  61.     /**
  62.       * @var string $inputAdd overwrite default
  63.       * @since pk-06-12-04
  64.       ***/
  65.     protected $inputAdd="style=\"text-align:right;\"";
  66.  
  67.     // ###########################################################
  68.     // OBJECT SETTINGS METHODS
  69.     // ###########################################################
  70.  
  71.     // ###########################################################
  72.     // FIELD DEFINITION DATA METHODS
  73.     // ###########################################################
  74.  
  75.     /**
  76.       * returns an array of field to bie shown in the edit form
  77.       * by using editTbl_echoForm
  78.       *
  79.       * the array is in the form:
  80.       *
  81.       * <code>
  82.       * [_sectionName_]
  83.       *      [TITLE] -> string
  84.       *      [_rowName_]
  85.       *         [FLDLAB]  (complete html code with <td></td>)
  86.       *         [FLDVAL] (complete html code with <td></td>)
  87.       * </code>
  88.       *
  89.       * @param boolean $debug 
  90.       *
  91.       * @returns array
  92.       *
  93.       * @since pk-06-04-26
  94.       * @version pk-06-05-18
  95.       *
  96.       ***/
  97.     function editTbl_getFieldEditArr($debug=FALSE{
  98.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_DBSELECTLIST::editTbl_getFieldEditArr","",0);
  99.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  100.  
  101.         $a_ret['LAYOUT']['UNIT']=array(
  102.             'FLDLAB'=>"Einheit",
  103.             'FLDVAL'=>"<input name=\"UNIT\" type=\"input\" value=\"".$this->unit."\" size=\"10\">"
  104.         );
  105.         $a_ret['LAYOUT']['PFMASK']=array(
  106.             'FLDLAB'=>"printf Mask <a href=\"http://www.php.net/sprintf\" target=\"_blank\">?</a>",
  107.             'FLDVAL'=>"<input name=\"pMask\" type=\"input\" value=\"".$this->pMask."\" size=\"10\">"
  108.         );
  109.         return $a_ret;
  110.     }
  111.  
  112.     /**
  113.       * echos the filed definition form
  114.       *
  115.       * @param boolean $debug 
  116.       *
  117.       * @deprecated since pk-06-05-18
  118.       *
  119.       ***/
  120.      function editTblForm($debug=FALSE{
  121.         $a_FieldEditArr=$this->editTbl_getFieldEditArr($debug);
  122.  
  123.         $this->editTbl_echoForm($a_FieldEditArr,$debug);
  124.     }
  125.     ###############################
  126.  
  127.     /**
  128.       * saves the field definition
  129.       *
  130.       * @return boolean 
  131.       *
  132.       ***/
  133.     function save({
  134.         $retparent::save();
  135.         $this->unit=(isset($_POST['UNIT']$_POST['UNIT'$this->unit);
  136.         $this->pMask=(isset($_POST['pMask']$_POST['pMask'$this->pMask);
  137.         return $ret;
  138.     }
  139.  
  140. // ###########################################################
  141. // OBJECT HTML FORM METHODS
  142. // ###########################################################
  143.  
  144.     /**
  145.       * adds $this->unit to to parent::getInputTag()
  146.       *
  147.       * @param mixed $aValue the value to set
  148.       * @param string $arrName 
  149.       * @param string $nameAdd  append something to name like "[VALUE]" for search forms
  150.       *
  151.       * @return string 
  152.       *
  153.       * @since pk-05-11-04
  154.       *
  155.       ***/
  156.     function getInputTag($aValue,$arrName,$nameAdd=""{
  157.         
  158.         if (!stristr($this->inputAdd,'onkeypress'))
  159.         {
  160.             $this->inputAdd.=" onkeypress=\"return ocsp_form_keyNumber(event,false);\"";
  161.         }
  162.         
  163.         $ret=parent::getInputTag(doubleval($aValue),$arrName,$nameAdd);
  164.         $ret.=" ".$this->unit;
  165.         return $ret;
  166.     }
  167.  
  168.     /**
  169.       * returns the html code for the field value input / show
  170.       * adds $this->myName to ${$this->myDataArrName}['_DBMS_FIELDS']
  171.       *
  172.       * @param int $mode 
  173.       * @param mixed $aValue 
  174.       * @param boolean $debug 
  175.       *
  176.       * @returns string
  177.       *
  178.       * @since pk-06-04-24
  179.       *
  180.       ***/
  181.     function getFieldTag($mode,$aValue=NULL,$debug=FALSE{
  182.         if (empty($this->myDataArrName)) $this->myDataArrName="DBVAL";
  183.         global ${$this->myDataArrName};
  184.         $debug=($debug || $this->fldDebug);
  185.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FLOAT::getFieldTag","MODE$mode,".htmlspecialchars(substr($aValue,0,10)),0);
  186.  
  187.         $this->myCurrentMode=$mode/* </pk-05-02-25> */
  188.         $ret="";
  189.         switch($mode{
  190.             case FRM_MODE_LIST:
  191.                 return "<div style=\"text-align:right;\">".parent::getFieldTag($mode,$aValue,$debug)."</div>";
  192.             default:
  193.                 return parent::getFieldTag($mode,$aValue,$debug);
  194.         }
  195.     }
  196.  
  197.  
  198.  
  199.     /**
  200.       * echos the html representation of the field
  201.       *
  202.       * @param int $mode 
  203.       * @param mixed $aValue 
  204.       * @param string $arrname 
  205.       *
  206.       * @return boolean 
  207.       *
  208.       ***/
  209.     function writeField($mode,$aValue="",$arrName="DBVAL"{
  210.         $ret=parent::writeField($mode,$aValue,$arrName);
  211.         if ($mode != FRM_MODE_HIDDEN{
  212.             echo " ".$this->unit;
  213.         }
  214.         return $ret;
  215.     }
  216.  
  217.     /**
  218.       * returns the field value
  219.       *
  220.       * @param  string  $aValue     the value
  221.       * @param  array   $err        error array
  222.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  223.       * @param  bool    $debug 
  224.       *
  225.       * @return string 
  226.       *
  227.       * @since   pk-03-12-13
  228.       * @version pk-03-12-13
  229.       * @version pk-05-11-19 check for ,
  230.       *
  231.       ***/
  232.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  233.         if ($debugecho "<hr><p><b>DBMS_FIELD_FLOAT::getValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  234.  
  235.         if (strstr($aValue,",")) // <pk-05-11-19>
  236.             if (strstr($aValue,".")) {
  237.                 if (strpos($aValue,"."strpos($aValue,",")) {
  238.                     $aValue=str_replace(".","",$aValue);
  239.                 else {
  240.                     $aValue=str_replace(",","",$aValue);
  241.                 }
  242.                 $aValue=str_replace(",",".",$aValue);
  243.             else {
  244.                 $aValue=str_replace(",",".",$aValue);
  245.             }
  246.         }
  247.  
  248.         if (($aValue == 0|| (doubleval($aValue))) {
  249.             return doubleval($aValue);
  250.         else if (empty($aValue)) {
  251.             if ($this->allowNull()) {
  252.                 return $GLOBALS[$this->getGlobalDBObjIdx()]->qs_getNullStmt();
  253.             else {
  254.                 $err['ERROR']=TRUE;
  255.                 $err[$this->myName]['MSG']="NULL_NOT_ALLOWED";
  256.                 $err[$this->myName]['LABEL']=$this->label;
  257.                 if ($debugprint_r($err);
  258.                 return FALSE;
  259.             }
  260.         else {
  261.             $err['ERROR']=TRUE;
  262.             $err[$this->myName]['MSG']   ="NO_NUMBER";
  263.             $err[$this->myName]['LABEL'=$this->label;
  264.             return NULL;
  265.         }
  266.     }
  267.  
  268.     /**
  269.       * add slashes to the value to add it to a sql command
  270.       *
  271.       * @param  string  $aValue     the value
  272.       * @param  array   $err        error array
  273.       * @param  string  $arrName    name of the global array to access field gloabl ${$arrName}
  274.       * @param  bool    $debug 
  275.       *
  276.       * @return string 
  277.       *
  278.       * @version pk-03-12-13
  279.       ***/
  280.     function slashedValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  281.         if ($debugecho "<hr><p><b>DBMS_FIELD_FLOAT::slashedValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  282.         return $this->getValue($aValue,$err,$arrName,$debug);
  283.     }
  284.  
  285.     /**
  286.       * returns the html representation of the field
  287.       *
  288.       * @param mixed $aValue the falue
  289.       * @param string $arrName name of the global array holding data values
  290.       * @param boolean $debug show debug info
  291.       *
  292.       * @return mixed   the html representation of the field
  293.       *
  294.       * @version pk-05-11-19 unit added
  295.       *
  296.       ***/
  297.     function getScreenValue($aValue=NULL,$arrName="DBVAL",$debug=FALSE{
  298.         if ($debugecho "<p><b>DBMS_FIELD_FLOAT::getScreenValue(".$aValue.",...)</b> (".get_class($this)."/".$this->myName.")</p>\n";
  299.         if (!empty($this->pMask)) {
  300.             return trim("<nobr>".sprintf($this->pMask,doubleval($aValue))." ".$this->unit."</nobr>");
  301.         else {
  302.             return trim("<nobr>".$aValue." ".$this->unit."</nobr>");
  303.         }
  304.     }
  305.  
  306.  
  307. }
  308. ?>

Documentation generated on Thu, 08 Jan 2009 17:41:38 +0100 by phpDocumentor 1.4.0a2