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\Controller\Customer; |
22
|
|
|
|
23
|
|
|
use HaaseIT\Toolbox\Tools; |
24
|
|
|
use Zend\ServiceManager\ServiceManager; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class Userhome |
28
|
|
|
* @package HaaseIT\HCSF\Controller\Customer |
29
|
|
|
*/ |
30
|
|
|
class Userhome extends Base |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var \HaaseIT\Toolbox\Textcat |
34
|
|
|
*/ |
35
|
|
|
private $textcats; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var \PDO |
39
|
|
|
*/ |
40
|
|
|
private $db; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Userhome constructor. |
44
|
|
|
* @param ServiceManager $serviceManager |
45
|
|
|
*/ |
46
|
|
|
public function __construct(ServiceManager $serviceManager) |
47
|
|
|
{ |
48
|
|
|
parent::__construct($serviceManager); |
49
|
|
|
$this->textcats = $serviceManager->get('textcats'); |
50
|
|
|
$this->db = $serviceManager->get('db'); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* |
55
|
|
|
*/ |
56
|
|
|
public function preparePage() |
57
|
|
|
{ |
58
|
|
|
$this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
59
|
|
|
$this->P->cb_pagetype = 'content'; |
60
|
|
|
|
61
|
|
|
if (!$this->helperCustomer->getUserData()) { |
62
|
|
|
$this->P->oPayload->cl_html = $this->textcats->T('denied_notloggedin'); |
63
|
|
|
} else { |
64
|
|
|
$this->P->cb_customcontenttemplate = 'customer/customerhome'; |
65
|
|
|
|
66
|
|
|
$aPData['display_logingreeting'] = false; |
|
|
|
|
67
|
|
|
if (filter_input(INPUT_GET, 'login') !== null) { |
68
|
|
|
$aPData['display_logingreeting'] = true; |
69
|
|
|
} |
70
|
|
|
if (filter_input(INPUT_GET, 'editprofile') !== null) { |
71
|
|
|
$aErr = []; |
72
|
|
|
|
73
|
|
|
if (filter_input(INPUT_POST, 'doEdit') === 'yes') { |
74
|
|
|
$sql = 'SELECT '.DB_ADDRESSFIELDS.' FROM customer WHERE cust_id != :id AND cust_email = :email'; |
75
|
|
|
|
76
|
|
|
$sEmail = filter_var(trim(Tools::getFormfield('email')), FILTER_SANITIZE_EMAIL); |
77
|
|
|
|
78
|
|
|
$hResult = $this->db->prepare($sql); |
79
|
|
|
$hResult->bindValue(':id', $_SESSION['user']['cust_id'], \PDO::PARAM_INT); |
80
|
|
|
$hResult->bindValue(':email', $sEmail, \PDO::PARAM_STR); |
81
|
|
|
$hResult->execute(); |
82
|
|
|
$iRows = $hResult->rowCount(); |
83
|
|
|
if ($iRows == 1) { |
84
|
|
|
$aErr['adrform_error_emailalreadytaken'] = true; |
85
|
|
|
} |
86
|
|
|
$aErr = $this->helperCustomer->validateCustomerForm($this->config->getLang(), $aErr, true); |
87
|
|
|
|
88
|
|
|
if (empty($aErr)) { |
89
|
|
|
if ($this->config->getCustomer('allow_edituserprofile')) { |
90
|
|
|
$aData = [ |
91
|
|
|
//'cust_email' => $sEmail, // disabled until renwewd email verification implemented |
92
|
|
|
'cust_corp' => filter_var(trim(Tools::getFormfield('corpname')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
93
|
|
|
'cust_name' => filter_var(trim(Tools::getFormfield('name')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
94
|
|
|
'cust_street' => filter_var(trim(Tools::getFormfield('street')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
95
|
|
|
'cust_zip' => filter_var(trim(Tools::getFormfield('zip')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
96
|
|
|
'cust_town' => filter_var(trim(Tools::getFormfield('town')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
97
|
|
|
'cust_phone' => filter_var(trim(Tools::getFormfield('phone')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
98
|
|
|
'cust_cellphone' => filter_var(trim(Tools::getFormfield('cellphone')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
99
|
|
|
'cust_fax' => filter_var(trim(Tools::getFormfield('fax')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
100
|
|
|
'cust_country' => filter_var(trim(Tools::getFormfield('country')), FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW), |
101
|
|
|
]; |
102
|
|
|
} |
103
|
|
|
$postpwd = filter_input(INPUT_POST, 'pwd'); |
104
|
|
|
if (!empty($postpwd)) { |
105
|
|
|
$aData['cust_password'] = password_hash($postpwd, PASSWORD_DEFAULT); |
|
|
|
|
106
|
|
|
$aPData['infopasswordchanged'] = true; |
107
|
|
|
} |
108
|
|
|
$aData['cust_id'] = $_SESSION['user']['cust_id']; |
109
|
|
|
|
110
|
|
|
if (count($aData) > 1) { |
111
|
|
|
$sql = \HaaseIT\Toolbox\DBTools::buildPSUpdateQuery($aData, 'customer', 'cust_id'); |
112
|
|
|
$hResult = $this->db->prepare($sql); |
113
|
|
|
foreach ($aData as $sKey => $sValue) { |
114
|
|
|
$hResult->bindValue(':'.$sKey, $sValue); |
115
|
|
|
} |
116
|
|
|
$hResult->execute(); |
117
|
|
|
$aPData['infochangessaved'] = true; |
118
|
|
|
} else { |
119
|
|
|
$aPData['infonothingchanged'] = true; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
$this->P->cb_customdata['customerform'] = $this->helperCustomer->buildCustomerForm( |
124
|
|
|
$this->config->getLang(), |
125
|
|
|
'editprofile', |
126
|
|
|
$aErr |
127
|
|
|
); |
128
|
|
|
//if (HelperConfig::$customer["allow_edituserprofile"]) $P["lang"]["cl_html"] .= '<br>'.$this->textcats->T("userprofile_infoeditemail"); // Future implementation |
129
|
|
|
} else { |
130
|
|
|
$this->P->cb_customdata['customerform'] = $this->helperCustomer->buildCustomerForm( |
131
|
|
|
$this->config->getLang(), |
132
|
|
|
'userhome' |
133
|
|
|
); |
134
|
|
|
} |
135
|
|
|
$aPData['showprofilelinks'] = false; |
136
|
|
|
if (filter_input(INPUT_GET, 'editprofile') === null) { |
137
|
|
|
$aPData['showprofilelinks'] = true; |
138
|
|
|
} |
139
|
|
|
if (isset($aPData) && count($aPData)) { |
140
|
|
|
$this->P->cb_customdata['userhome'] = $aPData; |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArray
is initialized the first time when the foreach loop is entered. You can also see that the value of thebar
key is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.