Source for file OCSP_FORM_BLOCK.phpclass

Documentation is available at OCSP_FORM_BLOCK.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_FORM_BLOCK.phpclass
  4.   *
  5.   *
  6.   * @project    Open CSP-Management
  7.   * @package    forms
  8.   * @category   dbms_form
  9.   *
  10.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @since  pk-07-06-30
  14.   *
  15.   ***/
  16.  
  17.  
  18. /**
  19.  * requirements
  20.  */
  21. require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."OCSP_OBJ.phpclass";
  22.  
  23. /**
  24.   * constants
  25.   */
  26. define('__OCSP_FRMBLK_VIEWINLINE__',0);
  27. define('__OCSP_FRMBLK_VIEWTAB__',1);
  28. define('__OCSP_FRMBLK_VIEWFIELDSET__',2);
  29. define('__OCSP_FRMBLK_VIEWTABLE__',3);
  30.  
  31. /**
  32.   * class OCSP_FORM_BLOCK
  33.   *
  34.   * @project    Open CSP-Management
  35.   * @package    forms
  36.   * @category   dbms_form
  37.   *
  38.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  39.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  40.   *
  41.   *
  42.   * @since  pk-07-06-30
  43.   *
  44.   */
  45. class OCSP_FORM_BLOCK extends OCSP_OBJ
  46. {
  47.  
  48.     /*** class constants  --------------------------------------------- */
  49.  
  50.     /**
  51.       * @constant string CLASS_SRC_FILE
  52.       */
  53.     const CLASS_SRC_FILE = __FILE__;    
  54.     
  55.     /*** Aggregations: */
  56.  
  57.  
  58.     /*** Compositions: */
  59.  
  60.     /**
  61.       * @var OCSP_FORM $myForm 
  62.       * @access protected
  63.       */
  64.     protected $myForm=NULL;
  65.  
  66.     /**
  67.       * @var array $myFields 
  68.       * @access protected
  69.       */
  70.     protected $myFields=array();
  71.  
  72.     /**
  73.       * @var int $curFieldMode 
  74.       * @access protected
  75.       */
  76.     protected $curFieldMode=-99// set to an unsed value
  77.  
  78.     /*** Attributes: ***/
  79.  
  80.     /**
  81.       * @var boolean $fieldsLoaded 
  82.       * @access protected
  83.       */
  84.     protected $fieldsLoaded=False;
  85.  
  86.  
  87.     /**
  88.       * db vars
  89.       */
  90.     protected $FRB_SHOW_RO=1;
  91.     protected $FRB_SHOW_EDIT=1;
  92.     protected $FRB_SHOW_NEW=1;
  93.     protected $FRB_SHOW_COPY=1;
  94.     protected $FRB_SHOW_DELETE=1;
  95.     protected $FRB_SHOW_LIST=1;
  96.     protected $FRB_GROUP_SHOW=0;
  97.  
  98.     /**
  99.       * @var array $myDBColumns 
  100.       * @access protected
  101.       */
  102.     protected $myBlockDBColumns=array('FRB_ID','FRM_ID','FRB_VIEWTYPE','FRB_ORIG_FRB_ID','FRB_ORIG_FRM_ID','FRB_SORTORDER','FRB_PARENT',
  103.                             'FRB_SHOW_RO','FRB_SHOW_NEW','FRB_SHOW_EDIT','FRB_SHOW_DELETE','FRB_SHOW_LIST','FRB_SHOW_COPY','FRB_GROUP_SHOW','FRB_GROUP_NEW','FRB_GROUP_EDIT',
  104.                             'FRB_CLASS','FRB_CLASSSRC','FRB_TABLES','FRB_LINKCOLS','FRB_NAME','FRB_OBJVALS',
  105.                             'FRB_SHOW_FRMBUTTONS','FRB_CSS_CLASS','FRB_CSS_STYLE','FRB_DESC','FRB_EXTCONF');
  106.  
  107.     /**
  108.       * @var OCSP_DB $myDBObj 
  109.       * @access protected
  110.       */
  111.     protected $myDBObj = NULL;
  112.  
  113.     // ------------------------------------
  114.  
  115.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  116.     // init methods
  117.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  118.  
  119.     /**
  120.       * @param OCSP_FORM $aForm 
  121.       * @param boolean $debug 
  122.       */
  123.     function OCSP_FORM_BLOCK(&$aForm,$debug=False)
  124.     {
  125.         $this->setMyForm($aForm);
  126.     }
  127.  
  128.     /**
  129.       * generates a new block form from a database row
  130.       *
  131.       * @param OCSP_FORM $aForm 
  132.       * @param array $row 
  133.       * @param boolean $debug 
  134.       *
  135.       * @return OCSP_FORM_BLOCK 
  136.       *
  137.       * @todo OCSP_FORM_BLOCK::getBlockObjFromRow() load class if not loaded
  138.       */
  139.     function getBlockObjFromRow(&$aForm,$row,$debug=False)
  140.     {
  141.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::getBlockObjFromRow()",print_r($row,True));
  142.  
  143.         if (isset($row['FRB_CLASS']&& ($row['FRB_CLASS'!= "OCSP_FORM_BLOCK"))
  144.         {
  145.             if (!class_exists($row['FRB_CLASS']))
  146.             {
  147.                 ocsp_logError(__FILE__,__LINE__,$row['FRB_CLASS']." does not exist");
  148.                 return NULL;
  149.             }
  150.             $str_cmd="\$obj_ret=new ".$row['FRB_CLASS']."(\$aForm);";
  151.             @eval($str_cmd);
  152.             if (!pcf_is_instance_of($obj_ret,'OCSP_FORM_BLOCK'))
  153.             {
  154.                 ocsp_logError(__FILE__,__LINE__,$str_cmd." failed");
  155.                 return NULL;
  156.             }
  157.         else {
  158.             $obj_ret=new OCSP_FORM_BLOCK($aForm);
  159.         }
  160.         foreach($row as $str_col => $mix_val)
  161.         {
  162.             $obj_ret->setMyDBColValue($str_col,$mix_val);
  163.         }
  164.         return $obj_ret;
  165.     }
  166.  
  167.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168.     // getter/setter methods
  169.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170.  
  171.     /**
  172.       * @returns boolean
  173.       */
  174.     function isTab()
  175.     {
  176.         if (isset($this->FRB_VIEWTYPE&& ($this->FRB_VIEWTYPE==__OCSP_FRMBLK_VIEWTAB__)) return True;
  177.         return False;
  178.     }
  179.  
  180.     /**
  181.       * @returns boolean
  182.       */
  183.     function isFieldSet()
  184.     {
  185.         if (isset($this->FRB_VIEWTYPE&& ($this->FRB_VIEWTYPE==__OCSP_FRMBLK_VIEWFIELDSET__)) return True;
  186.         return False;
  187.     }
  188.  
  189.     /**
  190.       * @return boolean 
  191.       */
  192.     function isTable()
  193.     {
  194.         if (isset($this->FRB_VIEWTYPE&& ($this->FRB_VIEWTYPE==__OCSP_FRMBLK_VIEWTABLE__)) return True;
  195.         return False;
  196.     }
  197.  
  198.     /**
  199.       * @return boolean 
  200.       */
  201.     function isInline()
  202.     {
  203.         if (!isset($this->FRB_VIEWTYPE|| intval($this->FRB_VIEWTYPE1return True;
  204.         return False;
  205.     }
  206.  
  207.     /**
  208.       * @return int 
  209.       */
  210.     function getViewType()
  211.     {
  212.         if (isset($this->FRB_VIEWTYPE)) return intval($this->FRB_VIEWTYPE);
  213.         return __OCSP_FRMBLK_VIEWINLINE__;
  214.     }
  215.  
  216.     /**
  217.       * @return boolean 
  218.       */
  219.     function showButtons()
  220.     {
  221.         if (isset($this->FRB_SHOW_FRMBUTTONS&& intval($this->FRB_SHOW_FRMBUTTONS)) return True;
  222.         return False;
  223.     }
  224.  
  225.  
  226.     /**
  227.       * @return OCSP_FORM 
  228.       */
  229.     function &getMyForm()
  230.     {
  231.         return $this->myForm;
  232.     }
  233.  
  234.     /**
  235.       * @param OCSP_FORM $aForm 
  236.       */
  237.     function setMyForm(&$aForm)
  238.     {
  239.         $this->myForm=&$aForm;
  240.         $this->FRM_ID=$aForm->getId();
  241.     }
  242.  
  243.     /**
  244.       * @return int 
  245.       */
  246.     function getFrmId()
  247.     {
  248.         if (pcf_is_instance_of($this->myForm,'OCSP_FORM'))
  249.         {
  250.             return $this->myForm->getId();
  251.         else if (isset($this->FRM_ID)) {
  252.             return intval($this->FRM_ID);
  253.         else {
  254.             return False;
  255.         }
  256.     }
  257.  
  258.  
  259.     // database values ----------------------------------
  260.  
  261.     /**
  262.       * @return int 
  263.       */
  264.     function getId()
  265.     {
  266.         if (isset($this->FRB_ID))
  267.         {
  268.             return intval($this->FRB_ID);
  269.         else {
  270.             return 0;
  271.         }
  272.     }
  273.  
  274.     /**
  275.      * sets the block id to the object and the fields
  276.      *
  277.      * @param unknown_type $aId 
  278.      */
  279.     function setId($aId)
  280.     {      
  281.         $this->FRB_ID=intval($aId);
  282.     }
  283.     
  284.     
  285.     /**
  286.       * @return string 
  287.       */
  288.     function getName()
  289.     {
  290.         if (isset($this->FRB_NAME&& !empty($this->FRB_NAME))
  291.         {
  292.             return $this->FRB_NAME;
  293.         }
  294.  
  295.         if (!intval($this->getId()))
  296.         {
  297.             return "DEFAULT";
  298.         else {
  299.             return $this->FRB_NAME;
  300.         }
  301.     }
  302.  
  303.     /**
  304.       * returns $this->FRB_NAME if intval($this->getId()
  305.       * @return string 
  306.       */
  307.     function getTitle()
  308.     {
  309.         if (intval($this->getId())) return $this->FRB_NAME;
  310.         return "";
  311.     }
  312.  
  313.     /**
  314.       * @param string $aName 
  315.       */
  316.     function setName($aName)
  317.     {
  318.         $this->FRB_NAME=$aName;
  319.     }
  320.  
  321.     /**
  322.       * @return int 
  323.       */
  324.     function getOrderNr()
  325.     {
  326.         if (isset($this->FRB_SORTORDER))
  327.         {
  328.             return intval($this->FRB_SORTORDER);
  329.         else {
  330.             return 0;
  331.         }
  332.     }
  333.  
  334.     /**
  335.       * @param int $ordNr 
  336.       */
  337.     function setOrderNr($ordNr)
  338.     {
  339.         $this->FRB_SORTORDER=$ordNr;
  340.     }
  341.  
  342.     /**
  343.       * returns an array with the show fields
  344.       *
  345.       * @return array 
  346.       */
  347.     function getShowFields()
  348.     {
  349.         return array(
  350.                 'FRB_SHOW_RO'       =>OCSP_FORM::getLangTxt('MOD_RO'),
  351.                 'FRB_SHOW_NEW'      =>OCSP_FORM::getLangTxt('MOD_NEW'),
  352.                 'FRB_SHOW_EDIT'     =>OCSP_FORM::getLangTxt('MOD_EDIT'),
  353.                 'FRB_SHOW_DELETE'   =>OCSP_FORM::getLangTxt('MOD_DELETE'),
  354.                 'FRB_SHOW_LIST'     =>OCSP_FORM::getLangTxt('MOD_LIST'),
  355.                 'FRB_SHOW_COPY'     =>OCSP_FORM::getLangTxt('MOD_COPY'),
  356.             );
  357.     }
  358.  
  359.     /**
  360.       * @param string $col 
  361.       * @param mixed $val 
  362.       */
  363.     function setMyDBColValue($col,$val)
  364.     {
  365.         if (in_array($col,$this->myBlockDBColumns))
  366.         {
  367.             $this->{$col}=$val;
  368.         }
  369.     }
  370.  
  371.     /**
  372.       * @param string $col 
  373.       * @return mixed 
  374.       */
  375.     function getMyDBColValue($col)
  376.     {
  377.         if (in_array($col,$this->myBlockDBColumns))
  378.         {
  379.             if (isset($this->{$col})) return $this->{$col};
  380.             else return NULL;
  381.         }
  382.     }
  383.  
  384.     /**
  385.       * @return string 
  386.       */
  387.     function getCssClass()
  388.     {
  389.         return $this->FRB_CSS_CLASS;
  390.     }
  391.  
  392.     /**
  393.       * @return string 
  394.       */
  395.     function getCssStyle()
  396.     {
  397.         return $this->FRB_CSS_STYLE;
  398.     }
  399.  
  400.     /**
  401.       * @return string 
  402.       */
  403.     function getDesc()
  404.     {
  405.         return $this->FRB_DESC;
  406.     }
  407.  
  408.     /**
  409.      * returns the extJS configuration options for the block
  410.      *
  411.      * @return string 
  412.      * @since pk-08-09-22
  413.      */
  414.     function getExtConf()
  415.     {
  416.         return $this->FRB_EXTCONF;
  417.     }
  418.     
  419.     /**
  420.       * returns if the block is linked from another form
  421.       * @return boolean 
  422.       */
  423.     function isLinked()
  424.     {
  425.         if (isset($this->FRB_ORIG_FRB_ID&& intval($this->FRB_ORIG_FRB_ID&& intval($this->FRB_ORIG_FRM_ID))
  426.         {
  427.             return True;
  428.         else {
  429.             return False;
  430.         }
  431.     }
  432.  
  433.     /**
  434.       * @return int 
  435.       */
  436.     function getLinkedFromFormId()
  437.     {
  438.         return intval($this->FRB_ORIG_FRM_ID);
  439.     }
  440.  
  441.     /**
  442.       * @return int 
  443.       */
  444.     function getLinkedFromBlockId()
  445.     {
  446.         return intval($this->FRB_ORIG_FRB_ID);
  447.     }
  448.  
  449.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  450.     // form block db methods
  451.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  452.  
  453.  
  454.     /**
  455.       * returns the db object from the form
  456.       *
  457.       * @param boolean $debug 
  458.       * @return OCSP_DB 
  459.       * @access public
  460.       */
  461.     function &getDBObj($debug=False)
  462.     {
  463.         if (!pcf_is_instance_of($this->myDBObj,'OCSP_DB'))
  464.         {
  465.             if (!pcf_is_instance_of($this->myForm,'OCSP_FORM'))
  466.             {
  467.                 $this->myDBObj NULL;
  468.             else {
  469.                 $this->myDBObj=$this->myForm->getDBObj($debug);
  470.             }
  471.         }
  472.         return $this->myDBObj;
  473.     }
  474.  
  475.     /**
  476.       * @param OCSP_DB $dbObj 
  477.       * @access public
  478.       */
  479.     function setDBObj(&$dbObj)
  480.     {
  481.         $this->myDBObj=&$dbObj;
  482.     }
  483.  
  484.     /**
  485.       * loads the block form the database
  486.       * @param boolean $debug 
  487.       * @access public
  488.       */
  489.     function loadFromDB($debug=False)
  490.     {
  491.         if ($debugechoDebugMethod(__FILE__,get_class($this)."OCSP_FORM_BLOCK::loadFormDB()");
  492.         if ($arr_Data=$this->getDBObj()->getArray("T_DBMS_FORMBLOCKS",array('FRM_ID' => intval($this->myForm->getId())),0,1,NULL,$debug))
  493.         {
  494.             $this->setDBRow($arr_Data);
  495.             $this->myFields=array();
  496.         }
  497.     }
  498.  
  499.     /**
  500.       * stores the block to the database
  501.       * @param boolean $debug 
  502.       */
  503.     function storeToDB($debug=False)
  504.     {
  505.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::storeToDB()");
  506.         $arr_dbRow=array();
  507.         foreach($this->myBlockDBColumns as $str_colName)
  508.         {
  509.             if (isset($this->{$str_colName}))
  510.             {
  511.                 $arr_dbRow[$str_colName]=$this->{$str_colName};
  512.             else {
  513.                 $arr_dbRow[$str_colName]=NULL;
  514.             }
  515.         }
  516.  
  517.         if (empty($arr_dbRow['FRB_TABLES']))
  518.         {
  519.             $arr_dbRow['FRB_TABLES']="__NO-DBFIELD__";
  520.             foreach($this->myFields as &$obj_field)
  521.             {
  522.                 $str_tbl=$obj_field->getTable();
  523.                 if (!empty($str_tbl&& (empty($arr_dbRow['FRB_TABLES']|| !strstr($arr_dbRow['FRB_TABLES'],$str_tbl)))
  524.                 {
  525.                     $arr_dbRow['FRB_TABLES'].=" ".$str_tbl;
  526.                 }
  527.             }
  528.         }
  529.  
  530.         if (intval($this->getId()))
  531.         {
  532.             if ($debugechoDebugLine(__FILE__,__LINE__,"updating existing block");
  533.             
  534.             if (!OCSP_OBJ::defaultWriteDBObj()->replaceArray('T_DBMS_FORMBLOCKS',$arr_dbRow,False))
  535.             {
  536.                 ocsp_logError(__FILE__,__LINE__,OCSP_OBJ::defaultWriteDBObj()->errorMsg("error updateing form block ".$this->getId())."\n".print_r($arr_dbRow,True));
  537.                 return False;
  538.             }
  539.         else {
  540.             if ($debugechoDebugLine(__FILE__,__LINE__,"inserting new block");
  541.             if ($this->getName(!= "DEFAULT")
  542.             {
  543.                 unset($arr_dbRow['FRB_ID']);
  544.                 if ($aId=OCSP_OBJ::defaultWriteDBObj()->insertArray('T_DBMS_FORMBLOCKS',$arr_dbRow,False,'FRB_ID'))
  545.                 {
  546.                     if ($arr_Data=OCSP_OBJ::defaultWriteDBObj()->getArray("T_DBMS_FORMBLOCKS",array('FRB_ID' => intval($aId)),0,1,NULL,False))
  547.                     // to also have db default values loaded
  548.                         foreach($arr_Data as $str_col => $mix_val)
  549.                         {
  550.                             $this->{$str_col}=$mix_val;
  551.                         }
  552.                     else {
  553.                         ocsp_logError(__FILE__,__LINE__,"error reloading inserted formblock ID:".$aId);
  554.                         return False;
  555.                     }
  556.                 else {
  557.                     ocsp_logError(__FILE__,__LINE__,OCSP_OBJ::defaultWriteDBObj()->errorMsg("error inserting formblock").print_r($arr_dbRow));
  558.                     return False;
  559.                 }
  560.             else if ($debug{
  561.                 echoDebugLine(__FILE__,__LINE__,"\$this->getName() returned DEFAULT");
  562.             }
  563.         }
  564.  
  565.         if ($debugechoDebugLine(__FILE__,__LINE__,"<h1>Field of ".$this->getName()."</h1>");
  566.         foreach($this->myFields as &$o_fld)
  567.         {
  568.             $this->storeFldToDb($o_fld,$debug);
  569.         }
  570.     }
  571.  
  572.     /**
  573.       * writes the field data to T_DBMS_FORMFIELDS
  574.       *
  575.       * @param DBMS_FIELD $aFld 
  576.       * @param boolean $debug 
  577.       * @param foreceLinked (if false linked block fields are not stored. this should only be tree if a block is linked to hide existing fields)
  578.       */
  579.     function storeFldToDb($aFld,$debug=False,$forceLinked=False)
  580.     {
  581.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::storeFldToDb(".$aFld->getKey().")");
  582.  
  583.         if ($this->isLinked(&& !$forceLinked)
  584.         {
  585.             if ($debugechoDebugLine(__FILE__,__LINE__,"Link Block no need to store fields to db");
  586.             return True;
  587.         }
  588.  
  589.         if ($aFld->isMarkedDeleted())
  590.         {
  591.             $arr_delKey=array(
  592.                 'FRM_ID'            => $this->getFrmId(),
  593.                 'FRB_ID'            => $this->getId(),
  594.                 'FLD_KEY'           => $aFld->getKey(),
  595.                 'FLD_TABLE'         => $aFld->getTable(),
  596.             );
  597.             OCSP_OBJ::defaultWriteDBObj()->deleteRows("T_DBMS_FORMFIELDS",$arr_delKey,True,$debug);
  598.         else {
  599.             $a_fldRow=array(
  600.                 'FRM_ID'            => $this->getFrmId(),
  601.                 'FRB_ID'            => $this->getId(),
  602.                 'FRM_CLASS'         => strtoupper(get_class($this->myForm)),
  603.                 'FRB_CLASS'         => strtoupper(get_class($this)),
  604.                 'FLD_KEY'           => $aFld->getKey(),
  605.                 'FLD_TABLE'         => $aFld->getTable(),
  606.                 'FLD_NAME'          => $aFld->getName(),
  607.                 'FRM_MODULE'        => $aFld->getModuleKey(),
  608.                 'FLD_IS_HIDDEN'     => intval($aFld->isHidden()),
  609.                 'FLD_ENABLE_NEW'    => intval($aFld->isEnabled(FRM_MODE_NEW)),
  610.                 'FLD_ENABLE_EDIT'   => intval($aFld->isEnabled(FRM_MODE_EDIT)),
  611.                 'FLD_SHOW_IN_LIST'  => intval($aFld->showInList()),
  612.                 'FLD_SORTORDER'     => intval($aFld->getOrderNr()),
  613.                 'FLD_CLASS'         => strtoupper(get_class($aFld)),
  614.                 'FLD_CLASS_SRC'     => $aFld->getSourceFile(),
  615.                 'FLD_B64OBJECT'     => base64_encode(serialize($aFld->getObjectData())),
  616.                 'FLD_LABEL'         => $aFld->getLabel()     // <pk-05-10-04 />
  617.             );
  618.             if ($debugechoDebugLine(__FILE__,__LINE__,"<p style=\"font-size: 75%;padding-left:20px;\">FRM_ID: ".$a_fldRow['FRM_ID']." FRB_ID: ".$a_fldRow['FRB_ID']." FLD_KEY: ".$a_fldRow['FLD_KEY']."</p>");
  619.             OCSP_OBJ::defaultWriteDBObj()->replaceArray("T_DBMS_FORMFIELDS",$a_fldRow,False);
  620.         }
  621.     }
  622.     
  623.     /**
  624.       * sets the database row to the object
  625.       *
  626.       * @param array $dbRow 
  627.       * @param boolean $debug 
  628.       * @access public
  629.       */
  630.     function setDBRow($dbRow,$debug=False)
  631.     {
  632.         foreach($dbRow as $str_col => $str_val)
  633.         {
  634.             $this->{$str_col}=$str_val;
  635.         }
  636.     }
  637.  
  638.     /**
  639.       * updates a block form $_POST[$arrName] values
  640.       *
  641.       * @param string $arrName 
  642.       * @param array $colNames 
  643.       * @param boolean $debug 
  644.       *
  645.       * @return boolean 
  646.       */
  647.     function updateBlockFromPost($arrName='DBVAL',$colNames=NULL,$debug=False)
  648.     {
  649.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::updateBlockFromPost()",print_r($colNames,True));
  650.  
  651.         if(!isset($_POST[$arrName]|| (!is_array($_POST[$arrName]))) return False;
  652.  
  653.         $this->getMyForm();         // ensure $this->myForm isset
  654.         $this->getDBObj();          // ensure $this->myDBObj isset
  655.         $this->getFields(-1);       // ensure all fields are loaded
  656.  
  657.         $arr_Data=$_POST[$arrName];
  658.         unset($arr_Data['FRB_ID'])// avoid overwriting
  659.         $b_reloadForm=False;        // if true the whole form is reloaded after the updates have been made
  660.  
  661.         $arr_Data['FRB_NAME']=trim($arr_Data['FRB_NAME']);
  662.         if (isset($arr_Data['FRB_NAME']&& !empty($arr_Data['FRB_NAME']&& ($arr_Data['FRB_NAME'!= $this->getName()))
  663.         {
  664.             $this->getDBObj()// ensure $this->myDBObj isset
  665.  
  666.             $str_query ="SELECT COUNT(*) FROM T_DBMS_FORMBLOCKS ";
  667.             $str_query.=" WHERE FRM_ID=".$this->getId();
  668.             $str_query.="   AND UPPER(FRB_NAME)=".$this->myDBObj->qs_getSlashedValue(strtoupper(trim($arr_Data['FRB_NAME'])));
  669.             $str_query.="   AND FRB_ID <> ".$this->getId();
  670.  
  671.             if (intval($this->myDBObj->getOne($str_query)))
  672.             {
  673.                 ocsp_logError(__FILE__,__LINE__,"Name: ".$arr_Data['FRB_NAME']." already in use",E_NOTICE);
  674.             else {
  675.                 $this->setName($arr_Data['FRB_NAME']);
  676.             }
  677.         }
  678.         if (isset($arr_Data['FRB_SORTORDER']&& intval($arr_Data['FRB_SORTORDER']&& ($this->getOrderNr(!= intval($arr_Data['FRB_SORTORDER'])))
  679.         {
  680.             $str_cmd ="UPDATE T_DBMS_FORMBLOCKS SET FRB_SORTORDER=FRB_SORTORDER+1 ";
  681.             $str_cmd.=" WHERE FRM_ID=".$this->getFrmId();
  682.             $str_cmd.="   AND FRB_SORTORDER >= ".intval($arr_Data['FRB_SORTORDER']);
  683.             if ($debugechoDebugLine(__FILE__,__LINE__,$str_cmd);
  684.             $this->myDBObj->executeCmd($str_cmd);
  685.  
  686.             $str_cmd ="UPDATE T_DBMS_FORMBLOCKS SET FRB_SORTORDER=".intval($arr_Data['FRB_SORTORDER']);
  687.             $str_cmd.=" WHERE FRM_ID=".$this->getFrmId();
  688.             $str_cmd.="   AND FRB_ID=".$this->getId();
  689.             if ($debugechoDebugLine(__FILE__,__LINE__,$str_cmd);
  690.             $this->myDBObj->executeCmd($str_cmd);
  691.  
  692.             $b_reloadForm=True;
  693.         }
  694.  
  695.         $arr_showCols=$this->getShowFields();
  696.         foreach($arr_showCols as $col => $lab)
  697.         {
  698.             if (isset($arr_Data[$col]))
  699.             {
  700.                 if (!empty($arr_Data[$col]))
  701.                 {
  702.                     $this->setMyDBColValue($col,True);
  703.                 else {
  704.                     $this->setMyDBColValue($col,False);
  705.                 }
  706.                 unset($arr_Data[$col]);
  707.             else {
  708.                 $this->setMyDBColValue($col,False);
  709.             }
  710.         }
  711.  
  712.         foreach($arr_Data as $col => $val)
  713.         {
  714.             $this->setMyDBColValue($col,$val);
  715.         }
  716.  
  717.         if (!$this->isLinked(&& is_array($colNames))
  718.         {
  719.             foreach($colNames as $str_colName)
  720.             {
  721.                 if ($debugecho "<p style=\"background-colorred\">$str_colName --".substr($str_colName,0,2)."--</p>";
  722.                 if (substr($str_colName,0,2!= "-:")
  723.                 {
  724.                     if ($obj_field=$this->myForm->getField($str_colName))
  725.                     {
  726.                         $this->addFieldObj($obj_field,$debug);
  727.                     else {
  728.                         ocsp_logError(__FILE__,__LINE__,"Field: ".$str_colName." not found");
  729.                     }
  730.                     $b_reloadForm=True;
  731.                 }
  732.             }
  733.         }
  734.         $this->storeToDb($debug);
  735.         $this->myForm->delCacheFiles();
  736.  
  737.         if ($b_reloadForm)
  738.         {
  739.             if ($debugechoDebugLine(__FILE__,__LINE__,"Reloading Form");
  740.             $this->myForm->loadBlocksFromDb();
  741.         }
  742.         return True;
  743.     }
  744.  
  745.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  746.     // export / import
  747.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  748.     
  749.    /**
  750.      * returns the form export string (php array)
  751.      * 
  752.      * @return string 
  753.      * 
  754.      * @since pk-08-10-31
  755.      */ 
  756.     public function getExportString()
  757.     {
  758.         $str_ret "array(\n";
  759.         
  760.         foreach($this->myBlockDBColumns as $str_colName)
  761.         {
  762.             $str_ret .= "\t\t\t\t'{$str_colName}' => \"base64_encode(serialize($this->{$str_colName})) "\",\n";
  763.         }
  764.         
  765.         if ($arr_fields $this->getFields(-1))
  766.         {
  767.             $str_ret .= "\t\t\t\t'_FIELDS' => array(\n";
  768.             $str_tabs "\t\t\t\t\t";
  769.             foreach($arr_fields as $obj_field)
  770.             {                                
  771.                 if ($arr_fldData $obj_field->getObjectVars()) 
  772.                 {            
  773.                     $str_ret .= $str_tabs "'{$obj_field->getKey()}' => array(\n";
  774.                     $str_ret .= $str_tabs "\t'class' => \"" get_class($obj_field"\",\n";
  775.                     foreach($arr_fldData as $str_valName => $mix_val)
  776.                     {
  777.                         switch($str_valName)
  778.                         {
  779.                             case "classSrcFile":
  780.                                 $str_ret .= $str_tabs."\t'{$str_valName}' => \"str_replace(__OCSP_PHPINCPATH__,'',$mix_val"\",\n";
  781.                                 break;
  782.                             default:
  783.                                 $str_ret .= $str_tabs."\t'{$str_valName}' => \"base64_encode(serialize($mix_val)) "\",\n";                                
  784.                         }
  785.                             
  786.                     }
  787.                 }
  788.                 $str_ret .= $str_tabs"), // field {$obj_field->getKey()}\n";        
  789.             }
  790.             $str_ret .= "\t\t\t\t) // _FIELDS\n";
  791.         }
  792.         
  793.         $str_ret .= "\t\t\t),// blockValues {$this->getId()}\n";
  794.         return $str_ret;
  795.     }
  796.  
  797.    /**
  798.      * imports the form from an array
  799.      * NOTE: does not save the form
  800.      *
  801.      * @param array $impArray 
  802.      * @param boolean $debug 
  803.      */
  804.     public function importFromArray($impArray,$debug=False)
  805.     {
  806.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::importFromArray()");
  807.  
  808.         if (isset($impArray['FRB_ID'])) unset($impArray['FRB_ID']);
  809.         if (isset($impArray['FRM_ID'])) unset($impArray['FRM_ID']);
  810.         
  811.         foreach($this->myBlockDBColumns as $str_colName)
  812.         {
  813.             if (isset($impArray[$str_colName]&& !empty($impArray[$str_colName]))
  814.             {
  815.                 $this->$str_colName unserialize(base64_decode($impArray[$str_colName]));
  816.             }
  817.         }
  818.         
  819.         if (isset($impArray['_FIELDS']&& is_array($impArray['_FIELDS']))
  820.         {
  821.             $arr_tables $this->myForm->getTables();
  822.             
  823.             if ($debugechoDebugLine(__FILE__,__LINE__,"importing " sizeof($impArray['_FIELDS']" fields");
  824.             foreach($impArray['_FIELDS'as $arr_fld)
  825.             {                
  826.                 pcf_require_class($arr_fld['class'],$arr_fld['classSrcFile']);
  827.                 $obj_fld new $arr_fld['class']();
  828.                 unset($arr_fld['class']);
  829.                 unset($arr_fld['classSrcFile']);
  830.                 
  831.                 $arr_fldValues array();
  832.                 foreach($arr_fld as $str_colName => $mix_value)
  833.                 {
  834.                     if (!empty($mix_value))
  835.                     {
  836.                         switch($str_colName)
  837.                         {
  838.                             case "myBlockId":
  839.                             case "myFrmId":
  840.                                 break;
  841.                             default:
  842.                                 $arr_fldValues[$str_colNameunserialize(base64_decode($mix_value));
  843.                         }
  844.                         
  845.                     }
  846.                 }
  847.                     
  848.                 $obj_fld->setObjectVars($arr_fldValues);
  849.                 $this->addFieldObj($obj_fld,$debug)
  850.                 if ($str_table $obj_fld->getTable())
  851.                 {
  852.                     if (substr($str_table,-3!= "_OV")
  853.                     {
  854.                         if (!in_array($str_table,$arr_tables&& OCSP_OBJ::defaultReadDBObj()->tblExists($str_table))
  855.                         {
  856.                             $arr_tables[$str_table;
  857.                             $this->myForm->registerTable($str_table);
  858.                         }
  859.                     }
  860.                 }
  861.                 
  862.             }
  863.         }
  864.     }
  865.     
  866.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  867.     // form block cache methods
  868.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  869.  
  870.     /**
  871.       * @param resource $hFile 
  872.       * @param boolean $debug 
  873.       */
  874.     function writeToFileCache($hFile,$debug=False)
  875.     {
  876.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::writeToFileCache()");
  877.  
  878.         $str_eol="\n";
  879.         $arr_dbRow=array();
  880.         foreach ($this->myBlockDBColumns as $str_col)
  881.         {
  882.             if (isset($this->{$str_col})) {
  883.                 $arr_dbRow[$str_col]=$this->{$str_col};
  884.             }
  885.         }
  886.         fwrite($hFile,"'block".$this->getId()."'=>array($str_eol");
  887.         fwrite($hFile,"'dbRow'=>unserialize(base64_decode(\"".base64_encode(serialize($arr_dbRow))."\")),$str_eol");
  888.         fwrite($hFile,"'fields'=>array($str_eol");
  889.         $arr_fields=$this->getFields(-1,$debug);
  890.         foreach ($arr_fields as &$obj_fld)
  891.         {
  892.             fwrite($hFile,"'".$obj_fld->getKey()."'=>unserialize(base64_decode(\"".base64_encode(serialize($obj_fld->getObjectData($debug)))."\")),$str_eol");
  893.         }
  894.         fwrite($hFile,")),$str_eol");
  895.     }
  896.  
  897.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  898.     // fields methods
  899.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  900.  
  901.     /**
  902.       * add all columns in a table to the block
  903.       *
  904.       * @param string $aTable 
  905.       * @param boolean $asHidden if true the columns are added as hidden fields
  906.       * @param boolean $debug 
  907.       *
  908.       * @return boolean 
  909.       *
  910.       *  requires OCSP_FORM_DBCONTROLL.phpclass
  911.       *
  912.       */
  913.     function addTable($aTable,$asHidden=True,$debug=False)
  914.     {
  915.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::addTable($aTable)");
  916.  
  917.         $this->getDBObj()// ensure we have a valid db connection
  918.         if (!($arr_tblDesc=$this->myDBObj->getDBTblDesc($aTable)))
  919.         {
  920.             ocsp_logError(__FILE__,__LINE__,'Error no tabledesc found for $aTable');
  921.             return False;
  922.         }
  923.  
  924.         if (!($o_frmDBControll=$this->myForm->getMyDBControll()))
  925.         {
  926.             ocsp_logError(__FILE__,__LINE__,"no db controll object");
  927.             return False;
  928.         }
  929.  
  930.         $this->getFields(-1)// ensure this my fields is loaded
  931.  
  932.         foreach($arr_tblDesc as $str_colName => $arr_colDesc)
  933.         {
  934.             if (!$this->myForm->getField($str_colName,$aTable))
  935.             {
  936.                 $i_ordNr=sizeof($this->myFields);
  937.                 $this->myFields[$i_ordNr]=$o_frmDBControll->generateField($arr_colDesc,$debug);
  938.                 $this->myFields[$i_ordNr]->setOrderNr($i_ordNr);
  939.                 $this->myFields[$i_ordNr]->setMyForm($this->getMyForm());
  940.             }
  941.         }
  942.  
  943.         return True;
  944.     }
  945.  
  946.     /**
  947.       * loads the fields form the database
  948.       *
  949.       * @param boolean $debug 
  950.       * @access public
  951.       */
  952.     function loadMyFieldsFromDb($debug=False)
  953.     {
  954.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::loadMyFieldsFromDb() [BlockId: ".$this->getId()."]");
  955.         $dbObj=$this->myForm->getDBObj()// ensure we have a database connection
  956.  
  957.         if ($this->isLinked())
  958.         {
  959.             $arr_filter=array('FRM_ID'=>intval($this->FRB_ORIG_FRM_ID),'FRB_ID' => intval($this->FRB_ORIG_FRB_ID));
  960.         else {
  961.             $arr_filter=array('FRM_ID'=>$this->getFrmId(),'FRB_ID' => $this->getId());
  962.         }
  963.  
  964.         if ($arr_fields=$dbObj->getArray('T_DBMS_FORMFIELDS',$arr_filter,0,0,'FLD_SORTORDER',False))
  965.         {
  966.             $i_sort=1;$this->myFields=array();
  967.             foreach($arr_fields as $arr_row)
  968.             {
  969.                 $arr_objData=unserialize(base64_decode($arr_row['FLD_B64OBJECT']));
  970.                 if (!class_exists($arr_row['FLD_CLASS']))
  971.                 {
  972.                     $b_loaded=OCSP_FORM::requireFieldClass($arr_row['FLD_CLASS'],$debug);
  973.                     
  974.                     if (!$b_loaded{
  975.                         // try to find the source file in the system
  976.                         $arr_sources=array(
  977.                             __OCSP_PROJECTPATH__.$arr_row['FLD_CLASS_SRC'],
  978.                             __OCSP_PHPINCPATH__.$arr_row['FLD_CLASS_SRC'],
  979.                             __OCSP_PROJECTPATH__.$arr_objData['OBJDESC']['SRCFILE'],
  980.                             __OCSP_PHPINCPATH__.$arr_objData['OBJDESC']['SRCFILE'],
  981.                             $arr_objData['OBJVAL']['classSrcFile']
  982.                         );
  983.                         foreach($arr_sources as $str_file)
  984.                         {
  985.                             if (file_exists($str_file&& !is_dir($str_file))
  986.                             {
  987.                                 require_once $str_file;
  988.                                 $b_loaded=True;
  989.                                 break;
  990.                             }
  991.                         }
  992.  
  993.  
  994.                         if (!$b_loaded && isset($arr_objData['OBJDESC']['SRCFILE']&& !empty($arr_objData['OBJDESC']['SRCFILE']))
  995.                         {
  996.                             require_once __OCSP_PHPINCPATH__."common/pcf_templates.phpinc";
  997.                             $str_src=pcf_tmpl_parse($arr_objData['OBJDESC']['SRCFILE'],$arr_objData['OBJVAL']);
  998.                             if (file_exists($str_src))
  999.                             {
  1000.                                 include $str_src;
  1001.                                 $b_loaded=True;
  1002.                             }
  1003.                         }
  1004.                     }
  1005.                     if (!$b_loaded)
  1006.                     {
  1007.                         ocsp_logError(__FILE__,__LINE__,"fieldclass ".$arr_row['FLD_CLASS']." not loaded<br />row:<p>".print_r($arr_row,True)."</p>objData:<p>".print_r($arr_objData,True)."</p>");
  1008.                     }
  1009.                 }
  1010.                 if (class_exists($arr_row['FLD_CLASS']))
  1011.                 {
  1012.                     eval("\$this->myFields['".$i_sort."']=new ".$arr_row['FLD_CLASS']."();");
  1013.                     if (is_object($this->myFields[$i_sort]))
  1014.                     {
  1015.                         //echoDebugLine(__FILE__,__LINE__,"Object values:<pre>".print_r(unserialize(base64_decode($arr_row['FLD_B64OBJECT'])),True)."</pre>");
  1016.                         $this->myFields[$i_sort]->setObjectVars($arr_objData['OBJVAL']);
  1017.                         $this->myFields[$i_sort]->setOrderNr($i_sort);
  1018.                         $this->myFields[$i_sort]->setMyForm($this->myForm);
  1019.                         $this->myFields[$i_sort]->setMyBlock($this);
  1020.                         $i_sort++;
  1021.                     }
  1022.                 else {
  1023.                     ocsp_logError(__FILE__,__LINE__,"fieldclass ".$arr_row['FLD_CLASS']." not loaded <pre>" print_r($arr_row,True"</pre>");
  1024.                 }
  1025.             }
  1026.         else {
  1027.             if($debugechoDebugLine(__FILE__,__LINE__,'block '.$this->getName()." has no fields");
  1028.             $b_loaded=True;
  1029.             $this->myFields=array();
  1030.         }
  1031.     }
  1032.  
  1033.  
  1034.     /**
  1035.       * returns the number of fields in the form
  1036.       *
  1037.       * @param int $mode 
  1038.       * @param boolean $debug 
  1039.       *
  1040.       */
  1041.     function getNofFields($mode=-1,$debug=False)
  1042.     {
  1043.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM::getNofFields()");
  1044.         $arr_fields=$this->getFields($mode,$debug);
  1045.         return sizeof($arr_fields);
  1046.     }
  1047.  
  1048.     /**
  1049.       * @param int $mode (-1 all modes)
  1050.       * @param boolean $debug 
  1051.       * 
  1052.       * @return array of DBMS_FIELDS
  1053.       *
  1054.       * @todo cacheing
  1055.       */
  1056.     function getFields($mode=-1,$debug=False)
  1057.     {
  1058.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::getFields($mode[BlockId".$this->getId()."]");
  1059.         if (!is_array($this->myFields|| (!sizeof($this->myFields)) || (($this->curFieldMode > -1&& ($mode != $this->curFieldMode)))
  1060.         {
  1061.             $this->loadMyFieldsFromDb($debug);
  1062.             $this->curFieldMode=$mode;
  1063.         }
  1064.         switch($mode)
  1065.         {
  1066.             case FRM_MODE_LIST:
  1067.                 $arr_ret=array();
  1068.                 foreach($this->myFields as &$objFld)
  1069.                 {
  1070.                     if (!$objFld->isHidden('list'))
  1071.                     {
  1072.                         while (isset($arr_ret[$objFld->getOrderNr()]))
  1073.                         {
  1074.                             $objFld->incOrderNr();
  1075.                         }
  1076.                         $arr_ret[$objFld->getOrderNr()]=&$objFld;
  1077.                     }
  1078.                 }
  1079.                 return $arr_ret;
  1080.             case FRM_MODE_NEW:
  1081.             case FRM_MODE_EDIT:
  1082.             case FRM_MODE_COPY:
  1083.                 $arr_ret=array();
  1084.                 foreach($this->myFields as &$objFld)
  1085.                 {
  1086.                     if (!$objFld->isHidden('form'))
  1087.                     {
  1088.                         while (isset($arr_ret[$objFld->getOrderNr()]))
  1089.                         {
  1090.                             $objFld->incOrderNr();
  1091.                         }
  1092.                         $arr_ret[$objFld->getOrderNr()]=&$objFld;
  1093.                     }
  1094.                 }
  1095.                 return $arr_ret;
  1096.             case FRM_MODE_SEARCH:
  1097.                 $arr_ret=array();
  1098.                 foreach($this->myFields as &$objFld)
  1099.                 {
  1100.                     if (!$objFld->isHidden('search'))
  1101.                     {
  1102.                         $arr_ret[]=&$objFld;
  1103.                     }
  1104.                 }
  1105.                 return $arr_ret;
  1106.             default:
  1107.                 return $this->myFields;
  1108.         }
  1109.  
  1110.     }
  1111.  
  1112.     /**
  1113.       * returns a field object
  1114.       *
  1115.       * @param string $aFldName 
  1116.       * @param string $aTable (empty to search in all tables)
  1117.       * @param string $aFldKey 
  1118.       * @param boolean $debug 
  1119.       * 
  1120.       * @return DBMS_FIELD 
  1121.       * 
  1122.       * @version pk-08-07-31
  1123.       * @version pk-08-11-06 object values added to table (_OV)
  1124.       */
  1125.     function &getField($aFldName,$aTable="",$aFldKey="",$debug=False)
  1126.     {
  1127.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::getField($aFldName)");
  1128.  
  1129.         if (!strstr($aFldKey,'.')) // no table field seperator ignore it 
  1130.         {
  1131.             $aFldKey "";
  1132.         }
  1133.         
  1134.         if ($this->getFields(-1,$debug))
  1135.         {        
  1136.             foreach($this->myFields as &$obj_fld)
  1137.             {
  1138.                 if (!empty($aFldKey&& ($obj_fld->getKey(== $aFldKey)) // <pk-08-07-31>
  1139.                 {
  1140.                     return $obj_fld;
  1141.                 else if ((!empty($aTable&& ($obj_fld->getTable(== $aTable)) || (empty($aTable))) {
  1142.                     if ($obj_fld->getName()==$aFldName)
  1143.                     {
  1144.                         return $obj_fld;
  1145.                     }
  1146.                 else if ((!empty($aTable&& ($obj_fld->getTable(== $aTable "_OV"))) // <pk-08-11-06>
  1147.                     if ($obj_fld->getName()==$aFldName)
  1148.                     {
  1149.                         return $obj_fld;
  1150.                     }                    
  1151.                 }
  1152.             }
  1153.         }
  1154.         $obj_ret=NULL;
  1155.         return $obj_ret;
  1156.     }
  1157.  
  1158.  
  1159.     /**
  1160.       * adds a field to $this->myFields and removes it from the original block
  1161.       *
  1162.       * @param DBMS_FIELD $aField 
  1163.       * @param boolean $debug 
  1164.       */
  1165.     function addFieldObj(&$aField,$debug=False)
  1166.     {
  1167.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::addFieldObj(".$aField->getKey().") [BlockId: ".$this->getId()."]");
  1168.  
  1169.         if ($obj_other $aField->getMyBlock())
  1170.         {
  1171.             $obj_other->removeFieldObj($aField,$debug);
  1172.         }
  1173.         
  1174.         $this->getFields(-1,$debug);
  1175.  
  1176.         $aField->setMyBlock($this,$debug);
  1177.         $this->myFields[]=$aField;
  1178.         $aField->setOrderNr(sizeof($this->myFields));
  1179.  
  1180.         if ($debug{
  1181.             echoDebugLine(__FILE__,__LINE__,"Field: ".$this->myFields[(sizeof($this->myFields)-1)]->getKey()." added to block ".$this->getId());
  1182.  
  1183.             $str_debug="";
  1184.             foreach($this->myFields as &$obj_fld{
  1185.                 $str_debug.=$obj_fld->getKey().", ";
  1186.             }
  1187.             echoDebugLine(__FILE__,__LINE__,"Fields: <p>".$str_debug."</p>");
  1188.         }
  1189.     }
  1190.  
  1191.     /**
  1192.       * removes the field from the block not from the database
  1193.       *
  1194.       * @param DBMS_FIELD $aField 
  1195.       * @param boolean $debug 
  1196.       */
  1197.     function removeFieldObj(&$aField,$debug=False)
  1198.     {
  1199.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::removeFieldObj(".$aField->getKey().") [BlockId: ".$this->getId()."]");
  1200.  
  1201.         $this->getFields(-1,$debug);$i_sort=1;
  1202.         foreach($this->myFields as $i_idx => &$obj_fld)
  1203.         {
  1204.             if ($obj_fld->getKey(!= $aField->getKey())
  1205.             {
  1206.                 $obj_fld->setOrderNr($i_sort++);
  1207.             else {
  1208.                 unset($this->myFields[$i_idx]);
  1209.                 if ($debugechoDebugLine(__FILE__,__LINE__,$aField->getKey()." removed from block ".$this->getId());
  1210.             }
  1211.         }
  1212.     }
  1213.  
  1214.     /**
  1215.       * creates a new field and add it to the block
  1216.       *
  1217.       * @param string $colName 
  1218.       * @param string $colType 
  1219.       * @param string $table 
  1220.       * @param int $size 
  1221.       * @param boolean $debug 
  1222.       *
  1223.       * @return DBMS_FIELD 
  1224.       */
  1225.     function &addNewField($colName,$colType,$table="__NO-DBFIELD__",$size=0,$debug=False)
  1226.     {
  1227.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::createField($colName,$colType,$table,$sizeBlock".$this->getId());
  1228.  
  1229.         $obj_field=NULL;
  1230.         if (empty($colName))
  1231.         {
  1232.             ocsp_logError(__FILE__,__LINE__,"no colum name set",E_WARNING);
  1233.             return $obj_field;
  1234.         }
  1235.         if (empty($colType))
  1236.         {
  1237.             ocsp_logError(__FILE__,__LINE__,"no colum type set",E_WARNING);
  1238.             return $obj_field;
  1239.         }
  1240.  
  1241.         require_once dirname(__FILE__)."/OCSP_FORM_DBCONTROLL.phpclass";
  1242.         $str_dbColName=preg_replace('/[^a-z0-9_]/i',"_"$colName);
  1243.  
  1244.         $obj_dbControll=OCSP_FORM_DBCONTROLL::newSubClass($this->getDBObj(),$debug);
  1245.         if ($arr_dbDesc=$obj_dbControll->generateColDesc($str_dbColName,$colType,$table,$size,$debug))
  1246.         {
  1247.             if ($obj_field=$obj_dbControll->generateField($arr_dbDesc,$debug))
  1248.             {
  1249.                 // <pk-08-07-12>
  1250.                 if (substr($table,-3== "_OV")
  1251.                 {
  1252.                     $obj_field->setTblAlias('OBJVALS_' substr($table,0,-3));
  1253.                 }
  1254.                 // </pk-08-07-12>
  1255.                 
  1256.                 $this->getFields(-1,$debug);
  1257.                 $this->myFields[]=&$obj_field;
  1258.  
  1259.                 $obj_field->setLabel($colName);
  1260.                 $obj_field->setOrderNr(sizeof($this->myFields));
  1261.                 $obj_field->setMyForm($this->getMyForm());
  1262.                 $obj_field->setMyBlock($this);                
  1263.                 if (method_exists($obj_field,'setDBObj'))
  1264.                 {
  1265.                     $obj_field->setDBObj($this->getDBObj);
  1266.                 }
  1267.                 return $obj_field;
  1268.             }
  1269.         }
  1270.     }
  1271.  
  1272.     // field sorting
  1273.  
  1274.     /**
  1275.       * moves a field in the block
  1276.       *
  1277.       * @param mixed $field (DBMS_FIELD or field name)
  1278.       * @param int $movedir (-1 = up,0=position,1=down)
  1279.       * @param int $newPos 
  1280.       * @param boolean $debug 
  1281.       *
  1282.       * @return boolean 
  1283.       * @access public
  1284.       */
  1285.     function moveField(&$field,$movedir=0,$newPos=0,$debug=False)
  1286.     {
  1287.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::moveField(\$field,$movedir,$newPos)");
  1288.  
  1289.         if (pcf_is_instance_of($field,'DBMS_FIELD'))
  1290.         {
  1291.             $obj_field=&$field;
  1292.             $obj_block=$obj_field->getMyBlock();
  1293.             if ($obj_block->getId(!= $this->getId())
  1294.             {
  1295.                 $this->addFieldObj($field);
  1296.             }
  1297.         else if (!empty($field)) {
  1298.             if (strstr($field,".")) {
  1299.                 $arr_fldName=explode('.',$field);
  1300.                 if (!($obj_field=$this->getField($arr_fldName[1],$arr_fldName[0],$debug)))
  1301.                 {
  1302.                     ocsp_logError(__FILE__,__LINE__,"field {$arr_fldName[1]} table {$arr_fldName[0]} not found",E_WARNING);
  1303.                     return False;
  1304.                 }
  1305.             else if (!($obj_field=$this->getField($field))) {
  1306.                 ocsp_logError(__FILE__,__LINE__,"field $field not found",E_WARNING);
  1307.                 return False;
  1308.             }
  1309.         else {
  1310.             ocsp_logError(__FILE__,__LINE__,"param \$field is empty",E_WARNING);
  1311.             return False;
  1312.         }
  1313.  
  1314.         switch(intval($movedir))
  1315.         {
  1316.             case -1:
  1317.             case 1:
  1318.                 $i_newPos=$obj_field->getOrderNr()+$movedir;
  1319.                 break;
  1320.             default:
  1321.                 $i_newPos=intval($newPos);
  1322.         }
  1323.         if ($debugechoDebugLine(__FILE__,__LINE__,"new position$i_newPos");
  1324.         $obj_field->setOrderNr($i_newPos);
  1325.  
  1326.         $arr_fields=$this->getFields(-1,$debug);
  1327.         $arr_tmp=array();
  1328.         $i_idx=-1;
  1329.         foreach($arr_fields as &$obj_blockFld)
  1330.         {
  1331.             if ($i_idx // first loop
  1332.             {
  1333.                 $i_idx=$obj_blockFld->getOrderNr();
  1334.                 if ($i_newPos $i_idx$i_newPos=$i_idx;
  1335.                 if ($debugechoDebugLine(__FILE__,__LINE__,"first orderNr in block$i_idx");
  1336.             }
  1337.  
  1338.             if ($i_newPos==$i_idx)
  1339.             {
  1340.                 $arr_tmp[$i_idx]=&$obj_field;
  1341.                 $obj_field->setOrderNr($i_idx);
  1342.                 if ($debugechoDebugLine(__FILE__,__LINE__,"setting moveField (".$obj_field->getKey()."sortOrder to $i_idx");
  1343.                 $i_idx++;
  1344.             }
  1345.  
  1346.             if ($obj_blockFld->getKey(!= $obj_field->getKey())
  1347.             {
  1348.                 if ($debug && ($obj_blockFld->getOrderNr(!= $i_idx)) echoDebugLine(__FILE__,__LINE__,"setting field (".$obj_field->getKey()."sortOrder to $i_idx");
  1349.                 $obj_blockFld->setOrderNr($i_idx);
  1350.                 $arr_tmp[$i_idx]=&$obj_blockFld;
  1351.                 $i_idx++;
  1352.             }
  1353.         }
  1354.  
  1355.         if ($obj_field->getOrderNr($i_idx)
  1356.         {
  1357.             if ($debugechoDebugLine(__FILE__,__LINE__,"index $i_idx not found in block");
  1358.             $arr_tmp[$i_idx]=&$obj_field;
  1359.             $obj_field->setOrderNr($i_idx);
  1360.         }
  1361.  
  1362.         $this->myFields=$arr_tmp;
  1363.         return True;
  1364.     }
  1365.  
  1366.  
  1367.  
  1368.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1369.     // show / rights
  1370.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1371.  
  1372.     /**
  1373.       * checks if we have a field in $scope
  1374.       *
  1375.       * @param string $scope 
  1376.       * @param boolean $debug 
  1377.       *
  1378.       * @return boolean 
  1379.       */
  1380.     function hasFieldInScope($scope,$debug=False)
  1381.     {
  1382.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::hasFieldInScope($scope)");
  1383.  
  1384.         foreach($this->myFields as &$obj_fld)
  1385.         {
  1386.             if (!$obj_fld->isHidden($scope)) return True;
  1387.         }
  1388.         return False;
  1389.     }
  1390.  
  1391.  
  1392.     /**
  1393.       * returns if the block is to show in $mode
  1394.       * checks $this->show.... and FRB_GROUP_...
  1395.       *
  1396.       * @param int $mode 
  1397.       * @param boolean $debug 
  1398.       *
  1399.       * @return boolean 
  1400.       * @access public
  1401.       *
  1402.       */
  1403.     function isToShow($mode,$debug=False)
  1404.     {
  1405.         global $OCSP_OBJ;
  1406.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FORM_BLOCK::isToShow($mode[".$this->getName()."|".$this->getId()."]");
  1407.         if (!$this->fieldsLoaded)
  1408.         {
  1409.             $this->getFields(-1,False)// to load $this->myFields
  1410.         }
  1411.  
  1412.         switch($mode)
  1413.         {
  1414.             case FRM_MODE_LIST:
  1415.                 if (!intval($this->getId()) && sizeof($this->myFields))
  1416.                 {
  1417.                     return $this->hasFieldInScope('list',$debug);
  1418.                 else if (isset($this->FRB_SHOW_LIST&& intval($this->FRB_SHOW_LIST)) {
  1419.                     if (intval($this->FRB_GROUP_SHOW))
  1420.                     {
  1421.                         return OCSP_OBJ::currentUser()->isGroupMember(intval($this->FRB_GROUP_SHOW));
  1422.                     else {
  1423.                         return True;
  1424.                     }
  1425.                 else {
  1426.                     return False;
  1427.                 }
  1428.             case FRM_MODE_NEW:
  1429.                 if ($debugechoDebugLine(__FILE__,__LINE__,"MODE NEW: FRB_SHOW_NEW = " $this->FRB_SHOW_NEW);
  1430.                 if (!intval($this->getId()) && sizeof($this->myFields))
  1431.                 {
  1432.                     return $this->hasFieldInScope('form',$debug);
  1433.                 else if (isset($this->FRB_SHOW_NEW&& intval($this->FRB_SHOW_NEW)) {
  1434.                     if (isset($this->FRB_GROUP_NEW&& intval($this->FRB_GROUP_NEW))
  1435.                     {
  1436.                         return OCSP_OBJ::currentUser()->isGroupMember(intval($this->FRB_GROUP_NEW));
  1437.                     else {
  1438.                         return $this->hasFieldInScope('form',$debug);
  1439.                     }
  1440.                 else {
  1441.                     return False;
  1442.                 }
  1443.                                 
  1444.             case FRM_MODE_COPY:
  1445.                 if (!intval($this->getId()) && sizeof($this->myFields))
  1446.                 {
  1447.                     return $this->hasFieldInScope('form',$debug);
  1448.                 else if (intval($this->FRB_SHOW_COPY)) {
  1449.                     if (isset($this->FRB_GROUP_NEW&& intval($this->FRB_GROUP_NEW))
  1450.                     {
  1451.                         return OCSP_OBJ::currentUser()->isGroupMember(intval($this->FRB_GROUP_NEW));
  1452.                     else {
  1453.                         return True;
  1454.                     }
  1455.                 else {
  1456.                     return False;
  1457.                 }
  1458.             case FRM_MODE_EDIT:            
  1459.                 if ($debugechoDebugLine(__FILE__,__LINE__,"FRM_MODE_EDIT:");
  1460.                 if (!intval($this->getId()))
  1461.                 {
  1462.                     return $this->hasFieldInScope('form',$debug);
  1463.                 else if (intval($this->FRB_SHOW_EDIT)) {
  1464.                     if ((intval($this->FRB_GROUP_EDIT)) && (!OCSP_OBJ::currentUser()->isGroupMember(intval($this->FRB_GROUP_EDIT))))
  1465.                     {
  1466.                         if ($debugechoDebugLine(__FILE__,__LINE__,"GROUP_EDIT: ".$this->FRB_GROUP_EDIT." return <strong>False</strong>");
  1467.                     }
  1468.                     $b_ret=$this->hasFieldInScope('form',$debug);
  1469.                     if ($debugechoDebugLine(__FILE__,__LINE__,"hasFieldInScope: return <strong>".($b_ret "True" "False")."</strong>");
  1470.                     return $b_ret;
  1471.                 else {
  1472.                     if ($debugechoDebugLine(__FILE__,__LINE__,"SHOW_EDIT: ".$this->FRB_SHOW_EDIT." return <strong>False</strong>");
  1473.                     return False;
  1474.                 }
  1475.                 break;
  1476.             case FRM_MODE_DELETE:
  1477.                 if ($debugechoDebugLine(__FILE__,__LINE__,"FRM_MODE_EDIT:");
  1478.                 if (!intval($this->getId()))
  1479.                 {
  1480.                     return $this->hasFieldInScope('form',$debug);
  1481.                 else if (intval($this->FRB_SHOW_DELETE)) {
  1482.                     $b_ret=$this->hasFieldInScope('form',$debug);
  1483.                     if ($debugechoDebugLine(__FILE__,__LINE__,"hasFieldInScope: return <strong>".($b_ret "True" "False")."</strong>");
  1484.                     return $b_ret;
  1485.                 else {
  1486.                     if ($debugechoDebugLine(__FILE__,__LINE__,"SHOW_DELETE: ".$this->FRB_SHOW_DELETE." return <strong>False</strong>");
  1487.                     return False;
  1488.                 }
  1489.                 break;
  1490.             case FRM_MODE_READONLY:
  1491.                 if ($this->FRB_SHOW_RO)
  1492.                 {
  1493.                     return $this->hasFieldInScope('form',$debug);
  1494.                 else 
  1495.                     False;
  1496.                 }
  1497.                 break;
  1498.             default:
  1499.                 ocsp_logError(__FILE__,__LINE__,"mode $mode not implemented in isToShow()");
  1500.                 return True;
  1501.         }
  1502.     }
  1503.  
  1504. // end of OCSP_FORM_BLOCK
  1505. ?>

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