Source for file CMS_PROJECT.phpclass

Documentation is available at CMS_PROJECT.phpclass

  1. <?php
  2. /**
  3.   * Class file CMS_PROJECT.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    cms
  7.   *
  8.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  9.   *
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version pk-04-07-27
  13.   * @version pk-07-05-08
  14.   * 
  15.   * @version $Id: CMS_PROJECT.phpclass,v 1.27 2008/12/02 07:36:22 pitlinz Exp $
  16.   */
  17.  
  18.     if (!defined('__OCSP_CMS_PHPINCPATH__'))
  19.     {
  20.         require_once __OCSP_DEFAULTCONFPATH__."cms.conf.phpinc";        
  21.     }
  22.  
  23.     pcf_require_interface('INFA_CMS_PROJECT',dirname(__FILE__"/");
  24.     pcf_require_class('CMS_MENU',"cms/menu/");
  25.     pcf_require_class('CMS_TABLEOBJ',dirname(__FILE__)."/");
  26.     
  27.     require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf.phpinc";
  28.  
  29.  
  30.     require_once __OCSP_CMS_PHPINCPATH__."menu"._OCSP_DIRSEP_."CMS_MENU_V2.phpclass";
  31.  
  32.  
  33. /**
  34.   * Class file CMS_PROJECT.phpclass
  35.   *
  36.   * @project    Open CSP-Management
  37.   * @package    cms
  38.   *
  39.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  40.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  41.   *
  42.   * @version pk-04-05-12
  43.   * @version pk-05-07-11
  44.   * @version pk-06-08-03 changed parent class from DBMS_TABLEOBJ to CMS_TABLEOBJ
  45.   * @version $Id: CMS_PROJECT.phpclass,v 1.27 2008/12/02 07:36:22 pitlinz Exp $
  46.   */
  47. class CMS_PROJECT extends CMS_TABLEOBJ implements INFA_CMS_PROJECT {
  48.  
  49.     // ---------------------------------------------------------------------------
  50.     // constants
  51.     // ---------------------------------------------------------------------------
  52.     
  53.     /**
  54.      * @constant string CLASS_SRC_FILE
  55.      *
  56.      * @abstract
  57.      */
  58.     const CLASS_SRC_FILE = __FILE__;    
  59.     
  60.     // ---------------------------------------------------------------------------
  61.     // class (static)
  62.     // ---------------------------------------------------------------------------
  63.     
  64.     /*** class vars ------------------------------------------------------ */
  65.     
  66.     /**
  67.      * unit of work for projects
  68.      *
  69.      * @staticvar array $loadedProjects 
  70.      */
  71.     protected static $loadedProjects array();
  72.     
  73.     /*** class methods --------------------------------------------------- */
  74.     
  75.     /**
  76.      * returns an instance of CMS_PROJECT
  77.      * 
  78.      * uses self::$loadedProjects as unit of work
  79.      *
  80.      * @param int $aId 
  81.      * @param boolean $force 
  82.      * @param boolean $debug 
  83.      * 
  84.      * @return CMS_PROJECT 
  85.      */
  86.     public static function &getInstance($aId,$force=False,$debug=False)
  87.     {
  88.         if ($debugechoDebugMethod(__FILE__,"static","CMS_PROJECT::getInstance({$aId})");
  89.         $aId intval($aId);
  90.         if (!isset(self::$loadedProjects[$aId]|| !self::$loadedProjects[$aId])
  91.         {
  92.             self::$loadedProjects[$aIdself::factoryFromId($aId,$force);
  93.         }
  94.         return self::$loadedProjects[$aId];
  95.     }
  96.     
  97.     public static function setInstance(&$aProject,$debug=False)
  98.     {
  99.         if ($debugechoDebugMethod(__FILE__,"static","CMS_PROJECT::setInstance()");
  100.         
  101.         if (method_exists($aProject,"getId"))
  102.         {
  103.             self::$loadedProjects[$aProject->getId()$aProject;
  104.         }
  105.     }
  106.     
  107.     /**
  108.      * returns if the project with $aId is in $loadedProjects
  109.      *
  110.      * @param int $aId 
  111.      * 
  112.      * @return boolean 
  113.      */
  114.     public static function isInstanced($aId)
  115.     {
  116.         $aId intval($aId);
  117.         return (isset(self::$loadedProjects[$aId]|| self::$loadedProjects[$aId]);
  118.     }
  119.     
  120.     
  121.     // ---------------------------------------------------------------------------
  122.     // object vars
  123.     // ---------------------------------------------------------------------------
  124.     
  125.     /*** compostion --------------------------------------------------- */
  126.     
  127.     /*** attributes  -------------------------------------------------- */
  128.     
  129.     /**
  130.       * @var string $myTable name of the db table
  131.       */
  132.     protected $myTable = "T_CMS_PROJECT";
  133.  
  134.     /**
  135.       * @var string $myIdColName 
  136.       */
  137.     protected $myIdColName = "PROJ_ID";
  138.  
  139.     /**
  140.      * fields in $this->myTable starts with
  141.      * 
  142.      * @var string $colPrevix 
  143.      */
  144.     protected $colPrevix = "PROJ_";
  145.  
  146.     /**
  147.       * @var string $myMenuTable 
  148.       */
  149.     protected $myMenuTable ="T_CMS_MENU";
  150.  
  151.     /**
  152.       * @var string $myPageTable 
  153.       */
  154.     protected $myPageTable ="T_CMS_PAGE";
  155.  
  156.  
  157.  
  158.     // ---------------------------------------------------------------------------
  159.     // factory / construct
  160.     // ---------------------------------------------------------------------------
  161.     
  162.     /**
  163.      * faktories a project object from the environment
  164.      *
  165.      * @param boolean $debug 
  166.      * 
  167.      * @return CMS_PROJECT 
  168.      */
  169.     public static function factoryFromEnv($debug=False)
  170.     {
  171.         if ($debugechoDebugMethod(__FILE__,"static","CMS_PROJECT::factoryFromEnv()");
  172.         
  173.         $int_projId (isset($_GET[self::getProjIdGetName()]intval($_GET[self::getProjIdGetName()](isset($_GET[self::getProjIdColName()]intval($_GET[self::getProjIdColName()]0));
  174.         $int_projId (intval($int_projId$int_projId (isset($_SERVER['PROJ_ID']intval($_SERVER['PROJ_ID']0));
  175.         
  176.         if (intval($int_projId))
  177.         {
  178.             if ($obj_project self::factoryFromId($int_projId))
  179.             {
  180.                 return $obj_project;
  181.             }
  182.         }
  183.         
  184.         if ($arr_row OCSP_CMS_CACHE::getInstance()->getServerProjRow($debug))
  185.         {
  186.             return self::factoryFromDBRow($arr_row,$debug);
  187.         }
  188.         
  189.         if ($arr_projectRows OCSP_OBJ::defaultReadDBObj()->getArray('T_CMS_PROJECT',array('PROJ_SHOW' => 1),0,0,'PROJ_SORTORDER,PROJ_ISDEFAULT DESC',$debug))
  190.         {
  191.             $arr_default Null;
  192.             $arr_project Null;
  193.             foreach($arr_projectRows as $arr_row)
  194.             {
  195.                 if (!$arr_default && intval($arr_row['PROJ_ISDEFAULT']))
  196.                 {
  197.                     $arr_default $arr_row;
  198.                 }
  199.                 
  200.                 if (stristr($_SERVER['SERVER_NAME'],$arr_row['PROJ_URL']))
  201.                 {
  202.                     $arr_project $arr_row;
  203.                     break// <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  204.                 }
  205.                 
  206.                 if (!$arr_project && !empty($arr_row['PROJ_URLREGEX'])) 
  207.                 {
  208.                     if ($arr_regex explode("\n",str_replace("\r","",$arr_row['PROJ_URLREGEX']))) 
  209.                     {
  210.                         foreach($arr_regex as $str_pattern
  211.                         {
  212.                             if (!empty($str_pattern))
  213.                              {
  214.                                  if ($debugechoDebugLine(__FILE__,__LINE__,"checking regex pattern {$str_pattern}");
  215.                                   if (@preg_match($str_pattern,$_SERVER['SERVER_NAME']))
  216.                                   {
  217.                                       $arr_project $arr_row;
  218.                                       break;
  219.                                   }
  220.                             }
  221.                         }
  222.                     }
  223.                 }                                
  224.             }
  225.             
  226.             if ($arr_project)
  227.             {
  228.                 return self::factoryFromDBRow($arr_project,$debug);
  229.             else {
  230.                 if ($arr_default)
  231.                 {
  232.                     return self::factoryFromDBRow($arr_default,$debug);
  233.                 else {
  234.                     return self::factoryFromDBRow($arr_projectRows[0]);
  235.                 }
  236.             }
  237.         }
  238.     }
  239.     
  240.     /**
  241.      * faktories a project from $aId
  242.      *
  243.      * @param int $aId 
  244.      * @param boolean $force 
  245.      * @param boolean $debug 
  246.      * 
  247.      * @return CMS_PROJECT 
  248.      * 
  249.      * @since pk-08-06-18
  250.      */
  251.     public static function factoryFromId($aId,$force=False,$debug=False)
  252.     {
  253.         if ($debugechoDebugMethod(__FILE__,"static","CMS_PROJECT::factoryFromId()");
  254.         
  255.         if (intval($aId))
  256.         {
  257.             if (!$arr_row OCSP_CMS_CACHE::getInstance()->getProjRow($aId))
  258.             {
  259.                 if (!$arr_row OCSP_OBJ::defaultReadDBObj()->getRow('T_CMS_PROJECT',array('PROJ_ID' => intval($aId))))
  260.                 {
  261.                     if (!$force
  262.                     {
  263.                         return Null;
  264.                     }
  265.                 }
  266.             }
  267.             
  268.             return self::factoryFromDBRow($arr_row,$debug);
  269.         }
  270.         
  271.         if ($force)
  272.         {
  273.             if ($debugechoDebugMethod(__FILE__,__LINE__,"returning new object");
  274.             $obj_ret new CMS_PROJECT();
  275.             $obj_ret->setId($aId);
  276.             return $obj_ret;
  277.         }
  278.             
  279.     }
  280.     
  281.     /**
  282.      * faktories a menu object from a database row
  283.      *
  284.      * @param array $dbRow 
  285.      * @param boolean $debug 
  286.      * 
  287.      * @return CMS_PROJECT 
  288.      * 
  289.      * @since pk-08-06-18
  290.      */
  291.     public static function factoryFromDBRow($dbRow,$debug=False)
  292.     {
  293.         $obj_project new CMS_PROJECT();
  294.         $obj_project->setDBRow($dbRow,True,$debug);
  295.         return $obj_project;
  296.     }
  297.     
  298.     /**
  299.       * init the object and populate if an id is submitted
  300.       *
  301.       * @param int $aProjId 
  302.       * @param string $gDBIdx 
  303.       * @param bool $debug 
  304.       *
  305.       * @version pk-07-08-16
  306.       * @version pk-08-06-18
  307.       */
  308.     function CMS_PROJECT($aProjId=0,$debug=False)
  309.     {
  310.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::CMS_PROJECT($aProjId)");
  311.         
  312.         if (intval($aProjId)) 
  313.         {
  314.             $this->init();
  315.             $this->setId($aProjId);
  316.             $this->dbPopulate($debug);
  317.         }
  318.     }
  319.  
  320.     /**
  321.       * generates a project object for the current environment settings
  322.       * also sets the following objects:
  323.       *
  324.       * - $this->curMenuTree
  325.       * - $this->curMenuNode
  326.       * - $this->curPageObj
  327.       *
  328.       * @param boolean $setGlobals if true the global variables in $OCSP_OBJ for the generated objects are set
  329.       * @param boolean $debug 
  330.       *
  331.       * @return CMS_PROJECT 
  332.       *
  333.       * @deprecated since pk-08-06-18
  334.       * 
  335.       */
  336.     function CMS_PROJECT_FROM_GET($setGlobals=True,$debug=False)
  337.     {
  338.         return CMS_PROJECT::factoryFromEnv($debug);        
  339.     }
  340.  
  341.     /** ---------------------------------------------------------------------------------------------------------
  342.       * getter & setter methods
  343.       * ---------------------------------------------------------------------------------------------------------
  344.       */
  345.  
  346.     /**
  347.       * returns the id
  348.       * @return int 
  349.       */
  350.     function getId({
  351.         return intval($this->getDBField($this->myIdColName));
  352.     }
  353.  
  354.     /**
  355.       * @param int $aId 
  356.       */
  357.     function setId($aId
  358.     {
  359.         $this->{$this->myIdColName}=intval($aId);
  360.     }
  361.  
  362.     /**
  363.       * returns the title or the name if no title is set
  364.       * if $this->getId() == 0 Default is returned
  365.       *
  366.       *
  367.       * @return string 
  368.       * @since pk-05-09-01
  369.       * @version pk-06-07-23
  370.       * @version pk-06-10-25 E_ALL
  371.       */
  372.     function getTitle()
  373.     {
  374.         if (!intval($this->getId())) // <pk-06-07-23> asume we have the default project
  375.             return "Default";
  376.         }
  377.         $s_title=$this->getDBField($this->colPrevix."TITLE");
  378.         return (empty($s_title$this->getDBField($this->colPrevix."NAME"$s_title);
  379.     }
  380.  
  381.     /**
  382.      * returns the project name
  383.      *
  384.      * @return string 
  385.      * 
  386.      * @since pk-08-08-12
  387.      */
  388.     public function getName()
  389.     {
  390.         return $this->getDBField($this->colPrevix."NAME");
  391.     }
  392.     
  393.     /**
  394.      * sets the project name
  395.      *
  396.      * @param string $aName 
  397.      * 
  398.      * @since pk-08-10-16
  399.      */
  400.     public function setName($aName)
  401.     {
  402.         $this->setDBField($this->colPrevix."NAME",$aName);
  403.     }
  404.  
  405.     /**
  406.       * despite the object vals the column PROJ_VARS holds variables
  407.       * only used in the current project in a text field each variable is in one line like name=value
  408.       *
  409.       * returns the value of a project var or NULL if the variable is not set
  410.       *
  411.       * @param string $varName name of the variable
  412.       * @param boolean $debug 
  413.       *
  414.       * @return string 
  415.       *
  416.       * @since pk-06-07-23
  417.       *
  418.       */
  419.     function getProjVar($varName,$debug=False{
  420.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::getProjVar()","Var:".$varName."\n".$this->getDBField('PROJ_VARS'));
  421.  
  422.         $s_vars=$this->getDBField('PROJ_VARS');
  423.         if (!empty($s_vars)) {
  424.             $s_vars=str_replace("\r","",$s_vars)// remove linefeed
  425.             if ($a_vars=explode("\n",$s_vars)) {
  426.                 foreach($a_vars as $s_varLine{
  427.                     $a_varDef=explode("=",$s_varLine,2)// <pk-06-08-04 /> bugfix
  428.                     if ($debugecho "<pre>Line: ".print_r($a_varDef,True)."</pre>";
  429.                     if ($a_varDef[0]==$varName{
  430.                         return $a_varDef[1];
  431.                     }
  432.                 }
  433.             }
  434.         else {
  435.             if ($debugecho "<p>PROJ_VARS NOT SET</p>";
  436.         }
  437.         return NULL;
  438.     }
  439.  
  440.     /**
  441.       * returns the image rootPath
  442.       *
  443.       * @param boolean $debug 
  444.       *
  445.       * @return string 
  446.       *
  447.       * @since pk-06-11-09
  448.       *
  449.       */
  450.     function getImgRootPath($debug=False{
  451.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::getImgRootPath()");
  452.  
  453.         if ($s_rd=$this->getDBField('PROJ_IMGROOTDIR')) {
  454.             if (is_dir($_SERVER['DOCUMENT_ROOT']."/".$s_rd)) {
  455.                 return $_SERVER['DOCUMENT_ROOT']."/".$s_rd;
  456.             }
  457.         }
  458.         return NULL;
  459.     }
  460.  
  461.     /**
  462.       * returns the language string
  463.       *
  464.       * @param string $txt 
  465.       * @param string $lang 
  466.       * 
  467.       * @global array $OCSP_CONF 
  468.       *
  469.       * @return string 
  470.       *
  471.       */
  472.     function getLangTxt($txt,$lang="DE")
  473.     {
  474.         global $OCSP_CONF;
  475.         
  476.         include_once dirname(__FILE__)."/languages/".strtolower($lang).".phpinc";
  477.  
  478.         if (isset($OCSP_CONF['OCSP_CMSLANG'][$lang][$txt]))
  479.         {
  480.             return $OCSP_CONF['OCSP_CMSLANG'][$lang][$txt];
  481.         else {
  482.             return $txt;
  483.         }
  484.     }
  485.     
  486.     /**
  487.      * returns the default template id
  488.      *
  489.      * @return int 
  490.      */
  491.     function getTemplateId()
  492.     {
  493.         return $this->getDBField('PROJ_DEF_PTMP_ID');
  494.     }
  495.     
  496.     /**
  497.      * returns if the project is the current project
  498.      * 
  499.      * NOTE only ID's are compared
  500.      *
  501.      * @return boolean 
  502.      */
  503.     public function isCurrent()
  504.     {
  505.         if (CMS_TABLEOBJ::get_currentProj())
  506.         {
  507.             return (CMS_TABLEOBJ::get_currentProj()->getId(== $this->getId());
  508.         }
  509.         return False;
  510.     }
  511.     
  512.     /**
  513.      * sets the project as current project in CMS_TABLEOBJ
  514.      */
  515.     public function setAsCurrent()
  516.     {
  517.         CMS_TABLEOBJ::set_currentProj($this);
  518.     }
  519.     
  520.     // ############################################################################
  521.     // load/find
  522.     // ############################################################################
  523.  
  524.  
  525.     /**
  526.       * tries to find out the project id from the environment
  527.       *
  528.       * @param boolean $debug 
  529.       * @param boolean $checkSession 
  530.       *
  531.       * @return int 
  532.       *
  533.       * @since pk-05-08-09
  534.       * @version pk-06-01-05
  535.       *
  536.       * @deprecated since pk-08-06-18
  537.       */
  538.     function getProjIdFromEnv($debug=False,$checkSession=False{
  539.         if ($debugecho "<p><b>CMS_PROJECT::getProjIdFromEnv()</b> (".get_class($this).")</p>";
  540.  
  541.         if (isset($_GET[$this->myIdColName]&& intval($_GET[$this->myIdColName])) {
  542.             // we have a PROJ_ID in the querystring
  543.             if ($debugecho "<blockquote>ID from querystring</blockquote>";
  544.             return intval($_GET[$this->myIdColName]);
  545.         }
  546.  
  547.         // do we have to check session?
  548.         if (($checkSession&& (isset($_SESSION[$this->myIdColName]&& intval($_SESSION[$this->myIdColName]))) // check session var
  549.                                                                           // NOTE session need be started before
  550.             if ($debugecho "<blockquote>ID from session</blockquote>";
  551.             return intval($_SESSION[$this->myIdColName]);
  552.         }
  553.  
  554.         // is project id set in http conf?
  555.         if (isset($_SERVER['PROJ_ID']&& intval($_SERVER['PROJ_ID'])) {
  556.             if ($debugecho "<blockquote>ID from _SERVER</blockquote>";
  557.             return intval($_SERVER['PROJ_ID']);
  558.         }
  559.  
  560.         // <pk-06-07-28> check if we already have one set so we use this
  561.         if (intval($this->getId())) {
  562.             if ($debugechoDebugLine(__FILE__,__LINE__,"ID from object");
  563.             return $this->getId();
  564.         }
  565.  
  566.  
  567.         if (!$this->isConnected(True,$debug))
  568.         {
  569.             die("no database connection");
  570.         }
  571.  
  572.         // no project found try to find out from _SERVER["HTTP_HOST"]
  573.         $s_query ="SELECT ".$this->myIdColName." FROM ".$this->myTable;
  574.         $s_query.=" WHERE UPPER(PROJ_URL)=".$this->myDBObj->qs_getSlashedValue(strtoupper($_SERVER['HTTP_HOST']));
  575.         if ($debugecho "<p>Searching Server: <br />".$s_query."</p>";
  576.         if ($i_Id=$this->myDBObj->quickQuery($s_query,0)) {
  577.             if ($this->cmsCacheIsUsable())
  578.             {
  579.                 $this->myCmsCache->addProjIdFromHTTP_HOST($i_Id);
  580.             }
  581.             if ($debugecho "<blockquote>ID from HTTP_HOST</blockquote>";
  582.             return $i_Id;
  583.         }
  584.  
  585.         // ok let's go into deep and check
  586.         $s_query ="SELECT * FROM ".$this->myTable;
  587.         $s_query.=" WHERE PROJ_SHOW > 0";
  588.         $s_query.=" ORDER BY PROJ_ISDEFAULT DESC, PROJ_SORTORDER" ;
  589.  
  590.         $a_firstProj=NULL;
  591.         if ($debugecho "<blockquote><p>Checking Regular Expressions</p>\n";
  592.         if ($o_Cursor=$this->myDBObj->query($s_query)) {
  593.             while($a_dbRow $o_Cursor->fetchArrayFld()) {
  594.                 if (empty($a_firstProj)) $a_firstProj=$a_dbRow// cache first result to use if
  595.                                                                 // if we do not find a proper regex
  596.                 if (!empty($a_dbRow['PROJ_URLREGEX'])) {
  597.                     if ($debugecho "<p>Checking Projekt: ".$a_dbRow['PROJ_NAME']." (ID: ".$a_dbRow['PROJ_ID'].")</p><ul>";
  598.                     if ($a_regExpNames=explode("\n",str_replace("\r","",$a_dbRow['PROJ_URLREGEX']))) {
  599.                         // we have regular expressions to check
  600.                         foreach($a_regExpNames as $s_pattern{
  601.                             $s_pattern=trim($s_pattern);
  602.                             if (!empty($s_pattern)) // skip empty lines
  603.                                 if ($debugecho "<li>Pattern$s_pattern<li>";
  604.                                 if (@preg_match($s_pattern,$_SERVER['SERVER_NAME'])) // <pk-06-01-05 /> @ added
  605.                                     if ($debugecho "</ul><p>MATCHES</p></blockquote>";
  606.                                     $o_Cursor->free()// as we don't know if we are at the last row
  607.                                     return intval($a_dbRow[$this->myIdColName]);
  608.                                     // <<<<<<<<<<<<<<< return point ----------------------------------------------------------
  609.                                 }
  610.                             }
  611.                         }
  612.                      }
  613.                 }
  614.             }
  615.         }
  616.  
  617.         // no project found try to find out from _SERVER['SERVER_NAME']
  618.         $s_query ="SELECT ".$this->myIdColName." FROM ".$this->myTable;
  619.         $s_query.=" WHERE UPPER(PROJ_URL)=".$this->myDBObj->qs_getSlashedValue(strtoupper($_SERVER['SERVER_NAME']));
  620.         if ($debugecho "<p>Searching Server: <br />".$s_query."</p>";
  621.         if ($i_Id=$this->myDBObj->quickQuery($s_query,0)) {
  622.             if ($this->cmsCacheIsUsable())
  623.             {
  624.                 $this->myCmsCache->addProjIdFromHTTP_HOST($i_Id);
  625.             }
  626.             if ($debugecho "<blockquote>ID from SERVER_NAME</blockquote>";
  627.             return $i_Id;
  628.         }
  629.  
  630.         if (isset($_SESSION[$this->myIdColName]&& intval($_SESSION[$this->myIdColName])) {
  631.             // fall back to session if set as we could not determine the
  632.             // a projectId
  633.             return intval($_SESSION[$this->myIdColName]);
  634.         }
  635.         return intval($a_firstProj[$this->myIdColName]);
  636.     }
  637.  
  638.  
  639.     /**
  640.       * tries to populate the project form the environment
  641.       * returns true if a page to show was found
  642.       *
  643.       * @param boolean $checkSession 
  644.       * @param boolean $debug 
  645.       *
  646.       * @return boolean 
  647.       *
  648.       * @since pk-05-07-11
  649.       * @version pk-05-08-08
  650.       * @version pk-07-06-07 session handling
  651.       * @version pk-07-08-13
  652.       *
  653.       * @var int $pagId 
  654.       * 
  655.       * @deprecated since pk-08-06-18
  656.       */
  657.     function populateFromEnv($checkSession=False,$debug=False{
  658.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::populateFromEnv()",($checkSession "checkSession\n" "").print_r($_GET,True));
  659.  
  660.         // <pk-07-08-13>
  661.         global $OCSP_OBJ;
  662.         if (!isset($OCSP_OBJ['SESSION']))
  663.         {
  664.             require_once $GLOBALS['OCSP']['PHPINCPATH']."common/OCSP_SESSION.phpclass";
  665.             OCSP_SESSION::start();
  666.         }
  667.  
  668.  
  669.         // first check if we have a page
  670.         if (isset($_GET[$this->myPageIdGetName]&& intval($_GET[$this->myPageIdGetName])) {
  671.             if ($this->setCurrentPage(intval($_GET[$this->myPageIdGetName]),False,True,$debug)) {  // ($pagId,$setMenu,$setProj)
  672.                 if ($debugechoDebug("<p><b>PageFound</b></p>");
  673.                 if ($checkSession$_SESSION[$this->myProjIdGetName]=$this->getId();
  674.                 return True;
  675.             }
  676.         }
  677.  
  678.         // secound check if we have a menu
  679.         if (isset($_GET[$this->myMenuIdGetName]&& intval($_GET[$this->myMenuIdGetName])) {
  680.             if ($this->setCurrentMenuNode(intval($_GET[$this->myMenuIdGetName]),True,$debug)) {
  681.                 if ($debugechoDebug("<p><b>MenuFound</b></p>");
  682.                 if ($checkSession$_SESSION[$this->myProjIdGetName]=$this->getId();
  683.                 return True;
  684.             }
  685.         }
  686.  
  687.         // third check the session
  688.         if ($checkSession && isset($_SESSION[$this->myProjIdGetName]&& intval($_SESSION[$this->myProjIdGetName]))
  689.         {
  690.             $this->setId($_SESSION[$this->myProjIdGetName]);
  691.         else {
  692.             $this->setId($this->getProjIdFromEnv($debug));
  693.             if ($checkSession$_SESSION[$this->myProjIdGetName]=$this->getId();
  694.         }
  695.  
  696.         if ($this->cmsCacheIsUsable(&& ($int_id=$this->getProjIdFromEnv()))
  697.         {
  698.             $this->setId($int_id);
  699.             $this->populateFromCache($debug);
  700.             return True;
  701.         else {
  702.             $this->dbPopulate($debug);
  703.             return True;
  704.         }
  705.  
  706.     }
  707.  
  708.  
  709.     /**
  710.       * gets the sortnumber from the database and
  711.       * calls the parent method
  712.       *
  713.       * @param bool $debug 
  714.       *
  715.       * @param return int
  716.       *
  717.       * @since pk-05-07-14
  718.       * @version pk-07-06-07
  719.       *
  720.       */
  721.     function dbInsert($debug=False{
  722.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::dbInsert()");
  723.  
  724.         $str_sortCol=$this-colPrevix."SORTORDER";
  725.         if (!intval($this->getDBField($str_sortCol)) && ($this->hasColumn($str_sortCol)))
  726.         {
  727.             $this->setDBField($str_sortCol,intval($this->myDBObj->quickQuery("SELECT MAX($str_sortColFROM T_CMS_PROJECT",0))+1);
  728.         }
  729.         return parent::dbInsert($debug);
  730.     }
  731.  
  732.     /**
  733.       * replaces the db values and clears cache
  734.       *
  735.       * @param boolean $debug 
  736.       *  @param boolean $ignorPopulated (if false the table MUST have been populated)
  737.       *
  738.       * @return boolean 
  739.       */
  740.     function dbReplace($debug=False,$ignorPopulated=False)
  741.     {
  742.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::dbReplace(".$this->getId().")");
  743.  
  744.         if (parent::dbReplace($debug,$ignorPopulated))
  745.         {
  746.             if ($this->cmsCacheIsUsable())
  747.             {
  748.                 $this->myCmsCache->cleanProject($this,$debug);
  749.             }
  750.             return True;
  751.         else {
  752.             return False;
  753.         }
  754.  
  755.     }
  756.  
  757.     // ######################################################################################################
  758.     //                                             MENU METHODS
  759.     // ######################################################################################################
  760.  
  761.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  762.     // menu tree (CMS_MENU)
  763.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  764.  
  765.     /**
  766.       * returns the menu tree from curMenuNode
  767.       *
  768.       * @param boolean $asPopulated (populates the keys)
  769.       * @param boolean $debug 
  770.       *
  771.       * @return CMS_MENU 
  772.       *
  773.       * @version pk-06-07-26
  774.       * @version pk-07-06-15 (caching)
  775.       *
  776.       */
  777.     function &getMenuTree($asPopulated=False,$debug=False{
  778.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::getMenuTree()",($asPopulated "populated" ""));
  779.  
  780.         if (!pcf_is_instance_of($this->myMenuTree,'CMS_MENU'))
  781.         {
  782.             $this->myMenuTree=CMS_MENU::getInstance($this->getId());
  783.         else  if ($asPopulated{
  784.             if (!$this->myMenuTree->isPopulated())
  785.             {
  786.                 $this->myMenuTree->populateTree(True,True,"",$debug);
  787.             }
  788.         }
  789.  
  790.         $this->myMenuTree->setMyProject($this);
  791.         return $this->myMenuTree;
  792.     }
  793.  
  794.  
  795.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  796.     // menu nodes (CMS_MENU_NODE)
  797.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  798.  
  799.     /**
  800.       * returns the current menu
  801.       *
  802.       * @param boolean $debug 
  803.       * @param boolean $checkPage (a menu node with an online page for the user is returned)
  804.       *
  805.       * @return CMS_MENU_NODE 
  806.       *
  807.       * @since pk-05-07-11
  808.       * @version pk-06-07-26
  809.       * @version pk-07-08-15
  810.       * @version pk-07-10-03
  811.       * @version pk-08-10-05 use CMS_TABLEOBJ::get_current*
  812.       */
  813.     function &getCurrentMenuNode($debug=False,$checkPage=True)
  814.     {
  815.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::getCurrentMenuNode()");
  816.         
  817.         if (is_object($this->myMenuNode&& pcf_class_implements($this->myMenuNode,'INFA_CMS_MENU_NODE'))
  818.         {
  819.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning already set object");
  820.             return $this->myMenuNode;
  821.         }
  822.  
  823.         if (is_object($this->myPageObj&& pcf_class_implements($this->myPageObj,'INFA_CMS_PAGE'))
  824.         {
  825.             $this->myMenuNode = $this->myPageObj->getMyMenuNode($debug);
  826.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning menu from already set page object");
  827.             return $this->myMenuNode;            
  828.         }
  829.         
  830.         
  831.         $bol_setAsCurrent False;
  832.         if ($this->isCurrent())
  833.         {
  834.             $obj_menu CMS_TABLEOBJ::get_currentMenu();
  835.             if (is_object($obj_menu&& pcf_class_implements($obj_menu,'INFA_CMS_MENU_NODE'))
  836.             {
  837.                 $this->myMenuNode = CMS_TABLEOBJ::get_currentMenu();
  838.                 if ($debugechoDebugLine(__FILE__,__LINE__,"returning current menu Obj");
  839.                 return $this->myMenuNode;
  840.             else {
  841.                 $bol_setAsCurrent True;
  842.             
  843.         
  844.             $obj_page CMS_TABLEOBJ::get_currentPage();
  845.             if (is_object($obj_page&& pcf_class_implements($obj_menu,'INFA_CMS_PAGE'))
  846.             {
  847.                 $this->myPageObj     = CMS_TABLEOBJ::get_currentPage();
  848.                 if ($bol_setAsCurrent)
  849.                 {
  850.                     CMS_TABLEOBJ::set_currentMenu($this->myPageObj->getMyMenuNode($debug));
  851.                 }
  852.                 $this->myMenuNode     = $this->myPageObj->getMyMenuNode($debug);
  853.                 if ($debugechoDebugLine(__FILE__,__LINE__,"returning menu from current page Obj");
  854.                 return $this->myMenuNode;
  855.             }
  856.         }
  857.  
  858.         
  859.  
  860.         if (pcf_is_instance_of($this->myPageObj,'CMS_PAGE_V2'))
  861.         {
  862.             if ($debugechoDebugMethod(__FILE__,__LINE__,"returning the menu of myPageObj");
  863.             return $this->myPageObj->getMyMenuNode($debug);
  864.         }
  865.  
  866.         if ($debugocsp_logError(__FILE__,__LINE__,"current menu not set",E_NOTICE);
  867.         pcf_require_class('CMS_MENU_NODE',"cms/menu/");
  868.         
  869.         if (!($this->myMenuNode=CMS_MENU_NODE::factoryFromKey($this->getId(),$this->getMenId(),$debug)))
  870.         {
  871.             $this->myMenuNode=new CMS_MENU_NODE(intval($this->getMenId()),"T_CMS_MENU".intval($this->getId()),True,$debug);
  872.             if (!intval($this->myMenuNode->getId())) $this->myMenuNode->setId(0);
  873.         }
  874.         $this->myMenuNode->setMyProject($this,$debug);
  875.  
  876.  
  877.         if ($checkPage{
  878.             $obj_page=$this->getCurrentPage($debug);
  879.             $this->myMenuNode = $obj_page->getMyMenuNode();
  880.              
  881.             if ($bol_setAsCurrent
  882.             {
  883.                 CMS_TABLEOBJ::set_currentMenu($obj_page->getMyMenuNode());
  884.             }            
  885.             return $this->myMenuNode;
  886.         }
  887.  
  888.         return $this->myMenuNode;
  889.     }
  890.  
  891.  
  892.  
  893.  
  894.     /**
  895.       * returns a new menu node overwrite this in child classes as needed
  896.       *
  897.       * @param mixed $values (array) dbval or (int) menId
  898.       * @param boolean $debug 
  899.       *
  900.       * @return CMS_MENU_NODE 
  901.       *
  902.       * @since pk-05-07-13
  903.       * @version pk-05-12-12
  904.       * @version pk-07-08-15 param values type mixed
  905.       *
  906.       *
  907.       * @requires CMS_MENU_NODE.phpclass
  908.       *
  909.       * @todo CMS_PROJECT::newMenuNode() setTitle() for 0 german of Root is set
  910.       */
  911.     function &newMenuNode($values,$debug{
  912.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::newMenuNode()",print_r($values,True));
  913.  
  914.         if ($debugecho("<blockquote style=\"font-size: 80%\">");
  915.         if ($this->getMenuTree(False,$debug))
  916.         {
  917.             if ($debugecho("</blockquote>");
  918.             if (is_array($values&& isset($values['MEN_ID']))
  919.             {
  920.                 if ($debugechoDebugLine(__FILE__,__LINE__,"value array submitted");
  921.                 if (!($obj_Node=$this->myMenuTree->getNodeObjectFromCache($values['MEN_ID'],$debug)))
  922.                 {
  923.                     $obj_Node=$this->myMenuTree->newNodeObject($values['MEN_ID'],$values,$debug);
  924.                 }
  925.             else if ($i_id=intval($values)) {
  926.                 if ($debugechoDebugLine(__FILE__,__LINE__,"id submitted");
  927.                 if (!($obj_Node=$this->myMenuTree->getNodeObjectFromCache($i_id,$debug)))
  928.                 {
  929.                     $obj_Node=$this->myMenuTree->populateNode($i_id,False,$debug);
  930.                 }
  931.             }
  932.  
  933.             if (!pcf_is_instance_of($obj_Node,'CMS_MENU_NODE')) {
  934.                 $obj_Node=new CMS_MENU_NODE();
  935.                 $obj_Node->setId(0);
  936.                 $obj_Node->setTitle("Wurzel");
  937.             }
  938.             
  939.             $obj_Node->setMyProject($this,$debug);            
  940.             return $obj_Node;
  941.         }
  942.         if ($debugechoDebug("</blockquote>");
  943.         ocsp_logError(__FILE__,__LINE__,"could not get menu tree",E_ERROR);
  944.     }
  945.  
  946.     // ######################################################################################################
  947.     //                                             PAGE METHODS
  948.     // ######################################################################################################
  949.  
  950.     /**
  951.       * returns the current page
  952.       *
  953.       * @param boolean $debug 
  954.       *
  955.       * @return CMS_PAGE 
  956.       *
  957.       * @requires CMS_PAGE.phpclass
  958.       *
  959.       * @version pk-07-08-15
  960.       * @version pk-08-10-05
  961.       */
  962.     function &getCurrentPage($debug=False)
  963.     {        
  964.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::getCurrentPage()");
  965.  
  966.         if (pcf_class_implements($this->myPageObj,'INFA_CMS_PAGE'))
  967.         {        
  968.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning object var \$this->myPageObj");
  969.             return $this->myPageObj;
  970.         }
  971.         
  972.         if (is_object(self::$currentPage&& method_exists(self::$currentPage,'getProjId'))
  973.         {            
  974.             if (self::$currentPage->getProjId(== $this->getId())
  975.             {
  976.                 if ($debugechoDebugLine(__FILE__,__LINE__,"returning class var  self::\$currentPage");
  977.                 if (!$this->myPageObj)
  978.                 {
  979.                     $this->myPageObj = &self::$currentPage;
  980.                 }
  981.                 return self::$currentPage;
  982.             }
  983.         }
  984.  
  985.         if ($this->getPageId())
  986.         {
  987.             require_once __OCSP_CMS_PHPINCPATH__."page/CMS_PAGE_V2.phpclass";
  988.             $this->myPageObj=CMS_PAGE_V2::CMS_PAGE_FROM_ID($this->getPageId(),True,$debug);
  989.             if ($debugechoDebugLine(__FILE__,__LINE__,"returning page ID: ".$this->getPageId()." class: ".get_class($this->myPageObj));
  990.             return $this->myPageObj;
  991.         }
  992.  
  993.         if (!pcf_is_instance_of($this->myMenuNode,'CMS_MENU_NODE'))
  994.         {
  995.             $this->getCurrentMenuNode($debug)// ensure $this->myMenuNode is set
  996.         }
  997.  
  998.         if ($debugechoDebugLine(__FILE__,__LINE__,"<p>myMenuNode: ".get_class($this->myMenuNode)." ID: ".$this->myMenuNode->getId()."</p>");
  999.  
  1000.         if ($this->myPageObj=$this->myMenuNode->getCurrentPage(True,True,NULL,$debug)) // goDown,online,xtraCondition
  1001.         {
  1002.             return $this->myPageObj;
  1003.         else {
  1004.             ocsp_logError(__FILE__,__LINE__,"could not find any page",E_ERROR);
  1005.             die();
  1006.         }
  1007.  
  1008.  
  1009.     }
  1010.  
  1011.     /**
  1012.      * returns the page template Id for the subpages
  1013.      *
  1014.      * @param boolean $debug 
  1015.      * 
  1016.      * @return int 
  1017.      * 
  1018.      * @since pk-08-06-07
  1019.      */
  1020.     public function getPageTmplateId($debug=False)
  1021.     {
  1022.          if ($int_ret $this->getDBField('PTMP_ID'))
  1023.         {
  1024.             return $int_ret;
  1025.         else {
  1026.             $str_query "SELECT PTMP_ID FROM T_CMS_TMPL_PAGE";
  1027.             $str_query.= " WHERE PROJ_ID IN(0," $this->getId(")";
  1028.             $str_query.= " ORDER BY PTMP_ISDEFAULT DESC,PROJ_ID DESC";
  1029.             
  1030.             if (!$this->isConnected(True))
  1031.             {
  1032.                 throw new Exception(_OCSP_EXCEP_NODBCONN_);
  1033.             }
  1034.             return $this->myDBObj->getOne($str_query);
  1035.         }
  1036.     }
  1037.  
  1038.  
  1039.     // ######################################################################################################
  1040.     //                                             LAYOUT / OUTPUT METHODS
  1041.     // ######################################################################################################
  1042.  
  1043.     // ____________________________________________
  1044.  
  1045.     /**
  1046.       * returns the include file for the page
  1047.       *
  1048.       * @param boolean $debug since  pk-06-11-23
  1049.       *
  1050.       * @return string 
  1051.       *
  1052.       * @since pk-05-07-12
  1053.       *
  1054.       * @version pk-05-12-02
  1055.       * @version pk-06-11-23
  1056.       * @version pk-07-08-22
  1057.       *
  1058.       */
  1059.     function getIndexPHP_inc($debug=False{
  1060.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::getIndexPHP_inc()",print_r($this->getDBVal(),True));
  1061.  
  1062.         $s_incFile=$this->getDBField('PROJ_INDEXPHPINC');
  1063.         if (empty($s_incFile&& (OCSP_CMS_CONF::getInstance()->getValue('DEFAULT_INDEXPHPINC')))
  1064.         {
  1065.             $s_incFile OCSP_CMS_CONF::getInstance()->getValue('DEFAULT_INDEXPHPINC')
  1066.         }
  1067.             
  1068.  
  1069.         if ($debugecho "<p>PROJ_INDEXPHPINC: ".$s_incFile."</p>";
  1070.  
  1071.         if (!empty($s_incFile)) {
  1072.             if (file_exists(OCSP_OBJ::getConf('PROJECTPATH').$s_incFile)) {
  1073.                 if ($debugechoDebug(__FILE__,"<p>Returning:  \OCSP_OBJ::getConf('PROJECTPATH') $s_incFile</p>");
  1074.                 return OCSP_OBJ::getConf('PROJECTPATH').$s_incFile;
  1075.             }
  1076.             if (file_exists(OCSP_OBJ::getConf('TEMPLATEPATH').$s_incFile)) {
  1077.                 if ($debugechoDebug(__FILE__,"<p>Returning ['PROJECT']['TEMPLPATH']$s_incFile</p>");
  1078.                 return OCSP_OBJ::getConf('TEMPLATEPATH').$s_incFile;
  1079.             }
  1080.         }
  1081.  
  1082.         if ($debug
  1083.         {
  1084.             echoDebugLine(__FILE__,__LINE__,"NO page include found<pre>OCSP_CONF: ".print_r($OCSP_CONF,True)."</pre>");
  1085.         }
  1086.         return Null;
  1087.  
  1088.     }
  1089.  
  1090.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1091.     // css project styles
  1092.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1093.  
  1094.     /**
  1095.       * returns the html code for the css style section in the header
  1096.       * if $media is not empty the styles are filter by this media
  1097.       *
  1098.       * the return value is treatend as template and parsed with $this->getDBVal() values
  1099.       *
  1100.       * @param string $media 
  1101.       * @param boolean $projectOnly 
  1102.       * @param boolean $asTemplate if True the return value is not parsed
  1103.       * @param boolean $debug 
  1104.       *
  1105.       * @return string 
  1106.       * @access public
  1107.       *
  1108.       * @since pk-06-07-19
  1109.       *
  1110.       * @requires __OCSP_CMS_PHPINCPATH__."css/CMS_CSSSTYLE.phpclass";
  1111.       * @access public
  1112.       */
  1113.     function getCSS_definition($media="",$projectOnly=False,$asTemplate=False,$debug=False{
  1114.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::getCSS_definition()");
  1115.  
  1116.         require_once __OCSP_CMS_PHPINCPATH__."css/CMS_CSSSTYLE.phpclass";
  1117.  
  1118.         $s_query="SELECT * FROM T_CMS_CSSSTYLES WHERE (PROJ_ID=".$this->getId();
  1119.         if (!$projectOnly{
  1120.             $s_query.=" OR PROJ_ID=0";
  1121.         }
  1122.         $s_query.=") AND STY_ALWAYSUSE=1";
  1123.         $s_query.=" ORDER BY PROJ_ID,STY_SORTORDER,STY_ID";
  1124.  
  1125.         if ($debugecho "<p style=\"padding-left:30px\">Query: ".$s_query."</p>";
  1126.  
  1127.         if ($o_styCursor=$this->myDBObj->query($s_query)) {
  1128.             $s_ret="<style type=\"text/css\">\n<!--\n";
  1129.             $s_ret."/* CMS_PROJECT::getCSS_definition(media$media,projectOnly".($projectOnly "True" "False").") */\n";
  1130.             while($a_sty=$o_styCursor->fetchArrayFld()) {
  1131.                 if ($debugecho "<p style=\"padding-left:45px;font-size:90%\">adding style: ".$a_sty['STY_NAME']."(".$a_sty['STY_ID'].")</p>\n";
  1132.  
  1133.                 $o_style=new CMS_CSSSTYLE();
  1134.                 $o_style->setDBRow($a_sty);
  1135.                 $s_ret.=$o_style->getCSSCode($media,($projectOnly $this->getId(: -1),$debug);
  1136.  
  1137.                 if (!empty($a_sty['STY_JAVACODE'])) {
  1138.                     $s_ret.="/* __STY_JAVACODE__START__ */\n";
  1139.                     $s_ret.="-->\n</style>\n";
  1140.                     $s_ret.="<script language=\"javascript\" type=\"text/javascript\">\n<!--\n";
  1141.                     $s_ret.=$a_sty['STY_JAVACODE'];
  1142.                     $s_ret.="\n//-->\n</script>\n";
  1143.                     $s_ret.="<!-- __STY_JAVACODE__END__ -->\n";
  1144.                     $s_ret.="<style type=\"text/css\">\n<!--\n";
  1145.                 }
  1146.            // while($a_sty=$o_styCursor->fetchArrayFld())
  1147.  
  1148.  
  1149.             $s_ret.="-->\n</style>\n\n";
  1150.             $s_ret.="\n <!-- /* DONE CMS_PROJECT::getCSS_definition */ --> \n";
  1151.         else {
  1152.             $s_ret="\n<!-- \n/* CMS_PROJECT::getCSS_definition() could not select any styles */\n-->\n";
  1153.         }
  1154.  
  1155.         if ($this->getDBField("PROJ_CSSINCLUDE")) {
  1156.             $s_ret.="<!--\n___START___PROJ_CSSINCLUDE___ (CMS_PROJECT::PROJ_CSSINCLUDE)\n-->\n";
  1157.             $s_ret.=$this->getDBField("PROJ_CSSINCLUDE")."\n";
  1158.             $s_ret.="\n<!--\n___END___PROJ_CSSINCLUDE___\n-->\n";
  1159.         }
  1160.  
  1161.         if ($asTemplate{
  1162.             return $s_ret;
  1163.         else {
  1164.             require_once $GLOBALS['OCSP']['PHPINCPATH']."common/pcf_templates.phpinc";
  1165.             return pcf_tmpl_parse($s_ret,$this->getDBVal(),$debug);
  1166.         }
  1167.     }
  1168.  
  1169.     /**
  1170.       * returns the an array with css formatings
  1171.       *
  1172.       * @param OCSP_CMS_HTMLPAGE $htmlPage 
  1173.       * @param boolean $debug 
  1174.       *
  1175.       * @access public
  1176.       * @since pk-07-06-08
  1177.       *
  1178.       * @requires __OCSP_CMS_PHPINCPATH__."css/CMS_CSSSTYLE.phpclass";
  1179.       *
  1180.       */
  1181.     function addCssToHTMLPage(&$htmlPage,$debug=False)
  1182.     {
  1183.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::addCssToHTMLPage()");
  1184.         if (pcf_is_instance_of($htmlPage,'OCSP_HTMLPAGE'))
  1185.         {
  1186.             $arr_Styles=NULL;
  1187.             if ($this->cmsCacheIsUsable())
  1188.             {
  1189.                 $arr_Styles=$this->myCmsCache->getProjCssArray($this->getId(),$debug);
  1190.             }
  1191.  
  1192.             if (!is_array($arr_Styles))
  1193.             {
  1194.                 $arr_Styles=array();
  1195.                 if (!$this->isConnected(True,$debug))
  1196.                 {
  1197.                     die("No Database");
  1198.                 }
  1199.  
  1200.                 require_once __OCSP_CMS_PHPINCPATH__."css/CMS_CSSSTYLE.phpclass";
  1201.  
  1202.                 $s_query="SELECT * FROM T_CMS_CSSSTYLES WHERE (PROJ_ID=".$this->getId()." OR PROJ_ID=0) AND STY_ALWAYSUSE=1";
  1203.                 $s_query.=" ORDER BY PROJ_ID,STY_SORTORDER,STY_ID";
  1204.  
  1205.                 if ($o_styCursor=$this->myDBObj->query($s_query)) {
  1206.                     while($arr_row=$o_styCursor->fetchArrayFld())
  1207.                     {
  1208.                         $obj_style=new CMS_CSSSTYLE();
  1209.                         $obj_style->setDBObj($this->myDBObj);
  1210.                         $obj_style->setDBRow($arr_row,True);
  1211.  
  1212.                         $arr_Styles[$obj_style->getId()]=array(
  1213.                                 'INC_LINK'  => $obj_style->getIncludeFile(),
  1214.                                 'INC_JS'    => $obj_style->getJSCode(),
  1215.                                 'CSS_TXT'   => $arr_row['STY_TXT'],
  1216.                                 'CSS_ARR'   => $obj_style->getCssClassArray()
  1217.                             );
  1218.  
  1219.                     }
  1220.                 }
  1221.                 if ($this->cmsCacheIsUsable())
  1222.                 {
  1223.                     $this->myCmsCache->setProjCssArray($this->getId(),$arr_Styles,$debug);
  1224.                 }
  1225.             }
  1226.  
  1227.             foreach($arr_Styles as $int_Id => $arr_sty)
  1228.             {
  1229.                 if ($int_Id != 'PEARCACHE_TS')
  1230.                 {
  1231.                     if (!empty($arr_sty['INC_LINK']))
  1232.                     {
  1233.                         $htmlPage->addCssSrcLink("<!-- STY_ID: ".$int_Id." -->\n".$arr_sty['INC_LINK']);
  1234.                     }
  1235.                     $htmlPage->addCssCode("/* ------------------------------------------------ \n\tSTY_ID$int_Id\n   ----- */");
  1236.                     if (!empty($arr_sty['CSS_TXT']))
  1237.                     {
  1238.                         $htmlPage->addCssCode($arr_sty['CSS_TXT']);
  1239.                     }
  1240.                     if (is_array($arr_sty['CSS_ARR']))
  1241.                     {
  1242.                         foreach($arr_sty['CSS_ARR'as $arr_css)
  1243.                         {
  1244.                             $htmlPage->addCssCode($arr_css['CSS_NAME']." {".$arr_css['CSS_DEFINITION']."}");
  1245.                         }
  1246.                     }
  1247.                     if (!empty($arr_sty['INC_JS']))
  1248.                     {
  1249.                         $htmlPage->addJsCode($arr_sty['INC_JS']);
  1250.                     }
  1251.                 }
  1252.             }
  1253.         }
  1254.     }
  1255.  
  1256.  
  1257.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1258.     // rights
  1259.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1260.  
  1261.     
  1262.     /**
  1263.       * returns the real group id for:
  1264.       * <code>
  1265.       *     _OCSP_GROUP_PROJ_ADMINGRP_     = -80;
  1266.       *     _OCSP_GROUP_PROJ_EDITOR_GRP_   = -81;
  1267.       *     _OCSP_GROUP_PROJ_AUTHOR_GRP_   = -82;
  1268.       *     _OCSP_GROUP_PROJ_USER_GRP_     = -83;
  1269.       * </code>
  1270.       *
  1271.       * @param int $projGrpId 
  1272.       * @param boolean $debug 
  1273.       *
  1274.       * @return int 
  1275.       *
  1276.       * @since pk-06-11-10
  1277.       *
  1278.       */
  1279.     function getProjGrpId($projGrpId,$debug=False{
  1280.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::getProjGrpId(".$projGrpId.")");
  1281.  
  1282.         switch($projGrpId{
  1283.             case _OCSP_GROUP_PROJ_ADMINGRP_:
  1284.                 $i_admGrp=$this->getDBField($this->colPrevix."ADMINGRP");
  1285.                 return (intval($i_admGrpintval($i_admGrp$GLOBALS['GROUPS']['CMSADMIN']);
  1286.             case _OCSP_GROUP_PROJ_EDITOR_GRP_:
  1287.                 $i_editorGrp=intval($this->getDBField($this->colPrevix."EDITOR_GRP"));
  1288.                 return (intval($i_editorGrpintval($i_editorGrp_OCSP_GROUP_CMSEDITOR_);
  1289.             case _OCSP_GROUP_PROJ_AUTHOR_GRP_:
  1290.                 $i_authorGrp=intval($this->getDBField($this->colPrevix."AUTHOR_GRP"));
  1291.                 return (intval($i_editorGrpintval($i_editorGrp_OCSP_GROUP_CMSAUTHOR_);
  1292.             default:
  1293.                 return intval($this->getDBField($this->colPrevix.'USRGRP'));
  1294.         }
  1295.     }
  1296.  
  1297.     /**
  1298.       * returns if the current user is member of the project group
  1299.       * <code>
  1300.       *     _OCSP_GROUP_PROJ_ADMINGRP_     = -80;
  1301.       *     _OCSP_GROUP_PROJ_EDITOR_GRP_   = -81;
  1302.       *     _OCSP_GROUP_PROJ_AUTHOR_GRP_   = -82;
  1303.       *     _OCSP_GROUP_PROJ_USER_GRP_     = -83;
  1304.       * </code>
  1305.       *
  1306.       * @param int $projGrpId 
  1307.       * @param boolean $strict only check the group do not check higher rights
  1308.       * @param boolean $debug 
  1309.       *
  1310.       * @return boolean 
  1311.       *
  1312.       * @since pk-06-11-10
  1313.       *
  1314.       */
  1315.     function curUserIsProjGrpMember($projGrpId,$strict=False,$debug=False{
  1316.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::curUserIsProjGrpMember(".$projGrpId.")");
  1317.  
  1318.         switch($projGrpId{
  1319.             case _OCSP_GROUP_PROJ_USER_GRP_:
  1320.                 if (OCSP_OBJ::currentUser()->isGroupMember($this->getProjGrpId($projGrpId,$debug))) {
  1321.                     return True;
  1322.                 else if ($strict{
  1323.                     return False;
  1324.                 }
  1325.             case _OCSP_GROUP_PROJ_AUTHOR_GRP_:
  1326.                 if (OCSP_OBJ::currentUser()->isGroupMember($this->getProjGrpId($projGrpId,$debug))) {
  1327.                     return True;
  1328.                 else if ($strict{
  1329.                     return False;
  1330.                 }
  1331.             case _OCSP_GROUP_PROJ_EDITOR_GRP_:
  1332.                 if (OCSP_OBJ::currentUser()->isGroupMember($this->getProjGrpId($projGrpId,$debug))) {
  1333.                     return True;
  1334.                 else if ($strict{
  1335.                     return False;
  1336.                 }
  1337.             case _OCSP_GROUP_PROJ_ADMINGRP_:
  1338.                 return (OCSP_OBJ::currentUser()->isGroupMember($this->getProjGrpId($projGrpId,$debug)));
  1339.             default:
  1340.                 return False;
  1341.         }
  1342.     }
  1343.  
  1344.     /**
  1345.       * returns if the current user is an administrator of the project
  1346.       *
  1347.       * @param boolean $debug 
  1348.       * @global array $OCSP_OBJ 
  1349.       * @return boolean 
  1350.       *
  1351.       * @since pk-05-09-01
  1352.       *
  1353.       */
  1354.     function curUserIsAdmin($debug=False{
  1355.         if ($debugecho "<p><b>CMS_PROJECT::curUserIsAdmin()</b> (".get_class($this).")</p>\n";
  1356.  
  1357.         if (OCSP_OBJ::currentUser()->isAdmin()) return True;
  1358.         if (OCSP_OBJ::currentUser()->isPublic()) return False;
  1359.         
  1360.         if ($admGrp=intval($this->getDBField($this->colPrevix."ADMINGRP"))) {
  1361.             if (OCSP_OBJ::currentUser()->isGroupMember($admGrp)) return True;
  1362.         }
  1363.         return OCSP_OBJ::currentUser()->isGroupMember(_OCSP_GROUP_CMSADMIN_);
  1364.     }
  1365.  
  1366.     /**
  1367.       * returns if the current user is an editor of the project
  1368.       *
  1369.       * @param boolean $debug 
  1370.       * @global array $OCSP_OBJ 
  1371.       * @return boolean 
  1372.       *
  1373.       * @since pk-05-12-14
  1374.       *
  1375.       */
  1376.     function curUserIsEditor($debug=False{
  1377.         if ($debugecho "<p><b>CMS_PROJECT::curUserIsEditor()</b> (".get_class($this).")</p>\n";
  1378.  
  1379.         if (OCSP_OBJ::currentUser()->isPublic()) return False;
  1380.  
  1381.         if ($editorGrp=intval($this->getDBField($this->colPrevix."EDITOR_GRP"))) {
  1382.             if (OCSP_OBJ::currentUser()->isGroupMember($editorGrp)) return True;
  1383.         else {
  1384.             if (OCSP_OBJ::currentUser()->isGroupMember(_OCSP_GROUP_CMSEDITOR_)) return True;
  1385.         }
  1386.  
  1387.         if (OCSP_OBJ::currentUser()->isGroupMember(_OCSP_GROUP_CMSEDITOR_))
  1388.         {
  1389.             return True;
  1390.         else {
  1391.             return $this->curUserIsAdmin($debug);
  1392.         }
  1393.     }
  1394.  
  1395.     /**
  1396.       * returns if the current user is an author of the project
  1397.       *
  1398.       * @param boolean $debug 
  1399.       * @global array $OCSP_OBJ 
  1400.       *
  1401.       * @return boolean 
  1402.       *
  1403.       * @since pk-05-12-14
  1404.       *
  1405.       */
  1406.     function curUserIsAuthor($debug=False{
  1407.         if ($debugecho "<p><b>CMS_PROJECT::curUserIsAuthor()</b> (".get_class($this).")</p>\n";
  1408.  
  1409.         if (OCSP_OBJ::currentUser()->isPublic()) return False;
  1410.         if (OCSP_OBJ::currentUser()->isGroupMember(_OCSP_GROUP_CMSAUTHOR_)) return True;
  1411.  
  1412.         if ($authorGrp=intval($this->getDBField($this->colPrevix."AUTHOR_GRP"))) {
  1413.             if ($debugecho "<p>checking group (".$this->colPrevix."AUTHOR_GRP) ID: ".$authorGrp."</p>";
  1414.             if (OCSP_OBJ::currentUser()->isGroupMember($authorGrp)) return True;
  1415.         }
  1416.  
  1417.            if (OCSP_OBJ::currentUser()->isGroupMember(_OCSP_GROUP_CMSAUTHOR_))
  1418.         {
  1419.             return True;
  1420.         else {        
  1421.             // check if the user is member of a group with heigher rights:
  1422.             return $this->curUserIsEditor($debug);
  1423.         }
  1424.     }
  1425.  
  1426.     /**
  1427.       * returns if the current user can open the project
  1428.       *
  1429.       * @param boolean $debug 
  1430.       *
  1431.       * @return boolean 
  1432.       *
  1433.       * @since pk-05-11-03
  1434.       * @version pk-06-11-10 PROJ_ -> $this->colPrevix
  1435.       *
  1436.       */
  1437.     function curUserCanOpen($debug=False{
  1438.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::curUserCanOpen()");
  1439.         
  1440.         if ($int_projGrp intval($this->getDBField($this->colPrevix.'USRGRP'))) 
  1441.         {
  1442.             if (OCSP_OBJ::currentUser(True)->isGroupMember($int_projGrp))
  1443.             {
  1444.                 return True;
  1445.             }
  1446.             return $this->curUserIsAuthor($debug);
  1447.         else {
  1448.             // public project
  1449.             return True;
  1450.         }
  1451.     }    
  1452.     
  1453.     /**
  1454.       * @param boolean $debug 
  1455.       * @return boolean 
  1456.       * @since pk-05-09-01
  1457.       */
  1458.     function curUserCanEdit($debug=False{
  1459.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::curUserCanEdit()","Project: ".$this->getId());
  1460.         return $this->curUserIsAuthor($debug);
  1461.     }
  1462.     
  1463.     /**
  1464.      * returns if the current user can delete the project
  1465.      * 
  1466.      * @param boolean $debug 
  1467.      * 
  1468.      * @return boolean 
  1469.      * 
  1470.      * @since pk-08-11-30
  1471.      */
  1472.     public function curUserCanDelete($debug=False)
  1473.     {
  1474.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::curUserCanDelete()");
  1475.         return $this->curUserIsAdmin();
  1476.     }
  1477.     
  1478.     /** ---------------------------------------------------------------------------------------------------------
  1479.       * cache methods
  1480.       * ---------------------------------------------------------------------------------------------------------
  1481.       */
  1482.  
  1483.     /**
  1484.       * tries to load the project form the cache
  1485.       * if failed $this->dbPopulate() is called
  1486.       *
  1487.       * @param boolean $debug 
  1488.       *
  1489.       * @return boolean 
  1490.       * @access public
  1491.       *
  1492.       */
  1493.     function populateFromCache($debug=False)
  1494.     {
  1495.         if ($debugechoDebugMethod(__FILE__,get_class($this),"CMS_PROJECT::populateFromCache()","PROJ_ID: ".$this->getId());
  1496.  
  1497.         if (!$this->cmsCacheIsUsable()) {
  1498.             if ($debugechoDebugLine(__FILE__,__LINE__,"cache is disabled");
  1499.             return $this->dbPopulate();
  1500.         }
  1501.  
  1502.         $arr_dbVals=$this->myCmsCache->getProjDBValues($this->getId(),$debug);
  1503.         if ($this->setCmsCacheArr($arr_dbVals,$debug))
  1504.         {
  1505.             return True;
  1506.         else {
  1507.             if ($this->dbPopulate($debug))
  1508.             {
  1509.                 $this->myCmsCache->setProjDBValues($this,$debug);
  1510.                 return True;
  1511.             }
  1512.         }
  1513.         return False;
  1514.     }
  1515.  
  1516. }
  1517.  
  1518. ?>

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