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/tmpl/default.php +301 -22 1.8.6 → 1.8.16 View file →
@@ -15,8 +15,10 @@
15 15 $busy = $this->busy;
16 16 $customer = $this->customer;
17 17 $payments = $this->payments;
18 18
19 +// load registry and history
20 +$registry = VBOBookingRegistry::getInstance($this->row, $this->rooms);
19 21 $history_obj = VikBooking::getBookingHistoryInstance($row['id']);
20 22
21 23 // availability helper
22 24 $av_helper = VikBooking::getAvailabilityInstance();
@@ -215,8 +217,24 @@
215 217
216 218 // extend administration sidebar
217 219 $adminSidebarForms = $this->onDisplayView('AdministrationSidebar');
218 220
221 +/**
222 + * Check if messaging accounts have been configured through the E4jConnect Channel Manager.
223 + * If some messaging API accounts have been configured, SMS fallback will no longer be displayed.
224 + *
225 + * @since 1.18.8 (J) - 1.8.8 (WP)
226 + */
227 +$messagingAccountConfigurations = [];
228 +if (class_exists('VCMMessagingAccountsModel')) {
229 + $messagingAccountConfigurations = VCMMessagingAccountsModel::getInstance()->getConfigurationsData(
230 + new VCMMessagingTemplateDecoratorBooking($registry),
231 + [
232 + 'listings' => $registry->getBookedListingIds(),
233 + ]
234 + );
235 +}
236 +
219 237 //Prepare modal (used for the Registration and for reconstructing the credit card details through the channel manager)
220 238 echo $vbo_app->getJmodalScript();
221 239 //end Prepare modal
222 240 ?>
@@ -720,9 +738,9 @@
720 738 },
721 739 (res) => {
722 740 // parse the JSON response that contains the categories object with all fields for the reporting
723 741 try {
724 - var misconduct_fields_rs = JSON.parse(res);
742 + var misconduct_fields_rs = typeof res === 'string' ? JSON.parse(res) : res;
725 743
726 744 // make sure the request was successful
727 745 if (!misconduct_fields_rs.status) {
728 746 alert(misconduct_fields_rs.error);
@@ -907,9 +925,9 @@
907 925 url: "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikchannelmanager&task=submit_bcom_guestmisconduct'); ?>",
908 926 data: submit_fields
909 927 }).done(function(res) {
910 928 try {
911 - var misconduct_rs = JSON.parse(res);
929 + var misconduct_rs = typeof res === 'string' ? JSON.parse(res) : res;
912 930 console.log(submit_fields, misconduct_rs);
913 931
914 932 // make sure the request was successful
915 933 if (!misconduct_rs.status) {
@@ -1047,9 +1065,9 @@
1047 1065 $orig_checkout_dt_obj = new JDate($prev_ir_data[0]->checkout_date);
1048 1066 ?>
1049 1067 <div class="vbo-bookdet-container vbo-bookdet-inquiry-alert">
1050 1068 <div class="vbo-bookdet-inquiry-alert-dismiss">
1051 - <button type="button" class="btn btn-warning" onclick="jQuery('.vbo-bookdet-inquiry-alert').remove();"><?php VikBookingIcons::e('times-circle'); ?> <?php echo JText::translate('VBOBTNKEEPREMIND'); ?></button>
1069 + <button type="button" class="btn btn-small btn-warning" onclick="jQuery('.vbo-bookdet-inquiry-alert').remove();"><?php VikBookingIcons::e('times-circle'); ?> <?php echo JText::translate('VBOBTNKEEPREMIND'); ?></button>
1052 1070 </div>
1053 1071 <div class="vbo-bookdet-inquiry-alert-message">
1054 1072 <div class="vbo-bookdet-inquiry-alert-top">
1055 1073 <span><?php echo JText::translate('VBO_WEB_INQUIRY_ALERT'); ?></span>
@@ -1083,8 +1101,43 @@
1083 1101 </div>
1084 1102 <div class="vbo-bookdet-inquiry-alert-bottom">
1085 1103 <span><?php echo JText::translate('VBO_WEB_INQUIRY_SUGG'); ?></span>
1086 1104 </div>
1105 + <?php
1106 + if (empty($row['idquote'])) {
1107 + // even if it cannot be a quote, we make sure it's just an inquiry for now
1108 + $createQuoteUri = 'index.php?option=com_vikbooking&view=managequote&' . http_build_query([
1109 + 'customer' => [
1110 + 'id' => $customer['id'] ?? null,
1111 + 'first_name' => $customer['first_name'] ?? null,
1112 + 'last_name' => $customer['last_name'] ?? null,
1113 + 'email' => $customer['email'] ?? null,
1114 + 'phone' => $customer['phone'] ?? null,
1115 + 'country' => $customer['country'] ?? null,
1116 + ],
1117 + 'inquiry' => [
1118 + 'checkin' => date('Y-m-d', $row['checkin']),
1119 + 'checkout' => date('Y-m-d', $row['checkout']),
1120 + 'parties' => array_map(function($or) {
1121 + return [
1122 + 'adults' => $or['adults'] ?? 1,
1123 + 'children' => $or['children'] ?? 0,
1124 + ];
1125 + }, $rooms),
1126 + 'rooms' => array_map(function($or) {
1127 + return [
1128 + 'id' => $or['idroom'] ?? 0,
1129 + ];
1130 + }, $rooms),
1131 + ],
1132 + ]);
1133 + ?>
1134 + <div class="vbo-bookdet-inquiry-alert-bottom">
1135 + <a class="btn vbo-config-btn" href="<?php echo VBOFactory::getPlatform()->getUri()->admin($createQuoteUri); ?>"><?php VikBookingIcons::e('file-alt'); ?> <?php echo JText::translate('VBO_CREATE_QUOTE'); ?></a>
1136 + </div>
1137 + <?php
1138 + }
1139 + ?>
1087 1140 </div>
1088 1141 </div>
1089 1142 <?php
1090 1143 }
@@ -1100,8 +1153,15 @@
1100 1153 <button onclick="document.location.href='index.php?option=com_vikbooking&task=editbusy&cid[]=<?php echo $row['id']; ?>';" class="btn vbo-config-btn" type="button"><i class="icon-pencil"></i> <?php echo JText::translate('VBMODRES'); ?></button>
1101 1154 </div>
1102 1155 <?php
1103 1156 }
1157 + if (!empty($row['idquote'])) {
1158 + ?>
1159 + <div class="vbo-bookingdet-command">
1160 + <button class="btn vbo-config-btn vbo-quote-details-btn" type="button"><?php VikBookingIcons::e('file-alt'); ?> <?php echo JText::translate('VBO_QUOTE_DETAILS'); ?></button>
1161 + </div>
1162 + <?php
1163 + }
1104 1164 if ((array_key_exists(1, $tars) && $tars[1]) || ($is_package || $is_cust_cost)) {
1105 1165
1106 1166 if (VBOPlatformDetection::isWordPress()) {
1107 1167 /**
@@ -1106,10 +1166,10 @@
1106 1166 if (VBOPlatformDetection::isWordPress()) {
1107 1167 /**
1108 1168 * @wponly display warning message if no valid Shortcodes found
1109 1169 */
1110 - $model = JModel::getInstance('vikbooking', 'shortcodes');
1111 - $itemid = $model->best('booking');
1170 + $model = JModel::getInstance('vikbooking', 'shortcodes');
1171 + $itemid = $model->best('booking');
1112 1172 if (!$itemid) {
1113 1173 VikError::raiseWarning('', 'No Shortcodes found, or no Shortcodes being used in Pages/Posts.');
1114 1174 }
1115 1175 }
@@ -1268,8 +1328,15 @@
1268 1328 * @since 1.18.0 (J) - 1.8.0 (WP)
1269 1329 */
1270 1330 $taskManager = VBOFactory::getTaskManager();
1271 1331 $bookingTasks = VBOTaskModelTask::getInstance()->filterItems(['id_order' => $row['id']]);
1332 +
1333 + /**
1334 + * Check if the booking should have had passcodes generated.
1335 + *
1336 + * @since 1.18.16 (J) - 1.8.16 (WP)
1337 + */
1338 + $shouldHavePasscodes = !$history_obj->hasEvent(['ND', 'MD']) && VBOFactory::getDoorAccessControl()->shouldBookingHavePasscodes($registry);
1272 1339 ?>
1273 1340
1274 1341 <div class="vbo-bookingdet-tab-cont" id="vbo-tab-details" style="display: block;">
1275 1342 <div class="vbo-bookingdet-innercontainer">
@@ -1316,8 +1383,20 @@
1316 1383 </div>
1317 1384 </div>
1318 1385 <?php
1319 1386 }
1387 + if ($shouldHavePasscodes) {
1388 + ?>
1389 + <div class="vbo-bookingdet-detcont vbo-bookingdet-detcont-dac vbo-hidein-print">
1390 + <div class="vbo-bookingdet-lblcont">
1391 + <label><?php echo JText::translate('VBO_W_DOORACCESSCONTROL_TITLE'); ?></label>
1392 + </div>
1393 + <div class="vbo-bookingdet-inpwrap vbo-bookingdet-dac-gen">
1394 + <a href="<?php echo VBOFactory::getPlatform()->getUri()->addCSRF('index.php?option=com_vikbooking&task=bookings.generatePasscodes&bid=' . $row['id']); ?>" class="btn"><?php echo JText::translate('VBO_CREATE_PASSCODE'); ?></a>
1395 + </div>
1396 + </div>
1397 + <?php
1398 + }
1320 1399 ?>
1321 1400 <div class="vbo-bookingdet-detcont<?php echo $row['closure'] > 0 ? ' vbo-bookingdet-closure' : ''; ?>">
1322 1401 <?php
1323 1402 $custdata_parts = explode("\n", $row['custdata']);
@@ -1342,11 +1421,11 @@
1342 1421 }
1343 1422 unset($custdet_parts[0]);
1344 1423 if ((!strcasecmp(trim($custdet_parts[1]), 'http') || !strcasecmp(trim($custdet_parts[1]), 'https')) && !empty($custdet_parts[2]) && strpos($custdet_parts[2], '//') !== false) {
1345 1424 // this is a URI
1346 - $custd_val = '<a href="' . trim(implode(':', $custdet_parts)) . '" target="_blank"><i class="' . VikBookingIcons::i('external-link') . '"></i></a>';
1425 + $custd_val = '<a href="' . htmlspecialchars(trim(implode(':', $custdet_parts))) . '" target="_blank"><i class="' . VikBookingIcons::i('external-link') . '"></i></a>';
1347 1426 } else {
1348 - $custd_val = trim(implode(':', $custdet_parts));
1427 + $custd_val = htmlspecialchars(trim(implode(':', $custdet_parts)));
1349 1428 }
1350 1429 }
1351 1430 ?>
1352 1431 <div class="vbo-bookingdet-userdetail">
@@ -1619,10 +1698,9 @@
1619 1698 <!-- Define role to detect the supported hook -->
1620 1699 <!-- {"rule":"customizer","event":"onDisplayViewVikBookingEditorderSidebar","key":"invoice","type":"field"} -->
1621 1700
1622 1701 <?php
1623 - if (isset($bookingSidebarForms['invoice']))
1624 - {
1702 + if (isset($bookingSidebarForms['invoice'])) {
1625 1703 echo $bookingSidebarForms['invoice'];
1626 1704 }
1627 1705 ?>
1628 1706
@@ -1652,10 +1730,9 @@
1652 1730 <!-- Define role to detect the supported hook -->
1653 1731 <!-- {"rule":"customizer","event":"onDisplayViewVikBookingEditorderSidebar","key":"email","type":"field"} -->
1654 1732
1655 1733 <?php
1656 - if (isset($bookingSidebarForms['email']))
1657 - {
1734 + if (isset($bookingSidebarForms['email'])) {
1658 1735 echo $bookingSidebarForms['email'];
1659 1736 }
1660 1737 ?>
1661 1738
@@ -1667,13 +1744,27 @@
1667 1744 <div class="vbo-bookingdet-inpwrap">
1668 1745 <div class="vbo-bookingdet-inpcont">
1669 1746 <?php echo $vbo_app->printPhoneInputField(array('name' => 'custphone', 'id' => 'custphone', 'value' => $this->escape($row['phone'])), array('nationalMode' => false, 'fullNumberOnBlur' => true)); ?>
1670 1747 </div>
1671 - <?php if (!empty($row['phone'])) : ?>
1748 + <?php
1749 + if (!empty($row['phone'])) {
1750 + if ($messagingAccountConfigurations) {
1751 + // send a message to the guest phone number through the messaging API account(s) configured
1752 + ?>
1672 1753 <div class="vbo-bookingdet-btncont">
1754 + <button type="button" class="btn vbo-config-btn vbo-bookingdet-send-tplmessage-btn" style="vertical-align: top;"><?php VikBookingIcons::e('paper-plane'); ?> <?php echo JText::translate('VBO_SEND_MESSAGE'); ?></button>
1755 + </div>
1756 + <?php
1757 + } else {
1758 + // fallback onto SMS
1759 + ?>
1760 + <div class="vbo-bookingdet-btncont">
1673 1761 <button type="button" class="btn vbo-config-btn" onclick="vboDisplaySendSMS();" style="vertical-align: top;"><?php VikBookingIcons::e('comment-dots'); ?> <?php echo JText::translate('VBSENDSMSACTION'); ?></button>
1674 1762 </div>
1675 - <?php endif; ?>
1763 + <?php
1764 + }
1765 + }
1766 + ?>
1676 1767 </div>
1677 1768
1678 1769 <!-- Define role to detect the supported hook -->
1679 1770 <!-- {"rule":"customizer","event":"onDisplayViewVikBookingEditorderSidebar","key":"phone","type":"field"} -->
@@ -1678,24 +1769,48 @@
1678 1769 <!-- Define role to detect the supported hook -->
1679 1770 <!-- {"rule":"customizer","event":"onDisplayViewVikBookingEditorderSidebar","key":"phone","type":"field"} -->
1680 1771
1681 1772 <?php
1682 - if (isset($bookingSidebarForms['phone']))
1683 - {
1773 + if (isset($bookingSidebarForms['phone'])) {
1684 1774 echo $bookingSidebarForms['phone'];
1685 1775 }
1686 1776 ?>
1687 1777
1688 1778 </div>
1779 + <?php
1780 + if ($phoneAlias = $registry->getAliasPhoneNumber()) {
1781 + ?>
1782 + <div class="vbo-bookingdet-detcont vbo-hidein-print">
1783 + <div class="vbo-bookingdet-lblcont">
1784 + <label for="phone_alias"><?php VikBookingIcons::e('user-shield'); ?> <?php echo JText::translate('VBO_PHONE_ALIAS'); ?></label>
1785 + </div>
1786 + <div class="vbo-bookingdet-inpwrap">
1787 + <div class="vbo-bookingdet-inpcont">
1788 + <input type="text" id="phone_alias" value="<?php echo $this->escape($phoneAlias); ?>" readonly />
1789 + </div>
1790 + <span class="vbo-param-setting-comment"><?php echo JText::translate('VBO_PHONE_ALIAS_HELP'); ?></span>
1791 + </div>
1689 1792
1793 + <!-- Define role to detect the supported hook -->
1794 + <!-- {"rule":"customizer","event":"onDisplayViewVikBookingEditorderSidebar","key":"phone_alias","type":"field"} -->
1795 +
1796 + <?php
1797 + if (isset($bookingSidebarForms['phone_alias'])) {
1798 + echo $bookingSidebarForms['phone_alias'];
1799 + }
1800 + ?>
1801 +
1802 + </div>
1803 + <?php
1804 + }
1805 + ?>
1806 +
1690 1807 <!-- Define role to detect the supported hook -->
1691 1808 <!-- {"rule":"customizer","event":"onDisplayViewVikBookingEditorderSidebar","type":"fieldset"} -->
1692 1809
1693 1810 <?php
1694 - foreach ($bookingSidebarForms as $legend => $form)
1695 - {
1696 - if (in_array($legend, ['userdetails', 'invoice', 'email', 'phone']))
1697 - {
1811 + foreach ($bookingSidebarForms as $legend => $form) {
1812 + if (in_array($legend, ['userdetails', 'invoice', 'email', 'phone'])) {
1698 1813 // skip default forms
1699 1814 continue;
1700 1815 }
1701 1816 ?>
@@ -2225,8 +2340,12 @@
2225 2340 <?php
2226 2341 if ($row['total'] > 0 && !$row['closure']) {
2227 2342 $has_paid = ($row['totpaid'] > 0);
2228 2343 $diff_to_pay = $has_paid ? ($row['total'] - $row['totpaid']) : 0;
2344 + if ($diff_to_pay && !empty($row['idorderota']) && !empty($row['channel']) && round($row['cmms'], 2) == round($diff_to_pay, 2)) {
2345 + // the outstanding balance is equal to the OTA commissions amount
2346 + $diff_to_pay = 0;
2347 + }
2229 2348 if ($has_paid || $row['status'] != 'standby') {
2230 2349 ?>
2231 2350 <tr class="vbo-bookingdet-summary-totpaid">
2232 2351 <td>&nbsp;</td>
@@ -2430,11 +2549,11 @@
2430 2549 <?php
2431 2550 }
2432 2551 $chpayment = '';
2433 2552 if ($payments) {
2434 - $chpayment = '<div><select name="newpayment" id="newpayment" onchange="changePayment();"><option value="">'.JText::translate('VBCHANGEPAYLABEL').'</option>';
2553 + $chpayment = '<div><select name="newpayment" id="newpayment" onchange="changePayment();"><option value="">- ' . JText::translate('VBCHANGEPAYLABEL') . ' -</option>';
2435 2554 foreach ($payments as $pay) {
2436 - $chpayment .= '<option value="'.$pay['id'].'">'.(is_array($payment) && $payment['id'] == $pay['id'] ? ' ::' : '').$pay['name'].'</option>';
2555 + $chpayment .= '<option value="' . $pay['id'] . '">' . (is_array($payment) && $payment['id'] == $pay['id'] ? '- ' : '') . $pay['name'] . '</option>';
2437 2556 }
2438 2557 $chpayment .= '</select></div>';
2439 2558 }
2440 2559 echo $chpayment;
@@ -2641,9 +2760,9 @@
2641 2760 ?>
2642 2761 </div>
2643 2762 <div class="vbo-bookingdet-noteslogs-cont">
2644 2763 <div id="vbadminnotesdiv" class="vbo-extra-panel" style="display: block;">
2645 - <textarea name="adminnotes" class="vbadminnotestarea"><?php echo strip_tags((string)$row['adminnotes']); ?></textarea>
2764 + <textarea name="adminnotes" class="vbadminnotestarea"><?php echo JHtml::fetch('esc_textarea', (string) $row['adminnotes']); ?></textarea>
2646 2765 <input type="submit" name="updadmnotes" value="<?php echo JText::translate('VBADMINNOTESUPD'); ?>" class="btn btn-success" />
2647 2766 </div>
2648 2767 <?php
2649 2768 if ($takings) {
@@ -3785,8 +3904,60 @@
3785 3904 <button type="submit" class="btn vbo-config-btn" onclick="document.getElementById('vbo-modal-form-email').submit();"><?php VikBookingIcons::e('envelope'); ?> <?php echo JText::translate('VBSENDEMAILACTION'); ?></button>
3786 3905 </div>
3787 3906 </div>
3788 3907
3908 +<div class="vbo-bookingdet-send-tplmessage-helper" style="display: none;">
3909 + <div class="vbo-bookingdet-send-tplmessage-wrap">
3910 + <div class="vbo-admin-container vbo-admin-container-full vbo-admin-container-compact">
3911 + <div class="vbo-params-wrap">
3912 + <div class="vbo-params-container">
3913 + <div class="vbo-params-block">
3914 + <?php
3915 + echo VBOParamsRendering::getInstance(
3916 + [
3917 + 'ma_identifier' => [
3918 + 'type' => 'elements',
3919 + 'label' => JText::translate('VBO_MESSAGE_TEMPLATE'),
3920 + 'asset_options' => [
3921 + 'placeholder' => JText::translate('VBO_MESSAGE_TEMPLATE'),
3922 + 'allowClear' => false,
3923 + ],
3924 + 'inline' => false,
3925 + 'wrapdivcls' => 'vbo-singleselect-inline-elems-wrap vbo-singleselect-inline-small-icons',
3926 + 'style_selection' => true,
3927 + 'attributes' => [
3928 + 'data-element' => 'message-template',
3929 + ],
3930 + 'elements' => array_map(function($maConfig) {
3931 + if (!empty($maConfig['channel_logo'])) {
3932 + $messTplName = sprintf('%s (%s)', $maConfig['name'], $maConfig['lang']);
3933 + } else {
3934 + $messTplName = sprintf('%s - %s (%s)', $maConfig['channel_name'], $maConfig['name'], $maConfig['lang']);
3935 + }
3936 + return array_filter([
3937 + 'id' => $maConfig['identifier'],
3938 + 'name' => $messTplName,
3939 + 'img_uri' => ($maConfig['channel_logo'] ?? '') ?: null,
3940 + ]);
3941 + }, $messagingAccountConfigurations),
3942 + ],
3943 + ],
3944 + []
3945 + )->setInputName('send_ma_tpl')->getHtml();
3946 + ?>
3947 + <div class="vbo-param-container">
3948 + <div class="vbo-param-label"><?php echo JText::translate('VBOPREVIEW'); ?></div>
3949 + <div class="vbo-param-setting">
3950 + <div class="vbo-ma-send-tplmessage-preview"></div>
3951 + </div>
3952 + </div>
3953 + </div>
3954 + </div>
3955 + </div>
3956 + </div>
3957 + </div>
3958 +</div>
3959 +
3789 3960 <script type="text/javascript">
3790 3961 var vbo_print_only = false;
3791 3962 if (typeof jQuery.fn.tooltip === 'function') {
3792 3963 jQuery(".hasTooltip").tooltip();
@@ -3893,8 +4064,12 @@
3893 4064 }
3894 4065 // reload the page to display the new information about the booking just modified
3895 4066 location.reload();
3896 4067 });
4068 + // register click event for the button to see the quote details
4069 + document.querySelector('.vbo-quote-details-btn')?.addEventListener('click', (e) => {
4070 + VBOCore.handleDisplayWidgetNotification({widget_id: 'quotes'}, {bid: <?php echo $row['id']; ?>});
4071 + });
3897 4072 // remove overbooking flag
3898 4073 jQuery('.vbo-label-overbooking').on('click', function() {
3899 4074 if (confirm(Joomla.JText._('VBO_CONF_RM_OVERBOOKING_FLAG'))) {
3900 4075 VBOCore.doAjax(
@@ -4249,8 +4424,112 @@
4249 4424 otaBidEl.setAttribute('data-tooltiptext', <?php echo json_encode(JText::translate('VBO_COPIED') . '!'); ?>);
4250 4425 }).catch((err) => {
4251 4426 // do nothing
4252 4427 });
4428 + });
4429 + }
4430 +
4431 + // register events for sending a message template through a messaging account configuration
4432 + const messagingAccountsData = <?php echo json_encode($messagingAccountConfigurations); ?>;
4433 + const sendTplMessBtn = document.querySelector('.vbo-bookingdet-send-tplmessage-btn');
4434 + const sendTplMessContWrap = document.querySelector('.vbo-bookingdet-send-tplmessage-wrap');
4435 + jQuery(sendTplMessContWrap).find('select[data-element="message-template"]').on('change', function() {
4436 + let maIdentifier = this.value;
4437 + let previewEl = sendTplMessContWrap.querySelector('.vbo-ma-send-tplmessage-preview');
4438 + previewEl.innerHTML = '';
4439 + if (maIdentifier) {
4440 + messagingAccountsData.forEach((maData) => {
4441 + if (maData?.identifier == maIdentifier) {
4442 + // update preview content
4443 + previewEl.innerHTML = maData?.preview_html || '';
4444 + }
4445 + });
4446 + }
4447 + });
4448 + if (sendTplMessBtn) {
4449 + sendTplMessBtn.addEventListener('click', () => {
4450 + let cancelBtn = document.createElement('button');
4451 + cancelBtn.setAttribute('type', 'button');
4452 + cancelBtn.classList.add('btn');
4453 + cancelBtn.textContent = <?php echo json_encode(JText::translate('VBANNULLA')); ?>;
4454 + cancelBtn.addEventListener('click', () => {
4455 + VBOCore.emitEvent('vbo-send-tplmessage-dismiss');
4456 + });
4457 +
4458 + let confirmBtn = document.createElement('button');
4459 + confirmBtn.setAttribute('type', 'button');
4460 + confirmBtn.classList.add('btn', 'btn-primary');
4461 + confirmBtn.innerHTML = '<?php VikBookingIcons::e('paper-plane'); ?> ' + <?php echo json_encode(JText::translate('VBO_SEND_MESSAGE')); ?>;
4462 + confirmBtn.addEventListener('click', () => {
4463 + // get message template identifier data
4464 + let tplIdentifier = sendTplMessContWrap.querySelector('select[data-element="message-template"]')?.value;
4465 + if (!tplIdentifier) {
4466 + alert('Invalid message template');
4467 + return;
4468 + }
4469 +
4470 + // obtain selected template details
4471 + let tplIdentifierParts = tplIdentifier.split(':');
4472 +
4473 + // start loading
4474 + VBOCore.emitEvent('vbo-send-tplmessage-loading');
4475 + confirmBtn.disabled = true;
4476 +
4477 + // make the request
4478 + VBOCore.doAjax(
4479 + "<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=messaging.sendMessageTemplate'); ?>",
4480 + {
4481 + account_id: tplIdentifierParts[0],
4482 + phone_id: tplIdentifierParts[1],
4483 + config_id: tplIdentifierParts[2],
4484 + booking_id: <?php echo $this->row['id']; ?>,
4485 + },
4486 + (resp) => {
4487 + // dismiss modal on success
4488 + VBOCore.emitEvent('vbo-send-tplmessage-dismiss');
4489 +
4490 + // display success message
4491 + VBOToast.enqueue(new VBOToastMessage({
4492 + body: <?php echo json_encode(JText::translate('VBSENDEMAILOK')); ?>,
4493 + icon: '<?php echo VikBookingIcons::i('check-circle'); ?>',
4494 + status: VBOToast.SUCCESS_STATUS,
4495 + action: () => {
4496 + VBOToast.dispose(true);
4497 + },
4498 + }));
4499 +
4500 + // reload the page (just for the new history event)
4501 + location.reload();
4502 + },
4503 + (error) => {
4504 + // display error message
4505 + alert(error.responseText);
4506 +
4507 + // stop loading
4508 + VBOCore.emitEvent('vbo-send-tplmessage-loading');
4509 + confirmBtn.disabled = false;
4510 + }
4511 + );
4512 + });
4513 +
4514 + let modalBody = VBOCore.displayModal({
4515 + suffix: 'vbo-send-tplmessage',
4516 + extra_class: 'vbo-modal-rounded',
4517 + title: <?php echo json_encode(JText::translate('VBO_SEND_MESSAGE')); ?>,
4518 + footer_left: cancelBtn,
4519 + footer_right: confirmBtn,
4520 + draggable: true,
4521 + lock_scroll: true,
4522 + dismiss_event: 'vbo-send-tplmessage-dismiss',
4523 + loading_event: 'vbo-send-tplmessage-loading',
4524 + onDismiss: () => {
4525 + document.querySelector('.vbo-bookingdet-send-tplmessage-helper').append(
4526 + sendTplMessContWrap
4527 + );
4528 + },
4529 + });
4530 +
4531 + (modalBody[0] || modalBody).append(sendTplMessContWrap);
4253 4532 });
4254 4533 }
4255 4534
4256 4535 });