shop.balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

voucher.php (8275B)


      1 <?php
      2 class ControllerAccountVoucher extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('account/voucher');
      7 
      8 		$this->document->setTitle($this->language->get('heading_title'));
      9 
     10 		if (!isset($this->session->data['vouchers'])) {
     11 			$this->session->data['vouchers'] = array();
     12 		}
     13 
     14 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
     15 			$this->session->data['vouchers'][mt_rand()] = array(
     16 				'description'      => sprintf($this->language->get('text_for'), $this->currency->format($this->request->post['amount'], $this->session->data['currency']), $this->request->post['to_name']),
     17 				'to_name'          => $this->request->post['to_name'],
     18 				'to_email'         => $this->request->post['to_email'],
     19 				'from_name'        => $this->request->post['from_name'],
     20 				'from_email'       => $this->request->post['from_email'],
     21 				'voucher_theme_id' => $this->request->post['voucher_theme_id'],
     22 				'message'          => $this->request->post['message'],
     23 				'amount'           => $this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency'))
     24 			);
     25 
     26 			$this->response->redirect($this->url->link('account/voucher/success'));
     27 		}
     28 
     29 		$data['breadcrumbs'] = array();
     30 
     31 		$data['breadcrumbs'][] = array(
     32 			'text' => $this->language->get('text_home'),
     33 			'href' => $this->url->link('common/home')
     34 		);
     35 
     36 		$data['breadcrumbs'][] = array(
     37 			'text' => $this->language->get('text_account'),
     38 			'href' => $this->url->link('account/account', '', true)
     39 		);
     40 
     41 		$data['breadcrumbs'][] = array(
     42 			'text' => $this->language->get('text_voucher'),
     43 			'href' => $this->url->link('account/voucher', '', true)
     44 		);
     45 
     46 		$data['help_amount'] = sprintf($this->language->get('help_amount'), $this->currency->format($this->config->get('config_voucher_min'), $this->session->data['currency']), $this->currency->format($this->config->get('config_voucher_max'), $this->session->data['currency']));
     47 
     48 		if (isset($this->error['warning'])) {
     49 			$data['error_warning'] = $this->error['warning'];
     50 		} else {
     51 			$data['error_warning'] = '';
     52 		}
     53 
     54 		if (isset($this->error['to_name'])) {
     55 			$data['error_to_name'] = $this->error['to_name'];
     56 		} else {
     57 			$data['error_to_name'] = '';
     58 		}
     59 
     60 		if (isset($this->error['to_email'])) {
     61 			$data['error_to_email'] = $this->error['to_email'];
     62 		} else {
     63 			$data['error_to_email'] = '';
     64 		}
     65 
     66 		if (isset($this->error['from_name'])) {
     67 			$data['error_from_name'] = $this->error['from_name'];
     68 		} else {
     69 			$data['error_from_name'] = '';
     70 		}
     71 
     72 		if (isset($this->error['from_email'])) {
     73 			$data['error_from_email'] = $this->error['from_email'];
     74 		} else {
     75 			$data['error_from_email'] = '';
     76 		}
     77 
     78 		if (isset($this->error['theme'])) {
     79 			$data['error_theme'] = $this->error['theme'];
     80 		} else {
     81 			$data['error_theme'] = '';
     82 		}
     83 
     84 		if (isset($this->error['amount'])) {
     85 			$data['error_amount'] = $this->error['amount'];
     86 		} else {
     87 			$data['error_amount'] = '';
     88 		}
     89 
     90 		$data['action'] = $this->url->link('account/voucher', '', true);
     91 
     92 		if (isset($this->request->post['to_name'])) {
     93 			$data['to_name'] = $this->request->post['to_name'];
     94 		} else {
     95 			$data['to_name'] = '';
     96 		}
     97 
     98 		if (isset($this->request->post['to_email'])) {
     99 			$data['to_email'] = $this->request->post['to_email'];
    100 		} else {
    101 			$data['to_email'] = '';
    102 		}
    103 
    104 		if (isset($this->request->post['from_name'])) {
    105 			$data['from_name'] = $this->request->post['from_name'];
    106 		} elseif ($this->customer->isLogged()) {
    107 			$data['from_name'] = $this->customer->getFirstName() . ' '  . $this->customer->getLastName();
    108 		} else {
    109 			$data['from_name'] = '';
    110 		}
    111 
    112 		if (isset($this->request->post['from_email'])) {
    113 			$data['from_email'] = $this->request->post['from_email'];
    114 		} elseif ($this->customer->isLogged()) {
    115 			$data['from_email'] = $this->customer->getEmail();
    116 		} else {
    117 			$data['from_email'] = '';
    118 		}
    119 
    120 		$this->load->model('extension/total/voucher_theme');
    121 
    122 		$data['voucher_themes'] = $this->model_extension_total_voucher_theme->getVoucherThemes();
    123 
    124 		if (isset($this->request->post['voucher_theme_id'])) {
    125 			$data['voucher_theme_id'] = $this->request->post['voucher_theme_id'];
    126 		} else {
    127 			$data['voucher_theme_id'] = '';
    128 		}
    129 
    130 		if (isset($this->request->post['message'])) {
    131 			$data['message'] = $this->request->post['message'];
    132 		} else {
    133 			$data['message'] = '';
    134 		}
    135 
    136 		if (isset($this->request->post['amount'])) {
    137 			$data['amount'] = $this->request->post['amount'];
    138 		} else {
    139 			$data['amount'] = $this->currency->format($this->config->get('config_voucher_min'), $this->config->get('config_currency'), false, false);
    140 		}
    141 
    142 		if (isset($this->request->post['agree'])) {
    143 			$data['agree'] = $this->request->post['agree'];
    144 		} else {
    145 			$data['agree'] = false;
    146 		}
    147 
    148 		$data['column_left'] = $this->load->controller('common/column_left');
    149 		$data['column_right'] = $this->load->controller('common/column_right');
    150 		$data['content_top'] = $this->load->controller('common/content_top');
    151 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
    152 		$data['footer'] = $this->load->controller('common/footer');
    153 		$data['header'] = $this->load->controller('common/header');
    154 
    155 		$this->response->setOutput($this->load->view('account/voucher', $data));
    156 	}
    157 
    158 	public function success() {
    159 		$this->load->language('account/voucher');
    160 
    161 		$this->document->setTitle($this->language->get('heading_title'));
    162 
    163 		$data['breadcrumbs'] = array();
    164 
    165 		$data['breadcrumbs'][] = array(
    166 			'text' => $this->language->get('text_home'),
    167 			'href' => $this->url->link('common/home')
    168 		);
    169 
    170 		$data['breadcrumbs'][] = array(
    171 			'text' => $this->language->get('heading_title'),
    172 			'href' => $this->url->link('account/voucher')
    173 		);
    174 
    175 		$data['continue'] = $this->url->link('checkout/cart');
    176 
    177 		$data['column_left'] = $this->load->controller('common/column_left');
    178 		$data['column_right'] = $this->load->controller('common/column_right');
    179 		$data['content_top'] = $this->load->controller('common/content_top');
    180 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
    181 		$data['footer'] = $this->load->controller('common/footer');
    182 		$data['header'] = $this->load->controller('common/header');
    183 
    184 		$this->response->setOutput($this->load->view('common/success', $data));
    185 	}
    186 
    187 	protected function validate() {
    188 		if ((utf8_strlen($this->request->post['to_name']) < 1) || (utf8_strlen($this->request->post['to_name']) > 64)) {
    189 			$this->error['to_name'] = $this->language->get('error_to_name');
    190 		}
    191 
    192 		if ((utf8_strlen($this->request->post['to_email']) > 96) || !filter_var($this->request->post['to_email'], FILTER_VALIDATE_EMAIL)) {
    193 			$this->error['to_email'] = $this->language->get('error_email');
    194 		}
    195 
    196 		if ((utf8_strlen($this->request->post['from_name']) < 1) || (utf8_strlen($this->request->post['from_name']) > 64)) {
    197 			$this->error['from_name'] = $this->language->get('error_from_name');
    198 		}
    199 
    200 		if ((utf8_strlen($this->request->post['from_email']) > 96) || !filter_var($this->request->post['from_email'], FILTER_VALIDATE_EMAIL)) {
    201 			$this->error['from_email'] = $this->language->get('error_email');
    202 		}
    203 
    204 		if (!isset($this->request->post['voucher_theme_id'])) {
    205 			$this->error['theme'] = $this->language->get('error_theme');
    206 		}
    207 
    208 		if (($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) < $this->config->get('config_voucher_min')) || ($this->currency->convert($this->request->post['amount'], $this->session->data['currency'], $this->config->get('config_currency')) > $this->config->get('config_voucher_max'))) {
    209 			$this->error['amount'] = sprintf($this->language->get('error_amount'), $this->currency->format($this->config->get('config_voucher_min'), $this->session->data['currency']), $this->currency->format($this->config->get('config_voucher_max'), $this->session->data['currency']));
    210 		}
    211 
    212 		if (!isset($this->request->post['agree'])) {
    213 			$this->error['warning'] = $this->language->get('error_agree');
    214 		}
    215 
    216 		return !$this->error;
    217 	}
    218 }