Source for file DBMS_FIELD_TIMESTAMP.phpclass

Documentation is available at DBMS_FIELD_TIMESTAMP.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_TIMESTAMP.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   timestamp
  8.   *
  9.   * @author     Peter Krebs <p.krebs@lvus.at>
  10.   * @copyright  (c) 2002-2005 by LVUS <http://www.lvus.at>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   ***/
  14.  
  15. /**
  16.   * requirements
  17.   */
  18. pcf_require_class('DBMS_FIELD_DATE',"db/frmClasses/");
  19.  
  20. /**
  21.   * Class DBMS_FIELD_TIMESTAMP
  22.   *
  23.   * Handles mySQL Timestamps Columns
  24.   *
  25.   * @project    Open CSP-Management
  26.   * @package    dbms_field
  27.   * @category   timestamp
  28.   *
  29.   * @author     Peter Krebs <p.krebs@lvus.at>
  30.   * @copyright  (c) 2002-2005 by LVUS <http://www.lvus.at>
  31.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   ***/
  34.     var $className     = "Timestamp";
  35.  
  36.     /**
  37.       * source file of the class
  38.       *
  39.       * @var string $classSrcFile 
  40.       * @since pk-05-01-20
  41.       ***/
  42.     var $classSrcFile=__FILE__;
  43.  
  44.     /**
  45.       * returns an array of field to bie shown in the edit form
  46.       * by using editTbl_echoForm
  47.       *
  48.       * the array is in the form:
  49.       *
  50.       * <code>
  51.       * [_sectionName_]
  52.       *      [TITLE] -> string
  53.       *      [_rowName_]
  54.       *         [FLDLAB]  (complete html code with <td></td>)
  55.       *         [FLDVAL] (complete html code with <td></td>)
  56.       * </code>
  57.       *
  58.       * NOTE as this is not implemented in the whole classTree at the moment ensure all parents use
  59.       * editTbl_echoForm() in theire editTblForm otherwise you'll get a mismatch of field order
  60.       *
  61.       * @param boolean $debug 
  62.       *
  63.       * @returns array
  64.       *
  65.       * @since pk-06-07-16
  66.       *
  67.       ***/
  68.     function editTbl_getFieldEditArr($debug=FALSE{
  69.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_DATE::editTbl_getFieldEditArr","",0);
  70.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  71.  
  72.         $a_ret['SHOW']['SHOWDATE']=array(
  73.             'FLDLAB'=>"Datum/Zeit anzeigen:",
  74.             'FLDVAL'=>"
  75.                     <input name=\"SHOWDATE\" type=\"checkbox\" ".($this->showDate ? "checked=\"checked\"" "")." value=\"1\" /> Datum anzeigen
  76.                     <input name=\"SHOWTIME\" type=\"checkbox\" ".($this->showTime ? "checked=\"checked\"" "")." value=\"1\" /> Zeit anzeigen"
  77.         );
  78.  
  79.         $a_ret['LAYOUT']['FLD_DATEFORMAT']=array(
  80.             'FLDLAB'=>"Datumsformat: <a href=\"http://at.php.net/manual/en/function.date.php\">?</a>",
  81.             'FLDVAL'=>"
  82.                         <input name=\"fldDateformat\" value=\"".$this->lstDateformat."\" size=\"25\" />
  83.                         <input name=\"hideCalendarBtn\" type=\"checkbox\" value=\"1\" ".($this->hideCalendarBtn ? "checked=\"checked\"" "")." /> KalenderPopup ausblenden\n
  84.                 "
  85.         );
  86.         $a_ret['LAYOUT']['FLD_TIMEFORMAT']=array(
  87.             'FLDLAB'=>"Zeitformat: <a href=\"http://at.php.net/manual/en/function.date.php\">?</a>",
  88.             'FLDVAL'=>"<input name=\"fldTimeformat\" value=\"".$this->fldTimeformat."\" size=\"25\" />"
  89.         );
  90.  
  91.         $a_ret['LIST']['LST_DATEFORMAT']=array(
  92.             'FLDLAB'=>"Datumsformat: <a href=\"http://at.php.net/manual/en/function.date.php\">?</a>",
  93.             'FLDVAL'=>"<input name=\"lstDateformat\" value=\"".$this->lstDateformat."\" size=\"25\" />"
  94.         );
  95.         $a_ret['LIST']['LST_TIMEFORMAT']=array(
  96.             'FLDLAB'=>"Zeitformat: <a href=\"http://at.php.net/manual/en/function.date.php\">?</a>",
  97.             'FLDVAL'=>"<input name=\"lstTimeformat\" value=\"".$this->lstTimeformat."\" size=\"25\" />"
  98.         );
  99.  
  100.         return $a_ret;
  101.     }
  102.  
  103.  
  104.  
  105.     /**
  106.       * converts a timestamp into a date object
  107.       *
  108.       * if $aValue is an array pcf_Date::setFromArray() is called to transform to a date
  109.       * if $aValue is doubleval pcf_Date::setMySqlTimeStamp() is called
  110.       *
  111.       * @param mixed $aValue 
  112.       * @param boolean $debug 
  113.       *
  114.       * @returns pcf_Date
  115.       *
  116.       ***/
  117.     function getTSDate($aValue,$debug=FALSE{
  118.         $debug=($debug || $this->fldDebug);
  119.         if ($debugecho "<p><b>DBMS_FIELD_TIMESTAMP::getTSDate($aValue,....)</b> (".get_class($this).")</p><blockquote>";
  120.  
  121.         $dateObj=new OCSP_DATE();
  122.         if (is_array($aValue)) {
  123.             if ($debugecho "<b>setFromArray</b><br />";
  124.             $dateObj->setFromArray($aValue);
  125.         else if (preg_match('/^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})/',$aValue)) {
  126.             if ($debugecho "<b>setDateStr</b><br />";
  127.             $dateObj->setDateStr($aValue,$debug);
  128.         else if (doubleval($aValue)) {
  129.             if ($debugecho "<b>setMySqlTimeStamp</b><br />";
  130.             $dateObj->setMySqlTimeStamp($aValue)/* <pk-04-12-29 /> */
  131.         else {
  132.             if ($debugecho "<b>setDateStr</b><br />";
  133.             $dateObj->setNULL();
  134.         }
  135.  
  136.         if ($debugecho "<pre>".pcf_object_info($dateObj)."</pre></blockquote>";
  137.  
  138.         return $dateObj;
  139.     }
  140.  
  141.  
  142.     /**
  143.       * returns the html code for the field value input / show
  144.       * adds $this->myName to ${$this->myDataArrName}['_DBMS_FIELDS']
  145.       *
  146.       * @param int $mode 
  147.       * @param mixed $aValue 
  148.       * @param boolean $debug 
  149.       *
  150.       * @returns string
  151.       *
  152.       * @since pk-04-12-29
  153.       *
  154.       * @version pk-05-09-05
  155.       * @version pk-06-01-09
  156.       *
  157.       ***/
  158.     function getFieldTag($mode,$aValue=NULL,$debug=FALSE{
  159.         $debug=($debug || $this->fldDebug);
  160.         if ($debugecho "<p><b>DBMS_FIELD_TIMESTAMP::getFieldTag($mode,$aValue,...)</b> (".get_class($this).")</p>";
  161.  
  162.         if (!empty($aValue)) // <pk-06-08-18>
  163.             $o_dateObj=$this->getTSDate($aValue,$debug);
  164.             if ($o_dateObj->isNULL()) {
  165.                 $aValue=NULL;
  166.             else {
  167.                 $aValue=$o_dateObj->dateStr("Y-m-d H:i:s");
  168.             }
  169.         }
  170.         switch($mode{
  171.             case FRM_MODE_NEW:
  172.                 $ret=parent::getFieldTag(FRM_MODE_READONLY,$aValue,$debug);
  173.                 if ($this->enableNew{
  174.                     $ret.=$this->getFieldTag(FRM_MODE_HIDDEN,$aValue,$debug);
  175.                 }
  176.                 return $ret;
  177.             case FRM_MODE_COPY// <pk-05-09-05>
  178.                 $ret=parent::getFieldTag(FRM_MODE_READONLY,$aValue,$debug);
  179.                 if ($this->enableCopy{
  180.                     $ret.=$this->getFieldTag(FRM_MODE_HIDDEN,$aValue,$debug);
  181.                 }
  182.                 return $ret;
  183.             case FRM_MODE_EDIT:
  184.                 $ret=parent::getFieldTag(FRM_MODE_READONLY,$aValue,$debug);
  185.                 if ($this->enableEdit{
  186.                     $ret.=$this->getFieldTag(FRM_MODE_HIDDEN,$aValue,$debug);
  187.                 }
  188.                 return $ret;
  189.             default:
  190.                 if (!empty($aValue)) // <pk-06-01-09>
  191.                     return parent::getFieldTag($mode,$aValue,$debug);
  192.                 else {
  193.                     return "&nbsp;";
  194.                 }  // </pk-06-01-09>
  195.         }
  196.     }
  197.  
  198.     /**
  199.       * returns the field default value
  200.       *
  201.       * if $defaultValue !empty it is returned
  202.       * else getDbDefault is return
  203.       *
  204.       * @return mixed 
  205.       *
  206.       * @version pk-04-08-17
  207.       *
  208.       ***/
  209.     function getDefaultValue($debug=FALSE){
  210.         $debug=($debug || $this->fldDebug);
  211.         if ($debugecho "<p><b>DBMS_FIELD_TIMESTAMP::getDefaultValue(...)</b> (".get_class($this).")</p>";
  212.         if ((trim(strtoupper($this->defaultValue)) == "NOW()"|| (trim(strtoupper($this->defaultValue))=="CURRENT_TIMESTAMP")) {
  213.             $aDate=new OCSP_DATE(FALSE);
  214.             return $aDate->getMySQLTimestamp();
  215.         else {
  216.             return parent::getDefaultValue($debug);
  217.         }
  218.     }
  219.  
  220.     /**
  221.       * returns the field value
  222.       *
  223.       * @param  string  $aValue     the value
  224.       * @param  array   $err        error array
  225.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  226.       * @param  bool    $debug 
  227.       *
  228.       * @return string 
  229.       *
  230.       * @since   pk-03-12-13
  231.       * @version pk-03-12-13
  232.       * @version pk-06-08-18
  233.       *
  234.       * @todo DBMS_FIELD_TIMESTAMP::getValue() returns MySQL Timestamp format
  235.       ***/
  236.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  237.         if ($debugecho "<hr><p><b>DBMS_FIELD_TIMESTAMP::getValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  238.         $o_dateObj=$this->getTSDate($aValue,$debug)// <pk-06-08-18 />
  239.         if ($debug{echo "<pre>";print_r($o_dateObj);echo "</pre>";}
  240.         return $o_dateObj->getMySQLTimestamp();
  241.     }
  242.  
  243.     /**
  244.       * add slashes to the value to add it to a sql command
  245.       *
  246.       * NOTE allways returns DB Now statement
  247.       *
  248.       * @param  string  $aValue     the value
  249.       * @param  array   $err        error array
  250.       * @param  string  $arrName    name of the global array to access field gloabl ${$arrName}
  251.       * @param  bool    $debug 
  252.       *
  253.       * @return string 
  254.       *
  255.       * @version pk-03-12-13
  256.       *
  257.       ***/
  258.     function slashedValue($aValue,&$err,$arrName="DBVAL",$debug=FALSE{
  259.         if ($debugecho "<hr><p><b>DBMS_FIELD_TIMESTAMP::slashedValue($aValue,$err,$arrName,$debug)</b> (".get_class($this)."/".$this->myName.")</p>";
  260.         return $GLOBALS[$this->getGlobalDBObjIdx()]->qs_getNowStmt();
  261.     }
  262.  
  263.     /**
  264.       * get a where clause for the search settings
  265.       *
  266.       * $aArr array post values of the serach form
  267.       * return string where clause
  268.       **/
  269.  
  270.     function searchWhere($aArr,$debug=FALSE{
  271.         if ($debugecho "<p><b>DMBS_FIELD_TIMESTAMP::searchWhere($aArr,$debug)</b> (".get_class($this).")</p>";
  272.  
  273.         if (!is_array($aArr)) return "";
  274.         if ($debug{echo "<blockquote><pre>";print_r($aArr);echo "</pre></blockquote>";}
  275.  
  276.         $err="";
  277.         if ($debugecho "<pre>"print_r($aArr)echo "</pre>"}
  278.  
  279.         if (!empty($aArr['ANDOR']))  {
  280.             $ret=($aArr['ANDOR'== "OR" " OR " " AND ");
  281.  
  282.             switch($aArr['COMPTYPE']// only to verify input
  283.                 case "<":
  284.                 case ">":
  285.                 case "=":
  286.                     $ret.=$this->myTable.".".$this->myName;
  287.                     $ret.=$aArr['COMPTYPE'];
  288.                     global $TEMPDBVAL;$TEMPDBVAL=$aArr;
  289.                     $ret.=parent::slashedValue($TEMPDBVAL,$err,"TEMPDBVAL",$debug);
  290.                     unset($TEMPDBVAL);
  291.                     break;
  292.                 default:
  293.                     echo "COMPTYPE NOT FOUND";
  294.                     return "";
  295.             }
  296.             return $ret;
  297.         else return "";
  298.     }
  299. // end class DBMS_FIELD_INT
  300. ?>

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