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 = "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; } }; ?>