PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.7
VikBooking Hotel Booking Engine & PMS v1.6.7
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.7, at admin/views/overv/view.html.php

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