All pastes #2073162 Raw Edit

Someone

public text v1 · immutable
#2073162 ·published 2011-06-01 09:47 UTC
rendered paste body
<?php

class ModuleDeliveryComplete extends Module
{
	protected $strTemplate = 'mod_delivery_complete';
	
	protected function compile()
	{
		$session = $this->Session->getData();
		//Bestellung abgesendet
		if($this->Input->post('submit')){
			$areas = unserialize($GLOBALS['TL_CONFIG']['delivery_area']);
			if($this->Input->post('name') == 'Vorname Nachname' || $this->Input->post('city') == 'Ort' || $this->Input->post('postal') == 'Postleitzahl' || $this->Input->post('phone') == 'Telefonnummer' || $this->Input->post('street') == 'Straße Hausnummer' || $this->Input->post('email') == 'Emailadresse') {
				$this->Template->status = 'Bitte alle Felder ausfüllen!';
			} else {
				foreach($areas as $area) {
					if($this->Input->post('postal') == $area[0]){
						if($session['sum'] <= $area[3]){
							$this->Template->status = 'Du hast den Mindestbestellwert für '.$area[1].' nicht erreicht';
						} else {
						//Bestellung erfolgreich
							$this->Template->status = 'Wir haben deine Bestellung erhalten und sind schon unterwegs nach '.$this->Input->post('city');
							//Datenbankeintrag
							$this->Database->prepare("INSERT INTO tl_delivery_offer (tstamp, articles, sum, time, name, street, additional, postal, city, phone, email, comment) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")->execute(time(), $session['articles'], $session['sum'], $this->Input->post('time'), $this->Input->post('name'), $this->Input->post('street'), $this->Input->post('street_additional'), $this->Input->post('postal'), $this->Input->post('city'), $this->Input->post('phone'), $this->Input->post('email'), $this->Input->post('comment'));
							//Email an Subway
							$mail_text = '
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title></title>
<style type="text/css">
body {font-size:16px; font-family:Arial, Helvetica, sans-serif; margin:0;}
tr {height: 15px;}
</style>
</head>
<body>
<table width="80%" style="margin:0 0 75px 10%">
	<tr style="font-weight:bold">
	<td width="15%">Wohin?:</td>
	<td width="85%">'.$this->Input->post('name').'</td>
	</tr>
	<tr style="font-weight:bold">
	<td width="15%"></td>
	<td width="85%">'.$this->Input->post('street').' ('.$this->Input->post('street_additional').')</td>
	</tr>
	<tr style="font-weight:bold">
	<td width="15%"></td>
	<td width="85%">'.$this->Input->post('postal').' '.$this->Input->post('city').'</td>
	</tr>
	<tr style="font-weight:bold">
	<td width="15%"></td>
	<td width="85%">Telefon: '.$this->Input->post('phone').' / Email: '.$this->Input->post('email').'</td>
	</tr>
	<tr>
	<td width="15%">Wann</td>
	<td width="85%">'.$this->Input->post('time').'</td>
	</tr>
	<tr>
	<td width="15%">Kommentar:</td>
	<td width="85%">'.$this->Input->post('comment').'</td>
	</tr>
</table>
<table width="80%" style="margin:5px 0 20px 10%">
	<tr>
	<td style="font-weight:bold">Bestellung-Nr. '.date('dmyHi').' / Datum: '.date('d.m.Y').' / Uhrzeit: '.date('H:i').'</td>
	</tr>
</table>
<table width="80%" style="margin: 0 0 0 10%">
	<tr>
	<td align="right">Gesamtpreis</td>
	</tr>
</table>
';
foreach($session['articles'] as $article){
	$article = unserialize($article);
	$mail_text .= '
<table width="80%" style="margin:0 0 25px 10%">
	<tr>
	<td width="15%" style="font-weight:bold">'.$article['amount'].' x</td>
	<td width="70%" style="font-weight:bold">'.$article['category'].': '.$article['title'].'</td>
	<td width="15%" align="right">'.$article['amount'] * $article['price'].' €</td>
	</tr>
	<tr>
	<td width="15%">Auswahl</td>
	<td width="70%">'.$article['variant'].'</td>
	<td width="15%" align="right"></td>
	</tr>
';
$options = explode(',', $article['options']);
foreach($options as $option){
$mail_text .= '
	<tr>
	<td width="15%"></td>
	<td width="70%">'.$option.'</td>
	<td width="15%" align="right"></td>
	</tr>
';
}
if($article['menu'] == 'true'){
	$mail_text .= '
	<tr>
	<td width="15%"></td>
	<td width="70%"></td>
	<td width="15%" align="right"></td>
	</tr>
	<tr>
	<td width="15%"></td>
	<td width="70%">als Menu mit '.$article['menu_snack'].' und '.$article['menu_drink'].' (+ Pfand)</td>
	<td width="15%" align="right"></td>
	</tr>
	';
}
}
$mail_text .= '
</table>
<table width="80%" style="margin:0 0 5px 10%; font-weight:bold">
	<tr>
	<td width="85%" align="right">Gesamtsumme:</td>
	<td width="15%" align="right">'.$session['sum'].' €</td>
	</tr>
</table>
</body>
</html>
							';
							$objEmail = new Email();
							$objEmail->from = $GLOBALS['TL_ADMIN_EMAIL'];
							$objEmail->subject = "Lieferservice nach ".$this->Input->post('city');
							$objEmail->html = html_entity_decode($mail_text);
							$objEmail->sendTo($GLOBALS['TL_CONFIG']['delivery_email']);
							//Session löschen
							unset($session['articles']);
							unset($session['sum']);
							$this->Session->setData($session);
						}
						break;
					} else {
						$this->Template->status = 'Leider liefern wir noch nicht nach '.$this->Input->post('city');
					}
				}
			}
		}
		//Artikel gelöscht
		if(is_numeric($this->Input->get('delete'))){
			$article = unserialize($session['articles'][$this->Input->get('delete')]);
			$session['sum'] = $session['sum'] - $article['price'] * $article['amount'];
			unset($session['articles'][$this->Input->get('delete')]);
			sort($session['articles']);
			$this->Session->setData($session);
		}
		if($session['articles']){
			$articles = array();
			foreach($session['articles'] as $article)
			{
				$articles[] = unserialize($article);
			}
			$arrArticles = array();
			foreach($articles as $article)
			{
				$arrArticles[] = array(
					'amount' => $article['amount'],
					'title' => $article['title'],
					'menu' => $article['menu'],
					'menu_drink' => $article['menu_drink'],
					'menu_snack' => $article['menu_snack'],
					'price' => $article['amount'] * $article['price']
				);
			}
		}
		$this->Template->sum = $session['sum'];
		$this->Template->articles = $arrArticles;
	}
}

?>