238 lines
6.2 KiB
PHP
238 lines
6.2 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");
|
|
|
|
/** Ticket Objects
|
|
* abstract superclass for ticket reservation related objects
|
|
*
|
|
* @version 1.0.0
|
|
* @since 2007-06-04
|
|
* @author martin lenzelbauer
|
|
*
|
|
*/
|
|
class TicketObject extends CmsObject{
|
|
|
|
// --- ticket object metadata --- //
|
|
|
|
var $classId; //id in the class table
|
|
|
|
|
|
/** C'tor (default settings)
|
|
* @param line sql result line
|
|
* @param parent parent element
|
|
*/
|
|
//-----------------------------------------------
|
|
function TicketObject($id, $parent){
|
|
//-----------------------------------------------
|
|
parent::CmsObject($id, $parent);
|
|
$this->classId = 0;
|
|
$this->visible = 1;
|
|
}
|
|
|
|
|
|
/** @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);
|
|
foreach($this->childObjects as $i=>$child){
|
|
$this->childObjects[$i]->load($path);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::save()
|
|
*/
|
|
//-----------------------------------------------
|
|
function save(){
|
|
//-----------------------------------------------
|
|
if($this->id){
|
|
$this->doSave();
|
|
}
|
|
else{
|
|
$this->doCreate();
|
|
}
|
|
}
|
|
|
|
|
|
/** updates the database
|
|
*/
|
|
//----------------------------------------------
|
|
function doSave(){
|
|
//----------------------------------------------
|
|
$childIds = array();
|
|
foreach($this->childObjects as $i=>$child){
|
|
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();
|
|
foreach($this->childObjects as $i=>$child){
|
|
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(){
|
|
//----------------------------------------------
|
|
foreach($this->childObjects as $i=>$child){
|
|
if(!$this->childObjects[$i]->canBeDeleted()){
|
|
$this->addError($this->toString().htmlspecialchars(" 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'];
|
|
}
|
|
}
|
|
|
|
|
|
/** @see CmsObject::doPrintMetadata()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doPrintMetadata(){
|
|
//-----------------------------------------------
|
|
return "";
|
|
}
|
|
|
|
|
|
/** returns the class id
|
|
*/
|
|
//-----------------------------------------------
|
|
function getClassId(){
|
|
//-----------------------------------------------
|
|
return $this->classId;
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
?>
|