285 lines
7.4 KiB
PHP
285 lines
7.4 KiB
PHP
<?php
|
|
|
|
/** Ticket Reduction
|
|
*
|
|
* @version 2.3.0
|
|
* @since 2007-02-16
|
|
* @author martin lenzelbauer
|
|
*
|
|
* @change 2008-02-14
|
|
* added type KULTURCARD
|
|
*
|
|
* @change 2008-06-12
|
|
* added type VOUCHER
|
|
*
|
|
* @change 2009-07-31
|
|
* added type ZEITORTECARD
|
|
*/
|
|
class TicketReduction extends TicketObject{
|
|
|
|
var $value; // value of the reduction
|
|
var $type; // - ... entry = entry minus [value]
|
|
// % ... entry = [value] percent of entry
|
|
// = ... entry = {value]
|
|
// 0 ... entry = 0 (for [value] tickets)
|
|
// k ... entry = 0 (for [value] tickets) == KULTURCARD
|
|
// z ... entry = 0 (for Zeitorte partners) == ZEITORTECARD
|
|
// v ... entry = [value] percent of entry == VOUCHER
|
|
// + ... entry = [value] == KOMBITICKET
|
|
// +k .. entry = [value] == KOMBITICKET + KULTURCARD
|
|
// k% .. entry = [value] percent of entry with KULTURCARD
|
|
// 14d . entry = [value] until 14 days before event
|
|
|
|
/** C'tor
|
|
*/
|
|
//------------------------------------------------
|
|
function TicketReduction($id, $parent){
|
|
//------------------------------------------------
|
|
parent::TicketObject($id, $parent);
|
|
$this->name = "[unbenannte Ermäßigung]";
|
|
$this->value = 0;
|
|
$this->type = "-";
|
|
$this->buttonDelete = true;
|
|
}
|
|
|
|
|
|
/** @see CmsObject::load()
|
|
*/
|
|
//-----------------------------------------------
|
|
function load($path=array()){
|
|
//-----------------------------------------------
|
|
parent::load($path);
|
|
if(!$this->classId){
|
|
return;
|
|
}
|
|
$query = sprintf("SELECT * FROM bruckm_ticketreduction WHERE id = %d", $this->classId);
|
|
$result = dbQuery($query);
|
|
$line = mysqli_fetch_array($result, MYSQLI_ASSOC);
|
|
$this->value = $line['value'];
|
|
$this->type = $line['type'];
|
|
}
|
|
|
|
|
|
/** @see TicketObject::doSave()
|
|
*/
|
|
//----------------------------------------------
|
|
function doSave(){
|
|
//----------------------------------------------
|
|
$query = sprintf("UPDATE bruckm_ticketreduction SET value = %s, type = %s WHERE id = %d",
|
|
sqlstring($this->value),
|
|
sqlstring($this->type),
|
|
sqlnum($this->classId));
|
|
dbQuery($query);
|
|
parent::doSave();
|
|
}
|
|
|
|
|
|
/** @see TicketObject::doCreate()
|
|
*/
|
|
//----------------------------------------------
|
|
function doCreate(){
|
|
//----------------------------------------------
|
|
$query = sprintf("INSERT INTO bruckm_ticketreduction (type) VALUES (%s)",
|
|
sqlstring($this->type));
|
|
dbQuery($query);
|
|
$this->classId = mysql_insert_id();
|
|
parent::doCreate();
|
|
}
|
|
|
|
|
|
/** @see TicketObject::doDelete()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doDelete(){
|
|
//-----------------------------------------------
|
|
parent::doDelete();
|
|
$query = sprintf("DELETE FROM bruckm_ticketreduction WHERE id = %d LIMIT 1", $this->classId);
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
/** @see TicketObject::canBeDeleted()
|
|
*/
|
|
//-----------------------------------------------
|
|
function canBeDeleted(){
|
|
//-----------------------------------------------
|
|
$query = sprintf("SELECT id FROM bruckm_ticketdate WHERE `date` > NOW() AND reductions LIKE %s LIMIT 1",
|
|
sqlstring("%\t".$this->id."\t%"));
|
|
$result = dbQuery($query);
|
|
if(mysql_num_rows($result) > 0){
|
|
$this->addError("Die Ermäßigung kann nicht gelöscht werden, da sie in einer oder mehreren aktuellen Veranstaltungen verwendet wird!");
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
|
|
/** @see TicketObject::install()
|
|
*/
|
|
//-----------------------------------------------
|
|
function install(){
|
|
//-----------------------------------------------
|
|
$query = "CREATE TABLE IF NOT EXISTS bruckm_ticketreduction (
|
|
id INT UNSIGNED NOT NULL AUTO_INCREMENT,
|
|
value INT UNSIGNED NOT NULL DEFAULT 0,
|
|
type ENUM ('-','%','=','0','k','v','+','+k','k%','14d') NOT NULL DEFAULT '-',
|
|
PRIMARY KEY (id)
|
|
)";
|
|
dbQuery($query);
|
|
}
|
|
|
|
|
|
/** @see CmsObject::update()
|
|
*/
|
|
//-----------------------------------------------
|
|
function update(){
|
|
//-----------------------------------------------
|
|
parent::update();
|
|
$this->value = $_POST['value'];
|
|
$this->type = $_POST['type'];
|
|
}
|
|
|
|
|
|
/** @see CmsObject::doPrintClassContent()
|
|
*/
|
|
//-----------------------------------------------
|
|
function doPrintClassContent(){
|
|
//-----------------------------------------------
|
|
$t = new Template(CMS_TEMPLATE_DIR."ticketreduction.html");
|
|
$t->setVar("NAME", htmlspecialchars($this->name));
|
|
$t->setVar("VALUE", $this->value);
|
|
$types = array("-", "%", "=", "0", "k", "v", "z", "+", "+k", "k%", "14d");
|
|
foreach($types as $type){
|
|
if($this->type == $type){
|
|
$t->setVar("TYPE$type", "selected=\"selected\"");
|
|
}
|
|
else{
|
|
$t->setVar("TYPE$type", "");
|
|
}
|
|
}
|
|
|
|
return $t->toString();
|
|
}
|
|
|
|
|
|
/** @see CmsObject::getCssClass()
|
|
*/
|
|
//------------------------------------------------
|
|
function getCssClass(){
|
|
//------------------------------------------------
|
|
return "itemTicketReduction";
|
|
}
|
|
|
|
|
|
// === ADDITIONAL METHODS ========================================================= //
|
|
|
|
|
|
/** returns name and type of reductions
|
|
* @return string
|
|
*/
|
|
//-----------------------------------------
|
|
function getShortInfo(){
|
|
//-----------------------------------------
|
|
$out = trim($this->name);
|
|
switch($this->type){
|
|
case '-':
|
|
$out .= " (minus ".$this->value."€)";
|
|
break;
|
|
case '%':
|
|
$out .= " (".$this->value."%)";
|
|
break;
|
|
case '0':
|
|
$out .= " (".$this->value." Freikarten)";
|
|
break;
|
|
case 'k':
|
|
$out .= " (".$this->value." Freikarten)";
|
|
break;
|
|
case '=':
|
|
$out .= " (".$this->value."€)";
|
|
break;
|
|
case 'v':
|
|
$out .= " (freier Eintritt)";
|
|
break;
|
|
case 'z':
|
|
$out .= " (".$this->value."%)";
|
|
break;
|
|
case '+':
|
|
$out .= " (".$this->value."€)";
|
|
break;
|
|
case '+k':
|
|
$out .= " (".$this->value."€)";
|
|
break;
|
|
case 'k%':
|
|
$out .= " (".$this->value."%)";
|
|
break;
|
|
case '14d':
|
|
$out .= " (".$this->value."€)";
|
|
break;
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
|
|
/** writes reduction data into xml
|
|
* @return string
|
|
*/
|
|
//----------------------------------------
|
|
function toXml(){
|
|
//----------------------------------------
|
|
$xml = "<reduction name=\"".trim($this->name)."\" id=\"".$this->id."\" ";
|
|
$xml .= "type=\"".$this->type."\" value=\"".$this->value."\" />";
|
|
return $xml;
|
|
}
|
|
|
|
|
|
/** calculates the actual reduced entry for a category
|
|
* @param entry original entry (for category)
|
|
* @return entry including reduction
|
|
*/
|
|
//----------------------------------------
|
|
function calcEntry($entry){
|
|
//----------------------------------------
|
|
switch($this->type){
|
|
case '-': return $entry - $this->value;
|
|
case '%': return floor($entry * $this->value/10)/10;
|
|
case '=': return $this->value;
|
|
case '0': return 0;
|
|
case 'k': return 0;
|
|
case 'v': return 0;
|
|
case 'z': return floor($entry * $this->value/10)/10;
|
|
case '+': return $this->value;
|
|
case '+k': return $this->value;
|
|
case 'k%': return floor($entry * $this->value/10)/10;
|
|
case '14d': return $this->value;
|
|
}
|
|
return $entry;
|
|
}
|
|
|
|
|
|
/** returns number formatted as money xx,xx (without currency symbol)
|
|
* @param number
|
|
* @return xx,xx
|
|
*/
|
|
//----------------------------------------
|
|
function moneyFormat($number){
|
|
//----------------------------------------
|
|
$money = explode(".", $number);
|
|
$out = $money[0];
|
|
$out .= ",";
|
|
if($money[1]){
|
|
if(strlen($money[1]) == 1){
|
|
$out .= $money[1]."0";
|
|
}
|
|
else{
|
|
$out .= $money[1];
|
|
}
|
|
}
|
|
else{
|
|
$out .= "00";
|
|
}
|
|
return $out;
|
|
}
|
|
|
|
};
|
|
|
|
?>
|