PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.6
VikBooking Hotel Booking Engine & PMS v1.6.6
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.6, at admin/views/calendar/view.html.php

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