/upload/catalog/controller/information/contact.php
PHP | 229 lines | 180 code | 49 blank | 0 comment | 33 complexity | b20d727d43d0a14192768939531f9830 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-3.0
- <?php
- class ControllerInformationContact extends Controller {
- private $error = array();
-
- public function index() {
- $this->data += $this->language->load('information/contact');
-
- $this->document->setTitle($this->language->get('heading_title'));
-
- if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
- $mail = new Mail();
- $mail->protocol = $this->config->get('config_mail_protocol');
- $mail->parameter = $this->config->get('config_mail_parameter');
- $mail->hostname = $this->config->get('config_smtp_host');
- $mail->username = $this->config->get('config_smtp_username');
- $mail->password = $this->config->get('config_smtp_password');
- $mail->port = $this->config->get('config_smtp_port');
- $mail->timeout = $this->config->get('config_smtp_timeout');
- $mail->setTo($this->config->get('config_email'));
- $mail->setFrom($this->request->post['email']);
- $mail->setSender($this->request->post['name']);
- $mail->setSubject(html_entity_decode(sprintf($this->language->get('email_subject'), $this->request->post['name']), ENT_QUOTES, 'UTF-8'));
- $mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));
- $mail->send();
-
- $this->redirect($this->url->link('information/contact/success'));
- }
-
- $this->data['breadcrumbs'] = array();
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_home'),
- 'href' => $this->url->link('common/home')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('information/contact')
- );
-
- if (isset($this->error['name'])) {
- $this->data['error_name'] = $this->error['name'];
- } else {
- $this->data['error_name'] = '';
- }
-
- if (isset($this->error['email'])) {
- $this->data['error_email'] = $this->error['email'];
- } else {
- $this->data['error_email'] = '';
- }
-
- if (isset($this->error['enquiry'])) {
- $this->data['error_enquiry'] = $this->error['enquiry'];
- } else {
- $this->data['error_enquiry'] = '';
- }
-
- if (isset($this->error['captcha'])) {
- $this->data['error_captcha'] = $this->error['captcha'];
- } else {
- $this->data['error_captcha'] = '';
- }
-
- $this->data['action'] = $this->url->link('information/contact');
-
- $this->data['store'] = $this->config->get('config_name');
- $this->data['address'] = nl2br($this->config->get('config_address'));
- $this->data['telephone'] = $this->config->get('config_telephone');
- $this->data['fax'] = $this->config->get('config_fax');
-
- if (isset($this->request->post['name'])) {
- $this->data['name'] = $this->request->post['name'];
- } else {
- $this->data['name'] = $this->customer->getFirstName();
- }
-
- if (isset($this->request->post['email'])) {
- $this->data['email'] = $this->request->post['email'];
- } else {
- $this->data['email'] = $this->customer->getEmail();
- }
-
- if (isset($this->request->post['enquiry'])) {
- $this->data['enquiry'] = $this->request->post['enquiry'];
- } else {
- $this->data['enquiry'] = '';
- }
-
- if (isset($this->request->post['captcha'])) {
- $this->data['captcha'] = $this->request->post['captcha'];
- } else {
- $this->data['captcha'] = '';
- }
-
- $this->data['locations'] = array();
-
- $this->load->model('setting/location');
-
- $results = $this->model_setting_location->getLocations();
-
- foreach($results as $result) {
- $this->data['locations'][] = array(
- 'location_id' => $result['location_id'],
- 'name' => $result['name'],
- 'address_1' => $result['address_1'],
- 'address_2' => $result['address_2'],
- 'city' => $result['city'],
- 'postcode' => $result['postcode'],
- 'geocode' => $result['geocode'],
- 'open' => $result['open'],
- 'comment' => $result['comment']
- );
- }
-
- if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/contact.tpl')) {
- $this->template = $this->config->get('config_template') . '/template/information/contact.tpl';
- } else {
- $this->template = 'default/template/information/contact.tpl';
- }
-
- $this->children = array(
- 'common/column_left',
- 'common/column_right',
- 'common/content_top',
- 'common/content_bottom',
- 'common/footer',
- 'common/header'
- );
-
- $this->response->setOutput($this->render());
- }
-
- public function success() {
- $this->data += $this->language->load('information/contact');
-
- $this->document->setTitle($this->language->get('heading_title'));
-
- $this->data['breadcrumbs'] = array();
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('text_home'),
- 'href' => $this->url->link('common/home')
- );
-
- $this->data['breadcrumbs'][] = array(
- 'text' => $this->language->get('heading_title'),
- 'href' => $this->url->link('information/contact')
- );
-
- $this->data['continue'] = $this->url->link('common/home');
-
- if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
- $this->template = $this->config->get('config_template') . '/template/common/success.tpl';
- } else {
- $this->template = 'default/template/common/success.tpl';
- }
-
- $this->children = array(
- 'common/column_left',
- 'common/column_right',
- 'common/content_top',
- 'common/content_bottom',
- 'common/footer',
- 'common/header'
- );
-
- $this->response->setOutput($this->render());
- }
-
- protected function validate() {
- if ((utf8_strlen($this->request->post['name']) < 3) || (utf8_strlen($this->request->post['name']) > 32)) {
- $this->error['name'] = $this->language->get('error_name');
- }
-
- if (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
- $this->error['email'] = $this->language->get('error_email');
- }
-
- if ((utf8_strlen($this->request->post['enquiry']) < 10) || (utf8_strlen($this->request->post['enquiry']) > 3000)) {
- $this->error['enquiry'] = $this->language->get('error_enquiry');
- }
-
- if (empty($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
- $this->error['captcha'] = $this->language->get('error_captcha');
- }
-
- if (!$this->error) {
- return true;
- } else {
- return false;
- }
- }
-
- public function captcha() {
- $this->session->data['captcha'] = substr(sha1(mt_rand()), 17, 6);
-
- $image = imagecreatetruecolor(150, 35);
-
- $width = imagesx($image);
- $height = imagesy($image);
-
- $black = imagecolorallocate($image, 0, 0, 0);
- $white = imagecolorallocate($image, 255, 255, 255);
- $red = imagecolorallocatealpha($image, 255, 0, 0, 75);
- $green = imagecolorallocatealpha($image, 0, 255, 0, 75);
- $blue = imagecolorallocatealpha($image, 0, 0, 255, 75);
-
- imagefilledrectangle($image, 0, 0, $width, $height, $white);
-
- imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red);
- imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green);
- imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue);
-
- imagefilledrectangle($image, 0, 0, $width, 0, $black);
- imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black);
- imagefilledrectangle($image, 0, 0, 0, $height - 1, $black);
- imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black);
-
- imagestring($image, 10, intval(($width - (strlen($this->session->data['captcha']) * 9)) / 2), intval(($height - 15) / 2), $this->session->data['captcha'], $black);
-
- header('Content-type: image/jpeg');
-
- imagejpeg($image);
-
- imagedestroy($image);
- }
- }
- ?>