PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.15
VikBooking Hotel Booking Engine & PMS v1.8.15
1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 1.7.3 All 36 releases
vikbooking / admin / helpers / conditionalrules / room_upgrade.php

room_upgrade.php in VikBooking Hotel Booking Engine & PMS 1.8.15, at admin/helpers/conditionalrules/room_upgrade.php

269 lines 8.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 /**
14 * Class handler for conditional rule "room upgrade".
15 *
16 * @since 1.16.0 (J) - 1.6.0 (WP)
17 */
18 class VikBookingConditionalRuleRoomUpgrade extends VikBookingConditionalRule
19 {
20 /**
21 * @var array
22 */
23 protected $upgrade_options = [];
24
25 /**
26 * Class constructor will define the rule name, description and identifier.
27 */
28 public function __construct()
29 {
30 // call parent constructor
31 parent::__construct();
32
33 $this->ruleName = JText::translate('VBO_ROOM_UPGRADE');
34 $this->ruleDescr = JText::translate('VBO_ROOM_UPGRADE_CONDTEXT_H');
35 $this->ruleId = basename(__FILE__);
36 }
37
38 /**
39 * Displays the rule parameters.
40 *
41 * @return void
42 */
43 public function renderParams()
44 {
45 ?>
46 <div class="vbo-param-container">
47 <div class="vbo-param-label"><?php echo JText::translate('VBO_ROOM_UPGRADE'); ?></div>
48 <div class="vbo-param-setting">
49 <?php echo $this->vbo_app->printYesNoButtons($this->inputName('can_upgrade'), JText::translate('VBYES'), JText::translate('VBNO'), (int)$this->getParam('can_upgrade', 0), 1, 0); ?>
50 <span class="vbo-param-setting-comment"><?php echo JText::translate('VBO_ROOM_UPGRADE_CONDTEXT_H'); ?></span>
51 </div>
52 </div>
53 <div class="vbo-param-container">
54 <div class="vbo-param-label"><?php echo JText::translate('VBO_ROOM_UPGRADE_ADDCONTMSG'); ?></div>
55 <div class="vbo-param-setting">
56 <?php echo $this->vbo_app->printYesNoButtons($this->inputName('add_details'), JText::translate('VBYES'), JText::translate('VBNO'), (int)$this->getParam('add_details', 0), 1, 0); ?>
57 <span class="vbo-param-setting-comment"><?php echo JText::translate('VBO_CONDTEXT_MSG') . ' - ' . JText::translate('VBO_CONDTEXT_TKN') . ': '; ?><span onclick="vboRoomUpgradeAddContentEditor('{room_upgrade}');" style="cursor: pointer;">{room_upgrade}</span></span>
58 </div>
59 </div>
60
61 <script type="text/javascript">
62 function vboRoomUpgradeAddContentEditor(str) {
63 if (!str) {
64 return;
65 }
66
67 try {
68 // "msg" is the name of the WYSIWYG editor of the conditional text
69 Joomla.editors.instances.msg.replaceSelection(str);
70 } catch(e) {
71 // do nothing
72 }
73 }
74 </script>
75 <?php
76 }
77
78 /**
79 * Tells whether the rule is compliant.
80 *
81 * @return bool True on success, false otherwise.
82 */
83 public function isCompliant()
84 {
85 $can_upgrade = (bool)$this->getParam('can_upgrade', 0);
86 if (!$can_upgrade) {
87 return true;
88 }
89
90 $booking = $this->getProperty('booking', []);
91 if (!is_array($booking) || !count($booking)) {
92 return false;
93 }
94
95 $rooms_booked = $this->getProperty('rooms', []);
96 if (!is_array($rooms_booked) || !count($rooms_booked)) {
97 return false;
98 }
99
100 // booking status must be confirmed
101 if ($this->getPropVal('booking', 'status', '') != 'confirmed') {
102 return false;
103 }
104
105 // translator object
106 $vbo_tn = VikBooking::getTranslator();
107
108 // look for available upgrade options
109 $this->upgrade_options = VBORoomHelper::getInstance([
110 'booking' => $booking,
111 'rooms' => $rooms_booked,
112 ], true)->getUpgradeOptions($vbo_tn);
113
114 return ($this->upgrade_options && $this->upgrade_options['upgrade']);
115 }
116
117 /**
118 * Allows to manipulate the message of the conditional text with dynamic contents.
119 *
120 * @override
121 *
122 * @param string $msg the current conditional text message.
123 *
124 * @return string the manipulated conditional text message.
125 */
126 public function manipulateMessage($msg)
127 {
128 $add_details = (bool)$this->getParam('add_details', 0);
129 if (!$add_details || !$this->upgrade_options || !$this->upgrade_options['upgrade']) {
130 return $msg;
131 }
132
133 // build HTML content
134 $upgrade_html_details = $this->buildHtmlUpgradeDetails();
135
136 if (strpos($msg, '{room_upgrade}') !== false) {
137 // exact placeholder tag found
138 return str_replace('{room_upgrade}', $upgrade_html_details, $msg);
139 }
140
141 // append upgrade details content to message
142 return $msg . $upgrade_html_details;
143 }
144
145 /**
146 * Builds the necessary HTML content with the upgrade details
147 * to be added to the conditional text message.
148 *
149 * @return string
150 */
151 protected function buildHtmlUpgradeDetails()
152 {
153 if (!$this->upgrade_options || !$this->upgrade_options['upgrade']) {
154 return '';
155 }
156
157 // access booking information
158 $booking = $this->getProperty('booking', []);
159 $rooms_booked = $this->getProperty('rooms', []);
160
161 // build booking link
162 $use_sid = !empty($booking['idorderota']) && !empty($booking['channel']) ? $booking['idorderota'] : $booking['sid'];
163 $booking_link = VikBooking::externalroute("index.php?option=com_vikbooking&view=booking&sid={$use_sid}&ts={$booking['ts']}&room_upgrade=1", false);
164
165 // get preferences
166 $currencysymb = VikBooking::getCurrencySymb();
167 $pref_colors = VikBooking::getPreferredColors();
168
169 // default colors for button-links
170 $btnlink_bgc = '#3d89d1';
171 $btnlink_col = '#ffffff';
172 if (!empty($pref_colors['bgcolor']) && !empty($pref_colors['fontcolor'])) {
173 $btnlink_bgc = $pref_colors['bgcolor'];
174 $btnlink_col = $pref_colors['fontcolor'];
175 }
176
177 // start output buffering
178 ob_start();
179
180 foreach ($this->upgrade_options['upgrade'] as $upgk => $upg_data) {
181 ?>
182 <div style="margin: 4px 0; padding: 6px;">
183 <?php
184 foreach ($upg_data['r_costs'] as $rid => $upgrade_sol) {
185 $upg_room_name = $this->upgrade_options['rooms'][$rid]['name'];
186 ?>
187 <div style="display: inline-block; margin: 4px; padding: 4px; border: 1px solid #ddd; border-radius: 6px; vertical-align: top; width: 100%; box-sizing: border-box;">
188 <div style="display: inline-block;width: 30%;float: left;">
189 <?php
190 if (!empty($this->upgrade_options['rooms'][$rid]['img'])) {
191 ?>
192 <img src="<?php echo VBO_SITE_URI; ?>resources/uploads/<?php echo $this->upgrade_options['rooms'][$rid]['img']; ?>" alt="<?php echo htmlspecialchars($upg_room_name); ?>" title="<?php echo htmlspecialchars($upg_room_name); ?>" style="border-radius: 4px; max-width: 100%; display: block;" />
193 <?php
194 }
195 ?>
196 </div>
197 <div style="font-weight: normal; display: inline-block; float: left; width: 68%; margin-left: 2%; padding: 4px 0;">
198 <div style="font-weight: bold;"><?php echo $upg_room_name; ?></div>
199 <?php
200 if (!empty($this->upgrade_options['rooms'][$rid]['smalldesc'])) {
201 ?>
202 <div style="margin: 3px 0 5px 0; font-size: 12px;"><?php echo $this->shortenDescr($this->upgrade_options['rooms'][$rid]['smalldesc']); ?></div>
203 <?php
204 }
205 ?>
206 <div style="margin-top: 5px;">
207 <span style="font-weight: bold;"><?php echo VikBooking::formatCurrencyNumber(VikBooking::numberFormat($upgrade_sol['upgrade_cost']), $currencysymb); ?></span><?php
208 if (isset($upg_data['discount']) && $upg_data['discount'] > 0) {
209 ?><span style="margin-left: 10px; color: #52aa20;"><?php echo JText::sprintf('VBO_YOU_SAVE_PCENT', $upg_data['discount'] . '%'); ?></span><?php
210 }
211 ?>
212 </div><?php
213 // do not touch empty PHP lines in order to avoid empty <p></p> tags with WordPress
214 ?></div>
215 <div style="margin: 8px 0 0 2%;float: left;">
216 <a href="<?php echo $booking_link; ?>" target="_blank" style="padding: 4px 6px; border: 1px solid #ddd; border-radius: 4px; background-color: <?php echo $btnlink_bgc; ?>; color: <?php echo $btnlink_col; ?>; text-decoration: none; font-weight:bold; display: inline-block;"><?php echo JText::translate('VBO_UPGRADE_CONFIRM'); ?></a>
217 </div>
218 </div>
219 <?php
220 }
221 ?>
222 </div>
223 <?php
224 }
225
226 // get the HTML buffer and return it
227 $html_content = ob_get_contents();
228 ob_end_clean();
229
230 return $html_content;
231 }
232
233 /**
234 * Shortens a description string.
235 *
236 * @param string $descr the original description string.
237 * @param int $chars the limit of chars to apply.
238 *
239 * @return string the shorten description string.
240 */
241 protected function shortenDescr($descr, $chars = 150)
242 {
243 if (function_exists('mb_strlen')) {
244 // safe multi-byte environment
245 if (mb_strlen($descr) > $chars) {
246 // we are forced to strip any HTML tags when using a sub-string
247 $descr = strip_tags($descr);
248 if (mb_strlen($descr) > $chars) {
249 // still exceeding the limit
250 $descr = mb_substr($descr, 0, $chars, 'UTF-8') . '...';
251 }
252 }
253
254 return $descr;
255 }
256
257 if (strlen($descr) > $chars) {
258 // we are forced to strip any HTML tags when using a sub-string
259 $descr = strip_tags($descr);
260 if (strlen($descr) > $chars) {
261 // still exceeding the limit
262 $descr = substr($descr, 0, $chars) . '...';
263 }
264 }
265
266 return $descr;
267 }
268 }
269