PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / empeditlocation.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
empeditlocation.php
315 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 location controller.
18 *
19 * @since 1.6
20 */
21 class VikAppointmentsControllerEmpeditlocation extends VAPEmployeeAreaController
22 {
23 /**
24 * Task used to access the creation page of a new record.
25 *
26 * @return boolean
27 *
28 * @since 1.7
29 */
30 public function add()
31 {
32 $app = JFactory::getApplication();
33 $auth = VAPEmployeeAuth::getInstance();
34
35 // unset user state for being recovered again
36 $app->setUserState('vap.emparea.location.data', array());
37
38 // check user permissions
39 if (!$auth->manageLocations())
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=empeditlocation');
49
50 return true;
51 }
52
53 /**
54 * Task used to access the management page of an existing record.
55 *
56 * @return boolean
57 *
58 * @since 1.7
59 */
60 public function edit()
61 {
62 $app = JFactory::getApplication();
63 $auth = VAPEmployeeAuth::getInstance();
64
65 // unset user state for being recovered again
66 $app->setUserState('vap.emparea.location.data', array());
67
68 $cid = $app->input->getUint('cid', array(0));
69
70 // check user permissions
71 if (!$auth->manageLocations($cid[0]))
72 {
73 // back to main list, not authorised to edit records
74 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
75 $this->cancel();
76
77 return false;
78 }
79
80 $this->setRedirect('index.php?option=com_vikappointments&view=empeditlocation&cid[]=' . $cid[0]);
81
82 return true;
83 }
84
85 /**
86 * Task used to save the record data set in the request.
87 * After saving, the user is redirected to the main list.
88 *
89 * @return void
90 *
91 * @since 1.7
92 */
93 public function saveclose()
94 {
95 if ($this->save())
96 {
97 $this->cancel();
98 }
99 }
100
101 /**
102 * Save employee location.
103 *
104 * @return void
105 */
106 public function save()
107 {
108 $app = JFactory::getApplication();
109 $input = $app->input;
110 $auth = VAPEmployeeAuth::getInstance();
111
112 /**
113 * Added token validation.
114 *
115 * @since 1.7
116 */
117 if (!JSession::checkToken())
118 {
119 // back to main list, missing CSRF-proof token
120 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
121 $this->cancel();
122
123 return false;
124 }
125
126 $id_location = $input->getUint('id', 0);
127
128 // check user permissions
129 if (!$auth->manageLocations($id_location))
130 {
131 // back to main list, not authorised to edit records
132 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
133 $this->cancel();
134
135 return false;
136 }
137
138 // get args
139 $args = array();
140 $args['name'] = $input->getString('name', '');
141 $args['id_country'] = $input->getUint('id_country', 0);
142 $args['id_state'] = $input->getUint('id_state', 0);
143 $args['id_city'] = $input->getUint('id_city', 0);
144 $args['address'] = $input->getString('address', '');
145 $args['zip'] = $input->getString('zip', '');
146 $args['latitude'] = $input->getFloat('latitude', 0);
147 $args['longitude'] = $input->getFloat('longitude', 0);
148 $args['id'] = $id_location;
149
150 // get location model
151 $model = $this->getModel();
152
153 // try to save arguments
154 $id = $model->save($args);
155
156 if (!$id)
157 {
158 // get string error
159 $error = $model->getError(null, true);
160
161 // display error message
162 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
163
164 $url = 'index.php?option=com_vikappointments&view=empeditlocation';
165
166 if ($id_location)
167 {
168 $url .= '&cid[]=' . $id_location;
169 }
170
171 // redirect to edit page
172 $this->setRedirect($url);
173
174 return false;
175 }
176
177 // display generic successful message
178 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
179
180 // redirect to edit page
181 $this->setRedirect('index.php?option=com_vikappointments&task=empeditlocation.edit&cid[]=' . $id);
182
183 return true;
184 }
185
186 /**
187 * Removes the location.
188 *
189 * @return void
190 */
191 public function delete()
192 {
193 $app = JFactory::getApplication();
194 $cid = $app->input->get('cid', array(), 'uint');
195
196 if ($id = $app->input->getUint('id'))
197 {
198 $cid[] = $id;
199 }
200
201 /**
202 * Added token validation.
203 * Both GET and POST are supported.
204 *
205 * @since 1.7
206 */
207 if (!JSession::checkToken() && !JSession::checkToken('get'))
208 {
209 // back to main list, missing CSRF-proof token
210 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
211 $this->cancel();
212
213 return false;
214 }
215
216 try
217 {
218 // delete selected records
219 if ($this->getModel()->delete($cid))
220 {
221 $app->enqueueMessage(JText::translate('VAPEMPLOCATIONREMOVED1'));
222 }
223 }
224 catch (Exception $e)
225 {
226 // an error occurred
227 $app->enqueueMessage($e->getMessage(), 'error');
228 $this->cancel();
229
230 return false;
231 }
232
233 // back to main list
234 $this->cancel();
235
236 return true;
237 }
238
239 /**
240 * Redirects the users to the main records list.
241 *
242 * @return void
243 *
244 * @since 1.7
245 */
246 public function cancel()
247 {
248 $this->setRedirect('index.php?option=com_vikappointments&view=emplocations');
249 }
250
251 /**
252 * AJAX end-point used to obtain all the states assigned to the given country.
253 * The task expects the following parameters to be set in request.
254 *
255 * @param integer id_country The country ID.
256 *
257 * @return void
258 *
259 * @since 1.7
260 */
261 function statesajax()
262 {
263 $input = JFactory::getApplication()->input;
264
265 /**
266 * Added token validation.
267 *
268 * @since 1.7
269 */
270 if (!JSession::checkToken())
271 {
272 // missing CSRF-proof token
273 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
274 }
275
276 $id_country = $input->getUint('id_country', 0);
277 $states = VAPLocations::getStates($id_country, 'state_name');
278
279 // send states to caller
280 $this->sendJSON($states);
281 }
282
283 /**
284 * AJAX end-point used to obtain all the cities assigned to the given state.
285 * The task expects the following parameters to be set in request.
286 *
287 * @param integer id_state The state ID.
288 *
289 * @return void
290 *
291 * @since 1.7
292 */
293 function citiesajax()
294 {
295 $input = JFactory::getApplication()->input;
296
297 /**
298 * Added token validation.
299 *
300 * @since 1.7
301 */
302 if (!JSession::checkToken())
303 {
304 // missing CSRF-proof token
305 UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN'));
306 }
307
308 $id_state = $input->getUint('id_state', 0);
309 $cities = VAPLocations::getCities($id_state, 'city_name');
310
311 // send cities to caller
312 $this->sendJSON($cities);
313 }
314 }
315