| 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 |
jimport('joomla.application.component.view'); |
| 14 |
|
| 15 |
class VikbookingViewRoomdetails extends JViewVikBooking |
| 16 |
{ |
| 17 |
public function display($tpl = null) |
| 18 |
{ |
| 19 |
VikBooking::prepareViewContent(); |
| 20 |
$proomid = VikRequest::getString('roomid', '', 'request'); |
| 21 |
$dbo = JFactory::getDbo(); |
| 22 |
$vbo_tn = VikBooking::getTranslator(); |
| 23 |
$q = "SELECT * FROM `#__vikbooking_rooms` WHERE `id`=".$dbo->quote($proomid)." AND `avail`='1';"; |
| 24 |
$dbo->setQuery($q); |
| 25 |
$room = $dbo->loadAssocList(); |
| 26 |
if ($room) { |
| 27 |
$vbo_tn->translateContents($room, '#__vikbooking_rooms'); |
| 28 |
|
| 29 |
/** |
| 30 |
* We calculate the default timestamps for check-in of today and check-out for tomorrow. |
| 31 |
* Useful to apply the today's rate by default for one night of stay. |
| 32 |
* |
| 33 |
* @since 1.13.5 |
| 34 |
*/ |
| 35 |
$vbo_df = VikBooking::getDateFormat(); |
| 36 |
$vbo_df = $vbo_df == "%d/%m/%Y" ? 'd/m/Y' : ($vbo_df == "%m/%d/%Y" ? 'm/d/Y' : 'Y/m/d'); |
| 37 |
$hcheckin = 0; |
| 38 |
$mcheckin = 0; |
| 39 |
$hcheckout = 0; |
| 40 |
$mcheckout = 0; |
| 41 |
$timeopst = VikBooking::getTimeOpenStore(); |
| 42 |
if (is_array($timeopst)) { |
| 43 |
$opent = VikBooking::getHoursMinutes($timeopst[0]); |
| 44 |
$closet = VikBooking::getHoursMinutes($timeopst[1]); |
| 45 |
$hcheckin = $opent[0]; |
| 46 |
$mcheckin = $opent[1]; |
| 47 |
$hcheckout = $closet[0]; |
| 48 |
$mcheckout = $closet[1]; |
| 49 |
} |
| 50 |
$checkin_today_ts = VikBooking::getDateTimestamp(date($vbo_df), $hcheckin, $mcheckin); |
| 51 |
$checkout_tomorrow_ts = VikBooking::getDateTimestamp(date($vbo_df, strtotime('tomorrow')), $hcheckout, $mcheckout); |
| 52 |
// |
| 53 |
$room[0]['base_cost'] = 0; |
| 54 |
$room[0]['cost'] = 0; |
| 55 |
$q = "SELECT * FROM `#__vikbooking_dispcost` WHERE `idroom`=".$dbo->quote($room[0]['id'])." ORDER BY `#__vikbooking_dispcost`.`days` ASC, `#__vikbooking_dispcost`.`cost` ASC"; |
| 56 |
$dbo->setQuery($q, 0, 1); |
| 57 |
$tar = $dbo->loadAssocList(); |
| 58 |
if ($tar) { |
| 59 |
$room[0]['base_cost'] = $tar[0]['cost'] / ($tar[0]['days'] > 1 ? $tar[0]['days'] : 1); |
| 60 |
/** |
| 61 |
* We apply the today's rate by default for one night of stay. |
| 62 |
* |
| 63 |
* @since 1.13.5 |
| 64 |
*/ |
| 65 |
$tar = VikBooking::applySeasonsRoom($tar, $checkin_today_ts, $checkout_tomorrow_ts); |
| 66 |
// |
| 67 |
$room[0]['cost'] = $tar[0]['cost'] / ($tar[0]['days'] > 1 ? $tar[0]['days'] : 1); |
| 68 |
} |
| 69 |
// |
| 70 |
|
| 71 |
$actnow = mktime(0, 0, 0, date('m'), 1, date('Y')); |
| 72 |
|
| 73 |
$q = "SELECT * FROM `#__vikbooking_busy` WHERE `idroom`='".$room[0]['id']."' AND (`checkin`>=".$actnow." OR `checkout`>=".$actnow.");"; |
| 74 |
$dbo->setQuery($q); |
| 75 |
$busy = $dbo->loadAssocList(); |
| 76 |
|
| 77 |
//seasons calendar |
| 78 |
$seasons_cal = array(); |
| 79 |
$use_seasons_cal = VikBooking::getRoomParam('seasoncal', $room[0]['params']); |
| 80 |
$seasons_cal_nights = explode(',', VikBooking::getRoomParam('seasoncal_nights', $room[0]['params'])); |
| 81 |
$seasons_cal_nights = VikBooking::filterNightsSeasonsCal($seasons_cal_nights); |
| 82 |
if (intval($use_seasons_cal) > 0 && count($seasons_cal_nights) > 0) { |
| 83 |
$q = "SELECT * FROM `#__vikbooking_seasons` WHERE `idrooms` LIKE '%-".$room[0]['id']."-%'".($use_seasons_cal == 2 ? " AND `promo`=0" : ($use_seasons_cal == 3 ? " AND `type`=1 AND `promo`=0" : "")).";"; |
| 84 |
$dbo->setQuery($q); |
| 85 |
$seasons = $dbo->loadAssocList(); |
| 86 |
if ($seasons) { |
| 87 |
$vbo_tn->translateContents($seasons, '#__vikbooking_seasons'); |
| 88 |
$q = "SELECT `p`.*,`tp`.`name`,`tp`.`attr`,`tp`.`idiva`,`tp`.`breakfast_included`,`tp`.`free_cancellation`,`tp`.`canc_deadline` FROM `#__vikbooking_dispcost` AS `p` LEFT JOIN `#__vikbooking_prices` `tp` ON `p`.`idprice`=`tp`.`id` WHERE `p`.`days` IN (".implode(',', $seasons_cal_nights).") AND `p`.`idroom`=".$room[0]['id']." ORDER BY `p`.`days` ASC, `p`.`cost` ASC;"; |
| 89 |
$dbo->setQuery($q); |
| 90 |
$tars = $dbo->loadAssocList(); |
| 91 |
if ($tars) { |
| 92 |
$vbo_tn->translateContents($tars, '#__vikbooking_prices', array('id' => 'idprice')); |
| 93 |
$arrtar = array(); |
| 94 |
foreach ($tars as $tar) { |
| 95 |
$arrtar[$tar['days']][] = $tar; |
| 96 |
} |
| 97 |
//Restrictions |
| 98 |
$all_restrictions = VikBooking::loadRestrictions(true, array($room[0]['id'])); |
| 99 |
$all_seasons = array(); |
| 100 |
$curtime = time(); |
| 101 |
foreach ($seasons as $sk => $s) { |
| 102 |
if (empty($s['from']) && empty($s['to'])) { |
| 103 |
continue; |
| 104 |
} |
| 105 |
$now_year = !empty($s['year']) ? $s['year'] : date('Y'); |
| 106 |
list($sfrom, $sto) = VikBooking::getSeasonRangeTs($s['from'], $s['to'], $now_year); |
| 107 |
if ($sto < $curtime && empty($s['year'])) { |
| 108 |
$now_year += 1; |
| 109 |
list($sfrom, $sto) = VikBooking::getSeasonRangeTs($s['from'], $s['to'], $now_year); |
| 110 |
} |
| 111 |
if ($sto >= $curtime) { |
| 112 |
$s['from_ts'] = $sfrom; |
| 113 |
$s['to_ts'] = $sto; |
| 114 |
$all_seasons[] = $s; |
| 115 |
} |
| 116 |
} |
| 117 |
if (count($all_seasons) > 0) { |
| 118 |
$seasons_cal['nights'] = $seasons_cal_nights; |
| 119 |
$seasons_cal['offseason'] = $arrtar; |
| 120 |
$all_seasons = VikBooking::sortSeasonsRangeTs($all_seasons); |
| 121 |
$seasons_cal['seasons'] = $all_seasons; |
| 122 |
$seasons_cal['season_prices'] = array(); |
| 123 |
$seasons_cal['restrictions'] = array(); |
| 124 |
//calc price changes for each season and for each num-night |
| 125 |
foreach ($all_seasons as $sk => $s) { |
| 126 |
$checkin_base_ts = $s['from_ts']; |
| 127 |
$is_dst = date('I', $checkin_base_ts); |
| 128 |
foreach ($arrtar as $numnights => $tar) { |
| 129 |
$checkout_base_ts = $s['to_ts']; |
| 130 |
for ($i = 1; $i <= $numnights; $i++) { |
| 131 |
$checkout_base_ts += 86400; |
| 132 |
$is_now_dst = date('I', $checkout_base_ts); |
| 133 |
if ($is_dst != $is_now_dst) { |
| 134 |
if ((int)$is_dst == 1) { |
| 135 |
$checkout_base_ts += 3600; |
| 136 |
} else { |
| 137 |
$checkout_base_ts -= 3600; |
| 138 |
} |
| 139 |
$is_dst = $is_now_dst; |
| 140 |
} |
| 141 |
} |
| 142 |
//calc check-in and check-out ts for the two dates |
| 143 |
$first = VikBooking::getDateTimestamp(date($vbo_df, $checkin_base_ts), $hcheckin, $mcheckin); |
| 144 |
$second = VikBooking::getDateTimestamp(date($vbo_df, $checkout_base_ts), $hcheckout, $mcheckout); |
| 145 |
$tar = VikBooking::applySeasonsRoom($tar, $first, $second, $s); |
| 146 |
$seasons_cal['season_prices'][$sk][$numnights] = $tar; |
| 147 |
//Restrictions |
| 148 |
if (count($all_restrictions) > 0) { |
| 149 |
$season_restr = VikBooking::parseSeasonRestrictions($first, $second, $numnights, $all_restrictions); |
| 150 |
if (count($season_restr) > 0) { |
| 151 |
$seasons_cal['restrictions'][$sk][$numnights] = $season_restr; |
| 152 |
} |
| 153 |
} |
| 154 |
} |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
} |
| 159 |
} |
| 160 |
//end seasons calendar |
| 161 |
//promotion min number of nights |
| 162 |
$ppromo = VikRequest::getInt('promo', 0, 'request'); |
| 163 |
$promo_season = []; |
| 164 |
if ($ppromo > 0) { |
| 165 |
$q = "SELECT * FROM `#__vikbooking_seasons` WHERE `id`=".(int)$ppromo." AND `promo`=1;"; |
| 166 |
$dbo->setQuery($q); |
| 167 |
$promo_season = (array) $dbo->loadAssoc(); |
| 168 |
if ($promo_season) { |
| 169 |
$vbo_tn->translateContents($promo_season, '#__vikbooking_seasons'); |
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
// attempt to load the first two "mandatory" checkbox fields |
| 174 |
$q = "SELECT * FROM `#__vikbooking_custfields` WHERE `type`='checkbox' AND `required`=1 ORDER BY `#__vikbooking_custfields`.`ordering` ASC"; |
| 175 |
$dbo->setQuery($q, 0, 2); |
| 176 |
$terms_fields = $dbo->loadAssocList(); |
| 177 |
if ($terms_fields) { |
| 178 |
$vbo_tn->translateContents($terms_fields, '#__vikbooking_custfields'); |
| 179 |
} |
| 180 |
|
| 181 |
$custptitle = VikBooking::getRoomParam('custptitle', $room[0]['params']); |
| 182 |
$custptitlew = VikBooking::getRoomParam('custptitlew', $room[0]['params']); |
| 183 |
$metakeywords = VikBooking::getRoomParam('metakeywords', $room[0]['params']); |
| 184 |
$metadescription = VikBooking::getRoomParam('metadescription', $room[0]['params']); |
| 185 |
$document = JFactory::getDocument(); |
| 186 |
if (!empty($custptitle)) { |
| 187 |
$ctitlewhere = !empty($custptitlew) ? $custptitlew : 'before'; |
| 188 |
$set_title = $custptitle.' - '.$document->getTitle(); |
| 189 |
if ($ctitlewhere == 'after') { |
| 190 |
$set_title = $document->getTitle().' - '.$custptitle; |
| 191 |
} elseif ($ctitlewhere == 'replace') { |
| 192 |
$set_title = $custptitle; |
| 193 |
} |
| 194 |
$document->setTitle($set_title); |
| 195 |
} |
| 196 |
if (!empty($metakeywords)) { |
| 197 |
$document->setMetaData('keywords', $metakeywords); |
| 198 |
} |
| 199 |
if (!empty($metadescription)) { |
| 200 |
$document->setMetaData('description', $metadescription); |
| 201 |
} |
| 202 |
//OpenGraph Tags |
| 203 |
if (!empty($custptitle)) { |
| 204 |
$document->setMetaData('og:title', $set_title); |
| 205 |
} |
| 206 |
if (!empty($room[0]['img'])) { |
| 207 |
$document->setMetaData('og:image', VBO_SITE_URI.'resources/uploads/'.$room[0]['img']); |
| 208 |
} |
| 209 |
if (!empty($room[0]['smalldesc'])) { |
| 210 |
$document->setMetaData('og:description', strip_tags($room[0]['smalldesc'])); |
| 211 |
} |
| 212 |
// |
| 213 |
$this->room = $room[0]; |
| 214 |
$this->busy = $busy; |
| 215 |
$this->seasons_cal = $seasons_cal; |
| 216 |
$this->promo_season = $promo_season; |
| 217 |
$this->terms_fields = $terms_fields; |
| 218 |
$this->vbo_tn = $vbo_tn; |
| 219 |
//theme |
| 220 |
$theme = VikBooking::getTheme(); |
| 221 |
if ($theme != 'default') { |
| 222 |
$thdir = VBO_SITE_PATH.DS.'themes'.DS.$theme.DS.'roomdetails'; |
| 223 |
if (is_dir($thdir)) { |
| 224 |
$this->_setPath('template', $thdir.DS); |
| 225 |
} |
| 226 |
} |
| 227 |
// |
| 228 |
parent::display($tpl); |
| 229 |
} else { |
| 230 |
$mainframe = JFactory::getApplication(); |
| 231 |
$mainframe->redirect("index.php?option=com_vikbooking&view=roomslist"); |
| 232 |
} |
| 233 |
} |
| 234 |
} |
| 235 |
|