PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/upload/catalog/controller/account/voucher.php

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