| 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 admin widget "today rooms occupancy". |
| 15 |
* |
| 16 |
* @since 1.4.0 |
| 17 |
*/ |
| 18 |
class VikBookingAdminWidgetTodayRoomsOccupancy extends VikBookingAdminWidget |
| 19 |
{ |
| 20 |
/** |
| 21 |
* Class constructor will define the widget name and identifier. |
| 22 |
*/ |
| 23 |
public function __construct() |
| 24 |
{ |
| 25 |
// call parent constructor |
| 26 |
parent::__construct(); |
| 27 |
|
| 28 |
$this->widgetName = JText::translate('VBDASHTODROCC'); |
| 29 |
$this->widgetDescr = JText::translate('VBO_W_TODROCC_DESCR'); |
| 30 |
$this->widgetId = basename(__FILE__, '.php'); |
| 31 |
|
| 32 |
/** |
| 33 |
* Define widget and icon and style name. |
| 34 |
* |
| 35 |
* @since 1.15.0 (J) - 1.5.0 (WP) |
| 36 |
*/ |
| 37 |
$this->widgetIcon = '<i class="' . VikBookingIcons::i('users') . '"></i>'; |
| 38 |
$this->widgetStyleName = 'green'; |
| 39 |
} |
| 40 |
|
| 41 |
public function render(VBOMultitaskData $data = null) |
| 42 |
{ |
| 43 |
$vbo_auth_bookings = JFactory::getUser()->authorise('core.vbo.bookings', 'com_vikbooking'); |
| 44 |
$busy = VikBooking::getAdminWidgetsInstance()->loadBusyRecordsUnclosed(); |
| 45 |
$info_rooms = array( |
| 46 |
'unpublished_rooms' => VikBooking::getAdminWidgetsInstance()->getRoomsData('unpublished_rooms'), |
| 47 |
'tot_rooms_units' => VikBooking::getAdminWidgetsInstance()->getRoomsData('tot_rooms_units'), |
| 48 |
'all_rooms_ids' => VikBooking::getAdminWidgetsInstance()->getRoomsData('all_rooms_ids'), |
| 49 |
'all_rooms_units' => VikBooking::getAdminWidgetsInstance()->getRoomsData('all_rooms_units'), |
| 50 |
'all_rooms_features' => VikBooking::getAdminWidgetsInstance()->getRoomsData('all_rooms_features'), |
| 51 |
); |
| 52 |
$today_tot_occupancy = 0; |
| 53 |
$today_end_ts = mktime(23, 59, 59, date("n"), date("j"), date("Y")); |
| 54 |
$today_info = getdate($today_end_ts); |
| 55 |
$tot_booked_today = 0; |
| 56 |
if (count($busy)) { |
| 57 |
foreach ($busy as $idroom => $rbusy) { |
| 58 |
if (in_array($idroom, $info_rooms['unpublished_rooms'])) { |
| 59 |
continue; |
| 60 |
} |
| 61 |
foreach ($rbusy as $b) { |
| 62 |
$tmpone = getdate($b['checkin']); |
| 63 |
$ritts = mktime(0, 0, 0, $tmpone['mon'], $tmpone['mday'], $tmpone['year']); |
| 64 |
$tmptwo = getdate($b['checkout']); |
| 65 |
$conts = mktime(0, 0, 0, $tmptwo['mon'], $tmptwo['mday'], $tmptwo['year']); |
| 66 |
if ($today_end_ts >= $ritts && $today_end_ts < $conts) { |
| 67 |
$tot_booked_today++; |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
$today_tot_occupancy = $tot_booked_today; |
| 73 |
if ($today_tot_occupancy <= 0) { |
| 74 |
// no contents to be displayed |
| 75 |
return; |
| 76 |
} |
| 77 |
|
| 78 |
// render the necessary PHP/JS code for the modal window only once |
| 79 |
if (!defined('VBO_JMODAL_CHECKIN_BOOKING')) { |
| 80 |
define('VBO_JMODAL_CHECKIN_BOOKING', 1); |
| 81 |
?> |
| 82 |
<script type="text/javascript"> |
| 83 |
function vboJModalShowCallback() { |
| 84 |
if (typeof vbo_t_on == "undefined") { |
| 85 |
return; |
| 86 |
} |
| 87 |
// simulate STOP click |
| 88 |
if (vbo_t_on) { |
| 89 |
vbo_t_on = false; |
| 90 |
clearTimeout(vbo_t); |
| 91 |
jQuery(".vbo-dashboard-refresh-play").fadeIn(); |
| 92 |
} |
| 93 |
} |
| 94 |
function vboJModalHideCallback() { |
| 95 |
if (typeof vbo_t_on == "undefined") { |
| 96 |
return; |
| 97 |
} |
| 98 |
// simulate PLAY click |
| 99 |
if (!vbo_t_on) { |
| 100 |
vboStartTimer(); |
| 101 |
jQuery(".vbo-dashboard-refresh-play").fadeOut(); |
| 102 |
} |
| 103 |
} |
| 104 |
</script> |
| 105 |
<?php |
| 106 |
echo $this->vbo_app->getJmodalScript('', 'vboJModalHideCallback();', 'vboJModalShowCallback();'); |
| 107 |
echo $this->vbo_app->getJmodalHtml('vbo-checkin-booking', JText::translate('VBOMANAGECHECKSINOUT')); |
| 108 |
} |
| 109 |
// |
| 110 |
|
| 111 |
$today_rbookmap = array(); |
| 112 |
$today_bidbookmap = array(); |
| 113 |
foreach ($busy as $idroom => $rbusy) { |
| 114 |
foreach ($rbusy as $b) { |
| 115 |
$tmpone = getdate($b['checkin']); |
| 116 |
$ritts = mktime(0, 0, 0, $tmpone['mon'], $tmpone['mday'], $tmpone['year']); |
| 117 |
$tmptwo = getdate($b['checkout']); |
| 118 |
$conts = mktime(0, 0, 0, $tmptwo['mon'], $tmptwo['mday'], $tmptwo['year']); |
| 119 |
if ($today_end_ts >= $ritts && $today_end_ts < $conts) { |
| 120 |
if (isset($today_rbookmap[$b['idroom']])) { |
| 121 |
$today_rbookmap[$b['idroom']]++; |
| 122 |
$today_bidbookmap[$b['idroom']][] = $b['id']; |
| 123 |
} else { |
| 124 |
$today_rbookmap[$b['idroom']] = 1; |
| 125 |
$today_bidbookmap[$b['idroom']] = array($b['id']); |
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
} |
| 130 |
?> |
| 131 |
<div class="vbo-admin-widget-wrapper"> |
| 132 |
<div class="vbo-admin-widget-head vbo-dashboard-today-occ-head"> |
| 133 |
<h4><?php echo $this->widgetIcon; ?> <span><?php echo $this->widgetName; ?></span></h4> |
| 134 |
<div class="btn-toolbar pull-right vbo-dashboard-search-today-occ"> |
| 135 |
<div class="btn-wrapper input-append"> |
| 136 |
<input type="text" class="today-search form-control" placeholder="<?php echo JText::translate('VBODASHSEARCHKEYS'); ?>"> |
| 137 |
<button type="button" class="btn" onclick="jQuery('.today-search').val('').trigger('keyup');"><i class="icon-remove"></i></button> |
| 138 |
</div> |
| 139 |
</div> |
| 140 |
</div> |
| 141 |
<div class="vbo-dashboard-today-occ-listcont"> |
| 142 |
<?php |
| 143 |
foreach ($today_rbookmap as $idr => $rbked) { |
| 144 |
$room_bookings_det = VikBooking::getRoomBookingsFromBusyIds($idr, $today_bidbookmap[$idr]); |
| 145 |
if ((count($room_bookings_det) == 1 && $room_bookings_det[0]['closure'] == 1) || !count($room_bookings_det)) { |
| 146 |
// skip rooms with just a closure, or with no real bookings (shared calendars) |
| 147 |
continue; |
| 148 |
} |
| 149 |
// calculate color for percentage of occupancy |
| 150 |
$tot_rooms_units = $info_rooms['all_rooms_units'][$idr]; |
| 151 |
$tot_rooms_units = $tot_rooms_units < 1 ? 1 : $tot_rooms_units; |
| 152 |
$percentage_booked = round((100 * $rbked / $tot_rooms_units), 2); |
| 153 |
$occupancy_cls = 'vbo-roomocc-units-free'; |
| 154 |
if ($percentage_booked > 33 && $percentage_booked <= 66) { |
| 155 |
$occupancy_cls = 'vbo-roomocc-units-half'; |
| 156 |
} elseif ($percentage_booked > 66 && $percentage_booked < 100) { |
| 157 |
$occupancy_cls = 'vbo-roomocc-units-threefourth'; |
| 158 |
} elseif ($percentage_booked >= 100) { |
| 159 |
$occupancy_cls = 'vbo-roomocc-units-full'; |
| 160 |
} |
| 161 |
?> |
| 162 |
<div class="vbo-dashboard-today-roomocc"> |
| 163 |
<div class="vbo-dashboard-today-roomocc-det"> |
| 164 |
<h5> |
| 165 |
<span class="vbo-dashboard-today-roomocc-det-rname"><?php echo $info_rooms['all_rooms_ids'][$idr]; ?></span> |
| 166 |
<span class="vbo-dashboard-roomocc-units-fromto <?php echo $occupancy_cls; ?>"> |
| 167 |
<span class="vbo-dashboard-roomocc-units-from"><?php echo $rbked; ?></span> / <span><?php echo $info_rooms['all_rooms_units'][$idr]; ?></span> |
| 168 |
</span> |
| 169 |
</h5> |
| 170 |
<div class="vbo-dashboard-today-roomocc-customers table-responsive"> |
| 171 |
<table class="table vbo-table-search-today"> |
| 172 |
<thead> |
| 173 |
<tr class="vbo-dashboard-today-roomocc-firstrow"> |
| 174 |
<th class="left"><?php echo JText::translate('VBCUSTOMERNOMINATIVE'); ?></th> |
| 175 |
<th class="center"> </th> |
| 176 |
<th class="right"><?php echo JText::translate('VBDASHUPRESFOUR'); ?></th> |
| 177 |
</tr> |
| 178 |
<tr class="warning no-results"> |
| 179 |
<td colspan="7"><i class="vboicn-warning"></i> <?php echo JText::translate('VBONORESULTS'); ?></td> |
| 180 |
</tr> |
| 181 |
</thead> |
| 182 |
<tbody> |
| 183 |
<?php |
| 184 |
foreach ($room_bookings_det as $rbind => $room_booking) { |
| 185 |
$nominative = strlen($room_booking['nominative']) > 1 ? $room_booking['nominative'] : VikBooking::getFirstCustDataField($room_booking['custdata']); |
| 186 |
$country_flag = ''; |
| 187 |
if (file_exists(VBO_ADMIN_PATH.DS.'resources'.DS.'countries'.DS.$room_booking['country'].'.png')) { |
| 188 |
$country_flag = '<img src="'.VBO_ADMIN_URI.'resources/countries/'.$room_booking['country'].'.png'.'" title="'.$room_booking['country'].'" class="vbo-country-flag vbo-country-flag-left"/>'; |
| 189 |
} |
| 190 |
//Room specific unit |
| 191 |
$room_first_feature = ' '; |
| 192 |
if (!empty($room_booking['roomindex']) && array_key_exists($idr, $info_rooms['all_rooms_features']) && count($info_rooms['all_rooms_features'][$idr]) > 0) { |
| 193 |
foreach ($info_rooms['all_rooms_features'][$idr] as $rind => $rfeatures) { |
| 194 |
if ($rind != $room_booking['roomindex']) { |
| 195 |
continue; |
| 196 |
} |
| 197 |
foreach ($rfeatures as $fname => $fval) { |
| 198 |
if (strlen($fval)) { |
| 199 |
$room_first_feature = '#'.$rind.' - '.JText::translate($fname).': '.$fval; |
| 200 |
break 2; |
| 201 |
} |
| 202 |
} |
| 203 |
} |
| 204 |
} |
| 205 |
// |
| 206 |
$act_status = ''; |
| 207 |
if ($vbo_auth_bookings && $room_booking['closure'] != 1 && $room_booking['checked'] != 0) { |
| 208 |
$act_status = '<button type="button" class="btn btn-small btn-primary pull-right pro-feature" onclick="vboOpenJModal(\'vbo-checkin-booking\', \'index.php?option=com_vikbooking&task=bookingcheckin&cid[]='.$room_booking['idorder'].'&tmpl=component\');"><i class="vboicn-users icn-nomargin"></i></button>'; |
| 209 |
} |
| 210 |
?> |
| 211 |
<tr class="vbo-dashboard-today-roomocc-rows"> |
| 212 |
<td class="searchable left"><?php echo $country_flag.'<a href="index.php?option=com_vikbooking&task=editorder&cid[]='.$room_booking['idorder'].'" target="_blank">'.$nominative.'</a>'; ?></td> |
| 213 |
<td class="searchable center"><?php echo $room_first_feature; ?></td> |
| 214 |
<td class="searchable right"> |
| 215 |
<div class="vbo-dashboard-today-roomocc-row-checkout"> |
| 216 |
<span class="vbo-dashboard-today-roomocc-checkout-dt"><?php echo date(str_replace("/", $this->datesep, $this->df).' H:i', $room_booking['checkout']); ?></span> |
| 217 |
<?php |
| 218 |
if (!empty($act_status)) { |
| 219 |
?> |
| 220 |
<span class="vbo-dashboard-today-roomocc-checkout-do"><?php echo $act_status; ?></span> |
| 221 |
<?php |
| 222 |
} |
| 223 |
?> |
| 224 |
</div> |
| 225 |
</td> |
| 226 |
</tr> |
| 227 |
<?php |
| 228 |
} |
| 229 |
?> |
| 230 |
</tbody> |
| 231 |
</table> |
| 232 |
</div> |
| 233 |
</div> |
| 234 |
</div> |
| 235 |
<?php |
| 236 |
} |
| 237 |
?> |
| 238 |
</div> |
| 239 |
</div> |
| 240 |
|
| 241 |
<script type="text/javascript"> |
| 242 |
jQuery(function() { |
| 243 |
/* Attempt to append the modal container to the body for the multitask panel */ |
| 244 |
let modal_container = jQuery('[id*="vbo-checkin-booking"][class*="modal"]'); |
| 245 |
if (modal_container.length) { |
| 246 |
modal_container.first().appendTo('body'); |
| 247 |
} |
| 248 |
|
| 249 |
/* Today Search */ |
| 250 |
jQuery(".today-search").keyup(function () { |
| 251 |
var inp_elem = jQuery(this); |
| 252 |
var instance_elem = inp_elem.closest('.vbo-admin-widget-wrapper'); |
| 253 |
var searchTerm = inp_elem.val(); |
| 254 |
var searchSplit = searchTerm.replace(/ /g, "'):containsi('"); |
| 255 |
jQuery.extend(jQuery.expr[':'], {'containsi': |
| 256 |
function(elem, i, match, array) { |
| 257 |
return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0; |
| 258 |
} |
| 259 |
}); |
| 260 |
instance_elem.find(".vbo-table-search-today tbody tr td.searchable").not(":containsi('" + searchSplit + "')").each(function(e) { |
| 261 |
jQuery(this).parent('tr').attr('visible', 'false'); |
| 262 |
}); |
| 263 |
instance_elem.find(".vbo-table-search-today tbody tr td.searchable:containsi('" + searchSplit + "')").each(function(e) { |
| 264 |
jQuery(this).parent('tr').attr('visible', 'true'); |
| 265 |
}); |
| 266 |
instance_elem.find('.vbo-table-search-today').each(function(k, v) { |
| 267 |
var jobCount = parseInt(jQuery(this).find('tbody tr[visible="true"]').length); |
| 268 |
if (jobCount > 0) { |
| 269 |
jQuery(this).find('.no-results').hide(); |
| 270 |
} else { |
| 271 |
jQuery(this).find('.no-results').show(); |
| 272 |
} |
| 273 |
}); |
| 274 |
}); |
| 275 |
}); |
| 276 |
</script> |
| 277 |
<?php |
| 278 |
} |
| 279 |
} |
| 280 |
|