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
4 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
4 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
4 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
4 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
makerecurrence.php
220 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 make recurrence controller. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsControllerMakerecurrence extends VAPControllerAdmin |
| 22 | { |
| 23 | /** |
| 24 | * AJAX end-point used to get a recurrence preview. |
| 25 | * This task expects the following arguments set in request. |
| 26 | * |
| 27 | * @param integer id The appointment ID. |
| 28 | * @param integer by The recurrence by identifier. |
| 29 | * @param integer amount The recurrence amount. |
| 30 | * @param integer for The recurrence for identifier. |
| 31 | * |
| 32 | * @return void |
| 33 | */ |
| 34 | public function preview() |
| 35 | { |
| 36 | $input = JFactory::getApplication()->input; |
| 37 | |
| 38 | /** |
| 39 | * Added token validation. |
| 40 | * |
| 41 | * @since 1.7 |
| 42 | */ |
| 43 | if (!JSession::checkToken()) |
| 44 | { |
| 45 | // missing CSRF-proof token |
| 46 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 47 | } |
| 48 | |
| 49 | $id = $input->getUint('id', 0); |
| 50 | |
| 51 | try |
| 52 | { |
| 53 | // get order details |
| 54 | VAPLoader::import('libraries.order.factory'); |
| 55 | $order = VAPOrderFactory::getAppointments($id, JFactory::getLanguage()->getTag()); |
| 56 | } |
| 57 | catch (Exception $e) |
| 58 | { |
| 59 | // raise AJAX error, order not found |
| 60 | UIErrorFactory::raiseError($e->getCode(), $e->getMessage()); |
| 61 | } |
| 62 | |
| 63 | // access first appointment |
| 64 | $appointment = $order->appointments[0]; |
| 65 | |
| 66 | // get recurrence instructions |
| 67 | $recurrence = array(); |
| 68 | $recurrence['by'] = $input->getUint('by', 0); |
| 69 | $recurrence['amount'] = $input->getUint('amount', 0); |
| 70 | $recurrence['for'] = $input->getUint('for', 0); |
| 71 | |
| 72 | // get recurrence model |
| 73 | $model = $this->getModel(); |
| 74 | |
| 75 | // create date by using the local timezone of the employee, because the DST |
| 76 | // might change over time |
| 77 | $tz = new DateTimeZone($this->getModel('employee')->getTimezone($appointment->employee->id)); |
| 78 | $empDate = JFactory::getDate($appointment->checkin->utc); |
| 79 | $empDate->setTimezone($tz); |
| 80 | |
| 81 | // compose dates recurrence |
| 82 | $arr = $model->getRecurrence($empDate, $recurrence); |
| 83 | |
| 84 | if (!$arr) |
| 85 | { |
| 86 | // invalid recurrence |
| 87 | UIErrorFactory::raiseError(500, JText::translate('VAPMAKERECNOROWS')); |
| 88 | } |
| 89 | |
| 90 | $config = VAPFactory::getConfig(); |
| 91 | |
| 92 | $results = array(); |
| 93 | |
| 94 | // iterate all dates found |
| 95 | foreach ($arr as $date) |
| 96 | { |
| 97 | $tmp = array(); |
| 98 | $tmp['format'] = JHtml::fetch('date', $date, $config->get('dateformat') . ' ' . $config->get('timeformat')); |
| 99 | $tmp['date'] = $date; |
| 100 | |
| 101 | // check the availability for the same appointment, |
| 102 | // but with the new date |
| 103 | $tmp['available'] = $model->checkAvailability($appointment, $date); |
| 104 | |
| 105 | if ($tmp['available']) |
| 106 | { |
| 107 | // available |
| 108 | $tmp['message'] = JText::translate('VAPMAKERECDATEOK'); |
| 109 | } |
| 110 | else |
| 111 | { |
| 112 | // not available |
| 113 | $tmp['message'] = JText::translate('VAPMAKERECDATEFAIL'); |
| 114 | |
| 115 | // get reason from model |
| 116 | $tmp['reason'] = $model->getError(null, true); |
| 117 | |
| 118 | // check availability for other employees assigned to this service |
| 119 | $tmp['employees'] = $model->checkRandomAvailability($appointment, $date); |
| 120 | |
| 121 | if (!$tmp['employees']) |
| 122 | { |
| 123 | // unset employees list if empty |
| 124 | $tmp['employees'] = null; |
| 125 | } |
| 126 | |
| 127 | // check availability close to the current date |
| 128 | $tmp['times'] = $model->checkNearbyAvailability($appointment, $date); |
| 129 | |
| 130 | if (!$tmp['times']) |
| 131 | { |
| 132 | // unset times list if empty |
| 133 | $tmp['times'] = null; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | // register result |
| 138 | $results[] = $tmp; |
| 139 | } |
| 140 | |
| 141 | // send response to caller |
| 142 | $this->sendJSON($results); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * AJAX end-point used to create a recurrence for the appointment. |
| 147 | * This task expects the following arguments set in request. |
| 148 | * |
| 149 | * @param integer id The appointment ID. |
| 150 | * @param integer by The recurrence by identifier. |
| 151 | * @param integer amount The recurrence amount. |
| 152 | * @param integer for The recurrence for identifier. |
| 153 | * @param array hints An associative array containing the hints for |
| 154 | * those appointments without availability. |
| 155 | * |
| 156 | * @return void |
| 157 | */ |
| 158 | public function create() |
| 159 | { |
| 160 | $input = JFactory::getApplication()->input; |
| 161 | |
| 162 | /** |
| 163 | * Added token validation. |
| 164 | * |
| 165 | * @since 1.7 |
| 166 | */ |
| 167 | if (!JSession::checkToken()) |
| 168 | { |
| 169 | // missing CSRF-proof token |
| 170 | UIErrorFactory::raiseError(403, JText::translate('JINVALID_TOKEN')); |
| 171 | } |
| 172 | |
| 173 | $id = $input->getUint('id', 0); |
| 174 | |
| 175 | try |
| 176 | { |
| 177 | // get order details |
| 178 | VAPLoader::import('libraries.order.factory'); |
| 179 | $order = VAPOrderFactory::getAppointments($id, JFactory::getLanguage()->getTag()); |
| 180 | } |
| 181 | catch (Exception $e) |
| 182 | { |
| 183 | // raise AJAX error, order not found |
| 184 | UIErrorFactory::raiseError($e->getCode(), $e->getMessage()); |
| 185 | } |
| 186 | |
| 187 | // access first appointment |
| 188 | $appointment = $order->appointments[0]; |
| 189 | |
| 190 | // get recurrence instructions |
| 191 | $recurrence = array(); |
| 192 | $recurrence['by'] = $input->getUint('by', 0); |
| 193 | $recurrence['amount'] = $input->getUint('amount', 0); |
| 194 | $recurrence['for'] = $input->getUint('for', 0); |
| 195 | |
| 196 | // get selected hints |
| 197 | $hints = $input->get('hints', array(), 'array'); |
| 198 | |
| 199 | // get recurrence model |
| 200 | $model = $this->getModel(); |
| 201 | |
| 202 | // create recurrence |
| 203 | $count = $model->createRecurrence($appointment, $recurrence, $hints); |
| 204 | |
| 205 | if (!$count) |
| 206 | { |
| 207 | // raise AJAX error, no created appointments |
| 208 | UIErrorFactory::raiseError(500, JText::translate('VAPMAKERECSUCCESS0')); |
| 209 | } |
| 210 | |
| 211 | // prepare response array |
| 212 | $result = array(); |
| 213 | $result['message'] = JText::sprintf('VAPMAKERECSUCCESS1', $count); |
| 214 | $result['count'] = $count; |
| 215 | |
| 216 | // send response to caller |
| 217 | $this->sendJSON($result); |
| 218 | } |
| 219 | } |
| 220 |