Source for file CMS_CHAPTER_V2.phpclass
Documentation is available at CMS_CHAPTER_V2.phpclass
* Class file CMS_CHAPTER_V2.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_CHAPTER_V2.phpclass,v 1.11 2008/08/11 08:37:38 pitlinz Exp $
require_once __OCSP_DEFAULTCONFPATH__."cms.conf.phpinc";
require_once __OCSP_CMS_PHPINCPATH__."template/chapter/TMPL_CHAPTER_V3.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_CHAPTER_V2.phpclass,v 1.11 2008/08/11 08:37:38 pitlinz Exp $
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
* @constant string CLASS_SRC_FILE
* @staticvar string $moduleKey
* @staticvar string $mytmplCol the column name for the page template foreign key
* @staticvar string $myPageTmplCol the column name for the page template foreign key
* @staticvar string $myTmplClass
* make sure the class file is included if you overwrite this
* @staticvar string $colPrevix the column name for the chapter columns
* @staticvar int $mySrcVersion
* @var string $classSrcFile source file of the class
* returns a the chapter object for chapter ID: $aId
if ($debug) echoDebugMethod(__FILE__
,"static","CMS_CHAPTER_V2::factoryFromId()");
$obj_ret->dbPopulate($debug);
* @param boolean $autoPopulate
* returns a the chapter object for chapter ID: $aId
* returns the class name of the object to store in the db
* overwrite in child classes
// ####################################################################
// ####################################################################
* merges {$this->colPrevix."FIELDS"} with Object values
* @return int sizeof myObjVals
if ($debug) echo
"<hr><p><b>CMS_CHAPTER_V2::populateObjVals()</b> (".
get_class($this).
")</p>";
parent::populateObjVals($debug);
if (!empty($this->{$this->colPrevix.
"FIELDS"})) {
// we have an old version where object values are stored
// serialized in column {$this->colPrevix."FIELDS"}
$a_fldArr=
@unserialize($this->{$this->colPrevix.
"FIELDS"});
foreach($a_fldArr as $s_key =>
$m_val) {
* inserts a new row to the table
* @param string $gDBIDX Index of $GLOBALS to the db object
* @param bool $debug show debug info
* @return int returns the autoIncFld ID if exists or 1 on success
$s_Query =
"SELECT MAX(IFNULL(".
$this->colPrevix.
"SORTORDER,0)) ";
$this->{$this->colPrevix.
"SORTORDER"}=
intval($GLOBALS[$gDBIDX]->quickQuery($s_Query,0)) +
1;
$this->setDBField('CHA_CREATE_AT','CURRENT_TIMESTAMP');
* replaces a row in the table
* if the object has not been populated (!$this->populateTS)
* @param bool $debug show debug info
* @param boolean $ignorPopulated (if false the table MUST have been populated)
function dbReplace($debug=
FALSE,$ignorPopulated=
FALSE) {
$this->setDBField('CHA_LASTCHANGE_AT','CURRENT_TIMESTAMP');
return parent::dbReplace($debug,$ignorPopulated);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* sets the templateobject;
* @param TMPL_CHAPTER $chatmpl;
* sets the TemplateObject by ID
* @var TMPL_CHAPTER_V3 $o_tmpl
if ($debug) echo
"<p><b>CMS_CHAPTER_V2::setTemplateObjId($chaTmplId)</b> (".
get_class($this).
")</p>\n";
if (!intval($chaTmplId)) return FALSE;
// nothing to do we already have the template loaded
if ($debug) echo
"<p>creating object: <br >\n\t".
$s_cmd.
"</p>\n";
* return the page template ID
echo
"<p><b>CMS_CHAPTER_V2::getPageTmplId()</b> (".
get_class($this).
")</b>\n";
* sets page filds used to identify the object
* @param CMS_PAGE $pagObj
$this->setArray($pagObj->getDBVAL(),FALSE,TRUE,$debug);
* returns a chapter input form not a database form
* as we have chapter fields not represented in the
* returns the form from the template
function &dbGetForm($mode=
0,$frmName=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>CMS_CHAPTER_V2::dbGetForm(MODE: $mode,FORM: $frmName,...)</b> (".
get_class($this).
")</p>\n";
$frmObj=
parent::dbGetForm($mode,$frmName,$debug);
if ($frmObj=
$this->myTemplate->getChapterForm($frmName,$debug)) {
$frmObj->myDBMS_TABLEOBJ_class =
get_class($this);
$frmObj->hideField('NLTP_ID');
$frmObj->hideField('PTMP_ID');
$frmObj->hideField($this->colPrevix.
"FIELDS");
$frmObj=
parent::dbGetForm($mode,$frmName,$debug);
if ((is_object($frmObj)) &&
(!empty($s_showModes))) {
require_once $GLOBALS['OCSP']['DBMSFLD_PATH'].
"DBMS_FIELD_DBLOOKUPSELECTLIST.phpclass";
$o_fld=
&$frmObj->getField("CHA_SHOWMODE",$this->myTable,$debug);
$o_fld->lookupTable =
"T_LOOKUP_CHA_SHOWMODE";
$o_fld->lookupShowField =
"CONCAT(LUP_VALUE,' (',LUP_KEY,')')";
$o_fld->lookupField =
"LUP_KEY";
$o_fld->lookupWhere =
"LUP_KEY IN (".
$s_showModes.
")";
* calls this::setFORMPOST() with this::dbGetForm() formular
* @param string $arrName name of the post array
* @param bool $debug show debug info
if ($debug) echo
"<hr><p><b>CMS_CHAPTER_V2::setPOSTVAL($frmObj,$dbval,$debug)</b> (".
get_class($this).
")</p>";
if (empty($arrName)) $arrName=
$_POST['FRMARRAYNAME'];
$_POST[$arrName][$this->myTemplate->getPTMPColName()]=
$this->myTemplate->getPTMPId(); // if not submitted
$_POST[$arrName][$this->myTemplate->getPTMPColName()]=
$this->myTemplate->getPTMPId(); // if not submitted
* sets post array with form checks
* @param DBMS_FORM $frmObj a formObj as ref
* @param array $dbVal array with data
* @globalvar array $DBVAL
function setFORMPOST(&$frmObj,$dbval,$debug=
FALSE,$frmMode=
0) {
if ($debug) echo
"<hr><p><b>CMS_CHAPTER_V2::setFORMPOST(\$frmObj,$dbval,$debug)</b> (".
get_class($this).
")</p><blockquote>";
$frmObj=
$this->dbGetForm($frmMode,"",$debug);
$frmObj=
$this->dbGetForm($frmMode,"",$debug);
if ($debug) echo
"</blockquote>";
if (parent::setFORMPOST($frmObj,$dbval,$debug)) { // <pk-05-08-30>
$a_chapFlds=
$frmObj->getValueArray($dbval,"CHAPTER",$arrName,$debug);
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
* moves the chapter up (decrease sortorder)
* note autosaves sortorder
if ($debug) echo
"<p><b>CMS_CHAPTER_V2::sort_MoveUp()</b> (".
get_class($this).
")</p>";
$s_Query =
"SELECT ".
$this->colPrevix.
"ID AS IDCOL, ".
$this->colPrevix.
"SORTORDER AS ORDERCOL";
$s_Query.=
" FROM ".
$this->myTable;
$s_Query.=
" ORDER BY ".
$this->colPrevix.
"SORTORDER DESC";
if ($debug) echo
"<p>".
$s_Query.
"</p>";
if ($a_Row=
$this->myDBObj->quickQuery($s_Query)) {
// get only the first row
if ($debug) echo
"<p>".
$s_Query.
"</p>";
$this->myDBObj->executeCmd($s_Query);
$s_Query.=
" WHERE ".
$this->colPrevix.
"ID = ".
$a_Row['IDCOL'];
if ($debug) echo
"<p>".
$s_Query.
"</p>";
$this->myDBObj->executeCmd($s_Query);
* moves the chapter down (increase sortorder)
* note: autosaves sortorder
if ($debug) echo
"<p><b>CMS_CHAPTER_V2::sort_MoveDown()</b> (".
get_class($this).
")</p>";
$s_Query =
"SELECT ".
$this->colPrevix.
"ID AS IDCOL, ".
$this->colPrevix.
"SORTORDER AS ORDERCOL";
$s_Query.=
" FROM ".
$this->myTable;
$s_Query.=
" ORDER BY ".
$this->colPrevix.
"SORTORDER";
if ($debug) echo
"<p>".
$s_Query.
"</p>";
if ($a_Row=
$this->myDBObj->quickQuery($s_Query)) {
// get only the first row
if ($debug) echo
"<p>".
$s_Query.
"</p>";
$this->myDBObj->executeCmd($s_Query);
$s_Query.=
" WHERE ".
$this->colPrevix.
"ID = ".
$a_Row['IDCOL'];
if ($debug) echo
"<p>".
$s_Query.
"</p>";
$this->myDBObj->executeCmd($s_Query);
* moves the chapter to a position
* note: autosaves sortorder
* if $postion > last postion
* the object will be moved to the end
* @var DBMS_CURSOR $o_Cursor
if ($debug) echo
"<p><b>CMS_CHAPTER_V2::sort_MoveToPos($position)</b> (".
get_class($this).
")</p>\n";
if (!intval($position)) return FALSE; // error illegal position
$s_Query =
"SELECT ".
$this->colPrevix.
"ID AS IDCOL, ".
$this->colPrevix.
"SORTORDER AS ORDERCOL";
$s_Query.=
" FROM ".
$this->myTable;
$s_Query.=
" AND ".
$this->colPrevix.
"ID <> ".
$this->getId(); // without me
$s_Query.=
" ORDER BY ".
$this->colPrevix.
"SORTORDER";
if ($o_Cursor=
$this->myDBObj->query($s_Query)) {
while($a_Row =
$o_Cursor->fetchArrayFld()) {
if ($i_ordNr ==
$position) {
$this->{$this->colPrevix.
"SORTORDER"}=
$position;
if (intval($a_Row['ORDERCOL']) !=
$i_ordNr) {
$s_Query =
"UPDATE ".
$this->myTable.
" SET ".
$this->colPrevix.
"SORTORDER=".
$i_ordNr;
$s_Query.=
" WHERE ".
$this->colPrevix.
"ID = ".
$a_Row['IDCOL'];
if ($debug) echo
"<p>".
$s_Query.
"</p>";
$this->myDBObj->executeCmd($s_Query);
$this->{$this->colPrevix.
"SORTORDER"}=
$i_ordNr;
// finaly save my own order position to the database
if ($debug) echo
"<p>".
$s_Query.
"</p>";
$this->myDBObj->executeCmd($s_Query);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// states and checks methods
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* checks if the user can edit the chapter
* @todo CMS_CHAPTER_V2::userCan() state check, showgroup check
function userCan($mode,$debug=
FALSE) {
return $this->myPageObj->curUserCanOpen($debug);
return $this->myPageObj->curUserCanInsert($debug);
* sets the state and checks if the user is allow to do this
* @param boolean $autoSave
* @global array $OCSP_OBJ
function setState($aState=
0,$autoSave=
FALSE,$debug=
FALSE) {
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"user not allowed to edit page");
if (isset
($GLOBALS['OCSP_CMS']['CHAPTERSTATE'][intval($aState)]))
if (!($OCSP_OBJ['USER']->isGroupMember($GLOBALS['OCSP_CMS']['CHAPTERSTATE'][intval($aState)]['GROUP'])))
ocsp_logError(__FILE__
,__LINE__
,"state $aState not defined",E_NOTICE);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* return the data array to use in the template
* @param boolean $fromFld
if ($debug) echo
"<p><b>CMS_CHAPTER_V2::getTemplateData(...)</b> (".
get_class($this).
")</p>";
$a_fldLst=
$this->myTemplate->getFieldList($debug,FALSE); // ($debug=FALSE,$autoSave=TRUE)
$s_arrName=
$this->getDBVAL();
foreach($a_fldLst as $fldObj) {
* returns the parsed chapter
* if $tmplVals is an array the return
* value is paresed with this
* -> you can use templates within the chapter value
* @param array $tmpldataArr
* @param char $tmplVarSign
* @param boolean $wysiwygPreView
function getTag($tmplVals=
NULL,$tmplVarSign=
'$',$wysiwygPreView=
FALSE,$debug=
FALSE) {
if ($debug) echo
"<p><b>CMS_CHAPTER_V2::getTag(...)</b> (".
get_class($this).
")</p>";
// <pk-06-10-02 /> bugfix with $tmplVals
$a_Vals=
array_merge($a_Vals,$this->getDBVAL(FALSE,FALSE,TRUE));
if ($debug) echo
"<pre style=\"font-size:80%;background-color: #C0C0C0; border: solid 1px blue;\">".
print_r($a_Vals,TRUE).
"</pre>";
$s_ret.=
$this->myTemplate->getTag($this->getDBVAL(FALSE,$debug,TRUE),"HTMLCODE",$debug,$wysiwygPreView);
Documentation generated on Thu, 08 Jan 2009 17:38:43 +0100 by phpDocumentor 1.4.0a2