<?php /** * eSales Media oxVoucher for Contao Open Source CMS * * Copyright (c) 2015 eSales Media * * @author Benjamin Roth [benjamin@esales-media.de] * @license proprietary */ namespace eSM_oxVoucher; class ModuleTicketDetails extends ModuleVoucher { /** * Template * @var string */ protected $strTemplate = 'mod_oxticket_details'; protected $blnHide = false; /** * Parse the template * @return string */ public function generate() { if (TL_MODE == 'BE') { /** @var \BackendTemplate|object $objTemplate */ $objTemplate = new \BackendTemplate('be_wildcard'); $objTemplate->wildcard = '### ' . utf8_strtoupper($GLOBALS['TL_LANG']['FMD']['oxticket_details'][0]) . ' ###'; $objTemplate->title = $this->headline; $objTemplate->id = $this->id; $objTemplate->link = $this->name; $objTemplate->href = 'contao/main.php?do=themes&table=tl_module&act=edit&id=' . $this->id; return $objTemplate->parse(); } $this->importOxDbInstance(); $strBuffer = parent::generate(); if (!$this->blnHide) { return $strBuffer; } } /** * Compile the current element */ protected function compile() { if (\Input::get('ticket_select') || \Input::post('FORM_SUBMIT') == 'eSM_oxTicket_details') { $objSQL = $this->oxDB->prepare("SELECT OXID FROM oxarticles WHERE OXID = ?"); if (\Input::post('FORM_SUBMIT') == 'eSM_oxTicket_details') { $objTicket = $objSQL->execute(strtolower(\Input::post('OXID'))); } else { $objTicket = $objSQL->execute(strtolower(\Input::get('ticket_select'))); } if ($objTicket->numRows < 1 || $objTicket->numRows > 1) { if (\Input::get('ticket_select')) { $this->Template->noTicket = sprintf($GLOBALS['TL_LANG']['MSC']['oxTicket']['noTicket'], \Input::get('ticket_select')); } return; } $objTicket = new TicketHandler($objTicket->OXID); // Update voucher if (\Input::post('FORM_SUBMIT') == 'eSM_oxTicket_details') { if (!\Validator::isNatural(\Input::post('ticket_sellamount')) || \Input::post('ticket_sellamount') < 1) { $strMessage = $GLOBALS['TL_LANG']['MSC']['oxTicket']['not_a_natural']; $strType = 'error'; } else if (\Input::post('ticket_sellamount') > $objTicket->oxstock) { $strMessage = sprintf($GLOBALS['TL_LANG']['MSC']['oxTicket']['stock_is_less'],\Input::post('ticket_sellamount')); $strType = 'error'; } else { $objTicket->reduceStock(\Input::post('ticket_sellamount')); $strMessage = sprintf($GLOBALS['TL_LANG']['MSC']['oxTicket']['ticket_confirm'],\Input::post('ticket_sellamount'),$objTicket->oxstock); $strType = 'confirm'; } $this->setMessage($strMessage, $strType); $this->reload(); } // Template Vars $blnInvalid = false; if (!$objTicket->isBuyable()) { $blnInvalid = true; if ($objTicket->oxstock <= 0) { $strInvalid = $GLOBALS['TL_LANG']['MSC']['oxTicket']['outofstock']; } else if (!$objTicket->isActiveTime()) { $strInvalid = $GLOBALS['TL_LANG']['MSC']['oxTicket']['notActiveTime']; } else if (!$objTicket->oxactive) { $strInvalid = $GLOBALS['TL_LANG']['MSC']['oxTicket']['notActive']; } else { $strInvalid = $GLOBALS['TL_LANG']['MSC']['oxTicket']['notBuyable']; } } $arrData = array ( 'titleDetails' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['detailsTitle'], 'titleSell' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['sellTitle'], 'lblTitle' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['lblTitle'], 'lblShortDesc' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['lblShortDesc'], 'lblActiveFrom' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['lblActiveFrom'], 'lblActiveTo' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['lblActiveTo'], 'lblSellTo' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['lblSellTo'], 'lblStock' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['lblStock'], 'lblPrice' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['lblPrice'], 'ticketOxid' => $objTicket->oxid, 'ticketTitle' => ($objTicket->isVariant() ? $objTicket->oxparenttitle.' '.$objTicket->oxvarselect : $objTicket->oxtitle), 'ticketShortDesc' => ($objTicket->isVariant() && !$objTicket->oxshortdesc ? $objTicket->oxparentshortdesc : $objTicket->oxshortdesc), 'activeFrom' => (!is_null($objTicket->oxactivefrom) ? \Date::parse(\Date::getNumericDatimFormat(),$objTicket->oxactivefrom) : ''), 'activeTo' => (!is_null($objTicket->oxactiveto) ? \Date::parse(\Date::getNumericDatimFormat(),$objTicket->oxactiveto) : ''), 'sellTo' => (!is_null($objTicket->oxesselluntil) ? \Date::parse(\Date::getNumericDatimFormat(),$objTicket->oxesselluntil) : ''), 'ticketStock' => $objTicket->oxstock, 'ticketPrice' => $this->getFormattedNumber($objTicket->oxprice), 'submitLabel' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['sellSubmitLabel'], 'valueLabel' => $GLOBALS['TL_LANG']['MSC']['oxTicket']['valueLabel'], 'invalid' => $blnInvalid, 'invalidStatus' => $strInvalid, 'messages' => $this->getMessages(), ); $this->Template->setData($arrData); } else { $this->blnHide = true; } } }