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

260 lines 8.9 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 $num_rooms = VikRequest::getInt('num_rooms', 0, 'request');
95 $num_rooms = empty($num_rooms) || $num_rooms <= 0 ? 1 : $num_rooms;
96 $pordstatus = VikRequest::getString('newstatus', '', 'request');
97 $pordstatus = (empty($pordstatus) || !in_array($pordstatus, array('confirmed', 'standby')) ? 'confirmed' : $pordstatus);
98 $pordstatus = intval($psetclosed) > 0 ? 'confirmed' : $pordstatus;
99 $pcountrycode = VikRequest::getString('countrycode', '', 'request');
100 $pstate = VikRequest::getString('state', '', 'request');
101 $pt_first_name = VikRequest::getString('t_first_name', '', 'request');
102 $pt_last_name = VikRequest::getString('t_last_name', '', 'request');
103 $pphone = VikRequest::getString('phone', '', 'request');
104 $pcustomer_id = VikRequest::getInt('customer_id', 0, 'request');
105 $ppaymentid = VikRequest::getString('payment', '', 'request');
106 $pcust_cost = VikRequest::getFloat('cust_cost', 0, 'request');
107 $proomcost = VikRequest::getFloat('roomcost', 0, 'request');
108 $pidprice = VikRequest::getInt('idprice', 0, 'request');
109 $id_tariff = 0;
110 $ptotalpnight = VikRequest::getString('totalpnight', 'total', 'request');
111 $ptaxid = VikRequest::getInt('taxid', 0, 'request');
112 $pcloseothers = VikRequest::getVar('closeothers', array());
113
114 $paymentmeth = '';
115 if (!empty($ppaymentid) && $payments) {
116 foreach ($payments as $pay) {
117 if (intval($pay['id']) == intval($ppaymentid)) {
118 $paymentmeth = $pay['id'].'='.$pay['name'];
119 break;
120 }
121 }
122 }
123
124 // check if a new booking should be created
125 if (!empty($pcheckindate) && !empty($pcheckoutdate)) {
126 // validate basic information submitted
127 $can_create_res = true;
128 if (!VikBooking::dateIsValid($pcheckindate) || !VikBooking::dateIsValid($pcheckoutdate)) {
129 $can_create_res = false;
130 VikError::raiseWarning('', JText::translate('ERRINVDATESEASON'));
131 }
132
133 // get stay timestamps
134 $first = VikBooking::getDateTimestamp($pcheckindate, $pcheckinh, $pcheckinm);
135 $second = VikBooking::getDateTimestamp($pcheckoutdate, $pcheckouth, $pcheckoutm);
136
137 if ($first >= $second) {
138 $can_create_res = false;
139 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));
140 }
141
142 // count nights of stay
143 $secdiff = $second - $first;
144 $daysdiff = $secdiff / 86400;
145 if (is_int($daysdiff)) {
146 if ($daysdiff < 1) {
147 $daysdiff = 1;
148 }
149 } else {
150 if ($daysdiff < 1) {
151 $daysdiff = 1;
152 } else {
153 $sum = floor($daysdiff) * 86400;
154 $newdiff = $secdiff - $sum;
155 $maxhmore = VikBooking::getHoursMoreRb() * 3600;
156 if ($maxhmore >= $newdiff) {
157 $daysdiff = floor($daysdiff);
158 } else {
159 $daysdiff = ceil($daysdiff);
160 }
161 }
162 }
163
164 if ($can_create_res) {
165 /**
166 * Get an instance of the reservation model by injecting all values.
167 *
168 * @since 1.16.0 (J) - 1.6.0 (WP)
169 */
170 $model_res = VBOModelReservation::getInstance([
171 'force_booking' => $forcebooking,
172 'split_stay' => $split_stay_data,
173 'set_closed' => $psetclosed,
174 'close_others' => $pcloseothers,
175 'status' => $pordstatus,
176 'checkin' => $first,
177 'checkout' => $second,
178 'checkin_h' => $pcheckinh,
179 'checkin_m' => $pcheckinm,
180 'checkout_h' => $pcheckouth,
181 'checkout_m' => $pcheckoutm,
182 'nights' => $daysdiff,
183 'num_rooms' => $num_rooms,
184 'adults' => $padults,
185 'children' => $pchildren,
186 'id_payment' => $paymentmeth,
187 ])->setCustomer([
188 'id' => $pcustomer_id,
189 'first_name' => $pt_first_name,
190 'last_name' => $pt_last_name,
191 'data' => $pcustdata,
192 'email' => $pcustmail,
193 'country' => $pcountrycode,
194 'state' => $pstate,
195 'phone' => $pphone,
196 ])->setRoom([
197 'id' => $room['id'],
198 'cust_cost' => $pcust_cost,
199 'total_or_pnight' => $ptotalpnight,
200 'room_cost' => $proomcost,
201 'id_price' => $pidprice,
202 'id_tax' => $ptaxid,
203 ]);
204
205 // store the reservation
206 $model_res->create();
207
208 // get the new booking ID
209 $res_id = $model_res->getNewBookingID();
210 if (!$res_id) {
211 VikError::raiseWarning('', $model_res->getError());
212 $app->redirect("index.php?option=com_vikbooking&task=calendar");
213 $app->close();
214 }
215
216 if ($pordstatus == 'standby') {
217 // redirect only if the booking status is pending
218 $app->enqueueMessage(JText::translate('VBQUICKRESWARNSTANDBY'));
219 $app->redirect("index.php?option=com_vikbooking&task=editbusy&cid[]=" . $res_id);
220 $app->close();
221 }
222
223 // check if any action for the Channel Manager should be displayed
224 $vcm_action = $model_res->getChannelManagerAction();
225 if ($vcm_action) {
226 VikError::raiseNotice('', $vcm_action);
227 }
228
229 // set new reservation ID
230 $new_res_id = $res_id;
231 }
232 }
233
234 $mints = mktime(0, 0, 0, date('m'), 1, date('Y'));
235 $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;";
236 $dbo->setQuery($q);
237 $busy = $dbo->loadAssocList();
238
239 $this->room = $room;
240 $this->new_res_id = $new_res_id;
241 $this->allc = $allc;
242 $this->payments = $payments;
243 $this->busy = $busy;
244 $this->vmode = $vmode;
245
246 // Display the template
247 parent::display($tpl);
248 }
249
250 /**
251 * Sets the toolbar
252 */
253 protected function addToolBar()
254 {
255 JToolBarHelper::title(JText::translate('VBMAINCALTITLE'), 'vikbooking');
256 JToolBarHelper::cancel( 'canceledorder', JText::translate('VBBACK'));
257 JToolBarHelper::spacer();
258 }
259 }
260