316 lines
9.0 KiB
PHP
316 lines
9.0 KiB
PHP
<?php
|
|
|
|
/** Standard Page Copy
|
|
*
|
|
* @version 2.1.0
|
|
* @date 2007-03-27
|
|
* @author martin lenzelbauer
|
|
*
|
|
* @change 2007-06-11
|
|
* fixed bug in update()
|
|
*
|
|
* @change 2007-06-15
|
|
* further change in update()
|
|
*
|
|
* @change 2007-06-16
|
|
* added canBeDeleted()
|
|
*
|
|
* @change 2008-09-23
|
|
* updated loading & publishing routines to keep memory low in PHP5
|
|
*/
|
|
class StdPageCopy extends StdPage{
|
|
|
|
var $originalId;
|
|
|
|
/** C'tor
|
|
*/
|
|
//------------------------------------------------
|
|
function StdPageCopy($id, $parent){
|
|
//------------------------------------------------
|
|
parent::StdPage($id, $parent);
|
|
$this->name = "[unbenannte Kopie]";
|
|
$this->originalId = 0;
|
|
}
|
|
|
|
|
|
/** @see CmsObject::load()
|
|
*/
|
|
//-----------------------------------------------
|
|
function load($path=array()){
|
|
//-----------------------------------------------
|
|
parent::load($path);
|
|
if(!$this->classId){
|
|
return;
|
|
}
|
|
$query = sprintf("SELECT * FROM bruckm_stdpagecopy WHERE id = %d", $this->classId);
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$this->template = $line['template'];
|
|
$this->originalId = $line['originalId'];
|
|
|
|
$query = sprintf("SELECT * FROM bruckm_stdpage WHERE id = %d", $this->originalId);
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$this->buildingBlocks = array();
|
|
if(strlen($line['buildingBlocks']) > 0){
|
|
$buildingBlocks = explode("\t", $line['buildingBlocks']);
|
|
foreach($buildingBlocks as $b){
|
|
$block = BuildingBlockFactory::instance($b);
|
|
$block->load();
|
|
$this->buildingBlocks[] = $block;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** @see Page::doSave()
|
|
*/
|
|
//----------------------------------------------
|
|
function doSave(){
|
|
//----------------------------------------------
|
|
$query = sprintf("UPDATE bruckm_stdpagecopy SET template = %s, originalId = %d WHERE id = %d",
|
|
sqlstring($this->template),
|
|
sqlnum($this->originalId),
|
|
sqlnum($this->classId));
|
|
dbQuery($query);
|
|
|
|
$buildingBlocks = array();
|
|
foreach($this->buildingBlocks as $i=>$block){
|
|
$this->buildingBlocks[$i]->save();
|
|
$buildingBlocks[] = $this->buildingBlocks[$i]->getReference();
|
|
}
|
|
$query = sprintf("UPDATE bruckm_stdpage SET buildingBlocks = %s WHERE id = %d",
|
|
sqlstring(implode("\t", $buildingBlocks)),
|
|
sqlnum($this->originalId));
|
|
dbQuery($query);
|
|
|
|
Page::doSave();
|
|
}
|
|
|
|
|
|
/** @see Page::doCreate()
|
|
*/
|
|
//----------------------------------------------
|
|
function doCreate(){
|
|
//----------------------------------------------
|
|
$query = sprintf("INSERT INTO bruckm_stdpagecopy (template) VALUES (%s)",
|
|
sqlstring($this->template));
|
|
dbQuery($query);
|
|
$this->classId = mysql_insert_id();
|
|
Page::doCreate();
|
|
}
|
|
|
|
|
|
/** @see Page::canBeDeleted()
|
|
*/
|
|
//----------------------------------------------
|
|
function canBeDeleted(){
|
|
//----------------------------------------------
|
|
return true;
|
|
}
|
|
|
|
|
|
/** @see Page::doDelete()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doDelete(){
|
|
//-----------------------------------------------
|
|
parent::doDelete();
|
|
$query = sprintf("DELETE FROM bruckm_stdpagecopy WHERE id = %d LIMIT 1", $this->classId);
|
|
dbQuery($query);
|
|
}
|
|
|
|
/** @see Page::install()
|
|
*/
|
|
//-----------------------------------------------
|
|
function install(){
|
|
//-----------------------------------------------
|
|
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_stdpagecopy (
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
originalId INT UNSIGNED NOT NULL,
|
|
template VARCHAR(100) NOT NULL,
|
|
PRIMARY KEY (id)
|
|
)");
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
/** @see CmsObject::update()
|
|
*/
|
|
//-----------------------------------------------
|
|
function update(){
|
|
//-----------------------------------------------
|
|
if(isset($_POST['stdpage']) && $_POST['stdpage'] != $this->originalId){
|
|
$this->originalId = $_POST['stdpage'];
|
|
$this->doLoadPageContents();
|
|
Page::update();
|
|
}
|
|
else{
|
|
parent::update();
|
|
}
|
|
if(isset($_POST['template'])){
|
|
$this->template = $_POST['template'];
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::doPrintClassContent()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doPrintClassContent(){
|
|
//-----------------------------------------------
|
|
$t = new Template(CMS_TEMPLATE_DIR."stdpagecopy.html");
|
|
$pages = "";
|
|
$query = sprintf("SELECT id,classId,name FROM bruckm_index WHERE class = %s ORDER BY name ASC",
|
|
sqlstring("StdPage"));
|
|
$result = dbQuery($query);
|
|
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
|
|
if($line['classId'] == $this->originalId){
|
|
$pages .= "<option value=\"$line[classId]\" selected=\"selected\">".htmlspecialchars($line['name']). " (ID: " . $line['id'] . ")</option>";
|
|
}
|
|
else{
|
|
$pages .= "<option value=\"$line[classId]\">".htmlspecialchars($line['name']). " (ID: " . $line['id'] . ")</option>";
|
|
}
|
|
}
|
|
$t->setVar("PAGES", $pages);
|
|
if($this->isEditable()){
|
|
$t->setVar("PAGES_DISABLED", "");
|
|
}
|
|
else{
|
|
$t->setVar("PAGES_DISABLED", "disabled=\"disabled\"");
|
|
}
|
|
|
|
$templates = "";
|
|
$templateFiles = array();
|
|
$dir = opendir(TEMPLATE_DIR);
|
|
while($file = readdir($dir)){
|
|
if(is_file(TEMPLATE_DIR.$file)){
|
|
$templateFiles[] = $file;
|
|
}
|
|
}
|
|
sort($templateFiles);
|
|
foreach($templateFiles as $file){
|
|
if($file == $this->template){
|
|
$templates .= "<option value=\"$file\" selected=\"selected\">$file</option>";
|
|
}
|
|
else{
|
|
$templates .= "<option value=\"$file\">$file</option>\n";
|
|
}
|
|
}
|
|
$t->setVar("TEMPLATES", $templates);
|
|
|
|
$out = $t->toString();
|
|
$out .= $this->doPrintBuildingBlockInsertBar(0);
|
|
foreach($this->buildingBlocks as $i=>$block){
|
|
$out .= $this->buildingBlocks[$i]->printContent($i);
|
|
$out .= $this->doPrintBuildingBlockInsertBar($i+1);
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
|
|
/** @see CmsObject::publish()
|
|
*/
|
|
//---------------------------------------------
|
|
function publish(){
|
|
//---------------------------------------------
|
|
if($original = StdPageCopy::getOriginalOf($this->originalId)){
|
|
$original->load();
|
|
$original->setTemplate($this->template);
|
|
$out = $original->publish();
|
|
$original->unloadParent();
|
|
$original->unload();
|
|
return $out;
|
|
}
|
|
logError(4, "Original StdPage not found (id: ".$this->id.", classId: ".$this->classId.")", __FILE__, __LINE__);
|
|
$this->addError("Die Originalseite kann nicht gefunden werden!");
|
|
return false;
|
|
}
|
|
|
|
|
|
/** @see Element::getCssClass()
|
|
*/
|
|
//------------------------------------------------
|
|
function getCssClass(){
|
|
//------------------------------------------------
|
|
return "itemStdPageCopy";
|
|
}
|
|
|
|
|
|
// === ADDITIONAL METHODS ================================================================= //
|
|
|
|
/** loads the page contents when a new original page is selected
|
|
*/
|
|
//------------------------------------------------
|
|
function doLoadPageContents(){
|
|
//------------------------------------------------
|
|
$query = sprintf("SELECT * FROM bruckm_stdpage WHERE id = %d", $this->originalId);
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$this->template = $line['template'];
|
|
$this->buildingBlocks = array();
|
|
if(strlen($line['buildingBlocks']) > 0){
|
|
$buildingBlocks = explode("\t", $line['buildingBlocks']);
|
|
foreach($buildingBlocks as $b){
|
|
$block = BuildingBlockFactory::instance($b);
|
|
$block->load();
|
|
$this->buildingBlocks[] = $block;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** returns all copies of an original StdPage
|
|
* @param originalId classId of the original
|
|
* @return array with copies
|
|
*/
|
|
//------------------------------------------------
|
|
function getCopiesOf($originalId){
|
|
//------------------------------------------------
|
|
$query = sprintf("SELECT id FROM bruckm_stdpagecopy WHERE originalId = %d",
|
|
sqlnum($originalId));
|
|
$result = dbQuery($query);
|
|
$copies = array();
|
|
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
|
|
$query = sprintf("SELECT id FROM bruckm_index WHERE class = 'StdPageCopy' AND classId = %d LIMIT 1", $line['id']);
|
|
$result2 = dbQuery($query);
|
|
$line2 = mysqli_fetch_array($result2, MYSQLI_ASSOC);
|
|
$copies[] = FlexiconFactory::instanceById($line2['id']);
|
|
}
|
|
return $copies;
|
|
}
|
|
|
|
|
|
/** returns the original StdPage
|
|
* @param copyId classId of a copy
|
|
* @return StdPage
|
|
*/
|
|
//----------------------------------------------
|
|
function getOriginalOf($copyId){
|
|
//----------------------------------------------
|
|
$query = sprintf("SELECT id FROM bruckm_index WHERE class = %s AND classId = %d LIMIT 1",
|
|
sqlstring("StdPage"),
|
|
sqlnum($copyId));
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
return FlexiconFactory::instanceById($line['id']);
|
|
}
|
|
|
|
|
|
/** publishes only the copy, not the original
|
|
*/
|
|
//---------------------------------------------
|
|
function publishCopy(){
|
|
//---------------------------------------------
|
|
$out = $this->doPublish();
|
|
$query = sprintf("UPDATE bruckm_index SET cache = %s WHERE id = %d",
|
|
sqlstring($out),
|
|
sqlnum($this->id));
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
?>
|