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

395 lines
11 KiB
PHP

<?php
require_once(ROOT."include/config.inc.php");
/** Ticket Date
*
* @version 2.1.0
* @since 2007-04-29
* @author martin lenzelbauer
*
* @change 2008-02-14
* replaced room flexicon id by room class id
* changed hasReservations() -> search for orders now
*/
class TicketDate{
var $id; //id
var $eventId; //if of the event
var $event; //TicketEvent object
var $date; //datetime
var $entries; //array of entries
var $reductions; //array of reductions
var $room; //class id of the room or room name
var $seats; //number of seats
/** C'tor
*/
//------------------------------------------------
function TicketDate($id=0, $event=NULL){
//------------------------------------------------
$this->id = $id;
$this->event = $event;
if($event){
$this->eventId = $event->getClassId();
}
$this->date = "";
$this->entries = array();
$this->reductions = array();
$this->room = "";
$this->seats = 0;
}
/** loads the data
*/
//-----------------------------------------------
function load(){
//-----------------------------------------------
$query = sprintf("SELECT * FROM bruckm_ticketdate WHERE id = %d", $this->id);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->date = $line['date'];
$this->eventId = $line['eventId'];
$this->entries = explode("\t", $line['entries']);
$this->reductions = explode("\t", $line['reductions']);
$this->room = $line['room'];
$this->seats = $line['seats'];
}
/** saves the data
*/
//-------------------------------------------------
function save(){
//-------------------------------------------------
if($this->id){
$this->doSave();
}
else{
$this->id = $this->doCreate();
}
}
/** upadtes the database
*/
//-------------------------------------------------
function doSave(){
//-------------------------------------------------
$query = sprintf("UPDATE bruckm_ticketdate SET `date` = %s, eventId = %d,
entries = %s, reductions = %s, room = %s, seats = %d
WHERE id = %d",
sqlstring($this->date),
sqlnum($this->eventId),
sqlstring(implode("\t", $this->entries)),
sqlstring(implode("\t", $this->reductions)),
sqlstring($this->room),
sqlnum($this->seats),
$this->id);
dbQuery($query);
}
/** creates a new database entry
*/
//-------------------------------------------------
function doCreate(){
//-------------------------------------------------
$query = sprintf("INSERT INTO bruckm_ticketdate (eventId, `date`, entries, reductions)
VALUES (%d, %s, %s, %s)",
sqlnum($this->eventId),
sqlstring($this->date),
sqlstring(implode("\t", $this->entries)),
sqlstring(implode("\t", $this->reductions)));
dbQuery($query);
return mysql_insert_id();
}
/** deletes the date and all reservations
*/
//-----------------------------------------------
function delete(){
//-----------------------------------------------
$query = sprintf("SELECT id FROM bruckm_ticket WHERE dateId = %d", $this->id);
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$t = new Ticket($line['id']);
$t->load();
$t->delete();
}
$query = sprintf("DELETE FROM bruckm_ticketdate WHERE id = %d", $this->id);
dbQuery($query);
}
/** installs the table
*/
//-----------------------------------------------
function install(){
//-----------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_ticketdate(
id INT NOT NULL AUTO_INCREMENT,
`date` DATETIME NULL,
eventId INT NOT NULL,
entries VARCHAR(32) NULL,
reductions VARCHAR(255) NULL,
room VARCHAR(50) NOT NULL DEFAULT '',
seats INT UNSIGNED NOT NULL DEFAULT 0,
PRIMARY KEY (id)
)");
dbQuery($query);
}
/** updates the data
*/
//-----------------------------------------------
function update(){
//-----------------------------------------------
$this->date = createDatetime($_POST["date_day".$this->id],
$_POST["date_month".$this->id],
$_POST["date_year".$this->id],
$_POST["date_hour".$this->id],
$_POST["date_min".$this->id]);
for($i=0; $i<3; $i++){
$this->entries[$i] = $_POST["date_entry$i".$this->id];
}
if(isset($_POST["date_reductions".$this->id])){
$this->reductions = $_POST["date_reductions".$this->id];
}
if(isset($_POST["date_room".$this->id])){
$this->room = $_POST["date_room".$this->id];
}
if(isset($_POST["date_seats".$this->id])){
$this->seats = $_POST["date_seats".$this->id];
}
}
/** prints the content
*/
//-----------------------------------------------
function printContent($position){
//-----------------------------------------------
$t = new Template(CMS_TEMPLATE_DIR."ticketdate.html");
$t->setVar("ID", $this->id);
$t->setVar("POSITION", $position);
//date
$t->setVar("DAY", datetimeGet($this->date, "d"));
$t->setVar("MONTH", datetimeGet($this->date, "m"));
$t->setVar("YEAR", datetimeGet($this->date, "Y"));
$t->setVar("HOUR", datetimeGet($this->date, "H"));
$t->setVar("MIN", datetimeGet($this->date, "i"));
//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=\"date_reductions".$this->id."[]\" value=\"$line[id]\" ";
if(in_array($line['id'], $this->reductions)){
$reductions .= "checked=\"checked\"";
}
$reductions .= " />" . htmlspecialchars($r->getShortInfo()) . "<br />";
}
$t->setVar("REDUCTIONS", $reductions);
//simple reservation only
if($this->event->getReservationType() == RESERVATION_SIMPLE){
$t->removeBlock("SEAT");
$t->removeBlock("TABLE");
$t->setVar("ROOM", htmlspecialchars($this->room));
$t->setVar("SEATS", $this->seats);
}
//seat reservation only
else if($this->event->getReservationType() == RESERVATION_SEAT){
$t->removeBlock("SIMPLE");
$t->removeBlock("TABLE");
$query = sprintf(
"SELECT i.classId, i.name
FROM bruckm_index AS i
JOIN bruckm_ticketroom AS tr ON tr.id = i.classId
WHERE i.class = 'TicketRoom'
AND tr.type = 'seat'
ORDER BY i.name ASC"
);
$result = dbQuery($query);
$rooms = "";
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
if($this->room == $line['classId']){
$rooms .= "<option value=\"$line[classId]\" selected=\"selected\">".htmlspecialchars($line['name'])."</option>";
}
else{
$rooms .= "<option value=\"$line[classId]\">".htmlspecialchars($line['name'])."</option>";
}
}
$t->setVar("ROOMS", $rooms);
if($this->hasReservations()){
$t->setVar("ROOM_DISABLED", "disabled=\"disabled\"");
}
else{
$t->setVar("ROOM_DISABLED", "");
}
}
// table reservation
else if($this->event->getReservationType() == RESERVATION_TABLE){
$t->removeBlock("SEAT");
$t->removeBlock("SIMPLE");
}
return $t->toString();
}
/** checks if the given data is valid
*/
//----------------------------------------------
function isValid(){
//----------------------------------------------
$ok = true;
if(!ereg("^[0-9]{4}[-][0-9]{2}[-][0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}$", $this->date) || ereg("^0000-00-00 00:00:00$", $this->date)){
logError(3, "Invalid date in TicketDate: ".$this->date, __FILE__, __LINE__);
$ok = false;
}
if(sizeof($this->reductions) == 0){
logError(3, "No reduction selected", __FILE__, __LINE__);
$ok = false;
}
if(strlen($this->entries[0]) == 0){
logError(3, "No entry given", __FILE__, __LINE__);
$ok = false;
}
if($this->event->getReservationType() == RESERVATION_SEAT && $this->room == 0){
logError(3, "No room selected", __FILE__, __LINE__);
$ok = false;
}
return $ok;
}
/** copies the entries from the event
* @param array with entries
*/
//-----------------------------------------
function setEntries($entries){
//-----------------------------------------
foreach($entries as $i=>$j){
$this->entries[$i] = $j;
}
}
/** copies the reductions from the event
* @param array with reductions
*/
//-----------------------------------------
function setReductions($reductions){
//-----------------------------------------
foreach($reductions as $i=>$j){
$this->reductions[$i] = $j;
}
}
/** sets the initial date
* @param datetime
*/
//----------------------------------------
function setDate($date){
//----------------------------------------
$this->date = $date;
}
/** writes date into xml
* @param allReductions true to return all reductions
* false to return only the date's reductions [default]
* @return string
*/
//----------------------------------------
function toXml($allReductions=false){
//----------------------------------------
$xml = "<date id=\"".$this->id."\" datetime=\"".datetime2dmyhi($this->date)."\" ";
$xml .= "room=\"".$this->room."\" roomid=\"".$this->room."\" roomseats=\"".$this->seats."\" ";
$xml .= "a=\"".$this->entries[0]."\" ";
if(sizeof($this->entries) > 1){
$xml .= "b=\"".$this->entries[1]."\" ";
if(sizeof($this->entries) > 2){
$xml .= "c=\"".$this->entries[2]."\" ";
}
}
$xml .= ">";
if($allReductions){
$query = sprintf("SELECT id FROM bruckm_index WHERE class = 'TicketReduction' ORDER BY name ASC");
$result = dbQuery($query);
while($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$r = FlexiconFactory::instanceById($line['id']);
$r->load();
$xml .= $r->toXml();
}
}
else{
foreach($this->reductions as $i){
$r = FlexiconFactory::instanceById($i);
$r->load();
$xml .= $r->toXml();
}
}
$xml .= "</date>";
return $xml;
}
/** checks if there are already reservations for this date
* @return true if there are reservations saved for this date
*/
//----------------------------------------------
function hasReservations(){
//----------------------------------------------
$query = sprintf("SELECT id FROM bruckm_ticketorder WHERE dateId = %d LIMIT 1", $this->id);
$result = dbQuery($query);
if(mysql_num_rows($result) > 0){
return true;
}
return false;
}
/** checks if the date is in the future
* @return true if in future
*/
//---------------------------------------
function isInFuture(){
//---------------------------------------
return compareDates($this->date, date("Y-m-d h:i:s")) >= 0;
}
/** returns the id
* @return number
*/
//--------------------------------------
function getId(){
//--------------------------------------
return $this->id;
}
/** @see Object::toString()
*/
//-------------------------------------
function toString(){
//-------------------------------------
return datetime2dmyhi($this->date);
}
};
?>