Source for file CLI_PROFILE.phpclass

Documentation is available at CLI_PROFILE.phpclass

  1. <?php
  2. /**
  3.   * Class file CLI_PROFILE.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    client
  7.   * @category   profile
  8.   *
  9.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   * 
  12.   * @version $Id$
  13.   */
  14.  
  15.     // ---------------------------------------------------------
  16.     // requirements
  17.     // ---------------------------------------------------------
  18.  
  19.  
  20.     if (!defined('_CLIENT_CONFIGURED_')) require_once __OCSP_DEFAULTCONFPATH__."client.conf.phpinc";
  21.     if (!defined('_CMS_CONFIGURED_')) require_once __OCSP_DEFAULTCONFPATH__."cms.conf.phpinc";
  22.  
  23.     pcf_require_interface('INFA_CLI_PROFILE',"client/");
  24.     
  25.     pcf_require_class('CMS_TABLEOBJ',"cms/");
  26.     pcf_require_class('CLI_PROFILE_FORM',"client/");
  27.     pcf_require_class('CLI_PROFILE_ENTRY',"client/");
  28.     
  29.  
  30. /**
  31.   * class to handel CLI_PROFILES
  32.   *
  33.   * @project    Open CSP-Management
  34.   * @package    client
  35.   * @category   profile
  36.   *
  37.   * @author Peter Krebs <pitlinz@users.sourceforge.net>
  38.   * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  39.   * 
  40.   * @version $Id:$
  41.   *  
  42.   * @todo       errorhandling like DBMS_FORM
  43.   *
  44.   */
  45. class CLI_PROFILE extends CMS_TABLEOBJ implements INFA_CLI_PROFILE 
  46. {
  47.     
  48.     /*** class constants  --------------------------------------------- */
  49.  
  50.     /**
  51.       * @constant string CLASS_SRC_FILE
  52.       */
  53.     const CLASS_SRC_FILE = __FILE__;
  54.  
  55.     // ---------------------------------------------------------------------------
  56.     // class (static)
  57.     // ---------------------------------------------------------------------------
  58.     
  59.     /*** class vars ------------------------------------------------------ */
  60.     
  61.     /**
  62.      * unit of work
  63.      *
  64.      * @staticvar array $loadedProfiles 
  65.      */
  66.     protected static $loadedProfiles array();
  67.     
  68.     /*** class methods --------------------------------------------------- */
  69.     
  70.     /**
  71.      * returns the unit of work instance
  72.      *
  73.      * @param int $aId 
  74.      * 
  75.      * @return CLI_PROFILE 
  76.      */
  77.     public static function &getInstance($aId)
  78.     {
  79.         if (intval($aId)) 
  80.         {
  81.             if (!isset(self::$loadedProfiles[intval($aId)]|| !pcf_is_instance_of(self::$loadedProfiles[intval($aId)],'CLI_PROFILE'))
  82.             {
  83.                 self::$loadedProfiles[intval($aId)self::factory_fromId(intval($aId));
  84.             }
  85.             return self::$loadedProfiles[intval($aId)];
  86.         }
  87.         
  88.         $obj_ret Null;
  89.         return $obj_ret;
  90.     }
  91.     
  92.     /**
  93.      * returns if we already have an instance of profile $aId
  94.      *
  95.      * @param int $aId 
  96.      * 
  97.      * @return boolean 
  98.      * 
  99.      * @since pk-09-01-02
  100.      */
  101.     public static function isInstanced($aId)
  102.     {
  103.         if (!isset(self::$loadedProfiles[intval($aId)])) 
  104.         {
  105.             return False;    
  106.         }
  107.         
  108.         return pcf_class_implements(self::$loadedProfiles[intval($aId)],'INVA_CLI_PROFILE');
  109.     }
  110.     
  111.     /**
  112.      * sets an instance
  113.      * 
  114.      * @param CLI_PROFILE $aProfile 
  115.      * 
  116.      * @since pk-09-01-02
  117.      */
  118.     public static function setInstance(&$aProfile)
  119.     {
  120.         if (pcf_class_implements($aProfile,'INFA_CLI_PROFILE'))
  121.         {
  122.             self::$loadedProfiles[$aProfile->getId()$aProfile;
  123.         }
  124.     }
  125.     
  126.     // ---------------------------------------------------------------------------
  127.     // object vars
  128.     // ---------------------------------------------------------------------------
  129.      
  130.     
  131.     
  132.     /**
  133.       * @staticvar string $myTable name of the db table
  134.       */
  135.     var $myTable="T_CLI_PROFILES";
  136.  
  137.     /**
  138.       * @staticvar string $colPrefix prefix of the table col names
  139.       */
  140.     var $colPrefix="CLP_";
  141.  
  142.     /**
  143.       * @staticvar string $myClassName name of the class to use in eval statements
  144.       */
  145.     var $myClassName="CLI_PROFILE";
  146.  
  147.     /**
  148.       * @var int $FKValue user/client/staff id
  149.       * @since pk-05-03-08
  150.       ***/
  151.     var $FKValue=0;
  152.  
  153.     /**
  154.       * @var string $classSrcFile source file of the class
  155.       * @since pk-05-08-08
  156.       ***/
  157.     var $myClassSrcFile=__FILE__;
  158.  
  159.     // ------------------------------------------------------
  160.     // construct / factory
  161.     // ------------------------------------------------------
  162.         
  163.     /**
  164.       * creates and initialize the object
  165.       *
  166.       * if $aId the object is populate and
  167.       * all other params are replaced
  168.       * with the database values
  169.       *
  170.       * @param  int     $projId 
  171.       * @param  int     $aId    if > 0 the object is populated
  172.       * @param  int     $grpId 
  173.       * @param  int     $pagId 
  174.       *
  175.       * @returns bool    is it populated ?
  176.       *
  177.       * @version pk-04-10-08
  178.       *
  179.       ***/
  180.     function CLI_PROFILE($projId=0,$aId=0,$grpId=0,$debug=False{
  181.         if ($debugecho "<hr /><p><b>CLI_PROFILE::CLI_PROFILE($projId,$aId,$grpId,$gDBIDX,$debug)</b> (".get_class($this).")</p><blockquote>";
  182.         $this->init($debug);
  183.         if (intval($aId)) {
  184.             $this->db_SetKey($this->colPrefix."ID",intval($aId));
  185.             $this->dbPopulate($debug);        // overwrites settings at the beginning
  186.         else {
  187.             $this->db_SetKey('PROJ_ID',intval($projId));
  188.             $this->setDBField('GRP_ID',intval($grpId));
  189.         }
  190.         if ($debugecho "</blockquote>";
  191.     }
  192.  
  193.     /**
  194.      * returns a profile object
  195.      *
  196.      * @param int $aId 
  197.      * @param boolean $debug 
  198.      * 
  199.      * @return CLI_PROFILE 
  200.      * 
  201.      * @since pk-08-01-25
  202.      */
  203.     public static function factory_fromId($aId,$debug=False)
  204.     {
  205.         return new CLI_PROFILE(0,$aId,0,$debug);
  206.     }
  207.     
  208.     public static function factory_entryObj($aId,$keyId,$clpIdx=0,$debug=False)
  209.     {
  210.         $obj_profile CLI_PROFILE::factory_fromId($aId);
  211.         $obj_entry $obj_profile->getEntryObj($keyId,$clpIdx,$debug);
  212.         return $obj_entry;
  213.     }
  214.     
  215.     
  216.     function getClassName({
  217.         return $this->myClassName;
  218.     }
  219.  
  220.     /**
  221.      * returns the id
  222.      *
  223.      * @return int 
  224.      ***/
  225.     function getId({
  226.         return $this->getDBField($this->colPrefix."ID");
  227.     }
  228.  
  229.     /**
  230.       * returns the grp id
  231.       *
  232.       * @returns int
  233.       *
  234.       * @since pk-05-02-24
  235.       *
  236.       ***/
  237.     function getGrpId({
  238.         return intval($this->getDBField('GRP_ID'));
  239.     }
  240.  
  241.    /**
  242.      * returns the Title
  243.      *
  244.      * @return string 
  245.      ***/
  246.     function getTitle({
  247.         return $this->getDBField($this->colPrefix."TITLE");
  248.     }
  249.  
  250.     /**
  251.       * returns if a profile allows multiple entries
  252.       *
  253.       * @return boolean 
  254.       *
  255.       * @since pk-04-10-11
  256.       *
  257.       ***/
  258.     function isMultiple({
  259.         return (intval($this->CLP_UNIQUEENTRYFalse TRUE);
  260.     }
  261.  
  262.     /**
  263.       * returns the number of entry rows required
  264.       * for the profile. This is used to create
  265.       * NULL Errormessages
  266.       *
  267.       * @returns int
  268.       *
  269.       * @since pk-04-10-12
  270.       *
  271.       ***/
  272.     function requiredNoR({
  273.         return (intval($this->CLP_MINENTRY));
  274.     }
  275.  
  276.     /**
  277.       * @returns int
  278.       *
  279.       * @since pk-05-08-21
  280.       * @version pk-06-10-24
  281.       *
  282.       ***/
  283.     function maxEntries({
  284.         if ($this->isMultiple()) {
  285.             if (intval($this->getDBField('CLP_MAXENTRY')) && (intval($this->CLP_MAXENTRY0)) {
  286.                 return intval($this->getDBField('CLP_MAXENTRY'));
  287.             else {
  288.                 return 2147483646// max integer -1
  289.             }
  290.         else {
  291.             return 1;
  292.         }
  293.     }
  294.  
  295.     /**
  296.       * sets the foreign key to the foreign table
  297.       *
  298.       * @param int $val 
  299.       *
  300.       * @since pk-05-03-08
  301.       * @version pk-06-10-23 (intval)
  302.       *
  303.       ***/
  304.     function setForeignKey($val{
  305.         $this->FKValue=intval($val);
  306.     }
  307.  
  308.  
  309.     /**
  310.       * returns the foreign key to the foreign table
  311.       *
  312.       * @returns int
  313.       *
  314.       * @since pk-05-03-08
  315.       * @version pk-06-10-23 (intval)
  316.       *
  317.       ***/
  318.     function getForeignKey({
  319.         return intval($this->FKValue);
  320.     }
  321.  
  322.  
  323.     /**
  324.       * @returns string
  325.       * @since pk-05-08-24
  326.       *
  327.       ***/
  328.     function getKeyTable({
  329.         return $this->CLP_KEYTABLE;
  330.     }
  331.  
  332.  
  333.     /**
  334.       * @returns boolean
  335.       * @since pk-07-01-11
  336.       ***/
  337.     function useInRegister({
  338.         return (intval($this->getDBField('CLP_USE_INREGISTER')) TRUE False);
  339.     }
  340.  
  341.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  342.     /*  ERROR HANDLING                                                          */
  343.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  344.  
  345.  
  346.     /**
  347.       * returns the profile empty error msg
  348.       *
  349.       * @returns string
  350.       *
  351.       * @since pk-04-10-12
  352.       *
  353.       ***/
  354.     function getEmptyErrMsg({
  355.         if (!empty($this->CLP_ENTRYERRMSG)) {
  356.             return $this->CLP_ENTRYERRMSG;
  357.         else {
  358.             return "Leeres Profil";
  359.         }
  360.     }
  361.  
  362.     /**
  363.       * resets profile errors
  364.       *
  365.       * @since pk-05-02-24
  366.       *
  367.       ***/
  368.     function clearErrors({
  369.         $this->ERRMSG=NULL;
  370.     }
  371.  
  372.     /**
  373.       * returns the profile error msg
  374.       *
  375.       * @param string $sep  is planed to
  376.       * @returns string
  377.       *
  378.       * @since pk-05-02-24
  379.       *
  380.       ***/
  381.     function getErrorMsg($sep="<br />"{
  382.         return $this->ERRMSG;
  383.     }
  384.  
  385.     /**
  386.       * inserts a new CLI_PROFILES to the database
  387.       *
  388.       * - calls parent::dbInsert()
  389.       * - creates profile table
  390.       *
  391.       * @param boolean $debug  show debug info
  392.       *
  393.       ***/
  394.     function dbInsert($debug=False{
  395.         if ($debugecho "<hr /><p><b>CLI_PROFILES:dbInsert($debug)</b></p><blockquote>";
  396.  
  397.         //if (!intval($this->CLP_DBVERSION))
  398.         $this->CLP_DBVERSION 2;
  399.         parent::dbInsert($debug);
  400.  
  401.         if ($this->getId()) {
  402.             $this->createEntryTbl($debug);
  403.             if (!parent::dbReplace($debug)) {
  404.                 if ($debugecho "<p style='color:red'>RETURNS False</p></blockquote>";
  405.                 return False;
  406.             }
  407.         }
  408.  
  409.         if ($debugecho "</blockquote><hr />";
  410.         return $this->getId();
  411.     }
  412.  
  413.     /**
  414.       * save the profile to db by replacing the row
  415.       * first check if CLP_TABLE is ok
  416.       *
  417.       * @param boolean $debug  show debug info
  418.       * @param boolean $ignorPopulated (if false the table MUST have been populated)
  419.       *
  420.       * @since pk-04-10-08
  421.       *
  422.       ***/
  423.     function dbReplace($debug=False,$ignorPopulated=False{
  424.         if ($debugecho "<hr /><p><b>CLI_PROFILES:dbReplace()</b></p><blockquote>";
  425.         $s_tblName=$this->getDBField('CLP_TABLE');
  426.         if (empty($s_tblName)) {
  427.             if (!$this->createEntryTbl($debug)) {
  428.                 return False;
  429.             }
  430.         else {
  431.             if (!$this->verifyEntryTbl($debug)) {
  432.                 return False;
  433.             }
  434.         }
  435.  
  436.         if ($debugecho "</blockquote>";
  437.         return parent::dbReplace($debug,$ignorPopulated);
  438.     }
  439.  
  440.     // #####################################################################
  441.  
  442.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  443.     /*  ENTRY TABLE Definition Methods                                                                                                                           */
  444.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  445.  
  446.     /**
  447.       * returns the key column name
  448.       *
  449.       * @returns string
  450.       *
  451.       * @since pk-05-09-23
  452.       *
  453.       ***/
  454.     function getKeyColName({
  455.         return $GLOBALS['OCSP_CLI']['PROFILETABLE'][$this->getDBField('CLP_KEYTABLE')]['KEY'];
  456.     }
  457.  
  458.  
  459.     /**
  460.       * checks if a $this->getDBField('CLP_TABLE') is a profile table
  461.       * Column CLP_ID must be AUTO_INCREMENT
  462.       * all other columns are added if not exists
  463.       *
  464.       * @params string $gDBIDX
  465.       * @param boolean $debug 
  466.       *
  467.       * @returns boolean
  468.       *
  469.       * @since pk-04-10-08
  470.       *
  471.       ***/
  472.     function verifyEntryTbl($debug=False{
  473.         if ($debugechoDebugMethod(__FILE__,__LINE__,"CLI_PROFILES:verifyEntryTbl($debug)");
  474.  
  475.         if (!$this->isConnected(TRUE,$debug))
  476.         {
  477.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  478.             return False;
  479.         }
  480.  
  481.         if ($this->myDBObj->tblExists($this->getDBField('CLP_TABLE'),$debug)) {
  482.             $tblDesc=$this->myDBObj->getDBTblDesc($this->getDBField('CLP_TABLE'),$debug);
  483.             $colDesc=array();
  484.  
  485.             if ($this->CLP_DBVERSION == 2$autoIncFld="CLP_IDX";
  486.             else                           $autoIncFld="CLP_ID";
  487.  
  488.  
  489.             if ((!isset($tblDesc[$autoIncFld])) || (!$tblDesc[$autoIncFld]['AUTO_INCREMENT']))  {
  490.                 echo "<p>Errorcolumn $autoIncFld not in table ".$this->getDBField('CLP_TABLE')." or CLP_ID is no AUTO_INC</p>";
  491.                 if ($debugecho "\$tblDesc=<pre>".print_r($tblDesc,TRUE)."</pre></blockquote>";
  492.                 return False;
  493.             }
  494.             $fkCol=$this->getKeyColName();
  495.             if (!isset($tblDesc[$fkCol])) {
  496.                 $colDesc[$fkColarray('TYPE'=>'int','LEN'=>11,'NULL'=>False);
  497.             }
  498.             if (!isset($tblDesc['CLP_ID'])) {
  499.                 $colDesc['CLP_ID'array('TYPE'=>'int','LEN'=>11,'NULL'=>False,'DEFAULT'=>$this->getId());
  500.             }
  501.             if (!isset($tblDesc['CLP_STATE'])) {
  502.                 $colDesc['CLP_STATE'array('TYPE'=>'int','LEN'=>4,'NULL'=>False,'DEFAULT'=>0);
  503.             }
  504.             if (!isset($tblDesc['CLP_UTIME'])) {
  505.                 $colDesc['CLP_UTIME'array('TYPE'=>'timestamp','NULL'=>False);
  506.             }
  507.             if (!isset($tblDesc['CLP_UUSER'])) {
  508.                 $colDesc['CLP_UUSER'array('TYPE'=>'int','NULL'=>False,'DEFAULT'=>0);
  509.             }
  510.             if (!isset($tblDesc['CLP_CTIME'])) {
  511.                 $colDesc['CLP_CTIME'array('TYPE'=>'timestamp','NULL'=>False);
  512.             }
  513.             if (!isset($tblDesc['CLP_CUSER'])) {
  514.                 $colDesc['CLP_CUSER'array('TYPE'=>'int','NULL'=>False,'DEFAULT'=>0);
  515.             }
  516.             if (!isset($tblDesc['CLP_RADDR'])) {
  517.                 $colDesc['CLP_RADDR'array('TYPE'=>'string','LEN'=>32,'NULL'=>TRUE,'DEFAULT'=>"\$REMOTE_ADDR\$");
  518.             }
  519.             if (!isset($tblDesc['CLP_HVIA'])) {
  520.                 $colDesc['CLP_HVIA'array('TYPE'=>'string','LEN'=>32,'NULL'=>TRUE,'DEFAULT'=>"\$HTTP_VIA\$");
  521.             }
  522.             if (!isset($tblDesc['CLP_HX_FORWD'])) {
  523.                 $colDesc['CLP_HX_FORWD'array('TYPE'=>'string','LEN'=>32,'NULL'=>TRUE,'DEFAULT'=>"\$HTTP_X_FORWARDED_FOR\$");
  524.             }
  525.  
  526.             if ($debugecho "<blockquote><p>\$colDesc</p><pre>".print_r($colDesc,TRUE)."</pre></blockquote>";
  527.  
  528.             foreach($colDesc as $colName => $dbDesc{
  529.                 $this->myDBObj->addColumn($this->getDBField('CLP_TABLE'),$colName,$dbDesc,$debug);
  530.             }
  531.             return TRUE;
  532.         else {
  533.             return False;
  534.         }
  535.     }
  536.  
  537.     /**
  538.       * creates a table for CLI_PROFILES entries
  539.       *
  540.       * @param string $gDBIDX Index of $GLOBALS to the db object
  541.       * @param boolean $debug  show debug info
  542.       * @returns boolean
  543.       *
  544.       * @version pk-04-10-08
  545.       *
  546.       * @todo col types are hardcoded mySQL -> change
  547.       *
  548.       ***/
  549.     function createEntryTbl($debug=False{
  550.         if ($debugecho "<hr /><p><b>CLI_PROFILES:createEntryTbl($gDBIDX,$debug)</b></p><blockquote>";
  551.  
  552.         if (!$this->isConnected(TRUE,$debug))
  553.         {
  554.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  555.             return False;
  556.         }
  557.  
  558.         if ($this->getId()) {
  559.             $s_tblName=$this->getDBField('CLP_TABLE');
  560.             if (empty($s_tblName)){
  561.                 $this->setDBField('CLP_TABLE',"T_CP_P".$this->colPrefix.$this->getProjId()."_PF".$this->getId());
  562.             }
  563.  
  564.             if ($this->myDBObj->tblExists($this->getDBField('CLP_TABLE'),$debug)) {
  565.                 $this->verifyEntryTbl($debug);
  566.             else {
  567.                 $this->CLP_DBVERSION=2;
  568.                 $cmd="CREATE TABLE ".$this->getDBField('CLP_TABLE')." (\n";
  569.                 $cmd.="CLP_IDX      INT NOT NULL AUTO_INCREMENT,\n";
  570.                 $cmd.="CLP_ID       INT NOT NULL,\n";
  571.                 $cmd.=$this->getKeyColName()."  INT NOT NULL,\n";
  572.                 $cmd.="CLP_STATE    TINYINT NOT NULL DEFAULT '0',\n";
  573.  
  574.                 $cmd.="PRIMARY KEY (CLP_IDX),";
  575.                 $cmd.="KEY (CLP_STATE,".$this->getKeyColName().")";
  576.                 $cmd.=")";
  577.                 if ($debugecho "<pre>$cmd</pre>";
  578.                 $this->myDBObj->executeCmd($cmd,$debug);
  579.                 return $this->verifyEntryTbl($debug);
  580.             }
  581.         else {
  582.             echo "<p>NO ID</p>";
  583.         }
  584.         if ($debugecho "</blockquote>";
  585.  
  586.         return $this->myDBObj->tblExists($this->getDBField('CLP_TABLE'),$debug);
  587.     }
  588.  
  589.     /**
  590.       * returns the entry table name
  591.       *
  592.       * @return string 
  593.       *
  594.       * @since pk-04-08-05
  595.       *
  596.       ***/
  597.     function getEntryTbl({
  598.         return $this->getDBField('CLP_TABLE');
  599.     }
  600.  
  601.  
  602.     /**
  603.       * returns the table desc of entry table
  604.       *
  605.       * @returns array
  606.       *
  607.       * @since pk-04-08-31
  608.       *
  609.       ***/
  610.     function getEntryTblDesc($debug=False{
  611.         if ($debugecho "<p><b>CLI_PROFILE::getEntryTblDesc(..)</b> (".get_class($this).")</p>";
  612.  
  613.         if (!$this->isConnected(TRUE,$debug))
  614.         {
  615.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  616.             return False;
  617.         }
  618.         return $this->myDBObj->getDBTblDesc($this->getEntryTbl(),$debug);
  619.     }
  620.  
  621.  
  622.     /**
  623.       * returns if for not multiple profiles the CLP_ID should
  624.       * be checked in the table or not.
  625.       *
  626.       * @returns boolean
  627.       * @since pk-06-10-11
  628.       ***/
  629.     function checkProfileIdInEntryQuery({
  630.         return (intval($this->getDBField('CLP_FRM_IGNORECLP_ID')) False TRUE);
  631.     }
  632.  
  633.  
  634.     /**
  635.       * returns an array with the columns of the entry table
  636.       * in case of an error an empty array is returned
  637.       *
  638.       * @returns array
  639.       *
  640.       * @since pk-05-02-26
  641.       *
  642.       ***/
  643.     function getEntryTblColumns($debug=False{
  644.         if ($debugecho "<p><b>CLI_PROFILE::getEntryTblColumns()</b> (".get_class($this).")</p>";
  645.         if ($desc=$this->getEntryTblDesc($debug)) {
  646.             return array_keys($desc);
  647.         else {
  648.             return array();
  649.         }
  650.     }
  651.  
  652.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  653.     /*  ENTRY object Methods                                                 */
  654.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  655.  
  656.     /**
  657.       * returns a (the first) entry row where keytable is $key and CLP_IDX is $idx
  658.       * if $key or $idx are 0 the are not included in the where
  659.       * useses $this->myDBObj->quickQuery()
  660.       *
  661.       * @param int $key 
  662.       * @param int $idx 
  663.       * @param boolean $debug 
  664.       * 
  665.       * @return array 
  666.       *
  667.       * @since pk-05-03-15
  668.       * @version pk-05-11-23
  669.       * @version pk-06-02-23
  670.       * @version pk-06-10-11
  671.       * @version pk-06-10-24
  672.       * @version pk-07-01-12 redesign of $key $idx checks
  673.       *
  674.       */
  675.     function getEntryRow($key=0,$idx=0,$debug=False{
  676.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::getEntryRow($key,$idx,...)");
  677.  
  678.         if (!intval($key&& !intval($idx)) {
  679.             return NULL;
  680.         }
  681.  
  682.         if (!$this->isConnected(TRUE,$debug))
  683.         {
  684.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_WARNING);
  685.             return NULL;
  686.         }
  687.  
  688.         $s_query=$this->getETblJoinSelStmt();
  689.         if (intval($key)) {
  690.             $s_query.=" AND etbl.".$this->getKeyColName()." = ".intval($key);
  691.         }
  692.  
  693.         if (intval($idx)) {
  694.             $s_query.=" AND etbl.CLP_IDX=".intval($idx);
  695.         }
  696.  
  697.         if ((!intval($key|| !intval($idx)) && ($this->isMultiple())) // <pk-05-11-23 /><pk-06-10-24 /> avoid the return of wrong rows
  698.             return NULL;
  699.         }
  700.         if ($debugechoDebugLine(__FILE__,__LINE__,"<blockquote><p>Query$s_query</p></blockquote>");
  701.         return $this->myDBObj->quickQuery($s_query);
  702.     }
  703.  
  704.     /**
  705.       * @param int $aKey 
  706.       * @param int $idx 
  707.       * @param boolean $debug 
  708.       *
  709.       * @return CLI_PROFILE_ENTRY 
  710.       */
  711.     function getEntryObj($key=NULL,$idx=0,$debug=False)
  712.     {
  713.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::getEntryObj($aKey,$idx)");
  714.  
  715.         if (!intval($key))
  716.         {
  717.             $key=$this->getForeignKey();
  718.         else {
  719.             $this->setForeignKey(intval($key));
  720.         }
  721.  
  722.         $obj_ret new CLI_PROFILE_ENTRY();
  723.         $obj_ret->setProfileObj($this,$debug);
  724.  
  725.         if (!($arr_entryRow=$this->getEntryRow($key,$idx,$debug)))
  726.         {
  727.             $arr_entryRow=$obj_ret->getDefaults();
  728.             $arr_entryRow['CLP_ID']=$this->getId();
  729.             $arr_entryRow[$this->getKeyColName()]=$this->getForeignKey();
  730.         }
  731.         
  732.         $b_asPopulated=(intval($arr_entryRow['CLP_IDX']&& intval($arr_entryRow[$this->getKeyColName()]));
  733.         $obj_ret->setDBRow($arr_entryRow,$b_asPopulated,$debug);
  734.  
  735.         return $obj_ret;
  736.     }
  737.  
  738.     /**
  739.       * @param int $mode 
  740.       * @param boolean $debug 
  741.       *
  742.       * @return mixed (the form id or the entry table name if form id is not set)
  743.       */
  744.     function getEntryTblFormIdName($mode,$debug=False)
  745.     {
  746.         if($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::getEntryTblFormIdName($mode)");
  747.  
  748.         switch($mode)
  749.         {
  750.             case FRM_MODE_LIST:
  751.                 if (intval($this->getDBField('CLP_FRMLST_ID')))
  752.                 {
  753.                     return intval($this->getDBField('CLP_FRMLST_ID'));
  754.                 }
  755.             default:
  756.                 if (intval($this->getDBField('CLP_FRM_ID')))
  757.                 {
  758.                     return intval($this->getDBField('CLP_FRM_ID'));
  759.                 }
  760.                 if ($debugocsp_logError(__FILE__,__LINE__,"Form Id not set",E_WARNING);
  761.                 return $this->getEntryTbl();
  762.         }
  763.     }
  764.  
  765.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  766.     /*  ENTRY TABLE Value Form Methods                                       */
  767.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  768.  
  769.     /**
  770.       * @deprecated since ???
  771.       */
  772.     function &dbGetProfileForm($frmName,$i_frmMode,$debug=False)
  773.     {
  774.         return $this->getEntryForm($i_frmMode,$frmName,$debug);
  775.     }
  776.  
  777.     /**
  778.       * returns a ponter to a formObj to use with the entry
  779.       *
  780.       * @param int $mode 
  781.       * @param string $frmName 
  782.       * @param boolean $debug 
  783.       *
  784.       * @returns CLI_PROFILE_FORM
  785.       *
  786.       * @version pk-06-10-22
  787.       * @version pk-06-12-21
  788.       *
  789.       ***/
  790.     function &getEntryForm($mode=FRM_MODE_READONLY,$frmName="",$debug=False{
  791.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::getEntryForm()");
  792.  
  793.         $o_frmObj=NULL;
  794.         if (!empty($frmName))
  795.         {
  796.             $o_frmObj=OCSP_FORM::factory_from_name($frmName,'CLI_PROFILE_FORM',$debug);
  797.         }
  798.  
  799.         if (!pcf_is_instance_of($o_frmObj,'OCSP_FORM'))
  800.         {
  801.             if ($mode==FRM_MODE_LIST)
  802.             {
  803.                 $i_frmId=(intval($this->getDBField('CLP_FRMLST_ID')) intval($this->getDBField('CLP_FRMLST_ID')) intval($this->getDBField('CLP_FRM_ID')));
  804.                 if (intval($i_frmId))
  805.                 {
  806.                     $o_frmObj=OCSP_FORM::factory_from_id($i_frmId,'CLI_PROFILE_FORM',$debug);
  807.                 else {
  808.                     ocsp_logError(__FILE__,__LINE__,"could not get list form id",E_WARNING);
  809.                 }
  810.             else if (intval($this->getDBField('CLP_FRM_ID'))) {
  811.                 $o_frmObj=OCSP_FORM::factory_from_id(intval($this->getDBField('CLP_FRM_ID')),'CLI_PROFILE_FORM',$debug);
  812.             else {
  813.                 ocsp_logError(__FILE__,__LINE__,"could not get form id",E_WARNING);
  814.             }
  815.         }
  816.  
  817.         if (pcf_is_instance_of($o_frmObj,'CLI_PROFILE_FORM'))
  818.         {
  819.             $o_frmObj->setProfileObj($this);
  820.             $o_frmObj->setDBObj($this->getDBObj());
  821.             return $o_frmObj;
  822.         }
  823.  
  824.         echo "<p>FormClass: <b>".get_class($o_frmObj)."</b></p>";
  825.  
  826.         ocsp_logError(__FILE__,__LINE__,"could not load the form for profile: ".$this->getTitle()." ID: ".$this->getId(),E_WARNING);
  827.         return $o_frmObj;
  828.  
  829.     }
  830.  
  831.  
  832.     /**
  833.       * inserts a posted form array into the content table
  834.       *
  835.       * @param CLI_PROFILE_FORM $frmObj 
  836.       * @param array $DBVAL 
  837.       * @param string $arrName 
  838.       * @param boolean $noEmptyCheck 
  839.       * @param boolean $debug 
  840.       *
  841.       * @returns bool
  842.       *
  843.       * @version pk-05-03-03
  844.       * @version pk-05-11-04
  845.       * @version pk-06-10-10
  846.       *
  847.       ***/
  848.     function insertPOSTEntry(&$frmObj,$DBVAL,$arrName="DBVAL",$noEmptyCheck=False,$debug=False{
  849.         if ($debug)  echo "<p><b>CLI_PROFILE::insertPOSTEntry(...)</b> (".get_class($this).")</p>";
  850.  
  851.         $o_eTbl=new CLI_PROFILE_ENTRY(0);
  852.         $o_eTbl->setProfileObj($this);
  853.  
  854.         if (!pcf_is_instance_of($frmObj,"CLI_PROFILE_FORM")) {
  855.             if (!($frmObj=$this->dbGetProfileForm("CLP_INPUTFORM",FRM_MODE_NEW,$debug))) {
  856.                 if ($debugecho "<p>\$frmObj is not an instance of DBMS_FORM</p>";
  857.                 return False;
  858.             }
  859.         else {
  860.             $o_tmpfrmObj=new CLI_PROFILE_FORM("CLP_INPUTFORM",$this->getId(),$this->getDBField('CLP_TABLE'));
  861.             $o_tmpfrmObj->setDBMSValues($frmObj);
  862.             if (intval($this->getDBField('CLP_FRM_IGNORECLP_ID'))) {
  863.                 $o_tmpfrmObj->hideField('CLP_ID');
  864.             }
  865.             $GLOBALS['DBMS_FORMS'][$o_tmpfrmObj->getId()]=$o_tmpfrmObj;
  866.             $frmObj=&$GLOBALS['DBMS_FORMS'][$o_tmpfrmObj->getId()];
  867.         }
  868.  
  869.         $i_pfId=(isset($DBVAL['CLP_ID']intval($DBVAL['CLP_ID']0);
  870.         if ($i_pfId != $this->getId())  {
  871.             $DBVAL['CLP_ID']=$this->getId();
  872.         }
  873.  
  874.         $fkCol=$GLOBALS['OCSP_CLI']['PROFILETABLE'][$this->CLP_KEYTABLE]['KEY'];
  875.         // <pk-05-11-04> set $this->FKValue if in $DBVAL
  876.         //               to avoid null values if field is hidden
  877.         if (isset($DBVAL[$fkCol]&& intval($DBVAL[$fkCol])) {
  878.             $this->FKValue=intval($DBVAL[$fkCol]);
  879.         else  if (strstr($DBVAL['_DBMS_FIELDS'],$fkCol)) {
  880.             $DBVAL[$fkCol]=$this->FKValue;
  881.         }
  882.         // </pk-05-11-04>
  883.  
  884.         $o_eTbl->setFORMPOST($frmObj,$DBVAL,$debug,TRUE,TRUE);
  885.         if (!$this->checkEntryRowArr($o_eTbl->getDBVal(),$debug)) {
  886.             if ($debugecho "<p>checkEntryRowArr returned FLASE</p></blockquote>";
  887.             $frmObj->setError($this->getErrorMsg,$this->colPrefix."ID");
  888.             return False;
  889.         }
  890.         return $o_eTbl->dbSave($this->get_gDBIDX(),$debug);
  891.  
  892.     }
  893.  
  894.     /**
  895.       * updates a posted form array into the content table
  896.       *
  897.       * @param CLI_PROFILE_FORM $frmObj 
  898.       * @param array $DBVAL 
  899.       * @param string $arrName 
  900.       * @param boolean $noEmptyCheck 
  901.       * @param boolean $debug 
  902.       *
  903.       * @returns bool
  904.       *
  905.       * @version pk-05-03-03
  906.       *
  907.       ***/
  908.     function updatePOSTEntry(&$frmObj,$DBVAL,$arrName="DBVAL",$noEmptyCheck=False,$debug=False{
  909.         if ($debugecho "<p><b>CLI_PROFILE::updatePOSTEntry(...)</b> (".get_class($this).")</p>";
  910.         return $this->insertPOSTEntry($frmObj,$DBVAL,$arrName,False,$debug);
  911.     }
  912.  
  913.     /**
  914.       * returns if a profile post has data
  915.       * postVals are not null and not equal to form defaults
  916.       *
  917.       * @param DBMS_FORM $frmObj 
  918.       * @param array $postVals 
  919.       * @param boolean $debug 
  920.       * @param boolean $noDefaultChk 
  921.       *
  922.       * @returns boolen
  923.       *
  924.       * @since pk-05-02-26
  925.       *
  926.       * @version pk-05-03-03
  927.       * @version pk-05-08-22 param no defaultchk added
  928.       * @version pk-05-11-08 debug info
  929.       *
  930.       ***/
  931.     function postArrHasData(&$frmObj,$postVals,$debug=False,$noDefaultChk=False{
  932.         if ($debugecho "<p><b>CLI_PROFILE::postArrHasData(...)</b> (".get_class($this).")</p>"// <pk-05-11-08 />
  933.         $frmDefVals=$frmObj->getDefaultValArr();
  934.  
  935.         if (!is_array($postVals)) return False;
  936.         if (implode(",",$postVals!= $postVals['_DBMS_FIELDS']{
  937.             // ok it is not empty but are the values only the default values
  938.  
  939.             if ((!empty($postVals['_DBMS_FIELDS'])) && ($flds=explode(",",$postVals['_DBMS_FIELDS']))) {
  940.                 // we have an OCSP Form Post array
  941.             else {
  942.                 // array is not a valid OCSP Form Post check with all fields
  943.                 $flds=getEntryTblColumns($debug=False);
  944.             }
  945.  
  946.             if ($debugecho "<p>Checking DefaultVals for fields:<p>";
  947.             if (is_array($flds)) {
  948.                 foreach ($flds as $fldIdx{
  949.                     if (!empty($postVals[$fldIdx])) //<pk-05-08-22>
  950.                         if ($postVals[$fldIdx!= $frmDefVals[$fldIdx]{
  951.                             if ($debugecho "<blockquote><p>profilePostHasData() returns <b>TURE</b><p></blockquote>";
  952.                             return TRUE;
  953.                         else if ($noDefaultChk// <pk-05-08-22>
  954.                             if ($debugecho "<blockquote><p>Field $fldIdx not empty</p></blockquote>";
  955.                             return TRUE;
  956.                         }
  957.                     // </pk-05-08-22>
  958.                 }
  959.             }
  960.         }
  961.  
  962.         if ($debugecho "<blockquote><p>profilePostHasData() returns <b>False</b></blockquote><p>";
  963.         return False;
  964.     }
  965.  
  966.     /**
  967.       * checks a array by including $GLOBALS['PROJECT']['PATH'].$this->CLP_ENTRYCHKIN
  968.       *
  969.       * returns $retVal which can be set in the include (default: TRUE)
  970.       *
  971.       * @note $dbVal is called by referenze so can be changed in the check include.
  972.       *
  973.       * @param array &$dbVal 
  974.       * @param boolean $debug 
  975.       *
  976.       * @returns boolean
  977.       *
  978.       ***/
  979.     function checkEntryRowArr(&$dbVal,$debug=False{
  980.         if ($debugecho "<p><b>CLI_PROFILES::checkEntryRowArr(...)</b> (".get_class($this).")</p>";
  981.  
  982.         $retVal=TRUE;
  983.         if (!empty($this->CLP_ENTRYCHKINC)) {
  984.             if (file_exists($GLOBALS['PROJECT']['PATH'].$this->CLP_ENTRYCHKINC)) {
  985.                 include $GLOBALS['PROJECT']['PATH'].$this->CLP_ENTRYCHKINC;
  986.             else {
  987.                 $this->ERRMSG="SYSTEMERROR: Werte konnten nicht berprft werden";
  988.                 return False;
  989.             }
  990.         }
  991.         if ($debugecho "<blockquote><p>RETURNS ".($retVal "TRUE" "False")."</p></blockquote>";
  992.         return $retVal;
  993.     }
  994.  
  995.  
  996.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  997.     //  ENTRY TABLE Value Data Methods                                      
  998.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  999.  
  1000.     /**
  1001.       * inserts an Row array into the entry table
  1002.       *
  1003.       * @param array $dbVal 
  1004.       * @param boolean $debug 
  1005.       *
  1006.       * @returns boolean
  1007.       *
  1008.       * @since pk-04-10-13
  1009.       * @version pk-04-11-17
  1010.       * @version pk-05-11-04
  1011.       *
  1012.       */
  1013.     function insertEntryRow($dbVal,$debug=False{
  1014.         if($debugecho "<p><b>CLI_PROFILES::insertEntryRow(...)</b> (".get_class($this).")</p>";
  1015.  
  1016.         $fkCol=$this->getKeyColName();
  1017.         if (!intval($dbVal[$fkCol])) {
  1018.             if (intval($this->FKValue)) {
  1019.                 $dbVal[$fkCol]=intval($this->FKValue);
  1020.             else  if (intval($_SESSION[$fkCol])) {
  1021.                 $dbVal[$fkCol]=intval($_SESSION[$fkCol]);
  1022.             else if (intval($_POST[$fkCol])) {
  1023.                 $dbVal[$fkCol]=intval($_POST[$fkCol]);
  1024.             else {
  1025.                 if ($debugecho "<p>\$dbVal[".$fkCol."] NOT SET</p>"// <pk-05-11-04>
  1026.                 return False;
  1027.             }
  1028.         }
  1029.  
  1030.         $colArr=array(
  1031.             "CLP_CTIME"     =>$this->myDBObj->qs_getNowStmt(),
  1032.             "CLP_CUSER"     =>$GLOBALS['USER']->getId(),
  1033.             "CLP_RADDR"     =>$_SERVER['REMOTE_ADDR'],
  1034.             "CLP_HVIA"      =>$_SERVER['HTTP_VIA'],
  1035.             "CLP_HX_FORWD"  =>$_SERVER['HTTP_X_FORWARDED_FOR']
  1036.         );
  1037.  
  1038.         /* <pk-04-11-17> */
  1039.         if ($this->CLP_DBVERSION == 2{
  1040.             $colArr['CLP_ID']=$this->getId();
  1041.         }
  1042.         /* </pk-04-11-17> */
  1043.  
  1044.         foreach($colArr as $col=>$defVal{
  1045.             if (empty($dbVal[$col])) $dbVal[$col]=$defVal;
  1046.         }
  1047.  
  1048.         if ($debugecho "<blockquote><p>dbVal:</p><pre>".print_r($dbVal,TRUE)."</pre></blockquote>";
  1049.  
  1050.         if (!$this->isConnected(TRUE,$debug))
  1051.         {
  1052.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1053.             return False;
  1054.         }
  1055.  
  1056.         return $this->myDBObj->insertArray($this->getEntryTbl(),$dbVal,$debug);
  1057.     }
  1058.  
  1059.     /**
  1060.       * updates an Row array into the entry table
  1061.       *
  1062.       * @param array $dbVal 
  1063.       * @param boolean $addNew 
  1064.       * @param boolean $debug 
  1065.       *
  1066.       * @returns boolean
  1067.       *
  1068.       * @since pk-04-10-15
  1069.       * @version pk-04-11-17
  1070.       * @version pk-05-11-04
  1071.       *
  1072.       ***/
  1073.     function updateEntryRow($dbVal,$addNew=TRUE,$debug=False{
  1074.         if($debugecho "<p><b>CLI_PROFILES::updateEntryRow(...)</b> (".get_class($this).")</p>";
  1075.  
  1076.         /* <pk-04-11-17> */
  1077.         if ($this->CLP_DBVERSION == 2{
  1078.             $dbVal['CLP_ID']=$this->getId();
  1079.         }
  1080.         /* </pk-04-11-17> */
  1081.  
  1082.  
  1083.         $query ="SELECT ".$this->getKeyColName().",CLP_IDX FROM ".$this->getEntryTbl();
  1084.  
  1085.         // <pk-05-11-04>
  1086.         //          select the row only by CLP_IDX
  1087.         //          to avoid errors if $fk chacnges
  1088.         $query.=" WHERE CLP_IDX=".$dbVal['CLP_IDX'];
  1089.         /*
  1090.         $query.=" WHERE ".$this->getKeyColName()."=".$fk;
  1091.         if (intval($dbVal['CLP_IDX'])) {
  1092.             $query.=" AND CLP_IDX=".$dbVal['CLP_IDX'];
  1093.         }
  1094.         */
  1095.         // </pk-05-11-04>
  1096.  
  1097.         if (!$this->isConnected(TRUE,$debug))
  1098.         {
  1099.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1100.             return False;
  1101.         }
  1102.  
  1103.         if (!$row=$this->myDBObj->quickQuery($query)) {
  1104.             if ($debugecho "<p>no data found $query</p>";
  1105.             if ($addNew{
  1106.                 return $this->insertEntryRow($dbVal,$debug);
  1107.             }
  1108.             return False;
  1109.         }
  1110.  
  1111.         foreach($dbVal as $key => $val{
  1112.             $row[$key]=$val;
  1113.         }
  1114.  
  1115.         $fk=intval($row[$this->getKeyColName()]);
  1116.         if (!$fk{
  1117.             if ($debugecho "<p>row[".$this->getKeyColName()."] not set</p>";
  1118.             return False;
  1119.         }
  1120.  
  1121.         if (!intval($row['CLP_CTIME'])) $row['CLP_CTIME']=$row['CLP_UTIME'];
  1122.         if (!intval($row['CLP_CUSER'])) $row['CLP_CUSER']=0;
  1123.         unset($row['CLP_UTIME']);
  1124.         $row['CLP_UUSER']=      $GLOBALS['USER']->getId();
  1125.         $row["CLP_RADDR"]=      $_SERVER['REMOTE_ADDR'];
  1126.         $row["CLP_HVIA"]=       $_SERVER['HTTP_VIA'];
  1127.         $row["CLP_HX_FORWD"]=   $_SERVER['HTTP_X_FORWARDED_FOR'];
  1128.         $row['CLP_ID']=         $this->getId();
  1129.  
  1130.         if ($this->checkEntryRowArr($row,$debug)) {
  1131.             return $this->myDBObj->replaceArray($this->getEntryTbl(),$row,$debug);
  1132.         else {
  1133.             return False;
  1134.         }
  1135.     }
  1136.  
  1137.     /**
  1138.       * deletes a row array
  1139.       *
  1140.       * @param int $keyVal 
  1141.       * @param int $idx 
  1142.       * @param boolean $debug 
  1143.       *
  1144.       * @returns boolean
  1145.       *
  1146.       * @since pk-05-03-22
  1147.       * @version pk-05-09-23
  1148.       *
  1149.       ***/
  1150.     function deleteEntryRow($keyVal,$idx=0,$debug=False{
  1151.         if ($debugecho "<p><b>CLI_PROFILE::deleteEntryRow($key,$idx...)</b> (".get_class($this).")</p>";
  1152.  
  1153.         $s_query="DELETE FROM ".$this->getEntryTbl()." WHERE 1=1 ";
  1154.         if (intval($keyVal)) {
  1155.             $s_query.=" AND ".$this->getKeyColName()." = ".intval($keyVal);
  1156.         else {
  1157.             return False;
  1158.         }
  1159.  
  1160.         if (intval($idx)) {
  1161.             $s_query.=" AND CLP_IDX=".intval($idx);
  1162.         }
  1163.  
  1164.         if ($debugecho "<blockquote><p>Cmd$s_query</p></blockquote>";
  1165.  
  1166.         if (!$this->isConnected(TRUE,$debug))
  1167.         {
  1168.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1169.             return False;
  1170.         }
  1171.         return $this->myDBObj->executeCmd($s_query);
  1172.     }
  1173.  
  1174.     /**
  1175.       * replaces all entries of a client/user/staff
  1176.       * @note deletes all entries from the table and then insert datarows in $dataArray
  1177.       *
  1178.       *
  1179.       * @param int $fkval foreign key
  1180.       * @param int $dataArray array of rows
  1181.       * @param boolean $debug 
  1182.       *
  1183.       * @returns int number of rows inserted
  1184.       *
  1185.       * @since pk-05-03-08
  1186.       *
  1187.       ***/
  1188.     function replaceAllEntries($fkVal,$dataArray,$debug=False{
  1189.         if ($debugecho "<p><b>CLI_PROFILE::replaceAllEntries($fkVal,....)</b> (".get_class($this).")</p>";
  1190.  
  1191.         if (!is_array($dataArray)) return False;
  1192.  
  1193.         $cmd ="DELETE FROM ".$this->getEntryTbl();
  1194.         $cmd.=" WHERE ".$this->getKeyColName()."=".$fkVal;
  1195.         $cmd.="   AND CLP_ID=".$this->getId();
  1196.  
  1197.         if ($debugecho "<p>CMD$cmd</p>";
  1198.  
  1199.         if (!$this->isConnected(TRUE,$debug))
  1200.         {
  1201.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1202.             return False;
  1203.         }
  1204.         $this->myDBObj->executeCmd($cmd);
  1205.  
  1206.         $this->setForeignKey($fkVal);
  1207.  
  1208.         $noR=0;
  1209.         foreach($dataArray as $idx =>$dbVal{
  1210.             if ($this->insertEntryRow($dbVal,$debug)) $noR++;
  1211.         }
  1212.         return $noR;
  1213.     }
  1214.  
  1215.     /**
  1216.       * returns the select statement for a join of Entrytable and Keytable
  1217.       *
  1218.       * @note values of ..TblKeys are the complete right side of condition
  1219.       *        examples
  1220.       *          - [CLI_NAME1] => "LIKE 'A%'"
  1221.       *          - [CTY_ID']   => "=1"
  1222.       *
  1223.       * @param array $keyTblKeys 
  1224.       * @param array $entrTblKeys 
  1225.       * @param boolean $debug 
  1226.       *
  1227.       * @returns string
  1228.       *
  1229.       * @since pk-05-03-15
  1230.       *
  1231.       ***/
  1232.     function getETblJoinSelStmt($keyTblKeys=NULL,$entrTblKeys=NULL,$debug=False{
  1233.         if ($debugecho "<p><b>CLI_PROFILE::getEntryTblSelectStmt(...)</b> (".get_class($this).")</p>";
  1234.  
  1235.         $s_stmt ="SELECT * FROM ".$this->getEntryTbl()." etbl JOIN ".$this->CLP_KEYTABLE." ktbl USING(".$this->getKeyColName().")";
  1236.         $s_stmt.=" WHERE 1=1"// to ensure we have a where
  1237.  
  1238.         if (is_array($keyTblKeys)) {
  1239.             foreach($keyTblKeys as $col => $con{
  1240.                 $s_stmt.=" AND ktbl.".$col.$con;
  1241.             }
  1242.         }
  1243.  
  1244.         if (is_array($entrTblKeys)) {
  1245.             foreach($entrTblKeys as $col => $con{
  1246.                 $s_stmt.=" AND etbl.".$col." ".$con;
  1247.             }
  1248.         }
  1249.  
  1250.         if (intval($this->getForeignKey())) {
  1251.             $s_stmt.=" AND etbl.".$this->getKeyColName()."=".$this->getForeignKey();
  1252.         }
  1253.  
  1254.         if ($this->checkProfileIdInEntryQuery()) // <pk-07-01-12 >
  1255.             $s_stmt.=" AND etbl.CLP_ID=".$this->getId();
  1256.         }
  1257.  
  1258.         return $s_stmt;
  1259.     }
  1260.  
  1261.     /**
  1262.       * returns an array of all entry rows where keytable key fit
  1263.       *
  1264.       * @param int $key 
  1265.       * @param boolean $debug 
  1266.       *
  1267.       * @since pk-05-09-23
  1268.       *
  1269.       * @var string $s_query 
  1270.       ***/
  1271.     function getEntryRowArray($key=0,$debug=False{
  1272.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::getEntryRowArray($key)");
  1273.  
  1274.         if (!$this->isConnected(TRUE,$debug))
  1275.         {
  1276.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1277.             return False;
  1278.         }
  1279.  
  1280.         $s_query="SELECT * FROM ".$this->getEntryTbl()." WHERE 1=1 ";
  1281.         if ($this->checkProfileIdInEntryQuery()) // <pk-06-10-11 >
  1282.             $s_query.=" AND CLP_ID=".$this->getId();
  1283.         }
  1284.         if (intval($key)) {
  1285.             $s_query.=" AND ".$this->getKeyColName()." = ".intval($key);
  1286.             if ($debugechoDebug(__FILE__,"<blockquote>Query: ".$s_query."</blockquote>");
  1287.             return $this->myDBObj->queryArray($s_query,-1,-1,TRUE,$debug);
  1288.         }
  1289.         return array();
  1290.  
  1291.  
  1292.     }
  1293.  
  1294.     /**
  1295.       * returns the number of entries for a key with state
  1296.       *
  1297.       * @param int $key 
  1298.       * @param int $state use -1 to ignore it
  1299.       * @param boolean $debug 
  1300.       *
  1301.       * @since pk-06-12-29
  1302.       *
  1303.       * @returns int
  1304.       *
  1305.       ***/
  1306.     function getNumberOfEntries($key=0,$state=-1,$debug=False{
  1307.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::getNumberOfEntries($key)");
  1308.  
  1309.         if (!$this->isConnected(TRUE,$debug))
  1310.         {
  1311.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1312.             return False;
  1313.         }
  1314.  
  1315.         $s_query.="SELECT COUNT(*) FROM ".$this->getEntryTbl();
  1316.         $s_query.=" WHERE ".$this->getKeyColName()."=".intval($key);
  1317.         if ($this->checkProfileIdInEntryQuery())   $s_query.=" AND CLP_ID=".$this->getId();
  1318.         if ($state > -1)                           $s_query.=" AND CLP_STATE=".intval($state);
  1319.  
  1320.         if ($debugechoDebug(__FILE__,"<p>".$s_query."</p>");
  1321.         return intval($this->myDBObj->quickQuery($s_query,0));
  1322.  
  1323.     }
  1324.  
  1325.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1326.     /* right methods                                                             */
  1327.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1328.  
  1329.     /**
  1330.       * returns if the current user is allowed to show the profile
  1331.       *
  1332.       * @param boolean $debug 
  1333.       * 
  1334.       * @global array $OCSP_OBJ 
  1335.       * 
  1336.       * @return boolean 
  1337.       *
  1338.       * @since pk-07-01-11
  1339.       *
  1340.       ***/
  1341.     function userCanShow($debug=False{
  1342.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::userCanShow()");
  1343.  
  1344.         if (!intval($this->getId())) return False// no profile loaded
  1345.  
  1346.         if (OCSP_OBJ::currentUser()->isGroupMember($this->getDBField('CLP_SHOWGRP'),$debug)) 
  1347.         {
  1348.             return True;
  1349.         else if ($debug{
  1350.             echoDebugLine(__FILE__,__LINE__,"User is not member of "$this->getDBField('CLP_SHOWGRP'));
  1351.         }
  1352.  
  1353.         return $this->userCanEdit();
  1354.     }
  1355.  
  1356.     /**
  1357.       * returns if the current user is allowed to show the profile
  1358.       *
  1359.       * @param boolean $debug 
  1360.       *
  1361.       * @global array $OCSP_OBJ 
  1362.       * 
  1363.       * @return boolean 
  1364.       *
  1365.       * @since pk-07-01-11
  1366.       *
  1367.       ***/
  1368.     function userCanInsert($debug=False{
  1369.         global $OCSP_OBJ;
  1370.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::userCanInsert()");
  1371.  
  1372.         if (!intval($this->getId())) return False// no profile loaded
  1373.  
  1374.         if (OCSP_OBJ::currentUser()->isGroupMember($this->getDBField('CLP_INPUTGRP'))) return TRUE;
  1375.         if ($this->useInRegister()) {
  1376.             if (OCSP_OBJ::currentUser()->isPublic()) return TRUE// as we have no user we asume that we are in the register process
  1377.             if (OCSP_OBJ::currentUser()->isGroupMember($this->getGrpId())) return TRUE// the user is member of the required group
  1378.                                                                                  // so we allow him to add data later
  1379.         }
  1380.  
  1381.         return $this->userCanEdit();
  1382.     }
  1383.  
  1384.  
  1385.     /**
  1386.       * returns if the current user is allowed to edit the profile
  1387.       *
  1388.       * @param boolean $debug 
  1389.       * 
  1390.       * @global array $OCSP_OBJ 
  1391.       * 
  1392.       * @return boolean 
  1393.       *
  1394.       * @since pk-07-01-11
  1395.       *
  1396.       ***/
  1397.     function userCanEdit($debug=False{
  1398.         global $OCSP_OBJ;
  1399.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CLI_PROFILE::userCanShow()");
  1400.  
  1401.         if (!intval($this->getId())) return False// no profile loaded
  1402.         if (OCSP_OBJ::currentUser()->isGroupMember($this->getDBField('CLP_EDITGRP'))) return TRUE;
  1403.     }
  1404.  
  1405.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1406.     /* sort methods                                                              */
  1407.     /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
  1408.  
  1409.     /**
  1410.       * @returns int
  1411.       ***/
  1412.     function getSortOrder({
  1413.         return intval($this->{$this->colPrevix."SORTORDER"});
  1414.     }
  1415.  
  1416.     /**
  1417.       * moves the profile up (decrease sortorder)
  1418.       * note autosaves sortorder
  1419.       *
  1420.       * @param boolean $debug 
  1421.       *
  1422.       * @since pk-05-08-08
  1423.       *
  1424.       * @var string $s_Query 
  1425.       * @var array  $a_Row 
  1426.       ***/
  1427.     function sort_MoveUp($debug=False{
  1428.         if ($debugecho "<p><b>CLI_PROFILE::sort_MoveUp()</b> (".get_class($this).")</p>";
  1429.  
  1430.         if (!$this->isConnected(TRUE,$debug))
  1431.         {
  1432.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1433.             return False;
  1434.         }
  1435.  
  1436.         if (intval($this->{$this->colPrevix."SORTORDER"}1{
  1437.             $s_Query "SELECT ".$this->colPrevix."ID AS IDCOL, ".$this->colPrevix."SORTORDER AS ORDERCOL";
  1438.             $s_Query.= "  FROM ".$this->myTable;
  1439.             $s_Query.= " WHERE PROJ_ID=".$this->getProjId();
  1440.             $s_Query.= "   AND ".$this->colPrevix."SORTORDER <= ".$this->getSortOrder();
  1441.             $s_Query.= "   AND ".$this->colPrevix."ID <> ".$this->getId();
  1442.             $s_Query.= " ORDER BY ".$this->colPrevix."SORTORDER DESC";
  1443.  
  1444.             if ($debugecho "<p>".$s_Query."</p>";
  1445.             if ($a_Row=$this->myDBObj->quickQuery($s_Query)) {
  1446.                 // get only the first row
  1447.  
  1448.                 $this->{$this->colPrevix."SORTORDER"intval($a_Row['ORDERCOL']);
  1449.                 $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".$this->getSortOrder();
  1450.                 $s_Query.=" WHERE ".$this->colPrevix."ID = ".$this->getId();
  1451.                 if ($debugecho "<p>".$s_Query."</p>";
  1452.                 $this->myDBObj->executeCmd($s_Query);
  1453.  
  1454.                 $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".($this->getSortOrder()+1);
  1455.                 $s_Query.=" WHERE ".$this->colPrevix."ID = ".$a_Row['IDCOL'];
  1456.                 if ($debugecho "<p>".$s_Query."</p>";
  1457.                 $this->myDBObj->executeCmd($s_Query);
  1458.             }
  1459.         }
  1460.     }
  1461.  
  1462.     /**
  1463.       * moves the profile down (increase sortorder)
  1464.       * note: autosaves sortorder
  1465.       *
  1466.       * @param boolean $debug 
  1467.       *
  1468.       * @since pk-05-08-03
  1469.       *
  1470.       * @var string $s_Query 
  1471.       * @var array  $a_Row 
  1472.       ***/
  1473.     function sort_MoveDown($debug=False{
  1474.         if ($debugecho "<p><b>CLI_PROFILE::sort_MoveDown()</b> (".get_class($this).")</p>";
  1475.  
  1476.         if (!$this->isConnected(TRUE,$debug))
  1477.         {
  1478.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1479.             return False;
  1480.         }
  1481.  
  1482.         if (intval($this->{$this->colPrevix."SORTORDER"}1{
  1483.             $s_Query "SELECT ".$this->colPrevix."ID AS IDCOL, ".$this->colPrevix."SORTORDER AS ORDERCOL";
  1484.             $s_Query.= "  FROM ".$this->myTable;
  1485.             $s_Query.= " WHERE PROJ_ID=".$this->getProjId();
  1486.             $s_Query.= "   AND ".$this->colPrevix."SORTORDER >= ".$this->getSortOrder();
  1487.             $s_Query.= "   AND ".$this->colPrevix."ID <> ".$this->getId();
  1488.             $s_Query.= " ORDER BY ".$this->colPrevix."SORTORDER";
  1489.  
  1490.             if ($debugecho "<p>".$s_Query."</p>";
  1491.             if ($a_Row=$this->myDBObj->quickQuery($s_Query)) {
  1492.                 // get only the first row
  1493.  
  1494.                 $this->{$this->colPrevix."SORTORDER"$this->getSortOrder()+1;
  1495.                 $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".$this->getSortOrder();
  1496.                 $s_Query.=" WHERE ".$this->colPrevix."ID = ".$this->getId();
  1497.                 if ($debugecho "<p>".$s_Query."</p>";
  1498.                 $this->myDBObj->executeCmd($s_Query);
  1499.  
  1500.                 $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".($this->getSortOrder()-1);
  1501.                 $s_Query.=" WHERE ".$this->colPrevix."ID = ".$a_Row['IDCOL'];
  1502.                 if ($debugecho "<p>".$s_Query."</p>";
  1503.                 $this->myDBObj->executeCmd($s_Query);
  1504.             }
  1505.         }
  1506.     }
  1507.  
  1508.     /**
  1509.       * moves the profile to a position
  1510.       * note: autosaves sortorder
  1511.       *
  1512.       * if $postion > last postion
  1513.       * the object will be moved to the end
  1514.       *
  1515.       * @param int $position 
  1516.       * @param boolean 
  1517.       *
  1518.       * @returns int
  1519.       *
  1520.       * @since pk-05-08-08
  1521.       *
  1522.       * @var int $i_ordNr 
  1523.       * @var string $s_Query 
  1524.       * @var DBMS_CURSOR $o_Cursor 
  1525.       * @var array $a_Row 
  1526.       *
  1527.       ***/
  1528.     function sort_MoveToPos($position,$debug=False{
  1529.         if ($debugecho "<p><b>CLI_PROFILE::sort_MoveToPos($position)</b> (".get_class($this).")</p>\n";
  1530.  
  1531.         if (!intval($position)) return False// error illegal position
  1532.         if ($this->getSortOrder(== intval($postion)) return $position// nothing to do
  1533.  
  1534.         if (!$this->isConnected(TRUE,$debug))
  1535.         {
  1536.             ocsp_logError(__FILE__,__LINE__,"no database connection",E_ERROR);
  1537.             return False;
  1538.         }
  1539.  
  1540.         $s_Query "SELECT ".$this->colPrevix."ID AS IDCOL, ".$this->colPrevix."SORTORDER AS ORDERCOL";
  1541.         $s_Query.= "  FROM ".$this->myTable;
  1542.         $s_Query.= " WHERE PROJ_ID=".$this->getProjId();
  1543.         $s_Query.= "   AND ".$this->colPrevix."ID <> ".$this->getId();  // without me
  1544.         $s_Query.= " ORDER BY ".$this->colPrevix."SORTORDER";
  1545.  
  1546.         $i_ordNr=1;
  1547.         if ($o_Cursor=$this->myDBObj->query($s_Query)) {
  1548.             while($a_Row $o_Cursor->fetchArrayFld()) {
  1549.                 if ($i_ordNr == $position{
  1550.                     // ok here i belong to
  1551.                     $this->{$this->colPrevix."SORTORDER"}=$position;
  1552.                     $i_ordNr++;
  1553.                 }
  1554.                 if (intval($a_Row['ORDERCOL']!= $i_ordNr{
  1555.                     // we have to update
  1556.                     $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".$i_ordNr;
  1557.                     $s_Query.=" WHERE ".$this->colPrevix."ID = ".$a_Row['IDCOL'];
  1558.                     if ($debugecho "<p>".$s_Query."</p>";
  1559.                     $this->myDBObj->executeCmd($s_Query);
  1560.                 }
  1561.                 $i_ordNr++;
  1562.             }
  1563.             if ($this->getSortOrder(!= intval($position)) {
  1564.                 // i belong to the end
  1565.                 $this->{$this->colPrevix."SORTORDER"}=$i_ordNr;
  1566.             }
  1567.  
  1568.             // finaly save my own order position to the database
  1569.             $s_Query ="UPDATE ".$this->myTable." SET ".$this->colPrevix."SORTORDER=".$this->getSortOrder();
  1570.             $s_Query.=" WHERE ".$this->colPrevix."ID = ".$this->getId();
  1571.             if ($debugecho "<p>".$s_Query."</p>";
  1572.             $this->myDBObj->executeCmd($s_Query);
  1573.             return $this->getSortOrder();
  1574.         else {
  1575.             return False;
  1576.         }
  1577.     }
  1578. }
  1579.  
  1580. ?>

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