| @@ -1,0 +1,245 @@ | ||
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * @package VikBooking - Libraries | |
| 4 | + * @subpackage lite | |
| 5 | + * @author E4J s.r.l. | |
| 6 | + * @copyright Copyright (C) 2022 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 | +/** | |
| 15 | + * Helper implementor used to apply the restrictions of the LITE version. | |
| 16 | + * | |
| 17 | + * @since 1.5.11 | |
| 18 | + */ | |
| 19 | +class VikBookingLiteHelper | |
| 20 | +{ | |
| 21 | + /** | |
| 22 | + * The platform application instance. | |
| 23 | + * | |
| 24 | + * @var JApplication | |
| 25 | + */ | |
| 26 | + private $app; | |
| 27 | + | |
| 28 | + /** | |
| 29 | + * The platform database instance. | |
| 30 | + * | |
| 31 | + * @var JDatabase | |
| 32 | + */ | |
| 33 | + private $db; | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Class constructor. | |
| 37 | + */ | |
| 38 | + public function __construct() | |
| 39 | + { | |
| 40 | + $this->app = JFactory::getApplication(); | |
| 41 | + $this->db = JFactory::getDbo(); | |
| 42 | + } | |
| 43 | + | |
| 44 | + /** | |
| 45 | + * Helper method used to disable the capabilities according | |
| 46 | + * to the restrictions applied by the LITE version. | |
| 47 | + * | |
| 48 | + * @param array $capabilities Array of key/value pairs where keys represent a capability name and boolean values | |
| 49 | + * represent whether the role has that capability. | |
| 50 | + * | |
| 51 | + * @return array The resulting capabilities lookup. | |
| 52 | + */ | |
| 53 | + public function restrictCapabilities(array $capabilities) | |
| 54 | + { | |
| 55 | + switch ($this->app->input->get('view')) | |
| 56 | + { | |
| 57 | + case 'ratesoverv': | |
| 58 | + // disable CREATE capability | |
| 59 | + $capabilities['com_vikbooking_create'] = false; | |
| 60 | + break; | |
| 61 | + | |
| 62 | + case 'editbusy': | |
| 63 | + case 'editorder': | |
| 64 | + // disable capability to access the MANAGEMENT section | |
| 65 | + $capabilities['com_vikbooking_vbo_management'] = false; | |
| 66 | + break; | |
| 67 | + | |
| 68 | + case 'customf': | |
| 69 | + // disable CREATE, EDIT and DELETE capabilities | |
| 70 | + $capabilities['com_vikbooking_create'] = false; | |
| 71 | + $capabilities['com_vikbooking_edit'] = false; | |
| 72 | + $capabilities['com_vikbooking_delete'] = false; | |
| 73 | + break; | |
| 74 | + } | |
| 75 | + | |
| 76 | + return $capabilities; | |
| 77 | + } | |
| 78 | + | |
| 79 | + /** | |
| 80 | + * Intercepts the request to return a custom error message when the current | |
| 81 | + * task is equal to "pricing.setnewrates". | |
| 82 | + * | |
| 83 | + * @return void | |
| 84 | + */ | |
| 85 | + public function disableSetNewRatesTask() | |
| 86 | + { | |
| 87 | + if ($this->app->input->get('task') === 'pricing.setnewrates') | |
| 88 | + { | |
| 89 | + $error = 'e4j.error.' . __('This Pricing Model is only supported in the Pro version.', 'vikbooking'); | |
| 90 | + VBOHttpDocument::getInstance($this->app)->close(200, $error); | |
| 91 | + } | |
| 92 | + } | |
| 93 | + | |
| 94 | + /** | |
| 95 | + * Helper method used to display an advertsing banner while trying | |
| 96 | + * to reach a page available only in the PRO version. | |
| 97 | + * | |
| 98 | + * @return void | |
| 99 | + */ | |
| 100 | + public function displayBanners() | |
| 101 | + { | |
| 102 | + if (!$this->app->isAdmin()) | |
| 103 | + { | |
| 104 | + return; | |
| 105 | + } | |
| 106 | + | |
| 107 | + $input = $this->app->input; | |
| 108 | + | |
| 109 | + // get current view | |
| 110 | + $view = $input->get('view', $input->get('task')); | |
| 111 | + | |
| 112 | + // define list of pages not supported by the LITE version | |
| 113 | + $lookup = array( | |
| 114 | + 'coupons' => '17', | |
| 115 | + 'crons' => 'crons', | |
| 116 | + 'customers' => '22', | |
| 117 | + 'einvoicing' => 'einvoicing', | |
| 118 | + 'invoices' => 'invoices', | |
| 119 | + 'operators' => 'operators', | |
| 120 | + 'optionals' => '6', | |
| 121 | + 'packages' => 'packages', | |
| 122 | + 'payments' => '14', | |
| 123 | + 'pmsreports' => 'pmsreports', | |
| 124 | + 'restrictions' => 'restrictions', | |
| 125 | + 'seasons' => '13', | |
| 126 | + 'stats' => 'stats', | |
| 127 | + ); | |
| 128 | + | |
| 129 | + // check whether the view is supported | |
| 130 | + if (!$view || !isset($lookup[$view])) | |
| 131 | + { | |
| 132 | + return; | |
| 133 | + } | |
| 134 | + | |
| 135 | + // use a missing view to display blank contents | |
| 136 | + $input->set('view', 'liteview'); | |
| 137 | + $input->set('task', ''); | |
| 138 | + $input->set('hide_menu', true); | |
| 139 | + | |
| 140 | + // display menu before unsetting the view | |
| 141 | + VikBookingHelper::printHeader($lookup[$view]); | |
| 142 | + | |
| 143 | + // display LITE banner | |
| 144 | + echo JLayoutHelper::render('html.license.lite', array('view' => $view)); | |
| 145 | + | |
| 146 | + if (VikBooking::showFooter()) | |
| 147 | + { | |
| 148 | + VikBookingHelper::printFooter(); | |
| 149 | + } | |
| 150 | + } | |
| 151 | + | |
| 152 | + /** | |
| 153 | + * Hides all the elements that owns a class equal to "pro-feature". | |
| 154 | + * | |
| 155 | + * @return void | |
| 156 | + */ | |
| 157 | + public function hideProFeatures() | |
| 158 | + { | |
| 159 | + JFactory::getDocument()->addStyleDeclaration('.pro-feature { display: none !important; }'); | |
| 160 | + } | |
| 161 | + | |
| 162 | + /** | |
| 163 | + * Disable all the features linked to the rooms management provided by | |
| 164 | + * the "editbusy" page. | |
| 165 | + * | |
| 166 | + * @return void | |
| 167 | + */ | |
| 168 | + public function disableEditBusyRoomFeatures() | |
| 169 | + { | |
| 170 | + if ($this->app->input->get('task') !== 'updatebusy') | |
| 171 | + { | |
| 172 | + return; | |
| 173 | + } | |
| 174 | + | |
| 175 | + // scan all the elements set in request | |
| 176 | + foreach ($this->app->input->getArray() as $k => $v) | |
| 177 | + { | |
| 178 | + // check whether the element name follows the switch_[ID] pattern | |
| 179 | + if (preg_match("/^switch_[0-9]+$/", $k)) | |
| 180 | + { | |
| 181 | + // unset switch element | |
| 182 | + $this->app->input->set($k, ''); | |
| 183 | + } | |
| 184 | + } | |
| 185 | + | |
| 186 | + // disable room cancellation | |
| 187 | + $this->app->input->set('rm_room_oid', 0); | |
| 188 | + // cannot add new rooms from the back-end | |
| 189 | + $this->app->input->set('add_room_id', 0); | |
| 190 | + } | |
| 191 | + | |
| 192 | + /** | |
| 193 | + * Helper method used to display the scripts and the HTML needed to | |
| 194 | + * allow the management of the terms-of-service custom field. | |
| 195 | + * | |
| 196 | + * @param JView $view The view instance. | |
| 197 | + * | |
| 198 | + * @return void | |
| 199 | + */ | |
| 200 | + public function displayTosFieldManagementForm($view) | |
| 201 | + { | |
| 202 | + // iterate all custom fields | |
| 203 | + foreach ($view->rows as $cf) | |
| 204 | + { | |
| 205 | + $cf = (array) $cf; | |
| 206 | + | |
| 207 | + // check if we have a checkbox field | |
| 208 | + if ($cf['type'] == 'checkbox') | |
| 209 | + { | |
| 210 | + // use scripts to manage ToS | |
| 211 | + echo JLayoutHelper::render('html.managetos.script', array('field' => $cf)); | |
| 212 | + } | |
| 213 | + } | |
| 214 | + } | |
| 215 | + | |
| 216 | + /** | |
| 217 | + * Helper method used to intercept the custom request used to update | |
| 218 | + * the terms-of-service custom field. | |
| 219 | + * | |
| 220 | + * @return void | |
| 221 | + */ | |
| 222 | + public function listenTosFieldSavingTask() | |
| 223 | + { | |
| 224 | + // check if we should save the TOS field | |
| 225 | + if ($this->app->input->get('task') == 'customf.savetosajax') | |
| 226 | + { | |
| 227 | + if (!JSession::checkToken()) | |
| 228 | + { | |
| 229 | + VBOHttpDocument::getInstance($this->app)->close(403, JText::translate('JINVALID_TOKEN')); | |
| 230 | + } | |
| 231 | + | |
| 232 | + $db = JFactory::getDbo(); | |
| 233 | + | |
| 234 | + $data = new stdClass; | |
| 235 | + $data->name = $this->app->input->get('name', '', 'string'); | |
| 236 | + $data->poplink = $this->app->input->get('poplink', '', 'string'); | |
| 237 | + $data->id = $this->app->input->get('id', 0, 'uint'); | |
| 238 | + | |
| 239 | + $db->updateObject('#__vikbooking_custfields', $data, 'id'); | |
| 240 | + | |
| 241 | + // return saved object to caller | |
| 242 | + VBOHttpDocument::getInstance($this->app)->json($data); | |
| 243 | + } | |
| 244 | + } | |
| 245 | +} | |