Source for file CMS_PROJECT.phpclass
Documentation is available at CMS_PROJECT.phpclass
* Class file CMS_PROJECT.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: CMS_PROJECT.phpclass,v 1.27 2008/12/02 07:36:22 pitlinz Exp $
if (!defined('__OCSP_CMS_PHPINCPATH__'))
require_once __OCSP_DEFAULTCONFPATH__.
"cms.conf.phpinc";
require_once __OCSP_PHPINCPATH__.
"common".
_OCSP_DIRSEP_.
"pcf.phpinc";
require_once __OCSP_CMS_PHPINCPATH__.
"menu".
_OCSP_DIRSEP_.
"CMS_MENU_V2.phpclass";
* Class file CMS_PROJECT.phpclass
* @project Open CSP-Management
* @author Peter Krebs <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version pk-06-08-03 changed parent class from DBMS_TABLEOBJ to CMS_TABLEOBJ
* @version $Id: CMS_PROJECT.phpclass,v 1.27 2008/12/02 07:36:22 pitlinz Exp $
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @constant string CLASS_SRC_FILE
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** class vars ------------------------------------------------------ */
* unit of work for projects
* @staticvar array $loadedProjects
protected static $loadedProjects =
array();
/*** class methods --------------------------------------------------- */
* returns an instance of CMS_PROJECT
* uses self::$loadedProjects as unit of work
public static function &getInstance($aId,$force=
False,$debug=
False)
if ($debug) echoDebugMethod(__FILE__
,"static","CMS_PROJECT::getInstance({$aId})");
if (!isset
(self::$loadedProjects[$aId]) ||
!self::$loadedProjects[$aId])
self::$loadedProjects[$aId] =
self::factoryFromId($aId,$force);
return self::$loadedProjects[$aId];
public static function setInstance(&$aProject,$debug=
False)
if ($debug) echoDebugMethod(__FILE__
,"static","CMS_PROJECT::setInstance()");
self::$loadedProjects[$aProject->getId()] =
$aProject;
* returns if the project with $aId is in $loadedProjects
return (isset
(self::$loadedProjects[$aId]) ||
self::$loadedProjects[$aId]);
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
/*** compostion --------------------------------------------------- */
/*** attributes -------------------------------------------------- */
* @var string $myTable name of the db table
* @var string $myIdColName
* fields in $this->myTable starts with
* @var string $myMenuTable
* @var string $myPageTable
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* faktories a project object from the environment
if ($debug) echoDebugMethod(__FILE__
,"static","CMS_PROJECT::factoryFromEnv()");
$int_projId =
(isset
($_GET[self::getProjIdGetName()]) ?
intval($_GET[self::getProjIdGetName()]) :
(isset
($_GET[self::getProjIdColName()]) ?
intval($_GET[self::getProjIdColName()]) :
0));
$int_projId =
(intval($int_projId) ?
$int_projId :
(isset
($_SERVER['PROJ_ID']) ?
intval($_SERVER['PROJ_ID']) :
0));
if ($obj_project =
self::factoryFromId($int_projId))
return self::factoryFromDBRow($arr_row,$debug);
if ($arr_projectRows =
OCSP_OBJ::defaultReadDBObj()->getArray('T_CMS_PROJECT',array('PROJ_SHOW' =>
1),0,0,'PROJ_SORTORDER,PROJ_ISDEFAULT DESC',$debug))
foreach($arr_projectRows as $arr_row)
if (!$arr_default &&
intval($arr_row['PROJ_ISDEFAULT']))
if (stristr($_SERVER['SERVER_NAME'],$arr_row['PROJ_URL']))
break; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
if (!$arr_project &&
!empty($arr_row['PROJ_URLREGEX']))
foreach($arr_regex as $str_pattern)
if (!empty($str_pattern))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"checking regex pattern {$str_pattern}");
if (@preg_match($str_pattern,$_SERVER['SERVER_NAME']))
return self::factoryFromDBRow($arr_project,$debug);
return self::factoryFromDBRow($arr_default,$debug);
return self::factoryFromDBRow($arr_projectRows[0]);
* faktories a project from $aId
public static function factoryFromId($aId,$force=
False,$debug=
False)
if ($debug) echoDebugMethod(__FILE__
,"static","CMS_PROJECT::factoryFromId()");
return self::factoryFromDBRow($arr_row,$debug);
* faktories a menu object from a database row
$obj_project->setDBRow($dbRow,True,$debug);
* init the object and populate if an id is submitted
* generates a project object for the current environment settings
* also sets the following objects:
* @param boolean $setGlobals if true the global variables in $OCSP_OBJ for the generated objects are set
* @deprecated since pk-08-06-18
/** ---------------------------------------------------------------------------------------------------------
* getter & setter methods
* ---------------------------------------------------------------------------------------------------------
* returns the title or the name if no title is set
* if $this->getId() == 0 Default is returned
* @version pk-06-10-25 E_ALL
if (!intval($this->getId())) { // <pk-06-07-23> asume we have the default project
* returns the project name
* despite the object vals the column PROJ_VARS holds variables
* only used in the current project in a text field each variable is in one line like name=value
* returns the value of a project var or NULL if the variable is not set
* @param string $varName name of the variable
$s_vars=
str_replace("\r","",$s_vars); // remove linefeed
if ($a_vars=
explode("\n",$s_vars)) {
foreach($a_vars as $s_varLine) {
$a_varDef=
explode("=",$s_varLine,2); // <pk-06-08-04 /> bugfix
if ($debug) echo
"<pre>Line: ".
print_r($a_varDef,True).
"</pre>";
if ($a_varDef[0]==
$varName) {
if ($debug) echo
"<p>PROJ_VARS NOT SET</p>";
* returns the image rootPath
if (is_dir($_SERVER['DOCUMENT_ROOT'].
"/".
$s_rd)) {
return $_SERVER['DOCUMENT_ROOT'].
"/".
$s_rd;
* returns the language string
* @global array $OCSP_CONF
if (isset
($OCSP_CONF['OCSP_CMSLANG'][$lang][$txt]))
return $OCSP_CONF['OCSP_CMSLANG'][$lang][$txt];
* returns the default template id
* returns if the project is the current project
* NOTE only ID's are compared
* sets the project as current project in CMS_TABLEOBJ
// ############################################################################
// ############################################################################
* tries to find out the project id from the environment
* @param boolean $checkSession
* @deprecated since pk-08-06-18
if ($debug) echo
"<p><b>CMS_PROJECT::getProjIdFromEnv()</b> (".
get_class($this).
")</p>";
// we have a PROJ_ID in the querystring
if ($debug) echo
"<blockquote>ID from querystring</blockquote>";
// do we have to check session?
// NOTE session need be started before
if ($debug) echo
"<blockquote>ID from session</blockquote>";
// is project id set in http conf?
if (isset
($_SERVER['PROJ_ID']) &&
intval($_SERVER['PROJ_ID'])) {
if ($debug) echo
"<blockquote>ID from _SERVER</blockquote>";
return intval($_SERVER['PROJ_ID']);
// <pk-06-07-28> check if we already have one set so we use this
die("no database connection");
// no project found try to find out from _SERVER["HTTP_HOST"]
$s_query.=
" WHERE UPPER(PROJ_URL)=".
$this->myDBObj->qs_getSlashedValue(strtoupper($_SERVER['HTTP_HOST']));
if ($debug) echo
"<p>Searching Server: <br />".
$s_query.
"</p>";
if ($i_Id=
$this->myDBObj->quickQuery($s_query,0)) {
if ($debug) echo
"<blockquote>ID from HTTP_HOST</blockquote>";
// ok let's go into deep and check
$s_query =
"SELECT * FROM ".
$this->myTable;
$s_query.=
" WHERE PROJ_SHOW > 0";
$s_query.=
" ORDER BY PROJ_ISDEFAULT DESC, PROJ_SORTORDER" ;
if ($debug) echo
"<blockquote><p>Checking Regular Expressions</p>\n";
if ($o_Cursor=
$this->myDBObj->query($s_query)) {
while($a_dbRow =
$o_Cursor->fetchArrayFld()) {
if (empty($a_firstProj)) $a_firstProj=
$a_dbRow; // cache first result to use if
// if we do not find a proper regex
if (!empty($a_dbRow['PROJ_URLREGEX'])) {
if ($debug) echo
"<p>Checking Projekt: ".
$a_dbRow['PROJ_NAME'].
" (ID: ".
$a_dbRow['PROJ_ID'].
")</p><ul>";
// we have regular expressions to check
foreach($a_regExpNames as $s_pattern) {
$s_pattern=
trim($s_pattern);
if (!empty($s_pattern)) { // skip empty lines
if ($debug) echo
"<li>Pattern: $s_pattern<li>";
if (@preg_match($s_pattern,$_SERVER['SERVER_NAME'])) { // <pk-06-01-05 /> @ added
if ($debug) echo
"</ul><p>MATCHES</p></blockquote>";
$o_Cursor->free(); // as we don't know if we are at the last row
// <<<<<<<<<<<<<<< return point ----------------------------------------------------------
// no project found try to find out from _SERVER['SERVER_NAME']
$s_query.=
" WHERE UPPER(PROJ_URL)=".
$this->myDBObj->qs_getSlashedValue(strtoupper($_SERVER['SERVER_NAME']));
if ($debug) echo
"<p>Searching Server: <br />".
$s_query.
"</p>";
if ($i_Id=
$this->myDBObj->quickQuery($s_query,0)) {
if ($debug) echo
"<blockquote>ID from SERVER_NAME</blockquote>";
// fall back to session if set as we could not determine the
* tries to populate the project form the environment
* returns true if a page to show was found
* @param boolean $checkSession
* @version pk-07-06-07 session handling
* @deprecated since pk-08-06-18
if (!isset
($OCSP_OBJ['SESSION']))
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/OCSP_SESSION.phpclass";
// first check if we have a page
if ($this->setCurrentPage(intval($_GET[$this->myPageIdGetName]),False,True,$debug)) { // ($pagId,$setMenu,$setProj)
if ($debug) echoDebug("<p><b>PageFound</b></p>");
// secound check if we have a menu
if ($debug) echoDebug("<p><b>MenuFound</b></p>");
// third check the session
* gets the sortnumber from the database and
* calls the parent method
$this->setDBField($str_sortCol,intval($this->myDBObj->quickQuery("SELECT MAX($str_sortCol) FROM T_CMS_PROJECT",0))+
1);
return parent::dbInsert($debug);
* replaces the db values and clears cache
* @param boolean $ignorPopulated (if false the table MUST have been populated)
function dbReplace($debug=
False,$ignorPopulated=
False)
if (parent::dbReplace($debug,$ignorPopulated))
// ######################################################################################################
// ######################################################################################################
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the menu tree from curMenuNode
* @param boolean $asPopulated (populates the keys)
* @version pk-07-06-15 (caching)
function &getMenuTree($asPopulated=
False,$debug=
False) {
} else if ($asPopulated) {
if (!$this->myMenuTree->isPopulated())
$this->myMenuTree->populateTree(True,True,"",$debug);
$this->myMenuTree->setMyProject($this);
return $this->myMenuTree;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// menu nodes (CMS_MENU_NODE)
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the current menu
* @param boolean $checkPage (a menu node with an online page for the user is returned)
* @version pk-08-10-05 use CMS_TABLEOBJ::get_current*
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning already set object");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning menu from already set page object");
$bol_setAsCurrent =
False;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning current menu Obj");
$bol_setAsCurrent =
True;
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning menu from current page Obj");
if ($debug) echoDebugMethod(__FILE__
,__LINE__
,"returning the menu of myPageObj");
return $this->myPageObj->getMyMenuNode($debug);
if ($debug) ocsp_logError(__FILE__
,__LINE__
,"current menu not set",E_NOTICE);
* returns a new menu node overwrite this in child classes as needed
* @param mixed $values (array) dbval or (int) menId
* @version pk-07-08-15 param values type mixed
* @requires CMS_MENU_NODE.phpclass
* @todo CMS_PROJECT::newMenuNode() setTitle() for 0 german of Root is set
if ($debug) echo
("<blockquote style=\"font-size: 80%\">");
if ($debug) echo
("</blockquote>");
if (is_array($values) && isset
($values['MEN_ID']))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"value array submitted");
if (!($obj_Node=
$this->myMenuTree->getNodeObjectFromCache($values['MEN_ID'],$debug)))
$obj_Node=
$this->myMenuTree->newNodeObject($values['MEN_ID'],$values,$debug);
} else if ($i_id=
intval($values)) {
if (!($obj_Node=
$this->myMenuTree->getNodeObjectFromCache($i_id,$debug)))
$obj_Node=
$this->myMenuTree->populateNode($i_id,False,$debug);
$obj_Node->setTitle("Wurzel");
$obj_Node->setMyProject($this,$debug);
ocsp_logError(__FILE__
,__LINE__
,"could not get menu tree",E_ERROR);
// ######################################################################################################
// ######################################################################################################
* returns the current page
* @requires CMS_PAGE.phpclass
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning object var \$this->myPageObj");
if (is_object(self::$currentPage) &&
method_exists(self::$currentPage,'getProjId'))
if (self::$currentPage->getProjId() ==
$this->getId())
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning class var self::\$currentPage");
return self::$currentPage;
require_once __OCSP_CMS_PHPINCPATH__.
"page/CMS_PAGE_V2.phpclass";
if ($this->myPageObj=
$this->myMenuNode->getCurrentPage(True,True,NULL,$debug)) // goDown,online,xtraCondition
ocsp_logError(__FILE__
,__LINE__
,"could not find any page",E_ERROR);
* returns the page template Id for the subpages
$str_query =
"SELECT PTMP_ID FROM T_CMS_TMPL_PAGE";
$str_query.=
" WHERE PROJ_ID IN(0," .
$this->getId() .
")";
$str_query.=
" ORDER BY PTMP_ISDEFAULT DESC,PROJ_ID DESC";
return $this->myDBObj->getOne($str_query);
// ######################################################################################################
// LAYOUT / OUTPUT METHODS
// ######################################################################################################
// ____________________________________________
* returns the include file for the page
* @param boolean $debug since pk-06-11-23
if ($debug) echo
"<p>PROJ_INDEXPHPINC: ".
$s_incFile.
"</p>";
if (!empty($s_incFile)) {
if ($debug) echoDebug(__FILE__
,"<p>Returning: \OCSP_OBJ::getConf('PROJECTPATH') $s_incFile</p>");
if ($debug) echoDebug(__FILE__
,"<p>Returning ['PROJECT']['TEMPLPATH']: $s_incFile</p>");
echoDebugLine(__FILE__
,__LINE__
,"NO page include found<pre>OCSP_CONF: ".
print_r($OCSP_CONF,True).
"</pre>");
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the html code for the css style section in the header
* if $media is not empty the styles are filter by this media
* the return value is treatend as template and parsed with $this->getDBVal() values
* @param boolean $projectOnly
* @param boolean $asTemplate if True the return value is not parsed
* @requires __OCSP_CMS_PHPINCPATH__."css/CMS_CSSSTYLE.phpclass";
function getCSS_definition($media=
"",$projectOnly=
False,$asTemplate=
False,$debug=
False) {
$s_query=
"SELECT * FROM T_CMS_CSSSTYLES WHERE (PROJ_ID=".
$this->getId();
$s_query.=
" OR PROJ_ID=0";
$s_query.=
") AND STY_ALWAYSUSE=1";
$s_query.=
" ORDER BY PROJ_ID,STY_SORTORDER,STY_ID";
if ($debug) echo
"<p style=\"padding-left:30px\">Query: ".
$s_query.
"</p>";
if ($o_styCursor=
$this->myDBObj->query($s_query)) {
$s_ret=
"<style type=\"text/css\">\n<!--\n";
$s_ret.
"/* CMS_PROJECT::getCSS_definition(media: $media,projectOnly: ".
($projectOnly ?
"True" :
"False").
") */\n";
while($a_sty=
$o_styCursor->fetchArrayFld()) {
if ($debug) echo
"<p style=\"padding-left:45px;font-size:90%\">adding style: ".
$a_sty['STY_NAME'].
"(".
$a_sty['STY_ID'].
")</p>\n";
$o_style->setDBRow($a_sty);
$s_ret.=
$o_style->getCSSCode($media,($projectOnly ?
$this->getId() : -
1),$debug);
if (!empty($a_sty['STY_JAVACODE'])) {
$s_ret.=
"/* __STY_JAVACODE__START__ */\n";
$s_ret.=
"-->\n</style>\n";
$s_ret.=
"<script language=\"javascript\" type=\"text/javascript\">\n<!--\n";
$s_ret.=
$a_sty['STY_JAVACODE'];
$s_ret.=
"\n//-->\n</script>\n";
$s_ret.=
"<!-- __STY_JAVACODE__END__ -->\n";
$s_ret.=
"<style type=\"text/css\">\n<!--\n";
} // while($a_sty=$o_styCursor->fetchArrayFld())
$s_ret.=
"-->\n</style>\n\n";
$s_ret.=
"\n <!-- /* DONE CMS_PROJECT::getCSS_definition */ --> \n";
$s_ret=
"\n<!-- \n/* CMS_PROJECT::getCSS_definition() could not select any styles */\n-->\n";
$s_ret.=
"<!--\n___START___PROJ_CSSINCLUDE___ (CMS_PROJECT::PROJ_CSSINCLUDE)\n-->\n";
$s_ret.=
$this->getDBField("PROJ_CSSINCLUDE").
"\n";
$s_ret.=
"\n<!--\n___END___PROJ_CSSINCLUDE___\n-->\n";
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/pcf_templates.phpinc";
* returns the an array with css formatings
* @param OCSP_CMS_HTMLPAGE $htmlPage
* @requires __OCSP_CMS_PHPINCPATH__."css/CMS_CSSSTYLE.phpclass";
$s_query=
"SELECT * FROM T_CMS_CSSSTYLES WHERE (PROJ_ID=".
$this->getId().
" OR PROJ_ID=0) AND STY_ALWAYSUSE=1";
$s_query.=
" ORDER BY PROJ_ID,STY_SORTORDER,STY_ID";
if ($o_styCursor=
$this->myDBObj->query($s_query)) {
while($arr_row=
$o_styCursor->fetchArrayFld())
$obj_style->setDBObj($this->myDBObj);
$obj_style->setDBRow($arr_row,True);
$arr_Styles[$obj_style->getId()]=
array(
'INC_LINK' =>
$obj_style->getIncludeFile(),
'INC_JS' =>
$obj_style->getJSCode(),
'CSS_TXT' =>
$arr_row['STY_TXT'],
'CSS_ARR' =>
$obj_style->getCssClassArray()
foreach($arr_Styles as $int_Id =>
$arr_sty)
if ($int_Id !=
'PEARCACHE_TS')
if (!empty($arr_sty['INC_LINK']))
$htmlPage->addCssSrcLink("<!-- STY_ID: ".
$int_Id.
" -->\n".
$arr_sty['INC_LINK']);
$htmlPage->addCssCode("/* ------------------------------------------------ \n\tSTY_ID: $int_Id\n ----- */");
if (!empty($arr_sty['CSS_TXT']))
$htmlPage->addCssCode($arr_sty['CSS_TXT']);
foreach($arr_sty['CSS_ARR'] as $arr_css)
$htmlPage->addCssCode($arr_css['CSS_NAME'].
" {".
$arr_css['CSS_DEFINITION'].
"}");
if (!empty($arr_sty['INC_JS']))
$htmlPage->addJsCode($arr_sty['INC_JS']);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the real group id for:
* _OCSP_GROUP_PROJ_ADMINGRP_ = -80;
* _OCSP_GROUP_PROJ_EDITOR_GRP_ = -81;
* _OCSP_GROUP_PROJ_AUTHOR_GRP_ = -82;
* _OCSP_GROUP_PROJ_USER_GRP_ = -83;
return (intval($i_admGrp) ?
intval($i_admGrp) :
$GLOBALS['GROUPS']['CMSADMIN']);
* returns if the current user is member of the project group
* _OCSP_GROUP_PROJ_ADMINGRP_ = -80;
* _OCSP_GROUP_PROJ_EDITOR_GRP_ = -81;
* _OCSP_GROUP_PROJ_AUTHOR_GRP_ = -82;
* _OCSP_GROUP_PROJ_USER_GRP_ = -83;
* @param boolean $strict only check the group do not check higher rights
* returns if the current user is an administrator of the project
* @global array $OCSP_OBJ
if ($debug) echo
"<p><b>CMS_PROJECT::curUserIsAdmin()</b> (".
get_class($this).
")</p>\n";
* returns if the current user is an editor of the project
* @global array $OCSP_OBJ
if ($debug) echo
"<p><b>CMS_PROJECT::curUserIsEditor()</b> (".
get_class($this).
")</p>\n";
* returns if the current user is an author of the project
* @global array $OCSP_OBJ
if ($debug) echo
"<p><b>CMS_PROJECT::curUserIsAuthor()</b> (".
get_class($this).
")</p>\n";
if ($debug) echo
"<p>checking group (".
$this->colPrevix.
"AUTHOR_GRP) ID: ".
$authorGrp.
"</p>";
// check if the user is member of a group with heigher rights:
* returns if the current user can open the project
* @version pk-06-11-10 PROJ_ -> $this->colPrevix
* returns if the current user can delete the project
/** ---------------------------------------------------------------------------------------------------------
* ---------------------------------------------------------------------------------------------------------
* tries to load the project form the cache
* if failed $this->dbPopulate() is called
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"cache is disabled");
Documentation generated on Thu, 08 Jan 2009 17:39:59 +0100 by phpDocumentor 1.4.0a2