PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
1.8.16 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 All 37 releases
← All changes | admin/views/editorder/view.html.php +521 -0 1.6.0 → 1.8.16 View file →
@@ -1,0 +1,521 @@
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 +// import Joomla view library
14 +jimport('joomla.application.component.view');
15 +
16 +class VikBookingViewEditorder extends JViewVikBooking
17 +{
18 + public function display($tpl = null)
19 + {
20 + // Set the toolbar
21 + $this->addToolBar();
22 +
23 + if (!JFactory::getUser()->authorise('core.vbo.bookings', 'com_vikbooking')) {
24 + VBOHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR'));
25 + }
26 +
27 + $cid = VikRequest::getVar('cid', array(0));
28 + $ido = $cid[0];
29 +
30 + if (is_file(VCM_ADMIN_PATH.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'vcm-channels.css')) {
31 + $document = JFactory::getDocument();
32 + $document->addStyleSheet(VCM_ADMIN_URI.'assets/css/vikchannelmanager.css');
33 + $document->addStyleSheet(VCM_ADMIN_URI.'assets/css/vcm-channels.css');
34 + if (method_exists('VikChannelManager', 'loadAppearancePreferenceAssets')) {
35 + VikChannelManager::loadAppearancePreferenceAssets();
36 + }
37 + }
38 +
39 + $dbo = JFactory::getDbo();
40 + $app = JFactory::getApplication();
41 + $user = JFactory::getUser();
42 +
43 + $q = "SELECT * FROM `#__vikbooking_orders` WHERE `id`=" . $dbo->quote($ido);
44 + $dbo->setQuery($q, 0, 1);
45 + $row = $dbo->loadAssoc();
46 + if (!$row) {
47 + $app->redirect("index.php?option=com_vikbooking&task=orders");
48 + $app->close();
49 + return;
50 + }
51 +
52 + /**
53 + * Check currency conversion request, if needed and supported.
54 + *
55 + * @since 1.15.0 (J) - 1.5.0 (WP)
56 + */
57 + $do_ota_curr_conv = VikRequest::getInt('do_ota_curr_conv', 0, 'request');
58 + if ($do_ota_curr_conv) {
59 + $ota_helper = new VBOCurrencyOta($row);
60 + if (!$ota_helper->convertReservationCurrency()) {
61 + VikError::raiseWarning('', 'Something went wrong while trying to convert the OTA currency');
62 + }
63 + $app->redirect('index.php?option=com_vikbooking&task=editorder&cid[]=' . $row['id']);
64 + $app->close();
65 + }
66 +
67 + $q = "SELECT `id`,`name` FROM `#__vikbooking_gpayments` ORDER BY `#__vikbooking_gpayments`.`name` ASC;";
68 + $dbo->setQuery($q);
69 + $payments = $dbo->loadAssocList();
70 +
71 + $cpin = VikBooking::getCPinIstance();
72 + // VBO 1.11 - change customer assigned to this booking
73 + $pnewcustid = VikRequest::getInt('newcustid', 0, 'request');
74 + if (!empty($pnewcustid)) {
75 + $cpin->updateCustomerBooking($row['id'], $pnewcustid);
76 + // update empty values for the booking
77 + if (empty($row['custmail']) || empty($row['phone'])) {
78 + // get customer information
79 + $customer = $cpin->getCustomerByID($pnewcustid);
80 + if ($customer && (!empty($customer['email']) || !empty($customer['phone']))) {
81 + if (empty($row['custmail']) && !empty($customer['email'])) {
82 + $q = "UPDATE `#__vikbooking_orders` SET `custmail`=" . $dbo->quote($customer['email']) . " WHERE `id`=" . $row['id'] . ";";
83 + $dbo->setQuery($q);
84 + $dbo->execute();
85 + $row['custmail'] = $customer['email'];
86 + }
87 + if (empty($row['phone']) && !empty($customer['phone'])) {
88 + $q = "UPDATE `#__vikbooking_orders` SET `phone`=" . $dbo->quote($customer['phone']) . " WHERE `id`=" . $row['id'] . ";";
89 + $dbo->setQuery($q);
90 + $dbo->execute();
91 + $row['phone'] = $customer['phone'];
92 + }
93 + }
94 + }
95 + }
96 +
97 + $customer = $cpin->getCustomerFromBooking($row['id']);
98 + if ($customer && !empty($customer['country'])) {
99 + if (file_exists(VBO_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'countries'.DIRECTORY_SEPARATOR.$customer['country'].'.png')) {
100 + $customer['country_img'] = '<img src="'.VBO_ADMIN_URI.'resources/countries/'.$customer['country'].'.png'.'" title="'.$customer['country'].'" class="vbo-country-flag vbo-country-flag-left"/>';
101 + }
102 + }
103 +
104 + $padminnotes = VikRequest::getString('adminnotes', '', 'request');
105 + $pupdadmnotes = VikRequest::getString('updadmnotes', '', 'request');
106 + $pinvnotes = VikRequest::getString('invnotes', '', 'request', VIKREQUEST_ALLOWHTML);
107 + $pupdinvnotes = VikRequest::getString('updinvnotes', '', 'request');
108 + $pnewpayment = VikRequest::getString('newpayment', '', 'request');
109 + $pnewlang = VikRequest::getString('newlang', '', 'request');
110 + $padmindisc = VikRequest::getString('admindisc', '', 'request');
111 + $ptot_taxes = VikRequest::getString('tot_taxes', '', 'request');
112 + $ptot_city_taxes = VikRequest::getString('tot_city_taxes', '', 'request');
113 + $ptot_fees = VikRequest::getString('tot_fees', '', 'request');
114 + $pcmms = VikRequest::getString('cmms', '', 'request');
115 + $ptot_damage_dep = VikRequest::getString('tot_damage_dep', '', 'request');
116 + $pcustmail = VikRequest::getString('custmail', '', 'request');
117 + $pcustphone = VikRequest::getString('custphone', '', 'request');
118 + $pmakepay = VikRequest::getInt('makepay', 0, 'request');
119 + $pnewamountpaid = VikRequest::getFloat('newamountpaid', -1, 'request');
120 + $pnewamountpaymeth = VikRequest::getString('newamountpaymeth', '', 'request');
121 + // we update the total paid also if the input is 0.0 (float) as the default value is -1 (int)
122 + if (($pnewamountpaid > 0 || ($pnewamountpaid == 0 && is_float($pnewamountpaid))) && (float)$row['totpaid'] != $pnewamountpaid) {
123 + $prevpaid = (float)$row['totpaid'];
124 + $q = "UPDATE `#__vikbooking_orders` SET `totpaid`=".$dbo->quote($pnewamountpaid)." WHERE `id`=".$row['id'].";";
125 + $dbo->setQuery($q);
126 + $dbo->execute();
127 + $row['totpaid'] = $pnewamountpaid;
128 + // Booking History log for new amount paid (payment update)
129 + $extra_data = null;
130 + $newpaympaytype = '';
131 + if ($pnewamountpaid > $prevpaid) {
132 + $extra_data = new stdClass;
133 + $extra_data->amount_paid = ($pnewamountpaid - $prevpaid);
134 + if (!empty($pnewamountpaymeth)) {
135 + $payparts = explode('_', $pnewamountpaymeth);
136 + $newpaympaytype = count($payparts) > 1 ? $payparts[1] : $pnewamountpaymeth;
137 + $extra_data->payment_method = $newpaympaytype;
138 + }
139 + }
140 + VikBooking::getBookingHistoryInstance()->setBid($row['id'])->setExtraData($extra_data)->store('PU', JText::sprintf('VBOPREVAMOUNTPAID', VikBooking::numberFormat($prevpaid) . (!empty($newpaympaytype) ? ' ('.$newpaympaytype.')' : '')));
141 + //
142 + }
143 + $pnewamountrefunded = VikRequest::getFloat('newamountrefunded', -1, 'request');
144 + // we update the total refunded also if the input is 0.0 (float) as the default value is -1 (int)
145 + if (($pnewamountrefunded > 0 || ($pnewamountrefunded == 0 && is_float($pnewamountrefunded))) && (float)$row['refund'] != $pnewamountrefunded) {
146 + $prevrefunded = $row['refund'];
147 + $refund_diff = $pnewamountrefunded - $row['refund'];
148 + if ($refund_diff > 0) {
149 + // refund amount increased, lower the booking total
150 + $newtotal = $row['total'] - $refund_diff;
151 + // lower also the amount paid
152 + $newtotpaid = $row['totpaid'] > 0 ? ($row['totpaid'] - $refund_diff) : $row['totpaid'];
153 + } else {
154 + // refund amount decreased, increase the booking total
155 + $newtotal = $row['total'] + abs($refund_diff);
156 + // leave the totpaid unchanged in this case
157 + $newtotpaid = $row['totpaid'];
158 + }
159 + $q = "UPDATE `#__vikbooking_orders` SET `total`=" . $dbo->quote($newtotal) . ", `totpaid`=" . ($newtotpaid == null ? 'NULL' : $dbo->quote($newtotpaid)) . ", `refund`=" . $dbo->quote($pnewamountrefunded) . " WHERE `id`=" . $row['id'] . ";";
160 + $dbo->setQuery($q);
161 + $dbo->execute();
162 + $row['total'] = $newtotal;
163 + $row['refund'] = $pnewamountrefunded;
164 + // booking history log for new amount refunded
165 + VikBooking::getBookingHistoryInstance($row['id'])
166 + ->setExtraData([
167 + 'amount_paid' => ($pnewamountrefunded - $prevrefunded),
168 + ])
169 + ->store('RU', JText::sprintf('VBO_NEWREFUND_AMOUNT', VikBooking::numberFormat($prevrefunded), VikBooking::numberFormat($pnewamountrefunded)));
170 + }
171 + $pnewamountpayable = VikRequest::getFloat('newamountpayable', -1, 'request');
172 + // we update the amount payable also if the input is 0.0 (float) as the default value is -1 (int)
173 + if (($pnewamountpayable > 0 || ($pnewamountpayable == 0 && is_float($pnewamountpayable))) && (float)$row['payable'] != $pnewamountpayable) {
174 + $q = "UPDATE `#__vikbooking_orders` SET `payable`=" . $dbo->quote($pnewamountpayable) . " WHERE `id`=" . $row['id'] . ";";
175 + $dbo->setQuery($q);
176 + $dbo->execute();
177 + $row['payable'] = $pnewamountpayable;
178 + // booking history log for new amount payable
179 + VikBooking::getBookingHistoryInstance()->setBid($row['id'])->store('PB', JText::sprintf('VBO_NEWPAYABLE_AMOUNT', VikBooking::numberFormat($pnewamountpayable)));
180 + // make sure to update the payment counter, or if no payments ever made, the system won't accept a transaction
181 + if (!$row['paymcount']) {
182 + // turn flag on
183 + $pmakepay = 1;
184 + }
185 + }
186 + if ($pmakepay > 0) {
187 + // check if the payment counter should be updated
188 + $q = "UPDATE `#__vikbooking_orders` SET `paymcount`=" . $pmakepay . " WHERE `id`=" . $row['id'] . ";";
189 + $dbo->setQuery($q);
190 + $dbo->execute();
191 + $row['paymcount'] = 1;
192 + }
193 + $pnewcancfee = VikRequest::getFloat('newcancfee', -1, 'request');
194 + // we update the cancellation fee amount also if the input is 0.0 (float) as the default value is -1 (int)
195 + if (($pnewcancfee > 0 || ($pnewcancfee == 0 && is_float($pnewcancfee))) && (float)$row['canc_fee'] != $pnewcancfee) {
196 + $q = "UPDATE `#__vikbooking_orders` SET `canc_fee`=" . $dbo->quote($pnewcancfee) . " WHERE `id`=" . $row['id'] . ";";
197 + $dbo->setQuery($q);
198 + $dbo->execute();
199 + $row['canc_fee'] = $pnewcancfee;
200 + // booking history log for new cancellation fee amount
201 + VikBooking::getBookingHistoryInstance()->setBid($row['id'])->store('MB', sprintf(JText::translate('VBO_CANC_FEE') . ': %s', VikBooking::numberFormat($pnewcancfee)));
202 + }
203 + if (!empty($padminnotes) || !empty($pupdadmnotes)) {
204 + $q = "UPDATE `#__vikbooking_orders` SET `adminnotes`=".$dbo->quote($padminnotes)." WHERE `id`=".$row['id'].";";
205 + $dbo->setQuery($q);
206 + $dbo->execute();
207 + $row['adminnotes'] = $padminnotes;
208 + }
209 + if (!empty($pinvnotes) || !empty($pupdinvnotes)) {
210 + $pinvnotes = strpos($pinvnotes, '<br') !== false ? $pinvnotes : nl2br($pinvnotes);
211 + $q = "UPDATE `#__vikbooking_orders` SET `inv_notes`=".$dbo->quote($pinvnotes)." WHERE `id`=".$row['id'].";";
212 + $dbo->setQuery($q);
213 + $dbo->execute();
214 + $row['inv_notes'] = $pinvnotes;
215 + }
216 + if (!empty($pnewpayment) && $payments) {
217 + foreach ($payments as $npay) {
218 + if ((int)$npay['id'] == (int)$pnewpayment) {
219 + $newpayvalid = $npay['id'].'='.$npay['name'];
220 + $q = "UPDATE `#__vikbooking_orders` SET `idpayment`=".$dbo->quote($newpayvalid)." WHERE `id`=".$row['id'].";";
221 + $dbo->setQuery($q);
222 + $dbo->execute();
223 + $row['idpayment'] = $newpayvalid;
224 + break;
225 + }
226 + }
227 + }
228 + if (!empty($pnewlang)) {
229 + $q = "UPDATE `#__vikbooking_orders` SET `lang`=".$dbo->quote($pnewlang)." WHERE `id`=".$row['id'].";";
230 + $dbo->setQuery($q);
231 + $dbo->execute();
232 + $row['lang'] = $pnewlang;
233 + }
234 + if (strlen($padmindisc) > 0) {
235 + if (floatval($padmindisc) > 0.00) {
236 + $admincoupon = '-1;'.floatval($padmindisc).';'.JText::translate('VBADMINDISCOUNT');
237 + } else {
238 + $admincoupon = '';
239 + }
240 + $expcoupon = explode(";", $row['coupon']);
241 + // make sure the new discount is different than the previous one, and that the total amount is greater than zero
242 + if ($row['total'] > 0 && (empty($row['coupon']) || (float)$expcoupon[1] != (float)$padmindisc)) {
243 + // re-calculate new total by adding the previous discount and by subtracting the new one
244 + $newtotal = $row['total'] + (!empty($row['coupon']) ? (float)$expcoupon[1] : 0);
245 + $newtotal -= (float)$padmindisc;
246 + //
247 + $q = "UPDATE `#__vikbooking_orders` SET `coupon`=" . $dbo->quote($admincoupon) . ", `total`=" . $dbo->quote($newtotal) . " WHERE `id`={$row['id']};";
248 + $dbo->setQuery($q);
249 + $dbo->execute();
250 + $row['coupon'] = $admincoupon;
251 + $row['total'] = $newtotal;
252 + }
253 + }
254 + if (strlen($ptot_taxes) > 0) {
255 + $q = "UPDATE `#__vikbooking_orders` SET `tot_taxes`='".floatval($ptot_taxes)."' WHERE `id`=".$row['id'].";";
256 + $dbo->setQuery($q);
257 + $dbo->execute();
258 + $row['tot_taxes'] = $ptot_taxes;
259 + }
260 + if (strlen($ptot_city_taxes) > 0) {
261 + $q = "UPDATE `#__vikbooking_orders` SET `tot_city_taxes`='".floatval($ptot_city_taxes)."' WHERE `id`=".$row['id'].";";
262 + $dbo->setQuery($q);
263 + $dbo->execute();
264 + $row['tot_city_taxes'] = $ptot_city_taxes;
265 + }
266 + if (strlen($ptot_fees) > 0) {
267 + $q = "UPDATE `#__vikbooking_orders` SET `tot_fees`='".floatval($ptot_fees)."' WHERE `id`=".$row['id'].";";
268 + $dbo->setQuery($q);
269 + $dbo->execute();
270 + $row['tot_fees'] = $ptot_fees;
271 + }
272 + if (strlen($pcmms) > 0) {
273 + $q = "UPDATE `#__vikbooking_orders` SET `cmms`='".floatval($pcmms)."' WHERE `id`=".$row['id'].";";
274 + $dbo->setQuery($q);
275 + $dbo->execute();
276 + $row['cmms'] = $pcmms;
277 + }
278 + if (strlen($ptot_damage_dep) > 0) {
279 + $q = "UPDATE `#__vikbooking_orders` SET `tot_damage_dep`='".floatval($ptot_damage_dep)."' WHERE `id`=".$row['id'].";";
280 + $dbo->setQuery($q);
281 + $dbo->execute();
282 + $row['tot_damage_dep'] = $ptot_damage_dep;
283 + }
284 + if (strlen($pcustmail) > 0) {
285 + $q = "UPDATE `#__vikbooking_orders` SET `custmail`=".$dbo->quote($pcustmail)." WHERE `id`=".$row['id'].";";
286 + $dbo->setQuery($q);
287 + $dbo->execute();
288 + $row['custmail'] = $pcustmail;
289 + }
290 + if (strlen($pcustphone) > 0) {
291 + $q = "UPDATE `#__vikbooking_orders` SET `phone`=".$dbo->quote($pcustphone)." WHERE `id`=".$row['id'].";";
292 + $dbo->setQuery($q);
293 + $dbo->execute();
294 + $row['phone'] = $pcustphone;
295 + }
296 +
297 + /**
298 + * Vik Channel Manager booking assignable channels.
299 + *
300 + * @since 1.16.3 (J) - 1.6.3 (WP)
301 + */
302 + $vcm_assign_channel = VikRequest::getString('vcm_assign_channel', '', 'request');
303 + if (!empty($vcm_assign_channel) && class_exists('VCMOtaBooking')) {
304 + // current unix timestamp will be used in place of OTA Reservation ID
305 + $set_ota_bid = time();
306 +
307 + // update fields on db
308 + $q = "UPDATE `#__vikbooking_orders` SET `idorderota`=" . $dbo->quote($set_ota_bid) . ", `channel`=" . $dbo->quote($vcm_assign_channel) . " WHERE `id`=" . $row['id'] . ";";
309 + $dbo->setQuery($q);
310 + $dbo->execute();
311 +
312 + // overwrite booking properties
313 + $row['idorderota'] = $set_ota_bid;
314 + $row['channel'] = $vcm_assign_channel;
315 +
316 + // update booking history
317 + $user = JFactory::getUser();
318 + VikBooking::getBookingHistoryInstance()->setBid($row['id'])->store('CM', "({$user->name}) " . JText::sprintf('VBO_BOOKING_OTA_ASSIGNED', $vcm_assign_channel));
319 + }
320 +
321 + // load data
322 + $q = "SELECT `or`.*,`r`.`name`,`r`.`fromadult`,`r`.`toadult`,`r`.`params` FROM `#__vikbooking_ordersrooms` AS `or`,`#__vikbooking_rooms` AS `r` WHERE `or`.`idorder`=".(int)$row['id']." AND `or`.`idroom`=`r`.`id` ORDER BY `or`.`id` ASC;";
323 + $dbo->setQuery($q);
324 + $rooms = $dbo->loadAssocList();
325 + $q = "SELECT * FROM `#__vikbooking_ordersbusy` WHERE `idorder`=".(int)$row['id'].";";
326 + $dbo->setQuery($q);
327 + $busy = $dbo->loadAssocList();
328 +
329 + // Rooms Specific Unit
330 + $proomindex = VikRequest::getVar('roomindex', array());
331 + if (!empty($proomindex) && is_array($proomindex) && count($proomindex)) {
332 + $orig_rooms = $rooms;
333 + foreach ($proomindex as $or_id => $rind) {
334 + if (empty($or_id)) {
335 + continue;
336 + }
337 + $q = "UPDATE `#__vikbooking_ordersrooms` SET `roomindex`=".(!empty($rind) ? (int)$rind : "NULL")." WHERE `id`=".(int)$or_id." AND `idorder`=".(int)$row['id'].";";
338 + $dbo->setQuery($q);
339 + $dbo->execute();
340 + // update global array reference
341 + $sub_unit_changed = false;
342 + foreach ($rooms as $korr => $orr) {
343 + if ((int)$or_id == (int)$orr['id']) {
344 + $sub_unit_changed = ((string)$orr['roomindex'] != (string)$rind);
345 + $rooms[$korr]['roomindex'] = $rind;
346 + break;
347 + }
348 + }
349 + if (!$sub_unit_changed) {
350 + // no need to store a booking history record
351 + continue;
352 + }
353 + // try to store a booking history record when switching room sub-unit index
354 + if (!empty($rind)) {
355 + foreach ($orig_rooms as $korr => $orr) {
356 + if ((int)$or_id != (int)$orr['id']) {
357 + continue;
358 + }
359 + if (empty($orr['params'])) {
360 + continue;
361 + }
362 + $room_params = json_decode($orr['params'], true);
363 + if (is_array($room_params) && !empty($room_params['features'])) {
364 + $prev_subindex = empty($orr['roomindex']) ? '---' : $orr['roomindex'];
365 + $new_subindex = $rind;
366 + foreach ($room_params['features'] as $origrind => $rfeatures) {
367 + if ($orr['roomindex'] == $origrind) {
368 + foreach ($rfeatures as $fname => $fval) {
369 + if (strlen($fval)) {
370 + $prev_subindex = '#' . $origrind . ' - ' . JText::translate($fname) . ': ' . $fval;
371 + break;
372 + }
373 + }
374 + }
375 + if ($rind == $origrind) {
376 + foreach ($rfeatures as $fname => $fval) {
377 + if (strlen($fval)) {
378 + $new_subindex = '#' . $origrind . ' - ' . JText::translate($fname) . ': ' . $fval;
379 + break;
380 + }
381 + }
382 + }
383 + }
384 + //Booking History
385 + VikBooking::getBookingHistoryInstance()->setBid($row['id'])->store('MB', "({$user->name}) " . JText::sprintf('VBOROOMSUBUNITCHANGEFT', $orr['name'], $prev_subindex, $new_subindex));
386 + //
387 + }
388 + }
389 + }
390 + }
391 + }
392 +
393 + // PCI DSS Checking
394 + if (!empty($row['idorderota']) && !empty($row['channel']) && !empty($row['paymentlog'])) {
395 + if (stripos($row['paymentlog'], 'card number') !== false && strpos($row['paymentlog'], '*') !== false) {
396 + $checkout_info = getdate($row['checkout']);
397 + /**
398 + * Limit for accessing the credit card details has been changed to check-out
399 + * day at 23:59:59 + 10 extra days. It used to be at 23:59:59 on check-out day.
400 + *
401 + * @since 1.13
402 + */
403 + $cardlimit = mktime(23, 59, 59, $checkout_info['mon'], ($checkout_info['mday'] + 10), $checkout_info['year']);
404 + if (time() > $cardlimit) {
405 + $newlogstr = JText::translate('VBOCCLOGDATAREMOVEDPCIDSS');
406 + $q = "UPDATE `#__vikbooking_orders` SET `paymentlog`=".$dbo->quote($newlogstr)." WHERE `id`=".$row['id'].";";
407 + $dbo->setQuery($q);
408 + $dbo->execute();
409 + $row['paymentlog'] = $newlogstr;
410 + }
411 + }
412 + }
413 +
414 + // unset credit card details, if needed, maybe to re-collect them
415 + $unset_cc = VikRequest::getInt('unset_cc', 0, 'request');
416 + if ($unset_cc && empty($row['idorderota']) && !empty($row['paymentlog'])) {
417 + $q = "UPDATE `#__vikbooking_orders` SET `paymentlog` = NULL WHERE `id` = " . $row['id'] . ";";
418 + $dbo->setQuery($q);
419 + $dbo->execute();
420 + $row['paymentlog'] = null;
421 + }
422 +
423 + // detect if VCM exists
424 + $vcm_exists = class_exists('VikChannelManager');
425 +
426 + // attempt to get the VCM review ID within a try-catch statement to avoid SQL errors
427 + $vcm_review = null;
428 + if ($vcm_exists) {
429 + try {
430 + $q = "SELECT * FROM `#__vikchannelmanager_otareviews` WHERE `idorder`=" . (int)$row['id'] . ";";
431 + $dbo->setQuery($q);
432 + $vcm_review = $dbo->loadAssoc();
433 + } catch (Exception $e) {
434 + // do nothing as VCM is probably not available/enabled/updated
435 + $vcm_review = null;
436 + }
437 + }
438 +
439 + /**
440 + * Check if the reservation requires/supports additional actions.
441 + *
442 + * @since 1.14 (J) - 1.4.0 (WP)
443 + */
444 + $vcm_decline_actions = 0;
445 + $vcm_pre_approval = 0;
446 + $vcm_special_offer = 0;
447 + $vcm_host_to_guest_review = 0;
448 + $vcm_cancel_active_res = 0;
449 + if ($vcm_exists) {
450 + try {
451 + if (method_exists('VikChannelManager', 'reservationNeedsDeclineReasons')) {
452 + $vcm_decline_actions = (int)VikChannelManager::reservationNeedsDeclineReasons($row);
453 + }
454 + if (method_exists('VikChannelManager', 'reservationSupportsPreApproval')) {
455 + $vcm_pre_approval = VikChannelManager::reservationSupportsPreApproval($row);
456 + $vcm_pre_approval = $vcm_pre_approval === false ? 0 : $vcm_pre_approval;
457 + }
458 + if (method_exists('VikChannelManager', 'reservationSupportsSpecialOffer')) {
459 + $vcm_special_offer = VikChannelManager::reservationSupportsSpecialOffer($row);
460 + $vcm_special_offer = $vcm_special_offer === false ? 0 : $vcm_special_offer;
461 + }
462 + if (method_exists('VikChannelManager', 'hostToGuestReviewSupported')) {
463 + $vcm_host_to_guest_review = VikChannelManager::hostToGuestReviewSupported($row);
464 + $vcm_host_to_guest_review = $vcm_host_to_guest_review === false ? 0 : $vcm_host_to_guest_review;
465 + }
466 + if (method_exists('VikChannelManager', 'cancelActiveOtaReservation')) {
467 + $vcm_cancel_active_res = (int)VikChannelManager::cancelActiveOtaReservation($row);
468 + }
469 + } catch (Exception $e) {
470 + // do nothing as VCM is probably not available/enabled/updated
471 + }
472 + }
473 +
474 + /**
475 + * Build currency conversion details, if needed and supported.
476 + *
477 + * @since 1.15.0 (J) - 1.5.0 (WP)
478 + */
479 + $ota_helper = new VBOCurrencyOta($row);
480 + $allows_conversion = $ota_helper->supportsConversion($row['total']);
481 + $conv_from_currency = $allows_conversion !== false ? $ota_helper->getOTACurrency() : null;
482 + $conv_to_currency = $allows_conversion !== false ? $ota_helper->getCurrencyName() : null;
483 +
484 + $this->row = $row;
485 + $this->rooms = $rooms;
486 + $this->busy = $busy;
487 + $this->customer = $customer;
488 + $this->payments = $payments;
489 + $this->vcm_review = $vcm_review;
490 + $this->vcm_decline_actions = $vcm_decline_actions;
491 + $this->vcm_pre_approval = $vcm_pre_approval;
492 + $this->vcm_special_offer = $vcm_special_offer;
493 + $this->vcm_host_to_guest_review = $vcm_host_to_guest_review;
494 + $this->vcm_cancel_active_res = $vcm_cancel_active_res;
495 + $this->allows_conversion = $allows_conversion;
496 + $this->conv_from_currency = $conv_from_currency;
497 + $this->conv_to_currency = $conv_to_currency;
498 +
499 + // Display the template
500 + parent::display($tpl);
501 + }
502 +
503 + /**
504 + * Sets the toolbar
505 + */
506 + protected function addToolBar() {
507 + $printreceipt = VikRequest::getInt('print', 0, 'request');
508 + if ($printreceipt) {
509 + // do not print any header or buttons if we are printing the receipt
510 + return;
511 + }
512 +
513 + JToolBarHelper::title(JText::translate('VBMAINORDERTITLEEDIT'), 'vikbooking');
514 + JToolBarHelper::cancel( 'canceledorder', JText::translate('VBBACK'));
515 + JToolBarHelper::spacer();
516 + JToolBarHelper::custom( 'prev_booking', 'backward', 'backward', JText::translate('VBJQCALPREV'), false);
517 + JToolBarHelper::spacer();
518 + JToolBarHelper::custom( 'next_booking', 'forward', 'forward', JText::translate('VBJQCALNEXT'), false);
519 + JToolBarHelper::spacer();
520 + }
521 +}