/catalog/controller/checkout/voucher.php

https://github.com/smadi/arabian-land · PHP · 259 lines · 205 code · 54 blank · 0 comment · 52 complexity · cbe6a82629b4c52d20ae0d9cf59db05d MD5 · raw file

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