Source for file TMPL_CHAPTER.phpclass
Documentation is available at TMPL_CHAPTER.phpclass
* Class file TMPL_CHAPTER.phpclass
* @project Open CSP-Management
* @category templates-chapter
* @author Peter Krebs <p.krebs@lvus.at>
* @copyright (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
require_once $GLOBALS['OCSP']['DEFAULTCONFPATH'].
"cms.conf.phpinc";
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/pcf.phpinc";
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/pcf_templates.phpinc";
require_once $GLOBALS['OCSP']['PHPFORMPATH'].
"forms.phpinc";
require_once $GLOBALS['OCSP_CMS']['PHPINCPATH'].
"cms_tableobj.phpclass"; // <pk-06-11-09/> CMS -> OCSP_CMS
* Handels chapter templates
* @project Open CSP-Management
* @category templates-chapter
* @author Peter Krebs <p.krebs@lvus.at>
* @copyright (c) 2002-2003 by Peter Krebs and Landesverlag Unternehmensservice
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @staticvar string $myTable
* @staticvar string $ptmplFld the column name for the page template foreign key
* @staticvar string $colPrevix the column name for the chapter columns
* @staticvar string $contTable the table holding the content
* @var array $tmplFields db columns with template code to extract
* @var array $inputFields array of DBMS_FIELD objects for the input form
* @var string $myFrmFldTableName (table name set in dbms_formfields)
* @var string $classSrcFile source file of the class
* @var array $myFldValTypes array of allowed db types
var $myFldValTypes=
array('string'=>
'String','int'=>
'Integer','float'=>
'Number','blob'=>
'Text');
* creates and inits and populates if all keys are set the object
* @param int $projId ID of the project - db foreign key
* @param int $ptmpId ID of the Page Template - db foreign key
* @param int $aId ID of the db COLUMN
* @param bool $issep is the chapter a layout element with no input
* @param int $langId language Id
function TMPL_CHAPTER($projId=
0,$ptmpId=
0,$aId=
0,$issep=
FALSE,$langId=
0,$gDBIDX=
"USRDB") {
if ($GLOBALS['DEBUGMODE']) echo
"<p><b>TMPL_CHAPTER::TMPL_CHAPTER($projId,$ptmpId,$aId,$issep,$langId,$gDBIDX)</b>(".
get_class($this).
")</p>";
$this->dbPopulateDB($this->gDBIDX,$GLOBALS['DEBUGMODE']);
* returns the db ID-column value
* sets the db ID-column value
* returns the page template id
* sets the page template id
* returns a database form and hides some system fields
function &dbGetForm($mode,$frmName=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>TMPL_CHAPTER::dbGetForm($mode,$frmName,...)</b> (".
get_class($this).
")</p>";
if ($frmObj=
parent::dbGetForm($mode,$frmName,$debug)) {
$frmObj->hideField($this->colPrevix.
"FIELDS");
$frmObj->hideField($this->colPrevix.
"FIELDSV2");
$frmObj->hideField($this->colPrevix.
"FIELDCLASSES");
* sets the objects field data vars FIELD,FIELDCLASSES
if ($debug) echo
"<p><b>TMPL_CHAPTER::setDBFieldDataCols()</b> (".
get_class($this).
")</p><blockquote><div style=\"font-size:75%;line-height 1em;background-color: #c0c0c0;\">";
$this->p_extractFields(FALSE,$debug); // check if all fields defined in the
// template(s) are in $this->inputFields
$fldClasses=
array(); // generate imploded field class list
foreach($fldClasses as $key =>
$count) $this->{$this->colPrevix.
"FIELDCLASSES"}.=
$key.
";";
if ($debug) echo
"</div></blockquote>";
* sets a database row to the object fields
* and extract fields from
* sets each key (=columname) value
* @param array $row the row form a select * from DBMS_TABLEOBJ::myTable
* @param bool $asPopulated set populateTS as if the object has been populated
function setDBRow($row,$asPopulated=
TRUE,$debug=
FALSE) {
if ($debug) echo
"<p><b>TMPL_CHAPTER::setDBRow($row,$asPopulated,$debug)</b> (".
get_class($this).
")</p><blockquote>";
parent::setDBrow($row,$asPopulated,$debug);
if (!empty($row[$this->colPrevix.
"FIELDCLASSES"])) {
// we have table version > 16 with field classes -> ensure the class source is loaded
foreach($fldClasses as $fldClass) {
$this->setDBFieldDataCols($debug); // make sure db column values are a repesentation of the row
if ($debug) echo
"</blockquote><hr>";
* sets the object field from $_POST[$arrName] and extracts fields
* note populates the template first to get all fields.
* @param string $arrName name of the post array
* @param bool $debug show debug info
* @version pk-03-12-14 as DBMS_TBLOBJ::setPOSTVAL() calls setDBRow no more need to overwrite
function setPOSTVAL($arrName=
"DBVAL",$debug=
FALSE) {
echo
"<hr><blockquote><p><b>TMPL_CHAPTER::setPOSTVAL($arrName,$debug)</b> (".
get_class($this).
")</p>";
echo
"<pre>";print_r($_POST[$arrName]);echo
"</pre>";
// $this->populateTS=time();
parent::setPOSTVAL($arrName,$debug);
if ($debug) echo
"</blockquote>";
* saves the object to the database
* if getId() dbReplace is called
* else dbInsert is called
* @param string $gDBIDX Index of $GLOBALS to the db object
* @param bool $debug show debug info
function dbSave($gDBIDX=
"USRDB",$debug=
FALSE) {
if ($debug) echo
"<hr><p><b>TMPL_CHAPTER::dbSave($gDBIDX,$debug)</b></p>";
if (!is_object($GLOBALS[$gDBIDX])) $gDBIDX=
"USRDB"; // old usage without params
* inserts a new row to the table
* we have to serialize the inputFields before saving
* @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
function dbInsert($gDBIDX=
"USRDB",$debug=
FALSE) {
if ($debug) echo
"<hr><p><b>TMPL_CHAPTER::dbInsert($gDBIDX,$debug)</b></p>";
$this->setDBFieldDataCols($debug); // make sure db column values are a repesentation of the object
return parent::dbInsert($gDBIDX,$debug);
* replaces a row in the table
* serialize $this->inputFields and calls parent::dbReplace()
* @param string $gDBIDX Index of $GLOBALS to the db object
* @param bool $debug show debug info
function dbReplace($gDBIDX=
"USRDB",$debug=
FALSE) {
if ($debug) echo
"<hr><p><b>TMPL_CHAPTER::dbReplace($gDBIDX,$debug)</b></p>";
$this->setDBFieldDataCols($debug); // make sure db column values are a repesentation of the object
return parent::dbReplace($gDBIDX,$debug);
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* returns the table head row for the fieldlist
if ($debug) echo
"<p><b>DBMS_fldLstHeader(...)</b> (".__FILE__.
")</p>";
<th align=\"center\">#</th>
<th align=\"center\">Field</th>
<th align=\"center\">Label</th>
<th align=\"center\">Input-Type</th>
<th align=\"center\">ShowClass</th>
<th colspan=\"6\"> </th>
* returns the htmlcode for a field row in the fieldlist
* @param DBMS_FIELD $fld the field object
* @param string $editUrl link to the field editor
* @param string $tdStyle column stylesheet (add ; at the end)
function fldLstRow(&$fld,$editUrl=
"",$funcUrl=
"",$tdStyle=
"",$debug=
FALSE) {
if ($debug) echo
"<p><b>DBMS_fldLstRow(...)</b> (".__FILE__.
")</p>";
if (empty($editUrl)) $editUrl=
$_SERVER['REQUEST_URI'];
$editUrl=
str_replace("&TMPLFIELD=".
$_GET['TMPLFIELD'],"",$editUrl);
$editUrl=
str_replace("&TMPLFLDCMD=".
$_GET['TMPLFLDCMD'],"",$editUrl);
$editUrl=
str_replace("&NEWTYPE=".
$_GET['NEWTYPE'],"",$editUrl);
$editUrl.=
"&TMPLFIELD=".
$fld->myName.
"&TMPLFLDCMD=EDIT";
$eLink=
"<a href=\"".
$editUrl.
"&FIELD=".
$fld->myName.
"\">";
if (empty($funcUrl)) $funcUrl=
$_SERVER['REQUEST_URI'];
$funcUrl=
str_replace("&TMPLFIELD=".
$_GET['TMPLFIELD'],"",$funcUrl);
$funcUrl=
str_replace("&TMPLFLDCMD=".
$_GET['TMPLFLDCMD'],"",$funcUrl);
$funcUrl=
str_replace("&NEWTYPE=".
$_GET['NEWTYPE'],"",$funcUrl);
$funcUrl.=
"&TMPLFIELD=".
$fld->myName;
if ($fld->isHidden) $tdstyle.=
"background: #c0c0c0;";
if ((!$fld->enableNew) &&
(!$fld->enableEdit)) $tdstyle.=
"color: #FF0000;";
else if (!$fld->enableNew) $tdstyle.=
"color: #FFFF00;";
else if (!$fld->enableEdit) $tdstyle.=
"color: #FF00FF;";
$style=
"style=\"".
$tdstyle.
"\"";
$ret.=
"\t<td $style>$eLink".
$fld->sortOrder.
"</a></td>\n";
$ret.=
"\t<td $style>$eLink".
$fld->myName.
"</a></td>\n";
$ret.=
"\t<td $style>$eLink".
$fld->label.
"</a></td>\n";
$ret.=
"\t<td $style><select name=\"ChangeType\" onChange=\"";
$ret.=
"if (confirm('Change Class To: '+this.options[this.selectedIndex].value)) { ";
$ret.=
" editLoc='".
$funcUrl.
"&TMPLFLDCMD=CHANGETYPE';";
$ret.=
" editLoc=editLoc+'&NEWTYPE='+this.options[this.selectedIndex].value;";
$ret.=
" document.location.href=editLoc;";
$ret.=
"\t\t<option value=\"".
$type.
"\" ";
if ($fld->dbDesc['TYPE']==
$type) $ret.=
"selected";
$ret.=
">".
$name.
"</option>\n";
$ret.=
"</select></td>\n";
$ret.=
$fld->editLst_getClassSelect($editUrl.
"&TMPLFLDCMD=CHANGECLASS",$selName=
"ChangeClass",$style=
"",$debug=
FALSE);
// ~~~~~~~~~~~~~~~ BUTTONS ~~~~~~~~~~~~~~~~~~~~
$ret.=
"\t<td width=\"17\" align=\"center\" class=\"button\">";
if ($fld->sortOrder >
1) {
$ret.=
"<a href=\"".
$funcUrl.
"&TMPLFLDCMD=UP\"><img src=\"".
$GLOBALS['OCSP']['SYSIMGURL'].
"buttons/up.gif\" border=\"0\" alt=\"move up\"></a></td>";
$ret.=
"\t<td width=\"17\" align=\"center\" class=\"button\">";
$ret.=
"<a href=\"".
$funcUrl.
"&TMPLFLDCMD=DOWN\"><img src=\"".
$GLOBALS['OCSP']['SYSIMGURL'].
"buttons/down.gif\" border=\"0\" alt=\"move down\"></a></td>";
$ret.=
"\t<td width=\"2\" style=\"font-size:1px;\"> </td>";
$ret.=
"\t<td width=\"17\" align=\"center\" class=\"button\">";
$ret.=
"<a href=\"".
$funcUrl.
"&TMPLFLDCMD=SHOW\"><img src=\"".
$GLOBALS['OCSP']['SYSIMGURL'].
"buttons/ishidden.gif\" border=\"0\" alt=\"show\"></a></td>";
$ret.=
"<a href=\"".
$funcUrl.
"&TMPLFLDCMD=HIDE\"><img src=\"".
$GLOBALS['OCSP']['SYSIMGURL'].
"buttons/isshown.gif\" border=\"0\" alt=\"hide\"></a></td>";
$ret.=
"\t<td width=\"2\" style=\"font-size:1px;\"> </td>";
$ret.=
"\t<td width=\"17\" align=\"center\" class=\"button\">";
$ret.=
"<a href=\"javascript:{if (confirm('Feld: ".
$fld->myName.
" löschen?')) ";
$ret.=
" document.location.href='".
$funcUrl.
"&TMPLFLDCMD=DELETE';";
$ret.=
"}\"><img src=\"".
$GLOBALS['OCSP']['SYSIMGURL'].
"buttons/delete.gif\" border=\"0\" alt=\"delete\"></a></td>\n";
#####################################
* checks the sortorder of the input fields
if ($debug) echo
"<p><b>TMPL_CHAPTER::p_checkSort(...)</b> (".
get_class($this).
")</p><blockquote>";
// first put the DBMS fields into a new array other objects will be deleted
// find the first free orderNr
if (intval($fld->sortOrder)) {
// for objects where it is set
while(isset
($fldArr[$fld->sortOrder])) $fld->sortOrder++
;
// for objects where it is not set
while(isset
($fldArr[$orderNr])) $orderNr++
;
$fld->sortOrder=
$orderNr;
if ($debug) echo
"<p>".
$fld->sortOrder.
": getting Field: ".
$fld->getName().
"</p>";
$fldArr[$fld->sortOrder]=
$fld;
if ($debug) echo
"<p>WRONG OBJECT: ".
print_r($fld).
"</p>";
// secound sort $fldArr and clear inputFields
// third set the new inputFields
foreach($fldArr as $fld) {
$fld->sortOrder=
$orderNr++
;
if ($debug) echo
"<p>setting Field: ".
$fld->getName().
" as Nr: ".
$fld->sortOrder.
"</p>";
if ($debug) echo
"<p>No Fields in \$this->inputFields</p>";
if ($debug) echo
"</blockquote>";
* PRIVATE extracts template fields from code fields
* @param bool $clearFirst call $this->inputFields =array(); ?
* @param bool $debug show debug info
if ($debug) echo
"<hr><p><b>TMPL_CHAPTER::p_extractFields($clearFirst,$debug)</b></p><blockquote>";
if ($debug) echo
"<p>INPUTFIELD: $fld</p><p style=\"font-family: courier; font-size: 10px;\">".
nl2br(htmlspecialchars($this->{$fld})).
"</p>";
foreach($codeArr as $key =>
$fld) {
if (!empty($key)) { /* <pk-05-02-08 /> */
if ($debug) echo
"<p>checking: $key </p><blockquote>";
if ($debug) echo
"<p style=\"font-size:80%\"><b>is Form Field</b> (".
print_r($fld,TRUE).
"</p>";
require_once $GLOBALS['OCSP']['DBMSFLD_PATH'].
"DBMS_FIELD.phpclass";
if ($debug) echo
"<p style=\"font-size:80%\">no Form Field (".
print_r($fld,TRUE).
"</p>";
if ($debug) echo
"</blockquote>";
if ($debug) echo
"<p>EMPTY FIELD</p>";
/* <pk-05-02-10 remove fields with illegal chars in key > */
$illegalchars=
array(" ","\n","<",">","&","?");
if ($debug) echo
"<p><b><u>Input Fields:</u></b></p>";
while (!$found && list
($idx,$iChar)=
each($illegalchars)) {
if (strstr($key,$iChar)) $found=
TRUE;
if ($debug) echo
"<p>$key: ".
get_class($fld).
"</p>";
if ($debug) echo
"</blockquote>";
// #################################
* sets the db datatype of a field
* @param string $fldName Name of the field
* @param string $dbType Name of the DB col type
* @param boolean $autosave save object after change
function setFieldDBType($fldName,$dbType,$autoSave=
TRUE,$debug=
FALSE) {
if ($debug) echo
"<p><b>TMPL_CHAPTER::setFieldDBType($fldName,$dbType,...)</b> (".
get_class($this).
")</p>";
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/pcf.phpinc";
if ($autoSave) $this->dbSave($this->get_gDBIDX(),$debug);
// #################################
* returns an array with pointers to the template fields
$this->dbSave($this->get_gDBIDX(),$debug);
if (empty($obj->myName)) $obj->myName=
$key;
if ($debug) echo
$obj->sortOrder.
": ".
$key.
" ".
$obj->label;
if (isset
($ret[$obj->sortOrder])) {
echo
"<p>DUPLICATE ORDERNR</p>";
$this->dbSave($this->get_gDBIDX(),$debug);
// #################################
* returns the form object for the chapter
* @param string $aForm Name of a DMBS_FORM if empty TABLENAME is used
* @param boolean $inputFieldsOnly hide all other fields
function &getChapterForm($aForm=
"",$debug=
FALSE,$inputFieldsOnly=
FALSE) {
require_once $GLOBALS['OCSP']['PHPFORMPATH'].
"forms.phpinc";
$ERR=
"FORM_NOT_FOUND ".
$aForm;
include $GLOBALS['PROJECT']['PHPINCPATH'].
"io/errors.phpinc";
$maxSortOrder=
sizeof($frmObj->frmFields);
$obj->sortOrder=
$obj->sortOrder+
$maxSortOrder;
$frmObj->addNoDBFieldObj($obj);
* returns a serialized array of the input fields in $postArr
* if $fldArr is an array the fields are added/replaced
* otherwise a new array is created
* @param boolean $keepServerName (replace http://SERVER_NAME/ with / ?)
function getFieldValues($postArr,$keepServerName=
FALSE, $debug=
FALSE,$fldArr=
NULL) {
if ($debug) echo
"<p><b>TMPL_CHAPTER::getFieldValues(\$postArr array(".
sizeof($postArr).
"),$keepServerName,$debug,\$fldArr array(".
sizeof($fldArr).
"))</b> (".
get_class($this).
")</p>";
// if ($debug) echo "<blockquote><pre>".htmlspecialchars(print_r($postArr,TRUE))."</pre></blockquote>";
if ($debug) echo
"<blockquote>Object: $key<pre>".
pcf_print_r($obj,TRUE,3).
"</pre>";
if (stristr($obj->className,"HTML")) {
if ((!$keepServerName) ||
($obj->getSetting("replaceServer"))) {
// replace http://servername/ with / to allow more systems
$retArr[$obj->myName]=
str_replace("http://".
$_SERVER['SERVER_NAME'].
"/","/",$postArr[$obj->myName]);
$retArr[$obj->myName]=
$postArr[$obj->myName];
$retArr[$obj->myName]=
$postArr[$obj->myName];
if ($debug) echo
"<blockquote>returns NULL</blockquote><hr>";
if ($debug) echo
"<blockquote>getFieldValues returns serialize of <pre>".
htmlspecialchars(print_r($retArr,TRUE)).
"</pre></blockquote><hr>";
* returns the html code for the template
function getTag($vals=
array(),$var=
"HTMLCODE",$debug=
FALSE) {
$arrName=
"tmplValArr_".
$this->getId;
echo
"<p><b>TMPL_CHAPTER::getTag(\$vals (".
sizeof($vals).
"),$var,...)</b> ".
get_class($this).
"</p>";
echo
"<pre>";print_r($vals);echo
"</pre>";
if ((!empty($tag)) &&
(is_array($vals))) {
while(list($fld,$val)=each($vals)) {
$tag=str_replace("\$*".$fld."\$",$val,$tag);
$fldLst=
$frmObj->getFieldArr();
foreach($fldLst as $fld) {
$tmplVals[$fld->myName]=
$fld->getHtmlTag($vals[$fld->myName],$arrName,$debug);
if ($debug) echo "<blockquote>Replace Field: ".$fld->myName."<br /><pre>".print_r($vals[$fld->myName],TRUE)."</pre></blockquote>";
$tag=str_replace("\$*".$fld->myName."\$",$fld->getHtmlTag($vals[$fld->myName],$arrName,$debug),$tag);
if (is_array($GLOBALS['CMS']['LINKREPLACE'])) {
if ($debug) echo
"<p>['CMS']['LINKREPLACE']: </p><pre>".
print_r($GLOBALS['CMS']['LINKREPLACE'],TRUE).
"</pre>";
$linkPattern=
"/(<a *)(href=\")([^\"]*)([^>]*)(>)/i";
foreach($links[3] as $lIdx =>
$repluri) {
// if ($debug) echo "<p>".trim($links[3][$lIdx])." -- ".$links[4][$lIdx]."</p>";
(!empty($GLOBALS['CMS']['EXLINKDFLTTRG'])) &&
$rplTarget =
$links[4][$lIdx].
" target=\"".
$GLOBALS['CMS']['EXLINKDFLTTRG'].
"\"";
if ($debug) echo
"<p>TARGETREPLACE: ".
$links[4][$lIdx].
"<br />.".
$rplTarget.
"</p>";
if ($debug) echo
("<p><b>Link $lIdx</b></p>");
foreach($GLOBALS['CMS']['LINKREPLACE'] as $rIdx =>
$rLinkArr) {
if (strstr($repluri,$rLinkArr['SRC'])) {
$replWith =
$links[1][$lIdx];
$replWith .=
$links[2][$lIdx];
if (!empty($GLOBALS['CMS']['LINKREPLACE'][$rIdx]['TARGET'])) {
$replWith .=
$links[4][$lIdx].
" target=\"".
$GLOBALS['CMS']['LINKREPLACE'][$rIdx]['TARGET'].
"\" ";
if ($rplTarget) $replWith.=
$rplTarget;
else $replWith .=
$links[4][$lIdx];
$replWith .=
$links[5][$lIdx];
// echo "<pre>\n".htmlspecialchars($repluri."\n".$dst."\n".$tag)."</pre>";
$replWith=
$links[1][$lIdx].
$links[2][$lIdx].
$links[3][$lIdx].
$rplTarget.
$links[5][$lIdx];
return pcf_tmpl_parse($tag,$vals,$debug); /* <pk-04-11-15 /> to replace values defined in the template values (forms for example) */
Documentation generated on Thu, 08 Jan 2009 17:48:47 +0100 by phpDocumentor 1.4.0a2