Source for file OCSP_FRMCONTR.phpclass

Documentation is available at OCSP_FRMCONTR.phpclass

  1. <?php
  2. /**
  3.   * Class file OCSP_FRMCONTR.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.   * @version $Id: OCSP_FRMCONTR.phpclass,v 1.33 2008/12/17 16:28:51 peterkrebs Exp $
  15.   */
  16.  
  17. require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_templates.phpinc";
  18. require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."OCSP_OBJ.phpclass";
  19.  
  20.  
  21. /**
  22.   * class OCSP_FRMCONTR
  23.   *
  24.   * @project    Open CSP-Management
  25.   * @package    forms
  26.   * @category   dbms_form
  27.   *
  28.   * @author     Peter Krebs (pk) <pitlinz@users.sourceforge.net>
  29.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  30.   *
  31.   * @since  pk-07-06-30
  32.   * @version pk-08-01-21 // extends OCSP_OBJ
  33.   * @version $Id: OCSP_FRMCONTR.phpclass,v 1.33 2008/12/17 16:28:51 peterkrebs Exp $
  34.   *
  35.   * @requires common/pcf_templates.phpinc
  36.   *
  37.   */
  38. class OCSP_FRMCONTR extends OCSP_OBJ
  39. {
  40.  
  41.     /*** Aggregations: */
  42.  
  43.  
  44.     /*** Compositions: */
  45.  
  46.     /**
  47.       * @var OCSP_FORM $myForm 
  48.       * @access protected
  49.       */
  50.     protected $myForm=Null;
  51.  
  52.     /**
  53.       * @var OCSP_DB $myDBObj 
  54.       * @access protected
  55.       * 
  56.       * @deprecated since pk-08-08-18 use OCSP_OBJ db ojbects
  57.       */
  58.     protected $myDBObj;
  59.  
  60.     /*** Attributes: */
  61.  
  62.     /**
  63.       * @var array $myFilter 
  64.       * @access protected
  65.       */
  66.     protected $myFilter=array();
  67.  
  68.     /**
  69.       * @var array $curRow 
  70.       * @access protected
  71.       */
  72.     protected $curRow=array();
  73.  
  74.     /**
  75.       * @var double $rowPopulateTS 
  76.       * @access protected
  77.       */
  78.     protected $rowPopulateTS=0;
  79.  
  80.     /**
  81.       * @var array $myCommands 
  82.       * @access proteced
  83.       */
  84.     protected $myCommands=array();
  85.  
  86.     /**
  87.       * @var string $myAction 
  88.       * @access protected
  89.       */
  90.     protected $myActionURL="";
  91.     
  92.     /**
  93.      * url to submit the form on reload
  94.      * 
  95.      * Note: $this->myForm->getSubmitAction($this->myForm->getFrmMode(),'RELOAD')
  96.      * overrules this setting
  97.      * 
  98.      * @var string $myReloadUrl 
  99.      * @since pk-08-06-14
  100.      */
  101.     protected $myReloadUrl;
  102.     
  103.     /**
  104.       * only used in checkRights() must not be used outside
  105.       * @var array $checkRights_userRights (array for each user)
  106.       * @access protected
  107.       */
  108.     protected $checkRights_userRights=array();
  109.  
  110.     /**
  111.       * only used in checkRights() must not be used outside
  112.       * @var int $checkRights_hasDBRightsSet (we have group entries in T_DBMS_FORMRIGHTS);
  113.       * @access protected
  114.       */
  115.     protected $checkRights_hasDBRightsSet=-1;
  116.  
  117.     /**
  118.       * if the form has a table object this method is called to check if a user has the rights
  119.       * to show the values
  120.       * @var string $userCanShowMethod 
  121.       * @access protected
  122.       */
  123.     protected $userCanShowMethod="userCanShow";
  124.  
  125.     /**
  126.      * hash key to identify the form in jOCSP
  127.      *
  128.      * @var string 
  129.      * @since pk-08-01-31
  130.      */
  131.     protected $myjOCSPHash = "";
  132.     
  133.     /*** Association */
  134.  
  135.     /**
  136.       * @var OCSP_FRMVIEW $myView 
  137.       * @access protected
  138.       */
  139.     protected $myView=NULL;
  140.  
  141.  
  142.     
  143.  
  144.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  145.     // init methods
  146.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147.  
  148.     /**
  149.       * @param OCSP_FORM $aForm 
  150.       * @param boolean $debug 
  151.       */
  152.     function __construct(&$aForm=NULL,$debug=False)
  153.     {
  154.         if (pcf_is_instance_of($aForm,'OCSP_FORM'))
  155.         {
  156.             $this->setMyForm($aForm);
  157.             if ($tmpControll=$this->myForm->getControll("NO",$debug))
  158.             {
  159.                 // cast the forms controll
  160.                 $this->setObjectValues($tmpControll->getObjectValues($debug),$debug);
  161.                 $this->myForm->setControll($this);
  162.             }
  163.         }
  164.     }
  165.  
  166.  
  167.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  168.     // getter/setter methods
  169.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  170.  
  171.     /**
  172.       * @return OCSP_FORM 
  173.       */
  174.     function &getMyForm()
  175.     {
  176.         return $this->myForm;
  177.     }
  178.  
  179.     /**
  180.       * @param OCSP_FORM $aForm 
  181.       */
  182.     function setMyForm(&$aForm)
  183.     {
  184.         $this->myForm=&$aForm;
  185.     }
  186.  
  187.     /**
  188.      * returns the current view
  189.      *
  190.      * @return unknown 
  191.      */
  192.     function &getView()
  193.     {
  194.         return $this->myView;
  195.     }
  196.     
  197.     /**
  198.       * @param OCSP_FRMVIEW $aView 
  199.       */
  200.     function setView(&$aView)
  201.     {
  202.         $this->myView=&$aView;
  203.     }
  204.  
  205.     /**
  206.       * @param array $aFilter 
  207.       */
  208.     function setFilter($aFilter)
  209.     {
  210.         $this->myFilter=$aFilter;
  211.     }
  212.  
  213.     /**
  214.      * @return array 
  215.      * 
  216.      * @since pk-08-06-05
  217.      */
  218.     public function getFilter()
  219.     {
  220.         return $this->myFilter;
  221.     }
  222.     
  223.     /**
  224.       * @param string $key 
  225.       * @param mixed $value 
  226.       */
  227.     public function addFilter($key,$value)
  228.     {
  229.         $this->myFilter[$key]=$value;
  230.     }
  231.     
  232.     /**
  233.      * removes a filter value from the current filter
  234.      * 
  235.      * @param string $key 
  236.      * 
  237.      * @since pk-08-06-05
  238.      */
  239.     public function unsetFilter($key)
  240.     {
  241.         if (isset($this->myFilter[$key]))
  242.         {
  243.             unset($this->myFilter[$key]);
  244.         }
  245.     }
  246.  
  247.     /**
  248.       * returns all values of the object
  249.       *
  250.       * @param boolean $debug 
  251.       *
  252.       * @return array 
  253.       * @access public
  254.       */
  255.     function getObjectValues($debug=False)
  256.     {
  257.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::getObjectValues()");
  258.         $arr_ret=get_object_vars($this);
  259.  
  260.         // ensure reference
  261.         $arr_ret['myForm']  =&$this->myForm;
  262.         $arr_ret['myDBObj'=&$this->myDBObj;
  263.         $arr_ret['myView']  =&$this->myView;
  264.  
  265.         return $arr_ret;
  266.     }
  267.  
  268.     /**
  269.       * @param array $objVals 
  270.       * @param boolean $debug 
  271.       * @access public
  272.       */
  273.     function setObjectValues($objVals,$debug=False{
  274.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::setObjectValues()");
  275.         foreach($objVals as $str_name => $m_val)
  276.         {
  277.             $this->{$str_name}=$m_val;
  278.         }
  279.     }
  280.  
  281.     /**
  282.       * @param string $aCmdName 
  283.       * @param int $aType (_OCSP_FRMCMDTYPE_...)
  284.       * @param string $cmdCode 
  285.       * @param string $aBlockName 
  286.       */
  287.     function setCommand($aCmdName,$aType,$cmdCode,$aBlockName='_FORM_')
  288.     {
  289.         if (empty($aBlockName)) $aBlockName='_FORM_';
  290.         $this->myCommands[$aBlockName][$aCmdName]=array(
  291.             'TYPE'=> $aType,
  292.             'CODE'=> $cmdCode
  293.         );
  294.     }
  295.  
  296.     /**
  297.       * @param string $aAction URL to send the form to
  298.       */
  299.     function setActionURL($aAction)
  300.     {
  301.         $this->myActionURL=$aAction;
  302.     }
  303.  
  304.     /**
  305.       * returns the action URL if set otherwise the default action for $this->myForm->getFrmMode()
  306.       *
  307.       * @param boolean $debug 
  308.       *
  309.       * @global $OCSP_CONF 
  310.       *
  311.       * @return string 
  312.       * 
  313.       * @version pk-08-02-07
  314.       */
  315.     function getActionURL($debug=False)
  316.     {
  317.         global $OCSP_CONF;
  318.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::getAction()","MODE: ".$this->myForm->getFrmMode());
  319.  
  320.         if (empty($this->myActionURL))        
  321.         {    // <pk-08-02-07 /> check if the form has a special action url 
  322.             $this->myActionURL $this->myForm->getSubmitAction($this->myForm->getFrmMode(),'ACTION');            
  323.         }
  324.         
  325.         if (!empty($this->myActionURL))
  326.         {
  327.             return $this->myActionURL;
  328.         }
  329.         
  330.         switch($this->myForm->getFrmMode())
  331.         {
  332.             case FRM_MODE_NEW:
  333.             case FRM_MODE_COPY:
  334.                 return $OCSP_CONF['SYSTEMURL']."forms/insert.php?".$_SERVER['QUERY_STRING'];
  335.             case FRM_MODE_EDIT:
  336.                 return $OCSP_CONF['SYSTEMURL']."forms/update.php?".$_SERVER['QUERY_STRING'];
  337.             case FRM_MODE_DELETE:
  338.                 return $OCSP_CONF['SYSTEMURL']."forms/delete.php?".$_SERVER['QUERY_STRING'];
  339.         }
  340.  
  341.         return "#";
  342.     }
  343.  
  344.     /**
  345.      * returns a reload url if set either in form or with setReloadUrl
  346.      * 
  347.      * the reload url is set when a (select) field change requires
  348.      * to reload the form. in this case the form is sent to the url
  349.      * as ajax request which returns a java script
  350.      * 
  351.      * settings stored in $this->myForm->getSubmitAction
  352.      * overwrites $this->myReloadUrl
  353.      *
  354.      * @return string 
  355.      * 
  356.      * @since pk-08-02-07
  357.      * @version pk-08-06-14
  358.      */
  359.     public function getReloadUrl()
  360.     {
  361.         $str_reloadUrl $this->myForm->getSubmitAction($this->myForm->getFrmMode(),'RELOAD');
  362.         if (!empty($str_reloadUrl))
  363.         {
  364.             return pcf_tmpl_parse($str_reloadUrl,$this->curRow);
  365.         }
  366.         
  367.         return $this->myReloadUrl;
  368.     }    
  369.     
  370.     /**
  371.      * @param string $aUrl 
  372.      * 
  373.      *  Note: $this->myForm->getSubmitAction overrules $this->myReloadUrl
  374.      * 
  375.      * @since pk-08-06-14
  376.      */
  377.     public function setReloadUrl($aUrl)
  378.     {
  379.         $this->myReloadUrl $aUrl;
  380.     }
  381.     
  382.     /**
  383.       * @param OCSP_AJAX $ajaxObj 
  384.       * @access public
  385.       * @since pk-07-09-18
  386.       */
  387.     function setAjaxObj(&$ajaxObj)
  388.     {
  389.         $this->myForm->ajax_setObj(&$ajaxObj);
  390.     }
  391.  
  392.     /**
  393.       * @param boolean $force (the instantiation of a new object)
  394.       * @return OCSP_AJAX 
  395.       * @access public
  396.       * @since pk-07-09-18
  397.       */
  398.     function &getAjaxObj($force=False)
  399.     {
  400.         return $this->myForm->ajax_getObj(False);
  401.     }
  402.  
  403.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  404.     // jOCSP commands
  405.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  406.     
  407.     /**
  408.      * returns a hash to identify the form
  409.      * if not set a new one is generated
  410.      *
  411.      * @since pk-08-01-31
  412.      * 
  413.      * @return string 
  414.      */
  415.     public function jOCSP_getfrmHash()
  416.     {
  417.          if (empty($this->myjOCSPHash)) 
  418.          {
  419.              /*
  420.              $str_idStr  = $this->myForm->getId();
  421.              $str_idStr .= print_r($this->myFilter,True);
  422.              $str_idStr .= $this->myForm->getFrmMode();
  423.              $this->myjOCSPHash = md5($str_idStr);
  424.              */
  425.             $this->myjOCSPHash $this->myForm->getMyJsId();
  426.          }
  427.          
  428.          return $this->myjOCSPHash;
  429.     }
  430.  
  431.     /**
  432.      * sets myjOCSPHash
  433.      *
  434.      * @param string $aHash 
  435.      */
  436.     public function jOCSP_setfrmHash($aHash)
  437.     {
  438.         $this->myjOCSPHash $aHash;
  439.         $this->myForm->setMyJsId($aHash);
  440.     }
  441.     
  442.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  443.     // db methods
  444.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  445.  
  446.     /**
  447.       * returns the db object from the form
  448.       *
  449.       * @param boolean $debug 
  450.       * @return OCSP_DB 
  451.       */
  452.     function &getDBObj($debug=False)
  453.     {
  454.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::getDBObj()");
  455.         if (!pcf_is_instance_of($this->myDBObj,'OCSP_DB'))
  456.         {
  457.             $this->myDBObj=$this->myForm->getDBObj($debug);
  458.             return $this->myDBObj;
  459.         else {
  460.             return $this->myDBObj;
  461.         }
  462.     }
  463.  
  464.     /**
  465.       * @return boolean 
  466.       */
  467.     function rowIsPopulated()
  468.     {
  469.         return (($this->rowPopulateTS (time(ini_get('max_execution_time'))) True False );
  470.     }
  471.  
  472.     /**
  473.       * populates one row from the database
  474.       * this is the first row fitting $this->myFilter
  475.       *
  476.       * @param array $filterAdd 
  477.       * @param boolean $debug 
  478.       *
  479.       * @return boolean 
  480.       *
  481.       * @todo for more than one table
  482.       *
  483.       */
  484.     function populateRow($filterAdd=NULL,$debug=False)
  485.     {       
  486.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::populateRow()",print_r($filterAdd,True));
  487.  
  488.         if (is_array($filterAdd&& sizeof($filterAdd))
  489.         {
  490.             $this->myFilter=array_merge($this->myFilter,$filterAdd);
  491.         }
  492.         
  493.         if ($this->curRow=OCSP_OBJ::defaultReadDBObj()->getArray($this->myForm->getMasterTable(),$this->myFilter,0,1,""))
  494.         {
  495.             $this->rowPopulateTS=time();
  496.             return True;
  497.         else {
  498.             if ($debugechoDebugLine(__FILE__,__LINE__,"<h3>could not populate row from "  $this->myForm->getMasterTable(."</h3>");
  499.             return False;
  500.         }
  501.     }
  502.  
  503.     /**
  504.       * sets the current row from outside
  505.       *
  506.       * @param array $aRow 
  507.       * @param boolean $debug 
  508.       *
  509.       * @access public
  510.       */
  511.     function setCurRow($aRow,$debug=False)
  512.     {
  513.         if (is_array($aRow&& sizeof($aRow))
  514.         {
  515.             $this->curRow=$aRow;
  516.             $this->rowPopulateTS=time();
  517.         }
  518.     }
  519.  
  520.     /**
  521.      * sets a value in $this-curRow
  522.      * 
  523.      * if (!$this->rowIsPopulated()) this->populateRow() is called
  524.      * before setting the value
  525.      * 
  526.      * @param string $colName 
  527.      * @param mixed $value 
  528.      * @param boolean $debug 
  529.      * 
  530.      */
  531.     function setCurRowValue($colName,$value,$debug=False)
  532.     {
  533.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::setCurRowValue($str_key)");
  534.         
  535.         if (!empty($colName))
  536.         {
  537.             if (!$this->rowIsPopulated())
  538.             {
  539.                 if ($debugechoDebugLine(__FILE__,__LINE__,"populateing row first (FrmMode: " $this->myForm->getFrmMode(.")");
  540.                 
  541.                 if ($this->myForm->getFrmMode(== FRM_MODE_NEW)                
  542.                 {
  543.                     if ($debugechoDebugLine(__FILE__,__LINE__,"new entry");                
  544.                     if (method_exists($this,'getDefaultValues'))
  545.                     {
  546.                         $this->getDefaultValues(True,$debug);   
  547.                     else if (!is_array($this->curRow)) {
  548.                         if (is_array($this->myFilter))
  549.                         {
  550.                             $this->curRow=$this->myFilter;
  551.                         else {
  552.                             $this->curRow=array();
  553.                         }
  554.                     }
  555.                 else {
  556.                     $this->populateRow(NULL,$debug);
  557.                 }
  558.             }
  559.             $this->curRow[$colName]=$value;
  560.         }
  561.     }
  562.     
  563.     /**
  564.       * returns the array of the current select DB values
  565.       * 
  566.       * @return array 
  567.       * 
  568.       * @deprecated since pk-08-01-14 (use getCurRow() instead)
  569.       */
  570.     function &getCurrentRow()
  571.     {
  572.         return $this->getCurRow();
  573.     }
  574.     
  575.     /**
  576.       * returns the array of the current select DB values
  577.       *
  578.       * @return array 
  579.       * 
  580.       * @since pk-08-01-14
  581.       */
  582.     function &getCurRow()
  583.     {
  584.         return $this->curRow;
  585.     }   
  586.  
  587.     /**
  588.      * returns a column value of the current row
  589.      *
  590.      * @param string $aColumn 
  591.      * 
  592.      * @return mixed 
  593.      * 
  594.      * @since pk-08-02-08
  595.      */
  596.     function getCurValue($aColumn)
  597.     {
  598.         if (isset($this->curRow[$aColumn]))
  599.         {
  600.             return $this->curRow[$aColumn];
  601.         }
  602.         return NULL;
  603.     }
  604.     
  605.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  606.     // field methods
  607.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  608.  
  609.     /**
  610.       * returns a template parsed with the current row
  611.       *
  612.       * @param string $aTmpl 
  613.       * @param boolean $debug 
  614.       *
  615.       * @return string 
  616.       *
  617.       * @requires pcf_templates.phpinc
  618.       */
  619.     function parseRowTmpl($aTmpl,$debug=False)
  620.     {
  621.         require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_templates.phpinc";
  622.         return pcf_tmpl_parse($aTmpl,$this->curRow);
  623.     }
  624.  
  625.     /**
  626.       *
  627.       * @param DBMS_FIELD $aField 
  628.       * @param string $aTemplate 
  629.       * @param boolean $debug 
  630.       *
  631.       * @return string 
  632.       *
  633.       * @requires common/pcf_templates.phpinc
  634.       */
  635.     function parseFieldTmpl(&$aField,$aTemplate,$debug=False)
  636.     {
  637.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::parseFieldTmpl()");
  638.  
  639.         require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_templates.phpinc";
  640.  
  641.         $arr_fldVals=$aField->getObjectVars();
  642.         return pcf_tmpl_parse($aTemplate,$arr_fldVals);
  643.  
  644.     }
  645.  
  646.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  647.     // validation methods
  648.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  649.  
  650.     /**
  651.       * @param int $mode 
  652.       * @param array $data 
  653.       * @param boolean $debug 
  654.       *
  655.       * @return boolean 
  656.       * @requires $GLOBALS['OCSP']['PHPINCPATH']."common/pcf_md5.phpinc"
  657.       */
  658.     function validateSubmit($mode,$data,$debug=False)
  659.     {
  660.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::validateValues()");
  661.  
  662.         $this->getMyForm()// ensure $this->myForm is set.
  663.         $this->myForm->setFrmMode($mode);
  664.         if (sizeof($data))
  665.         {
  666.             if ($debugechoDebugLine(__FILE__,__LINE__,"<hr><h2>\$data: </h2><pre>".print_r($data,true)."</pre>");
  667.             if (($this->myForm->getFrmMode()==FRM_MODE_EDIT|| ($this->myForm->getFrmMode()==FRM_MODE_COPY|| ($this->myForm->getFrmMode()==FRM_MODE_DELETE))
  668.             {
  669.                 if (!$this->rowIsPopulated())
  670.                 {
  671.                     if (!sizeof($this->myFilter))
  672.                     {
  673.                         if ($debugechoDebugLine(__FILE__,__LINE__,"<h3>NO FILTER SET</h3>");
  674.                         $this->myForm->setError($this->myForm->getLangTxt('NO_FILTER_SET'));
  675.                         return False;
  676.                     }
  677.                     $this->populateRow(NULL,$debug);
  678.                 }
  679.             }
  680.  
  681.             $GLOBALS[$this->myForm->getDataArrName()]=&$data;
  682.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$GLOBALS[" $this->myForm->getDataArrName("] set to \n" .print_r($data,True));            
  683.             
  684.             $b_return=True;
  685.  
  686.             if ($this->myForm->getFrmMode(== FRM_MODE_DELETE)
  687.             {
  688.                 // we have a read only form posted ignore value checks
  689.                 // check the delete key
  690.                 if (!isset($_POST['DELKEY']|| empty($_POST['DELKEY']))
  691.                 {
  692.                     $this->myForm->setError('NO DELKEY set');
  693.                     return False;
  694.                 }
  695.                 
  696.                 $this->populateRow(NULL,$debug)// to ensure having db values set
  697.                 
  698.                 $str_delKey $_POST['DELKEY'];
  699.                 if ($debugechoDebugLine(__FILE__,__LINE__,"<p>DeleteKey <pre>".md5(serialize($this->curRow))."\n" $str_delKey "\ncurRow:\n" print_r($this->curRow,True"</pre>");                
  700.                 if ($str_delKey != md5(serialize($this->curRow)))
  701.                 {
  702.                     $this->myForm->setError("DELKEY do not match");    
  703.                     return False;
  704.                 else {
  705.                     return True;
  706.                 }                
  707.             else {
  708.             
  709.                 $arr_blocks=$this->myForm->getBlocks($debug);
  710.                 foreach($arr_blocks as $int_blockId => &$obj_block)
  711.                 {
  712.     
  713.                     if ($obj_block->isToShow($this->myForm->getFrmMode(),$debug))
  714.                     {
  715.                         $b_return=($b_return && $this->validateBlockSubmit($obj_block,$data,$debug));
  716.                     }
  717.                 }
  718.             }
  719.         else {
  720.             $this->myForm->setError('NO DATA');
  721.             return False;
  722.         }
  723.  
  724.         return $b_return;
  725.     }
  726.  
  727.     /**
  728.       * validates the block fields
  729.       *
  730.       * @param OCSP_FORM_BLOCK $aBlock 
  731.       * @param array $data 
  732.       * @param boolean $debug 
  733.       *
  734.       * @return boolean 
  735.       * 
  736.       * @version pk-08-01-10
  737.       */
  738.     function validateBlockSubmit($aBlock,$data,$debug)
  739.     {
  740.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::validateBlockSubmit()");
  741.         //echoDebugLine(__FILE__,__LINE__,"<pre style=\"font-size:80%\">" . print_r($this->curRow,True) . "</pre>");
  742.  
  743.         $b_return=True;
  744.  
  745.         $arr_flds=$aBlock->getFields($this->myForm->getFrmMode(),False);
  746.  
  747.         if ($debug{
  748.             $arr_tmpData=$data;
  749.             $str_debug="<table border=\"1\">";
  750.             foreach($arr_flds as &$obj_fld)
  751.             {
  752.                 $str_debug.="<tr><td>".$obj_fld->getKey()."</td>";
  753.                 
  754.                 $str_debug.="<td>".htmlspecialchars((isset($this->curRow[$obj_fld->getName()])) print_r($this->curRow[$obj_fld->getName()],True$obj_fld->getName(" <strong>NOT SET</strong>")."</td>";
  755.                 $str_debug.="<td>".htmlspecialchars((isset($data[$obj_fld->getName()]print_r($data[$obj_fld->getName()],True'NOT SET'))."</td></tr>";
  756.                 unset($arr_tmpData[$obj_fld->getName()]);
  757.             }
  758.             $str_debug.="<tr><td colspan=\"3\"><strong>NOT IN BLOCK</strong></td></tr>";
  759.             if (is_array($arr_tmpData))
  760.             {
  761.                 foreach($arr_tmpData as $str_col => $m_val)
  762.                 {
  763.                     $str_debug.="<tr><td>$str_col</td>";
  764.                     if (isset($this->curRow[$str_col]))
  765.                     {
  766.                         $str_debug.="<td>".htmlspecialchars(print_r($this->curRow[$str_col],True))."</td>";
  767.                     else {
  768.                         $str_debug.="<td>&lt;notset&gt;</td>";
  769.                     }
  770.                     $str_debug .= "<td>".htmlspecialchars(print_r($m_val,True))."</td></tr>";
  771.                 }
  772.             }
  773.             $str_debug.="</table>";
  774.             echoDebugLine(__FILE__,__LINE__,"Block: ".$aBlock->getName().$str_debug);
  775.         }
  776.         
  777.         foreach($arr_flds as &$obj_fld)
  778.         {
  779.             $arr_error=array('ERROR'=>False);
  780.             $m_val=(isset($data[$obj_fld->getName()]$data[$obj_fld->getName()NULL)
  781.             
  782.             if ($obj_fld->isEnabled($this->myForm->getFrmMode(),False))
  783.             {                               
  784.                 $this->curRow[$obj_fld->getName()]=$obj_fld->getValue($m_val,&$arr_error,$this->myForm->getDataArrName(),$debug);
  785.             else if (pcf_is_instance_of($obj_fld,'DBMS_FIELD_FOREIGNKEY'&& $m_val !== NULL{
  786.                 if ($debugechoDebugLine(__FILE__,__LINE__,"FOREIGNKEY: ".$obj_fld->getKey());
  787.                 $this->curRow[$obj_fld->getName()]=$obj_fld->getValue($m_val,&$arr_error,$this->myForm->getDataArrName(),$debug);                
  788.             else if (pcf_is_instance_of($obj_fld,'DBMS_FIELD_AUTINC_KEY'&& ($this->myForm->getFrmMode()==FRM_MODE_EDIT)  && $m_val !== NULL{
  789.                 if ($debugechoDebugLine(__FILE__,__LINE__,"AUTINC_KEY: ".$obj_fld->getKey());
  790.                 $this->curRow[$obj_fld->getName()]=$obj_fld->getValue($data[$obj_fld->getName()],&$arr_error,$this->myForm->getDataArrName(),$debug)//<pk-08-01-10 />bugfix
  791.             else {                
  792.                 if ($debugechoDebugLine(__FILE__,__LINE__,$obj_fld->getKey()." (".get_class($obj_fld).") not checked");
  793.             }
  794.             if ($arr_error['ERROR'])
  795.             {
  796.                 unset($arr_error['ERROR']);
  797.                 foreach($arr_error as $str_fld => $arr_msg)
  798.                 {
  799.                     $this->myForm->setError($arr_msg,$obj_fld->getKey());
  800.                 }
  801.                 unset($arr_error);
  802.                 $b_return=False;
  803.                 if ($debugechoDebugLine(__FILE__,__LINE__,"Error setting Field: ".$obj_fld->getKey()." to ".$m_val."<pre>".print_r($arr_error,True)."</pre>");
  804.             else {
  805.                 if ($debug
  806.                 {
  807.                     if (isset($this->curRow[$obj_fld->getName()]))
  808.                     {
  809.                         echoDebugLine(__FILE__,__LINE__,$obj_fld->getKey()." set to ".$this->curRow[$obj_fld->getName()]);
  810.                     else {
  811.                         echoDebugLine(__FILE__,__LINE__,$obj_fld->getKey()." NOT set to ");
  812.                     }
  813.                 }
  814.                 unset($arr_error);
  815.             }            
  816.         }
  817.         if ($debugechoDebugLine(__FILE__,__LINE__,$aBlock->getName()." row: <pre>".print_r($this->curRow,True)."</pre>");
  818.         return $b_return;
  819.     }
  820.  
  821.  
  822.     /**
  823.       * save the row to the database
  824.       *
  825.       * @param boolean $debug 
  826.       *
  827.       * @return boolean 
  828.       *
  829.       */
  830.     function saveCurRow($debug)
  831.     {
  832.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::saveCurRow()");
  833.         if (!$this->checkRights($this->myForm->getFrmMode(),0,$debug))
  834.         {
  835.             ocsp_logError(__FILE__,__LINE__,"no rights",E_WARNING);
  836.             return False;
  837.         }
  838.         switch($this->myForm->getFrmMode())
  839.         {
  840.             case FRM_MODE_EDIT:
  841.                 if (!$this->rowIsPopulated())
  842.                 {
  843.                     $this->myForm->setError($this->myForm->getLangTxt('CAN_NOT_UPDATE_ROW').":".$this->myForm->getLangTxt('ROW_IS_NOT_POPULATED'));
  844.                     return False;
  845.                 }
  846.                 $this->getDBObj()// ensure $this->myDBObj is a valid DB Object
  847.                 $arr_tables=$this->myForm->getTables();
  848.                 foreach($arr_tables as $str_tbl)
  849.                 {
  850.                     if (!$this->myDBObj->replaceArray($str_tbl,$this->curRow,$debug))
  851.                     {
  852.                         $this->myForm->setError("Error updating table ",$str_tbl);
  853.                         return False;
  854.                     }
  855.                 }
  856.                 return True;
  857.             case FRM_MODE_COPY:
  858.             case FRM_MODE_NEW:
  859.                 $this->getDBObj()// ensure $this->myDBObj is a valid DB Object
  860.                 
  861.                 $arr_tables=$this->myForm->getTables();
  862.                 if ($str_masterTbl=$this->myForm->getMasterTable())
  863.                 {
  864.                     $obj_masterAutoInc=$this->myForm->getAutoIncField($str_masterTbl,$debug);
  865.                     if ((sizeof($arr_tables1&& !$obj_masterAutoInc)
  866.                     {
  867.                         ocsp_logError(__FILE__,__LINE__,"could not find autoinc key column for mastertable ($str_masterTbl)",E_ERROR);
  868.                         return False;                        
  869.                     }
  870.                     
  871.                     if ($mix_masterKey=$this->myDBObj->insertArray($str_masterTbl,$this->curRow,$debug))
  872.                     {    
  873.                         if ($obj_masterAutoInc)
  874.                         {    
  875.                             $this->setCurRowValue($obj_masterAutoInc->getDBColName(False),$mix_masterKey);
  876.                         }    
  877.                         
  878.                         $b_ok=True;
  879.                         
  880.                         foreach($arr_tables as $str_tbl)
  881.                         {
  882.                             if (($str_tbl != $str_masterTbl))
  883.                             {
  884.                                 if ($mix_key=$this->myDBObj->insertArray($str_tbl,$this->curRow,$debug))
  885.                                 {
  886.                                     if ($obj_autoInc=$this->myForm->getAutoIncField($str_tbl,$debug))
  887.                                     {
  888.                                         $this->setCurRowValue($obj_autoInc->getDBColName(False),$mix_key);
  889.                                     }
  890.                                 else {
  891.                                     $b_ok=False;                                
  892.                                 }
  893.                             }
  894.                         }
  895.                         // @todo undo
  896.                         return $b_ok;
  897.                     else {
  898.                         return False;
  899.                     }
  900.                 else {
  901.                     ocsp_logError(__FILE__,__LINE__,"no mastertable",E_ERROR);
  902.                 }
  903.                 break;
  904.             case FRM_MODE_DELETE:
  905.                 // <pk-08-06-14>
  906.                 $this->getDBObj()// ensure $this->myDBObj is a valid DB Object
  907.                 
  908.                 if (OCSP_OBJ::currentUser()->isPublic())
  909.                 {
  910.                     $this->myForm->setError('Löschen als Public ist nicht erlaubt');
  911.                     return False;
  912.                 }
  913.  
  914.                 if (!sizeof($this->myFilter))
  915.                 {
  916.                     $this->myForm->setError('Kein Filter gesetzt');
  917.                     return False;                                        
  918.                 }
  919.                 
  920.                 $arr_tables=$this->myForm->getTables();
  921.                 if (sizeof($arr_tables!= 1)
  922.                 {
  923.                     $this->myForm->setError('Löschen in mehreren Tabellen nicht erlaubt');
  924.                     return False;                    
  925.                 }
  926.                 
  927.                 if ($this->myDBObj->deleteArray($this->myForm->getMasterTable(),$this->curRow,$debug))
  928.                 {
  929.                     return True;
  930.                 else {
  931.                     $this->myForm->setError('konnte Datensatz nicht löschen');
  932.                     return False;
  933.                 }                
  934.                 break;
  935.             default:
  936.                 ocsp_logError(__FILE__,__LINE__,"mode: ".$this->myForm->getFrmMode()." not implemented",E_ERROR);
  937.         }
  938.     }
  939.  
  940.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  941.     // rights
  942.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  943.  
  944.     /**
  945.       * checks the user rights form the database
  946.       *
  947.       * @param int $mode 
  948.       * @param mixed $aUser (int) userId or (OCSP_USER) a user if 0 $GLOBALS['OCSP_OBJ']['USER'] is used
  949.       * @param boolean $debug 
  950.       *
  951.       * @return boolean 
  952.       *
  953.       * @access public
  954.       *
  955.       * @todo OCSP_FRMCONTR::checkRights => use cache
  956.       *
  957.       * @requires user/OCSP_USER.phpclass
  958.       *
  959.       */
  960.     function checkRights($mode,$aUser=0,$debug=False)
  961.     {
  962.         if ($debugechoDebugMethod(__FILE__,get_class($this),"OCSP_FRMCONTR::checkRights($mode)");
  963.  
  964.         if ($this->checkRights_hasDBRightsSet===0)
  965.         {
  966.             if ($debugechoDebugLine(__FILE__,__LINE__,"returns True (no rows in T_DBMS_FORMRIGHTS *CACHED*)");
  967.             return true// no entries in T_DBMS_FORMRIGHTS
  968.         }
  969.  
  970.         if (!$this->getDBObj())
  971.         {
  972.             throw new Exeception(_OCSP_EXCEP_NODBCONN_);
  973.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  974.             die();
  975.         }
  976.         if (!pcf_is_instance_of($aUser,'OCSP_USER'))
  977.         {
  978.             if (!intval($aUser)) {                
  979.                 $obj_user=OCSP_OBJ::currentUser();
  980.             else {
  981.                 if (isset($this->checkRights_userRights[intval($aUser)][$mode]))
  982.                 {
  983.                     return $this->checkRights_userRights[intval($aUser)][$mode];
  984.                 }
  985.  
  986.                 require_once __OCSP_PHPINCPAHT__."user"._OCSP_DIRSEP_."OCSP_USER.phpclass";
  987.                 if (!($obj_user=OCSP_USER::OCSP_USER_FROM_ID(intval($aUser),$this->getDBObj(),$debug)))
  988.                 {
  989.                     throw new Exception(_OCSP_EXCEP_NOUSER_);
  990.                 }
  991.             }
  992.         else {
  993.             $obj_user=&$aUser;
  994.         }
  995.  
  996.         if (isset($this->checkRights_userRights[$obj_user->getId()][$mode]))
  997.         {
  998.             return $this->checkRights_userRights[$obj_user->getId()][$mode];
  999.         }
  1000.  
  1001.         $str_query="SELECT COUNT(*) FROM T_DBMS_FORMRIGHTS WHERE FRM_ID=".$this->myForm->getId();
  1002.         if ($this->checkRights_hasDBRightsSet=intval($this->myDBObj->getOne($str_query)))
  1003.         {
  1004.             $str_query="SELECT GRP_ID FROM T_DBMS_FORMRIGHTS WHERE FRM_ID=".$this->myForm->getId();
  1005.             switch($this->myForm->getFrmMode())
  1006.             {
  1007.                 case FRM_COPY:
  1008.                     $str_query.=" AND FRI_SHOW=1";
  1009.                 case FRM_NEW:
  1010.                     $str_query.=" AND FRI_INSERT=1";
  1011.                     break;
  1012.                 case FRM_EDIT:
  1013.                     $str_query.=" AND FRI_SHOW=1";
  1014.                     $str_query.=" AND FRI_UDPDATE=1";
  1015.                     break;
  1016.                 case FRM_MODE_DELETE:
  1017.                     $str_query.=" AND FRI_SHOW=1";
  1018.                     $str_query.=" AND FRI_DELETE=1";
  1019.                     break;
  1020.                 default:
  1021.                     $str_query.=" AND FRI_SHOW=1";
  1022.             }
  1023.             
  1024.             if ($debugechoDebugLine(__FILE__,__LINE__,"rights query: <br />".$str_query."<pre>".print_r($arr_groups,True)."</pre>");            
  1025.             if ($arr_groups=$this->myDBObj->queryArray($str_query,0))
  1026.             {            
  1027.                 foreach($arr_groups as $int_grpId)
  1028.                 {
  1029.                     if ($obj_user->isGroupMember($int_grpId))
  1030.                     {
  1031.                         $this->checkRights_userRights[$obj_user->getId()][$mode]=true;
  1032.                         return true;
  1033.                     }
  1034.                 }
  1035.             else {
  1036.                 // no special settings for the form in the database found 
  1037.                   $this->checkRights_userRights[$obj_user->getId()][$mode]=true;
  1038.                 return true;                
  1039.             }
  1040.         else {
  1041.             if ($debugechoDebugLine(__FILE__,__LINE__,"returns True (no rows in T_DBMS_FORMRIGHTS)");
  1042.             return true;
  1043.         }
  1044.  
  1045.         $this->checkRights_userRights[$obj_user->getId()][$mode]=False;
  1046.         return False;
  1047.     }
  1048.  
  1049.     /**
  1050.      * if the form has a tableobject class getRowValue calls this
  1051.      * method to check if the current user is allowed to see the row
  1052.      *
  1053.      * NOTE: this leads to errors in counting as nofRows returns
  1054.      * the size of the list
  1055.      * 
  1056.      * @param string $methodName 
  1057.      */
  1058.     public function set_userCanShowMethod($methodName)
  1059.     {
  1060.         $this->userCanShowMethod $methodName;
  1061.     }
  1062.     
  1063. // end of OCSP_FRMCONTR
  1064. ?>

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