Source for file DBMS_TABLEOBJ.phpclass

Documentation is available at DBMS_TABLEOBJ.phpclass

  1. <?php
  2. /**
  3.   * Class file dbms_tableobj.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms
  7.   *
  8.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  9.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @version $Id: DBMS_TABLEOBJ.phpclass,v 1.60 2008/12/17 16:28:52 peterkrebs Exp $
  12.   */
  13.  
  14. /**
  15.   * requirements
  16.   */
  17.  
  18. if (!class_exists('OCSP_OBJ'))
  19. {
  20.     require_once __OCSP_PHPINCPATH__ 'common' _OCSP_DIRSEP_ 'OCSP_OBJ.phpclass';
  21. }
  22.  
  23. if (!interface_exists('INFA_DBMS_TABLEOBJ'))
  24. {
  25.     require_once dirname(__FILE___OCSP_DIRSEP_ "INFA_DBMS_TABLEOBJ.phpclass";
  26. }
  27.  
  28.  
  29. /**
  30.   * Base class DBMS_TABLEOBJ to handel table data in an object
  31.   *
  32.   *
  33.   * @project    Open CSP-Management
  34.   * @package    dbms
  35.   *
  36.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  37.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  38.   *
  39.   * @version pk-04-01-02
  40.   * @version pk-05-11-17
  41.   * @version pk-08-01-31
  42.   * @version $Id: DBMS_TABLEOBJ.phpclass,v 1.60 2008/12/17 16:28:52 peterkrebs Exp $
  43.  
  44.   * 
  45.   */
  46. class DBMS_TABLEOBJ extends OCSP_OBJ implements INFA_DBMS_TABLEOBJ 
  47. {
  48.  
  49.     /*** class constants  --------------------------------------------- */
  50.  
  51.     /**
  52.       * @constant string CLASS_SRC_FILE
  53.       */
  54.     const CLASS_SRC_FILE = __FILE__;
  55.  
  56.     /*** class variables  --------------------------------------------- */
  57.  
  58.     /**
  59.       * @staticvar array $staticClassVars vars which must not be copied
  60.       */
  61.     protected static $staticClassVars=array('myClassSrcFile');
  62.  
  63.     /**
  64.      * array of already seen tables definitions
  65.      *
  66.      * @staticvar array $dbTableDefinitions 
  67.      * @since pk-08-03-11
  68.      */
  69.     static $dbTableDefinitions array();
  70.     
  71.     /**
  72.       * @var array $myKeys      array of db primary key columns
  73.       ***/
  74.     protected $myKeys     =array();
  75.     /**
  76.       * @staticvar array $myFields    array of db column description
  77.       ***/
  78.     protected $myFields   =NULL;
  79.     /**
  80.       * @var string $autoIncFld name of the auto incremental column
  81.       ***/
  82.     protected $autoIncFld ="";
  83.     /**
  84.       * NOT FINAL !!!!!
  85.       * @staticvar string $myTable     NEED TO BE OVERRITTEN !!!!
  86.       */
  87.     protected $myTable="";
  88.  
  89.     /**
  90.       * @var double $myCacheTS     linux timestamp of the cache file
  91.       ***/
  92.     protected $myCacheTS=0;
  93.  
  94.     /**
  95.       * @var int $myMode            editing mode FRM_MODE_*
  96.       ***/
  97.     protected $myMode   =FRM_MODE_READONLY;
  98.  
  99.     /**
  100.       * @var double $valChangeTS    timestamp values changed
  101.       * @since  pk-03-10-25
  102.       ***/
  103.     protected $valChangeTS    = 1;            // greater then populate TS !
  104.  
  105.     /**
  106.       * @var boolean $objError   obj has errors
  107.       ***/
  108.     protected $objError   = False;
  109.     /**
  110.       * @var string $objErrorMsg obj error message
  111.       ***/
  112.     protected $objErrorMsg"";
  113.  
  114.     /**
  115.       * @var double $populateTS     linux timestamp when DB_TBLOBJ::dbPopulateDB() was called
  116.       ***/
  117.     protected $populateTS = 0;
  118.  
  119.     /**
  120.       * @var double $initTS     linux timestamp when DB_TBLOBJ::init() was called
  121.       ***/
  122.     protected $initTS     = 0;
  123.  
  124.     /**
  125.       * @var bool $hasObjVals 
  126.       * @since pk-05-07-13
  127.       ***/
  128.     protected $hasObjVals=False;
  129.  
  130.     /**
  131.       * @var array $myObjVals 
  132.       * @since pk-05-07-13
  133.       ***/
  134.     protected $myObjVals=array();
  135.  
  136.     /**
  137.       * @var double $myObjValsPopulateTS 
  138.       * @since pk-05-07-13
  139.       ***/
  140.     protected $myObjValsPopulateTS=0;
  141.     
  142.     /**
  143.      * array of linked (joined) table rows
  144.      * 
  145.      * this is used if a form has subtables or joins which are
  146.      * not directly implemented in the table object class to change
  147.      * this values on insert,update or delete
  148.      * 
  149.      * structure of the array:
  150.      * - [tableName][]
  151.      * -- [ROW] => array COL => VALUE
  152.      * -- [OBJ] => DBMS_TABLEOBJ
  153.      * -- [CMD] => one of _OCSP_DBCMD_* cmd
  154.      *
  155.      * @var array 
  156.      */
  157.     protected $myLinkedTableRows = array();
  158.  
  159.     /**
  160.       * @var array $frmPostSubObjVals 
  161.       * 
  162.       *  stru
  163.       * 
  164.       * @since pk-08-03-07
  165.       */
  166.     var $frmPostSubOjects=NULL;
  167.     
  168.  
  169.     /**
  170.       * constructor
  171.       *
  172.       * @param $tblName 
  173.       * @param $debug 
  174.       *
  175.       * @since pk-04-12-21
  176.       *
  177.       ***/
  178.     function DBMS_TABLEOBJ($tblName="",$debug=False{
  179.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::DBMS_TABLEOBJ($tblName)");
  180.  
  181.         if (!empty($tblName)) $this->myTable = $tblName;
  182.         $this->init($debug);
  183.     }
  184.  
  185.  
  186.     /**
  187.       * returns the table name
  188.       *
  189.       * @returns string
  190.       *
  191.       * @since pk-06-01-06
  192.       *
  193.       ***/
  194.     function getMyTable({
  195.         return $this->myTable;
  196.     }
  197.  
  198.     /**
  199.       * sets the table name an recals init
  200.       * if $this->myTable != $aTablName
  201.       *
  202.       * @param string $aTblName 
  203.       * @param boolean $debug 
  204.       *
  205.       * @returns boolean
  206.       *
  207.       * @since pk-06-02-09
  208.       * @version pk-06-05-27
  209.       * @version pk-07-07-11 removed $gDBIDX param
  210.       *
  211.       ***/
  212.     function setMyTable($aTblName,$debug=False{
  213.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setMyTable()","\$aTblName=$aTblName",0);
  214.  
  215.         if (empty($aTblName)) {
  216.             if ($debugechoDebug(__FILE__,"<p>NO TABLE SET</p>",1);
  217.             return False;
  218.         }
  219.  
  220.         if ($this->getMyTable(== $aTblName{
  221.             // do not change table
  222.             if (!$this->initTS$this->init($debug)// init tblobj if not done before
  223.             if ($debugechoDebug(__FILE__,"<p>table already initialized</p>",1);
  224.             return True;
  225.         }
  226.  
  227.         $this->myTable=$aTblName;
  228.         $this->initTS=0// clear init timestamp
  229.         $this->init($debug,False)// <pk-06-05-27 />
  230.         return True;
  231.     }
  232.  
  233.  
  234.     /**
  235.       * initalize the object
  236.       *
  237.       *     - tries to get the object from cache
  238.       *     - if fails load it from db
  239.       *       and write it to chache
  240.       *     - set initTS to now
  241.       *
  242.       * @param boolean $debug      version pk-03-10-24
  243.       * @param boolean $noCache    version pk-06-05-27
  244.       *
  245.       * @version pk-03-10-24
  246.       * @version pk-05-07-13
  247.       * @version pk-06-05-27
  248.       *
  249.       ***/
  250.     function init($debug=False,$noCache=False{
  251.         if ($debug{
  252.             echoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::init()","\$noCache=$noCache",0);
  253.             echo "<blockquote style=\"font-size: 60%;margin-right: 100px;\">";
  254.         }
  255.  
  256.         if (empty($this->myTable)) // <pk-06-05-27 />
  257.             if ($debugechoDebug(__FILE__,"<p>no Table set</p>",1);
  258.             return False;
  259.         }
  260.         if (($noCache|| (strtoupper(get_class($this)) == "DBMS_TABLEOBJ")) // do not cache
  261.             $this->_getDBFields($debug)// <pk-05-07-13 />
  262.             $this->initTS=time();
  263.         else if (!$this->cacheRestore($debug)) // <pk-06-05-27 /> <pk-06-10-20/>
  264.             $this->_getDBFields($debug)// <pk-05-07-13 />
  265.             $this->initTS=time();  // as cacheWriteTo only writes initialized objects this has to be set here
  266.             $this->cacheWriteTo($debug);
  267.         }
  268.  
  269.         $this->initTS=time();
  270.         $this->populateTS=0;
  271.  
  272.         if ($debug{
  273.             echo "<p>initTS: ".$this->initTS."</p></blockquote>";
  274.         }
  275.     }
  276.     
  277.     /**
  278.      * returns if the object is initialized
  279.      *
  280.      * @return boolean 
  281.      */
  282.        public function isInit(
  283.        {
  284.            return (($this->initTS + ini_get('max_execution_time'>= time()));
  285.        }
  286.  
  287.     /**
  288.       * returns the class source file
  289.       * if $this->classSrcFile is set
  290.       *
  291.       * add the following code to your class:
  292.       * <code>
  293.       *  / **
  294.       *   * source file of the class
  295.       *
  296.       *   * @staticvar string $classSrcFile
  297.       *   * @since pk-07-09-17
  298.       *   * /
  299.       *  protected $classSrcFile=__FILE__;
  300.       * </code>
  301.       *
  302.       * @param boolean $debug 
  303.       *
  304.       * @return string 
  305.       *
  306.       * @access public
  307.       * @since pk-07-09-17
  308.       * @version pk-08-03-02
  309.       */
  310.     function getClassInclude($debug=False)
  311.     {
  312.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::getClassInclude()");
  313.  
  314.         if ($str_incFile $this->get_myClassConstant('CLASS_SRC_FILE')) // <pk-08-03-02>
  315.         {   
  316.             return $str_incFile;
  317.         }
  318.         
  319.         if (property_exists(get_class($this),'classSrcFile'|| isset($this->classSrcFile))
  320.         {
  321.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning \$this->classSrcFile: ".$this->classSrcFile);
  322.             return $this->classSrcFile;
  323.         else {
  324.             return $this->getClassFile(False,$debug);
  325.         }
  326.     }
  327.  
  328.     /**
  329.       * sets an array with keys
  330.       *
  331.       * @param array $keyArray 
  332.       * @param boolean $debug since pk-06-05-28
  333.       *
  334.       * @version pk-06-05-28
  335.       *
  336.       ***/
  337.     function db_SetKeyArray$keyArray$debug=False {
  338.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::db_SetKeyArray",print_r($keyArray,True),0);
  339.         foreach($keyArray as $key => $val{
  340.             $this->{$key}=$val;
  341.         }
  342.         $this->valChangeTS=time()// <pk-03-10-25 />
  343.     }
  344.  
  345.  
  346.     /**
  347.       *
  348.       * @param string $kName 
  349.       * @param mixed  $kValue 
  350.       * @param boolean $debug since pk-06-05-28
  351.       *
  352.       */
  353.     function db_SetKey($kName,$kValue,$debug=False{
  354.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::db_SetKey",$kName." => ".$kValue,0);  // <pk-06-05-28 />
  355.                 
  356.         if (!empty($kName)) //
  357.             $this->{$kName}=$kValue;
  358.             $this->valChangeTS=time();  // <pk-03-10-25 />
  359.         else {
  360.             echoDebug(__FILE__,"<p><b>ERROR</b>DBMS_TABLEOBJ::db_SetKey() EMPTY KEY (".get_class($this).")</p>",1);
  361.         }
  362.     }
  363.  
  364.     /**
  365.       * returns the key array
  366.       * an array of all key fields
  367.       *
  368.       * @param bolean $debug 
  369.       *
  370.       * @returns array
  371.       *
  372.       * @since pk-05-06-23
  373.       *
  374.       ***/
  375.     public function getKeyArr($debug=False{
  376.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::getKeyArr()");
  377.         if (!$this->initTS$this->init($debug);
  378.         return $this->myKeys;
  379.     }
  380.  
  381.  
  382.     /**
  383.       * returns if the primary key columns are set
  384.       *
  385.       * @param boolean $debug 
  386.       *
  387.       * @return boolean 
  388.       *
  389.       * @since pk-07-10-02
  390.       */
  391.     function keysAreSet($debug=False)
  392.     {
  393.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::keysAreSet()","<pre>".print_r($this->myKeys,True)."</pre>");
  394.         if (!$this->initTS)
  395.         {
  396.             $this->init($debug);
  397.         }
  398.         
  399.         $b_keysSet=True;
  400.         foreach($this->myKeys as $str_col => $arr_desc)
  401.         {
  402.             if (!isset($this->{$str_col}|| empty($this->{$str_col}))
  403.             {
  404.                 $b_keysSet=False;
  405.             }
  406.         }
  407.         return $b_keysSet;
  408.     }
  409.  
  410.     /**
  411.       * generates a where clause to select the object identfied by DBMS_TBLOBJ::myKeys
  412.       *
  413.       * @param boolean $debug 
  414.       *
  415.       * @return string 
  416.       *
  417.       * @version pk-06-09-14 E_ALL
  418.       *
  419.       ***/
  420.     function getWhere($debug=False{
  421.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::getWhere()");
  422.  
  423.         $s_query=" WHERE ";  // the return string
  424.         $s_and"";          // used to add "AND" if more then one key is set
  425.  
  426.         foreach($this->myKeys as $s_key => $val{
  427.             if (!empty($s_key&& isset($this->{$s_key})) // <pk-06-09-14 />
  428.                 if ($debugecho "<li>$s_key = ".str_replace("'","\'",$this->{$s_key})."'</li>";
  429.                 $s_query.= $s_and $s_key" ='".str_replace("'","\'",$this->{$s_key})."'";
  430.                 $s_and " AND ";
  431.             else if ($debug// <pk-06-09-14>
  432.                 echoDebug(__FILE__,"Key $s_key is EMPTY");
  433.             }
  434.         }
  435.         if ($s_query == " WHERE "return "";
  436.         return $s_query;
  437.     }
  438.  
  439.     /**
  440.       * returns the dbDesc array ($this->myFields);
  441.       *
  442.       * @return array 
  443.       *
  444.       * @since pk-04-08-31
  445.       *
  446.       ***/
  447.     function getDbDesc($debug=False{
  448.         if ($debugecho "<p>DBMS_TABLEOBJ::getDbDesc(...)</b> (".get_class($this).")</p>";
  449.         return $this->myFields;
  450.     }
  451.  
  452.     /**
  453.       * returns the populate timestamp
  454.       * if it returns 0 the object has not been populated
  455.       * which means not that it is empty
  456.       *
  457.       * @returns int
  458.       *
  459.       * @since pk-03-12-18
  460.       ***/
  461.     function getPopulateTs(){
  462.         return $this->populateTS;
  463.     }
  464.  
  465.     /**
  466.       * returns if populateTS > 0
  467.       *
  468.       * @returns boolean
  469.       *
  470.       * @since pk-04-01-05
  471.       *
  472.       ***/
  473.     function isPopulated({
  474.         return ($this->populateTS True False);
  475.     }
  476.  
  477.     /**
  478.       * returns if valChangeTS > populateTS
  479.       *
  480.       * @return boolean 
  481.       *
  482.       * @since pk-06-05-28
  483.       *
  484.       ***/
  485.     function hasChanged({
  486.         return ($this->valChangeTS $this->populateTS);
  487.     }
  488.  
  489.     /**
  490.       * sets the changed flag ($this->valChangeTS > $this-populateTS)
  491.       *
  492.       * @param boolean $debug 
  493.       *
  494.       * @since pk-06-05-28
  495.       *
  496.       ***/
  497.     function setChanged($debug=False{
  498.         $this->valChangeTS=($this->populateTS >($this->populateTS+1time())// increas populateTS as we have secounds and not millisec
  499.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setChanged (Tbl.: ".$this->myTable.")","ValChange: ".$this->valChangeTS."\nPopulate: ".$this->populateTS,0);
  500.     }
  501.  
  502.     /**
  503.       * clears the changed flag
  504.       *
  505.       * @param boolean $debug 
  506.       *
  507.       * @since pk-06-10-24
  508.       *
  509.       ***/
  510.     function setUnChanged($debug=False{
  511.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setUnChanged()");
  512.         $this->valChangeTS=0;
  513.         if (!($this->populateTS 0)) $this->populateTS=1;
  514.     }
  515.  
  516.     /**
  517.       * populates the object from a key array
  518.       * NOTE if more columns fit $keys only the first is set
  519.       *
  520.       * @param array $keys 
  521.       * @param boolean $debug 
  522.       *
  523.       * @return boolean 
  524.       *
  525.       * @since pk-07-08-14
  526.       */
  527.     function populateFromKeys($keys,$debug=False)
  528.     {
  529.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::populateFromKeys()",print_r($keys,True));
  530.  
  531.         if (!is_array($keys))
  532.         {
  533.             ocsp_logError(__FILE__,__LINE__,get_class($this)."::populateFromKeys no key array submitted");
  534.             return False;
  535.         }
  536.         
  537.         $str_query  "SELECT * FROM ".$this->myTable;
  538.         $str_query .=  $this->getDBObj('r')->qs_getWhereClause($keys,$debug);
  539.  
  540.         if ($debugechoDebugLine(__FILE__,__LINE__,"Query$str_query");
  541.  
  542.         if ($arr_row $this->getDBObj('r')->quickQuery($str_query))
  543.         {
  544.             $this->setDBRow($arr_row,True,$debug);
  545.             return True;
  546.         else {
  547.             return False;
  548.         }
  549.  
  550.     }
  551.  
  552.     /**
  553.      * populates the object by extracting keys from a value array
  554.      *
  555.      * @param array $arrValues 
  556.      * @param boolean $debug 
  557.      * 
  558.      * @return boolean 
  559.      * 
  560.      * @since pk-08-12-18
  561.      */
  562.     function populateFromValues($arrValues,$debug=False)
  563.     {
  564.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::populateFromValues();");
  565.         
  566.         if (!is_array($arrValues)) return False;
  567.         
  568.         if ($arr_keys $this->getKeyArr())
  569.         {
  570.             $arr_filter array();
  571.             foreach($arr_keys as $str_key => $arr_desc)
  572.             {
  573.                 if (!isset($arrValues[$str_key])) 
  574.                 {
  575.                     return False;
  576.                 }
  577.                 $arr_filter[$str_key$arrValues[$str_key]
  578.             }
  579.             
  580.             if ($arr_row $this->getDBObj()->getRow($this->getMyTable(),$arr_filter,$debug))
  581.             {
  582.                 $this->setDBRow($arr_row,True);
  583.                 return True;                
  584.             }
  585.         else if ($debug{
  586.             echoDebugLine(__FILE__,__LINE__,"No keys for this object");
  587.         }
  588.         return False;
  589.         
  590.     }
  591.     
  592.     /**
  593.       * populates the object values form the database
  594.       *
  595.       *
  596.       * @since pk-03-12-18 calls $this->setDBRow() to set the object values
  597.       *
  598.       * @param string $gDBIDX GLOBAL ARRAY INDEX OF DB OBJECT
  599.       * @param boolean $debug  SHOW DEBUG INFO
  600.       *
  601.       * @returns boolean    found row ?
  602.       *
  603.       * @version pk-07-06-01
  604.       *
  605.       ***/
  606.     function dbPopulate($debug=False{
  607.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::dbPopulate()");
  608.         if ($debugecho "<blockquote style=\"font-size: 90%;background-color: #F0F0F0;\">";
  609.  
  610.         if (empty($this->myTable)) {  // from where ??
  611.             ocsp_logError(__FILE__,__LINE__,"no table set for ".get_class($this)." object ",E_ERROR);
  612.             if ($debugecho "</blockquote>";
  613.             return False;
  614.         }
  615.         
  616.         if (!$this->isInit())
  617.         {
  618.             $this->init($debug);
  619.         }
  620.  
  621.         if (!$this->keysAreSet()) {
  622.             if ($debugocsp_logError(__FILE__,__LINE__,"keys are not set",E_NOTICE);
  623.             if ($debugecho "</blockquote>";
  624.             return False;
  625.         }
  626.  
  627.         $query ="SELECT * FROM ".$this->myTable;
  628.         if ($str_where=$this->getWhere($debug))
  629.         {
  630.             $query.=$str_where;
  631.         else {
  632.             if ($debug{
  633.                 ocsp_logError(__FILE__,__LINE__,"no keys set for ".get_class($this)." object ",E_ERROR);
  634.                 echo "</blockquote>";
  635.             }
  636.             return False;
  637.         }
  638.         
  639.         if ($debugechoDebugLine(__FILE__,__LINE__,"Populate Query$query");
  640.         
  641.         if (!$this->isConnected(True,$debug))
  642.         {
  643.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  644.             if ($debugecho "</blockquote>";
  645.             return False;
  646.         }
  647.  
  648.         if ($debugechoDebugLine(__FILE__,__LINE__,"Populate Query$query");
  649.  
  650.         if (!$row=$this->getDBObj('r')->quickQuery($query)) {
  651.             $this->populateTS=0;
  652.             if ($debugocsp_logError(__FILE__,__LINE__,"$query returned no row class".get_class($this),E_NOTICE);
  653.             if ($debugecho "</blockquote>";
  654.             return False;
  655.         }
  656.         
  657.         if ($debug)
  658.         {
  659.             echoDebugLine(__FILE__,__LINE__,"got row");
  660.             if ($debugecho "</blockquote>";
  661.         }
  662.         
  663.         $bol_ret $this->setDBRow($row,True,$debug);
  664.         if ($debugechoDebugLine(__FILE__,__LINE__,"dbPopulate Returns: " ($bol_ret 'True' 'False'));
  665.         return $bol_ret;
  666.     }
  667.     
  668.  
  669.     /**
  670.       * populates the Object values
  671.       *
  672.       * @param boolean $debug 
  673.       *
  674.       * @return int sizeof myObjVals
  675.       *
  676.       * @since pk-05-07-13
  677.       * @version pk-07-04-16
  678.       *
  679.       ***/
  680.     function populateObjVals($debug=False{
  681.         if ($debugecho "<p><b>DBMS_TABLEOBJ::populateObjVals()</b> (".get_class($this).")</p>";
  682.         if ($this->hasObjVals(&& intval($this->getDBField($this->autoIncFld))) // <pk-07-08-18 />
  683.         {
  684.             if (!$this->isConnected(True,$debug))
  685.             {
  686.                 ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  687.                 return False;
  688.             }
  689.             // <pk-07-04-16 /> check if the outIncFld has a value
  690.             $s_Query="SELECT tbl.OV_NAME as VAR_NAME, tbl.* FROM ".$this->myTable."_OV tbl WHERE ".$this->autoIncFld."=".intval($this->getDBField($this->autoIncFld));
  691.             if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Object Value Query: <br />$s_Query</p>");
  692.             $this->myObjVals=$this->getDBObj('r')->queryArray($s_Query,0,-1);
  693.             $this->myObjValsPopulateTS=time();
  694.  
  695.             if (!is_array($this->myObjVals)) $this->myObjVals=array();
  696.             if ($debugechoDebugLine(__FILE__,__LINE__,"myObjVals:<pre style=\"font-size:75%\">".print_r($this->myObjVals,True)."</pre>");
  697.  
  698.             return sizeof($this->myObjVals);
  699.         else {
  700.             return 0;
  701.         }
  702.     }
  703.  
  704.     // -------------------------------------------------------
  705.     // db save methods (insert / replace (update) / delete)
  706.     // -------------------------------------------------------
  707.  
  708.     /**
  709.       * save the Object if $this->autoIncFld is not empty
  710.       *
  711.       * if (!empty($this->{$this->autoIncFld})) dbReplace is called else dbInsert
  712.       *
  713.       * overwrite in child classes to addopt to your needs
  714.       *
  715.       * @param string $gDBIDX GLOBAL ARRAY INDEX OF DB OBJECT
  716.       * @param boolean   $debug  SHOW DEBUG INFO
  717.       *
  718.       * @return mixed 
  719.       *
  720.       * @version pk-03-10-18
  721.       * @version pk-05-11-19 bugfix if no autoIncFld call replace
  722.       * @version pk-05-12-29 debug bugfix
  723.       *
  724.       *  history
  725.       *  - pk-03-10-18:
  726.       *        parame changed $mode -> $gDBIDX="USRDB",$debug=False
  727.       *
  728.       ***/
  729.     function dbSave($debug=False
  730.     {
  731.         if ($debug{
  732.             echoDebugMethod (__FILE__,get_class($this),"DBMS_TABLEOBJ::dbSave()");
  733.             if (!empty($this->autoIncFld)) // <pk-05-12-29>
  734.                 echoDebugLine(__FILE__,__LINE__,"<p>Auto Inc Field: ".$this->autoIncFld." has value: ".$this->{$this->autoIncFld}."</p>");
  735.             else {
  736.                 echoDebug(__FILE__,__LINE__,"<p>NO Auto Inc Field</p>");
  737.             // </pk-05-12-29>
  738.         }
  739.  
  740.         if (empty($this->autoIncFld|| (!empty($this->{$this->autoIncFld}))) // <pk-05-11-19 />
  741.             return $this->dbReplace($debug);
  742.         else
  743.             return $this->dbInsert($debug);
  744.     }
  745.  
  746.     /**
  747.       * saves the object values
  748.       *
  749.       * @param string $gDBIDX 
  750.       * @param boolean $clearFirst 
  751.       * @param boolean $debug 
  752.       *
  753.       * @returns int
  754.       *
  755.       * @since pk-05-07-14
  756.       * @version pk-07-08-18
  757.       *
  758.       ***/
  759.     function saveObjVals($clearFirst=False,$debug=False{
  760.         if ($debugechoDebugMethod(__FILE__,pcf_object_id($this),"DBMS_TABLEOBJ::saveObjVals(\$clearFirst=".intval($clearFirst).")");
  761.  
  762.         if (!$this->hasObjVals()) return 0// <pk-07-08-18 />
  763.  
  764.         if (!$this->isConnected(True,$debug)) // <pk-07-08-18>
  765.         {
  766.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  767.             return False;
  768.         }
  769.  
  770.         if (!intval($this->getDBField($this->autoIncFld))) {
  771.             ocsp_logError(__FILE__,__LINE__,"no autoIncFld set",E_ERROR);
  772.             return False;
  773.         }
  774.  
  775.         if ($clearFirst{
  776.             $s_Cmd="DELETE FROM ".$this->myTable."_OV tbl WHERE ".$this->autoIncFld."=".intval($this->getDBField($this->autoIncFld));
  777.             if ($debugechoDebugLine(__FILE__,__LINE__,"clear first:".$s_Cmd);
  778.             $this->getDBObj('w')->executeCmd($s_Cmd);
  779.         }
  780.  
  781.         if (is_array($this->myObjVals)) {
  782.             foreach($this->myObjVals as $s_name => $a_row{
  783.                 if (!empty($a_row['OV_VALUE'])) {
  784.                     $a_row[$this->autoIncFld]=intval($this->getDBField($this->autoIncFld));
  785.                     if (empty($a_row['OV_TYPE'])) $a_row['OV_TYPE']="string";
  786.                     if ($debugechoDebugLine(__FILE__,__LINE__,"setting $s_name to (".$a_row['OV_TYPE'].") ".$a_row['OV_VALUE']);
  787.                     $this->getDBObj('w')->replaceArray($this->myTable."_OV",$a_row);
  788.                 else if (!$clearFirst{
  789.                     if ($debugechoDebugLine(__FILE__,__LINE__,"deleting $s_name");
  790.                     $s_Cmd ="DELETE FROM ".$this->myTable."_OV ";
  791.                     $s_Cmd.=" WHERE ".$this->autoIncFld."=".intval($this->getDBField($this->autoIncFld));
  792.                     $s_Cmd.="   AND OV_NAME=".$this->getDBObj('w')->qs_getSlashedValue($s_name);
  793.                     $this->getDBObj('w')->executeCmd($s_Cmd);
  794.                 }
  795.             }
  796.         }
  797.     }
  798.  
  799.     /**
  800.       * inserts a new row to the table
  801.       *
  802.       * @param boolean   $debug  show debug info
  803.       *
  804.       * @return int   returns the autoIncFld ID if exists or 1 on success
  805.       *
  806.       * @version pk-03-10-22
  807.       * @version pk-03-10-25
  808.       * @version pk-04-12-21
  809.       * @version pk-06-01-24
  810.       * @version pk-07-08-17
  811.       * @version pk-08-03-07 linkedTables
  812.       */
  813.     function dbInsert($debug=False
  814.     {
  815.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::dbInsert()");
  816.  
  817.         if (empty($this->myTable)) 
  818.         {  // into which table ??
  819.             throw new Exception(_OCSP_TABLE_NOTABLE_ ":" get_class($this));
  820.         }
  821.  
  822.         if (!$this->isConnected(True,($debug 1)))
  823.         {
  824.             throw new Exception(_OCSP_EXCEP_NODBCONN_);
  825.         }
  826.  
  827.         if (!empty($this->autoIncFld)) {
  828.             // <pk-03-10-25>
  829.             // <pk-06-01-24>
  830.             if ($debugecho "<p>autoIncFld: ".$this->autoIncFld."</p>";
  831.  
  832.             $a_row=$this->getDBRow(False,$debug);
  833.             if ($debugechoDebugLine(__FILE__,__LINE__,"<pre style=\"font-size: 75%\">".print_r($a_row,True)."</pre>");
  834.             unset($a_row[$this->autoIncFld]);
  835.             // </pk-06-01-24>
  836.             try {
  837.                 if ($this->{$this->autoIncFld}=$this->getDBObj('w')->insertArray($this->myTable,$a_row,$debug)) 
  838.                 {
  839.                     $this->populateTS=time();   // <pk-03-12-19 />
  840.                     $this->valChangeTS=0;       // <pk-03-10-25 />
  841.     
  842.                     $this->saveLinkedTableRows($debug)// <pk-08-03-07 />
  843.                     
  844.                     // <pk-05-07-14>
  845.                     if ($this->hasObjVals()) // <pk-07-08-18 />
  846.                     {
  847.                         $this->saveObjVals(False,$debug);
  848.                     }
  849.                     // </pk-05-07-14>
  850.     
  851.                     return $this->{$this->autoIncFld};
  852.                     // </pk-03-10-25>
  853.                 else {
  854.                     if ($debugechoDebugLine(__FILE__,__LINE__,"<h1 style=\"color: red\">INSERT FAILED</h1>");
  855.                     throw new Exception(_OCSP_EXCEP_INSERTFAILED_);
  856.                 }
  857.             catch(Exception $e{
  858.                 if ($debugechoDebugLine(__FILE__,__LINE__,"Insert failed: <pre>" print_r($e,True"</pre>");
  859.                 throw new Exception(_OCSP_EXCEP_INSERTFAILED_)
  860.             }
  861.         else {
  862.             /* <pk-03-10-25> */
  863.             if ($ret $this->getDBObj('w')->insertArray($this->myTable,$this->getDBRow(False,$debug),$debug)) {
  864.                 $this->valChangeTS=0/* <pk-03-10-25 /> */
  865.                 $this->populateTS=time();   /* <pk-03-12-19 /> */
  866.                 return True;
  867.             else {
  868.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<h1 style=\"color: red\">INSERT FAILED</h1>");
  869.                 throw new Exception(_OCSP_EXCEP_INSERTFAILED_);
  870.             }
  871.             /* </pk-03-10-25> */
  872.         }
  873.     }
  874.  
  875.     /**
  876.       * replaces a row in the table
  877.       *
  878.       * if the object has not been populated (!$this->populateTS)
  879.       * False is returned
  880.       *
  881.       * @param boolean $debug  show debug info
  882.       * @param boolean $ignorPopulated (if False the table MUST have been populated)
  883.       *
  884.       * @return boolean 
  885.       *
  886.       * @version pk-03-10-22
  887.       * @version pk-07-08-17
  888.       * @version pk-07-12-06 $ignorPopulated added
  889.       ***/
  890.     function dbReplace($debug=False,$ignorPopulated=False
  891.     {
  892.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::dbReplace()","Table: ".$this->myTable,0);
  893.  
  894.         if (!$this->isConnected(True,$debug))
  895.         {
  896.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  897.             die();
  898.         }
  899.  
  900.         if (empty($this->myTable)) {  // into which table ??
  901.             $this->setError("NO TABLE SET");
  902.             if ($debugechoDebugLine(__FILE__,__LINE__,"dbReplace returns False: NO TABLE SET");
  903.             return False;
  904.         }
  905.  
  906.         if ((!$this->populateTS&& (!ignorPopulate)) 
  907.         {                            // table must be populated first
  908.                                      // this is for comatibility whith other dbs then mysql
  909.                                      // wich does not know REPLACE statement
  910.                                      // and REPLACE is done by insert and update
  911.             $this->setError("TABLE HAS NOT BEEN POPULATED");
  912.             if ($debugechoDebugLine(__FILE__,__LINE__,"dbReplace returns False: TABLE HAS NOT BEEN POPULATED");
  913.             return False;
  914.         }
  915.         $this->valChangeTS 0;     // <pk-03-10-25 />
  916.         $this->populateTS time()// <pk-03-12-19 />
  917.                 
  918.         if ($debugecho "<blockquote>";
  919.         $row=$this->getDBRow(True,$debug);
  920.         if ($debugecho "</blockquote>";
  921.         
  922.         if ($this->getDBObj('w')->replaceArray($this->myTable,$row,$debug)) {
  923.             if ($this->hasObjVals()) // <pk-07-08-18 />
  924.             {
  925.                 $this->saveObjVals(False,$debug);
  926.             }
  927.             // </pk-05-07-14>
  928.             if ($debugechoDebugLine(__FILE__,__LINE__,"dbReplace returns True");
  929.             
  930.             // <pk-08-02-01>
  931.             if (is_array($this->myLinkedTableRows&& sizeof($this->myLinkedTableRows))
  932.             {
  933.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<h1>linkedTableRows</h1><pre>".print_r($this->myLinkedTableRows,True)."</pre>");                
  934.                 
  935.                 $arr_keys=$this->getKeyArr();
  936.                 $arr_keyVals=array();
  937.                 foreach($arr_keys as $str_name => $arr_desc)
  938.                 {
  939.                     $arr_keyVals[$arr_desc['NAME']] $this->getDBField($arr_desc['NAME']);
  940.                 }
  941.                 
  942.                 //echo "KeyVals: <pre>".print_r($arr_keyVals,True)."</pre>";
  943.                 
  944.                 foreach($this->myLinkedTableRows as $str_table => $arr_cmdRowList)
  945.                 {
  946.  
  947.                     foreach($arr_cmdRowList as $arr_cmdRow)
  948.                     {
  949.                         foreach($arr_keyVals as $str_col => $mix_val)
  950.                         {
  951.                             $arr_cmdRow['ROW'][$str_col$mix_val;
  952.                         }
  953.                         
  954.                         switch($arr_cmdRow['CMD'])
  955.                         {
  956.                             case _OCSP_DBCMD_INSERT_
  957.                                 $this->getDBObj('w')->insertArray($str_table,$arr_cmdRow['ROW'],$debug);
  958.                                 break;
  959.                             case _OCSP_DBCMD_REPLACE_:
  960.                                 $this->getDBObj('w')->replaceArray($str_table,$arr_cmdRow['ROW'],$debug);
  961.                                 break;
  962.                             case _OCSP_DBCMD_UPDATE_:
  963.                                 $this->getDBObj('w')->updateArray($str_table,$arr_cmdRow['ROW'],$debug);
  964.                                 break;            
  965.                             case _OCSP_DBCMD_DELETE_:
  966.                                 $this->getDBObj('w')->deleteArray($str_table,$arr_cmdRow['ROW'],$debug);
  967.                                 break;          
  968.                             default:                            
  969.                                 ocsp_logError(__FILE__,__LINE__," linkedTable CMD " $arr_cmdRow['CMD'" not implemented",E_ERROR);
  970.                         }        
  971.                     }
  972.                 }
  973.                 
  974.             }
  975.             // </pk-08-02-01>
  976.             
  977.             return True;
  978.         else {
  979.             if ($debugechoDebugLine(__FILE__,__LINE__,"dbReplace returns False");
  980.             $this->setError("Konnte Datensatz nicht ersetzen");
  981.             return False;
  982.         }
  983.     }
  984.  
  985.     /**
  986.       * deletes the row from the database
  987.       *
  988.       * @param boolean $backupData 
  989.       * @param boolean $debug 
  990.       *
  991.       * @global array $OCSP_CONF 
  992.       *
  993.       * @returns boolean
  994.       *
  995.       * @since pk-05-02-08
  996.       * @version pk-05-02-12
  997.       * @version pk-05-07-29
  998.       * @version pk-05-09-05 also delete object vals
  999.       * @version pk-05-11-17 bugfix output started
  1000.       *
  1001.       */
  1002.     function dbDelete($backupData=False,$debug=False
  1003.     {
  1004.         global $OCSP_CONF;
  1005.  
  1006.         if ($debugechoDebugMethod(__FILE__,__LINE__,"DBMS_TABLEOBJ::dbDelete($backupData,...)");
  1007.  
  1008.         if (empty($this->myTable)) {  // into which table ??
  1009.             if ($debugecho "<p style='color=red;'>NO TABLE SET</p></blockquote><hr>";
  1010.             return False;
  1011.         }
  1012.  
  1013.         if (!$this->populateTS{    // table must be populated first
  1014.                                      // to be able to do the backup
  1015.             if ($debugecho "<p style='color=red;'>TABLE HAS NOT BEEN POPULATED</p></blockquote><hr>";
  1016.             $this->setError("L&Ouml;SCHEN: Datensatz nicht geladen");
  1017.             return False;
  1018.         }
  1019.  
  1020.         if (!$this->isConnected(True))
  1021.         {
  1022.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1023.             return False;
  1024.         }
  1025.  
  1026.         $cmd="DELETE FROM ".$this->myTable." ";
  1027.         if (!($where=$this->getWhere($debug))) {
  1028.             $this->setError("L&Ouml;SCHEN: Keine WHERE Bedingung");
  1029.             return False;
  1030.         }
  1031.         $cmd.=$where;
  1032.  
  1033.         if ($backupData{
  1034.             $int_backupMode=(isset($OCSP_CONF['DELBACKUPMODE']intval($OCSP_CONF['DELBACKUPMODE']0);
  1035.             switch($int_backupMode{
  1036.                 // planed to add some different modes like db
  1037.                 // set deletedflag
  1038.                 default:
  1039.                     if (empty($OCSP_CONF['BACKUPPATH'])) {
  1040.                         $backupDir=$OCSP_CONF['PROJECTPATH']."backup"._OCSP_DIRSEP_.trim($this->myTable)// <pk-06-07-24 /> trim table name
  1041.                     else {
  1042.                         $backupDir=$OCSP_CONF['BACKUPPATH'].trim($this->myTable);  // <pk-06-07-24 /> trim table name
  1043.                     }
  1044.                     require_once __OCSP_PHPINCPATH__."common/pcf_directory.phpinc";
  1045.                     if (pcf_checkDir($backupDir,True)) {
  1046.                         $filename="";
  1047.                         require_once __OCSP_PHPINCPATH__."common/pcf_file.phpinc";
  1048.                         $sep="";
  1049.                         foreach($this->myKeys as $key => $val{
  1050.                             $filename .= $sep.pcf_checkFileName($key)."_".pcf_checkFileName($this->{$val['NAME']})// <pk-05-07-29 /> bugfix
  1051.                             $sep="-";
  1052.                         }
  1053.                         if ($fp=fopen($backupDir._OCSP_DIRSEP_.$filename.".rowsave","w")) {
  1054.                             fwrite($fp,"<?php \n");
  1055.                             fwrite($fp,"\t\$objClass=\"".get_class($this)."\";\n");
  1056.                             $objVars=get_object_vars($this);
  1057.                             fwrite($fp,"\\*\n".str_replace("*\\","*__\\",print_r($objVars,True))."\n*\\")// <pk-05-11-17 /> bugfix output
  1058.                             foreach($objVars as $var => $val{
  1059.                                 if (!empty($val)) /* <pk-05-03-12> */
  1060.                                     $varStr="b64Data['".$var."']";
  1061.                                     $valStr=base64_encode($val."");
  1062.                                     fwrite($fp,"\t\$".$varStr."=\"".$valStr."\";\n");
  1063.                                 }
  1064.                             }
  1065.                             if ($this->hasObjVals()) // <pk-07-08-18 /> // <pk-05-09-05>
  1066.                             {
  1067.                                 fwrite($fp,"\$a_b64OV=array();\n");
  1068.                                 $s_query="SELECT * FROM ".$this->myTable."_OV WHERE ".$this->autoIncFld."=".$this->{$this->autoIncFld};
  1069.                                 if ($o_cursor=$this->getDBObj('r')->query($s_query)) {
  1070.                                     while($a_row=$o_cursor->fetchArrayFld()) {
  1071.                                         fwrite($fp,"\$a_b64OV[]=\"".base64_encode(serialize($a_row))."\";\n");
  1072.                                     }
  1073.                                 }
  1074.                             // </pk-05-09-05>
  1075.                             fwrite($fp,"?>");
  1076.                             fclose($fp);
  1077.                         else {
  1078.                             if ($debugecho "<p style=\"color:red;font-weight:bold\">ERROR could not creat file ".$backupDir."/".$filename.".rowsave"."</p>";
  1079.                         }
  1080.                     else {
  1081.                         if ($debugecho "<p style=\"color:red;font-weight:bold\">ERROR could not creat dir $backupDir</p>";
  1082.                     }
  1083.             }
  1084.         }
  1085.  
  1086.         if ($debugechoDebugLine(__FILE__,__LINE__,"<blockquote><p>".$cmd."</p></blockquote>");
  1087.         if ($this->getDBObj('w')->executeCmd($cmd)) {
  1088.  
  1089.             if ($this->hasObjVals()) // <pk-07-08-18 /> // <pk-05-09-05>
  1090.             {
  1091.                 $s_cmd="DELETE FROM ".$this->myTable."_OV WHERE ".$this->autoIncFld."=".$this->{$this->autoIncFld};
  1092.                 if ($debugecho "<blockquote>Deleting Object Vals<p>".$s_cmd."</p></blockquote>";
  1093.                 $this->getDBObj('w')->executeCmd($s_cmd);
  1094.             // </pk-05-09-05>
  1095.             return True;
  1096.         else {
  1097.             $this->setError("Konnte Datensatz nicht l&ouml;schen");
  1098.             return False;
  1099.         }
  1100.  
  1101.     }
  1102.  
  1103.     
  1104.     // ----------------------------------------------------------
  1105.     //  linked tables (joins) 
  1106.     // ----------------------------------------------------------
  1107.         
  1108.     /**
  1109.      * sets the row of an other table
  1110.      * 
  1111.      * this method is used to cache form values of other tables
  1112.      * which are joined in to $this->myTable
  1113.      * 
  1114.      * this rows must be considert in insert,update,delete
  1115.      * 
  1116.      * possible commands are
  1117.      * - _OCSP_DBCMD_INSERT_  (insert a new row)
  1118.      * - _OCSP_DBCMD_REPLACE_ (update an existing row or insert if not exists)
  1119.      * - _OCSP_DBCMD_UPDATE_  (update an existing row)
  1120.      * - _OCSP_DBCMD_DELETE_  (delete an existing row)
  1121.      *
  1122.      * @param string $tblName 
  1123.      * @param string $dbCmd 
  1124.      * @param array $aRow 
  1125.      * @param boolean $debug 
  1126.      * 
  1127.      */
  1128.     function setLinkedTableRow($tblName,$dbCmd,$aRow,$debug=False)
  1129.     {       
  1130.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setLinkedTableRow($tblName,$dbCmd,...);");
  1131.         
  1132.         if (!is_array($aRow|| !sizeof($aRow))
  1133.         {
  1134.             return False;
  1135.         }
  1136.         
  1137.         if (!isset($this->myLinkedTableRows[$tblName]))
  1138.         {
  1139.             $this->myLinkedTableRows[$tblName]=array();   
  1140.         }
  1141.         
  1142.         $str_idx md5($dbCmd implode('_',$aRow));
  1143.         $this->myLinkedTableRows[$tblName][$str_idx]['ROW']=$aRow;
  1144.         $this->myLinkedTableRows[$tblName][$str_idx]['CMD']=$dbCmd;
  1145.         
  1146.         if ($debugechoDebugLine(__FILE__,__LINE__,"LinkTable added: <pre>".print_r($this->myLinkedTableRows,True)."</pre>");
  1147.     }
  1148.     
  1149.     /**
  1150.      * handels linked tables after insert
  1151.      *
  1152.      * @param boolean $debug 
  1153.      * 
  1154.      * @return boolean 
  1155.      * 
  1156.      * @since pk-08-07-03
  1157.      * 
  1158.      */
  1159.     protected function saveLinkedTableRows($debug)
  1160.     {
  1161.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::insertLinkedTableRows()");
  1162.         if (sizeof($this->myLinkedTableRows))
  1163.         {
  1164.             foreach($this->myLinkedTableRows as $str_tbl => $arr_tblEntries)
  1165.             {
  1166.                 foreach($arr_tblEntries as $arr_rowcmd)
  1167.                 {
  1168.                     $this->saveLinkedRow($str_tbl,$arr_rowcmd['ROW'],$arr_rowcmd['CMD'],$debug);            
  1169.                 }
  1170.             }
  1171.         }
  1172.         return False;
  1173.     }
  1174.     
  1175.     /**
  1176.      * saves a linked row due to $cmd
  1177.      *
  1178.      * @param string $table 
  1179.      * @param array $row 
  1180.      * @param string $cmd (_OCSP_DBCMD_*)
  1181.      * @param boolean $debug 
  1182.      * 
  1183.      * @return boolean 
  1184.      * 
  1185.      * @since pk-08-03-07
  1186.      */
  1187.     public function saveLinkedRow($table,$row,$cmd,$debug=False)
  1188.     {
  1189.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::inserLinkedRow()");
  1190.         
  1191.         if (!is_array($this->myKeys))
  1192.         {
  1193.             throw new Exception(_OCSP_TABLE_NOTINIT_);
  1194.             return False;
  1195.         }
  1196.         
  1197.         if (!$this->isConnected(True))
  1198.         {
  1199.             throw new Exception(_OCSP_EXCEP_NODBCONN_);
  1200.             return False;
  1201.         }
  1202.         
  1203.         foreach($this->myKeys as $str_col => $arr_desc)
  1204.         {
  1205.             if ($mix_val $this->getDBField($str_col))
  1206.             {
  1207.                 $row[$str_col$mix_val;
  1208.             }
  1209.         }
  1210.  
  1211.         switch($cmd)
  1212.         {
  1213.             case _OCSP_DBCMD_INSERT_
  1214.                 return $this->getDBObj('w')->insertArray($table,$row,$debug);
  1215.             case _OCSP_DBCMD_REPLACE_:
  1216.                 return $this->getDBObj('w')->replaceArray($table,$row,$debug);
  1217.             case _OCSP_DBCMD_UPDATE_:
  1218.                 return $this->getDBObj('w')->updateArray($table,$row,$debug);            
  1219.             case _OCSP_DBCMD_DELETE_:
  1220.                 return $this->getDBObj('w')->deleteArray($table,$row,$debug);
  1221.             default:                            
  1222.                 if ($debugocsp_logError(__FILE__,__LINE__," linkedTable CMD " $arr_cmdRow['CMD'" not implemented",E_ERROR);
  1223.         }    
  1224.         return False;                
  1225.     }
  1226.     
  1227.     // ---------------------------------------------------------
  1228.     // column methods
  1229.     // ---------------------------------------------------------
  1230.     
  1231.     
  1232.     /**
  1233.       * returns if the table as a column named $colName
  1234.       *
  1235.       * @param string $colName 
  1236.       *
  1237.       * @returns boolean
  1238.       *
  1239.       * @since pk-05-07-28
  1240.       * @version pk-06-06-26
  1241.       *
  1242.       ***/
  1243.     function hasColumn($colName{
  1244.         if (isset($this->myFields[$colName])) return True;
  1245.         return False;
  1246.     }
  1247.  
  1248.     /**
  1249.       * returns the value of a db column
  1250.       *
  1251.       * NOTE no check of the value is accurate
  1252.       *
  1253.       * @param string $aColumn (name of the db column and the obj var holding the value of the column)
  1254.       * @param boolean $debug 
  1255.       * @param boolean $autoPopulate (populate the row if keysAreSet)
  1256.       *
  1257.       * @returns mixed
  1258.       *
  1259.       * @version pk-05-07-14
  1260.       * @version pk-07-08-22 check if the object is populated
  1261.       * @version pk-07-10-21 $autoPopulate to avoid enless loops
  1262.       * @version pk-08-10-14
  1263.       */
  1264.     public function getDBField($aColumn,$debug=False,$autoPopulate=True
  1265.     {
  1266.         // <pk-08-10-14>
  1267.         if (!$this->isInit())
  1268.         {
  1269.             $this->init();
  1270.         }
  1271.  
  1272.         if (!isset($this->myFields[$aColumn]))
  1273.         {
  1274.             if ($this->hasObjVals())
  1275.             {
  1276.                 if ($mix_ret $this->getObjValValue($aColumn,$autoPopulate,$debug))
  1277.                 {
  1278.                     return $mix_ret;         
  1279.                 }
  1280.             else {
  1281.                 if ($debugechoDebugLine(__FILE__,__LINE__,"WARNING: " $aColumn " not in table " $this->myTable);
  1282.             }
  1283.         }
  1284.  
  1285.         
  1286.         if (!$this->isPopulated(&& $autoPopulate)
  1287.         {
  1288.             if ($this->keysAreSet())
  1289.             {
  1290.                 $this->dbPopulate($debug);
  1291.             else {
  1292.                 if ($debugocsp_logError(__FILE__,__LINE__,get_class($this)." not populated when getting field $aColumn",E_NOTICE);
  1293.             }
  1294.         }
  1295.         
  1296.         if (isset($this->{$aColumn}))
  1297.         {
  1298.             return $this->{$aColumn};
  1299.         else {
  1300.             return Null;            
  1301.         }        
  1302.     }
  1303.  
  1304.     /**
  1305.       * sets the value of a object var (DB COLUMN)
  1306.       *
  1307.       * NOTE: does not save youe have to call DBMS_TBLOBJ::dbsave() to save
  1308.       *       the value permanently in the database
  1309.       *
  1310.       * @param string $aField DB Column Name or Obj Field
  1311.       * @param mixed  $aValue the value to set
  1312.       * @param boolean $debug since pk-05-07-28
  1313.       * @param boolean $strict do not use objVals
  1314.       *
  1315.       * @version pk-05-07-14
  1316.       * @version pk-05-07-28
  1317.       * @version pk-06-10-11
  1318.       * @version pk-07-10-01
  1319.       *
  1320.       */
  1321.     public function setDBField($aField,$aValue,$debug=False,$strict=False{
  1322.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setDBField($aField,".htmlspecialchars(substr($aValue,0,10))."...)");
  1323.         // <pk-06-10-11>
  1324.         if ($this->hasObjVals(&& (!isset($this->myFields[$aField])) && (!$strict)) // <pk-07-08-18 />
  1325.             if ($debugechoDebugLine(__FILE__,__LINE__,"Setting ObjValue");
  1326.             $this->setObjValValue($aField,$aValue);
  1327.             $this->setChanged();
  1328.         else if (isset($this->myFields[$aField])) {
  1329.             if ($debugechoDebugLine(__FILE__,__LINE__,"Column Value");
  1330.             $this->$aField=$aValue;
  1331.             $this->setChanged();
  1332.         else if ((!$strict&& (!empty($aField))) // <pk-06-10-24 />
  1333.             if ($debugechoDebugLine(__FILE__,__LINE__,"Field Value");
  1334.             $this->$aField=$aValue;
  1335.             $this->setChanged();
  1336.         }
  1337.         // </pk-06-10-11>
  1338.     }
  1339.  
  1340.     /**
  1341.       * sets the value of an object var (DB COLUMN) if it differs with $aValue
  1342.       *
  1343.       * if you use this method you can check with $this::hasChanged() method if
  1344.       * the object values differs from the database value.
  1345.       *
  1346.       *
  1347.       * @param string $aField   DB Column Name or Obj Field
  1348.       * @param mixed  $aValue   the value to set
  1349.       * @param boolean $debug   since pk-05-07-28
  1350.       *
  1351.       * @since pk-06-08-11
  1352.       *
  1353.       ***/
  1354.     public function setDBFieldIfDiff($aField,$aValue,$debug=False{
  1355.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setDBFieldIfDiff()",$aField.": \n".htmlspecialchars(substr($aValue,0,10)));
  1356.  
  1357.         $s_curVal=strval($this->getDBField($aField));
  1358.         if ($s_curVal != strval($aValue)) {
  1359.             $this->setDBField($aField,$aValue,$debug);
  1360.         }
  1361.     }
  1362.  
  1363.     /**
  1364.       * sets the value of an column if it is empty or not set
  1365.       *
  1366.       * if you use this method you can check with $this::hasChanged() method if
  1367.       * the object values differs from the database value.
  1368.       *
  1369.       * @param string $aField   DB Column Name or Obj Field
  1370.       * @param mixed  $aValue   the value to set
  1371.       * @param boolean $debug   since pk-05-07-28
  1372.       *
  1373.       * @since pk-06-12-20
  1374.       *
  1375.       ***/
  1376.     public function setDBFieldIfEmpty($aField,$aValue,$debug=False{
  1377.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setDBFieldIfEmpty()",$aField.": \n".htmlspecialchars(substr($aValue,0,10)));
  1378.  
  1379.         if (!$this->getDBField($aField)) {
  1380.             $this->setDBField($aField,$aValue,$debug);
  1381.         }
  1382.     }    
  1383.     
  1384.     /**
  1385.       * sets an object var if it's empty or null
  1386.       * NOTE the object var has to be set already
  1387.       * NOTE does not set the changed flag
  1388.       *
  1389.       * @param string $varName 
  1390.       * @param mixed $value 
  1391.       *
  1392.       * @return boolean (the value has been set)
  1393.       */
  1394.     public function setObjVarIfEmpty($varName,$value)
  1395.     {
  1396.         if (isset($this->{$varName}&& empty($this->{$varName}))
  1397.         {
  1398.             $this->{$varName}=$value;
  1399.             return True;
  1400.         else {
  1401.             return False;
  1402.         }
  1403.     }
  1404.  
  1405.  
  1406.     /**
  1407.       * @return boolean 
  1408.       * @since pk-07-08-18
  1409.       */
  1410.     function hasObjVals()
  1411.     {
  1412.         return $this->hasObjVals;
  1413.     }
  1414.  
  1415.     /**
  1416.       * returns an object value value
  1417.       *
  1418.       * @param string $name 
  1419.       * @param boolean $autoPopulate 
  1420.       * @param boolean $debug 
  1421.       *
  1422.       * @since pk-05-07-14
  1423.       * @version pk-05-08-26
  1424.       ***/
  1425.     function getObjValValue($name,$autoPopulate=True,$debug=False{
  1426.         if ($this->myObjValsPopulateTS >= time()ini_get('max_execution_time')) {
  1427.             if ($autoPopulate$this->populateObjVals($debug);
  1428.         }
  1429.         if (isset($this->myObjVals[$name]))
  1430.         {
  1431.             switch($this->myObjVals[$name]['OV_TYPE']{
  1432.                 case "array":
  1433.                     return unserialize($this->myObjVals[$name]['OV_VALUE']);
  1434.                 default:
  1435.                     return $this->myObjVals[$name]['OV_VALUE'];
  1436.             }
  1437.         }
  1438.     }
  1439.  
  1440.     /**
  1441.       * sets an object value value
  1442.       *
  1443.       * @param string $key 
  1444.       * @param string $val 
  1445.       * @param boolean $debug 
  1446.       *
  1447.       * @todo type check
  1448.       *
  1449.       * @since pk-05-07-14
  1450.       * @version pk-05-08-26
  1451.       *
  1452.       ***/
  1453.     function setObjValValue($key,$val,$debug=False{
  1454.         if ($debugecho "<p><b>DBMS_TABLEOBJ::setObjValValue($key,...)</b> (".get_class($this).")</p>";
  1455.  
  1456.         $type="string";
  1457.         if (is_array($val)) {
  1458.             $type="array";
  1459.             $val=serialize($val);
  1460.         }
  1461.  
  1462.         $this->myObjVals[$key]=array(
  1463.             'OV_NAME'   => $key,
  1464.             'OV_VALUE'  => $val,
  1465.             'OV_TYPE'   => $type,
  1466.             'OV_CHANGED'=> True
  1467.         );
  1468.     }
  1469.  
  1470.     /**
  1471.       * returns the object value array
  1472.       *
  1473.       * @param boolean $debug 
  1474.       *
  1475.       * @return array 
  1476.       *
  1477.       * @since pk-07-08-13
  1478.       * @version pk-08-06-19
  1479.       */
  1480.     function getObjValArray($debug=False)
  1481.     {
  1482.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::getObjValArray()");
  1483.  
  1484.         if (isset($this->{$this->autoIncFld})) // <pk-08-06-19>
  1485.         {
  1486.             if ($this->hasObjVals(&& intval($this->{$this->autoIncFld}))
  1487.             {
  1488.                 if ($this->myObjValsPopulateTS $this->populateTS)
  1489.                 {
  1490.                     $this->populateObjVals();
  1491.                 }
  1492.                 return $this->myObjVals;
  1493.             }
  1494.         }
  1495.     }
  1496.  
  1497.  
  1498.     /**
  1499.       * sets an array of values as object values
  1500.       *
  1501.       * @param array $valArr 
  1502.       * @param boolean $debug 
  1503.       *
  1504.       * @since pk-05-12-05
  1505.       *
  1506.       ***/
  1507.     function setObjValArray($valArr,$debug=False{
  1508.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setObjValArray()");
  1509.         if (is_array($valArr)) {
  1510.             foreach($valArr as $s_key => $s_val{
  1511.                 $this->setObjValValue($s_key,$s_val,$debug);
  1512.             }
  1513.         }
  1514.     }
  1515.  
  1516.     /**
  1517.       * returns a database form
  1518.       *
  1519.       * @param int $mode        dbms form show mode
  1520.       * @param string $frmName  dbms form name
  1521.       * @param boolean $debug   since pk-05-01-11
  1522.       * @param boolean $autonew generate a default form if no form is found
  1523.       *
  1524.       * @returns DBMS_FORM
  1525.       *
  1526.       * @version pk-05-01-31
  1527.       * @version pk-05-11-22
  1528.       * @version pk-05-11-29 if $frmName like 'ID:000' it is asumed to be the form id
  1529.       *
  1530.       * @requires __OCSP_PHPINCPATH__."db/forms/forms.phpinc";
  1531.       *
  1532.       * @deprecated since pk-07-08-16
  1533.       *
  1534.       ***/
  1535.     function &dbGetForm($mode,$frmName="",$debug=False,$autoNew=False)  {
  1536.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::dbGetForm()","MODE$mode \nNAME$frmName");
  1537.         if ((empty($frmName)) && (empty($this->myTable))) {  // no form ??
  1538.             if ($debugecho "<p style='color=red;'>NO form</p>";
  1539.             return False;
  1540.         }
  1541.  
  1542.         if (empty($frmName)) $frmName=$this->myTable;
  1543.  
  1544.         require_once __OCSP_PHPINCPATH__."db/forms/forms.phpinc"// <pk-07-06-01 />
  1545.         // <pk-05-01-11>
  1546.         // <pk-05-11-29>
  1547.         if (!$frmObj=&DBMS_form_loadName($frmName,$debug)) {
  1548.             if ((substr($frmName,0,3)=="ID:"&& (intval(substr($frmName,3)))) {
  1549.                 $frmObj=&DBMS_form_loadId(intval(substr($frmName,3)),$debug);
  1550.             }
  1551.         }
  1552.  
  1553.         //if (!is_object($frmObj) && ($frmName != $this->myTable)) {
  1554.         //    $frmObj=&DBMS_form_loadName($frmName,$debug);
  1555.         //}
  1556.  
  1557.         if (!is_object($frmObj&& ($autoNew)) {
  1558.             $frmObj=DBMS_form_new($frmName,$this->myTable,False);
  1559.         }
  1560.         // </pk-05-11-29>
  1561.  
  1562.         if (!empty($this->myClassSrcFile)) {    // <pk-05-01-31>
  1563.             if ($debugecho "<p>myClassSrcFile=".$this->myClassSrcFile."</p>";
  1564.             $frmObj->myDBMS_TABLEOBJ_include=$this->myClassSrcFile;
  1565.             $frmObj->myDBMS_TABLEOBJ_class  =get_class($this);
  1566.         // </pk-05-01-31>
  1567.  
  1568.         // <pk-05-11-23>
  1569.         if (is_object($frmObj&& (method_exists($frmObj,"setFrmMode"))) {
  1570.             $frmObj->setFrmMode($mode);
  1571.         }
  1572.         // </pk-05-11-23>
  1573.  
  1574.         return $frmObj;
  1575.         /* <pk-05-01-11> */
  1576.     }
  1577.  
  1578.     /**
  1579.      * returns the required form name
  1580.      * 
  1581.      * normaly this function return Null to let $this->getForm decide
  1582.      * which form ($this->getMyTable()) to use. In some subclasses it can
  1583.      * be useful to overwrite this methode to get a special form
  1584.      * 
  1585.      * This is also a way to tell ajax reloads to change form. in jOCSP/formRPC.php
  1586.      * is checked wether the currently loaded form (from the environment) fits to
  1587.      * the forms tableobject if this function returns a value.
  1588.      *
  1589.      * @return string 
  1590.      * 
  1591.      * @since pk-08-11-01
  1592.      */
  1593.     public function getFormName()
  1594.     {
  1595.         return Null;
  1596.     }
  1597.     
  1598.     /**
  1599.      * returns the form class name to use
  1600.      *
  1601.      * if you overwrite this method make sure the returned form
  1602.      * class source has been included
  1603.      * 
  1604.      * @return string 
  1605.      * 
  1606.      * @since pk-08-11-01
  1607.      */
  1608.     public function getFormClassName()
  1609.     {
  1610.         return 'OCSP_FORM';
  1611.     }
  1612.     
  1613.     /**
  1614.       * replaces dbGetForm and returns a OCSP_FORM
  1615.       *
  1616.       * @param int $mode 
  1617.       * @param mixed $form (string) form name (int) form id
  1618.       * @param boolean $debug 
  1619.       *
  1620.       * @return OCSP_FORM 
  1621.       *
  1622.       *  __OCSP_PHPINCPATH__
  1623.       * @requires db/forms/OCSP_FORM.phpclass
  1624.       *
  1625.       * @since pk-07-08-16
  1626.       * @version pk-08-06-26
  1627.       * @version pk-08-11-01 getFormName() & getFormClassName added
  1628.       */
  1629.     function &getForm($mode=FRM_MODE_READONLY,$form='',$frmClass='OCSP_FORM',$debug=False)
  1630.     {
  1631.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::getForm($mode,$form,$frmClass)");
  1632.  
  1633.         pcf_require_class('OCSP_FORM',"db/forms/");
  1634.         
  1635.         if (empty($form))         $form=($this->getFormName($this->getFormName($this->getMyTable());                
  1636.         if (empty($frmClass))     $frmClass=$this->getFormClassName();
  1637.  
  1638.         if (intval($form))
  1639.         {
  1640.             $obj_form=OCSP_FORM::factory_from_id(intval($form),$frmClass,$debug);
  1641.             $frmName="";
  1642.         else {
  1643.             $obj_form=OCSP_FORM::factory_from_Name($form,$frmClass,$debug);
  1644.             $frmName=$form;
  1645.         }
  1646.  
  1647.         if (pcf_is_instance_of($obj_form,'OCSP_FORM'))
  1648.         {
  1649.             $obj_form->setMyTblObj($this);
  1650.             $str_classSrc $this->get_mySourceFile();
  1651.             if (!empty($str_classSrc&& strstr($str_classSrc,get_class($this)))
  1652.             {
  1653.                 $obj_form->setTblObjInc($str_classSrc);
  1654.                 $obj_form->setTblObjClass(get_class($this));                
  1655.             else if (!empty($this->myClassSrcFile)) {
  1656.                 $obj_form->setTblObjInc($this->myClassSrcFile);
  1657.                 $obj_form->setTblObjClass(get_class($this));
  1658.             else {
  1659.                 ocsp_logError(__FILE__,__LINE__,"no source file for " get_class($this" (" $str_classSrc ");",E_WARNING);
  1660.             }
  1661.             $obj_form->setFrmMode($mode);
  1662.             if ($debugechoDebugLine(__FILE__,__LINE__,"form loaded Mode$mode/".$obj_form->getFrmMode());
  1663.             return $obj_form;
  1664.         else {
  1665.             $obj_form Null;
  1666.             return $obj_form;
  1667.             //ocsp_logError(__FILE__,__LINE__,"Class: ".get_class($this)." Table: ".$this->myTable.":<br />could not get OCSP_FORM fallback to old method",E_NOTICE);          
  1668.             //return $this->dbGetForm($mode,$frmName,$debug,False);
  1669.         }
  1670.     }
  1671.  
  1672.  
  1673.     /**
  1674.       * returns the db default value for aField
  1675.       *
  1676.       * @param string $aField 
  1677.       * @returns mixed
  1678.       *
  1679.       * @since pk-03-12-19
  1680.       *
  1681.       ***/
  1682.     function getFieldDBDefault($aField{
  1683.         if (isset($this->myFields[$aField]['DEFAULT'])) {
  1684.             return $this->myFields[$aField]['DEFAULT'];
  1685.         else {
  1686.             return NULL;
  1687.         }
  1688.     }
  1689.  
  1690.     /**
  1691.       *    returns an array of db default values
  1692.       *
  1693.       * @param boolean     $debug 
  1694.       *
  1695.       * @return array 
  1696.       *
  1697.       */
  1698.     public function getDefaults($debug=False)
  1699.     {
  1700.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::getDefaults()");
  1701.         if (!$this->initTS$this->init();
  1702.         $ret=array();
  1703.         if (is_array($this->myFields)) // <pk-07-12-17>
  1704.         {
  1705.             foreach($this->myFields as $key => $val{
  1706.                 if (isset($val['DEFAULT'])) {
  1707.                     $ret[$key]=$val['DEFAULT'];
  1708.                 }
  1709.             }
  1710.         }
  1711.         return $ret;
  1712.     }
  1713.  
  1714.     /**
  1715.       * sets the database default values to the fields
  1716.       *
  1717.       * COUTION overrides populated values
  1718.       *
  1719.       * @param boolean $debug show debug info
  1720.       *
  1721.       ***/
  1722.     function setDefaults($debug=False{
  1723.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setDefaults()");
  1724.         if (!$this->initTS$this->init();
  1725.         $ret=array();
  1726.         if (is_array($this->myFields)) {
  1727.             foreach($this->myFields as $key => $val{
  1728.                 if (isset($val['DEFAULT'])) {
  1729.                     $this->$key=$val['DEFAULT'];
  1730.                 }
  1731.             }
  1732.         }
  1733.         $this->valChangeTS=time()/* <pk-03-10-25 /> */
  1734.     }
  1735.     
  1736.     /**
  1737.       * returns a field => value array for dbms
  1738.       *
  1739.       * use this in cms and dbms elements to get
  1740.       * $DBVAL array
  1741.       *
  1742.       * overwrite this and add some special values
  1743.       * for objects if needed
  1744.       *
  1745.       * @see dbms
  1746.       *
  1747.       * @param boolean $setFIELDS    if True $ret['_DBMS_FIELDS'] is filled
  1748.       * @param boolean $debug        show debug info?
  1749.       * @param boolean $withObjVars  add object var values to the returned array
  1750.       *
  1751.       * @returns array
  1752.       *
  1753.       * @version pk-04-08-10 debug info changed
  1754.       * @version pk-05-07-14
  1755.       * @version pk-06-05-21 debugging
  1756.       * @version pk-07-06-19
  1757.       *
  1758.       ***/
  1759.     function getDBVal($setFIELDS=False,$debug=False,$withObjVars=True{
  1760.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TBLOBJ::getDBVal","Table: ".$this->myTable,0);
  1761.         
  1762.         if (!$this->initTS)        $this->init($debug);
  1763.         if (!$this->populateTS$this->dbPopulate($debug);
  1764.  
  1765.         if ($debug{echo "<pre>myFields\n";foreach($this->myFields as $key => $valArr){echo "$key\n";};echo "</pre>";}
  1766.         $ret=array();
  1767.         $sep="";
  1768.  
  1769.         // <pk-05-07-14>
  1770.         if ($withObjVars{
  1771.             if (($this->myObjValsPopulateTS $this->getPopulateTs())) // <pk-07-06-19 /> || (!is_array($this->myObjVals))) // <pk-05-08-26>
  1772.             {
  1773.                 $this->populateObjVals($debug);
  1774.             // </pk-05-08-26>
  1775.             if (is_array($this->myObjVals)) {
  1776.                 foreach($this->myObjVals as $s_Name => $a_Row{
  1777.                     $ret[$s_Name]=$a_Row['OV_VALUE'];
  1778.                     if ($setFIELDS{
  1779.                         $ret['_DBMS_FIELDS'].=$sep.$s_Name;
  1780.                         $sep=",";
  1781.                     }
  1782.                 }
  1783.             }
  1784.         }
  1785.         // </pk-05-07-14>
  1786.         if (!is_array($this->myFields))
  1787.         {
  1788.             
  1789.             $debug=TrueechoDebugLine(__FILE__,__LINE__,"\$this->myFields NOT SET");
  1790.             $this->init($debug);
  1791.         }
  1792.         foreach($this->myFields as $key => $val{
  1793.             if (isset($this->{$key})) {
  1794.                 $ret[$key]=$this->{$key};
  1795.                 if ($setFIELDS{
  1796.                     $ret['_DBMS_FIELDS'.= $sep.$key;
  1797.                     $sep=",";
  1798.                 }
  1799.             else {
  1800.                 if ($debugecho "$key not set <br />";
  1801.             }
  1802.         }
  1803.         if ($debugecho "</blockquote>";
  1804.         return $ret;
  1805.     }
  1806.     
  1807.  
  1808.     /**
  1809.       * returns a field => value array
  1810.       *
  1811.       * used also in insert and update statements
  1812.       *
  1813.       * make sure to not include some special values
  1814.       * and object columns are serialised
  1815.       *
  1816.       * @param boolean $withoutNull if True null values are not added to the array
  1817.       * @param boolean $debug 
  1818.       * @param boolean $withoutOV if False and $this->hasObjVals() the object value array is added with index __OCSP_OBJ_VALS__
  1819.       * @param boolean $fldAutoPopulate 
  1820.       * 
  1821.       * @returns array
  1822.       *
  1823.       *  done empty is not equal null !! pk-03-10-22
  1824.       *
  1825.       * @version pk-03-10-22
  1826.       * @version pk-06-07-31 check if $this->myFields is an array
  1827.       * @version pk-07-08-13
  1828.       * @version pk-08-06-06
  1829.       */
  1830.     function getDBRow($withoutNull=True,$debug=False,$withoutOV=False,$fldAutoPopulate=True
  1831.     {
  1832.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::getDBRow()");
  1833.         $arr_ret=array();
  1834.  
  1835.         if (!$this->initTS$this->init($debug);
  1836.         
  1837.         if (is_array($this->myFields)) // <pk-06-07-31 />
  1838.             foreach($this->myFields as $str_key => $arr_dbDesc{
  1839.                 if ($debugechoDebugLine(__FILE__,__LINE__,"Field$str_key");
  1840.                 if (!$withoutNull{
  1841.                     $arr_ret[$str_key]=$this->getDBField($str_key);
  1842.                 else {
  1843.                     $m_retVal=$this->getDBField($str_key,$debug,$fldAutoPopulate);
  1844.                     if (!empty($m_retVal))
  1845.                     {
  1846.                         $arr_ret[$str_key]=$m_retVal;
  1847.                     else if(strlen(strval($m_retVal)) 0{
  1848.                         $arr_ret[$str_key]=$m_retVal;
  1849.                     }
  1850.                 }
  1851.             }
  1852.         else {
  1853.             ocsp_logError(__FILE__,__LINE__,"TableObj ".get_class($this)." has no fields");
  1854.         }
  1855.         if (!$withoutOV && $this->hasObjVals())
  1856.         {
  1857.             $arr_ret['__OCSP_OBJ_VALS__']=$this->getObjValArray($debug);
  1858.         }
  1859.         return $arr_ret;;
  1860.     }
  1861.  
  1862.     
  1863.     /**
  1864.       * returns the the data array of a joins to the current row
  1865.       * requirements:
  1866.       * - $this->myTable must have an autoIncFld
  1867.       * - the foreign table must have a column called like $this->autoIncFld
  1868.       * - getDBField($this->autoIncFld) must return a value
  1869.       *
  1870.       * NOTE treats the join like 1:1 key means only the first matching row is returned
  1871.       *
  1872.       * @param array $tables 
  1873.       * @param array $filter (array(COLUMN => VALUE))
  1874.       * @param boolean $withObjVars 
  1875.       * @param boolean $debug 
  1876.       *
  1877.       * @returns array
  1878.       *
  1879.       * @since pk-07-08-27
  1880.       *
  1881.       * @todo DBMS_TABLEOBJ::dbGetDataArray() check the filter if the columns exists in foreign table
  1882.       ***/
  1883.     function dbGetDataArray($tables,$filter=NULL,$withObjVars=True,$debug=False)
  1884.     {
  1885.         if ($debugechoDebugMethod(__FILE__,__LINE__,"DBMS_TABLEOBJ::dbGetDataArray()","Tables: <pre>".print_r($tables,True)."</pre>Filter:<pre>".print_r($filter,True)."</pre>");
  1886.  
  1887.         $arr_ret=$this->getDBVal(False,$debug,$withObjVars);
  1888.         if (!empty($this->autoIncFld&& $this->getDBField($this->autoIncFld))
  1889.         {
  1890.             if (!is_array($filter))
  1891.             {
  1892.                 $filter=array($this->autoIncFld => $this->getDBField($this->autoIncFld));
  1893.             else {
  1894.                 $filter[$this->autoIncFld]=$this->getDBField($this->autoIncFld);
  1895.             }
  1896.             if (is_array($tables))
  1897.             {
  1898.                 foreach($tables as $str_tbl)
  1899.                 {
  1900.                     if ($str_tbl != $this->getMyTable())
  1901.                     {
  1902.                         if ($arr_tmp=$this->getDBObj('r')->getArray($str_tbl,$filter,0,1,$debug))
  1903.                         {
  1904.                             $arr_ret=array_merge($arr_tmp,$arr_ret);
  1905.                         }
  1906.                     }
  1907.                 }
  1908.             }
  1909.         }
  1910.         return $arr_ret;
  1911.     }
  1912.  
  1913.     /**
  1914.       * sets all fields of an array to the objcet
  1915.       *
  1916.       * @param array $valArr 
  1917.       * @param boolean $debug 
  1918.       *
  1919.       * @rerturn boolean
  1920.       *
  1921.       * @since pk-05-08-30
  1922.       * @version pk-05-10-04
  1923.       ***/
  1924.     function setDBVal($valArr,$debug=False{
  1925.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setDBVal(...)");
  1926.  
  1927.         if (!is_array($valArr)) {
  1928.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$valArr is not an array");
  1929.             return False;
  1930.         }
  1931.        
  1932.         foreach($valArr as $s_key => $s_val{
  1933.             $this->setDBField($s_key,$s_val,$debug);
  1934.         }
  1935.         if ($debug
  1936.         {
  1937.             $str_debug ="<p>setDBVAL():</p>";
  1938.             $str_debug ="<table><tr><th>\$valArr</th><th>DBVAL</th></tr><tr>";
  1939.             $str_debug.="<td><pre>".print_r($valArr,True)."</pre></td>";
  1940.             $str_debug.="<td><pre>".print_r($this->getDBVal(),True)."</pre></td>";
  1941.             $str_debug.="</tr></table>";
  1942.             echoDebugLine(__FILE__,__LINE__,$str_debug);    
  1943.         }
  1944.         return True// <pk-05-10-04 />
  1945.     }
  1946.  
  1947.     /**
  1948.       * sets a database row to the object fields
  1949.       *
  1950.       * sets each key (=columname) value
  1951.       *
  1952.       * if $row['__OCSP_OBJ_VALS__'] isset and an array this values are set as object values
  1953.       * else if $asPopulated object values are loaded
  1954.       *
  1955.       * @param  array $row            the row form a select * from DBMS_TABLEOBJ::myTable
  1956.       * @param  boolean $asPopulated    set populateTS as if the object has been populated
  1957.       * @param  boolean $debug 
  1958.       *
  1959.       * @return boolean 
  1960.       * 
  1961.       * @since pk-03-12-13  more debug infos
  1962.       * @version pk-07-08-10
  1963.       *
  1964.       */
  1965.     function setDBRow($row,$asPopulated=True,$debug=False
  1966.     {
  1967.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::setDBRow()",($asPopulated "\n<b>asPopulated</b>\n" "" ).$this->getMyTable(),0);
  1968.         if (is_array($row)) {
  1969.             $str_debugOut="";
  1970.             foreach($row as $key => $val{
  1971.                 if ($debug$str_debugOut.="$key=&gt;".htmlspecialchars($val."")."&lt;\n";
  1972.                 $this->{$key}=$val;
  1973.             }
  1974.             if ($debugechoDebugLine(__FILE__,__LINE__,"<pre style=\"font-size: 80%;padding-left:30px\">$str_debugOut</pre>");
  1975.             if ($asPopulated{
  1976.                 $this->populateTS=time();
  1977.             }
  1978.  
  1979.         else {
  1980.             ocsp_logError(__FILE__,__LINE__,"no row passed to set DBROW",E_WARNING);
  1981.             return False;
  1982.         }
  1983.  
  1984.         // <pk-07-08-10>
  1985.         if ($this->hasObjVals()) // <pk-07-08-18 />
  1986.         {
  1987.             if (isset($row['__OCSP_OBJ_VALS__']))
  1988.             {
  1989.                 if (is_array($row['__OCSP_OBJ_VALS__']))
  1990.                 {
  1991.                     $this->setObjValArray($row['__OCSP_OBJ_VALS__']);
  1992.                     $this->myObjValsPopulateTS=time();
  1993.                 }
  1994.             else if ($asPopulated{
  1995.                 $this->myObjVals=array()// clear object vals
  1996.                 $this->myObjValsPopulateTS 0;
  1997.                 if ($this->isConnected())
  1998.                 {
  1999.                     $this->populateObjVals($debug);
  2000.                 else {
  2001.                     if ($debugocsp_logError(__FILE__,__LINE__,"Object Values not loaded",E_NOTICE);
  2002.                 }
  2003.             }
  2004.         }
  2005.         // </pk-07-08-10>
  2006.  
  2007.         $this->setChanged()// <pk-06-07-28 />
  2008.         $bol_ret True;        
  2009.         if ($debugechoDebugLine(__FILE__,__LINE__,"setDBRow Returns: " ($bol_ret 'True' 'False'));
  2010.         return $bol_ret;
  2011.     }
  2012.  
  2013.  
  2014.     // #------------------------------------------------------------------#
  2015.     // #        ERROR HANDLING                                            #
  2016.     // #------------------------------------------------------------------#
  2017.  
  2018.     /**
  2019.       * echos the object
  2020.       *
  2021.       * @param boolean $fullMode 
  2022.       *
  2023.       * @since pk-04-07-30
  2024.       *
  2025.       */
  2026.     function writeDebugInfo($fullMode=False{
  2027.         echo "<h2 align=\"center\">DEBUGGING ".get_class($this)." </h2>";
  2028.         echo "<pre>";
  2029.         if ($fullMode{
  2030.             echo pcf_object_info($this);
  2031.         else {
  2032.             echo "properties: \n";
  2033.             foreach (get_object_vars($thisas $var=>$val{
  2034.                 if (is_array($val)) {
  2035.                     echo "array property: \t$var (".sizeof($this->{$var}).")\n";
  2036.                 else if (is_object($val)) {
  2037.                     echo "object property:\t$var (Class".get_class($this->{$var}).")\n";
  2038.                 else {
  2039.                     echo "value property: \t$var = ".htmlspecialchars($val)."\n";
  2040.                 }
  2041.             }
  2042.         }
  2043.  
  2044.         echo "</pre>";
  2045.  
  2046.     }
  2047.     
  2048.     /**
  2049.       * clears all errors
  2050.       */
  2051.     function clearErrors({
  2052.         $this->objError   False;
  2053.         $this->objErrorMsg"";
  2054.     }
  2055.  
  2056.     /**
  2057.       * @return boolean 
  2058.       *
  2059.       * @since pk-05-07-29
  2060.       *
  2061.       */
  2062.     function hasErrors({
  2063.         return $this->objError;
  2064.     }
  2065.  
  2066.     /**
  2067.       * @returns string
  2068.       *
  2069.       * @since pk-05-07-29
  2070.       *
  2071.       ***/
  2072.     function getErrorMsg({
  2073.         return $this->objErrorMsg;
  2074.     }
  2075.  
  2076.     /**
  2077.       * sets an error cmd
  2078.       *
  2079.       * @param string $errMsg 
  2080.       *
  2081.       * @since pk-05-07-29
  2082.       *
  2083.       ***/
  2084.     function setError($errMsg{
  2085.         $this->objError=True;
  2086.         if (!empty($this->objErrorMsg)) $this->objErrorMsg.="\n";
  2087.         $this->objErrorMsg.=$errMsg;
  2088.     }
  2089.  
  2090.  
  2091.  
  2092.     // #------------------------------------------------------------------#
  2093.     // #        CLASS AND CACHE METHODS PRIVATE USE ONLY                  #
  2094.     // #------------------------------------------------------------------#
  2095.  
  2096.     /**
  2097.       * overwrite in class implementation
  2098.       **/
  2099.  
  2100.     function userIsAllowed($mode{
  2101.         return True;
  2102.     }
  2103.  
  2104.     /**
  2105.       * class method sets $this->myFields
  2106.       *
  2107.       * @param boolean     $debug 
  2108.       * @access protected
  2109.       *
  2110.       * @return boolean 
  2111.       *
  2112.       * @version pk-04-12-21
  2113.       * @version pk-05-07-13
  2114.       * @version pk-07-04-14
  2115.       * @version pk-07-06-15
  2116.       * @version pk-08-03-11
  2117.       ***/
  2118.     protected function _getDBFields($debug=False{
  2119.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::_getDBFields()");
  2120.  
  2121.         if (isset(DBMS_TABLEOBJ::$dbTableDefinitions[$this->myTable]))
  2122.         {
  2123.             $fields DBMS_TABLEOBJ::$dbTableDefinitions[$this->myTable]['fields'];
  2124.         else {        
  2125.             if (!$this->isConnected(True,$debug))
  2126.             {
  2127.                 throw new Exception(_OCSP_EXCEP_NODBCONN_);
  2128.                 return False;
  2129.             }
  2130.             if ($fields=$this->getDBObj('r')->getDBTblDesc($this->myTable,False))
  2131.             {
  2132.                 DBMS_TABLEOBJ::$dbTableDefinitions[$this->myTable]['fields']     $fields;
  2133.                 DBMS_TABLEOBJ::$dbTableDefinitions[$this->myTable]['hasOVtbl']  $this->getDBObj('r')->tblExists($this->myTable."_OV",False);
  2134.             }           
  2135.         }
  2136.         
  2137.         if (is_array($fields)) {
  2138.             foreach($fields as $key => $fld{
  2139.                 if ($debugechoDebugLine(__FILE__,__LINE__,"\$fld: <pre>" print_r($fld,True"</pre>");
  2140.                 $this->myFields[$key]=$fld;
  2141.                 if ($fld['PRIMARY_KEY']{
  2142.                     if ($debugechoDebugLine(__FILE__,__LINE__,"PRIMARY_KEY: " print_r($fld,True)."</pre>");
  2143.                     $this->myKeys[$key]['NAME']=$key;
  2144.                     $this->myKeys[$key]['TYPE']=$fld['TYPE'];
  2145.                     $this->myKeys[$key]['AUTO_INCREMENT']=$fld['AUTO_INCREMENT'];
  2146.                     if ($fld['AUTO_INCREMENT'])
  2147.                         $this->autoIncFld=$key;
  2148.                 }
  2149.             }
  2150.             
  2151.         else {
  2152.             throw new Exception(_OCSP_EXCEP_TABLENOTFOUND_);
  2153.             return False;
  2154.         }
  2155.  
  2156.         if ((!empty($this->autoIncFld)) && (DBMS_TABLEOBJ::$dbTableDefinitions[$this->myTable]['hasOVtbl']))
  2157.         {
  2158.             $this->hasObjVals=True;
  2159.         else {
  2160.             $this->hasObjVals=False;
  2161.         }
  2162.         return True;
  2163.     }
  2164.  
  2165.  
  2166.     /**
  2167.       * PROTECTED check if cache is expired
  2168.       *
  2169.       *   returns if chache has reached
  2170.       *   OCSP_OBJ::getConf('OBJCACHEPATH')
  2171.       *
  2172.       * @param boolean     $debug 
  2173.       *
  2174.       * @returns bool
  2175.       * @access protected
  2176.       *
  2177.       * @version pk-04-01-02
  2178.       *
  2179.       ***/
  2180.     protected function p_cacheIsExpired($debug=False{
  2181.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::p_cacheIsExpired()");
  2182.         if (sizeof($this->myFields2/*<pk-04-01-02 /> bugfix $sizeof($this->fields) */
  2183.             if ($debugecho "<p>RETURN False (sizieof(\$this->myFields))</p>";
  2184.             return False;
  2185.         }
  2186.         if ($debugechoDebugLine(__FILE__,__LINE__,"
  2187.             Returns (myCacheTS: ".$this->myCacheTS." &gt ".(time(OCSP_OBJ::getConf('OBJCACHEPATH'))."
  2188.              ".($this->myCacheTS (time(OCSP_OBJ::getConf('OBJCACHEPATH')) "True" "False"));
  2189.         return ($this->myCacheTS (time(OCSP_OBJ::getConf('OBJCACHEPATH')) True False );
  2190.     }
  2191.  
  2192.  
  2193.     /**
  2194.       * PROTECTED get the name of the cache file
  2195.       *
  2196.       * returns the full path to the cache file name
  2197.       * or False if cacheing is disabled by
  2198.       * not setting $GLOBALS['PROJECT']['OBJCACHEPATH']
  2199.       *
  2200.       * @returns string
  2201.       *
  2202.       * @version pk-06-05-27 mytable added to filename
  2203.       * @version pk-08-06-15
  2204.       * 
  2205.       */
  2206.     protected function _getCacheFileName({
  2207.         $str_cacheDir OCSP_OBJ::getConf('OBJCACHEPATH');
  2208.         if (!empty($str_cacheDir)) {
  2209.             if (intval(OCSP_OBJ::getConf('OBJCACHELIFETIME')) 30{
  2210.                 // does not make sense to chache for such a shorte periode
  2211.                 return $str_cacheDir.get_class($this)."_".$this->myTable."_class.cache";
  2212.             }
  2213.         }
  2214.         return Null;
  2215.     }
  2216.  
  2217.     /**
  2218.       * PROTECTED cache object to filesystem
  2219.       *
  2220.       * writes CLASS Variables to class Cache-File
  2221.       *
  2222.       * @param boolean $debug 
  2223.       *
  2224.       * @returns bool False if an error occured or cacheing is disabled
  2225.       *
  2226.       * @version pk-05-07-13
  2227.       *
  2228.       ***/
  2229.     function cacheWriteTo($debug=False{
  2230.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TBLOBJ::cacheWriteTo()","File: ".$this->_getCacheFileName(),0);
  2231.  
  2232.         require_once __OCSP_PHPINCPATH__."common/pcf_directory.phpinc";
  2233.  
  2234.         if (!$this->initTS{
  2235.             if ($debugecho "<blockquote><p>OBJECT NOT INITIALIZED</p></blockquote>";
  2236.             return False;
  2237.             // only initialized objects can be cached
  2238.         }
  2239.         if (!$cacheFile=$this->_getCacheFileName()) {
  2240.             if ($debugecho "<blockquote><p>CACHE DISABLED</p></blockquote>";
  2241.             return False;
  2242.         }
  2243.  
  2244.         if (!pcf_checkDir(dirname($cacheFile),True,0700)) {
  2245.             if ($debugecho "<blockquote><p>Unable to create cache dir: ".dirname($cacheFile)."</p></blockquote>";
  2246.             return False;
  2247.         }
  2248.  
  2249.         if (!sizeof($this->myFields)) $this->_getDBFields()}
  2250.         
  2251.         if ($fp=fopen($cacheFile,"w")) {
  2252.             fwrite($fp,"<?php \n");
  2253.             fwrite($fp,"    \$className=\"".get_class($this)."\";\n");
  2254.             fwrite($fp,"    \$this->myCacheTS=".time().";\n");
  2255.             fwrite($fp,"    \$this->myTable=\"".$this->myTable."\";\n");
  2256.             fwrite($fp,"    \$this->autoIncFld=\"".$this->autoIncFld."\";\n");
  2257.             //if (!sizeof($this->myKeys)) { $this->c_GetKeys(); }
  2258.             fwrite($fp,"    \$keys=\"".str_replace('"','\"',serialize($this->myKeys))."\";\n");    
  2259.             //fwrite($fp,"    \$fields=\"".str_replace('"','\"',serialize($this->myFields))."\";\n");
  2260.             fwrite($fp,"    \$fields=\"".(base64_encode(serialize($this->myFields)))."\";\n");
  2261.             fwrite($fp,"    \$this->hasObjVals=".($this->hasObjVals("True" "False").";\n")// <pk-05-07-13 /> // <pk-07-08-18 />
  2262.             fwrite($fp,"?>");
  2263.             fclose($fp);
  2264.             return True;
  2265.         }
  2266.         return False;   // file could not be opened
  2267.     }
  2268.  
  2269.  
  2270.     /**
  2271.       *  PROTECTED cacheRestore
  2272.       *
  2273.       *   looks for a class cache an laods it if possible
  2274.       *
  2275.       * @param boolean $debug 
  2276.       *
  2277.       * @global array $OCSP_VAL 
  2278.       *
  2279.       * @version pk-04-12-21
  2280.       * @version pk-07-10-06
  2281.       *
  2282.       */
  2283.     protected function cacheRestore($debug=False{
  2284.         global $OCSP_VAL;
  2285.  
  2286.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::cacheRestore()");
  2287.         $this->objError   False;
  2288.         $this->objErrorMsg"";
  2289.  
  2290.         if (file_exists($this->_getCacheFileName())) {
  2291.             if ($debugecho "<blockquote><p>including file</p></blockquote>";
  2292.             @include $this->_getCacheFileName();
  2293.             $this->myKeys   =unserialize($keys);
  2294.             // $GLOBALS['OCSP_DBMS'][$this->get_gDBIDX()][$this->myTable]=unserialize($fields);
  2295.             // $this->myFields =&$GLOBALS['OCSP_DBMS'][$this->get_gDBIDX()][$this->myTable]; /* <pk-04-12-21 /> */
  2296.             $this->myFields=unserialize(base64_decode($fields));
  2297.             
  2298.             return $this->p_cacheIsExpired($debug);
  2299.         else {
  2300.             if ($debugecho "<blockquote><p>no file</p></blockquote>";
  2301.             return False;
  2302.         }
  2303.     }
  2304.  
  2305.     // #------------------------------------------------------------------#
  2306.     // #        export methods                                            #
  2307.     // #------------------------------------------------------------------#    
  2308.     
  2309.     
  2310.     /**
  2311.       * xmlExport of a Table Object
  2312.       *
  2313.       * @param string $xmlfile 
  2314.       * @param boolean $base64 
  2315.       * @param boolean $debug 
  2316.       *
  2317.       * @returns bool
  2318.       * @since sw-05-03-08
  2319.       *
  2320.       *  NEED TO BE OVERWRITTEN!!!
  2321.       *
  2322.       ***/
  2323.     function xmlExport($xmlfile="",$base64=True,$debug=False{
  2324.         if ($debugecho "<p><b>DBMS_TABLEOBJ::xmlExport($xmlfile,$base64,$debug)</b> (".get_class($this).")</p>";
  2325.         if (empty($xmlfile)) return False;
  2326.         if (intval(str_replace(".","",phpversion())) 499{
  2327.             $xmlfile=$GLOBALS['PROJECT']['DBEXPORT'].$this->getName().".xml";
  2328.             $domObj new domDocument();
  2329.             $domRoot $domObj->createElement($this->myTable."_LIST");
  2330.             $domObj->appendChild($domRoot);
  2331.             $this->xmladdDOMElement($domObj,$domRoot,$base64,$debug);
  2332.  
  2333.             $domObj->save($xmlfile);
  2334.         }
  2335.     }
  2336.  
  2337.     /**
  2338.       * adds TableObject Contents to domRoot
  2339.       *
  2340.       * @param mixed &$domObj           //reference to Parent DomObject
  2341.       * @param string $domRoot      //reference to Parent DomRoot
  2342.       * @param boolean $base64 
  2343.       * @param boolean $debug 
  2344.       *
  2345.       * @returns bool
  2346.       * @since sw-05-03-09
  2347.       *
  2348.       ***/
  2349.     function &xmladdDOMElement(&$domObj,&$domRoot,$base64=True,$debug=False{
  2350.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::xmladdDOMElement()");
  2351.  
  2352.  
  2353.         $valRoot $domObj->createElement($this->myTable);
  2354.         $domRoot->appendChild($valRoot);
  2355.  
  2356.         $TblFld=array();
  2357.         $FldVal=array();
  2358.         $TblContents array();
  2359.         $TblContents $this->getDBRow(False,$debug);
  2360.  
  2361.         foreach ($TblContents as $TblFld => $FldVal
  2362.         {
  2363.             if ($base64{
  2364.                 $str_xmlVal base64_encode($FldVal);
  2365.             else {
  2366.                 switch(True)
  2367.                 {
  2368.                     case (empty($FldVal)):
  2369.                         $str_xmlVal "";
  2370.                         break;
  2371.                     case (is_string($FldVal)):
  2372.                         $str_xmlVal htmlspecialchars($FldVal);
  2373.                         break;
  2374.                     case (is_array($FldVal)):
  2375.                         if ($debug)
  2376.                         {
  2377.                             echoDebugLine(__FILE__,__LINE__,"Value: " $FldVal);
  2378.                         }
  2379.                         $str_xmlVal htmlspecialchars(implode(";",$FldVal));
  2380.                         break;
  2381.                     case (is_numeric($FldVal)):
  2382.                         $str_xmlVal $FldVal;
  2383.                         break;
  2384.                     case (is_bool($FldVal)):
  2385.                         $str_xmlVal ($FldVal 0);
  2386.                         break;
  2387.                     default:
  2388.                         $str_xmlVal $FldVal;
  2389.                         break;        
  2390.                 }
  2391.                 
  2392.             }
  2393.  
  2394.             $domElem $domObj->createElement($TblFld,utf8_encode($str_xmlVal));
  2395.             $valRoot->appendChild($domElem);
  2396.         }
  2397.  
  2398.         return $valRoot;
  2399.     }
  2400.     
  2401.     /*** JSON ---------------------------------------- */
  2402.     
  2403.     /**
  2404.      * returns a json string for the object data
  2405.      * 
  2406.      * @param boolean $debug 
  2407.      * 
  2408.      * @return string (JSON)
  2409.      * 
  2410.      * @since pk-07-12-12
  2411.      */
  2412.     function getJSON($debug=False)
  2413.     {
  2414.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_TABLEOBJ::getJSON()");
  2415.         
  2416.         pcf_require_class('Services_JSON','common/');
  2417.         
  2418.         return Services_JSON::getInstance()->encode($this->getDBVal());
  2419.         
  2420.     }
  2421.  
  2422. }
  2423. ?>

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