Source for file DBMS_FIELD_TIME.phpclass

Documentation is available at DBMS_FIELD_TIME.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_TIME.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   real
  8.   *
  9.   * @author     Peter Krebs <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2005 by LVUS <http://opencsp.lvu.at>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. if (empty($GLOBALS['OCSP']['PHPFORMPATH'])) $GLOBALS['OCSP']['PHPFORMPATH']=dirname(__FILE__)."/";
  16.   
  17. if (!class_exists("DBMS_FIELD")) {
  18.     require_once $GLOBALS['OCSP']['PHPFORMPATH']."DBMS_FIELD.phpclass";
  19. }
  20.  
  21. /**
  22.   * Class DBMS_FIELD_TIME
  23.   *
  24.   * @project    Open CSP-Management
  25.   * @package    dbms_field
  26.   * @category   real
  27.   *
  28.   * @author     Peter Krebs <p.krebs@lvus.at>
  29.   * @copyright  (c) 2002-2005 by LVUS <http://opencsp.lvu.at>
  30.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  31.   *
  32.   ***/
  33. class DBMS_FIELD_TIME extends DBMS_FIELD {
  34.     var $className     = "Time";
  35.  
  36.     /**
  37.       * source file of the class
  38.       *
  39.       * @var string $classSrcFile 
  40.       * @since pk-05-02-19
  41.       ***/
  42.     var $classSrcFile=__FILE__;
  43.             
  44.     
  45.     // ###########################
  46.    
  47.     function getInputTag($aTimeArr,$arrName="DBVAL"{
  48.         $ret="";
  49.         $ret.="<input name=\"".$arrName."[".$this->myName."][HOUR]\" value=\"".($aTimeArr['HOUR'])."\" size=\"2\" maxlength=\"2\">:\n";
  50.         $ret.="<input name=\"".$arrName."[".$this->myName."][MIN]\"  value=\"".($aTimeArr['MIN'])"\" size=\"2\" maxlength=\"2\">:\n";
  51.         $ret.="<input name=\"".$arrName."[".$this->myName."][SEC]\"  value=\"".($aTimeArr['SEC'])"\" size=\"2\" maxlength=\"2\">\n";
  52.  
  53.         $ret.=" <a class=\"button\" href=\"#\" onClick=\"{";
  54.         $ret.="var aktDate=new Date();";
  55.         $ret.="setElemValByName(document.forms[0],'".$arrName."[".$this->myName."][HOUR]',aktDate.getHours());";
  56.         $ret.="setElemValByName(document.forms[0],'".$arrName."[".$this->myName."][MIN]',aktDate.getMinutes());";
  57.         $ret.="setElemValByName(document.forms[0],'".$arrName."[".$this->myName."][SEC]',aktDate.getSeconds());";
  58.         $ret.="}\"><img src=\"".$GLOBALS[PROJECT]['SYSIMGURL']."buttons/setnow.gif\" border=\"0\"></a> ";
  59.     
  60.         return $ret;
  61.     }
  62.  
  63.     function makeTimeArray($aString,$debug=FALSE{
  64.         require_once $GLOBALS['PHPINCPATH']."common/pcf.phpinc";
  65.         $ret=array('HOUR'=>'','MIN'=>'','SEC'=>'');
  66.         $arr=explode(":",$aString);
  67.         if (sizeof($arr == 3)) {
  68.             $ret['HOUR']=pcf_addzero(intval($arr[0]),2);
  69.             $ret['MIN'=pcf_addzero(intval($arr[1]),2);
  70.             $ret['SEC'=pcf_addzero(intval($arr[2]),2);
  71.         }
  72.         if ($debug{echo "<pre>$aString:\n";print_r($arr);print_r($ret);echo "</pre>";}
  73.         return $ret;
  74.     }
  75.  
  76.     /**
  77.       * @param int $mode 
  78.       * @param string $aValue 
  79.       * @param string $arrName 
  80.       * @param boolean $debug 
  81.       *
  82.       * @version pk-05-09-05
  83.       *
  84.       ***/
  85.     function writeField($mode,$aValue="",$arrName="DBVAL",$debug=FALSE{
  86.         switch($mode{
  87.             case FRM_MODE_NEW:
  88.                  if ($this->enableNew{
  89.                     if (empty($aValue)) $aValue=$this->defaultValue;
  90.                     echo $this->getInputTag($this->makeTimeArray($aValue),$arrName);
  91.                     echo $this->getAddTag($arrName);
  92.                     return TRUE;
  93.                  else {
  94.                     return $this->writeField(FRM_MODE_READONLY,$aValue,$arrName,$debug);
  95.                  }
  96.             case FRM_MODE_COPY// <pk-05-09-05>
  97.                  if ($this->enableCopy{
  98.                     if (empty($aValue)) $aValue=$this->defaultValue;
  99.                     echo $this->getInputTag($this->makeTimeArray($aValue),$arrName);
  100.                     echo $this->getAddTag($arrName);
  101.                     return TRUE;
  102.                  else {
  103.                     return $this->writeField(FRM_MODE_READONLY,$aValue,$arrName,$debug);
  104.                  }
  105.             case FRM_MODE_EDIT:
  106.                  if ($this->enableEdit{
  107.                     echo $this->getInputTag($this->makeTimeArray($aValue),$arrName);
  108.                     echo $this->getAddTag($arrName);
  109.                     return TRUE;
  110.                  else {
  111.                     return $this->writeField(FRM_MODE_READONLY,$aValue,$arrName,$debug);
  112.                     return FALSE;
  113.                  }
  114.             case FRM_MODE_HIDDEN:
  115.                 echo "<input name=\"".$arrName."[".$this->myName."]\" ";
  116.                 echo "value=\"".$aValue."\" type=\"hidden\">";
  117.                 return TRUE;
  118.  
  119.             case FRM_MODE_READONLY:
  120.                 echo $this->getScreenValue($aValue,$arrName,$debug);
  121.                 echo $this->getAddTag($arrName);
  122.                 return FALSE;
  123.             default:
  124.                 echo $this->getScreenValue($aValue,$arrName,$debug);
  125.                 return FALSE;
  126.         }
  127.     }
  128.  
  129.     function checkTime($timeArr{
  130.         if ((trim($timeArr['HOUR'])==""|| (intval($timeArr['HOUR']0|| (intval($timeArr['HOUR']24)) return FALSE;
  131.         if ((trim($timeArr['MIN'])==""|| (intval($timeArr['MIN']0|| (intval($timeArr['MIN']59)) return FALSE;
  132.         if ((trim($timeArr['SEC'])==""|| (intval($timeArr['SEC']0|| (intval($timeArr['SEC']59)) return FALSE;
  133.         return TRUE;
  134.     }
  135.  
  136.     /**
  137.       * returns the string representation of the time
  138.       *
  139.       * @param  string  $aValue     the value
  140.       * @param  array   $err        error array
  141.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  142.       * @param  bool    $debug 
  143.       *
  144.       * @return string 
  145.       *
  146.       * @since   pk-03-12-13
  147.       * @version pk-03-12-13
  148.       *
  149.       ***/
  150.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  151.         if ($debugecho "<hr><p><b>DBMS_FIELD_SELECTLIST::getValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  152.         if (!is_array($aValue)) {
  153.             $aValue=$this->makeTimeArray($aValue);
  154.         }
  155.  
  156.         if (!$this->checkTime($aValue)) {
  157.             if ($this->allowNull()) {
  158.                 return NULL;
  159.             else {
  160.                 $err['ERROR']=TRUE;
  161.                 $err[$this->myName]['MSG']="NULL_NOT_ALLOWED";
  162.                 $err[$this->myName]['LABEL']=$this->label;
  163.                 if ($debugprint_r($err);
  164.                 return FALSE;
  165.             }
  166.         }
  167.  
  168.         return implode(":",$aValue);
  169.     }
  170.  
  171.     /**
  172.       * add slashes to the value from getValue to add it to a sql command
  173.       *
  174.       * @param  string  $aValue     the value
  175.       * @param  array   $err        error array
  176.       * @param  string  $arrName    name of the global array to access field gloabl ${$arrName}
  177.       * @param  bool    $debug 
  178.       *
  179.       * @return string 
  180.       *
  181.       * @version pk-03-12-13
  182.       *
  183.       ***/
  184.     function slashedValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  185.         if ($debugecho "<hr><p><b>DBMS_FIELD_SELECTLIST::slashedValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  186.         if (!($aValue=$this->getValue($aValue,$err,$arrName,$debug))) {
  187.             return $GLOBALS[$this->getGlobalDBObjIdx()]->qs_getNullStmt();
  188.         }
  189.         return $GLOBALS[$this->getGlobalDBObjIdx()]->qs_getSlashedValue($aValue);
  190.     }
  191. }
  192. ?>

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