Source for file OCSP_FORM.phpclass

Documentation is available at OCSP_FORM.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_FORM.phpclass
  4.   *
  5.   *
  6.   * @project    Open CSP-Management
  7.   * @package    forms
  8.   * @category   dbms_form
  9.   *
  10.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @since  pk-07-06-28
  14.   * 
  15.   * @version $Id: OCSP_FORM.phpclass,v 1.66 2008/12/18 22:05:55 pitlinz Exp $
  16.   *
  17.   */
  18.  
  19. /**
  20.   * language file
  21.   * @includes ./languages/de.phpinc
  22.   * @todo include the proper languange file
  23.   *
  24.   */
  25. include_once dirname(__FILE__)._OCSP_DIRSEP_."languages"._OCSP_DIRSEP_."de.phpinc";
  26.  
  27.  
  28. /**
  29.   * @requires OCSP_FORM_BLOCK.phpclass
  30.   * @requires INFA_OCSP_FORM.phpclass
  31.   */
  32. pcf_require_interface('INFA_OCSP_FORM',dirname(__FILE___OCSP_DIRSEP_ "INFA_OCSP_FORM.phpclass");
  33. pcf_require_class('OCSP_OBJ',__OCSP_PHPINCPATH__ "common" _OCSP_DIRSEP_ "OCSP_OBJ.phpclass");
  34. pcf_require_class('OCSP_FORM_BLOCK',dirname(__FILE___OCSP_DIRSEP_ "OCSP_FORM_BLOCK.phpclass");
  35.  
  36.     
  37. /**
  38.   * Database Formular Basic Elements
  39.   * this class is without any layout elements to extend to what
  40.   * ever is needed
  41.   *
  42.   * @project    Open CSP-Management
  43.   * @package    forms
  44.   * @category   dbms_form
  45.   *
  46.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  47.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  48.   *
  49.   * @verions $Id: OCSP_FORM.phpclass,v 1.66 2008/12/18 22:05:55 pitlinz Exp $
  50.   */
  51. class OCSP_FORM 
  52.     extends OCSP_OBJ
  53.     implements INFA_OCSP_FORM 
  54. {
  55.  
  56.  
  57.     /*** class constants  --------------------------------------------- */
  58.  
  59.     /**
  60.       * @constant string CLASS_SRC_FILE
  61.       */
  62.     const CLASS_SRC_FILE = __FILE__;
  63.  
  64.     /**
  65.       * @constant string FORM_CACHE_DIR
  66.       */
  67.     const FORM_CACHE_DIR = "form_cache";
  68.  
  69.     /**
  70.       * @constant string FORM_CACHE_FILEEXT
  71.       */
  72.     const FORM_CACHE_FILEEXT = ".frm.cache";
  73.  
  74.  
  75.     
  76.     /*** class variables  --------------------------------------------- */
  77.  
  78.     /**
  79.       * @staticvar array $form_instances 
  80.       *  index starts at 1
  81.       * @access protected
  82.       */
  83.     static public $form_instances=array();
  84.  
  85.     /**
  86.       * @staticvar array $staticClassVars vars which must not be copied
  87.       */
  88.     protected static $staticClassVars=array('form_instances');
  89.  
  90.     /**
  91.      * @staticvar array $dbmsFieldClassDesc 
  92.      */
  93.     protected static $dbmsFieldClassDesc array();
  94.     
  95.     /**
  96.      * @staticvar array $dbmsFieldTypeClasses 
  97.      */
  98.     protected static $dbmsFieldTypeClasses array();
  99.     
  100.     /**
  101.      * returns the field class description for a field
  102.      *
  103.      * @param array $aClass 
  104.      * @param boolean $debug 
  105.      */
  106.     public static function getFieldClassDesc($aClassName='DBMS_FIELD',$debug=False)
  107.     {
  108. //$debug=True;        
  109.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::getFieldClassDesc(" $aClassName ")");
  110.         if (sizeof(self::$dbmsFieldClassDesc1)
  111.         {
  112.             self::loadFieldClassDesc($debug);
  113.         }
  114.         if (isset(self::$dbmsFieldClassDesc[$aClassName]))
  115.         {
  116.             return self::$dbmsFieldClassDesc[$aClassName];
  117.         }
  118.         if ($debugechoDebugLine(__FILE__,__LINE__,"returnung Null");
  119.         return Null;
  120.     }
  121.     
  122.     /**
  123.      * returns all field class descriptions
  124.      * 
  125.      * @return array 
  126.      */
  127.     public static function getFieldClassDescArr()
  128.     {
  129.         return self::$dbmsFieldClassDesc;
  130.     }
  131.     
  132.     /**
  133.      * requires the a field class src file
  134.      *
  135.      * @param string $aClassName 
  136.      * @param boolean $debug 
  137.      * 
  138.      * @return boolean 
  139.      */
  140.     public static function requireFieldClass($aClassName,$debug=False)
  141.     {
  142.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::requireFieldClass(" $aClassName ");");
  143.  
  144.         if (!class_exists($aClassName))
  145.         {
  146.             if (!$arr_fldDesc self::getFieldClassDesc($aClassName))
  147.             {
  148.                 if (file_exists(__OCSP_PHPINCPATH__ "db/frmClasses/" $aClassName ".phpclass"))
  149.                 {
  150.                     require_once __OCSP_PHPINCPATH__ "db/frmClasses/" $aClassName ".phpclass";
  151.                 }
  152.                 if (!class_exists($aClassName))
  153.                 {
  154.                     throw new Exception(_OCSP_EXCEP_FLDCLNOTDEF_ ":" $aClassName);
  155.                 }
  156.             }
  157.             
  158.             switch($arr_fldDesc['FLD_SYSTEM'])
  159.             {
  160.                 case "OCSP":
  161.                     if (file_exists(__OCSP_PHPINCPATH__ $arr_fldDesc['FLD_CLASS_SRC']))
  162.                     {
  163.                         pcf_require_class($aClassName,__OCSP_PHPINCPATH__ $arr_fldDesc['FLD_CLASS_SRC']);
  164.                         return True;
  165.                     else if (file_exists(__OCSP_PHPINCPATH__ "db" _OCSP_DIRSEP_ "frmClasses" _OCSP_DIRSEP_ $arr_fldDesc['FLD_CLASS_SRC']))  {
  166.                         pcf_require_class($aClassName,__OCSP_PHPINCPATH__ "db" _OCSP_DIRSEP_ "frmClasses" _OCSP_DIRSEP_ $arr_fldDesc['FLD_CLASS_SRC']);
  167.                         return True;
  168.                     else {
  169.                         return False
  170.                     }
  171.                 case "MODULE":
  172.                     if (!intval($arr_fldDesc['MOD_ID']))
  173.                     {
  174.                         throw new Exception(_OCSP_EXCEP_FLDCLNOTDEF_ ":" $aClassName " MODULE ID NOT SET");
  175.                     }
  176.                     pcf_require_class('OCSP_MODULE',__OCSP_PHPINCPATH__ "modules/OCSP_MODULE.phpclass");
  177.                     if ($obj_module OCSP_MODULE::factoryFromId($arr_fldDesc['MOD_ID']))
  178.                     {
  179.                         pcf_require_class($aClassName,$obj_module->getModuleIncPath()"/" $arr_fldDesc['FLD_CLASS_SRC']);
  180.                         return True;
  181.                     else {
  182.                         return False;
  183.                     }
  184.                 default:
  185.                     if (isset($GLOBALS[$arr_fldDesc['FLD_SYSTEM']]['PHPINCPATH']))
  186.                     {
  187.                         pcf_require_class($aClassName,$GLOBALS[$arr_fldDesc['FLD_SYSTEM']]['PHPINCPATH']"/" $arr_fldDesc['FLD_CLASS_SRC']);
  188.                         return True;                        
  189.                     else if (file_exists(__OCSP_PROJECTPATH__ $arr_fldDesc['FLD_CLASS_SRC'])) {
  190.                         pcf_require_class($aClassName,__OCSP_PROJECTPATH__$arr_fldDesc['FLD_CLASS_SRC']);
  191.                         return True;                                                
  192.                     else if (file_exists(__OCSP_PHPINCPATH__ $arr_fldDesc['FLD_CLASS_SRC'])) {
  193.                         pcf_require_class($aClassName,__OCSP_PHPINCPATH__$arr_fldDesc['FLD_CLASS_SRC']);
  194.                         return True;                                                
  195.                     
  196.                     
  197.                     return False;
  198.             }
  199.         else {
  200.             return True;
  201.         }
  202.         
  203.     }
  204.         
  205.     /**
  206.      * loads the field Desc from File cache and sets self::$dbmsFieldClassDesc
  207.      *
  208.      * @param boolean $debug 
  209.      * 
  210.      * @return boolean 
  211.      * 
  212.      * @version pk-08-06-13
  213.      */
  214.     public static function loadFieldClassDesc($debug=False)
  215.     {
  216.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::loadFieldClassDesc()");
  217.  
  218.         $str_cacheFile=OCSP_OBJ::getConf('OBJCACHEPATH')."form_cache"._OCSP_DIRSEP_."fielddesc.cache";
  219.         if (file_exists($str_cacheFile))
  220.         {
  221.             if ($arr_desc unserialize(file_get_contents($str_cacheFile)))
  222.             {
  223.                 self::$dbmsFieldClassDesc $arr_desc['DESC'];
  224.                 self::$dbmsFieldTypeClasses $arr_desc['TYPE'];    
  225.                 self::compat_setOCSP_DBMS_FIELDDESC($debug);        
  226.             }
  227.         else {
  228.             self::writeFieldDescToCache($debug);        
  229.         }
  230.     }
  231.     
  232.     /**
  233.      * loads field definition from the db and caches to a file
  234.      *
  235.      * @param boolean $debug 
  236.      * 
  237.      * @return boolean 
  238.      */
  239.     public static function writeFieldClassDescToCache($debug=False)
  240.     {
  241.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::writeFieldDescToCache()");
  242.  
  243.         if (self::$dbmsFieldClassDesc OCSP_OBJ::defaultReadDBObj()->getIndexedArray('T_DBMS_FIELDDESC',NULL,'FLD_CLASS',Null,0,0,"FLD_ISTYPEDEF DESC, FLD_TYPE",$debug))
  244.         {
  245.             self::$dbmsFieldTypeClasses=array();
  246.             foreach(self::$dbmsFieldClassDesc as $str_class => $arr_desc)
  247.             {
  248.                 self::$dbmsFieldTypeClasses[$arr_desc['FLD_TYPE']][$str_class;
  249.             }                                    
  250.         }
  251.         
  252.         self::compat_setOCSP_DBMS_FIELDDESC($debug);
  253.         
  254.         $str_cacheFile=OCSP_OBJ::getConf('OBJCACHEPATH')."form_cache"._OCSP_DIRSEP_."fielddesc.cache";
  255.  
  256.         if (!function_exists('pcf_checkDir')) require __OCSP_PHPINCPATH__."common/pcf_directory.phpinc";
  257.         if (!pcf_checkDir(dirname($str_cacheFile),True,0770,$debug))
  258.         {
  259.             ocsp_logError(__FILE__,__LINE__,"could not create cachedir: <br />$str_cacheDir");
  260.             return False;
  261.         }        
  262.         
  263.         $arr_desc array(
  264.                 'DESC' => self::$dbmsFieldClassDesc,
  265.                 'TYPE' => self::$dbmsFieldTypeClasses
  266.             );
  267.         file_put_contents($str_cacheFile,serialize($arr_desc));
  268.         return True;
  269.         
  270.     }
  271.     
  272.     /**
  273.      * sets the old style $GLOBALS['OCSP']['DBMS_FIELDDESC']
  274.      *
  275.      * @param boolean $debug 
  276.      */
  277.     public static function compat_setOCSP_DBMS_FIELDDESC($debug=False)
  278.     {
  279.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::compat_setOCSP_DBMS_FIELDDESC();");
  280.         foreach(self::$dbmsFieldClassDesc as &$arr_dbRow)
  281.         {
  282.             $GLOBALS['OCSP']['DBMS_FIELDDESC']['C'][$arr_dbRow['FLD_CLASS']]=$arr_dbRow;
  283.             $GLOBALS['OCSP']['DBMS_FIELDDESC']['T'][$arr_dbRow['FLD_TYPE']][]=&$GLOBALS['OCSP']['DBMS_FIELDDESC']['C'][$arr_dbRow['FLD_CLASS']];            
  284.         }
  285.     }
  286.  
  287.     /**
  288.      * clears the FieldClassDesc cache
  289.      * @param boolean $debug 
  290.      * @since pk-08-06-14
  291.      */
  292.     public static function clearFieldClassDescCache($debug=False)
  293.     {
  294.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::clearFieldClassDescCache();");
  295.         
  296.         @unlink(OCSP_OBJ::getConf('OBJCACHEPATH')."frmFldsDefinition.cache");
  297.         @unlink(OCSP_OBJ::getConf('OBJCACHEPATH')."form_cache"._OCSP_DIRSEP_."fielddesc.cache");        
  298.     }
  299.     
  300.     
  301.     /*** Aggregations: */
  302.  
  303.     /**
  304.       * @var OCSP_DB $myDBObj 
  305.       * @access protected
  306.       */
  307.     protected $myDBObj=NULL;
  308.  
  309.     /*** Compositions: */
  310.  
  311.     /**
  312.       * @var OCSP_FORM_BLOCK $myBlocks 
  313.       * @access protected
  314.       */
  315.     protected $myBlocks=array();
  316.  
  317.     /**
  318.       * @var OCSP_FRMVIEW_LIST $myView 
  319.       * @access protected
  320.       */
  321.     protected $myView=NULL;
  322.  
  323.     /**
  324.       * @var OCSP_FRMCONTR_LIST $myControll 
  325.       * @access protected
  326.       */
  327.     protected $myControl=NULL;
  328.  
  329.     /**
  330.       * @var OCSP_FORM_DBCONTROLL $myDBControll 
  331.       * @access protected
  332.       */
  333.     protected $myDBControll=NULL;
  334.  
  335.     /**
  336.       * the current table object class
  337.       * @var DBMS_TABLE_OBJ $myTblObj 
  338.       * @access protected
  339.       */
  340.     protected $myTblObj=NULL;
  341.  
  342.  
  343.     /**
  344.       * the ajax object used by the fields
  345.       * @var OCSP_AJAXFORM $myAjaxObj 
  346.       * @access protected
  347.       */
  348.     protected $myAjaxObj=NULL;
  349.  
  350.  
  351.     /*** Attributes: */
  352.  
  353.     /**
  354.       * index in self::instances_byId
  355.       * @var int $myInstanceId 
  356.       * @access protected
  357.       */
  358.     protected $myInstanceId=0;
  359.  
  360.     /**
  361.       * @var boolean $myFormValuesAreSet 
  362.       * @access protected
  363.       */
  364.     protected $myFormValuesAreSet=False;
  365.  
  366.     /**
  367.       * array with all tables the form uses
  368.       * note Index 0 is considered as master table
  369.       * the first table to load.
  370.       * if the tables are joined the order of adding to the join
  371.       * depends on the index
  372.       *
  373.       * the array is populated by exploding $this->FRM_TABLES (,-seperated)
  374.       *
  375.       * @var array $myTables 
  376.       * @access protected
  377.       */
  378.     protected $myTables=array();
  379.  
  380.     /**
  381.       * db attributes stored in T_DBMS_FORM
  382.       * @var int $FRM_ID 
  383.       * @access protected
  384.       */
  385.     protected $FRM_ID           = 0;
  386.     /**
  387.       * @var string $FRM_NAME 
  388.       * @access protected
  389.       */
  390.     protected $FRM_NAME         = "";
  391.     /**
  392.       * @var string $FRM_TABLES 
  393.       * @access protected
  394.       */
  395.     protected $FRM_TABLES       = "";
  396.     /**
  397.       * @var string $FRM_TITLE 
  398.       * @access protected
  399.       */
  400.     protected $FRM_TITLE        = "";
  401.     /**
  402.       * @var string $FRM_JOIN 
  403.       * @access protected
  404.       */
  405.     protected $FRM_JOIN         = "";
  406.     /**
  407.       * @var boolean $FRM_ISDEFLT 
  408.       * @access protected
  409.       */
  410.     protected $FRM_ISDEFLT      = False;
  411.     /**
  412.       * @var int $FRM_SRCVERSION 
  413.       * @access protected
  414.       */
  415.     protected $FRM_SRCVERSION   = 4;
  416.     /**
  417.       * @var string $FRM_LAYOUT 
  418.       * @access protected
  419.       */
  420.     protected $FRM_LAYOUT       = "";
  421.     /**
  422.       * @var int $FRM_DEBUG 
  423.       * @access protected
  424.       */
  425.     protected $FRM_DEBUG        = 0;
  426.     /**
  427.       * @var string $FRM_DESC 
  428.       * @access protected
  429.       */
  430.     protected $FRM_DESC         = "";
  431.     /**
  432.       * @var string $FRM_LSTGROUPS 
  433.       * @access protected
  434.       */
  435.     protected $FRM_LSTGROUPS    = "";
  436.  
  437.     /**
  438.      * disable to check the form on ajax relaod
  439.      * 
  440.      *
  441.      * @var boolean 
  442.      * 
  443.      * @since pk-08-11-01
  444.      */
  445.     protected $FRM_DISABLEAJAXCHANGEFORM = 0;
  446.  
  447.     /**
  448.       * @var array $myDBValues database representation of the form
  449.       * @access protected
  450.       */
  451.     protected $myDBValues   = array();
  452.  
  453.     /**
  454.       * @var array $myFormDBCols (columns of T_DBMS_FORM to use in the object)
  455.       * @access protected
  456.       */
  457.     protected $myFormDBCols=array('FRM_ID','FRM_NAME','FRM_TITLE','FRM_CLASS',
  458.                                   'FRM_TABLES','FRM_ISDEFLT','FRM_QUERY','FRM_JOIN',
  459.                                   'FRM_REVISION','FRM_SRCVERSION','FRM_LAYOUT','FRM_DEBUG','FRM_DESC','FRM_LSTGROUPS',
  460.                                   'FRM_DISABLEAJAXCHANGEFORM');
  461.  
  462.     /**
  463.       * include file for the table object
  464.       * @var string $tblObj_include 
  465.       * @access protected
  466.       */
  467.     protected $tblObj_include=NULL;
  468.  
  469.     /**
  470.       * class file of the table object
  471.       * @var string $tblObj_class 
  472.       */
  473.     protected $tblObj_class=NULL;
  474.  
  475.  
  476.     /**
  477.       * @var array $layoutFields 
  478.       * @access protected
  479.       */
  480.     protected $layoutFields=array();
  481.  
  482.     /**
  483.       * @var array $listGroups 
  484.       *
  485.       *  array [DBMS_FIELD->getKey()]:
  486.       *  - [CSSCLASS] a css class to use for the table row &lt;tr&gt;
  487.       *  - [CSSSTYLE] a css style to add inline to the row &lt;td&gt; / &lt;th&gt;
  488.       *  - [USE_TH]   boolean use &lt;th&gt; or &lt;td&gt; for the value
  489.       *  - [TMPL]     a template to parse
  490.       *  - [ORDERBY]  column(s) to add to sql sorting (if empty the field key is used)
  491.       * @access protected
  492.       */
  493.     protected $listGroups=array();
  494.  
  495.     /**
  496.       * @var array $submitActions 
  497.       * @access protected
  498.       */
  499.     protected $submitActions=array();
  500.  
  501.     /**
  502.       * @var int $frmMode 
  503.       * @access protected
  504.       */
  505.     protected $frmMode=0;
  506.  
  507.     /**
  508.       * @var array $myErrors array of error messages array('LABEL','MSG')
  509.       * @access protected
  510.       */
  511.     protected $myErrors = array();
  512.  
  513.     /**
  514.       * @var string $my_jsId a unique id of the form used to identify the form in the javascript array ocsp_frmList
  515.       * @access private
  516.       */
  517.     protected $my_jsId = "";
  518.     
  519.     /**
  520.      * array of fields which have to been pass through to class
  521.      * 
  522.      * if you need to add values to the form data on save
  523.      * without having it in the form available add it this array
  524.      * 
  525.      * the fields will be passed encrypted and overwrites values
  526.      * set in the form
  527.      * 
  528.      * @var array $myPassThroughFields 
  529.      * 
  530.      * @since pk-08-06-25
  531.      */
  532.     protected $myPassThroughFields = array();
  533.  
  534.     /*
  535.      * are rights set for the form?
  536.      * 
  537.      * - 1 yes
  538.      * - 0 not checked now
  539.      * - -1 no
  540.      * 
  541.      * @var int $rightsSet
  542.      * 
  543.      * @since pk-08-10-03
  544.      */    
  545.     protected $rightsSet = 0;
  546.     
  547.     /**
  548.      * alread loaded userrights from the db
  549.      *
  550.      * @var array $loadedUserRights 
  551.      */
  552.     protected $loadedUserRights = array();
  553.     
  554.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  555.     // init methods
  556.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  557.  
  558.     /**
  559.       * @param mixed $frmIdName 
  560.       *
  561.       * @param global array $OCSP_CONF
  562.       * @param boolean $debug 
  563.       *
  564.       * @return string (cache file path)
  565.       * @since pk-07-10-13
  566.       * @version pk-08-11-03
  567.       */
  568.     static public function getCacheFileName($frmIdName,$debug=False)
  569.     {
  570.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::getCacheFileName($frmIdName)");
  571.         $str_cacheFile=OCSP_CONF::getInstance('OCSP')->getValue('CACHEPATH').constant('OCSP_FORM::FORM_CACHE_DIR')._OCSP_DIRSEP_;
  572.         if (intval($frmIdName))
  573.         {
  574.             return $str_cacheFile.intval($frmIdName).OCSP_FORM::FORM_CACHE_FILEEXT;
  575.         else {
  576.             $str_fileName=preg_replace('/[^a-z0-9_\-\.]/i',"_"trim($frmIdName));
  577.             if (!empty($str_fileName)) {
  578.                 return $str_cacheFile.$str_fileName.constant('OCSP_FORM::FORM_CACHE_FILEEXT');
  579.             }
  580.         }
  581.  
  582.         ocsp_logError(__FILE__,__LINE__,"could not get chache file --$frmIdName--");
  583.     }
  584.  
  585.     /**
  586.       * @param mixed $frmIdName 
  587.       * @param string $className 
  588.       * @param boolean $debug 
  589.       *
  590.       * @return OCSP_FORM 
  591.       */
  592.     static public function &get_existing_instance($frmIdName,$className,$debug=False)
  593.     {
  594.         if ($debugechoDebugMethod(__FILE__,"static::","OCSP_FORM::get_existing_instance($frmIdName,$className)");
  595.  
  596.         $obj_found=NULL;
  597.         foreach(OCSP_FORM::$form_instances as $int_idx => $arr_instance)
  598.         {
  599.             if (intval($arr_instance['frmId']|| !empty($arr_instance['frmName']))
  600.             {
  601.                 // only populated objects
  602.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>$int_idxid: {$arr_instance['frmId']} name: {$arr_instance['frmName']}</p>");
  603.                 if (($arr_instance['frmId']==$frmIdName|| ($arr_instance['frmName']==$frmIdName)) {
  604.                     if ($arr_instance['class']==$className)
  605.                     {
  606.                         return $arr_instance['frmObj'];
  607.                     else {
  608.                         if (!$obj_found{
  609.                             $int_foundidx=$int_idx;
  610.                             $obj_found=$arr_instance['frmObj'];
  611.                         }
  612.                     }
  613.                 }
  614.             }
  615.         }
  616.         if ($obj_found)
  617.         {
  618.             self::castObj(OCSP_FORM::$form_instances[$int_foundidx]['frmObj'],$className);
  619.             return OCSP_FORM::$form_instances[$int_foundidx]['frmObj'];
  620.         }
  621.         return $obj_found;
  622.     }
  623.  
  624.     /**
  625.       * @param array $cacheArr 
  626.       * @param string $className (if set overwrite 'FRM_CLASS' in cacheArr )
  627.       * @param boolean $debug 
  628.       *
  629.       * @return OCSP_FORM 
  630.       *
  631.       * @requires pcf_templates.phpinc
  632.       *
  633.       * @since pk-07-10-13
  634.       */
  635.     static public function &factory_from_cacheArr($cacheArr,$className=NULL,$debug=False)
  636.     {
  637.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::factory_from_cacheArr()","<pre>".print_r($cacheArr['dbRow'],True)."</pre>");
  638.  
  639.         $obj_ret=NULL;
  640.         if (!isset($cacheArr['dbRow']['FRM_ID']|| !intval($cacheArr['dbRow']['FRM_ID']))
  641.         {
  642.             ocsp_logError(__FILE__,__LINE__,"\$cacheArr['dbRow']['FRM_ID'] not set",E_ERROR);
  643.             return $obj_ret;
  644.         }
  645.  
  646.         if (!isset($cacheArr['dbRow']['FRM_NAME']|| empty($cacheArr['dbRow']['FRM_NAME']))
  647.         {
  648.             ocsp_logError(__FILE__,__LINE__,"\$cacheArr['dbRow']['FRM_NAME'] not set",E_ERROR);
  649.             return $obj_ret;
  650.         }
  651.  
  652.         if ((empty($className)) || !class_exists($className))
  653.         {
  654.             if (!isset($cacheArr['FRM_CLASS']|| empty($cacheArr['FRM_CLASS']))
  655.             {
  656.                 ocsp_logError(__FILE__,__LINE__,"\$cacheArr['FRM_CLASS'] not set",E_ERROR);
  657.                 return $obj_ret;
  658.             }
  659.             if (!class_exists($cacheArr['FRM_CLASS']))
  660.             {
  661.                 if (isset($cacheArr['FRM_CLASSSRC']&& !empty($cacheArr['FRM_CLASSSRC']))
  662.                 {
  663.                     require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_templates.phpinc";
  664.                     $str_incFile=pcf_tmpl_parse($cacheArr['FRM_CLASSSRC']);
  665.                     require_once $str_incFile;
  666.                 else {
  667.                     ocsp_logError(__FILE__,__LINE__,"\$cacheArr['FRM_CLASSSRC'] not set",E_ERROR);
  668.                     return $obj_ret;
  669.                 }
  670.             }
  671.             $className=$cacheArr['FRM_CLASS'];
  672.         }
  673.  
  674.         if ($debugechoDebugLine(__FILE__,__LINE__,"\$obj_form=new $className({$cacheArr['dbRow']['FRM_ID']},{$cacheArr['dbRow']['FRM_NAME']},$debug);");
  675.         $obj_form=new $className($cacheArr['dbRow']['FRM_ID'],$cacheArr['dbRow']['FRM_NAME'],$debug);
  676.         $obj_form->setMyDBRow($cacheArr['dbRow'],$debug);
  677.         if ($debugechoDebugLine(__FILE__,__LINE__,"returning ".get_class($obj_form)." ID: ".$obj_form->getId()." Name:".$obj_form->getName());
  678.         return $obj_form;
  679.     }
  680.  
  681.     /**
  682.       * returns the form object with FRM_ID is $aId
  683.       *
  684.       * @param int $aId 
  685.       * @param string $className (note need to be loaded before if not a standard openCSP form class)
  686.       * @param boolean $debug 
  687.       * @param boolean $forceNew (do not check self::instances_byId)
  688.       *
  689.       * @return OCSP_FORM 
  690.       *
  691.       * @global array $OCSP_CONF 
  692.       *
  693.       * @access public
  694.       *
  695.       */
  696.     static public function &factory_from_id($aId,$className='',$debug=False,$forceNew=False)
  697.     {
  698.         if ($debugechoDebugMethod(__FILE__,(isset($thisget_class($this"direct call"),"OCSP_FORM::factory_from_id($aId,$className)");
  699.  
  700.         if (!intval($aId))
  701.         {
  702.             $obj_ret=NULL;return $obj_ret// avoid warning
  703.         }
  704.  
  705.         if (!$forceNew)
  706.         {
  707.             if ($obj_form=self::get_existing_instance($aId,$className,$debug))
  708.             {
  709.                 return $obj_form;
  710.             }
  711.         }
  712.  
  713.  
  714.         if (file_exists(OCSP_FORM::getCacheFileName($aId)))
  715.         {
  716.             include OCSP_FORM::getCacheFileName($aId);
  717.             if ($o_tmp=OCSP_FORM::factory_from_cacheArr($arr_cache,$className,$debug))
  718.             {
  719.                 if ($debugechoDebugLine(__FILE__,__LINE__,"returning ".get_class($o_tmp)." ID: ".$o_tmp->getId()." Name:".$o_tmp->getName());
  720.                 return $o_tmp;
  721.             }
  722.         }
  723.  
  724.         if (empty($className)) $className='OCSP_FORM';
  725.         if (class_exists($className))
  726.         {
  727.             $o_tmp=new $className($aId,'',$debug);
  728.         else {
  729.             if ($debugocsp_logError(__FILE__,__LINE__,"could not factory $className",E_WARNING);
  730.             $o_tmp=new OCSP_FORM($aId,'',$debug);
  731.         }
  732.  
  733.         if ($o_frm=$o_tmp->loadFromFileCache($aId,NULL,0.0,$debug))
  734.         {
  735.             self::castObj($o_frm,$className,$debug)// ensure the right class is set
  736.             return $o_frm;
  737.         }
  738.  
  739.         if ($o_frm=$o_tmp->loadFromDb($aId,NULL,0.0,$debug))
  740.         {
  741.             self::castObj($o_frm,$className,$debug)// ensure the right class is set
  742.             return $o_frm;
  743.         }
  744.  
  745.         if ($debugechoDebugLine(__FILE__,__LINE__,"no form found");
  746.     }
  747.  
  748.     /**
  749.       * returns the form object with FRM_NAME= $aName
  750.       *
  751.       * @global OCSP_FORM $OCSP_OBJ['FORMS']['BYID'][$o_tmp->getId()] used for memory cache of the form
  752.       * @global OCSP_FORM $OCSP_OBJ['FORMS']['BYNAME'][$o_tmp->getName()] used for memory cache of the form
  753.       *
  754.       * @param int $aId 
  755.       * @param float 
  756.       * @param string $className (note need to be loaded before if not a standard openCSP form class)
  757.       * @param boolean $debug 
  758.       * @param boolean $forceNew (do not check self::instances_byId)
  759.       *
  760.       * @return OCSP_FORM 
  761.       *
  762.       * @access public
  763.       * @static
  764.       */
  765.     static public function &factory_from_name($aName,$className=NULL,$debug=False,$forceNew=False)
  766.     {
  767.         if ($debugechoDebugMethod(__FILE__,(isset($thisget_class($this"direct call"),"OCSP_FORM::factory_from_name($aName,$className)");
  768.  
  769.         if (empty($aName)) return False;
  770.  
  771.         if (!$forceNew)
  772.         {
  773.             if ($obj_form=self::get_existing_instance($aName,$className,$debug))
  774.             {
  775.                 return $obj_form;
  776.             }
  777.         }
  778.  
  779.         if (file_exists(OCSP_FORM::getCacheFileName($aName)))
  780.         {
  781.             include OCSP_FORM::getCacheFileName($aName);
  782.             if ($o_tmp=OCSP_FORM::factory_from_cacheArr($arr_cache,$className,$debug))
  783.             {
  784.                 if ($debugechoDebugLine(__FILE__,__LINE__,"returning ".get_class($o_tmp)." ID: ".$o_tmp->getId()." Name:".$o_tmp->getName());
  785.                 return $o_tmp;
  786.             }
  787.         }
  788.  
  789.         if (empty($className)) $className='OCSP_FORM';
  790.         if (class_exists($className))
  791.         {
  792.             $o_tmp=new $className(0,$aName,$debug);
  793.         else {
  794.             if ($debugocsp_logError(__FILE__,__LINE__,"could not factory $className",E_WARNING);
  795.             $o_tmp=new OCSP_FORM(0,$aName,$debug);
  796.         }
  797.  
  798.         if ($o_frm=$o_tmp->loadFromDb(0,$aName,0.0,$debug))
  799.         {
  800.             self::castObj($o_frm,$className,$debug)// ensure the right class is set
  801.             return $o_frm;
  802.         }
  803.  
  804.         if ($debugechoDebugLine(__FILE__,__LINE__,"no form found");
  805.         return $o_tmp;
  806.     }
  807.  
  808.     /**
  809.       * @param boolean $debug 
  810.       *
  811.       * @requires pcf_md5.phpinc
  812.       *
  813.       * @return OCSP_FORM 
  814.       *
  815.       * @version pk-07-10-07
  816.       */
  817.     static public function &factory_from_request($debug=False)
  818.     {
  819.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getFRM_fromSubmit()");
  820.  
  821.         require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_md5.phpinc";
  822.         
  823.         
  824.         $obj_ret=NULL;
  825.  
  826.         if (isset($_REQUEST['OCSP_FORM_CLASS']&& !empty($_REQUEST['OCSP_FORM_CLASS']))
  827.         {
  828.             //require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_md5.phpinc";
  829.             $str_className=OCSP_SESSION::getInstance()->decrypt($_REQUEST['OCSP_FORM_CLASS']);
  830.             if ($debugechoDebugLine(__FILE__,__LINE__,"form class is ".$str_className);
  831.  
  832.             if (!class_exists($str_className))
  833.             {
  834.                 if (isset($_REQUEST['OCSP_FORM_INC']&& !empty($_REQUEST['OCSP_FORM_INC']))
  835.                 {
  836.                     $str_incFile=OCSP_SESSION::getInstance()->decrypt($_REQUEST['OCSP_FORM_INC']);
  837.                     if ($debugechoDebugLine(__FILE__,__LINE__,"class include: ".$str_incFile);
  838.                     require_once $str_incFile;
  839.                 }
  840.                 if (!class_exists($str_className))
  841.                 {
  842.                     if ($debugocsp_logError(__FILE__,__LINE__,"class $str_className not found");
  843.                     $str_className='OCSP_FORM';
  844.                 }
  845.             }
  846.         else {
  847.             $str_className='OCSP_FORM';
  848.         }
  849.  
  850.         if (isset($_REQUEST['OCSP_FORM_SETTING_CRYPT']))
  851.         {
  852.             $arr_frmSettings=unserialize(OCSP_SESSION::getInstance()->decrypt($_REQUEST['OCSP_FORM_SETTING_CRYPT']));
  853.             if (isset($arr_frmSettings['ID']&& intval($arr_frmSettings['ID']))
  854.             {
  855.                 $obj_ret self::factory_from_id(intval($arr_frmSettings['ID']),$str_className,$debug);
  856.             }
  857.         else if (isset($_REQUEST['DBMSFORMID']&& intval($_REQUEST['DBMSFORMID'])) {
  858.             $obj_ret self::factory_from_id(intval($_REQUEST['DBMSFORMID']),$str_className);
  859.         else if (isset($_REQUEST['OCSP_FORM_TBLOBJCLASS']&& !empty($_REQUEST['OCSP_FORM_TBLOBJCLASS'])) {
  860.             $str_dbObjClass=OCSP_SESSION::getInstance()->decrypt($_REQUEST['OCSP_FORM_TBLOBJCLASS']);
  861.             if (!class_exists($str_dbObjClass))
  862.             {
  863.                 require_once OCSP_SESSION::getInstance()->decrypt($_REQUEST['OCSP_FORM_TBLOBJINC']);                
  864.             }
  865.             $obj_tblObj new $str_dbObjClass();
  866.             $obj_ret $obj_tblObj->getForm(FRM_MODE_READONLY,NULL,$str_className,$debug);            
  867.         else {
  868.             return $obj_ret// NULL
  869.         }
  870.         
  871.         if (isset($_REQUEST['FRMHTMLNAME']&& !empty($_REQUEST['FRMHTMLNAME']))
  872.         {            
  873.             $obj_ret->setMyJsId(substr($_POST['FRMHTMLNAME'],4));
  874.             if ($debugpcf_js_alert(__LINE__ . "JsId set To" $obj_ret->getMyJsId());
  875.         
  876.         
  877.         if ($debug
  878.             echoDebugLine(__FILE__,__LINE__,"<p>\$arr_frmSettings: </p><pre>" print_r($arr_frmSettings,True"</pre>");
  879.         
  880.         return $obj_ret;
  881.     }
  882.  
  883.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  884.     // static methods
  885.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  886.     
  887.     /**
  888.      * returns an array of forms which fit's for $aTable
  889.      *
  890.      * @param string $aTable 
  891.      * @param boolean $debug 
  892.      * 
  893.      * @global array $OCSP_OBJ 
  894.      * 
  895.      * @return array 
  896.      * 
  897.      * @since pk-08-02-21
  898.      * 
  899.      */
  900.     static public function findForm_listForTable($aTable=NULL,$debug=False)
  901.     {
  902.         global $OCSP_OBJ;
  903.         
  904.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FROM::findForm_listForTable(" $aTable ")");
  905.  
  906.         if ($obj_db $OCSP_OBJ['USER']->getMyDBObj())
  907.         {
  908.             // @inlineSQL
  909.             $str_query  "SELECT FRM_ID,FRM_NAME,FRM_DESC FROM T_DBMS_FORM";
  910.             $str_query .= " WHERE FRM_TABLES LIKE '%" str_replace("'","%",$aTable"%'";
  911.             $str_query .= " ORDER BY FRM_ISDEFLT DESC";
  912.             
  913.             if ($arr_ret $obj_db->queryArray($str_query,0,-1))
  914.             {
  915.                 return $arr_ret;    
  916.             }
  917.         }
  918.         
  919.         return array();
  920.     }
  921.     
  922.     /**
  923.      * gets an html option list with all possible forms for $aTable
  924.      *
  925.      * @param string $aTable 
  926.      * @param int $selectedForm 
  927.      * @param boolean $debug 
  928.      * 
  929.      * @return string (html)
  930.      * 
  931.      * @since pk-08-02-21
  932.      * 
  933.      */
  934.     static public function findForm_getHTMLOptionList($aTable=NULL,$selectedForm=0,$debug=False)
  935.     {
  936.         global $OCSP_OBJ;
  937.         if ($debugechoDebugMethod(__FILE__,"static","OCSP_FORM::findForm_getHTMLOptionList(" $aTable ")");
  938.         
  939.         $str_ret "";
  940.         
  941.         if ($obj_db $OCSP_OBJ['USER']->getMyDBObj())
  942.         {
  943.             // @inlineSQL
  944.             $str_query  "SELECT FRM_ID,FRM_NAME,FRM_DESC FROM T_DBMS_FORM";
  945.             $str_query .= " WHERE FRM_TABLES LIKE '%" str_replace("'","%",$aTable"%'";
  946.             $str_query .= " ORDER BY FRM_ISDEFLT DESC";
  947.                                     
  948.             if ($arr_forms $obj_db->queryArray($str_query,0,-1))
  949.             {
  950.                 foreach($arr_forms as $arr_row)
  951.                 {
  952.                     $str_ret .= "<option value=\"" $arr_row['FRM_ID'"\"";
  953.                     if ($arr_row['FRM_ID'== $selectedForm)
  954.                     {
  955.                         $str_ret .= " selected=\"selected\"";
  956.                     }
  957.                     $str_ret .= " title=\"" str_replace("\"","&#34;",$arr_row['FRM_DESC']."\"";
  958.                     $str_ret .= ">" $arr_row['FRM_NAME'" (ID: " $arr_row['FRM_ID'")</option>\n"
  959.                         
  960.                 }
  961.             
  962.         
  963.     
  964.         return $str_ret;
  965.     }
  966.     
  967.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  968.     // constructor
  969.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  970.  
  971.     /**
  972.       * @param int $aId 
  973.       * @param string $aName 
  974.       * @param boolean $debug 
  975.       *
  976.       */
  977.     function __construct($aId=0,$aName="",$debug=False{
  978.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::__construct($aId,$aName)");
  979.         $this->myInstanceId=1;
  980.  
  981.         $this->FRM_ID=$aId;
  982.         $this->FRM_NAME=$aName;
  983.  
  984.         while (isset(OCSP_FORM::$form_instances[$this->myInstanceId]&& is_array(OCSP_FORM::$form_instances[$this->myInstanceId]))
  985.         {
  986.             $this->myInstanceId++;
  987.         }
  988.  
  989.         OCSP_FORM::$form_instances[$this->myInstanceId]=array(
  990.             'frmId'     => $aId,
  991.             'frmName'   => $aName,
  992.             'class'     => get_class($this),
  993.             'frmObj'    => &$this
  994.         );
  995.  
  996.         $this->myFormValuesAreSet=False;
  997.  
  998.         if ($debugechoDebugLine(__FILE__,__LINE__,"<p>OCSP_FORM::\$form_instances[".$this->myInstanceId."]</p>");
  999.     }
  1000.  
  1001.     /**
  1002.       * @return boolean 
  1003.       */
  1004.     public function formIsLoaded()
  1005.     {
  1006.         return $this->myFormValuesAreSet;
  1007.     }
  1008.  
  1009.  
  1010.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1011.     // getter setter methods
  1012.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1013.  
  1014.  
  1015.     /**
  1016.       * if $this->myDBObj is NULL a new connection to either
  1017.       * the users db or the global database will be establisched
  1018.       *
  1019.       * @param boolean $debug 
  1020.       *
  1021.       * @global array OCSP_OBJ
  1022.       *
  1023.       * @return OCSP_DB 
  1024.       *
  1025.       * @requires OCSP_DB.phpclass"
  1026.       */
  1027.     function &getDBObj($debug=False)
  1028.     {
  1029.         global $OCSP_OBJ;
  1030.  
  1031.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getDBObj()");
  1032.         if (pcf_is_instance_of($this->myDBObj,'OCSP_DB'))
  1033.         {
  1034.             if (!$this->myDBObj->isConnected())
  1035.             {
  1036.                 $this->myDBObj->connect();
  1037.             }
  1038.         else if (pcf_is_instance_of($this->myTblObj,'DBMS_TABLE_OBJ')) {
  1039.             $this->myDBObj=$this->myTblObj->getDBObj();
  1040.             if (!$this->myDBObj->isConnected())
  1041.             {
  1042.                 $this->myDBObj->connect();
  1043.             }
  1044.         else if (pcf_is_instance_of($OCSP_OBJ['USRDB'],'OCSP_DB')) {
  1045.             if (!$OCSP_OBJ['USRDB']->isConnected())
  1046.             {
  1047.                 $OCSP_OBJ['USRDB']->connect();
  1048.             }
  1049.             $this->myDBObj=&$OCSP_OBJ['USRDB'];
  1050.         else if (pcf_is_instance_of($OCSP_OBJ['USER'],'OCSP_USER')) {
  1051.             $this->myDBObj=$OCSP_OBJ['USER']->getMyDBObj();
  1052.         else {
  1053.             require_once __OCSP_PHPINCPATH__."db/OCSP_DB.phpclass";
  1054.             $this->myDBObj=OCSP_DB::newDBConnect("",False,$debug);
  1055.        }
  1056.         return $this->myDBObj;
  1057.     }
  1058.  
  1059.     /**
  1060.       * @param OCSP_DB $dbObj 
  1061.       * @param boolean $debug 
  1062.       */
  1063.     function setDBObj(&$dbObj,$debug=False)
  1064.     {
  1065.         $this->myDBObj=&$dbObj;
  1066.     }
  1067.  
  1068.  
  1069.     /**
  1070.       * @param OCSP_FORM_DBCONTROLL 
  1071.       * @access public
  1072.       */
  1073.     function setMyDBControll(&$aDB_CONTROLL)
  1074.     {
  1075.         $this->myDBControll=&$aDB_CONTROLL;
  1076.     }
  1077.  
  1078.     /**
  1079.       * uses $OCSP_OBJ['DBCTRL'][get_class($this->myDBObj)] as cache
  1080.       *
  1081.       * @param boolean $debug 
  1082.       *
  1083.       * @global array $OCSP_OBJ 
  1084.       *
  1085.       * @return OCSP_FORM_DBCONTROLL 
  1086.       *
  1087.       * @requires OCSP_FORM_DBCONTROLL.phpclass
  1088.       * 
  1089.       * @access public
  1090.       * 
  1091.       */
  1092.     function &getMyDBControll($debug=False)
  1093.     {
  1094.         global $OCSP_OBJ;
  1095.  
  1096.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getMyDBControll()");
  1097.         if (!pcf_is_instance_of($this->myDBControll,'OCSP_FORM_DBCONTROLL'))
  1098.         {
  1099.             if (!$this->getDBObj()) // to ensure we have $this->myDBObj set
  1100.             {
  1101.                 ocsp_logError(__FILE__,__LINE__,"no database connection");
  1102.                 return;
  1103.             }
  1104.             if (isset($OCSP_OBJ['DBCTRL'][get_class($this->myDBObj)]))
  1105.             {
  1106.                 $this->myDBControll=&$OCSP_OBJ['DBCTRL'][get_class($this->myDBObj)];
  1107.             else {
  1108.                 require_once dirname(__FILE__)."/OCSP_FORM_DBCONTROLL.phpclass";
  1109.                 $OCSP_OBJ['DBCTRL'][get_class($this->myDBObj)]=OCSP_FORM_DBCONTROLL::newSubClass($this->myDBObj);
  1110.                 $this->myDBControll=&$OCSP_OBJ['DBCTRL'][get_class($this->myDBObj)];
  1111.             }
  1112.         }
  1113.         return $this->myDBControll;
  1114.     }
  1115.  
  1116.     /**
  1117.       * returns the value of an object variable
  1118.       *
  1119.       * @param string $varName 
  1120.       *
  1121.       * @return mixed 
  1122.       *
  1123.       * @since pk-06-07-27
  1124.       *
  1125.       */
  1126.     function getObjectVar($varName)
  1127.     {
  1128.         if (isset($this->{$varName})) return $this->{$varName};
  1129.         return NULL;
  1130.     }
  1131.  
  1132.     /**
  1133.       * overwrite in child classes if get_class does not fit
  1134.       *
  1135.       * @return string 
  1136.       */
  1137.     function getClassName()
  1138.     {
  1139.         return strtoupper(get_class($this));
  1140.     }
  1141.  
  1142.     /**
  1143.       * @return int 
  1144.       */
  1145.     function getId()
  1146.     {
  1147.         return intval($this->FRM_ID);
  1148.     }
  1149.  
  1150.     /**
  1151.       * @param int $aId 
  1152.       * 
  1153.       * @since pk-08-01-30
  1154.       */
  1155.     function setId($aId)
  1156.     {
  1157.         if (intval($aId== 0// copy form -> reset block id
  1158.         {
  1159.             if ($arr_blocks=$this->getBlocks())
  1160.             {
  1161.                 foreach($arr_blocks as &$obj_block)
  1162.                 {
  1163.                     $obj_block->setId(0);
  1164.                 }
  1165.             }
  1166.         }
  1167.         $this->FRM_ID intval($aId);
  1168.     }
  1169.  
  1170.     /**
  1171.       * @return string 
  1172.       */
  1173.     function getName()
  1174.     {
  1175.         return $this->FRM_NAME;
  1176.     }
  1177.  
  1178.     /**
  1179.       * @param string $aName 
  1180.       */
  1181.     function setName($aName)
  1182.     {
  1183.         $this->FRM_NAME=$aName;
  1184.     }
  1185.  
  1186.     /**
  1187.       * if empty($this->my_jsId) it is set
  1188.       * @return string (the js id of the form)
  1189.       * @version pk-08-09-23
  1190.       */
  1191.     function getMyJsId()
  1192.     {
  1193.         if (empty($this->my_jsId))
  1194.         {
  1195.             $this->my_jsId=hash('md5',$this->getId().$this->getName().get_class($this).$this->getFrmMode().$_SERVER['SCRIPT_NAME'].time().print_r(microtime(),true));
  1196.         }
  1197.         return $this->my_jsId;
  1198.     }
  1199.  
  1200.     /**
  1201.       * @param string $aId 
  1202.       */
  1203.     function setMyJsId($aId)
  1204.     {
  1205.         $this->my_jsId=$aId;
  1206.     }
  1207.  
  1208.  
  1209.     /**
  1210.       * returns the html form name
  1211.       * @return string 
  1212.       * @access public
  1213.       */
  1214.     function getHTMLname()
  1215.     {
  1216.         return "frm_".$this->getMyJsId();
  1217.     }
  1218.  
  1219.     /**
  1220.      * returns the title of the form
  1221.      * @return string 
  1222.      * @access public
  1223.      */
  1224.     function getTitle()
  1225.     {
  1226.         return $this->FRM_TITLE;   
  1227.     }
  1228.     
  1229.     /**
  1230.       * returns the post sub array name of the form fields
  1231.       * @return string 
  1232.       * @access public
  1233.       */
  1234.     function getDataArrName()
  1235.     {
  1236.         return "DBVAL_".$this->getId();
  1237.     }
  1238.  
  1239.  
  1240.  
  1241.     /**
  1242.      * links a table object with the form
  1243.      * 
  1244.      * @param DBMS_TABLE_OBJ $tblObj 
  1245.      * @param boolean $debug 
  1246.      * 
  1247.      */
  1248.     function setMyTblObj(&$tblObj,$debug=False)
  1249.     {
  1250.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::setMyTblObj(".get_class($tblObj).")");
  1251.  
  1252.         $this->myTblObj=$tblObj;
  1253.         if (method_exists($tblObj,'getClassFile'))
  1254.         {
  1255.             $this->setTblObjClass(get_class($tblObj));
  1256.             $this->setTblObjInc($tblObj->getClassFile(False,$debug));
  1257.         else if (method_exists($tblObj,'get_mySourceFile')) {
  1258.             $str_srcFile=$tblObj->get_mySourceFile();
  1259.             if (stristr($str_srcFile,get_class($tblObj)))
  1260.             {
  1261.                 $this->setTblObjClass(get_class($tblObj));
  1262.                 $this->setTblObjInc($str_srcFile);    
  1263.             }
  1264.         else if ($debug{
  1265.             echoDebugLine(__FILE__,__LINE__,"method: " get_class($tblObj"::getClassFile()" " not found")
  1266.         }
  1267.     }
  1268.  
  1269.     /**
  1270.       * @param boolean $force (if False only $this->myTblObj is returned else it tries to instantiate a new object)
  1271.       * @param boolean $debug 
  1272.       *
  1273.       * @return DBMS_TABLEOBJ 
  1274.       *
  1275.       * @requires common/pcf_templates.phpinc
  1276.       */
  1277.     function &getMyTblObj($force=False,$debug=False)
  1278.     {
  1279.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getMyTblObj()","myTblObj: ".get_class($this->myTblObj));
  1280.  
  1281.         if (pcf_is_instance_of($this->myTblObj,'DBMS_TABLEOBJ'))
  1282.         {
  1283.             if ($debugechoDebugLine(__FILE__,__LINE__,"Returning existing Object");
  1284.             return $this->myTblObj;
  1285.         else if ($force && (!empty($this->tblObj_class))) {
  1286.             if ($debugechoDebugLine(__FILE__,__LINE__,"force instantiation of ".$this->tblObj_class."\n".get_class($this));
  1287.             if (!class_exists($this->tblObj_class))
  1288.             {
  1289.                 if (strstr($this->tblObj_include,"\$"))
  1290.                 {
  1291.                     require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  1292.                     $str_incFile=pcf_tmpl_parse($this->tblObj_include);
  1293.                 else {
  1294.                     $str_incFile=$this->tblObj_include;
  1295.                 }
  1296.                 if (file_exists($str_incFile))
  1297.                 {
  1298.                     require_once $str_incFile;
  1299.  
  1300.                 else {
  1301.                     ocsp_logError(__FILE__,__LINE__,"could not load source for " $this->tblObj_class "(" $str_incFile ")"E_WARNING);
  1302.                     return $this->myTblObj;
  1303.                 }
  1304.             }
  1305.             $str_cmd="\$this->myTblObj=new ".$this->tblObj_class."();";
  1306.             if ($debug)
  1307.             {
  1308.                 echoDebugLine(__FILE__,__LINE__,"tblobj command$str_cmd <br />Include".$str_incFile);
  1309.                 eval($str_cmd);
  1310.             else {
  1311.                 @eval($str_cmd);
  1312.             }
  1313.             if (!pcf_is_instance_of($this->myTblObj,$this->tblObj_class))
  1314.             {
  1315.                 ocsp_logError(__FILE__,__LINE__,"could not eval cmd: ".$str_cmd,E_ERROR);
  1316.                 $this->myTblObj=NULL;
  1317.             }
  1318.         }
  1319.  
  1320.         return $this->myTblObj;
  1321.     }
  1322.  
  1323.     /**
  1324.       * @param string $incFile 
  1325.       */
  1326.     function setTblObjInc($incFile,$debug=False)
  1327.     {
  1328.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::setTblObjInc(" $incFile ")");
  1329.         $this->tblObj_include=$incFile;
  1330.     }
  1331.  
  1332.     /**
  1333.       * returns the include file for the table object class
  1334.       *
  1335.       * @param boolean $debug 
  1336.       *
  1337.       * @return string 
  1338.       */
  1339.     function getTblObjInc($debug=False)
  1340.     {
  1341.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getTblObjInc()","tblObj: ".get_class($this->myTblObj));
  1342.         if (empty($this->tblObj_include&& is_object($this->myTblObj))        
  1343.         {
  1344.             if (method_exists($this->myTblObj,'getClassInclude'))
  1345.             {
  1346.                 $this->tblObj_include=$this->myTblObj->getClassInclude($debug);
  1347.             else if ($str_inc constant(get_class($this->myTblObj).'::CLASS_SRC_FILE')) {
  1348.                 $this->tblObj_include $str_inc;
  1349.             }
  1350.         }
  1351.         if ($debugechoDebugLine(__FILE__,__LINE__,get_class($this->myTblObj." include: " $this->tblObj_include);
  1352.         return $this->tblObj_include;
  1353.     }
  1354.     
  1355.     /**
  1356.       * @param string $className 
  1357.       */
  1358.     function setTblObjClass($className,$debug=False)
  1359.     {
  1360.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::setTblObjClass(" $className ")");
  1361.         $this->tblObj_class=$className;
  1362.     }
  1363.     
  1364.  
  1365.     /**
  1366.       * @return string 
  1367.       */
  1368.     function getTblObjClass()
  1369.     {
  1370.         return $this->tblObj_class;
  1371.     }
  1372.  
  1373.     // ------------------------------------------------------
  1374.     // form global commands / actions
  1375.     // ------------------------------------------------------    
  1376.     
  1377.     /**
  1378.      * get main commands of the form
  1379.      * 
  1380.      * used keywords:
  1381.      * - js: execute a java script
  1382.      * - default: open url
  1383.      * 
  1384.      * @param int $mode 
  1385.      * @param string $type ([ACTION|NEXT|RELOAD])
  1386.      *
  1387.      * @return string 
  1388.      */
  1389.     public function getSubmitAction($mode,$type='ACTION')
  1390.     {
  1391.         if (isset($this->submitActions[$type][$mode]))
  1392.         {
  1393.             return $this->submitActions[$type][$mode];
  1394.         else {
  1395.             return NULL;
  1396.         }
  1397.     }
  1398.  
  1399.     /**
  1400.      * sets a main cmmonad of the form
  1401.      * 
  1402.      * used keywords:
  1403.      * - js: execute a java script
  1404.      * - default: open url
  1405.      *  
  1406.      * @param int $mode 
  1407.      * @param string $uri 
  1408.      * @param string $type ([ACTION|NEXT|RELOAD])
  1409.      *
  1410.      * @return string 
  1411.      * 
  1412.      */
  1413.     public function setSubmitAction($mode,$uri,$type='ACTION')
  1414.     {
  1415.         return $this->submitActions[$type][$mode]=$uri;
  1416.     }    
  1417.     
  1418.     
  1419.     public function setAjaxDisableChangeForm($to)
  1420.     {
  1421.         $this->FRM_DISABLEAJAXCHANGEFORM intval($to)
  1422.     }
  1423.     
  1424.     /**
  1425.       * @return int 
  1426.       * @since pk-05-11-04
  1427.       ***/
  1428.     function getFrmMode({
  1429.         return $this->frmMode;
  1430.     }
  1431.  
  1432.     /**
  1433.       * @param int $mode 
  1434.       * @since pk-05-11-04
  1435.       ***/
  1436.     function setFrmMode($mode{
  1437.         $this->frmMode=intval($mode);
  1438.     }
  1439.  
  1440.  
  1441.     /**
  1442.       * @return array (the unserialized value of FRM_JOIN)
  1443.       */
  1444.     function getJoinCols()
  1445.     {
  1446.         if (!empty($this->FRM_JOIN)) {
  1447.             return unserialize($this->FRM_JOIN);
  1448.         else {
  1449.             return array();
  1450.         }
  1451.     }
  1452.  
  1453.  
  1454.     /**
  1455.       * returns the language string
  1456.       *
  1457.       * @param string $txt 
  1458.       * @param string $lang 
  1459.       *
  1460.       * @return string 
  1461.       *
  1462.       * @todo OCSP_FORM::getLangTxt() currently only DE is supported
  1463.       */
  1464.     function getLangTxt($txt,$lang="DE")
  1465.     {
  1466.         if (isset($GLOBALS['OCSP_FRMLANG']['DE'][$txt]))
  1467.         {
  1468.             return $GLOBALS['OCSP_FRMLANG']['DE'][$txt];
  1469.         else {
  1470.             return $txt;
  1471.         }
  1472.     }
  1473.  
  1474.  
  1475.     /*** ------------------------------------------------------------------------------------------- */
  1476.     // form db methods
  1477.     /*** ------------------------------------------------------------------------------------------- */
  1478.  
  1479.     /**
  1480.       * @param array $aRow 
  1481.       * @param boolean $debug 
  1482.       */
  1483.     function setMyDBRow($aRow,$debug=False)
  1484.     {
  1485.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::setMyDBRow()","<pre>".print_r($aRow,True)."</pre>");
  1486.         foreach($this->myFormDBCols as $str_col)
  1487.         {
  1488.             if (isset($aRow[$str_col]))
  1489.             {
  1490.                 $this->{$str_col}=$aRow[$str_col];
  1491.             else {
  1492.                 $this->{$str_col}=NULL;
  1493.             }
  1494.         }
  1495.  
  1496.         if (isset($aRow['FRM_TABLES']))
  1497.         {
  1498.             $this->myTables=explode(' ',$aRow['FRM_TABLES']);
  1499.         }
  1500.  
  1501.         if (isset($aRow['FRM_LAYOUT']&& !empty($aRow['FRM_LAYOUT']))
  1502.         {
  1503.             $this->layoutFields=unserialize(base64_decode($aRow['FRM_LAYOUT']));
  1504.         }
  1505.  
  1506.         if (isset($aRow['FRM_SUBMITACTION']&& (!empty($aRow['FRM_SUBMITACTION'])))
  1507.         {
  1508.             $this->submitActions=unserialize(base64_decode($aRow['FRM_SUBMITACTION']));
  1509.         }
  1510.  
  1511.         if (isset($aRow['FRM_SRCVERSION']&& (intval($aRow['FRM_SRCVERSION']4))
  1512.         {
  1513.             // update form
  1514.             if (isset($aRow['FRM_LNK_AFTERINSERT']&& (!empty($aRow['FRM_LNK_AFTERINSERT'])) && ($aRow['FRM_LNK_AFTERINSERT'!= "index.php"))
  1515.             {
  1516.                 $this->submitActions['AFTER']['FRM_MODE_NEW']=$aRow['FRM_LNK_AFTERINSERT'];
  1517.             }
  1518.             if (isset($aRow['FRM_LNK_AFTEREDIT']&& (!empty($aRow['FRM_LNK_AFTEREDIT'])) && ($aRow['FRM_LNK_AFTEREDIT'!= "index.php"))
  1519.             {
  1520.                 $this->submitActions['AFTER']['FRM_MODE_EDIT']=$aRow['FRM_LNK_AFTEREDIT'];
  1521.             }
  1522.             if (isset($aRow['FRM_LNK_AFTERDELETE']&& (!empty($aRow['FRM_LNK_AFTERDELETE'])) && ($aRow['FRM_LNK_AFTERDELETE'!= "index.php"))
  1523.             {
  1524.                 $this->submitActions['AFTER']['FRM_MODE_DELETE']=$aRow['FRM_LNK_AFTERDELETE'];
  1525.             }
  1526.         }
  1527.  
  1528.         if (intval($this->myInstanceId))
  1529.         {
  1530.             OCSP_FORM::$form_instances[$this->myInstanceId]['frmId']    =$this->FRM_ID;
  1531.             OCSP_FORM::$form_instances[$this->myInstanceId]['frmName']  =$this->FRM_NAME;
  1532.             OCSP_FORM::$form_instances[$this->myInstanceId]['class']    =get_class($this);
  1533.         }
  1534.         $this->myFormValuesAreSet=True;
  1535.     }
  1536.  
  1537.     /**
  1538.       * @param boolean $debug 
  1539.       *
  1540.       * @return array() 
  1541.       */
  1542.     function getMyDBRow($debug=False{
  1543.         foreach($this->myFormDBCols as $str_col{
  1544.             if (isset($this->{$str_col}))
  1545.             {
  1546.                 $arr_dbRow[$str_col]=$this->{$str_col};
  1547.             else {
  1548.                 $arr_dbRow[$str_col]=NULL;
  1549.             }
  1550.         }
  1551.  
  1552.         if (sizeof($this->layoutFields))
  1553.         {
  1554.             $arr_dbRow['FRM_LAYOUT'base64_encode(serialize($this->layoutFields));
  1555.         else {
  1556.             $arr_dbRow['FRM_LAYOUT'NULL;
  1557.         }
  1558.  
  1559.         if (is_array($this->myTables))
  1560.         {
  1561.             $arr_dbRow['FRM_TABLES']=implode(' ',$this->myTables);
  1562.         else {
  1563.             $arr_dbRow['FRM_TABLES']=$this->getMasterTable();
  1564.         }
  1565.  
  1566.         if (!isset($arr_objVals['FRM_CLASS']))
  1567.         {
  1568.             $arr_dbRow['FRM_CLASS']=get_class($this);
  1569.         }
  1570.  
  1571.         if (sizeof($this->submitActions))
  1572.         {
  1573.             $arr_dbRow['FRM_SUBMITACTION']=base64_encode(serialize($this->submitActions));
  1574.         else {
  1575.             $arr_dbRow['FRM_SUBMITACTION']=NULL;
  1576.         }
  1577.  
  1578.         $arr_dbRow['FRM_SRCVERSION']=4;
  1579.         return $arr_dbRow;
  1580.  
  1581.     }
  1582.  
  1583.     // loading form
  1584.  
  1585.     /**
  1586.       * returns a new form form the database
  1587.       *
  1588.       * @global OCSP_FORM $OCSP_OBJ['FORMS']['BYID'][$o_tmp->getId()] used for memory cache of the form
  1589.       * @global OCSP_FORM $OCSP_OBJ['FORMS']['BYNAME'][$o_tmp->getName()] used for memory cache of the form
  1590.       *
  1591.       * @param int $aId 
  1592.       * @param string $aName 
  1593.       * @param boolean $debug 
  1594.       * @param float $revision 
  1595.       *
  1596.       * @global $OCSP_OBJ 
  1597.       *
  1598.       * @return OSCP_FORM_BASIC 
  1599.       * @access public
  1600.       *
  1601.       * @todo load revision
  1602.       */
  1603.     function &loadFromDb($aId=0,$aName="",$revision=0.0,$debug)
  1604.     {
  1605.         global $OCSP_OBJ;
  1606.  
  1607.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::loadFromDb($aId,$aName,$revision)");
  1608.         $this->getDBObj($debug)// to ensure we have a db connection
  1609.  
  1610.         $arr_Data=array();
  1611.         if (intval($aId)) {
  1612.             $arr_Data=$this->myDBObj->getArray("T_DBMS_FORM",array('FRM_ID' => intval($aId)),0,1,NULL,$debug);
  1613.         }
  1614.         if (!sizeof($arr_Data&& (!empty($aName)))
  1615.         {
  1616.             $arr_Data=$this->myDBObj->getArray("T_DBMS_FORM",array('FRM_NAME' => $aName),0,1,NULL,$debug);
  1617.         }
  1618.  
  1619.         if (sizeof($arr_Data))
  1620.         {
  1621.             $o_tmp=&$this;
  1622.  
  1623.             if (!empty($arr_Data['FRM_CLASS']))
  1624.             {
  1625.                 self::castObj($o_tmp,$arr_Data['FRM_CLASS']);
  1626.             }
  1627.  
  1628.             $o_tmp->setMyDBRow($arr_Data,$debug);
  1629.             $o_tmp->writeToFileCache($debug);
  1630.         else {
  1631.             if (isset(OCSP_FORM::$form_instances[$this->myInstanceId]))
  1632.             {
  1633.                 // garbage
  1634.                 unset(OCSP_FORM::$form_instances[$this->myInstanceId]);
  1635.                 $this->myInstanceId=0;
  1636.             }
  1637.             $o_tmp=NULL;
  1638.         }
  1639.         return $o_tmp;
  1640.     }
  1641.  
  1642.     /**
  1643.       * deletes a form and all dependencies
  1644.       * @param boolean $debug 
  1645.       *
  1646.       */
  1647.     function deleteFromDb($debug=False)
  1648.     {
  1649.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::deleteFromDb()");
  1650.  
  1651.         if ($this->getDBObj())
  1652.         {
  1653.             $str_cacheFile=self::getCacheFileName($this->getId());
  1654.             @rename($str_cacheFile,$str_cacheFile.".bak");
  1655.             $str_cacheFile=self::getCacheFileName($this->getName());
  1656.             @rename($str_cacheFile,$str_cacheFile.".bak");;
  1657.  
  1658.             $arr_delKey=array('FRM_ID'=>$this->getId());
  1659.             $this->myDBObj->deleterows('T_DBMS_FORMFIELDS',$arr_delKey);
  1660.             $this->myDBObj->deleterows('T_DBMS_FORMRIGHTS',$arr_delKey);
  1661.             $this->myDBObj->deleterows('T_DBMS_FORMBLOCKS',$arr_delKey);
  1662.             $this->myDBObj->deleterows('T_DBMS_FORM',$arr_delKey);
  1663.  
  1664.  
  1665.             return True;
  1666.         }
  1667.     }
  1668.  
  1669.  
  1670.     /**
  1671.       * stores a form object and all depending objects (blocks and fields) to the database
  1672.       *
  1673.       * @param boolean $debug 
  1674.       * @access public
  1675.       */
  1676.     function storeToDb($debug=False)
  1677.     {
  1678.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::storeToDb()");
  1679.  
  1680.         $arr_dbRow=$this->getMyDBRow($debug);
  1681.  
  1682.         if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>".print_r($arr_dbRow,True)."</pre>");
  1683.  
  1684.         $arr_dbRow['FRM_UTIMESTAMP']=time();
  1685.         if (intval($this->getId()))
  1686.         {
  1687.             if ($debugechoDebugLine(__FILE__,__LINE__,"updateing existing form");
  1688.             if (!OCSP_OBJ::defaultWriteDBObj()->replaceArray('T_DBMS_FORM',$arr_dbRow,$debug))
  1689.             {
  1690.                 ocsp_logError(__FILE__,__LINE__,"error updateing form ".$this->getId()."\n".print_r($arr_dbRow,True));
  1691.                 //return False;
  1692.                 die();
  1693.             }
  1694.         else {
  1695.             if ($debugechoDebugLine(__FILE__,__LINE__,"inserting new form");
  1696.             unset($arr_dbRow['FRM_ID']);
  1697.             if ($aId=OCSP_OBJ::defaultWriteDBObj()->insertArray('T_DBMS_FORM',$arr_dbRow,$debug,'FRM_ID'))
  1698.             {
  1699.                 if ($arr_Data=OCSP_OBJ::defaultWriteDBObj()->getArray("T_DBMS_FORM",array('FRM_ID' => intval($aId)),0,1,NULL,$debug))
  1700.                 // to also have db default values loaded
  1701.                     foreach($arr_Data as $str_col => $mix_val)
  1702.                     {
  1703.                         $this->{$str_col}=$mix_val;
  1704.                     }
  1705.                 else {
  1706.                     ocsp_logError(__FILE__,__LINE__,"error reloading inserted form");
  1707.                     return False;
  1708.                 }
  1709.             else {
  1710.                 ocsp_logError(__FILE__,__LINE__,"error inserting form");
  1711.                 return False;
  1712.             }
  1713.         }
  1714.  
  1715.         foreach($this->myBlocks as &$o_block)
  1716.         {
  1717.             $o_block->setMyForm($this);
  1718.             $o_block->storeToDb($debug);
  1719.         }
  1720.  
  1721.         $this->delCacheFiles();
  1722.         return True;
  1723.     }
  1724.     
  1725.     /*** ------------------------------------------------------------------------------------------- */
  1726.     // export / import
  1727.     /*** ------------------------------------------------------------------------------------------- */
  1728.     
  1729.     /**
  1730.      * returns the form export string (php array)
  1731.      * 
  1732.      * @return string; 
  1733.      */
  1734.     public function getExportString()
  1735.     {
  1736.         $str_ret "array(\n";
  1737.         foreach($this->myFormDBCols as $str_colName)
  1738.         {
  1739.             $str_ret .= "\t'{$str_colName}' => \"base64_encode(serialize($this->{$str_colName})) "\",\n";
  1740.         }
  1741.         
  1742.         $str_ret .= "\t'_BLOCKS' => array(\n";
  1743.         if ($arr_blocks $this->getBlocks())
  1744.         {            
  1745.             $str_tabs "\t\t\t";
  1746.             foreach($arr_blocks as &$obj_block)
  1747.             {
  1748.                 $str_ret .= "\t\t'{$obj_block->getId()}' => array(\n"
  1749.                 $str_ret .= $str_tabs "'class' => \"" get_class($obj_block"\",\n";
  1750.                 $str_ret .= $str_tabs "'src'   => \"" str_replace(__OCSP_PHPINCPATH__,"",$obj_block->get_myClassConstant('CLASS_SRC_FILE')) "\",\n";
  1751.                 $str_ret .= $str_tabs "'blockValues' => " $obj_block->getExportString();
  1752.                 $str_ret .= "\t\t), // _BLOCK {$obj_block->getId()}\n";
  1753.             }
  1754.         }
  1755.         $str_ret .= "\t), // _BLOCKS\n";
  1756.         $str_ret .= ")\n";
  1757.         return $str_ret;
  1758.     }
  1759.     
  1760.     /**
  1761.      * imports the form from an array
  1762.      * NOTE: does not save the form
  1763.      *
  1764.      * @param array $impArray 
  1765.      * @param boolean $debug 
  1766.      */
  1767.     public function importFromArray($impArray,$debug=False)
  1768.     {
  1769.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::importFromArray()");
  1770.         
  1771.         if (isset($impArray['FRM_ID'])) unset($impArray['FRM_ID']);
  1772.         foreach($this->myFormDBCols as $str_colName)
  1773.         {
  1774.             if (isset($impArray[$str_colName]&& !empty($impArray[$str_colName]))
  1775.             {
  1776.                 $this->$str_colName unserialize(base64_decode($impArray[$str_colName]));
  1777.             }
  1778.         }
  1779.         
  1780.         if ($arr_blocks $this->getBlocks())
  1781.         {
  1782.             foreach($arr_blocks as &$obj_block)
  1783.             {
  1784.                 if (intval($obj_block->getId()))
  1785.                 {
  1786.                     $this->deleteBlock($obj_block->getId(),$debug);    
  1787.                 }
  1788.             }
  1789.         }
  1790.         
  1791.         $this->myBlocks array();
  1792.         $int_idx 0;
  1793.         if ($debugechoDebugLine(__FILE__,__LINE__,"importing " sizeof($impArray['_BLOCKS']" blocks");
  1794.         foreach($impArray['_BLOCKS'as $arr_block)
  1795.         {
  1796.             pcf_require_class($arr_block['class'],$arr_block['src']);
  1797.             $this->myBlocks[$int_idxnew $arr_block['class']($this);
  1798.             $this->myBlocks[$int_idx]->importFromArray($arr_block['blockValues'],$debug);
  1799.                         
  1800.             $int_idx++;
  1801.         }
  1802.         
  1803.     }
  1804.     
  1805.     /*** ------------------------------------------------------------------------------------------- */
  1806.     // form cache methods
  1807.     /*** ------------------------------------------------------------------------------------------- */
  1808.  
  1809.     /**
  1810.       * deletes the form cache files
  1811.       */
  1812.     function delCacheFiles()
  1813.     {
  1814.         @unlink(self::getCacheFileName($this->getId()));
  1815.         @unlink(self::getCacheFileName($this->getName()));
  1816.     }
  1817.  
  1818.     /**
  1819.       * returns a new form from the file cache
  1820.       *
  1821.       * @global OCSP_FORM $OCSP_OBJ['FORMS']['BYID'][$o_tmp->getId()] used for memory cache of the form
  1822.       * @global OCSP_FORM $OCSP_OBJ['FORMS']['BYNAME'][$o_tmp->getName()] used for memory cache of the form
  1823.       *
  1824.       * @param int $aId 
  1825.       * @param string $aName 
  1826.       * @param boolean $debug 
  1827.       * @param float $revision 
  1828.       *
  1829.       * @global $OCSP_OBJ 
  1830.       *
  1831.       * @return OCSP_FORM 
  1832.       *
  1833.       * @access protected
  1834.       *
  1835.       * @requires pcf_templates.phpinc
  1836.       *
  1837.       */
  1838.     protected function loadFromFileCache($aId=0,$aName="",$revision,$debug)
  1839.     {
  1840.         global $OCSP_OBJ;
  1841.  
  1842.         if ($debugechoDebugMethod(__FILE__,get_class($this),"loadFromFileCache($aId,$aName,$revision)");
  1843.  
  1844.         $obj_ret=NULL;
  1845.         $str_cacheDir OCSP_OBJ::getConf('OBJCACHEPATH')
  1846.         if (!empty($str_cacheDir)) {
  1847.             $str_cacheDir .="form_cache" _OCSP_DIRSEP_;
  1848.             if (intval($aId&& file_exists($str_cacheDir.$aId.".frm.cache"))
  1849.             {
  1850.                 if ($debug)
  1851.                 {
  1852.                     echoDebugLine(__FILE__,__LINE__,"including ".$str_cacheDir.$aId.".frm.cache");
  1853.                     include $str_cacheDir.$aId.".frm.cache";
  1854.                 else {
  1855.                     @include $str_cacheDir.$aId.".frm.cache";
  1856.                 }
  1857.             else if (!empty($aName&& file_exists($str_cacheDir.$aName.".frm.cache")) {
  1858.                 if ($debug)
  1859.                 {
  1860.                     echoDebugLine(__FILE__,__LINE__,"including ".$str_cacheDir.$aName.".frm.cache");
  1861.                     include $str_cacheDir.$aName.".frm.cache";
  1862.                 else {
  1863.                     @include $str_cacheDir.$aName.".frm.cache";
  1864.                 }
  1865.             else {
  1866.                 if ($debugechoDebugLine(__FILE__,__LINE__,"no cache File<br />".$str_cacheDir.$aId.".frm.cache");
  1867.                 return $obj_ret;
  1868.             }
  1869.  
  1870.             if ($arr_cache['CACHETS'time($GLOBALS['OCSP']['OBJCACHELIFETIME'])
  1871.             // cache is expired
  1872.                 return $obj_ret;
  1873.             }
  1874.  
  1875.             // check the object class
  1876.             if (!pcf_is_instance_of($frmObj,$arr_cache['FRM_CLASS']))
  1877.             {
  1878.                 if (!class_exists($arr_cache['FRM_CLASS']))
  1879.                 {
  1880.                     require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  1881.                     $str_incFile=pcf_tmpl_parse($arr_cache['FRM_CLASSSRC']);
  1882.                     if (file_exists($str_incFile))
  1883.                     {
  1884.                         require_once $str_incFile;
  1885.                     else if (file_exists(dirname(__FILE__)."/".$arr_cache['FRM_CLASS'].".phpclass")) {
  1886.                         require_once dirname(__FILE__)."/".$arr_cache['FRM_CLASS'].".phpclass";
  1887.                     else {
  1888.                         ocsp_logError(__FILE__,__LINE__,"form class ".$arr_cache['FRM_CLASS']." not loaded");
  1889.                         return $obj_ret;
  1890.                     }
  1891.                 }
  1892.                 if ($debug)
  1893.                 {
  1894.                     eval("\$o_tmp=new ".$arr_cache['FRM_CLASS']."();");
  1895.                 else {
  1896.                     @eval("\$o_tmp=new ".$arr_cache['FRM_CLASS']."();");
  1897.                 }
  1898.                 if (!pcf_is_instance_of($o_tmp,$arr_cache['FRM_CLASS']))
  1899.                 {
  1900.                         ocsp_logError(__FILE__,__LINE__,"form object (class: ".$arr_cache['FRM_CLASS'].") not instantiated");
  1901.                         return False;
  1902.                 }
  1903.                 $o_tmp->setMyDBRow($arr_cache['dbRow']);
  1904.  
  1905.                 if (!isset($OCSP_OBJ['FORMS']['BYID'][$o_tmp->getId()]))
  1906.                 {
  1907.                     $OCSP_OBJ['FORMS']['BYID'][$o_tmp->getId()]=$o_tmp;
  1908.                     $OCSP_OBJ['BYNAME'][$o_tmp->getName()]=&$OCSP_OBJ['FORMS']['BYID'][$o_tmp->getId()];
  1909.                     return $OCSP_OBJ['FORMS']['BYID'][$o_tmp->getId()];
  1910.                 }
  1911.  
  1912.                 return $o_tmp;
  1913.             }
  1914.         }
  1915.     }
  1916.  
  1917.     /**
  1918.       * writes the object to the file cache
  1919.       *
  1920.       * @param boolean $debug 
  1921.       *
  1922.       * @global $OCSP_CONF 
  1923.       *
  1924.       * @access protected
  1925.       *
  1926.       * @requires pcf_directory.phpinc
  1927.       */
  1928.     protected function writeToFileCache($debug)
  1929.     {
  1930.         global $OCSP_CONF;
  1931.  
  1932.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::writeToFileCache()");
  1933.         $str_cacheFile=OCSP_FORM::getCacheFileName($this->getId());
  1934.  
  1935.         $str_eol="\n";
  1936.  
  1937.         require_once __OCSP_PHPINCPATH__."common/pcf_directory.phpinc";
  1938.         if (!pcf_checkDir(dirname($str_cacheFile),True,0770,$debug))
  1939.         {
  1940.             ocsp_logError(__FILE__,__LINE__,"could not create cachedir: " dirname($str_cacheFile),E_WARNING);
  1941.             return False;
  1942.         }
  1943.  
  1944.         if ($h_file=fopen($str_cacheFile,'w'))
  1945.         {
  1946.             fwrite($h_file,"<?php\n");
  1947.             fwrite($h_file,"\$arr_cache=array($str_eol");
  1948.             fwrite($h_file,"'FRM_CLASS'=>\"".get_class($this)."\",$str_eol");
  1949.             if (strstr($this->get_mySourceFile(),__OCSP_PHPINCPATH__))
  1950.             {
  1951.                 fwrite($h_file,"'FRM_CLASSSRC'=>\"".str_replace(__OCSP_PHPINCPATH__,"\\\$@OCSP|PHPINCPATH\\\$",$this->get_mySourceFile())."\",$str_eol");
  1952.             else if (strstr($this->get_mySourceFile(),$OCSP_CONF['PROJECTPATH'])) {
  1953.                 fwrite($h_file,"'FRM_CLASSSRC'=>\"".str_replace($OCSP_CONF['PROJECTPATH'],"\\\$@OCSP|PROJECTPATH\\\$",$this->get_mySourceFile())."\",$str_eol");
  1954.             else {
  1955.                 fwrite($h_file,"'FRM_CLASSSRC'=>\"".$this->get_mySourceFile()."\",$str_eol");
  1956.             }
  1957.  
  1958.             $arr_dbRow=$this->getMyDBRow($debug);
  1959.             fwrite($h_file,"'dbRow'=>unserialize(base64_decode(\"".base64_encode(serialize($arr_dbRow))."\")),$str_eol");
  1960.  
  1961.             fwrite($h_file,"\n// ----------------------------- blocks ---------------------------- \n");
  1962.             fwrite($h_file,"'arr_blocks'=>array($str_eol");
  1963.             $arr_blocks=$this->getBlocks($debug);
  1964.             foreach($arr_blocks as &$obj_block)
  1965.             {
  1966.                 $obj_block->writeToFileCache($h_file,$debug);
  1967.             }
  1968.             fwrite($h_file,"),$str_eol");
  1969.  
  1970.             fwrite($h_file,"'CACHETS'=>doubleval(".time().")$str_eol");
  1971.             fwrite($h_file,");\n");
  1972.             fwrite($h_file,"?>");
  1973.             fclose($h_file);
  1974.             @symlink($str_cacheFile,self::getCacheFileName($this->getName()));
  1975.         else {
  1976.             if ($debugechoDebugLine(__FILE__,__LINE__,"could not open cachefile: <br />".$str_cacheDir."/".$this->getId().".frm.cache");
  1977.         }
  1978.  
  1979.     }
  1980.  
  1981.     /**
  1982.       * @param boolean $debug 
  1983.       * @see OCSP_FORM::writeFieldDescToCache()
  1984.       *
  1985.       * @deprecated since pk-08-06-13
  1986.       */
  1987.     function loadFieldDescFromCache($debug=False)
  1988.     {
  1989.         OCSP_FORM::loadFieldClassDesc();
  1990.     }
  1991.  
  1992.     /**
  1993.       * writes field definition array (T_DBMS_FIELDDESC) to the cache
  1994.       * and populated
  1995.       * - $GLOBALS['DBMS_FIELD_CLASSES']
  1996.       * - $GLOBALS['DBMS_FIELD_DESC']
  1997.       *
  1998.       * @param boolen $debug 
  1999.       *
  2000.       * @deprecated since pk-08-06-13
  2001.       * 
  2002.       */
  2003.     function writeFieldDescToCache($debug=False)
  2004.     {
  2005.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::writeFieldDescToCache()");
  2006.  
  2007.         OCSP_FORM::writeFieldClassDescToCache($debug);
  2008.     }
  2009.  
  2010.     /*** ------------------------------------------------------------------------------------------- */
  2011.     // table methods
  2012.     /*** ------------------------------------------------------------------------------------------- */
  2013.  
  2014.     /**
  2015.       * @return string 
  2016.       * @access public
  2017.       */
  2018.     function getMasterTable()
  2019.     {
  2020.         if (pcf_is_instance_of($this->myTblObj,'DBMS_TABLEOBJ'))
  2021.         {
  2022.             return $this->myTblObj->getMyTable();
  2023.         }
  2024.  
  2025.         if (isset($this->myTables[0]&& !empty($this->myTables[0]))
  2026.         {
  2027.             return $this->myTables[0];
  2028.         }
  2029.  
  2030.  
  2031.         if (strstr(trim($this->FRM_TABLES)," "))
  2032.         {
  2033.             $this->myTables=explode(" ",trim($this->FRM_TABLES));
  2034.             return $this->myTables[0];
  2035.         }
  2036.  
  2037.         if (!strstr($this->FRM_TABLES,","))
  2038.         {
  2039.             return $this->FRM_TABLES;
  2040.         else {
  2041.             return "";
  2042.         }
  2043.     }
  2044.     
  2045.     function setMasterTable($aTbl)
  2046.     {
  2047.         $this->getTables()// ensure $this->myTables is set
  2048.         if (is_array($this->myTables))
  2049.         {
  2050.             $arr_tmp=array($aTbl);
  2051.             foreach($this->myTables as $str_tbl)
  2052.             {
  2053.                 if ($str_tbl != $aTbl$arr_tmp[]=$str_tbl;
  2054.             }
  2055.             $this->myTables=$arr_tmp;
  2056.             
  2057.             $this->FRM_TABLES=implode(' ',$this->myTables);
  2058.         }
  2059.     }
  2060.  
  2061.     /**
  2062.       * @return array 
  2063.       * @access public
  2064.       */
  2065.     function getTables()
  2066.     {
  2067.         if (empty($this->FRM_TABLES&& (!sizeof($this->FRM_TABLES)))
  2068.         {
  2069.             return array();
  2070.         }
  2071.  
  2072.         if (!sizeof($this->myTables))
  2073.         {
  2074.             $this->myTables=explode(',',$this->FRM_TABLES);
  2075.         }
  2076.         return $this->myTables;
  2077.     }
  2078.  
  2079.  
  2080.     /**
  2081.       * adds a table to the form
  2082.       *
  2083.       * @param string $aTable 
  2084.       * @param int $aBlockId 
  2085.       * @param boolean $debug 
  2086.       *
  2087.       * @return boolean 
  2088.       */
  2089.     function addTable($aTable,$aBlockId=0,$debug=False)
  2090.     {
  2091.         if ($debugechoDebugMethod(__FILE__,get_class($this),"addTable($aTable)");
  2092.  
  2093.         if (!$obj_block=$this->getBlock($aBlockId))
  2094.         {
  2095.             ocsp_logError(__FILE__,__LINE__,"Block $aBlockId not found in form");
  2096.             return False;
  2097.         }
  2098.  
  2099.         if ($obj_block->addTable($aTable,$debug))
  2100.         {
  2101.             $this->registerTable($aTable);
  2102.             return True;
  2103.         else {
  2104.             return False;
  2105.         }
  2106.     }
  2107.     
  2108.     /**
  2109.      * register a table for use with the form
  2110.      * 
  2111.      * unlicke add table the columns are not loaded
  2112.      * 
  2113.      * @param string $aTable 
  2114.      * 
  2115.      * @since pk-08-10-31
  2116.      */
  2117.     public function registerTable($aTable)
  2118.     {
  2119.         if (!in_array($aTable,$this->myTables))
  2120.         {
  2121.             $this->myTables[]=$aTable;
  2122.         }
  2123.     }
  2124.  
  2125.     
  2126.     /**
  2127.      * removes a table an all table columns from the form
  2128.      * 
  2129.      * @param string $aTable 
  2130.      * @param boolean $debug 
  2131.      * 
  2132.      */
  2133.     function removeTable($aTable,$debug=False)
  2134.     {
  2135.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::removeTable($aTable)");
  2136.  
  2137.         if (!empty($aTable))
  2138.         {
  2139.             $this->getTables();
  2140.             if ($arr_flds=$this->getFields($aTable,$debug))
  2141.             {
  2142.                 foreach($arr_flds as &$obj_fld)
  2143.                 {
  2144.                     $this->deleteField($obj_fld->getKey());
  2145.                 }
  2146.             }
  2147.             if ($i_key=array_search($aTable,$this->myTables))
  2148.             {
  2149.                 unset($this->myTables[$i_key]);
  2150.                 return True;
  2151.             }
  2152.         }
  2153.         return False;
  2154.     }
  2155.  
  2156.     /**
  2157.       * returns an array of all primary key's found in the form
  2158.       *
  2159.       * the return array has the following structure:
  2160.       * array [table][] => &fieldobj
  2161.       *
  2162.       * @param boolean $debug 
  2163.       *
  2164.       * @return array 
  2165.       *
  2166.       * @since pk-07-09-30
  2167.       */
  2168.     function getKeyFields($debug=False)
  2169.     {
  2170.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getKeyFields()");
  2171.  
  2172.         $arr_ret=array();
  2173.         if ($arr_fields=$this->getFields())
  2174.         {
  2175.             foreach ($arr_fields as &$obj_field)
  2176.             {
  2177.                 if ($obj_field->isPrimaryKey($debug))
  2178.                 {
  2179.                     $arr_ret[$obj_field->getTable()][]=$obj_field;
  2180.                 }
  2181.             }
  2182.         }
  2183.         return $arr_ret;
  2184.     }
  2185.     
  2186.     /**
  2187.      * returns the autoincrement field of $tbl
  2188.      *
  2189.      * @param string $tbl 
  2190.      * @param boolan $debug 
  2191.      * 
  2192.      * @return DBMS_FIELD 
  2193.      * 
  2194.      * @since pk-08-01-15
  2195.      * 
  2196.      */
  2197.     function &getAutoIncField($tbl,$debug=False)
  2198.     {
  2199.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getAutoIncField($tbl)");
  2200.         
  2201.         if ($arr_fields=$this->getFields($tbl,$debug))
  2202.         {
  2203.             foreach($arr_fields as &$obj_field)
  2204.             {
  2205.                 if ($obj_field->isAutoInc()) return $obj_field;
  2206.             }
  2207.         }
  2208.         
  2209.         $null=NULL;
  2210.         return $null;
  2211.     }
  2212.  
  2213.  
  2214.     /*** ------------------------------------------------------------------------------------------- */
  2215.     // block methods
  2216.     /*** ------------------------------------------------------------------------------------------- */
  2217.  
  2218.     /**
  2219.       * returns the number of blocks
  2220.       * @param boolean $debug 
  2221.       */
  2222.     function getNofBlocks($debug=False)
  2223.     {
  2224.         if (!sizeof($this->myBlocks))
  2225.         {
  2226.             $this->getBlocks($debug);
  2227.         }
  2228.         return sizeof($this->myBlocks);
  2229.     }
  2230.  
  2231.     /**
  2232.       * @param boolean $debug 
  2233.       * @return array 
  2234.       * @todo cache
  2235.       */
  2236.     function &getBlocks($debug=False)
  2237.     {
  2238.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getBlocks()");
  2239.         if (!sizeof($this->myBlocks))
  2240.         {
  2241.             $this->loadBlocksFromDb($debug);
  2242.         }
  2243.         return $this->myBlocks;
  2244.     }
  2245.  
  2246.     /**
  2247.       * @param int $blockId 
  2248.       * @param boolean $debug 
  2249.       *
  2250.       * @return OCSP_FORM_BLOCK 
  2251.       */
  2252.     function &getBlock($blockId,$debug=False)
  2253.     {
  2254.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getBlock($blockId)");
  2255.         $this->getBlocks($debug);
  2256.         foreach($this->myBlocks as &$obj_block)
  2257.         {
  2258.             if ($obj_block->getId()==$blockIdreturn $obj_block;
  2259.         }
  2260.  
  2261.         ocsp_logError(__FILE__,__LINE__,"could not load block $blockId");
  2262.         $obj_ret=NULL;
  2263.         return $obj_ret;
  2264.     }
  2265.     
  2266.     /**
  2267.      * returns the first block with $blockName as Name
  2268.      * 
  2269.      * @param string $blockName 
  2270.      * @param boolean $debug 
  2271.      * 
  2272.      * @return OCSP_FORM_BLOCK 
  2273.      * 
  2274.      * @since pk-08-01-15
  2275.      */
  2276.     function &getBlockByName($blockName,$debug=False)
  2277.     {
  2278.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getBlockByName($blockName)");
  2279.         $this->getBlocks($debug);
  2280.         foreach($this->myBlocks as &$obj_block)
  2281.         {
  2282.             if ($obj_block->getName()==$blockNamereturn $obj_block;
  2283.         }
  2284.  
  2285.         ocsp_logError(__FILE__,__LINE__,"could not load block $blockId");
  2286.         $obj_ret=NULL;
  2287.         return $obj_ret;
  2288.     }    
  2289.  
  2290.     /**
  2291.       * adds a new block to the form and returns the block
  2292.       *
  2293.       * @param string $arrName 
  2294.       * @param array $colNames 
  2295.       * @param boolean $debug 
  2296.       *
  2297.       * @return boolean 
  2298.       */
  2299.     function addNewBlockFromPost($arrName='DBVAL',$colNames=NULL,$debug=False)
  2300.     {
  2301.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::addNewBlockFromPost($arrName)",print_r($colNames,True));
  2302.  
  2303.         //
  2304.         // check post values
  2305.         //
  2306.         if (!isset($_POST[$arrName]))
  2307.         {
  2308.             ocsp_logError(__FILE__,__LINE__,"\$_POST[$arrName] is not set");
  2309.             return False;
  2310.         }
  2311.  
  2312.         $arr_Data=$_POST[$arrName];
  2313.  
  2314.         if (!isset($arr_Data['FRB_NAME']))
  2315.         {
  2316.             ocsp_logError(__FILE__,__LINE__,"\$_POST[$arrName]['FRB_NAME'] is not set");
  2317.             return False;
  2318.         }
  2319.         return $this->addNewBlock($arr_Data,$colNames,$debug);
  2320.     }
  2321.  
  2322.     /**
  2323.       * adds a new block to the form and returns the block
  2324.       *
  2325.       * @param array $blockData 
  2326.       * @param array $colNames 
  2327.       * @param boolean $debug 
  2328.       *
  2329.       * @return boolean 
  2330.       */
  2331.     function addNewBlock($blockData,$colNames=NULL,$debug=False)
  2332.     {
  2333.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::addNewBlock()");
  2334.  
  2335.         $this->getDBObj()// ensure $this->myDBObj isset
  2336.  
  2337.         $str_query ="SELECT COUNT(*) FROM T_DBMS_FORMBLOCKS ";
  2338.         $str_query.=" WHERE FRM_ID=".$this->getId();
  2339.         $str_query.="   AND UPPER(FRB_NAME)=".$this->myDBObj->qs_getSlashedValue(strtoupper(trim($blockData['FRB_NAME'])));
  2340.  
  2341.         if (intval($this->myDBObj->getOne($str_query)))
  2342.         {
  2343.             ocsp_logError(__FILE__,__LINE__,"Name: ".$blockData['FRB_NAME']." already in use");
  2344.             return False;
  2345.         }
  2346.  
  2347.         //
  2348.         // check form is populated
  2349.         //
  2350.  
  2351.         $this->getBlocks($debug)// ensure the existing blocks are loaded
  2352.  
  2353.         //
  2354.         // generate the object
  2355.         //
  2356.  
  2357.         $obj_block=new OCSP_FORM_BLOCK($this);
  2358.         $obj_block->setDBObj($this->getDBObj());
  2359.         $obj_block->setName(trim($blockData['FRB_NAME']));
  2360.  
  2361.         if (isset($arr_Data['FRB_SORTORDER']&& intval($blockData['FRB_SORTORDER']))
  2362.         {
  2363.             $str_query="UPDATE T_DBMS_FORMBLOCKS SET FRB_SORTORDER=FRB_SORTORDER+1";
  2364.             $str_query.=" WHERE FRM_ID=".$this->getId();
  2365.             $str_query.="   AND FRB_SORTORDER >= ".intval($blockData['FRB_SORTORDER']);
  2366.             $this->myDBObj->executeCmd($str_query);
  2367.             $obj_block->setOrderNr(intval($blockData['FRB_SORTORDER']));
  2368.             unset($blockData['FRB_SORTORDER']);
  2369.         else {
  2370.             $str_query="SELECT COUNT(*) FROM T_DBMS_FORMBLOCKS ";
  2371.             $str_query.=" WHERE FRM_ID=".$this->getId();
  2372.             $obj_block->setOrderNr(intval($this->myDBObj->getOne($str_query))+1);
  2373.         }
  2374.  
  2375.         $arr_showCols=$obj_block->getShowFields();
  2376.         foreach($arr_showCols as $col => $lab)
  2377.         {
  2378.             if (isset($blockData[$col]))
  2379.             {
  2380.                 if (!empty($blockData[$col]))
  2381.                 {
  2382.                     $obj_block->setMyDBColValue($col,True);
  2383.                 else {
  2384.                     $obj_block->setMyDBColValue($col,False);
  2385.                 }
  2386.                 unset($blockData[$col]);
  2387.             else {
  2388.                 $obj_block->setMyDBColValue($col,False);
  2389.             }
  2390.         }
  2391.  
  2392.         foreach($blockData as $col => $val)
  2393.         {
  2394.             $obj_block->setMyDBColValue($col,$val);
  2395.         }
  2396.  
  2397.         $obj_block->storeToDb($debug)// to have an id
  2398.         if (intval($obj_block->getId()))
  2399.         {
  2400.             $this->myBlocks[]=&$obj_block;
  2401.             if (is_array($colNames))
  2402.             {
  2403.                 foreach($colNames as $str_colName)
  2404.                 {
  2405.                     if ($obj_field=$this->getField($str_colName))
  2406.                     {
  2407.                         $obj_block->addFieldObj($obj_field,$debug);
  2408.                     else {
  2409.                         ocsp_logError(__FILE__,__LINE__,"Field: ".$str_colName." not found");
  2410.                     }
  2411.                 }
  2412.             }
  2413.             $this->storeToDb($debug);
  2414.             $this->loadBlocksFromDb($debug);
  2415.             return True;
  2416.         else {
  2417.             ocsp_logError(__FILE__,__LINE__,"OCSP_FORM::addNewBlockFromPost()".$this->myDBObj->errorMsg('could not store block'));
  2418.             return False;
  2419.         }
  2420.     }
  2421.  
  2422.     /**
  2423.       * link a block from an other form
  2424.       *
  2425.       * @param int $blockId 
  2426.       * @param boolean $debug 
  2427.       *
  2428.       * @return boolean 
  2429.       *
  2430.       * @todo OCSP_FORM::linkBlock() inline SQL
  2431.       */
  2432.     function linkBlock($blockId,$debug=False)
  2433.     {
  2434.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::linkBlock($blockId)");
  2435.  
  2436.         $this->getBlocks($debug)// ensure the existing blocks are loaded
  2437.  
  2438.         $str_query="SELECT * FROM T_DBMS_FORMBLOCKS WHERE FRB_ID=".intval($blockId);
  2439.         if ($debugechoDebugLine(__FILE__,__LINE__,"loading Block$str_query");
  2440.         if ($arr_blockData=$this->myDBObj->quickQuery($str_query))
  2441.         {
  2442.             if ($objFromForm=OCSP_FORM::factory_from_id($arr_blockData['FRM_ID']))
  2443.             {
  2444.                 $objFromBlock=OCSP_FORM_BLOCK::getBlockObjFromRow($objFromForm,$arr_blockData,$debug);
  2445.                 $objFromBlock->setDBObj($this->myDBObj);
  2446.  
  2447.                 unset($arr_blockData['FRB_ID']);
  2448.                 $arr_blockData['FRM_ID']=$this->getId();
  2449.                 $arr_blockData['FRB_ORIG_FRB_ID']=$objFromBlock->getId();
  2450.                 $arr_blockData['FRB_ORIG_FRM_ID']=$objFromForm->getId();
  2451.  
  2452.                 if ($arr_blockData['FRB_ID']=$this->myDBObj->insertArray('T_DBMS_FORMBLOCKS',$arr_blockData))
  2453.                 {
  2454.                     $obj_newBlock=OCSP_FORM_BLOCK::getBlockObjFromRow($this,$arr_blockData,$debug);
  2455.  
  2456.                     $arr_fields=$objFromBlock->getFields(-1,$debug);
  2457.                     foreach($arr_fields as $objField)
  2458.                     {
  2459.                         if ($obj_frmField=$this->getField($objField->getKey()))
  2460.                         {
  2461.                             if ($debugechoDebugLine(__FILE__,__LINE__,"<p>".$objField->getKey()." in form</p>");
  2462.                             //$obj_newBlock->addFieldObj($obj_frmField,$debug);
  2463.                             if ($obj_oldBlock=$obj_frmField->getMyBlock())
  2464.                             {
  2465.                                 $obj_oldBlock->removeFieldObj($obj_frmField,$debug);
  2466.                             }
  2467.                             $obj_newBlock->storeFldToDb($obj_frmField,$debug,True);
  2468.                         }
  2469.                     }
  2470.                     $this->delCacheFiles();
  2471.                     $this->loadBlocksFromDb($debug);
  2472.                     return True;
  2473.                 }
  2474.             else {
  2475.  
  2476.                 return False;
  2477.             }
  2478.         else if ($debug{
  2479.             ocsp_logError(__FILE__,__LINE__,"could not load block with id$blockId",E_WARNING);
  2480.             return False;
  2481.         }
  2482.  
  2483.     }
  2484.  
  2485.  
  2486.     /**
  2487.       * link a block from an other form
  2488.       *
  2489.       * @param int $blockId 
  2490.       * @param boolean $debug 
  2491.       *
  2492.       * @return boolean 
  2493.       *
  2494.       * @todo OCSP_FORM::linkBlock() inline SQL
  2495.       */
  2496.     function copyBlock($blockId,$debug=False)
  2497.     {
  2498.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::linkBlock($blockId)");
  2499.  
  2500.         $this->getBlocks($debug)// ensure the existing blocks are loaded
  2501.  
  2502.         $str_query="SELECT * FROM T_DBMS_FORMBLOCKS WHERE FRB_ID=".intval($blockId);
  2503.         if ($debugechoDebugLine(__FILE__,__LINE__,"loading Block$str_query");
  2504.         if ($arr_blockData=$this->myDBObj->quickQuery($str_query))
  2505.         {
  2506.             if ($objFromForm=OCSP_FORM::factory_from_id($arr_blockData['FRM_ID']))
  2507.             {
  2508.                 $objFromBlock=OCSP_FORM_BLOCK::getBlockObjFromRow($objFromForm,$arr_blockData,$debug);
  2509.                 $objFromBlock->setDBObj($this->myDBObj);
  2510.  
  2511.                 unset($arr_blockData['FRB_ID']);
  2512.                 $arr_blockData['FRM_ID']=$this->getId();
  2513.                 $arr_blockData['FRB_ORIG_FRB_ID']=0;
  2514.                 $arr_blockData['FRB_ORIG_FRM_ID']=0;
  2515.  
  2516.                 if ($arr_blockData['FRB_ID']=$this->myDBObj->insertArray('T_DBMS_FORMBLOCKS',$arr_blockData))
  2517.                 {
  2518.                     $obj_newBlock=OCSP_FORM_BLOCK::getBlockObjFromRow($this,$arr_blockData,$debug);
  2519.  
  2520.                     $arr_fields=$objFromBlock->getFields(-1,$debug);
  2521.                     $obj_blockNull=NULL;
  2522.                     
  2523.                     $arr_tables $this->getTables();
  2524.                     foreach($arr_fields as $objField)
  2525.                     {
  2526.                         // check if the fields table is used in the form
  2527.                         $str_fldTbl $objField->getTblAlias();
  2528.                         if (!in_array($str_fldTbl,$arr_tables))
  2529.                         {
  2530.                             if ($debugechoDebugLine(__FILE__,__LINE__,"Checking Table: " $str_fldTbl);
  2531.                             if ('PAGEOBJVAL' == $str_fldTbl)
  2532.                             {
  2533.                                 continue;
  2534.                             }                            
  2535.                             if ('__NO-DBFIELD__' != $str_fldTbl)
  2536.                             {
  2537.                                 if (OCSP_OBJ::defaultReadDBObj()->tblExists($str_fldTbl))
  2538.                                 {
  2539.                                     // the table is not used in the form omit field
  2540.                                     continue;
  2541.                                 }
  2542.                             }
  2543.                         }
  2544.                         
  2545.                         if ($obj_frmField=$this->getField($objField->getKey()))
  2546.                         {
  2547.                             if ($debugechoDebugLine(__FILE__,__LINE__,"<p>".$objField->getKey()." in form</p>");
  2548.                             $obj_fldOriBlock=$obj_frmField->getMyBlock();
  2549.                             $obj_fldOriBlock->removeFieldObj($obj_frmField,$debug);
  2550.                         }
  2551.  
  2552.                         $objField->setMyForm($this);
  2553.                         $objField->setMyBlock($obj_blockNull);
  2554.                         $obj_newBlock->addFieldObj($objField);
  2555.  
  2556.                     }
  2557.                     $obj_newBlock->storeToDb();
  2558.                     $this->myBlocks[]=&$obj_newBlock;
  2559.                     $this->storeToDb($debug);
  2560.                     $this->delCacheFiles();
  2561.                     $this->loadBlocksFromDb($debug);
  2562.                     return True;
  2563.                 }
  2564.             else {
  2565.  
  2566.                 return False;
  2567.             }
  2568.         else if ($debug{
  2569.             ocsp_logError(__FILE__,__LINE__,"could not load block with id$blockId",E_WARNING);
  2570.             return False;
  2571.         }
  2572.  
  2573.     }
  2574.  
  2575.  
  2576.     /**
  2577.       * loads the form blocks from the database
  2578.       * into $this::myBlocks
  2579.       *
  2580.       * @param boolean $debug 
  2581.       * @access protected
  2582.       *
  2583.       * @todo OCSP_FORM::loadBlocksFromDb() only Class OCSP_FORM_BLOCK is implemented
  2584.       */
  2585.     function loadBlocksFromDb($debug=False)
  2586.     {
  2587.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::loadBlocks()");
  2588.         $this->getDBObj($debug)// to ensure we have a db connection
  2589.         $this->myBlocks=array()// unset all blocks
  2590.  
  2591.         $this->myBlocks[0]=new OCSP_FORM_BLOCK($this);
  2592.         $this->myBlocks[0]->setDBObj($this->myDBObj);
  2593.  
  2594.         $arr_Data=array();
  2595.         if ($arr_Data=$this->myDBObj->getArray("T_DBMS_FORMBLOCKS",array('FRM_ID'=>$this->getId()),0,0,'FRB_SORTORDER')) {
  2596.             $i_sortNr=1;$arr_resort=array();
  2597.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$arr_Data=<pre>".print_r($arr_Data,True)."</pre>");
  2598.             foreach($arr_Data as $arr_row)
  2599.             {
  2600.                 $this->myBlocks[$i_sortNr]=OCSP_FORM_BLOCK::getBlockObjFromRow($this,$arr_row,$debug);
  2601.                 if (intval($arr_row['FRB_SORTORDER']!= $i_sortNr)
  2602.                 {
  2603.                     // update sort order
  2604.                     $str_cmd ="UPDATE T_DBMS_FORMBLOCKS SET FRB_SORTORDER=".$i_sortNr;
  2605.                     $str_cmd.=" WHERE FRB_ID=".$arr_row['FRB_ID'];
  2606.                     $str_cmd.="   AND FRM_ID=".$this->getId();
  2607.                     $this->myDBObj->executeCmd($str_cmd);
  2608.                     $this->myBlocks[$i_sortNr]->setOrderNr($i_sortNr);
  2609.                 }
  2610.                 $i_sortNr++;
  2611.  
  2612.             }
  2613.         else if ($debug{
  2614.             if ($debugechoDebugLine(__FILE__,__LINE__,"no blocks loaded from T_DBMS_FORMBLOCKS");
  2615.         }
  2616.     }
  2617.  
  2618.     /**
  2619.       * marks a block as deleted (changes FRM_ID to $this->getId() * (-1))
  2620.       *
  2621.       * @param int $blockId 
  2622.       * @param boolean $debug 
  2623.       *
  2624.       * @return boolean 
  2625.       */
  2626.     function deleteBlock($blockId,$debug=False)
  2627.     {
  2628.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::deleteBlock($blockId)");
  2629.         if (!intval($blockId)) return False;
  2630.  
  2631.         if (!($obj_block=$this->getBlock($blockId)))
  2632.         {
  2633.             ocsp_logError(__FILE__,__LINE__,"could not get block $blockId in form ".$this->getId());
  2634.             return False;
  2635.         }
  2636.  
  2637.         $str_cmd ="UPDATE T_DBMS_FORMFIELDS SET FRB_ID=0";
  2638.         $str_cmd.=" WHERE FRB_ID=".$obj_block->getId();
  2639.         $str_cmd.="   AND FRM_ID=".$this->getId();
  2640.  
  2641.         $this->getDBObj()// ensure $this->myDBObj is set
  2642.         $this->myDBObj->executeCmd($str_cmd);
  2643.  
  2644.         $str_cmd="UPDATE T_DBMS_FORMBLOCKS SET FRM_ID=".($this->getId()*(-1)).", FRB_NAME=".$this->myDBObj->qs_getSlashedValue($obj_block->getId()."_".$obj_block->getName());
  2645.         $str_cmd.=" WHERE FRB_ID=".$obj_block->getId();
  2646.         $str_cmd.="   AND FRM_ID=".$this->getId();
  2647.         $this->myDBObj->executeCmd($str_cmd);
  2648.  
  2649.         $this->delCacheFiles();
  2650.         $this->loadBlocksFromDb();
  2651.         return True;
  2652.     }
  2653.  
  2654.     // ------------------------------------------------------------------------------------------- 
  2655.     // field methods
  2656.     // ------------------------------------------------------------------------------------------- 
  2657.  
  2658.     /**
  2659.       * returns the number of fields in the form
  2660.       *
  2661.       * @param int $mode 
  2662.       * @param boolean $debug 
  2663.       *
  2664.       */
  2665.     function getNofFields($mode=-1,$debug=False)
  2666.     {
  2667.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getNofFields()");
  2668.         $int_ret=0;
  2669.  
  2670.         if ($arr_blocks=$this->getBlocks($debug))
  2671.         {
  2672.             foreach($arr_blocks as &$obj_block)
  2673.             {
  2674.                 $int_ret $int_ret+$obj_block->getNofFields($mode,$debug);
  2675.             }
  2676.         }
  2677.         return $int_ret;
  2678.     }
  2679.  
  2680.     /**
  2681.       * returns an array of fields
  2682.       * 
  2683.       * @param string $aTable (empty to get all fields)
  2684.       * @param boolean $debug 
  2685.       * @param form mode (-1 == all fields)
  2686.       * 
  2687.       * @return array 
  2688.       * 
  2689.       * @version pk-08-11-06 ($frmMode added)
  2690.       */
  2691.     function getFields($aTable="",$debug=False,$frmMode = -1)
  2692.     {
  2693.         $arr_ret=array();
  2694.         $arr_blocks=$this->getBlocks($debug);
  2695.         foreach($arr_blocks as &$o_block)
  2696.         {
  2697.             $arr_bFields=$o_block->getFields($frmMode,$debug);
  2698.             foreach($arr_bFields as &$o_field)
  2699.             {
  2700.                 if (empty($aTable|| ($o_field->getTable()==$aTable))
  2701.                 {
  2702.                     $arr_ret[$o_field->getKey()]=&$o_field;
  2703.                 }
  2704.             }
  2705.         }
  2706.         return $arr_ret;
  2707.     }
  2708.  
  2709.     /**
  2710.       * returns a field object
  2711.       *
  2712.       * @param string $aFldName 
  2713.       * @param string $aTable (empty to search in all tables)
  2714.       * @param int $aBlockId (-1 to search in all blocks)
  2715.       * @param boolean $debug 
  2716.       *
  2717.       * @return DBMS_FIELD 
  2718.       *
  2719.       * @version pk-08-07-12 (OBJVALS_)
  2720.       */
  2721.     function &getField($aFldName,$aTable="",$aBlockId=-1,$debug=False)
  2722.     {
  2723.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getField({$aFldName},{$aTable},{$aBlockId})");
  2724.         
  2725.         if (empty($aTable&& strstr($aFldName,"."))
  2726.         {
  2727.             $str_searchFldKey $aFldName;
  2728.             list($aTable,$str_searchFldName)=explode(".",$aFldName,2);
  2729.         else {
  2730.             $str_searchFldKey "";
  2731.             $str_searchFldName $aFldName;
  2732.         }
  2733.         
  2734.         if (!empty($aTable&& (substr($aTable,0,8== "OBJVALS_")) // <pk-08-07-12 />
  2735.         {
  2736.             // table alias was used and object value
  2737.                $str_searchTable substr($aTable,8"_OV";
  2738.            else {
  2739.                $str_searchTable $aTable;
  2740.            }
  2741.             
  2742.         $obj_ret=NULL;
  2743.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getField($aFldName)");
  2744.         if (intval($aBlockId> -1)
  2745.         {
  2746.             if ($o_block=$this->getBlock($aBlockId,$debug))
  2747.             {
  2748.                 return $o_block->getField($str_searchFldName,$str_searchTable,$str_searchFldKey);
  2749.             }
  2750.         }
  2751.  
  2752.         $arr_blocks=$this->getBlocks();
  2753.         foreach($arr_blocks as &$o_block)
  2754.         {
  2755.             if ($obj_ret=$o_block->getField($str_searchFldName,$str_searchTable,$str_searchFldKey))
  2756.             {
  2757.                 return $obj_ret;
  2758.             
  2759.         }
  2760.  
  2761.         $obj_ret=NULL;
  2762.         return $obj_ret;
  2763.     }
  2764.  
  2765.     /**
  2766.       * changes the class of a field object
  2767.       *
  2768.       * @param string $fldKey 
  2769.       * @param string $className 
  2770.       * @param boolean $debug 
  2771.       *
  2772.       * @return boolean 
  2773.       * 
  2774.       */
  2775.     function castFieldTo($fldKey,$className,$debug=False)
  2776.     {       
  2777.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::castFieldTo($fldKey,$className)");
  2778.  
  2779.         
  2780.         if (!($obj_fld=$this->getField($fldKey)))
  2781.         {            
  2782.             ocsp_logError(__FILE__,__LINE__,"field not found $fldKey");
  2783.             return False;
  2784.         }
  2785.  
  2786.         if (get_class($obj_fld)==$className// nothing to do
  2787.         {
  2788.             return True;
  2789.         }
  2790.  
  2791.         if (!OCSP_FORM::requireFieldClass($className))
  2792.         {
  2793.             ocsp_logError(__FILE__,__LINE__,$className." not defined",E_ERROR);
  2794.             return False;
  2795.         }
  2796.  
  2797.         $str_cmd="\$o_tmp=new $className();";
  2798.         eval($str_cmd);
  2799.         //echo "$str_cmd\n".get_class($o_tmp)."\n$className\n";
  2800.         if (pcf_is_instance_of($o_tmp,$className))
  2801.         {
  2802.             $o_tmp->setObjVarsFrom($obj_fld,$debug);
  2803.  
  2804.             $obj_block=$o_tmp->getMyBlock();
  2805.             $obj_block->storeFldToDb($o_tmp,$debug);
  2806.             $obj_block->loadMyFieldsFromDb();
  2807.             return True;
  2808.         else {
  2809.             ocsp_logError(__FILE__,__LINE__,"Cmd$str_cmd failed");
  2810.             return False;
  2811.         }
  2812.     }
  2813.  
  2814.     /**
  2815.       * deletes a field
  2816.       * NOTE: does not delete the database column of this field
  2817.       * NOTE: does not store the form this has to be done outside
  2818.       *
  2819.       * @param string $fldKey 
  2820.       * @param int $blockId 
  2821.       * @param boolean $debug 
  2822.       *
  2823.       * @param return boolean
  2824.       *
  2825.       */
  2826.     function deleteField($fldKey,$blockId=-1,$debug=False)
  2827.     {
  2828.         if ($obj_field=$this->getField($fldKey,"",$blockId,$debug))
  2829.         {
  2830.             $obj_field->markDeleted();
  2831.             return True;
  2832.         else {
  2833.             return False;
  2834.         }
  2835.     }
  2836.  
  2837.     /**
  2838.       * creates the field column in the database
  2839.       *
  2840.       * @param mixed $filed (name or object)
  2841.       * @param boolean $debug 
  2842.       *
  2843.       * @return boolean 
  2844.       */
  2845.     function createDBColumn(&$field,$debug)
  2846.     {
  2847.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::createDBColumn()");
  2848.         
  2849.         if (!pcf_is_instance_of($field,'DBMS_FIELD'))
  2850.         {
  2851.             if (!($field=$this->getField($field)))
  2852.             {
  2853.                 return False;
  2854.             }
  2855.         }
  2856.  
  2857.         if (!($this->getMyDBControll($debug)))
  2858.         {
  2859.             ocsp_logError(__FILE__,__LINE__,"could not instatiate dbControll",E_ERROR);
  2860.             return False;
  2861.         }
  2862.  
  2863.         return $this->myDBControll->createDBColumn($field,$debug);
  2864.     }
  2865.  
  2866.     /**
  2867.       * foctory a new field object
  2868.       *
  2869.       * @param string $fldName 
  2870.       * @param string $fldClass 
  2871.       * @param array $dbDesc 
  2872.       * @param array $fieldValues 
  2873.       * @param boolean $debug 
  2874.       *
  2875.       * @return DBMS_FIELD 
  2876.       * 
  2877.       * @version pk-08-06-13
  2878.       * @version pk-08-06-17
  2879.       */
  2880.     function factory_field($fldName,$fldClass='',$dbDesc=array(),$fieldValues=array(),$debug=False)
  2881.     {
  2882.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::factory_field($fldName,$fldClass)","\$dbDesc:<pre>".print_r($dbDesc,True)."</pre>fieldValues:<pre>".print_r($fieldValues,True)."</pre>");
  2883.         if (empty($fldClass))
  2884.         {
  2885.             $this->getMyDBControll($debug);
  2886.             return $this->myDBControll->generateField($dbDesc,$debug);
  2887.         else {
  2888.             
  2889.             OCSP_FORM::requireFieldClass($fldClass,$debug);
  2890.  
  2891.             $obj_field new $fldClass((isset($dbDesc['TABLE']$dbDesc['TABLE'""),$fldName,$dbDesc);
  2892.             
  2893.             $fieldValues['myName']=$fldName;
  2894.             $fieldValues['dbDesc']=$dbDesc;
  2895.  
  2896.             $obj_field->setObjectVars($fieldValues,$debug);
  2897.             
  2898.             if ($debugechoDebugLine(__FILE__,__LINE__,"new field: " $obj_field->getName(" (class: " get_class($obj_field).")" );            
  2899.             return $obj_field;
  2900.         }
  2901.     }
  2902.  
  2903.     /**
  2904.       * set a field hidden
  2905.       *
  2906.       * @param string $aFldName 
  2907.       * @param string $aTable 
  2908.       * @param string $scope @see DBMS_FIELD::setHidden()
  2909.       * @param int $aBlockId 
  2910.       * @param boolean $debug 
  2911.       *
  2912.       * @since pk-04-03-08
  2913.       *
  2914.       ***/
  2915.     function hideField($aFldName,$aTable="",$scope="all",$aBlockId=-1,$debug=False
  2916.     {
  2917.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::hideField()",$tbl.".".$fldName);
  2918.         
  2919.         if ($obj_field=$this->getField($aFldName,$aTable,$aBlockId,$debug))
  2920.         {
  2921.             $obj_field->setHidden($scope);
  2922.         }
  2923.     }
  2924.     
  2925.     /**
  2926.      * returns an array with the primary key fields
  2927.      *
  2928.      * @param string $aTable 
  2929.      * @param boolean $debug 
  2930.      * 
  2931.      * @return array 
  2932.      * 
  2933.      * @since pk-08-10-03
  2934.      */
  2935.     public function getPKFields($aTable="",$debug=False)
  2936.     {
  2937.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getPKFields({$aTable})");
  2938.         
  2939.         $arr_ret array();
  2940.         if ($arr_fields $this->getFields($aTable,$debug))
  2941.         {
  2942.             foreach($arr_fields as &$obj_field)
  2943.             {
  2944.                 if ($obj_field->isPrimaryKey())
  2945.                 {
  2946.                     $arr_ret[$obj_field;
  2947.                 }
  2948.             }
  2949.         }
  2950.         return $arr_ret;
  2951.     }
  2952.  
  2953.     /** -------------------------------------------------------------------------------------------
  2954.      * layout fields
  2955.      *  -------------------------------------------------------------------------------------------
  2956.      */
  2957.  
  2958.     /**
  2959.       * @param string $key 
  2960.       * @param string $value 
  2961.       */
  2962.     function setLayoutField($key,$value)
  2963.     {
  2964.         $this->layoutFields[$key]=$value;
  2965.     }
  2966.  
  2967.     /**
  2968.      * returns a layout field (added into the tag)
  2969.      * 
  2970.      * list keys:
  2971.      * - FRMLST_TABLEADD
  2972.      * - FRMLST_THEADADD
  2973.      * - FRMLST_THADD
  2974.      * - FRMLST_TRADD_odd
  2975.      * - FRMLST_TRADD_even
  2976.      * - FRMLST_TDADD
  2977.      * - FRMLST_ADDBEFORELINKS
  2978.      * - FRMLST_ROWADD
  2979.      * - FRMLST_LIMIT
  2980.      * 
  2981.      * form keys:
  2982.      * - FRMFRM_FORMADD
  2983.      * - FRMFRM_FIELDSETADD
  2984.      * - FRMFRM_TABLEADD
  2985.      * 
  2986.      * @param string $key 
  2987.      * 
  2988.      * @return string 
  2989.      */
  2990.     function getLayoutField($key)
  2991.     {
  2992.         if (isset($this->layoutFields[$key])) return $this->layoutFields[$key];
  2993.         return Null;
  2994.     }
  2995.  
  2996.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2997.     // view methods
  2998.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2999.  
  3000.     /**
  3001.       * @return OCSP_FRMVIEW 
  3002.       */
  3003.     function getView()
  3004.     {
  3005.         return $this->myView;
  3006.     }
  3007.  
  3008.     /**
  3009.       * instantiates a new class if $this->myControl not type of $contrClass
  3010.       *
  3011.       * NOTE the class must exists or have it's code in __FILE__
  3012.       *
  3013.       * @param string $viewClass 
  3014.       * @param boolean $debug 
  3015.       * @return OCSP_FRMVIEW 
  3016.       *
  3017.       */
  3018.     function &getViewObj($viewClass="OCSP_FRMVIEW",$debug=False)
  3019.     {
  3020.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getViewObj()");
  3021.         if (pcf_is_instance_of($this->myView,$viewClass))
  3022.         {
  3023.             return $this->myView;
  3024.         else {
  3025.             if (!class_exists($viewClass))
  3026.             {
  3027.                 if (file_exists(dirname(__FILE__)."/".$viewClass.".phpclass"))
  3028.                 {
  3029.                     require_once dirname(__FILE__)."/".$viewClass.".phpclass";
  3030.                 else {
  3031.                     ocsp_logError(__FILE__,__LINE__,"ViewClass$viewClass does not exist");
  3032.                 }
  3033.             }
  3034.  
  3035.             if ($debug)
  3036.             {
  3037.                 eval("\$this->myView=new $viewClass(\$this);");
  3038.             else {
  3039.                 @eval("\$this->myView=new $viewClass(\$this);");
  3040.             }
  3041.  
  3042.             if (pcf_is_instance_of($this->myControl,'OCSP_FRMCONTR')) {
  3043.                 $this->myView->setControll($this->myControl);
  3044.                 $this->myControl->setView($this->myView);
  3045.             }
  3046.             return $this->myView;
  3047.         }
  3048.     }
  3049.  
  3050.     /**
  3051.       * @param string $viewClass 
  3052.       * @param boolean $debug 
  3053.       * @return OCSP_FRMVIEW_LIST 
  3054.       */
  3055.     function &getListView($viewClass="OCSP_FRMVIEW_LIST",$debug=False)
  3056.     {
  3057.         if($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getView($viewClass)");
  3058.  
  3059.         if (empty($viewClass)) $viewClass="OCSP_FRMVIEW_LIST";
  3060.         return $this->getViewObj($viewClass,$debug);
  3061.     }
  3062.  
  3063.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3064.     // controll methods
  3065.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3066.  
  3067.     /**
  3068.      * alias for $this->getControl()
  3069.      * @return OCSP_FRMCONTR 
  3070.      * 
  3071.      * @deprecated since pk-08-11-20
  3072.      */
  3073.     function &getControll()
  3074.     {
  3075.         return $this->getControl();
  3076.     }
  3077.     
  3078.     /**
  3079.       * @return OCSP_FRMCONTR 
  3080.       */
  3081.     function &getControl()
  3082.     {
  3083.         return $this->myControl;
  3084.     }    
  3085.  
  3086.     /**
  3087.      * alias for $this->getControlObj()
  3088.      *
  3089.      * @param string $contrClass 
  3090.      * @param boolean $debug 
  3091.      * @return OCSP_FRMCONTR 
  3092.      * 
  3093.      * @deprecated since pk-08-11-20
  3094.      */
  3095.     function &getControllObj($contrClass="OCSP_FRMCONTR",$debug=False)
  3096.     {
  3097.         return $this->getControlObj($contrClass,$debug);
  3098.     }
  3099.     
  3100.     /**
  3101.       * instantiates a new class if $this->myControl not type of $contrClass
  3102.       *
  3103.       * NOTE the class must exists or have it's code in __FILE__
  3104.       *
  3105.       * @param string $contrClass 
  3106.       * @param boolean $debug 
  3107.       *
  3108.       * @returns OCSP_FRMCONTR
  3109.       */
  3110.     function &getControlObj($contrClass="OCSP_FRMCONTR",$debug=False)
  3111.     {
  3112.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getControllObj($contrClass)");
  3113.  
  3114.         if (pcf_is_instance_of($this->myControl,$contrClass))
  3115.         {
  3116.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$this->myControl already set ".get_class($this->myControl));
  3117.             return $this->myControl;
  3118.         else {            
  3119.             if (!class_exists($contrClass))
  3120.             {
  3121.                 if (file_exists(dirname(__FILE__)._OCSP_DIRSEP_.$contrClass.".phpclass"))
  3122.                 {
  3123.                     require_once dirname(__FILE__)._OCSP_DIRSEP_.$contrClass.".phpclass";
  3124.                 else {
  3125.                     ocsp_logError(__FILE__,__LINE__,"ControllClass$contrClass does not exist",E_ERROR);
  3126.                     die();
  3127.                 }
  3128.             }
  3129.             
  3130.             if (pcf_is_instance_of($this->myControl,'OCSP_FRMCONTR'))
  3131.             {
  3132.                 $arr_contrValues=$this->myControl->getObjectValues($debug);
  3133.             else 
  3134.                 $arr_contrValues=NULL;
  3135.             }
  3136.              
  3137.             $obj_frmObj=&$this;
  3138.             $str_cmd="\$this->myControl=new $contrClass(\$obj_frmObj,".($debug "True" "False").");";
  3139.             if ($debug)
  3140.             {
  3141.                 echoDebugLine(__FILE__,__LINE__,"new controll cmd$str_cmd");
  3142.                 eval($str_cmd);
  3143.             else {
  3144.                 @eval($str_cmd);
  3145.             }
  3146.  
  3147.             if ($arr_contrValues && pcf_is_instance_of($this->myControl,'OCSP_FRMCONTR'))
  3148.             {
  3149.                 $this->myControl->setObjectValues($arr_contrValues,$debug);
  3150.             }
  3151.  
  3152.             if (pcf_is_instance_of($this->myView,'OCSP_FRMVIEW')) {
  3153.                 $this->myView->setControll($this->myControl);
  3154.                 $this->myControl->setView($this->myView);
  3155.             }
  3156.             $this->myControl->setMyForm($this);
  3157.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning new object ".get_class($this->myControl));
  3158.             return $this->myControl;
  3159.         }
  3160.     }
  3161.  
  3162.     /**
  3163.      *  sets a control
  3164.      * 
  3165.      * NOTE also changes the controll in $this->myView
  3166.      *      and sets the view in $aControll if $sync is True
  3167.      *
  3168.      * @param OCSP_FRMCONTR $aControl 
  3169.      * @param boolean $sync 
  3170.      * @param boolean $debug 
  3171.      *
  3172.      * @access public
  3173.      */
  3174.     public function setControl(&$aControl,$sync=True$debug=False)
  3175.     {
  3176.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::setControl()");
  3177.  
  3178.         $this->myControl=&$aControl;
  3179.         
  3180.         if ($sync)
  3181.         {            
  3182.             $this->myControl->setMyForm($this);
  3183.             if (pcf_is_instance_of($this->myView,'OCSP_FRMVIEW'))
  3184.             {
  3185.                 if ($debugechoDebugLine(__FILE__,__LINE__,"syncing view and controll");
  3186.                 $this->myView->setControll($this->myControl);
  3187.                 $this->myControl->setView($this->myView);
  3188.             }
  3189.         }
  3190.     }    
  3191.     
  3192.     /**
  3193.      * alias for setControl
  3194.      *
  3195.      * @param OCSP_FRMCONTR $aControl 
  3196.      * @param boolean $sync 
  3197.      * @param boolean $debug 
  3198.      * 
  3199.      * @deprecated since pk-08-12-03
  3200.      */
  3201.     public function setControll(&$aControl,$sync=True,$debug=False)
  3202.     {
  3203.         $this->setControl($aControl,$sync,$debug);
  3204.     }
  3205.     
  3206.     
  3207.     /**
  3208.       * returns the relaod url
  3209.       *
  3210.       * @param boolean $debug 
  3211.       *
  3212.       * @returns string
  3213.       *
  3214.       * @since pk-07-08-21
  3215.       *
  3216.       ***/
  3217.     function getReloadUri($debug=False)
  3218.     {
  3219.         if (method_exists($this->myControl,'getReloadUri'))
  3220.         {
  3221.             return $this->myControl->getReloadUri($debug);
  3222.         else {
  3223.             return "";
  3224.         }
  3225.     }
  3226.     
  3227.  
  3228.     /**
  3229.       * if $contrClass is not set to "NO" a controll object will be created
  3230.       * if none exists ($this->myControl) is empty
  3231.       *
  3232.       * if $contrClass is set to "NO" $this->myControl is returned as is
  3233.       * without checking that we
  3234.       *
  3235.       * @param string $contrClass 
  3236.       * @param boolean $debug 
  3237.       * @return OCSP_FRMCONTR_LIST 
  3238.       */
  3239.     function &getListControll($contrClass="OCSP_FRMCONTR_LIST",$debug=False)
  3240.     {
  3241.         if($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getListControll($contrClass)");
  3242.  
  3243.         if (empty($contrClass)) $contrClass="OCSP_FRMCONTR_LIST";
  3244.  
  3245.         if ($contrClass == "NO"{
  3246.             return $this->getControll();
  3247.         }
  3248.  
  3249.         return $this->getControllObj($contrClass,$debug);
  3250.     }
  3251.     
  3252.     /**
  3253.      * adds a pass-through field
  3254.      *
  3255.      * @param string $colName 
  3256.      * @param mixed $mixValue 
  3257.      */
  3258.     public function addPassThroughField($colName,$mixValue)
  3259.     {
  3260.         $this->myPassThroughFields[$colName$mixValue;
  3261.     }
  3262.     
  3263.     /**
  3264.      * returns the pass-through fields array
  3265.      *
  3266.      * @return $this->myPassThroughFields; 
  3267.      */
  3268.     public function getPassThroughFields()
  3269.     {
  3270.         return $this->myPassThroughFields;
  3271.     }
  3272.  
  3273.     /**
  3274.      * returns form command fields
  3275.      * 
  3276.      * commands needed in subclasses to validate submitdata
  3277.      * this is used in OCSP_FRMCONTR_FORM::getFormCmdFields()
  3278.      * 
  3279.      * NOTE: only added if form class != OCSP_FORM
  3280.      * 
  3281.      * @param boolean $debug 
  3282.      * 
  3283.      * @return array 
  3284.      * 
  3285.      * @since pk-07-12-05
  3286.      * @version pk-08-06-26
  3287.      */
  3288.     function getFormCmdFields($debug=False)
  3289.     {
  3290.         if ($debugechoDebugMethod(__FILE__,get_class($this),'OCSP_FORM::getFormCmdFields()');
  3291.         
  3292.         $arr_ret array();
  3293.        
  3294.         return $arr_ret;
  3295.         
  3296.     }
  3297.     
  3298.     // --------------------------------- data validation --------------------------------
  3299.  
  3300.     /**
  3301.       * @abstract for child objects to init on checkSubmitData
  3302.       *
  3303.       * @param array $frmSettings 
  3304.       * @param string $dataArrName 
  3305.       * @param array $frmValues 
  3306.       * @param boolean $debug 
  3307.       */
  3308.     function initCheckSubmitData($frmSettings,$dataArrName,$frmValues,$debug=False)
  3309.     {
  3310.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::initCheckSubmitData()");
  3311.     }
  3312.     
  3313.     /**
  3314.      * sets the tableobject class and include from $dataArr and
  3315.      * tries to instantiate by calling $this->getMyTblObj
  3316.      * 
  3317.      * if class is set in $dataArr and it could not be instantiated False is returned
  3318.      * else True is returned
  3319.      * 
  3320.      * @param array $dataArr (normaly $_POST)
  3321.      * @param boolean $debug 
  3322.      * 
  3323.      * @return boolean 
  3324.      * 
  3325.      * @since pk-07-12-05
  3326.      * 
  3327.      */
  3328.     function setTblObjFromSubmitData(&$dataArr,$debug=False)
  3329.     {
  3330.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FROM::setTblObjFromSubmit()");
  3331.         
  3332.         if (isset($dataArr['OCSP_FORM_TBLOBJCLASS']&& !empty($dataArr['OCSP_FORM_TBLOBJCLASS']))
  3333.         {
  3334.             $this->setTblObjClass(OCSP_SESSION::getInstance()->decrypt($dataArr['OCSP_FORM_TBLOBJCLASS']),$debug);
  3335.             $this->setTblObjInc(OCSP_SESSION::getInstance()->decrypt($dataArr['OCSP_FORM_TBLOBJINC']),$debug);
  3336.             if ($debugechoDebugLine(__FILE__,__LINE__,"<p>table object <strong>".$this->tblObj_class."</strongset in \$$dataArr</p>");
  3337.  
  3338.             if (!$this->getMyTblObj(True,$debug))
  3339.             {
  3340.                 $this->setError($this->getLangTxt('COULD_NOT_INSTANTIATE')." ".$this->tblObj_class);
  3341.                 return False;
  3342.             }
  3343.             
  3344.             return True;
  3345.         }
  3346.  
  3347.         return False;        
  3348.     }
  3349.  
  3350.     /**
  3351.       * @param string $method (POST|GET)
  3352.       * @param string $contrClass (sub)class Name of OCSP_FRMCONTR
  3353.       * @param boolean $debug 
  3354.       *
  3355.       * @return boolean (True if no error found)
  3356.       */
  3357.     function checkSubmitData($method="",$debug=False)
  3358.     {
  3359.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::checkSubmitData()");
  3360.  
  3361.         switch(strtoupper($method))
  3362.         {
  3363.             case "GET":
  3364.                 $arr_values=$_GET;
  3365.                 break;
  3366.             case "POST":
  3367.                 $arr_values=$_POST;
  3368.                 break;
  3369.             default:
  3370.                 $arr_values=$_REQUEST;
  3371.         }
  3372.  
  3373.         if (!isset($arr_values['OCSP_FORM_SETTING_CRYPT']))
  3374.         {
  3375.             $this->setError($this->getLangTxt('NO_SETTINGS_SUBMITTED'));
  3376.             return False;
  3377.         }
  3378.  
  3379.         $arr_settings=unserialize(OCSP_SESSION::getInstance()->decrypt($arr_values['OCSP_FORM_SETTING_CRYPT']));
  3380.        
  3381.         if ($debugechoDebugLine(__FILE__,__LINE__,"settings: <pre>".print_r($arr_settings,True)."</pre>");
  3382.  
  3383.         $this->setFrmMode(intval($arr_settings['MODE']));
  3384.  
  3385.         $str_dataArrName="DBVAL_".$arr_settings['ID'];
  3386.         
  3387.         if (isset($arr_values['PASSTHROUGH']&& is_array($arr_values['PASSTHROUGH']))
  3388.         {
  3389.             foreach($arr_values['PASSTHROUGH'as $str_col => $str_serVal)
  3390.             {
  3391.                 if (!empty($str_serVal))
  3392.                 {
  3393.                     $this->myPassThroughFields[$str_colunserialize(OCSP_SESSION::getInstance()->decrypt($str_serVal));
  3394.                     
  3395.                 else {
  3396.                     $this->myPassThroughFields[$str_colNull;
  3397.                 }
  3398.                 if (is_array($arr_values[$str_dataArrName]))
  3399.                 {
  3400.                     $arr_values[$str_dataArrName][$str_col$this->myPassThroughFields[$str_col];
  3401.                 }
  3402.             }
  3403.             
  3404.             if ($debugechoDebugLine(__FILE__,__LINE__,"pass through fields: <pre>" print_r($this->myPassThroughFields,True"</pre>");            
  3405.         }
  3406.         
  3407.         if (isset($arr_values['b64_PASSTHROUGH']&& !empty($arr_values['b64_PASSTHROUGH']))
  3408.         {
  3409.             $arr_passThrough unserialize(base64_decode($arr_values['b64_PASSTHROUGH']));
  3410.             if (is_array($arr_passThrough))
  3411.             {
  3412.                 foreach($arr_passThrough as $str_col => $mix_val)
  3413.                 {
  3414.                     $this->myPassThroughFields[$str_col$mix_val;
  3415.                 }
  3416.             }
  3417.         }
  3418.         
  3419.         if ($this->getFrmMode()==FRM_MODE_DELETE)
  3420.         {
  3421.             if ($debugechoDebugLine(__FILE__,__LINE__,"<h1>Delete</h1>");
  3422.             if (!isset($arr_values['DELKEY']|| empty($arr_values['DELKEY']))
  3423.             {
  3424.                 if ($debugechoDebugLine(__FILE__,__LINE__,"no data submitted");
  3425.                 $this->setError($this->getLangTxt('NO_DATA_SUBMITTED'));
  3426.                 return False;
  3427.             else {
  3428.                 $arr_values[$str_dataArrName]['DELKEY']=$arr_values['DELKEY'];
  3429.             }
  3430.         else {
  3431.             if (!isset($arr_values[$str_dataArrName]|| !is_array($arr_values[$str_dataArrName]))
  3432.             {
  3433.                 if ($debugechoDebugLine(__FILE__,__LINE__,"no data submitted");
  3434.                 $this->setError($this->getLangTxt('NO_DATA_SUBMITTED'));
  3435.                 return False;
  3436.             }
  3437.         }
  3438.         
  3439.         $this->initCheckSubmitData($arr_settings,$str_dataArrName,$arr_values,$debug);
  3440.  
  3441.         if (!$this->setTblObjFromSubmitData($arr_values,$debug&& isset($arr_values['OCSP_FORM_TBLOBJCLASS']))
  3442.         {
  3443.             // only returns False if classname is in $arr_values and can not be instantiated
  3444.             if ($debugechoDebugLine(__FILE__,__LINE__,"could not instanciate " $arr_values['OCSP_FORM_TBLOBJCLASS']);
  3445.             return False;
  3446.         }
  3447.  
  3448.         if ($debugechoDebugLine(__FILE__,__LINE__,"<h3>After table set</h3><pre>" print_r($arr_values,True"</pre>");
  3449.         
  3450.         $this->getControllObj($arr_settings['CLASS'],$debug);
  3451.         $this->myControl->setFilter($arr_settings['FILTER']);
  3452.         
  3453.         if (isset($arr_values['FRMTARGET']&& !empty($arr_values['FRMTARGET']))
  3454.         {
  3455.             if (method_exists($this->myControl,'setMyTarget'))
  3456.             {
  3457.                 $this->myControl->setMyTarget(base64_decode($arr_values['FRMTARGET']));
  3458.             }
  3459.         }
  3460.         
  3461.         if (isset($arr_values['FRMACTION']&& !empty($arr_values['FRMACTION']))
  3462.         {
  3463.             $this->myControl->setActionURL(base64_decode($arr_values['FRMACTION']));
  3464.         }
  3465.  
  3466.         if (isset($arr_values[$this->getName()."_NEXT"]&& method_exists($this->myControl,'setNextUrl'))
  3467.         {
  3468.             $this->myControl->setNextUrl(base64_decode($arr_values[$this->getName()."_NEXT"]));
  3469.         }
  3470.  
  3471.         
  3472.         // <pk-08-02-01>
  3473.         if (($arr_settings['MODE'== FRM_MODE_EDIT|| ($arr_settings['MODE'== FRM_MODE_NEW))
  3474.         {
  3475.                if (is_array($arr_settings['FILTER']))
  3476.                {
  3477.                    foreach($arr_settings['FILTER'as $str_col => $mix_val)
  3478.                    {
  3479.                        if (!isset($arr_values[$str_dataArrName][$str_col]|| empty($arr_values[$str_dataArrName][$str_col]))
  3480.                        {
  3481.                            $arr_values[$str_dataArrName][$str_col]=$mix_val;
  3482.                        }
  3483.                    }
  3484.                }
  3485.         
  3486.         // </pk-08-02-01>        
  3487.         return $this->myControl->validateSubmit($arr_settings['MODE'],$arr_values[$str_dataArrName],$debug);
  3488.     }
  3489.  
  3490.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3491.     // list methods
  3492.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3493.  
  3494.     /**
  3495.       *
  3496.       * settings:
  3497.       * - (OCSP_FRMVIEW_LIST) VIEWOBJ
  3498.       * - (string) VIEWCLASS
  3499.       *
  3500.       * - (OCSP_FRMCONTR_LIST) CONTROBJ
  3501.       * - (string) CONTRCLASS
  3502.       * - (string) LISTQUERY
  3503.       * - (array) FILTER
  3504.       * - (int) OFFSET
  3505.       * - (int) LIMIT
  3506.       * 
  3507.       * - (array) LSTGROUPS
  3508.       * - (string) ORDERBY
  3509.       * 
  3510.       * - (array) CONTRROWCMD
  3511.       * - (array) CONTRBUTTONS (['C'] => command ['I'] => icon tag)
  3512.       * - (array) FOOTERCMDS (['name'] => html)
  3513.       *
  3514.       * @param array $settings (array of settings to list view and controll)
  3515.       * @param boolean $debug 
  3516.       *
  3517.       * @return int (number of rows to show)
  3518.       * 
  3519.       * @version pk-08-01-22
  3520.       * @version pk-08-01-28 (CONTRROWCMD,CONTRBUTTONS added)
  3521.       */
  3522.     function prepareList($settings,$debug=False)
  3523.     {
  3524.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::prepareList()<pre>" print_r($settings,True"</pre>");
  3525.  
  3526.         if (isset($settings['VIEWOBJ']&& pcf_is_instance_of($settings['VIEWOBJ'],'OCSP_FRMVIEW'))
  3527.         {
  3528.             $this->myView=&$settings['VIEWOBJ'];
  3529.             $this->myView->setMyForm($this);
  3530.         else {
  3531.             $this->getListView((isset($settings['VIEWCLASS']$settings['VIEWCLASS'""),$debug);
  3532.         }
  3533.  
  3534.         if (isset($settings['CONTROBJ']&& pcf_is_instance_of($settings['CONTROBJ'],'OCSP_FRMCONTR'))
  3535.         {
  3536.             $this->myControl=&$settings['CONTROBJ'];
  3537.             $this->myControl->setMyForm($this);
  3538.         else {
  3539.             $this->getListControll((isset($settings['CONTRCLASS']$settings['CONTRCLASS']:""),$debug);
  3540.         }
  3541.         
  3542.         $this->myView->setControll($this->myControl);
  3543.         $this->myControl->setView($this->myView);
  3544.  
  3545.         
  3546.         if (isset($settings['LISTQUERY']))
  3547.         {
  3548.             $this->myControl->setListQuery($settings['LISTQUERY']);
  3549.         }
  3550.                 
  3551.         if (isset($settings['FILTER']&& is_array($settings['FILTER']))
  3552.         {
  3553.             $this->myControl->setFilter($settings['FILTER']);
  3554.         }
  3555.  
  3556.         if (!empty($this->FRM_LSTGROUPS))
  3557.         {
  3558.             $this->listGroups=unserialize($this->FRM_LSTGROUPS);
  3559.         else {
  3560.             $this->listGroups=array();
  3561.         }
  3562.         if (isset($settings['LSTGROUPS']&& is_array($settings['LSTGROUPS']))
  3563.         {
  3564.             foreach($this->listGroups as $str_col => $arr_def)
  3565.             {
  3566.                 if (isset($settings['LSTGROUPS'][$arr_def]))
  3567.                 {
  3568.                     $this->listGroups[$str_col]=array_merge($this->listGroups[$str_col],$settings['LSTGROUPS'][$arr_def]);
  3569.                     unset($settings['LSTGROUPS'][$arr_def]);
  3570.                 }
  3571.             }
  3572.             $this->listGroups=array_merge($this->listGroups,$settings['LSTGROUPS']);
  3573.         }
  3574.  
  3575.         $str_orderBy="";
  3576.         if (sizeof($this->listGroups))
  3577.         {
  3578.             foreach($this->listGroups as $str_col => $arr_def)
  3579.             {
  3580.                 $str_orderBy.=(isset($arr_def['ORDERBY']$arr_def['ORDERBY'$str_col).",";
  3581.             }
  3582.         }
  3583.         
  3584.         if (isset($settings['ORDERBY']&& !empty($settings['ORDERBY']))
  3585.         {
  3586.             $this->myControl->setOrderBy($str_orderBy.$settings['ORDERBY']);
  3587.         else if (!empty($str_orderBy)) {
  3588.             $this->myControl->setOrderBy(substr($str_orderBy,0,-1));
  3589.         }
  3590.  
  3591.         if (isset($settings['OFFSET'])) $this->myControl->setOffset(intval($settings['OFFSET']));
  3592.         if (isset($settings['LIMIT'])) $this->myControl->setLimit(intval($settings['LIMIT']));
  3593.  
  3594.         $this->myControl->initList($debug);
  3595.         
  3596.         // <pk-08-01-28>
  3597.         if (isset($settings['CONTRROWCMD']&& is_array($settings['CONTRROWCMD']))
  3598.             foreach($settings['CONTRROWCMD'as $str_event => $str_cmd)
  3599.             {
  3600.                 $this->myControl->setRowCmd($str_event,$str_cmd);
  3601.             }        
  3602.         
  3603.         if (isset($settings['CONTRBUTTONS']&& is_array($settings['CONTRBUTTONS'])) 
  3604.         {
  3605.             foreach($settings['CONTRBUTTONS'as $str_btn => $mix_btnDev)
  3606.             {
  3607.                 if ($debugecho "alert('Button: ".$str_btn.pcf_js_escape("\n".print_r($mix_btnDev,True))."');";
  3608.                 if (is_array($mix_btnDev))
  3609.                 {
  3610.                     $this->myControl->addCmdButton($str_btn,$mix_btnDev['C']);
  3611.                     if (isset($mix_btnDev['I']))
  3612.                     {
  3613.                         $this->myView->setButtonTag($str_btn,$mix_btnDev['I']);
  3614.                     }
  3615.                     $int_pos (isset($mix_btnDev['POS']intval($mix_btnDev['POS']1);
  3616.                     $this->myView->setButtonPos($str_btn,$int_pos);
  3617.                 else {
  3618.                     $this->myControl->addCmdButton($str_btn,$mix_btnDev);
  3619.                 }
  3620.             }            
  3621.         }
  3622.         // </pk-08-01-28>
  3623.  
  3624.         // <pk-08-12-21>
  3625.         if (isset($settings['FOOTERCMDS']&& is_array($settings['FOOTERCMDS']))
  3626.         {
  3627.             $this->myControl->setFooterCmdArr($settings['FOOTERCMDS']);
  3628.         }
  3629.         
  3630.         
  3631.         // <pk-08-05-30> session settings
  3632.         
  3633.         $str_lstKey $this->getId(get_class($thisget_class($this->myControlget_class($this->myView);
  3634.         $str_lstKey.= (isset($settings['LISTQUERY']$settings['LISTQUERY'"");
  3635.         $str_lstKey.= (isset($settings['FILTER']serialize($settings['FILTER']"NO FILTER");
  3636.         
  3637.         $settings['FRM_ID']        $this->getId();        
  3638.         $settings['FORMCLASS']    get_class($this);
  3639.         $settings['VIEWCLASS']     get_class($this->myView);
  3640.         $settigns['CONTRCLASS']    get_class($this->myControl);
  3641.         
  3642.         
  3643.         $str_lstKey "sess_" md5(serialize($str_lstKey));     
  3644.           OCSP_SESSION::getInstance()->setValue($str_lstKey,$settings);
  3645.           $this->myControl->setListKey($str_lstKey);        
  3646.         
  3647.         
  3648.     }
  3649.  
  3650.     /**
  3651.       * @return array 
  3652.       * @since pk-07-10-16
  3653.       */
  3654.     function get_listGroups()
  3655.     {
  3656.         if (is_array($this->listGroups))
  3657.         {
  3658.             return $this->listGroups;
  3659.         }
  3660.         if (!empty($this->FRM_LSTGROUPS))
  3661.         {
  3662.             $this->listGroups=unserialize($this->FRM_LSTGROUPS);
  3663.             return $this->listGroups;
  3664.         }
  3665.         return NULL;
  3666.     }
  3667.  
  3668.  
  3669.       
  3670.     
  3671.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3672.     // field ajax object
  3673.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3674.  
  3675.     /**
  3676.       * creates an OCSP_AJAXFORM for the form
  3677.       * @since pk-07-02-27
  3678.       * @access protected
  3679.       ***/
  3680.     protected function ajax_createObj({
  3681.         pcf_require_class('OCSP_AJAXFORM',"ajax/");
  3682.         $this->myAjaxObj=new OCSP_AJAXFORM();
  3683.         $this->myAjaxObj->setFormObject($this);
  3684.     }
  3685.  
  3686.     /**
  3687.       * @param boolean $force 
  3688.       *
  3689.       * @returns OCSP_AJAX
  3690.       * @since pk-07-02-27
  3691.       * @access public
  3692.       ***/
  3693.     function &ajax_getObj($force=True{
  3694.         if ($force && (!is_object($this->myAjaxObj|| (!pcf_is_instance_of($this->myAjaxObj,'OCSP_AJAX')))) {
  3695.             $this->ajax_createObj();
  3696.         }
  3697.         return $this->myAjaxObj;
  3698.     }
  3699.  
  3700.     /**
  3701.       * @param OCSP_AJAX $aAjaxFrmObj 
  3702.       * @since pk-07-02-27
  3703.       * @access public
  3704.       ***/
  3705.     function ajax_setObj(&$aAjaxFrmObj{
  3706.         $this->myAjaxObj=$aAjaxFrmObj;
  3707.     }
  3708.  
  3709.     /**
  3710.      * return if the form can be changed on an relaod
  3711.      * 
  3712.      * @return boolean 
  3713.      * 
  3714.      * @since pk-08-11-01
  3715.      */
  3716.     function ajax_canChangeForm()
  3717.     {
  3718.         return (intval($this->FRM_DISABLEAJAXCHANGEFORMFalse True);
  3719.     }
  3720.     
  3721.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3722.     // error handling
  3723.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3724.  
  3725.     /**
  3726.       * clears all errors
  3727.       * @param boolean $fieldsToo 
  3728.       * @param boolean $debug 
  3729.       *
  3730.       * @todo clear field errors if $fieldsToo
  3731.       */
  3732.     function clearErrors($fieldsTo=False)
  3733.     {
  3734.         $this->myErrors=array('ERROR'=>False);
  3735.         $arr_flds=$this->getFields("",$debug);
  3736.         foreach($arr_flds as &$obj_fld)
  3737.         {
  3738.             $obj_fld->clearError();
  3739.         }
  3740.     }
  3741.  
  3742.     /**
  3743.       * returns if the form has errors
  3744.       */
  3745.     function hasErrors()
  3746.     {
  3747.         if (isset($this->errors['ERROR'])) return $this->errors['ERROR'];
  3748.         return (sizeof($this->myErrorsTrue False);
  3749.     }
  3750.  
  3751.     /**
  3752.       * adds an error to this::errors
  3753.       *
  3754.       * @param mixed $aError either an array with LABEL and MSG values or only the message if empty only $this->errors['ERROR'] is set to True
  3755.       * @param string $fld 
  3756.       * @param boolean $debug 
  3757.       *
  3758.       ***/
  3759.     function setError($aError,$fld="",$debug=False{
  3760.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::setError()","Field$fld\nError$aError");
  3761.         $this->errors['ERROR']=True;
  3762.  
  3763.         if (is_array($aError))
  3764.         {
  3765.             $arr_Error=$aError;
  3766.         else if (!empty($aError)) {
  3767.             $arr_Error=array('LABEL'=>"FORMULAR",'MSG'=>$aError);
  3768.         else {
  3769.             return False;
  3770.         }
  3771.  
  3772.  
  3773.         if (empty($fld))
  3774.         {
  3775.             $this->myErrors[]=$arr_Error;
  3776.         else {
  3777.             if ($obj_fld=$this->getField($fld))
  3778.             {
  3779.                 $obj_fld->setErrorMsg($aError['MSG']);
  3780.             else {
  3781.                 $this->myErrors[$fld]=$arr_Error;
  3782.             }
  3783.         }
  3784.     }
  3785.  
  3786.  
  3787.     /**
  3788.       * returns the form errors
  3789.       *
  3790.       * @param boolean $withFields if True the field errors are also included
  3791.       * @param int $returnType 
  3792.       * @param boolean $debug 
  3793.       *
  3794.       * @return string 
  3795.       *
  3796.       * @todo OCSP_FORM::getErrors() only FRM_DATATYPE_STRING implemented now
  3797.       */
  3798.     function getErrors($withFields=False,$returnType=FRM_DATATYPE_STRING,$debug=False)
  3799.     {
  3800.         if ($debugechoDebugMethod(__FILE__,get_class($this)."OCSP_FORM::getErrors()");
  3801.         $str_ret="";
  3802.         if ($this->hasErrors())
  3803.         {
  3804.             $str_sep="";
  3805.             foreach($this->myErrors as $arr_Error)
  3806.             {
  3807.                 $str_ret.=$str_sep.$arr_Error['LABEL']." ".$arr_Error['MSG'];
  3808.                 $str_sep="<br />";
  3809.             }
  3810.  
  3811.             if ($withFields{
  3812.                 $arr_flds=$this->getFields("",$debug);
  3813.                 foreach($arr_flds as &$obj_fld)
  3814.                 {
  3815.                     if ($obj_fld->hasErrors())
  3816.                     {
  3817.                         $str_ret.=$str_sep.$obj_fld->getLabel()." ".$obj_fld->getErrorMsg();
  3818.                         $str_sep="<br />";
  3819.                     }
  3820.                 }
  3821.             }
  3822.         }
  3823.        return $str_ret;
  3824.     }
  3825.  
  3826.     /**
  3827.       * returns an array with all fields having an error
  3828.       *
  3829.       * @param boolean $debug 
  3830.       *
  3831.       * @return array 
  3832.       *
  3833.       */
  3834.     function getErrorFields($debug=False)
  3835.     {
  3836.         $arr_flds=$this->getFields("",$debug);
  3837.         $arr_ret=array();
  3838.         foreach($arr_flds as &$obj_field)
  3839.         {
  3840.             if ($obj_field->hasErrors())
  3841.             {
  3842.                 $i=$obj_field->getOrderNr();
  3843.                 while(isset($arr_ret[$i])) $i++;
  3844.                 $arr_ret[$i]=&$obj_field;
  3845.             }
  3846.         }
  3847.         ksort($arr_ret);
  3848.         return $arr_ret;
  3849.     }
  3850.  
  3851.  
  3852.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3853.     // rights
  3854.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3855.  
  3856.     public function rightsAreSet()
  3857.     {
  3858.         if (intval($this->rightsSet0)
  3859.         {
  3860.             return True;
  3861.         else if (intval($this->rightsSet 0)) {
  3862.             return False;
  3863.         else {
  3864.             $str_query "SELECT COUNT(*) FROM T_DBMS_FORMRIGHTS WHERE FRM_ID = " $this->getId();
  3865.             if (intval(OCSP_OBJ::defaultReadDBObj()->getOne($str_query)))
  3866.             {
  3867.                 $this->rightsSet 1;
  3868.                 return True;
  3869.             else {
  3870.                 $this->rightsSet = -1;
  3871.                 return False;
  3872.             }
  3873.         }
  3874.     }
  3875.     
  3876.     /**
  3877.      * loads the right settings from T_DBMS_FORMRIGHTS
  3878.      *
  3879.      * NOTE rights are only checked if a row is found in T_DBMS_FORMRIGHTS
  3880.      * 
  3881.      * @param string $str_col 
  3882.      * @param boolean $debug 
  3883.      * 
  3884.      * @return boolean 
  3885.      */
  3886.     protected function curUserCanCol($str_col,$debug=False)
  3887.     {
  3888.         if ($this->rightsAreSet())
  3889.         {
  3890.             if (isset($this->loadedUserRights[$str_col]))
  3891.             {
  3892.                 if ($debugechoDebugLine(__FILE__,__LINE__,"returning set value for {$str_col}($this->loadedUserRights[$str_col"TRUE" "FALSE"));
  3893.                 return $this->loadedUserRights[$str_col];
  3894.             }
  3895.             
  3896.             if ($str_groups OCSP_OBJ::currentUser(True)->getGroups(",",False))
  3897.             {
  3898.                 $str_query "SELECT MAX({$str_col}FROM T_DBMS_FORMRIGHTS";
  3899.                 $str_query.= " WHERE FRM_ID = " $this->getId();
  3900.                 $str_query.= " AND GRP_ID IN (" $str_groups ")";
  3901.                 
  3902.                 if ($debugechoDebugLine(__FILE__,__LINE__,"Query: " $str_query);
  3903.                 
  3904.                 if (intval(OCSP_OBJ::defaultReadDBObj()->getOne($str_query)))
  3905.                 {
  3906.                     $this->loadedUserRights[$str_colTrue;
  3907.                 else {
  3908.                     $this->loadedUserRights[$str_colFalse;
  3909.                 }
  3910.                 
  3911.                 return $this->loadedUserRights[$str_col];
  3912.             }
  3913.         else {
  3914.             if ($debugechoDebugLine(__FILE__,__LINE__,"no rights set for the form");
  3915.             return True;
  3916.         }        
  3917.     }
  3918.     
  3919.     /**
  3920.      * returns if the current user is allowed to open the form readonly
  3921.      *
  3922.      * NOTE rights are only checked if a row is found in T_DBMS_FORMRIGHTS
  3923.      * 
  3924.      * @return boolean 
  3925.      */
  3926.     public function curUserCanShow($debug=False)
  3927.     {
  3928.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::curUserCanShow()");
  3929.         return $this->curUserCanCol('FRI_SHOW',$debug);
  3930.     }
  3931.         
  3932.     /**
  3933.      * returns if the current user is allowed to open the form readonly
  3934.      *
  3935.      * NOTE rights are only checked if a row is found in T_DBMS_FORMRIGHTS
  3936.      * 
  3937.      * @return boolean 
  3938.      */
  3939.     public function curUserCanEdit($debug=False)
  3940.     {
  3941.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::curUserCanShow()");
  3942.         return $this->curUserCanCol('FRI_UPDATE',$debug);
  3943.     }    
  3944.     
  3945.     /**
  3946.      * returns if the current user is allowed to open the form readonly
  3947.      *
  3948.      * NOTE rights are only checked if a row is found in T_DBMS_FORMRIGHTS
  3949.      * 
  3950.      * @return boolean 
  3951.      */
  3952.     public function curUserCanInsert($debug=False)
  3953.     {
  3954.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::curUserCanShow()");
  3955.         return $this->curUserCanCol('FRI_INSERT',$debug);
  3956.     }    
  3957.  
  3958.     /**
  3959.      * returns if the current user is allowed to open the form readonly
  3960.      *
  3961.      * NOTE rights are only checked if a row is found in T_DBMS_FORMRIGHTS
  3962.      * 
  3963.      * @return boolean 
  3964.      */
  3965.     public function curUserCanDelete($debug=False)
  3966.     {
  3967.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::curUserCanShow()");
  3968.         return $this->curUserCanCol('FRI_DELETE',$debug);
  3969.     }        
  3970.     
  3971.     
  3972.     /**
  3973.      * returns if the current user is allowed to open the form readonly
  3974.      *
  3975.      * NOTE rights are only checked if a row is found in T_DBMS_FORMRIGHTS
  3976.      * 
  3977.      * @return boolean 
  3978.      */
  3979.     public function curUserCanExport($debug=False)
  3980.     {
  3981.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::curUserCanShow()");
  3982.         return $this->curUserCanCol('FRI_EXORT',$debug);
  3983.     }        
  3984.     
  3985.     /**
  3986.       * returns if the current user can save the form in the current mode
  3987.       *
  3988.       * @param boolean $debug 
  3989.       *
  3990.       * @return boolean 
  3991.       */
  3992.     function curUserCanSave($debug=False)
  3993.     {
  3994.           if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::curUserCanSave()");
  3995.  
  3996.         if (!pcf_is_instance_of($this->myControl,'OCSP_FRMCONTR'))
  3997.         {
  3998.             ocsp_logError(__FILE__,__LINE__,"controll not set",E_WARNING);
  3999.             return False;
  4000.         }
  4001.         if (method_exists($this->myControl,'curUserCanSave'))
  4002.         {
  4003.             return $this->myControl->curUserCanSave($debug);
  4004.         else {
  4005.             ocsp_logError(__FILE__,__LINE__,"method \$this->myControl(".get_class($this->myControl).")->curUserCanSave() not found",E_ERROR);
  4006.             exit();
  4007.         }
  4008.     }
  4009.  
  4010.  
  4011.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4012.     // compat handling
  4013.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4014.  
  4015.     /**
  4016.       * returns the html code for list from a query
  4017.       *
  4018.       * if $query is empty it is generated with:
  4019.       * <code>
  4020.       *     $query="SELECT ".$this->getList_SQLFieldLst().$this->getFromStmt();
  4021.       * </code>
  4022.       *
  4023.       * NOTE: use getList_SQLFieldLst() in the select statement if
  4024.       *       you have a LEFT JOIN to get the right fields and
  4025.       *       values
  4026.       *
  4027.       * layout class var used:
  4028.       *
  4029.       * - FRMLST_TABLEADD (<table $this->FRMLST_TABLEADD>)
  4030.       * - FRMLST_TRADD (<tr $this->FRMLST_TRADD[($rowNr % 2)] >)
  4031.       * - FRMLST_TDADD (<td $this->FRMLST_TDADD >)
  4032.       *
  4033.       *
  4034.       * @param int $nofRows return the number of rows processed
  4035.       * @param string $query if empty the query is generated
  4036.       * @param array $links 
  4037.       * @param string $sortLnk 
  4038.       * @param int $limit 
  4039.       * @param int $offset 
  4040.       * @param boolean $debug 
  4041.       *
  4042.       * @global array $OCSP_OBJ 
  4043.       * 
  4044.       * @returns string
  4045.       *
  4046.       * @since pk-04-12-31
  4047.       * @version pk-06-01-24
  4048.       *
  4049.       ***/
  4050.     function getHTMLLstFromQuery(&$nofRows,$query="",$links=NULL,$sortLnk=NULL,$limit=0,$offset=0,$debug=False
  4051.     {
  4052.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getHTMLLstFromQuery($query)");
  4053.         $str_ret="\n<!-- old style form call -->\n";
  4054.         
  4055.         $arr_settings=array(    
  4056.                 'LIMIT' => $limit,
  4057.                 'OFFSET'=> $offset,
  4058.             );
  4059.         $this->prepareList($arr_settings,$debug);
  4060.         
  4061.         if (is_array($links))
  4062.         {
  4063.             foreach($links as $str_cmd => $arr_detail)
  4064.             {
  4065.                 if (isset($arr_detail['A']&& (!empty($arr_detail['A'])))
  4066.                 {
  4067.                     if (preg_match("/^\<[A|a](.*)\>/",trim($arr_detail['A']),$arr_res))
  4068.                     {
  4069.                         $this->myControl->addCmdButton($str_cmd,$arr_res[1]);
  4070.                         //$str_ret.="<pre>".htmlspecialchars(print_r($arr_res,True))."</pre>";
  4071.                         if (isset($arr_detail['TEXT'])) {
  4072.                             $this->myView->setButtonTag($str_cmd,$arr_detail['TEXT']);
  4073.                         }
  4074.                     }                    
  4075.                 }
  4076.             }
  4077.         }
  4078.         
  4079.         $this->myControl->setListQuery($query);
  4080.         $nofRows=$this->myControl->getNofListRows();
  4081.         
  4082.         $str_ret.=$this->myView->getList($debug);
  4083.         
  4084.         if ($debug$str_ret.="<pre>".htmlspecialchars(print_r($links,True))."</pre>";
  4085.                 
  4086.         return $str_ret;
  4087.     }
  4088.     
  4089.  
  4090.  
  4091.  
  4092. // end class OCSP_FORM
  4093.  
  4094. ?>

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