PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
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 / site / views / promotions / view.html.php

view.html.php in VikBooking Hotel Booking Engine & PMS 1.8.16, at site/views/promotions/view.html.php

168 lines 5.7 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 jimport('joomla.application.component.view');
14
15 class VikbookingViewPromotions extends JViewVikBooking {
16 function display($tpl = null) {
17 VikBooking::prepareViewContent();
18 $dbo = JFactory::getDBO();
19 $vbo_tn = VikBooking::getTranslator();
20 $pshowrooms = VikRequest::getInt('showrooms', 1, 'request');
21 $pshowrooms = $pshowrooms == 1 ? 1 : 0;
22 $pmaxdate = VikRequest::getInt('maxdate', 6, 'request');
23 $plim = VikRequest::getInt('lim', 10, 'request');
24 $promotions = array();
25 $rooms = array();
26 $ind = 0;
27 $q = "SELECT * FROM `#__vikbooking_seasons` WHERE `promo`=1";
28 $dbo->setQuery($q, 0, $plim);
29 $all_promotions = $dbo->loadAssocList();
30 if ($all_promotions) {
31 $vbo_tn->translateContents($all_promotions, '#__vikbooking_seasons');
32 $base_year = (int)date('Y');
33 $base_ts = time();
34 $base_month = (int)date('n');
35 foreach ($all_promotions as $k => $promo) {
36 $promo_year = !empty($promo['year']) && $promo['year'] > 0 ? $promo['year'] : $base_year;
37 $promo_from_ts = ((int)mktime(0, 0, 0, 1, 1, $promo_year)) + $promo['from'];
38 $promo_to_ts = ((int)mktime(0, 0, 0, 1, 1, $promo_year)) + $promo['to'];
39 if ($promo_year % 4 == 0 && ($promo_year % 100 != 0 || $promo_year % 400 == 0)) {
40 //leap year
41 $leapts = mktime(0, 0, 0, 2, 29, $promo_year);
42 if ($promo_from_ts >= $leapts) {
43 $promo_from_ts += 86400;
44 }
45 }
46 if ($base_ts > $promo_from_ts && $base_ts > $promo_to_ts) {
47 if (empty($promo['year'])) {
48 $promo_year++;
49 $promo_from_ts = ((int)mktime(0, 0, 0, 1, 1, $promo_year)) + $promo['from'];
50 if ($promo_year % 4 == 0 && ($promo_year % 100 != 0 || $promo_year % 400 == 0)) {
51 //leap year
52 $leapts = mktime(0, 0, 0, 2, 29, $promo_year);
53 if ($promo_from_ts >= $leapts) {
54 $promo_from_ts += 86400;
55 }
56 }
57 } else {
58 //Start ts is in the past, not tied to the year, check if season end ts is in the future
59 $check_promo_to_ts = ((int)mktime(0, 0, 0, 1, 1, ($promo['from'] > $promo['to'] ? ($promo_year + 1) : $promo_year))) + $promo['to'];
60 if ($base_ts > $check_promo_to_ts) {
61 continue;
62 }
63 }
64 }
65 if ($promo['from'] > $promo['to']) {
66 $promo_year++;
67 }
68 $promo_to_ts = ((int)mktime(0, 0, 0, 1, 1, $promo_year)) + $promo['to'];
69 if ($promo_year % 4 == 0 && ($promo_year % 100 != 0 || $promo_year % 400 == 0)) {
70 //leap year
71 $leapts = mktime(0, 0, 0, 2, 29, $promo_year);
72 if ($promo_to_ts >= $leapts) {
73 $promo_to_ts += 86400;
74 }
75 }
76 if ($promo_from_ts < $promo_to_ts) {
77 //Begin: Check Max Date in the Future (Months)
78 $promo_from_month = (int)date('n', $promo_from_ts);
79 $promo_from_year = (int)date('Y', $promo_from_ts);
80 if ($base_year == $promo_from_year) {
81 //Same Year
82 $months_diff = $promo_from_month - $base_month;
83 if ($months_diff > $pmaxdate) {
84 continue;
85 }
86 } else {
87 //Different Year
88 $promo_from_month += 12 * ($promo_from_year - $base_year);
89 $months_diff = $promo_from_month - $base_month;
90 if ($months_diff > $pmaxdate) {
91 continue;
92 }
93 }
94 //End: Check Max Date in the Future (Months)
95 $promotions[$ind] = $all_promotions[$k];
96 $promotions[$ind]['promo_from_ts'] = $promo_from_ts;
97 $promotions[$ind]['promo_to_ts'] = $promo_to_ts;
98 $promotions[$ind]['promo_valid_ts'] = $promo_from_ts;
99 //set valid until to end ts in case of 0 days in advance
100 if (empty($promo['promodaysadv']) || !($promo['promodaysadv'] > 0)) {
101 $promotions[$ind]['promo_valid_ts'] = $promo_to_ts;
102 } elseif (!empty($promo['promodaysadv']) && $promo['promodaysadv'] > 0) {
103 $dst_from_ts = date('I', $promo_from_ts);
104 $valid_ts = $promo_from_ts - (86400 * $promo['promodaysadv']);
105 $dst_valid_ts = date('I', $valid_ts);
106 if ($dst_from_ts != $dst_valid_ts) {
107 if ($dst_valid_ts) {
108 $valid_ts -= 3600;
109 } else {
110 $valid_ts += 3600;
111 }
112 }
113 $promotions[$ind]['promo_valid_ts'] = $valid_ts;
114 }
115 $ind++;
116 }
117 }
118 if (count($promotions) > 0) {
119 $promo_map = array();
120 $sorted = array();
121 $promos_rooms = array();
122 foreach ($promotions as $k => $v) {
123 $promo_map[$k] = $v['promo_from_ts'];
124 $allrooms = explode(",", $v['idrooms']);
125 foreach ($allrooms as $idroom) {
126 $idroom = intval(str_replace("-", "", trim($idroom)));
127 if ($idroom > 0) {
128 $promos_rooms[$idroom] = $idroom;
129 }
130 }
131 }
132 asort($promo_map);
133 foreach ($promo_map as $k => $v) {
134 $sorted[$k] = $promotions[$k];
135 }
136 $promotions = $sorted;
137 if (count($promos_rooms) > 0) {
138 $q = "SELECT * FROM `#__vikbooking_rooms` WHERE `id` IN(".implode(",", $promos_rooms).") ORDER BY `#__vikbooking_rooms`.`name` ASC;";
139 $dbo->setQuery($q);
140 $dbo->execute();
141 if ($dbo->getNumRows() > 0) {
142 $fetch_rooms = $dbo->loadAssocList();
143 $vbo_tn->translateContents($fetch_rooms, '#__vikbooking_rooms');
144 foreach ($fetch_rooms as $v) {
145 $rooms[$v['id']] = $v;
146 }
147 }
148 }
149 }
150 }
151
152 $this->promotions = $promotions;
153 $this->rooms = $rooms;
154 $this->showrooms = $pshowrooms;
155 $this->vbo_tn = $vbo_tn;
156 //theme
157 $theme = VikBooking::getTheme();
158 if ($theme != 'default') {
159 $thdir = VBO_SITE_PATH.DS.'themes'.DS.$theme.DS.'promotions';
160 if (is_dir($thdir)) {
161 $this->_setPath('template', $thdir.DS);
162 }
163 }
164 //
165 parent :: display($tpl);
166 }
167 }
168