PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / location.php
vikappointments / admin / controllers Last commit date
analytics.php 2 days ago apiban.php 2 days ago apilog.php 2 days ago apiplugin.php 2 days ago apiuser.php 2 days ago backup.php 2 days ago calendar.php 2 days ago city.php 2 days ago closure.php 2 days ago configapp.php 2 days ago configcldays.php 2 days ago configcron.php 2 days ago configemp.php 2 days ago configsmsapi.php 2 days ago configuration.php 2 days ago conversion.php 2 days ago country.php 2 days ago coupon.php 2 days ago coupongroup.php 2 days ago cronjob.php 2 days ago cronjoblog.php 2 days ago customer.php 2 days ago customf.php 2 days ago dashboard.php 2 days ago emplocwdays.php 2 days ago employee.php 2 days ago emprates.php 2 days ago export.php 2 days ago exportres.php 2 days ago file.php 2 days ago findreservation.php 2 days ago group.php 2 days ago import.php 2 days ago index.html 2 days ago invoice.php 2 days ago langcustomf.php 2 days ago langemployee.php 2 days ago langgroup.php 2 days ago langmedia.php 2 days ago langoption.php 2 days ago langoptiongroup.php 2 days ago langpackage.php 2 days ago langpackgroup.php 2 days ago langpayment.php 2 days ago langservice.php 2 days ago langstatuscode.php 2 days ago langsubscr.php 2 days ago langtax.php 2 days ago location.php 2 days ago mailtext.php 2 days ago makerecurrence.php 2 days ago media.php 2 days ago multiorder.php 2 days ago option.php 2 days ago optiongroup.php 2 days ago package.php 2 days ago packgroup.php 2 days ago packorder.php 2 days ago payment.php 2 days ago rate.php 2 days ago reportsemp.php 2 days ago reportsser.php 2 days ago reservation.php 2 days ago restriction.php 2 days ago review.php 2 days ago service.php 2 days ago serworkday.php 2 days ago state.php 2 days ago statuscode.php 2 days ago subscription.php 2 days ago subscrorder.php 2 days ago tag.php 2 days ago tax.php 2 days ago usernote.php 2 days ago waitinglist.php 2 days ago webhook.php 2 days ago wizard.php 2 days ago
location.php
303 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.mvc.controllers.admin');
15
16 /**
17 * VikAppointments location controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerLocation extends VAPControllerAdmin
22 {
23 /**
24 * Task used to access the creation page of a new record.
25 *
26 * @return boolean
27 */
28 public function add()
29 {
30 $app = JFactory::getApplication();
31 $user = JFactory::getUser();
32
33 // unset user state for being recovered again
34 $app->setUserState('vap.location.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.locations', 'com_vikappointments'))
38 {
39 // back to main list, not authorised to create records
40 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
41 $this->cancel();
42
43 return false;
44 }
45
46 $url = 'index.php?option=com_vikappointments&view=managelocation';
47
48 $id_employee = $app->input->getUint('id_employee', 0);
49
50 if ($id_employee)
51 {
52 $url .= '&id_employee=' . $id_employee;
53 }
54
55 $this->setRedirect($url);
56
57 return true;
58 }
59
60 /**
61 * Task used to access the management page of an existing record.
62 *
63 * @return boolean
64 */
65 public function edit()
66 {
67 $app = JFactory::getApplication();
68 $user = JFactory::getUser();
69
70 // unset user state for being recovered again
71 $app->setUserState('vap.location.data', array());
72
73 // check user permissions
74 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.locations', 'com_vikappointments'))
75 {
76 // back to main list, not authorised to edit records
77 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
78 $this->cancel();
79
80 return false;
81 }
82
83 $cid = $app->input->getUint('cid', array(0));
84
85 $url = 'index.php?option=com_vikappointments&view=managelocation&cid[]=' . $cid[0];
86
87 $id_employee = $app->input->getUint('id_employee', 0);
88
89 if ($id_employee)
90 {
91 $url .= '&id_employee=' . $id_employee;
92 }
93
94 $this->setRedirect($url);
95
96 return true;
97 }
98
99 /**
100 * Task used to save the record data set in the request.
101 * After saving, the user is redirected to the main list.
102 *
103 * @return void
104 */
105 public function saveclose()
106 {
107 if ($this->save())
108 {
109 $this->cancel();
110 }
111 }
112
113 /**
114 * Task used to save the record data set in the request.
115 * After saving, the user is redirected to the creation
116 * page of a new record.
117 *
118 * @return void
119 */
120 public function savenew()
121 {
122 if ($this->save())
123 {
124 $url = 'index.php?option=com_vikappointments&task=location.add';
125
126 $id_employee = JFactory::getApplication()->input->getUint('id_employee', 0);
127
128 if ($id_employee)
129 {
130 $url .= '&id_employee=' . $id_employee;
131 }
132
133 $this->setRedirect($url);
134 }
135 }
136
137 /**
138 * Task used to save the record data set in the request.
139 * After saving, the user is redirected to the management
140 * page of the record that has been saved.
141 *
142 * @return boolean
143 */
144 public function save()
145 {
146 $app = JFactory::getApplication();
147 $input = $app->input;
148 $user = JFactory::getUser();
149
150 /**
151 * Added token validation.
152 *
153 * @since 1.7
154 */
155 if (!JSession::checkToken())
156 {
157 // back to main list, missing CSRF-proof token
158 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
159 $this->cancel();
160
161 return false;
162 }
163
164 $id_employee = $input->getUint('id_employee', 0);
165
166 $args = array();
167 $args['name'] = $input->getString('name');
168 $args['id_employee'] = $input->getUint('id_emp', $id_employee);
169 $args['id_country'] = $input->getUint('id_country', 0);
170 $args['id_state'] = $input->getUint('id_state', 0);
171 $args['id_city'] = $input->getUint('id_city', 0);
172 $args['address'] = $input->getString('address', '');
173 $args['zip'] = $input->getString('zip', '');
174 $args['latitude'] = $input->getString('latitude', '');
175 $args['longitude'] = $input->getString('longitude', '');
176 $args['id'] = $input->getUint('id', 0);
177
178 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
179
180 // check user permissions
181 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.locations', 'com_vikappointments'))
182 {
183 // back to main list, not authorised to create/edit records
184 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
185 $this->cancel();
186
187 return false;
188 }
189
190 // get location model
191 $location = $this->getModel();
192
193 // try to save arguments
194 $id = $location->save($args);
195
196 if (!$id)
197 {
198 // get string error
199 $error = $location->getError(null, true);
200
201 // display error message
202 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
203
204 $url = 'index.php?option=com_vikappointments&view=managelocation';
205
206 if ($args['id'])
207 {
208 $url .= '&cid[]=' . $args['id'];
209 }
210
211 if ($id_employee)
212 {
213 $url .= '&id_employee=' . $id_employee;
214 }
215
216 // redirect to new/edit page
217 $this->setRedirect($url);
218
219 return false;
220 }
221
222 // display generic successful message
223 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
224
225 $url = 'index.php?option=com_vikappointments&task=location.edit&cid[]=' . $id;
226
227 if ($id_employee)
228 {
229 $url .= '&id_employee=' . $id_employee;
230 }
231
232 // redirect to edit page
233 $this->setRedirect($url);
234
235 return true;
236 }
237
238 /**
239 * Deletes a list of records set in the request.
240 *
241 * @return boolean
242 */
243 public function delete()
244 {
245 $app = JFactory::getApplication();
246 $user = JFactory::getUser();
247
248 /**
249 * Added token validation.
250 * Both GET and POST are supported.
251 *
252 * @since 1.7
253 */
254 if (!JSession::checkToken() && !JSession::checkToken('get'))
255 {
256 // back to main list, missing CSRF-proof token
257 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
258 $this->cancel();
259
260 return false;
261 }
262
263 $cid = $app->input->get('cid', array(), 'uint');
264
265 // check user permissions
266 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.locations', 'com_vikappointments'))
267 {
268 // back to main list, not authorised to delete records
269 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
270 $this->cancel();
271
272 return false;
273 }
274
275 // delete selected records
276 $this->getModel()->delete($cid);
277
278 // back to main list
279 $this->cancel();
280
281 return true;
282 }
283
284 /**
285 * Redirects the users to the main records list.
286 *
287 * @return void
288 */
289 public function cancel()
290 {
291 $id_employee = JFactory::getApplication()->input->getUint('id_employee', 0);
292
293 $url = 'index.php?option=com_vikappointments&view=locations';
294
295 if ($id_employee)
296 {
297 $url .= '&id_employee=' . $id_employee;
298 }
299
300 $this->setRedirect($url);
301 }
302 }
303