PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.9
VikBooking Hotel Booking Engine & PMS v1.6.9
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / admin / views / tableaux / view.html.php

view.html.php in VikBooking Hotel Booking Engine & PMS 1.6.9, at admin/views/tableaux/view.html.php

286 lines 10.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 // import Joomla view library
14 jimport('joomla.application.component.view');
15
16 class VikBookingViewTableaux extends JViewVikBooking
17 {
18 public function display($tpl = null)
19 {
20 // Set the toolbar
21 $this->addToolBar();
22
23 $dbo = JFactory::getDbo();
24 $session = JFactory::getSession();
25 $cookie = JFactory::getApplication()->input->cookie;
26 $roomids = VikRequest::getVar('roomids', array(), 'request', 'int');
27 $month = VikRequest::getInt('month', 0, 'request');
28 $fromdate = VikRequest::getString('tbxfromdate', '', 'request');
29 $todate = VikRequest::getString('tbxtodate', '', 'request');
30 $sessfromts = $session->get('vbTbxFrom', '');
31 $sesstots = $session->get('vbTbxTo', '');
32 // view mode (classic or tag, taken from overv View)
33 $cbmode = $cookie->get('vbTagsMode', $session->get('vbTagsMode', ''), 'string');
34 $pbmode = !empty($cbmode) && ($cbmode == 'classic' || $cbmode == 'tags') ? $cbmode : 'classic';
35 VikRequest::setCookie('vbTagsMode', $pbmode, (time() + (86400 * 365)), '/');
36 $session->set('vbTagsMode', $pbmode);
37 // prepare dates
38 $now = empty($month) ? time() : $month;
39 $tsinfo = getdate($now);
40 $fromts = mktime(0, 0, 0, $tsinfo['mon'], 1, $tsinfo['year']);
41 $tots = mktime(23, 59, 59, $tsinfo['mon'], date('t', $now), $tsinfo['year']);
42 if (!empty($fromdate) && !empty($todate)) {
43 $fromts = VikBooking::getDateTimestamp($fromdate, 0, 0);
44 $tots = VikBooking::getDateTimestamp($todate, 23, 59, 59);
45 } elseif (!empty($sessfromts) && !empty($sesstots)) {
46 $fromts = $sessfromts;
47 $tots = $sesstots;
48 }
49 if (empty($fromts) || empty($tots) || $tots <= $fromts) {
50 $fromts = mktime(0, 0, 0, $tsinfo['mon'], 1, $tsinfo['year']);
51 $tots = mktime(23, 59, 59, $tsinfo['mon'], date('t', $now), $tsinfo['year']);
52 }
53 $session->set('vbTbxFrom', $fromts);
54 $session->set('vbTbxTo', $tots);
55
56 // make sure the list of rooms does not contain empty values for "all"
57 if (count($roomids) && empty($roomids[0])) {
58 $roomids = array();
59 }
60
61 // check the category filter by pushing the proper room ids
62 $reqcats = array();
63 $cat_ids_filter = array();
64 foreach ($roomids as $k => $rid) {
65 if (empty($rid)) {
66 continue;
67 }
68 $rid = (int)$rid;
69 if ($rid < 0) {
70 // it's a category ID when we get negative values
71 array_push($reqcats, ($rid + (abs($rid) * 2)));
72 // unset this value as we do not need it there for the query
73 unset($roomids[$k]);
74 }
75 }
76 // reset keys in case some were unset
77 $roomids = array_values($roomids);
78 if (count($reqcats)) {
79 // gather all room IDs from the given category IDs
80 $clauses = array();
81 foreach ($reqcats as $cat_id) {
82 array_push($clauses, "(`idcat`='" . $cat_id . ";' OR `idcat` LIKE '" . $cat_id . ";%' OR `idcat` LIKE '%;" . $cat_id . ";%' OR `idcat` LIKE '%;" . $cat_id . ";')");
83 }
84 $q = "SELECT `id`,`name`,`units`,`params` FROM `#__vikbooking_rooms` WHERE " . implode(' OR ', $clauses) . " ORDER BY `name` ASC;";
85 $dbo->setQuery($q);
86 $catrooms = $dbo->loadAssocList();
87 if ($catrooms) {
88 // push rooms gathered from category ID filter, if not already in filter
89 foreach ($catrooms as $catroom) {
90 if (in_array((string)$catroom['id'], $roomids) || in_array((int)$catroom['id'], $roomids)) {
91 continue;
92 }
93 array_push($roomids, $catroom['id']);
94 }
95 }
96 }
97 //
98
99 // get min and max dates
100 $mindate = 0;
101 $maxdate = 0;
102 $q = "SELECT `checkin` FROM `#__vikbooking_orders` WHERE `status`='confirmed' ORDER BY `checkin` ASC LIMIT 1;";
103 $dbo->setQuery($q);
104 $mindate = $dbo->loadResult();
105 if (!$mindate) {
106 $mindate = 0;
107 }
108 $q = "SELECT `checkout` FROM `#__vikbooking_orders` WHERE `status`='confirmed' ORDER BY `checkout` DESC LIMIT 1;";
109 $dbo->setQuery($q);
110 $maxdate = $dbo->loadResult();
111 if (!$maxdate) {
112 $maxdate = 0;
113 }
114
115 // build months array
116 $months = array();
117 $months_labels = array(
118 JText::translate('VBMONTHONE'),
119 JText::translate('VBMONTHTWO'),
120 JText::translate('VBMONTHTHREE'),
121 JText::translate('VBMONTHFOUR'),
122 JText::translate('VBMONTHFIVE'),
123 JText::translate('VBMONTHSIX'),
124 JText::translate('VBMONTHSEVEN'),
125 JText::translate('VBMONTHEIGHT'),
126 JText::translate('VBMONTHNINE'),
127 JText::translate('VBMONTHTEN'),
128 JText::translate('VBMONTHELEVEN'),
129 JText::translate('VBMONTHTWELVE')
130 );
131 if ($mindate > 0 && $maxdate > 0) {
132 // prev months (max 5, if any)
133 $minback = mktime(0, 0, 0, date('n', $mindate), 1, date('Y', $mindate));
134 $startinfo = getdate(mktime(23, 59, 59, ($tsinfo['mon'] - 1), $tsinfo['mday'], $tsinfo['year']));
135 $maxmonths = 5;
136 $monthscount = 0;
137 while ($startinfo[0] >= $minback && $monthscount < 5) {
138 // push prev month
139 array_push($months, array(
140 'name' => $months_labels[($startinfo['mon'] - 1)] . ' ' . $startinfo['year'],
141 'from' => mktime(0, 0, 0, $startinfo['mon'], 1, $startinfo['year']),
142 'to' => mktime(0, 0, 0, $startinfo['mon'], date('t', $startinfo[0]), $startinfo['year']),
143 ));
144
145 // next prev month
146 $startinfo = getdate(mktime(23, 59, 59, ($startinfo['mon'] - 1), $startinfo['mday'], $startinfo['year']));
147 $monthscount++;
148 }
149 // revert the array until now for the past months
150 $months = array_reverse($months);
151 // push current month
152 array_push($months, array(
153 'name' => $months_labels[($tsinfo['mon'] - 1)] . ' ' . $tsinfo['year'],
154 'from' => mktime(0, 0, 0, $tsinfo['mon'], 1, $tsinfo['year']),
155 'to' => mktime(0, 0, 0, $tsinfo['mon'], date('t', $tsinfo[0]), $tsinfo['year']),
156 ));
157 // future months (max 5, if any)
158 $maxnext = mktime(23, 59, 59, date('n', $maxdate), date('t', $maxdate), date('Y', $maxdate));
159 $startinfo = getdate(mktime(0, 0, 0, ($tsinfo['mon'] + 1), $tsinfo['mday'], $tsinfo['year']));
160 $maxmonths = 5;
161 $monthscount = 0;
162 while ($startinfo[0] <= $maxnext && $monthscount < 5) {
163 // push next month
164 array_push($months, array(
165 'name' => $months_labels[($startinfo['mon'] - 1)] . ' ' . $startinfo['year'],
166 'from' => mktime(0, 0, 0, $startinfo['mon'], 1, $startinfo['year']),
167 'to' => mktime(0, 0, 0, $startinfo['mon'], date('t', $startinfo[0]), $startinfo['year']),
168 ));
169
170 // next future month
171 $startinfo = getdate(mktime(0, 0, 0, ($startinfo['mon'] + 1), $startinfo['mday'], $startinfo['year']));
172 $monthscount++;
173 }
174 }
175
176 // get all rooms from filters
177 $rooms = array();
178 $q = "SELECT `id`,`name`,`units`,`params` FROM `#__vikbooking_rooms`".($roomids ? " WHERE `id` IN (".implode(', ', $roomids).")" : "")." ORDER BY `name` ASC;";
179 $dbo->setQuery($q);
180 $all = $dbo->loadAssocList();
181 if ($all) {
182 foreach ($all as $r) {
183 $rooms[$r['id']] = $r;
184 }
185 }
186 if (!$rooms) {
187 JFactory::getApplication()->redirect('index.php?option=com_vikbooking');
188 exit;
189 }
190 // all rooms must always be taken to compose the drop down
191 $allrooms = array();
192 if (!$roomids) {
193 $allrooms = $rooms;
194 } else {
195 $q = "SELECT `id`,`name`,`units` FROM `#__vikbooking_rooms` ORDER BY `name` ASC;";
196 $dbo->setQuery($q);
197 $all = $dbo->loadAssocList();
198 if ($all) {
199 foreach ($all as $r) {
200 $allrooms[$r['id']] = $r;
201 }
202 }
203 }
204
205 // get all occupied dates for these rooms
206 $rooms_busy = array();
207 $q = "SELECT `b`.*,`ob`.`idorder`,`o`.`custdata`,`o`.`status`,`o`.`totpaid`,`o`.`roomsnum`,`o`.`total`,`o`.`idorderota`,`o`.`channel`,`o`.`country`,`o`.`colortag`,`oc`.`idcustomer`,`c`.`first_name`,`c`.`last_name`,`c`.`pic`,
208 (SELECT GROUP_CONCAT(`or`.`roomindex` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `indexes`,
209 (SELECT GROUP_CONCAT(`or`.`idroom` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `roomids`
210 FROM `#__vikbooking_busy` AS `b`
211 LEFT JOIN `#__vikbooking_ordersbusy` AS `ob` ON `b`.`id`=`ob`.`idbusy`
212 LEFT JOIN `#__vikbooking_orders` AS `o` ON `ob`.`idorder`=`o`.`id`
213 LEFT JOIN `#__vikbooking_customers_orders` AS `oc` ON `ob`.`idorder`=`oc`.`idorder`
214 LEFT JOIN `#__vikbooking_customers` AS `c` ON `oc`.`idcustomer`=`c`.`id`
215 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
216 ORDER BY `b`.`checkin` ASC, `ob`.`idorder` ASC;";
217 $dbo->setQuery($q);
218 $busy = $dbo->loadAssocList();
219 if ($busy) {
220 foreach ($busy as $b) {
221 if (!isset($rooms_busy[$b['idroom']])) {
222 $rooms_busy[$b['idroom']] = array();
223 }
224 array_push($rooms_busy[$b['idroom']], $b);
225 }
226 }
227
228 /**
229 * Check the next festivities periodically
230 *
231 * @since 1.13.5
232 */
233 $fests = VikBooking::getFestivitiesInstance();
234 if ($fests->shouldCheckFestivities()) {
235 $fests->storeNextFestivities();
236 }
237 $festivities = $fests->loadFestDates(date('Y-m-d', $fromts), date('Y-m-d', $tots));
238
239 /**
240 * Load room day notes from first month
241 *
242 * @since 1.13.5
243 */
244 $rdaynotes = VikBooking::getCriticalDatesInstance()->loadRoomDayNotes(date('Y-m-d', $fromts), date('Y-m-d', $tots));
245 //
246
247 /**
248 * Load categories to be used for group filter.
249 *
250 * @since 1.13.5
251 */
252 $q = "SELECT `id`,`name` FROM `#__vikbooking_categories` ORDER BY `#__vikbooking_categories`.`name` ASC;";
253 $dbo->setQuery($q);
254 $categories = $dbo->loadAssocList();
255 $categories = $categories ? $categories : [];
256
257 $this->roomids = $roomids;
258 $this->rooms = $rooms;
259 $this->allrooms = $allrooms;
260 $this->categories = $categories;
261 $this->reqcats = $reqcats;
262 $this->mindate = $mindate;
263 $this->maxdate = $maxdate;
264 $this->rooms_busy = $rooms_busy;
265 $this->months = $months;
266 $this->fromts = $fromts;
267 $this->tots = $tots;
268 $this->pbmode = $pbmode;
269 $this->festivities = $festivities;
270 $this->rdaynotes = $rdaynotes;
271
272 // Display the template
273 parent::display($tpl);
274 }
275
276 /**
277 * Sets the toolbar
278 */
279 protected function addToolBar()
280 {
281 JToolBarHelper::title(JText::translate('VBMAINTABLEAUXTITLE'), 'vikbooking');
282 JToolBarHelper::cancel( 'canceldash', JText::translate('VBBACK'));
283 JToolBarHelper::spacer();
284 }
285 }
286