| 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 |
$rooms = $this->rooms; |
| 14 |
$tsstart = $this->tsstart; |
| 15 |
$wmonthsel = $this->wmonthsel; |
| 16 |
$busy = $this->busy; |
| 17 |
$vbo_tn = $this->vbo_tn; |
| 18 |
|
| 19 |
$showpartlyres=VikBooking::showPartlyReserved(); |
| 20 |
$vbdateformat = VikBooking::getDateFormat(); |
| 21 |
if ($vbdateformat == "%d/%m/%Y") { |
| 22 |
$df = 'd/m/Y'; |
| 23 |
} elseif ($vbdateformat == "%m/%d/%Y") { |
| 24 |
$df = 'm/d/Y'; |
| 25 |
} else { |
| 26 |
$df = 'Y/m/d'; |
| 27 |
} |
| 28 |
$datesep = VikBooking::getDateSeparator(); |
| 29 |
|
| 30 |
$document = JFactory::getDocument(); |
| 31 |
//load jQuery |
| 32 |
if (VikBooking::loadJquery()) { |
| 33 |
//JHtml::fetch('jquery.framework', true, true); |
| 34 |
JHtml::fetch('script', VBO_SITE_URI.'resources/jquery-1.12.4.min.js'); |
| 35 |
} |
| 36 |
|
| 37 |
$pmonth = VikRequest::getInt('month', '', 'request'); |
| 38 |
$pshowtype = VikRequest::getInt('showtype', 2, 'request'); |
| 39 |
//1 = do not show the units - 2 = show the units remaning - 3 = show the number of units booked. |
| 40 |
$pshowtype = $pshowtype >= 1 && $pshowtype <= 3 ? $pshowtype : 1; |
| 41 |
$pitemid = VikRequest::getString('Itemid', '', 'request'); |
| 42 |
|
| 43 |
$begin_info = getdate($tsstart); |
| 44 |
|
| 45 |
$rids_qstring = ''; |
| 46 |
foreach ($rooms as $room) { |
| 47 |
$rids_qstring .= '&room_ids[]=' . $room['id']; |
| 48 |
} |
| 49 |
|
| 50 |
$inonout_allowed = true; |
| 51 |
$timeopst = VikBooking::getTimeOpenStore(); |
| 52 |
if (is_array($timeopst)) { |
| 53 |
if ($timeopst[0] < $timeopst[1]) { |
| 54 |
// check-in not allowed on a day where there is already a check out (no arrivals/depatures on the same day) |
| 55 |
$inonout_allowed = false; |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
?> |
| 60 |
<h3><?php echo JText::translate('VBOAVAILABILITYCALENDAR'); ?></h3> |
| 61 |
|
| 62 |
<div class="vbo-availability-controls"> |
| 63 |
<form action="<?php echo JRoute::rewrite('index.php?option=com_vikbooking&view=availability' . $rids_qstring . (!empty($pitemid) ? '&Itemid='.$pitemid : '')); ?>" method="post" name="vbmonths"> |
| 64 |
<?php echo $wmonthsel; ?> |
| 65 |
<?php |
| 66 |
foreach ($rooms as $room) { |
| 67 |
?> |
| 68 |
<input type="hidden" name="room_ids[]" value="<?php echo $room['id']; ?>" /> |
| 69 |
<?php |
| 70 |
} |
| 71 |
?> |
| 72 |
<input type="hidden" name="showtype" value="<?php echo $pshowtype; ?>" /> |
| 73 |
</form> |
| 74 |
<div class="vblegendediv"> |
| 75 |
<span class="vblegenda"><span class="vblegenda-status vblegfree"> </span> <span class="vblegenda-lbl"> <?php echo JText::translate('VBLEGFREE'); ?></span></span> |
| 76 |
<?php |
| 77 |
if ($showpartlyres) { |
| 78 |
?> |
| 79 |
<span class="vblegenda"><span class="vblegenda-status vblegwarning"> </span> <span class="vblegenda-lbl"> <?php echo JText::translate('VBLEGWARNING'); ?></span></span> |
| 80 |
<?php |
| 81 |
} |
| 82 |
?> |
| 83 |
<span class="vblegenda"><span class="vblegenda-status vblegbusy"> </span> <span class="vblegenda-lbl"> <?php echo JText::translate('VBLEGBUSY'); ?></span></span> |
| 84 |
</div> |
| 85 |
</div> |
| 86 |
|
| 87 |
<?php |
| 88 |
$check = is_array($busy) && count($busy) > 0 ? true : false; |
| 89 |
$days_labels = array( |
| 90 |
JText::translate('VBSUN'), |
| 91 |
JText::translate('VBMON'), |
| 92 |
JText::translate('VBTUE'), |
| 93 |
JText::translate('VBWED'), |
| 94 |
JText::translate('VBTHU'), |
| 95 |
JText::translate('VBFRI'), |
| 96 |
JText::translate('VBSAT') |
| 97 |
); |
| 98 |
?> |
| 99 |
<div class="vbo-availability-wrapper"> |
| 100 |
<?php |
| 101 |
foreach ($rooms as $rk => $room) { |
| 102 |
$nowts = $begin_info; |
| 103 |
$carats = VikBooking::getRoomCaratOriz($room['idcarat'], $vbo_tn); |
| 104 |
?> |
| 105 |
<div class="vbo-availability-room-container"> |
| 106 |
<div class="vbo-availability-room-details"> |
| 107 |
<div class="vbo-availability-room-details-first"> |
| 108 |
<div class="vbo-availability-room-details-left"> |
| 109 |
<?php |
| 110 |
if (!empty($room['img'])) { |
| 111 |
?> |
| 112 |
<img src="<?php echo VBO_SITE_URI; ?>resources/uploads/<?php echo $room['img']; ?>" alt="<?php echo htmlspecialchars($room['name']); ?>"/> |
| 113 |
<?php |
| 114 |
} |
| 115 |
?> |
| 116 |
</div> |
| 117 |
<div class="vbo-availability-room-details-right"> |
| 118 |
<h4><?php echo $room['name']; ?></h4> |
| 119 |
<div class="vbo-availability-room-details-descr"> |
| 120 |
<?php echo $room['smalldesc']; ?> |
| 121 |
</div> |
| 122 |
<?php |
| 123 |
if (!empty($carats)) { |
| 124 |
?> |
| 125 |
<div class="room_carats"> |
| 126 |
<?php echo $carats; ?> |
| 127 |
</div> |
| 128 |
<?php |
| 129 |
} |
| 130 |
?> |
| 131 |
</div> |
| 132 |
</div> |
| 133 |
<div class="vbo-availability-room-details-last vbselectr"> |
| 134 |
<div class="vbo-availability-room-details-last-inner"> |
| 135 |
<a class="btn vbo-pref-color-btn" id="vbo-av-btn-<?php echo $room['id']; ?>" href="<?php echo JRoute::rewrite('index.php?option=com_vikbooking&view=roomdetails&roomid='.$room['id'].'&checkin=-1'.(!empty($pitemid) ? '&Itemid='.$pitemid : '')); ?>"><?php echo JText::translate('VBAVAILBOOKNOW'); ?></a> |
| 136 |
</div> |
| 137 |
<div class="vbo-availability-room-details-last-checkin" id="vbo-av-checkin-<?php echo $room['id']; ?>"><?php VikBookingIcons::e('sign-in', 'vbo-pref-color-element'); ?> <span></span></div> |
| 138 |
</div> |
| 139 |
</div> |
| 140 |
<div class="vbo-availability-room-monthcal table-responsive"> |
| 141 |
<table class="table" id="vbo-av-table-<?php echo $room['id']; ?>" data-room-table="<?php echo $room['id']; ?>"> |
| 142 |
<tr class="vbo-availability-room-monthdays"> |
| 143 |
<td class="vbo-availability-month-name vbo-pref-color-text" rowspan="2"><?php echo VikBooking::sayMonth($nowts['mon'])." ".$nowts['year']; ?></td> |
| 144 |
<?php |
| 145 |
$mon = $nowts['mon']; |
| 146 |
while ($nowts['mon'] == $mon) { |
| 147 |
?> |
| 148 |
<td class="vbo-availability-month-day"> |
| 149 |
<span class="vbo-availability-daynumber"><?php echo $nowts['mday']; ?></span> |
| 150 |
<span class="vbo-availability-weekday"><?php echo $days_labels[$nowts['wday']]; ?></span> |
| 151 |
</td> |
| 152 |
<?php |
| 153 |
$next = $nowts['mday'] + 1; |
| 154 |
$dayts = mktime(0, 0, 0, $nowts['mon'], $next, $nowts['year']); |
| 155 |
$nowts = getdate($dayts); |
| 156 |
} |
| 157 |
?> |
| 158 |
</tr> |
| 159 |
<tr class="vbo-availability-room-avdays"> |
| 160 |
<?php |
| 161 |
$nowts = getdate($tsstart); |
| 162 |
$mon = $nowts['mon']; |
| 163 |
while ($nowts['mon'] == $mon) { |
| 164 |
$dclass = "vbo-free-cell"; |
| 165 |
$is_checkin = false; |
| 166 |
$is_checkout = false; |
| 167 |
$dlnk = ""; |
| 168 |
$totfound = 0; |
| 169 |
if (array_key_exists($room['id'], $busy) && count($busy[$room['id']]) > 0) { |
| 170 |
foreach ($busy[$room['id']] as $b) { |
| 171 |
$info_in = getdate($b['checkin']); |
| 172 |
$checkin_ts = mktime(0, 0, 0, $info_in['mon'], $info_in['mday'], $info_in['year']); |
| 173 |
$info_out = getdate($b['checkout']); |
| 174 |
$checkout_ts = mktime(0, 0, 0, $info_out['mon'], $info_out['mday'], $info_out['year']); |
| 175 |
if ($nowts[0] >= $checkin_ts && $nowts[0] == $checkout_ts) { |
| 176 |
$is_checkout = true; |
| 177 |
} |
| 178 |
if ($nowts[0] >= $checkin_ts && $nowts[0] < $checkout_ts) { |
| 179 |
$totfound++; |
| 180 |
$dclass = "vbo-occupied-cell"; |
| 181 |
if ($nowts[0] == $checkin_ts) { |
| 182 |
$is_checkin = true; |
| 183 |
} |
| 184 |
} |
| 185 |
} |
| 186 |
} |
| 187 |
$useday = ($nowts['mday'] < 10 ? "0".$nowts['mday'] : $nowts['mday']); |
| 188 |
$dclass .= ($totfound < $room['units'] && $totfound > 0 ? ' vbo-partially-cell' : ''); |
| 189 |
|
| 190 |
// partially reserved days can be disabled from the configuration |
| 191 |
$dclass = !$showpartlyres && $totfound < $room['units'] && $totfound > 0 ? 'vbo-free-cell' : $dclass; |
| 192 |
if ($is_checkout && $room['units'] < 2 && !$inonout_allowed) { |
| 193 |
// in case check-in on check-out is disabled, add the occupied class for the check-out date |
| 194 |
$totfound = 1; |
| 195 |
$dclass = "vbo-occupied-cell"; |
| 196 |
} |
| 197 |
|
| 198 |
// check if the date is closed at property-level |
| 199 |
if (!$totfound && VikBooking::validateClosingDates($nowts[0], ($nowts[0] + 86399))) { |
| 200 |
// this date is closed at property-level |
| 201 |
$totfound = $room['units']; |
| 202 |
$dclass = "vbo-occupied-cell"; |
| 203 |
} |
| 204 |
|
| 205 |
$show_day_units = $totfound; |
| 206 |
if ($pshowtype == 1) { |
| 207 |
$show_day_units = ''; |
| 208 |
} elseif ($pshowtype == 2 && $totfound >= 1) { |
| 209 |
$show_day_units = ($room['units'] - $totfound); |
| 210 |
$show_day_units = $show_day_units < 0 ? 0 : $show_day_units; |
| 211 |
} elseif ($pshowtype == 3 && $totfound >= 1) { |
| 212 |
$show_day_units = $totfound; |
| 213 |
} |
| 214 |
if (!$showpartlyres && $totfound < $room['units'] && $totfound > 0) { |
| 215 |
$show_day_units = ''; |
| 216 |
} |
| 217 |
if ($totfound == 1) { |
| 218 |
$dclass .= $is_checkin === true ? ' vbo-checkinday-cell' : ''; |
| 219 |
$dclass .= $is_checkout === true ? ' vbo-checkoutday-cell' : ''; |
| 220 |
$dlnk = "<span class=\"vbo-availability-day-container\" data-units-booked=\"".$totfound."\" data-units-left=\"".($room['units'] - $totfound)."\">".$show_day_units."</span>"; |
| 221 |
} elseif ($totfound > 1) { |
| 222 |
$dlnk = "<span class=\"vbo-availability-day-container\" data-units-booked=\"".$totfound."\" data-units-left=\"".($room['units'] - $totfound)."\">".$show_day_units."</span>"; |
| 223 |
} |
| 224 |
?> |
| 225 |
<td class="<?php echo $dclass; ?>" data-cell-date="<?php echo date(str_replace("/", $datesep, $df), $nowts[0]); ?>" data-cell-ts="<?php echo $nowts[0]; ?>"><?php echo $dlnk; ?></td> |
| 226 |
<?php |
| 227 |
$next = $nowts['mday'] + 1; |
| 228 |
$dayts = mktime(0, 0, 0, $nowts['mon'], $next, $nowts['year']); |
| 229 |
$nowts = getdate($dayts); |
| 230 |
} |
| 231 |
?> |
| 232 |
</tr> |
| 233 |
</table> |
| 234 |
</div> |
| 235 |
</div> |
| 236 |
<?php |
| 237 |
} |
| 238 |
?> |
| 239 |
</div> |
| 240 |
|
| 241 |
<script type="text/javascript"> |
| 242 |
jQuery(function() { |
| 243 |
jQuery(".vbo-free-cell, .vbo-partially-cell").click(function() { |
| 244 |
var idroom = jQuery(this).closest("table").attr("data-room-table"); |
| 245 |
var celldate = jQuery(this).attr("data-cell-date"); |
| 246 |
var cellts = jQuery(this).attr("data-cell-ts"); |
| 247 |
if (idroom.length && celldate.length && cellts.length) { |
| 248 |
jQuery("#vbo-av-checkin-"+idroom).hide().find("span").text(""); |
| 249 |
if (jQuery("#vbo-av-btn-"+idroom).length) { |
| 250 |
var btnlink = jQuery("#vbo-av-btn-"+idroom).attr("href"); |
| 251 |
if (jQuery(this).hasClass("vbo-cell-selected-arrival")) { |
| 252 |
jQuery("#vbo-av-table-"+idroom).find("tr").find("td").removeClass("vbo-cell-selected-arrival"); |
| 253 |
jQuery("#vbo-av-checkin-"+idroom).fadeOut().find("span").text(celldate); |
| 254 |
btnlink = btnlink.replace(/(checkin=)[^\&]+/, '$1' + "-1"); |
| 255 |
} else { |
| 256 |
jQuery("#vbo-av-table-"+idroom).find("tr").find("td").removeClass("vbo-cell-selected-arrival"); |
| 257 |
jQuery(this).addClass("vbo-cell-selected-arrival"); |
| 258 |
jQuery("#vbo-av-checkin-"+idroom).fadeIn().find("span").text(celldate); |
| 259 |
btnlink = btnlink.replace(/(checkin=)[^\&]+/, '$1' + cellts); |
| 260 |
} |
| 261 |
jQuery("#vbo-av-btn-"+idroom).attr("href", btnlink); |
| 262 |
} |
| 263 |
} |
| 264 |
}); |
| 265 |
}); |
| 266 |
</script> |
| 267 |
|