shop.balmet.com

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

contact.php (7676B)


      1 <?php
      2 class ControllerInformationContact extends Controller {
      3 	private $error = array();
      4 
      5 	public function index() {
      6 		$this->load->language('information/contact');
      7 
      8 		$this->document->setTitle($this->language->get('heading_title'));
      9 
     10 		if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
     11 			$mail = new Mail($this->config->get('config_mail_engine'));
     12 			$mail->parameter = $this->config->get('config_mail_parameter');
     13 			$mail->smtp_hostname = $this->config->get('config_mail_smtp_hostname');
     14 			$mail->smtp_username = $this->config->get('config_mail_smtp_username');
     15 			$mail->smtp_password = html_entity_decode($this->config->get('config_mail_smtp_password'), ENT_QUOTES, 'UTF-8');
     16 			$mail->smtp_port = $this->config->get('config_mail_smtp_port');
     17 			$mail->smtp_timeout = $this->config->get('config_mail_smtp_timeout');
     18 
     19 			$mail->setTo($this->config->get('config_email'));
     20 			$mail->setFrom($this->config->get('config_email'));
     21 			$mail->setReplyTo($this->request->post['email']);
     22 			$mail->setSender(html_entity_decode($this->request->post['name'], ENT_QUOTES, 'UTF-8'));
     23 			$mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
     24 			$mail->setText($this->request->post['enquiry']);
     25 			$mail->send();
     26 
     27 			$this->response->redirect($this->url->link('information/contact/success'));
     28 		}
     29 
     30 		$data['breadcrumbs'] = array();
     31 
     32 		$data['breadcrumbs'][] = array(
     33 			'text' => $this->language->get('text_home'),
     34 			'href' => $this->url->link('common/home')
     35 		);
     36 
     37 		$data['breadcrumbs'][] = array(
     38 			'text' => $this->language->get('heading_title'),
     39 			'href' => $this->url->link('information/contact')
     40 		);
     41 
     42 		if (isset($this->error['name'])) {
     43 			$data['error_name'] = $this->error['name'];
     44 		} else {
     45 			$data['error_name'] = '';
     46 		}
     47 
     48 		if (isset($this->error['email'])) {
     49 			$data['error_email'] = $this->error['email'];
     50 		} else {
     51 			$data['error_email'] = '';
     52 		}
     53 
     54 		if (isset($this->error['enquiry'])) {
     55 			$data['error_enquiry'] = $this->error['enquiry'];
     56 		} else {
     57 			$data['error_enquiry'] = '';
     58 		}
     59 
     60 		$data['button_submit'] = $this->language->get('button_submit');
     61 
     62 		$data['action'] = $this->url->link('information/contact', '', true);
     63 
     64 		$this->load->model('tool/image');
     65 
     66 		if ($this->config->get('config_image')) {
     67 			$data['image'] = $this->model_tool_image->resize($this->config->get('config_image'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_height'));
     68 		} else {
     69 			$data['image'] = false;
     70 		}
     71 
     72 		$data['store'] = $this->config->get('config_name');
     73 		$data['address'] = nl2br($this->config->get('config_address'));
     74 		$data['geocode'] = $this->config->get('config_geocode');
     75 		$data['geocode_hl'] = $this->config->get('config_language');
     76 		$data['telephone'] = $this->config->get('config_telephone');
     77 		$data['fax'] = $this->config->get('config_fax');
     78 		$data['open'] = nl2br($this->config->get('config_open'));
     79 		$data['comment'] = $this->config->get('config_comment');
     80 
     81 		$data['locations'] = array();
     82 
     83 		$this->load->model('localisation/location');
     84 
     85 		foreach((array)$this->config->get('config_location') as $location_id) {
     86 			$location_info = $this->model_localisation_location->getLocation($location_id);
     87 
     88 			if ($location_info) {
     89 				if ($location_info['image']) {
     90 					$image = $this->model_tool_image->resize($location_info['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_width'), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_location_height'));
     91 				} else {
     92 					$image = false;
     93 				}
     94 
     95 				$data['locations'][] = array(
     96 					'location_id' => $location_info['location_id'],
     97 					'name'        => $location_info['name'],
     98 					'address'     => nl2br($location_info['address']),
     99 					'geocode'     => $location_info['geocode'],
    100 					'telephone'   => $location_info['telephone'],
    101 					'fax'         => $location_info['fax'],
    102 					'image'       => $image,
    103 					'open'        => nl2br($location_info['open']),
    104 					'comment'     => $location_info['comment']
    105 				);
    106 			}
    107 		}
    108 
    109 		if (isset($this->request->post['name'])) {
    110 			$data['name'] = $this->request->post['name'];
    111 		} else {
    112 			$data['name'] = $this->customer->getFirstName();
    113 		}
    114 
    115 		if (isset($this->request->post['email'])) {
    116 			$data['email'] = $this->request->post['email'];
    117 		} else {
    118 			$data['email'] = $this->customer->getEmail();
    119 		}
    120 
    121 		if (isset($this->request->post['enquiry'])) {
    122 			$data['enquiry'] = $this->request->post['enquiry'];
    123 		} else {
    124 			$data['enquiry'] = '';
    125 		}
    126 
    127 		// Captcha
    128 		if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
    129 			$data['captcha'] = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha'), $this->error);
    130 		} else {
    131 			$data['captcha'] = '';
    132 		}
    133 
    134 		$data['column_left'] = $this->load->controller('common/column_left');
    135 		$data['column_right'] = $this->load->controller('common/column_right');
    136 		$data['content_top'] = $this->load->controller('common/content_top');
    137 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
    138 		$data['footer'] = $this->load->controller('common/footer');
    139 		$data['header'] = $this->load->controller('common/header');
    140 
    141 		$this->response->setOutput($this->load->view('information/contact', $data));
    142 	}
    143 
    144 	protected function validate() {
    145 		if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
    146 			$this->error['name'] = $this->language->get('error_name');
    147 		}
    148 
    149 		if (!filter_var($this->request->post['email'], FILTER_VALIDATE_EMAIL)) {
    150 			$this->error['email'] = $this->language->get('error_email');
    151 		}
    152 
    153 		if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
    154 			$this->error['enquiry'] = $this->language->get('error_enquiry');
    155 		}
    156 
    157 		// Captcha
    158 		if ($this->config->get('captcha_' . $this->config->get('config_captcha') . '_status') && in_array('contact', (array)$this->config->get('config_captcha_page'))) {
    159 			$captcha = $this->load->controller('extension/captcha/' . $this->config->get('config_captcha') . '/validate');
    160 
    161 			if ($captcha) {
    162 				$this->error['captcha'] = $captcha;
    163 			}
    164 		}
    165 
    166 		return !$this->error;
    167 	}
    168 
    169 	public function success() {
    170 		$this->load->language('information/contact');
    171 
    172 		$this->document->setTitle($this->language->get('heading_title'));
    173 
    174 		$data['breadcrumbs'] = array();
    175 
    176 		$data['breadcrumbs'][] = array(
    177 			'text' => $this->language->get('text_home'),
    178 			'href' => $this->url->link('common/home')
    179 		);
    180 
    181 		$data['breadcrumbs'][] = array(
    182 			'text' => $this->language->get('heading_title'),
    183 			'href' => $this->url->link('information/contact')
    184 		);
    185 
    186 		$data['continue'] = $this->url->link('common/home');
    187 
    188 		$data['column_left'] = $this->load->controller('common/column_left');
    189 		$data['column_right'] = $this->load->controller('common/column_right');
    190 		$data['content_top'] = $this->load->controller('common/content_top');
    191 		$data['content_bottom'] = $this->load->controller('common/content_bottom');
    192 		$data['footer'] = $this->load->controller('common/footer');
    193 		$data['header'] = $this->load->controller('common/header');
    194 
    195 		$this->response->setOutput($this->load->view('common/success', $data));
    196 	}
    197 }