PluginProbe
VikBooking Hotel Booking Engine & PMS / trunk
VikBooking Hotel Booking Engine & PMS vtrunk
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 1.7.3 All 36 releases
vikbooking / admin / views / tableaux / view.html.php

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

257 lines 9.6 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 foreach ($all as $r) {
182 $rooms[$r['id']] = $r;
183 }
184 if (!$rooms) {
185 JFactory::getApplication()->redirect('index.php?option=com_vikbooking');
186 exit;
187 }
188
189 // get all occupied dates for these rooms
190 $rooms_busy = array();
191 $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`,
192 (SELECT GROUP_CONCAT(`or`.`roomindex` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `indexes`,
193 (SELECT GROUP_CONCAT(`or`.`idroom` SEPARATOR ';') FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`ob`.`idorder`) AS `roomids`
194 FROM `#__vikbooking_busy` AS `b`
195 LEFT JOIN `#__vikbooking_ordersbusy` AS `ob` ON `b`.`id`=`ob`.`idbusy`
196 LEFT JOIN `#__vikbooking_orders` AS `o` ON `ob`.`idorder`=`o`.`id`
197 LEFT JOIN `#__vikbooking_customers_orders` AS `oc` ON `ob`.`idorder`=`oc`.`idorder`
198 LEFT JOIN `#__vikbooking_customers` AS `c` ON `oc`.`idcustomer`=`c`.`id`
199 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
200 ORDER BY `b`.`checkin` ASC, `ob`.`idorder` ASC;";
201 $dbo->setQuery($q);
202 $busy = $dbo->loadAssocList();
203 if ($busy) {
204 foreach ($busy as $b) {
205 if (!isset($rooms_busy[$b['idroom']])) {
206 $rooms_busy[$b['idroom']] = array();
207 }
208 array_push($rooms_busy[$b['idroom']], $b);
209 }
210 }
211
212 /**
213 * Check the next festivities periodically
214 *
215 * @since 1.13.5
216 */
217 $fests = VikBooking::getFestivitiesInstance();
218 if ($fests->shouldCheckFestivities()) {
219 $fests->storeNextFestivities();
220 }
221 $festivities = $fests->loadFestDates(date('Y-m-d', $fromts), date('Y-m-d', $tots));
222
223 /**
224 * Load room day notes from first month
225 *
226 * @since 1.13.5
227 */
228 $rdaynotes = VikBooking::getCriticalDatesInstance()->loadRoomDayNotes(date('Y-m-d', $fromts), date('Y-m-d', $tots));
229
230 $this->roomids = $roomids;
231 $this->rooms = $rooms;
232 $this->reqcats = $reqcats;
233 $this->mindate = $mindate;
234 $this->maxdate = $maxdate;
235 $this->rooms_busy = $rooms_busy;
236 $this->months = $months;
237 $this->fromts = $fromts;
238 $this->tots = $tots;
239 $this->pbmode = $pbmode;
240 $this->festivities = $festivities;
241 $this->rdaynotes = $rdaynotes;
242
243 // Display the template
244 parent::display($tpl);
245 }
246
247 /**
248 * Sets the toolbar
249 */
250 protected function addToolBar()
251 {
252 JToolBarHelper::title(JText::translate('VBMAINTABLEAUXTITLE'), 'vikbooking');
253 JToolBarHelper::cancel( 'canceldash', JText::translate('VBBACK'));
254 JToolBarHelper::spacer();
255 }
256 }
257