Files
bm/public_html/public/cms/modules/ticketevent.class.php
2025-09-24 13:26:28 +02:00

1176 lines
35 KiB
PHP

<?php
require_once(ROOT."include/config.inc.php");
require_once(ROOT."include/date.inc.php");
require_once(CMS_DIR."modules/ticketdate.class.php");
define(RESERVATION_NONE, "none"); //no ticket reservation possible
define(RESERVATION_SIMPLE, "simple"); //simple ticket reservation
define(RESERVATION_SEAT, "seat"); //ticket reservation with choice of seat
define(RESERVATION_TABLE, "table"); //ticket reservation with choice of table
/** Ticket Event
*
* @version 2.1.0
* @since 2007-04-29
* @author martin lenzelbauer
*
* @change 2007-06-09
* added flexicon id, name and visibility to the event's class table
* for performance reasons
*
* @change 2007-06-15
* fixed PHP4 bug in getMenu() and getTemplate()
*
* @change 2007-06-17
* changed printInfoBox() - don't print info box for past events
*
* @change 2007-06-27
* added hack in printClassContent() to force IE to reload preview thumb
*
* @change 2007-07-18
* changed C'tor: initialised dates array to prevent foreach-warnings (only online?)
*
* @change 2007-09-29
* fixed bug in isInFuture() (include current day!)
*
* @change 2007-10-13
* added genres
*
* @change 2008-01-11
* prohibited changing the reservation type for non-admins, if "seat reservation" is currently active
*
* @change 2008-02-14
* redefined RESERVATION_* constants to strings (corresponding the enum in the database)
*
* @change 2012-01-18
* added owner (only owner and admin can delete events)
* added house
*/
class TicketEvent extends TicketObject{
var $startdate; //start date of the event
var $enddate; //end date of the event
var $category1; //flexicon id of main category
var $category2; //flexicon id of alternative category
var $category3; //flexicon id of alternative category
var $genre; //flexicon id of the meta genre
var $entries; //array of entries (a, b, c)
var $reductions; //array reduction ids
var $reservationType; //RESERVATION_NONE, RESERVATION_SIMPLE or RESERVATION_SEAT
var $thumb; //filename of the thumbnail
var $ownerId; // id of user who created this event
var $houseId; // the house this event is valid for
var $dates; //dates
var $thumbWidth = 50;
var $thumbHeight = 50;
var $thumbStretch = false;
/** C'tor
*/
//------------------------------------------------
function TicketEvent($id, $parent){
//------------------------------------------------
parent::TicketObject($id, $parent);
$this->name = "[Unbenannte Veranstaltung]";
$this->startDate = "";
$this->endDate = "";
$this->category1 = 0;
$this->category2 = 0;
$this->category3 = 0;
$this->genre = 0;
$this->reservationType = RESERVATION_NONE;
$this->thumb = "";
$this->entries = array();
$this->reductions = array();
$this->buttonPublish = true;
$this->dates = array();
$this->ownerId = 0;
$this->houseId = 0;
$this->assignDefaultValues();
}
/** @see CmsObject::load()
*/
//-----------------------------------------------
function load($path=array()){
//-----------------------------------------------
parent::load($path);
if(!$this->classId){
return;
}
$query = sprintf("SELECT * FROM bruckm_ticketevent WHERE id = %d", $this->classId);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
if($line['startDate']) $this->startDate = $line['startDate'] . " 00:00:00";
if($line['endDate']) $this->endDate = $line['endDate'] . " 23:59:59";
$this->category1 = $line['category1'];
$this->category2 = $line['category2'];
$this->category3 = $line['category3'];
$this->genre = $line['genre'];
$this->reservationType = $line['reservationType'];
if($line['entries']) $this->entries = explode("\t", $line['entries']);
if($line['reductions']) $this->reductions = explode("\t", $line['reductions']);
$this->thumb = $line['thumb'];
$this->ownerId = $line['ownerId'];
$this->houseId = $line['houseId'];
$this->dates = array();
if(strlen($line['dates']) > 0){
$dates = explode("\t", $line['dates']);
foreach($dates as $d){
$date = new TicketDate($d, $this);
$date->load();
$this->dates[] = $date;
}
}
}
/** @see TicketObject::doSave()
*/
//----------------------------------------------
function doSave(){
//----------------------------------------------
$dates = array();
foreach($this->dates as $i=>$date){
$this->dates[$i]->save();
$dates[] = $this->dates[$i]->getId();
}
$query = sprintf("UPDATE bruckm_ticketevent SET startDate = %s, endDate = %s,
category1 = %d, category2 = %d, category3 = %d, reservationType = %s,
thumb = %s, entries = %s, reductions = %s, dates = %s,
flexiconId = %d, name = %s, genre = %d, houseId = %d
WHERE id = %d",
sqlstring($this->startDate),
sqlstring($this->endDate),
sqlnum($this->category1),
sqlnum($this->category2),
sqlnum($this->category3),
sqlstring($this->reservationType),
sqlstring($this->thumb),
sqlstring(implode("\t", $this->entries)),
sqlstring(implode("\t", $this->reductions)),
sqlstring(implode("\t", $dates)),
sqlnum($this->id),
sqlstring($this->name),
sqlnum($this->genre),
sqlnum($this->houseId),
$this->classId);
dbQuery($query);
parent::doSave();
}
/** @see TicketObject::doCreate()
*/
//----------------------------------------------
function doCreate(){
//----------------------------------------------
$query = sprintf("INSERT INTO bruckm_ticketevent (dates, visible, ownerId) VALUES ('', 1, %d)", sqlnum($this->ownerId));
dbQuery($query);
$this->classId = mysql_insert_id();
parent::doCreate();
$this->childObjects[] = FlexiconFactory::instanceByClass("TicketPage", $this);
$this->doSave();
}
/** @see TicketObject::doDelete()
*/
//-----------------------------------------------
function doDelete(){
//-----------------------------------------------
parent::doDelete();
$query = sprintf("DELETE FROM bruckm_ticketevent WHERE id = %d LIMIT 1", $this->classId);
dbQuery($query);
foreach($this->dates as $i=>$date){
$this->dates[$i]->delete();
}
}
/** @see TicketObject::canBeDeleted()
*/
//-----------------------------------------------
function canBeDeleted(){
//-----------------------------------------------
return true;
}
/** @see TicketObject::install()
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_ticketevent (
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
flexiconId INT UNSIGNED NOT NULL,
name VARCHAR(200) NOT NULL DEFAULT '',
startDate DATE NULL,
endDate DATE NULL,
category1 INT NOT NULL DEFAULT 0,
category2 INT NOT NULL DEFAULT 0,
category3 INT NOT NULL DEFAULT 0,
genre INT NOT NULL DEFAULT 0,
entries VARCHAR(32) NULL,
reductions VARCHAR(255) NULL,
reservationType ENUM('none','simple','seat','table') NOT NULL DEFAULT 'none',
thumb VARCHAR(10) NOT NULL DEFAULT '',
dates VARCHAR(255) NULL,
visible TINYINT(1) NOT NULL DEFAULT 0,
ownerId INT NOT NULL DEFAULT 0,
houseId INT NOT NULL DEFAULT 0,
PRIMARY KEY (id)
)");
dbQuery($query);
TicketDate::install();
}
/** @see CmsObject::update()
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
parent::update();
$this->childObjects[0]->setName($this->name);
$this->startDate = createDate($_POST['startday'], $_POST['startmonth'], $_POST['startyear']);
$this->endDate = createDate($_POST['endday'], $_POST['endmonth'], $_POST['endyear']);
if(empty($this->endDate) && !empty($this->startDate)){
$this->endDate = $this->startDate;
}
if(strtotime($this->endDate) < strtotime($this->startDate)){
$this->endDate = $this->startDate;
}
$this->category1 = $_POST['category1'];
$this->category2 = $_POST['category2'];
$this->category3 = $_POST['category3'];
$this->genre = $_POST['genre'];
$this->houseId = $_POST['houseId'];
if(isset($_FILES['thumb']) && $_FILES['thumb']['error'] == UPLOAD_ERR_OK){
$this->thumb = $this->uploadPreviewImage($_FILES['thumb']);
}
//reservation-only fields
if($this->reservationType != RESERVATION_NONE){
for($i=0; $i<3; $i++){
$this->entries[$i] = $_POST["entry$i"];
}
}
if(isset($_POST['reductions'])){
$this->reductions = $_POST['reductions'];
}
//update dates
foreach($this->dates as $i=>$date){
$this->dates[$i]->update();
}
//change reservation type
if($this->reservationType != $_POST['reservationType']){
$this->changeReservationType($_POST['reservationType']);
}
}
/** @see CmsObject::printContent()
*/
//-----------------------------------------------
function printContent(){
//-----------------------------------------------
if(!$this->isEditable()){
return $this->doPrintNotEditable();
}
if($this->locked){
return $this->doPrintLocked();
}
if($this->isEditable()){
$out = $this->doPrintErrors();
$out .= $this->doPrintMetadata();
$out .= $this->doPrintClassContent();
}
foreach($this->childObjects as $i=>$child){
if($this->childObjects[$i]->isListable()){
$out .= $this->doPrintInsertBar($i);
$out .= $this->childObjects[$i]->printChildContent();
}
}
if($this->reservationType > RESERVATION_NONE){
$out .= $this->doPrintDateInsertBar(0);
foreach($this->dates as $i=>$date){
$out .= $this->dates[$i]->printContent($i);
}
}
$out .= $this->doPrintButtons();
return $out;
}
/** @see CmsObject::doPrintClassContent()
*/
//-----------------------------------------------
function doPrintClassContent(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."ticketevent.html");
$t->setVar("NAME", htmlspecialchars($this->name));
$t->setVar("START_DAY", dateGet($this->startDate, "d"));
$t->setVar("START_MONTH", dateGet($this->startDate, "m"));
$t->setVar("START_YEAR", dateGet($this->startDate, "Y"));
$t->setVar("END_DAY", dateGet($this->endDate, "d"));
$t->setVar("END_MONTH", dateGet($this->endDate, "m"));
$t->setVar("END_YEAR", dateGet($this->endDate, "Y"));
if($this->thumb){
$t->setVar("THUMB", TICKET_THUMB_DIR.$this->thumb."?random=".time());
}
else{
$t->removeBlock("THUMB");
}
if($this->reservationType == RESERVATION_SIMPLE){
$t->setVar("RESERVATION_SIMPLE", "selected=\"selected\"");
$t->setVar("RESERVATION_TABLE", "");
$t->setVar("RESERVATION_SEAT", "");
$t->setVar("RESERVATION_NONE", "");
}
else if($this->reservationType == RESERVATION_SEAT){
$t->setVar("RESERVATION_SEAT", "selected=\"selected\"");
$t->setVar("RESERVATION_TABLE", "");
$t->setVar("RESERVATION_SIMPLE", "");
$t->setVar("RESERVATION_NONE", "");
}
else if($this->reservationType == RESERVATION_TABLE){
$t->setVar("RESERVATION_TABLE", "selected=\"selected\"");
$t->setVar("RESERVATION_SEAT", "");
$t->setVar("RESERVATION_SIMPLE", "");
$t->setVar("RESERVATION_NONE", "");
}
else{
$t->setVar("RESERVATION_NONE", "selected=\"selected\"");
$t->setVar("RESERVATION_TABLE", "");
$t->setVar("RESERVATION_SIMPLE", "");
$t->setVar("RESERVATION_SEAT", "");
}
//categories
$query = sprintf("SELECT id,name FROM bruckm_index WHERE class = 'TicketCategory' ORDER BY name ASC");
$result = dbQuery($query);
$categories1 = "<option value=\"0\">&nbsp;</option>";
$categories2 = "<option value=\"0\">&nbsp;</option>";
$categories3 = "<option value=\"0\">&nbsp;</option>";
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if($line['id'] == $this->category1){
$categories1 .= "<option value=\"$line[id]\" selected=\"selected\">";
}
else{
$categories1 .= "<option value=\"$line[id]\">";
}
$categories1 .= htmlspecialchars($line['name'])."</option>";
if($line['id'] == $this->category2){
$categories2 .= "<option value=\"$line[id]\" selected=\"selected\">";
}
else{
$categories2 .= "<option value=\"$line[id]\">";
}
$categories2 .= htmlspecialchars($line['name'])."</option>";
if($line['id'] == $this->category3){
$categories3 .= "<option value=\"$line[id]\" selected=\"selected\">";
}
else{
$categories3 .= "<option value=\"$line[id]\">";
}
$categories3 .= htmlspecialchars($line['name'])."</option>";
}
$t->setVar("CATEGORIES1", $categories1);
$t->setVar("CATEGORIES2", $categories2);
$t->setVar("CATEGORIES3", $categories3);
//genres
$query = sprintf("SELECT id,name FROM bruckm_index WHERE class = 'TicketGenre' ORDER BY name ASC");
$result = dbQuery($query);
$genres = "<option value=\"0\">&nbsp;</option>";
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if($line['id'] == $this->genre){
$genres .= "<option value=\"$line[id]\" selected=\"selected\">";
}
else{
$genres .= "<option value=\"$line[id]\">";
}
$genres .= htmlspecialchars($line['name'])."</option>";
}
$t->setVar("GENRES", $genres);
// houses
$query = sprintf("SELECT * FROM bruckm_house ORDER BY position ASC");
$result = dbQuery($query);
$houses = ($this->houseId == 0) ? '<option value="0" selected="selected">Alle</option>' : '<option value="0">Alle</option>';
while ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
if ($line['id'] == $this->houseId) {
$houses .= '<option value="' . $line['id'] . '" selected="selected">';
}
else {
$houses .= '<option value="' . $line['id'] . '">';
}
$houses .= htmlspecialchars($line['name']) . '</option>';
}
$t->setVar("HOUSES", $houses);
//reservation-only fields
if($this->reservationType != RESERVATION_NONE){
//entries
for($i=0; $i<3; $i++){
$t->setVar("ENTRY$i", $this->entries[$i]);
}
//reductions
$query = sprintf("SELECT id FROM bruckm_index WHERE class = 'TicketReduction' ORDER BY name ASC");
$result = dbQuery($query);
$reductions = "";
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$r = FlexiconFactory::instanceById($line['id']);
$r->load();
$reductions .= "<input type=\"checkbox\" name=\"reductions[]\" value=\"$line[id]\" ";
if(in_array($line['id'], $this->reductions)){
$reductions .= "checked=\"checked\"";
}
$reductions .= " />" . htmlspecialchars($r->getShortInfo()) . "<br />";
}
$t->setVar("REDUCTIONS", $reductions);
//change reservation type
$ask = 0;
for($i=0; $i<sizeof($this->dates) && !$ask; $i++){
if($this->dates[$i]->hasReservations()){
$ask = 1;
}
}
$t->setVar("ASK", $ask);
}
else{
$t->removeBlock("RESERVATION");
$t->setVar("ASK", 0);
}
$t->setVar("RESERVATION_TYPE", $this->reservationType);
return $t->toString();
}
/** @see CmsObject::printChildContent()
*/
//----------------------------------------------
function printChildContent(){
//----------------------------------------------
$out = "<tr>";
$out .= "<td class=\"eventDate\">".datetime2dmy($this->lastUpdate)."</td>";
if($this->visible){
$out .= "<td class=\"eventName\">";
}
else{
$out .= "<td class=\"eventNameHighlight\">";
}
if ($_SESSION['userid'] == $this->ownerId || $_SESSION['userlevel'] == USER_ADMIN) {
$out .= "<a href=\"javascript:loadPage('".$this->printPath()."');\" target=\"_self\">".$this->toString()."</a> ";
$out .= "<a href=\"javascript:deleteElement(".$this->id.");\" target=\"_self\">(l&ouml;schen)</a>";
}
else {
$out .= $this->toString();
}
$out .= "</td>";
$out .= "</tr>";
return $out;
}
/** @see CmsObject::doPublish()
*/
//----------------------------------------------
function doPublish(){
//----------------------------------------------
$this->visible = 1;
$this->save();
}
/** @see DBElement::canBePublished()
*/
//----------------------------------------------
function canBePublished(){
//----------------------------------------------
$ok = true;
if(empty($this->name)){
$this->addError("Bitte vergeben Sie einen Titel für die Veranstaltung!");
$ok = false;
}
if(empty($this->startDate) || ereg("^0000-00-00$", $this->startDate)){
$this->addError("Bitte vergeben Sie ein Datum/Zeitraum!");
$ok = false;
}
if($this->category1 == 0){
if($this->category2 == 0 && $this->category3 == 0){
$this->addError("Bitte wählen Sie zumindest eine Kategorie, unter der die Veranstaltung eingeordnet werden soll!");
$ok = false;
}
else{
if($this->category2 != 0) $this->category1 = $this->category2;
else $this->category1 = $this->category3;
}
}
foreach($this->dates as $i=>$date){#
$date = clone($date);
if(!$date->isValid()){
$this->addError("Der Termin ".$date->toString()." ist fehlerhaft!");
$ok = false;
}
}
return $ok;
}
/** @see CmsObject::handleAction()
*/
//-----------------------------------------------
function handleAction($action, $position, $type){
//-----------------------------------------------
switch($action){
case "insertDate":
$this->doInsertDate($position);
break;
case "deleteDate":
$this->doDeleteDate($position);
break;
}
}
/** @see CmsObject::show()
*/
//---------------------------------------------
function show(){
//---------------------------------------------
$this->childObjects[0]->load();
return $this->childObjects[0]->show();
}
/** @see Element::getCssClass()
*/
//------------------------------------------------
function getCssClass(){
//------------------------------------------------
return "itemTicketEvent";
}
// === ADDITIONAL METHODS =============================================================== //
/** changes the reservation type and deletes all previous dates
* @param type new reservation type
*/
//-----------------------------------------------
function changeReservationType($type){
//-----------------------------------------------
if($this->reservationType == RESERVATION_SEAT && $_SESSION['userlevel'] != USER_ADMIN){
$this->addError("Der Reservierungstyp kann nicht mehr geändert werden!");
return;
}
$this->reservationType = $type;
foreach($this->dates as $i=>$date){
$this->dates[$i]->delete();
}
$this->dates = array();
}
/** uploads a preview image file
* @param file $_FILES file date
*/
//------------------------------------------------
function uploadPreviewImage($file){
//------------------------------------------------
//remove old image
if(!empty($this->thumb) && file_exists(TICKET_THUMB_DIR.$this->thumb)){
@unlink(TICKET_THUMB_DIR.$this->thumb);
}
//create target path
$imgSize = getImageSize($file['tmp_name']);
switch($imgSize[2]){
case 1: //gif
$path = $this->id.".gif";
break;
case 2: //jpg
$path = $this->id.".jpg";
break;
case 3: //png
$path = $this->id.".png";
break;
default:
logError(3, "Unsupported mime type: $file[name] ($imgSize[2])", __FILE__, __LINE__);
$this->addError("Das Bild verwendet ein nicht unterstütztes Dateiformat oder es ist beschädigt!");
return "";
}
//resize image
if($imgSize[0] > $this->thumbWidth || $imgSize[1] > $this->thumbHeight){
switch($imgSize[2]){
case 1: //gif
$original = imageCreateFromGif($file['tmp_name']);
break;
case 2: //jpg
$original = imageCreateFromJpeg($file['tmp_name']);
break;
case 3: //png
$original = imageCreateFromPng($file['tmp_name']);
break;
}
$origWidth = $imgSize[0];
$origHeight = $imgSize[1];
$width = $this->thumbWidth;
$height = $this->thumbHeight;
$origX = 0;
$origY = 0;
//clip image
if(!$this->thumbStretch){
if($origWidth > $origHeight){
$origX = ($origWidth - $origHeight)/2;
$origWidth = $origHeight;
}
else{
$origY = ($origHeight - $origWidth)/2;
$origHeight = $origWidth;
}
}
$small = imageCreateTrueColor($width, $height);
imageCopyResampled($small, $original, 0, 0, $origX, $origY, $width, $height, $origWidth, $origHeight);
switch($imgSize[2]){
case 1:
if(!@imageGif($small, TICKET_THUMB_DIR.$path)){
logError(4, "Could not create gif image: $path", __FILE__, __LINE__);
$this->addError("Das Bild konnte nicht erzeugt werden!");
return "";
}
break;
case 2:
if(!@imageJpeg($small, TICKET_THUMB_DIR.$path, 100)){
logError(4, "Could not create jpg image: $path", __FILE__, __LINE__);
$this->addError("Das Bild konnte nicht erzeugt werden!");
return "";
}
break;
case 3:
if(!@imagePng($small, TICKET_THUMB_DIR.$path)){
logError(4, "Could not create png image: $path", __FILE__, __LINE__);
$this->addError("Das Bild konnte nicht erzeugt werden!");
return "";
}
break;
}
imageDestroy($small);
imageDestroy($original);
@chmod(TICKET_THUMB_DIR.$path, 0777);
}
//copy image in original size
else{
if(@move_uploaded_file($file['tmp_name'], TICKET_THUMB_DIR.$path)){
@chmod(TICKET_THUMB_DIR.$path, 0777);
}
else{
logError(4, "Could not copy image: $file[tmp_name] => $path)", __FILE__, __LINE__);
$this->addError("Das Bild konnte nicht erzeugt werden!");
return "";
}
}
return $path;
}
/** inserts a date
* @param index position
*/
//-----------------------------------------------
function doInsertDate($index){
//-----------------------------------------------
$d = new TicketDate(0, $this);
$d->setDate($this->startDate." 19:30:00");
$d->setEntries($this->entries);
$d->setReductions($this->reductions);
$this->dates = array_insert($this->dates, $index, $d);
$this->save();
}
/** deletes a date
* @param index position
*/
//-----------------------------------------------
function doDeleteDate($index){
//-----------------------------------------------
$this->dates[$index]->delete();
$this->dates = array_remove($this->dates, $index);
$this->save();
}
/** prints a bar with buttons for inserting new dates
* @return string
*/
//-----------------------------------------------
function doPrintDateInsertBar($index){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."insertbar.html");
$button = "<div class=\"insert\" onMouseOver=\"showTooltip('%s einf&uuml;gen')\"".
"onClick=\"setAction('insertDate', %d, '%s'); document.forms[0].submit();\">".
"<img src=\"images/%s1.png\" alt=\"%s einf&uuml;gen\" onMouseOver=\"swapImage(this,2)\" onMouseOut=\"swapImage(this,1)\" />".
"</div>";
$out .= sprintf($button, "Termin", $index, "ticketdate", "ticketdate", "Termin");
$t->setVar("CLASSES", $out);
return $t->toString();
}
/** writes event data into xml
* @param allReductions true to return dates with all reductions
* @return string
*/
//----------------------------------------
function toXml($allReductions=false){
//----------------------------------------
$xml = "<event id=\"".$this->id."\" title=\"".$this->name."\" reservationtype=\"".$this->reservationType."\" >";
foreach($this->dates as $i=>$date){
$date->load();
if($date->isInFuture()){
$xml .= $date->toXml($allReductions);
}
}
$xml .= "</event>";
return $xml;
}
/** returns the year (of the end date)
* @return year
*/
//----------------------------------------
function getYear($begin=false){
//----------------------------------------
if ($begin) {
return dateGet($this->startDate, "Y");
}
return dateGet($this->endDate, "Y");
}
/** returns the start date
* @return start date (Y-m-d)
*/
//----------------------------------------
function getStartDate(){
//----------------------------------------
return $this->startDate;
}
/** returns the end date
* @return end date (Y-m-d)
*/
//----------------------------------------
function getEndDate(){
//----------------------------------------
return $this->endDate;
}
/** returns the reservation type
* @return integer value (see defines at the top of the file!)
*/
//----------------------------------------
function getReservationType(){
//----------------------------------------
return $this->reservationType;
}
/** returns the array of entries
* @return array
*/
//----------------------------------------
function getEntries(){
//----------------------------------------
return $this->entries;
}
/** returns the title of the event
* @return event
*/
//----------------------------------------
function getTitle(){
//----------------------------------------
return $this->name;
}
/** returns the id of the main category
* @return number
*/
//---------------------------------------
function getCategoryId(){
//---------------------------------------
return $this->category1;
}
/** returns the name of the main category
* @return string
*/
//---------------------------------------
function getCategoryName(){
//---------------------------------------
if($c = FlexiconFactory::instanceById($this->category1)){
$c->load();
return $c->toString();
}
return "keine Kategorie";
}
/** returns the html template that is selected in the PersonList
* @return template
*/
//------------------------------------------
function getTemplate(){
//------------------------------------------
if(!$this->parentObj){
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
}
$parent = clone($this->parentObj);
$parent->load();
return $parent->getTemplate();
}
/** returns the Menu object
* @return Menu
*/
//------------------------------------------
function getMenu(){
//------------------------------------------
if(!$this->parentId){
$this->parentId = 83;
}
if(!$this->parentObj){
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
}
$parent = clone($this->parentObj);
$parent->load();
return $parent->getMenu();
}
/** returns the genre name
* @return genre name
*/
//---------------------------------------
function getGenre(){
//---------------------------------------
if(!$this->genre){
return "";
}
$query = sprintf("SELECT name FROM bruckm_index WHERE id = %d");
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
return $line['name'];
}
/** checks if the event is in the future
* @return true if in future
*/
//---------------------------------------
function isInFuture(){
//---------------------------------------
return compareDates($this->endDate, date("Y-m-d")) >= 0;
}
/** checks if the event has support for the Kulturcard reduction
* @return true if kulturcard is supported
*/
//---------------------------------------
function hasKulturcard(){
//---------------------------------------
$kulturcardIds = $this->getKulturcardReductionIds();
$query = sprintf("SELECT reductions FROM bruckm_ticketdate WHERE eventId = %d", $this->classId);
$result = dbQuery($query);
while ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$reductionIds = explode("\t", $line['reductions']);
foreach ($kulturcardIds as $id) {
if (in_array($id, $reductionIds)) {
return true;
}
}
}
return false;
}
/** checks if the event has free entry
* @return true if there is no entry
*/
//---------------------------------------
function hasFreeEntry(){
//---------------------------------------
$freeCategories = array(197); // "Ausstellung"
if (in_array($this->category1, $freeCategories) && $this->reservationType == RESERVATION_NONE) {
return true;
}
return false;
}
/** loads a cached version of all kulturcard reductions
* @return array with flexiconIds of kulturcard reductions
*/
//---------------------------------------
function getKulturcardReductionIds() {
//---------------------------------------
if (!isset($_SESSION['KULTURCARD_REDUCTION_IDS'])) {
$query = "SELECT i.id
FROM bruckm_index AS i
JOIN bruckm_ticketreduction AS r ON i.classId = r.id
WHERE i.class = 'TicketReduction'
AND r.type IN ('k', '+k', 'k%')";
$result = dbQuery($query);
$ids = array();
while ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$ids[] = $line['id'];
}
$_SESSION['KULTURCARD_REDUCTION_IDS'] = $ids;
}
return $_SESSION['KULTURCARD_REDUCTION_IDS'];
}
/** prints as list item in EventList
* @param listId id of the EventList
* @param alt flag for alternating template
* @return string
*/
//----------------------------------------
function publishForEventList($listId, $alt){
//----------------------------------------
$t = new Template(TEMPLATE_DIR."subparts/event$alt.html");
$t->setVar("ID", $listId);
$t->setVar("EVENT_ID", $this->id);
$t->setVar("TITLE", $this->titleHook(htmlspecialchars($this->name)));
if(!empty($this->thumb)){
$t->setVar("THUMB", $this->thumb);
}
else{
$t->setVar("THUMB", "default$alt.jpg");
}
if(substr($this->startDate, 0, 10) == substr($this->endDate, 0, 10)){
$t->setVar("DATE", datetime2dmy($this->startDate));
}
else{
$t->setVar("DATE", datetime2dmy($this->startDate)." bis ".datetime2dmy($this->endDate));
}
if (!$this->hasKulturcard()) {
$t->removeBlock("KULTURCARD");
}
if (!$this->hasFreeEntry()) {
$t->removeBlock("FREE_ENTRY");
}
return $t->toString();
}
/** prints as list item in IndexPage
* @param listId id of the target EventList
* @return string
*/
//----------------------------------------
function publishForIndexPage($listId){
//----------------------------------------
$t = new Template(TEMPLATE_DIR."subparts/event0.html");
$t->setVar("ID", $listId);
$t->setVar("EVENT_ID", $this->id);
$t->setVar("TITLE", $this->titleHook(htmlspecialchars($this->wrap($this->name, 25))));
if(!empty($this->thumb)){
$t->setVar("THUMB", $this->thumb);
}
else{
$t->setVar("THUMB", "default0.jpg");
}
if(substr($this->startDate, 0, 10) == substr($this->endDate, 0, 10)){
$t->setVar("DATE", datetime2dmy($this->startDate));
}
else{
$t->setVar("DATE", datetime2dmy($this->startDate)." bis ".datetime2dmy($this->endDate));
}
if (!$this->hasKulturcard()) {
$t->removeBlock("KULTURCARD");
}
if (!$this->hasFreeEntry()) {
$t->removeBlock("FREE_ENTRY");
}
return $t->toString();
}
/** prints the ticket reservation info box on the detail page
* @return string
*/
//-----------------------------------------------
function printInfoBox(){
//-----------------------------------------------
// hack for canceled russkaja show
if ($this->classId == 2042) {
return "<h1>".$this->titleHook(htmlspecialchars($this->name))."</h1>";
}
if(time() > strtotime($this->endDate) || !$this->visible){
return "<h1>".$this->titleHook(htmlspecialchars($this->name))."</h1>";
}
$t = new Template(TEMPLATE_DIR."subparts/ticketbox.html");
$t->setVar("TITLE", $this->titleHook(htmlspecialchars($this->name)));
if(!empty($this->thumb)){
$t->setVar("THUMB", $this->thumb);
}
else{
$t->setVar("THUMB", "default0.jpg");
}
if(datetime2dmy($this->startDate) == datetime2dmy($this->endDate)){
$t->setVar("DATE", datetime2dmy($this->startDate));
}
else{
$t->setVar("DATE", datetime2dmy($this->startDate)." bis ".datetime2dmy($this->endDate));
}
if($this->reservationType != RESERVATION_NONE){
$t->setVar("ID", $this->classId);
$entries = array_unique($this->entries);
$e = "";
foreach($entries as $i=>$j){
if($j){
$e .= sprintf('%d,-', $j);
$e .= " | ";
}
}
$e = substr($e, 0, strlen($e)-2);
$t->setVar("ENTRIES", $e);
}
else{
$t->removeBlock("RESERVATION");
}
return $t->toString();
}
/** wraps lines for too long words
*/
//-----------------------------------------------
function wrap($string, $maxline){
//-----------------------------------------------
$inWords = explode(" ", $string);
$outWords = array();
$currentLine = 0;
foreach($inWords as $i=>$word){
if($currentLine + strlen($word) > $maxline){
$breakWord = substr($word, 0, $maxline-$currentLine);
$break = $this->getBreakPosition($breakWord);
if($break >= 0){
array_push($outWords, substr($breakWord, 0, $break+1));
$breakWord = substr($word, $break+1);
}
else{
$breakWord = $word;
}
$break = $this->getBreakPosition(substr($breakWord, 0, $maxlength));
while($break != -1 && strlen($breakWord) > $maxline){
array_push($outWords, substr($breakWord, 0, $break+1));
$breakWord = substr($breakWord, $break+1);
$break = $this->getBreakPosition(substr($breakWord, 0, $maxline));
}
array_push($outWords, $breakWord);
$currentLine = strlen($breakWord);
if($currentLine > $maxline){
$currentLine = 0;
}
}
else{
$currentLine += strlen($word) + 1;
array_push($outWords, $word);
}
}
return implode(" ", $outWords);
}
/** returns a good position for breaking the word
*/
//---------------------------------
function getBreakPosition($word){
//---------------------------------
$pos = strrpos($word, "-");
if($pos !== false){
return $pos;
}
$pos = strrpos($word, "|");
if($pos !== false){
return $pos;
}
return -1;
}
/** assigns default values for owner id (logged in user) and house (based on owner)
* serves as convenience method
*/
//---------------------------------
function assignDefaultValues() {
//---------------------------------
$this->ownerId = intval($_SESSION['userid']);
$query = sprintf("SELECT * FROM bruckm_house WHERE defaultUserId = %d LIMIT 1", $this->ownerId);
$result = dbQuery($query);
if ($line = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$this->houseId = $line['id'];
}
}
/** returns all events with reservations
* @static
* @return array of events
*
//----------------------------------
function getEventsForReservation(){
//----------------------------------
$events = array();
$query = sprintf("SELECT flexiconId FROM bruckm_ticketevent
WHERE endDate >= NOW() AND reservationType > 0 AND visible = 1
ORDER BY endDate ASC");
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$event = FlexiconFactory::instanceById($line['flexiconId']);
$event->load();
$events[] = $event;
}
return $events;
}*/
function titleHook($title) {
if ($title == 'ROLAND D&Uuml;RINGER &quot;ICH Einleben&quot;') {
return 'ROLAND D&Uuml;RINGER &quot;<s>ICH</s> Einleben&quot;';
}
return $title;
}
};
?>