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