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

291 lines
8.4 KiB
PHP

<?php
require_once(ROOT."include/config.inc.php");
require_once(ROOT."include/error.inc.php");
require_once(ROOT."include/db.inc.php");
require_once(CMS_DIR."modules/-ticketcustomer.class.php");
/** Ticket
*
* @version 2.0.2
* @since 2007-03-29
* @author martin lenzelbauer
*
* @change 2007-08-18
* added serial number of "Kulturkarte" reductions
* changed mailText()
*
* @change 2007-09-24
* removed customer deletion
*/
class Ticket{
var $id; //db id
var $category; //a, b or c
var $reduction; //id of the reduction
var $serial; //serial number of "Kulturkarte" reductions
var $seat; //seat nr
var $row; //row nr
var $floor; //floor name
var $room; //room name
var $seatIndex; //seat index (in template)
var $rowIndex; //row index (in template)
var $floorIndex; //floor index (in template)
var $dateId; //id of the TicketDate the ticket belongs to
var $cutomerId; //id of the TicketCustomer the ticket belongs to
var $customer; //TicketCustomer
/** C'tor
*/
//------------------------------------------------
function Ticket($data=NULL, $dateId=NULL){
//------------------------------------------------
$this->id = 0;
//decode data string
if($data){
$data = explode("\t", $data);
$this->category = $data[0];
$this->reduction = $data[1];
$this->seat = $data[2];
$this->row = $data[3];
$this->floor = $data[4];
$this->room = $data[5];
$this->seatIndex = $data[6];
$this->rowIndex = $data[7];
$this->floorIndex = $data[8];
$this->serial = $data[9]; //optional; only for "Kulturkarte" reductions
$this->dateId = $dateId;
}
}
/** installs the table
*/
//------------------------------------------------
function install(){
//------------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_ticket (
id INT NOT NULL AUTO_INCREMENT,
category VARCHAR(2) NOT NULL,
reductionId INT NOT NULL,
cultureCardId INT NOT NULL,
orderId INT NULL NULL,
seat SMALLINT UNSIGNED NOT NULL,
row SMALLINT UNSIGNED NOT NULL,
floor VARCHAR(64) NOT NULL,
room VARCHAR(64) NOT NULL,
seatIndex SMALLINT UNSIGNED NOT NULL,
rowIndex SMALLINT UNSIGNED NOT NULL,
floorIndex SMALLINT UNSIGNED NOT NULL,
dateId INT UNSIGNED NOT NULL,
customerId INT UNSIGNED NOT NULL,
printed TINYINT(1) NOT NULL default 0,
PRIMARY KEY(id)
)");
dbQuery($query);
}
/** loads the ticket from the database
*/
//-----------------------------------------------
function load(){
//-----------------------------------------------
if($this->id == 0){
return;
}
$query = sprintf("SELECT * FROM bruckm_ticket WHERE id = %d", $this->id);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->category = $line['category'];
$this->reduction = $line['reduction'];
$this->seat = $line['seat'];
$this->row = $line['row'];
$this->floor = $line['floor'];
$this->room = $line['room'];
$this->seatIndex = $line['seatIndex'];
$this->rowIndex = $line['rowIndex'];
$this->floorIndex = $line['floorIndex'];
$this->customerId = $line['customerId'];
$this->dateId = $line['dateId'];
}
/** loads the customer
*/
//-----------------------------------------------
function loadCustomer(){
//-----------------------------------------------
$this->customer = new TicketCustomer($this->customerId);
$this->customer->load();
}
/** saves the seat to the database
*/
//-----------------------------------------------
function save(){
//-----------------------------------------------
$query = sprintf("INSERT INTO bruckm_ticket (category, reduction, seat, row, floor, room,
seatIndex, rowIndex, floorIndex, dateId, customerId)
VALUES (%s, %d, %d, %d, %s, %s, %d, %d, %d, %d, %d)",
sqlstring($this->category),
sqlnum($this->reduction),
sqlnum($this->seat),
sqlnum($this->row),
sqlstring($this->floor),
sqlstring($this->room),
sqlnum($this->seatIndex),
sqlnum($this->rowIndex),
sqlnum($this->floorIndex),
sqlnum($this->dateId),
sqlnum($this->customerId));
dbQuery($query);
$this->id = mysql_insert_id();
}
/** save that the ticket was printed
*/
//------------------------------------------------
function saveAsPrinted(){
//------------------------------------------------
if($this->id == 0){
logError(4, "Ticket cannot be saved as 'printed': id is 0", __FILE__, __LINE__);
return;
}
$query = sprintf("UPDATE bruckm_ticket SET printed = 1 WHERE id = %d", $this->getTable(), $this->id);
dbQuery($query);
}
/** deletes the ticket
* deletes the customer, if he has no other tickets
*/
//-----------------------------------------------
function delete(){
//-----------------------------------------------
$query = sprintf("DELETE FROM bruckm_ticket WHERE id = %d", $this->id);
dbQuery($query);
/*
//check if there are other tickets of the same customer
$query = sprintf("SELECT id FROM bruckm_ticket WHERE customerId = %d LIMIT 1",
sqlnum($this->customerId));
$result = dbQuery($query);
if(mysql_num_rows($result) == 0){
$this->loadCustomer();
echo "delete customer!<br>";
$this->customer->delete();
}
*/
}
/** checks if the ticket (= the seat) is still available
* @return true, if successful
*/
//-----------------------------------------------
function isAvailable(){
//-----------------------------------------------
$query = sprintf("SELECT id FROM bruckm_ticket WHERE dateId = %d AND floorIndex = %d AND rowIndex = %d
AND seatIndex = %d",
sqlnum($this->dateId),
sqlnum($this->floorIndex),
sqlnum($this->rowIndex),
sqlnum($this->seatIndex));
$result = dbQuery($query);
if(mysql_num_rows($result) == 0){
return true;
}
return false;
}
/** @see Object::toString()
*/
//-----------------------------------------------
function toString(){
//-----------------------------------------------
return "Ticket (".$this->id."): ".$this->category."/".$this->seat."/".$this->row."/".$this->floor.", dateId:".$this->dateId.", customerId: ".$this->customerId;
}
/** returns index information as xml node
* @return string
*/
//-----------------------------------------------
function toXml(){
//-----------------------------------------------
$xml = "<ticket seat=\"".$this->seat."\" row=\"".$this->row."\" floor=\"".$this->floor."\"";
$xml .= " floorIndex=\"".$this->floorIndex."\" rowIndex=\"".$this->rowIndex."\"";
$xml .= " seatIndex=\"".$this->seatIndex."\" category=\"".$this->category."\"";
$xml .= " reduction=\"".$this->reduction."\" id=\"".$this->id."\"";
if($this->customer){
$xml .= " >".$this->customer->toXml()."</ticket>";
}
else{
$xml .= " />";
}
return $xml;
}
/** returns a ticket description text for the confirmation e-mail
* @param reductions array of all reductions
* @param entries array with entries for all categories
* @return string
*/
//-----------------------------------------------
function mailText($reductions, $entries){
//-----------------------------------------------
$out = "";
if($this->seat == 0){
$out .= sprintf("Kategorie %s", strtoupper($this->category));
}
else{
$out .= sprintf("(%s) Platz %d, Reihe %d, %s",
strtoupper($this->category),
$this->seat,
$this->row,
$this->floor);
}
$r = trim($reductions[$this->reduction]->getName());
if($this->serial){
$r .= " #".$this->serial;
}
$out .= sprintf(" (%s)\tEur %s", $r, TicketReduction::moneyFormat($reductions[$this->reduction]->calcEntry($entries[$this->category])));
return $out;
}
/** sets the customer
*/
//-----------------------------------------------
function setCustomerId($id){
//-----------------------------------------------
$this->customerId = $id;
}
/** sets the id
*/
//-----------------------------------------------
function setId($id){
//-----------------------------------------------
$this->id = $id;
}
/** returns the id
*/
//-----------------------------------------------
function getId(){
//-----------------------------------------------
return $this->id;
}
};
?>