|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
HCSF - A multilingual CMS and Shopsystem |
|
5
|
|
|
Copyright (C) 2014 Marcus Haase - [email protected] |
|
6
|
|
|
|
|
7
|
|
|
This program is free software: you can redistribute it and/or modify |
|
8
|
|
|
it under the terms of the GNU General Public License as published by |
|
9
|
|
|
the Free Software Foundation, either version 3 of the License, or |
|
10
|
|
|
(at your option) any later version. |
|
11
|
|
|
|
|
12
|
|
|
This program is distributed in the hope that it will be useful, |
|
13
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
14
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
15
|
|
|
GNU General Public License for more details. |
|
16
|
|
|
|
|
17
|
|
|
You should have received a copy of the GNU General Public License |
|
18
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace HaaseIT\HCSF\Customer; |
|
22
|
|
|
|
|
23
|
|
|
use HaaseIT\HCSF\HelperConfig; |
|
24
|
|
|
use HaaseIT\Toolbox\Tools; |
|
25
|
|
|
use Zend\ServiceManager\ServiceManager; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Class Helper |
|
29
|
|
|
* @package HaaseIT\HCSF\Customer |
|
30
|
|
|
*/ |
|
31
|
|
|
class Helper |
|
32
|
|
|
{ |
|
33
|
|
|
/** |
|
34
|
|
|
* @param string $sLang |
|
35
|
|
|
* @param array $aErr |
|
36
|
|
|
* @param bool $bEdit |
|
37
|
|
|
* @return array |
|
38
|
|
|
*/ |
|
39
|
|
|
public static function validateCustomerForm($sLang, $aErr = [], $bEdit = false) |
|
40
|
|
|
{ |
|
41
|
|
|
if (empty(filter_input(INPUT_POST, 'email', FILTER_VALIDATE_EMAIL))) { |
|
42
|
|
|
$aErr['email'] = true; |
|
43
|
|
|
} |
|
44
|
|
|
$postcorpname = filter_input(INPUT_POST, 'corpname', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
45
|
|
View Code Duplication |
if (HelperConfig::$customer['validate_corpname'] && (empty($postcorpname) || strlen(trim($postcorpname)) < 3)) { |
|
|
|
|
|
|
46
|
|
|
$aErr['corpname'] = true; |
|
47
|
|
|
} |
|
48
|
|
|
$postname = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
49
|
|
View Code Duplication |
if (HelperConfig::$customer['validate_name'] && (empty($postname) || strlen(trim($postname)) < 3)) { |
|
|
|
|
|
|
50
|
|
|
$aErr['name'] = true; |
|
51
|
|
|
} |
|
52
|
|
|
$poststreet = filter_input(INPUT_POST, 'street', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
53
|
|
View Code Duplication |
if (HelperConfig::$customer['validate_street'] && (empty($poststreet) || strlen(trim($poststreet)) < 3)) { |
|
|
|
|
|
|
54
|
|
|
$aErr['street'] = true; |
|
55
|
|
|
} |
|
56
|
|
|
$postzip = filter_input(INPUT_POST, 'zip', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
57
|
|
View Code Duplication |
if (HelperConfig::$customer['validate_zip'] && (empty($postzip) || strlen(trim($postzip)) < 4)) { |
|
|
|
|
|
|
58
|
|
|
$aErr['zip'] = true; |
|
59
|
|
|
} |
|
60
|
|
|
$posttown = filter_input(INPUT_POST, 'town', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
61
|
|
View Code Duplication |
if (HelperConfig::$customer['validate_town'] && (empty($posttown) || strlen(trim($posttown)) < 3)) { |
|
|
|
|
|
|
62
|
|
|
$aErr['town'] = true; |
|
63
|
|
|
} |
|
64
|
|
|
$postphone = filter_input(INPUT_POST, 'phone', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
65
|
|
View Code Duplication |
if (HelperConfig::$customer['validate_phone'] && (empty($postphone) || strlen(trim($postphone)) < 6)) { |
|
|
|
|
|
|
66
|
|
|
$aErr['phone'] = true; |
|
67
|
|
|
} |
|
68
|
|
|
$postcellphone = filter_input(INPUT_POST, 'cellphone', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
69
|
|
View Code Duplication |
if (HelperConfig::$customer['validate_cellphone'] && (empty($postcellphone) || strlen(trim($postcellphone)) < 11)) { |
|
|
|
|
|
|
70
|
|
|
$aErr['cellphone'] = true; |
|
71
|
|
|
} |
|
72
|
|
|
$postfax = filter_input(INPUT_POST, 'fax', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
73
|
|
View Code Duplication |
if (HelperConfig::$customer['validate_fax'] && (empty($postfax) || strlen(trim($postfax)) < 6)) { |
|
|
|
|
|
|
74
|
|
|
$aErr['fax'] = true; |
|
75
|
|
|
} |
|
76
|
|
|
$postcountry = filter_input(INPUT_POST, 'country', FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); |
|
77
|
|
|
if (HelperConfig::$customer['validate_country'] && (empty($postcountry) || !isset(HelperConfig::$countries['countries_' .$sLang][$postcountry]))) { |
|
78
|
|
|
$aErr['country'] = true; |
|
79
|
|
|
} |
|
80
|
|
|
$posttos = filter_input(INPUT_POST, 'tos'); |
|
81
|
|
|
if (!$bEdit && $posttos !== 'y') { |
|
82
|
|
|
$aErr['tos'] = true; |
|
83
|
|
|
} |
|
84
|
|
|
$postcancellationdisclaimer = filter_input(INPUT_POST, 'cancellationdisclaimer'); |
|
85
|
|
|
if (!$bEdit && $postcancellationdisclaimer !== 'y') { |
|
86
|
|
|
$aErr['cancellationdisclaimer'] = true; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
$postpwd = filter_input(INPUT_POST, 'pwd'); |
|
90
|
|
|
$postpwdc = filter_input(INPUT_POST, 'pwdc'); |
|
91
|
|
|
if (!$bEdit || !empty($postpwd)) { |
|
92
|
|
|
if (strlen($postpwd) < HelperConfig::$customer['minimum_length_password']) { |
|
93
|
|
|
$aErr['passwordlength'] = true; |
|
94
|
|
|
} |
|
95
|
|
|
if ($postpwd !== $postpwdc) { |
|
96
|
|
|
$aErr['passwordmatch'] = true; |
|
97
|
|
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $aErr; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* @param string $sLang |
|
105
|
|
|
* @return string |
|
106
|
|
|
*/ |
|
107
|
|
|
public static function getDefaultCountryByConfig($sLang) { |
|
108
|
|
|
if (isset(HelperConfig::$core['defaultcountrybylang'][$sLang])) { |
|
109
|
|
|
return HelperConfig::$core['defaultcountrybylang'][$sLang]; |
|
110
|
|
|
} |
|
111
|
|
|
return ''; |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* @param string $sKeyConfig |
|
116
|
|
|
* @param string $sKeyForm |
|
117
|
|
|
* @param array|bool $aUserData |
|
118
|
|
|
* @return bool |
|
119
|
|
|
*/ |
|
120
|
|
|
public static function getCustomerFormDefaultValue($sKeyConfig, $sKeyForm, $aUserData) { |
|
|
|
|
|
|
121
|
|
|
$sDefaultValue = self::getUserData($sKeyConfig, $aUserData); |
|
|
|
|
|
|
122
|
|
|
if (!$sDefaultValue && isset($_SESSION['formsave_addrform'][$sKeyForm])) { |
|
123
|
|
|
$sDefaultValue = $_SESSION['formsave_addrform'][$sKeyForm]; |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
return $sDefaultValue; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @param string $sLang |
|
131
|
|
|
* @param string $sPurpose |
|
132
|
|
|
* @param array $aErr |
|
133
|
|
|
* @param bool $aUserData |
|
134
|
|
|
* @return array |
|
135
|
|
|
*/ |
|
136
|
|
|
public static function buildCustomerForm($sLang, $sPurpose = 'none', $aErr = [], $aUserData = false) |
|
|
|
|
|
|
137
|
|
|
{ |
|
138
|
|
|
$sDefaultCountry = self::getCustomerFormDefaultValue('cust_country', 'country', $aUserData); |
|
139
|
|
|
|
|
140
|
|
|
// Purposes: shoppingcart, userhome, shopadmin, editprofile, register |
|
141
|
|
|
// fv = field_value, fr = field_required |
|
142
|
|
|
$aData = [ |
|
143
|
|
|
'purpose' => $sPurpose, |
|
144
|
|
|
'errormessage' => $aErr, |
|
145
|
|
|
'readonlycustno' => $sPurpose === 'shopadmin' ? true : false, |
|
146
|
|
|
'readonly' => |
|
147
|
|
|
$sPurpose === 'shopadmin' |
|
148
|
|
|
|| $sPurpose === 'userhome' |
|
149
|
|
|
|| ($sPurpose === 'editprofile' && !HelperConfig::$customer['allow_edituserprofile']) |
|
150
|
|
|
|| ($sPurpose === 'shoppingcart' && self::getUserData()) |
|
151
|
|
|
, |
|
152
|
|
|
'fv_custno' => Tools::getFormfield( |
|
153
|
|
|
'custno', |
|
154
|
|
|
self::getCustomerFormDefaultValue('cust_no', 'custno', $aUserData), |
|
|
|
|
|
|
155
|
|
|
true |
|
156
|
|
|
), |
|
157
|
|
|
'fv_email' => Tools::getFormfield( |
|
158
|
|
|
'email', |
|
159
|
|
|
self::getCustomerFormDefaultValue('cust_email', 'email', $aUserData), |
|
|
|
|
|
|
160
|
|
|
true |
|
161
|
|
|
), |
|
162
|
|
|
'fv_corpname' => Tools::getFormfield( |
|
163
|
|
|
'corpname', |
|
164
|
|
|
self::getCustomerFormDefaultValue('cust_corp', 'corpname', $aUserData), |
|
|
|
|
|
|
165
|
|
|
true |
|
166
|
|
|
), |
|
167
|
|
|
'fr_corpname' => HelperConfig::$customer['validate_corpname'], |
|
168
|
|
|
'fv_name' => Tools::getFormfield( |
|
169
|
|
|
'name', |
|
170
|
|
|
self::getCustomerFormDefaultValue('cust_name', 'name', $aUserData), |
|
|
|
|
|
|
171
|
|
|
true |
|
172
|
|
|
), |
|
173
|
|
|
'fr_name' => HelperConfig::$customer['validate_name'], |
|
174
|
|
|
'fv_street' => Tools::getFormfield( |
|
175
|
|
|
'street', |
|
176
|
|
|
self::getCustomerFormDefaultValue('cust_street', 'street', $aUserData), |
|
|
|
|
|
|
177
|
|
|
true |
|
178
|
|
|
), |
|
179
|
|
|
'fr_street' => HelperConfig::$customer['validate_street'], |
|
180
|
|
|
'fv_zip' => Tools::getFormfield( |
|
181
|
|
|
'zip', |
|
182
|
|
|
self::getCustomerFormDefaultValue('cust_zip', 'zip', $aUserData), |
|
|
|
|
|
|
183
|
|
|
true |
|
184
|
|
|
), |
|
185
|
|
|
'fr_zip' => HelperConfig::$customer['validate_zip'], |
|
186
|
|
|
'fv_town' => Tools::getFormfield( |
|
187
|
|
|
'town', |
|
188
|
|
|
self::getCustomerFormDefaultValue('cust_town', 'town', $aUserData), |
|
|
|
|
|
|
189
|
|
|
true |
|
190
|
|
|
), |
|
191
|
|
|
'fr_town' => HelperConfig::$customer['validate_town'], |
|
192
|
|
|
'fv_phone' => Tools::getFormfield( |
|
193
|
|
|
'phone', |
|
194
|
|
|
self::getCustomerFormDefaultValue('cust_phone', 'phone', $aUserData), |
|
|
|
|
|
|
195
|
|
|
true |
|
196
|
|
|
), |
|
197
|
|
|
'fr_phone' => HelperConfig::$customer['validate_phone'], |
|
198
|
|
|
'fv_cellphone' => Tools::getFormfield( |
|
199
|
|
|
'cellphone', |
|
200
|
|
|
self::getCustomerFormDefaultValue('cust_cellphone', 'cellphone', $aUserData), |
|
|
|
|
|
|
201
|
|
|
true |
|
202
|
|
|
), |
|
203
|
|
|
'fr_cellphone' => HelperConfig::$customer['validate_cellphone'], |
|
204
|
|
|
'fv_fax' => Tools::getFormfield( |
|
205
|
|
|
'fax', |
|
206
|
|
|
self::getCustomerFormDefaultValue('cust_fax', 'fax', $aUserData), |
|
|
|
|
|
|
207
|
|
|
true |
|
208
|
|
|
), |
|
209
|
|
|
'fr_fax' => HelperConfig::$customer['validate_fax'], |
|
210
|
|
|
'fv_country' => Tools::getFormfield( |
|
211
|
|
|
'country', |
|
212
|
|
|
($sDefaultCountry ? $sDefaultCountry : self::getDefaultCountryByConfig($sLang)), |
|
|
|
|
|
|
213
|
|
|
true |
|
214
|
|
|
), |
|
215
|
|
|
'fr_country' => HelperConfig::$customer['validate_country'], |
|
216
|
|
|
]; |
|
217
|
|
|
|
|
218
|
|
|
if ($sPurpose === 'admin') { |
|
219
|
|
|
$aData['fv_custgroups'] = HelperConfig::$customer['customer_groups']; |
|
220
|
|
|
$aData['fv_custgroup_selected'] = Tools::getFormfield('custgroup', self::getUserData('cust_group', $aUserData), true); |
|
|
|
|
|
|
221
|
|
|
} elseif ($sPurpose === 'shopadmin') { |
|
222
|
|
|
$aData['fv_custgroup'] = ''; |
|
223
|
|
|
if (isset(HelperConfig::$customer['customer_groups'][self::getUserData('cust_group', $aUserData)])) { |
|
224
|
|
|
$aData['fv_custgroup'] = HelperConfig::$customer['customer_groups'][self::getUserData('cust_group', $aUserData)]; |
|
225
|
|
|
} |
|
226
|
|
|
} |
|
227
|
|
|
|
|
228
|
|
|
if ($sPurpose === 'admin' || $sPurpose === 'register' || $sPurpose === 'editprofile') { |
|
229
|
|
|
$aData['fv_pwd'] = (($sPurpose === 'admin' || $sPurpose === 'editprofile') ? '' : Tools::getFormfield('pwd', '')); |
|
230
|
|
|
$aData['fv_pwdc'] = (($sPurpose === 'admin' || $sPurpose === 'editprofile') ? '' : Tools::getFormfield('pwdc', '')); |
|
231
|
|
|
} |
|
232
|
|
|
|
|
233
|
|
|
if ($sPurpose === 'shoppingcart') { |
|
234
|
|
|
$sRememberedRemarks = ''; |
|
235
|
|
|
if (isset($_SESSION['formsave_addrform']['remarks'])) { |
|
236
|
|
|
$sRememberedRemarks = $_SESSION['formsave_addrform']['remarks']; |
|
237
|
|
|
} |
|
238
|
|
|
$aData['fv_remarks'] = Tools::getFormfield('remarks', $sRememberedRemarks, true); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
if ($sPurpose === 'shoppingcart' || $sPurpose === 'register') { |
|
242
|
|
|
if (!self::getUserData()) { |
|
243
|
|
|
$aData['fv_tos'] = Tools::getCheckbox('tos', 'y'); |
|
244
|
|
|
$aData['fv_cancellationdisclaimer'] = Tools::getCheckbox('cancellationdisclaimer', 'y'); |
|
245
|
|
|
} |
|
246
|
|
|
} |
|
247
|
|
|
|
|
248
|
|
|
if ($sPurpose === 'shoppingcart') { |
|
249
|
|
|
$aData['fv_paymentmethods'] = HelperConfig::$shop['paymentmethods']; |
|
250
|
|
|
$aData['fv_paymentmethod'] = Tools::getFormfield('paymentmethod', ''); |
|
251
|
|
|
} |
|
252
|
|
|
|
|
253
|
|
|
if ($sPurpose === 'admin') { |
|
254
|
|
|
$aData['fv_active'] = self::getUserData('cust_active', $aUserData) === 'y'; |
|
255
|
|
|
$aData['fv_emailverified'] = self::getUserData('cust_emailverified', $aUserData) === 'y'; |
|
256
|
|
|
} |
|
257
|
|
|
return $aData; |
|
258
|
|
|
} |
|
259
|
|
|
|
|
260
|
|
|
/** |
|
261
|
|
|
* @param $sEmailVerificationcode |
|
262
|
|
|
* @param $sTargetAddress |
|
263
|
|
|
* @param ServiceManager $serviceManager |
|
264
|
|
|
* @param bool $bCust |
|
265
|
|
|
*/ |
|
266
|
|
|
public static function sendVerificationMail($sEmailVerificationcode, $sTargetAddress, ServiceManager $serviceManager, $bCust = false) |
|
267
|
|
|
{ |
|
268
|
|
|
if ($bCust) { |
|
269
|
|
|
$sSubject = $serviceManager->get('textcats')->T('register_mail_emailverification_subject'); |
|
270
|
|
|
|
|
271
|
|
|
$serverhttps = filter_input(INPUT_SERVER, 'HTTPS'); |
|
272
|
|
|
$servername = filter_input(INPUT_SERVER, 'SERVER_NAME', FILTER_SANITIZE_URL); |
|
273
|
|
|
$aP['link'] = 'http'.($serverhttps === 'on' ? 's' : '').'://'; |
|
|
|
|
|
|
274
|
|
|
$aP['link'] .= $servername.'/_misc/verifyemail.html?key='.$sEmailVerificationcode; |
|
275
|
|
|
|
|
276
|
|
|
$sMessage = $serviceManager->get('twig')->render('customer/sendverificationmail.twig', $aP); |
|
277
|
|
|
} else { |
|
278
|
|
|
$hardcodedtextcats = $serviceManager->get('hardcodedtextcats'); |
|
279
|
|
|
|
|
280
|
|
|
$sSubject = $hardcodedtextcats->get('newcustomerregistration_mail_subject'); |
|
281
|
|
|
$sMessage = $hardcodedtextcats->get('newcustomerregistration_mail_text1').' '; |
|
282
|
|
|
$sMessage .= $sTargetAddress.$hardcodedtextcats->get( |
|
283
|
|
|
'newcustomerregistration_mail_text2').' '.date(HelperConfig::$core['locale_format_date_time'] |
|
284
|
|
|
); |
|
285
|
|
|
$sTargetAddress = HelperConfig::$core['email_sender']; |
|
286
|
|
|
} |
|
287
|
|
|
|
|
288
|
|
|
\HaaseIT\HCSF\Helper::mailWrapper($sTargetAddress, $sSubject, $sMessage); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
/** |
|
292
|
|
|
* @param string $sField |
|
293
|
|
|
* @param bool $aUserdata |
|
294
|
|
|
* @return bool |
|
295
|
|
|
*/ |
|
296
|
|
|
public static function getUserData($sField = '', $aUserdata = false) |
|
|
|
|
|
|
297
|
|
|
{ |
|
298
|
|
|
if (!$aUserdata) { |
|
299
|
|
|
if (!isset($_SESSION['user']) || !is_array($_SESSION['user'])) { |
|
300
|
|
|
return false; |
|
301
|
|
|
} elseif ($sField == '') { |
|
302
|
|
|
return true; |
|
303
|
|
|
} |
|
304
|
|
|
|
|
305
|
|
|
if ($sField != '' && isset($_SESSION['user'][$sField]) && $_SESSION['user'][$sField] != '') { |
|
306
|
|
|
return $_SESSION['user'][$sField]; |
|
307
|
|
|
} |
|
308
|
|
|
} else { |
|
309
|
|
|
if (isset($aUserdata[$sField])) { |
|
310
|
|
|
return $aUserdata[$sField]; |
|
311
|
|
|
} elseif ($sField = '') { |
|
|
|
|
|
|
312
|
|
|
return false; |
|
313
|
|
|
} |
|
314
|
|
|
} |
|
315
|
|
|
} |
|
316
|
|
|
} |
|
317
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.