calendarweek.php
1 month ago
cart.php
1 month ago
confirmapp.php
1 month ago
empattachser.php
1 month ago
empeditcoupon.php
1 month ago
empeditcustfield.php
1 month ago
empeditlocation.php
1 month ago
empeditpay.php
1 month ago
empeditprofile.php
1 month ago
empeditservice.php
1 month ago
empeditwdays.php
1 month ago
emplocwdays.php
1 month ago
emplogin.php
1 month ago
employeesearch.php
1 month ago
employeeslist.php
1 month ago
empmakerecur.php
1 month ago
empmanres.php
1 month ago
empsettings.php
1 month ago
empsubscr.php
1 month ago
empsubscrorder.php
1 month ago
index.html
1 month ago
modules.php
1 month ago
order.php
1 month ago
packages.php
1 month ago
packagesconfirm.php
1 month ago
packagesorder.php
1 month ago
servicesearch.php
1 month ago
subscriptions.php
1 month ago
subscrpayment.php
1 month ago
userprofile.php
1 month ago
waitinglist.php
1 month ago
waitinglist.php
125 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 waiting list controller. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsControllerWaitinglist extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * AJAX end-point used to subscribe a user into the waiting list. |
| 25 | * This method expects the following parameters to be sent |
| 26 | * via POST or GET. |
| 27 | * |
| 28 | * @param string date The date for which the user should be subscribed. |
| 29 | * @param integer id_service The ID of the service for which the user is interested. |
| 30 | * @param integer id_employee The ID of the employee for which the user is interested. |
| 31 | * @param string email The user e-mail. |
| 32 | * @param string phone The user phone number. |
| 33 | * |
| 34 | * @return void |
| 35 | */ |
| 36 | public function subscribeajax() |
| 37 | { |
| 38 | $app = JFactory::getApplication(); |
| 39 | $input = $app->input; |
| 40 | |
| 41 | if (!VikAppointments::isWaitingList()) |
| 42 | { |
| 43 | // waiting list feature is blocked |
| 44 | UIErrorFactory::raiseError(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 45 | } |
| 46 | |
| 47 | $args = array(); |
| 48 | $args['timestamp'] = $input->getString('date', null); |
| 49 | $args['id_service'] = $input->getUint('id_service', 0); |
| 50 | $args['id_employee'] = $input->getUint('id_employee', 0); |
| 51 | $args['email'] = $input->getString('mail'); |
| 52 | $args['phone_number'] = $input->getString('phone'); |
| 53 | |
| 54 | // get waiting list model |
| 55 | $model = $this->getModel(); |
| 56 | |
| 57 | // subscribe into waiting list |
| 58 | if (!$model->subscribe($args)) |
| 59 | { |
| 60 | // get last error fetched |
| 61 | $error = $model->getError($index = null, $string = true); |
| 62 | UIErrorFactory::raiseError(500, $error ? $error : JText::translate('VAPWAITLISTADDED0')); |
| 63 | } |
| 64 | |
| 65 | // send response to caller |
| 66 | $this->sendJSON(json_encode(JText::translate('VAPWAITLISTADDED1'))); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Task used to unsubscribe a user from the waiting list. |
| 71 | * This method expects the following parameters to be sent |
| 72 | * via POST or GET. |
| 73 | * |
| 74 | * @param string email The user e-mail. |
| 75 | * @param string phone The user phone number. |
| 76 | * |
| 77 | * @return boolean |
| 78 | */ |
| 79 | public function unsubscribe() |
| 80 | { |
| 81 | $app = JFactory::getApplication(); |
| 82 | $input = $app->input; |
| 83 | $session = JFactory::getSession(); |
| 84 | |
| 85 | $itemid = $input->getUint('Itemid', 0); |
| 86 | |
| 87 | // set redirect URL |
| 88 | $url = 'index.php?option=com_vikappointments&view=unsubscr_waiting_list' . ($itemid ? '&Itemid=' . $itemid : ''); |
| 89 | |
| 90 | if (!JSession::checkToken()) |
| 91 | { |
| 92 | // direct access attempt |
| 93 | $app->enqueueMessage(JText::translate('JINVALID_TOKEN'), 'error'); |
| 94 | $this->setRedirect(JRoute::rewrite($url, false)); |
| 95 | return false; |
| 96 | } |
| 97 | |
| 98 | $args = array(); |
| 99 | $args['email'] = $input->getString('email'); |
| 100 | $args['phone_number'] = $input->getString('phone'); |
| 101 | |
| 102 | // get waiting list model |
| 103 | $model = $this->getModel(); |
| 104 | |
| 105 | // try to unsubscribe user |
| 106 | $count = $model->unsubscribe($args); |
| 107 | |
| 108 | // register count of deleted records in URL |
| 109 | $url .= '&deleted=' . $count; |
| 110 | $this->setRedirect(JRoute::rewrite($url, false)); |
| 111 | |
| 112 | if (!$count) |
| 113 | { |
| 114 | // get error message fetched by the model, if any |
| 115 | $error = $model->getError($index = null, $string = true); |
| 116 | |
| 117 | if ($error) |
| 118 | { |
| 119 | // enqueue error message |
| 120 | $app->enqueueMessage($error, 'error'); |
| 121 | } |
| 122 | } |
| 123 | } |
| 124 | } |
| 125 |