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

316 lines
9.0 KiB
PHP

<?php
/** TicketCustomer
* someone who bought a ticket
*
* @version 2.1.1
* @since 2007-03-29
* @author martin lenzelbauer
*
* @change 2007-09-24
* due to customer statistics all information is held in the table bruckm_ticketcustomer,
* the customers are not deleted and the table bruckm_customer is not used anymore
*
* @change 2007-11-15
* added creation date
* changed install() and save()
*/
class TicketCustomer{
var $firstname;
var $surname;
var $email;
var $address;
var $zip;
var $city;
var $country;
var $phone;
var $acad;
var $gender;
var $currentEvent;
var $currentGenre;
var $GENDER_M = "m";
var $GENDER_F = "f";
var $GENDER_X = "x";
/** C'tor
*/
//------------------------------------------------
function TicketCustomer($id=0){
//------------------------------------------------
$this->id = $id;
}
/** reads person data from $_POST array
*/
//------------------------------------------------
function fromPost(){
//------------------------------------------------
$this->firstname = utf8_decode($_POST["pFirstname"]);
$this->surname = utf8_decode($_POST["pSurname"]);
$this->email = utf8_decode($_POST["pEmail"]);
$this->address = utf8_decode($_POST["pAddress"]);
$this->zip = utf8_decode($_POST["pZip"]);
$this->city = utf8_decode($_POST["pCity"]);
$this->country = utf8_decode($_POST["pCountry"]);
$this->phone = utf8_decode($_POST["pPhone"]);
$this->acad = utf8_decode($_POST["pAcad"]);
$this->gender = utf8_decode($_POST["pGender"]);
$this->currentEvent = utf8_decode($_POST['eventTitle']);
//load genre
$query = sprintf("SELECT eventId FROM bruckm_ticketdate WHERE id = %d", $_POST['dateID']);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$query = sprintf("SELECT genre FROM bruckm_ticketevent WHERE flexiconId = %d LIMIT 1", $line['eventId']);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->currentGenre = $line['genre'];
}
/** installs the table
*/
//------------------------------------------------
function install(){
//------------------------------------------------
$query = sprintf("CREATE TABLE IF NOT EXISTS bruckm_ticketcustomer (
id INT NOT NULL AUTO_INCREMENT,
firstname VARCHAR(64) NOT NULL,
surname VARCHAR(64) NOT NULL,
email VARCHAR(255) NOT NULL,
gender VARCHAR(1) NOT NULL DEFAULT 'x',
address VARCHAR(128) NOT NULL,
zip SMALLINT NOT NULL,
city VARCHAR(64) NOT NULL,
country VARCHAR(32) NOT NULL,
phone VARCHAR(24) NOT NULL,
acad VARCHAR(16) NOT NULL,
eventCount INT NOT NULL DEFAULT 1,
events TEXT,
genres TEXT,
creationDate DATE,
newsletter ENUM ('no','yes') DEFAULT 'yes',
PRIMARY KEY(id),
INDEX(email),
INDEX(surname),
INDEX(firstname)
)");
dbQuery($query);
}
/** saves the customer to the database
*/
//-----------------------------------------------
function save(){
//-----------------------------------------------
if(empty($this->surname)){
return;
}
//create new customer
if($this->id == 0){
//check if newsletter is disabled for this e-mail address
$newsletter = "yes";
$query = sprintf("SELECT id FROM bruckm_ticketcustomer WHERE email = %s AND newsletter = 'no' LIMIT 1",
sqlstring($this->email));
$result = dbQuery($query);
if(mysql_num_rows($result) > 0){
$newsletter = "no";
}
//insert into database
$query = sprintf("INSERT INTO bruckm_ticketcustomer
(firstname, surname, email, gender, address, zip, city, country, phone, acad, events, genres, creationDate, newsletter)
VALUES (%s, %s, %s, %s, %s, %d, %s, %s, %s, %s, %s, %s, NOW(), %s)",
sqlstring($this->firstname),
sqlstring($this->surname),
sqlstring($this->email),
sqlstring($this->gender),
sqlstring($this->address),
sqlnum($this->zip),
sqlstring($this->city),
sqlstring($this->country),
sqlstring($this->phone),
sqlstring($this->acad),
sqlstring($this->currentEvent),
sqlstring($this->currentGenre),
sqlstring($newsletter));
dbQuery($query);
$this->id = mysql_insert_id();
}
//update existing customer
else{
$query = sprintf("SELECT * FROM bruckm_ticketcustomer WHERE id = %d", $this->id);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$zip = $line['zip'];
$city = $line['city'];
$address = $line['address'];
$phone = $line['phone'];
$acad = $line['acad'];
if($zip != $this->zip && !empty($this->zip)) $zip = $this->zip;
if($city != $this->city && !empty($this->city)) $city = $this->city;
if($address != $this->address && !empty($this->address)) $address = $this->address;
if($phone != $this->phone && !empty($this->phone)) $phone = $this->phone;
if($acad != $this->acad && !empty($this->acad)) $acad = $this->acad;
$query = sprintf("UPDATE bruckm_ticketcustomer SET zip = %d, city = %s, address = %s, phone = %s, acad = %s,
eventCount = eventCount+1, events = CONCAT(%s, events), genres = CONCAT(%s, genres) WHERE id = %d",
sqlnum($zip),
sqlstring($city),
sqlstring($address),
sqlstring($phone),
sqlstring($acad),
sqlstring($this->currentEvent.", "),
sqlstring($this->currentGenre.","),
sqlnum($this->id));
dbQuery($query);
}
}
/** loads data from database
*/
//-----------------------------------------------
function load(){
//-----------------------------------------------
if($this->id == 0){
return;
}
$query = sprintf("SELECT firstname,surname FROM bruckm_ticketcustomer WHERE id = %d",
$this->id);
$result = dbQuery($query);
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
$this->firstname = $line['firstname'];
$this->surname = $line['surname'];
}
/** deletes the customer
*/
//-----------------------------------------------
function delete(){
//-----------------------------------------------
$query = sprintf("DELETE FROM bruckm_ticketcustomer WHERE id = %d", $this->id);
dbQuery($query);
}
/** looks if the customer is already in the database and loads id
* @return true, if the customer is in the database
*/
//-----------------------------------------------
function findInDatabase(){
//-----------------------------------------------
$query = sprintf("SELECT id FROM bruckm_ticketcustomer WHERE email = %s AND surname = %s AND firstname = %s LIMIT 1",
sqlstring($this->email),
sqlstring($this->surname),
sqlstring($this->firstname));
$result = dbQuery($query);
if($line = mysqli_fetch_array($result, MYSQLI_ASSOC)){
$this->id = $line['id'];
#$this->load();
return true;
}
return false;
}
/** returns person data as xml
* @return xml string
*/
//----------------------------------------------
function toXml(){
//----------------------------------------------
$xml = "<person id=\"".$this->id."\" firstname=\"".$this->firstname."\" surname=\"".$this->surname."\" />";
return $xml;
}
/** returns the db id
* @return id
*/
//-----------------------------------------------
function getId(){
//-----------------------------------------------
return $this->id;
}
/** returns the e-mail address
* @return e-mail
*/
//-----------------------------------------------
function getEmail(){
//-----------------------------------------------
return $this->email;
}
/** returns the customer's gender
* @return gender
*/
//-----------------------------------------------
function getGender(){
//-----------------------------------------------
return $this->gender;
}
/** checks if the person has an academic title
* @return true, if title
*/
//-----------------------------------------------
function hasAcademicTitle(){
//-----------------------------------------------
return !empty($this->acad);
}
/** returns the academic title
* @return title
*/
//-----------------------------------------------
function getAcademicTitle(){
//-----------------------------------------------
return $this->acad;
}
/** return firstname
* @return firstname
*/
//-----------------------------------------------
function getFirstname(){
//-----------------------------------------------
return $this->fisrtname;
}
/** return surname
* @return surname
*/
//-----------------------------------------------
function getSurname(){
//-----------------------------------------------
return $this->surname;
}
/** return firstname + surname
* @return name
*/
//-----------------------------------------------
function getFullName(){
//-----------------------------------------------
return $this->firstname." ".$this->surname;
}
};
?>