251 lines
6.7 KiB
PHP
251 lines
6.7 KiB
PHP
<?php
|
|
require_once(ROOT."include/config.inc.php");
|
|
require_once(ROOT."include/template.inc.php");
|
|
require_once(ROOT."include/error.inc.php");
|
|
require_once(ROOT."include/array.inc.php");
|
|
require_once(ROOT."include/db.inc.php");
|
|
require_once(CMS_DIR."modules/_cmsobject.class.php");
|
|
|
|
/** Page
|
|
* abstract superclass for all pages
|
|
*
|
|
* @version 2.1.0
|
|
* @since 2007-05-01
|
|
* @author martin lenzelbauer
|
|
*
|
|
* @change 2007-06-18
|
|
* changed error output in canBeDeleted()
|
|
*
|
|
* @change 2008-09-23
|
|
* updated loading & publishing routines to keep memory low in PHP5
|
|
*
|
|
*/
|
|
class Page extends CmsObject{
|
|
|
|
// --- page metadata --- //
|
|
|
|
var $classId; //id in the class table
|
|
|
|
|
|
/** C'tor (default settings)
|
|
* @param line sql result line
|
|
* @param parent parent element
|
|
*/
|
|
//-----------------------------------------------
|
|
function Page($id, $parent){
|
|
//-----------------------------------------------
|
|
parent::CmsObject($id, $parent);
|
|
$this->classId = 0;
|
|
}
|
|
|
|
|
|
/** @see CmsObject::load()
|
|
*/
|
|
//-----------------------------------------------
|
|
function load($path=array()){
|
|
//-----------------------------------------------
|
|
$this->childObjects = array();
|
|
$query = sprintf("SELECT * FROM bruckm_index WHERE id = %d", $this->id);
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$this->name = $line['name'];
|
|
$this->classId = $line['classId'];
|
|
$this->parentId = $line['parentId'];
|
|
$this->editable = $line['editable'];
|
|
$this->listable = $line['listable'];
|
|
$this->visible = $line['visible'];
|
|
$this->lastUpdate = $line['lastUpdate'];
|
|
if(!empty($line['childObjects'])){
|
|
$childObjects = explode("\t", $line['childObjects']);
|
|
foreach($childObjects as $id){
|
|
$this->childObjects[] = FlexiconFactory::instanceById($id, $this);
|
|
}
|
|
}
|
|
if(sizeof($path) > 0 && $path[0] == $this->id){
|
|
array_shift($path);
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++) {
|
|
$this->childObjects[$i]->load($path);
|
|
}
|
|
}
|
|
$this->loaded = true;
|
|
}
|
|
|
|
|
|
/** @see CmsObject::save()
|
|
*/
|
|
//-----------------------------------------------
|
|
function save(){
|
|
//-----------------------------------------------
|
|
if($this->id){
|
|
$this->doSave();
|
|
}
|
|
else{
|
|
$this->doCreate();
|
|
}
|
|
}
|
|
|
|
|
|
/** updates the database
|
|
*/
|
|
//----------------------------------------------
|
|
function doSave(){
|
|
//----------------------------------------------
|
|
$childIds = array();
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++) {
|
|
if($this->childObjects[$i]->getId() == 0){
|
|
$this->childObjects[$i]->save();
|
|
}
|
|
$childIds[] = $this->childObjects[$i]->getId();
|
|
}
|
|
$query = sprintf("UPDATE bruckm_index SET
|
|
lastUpdate = NOW(),
|
|
name = %s,
|
|
classId = %d,
|
|
childObjects = %s,
|
|
editable = %s,
|
|
listable = %s,
|
|
visible = %d
|
|
WHERE id = %d",
|
|
sqlstring($this->name),
|
|
sqlnum($this->classId),
|
|
sqlstring(implode("\t", $childIds)),
|
|
sqlstring($this->editable),
|
|
sqlstring($this->listable),
|
|
sqlbool($this->visible),
|
|
sqlnum($this->id));
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
/** creates a new line in the database
|
|
*/
|
|
//----------------------------------------------
|
|
function doCreate(){
|
|
//----------------------------------------------
|
|
$childIds = array();
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++) {
|
|
if($this->childObjects[$i]->getId() == 0){
|
|
$this->childObjects[$i]->save();
|
|
}
|
|
$childIds[] = $this->childObjects[$i]->getId();
|
|
}
|
|
$query = sprintf("INSERT INTO bruckm_index (name, lastUpdate, class, classId,
|
|
parentId, childObjects, editable, listable, visible)
|
|
VALUES (%s, NOW(), %s, %d, %d, %s, %s, %s, %d)",
|
|
sqlstring($this->name),
|
|
sqlstring(get_class($this)),
|
|
sqlnum($this->classId),
|
|
sqlnum($this->parentId),
|
|
sqlstring(implode("\t", $childIds)),
|
|
sqlstring($this->editable),
|
|
sqlstring($this->listable),
|
|
sqlbool($this->visible));
|
|
dbQuery($query);
|
|
$this->id = mysql_insert_id();
|
|
}
|
|
|
|
|
|
/** @see CmsObject::delete()
|
|
*/
|
|
//-----------------------------------------------
|
|
function delete(){
|
|
//-----------------------------------------------
|
|
if($_SESSION['userlevel'] < $this->editable){
|
|
$this->addError("Sie besitzen nicht die nötigen Rechte, um dieses Element zu löschen!");
|
|
}
|
|
if($this->locked){
|
|
$this->addError("Das Element kann nicht gelöscht werden, da es gerade von einem anderen Benutzer bearbeitet wird");
|
|
return false;
|
|
}
|
|
if($this->id == 0){
|
|
return true;
|
|
}
|
|
if(!$this->canBeDeleted()){
|
|
return false;
|
|
}
|
|
$this->doDelete();
|
|
return true;
|
|
}
|
|
|
|
|
|
/** deletes data referenced by the page
|
|
* @return nothing
|
|
*/
|
|
//-----------------------------------------------
|
|
function doDelete(){
|
|
//-----------------------------------------------
|
|
$query = sprintf("DELETE FROM bruckm_index WHERE id = %d LIMIT 1", $this->id);
|
|
dbQuery($query);
|
|
foreach($this->childObjects as $i=>$child){
|
|
$this->childObjects[$i]->load();
|
|
$this->childObjects[$i]->delete();
|
|
}
|
|
}
|
|
|
|
|
|
/** checks wether the element can be deleted
|
|
* @returns true, if the element can be deleted
|
|
*/
|
|
//----------------------------------------------
|
|
function canBeDeleted(){
|
|
//----------------------------------------------
|
|
for($i = 0; $i < sizeof($this->childObjects); $i++) {
|
|
$this->childObjects[$i]->load();
|
|
if(!$this->childObjects[$i]->canBeDeleted()){
|
|
$this->addError($this->name." kann nicht gelöscht werden");
|
|
$this->addError($this->childObjects[$i]->getErrors());
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/** installs the database for class dependent data
|
|
*/
|
|
//----------------------------------------------
|
|
function install(){
|
|
//----------------------------------------------
|
|
return;
|
|
}
|
|
|
|
|
|
/** @see CmsObject::update()
|
|
*/
|
|
//-----------------------------------------------
|
|
function update(){
|
|
//-----------------------------------------------
|
|
if(isset($_POST['name'])){
|
|
$this->name = $_POST['name'];
|
|
$this->editable = $_POST['editable'];
|
|
$this->listable = $_POST['listable'];
|
|
$this->visible = $_POST['visible'];
|
|
}
|
|
}
|
|
|
|
|
|
/** prints a menu item
|
|
* @return string
|
|
*/
|
|
//-------------------------------------------
|
|
function printAsMenuItem(){
|
|
//-------------------------------------------
|
|
return "<li><a href=\"?id=".$this->id."\" target=\"_self\">".htmlspecialchars($this->name)."</a></li>";
|
|
}
|
|
|
|
|
|
/** updates the parent id
|
|
* @param parentId parent id
|
|
*/
|
|
//-------------------------------------------
|
|
function setParentId($parentId){
|
|
//-------------------------------------------
|
|
parent::setParentId($parentId);
|
|
$query = sprintf("UPDATE bruckm_index SET parentId = %d WHERE id = %d", $parentId, $this->getId());
|
|
dbQuery($query);
|
|
}
|
|
|
|
};
|
|
|
|
|
|
?>
|