apiban.php
4 years ago
apilog.php
2 years ago
apiplugin.php
4 years ago
apiuser.php
2 years ago
apiuseroptions.php
2 years ago
backup.php
4 months ago
caldays.php
1 month ago
calendar.php
1 month ago
city.php
4 years ago
closure.php
1 month ago
configapp.php
4 years ago
configcldays.php
4 years ago
configcron.php
4 years ago
configemp.php
4 years ago
configsmsapi.php
4 years ago
configuration.php
4 months ago
conversion.php
4 years ago
country.php
2 years ago
coupon.php
2 years ago
couponemployee.php
4 years ago
coupongroup.php
2 years ago
couponservice.php
4 years ago
cronjob.php
2 years ago
cronjoblog.php
4 years ago
customer.php
4 months ago
customf.php
2 years ago
customfservice.php
4 years ago
customizer.php
4 years ago
empgroup.php
2 years ago
employee.php
2 years ago
empsettings.php
4 years ago
file.php
4 years ago
findreservation.php
1 month ago
group.php
2 years ago
import.php
4 years ago
index.html
4 years ago
invoice.php
1 month ago
langcustomf.php
4 years ago
langempgroup.php
4 years ago
langemployee.php
4 years ago
langgroup.php
4 years ago
langmedia.php
4 years ago
langoption.php
2 years ago
langoptiongroup.php
4 years ago
langoptionvar.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
2 years ago
langtaxrule.php
4 years ago
location.php
2 years ago
mailtext.php
2 years ago
makerecurrence.php
1 month ago
media.php
2 years ago
multiorder.php
1 month ago
option.php
1 year ago
optiongroup.php
2 years ago
optionvar.php
1 year ago
orderstatus.php
2 years ago
package.php
2 years ago
packageservice.php
4 years ago
packgroup.php
2 years ago
packorder.php
2 years ago
packorderitem.php
1 month ago
payment.php
2 years ago
rate.php
2 years ago
reportsemp.php
4 months ago
reportsser.php
4 months ago
reservation.php
1 month ago
resoptassoc.php
2 years ago
restriction.php
2 years ago
review.php
3 years ago
serempassoc.php
1 year ago
seroptassoc.php
4 years ago
serrateassoc.php
4 years ago
serrestrassoc.php
4 years ago
service.php
2 years ago
state.php
2 years ago
statswidget.php
2 years ago
statuscode.php
2 years ago
subscription.php
1 month ago
subscrorder.php
1 month ago
tag.php
4 years ago
tax.php
2 years ago
taxrule.php
2 years ago
updateprogram.php
4 years ago
usernote.php
2 years ago
waitinglist.php
1 month ago
webhook.php
1 year ago
worktime.php
1 month ago
configuration.php
455 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.model'); |
| 15 | |
| 16 | /** |
| 17 | * VikAppointments configuration model. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsModelConfiguration extends JModelVAP |
| 22 | { |
| 23 | /** |
| 24 | * Hook identifier for triggers. |
| 25 | * |
| 26 | * @var string |
| 27 | */ |
| 28 | protected $hook = 'Config'; |
| 29 | |
| 30 | /** |
| 31 | * Saves the whole configuration. |
| 32 | * |
| 33 | * @param array $args An associative array. |
| 34 | * |
| 35 | * @return boolean True in case something has changed, false otherwise. |
| 36 | */ |
| 37 | public function saveAll(array $args = array()) |
| 38 | { |
| 39 | // sanitize configuration |
| 40 | $this->validate($args); |
| 41 | |
| 42 | try |
| 43 | { |
| 44 | /** |
| 45 | * Trigger event to allow the plugins to bind the object that |
| 46 | * is going to be saved. |
| 47 | * |
| 48 | * @param mixed &$config The configuration array. |
| 49 | * @param JModel $model The model instance. (@since 1.7) |
| 50 | * |
| 51 | * @return boolean False to abort saving. |
| 52 | * |
| 53 | * @throws Exception It is possible to throw an exception to abort |
| 54 | * the saving process and return a readable message. |
| 55 | * |
| 56 | * @since 1.6.6 |
| 57 | */ |
| 58 | if (VAPFactory::getEventDispatcher()->false('onBeforeSave' . $this->hook, array(&$args, $this))) |
| 59 | { |
| 60 | // abort in case a plugin returned false |
| 61 | return false; |
| 62 | } |
| 63 | } |
| 64 | catch (Exception $e) |
| 65 | { |
| 66 | // register the error thrown by the plugin and abort |
| 67 | $this->setError($e); |
| 68 | |
| 69 | return false; |
| 70 | } |
| 71 | |
| 72 | $dbo = JFactory::getDbo(); |
| 73 | |
| 74 | $changed = false; |
| 75 | |
| 76 | foreach ($args as $param => $setting) |
| 77 | { |
| 78 | $q = $dbo->getQuery(true) |
| 79 | ->update($dbo->qn('#__vikappointments_config')) |
| 80 | ->set($dbo->qn('setting') . ' = ' . $dbo->q($setting)) |
| 81 | ->where($dbo->qn('param') . ' = ' . $dbo->q($param)); |
| 82 | |
| 83 | $dbo->setQuery($q); |
| 84 | $dbo->execute(); |
| 85 | |
| 86 | $changed = $changed || $dbo->getAffectedRows(); |
| 87 | } |
| 88 | |
| 89 | /** |
| 90 | * Trigger event to allow the plugins to make something after saving |
| 91 | * a record in the database. |
| 92 | * |
| 93 | * @param array $args The configuration array. |
| 94 | * @param boolean $changed True in case something has changed. (@since 1.7) |
| 95 | * @param JModel $model The model instance. (@since 1.7) |
| 96 | * |
| 97 | * @return void |
| 98 | * |
| 99 | * @since 1.6.6 |
| 100 | */ |
| 101 | VAPFactory::getEventDispatcher()->trigger('onAfterSave' . $this->hook, array($args, $changed, $this)); |
| 102 | |
| 103 | return $changed; |
| 104 | } |
| 105 | |
| 106 | /** |
| 107 | * Validates and prepares the settings to be stored. |
| 108 | * |
| 109 | * @param array &$args The configuration associative array. |
| 110 | * |
| 111 | * @return void |
| 112 | */ |
| 113 | protected function validate(&$args) |
| 114 | { |
| 115 | if (isset($args['senderemail']) && $args['senderemail'] == '') |
| 116 | { |
| 117 | // use the e-mail of the current user |
| 118 | $args['senderemail'] = JFactory::getUser()->email; |
| 119 | } |
| 120 | |
| 121 | if (isset($args['mailattach']) && is_array($args['mailattach'])) |
| 122 | { |
| 123 | // stringify mail attachments |
| 124 | $args['mailattach'] = json_encode($args['mailattach']); |
| 125 | } |
| 126 | |
| 127 | if (isset($args['icsattach']) && is_array($args['icsattach'])) |
| 128 | { |
| 129 | // stringify ICS attachment rules |
| 130 | $args['icsattach'] = implode(';', $args['icsattach']); |
| 131 | } |
| 132 | |
| 133 | if (isset($args['csvattach']) && is_array($args['csvattach'])) |
| 134 | { |
| 135 | // stringify CSV attachment rules |
| 136 | $args['csvattach'] = implode(';', $args['csvattach']); |
| 137 | } |
| 138 | |
| 139 | if (isset($args['mailcustwhen']) && is_array($args['mailcustwhen'])) |
| 140 | { |
| 141 | // stringify list of accepted status codes |
| 142 | $args['mailcustwhen'] = json_encode($args['mailcustwhen']); |
| 143 | } |
| 144 | |
| 145 | if (isset($args['mailempwhen']) && is_array($args['mailempwhen'])) |
| 146 | { |
| 147 | // stringify list of accepted status codes |
| 148 | $args['mailempwhen'] = json_encode($args['mailempwhen']); |
| 149 | } |
| 150 | |
| 151 | if (isset($args['mailadminwhen']) && is_array($args['mailadminwhen'])) |
| 152 | { |
| 153 | // stringify list of accepted status codes |
| 154 | $args['mailadminwhen'] = json_encode($args['mailadminwhen']); |
| 155 | } |
| 156 | |
| 157 | // validate customer e-mail template |
| 158 | if (isset($args['mailtmpl'])) |
| 159 | { |
| 160 | if (empty($args['mailtmpl'])) |
| 161 | { |
| 162 | $args['mailtmpl'] = 'email_tmpl.php'; |
| 163 | } |
| 164 | else |
| 165 | { |
| 166 | $args['mailtmpl'] = basename($args['mailtmpl']); |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | // validate admin e-mail template |
| 171 | if (isset($args['adminmailtmpl'])) |
| 172 | { |
| 173 | if (empty($args['adminmailtmpl'])) |
| 174 | { |
| 175 | $args['adminmailtmpl'] = 'admin_email_tmpl.php'; |
| 176 | } |
| 177 | else |
| 178 | { |
| 179 | $args['adminmailtmpl'] = basename($args['adminmailtmpl']); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | // validate employee e-mail template |
| 184 | if (isset($args['empmailtmpl'])) |
| 185 | { |
| 186 | if (empty($args['empmailtmpl'])) |
| 187 | { |
| 188 | $args['empmailtmpl'] = 'employee_email_tmpl.php'; |
| 189 | } |
| 190 | else |
| 191 | { |
| 192 | $args['empmailtmpl'] = basename($args['empmailtmpl']); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | // validate cancellation e-mail template |
| 197 | if (isset($args['cancmailtmpl'])) |
| 198 | { |
| 199 | if (empty($args['cancmailtmpl'])) |
| 200 | { |
| 201 | $args['cancmailtmpl'] = 'cancellation_email_tmpl.php'; |
| 202 | } |
| 203 | else |
| 204 | { |
| 205 | $args['cancmailtmpl'] = basename($args['cancmailtmpl']); |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | // validate stock e-mail template |
| 210 | if (isset($args['stockmailtmpl'])) |
| 211 | { |
| 212 | if (empty($args['stockmailtmpl'])) |
| 213 | { |
| 214 | $args['stockmailtmpl'] = 'stock_email_tmpl.php'; |
| 215 | } |
| 216 | else |
| 217 | { |
| 218 | $args['stockmailtmpl'] = basename($args['stockmailtmpl']); |
| 219 | } |
| 220 | } |
| 221 | |
| 222 | // validate package e-mail template |
| 223 | if (isset($args['packmailtmpl'])) |
| 224 | { |
| 225 | if (empty($args['packmailtmpl'])) |
| 226 | { |
| 227 | $args['packmailtmpl'] = 'packages_email_tmpl.php'; |
| 228 | } |
| 229 | else |
| 230 | { |
| 231 | $args['packmailtmpl'] = basename($args['packmailtmpl']); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // validate waiting list e-mail template |
| 236 | if (isset($args['waitlistmailtmpl'])) |
| 237 | { |
| 238 | if (empty($args['waitlistmailtmpl'])) |
| 239 | { |
| 240 | $args['waitlistmailtmpl'] = 'waitlist_email_tmpl.php'; |
| 241 | } |
| 242 | else |
| 243 | { |
| 244 | $args['waitlistmailtmpl'] = basename($args['waitlistmailtmpl']); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | if (isset($args['selfconfirm']) && isset($args['defstatus'])) |
| 249 | { |
| 250 | // in case the default status is auto-approved, turn off the self confirmation |
| 251 | if (JHtml::fetch('vaphtml.status.isapproved', 'appointments', $args['defstatus'])) |
| 252 | { |
| 253 | $args['selfconfirm'] = 0; |
| 254 | } |
| 255 | } |
| 256 | |
| 257 | if (isset($args['keepapplock'])) |
| 258 | { |
| 259 | // give at least 5 minutes to complete the payment |
| 260 | $args['keepapplock'] = max(array(5, $args['keepapplock'])); |
| 261 | } |
| 262 | |
| 263 | if (isset($args['depositvalue'])) |
| 264 | { |
| 265 | // cannot have negative deposit |
| 266 | $args['depositvalue'] = abs((float) $args['depositvalue']); |
| 267 | |
| 268 | if (($args['deposittype'] ?? null) == 1) |
| 269 | { |
| 270 | // cannot have a deposit higher than 99% |
| 271 | $args['depositvalue'] = min(array(99, $args['depositvalue'])); |
| 272 | } |
| 273 | } |
| 274 | |
| 275 | if (isset($args['shoplink'])) |
| 276 | { |
| 277 | if ($args['shoplink'] != -2) |
| 278 | { |
| 279 | // unset custom shop link |
| 280 | $args['shoplinkcustom'] = ''; |
| 281 | } |
| 282 | else if (empty($args['shoplinkcustom'])) |
| 283 | { |
| 284 | // use default one |
| 285 | $args['shoplinkcustom'] = 'index.php'; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | if (isset($args['repeatbyrecur']) && is_array($args['repeatbyrecur'])) |
| 290 | { |
| 291 | // stringify repeat-by recurrence rules |
| 292 | $args['repeatbyrecur'] = implode(';', $args['repeatbyrecur']); |
| 293 | |
| 294 | if ($args['repeatbyrecur'] == '0;0;0;0;0;0;0;0') |
| 295 | { |
| 296 | $args['repeatbyrecur'] = '0;1;1;0;0;0;0;0'; |
| 297 | } |
| 298 | } |
| 299 | |
| 300 | if (isset($args['fornextrecur']) && is_array($args['fornextrecur'])) |
| 301 | { |
| 302 | // stringify for-next recurrence rules |
| 303 | $args['fornextrecur'] = implode(';', $args['fornextrecur']); |
| 304 | |
| 305 | if ($args['fornextrecur'] == '0;0;0;0') |
| 306 | { |
| 307 | $args['fornextrecur'] = '1;1;1;0'; |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | if (isset($args['minamountrecur']) && isset($args['maxamountrecur']) && $args['minamountrecur'] > $args['maxamountrecur']) |
| 312 | { |
| 313 | // cannot have min amount higher than max |
| 314 | $args['maxamountrecur'] = $args['minamountrecur']; |
| 315 | } |
| 316 | |
| 317 | if (isset($args['zipcodesfrom'])) |
| 318 | { |
| 319 | $args['zipcodes'] = array(); |
| 320 | |
| 321 | // stringify ZIP codes |
| 322 | foreach ($args['zipcodesfrom'] as $i => $from) |
| 323 | { |
| 324 | $to = !empty($args['zipcodesto'][$i]) ? $args['zipcodesto'][$i] : $from; |
| 325 | |
| 326 | if (empty($from) && !empty($to)) |
| 327 | { |
| 328 | // from empty, to filled-in |
| 329 | $from = $to; |
| 330 | } |
| 331 | |
| 332 | if ($from && $to) |
| 333 | { |
| 334 | $args['zipcodes'][] = array( |
| 335 | 'from' => $from, |
| 336 | 'to' => $to, |
| 337 | ); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | unset($args['zipcodesfrom']); |
| 342 | unset($args['zipcodesto']); |
| 343 | } |
| 344 | |
| 345 | if (isset($args['zipcodes']) && !is_string($args['zipcodes'])) |
| 346 | { |
| 347 | // stringify ZIP codes |
| 348 | $args['zipcodes'] = json_encode($args['zipcodes']); |
| 349 | } |
| 350 | |
| 351 | if (isset($args['listablecols']) && is_array($args['listablecols'])) |
| 352 | { |
| 353 | $listable_cols = array(); |
| 354 | |
| 355 | // stringify reservations list columns |
| 356 | foreach ($args['listablecols'] as $k => $v) |
| 357 | { |
| 358 | $tmp = explode(':', $v); |
| 359 | |
| 360 | if ($tmp[1] == 1) |
| 361 | { |
| 362 | $listable_cols[] = $tmp[0]; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | $args['listablecols'] = implode(',', $listable_cols); |
| 367 | } |
| 368 | |
| 369 | if (isset($args['listablecf']) && is_array($args['listablecf'])) |
| 370 | { |
| 371 | $listable_cols = array(); |
| 372 | |
| 373 | // stringify reservations list custom fields |
| 374 | foreach ($args['listablecf'] as $k => $v) |
| 375 | { |
| 376 | $tmp = explode(':', $v); |
| 377 | |
| 378 | if ($tmp[1] == 1) |
| 379 | { |
| 380 | $listable_cols[] = $tmp[0]; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | $args['listablecf'] = implode(',', $listable_cols); |
| 385 | } |
| 386 | |
| 387 | if (isset($args['waitlistsmscont']) && is_array($args['waitlistsmscont'])) |
| 388 | { |
| 389 | $languages = VikAppointments::getKnownLanguages(); |
| 390 | |
| 391 | $sms_wl_cont = array(); |
| 392 | |
| 393 | // stringify waiting list SMS contents |
| 394 | for ($i = 0; $i < count($languages); $i++) |
| 395 | { |
| 396 | for ($j = 0; $j < 2; $j++) |
| 397 | { |
| 398 | $sms_wl_cont[$j][$languages[$i]] = $args['waitlistsmscont'][$j][$i]; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | $args['waitlistsmscont'] = json_encode($sms_wl_cont); |
| 403 | } |
| 404 | |
| 405 | if (isset($args['emplistmode']) && is_array($args['emplistmode'])) |
| 406 | { |
| 407 | $active = false; |
| 408 | |
| 409 | // make sure at least one is active |
| 410 | foreach ($args['emplistmode'] as $v) |
| 411 | { |
| 412 | $active = $active || $v; |
| 413 | } |
| 414 | |
| 415 | if (!$active) |
| 416 | { |
| 417 | // turn on first one available |
| 418 | $args['emplistmode']["1"] = 1; |
| 419 | } |
| 420 | |
| 421 | // stringify employees ordering |
| 422 | $args['emplistmode'] = json_encode($args['emplistmode']); |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Method to get a table object. |
| 428 | * |
| 429 | * @param string $name The table name. |
| 430 | * @param string $prefix The class prefix. |
| 431 | * @param array $options Configuration array for table. |
| 432 | * |
| 433 | * @return JTable A table object. |
| 434 | * |
| 435 | * @throws Exception |
| 436 | */ |
| 437 | public function getTable($name = '', $prefix = '', $options = array()) |
| 438 | { |
| 439 | if (!$name) |
| 440 | { |
| 441 | // force configuration table |
| 442 | $name = 'configuration'; |
| 443 | } |
| 444 | |
| 445 | if (!$prefix) |
| 446 | { |
| 447 | // use default system prefix |
| 448 | $prefix = 'VAPTable'; |
| 449 | } |
| 450 | |
| 451 | // invoke parent |
| 452 | return parent::getTable($name, $prefix, $options); |
| 453 | } |
| 454 | } |
| 455 |