PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / empeditprofile.php
vikappointments / site / controllers Last commit date
calendarweek.php 3 years ago cart.php 1 month ago confirmapp.php 2 years ago empattachser.php 4 years ago empeditcoupon.php 4 years ago empeditcustfield.php 4 years ago empeditlocation.php 4 years ago empeditpay.php 4 years ago empeditprofile.php 5 months ago empeditservice.php 4 years ago empeditwdays.php 4 years ago emplocwdays.php 4 years ago emplogin.php 2 years ago employeesearch.php 2 years ago employeeslist.php 4 years ago empmakerecur.php 1 month ago empmanres.php 1 month ago empsettings.php 2 years ago empsubscr.php 4 years ago empsubscrorder.php 1 year ago index.html 6 years ago modules.php 1 year ago order.php 5 months ago packages.php 4 years ago packagesconfirm.php 4 years ago packagesorder.php 1 year ago servicesearch.php 2 years ago subscriptions.php 4 years ago subscrpayment.php 1 year ago userprofile.php 5 months ago waitinglist.php 4 years ago
empeditprofile.php
259 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 VAPLoader::import('libraries.employee.area.controller');
15
16 /**
17 * Employee area edit profile controller.
18 *
19 * @since 1.6
20 */
21 class VikAppointmentsControllerEmpeditprofile extends VAPEmployeeAreaController
22 {
23 /**
24 * Task used to access the management page of an existing record.
25 *
26 * @return boolean
27 *
28 * @since 1.7
29 */
30 public function edit()
31 {
32 $app = JFactory::getApplication();
33 $auth = VAPEmployeeAuth::getInstance();
34
35 // unset user state for being recovered again
36 $app->setUserState('vap.emparea.profile.data', array());
37
38 // check user permissions
39 if (!$auth->isEmployee() || !$auth->manage())
40 {
41 // back to main list, not authorised to edit records
42 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
43 $this->cancel();
44
45 return false;
46 }
47
48 $this->setRedirect('index.php?option=com_vikappointments&view=empeditprofile');
49
50 return true;
51 }
52
53 /**
54 * Task used to save the record data set in the request.
55 * After saving, the user is redirected to the main list.
56 *
57 * @return void
58 *
59 * @since 1.7
60 */
61 public function saveclose()
62 {
63 if ($this->save())
64 {
65 $this->cancel();
66 }
67 }
68
69 /**
70 * Task used to save the record data set in the request.
71 * After saving, the user is redirected to the management
72 * page of the record that has been saved.
73 *
74 * @param boolean $copy True to save the record as a copy.
75 *
76 * @return boolean
77 */
78 public function save($copy = false)
79 {
80 $app = JFactory::getApplication();
81 $input = $app->input;
82 $auth = VAPEmployeeAuth::getInstance();
83
84 /**
85 * Added token validation.
86 *
87 * @since 1.7
88 */
89 if (!JSession::checkToken())
90 {
91 // back to main list, missing CSRF-proof token
92 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
93 $this->cancel();
94
95 return false;
96 }
97
98 // check user permissions
99 if (!$auth->isEmployee() || !$auth->manage())
100 {
101 // back to main list, not authorised to edit records
102 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
103 $this->cancel();
104
105 return false;
106 }
107
108 $args = array();
109 $args['firstname'] = $input->getString('firstname');
110 $args['lastname'] = $input->getString('lastname');
111 $args['nickname'] = $input->getString('nickname');
112 $args['email'] = $input->getString('email');
113 $args['notify'] = $input->getUint('notify', 0);
114 $args['showphone'] = $input->getUint('showphone', 0);
115 $args['quick_contact'] = $input->getUint('quick_contact', 0);
116 $args['phone'] = $input->getString('phone');
117 $args['note'] = JComponentHelper::filterText($input->getRaw('note'));
118 $args['id_group'] = $input->getUint('id_group', 0);
119 $args['image'] = $auth->image;
120
121 if ($auth->nickname != $args['nickname'])
122 {
123 // rebuild alias every time the nickname changes
124 $args['alias'] = $args['nickname'];
125 }
126
127 // get employee model
128 $employee = $this->getModel();
129
130 // try to save arguments
131 $id = $employee->save($args);
132
133 if (!$id)
134 {
135 // get string error
136 $error = $employee->getError(null, true);
137
138 // display error message
139 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
140
141 // redirect to edit page
142 $this->setRedirect('index.php?option=com_vikappointments&view=empeditprofile');
143
144 return false;
145 }
146
147 // display generic successful message
148 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
149
150 // redirect to edit page
151 $this->setRedirect('index.php?option=com_vikappointments&task=empeditprofile.edit');
152
153 return true;
154 }
155
156 /**
157 * Task used to save the custom fields set in the request.
158 * After saving, the user is redirected to the main list.
159 *
160 * @return void
161 *
162 * @since 1.7.8
163 */
164 public function saveclosefields()
165 {
166 if ($this->savefields())
167 {
168 $this->cancel();
169 }
170 }
171
172 /**
173 * Task used to save the custom fields set in the request.
174 * After saving, the user is redirected to the management
175 * page of the record that has been saved.
176 *
177 * @param bool $copy True to save the record as a copy.
178 *
179 * @return bool
180 *
181 * @since 1.7.8
182 */
183 public function savefields($copy = false)
184 {
185 $app = JFactory::getApplication();
186 $auth = VAPEmployeeAuth::getInstance();
187
188 if (!JSession::checkToken())
189 {
190 // back to main list, missing CSRF-proof token
191 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
192 $this->cancel();
193
194 return false;
195 }
196
197 // check user permissions
198 if (!$auth->isEmployee())
199 {
200 // back to main list, not authorised to edit records
201 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
202 $this->cancel();
203
204 return false;
205 }
206
207 $missingRequiredFields = $auth->getMissingRequiredFields($this->customFields);
208
209 if (!$auth->manage() && !$missingRequiredFields)
210 {
211 // back to main list, there are no required fields to update
212 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
213 $this->cancel();
214
215 return false;
216 }
217
218 // get employee model
219 $employee = $this->getModel();
220
221 // try to save arguments
222 $id = $employee->saveFields();
223
224 if (!$id)
225 {
226 // get string error
227 $error = $employee->getError(null, true);
228
229 // display error message
230 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
231
232 // redirect to edit page
233 $this->setRedirect('index.php?option=com_vikappointments&view=empeditprofile');
234
235 return false;
236 }
237
238 // display generic successful message
239 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
240
241 // redirect to the login page
242 $this->setRedirect('index.php?option=com_vikappointments&task=emplogin');
243
244 return true;
245 }
246
247 /**
248 * Redirects the users to the main records list.
249 *
250 * @return void
251 *
252 * @since 1.7
253 */
254 public function cancel()
255 {
256 $this->setRedirect('index.php?option=com_vikappointments&view=emplogin');
257 }
258 }
259