Source for file CLI_PROFILE_FORM.phpclass

Documentation is available at CLI_PROFILE_FORM.phpclass

  1. <?php
  2. /**
  3.   * Class file CLI_PROFILE_FORM.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    client
  7.   *
  8.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  9.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  10.   *
  11.   * @since pk-04-01-04
  12.   * @version $Id: CLI_PROFILE_FORM.phpclass,v 1.8 2008/11/25 16:24:07 peterkrebs Exp $
  13.   */
  14.  
  15. /**
  16.   * @requirements
  17.   */
  18.  
  19.     pcf_require_class('CLI_PROFILE',dirname(__FILE__)."/CLI_PROFILE.phpclass");
  20.     pcf_require_class('OCSP_FORM',__OCSP_PHPINCPATH__."db/forms/OCSP_FORM.phpclass");
  21.  
  22. /**
  23.   * Class CLI_PROFILE_FORM handels forms for client profiles
  24.   * overwrites DBMS_FORM database functions to store the form in
  25.   * a row of T_CLI_PROFILES instead of T_DBMS_FORM
  26.   *
  27.   * @project    Open CSP-Management
  28.   * @package    client
  29.   *
  30.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  31.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  32.   *
  33.   * @since pk-04-01-04
  34.   * @version pk-05-09-14
  35.   * @version pk-06-10-22
  36.   * @version $Id: CLI_PROFILE_FORM.phpclass,v 1.8 2008/11/25 16:24:07 peterkrebs Exp $
  37.   */
  38. class CLI_PROFILE_FORM extends OCSP_FORM {
  39.  
  40.     /*** class constants  --------------------------------------------- */
  41.  
  42.     /**
  43.       * @constant string CLASS_SRC_FILE
  44.       */
  45.     const CLASS_SRC_FILE = __FILE__;
  46.  
  47.     /*** Compositions: */
  48.  
  49.     /**
  50.       * @var CLI_PROFILE $myProfile 
  51.       * @since pk-06-10-22
  52.       ***/
  53.     protected $myProfile=NULL;
  54.  
  55.     /*** Attributes: */
  56.  
  57.     /**
  58.       * @var int $CLP_ID 
  59.       ***/
  60.     protected $CLP_ID=0;
  61.  
  62.     /**
  63.       * @var string $column the column in T_CLI_PROFILES where the form is stored
  64.       ***/
  65.     protected $column="CLP_INPUTFORM";
  66.     
  67.     /**
  68.      * @var boolean $profileTblObjInit 
  69.      * @access protected
  70.      */
  71.     protected $profileTblObjInit=False;
  72.  
  73.  
  74.  
  75.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  76.     // profile methods
  77.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  78.  
  79.     /**
  80.       * returns the profile ID
  81.       *
  82.       * @return int 
  83.       *
  84.       * @since pk-06-10-22
  85.       *
  86.       ***/
  87.     function getProfileId({
  88.         return intval($this->CLP_ID);
  89.     }
  90.  
  91.     /**
  92.       * @param int $aId 
  93.       * @since pk-07-10-07
  94.       */
  95.     function setProfileId($aId)
  96.     {
  97.         $this->CLP_ID=intval($aId);
  98.     }
  99.  
  100.     /**
  101.       * returns the profile object
  102.       *
  103.       * @param boolean $debug 
  104.       *
  105.       * @return CLI_PROFILE 
  106.       *
  107.       * @since pk-06-10-22
  108.       *
  109.       ***/
  110.     function &getProfileObj($debug=False{
  111.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE_FORM::getProfileObj()");
  112.  
  113.         if (pcf_is_instance_of($this->myProfile,'CLI_PROFILE'&& ($this->myProfile->getId==$this->getProfileId())) {
  114.             return $this->myProfile;
  115.         }
  116.  
  117.         if ($debugechoDebug(__FILE__,"<p>generate new profile object</p>");
  118.         $this->myProfile=new CLI_PROFILE(0,intval($this->getProfileId()));
  119.         return $this->myProfile;
  120.     }
  121.  
  122.     /**
  123.       * sets the profile object
  124.       *
  125.       * @param CLI_PROFILE $aProfile 
  126.       *
  127.       * @since pk-06-10-22
  128.       *
  129.       ***/
  130.     function setProfileObj(&$aProfile{
  131.         if (pcf_is_instance_of($aProfile,'CLI_PROFILE')) {
  132.             $this->myProfile=$aProfile;
  133.             $this->CLP_ID=$aProfile->getId();
  134.         }
  135.     }
  136.  
  137.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  138.     // DB FORM methods
  139.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  140.  
  141.     /**
  142.      * add some values to the forms (hidden) command fields
  143.      * 
  144.      * @param boolean $debug 
  145.      * 
  146.      * @return array 
  147.      * 
  148.      * @since pk-07-12-17
  149.      * 
  150.      */    
  151.     function getFormCmdFields($debug=False)
  152.     {
  153.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE_FORM::getFormCmdFields()");
  154.         
  155.         $arr_ret=parent::getFormCmdFields($debug);
  156.  
  157.         $arr_ret['CLP_ID']=$this->getProfileId();
  158.         
  159.         if (is_object($this->myProfile))
  160.         $arr_ret['CLP_CLASS']=get_class($this->myProfile);
  161.         $arr_ret['CLP_SRC']    =$this->myProfile->get_mySourceFile();
  162.                 
  163.         $arr_ret[$this->myProfile->getKeyColName()$this->getControl()->getCurValue($this->myProfile->getKeyColName());
  164.         
  165.         return $arr_ret;
  166.     }
  167.     
  168.     
  169.     
  170.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  171.     // Form methods
  172.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  173.  
  174.     /**
  175.      * sets the tableobject class and include from $dataArr and
  176.      * tries to instantiate by calling $this->getMyTblObj
  177.      * 
  178.      * if class is set in $dataArr and it could not be instantiated False is returned
  179.      * else True is returned
  180.      * 
  181.      * @param array $dataArr (normaly $_POST)
  182.      * @param boolean $debug 
  183.      * 
  184.      * @return boolean 
  185.      * 
  186.      * @since pk-07-12-05
  187.      * 
  188.      */
  189.     function setTblObjFromSubmitData(&$dataArr,$debug=False)
  190.     {
  191.         require_once __OCSP_PHPINCPATH__."common/pcf_md5.phpinc";
  192.              
  193.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE_FORM::setTblObjFromSubmit()");
  194.         
  195.         if (isset($dataArr[get_class($this)."_CMDS"]))
  196.         {
  197.             $arr_frmCmds=unserialize(pcfmd5_decrypt($dataArr[get_class($this)."_CMDS"]));
  198.         else {
  199.             $arr_frmCmds=NULL;    
  200.         }
  201.         
  202.         if ($debugechoDebugLine(__FILE__,__LINE__,"FORMCMDS: <pre>".print_r($arr_frmCmds,True)."</pre>");
  203.         
  204.         $str_valKey=(isset($dataArr['FRMARRAYNAME']$dataArr['FRMARRAYNAME'"DBVAL");
  205.  
  206.         if (isset($dataArr[$str_valKey]['CLP_ID']&& intval($dataArr[$str_valKey]['CLP_ID'])) 
  207.         {
  208.             // profile in post array 
  209.             $this->setProfileId(intval($dataArr[$str_valKey]['CLP_ID']));
  210.         else if (isset($arr_frmCmds['CLP_ID']&& intval($arr_frmCmds['CLP_ID'])) {
  211.             $this->setProfileId(intval($arr_frmCmds['CLP_ID']));
  212.         }
  213.                 
  214.         
  215.         if (intval($this->getProfileId()))
  216.         {
  217.             if (isset($arr_frmCmds['CLP_CLASS']&& !empty($arr_frmCmds['CLP_CLASS']))
  218.             {
  219.                 if (!class_exists($arr_frmCmds['CLP_CLASS'])) {
  220.                     if (!empty($arr_frmCmds['CLP_SRC']&& file_exists($arr_frmCmds['CLP_SRC']))
  221.                     {
  222.                         require_once $arr_frmCmds['CLP_SRC'];
  223.                     else {
  224.                         $arr_frmCmds['CLP_CLASS']="CLI_PROFILE";
  225.                     }
  226.                 }
  227.             else {
  228.                 $arr_frmCmds['CLP_CLASS']="CLI_PROFILE";
  229.             }
  230.             
  231.             $i_projId=(isset($dataArr[$str_valKey]['PROJ_ID']intval($dataArr[$str_valKey]['PROJ_ID']0);
  232.             
  233.             $str_cmd="\$this->myProfile=new ".$arr_frmCmds['CLP_CLASS']."($i_projId,".$this->getProfileId().");";
  234.             
  235.             if ($debugechoDebugLine(__FILE__,__LINE__,"PROFILE_CMD: ".$str_cmd);
  236.             eval($str_cmd);
  237.             
  238.             if (pcf_is_instance_of($this->myProfile,'CLI_PROFILE'))
  239.             {
  240.                 $this->myTblObj=$this->myProfile->getEntryObj();
  241.                 $dataArr[$str_valKey]['CLP_ID']=$this->myProfile->getId();
  242.                 if (isset($dataArr[$str_valKey]['CLP_IDX']))
  243.                 {
  244.                     $this->myTblObj->setDBField('CLP_IDX',$dataArr[$str_valKey]['CLP_IDX']);
  245.                 else {
  246.                     if (!isset($dataArr[$str_valKey][$this->myProfile->getKeyColName()]|| empty($dataArr[$str_valKey][$this->myProfile->getKeyColName()])) 
  247.                     {
  248.                         if ($debugechoDebugLine(__FILE__,__LINE__,"<p>setting foreign key : " $this->myProfile->getKeyColName(" from frmCmd value to " $arr_frmCmds[$this->myProfile->getKeyColName()])
  249.                         $dataArr[$str_valKey][$this->myProfile->getKeyColName()$arr_frmCmds[$this->myProfile->getKeyColName()];
  250.                         $this->myTblObj->setDBField($this->myProfile->getKeyColName(),$arr_frmCmds[$this->myProfile->getKeyColName()],$debug);               
  251.                     }
  252.                 }
  253.                 if ($debugechoDebugLine(__FILE__,__LINE__,'table object set');
  254.                 return True;
  255.             }
  256.                         
  257.             
  258.         }
  259.         
  260.         return parent::setTblObjFromSubmitData($dataArr,$debug);
  261.             
  262.     }        
  263.     
  264.     /**
  265.       * @param DBMS_TABLE_OBJ $tblObj 
  266.       * @param boolean $debug 
  267.       */
  268.     function setMyTblObj(&$tblObj,$debug=False)
  269.     {
  270.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE_FORM::setMyTblObj(".get_class($tblObj).")");
  271.  
  272.         parent::setMyTblObj($tblObj,$debug);
  273.         if (method_exists($this->myTblObj,'getProfileObj'))
  274.         {
  275.             $obj_profile=$this->myTblObj->getProfileObj();
  276.             if (intval($obj_profile->getId()))
  277.             {
  278.                 $this->setProfileObj($this->myTblObj->getProfileObj());
  279.             }
  280.         }
  281.     }
  282.  
  283.     /**
  284.       * @param boolean $force (if false only $this->myTblObj is returned else it tries to instantiate a new object)
  285.       * @param boolean $debug 
  286.       *
  287.       * @return DBMS_TABLE_OBJ 
  288.       *
  289.       * @requires common/pcf_templates.phpinc
  290.       */
  291.     function &getMyTblObj($force=False,$debug=False)
  292.     {
  293.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE_FORM::getMyTblObj()","myTblObj: ".get_class($this->myTblObj));
  294.  
  295.         if (pcf_is_instance_of($this->myTblObj,'CLI_PROFILE_ENTRY'))
  296.         {
  297.             if ($debugechoDebugLine(__FILE__,__LINE__,'Returning exisiting object');
  298.             return $this->myTblObj;
  299.         }
  300.         
  301.         if ($force && (pcf_is_instance_of($this->myProfile,'CLI_PROFILE')))
  302.         {
  303.             if ($debugechoDebugLine(__FILE__,__LINE__,'Returning new object');
  304.             $this->myTblObj = $this->myProfile->getEntryObj();
  305.             return $this->myTblObj;
  306.         }
  307.         
  308.         
  309.         if ($debugechoDebugLine(__FILE__,__LINE__,"<hr />Getting TblObj");
  310.         
  311.         if (!$obj_ret parent::getMyTblObj($force,$debug))
  312.         {
  313.             if (!$force)
  314.             {
  315.                 return $obj_ret;
  316.             }
  317.             // generate a PROFILE ENTRY object
  318.             if (!class_exists('CLI_PROFILE_ENTRY'))
  319.             {
  320.                 require_once dirname(__FILE___OCSP_DIRSEP_ "CLI_PROFILE_ENTRY.phpclass";
  321.             }
  322.             $this->myTblObj = new CLI_PROFIL_ENTRY();
  323.         }
  324.         
  325.         if ($debugechoDebugLine(__FILE__,__LINE__,"Getting TblObj done <hr />");
  326.         if (method_exists($this->myTblObj,'setProfileObj'))
  327.         {
  328.             if (!intval($this->myTblObj->getProfileId()))
  329.             {
  330.                 $this->myTblObj->setProfileObj($this->myProfile,$debug);
  331.                 if (!intval($this->myTblObj->getDBField($this->myProfile->getKeyColName())))
  332.                 {
  333.                     $this->myTblObj->setDBField($this->myProfile->getKeyColName(),$this->myProfile->getForeignKey());
  334.                 }
  335.             else {
  336.                 
  337.                 $this->setProfileObj($this->myTblObj->getProfileObj($debug));
  338.             }
  339.         }
  340.  
  341. //if ($debug) echoDebugLine(__FILE__,__LINE__,"Returning ".($obj_ret->isPopulated() ? "<b>populated</b>" : "not populated")." Object of ".get_class($obj_ret));
  342.         if ($debugechoDebugLine(__FILE__,__LINE__,"Returning  Object of ".get_class($obj_ret));
  343.         return $this->myTblObj;
  344.     }
  345.  
  346.     /**
  347.       * @abstract for child objects to init on checkSubmitData
  348.       *
  349.       * @param array $frmSettings 
  350.       * @param string $dataArrName 
  351.       * @param array $frmValues 
  352.       * @param boolean $debug 
  353.       */
  354.     function initCheckSubmitData(&$frmSettings,$dataArrName,&$frmValues,$debug=False)
  355.     {
  356.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE_FORM::initCheckSubmitData()");
  357.         
  358.         if ($debugecho "<pre>frmSettings: \n".print_r($frmSettings,True)."</pre>";
  359.         
  360.         if (!isset($frmValues[$dataArrName]['CLP_ID']|| !intval($frmValues[$dataArrName]['CLP_ID']))
  361.         {
  362.             if (intval($frmSettings['FILTER']['CLP_ID']))
  363.             {
  364.                 $frmValues[$dataArrName]['CLP_ID']=intval($frmSettings['FILTER']['CLP_ID']);
  365.                 $this->setProfileId($frmValues[$dataArrName]['CLP_ID']);
  366.             }
  367.             if (intval($this->getProfileId()))
  368.             {
  369.                 $frmValues[$dataArrName]['CLP_ID']=$this->getProfileId();
  370.             }
  371.         else {
  372.             $this->setProfileId($frmValues[$dataArrName]['CLP_ID']);
  373.         }
  374.  
  375.         if ($frmSettings['MODE'== FRM_MODE_EDIT)
  376.         {
  377.             if (!isset($frmValues[$dataArrName]['CLP_IDX']|| !intval($frmValues[$dataArrName]['CLP_IDX']))
  378.             {
  379.                  if (intval($frmSettings['FILTER']['CLP_IDX']))
  380.                  {
  381.                      $frmValues[$dataArrName]['CLP_IDX']=$frmSettings['FILTER']['CLP_IDX'];
  382.                  }
  383.             }
  384.         }                
  385.     }
  386.     
  387.  
  388.  
  389.  
  390. }
  391. ?>

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