PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / location.php
vikappointments / admin / controllers Last commit date
analytics.php 4 years ago apiban.php 4 years ago apilog.php 4 years ago apiplugin.php 4 years ago apiuser.php 4 years ago backup.php 4 years ago calendar.php 4 years ago city.php 4 years ago closure.php 1 month ago configapp.php 4 years ago configcldays.php 2 years ago configcron.php 4 years ago configemp.php 4 years ago configsmsapi.php 4 years ago configuration.php 1 month ago conversion.php 1 year ago country.php 4 years ago coupon.php 4 years ago coupongroup.php 4 years ago cronjob.php 2 years ago cronjoblog.php 4 years ago customer.php 5 months ago customf.php 1 year ago dashboard.php 4 years ago emplocwdays.php 4 years ago employee.php 1 year ago emprates.php 4 years ago export.php 4 years ago exportres.php 4 years ago file.php 5 months ago findreservation.php 1 month ago group.php 4 years ago import.php 4 years ago index.html 4 years ago invoice.php 1 month ago langcustomf.php 4 years ago langemployee.php 4 years ago langgroup.php 4 years ago langmedia.php 4 years ago langoption.php 4 years ago langoptiongroup.php 4 years ago langpackage.php 4 years ago langpackgroup.php 4 years ago langpayment.php 4 years ago langservice.php 4 years ago langstatuscode.php 4 years ago langsubscr.php 4 years ago langtax.php 4 years ago location.php 4 years ago mailtext.php 2 years ago makerecurrence.php 1 month ago media.php 4 years ago multiorder.php 4 years ago option.php 5 months ago optiongroup.php 4 years ago package.php 2 years ago packgroup.php 4 years ago packorder.php 1 year ago payment.php 4 years ago rate.php 4 years ago reportsemp.php 4 years ago reportsser.php 4 years ago reservation.php 1 month ago restriction.php 4 years ago review.php 4 years ago service.php 1 year ago serworkday.php 5 months ago state.php 4 years ago statuscode.php 4 years ago subscription.php 4 years ago subscrorder.php 4 years ago tag.php 4 years ago tax.php 4 years ago usernote.php 4 years ago waitinglist.php 4 years ago webhook.php 4 years ago wizard.php 1 year 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