Source for file OCSP_FRMCONTR_FORM.phpclass

Documentation is available at OCSP_FRMCONTR_FORM.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_FRMCONTR_FORM.phpclass
  4.   *
  5.   *
  6.   * @project    Open CSP-Management
  7.   * @package    forms
  8.   * @category   dbms_form
  9.   *
  10.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @since  pk-07-07-02
  14.   * @version $Id: OCSP_FRMCONTR_FORM.phpclass,v 1.51 2008/12/17 16:28:51 peterkrebs Exp $
  15.   */
  16.  
  17. if (!class_exists('OCSP_FRMCONTR'))
  18. {
  19.     require_once dirname(__FILE__)_OCSP_DIRSEP_ "OCSP_FRMCONTR.phpclass";
  20. }    
  21.  
  22.  
  23. /**
  24.   * class OCSP_FRMCONTR_FORM
  25.   *
  26.   * @project    Open CSP-Management
  27.   * @package    forms
  28.   * @category   dbms_form
  29.   *
  30.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  31.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   * @since  pk-07-07-02
  34.   * @version $Id: OCSP_FRMCONTR_FORM.phpclass,v 1.51 2008/12/17 16:28:51 peterkrebs Exp $
  35.   */
  36.     extends OCSP_FRMCONTR
  37. {
  38.  
  39.     /*** class constants  --------------------------------------------- */
  40.  
  41.     /**
  42.       * @constant string CLASS_SRC_FILE
  43.       * @since pk-08-02-04
  44.       */
  45.     const CLASS_SRC_FILE = __FILE__;           
  46.     
  47.     /*** Aggregations: */
  48.  
  49.     /*** Compositions: */
  50.  
  51.     /*** Attributes: */
  52.  
  53.     /**
  54.       * @var string $myMethod 
  55.       * @access protected
  56.       */
  57.     protected $myMethod="";
  58.  
  59.     /**
  60.       * if $this->myNextUrl starts with js: a javascript code will be evaluated else it is assumed to be a norm link
  61.       * @var string $myNextUrl 
  62.       * @access protected
  63.       */
  64.     protected $myNextUrl="";
  65.  
  66.     /**
  67.       * @var string $myTarget 
  68.       * @access protected
  69.       */
  70.     protected $myTarget="";
  71.  
  72.     /**
  73.       * js events for 'fldName' and 'fldValue
  74.       * @var array $rmFldEvents 
  75.       * @access protected
  76.       * @since pk-07-09-23
  77.       */
  78.     protected $frmFldEvents=array();
  79.     
  80.     /**
  81.      * returns an array with js required
  82.      * 
  83.      */
  84.     protected $myJsRequirements = array();
  85.  
  86.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  87.     // init methods
  88.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  89.  
  90.  
  91.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  92.     // getter/setter methods
  93.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  94.  
  95.  
  96.     /**
  97.       * @param string $aCmd 
  98.       */
  99.     function setBackCmd($aCmd)
  100.     {
  101.         $this->myBackCmd=$aCmd;
  102.     }
  103.  
  104.     /**
  105.       *
  106.       * @param string $aUrl 
  107.       */
  108.     function setNextUrl($aUrl)
  109.     {
  110.         $this->myNextUrl=$aUrl;
  111.     }
  112.  
  113.     /**
  114.       * if next url is not set tries to get it from $_REQUEST
  115.       * the url is parsed with $this->curRow
  116.       *
  117.       * @param boolean $parseTmpl 
  118.       * @param boolean $debug 
  119.       * 
  120.       * @return string 
  121.       */
  122.     function getNextUrl($parseTmpl=True,$debug=False)
  123.     {
  124.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getNextUrl()");
  125.         if (empty($this->myNextUrl))
  126.         {
  127.             if (isset($_REQUEST[$this->myForm->getName().'_NEXT']&& !empty($_REQUEST[$this->myForm->getName().'_NEXT']))
  128.             {
  129.                 $str_ret=base64_decode($_REQUEST[$this->myForm->getName().'_NEXT']);
  130.                 if ($debugechoDebugMethod(__FILE__,__LINE__,"using request: " $str_ret);
  131.             else {
  132.                 $str_ret=$_SERVER['SCRIPT_NAME'];
  133.             }
  134.         else {
  135.             $str_ret=$this->myNextUrl;
  136.         }
  137.  
  138.         if ($debugechoDebugLine(__FILE__,__LINE__,"curRow: <pre>" print_r($this->curRow,true"</pre>" $str_ret);
  139.         if ($parseTmpl)
  140.         {
  141.             pcf_require_class('OCSP_TEMPLATE',"common/");
  142.             return OCSP_TEMPLATE::parse($str_ret,$this->curRow,$debug);
  143.         else {
  144.             return $str_ret;
  145.         }
  146.     }
  147.    
  148.     /**
  149.       * @param strign $aTarget 
  150.       */
  151.     function setMyTarget($aTarget)
  152.     {
  153.         $this->myTarget=$aTarget;
  154.     }
  155.  
  156.     /**
  157.       * @return string 
  158.       */
  159.     function getMyTarget()
  160.     {
  161.         return $this->myTarget;
  162.     }
  163.  
  164.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  165.     // form db methods
  166.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167.  
  168.     /**
  169.      * sets the database values of the forms tableobject
  170.      *
  171.      * @param boolean $debug 
  172.      * 
  173.      * @return boolean 
  174.      * 
  175.      * @since pk-08-03-07
  176.      */
  177.     protected function setTblObjDBVal($debug=False)
  178.     {
  179.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::setTblObjDBVal()");
  180.         
  181.         if ($obj_tblObj $this->getMyForm()->getMyTblObj(True))
  182.         {            
  183.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$obj_tblObj=" get_class($obj_tblObj"<pre>" print_r($this->curRow,True"</pre>");
  184.                         
  185.             if ($this->getMyForm()->getFrmMode(== FRM_MODE_EDIT)
  186.             {
  187.                 if ($obj_tblObj->populateFromValues($this->curRow,$debug))
  188.                 {
  189.                     if ($obj_tblObj->hasObjVals())
  190.                     {
  191.                         $obj_tblObj->populateObjVals($debug);
  192.                     }
  193.                 }
  194.                 
  195.             }
  196.             
  197.             //if ($arr_fields = $this->myForm->getFields($obj_tblObj->getMyTable()))
  198.             if ($arr_fields $this->myForm->getFields("",False,$this->myForm->getFrmMode())) // <pk-08-03-31 /> <pk-08-11-06 />
  199.             {
  200.                     
  201.                 $arr_tblObjVals array();
  202.                 foreach($this->curRow as $str_col => $mix_val)
  203.                 {
  204.                     if ($obj_fld $this->myForm->getField($str_col,$obj_tblObj->getMyTable(),-1))
  205.                     {
  206.                         $arr_tblObjVals[$str_col$this->curRow[$str_col];
  207.                         unset($arr_fields[$obj_fld->getKey()]);
  208.                     else if ($debug{
  209.                         echoDebugLine(__FILE__,__LINE__,"<strong>" $str_col "</strong> not in form");
  210.                     }
  211.                 }
  212.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<pre>" print_r(array_keys($arr_fields),True"</pre>");
  213.  
  214.                 $obj_tblObj->setDBVal($arr_tblObjVals,$debug);
  215.                 //$obj_tblObj->setDBRow()
  216.                 
  217.                 if (($arr_frmTables $this->myForm->getTables()) && (sizeof($arr_frmTables1))
  218.                 {
  219.                     switch($this->myForm->getFrmMode())
  220.                     {
  221.                         case FRM_MODE_NEW:
  222.                         case FRM_MODE_EDIT:
  223.                         case FRM_MODE_COPY:
  224.                             $cmd_lnkTbl _OCSP_DBCMD_REPLACE_;
  225.                             break;
  226.                         case FRM_MODE_DELETE:
  227.                             $cmd_lnkTbl _OCSP_DBCMD_DELETE_;
  228.                             break;                            
  229.                         default:
  230.                             $cmd_lnkTbl False;
  231.                                                             
  232.                     }
  233.  
  234.                     foreach($arr_frmTables as $str_table)
  235.                     {
  236.                         if ($str_table != $obj_tblObj->getMyTable())
  237.                         {
  238.                             if ($arr_fields $this->myForm->getFields($str_table))
  239.                             {
  240.                                 $arr_subTblVals=array();
  241.                                 foreach($arr_fields as $obj_fld)
  242.                                 {
  243.                                     if (isset($this->curRow[$obj_fld->getName()]))
  244.                                     {
  245.                                         $arr_subTblVals[$obj_fld->getName()$this->curRow[$obj_fld->getName()];                            
  246.                                     }
  247.                                 }
  248.                                 if (sizeof($arr_subTblVals))
  249.                                 {
  250.                                     $obj_tblObj->setLinkedTableRow($str_table,$cmd_lnkTbl,$arr_subTblVals,$debug);
  251.                                 }
  252.                             }
  253.                         }
  254.                     }
  255.                 }
  256.                 return True;
  257.             }
  258.         }        
  259.         return False;
  260.     }
  261.     
  262.     /**
  263.      * sets $this->myFilter from the values
  264.      *
  265.      * @param boolean $debug 
  266.      */
  267.     protected function getFilterFromValues($debug=False)
  268.     {
  269.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getFilterFromValues()");
  270.         
  271.         if ($arr_tblKeys=$this->myForm->getKeyFields())
  272.            {                
  273.             foreach($arr_tblKeys as $str_tbl => $arr_keys)
  274.             {
  275.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Table$str_tbl</p>");
  276.                 if (is_array($arr_keys))
  277.                 {
  278.                     foreach($arr_keys as &$obj_fld)
  279.                     {
  280.                         if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Col: ".$obj_fld->getDBColName(False)."</p>");
  281.                         if (!isset($this->myFilter[$obj_fld->getDBColName(False)]))
  282.                         {
  283.                             if (isset($this->curRow[$obj_fld->getDBColName(False)]))
  284.                             {
  285.                                 $this->myFilter[$obj_fld->getDBColName(False)]=$this->curRow[$obj_fld->getDBColName(False)];
  286.                             }
  287.                         }
  288.                     }
  289.                 }
  290.             }
  291.         }          
  292.     }
  293.     
  294.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  295.     // jOCSP elementes
  296.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  297.     
  298.     /**
  299.      * returns the javas script to load jOCSP framework
  300.      *
  301.      * @param boolean $debug 
  302.      * 
  303.      * @global array $OCSP_CONF 
  304.      * 
  305.      * @return string (js)
  306.      */
  307.     public function jOCSP_getFormInitCmd($debug=False)
  308.     {
  309.         if ($debugechoDebugMethod(__FILE__,get_class($this),'OCSP_FRMCONTR_FORM::jOCSP_getFormInitCmd()');
  310.  
  311.         if (!$this->rowIsPopulated())
  312.         {
  313.             $this->populateRow(Null,$debug);
  314.         }        
  315.         
  316.         $str_js "
  317.  
  318.                 // ---------------------------------------------
  319.                 // OCSP_FRMCONTR_FORM::jOCSP_getFormInitCmd
  320.                 // ---------------------------------------------
  321.                 
  322.                 var frmDesc = {
  323.                         frmId: " $this->myForm->getId(",
  324.                         domId: '" $this->getFormHTMLId(."',
  325.                         myName: '" $this->getFormHTMLId(."',
  326.                         myAction: '" pcf_js_escape($this->getActionURL()) ."'                        
  327.                     }
  328.                                         
  329.                 if (typeof(window.jOCSP.ocspFormObj) == \"undefined\") 
  330.                 {                
  331.                     jOCSP.requestScript('" self::getConf('SYSTEMURL'"jOCSP/jOCSP_form.js',true,0);
  332.                 }
  333.                 
  334.                 if (typeof(window.jQuery.fn.ajaxSubmit) == \"undefined\")
  335.                 {
  336.                     jOCSP.requestScript('" self::getConf('SYSTEMURL'"javascript/jquery/jquery.form.js',false,1000);
  337.                 }
  338.  
  339.                 if (!jOCSP.getFormByHash['" $this->jOCSP_getfrmHash("'])
  340.                 {
  341.                     jOCSP.initForm('" $this->jOCSP_getfrmHash("',frmDesc);
  342.                 }
  343.             ";
  344.         
  345.         $arr_fields $this->myForm->getFields();
  346.         
  347.         $arr_requirements array();
  348.         
  349.         foreach($arr_fields as &$obj_fld)
  350.         {
  351.             $obj_fld->setMyForm($this->myForm);
  352.             $obj_fld->setControll($this);
  353.             
  354.             if (($arr_jsReq $obj_fld->jOCSP_getRequiredModules()) && sizeof($arr_jsReq))
  355.             {
  356.                 if (is_array($arr_jsReq))
  357.                 {
  358.                     foreach($arr_jsReq as $arr_req)
  359.                     {
  360.                         if (is_array($arr_req&& isset($arr_req['CLASS']))
  361.                         {                
  362.                             if (!isset($arr_requirements[$arr_req['CLASS']]))
  363.                             {
  364.                                 $arr_requirements[$arr_req['CLASS']] $arr_req['SRC'];
  365.                             }
  366.                         }
  367.                     }
  368.                 else {
  369.                     echoDebugLine(__FILE__,__LINE__,"<p>Field:" $obj_fld->getName("(" get_class($obj_fld")</p><pre>" print_r($arr_jsReq,True"</pre>");
  370.                 }
  371.             }            
  372.         }
  373.         
  374.         $str_js .= "\n\n// form requirements ---------------------------\n";
  375.         foreach($arr_requirements as $str_class => $str_src)
  376.         {
  377.             if (!empty($str_src))
  378.             {
  379.                 $str_js.="
  380.                     if (typeof({$str_class}) == 'undefined') 
  381.                     {
  382.                         jOCSP.requestScript('{$str_src}');
  383.                     }
  384.                 ";
  385.             }
  386.         }
  387.         $str_js .= "// done form requirements ---------------------------\n\n";
  388.         
  389.         
  390.         return $str_js;
  391.     }
  392.     
  393.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  394.     // controll elementes
  395.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  396.  
  397.     // javascript to add (after </form>);
  398.  
  399.     /**
  400.       * @param boolean $debug 
  401.       * @return string 
  402.       */
  403.     function getFormJavaScript($debug=False)
  404.     {
  405.         return "";
  406.     }
  407.  
  408.     // form tag <form ...>
  409.  
  410.     /**
  411.       * returns the form html id/name
  412.       *
  413.       * @param boolean $debug 
  414.       * @return string the form id
  415.       * @access public
  416.       */
  417.     function getFormHTMLId($debug=False)
  418.     {
  419.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getFormHTMLId()");
  420.         return $this->myForm->getHTMLname();
  421.     }
  422.  
  423.     /**
  424.       * @param int $aMode 
  425.       * @param boolean $debug 
  426.       *
  427.       * @return string 
  428.       *
  429.       * @access public
  430.       */
  431.     function getFormEvents($aMode=FRM_MODE_READONLY,$debug=False)
  432.     {
  433.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getFormEvents()");
  434.  
  435.         $this->myForm->setFrmMode($aMode);
  436.         $str_ret "";
  437.  
  438.         if ($str_aURL=$this->getActionURL())
  439.         {
  440.             $str_ret.=" action=\"".$str_aURL."\"";
  441.         }
  442.  
  443.         if (!empty($this->myMethod))
  444.         {
  445.             $str_ret.=" method=\"".$this->myMethod."\"";
  446.         else {
  447.             $str_ret.=" method=\"post\"";
  448.         }
  449.  
  450.         if (!empty($this->myTarget))
  451.         {
  452.             $str_ret.=" target=\"".$this->myTarget."\"";
  453.         }
  454.         
  455.         $str_ret .= " accept-charset=\"utf-8\"";
  456.         return $str_ret;
  457.     }
  458.  
  459.     
  460.  
  461.     
  462.     /**
  463.      * returns if the form has button commands
  464.      * 
  465.      * checks $this->myCommands['_FORM_'] for values and the form mode
  466.      * 
  467.      * @param boolean $debug 
  468.      *
  469.      * @return boolean 
  470.      */
  471.     function hasCmdButtons($debug=False)
  472.     {
  473.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::hasCmdButtons()");
  474.         if (isset($this->myCommands['_FORM_']&& is_array($this->myCommands['_FORM_']&& sizeof($this->myCommands['_FORM_']))
  475.         {
  476.             return TRUE;
  477.         }
  478.         switch($this->myForm->getFrmMode())
  479.         {
  480.             case FRM_MODE_NEW:
  481.             case FRM_MODE_EDIT:
  482.             case FRM_MODE_COPY:
  483.             case FRM_MODE_DELETE:
  484.                 return TRUE;
  485.         }
  486.         return False;
  487.  
  488.     }
  489.  
  490.     /**
  491.       * @param boolean $debug 
  492.       *
  493.       * @global array $OCSP_OBJ 
  494.       * @global array $OCSP_CONF 
  495.       *
  496.       * @access public
  497.       */
  498.     function getFormCmdButtons($debug=False)
  499.     {
  500.         global $OCSP_OBJ,$OCSP_CONF;
  501.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getFormCmdButtons()");
  502.  
  503.         $str_ret="";
  504.  
  505.         if (!empty($this->myBackCmd))
  506.         {
  507.             $str_ret.="<a onClick=\"".$this->myBackCmd."\">";
  508.             $str_ret.=$this->myView->getButton('BACK');
  509.             $str_ret.="</a>";
  510.         }
  511.  
  512.  
  513.         switch($this->myForm->getFrmMode())
  514.         {
  515.             case FRM_MODE_NEW:
  516.             case FRM_MODE_EDIT:
  517.             case FRM_MODE_COPY:
  518.                 if (!isset($this->myCommands['_FORM_']['SAVE']))
  519.                 {
  520.                     $str_ret.=$this->getSubmitButton();
  521.                 }
  522.                 if (!isset($this->myCommands['_FORM_']['RESET']))
  523.                 {
  524.                     $str_ret.=$this->getResetButton();
  525.                 }
  526.                 break;
  527.             case FRM_MODE_DELETE:
  528.                 if (!isset($this->myCommands['_FORM_']['DELETE']))
  529.                 {
  530.                     $str_ret.=$this->getSubmitButton();
  531.                 }
  532.                 break;
  533.  
  534.         }
  535.  
  536.         if (isset($this->myCommands['_FORM_']&& is_array($this->myCommands['_FORM_']))
  537.         {
  538.             foreach($this->myCommands['_FORM_'as $str_cmd => $arr_settings)
  539.             {
  540.                 switch($arr_settings['TYPE'])
  541.                 {
  542.                     case _OCSP_FRMCMDTYPE_BTNJS_:
  543.  
  544.                         $str_ret.="<a onClick=\"".pcf_tmpl_parse($arr_settings['CODE'],$this->curRow)."\">";
  545.                         $str_ret.=$this->myView->getButton($str_cmd);
  546.                         $str_ret.="</a>";
  547.                         break;
  548.                     case _OCSP_FRMCMDTYPE_BTNLINK_:
  549.                         $str_ret.="<a href=\"".pcf_tmpl_parse($arr_settings['CODE'],$this->curRow)."\">";
  550.                         $str_ret.=$this->myView->getButton($str_cmd);
  551.                         $str_ret.="</a>";
  552.                         break;
  553.                 }
  554.             }
  555.         }        
  556.         
  557.         if (OCSP_OBJ::currentUser()->isGroupMember(_OCSP_GROUP_DBMS_))
  558.         {
  559.             $str_ret.="&nbsp;&nbsp;<a href=\"" OCSP_OBJ::getConf('ADMINURL'"dbms/form.php?FRM_ID=".$this->myForm->getId()."\" target=\"_blank\">
  560.                         <img src=\"{$OCSP_CONF['SYSIMGURL']}/icons-22x22/editConstruct.gif\" class=\"button\" /></a>";
  561.         }
  562.  
  563.         $str_ret=$this->myView->getButtonOuterDiv($debug).$str_ret."</div>\n";
  564.         return "\n".$str_ret;
  565.     }
  566.  
  567.     /**
  568.       * @param boolean $debug 
  569.       *  
  570.       * @return string 
  571.       */
  572.     function getSubmitButton($debug=False)
  573.     {
  574.         $str_ret=$this->myView->getButtonOuterDiv($debug);
  575.         $str_ret.="<a href=\"#\" onClick=\"document.forms['".$this->getFormHTMLId()."'].submit();\">";
  576.         $str_ret.=$this->myView->getButton('SAVE');
  577.         $str_ret.="</a></div>\n";
  578.         return $str_ret;
  579.     }
  580.  
  581.     /**
  582.      * @param boolean $debug 
  583.      * 
  584.      * @return string 
  585.      */
  586.     function getResetButton($debug=False)
  587.     {
  588.         $str_ret=$this->myView->getButtonOuterDiv($debug);
  589.         $str_ret.="<a href=\"#\" onClick=\"document.forms['".$this->getFormHTMLId()."'].reset();\">";
  590.         $str_ret.=$this->myView->getButton('RESET');
  591.         $str_ret.="</a></div>\n";
  592.         return $str_ret;
  593.     }
  594.  
  595.     /**
  596.      * returns hiddenfields identifying the form and the tableobject
  597.      * 
  598.      * @param boolean $debug 
  599.      * 
  600.      * @return string 
  601.      * 
  602.      * @version pk-08-06-26
  603.      */
  604.     function getFormCmdFields($debug=False)
  605.     {
  606.         ob_start();
  607.         
  608.         $str_ret="";
  609.  
  610.         if (($this->myForm->getFrmMode(!= FRM_MODE_SEARCH&& (!($this->rowPopulateTS)))
  611.         {
  612.             if ($this->myForm->getFrmMode(!= FRM_MODE_NEW)
  613.             {
  614.                 $this->populateRow(NULL,$debug)// ensure the row is populated
  615.             else {
  616.                 $this->getDefaultValues(TRUE,$debug);                
  617.             }
  618.         }
  619.  
  620.         if ($debug
  621.             $str_ret.="<p>Filter: </p><pre>".print_r($this->myFilter,TRUE)."</pre>";
  622.         
  623.         if (
  624.             (($this->myForm->getFrmMode(== FRM_MODE_EDIT|| ($this->myForm->getFrmMode(== FRM_MODE_DELETE))
  625.             && (!sizeof($this->myFilter))
  626.            // empty filter -> try to get it from primary keys
  627.         {
  628.             $this->getFilterFromValues($debug);           
  629.         }
  630.         
  631.         if ($debug
  632.             $str_ret.="<p>Filter: </p><pre>".print_r($this->myFilter,TRUE)."</pre>";
  633.  
  634.         $arr_ocspFormSettings=array(
  635.                 'ID'        => $this->myForm->getId(),
  636.                 'MODE'      => $this->myForm->getFrmMode(),
  637.                 'FILTER'    => $this->myFilter,
  638.                 'CLASS'     => get_class($this),
  639.                 'USER_ID'    => OCSP_OBJ::currentUser()->getId()
  640.             );
  641.  
  642.         $str_ret.="\n\n<!-- ".get_class($this)."::getFormCmdFields() -->\n";
  643.         $str_ret.="<input type=\"hidden\" name=\"FRMHTMLNAME\" value=\"".$this->myForm->getHTMLname()."\" />\n";
  644.         $str_ret.="<input type=\"hidden\" name=\"DBMSFORMID\"  value=\"".$this->myForm->getId()."\" />\n";
  645.         $str_ret.="<input type=\"hidden\" name=\"OCSP_FORM_SETTING_CRYPT\" value=\"".OCSP_SESSION::getInstance()->encrypt(serialize($arr_ocspFormSettings))."\" />\n";
  646.         $str_ret.="<input type=\"hidden\" name=\"FRMMODE\" value=\"".$this->myForm->getFrmMode()."\" />\n";
  647.  
  648.         if (!empty($this->myActionURL))
  649.         {
  650.             $str_ret.="<input type=\"hidden\" name=\"FRMACTION\" value=\"".base64_encode($this->getActionURL())."\" />\n";
  651.         }
  652.  
  653.         $str_ret.="<input type=\"hidden\" name=\"FRMARRAYNAME\" value=\"".$this->myForm->getDataArrName()."\" />\n";
  654.         
  655.         if (!empty($this->myTarget))
  656.         {
  657.             $str_ret.="<input type=\"hidden\" name=\"FRMTARGET\" value=\"".base64_encode($this->myTarget)."\" />\n";
  658.         }
  659.         $str_ret.="<input type=\"hidden\" name=\"".$this->myForm->getName()."_NEXT\" value=\"".base64_encode($this->getNextUrl(False))."\" />\n";
  660.         $str_ret.="<input type=\"hidden\" name=\"".$this->myForm->getName()."_REQUEST\" value=\"".OCSP_SESSION::getInstance()->encrypt($_SERVER['REQUEST_URI'])."\" />\n";
  661.         $str_ret.="<input type=\"hidden\" name=\"SESSID\" value=\"".session_id()."\" />\n";
  662.         //$str_ret.="<input type=\"hidden\" name=\"RELOAD\" value=\"0\" />\n";
  663.  
  664.         if ($this->myForm->getFrmMode()==FRM_MODE_DELETE)
  665.         {                        
  666.             $this->populateRow(NULL,$debug)// ensure we have DB values for deletekey
  667.             if ($obj_tblObj=$this->myForm->getMyTblObj(False,$debug))
  668.             {                
  669.                 $str_serKey print_r($obj_tblObj->getDBRow(),True);;                
  670.                 if ($debug$str_ret.="<p>" basename(__FILE__" Line: " . __LINE__ . "</p><p>DeleteKey " md5($str_serKey"</p><pre>{$str_serKey}</pre>";
  671.                 $str_ret.="<input type=\"hidden\" name=\"DELKEY\" value=\"" md5($str_serKey"\" />\n";                
  672.             else {
  673.                 if ($debug$str_ret.="<p>DeleteKey ".md5(serialize($this->curRow))."</p><pre>" print_r($this->curRow,True"</pre>";
  674.                 $str_ret.="<input type=\"hidden\" name=\"DELKEY\" value=\"".md5(serialize($this->curRow))."\" />\n";
  675.             }
  676.         }
  677.  
  678.         //$debug=True;echoDebugLine(__FILE__,__LINE__,"debug on");        
  679.         if (($obj_tblObj=$this->myForm->getMyTblObj(False,$debug)) && $this->myForm->getTblObjClass())
  680.         {
  681.             if ($debugechoDebugLine(__FILE__,__LINE__,"class: " $this->myForm->getTblObjClass(" include: " $this->myForm->getTblObjInc());
  682.             $str_ret.="<input type=\"hidden\" name=\"OCSP_FORM_TBLOBJCLASS\" value=\"".OCSP_SESSION::getInstance()->encrypt($this->myForm->getTblObjClass())."\" />\n";
  683.             $str_ret.="<input type=\"hidden\" name=\"OCSP_FORM_TBLOBJINC\" value=\"".OCSP_SESSION::getInstance()->encrypt($this->myForm->getTblObjInc())."\" />\n";
  684.         }
  685.  
  686.         if (get_class($this->myForm!= 'OCSP_FORM')
  687.         {
  688.             $str_ret.="<input type=\"hidden\" name=\"OCSP_FORM_CLASS\" value=\"".OCSP_SESSION::getInstance()->encrypt(get_class($this->myForm))."\" />\n";
  689.             $str_ret.="<input type=\"hidden\" name=\"OCSP_FORM_INC\" value=\"".OCSP_SESSION::getInstance()->encrypt($this->myForm->get_mySourceFile())."\" />\n";
  690.          }
  691.             
  692.          // <pk-08-06-26>
  693.          if ($arr_formCmds $this->myForm->getFormCmdFields($debug))
  694.         {
  695.             if (is_array($arr_formCmds&& sizeof($arr_formCmds))
  696.             {
  697.                 $str_ret.="<input type=\"hidden\" name=\"".get_class($this->myForm)."_CMDS\" value=\"".OCSP_SESSION::getInstance()->encrypt(serialize($arr_formCmds))."\" />\n";
  698.             }
  699.          }            
  700.          
  701.          //$str_ret .= dirname(__FILE__) . " Line: " . __LINE__ . "<p>PassThrough:</p><pre>" . print_r($this->myForm->getPassThroughFields(),True) . "</pre>";
  702.          if ($arr_passThrough $this->myForm->getPassThroughFields())
  703.          {
  704.              foreach($arr_passThrough as $str_col => $mix_value);
  705.              {
  706.                  $str_ret.="<input type=\"hidden\" name=\"PASSTHROUGH[" $str_col "]\" value=\"" OCSP_SESSION::getInstance()->encrypt(serialize($mix_value)) "\" />\n";
  707.              }
  708.          }
  709.          
  710.          // </pk-08-06-26>
  711.          
  712.          if ($debug$str_ret .= ob_get_contents();
  713.          ob_end_clean();
  714.          
  715.         return "\n".$str_ret;
  716.     }
  717.     
  718.     
  719.     // -------------------------------------------
  720.     // fields
  721.     // -------------------------------------------
  722.     
  723.     /**
  724.      * returns the field value set in $this->curRow
  725.      *
  726.      * @param DBMS_FIELD $aField 
  727.      * @param int $fldMode 
  728.      * @param boolean $debug 
  729.      * 
  730.      * @return mixed 
  731.      * 
  732.      * @since pk-08-09-09
  733.      */
  734.     public function getFieldValue(&$aField,$fldMode=-1,$debug=False)
  735.     {
  736.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getFieldValue(" $aField->getName(")");
  737.         if (!$this->rowIsPopulated())
  738.         {
  739.             $this->populateRow(Null,$debug);
  740.         }
  741.         
  742.         // seting curRow to global array
  743.         // enableing the fields to access other row values
  744.         
  745.         $str_dataArrName $this->getMyForm()->getDataArrName();
  746.         global ${$str_dataArrName};
  747.         ${$str_dataArrName$this->curRow;        
  748.         $aField->setDataArrName($str_dataArrName);
  749.         
  750.         $aField->setControl($this);
  751.                
  752.         if ($fldMode == -1)
  753.         {
  754.             $fldMode=$this->myForm->getFrmMode();
  755.         }         
  756.         
  757.         if (isset($this->curRow[$aField->getName()]))
  758.         {
  759.             $m_val=$this->curRow[$aField->getName()];
  760.         else {
  761.             if ($fldMode == FRM_MODE_EDIT)
  762.             {
  763.                 if ($debugocsp_logError(__FILE__,__LINE__,"Object: ".get_class($this)." value for ".$aField->getName()." not set",E_NOTICE);
  764.             }
  765.             $m_val=Null;
  766.         }
  767.         
  768.         return $m_val;
  769.     }
  770.  
  771.         
  772.     /**
  773.      * returns the html tag of a field
  774.      * 
  775.      * @param DBMS_FIELD $aField 
  776.      * @param boolean $debug 
  777.      * @param int $fldMode 
  778.      *
  779.      * @global ${$this->myForm->getDataArrName()} 
  780.      *
  781.      * @version pk-07-11-29 $fldMode added
  782.      * @version pk-08-02-06 jOCSP
  783.      * 
  784.      * @return string (html)
  785.      * 
  786.      */
  787.     function getFieldTag(&$aField,$debug=False,$fldMode=-1)
  788.     {
  789.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getFieldTag({$aField->getName()})");
  790.         
  791.         if ($fldMode == -1)
  792.         {
  793.             $fldMode=$this->getMyForm()->getFrmMode();
  794.         
  795.         
  796.         $str_dataArrName $this->getMyForm()->getDataArrName();
  797.         global ${$str_dataArrName};
  798.         ${$str_dataArrName$this->curRow;        
  799.         $aField->setDataArrName($str_dataArrName);        
  800.         
  801.         $aField->setMyForm($this->getMyForm());
  802.         $aField->setControll($this);
  803.         
  804.         $m_val $this->getFieldValue($aField,$fldMode,$debug);
  805.                 
  806.         // note order of commands important for group fields        
  807.         $str_js "jOCSP.addFieldObjToFormByHash('" $this->jOCSP_getfrmHash("',".$aField->jOCSP_getFieldObj($debug).");";
  808.         $str_ret $aField->getFormFieldTag($fldMode,$m_val,$debug);
  809.         
  810.         if ($obj_ajax $this->myForm->ajax_getObj(False))
  811.         {
  812.             $obj_ajax->addJsCode($str_js);
  813.         else {
  814.             $str_ret .= "
  815.                 <script type=\"text/javascript\" language=\"javascript\">
  816.                 <!--
  817.                 " $str_js "
  818.                 // -->
  819.                 </script>
  820.                 ";
  821.         }
  822.  
  823.         return $str_ret;
  824.     }
  825.     
  826.     
  827.     // footer
  828.  
  829.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  830.     // field event methods methods
  831.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  832.  
  833.     /**
  834.       * Note: don't use unescaped " in $jsCmd
  835.       *       $jsCmd can be a template which is parsed with the current form values
  836.       *
  837.       * @param string $fldType (fldName | fldValue)
  838.       * @param string $jsEvent (js event like onClick)
  839.       * @param string $jsCmd   (js to execute on the event)
  840.       *
  841.       * @since pk-07-09-23
  842.       */
  843.     function setFieldEvent($fldType,$jsEvent,$jsCmd)
  844.     {
  845.         $this->frmFldEvents[$fldType][$jsEvent]=$jsCmd;
  846.     }
  847.  
  848.     /**
  849.       * @param string $fldType 
  850.       * @param boolean $debug 
  851.       *
  852.       * @requires pcf_templates.phpinc
  853.       *
  854.       * @return string 
  855.       */
  856.     function getFieldEvents($fldType,$debug=False)
  857.     {
  858.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getFormEvents($fldType)");
  859.         $str_ret="";
  860.         if (isset($this->frmFldEvents[$fldType]&& is_array($this->frmFldEvents[$fldType]))
  861.         {
  862.             require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_templates.phpinc";
  863.             foreach($this->frmFldEvents[$fldTypeas $str_event => $str_jsCmd)
  864.             if (!empty($str_jsCmd))
  865.             {
  866.                 $str_ret=" $str_event=\"".pcf_tmpl_parse($str_jsCmd,$this->curRow)."\"";
  867.             }
  868.         }
  869.  
  870.         return $str_ret;
  871.     }
  872.  
  873.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  874.     // db methods
  875.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  876.  
  877.     /**
  878.      * returns an arry with the database and form default values
  879.      * 
  880.      * if $asCurRow the default values are merged with none empty values in $this->curRow
  881.      * $this->rowPopulateTS is set
  882.      * 
  883.      * @param boolean $asCurRow 
  884.      * @param boolean $debug 
  885.      * 
  886.      * @return array 
  887.      * 
  888.      * @since pk-07-12-05
  889.      * @version pk-08-02-21
  890.      * 
  891.      */
  892.     function getDefaultValues($asCurRow=True,$debug=False)
  893.     {
  894.         require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_templates.phpinc";        
  895.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::getDefaultValues()");
  896.         
  897.         if ($obj_tblObj $this->myForm->getMyTblObj(True))
  898.         {
  899.             $arr_defaults $obj_tblObj->getDefaults();            
  900.             if ($asCurRow && ($this->myForm->getFrmMode(== FRM_MODE_NEW))
  901.             {                 
  902.                 // set values which are set in table object
  903.                 // <pk-08-02-21>
  904.                 $arr_objVals $obj_tblObj->getDBVal();
  905.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>table object set values:</p><pre>" print_r($arr_objVals,True"</pre>");
  906.                 
  907.                 foreach($arr_objVals as $str_colName => $mix_value)
  908.                 {
  909.                     if (!empty($mix_value)) 
  910.                     {
  911.                         $arr_defaults[$str_colName$mix_value;
  912.                     }
  913.                 }
  914.                 // </pk-08-02-21>
  915.             }
  916.         else {
  917.             $arr_defaults array();
  918.         }
  919.         
  920.         if ($debugechoDebugLine(__FILE__,__LINE__,"<p><strong>DB Defaults:</strong></p><pre>" print_r($arr_defaults,True"</pre>");
  921.         
  922.         
  923.         $arr_flds=$this->myForm->getFields();
  924.         foreach($arr_flds as &$obj_fld)
  925.         {
  926.             if ($m_default=$obj_fld->getDefaultValue())
  927.             {
  928.                 //if ($debug) echoDebugLine(__FILE__,__LINE__,"Field: " . $obj_fld->getName() . " Default: &gt;" . $m_default . "&lt;");
  929.                 $arr_defaults[$obj_fld->getName()]=$m_default;
  930.             }
  931.         }
  932.  
  933.         //if ($debug) echoDebugLine(__FILE__,__LINE__,"<p><strong>\$arr_defaults:</strong> with Form Field defaults</p><pre>" . print_r($arr_defaults,True) . "</pre>");
  934.                 
  935.         if ($asCurRow && !is_array($this->curRow)) $this->curRow=array();
  936.         foreach($arr_defaults as $s_key => $m_val)
  937.         {
  938.             $arr_defaults[$s_key]=pcf_tmpl_parse($m_val,$arr_defaults);
  939.             if ($asCurRow)
  940.             {
  941.                 if (!isset($this->curRow[$s_key]|| empty($this->curRow[$s_key]))
  942.                 {
  943.                     $this->curRow[$s_key]=$arr_defaults[$s_key];
  944.                 }
  945.             }
  946.         }
  947.  
  948.         //if ($debug) echoDebugLine(__FILE__,__LINE__,"<p><strong>\${".get_class($this)."}->curRow:</strong> with set</p><pre>" . print_r($this->curRow,True) . "</pre>");
  949.         
  950.         if ($asCurRow)
  951.         {
  952.             if (sizeof($this->myFilter))
  953.             {
  954.                 foreach($this->myFilter as $str_col => $mix_value)
  955.                 {
  956.                        if (!isset($this->curRow[$str_col]|| empty($this->curRow[$str_col]))
  957.                        {
  958.                            $this->curRow[$str_col$mix_value;
  959.                        }
  960.                 }
  961.             }
  962.             global ${$this->myForm->getDataArrName()};
  963.             ${$this->myForm->getDataArrName()}=&$this->curRow;
  964.             $this->rowPopulateTS=time();
  965.         }
  966.         
  967.         if ($debugechoDebugLine(__FILE__,__LINE__,"<p>Defaults:</p><pre>" print_r($arr_defaults,true"</pre>");
  968.         return $arr_defaults;                
  969.     }
  970.     
  971.     /**
  972.       * populates one row from the database
  973.       * if a tableobject is set it is populated (if not already done)
  974.       * if $this->myForm has
  975.       *
  976.       * @param array $filterAdd 
  977.       * @param boolean $debug 
  978.       *
  979.       * @return boolean 
  980.       *
  981.       * @todo for more than one table
  982.       *
  983.       * @global {$this->myForm->getDataArrName()} 
  984.       *
  985.       */
  986.     function populateRow($filterAdd=NULL,$debug=False)
  987.     {
  988.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::populateRow()","\n\nFilter: <pre>".print_r($this->myFilter,True)."</pre>Filter Add:<pre>".print_r($filterAdd,TRUE)."</pre>\n\n");
  989.  
  990.         global ${$this->myForm->getDataArrName()};
  991.         
  992.         if ($obj_tblObj $this->myForm->getMyTblObj(True,$debug))
  993.         {                        
  994.             
  995.             if (!$obj_tblObj->isPopulated())
  996.             {                                
  997.                 if ($debugechoDebugMethod(__FILE__,__LINE__,"table object is not populated");
  998.                 if (!sizeof($this->myFilter&& !is_array($filterAdd&& !sizeof($filterAdd))
  999.                 {
  1000.                     if ($debugechoDebugLine(__FILE__,__LINE__,"<h3>NO FILTER SET</h3>");
  1001.                     $this->myForm->setError($this->myForm->getLangTxt('NO_FILTER_SET'));
  1002.                     return False;
  1003.                 }
  1004.                 foreach($this->myFilter as $str_col => $m_val)
  1005.                 {
  1006.                     $obj_tblObj->db_SetKey($str_col,$m_val);
  1007.                 }
  1008.  
  1009.                 if (is_array($filterAdd))
  1010.                 {
  1011.                     foreach($filterAdd as $str_col => $m_val)
  1012.                     {
  1013.                         $obj_tblObj->db_SetKey($str_col,$m_val);
  1014.                     }
  1015.                 }
  1016.  
  1017.                 if ($this->myForm->getFrmMode(== FRM_MODE_NEW)
  1018.                 {
  1019.                     if ($debugechoDebugLine(__FILE__,__LINE__,"setting default values as populated");
  1020.                     $obj_tblObj->setDBRow($this->getDefaultValues($true),True);
  1021.                     return True;                    
  1022.                 else {                                    
  1023.                     if (!$obj_tblObj->dbPopulate())
  1024.                     {
  1025.                         $this->myForm->setError($this->myForm->getLangTxt('ROW_IS_NOT_POPULATED')." Filter: ".print_r($this->myFilter));
  1026.                         return False;
  1027.                     }
  1028.                 }
  1029.             else {
  1030.                 if ($debugechoDebugLine(__FILE__,__LINE__,"\$obj_tblObj is populated");
  1031.             }
  1032.  
  1033.             if (is_array($filterAdd))
  1034.                 $arr_filter=array_merge($filterAdd,$this->myFilter);
  1035.             else            
  1036.                 $arr_filter=$this->myFilter;    
  1037.             
  1038.             $this->curRow=$obj_tblObj->dbGetDataArray($this->myForm->getTables(),$arr_filter,True,$debug);
  1039.             $this->rowPopulateTS=time();
  1040.  
  1041.             // overwrite filter
  1042.             if ($arr_keys=$obj_tblObj->getKeyArr())
  1043.             {
  1044.                 $this->myFilter=array();
  1045.                 foreach($arr_keys as $str_col => $arr_desc)
  1046.                 {
  1047.                     if (isset($this->curRow[$str_col]))
  1048.                     {
  1049.                         $this->myFilter[$str_col]=$this->curRow[$str_col];
  1050.                     }
  1051.                 }
  1052.             }
  1053.             if ($debugechoDebugLine(__FILE__,__LINE__,"Object: ".get_class($this)." curRow: <pre style=\"font-size:50%\">".print_r($this->curRow,True)."</pre>");
  1054.  
  1055.             ${$this->myForm->getDataArrName()}=&$this->curRow;
  1056.             return True;
  1057.  
  1058.         else {
  1059.             if (parent::populateRow($filterAdd,$debug))
  1060.             {
  1061.                 ${$this->myForm->getDataArrName()}=&$this->curRow;
  1062.                 return True;
  1063.             }
  1064.         }
  1065.         
  1066.         if ($debugechoDebugLine(__FILE__,__LINE__,"\n\n-------------could not populate row-------------------\n\n\n\n");
  1067.         return False;
  1068.      }
  1069.      
  1070.      
  1071.     /**
  1072.      * sets the form row values from an array
  1073.      *
  1074.      * @param array $valArr 
  1075.      * @param boolean $debug 
  1076.      * 
  1077.      */
  1078.        public function setValuesFromArray($valArr,$debug=False)
  1079.        {
  1080.            if (!$this->rowIsPopulated())
  1081.            {
  1082.                if ($this->myForm->getFrmMode(== FRM_MODE_NEW)
  1083.                {
  1084.                    $this->getDefaultValues(TRUE,$debug);
  1085.                else {
  1086.                    $this->populateRow(NULL,$debug);
  1087.                }
  1088.            }
  1089.            
  1090.            foreach($valArr as $str_key => $str_val)
  1091.            {
  1092.                if ($obj_field $this->myForm->getField($str_key))
  1093.                {
  1094.                    $arr_dummy array();
  1095.                    $this->curRow[$str_key$obj_field->getValue($str_val,$arr_dummy)
  1096.                }
  1097.            }
  1098.        }
  1099.  
  1100.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1101.     // validation
  1102.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1103.  
  1104.     /**
  1105.       * @param int $mode 
  1106.       * @param array $data 
  1107.       * @param boolean $debug 
  1108.       *
  1109.       * @return boolean 
  1110.       *
  1111.       */
  1112.     function validateSubmit($mode,$data,$debug=False)
  1113.     {         
  1114.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::validateSubmit()");
  1115.  
  1116.         $this->getMyForm();                 // ensure $this->myForm is set.
  1117.         $this->myForm->setFrmMode($mode);   // to be sure it's set in case the method is not called from $this->myForm
  1118.  
  1119.         if ($obj_tblObj=$this->myForm->getMyTblObj(True,$debug))
  1120.         {
  1121.             if ($debugechoDebugLine(__FILE__,__LINE__,"\n\n\n\n\n\nTable object found: " get_class($obj_tblObj"\n\n\n\n\n\n");
  1122.             switch($mode)
  1123.             {
  1124.                 case FRM_MODE_EDIT:
  1125.                 case FRM_MODE_COPY:
  1126.                     if (!$this->populateRow(NULL,$debug))
  1127.                     {
  1128.                         // error handling should be done in populateRow
  1129.                         return False;
  1130.                     }
  1131.                     break;
  1132.                 case FRM_MODE_NEW:
  1133.                     $this->getDefaultValues(True,$debug);
  1134.                     break;
  1135.                 case FRM_MODE_DELETE:
  1136.                     if ($debugechoDebugLine(__FILE__,__LINE__,"<h1>Delete from class: " get_class($obj_tblObj"</h1>");
  1137.                     if (!$this->populateRow(NULL))
  1138.                     {
  1139.                         // error handling should be done in populateRow
  1140.                            if ($debugechoDebugLine(__FILE__,__LINE__,"<h2>could not populate row</h2>");
  1141.                         return False;
  1142.                     }
  1143.                     
  1144.                     $str_serKey print_r($obj_tblObj->getDBRow(),True);
  1145.                     if ($debugechoDebugLine(__FILE__,__LINE__,"<strong>delete key:</strong>"$data['DELKEY']  "<br />" md5($str_serKey" class: " get_class($obj_tblObj"<pre>{$str_serKey}</pre>");
  1146.                     return ($data['DELKEY'== md5($str_serKey));
  1147.                 default:
  1148.                     throw new Exception('UNKNOWN FORM MODE');            
  1149.             }
  1150.  
  1151.          
  1152.             if ($debugechoDebugLine(__FILE__,__LINE__,"<hr><h2>\$data: </h2><pre>".print_r($data,true)."</pre>");            
  1153.             
  1154.             $GLOBALS[$this->myForm->getDataArrName()]=&$data;
  1155.             $b_return=True;
  1156.  
  1157.             if ($arr_blocks=$this->myForm->getBlocks())
  1158.             {
  1159.                 foreach($arr_blocks as $int_blockId => &$obj_block)
  1160.                 {
  1161.                     if ($debugechoDebugLine(__FILE__,__LINE__,"<h1>Checking Block: ".$obj_block->getName()."</h1>");
  1162.                     if ($obj_block->isToShow($this->myForm->getFrmMode()))
  1163.                     {
  1164.                         $b_blockOk=$this->validateBlockSubmit($obj_block,$data,$debug);
  1165.                         $b_return=($b_return && $b_blockOk);
  1166.                     else if ($debug{
  1167.                         echoDebugLine(__FILE__,__LINE__,"<p>Block is not to show in mode: ".$this->myForm->getFrmMode());
  1168.                     }
  1169.                 }
  1170.             
  1171.             return $b_return;
  1172.         else {
  1173.             if ($debugechoDebugLine(__FILE__,__LINE__,"<h3>calling parent::vaildateSubmit()</h3>");
  1174.             return parent::validateSubmit($mode,$data,$debug);
  1175.         }
  1176.  
  1177.     }
  1178.  
  1179.    /**
  1180.       * save the row to the database
  1181.       *
  1182.       * @param boolean $debug 
  1183.       *
  1184.       * @return boolean 
  1185.       *
  1186.       * @version pk-08-06-26 passthrough fields
  1187.       */
  1188.     function saveCurRow($debug)
  1189.     {
  1190.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::saveCurRow()");
  1191.                 
  1192.         if ($arr_passthrough $this->myForm->getPassThroughFields()) // <pk-06-08-26>
  1193.         {
  1194.             foreach($arr_passthrough as $str_col => $mix_val)
  1195.             {
  1196.                 $this->curRow[$str_col$mix_val;
  1197.             }
  1198.         }
  1199.         
  1200.         if (!$this->curUserCanSave($debug)) {
  1201.             ocsp_logError(__FILE__,__LINE__,'no rights',E_NOTICE);
  1202.             return False;
  1203.         }
  1204.         if ($obj_tblObj=$this->myForm->getMyTblObj(True,$debug))
  1205.         {
  1206.             if ($debugechoDebugLine(__FILE__,__LINE__,"<h3>using tableobject <strong>" get_class($obj_tblObj"</strong> to save</h3>");
  1207.             switch($this->myForm->getFrmMode())
  1208.             {
  1209.                 case FRM_MODE_EDIT:
  1210.                     if (!$this->rowIsPopulated())
  1211.                     {
  1212.                         $this->myForm->setError($this->myForm->getLangTxt('CAN_NOT_UPDATE_ROW').":".$this->myForm->getLangTxt('ROW_IS_NOT_POPULATED'));
  1213.                         return False;
  1214.                     }
  1215.                     $this->setTblObjDBVal($debug);
  1216.                     if ($debugechoDebugLine(__FILE__,__LINE__,"VALUES: <pre>".print_r($obj_tblObj->getDBVal(),True)."</pre>");
  1217.                     if ($mix_ret $obj_tblObj->dbReplace($debug))
  1218.                     {
  1219.                         // merge curRow with dbValues to get the values 
  1220.                         // manipulated on replace
  1221.                         $this->curRow = array_merge($this->curRow,$obj_tblObj->getDBVal());
  1222.                         
  1223.                     }
  1224.                     return $mix_ret;
  1225.                     // <<<<<<<<<<<<<<<<<<<<<<<<<
  1226.                     // return
  1227.                     // <<<<<<<<<<<<<<<<<<<<<<<<<                    
  1228.                 case FRM_MODE_COPY:
  1229.                 case FRM_MODE_NEW:                    
  1230.                     $this->setTblObjDBVal($debug);
  1231.                     if ($mix_ret $obj_tblObj->dbInsert($debug))
  1232.                     {
  1233.                         $this->curRow = array_merge($this->curRow,$obj_tblObj->getDBVal());
  1234.                     }
  1235.                     return $mix_ret;
  1236.                     // <<<<<<<<<<<<<<<<<<<<<<<<<
  1237.                     // return
  1238.                     // <<<<<<<<<<<<<<<<<<<<<<<<<
  1239.                     
  1240.                 case FRM_MODE_DELETE:
  1241.                        $this->setTblObjDBVal($debug);                    
  1242.                     $obj_tblObj->dbDelete(true,$debug);
  1243.                     return True;
  1244.                     // <<<<<<<<<<<<<<<<<<<<<<<<<
  1245.                     // return
  1246.                     // <<<<<<<<<<<<<<<<<<<<<<<<<
  1247.                     
  1248.                 default:
  1249.                     return False;
  1250.                     // <<<<<<<<<<<<<<<<<<<<<<<<<
  1251.                     // return
  1252.                     // <<<<<<<<<<<<<<<<<<<<<<<<<
  1253.                     
  1254.             }
  1255.         else {
  1256.             return parent::saveCurRow($debug);
  1257.         }
  1258.     }
  1259.  
  1260.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1261.     // rights
  1262.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1263.  
  1264.     /**
  1265.       * returns if the current user can save the form in the current mode
  1266.       *
  1267.       * @param boolean $debug 
  1268.       *
  1269.       * @return boolean 
  1270.       * @access protected
  1271.       */
  1272.     function curUserCanSave($debug=False)
  1273.     {
  1274.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR_FORM::curUserCanSave()");
  1275.  
  1276.         if ($obj_tblObj=$this->myForm->getMyTblObj(True,$debug))
  1277.         {
  1278.             $this->setTblObjDBVal($debug);
  1279.             //$obj_tblObj->setDBVal($this->getCurRow(),$debug); // <pk-08-01-14> ensure the object has dataset.
  1280.             switch($this->myForm->getFrmMode())
  1281.             {
  1282.                 case FRM_MODE_COPY:
  1283.                 case FRM_MODE_NEW:
  1284.                     if (method_exists($obj_tblObj,'curUserCanInsert'))
  1285.                     {
  1286.                         if ($debugechoDebugLine(__FILE__,__LINE__,"checking ".get_class($obj_tblObj)."->curUserCanInsert()");
  1287.                         if (!$obj_tblObj->curUserCanInsert()) return False;
  1288.                     }
  1289.                     break;
  1290.                 case FRM_MODE_EDIT:
  1291.                     if (method_exists($obj_tblObj,'curUserCanEdit'))
  1292.                     {
  1293.                         if ($debugechoDebugLine(__FILE__,__LINE__,"checking ".get_class($obj_tblObj)."->curUserCanEdit()");
  1294.                         if (!$obj_tblObj->curUserCanEdit()) return False;
  1295.                     }
  1296.                     break;
  1297.                 case FRM_MODE_DELETE:
  1298.                     if (method_exists($obj_tblObj,'curUserCanDelete'))
  1299.                     {
  1300.                         if ($debugechoDebugLine(__FILE__,__LINE__,"checking ".get_class($obj_tblObj)."->curUserCanDelete()");
  1301.                         if (!$obj_tblObj->curUserCanDelete()) return False;
  1302.                     }
  1303.                     break;
  1304.             }
  1305.         }
  1306.         return $this->checkRights($this->myForm->getFrmMode(),$GLOBALS['OCSP_OBJ']['USER'],$debug);
  1307.     }
  1308.  
  1309. // end of OCSP_FRMCONTR_FORM
  1310. ?>

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