PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
trunk 1.2.17 1.2.18 1.2.19
vikappointments / admin / controllers / conversion.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
conversion.php
334 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 conversion code controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerConversion 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.conversion.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.config', '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 $this->setRedirect('index.php?option=com_vikappointments&view=manageconversion');
47
48 return true;
49 }
50
51 /**
52 * Task used to access the management page of an existing record.
53 *
54 * @return boolean
55 */
56 public function edit()
57 {
58 $app = JFactory::getApplication();
59 $user = JFactory::getUser();
60
61 // unset user state for being recovered again
62 $app->setUserState('vap.conversion.data', array());
63
64 // check user permissions
65 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.config', 'com_vikappointments'))
66 {
67 // back to main list, not authorised to edit records
68 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
69 $this->cancel();
70
71 return false;
72 }
73
74 $cid = $app->input->getUint('cid', array(0));
75
76 $this->setRedirect('index.php?option=com_vikappointments&view=manageconversion&cid[]=' . $cid[0]);
77
78 return true;
79 }
80
81 /**
82 * Task used to save the record data set in the request.
83 * After saving, the user is redirected to the main list.
84 *
85 * @return void
86 */
87 public function saveclose()
88 {
89 if ($this->save())
90 {
91 $this->cancel();
92 }
93 }
94
95 /**
96 * Task used to save the record data set in the request.
97 * After saving, the user is redirected to the creation
98 * page of a new record.
99 *
100 * @return void
101 */
102 public function savenew()
103 {
104 if ($this->save())
105 {
106 $this->setRedirect('index.php?option=com_vikappointments&task=conversion.add');
107 }
108 }
109
110 /**
111 * Task used to save the record data as a copy of the current item.
112 * After saving, the user is redirected to the management
113 * page of the record that has been saved.
114 *
115 * @return void
116 */
117 public function savecopy()
118 {
119 $this->save(true);
120 }
121
122 /**
123 * Task used to save the record data set in the request.
124 * After saving, the user is redirected to the management
125 * page of the record that has been saved.
126 *
127 * @param boolean $copy True to save the record as a copy.
128 *
129 * @return boolean
130 */
131 public function save($copy = false)
132 {
133 $app = JFactory::getApplication();
134 $input = $app->input;
135 $user = JFactory::getUser();
136
137 /**
138 * Added token validation.
139 *
140 * @since 1.7
141 */
142 if (!JSession::checkToken())
143 {
144 // back to main list, missing CSRF-proof token
145 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
146 $this->cancel();
147
148 return false;
149 }
150
151 $args = array();
152 $args['title'] = $input->getString('title', '');
153 $args['published'] = $input->getUint('published', 0);
154 $args['statuses'] = $input->getString('statuses', array());
155 $args['jsfile'] = $input->getString('jsfile', '');
156 $args['snippet'] = $input->getRaw('snippet', '');
157 $args['page'] = $input->getString('page', '');
158 $args['type'] = $input->getString('type', '');
159 $args['id'] = $input->getUint('id', 0);
160
161 $args['attributes'] = [];
162 $attrName = $input->getString('attribute_name', []);
163 $attrValue = $input->getString('attribute_value', []);
164
165 for ($i = 0; $i < count($attrName); $i++) {
166 $v = ($attrValue[$i] ?? '');
167
168 if ($v === '') {
169 $v = true;
170 }
171
172 $args['attributes'][$attrName[$i]] = $v;
173 }
174
175 if ($copy)
176 {
177 // unset ID to create a copy
178 $args['id'] = 0;
179 }
180
181 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
182
183 // check user permissions
184 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.config', 'com_vikappointments'))
185 {
186 // back to main list, not authorised to create/edit records
187 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
188 $this->cancel();
189
190 return false;
191 }
192
193 // get conversion model
194 $conversion = $this->getModel();
195
196 // try to save arguments
197 $id = $conversion->save($args);
198
199 if (!$id)
200 {
201 // get string error
202 $error = $conversion->getError(null, true);
203
204 // display error message
205 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
206
207 $url = 'index.php?option=com_vikappointments&view=manageconversion';
208
209 if ($args['id'])
210 {
211 $url .= '&cid[]=' . $args['id'];
212 }
213
214 // redirect to new/edit page
215 $this->setRedirect($url);
216
217 return false;
218 }
219
220 // display generic successful message
221 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
222
223 // redirect to edit page
224 $this->setRedirect('index.php?option=com_vikappointments&task=conversion.edit&cid[]=' . $id);
225
226 return true;
227 }
228
229 /**
230 * Deletes a list of records set in the request.
231 *
232 * @return boolean
233 */
234 public function delete()
235 {
236 $app = JFactory::getApplication();
237 $user = JFactory::getUser();
238
239 /**
240 * Added token validation.
241 * Both GET and POST are supported.
242 *
243 * @since 1.7
244 */
245 if (!JSession::checkToken() && !JSession::checkToken('get'))
246 {
247 // back to main list, missing CSRF-proof token
248 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
249 $this->cancel();
250
251 return false;
252 }
253
254 $cid = $app->input->get('cid', array(), 'uint');
255
256 // check user permissions
257 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.config', 'com_vikappointments'))
258 {
259 // back to main list, not authorised to delete records
260 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
261 $this->cancel();
262
263 return false;
264 }
265
266 // delete selected records
267 $this->getModel()->delete($cid);
268
269 // back to main list
270 $this->cancel();
271
272 return true;
273 }
274
275 /**
276 * Publishes the selected records.
277 *
278 * @return boolean
279 */
280 public function publish()
281 {
282 $app = JFactory::getApplication();
283 $user = JFactory::getUser();
284
285 /**
286 * Added token validation.
287 * Both GET and POST are supported.
288 *
289 * @since 1.7
290 */
291 if (!JSession::checkToken() && !JSession::checkToken('get'))
292 {
293 // back to main list, missing CSRF-proof token
294 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
295 $this->cancel();
296
297 return false;
298 }
299
300 $cid = $app->input->get('cid', array(), 'uint');
301 $task = $app->input->get('task', null);
302
303 $state = $task == 'unpublish' ? 0 : 1;
304
305 // check user permissions
306 if (!$user->authorise('core.edit.state', 'com_vikappointments') || !$user->authorise('core.access.config', 'com_vikappointments'))
307 {
308 // back to main list, not authorised to edit records
309 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
310 $this->cancel();
311
312 return false;
313 }
314
315 // change state of selected records
316 $this->getModel()->publish($cid, $state);
317
318 // back to main list
319 $this->cancel();
320
321 return true;
322 }
323
324 /**
325 * Redirects the users to the main records list.
326 *
327 * @return void
328 */
329 public function cancel()
330 {
331 $this->setRedirect('index.php?option=com_vikappointments&view=conversions');
332 }
333 }
334