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

419 lines
12 KiB
PHP

<?php
/** Ticket Event Container
*
* @version 1.9.2
* @since 2007-05-01
* @author martin lenzelbauer
*
* @change 2007-06-09
* matched changes in TicketEvent (performance reasons)
*
* @change 2007-06-18
* changed load() due to changes in Container
*/
class TicketEventContainer extends Container{
var $category; //flexicon id of the category or '0' for all categories
var $period; //0 = all, 1 = future, -1 = past
var $searchTerm; //search term
/** C'tor
*/
//-----------------------------------------------
function TicketEventContainer($id=0, $parent=NULL){
//-----------------------------------------------
parent::Container($id, $parent);
$this->name = "Veranstaltungen";
$this->objectsClass = "TicketEvent";
$this->allowedChildObjects = array("ticketevent");
$this->category = 0;
$this->period = 1;
$this->searchTerm = "";
$this->allowedProperties = array("name", "startDate", "visible");
$this->propertyLabels = array("Titel", "Datum", "veröffentlicht");
}
/** @see CmsObject::load()
*/
//-----------------------------------------------
function load($path=array()){
//-----------------------------------------------
//load nothing
if(sizeof($path) == 0){
return;
}
//load container settings
$query = sprintf("SELECT * FROM bruckm_container WHERE container = %s AND user = %s",
sqlstring(get_class($this)),
sqlstring($_SESSION['user']));
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->order = $line['order'];
if(substr($line['property'], 0, 4) == "sort"){
$properties = explode(",", substr($line['property'], 5));
$this->property = $properties[0];
$this->category = $properties[1];
$this->period = $properties[2];
}
else{
$this->searchTerm = substr($line['property'], 7);
}
//load only current event
if(sizeof($path) > 1){
$this->childObjects = array();
$query = sprintf("SELECT id FROM bruckm_index WHERE class = %s AND id = %d",
sqlstring($this->objectsClass),
sqlnum($path[1]));
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$this->childObjects[] = FlexiconFactory::instanceById($line['id'], $this);
}
}
//load all events
else if(sizeof($path) > 0 && $path[0] == $this->id){
$this->updateSortingSettings();
$this->childObjects = array();
if(!empty($this->searchTerm)){
$this->doSearchEvents();
}
else{
$this->doLoadEvents();
}
}
//load event data
if(sizeof($path) > 0 && $path[0] == $this->id){
array_shift($path);
foreach($this->childObjects as $i=>$child){
$this->childObjects[$i]->load($path);
}
}
#$this->sort();
}
/** @see Container::install()
*/
//----------------------------------------------
function install(){
//----------------------------------------------
parent::install();
$query = sprintf("SELECT * FROM bruckm_container WHERE container = %s",
sqlstring(get_class()));
$result = dbQuery($query);
if(mysql_num_rows($result) > 0){
return;
}
$query = sprintf("INSERT INTO bruckm_container (container, property, `order`) VALUES (%s, %s, %s)",
sqlstring(get_class()),
sqlstring("name"),
sqlstring("ASC"));
dbQuery($query);
}
/** @see Container::updateSortingSettings()
*/
//-----------------------------------------------
function updateSortingSettings(){
//-----------------------------------------------
$property = "";
$this->order = $_POST['order'];
if(isset($_POST['container_submit'])){
$this->property = $_POST['property'];
$this->category = $_POST['category'];
$this->period = $_POST['period'];
$this->searchTerm = "";
$property = "sort=".$this->property.",".$this->category.",".$this->period;
}
else if(isset($_POST['container_search'])){
$this->searchTerm = $_POST['searchTerm'];
$property = "search=".$this->searchTerm;
}
if(!empty($property)){
$query = sprintf("INSERT INTO bruckm_container (container, user, property, `order`) VALUES (%s, %s, %s, %s)
ON DUPLICATE KEY UPDATE property = %s, `order` = %s",
sqlstring(get_class($this)),
sqlstring($_SESSION['user']),
sqlstring($property),
sqlstring($this->order),
sqlstring($property),
sqlstring($this->order));
dbQuery($query);
}
}
/** @see CmsObject::printContent();
*/
//-----------------------------------------------
function printContent(){
//-----------------------------------------------
$out = $this->doPrintErrors();
$out .= $this->doPrintMetadata();
$categories = array();
$out .= $this->doPrintInsertBar(0);
if(!empty($this->searchTerm)){
$out .= $this->doPrintSearchResults();
}
else{
$out .= $this->doPrintEventList();
}
$out .= $this->doPrintInsertBar(0);
return $out;
}
/** @see CmsObject:doPrintMetadata()
*/
//-----------------------------------------------
function doPrintMetadata(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."ticketeventcontainer1.html");
$t->setVar("NAME", htmlspecialchars($this->name));
//standard properties
$p = "";
foreach($this->allowedProperties as $i=>$prop){
if($prop == $this->property){
$p .= "<option value=\"$prop\" selected=\"selected\">";
}
else{
$p .= "<option value=\"$prop\">";
}
$p .= htmlspecialchars($this->propertyLabels[$i])."</option>";
}
$t->setVar("PROPERTIES", $p);
if($this->order == "ASC"){
$t->setVar("ORDER_ASC", "selected=\"selected\"");
$t->setVar("ORDER_DESC", "");
}
else{
$t->setVar("ORDER_DESC", "selected=\"selected\"");
$t->setVar("ORDER_ASC", "");
}
//categories
$query = sprintf("SELECT id,name FROM bruckm_index WHERE class = 'TicketCategory' ORDER BY name ASC");
$result = dbQuery($query);
$c = "<option value=\"0\">alle</option>";
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if($line['id'] == $this->category){
$c .= "<option value=\"$line[id]\" selected=\"selected\">".htmlspecialchars($line['name'])."</option>";
}
else{
$c .= "<option value=\"$line[id]\">".htmlspecialchars($line['name'])."</option>";
}
}
$t->setVar("CATEGORIES", $c);
//periods
$p = "<option value=\"0\">alle</option>";
if($this->period == 1){
$p .= "<option value=\"1\" selected=\"selected\">aktuell</option>";
}
else{
$p .= "<option value=\"1\">aktuell</option>";
}
if($this->period == -1){
$p .= "<option value=\"-1\" selected=\"selected\">vergangen</option>";
}
else{
$p .= "<option value=\"-1\">vergangen</option>";
}
$t->setVar("PERIODS", $p);
return $t->toString();
}
/** @see CmsObject::handleAction()
*/
//---------------------------------------------
function handleAction($action, $position, $type){
//---------------------------------------------
return;
}
/** @see CmsObject::getCssClass()
*/
//-----------------------------------------------
function getCssClass(){
//-----------------------------------------------
return "itemTicketEvent";
}
/** @see Container::compare()
*/
//---------------------------------------------
function compare($obj1, $obj2){
//---------------------------------------------
$c1 = $obj1->getCategoryName();
$c2 = $obj2->getCategoryName();
$result = strcmp($c1, $c2);
if($result != 0){
return $result;
}
switch($this->property){
case "name":
$result = strcasecmp($obj1->getName(), $obj2->getName());
break;
case "lastUpdate":
$d1 = strtotime($obj1->getLastUpdate());
$d2 = strtotime($obj2->getLastUpdate());
if($d1 < $d2) $result = -1;
else $result = 1;
break;
case "id":
$id1 = strtotime($obj1->getId());
$id2 = strtotime($obj2->getId());
if($id1 < $id2) $result = -1;
else $result = 1;
break;
case "visible":
$v1 = $obj1->isVisible();
$v2 = $obj2->isVisible();
if($v1 < $v2) $result = -1;
else $result = 1;
break;
case "startDate":
$d1 = $obj1->getStartDate();
$d2 = $obj2->getStartDate();
$result = compareDates($d1, $d2);
break;
}
if($this->order == "DESC"){
$result = -$result;
}
return $result;
}
// === ADDITIONAL METHODS ================================================================= //
/** searches for events
*/
//----------------------------------------------
function doSearchEvents(){
//----------------------------------------------
$query = sprintf("SELECT flexiconId FROM bruckm_ticketevent
WHERE name LIKE %s
ORDER BY category1 ASC, name ASC",
sqlstring("%".$this->searchTerm."%"));
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$this->childObjects[] = FlexiconFactory::instanceById($line['flexiconId'], $this);
}
}
/** loads all events matching the filter criteria
*/
//----------------------------------------------
function doLoadEvents(){
//----------------------------------------------
$query = "SELECT flexiconId FROM bruckm_ticketevent ";
$where = 0;
//single category or all categories
if($this->category != 0){
$c = $this->category;
$query .= "WHERE (category1 = $c OR category2 = $c OR category3 = $c) ";
$where++;
}
//future or past events
if($this->period != 0){
if($this->period > 0){
if($where > 0){
$query .= "AND (endDate >= '" . date("Y-m-d") . "') ";
}
else{
$query .= "WHERE (endDate >= '" . date("Y-m-d") . "') ";
}
}
else{
if($where > 0){
$query .= "AND (endDate < '" . date("Y-m-d") . "') ";
}
else{
$query .= "WHERE (endDate < '" . date("Y-m-d") . "') ";
}
}
$where++;
}
//order: name, start date or visibility
$query .= "ORDER BY category1 ASC, ".$this->property." ".$this->order;
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$this->childObjects[] = FlexiconFactory::instanceById($line['flexiconId'], $this);
}
}
/** lists all search results
* @return string
*/
//----------------------------------------------
function doPrintSearchResults(){
//----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."ticketeventcontainer2.html");
$t->setVar("TITLE", htmlspecialchars(sizeof($this->childObjects)." Ergebnisse für den Suchbegriff '".$this->searchTerm."'"));
$events = "";
foreach($this->childObjects as $i=>$child){
$events .= $this->childObjects[$i]->printChildContent();
}
$t->setVar("EVENTS", $events);
return $t->toString();
}
/** lists all events, sorted by category
* @return string
*/
//----------------------------------------------
function doPrintEventList(){
//----------------------------------------------
//print single category view
if($this->category != 0){
$t = new Template(CMS_TEMPLATE_DIR."ticketeventcontainer2.html");
$c = FlexiconFactory::instanceById($this->category);
$c->load();
$t->setVar("TITLE", $c->toString());
$events = "";
foreach($this->childObjects as $i=>$child){
$events .= $this->childObjects[$i]->printChildContent();
}
$t->setVar("EVENTS", $events);
return $t->toString();
}
//print all categories
$out = "";
$categories = array();
foreach($this->childObjects as $i=>$child){
if(!in_array($child->getCategoryId(), $categories)){
$categories[] = $child->getCategoryId();
if($t){
$t->setVar("EVENTS", $events);
$out .= $t->toString();
}
$t = new Template(CMS_TEMPLATE_DIR."ticketeventcontainer2.html");
$t->setVar("TITLE", $child->getCategoryName());
$events = "";
}
$events .= $this->childObjects[$i]->printChildContent();
}
if($t){
$t->setVar("EVENTS", $events);
$out .= $t->toString();
}
return $out;
}
};
?>