| 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 VikbookingViewTableaux extends JViewVikBooking |
| 16 |
{ |
| 17 |
public function display($tpl = null) |
| 18 |
{ |
| 19 |
// set noindex instruction for robots |
| 20 |
$document = JFactory::getDocument(); |
| 21 |
$document->setMetaData('robots', 'noindex, nofollow'); |
| 22 |
|
| 23 |
$app = JFactory::getApplication(); |
| 24 |
$dbo = JFactory::getDbo(); |
| 25 |
$opobj = VikBooking::getOperatorInstance(); |
| 26 |
|
| 27 |
$operator = $opobj->getOperatorAccount(); |
| 28 |
if ($operator === false) { |
| 29 |
// operator needs to log in |
| 30 |
$pitemid = VikRequest::getInt('Itemid', '', 'request'); |
| 31 |
$app->redirect(JRoute::rewrite('index.php?option=com_vikbooking&view=operators'.(!empty($pitemid) ? '&Itemid='.$pitemid : ''), false)); |
| 32 |
exit; |
| 33 |
} |
| 34 |
|
| 35 |
// check permissions for tableaux |
| 36 |
if (!$opobj->checkPermissions($operator, 'tableaux')) { |
| 37 |
// operator is not authorized |
| 38 |
VikError::raiseWarning('', JText::translate('VBONOTAUTHORIZEDRES')); |
| 39 |
$pitemid = VikRequest::getInt('Itemid', '', 'request'); |
| 40 |
$app->redirect(JRoute::rewrite('index.php?option=com_vikbooking&view=operators'.(!empty($pitemid) ? '&Itemid='.$pitemid : ''), false)); |
| 41 |
exit; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* We allow the "visible days" setting to be negative. In this case |
| 46 |
* we double it to get the number of past and future visible days. |
| 47 |
* |
| 48 |
* @since 1.16.9 (J) - 1.6.9 (WP) |
| 49 |
*/ |
| 50 |
$past_days = 0; |
| 51 |
$visible_days = $operator['perms']['days'] ?: 0; |
| 52 |
if ($visible_days < 0) { |
| 53 |
$visible_days = $visible_days + (abs($visible_days) * 2); |
| 54 |
$past_days = $visible_days; |
| 55 |
} |
| 56 |
|
| 57 |
// prepare tableaux data |
| 58 |
$tsinfo = getdate(); |
| 59 |
$fromts = mktime(0, 0, 0, $tsinfo['mon'], ($tsinfo['mday'] - $past_days), $tsinfo['year']); |
| 60 |
$tots = mktime(23, 59, 59, $tsinfo['mon'], ($tsinfo['mday'] + $visible_days), $tsinfo['year']); |
| 61 |
|
| 62 |
$roomids = array_filter((array) ($operator['perms']['rooms'] ?? [])); |
| 63 |
|
| 64 |
// get all rooms enabled for the operator |
| 65 |
$rooms = []; |
| 66 |
$q = "SELECT `id`,`name`,`units`,`params` FROM `#__vikbooking_rooms`" . ($roomids ? " WHERE `id` IN (" . implode(', ', array_map('intval', $roomids)) . ")" : "") . " ORDER BY `name` ASC;"; |
| 67 |
$dbo->setQuery($q); |
| 68 |
$all = $dbo->loadAssocList(); |
| 69 |
foreach ($all as $r) { |
| 70 |
$rooms[$r['id']] = $r; |
| 71 |
} |
| 72 |
|
| 73 |
if (!$rooms) { |
| 74 |
VikError::raiseWarning('', JText::translate('VBONOTAUTHORIZEDRES').' (#2)'); |
| 75 |
$pitemid = VikRequest::getInt('Itemid', '', 'request'); |
| 76 |
$app->redirect(JRoute::rewrite('index.php?option=com_vikbooking&view=operators'.(!empty($pitemid) ? '&Itemid='.$pitemid : ''), false)); |
| 77 |
exit; |
| 78 |
} |
| 79 |
|
| 80 |
// get all occupied dates for these rooms |
| 81 |
$rooms_busy = []; |
| 82 |
$q = "SELECT `b`.*,`ob`.`idorder`,`o`.`custdata`,`o`.`status`,`o`.`country`,`o`.`phone`,`oc`.`idcustomer`,`c`.`first_name`,`c`.`last_name`, |
| 83 |
(SELECT GROUP_CONCAT(`or`.`roomindex` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `indexes`, |
| 84 |
(SELECT GROUP_CONCAT(`or`.`adults` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `adults`, |
| 85 |
(SELECT GROUP_CONCAT(`or`.`children` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `children`, |
| 86 |
(SELECT GROUP_CONCAT(`or`.`pets` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `pets`, |
| 87 |
(SELECT GROUP_CONCAT(`or`.`t_first_name` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `tnames`, |
| 88 |
(SELECT GROUP_CONCAT(`or`.`t_last_name` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `tlnames`, |
| 89 |
(SELECT GROUP_CONCAT(`or`.`optionals` SEPARATOR '__') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `roptions`, |
| 90 |
(SELECT GROUP_CONCAT(`or`.`extracosts` SEPARATOR '__') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `rextras`, |
| 91 |
(SELECT GROUP_CONCAT(`or`.`idtar` SEPARATOR '__') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `ridtars`, |
| 92 |
(SELECT GROUP_CONCAT(`or`.`otarplan` SEPARATOR '__') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `rotarplans` |
| 93 |
FROM `#__vikbooking_busy` AS `b` |
| 94 |
LEFT JOIN `#__vikbooking_ordersbusy` AS `ob` ON `b`.`id`=`ob`.`idbusy` |
| 95 |
LEFT JOIN `#__vikbooking_orders` AS `o` ON `ob`.`idorder`=`o`.`id` |
| 96 |
LEFT JOIN `#__vikbooking_customers_orders` AS `oc` ON `ob`.`idorder`=`oc`.`idorder` |
| 97 |
LEFT JOIN `#__vikbooking_customers` AS `c` ON `oc`.`idcustomer`=`c`.`id` |
| 98 |
WHERE `b`.`idroom` IN (" . implode(', ', array_keys($rooms)) . ") AND (`b`.`checkin`>=" . $fromts . " OR `b`.`checkout`>=" . $fromts . ") AND (`b`.`checkin`<=" . $tots . " OR `b`.`checkout`<=" . $fromts . ") AND `o`.`status`='confirmed' AND `o`.`closure`=0 |
| 99 |
ORDER BY `b`.`checkin` ASC, `ob`.`idorder` ASC;"; |
| 100 |
$dbo->setQuery($q); |
| 101 |
$busy = $dbo->loadAssocList(); |
| 102 |
|
| 103 |
foreach ($busy as $b) { |
| 104 |
if (!isset($rooms_busy[$b['idroom']])) { |
| 105 |
$rooms_busy[$b['idroom']] = []; |
| 106 |
} |
| 107 |
array_push($rooms_busy[$b['idroom']], $b); |
| 108 |
} |
| 109 |
|
| 110 |
/** |
| 111 |
* Check the next festivities periodically |
| 112 |
* |
| 113 |
* @since 1.13.5 |
| 114 |
*/ |
| 115 |
$fests = VikBooking::getFestivitiesInstance(); |
| 116 |
if ($fests->shouldCheckFestivities()) { |
| 117 |
$fests->storeNextFestivities(); |
| 118 |
} |
| 119 |
$festivities = $fests->loadFestDates(date('Y-m-d', $fromts), date('Y-m-d', $tots)); |
| 120 |
|
| 121 |
/** |
| 122 |
* Load room day notes from first month |
| 123 |
* |
| 124 |
* @since 1.13.5 |
| 125 |
*/ |
| 126 |
$rdaynotes = VikBooking::getCriticalDatesInstance()->loadRoomDayNotes(date('Y-m-d', $fromts), date('Y-m-d', $tots)); |
| 127 |
|
| 128 |
// load all options |
| 129 |
$all_options = []; |
| 130 |
$q = "SELECT * FROM `#__vikbooking_optionals` WHERE `forcesel`=0 AND `is_citytax`=0 AND `is_fee`=0;"; |
| 131 |
$dbo->setQuery($q); |
| 132 |
$records = $dbo->loadAssocList(); |
| 133 |
|
| 134 |
foreach ($records as $opt) { |
| 135 |
$all_options[$opt['id']] = $opt; |
| 136 |
} |
| 137 |
|
| 138 |
$this->operator = $operator; |
| 139 |
$this->rooms = $rooms; |
| 140 |
$this->rooms_busy = $rooms_busy; |
| 141 |
$this->fromts = $fromts; |
| 142 |
$this->tots = $tots; |
| 143 |
$this->festivities = $festivities; |
| 144 |
$this->rdaynotes = $rdaynotes; |
| 145 |
$this->all_options = $all_options; |
| 146 |
$this->visible_days = $visible_days; |
| 147 |
$this->past_days = $past_days; |
| 148 |
|
| 149 |
parent::display($tpl); |
| 150 |
} |
| 151 |
|
| 152 |
/** |
| 153 |
* Gets the rate plan name from the given tariff ID. |
| 154 |
* |
| 155 |
* @param int $idtar the tariff id. |
| 156 |
* |
| 157 |
* @return null|string the rate plan name or null. |
| 158 |
*/ |
| 159 |
public function getRatePlanFromTariff($idtar) |
| 160 |
{ |
| 161 |
$idtar = (int)$idtar; |
| 162 |
if (empty($idtar)) { |
| 163 |
return null; |
| 164 |
} |
| 165 |
|
| 166 |
$dbo = JFactory::getDbo(); |
| 167 |
|
| 168 |
$q = "SELECT `d`.`idprice`, `p`.`name` |
| 169 |
FROM `#__vikbooking_dispcost` AS `d` |
| 170 |
LEFT JOIN `#__vikbooking_prices` AS `p` ON `d`.`idprice`=`p`.`id` |
| 171 |
WHERE `d`.`id`={$idtar} AND `p`.`name` IS NOT NULL"; |
| 172 |
$dbo->setQuery($q, 0, 1); |
| 173 |
$record = $dbo->loadAssoc(); |
| 174 |
|
| 175 |
if (!$record) { |
| 176 |
return null; |
| 177 |
} |
| 178 |
|
| 179 |
return $record['name']; |
| 180 |
} |
| 181 |
} |
| 182 |
|