| 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 |
$dbo = JFactory::getDbo(); |
| 14 |
$app = JFactory::getApplication(); |
| 15 |
|
| 16 |
$vbo_app = VikBooking::getVboApplication(); |
| 17 |
$vbo_app->loadSelect2(); |
| 18 |
|
| 19 |
$config = VBOFactory::getConfig(); |
| 20 |
|
| 21 |
JText::script('VBO_CREATE_LISTING_ON_OTA'); |
| 22 |
JText::script('VBOCHECKINSTATUSUPDATED'); |
| 23 |
JText::script('VBO_OTA_ACCOUNT_ID'); |
| 24 |
JText::script('VBO_OTA_LISTING_ID'); |
| 25 |
JText::script('VBANNULLA'); |
| 26 |
JText::script('VBSAVE'); |
| 27 |
JText::script('VBOCATEGORYFILTER'); |
| 28 |
|
| 29 |
$rows = $this->rows; |
| 30 |
$lim0 = $this->lim0; |
| 31 |
$navbut = $this->navbut; |
| 32 |
$orderby = $this->orderby; |
| 33 |
$ordersort = $this->ordersort; |
| 34 |
|
| 35 |
$prname = $app->getUserStateFromRequest("vbo.rooms.rname", 'rname', '', 'string'); |
| 36 |
$pidcat = $app->getUserStateFromRequest("vbo.rooms.idcat", 'idcat', 0, 'int'); |
| 37 |
?> |
| 38 |
<div class="vbo-list-form-filters vbo-btn-toolbar"> |
| 39 |
<form action="index.php?option=com_vikbooking&task=rooms" method="post" name="roomsform"> |
| 40 |
<div style="width: 100%; display: inline-block;" class="btn-toolbar" id="filter-bar"> |
| 41 |
<div class="btn-group pull-left"> |
| 42 |
<select name="idcat" id="idcat" onchange="document.roomsform.submit();"> |
| 43 |
<option></option> |
| 44 |
<?php |
| 45 |
foreach ($this->allcats as $cat) { |
| 46 |
?> |
| 47 |
<option value="<?php echo $cat['id']; ?>"<?php echo $cat['id'] == $pidcat ? ' selected="selected"' : ''; ?>><?php echo $cat['name']; ?></option> |
| 48 |
<?php |
| 49 |
} |
| 50 |
?> |
| 51 |
</select> |
| 52 |
</div> |
| 53 |
<div class="btn-group pull-left input-append btn-group-right-el"> |
| 54 |
<input type="text" name="rname" id="rname" value="<?php echo $this->escape($prname); ?>" size="40" placeholder="<?php echo $this->escape(JText::translate('VBPVIEWROOMONE')); ?>"/> |
| 55 |
<button type="button" class="btn btn-secondary" onclick="document.roomsform.submit();"><i class="icon-search"></i></button> |
| 56 |
</div> |
| 57 |
<div class="btn-group pull-left"> |
| 58 |
<button type="button" class="btn btn-secondary" onclick="document.getElementById('rname').value='';document.getElementById('idcat').value='';document.roomsform.submit();"><?php echo JText::translate('JSEARCH_FILTER_CLEAR'); ?></button> |
| 59 |
</div> |
| 60 |
</div> |
| 61 |
<input type="hidden" name="task" value="rooms" /> |
| 62 |
<input type="hidden" name="option" value="com_vikbooking" /> |
| 63 |
</form> |
| 64 |
</div> |
| 65 |
<script> |
| 66 |
(function($) { |
| 67 |
'use strict'; |
| 68 |
|
| 69 |
$(function() { |
| 70 |
$('#idcat').select2({ |
| 71 |
allowClear: true, |
| 72 |
placeholder: Joomla.JText._('VBOCATEGORYFILTER'), |
| 73 |
width: 200, |
| 74 |
}); |
| 75 |
}); |
| 76 |
})(jQuery); |
| 77 |
</script> |
| 78 |
<?php |
| 79 |
if (empty($rows)) { |
| 80 |
?> |
| 81 |
<p class="warn"><?php echo JText::translate('VBNOROOMSFOUND'); ?></p> |
| 82 |
<form action="index.php?option=com_vikbooking" method="post" name="adminForm" id="adminForm"> |
| 83 |
<input type="hidden" name="task" value="" /> |
| 84 |
<input type="hidden" name="option" value="com_vikbooking" /> |
| 85 |
</form> |
| 86 |
<?php |
| 87 |
} else { |
| 88 |
?> |
| 89 |
<form action="index.php?option=com_vikbooking" method="post" name="adminForm" id="adminForm" class="vbo-list-form"> |
| 90 |
<div class="table-responsive"> |
| 91 |
<table cellpadding="4" cellspacing="0" border="0" width="100%" class="table table-striped vbo-list-table"> |
| 92 |
<thead> |
| 93 |
<tr> |
| 94 |
<th width="20"> |
| 95 |
<input type="checkbox" onclick="Joomla.checkAll(this)" value="" name="checkall-toggle"> |
| 96 |
</th> |
| 97 |
<th class="title left" width="150"> |
| 98 |
<a href="index.php?option=com_vikbooking&task=rooms&vborderby=name&vbordersort=<?php echo ($orderby == "name" && $ordersort == "ASC" ? "DESC" : "ASC"); ?>" class="<?php echo ($orderby == "name" && $ordersort == "ASC" ? "vbo-list-activesort" : ($orderby == "name" ? "vbo-list-activesort" : "")); ?>"> |
| 99 |
<?php echo JText::translate('VBPVIEWROOMONE').($orderby == "name" && $ordersort == "ASC" ? '<i class="'.VikBookingIcons::i('sort-asc').'"></i>' : ($orderby == "name" ? '<i class="'.VikBookingIcons::i('sort-desc').'"></i>' : '<i class="'.VikBookingIcons::i('sort').'"></i>')); ?> |
| 100 |
</a> |
| 101 |
</th> |
| 102 |
<th class="title center" align="center" width="75"> |
| 103 |
<a href="index.php?option=com_vikbooking&task=rooms&vborderby=toadult&vbordersort=<?php echo ($orderby == "toadult" && $ordersort == "ASC" ? "DESC" : "ASC"); ?>" class="<?php echo ($orderby == "toadult" && $ordersort == "ASC" ? "vbo-list-activesort" : ($orderby == "toadult" ? "vbo-list-activesort" : "")); ?>"> |
| 104 |
<?php echo JText::translate('VBPVIEWROOMADULTS').($orderby == "toadult" && $ordersort == "ASC" ? '<i class="'.VikBookingIcons::i('sort-asc').'"></i>' : ($orderby == "toadult" ? '<i class="'.VikBookingIcons::i('sort-desc').'"></i>' : '<i class="'.VikBookingIcons::i('sort').'"></i>')); ?> |
| 105 |
</a> |
| 106 |
</th> |
| 107 |
<th class="title center" align="center" width="75"> |
| 108 |
<a href="index.php?option=com_vikbooking&task=rooms&vborderby=tochild&vbordersort=<?php echo ($orderby == "tochild" && $ordersort == "ASC" ? "DESC" : "ASC"); ?>" class="<?php echo ($orderby == "tochild" && $ordersort == "ASC" ? "vbo-list-activesort" : ($orderby == "tochild" ? "vbo-list-activesort" : "")); ?>"> |
| 109 |
<?php echo JText::translate('VBPVIEWROOMCHILDREN').($orderby == "tochild" && $ordersort == "ASC" ? '<i class="'.VikBookingIcons::i('sort-asc').'"></i>' : ($orderby == "tochild" ? '<i class="'.VikBookingIcons::i('sort-desc').'"></i>' : '<i class="'.VikBookingIcons::i('sort').'"></i>')); ?> |
| 110 |
</a> |
| 111 |
</th> |
| 112 |
<th class="title center" align="center" width="75"> |
| 113 |
<a href="index.php?option=com_vikbooking&task=rooms&vborderby=totpeople&vbordersort=<?php echo ($orderby == "totpeople" && $ordersort == "ASC" ? "DESC" : "ASC"); ?>" class="<?php echo ($orderby == "totpeople" && $ordersort == "ASC" ? "vbo-list-activesort" : ($orderby == "totpeople" ? "vbo-list-activesort" : "")); ?>"> |
| 114 |
<?php echo JText::translate('VBPVIEWROOMTOTPEOPLE').($orderby == "totpeople" && $ordersort == "ASC" ? '<i class="'.VikBookingIcons::i('sort-asc').'"></i>' : ($orderby == "totpeople" ? '<i class="'.VikBookingIcons::i('sort-desc').'"></i>' : '<i class="'.VikBookingIcons::i('sort').'"></i>')); ?> |
| 115 |
</a> |
| 116 |
</th> |
| 117 |
<th class="title center" width="75"><?php echo JText::translate( 'VBPVIEWROOMTWO' ); ?></th> |
| 118 |
<th class="title center" align="center" width="75"><?php echo JText::translate( 'VBPVIEWROOMTHREE' ); ?></th> |
| 119 |
<th class="title center" align="center" width="75"><?php echo JText::translate( 'VBPVIEWROOMFOUR' ); ?></th> |
| 120 |
<th class="title center" align="center" width="100"><?php echo JText::translate( 'VBOCHANNELS' ); ?></th> |
| 121 |
<th class="title center" align="center" width="75"> |
| 122 |
<a href="index.php?option=com_vikbooking&task=rooms&vborderby=units&vbordersort=<?php echo ($orderby == "units" && $ordersort == "ASC" ? "DESC" : "ASC"); ?>" class="<?php echo ($orderby == "units" && $ordersort == "ASC" ? "vbo-list-activesort" : ($orderby == "units" ? "vbo-list-activesort" : "")); ?>"> |
| 123 |
<?php echo JText::translate('VBPVIEWROOMSEVEN').($orderby == "units" && $ordersort == "ASC" ? '<i class="'.VikBookingIcons::i('sort-asc').'"></i>' : ($orderby == "units" ? '<i class="'.VikBookingIcons::i('sort-desc').'"></i>' : '<i class="'.VikBookingIcons::i('sort').'"></i>')); ?> |
| 124 |
</a> |
| 125 |
</th> |
| 126 |
<th class="title center" align="center" width="100"> |
| 127 |
<a href="index.php?option=com_vikbooking&task=rooms&vborderby=avail&vbordersort=<?php echo ($orderby == "avail" && $ordersort == "ASC" ? "DESC" : "ASC"); ?>" class="<?php echo ($orderby == "avail" && $ordersort == "ASC" ? "vbo-list-activesort" : ($orderby == "avail" ? "vbo-list-activesort" : "")); ?>"> |
| 128 |
<?php echo JText::translate('VBPVIEWROOMSIX').($orderby == "avail" && $ordersort == "ASC" ? '<i class="'.VikBookingIcons::i('sort-asc').'"></i>' : ($orderby == "avail" ? '<i class="'.VikBookingIcons::i('sort-desc').'"></i>' : '<i class="'.VikBookingIcons::i('sort').'"></i>')); ?> |
| 129 |
</a> |
| 130 |
</th> |
| 131 |
</tr> |
| 132 |
</thead> |
| 133 |
<?php |
| 134 |
$vcm_logos = VikBooking::getVcmChannelsLogo('', true); |
| 135 |
$website_source_lbl = JText::translate('VBORDFROMSITE'); |
| 136 |
$kk = 0; |
| 137 |
$i = 0; |
| 138 |
for ($i = 0, $n = count($rows); $i < $n; $i++) { |
| 139 |
$row = $rows[$i]; |
| 140 |
$categories = []; |
| 141 |
if (strlen(trim(str_replace(";", "", (string)$row['idcat']))) > 0) { |
| 142 |
$cat = explode(";", $row['idcat']); |
| 143 |
$catsfound = false; |
| 144 |
$q = "SELECT `name` FROM `#__vikbooking_categories` WHERE "; |
| 145 |
foreach ($cat as $k => $cc) { |
| 146 |
if (!empty($cc)) { |
| 147 |
$q .= "`id`=".$dbo->quote($cc)." "; |
| 148 |
if ($cc != end($cat) && !empty($cat[($k + 1)])) { |
| 149 |
$q .= "OR "; |
| 150 |
} |
| 151 |
$catsfound = true; |
| 152 |
} |
| 153 |
} |
| 154 |
$q .= ";"; |
| 155 |
if ($catsfound) { |
| 156 |
$dbo->setQuery($q); |
| 157 |
$lines = $dbo->loadAssocList(); |
| 158 |
foreach ($lines as $ll) { |
| 159 |
$categories[] = $ll['name']; |
| 160 |
} |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
$caratteristiche = '<span class="label">0</span>'; |
| 165 |
if (!empty($row['idcarat'])) { |
| 166 |
$tmpcarat = explode(";", $row['idcarat']); |
| 167 |
$caratteristiche = '<span class="label">' . VikBooking::totElements($tmpcarat) . '</span>'; |
| 168 |
} |
| 169 |
|
| 170 |
$optionals = '<span class="label">0</span>'; |
| 171 |
if (!empty($row['idopt'])) { |
| 172 |
$tmpopt = explode(";", $row['idopt']); |
| 173 |
$optionals = '<span class="label">' . VikBooking::totElements($tmpopt) . '</span>'; |
| 174 |
} |
| 175 |
|
| 176 |
if ($row['fromadult'] == $row['toadult']) { |
| 177 |
$stradult = $row['fromadult']; |
| 178 |
} else { |
| 179 |
$stradult = $row['fromadult'].' - '.$row['toadult']; |
| 180 |
} |
| 181 |
if ($row['fromchild'] == $row['tochild']) { |
| 182 |
$strchild = $row['fromchild']; |
| 183 |
} else { |
| 184 |
$strchild = $row['fromchild'].' - '.$row['tochild']; |
| 185 |
} |
| 186 |
|
| 187 |
// shared calendar icon |
| 188 |
$sharedcal = ''; |
| 189 |
if (!empty($row['sharedcals'])) { |
| 190 |
$sharedcal = '<span class="vbo-room-sharedcalendar" title="' . $this->escape(JText::translate('VBOROOMCALENDARSHARED')) . '"><i class="' . VikBookingIcons::i('calendar-check') . '"></i></span> '; |
| 191 |
} |
| 192 |
|
| 193 |
// VCM room's channels mapped |
| 194 |
$website_source_lbl_short = substr($website_source_lbl, 0, 1); |
| 195 |
if (function_exists('mb_substr')) { |
| 196 |
$website_source_lbl_short = mb_substr($website_source_lbl, 0, 1, 'UTF-8'); |
| 197 |
} |
| 198 |
$roomchannels = array($website_source_lbl => strtoupper($website_source_lbl_short)); |
| 199 |
$otachannels = is_object($vcm_logos) && method_exists($vcm_logos, 'getVboRoomLogosMapped') ? $vcm_logos->getVboRoomLogosMapped($row['id']) : array(); |
| 200 |
$roomchannels = count($otachannels) ? array() : $roomchannels; |
| 201 |
$roomchannels = array_merge($roomchannels, $otachannels); |
| 202 |
|
| 203 |
// VCM room onboardable OTAs |
| 204 |
$onboardable_otas = []; |
| 205 |
$room_ota_accounts = []; |
| 206 |
if (is_object($vcm_logos) && method_exists($vcm_logos, 'getRoomOnboardableChannels')) { |
| 207 |
$onboardable_otas = $vcm_logos->getRoomOnboardableChannels($row['id']); |
| 208 |
$room_ota_accounts = $vcm_logos->getRoomOtaAccounts(); |
| 209 |
$room_ota_accounts = $room_ota_accounts[$row['id']] ?? []; |
| 210 |
} |
| 211 |
|
| 212 |
// room upgrade option |
| 213 |
$room_upgrade_options = $config->getArray('room_upgrade_options_' . $row['id'], []); |
| 214 |
$room_upgrade_enabled = (!empty($room_upgrade_options['rooms']) && $room_upgrade_options['rooms']); |
| 215 |
?> |
| 216 |
<tr class="row<?php echo $kk; ?>"> |
| 217 |
<td><input type="checkbox" id="cb<?php echo $i;?>" name="cid[]" value="<?php echo $row['id']; ?>" onclick="Joomla.isChecked(this.checked);"></td> |
| 218 |
<td class="vbo-highlighted-td"><a href="index.php?option=com_vikbooking&task=editroom&cid[]=<?php echo $row['id']; ?>"><?php echo $row['name']; ?></a></td> |
| 219 |
<td class="center"><?php echo $stradult; ?></td> |
| 220 |
<td class="center"><?php echo $strchild; ?></td> |
| 221 |
<td class="center"><?php echo $row['mintotpeople'].' - '.$row['totpeople']; ?></td> |
| 222 |
<td class="center"><?php |
| 223 |
if ($categories && count($categories) < 4) { |
| 224 |
echo implode(', ', $categories); |
| 225 |
} else if ($categories) { |
| 226 |
?> |
| 227 |
<span class="label" title="<?php echo $this->escape(implode(', ', $categories)); ?>"><?php echo count($categories); ?></span> |
| 228 |
<?php |
| 229 |
} else { |
| 230 |
echo '----' ; |
| 231 |
} |
| 232 |
?></td> |
| 233 |
<td class="center"> |
| 234 |
<?php |
| 235 |
if (strpos((string)$row['params'], 'geo":{"enabled":1') !== false) { |
| 236 |
?> |
| 237 |
<span class="vbo-room-sharedcalendar" title="<?php echo $this->escape(JText::translate('VBO_GEO_INFO')); ?>"><?php VikBookingIcons::e('map-marked-alt'); ?></span> |
| 238 |
<?php |
| 239 |
} |
| 240 |
if ($room_upgrade_enabled) { |
| 241 |
?> |
| 242 |
<span class="vbo-room-sharedcalendar" title="<?php echo $this->escape(JText::translate('VBO_ROOM_UPGRADE')); ?>"><?php VikBookingIcons::e('gem'); ?></span> |
| 243 |
<?php |
| 244 |
} |
| 245 |
echo $caratteristiche; |
| 246 |
?> |
| 247 |
</td> |
| 248 |
<td class="center"><?php echo $optionals; ?></td> |
| 249 |
<td class="center"> |
| 250 |
<div class="vbo-room-channels-mapped-wrap"> |
| 251 |
<?php |
| 252 |
$ch_counter = 0; |
| 253 |
foreach ($roomchannels as $source => $churi) { |
| 254 |
if (in_array(preg_replace("/api$/", '', $source), $onboardable_otas)) { |
| 255 |
// the room is mapped with the current channel, but we have a pending onboarding |
| 256 |
$ch_counter++; |
| 257 |
continue; |
| 258 |
} |
| 259 |
|
| 260 |
$is_img = (strpos($churi, 'http') !== false); |
| 261 |
// build readable channel name |
| 262 |
$raw_ch_name = $source; |
| 263 |
$lower_name = strtolower($raw_ch_name); |
| 264 |
$lower_name = preg_replace("/(hotel|vr)$/", ' $1', $lower_name); |
| 265 |
$channel_name = ucwords(preg_replace("/api$/", '', $lower_name)); |
| 266 |
// build OTA account attributes |
| 267 |
$ota_account_attributes = []; |
| 268 |
if (!strcasecmp(($room_ota_accounts[$ch_counter]['channel'] ?? ''), $source)) { |
| 269 |
$ota_account_attributes = [ |
| 270 |
'data-ota-name="' . $this->escape($channel_name) . '"', |
| 271 |
'data-ota-idroom="' . $this->escape(($room_ota_accounts[$ch_counter]['idroomota'] ?? '')) . '"', |
| 272 |
'data-ota-account-name="' . $this->escape(($room_ota_accounts[$ch_counter]['account_name'] ?? '')) . '"', |
| 273 |
'data-ota-account-id="' . $this->escape(($room_ota_accounts[$ch_counter]['host_main_id'] ?? '')) . '"', |
| 274 |
]; |
| 275 |
} |
| 276 |
?> |
| 277 |
<div class="vbo-tooltip vbo-tooltip-top vbo-room-channels-mapped-ch" data-tooltiptext="<?php echo $this->escape($channel_name); ?>"<?php echo $ota_account_attributes ? ' ' . implode(' ', $ota_account_attributes) : ''; ?>> |
| 278 |
<span class="vbo-room-channels-mapped-ch-lbl"> |
| 279 |
<?php |
| 280 |
if ($is_img) { |
| 281 |
?> |
| 282 |
<img src="<?php echo $churi; ?>" alt="<?php echo $source; ?>" /> |
| 283 |
<?php |
| 284 |
} else { |
| 285 |
?> |
| 286 |
<span><?php echo $churi; ?></span> |
| 287 |
<?php |
| 288 |
} |
| 289 |
?> |
| 290 |
</span> |
| 291 |
</div> |
| 292 |
<?php |
| 293 |
$ch_counter++; |
| 294 |
} |
| 295 |
foreach ($onboardable_otas as $ch_id => $ch_name) { |
| 296 |
$ch_logo_url = $vcm_logos ? $vcm_logos->setProvenience($ch_name, $ch_name)->getTinyLogoURL() : ''; |
| 297 |
if (!$ch_logo_url || strpos($ch_logo_url, 'http') === false) { |
| 298 |
continue; |
| 299 |
} |
| 300 |
?> |
| 301 |
<div |
| 302 |
class="vbo-tooltip vbo-tooltip-top vbo-room-channels-onboard-ch" |
| 303 |
data-chid="<?php echo $ch_id; ?>" |
| 304 |
data-chname="<?php echo $this->escape($ch_name); ?>" |
| 305 |
data-roomid="<?php echo $row['id']; ?>" |
| 306 |
data-tooltiptext="<?php echo $this->escape(JText::sprintf('VBO_CREATE_LISTING_ON_OTA', $ch_name)); ?>" |
| 307 |
> |
| 308 |
<span class="vbo-room-channels-onboard-ch-lbl"> |
| 309 |
<?php VikBookingIcons::e('plus'); ?> |
| 310 |
<img src="<?php echo $ch_logo_url; ?>" alt="<?php echo $ch_name; ?>" /> |
| 311 |
</span> |
| 312 |
</div> |
| 313 |
<?php |
| 314 |
} |
| 315 |
?> |
| 316 |
</div> |
| 317 |
</td> |
| 318 |
<td class="center"><?php echo $sharedcal . '<span class="label label-info">' . $row['units'] . '</span>'; ?></td> |
| 319 |
<td class="center"> |
| 320 |
<a href="<?php echo VBOFactory::getPlatform()->getUri()->addCSRF('index.php?option=com_vikbooking&task=modavail&cid[]=' . $row['id'], true); ?>"><?php echo (intval($row['avail'])=="1" ? "<i class=\"".VikBookingIcons::i('check', 'vbo-icn-img')."\" style=\"color: #099909;\" title=\"".JText::translate('VBMAKENOTAVAIL')."\"></i>" : "<i class=\"".VikBookingIcons::i('times-circle', 'vbo-icn-img')."\" style=\"color: #ff0000;\" title=\"".JText::translate('VBMAKEAVAIL')."\"></i>"); ?></a> |
| 321 |
</td> |
| 322 |
</tr> |
| 323 |
<?php |
| 324 |
$kk = 1 - $kk; |
| 325 |
} |
| 326 |
?> |
| 327 |
</table> |
| 328 |
</div> |
| 329 |
<input type="hidden" name="option" value="com_vikbooking" /> |
| 330 |
<input type="hidden" name="task" value="rooms" /> |
| 331 |
<input type="hidden" name="boxchecked" value="0" /> |
| 332 |
<input type="hidden" name="rname" value="<?php echo $prname; ?>" /> |
| 333 |
<input type="hidden" name="idcat" value="<?php echo $pidcat; ?>" /> |
| 334 |
<?php echo JHtml::fetch('form.token'); ?> |
| 335 |
<?php echo $navbut; ?> |
| 336 |
</form> |
| 337 |
|
| 338 |
<script type="text/javascript"> |
| 339 |
jQuery(function() { |
| 340 |
|
| 341 |
jQuery('.vbo-room-channels-onboard-ch').on('click', function() { |
| 342 |
let channel_id = jQuery(this).attr('data-chid'); |
| 343 |
let channel_name = jQuery(this).attr('data-chname'); |
| 344 |
let room_id = jQuery(this).attr('data-roomid'); |
| 345 |
let room_name = jQuery(this).closest('tr').find('td.vbo-highlighted-td').text(); |
| 346 |
|
| 347 |
let cancel_btn = jQuery('<button></button>') |
| 348 |
.attr('type', 'button') |
| 349 |
.addClass('btn') |
| 350 |
.text(Joomla.JText._('VBANNULLA')) |
| 351 |
.on('click', function() { |
| 352 |
VBOCore.emitEvent('vbo-ota-onboard-listing-dismiss'); |
| 353 |
}); |
| 354 |
|
| 355 |
let save_btn = jQuery('<button></button>') |
| 356 |
.attr('type', 'button') |
| 357 |
.addClass('btn btn-success') |
| 358 |
.text(Joomla.JText._('VBSAVE')) |
| 359 |
.on('click', function() { |
| 360 |
// start loading |
| 361 |
VBOCore.emitEvent('vbo-ota-onboard-listing-loading'); |
| 362 |
|
| 363 |
try { |
| 364 |
// prepare toast message container |
| 365 |
VBOToast.create(VBOToast.POSITION_TOP_CENTER); |
| 366 |
VBOToast.changePosition(VBOToast.POSITION_TOP_CENTER); |
| 367 |
} catch(err) { |
| 368 |
// do nothing |
| 369 |
} |
| 370 |
|
| 371 |
// get form values |
| 372 |
let formValues = jQuery('#vbo-vcm-onboard-listing-form').serialize(); |
| 373 |
|
| 374 |
// perform the request |
| 375 |
VBOCore.doAjax( |
| 376 |
"<?php echo VikBooking::ajaxUrl('index.php?option=com_vikchannelmanager&task=otaonboarding.create'); ?>", |
| 377 |
formValues, |
| 378 |
(resp) => { |
| 379 |
// dispatch toast success message |
| 380 |
VBOToast.enqueue(new VBOToastMessage({ |
| 381 |
body: Joomla.JText._('VBOCHECKINSTATUSUPDATED'), |
| 382 |
icon: 'fas fa-check-circle', |
| 383 |
status: VBOToast.SUCCESS_STATUS, |
| 384 |
action: () => { |
| 385 |
VBOToast.dispose(true); |
| 386 |
}, |
| 387 |
})); |
| 388 |
|
| 389 |
// dismiss the modal on success |
| 390 |
VBOCore.emitEvent('vbo-ota-onboard-listing-dismiss'); |
| 391 |
|
| 392 |
// reload the current page |
| 393 |
window.location.reload(); |
| 394 |
}, |
| 395 |
(error) => { |
| 396 |
// stop loading |
| 397 |
VBOCore.emitEvent('vbo-ota-onboard-listing-loading'); |
| 398 |
|
| 399 |
// attempt to decode the possible JSON erroneous response |
| 400 |
try { |
| 401 |
let errorData = JSON.parse(error.responseText); |
| 402 |
|
| 403 |
// dispatch the event to display the current progress |
| 404 |
VBOCore.emitEvent('vbo-vcm-onboard-progress-updated', errorData); |
| 405 |
|
| 406 |
// display a delayed error |
| 407 |
setTimeout(() => { |
| 408 |
alert(errorData.error); |
| 409 |
}, 100); |
| 410 |
} catch(err) { |
| 411 |
// display the raw error as it was not a JSON-encoded string |
| 412 |
alert(error.responseText); |
| 413 |
} |
| 414 |
} |
| 415 |
); |
| 416 |
}); |
| 417 |
|
| 418 |
let modal_body = VBOCore.displayModal({ |
| 419 |
suffix: 'ota-onboard-listing', |
| 420 |
extra_class: 'vbo-modal-rounded vbo-modal-tall', |
| 421 |
title: Joomla.JText._('VBO_CREATE_LISTING_ON_OTA').replace('%s', channel_name) + ' - ' + room_name, |
| 422 |
footer_left: cancel_btn, |
| 423 |
footer_right: save_btn, |
| 424 |
dismiss_event: 'vbo-ota-onboard-listing-dismiss', |
| 425 |
loading_event: 'vbo-ota-onboard-listing-loading', |
| 426 |
}); |
| 427 |
|
| 428 |
// start loading |
| 429 |
VBOCore.emitEvent('vbo-ota-onboard-listing-loading'); |
| 430 |
|
| 431 |
// perform the request |
| 432 |
VBOCore.doAjax( |
| 433 |
"<?php echo VikBooking::ajaxUrl('index.php?option=com_vikchannelmanager&task=otaonboarding.new'); ?>", |
| 434 |
{ |
| 435 |
channel_id: channel_id, |
| 436 |
channel_name: channel_name, |
| 437 |
room_id: room_id, |
| 438 |
}, |
| 439 |
(resp) => { |
| 440 |
// stop loading |
| 441 |
VBOCore.emitEvent('vbo-ota-onboard-listing-loading'); |
| 442 |
try { |
| 443 |
let obj_res = typeof resp === 'string' ? JSON.parse(resp) : resp; |
| 444 |
modal_body.append(obj_res['html']); |
| 445 |
} catch (err) { |
| 446 |
console.error('Error decoding the response', err, resp); |
| 447 |
} |
| 448 |
}, |
| 449 |
(error) => { |
| 450 |
alert(error.responseText); |
| 451 |
// dismiss the modal |
| 452 |
VBOCore.emitEvent('vbo-ota-onboard-listing-dismiss'); |
| 453 |
} |
| 454 |
); |
| 455 |
}); |
| 456 |
|
| 457 |
jQuery('.vbo-room-channels-mapped-ch[data-ota-idroom]').on('click', function() { |
| 458 |
let room_name = jQuery(this).closest('tr').find('td.vbo-highlighted-td').text(); |
| 459 |
let channel_img = jQuery(this).find('img').attr('src'); |
| 460 |
let ota_name = jQuery(this).attr('data-ota-name'); |
| 461 |
let ota_idroom = jQuery(this).attr('data-ota-idroom'); |
| 462 |
let ota_account_name = jQuery(this).attr('data-ota-account-name'); |
| 463 |
let ota_account_id = jQuery(this).attr('data-ota-account-id'); |
| 464 |
|
| 465 |
if (!ota_name || !ota_idroom || !ota_account_id) { |
| 466 |
return; |
| 467 |
} |
| 468 |
|
| 469 |
let listing_details_html = ''; |
| 470 |
listing_details_html += '<div class="vbo-admin-container vbo-admin-container-full vbo-admin-container-compact">'; |
| 471 |
listing_details_html += ' <div class="vbo-params-wrap">'; |
| 472 |
listing_details_html += ' <div class="vbo-params-container">'; |
| 473 |
listing_details_html += ' <div class="vbo-params-block">'; |
| 474 |
|
| 475 |
listing_details_html += ' <div class="vbo-param-container">'; |
| 476 |
listing_details_html += ' <div class="vbo-param-label"><img class="vbo-room-ota-listing-details" src="' + channel_img + '" title="' + ota_name + '" /></div>'; |
| 477 |
listing_details_html += ' <div class="vbo-param-setting"><strong>' + ota_account_name + '</strong></div>'; |
| 478 |
listing_details_html += ' </div>'; |
| 479 |
|
| 480 |
listing_details_html += ' <div class="vbo-param-container">'; |
| 481 |
listing_details_html += ' <div class="vbo-param-label"><strong>' + Joomla.JText._('VBO_OTA_ACCOUNT_ID') + '</strong></div>'; |
| 482 |
listing_details_html += ' <div class="vbo-param-setting"><span class="label label-info">' + ota_account_id + '</span></div>'; |
| 483 |
listing_details_html += ' </div>'; |
| 484 |
|
| 485 |
listing_details_html += ' <div class="vbo-param-container">'; |
| 486 |
listing_details_html += ' <div class="vbo-param-label"><strong>' + Joomla.JText._('VBO_OTA_LISTING_ID') + '</strong></div>'; |
| 487 |
listing_details_html += ' <div class="vbo-param-setting"><span class="label label-info">' + ota_idroom + '</span></div>'; |
| 488 |
listing_details_html += ' </div>'; |
| 489 |
|
| 490 |
listing_details_html += ' </div>'; |
| 491 |
listing_details_html += ' </div>'; |
| 492 |
listing_details_html += ' </div>'; |
| 493 |
listing_details_html += '</div>'; |
| 494 |
|
| 495 |
VBOCore.displayModal({ |
| 496 |
suffix: 'ota-listing-details', |
| 497 |
extra_class: 'vbo-modal-rounded vbo-modal-dialog vbo-modal-nofooter', |
| 498 |
title: room_name, |
| 499 |
body: listing_details_html, |
| 500 |
}); |
| 501 |
}); |
| 502 |
|
| 503 |
/** |
| 504 |
* Mini thumbnails background generation. |
| 505 |
*/ |
| 506 |
setTimeout(() => { |
| 507 |
VBOCore.doAjax( |
| 508 |
"<?php echo VikBooking::ajaxUrl('index.php?option=com_vikbooking&task=listings.check_mini_thumbnails'); ?>", |
| 509 |
{}, |
| 510 |
(result) => { |
| 511 |
if (typeof result === 'object') { |
| 512 |
console.info('Mini thumbnails processed (' + result.processed + ') and generated (' + result.generated + ').'); |
| 513 |
} |
| 514 |
}, |
| 515 |
(error) => { |
| 516 |
console.error(error); |
| 517 |
} |
| 518 |
); |
| 519 |
}, 1000); |
| 520 |
|
| 521 |
}); |
| 522 |
</script> |
| 523 |
<?php |
| 524 |
} |
| 525 |
|