Source for file DBMS_FIELD_INT.phpclass

Documentation is available at DBMS_FIELD_INT.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_INT.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   int
  8.   *
  9.   * @author     Peter Krebs <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. if (!isset($GLOBALS['OCSP']['DBMSFLD_PATH']))
  16. {
  17.     $GLOBALS['OCSP']['DBMSFLD_PATH']=dirname(__FILE__)._OCSP_DIRSEP_;
  18. }
  19.  
  20. require_once $GLOBALS['OCSP']['DBMSFLD_PATH']."DBMS_FIELD.phpclass";
  21.  
  22. /**
  23.   * Class DBMS_FIELD_INT
  24.   *
  25.   * @project    Open CSP-Management
  26.   * @package    dbms_field
  27.   * @category   int
  28.   *
  29.   * @author     Peter Krebs <p.krebs@lvus.at>
  30.   * @copyright  (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
  31.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   *
  34.   ***/
  35. class DBMS_FIELD_INT extends DBMS_FIELD {
  36.     var $className     = "Integer";
  37.     var $javaCheck     = TRUE;
  38.     var $defaultValue  = 0;
  39.     /**
  40.       * @var string $unit added to the output
  41.       ***/
  42.     var $unit          = "";
  43.  
  44.     /**
  45.       * @var boolean $hideUnitInLst 
  46.       * @since pk-07-03-05
  47.       * @access protected
  48.       ***/
  49.     protected $hideUnitInLst=FALSE;
  50.  
  51.     /**
  52.       * @var boolean $null2zero save NULL values as zero (0)
  53.       ***/
  54.     var $null2zero     = FALSE;
  55.  
  56.     /**
  57.       * source file of the class
  58.       *
  59.       * @var string $classSrcFile 
  60.       * @since pk-05-01-14
  61.       ***/
  62.     var $classSrcFile=__FILE__;
  63.  
  64.     /**
  65.       * @var string $inputAdd overwrite default
  66.       * @since pk-06-12-04
  67.       ***/
  68.     var $inputAdd="style=\"text-align:right;\"";
  69.  
  70.     // ###########################################################
  71.     // OBJECT SETTINGS METHODS
  72.     // ###########################################################
  73.  
  74.     // ###########################################################
  75.     // FIELD DEFINITION DATA METHODS
  76.     // ###########################################################
  77.  
  78.     /**
  79.       * returns an array of field to bie shown in the edit form
  80.       * by using editTbl_echoForm
  81.       *
  82.       * the array is in the form:
  83.       *
  84.       * <code>
  85.       * [_sectionName_]
  86.       *      [TITLE] -> string
  87.       *      [_rowName_]
  88.       *         [FLDLAB]  (complete html code with <td></td>)
  89.       *         [FLDVAL] (complete html code with <td></td>)
  90.       * </code>
  91.       *
  92.       * @param boolean $debug 
  93.       *
  94.       * @returns array
  95.       *
  96.       * @since pk-06-06-29
  97.       * @version pk-07-03-05 (hideUnitInLst)
  98.       *
  99.       ***/
  100.     function editTbl_getFieldEditArr($debug=FALSE{
  101.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_INT::editTbl_getFieldEditArr","",0);
  102.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  103.  
  104.         $a_ret['LAYOUT']['UNIT']=array(
  105.             'FLDLAB'    => "Einheit:",
  106.             'FLDVAL'    => "<input name=\"UNIT\" type=\"input\" value=\"".$this->unit."\" size=\"10\"><input name=\"hideUnitInLst\" type=\"checkbox\" value=\"1\" ".($this->hideUnitInLst ? "checked" "")."> in Liste nicht anzeigen"
  107.         );
  108.         $a_ret['VALCHECKS']['NULL2ZERO']=array(
  109.             'FLDLAB'    => "NULL zu Null (0):",
  110.             'FLDVAL'    => '<input name="null2zero" type="checkbox" value="1" '.($this->null2zero ? 'checked' '').'> ja NULL-Werte als 0 speichern'
  111.         );
  112.  
  113.         return $a_ret;
  114.     }
  115.  
  116.     /**
  117.       * echos the filed definition form
  118.       *
  119.       * @param boolean $showSize obsulet
  120.       * @param boolean $showUnit obsulet
  121.       * @param boolean $showNull obsulet
  122.       *
  123.       * @deprecated since pk-06-06-29
  124.       *
  125.       ***/
  126.     function editTblForm($showSize=FALSE,$showUnit=TRUE,$showNull=TRUE{
  127.         $a_FieldEditArr=$this->editTbl_getFieldEditArr($debug);
  128.         $this->editTbl_echoForm($a_FieldEditArr,$debug);
  129.     }
  130.  
  131.  
  132.     /**
  133.       * saves the form desc
  134.       *
  135.       * @returns boolean
  136.       *
  137.       * @version pk-04-10-12
  138.       * @version pk-07-03-05 (hideUnitInLst)
  139.       *
  140.       ***/
  141.     function save({
  142.         $ret parent::save();
  143.  
  144.         $this->null2zero = ((isset($_POST['null2zero']&& intval($_POST['null2zero'])) TRUE FALSE);
  145.         $this->unit=(isset($_POST['UNIT']$_POST['UNIT'"");
  146.         $this->hideUnitInLst=((isset($_POST['hideUnitInLst']&& intval($_POST['hideUnitInLst'])) TRUE FALSE);
  147.  
  148.         return $ret;
  149.     }
  150.  
  151. // ###########################################################
  152. // OBJECT HTML FORM METHODS
  153. // ###########################################################
  154.  
  155.     /**
  156.       * adds $this->unit to to parent::getInputTag()
  157.       *
  158.       * @param mixed $aValue the value to set
  159.       * @param string $arrName 
  160.       * @param string $nameAdd  append something to name like "[VALUE]" for search forms
  161.       *
  162.       * @return string 
  163.       *
  164.       ***/
  165.     function getInputTag($aValue,$arrName,$nameAdd=""{
  166.         if ((strtoupper($aValue== "NULL"|| (empty($aValue&& (strval($aValue!== "0"))) // <pk-06-08-06>
  167.             if ($this->null2zero)  $aValue=0;
  168.             else                   $aValue="";
  169.         else {
  170.             $aValue=intval($aValue);
  171.         }
  172.         
  173.         if (!stristr($this->inputAdd,'onkeypress'))
  174.         {
  175.             $this->inputAdd.=" onkeypress=\"return jOCSP.ocspFormFldEvents.keyNumber(event,true);\"";
  176.         }
  177.         $ret=parent::getInputTag($aValue,$arrName,$nameAdd);
  178.         $ret.=" ".$this->unit;
  179.         return $ret;
  180.     }
  181.  
  182.  
  183.     // ################################################
  184.     // SEARCH FORM METHODS
  185.     // ################################################
  186.  
  187.     /**
  188.       * echos a compare type select for search forms
  189.       *
  190.       * @param string $arrName 
  191.       *
  192.       * @version pk-04-12-29
  193.       *
  194.       ***/
  195.     function writeSearchCompTypes($arrName{
  196.         echo $this->getSearchCompTypes($arrName);
  197.     }
  198.  
  199.     /**
  200.       * returns the html code for the search compare type select
  201.       *
  202.       * @param string $arrName 
  203.       *
  204.       * @returns string
  205.       *
  206.       * @since pk-04-12-29
  207.       *
  208.       ***/
  209.     function getSearchCompTypes($arrName{
  210.         $ret ="<select name=\"".$arrName."[".$this->myName."][COMPTYPE]\">";
  211.         $ret.="  <option value=\"=\">=</option>";
  212.         $ret.="  <option value=\"<\">&lt;</option>";
  213.         $ret.="  <option value=\">\">&gt;</option>";
  214.         $ret.="  <option value=\"<>\">&lt;&gt;</option>";
  215.         $ret.="  <option value=\"=0\">=0</option>";
  216.         $ret.="</select>";
  217.         return $ret;
  218.     }
  219.  
  220.     /**
  221.       * returns the where statement part for the field
  222.       *
  223.       * @param array $aArr  form input array
  224.       * @param bool $debug 
  225.       *
  226.       * @return string 
  227.       *
  228.       * @version pk-05-02-04
  229.       ***/
  230.     function searchWhere($aArr,$debug=FALSE{
  231.         if ($debugecho "<p><b>DMBS_FIELD_INT::searchWhere($aArr,$debug)</b> (".get_class($this).")</p>";
  232.  
  233.         if (!is_array($aArr)) return "";
  234.  
  235.         if (!intval($aArr['VALUE']&& ($aArr['COMPTYPE']!="=0")) return "";
  236.  
  237.  
  238.         if ($debug{echo "<blockquote><pre>";print_r($aArr);echo "</pre></blockquote>";}
  239.  
  240.         if (!empty($aArr['ANDOR']))  /* <pk-04-02-25 />*/
  241.             $ret=($aArr['ANDOR'== "OR" " OR " " AND ");
  242.             $ret.=$this->myTable.".".$this->myName;
  243.             switch($aArr['COMPTYPE']// check input
  244.                 case "<":
  245.                     $ret.=" < ";
  246.                     break;
  247.                 case ">":
  248.                     $ret.=" > ";
  249.                     break;
  250.                 case "<>":
  251.                     $ret.=" <> ";
  252.                     break;
  253.                 default:
  254.                     $ret.=" = ";
  255.             }
  256.             $ret.=intval($aArr['VALUE']);
  257.             return $ret;
  258.         else return "";
  259.     }
  260.  
  261.     // ###########################################################
  262.     // OBJECT VALUE CHECK/RETURN METHODS
  263.     // ###########################################################
  264.  
  265.     /**
  266.       * adds unit to parent::getScreenValue()
  267.       *
  268.       * @param mixed    $aValue     the falue
  269.       * @param string $arrName  name of the global array holding data values
  270.       * @param bool     $debug      show debug info
  271.       *
  272.       * @return mixed   the html representation of the field
  273.       ***/
  274.     function getScreenValue($aValue=NULL,$arrName="DBVAL",$debug=FALSE{
  275.         return $aValue." ".$this->unit;
  276.     }
  277.  
  278.     /**
  279.       * returns the html representation of the field in a list (table col)
  280.       *
  281.       * @param mixed    $aValue     the falue
  282.       * @param string $arrName  name of the global array holding data values
  283.       * @param bool     $debug      show debug info
  284.       *
  285.       * @returns string the html representation of the field
  286.       *
  287.       * @since pk-07-03-05
  288.       *
  289.       ***/
  290.     function getListValue($aValue=NULL,$arrName="DBVAL",$debug=FALSE{
  291.         if ($debugechoDebugMethod(__FILE__." L: ".__LINE__,get_class($this),__CLASS__."::getListValue()");
  292.         return "<nobr>".$aValue.($this->hideUnitInLst ? "" " ".$this->unit)."</nobr>";
  293.     }
  294.  
  295.     /**
  296.       * returns the field value
  297.       *
  298.       * @param  string  $aValue     the value
  299.       * @param  array   $err        error array
  300.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  301.       * @param  bool    $debug 
  302.       *
  303.       * @return string 
  304.       *
  305.       * @since   pk-03-12-13
  306.       * @version pk-04-12-02
  307.       *
  308.       ***/
  309.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  310.         $debug=($debug || $this->fldDebug);
  311.         if ($debugecho "<hr><p><b>DBMS_FIELD_INT::getValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  312.  
  313.         if ((intval($aValue)) || ($aValue === 0|| ($aValue === "0")) {
  314.             return intval($aValue);
  315.         else {
  316.             if ($debugecho "<p>dbDesc:</p><pre>".print_r($this->dbDesc,TRUE)."</pre>";
  317.             if ($this->dbDesc['AUTO_INCREMENT']{
  318.                 // assume we have a new row
  319.                 if ($debugecho "<p>assuming new</p>";
  320.                 return NULL;
  321.             else if ($this->null2zero{      /* <pk-04-12-02 /> */
  322.                  return 0;
  323.             else if ($this->allowNull()) {
  324.                 return OCSP_OBJ::defaultReadDBObj()->qs_getNullStmt();
  325.             else {
  326.                 $err['ERROR']=True;
  327.                 $err[$this->myName]['MSG']=(empty($this->nullErrMsg$this->label.": NULL_NOT_ALLOWED" $this->nullErrMsg);
  328.                 $err[$this->myName]['LABEL']=$this->label;
  329.                 if ($debugecho "<blockquote>ERROR:<pre>".print_r($err,TRUE)."</pre>";
  330.                 return False;
  331.             }
  332.         }
  333.     }
  334.  
  335.     /**
  336.       * add slashes to the value to add it to a sql command
  337.       *
  338.       * @param  string  $aValue     the value
  339.       * @param  array   $err        error array
  340.       * @param  string  $arrName    name of the global array to access field gloabl ${$arrName}
  341.       * @param  bool    $debug 
  342.       *
  343.       * @return string 
  344.       *
  345.       * @version pk-03-12-13
  346.       *
  347.       ***/
  348.     function slashedValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  349.         if ($debugecho "<hr><p><b>DBMS_FIELD_INT::slashedValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  350.         return $this->getValue($aValue,$err,$arrName,$debug);
  351.     }
  352.  
  353.  
  354.  
  355. }
  356. ?>

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