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 / calendar / view.html.php

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

275 lines 9.5 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 VikBookingViewCalendar 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') && !JFactory::getUser()->authorise('core.vbo.bookings', 'com_vikbooking')) {
24 VBOHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR'));
25 }
26
27 $cid = VikRequest::getVar('cid', array(0));
28 $aid = $cid[0];
29
30 $app = JFactory::getApplication();
31 $dbo = JFactory::getDbo();
32 $session = JFactory::getSession();
33
34 $rid = $session->get('vbCalRid', '');
35 $aid = !empty($rid) && empty($aid) ? $rid : $aid;
36 if (empty($aid)) {
37 $q = "SELECT `id` FROM `#__vikbooking_rooms` ORDER BY `#__vikbooking_rooms`.`name` ASC";
38 $dbo->setQuery($q, 0, 1);
39 $aid = $dbo->loadResult();
40 }
41 if (empty($aid)) {
42 VikError::raiseWarning('', 'No Rooms.');
43 $app->redirect("index.php?option=com_vikbooking&task=rooms");
44 $app->close();
45 }
46
47 $session->set('vbCalRid', $aid);
48 $pvmode = VikRequest::getString('vmode', '', 'request');
49 $cur_vmode = $session->get('vikbookingvmode', "");
50 if (!empty($pvmode) && ctype_digit($pvmode)) {
51 $session->set('vikbookingvmode', $pvmode);
52 } elseif (empty($cur_vmode)) {
53 $session->set('vikbookingvmode', "12");
54 }
55 $vmode = (int)$session->get('vikbookingvmode', "12");
56
57 // new reservation ID default status
58 $new_res_id = 0;
59
60 $q = "SELECT `id`,`name`,`img`,`units` FROM `#__vikbooking_rooms` WHERE `id`=".$dbo->quote($aid);
61 $dbo->setQuery($q, 0, 1);
62 $room = $dbo->loadAssoc();
63 if (!$room) {
64 VikError::raiseWarning('', 'No Rooms.');
65 $app->redirect("index.php?option=com_vikbooking&task=rooms");
66 $app->close();
67 }
68
69 $q = "SELECT `id`,`name`,`units` FROM `#__vikbooking_rooms` ORDER BY `#__vikbooking_rooms`.`name` ASC;";
70 $dbo->setQuery($q);
71 $allc = $dbo->loadAssocList();
72
73 $q = "SELECT `id`,`name` FROM `#__vikbooking_gpayments` ORDER BY `#__vikbooking_gpayments`.`name` ASC;";
74 $dbo->setQuery($q);
75 $payments = $dbo->loadAssocList();
76
77 /**
78 * Split stay data for booking.
79 *
80 * @since 1.16.0 (J) - 1.6.0 (WP)
81 */
82 $split_stay_data = VikRequest::getVar('split_stay_data', array());
83
84 $actnow = time();
85 $forced_reason = '';
86 $forcebooking = VikRequest::getInt('forcebooking', 0, 'request');
87 $pcheckindate = VikRequest::getString('checkindate', '', 'request');
88 $pcheckoutdate = VikRequest::getString('checkoutdate', '', 'request');
89 $pcheckinh = VikRequest::getString('checkinh', '', 'request');
90 $pcheckinm = VikRequest::getString('checkinm', '', 'request');
91 $pcheckouth = VikRequest::getString('checkouth', '', 'request');
92 $pcheckoutm = VikRequest::getString('checkoutm', '', 'request');
93 $pcustdata = VikRequest::getString('custdata', '', 'request');
94 $pcustmail = VikRequest::getString('custmail', '', 'request');
95 $padults = VikRequest::getInt('adults', 0, 'request');
96 $pchildren = VikRequest::getInt('children', 0, 'request');
97 $psetclosed = VikRequest::getInt('setclosed', 0, 'request');
98 $psetunitsclosed = VikRequest::getInt('setunitsclosed', 0, 'request');
99 $num_rooms = VikRequest::getInt('num_rooms', 0, 'request');
100 $num_rooms = empty($num_rooms) || $num_rooms <= 0 ? 1 : $num_rooms;
101 $pordstatus = VikRequest::getString('newstatus', '', 'request');
102 $pordstatus = (empty($pordstatus) || !in_array($pordstatus, array('confirmed', 'standby')) ? 'confirmed' : $pordstatus);
103 $pordstatus = intval($psetclosed) > 0 ? 'confirmed' : $pordstatus;
104 $pcountrycode = VikRequest::getString('countrycode', '', 'request');
105 $pstate = VikRequest::getString('state', '', 'request');
106 $pt_first_name = VikRequest::getString('t_first_name', '', 'request');
107 $pt_last_name = VikRequest::getString('t_last_name', '', 'request');
108 $pphone = VikRequest::getString('phone', '', 'request');
109 $pcustomer_id = VikRequest::getInt('customer_id', 0, 'request');
110 $ppaymentid = VikRequest::getString('payment', '', 'request');
111 $pcust_cost = VikRequest::getFloat('cust_cost', 0, 'request');
112 $proomcost = VikRequest::getFloat('roomcost', 0, 'request');
113 $pidprice = VikRequest::getInt('idprice', 0, 'request');
114 $id_tariff = 0;
115 $ptotalpnight = VikRequest::getString('totalpnight', 'total', 'request');
116 $ptaxid = VikRequest::getInt('taxid', 0, 'request');
117 $pcloseothers = VikRequest::getVar('closeothers', array());
118
119 /**
120 * Mark the units as closed in case of a regular reservation for no customers.
121 *
122 * @since 1.16.6 (J) - 1.6.6 (WP)
123 */
124 if ($psetunitsclosed && ($psetclosed || $pordstatus != 'confirmed' || $pcustomer_id)) {
125 $psetunitsclosed = 0;
126 }
127
128 $paymentmeth = '';
129 if (!empty($ppaymentid) && $payments) {
130 foreach ($payments as $pay) {
131 if (intval($pay['id']) == intval($ppaymentid)) {
132 $paymentmeth = $pay['id'].'='.$pay['name'];
133 break;
134 }
135 }
136 }
137
138 // check if a new booking should be created
139 if (!empty($pcheckindate) && !empty($pcheckoutdate)) {
140 // validate basic information submitted
141 $can_create_res = true;
142 if (!VikBooking::dateIsValid($pcheckindate) || !VikBooking::dateIsValid($pcheckoutdate)) {
143 $can_create_res = false;
144 VikError::raiseWarning('', JText::translate('ERRINVDATESEASON'));
145 }
146
147 // get stay timestamps
148 $first = VikBooking::getDateTimestamp($pcheckindate, $pcheckinh, $pcheckinm);
149 $second = VikBooking::getDateTimestamp($pcheckoutdate, $pcheckouth, $pcheckoutm);
150
151 if ($first >= $second) {
152 $can_create_res = false;
153 VikError::raiseWarning('', 'Invalid Dates: current server time is '.date('Y-m-d H:i', $actnow).'. Reservation requested from '.date('Y-m-d H:i', $first).' to '.date('Y-m-d H:i', $second));
154 }
155
156 // count nights of stay
157 $secdiff = $second - $first;
158 $daysdiff = $secdiff / 86400;
159 if (is_int($daysdiff)) {
160 if ($daysdiff < 1) {
161 $daysdiff = 1;
162 }
163 } else {
164 if ($daysdiff < 1) {
165 $daysdiff = 1;
166 } else {
167 $sum = floor($daysdiff) * 86400;
168 $newdiff = $secdiff - $sum;
169 $maxhmore = VikBooking::getHoursMoreRb() * 3600;
170 if ($maxhmore >= $newdiff) {
171 $daysdiff = floor($daysdiff);
172 } else {
173 $daysdiff = ceil($daysdiff);
174 }
175 }
176 }
177
178 if ($can_create_res) {
179 /**
180 * Get an instance of the reservation model by injecting all values.
181 *
182 * @since 1.16.0 (J) - 1.6.0 (WP)
183 */
184 $model_res = VBOModelReservation::getInstance([
185 'force_booking' => $forcebooking,
186 'split_stay' => $split_stay_data,
187 'set_closed' => $psetclosed,
188 'units_closed' => $psetunitsclosed,
189 'close_others' => $pcloseothers,
190 'status' => $pordstatus,
191 'checkin' => $first,
192 'checkout' => $second,
193 'checkin_h' => $pcheckinh,
194 'checkin_m' => $pcheckinm,
195 'checkout_h' => $pcheckouth,
196 'checkout_m' => $pcheckoutm,
197 'nights' => $daysdiff,
198 'num_rooms' => $num_rooms,
199 'adults' => $padults,
200 'children' => $pchildren,
201 'id_payment' => $paymentmeth,
202 ])->setCustomer([
203 'id' => $pcustomer_id,
204 'first_name' => $pt_first_name,
205 'last_name' => $pt_last_name,
206 'data' => $pcustdata,
207 'email' => $pcustmail,
208 'country' => $pcountrycode,
209 'state' => $pstate,
210 'phone' => $pphone,
211 ])->setRoom([
212 'id' => $room['id'],
213 'cust_cost' => $pcust_cost,
214 'total_or_pnight' => $ptotalpnight,
215 'room_cost' => $proomcost,
216 'id_price' => $pidprice,
217 'id_tax' => $ptaxid,
218 ]);
219
220 // store the reservation
221 $model_res->create();
222
223 // get the new booking ID
224 $res_id = $model_res->getNewBookingID();
225 if (!$res_id) {
226 VikError::raiseWarning('', $model_res->getError());
227 $app->redirect("index.php?option=com_vikbooking&task=calendar");
228 $app->close();
229 }
230
231 // check if any action for the Channel Manager should be displayed
232 $vcm_action = $model_res->getChannelManagerAction();
233 if ($vcm_action) {
234 VikError::raiseNotice('', $vcm_action);
235 }
236
237 if ($pordstatus == 'standby') {
238 // redirect only if the booking status is pending
239 $app->enqueueMessage(JText::translate('VBQUICKRESWARNSTANDBY'));
240 $app->redirect("index.php?option=com_vikbooking&task=editbusy&cid[]=" . $res_id);
241 $app->close();
242 }
243
244 // set new reservation ID
245 $new_res_id = $res_id;
246 }
247 }
248
249 $mints = mktime(0, 0, 0, date('m'), 1, date('Y'));
250 $q = "SELECT `b`.*,`ob`.`idorder`,`o`.`closure` FROM `#__vikbooking_busy` AS `b` LEFT JOIN `#__vikbooking_ordersbusy` `ob` ON `ob`.`idbusy`=`b`.`id` LEFT JOIN `#__vikbooking_orders` `o` ON `o`.`id`=`ob`.`idorder` WHERE `b`.`idroom`=".(int)$room['id']." AND (`b`.`checkin`>=".$mints." OR `b`.`checkout`>=".$mints.") AND `ob`.`idorder` IS NOT NULL;";
251 $dbo->setQuery($q);
252 $busy = $dbo->loadAssocList();
253
254 $this->room = $room;
255 $this->new_res_id = $new_res_id;
256 $this->allc = $allc;
257 $this->payments = $payments;
258 $this->busy = $busy;
259 $this->vmode = $vmode;
260
261 // Display the template
262 parent::display($tpl);
263 }
264
265 /**
266 * Sets the toolbar
267 */
268 protected function addToolBar()
269 {
270 JToolBarHelper::title(JText::translate('VBMAINCALTITLE'), 'vikbooking');
271 JToolBarHelper::cancel( 'canceledorder', JText::translate('VBBACK'));
272 JToolBarHelper::spacer();
273 }
274 }
275