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!
"; $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 = "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().""; } 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; } }; ?>