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

579 lines
15 KiB
PHP

<?php
/** Event List
*
* @version 1.9.2
* @since 2007-06-01
* @author martin lenzelbauer
*
* @change 2007-06-09
* matched changes in TicketEvent (performance reasons)
*
* @change 2007-06-15
* fixed PHP4 bug in getMenu() and doPublish()
*
* @change 2012-01-18
* added house id
*/
class EventList extends Page{
var $category; //flexicon id of the event category
var $type; //current events or archive
var $template; //html template
var $houseId; //this list shows only events for the given house
/** C'tor
*/
//------------------------------------------------
function EventList($id, $parent){
//------------------------------------------------
parent::Page($id, $parent);
$this->name = "[Veranstaltungsliste]";
$this->category = 0;
$this->type = "current";
$this->houseId = 0;
$this->dynamic = true;
$this->buttonPreview = true;
$this->buttonPublish = true;
$this->template = "";
$this->editable = USER_ADMIN;
}
/** @see Page::install()
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_eventlist (
id INT NOT NULL AUTO_INCREMENT,
category INT UNSIGNED NOT NULL DEFAULT 0,
type ENUM('current','archive','artist') NOT NULL DEFAULT 'current',
template VARCHAR(100) NOT NULL DEFAULT '',
houseId INT NOT NULL DEFAULT 0,
PRIMARY KEY (id)
)");
dbQuery($query);
}
/** @see CmsObject::load()
*/
//-----------------------------------------------
function load($path=array()){
//-----------------------------------------------
parent::load($path);
if(!$this->classId){
return;
}
$query = sprintf("SELECT * FROM bruckm_eventlist WHERE id = %d", $this->classId);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->category = $line['category'];
$this->type = $line['type'];
$this->template = $line['template'];
$this->houseId = $line['houseId'];
}
/** @see Page::doSave()
*/
//----------------------------------------------
function doSave(){
//----------------------------------------------
$query = sprintf("UPDATE bruckm_eventlist SET category = %s, type = %s, template = %s, houseId = %d WHERE id = %d",
sqlstring($this->category),
sqlstring($this->type),
sqlstring($this->template),
sqlnum($this->houseId),
sqlnum($this->classId));
dbQuery($query);
parent::doSave();
}
/** @see Page::doCreate()
*/
//----------------------------------------------
function doCreate(){
//----------------------------------------------
$query = sprintf("INSERT INTO bruckm_eventlist (category) VALUES (%s)", sqlstring($this->category));
dbQuery($query);
$this->classId = mysql_insert_id();
parent::doCreate();
}
/** @see Page::doDelete()
*/
//-----------------------------------------------
function doDelete(){
//-----------------------------------------------
parent::doDelete();
$query = sprintf("DELETE FROM bruckm_eventlist WHERE id = %d LIMIT 1", $this->classId);
dbQuery($query);
}
/** @see CmsObject::update()
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
parent::update();
$this->category = $_POST['category'];
$this->type = $_POST['type'];
$this->houseId = $_POST['houseId'];
if(isset($_POST['template'])){
$this->template = $_POST['template'];
}
}
/** @see CmsObject::doPrintClassContent()
*/
//-----------------------------------------------
function doPrintClassContent(){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."eventlist.html");
$options = "<option value=\"0\">Alle</option>";
$query = sprintf("SELECT id,name FROM bruckm_index WHERE class = 'TicketCategory' ORDER BY name ASC");
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if($line['id'] == $this->category){
$options .= "<option value=\"$line[id]\" selected=\"selected\">".htmlspecialchars($line['name'])."</option>";
}
else{
$options .= "<option value=\"$line[id]\">".htmlspecialchars($line['name'])."</option>";
}
}
$t->setVar("CATEGORIES", $options);
if($this->type == "current"){
$t->setVar("TYPE_CURRENT", "selected=\"selected\"");
$t->setVar("TYPE_ARCHIVE", "");
$t->setVar("TYPE_ARTIST", "");
}
else if($this->type == "artist"){
$t->setVar("TYPE_ARTIST", "selected=\"selected\"");
$t->setVar("TYPE_ARCHIVE", "");
$t->setVar("TYPE_CURRENT", "");
}
else{
$t->setVar("TYPE_ARCHIVE", "selected=\"selected\"");
$t->setVar("TYPE_CURRENT", "");
$t->setVar("TYPE_ARTIST", "");
}
$templates = "";
$dir = opendir(TEMPLATE_DIR);
while($file = readdir($dir)){
if(is_file(TEMPLATE_DIR.$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);
if($this->isEditable()){
$t->setVar("TEMPLATE_DISABLED", "");
}
else{
$t->setVar("TEMPLATES_DISABLED", "disabled=\"disabled\"");
}
// houses
$query = sprintf("SELECT * FROM bruckm_house ORDER BY position ASC");
$result = dbQuery($query);
$houses = "";
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);
return $t->toString();
}
/** @see CmsObject::canBePublished()
*/
//----------------------------------------------
function canBePublished(){
//----------------------------------------------
if(empty($this->template)){
logError(3, "No template selected", __FILE__, __LINE__);
$this->addError("Bitte wählen Sie ein Template aus!");
return false;
}
return true;
}
/** @see CmsObject::publish()
*/
//---------------------------------------------
function doPublish(){
//---------------------------------------------
if(isset($_GET['event'])){
return $this->printEvent($_GET['event']);
}
$t = new Template(TEMPLATE_DIR.$this->template);
$content = "<h1>".$this->toString()."</h1>";
$content .= $this->printCustomerInfo();
$content .= $this->printCategories();
if($this->type == "current"){
$content .= $this->printCurrentEvents();
} else if($this->type == "artist"){
$content .= $this->printArtistEvents();
} else {
$content .= $this->printPastEvents();
}
$t->setVar("CONTENT", $content);
if(!$this->parentObj){
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
}
$parent = clone($this->parentObj);
$parent->load();
$t = $parent->printMenu($t);
$t->setVar("TITLE", $this->toString());
return $t->toString();
}
/** @see CmsObject::show()
*/
//------------------------------------------------
function show(){
//------------------------------------------------
if($this->canBePublished()){
return $this->doPublish();
}
}
/** @see CmsObject::getCssClass()
*/
//------------------------------------------------
function getCssClass(){
//------------------------------------------------
return "itemTicketEvent";
}
// === ADDITIONAL METHODS ============================================== //
/** prints a category selector
* @return string
*/
//------------------------------------------------
function printCategories(){
//------------------------------------------------
if(isset($_GET['category'])){
$category = $_GET['category'];
}
else{
$category = $this->category;
}
### BEGIN HACK: exclude events, tanz, seminar, kino ###
$query = sprintf("SELECT id,name FROM bruckm_index WHERE class = 'TicketCategory' AND id NOT IN (201, 203, 1993, 2041) ORDER BY name ASC");
### END HACK ###
$result = dbQuery($query);
$out = "<div>";
if($category == 0){
$out .= "<em>alle</em>";
}
else{
$out .= "<a href=\"?id=".$this->id."&amp;category=0\" target=\"_self\" class=\"sans\">alle</a>";
}
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$out .= " | ";
if($category == $line['id']){
$out .= "<em>".htmlspecialchars($line['name'])."</em>";
}
else{
$out .= "<a href=\"?id=".$this->id."&amp;category=$line[id]\" target=\"_self\" class=\"sans\">".htmlspecialchars($line['name'])."</a>";
}
}
### BEGIN HACK: add 'events' to the end of the list ###
$out .= " | ";
if($category == 203){
$out .= "<em>Event</em>";
}
else{
$out .= "<a href=\"?id=".$this->id."&amp;category=203\" target=\"_self\" class=\"sans\">Event</a>";
}
### END HACK ###
$out .= "</div><br />";
return $out;
}
/** prints a section with additional infos for customers
* @return string
*/
//------------------------------------------------
function printCustomerInfo(){
//------------------------------------------------
$t = new Template(TEMPLATE_DIR."subparts/events-info.html");
return $t->toString();
}
/** prints current events for the selected category
* @return string
*/
//----------------------------------------------
function printCurrentEvents(){
//----------------------------------------------
global $IGNORED_EVENTS; // see include/events.inc.php
if(isset($_GET['category'])){
$category = $_GET['category'];
}
else{
$category = $this->category;
}
$query = sprintf("SELECT flexiconId FROM bruckm_ticketevent WHERE endDate >= '%s' ", date("Y-m-d"));
if ($this->houseId != 0) {
$query .= sprintf("AND (houseId = %d OR houseId = 0) ", $this->houseId);
}
if ($category != 0) {
$query .= sprintf("AND (category1 = %d OR category2 = %d OR category3 = %d) ", sqlnum($category), sqlnum($category), sqlnum($category));
}
$query .= "ORDER BY startDate ASC, endDate DESC";
$result = dbQuery($query);
$out = "";
$i = 1;
$navi = "<div>";
$years = array();
$currYear = date ("Y");
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$event = FlexiconFactory::instanceById($line['flexiconId'], $this);
$event->load();
if($event->isVisible() && !in_array($line['flexiconId'], $IGNORED_EVENTS)){
$y = $event->getYear(true);
if ($y < $currYear) $y = $currYear;
if(!in_array($y, $years)){
$years[] = $y;
$out .= "<a id=\"y$y\"></a><h1>$y</h1>";
$navi .= "<a href=\"#y$y\" target=\"_self\">$y</a> | ";
}
$out .= $event->publishForEventList($this->id, $i%2);
$i++;
}
}
if (sizeof($years) > 1) {
$out = substr($navi, 0, strlen($navi)-2) . "</div>" . $out;
}
return $out;
}
/** prints past events for the selected category
* @return string
*/
//----------------------------------------------
function printPastEvents(){
//----------------------------------------------
if(isset($_GET['category'])){
$category = $_GET['category'];
}
else{
$category = $this->category;
}
$query = "SELECT flexiconId FROM bruckm_ticketevent WHERE endDate < NOW() ";
if ($this->houseId != 0) {
$query .= sprintf("AND (houseId = %d OR houseId = 0) ", $this->houseId);
}
if ($category != 0) {
$query .= sprintf("AND (category1 = %d OR category2 = %d OR category3 = %d) ", sqlnum($category), sqlnum($category), sqlnum($category));
}
$query .= "ORDER BY endDate DESC";
$result = dbQuery($query);
$out = "";
$navi = "<div>";
$i = 1;
$years = array();
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$event = FlexiconFactory::instanceById($line['flexiconId'], $this);
$event->load();
if($event->isVisible()){
$y = $event->getYear();
if(!in_array($y, $years)){
$years[] = $y;
$out .= "<a id=\"y$y\"></a><h1>$y</h1>";
$navi .= "<a href=\"#y$y\" target=\"_self\">$y</a> | ";
}
$out .= $event->publishForEventList($this->id, $i%2);
$i++;
}
}
$navi = substr($navi, 0, strlen($navi)-2) . "</div>";
$out = $navi . $out;
return $out;
}
/** prints past events for the selected category
* @return string
*/
//----------------------------------------------
function printArtistEvents(){
//----------------------------------------------
$excludeIds = array(
281,
339,
375,
379,
411,
423,
431,
437,
449,
459,
465,
471,
483,
489,
503,
507,
521,
557,
561,
655,
750,
807,
869,
899,
906,
987,
991,
1083,
1093,
1095,
1137,
1308,
1310,
1425,
1448,
1595,
1598,
1643,
1671,
1723,
1751,
1756,
1770,
1805,
1817,
1892,
1926,
1941,
1956,
2156,
2173,
2178,
2193,
2205,
2214,
2236
);
if(isset($_GET['category'])){
$category = $_GET['category'];
}
else{
$category = $this->category;
}
$query = "SELECT flexiconId FROM bruckm_ticketevent WHERE endDate < NOW() ";
if ($this->houseId != 0) {
$query .= sprintf("AND (houseId = %d OR houseId = 0) ", $this->houseId);
}
if ($category != 0) {
$query .= sprintf("AND (category1 = %d OR category2 = %d OR category3 = %d) ", sqlnum($category), sqlnum($category), sqlnum($category));
}
$query .= "ORDER BY endDate DESC";
$result = dbQuery($query);
$out = "";
$navi = "<div>";
$i = 1;
$years = array();
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if (!in_array($line['flexiconId'], $excludeIds)) {
$event = FlexiconFactory::instanceById($line['flexiconId'], $this);
$event->load();
if($event->isVisible()){
$y = $event->getYear();
if(!in_array($y, $years)){
$years[] = $y;
$out .= "<a id=\"y$y\"></a><h1>$y</h1>";
$navi .= "<a href=\"#y$y\" target=\"_self\">$y</a> | ";
}
$out .= $event->publishForEventList($this->id, $i%2);
$i++;
}
}
}
$navi = substr($navi, 0, strlen($navi)-2) . "</div>";
$out = $navi . $out;
return $out;
}
/** prints single view of an event
* @param id event id
* @return string
*/
//-------------------------------------------------
function printEvent($id){
//-------------------------------------------------
$event = FlexiconFactory::instanceById($id, $this);
if (!$event) {
header('Location: http://www.bruckmuehle.at');
exit;
}
$event->load();
return $event->show();
}
/** returns the name of the template file
* @return template
*/
//-----------------------------------------------
function getTemplate(){
//-----------------------------------------------
return $this->template;
}
/** returns the Menu object
* @return Menu
*/
//-----------------------------------------------
function getMenu(){
//-----------------------------------------------
if(!$this->parentObj){
$this->parentObj = FlexiconFactory::instanceById($this->parentId);
}
$parent = clone($this->parentObj);
$parent->load();
return $parent;
}
};
?>