Source for file DBMS_FORM.phpclass

Documentation is available at DBMS_FORM.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FORM.phpclass
  4.   *
  5.   * I splitted the old php/db/forms.phpclass into
  6.   * 2 files php/db/forms.phpinc and this to be
  7.   * more flexible with own styled forms
  8.   *
  9.   * now you can simply copy the php/db/forms/ dir
  10.   * to your own project path and set $GLOBALS['PRJOECT']['PHPFORMPATH']
  11.   * tho the new directory where you can change the classes to fit
  12.   * your requirements.
  13.   *
  14.   * @project    Open CSP-Management
  15.   * @package    forms
  16.   * @category   dbms_form
  17.   *
  18.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  19.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  20.   *
  21.   * @since  pk-03-12-18
  22.   *
  23.   ***/
  24.  
  25. /**
  26.  * requirements
  27.  */
  28.  
  29. require_once dirname(__FILE__)._OCSP_DIRSEP_."forms.phpinc";
  30.  
  31. /**
  32.   * Databese Formulars / Lists
  33.   *
  34.   * this class can be used to handel all kind of forms needed
  35.   * it is administrated through the admin link: /admin/dbms
  36.   *
  37.   *
  38.   * SRCVERSION 2
  39.   *
  40.   * - the fields are no longer stored just by serialize
  41.   *   DBMS_FORM::fieldLst instead a seralized are is stored
  42.   *   therefore the classes need not to be preloaded
  43.   *
  44.   * - each field requieres the a DBMS_FIELD::getObjectData()
  45.   *   function returning a 2 dimensional array:
  46.   *     -- $fldData['OBJDESC'] -> discription of the object
  47.   *     -- $fldData['OBJVAL']  -> get_object_vars($this)
  48.   *   @see DBMS_FORM::fieldLst_ToTxt()
  49.   *
  50.   *  - before the fieldObject is created by evaluating
  51.   *      <code>eval("\$fld=new ".$fldData['OBJDESC']['SRCFILE']."()");</code>
  52.   *      the object class source is included with
  53.   *      <code>require_once $GLOBALS['PROJECT']['PATH'].$fldData['OBJDESC']['SRCFILE']; </code>
  54.   *     @see DBMS_FORM::fieldLst_FromTxt()
  55.   *
  56.   * @project    Open CSP-Management
  57.   * @package    forms
  58.   * @category   dbms_form
  59.   *
  60.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  61.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  62.   *
  63.   * @version pk-04-10-05
  64.   * @version pk-05-11-04
  65.   * @version pk-07-02-27 ajax
  66.   *
  67.   ***/
  68. class DBMS_FORM {
  69.     /**
  70.       * @var int $frmId 
  71.       ***/
  72.     var $frmId          =0;
  73.     /**
  74.       * @var string $frmName        unique name of the form
  75.       ***/
  76.     var $frmName        =NULL;
  77.     /**
  78.       * @var string $frmRevsion     fore future use
  79.       ***/
  80.     var $frmRevision    =1;
  81.     /**
  82.       * @var longstring $frmDesc    Beschreibungstext
  83.       ***/
  84.     var $frmDesc        =NULL;
  85.     /**
  86.       * @var array $frmTables       array with db tablenames used in the form
  87.       ***/
  88.     var $frmTables      =array();
  89.     /**
  90.       * @var boolean $isTblDefault     the form is the default form for the one and only table it uses
  91.       ***/
  92.     var $isTblDefault   =FALSE;
  93.     /**
  94.       * @var array $frmKeys         array of the db key colum names
  95.       ***/
  96.     var $frmKeys        =array();
  97.     /**
  98.       * @var array $frmFields       array of field objects DBMS_FIELD or child classes
  99.       ***/
  100.     var $frmFields      =array();
  101.     /**
  102.       * @var string $frmQuery 
  103.       ***/
  104.     var $frmQuery       ="";
  105.     /**
  106.       * @var array $frmJoin         array of identifing foreign key COLUMNS
  107.       *                              key is the DB column name
  108.       *                              value is an array of DB columns (TABLENAME.COLNAME)
  109.       ***/
  110.     var $frmJoin        =array();
  111.  
  112.     /**
  113.       * @var array $frmRights       array of groups and access rights
  114.       * @todo                       form rights are not implemented jet
  115.       ***/
  116.     var $frmRights      =array();
  117.  
  118.     /**
  119.       * @var linuxTimestamp $lastDBCheck    timestamp when db-columns/fields has been checked
  120.       *                                      with the database tables
  121.       ***/
  122.     var $lastDBCheck    =0;
  123.  
  124.     /**
  125.       * @var boolean $debugMode 
  126.       * @since pk-04-07-23
  127.       ***/
  128.     var $debugMode      = FALSE;
  129.  
  130.     /**
  131.       * @var array $errors 
  132.       *
  133.       *  array (
  134.       *      [ERRORS] boolean
  135.       *      [FLD] array [LABEL],[MSG]
  136.       ***/
  137.     var $errors         = array();
  138.  
  139.     /**
  140.       * @var string $myDBMS_TABLEOBJ_include  table object class include
  141.       * @since pk-05-01-11
  142.       ***/
  143.     var $myDBMS_TABLEOBJ_include = "";
  144.  
  145.     /**
  146.       * @var string $myDBMS_TABLEOBJ_class  table object class
  147.       * @since pk-05-01-11
  148.       ***/
  149.     var $myDBMS_TABLEOBJ_class = "";
  150.  
  151.     /**
  152.       * @var array $buttons definition
  153.       * @since pk-05-02-16
  154.       * @todo add to dbms admin to customize buttons per form
  155.       ***/
  156.     var $HTMLFORM_button_src=array();
  157.  
  158.     /**
  159.       * @var string $gDBIDX $GLOBALS[] index of db object
  160.       * @since pk-05-02-17
  161.       * @deprecated since pk-07-06-28
  162.       ***/
  163.     var $gDBIDX="USRDB";
  164.  
  165.     /**
  166.       * @var OCSP_DB $myDBObj 
  167.       * @since pk-07-06-28
  168.       * @access protected
  169.       */
  170.     protected $myDBObj=NULL;
  171.  
  172.  
  173.     /**
  174.       * @var string $FRMLST_THADD list header th add tag
  175.       * @since pk-05-03-16
  176.       ***/
  177.     var $FRMLST_THADD="class=\"lstHeader\"";
  178.  
  179.     /**
  180.       * @var boolean $debugInsert 
  181.       * @since pk-05-03-23
  182.       ***/
  183.     var $debugInsert=FALSE;
  184.     /**
  185.       * @var boolean $debugUpdate 
  186.       * @since pk-05-03-23
  187.       ***/
  188.     var $debugUpdate=FALSE;
  189.     /**
  190.       * @var boolean $debugDelete 
  191.       * @since pk-05-03-23
  192.       ***/
  193.     var $debugDelete=FALSE;
  194.  
  195.     /**
  196.       * @var array $layoutFields 
  197.       * @since pk-05-04-18
  198.       ***/
  199.     var $layoutFields=array();
  200.  
  201.     /**
  202.       * @var boolean $lstShowRowNr 
  203.       * @since pk-05-07-05
  204.       ***/
  205.     var $lstShowRowNr=FALSE;
  206.  
  207.     /**
  208.       * name of the html forms
  209.       * @var string $myHTMLName 
  210.       * @since pk-05-09-16
  211.       ***/
  212.     var $myHTMLName="";
  213.  
  214.     /**
  215.       * show mode of the form
  216.       * @var int $frmMode 
  217.       * @since pk-05-11-04
  218.       ***/
  219.     var $frmMode=0;
  220.  
  221.     /**
  222.       * @var string $FRMEDITURL 
  223.       * @since pk-05-01-09
  224.       ***/
  225.     var $FRMEDITURL=NULL;
  226.     /**
  227.       * @var string $FRMDELETEURL 
  228.       ***/
  229.     var $FRMDELETEURL=NULL;
  230.  
  231.     /**
  232.       * @var string HTMLFORM_arrayName
  233.       * @since pk-06-03-07
  234.       ***/
  235.     var $HTMLFORM_arrayName="DBVAL";
  236.  
  237.     /**
  238.       * @var string HTMLFORM_URL_back if empty history.back()
  239.       ***/
  240.     var $HTMLFORM_URL_back="";
  241.  
  242.     /**
  243.       * @var int FRMLST_LIMIT number of lines per list (0=no limit)
  244.       * @since pk-06-05-08
  245.       ***/
  246.     var $FRMLST_LIMIT=0;
  247.  
  248.     /**
  249.       * some layout vars
  250.       *
  251.       **/
  252.  
  253.     var $FRMLST_TABLEADD    = "";
  254.     var $FRMLST_ROWADD      = "";
  255.     var $FRMLST_TRADD       = "";
  256.     var $FRMLST_TDADD       = "";
  257.     var $FRMLST_TDFLDADD    = "";
  258.     var $FRMLST_ADDBEFORELINKS = "";
  259.  
  260.     var $FRMTAGADD          = "";
  261.     var $FRMADDBUTTONS      = "";
  262.     var $FRMNOBUTTONS       = FALSE;
  263.  
  264.     /**
  265.       * @var string $myClassSrcFile sourcefile of the class
  266.       * @since pk-06-12-17
  267.       ***/
  268.     var $myClassSrcFile=__FILE__;
  269.  
  270.     /**
  271.       * the ajax object for the form
  272.       * NOTE: the class source is not automaticaly implemented
  273.       *
  274.       * @var AJAX_FORM $myAjaxObj 
  275.       * @since pk-07-02-27
  276.       * @access protected
  277.       ***/
  278.     protected $myAjaxObj=NULL;
  279.  
  280.     // ###############################
  281.  
  282.     /**
  283.       * @param int $aId     FRM_ID in the database if !0 the form is loaded from the database
  284.       * @param boolean $debug since pk-05-01-12
  285.       *
  286.       ***/
  287.     function DBMS_FORM($aId=0,$debug=FALSE{
  288.         $this->setHTMLFORM_BtnSource($debug);
  289.         if (intval($aId)) {
  290.             $this->frmId=intval($aId);
  291.             return $this->loadFromDb($debug);
  292.         }
  293.     }
  294.  
  295.     /**
  296.       * returns the value of an object variable
  297.       *
  298.       * @param string $varName 
  299.       *
  300.       * @return mixed 
  301.       *
  302.       * @since pk-06-07-27
  303.       *
  304.       ***/
  305.     function getObjectVar($varName{
  306.         if (isset($this->{$varName})) return $this->{$varName};
  307.         return NULL;
  308.     }
  309.  
  310.     /**
  311.       * sets the value of an object variable
  312.       *
  313.       * @param string $varName 
  314.       * @param mixed $value 
  315.       *
  316.       * @since pk-06-09-14
  317.       *
  318.       ***/
  319.     function setObjectVar($varName,$value{
  320.         if (!empty($varName)) $this->{$varName$value;
  321.     }
  322.  
  323.    /**
  324.      * @param string $idx 
  325.      *
  326.      * @since pk-05-02-17
  327.      * @deprecated since pk-07-06-28
  328.      *
  329.      */
  330.     function set_gDBIDX($idx{
  331.         $this->gDBIDX=$idx;
  332.     }
  333.  
  334.    /**
  335.      * gets gDBIDX
  336.      *
  337.      * @returns string
  338.      *
  339.      * @since pk-05-02-17
  340.      * @deprecated since pk-07-06-28
  341.      */
  342.     function get_gDBIDX({
  343.         if (empty($this->gDBIDX)) return "USRDB";
  344.         else return $this->gDBIDX;
  345.     }
  346.  
  347.     /**
  348.       * returns the db ojbect of the form and ensures the db object is connected
  349.       *
  350.       * @param boolean $debug 
  351.       *
  352.       * @return OCSP_DB 
  353.       * @since pk-07-06-28
  354.       * @access public
  355.       *
  356.       * @requires __OCSP_PHPINCPATH__."db/OCSP_DB.phpclass"
  357.       */
  358.     function &getDBObj($debug=FALSE)
  359.     {
  360.         return OCSP_OBJ::defaultReadDBObj();
  361.     }
  362.  
  363.  
  364.  
  365.  
  366.     /**
  367.       * returns the class file
  368.       *
  369.       * @param boolean $withoutOCSPPath 
  370.       *
  371.       * @returns string
  372.       *
  373.       * @version pk-06-12-17 // use of $this->myClassSrcFile instead of __FILE__
  374.       *
  375.       ***/
  376.     function getClassFile($withoutOCSPPath=FALSE{
  377.         if (isset($this->myClassSrcFile|| (empty($this->myClassSrcFile))) {
  378.             $this->myClassSrcFile=__FILE__;
  379.         }
  380.         if ($withoutOCSPPath{
  381.             return str_replace($GLOBALS['OCSP']['PATH'],"",$this->myClassSrcFile);
  382.         else {
  383.             return $this->myClassSrcFile;
  384.         }
  385.     }
  386.  
  387.     /**
  388.       * marks the form as new it will be inserted on $this::storeToDb
  389.       *
  390.       * @param string $frmName 
  391.       *
  392.       * @since pk-06-01-24
  393.       *
  394.       ***/
  395.     function setAsNew($frmName=NULL,$frmDesc="",$debug="0"{
  396.         if ($debugechoDebug(__FILE__,"<p><b>DBMS_FORM::setAsNew($frmName)</b> (".get_class($this).")</p>",0);
  397.  
  398.         $this->frmId=0;
  399.         if (!empty($frmName)) $this->frmName=$frmName;
  400.         else $this->frmName=$this->frmName."_NEW";
  401.         $this->lastDBCheck=0;
  402.         $this->isTblDefault=FALSE;
  403.         if (!empty($frmDesc)) $this->frmDesc=$frmDesc;
  404.     }
  405.  
  406.     /**
  407.       * returns the name of the form
  408.       *
  409.       * @returns string  unique name of the form
  410.       *
  411.       ***/
  412.     function getName({
  413.         return $this->frmName;
  414.     }
  415.  
  416.     /**
  417.       * @param string $aName 
  418.       * @since pk-05-09-14
  419.       ***/
  420.     function setName($aName{
  421.         $this->frmName=$aName;
  422.     }
  423.  
  424.     /**
  425.       * returns the name of the form in the html form
  426.       * <form name="....">
  427.       * @returns string
  428.       * @since pk-05-09-16
  429.       ***/
  430.     function getHTMLName({
  431.         if (!empty($this->myHTMLName))
  432.             return $this->myHTMLName;
  433.         else return $this->getName();
  434.     }
  435.  
  436.     /**
  437.       * sets the name of the form in the html form
  438.       * <form name="....">
  439.       * @param string 
  440.       * @since pk-05-09-16
  441.       ***/
  442.     function setHTMLName($aName{
  443.         $this->myHTMLName=$aName;
  444.     }
  445.  
  446.  
  447.  
  448.     /**
  449.       * @returns string
  450.       * @since pk-05-08-25
  451.       ***/
  452.     function getTitle({
  453.         if (empty($this->frmTitle)) return $this->getName();
  454.         return $this->frmTitle;
  455.     }
  456.  
  457.     /**
  458.       * returns the name of the form
  459.       *
  460.       * @returns int  ID of the form
  461.       * @version pk-03-10-22
  462.       *
  463.       ***/
  464.     function getId({
  465.         return intval($this->frmId);
  466.     }
  467.  
  468.     /**
  469.       * @param int $mode 
  470.       *
  471.       * @returns boolean $this->debugMode
  472.       *
  473.       * @since pk-04-07-23
  474.       * @version pk-06-01-03
  475.       *
  476.       ****/
  477.     function getDebugMode($mode=0{
  478.         switch($mode{
  479.             case FRM_MODE_NEW:
  480.             case FRM_MODE_COPY:
  481.                 return $this->debugInsert;
  482.             case FRM_MODE_EDIT:
  483.                 return $this->debugUpdate;
  484.             case FRM_MODE_DELETE:
  485.                 return $this->debugDelete;
  486.             default:
  487.                 return $this->debugMode;
  488.         }
  489.     }
  490.  
  491.  
  492.  
  493.     /**
  494.       * @returns int
  495.       * @since pk-05-11-04
  496.       ***/
  497.     function getFrmMode({
  498.         return $this->frmMode;
  499.     }
  500.  
  501.     /**
  502.       * @param int $mode 
  503.       * @since pk-05-11-04
  504.       ***/
  505.     function setFrmMode($mode{
  506.         return $this->frmMode=intval($mode);
  507.     }
  508.  
  509.  
  510.     /**
  511.       * creates a form
  512.       *
  513.       * @param string $aName        name of the form
  514.       * @param string $tbls         comma seperated list of tables used
  515.       * @param boolean   $asDefault    it's the default form ($aName equal $tbls)
  516.       *
  517.       * @returns bool;
  518.       *
  519.       ***/
  520.     function create($aName,$tbls="",$asDefault=0{
  521.         if (!$GLOBALS['USRDB']->isConnectedreturn FALSE;
  522.  
  523.         if (!$this->frmId{
  524.            $this->frmName=$aName;
  525.            if (!empty($tbls)) {
  526.                $this->frmTables=explode(" ",trim($tbls));
  527.                if (($asDefault&& (count($this->frmTables1)) {
  528.                    return FALSE;
  529.                }
  530.                $this->isTblDefault=$asDefault;
  531.            else if($asDefault{
  532.                return FALSE;
  533.            }
  534.  
  535.            $this->updateFields();
  536.            $this->storeToDb();
  537.         }
  538.         return $this->frmId;
  539.     }
  540.  
  541.  
  542.     /**
  543.       * unserializes a fieldRow (array element)
  544.       *
  545.       * @param string $key 
  546.       * @param array $fldDesc 
  547.       * @param boolean $debug 
  548.       * @param array $fldRow the database row since pk-06-07-28
  549.       *
  550.       * @since pk-05-07-14
  551.       * @version pk-05-10-25
  552.       * @version pk-05-12-01
  553.       * @version pk-06-07-28
  554.       * @version pk-07-03-05
  555.       *
  556.       ***/
  557.     function unserFldRow($key,$fldDesc,$debug=FALSE,$fldRow=NULL{
  558.         if ($debugecho "<p><b>DBMS_FORM::unserFldRow($key,...)</b> (".get_class($this).")</p><blockquote>";
  559.  
  560.         if (!isset($fldDesc['OBJDESC']['CLASS']|| empty($fldDesc['OBJDESC']['CLASS'])) // <pk-07-03-05>
  561.             $fldDesc['OBJDESC']['CLASS']=$fldRow['FLD_CLASS'];
  562.         }
  563.  
  564.         if (!class_exists($fldDesc['OBJDESC']['CLASS'])) {
  565.             if (!DBMS_field_IncludeSrc($fldDesc['OBJDESC']['CLASS'],$debug)) {
  566.                 if ($debugecho "<p>unserFldRow $key:</p><pre>".print_r($fldDesc,TRUE)."</pre><p>\$fldRow: </p><pre>".print_r($fldRow,TRUE)."</pre>";
  567.                 // <pk-07-03-05>
  568.  
  569.                 $b_found=FALSE;
  570.                 $s_incFile=pcf_parsePathTmpl($fldDesc['OBJDESC']['SRCFILE']);
  571.                 if (file_exists($s_incFile)) {
  572.                     require_once $s_incFile;
  573.                     $b_found=(class_exists($fldDesc['OBJDESC']['CLASS']));
  574.                 }
  575.                 if (!$b_found{
  576.                     $a_incFile=array();
  577.                     $a_incFile[]=pcf_parsePathTmpl($fldDesc['OBJDESC']['SRCFILE']);
  578.                     $a_incFile[]=$GLOBALS['PROJECT']['PATH'].$fldDesc['OBJDESC']['SRCFILE'];
  579.                     if (isset($fldRow['FLD_CLASS_SRC']&& (!empty($fldRow['FLD_CLASS_SRC']))) {
  580.                         $a_incFile[]=$GLOBALS['PROJECT']['PATH'].$fldRow['FLD_CLASS_SRC'];
  581.                         $a_incFile[]=$GLOBALS['PROJECT']['PHPINCPATH'].$fldRow['FLD_CLASS_SRC'];
  582.                         $a_incFile[]=__OCSP_PHPINCPATH__.$fldRow['FLD_CLASS_SRC'];
  583.                     }
  584.                     $a_incFile[]=$GLOBALS['PROJECT']['PHPINCPATH'].$fldDesc['OBJDESC']['SRCFILE'];
  585.                     $a_incFile[]=$fldDesc['OBJDESC']['SRCFILE'];
  586.                     $a_incFile[]=__OCSP_PHPINCPATH__."db/frmClasses/".basename($fldDesc['OBJDESC']['SRCFILE']);
  587.                     $a_incFile[]=__OCSP_PHPINCPATH__."db/frmClasses/".basename($fldRow['FLD_CLASS_SRC']);
  588.  
  589.                     while(!$b_found && list($s_classFile)=each($a_incFile)) {
  590.                         if (file_exists($s_classFile&& (!is_dir($s_classFile))) {
  591.                             require_once $s_classFile;
  592.                             if (class_exists($fldDesc['OBJDESC']['CLASS'])) {
  593.                                 $b_found=TRUE;
  594.                             }
  595.                         }
  596.                     }
  597.  
  598.                     if (!$b_found{
  599.                         $fldDesc['OBJDESC']['CLASS']="DBMS_FIELD";
  600.                         if ($debugecho "<p>CLASSFILE NOT FOUND -> CHANGED TO DBMS_FIELD</p>";
  601.                     }
  602.                 }
  603.             }
  604.         }
  605.  
  606.         $cmd="\$this->frmFields[\$key]=new ".$fldDesc['OBJDESC']['CLASS'].";";
  607.         if ($debugecho "<p><br />$cmd</p></blockquote>";
  608.         eval($cmd);
  609.         if (is_object($this->frmFields[$key])) {
  610.             $this->frmFields[$key]->setObjectVars($fldDesc['OBJVAL']);
  611.             if (isset($fldRow['FLD_SORTORDER']&& intval($fldRow['FLD_SORTORDER'])) // <pk-06-07-28> get sortorder from DB
  612.                 $this->frmFields[$key]->setOrderNr(intval($fldRow['FLD_SORTORDER']));
  613.             }
  614.             return TRUE;
  615.         else {
  616.             unset($this->frmFields[$key]);
  617.             return FALSE;
  618.         }
  619.     }
  620.  
  621.  
  622.     /**
  623.       * generates frmFields out of a string
  624.       * generated with DBMS_FORM::db_setFieldLst
  625.       *
  626.       * @param string $dbVal 
  627.       * @param boolean $debug 
  628.       *
  629.       * @returns boolean TRUE if succeed
  630.       *
  631.       * @since pk-04-10-05
  632.       * @version pk-05-07-14
  633.       *
  634.       ***/
  635.     function fieldLst_FromTxt($serTxt,$debug=FALSE{
  636.         if ($debugecho "<p><b>DBMS_FORM::fieldLst_FromTxt(...)</b> (".get_class($this).")</p>";
  637.  
  638.         $fldDescArr=unserialize($serTxt);
  639.         if ($debugecho "<p>\$serTxt<br />$serTxt</p><pre>".print_r($fldDescArr,TRUE)."</pre>";
  640.  
  641.         if (is_array($fldDescArr)) {
  642.             $hasError=FALSE;
  643.             if ($debugecho "<blockquote>";
  644.             foreach($fldDescArr as $key => $fldDesc{
  645.                 if (!is_array($fldDesc)) {
  646.                     $fldDesc=unserialize(base64_decode($fldDesc));
  647.                 }
  648.                 if (!$this->unserFldRow($key,$fldDesc,$debug)) {
  649.                     $hasError=TRUE;
  650.                 }
  651.             }
  652.  
  653.             if ($debugecho "<p>DONE fieldLst_FromTxt</p></blockquote>";
  654.             return ($hasError FALSE TRUE);
  655.         else {
  656.             if ($debugecho "<blockquote>\$fldDescArr<pre>".print_r($fldDescArr)."</pre></blockquote>";
  657.             return FALSE;
  658.         }
  659.     }
  660.  
  661.  
  662.     /**
  663.       * generates a string to store the fieldlist
  664.       * into a blob (text) field
  665.       *
  666.       * @param boolean $debug 
  667.       *
  668.       * @returns string
  669.       *
  670.       * @version pk-05-01-13
  671.       *
  672.       ***/
  673.     function fieldLst_ToTxt($debug=FALSE{
  674.         if ($debugecho "<p><b>DBMS_FORM::fieldLst_ToTxt(...)</b> (".get_class($this).")</p><blockquote>";
  675.  
  676.         $ret=array();
  677.         foreach($this->frmFields as $key => &$fld{
  678.             $ret[$key]=base64_encode(serialize($fld->getObjectData($debug)));
  679.         }
  680.         if ($debugecho "</blockquote>";
  681.         return serialize($ret);
  682.     }
  683.  
  684.  
  685.     /**
  686.       * returns an array representing the table row of the
  687.       * form object
  688.       *
  689.       * @param boolean $withoutNull 
  690.       * @param boolean $debug 
  691.       * @param int $srcVersion (pk-05-07-14)
  692.       *
  693.       * @returns array
  694.       *
  695.       * @since pk-04-10-07
  696.       * @version pk-05-03-23 debugMode changed
  697.       * @version pk-05-07-14
  698.       * @version pk-05-08-25
  699.       *
  700.       ***/
  701.     function getDBRow($withoutNull=FALSE,$debug=FALSE,$srcVersion=3{
  702.         if ($debugecho "<p><b>DBMS_FORM::getDBRow($withoutNull,$debug)</b> (".get_class($this).")</p><blockquote><hr />";
  703.  
  704.         $dbValues=array();
  705.         if ($this->frmId{
  706.            $dbValues['FRM_ID']      =$this->frmId;
  707.         }
  708.         $dbValues['FRM_REVISION']   =$this->getObjectVar('frmRevision');
  709.         $dbValues['FRM_NAME']       =$this->frmName;
  710.         $dbValues['FRM_TITLE']      =$this->getObjectVar('frmTitle')// <pk-05-08-25 />
  711.         $dbValues['FRM_DESC']       =$this->getObjectVar('frmDesc');
  712.  
  713.         $dbValues['FRM_TABLES']     =implode(" ",$this->frmTables);
  714.         $dbValues['FRM_ISDEFLT']    =$this->isTblDefault;
  715.  
  716.         $dbValues['FRM_QUERY']      =$this->frmQuery;
  717.         $dbValues['FRM_KEYS']       =serialize($this->frmKeys);
  718.  
  719.         // <pk-05-07-14>
  720.         if ($srcVersion 3{
  721.             if (empty($this->serFieldsV0)) /* <pk-05-01-12> */
  722.                 $dbValues['FRM_FIELDS']  =serialize($this->frmFields);
  723.             else {
  724.                 $dbValues['FRM_FIELDS']  =$this->serFieldsV0;
  725.             }
  726.             // <pk-04-10-05>
  727.             $fldStr=$this->fieldLst_ToTxt($debug);
  728.             if ($debugecho "<p>fldStr:</p><blockquote><pre>".print_r(unserialize($fldStr),TRUE)."</pre></blockquote>";
  729.             $dbValues['FRM_FIELDSV2']   =$fldStr;
  730.             $dbValues['FRM_SRCVERSION'=2;
  731.             /* </pk-04-10-05> */
  732.         else {
  733.             $dbValues['FRM_SRCVERSION'=$srcVersion;
  734.             $dbValues['FRM_FIELDS']     ="";
  735.             $dbValues['FRM_FIELDSV2']   ="";
  736.             // add the fields in a none db array used in cache
  737.             $fldStr=$this->fieldLst_ToTxt($debug);
  738.             if ($debugecho "<p>fldStr:</p><blockquote><pre>".print_r(unserialize($fldStr),TRUE)."</pre></blockquote>";
  739.             $dbValues['_NODB_FIELDS_']   =$fldStr;
  740.         }
  741.  
  742.         $dbValues['FRM_JOIN']       =serialize($this->frmJoin);
  743.  
  744.         $dbValues['FRM_RIGHTS']     =serialize($this->frmRights);
  745.         /* <pk-05-03-23> */
  746.         $debugMode=intval($this->debugMode);
  747.         $debugMode+=(intval($this->debugInsert))*2;
  748.         $debugMode+=(intval($this->debugUpdate))*4;
  749.         $debugMode+=(intval($this->debugDelete))*8;
  750.         $dbValues['FRM_DEBUG']      $debugMode;
  751.         /* </pk-05-03-23> */
  752.  
  753.  
  754.         $dbValues['FRM_UTIMESTAMP'=time();
  755.  
  756.         /* <pk-04-07-28> */
  757.         $dbValues['FRM_LNK_AFTERINSERT'$this->getObjectVar('FRM_LNK_AFTERINSERT');
  758.         $dbValues['FRM_LNK_AFTEREDIT']   $this->getObjectVar('FRM_LNK_AFTEREDIT');
  759.         $dbValues['FRM_LNK_AFTERDELETE'$this->getObjectVar('FRM_LNK_AFTERDELETE');
  760.         /* </ pk-04-07-28> */
  761.  
  762.         if ($withoutNull{
  763.             foreach($dbValues as $key => $val{
  764.                 if (!empty($val|| ($val === 0|| ($val === "0")) $tmp[$key]=$val;
  765.             }
  766.             $dbValues=$tmp;
  767.         }
  768.  
  769.         $dbValues['FRM_LAYOUT'base64_encode(serialize($this->layoutFields))/* <pk-05-04-18 /> */
  770.  
  771.         if ($debugecho "<hr /><p><b>END</b>DBMS_FORM::getDBRow()</p></blockquote>";
  772.         return $dbValues;
  773.     }
  774.  
  775.     /**
  776.       * sets the object values from a data array
  777.       *
  778.       * @param array $dbVal 
  779.       * @param boolean $asPopulated not used
  780.       * @param boolean $debug 
  781.       *
  782.       * @since pk-04-10-07
  783.       *
  784.       * @version pk-05-03-23
  785.       * @version pk-05-08-25
  786.       *
  787.       ***/
  788.     function setDBRow($dbVal,$asPopulated=TRUE,$debug=FALSE{
  789.         if ($debugecho "<p><b>DBMS_FORM::setDBRow($row,$asPopulated,$debug)</b> (".get_class($this).")</p>";
  790.  
  791.         $this->frmId        $dbVal['FRM_ID'];
  792.         $this->frmRevision  $dbVal['FRM_REVISION'];
  793.         $this->frmName      $dbVal['FRM_NAME'];
  794.         $this->frmTitle     $dbVal['FRM_TITLE']// <pk-05-08-25 />
  795.         $this->frmDesc      $dbVal['FRM_DESC'];
  796.         $this->frmTables    explode(" ",trim($dbVal['FRM_TABLES']));
  797.         $this->isTblDefault $dbVal['FRM_ISDEFLT'];
  798.         $this->frmQuery     $dbVal['FRM_QUERY'];
  799.         if (!isset($dbVal['FRM_JOIN']|| !empty($dbVal['FRM_JOIN']))
  800.         {
  801.             $this->frmJoin      unserialize($dbVal['FRM_JOIN']);
  802.         }
  803.         if (isset($dbVal['FRM_KEYS']&& !empty($dbVal['FRM_KEYS']))
  804.         {
  805.             $this->frmKeys      unserialize($dbVal['FRM_KEYS']);
  806.         }
  807.         if ($debugecho "<p>FRM_SRCVERSION: ".$dbVal['FRM_SRCVERSION']."</p>";
  808.  
  809.         if (intval($dbVal['FRM_SRCVERSION']2{
  810.             if ($debugecho "<p>SOURCEVERSION < 2 set fields</p>";
  811.             $this->frmFields    unserialize($dbVal['FRM_FIELDS']);
  812.             $this->serFieldsV0 $dbVal['FRM_FIELDS'];
  813.         else {
  814.             if ($dbVal['FRM_SRCVERSION'3{
  815.                 $fldStr=$dbVal['FRM_FIELDSV2'];
  816.             else {
  817.                 $fldStr=(isset($dbVal['_NODB_FIELDS_']$dbVal['_NODB_FIELDS_'"");
  818.             }
  819.             if (!empty($fldStr)) {
  820.                 if ($debugecho "<p>SOURCEVERSION 2 set fields</p>";
  821.                 if (substr($fldStr,0,8)=="~~BA64~~"{
  822.                     $fldStr=str_replace("~~BA64~~","",$fldStr);
  823.                     $fldStr=base64_decode($fldStr);
  824.                 }
  825.  
  826.                 if ($debugecho "<p>fldStr:<br />$fldStr</p>";
  827.                 if (!$this->fieldLst_FromTxt($fldStr,$debug)) {
  828.                     // $this->frmFields    = unserialize($dbVal['FRM_FIELDS']);
  829.                     $this->frmFields unserialize(base64_decode($dbVal['FRM_FIELDS']));
  830.                     $this->serFieldsV0 $dbVal['FRM_FIELDS'];
  831.                     if (!is_array($this->frmFields)) {
  832.                         echo "<p><b>ERROR LOADING FORM</b></p>";
  833.                         return FALSE;
  834.                     }
  835.                 }
  836.             }
  837.         }
  838.         $this->lastDBCheck  $dbVal['FRM_UTIMESTAMP'];
  839.         /* <pk-05-03-23> */
  840.         $debugMode=intval($dbVal['FRM_DEBUG']);
  841.         if ($debugMode 7$this->debugDelete=TRUE;$debugMode=$debugMode-8else $this->debugDelete=FALSE;
  842.         if ($debugMode 3$this->debugUpdate=TRUE;$debugMode=$debugMode-4else $this->debugUpdate=FALSE;
  843.         if ($debugMode 1$this->debugInsert=TRUE;$debugMode=$debugMode-2else $this->debugInsert=FALSE;
  844.         if ($debugMode 0$this->debugMode=TRUEelse $this->debugMode=FALSE;
  845.         /* </pk-05-03-23> */
  846.  
  847.         /* <pk-04-07-28> */
  848.         $this->FRM_LNK_AFTERINSERT  $dbVal['FRM_LNK_AFTERINSERT'];
  849.         $this->FRM_LNK_AFTEREDIT    $dbVal['FRM_LNK_AFTEREDIT'];
  850.         $this->FRM_LNK_AFTERDELETE  $dbVal['FRM_LNK_AFTERDELETE'];
  851.         /* </ pk-04-07-28> */
  852.  
  853.         /* <pk-05-04-18> */
  854.         $this->layoutFields unserialize(base64_decode($dbVal['FRM_LAYOUT']));
  855.         if (!is_array($this->layoutFields)) $this->layoutFields=array();
  856.         foreach($this->layoutFields as $key => $val{
  857.             $this->$key=$val;
  858.         }
  859.         /* </pk-05-04-18> */
  860.  
  861.         $query="SELECT * FROM T_DBMS_FORMRIGHTS WHERE FRM_ID=".$this->frmId;
  862.  
  863.         $this->frmRights=array();
  864.         $this->getDBObj();
  865.         if ($cursor=OCSP_OBJ::defaultReadDBObj()->query($query)) {
  866.             while($row $cursor->fetchArrayFld()) {
  867.                 $grp=$row['GRP_ID'];
  868.                 unset($row['GRP_ID']);
  869.                 unset($row['FRM_ID']);
  870.                 foreach($row as $key => $val{
  871.                     if (intval($val)) {
  872.                         $this->frmRights[$key][]=$grp;
  873.                     }
  874.                 }
  875.             }
  876.         }
  877.  
  878.         if (intval($dbVal['FRM_SRCVERSION']3{
  879.             if ($debugecho "<p>UPDATING FORM</p><blockquote>";
  880.             $this->storeToDb($debug);
  881.             if ($debugecho "</blockquote>";
  882.         }
  883.         return TRUE;
  884.     }
  885.  
  886.     /**
  887.       * stores a form object to database table T_DBMS_FORM
  888.       *
  889.       * uses $GLOBALS['USRDB'] as database object calls
  890.       * <code>
  891.       * if ($this->frmId) {
  892.       *    return $GLOBALS['USRDB']->replace("T_DBMS_FORM",$dbValues,$debug);
  893.       * } else {
  894.       *    INSERT FORM -> update fields -> UPDATE FROM
  895.       * }
  896.       * </code>
  897.       *
  898.       * @param boolean $debug 
  899.       *
  900.       * @returns bool
  901.       *
  902.       * @version pk-04-10-07
  903.       * @version pk-05-01-13 update fields after insert
  904.       * @version pk-05-07-11 T_DBMS_FORMFIELDS added
  905.       * @version pk-07-06-10 FRM_CLASS added
  906.       * @version pk-08-06-03
  907.       ***/
  908.     function storeToDb($debug=FALSE{
  909.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::storeToDb(...)");
  910.         $dbValues=$this->getDBRow(FALSE,$debug,3);
  911.         $dbValues['FRM_SRCVERSION']=3;
  912.  
  913.         $this->clearCache();
  914.         if ($debug{echo "<p>\$dbValues</p><pre>".print_r($dbValues,TRUE)."</pre>";}
  915.  
  916.         if ($this->frmId{
  917.             if (!($GLOBALS['USRDB']->replace("T_DBMS_FORM",$dbValues,$debug))) {
  918.                 echo "<p>ERROR SAVING FORM (replace)</p>";
  919.                 return FALSE;
  920.             }
  921.         else {
  922.             /* <pk-05-01-13> */
  923.             if ($this->frmId=$GLOBALS['USRDB']->insertArray("T_DBMS_FORM",$dbValues,$debug)) {
  924.                 if ($debugecho "<blockquote><p>Setting new frmId to fields</p>";
  925.                 foreach($this->frmFields as $key => $fldObj{
  926.                     $this->frmFields[$key]->setFrmId($this->frmId)// sets the form id to the fields
  927.                 }
  928.                 if ($this->storeToDb($debug)) {
  929.                     if ($debugecho "<hr width=\"75%\" align=\"center\"></blockquote><p>storeToDb return TRUE</p>";
  930.                     if (!DBMS_form_register($this,$debug)) {
  931.                         return FALSE;
  932.                     }
  933.                 else {
  934.                     if ($debugecho "<hr width=\"75%\" align=\"center\"></blockquote><p style=\"color:red;font-weight:bold;\">storeToDb return TRUE</p>";
  935.                     return FALSE;
  936.                 }
  937.             else {
  938.                 return FALSE;
  939.             }
  940.             /* </pk-05-01-13> */
  941.         }
  942.  
  943.         /* <pk-05-07-11> */
  944.         if (intval($this->frmId)) {
  945.             if (sizeof($this->frmFields1{
  946.                 // Delete all fields (as we don't know if some has been deleted)
  947.                 $GLOBALS['USRDB']->executeCmd("DELETE FROM T_DBMS_FORMFIELDS WHERE FRM_ID=".intval($this->frmId)." AND FRM_MODULE='DBMS'");
  948.             }
  949.  
  950.             // @var array $a_fldRow
  951.             $a_fldRow=array();
  952.  
  953.             foreach($this->frmFields as $key => $fld{
  954.                 $a_fldRow=array(
  955.                     'FRM_ID'            => $this->frmId,
  956.                     'FRM_CLASS'         => strtoupper(get_class($this)),
  957.                     'FLD_KEY'           => $key,
  958.                     'FLD_TABLE'         => $fld->getTable(),
  959.                     'FLD_NAME'          => $fld->getName(),
  960.                     'FRM_MODULE'        => 'DBMS',
  961.                     'FLD_IS_HIDDEN'     => intval($fld->isHidden()),
  962.                     'FLD_ENABLE_NEW'    => intval($fld->isEnabled(FRM_MODE_NEW)),
  963.                     'FLD_ENABLE_EDIT'   => intval($fld->isEnabled(FRM_MODE_EDIT)),
  964.                     'FLD_SHOW_IN_LIST'  => intval($fld->isHidden('list')),
  965.                     'FLD_SORTORDER'     => intval($fld->getOrderNr()),
  966.                     'FLD_CLASS'         => strtoupper(get_class($fld)),
  967.                     'FLD_CLASS_SRC'     => $fld->getSourceFile($debug),
  968.                     'FLD_B64OBJECT'     => base64_encode(serialize($fld->getObjectData($debug))),
  969.                     'FLD_LABEL'         => $fld->getLabel()     // <pk-05-10-04 />
  970.                 );
  971.                 $GLOBALS['USRDB']->replace("T_DBMS_FORMFIELDS",$a_fldRow,$debug);
  972.             }
  973.             return TRUE;
  974.         }
  975.         /* </pk-05-07-11> */
  976.     }
  977.  
  978.     /**
  979.       * loads the form form the database
  980.       *
  981.       * returns true if a row with $this->id is fetched from the db
  982.       * NOTE: table columns are hard coded changes to the database table
  983.       *       can create errors
  984.       *
  985.       * @returns boolean succeed?
  986.       *
  987.       * @version pk-04-07-28
  988.       * @version pk-05-07-14
  989.       *
  990.       * @var string $s_Query 
  991.       * @var DBCURSOR $o_Cursor 
  992.       * @var array $a_fldRow 
  993.       * @var array $a_fldDesc 
  994.       *
  995.       ***/
  996.     function loadFromDb($debug=FALSE{
  997.         if ($debugecho "<p><b>DBMS_FORM::loadFromDb(...)</b> (".get_class($this).")</p>";
  998.         if ($this->frmId{
  999.             $this->getDBObj();
  1000.             $query="SELECT * FROM T_DBMS_FORM WHERE FRM_ID=".intval($this->frmId);
  1001.             if ($dbVal=OCSP_OBJ::defaultReadDBObj()->quickQuery($query)) {
  1002.                 if ($this->setDBRow($dbVal,TRUE,$debug)) {
  1003.                     if (intval($dbVal['FRM_SRCVERSION']2{
  1004.                         $s_Query ="SELECT * FROM T_DBMS_FORMFIELDS ";
  1005.                         $s_Query.=" WHERE FRM_ID=".intval($this->frmId);
  1006.                         $s_Query.="   AND FRM_MODULE='DBMS'";
  1007.                         $s_Query.=" ORDER BY FLD_SORTORDER";
  1008.                         if ($debugecho "<p>".$s_Query."</p>";
  1009.                         if ($o_Cursor=OCSP_OBJ::defaultReadDBObj()->query($s_Query)) {
  1010.                             while ($a_fldRow=$o_Cursor->fetchArrayFld()) {
  1011.                                 if ($debugecho "<p>FIELD: ".$a_fldRow['FLD_KEY']."</p><blockquote>";
  1012.                                 $a_fldDesc=unserialize(base64_decode($a_fldRow['FLD_B64OBJECT']));
  1013.                                 $this->unserFldRow($a_fldRow['FLD_KEY'],$a_fldDesc,$debug,$a_fldRow);
  1014.                                 if ($debugecho "</blockquote>";
  1015.                             }
  1016.                         else {
  1017.                             echo "<p>ERROR IN QUERY$o_Query</p>";
  1018.                         }
  1019.                     }
  1020.                     return TRUE;
  1021.                 }
  1022.            else {
  1023.                return FALSE;
  1024.            }
  1025.         else {
  1026.             return FALSE;
  1027.         }
  1028.  
  1029.      }
  1030.  
  1031.     /**
  1032.       * removes the cache files of the form
  1033.       *
  1034.       * @param boolean $clear_tblcache 
  1035.       *
  1036.       * @version pk-06-04-23
  1037.       *
  1038.       ***/
  1039.     function clearCache($clear_tblcache=FALSE{
  1040.         if (!empty($GLOBALS['PROJECT']['OBJCACHEPATH'])) {
  1041.             @unlink($GLOBALS['PROJECT']['OBJCACHEPATH']."dbms_forms/".$this->frmId.".cache");
  1042.             @unlink($GLOBALS['PROJECT']['OBJCACHEPATH']."dbms_forms/".$this->frmName.".cache");
  1043.             if ($clear_tblcache{
  1044.                 if ($a_tbls=$this->getTableList()) {
  1045.                     foreach($this->frmTables as $tbl{
  1046.                         foreach (glob($GLOBALS['PROJECT']['OBJCACHEPATH'].$tbl."*.cache"as $s_fileName{
  1047.                             @unlink($s_fileName);
  1048.                         }
  1049.                     }
  1050.                 }
  1051.             }
  1052.         }
  1053.     }
  1054.  
  1055.  
  1056.     /**
  1057.       * merges the fields of an other form to $this
  1058.       * if ($prepend) is true the fields will be prepended
  1059.       * else appended to the fieldlist
  1060.       *
  1061.       * @param DBMS_FORM $frmMerge 
  1062.       * @param boolean $prepend 
  1063.       * @param boolean $debug 
  1064.       *
  1065.       * @returns boolean
  1066.       *
  1067.       * @since pk-06-01-24
  1068.       *
  1069.       ***/
  1070.     function mergeFormFields(&$frmMerge,$prepend=FALSE,$debug=FALSE{
  1071.         if ($debugechoDebug(__FILE__,"<p><b>DBMS_FORM::mergeForm(...)</b> (".get_class($this).")</p>",0);
  1072.  
  1073.         if (!is_object($frmMerge)) return FALSE;
  1074.  
  1075.         // get sorted fieldlists from both
  1076.         $a_addflds=$frmMerge->getFieldArr(TRUE);
  1077.         $a_myflds =$this->getFieldArr(TRUE);
  1078.  
  1079.         // determin sortindex ot the new fields
  1080.         if ($prepend)   $i_sort=1;
  1081.         else            $i_sort=sizeof($a_myflds)+1;
  1082.  
  1083.         foreach($a_addflds as $key => $o_fld{
  1084.             // add the form form fields to
  1085.             if (!$this->fieldExists($o_fld->getName(),$o_fld->getTable())) {
  1086.                 // avoid double entries
  1087.                 if ($debugechoDebug(__FILE__,"<p>".$o_fld->getName()." TBL ".$o_fld->getTable()."</p>",1);
  1088.                 $o_fld->sortOrder=$i_sort++// at position
  1089.                 $this->addFieldObj($o_fld,TRUE,$debug,TRUE);
  1090.             }
  1091.         }
  1092.  
  1093.         if ($prepend{
  1094.             // move the already existing fields behind the new ones
  1095.             foreach($a_myflds as $key => $o_fld{
  1096.                 $a_myflds[$key]->sortOrder=$i_sort++;
  1097.             }
  1098.         }
  1099.  
  1100.         // finaly add the tables of the merge form to myTable
  1101.         foreach($frmMerge->frmTables as $s_tbl{
  1102.             // adding tables to $aktForm
  1103.             if ($debugechoDebug(__FILE__,"<p>Adding Table$s_tbl</p>",1);
  1104.             $this->addTable($s_tbl,FALSE,$debug);
  1105.         }
  1106.  
  1107.         return TRUE;
  1108.  
  1109.     }
  1110.  
  1111.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1112.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1113.     /*                                                                                    */
  1114.     /*          FORM RIGHTS                                                               */
  1115.     /*                                                                                    */
  1116.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1117.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1118.  
  1119.     /**
  1120.       * private method checks right from table T_DBMS_FORMRIGHTS
  1121.       *
  1122.       * @param string $col right column name
  1123.       * @param int $usrId user id (if !intval($GLBOALS['USER'] is used)
  1124.       * @param boolean $debug 
  1125.       *
  1126.       * @returns boolean
  1127.       *
  1128.       * @since pk-05-02-15
  1129.       * @version pk-05-07-21
  1130.       * @version pk-06-03-06 memory cache $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col] added
  1131.       *
  1132.       ***/
  1133.     function p_userCan($col,$usrId=NULL,$debug=FALSE{
  1134.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::p_userCan($col,$usrId,...)",$this->getName(),0);
  1135.  
  1136.         if (!intval($usrId)) {
  1137.             if ($GLOBALS['USER']->isAdmin()) {
  1138.                 // no check for admins required
  1139.                 if ($debugecho "<p>No check for admin return TRUE</p>";
  1140.                 return TRUE;
  1141.             }
  1142.             $usrId=$GLOBALS['USER']->getId();             // check against current user
  1143.         }
  1144.  
  1145.         if ($GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]return TRUE// </pk-06-03-06> memory cached value
  1146.  
  1147.         if ($GLOBALS['OCSP']['FRMDEFAULTRIGHT']// <pk-06-03-06>
  1148.             $s_query="SELECT COUNT(*) FROM T_DBMS_FORMRIGHTS WHERE FRM_ID=".$this->getId();
  1149.             if (!intval($GLOBALS['USRDB']->quickQuery($s_query,0))) {
  1150.                 $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=TRUE;
  1151.                 return TRUE;
  1152.             }
  1153.         }
  1154.  
  1155.         if (!intval($usrId)) // we have a public user -> check against group id 0
  1156.             $query ="SELECT * FROM T_DBMS_FORMRIGHTS ";
  1157.             $query.=" WHERE FRM_ID=".$this->getId();
  1158.             $query.="   AND GRP_ID=0";
  1159.             $query.="   AND ".$col."<>0";
  1160.             if ($debugecho "<p>Checking Public</p>";
  1161.             if ($GLOBALS['USRDB']->quickQuery($query)) {
  1162.                 $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=TRUE;
  1163.                 return TRUE// the query returned a result -> public can do
  1164.             else {
  1165.                 return FALSE// no row found -> public can not do
  1166.             }
  1167.         }
  1168.  
  1169.         $query ="SELECT GRP_ID FROM T_DBMS_FORMRIGHTS WHERE FRM_ID=".$this->getId();
  1170.         $query.=" AND $col<>0 ORDER BY GRP_ID";
  1171.  
  1172.         if ($debugechoDebug(__FILE__,"<p>NOT PUBLIC$query</p>",1);
  1173.         if (!($allowedGrps=$GLOBALS['USRDB']->queryArray($query))) {
  1174.             return FALSE;
  1175.         }
  1176.  
  1177.         $query ="SELECT GRP_ID FROM T_SYS_GROUPMEMBER WHERE USR_ID=".intval($usrId);
  1178.         $query.=" AND GRP_ID IN (";
  1179.         $sep="";
  1180.         foreach($allowedGrps as $grpId{
  1181.             if ($grpId==0{
  1182.                 // public no more need to check
  1183.                 $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=TRUE;
  1184.                 return TRUE;
  1185.             }
  1186.             if (($grpId==-1&& ($usrId==$GLOBALS['USER']->getId())) {
  1187.                 $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=TRUE;
  1188.                 return TRUE// only logged in users and user is logged in
  1189.             }
  1190.             $query.=$sep.$grpId;
  1191.             $sep=",";
  1192.         }
  1193.         $query.= ")";
  1194.  
  1195.         if ($debugecho "<p>$query</p>";
  1196.         $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col]=$GLOBALS['USRDB']->quickQuery($query);
  1197.         return $GLOBALS['OCSP']['CACHE']['FRMRIGHTS'][$this->getId()][$usrId][$col];
  1198.     }
  1199.  
  1200.     /**
  1201.       * checks if a user is allowed to edit (update) the data
  1202.       *
  1203.       * @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
  1204.       * @param boolean $debug 
  1205.       *
  1206.       * @returns boolean
  1207.       *
  1208.       * @since pk-05-02-15
  1209.       *
  1210.       ***/
  1211.     function userCanEdit($usrId=0,$debug=FALSE{
  1212.         if ($debugecho "<p><b>DBMS_FORM::userCanEdit($usrId)</b> (".get_class($this)."/".$this->myName.")</p>";
  1213.         return $this->p_userCan("FRI_UPDATE",$usrId,$debug);
  1214.     }
  1215.  
  1216.     /**
  1217.       * checks if a user is allowed to add (insert) new data
  1218.       *
  1219.       * @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
  1220.       * @param boolean $debug 
  1221.       *
  1222.       * @returns boolean
  1223.       *
  1224.       * @since pk-05-03-17
  1225.       *
  1226.       ***/
  1227.     function userCanInsert($usrId=0,$debug=FALSE{
  1228.         if ($debugecho "<p><b>DBMS_FORM::userCanInsert($usrId)</b> (".get_class($this)."/".$this->myName.")</p>";
  1229.         return $this->p_userCan("FRI_INSERT",$usrId,$debug);
  1230.     }
  1231.  
  1232.  
  1233.     /**
  1234.       * checks if a user is allowed to delete the data
  1235.       *
  1236.       * @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
  1237.       * @param boolean $debug 
  1238.       *
  1239.       * @returns boolean
  1240.       *
  1241.       * @since pk-05-03-17
  1242.       *
  1243.       ***/
  1244.     function userCanDelete($usrId=0,$debug=FALSE{
  1245.         if ($debugecho "<p><b>DBMS_FORM::userCanDelete($usrId)</b> (".get_class($this)."/".$this->myName.")</p>";
  1246.         return $this->p_userCan("FRI_DELETE",$usrId,$debug);
  1247.     }
  1248.  
  1249.     /**
  1250.       * checks if a user is allowed to show the data
  1251.       *
  1252.       * @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
  1253.       * @param boolean $debug 
  1254.       *
  1255.       * @returns boolean
  1256.       *
  1257.       * @since pk-05-03-17
  1258.       *
  1259.       ***/
  1260.     function userCanShow($usrId=0,$debug=FALSE{
  1261.         if ($debugecho "<p><b>DBMS_FORM::userCanShow($usrId)</b> (".get_class($this)."/".$this->myName.")</p>";
  1262.         return $this->p_userCan("FRI_SHOW",$usrId,$debug);
  1263.     }
  1264.  
  1265.     /**
  1266.       * checks if a user is allowed to export the data
  1267.       *
  1268.       * @param int $usrId the user id if (!isset $GLOBALS['USER']->getId() is used)
  1269.       * @param boolean $debug 
  1270.       *
  1271.       * @returns boolean
  1272.       *
  1273.       * @since pk-06-01-25
  1274.       *
  1275.       ***/
  1276.     function userCanExport($usrId=0,$debug=FALSE{
  1277.         if ($debugecho "<p><b>DBMS_FORM::userCanExport($usrId)</b> (".get_class($this)."/".$this->myName.")</p>";
  1278.         return $this->p_userCan("FRI_EXPORT",$usrId,$debug);
  1279.     }
  1280.  
  1281.     /**
  1282.       * returns a html statement for no rights errors
  1283.       *
  1284.       * @param int $usrId 
  1285.       * @param int $mode 
  1286.       * @param array $dbVal 
  1287.       * @param string $txtInfo 
  1288.       * @param boolean $debug 
  1289.       *
  1290.       * @returns string
  1291.       *
  1292.       * @since pk-06-02-13
  1293.       *
  1294.       ***/
  1295.     function getHTMLFormNoRights($usrId=0,$mode=FRM_READONLY,$dbVal=NULL,$txtInfo="",$debug=FALSE{
  1296.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::getHTMLFormNoRights()","",0);
  1297.  
  1298.         $this->setHTMLFORM_objectVar($DBVAL,$mode,$frmAction,$nextURI,$arrName,$debug);
  1299.  
  1300.  
  1301.         $ret="\n\n<!-- ____________________FORMULAR START___________________________ -->\n\n";
  1302.         $s_ret ="<form name=\"".$this->getHTMLName()."\" ".$this->FRMTAGADD." >\n"// use form to have the right table layout if css and form id is used
  1303.         $ret.="<table ".$this->FRMTBLTAG.">\n";
  1304.         $ret.=$this->FRMTBLHEADERROW;
  1305.  
  1306.         $ret.="\t<tr><td class=\"frmErrorLabel\">Fehler</td><td class=\"frmErrorText\"><br /><br />Sie sind nicht berechtigt hier ";
  1307.         switch($mode{
  1308.             case FRM_MODE_READONLY:
  1309.                 $ret.="Daten zu sehen.";
  1310.                 break;
  1311.             case FRM_MODE_NEW:
  1312.                 $ret.="neue Daten anzulgen.";
  1313.  
  1314.                 break;
  1315.             case FRM_MODE_EDIT:
  1316.                 $ret.="Daten zu bearbeiten.";
  1317.                 break;
  1318.             case FRM_MODE_COPY:
  1319.                 $ret.="Daten zu kopieren";
  1320.                 break;
  1321.             default:
  1322.                 $ret.=".";
  1323.         }
  1324.         $ret.="<br /><br />&nbsp;</td></tr>\n";
  1325.  
  1326.         $ret ="\n\t<!-- _______ BUTTONS ______ -->\n\n";
  1327.         $ret.="\t<tr><td class=\"frmButtons\" colspan=\"2\">\n";
  1328.  
  1329.         if (!empty($_GET['OPENERURL'])) {
  1330.             // we are in a popup add close button
  1331.             $ret.="\t\t<a href=\"#\" onClick=\"javascript:{top.close();}\">";
  1332.             $ret.="<img src=\"".$this->HTMLFORM_button_src['CLOSE']."\" alt=\"schliessen\" border=\"0\" class=\"button\">";
  1333.             $ret.="</a>\n";
  1334.         else if (!empty($this->HTMLFORM_URL_back)) {
  1335.             $s_link=pcf_HTML_changeURI_GetValue($this->HTMLFORM_URL_back,session_name(),session_id());
  1336.             $ret.="\t\t<a href=\"".$s_link."\">";
  1337.             $ret.="<img src=\"".$this->HTMLFORM_button_src['BACK']."\" class=\"button\" alt=\"abbrechen\" border=\"0\" class=\"button\">";
  1338.             $ret.="</a>\n";
  1339.         else {
  1340.             $ret.="\t\t<a name=\"btnBack\" onClick=\"history.back()\">";
  1341.             $ret.="<img src=\"".$this->HTMLFORM_button_src['BACK']."\" class=\"button\" alt=\"abbrechen\" border=\"0\" class=\"button\">";
  1342.             $ret.="</a>\n";
  1343.         }
  1344.  
  1345.         $ret.="</table>\n";
  1346.         $ret.="</form>\n";
  1347.         $ret.="\n\n<!-- __________________FORMULAR ".$this->getName()." END_________________________ -->\n\n";
  1348.  
  1349.         return $ret;
  1350.     }
  1351.  
  1352.     /**
  1353.       * returns if the user is allowed in mode
  1354.       *
  1355.       * @param int $usrId 
  1356.       * @param int $mode 
  1357.       * @param boolean $debug 
  1358.       *
  1359.       * @returns boolean
  1360.       *
  1361.       * @since pk-06-03-06
  1362.       *
  1363.       ***/
  1364.     function userCanMode($usrId,$mode,$debug=FALSE{
  1365.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::userCanMode()","usrId=$usrId\nmode=$mode",0);
  1366.  
  1367.         switch($mode{
  1368.             case FRM_MODE_NEW:
  1369.             case FRM_MODE_COPY:
  1370.                 return $this->userCanInsert($usrId,$debug);
  1371.             case FRM_MODE_EDIT:
  1372.                 return $this->userCanEdit($usrId,$debug);
  1373.             case FRM_MODE_DELETE:
  1374.                 return $this->userCanDelete($usrId,$debug);
  1375.             default:
  1376.                 return $this->userCanShow($usrId,$debug);
  1377.         }
  1378.     }
  1379.  
  1380.  
  1381.  
  1382.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1383.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1384.     /*                                                                                    */
  1385.     /*              FIELD METHODS                                                         */
  1386.     /*                                                                                    */
  1387.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1388.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1389.  
  1390.     /**
  1391.       * checks if a field with $fldName exists for table $tbl (if not empty)
  1392.       *
  1393.       * @param string $fldName name of the field
  1394.       * @param string $tbl name of the table (only checked if not empty)
  1395.       *
  1396.       * @returns boolean
  1397.       *
  1398.       ***/
  1399.     function fieldExists($fldName,$tbl=""{
  1400.         foreach($this->frmFields as $key => $fld{
  1401.             if (!empty($tbl)) {
  1402.                 if ($fld->getKey(== $tbl.".".$fldNamereturn TRUE;
  1403.             else {
  1404.                 if ($fld->getName()==$fldNamereturn TRUE;
  1405.             }
  1406.         }
  1407.         return FALSE;
  1408.     }
  1409.  
  1410.     /**
  1411.       * transform a key to a dbusable column name
  1412.       * (only letters, numbers and underscore)
  1413.       *
  1414.       * @param string $key 
  1415.       * @returns string
  1416.       *
  1417.       *  since pk-04-01-11
  1418.       ***/
  1419.     function generateDBKey($key{
  1420.         return preg_replace("/[^a-zA-Z0-9_]/","_",$key);
  1421.     }
  1422.  
  1423.     /**
  1424.       * returns if the form has a sortcolumn (DBMS_FIELD_ORDERNR)
  1425.       *
  1426.       * @param boolean $withArrowOnly 
  1427.       * @param boolean $debug 
  1428.       *
  1429.       * @returns boolean
  1430.       *
  1431.       * @since pk-06-01-25
  1432.       *
  1433.       ***/
  1434.     function hasSortFld($withArrowOnly=FALSE,$debug=FALSE{
  1435.         if ($debugechoDebug(__FILE__,"<p><b>DBMS_FORM::hasSortColumn()</b> (".get_class($this).")</p>",0);
  1436.         foreach($this->frmFields as $key => $o_fld{
  1437.             if (strtoupper(get_class($o_fld))=="DBMS_FIELD_ORDERNR"{
  1438.                 if ($withArrowOnly && $o_fld->showArrows{
  1439.                     return TRUE;
  1440.                 else if (!$withArrowOnly{
  1441.                     return TRUE;
  1442.                 }
  1443.             }
  1444.         }
  1445.     }
  1446.  
  1447.     /**
  1448.       * creates a new field
  1449.       *
  1450.       * @param string $class    class name
  1451.       * @param string $key      column name
  1452.       * @param string $tbl      table name
  1453.       * @param int $orderNr 
  1454.       * @param string $label 
  1455.       * @param array $dbDesc 
  1456.       * @param boolean $debug 
  1457.       *
  1458.       * @returns DBMS_FIELD
  1459.       *
  1460.       * @version pk-04-01-11
  1461.       * @version pk-05-02-17
  1462.       *
  1463.       ***/
  1464.     function &newField($class,$key,$tbl=DBMS_NO_DBFIELD,$orderNr=0,$label="",$dbDesc=NULL,$debug=FALSE{
  1465.         /* <pk-05-02-17> */
  1466.         $debug=($debug || $this->debugMode);
  1467.         if ($debugecho "<p><b>DBMS_FORM::newField($class,$key,$tbl,$orderNr,.....)</b> (".get_class($this).")</p>";
  1468.         /* </pk-05-02-17> */
  1469.  
  1470.         if (empty($class)) $class="DBMS_FIELD";
  1471.  
  1472.         $fld=NULL;
  1473.         if (!is_array($dbDesc)) {
  1474.             $dbDesc=array();
  1475.             $dbDesc['TYPE']="unknown";
  1476.         }
  1477.         if (!isset($dbDesc['FLAGS']|| !is_array($dbDesc['FLAGS'])) {
  1478.             $dbDesc['FLAGS']=array();
  1479.         }
  1480.  
  1481.         if (!$orderNr{
  1482.             $orderNr count($this->frmFields)+1;
  1483.         else {
  1484.             reset($this->frmFields);
  1485.             while(list($key,$obj)=each($this->frmFields)) {
  1486.                 if ($obj->sortOrder >= $orderNr$obj->sortOrder++;
  1487.             }
  1488.         }
  1489.  
  1490.         // TODO
  1491.  
  1492.         if (!class_exists($class)) {
  1493.             /* <pk-05-06-14> */
  1494.             if (!isset($GLOBALS['PROJECT']['DBMSFLDCLASS_SRC'][$class])) {
  1495.                 if (isset($GLOBALS['DBMD_FLDCLASS_DESC'][$class])) {
  1496.                     $GLOBALS['PROJECT']['DBMSFLDCLASS_SRC'][$class]=$GLOBALS['PROJECT']['PHPINCPATH'].$GLOBALS['DBMD_FLDCLASS_DESC'][$class]['FLD_CLASS_SRC'];
  1497.                 }
  1498.             }
  1499.             /* </pk-05-06-14> */
  1500.             if (file_exists($GLOBALS['PROJECT']['DBMSFLDCLASS_SRC'][$class])) {
  1501.                 require_once $GLOBALS['PROJECT']['DBMSFLDCLASS_SRC'][$class];
  1502.             else if (file_exists($GLOBALS['OCSP']['DBMSFLD_PATH'].$class.".phpclass")) // <pk-05-11-14>
  1503.                 require_once $GLOBALS['OCSP']['DBMSFLD_PATH'].$class.".phpclass";
  1504.             else {
  1505.                 echo "<p>Error Loding class$class</p>";
  1506.                 echo "<pre>".print_r($GLOBALS['OCSP'],TRUE)."</pre>";
  1507.             }
  1508.         }
  1509.  
  1510.         $cmd="\$fld=new ".$class;
  1511.         $cmd .="(\$tbl,\$key,\$dbDesc,\$orderNr,\$label);";
  1512.         if (($debug)) echo "<pre>$cmd</pre>";
  1513.         eval($cmd);
  1514.         if ($debug{echo "<p>Field: ".$fld->getKey()." Class: ".get_class($fld)." created</p>";}
  1515.         $fld->setFrmId($this->frmId)/* <pk-04-02-23 /> */
  1516.         return $fld;
  1517.     }
  1518.  
  1519.     /**
  1520.       * adds a new field and get the class out of type
  1521.       *
  1522.       * @param string $class    class name
  1523.       * @param string $key      column name
  1524.       * @param array $dbDesc    db field description array
  1525.       * @param string $label 
  1526.       * @param string $tbl      table name
  1527.       * @param boolean $debug 
  1528.       *
  1529.       * @returns DBMS_FIELD
  1530.       *
  1531.       * @since pk-04-01-11
  1532.       * @version pk-06-02-01
  1533.       *
  1534.       ***/
  1535.     function &addClassField($class,$key,$dbDesc=NULL,$label="",$tbl=DBMS_NO_DBFIELD,$debug=FALSE{
  1536.         if ($debugechoDebug(__FILE__,"<p><b>DBMS_FORM::addClassField($class,$key,$dbDesc,$label,$tbl,$debug)</b> (".get_class($this).")</p>",0);
  1537.         $key=$this->generateDBKey($key);
  1538.         $this->frmFields[$tbl.".".$key]=&$this->newField($class,$key,$tbl,0,$label,$dbDesc,$debug);
  1539.         $this->frmFields[$tbl.".".$key]->setFrmId($this->frmId)// <pk-04-02-23 />
  1540.         $this->frmFields[$tbl.".".$key]->sortOrder=sizeof($this->frmFields)+1// <pk-06-02-01 />
  1541.         return $this->frmFields[$tbl.".".$key];
  1542.     }
  1543.  
  1544.     /**
  1545.       * adds a new field and get the class out of type
  1546.       * if the class could not derived from
  1547.       * $GLOBALS['DBMS_FIELD_CLASSES'][$type] DBMS_FIELD is used
  1548.       *
  1549.       * @param string $key      column name
  1550.       * @param string $type     column db type
  1551.       * @param array $dbDesc 
  1552.       * @param string $label 
  1553.       * @param string $tbl 
  1554.       * @param boolean $debug 
  1555.       *
  1556.       * @returns DBMS_FIELD
  1557.       *
  1558.       * @version pk-05-07-14
  1559.       *
  1560.       ***/
  1561.     function &addField($key,$type="unknown",$dbDesc=NULL,$label="",$tbl=DBMS_NO_DBFIELD,$debug=FALSE{
  1562.         if ($debugecho "<p><b>DBMS_FORM::addField($class,$key,$dbDesc,$label,$tbl,$debug)</b> (".get_class($this).")</p><blockquote>";
  1563.         if (!is_array($dbDesc)) {
  1564.             $dbDesc=array();
  1565.             $dbDesc['TYPE']=$type;
  1566.             $dbDesc['NULL']=TRUE// <pk-05-07-14>
  1567.         }
  1568.  
  1569.         if (!isset($dbDesc['FLAGS']|| !is_array($dbDesc['FLAGS'])) $dbDesc['FLAGS']=array()// <pk-06-07-27 /> E_ALL
  1570.  
  1571.         if (isset($GLOBALS['DBMS_FIELD_CLASSES'][$type]&& $GLOBALS['DBMS_FIELD_CLASSES'][$type]{
  1572.             $class=$GLOBALS['DBMS_FIELD_CLASSES'][$type];
  1573.         else {
  1574.             $class="DBMS_FIELD";
  1575.         }
  1576.         return $this->addClassField($class,$key,$dbDesc,$label,$tbl,$debug);
  1577.     }
  1578.  
  1579.     function &addPKField($key,$label="",$type="unknown",$dbDesc=NULL,$tbl=DBMS_NO_DBFIELD,$debug=FALSE{
  1580.         $key=$this->generateDBKey($key);
  1581.         $dbDesc['PRIMARY_KEY']=TRUE;
  1582.         $dbDesc['NULL']=FALSE;
  1583.  
  1584.         $fld=$this->addField($key,$type,$dbDesc,$label,$tbl,$debug);
  1585.         $fld->hideNew=TRUE;
  1586.         $fld->enbaleNew=FALSE;
  1587.         $tmp['TABLE']=$tbl;
  1588.         $tmp['NAME'=$key;
  1589.         $this->frmKeys[]=$tmp;
  1590.         return $fld;
  1591.     }
  1592.  
  1593.     function &addNoDbField($key,$label="",$type="unknown",$tbl=DBMS_NO_DBFIELD,$debug=FALSE{
  1594.         if ($debugecho "<p><b>DBMS_FORM::addNoDbField($key,$label,$type,$tbl,...)</b> (".get_class($this).")</p>";
  1595.         return $this->addField($key,$type,NULL,$label,$tbl,$debug);
  1596.     }
  1597.  
  1598.     function &addNoDbClassField($class,$key,$label="",$tbl=DBMS_NO_DBFIELD,$debug=FALSE{
  1599.         if ($debugecho "<p><b>DBMS_FORM::addNoDbClassField($class,$key,$label,$tbl,...)</b> (".get_class($this).")</p>";
  1600.         return $this->addClassField($class,$key,array("NULL" => TRUE),$label,$tbl,$debug);
  1601.     }
  1602.  
  1603.     /**
  1604.       * adds afield object to the form
  1605.       *
  1606.       * @param DBMS_FIELD $field 
  1607.       * @param boolean $keepTable 
  1608.       * @param boolean $debug 
  1609.       * @param boolean $keepSort 
  1610.       *
  1611.       * @returns DBMS_FIELD;
  1612.       *
  1613.       * @since pk-05-02-17
  1614.       * @version pk-06-01-11
  1615.       * @version pk-06-07-14
  1616.       *
  1617.       ***/
  1618.     function &addFieldObj($field,$keepTable=TRUE,$debug=FALSE,$keepSort=FALSE{
  1619.         $this->frmFields[$field->getKey()]=$field;
  1620.         if (!$keepSort{
  1621.             $field->sortOrder=sizeof($this->frmFields);
  1622.         else // <pk-06-07-14 />
  1623.             $a_fldLst=$this->getFieldArr(TRUE);
  1624.             $i_sortNr=$field->sortOrder;$i_idx=$i_sortNr;
  1625.             $i_end=intval(key(end($a_fldLst)))+1;
  1626.             while($i_idx<$i_end{
  1627.                 if (is_object($a_fldLst[$i_idx])) {
  1628.                     $a_fldLst[$i_idx]->sortOrder=++$i_sortNr;
  1629.                 }
  1630.                 $i_idx++;
  1631.             }
  1632.         }
  1633.         $field->myFrmId=$this->getId();
  1634.         return $this->frmFields[$field->getKey()];
  1635.     }
  1636.  
  1637.     /**
  1638.       * adds a field object to the form
  1639.       *
  1640.       * @param DBMS_FIELD     $field 
  1641.       * @param boolean           $debug 
  1642.       *
  1643.       * @returns &DBMS_FIELD   pointer to the copy of the field inserted to the form
  1644.       *
  1645.       * @version pk-05-02-17
  1646.       *
  1647.       ***/
  1648.     function &addNoDBFieldObj($field,$debug=FALSE{
  1649.         if ($debugprint_r($field);
  1650.         $this->frmFields[$field->getKey()]=$field;
  1651.         $field->setOrderNr(sizeof($this->frmFields))/* <pk-05-02-17 /> */
  1652.         $field->setFrmId($this->getId());
  1653.         return $this->frmFields[$field->getKey()];
  1654.     }
  1655.  
  1656.  
  1657.     /**
  1658.       * creates a db column out of a field
  1659.       *
  1660.       * @param string $fldName 
  1661.       * @param bool $debug 
  1662.       *
  1663.       * @return bool 
  1664.       *
  1665.       * @since pk-06-01-11
  1666.       * @version pk-06-04-23 clearCache added
  1667.       ***/
  1668.     function createDBColumn($fldName,$debug=FALSE{
  1669.         if ($debugecho "<p><b>DBMS_FORM::createDBColumn($fldName,$debug)</b> (".get_class($this).")</p>";
  1670.  
  1671.         if ($fld=$this->frmFields[$fldName]{
  1672.             // check if we have a table
  1673.             $s_tbl=$fld->getTable();
  1674.             if ($GLOBALS[$this->get_gDBIDX()]->tblExists($s_tbl)) {
  1675.                 if (($fld->dbDesc['TYPE'!= "layout"&& (substr($fld->myTableAlias,0,8!= "OBJVALS_")) {
  1676.                     // ok we have no layout field and no object value field -> we can alter the table
  1677.                     // adjust fields db description
  1678.                     $dbDesc=$fld->getdbDesc();
  1679.                     if (!intval($dbDesc['LEN'])) {
  1680.                         $dbDesc['LEN']=$fld->maxlength// set field length to max input length
  1681.                     }
  1682.                     $dbDesc['NULL']=1;              // always allow null to avoid errors if the table is used
  1683.                                                     // for other forms which do not use the column
  1684.                                                     // -> use the form to check null values
  1685.  
  1686.                     $s_cmd ="ALTER TABLE ".$s_tbl." ADD ".$fld->getName();
  1687.                     $s_cmd.= $GLOBALS[$this->gDBIDX]->getColumnDef($dbDesc,$debug);
  1688.                     if ($debugecho "<p>CMD: <b>$cmd</b></p>\n";
  1689.                     $GLOBALS[$this->get_gDBIDX()]->executeCmd($s_cmd);
  1690.                     if ($fld->setTable($s_tbl,"",TRUE,$debug)) {
  1691.                         $this->clearCache(TRUE);
  1692.                         return TRUE;
  1693.                     }
  1694.                 }
  1695.             }
  1696.         }
  1697.         return FALSE;
  1698.     }
  1699.  
  1700.  
  1701.  
  1702.  
  1703.     // #########################################
  1704.  
  1705.     /**
  1706.       * deletes field
  1707.       *
  1708.       * @param boolean $field 
  1709.       * @param boolean $debug 
  1710.       *
  1711.       * @access public
  1712.       */
  1713.     function deleteField($field,$debug=FALSE{
  1714.         if (is_object($this->frmFields[$field])) {
  1715.             if ($debugecho "deleteing field$field<br />";
  1716.             $ordNr=$this->frmFields[$field]->sortOrder;
  1717.             reset($this->frmFields);
  1718.             while(list($key,$obj)=each($this->frmFields)) {
  1719.                 if ($obj->sortOrder >= $ordNr$obj->sortOrder--;
  1720.             }
  1721.         }
  1722.         unset($this->frmFields[$field]);
  1723.     }
  1724.  
  1725.     // #########################################
  1726.  
  1727.     /**
  1728.       * checks if the table has changed
  1729.       *
  1730.       * @param boolean $debug 
  1731.       *
  1732.       * @version pk-06-08-02 hide new fields by default
  1733.       *
  1734.       ***/
  1735.     function updateFields($debug=FALSE{
  1736.         if ($debugecho "<p><b>DBMS_FORM::updateFields($debug)</b> (".get_class($this).") </p><blockquote>";
  1737.         if (!$GLOBALS['USRDB']->isConnectedreturn FALSE;
  1738.  
  1739.         $b_hide ((sizeof($this->frmFields)1TRUE FALSE)// <pk-06-08-02> we alread have fields -> hide by default
  1740.         $this->frmKeys=array();
  1741.         foreach($this->frmTables as $tbl// <pk-06-08-09> bugfix
  1742.             if ($debugecho "<p>checking Table$tbl</p>";
  1743.             if ($fields=$GLOBALS['USRDB']->getDBTblDesc($tbl)) {
  1744.                 foreach($fields as $key => $a_fldDesc{
  1745.                     if ($debugecho "<pre>$key: \n".print_r($a_fldDesc,TRUE)."</p>";
  1746.                     if (empty($this->frmFields[$tbl.".".$key])) {
  1747.                         $o_fld=$this->addField($key,$a_fldDesc['TYPE'],$a_fldDesc,"",$tbl,$debug);
  1748.                         if ($b_hide// <pk-06-08-02>
  1749.                             $o_fld->setHidden();
  1750.                         }
  1751.                     else {
  1752.                         if ($debug{echo "<pre>";get_class($this->frmFields[$tbl.".".$key]);echo "</pre>";}
  1753.                         $this->frmFields[$tbl.".".$key]->check($a_fldDesc);
  1754.                         $this->frmFields[$tbl.".".$key]->setFrmId($this->frmId)/* <pk-04-02-23 /> */
  1755.                         $fld=&$this->frmFields[$tbl.".".$key];
  1756.                     }
  1757.                     if ((is_object($fld&& $fld->isPrimaryKey()) || intval($a_fldDesc['PRIMARY_KEY'])) // <pk-06-08-07 /> bugfix
  1758.                         $tmp['TABLE']=$tbl;
  1759.                         $tmp['NAME'=$key;
  1760.                         $this->frmKeys[]=$tmp;
  1761.                     }
  1762.                 }
  1763.             }
  1764.         }
  1765.         $this->storeToDb();
  1766.         $this->lastDBCheck=time();
  1767.         if ($debugecho "<p>frmKeys:</p><pre>".print_r($this->frmKeys,TRUE)."</pre></blockquote>";
  1768.     }
  1769.  
  1770.     /**
  1771.       * sets myForm in each field
  1772.       *
  1773.       * @param boolean $debug 
  1774.       *
  1775.       * @since pk-05-09-14
  1776.       *
  1777.       ***/
  1778.     function setFldFrmObj($debug=FALSE{
  1779.         if ($debugecho "<p><b>DBMS_FORM::setFldFrmObj()</b> (".get_class($this).")</p>";
  1780.  
  1781.         if ($a_fldKeys=array_keys($this->frmFields)) {
  1782.             foreach($a_fldKeys as $s_fldKey{
  1783.                 if (is_object($this->frmFields[$s_fldKey])) {
  1784.                     $this->frmFields[$s_fldKey]->setMyForm($this);
  1785.                 }
  1786.             }
  1787.         }
  1788.     }
  1789.  
  1790.  
  1791.     /**
  1792.       * returns the number of fields
  1793.       *
  1794.       * @return int 
  1795.       * @since pk-07-04-23
  1796.       * @access public
  1797.       */
  1798.     function getNofFields()
  1799.     {
  1800.         return sizeof($this->frmFields);
  1801.     }
  1802.  
  1803.     // ###############################
  1804.  
  1805.     /**
  1806.       * populates the join array $frmJoin
  1807.       *
  1808.       * first find all primary keys
  1809.       * if a primary key COLNAME occures more then 1 time
  1810.       * an array with field names (TABLENAME.COLNAME) as value is
  1811.       * added to $frmJoin[COLNAME]
  1812.       *
  1813.       * @param boolean $debug  show debug info
  1814.       *
  1815.       * @version pk-06-01-25
  1816.       *
  1817.       ***/
  1818.     function generateJoin($debug=FALSE{
  1819.         $debug=($debug || $this->debugMode);
  1820.         if ($debugechoDebug(__FILE__,"<p><b>DBMS_FORM::generateJoin()</b> ".get_class($this)."</p>",0);
  1821.  
  1822.         $a_joinFlds      array();
  1823.         $a_joinCandidatesarray()// <pk-06-01-25 />
  1824.  
  1825.         if (sizeof($this->frmTables1{             // we have 2 or more table we need a join
  1826.             if ($this->lastDBCheck+600 time()) {      // check if the object is sync with the database
  1827.                 $this->updateFields($debug);            // update object
  1828.             }
  1829.             reset ($this->frmFields);
  1830.             while(list($key,$field)=each($this->frmFields)) {   // note $key is TABLENAME.COLNAME
  1831.                 if ($field->dbDesc['PRIMARY_KEY']{            // its a primary key
  1832.                     $a_joinFlds[$field->myName][]=$key;         // add it to a COLNAME array
  1833.                 else if (!empty($field->dbDesc['KEY'])) {     // <pk-06-01-25>
  1834.                     $a_joinCandidates[$field->myName][]=$key;   // add key fields to joinCandidates
  1835.                 }
  1836.             }
  1837.  
  1838.             if ($debugecho "<pre>PK's:\n".print_r($a_joinFlds,TRUE)."\nKEYS:\n".print_r($a_joinCandidates,TRUE)."</pre>";
  1839.  
  1840.             reset($a_joinFlds);
  1841.             while(list($key,$val)=each($a_joinFlds)) {
  1842.                 if ($debugprint_r($val);
  1843.                 if (sizeof($val1{                     // we found more then one COLNAME as pk in the form
  1844.                     $this->frmJoin[$key]=$val;
  1845.                 else if ($a_joinCandidates[$key]{       // we found a Primary key and a key with same colname in
  1846.                                                             // an other table
  1847.                     $this->frmJoin[$key]=array_merge($val,$a_joinCandidates[$key]);
  1848.                 }
  1849.             }
  1850.         }
  1851.     }
  1852.  
  1853.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1854.     /*  table methods                                                    */
  1855.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1856.  
  1857.  
  1858.     /**
  1859.       * adds a table to the form
  1860.       *
  1861.       * @param string $aTable name of the tablename
  1862.       * @param boolean $isDefaultFrm the form is default for the table
  1863.       * @param boolean $debug since pk-05-02-22
  1864.       *
  1865.       * @returns boolean
  1866.       *
  1867.       * @version pk-05-02-22
  1868.       * @version pk-06-01-11
  1869.       *
  1870.       ***/
  1871.     function addTable($aTable,$isDefaultFrm=FALSE,$debug=FALSE){
  1872.         if ($debugechoDebug(__FILE__,"<p><b>DBMS_FORM::addTable($aTable,$isDefaultFrm,...)</b> (".get_class($this).")</p>",0);
  1873.  
  1874.         if (!$GLOBALS['USRDB']->isConnectedreturn FALSE;
  1875.         // if ($this->isTblDefault && !empty($this->frmTables)) return FALSE; <pk-06-01-11 />
  1876.  
  1877.         if (!($arr=$GLOBALS['USRDB']->getDBTblDesc($aTable))) {
  1878.            if ($debugechoDebug(__FILE__,"<p>Could not get DBTblDesc for $aTable</p>\n",1);
  1879.            return FALSE;
  1880.         }
  1881.  
  1882.         if (!in_array($aTable,$this->frmTables)) {
  1883.            $this->frmTables[]=$aTable;
  1884.            $this->isTblDefault=$isDefaultFrm;
  1885.         }
  1886.  
  1887.         $this->updateFields();
  1888.         return TRUE;
  1889.     }
  1890.  
  1891.  
  1892.     /**
  1893.       * removes a table from the form
  1894.       *
  1895.       * @param string $aTable name of the tablename
  1896.       * @param boolean $debug 
  1897.       *
  1898.       * @returns boolean
  1899.       *
  1900.       ***/
  1901.     function removeTable($aTable,$debug=FALSE{
  1902.         if ($debugecho "<p><b>DBMS_FORM::removeTable($aTable,...)</b> (".get_class($this).")</p>";
  1903.  
  1904.         $aArr=$this->frmTables;
  1905.         $this->frmTables=array();
  1906.         reset($aArr);
  1907.         while(list($key,$val)=each($aArr)) {
  1908.             if ($val != $aTable{
  1909.                 $this->frmTables[]=$aTable;
  1910.             }
  1911.         }
  1912.  
  1913.         $this->removeTableFields($aTable,$debug);   /* <pk-04-07-30 /> */
  1914.         if ($debugprint_r($this->frmTables);
  1915.     }
  1916.  
  1917.     /**
  1918.       * removes all fields of a Table
  1919.       *
  1920.       * @param string $aTable 
  1921.       * @param boolean $debug 
  1922.       *
  1923.       * @since pk-04-07-30
  1924.       *
  1925.       ***/
  1926.     function removeTableFields($aTable,$debug=FALSE{
  1927.         $aArr=array();
  1928.         reset($this->frmFields);
  1929.         while(list($key,$field)=each($this->frmFields)) {
  1930.             if ($field->getTable(== $aTable)
  1931.                 unset($this->fileds[$key]);
  1932.             else
  1933.                 $aArr[$key]=&$this->frmFields[$key];
  1934.         }
  1935.         $this->frmFields=$aArr;
  1936.     }
  1937.  
  1938.     /**
  1939.       * check if the form uses $aTable
  1940.       *
  1941.       * @param string $aTable 
  1942.       *
  1943.       * @returns boolean
  1944.       *
  1945.       * @since pk-05-02-22
  1946.       *
  1947.       ***/
  1948.     function usesTable($aTable{
  1949.         if (!is_array($this->frmTables)) return FALSE;
  1950.         if (empty($aTable))              return FALSE;
  1951.         return (in_array($aTable,$this->frmTables));
  1952.     }
  1953.  
  1954.     // ###############################
  1955.  
  1956.  
  1957.     function writeTableList($aSelectName="",$sep="\n"{
  1958.         if (!empty($aSelectName)) {
  1959.             echo "CODE IMPLEMENTED";
  1960.         else {
  1961.             echo trim(implode($sep,$this->frmTables),$sep);
  1962.         }
  1963.     }
  1964.  
  1965.     /**
  1966.       * returns the table list
  1967.       *
  1968.       * @returns array
  1969.       *
  1970.       * @since pk-04-07-28
  1971.       *
  1972.       ***/
  1973.     function getTableList({
  1974.         return $this->frmTables;
  1975.     }
  1976.  
  1977.     /**
  1978.       * returns the key array
  1979.       *
  1980.       * @param boolean $nameToIndex     set the array index to the column name
  1981.       * @param boolean $withoutTable    don't use table names in array index (see the TABLES field in value array)
  1982.       *
  1983.       * @returns array
  1984.       *
  1985.       ***/
  1986.     function getKeyArray($nameToIndex=FALSE,$withoutTable=TRUE{
  1987.         // <pk-06-05-15>
  1988.         if ($nameToIndex{
  1989.             $a_ret=array();
  1990.             foreach($this->frmKeys as $a_key{
  1991.                 if ($withoutTable{
  1992.                     $s_idx=$a_key['NAME'];
  1993.                 else {
  1994.                     $s_idx=$a_key['TABLE'].".".$a_key['NAME'];
  1995.                 }
  1996.                 $a_ret[$s_idx]=$a_key;
  1997.                 $a_ret[$s_idx]['TABLES'][]=$a_key['TABLE'];
  1998.             }
  1999.             return $a_ret;
  2000.         }
  2001.         // </pk-06-05-15>
  2002.         return $this->frmKeys;
  2003.     }
  2004.  
  2005.     /**
  2006.       * returns an array with the key column names
  2007.       *
  2008.       * @returns array
  2009.       *
  2010.       * @since pk-06-02-06
  2011.       *
  2012.       ***/
  2013.     function getKeyColNames({
  2014.         $a_ret=array();
  2015.         foreach($this->frmKeys as $a_key{
  2016.             $a_ret[$a_key['NAME']]=$a_key['NAME'];
  2017.         }
  2018.         return $a_ret;
  2019.     }
  2020.  
  2021.  
  2022.     function getFieldDescArray({
  2023.         $retArr=array();
  2024.         foreach ($this->frmFields as $key => $fldObj{
  2025.             $retArr[$key]   =$fldObj->dbDesc;
  2026.             $retArr['NAME'=$fldObj->myName;
  2027.         }
  2028.         return $retArr;
  2029.     }
  2030.  
  2031.     /**
  2032.       * generates a sql from statement
  2033.       *
  2034.       * @param boolean $debug (since pk-06-07-31)
  2035.       *
  2036.       * @returns string
  2037.       *
  2038.       * @version pk-05-02-16
  2039.       *
  2040.       * @todo currently only mysql join is implemented
  2041.       *
  2042.       ***/
  2043.     function getFromStmt($debug=FALSE{
  2044.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::getFromStmt()");
  2045.  
  2046.         reset($this->frmTables);
  2047.         if (!empty($this->frmQuery)) {
  2048.             if ($debugechoDebug(__FILE__,"<p>returning stored query: <br />".$this->frmQuery."</p>");
  2049.             return $this->frmQuery;
  2050.         }
  2051.         $ret=""// <pk-06-09-11 /> E_ALL
  2052.  
  2053.         if (sizeof($this->frmJoin)) {
  2054.             if ($debugechoDebug(__FILE__,"<p>Generating Join</p>");
  2055.             $tbls=array();
  2056.             foreach($this->frmJoin as $col => $tblLst{
  2057.                 foreach($tblLst as $tblCol{
  2058.                    list($tbl,$col)=explode(".",$tblCol);
  2059.                    $tbls[$tbl][]=$col;
  2060.                 }
  2061.             }
  2062.             $ret.=" FROM ";
  2063.             $notbls=0;
  2064.             $keys="";
  2065.             foreach($this->frmTables as $tbl{
  2066.                 if (!strstr($ret,$tbl)) {
  2067.                     if ($notbls==0{
  2068.                         $ret.=$tbl;
  2069.                         foreach($tbls[$tblas $col$keys.=":".$col.":";
  2070.                     else {
  2071.                         $sep="";
  2072.                         $ret.=" LEFT JOIN ".$tbl." USING(";
  2073.                         foreach($tbls[$tblas $col{
  2074.                             if (strstr($keys,":".$col.":")) {
  2075.                                 $ret.=$sep.$col$sep=",";
  2076.                             else {
  2077.                                 $keys.=":".$col.":";
  2078.                             }
  2079.                         }
  2080.                         $ret.=")";
  2081.                     }
  2082.                     //$ret.="<br />keys: $keys<br />";
  2083.                     $notbls++;
  2084.                 }
  2085.  
  2086.             }
  2087.  
  2088.             /*
  2089.             $ret.= $this->frmTables[0];
  2090.             $ret.=" LEFT JOIN ".$this->frmTables[1];
  2091.             $ret.=" USING (";
  2092.             foreach($this->frmJoin as $key => $val) {
  2093.                 $ret.=$sep.$key;
  2094.                 $sep=",";
  2095.             }
  2096.             $ret.=")";
  2097.             */
  2098.         else {
  2099.             $ret " FROM ";
  2100.             $sep "";
  2101.             foreach($this->frmTables as $key =>$val){
  2102.                 $ret.= $sep.$val;
  2103.                 $sep=",";
  2104.             }
  2105.         }
  2106.         return $ret;
  2107.     }
  2108.  
  2109.  
  2110.  
  2111.  
  2112.  
  2113.     // ###############################
  2114.  
  2115.     /**
  2116.       * returns a pointer to a field object
  2117.       *
  2118.       * @param string $name     (COLUMN) name of the field or the field key (table.name) where $table is empty
  2119.       * @param string $table    table name the field belongs to if empty fields are checked for name fit
  2120.       * @param boolean $debug      show debug info
  2121.       *
  2122.       * @return DBMS_FIELD 
  2123.       *
  2124.       * @since pk-03-12-17
  2125.       * @version pk-07-02-27
  2126.       *
  2127.       ***/
  2128.     function &getField($name,$table="",$debug=FALSE{
  2129.         if ($debug{
  2130.             echo "<hr /><p><b>DBMS_FORM::getField($name,$table,$debug)</b></p><blockquote>";
  2131.             // foreach($this->frmFields as $key => $obj) {echo $key."<br />";}
  2132.         }
  2133.  
  2134.         // quick version if a table is specified
  2135.         if ((isset($this->frmFields[$table.".".$name])) && (is_object($this->frmFields[$table.".".$name]))) {
  2136.             if ($debugecho "<p style=\"font-size:10px\">FOUND frmFields[\$table.\$name]</p></blockquote>";
  2137.             return $this->frmFields[$table.".".$name];
  2138.         else if (empty($table&& isset($this->frmFields[$name]&& is_object($this->frmFields[$name])) // <pk-07-02-27 >
  2139.             if ($debugecho "<p style=\"font-size:10px\">FOUND frmFields[\$name]</p></blockquote>";
  2140.             return $this->frmFields[$name];
  2141.         else if (!empty($table)) {
  2142.             // we do not have a field for this table
  2143.             if ($debugecho "<p style=\"font-size:10px\">NO OBJECT frmFields[\$table.\$name]</p></blockquote>";
  2144.             $o_retNull=NULL;return $o_retNull// <pk-06-08-01 /> E_ALL
  2145.         }
  2146.  
  2147.         if ($debugecho "<p style=\"font-size:8px\">";
  2148.         foreach($this->frmFields as $key => &$fld// <pk-07-02-27 /> & ptr to fld to save memory
  2149.             if ($debugecho "frmFields[$key] named".$fld->getName()."<br />";
  2150.             if ($fld->getName()==$name{
  2151.                 if ($debugecho "</p><p style=\"font-size:10px\">FOUND frmFields[\$table.\$name]</p></blockquote>";
  2152.                 return $this->frmFields[$key];
  2153.                     // do not return $fld here
  2154.                     // as it is a copy of the field (PHP Version 4.2.x)
  2155.             }
  2156.         }
  2157.         if ($debugecho "</p><p style=\"font-size:10px\">NOTHING FOUND</p></blockquote>";
  2158.         $o_retNull=NULL;            // <pk-06-08-01 /> E_ALL
  2159.         return $o_retNull;
  2160.     }
  2161.  
  2162.     /**
  2163.       * sets a field object
  2164.       *
  2165.       * @param string $tbl 
  2166.       * @param DBMS_FIELD $fld 
  2167.       * @param boolean $debug 
  2168.       *
  2169.       * @since am-06-05-15
  2170.       *
  2171.       ***/
  2172.     function setFieldObj($sTbl,$fld,$debug=FALSE{
  2173.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::setFieldObj",$sTbl.".".$fld->getName(),0);
  2174.  
  2175.         $fld->setTable($sTbl,"",TRUE,$debug);
  2176.         $this->frmFields[$sTbl.".".$fld->getName()]=$fld;
  2177.  
  2178.     }
  2179.  
  2180.     /**
  2181.       * returns the form field array
  2182.       *
  2183.       * @param boolean $withoutTable include table name in the key
  2184.       *
  2185.       * @returns array
  2186.       *
  2187.       * @since am-06-05-15
  2188.       *
  2189.       ***/
  2190.     function get_frmFields($withoutTable=FALSE{
  2191.         if ($withoutTable{
  2192.             $a_ret=array();
  2193.             foreach($this->frmFields as $o_fld{
  2194.                 $a_ret[$o_fld->getName]=$o_fld;
  2195.             }
  2196.             return $a_ret;
  2197.         else {
  2198.             return $this->frmFields;
  2199.         }
  2200.     }
  2201.  
  2202.     /**
  2203.       * returns an array of pointers to the form fields
  2204.       *
  2205.       * @param boolean sorted  array index is field order nr
  2206.       *
  2207.       * @returns array of &DBMS_FIELDS
  2208.       * @access public
  2209.       *
  2210.       * @version pk-04-07-23
  2211.       * @version pk-07-05-03
  2212.       *
  2213.       */
  2214.     function getFieldArr($sorted=TRUE{
  2215.         $arr_ret=array();
  2216.         reset($this->frmFields);
  2217.         while (list($str_key,$obj_fld)=each($this->frmFields)) {
  2218.             if (get_class($this->frmFields[$str_key])=="__PHP_Incomplete_Class"{
  2219.                 echo "<p>$str_key".get_class($this->frmFields[$str_key])."</p>";
  2220.             }
  2221.             $this->frmFields[$str_key]->setMyForm($this);
  2222.             if ($sorted{
  2223.                 // <pk-04-07-23 />
  2224.                 $int_sortKey=(($obj_fld->getOrderNr(0$obj_fld->getOrderNr(1)// <pk-07-05-04 />
  2225.                 while(isset($arr_ret[$int_sortKey]&& (is_object($arr_ret[$int_sortKey]))) {
  2226.                     $int_sortKey++;
  2227.                 }
  2228.                 $arr_ret[$int_sortKey]=&$this->frmFields[$str_key];
  2229.                 $this->frmFields[$str_key]->setOrderNr($int_sortKey);  // <pk-07-05-04 />
  2230.                 // <pk-04-07-23 />
  2231.             else {
  2232.                 $arr_ret[]=&$this->frmFields[$str_key];
  2233.             }
  2234.         }
  2235.         if ($sortedksort($arr_ret);
  2236.         return $arr_ret;
  2237.     }
  2238.  
  2239.     /**
  2240.       * returns an array of fields (for compatibility with new version (OCSP_FORM)
  2241.       * @param string $aTable (empty to get all fields)
  2242.       * @param boolean $debug 
  2243.       *
  2244.       * @return array 
  2245.       */
  2246.     function getFields($aTable='',$debug=FALSE)
  2247.     {
  2248.         $arr_ret=array();
  2249.         $arr_fields=$this->getFieldArr(TRUE);
  2250.         foreach($arr_fields as &$obj_field)
  2251.         {
  2252.             if (empty($aTable|| ($obj_field->getTable()==$aTable))
  2253.             {
  2254.                 $arr_ret[$obj_field->getKey()]=&$obj_field;
  2255.             }
  2256.         }
  2257.         return $arr_ret;
  2258.     }
  2259.  
  2260.     /**
  2261.       * returns an array with all auto_inc fields
  2262.       *
  2263.       * @param boolean $debug 
  2264.       *
  2265.       * @returns array
  2266.       *
  2267.       * @since pk-06-01-24
  2268.       *
  2269.       ***/
  2270.     function getAutoIncFields($debug=FALSE{
  2271.         if ($debugechoDebug(__FILE__,"<p><b>DBMS_FORM::getAutoIncFields()</b> (".get_class($this).")</p>",0);
  2272.  
  2273.         $a_ret=array();
  2274.         foreach($this->frmFields as $key => $obj{
  2275.             if ($obj->dbDesc['AUTO_INCREMENT']{
  2276.                 $a_ret[]=$obj->dbDesc['COLNAME'];
  2277.             }
  2278.         }
  2279.  
  2280.         return $a_ret;
  2281.     }
  2282.  
  2283.     function cleanupFieldArr({
  2284.         $fldLst=$this->frmFields;
  2285.         foreach($fldLst as $key => $fld{
  2286.             if (!(is_object($fldLst[$key])) ||  !(pcf_is_instance_of($fldLst[$key],"DBMS_FIELD"))) {
  2287.                 unset($this->frmFields[$key]);
  2288.             }
  2289.         }
  2290.     }
  2291.  
  2292.     /**
  2293.       * disables or enables a field in a FRM_MODE_NEW or FRM_MODE_EDIT
  2294.       * if (mode == -1) FRM_MODE_NEW and FRM_MODE_EDIT are used
  2295.       *
  2296.       * @param boolean $enabled 
  2297.       * @param string $fldName 
  2298.       * @param int $mode 
  2299.       * @param string $tbl 
  2300.       * @param boolean $debug 
  2301.       *
  2302.       * @since pk-05-07-21
  2303.       *
  2304.       * @var boolean $b_IsToChange 
  2305.       * @var string $key 
  2306.       * @var DBMS_FIELD $fld 
  2307.       *
  2308.       ***/
  2309.     function en_disAbleField($enabled,$fldName,$mode=-1,$tbl="",$debug=FALSE{
  2310.         if ($debugecho "<p><b>DBMS_FORM::en_disAbleField(".($enabled "enable" "disable").",$fldName,$tbl,$debug)</b> (".get_class($this).")</p>";
  2311.         foreach($this->frmFields as $key => $fld{
  2312.             if ($debugecho "<li style=\"font-size:9px;\">FLD$key (".$fld->getKey()." / ".$fld->getName().")";
  2313.  
  2314.             if (!empty($tbl)) {
  2315.                 $b_IsToChange =($fld->getKey(== $tbl.".".$fldName);
  2316.             else {
  2317.                 $b_IsToChange ($fld->getName()==$fldName);
  2318.             }
  2319.             if ($b_IsToChange{
  2320.                 switch($mode{
  2321.                     case FRM_MODE_NEW:
  2322.                         $this->frmFields[$key]->enableNew=$enabled;
  2323.                         break;
  2324.                     case FRM_MODE_COPY:
  2325.                         $this->frmFields[$key]->enableCopy=$enabled;
  2326.                         break;
  2327.                     case FRM_MODE_EDIT:
  2328.                         $this->frmFields[$key]->enableEdit=$enabled;
  2329.                         break;
  2330.                     case -1:
  2331.                         $this->frmFields[$key]->enableNew=$enabled;
  2332.                         $this->frmFields[$key]->enableEdit=$enabled;
  2333.                         $this->frmFields[$key]->enableCopy=$enabled;
  2334.                         break;
  2335.                 }
  2336.                 if ($debugecho " <b>FOUND</b>";
  2337.             }
  2338.             if ($debugecho "</li>";
  2339.         }
  2340.     }
  2341.  
  2342.     /**
  2343.       * disables a field in a FRM_MODE_NEW or FRM_MODE_EDIT
  2344.       * if (mode == -1) FRM_MODE_NEW and FRM_MODE_EDIT are used
  2345.       *
  2346.       * @param string $fldName 
  2347.       * @param int $mode 
  2348.       * @param string $tbl 
  2349.       * @param boolean $debug 
  2350.       *
  2351.       * @since pk-05-07-21
  2352.       *
  2353.       ***/
  2354.     function enableField($fldName,$mode=-1,$tbl="",$debug=FALSE{
  2355.         if ($debugecho "<p><b>DBMS_FORM::enableField($fldName,$tbl,$debug)</b> (".get_class($this).")</p>";
  2356.         $this->en_disAbleField(TRUE,$fldName,$mode,$tbl,$debug);
  2357.     }
  2358.  
  2359.     /**
  2360.       * disables a field in a FRM_MODE_NEW or FRM_MODE_EDIT
  2361.       * if (mode == -1) FRM_MODE_NEW and FRM_MODE_EDIT are used
  2362.       *
  2363.       * @param string $fldName 
  2364.       * @param int $mode 
  2365.       * @param string $tbl 
  2366.       * @param boolean $debug 
  2367.       *
  2368.       * @since pk-05-07-19
  2369.       * @version pk-05-07-21
  2370.       *
  2371.       ***/
  2372.     function disableField($fldName,$mode=-1,$tbl="",$debug=FALSE{
  2373.         if ($debugecho "<p><b>DBMS_FORM::disableField($fldName,$tbl,$debug)</b> (".get_class($this).")</p>";
  2374.         $this->en_disAbleField(FALSE,$fldName,$mode,$tbl,$debug);
  2375.     }
  2376.  
  2377.  
  2378.     /**
  2379.       * set a field hidden
  2380.       *
  2381.       * @param string $fldName 
  2382.       * @param string $tbl 
  2383.       * @param boolean $debug 
  2384.       *
  2385.       * @since pk-04-03-08
  2386.       *
  2387.       ***/
  2388.     function hideField($fldName,$tbl="",$debug=FALSE{
  2389.         if ($debugecho "<p><b>DBMS_FORM::hideField($fldName,$tbl,$debug)</b> (".get_class($this).")</p>";
  2390.         foreach($this->frmFields as $key => $fld{
  2391.             if ($debugecho "<li style=\"font-size:9px;\">FLD$key (".$fld->getKey()." / ".$fld->getName().")";
  2392.             if (!empty($tbl)) {
  2393.                 if ($fld->getKey(== $tbl.".".$fldName{
  2394.                     $this->frmFields[$key]->isHidden=TRUE;
  2395.                     if ($debugecho " <b>FOUND</b>";
  2396.                 }
  2397.             else {
  2398.                 if ($fld->getName()==$fldName{
  2399.                     $this->frmFields[$key]->isHidden=TRUE;
  2400.                     if ($debugecho " <b>FOUND</b>";
  2401.                 }
  2402.             }
  2403.             if ($debugecho "</li>";
  2404.         }
  2405.     }
  2406.  
  2407.     /**
  2408.       * enable field in list
  2409.       *
  2410.       * @param string $fldName 
  2411.       * @param string $tbl 
  2412.       * @param boolean $debug 
  2413.       *
  2414.       * @since pk-06-09-06
  2415.       *
  2416.       ***/
  2417.     function showFieldInList($fldName,$tbl="",$debug=FALSE{
  2418.         if ($debugecho "<p><b>DBMS_FORM::hideField($fldName,$tbl,$debug)</b> (".get_class($this).")</p>";
  2419.         foreach($this->frmFields as $key => $fld{
  2420.             if ($debugecho "<li style=\"font-size:9px;\">FLD$key (".$fld->getKey()." / ".$fld->getName().")";
  2421.             if (!empty($tbl)) {
  2422.                 if ($fld->getKey(== $tbl.".".$fldName{
  2423.                     $this->frmFields[$key]->showInList=TRUE;
  2424.                     if ($debugecho " <b>FOUND</b>";
  2425.                 }
  2426.             else {
  2427.                 if ($fld->getName()==$fldName{
  2428.                     $this->frmFields[$key]->showInList=TRUE;
  2429.                     if ($debugecho " <b>FOUND</b>";
  2430.                 }
  2431.             }
  2432.             if ($debugecho "</li>";
  2433.         }
  2434.     }
  2435.  
  2436.     /**
  2437.       * set a field not hidden
  2438.       *
  2439.       * @param string $fldName 
  2440.       * @param string $tbl 
  2441.       * @param boolean $debug 
  2442.       *
  2443.       * @since pk-04-10-11
  2444.       *
  2445.       ***/
  2446.     function showField($fldName,$tbl="",$debug=FALSE{
  2447.         if ($debugecho "<p><b>DBMS_FORM::hideField($fldName,$tbl,$debug)</b> (".get_class($this).")</p>";
  2448.         foreach($this->frmFields as $key => $fld{
  2449.             if ($debugecho "<li style=\"font-size:9px;\">FLD$key (".$fld->getKey()." / ".$fld->getName().")";
  2450.             if (!empty($tbl)) {
  2451.                 if ($fld->getKey(== $tbl.".".$fldName{
  2452.                     $this->frmFields[$key]->isHidden=FALSE;
  2453.                     if ($debugecho " <b>FOUND</b>";
  2454.                 }
  2455.             else {
  2456.                 if ($fld->getName()==$fldName{
  2457.                     $this->frmFields[$key]->isHidden=FALSE;
  2458.                     if ($debugecho " <b>FOUND</b>";
  2459.                 }
  2460.             }
  2461.             if ($debugecho "</li>";
  2462.         }
  2463.     }
  2464.  
  2465.  
  2466.     /**
  2467.       * hides all fields of a table
  2468.       *
  2469.       * @param string $tbl 
  2470.       * @param boolean $debug 
  2471.       *
  2472.       * @since pk-04-07-30
  2473.       *
  2474.       ***/
  2475.     function hideAllTblFields($tbl,$debug=FALSE{
  2476.         if ($debugecho "<p><b>DBMS_FORM::hideAllTblFields($tbl,$debug)</b> (".get_class($this).")</p>";
  2477.         foreach($this->frmFields as $key => $fld{
  2478.             if ($fld->getTblAlias(== $tbl || $fld->getTable(== $tbl{
  2479.                 $this->frmFields[$key]->setHidden();
  2480.             }
  2481.         }
  2482.     }
  2483.  
  2484.     /**
  2485.       * returns an array with the field default values;
  2486.       *
  2487.       * @param string $table if not empty only fields of $table are returned
  2488.       * @param boolean $debug 
  2489.       *
  2490.       * @returns array an array with field name as key and default value
  2491.       *
  2492.       *  pk-04-08-31: param $debug added
  2493.       *
  2494.       * @version pk-04-08-31
  2495.       *
  2496.       ***/
  2497.     function getDefaultValArr($table="",$debug=FALSE{
  2498.         $debug=($debug || $this->debugMode);
  2499.         if ($debugecho "<p><b>DBMS_FORM::getDefaultValArr($table,$debug)</b> (".get_class($this)."/".$this->getId().")</p>";
  2500.         $ret=array();
  2501.         foreach($this->frmFields as $key => $obj{
  2502.             if ((empty($table)) || ($obj->myTable==$table))
  2503.                 $ret[$obj->getName()]=$obj->getDefaultValue();
  2504.         }
  2505.         if ($debugecho "<blockquote><p>Default Values:</p><pre style=\"font-size:75%\">".print_r($ret,TRUE)."</pre></blockquote>";
  2506.         return $ret;
  2507.     }
  2508.  
  2509.     /**
  2510.       * returns the relaod url
  2511.       *
  2512.       * @param boolean $debug 
  2513.       *
  2514.       * @returns string
  2515.       *
  2516.       * @since pk-07-01-18
  2517.       *
  2518.       ***/
  2519.     function getReloadUri($debug=FALSE{
  2520.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::getReloadUri()");
  2521.         $s_ret="";
  2522.         if (!empty($this->HTMLFORM_URL_reload)) {
  2523.             $s_ret=$this->HTMLFORM_URL_reload;
  2524.         else {
  2525.             $s_ret=$_SERVER['REQUEST_URI'];
  2526.         }
  2527.         $s_ret=pcf_HTML_changeURI_GetValue($s_ret,session_name(),session_id());
  2528.         if ($debugechoDebug(__FILE__,"<p style=\"padding-left: 20px\">Returns: ".$s_ret."</p>");
  2529.         return $s_ret;
  2530.     }
  2531.  
  2532.     /**
  2533.       * returns if the form is reloaded
  2534.       *
  2535.       * @param string $postArrName 
  2536.       * @param boolean $debug 
  2537.       *
  2538.       * @return boolean 
  2539.       *
  2540.       * @since pk-07-03-02
  2541.       *
  2542.       * @access public
  2543.       *
  2544.       ***/
  2545.     function isReloaded($postArrName,$debug=FALSE{
  2546.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::isReloaded()");
  2547.  
  2548.         if (isset($GLOBALS['FORCERELOAD']&& $GLOBALS['FORCERELOAD']return TRUE;
  2549.  
  2550.         if (!empty($postArrName&& isset($_POST[$postArrName]&& (is_array($_POST[$postArrName]))) {
  2551.             if (isset($_SERVER['HTTP_REFERER'])) {
  2552.                 // extract scripts
  2553.                 $s_refUrl=ereg_replace("https?://([^/]+)"""$_SERVER['HTTP_REFERER']);
  2554.                 $s_aktUrl=$_SERVER['REQUEST_URI'];
  2555.  
  2556.                 // remove the reload get param (rldFRM)
  2557.                 $s_refUrl=trim(pcf_HTML_changeURI_GetValue($s_refUrl,'rldFRM',""));
  2558.                 $s_aktUrl=trim(pcf_HTML_changeURI_GetValue($s_aktUrl,'rldFRM',""));
  2559.  
  2560.                 return ($s_refUrl==$s_aktUrl);
  2561.             }
  2562.         }
  2563.         return FALSE;
  2564.     }
  2565.  
  2566.     /**
  2567.       * check if the form is relaoded
  2568.       * and we have to use the posted values instead of $aktRow
  2569.       * if $aktRow is not an array the form default values are used
  2570.       *
  2571.       * @param array $aktRow 
  2572.       * @param boolean $debug 
  2573.       * @param boolean $pArrName 
  2574.       *
  2575.       * @returns array
  2576.       *
  2577.       * @since pk-05-08-08
  2578.       * @version pk-05-11-17 debug infos
  2579.       * @version pk-05-11-23
  2580.       * @version pk-05-11-25 debug info
  2581.       * @version pk-05-11-29 bugfix
  2582.       * @version pk-06-10-25 bugfix regex http? -> https?
  2583.       * @version pk-07-02-28
  2584.       *
  2585.       * @var string $s_refUrl 
  2586.       * @var string $s_aktUrl 
  2587.       * @var string $s_frmAction 
  2588.       * @var int $i_frmMode 
  2589.       * @var array $a_fldLst 
  2590.       * @var DBMS_FIELD $o_fld 
  2591.       *
  2592.       ***/
  2593.     function reloadCheck($aktRow=NULL,$debug=FALSE,$pArrName=""{
  2594.         if ($debugecho "<p><b>DBMS_FORM::reloadCheck(...)</b> (".get_class($this).")</p><blockquote>\n";
  2595.  
  2596.         if ($debugecho "<p>\$aktRow:</p><pre>".print_r($aktRow,TRUE)."</pre>";
  2597.         if (empty($aktRow)) {
  2598.             // no array -> load form default values
  2599.             if ($debugecho "<p>Loading default values</p><blockquote><hr>"// <pk-05-11-29 />
  2600.             $aktRow=$this->getDefaultValArr("",$debug);
  2601.             if ($debugecho "<hr></blockquote>"// <pk-05-11-29 />
  2602.         }
  2603.  
  2604.         // extract URL's to compare
  2605.         if (!isset($_SERVER['HTTP_REFERER']|| (!($s_refUrl=ereg_replace("https?://([^/]+)"""$_SERVER['HTTP_REFERER'])))) // <pk-06-10-26 /> // <pk-07-02-28 /> E_ALL
  2606.             // we do not have a referer -> the form could not be reloaded
  2607.             if ($debugecho "<p>EREG: <br />".$_SERVER['HTTP_REFERER']."<br />".$s_refUrl."<br />".$_SERVER['REQUEST_URI']."</p></blockquote>";
  2608.             return $aktRow;
  2609.         }
  2610.         $s_aktUrl=$_SERVER['REQUEST_URI'];
  2611.         $s_aktion=(isset($_POST['FRMACTION']$_POST['FRMACTION'"");
  2612.         $s_frmAction=substr($s_aktUrl,(strlen($s_aktion)*-1))// remove server (http://server.domain.ttl)
  2613.  
  2614.         // now check the post values
  2615.         // <pk-05-11-23>
  2616.         if (!empty($pArrName)) {
  2617.             $s_arrName=$pArrName;
  2618.         else if (isset($_POST['FRMARRAYNAME']&& !empty($_POST['FRMARRAYNAME'])) {
  2619.             $s_arrName=$_POST['FRMARRAYNAME'];
  2620.         else {
  2621.             if ($debugecho "<p>no FRMARRAYNAME posted</p></blockquote>";
  2622.             return $aktRow;
  2623.         }
  2624.  
  2625.         if ((!isset($_POST[$s_arrName])) || (!is_array($_POST[$s_arrName]))) // <pk-06-07-22 />
  2626.             // we do not have a form post
  2627.             if ($debugecho "<p>no POST array</p></blockquote>";
  2628.             return $aktRow;
  2629.         }
  2630.         // </pk-05-11-23>
  2631.  
  2632.         // we do not check form Id as forms could also change
  2633.         // now check if we have the same urls
  2634.  
  2635.         // <pk-06-10-05 > but first remove the reload get param (rldFRM)
  2636.         $s_refUrl=trim(pcf_HTML_changeURI_GetValue($s_refUrl,'rldFRM',""))// <pk-06-10-18>
  2637.         $s_aktUrl=trim(pcf_HTML_changeURI_GetValue($s_aktUrl,'rldFRM',""))// <pk-06-10-18>
  2638.  
  2639.         // <pk-06-10-18>
  2640.         if (substr($s_aktUrl,-1)=="?"$s_aktUrl=substr($s_aktUrl,0,-1);
  2641.         if (substr($s_refUrl,-1)=="?"$s_refUrl=substr($s_refUrl,0,-1);
  2642.         if ($debugecho "<p>Ref$s_refUrl<br />Akt$s_aktUrl</p>";
  2643.         // </pk-06-10-18>
  2644.  
  2645.         if (!isset($GLOBALS['FORCERELOAD'])) $GLOBALS['FORCERELOAD']=FALSE// <pk-06-09-14 /> E_ALL
  2646.         if (($s_refUrl == $s_aktUrl|| ($GLOBALS['FORCERELOAD']|| ($s_frmAction == $_POST['FRMACTION'])) {
  2647.             // the url is identical (each form is submited to itself in case of reload)
  2648.             $aktRow=array_merge($aktRow,$_POST[$s_arrName]);  // array_merge is used to have fields
  2649.                                                               // which are not posted but set outside
  2650.                                                               // in the value array
  2651.  
  2652.             global ${$s_arrName};
  2653.             ${$s_arrName}=$_POST[$s_arrName];
  2654.             $i_frmMode=$_POST['FRMMODE'];
  2655.             $a_err=NULL;
  2656.             $a_fldLst=$this->getFieldArr();
  2657.             foreach($a_fldLst as $o_fld{
  2658.                 if (isset($_POST[$s_arrName][$o_fld->getName()])) {
  2659.                     if ($debugecho "<p style=\"font-size:75%\">setting field: ".$o_fld->getName()." POST value: ".nl2br(htmlspecialchars(print_r($_POST[$s_arrName][$o_fld->getName()]),TRUE))." &lt;-&gt; ";  // <pk-05-11-17 />
  2660.                     $aktRow[$o_fld->getName()]=$o_fld->getValue(${$s_arrName}[$o_fld->getName()],$a_err,$s_arrName);
  2661.                     if ($debugecho " Return value: ".@htmlspecialchars($aktRow[$o_fld->getName()])."</p>\n";
  2662.                 else if (pcf_is_instance_of($o_fld,"DBMS_FIELD_CHECKBOX")) {
  2663.                     if ($debugecho "<p style=\"font-size:75%\"><b>un</b>setting field: ".$o_fld->getName()."</p>"// <pk-05-11-17 />
  2664.                     unset($aktRow[$o_fld->getName()]);
  2665.                 }
  2666.             }
  2667.         }
  2668.         if ($debugecho "</blockquote>";
  2669.         return $aktRow;
  2670.     }
  2671.  
  2672.     /* **************************************************************** */
  2673.     /* **************************************************************** */
  2674.     /* **************************************************************** */
  2675.  
  2676.     /**
  2677.       * gets the html (javaScriptCode) for the formular start
  2678.       *
  2679.       * @param string $frmName 
  2680.       * @param int $mode 
  2681.       * @param boolean $withJSInc @deprecated since pk-07-02-28 (allways check for includes)
  2682.       * @param boolean $debug 
  2683.       *
  2684.       * @returns string
  2685.       *
  2686.       * @since pk-04-09-08
  2687.       * @version pk-06-11-22 usage of html_includes
  2688.       * @version pk-07-02-28 use pcf_get_htmlJsInclude
  2689.       *
  2690.       ***/
  2691.     function getJavaCode($mode=FRM_MODE_READONLY,$withJSInc=FALSE,$debug=FALSE{
  2692.         $debug ($debug || $this->debugMode);
  2693.         if ($debugecho "<p><b>DBMS_FORM::getJavaStart($mode,$withJSInc,...)</b> (".get_class($this).")</p>";
  2694.  
  2695.         $ret="\n<!-- _____________________ DBMS_FORM HEADER _________________ -->\n";
  2696.         // <pk-07-02-27>
  2697.         $s_ret.=pcf_get_htmlJsInclude("/system/javascript/window.js.php");
  2698.         $s_ret.=pcf_get_htmlJsInclude("/system/javascript/forms.js.php");
  2699.         // </pk-07-02-27>
  2700.  
  2701.         $ret .="\n<script language=\"javascript\">\n";
  2702.         $ret .="    <!--\n";
  2703.         $ret .="        var ".$this->frmName."_mode=".$mode.";\n\n";
  2704.  
  2705.         switch($mode{
  2706.             case FRM_MODE_NEW:
  2707.             case FRM_MODE_COPY:
  2708.             case FRM_MODE_EDIT:
  2709.             case FRM_MODE_SEARCH:
  2710.                 $ret .="        function ".$this->frmName."_onSubmit() {\n";
  2711.                 $ret .="            return true;\n";
  2712.                 $ret .="        }\n";
  2713.  
  2714.                 break;
  2715.             default:
  2716.                 $ret .="        /* NO CODE AVALABLE */\n";
  2717.         }
  2718.         $ret .="    //-->\n";
  2719.         $ret .="</script>\n";
  2720.  
  2721.         return $ret;
  2722.     }
  2723.  
  2724.     /**
  2725.       * writes a field and sets the fields form Id
  2726.       *
  2727.       * @param string $name index in $this->frmFields
  2728.       * @param int $mode 
  2729.       * @param any $val 
  2730.       * @param string $arrName 
  2731.       * @param boolean $debug 
  2732.       *
  2733.       * @version pk-04-07-29
  2734.       *
  2735.       ***/
  2736.     function writeField($name,$mode,$val,$arrName="DBVAL",$debug=FALSE{
  2737.         if (is_object($this->frmFields[$name])) {
  2738.             $this->frmFields[$name]->setFrmId($this->frmId);
  2739.             $this->frmFields[$name]->writeField($mode,$val,$arrName,$debug);
  2740.         }
  2741.     }
  2742.  
  2743.  
  2744.     /**
  2745.       * writes a form table from a query
  2746.       *
  2747.       * @param DB_xxx $DBOBJ 
  2748.       * @param string $query 
  2749.       * @param int $mode 
  2750.       * @param string $arrName 
  2751.       * @param boolean $debug 
  2752.       *
  2753.       * @returns string
  2754.       *
  2755.       * @version pk-04-02-23
  2756.       * @version pk-05-11-04
  2757.       ***/
  2758.     function writeTableFromQuery($DBOBJ,$query,$mode=FRM_MODE_READONLY,$arrName="DBVAL",$debug=FALSE{
  2759.         if (empty($query)) return FALSE;
  2760.         $this->setFrmMode($mode)// <pk-05-11-04 />
  2761.  
  2762.         if (!$DBVAL=$DBOBJ->quickQuery($query)) return FALSE;
  2763.         return $this->writeTableFromArray($DBVAL,$mode,$arrName,$debug);
  2764.     }
  2765.  
  2766.     /**
  2767.       * writes a form table from a query
  2768.       *
  2769.       * @param DB_xxx $DBOBJ 
  2770.       * @param string $query 
  2771.       * @param int $mode 
  2772.       * @param string $arrName 
  2773.       * @param boolean $debug 
  2774.       *
  2775.       * @returns string
  2776.       *
  2777.       * @version pk-04-09-08
  2778.       * @version pk-05-11-04
  2779.       ***/
  2780.     function writeTableFromArray($DBVAL,$mode=FRM_MODE_READONLY,$arrName="DBVAL",$debug=FALSE{
  2781.         $debug=($debug || $this->debugMode);
  2782.         $this->setFrmMode($mode)// <pk-05-11-04 />
  2783.         if (!is_array($DBVAL)) {
  2784.             if ($debugecho "NO ARRAY ".$this->frmName."<br />";
  2785.             return FALSE;
  2786.         }
  2787.  
  2788.         // if ($_SERVER['REMOTE_ADDR']=="10.8.8.22") $debug=TRUE;
  2789.  
  2790.         $GLOBALS['TMP_FROMDATAARRAY_'.$this->frmId]=&$DBVAL;    /* <pk-04-02-03 /> */
  2791.         $fields="";$sep="";
  2792.         $fldLst=$this->getFieldArr(TRUE);
  2793.         while(list($fld,$obj)=each($fldLst)) {
  2794.             /* <pk-04-02-03> */
  2795.             if ($debug$obj->fldDebug=$debug;
  2796.             $obj->setDataArrName($arrName)/* <pk-04-09-08 /> */
  2797.             if (!$obj->getGrpKey()) {
  2798.                 // if ($debug){echo "<tr><td colspan=\"2\"><pre>";print_r($obj);echo "</pre></td></tr>"; }
  2799.                 unset($GLOBALS['TMP_GRPFIELDS_'.$this->frmId]);
  2800.                 if ($obj->writeFieldRow($mode,$DBVAL[$obj->myName],$arrName,"","","",$debug)) {
  2801.                     if (!empty($GLOBALS['TMP_GRPFIELDS_'.$this->frmId])) {
  2802.                         $fields.=$sep.$GLOBALS['TMP_GRPFIELDS_'.$this->frmId];
  2803.                     else {
  2804.                         $fields.=$sep.$obj->myName;
  2805.                     }
  2806.                     $sep=",";
  2807.                 }
  2808.             }
  2809.             /* </ pk-04-02-03> */
  2810.         }
  2811.         echo "\n<input name=\"".$arrName."[_DBMS_FIELDS]\" type=\"hidden\" value=\"$fields\">\n";
  2812.         return $fields;
  2813.     }
  2814.  
  2815.  
  2816.     /**
  2817.       * returns the form table rows
  2818.       *
  2819.       * @param array $DBVAL 
  2820.       * @param int $mode 
  2821.       * @param string $arrName 
  2822.       * @param boolean $debug 
  2823.       *
  2824.       * @returns string
  2825.       *
  2826.       * @since pk-
  2827.       * @version pk-05-11-04
  2828.       * @version pk-06-04-02 add foreign keyfields as hidden input if they do have values in $DBVAL
  2829.       * @version pk-06-11-19 set the form object to the field
  2830.       *
  2831.       ***/
  2832.     function getTableFromArray($DBVAL,$mode=FRM_MODE_READONLY,$arrName="DBVAL",$debug=FALSE{
  2833.         $debug ($debug || $this->debugMode);
  2834.         if ($debugecho "<p><b>DBMS_FORM::getTableFromArray(\$DBVAL,$mode,$arrName,...)</b> (".get_class($this).")</p>";
  2835.  
  2836.         $this->setFrmMode($mode)// <pk-05-11-04 />
  2837.  
  2838.         global ${$arrName};
  2839.         $DBVAL['_DBMS_FIELDS']=""// <pk-05-12-05 />
  2840.  
  2841.         if (!is_array(${$arrName})) {
  2842.             ${$arrName}=$DBVAL;
  2843.         }
  2844.  
  2845.         if ($debug{
  2846.             echo "<p>DATA:</p><blockquote>";
  2847.             if (is_array($DBVAL)) {
  2848.                 foreach ($DBVAL as $key => $val{
  2849.                     echo "<p>$key: <br />".htmlspecialchars(substr(print_r($val,TRUE),0,60))."</p>";
  2850.                 }
  2851.             else {
  2852.                 echo "<p>\$DBVAL IS NOT AN ARRAY</p><pre style=\"font-size:75%;\">\$DBVAL:\n".print_r($DBVAL,TRUE)."</pre>";
  2853.             }
  2854.             echo "</blockquote>";
  2855.         }
  2856.         $ret="";
  2857.  
  2858.         $GLOBALS['TMP_FROMDATAARRAY_'.$this->frmId]=&$DBVAL;    /* <pk-04-02-03 /> */
  2859.         $fields="";$sep="";
  2860.         $fldLst=$this->getFieldArr(TRUE);
  2861.         $a_hiddenFKFlds=array()// <pk-06-04-02 />
  2862.         $a_hiddenFields=array()// <pk-06-11-15 />
  2863.         foreach($fldLst as $fld => &$obj// <pk-07-02-15 ref $obj instead of new var mainly to save memory
  2864.             $obj->setDataArrName($arrName);
  2865.             $obj->setMyForm($this)// <pk-06-11-19 />
  2866.  
  2867.             if ($debugecho "<blockquote><p>NAME: |".$obj->getName()."| VALUE: |".substr($DBVAL[$obj->getName()],0,30)."| HIDDEN: |".$obj->isToShow($mode,$DBVAL)."|</p>";
  2868.             if ($obj->isToShow($mode,$DBVAL,$debug)) {
  2869.                 if (!$obj->getGrpKey()) {
  2870.                     $ret.=$obj->getFieldRow($mode,(isset($DBVAL[$obj->getName()]$DBVAL[$obj->getName()NULL),$debug);
  2871.                 }
  2872.             else if ($mode==FRM_MODE_NEW && pcf_is_instance_of($obj,"DBMS_FIELD_FOREIGNKEY")) // <pk-06-04-02>
  2873.                 if (!empty($DBVAL[$obj->myName])) $a_hiddenFKFlds[]=$obj;
  2874.             else if (($mode==FRM_MODE_NEW|| ($mode==FRM_MODE_COPY)) // <pk-06-11-15>
  2875.                 if (!empty($DBVAL[$obj->myName])) $a_hiddenFields[]=$obj;
  2876.             else if ((($mode==FRM_MODE_EDIT|| ($mode==FRM_MODE_DELETE)) && $obj->isPrimaryKey()) // <pk-07-02-15 /> ensure primary keys are set
  2877.                 $a_hiddenFields[]=$obj;
  2878.             }
  2879.             if ($debugecho "<hr /></blockquote>";
  2880.         }
  2881.         // <pk-06-04-02>
  2882.         // <pk-07-02-15>
  2883.         $ret_pre="";
  2884.         if (sizeof($a_hiddenFields)) {
  2885.             foreach($a_hiddenFields as $obj{
  2886.                 $ret_pre.="\n<!-- hidden value fields -->\n";
  2887.                 $ret_pre.=$obj->getFieldTag(FRM_MODE_HIDDEN,$DBVAL[$obj->getName()],$debug)."\n";
  2888.                 $ret_pre.="<!-- /hidden value fields -->\n\n";
  2889.             }
  2890.         }
  2891.         if (($mode==FRM_MODE_NEW || ($mode==FRM_MODE_COPY)) && sizeof($a_hiddenFKFlds)) {
  2892.             foreach($a_hiddenFKFlds as $obj{
  2893.                 $ret_pre.="\n<!-- hidden foreign keys -->\n";
  2894.                 $ret_pre.=$obj->getFieldTag(FRM_MODE_HIDDEN,$DBVAL[$obj->myName],$debug)."\n";
  2895.                 $ret_pre.="<!-- /hidden foreign keys -->\n\n";
  2896.             }
  2897.         }
  2898.         $ret=$ret_pre.$ret// have the auto added hidden fields at the beginning to avoid overwriting when the field names
  2899.                             // exists twice (in joins for example)
  2900.         // </pk-07-02-15>
  2901.         // </pk-06-04-02>
  2902.         if (isset(${$arrName}['_DBMS_FIELDS'])) // <pk-06-09-14 /> E_ALL
  2903.             $ret.="\n<input name=\"".$arrName."[_DBMS_FIELDS]\" type=\"hidden\" value=\"".${$arrName}['_DBMS_FIELDS']."\">\n";
  2904.         }
  2905.         return $ret;
  2906.  
  2907.     }
  2908.  
  2909.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  2910.     /*  HTML
  2911.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  2912.  
  2913.     /**
  2914.       * sets the button array
  2915.       *
  2916.       * @since pk-05-03-22
  2917.       * @version pk-05-08-08 png -> gif
  2918.       *
  2919.       ***/
  2920.     function setHTMLFORM_BtnSource($debug=FALSE{
  2921.         if ($debugecho "<p><b>DBMS_FORM::setHTMLFORM_BtnSource(...)</b> (".get_class($this).")</p>";
  2922.         $this->HTMLFORM_button_src=array(
  2923.             'BACK'  => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/back1.gif",
  2924.             'CLOSE' => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/exit.gif",
  2925.             'EDIT'  => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/edit.gif",
  2926.             'FIND'  => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/filter.gif",
  2927.             'SAVE'  => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/filesave.gif",
  2928.             'COPY'  => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/filesaveas.gif",
  2929.             'STOP'  => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/stop_hand.gif",
  2930.             'TRASH' => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/edittrash.gif",
  2931.             'UNDO'  => $GLOBALS['PROJECT']['SYSIMGURL']."icons-22x22/undo.gif"
  2932.         );
  2933.     }
  2934.  
  2935.     /**
  2936.       * sets object HTMLFORM variables:
  2937.       * - HTMLFORM_mode
  2938.       * - HTMLFORM_URL_action
  2939.       * - HTMLFORM_URL_back
  2940.       * - HTMLFORM_URL_next
  2941.       * - HTMLFORM_URL_reload
  2942.       *
  2943.       * @param array $DBVAL 
  2944.       * @param int $mode 
  2945.       * @param string $frmAction 
  2946.       * @param string $nextURI 
  2947.       * @param string $arrName 
  2948.       * @param boolean $debug 
  2949.       *
  2950.       * @since pk-05-03-22
  2951.       * @version pk-05-06-22
  2952.       * @version pk-05-09-05
  2953.       * @version pk-05-11-04
  2954.       * @version pk-06-03-07 HTMLFORM_arrayName added
  2955.       *
  2956.       ***/
  2957.     function setHTMLFORM_objectVar($DBVAL,$mode=FRM_MODE_READONLY,$frmAction="",$nextURI="",$arrName="DBVAL",$debug=FALSE{
  2958.         $debug ($debug || $this->debugMode);
  2959.         if ($debugecho "<p><b>DBMS_FORM::setHTMLFORM_objectVar(\$DBVAL,$mode,$frmAction,$nextURI,$arrName,...)</b> (".get_class($this).")</p>";
  2960.  
  2961.         $this->setFrmMode($mode)// <pk-05-11-04 />
  2962.  
  2963.         global ${$arrName};
  2964.         ${$arrName}=&$DBVAL;
  2965.  
  2966.         // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2967.         // setting HTMLFORM object vars
  2968.  
  2969.         $this->HTMLFORM_arrayName=$arrName// <pk-06-03-07 />
  2970.         $this->HTMLFORM_mode=$mode;
  2971.         if (empty($frmAction)) {
  2972.             switch($mode{
  2973.                 case FRM_MODE_NEW:
  2974.                 case FRM_MODE_COPY// <pk-05-09-05>
  2975.                     $this->HTMLFORM_URL_action=$GLOBALS['PROJECT']['SYSTEMURL']."forms/insert.php?".$_SERVER['QUERY_STRING'];
  2976.                     break;
  2977.                 case FRM_MODE_EDIT:
  2978.                     $this->HTMLFORM_URL_action=$GLOBALS['PROJECT']['SYSTEMURL']."forms/update.php?".$_SERVER['QUERY_STRING'];
  2979.                     break;
  2980.                 case FRM_MODE_DELETE:
  2981.                     $this->HTMLFORM_URL_action=$GLOBALS['PROJECT']['SYSTEMURL']."forms/delete.php?".$_SERVER['QUERY_STRING'];
  2982.                     break;
  2983.             }
  2984.         else {
  2985.             $this->HTMLFORM_URL_action=$frmAction;
  2986.         }
  2987.  
  2988.         if (empty($_POST['FRMRELOADURL']))   {
  2989.             if (empty($this->HTMLFORM_URL_reload)) // <pk-05-07-20>
  2990.                 $this->HTMLFORM_URL_reload=$_SERVER['REQUEST_URI'];
  2991.             // </ pk-05-07-20>
  2992.         else {
  2993.             $this->HTMLFORM_URL_reload=$_POST['FRMRELOADURL'];
  2994.         }
  2995.  
  2996.         if (!strstr($this->HTMLFORM_URL_reload,"?")) $this->HTMLFORM_URL_reload.="FRMID=".$this->getId()// <pk-05-07-06 />
  2997.  
  2998.         // <pk-05-06-22> only set backurl if not set
  2999.         if (empty($this->HTMLFORM_URL_back)) {
  3000.             if (!empty($_POST['B64FRMREFURL'])) $this->HTMLFORM_URL_back=base64_decode($_POST['B64FRMREFURL']);
  3001.             else                                $this->HTMLFORM_URL_back=(isset($_SERVER['HTTP_REFERER']$_SERVER['HTTP_REFERER'"");
  3002.         }
  3003.         // </pk-05-06-22>
  3004.  
  3005.  
  3006.         if (strstr($nextURI,"/system/forms/"&& (!empty($_POST[$this->getName()."_NEXT"]))) // <pk-05-10-26>
  3007.             $this->HTMLFORM_URL_next base64_decode($_POST[$this->getName()."_NEXT"]);
  3008.         else if (!empty($nextURI))                        $this->HTMLFORM_URL_next $nextURI;
  3009.         else if (!empty($_POST[$this->getName()."_NEXT"]))  $this->HTMLFORM_URL_next base64_decode($_POST[$this->getName()."_NEXT"]);
  3010.         else if (!empty($_SERVER['HTTP_REFERER']))          $this->HTMLFORM_URL_next $_SERVER['HTTP_REFERER'];
  3011.         else                                                $this->HTMLFORM_URL_next $nextURI=dirname($_SERVER['SCRIPT_FILENAME'])."/index.php?".$_SERVER['QUERY_STRING'];
  3012.  
  3013.     }
  3014.  
  3015.  
  3016.     /**
  3017.       * returns the html form statement
  3018.       *
  3019.       * @returns string
  3020.       *
  3021.       * @since pk-06-02-06
  3022.       * @version pk-07-01-18
  3023.       *
  3024.       ***/
  3025.     function getHTMLFormStatement({
  3026.         if (empty($this->HTMLFORM_URL_action)) {
  3027.             switch(intval($this->HTMLFORM_mode)) {
  3028.                 case FRM_MODE_NEW:
  3029.                 case FRM_MODE_COPY:
  3030.                     $s_action=$GLOBALS['PROJECT']['SYSTEMURL']."forms/insert.php?".$_SERVER['QUERY_STRING'];
  3031.                     break;
  3032.                 case FRM_MODE_EDIT:
  3033.                     $s_action=$GLOBALS['PROJECT']['SYSTEMURL']."forms/update.php?".$_SERVER['QUERY_STRING'];
  3034.                     break;
  3035.                 case FRM_MODE_DELETE:
  3036.                    $s_action=$GLOBALS['PROJECT']['SYSTEMURL']."forms/delete.php?".$_SERVER['QUERY_STRING'];
  3037.                     break;
  3038.                 default:
  3039.                     $s_action=$_SERVER['REQUEST_URI'];
  3040.             }
  3041.             $this->HTMLFORM_URL_action=$s_action;
  3042.         else {
  3043.             $s_action=$this->HTMLFORM_URL_action;
  3044.         }
  3045.         if (isset($_GET[session_name()])) {
  3046.             $s_action=pcf_HTML_changeURI_GetValue($s_action,session_name(),session_id());
  3047.         }
  3048.  
  3049.         $s_ret ="\n<form name=\"".$this->getHTMLName()."\" method=\"post\" action=\"".$s_action."\" ".$this->FRMTAGADD." >\n";
  3050.         return $s_ret;
  3051.     }
  3052.  
  3053.     /**
  3054.       * returns the html code for the hidden form fields
  3055.       * beside the method parameters the HTMLFORM object:
  3056.       * - HTMLFORM_mode
  3057.       * - HTMLFORM_URL_action
  3058.       * - HTMLFORM_URL_back
  3059.       * - HTMLFORM_URL_next
  3060.       * - HTMLFORM_URL_reload
  3061.       * are used.
  3062.       *
  3063.       * @param string $arrName 
  3064.       * @param boolean $debug 
  3065.       *
  3066.       * @returns string
  3067.       *
  3068.       * @since pk-05-03-22
  3069.       * @version pk-05-09-13
  3070.       * @version pk-06-09-11 FRMRELOADFLD added
  3071.       *
  3072.       ***/
  3073.     function getHTMLFormHiddenFields($arrName="DBVAL",$debug=FALSE{
  3074.         if ($debugecho "<p><b>DBMS_FORM::getHTMLFormHiddenFields(...)</b> (".get_class($this).")</p>";
  3075.         global ${$arrName}// <pk-05-09-13>
  3076.  
  3077.         require_once __OCSP_PHPINCPATH__."common/pcf_md5.phpinc";
  3078.  
  3079.         $ret ="\n\t<!-- _______ HIDDEN COMMAND FIELDS ______ -->\n";
  3080.         $ret.="\t\t<input type=\"hidden\" name=\"FRMMODE\"          value=\"".$this->HTMLFORM_mode."\">\n";
  3081.         $ret.="\t\t<input type=\"hidden\" name=\"FRMACTION\"        value=\"".$this->HTMLFORM_URL_action."\">\n";
  3082.  
  3083.         $ret.="\t\t<input type=\"hidden\" name=\"DBMSFORMID\"       value=\"".$this->getId()."\">\n";
  3084.         $ret.="\t\t<input type=\"hidden\" name=\"FRMARRAYNAME\"     value=\"".$arrName."\">\n";
  3085.         $ret.="\t\t<input type=\"hidden\" name=\"FRMRELOADFLD\"     value=\"\">\n"// <pk-06-09-11 />
  3086.  
  3087.         // infos about the table object (if not of class DBMS_TABLEOBJ)
  3088.         $valInc="";$valClass="";
  3089.         if (!empty($this->myDBMS_TABLEOBJ_class)) {
  3090.             $valClass=$this->myDBMS_TABLEOBJ_class;
  3091.             if (empty($this->myDBMS_TABLEOBJ_include)) {
  3092.                 // we only have the class
  3093.                 // check if can get the source
  3094.                 if (class_exists($valClass)) {
  3095.                     // the class source is included
  3096.                     @eval("\$obj=new ".$valClass."();");
  3097.                     if (is_object($obj&& method_exists($obj,"getClassFile")) {
  3098.                         // the class has the method getClassFile no check if it reaturns a value
  3099.                         // see DBMS_TABLEOBJ how to implement this class
  3100.                         if (!($this->myDBMS_TABLEOBJ_include=$obj->getClassFile(FALSE,$debug))) $valClass=NULL;
  3101.                     else $valClass=NULL;
  3102.                     unset($obj);
  3103.                 else $valClass=NULL;
  3104.  
  3105.             }
  3106.             $valInc  =pcfmd5_encrypt($this->myDBMS_TABLEOBJ_include);
  3107.             if ($debug$ret.= "\t\t<!-- DBMS_TABLEOBJ_include: ".$this->myDBMS_TABLEOBJ_include." -->\n";
  3108.         else if (!empty($_POST['DBMS_TABLEOBJ_class'])) {
  3109.             // we already have post values by form reload
  3110.             // ensure not to get values from a previous form here.
  3111.             $valClass=$_POST['DBMS_TABLEOBJ_class'];
  3112.             $valInc  =$_POST['DBMS_TABLEOBJ_include'];
  3113.         }
  3114.         if (!empty($valClass)) {
  3115.             $ret.="\t\t<input type=\"hidden\" name=\"DBMS_TABLEOBJ_include\"    value=\"".$valInc."\">\n";
  3116.             $ret.="\t\t<input type=\"hidden\" name=\"DBMS_TABLEOBJ_class\"      value=\"".$valClass."\">\n";
  3117.         }
  3118.  
  3119.         $ret.="\t\t<input type=\"hidden\" name=\"FRMQUERYSTRING\"   value=\"";
  3120.         if (empty($_POST['FRMQUERYSTRING']))                        $ret.=$_SERVER['QUERY_STRING']."\">\n";
  3121.         else                                                        $ret.=$_POST['FRMQUERYSTRING']."\">\n";
  3122.  
  3123.         $ret.="\t\t<input type=\"hidden\" name=\"FRMSCRIPTFILENAMECRYPT\" value=\"";
  3124.         if (empty($_POST['FRMSCRIPTFILENAMECRYPT']))                $ret.=pcfmd5_encrypt($_SERVER['SCRIPT_FILENAME'])."\">\n";
  3125.         else                                                        $ret.=$_POST['FRMSCRIPTFILENAMECRYPT']."\">\n";
  3126.  
  3127.         $ret.="\t\t<input type=\"hidden\" name=\"FRMRELOADURL\"     value=\"".$this->HTMLFORM_URL_reload."\">\n";
  3128.         $ret.="\t\t<input type=\"hidden\" name=\"".$this->getName()."_NEXT\" value=\"".base64_encode($this->HTMLFORM_URL_next)."\">\n";
  3129.  
  3130.         $ret.="\t\t<input type=\"hidden\" name=\"B64FRMREFURL\" value=\"".base64_encode($this->HTMLFORM_URL_back)."\">\n";
  3131.  
  3132.         // <pk-05-09-13>
  3133.         if (($this->HTMLFORM_mode==FRM_MODE_EDIT|| ($this->HTMLFORM_mode==FRM_MODE_COPY)) {
  3134.             if (empty($_POST[$this->getName().'_FRMKEYS'])) {
  3135.                 $a_keys=$this->getKeyArray();
  3136.                 $a_postKeys=array();
  3137.                 if (is_array($a_keys)) // <pk-06-08-08 >
  3138.                     foreach($a_keys as $a_keyData{
  3139.                         $a_keyData['VALUE']=${$arrName}[$a_keyData['NAME']];
  3140.                         $a_postKeys[]=$a_keyData;
  3141.                     }
  3142.                 }
  3143.                 if ($debugecho "<pre>".print_r($a_postKeys,TRUE)."</pre>";
  3144.                 $ret.="\t\t<input type=\"hidden\" name=\"".$this->getName()."_FRMKEYS\" value=\"".base64_encode(serialize($a_postKeys))."\">\n";
  3145.             else {
  3146.                 $ret.="\t\t<input type=\"hidden\" name=\"".$this->getName()."_FRMKEYS\" value=\"".$_POST[$this->getName().'_FRMKEYS']."\">\n";
  3147.             }
  3148.         }
  3149.         // </pk-05-09-13>
  3150.  
  3151.         $ret.="\t<!-- _______ END HIDDEN COMMAND FIELDS ______ -->\n\n";
  3152.  
  3153.         return $ret;
  3154.     }
  3155.  
  3156.     /**
  3157.       * returns the html code for the form buttons row (colspan=2)
  3158.       *
  3159.       * beside the method parameters the HTMLFORM object:
  3160.       * - HTMLFORM_URL_action
  3161.       * - HTMLFORM_URL_back
  3162.       * - HTMLFORM_URL_next
  3163.       * - HTMLFORM_URL_reload
  3164.       * - FRMADDBUTTONS html code to add in the button line
  3165.       * are used.
  3166.       *
  3167.       * button images are derived from $this->HTMLFORM_button_src[] array
  3168.       *
  3169.       * in read only mode
  3170.       *     if userCanEdit editbutton is added
  3171.       *         link is $this::FRMEDITURL or $this::HTMLFORM_URL_reload?FRMCMD=EDIT
  3172.       *     if userCanDelete delete button is added
  3173.       *         only if not emtpy $this::FRMDELETEURL
  3174.       * @param int $mode 
  3175.       * @param string $arrName 
  3176.       * @param boolean $debug 
  3177.       *
  3178.       * @returns string
  3179.       *
  3180.       * @since pk-05-03-22
  3181.       * @version pk-05-12-14
  3182.       * @version pk-06-01-09
  3183.       * @version pk-06-02-13 class=\"button\" added to img-tages
  3184.       * @version pk-06-09-11 remove _DBMS_FIELDS from MD5DELVALKEY
  3185.       *
  3186.       ***/
  3187.     function getHTMLFormButtons($mode=FRM_MODE_READONLY,$arrName="DBVAL",$debug=FALSE{
  3188.         if ($debugecho "<p><b>DBMS_FORM::getHTMLFormButtons(...)</b> (".get_class($this).")</p>";
  3189.  
  3190.         $this->setHTMLFORM_BtnSource()// <pk-06-12-18 />
  3191.         require_once __OCSP_PHPINCPATH__."common/pcf_md5.phpinc";
  3192.  
  3193.         $ret ="\n\t<!-- _______ BUTTONS ______ -->\n\n";
  3194.         $ret.="\t<tr><td class=\"frmButtons\" colspan=\"2\">\n";
  3195.  
  3196.         if ($GLOBALS['USER']->isAdmin()) {
  3197.             $ret.="<div style=\"padding:0px;margin:0px;display:inline;float:right;\">";
  3198.             $ret.="<a href=\"".$GLOBALS['PROJECT']['ADMINURL']."dbms/editframe.php?FRM_ID=".$this->getId()."\" target=\"_blank\" title=\"Formular bearbeiten\">";
  3199.             $ret.="<img src=\"".$GLOBALS['PROJECT']['SYSIMGURL']."/icons-22x22/editConstruct.gif\" border=\"0\" alt=\"Formular bearbeiten\" class=\"button\"></a>\n";
  3200.             $ret.="</div>";
  3201.         }
  3202.  
  3203.         if (!empty($_GET['OPENERURL'])) {
  3204.             // we are in a popup add close button
  3205.             $ret.="\t\t<a href=\"#\" onClick=\"javascript:{top.close();}\">";
  3206.             $ret.="<img src=\"".$this->HTMLFORM_button_src['CLOSE']."\" alt=\"schliessen\" border=\"0\" class=\"button\">";
  3207.             $ret.="</a>\n";
  3208.         else if (!empty($this->HTMLFORM_URL_back)) {
  3209.             $ret.="\t\t<a href=\"$this->HTMLFORM_URL_back\">";
  3210.             $ret.="<img src=\"".$this->HTMLFORM_button_src['BACK']."\" class=\"button\" alt=\"abbrechen\" border=\"0\" class=\"button\">";
  3211.             $ret.="</a>\n";
  3212.         }
  3213.  
  3214.         switch($mode{
  3215.             case FRM_MODE_SEARCH:
  3216.                 $ret.="\t\t<input type=\"hidden\" name=\"SEARCH\">\n";
  3217.                 $ret.="\t\t<a href=\"#\" onClick=\"document.forms['".$this->getHTMLName()."'].SEARCH.value='".$this->getName()."';document.forms['".$this->getHTMLName()."'].submit()\">";
  3218.                 $ret.="<img src=\"".$this->HTMLFORM_button_src['FIND']."\" class=\"button\" alt=\"filtern\" border=\"0\" class=\"button\">";
  3219.                 $ret.="</a>\n";
  3220.                 break;
  3221.             case FRM_MODE_DELETE:
  3222.                 global ${$arrName};
  3223.                 $DBVAL=${$arrName};
  3224.                 if (!is_array($DBVAL)) {
  3225.                     if ($debugecho "\n<h2 style=\"color: red;font-weight:bold\">ERROR</h2><p>global var \$".$arrName." is not an array</p>\n";
  3226.                     $DBVAL=array();
  3227.                 }
  3228.                 foreach($DBVAL as $key => $val{
  3229.                     $ret.="\t\t\t<input type=\"hidden\" name=\"".$arrName."[".$key."]\" value=\"".htmlspecialchars($val)."\">\n";
  3230.                 }
  3231.  
  3232.                 if (empty($_GET['OPENERURL']&& empty($this->HTMLFORM_URL_back)) {
  3233.                     $ret.="\t\t<a href=\"#\" onClick=\"javascript:{history.back()}\">";
  3234.                     $ret.="<img src=\"".$this->HTMLFORM_button_src['BACK']."\" class=\"button\" alt=\"abbrechen\" border=\"0\">";
  3235.                     $ret.="</a>\n";
  3236.                 }
  3237.                 // <pk-06-09-11>
  3238.                 $a_dbVal=$DBVAL;
  3239.                 unset($a_dbVal['_DBMS_FIELDS']);
  3240.  
  3241.                 $ret.="\t\t\t<input type=\"hidden\" name=\"MD5DELVALKEY\" value=\"".pcfmd5_encrypt(serialize($a_dbVal))."\">\n";
  3242.                 // </pk-06-09-11>
  3243.                 $ret.="\t\t<a href=\"#\" onClick=\"document.forms['".$this->getHTMLName()."'].submit()\">";
  3244.                 $ret.="<img src=\"".$this->HTMLFORM_button_src['TRASH']."\" class=\"button\" alt=\"l�chen\" border=\"0\">";
  3245.                 $ret.="</a>\n";
  3246.                 break;
  3247.             default:
  3248.                 if (empty($_GET['OPENERURL']&& empty($this->HTMLFORM_URL_back)) {
  3249.                     $ret.="\t\t<a href=\"#\" onClick=\"javascript:{history.back()}\">";
  3250.                     $ret.="<img src=\"".$this->HTMLFORM_button_src['BACK']."\" class=\"button\" alt=\"abbrechen\" border=\"0\">";
  3251.                     $ret.="</a>\n";
  3252.                 }
  3253.  
  3254.                 if ($mode != FRM_MODE_READONLY{
  3255.                     if ($mode != FRM_MODE_COPY{
  3256.                         $ret.="\t\t<a href=\"#\" onClick=\"document.forms['".$this->getHTMLName()."'].submit()\" title=\"speichern\">";
  3257.                         $ret.="<img src=\"".$this->HTMLFORM_button_src['SAVE']."\" class=\"button\" alt=\"speichern\" border=\"0\">";
  3258.                         $ret.="</a>\n";
  3259.                     else {
  3260.                         $ret.="\t\t<a href=\"#\" onClick=\"document.forms['".$this->getHTMLName()."'].submit()\" title=\"Kopie speichern\">";
  3261.                         $ret.="<img src=\"".$this->HTMLFORM_button_src['COPY']."\" class=\"button\" alt=\"speichern\" border=\"0\">";
  3262.                         $ret.="</a>\n";
  3263.                     }
  3264.                 }
  3265.  
  3266.                 if (($mode == FRM_MODE_EDIT&& (!empty($this->FRMDELETEURL))) // <pk-05-12-14>
  3267.                     // we assume here that if the user is allowed to edit the form data he will also be allowed to delete the row
  3268.                     // this can be done here because normale $this->FRMDELETEURL should lead to a page were the user is asked
  3269.                     // if he realy wants to delete the data and here you should also check if he is allowed to
  3270.                     $ret.="\t\t<a href=\"".pcf_HTML_changeURI_GetValue($this->FRMDELETEURL,session_name(),session_id())."\">";
  3271.                     $ret.="<img src=\"".$this->HTMLFORM_button_src['TRASH']."\" class=\"button\" alt=\"l&ouml;schen\" border=\"0\">";
  3272.                     $ret.="</a>\n";
  3273.                 }
  3274.  
  3275.         }
  3276.  
  3277.         if ($mode != FRM_MODE_READONLY{
  3278.             if ($mode != FRM_MODE_DELETE{
  3279.                 $ret.="\t\t<a href=\"#\" onClick=\"{document.forms['".$this->getHTMLName()."'].reset();}\">";
  3280.                 $ret.="<img src=\"".$this->HTMLFORM_button_src['UNDO']."\" class=\"button\" alt=\"reset\" border=\"0\" class=\"button\">";
  3281.                 $ret.="</a>\n";
  3282.             }
  3283.         else {
  3284.             if ($this->userCanEdit(0,$debug)) {
  3285.                 if (!empty($this->FRMEDITURL)) {// <pk-06-01-09 >
  3286.                     $s_editUrl=$this->FRMEDITURL;
  3287.                 else {
  3288.                     $s_editUrl=$this->HTMLFORM_URL_reload;
  3289.                     if (!strstr($s_editUrl,"&FRMCMD=EDIT")) $s_editUrl.="&FRMCMD=EDIT";
  3290.                 }
  3291.                 $s_editUrl=pcf_HTML_changeURI_GetValue($s_editUrl,session_name(),session_id());
  3292.                 $ret.="\t\t<a href=\"#\" onClick=\"document.location.href='".$s_editUrl."';\">";
  3293.                 $ret.="<img src=\"".$this->HTMLFORM_button_src['EDIT']."\" class=\"button\" alt=\"reset\" border=\"0\" class=\"button\">";
  3294.                 $ret.="</a>\n";
  3295.             }
  3296.             if ($this->userCanDelete(0,$debug&& (!empty($this->FRMDELETEURL))) // <pk-06-01-09>
  3297.                 $ret.="\t\t<a href=\"".pcf_HTML_changeURI_GetValue($this->FRMDELETEURL,session_name(),session_id())."\">";
  3298.                 $ret.="<img src=\"".$this->HTMLFORM_button_src['TRASH']."\" class=\"button\" alt=\"l&ouml;schen\" border=\"0\" class=\"button\">";
  3299.                 $ret.="</a>\n";
  3300.             }
  3301.         }
  3302.  
  3303.  
  3304.         $ret.=$this->FRMADDBUTTONS;
  3305.  
  3306.         $ret.="\t</td></tr>\n";
  3307.         $ret.="\n\t<!-- _______ END BUTTONS ______ -->\n\n";
  3308.  
  3309.         return $ret;
  3310.     }
  3311.  
  3312.  
  3313.  
  3314.  
  3315.     /**
  3316.       * returns the html code for the complete form
  3317.       *
  3318.       * object vars used
  3319.       * you can set them to change layout or enlarge functionality
  3320.       *
  3321.       * - FRMTAGADD (<form ..... FRMTAGADD>)
  3322.       * - FRMTBLTAG (<table .... FRMTBLTAG>)
  3323.       * - FRMTBLHEADERROW (1st row in the table example: <tr><td colspan="2">.....</td></tr>);
  3324.       * - FRMDELETEURL (<a href=\"$this->FRMDELETEURL\">...)
  3325.       * - FRMADDBUTTONS (html code to add in the button line)
  3326.       * - FRMNOBUTTONS do not add buttons in read only mode
  3327.       *
  3328.       * @param array $DBVAL 
  3329.       * @param int $mode 
  3330.       * @param string $frmAction 
  3331.       * @param string $nextURI 
  3332.       * @param string $arrName 
  3333.       * @param boolean $debug 
  3334.       *
  3335.       * @returns string
  3336.       *
  3337.       * @since pk-04-12-29
  3338.       * @version pk-05-02-08 if $frmAction != "" don't append $_SERVER['QUERY_STRING']
  3339.       * @version pk-06-02-06 call of getHTMLFormStatement()
  3340.       * @version pk-07-02-28 pcf_get_htmlJsInclude
  3341.       *
  3342.       * @todo BUG DBMSFORMID sometimes DBMSFORMID is 0 workaround with $_POST is done now
  3343.       *
  3344.       ***/
  3345.     function getHTMLFormFromArray($DBVAL,$mode=FRM_MODE_READONLY,$frmAction="",$nextURI="",$arrName="DBVAL",$debug=FALSE{
  3346.         $debug ($debug || $this->debugMode);
  3347.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::getTableFromArray(\$DBVAL,$mode,$frmAction,$nextURI,$arrName,...)");
  3348.  
  3349.         global ${$arrName};
  3350.         ${$arrName}=&$DBVAL;
  3351.  
  3352.         if (empty($nextURI)) $nextURI=$_SERVER['SCRIPT_NAME'];
  3353.  
  3354.         $this->setHTMLFORM_objectVar($DBVAL,$mode,$frmAction,$nextURI,$arrName,$debug);
  3355.  
  3356.         $s_ret="\n\n<!-- ____________________FORMULAR START___________________________ -->\n\n";
  3357.         //        $s_ret.=pcf_get_htmlJsInclude($GLOBALS['PROJECT']['JAVASCRIPTURL']."forms.js.php"); // <pk-07-02-28 />
  3358.         $s_ret.=$this->getHTMLFormStatement()// <pk-06-02-06>
  3359.         $s_ret.=$this->getHTMLFormHiddenFields($arrName,$debug);
  3360.  
  3361.         $s_ret.="<table ".(isset($this->FRMTBLTAG$this->FRMTBLTAG "").">\n"// <pk-06-08-09 /> E_ALL
  3362.         if (isset($this->FRMTBLHEADERROW&& (!empty($this->FRMTBLHEADERROW))) // <pk-06-08-09 /> E_ALL
  3363.             $s_ret.=$this->FRMTBLHEADERROW;
  3364.         }
  3365.  
  3366.         if ($this->hasErrors()) {
  3367.             $s_ret.="\t<tr><td class=\"frmErrorLabel\">Fehler</td><td class=\"frmErrorText\">".$this->getErrors("<br />")."</td></tr>\n";
  3368.         }
  3369.  
  3370.         $s_ret.="\n\t<!-- ____________________ FORM DATA ____________________ -->\n";
  3371.         $s_ret.=$this->getTableFromArray($DBVAL,$mode,$arrName,$debug);
  3372.         $s_ret.="\t<!-- ____________________ END FORM DATA ____________________ -->\n\n";
  3373.  
  3374.         if (($mode != FRM_MODE_READONLY|| (!$this->FRMNOBUTTONS)) // <pk-06-12-29>
  3375.             $s_ret.=$this->getHTMLFormButtons($mode,$arrName,$debug);
  3376.         }
  3377.  
  3378.         $s_ret.="</table>\n";
  3379.         $s_ret.="</form>\n";
  3380.         $s_ret.="\n\n<!-- __________________FORMULAR ".$this->getName()." END_________________________ -->\n\n";
  3381.  
  3382.         return $s_ret;
  3383.     }
  3384.  
  3385.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3386.     // tabs
  3387.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3388.  
  3389.     /**
  3390.       * returns an array with links to use in a tab
  3391.       * NOTE templates are not parsed
  3392.       *
  3393.       * @param int $mode 
  3394.       * @param boolean $debug 
  3395.       *
  3396.       * @return array 
  3397.       *
  3398.       * @since pk-06-09-12
  3399.       *
  3400.       ***/
  3401.     function getTabLinkArray($mode,$debug=FALSE{
  3402.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::getTabLinkArray()");
  3403.  
  3404.         $a_ret=array();
  3405.         $a_fields=$this->getFieldArr(TRUE);
  3406.         foreach($a_fields as &$o_fld{
  3407.             if (isset($o_fld->lstLink['ASTAB']&& $o_fld->lstLink['ASTAB'&& $o_fld->isToShow($mode,$debug)) {
  3408.                 $a_ret[$o_fld->getName()]=$o_fld->lstLink;
  3409.             }
  3410.         }
  3411.         return $a_ret;
  3412.     }
  3413.  
  3414.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3415.     // checks
  3416.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3417.  
  3418.     /**
  3419.       * checks if all required (NOT NULL FIELDS) are set
  3420.       *
  3421.       * @param array    $postArr    Array with values
  3422.       * @param string   $table      Name of the table if empty all tabels are checked
  3423.       * @param string   $arrName    Name of the global data array (${$arrName})
  3424.       * @param boolean     $debug      show debug information
  3425.       *
  3426.       * @returns boolean    TRUE if all fields are set else FALSE
  3427.       *
  3428.         version pk-03-10-14
  3429.       * @version pk-03-12-13    getValue instead of slashedValue
  3430.       * @version pk-04-08-03    use $obj->allow NULL
  3431.       *
  3432.       ***/
  3433.     function checkForNVL($postArr,$table="",$arrName="DBVAL",$debug=FALSE{
  3434.         $debug=($debug || $this->debugMode);
  3435.         if ($debug{
  3436.             echoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::checkForNVL()");
  3437.             echoDebug(__FILE__,"<pre style=\"background-color:#C0C0C0;border: solid 1px blue;\">".print_r($postArr,TRUE)."</pre>");
  3438.         }
  3439.         $ret=TRUE;
  3440.         $fldLst=$this->getFieldArr(TRUE);   // to have the error messages in same order as fields
  3441.         foreach($fldLst as $key => $obj{
  3442.             if (!$obj->isHidden && !$obj->allowNull &&
  3443.                 ((empty($table)) || ($obj->myTable == $table|| ($obj->myTableAlias  == $table))) {
  3444.                 if ($debugechoDebug(__FILE__,"<blockquote style=\"font-size: 80%\"><p>Testing: ".$obj->myName." Value: ".htmlspecialchars($postArr[$obj->myName])."</p>");
  3445.                 if ($obj->getValue($postArr[$obj->myName],$this->errors,$arrName,$debug=== FALSE{
  3446.                     if ($debugechoDebug(__FILE__,"<p style='color:red;font-weight:bolder;'> error in field: ".$obj->myName."</p>");
  3447.                     $ret=FALSE;
  3448.                 }
  3449.                 if ($debugechoDebug(__FILE__,"</blockquote>\n");
  3450.             }
  3451.         }
  3452.         if ($debugechoDebug(__FILE__,"<p style=\"font-size: 120%;\">DBMS_FORM::checkForNVL() returns: ".($ret "TREU" "FALSE ")."</p><hr />");
  3453.         return $ret;
  3454.     }
  3455.  
  3456.     /**
  3457.       * generates a sql update statement key = value pares
  3458.       * NOTE $cmd call by reference!!
  3459.       *
  3460.       * as this only APPENDS key=value pares to seperated with a ","
  3461.       * to the command you have to take care for a valid sql statement
  3462.       *
  3463.       * ATTANTION: the , is only set between key=value
  3464.       *
  3465.       * example:
  3466.       * <code>
  3467.       * $DBVAL=$_POST;
  3468.       * $cmd="UPDATE mytable SET myNotPostedField=1,";
  3469.       * // append http posted fields
  3470.       * if (!$frmObj->getUpdateValues($DBVAL,$cmd,"mytable","DBVAL") {
  3471.       *     // show error message
  3472.       *     $frmObj->writeErros();
  3473.       * } else {
  3474.       *     $cmd .= " WHERE myKey=1";
  3475.       *     $DBOBJ->executeCmd($cmd)
  3476.       * }
  3477.       * </code>
  3478.       *
  3479.       * @param array    $postArr   array with key=>value
  3480.       * @param string   &$cmd      IN-OUT first part of the sql statement includeing key word SET
  3481.       * @param string   $table     use only this table if set
  3482.       * @param string   $arrName   name of the global key=>value (${$arrName})
  3483.       * @param boolean     $debug     show debug option
  3484.       *
  3485.       * @returns boolean    TRUE
  3486.       *
  3487.       ***/
  3488.     function getUpdateValues($postArr,&$cmd,$table="",$arrName="DBVAL",$debug=FALSE{
  3489.         $debug=($debug || $this->debugMode);
  3490.         if ($debugecho "<hr /><p><b>DBMS_FORM::getUpdateValues($postArr,$cmd,$table,$arrName,$debug)</b></p><blockquote>";
  3491.         $sep=" ";
  3492.         if (!is_array($this->errors)) {
  3493.            $this->errors=array();
  3494.            $this->errors['ERROR']=FALSE;
  3495.         }
  3496.  
  3497.         if (isset($postArr['_DBMS_FIELDS'])) {
  3498.             $fieldLst=explode(",",$postArr['_DBMS_FIELDS']);
  3499.         else {
  3500.             if (!is_array($postArr)) {
  3501.                 $ERR="DBMS_FORM_NO_POST_ARRAY";
  3502.                 include $PROJECT['PHPINCPATH']."io/errors.phpinc";
  3503.                 die();
  3504.             }
  3505.             while(list($key,$valeach($postArr)) {
  3506.                 $fieldLst[]=$key;
  3507.             }
  3508.         }
  3509.  
  3510.         foreach($this->frmFields as $key => $obj{
  3511.             if ($debugecho "checking Field: ".$obj->myName.": ";
  3512.             if (in_array($obj->myName,$fieldLst)) {
  3513.                 if ($debugecho " FOUND ";
  3514.                 if ((empty($table)) || ($obj->myTable == $table|| ($obj->myTableAlias  == $table)) {
  3515.                     if ($tmp=$obj->getAssignment($postArr[$obj->myName],$this->errors,$arrName,$debug)) {
  3516.                         $cmd .= $sep.$tmp;
  3517.                         $sep=", ";
  3518.                     }
  3519.                 }
  3520.             }
  3521.             if ($debugecho "\n<br />";
  3522.         }
  3523.         return ($this->errors['ERROR'FALSE TRUE);
  3524.     }
  3525.  
  3526.     /**
  3527.       * returns an array with values checked against the form
  3528.       * sets the form errors in case of array but always returns the array
  3529.       * check the form for errors with this::hasErrors() before proceeding
  3530.       *
  3531.       * @param array $postArr   array with key=>value
  3532.       * @param string $table     use only this table if set
  3533.       * @param string $arrName   name of the global key=>value (${$arrName})
  3534.       * @param boolean $debug     show debug option
  3535.       *
  3536.       * @returns array
  3537.       *
  3538.       * @since   pk-03-12-13
  3539.       * @version pk-03-12-13
  3540.       * @version pk-05-02-22 don't check hidden fields (leads to errors in joins)
  3541.       * @version pk-05-12-05 debuging
  3542.       * @version pk-05-12-29 handling hidden auto_inc fields
  3543.       * @version pk-06-01-13 auto_inc fields are always NULL in FRM_MODE_NEW and FRM_MODE_COPY
  3544.       * @version pk-06-02-16 handling of sortorder fields (DBMS_FIELD_ORDERNR)
  3545.       ***/
  3546.     function getValueArray($postArr,$table="",$arrName="DBVAL",$debug=FALSE{
  3547.         if ($debug{
  3548.             echoDebug(__FILE__,"<p><b>DBMS_FORM::getValueArray(\$postArr,$table,$arrName,$debug)</b> (".get_class($this)."/".$this->frmName.")</p>",0);
  3549.             echoDebug(__FILE__,"<blockquote>\$postArr=<pre style=\"font-size:60%\">".htmlspecialchars(print_r($postArr,TRUE))."</pre></blockquote>",2);
  3550.         }
  3551.  
  3552.         if (!is_array($this->errors)) {
  3553.            $this->errors=array();
  3554.            $this->errors['ERROR']=FALSE;
  3555.         }
  3556.  
  3557.         if (!is_array($postArr)) {
  3558.             $this->errors['ERROR']=TRUE;
  3559.             $ERR=array(
  3560.                 'LABEL'=> 'FORMULAR: '.$this->frmName,
  3561.                 'MSG'  => 'keine Daten bermittelt'
  3562.             );
  3563.             return FALSE;
  3564.         }
  3565.  
  3566.         if (isset($postArr['_DBMS_FIELDS'])) {
  3567.             $fieldLst=explode(",",$postArr['_DBMS_FIELDS']);
  3568.         else {
  3569.             foreach($postArr as $key => $val{
  3570.                 $fieldLst[$key]=$key;   // to avoid multiple entries for fields with more then one input
  3571.             }
  3572.         }
  3573.  
  3574.         if ($debug{
  3575.             echoDebug(__FILE__,"<blockquote style=\"color:red\"><p>Checking for fields: ".implode(",",$fieldLst)."</p>",0);
  3576.         }
  3577.  
  3578.         $retArr=array();
  3579.         foreach($this->frmFields as $key => &$obj{
  3580.             if ($debugechoDebug(__FILE__,"<p>checking Field: <b>".$obj->getName()."</b>: (".get_class($obj).") \n",0);
  3581.             if (($obj->isAutoInc()) && (empty($postArr[$obj->getName()])) && (($this->getFrmMode()==FRM_MODE_NEW|| ($this->getFrmMode()==FRM_MODE_COPY))) // <pk-06-01-13>
  3582.                 // do not check empty AUTO_INCREMENT fields as the will be set if the data is stored
  3583.                 // if they are set we have to check them they could be of an other table
  3584.                 $retArr[$obj->getName()]=NULL;
  3585.                 // </ pk-06-01-13>
  3586.             else if (in_array($obj->getName(),$fieldLst)) {
  3587.                 if (!$obj->isHidden()) /* <pk-05-02-22> */
  3588.                     if ($debugechoDebug(__FILE__," FOUND ",0);
  3589.                     if ((empty($table)) || (trim($obj->getTable()) == trim($table)) || (trim($obj->getTblAlias())  == trim($table))) 
  3590.                     {
  3591.                         $s_value=(isset($postArr[$obj->getName()]$postArr[$obj->getName()NULL);
  3592.                         $retArr[$obj->getName()]=$obj->getValue($s_value,$this->errors,$arrName,$debug);
  3593.                         if ($debug{
  3594.                             echoDebug(__FILE__,"<pre style=\"font-size:10px;padding-left:20px;\">VALUES: ".htmlspecialchars(print_r($retArr[$obj->getName()],TRUE))."</pre>",1);
  3595.                             if ($this->hasErrors())  echoDebug(__FILE__,"<p style=\"background-color:red\">FORM HAS ERRORS --- FORM HAS ERRORS</p>",0);
  3596.                         }
  3597.                     else {
  3598.                         if ($debugechoDebug(__FILE__," but in ".$obj->myTable."  and not in ".$table,0)// <pk-05-12-05 />
  3599.                     }
  3600.                 else // <pk-06-08-18 />
  3601.                     if ($debugechoDebug(__FILE__," FOUND BUT HIDDEN",0);
  3602.                 // </pk-05-02-22>
  3603.                 unset($fieldLst[$obj->getName()]);
  3604.             else if (($obj->isAutoInc()) && ($this->getFrmMode()==FRM_MODE_EDIT)) // <pk-05-12-29>
  3605.                 // we have a hidden auto_inc field is the value set?
  3606.                 if (intval($postArr[$obj->getName()])) {
  3607.                     $retArr[$obj->getName()]=intval($postArr[$obj->getName()]);
  3608.                 }
  3609.             else if (pcf_is_instance_of($obj,"DBMS_FIELD_ORDERNR")) //<pk-06-02-16>
  3610.                 // handling of hidden disabled sortfields
  3611.                 if (!$obj->dbDesc['NULL']{
  3612.                     // not null column -> get a value to avoid errors
  3613.                     if ((empty($table)) || (trim($obj->getTable()) == trim($table)) || (trim($obj->getTblAlias())  == trim($table))) 
  3614.                     {
  3615.                         if (isset($postArr[$obj->getName()]&& intval($postArr[$obj->getName()])) // <pk-07-01-16 /> E_ALL
  3616.                             // we have a value set somewhere else use it
  3617.                             $retArr[$obj->getName()]=$postArr[$obj->getName()];
  3618.                         else {
  3619.                             $retArr[$obj->getName()]=$obj->getValue($postArr[$obj->getName()],$s_tmp,$arrName,$debug)// use $s_tmp to avoid form errors
  3620.                             if (!intval($retArr[$obj->getName()])) {
  3621.                                 $retArr[$obj->getName()]=1// set to 1 in case of no new value could be found by the field
  3622.                             }
  3623.                         }
  3624.                     }
  3625.                 }
  3626.             else if (isset($postArr[$obj->getName()]&& (!empty($postArr[$obj->getName()]))) // <pk-06-08-18 />
  3627.                 // check fields which are posted with values and not hidden but not in $fieldLst
  3628.                 // this happens when one field turns on or off another during getValue
  3629.                 // so you are able to add fields from another one you only have to look the the field changes the other
  3630.                 // comes first.
  3631.                 if ($debugechoDebug(__FILE__," FOUND IN POSTARRAY ",0);
  3632.                 if ((empty($table)) || (trim($obj->myTable== trim($table)) || (trim($obj->myTableAlias)  == trim($table))) {
  3633.                     if ($debugechoDebug(__FILE__," AND HAS VALUES for the table",0);
  3634.                     $retArr[$obj->getName()]=$obj->getValue($postArr[$obj->getName()],$s_tmp,$arrName,$debug)// use $s_tmp to avoid form errors
  3635.                 }
  3636.             }
  3637.             if ($debugechoDebug(__FILE__,"\n</p>",0);
  3638.         }
  3639.  
  3640.         if ($debugechoDebug(__FILE__,"<p>Returns:</p><pre>".htmlspecialchars(print_r($retArr,TRUE))."</pre></blockquote>",2);
  3641.         return $retArr;
  3642.     }
  3643.  
  3644.     /**
  3645.       * returns an 2 dimensional array of all form data [table][col]
  3646.       *
  3647.       * @param array $postArr   array with key=>value
  3648.       * @param boolean $debug     show debug option
  3649.       *
  3650.       * @returns array
  3651.       *
  3652.       * @since   pk-05-12-05
  3653.       * @version pk-06-01-13
  3654.       *
  3655.       ***/
  3656.     function getTableValueArrays($postArr,$debug=FALSE{
  3657.         if ($debug{
  3658.             echo "<hr><p><b>DBMS_FORM::getTableValueArrays(\$postArr,$arrName,$debug)</b> (".get_class($this)."/".$this->frmName.")</p>";
  3659.         }
  3660.  
  3661.         if (!is_array($this->errors)) {
  3662.            $this->errors=array();
  3663.            $this->errors['ERROR']=FALSE;
  3664.         }
  3665.  
  3666.         if (!is_array($postArr)) {
  3667.             $this->errors['ERROR']=TRUE;
  3668.             $ERR=array(
  3669.                 'LABEL'=> 'FORMULAR: '.$this->frmName,
  3670.                 'MSG'  => 'keine Daten bermittelt'
  3671.             );
  3672.             return FALSE;
  3673.         }
  3674.  
  3675.         if (isset($postArr['_DBMS_FIELDS'])) {
  3676.             $fieldLst=explode(",","::DUMMY::,".$postArr['_DBMS_FIELDS']);
  3677.         else {
  3678.             $fieldLst=array(0=>"::DUMMY::");
  3679.             foreach($postArr as $key => $val{
  3680.                 $fieldLst[$key]=$key;   // to avoid multiple entries for fields with more then one input
  3681.             }
  3682.         }
  3683.         $a_fldLst=array_flip($fieldLst);
  3684.  
  3685.         $s_arrName="GTVA_DBVAL".time();
  3686.         global ${$s_arrName};
  3687.         ${$s_arrName}=$postArr;
  3688.  
  3689.         if ($debug{
  3690.             echo "<p>Checking for fields: ".implode(",",$fieldLst)."</p>";
  3691.         }
  3692.  
  3693.         $retArr=array();
  3694.         foreach($this->frmFields as $key => $obj{
  3695.             if ($debug{echo "<p>checking Field: <b>".$obj->myName."</b>: (".get_class($obj).") \n";flush();}
  3696.             // <pk-06-01-13>
  3697.             if (($obj->dbDesc['AUTO_INCREMENT']&& (empty($postArr[$obj->myName])) && (($this->getFrmMode()==FRM_MODE_NEW|| ($this->getFrmMode()==FRM_MODE_COPY))) // <pk-06-01-13>
  3698.                 // do not check empty AUTO_INCREMENT fields as the will be set if the data is stored
  3699.                 // if they are set we have to check them they could be of an other table if the form consists of more than one
  3700.                 $retArr[$obj->myTable][$obj->myName]=NULL;
  3701.             else if (($obj->isToShow($this->getFrmMode(),$postArr)) && (intval($a_fldLst[$obj->myName]))) // in_array($obj->myName,$fieldLst))) {
  3702.                 if ($debugecho " FOUND ";
  3703.                 $retArr[$obj->myTable][$obj->myName]=$obj->getValue($postArr[$obj->myName],$this->errors,$s_arrName,FALSE)// no debug can be set in the field
  3704.                 if ($debug{
  3705.                     echo " VALUES: ".htmlspecialchars(print_r($retArr[$obj->myName]));
  3706.                     if ($this->hasErrors())  echo "<p style=\"background-color:red\">FORM HAS ERRORS --- FORM HAS ERRORS";
  3707.                 }
  3708.             else if (($obj->dbDesc['AUTO_INCREMENT']&& ($this->getFrmMode()==FRM_MODE_EDIT)) {
  3709.                 // we have a hidden auto_inc field is the value set?
  3710.                 // just set it :-)
  3711.                 if (intval($postArr[$obj->myName])) {
  3712.                     $retArr[$obj->myTable][$obj->myName]=intval($postArr[$obj->myName]);
  3713.                 }
  3714.             }
  3715.             // </pk-06-01-13>
  3716.             unset($a_fldLst[$obj->myName]);
  3717.             if ($debug{echo "\n</p>";flush();}
  3718.         }
  3719.  
  3720.         if (sizeof($a_fldLst)) {
  3721.             if ($debugecho "<p>NOT PROCESSED Fields:</p><pre>".print_r($a_fldLst,TRUE)."</pre>";
  3722.         }
  3723.  
  3724.         if ($debugecho "<p>DBMS_FORM::getTableValueArrays() Returns:</p><pre>".htmlspecialchars(print_r($retArr,TRUE))."</pre></blockquote>";
  3725.         unset(${$s_arrName});
  3726.         return $retArr;
  3727.     }
  3728.  
  3729.  
  3730.     /**
  3731.       * appends the values set in postArr to $cmd to use in SQL Where
  3732.       *
  3733.       * $cmd .= [AND] DBMS_FIELD::getAssignment()
  3734.       *
  3735.       * @param array $postArr 
  3736.       * @param string $cmd 
  3737.       * @param string $table 
  3738.       * @param string $arrName 
  3739.       * @param boolean $debug 
  3740.       *
  3741.       * @returns bool
  3742.       *
  3743.       ***/
  3744.     function getWhereValues($postArr,&$cmd,$table="",$arrName="DBVAL",$debug=FALSE{
  3745.         if ($debugecho "<pregetWhereValues($postArr,$cmd,$table,$arrName):\n\n";print_r($postArr);echo "</pre>";}
  3746.  
  3747.         $sep=" ";
  3748.         if (!is_array($this->errors)) {
  3749.            $this->errors=array();
  3750.            $this->errors['ERROR']=FALSE;
  3751.         }
  3752.  
  3753.         reset($this->frmKeys);
  3754.         while (list($key,$val)=each($this->frmKeys)) {
  3755.             if ($debugecho "checking Field: ".$val['NAME'].": ";
  3756.             if (isset($postArr[$val['NAME']])) {
  3757.                 if ($debugecho " FOUND ";
  3758.                 if ((empty($table)) || ($val['TABLE'== $table|| ($val['TABLE']  == $table)) {
  3759.                     $obj=&$this->frmFields[$val['TABLE'].".".$val['NAME']];
  3760.                     if ($tmp=$obj->getAssignment($postArr[$obj->myName],$this->errors,$arrName,$debug)) {
  3761.                         $cmd .= $sep.$tmp;
  3762.                         $sep=" AND ";
  3763.                     }
  3764.                 }
  3765.             else {
  3766.                 $this->errors['ERRORS']=TRUE;
  3767.                 $this->errors[$val['NAME']]="KEY_NOT_SET";
  3768.             }
  3769.             if ($debugecho "\n<br />";
  3770.         }
  3771.         return ($this->hasErrors(FALSE TRUE);
  3772.     }
  3773.  
  3774.     /**
  3775.       * returns a query string for the row in $rowArr
  3776.       *
  3777.       * @param array $dataArr 
  3778.       * @param string $table 
  3779.       * @param boolean $debug 
  3780.       *
  3781.       * @returns string
  3782.       *
  3783.       * @since pk-04-07-29
  3784.       *
  3785.       ***/
  3786.     function getRowQueryString($dataArr,$table="",$debug=FALSE{
  3787.         if ($debugecho "<p><b>DBMS_FORM::getRowQueryString(\$dataArr (".sizeof($dataArr)." Elements),$table..)</b> (".get_class($this).")</p>";
  3788.  
  3789.         $ret="";$sep="";
  3790.         foreach ($this->frmKeys as $key{
  3791.             if (empty($table|| ($key['TABLE']==$table)) {
  3792.                 $ret .= $sep.$key['NAME']."=".$dataArr[$key['NAME']];
  3793.                 $sep  "&";
  3794.             }
  3795.         }
  3796.         return $ret;
  3797.     }
  3798.  
  3799.  
  3800.     /**
  3801.       * generates a string with the column names to use in an insert statement
  3802.       * appends a comma seperated list to $cmd
  3803.       *
  3804.       * @see DBMS_FORM::getInsertValues for code example
  3805.       *
  3806.       * @param array    $postArr     array of fields posted by the form
  3807.       * @param string   &$cmd        the return string
  3808.       * @param string   $table       name of the table if set only oolumns of $table are added
  3809.       * @param boolean     $debug 
  3810.       *
  3811.       * @returns boolean    DBMS_FORM::hasErrors()
  3812.       *
  3813.       ***/
  3814.     function getInsertCols($postArr,&$cmd,$table="",$debug=FALSE{
  3815.         if ($debugecho "<hr><p><b>DBMS_FORM::getInsertCols($postArr,$cmd,$table,$debug)</b> (".get_class($this)." | ".$this->frmName.")</p><blockquote>";
  3816.         $sep=" ";
  3817.         if (isset($postArr['_DBMS_FIELDS'])) {
  3818.             $fieldLst=explode(",",$postArr['_DBMS_FIELDS']);
  3819.         else {
  3820.             if (!is_array($postArr)) {
  3821.                 $ERR="DBMS_FORM_NO_POST_ARRAY";
  3822.                 include $PROJECT['PHPINCPATH']."io/errors.phpinc";
  3823.                 die();
  3824.             }
  3825.             while(list($key,$valeach($postArr)) {
  3826.                 $fieldLst[]=$key;
  3827.             }
  3828.         }
  3829.  
  3830.         reset($this->frmFields);
  3831.         while (list($key,$obj)=each($this->frmFields)) {
  3832.             if ($debugecho "checking Field: ".$obj->myName.": ";
  3833.             if (in_array($obj->myName,$fieldLst)) {
  3834.                 if ($debugecho " FOUND ";
  3835.                 if ((!$obj->isAutoInc()) && ((empty($table)) || ($obj->myTable == $table|| ($obj->myTableAlias  == $table))) {
  3836.                     if ($debugecho "<pre>".print_r($obj->dbDesc,TRUE)."</pre>";
  3837.                     $cmd .= $sep.$obj->myName;
  3838.                     $sep=", ";
  3839.                 }
  3840.             }
  3841.             if ($debugecho "\n<br />";
  3842.         }
  3843.         if ($debugecho "</blockquote>";
  3844.         return ($this->hasErrors(FALSE TRUE);
  3845.  
  3846.     }
  3847.  
  3848.     /**
  3849.       * generates a string with comma seperated slashed
  3850.       * field values to use in an insert statement together
  3851.       * with DMBS_FORM::getInsertCols()
  3852.       *
  3853.       * example:
  3854.       * <code>
  3855.       * $frmObj->clearErrors();
  3856.       * $errors=TRUE;
  3857.       * do {
  3858.       *     $query="INSERT INTO T_CMS_MENU (";
  3859.       *     if (!($frmObj->getInsertCols($DBVAL,$query))) break;
  3860.       *     $query.=") VALUES (";
  3861.       *     if (!($frmObj->getInsertValues($DBVAL,$query))) break;
  3862.       *     $query.=")";
  3863.       *     $errors=FALSE;
  3864.       * } while (FALSE);
  3865.       * </code>
  3866.       *
  3867.       * @param array    $postArr     array of fields posted by the form
  3868.       * @param string   &$cmd        the return string
  3869.       * @param string   $table       name of the table if set only oolumns of $table are added
  3870.       * @param boolean     $debug 
  3871.       *
  3872.       * @return boolean    DBMS_FORM::hasErrors()
  3873.       *
  3874.       ***/
  3875.     function getInsertValues($postArr,&$cmd,$table="",$arrName="DBVAL",$debug=FALSE{
  3876.         if ($debugecho "<hr><p><b>DBMS_FORM::getInsertCols($postArr,$cmd,$table,$debug)</b> (".get_class($this)." | ".$this->frmName.")</p><blockquote>";
  3877.         $sep=" ";
  3878.         if (isset($postArr['_DBMS_FIELDS'])) {
  3879.             $fieldLst=explode(",",$postArr['_DBMS_FIELDS']);
  3880.         else {
  3881.             if (!is_array($postArr)) {
  3882.                 $ERR="DBMS_FORM_NO_POST_ARRAY";
  3883.                 include $PROJECT['PHPINCPATH']."io/errors.phpinc";
  3884.                 die();
  3885.             }
  3886.             while(list($key,$valeach($postArr)) {
  3887.                 $fieldLst[]=$key;
  3888.             }
  3889.         }
  3890.  
  3891.         reset($this->frmFields);
  3892.         while (list($key,$obj)=each($this->frmFields)) {
  3893.             if ($debugecho "<p>checking Field: ".$obj->myName.": </p><blockquote>";
  3894.             if (in_array($obj->myName,$fieldLst)) {
  3895.                 if ($debugecho " FOUND ";
  3896.                 if ((empty($table)) || ($obj->myTable == $table|| ($obj->myTableAlias  == $table)) {
  3897.                     $cmd .= $sep.$obj->slashedValue($postArr[$obj->myName],$this->errors,$arrName,$debug);
  3898.                     $sep=", ";
  3899.                 }
  3900.             }
  3901.             if ($debugecho "\n</blockquote>";
  3902.         }
  3903.         if ($debug{echo "<pre>ERRORS:\n";print_r($this->errors);echo "</pre></blockquote>";}
  3904.         return ($this->hasErrors(FALSE TRUE);
  3905.     }
  3906.  
  3907.  
  3908.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3909.     // error handling
  3910.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  3911.  
  3912.     /**
  3913.       * echos the form errors
  3914.       *
  3915.       * @param boolean $withLabel 
  3916.       *
  3917.       ***/
  3918.     function writeErros($withLabel=TRUE{
  3919.         if (is_array($this->errors)) {
  3920.             reset($this->errors);
  3921.             while(list($fld,$err)=each($this->errors)) {
  3922.                 if (is_array($err)) {
  3923.                     echo "<p style=\"background-color:red;\">";
  3924.                     if ($wihtLabelecho $err['LABEL'].": ";
  3925.                     echo $err['MSG'];
  3926.                     echo "</p>";
  3927.                 }
  3928.             }
  3929.         }
  3930.     }
  3931.  
  3932.     /**
  3933.       * returns the error in a string
  3934.       *
  3935.       * @param string $sep 
  3936.       * @param boolean $debug 
  3937.       * @param boolean $withoutLabel 
  3938.       *
  3939.       * @returns string
  3940.       *
  3941.       * @version pk-04-12-30
  3942.       *
  3943.       ***/
  3944.     function getErrors($sep="\n",$debug=FALSE,$withoutLabel=TRUE{
  3945.         if ($debugecho "<p><b>DBMS_FORM::getErrors(".htmlspecialchars($sep).",...)</b> (".get_class($this).")<br />FORM: ".$this->frmName." (".$this->frmId.") </p>";
  3946.         $ret="";
  3947.         if (is_array($this->errors)) {
  3948.             foreach($this->errors as $fld => $arr{
  3949.                 if ($fld != "ERROR"{
  3950.                     if ($debugecho "<blockquote>$fld:<pre>".print_r($arr,TRUE)."</pre></blockquote>";
  3951.                     if ($withoutLabel{
  3952.                         $ret.=$arr['MSG'].$sep;
  3953.                     else {
  3954.                         $ret.=$arr['LABEL'].": ".$arr['MSG'].$sep;
  3955.                     }
  3956.                 }
  3957.             }
  3958.         }
  3959.         return $ret;
  3960.     }
  3961.  
  3962.  
  3963.     /**
  3964.       * unsets $this->errors
  3965.       **/
  3966.  
  3967.     function clearErrors({
  3968.         unset($this->errors);
  3969.         $this->errors['ERROR']=FALSE;
  3970.     }
  3971.  
  3972.     /**
  3973.       * adds an error to this::errors
  3974.       *
  3975.       * @param array $aError with LABEL und MSG values
  3976.       * @param string $fld 
  3977.       *
  3978.       * @since pk-03-12-14
  3979.       * @version pk-03-12-14
  3980.       * @version pk-05-08-30
  3981.       *
  3982.       ***/
  3983.     function setError($aError,$fld=""{
  3984.         $this->errors['ERROR']=TRUE;
  3985.         if (empty($fld)) $fld=$this->frmName."_".sizeof($this->errors);
  3986.         // <pk-05-08-30>
  3987.         if (is_array($aError)) $this->errors[$fld]=$aError;
  3988.         else $this->errors[$fld]['MSG']=$aError;
  3989.         // </pk-05-08-30>
  3990.     }
  3991.  
  3992.     /**
  3993.       * checks $this->errors
  3994.       *
  3995.       * @returns bool
  3996.       *
  3997.       * @version pk-03-12-13
  3998.       *
  3999.       ***/
  4000.     function hasErrors({
  4001.         if (isset($this->errors['ERROR']))
  4002.             return ($this->errors['ERROR']);
  4003.         else
  4004.             return FALSE;
  4005.     }
  4006.  
  4007.     /**
  4008.       * returns the error array
  4009.       *
  4010.       * @returns array
  4011.       *
  4012.       * @since pk-06-03-06
  4013.       *
  4014.       ***/
  4015.     function getErrorArr({
  4016.         return $this->errors;
  4017.     }
  4018.  
  4019.     /**
  4020.       * sets the error array
  4021.       *
  4022.       * @param array $errArr 
  4023.       * @param boolean $merge 
  4024.       *
  4025.       * @since pk-06-03-06
  4026.       *
  4027.       ***/
  4028.     function setErrorArr($errArr,$merge=TRUE{
  4029.         if (!is_array($errArr)) return FALSE;   // no array -> do nothing
  4030.  
  4031.         if (!is_array($this->errors)) $this->errors=array('ERROR' => FALSE)// make sure we have an array
  4032.  
  4033.         if ($merge{
  4034.             $this->errors=array_merge($this->errors,$errArr);
  4035.         else {
  4036.             $this->errors=$errArr;
  4037.         }
  4038.     }
  4039.  
  4040.     // ##########################################################################################
  4041.     // ##########################################################################################
  4042.     //
  4043.     // list methods
  4044.     //
  4045.     // ##########################################################################################
  4046.     // ##########################################################################################
  4047.  
  4048.  
  4049.     /**
  4050.       * sets lstShowRowNr
  4051.       *
  4052.       * @param boolean $on 
  4053.       *
  4054.       * @since pk-05-07-05
  4055.       *
  4056.       ***/
  4057.     function lstShowRowNrOnOff($on=TRUE{
  4058.         $this->lstShowRowNr=$on;
  4059.     }
  4060.  
  4061.  
  4062.  
  4063.     /**
  4064.       * countListCols
  4065.       *
  4066.       * returns the number of cols the list table has
  4067.       *
  4068.       * @param array $links 
  4069.       * @param array $fields 
  4070.       *
  4071.       * @returns int
  4072.       *
  4073.       * @version pk-05-03-17
  4074.       * @version pk-05-07-05
  4075.       *
  4076.       ***/
  4077.     function countListCols($links=NULL,$fields=NULL{
  4078.         if (!is_array($fields)) $fields=$this->getFieldArr(TRUE);
  4079.  
  4080.         reset($fields)$cols=0;
  4081.         while(list($key,$val)=each($fields)) {
  4082.             if ((!$val->isHidden&& ($val->showInList)) {
  4083.                 /* <pk-05-03-17> */
  4084.                 if ($val->lstColSpan 1$cols $cols+$val->lstColSpan;
  4085.                 else $cols++;
  4086.                 /* </pk-05-03-17> */
  4087.             }
  4088.         }
  4089.         if (is_array($links)) $cols $cols sizeof($links);
  4090.  
  4091.         if ($this->lstShowRowNr$cols++// pk-05-07-05
  4092.         return $cols;
  4093.     }
  4094.  
  4095.     /**
  4096.       * returns the link url for a row
  4097.       *
  4098.       * $link is array with keys:
  4099.       * - URL           template of the url
  4100.       * - CHECKFLDS     array of rows => values which have to fit to link
  4101.       *
  4102.       * @param array $link 
  4103.       * @param array $row 
  4104.       * @param int $rowNr 
  4105.       * @param boolean $debug 
  4106.       *
  4107.       * @returns string
  4108.       *
  4109.       * @version pk-06-01-09
  4110.       *
  4111.       ***/
  4112.     function p_getListRowLink($link,$row,$rowNr,$debug=FALSE{
  4113.         if (debugechoDebug(__FILE__,"<p><b>DBMS_FORM::p_getListRowLink(...)</b> (".get_class($this).")</p>",1);
  4114.         $alink=NULL;
  4115.  
  4116.         if (is_array($link['CHECKFLDS'])) {
  4117.             $showLink=TRUE;
  4118.             if ($debug{echo "<pre>";print_r($row);echo "\n\n";print_r($val['CHECKFLDS']);echo "</pre>";}
  4119.             foreach($link['CHECKFLDS'as $checkKey => $checkVal{
  4120.                 if ($row[$checkKey]!=$checkVal{
  4121.                     $alink=NULL;
  4122.                 }
  4123.             }
  4124.         }
  4125.  
  4126.         $alink=$link['URL'];
  4127.  
  4128.         $linkParams="ROWNR=".$rowNr;
  4129.         foreach($this->frmFields as $fkey =>$fObj{
  4130.             if ($fObj->dbDesc['PRIMARY_KEY']{
  4131.                 $linkParams.="&".$fObj->myName."=".$row[$fObj->myName];
  4132.             }
  4133.         }
  4134.  
  4135.         require_once __OCSP_PHPINCPATH__."pcf_templates.phpinc";
  4136.  
  4137.         if (stristr($link['URL'],"javascript")) {
  4138.             $alink=str_replace("\$*ROWNR\$",$rowNr,$alink);
  4139.             return pcf_tmpl_parse($alink,$row);
  4140.         else {
  4141.             $alink.=$linkParams;
  4142.             return pcf_HTML_getEncodedURI(pcf_tmpl_parse($alink,$row),TRUE);
  4143.         }
  4144.  
  4145.     }
  4146.  
  4147.     /**
  4148.       * echos a html table row <tr> ... </tr> for a row
  4149.       *
  4150.       * NOTE:   sets the global $FORMS_LISTROW
  4151.       *         only use this global var in function called within
  4152.       *         this function it is used in field objects
  4153.       *         to access values of other fields with global ${$arrName}
  4154.       *
  4155.       * link array creates a <a ></a> HTML code with
  4156.       * the folowing attributes (if array links[attrib] ! empty)
  4157.       *
  4158.       * - TARGET    target=".."
  4159.       * - ACLASS    class=".."
  4160.       * - ASTYLE    style=".."
  4161.       * - ATAGADD   additional tags added as is
  4162.       * - URL       used in p_getListRowLink {@link DBMS_FORM::p_getListRowLink}
  4163.       * - CHECKFLDS used in p_getListRowLink {@link DBMS_FORM::p_getListRowLink}
  4164.       * - IMG       a button img (tag or only source) both are handeled
  4165.       *             <code>
  4166.       *                 if (stristr($val['IMG'],"src=")) {
  4167.       *                     echo "<img ".$val['IMG'].">";   // new style by gaisi
  4168.       *                  } else {
  4169.       *                      echo "<img src=\"".$val['IMG']."\" alt=\"".$val['TEXT']."\" border=\"0\">";
  4170.       *                  }
  4171.       *             </code>
  4172.       * - TEXT      text to show if no IMG or alt of the image
  4173.       *
  4174.       *
  4175.       * if $links['EDIT'] isset each data colum is link to the url
  4176.       *
  4177.       * @param array    $row    array of row falues wiht col names as index
  4178.       * @param int      $rowNr  Counter for the row (added to links)
  4179.       * @param array    $links  array of link arrays to add in the button
  4180.       * @param array    $fields $this->getFieldArr(TRUE) to not call the function for every row
  4181.       * @param string   $trTag  HTML-Code to append in <tr ...> tag
  4182.       * @param array    $tdDesc array with tag options in <td ...> tag
  4183.       * @param boolean     $debug  show debug info
  4184.       *
  4185.       * @globals array  $FORMS_LISTROW is set at the beginning and unset at the end
  4186.       *
  4187.       * @version pk-03-12-12
  4188.       * @version pk-05-07-05 $this->lstShowRowNr
  4189.       * @version pk-05-07-08 $val->lstTDAdd added
  4190.       *
  4191.       * @deprecated since pk-07-01-10
  4192.       *
  4193.       ***/
  4194.     function writeListRow($row,$rowNr,$links,$fields=NULL,$trTag="",$tdDesc="",$debug=FALSE{
  4195.         global $FORMS_LISTROW;
  4196.  
  4197.         if (!isset($tdDesc[$val->myName]['COLTAG'])) $tdDesc[$val->myName]['COLTAG']="";
  4198.         $FORMS_LISTROW=$row;
  4199.         echo "<tr $trTag>\n";
  4200.         if (!$fields$fields=$this->getFieldArr(TRUE);
  4201.  
  4202.         $fldLink="";
  4203.  
  4204.         require_once $GLOBALS['PHPINCPATH']."common/pcf_templates.phpinc";
  4205.  
  4206.         // <pk-04-09-02>
  4207.         if ((!empty($links['EDIT']['URL'])) || (!empty($links['EDIT']['URLTMPL'])))  {
  4208.             if (!empty($links['EDIT']['URLTMPL'])) {
  4209.                 $alink=pcf_tmpl_parse($links['EDIT']['URLTMPL'],$row,$debug);
  4210.             else {
  4211.                 $alink=$this->p_getListRowLink($links['EDIT'],$row,$rowNr,$debug);
  4212.             }
  4213.             // </ pk-04-09-02>
  4214.             $colLink_start="<a href=\"".$alink."\"";
  4215.             if (!empty($links['EDIT']['TARGET']))  $colLink_start.= " target=\"".$links['EDIT']['TARGET']."\"";
  4216.             if (!empty($links['EDIT']['ACLASS']))  $colLink_start.= " class=\"".$links['EDIT']['ACLASS']."\"";
  4217.             if (!empty($links['EDIT']['ASTYLE']))  $colLink_start.= " style=\"".$links['EDIT']['ASTYLE']."\"";
  4218.             if (!empty($links['EDIT']['ATAGADD']))
  4219.                 $colLink_start.= " ".pcf_tmpl_parse($links['EDIT']['ATAGADD'],$row,$debug)// <pk-04-09-02 />
  4220.             $colLink_start.=">";
  4221.             $colLink_end="</a>";
  4222.         }
  4223.  
  4224.         if ($this->lstShowRowNrecho "<td align=\"right\">".($rowNr+1)."</td>\n"// <pk-05-07-05 />
  4225.  
  4226.  
  4227.         reset($fields);
  4228.         while(list($key,$val)=each($fields)) {
  4229.             if ($val->isToShow(FRM_MODE_LIST,NULL,$debug)) {
  4230.                 // pk-03-10-17
  4231.                 $fldLinkEnd="";
  4232.                 //echo "\t<td>".$row[$val->myName]."</td>\n";
  4233.                 echo "\t<td ".$tdDesc[$val->myName]['COLTAG'];
  4234.                 if ($val->lstColSpan 1echo " colspan=\"".$val->lstColSpan."\" ";
  4235.                 echo pcf_tmpl_parse($val->lstTDAdd,$row,$debug)// <pk-05-07-08 />
  4236.                 echo ">".$tdDesc[$val->myName]['PREPAND'];
  4237.                 // <pk-06-10-20>
  4238.                 $fldLinkStart=$val->getListLink($row[$val->myName],"FORMS_LISTROW");
  4239.                 if ($fldLinkStart=="[EDIT]"// <pk-06-10-20>
  4240.                     echo $colLink_start;
  4241.                     $fldLinkEnd $colLink_end;
  4242.                 else if (!empty($fldLinkStart)) {
  4243.                     echo $fldLinkStart;
  4244.                     if (stristr($fldLinkStart,"<a"&& !(stristr($fldLinkStart,"</a>"))) {
  4245.                         $fldLinkEnd="</a>";
  4246.                     else {
  4247.                         $fldLinkEnd="";
  4248.                     }
  4249.                 else {
  4250.                     $fldLinkEnd="";
  4251.                 }
  4252.  
  4253.                 $val->writeField(FRM_MODE_LIST,$row[$val->myName],"FORMS_LISTROW");
  4254.                 echo $fldLinkEnd;
  4255.                 // /pk-03-10-17
  4256.                 echo $tdDesc[$val->myName]['APPAND']."</td>\n";
  4257.             }
  4258.         }
  4259.  
  4260.         echo $this->FRMLST_ADDBEFORELINKS;
  4261.         if (is_array($links)) {
  4262.             reset($links);
  4263.             if ($debug{echo "<!--\n";print_r($links);echo "\n-->\n";}
  4264.             while(list($key,$val)=each($links)) {
  4265.  
  4266.                 echo "<td";
  4267.                 if (!empty($val['WIDTH'])) echo " width=\"".$val['WIDTH']."\"";
  4268.                 if (!empty($val['CLASS'])) echo " class=\"".$val['CLASS']."\"";
  4269.                 if (!empty($val['STYLE'])) echo " style=\"".$val['STYLE']."\"";
  4270.  
  4271.                 $alink=NULL;
  4272.                 if (!empty($val['URLTMPL'])) {
  4273.                     $alink=pcf_tmpl_parse($val['URLTMPL'],$row,$debug);
  4274.                 else {
  4275.                     $alink=$this->p_getListRowLink($val,$row,$rowNr,$debug);
  4276.                 }
  4277.  
  4278.                 if ($alink{
  4279.                     echo "><a href=\"".$alink."\"";
  4280.                     if (!empty($val['TARGET']))     echo " target=\"".$val['TARGET']."\"";
  4281.                     if (!empty($val['ACLASS']))     echo " class=\"".$val['ACLASS']."\"";
  4282.                     if (!empty($val['ASTYLE']))     echo " style=\"".$val['ASTYLE']."\"";
  4283.                     if (!empty($val['ATAGADD']))    echo " ".pcf_tmpl_parse($val['ATAGADD'],$row,$debug);
  4284.                     echo ">";
  4285.  
  4286.                     if ($debug{echo "<!--\n";print_r($val);echo "\n-->\n";}
  4287.                     if (!empty($val['IMG'])) {
  4288.                         if (stristr($val['IMG'],"src=")) {
  4289.                             echo "<img ".$val['IMG'].">";   // new style by gaisi
  4290.                         else {
  4291.                             echo "<img src=\"".$val['IMG']."\" alt=\"".$val['TEXT']."\" border=\"0\">";
  4292.                         }
  4293.                     else {
  4294.                         echo $val['TEXT'];
  4295.                     }
  4296.                     echo "</a>";
  4297.                 else {
  4298.                     echo "&nbsp;";
  4299.                 }
  4300.                 echo "</td>\n";
  4301.             }
  4302.         }
  4303.         echo $this->FRMLST_ROWADD;
  4304.         echo "</tr>\n";
  4305.         unset($FORMS_LISTROW);
  4306.     }
  4307.  
  4308.     /**
  4309.       * returns an object value for a row
  4310.       *
  4311.       *
  4312.       * @param DBMS_FIELD $fldObj 
  4313.       * @param array $row 
  4314.       * @param boolean $debug 
  4315.       * 
  4316.       * @global $OCSP_OBJ 
  4317.       *
  4318.       * @returns mixed
  4319.       *
  4320.       * @since pk-05-10-06
  4321.       *
  4322.       */
  4323.     function getRowObjValue(&$fldObj,$row,$debug=FALSE
  4324.     {
  4325.         global $OCSP_OBJ;
  4326.         
  4327.         if ($debugecho "<p><b>DBMS_FORM::getRowObjValue(...)</b> (".get_class($this).")</p>\n";
  4328.         $s_table=str_replace("OBJVALS_","",$fldObj->getTable());
  4329.  
  4330.         $s_keyFld="";
  4331.         if (is_array($this->frmKeys))
  4332.         {
  4333.             reset($this->frmKeys);
  4334.             while(empty($s_keyFld&& (list($i_idx,$a_keyData)=each($this->frmKeys))) {
  4335.                 if ($a_keyData['TABLE']==$s_table{
  4336.                     $s_keyFld=$a_keyData['NAME'];
  4337.                 }
  4338.             }
  4339.         }
  4340.  
  4341.         $s_query="SELECT OV_VALUE FROM ".$s_table."_OV WHERE ".$s_keyFld."=".$OCSP_OBJ['USRDB']->qs_getSlashedValue($row[$s_keyFld]);
  4342.         $s_query.=" AND OV_NAME=".$OCSP_OBJ['USRDB']->qs_getSlashedValue($fldObj->getName());
  4343.  
  4344.         if ($debugecho "<p>Query$s_query</p>";
  4345.         if ($s_ret=$OCSP_OBJ['USRDB']->quickQuery($s_query,0)) {
  4346.             if ($debugecho "<p>FOUND</p>";
  4347.             return $s_ret;
  4348.         else {
  4349.             if ($debugecho "<p>NOT FOUND</p>";
  4350.             return NULL;
  4351.         }
  4352.     }
  4353.  
  4354.  
  4355.  
  4356.     /**
  4357.       * returns the htmlCode for a list row
  4358.       *
  4359.       * layout class var used:
  4360.       *
  4361.       * - FRMLST_TRADD (<tr $this->FRMLST_TRADD[($rowNr % 2)] >)
  4362.       * - FRMLST_TDADD (<td $this->FRMLST_TDADD >)
  4363.       * - FRMLST_TDFLDADD (<td $this->FRMLST_TDADD $this->FRMLST_TDFLDADD[FLDNAME] >)
  4364.       *
  4365.       * links array creates links at the end of the row
  4366.       * $links[colname|linkname]
  4367.       *     -[A]            => link templdate parsed with $row
  4368.       *     -[TEXT]         => the html code for the link button
  4369.       *     -[SHOWQUERY]    => if str_replace(";","%","SELECT ".pcf_tmpl_parse($lArr['SHOWQUERY'],$row)) is TRUE the link is show otherwise not
  4370.       *     -[GROUPID]      => overrules [SHOWQUERY]
  4371.       *
  4372.       * if $links['EDIT'] isset each data colum is link to the url
  4373.       * if the link key == fldname the link is added to the field
  4374.       *
  4375.       *
  4376.       * @param array $row 
  4377.       * @param int $rowNr 
  4378.       * @param array $links 
  4379.       * @param boolean $debug 
  4380.       *
  4381.       * @returns string
  4382.       *
  4383.       * @since pk-04-12-30
  4384.       *
  4385.       * @version pk-05-04-13 anchor added
  4386.       * @version pk-05-07-05 $this->lstShowRowNr
  4387.       * @version pk-05-07-08
  4388.       * @version pk-05-10-06 object values added
  4389.       * @version pk-05-11-15 button cols width 20 added
  4390.       * @version pk-06-03-02 [GROUPID] added
  4391.       * @version pk-06-09-08 $rowNr call by reference
  4392.       * @version pk-06-10-20 linking of the column
  4393.       *
  4394.       * @todo check edit link && check column links
  4395.       *
  4396.       */
  4397.     function getListRow($row,&$rowNr,$links=NULL,$debug=FALSE{
  4398.         if ($debug{
  4399.             echo "<p><b>DBMS_FORM::getListRow(...)</b> (".get_class($this).")</p><blockquote>";
  4400.             echo "<p style=\"font-weight: 75%\">VALUES:</p><pre style=\"font-weight: 75%\">".print_r($row,TRUE)."</pre>";
  4401.         }
  4402.  
  4403.         if (!is_array($row)) {
  4404.             if ($debugecho "<p>ERROR \$row is not an array</p></blockquote>";
  4405.             return "";
  4406.         }
  4407.  
  4408.         if (!is_array($links)) $links=array()// to avoid errors
  4409.  
  4410.         $arrName $this->getName()."_FRMLSTROW";
  4411.         global ${$arrName};
  4412.         ${$arrName}=$row;
  4413.  
  4414.         require_once __OCSP_PHPINCPATH__ ."common/pcf_templates.phpinc";
  4415.         $i_odEven=($rowNr 2);
  4416.         $s_ret="\n\t<tr ".(isset($this->FRMLST_TRADD[$i_odEven]pcf_tmpl_parse($this->FRMLST_TRADD[($rowNr 2)],$row"").">\n";
  4417.         $fields=$this->getFieldArr(TRUE);
  4418.  
  4419.         require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  4420.         if (!empty($links['EDIT']['A'])) $editLink="<a ".pcf_tmpl_parse($links['EDIT']['A'],$row)." >";
  4421.  
  4422.  
  4423.         if ($this->lstShowRowNr$s_ret.="\t\t<td ".$this->FRMLST_TDADD." align=\"right\">".($rowNr+1)."</td>\n"// <pk-05-07-05 />
  4424.  
  4425.         $anchorSet=FALSE;$anchor="";            /* <pk-05-04-13 /> */
  4426.  
  4427.         foreach($fields as $key => &$fldObj{
  4428.             if ($debugecho "<pre>FIELD: ".$fldObj->getName()."\nVALUE:".htmlspecialchars($row[$fldObj->myName])."\n";
  4429.             $fldObj->setDataArrName($arrName)// <pk-06-08-18 /> use method instead of direct object access
  4430.  
  4431.             $arr_fldDesc=$fldObj->getdbDesc();
  4432.             $arr_fldLink=$fldObj->getListLinkArr();
  4433.             
  4434.             if (isset($arr_fldDesc['AUTO_INCREMENT']&& ($arr_fldDesc['AUTO_INCREMENT']&& isset($row[$fldObj->getName()])) // <pk-05-04-13 /> <pk-06-07-24 /><pk-07-01-10 /> E_ALL
  4435.                 $anchor="<a name=\"".$fldObj->getName()."_".$row[$fldObj->getName()]."\"></a>";
  4436.             }
  4437.  
  4438.             if ($fldObj->isToShow(FRM_MODE_LIST,NULL,$debug)) // <pk-07-01-10 />
  4439.                 if ((intval($fldObj->getLstColSpan()))) // <pk-06-09-12>
  4440.                     $s_ret.="\t\t<!-- ____________".$fldObj->getName()."__________ -->\n";
  4441.                     $s_ret.="\t\t<td ".$this->FRMLST_TDADD." ".(isset($this->FRMLST_TDFLDADD[$fldObj->getName()]$this->FRMLST_TDFLDADD[$fldObj->getName()"");
  4442.                     if ($fldObj->getLstColSpan(1$s_ret.=" colspan=\"".$fldObj->getLstColSpan()."\" ";
  4443.                     $s_ret.= " ".pcf_tmpl_parse($fldObj->get_lstTDAdd(),$row)// <pk-05-07-08 />
  4444.                     $s_ret.=">\n";
  4445.  
  4446.                     if ((!$anchorSet&& (!empty($anchor))) /* <pk-05-04-13 /> */
  4447.                         $s_ret.=$anchor."\n";
  4448.                         $anchorSet=TRUE;
  4449.                     }
  4450.                     $s_ret.="\t";
  4451.  
  4452.                     $b_linked=FALSE// <pk-06-11-07 />
  4453.                     // <pk-06-10-20>
  4454.                     if (isset($links[$fldObj->getName()]['A']&& !empty($links[$fldObj->getName()]['A'])) {
  4455.                         // link set from outside alway rules hope developers know what they are doing
  4456.                         $s_ret.="<a ".pcf_tmpl_parse($links[$fldObj->getName()]['A'],$row)." >";
  4457.                         $b_linked=TRUE;
  4458.                     else if (isset($row[$fldObj->getName()])) // <pk-07-02-08 /> E_ALL
  4459.                         $s_fldLnk=$fldObj->getListLink($row[$fldObj->getName()],$arrName);
  4460.                         if ($s_fldLnk=="[EDIT]"{
  4461.                             // use the edit link if is set
  4462.                             if (!empty($links['EDIT']['A'])) {
  4463.                                 $s_ret.="<a ".pcf_tmpl_parse($links['EDIT']['A'],$row)." >";
  4464.                                 $b_linked=TRUE;
  4465.                             }
  4466.                         else if (!empty($s_fldLnk)) {
  4467.                             $s_ret.=$s_fldLnk;
  4468.                             $b_linked=((!stristr($s_fldLnk,"</a>")) TRUE FALSE);                            
  4469.                             if (!empty($arr_fldLink['TEXT'])) {
  4470.                                 $links[$fldObj->getName()]=$arr_fldLink;
  4471.                             }
  4472.                         }
  4473.                     }
  4474.  
  4475.                     if (!isset($row[$fldObj->getName()])) {
  4476.                         if (substr($fldObj->getTable(),0,8)=="OBJVALS_"{
  4477.                             $row[$fldObj->getName()]=$this->getRowObjValue($fldObj,$row,$debug);
  4478.                         }
  4479.                     }
  4480.                     // </pk-05-10-06>
  4481.                     if (!isset($row[$fldObj->getName()])) $row[$fldObj->getName()]=NULL;
  4482.                     $s_ret.=$fldObj->getFieldTag(FRM_MODE_LIST,$row[$fldObj->getName()],$debug);
  4483.                     if ($b_linked$s_ret.="</a>";
  4484.                     $s_ret.="</td>\n";
  4485.                 else if (!empty($arr_fldLink['TEXT'])) {
  4486.                     $links[$fldObj->getName()]=$arr_fldLink// <pk-06-09-12 /> to ensure it is in the button list
  4487.                 }
  4488.             else if ($debug{
  4489.                 echo "isHidden: ".$fldObj->isHidden(FRM_MODE_LIST)."\n";
  4490.                 echo "showInList: ".$fldObj->showInList()."\n";
  4491.             }
  4492.             if ($debugecho "</pre>";
  4493.         }
  4494.  
  4495.         $s_ret.=$this->FRMLST_ADDBEFORELINKS;
  4496.         foreach($links as $name => $lArr{
  4497.             $s_ret.="\n\t\t<!-- ____ LINKS________ -->\n";
  4498.             $b_showLink=FALSE;
  4499.             if (!empty($lArr['TEXT'])) {
  4500.                 $s_ret.="\t\t<td ".$this->FRMLST_TDADD." width=\"20\" align=\"center\">"// <pk-05-11-15 />
  4501.                 if (!empty($lArr['SHOWQUERY'])) // <pk-05-11-07>
  4502.                     // todo security check
  4503.                     $s_showQuery=str_replace(";","%","SELECT ".pcf_tmpl_parse($lArr['SHOWQUERY'],$row));
  4504.                     $b_showLink=(intval($GLOBALS['USRDB']->quickQuery($s_showQuery,0)) TRUE FALSE);
  4505.                 else {
  4506.                     $b_showLink=TRUE;
  4507.                 }
  4508.  
  4509.                 if (isset($lArr['GROUPID']&& (intval($lArr['GROUPID']))) // <pk-06-03-02>
  4510.                     $b_showLink=($b_showLink && ($GLOBALS['USER']->isGroupMember(intval($lArr['GROUPID']))));
  4511.                 }
  4512.  
  4513.                 if ($b_showLink &&  (isset($lArr['A']))) // <pk-06-07-28 /> E_ALL
  4514.                     $s_ret.="<a ".pcf_tmpl_parse($lArr['A'],$row)." >";
  4515.                     $s_ret.=pcf_tmpl_parse($lArr['TEXT'],$row);
  4516.                     $s_ret.="</a>";
  4517.                 else {
  4518.                     $s_ret.="&nbsp;";
  4519.                 }
  4520.  
  4521.                 $s_ret.="</td>\n";
  4522.             }
  4523.             $s_ret.="\n\t\t<!-- ____ END LINKS ___ -->\n";
  4524.         }
  4525.  
  4526.         $s_ret.="\t\t".$this->FRMLST_ROWADD."\n";
  4527.         $s_ret.="\t</tr>";
  4528.  
  4529.         if ($debugecho "</blockquote>";
  4530.         $rowNr++;
  4531.         return $s_ret;
  4532.     }
  4533.  
  4534.     /**
  4535.       * returns the SQL-Fieldlist for Lists
  4536.       *
  4537.       * @param boolean $debug 
  4538.       *
  4539.       * @returns string
  4540.       *
  4541.       * @since pk-05-02-16
  4542.       * @version pk-05-02-22 add primary keys
  4543.       * @version pk-06-05-15 bugfix; debugging
  4544.       *
  4545.       ***/
  4546.     function getList_SQLFieldLst($debug=FALSE{
  4547.         $debug=($debug || $this->debugMode);
  4548.         if ($debugecho "<p><b>DBMS_FORM::getList_SQLFieldLst()</b> (".get_class($this).")</p>";
  4549.  
  4550.         $ret="";$sep="";
  4551.         $fields=$this->getFieldArr(TRUE);
  4552.         
  4553.         foreach($fields as &$fldObj{
  4554.             $arr_dbDesc=$fldObj->getdbDesc();
  4555.             if ($debugecho "<pre>".print_r($fldObj->dbDesc,TRUE)."</pre>";
  4556.             if ((!$fldObj->isHidden()) && ($fldObj->showInList())) {
  4557.                 if ($cName=$fldObj->getDBColName()) {
  4558.                     $ret.=$sep.$cName;
  4559.                     $sep=", ";
  4560.                 }
  4561.             else if ($arr_dbDesc['PRIMARY_KEY']/* <pk-05-02-22 >*/
  4562.                 if ($debugecho "<p>checking PRIMARY_KEY: ".$fldObj->getName()."</p>";
  4563.                 if (!strstr($ret,".".$fldObj->getName())) // <pk-06-05-15 bugfix />
  4564.                     if ($cName=$fldObj->getDBColName()) {
  4565.                         $ret.=$sep.$cName;
  4566.                         $sep=", ";
  4567.                     }
  4568.                 }
  4569.             /* </pk-05-02-22> */
  4570.         }
  4571.         if (empty($ret)) return "*";
  4572.         return $ret;
  4573.     }
  4574.  
  4575.     /**
  4576.       * echos the list header Row
  4577.       *
  4578.       * class = "lstHeader" is added to <a> html tag
  4579.       * $this->FRMLST_THADD is added to <th>
  4580.       *
  4581.       * @param int $noCols number of columns
  4582.       * @param array $links Linkicons to count colspan of the last row
  4583.       * @param string $sortLink links the col title
  4584.       * @param boolean $debug 
  4585.       *
  4586.       * @returns string
  4587.       *
  4588.       * @version pk-04-02-15
  4589.       * @version pk-05-03-16
  4590.       * @version pk-05-04-15 $fldObj->lstLink added
  4591.       * @version pk-05-07-05 $this->lstShowRowNr
  4592.       * @version pk-05-11-07 links SHOWQUERY added
  4593.       * @version pk-05-11-30 add ? or & to $sortLnk
  4594.       * @version pk-06-01-19 lstLabel added in fields
  4595.       * @version pk-06-02-23 check dbDesc['COLNAME'] in sortLink
  4596.       * @version pk-06-09-12 use $fldObj->lstColSpan
  4597.       * @version pk-07-01-10 use $fldObj->isToShow() instead of direct access
  4598.       *
  4599.       * @todo check query for SHOWQUERY
  4600.       ***/
  4601.     function getListHeaderRow(&$noCols,$links=NULL,$sortLnk="",$debug=FALSE{
  4602.         if ($debugecho "<p><b>DBMS_FORM::getListHeaderRow(...)</b> (".get_class($this).")</p><blockquote>";
  4603.  
  4604.         $fields=$this->getFieldArr(TRUE);
  4605.  
  4606.         $ret="\n\t<tr>\n";
  4607.  
  4608.         if ($this->lstShowRowNr$ret.="\t\t<th ".$this->FRMLST_THADD." align=\"center\">#</th>\n"// <pk-05-07-05 />
  4609.  
  4610.         // <pk-05-11-30>
  4611.         $sortLnk=trim($sortLnk);
  4612.         if (!empty($sortLnk)) {
  4613.             if ((substr($sortLnk,-1!= "?"&& (substr($sortLnk,-1!= "&")) {
  4614.                 if (!strstr($sortLnk,"?")) $sortLnk.="?"else $sortLnk.="&";
  4615.             }
  4616.         }
  4617.         // </pk-05-11-30>
  4618.  
  4619.         foreach($fields as $fldObj{
  4620.             if ($fldObj->isToShow(FRM_MODE_LIST,NULL,$debug)) // pk-07-01-10 />
  4621.                 if (intval($fldObj->getLstColSpan())) {// <pk-06-09-12 />
  4622.                     $ret.="\t\t<th ".$this->FRMLST_THADD.">"// pk-05-03-16
  4623.                     $arr_fldDesc=$fldObj->getdbDesc();
  4624.                     if ((!empty($sortLnk)) && (!empty($arr_fldDesc['COLNAME']))) // <pk-06-02-23>
  4625.                         $ret.= "<a class=\"lstHeader\" href=\"".$sortLnk."SORTCOL=".$arr_fldDesc['COLNAME']."\">";
  4626.                     }
  4627.                     $ret.= $fldObj->getLstLabel()// <pk-06-01-19 />
  4628.                     if ((!empty($sortLnk)) && (!empty($arr_fldDesc['COLNAME']))) {
  4629.                         $ret.= "</a>";
  4630.                     }
  4631.                     $ret.=  "</th>\n";
  4632.                     $noCols+=intval($fldObj->getLstColSpan())// <pk-06-09-12 />
  4633.                     /* <pk-05-04-15> */
  4634.                     if ($fldObj->getListLinkArr()) {
  4635.                         if (!isset($links[$fldObj->getName()])) {
  4636.                             $links[$fldObj->getName()]=$fldObj->getListLinkArr();
  4637.                         }
  4638.                     }
  4639.                     /* </pk-05-04-15> */
  4640.                 else if ($fldObj->getListLinkArr()) {
  4641.                     if (!isset($links[$fldObj->getName()])) {
  4642.                         $links[$fldObj->getName()]=$fldObj->getListLinkArr();
  4643.                     }
  4644.                 }
  4645.             }
  4646.         }
  4647.         if (is_array($links&& (sizeof($links))) {
  4648.             $ret.="\t\t<th ".$this->FRMLST_THADD." colspan=\"".sizeof($links)."\" width=\"".(sizeof($links)*20)."\">";
  4649.             if ($GLOBALS['USER']->isAdmin()) {
  4650.                 $ret.="<a href=\"".$GLOBALS['PROJECT']['ADMINURL']."dbms/editframe.php?FRM_ID=".$this->getId()."\" target=\"_blank\" title=\"Formular bearbeiten\">";
  4651.                 $ret.="<img src=\"".$GLOBALS['PROJECT']['SYSIMGURL']."/icons-22x22/editConstruct.gif\" border=\"0\" alt=\"Formular bearbeiten\" class=\"button\"></a>\n";
  4652.             }
  4653.             $ret.="</th>\n"//<pk-05-11-15 /> <pk-06-05-17 />
  4654.             $noCols=$noCols+sizeof($links);
  4655.         }
  4656.  
  4657.         $ret.=  "\t</tr>\n";
  4658.         if ($debugecho "</blockquote>";
  4659.         return $ret;
  4660.     }
  4661.  
  4662.  
  4663.     /**
  4664.       * returns an array with key=column name and value = label of the form
  4665.       *
  4666.       * @param boolean $debug 
  4667.       *
  4668.       * @returns array
  4669.       *
  4670.       * @since pk-05-07-06
  4671.       *
  4672.       ***/
  4673.     function getListColLabelArr($debug=FALSE{
  4674.         // @var array $a_ret
  4675.         $a_ret=array();
  4676.         // @var array $a_fields
  4677.         $a_fields=$this->getFieldArr(TRUE);
  4678.         // @var DBMS_FIELD $o_fld
  4679.         $o_fld=NULL;
  4680.  
  4681.         if ($debugecho "<p><b>DBMS_FORM::getListColLabelArr()</b></p>";
  4682.  
  4683.         foreach($a_fields as $o_fld{
  4684.             if ((!$o_fld->isHidden&& ($o_fld->showInList)) {
  4685.                 $a_ret[$o_fld->getName()]=$o_fld->label;
  4686.             }
  4687.         }
  4688.  
  4689.         return $a_ret;
  4690.     }
  4691.  
  4692.  
  4693.     /**
  4694.       * returns the html code for list from a database cursor object
  4695.       *
  4696.       * $cursor->fetchArrayFld() is called to get the row
  4697.       *
  4698.       * NOTE: use getList_SQLFieldLst() in the select statement if
  4699.       *       you have a LEFT JOIN to get the right fields and
  4700.       *       values
  4701.       *
  4702.       * layout class var used:
  4703.       *
  4704.       * - FRMLST_TABLEADD (<table $this$this->FRMLST_TABLEADD>)
  4705.       * - FRMLST_TRADD (<tr $this->FRMLST_TRADD[($rowNr % 2)] >)
  4706.       * - FRMLST_TDADD (<td $this->FRMLST_TDADD >)
  4707.       *
  4708.       *
  4709.       * @param DBCURSOR $cursor 
  4710.       * @param int $nofRows 
  4711.       * @param array $links 
  4712.       * @param string $sortLnk 
  4713.       * @param boolean $debug 
  4714.       *
  4715.       * @returns string
  4716.       *
  4717.       * @since pk-04-12-31
  4718.       *
  4719.       ***/
  4720.     function getHTMLLstFromCursor($cursor,&$nofRows,$links=NULL,$sortLnk=NULL,$debug=FALSE{
  4721.         if ($debugecho "<p><b>DBMS_FORM::getHTMLLstFromCursor(...)</b> (".get_class($this).")</p><blockquote>";
  4722.  
  4723.         if (!is_object($cursor)) {
  4724.             if ($debugecho "<p>\$cursor IS NO OBJECT</p></blockquote>";
  4725.             return NULL;
  4726.         }
  4727.  
  4728.         $ret="\n<!-- ______ LISTTable ".$this->getName()." ________________ -->";
  4729.         $ret.="<table ".$this->FRMLST_TABLEADD.">";
  4730.         $nofCols=0;
  4731.         $ret.=$this->getListHeaderRow($nofCols,$links,$sortLnk,$debug);
  4732.  
  4733.         while ($row=$cursor->fetchArrayFld()) {
  4734.             $ret.=$this->getListRow($row,$nofRows,$links,$debug);
  4735.         }
  4736.  
  4737.         $ret.="</table>";
  4738.         $ret.="\n<!-- ______ END LISTTable ".$this->getName()." ____________ -->";
  4739.         if ($debugecho "</blockquote><p>END getHTMLLstFromCursor(...)</p>";
  4740.         return $ret;
  4741.     }
  4742.  
  4743.     /**
  4744.       * returns the html code for list from a query
  4745.       *
  4746.       * if $query is empty it is generated with:
  4747.       * <code>
  4748.       *     $query="SELECT ".$this->getList_SQLFieldLst().$this->getFromStmt();
  4749.       * </code>
  4750.       *
  4751.       * NOTE: use getList_SQLFieldLst() in the select statement if
  4752.       *       you have a LEFT JOIN to get the right fields and
  4753.       *       values
  4754.       *
  4755.       * layout class var used:
  4756.       *
  4757.       * - FRMLST_TABLEADD (<table $this->FRMLST_TABLEADD>)
  4758.       * - FRMLST_TRADD (<tr $this->FRMLST_TRADD[($rowNr % 2)] >)
  4759.       * - FRMLST_TDADD (<td $this->FRMLST_TDADD >)
  4760.       *
  4761.       *
  4762.       * @param int $nofRows return the number of rows processed
  4763.       * @param string $query if empty the query is generated
  4764.       * @param array $links 
  4765.       * @param string $sortLnk 
  4766.       * @param int $limit 
  4767.       * @param int $offset 
  4768.       * @param boolean $debug 
  4769.       *
  4770.       * @global array $OCSP_OBJ 
  4771.       * 
  4772.       * @returns string
  4773.       *
  4774.       * @since pk-04-12-31
  4775.       * @version pk-06-01-24
  4776.       *
  4777.       * @todo only mysqlcode for limit
  4778.       *
  4779.       ***/
  4780.     function getHTMLLstFromQuery(&$nofRows,$query="",$links=NULL,$sortLnk=NULL,$limit=0,$offset=0,$debug=FALSE{
  4781.         global $OCSP_OBJ;
  4782.         
  4783.         if ($debugecho "<p><b>DBMS_FORM::getHTMLLstFromQuery(...)</b> (".get_class($this).")</p><blockquote>";
  4784.        
  4785.  
  4786.         if (empty($query)) $query="SELECT ".$this->getList_SQLFieldLst().$this->getFromStmt();
  4787.         if ((intval($limit)) && (!strstr($query,"LIMIT"))) {
  4788.             $query.=" LIMIT ".intval($offset).",".$limit;
  4789.         }
  4790.         if ($debugecho "<p>Query$query</p>";
  4791.         if ($cursor=$OCSP_OBJ['USRDB']->query($query)) {
  4792.             $ret=$this->getHTMLLstFromCursor($cursor,$nofRows,$links,$sortLnk,$debug)// <pk-06-01-24 /> bugfix sortLink
  4793.             $cursor->free();
  4794.         else {
  4795.             if ($debugecho "<p>ERROR could not query </p>";
  4796.             $nofRows=0;
  4797.         }
  4798.         if ($debugecho "</blockquote>";
  4799.         return $ret;
  4800.     }
  4801.  
  4802.  
  4803.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4804.     // data export methods
  4805.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  4806.  
  4807.     /**
  4808.       * returns the csv header line (column names)
  4809.       *
  4810.       * @param array $row 
  4811.       * @param char $fldSep field seperator
  4812.       * @param char $txtSep string seperator
  4813.       * @param boolean $allFields check exportCSV is set in the field
  4814.       * @param boolean $debug 
  4815.       *
  4816.       ***/
  4817.     function getCSVHeadLine($row=NULL,$fldSep=';',$txtSep='"',$allFields=FALSE,$debug=FALSE{
  4818.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::getCSVLine()");
  4819.         $fields=$this->getFieldArr(TRUE);
  4820.  
  4821.         $s_ret="";
  4822.         foreach($fields as $s_key => &$fldObj{
  4823.             if ($allFields || $fldObj->exportCSV()) {
  4824.                 if (isset($row[$fldObj->getName()])) {
  4825.                     $s_ret.=$txtSep.$fldObj->getName().$txtSep;
  4826.                 }
  4827.                 $s_ret.=$fldSep;
  4828.             }
  4829.         }
  4830.         $s_ret.="\r\n";
  4831.         return $s_ret;
  4832.     }
  4833.  
  4834.  
  4835.     /**
  4836.       * returns a csv line
  4837.       *
  4838.       * @param array $row 
  4839.       * @param char $fldSep field seperator
  4840.       * @param char $txtSep string seperator
  4841.       * @param boolean $allFields check exportCSV is set in the field
  4842.       * @param boolean $debug 
  4843.       *
  4844.       ***/
  4845.     function getCSVLine($row,$fldSep=';',$txtSep='"',$allFields=FALSE,$debug=FALSE{
  4846.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FORM::getCSVLine()");
  4847.  
  4848.         $arrName $this->getName()."_CSVLSTROW";
  4849.         global ${$arrName};
  4850.         ${$arrName}=$row;
  4851.  
  4852.         $fields=$this->getFieldArr(TRUE);
  4853.  
  4854.         $s_ret="";
  4855.         foreach($fields as $s_key => &$fldObj{
  4856.             if ($allFields || $fldObj->exportCSV()) {
  4857.                 if (isset($row[$fldObj->getName()])) {
  4858.                     $s_ret.=$fldObj->getCSV_Value($row[$fldObj->getName()],$arrName,$txtSep,$debug);
  4859.                 }
  4860.                 $s_ret.=$fldSep;
  4861.             }
  4862.         }
  4863.         $s_ret.="\r\n";
  4864.         return $s_ret;
  4865.     }
  4866.  
  4867.     // ################################
  4868.  
  4869.     /**
  4870.       * echos a searchForm
  4871.       *
  4872.       * @param string $arrName 
  4873.       * @param string $trTag 
  4874.       * @param boolean $debug 
  4875.       *
  4876.       * @version pk-04-11-10
  4877.       *
  4878.       ***/
  4879.     function writeSearchForm($arrName="DBSEARCH",$trTag="",$debug=FALSE{
  4880.          $fields=$this->getFieldArr(TRUE);
  4881.          reset($fields);
  4882.          while(list($key,$fld)=each($fields)) {
  4883.             if (!$fld->isHidden && $fld->isSearchable{
  4884.                 echo "\n<tr ".$trTag.">";
  4885.                 $fld->writeLabelCol();
  4886.                 $fld->writeInputCol(FRM_MODE_SEARCH,"",$arrName);
  4887.                 echo "</tr>";
  4888.             }
  4889.          }
  4890.     }
  4891.  
  4892.     /**
  4893.       * generates a where statement for search
  4894.       *
  4895.       * @param array $postArr 
  4896.       * @param boolean $debug 
  4897.       * @param boolean $alwaysRetWhere if true return WHERE 1=1 if no values found
  4898.       *
  4899.       * @returns string
  4900.       *
  4901.       * @version pk-05-08-11
  4902.       * @version pk-06-01-25 $alwaysRetWhere added
  4903.       * @version pk-07-01-09 skip filds with no db
  4904.       *
  4905.       * @var string $s_where 
  4906.       * @var array $a_fields 
  4907.       * @var string $s_key 
  4908.       * @var DBMS_FIELD $o_fld 
  4909.       *
  4910.       ***/
  4911.     function getSearchWhere($postArr,$debug=FALSE,$alwaysRetWhere=TRUE{
  4912.         if ($debugechoDebug(__FILE__,"<p><b>DBMS_FORM::getSearchWhere(...)</b> (".get_class($this)."</p>",0);
  4913.         if (!is_array($postArr)) return "";
  4914.  
  4915.         $s_where="WHERE 1=1";
  4916.         $a_fields=$this->getFieldArr();
  4917.  
  4918.         if ($debugecho "<blockquote>";
  4919.         foreach($a_fields as $s_key => &$o_fld{
  4920.             if (isset($postArr[$o_fld->getName()]['VALUE']&& (!$o_fld->isHidden()) && ($o_fld->isSearchable()) && ($o_fld->getTable(!= DBMS_NO_DBFIELD)) {
  4921.                 if ($debugecho "<p>Checking Field: <b>".$o_fld->getName()."</b> Value: ".$postArr[$o_fld->getName()]['VALUE']."</p>";
  4922.                 if (!empty($postArr[$o_fld->getName()]['VALUE']|| ($postArr[$o_fld->getName()]['VALUE']==="0")) // <pk-06-02-13 /> do not ignore "0" as value
  4923.                     if ($debugecho "<blockquote>";
  4924.  
  4925.                     $s_where.=" ".$o_fld->searchWhere($postArr[$o_fld->myName],$debug);
  4926.                     if ($debugecho "</blockquote>";
  4927.                 }
  4928.             }
  4929.         }
  4930.         if ($debugecho "</blockquote>";
  4931.         if ((!$alwaysRetWhere&& ($s_where=="WHERE 1=1")) return NULL// <pk-06-01-24>
  4932.         return $s_where;
  4933.     }
  4934.  
  4935.     /**
  4936.       * exports the form to an xml file
  4937.       *
  4938.       * @param string $xmlfile 
  4939.       * @param boolean $base64 
  4940.       * @param boolean $debug 
  4941.       * @param boolean $echoXML 
  4942.       *
  4943.       * @returns bool;
  4944.       *
  4945.       ***/
  4946.     function xmlExport($xmlfile="",$base64=TRUE,$debug=FALSE,$echoXML=TRUE{
  4947.         $debug=($debug || $this->debugMode);
  4948.         if ($debugecho "<hr /><p><b>DBMS_FORM::xmlExport($xmlfile,$debug)</b></p><blockquote>";
  4949.         if (empty($xmlfile)) $xmlfile=$GLOBALS['PROJECT']['DBEXPORT'].$this->frmName.".xml";
  4950.  
  4951.         $domObj new domDocument();
  4952.  
  4953.         $domObj->appendChild($domObj->createElement("DBMSFORMLST"));
  4954.  
  4955.         $frmRoot $domObj->createElement("DBMSFORM");
  4956.         $domObj->documentElement->appendChild($frmRoot);
  4957.  
  4958.         $valRoot $domObj->createElement("FRM_VALUES");
  4959.         $frmRoot->appendChild($valRoot);
  4960.  
  4961.         $objArrs=array();
  4962.         $objObjs=array();
  4963.         foreach (get_object_vars($thisas $var=>$val{
  4964.             if (is_object($val)) {
  4965.                 $objObjs[$var]=$var;
  4966.             else if (is_array($val)) {
  4967.                 $objArrs[$var]=$var;
  4968.             else {
  4969.                 if ($base64)    $val=base64_encode($val);
  4970.                 else            $val=htmlspecialchars($val);
  4971.                 $domElem=$domObj->createElement($var,utf8_encode($val));
  4972.             }
  4973.             $valRoot->appendChild($domElem);
  4974.         }
  4975.  
  4976.         $arrRoot=$domObj->createElement("FRM_TABLE_LST");
  4977.         $frmRoot->appendChild($arrRoot);
  4978.         foreach ($this->frmTables as $tbl{
  4979.             $domElem $domObj->createElement("FRM_TABLE",utf8_encode($tbl));
  4980.             $arrRoot->appendChild($domElem);
  4981.         }
  4982.         unset ($objArrs['frmTables']);
  4983.  
  4984.         $arrRoot=$domObj->createElement("DBMS_FLD_LST");
  4985.         $frmRoot->appendChild($arrRoot);
  4986.         foreach ($this->frmFields as $key => $fld{
  4987.             $fldRoot $domObj->createElement("DBMS_FLD");
  4988.             $arrRoot->appendChild($fldRoot);
  4989.             $fldRoot->appendChild($domObj->createElement("FLD_IDXKEY",utf8_encode($key)));
  4990.             $fldRoot->appendChild($domObj->createElement("FLD_CLASS",utf8_encode(strtoupper(get_class($fld)))));
  4991.             $this->frmFields[$key]->xmladdDOMElement($domObj,$fldRoot,$base64,$debug);
  4992.         }
  4993.         unset($objArrs['frmFields']);
  4994.  
  4995.         $arrRoot=$domObj->createElement("FRM_KEY_LST");
  4996.         $frmRoot->appendChild($arrRoot);
  4997.         foreach ($this->frmKeys as $key{
  4998.             $keyElem $domObj->createElement("FRM_KEY");
  4999.             $arrRoot->appendChild($keyElem);
  5000.             $keyElem->appendChild($domObj->createElement("TABLE",utf8_encode($key['TABLE'])));
  5001.             $keyElem->appendChild($domObj->createElement("NAME",utf8_encode($key['NAME'])));
  5002.         }
  5003.         unset ($objArrs['frmKeys']);
  5004.  
  5005.         $serValRoot=$frmRoot->appendChild($domObj->createElement("FRM_SERVALUES"));
  5006.         foreach($objArrs as $key{
  5007.             $val=serialize($this->{$key});
  5008.             if ($base64)    $val=base64_encode($val);
  5009.             else            $val=htmlspecialchars($val);
  5010.             $serValRoot->appendChild($domObj->createElement($key,utf8_encode($val)));
  5011.         }
  5012.         foreach($objObjs as $key{
  5013.             $serValRoot->appendChild($domObj->createElement($key,utf8_encode(serialize($this->{$key}))));
  5014.         }
  5015.  
  5016.         if ($debugecho "<pre>"htmlspecialchars(str_replace("<","\n<",$domObj->saveXML()))."</pre>";;
  5017.         $domObj->save($xmlfile);
  5018.  
  5019.         if ($debugecho "</blockquote>";
  5020.         if ($echoXML{
  5021.             header("Content-Type: text/xml");
  5022.             echo $domObj->saveXML();
  5023.         else {
  5024.             $domObj->saveXML();
  5025.         }
  5026.         return $xmlfile;
  5027.     }
  5028.  
  5029.     /**
  5030.       * exports the form to an xml file
  5031.       *
  5032.       * @param DomElement $frmNode 
  5033.       * @parma boolean $debug
  5034.       *
  5035.       * @returns bool;
  5036.       *
  5037.       * @version pk-06-05-25
  5038.       *
  5039.       ***/
  5040.     function xmlDomNodeImport($frmNode,$debug=FALSE{
  5041.         if ($debugecho "<pre>".$frmNode->nodeName.": ".$frmNode->childNodes->length."</pre>";
  5042.         DBMS_field_IncludeAllSrc($debug)// <pk-06-05-29 />
  5043.         foreach($frmNode->childNodes as $node{
  5044.             if ($debugecho "<pre>".$node->nodeName.": ".$node->childNodes->length."</pre>";
  5045.             switch($node->nodeName{
  5046.                 case "FRM_VALUES":
  5047.                     foreach($node->childNodes as $valNode{
  5048.                         if ($debugecho "<blockquote><p><b>".$valNode->nodeName."</b> ".utf8_decode($valNode->nodeValue)."</p>";
  5049.                         $this->{$valNode->nodeName}=utf8_decode($valNode->nodeValue);
  5050.                         if ($debugecho "</blockquote>";
  5051.                     }
  5052.                     break;
  5053.                 case "FRM_SERVALUES":
  5054.                     foreach($node->childNodes as $valNode{
  5055.                         if ($debugecho "<blockquote><p><b>".$valNode->nodeName."</b> ".utf8_decode($valNode->nodeValue)."</p>";
  5056.                         $this->{$valNode->nodeName}=unserialize(utf8_decode($valNode->nodeValue));
  5057.                         if ($debugecho "</blockquote>";
  5058.                     }
  5059.                     break;
  5060.                 case "FRM_TABLE_LST":
  5061.                     foreach($node->childNodes as $tblNode{
  5062.                         if ($tblNode->nodeName == "FRM_TABLE"{
  5063.                             $this->frmTables[]=utf8_decode($tblNode->nodeValue);
  5064.                         }
  5065.                     }
  5066.                     break;
  5067.                 case "FRM_KEY_LST":
  5068.                     foreach($node->childNodes as $tblNode{
  5069.                         if ($tblNode->nodeName == "FRM_KEY"{
  5070.                             $kArr=array();
  5071.                             foreach($tblNode->childNodes as $valNode{
  5072.                                 $kArr[$valNode->nodeName]=utf8_decode($valNode->nodeValue);
  5073.                             }
  5074.                             $this->frmKeys[]=$kArr;
  5075.                         }
  5076.                     }
  5077.                     break;
  5078.                 case "DBMS_FLD_LST":
  5079.                     foreach($node->childNodes as $fldNode{
  5080.                         //echo "<p>DBMS_FLD NODE: ".$fldNode->nodeName."<br /><pre>".$fldNode->nodeValue."</pre></p>";
  5081.                         if ($fldNode->nodeName == "DBMS_FLD"{
  5082.                             if ($debugecho "<p>DBMS_FLD NODE: ".$fldNode->nodeName."<br /><pre>".$fldNode->nodeValue."</pre></p>";
  5083.                             $nArr=array();
  5084.                             foreach($fldNode->childNodes as $valNode{
  5085.                                 // we have no dtd yet -> $fldNode->getElementsByTagName() won't work
  5086.                                 if ($debugecho "<pre>\t".$valNode->nodeName.":\n\t\t".$valNode->nodeValue."</pre>";
  5087.                                 switch($valNode->nodeName{
  5088.                                     case "FLD_IDXKEY":
  5089.                                         $nArr['FLD_IDXKEY']=utf8_decode($valNode->nodeValue);
  5090.                                         break;
  5091.                                     case "FLD_CLASS":
  5092.                                         $nArr['FLD_CLASS']=utf8_decode($valNode->nodeValue);
  5093.                                         break;
  5094.                                     default:
  5095.                                         if ($debugecho "<pre>\t".$valNode->nodeName."</pre>";
  5096.                                 }
  5097.  
  5098.                             }
  5099.                             if (!empty($nArr['FLD_CLASS']&& !empty($nArr['FLD_IDXKEY'])) {
  5100.                                 $cmd ="\$this->frmFields['".$nArr['FLD_IDXKEY']."']= new ".$nArr['FLD_CLASS'];
  5101.                                 $cmd.="(".str_replace(".",",",$nArr['FLD_IDXKEY']).",array());";
  5102.                                 eval($cmd);
  5103.                                 if (is_object($this->frmFields[$nArr['FLD_IDXKEY']])) {
  5104.                                     $this->frmFields[$nArr['FLD_IDXKEY']]->xml_loadDomElement($fldNode,$debug);
  5105.                                 }
  5106.                             else if ($debug{
  5107.                                 echo "<p>NODE: ".$fldNode->nodeName."</p>";
  5108.                                 echo "<pre>";print_r($nArr);echo "</pre>";
  5109.                             }
  5110.                         else if ($debug{
  5111.                             echo "<p>UNKNOWN NODE: ".$fldNode->nodeName."</p>";
  5112.                         }
  5113.  
  5114.                     }
  5115.                     break;
  5116.                 default:
  5117.                     echo "<p>NODE: ".$node->nodeName."</p>";
  5118.             }
  5119.         }
  5120.     }
  5121.  
  5122.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  5123.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  5124.     /*                                                                                    */
  5125.     /*              AJAX METHODS                                                          */
  5126.     /*                                                                                    */
  5127.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  5128.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  5129.  
  5130.     /**
  5131.       * creates an AJAX_FORM for the form
  5132.       * @since pk-07-02-27
  5133.       * @access protected
  5134.       ***/
  5135.     protected function ajax_createObj({
  5136.         require_once __OCSP_PHPINCPATH__."ajax/OCSP_AJAXFORM.phpclass";
  5137.         $this->myAjaxObj=new OCSP_AJAXFORM();
  5138.         $this->myAjaxObj->setFormObject($this);
  5139.     }
  5140.  
  5141.     /**
  5142.       * @returns AJAX_FORM
  5143.       * @since pk-07-02-27
  5144.       * @access public
  5145.       ***/
  5146.     function &ajax_getObj({
  5147.         if (!is_object($this->myAjaxObj|| (!pcf_is_instance_of($this->myAjaxObj,'OCSP_AJAX'))) {
  5148.             $this->ajax_createObj();
  5149.         }
  5150.         return $this->myAjaxObj;
  5151.     }
  5152.  
  5153.     /**
  5154.       * @param AJAX_FORM $aAjaxFrmObj 
  5155.       * @since pk-07-02-27
  5156.       * @access public
  5157.       ***/
  5158.     function ajax_setObj(&$aAjaxFrmObj{
  5159.         $this->myAjaxObj=$aAjaxFrmObj;
  5160.     }
  5161.  
  5162.  
  5163.  
  5164.  
  5165.  
  5166.  
  5167. // end class DBMS_FORM
  5168.  
  5169. ?>

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