allorders.php
1 day ago
calendarweek.php
1 day ago
cart.php
1 day ago
confirmapp.php
1 day ago
empaccountstat.php
1 day ago
empattachser.php
1 day ago
empcoupons.php
1 day ago
empcustfields.php
1 day ago
empeditcoupon.php
1 day ago
empeditcustfield.php
1 day ago
empeditlocation.php
1 day ago
empeditpay.php
1 day ago
empeditprofile.php
1 day ago
empeditservice.php
1 day ago
empeditwdays.php
1 day ago
emplocations.php
1 day ago
emplocwdays.php
1 day ago
emplogin.php
1 day ago
employeesearch.php
1 day ago
employeeslist.php
1 day ago
empmanres.php
1 day ago
emppaylist.php
1 day ago
empserviceslist.php
1 day ago
empsettingsman.php
1 day ago
empsubscrcart.php
1 day ago
empsubscrhistory.php
1 day ago
empsubscrorder.php
1 day ago
empwdays.php
1 day ago
index.html
1 day ago
packages.php
1 day ago
packagescart.php
1 day ago
packagesconfirm.php
1 day ago
packorders.php
1 day ago
servicesearch.php
1 day ago
serviceslist.php
1 day ago
subscrcart.php
1 day ago
subscrhistory.php
1 day ago
subscrpayment.php
1 day ago
empsettingsman.php
163 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 employee area settings management model. |
| 18 | * |
| 19 | * @since 1.7 |
| 20 | */ |
| 21 | class VikAppointmentsModelEmpsettingsman extends JModelVAP |
| 22 | { |
| 23 | /** |
| 24 | * Basic save implementation. |
| 25 | * |
| 26 | * @param mixed $data Either an array or an object of data to save. |
| 27 | * |
| 28 | * @return mixed The ID of the record on success, false otherwise. |
| 29 | */ |
| 30 | public function save($data) |
| 31 | { |
| 32 | $auth = VAPEmployeeAuth::getInstance(); |
| 33 | |
| 34 | $settings = $auth->getSettings(); |
| 35 | |
| 36 | // validate ZIP code |
| 37 | if ($data['zip_field_id'] > 0 && !$auth->manageCustomFields($data['zip_field_id'])) |
| 38 | { |
| 39 | $data['zip_field_id'] = 0; |
| 40 | } |
| 41 | |
| 42 | // validate list limit |
| 43 | if (!in_array($data['listlimit'], array(5, 10, 15, 20, 50))) |
| 44 | { |
| 45 | $data['listlimit'] = $settings->listlimit; |
| 46 | } |
| 47 | |
| 48 | // validate list position |
| 49 | if (!in_array($data['listposition'], array(1, 2))) |
| 50 | { |
| 51 | $data['listposition'] = $settings->listposition; |
| 52 | } |
| 53 | |
| 54 | // validate list ordering |
| 55 | if (!in_array($data['listordering'], array('ASC', 'DESC'))) |
| 56 | { |
| 57 | $data['listordering'] = $settings->listordering; |
| 58 | } |
| 59 | |
| 60 | // validate number of calendars |
| 61 | if (!in_array($data['numcals'], array(1, 3, 6, 9, 12))) |
| 62 | { |
| 63 | $data['numcals'] = $settings->numcals; |
| 64 | } |
| 65 | |
| 66 | // validate first month |
| 67 | if ($data['firstmonth'] < 1 || $data['firstmonth'] > 12) |
| 68 | { |
| 69 | $data['firstmonth'] = 0; |
| 70 | } |
| 71 | |
| 72 | // fill SYNC KEY if empty |
| 73 | if (empty($data['synckey'])) |
| 74 | { |
| 75 | $data['synckey'] = VikAppointments::generateSerialCode(12, 'employee-synckey'); |
| 76 | } |
| 77 | |
| 78 | if (isset($data['zipcodesfrom'])) |
| 79 | { |
| 80 | $data['zipcodes'] = array(); |
| 81 | |
| 82 | // stringify ZIP codes |
| 83 | foreach ($data['zipcodesfrom'] as $i => $from) |
| 84 | { |
| 85 | $to = !empty($data['zipcodesto'][$i]) ? $data['zipcodesto'][$i] : $from; |
| 86 | |
| 87 | if (empty($from) && !empty($to)) |
| 88 | { |
| 89 | // from empty, to filled-in |
| 90 | $from = $to; |
| 91 | } |
| 92 | |
| 93 | if ($from && $to) |
| 94 | { |
| 95 | $data['zipcodes'][] = array( |
| 96 | 'from' => $from, |
| 97 | 'to' => $to, |
| 98 | ); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | unset($data['zipcodesfrom']); |
| 103 | unset($data['zipcodesto']); |
| 104 | } |
| 105 | |
| 106 | if (isset($data['zipcodes']) && !is_string($data['zipcodes'])) |
| 107 | { |
| 108 | // stringify ZIP codes |
| 109 | $data['zipcodes'] = json_encode($data['zipcodes']); |
| 110 | } |
| 111 | |
| 112 | $dispatcher = VAPFactory::getEventDispatcher(); |
| 113 | |
| 114 | /** |
| 115 | * Trigger event to allow the plugins to bind the object that |
| 116 | * is going to be saved. |
| 117 | * |
| 118 | * @param array &$data The array to bind. |
| 119 | * @param JModel $model The current model instance. (@since 1.7) |
| 120 | * |
| 121 | * @return boolean True on success, false otherwise. |
| 122 | * |
| 123 | * @since 1.6.6 |
| 124 | */ |
| 125 | if ($dispatcher->false('onBeforeSaveEmployeeSettings', array(&$data, $this))) |
| 126 | { |
| 127 | // a plugin prevented the saving process |
| 128 | return false; |
| 129 | } |
| 130 | |
| 131 | // inject employee ID and settings ID |
| 132 | $data['id'] = $settings->id; |
| 133 | $data['id_employee'] = $auth->id; |
| 134 | |
| 135 | // delegate save to employee settings model (save settings) |
| 136 | $result = JModelVAP::getInstance('empsettings')->save($data); |
| 137 | |
| 138 | $employee = array( |
| 139 | 'id' => $auth->id, |
| 140 | 'timezone' => $data['timezone'], |
| 141 | 'synckey' => $data['synckey'], |
| 142 | ); |
| 143 | |
| 144 | // delegate save to employee model (save timezone and sync key) |
| 145 | $result = JModelVAP::getInstance('employee')->save($employee) || $result; |
| 146 | |
| 147 | /** |
| 148 | * Trigger event to allow the plugins to make something after saving |
| 149 | * a record in the database. |
| 150 | * |
| 151 | * @param array $data The saved record. |
| 152 | * @param JModel $model The current model instance. (@since 1.7) |
| 153 | * |
| 154 | * @return void |
| 155 | * |
| 156 | * @since 1.6.6 |
| 157 | */ |
| 158 | $dispatcher->trigger('onAfterSaveEmployeeSettings', array($data, $this)); |
| 159 | |
| 160 | return $result; |
| 161 | } |
| 162 | } |
| 163 |