PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / trunk
VikAppointments Services Booking Calendar vtrunk
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / controllers / employeesearch.php
vikappointments / site / controllers Last commit date
calendarweek.php 3 years ago cart.php 3 months ago confirmapp.php 1 day 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 6 months ago empeditservice.php 4 years ago empeditwdays.php 4 years ago emplocwdays.php 4 years ago emplogin.php 1 day ago employeesearch.php 1 day ago employeeslist.php 4 years ago empmakerecur.php 3 months ago empmanres.php 3 months ago empsettings.php 2 years ago empsubscr.php 4 years ago empsubscrorder.php 2 years ago index.html 7 years ago modules.php 2 years ago order.php 6 months ago packages.php 4 years ago packagesconfirm.php 4 years ago packagesorder.php 2 years ago servicesearch.php 1 day ago subscriptions.php 4 years ago subscrpayment.php 2 years ago userprofile.php 1 day ago waitinglist.php 4 years ago
employeesearch.php
322 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 employee search view controller.
18 *
19 * @since 1.7
20 */
21 class VikAppointmentsControllerEmployeesearch extends VAPControllerAdmin
22 {
23 /**
24 * Task used to send a contact message to the specified employee.
25 * This method expects the following parameters to be sent
26 * via POST or GET.
27 *
28 * @param integer id_employee The ID of the employee.
29 * @param string sendername The sender name.
30 * @param string sendermail The sender e-mail.
31 * @param string mail_content The contents to send via mail.
32 * @param string return An optional return URL.
33 *
34 * @return boolean
35 */
36 public function quickcontact()
37 {
38 $app = JFactory::getApplication();
39 $input = $app->input;
40 $dbo = JFactory::getDbo();
41
42 $itemid = $input->getInt('Itemid');
43
44 $id_employee = $input->getUint('id_employee', 0);
45 $name = $input->getString('sendername');
46 $email = $input->getString('sendermail');
47 $content = $input->getString('mail_content');
48
49 $return_url = $input->getBase64('return');
50
51 if ($return_url)
52 {
53 // use given URL
54 $return_url = base64_decode($return_url);
55 }
56 else
57 {
58 // create new URL
59 $return_url = 'index.php?option=com_vikappointments&view=employeeslist&id_emp=' . $id_employee;
60
61 if ($itemid)
62 {
63 $return_url .= '&Itemid=' . $itemid;
64 }
65 }
66
67 // set return URL as redirect
68 $this->setRedirect(JRoute::rewrite($return_url, false));
69
70 // validate session token to avoid direct requests
71 if (!JSession::checkToken())
72 {
73 // invalid session token
74 $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error');
75 return false;
76 }
77
78 $vik = VAPApplication::getInstance();
79
80 // in case of CAPTCHA, validate it
81 if (($captcha = $vik->getGlobalCaptcha()) && !$vik->captcha('check', ['captcha' => $captcha, 'name' => 'contact']))
82 {
83 // invalid captcha
84 $app->enqueueMessage(JText::translate('PLG_RECAPTCHA_ERROR_EMPTY_SOLUTION'), 'error');
85 return false;
86 }
87
88 // get view model
89 $model = $this->getModel();
90
91 // try to send the e-mail to the employee
92 if (!$model->askQuestion($id_employee, $name, $email, $content))
93 {
94 // extract error from model
95 $error = $model->getError($index = null, $string = true);
96 $app->enqueueMessage($error, 'error');
97 return false;
98 }
99
100 // e-mail sent successfully
101 $app->enqueueMessage(JText::translate('VAPQUICKCONTACTMAILSENT'));
102 return true;
103 }
104
105 /**
106 * Task used to leave a review for the specified employee.
107 * This method expects the following parameters to be sent
108 * via POST or GET.
109 *
110 * @param string title The review title.
111 * @param string comment The review comment.
112 * @param integer rating The review rating (1-5).
113 * @param integer id_employee The ID of the employee to review.
114 *
115 * @return boolean
116 */
117 public function leavereview()
118 {
119 $app = JFactory::getApplication();
120 $input = $app->input;
121
122 $args = array();
123 $args['title'] = $input->getString('title');
124 $args['comment'] = $input->getString('comment');
125 $args['rating'] = $input->getUint('rating', 0);
126 $args['id_employee'] = $input->getUint('id_employee', 0);
127
128 $itemid = $input->getUint('Itemid');
129 $this->setRedirect(JRoute::rewrite('index.php?option=com_vikappointments&view=employeesearch&id_employee=' . $args['id_employee'] . ($itemid ? '&Itemid=' . $itemid : ''), false));
130
131 // get review model
132 $model = $this->getModel('review');
133
134 if (!$model->leave($args))
135 {
136 // get last error fetched
137 $error = $model->getError($index = null, $string = true);
138 $app->enqueueMessage($error ? $error : JText::translate('VAPPOSTREVIEWINSERTERR'), 'error');
139 return false;
140 }
141
142 if ($model->getData()->published)
143 {
144 // review published
145 $app->enqueueMessage(JText::translate('VAPPOSTREVIEWCREATEDCONF'));
146 }
147 else
148 {
149 // review waiting for approval
150 $app->enqueueMessage(JText::translate('VAPPOSTREVIEWCREATEDPEND'));
151 }
152
153 return true;
154 }
155
156 /**
157 * AJAX task used to load more reviews for the specified employee.
158 * This method expects the following parameters to be sent
159 * via POST or GET.
160 *
161 * @param integer id_employee The employee ID.
162 * @param integer start The starting limit.
163 *
164 * @return void
165 */
166 public function loadreviews()
167 {
168 $app = JFactory::getApplication();
169 $input = $app->input;
170
171 $id_emp = $input->getUint('id_employee', 0);
172 $lim0 = $input->getUint('start', 0);
173
174 $reviews = VikAppointments::loadReviews('employee', $id_emp, $lim0);
175
176 $result = new stdClass;
177 $result->size = $reviews->size;
178 $result->reviews = array();
179
180 foreach ($reviews->rows as $review)
181 {
182 $data = array(
183 'review' => $review,
184 'datetime_format' => JText::translate('DATE_FORMAT_LC2'),
185 );
186
187 /**
188 * The review block is displayed from the layout below:
189 * /components/com_vikappointments/layouts/review/default.php
190 *
191 * If you need to change something from this layout, just create
192 * an override of this layout by following the instructions below:
193 * - open the back-end of your Joomla
194 * - visit the Extensions > Templates > Templates page
195 * - edit the active template
196 * - access the "Create Overrides" tab
197 * - select Layouts > com_vikappointments > review
198 * - start editing the default.php file on your template to create your own layout
199 *
200 * @since 1.6
201 */
202 $result->reviews[] = JLayoutHelper::render('review.default', $data);
203 }
204
205 // send reviews to caller
206 $this->sendJSON($result);
207 }
208
209 /**
210 * AJAX end-point used to fetch the availability timeline.
211 * This task expects the following arguments set in request.
212 *
213 * @param integer $id_ser The service ID.
214 * @param integer $id_emp The employee ID.
215 * @param string $day The check-in date.
216 * @param integer $people The number of participants.
217 * @param array $locations A list of selected locations.
218 *
219 * @return void
220 */
221 public function timelineajax()
222 {
223 $input = JFactory::getApplication()->input;
224
225 $args = array();
226 $args['id_emp'] = $input->getUint('id_emp', 0);
227 $args['id_ser'] = $input->getUint('id_ser', 0);
228 $args['date'] = $input->getString('day', '');
229 $args['people'] = $input->getUint('people', 1);
230 $args['locations'] = $input->getUint('locations', null);
231 $args['admin'] = $input->getBool('admin', false);
232
233 if ($args['admin'])
234 {
235 // requested administrator right, make sure the user is an employee
236 $args['admin'] = VAPEmployeeAuth::getInstance()->isEmployee();
237
238 if ($args['admin'])
239 {
240 // in case of employee, check if we are editing a reservation
241 $args['id_res'] = $input->getUint('id_res');
242 }
243 }
244
245 // get model
246 $model = $this->getModel();
247 // use model to create the timeline
248 $timeline = $model->getTimeline($args);
249
250 $result = new stdClass;
251
252 if ($timeline)
253 {
254 // create timeline response
255 $result->html = $timeline->display();
256 $result->timeline = $timeline->getTimeline();
257
258 // recalculate rate by specifing the selected arguments
259 $result->rate = VAPSpecialRates::getRate($args['id_ser'], $args['id_emp'], $args['date'], $args['people']);
260
261 // fetch service details
262 $service = $this->getModel('service')->getItem($args['id_ser']);
263
264 if ($service->priceperpeople)
265 {
266 // multiply by the number of selected participants
267 $result->rate *= $args['people'];
268 }
269 }
270 else
271 {
272 // raise error message
273 $result->error = $model->getError($index = null, $string = true);
274 $result->timeline = array();
275 }
276
277 // send timeline to caller
278 $this->sendJSON($result);
279 }
280
281 /**
282 * AJAX end-point used to refresh the price of the given service.
283 * This task expects the following arguments set in request.
284 *
285 * @param integer $id_ser The service ID.
286 * @param integer $id_emp The employee ID.
287 * @param string $day The check-in date.
288 * @param integer $people The number of participants.
289 *
290 * @return void
291 *
292 * @since 1.7.4
293 */
294 public function refreshprice()
295 {
296 $input = JFactory::getApplication()->input;
297
298 $args = [];
299 $args['id_emp'] = $input->getUint('id_emp', 0);
300 $args['id_ser'] = $input->getUint('id_ser', 0);
301 $args['date'] = $input->getString('day', '');
302 $args['people'] = $input->getUint('people', 1);
303
304 $result = new stdClass;
305 $result->rate = 0;
306
307 // recalculate rate by specifing the selected arguments
308 $result->rate = VAPSpecialRates::getRate($args['id_ser'], $args['id_emp'], $args['date'], $args['people']);
309
310 // fetch service details
311 $service = $this->getModel('service')->getItem($args['id_ser']);
312
313 if ($service->priceperpeople)
314 {
315 // multiply by the number of selected participants
316 $result->rate *= $args['people'];
317 }
318
319 $this->sendJSON($result);
320 }
321 }
322