PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.8
VikBooking Hotel Booking Engine & PMS v1.6.8
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 / overv / view.html.php

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

287 lines 10.4 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 VikBookingViewOverv extends JViewVikBooking
17 {
18 public function display($tpl = null)
19 {
20 // Set the toolbar
21 $this->addToolBar();
22
23 if (!JFactory::getUser()->authorise('core.vbo.availability', 'com_vikbooking')) {
24 VBOHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR'));
25 }
26
27 $dbo = JFactory::getDbo();
28 $app = JFactory::getApplication();
29
30 if (file_exists(VCM_ADMIN_PATH.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'vcm-channels.css')) {
31 $document = JFactory::getDocument();
32 $document->addStyleSheet(VCM_ADMIN_URI.'assets/css/vcm-channels.css');
33 }
34 $session = JFactory::getSession();
35 $cookie = JFactory::getApplication()->input->cookie;
36 $pmonth = VikRequest::getString('month', '', 'request');
37 $pmnum = VikRequest::getInt('mnum', '', 'request');
38 $cmnum = $cookie->get('vbOvwMnum', '', 'string');
39 $punits_show_type = VikRequest::getString('units_show_type', '', 'request');
40 // category filter
41 $pcategory_id = VikRequest::getString('category_id', '', 'request');
42 $scategory_id = $session->get('vbOvwCatid', 0);
43 $pcategory_id = !strlen($pcategory_id) && !empty($scategory_id) ? $scategory_id : $pcategory_id;
44 $session->set('vbOvwCatid', $pcategory_id);
45 //
46
47 $pbmode = VikRequest::getString('bmode', '', 'request');
48 if (!empty($pbmode) && ($pbmode == 'classic' || $pbmode == 'tags')) {
49 VikRequest::setCookie('vbTagsMode', $pbmode, (time() + (86400 * 365)), '/');
50 $session->set('vbTagsMode', $pbmode);
51 } else {
52 $cbmode = $cookie->get('vbTagsMode', '', 'string');
53 $pbmode = (!empty($cbmode) && ($cbmode == 'classic' || $cbmode == 'tags') ? $cbmode : 'classic');
54 VikRequest::setCookie('vbTagsMode', $pbmode, (time() + (86400 * 365)), '/');
55 $session->set('vbTagsMode', $pbmode);
56 }
57
58 if (!empty($punits_show_type)) {
59 $session->set('vbUnitsShowType', $punits_show_type);
60 }
61 if (empty($pmonth)) {
62 $sess_month = $session->get('vbOverviewMonth', '');
63 if (!empty($sess_month)) {
64 $pmonth = $sess_month;
65 }
66 }
67 if (intval($cmnum) > 0 && empty($pmnum)) {
68 $pmnum = $cmnum;
69 }
70 if ($pmnum > 0) {
71 VikRequest::setCookie('vbOvwMnum', $pmnum, (time() + (86400 * 365)), '/');
72 $session->set('vbOvwMnum', $pmnum);
73 } else {
74 $smnum = $session->get('vbOvwMnum', '1');
75 $pmnum = intval($smnum) > 0 ? $smnum : 1;
76 }
77
78 // remove expired locked records
79 $q = "DELETE FROM `#__vikbooking_tmplock` WHERE `until`<" . time() . ";";
80 $dbo->setQuery($q);
81 $dbo->execute();
82
83 $q = "SELECT `checkin` FROM `#__vikbooking_busy` ORDER BY `checkin` ASC LIMIT 1;";
84 $dbo->setQuery($q);
85 $oldest_checkin = $dbo->loadResult();
86 if (!$oldest_checkin) {
87 $oldest_checkin = 0;
88 }
89
90 $q = "SELECT `checkout` FROM `#__vikbooking_busy` ORDER BY `checkout` DESC LIMIT 1;";
91 $dbo->setQuery($q);
92 $furthest_checkout = $dbo->loadResult();
93 if (!$furthest_checkout) {
94 $furthest_checkout = 0;
95 }
96
97 if (!empty($pmonth)) {
98 $session->set('vbOverviewMonth', $pmonth);
99 $tsstart = $pmonth;
100 } else {
101 $oggid = getdate();
102 $tsstart = mktime(0, 0, 0, $oggid['mon'], 1, $oggid['year']);
103 }
104 $oggid = getdate($tsstart);
105 $tsend = mktime(0, 0, 0, ($oggid['mon'] + $pmnum), 1, $oggid['year']);
106 $today = getdate();
107 $firstmonth = mktime(0, 0, 0, $today['mon'], 1, $today['year']);
108 $wmonthsel = "<select name=\"month\" onchange=\"document.vboverview.submit();\">\n";
109 if ($oldest_checkin) {
110 $oldest_date = getdate($oldest_checkin);
111 $oldest_month = mktime(0, 0, 0, $oldest_date['mon'], 1, $oldest_date['year']);
112 if ($oldest_month < $firstmonth) {
113 while ($oldest_month < $firstmonth) {
114 $wmonthsel .= "<option value=\"".$oldest_month."\"".($oldest_month == $tsstart ? " selected=\"selected\"" : "").">".VikBooking::sayMonth($oldest_date['mon'])." ".$oldest_date['year']."</option>\n";
115 if ($oldest_date['mon']==12) {
116 $nextmon = 1;
117 $year = $oldest_date['year'] + 1;
118 } else {
119 $nextmon = $oldest_date['mon'] + 1;
120 $year = $oldest_date['year'];
121 }
122 $oldest_month = mktime(0, 0, 0, $nextmon, 1, $year);
123 $oldest_date = getdate($oldest_month);
124 }
125 }
126 }
127 $wmonthsel .= "<option value=\"".$firstmonth."\"".($firstmonth == $tsstart ? " selected=\"selected\"" : "").">".VikBooking::sayMonth($today['mon'])." ".$today['year']."</option>\n";
128 $futuremonths = 12;
129 if ($furthest_checkout) {
130 $furthest_date = getdate($furthest_checkout);
131 $furthest_month = mktime(0, 0, 0, $furthest_date['mon'], 1, $furthest_date['year']);
132 if ($furthest_month > $firstmonth) {
133 $monthsdiff = floor(($furthest_month - $firstmonth) / (86400 * 30));
134 $futuremonths = $monthsdiff > $futuremonths ? $monthsdiff : $futuremonths;
135 }
136 }
137 for ($i = 1; $i <= $futuremonths; $i++) {
138 $newts = getdate($firstmonth);
139 if ($newts['mon'] == 12) {
140 $nextmon = 1;
141 $year = $newts['year'] + 1;
142 } else {
143 $nextmon = $newts['mon'] + 1;
144 $year = $newts['year'];
145 }
146 $firstmonth = mktime(0, 0, 0, $nextmon, 1, $year);
147 $newts = getdate($firstmonth);
148 $wmonthsel .= "<option value=\"".$firstmonth."\"".($firstmonth==$tsstart ? " selected=\"selected\"" : "").">".VikBooking::sayMonth($newts['mon'])." ".$newts['year']."</option>\n";
149 }
150 $wmonthsel .= "</select>\n";
151
152 $lim = $app->getUserStateFromRequest("com_vikbooking.limit", 'limit', $app->get('list_limit'), 'int');
153 $lim0 = VikRequest::getVar('limitstart', 0, '', 'int');
154 /**
155 * Filter by category.
156 *
157 * @since 1.13
158 */
159 $catfilter = !empty($pcategory_id) ? "(`r`.`idcat`='" . $pcategory_id . ";' OR `r`.`idcat` LIKE '" . $pcategory_id . ";%' OR `r`.`idcat` LIKE '%;" . $pcategory_id . ";%' OR `r`.`idcat` LIKE '%;" . $pcategory_id . ";')" : "";
160 //
161 $q = "SELECT SQL_CALC_FOUND_ROWS `r`.* FROM `#__vikbooking_rooms` AS `r`" . (!empty($catfilter) ? " WHERE " . $catfilter : '') . " ORDER BY `r`.`name` ASC";
162 $dbo->setQuery($q, $lim0, $lim);
163 $rows = $dbo->loadAssocList();
164 if (!$rows) {
165 if ($session->get('vbOvwCatid', '')) {
166 // unset empty category with no rooms
167 $session->set('vbOvwCatid', 0);
168 }
169 VikError::raiseWarning('', JText::translate('VBOVERVIEWNOROOMS'));
170 $app->redirect("index.php?option=com_vikbooking");
171 $app->close();
172 }
173
174 $dbo->setQuery('SELECT FOUND_ROWS();');
175 jimport('joomla.html.pagination');
176 $pageNav = new JPagination( $dbo->loadResult(), $lim0, $lim );
177 $navbut = "<table align=\"center\"><tr><td>".$pageNav->getListFooter()."</td></tr></table>";
178
179 /**
180 * Filter by category.
181 *
182 * @since 1.13 (J) - 1.3 (WP)
183 */
184 $categories = [];
185 $q = "SELECT `id`,`name` FROM `#__vikbooking_categories` ORDER BY `name` ASC;";
186 $dbo->setQuery($q);
187 $allcats = $dbo->loadAssocList();
188 if ($allcats) {
189 foreach ($allcats as $cat) {
190 $categories[$cat['id']] = $cat['name'];
191 }
192 }
193
194 // load records with basic information.
195 $arrbusy = [
196 'tmplock' => [],
197 ];
198 $actnow = time();
199 foreach ($rows as $r) {
200 $q = "SELECT `b`.*,`ob`.`idorder`,`o`.`custdata`,`o`.`days`,`o`.`roomsnum`,`o`.`idorderota`,`o`.`channel`,`o`.`closure`
201 FROM `#__vikbooking_busy` AS `b`
202 LEFT JOIN `#__vikbooking_ordersbusy` AS `ob` ON `b`.`id`=`ob`.`idbusy`
203 LEFT JOIN `#__vikbooking_orders` AS `o` ON `ob`.`idorder`=`o`.`id`
204 WHERE `b`.`idroom`=" . (int)$r['id'] . " AND (`b`.`checkin`>=" . $tsstart . " OR `b`.`checkout`>=" . $tsstart . ") AND (`b`.`checkin`<=" . $tsend . " OR `b`.`checkout`<=" . $tsstart . ");";
205 $dbo->setQuery($q);
206 $occ_rows = $dbo->loadAssocList();
207 $arrbusy[$r['id']] = $occ_rows ? $occ_rows : [];
208
209 // locked (stand-by) records
210 $q = "SELECT `l`.*,`or`.`idroom` FROM `#__vikbooking_tmplock` AS `l` LEFT JOIN `#__vikbooking_ordersrooms` AS `or` ON `l`.`idorder`=`or`.`idorder` WHERE `or`.`idroom`='".$r['id']."' AND (`l`.`checkin`>=".$tsstart." OR `l`.`checkout`>=".$tsstart.") AND (`l`.`checkin`<=".$tsend." OR `l`.`checkout`<=".$tsstart.") AND `l`.`until`>=".$actnow.";";
211 $dbo->setQuery($q);
212 $lock_rows = $dbo->loadAssocList();
213 if ($lock_rows) {
214 $arrbusy['tmplock'][$r['id']] = $lock_rows;
215 }
216 }
217
218 // collect additional information for each booking
219 $extra_info_map = [];
220 foreach ($arrbusy as $rid => $roomres) {
221 foreach ($roomres as $k => $res) {
222 if (empty($res['idorder'])) {
223 continue;
224 }
225 if (isset($extra_info_map[$res['idorder']])) {
226 // merge existing extra information
227 $arrbusy[$rid][$k] = array_merge($res, $extra_info_map[$res['idorder']]);
228 continue;
229 }
230 // get booking extra information
231 $q = "SELECT `oc`.`idcustomer`,`c`.`first_name`,`c`.`last_name`,`c`.`pic`
232 FROM `#__vikbooking_customers_orders` AS `oc`
233 LEFT JOIN `#__vikbooking_customers` AS `c` ON `oc`.`idcustomer`=`c`.`id`
234 WHERE `oc`.`idorder`={$res['idorder']}";
235 $dbo->setQuery($q, 0, 1);
236 $extra_info = $dbo->loadAssoc();
237 $extra_info = $extra_info ? $extra_info : [];
238 // merge and map booking extra information
239 $arrbusy[$rid][$k] = array_merge($res, $extra_info);
240 $extra_info_map[$res['idorder']] = $extra_info;
241 }
242 }
243
244 /**
245 * Check the next festivities periodically
246 *
247 * @since 1.12.0 (J) - 1.2 (WP)
248 */
249 $fests = VikBooking::getFestivitiesInstance();
250 if ($fests->shouldCheckFestivities()) {
251 $fests->storeNextFestivities();
252 }
253 $festivities = $fests->loadFestDates(date('Y-m-d', $tsstart), date('Y-m-d', $tsend));
254
255 /**
256 * Load room day notes from first month
257 *
258 * @since 1.13.5 (J) - 1.3 (WP)
259 */
260 $rdaynotes = VikBooking::getCriticalDatesInstance()->loadRoomDayNotes(date('Y-m-d', $tsstart), date('Y-m-d', $tsend));
261 //
262
263 $this->rows = $rows;
264 $this->arrbusy = $arrbusy;
265 $this->wmonthsel = $wmonthsel;
266 $this->tsstart = $tsstart;
267 $this->festivities = $festivities;
268 $this->rdaynotes = $rdaynotes;
269 $this->lim0 = $lim0;
270 $this->navbut = $navbut;
271 $this->categories = $categories;
272
273 // Display the template
274 parent::display($tpl);
275 }
276
277 /**
278 * Sets the toolbar
279 */
280 protected function addToolBar()
281 {
282 JToolBarHelper::title(JText::translate('VBMAINOVERVIEWTITLE'), 'vikbooking');
283 JToolBarHelper::cancel( 'canceledorder', JText::translate('VBBACK'));
284 JToolBarHelper::spacer();
285 }
286 }
287