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

279 lines 10.1 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 VikError::raiseWarning('', JText::translate('VBOVERVIEWNOROOMS'));
162 $app->redirect("index.php?option=com_vikbooking");
163 $app->close();
164 }
165
166 $dbo->setQuery('SELECT FOUND_ROWS();');
167 jimport('joomla.html.pagination');
168 $pageNav = new JPagination( $dbo->loadResult(), $lim0, $lim );
169 $navbut = "<table align=\"center\"><tr><td>".$pageNav->getListFooter()."</td></tr></table>";
170
171 /**
172 * Filter by category.
173 *
174 * @since 1.13 (J) - 1.3 (WP)
175 */
176 $categories = [];
177 $q = "SELECT `id`,`name` FROM `#__vikbooking_categories` ORDER BY `name` ASC;";
178 $dbo->setQuery($q);
179 $allcats = $dbo->loadAssocList();
180 if ($allcats) {
181 foreach ($allcats as $cat) {
182 $categories[$cat['id']] = $cat['name'];
183 }
184 }
185
186 // load records with basic information.
187 $arrbusy = [
188 'tmplock' => [],
189 ];
190 $actnow = time();
191 foreach ($rows as $r) {
192 $q = "SELECT `b`.*,`ob`.`idorder`,`o`.`custdata`,`o`.`days`,`o`.`roomsnum`,`o`.`idorderota`,`o`.`channel`,`o`.`closure`
193 FROM `#__vikbooking_busy` AS `b`
194 LEFT JOIN `#__vikbooking_ordersbusy` AS `ob` ON `b`.`id`=`ob`.`idbusy`
195 LEFT JOIN `#__vikbooking_orders` AS `o` ON `ob`.`idorder`=`o`.`id`
196 WHERE `b`.`idroom`=" . (int)$r['id'] . " AND (`b`.`checkin`>=" . $tsstart . " OR `b`.`checkout`>=" . $tsstart . ") AND (`b`.`checkin`<=" . $tsend . " OR `b`.`checkout`<=" . $tsstart . ");";
197 $dbo->setQuery($q);
198 $occ_rows = $dbo->loadAssocList();
199 $arrbusy[$r['id']] = $occ_rows ? $occ_rows : [];
200
201 // locked (stand-by) records
202 $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.";";
203 $dbo->setQuery($q);
204 $lock_rows = $dbo->loadAssocList();
205 if ($lock_rows) {
206 $arrbusy['tmplock'][$r['id']] = $lock_rows;
207 }
208 }
209
210 // collect additional information for each booking
211 $extra_info_map = [];
212 foreach ($arrbusy as $rid => $roomres) {
213 foreach ($roomres as $k => $res) {
214 if (empty($res['idorder'])) {
215 continue;
216 }
217 if (isset($extra_info_map[$res['idorder']])) {
218 // merge existing extra information
219 $arrbusy[$rid][$k] = array_merge($res, $extra_info_map[$res['idorder']]);
220 continue;
221 }
222 // get booking extra information
223 $q = "SELECT `oc`.`idcustomer`,`c`.`first_name`,`c`.`last_name`,`c`.`pic`
224 FROM `#__vikbooking_customers_orders` AS `oc`
225 LEFT JOIN `#__vikbooking_customers` AS `c` ON `oc`.`idcustomer`=`c`.`id`
226 WHERE `oc`.`idorder`={$res['idorder']}";
227 $dbo->setQuery($q, 0, 1);
228 $extra_info = $dbo->loadAssoc();
229 $extra_info = $extra_info ? $extra_info : [];
230 // merge and map booking extra information
231 $arrbusy[$rid][$k] = array_merge($res, $extra_info);
232 $extra_info_map[$res['idorder']] = $extra_info;
233 }
234 }
235
236 /**
237 * Check the next festivities periodically
238 *
239 * @since 1.12.0 (J) - 1.2 (WP)
240 */
241 $fests = VikBooking::getFestivitiesInstance();
242 if ($fests->shouldCheckFestivities()) {
243 $fests->storeNextFestivities();
244 }
245 $festivities = $fests->loadFestDates(date('Y-m-d', $tsstart), date('Y-m-d', $tsend));
246
247 /**
248 * Load room day notes from first month
249 *
250 * @since 1.13.5 (J) - 1.3 (WP)
251 */
252 $rdaynotes = VikBooking::getCriticalDatesInstance()->loadRoomDayNotes(date('Y-m-d', $tsstart), date('Y-m-d', $tsend));
253 //
254
255 $this->rows = $rows;
256 $this->arrbusy = $arrbusy;
257 $this->wmonthsel = $wmonthsel;
258 $this->tsstart = $tsstart;
259 $this->festivities = $festivities;
260 $this->rdaynotes = $rdaynotes;
261 $this->lim0 = $lim0;
262 $this->navbut = $navbut;
263 $this->categories = $categories;
264
265 // Display the template
266 parent::display($tpl);
267 }
268
269 /**
270 * Sets the toolbar
271 */
272 protected function addToolBar()
273 {
274 JToolBarHelper::title(JText::translate('VBMAINOVERVIEWTITLE'), 'vikbooking');
275 JToolBarHelper::cancel( 'canceledorder', JText::translate('VBBACK'));
276 JToolBarHelper::spacer();
277 }
278 }
279