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 / review.php
vikappointments / admin / controllers Last commit date
analytics.php 4 days ago apiban.php 4 days ago apilog.php 4 days ago apiplugin.php 4 days ago apiuser.php 4 days ago backup.php 4 days ago calendar.php 4 days ago city.php 4 days ago closure.php 4 days ago configapp.php 4 days ago configcldays.php 4 days ago configcron.php 4 days ago configemp.php 4 days ago configsmsapi.php 4 days ago configuration.php 4 days ago conversion.php 4 days ago country.php 4 days ago coupon.php 4 days ago coupongroup.php 4 days ago cronjob.php 4 days ago cronjoblog.php 4 days ago customer.php 4 days ago customf.php 4 days ago dashboard.php 4 days ago emplocwdays.php 4 days ago employee.php 4 days ago emprates.php 4 days ago export.php 4 days ago exportres.php 4 days ago file.php 4 days ago findreservation.php 4 days ago group.php 4 days ago import.php 4 days ago index.html 4 days ago invoice.php 4 days ago langcustomf.php 4 days ago langemployee.php 4 days ago langgroup.php 4 days ago langmedia.php 4 days ago langoption.php 4 days ago langoptiongroup.php 4 days ago langpackage.php 4 days ago langpackgroup.php 4 days ago langpayment.php 4 days ago langservice.php 4 days ago langstatuscode.php 4 days ago langsubscr.php 4 days ago langtax.php 4 days ago location.php 4 days ago mailtext.php 4 days ago makerecurrence.php 4 days ago media.php 4 days ago multiorder.php 4 days ago option.php 4 days ago optiongroup.php 4 days ago package.php 4 days ago packgroup.php 4 days ago packorder.php 4 days ago payment.php 4 days ago rate.php 4 days ago reportsemp.php 4 days ago reportsser.php 4 days ago reservation.php 4 days ago restriction.php 4 days ago review.php 4 days ago service.php 4 days ago serworkday.php 4 days ago state.php 4 days ago statuscode.php 4 days ago subscription.php 4 days ago subscrorder.php 4 days ago tag.php 4 days ago tax.php 4 days ago usernote.php 4 days ago waitinglist.php 4 days ago webhook.php 4 days ago wizard.php 4 days ago
review.php
318 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 review controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerReview 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.review.data', array());
35
36 // check user permissions
37 if (!$user->authorise('core.create', 'com_vikappointments') || !$user->authorise('core.access.reviews', '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=managereview');
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.review.data', array());
63
64 // check user permissions
65 if (!$user->authorise('core.edit', 'com_vikappointments') || !$user->authorise('core.access.reviews', '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=managereview&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=review.add');
107 }
108 }
109
110 /**
111 * Task used to save the record data set in the request.
112 * After saving, the user is redirected to the management
113 * page of the record that has been saved.
114 *
115 * @param boolean $copy True to save the record as a copy.
116 *
117 * @return boolean
118 */
119 public function save($copy = false)
120 {
121 $app = JFactory::getApplication();
122 $input = $app->input;
123 $user = JFactory::getUser();
124
125 /**
126 * Added token validation.
127 *
128 * @since 1.7
129 */
130 if (!JSession::checkToken())
131 {
132 // back to main list, missing CSRF-proof token
133 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
134 $this->cancel();
135
136 return false;
137 }
138
139 $args = array();
140 $args['title'] = $input->getString('title', '');
141 $args['jid'] = $input->getUint('jid', 0);
142 $args['name'] = $input->getString('name', '');
143 $args['email'] = $input->getString('email', '');
144 $args['timestamp'] = $input->getString('timestamp', '');
145 $args['rating'] = $input->getUint('rating', 3);
146 $args['published'] = $input->getUint('published', 0);
147 $args['langtag'] = $input->getString('langtag', '');
148 $args['comment'] = $input->getString('comment', '');
149 $args['type'] = $input->getString('type', 'id_service');
150 $args['id'] = $input->getUint('id', 0);
151
152 /**
153 * Convert timestamp from local timezone to UTC.
154 *
155 * @since 1.7
156 */
157 $args['timestamp'] = VAPDateHelper::getSqlDateLocale($args['timestamp']);
158
159 // unset by default both the records
160 $args['id_employee'] = $args['id_service'] = 0;
161
162 // recover record according to the selected type
163 $args[$args['type']] = $input->getUint($args['type'], 0);
164
165 $rule = 'core.' . ($args['id'] > 0 ? 'edit' : 'create');
166
167 // check user permissions
168 if (!$user->authorise($rule, 'com_vikappointments') || !$user->authorise('core.access.reviews', 'com_vikappointments'))
169 {
170 // back to main list, not authorised to create/edit records
171 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
172 $this->cancel();
173
174 return false;
175 }
176
177 // get review model
178 $review = $this->getModel();
179
180 // try to save arguments
181 $id = $review->save($args);
182
183 if (!$id)
184 {
185 // get string error
186 $error = $review->getError(null, true);
187
188 // display error message
189 $app->enqueueMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $error), 'error');
190
191 $url = 'index.php?option=com_vikappointments&view=managereview';
192
193 if ($args['id'])
194 {
195 $url .= '&cid[]=' . $args['id'];
196 }
197
198 // redirect to new/edit page
199 $this->setRedirect($url);
200
201 return false;
202 }
203
204 // display generic successful message
205 $app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS'));
206
207 // redirect to edit page
208 $this->setRedirect('index.php?option=com_vikappointments&task=review.edit&cid[]=' . $id);
209
210 return true;
211 }
212
213 /**
214 * Deletes a list of records set in the request.
215 *
216 * @return boolean
217 */
218 public function delete()
219 {
220 $app = JFactory::getApplication();
221 $user = JFactory::getUser();
222
223 /**
224 * Added token validation.
225 * Both GET and POST are supported.
226 *
227 * @since 1.7
228 */
229 if (!JSession::checkToken() && !JSession::checkToken('get'))
230 {
231 // back to main list, missing CSRF-proof token
232 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
233 $this->cancel();
234
235 return false;
236 }
237
238 $cid = $app->input->get('cid', array(), 'uint');
239
240 // check user permissions
241 if (!$user->authorise('core.delete', 'com_vikappointments') || !$user->authorise('core.access.reviews', 'com_vikappointments'))
242 {
243 // back to main list, not authorised to delete records
244 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
245 $this->cancel();
246
247 return false;
248 }
249
250 // delete selected records
251 $this->getModel()->delete($cid);
252
253 // back to main list
254 $this->cancel();
255
256 return true;
257 }
258
259 /**
260 * Publishes the selected records.
261 *
262 * @return boolean
263 */
264 public function publish()
265 {
266 $app = JFactory::getApplication();
267 $user = JFactory::getUser();
268
269 /**
270 * Added token validation.
271 * Both GET and POST are supported.
272 *
273 * @since 1.7
274 */
275 if (!JSession::checkToken() && !JSession::checkToken('get'))
276 {
277 // back to main list, missing CSRF-proof token
278 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
279 $this->cancel();
280
281 return false;
282 }
283
284 $cid = $app->input->get('cid', array(), 'uint');
285 $task = $app->input->get('task', null);
286
287 $state = $task == 'unpublish' ? 0 : 1;
288
289 // check user permissions
290 if (!$user->authorise('core.edit.state', 'com_vikappointments') || !$user->authorise('core.access.reviews', 'com_vikappointments'))
291 {
292 // back to main list, not authorised to edit records
293 $app->enqueueMessage(JText::translate('JERROR_ALERTNOAUTHOR'), 'error');
294 $this->cancel();
295
296 return false;
297 }
298
299 // change state of selected records
300 $this->getModel()->publish($cid, $state);
301
302 // back to main list
303 $this->cancel();
304
305 return true;
306 }
307
308 /**
309 * Redirects the users to the main records list.
310 *
311 * @return void
312 */
313 public function cancel()
314 {
315 $this->setRedirect('index.php?option=com_vikappointments&view=reviews');
316 }
317 }
318