| @@ -1,0 +1,75 @@ | ||
| 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 VikbookingViewVikbooking extends JViewVikBooking { | |
| 16 | + function display($tpl = null) { | |
| 17 | + VikBooking::prepareViewContent(); | |
| 18 | + $dbo = JFactory::getDBO(); | |
| 19 | + $session = JFactory::getSession(); | |
| 20 | + //booking modification start | |
| 21 | + $mod_booking = array(); | |
| 22 | + $pmodify_sid = VikRequest::getString('modify_sid', '', 'request'); | |
| 23 | + $pmodify_id = VikRequest::getInt('modify_id', '', 'request'); | |
| 24 | + if (!empty($pmodify_sid) && !empty($pmodify_id)) { | |
| 25 | + $q = "SELECT * FROM `#__vikbooking_orders` WHERE `id`=".intval($pmodify_id)." AND `sid`=".$dbo->quote($pmodify_sid)." AND `status`='confirmed' AND `split_stay`=0;"; | |
| 26 | + $dbo->setQuery($q); | |
| 27 | + $dbo->execute(); | |
| 28 | + if ($dbo->getNumRows() == 1) { | |
| 29 | + $mod_booking = $dbo->loadAssoc(); | |
| 30 | + //check if modification is allowed | |
| 31 | + $days_to_arrival = 0; | |
| 32 | + $now_info = getdate(); | |
| 33 | + $checkin_info = getdate($mod_booking['checkin']); | |
| 34 | + if ($now_info[0] < $checkin_info[0]) { | |
| 35 | + while ($now_info[0] < $checkin_info[0]) { | |
| 36 | + if (!($now_info['mday'] != $checkin_info['mday'] || $now_info['mon'] != $checkin_info['mon'] || $now_info['year'] != $checkin_info['year'])) { | |
| 37 | + break; | |
| 38 | + } | |
| 39 | + $days_to_arrival++; | |
| 40 | + $now_info = getdate(mktime(0, 0, 0, $now_info['mon'], ($now_info['mday'] + 1), $now_info['year'])); | |
| 41 | + } | |
| 42 | + } | |
| 43 | + $resmodcanc = VikBooking::getReservationModCanc(); | |
| 44 | + $resmodcanc = $days_to_arrival < 1 ? 0 : $resmodcanc; | |
| 45 | + $resmodcancmin = VikBooking::getReservationModCancMin(); | |
| 46 | + $mod_allowed = ($resmodcanc > 1 && $resmodcanc != 3 && $days_to_arrival >= $resmodcancmin); | |
| 47 | + if (!$mod_allowed) { | |
| 48 | + VikError::raiseWarning('', JText::translate('VBOERRCANNOTMODBOOK')); | |
| 49 | + $mainframe = JFactory::getApplication(); | |
| 50 | + $mainframe->redirect(JRoute::rewrite("index.php?option=com_vikbooking&view=booking&sid=".$mod_booking['sid']."&ts=".$mod_booking['ts'], false)); | |
| 51 | + exit; | |
| 52 | + } | |
| 53 | + //start session for modifying the booking | |
| 54 | + $session->set('vboModBooking', $mod_booking); | |
| 55 | + } | |
| 56 | + } else { | |
| 57 | + //check if a booking modification was previously stored in the session (and not unset) to re-start it | |
| 58 | + $cur_mod = $session->get('vboModBooking', ''); | |
| 59 | + if (is_array($cur_mod) && count($cur_mod)) { | |
| 60 | + $mod_booking = $cur_mod; | |
| 61 | + } | |
| 62 | + } | |
| 63 | + $this->mod_booking = $mod_booking; | |
| 64 | + //theme | |
| 65 | + $theme = VikBooking::getTheme(); | |
| 66 | + if ($theme != 'default') { | |
| 67 | + $thdir = VBO_SITE_PATH.DS.'themes'.DS.$theme.DS.'vikbooking'; | |
| 68 | + if (is_dir($thdir)) { | |
| 69 | + $this->_setPath('template', $thdir.DS); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + // | |
| 73 | + parent::display($tpl); | |
| 74 | + } | |
| 75 | +} | |