Guest User

Untitled

a guest
Dec 10th, 2017
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.24 KB | None | 0 0
  1. <?php
  2. class ControllerInformationContact extends Controller {
  3. private $error = array();
  4.  
  5. public function index() {
  6. $this->language->load('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();
  12. $mail->protocol = $this->config->get('config_mail_protocol');
  13. $mail->parameter = $this->config->get('config_mail_parameter');
  14. $mail->hostname = $this->config->get('config_smtp_host');
  15. $mail->username = $this->config->get('config_smtp_username');
  16. $mail->password = $this->config->get('config_smtp_password');
  17. $mail->port = $this->config->get('config_smtp_port');
  18. $mail->timeout = $this->config->get('config_smtp_timeout');
  19. $mail->setTo($this->config->get('config_email'));
  20. $mail->setFrom($this->request->post['email']);
  21. $mail->setSender($this->request->post['name']);
  22. $mail->setSubject(sprintf($this->language->get('email_subject'), $this->request->post['name']));
  23. $mail->setText(strip_tags(html_entity_decode($this->request->post['enquiry'], ENT_QUOTES, 'UTF-8')));
  24. $mail->send();
  25.  
  26. $this->redirect($this->url->link('information/contact/success'));
  27. }
  28.  
  29. $this->data['breadcrumbs'] = array();
  30.  
  31. $this->data['breadcrumbs'][] = array(
  32. 'text' => $this->language->get('text_home'),
  33. 'href' => $this->url->link('common/home'),
  34. 'separator' => false
  35. );
  36.  
  37. $this->data['breadcrumbs'][] = array(
  38. 'text' => $this->language->get('heading_title'),
  39. 'href' => $this->url->link('information/contact'),
  40. 'separator' => $this->language->get('text_separator')
  41. );
  42.  
  43. $this->data['heading_title'] = $this->language->get('heading_title');
  44.  
  45. $this->data['text_location'] = $this->language->get('text_location');
  46. $this->data['text_contact'] = $this->language->get('text_contact');
  47. $this->data['text_address'] = $this->language->get('text_address');
  48. $this->data['text_telephone'] = $this->language->get('text_telephone');
  49. $this->data['text_fax'] = $this->language->get('text_fax');
  50.  
  51. $this->data['entry_name'] = $this->language->get('entry_name');
  52. $this->data['entry_email'] = $this->language->get('entry_email');
  53. $this->data['entry_enquiry'] = $this->language->get('entry_enquiry');
  54. $this->data['entry_captcha'] = $this->language->get('entry_captcha');
  55.  
  56. if (isset($this->error['name'])) {
  57. $this->data['error_name'] = $this->error['name'];
  58. } else {
  59. $this->data['error_name'] = '';
  60. }
  61.  
  62. if (isset($this->error['email'])) {
  63. $this->data['error_email'] = $this->error['email'];
  64. } else {
  65. $this->data['error_email'] = '';
  66. }
  67.  
  68. if (isset($this->error['enquiry'])) {
  69. $this->data['error_enquiry'] = $this->error['enquiry'];
  70. } else {
  71. $this->data['error_enquiry'] = '';
  72. }
  73. if (isset($this->error['captcha'])) {
  74. $this->data['error_captcha'] = $this->error['captcha'];
  75. } else {
  76. $this->data['error_captcha'] = '';
  77. }
  78.  
  79. $this->data['button_continue'] = $this->language->get('button_continue');
  80.  
  81. $this->data['action'] = $this->url->link('information/contact');
  82. $this->data['store'] = $this->config->get('config_name');
  83. $this->data['address'] = nl2br($this->config->get('config_address'));
  84. $this->data['telephone'] = $this->config->get('config_telephone');
  85. $this->data['fax'] = $this->config->get('config_fax');
  86.  
  87. if (isset($this->request->post['name'])) {
  88. $this->data['name'] = $this->request->post['name'];
  89. } else {
  90. $this->data['name'] = '';
  91. }
  92.  
  93. if (isset($this->request->post['email'])) {
  94. $this->data['email'] = $this->request->post['email'];
  95. } else {
  96. $this->data['email'] = '';
  97. }
  98.  
  99. if (isset($this->request->post['enquiry'])) {
  100. $this->data['enquiry'] = $this->request->post['enquiry'];
  101. } else {
  102. $this->data['enquiry'] = '';
  103. }
  104.  
  105. if (isset($this->request->post['captcha'])) {
  106. $this->data['captcha'] = $this->request->post['captcha'];
  107. } else {
  108. $this->data['captcha'] = '';
  109. }
  110.  
  111. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/information/contact.tpl')) {
  112. $this->template = $this->config->get('config_template') . '/template/information/contact.tpl';
  113. } else {
  114. $this->template = 'default/template/information/contact.tpl';
  115. }
  116.  
  117. $this->children = array(
  118. 'common/column_left',
  119. 'common/column_right',
  120. 'common/content_top',
  121. 'common/content_bottom',
  122. 'common/footer',
  123. 'common/header'
  124. );
  125.  
  126. $this->response->setOutput($this->render());
  127. }
  128.  
  129. public function success() {
  130. $this->language->load('information/contact');
  131.  
  132. $this->document->setTitle($this->language->get('heading_title'));
  133.  
  134. $this->data['breadcrumbs'] = array();
  135.  
  136. $this->data['breadcrumbs'][] = array(
  137. 'text' => $this->language->get('text_home'),
  138. 'href' => $this->url->link('common/home'),
  139. 'separator' => false
  140. );
  141.  
  142. $this->data['breadcrumbs'][] = array(
  143. 'text' => $this->language->get('heading_title'),
  144. 'href' => $this->url->link('information/contact'),
  145. 'separator' => $this->language->get('text_separator')
  146. );
  147.  
  148. $this->data['heading_title'] = $this->language->get('heading_title');
  149.  
  150. $this->data['text_message'] = $this->language->get('text_message');
  151.  
  152. $this->data['button_continue'] = $this->language->get('button_continue');
  153.  
  154. $this->data['continue'] = $this->url->link('common/home');
  155.  
  156. if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/success.tpl')) {
  157. $this->template = $this->config->get('config_template') . '/template/common/success.tpl';
  158. } else {
  159. $this->template = 'default/template/common/success.tpl';
  160. }
  161.  
  162. $this->children = array(
  163. 'common/column_left',
  164. 'common/column_right',
  165. 'common/content_top',
  166. 'common/content_bottom',
  167. 'common/footer',
  168. 'common/header'
  169. );
  170.  
  171. $this->response->setOutput($this->render());
  172. }
  173.  
  174. public function captcha() {
  175. $this->load->library('captcha');
  176.  
  177. $captcha = new Captcha();
  178.  
  179. $this->session->data['captcha'] = $captcha->getCode();
  180.  
  181. $captcha->showImage();
  182. }
  183.  
  184. private function validate() {
  185. if ((strlen(utf8_decode($this->request->post['name'])) < 3) || (strlen(utf8_decode($this->request->post['name'])) > 32)) {
  186. $this->error['name'] = $this->language->get('error_name');
  187. }
  188.  
  189. if (!preg_match('/^[^\@]+@.*\.[a-z]{2,6}$/i', $this->request->post['email'])) {
  190. $this->error['email'] = $this->language->get('error_email');
  191. }
  192.  
  193. if ((strlen(utf8_decode($this->request->post['enquiry'])) < 10) || (strlen(utf8_decode($this->request->post['enquiry'])) > 3000)) {
  194. $this->error['enquiry'] = $this->language->get('error_enquiry');
  195. }
  196.  
  197. if (!isset($this->session->data['captcha']) || ($this->session->data['captcha'] != $this->request->post['captcha'])) {
  198. $this->error['captcha'] = $this->language->get('error_captcha');
  199. }
  200.  
  201. if (!$this->error) {
  202. return true;
  203. } else {
  204. return false;
  205. }
  206. }
  207. }
  208. ?>
Add Comment
Please, Sign In to add comment