| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikRentCar |
| 4 |
* @subpackage com_vikrentcar |
| 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 controller library |
| 14 |
jimport('joomla.application.component.controller'); |
| 15 |
|
| 16 |
class VikRentCarController extends JControllerVikRentCar |
| 17 |
{ |
| 18 |
/** |
| 19 |
* Default controller's method when no task is defined, |
| 20 |
* or no method exists for that task. If a View is requested. |
| 21 |
* attempts to set it, otherwise sets the default View. |
| 22 |
*/ |
| 23 |
public function display($cachable = false, $urlparams = array()) { |
| 24 |
|
| 25 |
$view = VikRequest::getVar('view', ''); |
| 26 |
$header_val = ''; |
| 27 |
|
| 28 |
if (!empty($view)) { |
| 29 |
$header_val = $view; |
| 30 |
VikRequest::setVar('view', $view); |
| 31 |
} else { |
| 32 |
$header_val = '18'; |
| 33 |
VikRequest::setVar('view', 'dashboard'); |
| 34 |
} |
| 35 |
|
| 36 |
$hide_menu = JFactory::getApplication()->input->getBool('hide_menu', false); |
| 37 |
|
| 38 |
if ($hide_menu === false) { |
| 39 |
VikRentCarHelper::printHeader($header_val); |
| 40 |
} |
| 41 |
|
| 42 |
parent::display(); |
| 43 |
|
| 44 |
if (VikRentCar::showFooter() && $hide_menu === false) { |
| 45 |
VikRentCarHelper::printFooter(); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
public function places() { |
| 50 |
VikRentCarHelper::printHeader("3"); |
| 51 |
|
| 52 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'places')); |
| 53 |
|
| 54 |
parent::display(); |
| 55 |
|
| 56 |
if (VikRentCar::showFooter()) { |
| 57 |
VikRentCarHelper::printFooter(); |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
public function newplace() { |
| 62 |
VikRentCarHelper::printHeader("3"); |
| 63 |
|
| 64 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageplace')); |
| 65 |
|
| 66 |
parent::display(); |
| 67 |
|
| 68 |
if (VikRentCar::showFooter()) { |
| 69 |
VikRentCarHelper::printFooter(); |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
public function editplace() { |
| 74 |
VikRentCarHelper::printHeader("3"); |
| 75 |
|
| 76 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageplace')); |
| 77 |
|
| 78 |
parent::display(); |
| 79 |
|
| 80 |
if (VikRentCar::showFooter()) { |
| 81 |
VikRentCarHelper::printFooter(); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public function createplace() { |
| 86 |
if (!JSession::checkToken()) { |
| 87 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 88 |
} |
| 89 |
$dbo = JFactory::getDbo(); |
| 90 |
$app = JFactory::getApplication(); |
| 91 |
|
| 92 |
$pname = VikRequest::getString('placename', '', 'request'); |
| 93 |
$paddress = VikRequest::getString('address', '', 'request'); |
| 94 |
$plat = VikRequest::getString('lat', '', 'request'); |
| 95 |
$plng = VikRequest::getString('lng', '', 'request'); |
| 96 |
$ppraliq = VikRequest::getString('praliq', '', 'request'); |
| 97 |
$pdescr = VikRequest::getString('descr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 98 |
$popentimefh = VikRequest::getString('opentimefh', '', 'request'); |
| 99 |
$popentimefm = VikRequest::getInt('opentimefm', '', 'request'); |
| 100 |
$popentimeth = VikRequest::getString('opentimeth', '', 'request'); |
| 101 |
$popentimetm = VikRequest::getInt('opentimetm', '', 'request'); |
| 102 |
$pclosingdays = VikRequest::getString('closingdays', '', 'request'); |
| 103 |
$psuggopentimeh = VikRequest::getInt('suggopentimeh', '', 'request'); |
| 104 |
$pwopeningfh = VikRequest::getVar('wopeningfh', []); |
| 105 |
$pwopeningfm = VikRequest::getVar('wopeningfm', []); |
| 106 |
$pwopeningth = VikRequest::getVar('wopeningth', []); |
| 107 |
$pwopeningtm = VikRequest::getVar('wopeningtm', []); |
| 108 |
$pwbreakingfh = VikRequest::getVar('wbreakingfh', []); |
| 109 |
$pwbreakingfm = VikRequest::getVar('wbreakingfm', []); |
| 110 |
$pwbreakingth = VikRequest::getVar('wbreakingth', []); |
| 111 |
$pwbreakingtm = VikRequest::getVar('wbreakingtm', []); |
| 112 |
$pcombomap = VikRequest::getVar('combomap', []); |
| 113 |
$opentime = ""; |
| 114 |
$suggopentimeh = !empty($psuggopentimeh) ? ($psuggopentimeh * 3600) : ''; |
| 115 |
if (strlen($popentimefh) > 0 && strlen($popentimeth) > 0) { |
| 116 |
$openingh = $popentimefh * 3600; |
| 117 |
$openingm = $popentimefm * 60; |
| 118 |
$openingts = $openingh + $openingm; |
| 119 |
$closingh = $popentimeth * 3600; |
| 120 |
$closingm = $popentimetm * 60; |
| 121 |
$closingts = $closingh + $closingm; |
| 122 |
if ($closingts > $openingts || $openingts > $closingts) { |
| 123 |
$opentime = $openingts."-".$closingts; |
| 124 |
} |
| 125 |
} |
| 126 |
if (!empty($pname)) { |
| 127 |
$q = "SELECT `ordering` FROM `#__vikrentcar_places` ORDER BY `#__vikrentcar_places`.`ordering` DESC LIMIT 1;"; |
| 128 |
$dbo->setQuery($q); |
| 129 |
$dbo->execute(); |
| 130 |
if ($dbo->getNumRows() == 1) { |
| 131 |
$getlast = $dbo->loadResult(); |
| 132 |
$newsortnum = $getlast + 1; |
| 133 |
} else { |
| 134 |
$newsortnum = 1; |
| 135 |
} |
| 136 |
|
| 137 |
// VRC 1.12 - override opening time |
| 138 |
$wopening = []; |
| 139 |
foreach ($pwopeningfh as $d_ind => $fh) { |
| 140 |
if (!strlen($fh) || isset($wopening[$d_ind]) || $d_ind > 6 || !isset($pwopeningth[$d_ind]) || !strlen($pwopeningth[$d_ind])) { |
| 141 |
continue; |
| 142 |
} |
| 143 |
$wopening[$d_ind] = [ |
| 144 |
'fh' => (int)$fh, |
| 145 |
'fm' => (int)$pwopeningfm[$d_ind], |
| 146 |
'th' => (int)$pwopeningth[$d_ind], |
| 147 |
'tm' => (int)$pwopeningtm[$d_ind], |
| 148 |
]; |
| 149 |
/** |
| 150 |
* We allow breaks between the opening times. |
| 151 |
* |
| 152 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 153 |
*/ |
| 154 |
$breaks = []; |
| 155 |
if (!empty($pwbreakingfh[$d_ind])) { |
| 156 |
foreach ($pwbreakingfh[$d_ind] as $bk => $break_fh) { |
| 157 |
if (!strlen($break_fh) || !isset($pwbreakingth[$d_ind]) || !isset($pwbreakingth[$d_ind][$bk]) || !strlen($pwbreakingth[$d_ind][$bk])) { |
| 158 |
continue; |
| 159 |
} |
| 160 |
// push break |
| 161 |
$breaks[] = [ |
| 162 |
'fh' => (int)$break_fh, |
| 163 |
'fm' => (int)$pwbreakingfm[$d_ind][$bk], |
| 164 |
'th' => (int)$pwbreakingth[$d_ind][$bk], |
| 165 |
'tm' => (int)$pwbreakingtm[$d_ind][$bk], |
| 166 |
]; |
| 167 |
} |
| 168 |
} |
| 169 |
if (count($breaks)) { |
| 170 |
// push week-day breaks |
| 171 |
$wopening[$d_ind]['breaks'] = $breaks; |
| 172 |
} |
| 173 |
} |
| 174 |
|
| 175 |
$combomap = []; |
| 176 |
if ($pcombomap) { |
| 177 |
$combomap = array_map('intval', $pcombomap); |
| 178 |
} |
| 179 |
|
| 180 |
$q = "INSERT INTO `#__vikrentcar_places` (`name`,`lat`,`lng`,`descr`,`opentime`,`closingdays`,`idiva`,`defaulttime`,`ordering`,`address`,`wopening`,`combomap`) VALUES(".$dbo->quote($pname).", ".$dbo->quote($plat).", ".$dbo->quote($plng).", ".$dbo->quote($pdescr).", '".$opentime."', ".$dbo->quote($pclosingdays).", ".(!empty($ppraliq) ? intval($ppraliq) : "NULL").", ".(!empty($suggopentimeh) ? "'".$suggopentimeh."'" : "NULL").", ".$newsortnum.", ".$dbo->quote($paddress).", ".$dbo->quote(json_encode($wopening)).", ".$dbo->quote(json_encode($combomap)).");"; |
| 181 |
$dbo->setQuery($q); |
| 182 |
$dbo->execute(); |
| 183 |
$app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS')); |
| 184 |
} |
| 185 |
$app->redirect("index.php?option=com_vikrentcar&task=places"); |
| 186 |
} |
| 187 |
|
| 188 |
public function updateplace() |
| 189 |
{ |
| 190 |
if (!JSession::checkToken()) { |
| 191 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 192 |
} |
| 193 |
$this->do_updateplace(); |
| 194 |
} |
| 195 |
|
| 196 |
public function updateplaceapply() |
| 197 |
{ |
| 198 |
if (!JSession::checkToken()) { |
| 199 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 200 |
} |
| 201 |
$this->do_updateplace(true); |
| 202 |
} |
| 203 |
|
| 204 |
protected function do_updateplace($remain = false) |
| 205 |
{ |
| 206 |
$dbo = JFactory::getDbo(); |
| 207 |
$app = JFactory::getApplication(); |
| 208 |
|
| 209 |
$pname = VikRequest::getString('placename', '', 'request'); |
| 210 |
$paddress = VikRequest::getString('address', '', 'request'); |
| 211 |
$plat = VikRequest::getString('lat', '', 'request'); |
| 212 |
$plng = VikRequest::getString('lng', '', 'request'); |
| 213 |
$ppraliq = VikRequest::getString('praliq', '', 'request'); |
| 214 |
$pdescr = VikRequest::getString('descr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 215 |
$pwhereup = VikRequest::getInt('whereup', 0, 'request'); |
| 216 |
$popentimefh = VikRequest::getString('opentimefh', '', 'request'); |
| 217 |
$popentimefm = VikRequest::getInt('opentimefm', '', 'request'); |
| 218 |
$popentimeth = VikRequest::getString('opentimeth', '', 'request'); |
| 219 |
$popentimetm = VikRequest::getInt('opentimetm', '', 'request'); |
| 220 |
$pclosingdays = VikRequest::getString('closingdays', '', 'request'); |
| 221 |
$psuggopentimeh = VikRequest::getInt('suggopentimeh', '', 'request'); |
| 222 |
$pwopeningfh = VikRequest::getVar('wopeningfh', []); |
| 223 |
$pwopeningfm = VikRequest::getVar('wopeningfm', []); |
| 224 |
$pwopeningth = VikRequest::getVar('wopeningth', []); |
| 225 |
$pwopeningtm = VikRequest::getVar('wopeningtm', []); |
| 226 |
$pwbreakingfh = VikRequest::getVar('wbreakingfh', []); |
| 227 |
$pwbreakingfm = VikRequest::getVar('wbreakingfm', []); |
| 228 |
$pwbreakingth = VikRequest::getVar('wbreakingth', []); |
| 229 |
$pwbreakingtm = VikRequest::getVar('wbreakingtm', []); |
| 230 |
$pcombomap = VikRequest::getVar('combomap', []); |
| 231 |
$opentime = ""; |
| 232 |
$suggopentimeh = !empty($psuggopentimeh) ? ($psuggopentimeh * 3600) : ''; |
| 233 |
if (strlen($popentimefh) > 0 && strlen($popentimeth) > 0) { |
| 234 |
$openingh = $popentimefh * 3600; |
| 235 |
$openingm = $popentimefm * 60; |
| 236 |
$openingts = $openingh + $openingm; |
| 237 |
$closingh = $popentimeth * 3600; |
| 238 |
$closingm = $popentimetm * 60; |
| 239 |
$closingts = $closingh + $closingm; |
| 240 |
if ($closingts > $openingts || $openingts > $closingts) { |
| 241 |
$opentime = $openingts."-".$closingts; |
| 242 |
} |
| 243 |
} |
| 244 |
if (!empty($pname)) { |
| 245 |
|
| 246 |
// VRC 1.12 - override opening time |
| 247 |
$wopening = []; |
| 248 |
foreach ($pwopeningfh as $d_ind => $fh) { |
| 249 |
if (!strlen($fh) || isset($wopening[$d_ind]) || $d_ind > 6 || !isset($pwopeningth[$d_ind]) || !strlen($pwopeningth[$d_ind])) { |
| 250 |
continue; |
| 251 |
} |
| 252 |
$wopening[$d_ind] = [ |
| 253 |
'fh' => (int)$fh, |
| 254 |
'fm' => (int)$pwopeningfm[$d_ind], |
| 255 |
'th' => (int)$pwopeningth[$d_ind], |
| 256 |
'tm' => (int)$pwopeningtm[$d_ind], |
| 257 |
]; |
| 258 |
/** |
| 259 |
* We allow breaks between the opening times. |
| 260 |
* |
| 261 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 262 |
*/ |
| 263 |
$breaks = []; |
| 264 |
if (!empty($pwbreakingfh[$d_ind])) { |
| 265 |
foreach ($pwbreakingfh[$d_ind] as $bk => $break_fh) { |
| 266 |
if (!strlen($break_fh) || !isset($pwbreakingth[$d_ind]) || !isset($pwbreakingth[$d_ind][$bk]) || !strlen($pwbreakingth[$d_ind][$bk])) { |
| 267 |
continue; |
| 268 |
} |
| 269 |
// push break |
| 270 |
$breaks[] = [ |
| 271 |
'fh' => (int)$break_fh, |
| 272 |
'fm' => (int)$pwbreakingfm[$d_ind][$bk], |
| 273 |
'th' => (int)$pwbreakingth[$d_ind][$bk], |
| 274 |
'tm' => (int)$pwbreakingtm[$d_ind][$bk], |
| 275 |
]; |
| 276 |
} |
| 277 |
} |
| 278 |
if (count($breaks)) { |
| 279 |
// push week-day breaks |
| 280 |
$wopening[$d_ind]['breaks'] = $breaks; |
| 281 |
} |
| 282 |
} |
| 283 |
|
| 284 |
$combomap = []; |
| 285 |
if ($pcombomap) { |
| 286 |
$combomap = array_map('intval', $pcombomap); |
| 287 |
} |
| 288 |
|
| 289 |
$q = "UPDATE `#__vikrentcar_places` SET `name`=".$dbo->quote($pname).",`lat`=".$dbo->quote($plat).",`lng`=".$dbo->quote($plng).",`descr`=".$dbo->quote($pdescr).",`opentime`='".$opentime."',`closingdays`=".$dbo->quote($pclosingdays).",`idiva`=".(!empty($ppraliq) ? intval($ppraliq) : "NULL").",`defaulttime`=".(!empty($suggopentimeh) ? "'".$suggopentimeh."'" : "NULL").",`address`=".$dbo->quote($paddress).",`wopening`=".$dbo->quote(json_encode($wopening)).",`combomap`=".$dbo->quote(json_encode($combomap))." WHERE `id`=".$dbo->quote($pwhereup).";"; |
| 290 |
$dbo->setQuery($q); |
| 291 |
$dbo->execute(); |
| 292 |
$app->enqueueMessage(JText::translate('JLIB_APPLICATION_SAVE_SUCCESS')); |
| 293 |
} |
| 294 |
|
| 295 |
if ($remain === true) { |
| 296 |
$app->redirect("index.php?option=com_vikrentcar&task=editplace&cid[]=" . $pwhereup); |
| 297 |
exit; |
| 298 |
} |
| 299 |
$app->redirect("index.php?option=com_vikrentcar&task=places"); |
| 300 |
} |
| 301 |
|
| 302 |
public function removeplace() { |
| 303 |
if (!JSession::checkToken()) { |
| 304 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 305 |
} |
| 306 |
$ids = VikRequest::getVar('cid', array(0)); |
| 307 |
if (@count($ids)) { |
| 308 |
$dbo = JFactory::getDbo(); |
| 309 |
foreach ($ids as $d) { |
| 310 |
$q = "DELETE FROM `#__vikrentcar_places` WHERE `id`=".$dbo->quote($d).";"; |
| 311 |
$dbo->setQuery($q); |
| 312 |
$dbo->execute(); |
| 313 |
} |
| 314 |
} |
| 315 |
$mainframe = JFactory::getApplication(); |
| 316 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=places"); |
| 317 |
} |
| 318 |
|
| 319 |
public function cancelplace() { |
| 320 |
$mainframe = JFactory::getApplication(); |
| 321 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=places"); |
| 322 |
} |
| 323 |
|
| 324 |
public function iva() { |
| 325 |
VikRentCarHelper::printHeader("2"); |
| 326 |
|
| 327 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'iva')); |
| 328 |
|
| 329 |
parent::display(); |
| 330 |
|
| 331 |
if (VikRentCar::showFooter()) { |
| 332 |
VikRentCarHelper::printFooter(); |
| 333 |
} |
| 334 |
} |
| 335 |
|
| 336 |
public function newiva() { |
| 337 |
VikRentCarHelper::printHeader("2"); |
| 338 |
|
| 339 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageiva')); |
| 340 |
|
| 341 |
parent::display(); |
| 342 |
|
| 343 |
if (VikRentCar::showFooter()) { |
| 344 |
VikRentCarHelper::printFooter(); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
public function editiva() { |
| 349 |
VikRentCarHelper::printHeader("2"); |
| 350 |
|
| 351 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageiva')); |
| 352 |
|
| 353 |
parent::display(); |
| 354 |
|
| 355 |
if (VikRentCar::showFooter()) { |
| 356 |
VikRentCarHelper::printFooter(); |
| 357 |
} |
| 358 |
} |
| 359 |
|
| 360 |
public function createiva() { |
| 361 |
if (!JSession::checkToken()) { |
| 362 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 363 |
} |
| 364 |
$paliqname = VikRequest::getString('aliqname', '', 'request'); |
| 365 |
$paliqperc = VikRequest::getString('aliqperc', '', 'request'); |
| 366 |
if (!empty($paliqperc)) { |
| 367 |
$dbo = JFactory::getDbo(); |
| 368 |
$q = "INSERT INTO `#__vikrentcar_iva` (`name`,`aliq`) VALUES(".$dbo->quote($paliqname).", ".floatval($paliqperc).");"; |
| 369 |
$dbo->setQuery($q); |
| 370 |
$dbo->execute(); |
| 371 |
} |
| 372 |
$mainframe = JFactory::getApplication(); |
| 373 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=iva"); |
| 374 |
} |
| 375 |
|
| 376 |
public function updateiva() { |
| 377 |
if (!JSession::checkToken()) { |
| 378 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 379 |
} |
| 380 |
$paliqname = VikRequest::getString('aliqname', '', 'request'); |
| 381 |
$paliqperc = VikRequest::getString('aliqperc', '', 'request'); |
| 382 |
$pwhereup = VikRequest::getString('whereup', '', 'request'); |
| 383 |
if (!empty($paliqperc)) { |
| 384 |
$dbo = JFactory::getDbo(); |
| 385 |
$q = "UPDATE `#__vikrentcar_iva` SET `name`=".$dbo->quote($paliqname).",`aliq`=".floatval($paliqperc)." WHERE `id`=".intval($pwhereup).";"; |
| 386 |
$dbo->setQuery($q); |
| 387 |
$dbo->execute(); |
| 388 |
} |
| 389 |
$mainframe = JFactory::getApplication(); |
| 390 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=iva"); |
| 391 |
} |
| 392 |
|
| 393 |
public function removeiva() { |
| 394 |
if (!JSession::checkToken()) { |
| 395 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 396 |
} |
| 397 |
$ids = VikRequest::getVar('cid', array(0)); |
| 398 |
if (@count($ids)) { |
| 399 |
$dbo = JFactory::getDbo(); |
| 400 |
foreach ($ids as $d) { |
| 401 |
$q = "DELETE FROM `#__vikrentcar_iva` WHERE `id`=".$dbo->quote($d).";"; |
| 402 |
$dbo->setQuery($q); |
| 403 |
$dbo->execute(); |
| 404 |
} |
| 405 |
} |
| 406 |
$mainframe = JFactory::getApplication(); |
| 407 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=iva"); |
| 408 |
} |
| 409 |
|
| 410 |
public function canceliva() { |
| 411 |
$mainframe = JFactory::getApplication(); |
| 412 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=iva"); |
| 413 |
} |
| 414 |
|
| 415 |
public function prices() { |
| 416 |
VikRentCarHelper::printHeader("1"); |
| 417 |
|
| 418 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'prices')); |
| 419 |
|
| 420 |
parent::display(); |
| 421 |
|
| 422 |
if (VikRentCar::showFooter()) { |
| 423 |
VikRentCarHelper::printFooter(); |
| 424 |
} |
| 425 |
} |
| 426 |
|
| 427 |
public function newprice() { |
| 428 |
VikRentCarHelper::printHeader("1"); |
| 429 |
|
| 430 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageprice')); |
| 431 |
|
| 432 |
parent::display(); |
| 433 |
|
| 434 |
if (VikRentCar::showFooter()) { |
| 435 |
VikRentCarHelper::printFooter(); |
| 436 |
} |
| 437 |
} |
| 438 |
|
| 439 |
public function editprice() { |
| 440 |
VikRentCarHelper::printHeader("1"); |
| 441 |
|
| 442 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageprice')); |
| 443 |
|
| 444 |
parent::display(); |
| 445 |
|
| 446 |
if (VikRentCar::showFooter()) { |
| 447 |
VikRentCarHelper::printFooter(); |
| 448 |
} |
| 449 |
} |
| 450 |
|
| 451 |
public function createprice() { |
| 452 |
if (!JSession::checkToken()) { |
| 453 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 454 |
} |
| 455 |
$pprice = VikRequest::getString('price', '', 'request'); |
| 456 |
$pattr = VikRequest::getString('attr', '', 'request'); |
| 457 |
$ppraliq = VikRequest::getString('praliq', '', 'request'); |
| 458 |
if (!empty($pprice)) { |
| 459 |
$dbo = JFactory::getDbo(); |
| 460 |
$q = "INSERT INTO `#__vikrentcar_prices` (`name`,`attr`,`idiva`) VALUES(".$dbo->quote($pprice).", ".$dbo->quote($pattr).", ".(!empty($ppraliq) ? intval($ppraliq) : 'NULL').");"; |
| 461 |
$dbo->setQuery($q); |
| 462 |
$dbo->execute(); |
| 463 |
} |
| 464 |
$mainframe = JFactory::getApplication(); |
| 465 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=prices"); |
| 466 |
} |
| 467 |
|
| 468 |
public function updateprice() { |
| 469 |
if (!JSession::checkToken()) { |
| 470 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 471 |
} |
| 472 |
$pprice = VikRequest::getString('price', '', 'request'); |
| 473 |
$pattr = VikRequest::getString('attr', '', 'request'); |
| 474 |
$ppraliq = VikRequest::getString('praliq', '', 'request'); |
| 475 |
$pwhereup = VikRequest::getString('whereup', '', 'request'); |
| 476 |
if (!empty($pprice)) { |
| 477 |
$dbo = JFactory::getDbo(); |
| 478 |
$q = "UPDATE `#__vikrentcar_prices` SET `name`=".$dbo->quote($pprice).",`attr`=".$dbo->quote($pattr).",`idiva`=".(!empty($ppraliq) ? intval($ppraliq) : 'NULL')." WHERE `id`=".$dbo->quote($pwhereup).";"; |
| 479 |
$dbo->setQuery($q); |
| 480 |
$dbo->execute(); |
| 481 |
} |
| 482 |
$mainframe = JFactory::getApplication(); |
| 483 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=prices"); |
| 484 |
} |
| 485 |
|
| 486 |
public function removeprice() { |
| 487 |
if (!JSession::checkToken()) { |
| 488 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 489 |
} |
| 490 |
$ids = VikRequest::getVar('cid', array(0)); |
| 491 |
if (@count($ids)) { |
| 492 |
$dbo = JFactory::getDbo(); |
| 493 |
foreach ($ids as $d) { |
| 494 |
$q = "DELETE FROM `#__vikrentcar_prices` WHERE `id`=".$dbo->quote($d).";"; |
| 495 |
$dbo->setQuery($q); |
| 496 |
$dbo->execute(); |
| 497 |
} |
| 498 |
} |
| 499 |
$mainframe = JFactory::getApplication(); |
| 500 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=prices"); |
| 501 |
} |
| 502 |
|
| 503 |
public function cancelprice() { |
| 504 |
$mainframe = JFactory::getApplication(); |
| 505 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=prices"); |
| 506 |
} |
| 507 |
|
| 508 |
public function categories() { |
| 509 |
VikRentCarHelper::printHeader("4"); |
| 510 |
|
| 511 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'categories')); |
| 512 |
|
| 513 |
parent::display(); |
| 514 |
|
| 515 |
if (VikRentCar::showFooter()) { |
| 516 |
VikRentCarHelper::printFooter(); |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
public function newcat() { |
| 521 |
VikRentCarHelper::printHeader("4"); |
| 522 |
|
| 523 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecat')); |
| 524 |
|
| 525 |
parent::display(); |
| 526 |
|
| 527 |
if (VikRentCar::showFooter()) { |
| 528 |
VikRentCarHelper::printFooter(); |
| 529 |
} |
| 530 |
} |
| 531 |
|
| 532 |
public function editcat() { |
| 533 |
VikRentCarHelper::printHeader("4"); |
| 534 |
|
| 535 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecat')); |
| 536 |
|
| 537 |
parent::display(); |
| 538 |
|
| 539 |
if (VikRentCar::showFooter()) { |
| 540 |
VikRentCarHelper::printFooter(); |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
public function createcat() { |
| 545 |
if (!JSession::checkToken()) { |
| 546 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 547 |
} |
| 548 |
$pcatname = VikRequest::getString('catname', '', 'request'); |
| 549 |
$pdescr = VikRequest::getString('descr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 550 |
if (!empty($pcatname)) { |
| 551 |
$dbo = JFactory::getDbo(); |
| 552 |
$q = "SELECT `ordering` FROM `#__vikrentcar_categories` ORDER BY `#__vikrentcar_categories`.`ordering` DESC LIMIT 1;"; |
| 553 |
$dbo->setQuery($q); |
| 554 |
$dbo->execute(); |
| 555 |
if ($dbo->getNumRows() == 1) { |
| 556 |
$getlast = $dbo->loadResult(); |
| 557 |
$newsortnum = $getlast + 1; |
| 558 |
} else { |
| 559 |
$newsortnum = 1; |
| 560 |
} |
| 561 |
$q = "INSERT INTO `#__vikrentcar_categories` (`name`,`descr`,`ordering`) VALUES(".$dbo->quote($pcatname).", ".$dbo->quote($pdescr).", ".(int)$newsortnum.");"; |
| 562 |
$dbo->setQuery($q); |
| 563 |
$dbo->execute(); |
| 564 |
} |
| 565 |
$mainframe = JFactory::getApplication(); |
| 566 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=categories"); |
| 567 |
} |
| 568 |
|
| 569 |
public function updatecat() { |
| 570 |
if (!JSession::checkToken()) { |
| 571 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 572 |
} |
| 573 |
$pcatname = VikRequest::getString('catname', '', 'request'); |
| 574 |
$pdescr = VikRequest::getString('descr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 575 |
$pwhereup = VikRequest::getString('whereup', '', 'request'); |
| 576 |
if (!empty($pcatname)) { |
| 577 |
$dbo = JFactory::getDbo(); |
| 578 |
$q = "UPDATE `#__vikrentcar_categories` SET `name`=".$dbo->quote($pcatname).", `descr`=".$dbo->quote($pdescr)." WHERE `id`=".$dbo->quote($pwhereup).";"; |
| 579 |
$dbo->setQuery($q); |
| 580 |
$dbo->execute(); |
| 581 |
} |
| 582 |
$mainframe = JFactory::getApplication(); |
| 583 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=categories"); |
| 584 |
} |
| 585 |
|
| 586 |
public function removecat() { |
| 587 |
if (!JSession::checkToken()) { |
| 588 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 589 |
} |
| 590 |
$ids = VikRequest::getVar('cid', array(0)); |
| 591 |
if (@count($ids)) { |
| 592 |
$dbo = JFactory::getDbo(); |
| 593 |
foreach ($ids as $d) { |
| 594 |
$q = "DELETE FROM `#__vikrentcar_categories` WHERE `id`=".$dbo->quote($d).";"; |
| 595 |
$dbo->setQuery($q); |
| 596 |
$dbo->execute(); |
| 597 |
} |
| 598 |
} |
| 599 |
$mainframe = JFactory::getApplication(); |
| 600 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=categories"); |
| 601 |
} |
| 602 |
|
| 603 |
public function cancelcat() { |
| 604 |
$mainframe = JFactory::getApplication(); |
| 605 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=categories"); |
| 606 |
} |
| 607 |
|
| 608 |
/** |
| 609 |
* Helper task to remove uploaded images without needing to replace them. |
| 610 |
* |
| 611 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 612 |
*/ |
| 613 |
public function trash_upld_img() |
| 614 |
{ |
| 615 |
$app = JFactory::getApplication(); |
| 616 |
$dbo = JFactory::getDbo(); |
| 617 |
|
| 618 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 619 |
$prid = VikRequest::getInt('rid', 0, 'request'); |
| 620 |
|
| 621 |
$red_to = 'index.php?option=com_vikrentcar'; |
| 622 |
|
| 623 |
if ($ptype == 'carat') { |
| 624 |
// unset the image from a characteristic record |
| 625 |
$q = "SELECT * FROM `#__vikrentcar_caratteristiche` WHERE `id`={$prid}"; |
| 626 |
$dbo->setQuery($q); |
| 627 |
$dbo->execute(); |
| 628 |
if ($dbo->getNumRows()) { |
| 629 |
$record = $dbo->loadObject(); |
| 630 |
$path_to_icon = VRC_ADMIN_PATH . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . $record->icon; |
| 631 |
if (is_file($path_to_icon)) { |
| 632 |
// delete the file |
| 633 |
JFile::delete($path_to_icon); |
| 634 |
} |
| 635 |
// update record |
| 636 |
$record->icon = ''; |
| 637 |
$dbo->updateObject('#__vikrentcar_caratteristiche', $record, 'id'); |
| 638 |
// set redirect URL |
| 639 |
$red_to = 'index.php?option=com_vikrentcar&task=editcarat&cid[]=' . $record->id; |
| 640 |
} |
| 641 |
} elseif ($ptype == 'option') { |
| 642 |
// unset the image from an option/extra record |
| 643 |
$q = "SELECT `id`,`img` FROM `#__vikrentcar_optionals` WHERE `id`={$prid}"; |
| 644 |
$dbo->setQuery($q); |
| 645 |
$dbo->execute(); |
| 646 |
if ($dbo->getNumRows()) { |
| 647 |
$record = $dbo->loadObject(); |
| 648 |
$path_to_icon = VRC_ADMIN_PATH . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . $record->img; |
| 649 |
if (is_file($path_to_icon)) { |
| 650 |
// delete the file |
| 651 |
JFile::delete($path_to_icon); |
| 652 |
} |
| 653 |
// update record |
| 654 |
$record->img = ''; |
| 655 |
$dbo->updateObject('#__vikrentcar_optionals', $record, 'id'); |
| 656 |
// set redirect URL |
| 657 |
$red_to = 'index.php?option=com_vikrentcar&task=editoptional&cid[]=' . $record->id; |
| 658 |
} |
| 659 |
} |
| 660 |
|
| 661 |
$app->redirect($red_to); |
| 662 |
$app->close(); |
| 663 |
} |
| 664 |
|
| 665 |
public function carat() { |
| 666 |
VikRentCarHelper::printHeader("5"); |
| 667 |
|
| 668 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'carat')); |
| 669 |
|
| 670 |
parent::display(); |
| 671 |
|
| 672 |
if (VikRentCar::showFooter()) { |
| 673 |
VikRentCarHelper::printFooter(); |
| 674 |
} |
| 675 |
} |
| 676 |
|
| 677 |
public function newcarat() { |
| 678 |
VikRentCarHelper::printHeader("5"); |
| 679 |
|
| 680 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecarat')); |
| 681 |
|
| 682 |
parent::display(); |
| 683 |
|
| 684 |
if (VikRentCar::showFooter()) { |
| 685 |
VikRentCarHelper::printFooter(); |
| 686 |
} |
| 687 |
} |
| 688 |
|
| 689 |
public function editcarat() { |
| 690 |
VikRentCarHelper::printHeader("5"); |
| 691 |
|
| 692 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecarat')); |
| 693 |
|
| 694 |
parent::display(); |
| 695 |
|
| 696 |
if (VikRentCar::showFooter()) { |
| 697 |
VikRentCarHelper::printFooter(); |
| 698 |
} |
| 699 |
} |
| 700 |
|
| 701 |
public function createcarat() { |
| 702 |
if (!JSession::checkToken()) { |
| 703 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 704 |
} |
| 705 |
$pcaratname = VikRequest::getString('caratname', '', 'request'); |
| 706 |
$pcaratmix = VikRequest::getString('caratmix', '', 'request'); |
| 707 |
$pcarattextimg = VikRequest::getString('carattextimg', '', 'request', VIKREQUEST_ALLOWHTML); |
| 708 |
$pautoresize = VikRequest::getString('autoresize', '', 'request'); |
| 709 |
$presizeto = VikRequest::getString('resizeto', '', 'request'); |
| 710 |
$pidcars = VikRequest::getVar('idcars', array()); |
| 711 |
if (!empty($pcaratname)) { |
| 712 |
$picon = ""; |
| 713 |
if (intval($_FILES['caraticon']['error']) == 0 && VikRentCar::caniWrite(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR) && trim($_FILES['caraticon']['name'])!="") { |
| 714 |
jimport('joomla.filesystem.file'); |
| 715 |
if (@is_uploaded_file($_FILES['caraticon']['tmp_name'])) { |
| 716 |
$safename = JFile::makeSafe(str_replace(" ", "_", strtolower($_FILES['caraticon']['name']))); |
| 717 |
if (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename)) { |
| 718 |
$j = 1; |
| 719 |
while (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename)) { |
| 720 |
$j++; |
| 721 |
} |
| 722 |
$pwhere = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename; |
| 723 |
} else { |
| 724 |
$j = ""; |
| 725 |
$pwhere = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename; |
| 726 |
} |
| 727 |
if (!getimagesize($_FILES['caraticon']['tmp_name']) || !preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $safename)) { |
| 728 |
@unlink($pwhere); |
| 729 |
} elseif (VikRentCar::uploadFile($_FILES['caraticon']['tmp_name'], $pwhere)) { |
| 730 |
@chmod($pwhere, 0644); |
| 731 |
$picon = $j.$safename; |
| 732 |
if ($pautoresize == "1" && !empty($presizeto)) { |
| 733 |
$eforj = new VikResizer(); |
| 734 |
$origmod = $eforj->proportionalImage($pwhere, VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'r_'.$j.$safename, $presizeto, $presizeto); |
| 735 |
if ($origmod) { |
| 736 |
@unlink($pwhere); |
| 737 |
$picon = 'r_'.$j.$safename; |
| 738 |
} |
| 739 |
} |
| 740 |
} |
| 741 |
} |
| 742 |
} |
| 743 |
$dbo = JFactory::getDbo(); |
| 744 |
$q = "SELECT `ordering` FROM `#__vikrentcar_caratteristiche` ORDER BY `#__vikrentcar_caratteristiche`.`ordering` DESC LIMIT 1;"; |
| 745 |
$dbo->setQuery($q); |
| 746 |
$dbo->execute(); |
| 747 |
if ($dbo->getNumRows() == 1) { |
| 748 |
$getlast = $dbo->loadResult(); |
| 749 |
$newsortnum = $getlast + 1; |
| 750 |
} else { |
| 751 |
$newsortnum = 1; |
| 752 |
} |
| 753 |
$pordering = VikRequest::getInt('ordering', 0, 'request'); |
| 754 |
$newsortnum = !empty($pordering) ? $pordering : $newsortnum; |
| 755 |
$q = "INSERT INTO `#__vikrentcar_caratteristiche` (`name`,`icon`,`align`,`textimg`,`ordering`) VALUES(".$dbo->quote($pcaratname).", ".$dbo->quote($picon).", ".$dbo->quote($pcaratmix).", ".$dbo->quote($pcarattextimg).", '".$newsortnum."');"; |
| 756 |
$dbo->setQuery($q); |
| 757 |
$dbo->execute(); |
| 758 |
|
| 759 |
$new_carat_id = $dbo->insertid(); |
| 760 |
if (!empty($new_carat_id)) { |
| 761 |
// assign/unset carat-cars relations |
| 762 |
$cars_with_carat = array(); |
| 763 |
if (count($pidcars)) { |
| 764 |
// assign this new carat to the requested cars |
| 765 |
foreach ($pidcars as $idcar) { |
| 766 |
if (empty($idcar)) { |
| 767 |
continue; |
| 768 |
} |
| 769 |
$q = "SELECT `id`, `idcarat` FROM `#__vikrentcar_cars` WHERE `id`=" . (int)$idcar . ";"; |
| 770 |
$dbo->setQuery($q); |
| 771 |
$dbo->execute(); |
| 772 |
if (!$dbo->getNumRows()) { |
| 773 |
continue; |
| 774 |
} |
| 775 |
$car_data = $dbo->loadAssoc(); |
| 776 |
array_push($cars_with_carat, $car_data['id']); |
| 777 |
$current_carats = empty($car_data['idcarat']) ? array() : explode(';', rtrim($car_data['idcarat'], ';')); |
| 778 |
if (in_array((string)$new_carat_id, $current_carats)) { |
| 779 |
continue; |
| 780 |
} |
| 781 |
if (count($current_carats) === 1 && (string)$current_carats[0] == '0') { |
| 782 |
// make sure we do not concatenate a real ID to 0 |
| 783 |
$current_carats = array(); |
| 784 |
} |
| 785 |
array_push($current_carats, $new_carat_id); |
| 786 |
$new_opts = implode(';', $current_carats) . ';'; |
| 787 |
$q = "UPDATE `#__vikrentcar_cars` SET `idcarat`=" . $dbo->quote($new_opts) . " WHERE `id`={$car_data['id']};"; |
| 788 |
$dbo->setQuery($q); |
| 789 |
$dbo->execute(); |
| 790 |
} |
| 791 |
} |
| 792 |
if (!count($cars_with_carat)) { |
| 793 |
// get all cars to unset this carat (if previously set) |
| 794 |
array_push($cars_with_carat, '0'); |
| 795 |
} |
| 796 |
// unset the carat from the other cars that may have it |
| 797 |
$q = "SELECT `id`, `idcarat` FROM `#__vikrentcar_cars` WHERE `id` NOT IN (" . implode(', ', $cars_with_carat) . ");"; |
| 798 |
$dbo->setQuery($q); |
| 799 |
$dbo->execute(); |
| 800 |
if ($dbo->getNumRows()) { |
| 801 |
$unset_cars_carat = $dbo->loadAssocList(); |
| 802 |
foreach ($unset_cars_carat as $car_data) { |
| 803 |
$current_carats = empty($car_data['idcarat']) ? array() : explode(';', rtrim($car_data['idcarat'], ';')); |
| 804 |
if (!in_array((string)$new_carat_id, $current_carats)) { |
| 805 |
// this car is not using this carat |
| 806 |
continue; |
| 807 |
} |
| 808 |
$caratkey = array_search((string)$new_carat_id, $current_carats); |
| 809 |
if ($caratkey === false) { |
| 810 |
// key not found |
| 811 |
continue; |
| 812 |
} |
| 813 |
// unset this carat ID from the string |
| 814 |
unset($current_carats[$caratkey]); |
| 815 |
if (!count($current_carats)) { |
| 816 |
// a car with no carats assigned will be listed as "0;" |
| 817 |
$current_carats = array(0); |
| 818 |
} |
| 819 |
$new_opts = implode(';', $current_carats) . ';'; |
| 820 |
$q = "UPDATE `#__vikrentcar_cars` SET `idcarat`=" . $dbo->quote($new_opts) . " WHERE `id`={$car_data['id']};"; |
| 821 |
$dbo->setQuery($q); |
| 822 |
$dbo->execute(); |
| 823 |
} |
| 824 |
} |
| 825 |
// |
| 826 |
} |
| 827 |
} |
| 828 |
$mainframe = JFactory::getApplication(); |
| 829 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=carat"); |
| 830 |
} |
| 831 |
|
| 832 |
public function updatecarat() { |
| 833 |
if (!JSession::checkToken()) { |
| 834 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 835 |
} |
| 836 |
$pcaratname = VikRequest::getString('caratname', '', 'request'); |
| 837 |
$pcaratmix = VikRequest::getString('caratmix', '', 'request'); |
| 838 |
$pcarattextimg = VikRequest::getString('carattextimg', '', 'request', VIKREQUEST_ALLOWHTML); |
| 839 |
$pwhereup = VikRequest::getString('whereup', '', 'request'); |
| 840 |
$pautoresize = VikRequest::getString('autoresize', '', 'request'); |
| 841 |
$presizeto = VikRequest::getString('resizeto', '', 'request'); |
| 842 |
$pidcars = VikRequest::getVar('idcars', array()); |
| 843 |
$pordering = VikRequest::getInt('ordering', 1, 'request'); |
| 844 |
if (!empty($pcaratname)) { |
| 845 |
$picon = ''; |
| 846 |
if (intval($_FILES['caraticon']['error']) == 0 && VikRentCar::caniWrite(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR) && trim($_FILES['caraticon']['name'])!="") { |
| 847 |
jimport('joomla.filesystem.file'); |
| 848 |
if (@is_uploaded_file($_FILES['caraticon']['tmp_name'])) { |
| 849 |
$safename = JFile::makeSafe(str_replace(" ", "_", strtolower($_FILES['caraticon']['name']))); |
| 850 |
if (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename)) { |
| 851 |
$j = 1; |
| 852 |
while (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename)) { |
| 853 |
$j++; |
| 854 |
} |
| 855 |
$pwhere=VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename; |
| 856 |
} else { |
| 857 |
$j = ""; |
| 858 |
$pwhere = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename; |
| 859 |
} |
| 860 |
if (!getimagesize($_FILES['caraticon']['tmp_name']) || !preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $safename)) { |
| 861 |
@unlink($pwhere); |
| 862 |
} elseif (VikRentCar::uploadFile($_FILES['caraticon']['tmp_name'], $pwhere)) { |
| 863 |
@chmod($pwhere, 0644); |
| 864 |
$picon = $j.$safename; |
| 865 |
if ($pautoresize == "1" && !empty($presizeto)) { |
| 866 |
$eforj = new VikResizer(); |
| 867 |
$origmod = $eforj->proportionalImage($pwhere, VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'r_'.$j.$safename, $presizeto, $presizeto); |
| 868 |
if ($origmod) { |
| 869 |
@unlink($pwhere); |
| 870 |
$picon = 'r_'.$j.$safename; |
| 871 |
} |
| 872 |
} |
| 873 |
} |
| 874 |
} |
| 875 |
} |
| 876 |
$dbo = JFactory::getDbo(); |
| 877 |
$q = "UPDATE `#__vikrentcar_caratteristiche` SET `name`=".$dbo->quote($pcaratname).",".(strlen($picon) > 0 ? "`icon`='".$picon."'," : "")."`align`=".$dbo->quote($pcaratmix).",`textimg`=".$dbo->quote($pcarattextimg).",`ordering`={$pordering} WHERE `id`=".$dbo->quote($pwhereup).";"; |
| 878 |
$dbo->setQuery($q); |
| 879 |
$dbo->execute(); |
| 880 |
|
| 881 |
// assign/unset carat-cars relations |
| 882 |
$cars_with_carat = array(); |
| 883 |
if (count($pidcars)) { |
| 884 |
// assign this new carat to the requested cars |
| 885 |
foreach ($pidcars as $idcar) { |
| 886 |
if (empty($idcar)) { |
| 887 |
continue; |
| 888 |
} |
| 889 |
$q = "SELECT `id`, `idcarat` FROM `#__vikrentcar_cars` WHERE `id`=" . (int)$idcar . ";"; |
| 890 |
$dbo->setQuery($q); |
| 891 |
$dbo->execute(); |
| 892 |
if (!$dbo->getNumRows()) { |
| 893 |
continue; |
| 894 |
} |
| 895 |
$car_data = $dbo->loadAssoc(); |
| 896 |
array_push($cars_with_carat, $car_data['id']); |
| 897 |
$current_carats = empty($car_data['idcarat']) ? array() : explode(';', rtrim($car_data['idcarat'], ';')); |
| 898 |
if (in_array((string)$pwhereup, $current_carats)) { |
| 899 |
continue; |
| 900 |
} |
| 901 |
if (count($current_carats) === 1 && (string)$current_carats[0] == '0') { |
| 902 |
// make sure we do not concatenate a real ID to 0 |
| 903 |
$current_carats = array(); |
| 904 |
} |
| 905 |
array_push($current_carats, $pwhereup); |
| 906 |
$new_carats = implode(';', $current_carats) . ';'; |
| 907 |
$q = "UPDATE `#__vikrentcar_cars` SET `idcarat`=" . $dbo->quote($new_carats) . " WHERE `id`={$car_data['id']};"; |
| 908 |
$dbo->setQuery($q); |
| 909 |
$dbo->execute(); |
| 910 |
} |
| 911 |
} |
| 912 |
if (!count($cars_with_carat)) { |
| 913 |
// get all cars to unset this carat (if previously set) |
| 914 |
array_push($cars_with_carat, '0'); |
| 915 |
} |
| 916 |
// unset the carat from the other cars that may have it |
| 917 |
$q = "SELECT `id`, `idcarat` FROM `#__vikrentcar_cars` WHERE `id` NOT IN (" . implode(', ', $cars_with_carat) . ");"; |
| 918 |
$dbo->setQuery($q); |
| 919 |
$dbo->execute(); |
| 920 |
if ($dbo->getNumRows()) { |
| 921 |
$unset_cars_carat = $dbo->loadAssocList(); |
| 922 |
foreach ($unset_cars_carat as $car_data) { |
| 923 |
$current_carats = empty($car_data['idcarat']) ? array() : explode(';', rtrim($car_data['idcarat'], ';')); |
| 924 |
if (!in_array((string)$pwhereup, $current_carats)) { |
| 925 |
// this car is not using this carat |
| 926 |
continue; |
| 927 |
} |
| 928 |
$caratkey = array_search((string)$pwhereup, $current_carats); |
| 929 |
if ($caratkey === false) { |
| 930 |
// key not found |
| 931 |
continue; |
| 932 |
} |
| 933 |
// unset this carat ID from the string |
| 934 |
unset($current_carats[$caratkey]); |
| 935 |
if (!count($current_carats)) { |
| 936 |
// a car with no carats assigned will be listed as "0;" |
| 937 |
$current_carats = array(0); |
| 938 |
} |
| 939 |
$new_carats = implode(';', $current_carats) . ';'; |
| 940 |
$q = "UPDATE `#__vikrentcar_cars` SET `idcarat`=" . $dbo->quote($new_carats) . " WHERE `id`={$car_data['id']};"; |
| 941 |
$dbo->setQuery($q); |
| 942 |
$dbo->execute(); |
| 943 |
} |
| 944 |
} |
| 945 |
// |
| 946 |
} |
| 947 |
$mainframe = JFactory::getApplication(); |
| 948 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=carat"); |
| 949 |
} |
| 950 |
|
| 951 |
public function removecarat() { |
| 952 |
if (!JSession::checkToken()) { |
| 953 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 954 |
} |
| 955 |
$ids = VikRequest::getVar('cid', array(0)); |
| 956 |
if (@count($ids)) { |
| 957 |
$dbo = JFactory::getDbo(); |
| 958 |
foreach ($ids as $d) { |
| 959 |
$q = "SELECT `icon` FROM `#__vikrentcar_caratteristiche` WHERE `id`=".$dbo->quote($d).";"; |
| 960 |
$dbo->setQuery($q); |
| 961 |
$dbo->execute(); |
| 962 |
if ($dbo->getNumRows() == 1) { |
| 963 |
$rows = $dbo->loadAssocList(); |
| 964 |
if (!empty($rows[0]['icon']) && file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$rows[0]['icon'])) { |
| 965 |
@unlink(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$rows[0]['icon']); |
| 966 |
} |
| 967 |
} |
| 968 |
$q = "DELETE FROM `#__vikrentcar_caratteristiche` WHERE `id`=".$dbo->quote($d).";"; |
| 969 |
$dbo->setQuery($q); |
| 970 |
$dbo->execute(); |
| 971 |
} |
| 972 |
} |
| 973 |
$mainframe = JFactory::getApplication(); |
| 974 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=carat"); |
| 975 |
} |
| 976 |
|
| 977 |
public function cancelcarat() { |
| 978 |
$mainframe = JFactory::getApplication(); |
| 979 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=carat"); |
| 980 |
} |
| 981 |
|
| 982 |
public function optionals() { |
| 983 |
VikRentCarHelper::printHeader("6"); |
| 984 |
|
| 985 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'optionals')); |
| 986 |
|
| 987 |
parent::display(); |
| 988 |
|
| 989 |
if (VikRentCar::showFooter()) { |
| 990 |
VikRentCarHelper::printFooter(); |
| 991 |
} |
| 992 |
} |
| 993 |
|
| 994 |
public function newoptional() { |
| 995 |
VikRentCarHelper::printHeader("6"); |
| 996 |
|
| 997 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageopt')); |
| 998 |
|
| 999 |
parent::display(); |
| 1000 |
|
| 1001 |
if (VikRentCar::showFooter()) { |
| 1002 |
VikRentCarHelper::printFooter(); |
| 1003 |
} |
| 1004 |
} |
| 1005 |
|
| 1006 |
public function editoptional() { |
| 1007 |
VikRentCarHelper::printHeader("6"); |
| 1008 |
|
| 1009 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageopt')); |
| 1010 |
|
| 1011 |
parent::display(); |
| 1012 |
|
| 1013 |
if (VikRentCar::showFooter()) { |
| 1014 |
VikRentCarHelper::printFooter(); |
| 1015 |
} |
| 1016 |
} |
| 1017 |
|
| 1018 |
public function createoptional() { |
| 1019 |
if (!JSession::checkToken()) { |
| 1020 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 1021 |
} |
| 1022 |
$app = JFactory::getApplication(); |
| 1023 |
$poptname = VikRequest::getString('optname', '', 'request'); |
| 1024 |
$poptdescr = VikRequest::getString('optdescr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 1025 |
$poptcost = VikRequest::getFloat('optcost', '', 'request'); |
| 1026 |
$poptperday = VikRequest::getString('optperday', '', 'request'); |
| 1027 |
$pmaxprice = VikRequest::getFloat('maxprice', '', 'request'); |
| 1028 |
$popthmany = VikRequest::getString('opthmany', '', 'request'); |
| 1029 |
$poptaliq = VikRequest::getString('optaliq', '', 'request'); |
| 1030 |
$pautoresize = VikRequest::getString('autoresize', '', 'request'); |
| 1031 |
$presizeto = VikRequest::getString('resizeto', '', 'request'); |
| 1032 |
$pforcesel = VikRequest::getString('forcesel', '', 'request'); |
| 1033 |
$pforceval = VikRequest::getString('forceval', '', 'request'); |
| 1034 |
$pforceifdays = VikRequest::getInt('forceifdays', '', 'request'); |
| 1035 |
$pmaxdays = VikRequest::getInt('maxdays', 0, 'request'); |
| 1036 |
$pforcevalperday = VikRequest::getString('forcevalperday', '', 'request'); |
| 1037 |
$pidcars = VikRequest::getVar('idcars', array()); |
| 1038 |
$pforcesel = $pforcesel == "1" ? 1 : 0; |
| 1039 |
if ($pforcesel == 1) { |
| 1040 |
$strforceval = intval($pforceval)."-".($pforcevalperday == "1" ? "1" : "0"); |
| 1041 |
} else { |
| 1042 |
$strforceval = ""; |
| 1043 |
} |
| 1044 |
if (!empty($poptname)) { |
| 1045 |
$picon = ''; |
| 1046 |
/** |
| 1047 |
* In order to avoid issues with the calculation of the taxes for the options, |
| 1048 |
* the name should not contain the semi-colon (:) or the currency name. |
| 1049 |
* |
| 1050 |
* @since February 2019 |
| 1051 |
*/ |
| 1052 |
$poptname = str_replace(':', '', str_replace(VikRentCar::getCurrencyName(), '', $poptname)); |
| 1053 |
// |
| 1054 |
if (intval($_FILES['optimg']['error']) == 0 && VikRentCar::caniWrite(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR) && trim($_FILES['optimg']['name'])!="") { |
| 1055 |
jimport('joomla.filesystem.file'); |
| 1056 |
if (@is_uploaded_file($_FILES['optimg']['tmp_name'])) { |
| 1057 |
$safename = JFile::makeSafe(str_replace(" ", "_", strtolower($_FILES['optimg']['name']))); |
| 1058 |
if (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename)) { |
| 1059 |
$j = 1; |
| 1060 |
while (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename)) { |
| 1061 |
$j++; |
| 1062 |
} |
| 1063 |
$pwhere = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename; |
| 1064 |
} else { |
| 1065 |
$j = ""; |
| 1066 |
$pwhere = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename; |
| 1067 |
} |
| 1068 |
|
| 1069 |
if (!getimagesize($_FILES['optimg']['tmp_name']) || !preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $safename)) { |
| 1070 |
@unlink($pwhere); |
| 1071 |
} elseif (VikRentCar::uploadFile($_FILES['optimg']['tmp_name'], $pwhere)) { |
| 1072 |
@chmod($pwhere, 0644); |
| 1073 |
$picon = $j.$safename; |
| 1074 |
if ($pautoresize == "1" && !empty($presizeto)) { |
| 1075 |
$eforj = new VikResizer(); |
| 1076 |
$origmod = $eforj->proportionalImage($pwhere, VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'r_'.$j.$safename, $presizeto, $presizeto); |
| 1077 |
if ($origmod) { |
| 1078 |
@unlink($pwhere); |
| 1079 |
$picon = 'r_'.$j.$safename; |
| 1080 |
} |
| 1081 |
} |
| 1082 |
} |
| 1083 |
} |
| 1084 |
} |
| 1085 |
$poptperday = ($poptperday == "each" ? "1" : "0"); |
| 1086 |
($popthmany == "yes" ? $popthmany = "1" : $popthmany = "0"); |
| 1087 |
$dbo = JFactory::getDbo(); |
| 1088 |
$q = "SELECT `ordering` FROM `#__vikrentcar_optionals` ORDER BY `#__vikrentcar_optionals`.`ordering` DESC LIMIT 1;"; |
| 1089 |
$dbo->setQuery($q); |
| 1090 |
$dbo->execute(); |
| 1091 |
if ($dbo->getNumRows() == 1) { |
| 1092 |
$getlast = $dbo->loadResult(); |
| 1093 |
$newsortnum = $getlast + 1; |
| 1094 |
} else { |
| 1095 |
$newsortnum = 1; |
| 1096 |
} |
| 1097 |
$q = "INSERT INTO `#__vikrentcar_optionals` (`name`,`descr`,`cost`,`perday`,`hmany`,`img`,`idiva`,`maxprice`,`forcesel`,`forceval`,`ordering`,`forceifdays`,`maxdays`) VALUES(".$dbo->quote($poptname).", ".$dbo->quote($poptdescr).", ".$dbo->quote($poptcost).", ".$dbo->quote($poptperday).", ".$dbo->quote($popthmany).", '".$picon."', ".$dbo->quote($poptaliq).", ".$dbo->quote($pmaxprice).", '".$pforcesel."', '".$strforceval."', '".$newsortnum."', '".$pforceifdays."', {$pmaxdays});"; |
| 1098 |
$dbo->setQuery($q); |
| 1099 |
$dbo->execute(); |
| 1100 |
$newoptid = $dbo->insertid(); |
| 1101 |
$app->enqueueMessage(JText::translate('VRCSUCCUPDOPTION')); |
| 1102 |
|
| 1103 |
if (!empty($newoptid)) { |
| 1104 |
// assign/unset option-cars relations |
| 1105 |
$cars_with_opt = array(); |
| 1106 |
if (count($pidcars)) { |
| 1107 |
// assign this new option to the requested cars |
| 1108 |
foreach ($pidcars as $idcar) { |
| 1109 |
if (empty($idcar)) { |
| 1110 |
continue; |
| 1111 |
} |
| 1112 |
$q = "SELECT `id`, `idopt` FROM `#__vikrentcar_cars` WHERE `id`=" . (int)$idcar . ";"; |
| 1113 |
$dbo->setQuery($q); |
| 1114 |
$dbo->execute(); |
| 1115 |
if (!$dbo->getNumRows()) { |
| 1116 |
continue; |
| 1117 |
} |
| 1118 |
$car_data = $dbo->loadAssoc(); |
| 1119 |
array_push($cars_with_opt, $car_data['id']); |
| 1120 |
$current_opts = empty($car_data['idopt']) ? array() : explode(';', rtrim($car_data['idopt'], ';')); |
| 1121 |
if (in_array((string)$newoptid, $current_opts)) { |
| 1122 |
continue; |
| 1123 |
} |
| 1124 |
if (count($current_opts) === 1 && (string)$current_opts[0] == '0') { |
| 1125 |
// make sure we do not concatenate a real ID to 0 |
| 1126 |
$current_opts = array(); |
| 1127 |
} |
| 1128 |
array_push($current_opts, $newoptid); |
| 1129 |
$new_opts = implode(';', $current_opts) . ';'; |
| 1130 |
$q = "UPDATE `#__vikrentcar_cars` SET `idopt`=" . $dbo->quote($new_opts) . " WHERE `id`={$car_data['id']};"; |
| 1131 |
$dbo->setQuery($q); |
| 1132 |
$dbo->execute(); |
| 1133 |
} |
| 1134 |
} |
| 1135 |
if (!count($cars_with_opt)) { |
| 1136 |
// get all cars to unset this option (if previously set) |
| 1137 |
array_push($cars_with_opt, '0'); |
| 1138 |
} |
| 1139 |
// unset the option from the other cars that may have it |
| 1140 |
$q = "SELECT `id`, `idopt` FROM `#__vikrentcar_cars` WHERE `id` NOT IN (" . implode(', ', $cars_with_opt) . ");"; |
| 1141 |
$dbo->setQuery($q); |
| 1142 |
$dbo->execute(); |
| 1143 |
if ($dbo->getNumRows()) { |
| 1144 |
$unset_cars_opt = $dbo->loadAssocList(); |
| 1145 |
foreach ($unset_cars_opt as $car_data) { |
| 1146 |
$current_opts = empty($car_data['idopt']) ? array() : explode(';', rtrim($car_data['idopt'], ';')); |
| 1147 |
if (!in_array((string)$newoptid, $current_opts)) { |
| 1148 |
// this car is not using this option |
| 1149 |
continue; |
| 1150 |
} |
| 1151 |
$optkey = array_search((string)$newoptid, $current_opts); |
| 1152 |
if ($optkey === false) { |
| 1153 |
// key not found |
| 1154 |
continue; |
| 1155 |
} |
| 1156 |
// unset this option ID from the string |
| 1157 |
unset($current_opts[$optkey]); |
| 1158 |
if (!count($current_opts)) { |
| 1159 |
// a car with no options assigned will be listed as "0;" |
| 1160 |
$current_opts = array(0); |
| 1161 |
} |
| 1162 |
$new_opts = implode(';', $current_opts) . ';'; |
| 1163 |
$q = "UPDATE `#__vikrentcar_cars` SET `idopt`=" . $dbo->quote($new_opts) . " WHERE `id`={$car_data['id']};"; |
| 1164 |
$dbo->setQuery($q); |
| 1165 |
$dbo->execute(); |
| 1166 |
} |
| 1167 |
} |
| 1168 |
// |
| 1169 |
} |
| 1170 |
} |
| 1171 |
|
| 1172 |
$app->redirect("index.php?option=com_vikrentcar&task=optionals"); |
| 1173 |
} |
| 1174 |
|
| 1175 |
public function updateoptional() { |
| 1176 |
if (!JSession::checkToken()) { |
| 1177 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 1178 |
} |
| 1179 |
$app = JFactory::getApplication(); |
| 1180 |
$poptname = VikRequest::getString('optname', '', 'request'); |
| 1181 |
$poptdescr = VikRequest::getString('optdescr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 1182 |
$poptcost = VikRequest::getFloat('optcost', '', 'request'); |
| 1183 |
$poptperday = VikRequest::getString('optperday', '', 'request'); |
| 1184 |
$pmaxprice = VikRequest::getFloat('maxprice', '', 'request'); |
| 1185 |
$popthmany = VikRequest::getString('opthmany', '', 'request'); |
| 1186 |
$poptaliq = VikRequest::getString('optaliq', '', 'request'); |
| 1187 |
$pwhereup = VikRequest::getString('whereup', '', 'request'); |
| 1188 |
$pautoresize = VikRequest::getString('autoresize', '', 'request'); |
| 1189 |
$presizeto = VikRequest::getString('resizeto', '', 'request'); |
| 1190 |
$pforcesel = VikRequest::getString('forcesel', '', 'request'); |
| 1191 |
$pforceval = VikRequest::getString('forceval', '', 'request'); |
| 1192 |
$pforceifdays = VikRequest::getInt('forceifdays', '', 'request'); |
| 1193 |
$pmaxdays = VikRequest::getInt('maxdays', 0, 'request'); |
| 1194 |
$pforcevalperday = VikRequest::getString('forcevalperday', '', 'request'); |
| 1195 |
$pidcars = VikRequest::getVar('idcars', array()); |
| 1196 |
$pforcesel = $pforcesel == "1" ? 1 : 0; |
| 1197 |
if ($pforcesel == 1) { |
| 1198 |
$strforceval = intval($pforceval)."-".($pforcevalperday == "1" ? "1" : "0"); |
| 1199 |
} else { |
| 1200 |
$strforceval = ""; |
| 1201 |
} |
| 1202 |
if (!empty($poptname)) { |
| 1203 |
$picon = ''; |
| 1204 |
/** |
| 1205 |
* In order to avoid issues with the calculation of the taxes for the options, |
| 1206 |
* the name should not contain the semi-colon (:) or the currency name. |
| 1207 |
* |
| 1208 |
* @since February 2019 |
| 1209 |
*/ |
| 1210 |
$poptname = str_replace(':', '', str_replace(VikRentCar::getCurrencyName(), '', $poptname)); |
| 1211 |
// |
| 1212 |
if (intval($_FILES['optimg']['error']) == 0 && VikRentCar::caniWrite(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR) && trim($_FILES['optimg']['name'])!="") { |
| 1213 |
jimport('joomla.filesystem.file'); |
| 1214 |
if (@is_uploaded_file($_FILES['optimg']['tmp_name'])) { |
| 1215 |
$safename = JFile::makeSafe(str_replace(" ", "_", strtolower($_FILES['optimg']['name']))); |
| 1216 |
if (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename)) { |
| 1217 |
$j = 1; |
| 1218 |
while (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename)) { |
| 1219 |
$j++; |
| 1220 |
} |
| 1221 |
$pwhere = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename; |
| 1222 |
} else { |
| 1223 |
$j = ""; |
| 1224 |
$pwhere = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename; |
| 1225 |
} |
| 1226 |
if (!getimagesize($_FILES['optimg']['tmp_name']) || !preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $safename)) { |
| 1227 |
@unlink($pwhere); |
| 1228 |
} elseif (VikRentCar::uploadFile($_FILES['optimg']['tmp_name'], $pwhere)) { |
| 1229 |
@chmod($pwhere, 0644); |
| 1230 |
$picon = $j.$safename; |
| 1231 |
if ($pautoresize == "1" && !empty($presizeto)) { |
| 1232 |
$eforj = new VikResizer(); |
| 1233 |
$origmod = $eforj->proportionalImage($pwhere, VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'r_'.$j.$safename, $presizeto, $presizeto); |
| 1234 |
if ($origmod) { |
| 1235 |
@unlink($pwhere); |
| 1236 |
$picon = 'r_'.$j.$safename; |
| 1237 |
} |
| 1238 |
} |
| 1239 |
} |
| 1240 |
} |
| 1241 |
} |
| 1242 |
($poptperday == "each" ? $poptperday="1" : $poptperday="0"); |
| 1243 |
($popthmany == "yes" ? $popthmany="1" : $popthmany="0"); |
| 1244 |
$dbo = JFactory::getDbo(); |
| 1245 |
$q = "UPDATE `#__vikrentcar_optionals` SET `name`=".$dbo->quote($poptname).",`descr`=".$dbo->quote($poptdescr).",`cost`=".$dbo->quote($poptcost).",`perday`=".$dbo->quote($poptperday).",`hmany`=".$dbo->quote($popthmany).",".(strlen($picon)>0 ? "`img`='".$picon."'," : "")."`idiva`=".$dbo->quote($poptaliq).", `maxprice`=".$dbo->quote($pmaxprice).", `forcesel`='".$pforcesel."', `forceval`='".$strforceval."', `forceifdays`='".$pforceifdays."', `maxdays`={$pmaxdays} WHERE `id`=".$dbo->quote($pwhereup).";"; |
| 1246 |
$dbo->setQuery($q); |
| 1247 |
$dbo->execute(); |
| 1248 |
$app->enqueueMessage(JText::translate('VRCSUCCUPDOPTION')); |
| 1249 |
|
| 1250 |
// assign/unset option-cars relations |
| 1251 |
$cars_with_opt = array(); |
| 1252 |
if (count($pidcars)) { |
| 1253 |
// assign this new option to the requested cars |
| 1254 |
foreach ($pidcars as $idcar) { |
| 1255 |
if (empty($idcar)) { |
| 1256 |
continue; |
| 1257 |
} |
| 1258 |
$q = "SELECT `id`, `idopt` FROM `#__vikrentcar_cars` WHERE `id`=" . (int)$idcar . ";"; |
| 1259 |
$dbo->setQuery($q); |
| 1260 |
$dbo->execute(); |
| 1261 |
if (!$dbo->getNumRows()) { |
| 1262 |
continue; |
| 1263 |
} |
| 1264 |
$car_data = $dbo->loadAssoc(); |
| 1265 |
array_push($cars_with_opt, $car_data['id']); |
| 1266 |
$current_opts = empty($car_data['idopt']) ? array() : explode(';', rtrim($car_data['idopt'], ';')); |
| 1267 |
if (in_array((string)$pwhereup, $current_opts)) { |
| 1268 |
continue; |
| 1269 |
} |
| 1270 |
if (count($current_opts) === 1 && (string)$current_opts[0] == '0') { |
| 1271 |
// make sure we do not concatenate a real ID to 0 |
| 1272 |
$current_opts = array(); |
| 1273 |
} |
| 1274 |
array_push($current_opts, $pwhereup); |
| 1275 |
$new_opts = implode(';', $current_opts) . ';'; |
| 1276 |
$q = "UPDATE `#__vikrentcar_cars` SET `idopt`=" . $dbo->quote($new_opts) . " WHERE `id`={$car_data['id']};"; |
| 1277 |
$dbo->setQuery($q); |
| 1278 |
$dbo->execute(); |
| 1279 |
} |
| 1280 |
} |
| 1281 |
if (!count($cars_with_opt)) { |
| 1282 |
// get all cars to unset this option (if previously set) |
| 1283 |
array_push($cars_with_opt, '0'); |
| 1284 |
} |
| 1285 |
// unset the option from the other cars that may have it |
| 1286 |
$q = "SELECT `id`, `idopt` FROM `#__vikrentcar_cars` WHERE `id` NOT IN (" . implode(', ', $cars_with_opt) . ");"; |
| 1287 |
$dbo->setQuery($q); |
| 1288 |
$dbo->execute(); |
| 1289 |
if ($dbo->getNumRows()) { |
| 1290 |
$unset_cars_opt = $dbo->loadAssocList(); |
| 1291 |
foreach ($unset_cars_opt as $car_data) { |
| 1292 |
$current_opts = empty($car_data['idopt']) ? array() : explode(';', rtrim($car_data['idopt'], ';')); |
| 1293 |
if (!in_array((string)$pwhereup, $current_opts)) { |
| 1294 |
// this car is not using this option |
| 1295 |
continue; |
| 1296 |
} |
| 1297 |
$optkey = array_search((string)$pwhereup, $current_opts); |
| 1298 |
if ($optkey === false) { |
| 1299 |
// key not found |
| 1300 |
continue; |
| 1301 |
} |
| 1302 |
// unset this option ID from the string |
| 1303 |
unset($current_opts[$optkey]); |
| 1304 |
if (!count($current_opts)) { |
| 1305 |
// a car with no options assigned will be listed as "0;" |
| 1306 |
$current_opts = array(0); |
| 1307 |
} |
| 1308 |
$new_opts = implode(';', $current_opts) . ';'; |
| 1309 |
$q = "UPDATE `#__vikrentcar_cars` SET `idopt`=" . $dbo->quote($new_opts) . " WHERE `id`={$car_data['id']};"; |
| 1310 |
$dbo->setQuery($q); |
| 1311 |
$dbo->execute(); |
| 1312 |
} |
| 1313 |
} |
| 1314 |
// |
| 1315 |
} |
| 1316 |
|
| 1317 |
$app->redirect("index.php?option=com_vikrentcar&task=optionals"); |
| 1318 |
} |
| 1319 |
|
| 1320 |
public function removeoptionals() { |
| 1321 |
if (!JSession::checkToken()) { |
| 1322 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 1323 |
} |
| 1324 |
$ids = VikRequest::getVar('cid', array(0)); |
| 1325 |
if (@count($ids)) { |
| 1326 |
$dbo = JFactory::getDbo(); |
| 1327 |
foreach ($ids as $d) { |
| 1328 |
$q = "SELECT `img` FROM `#__vikrentcar_optionals` WHERE `id`=".$dbo->quote($d).";"; |
| 1329 |
$dbo->setQuery($q); |
| 1330 |
$dbo->execute(); |
| 1331 |
if ($dbo->getNumRows() == 1) { |
| 1332 |
$rows = $dbo->loadAssocList(); |
| 1333 |
if (!empty($rows[0]['img']) && file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$rows[0]['img'])) { |
| 1334 |
@unlink(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$rows[0]['img']); |
| 1335 |
} |
| 1336 |
} |
| 1337 |
$q = "DELETE FROM `#__vikrentcar_optionals` WHERE `id`=".$dbo->quote($d).";"; |
| 1338 |
$dbo->setQuery($q); |
| 1339 |
$dbo->execute(); |
| 1340 |
} |
| 1341 |
} |
| 1342 |
$mainframe = JFactory::getApplication(); |
| 1343 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=optionals"); |
| 1344 |
} |
| 1345 |
|
| 1346 |
public function canceloptional() { |
| 1347 |
$mainframe = JFactory::getApplication(); |
| 1348 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=optionals"); |
| 1349 |
} |
| 1350 |
|
| 1351 |
public function cars() { |
| 1352 |
if (!JFactory::getUser()->authorise('core.vrc.cars', 'com_vikrentcar')) { |
| 1353 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 1354 |
} |
| 1355 |
|
| 1356 |
VikRentCarHelper::printHeader("7"); |
| 1357 |
|
| 1358 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'cars')); |
| 1359 |
|
| 1360 |
parent::display(); |
| 1361 |
|
| 1362 |
if (VikRentCar::showFooter()) { |
| 1363 |
VikRentCarHelper::printFooter(); |
| 1364 |
} |
| 1365 |
} |
| 1366 |
|
| 1367 |
public function newcar() { |
| 1368 |
if (!JFactory::getUser()->authorise('core.vrc.cars', 'com_vikrentcar')) { |
| 1369 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 1370 |
} |
| 1371 |
|
| 1372 |
VikRentCarHelper::printHeader("7"); |
| 1373 |
|
| 1374 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecar')); |
| 1375 |
|
| 1376 |
parent::display(); |
| 1377 |
|
| 1378 |
if (VikRentCar::showFooter()) { |
| 1379 |
VikRentCarHelper::printFooter(); |
| 1380 |
} |
| 1381 |
} |
| 1382 |
|
| 1383 |
public function editcar() { |
| 1384 |
if (!JFactory::getUser()->authorise('core.vrc.cars', 'com_vikrentcar')) { |
| 1385 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 1386 |
} |
| 1387 |
|
| 1388 |
VikRentCarHelper::printHeader("7"); |
| 1389 |
|
| 1390 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecar')); |
| 1391 |
|
| 1392 |
parent::display(); |
| 1393 |
|
| 1394 |
if (VikRentCar::showFooter()) { |
| 1395 |
VikRentCarHelper::printFooter(); |
| 1396 |
} |
| 1397 |
} |
| 1398 |
|
| 1399 |
public function createcar() { |
| 1400 |
if (!JSession::checkToken()) { |
| 1401 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 1402 |
} |
| 1403 |
$mainframe = JFactory::getApplication(); |
| 1404 |
$pcname = VikRequest::getString('cname', '', 'request'); |
| 1405 |
$pccat = VikRequest::getVar('ccat', array(0)); |
| 1406 |
$pcdescr = VikRequest::getString('cdescr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 1407 |
$pshort_info = VikRequest::getString('short_info', '', 'request', VIKREQUEST_ALLOWHTML); |
| 1408 |
$pcplace = VikRequest::getVar('cplace', array(0)); |
| 1409 |
$pcretplace = VikRequest::getVar('cretplace', array(0)); |
| 1410 |
$pccarat = VikRequest::getVar('ccarat', array(0)); |
| 1411 |
$pcoptional = VikRequest::getVar('coptional', array(0)); |
| 1412 |
$pcavail = VikRequest::getString('cavail', '', 'request'); |
| 1413 |
$pautoresize = VikRequest::getString('autoresize', '', 'request'); |
| 1414 |
$presizeto = VikRequest::getString('resizeto', '', 'request'); |
| 1415 |
$pautoresizemore = VikRequest::getString('autoresizemore', '', 'request'); |
| 1416 |
$presizetomore = VikRequest::getString('resizetomore', '', 'request'); |
| 1417 |
$punits = VikRequest::getInt('units', '', 'request'); |
| 1418 |
$pimages = VikRequest::getVar('cimgmore', null, 'files', 'array'); |
| 1419 |
$pstartfrom = VikRequest::getString('startfrom', '', 'request'); |
| 1420 |
$psdailycost = VikRequest::getString('sdailycost', '', 'request'); |
| 1421 |
$psdailycost = intval($psdailycost) == 1 ? 1 : 0; |
| 1422 |
$pshourlycal = VikRequest::getString('shourlycal', '', 'request'); |
| 1423 |
$pshourlycal = intval($pshourlycal) == 1 ? 1 : 0; |
| 1424 |
$preqinfo = VikRequest::getInt('reqinfo', '', 'request'); |
| 1425 |
$pemail = VikRequest::getString('email', '', 'request'); |
| 1426 |
$pcustptitle = VikRequest::getString('custptitle', '', 'request'); |
| 1427 |
$pcustptitlew = VikRequest::getString('custptitlew', '', 'request'); |
| 1428 |
$pcustptitlew = in_array($pcustptitlew, array('before', 'after', 'replace')) ? $pcustptitlew : 'before'; |
| 1429 |
$pmetakeywords = VikRequest::getString('metakeywords', '', 'request'); |
| 1430 |
$pmetadescription = VikRequest::getString('metadescription', '', 'request'); |
| 1431 |
$psefalias = VikRequest::getString('sefalias', '', 'request'); |
| 1432 |
$psefalias = empty($psefalias) ? JFilterOutput::stringURLSafe($pcname) : JFilterOutput::stringURLSafe($psefalias); |
| 1433 |
|
| 1434 |
jimport('joomla.filesystem.file'); |
| 1435 |
$updpath = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 1436 |
|
| 1437 |
if (empty($pcname)) { |
| 1438 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 1439 |
exit; |
| 1440 |
} |
| 1441 |
|
| 1442 |
$picon = ""; |
| 1443 |
if (($_FILES['cimg'] ?? null) && !intval($_FILES['cimg']['error']) && VikRentCar::caniWrite($updpath) && strlen(trim($_FILES['cimg']['name'])) && @is_uploaded_file($_FILES['cimg']['tmp_name'])) { |
| 1444 |
$safename=JFile::makeSafe(str_replace(" ", "_", strtolower($_FILES['cimg']['name']))); |
| 1445 |
if (file_exists($updpath.$safename)) { |
| 1446 |
$j=1; |
| 1447 |
while (file_exists($updpath.$j.$safename)) { |
| 1448 |
$j++; |
| 1449 |
} |
| 1450 |
$pwhere=$updpath.$j.$safename; |
| 1451 |
} else { |
| 1452 |
$j=""; |
| 1453 |
$pwhere=$updpath.$safename; |
| 1454 |
} |
| 1455 |
if (!getimagesize($_FILES['cimg']['tmp_name']) || !preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $safename)) { |
| 1456 |
@unlink($pwhere); |
| 1457 |
} elseif (VikRentCar::uploadFile($_FILES['cimg']['tmp_name'], $pwhere)) { |
| 1458 |
$picon = $j . $safename; |
| 1459 |
if ((int) $pautoresize && !empty($presizeto)) { |
| 1460 |
$origmod = (new VikResizer)->proportionalImage($pwhere, $updpath . 'r_' . $j . $safename, $presizeto, $presizeto); |
| 1461 |
if ($origmod) { |
| 1462 |
@unlink($pwhere); |
| 1463 |
$picon = 'r_' . $j . $safename; |
| 1464 |
} |
| 1465 |
} |
| 1466 |
/** |
| 1467 |
* We statically use a value of 600px for a better CSS forcing result for |
| 1468 |
* the thumbnail of the car's main image to be used mainly in the Carslist. |
| 1469 |
* The method VikRentCar::getThumbnailsWidth() is now used to get the max |
| 1470 |
* size of the thumbnails for the Cardetails (extra images). It was previously |
| 1471 |
* used to calculate the max thumb size for the car's main image in the Carslist. |
| 1472 |
* |
| 1473 |
* @since 1.13 |
| 1474 |
*/ |
| 1475 |
$thumbs_width = 600; |
| 1476 |
if ($mainimginfo[0] > $thumbs_width) { |
| 1477 |
$eforj = new VikResizer(); |
| 1478 |
(new VikResizer)->proportionalImage($updpath.$picon, $updpath.'vthumb_'.$picon, $thumbs_width, $thumbs_width); |
| 1479 |
} |
| 1480 |
} |
| 1481 |
} |
| 1482 |
|
| 1483 |
// more images |
| 1484 |
$arrimgs = []; |
| 1485 |
$creativik = new VikResizer(); |
| 1486 |
$bigsdest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 1487 |
$thumbsdest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 1488 |
$dest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 1489 |
$moreimagestr = ""; |
| 1490 |
foreach ($pimages['name'] as $kk => $ci) { |
| 1491 |
if (!empty($ci)) { |
| 1492 |
$arrimgs[] = $kk; |
| 1493 |
} |
| 1494 |
} |
| 1495 |
foreach ($arrimgs as $imgk) { |
| 1496 |
if (strlen(trim($pimages['name'][$imgk]))) { |
| 1497 |
$filename = JFile::makeSafe(str_replace(" ", "_", strtolower($pimages['name'][$imgk]))); |
| 1498 |
$src = $pimages['tmp_name'][$imgk]; |
| 1499 |
$j=""; |
| 1500 |
if (file_exists($dest.$filename)) { |
| 1501 |
$j=rand(171, 1717); |
| 1502 |
while (file_exists($dest.$j.$filename)) { |
| 1503 |
$j++; |
| 1504 |
} |
| 1505 |
} |
| 1506 |
$finaldest = $dest.$j.$filename; |
| 1507 |
$check = !empty($pimages['tmp_name'][$imgk]) ? getimagesize($pimages['tmp_name'][$imgk]) : []; |
| 1508 |
if (($check[2] & imagetypes()) && preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $filename)) { |
| 1509 |
if (VikRentCar::uploadFile($src, $finaldest)) { |
| 1510 |
$gimg=$j.$filename; |
| 1511 |
//orig img |
| 1512 |
$origmod = true; |
| 1513 |
if ($pautoresizemore == "1" && !empty($presizetomore)) { |
| 1514 |
$origmod = $creativik->proportionalImage($finaldest, $bigsdest.'big_'.$j.$filename, $presizetomore, $presizetomore); |
| 1515 |
} else { |
| 1516 |
VikRentCar::uploadFile($finaldest, $bigsdest.'big_'.$j.$filename, true); |
| 1517 |
} |
| 1518 |
//thumb |
| 1519 |
$thumbs_size = VikRentCar::getThumbnailsWidth(); |
| 1520 |
$thumb = $creativik->proportionalImage($finaldest, $thumbsdest.'thumb_'.$j.$filename, $thumbs_size, $thumbs_size); |
| 1521 |
if (!$thumb || !$origmod) { |
| 1522 |
if (file_exists($bigsdest.'big_'.$j.$filename)) @unlink($bigsdest.'big_'.$j.$filename); |
| 1523 |
if (file_exists($thumbsdest.'thumb_'.$j.$filename)) @unlink($thumbsdest.'thumb_'.$j.$filename); |
| 1524 |
VikError::raiseWarning('', 'Error While Uploading the File: '.$pimages['name'][$imgk]); |
| 1525 |
} else { |
| 1526 |
$moreimagestr.=$j.$filename.";;"; |
| 1527 |
} |
| 1528 |
@unlink($finaldest); |
| 1529 |
} else { |
| 1530 |
VikError::raiseWarning('', 'Error While Uploading the File: '.$pimages['name'][$imgk]); |
| 1531 |
} |
| 1532 |
} else { |
| 1533 |
VikError::raiseWarning('', 'Error While Uploading the File: '.$pimages['name'][$imgk]); |
| 1534 |
} |
| 1535 |
} |
| 1536 |
} |
| 1537 |
//end more images |
| 1538 |
if (is_array($pcplace) && count($pcplace)) { |
| 1539 |
$pcplacedef=""; |
| 1540 |
foreach ($pcplace as $cpla) { |
| 1541 |
$pcplacedef.=$cpla.";"; |
| 1542 |
} |
| 1543 |
} else { |
| 1544 |
$pcplacedef=""; |
| 1545 |
} |
| 1546 |
if (is_array($pcretplace) && count($pcretplace)) { |
| 1547 |
$pcretplacedef=""; |
| 1548 |
foreach ($pcretplace as $cpla) { |
| 1549 |
$pcretplacedef.=$cpla.";"; |
| 1550 |
} |
| 1551 |
} else { |
| 1552 |
$pcretplacedef=""; |
| 1553 |
} |
| 1554 |
if (is_array($pccat) && count($pccat)) { |
| 1555 |
$pccatdef=""; |
| 1556 |
foreach ($pccat as $ccat) { |
| 1557 |
$pccatdef.=$ccat.";"; |
| 1558 |
} |
| 1559 |
} else { |
| 1560 |
$pccatdef=""; |
| 1561 |
} |
| 1562 |
if (is_array($pccarat) && count($pccarat)) { |
| 1563 |
$pccaratdef=""; |
| 1564 |
foreach ($pccarat as $ccarat) { |
| 1565 |
$pccaratdef.=$ccarat.";"; |
| 1566 |
} |
| 1567 |
} else { |
| 1568 |
$pccaratdef=""; |
| 1569 |
} |
| 1570 |
if (is_array($pcoptional) && count($pcoptional)) { |
| 1571 |
$pcoptionaldef=""; |
| 1572 |
foreach ($pcoptional as $coptional) { |
| 1573 |
$pcoptionaldef.=$coptional.";"; |
| 1574 |
} |
| 1575 |
} else { |
| 1576 |
$pcoptionaldef=""; |
| 1577 |
} |
| 1578 |
$pcavaildef=($pcavail=="yes" ? "1" : "0"); |
| 1579 |
|
| 1580 |
//params |
| 1581 |
$car_params = array(); |
| 1582 |
$car_params['sdailycost'] = $psdailycost; |
| 1583 |
$car_params['reqinfo'] = $preqinfo; |
| 1584 |
$car_params['email'] = $pemail; |
| 1585 |
$car_params['custptitle'] = $pcustptitle; |
| 1586 |
$car_params['custptitlew'] = $pcustptitlew; |
| 1587 |
$car_params['metakeywords'] = $pmetakeywords; |
| 1588 |
$car_params['metadescription'] = $pmetadescription; |
| 1589 |
$car_params['shourlycal'] = $pshourlycal; |
| 1590 |
$car_params['inspection'] = VikRequest::getString('inspection', '', 'request'); |
| 1591 |
|
| 1592 |
if (!empty($car_params['inspection']) && preg_match("/.png$/i", $car_params['inspection'])) { |
| 1593 |
// make sure the file is valid |
| 1594 |
$cms_base_p = defined('ABSPATH') ? ABSPATH : JPATH_SITE; |
| 1595 |
$custom_inspection_p = JPath::clean($cms_base_p . '/' . $car_params['inspection']); |
| 1596 |
if (!is_file($custom_inspection_p)) { |
| 1597 |
$car_params['inspection'] = null; |
| 1598 |
} |
| 1599 |
} else { |
| 1600 |
$car_params['inspection'] = null; |
| 1601 |
} |
| 1602 |
|
| 1603 |
//distinctive features |
| 1604 |
$car_params['features'] = array(); |
| 1605 |
if ($punits > 0) { |
| 1606 |
for ($i=1; $i <= $punits; $i++) { |
| 1607 |
$distf_name = VikRequest::getVar('feature-name'.$i, array()); |
| 1608 |
$distf_lang = VikRequest::getVar('feature-lang'.$i, array()); |
| 1609 |
$distf_value = VikRequest::getVar('feature-value'.$i, array()); |
| 1610 |
foreach ($distf_name as $distf_k => $distf) { |
| 1611 |
if (!empty($distf) && isset($distf_value[$distf_k])) { |
| 1612 |
$use_key = $distf; |
| 1613 |
if (!empty($distf_lang[$distf_k]) && JText::translate($distf_lang[$distf_k]) == $distf) { |
| 1614 |
$use_key = $distf_lang[$distf_k]; |
| 1615 |
} |
| 1616 |
$car_params['features'][$i][$use_key] = $distf_value[$distf_k]; |
| 1617 |
} |
| 1618 |
} |
| 1619 |
} |
| 1620 |
} |
| 1621 |
// |
| 1622 |
$dbo = JFactory::getDbo(); |
| 1623 |
$q = "INSERT INTO `#__vikrentcar_cars` (`name`,`img`,`idcat`,`idcarat`,`idopt`,`info`,`idplace`,`avail`,`units`,`idretplace`,`moreimgs`,`startfrom`,`short_info`,`params`,`alias`) VALUES(".$dbo->quote($pcname).",".$dbo->quote($picon).",".$dbo->quote($pccatdef).",".$dbo->quote($pccaratdef).",".$dbo->quote($pcoptionaldef).",".$dbo->quote($pcdescr).",".$dbo->quote($pcplacedef).",".$dbo->quote($pcavaildef).",".($punits > 0 ? $dbo->quote($punits) : "'1'").",".$dbo->quote($pcretplacedef).", ".$dbo->quote($moreimagestr).", ".(strlen($pstartfrom) > 0 ? "'".$pstartfrom."'" : "null").", ".$dbo->quote($pshort_info).", ".$dbo->quote(json_encode($car_params)).", ".$dbo->quote($psefalias).");"; |
| 1624 |
$dbo->setQuery($q); |
| 1625 |
$dbo->execute(); |
| 1626 |
$lid = $dbo->insertid(); |
| 1627 |
if (!empty($lid)) { |
| 1628 |
$mainframe->enqueueMessage(JText::translate('VRCCARSAVEOK')); |
| 1629 |
|
| 1630 |
/** |
| 1631 |
* Import remote iCal calendars. |
| 1632 |
* |
| 1633 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 1634 |
*/ |
| 1635 |
$import_calendars = VikRequest::getVar('calendars', array()); |
| 1636 |
if (!empty($import_calendars) && !empty($import_calendars['url'])) { |
| 1637 |
// parse all calendars |
| 1638 |
foreach ($import_calendars['url'] as $cal_key => $cal_url) { |
| 1639 |
if (empty($cal_url)) { |
| 1640 |
continue; |
| 1641 |
} |
| 1642 |
// build record object |
| 1643 |
$record = new stdClass; |
| 1644 |
$record->idcar = (int)$lid; |
| 1645 |
$record->name = isset($import_calendars['name']) && !empty($import_calendars['name'][$cal_key]) ? $import_calendars['name'][$cal_key] : JText::translate('VRC_IMPORT_CALENDAR_URL'); |
| 1646 |
$record->url = $cal_url; |
| 1647 |
// insert object |
| 1648 |
$dbo->insertObject('#__vikrentcar_cars_icals', $record, 'id'); |
| 1649 |
} |
| 1650 |
} |
| 1651 |
|
| 1652 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=tariffs&cid[]=".$lid); |
| 1653 |
} else { |
| 1654 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 1655 |
} |
| 1656 |
} |
| 1657 |
|
| 1658 |
public function updatecar() { |
| 1659 |
if (!JSession::checkToken()) { |
| 1660 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 1661 |
} |
| 1662 |
$this->do_updatecar(); |
| 1663 |
} |
| 1664 |
|
| 1665 |
public function updatecarapply() { |
| 1666 |
if (!JSession::checkToken()) { |
| 1667 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 1668 |
} |
| 1669 |
$this->do_updatecar(true); |
| 1670 |
} |
| 1671 |
|
| 1672 |
private function do_updatecar($remain = false) { |
| 1673 |
$mainframe = JFactory::getApplication(); |
| 1674 |
$pcname = VikRequest::getString('cname', '', 'request'); |
| 1675 |
$pccat = VikRequest::getVar('ccat', array(0)); |
| 1676 |
$pcdescr = VikRequest::getString('cdescr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 1677 |
$pshort_info = VikRequest::getString('short_info', '', 'request', VIKREQUEST_ALLOWHTML); |
| 1678 |
$pcplace = VikRequest::getVar('cplace', array(0)); |
| 1679 |
$pcretplace = VikRequest::getVar('cretplace', array(0)); |
| 1680 |
$pccarat = VikRequest::getVar('ccarat', array(0)); |
| 1681 |
$pcoptional = VikRequest::getVar('coptional', array(0)); |
| 1682 |
$pcavail = VikRequest::getString('cavail', '', 'request'); |
| 1683 |
$pwhereup = VikRequest::getString('whereup', '', 'request'); |
| 1684 |
$pautoresize = VikRequest::getString('autoresize', '', 'request'); |
| 1685 |
$presizeto = VikRequest::getString('resizeto', '', 'request'); |
| 1686 |
$pautoresizemore = VikRequest::getString('autoresizemore', '', 'request'); |
| 1687 |
$presizetomore = VikRequest::getString('resizetomore', '', 'request'); |
| 1688 |
$punits = VikRequest::getInt('units', '', 'request'); |
| 1689 |
$pimages = VikRequest::getVar('cimgmore', null, 'files', 'array'); |
| 1690 |
$pactmoreimgs = VikRequest::getString('actmoreimgs', '', 'request'); |
| 1691 |
$pstartfrom = VikRequest::getString('startfrom', '', 'request'); |
| 1692 |
$psdailycost = VikRequest::getString('sdailycost', '', 'request'); |
| 1693 |
$psdailycost = intval($psdailycost) == 1 ? 1 : 0; |
| 1694 |
$pshourlycal = VikRequest::getString('shourlycal', '', 'request'); |
| 1695 |
$pshourlycal = intval($pshourlycal) == 1 ? 1 : 0; |
| 1696 |
$preqinfo = VikRequest::getInt('reqinfo', '', 'request'); |
| 1697 |
$pemail = VikRequest::getString('email', '', 'request'); |
| 1698 |
$pcustptitle = VikRequest::getString('custptitle', '', 'request'); |
| 1699 |
$pcustptitlew = VikRequest::getString('custptitlew', '', 'request'); |
| 1700 |
$pcustptitlew = in_array($pcustptitlew, array('before', 'after', 'replace')) ? $pcustptitlew : 'before'; |
| 1701 |
$pmetakeywords = VikRequest::getString('metakeywords', '', 'request'); |
| 1702 |
$pmetadescription = VikRequest::getString('metadescription', '', 'request'); |
| 1703 |
$psefalias = VikRequest::getString('sefalias', '', 'request'); |
| 1704 |
$psefalias = empty($psefalias) ? JFilterOutput::stringURLSafe($pcname) : JFilterOutput::stringURLSafe($psefalias); |
| 1705 |
$pimgsorting = VikRequest::getVar('imgsorting', array()); |
| 1706 |
|
| 1707 |
jimport('joomla.filesystem.file'); |
| 1708 |
$updpath = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 1709 |
|
| 1710 |
if (empty($pcname)) { |
| 1711 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 1712 |
exit; |
| 1713 |
} |
| 1714 |
|
| 1715 |
$picon = ""; |
| 1716 |
if (($_FILES['cimg'] ?? null) && !intval($_FILES['cimg']['error']) && VikRentCar::caniWrite($updpath) && strlen(trim($_FILES['cimg']['name'])) && @is_uploaded_file($_FILES['cimg']['tmp_name'])) { |
| 1717 |
$safename=JFile::makeSafe(str_replace(" ", "_", strtolower($_FILES['cimg']['name']))); |
| 1718 |
if (file_exists($updpath.$safename)) { |
| 1719 |
$j=1; |
| 1720 |
while (file_exists($updpath.$j.$safename)) { |
| 1721 |
$j++; |
| 1722 |
} |
| 1723 |
$pwhere=$updpath.$j.$safename; |
| 1724 |
} else { |
| 1725 |
$j=""; |
| 1726 |
$pwhere=$updpath.$safename; |
| 1727 |
} |
| 1728 |
if (!getimagesize($_FILES['cimg']['tmp_name']) || !preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $safename)) { |
| 1729 |
@unlink($pwhere); |
| 1730 |
} elseif (VikRentCar::uploadFile($_FILES['cimg']['tmp_name'], $pwhere)) { |
| 1731 |
$picon = $j . $safename; |
| 1732 |
if ((int) $pautoresize && !empty($presizeto)) { |
| 1733 |
$origmod = (new VikResizer)->proportionalImage($pwhere, $updpath . 'r_' . $j . $safename, $presizeto, $presizeto); |
| 1734 |
if ($origmod) { |
| 1735 |
@unlink($pwhere); |
| 1736 |
$picon = 'r_' . $j . $safename; |
| 1737 |
} |
| 1738 |
} |
| 1739 |
/** |
| 1740 |
* We statically use a value of 600px for a better CSS forcing result for |
| 1741 |
* the thumbnail of the car's main image to be used mainly in the Carslist. |
| 1742 |
* The method VikRentCar::getThumbnailsWidth() is now used to get the max |
| 1743 |
* size of the thumbnails for the Cardetails (extra images). It was previously |
| 1744 |
* used to calculate the max thumb size for the car's main image in the Carslist. |
| 1745 |
* |
| 1746 |
* @since 1.13 |
| 1747 |
*/ |
| 1748 |
$thumbs_width = 600; |
| 1749 |
if ($mainimginfo[0] > $thumbs_width) { |
| 1750 |
$eforj = new VikResizer(); |
| 1751 |
(new VikResizer)->proportionalImage($updpath.$picon, $updpath.'vthumb_'.$picon, $thumbs_width, $thumbs_width); |
| 1752 |
} |
| 1753 |
} |
| 1754 |
} |
| 1755 |
|
| 1756 |
// more images |
| 1757 |
$arrimgs = []; |
| 1758 |
$creativik = new VikResizer(); |
| 1759 |
$bigsdest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 1760 |
$thumbsdest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 1761 |
$dest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 1762 |
$moreimagestr = $pactmoreimgs; |
| 1763 |
foreach ($pimages['name'] as $kk => $ci) { |
| 1764 |
if (!empty($ci)) { |
| 1765 |
$arrimgs[] = $kk; |
| 1766 |
} |
| 1767 |
} |
| 1768 |
foreach ($arrimgs as $imgk) { |
| 1769 |
if (strlen(trim($pimages['name'][$imgk]))) { |
| 1770 |
$filename = JFile::makeSafe(str_replace(" ", "_", strtolower($pimages['name'][$imgk]))); |
| 1771 |
$src = $pimages['tmp_name'][$imgk]; |
| 1772 |
$j=""; |
| 1773 |
if (file_exists($dest.$filename)) { |
| 1774 |
$j=rand(171, 1717); |
| 1775 |
while (file_exists($dest.$j.$filename)) { |
| 1776 |
$j++; |
| 1777 |
} |
| 1778 |
} |
| 1779 |
$finaldest = $dest.$j.$filename; |
| 1780 |
$check = !empty($pimages['tmp_name'][$imgk]) ? getimagesize($pimages['tmp_name'][$imgk]) : []; |
| 1781 |
if (($check[2] & imagetypes()) && preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $filename)) { |
| 1782 |
if (VikRentCar::uploadFile($src, $finaldest)) { |
| 1783 |
$gimg=$j.$filename; |
| 1784 |
//orig img |
| 1785 |
$origmod = true; |
| 1786 |
if ($pautoresizemore == "1" && !empty($presizetomore)) { |
| 1787 |
$origmod = $creativik->proportionalImage($finaldest, $bigsdest.'big_'.$j.$filename, $presizetomore, $presizetomore); |
| 1788 |
} else { |
| 1789 |
VikRentCar::uploadFile($finaldest, $bigsdest.'big_'.$j.$filename, true); |
| 1790 |
} |
| 1791 |
//thumb |
| 1792 |
$thumbs_size = VikRentCar::getThumbnailsWidth(); |
| 1793 |
$thumb = $creativik->proportionalImage($finaldest, $thumbsdest.'thumb_'.$j.$filename, $thumbs_size, $thumbs_size); |
| 1794 |
if (!$thumb || !$origmod) { |
| 1795 |
if (file_exists($bigsdest.'big_'.$j.$filename)) @unlink($bigsdest.'big_'.$j.$filename); |
| 1796 |
if (file_exists($thumbsdest.'thumb_'.$j.$filename)) @unlink($thumbsdest.'thumb_'.$j.$filename); |
| 1797 |
VikError::raiseWarning('', 'Error While Uploading the File: '.$pimages['name'][$imgk]); |
| 1798 |
} else { |
| 1799 |
$moreimagestr.=$j.$filename.";;"; |
| 1800 |
} |
| 1801 |
@unlink($finaldest); |
| 1802 |
} else { |
| 1803 |
VikError::raiseWarning('', 'Error While Uploading the File: '.$pimages['name'][$imgk]); |
| 1804 |
} |
| 1805 |
} else { |
| 1806 |
VikError::raiseWarning('', 'Error While Uploading the File: '.$pimages['name'][$imgk]); |
| 1807 |
} |
| 1808 |
} |
| 1809 |
} |
| 1810 |
|
| 1811 |
/** |
| 1812 |
* Sorting of extra images. |
| 1813 |
* |
| 1814 |
* @since 1.14 |
| 1815 |
*/ |
| 1816 |
$sorted_extraim = array(); |
| 1817 |
$extraim_parts = explode(';;', $moreimagestr); |
| 1818 |
foreach ($pimgsorting as $k => $v) { |
| 1819 |
$capkey = -1; |
| 1820 |
if (isset($extraim_parts[$k])) { |
| 1821 |
$sorted_extraim[] = $v; |
| 1822 |
} |
| 1823 |
} |
| 1824 |
$tot_sorted_im = count($sorted_extraim); |
| 1825 |
if ($tot_sorted_im != count($extraim_parts)) { |
| 1826 |
foreach ($extraim_parts as $k => $v) { |
| 1827 |
if ($k <= ($tot_sorted_im - 1)) { |
| 1828 |
continue; |
| 1829 |
} |
| 1830 |
$sorted_extraim[] = $v; |
| 1831 |
} |
| 1832 |
} |
| 1833 |
$moreimagestr = implode(';;', $sorted_extraim); |
| 1834 |
// |
| 1835 |
|
| 1836 |
//end more images |
| 1837 |
if (is_array($pcplace) && count($pcplace)) { |
| 1838 |
$pcplacedef=""; |
| 1839 |
foreach ($pcplace as $cpla) { |
| 1840 |
$pcplacedef.=$cpla.";"; |
| 1841 |
} |
| 1842 |
} else { |
| 1843 |
$pcplacedef=""; |
| 1844 |
} |
| 1845 |
if (is_array($pcretplace) && count($pcretplace)) { |
| 1846 |
$pcretplacedef=""; |
| 1847 |
foreach ($pcretplace as $cpla) { |
| 1848 |
$pcretplacedef.=$cpla.";"; |
| 1849 |
} |
| 1850 |
} else { |
| 1851 |
$pcretplacedef=""; |
| 1852 |
} |
| 1853 |
if (is_array($pccat) && count($pccat)) { |
| 1854 |
$pccatdef=""; |
| 1855 |
foreach ($pccat as $ccat) { |
| 1856 |
$pccatdef.=$ccat.";"; |
| 1857 |
} |
| 1858 |
} else { |
| 1859 |
$pccatdef=""; |
| 1860 |
} |
| 1861 |
if (is_array($pccarat) && count($pccarat)) { |
| 1862 |
$pccaratdef=""; |
| 1863 |
foreach ($pccarat as $ccarat) { |
| 1864 |
$pccaratdef.=$ccarat.";"; |
| 1865 |
} |
| 1866 |
} else { |
| 1867 |
$pccaratdef=""; |
| 1868 |
} |
| 1869 |
if (is_array($pcoptional) && count($pcoptional)) { |
| 1870 |
$pcoptionaldef=""; |
| 1871 |
foreach ($pcoptional as $coptional) { |
| 1872 |
$pcoptionaldef.=$coptional.";"; |
| 1873 |
} |
| 1874 |
} else { |
| 1875 |
$pcoptionaldef=""; |
| 1876 |
} |
| 1877 |
$pcavaildef=($pcavail=="yes" ? "1" : "0"); |
| 1878 |
|
| 1879 |
//params |
| 1880 |
$car_params = array(); |
| 1881 |
$car_params['sdailycost'] = $psdailycost; |
| 1882 |
$car_params['reqinfo'] = $preqinfo; |
| 1883 |
$car_params['email'] = $pemail; |
| 1884 |
$car_params['custptitle'] = $pcustptitle; |
| 1885 |
$car_params['custptitlew'] = $pcustptitlew; |
| 1886 |
$car_params['metakeywords'] = $pmetakeywords; |
| 1887 |
$car_params['metadescription'] = $pmetadescription; |
| 1888 |
$car_params['shourlycal'] = $pshourlycal; |
| 1889 |
$car_params['inspection'] = VikRequest::getString('inspection', '', 'request'); |
| 1890 |
|
| 1891 |
//distinctive features |
| 1892 |
$car_params['features'] = array(); |
| 1893 |
$damages = array(); |
| 1894 |
$damage_show_type = VikRentCar::getDamageShowType(); |
| 1895 |
$damage_png_path = implode(DIRECTORY_SEPARATOR, [VRC_ADMIN_PATH, 'resources', 'damage_mark.png']); |
| 1896 |
$cstatus_png_path = implode(DIRECTORY_SEPARATOR, [VRC_SITE_PATH, 'helpers', 'car_damages', 'car_inspection.png']); |
| 1897 |
if (!empty($car_params['inspection']) && preg_match("/.png$/i", $car_params['inspection'])) { |
| 1898 |
$cms_base_p = defined('ABSPATH') ? ABSPATH : JPATH_SITE; |
| 1899 |
$custom_inspection_p = JPath::clean($cms_base_p . '/' . $car_params['inspection']); |
| 1900 |
if (is_file($custom_inspection_p)) { |
| 1901 |
// must be a relative path to the CMS media manager |
| 1902 |
$cstatus_png_path = $custom_inspection_p; |
| 1903 |
} |
| 1904 |
} else { |
| 1905 |
$car_params['inspection'] = null; |
| 1906 |
} |
| 1907 |
$damage_font = 'helsinki'; |
| 1908 |
$damage_font_size = 11; |
| 1909 |
// Set the enviroment variable for PHP-GD |
| 1910 |
if (function_exists('putenv')) { |
| 1911 |
//font residing in VRC_ADMIN_PATH/resources/ (arial.ttf by default) |
| 1912 |
putenv('GDFONTPATH=' . realpath(VRC_ADMIN_PATH.DS.'resources')); |
| 1913 |
//$font = 'dejavusans'; //i.e. for loading the file dejavusans.ttf or use a custom font |
| 1914 |
} |
| 1915 |
// |
| 1916 |
$gd_available = function_exists('imagecreatefrompng'); |
| 1917 |
if ($gd_available) { |
| 1918 |
$damage_png = imagecreatefrompng($damage_png_path); |
| 1919 |
imagesavealpha($damage_png, true); |
| 1920 |
imagealphablending($damage_png, true); |
| 1921 |
list($damage_png_width, $damage_png_height) = getimagesize($damage_png_path); |
| 1922 |
list($cstatus_png_width, $cstatus_png_height) = getimagesize($cstatus_png_path); |
| 1923 |
} |
| 1924 |
if ($punits > 0) { |
| 1925 |
for ($i=1; $i <= $punits; $i++) { |
| 1926 |
$distf_name = VikRequest::getVar('feature-name'.$i, array()); |
| 1927 |
$distf_lang = VikRequest::getVar('feature-lang'.$i, array()); |
| 1928 |
$distf_value = VikRequest::getVar('feature-value'.$i, array()); |
| 1929 |
foreach ($distf_name as $distf_k => $distf) { |
| 1930 |
if (!empty($distf) && isset($distf_value[$distf_k])) { |
| 1931 |
$use_key = $distf; |
| 1932 |
if (!empty($distf_lang[$distf_k]) && JText::translate($distf_lang[$distf_k]) == $distf) { |
| 1933 |
$use_key = $distf_lang[$distf_k]; |
| 1934 |
} |
| 1935 |
$car_params['features'][$i][$use_key] = $distf_value[$distf_k]; |
| 1936 |
} |
| 1937 |
} |
| 1938 |
//damages |
| 1939 |
$damage_notes = VikRequest::getVar('car-'.$i.'-damage', array()); |
| 1940 |
$damage_notes_x = VikRequest::getVar('car-'.$i.'-damage-x', array()); |
| 1941 |
$damage_notes_y = VikRequest::getVar('car-'.$i.'-damage-y', array()); |
| 1942 |
$dind = 1; |
| 1943 |
foreach ($damage_notes as $dk => $damage) { |
| 1944 |
if (!strlen($damage)) { |
| 1945 |
continue; |
| 1946 |
} |
| 1947 |
if (!isset($damage_notes_x[$dk]) || !strlen($damage_notes_x[$dk])) { |
| 1948 |
continue; |
| 1949 |
} |
| 1950 |
if (!isset($damage_notes_y[$dk]) || !strlen($damage_notes_y[$dk])) { |
| 1951 |
continue; |
| 1952 |
} |
| 1953 |
if (!isset($damages[$i])) { |
| 1954 |
$damages[$i] = array(); |
| 1955 |
} |
| 1956 |
if (!isset($damages[$i][$dind])) { |
| 1957 |
$damages[$i][$dind] = array(); |
| 1958 |
} |
| 1959 |
$damages[$i][$dind]['notes'] = $damage; |
| 1960 |
$damages[$i][$dind]['x'] = $damage_notes_x[$dk]; |
| 1961 |
$damages[$i][$dind]['y'] = $damage_notes_y[$dk]; |
| 1962 |
$dind++; |
| 1963 |
} |
| 1964 |
$tot_dmg = isset($damages[$i]) ? count($damages[$i]) : 0; |
| 1965 |
if ($tot_dmg > 0 && $gd_available) { |
| 1966 |
//generate PNG |
| 1967 |
$base_png = imagecreatefrompng($cstatus_png_path); |
| 1968 |
imagesavealpha($base_png, true); |
| 1969 |
imagealphablending($base_png, true); |
| 1970 |
$unit_png = imagecreatetruecolor($cstatus_png_width, $cstatus_png_height); |
| 1971 |
$white = imagecolorallocate($unit_png, 255, 255, 255); |
| 1972 |
$black = imagecolorallocate($unit_png, 0, 0, 0); |
| 1973 |
imagefill($unit_png, 0, 0, $black); |
| 1974 |
imagecopy($unit_png, $base_png, 0, 0, 0, 0, $cstatus_png_width, $cstatus_png_height); |
| 1975 |
$dk = $tot_dmg; |
| 1976 |
foreach ($damages[$i] as $dind => $dmg_point) { |
| 1977 |
//damage PNG |
| 1978 |
$allocate_x = (int)((int)$dmg_point['x'] - ((int)$damage_png_width / 2)); |
| 1979 |
$allocate_y = (int)((int)$dmg_point['y'] - ((int)$damage_png_height / 2)); |
| 1980 |
imagecopy($unit_png, $damage_png, $allocate_x, $allocate_y, 0, 0, $damage_png_width, $damage_png_height); |
| 1981 |
if ($damage_show_type > 1) { |
| 1982 |
$type_space = imagettfbbox($damage_font_size, 0, $damage_font, (string)$dk); |
| 1983 |
$type_width = floor($type_space[4] - $type_space[0]); |
| 1984 |
$type_height = floor($type_space[5] - $type_space[1]); |
| 1985 |
$allocate_x = ceil((int)$dmg_point['x'] - ((int)$type_width / 2)); |
| 1986 |
$allocate_y = floor((int)$dmg_point['y'] - ((int)$type_height / 2)); |
| 1987 |
imagettftext($unit_png, $damage_font_size, 0, $allocate_x, $allocate_y, $white, $damage_font, (string)$dk); |
| 1988 |
} |
| 1989 |
$dk--; |
| 1990 |
} |
| 1991 |
imagepng($unit_png, VRC_SITE_PATH.DS.'helpers'.DS.'car_damages'.DS.$pwhereup.'_'.$i.'.png'); |
| 1992 |
imagedestroy($unit_png); |
| 1993 |
} else { |
| 1994 |
if (file_exists(VRC_SITE_PATH.DS.'helpers'.DS.'car_damages'.DS.$pwhereup.'_'.$i.'.png')) { |
| 1995 |
unlink(VRC_SITE_PATH.DS.'helpers'.DS.'car_damages'.DS.$pwhereup.'_'.$i.'.png'); |
| 1996 |
} |
| 1997 |
} |
| 1998 |
} |
| 1999 |
if (count($damages) > 0) { |
| 2000 |
$car_params['damages'] = $damages; |
| 2001 |
} |
| 2002 |
} |
| 2003 |
// |
| 2004 |
$dbo = JFactory::getDbo(); |
| 2005 |
$q = "UPDATE `#__vikrentcar_cars` SET `name`=".$dbo->quote($pcname).",".(strlen($picon) > 0 ? "`img`='".$picon."'," : "")."`idcat`=".$dbo->quote($pccatdef).",`idcarat`=".$dbo->quote($pccaratdef).",`idopt`=".$dbo->quote($pcoptionaldef).",`info`=".$dbo->quote($pcdescr).",`idplace`=".$dbo->quote($pcplacedef).",`avail`=".$dbo->quote($pcavaildef).",`units`=".($punits > 0 ? $dbo->quote($punits) : "'1'").",`idretplace`=".$dbo->quote($pcretplacedef).",`moreimgs`=".$dbo->quote($moreimagestr).",`startfrom`=".(strlen($pstartfrom) > 0 ? "'".$pstartfrom."'" : "null").",`short_info`=".$dbo->quote($pshort_info).",`params`=".$dbo->quote(json_encode($car_params)).",`alias`=".$dbo->quote($psefalias)." WHERE `id`=".$dbo->quote($pwhereup).";"; |
| 2006 |
$dbo->setQuery($q); |
| 2007 |
$dbo->execute(); |
| 2008 |
$mainframe->enqueueMessage(JText::translate('VRCCARUPDATEOK')); |
| 2009 |
|
| 2010 |
/** |
| 2011 |
* Import remote iCal calendars. |
| 2012 |
* |
| 2013 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 2014 |
*/ |
| 2015 |
$import_calendars = VikRequest::getVar('calendars', array()); |
| 2016 |
if (empty($import_calendars) || empty($import_calendars['url'])) { |
| 2017 |
// make sure to remove any calendar for this car |
| 2018 |
$q = "DELETE FROM `#__vikrentcar_cars_icals` WHERE `idcar`=" . (int)$pwhereup . ";"; |
| 2019 |
$dbo->setQuery($q); |
| 2020 |
$dbo->execute(); |
| 2021 |
} else { |
| 2022 |
// parse all calendars |
| 2023 |
foreach ($import_calendars['url'] as $cal_key => $cal_url) { |
| 2024 |
$cal_existed = (isset($import_calendars['id']) && !empty($import_calendars['id'][$cal_key])); |
| 2025 |
if (empty($cal_url)) { |
| 2026 |
if ($cal_existed) { |
| 2027 |
$q = "DELETE FROM `#__vikrentcar_cars_icals` WHERE `id`=" . (int)$import_calendars['id'][$cal_key] . ";"; |
| 2028 |
$dbo->setQuery($q); |
| 2029 |
$dbo->execute(); |
| 2030 |
} |
| 2031 |
continue; |
| 2032 |
} |
| 2033 |
// build record object |
| 2034 |
$record = new stdClass; |
| 2035 |
$record->idcar = (int)$pwhereup; |
| 2036 |
$record->name = isset($import_calendars['name']) && !empty($import_calendars['name'][$cal_key]) ? $import_calendars['name'][$cal_key] : JText::translate('VRC_IMPORT_CALENDAR_URL'); |
| 2037 |
$record->url = $cal_url; |
| 2038 |
if ($cal_existed) { |
| 2039 |
// update record |
| 2040 |
$record->id = (int)$import_calendars['id'][$cal_key]; |
| 2041 |
$dbo->updateObject('#__vikrentcar_cars_icals', $record, 'id'); |
| 2042 |
} else { |
| 2043 |
// insert object |
| 2044 |
$dbo->insertObject('#__vikrentcar_cars_icals', $record, 'id'); |
| 2045 |
} |
| 2046 |
} |
| 2047 |
} |
| 2048 |
|
| 2049 |
if ($remain === true) { |
| 2050 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editcar&cid[]=".$pwhereup); |
| 2051 |
exit; |
| 2052 |
} |
| 2053 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 2054 |
} |
| 2055 |
|
| 2056 |
public function clone_car() |
| 2057 |
{ |
| 2058 |
if (!JSession::checkToken()) { |
| 2059 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2060 |
} |
| 2061 |
|
| 2062 |
$app = JFactory::getApplication(); |
| 2063 |
$dbo = JFactory::getDbo(); |
| 2064 |
|
| 2065 |
$car_id = VikRequest::getInt('whereup', 0, 'request'); |
| 2066 |
|
| 2067 |
if (empty($car_id)) { |
| 2068 |
$app->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 2069 |
$app->close(); |
| 2070 |
} |
| 2071 |
|
| 2072 |
$q = "SELECT * FROM `#__vikrentcar_cars` WHERE `id`=" . $car_id; |
| 2073 |
$dbo->setQuery($q); |
| 2074 |
$dbo->execute(); |
| 2075 |
|
| 2076 |
if (!$dbo->getNumRows()) { |
| 2077 |
$app->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 2078 |
$app->close(); |
| 2079 |
} |
| 2080 |
|
| 2081 |
$toclone = $dbo->loadObject(); |
| 2082 |
unset($toclone->id); |
| 2083 |
$toclone->name .= ' (Copy)'; |
| 2084 |
|
| 2085 |
$dbo->insertObject('#__vikrentcar_cars', $toclone, 'id'); |
| 2086 |
|
| 2087 |
if (!isset($toclone->id)) { |
| 2088 |
$app->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 2089 |
$app->close(); |
| 2090 |
} |
| 2091 |
|
| 2092 |
$app->redirect("index.php?option=com_vikrentcar&task=editcar&cid[]=" . $toclone->id); |
| 2093 |
$app->close(); |
| 2094 |
} |
| 2095 |
|
| 2096 |
public function removecar() { |
| 2097 |
if (!JSession::checkToken()) { |
| 2098 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2099 |
} |
| 2100 |
$ids = VikRequest::getVar('cid', array(0)); |
| 2101 |
if (@count($ids)) { |
| 2102 |
$dbo = JFactory::getDbo(); |
| 2103 |
foreach ($ids as $d) { |
| 2104 |
$q = "DELETE FROM `#__vikrentcar_cars` WHERE `id`=".$dbo->quote($d).";"; |
| 2105 |
$dbo->setQuery($q); |
| 2106 |
$dbo->execute(); |
| 2107 |
$q = "DELETE FROM `#__vikrentcar_dispcost` WHERE `idcar`=".$dbo->quote($d).";"; |
| 2108 |
$dbo->setQuery($q); |
| 2109 |
$dbo->execute(); |
| 2110 |
} |
| 2111 |
} |
| 2112 |
$mainframe = JFactory::getApplication(); |
| 2113 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 2114 |
} |
| 2115 |
|
| 2116 |
public function modavail() { |
| 2117 |
$cid = VikRequest::getVar('cid', array(0)); |
| 2118 |
$car = $cid[0]; |
| 2119 |
if (!empty($car)) { |
| 2120 |
$dbo = JFactory::getDbo(); |
| 2121 |
$q = "SELECT `avail` FROM `#__vikrentcar_cars` WHERE `id`=".$dbo->quote($car).";"; |
| 2122 |
$dbo->setQuery($q); |
| 2123 |
$dbo->execute(); |
| 2124 |
$get = $dbo->loadAssocList(); |
| 2125 |
$q = "UPDATE `#__vikrentcar_cars` SET `avail`='".(intval($get[0]['avail'])==1 ? 0 : 1)."' WHERE `id`=".$dbo->quote($car).";"; |
| 2126 |
$dbo->setQuery($q); |
| 2127 |
$dbo->execute(); |
| 2128 |
} |
| 2129 |
$mainframe = JFactory::getApplication(); |
| 2130 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 2131 |
} |
| 2132 |
|
| 2133 |
public function tariffs() { |
| 2134 |
if (!JFactory::getUser()->authorise('core.vrc.prices', 'com_vikrentcar')) { |
| 2135 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 2136 |
} |
| 2137 |
|
| 2138 |
VikRentCarHelper::printHeader("fares"); |
| 2139 |
|
| 2140 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'tariffs')); |
| 2141 |
|
| 2142 |
parent::display(); |
| 2143 |
|
| 2144 |
if (VikRentCar::showFooter()) { |
| 2145 |
VikRentCarHelper::printFooter(); |
| 2146 |
} |
| 2147 |
} |
| 2148 |
|
| 2149 |
public function removetariffs() { |
| 2150 |
if (!JSession::checkToken()) { |
| 2151 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2152 |
} |
| 2153 |
$ids = VikRequest::getVar('cid', array(0)); |
| 2154 |
$pcarid = VikRequest::getString('carid', '', 'request'); |
| 2155 |
if (@count($ids)) { |
| 2156 |
$dbo = JFactory::getDbo(); |
| 2157 |
foreach ($ids as $r) { |
| 2158 |
$x=explode(";", $r); |
| 2159 |
foreach ($x as $rm) { |
| 2160 |
if (!empty($rm)) { |
| 2161 |
$q = "DELETE FROM `#__vikrentcar_dispcost` WHERE `id`=".$dbo->quote($rm).";"; |
| 2162 |
$dbo->setQuery($q); |
| 2163 |
$dbo->execute(); |
| 2164 |
} |
| 2165 |
} |
| 2166 |
} |
| 2167 |
} |
| 2168 |
$mainframe = JFactory::getApplication(); |
| 2169 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=tariffs&cid[]=".$pcarid); |
| 2170 |
} |
| 2171 |
|
| 2172 |
public function tariffshours() { |
| 2173 |
if (!JFactory::getUser()->authorise('core.vrc.prices', 'com_vikrentcar')) { |
| 2174 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 2175 |
} |
| 2176 |
|
| 2177 |
VikRentCarHelper::printHeader("fares"); |
| 2178 |
|
| 2179 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'tariffshours')); |
| 2180 |
|
| 2181 |
parent::display(); |
| 2182 |
|
| 2183 |
if (VikRentCar::showFooter()) { |
| 2184 |
VikRentCarHelper::printFooter(); |
| 2185 |
} |
| 2186 |
} |
| 2187 |
|
| 2188 |
public function removetariffshours() { |
| 2189 |
if (!JSession::checkToken()) { |
| 2190 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2191 |
} |
| 2192 |
$ids = VikRequest::getVar('cid', array(0)); |
| 2193 |
$pcarid = VikRequest::getString('carid', '', 'request'); |
| 2194 |
if (@count($ids)) { |
| 2195 |
$dbo = JFactory::getDbo(); |
| 2196 |
foreach ($ids as $r) { |
| 2197 |
$x = explode(";", $r); |
| 2198 |
foreach ($x as $rm) { |
| 2199 |
if (!empty($rm)) { |
| 2200 |
$q = "DELETE FROM `#__vikrentcar_dispcosthours` WHERE `id`=".$dbo->quote($rm).";"; |
| 2201 |
$dbo->setQuery($q); |
| 2202 |
$dbo->execute(); |
| 2203 |
} |
| 2204 |
} |
| 2205 |
} |
| 2206 |
} |
| 2207 |
$mainframe = JFactory::getApplication(); |
| 2208 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=tariffshours&cid[]=".$pcarid); |
| 2209 |
} |
| 2210 |
|
| 2211 |
public function hourscharges() { |
| 2212 |
if (!JFactory::getUser()->authorise('core.vrc.prices', 'com_vikrentcar')) { |
| 2213 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 2214 |
} |
| 2215 |
|
| 2216 |
VikRentCarHelper::printHeader("fares"); |
| 2217 |
|
| 2218 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'hourscharges')); |
| 2219 |
|
| 2220 |
parent::display(); |
| 2221 |
|
| 2222 |
if (VikRentCar::showFooter()) { |
| 2223 |
VikRentCarHelper::printFooter(); |
| 2224 |
} |
| 2225 |
} |
| 2226 |
|
| 2227 |
public function removehourscharges() { |
| 2228 |
if (!JSession::checkToken()) { |
| 2229 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2230 |
} |
| 2231 |
$ids = VikRequest::getVar('cid', array(0)); |
| 2232 |
$pcarid = VikRequest::getString('carid', '', 'request'); |
| 2233 |
if (@count($ids)) { |
| 2234 |
$dbo = JFactory::getDbo(); |
| 2235 |
foreach ($ids as $r) { |
| 2236 |
$x=explode(";", $r); |
| 2237 |
foreach ($x as $rm) { |
| 2238 |
if (!empty($rm)) { |
| 2239 |
$q = "DELETE FROM `#__vikrentcar_hourscharges` WHERE `id`=".$dbo->quote($rm).";"; |
| 2240 |
$dbo->setQuery($q); |
| 2241 |
$dbo->execute(); |
| 2242 |
} |
| 2243 |
} |
| 2244 |
} |
| 2245 |
} |
| 2246 |
$mainframe = JFactory::getApplication(); |
| 2247 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=hourscharges&cid[]=".$pcarid); |
| 2248 |
} |
| 2249 |
|
| 2250 |
public function cancel() { |
| 2251 |
$mainframe = JFactory::getApplication(); |
| 2252 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=cars"); |
| 2253 |
} |
| 2254 |
|
| 2255 |
public function calendar() { |
| 2256 |
VikRentCarHelper::printHeader("19"); |
| 2257 |
|
| 2258 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'calendar')); |
| 2259 |
|
| 2260 |
parent::display(); |
| 2261 |
|
| 2262 |
if (VikRentCar::showFooter()) { |
| 2263 |
VikRentCarHelper::printFooter(); |
| 2264 |
} |
| 2265 |
} |
| 2266 |
|
| 2267 |
public function cancelcalendar() { |
| 2268 |
$pidcar = VikRequest::getString('idcar', '', 'request'); |
| 2269 |
$preturn = VikRequest::getString('return', '', 'request'); |
| 2270 |
$pidorder = VikRequest::getString('idorder', '', 'request'); |
| 2271 |
$mainframe = JFactory::getApplication(); |
| 2272 |
if ($preturn == 'order' && !empty($pidorder)) { |
| 2273 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=".$pidorder); |
| 2274 |
} else { |
| 2275 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=calendar&cid[]=".$pidcar); |
| 2276 |
} |
| 2277 |
} |
| 2278 |
|
| 2279 |
public function goconfig() { |
| 2280 |
$mainframe = JFactory::getApplication(); |
| 2281 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=config"); |
| 2282 |
} |
| 2283 |
|
| 2284 |
public function config() { |
| 2285 |
VikRentCarHelper::printHeader("11"); |
| 2286 |
|
| 2287 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'config')); |
| 2288 |
|
| 2289 |
parent::display(); |
| 2290 |
|
| 2291 |
if (VikRentCar::showFooter()) { |
| 2292 |
VikRentCarHelper::printFooter(); |
| 2293 |
} |
| 2294 |
} |
| 2295 |
|
| 2296 |
public function saveconfig() |
| 2297 |
{ |
| 2298 |
if (!JSession::checkToken()) { |
| 2299 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2300 |
} |
| 2301 |
|
| 2302 |
$dbo = JFactory::getDbo(); |
| 2303 |
$app = JFactory::getApplication(); |
| 2304 |
$session = JFactory::getSession(); |
| 2305 |
|
| 2306 |
$config = VRCFactory::getConfig(); |
| 2307 |
|
| 2308 |
$pallowrent = VikRequest::getString('allowrent', '', 'request'); |
| 2309 |
$pdisabledrentmsg = VikRequest::getString('disabledrentmsg', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2310 |
$ptimeopenstorealw = VikRequest::getString('timeopenstorealw', '', 'request'); |
| 2311 |
$ptimeopenstorefh = VikRequest::getString('timeopenstorefh', '', 'request'); |
| 2312 |
$ptimeopenstorefm = VikRequest::getString('timeopenstorefm', '', 'request'); |
| 2313 |
$ptimeopenstoreth = VikRequest::getString('timeopenstoreth', '', 'request'); |
| 2314 |
$ptimeopenstoretm = VikRequest::getString('timeopenstoretm', '', 'request'); |
| 2315 |
$phoursmorerentback = VikRequest::getString('hoursmorerentback', '', 'request'); |
| 2316 |
$phoursmorecaravail = VikRequest::getString('hoursmorecaravail', '', 'request'); |
| 2317 |
$pplacesfront = VikRequest::getString('placesfront', '', 'request'); |
| 2318 |
$pdateformat = VikRequest::getString('dateformat', '', 'request'); |
| 2319 |
$ptimeformat = VikRequest::getString('timeformat', '', 'request'); |
| 2320 |
$pshowcategories = VikRequest::getString('showcategories', '', 'request'); |
| 2321 |
$pcharatsfilter = VikRequest::getString('charatsfilter', '', 'request'); |
| 2322 |
$pcharatsfilter = $pcharatsfilter == 'yes' ? 1 : 0; |
| 2323 |
$pdamageshowtype = VikRequest::getInt('damageshowtype', '', 'request'); |
| 2324 |
$pdamageshowtype = $pdamageshowtype > 0 && $pdamageshowtype < 4 ? $pdamageshowtype : 1; |
| 2325 |
$ptokenform = VikRequest::getString('tokenform', '', 'request'); |
| 2326 |
$padminemail = VikRequest::getString('adminemail', '', 'request'); |
| 2327 |
$psenderemail = VikRequest::getString('senderemail', '', 'request'); |
| 2328 |
$picalkey = VikRequest::getString('icalkey', '', 'request'); |
| 2329 |
$picalkey = str_replace(' ', '', $picalkey); |
| 2330 |
$pminuteslock = VikRequest::getString('minuteslock', '', 'request'); |
| 2331 |
$pfooterordmail = VikRequest::getString('footerordmail', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2332 |
$prequirelogin = VikRequest::getString('requirelogin', '', 'request'); |
| 2333 |
$pusefa = VikRequest::getInt('usefa', '', 'request'); |
| 2334 |
$pusefa = $pusefa > 0 ? 1 : 0; |
| 2335 |
$ploadjquery = VikRequest::getString('loadjquery', '', 'request'); |
| 2336 |
$ploadjquery = $ploadjquery == "yes" ? "1" : "0"; |
| 2337 |
$pcalendar = VikRequest::getString('calendar', '', 'request'); |
| 2338 |
$pcalendar = $pcalendar == "joomla" ? "joomla" : "jqueryui"; |
| 2339 |
$pehourschbasp = VikRequest::getString('ehourschbasp', '', 'request'); |
| 2340 |
$pehourschbasp = $pehourschbasp == "1" ? 1 : 0; |
| 2341 |
$penablecoupons = VikRequest::getString('enablecoupons', '', 'request'); |
| 2342 |
$penablecoupons = $penablecoupons == "1" ? 1 : 0; |
| 2343 |
$penablepin = VikRequest::getInt('enablepin', 0, 'request'); |
| 2344 |
$penablepin = $penablepin > 0 ? 1 : 0; |
| 2345 |
$ptodaybookings = VikRequest::getString('todaybookings', '', 'request'); |
| 2346 |
$ptodaybookings = $ptodaybookings == "1" ? 1 : 0; |
| 2347 |
$ppickondrop = VikRequest::getInt('pickondrop', '', 'request'); |
| 2348 |
$ppickondrop = $ppickondrop === 1 ? 1 : 0; |
| 2349 |
$psetdropdplus = VikRequest::getString('setdropdplus', '', 'request'); |
| 2350 |
$psetdropdplus = !empty($psetdropdplus) ? intval($psetdropdplus) : ''; |
| 2351 |
$pmindaysadvance = VikRequest::getInt('mindaysadvance', '', 'request'); |
| 2352 |
$pmindaysadvance = $pmindaysadvance < 0 ? 0 : $pmindaysadvance; |
| 2353 |
$pmaxdate = VikRequest::getString('maxdate', '', 'request'); |
| 2354 |
$pmaxdate = intval($pmaxdate) < 1 ? 2 : $pmaxdate; |
| 2355 |
$pmaxdateinterval = VikRequest::getString('maxdateinterval', '', 'request'); |
| 2356 |
$pmaxdateinterval = !in_array($pmaxdateinterval, array('d', 'w', 'm', 'y')) ? 'y' : $pmaxdateinterval; |
| 2357 |
$maxdate_str = '+'.$pmaxdate.$pmaxdateinterval; |
| 2358 |
$pvrcsef = VikRequest::getInt('vrcsef', '', 'request'); |
| 2359 |
$vrcsef = file_exists(VRC_SITE_PATH.DS.'router.php'); |
| 2360 |
if ($pvrcsef === 1) { |
| 2361 |
if (!$vrcsef) { |
| 2362 |
rename(VRC_SITE_PATH.DS.'_router.php', VRC_SITE_PATH.DS.'router.php'); |
| 2363 |
} |
| 2364 |
} else { |
| 2365 |
if ($vrcsef) { |
| 2366 |
rename(VRC_SITE_PATH.DS.'router.php', VRC_SITE_PATH.DS.'_router.php'); |
| 2367 |
} |
| 2368 |
} |
| 2369 |
$pcronkey = VikRequest::getString('cronkey', '', 'request'); |
| 2370 |
$pmultilang = VikRequest::getString('multilang', '', 'request'); |
| 2371 |
$pmultilang = $pmultilang == "1" ? 1 : 0; |
| 2372 |
$res_backend_path = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 2373 |
$picon=""; |
| 2374 |
if (intval($_FILES['sitelogo']['error']) == 0 && trim($_FILES['sitelogo']['name'])!="") { |
| 2375 |
jimport('joomla.filesystem.file'); |
| 2376 |
if (@is_uploaded_file($_FILES['sitelogo']['tmp_name'])) { |
| 2377 |
$safename=JFile::makeSafe(str_replace(" ", "_", strtolower($_FILES['sitelogo']['name']))); |
| 2378 |
if (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename)) { |
| 2379 |
$j=1; |
| 2380 |
while (file_exists(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename)) { |
| 2381 |
$j++; |
| 2382 |
} |
| 2383 |
$pwhere=VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$j.$safename; |
| 2384 |
} else { |
| 2385 |
$j=""; |
| 2386 |
$pwhere=VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.$safename; |
| 2387 |
} |
| 2388 |
if (!getimagesize($_FILES['sitelogo']['tmp_name']) || !preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $safename)) { |
| 2389 |
@unlink($pwhere); |
| 2390 |
} elseif (VikRentCar::uploadFile($_FILES['sitelogo']['tmp_name'], $pwhere)) { |
| 2391 |
@chmod($pwhere, 0644); |
| 2392 |
$picon=$j.$safename; |
| 2393 |
} |
| 2394 |
} |
| 2395 |
if (!empty($picon)) { |
| 2396 |
$config->set('sitelogo', $picon); |
| 2397 |
} |
| 2398 |
} |
| 2399 |
$pbackicon = ""; |
| 2400 |
if (intval($_FILES['backlogo']['error']) == 0 && trim($_FILES['backlogo']['name'])!="") { |
| 2401 |
jimport('joomla.filesystem.file'); |
| 2402 |
if (@is_uploaded_file($_FILES['backlogo']['tmp_name'])) { |
| 2403 |
$safename = JFile::makeSafe(str_replace(" ", "_", strtolower($_FILES['backlogo']['name']))); |
| 2404 |
if (file_exists($res_backend_path.$safename)) { |
| 2405 |
$j=1; |
| 2406 |
while (file_exists($res_backend_path.$j.$safename)) { |
| 2407 |
$j++; |
| 2408 |
} |
| 2409 |
$pwhere=$res_backend_path.$j.$safename; |
| 2410 |
} else { |
| 2411 |
$j=""; |
| 2412 |
$pwhere=$res_backend_path.$safename; |
| 2413 |
} |
| 2414 |
if (!getimagesize($_FILES['backlogo']['tmp_name']) || !preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $safename)) { |
| 2415 |
@unlink($pwhere); |
| 2416 |
} elseif (VikRentCar::uploadFile($_FILES['backlogo']['tmp_name'], $pwhere)) { |
| 2417 |
@chmod($pwhere, 0644); |
| 2418 |
$pbackicon=$j.$safename; |
| 2419 |
} |
| 2420 |
} |
| 2421 |
if (!empty($pbackicon)) { |
| 2422 |
$config->set('backlogo', $pbackicon); |
| 2423 |
} |
| 2424 |
} |
| 2425 |
|
| 2426 |
if (empty($pallowrent) || $pallowrent != "1") { |
| 2427 |
$config->set('allowrent', 0); |
| 2428 |
} else { |
| 2429 |
$config->set('allowrent', 1); |
| 2430 |
} |
| 2431 |
|
| 2432 |
if (empty($pplacesfront) || $pplacesfront != "yes") { |
| 2433 |
$config->set('placesfront', 0); |
| 2434 |
} else { |
| 2435 |
$config->set('placesfront', 1); |
| 2436 |
} |
| 2437 |
|
| 2438 |
if (empty($pshowcategories) || $pshowcategories != "yes") { |
| 2439 |
$config->set('showcategories', 0); |
| 2440 |
} else { |
| 2441 |
$config->set('showcategories', 1); |
| 2442 |
} |
| 2443 |
|
| 2444 |
$config->set('charatsfilter', $pcharatsfilter); |
| 2445 |
$config->set('damageshowtype', $pdamageshowtype); |
| 2446 |
|
| 2447 |
if (empty($ptokenform) || $ptokenform != "yes") { |
| 2448 |
$config->set('tokenform', 0); |
| 2449 |
} else { |
| 2450 |
$config->set('tokenform', 1); |
| 2451 |
} |
| 2452 |
|
| 2453 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=".$dbo->quote($pfooterordmail)." WHERE `param`='footerordmail';"; |
| 2454 |
$dbo->setQuery($q); |
| 2455 |
$dbo->execute(); |
| 2456 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=".$dbo->quote($pdisabledrentmsg)." WHERE `param`='disabledrentmsg';"; |
| 2457 |
$dbo->setQuery($q); |
| 2458 |
$dbo->execute(); |
| 2459 |
|
| 2460 |
/** |
| 2461 |
* PDF contract text. |
| 2462 |
* |
| 2463 |
* @since 1.15.5 (J) - 1.4.0 (WP) |
| 2464 |
*/ |
| 2465 |
$pdf_contract_text = VikRequest::getString('pdf_contract_text', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2466 |
// replace any possible placeholder for special tags |
| 2467 |
$pdf_contract_text = preg_replace_callback("/(<strong class=\"vrc-editor-hl-specialtag\">)([^<]+)(<\/strong>)/", function($match) { |
| 2468 |
return $match[2]; |
| 2469 |
}, $pdf_contract_text); |
| 2470 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=" . $dbo->q($pdf_contract_text) . " WHERE `param`='pdf_contract_text';"; |
| 2471 |
$dbo->setQuery($q); |
| 2472 |
$dbo->execute(); |
| 2473 |
|
| 2474 |
$config->set('adminemail', $padminemail); |
| 2475 |
$config->set('senderemail', $psenderemail); |
| 2476 |
$config->set('icalkey', $picalkey); |
| 2477 |
$config->set('multilang', $pmultilang); |
| 2478 |
|
| 2479 |
if (empty($pdateformat)) { |
| 2480 |
$pdateformat="%d/%m/%Y"; |
| 2481 |
} |
| 2482 |
$config->set('dateformat', $pdateformat); |
| 2483 |
$session->set('getDateFormat', ''); |
| 2484 |
|
| 2485 |
$config->set('timeformat', $ptimeformat); |
| 2486 |
$config->set('minuteslock', $pminuteslock); |
| 2487 |
|
| 2488 |
if (!empty($ptimeopenstorealw)) { |
| 2489 |
$config->set('timeopenstore', ''); |
| 2490 |
} else { |
| 2491 |
$openingh = $ptimeopenstorefh * 3600; |
| 2492 |
$openingm = $ptimeopenstorefm * 60; |
| 2493 |
$openingts = $openingh + $openingm; |
| 2494 |
$closingh = $ptimeopenstoreth * 3600; |
| 2495 |
$closingm = $ptimeopenstoretm * 60; |
| 2496 |
$closingts = $closingh + $closingm; |
| 2497 |
if ($closingts <= $openingts) { |
| 2498 |
$config->set('timeopenstore', ''); |
| 2499 |
} else { |
| 2500 |
$config->set('timeopenstore', "{$openingts}-{$closingts}"); |
| 2501 |
} |
| 2502 |
} |
| 2503 |
|
| 2504 |
if (!ctype_digit($phoursmorerentback)) { |
| 2505 |
$phoursmorerentback="0"; |
| 2506 |
} |
| 2507 |
if (!ctype_digit($phoursmorecaravail)) { |
| 2508 |
$phoursmorecaravail="0"; |
| 2509 |
} |
| 2510 |
$config->set('hoursmorerentback', $phoursmorerentback); |
| 2511 |
$config->set('hoursmorecaravail', $phoursmorecaravail); |
| 2512 |
$config->set('requirelogin', ($prequirelogin == "1" ? "1" : "0")); |
| 2513 |
$config->set('usefa', (string)$pusefa); |
| 2514 |
|
| 2515 |
|
| 2516 |
$config->set('loadjquery', $ploadjquery); |
| 2517 |
$config->set('calendar', $pcalendar); |
| 2518 |
$config->set('ehourschbasp', $pehourschbasp); |
| 2519 |
$config->set('enablecoupons', $penablecoupons); |
| 2520 |
$config->set('enablepin', $penablepin); |
| 2521 |
$config->set('todaybookings', $ptodaybookings); |
| 2522 |
$config->set('pickondrop', (string)$ppickondrop); |
| 2523 |
$config->set('setdropdplus', $psetdropdplus); |
| 2524 |
$config->set('mindaysadvance', $pmindaysadvance); |
| 2525 |
$config->set('maxdate', $maxdate_str); |
| 2526 |
$config->set('cronkey', $pcronkey); |
| 2527 |
|
| 2528 |
if (VRCPlatformDetection::isWordPress()) { |
| 2529 |
/** |
| 2530 |
* Toggle the loading of the Bootstrap assets on any site section. |
| 2531 |
* |
| 2532 |
* @since 1.1.4 |
| 2533 |
*/ |
| 2534 |
$pbootstrap = VikRequest::getInt('bootstrap', 0, 'request'); |
| 2535 |
$config->set('bootstrap', $pbootstrap); |
| 2536 |
} |
| 2537 |
|
| 2538 |
// preferred countries ordering, or custom countries. |
| 2539 |
$pref_countries = VikRequest::getVar('pref_countries', array()); |
| 2540 |
$cust_pref_countries = VikRequest::getString('cust_pref_countries', '', 'request'); |
| 2541 |
$pref_countries = !is_array($pref_countries) || empty($pref_countries[0]) ? VikRentCar::preferredCountriesOrdering() : $pref_countries; |
| 2542 |
if (!empty($cust_pref_countries)) { |
| 2543 |
$all_custom_prefcountries = array(); |
| 2544 |
$cust_pref_countries = explode(',', $cust_pref_countries); |
| 2545 |
foreach ($cust_pref_countries as $cust_pref_country) { |
| 2546 |
$cust_pref_country = trim(strtolower($cust_pref_country)); |
| 2547 |
if (empty($cust_pref_country) || strlen($cust_pref_country) != 2) { |
| 2548 |
continue; |
| 2549 |
} |
| 2550 |
array_push($all_custom_prefcountries, $cust_pref_country); |
| 2551 |
} |
| 2552 |
if (count($all_custom_prefcountries)) { |
| 2553 |
$pref_countries = $all_custom_prefcountries; |
| 2554 |
} |
| 2555 |
} |
| 2556 |
$config->set('preferred_countries', json_encode($pref_countries)); |
| 2557 |
|
| 2558 |
$psearchsuggestions = VikRequest::getInt('searchsuggestions', 0, 'request'); |
| 2559 |
$config->set('searchsuggestions', $psearchsuggestions); |
| 2560 |
|
| 2561 |
$pmultipay = VikRequest::getInt('multipay', 0, 'request'); |
| 2562 |
$config->set('multipay', $pmultipay); |
| 2563 |
|
| 2564 |
$pdocsupload = VikRequest::getInt('docsupload', 0, 'request'); |
| 2565 |
$config->set('docsupload', $pdocsupload); |
| 2566 |
|
| 2567 |
$pdocsuploadinstr = VikRequest::getString('docsuploadinstr', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2568 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=".$dbo->quote($pdocsuploadinstr)." WHERE `param`='docsuploadinstr';"; |
| 2569 |
$dbo->setQuery($q); |
| 2570 |
$dbo->execute(); |
| 2571 |
|
| 2572 |
$pref_textcolor = VikRequest::getString('pref_textcolor', '', 'request'); |
| 2573 |
$pref_bgcolor = VikRequest::getString('pref_bgcolor', '', 'request'); |
| 2574 |
$pref_fontcolor = VikRequest::getString('pref_fontcolor', '', 'request'); |
| 2575 |
$pref_bgcolorhov = VikRequest::getString('pref_bgcolorhov', '', 'request'); |
| 2576 |
$pref_fontcolorhov = VikRequest::getString('pref_fontcolorhov', '', 'request'); |
| 2577 |
$pref_colors = array( |
| 2578 |
'textcolor' => $pref_textcolor, |
| 2579 |
'bgcolor' => $pref_bgcolor, |
| 2580 |
'fontcolor' => $pref_fontcolor, |
| 2581 |
'bgcolorhov' => $pref_bgcolorhov, |
| 2582 |
'fontcolorhov' => $pref_fontcolorhov, |
| 2583 |
); |
| 2584 |
$config->set('pref_colors', json_encode($pref_colors)); |
| 2585 |
|
| 2586 |
/** |
| 2587 |
* Appearance preferences (light, auto, dark mode). |
| 2588 |
* |
| 2589 |
* @since 1.15.5 (J) - 1.4.0 (WP) |
| 2590 |
*/ |
| 2591 |
$appearance_pref = VikRequest::getString('appearance_pref', ''); |
| 2592 |
$appearance_front = VikRequest::getInt('appearance_front', 0); |
| 2593 |
$config->set('appearance_pref', $appearance_pref); |
| 2594 |
$config->set('appearance_front', $appearance_front); |
| 2595 |
|
| 2596 |
$pfronttitle = VikRequest::getString('fronttitle', '', 'request'); |
| 2597 |
$pshowfooter = VikRequest::getString('showfooter', '', 'request'); |
| 2598 |
$pintromain = VikRequest::getString('intromain', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2599 |
$pclosingmain = VikRequest::getString('closingmain', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2600 |
$pcurrencyname = VikRequest::getString('currencyname', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2601 |
$pcurrencysymb = VikRequest::getString('currencysymb', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2602 |
$pcurrencycodepp = VikRequest::getString('currencycodepp', '', 'request'); |
| 2603 |
$pnumdecimals = VikRequest::getString('numdecimals', '', 'request'); |
| 2604 |
$pnumdecimals = intval($pnumdecimals); |
| 2605 |
$pdecseparator = VikRequest::getString('decseparator', '', 'request'); |
| 2606 |
$pdecseparator = empty($pdecseparator) ? '.' : $pdecseparator; |
| 2607 |
$pthoseparator = VikRequest::getString('thoseparator', '', 'request'); |
| 2608 |
$numberformatstr = $pnumdecimals.':'.$pdecseparator.':'.$pthoseparator; |
| 2609 |
$pshowpartlyreserved = VikRequest::getString('showpartlyreserved', '', 'request'); |
| 2610 |
$pshowpartlyreserved = $pshowpartlyreserved == "yes" ? 1 : 0; |
| 2611 |
$pnumcalendars = VikRequest::getInt('numcalendars', '', 'request'); |
| 2612 |
$pnumcalendars = $pnumcalendars > -1 ? $pnumcalendars : 3; |
| 2613 |
$pthumbswidth = VikRequest::getInt('thumbswidth', '', 'request'); |
| 2614 |
$pthumbswidth = $pthumbswidth > 0 ? $pthumbswidth : 100; |
| 2615 |
$pfirstwday = VikRequest::getString('firstwday', '', 'request'); |
| 2616 |
$pfirstwday = intval($pfirstwday) >= 0 && intval($pfirstwday) <= 6 ? $pfirstwday : '0'; |
| 2617 |
|
| 2618 |
/** |
| 2619 |
* Search results style. |
| 2620 |
* |
| 2621 |
* @since 1.15.5 (J) - 1.4.0 (WP) |
| 2622 |
*/ |
| 2623 |
$config->set('searchresstyle', VikRequest::getString('searchresstyle', 'list', 'request')); |
| 2624 |
|
| 2625 |
// iCal export past months |
| 2626 |
$config->set('ical_past_months', VikRequest::getInt('ical_past_months', 0, 'request')); |
| 2627 |
|
| 2628 |
// Google Maps API Key |
| 2629 |
$pgmapskey = VikRequest::getString('gmapskey', '', 'request'); |
| 2630 |
$config->set('gmapskey', $pgmapskey); |
| 2631 |
|
| 2632 |
// Ipinfo.io API Token |
| 2633 |
$pipinfo_token = VikRequest::getString('ipinfo_token', '', 'request'); |
| 2634 |
$config->set('ipinfo_token', $pipinfo_token); |
| 2635 |
|
| 2636 |
// theme |
| 2637 |
$ptheme = VikRequest::getString('theme', '', 'request'); |
| 2638 |
if (empty($ptheme) || $ptheme == 'default') { |
| 2639 |
$ptheme = 'default'; |
| 2640 |
} else { |
| 2641 |
$validtheme = false; |
| 2642 |
$themes = glob(VRC_SITE_PATH.DS.'themes'.DS.'*'); |
| 2643 |
if ($themes) { |
| 2644 |
$strip = VRC_SITE_PATH.DS.'themes'.DS; |
| 2645 |
foreach ($themes as $th) { |
| 2646 |
if (is_dir($th)) { |
| 2647 |
$tname = str_replace($strip, '', $th); |
| 2648 |
if ($tname == $ptheme) { |
| 2649 |
$validtheme = true; |
| 2650 |
break; |
| 2651 |
} |
| 2652 |
} |
| 2653 |
} |
| 2654 |
} |
| 2655 |
if ($validtheme == false) { |
| 2656 |
$ptheme = 'default'; |
| 2657 |
} |
| 2658 |
} |
| 2659 |
$config->set('theme', $ptheme); |
| 2660 |
|
| 2661 |
$config->set('showpartlyreserved', $pshowpartlyreserved); |
| 2662 |
$config->set('numcalendars', $pnumcalendars); |
| 2663 |
$config->set('thumbswidth', $pthumbswidth); |
| 2664 |
$config->set('firstwday', $pfirstwday); |
| 2665 |
$config->set('currencyname', $pcurrencyname); |
| 2666 |
$config->set('currencysymb', $pcurrencysymb); |
| 2667 |
$config->set('currencycodepp', $pcurrencycodepp); |
| 2668 |
$config->set('numberformat', $numberformatstr); |
| 2669 |
if (empty($pshowfooter) || $pshowfooter != "yes") { |
| 2670 |
$config->set('showfooter', 0); |
| 2671 |
} else { |
| 2672 |
$config->set('showfooter', 1); |
| 2673 |
} |
| 2674 |
$session->set('getCurrencySymb', ''); |
| 2675 |
|
| 2676 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=".$dbo->quote($pfronttitle)." WHERE `param`='fronttitle';"; |
| 2677 |
$dbo->setQuery($q); |
| 2678 |
$dbo->execute(); |
| 2679 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=".$dbo->quote($pintromain)." WHERE `param`='intromain';"; |
| 2680 |
$dbo->setQuery($q); |
| 2681 |
$dbo->execute(); |
| 2682 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=".$dbo->quote($pclosingmain)." WHERE `param`='closingmain';"; |
| 2683 |
$dbo->setQuery($q); |
| 2684 |
$dbo->execute(); |
| 2685 |
|
| 2686 |
$pivainclusa = VikRequest::getString('ivainclusa', '', 'request'); |
| 2687 |
$ptaxsummary = VikRequest::getString('taxsummary', '', 'request'); |
| 2688 |
$ptaxsummary = empty($ptaxsummary) || $ptaxsummary != "yes" ? "0" : "1"; |
| 2689 |
$pccpaypal = VikRequest::getString('ccpaypal', '', 'request'); |
| 2690 |
$ppaytotal = VikRequest::getString('paytotal', '', 'request'); |
| 2691 |
$ppayaccpercent = VikRequest::getString('payaccpercent', '', 'request'); |
| 2692 |
$ptypedeposit = VikRequest::getString('typedeposit', '', 'request'); |
| 2693 |
$ptypedeposit = $ptypedeposit == 'fixed' ? 'fixed' : 'pcent'; |
| 2694 |
$ppaymentname = VikRequest::getString('paymentname', '', 'request'); |
| 2695 |
if (empty($pivainclusa) || $pivainclusa != "yes") { |
| 2696 |
$config->set('ivainclusa', 0); |
| 2697 |
} else { |
| 2698 |
$config->set('ivainclusa', 1); |
| 2699 |
} |
| 2700 |
if (empty($ppaytotal) || $ppaytotal != "yes") { |
| 2701 |
$config->set('paytotal', 0); |
| 2702 |
} else { |
| 2703 |
$config->set('paytotal', 1); |
| 2704 |
} |
| 2705 |
$config->set('depcustchoice', VikRequest::getInt('depcustchoice', 0, 'request')); |
| 2706 |
|
| 2707 |
$config->set('taxsummary', $ptaxsummary); |
| 2708 |
$config->set('ccpaypal', $pccpaypal); |
| 2709 |
$config->set('payaccpercent', $ppayaccpercent); |
| 2710 |
$config->set('typedeposit', $ptypedeposit); |
| 2711 |
|
| 2712 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=".$dbo->quote($ppaymentname)." WHERE `param`='paymentname';"; |
| 2713 |
$dbo->setQuery($q); |
| 2714 |
$dbo->execute(); |
| 2715 |
|
| 2716 |
$psendpdf = VikRequest::getString('sendpdf', '', 'request'); |
| 2717 |
$pdisclaimer = VikRequest::getString('disclaimer', '', 'request', VIKREQUEST_ALLOWHTML); |
| 2718 |
|
| 2719 |
if (empty($psendpdf) || $psendpdf != "yes") { |
| 2720 |
$config->set('sendpdf', 0); |
| 2721 |
} else { |
| 2722 |
$config->set('sendpdf', 1); |
| 2723 |
} |
| 2724 |
|
| 2725 |
$psendemailwhen = VikRequest::getInt('sendemailwhen', '', 'request'); |
| 2726 |
$psendemailwhen = $psendemailwhen > 1 ? 2 : 1; |
| 2727 |
$pattachical = VikRequest::getInt('attachical', 0, 'request'); |
| 2728 |
$pattachical = $pattachical >= 0 && $pattachical <= 3 ? $pattachical : 1; |
| 2729 |
$picalendtype = VikRequest::getString('icalendtype', '', 'request'); |
| 2730 |
$picalendtype = $picalendtype == 'pick' ? 'pick' : 'drop'; |
| 2731 |
|
| 2732 |
$config->set('emailsendwhen', $psendemailwhen); |
| 2733 |
$config->set('attachical', $pattachical); |
| 2734 |
$config->set('icalendtype', $picalendtype); |
| 2735 |
|
| 2736 |
$q = "UPDATE `#__vikrentcar_texts` SET `setting`=".$dbo->quote($pdisclaimer)." WHERE `param`='disclaimer';"; |
| 2737 |
$dbo->setQuery($q); |
| 2738 |
$dbo->execute(); |
| 2739 |
|
| 2740 |
/** |
| 2741 |
* Backup settings |
| 2742 |
* |
| 2743 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 2744 |
*/ |
| 2745 |
$backup_type = $app->input->getString('backuptype', 'full'); |
| 2746 |
$backup_folder = $app->input->getString('backupfolder', ''); |
| 2747 |
|
| 2748 |
$tmp = $app->get('tmp_path'); |
| 2749 |
|
| 2750 |
if (!$backup_folder) |
| 2751 |
{ |
| 2752 |
// path not specified, use temporary folder |
| 2753 |
$backup_folder = $tmp; |
| 2754 |
} |
| 2755 |
|
| 2756 |
$current = $config->get('backupfolder'); |
| 2757 |
|
| 2758 |
if (!$current) |
| 2759 |
{ |
| 2760 |
// path was missing, use temporary folder |
| 2761 |
$current = $tmp; |
| 2762 |
} |
| 2763 |
|
| 2764 |
// check whether the backup folder has been moved |
| 2765 |
if ($current && $backup_folder && rtrim($current, DIRECTORY_SEPARATOR) !== rtrim($backup_folder, DIRECTORY_SEPARATOR)) |
| 2766 |
{ |
| 2767 |
$backupModel = new VRCModelBackup(); |
| 2768 |
|
| 2769 |
// backup folder moved, try to copy all the existing overrides |
| 2770 |
if (!$backupModel->moveArchives($backup_folder)) |
| 2771 |
{ |
| 2772 |
// iterate all errors and display them |
| 2773 |
foreach ($backupModel->getErrors() as $error) |
| 2774 |
{ |
| 2775 |
$app->enqueueMessage($error, 'warning'); |
| 2776 |
} |
| 2777 |
} |
| 2778 |
} |
| 2779 |
|
| 2780 |
// save configuration |
| 2781 |
$config->set('backuptype', $backup_type); |
| 2782 |
$config->set('backupfolder', $backup_folder); |
| 2783 |
|
| 2784 |
// forced pickup/drop off times |
| 2785 |
$forcedtimes = $app->input->getInt('forcedtimes', 0); |
| 2786 |
$forced_pickup = $forcedtimes ? $app->input->getString('forced_pickup', '') : ''; |
| 2787 |
$forced_dropoff = $forcedtimes ? $app->input->getString('forced_dropoff', '') : ''; |
| 2788 |
|
| 2789 |
$config->set('forced_pickup', $forced_pickup); |
| 2790 |
$config->set('forced_dropoff', $forced_dropoff); |
| 2791 |
|
| 2792 |
// auto-assign car unit |
| 2793 |
$config->set('autocarunit', $app->input->getInt('autocarunit', 0)); |
| 2794 |
|
| 2795 |
$app->enqueueMessage(JText::translate('VRSETTINGSAVED')); |
| 2796 |
$app->redirect("index.php?option=com_vikrentcar&task=config"); |
| 2797 |
} |
| 2798 |
|
| 2799 |
public function renewsession() { |
| 2800 |
/* |
| 2801 |
* @wponly |
| 2802 |
* We just destroy the session |
| 2803 |
*/ |
| 2804 |
JSessionHandler::destroy(); |
| 2805 |
$mainframe = JFactory::getApplication(); |
| 2806 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=config"); |
| 2807 |
} |
| 2808 |
|
| 2809 |
public function trackings() { |
| 2810 |
VikRentCarHelper::printHeader("trackings"); |
| 2811 |
|
| 2812 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'trackings')); |
| 2813 |
|
| 2814 |
parent::display(); |
| 2815 |
|
| 2816 |
if (VikRentCar::showFooter()) { |
| 2817 |
VikRentCarHelper::printFooter(); |
| 2818 |
} |
| 2819 |
} |
| 2820 |
|
| 2821 |
public function trkconfig() { |
| 2822 |
VikRentCarHelper::printHeader("trackings"); |
| 2823 |
|
| 2824 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'trkconfig')); |
| 2825 |
|
| 2826 |
parent::display(); |
| 2827 |
|
| 2828 |
if (VikRentCar::showFooter()) { |
| 2829 |
VikRentCarHelper::printFooter(); |
| 2830 |
} |
| 2831 |
} |
| 2832 |
|
| 2833 |
public function savetrkconfigstay() { |
| 2834 |
if (!JSession::checkToken()) { |
| 2835 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2836 |
} |
| 2837 |
$this->do_savetrkconfig(true); |
| 2838 |
} |
| 2839 |
|
| 2840 |
public function savetrkconfig() { |
| 2841 |
if (!JSession::checkToken()) { |
| 2842 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2843 |
} |
| 2844 |
$this->do_savetrkconfig(); |
| 2845 |
} |
| 2846 |
|
| 2847 |
private function do_savetrkconfig($stay = false) |
| 2848 |
{ |
| 2849 |
$config = VRCFactory::getConfig(); |
| 2850 |
|
| 2851 |
$trkenabled = VikRequest::getInt('trkenabled', 0, 'request'); |
| 2852 |
$trkenabled = $trkenabled == 1 ? 1 : 0; |
| 2853 |
$trkcookierfrdur = VikRequest::getFloat('trkcookierfrdur', 1, 'request'); |
| 2854 |
$trkcookierfrdur = $trkcookierfrdur < 0.1 ? 1 : $trkcookierfrdur; |
| 2855 |
$trkcampname = VikRequest::getVar('trkcampname', []); |
| 2856 |
$trkcampkey = VikRequest::getVar('trkcampkey', []); |
| 2857 |
$trkcampval = VikRequest::getVar('trkcampval', []); |
| 2858 |
$trkcampaigns = []; |
| 2859 |
foreach ($trkcampname as $k => $v) { |
| 2860 |
if (empty($trkcampkey[$k])) { |
| 2861 |
continue; |
| 2862 |
} |
| 2863 |
$trkcampkey[$k] = str_replace(' ', '', trim($trkcampkey[$k])); |
| 2864 |
$name = !empty($v) ? $v : date('Y-m-d').' '.(count($trkcampaigns) + 1); |
| 2865 |
$trkcampaigns[$trkcampkey[$k]] = [ |
| 2866 |
'key' => $trkcampkey[$k], |
| 2867 |
'value' => $trkcampval[$k], |
| 2868 |
'name' => $name, |
| 2869 |
]; |
| 2870 |
} |
| 2871 |
|
| 2872 |
$config->set('trkenabled', $trkenabled); |
| 2873 |
$config->set('trkcookierfrdur', $trkcookierfrdur); |
| 2874 |
$config->set('trkcampaigns', json_encode($trkcampaigns)); |
| 2875 |
|
| 2876 |
$measurment_driver = VikRequest::getString('measurment_driver', '', 'request'); |
| 2877 |
$measurment_params = []; |
| 2878 |
$vikparams = VikRequest::getVar('vikparams', []); |
| 2879 |
foreach ($vikparams as $setting => $cont) { |
| 2880 |
if (strlen($setting) > 0) { |
| 2881 |
$measurment_params[$setting] = $cont; |
| 2882 |
} |
| 2883 |
} |
| 2884 |
|
| 2885 |
$config->set('measurment_driver', $measurment_driver); |
| 2886 |
$config->set('measurment_params', json_encode($measurment_params)); |
| 2887 |
|
| 2888 |
$app = JFactory::getApplication(); |
| 2889 |
$app->redirect("index.php?option=com_vikrentcar&task=".($stay ? 'trkconfig' : 'trackings')); |
| 2890 |
} |
| 2891 |
|
| 2892 |
public function modtracking() { |
| 2893 |
$dbo = JFactory::getDbo(); |
| 2894 |
$cid = VikRequest::getVar('cid', array()); |
| 2895 |
foreach ($cid as $id) { |
| 2896 |
if (!empty($id)) { |
| 2897 |
$q = "SELECT `id`,`published` FROM `#__vikrentcar_trackings` WHERE `id`=".(int)$id.";"; |
| 2898 |
$dbo->setQuery($q); |
| 2899 |
$dbo->execute(); |
| 2900 |
if ($dbo->getNumRows()) { |
| 2901 |
$data = $dbo->loadAssoc(); |
| 2902 |
$q = "UPDATE `#__vikrentcar_trackings` SET `published`=".($data['published'] ? '0' : '1')." WHERE `id`=".(int)$data['id'].";"; |
| 2903 |
$dbo->setQuery($q); |
| 2904 |
$dbo->execute(); |
| 2905 |
} |
| 2906 |
} |
| 2907 |
} |
| 2908 |
$mainframe = JFactory::getApplication(); |
| 2909 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=trackings"); |
| 2910 |
} |
| 2911 |
|
| 2912 |
public function removetrackings() { |
| 2913 |
if (!JSession::checkToken()) { |
| 2914 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 2915 |
} |
| 2916 |
$ids = VikRequest::getVar('cid', array()); |
| 2917 |
if (count($ids)) { |
| 2918 |
$dbo = JFactory::getDbo(); |
| 2919 |
foreach ($ids as $d){ |
| 2920 |
$q = "DELETE FROM `#__vikrentcar_trackings` WHERE `id`=".(int)$d.";"; |
| 2921 |
$dbo->setQuery($q); |
| 2922 |
$dbo->execute(); |
| 2923 |
$q = "DELETE FROM `#__vikrentcar_tracking_infos` WHERE `idtracking`=".(int)$d.";"; |
| 2924 |
$dbo->setQuery($q); |
| 2925 |
$dbo->execute(); |
| 2926 |
} |
| 2927 |
} |
| 2928 |
$mainframe = JFactory::getApplication(); |
| 2929 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=trackings"); |
| 2930 |
} |
| 2931 |
|
| 2932 |
/** |
| 2933 |
* Invokes the Tracker class to obtain |
| 2934 |
* geo information about the IP addresses. |
| 2935 |
* This task is called via ajax. |
| 2936 |
* |
| 2937 |
* @since 1.11 |
| 2938 |
*/ |
| 2939 |
public function getgeoinfo() { |
| 2940 |
$ips = VikRequest::getVar('ips', array()); |
| 2941 |
if (!count($ips)) { |
| 2942 |
echo 'e4j.error.empty IPs'; |
| 2943 |
exit; |
| 2944 |
} |
| 2945 |
|
| 2946 |
// require the Tracker class without instantiating the object |
| 2947 |
VikRentCar::getTracker(true); |
| 2948 |
$geo_info = VikRentCarTracker::getIpGeoInfo($ips); |
| 2949 |
|
| 2950 |
if ($geo_info === false) { |
| 2951 |
echo 'e4j.error.Tracker error, could not get geo info from IPs'; |
| 2952 |
exit; |
| 2953 |
} |
| 2954 |
|
| 2955 |
if (is_string($geo_info)) { |
| 2956 |
echo 'e4j.error.' . JHtml::fetch('esc_html', $geo_info); |
| 2957 |
exit; |
| 2958 |
} |
| 2959 |
|
| 2960 |
// update db values and compose response |
| 2961 |
$dbo = JFactory::getDbo(); |
| 2962 |
$resp = array(); |
| 2963 |
foreach ($geo_info as $id => $geo) { |
| 2964 |
if (is_null($geo) || $geo === false) { |
| 2965 |
continue; |
| 2966 |
} |
| 2967 |
// compose geo info string |
| 2968 |
$geovals = array(); |
| 2969 |
if (!empty($geo['city'])) { |
| 2970 |
array_push($geovals, $geo['city']); |
| 2971 |
} |
| 2972 |
if (!empty($geo['region'])) { |
| 2973 |
array_push($geovals, $geo['region']); |
| 2974 |
} |
| 2975 |
$threecode = ''; |
| 2976 |
$cname = ''; |
| 2977 |
if (!empty($geo['country'])) { |
| 2978 |
// returned country is a 2-char code, get the 3-char country code |
| 2979 |
$q = "SELECT `country_3_code`,`country_name` FROM `#__vikrentcar_countries` WHERE `country_2_code`=".$dbo->quote($geo['country']).";"; |
| 2980 |
$dbo->setQuery($q); |
| 2981 |
$dbo->execute(); |
| 2982 |
if ($dbo->getNumRows()) { |
| 2983 |
$cinfo = $dbo->loadAssoc(); |
| 2984 |
$threecode = $cinfo['country_3_code']; |
| 2985 |
$cname = $cinfo['country_name']; |
| 2986 |
} |
| 2987 |
array_push($geovals, (empty($cname) ? $geo['country'] : $cname)); |
| 2988 |
} |
| 2989 |
|
| 2990 |
// full geo information string |
| 2991 |
$geoinfostr = implode(', ', $geovals); |
| 2992 |
|
| 2993 |
// push data to the response pool |
| 2994 |
$resp[$id] = array(); |
| 2995 |
$resp[$id]['geo'] = $geoinfostr; |
| 2996 |
if (!empty($cname)) { |
| 2997 |
$resp[$id]['country'] = $cname; |
| 2998 |
} |
| 2999 |
if (!empty($threecode)) { |
| 3000 |
$resp[$id]['country3'] = $threecode; |
| 3001 |
} |
| 3002 |
|
| 3003 |
// update main tracking record |
| 3004 |
$q = "UPDATE `#__vikrentcar_trackings` SET `geo`=".$dbo->quote($geoinfostr).(!empty($threecode) ? ', `country`='.$dbo->quote($threecode) : '')." WHERE `id`=".(int)$id.";"; |
| 3005 |
$dbo->setQuery($q); |
| 3006 |
$dbo->execute(); |
| 3007 |
} |
| 3008 |
|
| 3009 |
// output the JSON response |
| 3010 |
echo json_encode($resp); |
| 3011 |
exit; |
| 3012 |
} |
| 3013 |
|
| 3014 |
public function locfees() { |
| 3015 |
VikRentCarHelper::printHeader("12"); |
| 3016 |
|
| 3017 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'locfees')); |
| 3018 |
|
| 3019 |
parent::display(); |
| 3020 |
|
| 3021 |
if (VikRentCar::showFooter()) { |
| 3022 |
VikRentCarHelper::printFooter(); |
| 3023 |
} |
| 3024 |
} |
| 3025 |
|
| 3026 |
public function newlocfee() { |
| 3027 |
VikRentCarHelper::printHeader("12"); |
| 3028 |
|
| 3029 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managelocfee')); |
| 3030 |
|
| 3031 |
parent::display(); |
| 3032 |
|
| 3033 |
if (VikRentCar::showFooter()) { |
| 3034 |
VikRentCarHelper::printFooter(); |
| 3035 |
} |
| 3036 |
} |
| 3037 |
|
| 3038 |
public function editlocfee() { |
| 3039 |
VikRentCarHelper::printHeader("12"); |
| 3040 |
|
| 3041 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managelocfee')); |
| 3042 |
|
| 3043 |
parent::display(); |
| 3044 |
|
| 3045 |
if (VikRentCar::showFooter()) { |
| 3046 |
VikRentCarHelper::printFooter(); |
| 3047 |
} |
| 3048 |
} |
| 3049 |
|
| 3050 |
public function createlocfee() { |
| 3051 |
if (!JSession::checkToken()) { |
| 3052 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3053 |
} |
| 3054 |
$mainframe = JFactory::getApplication(); |
| 3055 |
$pfrom = VikRequest::getInt('from', 0, 'request'); |
| 3056 |
$pto = VikRequest::getInt('to', 0, 'request'); |
| 3057 |
$pcost = VikRequest::getFloat('cost', 0, 'request'); |
| 3058 |
$pdaily = VikRequest::getInt('daily', 0, 'request'); |
| 3059 |
$paliq = VikRequest::getInt('aliq', 0, 'request'); |
| 3060 |
$pinvert = VikRequest::getInt('invert', 0, 'request'); |
| 3061 |
$pany_oneway = VikRequest::getInt('any_oneway', 0, 'request'); |
| 3062 |
$pnightsoverrides = VikRequest::getVar('nightsoverrides', array()); |
| 3063 |
$pvaluesoverrides = VikRequest::getVar('valuesoverrides', array()); |
| 3064 |
|
| 3065 |
$dbo = JFactory::getDbo(); |
| 3066 |
if ((!empty($pfrom) && !empty($pto)) || !empty($pany_oneway)) { |
| 3067 |
$losverridestr = ""; |
| 3068 |
if (count($pnightsoverrides) > 0 && count($pvaluesoverrides) > 0) { |
| 3069 |
foreach ($pnightsoverrides as $ko => $no) { |
| 3070 |
if (!empty($no) && strlen(trim($pvaluesoverrides[$ko])) > 0) { |
| 3071 |
$losverridestr .= (int)$no.':'.floatval($pvaluesoverrides[$ko]).'_'; |
| 3072 |
} |
| 3073 |
} |
| 3074 |
} |
| 3075 |
$q = "INSERT INTO `#__vikrentcar_locfees` (`from`,`to`,`daily`,`cost`,`idiva`,`invert`,`losoverride`,`any_oneway`) VALUES(".$dbo->quote($pfrom).", ".$dbo->quote($pto).", ".$pdaily.", ".$dbo->quote($pcost).", ".$dbo->quote($paliq).", '".$pinvert."', '".$losverridestr."', " . $pany_oneway . ");"; |
| 3076 |
$dbo->setQuery($q); |
| 3077 |
$dbo->execute(); |
| 3078 |
$mainframe->enqueueMessage(JText::translate('VRLOCFEESAVED')); |
| 3079 |
} |
| 3080 |
|
| 3081 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=locfees"); |
| 3082 |
} |
| 3083 |
|
| 3084 |
public function updatelocfee() { |
| 3085 |
if (!JSession::checkToken()) { |
| 3086 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3087 |
} |
| 3088 |
$mainframe = JFactory::getApplication(); |
| 3089 |
$pwhere = VikRequest::getString('where', '', 'request'); |
| 3090 |
$pfrom = VikRequest::getInt('from', 0, 'request'); |
| 3091 |
$pto = VikRequest::getInt('to', 0, 'request'); |
| 3092 |
$pcost = VikRequest::getFloat('cost', 0, 'request'); |
| 3093 |
$pdaily = VikRequest::getInt('daily', 0, 'request'); |
| 3094 |
$paliq = VikRequest::getInt('aliq', 0, 'request'); |
| 3095 |
$pinvert = VikRequest::getInt('invert', 0, 'request'); |
| 3096 |
$pany_oneway = VikRequest::getInt('any_oneway', 0, 'request'); |
| 3097 |
$pnightsoverrides = VikRequest::getVar('nightsoverrides', array()); |
| 3098 |
$pvaluesoverrides = VikRequest::getVar('valuesoverrides', array()); |
| 3099 |
|
| 3100 |
$dbo = JFactory::getDbo(); |
| 3101 |
if (!empty($pwhere) && ((!empty($pfrom) && !empty($pto)) || !empty($pany_oneway))) { |
| 3102 |
$losverridestr = ""; |
| 3103 |
if (count($pnightsoverrides) > 0 && count($pvaluesoverrides) > 0) { |
| 3104 |
foreach ($pnightsoverrides as $ko => $no) { |
| 3105 |
if (!empty($no) && strlen(trim($pvaluesoverrides[$ko])) > 0) { |
| 3106 |
$losverridestr .= (int)$no.':'.floatval($pvaluesoverrides[$ko]).'_'; |
| 3107 |
} |
| 3108 |
} |
| 3109 |
} |
| 3110 |
$q = "UPDATE `#__vikrentcar_locfees` SET `from`=".$dbo->quote($pfrom).",`to`=".$dbo->quote($pto).",`daily`=".$pdaily.",`cost`=".$dbo->quote($pcost).",`idiva`=".$dbo->quote($paliq).",`invert`='".$pinvert."',`losoverride`='".$losverridestr."',`any_oneway`=" . $pany_oneway . " WHERE `id`=".$dbo->quote($pwhere).";"; |
| 3111 |
$dbo->setQuery($q); |
| 3112 |
$dbo->execute(); |
| 3113 |
$mainframe->enqueueMessage(JText::translate('VRLOCFEEUPDATE')); |
| 3114 |
} |
| 3115 |
|
| 3116 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=locfees"); |
| 3117 |
} |
| 3118 |
|
| 3119 |
public function removelocfee() { |
| 3120 |
if (!JSession::checkToken()) { |
| 3121 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3122 |
} |
| 3123 |
$ids = VikRequest::getVar('cid', array(0)); |
| 3124 |
if (@count($ids)) { |
| 3125 |
$dbo = JFactory::getDbo(); |
| 3126 |
foreach ($ids as $d) { |
| 3127 |
$q = "DELETE FROM `#__vikrentcar_locfees` WHERE `id`=".$dbo->quote($d).";"; |
| 3128 |
$dbo->setQuery($q); |
| 3129 |
$dbo->execute(); |
| 3130 |
} |
| 3131 |
} |
| 3132 |
$mainframe = JFactory::getApplication(); |
| 3133 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=locfees"); |
| 3134 |
} |
| 3135 |
|
| 3136 |
public function cancellocfee() { |
| 3137 |
$mainframe = JFactory::getApplication(); |
| 3138 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=locfees"); |
| 3139 |
} |
| 3140 |
|
| 3141 |
public function seasons() { |
| 3142 |
VikRentCarHelper::printHeader("13"); |
| 3143 |
|
| 3144 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'seasons')); |
| 3145 |
|
| 3146 |
parent::display(); |
| 3147 |
|
| 3148 |
if (VikRentCar::showFooter()) { |
| 3149 |
VikRentCarHelper::printFooter(); |
| 3150 |
} |
| 3151 |
} |
| 3152 |
|
| 3153 |
public function newseason() { |
| 3154 |
VikRentCarHelper::printHeader("13"); |
| 3155 |
|
| 3156 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageseason')); |
| 3157 |
|
| 3158 |
parent::display(); |
| 3159 |
|
| 3160 |
if (VikRentCar::showFooter()) { |
| 3161 |
VikRentCarHelper::printFooter(); |
| 3162 |
} |
| 3163 |
} |
| 3164 |
|
| 3165 |
public function editseason() { |
| 3166 |
VikRentCarHelper::printHeader("13"); |
| 3167 |
|
| 3168 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageseason')); |
| 3169 |
|
| 3170 |
parent::display(); |
| 3171 |
|
| 3172 |
if (VikRentCar::showFooter()) { |
| 3173 |
VikRentCarHelper::printFooter(); |
| 3174 |
} |
| 3175 |
} |
| 3176 |
|
| 3177 |
public function createseason() { |
| 3178 |
if (!JSession::checkToken()) { |
| 3179 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3180 |
} |
| 3181 |
$this->do_createseason(); |
| 3182 |
} |
| 3183 |
|
| 3184 |
public function createseason_new() { |
| 3185 |
if (!JSession::checkToken()) { |
| 3186 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3187 |
} |
| 3188 |
$this->do_createseason(true); |
| 3189 |
} |
| 3190 |
|
| 3191 |
private function do_createseason($andnew = false) { |
| 3192 |
$mainframe = JFactory::getApplication(); |
| 3193 |
$pfrom = VikRequest::getString('from', '', 'request'); |
| 3194 |
$pto = VikRequest::getString('to', '', 'request'); |
| 3195 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 3196 |
$pdiffcost = VikRequest::getString('diffcost', '', 'request'); |
| 3197 |
$pidlocation = VikRequest::getInt('idlocation', '', 'request'); |
| 3198 |
$pidcars = VikRequest::getVar('idcars', array(0)); |
| 3199 |
$pidprices = VikRequest::getVar('idprices', array(0)); |
| 3200 |
$pwdays = VikRequest::getVar('wdays', array()); |
| 3201 |
$pspname = VikRequest::getString('spname', '', 'request'); |
| 3202 |
$ppickupincl = VikRequest::getString('pickupincl', '', 'request'); |
| 3203 |
$ppickupincl = $ppickupincl == 1 ? 1 : 0; |
| 3204 |
$pkeepfirstdayrate = VikRequest::getString('keepfirstdayrate', '', 'request'); |
| 3205 |
$pkeepfirstdayrate = $pkeepfirstdayrate == 1 ? 1 : 0; |
| 3206 |
$pval_pcent = VikRequest::getString('val_pcent', '', 'request'); |
| 3207 |
$pval_pcent = $pval_pcent == "1" ? 1 : 2; |
| 3208 |
$proundmode = VikRequest::getString('roundmode', '', 'request'); |
| 3209 |
$proundmode = (!empty($proundmode) && in_array($proundmode, array('PHP_ROUND_HALF_UP', 'PHP_ROUND_HALF_DOWN')) ? $proundmode : ''); |
| 3210 |
$pyeartied = VikRequest::getString('yeartied', '', 'request'); |
| 3211 |
$pyeartied = $pyeartied == "1" ? 1 : 0; |
| 3212 |
$tieyear = 0; |
| 3213 |
$ppromo = VikRequest::getInt('promo', '', 'request'); |
| 3214 |
$ppromodaysadv = VikRequest::getInt('promodaysadv', '', 'request'); |
| 3215 |
$ppromotxt = VikRequest::getString('promotxt', '', 'request', VIKREQUEST_ALLOWHTML); |
| 3216 |
$pnightsoverrides = VikRequest::getVar('nightsoverrides', array()); |
| 3217 |
$pvaluesoverrides = VikRequest::getVar('valuesoverrides', array()); |
| 3218 |
$pandmoreoverride = VikRequest::getVar('andmoreoverride', array()); |
| 3219 |
$ppromominlos = VikRequest::getInt('promominlos', '', 'request'); |
| 3220 |
$ppromolastmind = VikRequest::getInt('promolastmind', 0, 'request'); |
| 3221 |
$ppromolastminh = VikRequest::getInt('promolastminh', 0, 'request'); |
| 3222 |
$promolastmin = ($ppromolastmind * 86400) + ($ppromolastminh * 3600); |
| 3223 |
$ppromofinalprice = VikRequest::getInt('promofinalprice', 0, 'request'); |
| 3224 |
$ppromofinalprice = $ppromo ? $ppromofinalprice : 0; |
| 3225 |
$losverridestr = ""; |
| 3226 |
$dbo = JFactory::getDbo(); |
| 3227 |
if ((!empty($pfrom) && !empty($pto)) || count($pwdays) > 0) { |
| 3228 |
$skipseason = false; |
| 3229 |
if (empty($pfrom) || empty($pto)) { |
| 3230 |
$skipseason = true; |
| 3231 |
} |
| 3232 |
$skipdays = false; |
| 3233 |
$wdaystr = null; |
| 3234 |
if (count($pwdays) == 0) { |
| 3235 |
$skipdays = true; |
| 3236 |
} else { |
| 3237 |
$wdaystr = ""; |
| 3238 |
foreach ($pwdays as $wd) { |
| 3239 |
$wdaystr .= $wd.';'; |
| 3240 |
} |
| 3241 |
} |
| 3242 |
$carstr=""; |
| 3243 |
if (@count($pidcars) > 0) { |
| 3244 |
foreach ($pidcars as $car) { |
| 3245 |
$carstr.="-".$car."-,"; |
| 3246 |
} |
| 3247 |
} |
| 3248 |
$pricestr=""; |
| 3249 |
if (@count($pidprices) > 0) { |
| 3250 |
foreach ($pidprices as $price) { |
| 3251 |
if (empty($price)) { |
| 3252 |
continue; |
| 3253 |
} |
| 3254 |
$pricestr.="-".$price."-,"; |
| 3255 |
} |
| 3256 |
} |
| 3257 |
$valid = true; |
| 3258 |
$double_records = array(); |
| 3259 |
$sfrom = null; |
| 3260 |
$sto = null; |
| 3261 |
// value overrides |
| 3262 |
if (count($pnightsoverrides) > 0 && count($pvaluesoverrides) > 0) { |
| 3263 |
foreach ($pnightsoverrides as $ko => $no) { |
| 3264 |
if (!empty($no) && strlen(trim($pvaluesoverrides[$ko])) > 0) { |
| 3265 |
$infiniteclause = intval($pandmoreoverride[$ko]) == 1 ? '-i' : ''; |
| 3266 |
$losverridestr .= intval($no).$infiniteclause.':'.trim($pvaluesoverrides[$ko]).'_'; |
| 3267 |
} |
| 3268 |
} |
| 3269 |
} |
| 3270 |
// |
| 3271 |
if (!$skipseason) { |
| 3272 |
$first = VikRentCar::getDateTimestamp($pfrom, 0, 0); |
| 3273 |
$second = VikRentCar::getDateTimestamp($pto, 0, 0); |
| 3274 |
if ($second > 0 && $second == $first) { |
| 3275 |
$second += 86399; |
| 3276 |
} |
| 3277 |
if ($second > $first) { |
| 3278 |
$baseone = getdate($first); |
| 3279 |
$basets = mktime(0, 0, 0, 1, 1, $baseone['year']); |
| 3280 |
$sfrom = $baseone[0] - $basets; |
| 3281 |
$basetwo = getdate($second); |
| 3282 |
$basets = mktime(0, 0, 0, 1, 1, $basetwo['year']); |
| 3283 |
$sto = $basetwo[0] - $basets; |
| 3284 |
//check leap year |
| 3285 |
if ($baseone['year'] % 4 == 0 && ($baseone['year'] % 100 != 0 || $baseone['year'] % 400 == 0)) { |
| 3286 |
$leapts = mktime(0, 0, 0, 2, 29, $baseone['year']); |
| 3287 |
if ($baseone[0] > $leapts) { |
| 3288 |
$sfrom -= 86400; |
| 3289 |
/** |
| 3290 |
* To avoid issue with leap years and dates near Feb 29th, we only reduce the seconds if these were reduced |
| 3291 |
* for the from-date of the seasons. Doing it just for the to-date in 2019 for 2020 (leap) produced invalid results. |
| 3292 |
* |
| 3293 |
* @since July 2nd 2019 |
| 3294 |
*/ |
| 3295 |
if ($basetwo['year'] % 4 == 0 && ($basetwo['year'] % 100 != 0 || $basetwo['year'] % 400 == 0)) { |
| 3296 |
$leapts = mktime(0, 0, 0, 2, 29, $basetwo['year']); |
| 3297 |
if ($basetwo[0] > $leapts) { |
| 3298 |
$sto -= date('d-m', $baseone[0]) != '31-12' && date('d-m', $basetwo[0]) == '31-12' ? 1 : 86400; |
| 3299 |
} |
| 3300 |
} |
| 3301 |
} |
| 3302 |
} |
| 3303 |
//end leap year |
| 3304 |
//tied to the year |
| 3305 |
if ($pyeartied == 1) { |
| 3306 |
$tieyear = $baseone['year']; |
| 3307 |
} |
| 3308 |
// |
| 3309 |
//check if seasons dates are valid |
| 3310 |
$q = "SELECT `id`,`spname` FROM `#__vikrentcar_seasons` WHERE `from`<".$dbo->quote($sfrom)." AND `to`>".$dbo->quote($sfrom)." AND `idcars`=".$dbo->quote($carstr)." AND `locations`=".$dbo->quote($pidlocation)."".(!$skipdays ? " AND `wdays`='".$wdaystr."'" : "").($skipdays ? " AND (`from` > 0 OR `to` > 0) AND `wdays`=''" : "").($pyeartied == 1 ? " AND `year`=".$tieyear : " AND `year` IS NULL")." AND `idprices`=".$dbo->quote($pricestr)." AND `promo`=".$ppromo." AND `losoverride`=".$dbo->quote($losverridestr).";"; |
| 3311 |
$dbo->setQuery($q); |
| 3312 |
$dbo->execute(); |
| 3313 |
$totfirst = $dbo->getNumRows(); |
| 3314 |
if ($totfirst > 0) { |
| 3315 |
$valid = false; |
| 3316 |
$similar = $dbo->loadAssocList(); |
| 3317 |
foreach ($similar as $sim) { |
| 3318 |
$double_records[] = $sim['spname']; |
| 3319 |
} |
| 3320 |
} |
| 3321 |
$q = "SELECT `id`,`spname` FROM `#__vikrentcar_seasons` WHERE `from`<".$dbo->quote($sto)." AND `to`>".$dbo->quote($sto)." AND `idcars`=".$dbo->quote($carstr)." AND `locations`=".$dbo->quote($pidlocation)."".(!$skipdays ? " AND `wdays`='".$wdaystr."'" : "").($skipdays ? " AND (`from` > 0 OR `to` > 0) AND `wdays`=''" : "").($pyeartied == 1 ? " AND `year`=".$tieyear : " AND `year` IS NULL")." AND `idprices`=".$dbo->quote($pricestr)." AND `promo`=".$ppromo." AND `losoverride`=".$dbo->quote($losverridestr).";"; |
| 3322 |
$dbo->setQuery($q); |
| 3323 |
$dbo->execute(); |
| 3324 |
$totsecond = $dbo->getNumRows(); |
| 3325 |
if ($totsecond > 0) { |
| 3326 |
$valid = false; |
| 3327 |
$similar = $dbo->loadAssocList(); |
| 3328 |
foreach ($similar as $sim) { |
| 3329 |
$double_records[] = $sim['spname']; |
| 3330 |
} |
| 3331 |
} |
| 3332 |
$q = "SELECT `id`,`spname` FROM `#__vikrentcar_seasons` WHERE `from`>=".$dbo->quote($sfrom)." AND `from`<=".$dbo->quote($sto)." AND `to`>=".$dbo->quote($sfrom)." AND `to`<=".$dbo->quote($sto)." AND `idcars`=".$dbo->quote($carstr)." AND `locations`=".$dbo->quote($pidlocation)."".(!$skipdays ? " AND `wdays`='".$wdaystr."'" : "").($skipdays ? " AND (`from` > 0 OR `to` > 0) AND `wdays`=''" : "").($pyeartied == 1 ? " AND `year`=".$tieyear : " AND `year` IS NULL")." AND `idprices`=".$dbo->quote($pricestr)." AND `promo`=".$ppromo." AND `losoverride`=".$dbo->quote($losverridestr).";"; |
| 3333 |
$dbo->setQuery($q); |
| 3334 |
$dbo->execute(); |
| 3335 |
$totthird = $dbo->getNumRows(); |
| 3336 |
if ($totthird > 0) { |
| 3337 |
$valid = false; |
| 3338 |
$similar = $dbo->loadAssocList(); |
| 3339 |
foreach ($similar as $sim) { |
| 3340 |
$double_records[] = $sim['spname']; |
| 3341 |
} |
| 3342 |
} |
| 3343 |
// |
| 3344 |
} else { |
| 3345 |
VikError::raiseWarning('', JText::translate('ERRINVDATESEASON')); |
| 3346 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newseason"); |
| 3347 |
} |
| 3348 |
} |
| 3349 |
if ($valid || $ppromo === 1) { |
| 3350 |
$q = "INSERT INTO `#__vikrentcar_seasons` (`type`,`from`,`to`,`diffcost`,`idcars`,`locations`,`spname`,`wdays`,`pickupincl`,`val_pcent`,`losoverride`,`keepfirstdayrate`,`roundmode`,`year`,`idprices`,`promo`,`promodaysadv`,`promotxt`,`promominlos`,`promolastmin`,`promofinalprice`) VALUES('".($ptype == "1" ? "1" : "2")."', ".$dbo->quote($sfrom).", ".$dbo->quote($sto).", ".$dbo->quote($pdiffcost).", ".$dbo->quote($carstr).", ".$dbo->quote($pidlocation).", ".$dbo->quote($pspname).", ".$dbo->quote($wdaystr).", '".$ppickupincl."', '".$pval_pcent."', ".$dbo->quote($losverridestr).", '".$pkeepfirstdayrate."', ".(!empty($proundmode) ? "'".$proundmode."'" : "null").", ".($pyeartied == 1 ? $tieyear : "NULL").", ".$dbo->quote($pricestr).", ".($ppromo == 1 ? '1' : '0').", ".(!empty($ppromodaysadv) ? $ppromodaysadv : "null").", ".$dbo->quote($ppromotxt).", ".(!empty($ppromominlos) ? $ppromominlos : "0").", ".(int)$promolastmin.", {$ppromofinalprice});"; |
| 3351 |
$dbo->setQuery($q); |
| 3352 |
$dbo->execute(); |
| 3353 |
$mainframe->enqueueMessage(JText::translate('VRSEASONSAVED')); |
| 3354 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=".($andnew ? 'newseason' : 'seasons')); |
| 3355 |
} else { |
| 3356 |
VikError::raiseWarning('', JText::translate('ERRINVDATECARSLOCSEASON').(count($double_records) > 0 ? ' ('.implode(', ', $double_records).')' : '')); |
| 3357 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newseason"); |
| 3358 |
} |
| 3359 |
} else { |
| 3360 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newseason"); |
| 3361 |
} |
| 3362 |
} |
| 3363 |
|
| 3364 |
public function updateseason() { |
| 3365 |
if (!JSession::checkToken()) { |
| 3366 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3367 |
} |
| 3368 |
$this->do_updateseason(); |
| 3369 |
} |
| 3370 |
|
| 3371 |
public function updateseasonstay() { |
| 3372 |
if (!JSession::checkToken()) { |
| 3373 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3374 |
} |
| 3375 |
$this->do_updateseason(true); |
| 3376 |
} |
| 3377 |
|
| 3378 |
public function do_updateseason($stay = false) |
| 3379 |
{ |
| 3380 |
$app = JFactory::getApplication(); |
| 3381 |
$dbo = JFactory::getDbo(); |
| 3382 |
|
| 3383 |
$pwhere = VikRequest::getInt('where', 0, 'request'); |
| 3384 |
|
| 3385 |
$pfrom = VikRequest::getString('from', '', 'request'); |
| 3386 |
$pto = VikRequest::getString('to', '', 'request'); |
| 3387 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 3388 |
$pdiffcost = VikRequest::getString('diffcost', '', 'request'); |
| 3389 |
$pidlocation = VikRequest::getInt('idlocation', '', 'request'); |
| 3390 |
$pidcars = VikRequest::getVar('idcars', array(0)); |
| 3391 |
$pidprices = VikRequest::getVar('idprices', array(0)); |
| 3392 |
$pwdays = VikRequest::getVar('wdays', array()); |
| 3393 |
$pspname = VikRequest::getString('spname', '', 'request'); |
| 3394 |
$ppickupincl = VikRequest::getString('pickupincl', '', 'request'); |
| 3395 |
$ppickupincl = $ppickupincl == 1 ? 1 : 0; |
| 3396 |
$pkeepfirstdayrate = VikRequest::getString('keepfirstdayrate', '', 'request'); |
| 3397 |
$pkeepfirstdayrate = $pkeepfirstdayrate == 1 ? 1 : 0; |
| 3398 |
$pval_pcent = VikRequest::getString('val_pcent', '', 'request'); |
| 3399 |
$pval_pcent = $pval_pcent == "1" ? 1 : 2; |
| 3400 |
$proundmode = VikRequest::getString('roundmode', '', 'request'); |
| 3401 |
$proundmode = (!empty($proundmode) && in_array($proundmode, array('PHP_ROUND_HALF_UP', 'PHP_ROUND_HALF_DOWN')) ? $proundmode : ''); |
| 3402 |
$pyeartied = VikRequest::getString('yeartied', '', 'request'); |
| 3403 |
$pyeartied = $pyeartied == "1" ? 1 : 0; |
| 3404 |
$tieyear = 0; |
| 3405 |
$ppromo = VikRequest::getInt('promo', '', 'request'); |
| 3406 |
$ppromo = $ppromo == 1 ? 1 : 0; |
| 3407 |
$ppromodaysadv = VikRequest::getInt('promodaysadv', '', 'request'); |
| 3408 |
$ppromotxt = VikRequest::getString('promotxt', '', 'request', VIKREQUEST_ALLOWHTML); |
| 3409 |
$pnightsoverrides = VikRequest::getVar('nightsoverrides', array()); |
| 3410 |
$pvaluesoverrides = VikRequest::getVar('valuesoverrides', array()); |
| 3411 |
$pandmoreoverride = VikRequest::getVar('andmoreoverride', array()); |
| 3412 |
$ppromominlos = VikRequest::getInt('promominlos', '', 'request'); |
| 3413 |
$ppromolastmind = VikRequest::getInt('promolastmind', 0, 'request'); |
| 3414 |
$ppromolastminh = VikRequest::getInt('promolastminh', 0, 'request'); |
| 3415 |
$promolastmin = ($ppromolastmind * 86400) + ($ppromolastminh * 3600); |
| 3416 |
$ppromofinalprice = VikRequest::getInt('promofinalprice', 0, 'request'); |
| 3417 |
$ppromofinalprice = $ppromo ? $ppromofinalprice : 0; |
| 3418 |
$losverridestr = ""; |
| 3419 |
|
| 3420 |
if ((!empty($pfrom) && !empty($pto)) || $pwdays) { |
| 3421 |
$skipseason = false; |
| 3422 |
if (empty($pfrom) || empty($pto)) { |
| 3423 |
$skipseason = true; |
| 3424 |
} |
| 3425 |
$skipdays = false; |
| 3426 |
$wdaystr = null; |
| 3427 |
if (!$pwdays) { |
| 3428 |
$skipdays = true; |
| 3429 |
} else { |
| 3430 |
$wdaystr = ""; |
| 3431 |
foreach ($pwdays as $wd) { |
| 3432 |
$wdaystr .= $wd.';'; |
| 3433 |
} |
| 3434 |
} |
| 3435 |
$carstr=""; |
| 3436 |
if ($pidcars) { |
| 3437 |
foreach ($pidcars as $car) { |
| 3438 |
$carstr.="-".$car."-,"; |
| 3439 |
} |
| 3440 |
} |
| 3441 |
$pricestr=""; |
| 3442 |
if ($pidprices) { |
| 3443 |
foreach ($pidprices as $price) { |
| 3444 |
if (empty($price)) { |
| 3445 |
continue; |
| 3446 |
} |
| 3447 |
$pricestr.="-".$price."-,"; |
| 3448 |
} |
| 3449 |
} |
| 3450 |
$valid = true; |
| 3451 |
$double_records = array(); |
| 3452 |
$sfrom = null; |
| 3453 |
$sto = null; |
| 3454 |
// value overrides |
| 3455 |
if (count($pnightsoverrides) > 0 && count($pvaluesoverrides) > 0) { |
| 3456 |
foreach ($pnightsoverrides as $ko => $no) { |
| 3457 |
if (!empty($no) && strlen(trim($pvaluesoverrides[$ko])) > 0) { |
| 3458 |
$infiniteclause = intval($pandmoreoverride[$ko]) == 1 ? '-i' : ''; |
| 3459 |
$losverridestr .= intval($no).$infiniteclause.':'.trim($pvaluesoverrides[$ko]).'_'; |
| 3460 |
} |
| 3461 |
} |
| 3462 |
} |
| 3463 |
// |
| 3464 |
if (!$skipseason) { |
| 3465 |
$first = VikRentCar::getDateTimestamp($pfrom, 0, 0); |
| 3466 |
$second = VikRentCar::getDateTimestamp($pto, 0, 0); |
| 3467 |
|
| 3468 |
if ($second > 0 && $second == $first) { |
| 3469 |
$second += 86399; |
| 3470 |
} |
| 3471 |
|
| 3472 |
if ($second > $first) { |
| 3473 |
$baseone = getdate($first); |
| 3474 |
$basets = mktime(0, 0, 0, 1, 1, $baseone['year']); |
| 3475 |
$sfrom = $baseone[0] - $basets; |
| 3476 |
$basetwo = getdate($second); |
| 3477 |
$basets = mktime(0, 0, 0, 1, 1, $basetwo['year']); |
| 3478 |
$sto = $basetwo[0] - $basets; |
| 3479 |
|
| 3480 |
// check leap year |
| 3481 |
if ($baseone['year'] % 4 == 0 && ($baseone['year'] % 100 != 0 || $baseone['year'] % 400 == 0)) { |
| 3482 |
$leapts = mktime(0, 0, 0, 2, 29, $baseone['year']); |
| 3483 |
if ($baseone[0] > $leapts) { |
| 3484 |
$sfrom -= 86400; |
| 3485 |
/** |
| 3486 |
* To avoid issue with leap years and dates near Feb 29th, we only reduce the seconds if these were reduced |
| 3487 |
* for the from-date of the seasons. Doing it just for the to-date in 2019 for 2020 (leap) produced invalid results. |
| 3488 |
* |
| 3489 |
* @since July 2nd 2019 |
| 3490 |
*/ |
| 3491 |
if ($basetwo['year'] % 4 == 0 && ($basetwo['year'] % 100 != 0 || $basetwo['year'] % 400 == 0)) { |
| 3492 |
$leapts = mktime(0, 0, 0, 2, 29, $basetwo['year']); |
| 3493 |
if ($basetwo[0] > $leapts) { |
| 3494 |
$sto -= date('d-m', $baseone[0]) != '31-12' && date('d-m', $basetwo[0]) == '31-12' ? 1 : 86400; |
| 3495 |
} |
| 3496 |
} |
| 3497 |
} |
| 3498 |
} |
| 3499 |
|
| 3500 |
// tied to the year |
| 3501 |
if ($pyeartied == 1) { |
| 3502 |
$tieyear = $baseone['year']; |
| 3503 |
} |
| 3504 |
|
| 3505 |
//check if seasons dates are valid |
| 3506 |
$q = "SELECT `id`,`spname` FROM `#__vikrentcar_seasons` WHERE `from`<".$dbo->quote($sfrom)." AND `to`>".$dbo->quote($sfrom)." AND `id`!=".$dbo->quote($pwhere)." AND `idcars`=".$dbo->quote($carstr)." AND `locations`=".$dbo->quote($pidlocation)."".(!$skipdays ? " AND `wdays`='".$wdaystr."'" : "").($skipdays ? " AND (`from` > 0 OR `to` > 0) AND `wdays`=''" : "").($pyeartied == 1 ? " AND `year`=".$tieyear : " AND `year` IS NULL")." AND `idprices`=".$dbo->quote($pricestr)." AND `promo`=".$ppromo." AND `losoverride`=".$dbo->quote($losverridestr).";"; |
| 3507 |
$dbo->setQuery($q); |
| 3508 |
$dbo->execute(); |
| 3509 |
$totfirst = $dbo->getNumRows(); |
| 3510 |
if ($totfirst > 0) { |
| 3511 |
$valid = false; |
| 3512 |
$similar = $dbo->loadAssocList(); |
| 3513 |
foreach ($similar as $sim) { |
| 3514 |
$double_records[] = $sim['spname']; |
| 3515 |
} |
| 3516 |
} |
| 3517 |
$q = "SELECT `id`,`spname` FROM `#__vikrentcar_seasons` WHERE `from`<".$dbo->quote($sto)." AND `to`>".$dbo->quote($sto)." AND `id`!=".$dbo->quote($pwhere)." AND `idcars`=".$dbo->quote($carstr)." AND `locations`=".$dbo->quote($pidlocation)."".(!$skipdays ? " AND `wdays`='".$wdaystr."'" : "").($skipdays ? " AND (`from` > 0 OR `to` > 0) AND `wdays`=''" : "").($pyeartied == 1 ? " AND `year`=".$tieyear : " AND `year` IS NULL")." AND `idprices`=".$dbo->quote($pricestr)." AND `promo`=".$ppromo." AND `losoverride`=".$dbo->quote($losverridestr).";"; |
| 3518 |
$dbo->setQuery($q); |
| 3519 |
$dbo->execute(); |
| 3520 |
$totsecond = $dbo->getNumRows(); |
| 3521 |
if ($totsecond > 0) { |
| 3522 |
$valid = false; |
| 3523 |
$similar = $dbo->loadAssocList(); |
| 3524 |
foreach ($similar as $sim) { |
| 3525 |
$double_records[] = $sim['spname']; |
| 3526 |
} |
| 3527 |
} |
| 3528 |
$q = "SELECT `id`,`spname` FROM `#__vikrentcar_seasons` WHERE `from`>=".$dbo->quote($sfrom)." AND `from`<=".$dbo->quote($sto)." AND `to`>=".$dbo->quote($sfrom)." AND `to`<=".$dbo->quote($sto)." AND `id`!=".$dbo->quote($pwhere)." AND `idcars`=".$dbo->quote($carstr)." AND `locations`=".$dbo->quote($pidlocation)."".(!$skipdays ? " AND `wdays`='".$wdaystr."'" : "").($skipdays ? " AND (`from` > 0 OR `to` > 0) AND `wdays`=''" : "").($pyeartied == 1 ? " AND `year`=".$tieyear : " AND `year` IS NULL")." AND `idprices`=".$dbo->quote($pricestr)." AND `promo`=".$ppromo." AND `losoverride`=".$dbo->quote($losverridestr).";"; |
| 3529 |
$dbo->setQuery($q); |
| 3530 |
$dbo->execute(); |
| 3531 |
$totthird = $dbo->getNumRows(); |
| 3532 |
if ($totthird > 0) { |
| 3533 |
$valid = false; |
| 3534 |
$similar = $dbo->loadAssocList(); |
| 3535 |
foreach ($similar as $sim) { |
| 3536 |
$double_records[] = $sim['spname']; |
| 3537 |
} |
| 3538 |
} |
| 3539 |
// |
| 3540 |
} else { |
| 3541 |
VikError::raiseWarning('', JText::translate('ERRINVDATESEASON')); |
| 3542 |
$app->redirect("index.php?option=com_vikrentcar&task=editseason&cid[]=".$pwhere); |
| 3543 |
} |
| 3544 |
} |
| 3545 |
if ($valid) { |
| 3546 |
$q = "UPDATE `#__vikrentcar_seasons` SET `type`='".($ptype == "1" ? "1" : "2")."',`from`=".$dbo->quote($sfrom).",`to`=".$dbo->quote($sto).",`diffcost`=".$dbo->quote($pdiffcost).",`idcars`=".$dbo->quote($carstr).",`locations`=".$dbo->quote($pidlocation).",`spname`=".$dbo->quote($pspname).",`wdays`='".$wdaystr."',`pickupincl`='".$ppickupincl."',`val_pcent`='".$pval_pcent."',`losoverride`=".$dbo->quote($losverridestr).",`keepfirstdayrate`='".$pkeepfirstdayrate."',`roundmode`=".(!empty($proundmode) ? "'".$proundmode."'" : "null").",`year`=".($pyeartied == 1 ? $tieyear : "NULL").",`idprices`=".$dbo->quote($pricestr).",`promo`=".$ppromo.",`promodaysadv`=".(!empty($ppromodaysadv) ? $ppromodaysadv : "null").",`promotxt`=".$dbo->quote($ppromotxt).",`promominlos`=".(!empty($ppromominlos) ? $ppromominlos : "0").",`promolastmin`=".(int)$promolastmin.",`promofinalprice`={$ppromofinalprice} WHERE `id`=".$dbo->quote($pwhere).";"; |
| 3547 |
$dbo->setQuery($q); |
| 3548 |
$dbo->execute(); |
| 3549 |
$app->enqueueMessage(JText::translate('VRSEASONUPDATED')); |
| 3550 |
if ($stay) { |
| 3551 |
$app->redirect("index.php?option=com_vikrentcar&task=editseason&cid[]=".$pwhere); |
| 3552 |
} else { |
| 3553 |
$app->redirect("index.php?option=com_vikrentcar&task=seasons"); |
| 3554 |
} |
| 3555 |
} else { |
| 3556 |
VikError::raiseWarning('', JText::translate('ERRINVDATECARSLOCSEASON').(count($double_records) > 0 ? ' ('.implode(', ', $double_records).')' : '')); |
| 3557 |
$app->redirect("index.php?option=com_vikrentcar&task=editseason&cid[]=".$pwhere); |
| 3558 |
} |
| 3559 |
} else { |
| 3560 |
$app->redirect("index.php?option=com_vikrentcar&task=editseason&cid[]=".$pwhere); |
| 3561 |
} |
| 3562 |
} |
| 3563 |
|
| 3564 |
public function removeseasons() { |
| 3565 |
if (!JSession::checkToken()) { |
| 3566 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3567 |
} |
| 3568 |
$ids = VikRequest::getVar('cid', array(0)); |
| 3569 |
$pidcar = VikRequest::getInt('idcar', '', 'request'); |
| 3570 |
$pwhere = VikRequest::getInt('where', '', 'request'); |
| 3571 |
if (!empty($pwhere)) { |
| 3572 |
$ids = array($pwhere); |
| 3573 |
} |
| 3574 |
if (count($ids)) { |
| 3575 |
$dbo = JFactory::getDbo(); |
| 3576 |
foreach ($ids as $d) { |
| 3577 |
if (empty($d)) { |
| 3578 |
continue; |
| 3579 |
} |
| 3580 |
$q = "DELETE FROM `#__vikrentcar_seasons` WHERE `id`=".$dbo->quote($d).";"; |
| 3581 |
$dbo->setQuery($q); |
| 3582 |
$dbo->execute(); |
| 3583 |
} |
| 3584 |
} |
| 3585 |
$mainframe = JFactory::getApplication(); |
| 3586 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=seasons".(!empty($pidcar) ? '&idcar='.$pidcar : '')); |
| 3587 |
} |
| 3588 |
|
| 3589 |
public function cancelseason() { |
| 3590 |
$mainframe = JFactory::getApplication(); |
| 3591 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=seasons"); |
| 3592 |
} |
| 3593 |
|
| 3594 |
public function payments() { |
| 3595 |
VikRentCarHelper::printHeader("14"); |
| 3596 |
|
| 3597 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'payments')); |
| 3598 |
|
| 3599 |
parent::display(); |
| 3600 |
|
| 3601 |
if (VikRentCar::showFooter()) { |
| 3602 |
VikRentCarHelper::printFooter(); |
| 3603 |
} |
| 3604 |
} |
| 3605 |
|
| 3606 |
public function newpayment() { |
| 3607 |
VikRentCarHelper::printHeader("14"); |
| 3608 |
|
| 3609 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managepayment')); |
| 3610 |
|
| 3611 |
parent::display(); |
| 3612 |
|
| 3613 |
if (VikRentCar::showFooter()) { |
| 3614 |
VikRentCarHelper::printFooter(); |
| 3615 |
} |
| 3616 |
} |
| 3617 |
|
| 3618 |
public function editpayment() { |
| 3619 |
VikRentCarHelper::printHeader("14"); |
| 3620 |
|
| 3621 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managepayment')); |
| 3622 |
|
| 3623 |
parent::display(); |
| 3624 |
|
| 3625 |
if (VikRentCar::showFooter()) { |
| 3626 |
VikRentCarHelper::printFooter(); |
| 3627 |
} |
| 3628 |
} |
| 3629 |
|
| 3630 |
public function createpayment() { |
| 3631 |
if (!JSession::checkToken()) { |
| 3632 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3633 |
} |
| 3634 |
$mainframe = JFactory::getApplication(); |
| 3635 |
$pname = VikRequest::getString('name', '', 'request'); |
| 3636 |
$ppayment = VikRequest::getString('payment', '', 'request'); |
| 3637 |
$ppublished = VikRequest::getString('published', '', 'request'); |
| 3638 |
$pcharge = VikRequest::getFloat('charge', '', 'request'); |
| 3639 |
$psetconfirmed = VikRequest::getString('setconfirmed', '', 'request'); |
| 3640 |
$pshownotealw = VikRequest::getString('shownotealw', '', 'request'); |
| 3641 |
$pnote = VikRequest::getString('note', '', 'request', VIKREQUEST_ALLOWHTML); |
| 3642 |
$pval_pcent = VikRequest::getString('val_pcent', '', 'request'); |
| 3643 |
$pval_pcent = !in_array($pval_pcent, array('1', '2')) ? 1 : $pval_pcent; |
| 3644 |
$pch_disc = VikRequest::getString('ch_disc', '', 'request'); |
| 3645 |
$pch_disc = !in_array($pch_disc, array('1', '2')) ? 1 : $pch_disc; |
| 3646 |
$poutposition = VikRequest::getString('outposition', 'top', 'request'); |
| 3647 |
$plogo = VikRequest::getString('logo', '', 'request'); |
| 3648 |
$vikpaymentparams = VikRequest::getVar('vikpaymentparams', array(0)); |
| 3649 |
$payparamarr = array(); |
| 3650 |
$payparamstr = ''; |
| 3651 |
if (count($vikpaymentparams) > 0) { |
| 3652 |
foreach ($vikpaymentparams as $setting => $cont) { |
| 3653 |
if (strlen($setting) > 0) { |
| 3654 |
$payparamarr[$setting] = $cont; |
| 3655 |
} |
| 3656 |
} |
| 3657 |
if (count($payparamarr) > 0) { |
| 3658 |
$payparamstr = json_encode($payparamarr); |
| 3659 |
} |
| 3660 |
} |
| 3661 |
$dbo = JFactory::getDbo(); |
| 3662 |
if (!empty($pname) && !empty($ppayment)) { |
| 3663 |
$setpub=$ppublished=="1" ? 1 : 0; |
| 3664 |
$psetconfirmed=$psetconfirmed=="1" ? 1 : 0; |
| 3665 |
$pshownotealw=$pshownotealw=="1" ? 1 : 0; |
| 3666 |
$q = "SELECT `id` FROM `#__vikrentcar_gpayments` WHERE `file`=".$dbo->quote($ppayment).";"; |
| 3667 |
$dbo->setQuery($q); |
| 3668 |
$dbo->execute(); |
| 3669 |
//VikRentCar 1.8 : no longer block payment methods that are using the same PHP file |
| 3670 |
if ($dbo->getNumRows() >= 0) { |
| 3671 |
$q = "INSERT INTO `#__vikrentcar_gpayments` (`name`,`file`,`published`,`note`,`charge`,`setconfirmed`,`shownotealw`,`val_pcent`,`ch_disc`,`params`,`outposition`,`logo`) VALUES(".$dbo->quote($pname).",".$dbo->quote($ppayment).",".$dbo->quote($setpub).",".$dbo->quote($pnote).",".$dbo->quote($pcharge).",".$dbo->quote($psetconfirmed).",".$dbo->quote($pshownotealw).",'".$pval_pcent."','".$pch_disc."',".$dbo->quote($payparamstr).", " . $dbo->quote($poutposition) . ", " . $dbo->quote($plogo) . ");"; |
| 3672 |
$dbo->setQuery($q); |
| 3673 |
$dbo->execute(); |
| 3674 |
$mainframe->enqueueMessage(JText::translate('VRPAYMENTSAVED')); |
| 3675 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=payments"); |
| 3676 |
} else { |
| 3677 |
VikError::raiseWarning('', JText::translate('ERRINVFILEPAYMENT')); |
| 3678 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newpayment"); |
| 3679 |
} |
| 3680 |
} else { |
| 3681 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newpayment"); |
| 3682 |
} |
| 3683 |
} |
| 3684 |
|
| 3685 |
public function updatepayment() { |
| 3686 |
if (!JSession::checkToken()) { |
| 3687 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3688 |
} |
| 3689 |
$mainframe = JFactory::getApplication(); |
| 3690 |
$pwhere = VikRequest::getString('where', '', 'request'); |
| 3691 |
$pname = VikRequest::getString('name', '', 'request'); |
| 3692 |
$ppayment = VikRequest::getString('payment', '', 'request'); |
| 3693 |
$ppublished = VikRequest::getString('published', '', 'request'); |
| 3694 |
$pcharge = VikRequest::getFloat('charge', '', 'request'); |
| 3695 |
$psetconfirmed = VikRequest::getString('setconfirmed', '', 'request'); |
| 3696 |
$pshownotealw = VikRequest::getString('shownotealw', '', 'request'); |
| 3697 |
$pnote = VikRequest::getString('note', '', 'request', VIKREQUEST_ALLOWHTML); |
| 3698 |
$pval_pcent = VikRequest::getString('val_pcent', '', 'request'); |
| 3699 |
$pval_pcent = !in_array($pval_pcent, array('1', '2')) ? 1 : $pval_pcent; |
| 3700 |
$pch_disc = VikRequest::getString('ch_disc', '', 'request'); |
| 3701 |
$pch_disc = !in_array($pch_disc, array('1', '2')) ? 1 : $pch_disc; |
| 3702 |
$poutposition = VikRequest::getString('outposition', 'top', 'request'); |
| 3703 |
$plogo = VikRequest::getString('logo', '', 'request'); |
| 3704 |
$vikpaymentparams = VikRequest::getVar('vikpaymentparams', array(0)); |
| 3705 |
$payparamarr = array(); |
| 3706 |
$payparamstr = ''; |
| 3707 |
if (count($vikpaymentparams) > 0) { |
| 3708 |
foreach ($vikpaymentparams as $setting => $cont) { |
| 3709 |
if (strlen($setting) > 0) { |
| 3710 |
$payparamarr[$setting] = $cont; |
| 3711 |
} |
| 3712 |
} |
| 3713 |
if (count($payparamarr) > 0) { |
| 3714 |
$payparamstr = json_encode($payparamarr); |
| 3715 |
} |
| 3716 |
} |
| 3717 |
$dbo = JFactory::getDbo(); |
| 3718 |
if (!empty($pname) && !empty($ppayment) && !empty($pwhere)) { |
| 3719 |
$setpub=$ppublished=="1" ? 1 : 0; |
| 3720 |
$psetconfirmed=$psetconfirmed=="1" ? 1 : 0; |
| 3721 |
$pshownotealw=$pshownotealw=="1" ? 1 : 0; |
| 3722 |
$q = "SELECT `id` FROM `#__vikrentcar_gpayments` WHERE `file`=".$dbo->quote($ppayment)." AND `id`!='".$pwhere."';"; |
| 3723 |
$dbo->setQuery($q); |
| 3724 |
$dbo->execute(); |
| 3725 |
//VikRentCar 1.8 : no longer block payment methods that are using the same PHP file |
| 3726 |
if ($dbo->getNumRows() >= 0) { |
| 3727 |
$q = "UPDATE `#__vikrentcar_gpayments` SET `name`=".$dbo->quote($pname).",`file`=".$dbo->quote($ppayment).",`published`=".$dbo->quote($setpub).",`note`=".$dbo->quote($pnote).",`charge`=".$dbo->quote($pcharge).",`setconfirmed`=".$dbo->quote($psetconfirmed).",`shownotealw`=".$dbo->quote($pshownotealw).",`val_pcent`='".$pval_pcent."',`ch_disc`='".$pch_disc."',`params`=".$dbo->quote($payparamstr).",`outposition`=" . $dbo->quote($poutposition) . ",`logo`=" . $dbo->quote($plogo) . " WHERE `id`=".$dbo->quote($pwhere).";"; |
| 3728 |
$dbo->setQuery($q); |
| 3729 |
$dbo->execute(); |
| 3730 |
$mainframe->enqueueMessage(JText::translate('VRPAYMENTUPDATED')); |
| 3731 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=payments"); |
| 3732 |
} else { |
| 3733 |
VikError::raiseWarning('', JText::translate('ERRINVFILEPAYMENT')); |
| 3734 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editpayment&cid[]=".$pwhere); |
| 3735 |
} |
| 3736 |
} else { |
| 3737 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editpayment&cid[]=".$pwhere); |
| 3738 |
} |
| 3739 |
} |
| 3740 |
|
| 3741 |
public function removepayments() { |
| 3742 |
if (!JSession::checkToken()) { |
| 3743 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 3744 |
} |
| 3745 |
$ids = VikRequest::getVar('cid', array(0)); |
| 3746 |
if (@count($ids)) { |
| 3747 |
$dbo = JFactory::getDbo(); |
| 3748 |
foreach ($ids as $d) { |
| 3749 |
$q = "DELETE FROM `#__vikrentcar_gpayments` WHERE `id`=".$dbo->quote($d).";"; |
| 3750 |
$dbo->setQuery($q); |
| 3751 |
$dbo->execute(); |
| 3752 |
} |
| 3753 |
} |
| 3754 |
$mainframe = JFactory::getApplication(); |
| 3755 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=payments"); |
| 3756 |
} |
| 3757 |
|
| 3758 |
public function cancelpayment() { |
| 3759 |
$mainframe = JFactory::getApplication(); |
| 3760 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=payments"); |
| 3761 |
} |
| 3762 |
|
| 3763 |
public function modavailpayment() { |
| 3764 |
$cid = VikRequest::getVar('cid', array(0)); |
| 3765 |
$idp = $cid[0]; |
| 3766 |
if (!empty($idp)) { |
| 3767 |
$dbo = JFactory::getDBO(); |
| 3768 |
$q = "SELECT `published` FROM `#__vikrentcar_gpayments` WHERE `id`=".intval($idp).";"; |
| 3769 |
$dbo->setQuery($q); |
| 3770 |
$dbo->execute(); |
| 3771 |
$get = $dbo->loadAssocList(); |
| 3772 |
$q = "UPDATE `#__vikrentcar_gpayments` SET `published`=".(intval($get[0]['published']) == 1 ? '0' : '1')." WHERE `id`=".intval($idp).";"; |
| 3773 |
$dbo->setQuery($q); |
| 3774 |
$dbo->execute(); |
| 3775 |
} |
| 3776 |
$mainframe = JFactory::getApplication(); |
| 3777 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=payments"); |
| 3778 |
} |
| 3779 |
|
| 3780 |
public function sortpayment() { |
| 3781 |
$cid = VikRequest::getVar('cid', array(0)); |
| 3782 |
$sortid = $cid[0]; |
| 3783 |
$dbo = JFactory::getDBO(); |
| 3784 |
$mainframe = JFactory::getApplication(); |
| 3785 |
$pmode = VikRequest::getString('mode', '', 'request'); |
| 3786 |
if (!empty($pmode) && !empty($sortid)) { |
| 3787 |
$q = "SELECT `id`,`ordering` FROM `#__vikrentcar_gpayments` ORDER BY `#__vikrentcar_gpayments`.`ordering` ASC;"; |
| 3788 |
$dbo->setQuery($q); |
| 3789 |
$dbo->execute(); |
| 3790 |
$totr=$dbo->getNumRows(); |
| 3791 |
if ($totr > 1) { |
| 3792 |
$data = $dbo->loadAssocList(); |
| 3793 |
if ($pmode == "up") { |
| 3794 |
foreach ($data as $v) { |
| 3795 |
if ($v['id'] == $sortid) { |
| 3796 |
$y = $v['ordering']; |
| 3797 |
} |
| 3798 |
} |
| 3799 |
if ($y && $y > 1) { |
| 3800 |
$vik = $y - 1; |
| 3801 |
$found = false; |
| 3802 |
foreach ($data as $v) { |
| 3803 |
if (intval($v['ordering']) == intval($vik)) { |
| 3804 |
$found = true; |
| 3805 |
$q = "UPDATE `#__vikrentcar_gpayments` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 3806 |
$dbo->setQuery($q); |
| 3807 |
$dbo->execute(); |
| 3808 |
$q = "UPDATE `#__vikrentcar_gpayments` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 3809 |
$dbo->setQuery($q); |
| 3810 |
$dbo->execute(); |
| 3811 |
break; |
| 3812 |
} |
| 3813 |
} |
| 3814 |
if (!$found) { |
| 3815 |
$q = "UPDATE `#__vikrentcar_gpayments` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 3816 |
$dbo->setQuery($q); |
| 3817 |
$dbo->execute(); |
| 3818 |
} |
| 3819 |
} |
| 3820 |
} elseif ($pmode == "down") { |
| 3821 |
foreach ($data as $v) { |
| 3822 |
if ($v['id'] == $sortid) { |
| 3823 |
$y = $v['ordering']; |
| 3824 |
} |
| 3825 |
} |
| 3826 |
if ($y) { |
| 3827 |
$vik = $y + 1; |
| 3828 |
$found = false; |
| 3829 |
foreach ($data as $v) { |
| 3830 |
if (intval($v['ordering']) == intval($vik)) { |
| 3831 |
$found=true; |
| 3832 |
$q = "UPDATE `#__vikrentcar_gpayments` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 3833 |
$dbo->setQuery($q); |
| 3834 |
$dbo->execute(); |
| 3835 |
$q = "UPDATE `#__vikrentcar_gpayments` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 3836 |
$dbo->setQuery($q); |
| 3837 |
$dbo->execute(); |
| 3838 |
break; |
| 3839 |
} |
| 3840 |
} |
| 3841 |
if (!$found) { |
| 3842 |
$q = "UPDATE `#__vikrentcar_gpayments` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 3843 |
$dbo->setQuery($q); |
| 3844 |
$dbo->execute(); |
| 3845 |
} |
| 3846 |
} |
| 3847 |
} |
| 3848 |
} |
| 3849 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=payments"); |
| 3850 |
} else { |
| 3851 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 3852 |
} |
| 3853 |
} |
| 3854 |
|
| 3855 |
public function setordconfirmed() { |
| 3856 |
$cid = VikRequest::getVar('cid', array(0)); |
| 3857 |
$oid = $cid[0]; |
| 3858 |
$dbo = JFactory::getDbo(); |
| 3859 |
$app = JFactory::getApplication(); |
| 3860 |
$q = "SELECT * FROM `#__vikrentcar_orders` WHERE `id`=".(int)$oid." AND `status` != 'confirmed';"; |
| 3861 |
$dbo->setQuery($q); |
| 3862 |
$dbo->execute(); |
| 3863 |
if ($dbo->getNumRows() == 1) { |
| 3864 |
$order = $dbo->loadAssocList(); |
| 3865 |
$vrc_tn = VikRentCar::getTranslator(); |
| 3866 |
//check if the language in use is the same as the one used during the checkout |
| 3867 |
if (!empty($order[0]['lang'])) { |
| 3868 |
$lang = JFactory::getLanguage(); |
| 3869 |
if ($lang->getTag() != $order[0]['lang']) { |
| 3870 |
$lang->load('com_vikrentcar', VIKRENTCAR_ADMIN_LANG, $order[0]['lang'], true); |
| 3871 |
$vrc_tn::$force_tolang = $order[0]['lang']; |
| 3872 |
} |
| 3873 |
} |
| 3874 |
// |
| 3875 |
$q = "SELECT `units` FROM `#__vikrentcar_cars` WHERE `id`='".$order[0]['idcar']."';"; |
| 3876 |
$dbo->setQuery($q); |
| 3877 |
$dbo->execute(); |
| 3878 |
$units = $dbo->loadResult(); |
| 3879 |
$realback = VikRentCar::getHoursCarAvail() * 3600; |
| 3880 |
$realback += $order[0]['consegna']; |
| 3881 |
|
| 3882 |
/** |
| 3883 |
* Setting an order to confirmed is now allowed only in case of availability |
| 3884 |
* unless the administrator decides to force the confirmation of the order. |
| 3885 |
* |
| 3886 |
* @since 1.14.5 (J) - 1.2.0 (WP) |
| 3887 |
*/ |
| 3888 |
$pforce_availability = VikRequest::getInt('force_av', 0, 'request'); |
| 3889 |
$forced_availability = false; |
| 3890 |
$is_available = VikRentCar::carBookable($order[0]['idcar'], $units, $order[0]['ritiro'], $order[0]['consegna']); |
| 3891 |
$history_descr = ''; |
| 3892 |
|
| 3893 |
if (!$is_available && !$pforce_availability) { |
| 3894 |
// raise errors and redirect |
| 3895 |
VikError::raiseWarning('', JText::translate('VRBOOKNOTMADE')); |
| 3896 |
VikError::raiseWarning('', JText::translate('VRCFORCEAVAILABILITYCONF') . ' <a class="btn btn-danger" href="index.php?option=com_vikrentcar&task=setordconfirmed&force_av=1&cid[]=' . $oid . '">' . JText::translate('VRCFORCEAVAILABILITY') . '</a>'); |
| 3897 |
|
| 3898 |
$app->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=".$oid); |
| 3899 |
exit; |
| 3900 |
} |
| 3901 |
|
| 3902 |
if (!$is_available && $pforce_availability) { |
| 3903 |
// turn on flag to save that the order was forced |
| 3904 |
$forced_availability = true; |
| 3905 |
$history_descr = JText::translate('VRCAVAILABILITYFORCED'); |
| 3906 |
} |
| 3907 |
|
| 3908 |
// occupy the car |
| 3909 |
$q = "INSERT INTO `#__vikrentcar_busy` (`idcar`,`ritiro`,`consegna`,`realback`) VALUES(".(int)$order[0]['idcar'].",".(int)$order[0]['ritiro'].",".(int)$order[0]['consegna'].",".(int)$realback.");"; |
| 3910 |
$dbo->setQuery($q); |
| 3911 |
$dbo->execute(); |
| 3912 |
$busynow = $dbo->insertid(); |
| 3913 |
|
| 3914 |
// assign car specific unit |
| 3915 |
$car_index = null; |
| 3916 |
if (VRCFactory::getConfig()->get('autocarunit', 1)) { |
| 3917 |
$car_indexes = VikRentCar::getCarUnitNumsUnavailable($order[0], true); |
| 3918 |
if (!empty($car_indexes)) { |
| 3919 |
$car_index = $car_indexes[0]; |
| 3920 |
} |
| 3921 |
} |
| 3922 |
|
| 3923 |
// update records |
| 3924 |
$q = "UPDATE `#__vikrentcar_orders` SET `idbusy`=" . (int)$busynow . ", `status`='confirmed', `carindex`=" . (!empty($car_index) ? (int)$car_index : 'NULL') . " WHERE `id`=" . (int)$order[0]['id'] . ";"; |
| 3925 |
$dbo->setQuery($q); |
| 3926 |
$dbo->execute(); |
| 3927 |
$q = "DELETE FROM `#__vikrentcar_tmplock` WHERE `idorder`=".(int)$order[0]['id'].";"; |
| 3928 |
$dbo->setQuery($q); |
| 3929 |
$dbo->execute(); |
| 3930 |
// Booking History |
| 3931 |
VikRentCar::getOrderHistoryInstance()->setBid($order[0]['id'])->store('TC', $history_descr); |
| 3932 |
// |
| 3933 |
//send mail |
| 3934 |
$ftitle = VikRentCar::getFrontTitle($vrc_tn); |
| 3935 |
$nowts = $order[0]['ts']; |
| 3936 |
$carinfo = VikRentCar::getCarInfo($order[0]['idcar'], $vrc_tn); |
| 3937 |
$viklink = VikRentCar::externalroute("index.php?option=com_vikrentcar&view=order&sid=" . $order[0]['sid'] . "&ts=" . $order[0]['ts'] . (!empty($order[0]['lang']) ? '&lang=' . $order[0]['lang'] : ''), false); |
| 3938 |
// |
| 3939 |
$is_cust_cost = (!empty($order[0]['cust_cost']) && $order[0]['cust_cost'] > 0); |
| 3940 |
if (!empty($order[0]['idtar'])) { |
| 3941 |
//vikrentcar 1.5 |
| 3942 |
if ($order[0]['hourly'] == 1) { |
| 3943 |
$q = "SELECT * FROM `#__vikrentcar_dispcosthours` WHERE `id`=".(int)$order[0]['idtar'].";"; |
| 3944 |
} else { |
| 3945 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `id`=".(int)$order[0]['idtar'].";"; |
| 3946 |
} |
| 3947 |
// |
| 3948 |
$dbo->setQuery($q); |
| 3949 |
$dbo->execute(); |
| 3950 |
if ($dbo->getNumRows() == 0) { |
| 3951 |
if ($order[0]['hourly'] == 1) { |
| 3952 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `id`=".(int)$order[0]['idtar'].";"; |
| 3953 |
$dbo->setQuery($q); |
| 3954 |
$dbo->execute(); |
| 3955 |
if ($dbo->getNumRows() == 1) { |
| 3956 |
$tar = $dbo->loadAssocList(); |
| 3957 |
} |
| 3958 |
} |
| 3959 |
} else { |
| 3960 |
$tar = $dbo->loadAssocList(); |
| 3961 |
} |
| 3962 |
} elseif ($is_cust_cost) { |
| 3963 |
//Custom Rate |
| 3964 |
$tar = array(0 => array( |
| 3965 |
'id' => -1, |
| 3966 |
'idcar' => $order[0]['idcar'], |
| 3967 |
'days' => $order[0]['days'], |
| 3968 |
'idprice' => -1, |
| 3969 |
'cost' => $order[0]['cust_cost'], |
| 3970 |
'attrdata' => '', |
| 3971 |
)); |
| 3972 |
} |
| 3973 |
//vikrentcar 1.5 |
| 3974 |
if ($order[0]['hourly'] == 1 && !empty($tar[0]['hours'])) { |
| 3975 |
foreach ($tar as $kt => $vt) { |
| 3976 |
$tar[$kt]['days'] = 1; |
| 3977 |
} |
| 3978 |
} |
| 3979 |
// |
| 3980 |
//vikrentcar 1.6 |
| 3981 |
$checkhourscharges = 0; |
| 3982 |
$ppickup = $order[0]['ritiro']; |
| 3983 |
$prelease = $order[0]['consegna']; |
| 3984 |
$secdiff = $prelease - $ppickup; |
| 3985 |
$daysdiff = $secdiff / 86400; |
| 3986 |
if (is_int($daysdiff)) { |
| 3987 |
if ($daysdiff < 1) { |
| 3988 |
$daysdiff = 1; |
| 3989 |
} |
| 3990 |
} else { |
| 3991 |
if ($daysdiff < 1) { |
| 3992 |
$daysdiff = 1; |
| 3993 |
} else { |
| 3994 |
$sum = floor($daysdiff) * 86400; |
| 3995 |
$newdiff = $secdiff - $sum; |
| 3996 |
$maxhmore = VikRentCar::getHoursMoreRb() * 3600; |
| 3997 |
if ($maxhmore >= $newdiff) { |
| 3998 |
$daysdiff = floor($daysdiff); |
| 3999 |
} else { |
| 4000 |
$daysdiff = ceil($daysdiff); |
| 4001 |
/** |
| 4002 |
* Apply proper rounding with gratuity period. |
| 4003 |
* |
| 4004 |
* @since 1.15.1 (J) - 1.3.2 (WP) |
| 4005 |
* @since 1.15.8 (J) - 1.4.5 (WP) |
| 4006 |
*/ |
| 4007 |
$ehours_float = ($newdiff - $maxhmore) / 3600; |
| 4008 |
$ehours = intval(ceil($ehours_float)); |
| 4009 |
$ehours = !$ehours && $ehours_float > 0 && $maxhmore > 0 ? 1 : $ehours; |
| 4010 |
$checkhourscharges = $ehours; |
| 4011 |
if ($checkhourscharges > 0) { |
| 4012 |
$aehourschbasp = VikRentCar::applyExtraHoursChargesBasp(); |
| 4013 |
} |
| 4014 |
} |
| 4015 |
} |
| 4016 |
} |
| 4017 |
if ($checkhourscharges > 0 && $aehourschbasp == true && !$is_cust_cost) { |
| 4018 |
$ret = VikRentCar::applyExtraHoursChargesCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, false, true, true); |
| 4019 |
$tar = $ret['return']; |
| 4020 |
$calcdays = $ret['days']; |
| 4021 |
} |
| 4022 |
if ($checkhourscharges > 0 && $aehourschbasp == false && !$is_cust_cost) { |
| 4023 |
$tar = VikRentCar::extraHoursSetPreviousFareCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, true); |
| 4024 |
$tar = VikRentCar::applySeasonsCar($tar, $order[0]['ritiro'], $order[0]['consegna'], $order[0]['idplace']); |
| 4025 |
$ret = VikRentCar::applyExtraHoursChargesCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, true, true, true); |
| 4026 |
$tar = $ret['return']; |
| 4027 |
$calcdays = $ret['days']; |
| 4028 |
} else { |
| 4029 |
if (!$is_cust_cost) { |
| 4030 |
//Seasonal prices only if not a custom rate |
| 4031 |
$tar = VikRentCar::applySeasonsCar($tar, $order[0]['ritiro'], $order[0]['consegna'], $order[0]['idplace']); |
| 4032 |
} |
| 4033 |
} |
| 4034 |
// |
| 4035 |
$ritplace = (!empty($order[0]['idplace']) ? VikRentCar::getPlaceName($order[0]['idplace'], $vrc_tn) : ""); |
| 4036 |
$consegnaplace = (!empty($order[0]['idreturnplace']) ? VikRentCar::getPlaceName($order[0]['idreturnplace'], $vrc_tn) : ""); |
| 4037 |
$costplusiva = $is_cust_cost ? VikRentCar::sayCustCostPlusIva($tar[0]['cost'], $order[0]['cust_idiva']) : VikRentCar::sayCostPlusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 4038 |
$costminusiva = $is_cust_cost ? VikRentCar::sayCustCostMinusIva($tar[0]['cost'], $order[0]['cust_idiva']) : VikRentCar::sayCostMinusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 4039 |
$pricestr = ($is_cust_cost ? JText::translate('VRCRENTCUSTRATEPLAN').": ".$costplusiva : VikRentCar::getPriceName($tar[0]['idprice'], $vrc_tn)).": ".$costplusiva.(!empty($tar[0]['attrdata']) ? "\n".VikRentCar::getPriceAttr($tar[0]['idprice'], $vrc_tn).": ".$tar[0]['attrdata'] : ""); |
| 4040 |
$isdue = $is_cust_cost ? $tar[0]['cost'] : VikRentCar::sayCostPlusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 4041 |
$tot_taxes = ($costplusiva - $costminusiva); |
| 4042 |
$optstr = ""; |
| 4043 |
$optarrtaxnet = array(); |
| 4044 |
if (!empty($order[0]['optionals'])) { |
| 4045 |
$stepo = explode(";", $order[0]['optionals']); |
| 4046 |
foreach ($stepo as $oo) { |
| 4047 |
if (!empty($oo)) { |
| 4048 |
$stept = explode(":", $oo); |
| 4049 |
$q = "SELECT `id`,`name`,`cost`,`perday`,`hmany`,`idiva`,`maxprice` FROM `#__vikrentcar_optionals` WHERE `id`=".$dbo->quote($stept[0]).";"; |
| 4050 |
$dbo->setQuery($q); |
| 4051 |
$dbo->execute(); |
| 4052 |
if ($dbo->getNumRows() == 1) { |
| 4053 |
$actopt=$dbo->loadAssocList(); |
| 4054 |
$vrc_tn->translateContents($actopt, '#__vikrentcar_optionals'); |
| 4055 |
$realcost = intval($actopt[0]['perday']) == 1 ? ($actopt[0]['cost'] * $order[0]['days'] * $stept[1]) : ($actopt[0]['cost'] * $stept[1]); |
| 4056 |
$basequancost = intval($actopt[0]['perday']) == 1 ? ($actopt[0]['cost'] * $order[0]['days']) : $actopt[0]['cost']; |
| 4057 |
if (!empty($actopt[0]['maxprice']) && $actopt[0]['maxprice'] > 0 && $basequancost > $actopt[0]['maxprice']) { |
| 4058 |
$realcost = $actopt[0]['maxprice']; |
| 4059 |
if (intval($actopt[0]['hmany']) == 1 && intval($stept[1]) > 1) { |
| 4060 |
$realcost = $actopt[0]['maxprice'] * $stept[1]; |
| 4061 |
} |
| 4062 |
} |
| 4063 |
$tmpopr = VikRentCar::sayOptionalsPlusIva($realcost, $actopt[0]['idiva'], $order[0]); |
| 4064 |
$isdue += $tmpopr; |
| 4065 |
$optnetprice = VikRentCar::sayOptionalsMinusIva($realcost, $actopt[0]['idiva'], $order[0]); |
| 4066 |
$optarrtaxnet[] = $optnetprice; |
| 4067 |
$optstr .= ($stept[1] > 1 ? $stept[1]." " : "").$actopt[0]['name'].": ".$tmpopr."\n"; |
| 4068 |
$tot_taxes += ($tmpopr - $optnetprice); |
| 4069 |
} |
| 4070 |
} |
| 4071 |
} |
| 4072 |
} |
| 4073 |
//custom extra costs |
| 4074 |
if (!empty($order[0]['extracosts'])) { |
| 4075 |
$cur_extra_costs = json_decode($order[0]['extracosts'], true); |
| 4076 |
foreach ($cur_extra_costs as $eck => $ecv) { |
| 4077 |
$efee_cost = VikRentCar::sayOptionalsPlusIva($ecv['cost'], $ecv['idtax'], $order[0]); |
| 4078 |
$isdue += $efee_cost; |
| 4079 |
$efee_cost_without = VikRentCar::sayOptionalsMinusIva($ecv['cost'], $ecv['idtax'], $order[0]); |
| 4080 |
$optarrtaxnet[] = $efee_cost_without; |
| 4081 |
$optstr.=$ecv['name'].": ".$efee_cost."\n"; |
| 4082 |
$tot_taxes += ($efee_cost - $efee_cost_without); |
| 4083 |
} |
| 4084 |
} |
| 4085 |
// |
| 4086 |
$maillocfee=""; |
| 4087 |
$locfeewithouttax = 0; |
| 4088 |
if (!empty($order[0]['idplace']) && !empty($order[0]['idreturnplace'])) { |
| 4089 |
$locfee=VikRentCar::getLocFee($order[0]['idplace'], $order[0]['idreturnplace']); |
| 4090 |
if ($locfee) { |
| 4091 |
//VikRentCar 1.7 - Location fees overrides |
| 4092 |
if (strlen($locfee['losoverride']) > 0) { |
| 4093 |
$arrvaloverrides = array(); |
| 4094 |
$valovrparts = explode('_', $locfee['losoverride']); |
| 4095 |
foreach ($valovrparts as $valovr) { |
| 4096 |
if (!empty($valovr)) { |
| 4097 |
$ovrinfo = explode(':', $valovr); |
| 4098 |
$arrvaloverrides[$ovrinfo[0]] = $ovrinfo[1]; |
| 4099 |
} |
| 4100 |
} |
| 4101 |
if (array_key_exists($order[0]['days'], $arrvaloverrides)) { |
| 4102 |
$locfee['cost'] = $arrvaloverrides[$order[0]['days']]; |
| 4103 |
} |
| 4104 |
} |
| 4105 |
//end VikRentCar 1.7 - Location fees overrides |
| 4106 |
$locfeecost = intval($locfee['daily']) == 1 ? ($locfee['cost'] * $order[0]['days']) : $locfee['cost']; |
| 4107 |
$locfeewith = VikRentCar::sayLocFeePlusIva($locfeecost, $locfee['idiva'], $order[0]); |
| 4108 |
$isdue += $locfeewith; |
| 4109 |
$locfeewithouttax = VikRentCar::sayLocFeeMinusIva($locfeecost, $locfee['idiva'], $order[0]); |
| 4110 |
$maillocfee = $locfeewith; |
| 4111 |
$tot_taxes += ($locfeewith - $locfeewithouttax); |
| 4112 |
} |
| 4113 |
} |
| 4114 |
//VRC 1.9 - Out of Hours Fees |
| 4115 |
$oohfee = VikRentCar::getOutOfHoursFees($order[0]['idplace'], $order[0]['idreturnplace'], $order[0]['ritiro'], $order[0]['consegna'], array('id' => $order[0]['idcar'])); |
| 4116 |
$mailoohfee = ""; |
| 4117 |
$oohfeewithouttax = 0; |
| 4118 |
if (count($oohfee) > 0) { |
| 4119 |
$oohfeewith = VikRentCar::sayOohFeePlusIva($oohfee['cost'], $oohfee['idiva']); |
| 4120 |
$isdue += $oohfeewith; |
| 4121 |
$oohfeewithouttax = VikRentCar::sayOohFeeMinusIva($oohfee['cost'], $oohfee['idiva']); |
| 4122 |
$mailoohfee = $oohfeewith; |
| 4123 |
$tot_taxes += ($oohfeewith - $oohfeewithouttax); |
| 4124 |
} |
| 4125 |
// |
| 4126 |
//vikrentcar 1.6 coupon |
| 4127 |
$usedcoupon = false; |
| 4128 |
$origisdue = $isdue; |
| 4129 |
if (strlen($order[0]['coupon']) > 0) { |
| 4130 |
$usedcoupon = true; |
| 4131 |
$expcoupon = explode(";", $order[0]['coupon']); |
| 4132 |
$isdue = $isdue - $expcoupon[1]; |
| 4133 |
// old total : old taxes = new total : new taxes |
| 4134 |
$tot_taxes = $tot_taxes * $isdue / $origisdue; |
| 4135 |
} |
| 4136 |
// |
| 4137 |
if (!empty($busynow)) { |
| 4138 |
$arrayinfopdf = array( |
| 4139 |
'days' => $order[0]['days'], |
| 4140 |
'tarminusiva' => $costminusiva, |
| 4141 |
'tartax' => ($costplusiva - $costminusiva), |
| 4142 |
'opttaxnet' => $optarrtaxnet, |
| 4143 |
'locfeenet' => $locfeewithouttax, |
| 4144 |
'oohfeenet' => $oohfeewithouttax, |
| 4145 |
'order_id' => $order[0]['id'], |
| 4146 |
'tot_paid' => $order[0]['totpaid'], |
| 4147 |
); |
| 4148 |
$app->enqueueMessage(JText::translate('VRORDERSETASCONF')); |
| 4149 |
// notify the customer unless it was a re-confirmation |
| 4150 |
$pskip = VikRequest::getInt('skip_notification', 0, 'request'); |
| 4151 |
if ($pskip < 1) { |
| 4152 |
VikRentCar::sendOrderEmail($order[0]['id'], array('customer')); |
| 4153 |
} |
| 4154 |
} |
| 4155 |
} |
| 4156 |
$app->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=".$oid); |
| 4157 |
} |
| 4158 |
|
| 4159 |
public function overv() { |
| 4160 |
VikRentCarHelper::printHeader("15"); |
| 4161 |
|
| 4162 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'overv')); |
| 4163 |
|
| 4164 |
parent::display(); |
| 4165 |
|
| 4166 |
if (VikRentCar::showFooter()) { |
| 4167 |
VikRentCarHelper::printFooter(); |
| 4168 |
} |
| 4169 |
} |
| 4170 |
|
| 4171 |
public function canceloverv() { |
| 4172 |
$mainframe = JFactory::getApplication(); |
| 4173 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=overv"); |
| 4174 |
} |
| 4175 |
|
| 4176 |
public function cancelbusy() { |
| 4177 |
$pidorder = VikRequest::getString('idorder', '', 'request'); |
| 4178 |
$pgoto = VikRequest::getString('goto', '', 'request', VIKREQUEST_ALLOWRAW); |
| 4179 |
$mainframe = JFactory::getApplication(); |
| 4180 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=".$pidorder.($pgoto == 'overv' ? '&goto=overv' : '')); |
| 4181 |
} |
| 4182 |
|
| 4183 |
public function customf() { |
| 4184 |
VikRentCarHelper::printHeader("16"); |
| 4185 |
|
| 4186 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'customf')); |
| 4187 |
|
| 4188 |
parent::display(); |
| 4189 |
|
| 4190 |
if (VikRentCar::showFooter()) { |
| 4191 |
VikRentCarHelper::printFooter(); |
| 4192 |
} |
| 4193 |
} |
| 4194 |
|
| 4195 |
public function newcustomf() { |
| 4196 |
VikRentCarHelper::printHeader("16"); |
| 4197 |
|
| 4198 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecustomf')); |
| 4199 |
|
| 4200 |
parent::display(); |
| 4201 |
|
| 4202 |
if (VikRentCar::showFooter()) { |
| 4203 |
VikRentCarHelper::printFooter(); |
| 4204 |
} |
| 4205 |
} |
| 4206 |
|
| 4207 |
public function editcustomf() { |
| 4208 |
VikRentCarHelper::printHeader("16"); |
| 4209 |
|
| 4210 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecustomf')); |
| 4211 |
|
| 4212 |
parent::display(); |
| 4213 |
|
| 4214 |
if (VikRentCar::showFooter()) { |
| 4215 |
VikRentCarHelper::printFooter(); |
| 4216 |
} |
| 4217 |
} |
| 4218 |
|
| 4219 |
public function createcustomf() { |
| 4220 |
if (!JSession::checkToken()) { |
| 4221 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 4222 |
} |
| 4223 |
$pname = VikRequest::getString('name', '', 'request', VIKREQUEST_ALLOWHTML); |
| 4224 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 4225 |
$pchoose = VikRequest::getVar('choose', array(0)); |
| 4226 |
$prequired = VikRequest::getString('required', '', 'request'); |
| 4227 |
$prequired = $prequired == "1" ? 1 : 0; |
| 4228 |
$pflag = VikRequest::getString('flag', '', 'request'); |
| 4229 |
$pisemail = $pflag == 'isemail' ? 1 : 0; |
| 4230 |
$pisnominative = $pflag == 'isnominative' && $ptype == 'text' ? 1 : 0; |
| 4231 |
$pisphone = $pflag == 'isphone' && $ptype == 'text' ? 1 : 0; |
| 4232 |
$pisaddress = $pflag == 'isaddress' && $ptype == 'text' ? 1 : 0; |
| 4233 |
$piscity = $pflag == 'iscity' && $ptype == 'text' ? 1 : 0; |
| 4234 |
$piszip = $pflag == 'iszip' && $ptype == 'text' ? 1 : 0; |
| 4235 |
$piscompany = $pflag == 'iscompany' && $ptype == 'text' ? 1 : 0; |
| 4236 |
$pisvat = $pflag == 'isvat' && $ptype == 'text' ? 1 : 0; |
| 4237 |
$fieldflag = ''; |
| 4238 |
if ($pisaddress == 1) { |
| 4239 |
$fieldflag = 'address'; |
| 4240 |
} elseif ($piscity == 1) { |
| 4241 |
$fieldflag = 'city'; |
| 4242 |
} elseif ($piszip == 1) { |
| 4243 |
$fieldflag = 'zip'; |
| 4244 |
} elseif ($piscompany == 1) { |
| 4245 |
$fieldflag = 'company'; |
| 4246 |
} elseif ($pisvat == 1) { |
| 4247 |
$fieldflag = 'vat'; |
| 4248 |
} |
| 4249 |
$ppoplink = VikRequest::getString('poplink', '', 'request'); |
| 4250 |
$choosestr = ""; |
| 4251 |
if (@count($pchoose) > 0) { |
| 4252 |
foreach ($pchoose as $ch) { |
| 4253 |
if (!empty($ch)) { |
| 4254 |
$choosestr .= $ch.";;__;;"; |
| 4255 |
} |
| 4256 |
} |
| 4257 |
} |
| 4258 |
$dbo = JFactory::getDbo(); |
| 4259 |
$q = "SELECT `ordering` FROM `#__vikrentcar_custfields` ORDER BY `#__vikrentcar_custfields`.`ordering` DESC LIMIT 1;"; |
| 4260 |
$dbo->setQuery($q); |
| 4261 |
$dbo->execute(); |
| 4262 |
if ($dbo->getNumRows() == 1) { |
| 4263 |
$getlast = $dbo->loadResult(); |
| 4264 |
$newsortnum = $getlast + 1; |
| 4265 |
} else { |
| 4266 |
$newsortnum = 1; |
| 4267 |
} |
| 4268 |
$q = "INSERT INTO `#__vikrentcar_custfields` (`name`,`type`,`choose`,`required`,`ordering`,`isemail`,`poplink`,`isnominative`,`isphone`,`flag`) VALUES(".$dbo->quote($pname).", ".$dbo->quote($ptype).", ".$dbo->quote($choosestr).", ".$dbo->quote($prequired).", ".$dbo->quote($newsortnum).", ".$dbo->quote($pisemail).", ".$dbo->quote($ppoplink).", ".$pisnominative.", ".$pisphone.", ".$dbo->quote($fieldflag).");"; |
| 4269 |
$dbo->setQuery($q); |
| 4270 |
$dbo->execute(); |
| 4271 |
$mainframe = JFactory::getApplication(); |
| 4272 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customf"); |
| 4273 |
} |
| 4274 |
|
| 4275 |
public function updatecustomf() { |
| 4276 |
if (!JSession::checkToken()) { |
| 4277 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 4278 |
} |
| 4279 |
$pname = VikRequest::getString('name', '', 'request', VIKREQUEST_ALLOWHTML); |
| 4280 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 4281 |
$pchoose = VikRequest::getVar('choose', array(0)); |
| 4282 |
$prequired = VikRequest::getString('required', '', 'request'); |
| 4283 |
$prequired = $prequired == "1" ? 1 : 0; |
| 4284 |
$pflag = VikRequest::getString('flag', '', 'request'); |
| 4285 |
$pisemail = $pflag == 'isemail' ? 1 : 0; |
| 4286 |
$pisnominative = $pflag == 'isnominative' && $ptype == 'text' ? 1 : 0; |
| 4287 |
$pisphone = $pflag == 'isphone' && $ptype == 'text' ? 1 : 0; |
| 4288 |
$pisaddress = $pflag == 'isaddress' && $ptype == 'text' ? 1 : 0; |
| 4289 |
$piscity = $pflag == 'iscity' && $ptype == 'text' ? 1 : 0; |
| 4290 |
$piszip = $pflag == 'iszip' && $ptype == 'text' ? 1 : 0; |
| 4291 |
$piscompany = $pflag == 'iscompany' && $ptype == 'text' ? 1 : 0; |
| 4292 |
$pisvat = $pflag == 'isvat' && $ptype == 'text' ? 1 : 0; |
| 4293 |
$fieldflag = ''; |
| 4294 |
if ($pisaddress == 1) { |
| 4295 |
$fieldflag = 'address'; |
| 4296 |
} elseif ($piscity == 1) { |
| 4297 |
$fieldflag = 'city'; |
| 4298 |
} elseif ($piszip == 1) { |
| 4299 |
$fieldflag = 'zip'; |
| 4300 |
} elseif ($piscompany == 1) { |
| 4301 |
$fieldflag = 'company'; |
| 4302 |
} elseif ($pisvat == 1) { |
| 4303 |
$fieldflag = 'vat'; |
| 4304 |
} |
| 4305 |
$ppoplink = VikRequest::getString('poplink', '', 'request'); |
| 4306 |
$pwhere = VikRequest::getInt('where', '', 'request'); |
| 4307 |
$choosestr = ""; |
| 4308 |
if (@count($pchoose) > 0) { |
| 4309 |
foreach ($pchoose as $ch) { |
| 4310 |
if (!empty($ch)) { |
| 4311 |
$choosestr .= $ch.";;__;;"; |
| 4312 |
} |
| 4313 |
} |
| 4314 |
} |
| 4315 |
$dbo = JFactory::getDbo(); |
| 4316 |
$q = "UPDATE `#__vikrentcar_custfields` SET `name`=".$dbo->quote($pname).",`type`=".$dbo->quote($ptype).",`choose`=".$dbo->quote($choosestr).",`required`=".$dbo->quote($prequired).",`isemail`=".$dbo->quote($pisemail).",`poplink`=".$dbo->quote($ppoplink).",`isnominative`=".$pisnominative.",`isphone`=".$pisphone.",`flag`=".$dbo->quote($fieldflag)." WHERE `id`=".$dbo->quote($pwhere).";"; |
| 4317 |
$dbo->setQuery($q); |
| 4318 |
$dbo->execute(); |
| 4319 |
$mainframe = JFactory::getApplication(); |
| 4320 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customf"); |
| 4321 |
} |
| 4322 |
|
| 4323 |
public function removecustomf() { |
| 4324 |
if (!JSession::checkToken()) { |
| 4325 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 4326 |
} |
| 4327 |
$ids = VikRequest::getVar('cid', array(0)); |
| 4328 |
if (@count($ids)) { |
| 4329 |
$dbo = JFactory::getDbo(); |
| 4330 |
foreach ($ids as $d) { |
| 4331 |
$q = "DELETE FROM `#__vikrentcar_custfields` WHERE `id`=".$dbo->quote($d).";"; |
| 4332 |
$dbo->setQuery($q); |
| 4333 |
$dbo->execute(); |
| 4334 |
} |
| 4335 |
} |
| 4336 |
$mainframe = JFactory::getApplication(); |
| 4337 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customf"); |
| 4338 |
} |
| 4339 |
|
| 4340 |
public function cancelcustomf() { |
| 4341 |
$mainframe = JFactory::getApplication(); |
| 4342 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customf"); |
| 4343 |
} |
| 4344 |
|
| 4345 |
public function sortfield() { |
| 4346 |
$sortid = VikRequest::getVar('cid', array(0)); |
| 4347 |
$pmode = VikRequest::getString('mode', '', 'request'); |
| 4348 |
$dbo = JFactory::getDbo(); |
| 4349 |
$mainframe = JFactory::getApplication(); |
| 4350 |
if (!empty($pmode)) { |
| 4351 |
$q = "SELECT `id`,`ordering` FROM `#__vikrentcar_custfields` ORDER BY `#__vikrentcar_custfields`.`ordering` ASC;"; |
| 4352 |
$dbo->setQuery($q); |
| 4353 |
$dbo->execute(); |
| 4354 |
$totr=$dbo->getNumRows(); |
| 4355 |
if ($totr > 1) { |
| 4356 |
$data = $dbo->loadAssocList(); |
| 4357 |
if ($pmode == "up") { |
| 4358 |
foreach ($data as $v) { |
| 4359 |
if ($v['id'] == $sortid[0]) { |
| 4360 |
$y = $v['ordering']; |
| 4361 |
} |
| 4362 |
} |
| 4363 |
if ($y && $y > 1) { |
| 4364 |
$vik = $y - 1; |
| 4365 |
$found = false; |
| 4366 |
foreach ($data as $v) { |
| 4367 |
if (intval($v['ordering'])==intval($vik)) { |
| 4368 |
$found = true; |
| 4369 |
$q = "UPDATE `#__vikrentcar_custfields` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 4370 |
$dbo->setQuery($q); |
| 4371 |
$dbo->execute(); |
| 4372 |
$q = "UPDATE `#__vikrentcar_custfields` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 4373 |
$dbo->setQuery($q); |
| 4374 |
$dbo->execute(); |
| 4375 |
break; |
| 4376 |
} |
| 4377 |
} |
| 4378 |
if (!$found) { |
| 4379 |
$q = "UPDATE `#__vikrentcar_custfields` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 4380 |
$dbo->setQuery($q); |
| 4381 |
$dbo->execute(); |
| 4382 |
} |
| 4383 |
} |
| 4384 |
} elseif ($pmode == "down") { |
| 4385 |
foreach ($data as $v) { |
| 4386 |
if ($v['id'] == $sortid[0]) { |
| 4387 |
$y = $v['ordering']; |
| 4388 |
} |
| 4389 |
} |
| 4390 |
if ($y) { |
| 4391 |
$vik = $y + 1; |
| 4392 |
$found = false; |
| 4393 |
foreach ($data as $v) { |
| 4394 |
if (intval($v['ordering'])==intval($vik)) { |
| 4395 |
$found = true; |
| 4396 |
$q = "UPDATE `#__vikrentcar_custfields` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 4397 |
$dbo->setQuery($q); |
| 4398 |
$dbo->execute(); |
| 4399 |
$q = "UPDATE `#__vikrentcar_custfields` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 4400 |
$dbo->setQuery($q); |
| 4401 |
$dbo->execute(); |
| 4402 |
break; |
| 4403 |
} |
| 4404 |
} |
| 4405 |
if (!$found) { |
| 4406 |
$q = "UPDATE `#__vikrentcar_custfields` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 4407 |
$dbo->setQuery($q); |
| 4408 |
$dbo->execute(); |
| 4409 |
} |
| 4410 |
} |
| 4411 |
} |
| 4412 |
} |
| 4413 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customf"); |
| 4414 |
} else { |
| 4415 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 4416 |
} |
| 4417 |
} |
| 4418 |
|
| 4419 |
public function removemoreimgs() { |
| 4420 |
$mainframe = JFactory::getApplication(); |
| 4421 |
$pcarid = VikRequest::getInt('carid', '', 'request'); |
| 4422 |
$pimgind = VikRequest::getInt('imgind', '', 'request'); |
| 4423 |
if (!empty($pcarid) && strlen($pimgind) > 0) { |
| 4424 |
$dbo = JFactory::getDbo(); |
| 4425 |
$q = "SELECT `moreimgs` FROM `#__vikrentcar_cars` WHERE `id`='".$pcarid."';"; |
| 4426 |
$dbo->setQuery($q); |
| 4427 |
$dbo->execute(); |
| 4428 |
$actmore = $dbo->loadResult(); |
| 4429 |
if (strlen($actmore) > 0) { |
| 4430 |
$actsplit = explode(';;', $actmore); |
| 4431 |
if (array_key_exists($pimgind, $actsplit)) { |
| 4432 |
@unlink(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'big_'.$actsplit[$pimgind]); |
| 4433 |
@unlink(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'thumb_'.$actsplit[$pimgind]); |
| 4434 |
unset($actsplit[$pimgind]); |
| 4435 |
$newstr = ""; |
| 4436 |
foreach ($actsplit as $oi) { |
| 4437 |
if (!empty($oi)) { |
| 4438 |
$newstr .= $oi.';;'; |
| 4439 |
} |
| 4440 |
} |
| 4441 |
$q = "UPDATE `#__vikrentcar_cars` SET `moreimgs`=".$dbo->quote($newstr)." WHERE `id`='".$pcarid."';"; |
| 4442 |
$dbo->setQuery($q); |
| 4443 |
$dbo->execute(); |
| 4444 |
} |
| 4445 |
} |
| 4446 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editcar&cid[]=".$pcarid); |
| 4447 |
} else { |
| 4448 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 4449 |
} |
| 4450 |
} |
| 4451 |
|
| 4452 |
public function coupons() { |
| 4453 |
VikRentCarHelper::printHeader("17"); |
| 4454 |
|
| 4455 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'coupons')); |
| 4456 |
|
| 4457 |
parent::display(); |
| 4458 |
|
| 4459 |
if (VikRentCar::showFooter()) { |
| 4460 |
VikRentCarHelper::printFooter(); |
| 4461 |
} |
| 4462 |
} |
| 4463 |
|
| 4464 |
public function newcoupon() { |
| 4465 |
VikRentCarHelper::printHeader("17"); |
| 4466 |
|
| 4467 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecoupon')); |
| 4468 |
|
| 4469 |
parent::display(); |
| 4470 |
|
| 4471 |
if (VikRentCar::showFooter()) { |
| 4472 |
VikRentCarHelper::printFooter(); |
| 4473 |
} |
| 4474 |
} |
| 4475 |
|
| 4476 |
public function editcoupon() { |
| 4477 |
VikRentCarHelper::printHeader("17"); |
| 4478 |
|
| 4479 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecoupon')); |
| 4480 |
|
| 4481 |
parent::display(); |
| 4482 |
|
| 4483 |
if (VikRentCar::showFooter()) { |
| 4484 |
VikRentCarHelper::printFooter(); |
| 4485 |
} |
| 4486 |
} |
| 4487 |
|
| 4488 |
public function createcoupon() { |
| 4489 |
if (!JSession::checkToken()) { |
| 4490 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 4491 |
} |
| 4492 |
$mainframe = JFactory::getApplication(); |
| 4493 |
$pcode = VikRequest::getString('code', '', 'request'); |
| 4494 |
$pvalue = VikRequest::getFloat('value', '', 'request'); |
| 4495 |
$pfrom = VikRequest::getString('from', '', 'request'); |
| 4496 |
$pto = VikRequest::getString('to', '', 'request'); |
| 4497 |
$pidcars = VikRequest::getVar('idcars', array(0)); |
| 4498 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 4499 |
$ptype = $ptype == "1" ? 1 : 2; |
| 4500 |
$ppercentot = VikRequest::getString('percentot', '', 'request'); |
| 4501 |
$ppercentot = $ppercentot == "1" ? 1 : 2; |
| 4502 |
$pallvehicles = VikRequest::getString('allvehicles', '', 'request'); |
| 4503 |
$pallvehicles = $pallvehicles == "1" ? 1 : 0; |
| 4504 |
$pmintotord = VikRequest::getFloat('mintotord', 0, 'request'); |
| 4505 |
$pmaxtotord = VikRequest::getFloat('maxtotord', 0, 'request'); |
| 4506 |
$pexcludetaxes = VikRequest::getInt('excludetaxes', 0, 'request'); |
| 4507 |
$stridcars = ""; |
| 4508 |
if ($pidcars && $pallvehicles != 1) { |
| 4509 |
foreach ($pidcars as $ch) { |
| 4510 |
if (!empty($ch)) { |
| 4511 |
$stridcars .= ";".$ch.";"; |
| 4512 |
} |
| 4513 |
} |
| 4514 |
} |
| 4515 |
$strdatevalid = ""; |
| 4516 |
if (strlen($pfrom) > 0 && strlen($pto) > 0) { |
| 4517 |
$first = VikRentCar::getDateTimestamp($pfrom, 0, 0); |
| 4518 |
$second = VikRentCar::getDateTimestamp($pto, 0, 0); |
| 4519 |
if ($first < $second) { |
| 4520 |
$strdatevalid .= $first."-".$second; |
| 4521 |
} |
| 4522 |
} |
| 4523 |
$dbo = JFactory::getDbo(); |
| 4524 |
$q = "SELECT * FROM `#__vikrentcar_coupons` WHERE `code`=".$dbo->quote($pcode).";"; |
| 4525 |
$dbo->setQuery($q); |
| 4526 |
$dbo->execute(); |
| 4527 |
if ($dbo->getNumRows() > 0) { |
| 4528 |
VikError::raiseWarning('', JText::translate('VRCCOUPONEXISTS')); |
| 4529 |
} else { |
| 4530 |
$mainframe->enqueueMessage(JText::translate('VRCCOUPONSAVEOK')); |
| 4531 |
$q = "INSERT INTO `#__vikrentcar_coupons` (`code`,`type`,`percentot`,`value`,`datevalid`,`allvehicles`,`idcars`,`mintotord`,`maxtotord`,`excludetaxes`) VALUES(".$dbo->quote($pcode).",'".$ptype."','".$ppercentot."',".$dbo->quote($pvalue).",'".$strdatevalid."','".$pallvehicles."','".$stridcars."', ".$dbo->quote($pmintotord).", ".$dbo->quote($pmaxtotord).", " . $pexcludetaxes . ");"; |
| 4532 |
$dbo->setQuery($q); |
| 4533 |
$dbo->execute(); |
| 4534 |
} |
| 4535 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=coupons"); |
| 4536 |
} |
| 4537 |
|
| 4538 |
public function updatecoupon() { |
| 4539 |
if (!JSession::checkToken()) { |
| 4540 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 4541 |
} |
| 4542 |
$mainframe = JFactory::getApplication(); |
| 4543 |
$pcode = VikRequest::getString('code', '', 'request'); |
| 4544 |
$pvalue = VikRequest::getFloat('value', '', 'request'); |
| 4545 |
$pfrom = VikRequest::getString('from', '', 'request'); |
| 4546 |
$pto = VikRequest::getString('to', '', 'request'); |
| 4547 |
$pidcars = VikRequest::getVar('idcars', array(0)); |
| 4548 |
$pwhere = VikRequest::getString('where', '', 'request'); |
| 4549 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 4550 |
$ptype = $ptype == "1" ? 1 : 2; |
| 4551 |
$ppercentot = VikRequest::getString('percentot', '', 'request'); |
| 4552 |
$ppercentot = $ppercentot == "1" ? 1 : 2; |
| 4553 |
$pallvehicles = VikRequest::getString('allvehicles', '', 'request'); |
| 4554 |
$pallvehicles = $pallvehicles == "1" ? 1 : 0; |
| 4555 |
$pmintotord = VikRequest::getFloat('mintotord', 0, 'request'); |
| 4556 |
$pmaxtotord = VikRequest::getFloat('maxtotord', 0, 'request'); |
| 4557 |
$pexcludetaxes = VikRequest::getInt('excludetaxes', 0, 'request'); |
| 4558 |
$stridcars = ""; |
| 4559 |
if ($pidcars && $pallvehicles != 1) { |
| 4560 |
foreach ($pidcars as $ch) { |
| 4561 |
if (!empty($ch)) { |
| 4562 |
$stridcars .= ";".$ch.";"; |
| 4563 |
} |
| 4564 |
} |
| 4565 |
} |
| 4566 |
$strdatevalid = ""; |
| 4567 |
if (strlen($pfrom) > 0 && strlen($pto) > 0) { |
| 4568 |
$first = VikRentCar::getDateTimestamp($pfrom, 0, 0); |
| 4569 |
$second = VikRentCar::getDateTimestamp($pto, 0, 0); |
| 4570 |
if ($first < $second) { |
| 4571 |
$strdatevalid .= $first."-".$second; |
| 4572 |
} |
| 4573 |
} |
| 4574 |
$dbo = JFactory::getDbo(); |
| 4575 |
$q = "SELECT * FROM `#__vikrentcar_coupons` WHERE `code`=".$dbo->quote($pcode)." AND `id`!='".$pwhere."';"; |
| 4576 |
$dbo->setQuery($q); |
| 4577 |
$dbo->execute(); |
| 4578 |
if ($dbo->getNumRows() > 0) { |
| 4579 |
VikError::raiseWarning('', JText::translate('VRCCOUPONEXISTS')); |
| 4580 |
} else { |
| 4581 |
$mainframe->enqueueMessage(JText::translate('VRCCOUPONSAVEOK')); |
| 4582 |
$q = "UPDATE `#__vikrentcar_coupons` SET `code`=".$dbo->quote($pcode).",`type`='".$ptype."',`percentot`='".$ppercentot."',`value`=".$dbo->quote($pvalue).",`datevalid`='".$strdatevalid."',`allvehicles`='".$pallvehicles."',`idcars`='".$stridcars."',`mintotord`=".$dbo->quote($pmintotord).",`maxtotord`=".$dbo->quote($pmaxtotord).",`excludetaxes`=" . $pexcludetaxes . " WHERE `id`='".$pwhere."';"; |
| 4583 |
$dbo->setQuery($q); |
| 4584 |
$dbo->execute(); |
| 4585 |
} |
| 4586 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=coupons"); |
| 4587 |
} |
| 4588 |
|
| 4589 |
public function removecoupons() { |
| 4590 |
if (!JSession::checkToken()) { |
| 4591 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 4592 |
} |
| 4593 |
$ids = VikRequest::getVar('cid', array(0)); |
| 4594 |
if (@count($ids)) { |
| 4595 |
$dbo = JFactory::getDbo(); |
| 4596 |
foreach ($ids as $d) { |
| 4597 |
$q = "DELETE FROM `#__vikrentcar_coupons` WHERE `id`=".$dbo->quote($d).";"; |
| 4598 |
$dbo->setQuery($q); |
| 4599 |
$dbo->execute(); |
| 4600 |
} |
| 4601 |
} |
| 4602 |
$mainframe = JFactory::getApplication(); |
| 4603 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=coupons"); |
| 4604 |
} |
| 4605 |
|
| 4606 |
public function cancelcoupon() { |
| 4607 |
$mainframe = JFactory::getApplication(); |
| 4608 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=coupons"); |
| 4609 |
} |
| 4610 |
|
| 4611 |
public function resendordemail() { |
| 4612 |
$cid = VikRequest::getVar('cid', array(0)); |
| 4613 |
$oid = (int)$cid[0]; |
| 4614 |
$this->do_resendordemail($oid); |
| 4615 |
} |
| 4616 |
|
| 4617 |
public function sendcancordemail() { |
| 4618 |
$cid = VikRequest::getVar('cid', array(0)); |
| 4619 |
$oid = (int)$cid[0]; |
| 4620 |
$this->do_resendordemail($oid, false, true); |
| 4621 |
} |
| 4622 |
|
| 4623 |
private function do_resendordemail($oid, $checkdbsendpdf = false, $cancellation = false) { |
| 4624 |
$dbo = JFactory::getDbo(); |
| 4625 |
$mainframe = JFactory::getApplication(); |
| 4626 |
$q = "SELECT * FROM `#__vikrentcar_orders` WHERE `id`=".$oid.";"; |
| 4627 |
$dbo->setQuery($q); |
| 4628 |
$dbo->execute(); |
| 4629 |
if ($dbo->getNumRows() == 1) { |
| 4630 |
$order = $dbo->loadAssocList(); |
| 4631 |
$vrc_tn = VikRentCar::getTranslator(); |
| 4632 |
//check if the language in use is the same as the one used during the checkout |
| 4633 |
if (!empty($order[0]['lang'])) { |
| 4634 |
$lang = JFactory::getLanguage(); |
| 4635 |
if ($lang->getTag() != $order[0]['lang']) { |
| 4636 |
$lang->load('com_vikrentcar', VIKRENTCAR_ADMIN_LANG, $order[0]['lang'], true); |
| 4637 |
$vrc_tn::$force_tolang = $order[0]['lang']; |
| 4638 |
} |
| 4639 |
} |
| 4640 |
|
| 4641 |
//send mail |
| 4642 |
$ftitle = VikRentCar::getFrontTitle($vrc_tn); |
| 4643 |
$nowts = $order[0]['ts']; |
| 4644 |
$carinfo = VikRentCar::getCarInfo($order[0]['idcar'], $vrc_tn); |
| 4645 |
|
| 4646 |
/** |
| 4647 |
* We try to find the proper Itemid for the View "order" by passing the booking language tag. |
| 4648 |
* |
| 4649 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 4650 |
*/ |
| 4651 |
$best_itemid = null; |
| 4652 |
if (defined('ABSPATH') && !empty($order[0]['lang'])) { |
| 4653 |
// get itemid from the Shortcodes model |
| 4654 |
$model = JModel::getInstance('vikrentcar', 'shortcodes'); |
| 4655 |
$best_itemid = $model->best('order', $order[0]['lang']); |
| 4656 |
} |
| 4657 |
$viklink = VikRentCar::externalroute("index.php?option=com_vikrentcar&view=order&sid=" . $order[0]['sid'] . "&ts=".$order[0]['ts'] . (!empty($order[0]['lang']) ? '&lang=' . $order[0]['lang'] : ''), false, $best_itemid); |
| 4658 |
|
| 4659 |
$is_cust_cost = (!empty($order[0]['cust_cost']) && $order[0]['cust_cost'] > 0); |
| 4660 |
$tar = [ |
| 4661 |
[ |
| 4662 |
'id' => -1, |
| 4663 |
'idcar' => $order[0]['idcar'], |
| 4664 |
'days' => $order[0]['days'], |
| 4665 |
'idprice' => -1, |
| 4666 |
'cost' => 0, |
| 4667 |
'attrdata' => '', |
| 4668 |
] |
| 4669 |
]; |
| 4670 |
if (!empty($order[0]['idtar'])) { |
| 4671 |
//vikrentcar 1.5 |
| 4672 |
if ($order[0]['hourly'] == 1) { |
| 4673 |
$q = "SELECT * FROM `#__vikrentcar_dispcosthours` WHERE `id`='".$order[0]['idtar']."';"; |
| 4674 |
} else { |
| 4675 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `id`='".$order[0]['idtar']."';"; |
| 4676 |
} |
| 4677 |
// |
| 4678 |
$dbo->setQuery($q); |
| 4679 |
$dbo->execute(); |
| 4680 |
if ($dbo->getNumRows() == 0) { |
| 4681 |
if ($order[0]['hourly'] == 1) { |
| 4682 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `id`='".$order[0]['idtar']."';"; |
| 4683 |
$dbo->setQuery($q); |
| 4684 |
$dbo->execute(); |
| 4685 |
if ($dbo->getNumRows() == 1) { |
| 4686 |
$tar = $dbo->loadAssocList(); |
| 4687 |
} |
| 4688 |
} |
| 4689 |
} else { |
| 4690 |
$tar = $dbo->loadAssocList(); |
| 4691 |
} |
| 4692 |
} elseif ($is_cust_cost) { |
| 4693 |
//Custom Rate |
| 4694 |
$tar = [ |
| 4695 |
[ |
| 4696 |
'id' => -1, |
| 4697 |
'idcar' => $order[0]['idcar'], |
| 4698 |
'days' => $order[0]['days'], |
| 4699 |
'idprice' => -1, |
| 4700 |
'cost' => $order[0]['cust_cost'], |
| 4701 |
'attrdata' => '', |
| 4702 |
] |
| 4703 |
]; |
| 4704 |
} |
| 4705 |
//vikrentcar 1.5 |
| 4706 |
if ($order[0]['hourly'] == 1 && !empty($tar[0]['hours'])) { |
| 4707 |
foreach ($tar as $kt => $vt) { |
| 4708 |
$tar[$kt]['days'] = 1; |
| 4709 |
} |
| 4710 |
} |
| 4711 |
// |
| 4712 |
//vikrentcar 1.6 |
| 4713 |
$checkhourscharges = 0; |
| 4714 |
$ppickup = $order[0]['ritiro']; |
| 4715 |
$prelease = $order[0]['consegna']; |
| 4716 |
$secdiff = $prelease - $ppickup; |
| 4717 |
$daysdiff = $secdiff / 86400; |
| 4718 |
if (is_int($daysdiff)) { |
| 4719 |
if ($daysdiff < 1) { |
| 4720 |
$daysdiff = 1; |
| 4721 |
} |
| 4722 |
} else { |
| 4723 |
if ($daysdiff < 1) { |
| 4724 |
$daysdiff = 1; |
| 4725 |
} else { |
| 4726 |
$sum = floor($daysdiff) * 86400; |
| 4727 |
$newdiff = $secdiff - $sum; |
| 4728 |
$maxhmore = VikRentCar::getHoursMoreRb() * 3600; |
| 4729 |
if ($maxhmore >= $newdiff) { |
| 4730 |
$daysdiff = floor($daysdiff); |
| 4731 |
} else { |
| 4732 |
$daysdiff = ceil($daysdiff); |
| 4733 |
/** |
| 4734 |
* Apply proper rounding with gratuity period. |
| 4735 |
* |
| 4736 |
* @since 1.15.1 (J) - 1.3.2 (WP) |
| 4737 |
* @since 1.15.8 (J) - 1.4.5 (WP) |
| 4738 |
*/ |
| 4739 |
$ehours_float = ($newdiff - $maxhmore) / 3600; |
| 4740 |
$ehours = intval(ceil($ehours_float)); |
| 4741 |
$ehours = !$ehours && $ehours_float > 0 && $maxhmore > 0 ? 1 : $ehours; |
| 4742 |
$checkhourscharges = $ehours; |
| 4743 |
if ($checkhourscharges > 0) { |
| 4744 |
$aehourschbasp = VikRentCar::applyExtraHoursChargesBasp(); |
| 4745 |
} |
| 4746 |
} |
| 4747 |
} |
| 4748 |
} |
| 4749 |
if ($checkhourscharges > 0 && $aehourschbasp == true && !$is_cust_cost) { |
| 4750 |
$ret = VikRentCar::applyExtraHoursChargesCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, false, true, true); |
| 4751 |
$tar = $ret['return']; |
| 4752 |
$calcdays = $ret['days']; |
| 4753 |
} |
| 4754 |
if ($checkhourscharges > 0 && $aehourschbasp == false && !$is_cust_cost) { |
| 4755 |
$tar = VikRentCar::extraHoursSetPreviousFareCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, true); |
| 4756 |
$tar = VikRentCar::applySeasonsCar($tar, $order[0]['ritiro'], $order[0]['consegna'], $order[0]['idplace']); |
| 4757 |
$ret = VikRentCar::applyExtraHoursChargesCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, true, true, true); |
| 4758 |
$tar = $ret['return']; |
| 4759 |
$calcdays = $ret['days']; |
| 4760 |
} else { |
| 4761 |
if (!$is_cust_cost) { |
| 4762 |
//Seasonal prices only if not a custom rate |
| 4763 |
$tar = VikRentCar::applySeasonsCar($tar, $order[0]['ritiro'], $order[0]['consegna'], $order[0]['idplace']); |
| 4764 |
} |
| 4765 |
} |
| 4766 |
// |
| 4767 |
$ritplace = (!empty($order[0]['idplace']) ? VikRentCar::getPlaceName($order[0]['idplace'], $vrc_tn) : ""); |
| 4768 |
$consegnaplace = (!empty($order[0]['idreturnplace']) ? VikRentCar::getPlaceName($order[0]['idreturnplace'], $vrc_tn) : ""); |
| 4769 |
$costplusiva = $is_cust_cost ? VikRentCar::sayCustCostPlusIva($tar[0]['cost'], $order[0]['cust_idiva']) : VikRentCar::sayCostPlusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 4770 |
$costminusiva = $is_cust_cost ? VikRentCar::sayCustCostMinusIva($tar[0]['cost'], $order[0]['cust_idiva']) : VikRentCar::sayCostMinusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 4771 |
$pricestr = ($is_cust_cost ? JText::translate('VRCRENTCUSTRATEPLAN').": ".$costplusiva : VikRentCar::getPriceName($tar[0]['idprice'], $vrc_tn)).": ".$costplusiva.(!empty($tar[0]['attrdata']) ? "\n".VikRentCar::getPriceAttr($tar[0]['idprice'], $vrc_tn).": ".$tar[0]['attrdata'] : ""); |
| 4772 |
$isdue = $is_cust_cost ? $tar[0]['cost'] : VikRentCar::sayCostPlusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 4773 |
$optstr = ""; |
| 4774 |
$optarrtaxnet = array(); |
| 4775 |
if (!empty($order[0]['optionals'])) { |
| 4776 |
$stepo = explode(";", $order[0]['optionals']); |
| 4777 |
foreach ($stepo as $oo) { |
| 4778 |
if (!empty($oo)) { |
| 4779 |
$stept = explode(":", $oo); |
| 4780 |
$q = "SELECT `id`,`name`,`cost`,`perday`,`hmany`,`idiva`,`maxprice` FROM `#__vikrentcar_optionals` WHERE `id`=".$dbo->quote($stept[0]).";"; |
| 4781 |
$dbo->setQuery($q); |
| 4782 |
$dbo->execute(); |
| 4783 |
if ($dbo->getNumRows() == 1) { |
| 4784 |
$actopt = $dbo->loadAssocList(); |
| 4785 |
$vrc_tn->translateContents($actopt, '#__vikrentcar_optionals'); |
| 4786 |
$realcost = intval($actopt[0]['perday']) == 1 ? ($actopt[0]['cost'] * $order[0]['days'] * $stept[1]) : ($actopt[0]['cost'] * $stept[1]); |
| 4787 |
$basequancost = intval($actopt[0]['perday']) == 1 ? ($actopt[0]['cost'] * $order[0]['days']) : $actopt[0]['cost']; |
| 4788 |
if (!empty($actopt[0]['maxprice']) && $actopt[0]['maxprice'] > 0 && $basequancost > $actopt[0]['maxprice']) { |
| 4789 |
$realcost = $actopt[0]['maxprice']; |
| 4790 |
if (intval($actopt[0]['hmany']) == 1 && intval($stept[1]) > 1) { |
| 4791 |
$realcost = $actopt[0]['maxprice'] * $stept[1]; |
| 4792 |
} |
| 4793 |
} |
| 4794 |
$tmpopr = VikRentCar::sayOptionalsPlusIva($realcost, $actopt[0]['idiva'], $order[0]); |
| 4795 |
$isdue += $tmpopr; |
| 4796 |
$optnetprice = VikRentCar::sayOptionalsMinusIva($realcost, $actopt[0]['idiva'], $order[0]); |
| 4797 |
$optarrtaxnet[] = $optnetprice; |
| 4798 |
$optstr .= ($stept[1] > 1 ? $stept[1]." " : "").$actopt[0]['name'].": ".$tmpopr."\n"; |
| 4799 |
} |
| 4800 |
} |
| 4801 |
} |
| 4802 |
} |
| 4803 |
//custom extra costs |
| 4804 |
if (!empty($order[0]['extracosts'])) { |
| 4805 |
$cur_extra_costs = json_decode($order[0]['extracosts'], true); |
| 4806 |
foreach ($cur_extra_costs as $eck => $ecv) { |
| 4807 |
$efee_cost = VikRentCar::sayOptionalsPlusIva($ecv['cost'], $ecv['idtax'], $order[0]); |
| 4808 |
$isdue += $efee_cost; |
| 4809 |
$efee_cost_without = VikRentCar::sayOptionalsMinusIva($ecv['cost'], $ecv['idtax'], $order[0]); |
| 4810 |
$optarrtaxnet[] = $efee_cost_without; |
| 4811 |
$optstr .= $ecv['name'].": ".$efee_cost."\n"; |
| 4812 |
} |
| 4813 |
} |
| 4814 |
// |
| 4815 |
$maillocfee = ""; |
| 4816 |
$locfeewithouttax = 0; |
| 4817 |
if (!empty($order[0]['idplace']) && !empty($order[0]['idreturnplace'])) { |
| 4818 |
$locfee = VikRentCar::getLocFee($order[0]['idplace'], $order[0]['idreturnplace']); |
| 4819 |
if ($locfee) { |
| 4820 |
//VikRentCar 1.7 - Location fees overrides |
| 4821 |
if (strlen($locfee['losoverride']) > 0) { |
| 4822 |
$arrvaloverrides = array(); |
| 4823 |
$valovrparts = explode('_', $locfee['losoverride']); |
| 4824 |
foreach ($valovrparts as $valovr) { |
| 4825 |
if (!empty($valovr)) { |
| 4826 |
$ovrinfo = explode(':', $valovr); |
| 4827 |
$arrvaloverrides[$ovrinfo[0]] = $ovrinfo[1]; |
| 4828 |
} |
| 4829 |
} |
| 4830 |
if (array_key_exists($order[0]['days'], $arrvaloverrides)) { |
| 4831 |
$locfee['cost'] = $arrvaloverrides[$order[0]['days']]; |
| 4832 |
} |
| 4833 |
} |
| 4834 |
//end VikRentCar 1.7 - Location fees overrides |
| 4835 |
$locfeecost = intval($locfee['daily']) == 1 ? ($locfee['cost'] * $order[0]['days']) : $locfee['cost']; |
| 4836 |
$locfeewith = VikRentCar::sayLocFeePlusIva($locfeecost, $locfee['idiva'], $order[0]); |
| 4837 |
$isdue += $locfeewith; |
| 4838 |
$locfeewithouttax = VikRentCar::sayLocFeeMinusIva($locfeecost, $locfee['idiva'], $order[0]); |
| 4839 |
$maillocfee = $locfeewith; |
| 4840 |
} |
| 4841 |
} |
| 4842 |
//VRC 1.9 - Out of Hours Fees |
| 4843 |
$oohfee = VikRentCar::getOutOfHoursFees($order[0]['idplace'], $order[0]['idreturnplace'], $order[0]['ritiro'], $order[0]['consegna'], array('id' => $order[0]['idcar'])); |
| 4844 |
$mailoohfee = ""; |
| 4845 |
$oohfeewithouttax = 0; |
| 4846 |
if (count($oohfee) > 0) { |
| 4847 |
$oohfeewith = VikRentCar::sayOohFeePlusIva($oohfee['cost'], $oohfee['idiva']); |
| 4848 |
$isdue += $oohfeewith; |
| 4849 |
$oohfeewithouttax = VikRentCar::sayOohFeeMinusIva($oohfee['cost'], $oohfee['idiva']); |
| 4850 |
$mailoohfee = $oohfeewith; |
| 4851 |
} |
| 4852 |
// |
| 4853 |
//vikrentcar 1.6 coupon |
| 4854 |
$usedcoupon = false; |
| 4855 |
$origisdue = $isdue; |
| 4856 |
if (strlen($order[0]['coupon']) > 0) { |
| 4857 |
$usedcoupon = true; |
| 4858 |
$expcoupon = explode(";", $order[0]['coupon']); |
| 4859 |
$isdue = $isdue - $expcoupon[1]; |
| 4860 |
} |
| 4861 |
// |
| 4862 |
if (!empty($order[0]['custmail'])) { |
| 4863 |
$arrayinfopdf = [ |
| 4864 |
'days' => $order[0]['days'], |
| 4865 |
'tarminusiva' => $costminusiva, |
| 4866 |
'tartax' => ($costplusiva - $costminusiva), |
| 4867 |
'opttaxnet' => $optarrtaxnet, |
| 4868 |
'locfeenet' => $locfeewithouttax, |
| 4869 |
'oohfeenet' => $oohfeewithouttax, |
| 4870 |
'order_id' => $order[0]['id'], |
| 4871 |
'tot_paid' => $order[0]['totpaid'], |
| 4872 |
]; |
| 4873 |
|
| 4874 |
$sendpdf = true; |
| 4875 |
if (!$checkdbsendpdf) { |
| 4876 |
$psendpdf = VikRequest::getString('sendpdf', '', 'request'); |
| 4877 |
if ($psendpdf != "1") { |
| 4878 |
$sendpdf = false; |
| 4879 |
} |
| 4880 |
} |
| 4881 |
$sendpdf = $cancellation ? false : $sendpdf; |
| 4882 |
|
| 4883 |
VikRentCar::sendOrderEmail($order[0]['id'], ['customer'], true, $sendpdf); |
| 4884 |
|
| 4885 |
if ($cancellation) { |
| 4886 |
/** |
| 4887 |
* If "send cancellation email", we log the event in the history. |
| 4888 |
* |
| 4889 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 4890 |
*/ |
| 4891 |
VikRentCar::getOrderHistoryInstance()->setBid($order[0]['id'])->store('EC'); |
| 4892 |
$mainframe->enqueueMessage(JText::sprintf('VRC_CANC_EMAIL_SENT_TO', $order[0]['custmail'])); |
| 4893 |
} else { |
| 4894 |
$mainframe->enqueueMessage(JText::sprintf('VRORDERMAILRESENT', $order[0]['custmail'])); |
| 4895 |
} |
| 4896 |
} else { |
| 4897 |
VikError::raiseWarning('', JText::translate('VRORDERMAILRESENTNOREC')); |
| 4898 |
} |
| 4899 |
} |
| 4900 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=".$oid); |
| 4901 |
} |
| 4902 |
|
| 4903 |
public function sortcarat() { |
| 4904 |
$mainframe = JFactory::getApplication(); |
| 4905 |
$sortid = VikRequest::getVar('cid', array(0)); |
| 4906 |
$pmode = VikRequest::getString('mode', '', 'request'); |
| 4907 |
$dbo = JFactory::getDbo(); |
| 4908 |
if (!empty($pmode)) { |
| 4909 |
$q = "SELECT `id`,`ordering` FROM `#__vikrentcar_caratteristiche` ORDER BY `#__vikrentcar_caratteristiche`.`ordering` ASC;"; |
| 4910 |
$dbo->setQuery($q); |
| 4911 |
$dbo->execute(); |
| 4912 |
$totr = $dbo->getNumRows(); |
| 4913 |
if ($totr > 1) { |
| 4914 |
$data = $dbo->loadAssocList(); |
| 4915 |
if ($pmode == "up") { |
| 4916 |
foreach ($data as $v) { |
| 4917 |
if ($v['id'] == $sortid[0]) { |
| 4918 |
$y = $v['ordering']; |
| 4919 |
} |
| 4920 |
} |
| 4921 |
if ($y && $y > 1) { |
| 4922 |
$vik = $y - 1; |
| 4923 |
$found = false; |
| 4924 |
foreach ($data as $v) { |
| 4925 |
if (intval($v['ordering'])==intval($vik)) { |
| 4926 |
$found = true; |
| 4927 |
$q = "UPDATE `#__vikrentcar_caratteristiche` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 4928 |
$dbo->setQuery($q); |
| 4929 |
$dbo->execute(); |
| 4930 |
$q = "UPDATE `#__vikrentcar_caratteristiche` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 4931 |
$dbo->setQuery($q); |
| 4932 |
$dbo->execute(); |
| 4933 |
break; |
| 4934 |
} |
| 4935 |
} |
| 4936 |
if (!$found) { |
| 4937 |
$q = "UPDATE `#__vikrentcar_caratteristiche` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 4938 |
$dbo->setQuery($q); |
| 4939 |
$dbo->execute(); |
| 4940 |
} |
| 4941 |
} |
| 4942 |
} elseif ($pmode == "down") { |
| 4943 |
foreach ($data as $v) { |
| 4944 |
if ($v['id'] == $sortid[0]) { |
| 4945 |
$y = $v['ordering']; |
| 4946 |
} |
| 4947 |
} |
| 4948 |
if ($y) { |
| 4949 |
$vik = $y + 1; |
| 4950 |
$found = false; |
| 4951 |
foreach ($data as $v) { |
| 4952 |
if (intval($v['ordering']) == intval($vik)) { |
| 4953 |
$found = true; |
| 4954 |
$q = "UPDATE `#__vikrentcar_caratteristiche` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 4955 |
$dbo->setQuery($q); |
| 4956 |
$dbo->execute(); |
| 4957 |
$q = "UPDATE `#__vikrentcar_caratteristiche` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 4958 |
$dbo->setQuery($q); |
| 4959 |
$dbo->execute(); |
| 4960 |
break; |
| 4961 |
} |
| 4962 |
} |
| 4963 |
if (!$found) { |
| 4964 |
$q = "UPDATE `#__vikrentcar_caratteristiche` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 4965 |
$dbo->setQuery($q); |
| 4966 |
$dbo->execute(); |
| 4967 |
} |
| 4968 |
} |
| 4969 |
} |
| 4970 |
} |
| 4971 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=carat"); |
| 4972 |
} else { |
| 4973 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 4974 |
} |
| 4975 |
} |
| 4976 |
|
| 4977 |
public function sortoptional() { |
| 4978 |
$mainframe = JFactory::getApplication(); |
| 4979 |
$sortid = VikRequest::getVar('cid', array(0)); |
| 4980 |
$pmode = VikRequest::getString('mode', '', 'request'); |
| 4981 |
$dbo = JFactory::getDbo(); |
| 4982 |
if (!empty($pmode)) { |
| 4983 |
$q = "SELECT `id`,`ordering` FROM `#__vikrentcar_optionals` ORDER BY `#__vikrentcar_optionals`.`ordering` ASC;"; |
| 4984 |
$dbo->setQuery($q); |
| 4985 |
$dbo->execute(); |
| 4986 |
$totr=$dbo->getNumRows(); |
| 4987 |
if ($totr > 1) { |
| 4988 |
$data = $dbo->loadAssocList(); |
| 4989 |
if ($pmode == "up") { |
| 4990 |
foreach ($data as $v) { |
| 4991 |
if ($v['id'] == $sortid[0]) { |
| 4992 |
$y = $v['ordering']; |
| 4993 |
} |
| 4994 |
} |
| 4995 |
if ($y && $y > 1) { |
| 4996 |
$vik = $y - 1; |
| 4997 |
$found = false; |
| 4998 |
foreach ($data as $v) { |
| 4999 |
if (intval($v['ordering']) == intval($vik)) { |
| 5000 |
$found = true; |
| 5001 |
$q = "UPDATE `#__vikrentcar_optionals` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 5002 |
$dbo->setQuery($q); |
| 5003 |
$dbo->execute(); |
| 5004 |
$q = "UPDATE `#__vikrentcar_optionals` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 5005 |
$dbo->setQuery($q); |
| 5006 |
$dbo->execute(); |
| 5007 |
break; |
| 5008 |
} |
| 5009 |
} |
| 5010 |
if (!$found) { |
| 5011 |
$q = "UPDATE `#__vikrentcar_optionals` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 5012 |
$dbo->setQuery($q); |
| 5013 |
$dbo->execute(); |
| 5014 |
} |
| 5015 |
} |
| 5016 |
} elseif ($pmode == "down") { |
| 5017 |
foreach ($data as $v) { |
| 5018 |
if ($v['id'] == $sortid[0]) { |
| 5019 |
$y = $v['ordering']; |
| 5020 |
} |
| 5021 |
} |
| 5022 |
if ($y) { |
| 5023 |
$vik = $y + 1; |
| 5024 |
$found = false; |
| 5025 |
foreach ($data as $v) { |
| 5026 |
if (intval($v['ordering']) == intval($vik)) { |
| 5027 |
$found = true; |
| 5028 |
$q = "UPDATE `#__vikrentcar_optionals` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 5029 |
$dbo->setQuery($q); |
| 5030 |
$dbo->execute(); |
| 5031 |
$q = "UPDATE `#__vikrentcar_optionals` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 5032 |
$dbo->setQuery($q); |
| 5033 |
$dbo->execute(); |
| 5034 |
break; |
| 5035 |
} |
| 5036 |
} |
| 5037 |
if (!$found) { |
| 5038 |
$q = "UPDATE `#__vikrentcar_optionals` SET `ordering`='".$vik."' WHERE `id`='".$sortid[0]."' LIMIT 1;"; |
| 5039 |
$dbo->setQuery($q); |
| 5040 |
$dbo->execute(); |
| 5041 |
} |
| 5042 |
} |
| 5043 |
} |
| 5044 |
} |
| 5045 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=optionals"); |
| 5046 |
} else { |
| 5047 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 5048 |
} |
| 5049 |
} |
| 5050 |
|
| 5051 |
public function export() { |
| 5052 |
VikRentCarHelper::printHeader("8"); |
| 5053 |
|
| 5054 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'export')); |
| 5055 |
|
| 5056 |
parent::display(); |
| 5057 |
|
| 5058 |
if (VikRentCar::showFooter()) { |
| 5059 |
VikRentCarHelper::printFooter(); |
| 5060 |
} |
| 5061 |
} |
| 5062 |
|
| 5063 |
public function doexport() { |
| 5064 |
$dbo = JFactory::getDbo(); |
| 5065 |
$mainframe = JFactory::getApplication(); |
| 5066 |
$oids = VikRequest::getVar('cid', array(0)); |
| 5067 |
$oids = count($oids) > 0 && intval($oids[key($oids)]) > 0 ? $oids : array(); |
| 5068 |
$pfrom = VikRequest::getString('from', '', 'request'); |
| 5069 |
$pto = VikRequest::getString('to', '', 'request'); |
| 5070 |
$pdatetype = VikRequest::getString('datetype', '', 'request'); |
| 5071 |
$pdatetype = $pdatetype == 'ts' ? 'ts' : 'ritiro'; |
| 5072 |
$plocation = VikRequest::getString('location', '', 'request'); |
| 5073 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 5074 |
$ptype = $ptype == "csv" ? "csv" : ($ptype == "xml" ? "xml" : "ics"); |
| 5075 |
$pstatus = VikRequest::getString('status', '', 'request'); |
| 5076 |
$pdateformat = VikRequest::getString('dateformat', '', 'request'); |
| 5077 |
$pxml_file = VikRequest::getString('xml_file', '', 'request'); |
| 5078 |
$nowdf = VikRentCar::getDateFormat(true); |
| 5079 |
$nowtf = VikRentCar::getTimeFormat(true); |
| 5080 |
$pdateformat .= ' '.$nowtf; |
| 5081 |
$tf = $nowtf; |
| 5082 |
if ($nowdf == "%d/%m/%Y") { |
| 5083 |
$df = 'd/m/Y'; |
| 5084 |
} elseif ($nowdf == "%m/%d/%Y") { |
| 5085 |
$df = 'm/d/Y'; |
| 5086 |
} else { |
| 5087 |
$df = 'Y/m/d'; |
| 5088 |
} |
| 5089 |
$clauses = array(); |
| 5090 |
if (count($oids) > 0) { |
| 5091 |
$clauses[] = "`o`.`id` IN(".implode(',', $oids).")"; |
| 5092 |
} |
| 5093 |
if ($pstatus == "C") { |
| 5094 |
$clauses[] = "`o`.`status`='confirmed'"; |
| 5095 |
} |
| 5096 |
if (!empty($pfrom) && VikRentCar::dateIsValid($pfrom)) { |
| 5097 |
$fromts = VikRentCar::getDateTimestamp($pfrom, '0', '0'); |
| 5098 |
$clauses[] = "`o`.`".$pdatetype."`>=".$fromts; |
| 5099 |
} |
| 5100 |
if (!empty($pto) && VikRentCar::dateIsValid($pto)) { |
| 5101 |
$tots = VikRentCar::getDateTimestamp($pto, '23', '59'); |
| 5102 |
$clauses[] = "`o`.`".$pdatetype."`<=".$tots; |
| 5103 |
} |
| 5104 |
if (!empty($plocation)) { |
| 5105 |
$clauses[] = "(`o`.`idplace`=".intval($plocation)." OR `o`.`idreturnplace`=".intval($plocation).")"; |
| 5106 |
} |
| 5107 |
$download_string = ''; |
| 5108 |
$q = "SELECT `o`.*,`lp`.`name` AS `pickup_location_name`,`ld`.`name` AS `dropoff_location_name` FROM `#__vikrentcar_orders` AS `o` ". |
| 5109 |
"LEFT JOIN `#__vikrentcar_places` `lp` ON `o`.`idplace`=`lp`.`id` ". |
| 5110 |
"LEFT JOIN `#__vikrentcar_places` `ld` ON `o`.`idreturnplace`=`ld`.`id`".(count($clauses) > 0 ? " WHERE ".implode(' AND ', $clauses) : "")." ORDER BY `o`.`ritiro` ASC;"; |
| 5111 |
$dbo->setQuery($q); |
| 5112 |
$dbo->execute(); |
| 5113 |
if ($dbo->getNumRows() > 0) { |
| 5114 |
$rows = $dbo->loadAssocList(); |
| 5115 |
if ($ptype == "csv") { |
| 5116 |
//init csv creation |
| 5117 |
$csvlines = array(); |
| 5118 |
$csvlines[] = array('ID', JText::translate('VRCEXPCSVPICK'), JText::translate('VRCEXPCSVDROP'), JText::translate('VRCEXPCSVCAR'), JText::translate('VRCEXPCSVPICKLOC'), JText::translate('VRCEXPCSVDROPLOC'), JText::translate('VRCEXPCSVCUSTINFO'), JText::translate('VRCEXPCSVPAYMETH'), JText::translate('VRCEXPCSVORDSTATUS'), JText::translate('VRCEXPCSVTOT'), JText::translate('VRCEXPCSVTOTPAID')); |
| 5119 |
foreach ($rows as $r) { |
| 5120 |
$pickdate = $pdatetype == 'ts' ? $r['ritiro'] : date($pdateformat, $r['ritiro']); |
| 5121 |
$dropdate = $pdatetype == 'ts' ? $r['consegna'] : date($pdateformat, $r['consegna']); |
| 5122 |
$car = VikRentCar::getCarInfo($r['idcar']); |
| 5123 |
$pickloc = VikRentCar::getPlaceName($r['idplace']); |
| 5124 |
$droploc = VikRentCar::getPlaceName($r['idreturnplace']); |
| 5125 |
$custdata = preg_replace('/\s+/', ' ', trim($r['custdata'])); |
| 5126 |
$payment = VikRentCar::getPayment($r['idpayment']); |
| 5127 |
$saystatus = ($r['status']=="confirmed" ? JText::translate('VRCONFIRMED') : ($r['status'] == 'standby' ? JText::translate('VRSTANDBY') : JText::translate('VRCANCELLED'))); |
| 5128 |
$csvlines[] = array($r['id'], $pickdate, $dropdate, $car['name'], $pickloc, $droploc, $custdata, $payment['name'], $saystatus, number_format($r['order_total'], 2), number_format($r['totpaid'], 2)); |
| 5129 |
} |
| 5130 |
//end csv creation |
| 5131 |
} elseif ($ptype == "ics") { |
| 5132 |
//init ics creation |
| 5133 |
$icslines = array(); |
| 5134 |
$icscontent = "BEGIN:VCALENDAR\n"; |
| 5135 |
$icscontent .= "VERSION:2.0\n"; |
| 5136 |
$icscontent .= "PRODID:-//e4j//VikRentCar//EN\n"; |
| 5137 |
$icscontent .= "CALSCALE:GREGORIAN\n"; |
| 5138 |
$str = ""; |
| 5139 |
foreach ($rows as $r) { |
| 5140 |
$uri = VikRentCar::externalroute('index.php?option=com_vikrentcar&view=order&sid=' . $r['sid'] . '&ts=' . $r['ts'] . (!empty($r['lang']) ? '&lang=' . $r['lang'] : ''), false); |
| 5141 |
$pickloc = VikRentCar::getPlaceName($r['idplace']); |
| 5142 |
$car = VikRentCar::getCarInfo($r['idcar']); |
| 5143 |
//$custdata = preg_replace('/\s+/', ' ', trim($r['custdata'])); |
| 5144 |
//$description = $car['name']."\\n".$r['custdata']; |
| 5145 |
$description = $car['name']."\\n".str_replace("\n", "\\n", trim($r['custdata'])); |
| 5146 |
$str .= "BEGIN:VEVENT\n"; |
| 5147 |
//End of the Event set as Pickup Date, decomment line below to have it on Drop Off Date |
| 5148 |
//$str .= "DTEND:".date('Ymd\THis\Z', $r['consegna'])."\n"; |
| 5149 |
$str .= "DTEND:".date('Ymd\THis\Z', $r['ritiro'])."\n"; |
| 5150 |
// |
| 5151 |
$str .= "UID:".uniqid()."\n"; |
| 5152 |
$str .= "DTSTAMP:".date('Ymd\THis\Z', time())."\n"; |
| 5153 |
$str .= "LOCATION:".preg_replace('/([\,;])/','\\\$1', $pickloc)."\n"; |
| 5154 |
$str .= ((strlen($description) > 0 ) ? "DESCRIPTION:".preg_replace('/([\,;])/','\\\$1', $description)."\n" : ""); |
| 5155 |
$str .= "URL;VALUE=URI:".preg_replace('/([\,;])/','\\\$1', $uri)."\n"; |
| 5156 |
$str .= "SUMMARY:".JText::sprintf('VRCICSEXPSUMMARY', date($tf, $r['ritiro']))."\n"; |
| 5157 |
$str .= "DTSTART:".date('Ymd\THis\Z', $r['ritiro'])."\n"; |
| 5158 |
$str .= "END:VEVENT\n"; |
| 5159 |
} |
| 5160 |
$icscontent .= $str; |
| 5161 |
$icscontent .= "END:VCALENDAR\n"; |
| 5162 |
$download_string = $icscontent; |
| 5163 |
//end ics creation |
| 5164 |
} elseif ($ptype == "xml") { |
| 5165 |
//init xml creation |
| 5166 |
if (!empty($pxml_file) && file_exists(VRC_ADMIN_PATH.DS.'xml_export'.DS.$pxml_file)) { |
| 5167 |
require_once(VRC_ADMIN_PATH.DS.'xml_export'.DS.$pxml_file); |
| 5168 |
foreach ($rows as $key => $row) { |
| 5169 |
$rows[$key]['car_details'] = VikRentCar::getCarInfo($row['idcar']); |
| 5170 |
$rows[$key]['price_info'] = ''; |
| 5171 |
$q = "SELECT `c`.`idprice`,`c`.`cost`,`c`.`attrdata`,`p`.`name`,`p`.`idiva`,`t`.`aliq` FROM `#__vikrentcar_dispcost` AS `c` LEFT JOIN `#__vikrentcar_prices` `p` ON `c`.`idprice`=`p`.`id` LEFT JOIN `#__vikrentcar_iva` `t` ON `p`.`idiva`=`t`.`id` WHERE `c`.`id`=".(intval($row['idtar'])).";"; |
| 5172 |
$dbo->setQuery($q); |
| 5173 |
$dbo->execute(); |
| 5174 |
if ($dbo->getNumRows() > 0) { |
| 5175 |
$price_info = $dbo->loadAssoc(); |
| 5176 |
$rows[$key]['price_info'] = $price_info; |
| 5177 |
} |
| 5178 |
$rows[$key]['car_details']['category_name'] = ''; |
| 5179 |
if (!empty($rows[$key]['car_details']['idcat'])) { |
| 5180 |
$all_cats = explode(';', $rows[$key]['car_details']['idcat']); |
| 5181 |
$rows[$key]['car_details']['category_name'] = VikRentCar::getCategoryName($all_cats[0]); |
| 5182 |
} |
| 5183 |
} |
| 5184 |
$obj = new vikRentCarXmlExport($rows); |
| 5185 |
$download_string = $obj->generateXml(); |
| 5186 |
} else { |
| 5187 |
VikError::raiseWarning('', JText::translate('VRCEXPORTERRFILE')); |
| 5188 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=orders"); |
| 5189 |
} |
| 5190 |
//end xml creation |
| 5191 |
} |
| 5192 |
//download file from buffer |
| 5193 |
$dfilename = 'export_'.date('Y-m-d_H_i').'.'.$ptype; |
| 5194 |
if ($ptype == "csv") { |
| 5195 |
header("Content-type: text/csv"); |
| 5196 |
header("Cache-Control: no-store, no-cache"); |
| 5197 |
header('Content-Disposition: attachment; filename="'.$dfilename.'"'); |
| 5198 |
$outstream = fopen("php://output", 'w'); |
| 5199 |
foreach ($csvlines as $csvline) { |
| 5200 |
fputcsv($outstream, $csvline); |
| 5201 |
} |
| 5202 |
fclose($outstream); |
| 5203 |
exit; |
| 5204 |
} else { |
| 5205 |
if ($ptype == "xml") { |
| 5206 |
header("Content-Type: text/xml; "); |
| 5207 |
} else { |
| 5208 |
header("Content-Type: application/octet-stream; "); |
| 5209 |
} |
| 5210 |
header("Cache-Control: no-store, no-cache"); |
| 5211 |
header("Content-Disposition: attachment; filename=\"".$dfilename."\""); |
| 5212 |
$f = fopen('php://output', "w"); |
| 5213 |
fwrite($f, $download_string); |
| 5214 |
fclose($f); |
| 5215 |
exit; |
| 5216 |
} |
| 5217 |
} else { |
| 5218 |
VikError::raiseWarning('', JText::translate('VRCEXPORTERRNOREC')); |
| 5219 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=orders"); |
| 5220 |
} |
| 5221 |
} |
| 5222 |
|
| 5223 |
public function oohfees() { |
| 5224 |
VikRentCarHelper::printHeader("20"); |
| 5225 |
|
| 5226 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'oohfees')); |
| 5227 |
|
| 5228 |
parent::display(); |
| 5229 |
|
| 5230 |
if (VikRentCar::showFooter()) { |
| 5231 |
VikRentCarHelper::printFooter(); |
| 5232 |
} |
| 5233 |
} |
| 5234 |
|
| 5235 |
public function newoohfee() { |
| 5236 |
VikRentCarHelper::printHeader("20"); |
| 5237 |
|
| 5238 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageoohfee')); |
| 5239 |
|
| 5240 |
parent::display(); |
| 5241 |
|
| 5242 |
if (VikRentCar::showFooter()) { |
| 5243 |
VikRentCarHelper::printFooter(); |
| 5244 |
} |
| 5245 |
} |
| 5246 |
|
| 5247 |
public function editoohfee() { |
| 5248 |
VikRentCarHelper::printHeader("20"); |
| 5249 |
|
| 5250 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'manageoohfee')); |
| 5251 |
|
| 5252 |
parent::display(); |
| 5253 |
|
| 5254 |
if (VikRentCar::showFooter()) { |
| 5255 |
VikRentCarHelper::printFooter(); |
| 5256 |
} |
| 5257 |
} |
| 5258 |
|
| 5259 |
public function createoohfee() { |
| 5260 |
if (!JSession::checkToken()) { |
| 5261 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 5262 |
} |
| 5263 |
$dbo = JFactory::getDbo(); |
| 5264 |
$mainframe = JFactory::getApplication(); |
| 5265 |
$pname = VikRequest::getString('name', '', 'request'); |
| 5266 |
$pfrom = VikRequest::getInt('from', '', 'request'); |
| 5267 |
$pto = VikRequest::getInt('to', '', 'request'); |
| 5268 |
$ppickcharge = (float)VikRequest::getString('pickcharge', '', 'request'); |
| 5269 |
$pdropcharge = (float)VikRequest::getString('dropcharge', '', 'request'); |
| 5270 |
$pmaxcharge = (float)VikRequest::getString('maxcharge', '', 'request'); |
| 5271 |
$pidcars = VikRequest::getVar('idcars', array(0)); |
| 5272 |
$pidplace = VikRequest::getVar('idplace', array(0)); |
| 5273 |
$ptype = VikRequest::getInt('type', '', 'request'); |
| 5274 |
$ptype = $ptype > 1 && $ptype <= 3 ? $ptype : 1; |
| 5275 |
$paliq = VikRequest::getInt('aliq', '', 'request'); |
| 5276 |
$pwdays = VikRequest::getVar('wdays', array(0)); |
| 5277 |
if (!(empty($pfrom) && empty($pto)) && $pfrom != $pto && $pfrom < 86400 && $pto < 86400) { |
| 5278 |
$wdays_str = ''; |
| 5279 |
foreach ($pwdays as $wday) { |
| 5280 |
if (!strlen($wday) > 0) { |
| 5281 |
continue; |
| 5282 |
} |
| 5283 |
$wdays_str .= '-'.(int)$wday.'-,'; |
| 5284 |
} |
| 5285 |
$wdays_str = rtrim($wdays_str, ','); |
| 5286 |
$cars_str = ''; |
| 5287 |
foreach ($pidcars as $idcar) { |
| 5288 |
if (empty($idcar)) { |
| 5289 |
continue; |
| 5290 |
} |
| 5291 |
$cars_str .= "-".$idcar."-,"; |
| 5292 |
} |
| 5293 |
$q = "INSERT INTO `#__vikrentcar_oohfees` (`oohname`,`pickcharge`,`dropcharge`,`maxcharge`,`idcars`,`from`,`to`,`type`,`idiva`,`wdays`) VALUES(".$dbo->quote($pname).", ".$dbo->quote($ppickcharge).", ".$dbo->quote($pdropcharge).", ".$dbo->quote($pmaxcharge).", ".$dbo->quote($cars_str).", ".$pfrom.", ".$pto.", ".$ptype.", ".(!empty($paliq) ? $paliq : 'NULL').", ".$dbo->quote($wdays_str).");"; |
| 5294 |
$dbo->setQuery($q); |
| 5295 |
$dbo->execute(); |
| 5296 |
$lid = $dbo->insertid(); |
| 5297 |
if (!empty($lid)) { |
| 5298 |
foreach ($pidplace as $idplace) { |
| 5299 |
if (empty($idplace)) { |
| 5300 |
continue; |
| 5301 |
} |
| 5302 |
$q = "INSERT INTO `#__vikrentcar_oohfees_locxref` (`idooh`,`idlocation`) VALUES(".$lid.", ".(int)$idplace.");"; |
| 5303 |
$dbo->setQuery($q); |
| 5304 |
$dbo->execute(); |
| 5305 |
} |
| 5306 |
$mainframe->enqueueMessage(JText::translate('VRCOOHFEESAVED')); |
| 5307 |
} |
| 5308 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=oohfees"); |
| 5309 |
} else { |
| 5310 |
VikError::raiseWarning('', JText::translate('VRCOOHERRTIME')); |
| 5311 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newoohfee"); |
| 5312 |
} |
| 5313 |
} |
| 5314 |
|
| 5315 |
public function updateoohfee() { |
| 5316 |
if (!JSession::checkToken()) { |
| 5317 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 5318 |
} |
| 5319 |
$dbo = JFactory::getDbo(); |
| 5320 |
$mainframe = JFactory::getApplication(); |
| 5321 |
$pname = VikRequest::getString('name', '', 'request'); |
| 5322 |
$pfrom = VikRequest::getInt('from', '', 'request'); |
| 5323 |
$pto = VikRequest::getInt('to', '', 'request'); |
| 5324 |
$ppickcharge = (float)VikRequest::getString('pickcharge', '', 'request'); |
| 5325 |
$pdropcharge = (float)VikRequest::getString('dropcharge', '', 'request'); |
| 5326 |
$pmaxcharge = (float)VikRequest::getString('maxcharge', '', 'request'); |
| 5327 |
$pidcars = VikRequest::getVar('idcars', array(0)); |
| 5328 |
$pidplace = VikRequest::getVar('idplace', array(0)); |
| 5329 |
$ptype = VikRequest::getInt('type', '', 'request'); |
| 5330 |
$ptype = $ptype > 1 && $ptype <= 3 ? $ptype : 1; |
| 5331 |
$paliq = VikRequest::getInt('aliq', '', 'request'); |
| 5332 |
$pwdays = VikRequest::getVar('wdays', array(0)); |
| 5333 |
$pwhere = VikRequest::getInt('where', '', 'request'); |
| 5334 |
if (!(empty($pfrom) && empty($pto)) && $pfrom != $pto && $pfrom < 86400 && $pto < 86400 && !empty($pwhere)) { |
| 5335 |
$wdays_str = ''; |
| 5336 |
foreach ($pwdays as $wday) { |
| 5337 |
if (!strlen($wday) > 0) { |
| 5338 |
continue; |
| 5339 |
} |
| 5340 |
$wdays_str .= '-'.(int)$wday.'-,'; |
| 5341 |
} |
| 5342 |
$wdays_str = rtrim($wdays_str, ','); |
| 5343 |
$cars_str = ''; |
| 5344 |
foreach ($pidcars as $idcar) { |
| 5345 |
if (empty($idcar)) { |
| 5346 |
continue; |
| 5347 |
} |
| 5348 |
$cars_str .= "-".$idcar."-,"; |
| 5349 |
} |
| 5350 |
$q = "UPDATE `#__vikrentcar_oohfees` SET `oohname`=".$dbo->quote($pname).",`pickcharge`=".$dbo->quote($ppickcharge).",`dropcharge`=".$dbo->quote($pdropcharge).",`maxcharge`=".$dbo->quote($pmaxcharge).",`idcars`=".$dbo->quote($cars_str).",`from`=".$pfrom.",`to`=".$pto.",`type`=".$ptype.",`idiva`=".(!empty($paliq) ? $paliq : 'NULL').",`wdays`=".$dbo->quote($wdays_str)." WHERE `id`=".$pwhere.";"; |
| 5351 |
$dbo->setQuery($q); |
| 5352 |
$dbo->execute(); |
| 5353 |
$q = "DELETE FROM `#__vikrentcar_oohfees_locxref` WHERE `idooh`=".$pwhere.";"; |
| 5354 |
$dbo->setQuery($q); |
| 5355 |
$dbo->execute(); |
| 5356 |
foreach ($pidplace as $idplace) { |
| 5357 |
if (empty($idplace)) { |
| 5358 |
continue; |
| 5359 |
} |
| 5360 |
$q = "INSERT INTO `#__vikrentcar_oohfees_locxref` (`idooh`,`idlocation`) VALUES(".$pwhere.", ".(int)$idplace.");"; |
| 5361 |
$dbo->setQuery($q); |
| 5362 |
$dbo->execute(); |
| 5363 |
} |
| 5364 |
$mainframe->enqueueMessage(JText::translate('VRCOOHFEESAVED')); |
| 5365 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=oohfees"); |
| 5366 |
} else { |
| 5367 |
VikError::raiseWarning('', JText::translate('VRCOOHERRTIME')); |
| 5368 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=oohfees"); |
| 5369 |
} |
| 5370 |
} |
| 5371 |
|
| 5372 |
public function removeoohfees() { |
| 5373 |
if (!JSession::checkToken()) { |
| 5374 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 5375 |
} |
| 5376 |
$ids = VikRequest::getVar('cid', array(0)); |
| 5377 |
if (@count($ids)) { |
| 5378 |
$dbo = JFactory::getDbo(); |
| 5379 |
foreach ($ids as $d) { |
| 5380 |
$q = "DELETE FROM `#__vikrentcar_oohfees` WHERE `id`=".$dbo->quote($d).";"; |
| 5381 |
$dbo->setQuery($q); |
| 5382 |
$dbo->execute(); |
| 5383 |
$q = "DELETE FROM `#__vikrentcar_oohfees_locxref` WHERE `idooh`=".$dbo->quote($d).";"; |
| 5384 |
$dbo->setQuery($q); |
| 5385 |
$dbo->execute(); |
| 5386 |
} |
| 5387 |
} |
| 5388 |
$mainframe = JFactory::getApplication(); |
| 5389 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=oohfees"); |
| 5390 |
} |
| 5391 |
|
| 5392 |
public function canceloohfee() { |
| 5393 |
$mainframe = JFactory::getApplication(); |
| 5394 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=oohfees"); |
| 5395 |
} |
| 5396 |
|
| 5397 |
public function customercheckin() { |
| 5398 |
$dbo = JFactory::getDbo(); |
| 5399 |
$cid = VikRequest::getVar('cid', array(0)); |
| 5400 |
$oid = (int)$cid[0]; |
| 5401 |
$q = "SELECT * FROM `#__vikrentcar_orders` WHERE `id`=".$oid.";"; |
| 5402 |
$dbo->setQuery($q); |
| 5403 |
$dbo->execute(); |
| 5404 |
if ($dbo->getNumRows() == 1) { |
| 5405 |
$order = $dbo->loadAssocList(); |
| 5406 |
$vrc_tn = VikRentCar::getTranslator(); |
| 5407 |
//check if the language in use is the same as the one used during the checkout |
| 5408 |
if (!empty($order[0]['lang'])) { |
| 5409 |
$lang = JFactory::getLanguage(); |
| 5410 |
if ($lang->getTag() != $order[0]['lang']) { |
| 5411 |
$lang->load('com_vikrentcar', VIKRENTCAR_ADMIN_LANG, $order[0]['lang'], true); |
| 5412 |
$vrc_tn::$force_tolang = $order[0]['lang']; |
| 5413 |
} |
| 5414 |
} |
| 5415 |
// |
| 5416 |
//send mail |
| 5417 |
$ftitle = VikRentCar::getFrontTitle(); |
| 5418 |
$nowts = $order[0]['ts']; |
| 5419 |
$carinfo = VikRentCar::getCarInfo($order[0]['idcar'], $vrc_tn); |
| 5420 |
$viklink = VikRentCar::externalroute("index.php?option=com_vikrentcar&view=order&sid=" . $order[0]['sid'] . "&ts=" . $order[0]['ts'] . (!empty($order[0]['lang']) ? '&lang=' . $order[0]['lang'] : ''), false); |
| 5421 |
// |
| 5422 |
$is_cust_cost = (!empty($order[0]['cust_cost']) && $order[0]['cust_cost'] > 0); |
| 5423 |
if (!empty($order[0]['idtar'])) { |
| 5424 |
//vikrentcar 1.5 |
| 5425 |
if ($order[0]['hourly'] == 1) { |
| 5426 |
$q = "SELECT * FROM `#__vikrentcar_dispcosthours` WHERE `id`='".$order[0]['idtar']."';"; |
| 5427 |
} else { |
| 5428 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `id`='".$order[0]['idtar']."';"; |
| 5429 |
} |
| 5430 |
// |
| 5431 |
$dbo->setQuery($q); |
| 5432 |
$dbo->execute(); |
| 5433 |
if ($dbo->getNumRows() == 0) { |
| 5434 |
if ($order[0]['hourly'] == 1) { |
| 5435 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `id`='".$order[0]['idtar']."';"; |
| 5436 |
$dbo->setQuery($q); |
| 5437 |
$dbo->execute(); |
| 5438 |
if ($dbo->getNumRows() == 1) { |
| 5439 |
$tar = $dbo->loadAssocList(); |
| 5440 |
} |
| 5441 |
} |
| 5442 |
} else { |
| 5443 |
$tar = $dbo->loadAssocList(); |
| 5444 |
} |
| 5445 |
} elseif ($is_cust_cost) { |
| 5446 |
//Custom Rate |
| 5447 |
$tar = array(0 => array( |
| 5448 |
'id' => -1, |
| 5449 |
'idcar' => $order[0]['idcar'], |
| 5450 |
'days' => $order[0]['days'], |
| 5451 |
'idprice' => -1, |
| 5452 |
'cost' => $order[0]['cust_cost'], |
| 5453 |
'attrdata' => '', |
| 5454 |
)); |
| 5455 |
} |
| 5456 |
//vikrentcar 1.5 |
| 5457 |
if ($order[0]['hourly'] == 1 && !empty($tar[0]['hours'])) { |
| 5458 |
foreach ($tar as $kt => $vt) { |
| 5459 |
$tar[$kt]['days'] = 1; |
| 5460 |
} |
| 5461 |
} |
| 5462 |
// |
| 5463 |
//vikrentcar 1.6 |
| 5464 |
$checkhourscharges = 0; |
| 5465 |
$ppickup = $order[0]['ritiro']; |
| 5466 |
$prelease = $order[0]['consegna']; |
| 5467 |
$secdiff = $prelease - $ppickup; |
| 5468 |
$daysdiff = $secdiff / 86400; |
| 5469 |
if (is_int($daysdiff)) { |
| 5470 |
if ($daysdiff < 1) { |
| 5471 |
$daysdiff = 1; |
| 5472 |
} |
| 5473 |
} else { |
| 5474 |
if ($daysdiff < 1) { |
| 5475 |
$daysdiff = 1; |
| 5476 |
} else { |
| 5477 |
$sum = floor($daysdiff) * 86400; |
| 5478 |
$newdiff = $secdiff - $sum; |
| 5479 |
$maxhmore = VikRentCar::getHoursMoreRb() * 3600; |
| 5480 |
if ($maxhmore >= $newdiff) { |
| 5481 |
$daysdiff = floor($daysdiff); |
| 5482 |
} else { |
| 5483 |
$daysdiff = ceil($daysdiff); |
| 5484 |
/** |
| 5485 |
* Apply proper rounding with gratuity period. |
| 5486 |
* |
| 5487 |
* @since 1.15.1 (J) - 1.3.2 (WP) |
| 5488 |
* @since 1.15.8 (J) - 1.4.5 (WP) |
| 5489 |
*/ |
| 5490 |
$ehours_float = ($newdiff - $maxhmore) / 3600; |
| 5491 |
$ehours = intval(ceil($ehours_float)); |
| 5492 |
$ehours = !$ehours && $ehours_float > 0 && $maxhmore > 0 ? 1 : $ehours; |
| 5493 |
$checkhourscharges = $ehours; |
| 5494 |
if ($checkhourscharges > 0) { |
| 5495 |
$aehourschbasp = VikRentCar::applyExtraHoursChargesBasp(); |
| 5496 |
} |
| 5497 |
} |
| 5498 |
} |
| 5499 |
} |
| 5500 |
if ($checkhourscharges > 0 && $aehourschbasp == true && !$is_cust_cost) { |
| 5501 |
$ret = VikRentCar::applyExtraHoursChargesCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, false, true, true); |
| 5502 |
$tar = $ret['return']; |
| 5503 |
$calcdays = $ret['days']; |
| 5504 |
} |
| 5505 |
if ($checkhourscharges > 0 && $aehourschbasp == false && !$is_cust_cost) { |
| 5506 |
$tar = VikRentCar::extraHoursSetPreviousFareCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, true); |
| 5507 |
$tar = VikRentCar::applySeasonsCar($tar, $order[0]['ritiro'], $order[0]['consegna'], $order[0]['idplace']); |
| 5508 |
$ret = VikRentCar::applyExtraHoursChargesCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, true, true, true); |
| 5509 |
$tar = $ret['return']; |
| 5510 |
$calcdays = $ret['days']; |
| 5511 |
} else { |
| 5512 |
if (!$is_cust_cost) { |
| 5513 |
//Seasonal prices only if not a custom rate |
| 5514 |
$tar = VikRentCar::applySeasonsCar($tar, $order[0]['ritiro'], $order[0]['consegna'], $order[0]['idplace']); |
| 5515 |
} |
| 5516 |
} |
| 5517 |
// |
| 5518 |
$ritplace = (!empty($order[0]['idplace']) ? VikRentCar::getPlaceName($order[0]['idplace'], $vrc_tn) : ""); |
| 5519 |
$consegnaplace = (!empty($order[0]['idreturnplace']) ? VikRentCar::getPlaceName($order[0]['idreturnplace'], $vrc_tn) : ""); |
| 5520 |
$costplusiva = $is_cust_cost ? VikRentCar::sayCustCostPlusIva($tar[0]['cost'], $order[0]['cust_idiva']) : VikRentCar::sayCostPlusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 5521 |
$costminusiva = $is_cust_cost ? VikRentCar::sayCustCostMinusIva($tar[0]['cost'], $order[0]['cust_idiva']) : VikRentCar::sayCostMinusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 5522 |
$pricestr = ($is_cust_cost ? JText::translate('VRCRENTCUSTRATEPLAN').": ".$costplusiva : VikRentCar::getPriceName($tar[0]['idprice'], $vrc_tn)).": ".$costplusiva.(!empty($tar[0]['attrdata']) ? "\n".VikRentCar::getPriceAttr($tar[0]['idprice'], $vrc_tn).": ".$tar[0]['attrdata'] : ""); |
| 5523 |
$isdue = $is_cust_cost ? $tar[0]['cost'] : VikRentCar::sayCostPlusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 5524 |
$optstr = ""; |
| 5525 |
$optarrtaxnet = array(); |
| 5526 |
if (!empty($order[0]['optionals'])) { |
| 5527 |
$stepo=explode(";", $order[0]['optionals']); |
| 5528 |
foreach ($stepo as $oo) { |
| 5529 |
if (!empty($oo)) { |
| 5530 |
$stept = explode(":", $oo); |
| 5531 |
$q = "SELECT `id`,`name`,`cost`,`perday`,`hmany`,`idiva`,`maxprice` FROM `#__vikrentcar_optionals` WHERE `id`=".$dbo->quote($stept[0]).";"; |
| 5532 |
$dbo->setQuery($q); |
| 5533 |
$actopt = $dbo->loadAssocList(); |
| 5534 |
if ($actopt) { |
| 5535 |
$vrc_tn->translateContents($actopt, '#__vikrentcar_optionals'); |
| 5536 |
$realcost = intval($actopt[0]['perday']) == 1 ? ($actopt[0]['cost'] * $order[0]['days'] * $stept[1]) : ($actopt[0]['cost'] * $stept[1]); |
| 5537 |
$basequancost = intval($actopt[0]['perday']) == 1 ? ($actopt[0]['cost'] * $order[0]['days']) : $actopt[0]['cost']; |
| 5538 |
if (!empty($actopt[0]['maxprice']) && $actopt[0]['maxprice'] > 0 && $basequancost > $actopt[0]['maxprice']) { |
| 5539 |
$realcost = $actopt[0]['maxprice']; |
| 5540 |
if (intval($actopt[0]['hmany']) == 1 && intval($stept[1]) > 1) { |
| 5541 |
$realcost = $actopt[0]['maxprice'] * $stept[1]; |
| 5542 |
} |
| 5543 |
} |
| 5544 |
$tmpopr = VikRentCar::sayOptionalsPlusIva($realcost, $actopt[0]['idiva'], $order[0]); |
| 5545 |
$isdue += $tmpopr; |
| 5546 |
$optnetprice = VikRentCar::sayOptionalsMinusIva($realcost, $actopt[0]['idiva'], $order[0]); |
| 5547 |
$optarrtaxnet[] = $optnetprice; |
| 5548 |
$optstr .= ($stept[1] > 1 ? $stept[1]." " : "").$actopt[0]['name'].": ".$tmpopr."\n"; |
| 5549 |
} |
| 5550 |
} |
| 5551 |
} |
| 5552 |
} |
| 5553 |
//custom extra costs |
| 5554 |
if (!empty($order[0]['extracosts'])) { |
| 5555 |
$cur_extra_costs = json_decode($order[0]['extracosts'], true); |
| 5556 |
foreach ($cur_extra_costs as $eck => $ecv) { |
| 5557 |
$efee_cost = VikRentCar::sayOptionalsPlusIva($ecv['cost'], $ecv['idtax'], $order[0]); |
| 5558 |
$isdue += $efee_cost; |
| 5559 |
$efee_cost_without = VikRentCar::sayOptionalsMinusIva($ecv['cost'], $ecv['idtax'], $order[0]); |
| 5560 |
$optarrtaxnet[] = $efee_cost_without; |
| 5561 |
$optstr.=$ecv['name'].": ".$efee_cost."\n"; |
| 5562 |
} |
| 5563 |
} |
| 5564 |
// |
| 5565 |
$maillocfee = ""; |
| 5566 |
$locfeewithouttax = 0; |
| 5567 |
if (!empty($order[0]['idplace']) && !empty($order[0]['idreturnplace'])) { |
| 5568 |
$locfee = VikRentCar::getLocFee($order[0]['idplace'], $order[0]['idreturnplace']); |
| 5569 |
if ($locfee) { |
| 5570 |
//VikRentCar 1.7 - Location fees overrides |
| 5571 |
if (strlen($locfee['losoverride']) > 0) { |
| 5572 |
$arrvaloverrides = array(); |
| 5573 |
$valovrparts = explode('_', $locfee['losoverride']); |
| 5574 |
foreach ($valovrparts as $valovr) { |
| 5575 |
if (!empty($valovr)) { |
| 5576 |
$ovrinfo = explode(':', $valovr); |
| 5577 |
$arrvaloverrides[$ovrinfo[0]] = $ovrinfo[1]; |
| 5578 |
} |
| 5579 |
} |
| 5580 |
if (array_key_exists($order[0]['days'], $arrvaloverrides)) { |
| 5581 |
$locfee['cost'] = $arrvaloverrides[$order[0]['days']]; |
| 5582 |
} |
| 5583 |
} |
| 5584 |
//end VikRentCar 1.7 - Location fees overrides |
| 5585 |
$locfeecost = intval($locfee['daily']) == 1 ? ($locfee['cost'] * $order[0]['days']) : $locfee['cost']; |
| 5586 |
$locfeewith = VikRentCar::sayLocFeePlusIva($locfeecost, $locfee['idiva'], $order[0]); |
| 5587 |
$isdue += $locfeewith; |
| 5588 |
$locfeewithouttax = VikRentCar::sayLocFeeMinusIva($locfeecost, $locfee['idiva'], $order[0]); |
| 5589 |
$maillocfee = $locfeewith; |
| 5590 |
} |
| 5591 |
} |
| 5592 |
//VRC 1.9 - Out of Hours Fees |
| 5593 |
$oohfee = VikRentCar::getOutOfHoursFees($order[0]['idplace'], $order[0]['idreturnplace'], $order[0]['ritiro'], $order[0]['consegna'], array('id' => $order[0]['idcar'])); |
| 5594 |
$mailoohfee = ""; |
| 5595 |
$oohfeewithouttax = 0; |
| 5596 |
if (count($oohfee) > 0) { |
| 5597 |
$oohfeewith = VikRentCar::sayOohFeePlusIva($oohfee['cost'], $oohfee['idiva']); |
| 5598 |
$isdue += $oohfeewith; |
| 5599 |
$oohfeewithouttax = VikRentCar::sayOohFeeMinusIva($oohfee['cost'], $oohfee['idiva']); |
| 5600 |
$mailoohfee = $oohfeewith; |
| 5601 |
} |
| 5602 |
// |
| 5603 |
//vikrentcar 1.6 coupon |
| 5604 |
$usedcoupon = false; |
| 5605 |
$origisdue = $isdue; |
| 5606 |
if (strlen($order[0]['coupon']) > 0) { |
| 5607 |
$usedcoupon = true; |
| 5608 |
$expcoupon = explode(";", $order[0]['coupon']); |
| 5609 |
$isdue = $isdue - $expcoupon[1]; |
| 5610 |
} |
| 5611 |
// |
| 5612 |
$arrayinfopdf = array('days' => $order[0]['days'], 'tarminusiva' => $costminusiva, 'tartax' => ($costplusiva - $costminusiva), 'opttaxnet' => $optarrtaxnet, 'locfeenet' => $locfeewithouttax, 'oohfeenet' => $oohfeewithouttax, 'order_id' => $order[0]['id'], 'tot_paid' => $order[0]['totpaid']); |
| 5613 |
$saystatus = $order[0]['status'] == 'confirmed' ? JText::translate('VRCOMPLETED') : ($order[0]['status'] == 'standby' ? JText::translate('VRSTANDBY') : JText::translate('VRCANCELLED')); |
| 5614 |
VikRentCar::generateCheckinPdf($order[0]['custmail'], strip_tags($ftitle)." ".JText::translate('VRRENTALORD'), $ftitle, $nowts, $order[0]['custdata'], $carinfo['name'], $order[0]['ritiro'], $order[0]['consegna'], $pricestr, $optstr, $isdue, $viklink, $saystatus, $ritplace, $consegnaplace, $maillocfee, $mailoohfee, $order[0]['id'], $order[0]['coupon'], $arrayinfopdf); |
| 5615 |
|
| 5616 |
// store order history record |
| 5617 |
$history_obj = VikRentCar::getOrderHistoryInstance()->setBid($order[0]['id']); |
| 5618 |
if (!$history_obj->hasEvent('RB')) { |
| 5619 |
$history_obj->store('RB'); |
| 5620 |
// update order record with new registration status (started) |
| 5621 |
$order_record = new stdClass; |
| 5622 |
$order_record->id = $order[0]['id']; |
| 5623 |
$order_record->reg = 1; |
| 5624 |
$dbo->updateObject('#__vikrentcar_orders', $order_record, 'id'); |
| 5625 |
} |
| 5626 |
} |
| 5627 |
$mainframe = JFactory::getApplication(); |
| 5628 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=".$oid); |
| 5629 |
} |
| 5630 |
|
| 5631 |
public function sortlocation() { |
| 5632 |
$cid = VikRequest::getVar('cid', array(0)); |
| 5633 |
$sortid = (int)$cid[0]; |
| 5634 |
$pmode = VikRequest::getString('mode', '', 'request'); |
| 5635 |
$dbo = JFactory::getDbo(); |
| 5636 |
$mainframe = JFactory::getApplication(); |
| 5637 |
if (!empty($pmode)) { |
| 5638 |
$q = "SELECT `id`,`ordering` FROM `#__vikrentcar_places` ORDER BY `#__vikrentcar_places`.`ordering` ASC;"; |
| 5639 |
$dbo->setQuery($q); |
| 5640 |
$dbo->execute(); |
| 5641 |
$totr=$dbo->getNumRows(); |
| 5642 |
if ($totr > 1) { |
| 5643 |
$data = $dbo->loadAssocList(); |
| 5644 |
if ($pmode == "up") { |
| 5645 |
foreach ($data as $v) { |
| 5646 |
if ($v['id'] == $sortid) { |
| 5647 |
$y = $v['ordering']; |
| 5648 |
} |
| 5649 |
} |
| 5650 |
if ($y && $y > 1) { |
| 5651 |
$vik = $y - 1; |
| 5652 |
$found = false; |
| 5653 |
foreach ($data as $v) { |
| 5654 |
if (intval($v['ordering'])==intval($vik)) { |
| 5655 |
$found = true; |
| 5656 |
$q = "UPDATE `#__vikrentcar_places` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 5657 |
$dbo->setQuery($q); |
| 5658 |
$dbo->execute(); |
| 5659 |
$q = "UPDATE `#__vikrentcar_places` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 5660 |
$dbo->setQuery($q); |
| 5661 |
$dbo->execute(); |
| 5662 |
break; |
| 5663 |
} |
| 5664 |
} |
| 5665 |
if (!$found) { |
| 5666 |
$q = "UPDATE `#__vikrentcar_places` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 5667 |
$dbo->setQuery($q); |
| 5668 |
$dbo->execute(); |
| 5669 |
} |
| 5670 |
} |
| 5671 |
} elseif ($pmode == "down") { |
| 5672 |
foreach ($data as $v) { |
| 5673 |
if ($v['id'] == $sortid[0]) { |
| 5674 |
$y = $v['ordering']; |
| 5675 |
} |
| 5676 |
} |
| 5677 |
if ($y) { |
| 5678 |
$vik = $y + 1; |
| 5679 |
$found = false; |
| 5680 |
foreach ($data as $v) { |
| 5681 |
if (intval($v['ordering']) == intval($vik)) { |
| 5682 |
$found = true; |
| 5683 |
$q = "UPDATE `#__vikrentcar_places` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 5684 |
$dbo->setQuery($q); |
| 5685 |
$dbo->execute(); |
| 5686 |
$q = "UPDATE `#__vikrentcar_places` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 5687 |
$dbo->setQuery($q); |
| 5688 |
$dbo->execute(); |
| 5689 |
break; |
| 5690 |
} |
| 5691 |
} |
| 5692 |
if (!$found) { |
| 5693 |
$q = "UPDATE `#__vikrentcar_places` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 5694 |
$dbo->setQuery($q); |
| 5695 |
$dbo->execute(); |
| 5696 |
} |
| 5697 |
} |
| 5698 |
} |
| 5699 |
} |
| 5700 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=places"); |
| 5701 |
} else { |
| 5702 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 5703 |
} |
| 5704 |
} |
| 5705 |
|
| 5706 |
public function geninvoices() { |
| 5707 |
$ids = VikRequest::getVar('cid', array(0)); |
| 5708 |
$mainframe = JFactory::getApplication(); |
| 5709 |
if (@count($ids)) { |
| 5710 |
$dbo = JFactory::getDbo(); |
| 5711 |
require_once(VRC_SITE_PATH . DIRECTORY_SEPARATOR . "helpers" . DIRECTORY_SEPARATOR . "tcpdf" . DIRECTORY_SEPARATOR . 'tcpdf.php'); |
| 5712 |
if (is_file(VRC_SITE_PATH . DIRECTORY_SEPARATOR . "helpers" . DIRECTORY_SEPARATOR . "tcpdf" . DIRECTORY_SEPARATOR . "fonts" . DIRECTORY_SEPARATOR . "dejavusans.php")) { |
| 5713 |
$usepdffont = 'dejavusans'; |
| 5714 |
} else { |
| 5715 |
$usepdffont = 'helvetica'; |
| 5716 |
} |
| 5717 |
|
| 5718 |
/** |
| 5719 |
* Trigger event to allow third party plugins to return a specific font name. |
| 5720 |
* |
| 5721 |
* @since 1.15.1 (J) - 1.3.2 (WP) |
| 5722 |
*/ |
| 5723 |
$custom_pdf_font = VRCFactory::getPlatform()->getDispatcher()->filter('onGetPdfFontNameVikRentCar', [$usepdffont]); |
| 5724 |
if (is_array($custom_pdf_font) && !empty($custom_pdf_font[0])) { |
| 5725 |
$usepdffont = $custom_pdf_font[0]; |
| 5726 |
} |
| 5727 |
|
| 5728 |
$pinvoice_num = VikRequest::getInt('invoice_num', '', 'request'); |
| 5729 |
$pinvoice_num = $pinvoice_num <= 0 ? 1 : $pinvoice_num; |
| 5730 |
$pinvoice_suff = VikRequest::getString('invoice_suff', '', 'request'); |
| 5731 |
$pinvoice_date = VikRequest::getString('invoice_date', '', 'request'); |
| 5732 |
$pcompany_info = VikRequest::getString('company_info', '', 'request', VIKREQUEST_ALLOWHTML); |
| 5733 |
$pinvoice_send = VikRequest::getString('invoice_send', '', 'request'); |
| 5734 |
$pinvoice_send = $pinvoice_send == '1' ? 1 : 0; |
| 5735 |
$nowdf = VikRentCar::getDateFormat(true); |
| 5736 |
$nowtf = VikRentCar::getTimeFormat(true); |
| 5737 |
$tf = $nowtf; |
| 5738 |
if ($nowdf == "%d/%m/%Y") { |
| 5739 |
$df = 'd/m/Y'; |
| 5740 |
} elseif ($nowdf == "%m/%d/%Y") { |
| 5741 |
$df = 'm/d/Y'; |
| 5742 |
} else { |
| 5743 |
$df = 'Y/m/d'; |
| 5744 |
} |
| 5745 |
$today = date($df); |
| 5746 |
$admail = VikRentCar::getAdminMail(); |
| 5747 |
$currencyname = VikRentCar::getCurrencyName(); |
| 5748 |
$companylogo = VikRentCar::getSiteLogo(); |
| 5749 |
$uselogo = ''; |
| 5750 |
if (!empty($companylogo)) { |
| 5751 |
$uselogo = '<img src="'.VRC_ADMIN_URI.'resources/'.$companylogo.'"/>'; |
| 5752 |
} |
| 5753 |
$totinvgen = 0; |
| 5754 |
sort($ids); |
| 5755 |
$vrc_tn = VikRentCar::getTranslator(); |
| 5756 |
foreach ($ids as $oid) { |
| 5757 |
$q = "SELECT * FROM `#__vikrentcar_orders` WHERE `id`=".(int)$oid." AND `status`='confirmed';"; |
| 5758 |
$dbo->setQuery($q); |
| 5759 |
$dbo->execute(); |
| 5760 |
if ($dbo->getNumRows() == 1) { |
| 5761 |
$order = $dbo->loadAssocList(); |
| 5762 |
$isdue = 0; |
| 5763 |
$descriptions = array(); |
| 5764 |
$netprices = array(); |
| 5765 |
$taxes = array(); |
| 5766 |
//check if the language in use is the same as the one used during the checkout |
| 5767 |
if (!empty($order[0]['lang'])) { |
| 5768 |
$lang = JFactory::getLanguage(); |
| 5769 |
if ($lang->getTag() != $order[0]['lang']) { |
| 5770 |
$lang->load('com_vikrentcar', VIKRENTCAR_ADMIN_LANG, $order[0]['lang'], true); |
| 5771 |
$vrc_tn::$force_tolang = $order[0]['lang']; |
| 5772 |
} |
| 5773 |
} |
| 5774 |
// |
| 5775 |
$car = VikRentCar::getCarInfo($order[0]['idcar']); |
| 5776 |
$is_cust_cost = (!empty($order[0]['cust_cost']) && $order[0]['cust_cost'] > 0); |
| 5777 |
if (!empty($order[0]['idtar'])) { |
| 5778 |
if ($order[0]['hourly'] == 1) { |
| 5779 |
$q = "SELECT * FROM `#__vikrentcar_dispcosthours` WHERE `id`='".$order[0]['idtar']."';"; |
| 5780 |
} else { |
| 5781 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `id`='".$order[0]['idtar']."';"; |
| 5782 |
} |
| 5783 |
$dbo->setQuery($q); |
| 5784 |
$dbo->execute(); |
| 5785 |
if ($dbo->getNumRows() == 0) { |
| 5786 |
if ($order[0]['hourly'] == 1) { |
| 5787 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `id`='".$order[0]['idtar']."';"; |
| 5788 |
$dbo->setQuery($q); |
| 5789 |
$dbo->execute(); |
| 5790 |
if ($dbo->getNumRows() == 1) { |
| 5791 |
$tar = $dbo->loadAssocList(); |
| 5792 |
} |
| 5793 |
} |
| 5794 |
} else { |
| 5795 |
$tar = $dbo->loadAssocList(); |
| 5796 |
} |
| 5797 |
} elseif ($is_cust_cost) { |
| 5798 |
//Custom Rate |
| 5799 |
$tar = array(0 => array( |
| 5800 |
'id' => -1, |
| 5801 |
'idcar' => $order[0]['idcar'], |
| 5802 |
'days' => $order[0]['days'], |
| 5803 |
'idprice' => -1, |
| 5804 |
'cost' => $order[0]['cust_cost'], |
| 5805 |
'attrdata' => '', |
| 5806 |
)); |
| 5807 |
} |
| 5808 |
if ($order[0]['hourly'] == 1 && !empty($tar[0]['hours'])) { |
| 5809 |
foreach ($tar as $kt => $vt) { |
| 5810 |
$tar[$kt]['days'] = 1; |
| 5811 |
} |
| 5812 |
} |
| 5813 |
$checkhourscharges = 0; |
| 5814 |
$ppickup = $order[0]['ritiro']; |
| 5815 |
$prelease = $order[0]['consegna']; |
| 5816 |
$secdiff = $prelease - $ppickup; |
| 5817 |
$daysdiff = $secdiff / 86400; |
| 5818 |
if (is_int($daysdiff)) { |
| 5819 |
if ($daysdiff < 1) { |
| 5820 |
$daysdiff = 1; |
| 5821 |
} |
| 5822 |
} else { |
| 5823 |
if ($daysdiff < 1) { |
| 5824 |
$daysdiff = 1; |
| 5825 |
} else { |
| 5826 |
$sum = floor($daysdiff) * 86400; |
| 5827 |
$newdiff = $secdiff - $sum; |
| 5828 |
$maxhmore = VikRentCar::getHoursMoreRb() * 3600; |
| 5829 |
if ($maxhmore >= $newdiff) { |
| 5830 |
$daysdiff = floor($daysdiff); |
| 5831 |
} else { |
| 5832 |
$daysdiff = ceil($daysdiff); |
| 5833 |
/** |
| 5834 |
* Apply proper rounding with gratuity period. |
| 5835 |
* |
| 5836 |
* @since 1.15.1 (J) - 1.3.2 (WP) |
| 5837 |
* @since 1.15.8 (J) - 1.4.5 (WP) |
| 5838 |
*/ |
| 5839 |
$ehours_float = ($newdiff - $maxhmore) / 3600; |
| 5840 |
$ehours = intval(ceil($ehours_float)); |
| 5841 |
$ehours = !$ehours && $ehours_float > 0 && $maxhmore > 0 ? 1 : $ehours; |
| 5842 |
$checkhourscharges = $ehours; |
| 5843 |
if ($checkhourscharges > 0) { |
| 5844 |
$aehourschbasp = VikRentCar::applyExtraHoursChargesBasp(); |
| 5845 |
} |
| 5846 |
} |
| 5847 |
} |
| 5848 |
} |
| 5849 |
if ($checkhourscharges > 0 && $aehourschbasp == true && !$is_cust_cost) { |
| 5850 |
$ret = VikRentCar::applyExtraHoursChargesCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, false, true, true); |
| 5851 |
$tar = $ret['return']; |
| 5852 |
$calcdays = $ret['days']; |
| 5853 |
} |
| 5854 |
if ($checkhourscharges > 0 && $aehourschbasp == false && !$is_cust_cost) { |
| 5855 |
$tar = VikRentCar::extraHoursSetPreviousFareCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, true); |
| 5856 |
$tar = VikRentCar::applySeasonsCar($tar, $order[0]['ritiro'], $order[0]['consegna'], $order[0]['idplace']); |
| 5857 |
$ret = VikRentCar::applyExtraHoursChargesCar($tar, $order[0]['idcar'], $checkhourscharges, $daysdiff, true, true, true); |
| 5858 |
$tar = $ret['return']; |
| 5859 |
$calcdays = $ret['days']; |
| 5860 |
} else { |
| 5861 |
if (!$is_cust_cost) { |
| 5862 |
//Seasonal prices only if not a custom rate |
| 5863 |
$tar = VikRentCar::applySeasonsCar($tar, $order[0]['ritiro'], $order[0]['consegna'], $order[0]['idplace']); |
| 5864 |
} |
| 5865 |
} |
| 5866 |
$ritplace = (!empty($order[0]['idplace']) ? VikRentCar::getPlaceName($order[0]['idplace']) : ""); |
| 5867 |
$consegnaplace = (!empty($order[0]['idreturnplace']) ? VikRentCar::getPlaceName($order[0]['idreturnplace']) : ""); |
| 5868 |
$costplusiva = $is_cust_cost ? VikRentCar::sayCustCostPlusIva($tar[0]['cost'], $order[0]['cust_idiva']) : VikRentCar::sayCostPlusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 5869 |
$costminusiva = $is_cust_cost ? VikRentCar::sayCustCostMinusIva($tar[0]['cost'], $order[0]['cust_idiva']) : VikRentCar::sayCostMinusIva($tar[0]['cost'], $tar[0]['idprice'], $order[0]); |
| 5870 |
$pricestr = JText::sprintf('VRCINVDESCRCONT', $car['name'], date($df.' '.$tf, $order[0]['ritiro']))."\n"; |
| 5871 |
$pricestr .= ($is_cust_cost ? JText::translate('VRCRENTCUSTRATEPLAN') : VikRentCar::getPriceName($tar[0]['idprice'])).(!empty($tar[0]['attrdata']) ? "\n".VikRentCar::getPriceAttr($tar[0]['idprice']).": ".$tar[0]['attrdata'] : ""); |
| 5872 |
//description |
| 5873 |
$descriptions[] = nl2br(rtrim($pricestr, "\n")); |
| 5874 |
//Prices |
| 5875 |
$netprices[] = $costminusiva; |
| 5876 |
$taxes[] = ($costplusiva - $costminusiva); |
| 5877 |
$isdue = $costplusiva; |
| 5878 |
//Options |
| 5879 |
if (!empty($order[0]['optionals'])) { |
| 5880 |
$stepo=explode(";", $order[0]['optionals']); |
| 5881 |
foreach ($stepo as $oo) { |
| 5882 |
if (!empty($oo)) { |
| 5883 |
$stept=explode(":", $oo); |
| 5884 |
$q = "SELECT `id`,`name`,`cost`,`perday`,`hmany`,`idiva`,`maxprice` FROM `#__vikrentcar_optionals` WHERE `id`=".intval($stept[0]).";"; |
| 5885 |
$dbo->setQuery($q); |
| 5886 |
$dbo->execute(); |
| 5887 |
if ($dbo->getNumRows() == 1) { |
| 5888 |
$actopt = $dbo->loadAssocList(); |
| 5889 |
$realcost = intval($actopt[0]['perday']) == 1 ? ($actopt[0]['cost'] * $order[0]['days'] * $stept[1]) : ($actopt[0]['cost'] * $stept[1]); |
| 5890 |
$basequancost = intval($actopt[0]['perday']) == 1 ? ($actopt[0]['cost'] * $order[0]['days']) : $actopt[0]['cost']; |
| 5891 |
if (!empty($actopt[0]['maxprice']) && $actopt[0]['maxprice'] > 0 && $basequancost > $actopt[0]['maxprice']) { |
| 5892 |
$realcost = $actopt[0]['maxprice']; |
| 5893 |
if (intval($actopt[0]['hmany']) == 1 && intval($stept[1]) > 1) { |
| 5894 |
$realcost = $actopt[0]['maxprice'] * $stept[1]; |
| 5895 |
} |
| 5896 |
} |
| 5897 |
$tmpopr = VikRentCar::sayOptionalsPlusIva($realcost, $actopt[0]['idiva'], $order[0]); |
| 5898 |
$isdue += $tmpopr; |
| 5899 |
$optnetprice = VikRentCar::sayOptionalsMinusIva($realcost, $actopt[0]['idiva'], $order[0]); |
| 5900 |
$descriptions[] = ($stept[1] > 1 ? $stept[1]." " : "").$actopt[0]['name'].": ".$tmpopr; |
| 5901 |
$netprices[] = $optnetprice; |
| 5902 |
$taxes[] = ($tmpopr - $optnetprice); |
| 5903 |
} |
| 5904 |
} |
| 5905 |
} |
| 5906 |
} |
| 5907 |
//Location Fees |
| 5908 |
if (!empty($order[0]['idplace']) && !empty($order[0]['idreturnplace'])) { |
| 5909 |
$locfee=VikRentCar::getLocFee($order[0]['idplace'], $order[0]['idreturnplace']); |
| 5910 |
if ($locfee) { |
| 5911 |
if (strlen($locfee['losoverride']) > 0) { |
| 5912 |
$arrvaloverrides = array(); |
| 5913 |
$valovrparts = explode('_', $locfee['losoverride']); |
| 5914 |
foreach ($valovrparts as $valovr) { |
| 5915 |
if (!empty($valovr)) { |
| 5916 |
$ovrinfo = explode(':', $valovr); |
| 5917 |
$arrvaloverrides[$ovrinfo[0]] = $ovrinfo[1]; |
| 5918 |
} |
| 5919 |
} |
| 5920 |
if (array_key_exists($order[0]['days'], $arrvaloverrides)) { |
| 5921 |
$locfee['cost'] = $arrvaloverrides[$order[0]['days']]; |
| 5922 |
} |
| 5923 |
} |
| 5924 |
$locfeecost=intval($locfee['daily']) == 1 ? ($locfee['cost'] * $order[0]['days']) : $locfee['cost']; |
| 5925 |
$locfeewith=VikRentCar::sayLocFeePlusIva($locfeecost, $locfee['idiva'], $order[0]); |
| 5926 |
$isdue+=$locfeewith; |
| 5927 |
$locfeewithouttax = VikRentCar::sayLocFeeMinusIva($locfeecost, $locfee['idiva'], $order[0]); |
| 5928 |
$descriptions[] = JText::translate('VRLOCFEETOPAY'); |
| 5929 |
$netprices[] = $locfeewithouttax; |
| 5930 |
$taxes[] = ($locfeewith - $locfeewithouttax); |
| 5931 |
} |
| 5932 |
} |
| 5933 |
//Out of Hours Fees |
| 5934 |
$oohfee = VikRentCar::getOutOfHoursFees($order[0]['idplace'], $order[0]['idreturnplace'], $order[0]['ritiro'], $order[0]['consegna'], array('id' => $order[0]['idcar'])); |
| 5935 |
if (count($oohfee) > 0) { |
| 5936 |
$oohfeewith = VikRentCar::sayOohFeePlusIva($oohfee['cost'], $oohfee['idiva']); |
| 5937 |
$isdue += $oohfeewith; |
| 5938 |
$oohfeewithouttax = VikRentCar::sayOohFeeMinusIva($oohfee['cost'], $oohfee['idiva']); |
| 5939 |
$mailoohfee = $oohfeewith; |
| 5940 |
$descriptions[] = JText::translate('VRCOOHFEEAMOUNT'); |
| 5941 |
$netprices[] = $oohfeewithouttax; |
| 5942 |
$taxes[] = ($oohfeewith - $oohfeewithouttax); |
| 5943 |
} |
| 5944 |
//custom extra costs |
| 5945 |
if (!empty($order[0]['extracosts'])) { |
| 5946 |
$cur_extra_costs = json_decode($order[0]['extracosts'], true); |
| 5947 |
foreach ($cur_extra_costs as $eck => $ecv) { |
| 5948 |
$efee_cost = VikRentCar::sayOptionalsPlusIva($ecv['cost'], $ecv['idtax'], $order[0]); |
| 5949 |
$isdue += $efee_cost; |
| 5950 |
$efee_cost_without = VikRentCar::sayOptionalsMinusIva($ecv['cost'], $ecv['idtax'], $order[0]); |
| 5951 |
$descriptions[] = $ecv['name']; |
| 5952 |
$netprices[] = $efee_cost_without; |
| 5953 |
$taxes[] = ($efee_cost - $efee_cost_without); |
| 5954 |
} |
| 5955 |
} |
| 5956 |
// |
| 5957 |
//date |
| 5958 |
$usedate = $pinvoice_date == '0' ? date($df, $order[0]['ts']) : $today; |
| 5959 |
//compose body |
| 5960 |
list($invoicetpl, $pdfparams) = VikRentCar::loadInvoiceTmpl($order[0]); |
| 5961 |
$hbody = VikRentCar::parseInvoiceTemplate($invoicetpl, $order[0], $car, array('currencyname' => $currencyname, 'company_logo' => $uselogo, 'company_info' => nl2br($pcompany_info), 'invoice_number' => $pinvoice_num, 'invoice_suffix' => $pinvoice_suff, 'invoice_date' => $usedate, 'invoice_products_descriptions' => $descriptions, 'invoice_products_netprices' => $netprices, 'invoice_products_taxes' => $taxes, 'invoice_grandtotal' => $isdue)); |
| 5962 |
//generate PDF |
| 5963 |
$pdffname = $order[0]['id'] . '_' . $order[0]['sid'] . '.pdf'; |
| 5964 |
$pathpdf = VRC_SITE_PATH . DIRECTORY_SEPARATOR . "helpers" . DIRECTORY_SEPARATOR . "invoices" . DIRECTORY_SEPARATOR . "generated" . DIRECTORY_SEPARATOR . $pdffname; |
| 5965 |
if (file_exists($pathpdf)) @unlink($pathpdf); |
| 5966 |
$pdf_page_format = is_array($pdfparams['pdf_page_format']) ? $pdfparams['pdf_page_format'] : constant($pdfparams['pdf_page_format']); |
| 5967 |
$pdf = new TCPDF(constant($pdfparams['pdf_page_orientation']), constant($pdfparams['pdf_unit']), $pdf_page_format, true, 'UTF-8', false); |
| 5968 |
$pdf->SetTitle(JText::translate('VRCINVNUM').' '.$pinvoice_num); |
| 5969 |
//Header for each page of the pdf |
| 5970 |
if ($pdfparams['show_header'] == 1 && count($pdfparams['header_data']) > 0) { |
| 5971 |
$pdf->SetHeaderData($pdfparams['header_data'][0], $pdfparams['header_data'][1], $pdfparams['header_data'][2], $pdfparams['header_data'][3], $pdfparams['header_data'][4], $pdfparams['header_data'][5]); |
| 5972 |
} |
| 5973 |
//Change some currencies to their unicode (decimal) value |
| 5974 |
$unichr_map = array('EUR' => 8364, 'USD' => 36, 'AUD' => 36, 'CAD' => 36, 'GBP' => 163); |
| 5975 |
if (array_key_exists($currencyname, $unichr_map)) { |
| 5976 |
$hbody = str_replace($currencyname, TCPDF_FONTS::unichr($unichr_map[$currencyname]), $hbody); |
| 5977 |
} |
| 5978 |
//header and footer fonts |
| 5979 |
$pdf->setHeaderFont(array($usepdffont, '', $pdfparams['header_font_size'])); |
| 5980 |
$pdf->setFooterFont(array($usepdffont, '', $pdfparams['footer_font_size'])); |
| 5981 |
//margins |
| 5982 |
$pdf->SetMargins(constant($pdfparams['pdf_margin_left']), constant($pdfparams['pdf_margin_top']), constant($pdfparams['pdf_margin_right'])); |
| 5983 |
$pdf->SetHeaderMargin(constant($pdfparams['pdf_margin_header'])); |
| 5984 |
$pdf->SetFooterMargin(constant($pdfparams['pdf_margin_footer'])); |
| 5985 |
// |
| 5986 |
$pdf->SetAutoPageBreak(true, constant($pdfparams['pdf_margin_bottom'])); |
| 5987 |
$pdf->setImageScale(constant($pdfparams['pdf_image_scale_ratio'])); |
| 5988 |
$pdf->SetFont($usepdffont, '', (int)$pdfparams['body_font_size']); |
| 5989 |
if ($pdfparams['show_header'] == 0 || !(count($pdfparams['header_data']) > 0)) { |
| 5990 |
$pdf->SetPrintHeader(false); |
| 5991 |
} |
| 5992 |
if ($pdfparams['show_footer'] == 0) { |
| 5993 |
$pdf->SetPrintFooter(false); |
| 5994 |
} |
| 5995 |
$pdf->AddPage(); |
| 5996 |
$pdf->writeHTML($hbody, true, false, true, false, ''); |
| 5997 |
$pdf->lastPage(); |
| 5998 |
$pdf->Output($pathpdf, 'F'); |
| 5999 |
if (file_exists($pathpdf)) { |
| 6000 |
if ($pinvoice_send == 1) { |
| 6001 |
//send invoice via email |
| 6002 |
$vrc_app = new VrcApplication(); |
| 6003 |
$vrc_app->sendMail($admail, $admail, $order[0]['custmail'], $admail, JText::translate('VRCINVMAILSUBJ'), JText::translate('VRCINVMAILCONT'), true, 'base64', $pathpdf); |
| 6004 |
unset($mailer); |
| 6005 |
} |
| 6006 |
$totinvgen++; |
| 6007 |
$pinvoice_num++; |
| 6008 |
/** |
| 6009 |
* @wponly - trigger files mirroring |
| 6010 |
*/ |
| 6011 |
VikRentCarLoader::import('update.manager'); |
| 6012 |
VikRentCarUpdateManager::triggerUploadBackup($pathpdf); |
| 6013 |
// |
| 6014 |
} |
| 6015 |
} |
| 6016 |
} |
| 6017 |
$mainframe->enqueueMessage(JText::sprintf('VRCTOTINVGEN', $totinvgen)); |
| 6018 |
//update values used |
| 6019 |
$q = "UPDATE `#__vikrentcar_config` SET `setting`='".($pinvoice_num - 1)."' WHERE `param`='invoiceinum';"; |
| 6020 |
$dbo->setQuery($q); |
| 6021 |
$dbo->execute(); |
| 6022 |
$q = "UPDATE `#__vikrentcar_config` SET `setting`=".$dbo->quote($pinvoice_suff)." WHERE `param`='invoicesuffix';"; |
| 6023 |
$dbo->setQuery($q); |
| 6024 |
$dbo->execute(); |
| 6025 |
$q = "UPDATE `#__vikrentcar_config` SET `setting`=".$dbo->quote($pcompany_info)." WHERE `param`='invcompanyinfo';"; |
| 6026 |
$dbo->setQuery($q); |
| 6027 |
$dbo->execute(); |
| 6028 |
// |
| 6029 |
} |
| 6030 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=orders"); |
| 6031 |
} |
| 6032 |
|
| 6033 |
public function loadcronparams() { |
| 6034 |
//to be called via ajax |
| 6035 |
$html = '---------'; |
| 6036 |
$phpfile = VikRequest::getString('phpfile', '', 'request'); |
| 6037 |
if (!empty($phpfile)) { |
| 6038 |
$html = VikRentCar::displayCronParameters($phpfile); |
| 6039 |
} |
| 6040 |
/** |
| 6041 |
* The HTML content is built by an internal method that does not trigger any hook |
| 6042 |
* where third party plugins could interfere. We cannot escape this HTML string, |
| 6043 |
* nor can we convert special chars into HTML entities, as this is the response |
| 6044 |
* of an AJAX request, and the HTML code needs to be displayed accordingly. |
| 6045 |
* If we were to escape the HTML string, then the AJAX response would be useless, |
| 6046 |
* as it would be HTML code converted into text with HTML entities. |
| 6047 |
*/ |
| 6048 |
echo $html; |
| 6049 |
exit; |
| 6050 |
} |
| 6051 |
|
| 6052 |
public function loadpaymentparams() { |
| 6053 |
//to be called via ajax |
| 6054 |
$html = '---------'; |
| 6055 |
$phpfile = VikRequest::getString('phpfile', '', 'request'); |
| 6056 |
if (!empty($phpfile)) { |
| 6057 |
$html = VikRentCar::displayPaymentParameters($phpfile); |
| 6058 |
} |
| 6059 |
/** |
| 6060 |
* The HTML content is built by an internal method that does not trigger any hook |
| 6061 |
* where third party plugins could interfere. We cannot escape this HTML string, |
| 6062 |
* nor can we convert special chars into HTML entities, as this is the response |
| 6063 |
* of an AJAX request, and the HTML code needs to be displayed accordingly. |
| 6064 |
* If we were to escape the HTML string, then the AJAX response would be useless, |
| 6065 |
* as it would be HTML code converted into text with HTML entities. |
| 6066 |
*/ |
| 6067 |
echo $html; |
| 6068 |
exit; |
| 6069 |
} |
| 6070 |
|
| 6071 |
public function translations() { |
| 6072 |
VikRentCarHelper::printHeader("21"); |
| 6073 |
|
| 6074 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'translations')); |
| 6075 |
|
| 6076 |
parent::display(); |
| 6077 |
|
| 6078 |
if (VikRentCar::showFooter()) { |
| 6079 |
VikRentCarHelper::printFooter(); |
| 6080 |
} |
| 6081 |
} |
| 6082 |
|
| 6083 |
public function savetranslation() { |
| 6084 |
if (!JSession::checkToken()) { |
| 6085 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 6086 |
} |
| 6087 |
$this->do_savetranslation(); |
| 6088 |
} |
| 6089 |
|
| 6090 |
public function savetranslationstay() { |
| 6091 |
if (!JSession::checkToken()) { |
| 6092 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 6093 |
} |
| 6094 |
$this->do_savetranslation(true); |
| 6095 |
} |
| 6096 |
|
| 6097 |
private function do_savetranslation($stay = false) { |
| 6098 |
$dbo = JFactory::getDbo(); |
| 6099 |
$mainframe = JFactory::getApplication(); |
| 6100 |
$vrc_tn = VikRentCar::getTranslator(); |
| 6101 |
$table = VikRequest::getString('vrc_table', '', 'request'); |
| 6102 |
$cur_langtab = VikRequest::getString('vrc_lang', '', 'request'); |
| 6103 |
$langs = $vrc_tn->getLanguagesList(); |
| 6104 |
$xml_tables = $vrc_tn->getTranslationTables(); |
| 6105 |
if (!empty($table) && array_key_exists($table, $xml_tables)) { |
| 6106 |
$tn = VikRequest::getVar('tn', array(), 'request', 'array', VIKREQUEST_ALLOWRAW); |
| 6107 |
$tn_saved = 0; |
| 6108 |
$table_cols = $vrc_tn->getTableColumns($table); |
| 6109 |
foreach ($langs as $ltag => $lang) { |
| 6110 |
if ($ltag == $vrc_tn->default_lang) { |
| 6111 |
continue; |
| 6112 |
} |
| 6113 |
if (array_key_exists($ltag, $tn) && count($tn[$ltag]) > 0) { |
| 6114 |
foreach ($tn[$ltag] as $reference_id => $translation) { |
| 6115 |
$lang_translation = array(); |
| 6116 |
foreach ($table_cols as $field => $fdetails) { |
| 6117 |
if (!array_key_exists($field, $translation)) { |
| 6118 |
continue; |
| 6119 |
} |
| 6120 |
$ftype = $fdetails['type']; |
| 6121 |
if ($ftype == 'skip') { |
| 6122 |
continue; |
| 6123 |
} |
| 6124 |
|
| 6125 |
if (is_array($translation[$field])) { |
| 6126 |
foreach ($translation[$field] as $tn_field_k => $tn_field_v) { |
| 6127 |
if (!is_string($tn_field_v)) { |
| 6128 |
continue; |
| 6129 |
} |
| 6130 |
// replace any possible placeholder for special tags |
| 6131 |
$translation[$field][$tn_field_k] = preg_replace_callback("/(<strong class=\"vrc-editor-hl-specialtag\">)([^<]+)(<\/strong>)/", function($match) { |
| 6132 |
return $match[2]; |
| 6133 |
}, $translation[$field][$tn_field_k]); |
| 6134 |
} |
| 6135 |
} elseif (!empty($translation[$field])) { |
| 6136 |
// replace any possible placeholder for special tags |
| 6137 |
$translation[$field] = preg_replace_callback("/(<strong class=\"vrc-editor-hl-specialtag\">)([^<]+)(<\/strong>)/", function($match) { |
| 6138 |
return $match[2]; |
| 6139 |
}, $translation[$field]); |
| 6140 |
} |
| 6141 |
|
| 6142 |
if ($ftype == 'json' && !is_scalar($translation[$field])) { |
| 6143 |
$translation[$field] = json_encode($translation[$field]); |
| 6144 |
} |
| 6145 |
$lang_translation[$field] = $translation[$field]; |
| 6146 |
} |
| 6147 |
if (count($lang_translation) > 0) { |
| 6148 |
$q = "SELECT `id` FROM `#__vikrentcar_translations` WHERE `table`=".$dbo->quote($table)." AND `lang`=".$dbo->quote($ltag)." AND `reference_id`=".$dbo->quote((int)$reference_id).";"; |
| 6149 |
$dbo->setQuery($q); |
| 6150 |
$dbo->execute(); |
| 6151 |
if ($dbo->getNumRows() > 0) { |
| 6152 |
$last_id = $dbo->loadResult(); |
| 6153 |
$q = "UPDATE `#__vikrentcar_translations` SET `content`=".$dbo->quote(json_encode($lang_translation))." WHERE `id`=".(int)$last_id.";"; |
| 6154 |
} else { |
| 6155 |
$q = "INSERT INTO `#__vikrentcar_translations` (`table`,`lang`,`reference_id`,`content`) VALUES (".$dbo->quote($table).", ".$dbo->quote($ltag).", ".$dbo->quote((int)$reference_id).", ".$dbo->quote(json_encode($lang_translation)).");"; |
| 6156 |
} |
| 6157 |
$dbo->setQuery($q); |
| 6158 |
$dbo->execute(); |
| 6159 |
$tn_saved++; |
| 6160 |
} |
| 6161 |
} |
| 6162 |
} |
| 6163 |
} |
| 6164 |
if ($tn_saved > 0) { |
| 6165 |
$mainframe->enqueueMessage(JText::translate('VRCTRANSLSAVEDOK')); |
| 6166 |
} |
| 6167 |
} else { |
| 6168 |
VikError::raiseWarning('', JText::translate('VRCTRANSLATIONERRINVTABLE')); |
| 6169 |
} |
| 6170 |
$mainframe->redirect("index.php?option=com_vikrentcar".($stay ? '&task=translations&vrc_table='.$vrc_tn->replacePrefix($table).'&vrc_lang='.$cur_langtab : '').'&limitstart='.$vrc_tn->lim0.'&limit='.$vrc_tn->lim); |
| 6171 |
} |
| 6172 |
|
| 6173 |
public function sortcategory() { |
| 6174 |
$cid = VikRequest::getVar('cid', array(0)); |
| 6175 |
$sortid = (int)$cid[0]; |
| 6176 |
$pmode = VikRequest::getString('mode', '', 'request'); |
| 6177 |
$dbo = JFactory::getDbo(); |
| 6178 |
$mainframe = JFactory::getApplication(); |
| 6179 |
if (!empty($pmode)) { |
| 6180 |
$q = "SELECT `id`,`ordering` FROM `#__vikrentcar_categories` ORDER BY `#__vikrentcar_categories`.`ordering` ASC;"; |
| 6181 |
$dbo->setQuery($q); |
| 6182 |
$dbo->execute(); |
| 6183 |
$totr=$dbo->getNumRows(); |
| 6184 |
if ($totr > 1) { |
| 6185 |
$data = $dbo->loadAssocList(); |
| 6186 |
if ($pmode == "up") { |
| 6187 |
foreach ($data as $v) { |
| 6188 |
if ($v['id'] == $sortid) { |
| 6189 |
$y = $v['ordering']; |
| 6190 |
} |
| 6191 |
} |
| 6192 |
if ($y && $y > 1) { |
| 6193 |
$vik = $y - 1; |
| 6194 |
$found = false; |
| 6195 |
foreach ($data as $v) { |
| 6196 |
if (intval($v['ordering']) == intval($vik)) { |
| 6197 |
$found = true; |
| 6198 |
$q = "UPDATE `#__vikrentcar_categories` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 6199 |
$dbo->setQuery($q); |
| 6200 |
$dbo->execute(); |
| 6201 |
$q = "UPDATE `#__vikrentcar_categories` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 6202 |
$dbo->setQuery($q); |
| 6203 |
$dbo->execute(); |
| 6204 |
break; |
| 6205 |
} |
| 6206 |
} |
| 6207 |
if (!$found) { |
| 6208 |
$q = "UPDATE `#__vikrentcar_categories` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 6209 |
$dbo->setQuery($q); |
| 6210 |
$dbo->execute(); |
| 6211 |
} |
| 6212 |
} |
| 6213 |
} elseif ($pmode == "down") { |
| 6214 |
foreach ($data as $v) { |
| 6215 |
if ($v['id'] == $sortid[0]) { |
| 6216 |
$y = $v['ordering']; |
| 6217 |
} |
| 6218 |
} |
| 6219 |
if ($y) { |
| 6220 |
$vik = $y + 1; |
| 6221 |
$found = false; |
| 6222 |
foreach ($data as $v) { |
| 6223 |
if (intval($v['ordering']) == intval($vik)) { |
| 6224 |
$found = true; |
| 6225 |
$q = "UPDATE `#__vikrentcar_categories` SET `ordering`='".$y."' WHERE `id`='".$v['id']."' LIMIT 1;"; |
| 6226 |
$dbo->setQuery($q); |
| 6227 |
$dbo->execute(); |
| 6228 |
$q = "UPDATE `#__vikrentcar_categories` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 6229 |
$dbo->setQuery($q); |
| 6230 |
$dbo->execute(); |
| 6231 |
break; |
| 6232 |
} |
| 6233 |
} |
| 6234 |
if (!$found) { |
| 6235 |
$q = "UPDATE `#__vikrentcar_categories` SET `ordering`='".$vik."' WHERE `id`='".$sortid."' LIMIT 1;"; |
| 6236 |
$dbo->setQuery($q); |
| 6237 |
$dbo->execute(); |
| 6238 |
} |
| 6239 |
} |
| 6240 |
} |
| 6241 |
} |
| 6242 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=categories"); |
| 6243 |
} else { |
| 6244 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 6245 |
} |
| 6246 |
} |
| 6247 |
|
| 6248 |
public function edittmplfile() { |
| 6249 |
//modal box, so we do not set menu or footer |
| 6250 |
|
| 6251 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'edittmplfile')); |
| 6252 |
|
| 6253 |
parent::display(); |
| 6254 |
} |
| 6255 |
|
| 6256 |
public function tmplfileprew() { |
| 6257 |
//modal box, so we do not set menu or footer |
| 6258 |
|
| 6259 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'tmplfileprew')); |
| 6260 |
|
| 6261 |
parent::display(); |
| 6262 |
} |
| 6263 |
|
| 6264 |
public function savetmplfile() { |
| 6265 |
if (!JSession::checkToken()) { |
| 6266 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 6267 |
} |
| 6268 |
$fpath = VikRequest::getString('path', '', 'request', VIKREQUEST_ALLOWRAW); |
| 6269 |
$pcont = VikRequest::getString('cont', '', 'request', VIKREQUEST_ALLOWRAW); |
| 6270 |
$mainframe = JFactory::getApplication(); |
| 6271 |
$exists = file_exists($fpath) ? true : false; |
| 6272 |
if (!$exists) { |
| 6273 |
$fpath = urldecode($fpath); |
| 6274 |
} |
| 6275 |
$fpath = file_exists($fpath) ? $fpath : ''; |
| 6276 |
if (!empty($fpath)) { |
| 6277 |
$fp = fopen($fpath, 'wb'); |
| 6278 |
$byt = (int)fwrite($fp, $pcont); |
| 6279 |
fclose($fp); |
| 6280 |
if ($byt > 0) { |
| 6281 |
$mainframe->enqueueMessage(JText::translate('VRCUPDTMPLFILEOK')); |
| 6282 |
/** |
| 6283 |
* @wponly call the UpdateManager Class to temporary store modifications made to template files |
| 6284 |
*/ |
| 6285 |
VikRentCarUpdateManager::storeTemplateContent($fpath, $pcont); |
| 6286 |
// |
| 6287 |
} else { |
| 6288 |
VikError::raiseWarning('', JText::translate('VRCUPDTMPLFILENOBYTES')); |
| 6289 |
} |
| 6290 |
} else { |
| 6291 |
VikError::raiseWarning('', JText::translate('VRCUPDTMPLFILEERR')); |
| 6292 |
} |
| 6293 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=edittmplfile&path=".$fpath."&tmpl=component"); |
| 6294 |
|
| 6295 |
exit; |
| 6296 |
} |
| 6297 |
|
| 6298 |
public function unlockrecords() { |
| 6299 |
$ids = VikRequest::getVar('cid', array(0)); |
| 6300 |
if (@count($ids)) { |
| 6301 |
$dbo = JFactory::getDbo(); |
| 6302 |
foreach ($ids as $d) { |
| 6303 |
$q = "DELETE FROM `#__vikrentcar_tmplock` WHERE `id`=".$dbo->quote($d).";"; |
| 6304 |
$dbo->setQuery($q); |
| 6305 |
$dbo->execute(); |
| 6306 |
} |
| 6307 |
} |
| 6308 |
$mainframe = JFactory::getApplication(); |
| 6309 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 6310 |
} |
| 6311 |
|
| 6312 |
public function graphs() { |
| 6313 |
VikRentCarHelper::printHeader("22"); |
| 6314 |
|
| 6315 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'graphs')); |
| 6316 |
|
| 6317 |
parent::display(); |
| 6318 |
|
| 6319 |
if (VikRentCar::showFooter()) { |
| 6320 |
VikRentCarHelper::printFooter(); |
| 6321 |
} |
| 6322 |
} |
| 6323 |
|
| 6324 |
public function choosebusy() { |
| 6325 |
VikRentCarHelper::printHeader("8"); |
| 6326 |
|
| 6327 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'choosebusy')); |
| 6328 |
|
| 6329 |
parent::display(); |
| 6330 |
|
| 6331 |
if (VikRentCar::showFooter()) { |
| 6332 |
VikRentCarHelper::printFooter(); |
| 6333 |
} |
| 6334 |
} |
| 6335 |
|
| 6336 |
public function orders() { |
| 6337 |
VikRentCarHelper::printHeader("8"); |
| 6338 |
|
| 6339 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'orders')); |
| 6340 |
|
| 6341 |
parent::display(); |
| 6342 |
|
| 6343 |
if (VikRentCar::showFooter()) { |
| 6344 |
VikRentCarHelper::printFooter(); |
| 6345 |
} |
| 6346 |
} |
| 6347 |
|
| 6348 |
public function removeorders() { |
| 6349 |
if (!JSession::checkToken()) { |
| 6350 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 6351 |
} |
| 6352 |
$dbo = JFactory::getDbo(); |
| 6353 |
$mainframe = JFactory::getApplication(); |
| 6354 |
$ids = VikRequest::getVar('cid', array(0)); |
| 6355 |
if (is_array($ids) && count($ids)) { |
| 6356 |
foreach ($ids as $d) { |
| 6357 |
$q = "SELECT `o`.*,`b`.`stop_sales` FROM `#__vikrentcar_orders` AS `o` LEFT JOIN `#__vikrentcar_busy` `b` ON `b`.`id`=`o`.`idbusy` WHERE `o`.`id`=".$dbo->quote((int)$d).";"; |
| 6358 |
$dbo->setQuery($q); |
| 6359 |
$dbo->execute(); |
| 6360 |
if ($dbo->getNumRows() == 1) { |
| 6361 |
$rows = $dbo->loadAssocList(); |
| 6362 |
if (!empty($rows[0]['idbusy'])) { |
| 6363 |
$q = "DELETE FROM `#__vikrentcar_busy` WHERE `id`=" . (int)$rows[0]['idbusy'] . ";"; |
| 6364 |
$dbo->setQuery($q); |
| 6365 |
$dbo->execute(); |
| 6366 |
} |
| 6367 |
$q = "DELETE FROM `#__vikrentcar_tmplock` WHERE `idorder`=" . (int)$rows[0]['id'] . ";"; |
| 6368 |
$dbo->setQuery($q); |
| 6369 |
$dbo->execute(); |
| 6370 |
if ($rows[0]['status'] == 'cancelled') { |
| 6371 |
$q = "DELETE FROM `#__vikrentcar_customers_orders` WHERE `idorder`=" . (int)$rows[0]['id'] . ";"; |
| 6372 |
$dbo->setQuery($q); |
| 6373 |
$dbo->execute(); |
| 6374 |
$q = "DELETE FROM `#__vikrentcar_orders` WHERE `id`=" . (int)$rows[0]['id'] . ";"; |
| 6375 |
$dbo->setQuery($q); |
| 6376 |
$dbo->execute(); |
| 6377 |
$q = "DELETE FROM `#__vikrentcar_orderhistory` WHERE `idorder`=" . (int)$rows[0]['id'] . ";"; |
| 6378 |
$dbo->setQuery($q); |
| 6379 |
$dbo->execute(); |
| 6380 |
} else { |
| 6381 |
$q = "UPDATE `#__vikrentcar_orders` SET `idbusy`=NULL,`status`='cancelled' WHERE `id`=" . (int)$rows[0]['id'] . ";"; |
| 6382 |
$dbo->setQuery($q); |
| 6383 |
$dbo->execute(); |
| 6384 |
// Booking History |
| 6385 |
VikRentCar::getOrderHistoryInstance()->setBid($rows[0]['id'])->store('CB'); |
| 6386 |
// |
| 6387 |
} |
| 6388 |
} |
| 6389 |
} |
| 6390 |
$mainframe->enqueueMessage(JText::translate('VRMESSDELBUSY')); |
| 6391 |
} |
| 6392 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=orders"); |
| 6393 |
} |
| 6394 |
|
| 6395 |
public function canceledorder() { |
| 6396 |
$pgoto = VikRequest::getString('goto', '', 'request', VIKREQUEST_ALLOWRAW); |
| 6397 |
$mainframe = JFactory::getApplication(); |
| 6398 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=".($pgoto == 'overv' ? 'overv' : 'orders')); |
| 6399 |
} |
| 6400 |
|
| 6401 |
public function removebusy() { |
| 6402 |
$mainframe = JFactory::getApplication(); |
| 6403 |
$pidbusy = VikRequest::getInt('idbusy', '', 'request'); |
| 6404 |
$pidorder = VikRequest::getInt('idorder', '', 'request'); |
| 6405 |
$pidcar = VikRequest::getString('idcar', '', 'request'); |
| 6406 |
$pgoto = VikRequest::getString('goto', '', 'request', VIKREQUEST_ALLOWRAW); |
| 6407 |
$preturn = VikRequest::getString('return', '', 'request'); |
| 6408 |
if (!empty($pidorder) && !empty($pidcar)) { |
| 6409 |
$dbo = JFactory::getDbo(); |
| 6410 |
$q = "SELECT `o`.*,`b`.`stop_sales` FROM `#__vikrentcar_orders` AS `o` LEFT JOIN `#__vikrentcar_busy` `b` ON `b`.`id`=`o`.`idbusy` WHERE `o`.`id`=".$dbo->quote($pidorder).";"; |
| 6411 |
$dbo->setQuery($q); |
| 6412 |
$dbo->execute(); |
| 6413 |
if ($dbo->getNumRows() == 1) { |
| 6414 |
$ord = $dbo->loadAssocList(); |
| 6415 |
$q = "DELETE FROM `#__vikrentcar_tmplock` WHERE `idorder`=" . (int)$ord[0]['id'] . ";"; |
| 6416 |
$dbo->setQuery($q); |
| 6417 |
$dbo->execute(); |
| 6418 |
if ($ord[0]['status'] == 'cancelled') { |
| 6419 |
$q = "DELETE FROM `#__vikrentcar_customers_orders` WHERE `idorder`=" . (int)$ord[0]['id'] . ";"; |
| 6420 |
$dbo->setQuery($q); |
| 6421 |
$dbo->execute(); |
| 6422 |
$q = "DELETE FROM `#__vikrentcar_orders` WHERE `id`=" . (int)$ord[0]['id'] . " LIMIT 1;"; |
| 6423 |
$dbo->setQuery($q); |
| 6424 |
$dbo->execute(); |
| 6425 |
$q = "DELETE FROM `#__vikrentcar_orderhistory` WHERE `idorder`=" . (int)$ord[0]['id'] . ";"; |
| 6426 |
$dbo->setQuery($q); |
| 6427 |
$dbo->execute(); |
| 6428 |
} else { |
| 6429 |
$q = "UPDATE `#__vikrentcar_orders` SET `idbusy`=NULL,`status`='cancelled' WHERE `id`=" . (int)$ord[0]['id'] . ";"; |
| 6430 |
$dbo->setQuery($q); |
| 6431 |
$dbo->execute(); |
| 6432 |
// Booking History |
| 6433 |
VikRentCar::getOrderHistoryInstance()->setBid($ord[0]['id'])->store('CB'); |
| 6434 |
// |
| 6435 |
} |
| 6436 |
$mainframe->enqueueMessage(JText::translate('VRMESSDELBUSY')); |
| 6437 |
/** |
| 6438 |
* Make sure to free up the vehicle in the previously booked dates. |
| 6439 |
* In case the busy ID is not passed in the request, we force it. |
| 6440 |
* |
| 6441 |
* @since 1.2.0 |
| 6442 |
*/ |
| 6443 |
if (!empty($ord[0]['idbusy'])) { |
| 6444 |
// no matter what, this is the busy record that must be removed |
| 6445 |
$pidbusy = (int)$ord[0]['idbusy']; |
| 6446 |
} |
| 6447 |
} |
| 6448 |
if (!empty($pidbusy)) { |
| 6449 |
$q = "DELETE FROM `#__vikrentcar_busy` WHERE `id`=".$dbo->quote($pidbusy)." LIMIT 1;"; |
| 6450 |
$dbo->setQuery($q); |
| 6451 |
$dbo->execute(); |
| 6452 |
} |
| 6453 |
} |
| 6454 |
if ($preturn == 'order' && $ord[0]['status'] != 'cancelled') { |
| 6455 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=".$pidorder); |
| 6456 |
} else { |
| 6457 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=".($pgoto == 'overv' ? 'overv' : 'orders')); |
| 6458 |
} |
| 6459 |
} |
| 6460 |
|
| 6461 |
public function updatebusy() { |
| 6462 |
$mainframe = JFactory::getApplication(); |
| 6463 |
$pidbusy = VikRequest::getString('idbusy', '', 'request'); |
| 6464 |
$pidorder = VikRequest::getInt('idorder', '', 'request'); |
| 6465 |
$preturn = VikRequest::getString('return', '', 'request'); |
| 6466 |
$porder_total = VikRequest::getString('order_total', '', 'request'); |
| 6467 |
$pnewidcar = VikRequest::getInt('newidcar', '', 'request'); |
| 6468 |
$pidplace = VikRequest::getInt('idplace', '', 'request'); |
| 6469 |
$pidreturnplace = VikRequest::getInt('idreturnplace', '', 'request'); |
| 6470 |
$ppickupdate = VikRequest::getString('pickupdate', '', 'request'); |
| 6471 |
$preleasedate = VikRequest::getString('releasedate', '', 'request'); |
| 6472 |
$ppickuph = VikRequest::getString('pickuph', '', 'request'); |
| 6473 |
$ppickupm = VikRequest::getString('pickupm', '', 'request'); |
| 6474 |
$preleaseh = VikRequest::getString('releaseh', '', 'request'); |
| 6475 |
$preleasem = VikRequest::getString('releasem', '', 'request'); |
| 6476 |
$pidcar = VikRequest::getString('idcar', '', 'request'); |
| 6477 |
$origidcar = $pidcar; |
| 6478 |
if (!empty($pnewidcar) && $pnewidcar > 0) { |
| 6479 |
$pidcar = $pnewidcar; |
| 6480 |
} |
| 6481 |
$pcustdata = VikRequest::getString('custdata', '', 'request'); |
| 6482 |
$pareprices = VikRequest::getString('areprices', '', 'request'); |
| 6483 |
$ppriceid = VikRequest::getInt('priceid', '', 'request'); |
| 6484 |
$ptotpaid = VikRequest::getString('totpaid', '', 'request'); |
| 6485 |
//VikRentCar 1.7 |
| 6486 |
$pstandbyquick = VikRequest::getString('standbyquick', '', 'request'); |
| 6487 |
$pstandbyquick = $pstandbyquick == "1" ? 1 : 0; |
| 6488 |
$pnotifycust = VikRequest::getString('notifycust', '', 'request'); |
| 6489 |
$pnotifycust = $pnotifycust == "1" ? 1 : 0; |
| 6490 |
// |
| 6491 |
$pcust_cost = VikRequest::getFloat('cust_cost', '', 'request'); |
| 6492 |
$paliq = VikRequest::getInt('aliq', '', 'request'); |
| 6493 |
$pextracn = VikRequest::getVar('extracn', array()); |
| 6494 |
$pextracc = VikRequest::getVar('extracc', array()); |
| 6495 |
$pextractx = VikRequest::getVar('extractx', array()); |
| 6496 |
$isdue = 0; |
| 6497 |
$tot_taxes = 0; |
| 6498 |
$dbo = JFactory::getDbo(); |
| 6499 |
$actnow = time(); |
| 6500 |
$nowdf = VikRentCar::getDateFormat(true); |
| 6501 |
if ($nowdf == "%d/%m/%Y") { |
| 6502 |
$df = 'd/m/Y'; |
| 6503 |
} elseif ($nowdf == "%m/%d/%Y") { |
| 6504 |
$df = 'm/d/Y'; |
| 6505 |
} else { |
| 6506 |
$df = 'Y/m/d'; |
| 6507 |
} |
| 6508 |
if (!empty($pidorder)) { |
| 6509 |
$first = VikRentCar::getDateTimestamp($ppickupdate, $ppickuph, $ppickupm); |
| 6510 |
$second = VikRentCar::getDateTimestamp($preleasedate, $preleaseh, $preleasem); |
| 6511 |
if ($second > $first) { |
| 6512 |
$q = "SELECT `units` FROM `#__vikrentcar_cars` WHERE `id`=".$dbo->quote($pidcar).";"; |
| 6513 |
$dbo->setQuery($q); |
| 6514 |
$dbo->execute(); |
| 6515 |
$units = $dbo->loadResult(); |
| 6516 |
//vikrentcar 1.5 |
| 6517 |
$checkhourly = false; |
| 6518 |
$checkhourscharges = 0; |
| 6519 |
$hoursdiff = 0; |
| 6520 |
$secdiff = $second - $first; |
| 6521 |
$daysdiff = $secdiff / 86400; |
| 6522 |
if (is_int($daysdiff)) { |
| 6523 |
if ($daysdiff < 1) { |
| 6524 |
$daysdiff = 1; |
| 6525 |
} |
| 6526 |
} else { |
| 6527 |
if ($daysdiff < 1) { |
| 6528 |
$daysdiff = 1; |
| 6529 |
$checkhourly = true; |
| 6530 |
$ophours = $secdiff / 3600; |
| 6531 |
$hoursdiff = intval(round($ophours)); |
| 6532 |
if ($hoursdiff < 1) { |
| 6533 |
$hoursdiff = 1; |
| 6534 |
} |
| 6535 |
} else { |
| 6536 |
$sum = floor($daysdiff) * 86400; |
| 6537 |
$newdiff = $secdiff - $sum; |
| 6538 |
$maxhmore = VikRentCar::getHoursMoreRb() * 3600; |
| 6539 |
if ($maxhmore >= $newdiff) { |
| 6540 |
$daysdiff = floor($daysdiff); |
| 6541 |
} else { |
| 6542 |
$daysdiff = ceil($daysdiff); |
| 6543 |
/** |
| 6544 |
* Apply proper rounding with gratuity period. |
| 6545 |
* |
| 6546 |
* @since 1.15.1 (J) - 1.3.2 (WP) |
| 6547 |
* @since 1.15.8 (J) - 1.4.5 (WP) |
| 6548 |
*/ |
| 6549 |
$ehours_float = ($newdiff - $maxhmore) / 3600; |
| 6550 |
$ehours = intval(ceil($ehours_float)); |
| 6551 |
$ehours = !$ehours && $ehours_float > 0 && $maxhmore > 0 ? 1 : $ehours; |
| 6552 |
$checkhourscharges = $ehours; |
| 6553 |
if ($checkhourscharges > 0) { |
| 6554 |
$aehourschbasp = VikRentCar::applyExtraHoursChargesBasp(); |
| 6555 |
} |
| 6556 |
} |
| 6557 |
|
| 6558 |
} |
| 6559 |
} |
| 6560 |
|
| 6561 |
/** |
| 6562 |
* We allow the administrator to force the update of a rental order |
| 6563 |
* even if the car is fully booked or locked in the new dates. |
| 6564 |
* |
| 6565 |
* @since 1.14.5 (J) - 1.2.0 (WP) |
| 6566 |
*/ |
| 6567 |
$pforce_availability = VikRequest::getInt('force_av', 0, 'request'); |
| 6568 |
$forced_availability = false; |
| 6569 |
$history_descr = ''; |
| 6570 |
|
| 6571 |
$opertwounits = true; |
| 6572 |
$check = "SELECT `b`.`id`,`b`.`ritiro`,`b`.`consegna`,`b`.`realback`,`b`.`stop_sales`,`o`.`id` AS `idorder` |
| 6573 |
FROM `#__vikrentcar_busy` AS `b` |
| 6574 |
LEFT JOIN `#__vikrentcar_orders` AS `o` ON `o`.`idbusy`=`b`.`id` |
| 6575 |
WHERE `b`.`idcar`=" . (int)$pidcar . " AND `b`.`id`!=" . $dbo->quote($pidbusy) . " AND `b`.`realback` >= " . $first . " |
| 6576 |
ORDER BY `b`.`ritiro` ASC;"; |
| 6577 |
$dbo->setQuery($check); |
| 6578 |
$busy = $dbo->loadAssocList(); |
| 6579 |
if ($busy) { |
| 6580 |
$opertwounits = VikRentCar::carBookable($pidcar, $units, $first, $second, $busy); |
| 6581 |
} |
| 6582 |
// |
| 6583 |
$is_car_locked = !VikRentCar::carNotLocked($pidcar, $units, $first, $second); |
| 6584 |
if ($pforce_availability || !$is_car_locked) { |
| 6585 |
// car is not temporarily locked, or forced availability |
| 6586 |
if ($is_car_locked && $pforce_availability) { |
| 6587 |
// turn flag on |
| 6588 |
$forced_availability = true; |
| 6589 |
$history_descr = "\n" . JText::translate('VRCAVAILABILITYFORCED'); |
| 6590 |
} |
| 6591 |
if ($pforce_availability || $opertwounits) { |
| 6592 |
// car is not fully booked, or forced availability |
| 6593 |
if (!$opertwounits && $pforce_availability) { |
| 6594 |
// turn flag on |
| 6595 |
$forced_availability = true; |
| 6596 |
$history_descr = "\n" . JText::translate('VRCAVAILABILITYFORCED'); |
| 6597 |
} |
| 6598 |
$doup = false; |
| 6599 |
//vikrentcar 1.5 |
| 6600 |
if ($checkhourly) { |
| 6601 |
$q = "SELECT * FROM `#__vikrentcar_dispcosthours` WHERE `idcar`=" . (int)$pidcar . " AND `hours`=" . (int)$hoursdiff . " AND `idprice`=" . (int)$ppriceid . ";"; |
| 6602 |
} else { |
| 6603 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `idcar`=" . (int)$pidcar . " AND `days`=" . (int)$daysdiff . " AND `idprice`=" . (int)$ppriceid . ";"; |
| 6604 |
} |
| 6605 |
// |
| 6606 |
$dbo->setQuery($q); |
| 6607 |
$dbo->execute(); |
| 6608 |
if ($dbo->getNumRows() == 1) { |
| 6609 |
$dispcost = $dbo->loadAssocList(); |
| 6610 |
//vikrentcar 1.5 |
| 6611 |
if ($checkhourly) { |
| 6612 |
foreach ($dispcost as $kt => $vt) { |
| 6613 |
$dispcost[$kt]['days'] = 1; |
| 6614 |
} |
| 6615 |
} |
| 6616 |
$doup = true; |
| 6617 |
} else { |
| 6618 |
//there are no hourly prices |
| 6619 |
if ($checkhourly) { |
| 6620 |
$q = "SELECT * FROM `#__vikrentcar_dispcost` WHERE `idcar`=" . (int)$pidcar . " AND `days`=" . (int)$daysdiff . " AND `idprice`=" . (int)$ppriceid . ";"; |
| 6621 |
$dbo->setQuery($q); |
| 6622 |
$dbo->execute(); |
| 6623 |
if ($dbo->getNumRows() == 1) { |
| 6624 |
$dispcost = $dbo->loadAssocList(); |
| 6625 |
$doup = true; |
| 6626 |
} |
| 6627 |
} |
| 6628 |
} |
| 6629 |
if (isset($dispcost) && is_array($dispcost) && $checkhourscharges > 0 && $aehourschbasp === true) { |
| 6630 |
$dispcost = VikRentCar::applyExtraHoursChargesCar($dispcost, $pidcar, $checkhourscharges, $daysdiff); |
| 6631 |
} |
| 6632 |
//VRC 1.11 Custom Rate |
| 6633 |
$set_custom_rate = 0; |
| 6634 |
if (!$doup && empty($ppriceid) && !empty($pcust_cost) && floatval($pcust_cost) > 0) { |
| 6635 |
$doup = true; |
| 6636 |
$set_custom_rate = $pcust_cost; |
| 6637 |
} |
| 6638 |
// |
| 6639 |
if ($doup === true || intval($pidcar) != intval($origidcar)) { |
| 6640 |
$realback = VikRentCar::getHoursCarAvail() * 3600; |
| 6641 |
$realback += $second; |
| 6642 |
if (!empty($pidbusy)) { |
| 6643 |
$q = "UPDATE `#__vikrentcar_busy` SET `idcar`=".(int)$pidcar.",`ritiro`='".$first."', `consegna`='".$second."', `realback`='".$realback."' WHERE `id`=".$dbo->quote($pidbusy).";"; |
| 6644 |
$dbo->setQuery($q); |
| 6645 |
$dbo->execute(); |
| 6646 |
} |
| 6647 |
$q = "SELECT * FROM `#__vikrentcar_orders` WHERE `id`=" . (int)$pidorder . ";"; |
| 6648 |
$dbo->setQuery($q); |
| 6649 |
$dbo->execute(); |
| 6650 |
if ($dbo->getNumRows() != 1) { |
| 6651 |
throw new Exception("Order not found", 404); |
| 6652 |
|
| 6653 |
} |
| 6654 |
$orderdata = $dbo->loadAssocList(); |
| 6655 |
$qfinal_args = array(); |
| 6656 |
$qfinal_args['custdata'] = $pcustdata; |
| 6657 |
$qfinal_args['idcar'] = (int)$pidcar; |
| 6658 |
// we do not use $daysdiff due to the extra hours charges that may override the duration |
| 6659 |
$qfinal_args['days'] = isset($dispcost) ? (int)$dispcost[0]['days'] : $daysdiff; |
| 6660 |
// |
| 6661 |
$qfinal_args['ritiro'] = (int)$first; |
| 6662 |
$qfinal_args['consegna'] = (int)$second; |
| 6663 |
if (is_array($dispcost) && $doup === true && empty($set_custom_rate)) { |
| 6664 |
$qfinal_args['idtar'] = (int)$dispcost[0]['id']; |
| 6665 |
$qfinal_args['cust_cost'] = null; |
| 6666 |
$qfinal_args['cust_idiva'] = null; |
| 6667 |
if ($checkhourscharges > 0 && $aehourschbasp === false) { |
| 6668 |
$dispcost = VikRentCar::extraHoursSetPreviousFareCar($dispcost, $pidcar, $checkhourscharges, $daysdiff); |
| 6669 |
$dispcost = VikRentCar::applySeasonsCar($dispcost, $first, $second, $pidplace); |
| 6670 |
$dispcost = VikRentCar::applyExtraHoursChargesCar($dispcost, $pidcar, $checkhourscharges, $daysdiff, true); |
| 6671 |
// update the days of rental |
| 6672 |
$qfinal_args['days'] = (int)$dispcost[0]['days']; |
| 6673 |
} else { |
| 6674 |
$dispcost = VikRentCar::applySeasonsCar($dispcost, $first, $second, $pidplace); |
| 6675 |
} |
| 6676 |
$cost_with = VikRentCar::sayCostPlusIva($dispcost[0]['cost'], $dispcost[0]['idprice']); |
| 6677 |
$cost_net = VikRentCar::sayCostMinusIva($dispcost[0]['cost'], $dispcost[0]['idprice']); |
| 6678 |
$isdue += $cost_with; |
| 6679 |
$tot_taxes += $cost_with - $cost_net; |
| 6680 |
} elseif ($set_custom_rate > 0) { |
| 6681 |
$qfinal_args['idtar'] = null; |
| 6682 |
$qfinal_args['cust_cost'] = $set_custom_rate; |
| 6683 |
if (!empty($paliq)) { |
| 6684 |
$qfinal_args['cust_idiva'] = (int)$paliq; |
| 6685 |
} |
| 6686 |
$cust_plus_tax = VikRentCar::sayCustCostPlusIva($set_custom_rate, (int)$paliq); |
| 6687 |
$isdue += $cust_plus_tax; |
| 6688 |
$cust_net = VikRentCar::sayCustCostMinusIva($set_custom_rate, (int)$paliq); |
| 6689 |
$tot_taxes += ($cust_plus_tax - $cust_net); |
| 6690 |
} elseif ($doup === false) { |
| 6691 |
$qfinal_args['idtar'] = null; |
| 6692 |
if (intval($pidcar) != intval($origidcar)) { |
| 6693 |
VikError::raiseNotice('', JText::translate('VRCUPDBUSYCARSWITCHED')); |
| 6694 |
} |
| 6695 |
} |
| 6696 |
// we update $daysdiff with the nwely calculated days from the tariffs |
| 6697 |
$daysdiff = isset($dispcost) ? (int)$dispcost[0]['days'] : $daysdiff; |
| 6698 |
// |
| 6699 |
$q = "SELECT * FROM `#__vikrentcar_optionals`;"; |
| 6700 |
$dbo->setQuery($q); |
| 6701 |
$dbo->execute(); |
| 6702 |
if ($dbo->getNumRows() > 0) { |
| 6703 |
$toptionals = $dbo->loadAssocList(); |
| 6704 |
$wop = ''; |
| 6705 |
foreach ($toptionals as $opt) { |
| 6706 |
$tmpvar = VikRequest::getString('optid'.$opt['id'], '', 'request'); |
| 6707 |
if (!empty($tmpvar)) { |
| 6708 |
$wop .= $opt['id'].":".$tmpvar.";"; |
| 6709 |
$realcost = intval($opt['perday']) == 1 ? ($opt['cost'] * $daysdiff * $tmpvar) : ($opt['cost'] * $tmpvar); |
| 6710 |
$basequancost = intval($opt['perday']) == 1 ? ($opt['cost'] * $daysdiff) : $opt['cost']; |
| 6711 |
if (!empty($opt['maxprice']) && $opt['maxprice'] > 0 && $basequancost > $opt['maxprice']) { |
| 6712 |
$realcost = $opt['maxprice']; |
| 6713 |
if (intval($opt['hmany']) == 1 && intval($tmpvar) > 1) { |
| 6714 |
$realcost = $opt['maxprice'] * $tmpvar; |
| 6715 |
} |
| 6716 |
} |
| 6717 |
$opt_with = VikRentCar::sayOptionalsPlusIva($realcost, $opt['idiva']); |
| 6718 |
$opt_without = VikRentCar::sayOptionalsMinusIva($realcost, $opt['idiva']); |
| 6719 |
$isdue += $opt_with; |
| 6720 |
$tot_taxes += ($opt_with - $opt_without); |
| 6721 |
} |
| 6722 |
} |
| 6723 |
$qfinal_args['optionals'] = $wop; |
| 6724 |
} |
| 6725 |
if ($pidplace != $orderdata[0]['idplace']) { |
| 6726 |
$qfinal_args['idplace'] = $pidplace; |
| 6727 |
} |
| 6728 |
if ($pidreturnplace != $orderdata[0]['idreturnplace']) { |
| 6729 |
$qfinal_args['idreturnplace'] = $pidreturnplace; |
| 6730 |
} |
| 6731 |
if (strlen($ptotpaid) > 0) { |
| 6732 |
$qfinal_args['totpaid'] = floatval($ptotpaid); |
| 6733 |
} else { |
| 6734 |
$qfinal_args['totpaid'] = null; |
| 6735 |
} |
| 6736 |
//calculate the extra costs and increase taxes + isdue |
| 6737 |
$extracosts_arr = array(); |
| 6738 |
if (count($pextracn) > 0) { |
| 6739 |
foreach ($pextracn as $eck => $ecn) { |
| 6740 |
if (strlen($ecn) > 0 && array_key_exists($eck, $pextracc) && floatval($pextracc[$eck]) >= 0.00) { |
| 6741 |
$ecidtax = array_key_exists($eck, $pextractx) && intval($pextractx[$eck]) > 0 ? (int)$pextractx[$eck] : ''; |
| 6742 |
$extracosts_arr[] = array('name' => $ecn, 'cost' => (float)$pextracc[$eck], 'idtax' => $ecidtax); |
| 6743 |
$ecplustax = !empty($ecidtax) ? VikRentCar::sayOptionalsPlusIva((float)$pextracc[$eck], $ecidtax, $orderdata[0]) : (float)$pextracc[$eck]; |
| 6744 |
$ecminustax = !empty($ecidtax) ? VikRentCar::sayOptionalsMinusIva((float)$pextracc[$eck], $ecidtax, $orderdata[0]) : (float)$pextracc[$eck]; |
| 6745 |
$isdue += $ecplustax; |
| 6746 |
$tot_taxes += ($ecplustax - $ecminustax); |
| 6747 |
} |
| 6748 |
} |
| 6749 |
} |
| 6750 |
if (count($extracosts_arr) > 0) { |
| 6751 |
$qfinal_args['extracosts'] = json_encode($extracosts_arr); |
| 6752 |
} else { |
| 6753 |
$qfinal_args['extracosts'] = null; |
| 6754 |
} |
| 6755 |
//end extra costs |
| 6756 |
|
| 6757 |
/** |
| 6758 |
* We are now calculating automatically also the location and out-of-hours fees. |
| 6759 |
* |
| 6760 |
* |
| 6761 |
* @since 1.1.0 |
| 6762 |
*/ |
| 6763 |
// location fees |
| 6764 |
if (!empty($pidplace) && !empty($pidreturnplace)) { |
| 6765 |
$locfee = VikRentCar::getLocFee($pidplace, $pidreturnplace); |
| 6766 |
if ($locfee) { |
| 6767 |
// location fees overrides |
| 6768 |
if (strlen($locfee['losoverride']) > 0) { |
| 6769 |
$arrvaloverrides = array(); |
| 6770 |
$valovrparts = explode('_', $locfee['losoverride']); |
| 6771 |
foreach ($valovrparts as $valovr) { |
| 6772 |
if (!empty($valovr)) { |
| 6773 |
$ovrinfo = explode(':', $valovr); |
| 6774 |
$arrvaloverrides[(int)$ovrinfo[0]] = $ovrinfo[1]; |
| 6775 |
} |
| 6776 |
} |
| 6777 |
if (array_key_exists((int)$daysdiff, $arrvaloverrides)) { |
| 6778 |
$locfee['cost'] = $arrvaloverrides[$daysdiff]; |
| 6779 |
} |
| 6780 |
} |
| 6781 |
// end location fees overrides |
| 6782 |
$locfeecost = intval($locfee['daily']) == 1 ? ($locfee['cost'] * $daysdiff) : $locfee['cost']; |
| 6783 |
$locfeewith = VikRentCar::sayLocFeePlusIva($locfeecost, $locfee['idiva']); |
| 6784 |
$locfeewithout = VikRentCar::sayLocFeeMinusIva($locfeecost, $locfee['idiva']); |
| 6785 |
$isdue += $locfeewith; |
| 6786 |
$tot_taxes += ($locfeewith - $locfeewithout); |
| 6787 |
} |
| 6788 |
} |
| 6789 |
// out of hours fees |
| 6790 |
$oohfee = VikRentCar::getOutOfHoursFees($pidplace, $pidreturnplace, $first, $second, array('id' => (int)$pidcar)); |
| 6791 |
if (count($oohfee)) { |
| 6792 |
$oohfeewith = VikRentCar::sayOohFeePlusIva($oohfee['cost'], $oohfee['idiva']); |
| 6793 |
$oohfeewithout = VikRentCar::sayOohFeeMinusIva($oohfee['cost'], $oohfee['idiva']); |
| 6794 |
$isdue += $oohfeewith; |
| 6795 |
$tot_taxes += ($oohfeewith - $oohfeewithout); |
| 6796 |
} |
| 6797 |
// |
| 6798 |
|
| 6799 |
if (strlen($porder_total) > 0) { |
| 6800 |
// the order total amount can be forced manually to a specific value |
| 6801 |
$qfinal_args['order_total'] = floatval($porder_total); |
| 6802 |
} elseif ($isdue > 0) { |
| 6803 |
// VRC 1.12 if no order total specified, update it to what the value would be at today's date |
| 6804 |
$qfinal_args['order_total'] = floatval($isdue); |
| 6805 |
} |
| 6806 |
|
| 6807 |
/** |
| 6808 |
* Make sure to update the total amount of taxes. |
| 6809 |
* |
| 6810 |
* @since 1.1.0 |
| 6811 |
*/ |
| 6812 |
$qfinal_args['tot_taxes'] = floatval($tot_taxes); |
| 6813 |
// |
| 6814 |
|
| 6815 |
$order_record = (object)$qfinal_args; |
| 6816 |
$order_record->id = (int)$orderdata[0]['id']; |
| 6817 |
$dbo->updateObject('#__vikrentcar_orders', $order_record, 'id', true); |
| 6818 |
|
| 6819 |
// Booking History |
| 6820 |
$user = JFactory::getUser(); |
| 6821 |
VikRentCar::getOrderHistoryInstance()->setBid($orderdata[0]['id'])->store('MB', "({$user->name}) " . VikRentCar::getLogBookingModification($orderdata[0]) . $history_descr); |
| 6822 |
// |
| 6823 |
|
| 6824 |
$mainframe->enqueueMessage(JText::translate('RESUPDATED')); |
| 6825 |
//VikRentCar 1.7 |
| 6826 |
if ($pstandbyquick == 1 && !empty($pidbusy)) { |
| 6827 |
//remove busy because this is an order from quick reservation with standby status |
| 6828 |
$q = "DELETE FROM `#__vikrentcar_busy` WHERE `id`=".(int)$pidbusy.";"; |
| 6829 |
$dbo->setQuery($q); |
| 6830 |
$dbo->execute(); |
| 6831 |
$q = "UPDATE `#__vikrentcar_orders` SET `idbusy`=NULL WHERE `id`=".(int)$orderdata[0]['id'].";"; |
| 6832 |
$dbo->setQuery($q); |
| 6833 |
$dbo->execute(); |
| 6834 |
} |
| 6835 |
if ($pnotifycust == 1) { |
| 6836 |
$this->do_resendordemail($orderdata[0]['id'], true); |
| 6837 |
return; |
| 6838 |
} |
| 6839 |
// |
| 6840 |
} |
| 6841 |
} else { |
| 6842 |
// raise errors |
| 6843 |
VikError::raiseWarning('', JText::translate('VRCARNOTRIT')." ".date($df.' H:i', $first)." ".JText::translate('VRCARNOTCONSTO')." ".date($df.' H:i', $second)); |
| 6844 |
VikError::raiseWarning('', JText::translate('VRCFORCEAVAILABILITYCONF') . ' <a class="btn btn-danger" href="index.php?option=com_vikrentcar&task=editbusy&return=order&force_av=1&cid[]=' . $pidorder . '">' . JText::translate('VRCFORCEAVAILABILITY') . '</a>'); |
| 6845 |
} |
| 6846 |
} else { |
| 6847 |
// raise errors |
| 6848 |
VikError::raiseWarning('', JText::translate('ERRCARLOCKED')); |
| 6849 |
VikError::raiseWarning('', JText::translate('VRCFORCEAVAILABILITYCONF') . ' <a class="btn btn-danger" href="index.php?option=com_vikrentcar&task=editbusy&return=order&force_av=1&cid[]=' . $pidorder . '">' . JText::translate('VRCFORCEAVAILABILITY') . '</a>'); |
| 6850 |
} |
| 6851 |
} else { |
| 6852 |
VikError::raiseWarning('', JText::translate('ERRPREV')); |
| 6853 |
} |
| 6854 |
if (intval($pidcar) != intval($origidcar)) { |
| 6855 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editbusy&return=".$preturn."&cid[]=".$pidorder); |
| 6856 |
} elseif ($preturn == 'order') { |
| 6857 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=".$pidorder); |
| 6858 |
} else { |
| 6859 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=calendar&cid[]=".$pidcar); |
| 6860 |
} |
| 6861 |
} else { |
| 6862 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=orders"); |
| 6863 |
} |
| 6864 |
} |
| 6865 |
|
| 6866 |
public function editorder() { |
| 6867 |
VikRentCarHelper::printHeader("8"); |
| 6868 |
|
| 6869 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'editorder')); |
| 6870 |
|
| 6871 |
parent::display(); |
| 6872 |
|
| 6873 |
if (VikRentCar::showFooter()) { |
| 6874 |
VikRentCarHelper::printFooter(); |
| 6875 |
} |
| 6876 |
} |
| 6877 |
|
| 6878 |
public function editbusy() { |
| 6879 |
VikRentCarHelper::printHeader("8"); |
| 6880 |
|
| 6881 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'editbusy')); |
| 6882 |
|
| 6883 |
parent::display(); |
| 6884 |
|
| 6885 |
if (VikRentCar::showFooter()) { |
| 6886 |
VikRentCarHelper::printFooter(); |
| 6887 |
} |
| 6888 |
} |
| 6889 |
|
| 6890 |
public function checkversion() { |
| 6891 |
$params = new stdClass; |
| 6892 |
$params->version = VIKRENTCAR_SOFTWARE_VERSION; |
| 6893 |
$params->alias = 'com_vikrentcar'; |
| 6894 |
|
| 6895 |
$result = array(); |
| 6896 |
|
| 6897 |
if (!count($result)) { |
| 6898 |
$result = new stdClass; |
| 6899 |
$result->status = 0; |
| 6900 |
} else { |
| 6901 |
$result = $result[0]; |
| 6902 |
} |
| 6903 |
|
| 6904 |
echo json_encode($result); |
| 6905 |
exit; |
| 6906 |
} |
| 6907 |
|
| 6908 |
public function updateprogram() { |
| 6909 |
$params = new stdClass; |
| 6910 |
$params->version = VIKRENTCAR_SOFTWARE_VERSION; |
| 6911 |
$params->alias = 'com_vikrentcar'; |
| 6912 |
|
| 6913 |
$result = array(); |
| 6914 |
|
| 6915 |
if (!count($result) || !$result[0]) { |
| 6916 |
if (class_exists('JEventDispatcher')) { |
| 6917 |
$result = $dispatcher->trigger('checkVersion', array(&$params)); |
| 6918 |
} else { |
| 6919 |
$app = JFactory::getApplication(); |
| 6920 |
if (method_exists($app, 'triggerEvent')) { |
| 6921 |
$result = $app->triggerEvent('checkVersion', array(&$params)); |
| 6922 |
} |
| 6923 |
} |
| 6924 |
} |
| 6925 |
|
| 6926 |
if (!count($result) || !$result[0]->status || !$result[0]->response->status) { |
| 6927 |
exit('Error, plugin disabled'); |
| 6928 |
} |
| 6929 |
|
| 6930 |
JToolbarHelper::title(JText::translate('VRMAINTITLEUPDATEPROGRAM')); |
| 6931 |
|
| 6932 |
VikRentCarHelper::pUpdateProgram($result[0]->response); |
| 6933 |
} |
| 6934 |
|
| 6935 |
public function updateprogramlaunch() { |
| 6936 |
$params = new stdClass; |
| 6937 |
$params->version = VIKRENTCAR_SOFTWARE_VERSION; |
| 6938 |
$params->alias = 'com_vikrentcar'; |
| 6939 |
|
| 6940 |
$json = new stdClass; |
| 6941 |
$json->status = false; |
| 6942 |
|
| 6943 |
echo json_encode($json); |
| 6944 |
exit; |
| 6945 |
} |
| 6946 |
|
| 6947 |
public function customers() { |
| 6948 |
VikRentCarHelper::printHeader("customers"); |
| 6949 |
|
| 6950 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'customers')); |
| 6951 |
|
| 6952 |
parent::display(); |
| 6953 |
|
| 6954 |
if (VikRentCar::showFooter()) { |
| 6955 |
VikRentCarHelper::printFooter(); |
| 6956 |
} |
| 6957 |
} |
| 6958 |
|
| 6959 |
public function newcustomer() { |
| 6960 |
VikRentCarHelper::printHeader("customers"); |
| 6961 |
|
| 6962 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecustomer')); |
| 6963 |
|
| 6964 |
parent::display(); |
| 6965 |
|
| 6966 |
if (VikRentCar::showFooter()) { |
| 6967 |
VikRentCarHelper::printFooter(); |
| 6968 |
} |
| 6969 |
} |
| 6970 |
|
| 6971 |
public function editcustomer() { |
| 6972 |
VikRentCarHelper::printHeader("customers"); |
| 6973 |
|
| 6974 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecustomer')); |
| 6975 |
|
| 6976 |
parent::display(); |
| 6977 |
|
| 6978 |
if (VikRentCar::showFooter()) { |
| 6979 |
VikRentCarHelper::printFooter(); |
| 6980 |
} |
| 6981 |
} |
| 6982 |
|
| 6983 |
public function removecustomers() { |
| 6984 |
if (!JSession::checkToken()) { |
| 6985 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 6986 |
} |
| 6987 |
$ids = VikRequest::getVar('cid', array(0)); |
| 6988 |
if (@count($ids)) { |
| 6989 |
$dbo = JFactory::getDbo(); |
| 6990 |
$cpin = VikRentCar::getCPinIstance(); |
| 6991 |
foreach ($ids as $d) { |
| 6992 |
$cpin->pluginCustomerSync($d, 'delete'); |
| 6993 |
$q = "DELETE FROM `#__vikrentcar_customers` WHERE `id`=".(int)$d.";"; |
| 6994 |
$dbo->setQuery($q); |
| 6995 |
$dbo->execute(); |
| 6996 |
} |
| 6997 |
} |
| 6998 |
$mainframe = JFactory::getApplication(); |
| 6999 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customers"); |
| 7000 |
} |
| 7001 |
|
| 7002 |
public function savecustomer() { |
| 7003 |
if (!JSession::checkToken()) { |
| 7004 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 7005 |
} |
| 7006 |
$dbo = JFactory::getDbo(); |
| 7007 |
$mainframe = JFactory::getApplication(); |
| 7008 |
$pfirst_name = VikRequest::getString('first_name', '', 'request'); |
| 7009 |
$plast_name = VikRequest::getString('last_name', '', 'request'); |
| 7010 |
$pcompany = VikRequest::getString('company', '', 'request'); |
| 7011 |
$pvat = VikRequest::getString('vat', '', 'request'); |
| 7012 |
$pemail = VikRequest::getString('email', '', 'request'); |
| 7013 |
$pphone = VikRequest::getString('phone', '', 'request'); |
| 7014 |
$pcountry = VikRequest::getString('country', '', 'request'); |
| 7015 |
$ppin = VikRequest::getString('pin', '', 'request'); |
| 7016 |
$pujid = VikRequest::getInt('ujid', '', 'request'); |
| 7017 |
$paddress = VikRequest::getString('address', '', 'request'); |
| 7018 |
$pcity = VikRequest::getString('city', '', 'request'); |
| 7019 |
$pzip = VikRequest::getString('zip', '', 'request'); |
| 7020 |
$pgender = VikRequest::getString('gender', '', 'request'); |
| 7021 |
$pgender = in_array($pgender, array('F', 'M')) ? $pgender : ''; |
| 7022 |
$pbdate = VikRequest::getString('bdate', '', 'request'); |
| 7023 |
$ppbirth = VikRequest::getString('pbirth', '', 'request'); |
| 7024 |
$pdoctype = VikRequest::getString('doctype', '', 'request'); |
| 7025 |
$pdocnum = VikRequest::getString('docnum', '', 'request'); |
| 7026 |
$pnotes = VikRequest::getString('notes', '', 'request'); |
| 7027 |
$pscandocimg = VikRequest::getString('scandocimg', '', 'request'); |
| 7028 |
$pischannel = VikRequest::getInt('ischannel', '', 'request'); |
| 7029 |
$pcommission = VikRequest::getFloat('commission', '', 'request'); |
| 7030 |
$pcalccmmon = VikRequest::getInt('calccmmon', '', 'request'); |
| 7031 |
$papplycmmon = VikRequest::getInt('applycmmon', '', 'request'); |
| 7032 |
$pchname = VikRequest::getString('chname', '', 'request'); |
| 7033 |
$pchcolor = VikRequest::getString('chcolor', '', 'request'); |
| 7034 |
$ptmpl = VikRequest::getString('tmpl', '', 'request'); |
| 7035 |
$pgoto = VikRequest::getString('goto', '', 'request', VIKREQUEST_ALLOWRAW); |
| 7036 |
$pbid = VikRequest::getInt('bid', '', 'request'); |
| 7037 |
if (!empty($pfirst_name) && !empty($plast_name)) { |
| 7038 |
$cpin = VikRentCar::getCPinIstance(); |
| 7039 |
$q = "SELECT * FROM `#__vikrentcar_customers` WHERE `email`=".$dbo->quote($pemail)." LIMIT 1;"; |
| 7040 |
$dbo->setQuery($q); |
| 7041 |
$dbo->execute(); |
| 7042 |
if ($dbo->getNumRows() == 0) { |
| 7043 |
if (empty($ppin)) { |
| 7044 |
$ppin = $cpin->generateUniquePin(); |
| 7045 |
} elseif ($cpin->pinExists($ppin)) { |
| 7046 |
$ppin = $cpin->generateUniquePin(); |
| 7047 |
} |
| 7048 |
//file upload |
| 7049 |
$pimg = VikRequest::getVar('docimg', null, 'files', 'array'); |
| 7050 |
jimport('joomla.filesystem.file'); |
| 7051 |
$gimg = ""; |
| 7052 |
if (isset($pimg) && strlen(trim($pimg['name']))) { |
| 7053 |
$filename = JFile::makeSafe(rand(100, 9999).str_replace(" ", "_", strtolower($pimg['name']))); |
| 7054 |
$src = $pimg['tmp_name']; |
| 7055 |
$dest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'idscans'.DIRECTORY_SEPARATOR; |
| 7056 |
$j = ""; |
| 7057 |
if (file_exists($dest.$filename)) { |
| 7058 |
$j = rand(171, 1717); |
| 7059 |
while (file_exists($dest.$j.$filename)) { |
| 7060 |
$j++; |
| 7061 |
} |
| 7062 |
} |
| 7063 |
$finaldest = $dest.$j.$filename; |
| 7064 |
$check = !empty($pimg['tmp_name']) ? getimagesize($pimg['tmp_name']) : []; |
| 7065 |
if (($check[2] & imagetypes()) && preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $filename)) { |
| 7066 |
if (VikRentCar::uploadFile($src, $finaldest)) { |
| 7067 |
$gimg = $j.$filename; |
| 7068 |
} else { |
| 7069 |
VikError::raiseWarning('', 'Error while uploading image'); |
| 7070 |
} |
| 7071 |
} else { |
| 7072 |
VikError::raiseWarning('', 'Uploaded file is not an Image'); |
| 7073 |
} |
| 7074 |
} elseif (!empty($pscandocimg)) { |
| 7075 |
$gimg = $pscandocimg; |
| 7076 |
} |
| 7077 |
// |
| 7078 |
$q = "INSERT INTO `#__vikrentcar_customers` (`first_name`,`last_name`,`email`,`phone`,`country`,`pin`,`ujid`,`address`,`city`,`zip`,`doctype`,`docnum`,`docimg`,`notes`,`company`,`vat`,`gender`,`bdate`,`pbirth`) VALUES(".$dbo->quote($pfirst_name).", ".$dbo->quote($plast_name).", ".$dbo->quote($pemail).", ".$dbo->quote($pphone).", ".$dbo->quote($pcountry).", ".$dbo->quote($ppin).", ".$dbo->quote($pujid).", ".$dbo->quote($paddress).", ".$dbo->quote($pcity).", ".$dbo->quote($pzip).", ".$dbo->quote($pdoctype).", ".$dbo->quote($pdocnum).", ".$dbo->quote($gimg).", ".$dbo->quote($pnotes).", ".$dbo->quote($pcompany).", ".$dbo->quote($pvat).", ".$dbo->quote($pgender).", ".$dbo->quote($pbdate).", ".$dbo->quote($ppbirth).");"; |
| 7079 |
$dbo->setQuery($q); |
| 7080 |
$dbo->execute(); |
| 7081 |
$lid = $dbo->insertid(); |
| 7082 |
$cpin->pluginCustomerSync($lid, 'insert'); |
| 7083 |
if (!empty($lid)) { |
| 7084 |
$mainframe->enqueueMessage(JText::translate('VRCUSTOMERSAVED')); |
| 7085 |
} |
| 7086 |
// check if coming from a specific task |
| 7087 |
if (!empty($pgoto) && !empty($pbid)) { |
| 7088 |
$cpin->setNewPin($ppin); |
| 7089 |
$cpin->setNewCustomerId($lid); |
| 7090 |
$cpin->saveCustomerBooking($pbid); |
| 7091 |
$mainframe->redirect(base64_decode($pgoto)); |
| 7092 |
exit; |
| 7093 |
} |
| 7094 |
} else { |
| 7095 |
//email already exists |
| 7096 |
$ex_customer = $dbo->loadAssoc(); |
| 7097 |
if (!empty($pgoto) && !empty($pbid)) { |
| 7098 |
// check if coming from a specific task |
| 7099 |
$cpin->setNewPin($ex_customer['pin']); |
| 7100 |
$cpin->setNewCustomerId($ex_customer['id']); |
| 7101 |
$cpin->saveCustomerBooking($pbid); |
| 7102 |
VikError::raiseWarning('', JText::translate('VRERRCUSTOMEREMAILEXISTS').' ('.$ex_customer['first_name'].' '.$ex_customer['last_name'].')'); |
| 7103 |
$mainframe->redirect(base64_decode($pgoto)); |
| 7104 |
exit; |
| 7105 |
} else { |
| 7106 |
VikError::raiseWarning('', JText::translate('VRERRCUSTOMEREMAILEXISTS').'<br/><a href="index.php?option=com_vikrentcar&task=editcustomer&cid[]='.$ex_customer['id'].'" target="_blank">'.$ex_customer['first_name'].' '.$ex_customer['last_name'].'</a>'); |
| 7107 |
} |
| 7108 |
} |
| 7109 |
} |
| 7110 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customers"); |
| 7111 |
} |
| 7112 |
|
| 7113 |
public function updatecustomer() { |
| 7114 |
if (!JSession::checkToken()) { |
| 7115 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 7116 |
} |
| 7117 |
$this->do_updatecustomer(); |
| 7118 |
} |
| 7119 |
|
| 7120 |
public function updatecustomerstay() { |
| 7121 |
if (!JSession::checkToken()) { |
| 7122 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 7123 |
} |
| 7124 |
$this->do_updatecustomer(true); |
| 7125 |
} |
| 7126 |
|
| 7127 |
private function do_updatecustomer($stay = false) { |
| 7128 |
$dbo = JFactory::getDbo(); |
| 7129 |
$mainframe = JFactory::getApplication(); |
| 7130 |
$pfirst_name = VikRequest::getString('first_name', '', 'request'); |
| 7131 |
$plast_name = VikRequest::getString('last_name', '', 'request'); |
| 7132 |
$pcompany = VikRequest::getString('company', '', 'request'); |
| 7133 |
$pvat = VikRequest::getString('vat', '', 'request'); |
| 7134 |
$pemail = VikRequest::getString('email', '', 'request'); |
| 7135 |
$pphone = VikRequest::getString('phone', '', 'request'); |
| 7136 |
$pcountry = VikRequest::getString('country', '', 'request'); |
| 7137 |
$ppin = VikRequest::getString('pin', '', 'request'); |
| 7138 |
$pujid = VikRequest::getInt('ujid', '', 'request'); |
| 7139 |
$paddress = VikRequest::getString('address', '', 'request'); |
| 7140 |
$pcity = VikRequest::getString('city', '', 'request'); |
| 7141 |
$pzip = VikRequest::getString('zip', '', 'request'); |
| 7142 |
$pgender = VikRequest::getString('gender', '', 'request'); |
| 7143 |
$pgender = in_array($pgender, array('F', 'M')) ? $pgender : ''; |
| 7144 |
$pbdate = VikRequest::getString('bdate', '', 'request'); |
| 7145 |
$ppbirth = VikRequest::getString('pbirth', '', 'request'); |
| 7146 |
$pdoctype = VikRequest::getString('doctype', '', 'request'); |
| 7147 |
$pdocnum = VikRequest::getString('docnum', '', 'request'); |
| 7148 |
$pnotes = VikRequest::getString('notes', '', 'request'); |
| 7149 |
$pscandocimg = VikRequest::getString('scandocimg', '', 'request'); |
| 7150 |
$pischannel = VikRequest::getInt('ischannel', '', 'request'); |
| 7151 |
$pcommission = VikRequest::getFloat('commission', '', 'request'); |
| 7152 |
$pcalccmmon = VikRequest::getInt('calccmmon', '', 'request'); |
| 7153 |
$papplycmmon = VikRequest::getInt('applycmmon', '', 'request'); |
| 7154 |
$pchname = VikRequest::getString('chname', '', 'request'); |
| 7155 |
$pchcolor = VikRequest::getString('chcolor', '', 'request'); |
| 7156 |
$pwhere = VikRequest::getInt('where', '', 'request'); |
| 7157 |
$ptmpl = VikRequest::getString('tmpl', '', 'request'); |
| 7158 |
$pbid = VikRequest::getInt('bid', '', 'request'); |
| 7159 |
$pgoto = VikRequest::getString('goto', '', 'request', VIKREQUEST_ALLOWRAW); |
| 7160 |
if (!empty($pwhere) && !empty($pfirst_name) && !empty($plast_name)) { |
| 7161 |
$q = "SELECT * FROM `#__vikrentcar_customers` WHERE `id`=".(int)$pwhere." LIMIT 1;"; |
| 7162 |
$dbo->setQuery($q); |
| 7163 |
$dbo->execute(); |
| 7164 |
if ($dbo->getNumRows() == 1) { |
| 7165 |
$customer = $dbo->loadAssoc(); |
| 7166 |
} else { |
| 7167 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customers"); |
| 7168 |
exit; |
| 7169 |
} |
| 7170 |
$q = "SELECT * FROM `#__vikrentcar_customers` WHERE `email`=".$dbo->quote($pemail)." AND `id`!=".(int)$pwhere." LIMIT 1;"; |
| 7171 |
$dbo->setQuery($q); |
| 7172 |
$dbo->execute(); |
| 7173 |
if ($dbo->getNumRows() == 0) { |
| 7174 |
$cpin = VikRentCar::getCPinIstance(); |
| 7175 |
if (empty($ppin)) { |
| 7176 |
$ppin = $customer['pin']; |
| 7177 |
} elseif ($cpin->pinExists($ppin, $customer['pin'])) { |
| 7178 |
$ppin = $cpin->generateUniquePin(); |
| 7179 |
} |
| 7180 |
//file upload |
| 7181 |
$pimg = VikRequest::getVar('docimg', null, 'files', 'array'); |
| 7182 |
jimport('joomla.filesystem.file'); |
| 7183 |
$gimg = ""; |
| 7184 |
if (isset($pimg) && strlen(trim($pimg['name']))) { |
| 7185 |
$filename = JFile::makeSafe(rand(100, 9999).str_replace(" ", "_", strtolower($pimg['name']))); |
| 7186 |
$src = $pimg['tmp_name']; |
| 7187 |
$dest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'idscans'.DIRECTORY_SEPARATOR; |
| 7188 |
$j = ""; |
| 7189 |
if (file_exists($dest.$filename)) { |
| 7190 |
$j = rand(171, 1717); |
| 7191 |
while (file_exists($dest.$j.$filename)) { |
| 7192 |
$j++; |
| 7193 |
} |
| 7194 |
} |
| 7195 |
$finaldest = $dest.$j.$filename; |
| 7196 |
$check = !empty($pimg['tmp_name']) ? getimagesize($pimg['tmp_name']) : []; |
| 7197 |
if (($check[2] & imagetypes()) && preg_match("/\.(a?png|jpe?g|bmp|gif|ico|webp)\z/i", $filename)) { |
| 7198 |
if (VikRentCar::uploadFile($src, $finaldest)) { |
| 7199 |
$gimg = $j.$filename; |
| 7200 |
} else { |
| 7201 |
VikError::raiseWarning('', 'Error while uploading image'); |
| 7202 |
} |
| 7203 |
} else { |
| 7204 |
VikError::raiseWarning('', 'Uploaded file is not an Image'); |
| 7205 |
} |
| 7206 |
} elseif (!empty($pscandocimg)) { |
| 7207 |
$gimg = $pscandocimg; |
| 7208 |
} |
| 7209 |
// |
| 7210 |
$q = "UPDATE `#__vikrentcar_customers` SET `first_name`=".$dbo->quote($pfirst_name).",`last_name`=".$dbo->quote($plast_name).",`email`=".$dbo->quote($pemail).",`phone`=".$dbo->quote($pphone).",`country`=".$dbo->quote($pcountry).",`pin`=".$dbo->quote($ppin).",`ujid`=".$dbo->quote($pujid).",`address`=".$dbo->quote($paddress).",`city`=".$dbo->quote($pcity).",`zip`=".$dbo->quote($pzip).",`doctype`=".$dbo->quote($pdoctype).",`docnum`=".$dbo->quote($pdocnum).(!empty($gimg) ? ",`docimg`=".$dbo->quote($gimg) : "").",`notes`=".$dbo->quote($pnotes).",`company`=".$dbo->quote($pcompany).",`vat`=".$dbo->quote($pvat).",`gender`=".$dbo->quote($pgender).",`bdate`=".$dbo->quote($pbdate).",`pbirth`=".$dbo->quote($ppbirth)." WHERE `id`=".(int)$pwhere.";"; |
| 7211 |
$dbo->setQuery($q); |
| 7212 |
$dbo->execute(); |
| 7213 |
$cpin->pluginCustomerSync($pwhere, 'update'); |
| 7214 |
$mainframe->enqueueMessage(JText::translate('VRCUSTOMERSAVED')); |
| 7215 |
} else { |
| 7216 |
//email already exists |
| 7217 |
$ex_customer = $dbo->loadAssoc(); |
| 7218 |
if (!empty($pgoto)) { |
| 7219 |
// check if coming from a specific task |
| 7220 |
VikError::raiseWarning('', JText::translate('VRERRCUSTOMEREMAILEXISTS').' ('.$ex_customer['first_name'].' '.$ex_customer['last_name'].')'); |
| 7221 |
$mainframe->redirect(base64_decode($pgoto)); |
| 7222 |
exit; |
| 7223 |
} else { |
| 7224 |
VikError::raiseWarning('', JText::translate('VRERRCUSTOMEREMAILEXISTS').'<br/><a href="index.php?option=com_vikrentcar&task=editcustomer&cid[]='.$ex_customer['id'].'" target="_blank">'.$ex_customer['first_name'].' '.$ex_customer['last_name'].'</a>'); |
| 7225 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editcustomer&cid[]=".$pwhere); |
| 7226 |
exit; |
| 7227 |
} |
| 7228 |
} |
| 7229 |
} |
| 7230 |
// check if coming from a specific task |
| 7231 |
if (!empty($pgoto)) { |
| 7232 |
$mainframe->redirect(base64_decode($pgoto)); |
| 7233 |
exit; |
| 7234 |
} |
| 7235 |
|
| 7236 |
if ($stay) { |
| 7237 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editcustomer&cid[]=".$pwhere); |
| 7238 |
} else { |
| 7239 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customers"); |
| 7240 |
} |
| 7241 |
} |
| 7242 |
|
| 7243 |
public function cancelcustomer() { |
| 7244 |
$mainframe = JFactory::getApplication(); |
| 7245 |
$pgoto = VikRequest::getString('goto', '', 'request', VIKREQUEST_ALLOWRAW); |
| 7246 |
if (!empty($pgoto)) { |
| 7247 |
$mainframe->redirect(base64_decode($pgoto)); |
| 7248 |
exit; |
| 7249 |
} |
| 7250 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customers"); |
| 7251 |
} |
| 7252 |
|
| 7253 |
public function searchcustomer() { |
| 7254 |
//to be called via ajax |
| 7255 |
$kw = VikRequest::getString('kw', '', 'request'); |
| 7256 |
$nopin = VikRequest::getInt('nopin', '', 'request'); |
| 7257 |
$email = VikRequest::getInt('email', 0, 'request'); |
| 7258 |
$cstring = ''; |
| 7259 |
if (strlen($kw) > 0) { |
| 7260 |
$dbo = JFactory::getDbo(); |
| 7261 |
if ($nopin > 0) { |
| 7262 |
//page all bookings |
| 7263 |
$q = "SELECT * FROM `#__vikrentcar_customers` WHERE CONCAT_WS(' ', `first_name`, `last_name`) LIKE ".$dbo->quote("%".$kw."%")." OR `email` LIKE ".$dbo->quote("%".$kw."%")." ORDER BY `first_name` ASC LIMIT 30;"; |
| 7264 |
} elseif ($email > 0) { |
| 7265 |
// page calendar for checking if an email exists |
| 7266 |
$q = "SELECT `first_name`, `last_name`, `email` FROM `#__vikrentcar_customers` WHERE `email`=".$dbo->quote($kw).";"; |
| 7267 |
} else { |
| 7268 |
//page calendar |
| 7269 |
$q = "SELECT * FROM `#__vikrentcar_customers` WHERE CONCAT_WS(' ', `first_name`, `last_name`) LIKE ".$dbo->quote("%".$kw."%")." OR `email` LIKE ".$dbo->quote("%".$kw."%")." OR `pin` LIKE ".$dbo->quote("%".$kw."%")." ORDER BY `first_name` ASC;"; |
| 7270 |
} |
| 7271 |
$dbo->setQuery($q); |
| 7272 |
$dbo->execute(); |
| 7273 |
if ($dbo->getNumRows() > 0) { |
| 7274 |
$customers = $dbo->loadAssocList(); |
| 7275 |
$cust_old_fields = array(); |
| 7276 |
$cstring_search = '<div class="vrc-custsearchres-inner">' . "\n"; |
| 7277 |
foreach ($customers as $k => $v) { |
| 7278 |
$cstring_search .= '<div class="vrc-custsearchres-entry" data-custid="' . (int) $v['id'] . '" data-email="' . htmlspecialchars($v['email']) . '" data-phone="' . htmlspecialchars($v['phone']) . '" data-country="' . htmlspecialchars($v['country']) . '" data-pin="' . htmlspecialchars($v['pin']) . '" data-firstname="' . htmlspecialchars($v['first_name']) . '" data-lastname="' . htmlspecialchars($v['last_name']) . '">'."\n"; |
| 7279 |
$cstring_search .= '<span class="vrc-custsearchres-cflag">'; |
| 7280 |
if (is_file(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'countries'.DIRECTORY_SEPARATOR.$v['country'].'.png')) { |
| 7281 |
$cstring_search .= '<img src="'.VRC_ADMIN_URI.'resources/countries/'.$v['country'].'.png'.'" title="'.$v['country'].'" class="vrc-country-flag"/>'."\n"; |
| 7282 |
} else { |
| 7283 |
$cstring_search .= '<i class="' . VikRentCarIcons::i('globe') . '"></i>'; |
| 7284 |
} |
| 7285 |
$cstring_search .= '</span>'; |
| 7286 |
$cstring_search .= '<span class="vrc-custsearchres-name" title="' . htmlspecialchars($v['email']) . '">'.$v['first_name'].' '.$v['last_name'].'</span>'."\n"; |
| 7287 |
if (!($nopin > 0)) { |
| 7288 |
$cstring_search .= '<span class="vrc-custsearchres-pin">'.$v['pin'].'</span>'."\n"; |
| 7289 |
} |
| 7290 |
$cstring_search .= '</div>'."\n"; |
| 7291 |
if (!empty($v['cfields'])) { |
| 7292 |
$oldfields = json_decode($v['cfields'], true); |
| 7293 |
if (is_array($oldfields) && count($oldfields)) { |
| 7294 |
$cust_old_fields[$v['id']] = $oldfields; |
| 7295 |
} |
| 7296 |
} |
| 7297 |
} |
| 7298 |
$cstring_search .= '</div>'."\n"; |
| 7299 |
$cstring = json_encode(array(($nopin > 0 ? '' : $cust_old_fields), $cstring_search)); |
| 7300 |
} |
| 7301 |
} |
| 7302 |
/** |
| 7303 |
* The HTML content is built directly in this task by escaping the necessary values, |
| 7304 |
* and no third party plugins could interfere. We cannot escape this HTML string, |
| 7305 |
* nor can we convert special chars into HTML entities, as this is the response |
| 7306 |
* of an AJAX request, and the HTML code needs to be displayed accordingly. |
| 7307 |
* If we were to escape the HTML string, then the AJAX response would be useless, |
| 7308 |
* as it would be HTML code converted into text with HTML entities. |
| 7309 |
*/ |
| 7310 |
echo $cstring; |
| 7311 |
exit; |
| 7312 |
} |
| 7313 |
|
| 7314 |
public function exportcustomers() { |
| 7315 |
//we do not set the menu for this view |
| 7316 |
|
| 7317 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'exportcustomers')); |
| 7318 |
|
| 7319 |
parent::display(); |
| 7320 |
|
| 7321 |
if (VikRentCar::showFooter()) { |
| 7322 |
VikRentCarHelper::printFooter(); |
| 7323 |
} |
| 7324 |
} |
| 7325 |
|
| 7326 |
public function exportcustomerslaunch() { |
| 7327 |
$cid = VikRequest::getVar('cid', array(0)); |
| 7328 |
$dbo = JFactory::getDbo(); |
| 7329 |
$pnotes = VikRequest::getInt('notes', '', 'request'); |
| 7330 |
$pscanimg = VikRequest::getInt('scanimg', '', 'request'); |
| 7331 |
$ppin = VikRequest::getInt('pin', '', 'request'); |
| 7332 |
$pcountry = VikRequest::getString('country', '', 'request'); |
| 7333 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 7334 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 7335 |
$pdatefilt = VikRequest::getInt('datefilt', '', 'request'); |
| 7336 |
$clauses = array(); |
| 7337 |
if (count($cid) > 0 && !empty($cid[0])) { |
| 7338 |
$clauses[] = "`c`.`id` IN (".implode(', ', $cid).")"; |
| 7339 |
} |
| 7340 |
if (!empty($pcountry)) { |
| 7341 |
$clauses[] = "`c`.`country`=".$dbo->quote($pcountry); |
| 7342 |
} |
| 7343 |
$datescol = '`bk`.`ts`'; |
| 7344 |
if ($pdatefilt > 0) { |
| 7345 |
if ($pdatefilt == 1) { |
| 7346 |
$datescol = '`bk`.`ts`'; |
| 7347 |
} elseif ($pdatefilt == 2) { |
| 7348 |
$datescol = '`bk`.`ritiro`'; |
| 7349 |
} elseif ($pdatefilt == 3) { |
| 7350 |
$datescol = '`bk`.`consegna`'; |
| 7351 |
} |
| 7352 |
} |
| 7353 |
if (!empty($pfromdate)) { |
| 7354 |
$from_ts = VikRentCar::getDateTimestamp($pfromdate, 0, 0); |
| 7355 |
$clauses[] = $datescol.">=".$from_ts; |
| 7356 |
} |
| 7357 |
if (!empty($ptodate)) { |
| 7358 |
$to_ts = VikRentCar::getDateTimestamp($ptodate, 23, 59); |
| 7359 |
$clauses[] = $datescol."<=".$to_ts; |
| 7360 |
} |
| 7361 |
//this query below is safe with the error #1055 when sql_mode=only_full_group_by |
| 7362 |
$q = "SELECT `c`.`id`,`c`.`first_name`,`c`.`last_name`,`c`.`email`,`c`.`phone`,`c`.`country`,`c`.`cfields`,`c`.`pin`,`c`.`ujid`,`c`.`address`,`c`.`city`,`c`.`zip`,`c`.`doctype`,`c`.`docnum`,`c`.`docimg`,`c`.`notes`,`c`.`company`,`c`.`vat`,`c`.`gender`,`c`.`bdate`,`c`.`pbirth`,". |
| 7363 |
"(SELECT COUNT(*) FROM `#__vikrentcar_customers_orders` AS `co` WHERE `co`.`idcustomer`=`c`.`id`) AS `tot_bookings`,". |
| 7364 |
"`cy`.`country_3_code`,`cy`.`country_name` ". |
| 7365 |
"FROM `#__vikrentcar_customers` AS `c` LEFT JOIN `#__vikrentcar_countries` `cy` ON `cy`.`country_3_code`=`c`.`country` ". |
| 7366 |
"LEFT JOIN `#__vikrentcar_customers_orders` `co` ON `co`.`idcustomer`=`c`.`id` ". |
| 7367 |
"LEFT JOIN `#__vikrentcar_orders` `bk` ON `bk`.`id`=`co`.`idorder`". |
| 7368 |
(count($clauses) > 0 ? " WHERE ".implode(' AND ', $clauses) : "")." |
| 7369 |
GROUP BY `c`.`id`,`c`.`first_name`,`c`.`last_name`,`c`.`email`,`c`.`phone`,`c`.`country`,`c`.`cfields`,`c`.`pin`,`c`.`ujid`,`c`.`address`,`c`.`city`,`c`.`zip`,`c`.`doctype`,`c`.`docnum`,`c`.`docimg`,`c`.`notes`,`c`.`company`,`c`.`vat`,`c`.`gender`,`c`.`bdate`,`c`.`pbirth`,`cy`.`country_3_code`,`cy`.`country_name` ". |
| 7370 |
"ORDER BY `c`.`last_name` ASC;"; |
| 7371 |
$dbo->setQuery($q); |
| 7372 |
$dbo->execute(); |
| 7373 |
if (!($dbo->getNumRows() > 0)) { |
| 7374 |
VikError::raiseWarning('', JText::translate('VRCNORECORDSCSVCUSTOMERS')); |
| 7375 |
$mainframe = JFactory::getApplication(); |
| 7376 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=customers"); |
| 7377 |
exit; |
| 7378 |
} |
| 7379 |
$customers = $dbo->loadAssocList(); |
| 7380 |
$csvlines = array(); |
| 7381 |
$csvheadline = array('ID', JText::translate('VRCUSTOMERLASTNAME'), JText::translate('VRCUSTOMERFIRSTNAME'), JText::translate('VRCUSTOMEREMAIL'), JText::translate('VRCUSTOMERPHONE'), JText::translate('VRCUSTOMERADDRESS'), JText::translate('VRCUSTOMERCITY'), JText::translate('VRCUSTOMERZIP'), JText::translate('VRCUSTOMERCOUNTRY'), JText::translate('VRCUSTOMERTOTBOOKINGS')); |
| 7382 |
if ($ppin > 0) { |
| 7383 |
$csvheadline[] = JText::translate('VRCUSTOMERPIN'); |
| 7384 |
} |
| 7385 |
if ($pscanimg > 0) { |
| 7386 |
$csvheadline[] = JText::translate('VRCUSTOMERDOCTYPE'); |
| 7387 |
$csvheadline[] = JText::translate('VRCUSTOMERDOCNUM'); |
| 7388 |
$csvheadline[] = JText::translate('VRCUSTOMERDOCIMG'); |
| 7389 |
} |
| 7390 |
if ($pnotes > 0) { |
| 7391 |
$csvheadline[] = JText::translate('VRCUSTOMERNOTES'); |
| 7392 |
} |
| 7393 |
$csvlines[] = $csvheadline; |
| 7394 |
foreach ($customers as $customer) { |
| 7395 |
$csvcustomerline = array($customer['id'], $customer['last_name'], $customer['first_name'], $customer['email'], $customer['phone'], $customer['address'], $customer['city'], $customer['zip'], $customer['country_name'], $customer['tot_bookings']); |
| 7396 |
if ($ppin > 0) { |
| 7397 |
$csvcustomerline[] = $customer['pin']; |
| 7398 |
} |
| 7399 |
if ($pscanimg > 0) { |
| 7400 |
$csvcustomerline[] = $customer['doctype']; |
| 7401 |
$csvcustomerline[] = $customer['docnum']; |
| 7402 |
$csvcustomerline[] = (!empty($customer['docimg']) ? VRC_ADMIN_URI.'resources/idscans/'.$customer['docimg'] : ''); |
| 7403 |
} |
| 7404 |
if ($pnotes > 0) { |
| 7405 |
$csvcustomerline[] = $customer['notes']; |
| 7406 |
} |
| 7407 |
$csvlines[] = $csvcustomerline; |
| 7408 |
} |
| 7409 |
header("Content-type: text/csv"); |
| 7410 |
header("Cache-Control: no-store, no-cache"); |
| 7411 |
header('Content-Disposition: attachment; filename="customers_export_'.(!empty($pcountry) ? strtolower($pcountry).'_' : '').date('Y-m-d').'.csv"'); |
| 7412 |
$outstream = fopen("php://output", 'w'); |
| 7413 |
foreach ($csvlines as $csvline) { |
| 7414 |
fputcsv($outstream, $csvline); |
| 7415 |
} |
| 7416 |
fclose($outstream); |
| 7417 |
exit; |
| 7418 |
} |
| 7419 |
|
| 7420 |
public function sendcustomemail() { |
| 7421 |
$dbo = JFactory::getDbo(); |
| 7422 |
$mainframe = JFactory::getApplication(); |
| 7423 |
$vrc_tn = VikRentCar::getTranslator(); |
| 7424 |
$pbid = VikRequest::getInt('bid', '', 'request'); |
| 7425 |
$pemailsubj = VikRequest::getString('emailsubj', '', 'request'); |
| 7426 |
$pemail = VikRequest::getString('email', '', 'request'); |
| 7427 |
$pemailcont = VikRequest::getString('emailcont', '', 'request', VIKREQUEST_ALLOWRAW); |
| 7428 |
$pemailfrom = VikRequest::getString('emailfrom', '', 'request'); |
| 7429 |
$pgoto = VikRequest::getString('goto', '', 'request', VIKREQUEST_ALLOWRAW); |
| 7430 |
$pgoto = !empty($pgoto) ? urldecode($pgoto) : 'index.php?option=com_vikrentcar'; |
| 7431 |
if (!empty($pemail) && !empty($pemailcont)) { |
| 7432 |
$email_attach = null; |
| 7433 |
jimport('joomla.filesystem.file'); |
| 7434 |
$pemailattch = VikRequest::getVar('emailattch', null, 'files', 'array'); |
| 7435 |
if (isset($pemailattch) && strlen(trim($pemailattch['name']))) { |
| 7436 |
$filename = JFile::makeSafe(str_replace(" ", "_", strtolower($pemailattch['name']))); |
| 7437 |
$src = $pemailattch['tmp_name']; |
| 7438 |
$dest = VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR; |
| 7439 |
$j = ""; |
| 7440 |
if (file_exists($dest.$filename)) { |
| 7441 |
$j = rand(171, 1717); |
| 7442 |
while (file_exists($dest.$j.$filename)) { |
| 7443 |
$j++; |
| 7444 |
} |
| 7445 |
} |
| 7446 |
$finaldest = $dest.$j.$filename; |
| 7447 |
if (VikRentCar::uploadFile($src, $finaldest)) { |
| 7448 |
$email_attach = $finaldest; |
| 7449 |
} else { |
| 7450 |
VikError::raiseWarning('', 'Error uploading the attachment. Email not sent.'); |
| 7451 |
$mainframe->redirect($pgoto); |
| 7452 |
exit; |
| 7453 |
} |
| 7454 |
} |
| 7455 |
//VRC 1.12 - special tags for the custom email template files and messages |
| 7456 |
$orig_mail_cont = $pemailcont; |
| 7457 |
if (strpos($pemailcont, '{') !== false && strpos($pemailcont, '}') !== false) { |
| 7458 |
$order = array(); |
| 7459 |
$q = "SELECT `o`.*,`co`.`idcustomer`,CONCAT_WS(' ',`c`.`first_name`,`c`.`last_name`) AS `customer_name`,`c`.`pin` AS `customer_pin`,`nat`.`country_name` FROM `#__vikrentcar_orders` AS `o` LEFT JOIN `#__vikrentcar_customers_orders` `co` ON `co`.`idorder`=`o`.`id` AND `co`.`idorder`=".(int)$pbid." LEFT JOIN `#__vikrentcar_customers` `c` ON `c`.`id`=`co`.`idcustomer` LEFT JOIN `#__vikrentcar_countries` `nat` ON `nat`.`country_3_code`=`o`.`country` WHERE `o`.`id`=".(int)$pbid.";"; |
| 7460 |
$dbo->setQuery($q); |
| 7461 |
$dbo->execute(); |
| 7462 |
if ($dbo->getNumRows() > 0) { |
| 7463 |
$order = $dbo->loadAssoc(); |
| 7464 |
} |
| 7465 |
// parse the special tokens to build the message |
| 7466 |
$pemailcont = VikRentCar::parseSpecialTokens($order, $pemailcont); |
| 7467 |
} |
| 7468 |
// |
| 7469 |
$is_html = (strpos($pemailcont, '<') !== false && strpos($pemailcont, '>') !== false); |
| 7470 |
$pemailcont = $is_html ? nl2br($pemailcont) : $pemailcont; |
| 7471 |
$vrc_app = new VrcApplication(); |
| 7472 |
$vrc_app->sendMail($pemailfrom, $pemailfrom, $pemail, $pemailfrom, $pemailsubj, $pemailcont, $is_html, 'base64', $email_attach); |
| 7473 |
$mainframe->enqueueMessage(JText::translate('VRSENDEMAILOK')); |
| 7474 |
if ($email_attach !== null) { |
| 7475 |
@unlink($email_attach); |
| 7476 |
} |
| 7477 |
// Booking History |
| 7478 |
VikRentCar::getOrderHistoryInstance()->setBid($pbid)->store('CE', nl2br($pemailsubj . "\n\n" . $pemailcont)); |
| 7479 |
// |
| 7480 |
//Save email template for future sending |
| 7481 |
$config_rec_exists = false; |
| 7482 |
$emtpl = array( |
| 7483 |
'emailsubj' => $pemailsubj, |
| 7484 |
'emailcont' => $orig_mail_cont, |
| 7485 |
'emailfrom' => $pemailfrom |
| 7486 |
); |
| 7487 |
$cur_emtpl = array(); |
| 7488 |
$q = "SELECT `setting` FROM `#__vikrentcar_config` WHERE `param`='customemailtpls';"; |
| 7489 |
$dbo->setQuery($q); |
| 7490 |
$dbo->execute(); |
| 7491 |
if ($dbo->getNumRows() > 0) { |
| 7492 |
$config_rec_exists = true; |
| 7493 |
$cur_emtpl = $dbo->loadResult(); |
| 7494 |
$cur_emtpl = empty($cur_emtpl) ? array() : json_decode($cur_emtpl, true); |
| 7495 |
$cur_emtpl = is_array($cur_emtpl) ? $cur_emtpl : array(); |
| 7496 |
} |
| 7497 |
if (count($cur_emtpl) > 0) { |
| 7498 |
$existing_subj = false; |
| 7499 |
foreach ($cur_emtpl as $emk => $emv) { |
| 7500 |
if (array_key_exists('emailsubj', $emv) && $emv['emailsubj'] == $emtpl['emailsubj']) { |
| 7501 |
$cur_emtpl[$emk] = $emtpl; |
| 7502 |
$existing_subj = true; |
| 7503 |
break; |
| 7504 |
} |
| 7505 |
} |
| 7506 |
if ($existing_subj === false) { |
| 7507 |
$cur_emtpl[] = $emtpl; |
| 7508 |
} |
| 7509 |
} else { |
| 7510 |
$cur_emtpl[] = $emtpl; |
| 7511 |
} |
| 7512 |
if (count($cur_emtpl) > 10) { |
| 7513 |
//Max 10 templates to avoid problems with the size of the field and truncated json strings |
| 7514 |
$exceed = count($cur_emtpl) - 10; |
| 7515 |
for ($tl=0; $tl < $exceed; $tl++) { |
| 7516 |
unset($cur_emtpl[$tl]); |
| 7517 |
} |
| 7518 |
$cur_emtpl = array_values($cur_emtpl); |
| 7519 |
} |
| 7520 |
if ($config_rec_exists === true) { |
| 7521 |
$q = "UPDATE `#__vikrentcar_config` SET `setting`=".$dbo->quote(json_encode($cur_emtpl))." WHERE `param`='customemailtpls';"; |
| 7522 |
$dbo->setQuery($q); |
| 7523 |
$dbo->execute(); |
| 7524 |
} else { |
| 7525 |
$q = "INSERT INTO `#__vikrentcar_config` (`param`,`setting`) VALUES ('customemailtpls', ".$dbo->quote(json_encode($cur_emtpl)).");"; |
| 7526 |
$dbo->setQuery($q); |
| 7527 |
$dbo->execute(); |
| 7528 |
} |
| 7529 |
// |
| 7530 |
} else { |
| 7531 |
VikError::raiseWarning('', JText::translate('VRSENDEMAILERRMISSDATA')); |
| 7532 |
} |
| 7533 |
$mainframe->redirect($pgoto); |
| 7534 |
} |
| 7535 |
|
| 7536 |
public function rmcustomemailtpl() { |
| 7537 |
$cid = VikRequest::getVar('cid', array(0)); |
| 7538 |
$oid = $cid[0]; |
| 7539 |
$dbo = JFactory::getDbo(); |
| 7540 |
$mainframe = JFactory::getApplication(); |
| 7541 |
$tplind = VikRequest::getInt('tplind', '', 'request'); |
| 7542 |
if (empty($oid) || !(strlen($tplind) > 0)) { |
| 7543 |
VikError::raiseWarning('', 'Missing Data.'); |
| 7544 |
$mainframe->redirect('index.php?option=com_vikrentcar'); |
| 7545 |
exit; |
| 7546 |
} |
| 7547 |
$cur_emtpl = array(); |
| 7548 |
$q = "SELECT `setting` FROM `#__vikrentcar_config` WHERE `param`='customemailtpls';"; |
| 7549 |
$dbo->setQuery($q); |
| 7550 |
$dbo->execute(); |
| 7551 |
if ($dbo->getNumRows() > 0) { |
| 7552 |
$cur_emtpl = $dbo->loadResult(); |
| 7553 |
$cur_emtpl = empty($cur_emtpl) ? array() : json_decode($cur_emtpl, true); |
| 7554 |
$cur_emtpl = is_array($cur_emtpl) ? $cur_emtpl : array(); |
| 7555 |
} else { |
| 7556 |
VikError::raiseWarning('', 'Missing Templates Record.'); |
| 7557 |
$mainframe->redirect('index.php?option=com_vikrentcar'); |
| 7558 |
exit; |
| 7559 |
} |
| 7560 |
if (array_key_exists($tplind, $cur_emtpl)) { |
| 7561 |
unset($cur_emtpl[$tplind]); |
| 7562 |
$cur_emtpl = count($cur_emtpl) > 0 ? array_values($cur_emtpl) : array(); |
| 7563 |
$q = "UPDATE `#__vikrentcar_config` SET `setting`=".$dbo->quote(json_encode($cur_emtpl))." WHERE `param`='customemailtpls';"; |
| 7564 |
$dbo->setQuery($q); |
| 7565 |
$dbo->execute(); |
| 7566 |
} |
| 7567 |
$mainframe->redirect('index.php?option=com_vikrentcar&task=editorder&cid[]='.$oid.'&customemail=1'); |
| 7568 |
exit; |
| 7569 |
} |
| 7570 |
|
| 7571 |
public function pmsreports() { |
| 7572 |
VikRentCarHelper::printHeader("pmsreports"); |
| 7573 |
|
| 7574 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'pmsreports')); |
| 7575 |
|
| 7576 |
parent::display(); |
| 7577 |
|
| 7578 |
if (VikRentCar::showFooter()) { |
| 7579 |
VikRentCarHelper::printFooter(); |
| 7580 |
} |
| 7581 |
} |
| 7582 |
|
| 7583 |
public function ratesoverv() { |
| 7584 |
VikRentCarHelper::printHeader("ratesoverv"); |
| 7585 |
|
| 7586 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'ratesoverv')); |
| 7587 |
|
| 7588 |
parent::display(); |
| 7589 |
|
| 7590 |
if (VikRentCar::showFooter()) { |
| 7591 |
VikRentCarHelper::printFooter(); |
| 7592 |
} |
| 7593 |
} |
| 7594 |
|
| 7595 |
public function restrictions() { |
| 7596 |
VikRentCarHelper::printHeader("restrictions"); |
| 7597 |
|
| 7598 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'restrictions')); |
| 7599 |
|
| 7600 |
parent::display(); |
| 7601 |
|
| 7602 |
if (VikRentCar::showFooter()) { |
| 7603 |
VikRentCarHelper::printFooter(); |
| 7604 |
} |
| 7605 |
} |
| 7606 |
|
| 7607 |
public function newrestriction() { |
| 7608 |
VikRentCarHelper::printHeader("restrictions"); |
| 7609 |
|
| 7610 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managerestriction')); |
| 7611 |
|
| 7612 |
parent::display(); |
| 7613 |
|
| 7614 |
if (VikRentCar::showFooter()) { |
| 7615 |
VikRentCarHelper::printFooter(); |
| 7616 |
} |
| 7617 |
} |
| 7618 |
|
| 7619 |
public function editrestriction() { |
| 7620 |
VikRentCarHelper::printHeader("restrictions"); |
| 7621 |
|
| 7622 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managerestriction')); |
| 7623 |
|
| 7624 |
parent::display(); |
| 7625 |
|
| 7626 |
if (VikRentCar::showFooter()) { |
| 7627 |
VikRentCarHelper::printFooter(); |
| 7628 |
} |
| 7629 |
} |
| 7630 |
|
| 7631 |
public function createrestriction() { |
| 7632 |
if (!JSession::checkToken()) { |
| 7633 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 7634 |
} |
| 7635 |
$dbo = JFactory::getDbo(); |
| 7636 |
$mainframe = JFactory::getApplication(); |
| 7637 |
$session = JFactory::getSession(); |
| 7638 |
$pname = VikRequest::getString('name', '', 'request'); |
| 7639 |
$pmonth = VikRequest::getInt('month', '', 'request'); |
| 7640 |
$pmonth = empty($pmonth) ? 0 : $pmonth; |
| 7641 |
$pname = empty($pname) ? 'Restriction '.$pmonth : $pname; |
| 7642 |
$pdfrom = VikRequest::getString('dfrom', '', 'request'); |
| 7643 |
$pdto = VikRequest::getString('dto', '', 'request'); |
| 7644 |
$pwday = VikRequest::getString('wday', '', 'request'); |
| 7645 |
$pwdaytwo = VikRequest::getString('wdaytwo', '', 'request'); |
| 7646 |
$pwdaytwo = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday == $pwdaytwo ? '' : $pwdaytwo; |
| 7647 |
$pcomboa = VikRequest::getString('comboa', '', 'request'); |
| 7648 |
$pcomboa = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo ? $pcomboa : ''; |
| 7649 |
$pcombob = VikRequest::getString('combob', '', 'request'); |
| 7650 |
$pcombob = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo ? $pcombob : ''; |
| 7651 |
$pcomboc = VikRequest::getString('comboc', '', 'request'); |
| 7652 |
$pcomboc = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo ? $pcomboc : ''; |
| 7653 |
$pcombod = VikRequest::getString('combod', '', 'request'); |
| 7654 |
$pcombod = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo ? $pcombod : ''; |
| 7655 |
$combostr = ''; |
| 7656 |
$combostr .= strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo && !empty($pcomboa) ? $pcomboa.':' : ':'; |
| 7657 |
$combostr .= strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo && !empty($pcombob) ? $pcombob.':' : ':'; |
| 7658 |
$combostr .= strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo && !empty($pcomboc) ? $pcomboc.':' : ':'; |
| 7659 |
$combostr .= strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo && !empty($pcombod) ? $pcombod : ''; |
| 7660 |
$pminlos = VikRequest::getInt('minlos', 0, 'request'); |
| 7661 |
$pminlos = $pminlos < 0 ? 1 : $pminlos; |
| 7662 |
$pmaxlos = VikRequest::getInt('maxlos', 0, 'request'); |
| 7663 |
$pmaxlos = empty($pmaxlos) ? 0 : $pmaxlos; |
| 7664 |
$pmultiplyminlos = VikRequest::getString('multiplyminlos', '', 'request'); |
| 7665 |
$pmultiplyminlos = empty($pmultiplyminlos) ? 0 : 1; |
| 7666 |
$pallcars = VikRequest::getString('allcars', '', 'request'); |
| 7667 |
$pallcars = $pallcars == "1" ? 1 : 0; |
| 7668 |
$pidcars = VikRequest::getVar('idcars', array(0)); |
| 7669 |
$ridr = ''; |
| 7670 |
$caridsforsess = array(); |
| 7671 |
if (!empty($pidcars) && @count($pidcars) && $pallcars == 0) { |
| 7672 |
foreach ($pidcars as $idr) { |
| 7673 |
if (empty($idr)) { |
| 7674 |
continue; |
| 7675 |
} |
| 7676 |
$ridr .= '-'.$idr.'-;'; |
| 7677 |
$caridsforsess[] = (int)$idr; |
| 7678 |
} |
| 7679 |
} elseif ($pallcars > 0) { |
| 7680 |
$q = "SELECT `id` FROM `#__vikrentcar_cars`;"; |
| 7681 |
$dbo->setQuery($q); |
| 7682 |
$dbo->execute(); |
| 7683 |
if ($dbo->getNumRows() > 0) { |
| 7684 |
$fetchids = $dbo->loadAssocList(); |
| 7685 |
foreach ($fetchids as $fetchid) { |
| 7686 |
$caridsforsess[] = (int)$fetchid['id']; |
| 7687 |
} |
| 7688 |
} |
| 7689 |
} |
| 7690 |
$pcta = VikRequest::getInt('cta', '', 'request'); |
| 7691 |
$pctd = VikRequest::getInt('ctd', '', 'request'); |
| 7692 |
$pctad = VikRequest::getVar('ctad', array()); |
| 7693 |
$pctdd = VikRequest::getVar('ctdd', array()); |
| 7694 |
if (!$pminlos && !strlen($pwday) && empty($pctad) && empty($pctdd)) { |
| 7695 |
VikError::raiseWarning('', JText::translate('VRUSELESSRESTRICTION')); |
| 7696 |
$mainframe = JFactory::getApplication(); |
| 7697 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newrestriction"); |
| 7698 |
$mainframe->close(); |
| 7699 |
} else { |
| 7700 |
//check if there are restrictions for this month |
| 7701 |
if ($pmonth > 0) { |
| 7702 |
$q = "SELECT `id` FROM `#__vikrentcar_restrictions` WHERE `month`='".$pmonth."';"; |
| 7703 |
$dbo->setQuery($q); |
| 7704 |
$dbo->execute(); |
| 7705 |
if ($dbo->getNumRows() > 0) { |
| 7706 |
VikError::raiseWarning('', JText::translate('VRRESTRICTIONMONTHEXISTS')); |
| 7707 |
$mainframe = JFactory::getApplication(); |
| 7708 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newrestriction"); |
| 7709 |
} |
| 7710 |
$pdfrom = 0; |
| 7711 |
$pdto = 0; |
| 7712 |
} else { |
| 7713 |
//dates range |
| 7714 |
if (empty($pdfrom) || empty($pdto)) { |
| 7715 |
VikError::raiseWarning('', JText::translate('VRRESTRICTIONERRDRANGE')); |
| 7716 |
$mainframe = JFactory::getApplication(); |
| 7717 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newrestriction"); |
| 7718 |
} else { |
| 7719 |
$pdfrom = VikRentCar::getDateTimestamp($pdfrom, 0, 0); |
| 7720 |
$pdto = VikRentCar::getDateTimestamp($pdto, 0, 0); |
| 7721 |
} |
| 7722 |
} |
| 7723 |
//CTA and CTD |
| 7724 |
$setcta = array(); |
| 7725 |
$setctd = array(); |
| 7726 |
if ($pcta > 0 && count($pctad) > 0) { |
| 7727 |
foreach ($pctad as $ctwd) { |
| 7728 |
if (strlen($ctwd)) { |
| 7729 |
$setcta[] = '-'.(int)$ctwd.'-'; |
| 7730 |
} |
| 7731 |
} |
| 7732 |
} |
| 7733 |
if ($pctd > 0 && count($pctdd) > 0) { |
| 7734 |
foreach ($pctdd as $ctwd) { |
| 7735 |
if (strlen($ctwd)) { |
| 7736 |
$setctd[] = '-'.(int)$ctwd.'-'; |
| 7737 |
} |
| 7738 |
} |
| 7739 |
} |
| 7740 |
// |
| 7741 |
$q = "INSERT INTO `#__vikrentcar_restrictions` (`name`,`month`,`wday`,`minlos`,`multiplyminlos`,`maxlos`,`dfrom`,`dto`,`wdaytwo`,`wdaycombo`,`allcars`,`idcars`,`ctad`,`ctdd`) VALUES(".$dbo->quote($pname).", '".$pmonth."', ".(strlen($pwday) > 0 ? "'".$pwday."'" : "NULL").", '".$pminlos."', '".$pmultiplyminlos."', '".$pmaxlos."', ".$pdfrom.", ".$pdto.", ".(strlen($pwday) > 0 && strlen($pwdaytwo) > 0 ? intval($pwdaytwo) : "NULL").", ".(strlen($combostr) > 0 ? $dbo->quote($combostr) : "NULL").", ".$pallcars.", ".(strlen($ridr) > 0 ? $dbo->quote($ridr) : "NULL").", ".(count($setcta) > 0 ? $dbo->quote(implode(',', $setcta)) : "NULL").", ".(count($setctd) > 0 ? $dbo->quote(implode(',', $setctd)) : "NULL").");"; |
| 7742 |
$dbo->setQuery($q); |
| 7743 |
$dbo->execute(); |
| 7744 |
$lid = $dbo->insertid(); |
| 7745 |
if (!empty($lid)) { |
| 7746 |
/** |
| 7747 |
* Repeat restriction on the selected week days until the limit |
| 7748 |
* |
| 7749 |
* @since 1.14 |
| 7750 |
*/ |
| 7751 |
$prepeat = VikRequest::getInt('repeat', 0, 'request'); |
| 7752 |
$prepeatuntil = VikRequest::getString('repeatuntil', '', 'request'); |
| 7753 |
if ($prepeat > 0 && !empty($prepeatuntil) && $pdfrom > 0 && $pdto > 0) { |
| 7754 |
$repeat_intervals = array(); |
| 7755 |
$start = getdate($pdfrom); |
| 7756 |
$end = getdate($pdto); |
| 7757 |
$wdays = array(); |
| 7758 |
while ($start[0] <= $end[0]) { |
| 7759 |
// push requested week day |
| 7760 |
array_push($wdays, $start['wday']); |
| 7761 |
// next day |
| 7762 |
$start = getdate(mktime($start['hours'], $start['minutes'], $start['seconds'], $start['mon'], ($start['mday'] + 1), $start['year'])); |
| 7763 |
} |
| 7764 |
$dtuntil = VikRentCar::getDateTimestamp($prepeatuntil, 23, 59, 59); |
| 7765 |
if (count($wdays) < 7 && $dtuntil > $pdto) { |
| 7766 |
// increment end date for the repeat |
| 7767 |
$end = getdate(mktime($end['hours'], $end['minutes'], $end['seconds'], $end['mon'], ($end['mday'] + 1), $end['year'])); |
| 7768 |
// |
| 7769 |
$until_info = getdate($dtuntil); |
| 7770 |
$interval = array(); |
| 7771 |
while ($end[0] <= $until_info[0]) { |
| 7772 |
if (in_array($end['wday'], $wdays)) { |
| 7773 |
if (!isset($interval['from'])) { |
| 7774 |
$interval['from'] = $end[0]; |
| 7775 |
} |
| 7776 |
$interval['to'] = $end[0]; |
| 7777 |
} else { |
| 7778 |
if (isset($interval['from'])) { |
| 7779 |
// append interval |
| 7780 |
array_push($repeat_intervals, $interval); |
| 7781 |
// reset interval |
| 7782 |
$interval = array(); |
| 7783 |
} |
| 7784 |
} |
| 7785 |
// next day |
| 7786 |
$end = getdate(mktime($end['hours'], $end['minutes'], $end['seconds'], $end['mon'], ($end['mday'] + 1), $end['year'])); |
| 7787 |
} |
| 7788 |
if (isset($interval['from'])) { |
| 7789 |
// append last hanging interval |
| 7790 |
array_push($repeat_intervals, $interval); |
| 7791 |
} |
| 7792 |
if (count($repeat_intervals)) { |
| 7793 |
// create the repeated records for the calculated intervals |
| 7794 |
$repeat_count = 2; |
| 7795 |
foreach ($repeat_intervals as $rp) { |
| 7796 |
if (date('Y-m-d', $rp['from']) == date('Y-m-d', $rp['to'])) { |
| 7797 |
// adjust time in case of equal dates (1 single day restriction) |
| 7798 |
$rpfrom = getdate($rp['from']); |
| 7799 |
$rpto = getdate($rp['to']); |
| 7800 |
$rp['from'] = mktime(0, 0, 0, $rpfrom['mon'], $rpfrom['mday'], $rpfrom['year']); |
| 7801 |
$rp['to'] = mktime(0, 0, 0, $rpto['mon'], $rpto['mday'], $rpto['year']); |
| 7802 |
} |
| 7803 |
// adjust name |
| 7804 |
$restr_rp_name = $pname . " #{$repeat_count}"; |
| 7805 |
// |
| 7806 |
$q = "INSERT INTO `#__vikrentcar_restrictions` (`name`,`month`,`wday`,`minlos`,`multiplyminlos`,`maxlos`,`dfrom`,`dto`,`wdaytwo`,`wdaycombo`,`allcars`,`idcars`,`ctad`,`ctdd`) VALUES(".$dbo->quote($restr_rp_name).", '".$pmonth."', ".(strlen($pwday) > 0 ? "'".$pwday."'" : "NULL").", '".$pminlos."', '".$pmultiplyminlos."', '".$pmaxlos."', ".$rp['from'].", ".$rp['to'].", ".(strlen($pwday) > 0 && strlen($pwdaytwo) > 0 ? intval($pwdaytwo) : "NULL").", ".(strlen($combostr) > 0 ? $dbo->quote($combostr) : "NULL").", ".$pallcars.", ".(strlen($ridr) > 0 ? $dbo->quote($ridr) : "NULL").", ".(count($setcta) > 0 ? $dbo->quote(implode(',', $setcta)) : "NULL").", ".(count($setctd) > 0 ? $dbo->quote(implode(',', $setctd)) : "NULL").");"; |
| 7807 |
$dbo->setQuery($q); |
| 7808 |
$dbo->execute(); |
| 7809 |
$lid = $dbo->insertid(); |
| 7810 |
if (!empty($lid)) { |
| 7811 |
$repeat_count++; |
| 7812 |
} |
| 7813 |
} |
| 7814 |
} |
| 7815 |
} |
| 7816 |
} |
| 7817 |
// |
| 7818 |
$mainframe->enqueueMessage(JText::translate('VRRESTRICTIONSAVED')); |
| 7819 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=restrictions"); |
| 7820 |
} else { |
| 7821 |
VikError::raiseWarning('', 'Error while saving'); |
| 7822 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=newrestriction"); |
| 7823 |
} |
| 7824 |
} |
| 7825 |
} |
| 7826 |
|
| 7827 |
public function updaterestriction() { |
| 7828 |
if (!JSession::checkToken()) { |
| 7829 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 7830 |
} |
| 7831 |
$dbo = JFactory::getDbo(); |
| 7832 |
$mainframe = JFactory::getApplication(); |
| 7833 |
$session = JFactory::getSession(); |
| 7834 |
$pwhere = VikRequest::getInt('where', '', 'request'); |
| 7835 |
$pname = VikRequest::getString('name', '', 'request'); |
| 7836 |
$pmonth = VikRequest::getInt('month', '', 'request'); |
| 7837 |
$pmonth = empty($pmonth) ? 0 : $pmonth; |
| 7838 |
$pname = empty($pname) ? 'Restriction '.$pmonth : $pname; |
| 7839 |
$pdfrom = VikRequest::getString('dfrom', '', 'request'); |
| 7840 |
$pdto = VikRequest::getString('dto', '', 'request'); |
| 7841 |
$pwday = VikRequest::getString('wday', '', 'request'); |
| 7842 |
$pwdaytwo = VikRequest::getString('wdaytwo', '', 'request'); |
| 7843 |
$pwdaytwo = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday == $pwdaytwo ? '' : $pwdaytwo; |
| 7844 |
$pcomboa = VikRequest::getString('comboa', '', 'request'); |
| 7845 |
$pcomboa = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo ? $pcomboa : ''; |
| 7846 |
$pcombob = VikRequest::getString('combob', '', 'request'); |
| 7847 |
$pcombob = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo ? $pcombob : ''; |
| 7848 |
$pcomboc = VikRequest::getString('comboc', '', 'request'); |
| 7849 |
$pcomboc = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo ? $pcomboc : ''; |
| 7850 |
$pcombod = VikRequest::getString('combod', '', 'request'); |
| 7851 |
$pcombod = strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo ? $pcombod : ''; |
| 7852 |
$combostr = ''; |
| 7853 |
$combostr .= strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo && !empty($pcomboa) ? $pcomboa.':' : ':'; |
| 7854 |
$combostr .= strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo && !empty($pcombob) ? $pcombob.':' : ':'; |
| 7855 |
$combostr .= strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo && !empty($pcomboc) ? $pcomboc.':' : ':'; |
| 7856 |
$combostr .= strlen($pwday) > 0 && strlen($pwdaytwo) > 0 && $pwday != $pwdaytwo && !empty($pcombod) ? $pcombod : ''; |
| 7857 |
$pminlos = VikRequest::getInt('minlos', 0, 'request'); |
| 7858 |
$pminlos = $pminlos < 0 ? 1 : $pminlos; |
| 7859 |
$pmaxlos = VikRequest::getInt('maxlos', 0, 'request'); |
| 7860 |
$pmaxlos = empty($pmaxlos) ? 0 : $pmaxlos; |
| 7861 |
$pmultiplyminlos = VikRequest::getString('multiplyminlos', '', 'request'); |
| 7862 |
$pmultiplyminlos = empty($pmultiplyminlos) ? 0 : 1; |
| 7863 |
$pallcars = VikRequest::getString('allcars', '', 'request'); |
| 7864 |
$pallcars = $pallcars == "1" ? 1 : 0; |
| 7865 |
$pidcars = VikRequest::getVar('idcars', array(0)); |
| 7866 |
$ridr = ''; |
| 7867 |
$caridsforsess = array(); |
| 7868 |
if (!empty($pidcars) && @count($pidcars) && $pallcars == 0) { |
| 7869 |
foreach ($pidcars as $idr) { |
| 7870 |
if (empty($idr)) { |
| 7871 |
continue; |
| 7872 |
} |
| 7873 |
$ridr .= '-'.$idr.'-;'; |
| 7874 |
$caridsforsess[] = (int)$idr; |
| 7875 |
} |
| 7876 |
} elseif ($pallcars > 0) { |
| 7877 |
$q = "SELECT `id` FROM `#__vikrentcar_cars`;"; |
| 7878 |
$dbo->setQuery($q); |
| 7879 |
$dbo->execute(); |
| 7880 |
if ($dbo->getNumRows() > 0) { |
| 7881 |
$fetchids = $dbo->loadAssocList(); |
| 7882 |
foreach ($fetchids as $fetchid) { |
| 7883 |
$caridsforsess[] = (int)$fetchid['id']; |
| 7884 |
} |
| 7885 |
} |
| 7886 |
} |
| 7887 |
$pcta = VikRequest::getInt('cta', '', 'request'); |
| 7888 |
$pctd = VikRequest::getInt('ctd', '', 'request'); |
| 7889 |
$pctad = VikRequest::getVar('ctad', array()); |
| 7890 |
$pctdd = VikRequest::getVar('ctdd', array()); |
| 7891 |
if (!$pminlos && !strlen($pwday) && empty($pctad) && empty($pctdd)) { |
| 7892 |
VikError::raiseWarning('', JText::translate('VRUSELESSRESTRICTION')); |
| 7893 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editrestriction&cid[]=".$pwhere); |
| 7894 |
$mainframe->close(); |
| 7895 |
} else { |
| 7896 |
//check if there are restrictions for this month |
| 7897 |
if ($pmonth > 0) { |
| 7898 |
$q = "SELECT `id` FROM `#__vikrentcar_restrictions` WHERE `month`='".$pmonth."' AND `id`!='".$pwhere."';"; |
| 7899 |
$dbo->setQuery($q); |
| 7900 |
$dbo->execute(); |
| 7901 |
if ($dbo->getNumRows() > 0) { |
| 7902 |
VikError::raiseWarning('', JText::translate('VRRESTRICTIONMONTHEXISTS')); |
| 7903 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editrestriction&cid[]=".$pwhere); |
| 7904 |
} |
| 7905 |
$pdfrom = 0; |
| 7906 |
$pdto = 0; |
| 7907 |
} else { |
| 7908 |
//dates range |
| 7909 |
if (empty($pdfrom) || empty($pdto)) { |
| 7910 |
VikError::raiseWarning('', JText::translate('VRRESTRICTIONERRDRANGE')); |
| 7911 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=editrestriction&cid[]=".$pwhere); |
| 7912 |
} else { |
| 7913 |
$pdfrom = VikRentCar::getDateTimestamp($pdfrom, 0, 0); |
| 7914 |
$pdto = VikRentCar::getDateTimestamp($pdto, 0, 0); |
| 7915 |
} |
| 7916 |
} |
| 7917 |
//CTA and CTD |
| 7918 |
$setcta = array(); |
| 7919 |
$setctd = array(); |
| 7920 |
if ($pcta > 0 && count($pctad) > 0) { |
| 7921 |
foreach ($pctad as $ctwd) { |
| 7922 |
if (strlen($ctwd)) { |
| 7923 |
$setcta[] = '-'.(int)$ctwd.'-'; |
| 7924 |
} |
| 7925 |
} |
| 7926 |
} |
| 7927 |
if ($pctd > 0 && count($pctdd) > 0) { |
| 7928 |
foreach ($pctdd as $ctwd) { |
| 7929 |
if (strlen($ctwd)) { |
| 7930 |
$setctd[] = '-'.(int)$ctwd.'-'; |
| 7931 |
} |
| 7932 |
} |
| 7933 |
} |
| 7934 |
// |
| 7935 |
$q = "UPDATE `#__vikrentcar_restrictions` SET `name`=".$dbo->quote($pname).",`month`='".$pmonth."',`wday`=".(strlen($pwday) > 0 ? "'".$pwday."'" : "NULL").",`minlos`='".$pminlos."',`multiplyminlos`='".$pmultiplyminlos."',`maxlos`='".$pmaxlos."',`dfrom`=".$pdfrom.",`dto`=".$pdto.",`wdaytwo`=".(strlen($pwday) > 0 && strlen($pwdaytwo) > 0 ? intval($pwdaytwo) : "NULL").",`wdaycombo`=".(strlen($combostr) > 0 ? $dbo->quote($combostr) : "NULL").",`allcars`=".$pallcars.",`idcars`=".(strlen($ridr) > 0 ? $dbo->quote($ridr) : "NULL").", `ctad`=".(count($setcta) > 0 ? $dbo->quote(implode(',', $setcta)) : "NULL").", `ctdd`=".(count($setctd) > 0 ? $dbo->quote(implode(',', $setctd)) : "NULL")." WHERE `id`='".$pwhere."';"; |
| 7936 |
$dbo->setQuery($q); |
| 7937 |
$dbo->execute(); |
| 7938 |
$mainframe->enqueueMessage(JText::translate('VRRESTRICTIONSAVED')); |
| 7939 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=restrictions"); |
| 7940 |
} |
| 7941 |
} |
| 7942 |
|
| 7943 |
public function removerestrictions() { |
| 7944 |
if (!JSession::checkToken()) { |
| 7945 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 7946 |
} |
| 7947 |
$ids = VikRequest::getVar('cid', array(0)); |
| 7948 |
if (@count($ids)) { |
| 7949 |
$dbo = JFactory::getDbo(); |
| 7950 |
foreach ($ids as $d) { |
| 7951 |
$q = "DELETE FROM `#__vikrentcar_restrictions` WHERE `id`=".(int)$d.";"; |
| 7952 |
$dbo->setQuery($q); |
| 7953 |
$dbo->execute(); |
| 7954 |
} |
| 7955 |
} |
| 7956 |
$mainframe = JFactory::getApplication(); |
| 7957 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=restrictions"); |
| 7958 |
} |
| 7959 |
|
| 7960 |
public function cancelrestriction() { |
| 7961 |
$mainframe = JFactory::getApplication(); |
| 7962 |
$mainframe->redirect("index.php?option=com_vikrentcar&task=restrictions"); |
| 7963 |
} |
| 7964 |
|
| 7965 |
public function modcarrateplans() { |
| 7966 |
$dbo = JFactory::getDbo(); |
| 7967 |
$pid_car = VikRequest::getInt('id_car', '', 'request'); |
| 7968 |
$pid_price = VikRequest::getInt('id_price', '', 'request'); |
| 7969 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 7970 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 7971 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 7972 |
if (empty($pid_car) || empty($pid_price) || empty($ptype) || empty($pfromdate) || empty($ptodate) || !(strtotime($pfromdate) > 0) || !(strtotime($ptodate) > 0)) { |
| 7973 |
echo 'e4j.error.'.addslashes(JText::translate('VRRATESOVWERRMODRPLANS')); |
| 7974 |
exit; |
| 7975 |
} |
| 7976 |
$price_record = array(); |
| 7977 |
$q = "SELECT * FROM `#__vikrentcar_prices` WHERE `id`=".$pid_price.";"; |
| 7978 |
$dbo->setQuery($q); |
| 7979 |
$dbo->execute(); |
| 7980 |
if ($dbo->getNumRows() > 0) { |
| 7981 |
$price_record = $dbo->loadAssoc(); |
| 7982 |
} |
| 7983 |
if (!count($price_record) > 0) { |
| 7984 |
echo 'e4j.error.'.addslashes(JText::translate('VRRATESOVWERRMODRPLANS')).'.'; |
| 7985 |
exit; |
| 7986 |
} |
| 7987 |
$current_closed = array(); |
| 7988 |
if (!empty($price_record['closingd'])) { |
| 7989 |
$current_closed = json_decode($price_record['closingd'], true); |
| 7990 |
if (!is_array($current_closed)) { |
| 7991 |
$current_closed = array(); |
| 7992 |
} |
| 7993 |
} |
| 7994 |
$start_ts = strtotime($pfromdate); |
| 7995 |
$end_ts = strtotime($ptodate); |
| 7996 |
$infostart = getdate($start_ts); |
| 7997 |
$all_days = array(); |
| 7998 |
$output = array(); |
| 7999 |
while ($infostart[0] > 0 && $infostart[0] <= $end_ts) { |
| 8000 |
$all_days[] = date('Y-m-d', $infostart[0]); |
| 8001 |
$indkey = $infostart['mday'].'-'.$infostart['mon'].'-'.$infostart['year'].'-'.$pid_price; |
| 8002 |
$output[$indkey] = array(); |
| 8003 |
$infostart = getdate(mktime(0, 0, 0, $infostart['mon'], ($infostart['mday'] + 1), $infostart['year'])); |
| 8004 |
} |
| 8005 |
if ($ptype == 'close') { |
| 8006 |
if (!array_key_exists($pid_car, $current_closed)) { |
| 8007 |
$current_closed[$pid_car] = array(); |
| 8008 |
} |
| 8009 |
foreach ($all_days as $daymod) { |
| 8010 |
if (!in_array($daymod, $current_closed[$pid_car])) { |
| 8011 |
$current_closed[$pid_car][] = $daymod; |
| 8012 |
} |
| 8013 |
} |
| 8014 |
} else { |
| 8015 |
//open |
| 8016 |
if (array_key_exists($pid_car, $current_closed)) { |
| 8017 |
foreach ($all_days as $daymod) { |
| 8018 |
if (in_array($daymod, $current_closed[$pid_car])) { |
| 8019 |
foreach ($current_closed[$pid_car] as $ck => $cv) { |
| 8020 |
if ($daymod == $cv) { |
| 8021 |
unset($current_closed[$pid_car][$ck]); |
| 8022 |
} |
| 8023 |
} |
| 8024 |
} |
| 8025 |
} |
| 8026 |
} else { |
| 8027 |
$current_closed[$pid_car] = array(); |
| 8028 |
} |
| 8029 |
} |
| 8030 |
if (!count($current_closed[$pid_car]) > 0) { |
| 8031 |
unset($current_closed[$pid_car]); |
| 8032 |
} |
| 8033 |
$q = "UPDATE `#__vikrentcar_prices` SET `closingd`=".(count($current_closed) > 0 ? $dbo->quote(json_encode($current_closed)) : "NULL")." WHERE `id`=".(int)$pid_price.";"; |
| 8034 |
$dbo->setQuery($q); |
| 8035 |
$dbo->execute(); |
| 8036 |
$oldcsscls = $ptype == 'close' ? 'vrc-roverw-rplan-on' : 'vrc-roverw-rplan-off'; |
| 8037 |
$newcsscls = $ptype == 'close' ? 'vrc-roverw-rplan-off' : 'vrc-roverw-rplan-on'; |
| 8038 |
foreach ($output as $ok => $ov) { |
| 8039 |
$output[$ok] = array('oldcls' => $oldcsscls, 'newcls' => $newcsscls); |
| 8040 |
} |
| 8041 |
|
| 8042 |
$pdebug = VikRequest::getInt('e4j_debug', '', 'request'); |
| 8043 |
if ($pdebug == 1) { |
| 8044 |
echo "e4j.error.\n".print_r($current_closed, true)."\n"; |
| 8045 |
echo print_r($output, true)."\n\n"; |
| 8046 |
echo print_r($all_days, true)."\n"; |
| 8047 |
} |
| 8048 |
echo json_encode($output); |
| 8049 |
exit; |
| 8050 |
} |
| 8051 |
|
| 8052 |
public function calc_rates() |
| 8053 |
{ |
| 8054 |
$response = 'e4j.error.ErrorCode(1) Server is blocking the self-request'; |
| 8055 |
|
| 8056 |
$currencysymb = VikRentCar::getCurrencySymb(); |
| 8057 |
$vrc_df = VikRentCar::getDateFormat(); |
| 8058 |
$df = $vrc_df == "%d/%m/%Y" ? 'd/m/Y' : ($vrc_df == "%m/%d/%Y" ? 'm/d/Y' : 'Y/m/d'); |
| 8059 |
|
| 8060 |
$pcheckinh = 0; |
| 8061 |
$pcheckinm = 0; |
| 8062 |
$pcheckouth = 0; |
| 8063 |
$pcheckoutm = 0; |
| 8064 |
$timeopst = VikRentCar::getTimeOpenStore(); |
| 8065 |
if (is_array($timeopst)) { |
| 8066 |
$opent = VikRentCar::getHoursMinutes($timeopst[0]); |
| 8067 |
$closet = VikRentCar::getHoursMinutes($timeopst[1]); |
| 8068 |
$pcheckinh = $opent[0]; |
| 8069 |
$pcheckinm = $opent[1]; |
| 8070 |
// set drop off time equal to pick up time to avoid getting extra days of rent |
| 8071 |
$pcheckouth = $pcheckinh; |
| 8072 |
$pcheckoutm = $pcheckinm; |
| 8073 |
} |
| 8074 |
|
| 8075 |
$id_car = VikRequest::getInt('id_car', '', 'request'); |
| 8076 |
$pickup = VikRequest::getString('pickup', '', 'request'); |
| 8077 |
$days = VikRequest::getInt('num_days', 1, 'request'); |
| 8078 |
|
| 8079 |
/** |
| 8080 |
* The page Calendar may call this task via AJAX to obtain information |
| 8081 |
* about the various rate plans and final costs associated. |
| 8082 |
* |
| 8083 |
* @since 1.14 (J) - 1.1.0 (WP) |
| 8084 |
*/ |
| 8085 |
$only_rates = VikRequest::getInt('only_rates', 0, 'request'); |
| 8086 |
$units = VikRequest::getInt('units', 1, 'request'); |
| 8087 |
$checkinfdate = VikRequest::getString('checkinfdate', '', 'request'); |
| 8088 |
|
| 8089 |
if (!empty($checkinfdate) && empty($pickup)) { |
| 8090 |
$pickup = date('Y-m-d', VikRentCar::getDateTimestamp($checkinfdate, 0, 0, 0)); |
| 8091 |
} |
| 8092 |
$price_details = array(); |
| 8093 |
|
| 8094 |
$pickup_ts = strtotime($pickup); |
| 8095 |
if (empty($pickup_ts)) { |
| 8096 |
$pickup = date('Y-m-d'); |
| 8097 |
$pickup_ts = strtotime($pickup); |
| 8098 |
} |
| 8099 |
$is_dst = date('I', $pickup_ts); |
| 8100 |
$dropoff_ts = $pickup_ts; |
| 8101 |
for ($i = 1; $i <= $days; $i++) { |
| 8102 |
$dropoff_ts += 86400; |
| 8103 |
$is_now_dst = date('I', $dropoff_ts); |
| 8104 |
if ($is_dst != $is_now_dst) { |
| 8105 |
if ((int)$is_dst == 1) { |
| 8106 |
$dropoff_ts += 3600; |
| 8107 |
} else { |
| 8108 |
$dropoff_ts -= 3600; |
| 8109 |
} |
| 8110 |
$is_dst = $is_now_dst; |
| 8111 |
} |
| 8112 |
} |
| 8113 |
$checkout = date('Y-m-d', $dropoff_ts); |
| 8114 |
|
| 8115 |
/** |
| 8116 |
* Check if the request contains the requested times for pickup and drop off. |
| 8117 |
* |
| 8118 |
* @since 1.15.6 (J) - 1.4.1 (WP) |
| 8119 |
*/ |
| 8120 |
$booking_times = JFactory::getApplication()->input->get('times', [], 'array'); |
| 8121 |
if ($booking_times) { |
| 8122 |
// overwrite times for pickup and drop off by using the request values |
| 8123 |
$pcheckinh = (int) ($booking_times['pickup_h'] ?? $pcheckinh); |
| 8124 |
$pcheckinm = (int) ($booking_times['pickup_m'] ?? 0); |
| 8125 |
$pcheckouth = (int) ($booking_times['dropoff_h'] ?? $pcheckouth); |
| 8126 |
$pcheckoutm = (int) ($booking_times['dropoff_m'] ?? 0); |
| 8127 |
} |
| 8128 |
|
| 8129 |
$endpoint = VikRentCar::externalroute('index.php?option=com_vikrentcar&task=search'); |
| 8130 |
if (VRCPlatformDetection::isWordPress()) { |
| 8131 |
/** |
| 8132 |
* @wponly Rewrite URI for front-end |
| 8133 |
*/ |
| 8134 |
$model = JModel::getInstance('vikrentcar', 'shortcodes'); |
| 8135 |
$itemid = $model->best('vikrentcar'); |
| 8136 |
if ($itemid) { |
| 8137 |
$endpoint = str_replace(JUri::root(), '', $endpoint); |
| 8138 |
$endpoint = JRoute::rewrite($endpoint . "&Itemid={$itemid}", false); |
| 8139 |
} |
| 8140 |
} |
| 8141 |
|
| 8142 |
$rates_data = 'e4jauth=%s&getjson=1&pickupdate='.date($df, $pickup_ts).'&pickuph='.$pcheckinh.'&pickupm='.$pcheckinm.'&releasedate='.date($df, $dropoff_ts).'&releaseh='.$pcheckouth.'&releasem='.$pcheckoutm; |
| 8143 |
|
| 8144 |
// start CMS's native HTTP transporter |
| 8145 |
$http = new JHttp(); |
| 8146 |
$headers = array( |
| 8147 |
'Content-Type' => 'application/x-www-form-urlencoded' |
| 8148 |
); |
| 8149 |
|
| 8150 |
$cua = VikRequest::getString('HTTP_USER_AGENT', '', 'server'); |
| 8151 |
if (!empty($cua)) { |
| 8152 |
$headers['userAgent'] = $cua; |
| 8153 |
} |
| 8154 |
|
| 8155 |
$result = $http->post($endpoint, sprintf($rates_data, md5('vrc.e4j.vrc')), $headers); |
| 8156 |
if ($result->code != 200) { |
| 8157 |
$response = "e4j.error.Communication error ({$result->code}): {$result->body}"; |
| 8158 |
} else { |
| 8159 |
$res = $result->body; |
| 8160 |
$arr_res = json_decode($res, true); |
| 8161 |
|
| 8162 |
/** |
| 8163 |
* We try to check if decoding was unsuccessful, maybe because the response is mixed with HTML code of the Template/Theme. |
| 8164 |
* In this case we try to extract the JSON string from the plain response to decode only that text. |
| 8165 |
* |
| 8166 |
* @since 1.14 Rev2 (J) - 1.1.3 (WP) |
| 8167 |
*/ |
| 8168 |
if (function_exists('json_last_error') && json_last_error() !== JSON_ERROR_NONE) { |
| 8169 |
$pattern = '/\{(?:[^{}]|(?R))*\}/x'; |
| 8170 |
$matchcount = preg_match_all($pattern, $res, $matches); |
| 8171 |
if ($matchcount && isset($matches[0]) && count($matches[0])) { |
| 8172 |
// we have found JSON strings inside the raw response, we get the last JSON string |
| 8173 |
$arr_res = json_decode($matches[0][(count($matches[0]) - 1)], true); |
| 8174 |
} |
| 8175 |
} |
| 8176 |
// |
| 8177 |
|
| 8178 |
if (is_array($arr_res)) { |
| 8179 |
if (!array_key_exists('e4j.error', $arr_res)) { |
| 8180 |
if (array_key_exists($id_car, $arr_res)) { |
| 8181 |
$response = ''; |
| 8182 |
foreach ($arr_res[$id_car] as $rate) { |
| 8183 |
// build pricing object |
| 8184 |
$rplan_details = new stdClass; |
| 8185 |
$rplan_details->idprice = $rate['idprice']; |
| 8186 |
$rplan_details->name = $rate['pricename']; |
| 8187 |
$rplan_details->tot = $rate['cost']; |
| 8188 |
$rplan_details->ftot = $currencysymb . ' ' . VikRentCar::numberFormat(($rate['cost'])); |
| 8189 |
array_push($price_details, $rplan_details); |
| 8190 |
// |
| 8191 |
$extra_response = ''; |
| 8192 |
$response .= '<div class="vrc-calcrates-rateblock" data-idprice="' . $rate['idprice'] . '" data-idcar="' . $id_car . '" data-pickup="' . $pickup . '" data-dropoff="' . $checkout . '">'; |
| 8193 |
$response .= '<span class="vrc-calcrates-ratename">'.$rate['pricename'].'</span>'; |
| 8194 |
if (array_key_exists('affdays', $rate) && $rate['affdays'] > 0) { |
| 8195 |
$extra_response .= '<span class="vrc-calcrates-extrapricedet vrc-calcrates-ratespaffdays"><span>'.JText::translate('VRCALCRATESSPAFFDAYS').'</span>'.$rate['affdays'].'</span>'; |
| 8196 |
} |
| 8197 |
$tot = round($rate['cost'], 2); |
| 8198 |
$response .= '<span class="vrc-calcrates-pricedet vrc-calcrates-ratetotal"><span>'.JText::translate('VRCALCRATESTOT').'</span>'.$currencysymb.' '.VikRentCar::numberFormat($tot).'</span>'; |
| 8199 |
if (!empty($extra_response)) { |
| 8200 |
$response .= '<div class="vrc-calcrates-info">'.$extra_response.'</div>'; |
| 8201 |
} |
| 8202 |
$response .= '</div>'; |
| 8203 |
} |
| 8204 |
//Debug |
| 8205 |
//$response .= '<br/><pre>'.print_r($arr_res, true).'</pre><br/>'; |
| 8206 |
} else { |
| 8207 |
$response = 'e4j.error.'.JText::sprintf('VRCALCRATESCARNOTAVAILCOMBO', date($df, $pickup_ts), date($df, $dropoff_ts)); |
| 8208 |
} |
| 8209 |
} else { |
| 8210 |
$response = 'e4j.error.'.$arr_res['e4j.error']; |
| 8211 |
} |
| 8212 |
} else { |
| 8213 |
$response = (strpos($res, 'e4j.error') === false ? 'e4j.error' : '').$res; |
| 8214 |
} |
| 8215 |
} |
| 8216 |
|
| 8217 |
if ($only_rates && strpos($response, 'e4j.error') === false) { |
| 8218 |
echo json_encode($price_details); |
| 8219 |
exit; |
| 8220 |
} |
| 8221 |
|
| 8222 |
// Do not do only echo trim($response); or the currency symbol may not be encoded on some servers |
| 8223 |
echo json_encode(array(trim($response))); |
| 8224 |
exit; |
| 8225 |
} |
| 8226 |
|
| 8227 |
/** |
| 8228 |
* AJAX request made to get the information about certain rental orders. |
| 8229 |
* |
| 8230 |
* @return void |
| 8231 |
* |
| 8232 |
* @since 1.13 |
| 8233 |
*/ |
| 8234 |
public function getordersinfo() { |
| 8235 |
$dbo = JFactory::getDbo(); |
| 8236 |
$booking_infos = array(); |
| 8237 |
$bookings = array(); |
| 8238 |
$pidorders = VikRequest::getString('idorders', '', 'request'); |
| 8239 |
$psubcar = VikRequest::getString('subcar', '', 'request'); |
| 8240 |
if (!empty($pidorders)) { |
| 8241 |
$bookings = explode(',', $pidorders); |
| 8242 |
foreach ($bookings as $k => $v) { |
| 8243 |
$v = intval(str_replace('-', '', $v)); |
| 8244 |
if (empty($v)) { |
| 8245 |
unset($bookings[$k]); |
| 8246 |
continue; |
| 8247 |
} |
| 8248 |
$bookings[$k] = $v; |
| 8249 |
} |
| 8250 |
} |
| 8251 |
$bookings = array_values($bookings); |
| 8252 |
if (!count($bookings)) { |
| 8253 |
/** |
| 8254 |
* AJAX requests made by the page availability overview may contain empty booking IDs |
| 8255 |
* due to SQL errors that only booked the car, but could not save the booking record. |
| 8256 |
* Clean up busy (ghost) records where the busy relations contain empty booking IDs. |
| 8257 |
* |
| 8258 |
* @since 1.14.6 (J) - 1.2.4 (WP) |
| 8259 |
*/ |
| 8260 |
$hanging_busy_ids = []; |
| 8261 |
$q = "SELECT `b`.`id`, `o`.`id` AS `id_order` FROM `#__vikrentcar_busy` AS `b` LEFT JOIN `#__vikrentcar_orders` AS `o` ON `b`.`id`=`o`.`idbusy` WHERE `o`.`id` = 0 OR `o`.`id` IS NULL"; |
| 8262 |
$dbo->setQuery($q); |
| 8263 |
$dbo->execute(); |
| 8264 |
if ($dbo->getNumRows()) { |
| 8265 |
$removelist = $dbo->loadAssocList(); |
| 8266 |
foreach ($removelist as $ghost_record) { |
| 8267 |
if (!empty($ghost_record['id']) && !in_array($ghost_record['id'], $hanging_busy_ids)) { |
| 8268 |
$hanging_busy_ids[] = $ghost_record['id']; |
| 8269 |
} |
| 8270 |
} |
| 8271 |
} |
| 8272 |
if (count($hanging_busy_ids)) { |
| 8273 |
// clean up ghost records |
| 8274 |
$q = "DELETE FROM `#__vikrentcar_busy` WHERE `id` IN (" . implode(', ', $hanging_busy_ids) . ");"; |
| 8275 |
$dbo->setQuery($q); |
| 8276 |
$dbo->execute(); |
| 8277 |
} |
| 8278 |
|
| 8279 |
echo 'e4j.error.1 Missing Data - Please reload the page'; |
| 8280 |
exit; |
| 8281 |
} |
| 8282 |
$nowtf = VikRentCar::getTimeFormat(true); |
| 8283 |
$nowdf = VikRentCar::getDateFormat(true); |
| 8284 |
if ($nowdf == "%d/%m/%Y") { |
| 8285 |
$df = 'd/m/Y'; |
| 8286 |
} elseif ($nowdf == "%m/%d/%Y") { |
| 8287 |
$df = 'm/d/Y'; |
| 8288 |
} else { |
| 8289 |
$df = 'Y/m/d'; |
| 8290 |
} |
| 8291 |
$q = "SELECT `o`.*, `c`.`name` AS `car_name`, `c`.`params` AS `car_params`, `p`.`name` AS `pickup_place` |
| 8292 |
FROM `#__vikrentcar_orders` AS `o` |
| 8293 |
LEFT JOIN `#__vikrentcar_cars` `c` ON `c`.`id`=`o`.`idcar` |
| 8294 |
LEFT JOIN `#__vikrentcar_places` `p` ON `p`.`id`=`o`.`idplace` |
| 8295 |
WHERE `o`.`id` IN (".implode(', ', $bookings).");"; |
| 8296 |
$dbo->setQuery($q); |
| 8297 |
$dbo->execute(); |
| 8298 |
if ($dbo->getNumRows() > 0) { |
| 8299 |
$booking_infos = $dbo->loadAssocList(); |
| 8300 |
foreach ($booking_infos as $k => $row) { |
| 8301 |
//car, amounts and guests information |
| 8302 |
$booking_infos[$k]['status_lbl'] = ($row['status'] != 'confirmed' && $row['status'] != 'standby' ? $row['status'] : ($row['status'] == 'confirmed' ? JText::translate('VRCONFIRMED') : JText::translate('VRSTANDBY'))); |
| 8303 |
$booking_infos[$k]['format_tot'] = VikRentCar::numberFormat($row['order_total']); |
| 8304 |
$booking_infos[$k]['format_totpaid'] = VikRentCar::numberFormat($row['totpaid']); |
| 8305 |
// to avoid using a double left join in the query for the return place name, we use a single query |
| 8306 |
$booking_infos[$k]['dropoff_place'] = !empty($row['idreturnplace']) ? VikRentCar::getPlaceName($row['idreturnplace']) : ''; |
| 8307 |
//Rooms Indexes |
| 8308 |
$cindexes = array(); |
| 8309 |
$subcardata = !empty($psubcar) ? explode('-', $psubcar) : array(); |
| 8310 |
if ($row['status'] == "confirmed" && !empty($row['params']) && strlen($row['carindex'])) { |
| 8311 |
$car_params = json_decode($row['params'], true); |
| 8312 |
if (is_array($car_params) && array_key_exists('features', $car_params) && @count($car_params['features']) > 0) { |
| 8313 |
foreach ($car_params['features'] as $cind => $cfeatures) { |
| 8314 |
if ($cind == $row['carindex']) { |
| 8315 |
$ind_str = ''; |
| 8316 |
foreach ($cfeatures as $fname => $fval) { |
| 8317 |
if (strlen($fval)) { |
| 8318 |
$ind_str = '#'.$cind.' - '.JText::translate($fname).': '.$fval; |
| 8319 |
break; |
| 8320 |
} |
| 8321 |
} |
| 8322 |
if (!array_key_exists($row['car_name'], $cindexes)) { |
| 8323 |
$cindexes[$row['car_name']] = $ind_str; |
| 8324 |
} else { |
| 8325 |
$cindexes[$row['car_name']] .= ', '.$ind_str; |
| 8326 |
} |
| 8327 |
break; |
| 8328 |
} |
| 8329 |
} |
| 8330 |
} |
| 8331 |
} |
| 8332 |
if (count($cindexes)) { |
| 8333 |
$booking_infos[$k]['cindexes'] = $cindexes; |
| 8334 |
} |
| 8335 |
//Customer Details |
| 8336 |
$custdata = $row['custdata']; |
| 8337 |
$custdata_parts = explode("\n", $row['custdata']); |
| 8338 |
if (count($custdata_parts) > 2 && strpos($custdata_parts[0], ':') !== false && strpos($custdata_parts[1], ':') !== false) { |
| 8339 |
//get the first two fields |
| 8340 |
$custvalues = array(); |
| 8341 |
foreach ($custdata_parts as $custdet) { |
| 8342 |
if (strlen($custdet) < 1) { |
| 8343 |
continue; |
| 8344 |
} |
| 8345 |
$custdet_parts = explode(':', $custdet); |
| 8346 |
if (count($custdet_parts) >= 2) { |
| 8347 |
unset($custdet_parts[0]); |
| 8348 |
array_push($custvalues, trim(implode(':', $custdet_parts))); |
| 8349 |
} |
| 8350 |
if (count($custvalues) > 1) { |
| 8351 |
break; |
| 8352 |
} |
| 8353 |
} |
| 8354 |
if (count($custvalues) > 1) { |
| 8355 |
$custdata = implode(' ', $custvalues); |
| 8356 |
} |
| 8357 |
} |
| 8358 |
if (strlen($custdata) > 45) { |
| 8359 |
$custdata = substr($custdata, 0, 45)." ..."; |
| 8360 |
} |
| 8361 |
|
| 8362 |
$q = "SELECT `c`.*,`co`.`idorder` FROM `#__vikrentcar_customers` AS `c` LEFT JOIN `#__vikrentcar_customers_orders` `co` ON `c`.`id`=`co`.`idcustomer` WHERE `co`.`idorder`=".$row['id'].";"; |
| 8363 |
$dbo->setQuery($q); |
| 8364 |
$dbo->execute(); |
| 8365 |
if ($dbo->getNumRows() > 0) { |
| 8366 |
$cust_country = $dbo->loadAssocList(); |
| 8367 |
$cust_country = $cust_country[0]; |
| 8368 |
if (!empty($cust_country['first_name'])) { |
| 8369 |
$custdata = $cust_country['first_name'].' '.$cust_country['last_name']; |
| 8370 |
if (!empty($cust_country['country'])) { |
| 8371 |
if (is_file(VRC_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'countries'.DIRECTORY_SEPARATOR.$cust_country['country'].'.png')) { |
| 8372 |
$custdata .= '<img src="'.VRC_ADMIN_URI.'resources/countries/'.$cust_country['country'].'.png'.'" title="'.$cust_country['country'].'" class="vrc-country-flag vrc-country-flag-left"/>'; |
| 8373 |
} |
| 8374 |
} |
| 8375 |
} |
| 8376 |
} |
| 8377 |
$custdata = JText::translate('VRDBTEXTROOMCLOSED') == $row['custdata'] ? '<span class="vrordersroomclosed">'.JText::translate('VRDBTEXTROOMCLOSED').'</span>' : $custdata; |
| 8378 |
$booking_infos[$k]['cinfo'] = $custdata; |
| 8379 |
//Formatted dates |
| 8380 |
$booking_infos[$k]['ts'] = date($df . ' ' . $nowtf, $row['ts']); |
| 8381 |
$booking_infos[$k]['pickup'] = date($df . ' ' . $nowtf, $row['ritiro']); |
| 8382 |
$booking_infos[$k]['dropoff'] = date($df . ' ' . $nowtf, $row['consegna']); |
| 8383 |
} |
| 8384 |
} |
| 8385 |
if (!(count($booking_infos) > 0)) { |
| 8386 |
echo 'e4j.error.2 Missing Data'; |
| 8387 |
exit; |
| 8388 |
} |
| 8389 |
|
| 8390 |
echo json_encode($booking_infos); |
| 8391 |
exit; |
| 8392 |
} |
| 8393 |
|
| 8394 |
/** |
| 8395 |
* This is an AJAX endpoint. |
| 8396 |
*/ |
| 8397 |
public function cron_exec() |
| 8398 |
{ |
| 8399 |
ob_start(); |
| 8400 |
|
| 8401 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'cronexec')); |
| 8402 |
|
| 8403 |
parent::display(); |
| 8404 |
|
| 8405 |
$content = ob_get_contents(); |
| 8406 |
ob_end_clean(); |
| 8407 |
|
| 8408 |
VRCHttpDocument::getInstance()->json([$content]); |
| 8409 |
} |
| 8410 |
|
| 8411 |
public function downloadcron() |
| 8412 |
{ |
| 8413 |
/** |
| 8414 |
* @wponly no more executable files need to be downloaded for WordPress. |
| 8415 |
*/ |
| 8416 |
VRCHttpDocument::getInstance()->close(406, 'Cron Jobs must be executed through WP-Cron'); |
| 8417 |
} |
| 8418 |
|
| 8419 |
/** |
| 8420 |
* This is an AJAX endpoint. |
| 8421 |
*/ |
| 8422 |
public function cronlogs() |
| 8423 |
{ |
| 8424 |
$dbo = JFactory::getDBO(); |
| 8425 |
$pcron_id = VikRequest::getInt('cron_id', '', 'request'); |
| 8426 |
|
| 8427 |
ob_start(); |
| 8428 |
|
| 8429 |
$q = "SELECT * FROM `#__vikrentcar_cronjobs` WHERE `id`=".(int)$pcron_id.";"; |
| 8430 |
$dbo->setQuery($q); |
| 8431 |
$dbo->execute(); |
| 8432 |
if ($dbo->getNumRows() == 1) { |
| 8433 |
$cron_data = $dbo->loadAssoc(); |
| 8434 |
$cron_data['logs'] = empty($cron_data['logs']) ? '--------' : $cron_data['logs']; |
| 8435 |
echo '<pre>'.print_r($cron_data['logs'], true).'</pre>'; |
| 8436 |
} |
| 8437 |
|
| 8438 |
$content = ob_get_contents(); |
| 8439 |
ob_end_clean(); |
| 8440 |
|
| 8441 |
VRCHttpDocument::getInstance()->json([$content]); |
| 8442 |
} |
| 8443 |
|
| 8444 |
public function canceldash() { |
| 8445 |
$mainframe = JFactory::getApplication(); |
| 8446 |
$mainframe->redirect("index.php?option=com_vikrentcar"); |
| 8447 |
} |
| 8448 |
|
| 8449 |
/** |
| 8450 |
* Hidden task to clean up duplicate records in certain database tables |
| 8451 |
* due to a double execution of the installation queries. |
| 8452 |
* |
| 8453 |
* @since November 4th 2020 |
| 8454 |
*/ |
| 8455 |
public function clean_duplicate_records() { |
| 8456 |
$dbo = JFactory::getDbo(); |
| 8457 |
|
| 8458 |
$tables_with_duplicates = array( |
| 8459 |
'#__vikrentcar_config' => array( |
| 8460 |
'id_key' => 'id', |
| 8461 |
'compare_key' => 'param', |
| 8462 |
), |
| 8463 |
'#__vikrentcar_countries' => array( |
| 8464 |
'id_key' => 'id', |
| 8465 |
'compare_key' => 'country_3_code', |
| 8466 |
), |
| 8467 |
'#__vikrentcar_custfields' => array( |
| 8468 |
'id_key' => 'id', |
| 8469 |
'compare_key' => 'name', |
| 8470 |
), |
| 8471 |
'#__vikrentcar_texts' => array( |
| 8472 |
'id_key' => 'id', |
| 8473 |
'compare_key' => 'param', |
| 8474 |
), |
| 8475 |
); |
| 8476 |
|
| 8477 |
foreach ($tables_with_duplicates as $tblname => $data) { |
| 8478 |
$doubles = array(); |
| 8479 |
$storage = array(); |
| 8480 |
$rmlist = array(); |
| 8481 |
$q = "SELECT * FROM `{$tblname}` ORDER BY `{$data['id_key']}` DESC;"; |
| 8482 |
$dbo->setQuery($q); |
| 8483 |
$dbo->execute(); |
| 8484 |
if (!$dbo->getNumRows()) { |
| 8485 |
echo "<p>No records found in table {$tblname}</p>"; |
| 8486 |
continue; |
| 8487 |
} |
| 8488 |
$rows = $dbo->loadAssocList(); |
| 8489 |
foreach ($rows as $row) { |
| 8490 |
if (!isset($doubles[$row[$data['compare_key']]])) { |
| 8491 |
$doubles[$row[$data['compare_key']]] = 0; |
| 8492 |
} |
| 8493 |
$doubles[$row[$data['compare_key']]]++; |
| 8494 |
if (!isset($storage[$row[$data['compare_key']]])) { |
| 8495 |
$storage[$row[$data['compare_key']]] = array(); |
| 8496 |
} |
| 8497 |
array_push($storage[$row[$data['compare_key']]], $row[$data['id_key']]); |
| 8498 |
} |
| 8499 |
foreach ($doubles as $paramkey => $paramcount) { |
| 8500 |
if ($paramcount < 2 || !isset($storage[$paramkey]) || count($storage[$paramkey]) < 2 || $paramcount != count($storage[$paramkey])) { |
| 8501 |
continue; |
| 8502 |
} |
| 8503 |
$exceeding = $paramcount - 1; |
| 8504 |
for ($x = 0; $x < $exceeding; $x++) { |
| 8505 |
array_push($rmlist, $storage[$paramkey][$x]); |
| 8506 |
} |
| 8507 |
} |
| 8508 |
echo "<p>Total records found in table {$tblname}: " . count($rows) . "</p>"; |
| 8509 |
echo '<p>Total records to remove: ' . count($rmlist) . '</p>'; |
| 8510 |
echo '<pre style="display: none;">'.print_r($rmlist, true).'</pre><br/>'; |
| 8511 |
if (count($rmlist)) { |
| 8512 |
$q = "DELETE FROM `{$tblname}` WHERE `{$data['id_key']}` IN (" . implode(', ', $rmlist) . ");"; |
| 8513 |
$dbo->setQuery($q); |
| 8514 |
$dbo->execute(); |
| 8515 |
} |
| 8516 |
} |
| 8517 |
} |
| 8518 |
|
| 8519 |
/** |
| 8520 |
* Hidden task to scan all database tables of VikRentCar to ensure the column `id` is |
| 8521 |
* defined as a primary key and got an auto-increment extra flag properly defined and set. |
| 8522 |
* We've noticed that some third-party plugins used to migrate WP sites may break the |
| 8523 |
* primary keys, and so new records won't get an ID. |
| 8524 |
* |
| 8525 |
* @since 1.15.9 (J) - 1.4.6 (WP) |
| 8526 |
*/ |
| 8527 |
public function fix_autoincrement_tables() |
| 8528 |
{ |
| 8529 |
if (!JFactory::getUser()->authorise('core.admin', 'com_vikrentcar')) { |
| 8530 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 8531 |
} |
| 8532 |
|
| 8533 |
$dbo = JFactory::getDbo(); |
| 8534 |
|
| 8535 |
// load all the installed database tables |
| 8536 |
$tables = $dbo->getTableList(); |
| 8537 |
|
| 8538 |
// get current database prefix |
| 8539 |
$prefix = $dbo->getPrefix(); |
| 8540 |
|
| 8541 |
// replace prefix with placeholder |
| 8542 |
$tables = array_map(function($table) use ($prefix) |
| 8543 |
{ |
| 8544 |
return preg_replace("/^{$prefix}/", '#__', $table); |
| 8545 |
}, $tables); |
| 8546 |
|
| 8547 |
// remove all the tables that do not belong to VikRentCar |
| 8548 |
$tables = array_values(array_filter($tables, function($table) |
| 8549 |
{ |
| 8550 |
if (preg_match("/^#__vikrentcar_config$/", $table)) |
| 8551 |
{ |
| 8552 |
// exclude the configuration table, which will be handled in a different way |
| 8553 |
return false; |
| 8554 |
} |
| 8555 |
|
| 8556 |
return preg_match("/^#__vikrentcar_/", $table); |
| 8557 |
})); |
| 8558 |
|
| 8559 |
foreach ($tables as $table) { |
| 8560 |
$columns = $dbo->getTableColumns($table, false); |
| 8561 |
if (!isset($columns['id']) || empty($columns['id']->Type) || !empty($columns['id']->Extra)) { |
| 8562 |
continue; |
| 8563 |
} |
| 8564 |
|
| 8565 |
echo 'Fixing ' . $table. ' for missing auto-increment<br/><pre>' . print_r($columns['id'], true) . '</pre><br/>'; |
| 8566 |
|
| 8567 |
// set auto-increment and primary key |
| 8568 |
$dbo->setQuery("ALTER TABLE `{$table}` MODIFY `id` " . $columns['id']->Type . " NOT NULL AUTO_INCREMENT PRIMARY KEY;"); |
| 8569 |
$dbo->execute(); |
| 8570 |
|
| 8571 |
// count next auto-increment |
| 8572 |
$dbo->setQuery("SELECT MAX(`id`) FROM `{$table}`"); |
| 8573 |
$next_ai = (int) $dbo->loadResult() + 1; |
| 8574 |
|
| 8575 |
// update next auto-increment value |
| 8576 |
$dbo->setQuery("ALTER TABLE `{$table}` AUTO_INCREMENT = {$next_ai}"); |
| 8577 |
$dbo->execute(); |
| 8578 |
} |
| 8579 |
} |
| 8580 |
|
| 8581 |
/** |
| 8582 |
* Hidden task to (re-)run the update queries from a given plugin version. |
| 8583 |
* Useful to ensure the database structure is up-to-date and no update queries went lost. |
| 8584 |
* |
| 8585 |
* @since 1.15.9 (J) - 1.4.6 (WP) |
| 8586 |
*/ |
| 8587 |
public function run_update_queries() |
| 8588 |
{ |
| 8589 |
$app = JFactory::getApplication(); |
| 8590 |
$dbo = JFactory::getDbo(); |
| 8591 |
|
| 8592 |
if (!JFactory::getUser()->authorise('core.admin', 'com_vikrentcar')) { |
| 8593 |
VRCHttpDocument::getInstance($app)->close(403, JText::translate('JERROR_ALERTNOAUTHOR')); |
| 8594 |
} |
| 8595 |
|
| 8596 |
$from_version = $app->input->getString('from_version'); |
| 8597 |
|
| 8598 |
if (empty($from_version)) { |
| 8599 |
VRCHttpDocument::getInstance()->close(400, 'Missing from version value.'); |
| 8600 |
} |
| 8601 |
|
| 8602 |
// determine the SQL updates directory path |
| 8603 |
$sql_updates_path = ''; |
| 8604 |
if (VRCPlatformDetection::isWordPress()) { |
| 8605 |
$sql_updates_path = implode(DIRECTORY_SEPARATOR, [VIKRENTCAR_BASE, 'sql', 'update', 'mysql']); |
| 8606 |
} else { |
| 8607 |
$sql_updates_path = implode(DIRECTORY_SEPARATOR, [VRC_ADMIN_PATH, 'sql', 'updates', 'mysql']); |
| 8608 |
} |
| 8609 |
|
| 8610 |
if (!$sql_updates_path || !is_dir($sql_updates_path)) { |
| 8611 |
VRCHttpDocument::getInstance()->close(500, 'Could not find SQL updates path.'); |
| 8612 |
} |
| 8613 |
|
| 8614 |
// read all SQL update files |
| 8615 |
$sql_update_files = JFolder::files($sql_updates_path, '\.sql', $recurse = false, $full = true); |
| 8616 |
|
| 8617 |
// filter SQL files with just the valid ones |
| 8618 |
$sql_update_files = array_filter($sql_update_files, function($sql_update_file) use ($from_version) { |
| 8619 |
$file_version = basename($sql_update_file, '.sql'); |
| 8620 |
return version_compare($file_version, $from_version, '>='); |
| 8621 |
}); |
| 8622 |
|
| 8623 |
// sort files by version ascending |
| 8624 |
usort($sql_update_files, function($a, $b) { |
| 8625 |
return version_compare(basename($a, '.sql'), basename($b, '.sql')); |
| 8626 |
}); |
| 8627 |
|
| 8628 |
if (!$sql_update_files) { |
| 8629 |
VRCHttpDocument::getInstance()->close(500, sprintf('Could not find any suitable SQL update file from version %s.', $from_version)); |
| 8630 |
} |
| 8631 |
|
| 8632 |
$success_queries = 0; |
| 8633 |
|
| 8634 |
foreach ($sql_update_files as $file) { |
| 8635 |
$handle = fopen($file, 'r'); |
| 8636 |
|
| 8637 |
$bytes = ''; |
| 8638 |
while (!feof($handle)) { |
| 8639 |
$bytes .= fread($handle, 8192); |
| 8640 |
} |
| 8641 |
|
| 8642 |
fclose($handle); |
| 8643 |
|
| 8644 |
if (VRCPlatformDetection::isWordPress()) { |
| 8645 |
$queries_list = JDatabaseHelper::splitSql($bytes); |
| 8646 |
} else { |
| 8647 |
try { |
| 8648 |
$queries_list = Joomla\Database\DatabaseDriver::splitSql($bytes); |
| 8649 |
} catch(Throwable $e) { |
| 8650 |
$app->enqueueMessage(sprintf('Error splitting queries: %s', $e->getMessage()), 'error'); |
| 8651 |
$queries_list = []; |
| 8652 |
} |
| 8653 |
} |
| 8654 |
|
| 8655 |
foreach ($queries_list as $q) { |
| 8656 |
try { |
| 8657 |
$dbo->setQuery($q); |
| 8658 |
$result = $dbo->execute(); |
| 8659 |
} catch (Exception $e) { |
| 8660 |
$result = false; |
| 8661 |
$app->enqueueMessage(sprintf('Error executing query: %s', $e->getMessage()), 'warning'); |
| 8662 |
} |
| 8663 |
|
| 8664 |
if ($result) { |
| 8665 |
$success_queries++; |
| 8666 |
} |
| 8667 |
} |
| 8668 |
} |
| 8669 |
|
| 8670 |
if ($success_queries) { |
| 8671 |
$app->enqueueMessage(sprintf('Successful queries: %d', $success_queries), 'success'); |
| 8672 |
} |
| 8673 |
|
| 8674 |
// send response to output |
| 8675 |
echo '<pre>'.print_r($sql_update_files, true).'</pre><br/>'; |
| 8676 |
} |
| 8677 |
|
| 8678 |
/** |
| 8679 |
* Go to the previous order. |
| 8680 |
* |
| 8681 |
* @uses navigateToOrder() |
| 8682 |
* |
| 8683 |
* @since 1.2.0 |
| 8684 |
*/ |
| 8685 |
public function prev_order() |
| 8686 |
{ |
| 8687 |
$this->navigateToOrder('prev'); |
| 8688 |
} |
| 8689 |
|
| 8690 |
/** |
| 8691 |
* Go to the next order. |
| 8692 |
* |
| 8693 |
* @uses navigateToOrder() |
| 8694 |
* |
| 8695 |
* @since 1.2.0 |
| 8696 |
*/ |
| 8697 |
public function next_order() |
| 8698 |
{ |
| 8699 |
$this->navigateToOrder('next'); |
| 8700 |
} |
| 8701 |
|
| 8702 |
/** |
| 8703 |
* Given the current order ID in the request, we navigate |
| 8704 |
* either to the next or to the previous reservation (if any). |
| 8705 |
* |
| 8706 |
* @param string $direction either next or prev. |
| 8707 |
* |
| 8708 |
* @return void |
| 8709 |
* |
| 8710 |
* @since 1.2.0 |
| 8711 |
*/ |
| 8712 |
private function navigateToOrder($direction = 'next') |
| 8713 |
{ |
| 8714 |
$bid = VikRequest::getInt('whereup', 0, 'request'); |
| 8715 |
if (empty($bid) || $bid < 1 || !in_array($direction, array('prev', 'next'))) { |
| 8716 |
throw new Exception("Invalid request", 400); |
| 8717 |
} |
| 8718 |
|
| 8719 |
$dbo = JFactory::getDbo(); |
| 8720 |
$app = JFactory::getApplication(); |
| 8721 |
|
| 8722 |
$q = "SELECT `id` FROM `#__vikrentcar_orders` WHERE `id`" . ($direction == 'next' ? '>' : '<') . "{$bid} ORDER BY `id` " . ($direction == 'next' ? 'ASC' : 'DESC'); |
| 8723 |
$dbo->setQuery($q, 0, 1); |
| 8724 |
$dbo->execute(); |
| 8725 |
if (!$dbo->getNumRows()) { |
| 8726 |
VikError::raiseWarning('', JText::translate('VRPEDITBUSYONE')); |
| 8727 |
$app->redirect("index.php?option=com_vikrentcar&task=orders"); |
| 8728 |
exit; |
| 8729 |
} |
| 8730 |
|
| 8731 |
$app->redirect("index.php?option=com_vikrentcar&task=editorder&cid[]=" . $dbo->loadResult()); |
| 8732 |
exit; |
| 8733 |
} |
| 8734 |
|
| 8735 |
/** |
| 8736 |
* AJAX request for adding a new car-day note. |
| 8737 |
* |
| 8738 |
* @return void |
| 8739 |
* |
| 8740 |
* @since 1.14.5 (J) - 1.2.0 (WP) |
| 8741 |
*/ |
| 8742 |
public function add_cardaynote() |
| 8743 |
{ |
| 8744 |
if (!JSession::checkToken()) { |
| 8745 |
// missing CSRF-proof token |
| 8746 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JINVALID_TOKEN')); |
| 8747 |
} |
| 8748 |
|
| 8749 |
$dt = VikRequest::getString('dt', '', 'request'); |
| 8750 |
$idcar = VikRequest::getInt('idcar', 0, 'request'); |
| 8751 |
$subunit = VikRequest::getInt('subunit', 0, 'request'); |
| 8752 |
$type = VikRequest::getString('type', '', 'request'); |
| 8753 |
$type = empty($type) ? 'custom' : $type; |
| 8754 |
$name = VikRequest::getString('name', '', 'request'); |
| 8755 |
$descr = VikRequest::getString('descr', '', 'request'); |
| 8756 |
$cdays = VikRequest::getInt('cdays', 0, 'request'); |
| 8757 |
$cdays = $cdays < 0 ? 0 : $cdays; |
| 8758 |
$cdays = $cdays > 365 ? 365 : $cdays; |
| 8759 |
if (empty($idcar) || empty($dt) || !strtotime($dt)) { |
| 8760 |
echo 'e4j.error.1'; |
| 8761 |
exit; |
| 8762 |
} |
| 8763 |
|
| 8764 |
// reload end date |
| 8765 |
$end_date = $dt; |
| 8766 |
|
| 8767 |
// build critical date object |
| 8768 |
$new_note = array( |
| 8769 |
'name' => $name, |
| 8770 |
'type' => $type, |
| 8771 |
'descr' => $descr, |
| 8772 |
); |
| 8773 |
|
| 8774 |
// get object |
| 8775 |
$notes = VikRentCar::getCriticalDatesInstance(); |
| 8776 |
|
| 8777 |
// store the notes for all consecutive dates |
| 8778 |
for ($i = 0; $i <= $cdays; $i++) { |
| 8779 |
$store_dt = $dt; |
| 8780 |
if ($i > 0) { |
| 8781 |
$dt_info = getdate(strtotime($store_dt)); |
| 8782 |
$store_dt = date('Y-m-d', mktime(0, 0, 0, $dt_info['mon'], ($dt_info['mday'] + $i), $dt_info['year'])); |
| 8783 |
$end_date = $store_dt; |
| 8784 |
} |
| 8785 |
$result = $notes->storeDayNote($new_note, $store_dt, $idcar, $subunit); |
| 8786 |
if (!$result) { |
| 8787 |
echo 'e4j.error.2'; |
| 8788 |
exit; |
| 8789 |
} |
| 8790 |
} |
| 8791 |
|
| 8792 |
// reload all car day notes for this day for the AJAX response |
| 8793 |
$all_notes = $notes->loadCarDayNotes($dt, $end_date, $idcar, $subunit); |
| 8794 |
|
| 8795 |
if (!$all_notes) { |
| 8796 |
// no notes found even after storing it |
| 8797 |
echo 'e4j.error.3'; |
| 8798 |
exit; |
| 8799 |
} |
| 8800 |
|
| 8801 |
// output the JSON encoded response and exit |
| 8802 |
VRCHttpDocument::getInstance()->json($all_notes); |
| 8803 |
} |
| 8804 |
|
| 8805 |
/** |
| 8806 |
* AJAX request for removing a car day note. |
| 8807 |
* |
| 8808 |
* @return void |
| 8809 |
* |
| 8810 |
* @since 1.14.5 (J) - 1.2.0 (WP) |
| 8811 |
*/ |
| 8812 |
public function remove_cardaynote() |
| 8813 |
{ |
| 8814 |
if (!JSession::checkToken()) { |
| 8815 |
// missing CSRF-proof token |
| 8816 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JINVALID_TOKEN')); |
| 8817 |
} |
| 8818 |
|
| 8819 |
$dt = VikRequest::getString('dt', '', 'request'); |
| 8820 |
$idcar = VikRequest::getInt('idcar', 0, 'request'); |
| 8821 |
$subunit = VikRequest::getInt('subunit', 0, 'request'); |
| 8822 |
$type = VikRequest::getString('type', '', 'request'); |
| 8823 |
$type = empty($type) ? 'custom' : $type; |
| 8824 |
$ind = VikRequest::getInt('ind', 0, 'request'); |
| 8825 |
if (empty($dt) || !strtotime($dt)) { |
| 8826 |
echo 'e4j.error.1'; |
| 8827 |
exit; |
| 8828 |
} |
| 8829 |
|
| 8830 |
$notes = VikRentCar::getCriticalDatesInstance(); |
| 8831 |
$result = $notes->deleteDayNote($ind, $dt, $idcar, $subunit, $type); |
| 8832 |
if (!$result) { |
| 8833 |
echo 'e4j.error.2'; |
| 8834 |
exit; |
| 8835 |
} |
| 8836 |
|
| 8837 |
echo 'e4j.ok'; |
| 8838 |
exit; |
| 8839 |
} |
| 8840 |
|
| 8841 |
/** |
| 8842 |
* AJAX request for storing an event for a booking. |
| 8843 |
* This endpoint could be used for any kind of purpose. |
| 8844 |
* |
| 8845 |
* @return void |
| 8846 |
* |
| 8847 |
* @since 1.2.0 |
| 8848 |
*/ |
| 8849 |
public function store_booking_history_event() |
| 8850 |
{ |
| 8851 |
$bid = VikRequest::getInt('bid', 0, 'request'); |
| 8852 |
$event = VikRequest::getString('event', '', 'request'); |
| 8853 |
$descr = VikRequest::getString('descr', '', 'request'); |
| 8854 |
|
| 8855 |
if (empty($bid) || empty($event)) { |
| 8856 |
throw new Exception("Missing required information", 500); |
| 8857 |
} |
| 8858 |
|
| 8859 |
// Booking History |
| 8860 |
VikRentCar::getOrderHistoryInstance()->setBid($bid)->store($event, $descr); |
| 8861 |
// |
| 8862 |
|
| 8863 |
echo 'e4j.ok'; |
| 8864 |
exit; |
| 8865 |
} |
| 8866 |
|
| 8867 |
/** |
| 8868 |
* Loads a specific admin widget ID and executes the requested method. |
| 8869 |
* Useful for loading a newly added widget, or to execute custom functions. |
| 8870 |
* |
| 8871 |
* @see this is an AJAX endpoint. |
| 8872 |
* |
| 8873 |
* @since 1.14.5 (J) - 1.2.0 (WP) |
| 8874 |
*/ |
| 8875 |
public function exec_admin_widget() |
| 8876 |
{ |
| 8877 |
if (!JSession::checkToken()) { |
| 8878 |
// missing CSRF-proof token |
| 8879 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JINVALID_TOKEN')); |
| 8880 |
} |
| 8881 |
|
| 8882 |
$widget_id = VikRequest::getString('widget_id', '', 'request'); |
| 8883 |
$call = VikRequest::getString('call', '', 'request'); |
| 8884 |
|
| 8885 |
if (empty($widget_id)) { |
| 8886 |
VRCHttpDocument::getInstance()->close(500, 'Empty Admin Widget ID'); |
| 8887 |
} |
| 8888 |
|
| 8889 |
if (empty($call)) { |
| 8890 |
VRCHttpDocument::getInstance()->close(500, 'Empty Admin Widget Callback'); |
| 8891 |
} |
| 8892 |
|
| 8893 |
// invoke admin widgets helper |
| 8894 |
$widgets_helper = VikRentCar::getAdminWidgetsInstance(); |
| 8895 |
$widget = $widgets_helper->getWidget($widget_id); |
| 8896 |
|
| 8897 |
if ($widget === false) { |
| 8898 |
VRCHttpDocument::getInstance()->close(404, 'Requested Admin Widget not found'); |
| 8899 |
} |
| 8900 |
|
| 8901 |
if (!method_exists($widget, $call) || !is_callable(array($widget, $call))) { |
| 8902 |
VRCHttpDocument::getInstance()->close(403, 'Admin Widget Callback not found or forbidden'); |
| 8903 |
} |
| 8904 |
|
| 8905 |
try { |
| 8906 |
// invoke the widget's method within a buffer |
| 8907 |
ob_start(); |
| 8908 |
$widget->{$call}(); |
| 8909 |
$widget_response = ob_get_contents(); |
| 8910 |
ob_end_clean(); |
| 8911 |
} catch (Throwable $e) { |
| 8912 |
VRCHttpDocument::getInstance()->close($e->getCode() ?: 500, $e->getMessage()); |
| 8913 |
} catch (Exception $e) { |
| 8914 |
VRCHttpDocument::getInstance()->close($e->getCode(), $e->getMessage()); |
| 8915 |
} |
| 8916 |
|
| 8917 |
// prepare response object with a property equal to the called method |
| 8918 |
$response = new stdClass; |
| 8919 |
$response->{$call} = $widget_response; |
| 8920 |
|
| 8921 |
// output the JSON encoded response and exit |
| 8922 |
VRCHttpDocument::getInstance()->json($response); |
| 8923 |
} |
| 8924 |
|
| 8925 |
/** |
| 8926 |
* Updates the map of admin widgets. |
| 8927 |
* |
| 8928 |
* @see this is an AJAX endpoint. |
| 8929 |
* |
| 8930 |
* @since 1.14.5 (J) - 1.2.0 (WP) |
| 8931 |
*/ |
| 8932 |
public function save_admin_widgets() |
| 8933 |
{ |
| 8934 |
if (!JSession::checkToken()) { |
| 8935 |
// missing CSRF-proof token |
| 8936 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JINVALID_TOKEN')); |
| 8937 |
} |
| 8938 |
|
| 8939 |
// make sure permissions are sufficient |
| 8940 |
if (!JFactory::getUser()->authorise('core.vrc.gsettings', 'com_vikrentcar')) { |
| 8941 |
VRCHttpDocument::getInstance()->close(403, 'You are not authorized to modify the widgets.'); |
| 8942 |
} |
| 8943 |
|
| 8944 |
$psections = VikRequest::getVar('sections', array(), 'request', 'array'); |
| 8945 |
if (!is_array($psections) || !count($psections)) { |
| 8946 |
VRCHttpDocument::getInstance()->close(500, 'No sections found in map'); |
| 8947 |
} |
| 8948 |
|
| 8949 |
// request values are all converted to arrays, so restore the object styling |
| 8950 |
$psections = json_decode(json_encode($psections)); |
| 8951 |
|
| 8952 |
// update map |
| 8953 |
$result = VikRentCar::getAdminWidgetsInstance()->updateWidgetsMap($psections); |
| 8954 |
|
| 8955 |
$response = new stdClass; |
| 8956 |
$response->status = (int)$result; |
| 8957 |
|
| 8958 |
// output the JSON encoded response and exit |
| 8959 |
VRCHttpDocument::getInstance()->json($response); |
| 8960 |
} |
| 8961 |
|
| 8962 |
/** |
| 8963 |
* Restores the default admin widgets map. |
| 8964 |
* |
| 8965 |
* @since 1.14.5 (J) - 1.2.0 (WP) |
| 8966 |
*/ |
| 8967 |
public function reset_admin_widgets() |
| 8968 |
{ |
| 8969 |
// reset map and redirect to dashboard |
| 8970 |
VikRentCar::getAdminWidgetsInstance()->restoreDefaultWidgetsMap(); |
| 8971 |
|
| 8972 |
JFactory::getApplication()->redirect('index.php?option=com_vikrentcar'); |
| 8973 |
exit; |
| 8974 |
} |
| 8975 |
|
| 8976 |
/** |
| 8977 |
* Updates the welcome message status for the widget's customizer via AJAX. |
| 8978 |
* |
| 8979 |
* @since 1.14.5 (J) - 1.2.0 (WP) |
| 8980 |
*/ |
| 8981 |
public function admin_widgets_welcome() |
| 8982 |
{ |
| 8983 |
if (!JSession::checkToken()) { |
| 8984 |
// missing CSRF-proof token |
| 8985 |
VRCHttpDocument::getInstance()->close(403, JText::translate('JINVALID_TOKEN')); |
| 8986 |
} |
| 8987 |
|
| 8988 |
$hide_welcome = VikRequest::getInt('hide_welcome', 0, 'request'); |
| 8989 |
// update configuration value |
| 8990 |
VikRentCar::getAdminWidgetsInstance()->updateWelcome($hide_welcome); |
| 8991 |
|
| 8992 |
$response = new stdClass; |
| 8993 |
$response->status = $hide_welcome; |
| 8994 |
|
| 8995 |
// output the JSON encoded response and exit |
| 8996 |
VRCHttpDocument::getInstance()->json($response); |
| 8997 |
} |
| 8998 |
|
| 8999 |
/** |
| 9000 |
* Back-end order registration status modal View. |
| 9001 |
* |
| 9002 |
* @since 1.2.0 |
| 9003 |
*/ |
| 9004 |
public function orderregistration() |
| 9005 |
{ |
| 9006 |
//modal box, so we do not set menu or footer |
| 9007 |
|
| 9008 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'orderregistration')); |
| 9009 |
|
| 9010 |
parent::display(); |
| 9011 |
} |
| 9012 |
|
| 9013 |
/** |
| 9014 |
* AJAX endpoint to update the registration status for an order. |
| 9015 |
* |
| 9016 |
* @since 1.2.0 |
| 9017 |
*/ |
| 9018 |
public function update_reg_status() |
| 9019 |
{ |
| 9020 |
$dbo = JFactory::getDbo(); |
| 9021 |
$cid = VikRequest::getVar('cid', array(0)); |
| 9022 |
|
| 9023 |
if (empty($cid[0])) { |
| 9024 |
throw new Exception("Missing order ID", 404); |
| 9025 |
} |
| 9026 |
|
| 9027 |
$q = "SELECT * FROM `#__vikrentcar_orders` WHERE `id`=" . (int)$cid[0] . ";"; |
| 9028 |
$dbo->setQuery($q); |
| 9029 |
$dbo->execute(); |
| 9030 |
if (!$dbo->getNumRows()) { |
| 9031 |
throw new Exception("Order ID not found", 404); |
| 9032 |
} |
| 9033 |
$order = $dbo->loadAssoc(); |
| 9034 |
|
| 9035 |
$newregstatus = VikRequest::getInt('newregstatus', 0, 'request'); |
| 9036 |
$regstatusnotes = VikRequest::getString('regstatusnotes', '', 'request'); |
| 9037 |
|
| 9038 |
$valid_statuses = array(-1, 0, 1, 2); |
| 9039 |
if (!in_array($newregstatus, $valid_statuses)) { |
| 9040 |
throw new Exception("Bad status value", 400); |
| 9041 |
} |
| 9042 |
|
| 9043 |
// get order history |
| 9044 |
$history_obj = VikRentCar::getOrderHistoryInstance()->setBid($order['id']); |
| 9045 |
|
| 9046 |
// update order record |
| 9047 |
$order_record = new stdClass; |
| 9048 |
$order_record->id = $order['id']; |
| 9049 |
$order_record->reg = $newregstatus; |
| 9050 |
|
| 9051 |
$dbo->updateObject('#__vikrentcar_orders', $order_record, 'id'); |
| 9052 |
|
| 9053 |
// use order history to store the information of this event (default to unset) |
| 9054 |
$history_type = 'RA'; |
| 9055 |
if ($newregstatus === -1) { |
| 9056 |
// no show |
| 9057 |
$history_type = 'RZ'; |
| 9058 |
} elseif ($newregstatus === 1) { |
| 9059 |
// started |
| 9060 |
$history_type = 'RB'; |
| 9061 |
} elseif ($newregstatus === 2) { |
| 9062 |
// terminated |
| 9063 |
$history_type = 'RC'; |
| 9064 |
} |
| 9065 |
|
| 9066 |
// build the extra description for the event |
| 9067 |
$history_extra_descr = date(VikRentCar::getTimeFormat()); |
| 9068 |
$prev_started_dt = $history_obj->hasEvent('RB'); |
| 9069 |
if ($history_type == 'RC' && $prev_started_dt !== false) { |
| 9070 |
// calculate the exact duration of the rental from last check-in (started) event |
| 9071 |
$from_dobj = new DateTime($prev_started_dt); |
| 9072 |
$to_dobj = new DateTime(date('Y-m-d H:i:s')); |
| 9073 |
$dobj_interval = $from_dobj->diff($to_dobj); |
| 9074 |
// format exact duration of rent in days, hours and minutes |
| 9075 |
$history_extra_descr = JText::translate('VRC_TOT_DURATION') . ': ' . $dobj_interval->format('%d ' . JText::translate('VRDAYS') . ', %h ' . JText::translate('VRCONFIGONETENEIGHT') . ', %i ' . JText::translate('VRCTRKDIFFMINS')); |
| 9076 |
} |
| 9077 |
|
| 9078 |
// always display full time of the operation |
| 9079 |
$regstatusnotes = $history_extra_descr . "\n" . $regstatusnotes; |
| 9080 |
// store history record |
| 9081 |
$history_obj->store($history_type, $regstatusnotes); |
| 9082 |
|
| 9083 |
// set new buttons class and text |
| 9084 |
$reg_status = JText::translate('VRC_ORDER_REGISTRATION_NONE'); |
| 9085 |
$reg_class = 'btn btn-small btn-secondary'; |
| 9086 |
if ($newregstatus < 0) { |
| 9087 |
// no show |
| 9088 |
$reg_status = JText::translate('VRC_ORDER_REGISTRATION_NOSHOW'); |
| 9089 |
$reg_class = 'btn btn-small btn-danger'; |
| 9090 |
} elseif ($newregstatus === 1) { |
| 9091 |
// started |
| 9092 |
$reg_status = JText::translate('VRC_ORDER_REGISTRATION_STARTED'); |
| 9093 |
$reg_class = 'btn btn-small btn-primary'; |
| 9094 |
} elseif ($newregstatus === 2) { |
| 9095 |
// terminated |
| 9096 |
$reg_status = JText::translate('VRC_ORDER_REGISTRATION_TERMINATED'); |
| 9097 |
$reg_class = 'btn btn-small btn-primary'; |
| 9098 |
} |
| 9099 |
|
| 9100 |
$response = array( |
| 9101 |
'btn_class' => $reg_class, |
| 9102 |
'btn_text' => $reg_status, |
| 9103 |
); |
| 9104 |
|
| 9105 |
echo json_encode($response); |
| 9106 |
exit; |
| 9107 |
} |
| 9108 |
|
| 9109 |
/** |
| 9110 |
* AJAX upload the customer documents. |
| 9111 |
* |
| 9112 |
* @return void |
| 9113 |
* |
| 9114 |
* @throws Exception |
| 9115 |
* |
| 9116 |
* @since 1.2.0 |
| 9117 |
*/ |
| 9118 |
public function upload_customer_document() |
| 9119 |
{ |
| 9120 |
$input = JFactory::getApplication()->input; |
| 9121 |
$dbo = JFactory::getDbo(); |
| 9122 |
|
| 9123 |
$customer_id = $input->getUint('customer', 0); |
| 9124 |
|
| 9125 |
$result = new stdClass; |
| 9126 |
$result->status = 0; |
| 9127 |
|
| 9128 |
try |
| 9129 |
{ |
| 9130 |
$q = $dbo->getQuery(true) |
| 9131 |
->select($dbo->qn(array( |
| 9132 |
'id', |
| 9133 |
'first_name', |
| 9134 |
'last_name', |
| 9135 |
'email', |
| 9136 |
'docsfolder', |
| 9137 |
))) |
| 9138 |
->from($dbo->qn('#__vikrentcar_customers')) |
| 9139 |
->where($dbo->qn('id') . ' = ' . $customer_id); |
| 9140 |
|
| 9141 |
$dbo->setQuery($q, 0, 1); |
| 9142 |
$dbo->execute(); |
| 9143 |
|
| 9144 |
if (!$dbo->getNumRows()) |
| 9145 |
{ |
| 9146 |
throw new Exception(sprintf('Customer [%d] not found', $customer_id), 404); |
| 9147 |
} |
| 9148 |
|
| 9149 |
$customer = $dbo->loadObject(); |
| 9150 |
|
| 9151 |
// fetch documents folder path |
| 9152 |
$dirpath = VRC_CUSTOMERS_PATH . DIRECTORY_SEPARATOR; |
| 9153 |
|
| 9154 |
// check if we have a valid directory |
| 9155 |
if (empty($customer->docsfolder) || !is_dir($dirpath . $customer->docsfolder)) |
| 9156 |
{ |
| 9157 |
// randomize string |
| 9158 |
$customer->seed = uniqid(); |
| 9159 |
|
| 9160 |
// create blocks for hashed folder |
| 9161 |
$parts = [ |
| 9162 |
$customer->first_name, |
| 9163 |
$customer->last_name, |
| 9164 |
md5(serialize($customer)), |
| 9165 |
]; |
| 9166 |
|
| 9167 |
// join fetched parts |
| 9168 |
$customer->docsfolder = JFilterOutput::stringURLSafe(implode('-', array_filter($parts))); |
| 9169 |
|
| 9170 |
if (strlen($customer->docsfolder) < 16) |
| 9171 |
{ |
| 9172 |
throw new Exception('Possible security breach. Please specify the most details as possible.', 400); |
| 9173 |
} |
| 9174 |
|
| 9175 |
jimport('joomla.filesystem.folder'); |
| 9176 |
|
| 9177 |
// create a folder for this customer |
| 9178 |
$created = JFolder::create($dirpath . $customer->docsfolder); |
| 9179 |
|
| 9180 |
if (!$created) |
| 9181 |
{ |
| 9182 |
throw new Exception(sprintf('Unable to create the folder [%s]', $dirpath . $customer->docsfolder), 403); |
| 9183 |
} |
| 9184 |
|
| 9185 |
unset($customer->seed); |
| 9186 |
|
| 9187 |
// update docs folder |
| 9188 |
$dbo->updateObject('#__vikrentcar_customers', $customer, 'id'); |
| 9189 |
} |
| 9190 |
|
| 9191 |
// get file from request |
| 9192 |
$file = $input->files->get('file', array(), 'array'); |
| 9193 |
|
| 9194 |
// try to upload the file |
| 9195 |
$result = VikRentCar::uploadFileFromRequest($file, $dirpath . $customer->docsfolder, 'png,jpg,jpeg,bmp,heic,zip,rar,pdf,doc,docx,rtf,odt,pages,xls,xlsx,csv,ods,numbers,txt,md'); |
| 9196 |
$result->status = 1; |
| 9197 |
|
| 9198 |
$result->size = JHtml::fetch('number.bytes', filesize($result->path), 'auto', 0); |
| 9199 |
$result->url = str_replace(DIRECTORY_SEPARATOR, '/', str_replace(VRC_CUSTOMERS_PATH . DIRECTORY_SEPARATOR, VRC_CUSTOMERS_URI, $result->path)); |
| 9200 |
} |
| 9201 |
catch (Exception $e) |
| 9202 |
{ |
| 9203 |
$result->error = $e->getMessage(); |
| 9204 |
$result->code = $e->getCode(); |
| 9205 |
} |
| 9206 |
|
| 9207 |
echo json_encode($result); |
| 9208 |
exit; |
| 9209 |
} |
| 9210 |
|
| 9211 |
/** |
| 9212 |
* AJAX delete the customer documents. |
| 9213 |
* |
| 9214 |
* @return void |
| 9215 |
* |
| 9216 |
* @throws Exception |
| 9217 |
* |
| 9218 |
* @since 1.2.0 |
| 9219 |
*/ |
| 9220 |
public function delete_customer_document() |
| 9221 |
{ |
| 9222 |
$input = JFactory::getApplication()->input; |
| 9223 |
$dbo = JFactory::getDbo(); |
| 9224 |
|
| 9225 |
$customer_id = $input->getUint('customer', 0); |
| 9226 |
|
| 9227 |
$result = new stdClass; |
| 9228 |
$result->status = 0; |
| 9229 |
|
| 9230 |
$q = $dbo->getQuery(true) |
| 9231 |
->select($dbo->qn('docsfolder')) |
| 9232 |
->from($dbo->qn('#__vikrentcar_customers')) |
| 9233 |
->where($dbo->qn('id') . ' = ' . $customer_id); |
| 9234 |
|
| 9235 |
$dbo->setQuery($q, 0, 1); |
| 9236 |
$dbo->execute(); |
| 9237 |
|
| 9238 |
if (!$dbo->getNumRows()) |
| 9239 |
{ |
| 9240 |
throw new Exception(sprintf('Customer [%d] not found', $customer_id), 404); |
| 9241 |
} |
| 9242 |
|
| 9243 |
$folder = $dbo->loadResult(); |
| 9244 |
|
| 9245 |
if (!$folder) |
| 9246 |
{ |
| 9247 |
throw new Exception('The customer does not have any documents', 500); |
| 9248 |
} |
| 9249 |
|
| 9250 |
$file = $input->getString('file'); |
| 9251 |
|
| 9252 |
if (!$file) |
| 9253 |
{ |
| 9254 |
throw new Exception('File to remove not specified', 400); |
| 9255 |
} |
| 9256 |
|
| 9257 |
$path = implode(DIRECTORY_SEPARATOR, array(VRC_CUSTOMERS_PATH, $folder, $file)); |
| 9258 |
|
| 9259 |
if (!is_file($path)) |
| 9260 |
{ |
| 9261 |
throw new Exception(sprintf('File [%s] not found', $path), 404); |
| 9262 |
} |
| 9263 |
|
| 9264 |
jimport('joomla.filesystem.file'); |
| 9265 |
|
| 9266 |
$removed = JFile::delete($path); |
| 9267 |
|
| 9268 |
echo json_encode(array('status' => (int) $removed)); |
| 9269 |
exit; |
| 9270 |
} |
| 9271 |
|
| 9272 |
/** |
| 9273 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9274 |
*/ |
| 9275 |
public function newcondtext() |
| 9276 |
{ |
| 9277 |
VikRentCarHelper::printHeader("11"); |
| 9278 |
|
| 9279 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecondtext')); |
| 9280 |
|
| 9281 |
parent::display(); |
| 9282 |
|
| 9283 |
if (VikRentCar::showFooter()) { |
| 9284 |
VikRentCarHelper::printFooter(); |
| 9285 |
} |
| 9286 |
} |
| 9287 |
|
| 9288 |
/** |
| 9289 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9290 |
*/ |
| 9291 |
public function editcondtext() |
| 9292 |
{ |
| 9293 |
VikRentCarHelper::printHeader("11"); |
| 9294 |
|
| 9295 |
VikRequest::setVar('view', VikRequest::getCmd('view', 'managecondtext')); |
| 9296 |
|
| 9297 |
parent::display(); |
| 9298 |
|
| 9299 |
if (VikRentCar::showFooter()) { |
| 9300 |
VikRentCarHelper::printFooter(); |
| 9301 |
} |
| 9302 |
} |
| 9303 |
|
| 9304 |
/** |
| 9305 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9306 |
*/ |
| 9307 |
public function cancelcondtext() |
| 9308 |
{ |
| 9309 |
JFactory::getApplication()->redirect('index.php?option=com_vikrentcar&task=config&tab=5'); |
| 9310 |
} |
| 9311 |
|
| 9312 |
/** |
| 9313 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9314 |
*/ |
| 9315 |
public function createcondtext() |
| 9316 |
{ |
| 9317 |
if (!JSession::checkToken()) { |
| 9318 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 9319 |
} |
| 9320 |
$this->_doCreateCondText(); |
| 9321 |
} |
| 9322 |
|
| 9323 |
/** |
| 9324 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9325 |
*/ |
| 9326 |
public function createcondtextstay() |
| 9327 |
{ |
| 9328 |
if (!JSession::checkToken()) { |
| 9329 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 9330 |
} |
| 9331 |
$this->_doCreateCondText(true); |
| 9332 |
} |
| 9333 |
|
| 9334 |
/** |
| 9335 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9336 |
*/ |
| 9337 |
private function _doCreateCondText($stay = false) |
| 9338 |
{ |
| 9339 |
$dbo = JFactory::getDbo(); |
| 9340 |
$app = JFactory::getApplication(); |
| 9341 |
$rules_helper = VikRentCar::getConditionalRulesInstance(); |
| 9342 |
$rules_list = $rules_helper->composeRulesParamsFromRequest(); |
| 9343 |
|
| 9344 |
$condtextname = VikRequest::getString('condtextname', '', 'request'); |
| 9345 |
$condtexttkn = VikRequest::getString('condtexttkn', '', 'request'); |
| 9346 |
$msg = VikRequest::getString('msg', '', 'request', VIKREQUEST_ALLOWRAW); |
| 9347 |
$debug = VikRequest::getInt('debug', 0, 'request'); |
| 9348 |
if (empty($condtextname)) { |
| 9349 |
$condtextname = date('Y-m-dHis'); |
| 9350 |
$condtexttkn = '{condition: ' . date('YmdHis') . '}'; |
| 9351 |
} |
| 9352 |
|
| 9353 |
$existing_tokens = $rules_helper->getSpecialTags(); |
| 9354 |
if (count($existing_tokens) && isset($existing_tokens[$condtexttkn])) { |
| 9355 |
VikError::raiseWarning('', 'Another conditional text with the same special tag already exists'); |
| 9356 |
$app->redirect('index.php?option=com_vikrentcar&task=newcondtext'); |
| 9357 |
exit; |
| 9358 |
} |
| 9359 |
|
| 9360 |
$data = new stdClass; |
| 9361 |
$data->name = $condtextname; |
| 9362 |
$data->token = $condtexttkn; |
| 9363 |
$data->rules = json_encode($rules_list); |
| 9364 |
$data->msg = $msg; |
| 9365 |
$data->lastupd = JDate::getInstance()->toSql(); |
| 9366 |
$data->debug = $debug; |
| 9367 |
|
| 9368 |
$dbo->insertObject('#__vikrentcar_condtexts', $data, 'id'); |
| 9369 |
|
| 9370 |
if (isset($data->id)) { |
| 9371 |
$app->enqueueMessage(JText::translate('VRSEASONUPDATED')); |
| 9372 |
} |
| 9373 |
|
| 9374 |
if (!$stay || !isset($data->id)) { |
| 9375 |
$this->cancelcondtext(); |
| 9376 |
exit; |
| 9377 |
} |
| 9378 |
|
| 9379 |
$app->redirect('index.php?option=com_vikrentcar&task=editcondtext&cid[]=' . $data->id); |
| 9380 |
} |
| 9381 |
|
| 9382 |
/** |
| 9383 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9384 |
*/ |
| 9385 |
public function updatecondtext() |
| 9386 |
{ |
| 9387 |
if (!JSession::checkToken()) { |
| 9388 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 9389 |
} |
| 9390 |
$this->_doUpdateCondText(); |
| 9391 |
} |
| 9392 |
|
| 9393 |
/** |
| 9394 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9395 |
*/ |
| 9396 |
public function updatecondtextstay() |
| 9397 |
{ |
| 9398 |
if (!JSession::checkToken()) { |
| 9399 |
throw new Exception(JText::translate('JINVALID_TOKEN'), 403); |
| 9400 |
} |
| 9401 |
$this->_doUpdateCondText(true); |
| 9402 |
} |
| 9403 |
|
| 9404 |
/** |
| 9405 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9406 |
*/ |
| 9407 |
private function _doUpdateCondText($stay = false) |
| 9408 |
{ |
| 9409 |
$dbo = JFactory::getDbo(); |
| 9410 |
$app = JFactory::getApplication(); |
| 9411 |
$rules_helper = VikRentCar::getConditionalRulesInstance(); |
| 9412 |
$rules_list = $rules_helper->composeRulesParamsFromRequest(); |
| 9413 |
|
| 9414 |
$pwhere = VikRequest::getInt('where', '', 'request'); |
| 9415 |
$condtextname = VikRequest::getString('condtextname', '', 'request'); |
| 9416 |
$condtexttkn = VikRequest::getString('condtexttkn', '', 'request'); |
| 9417 |
$msg = VikRequest::getString('msg', '', 'request', VIKREQUEST_ALLOWRAW); |
| 9418 |
$debug = VikRequest::getInt('debug', 0, 'request'); |
| 9419 |
if (empty($condtextname)) { |
| 9420 |
$condtextname = date('Y-m-dHis'); |
| 9421 |
$condtexttkn = '{condition: ' . date('YmdHis') . '}'; |
| 9422 |
} |
| 9423 |
|
| 9424 |
$existing_tokens = $rules_helper->getSpecialTags(); |
| 9425 |
if (count($existing_tokens) && isset($existing_tokens[$condtexttkn]) && ($existing_tokens[$condtexttkn]['id'] != $pwhere)) { |
| 9426 |
VikError::raiseWarning('', 'Another conditional text with the same special tag already exists (' . $existing_tokens[$condtexttkn]['name'] . ')'); |
| 9427 |
$app->redirect('index.php?option=com_vikrentcar&task=editcondtext&cid[]=' . $pwhere); |
| 9428 |
exit; |
| 9429 |
} |
| 9430 |
|
| 9431 |
$data = new stdClass; |
| 9432 |
$data->id = $pwhere; |
| 9433 |
$data->name = $condtextname; |
| 9434 |
$data->token = $condtexttkn; |
| 9435 |
$data->rules = json_encode($rules_list); |
| 9436 |
$data->msg = $msg; |
| 9437 |
$data->lastupd = JDate::getInstance()->toSql(); |
| 9438 |
$data->debug = $debug; |
| 9439 |
|
| 9440 |
$dbo->updateObject('#__vikrentcar_condtexts', $data, 'id'); |
| 9441 |
|
| 9442 |
$app->enqueueMessage(JText::translate('VRSEASONUPDATED')); |
| 9443 |
|
| 9444 |
if (!$stay) { |
| 9445 |
$this->cancelcondtext(); |
| 9446 |
exit; |
| 9447 |
} |
| 9448 |
|
| 9449 |
$app->redirect('index.php?option=com_vikrentcar&task=editcondtext&cid[]=' . $data->id); |
| 9450 |
} |
| 9451 |
|
| 9452 |
/** |
| 9453 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9454 |
*/ |
| 9455 |
public function removecondtext() |
| 9456 |
{ |
| 9457 |
$dbo = JFactory::getDbo(); |
| 9458 |
$ids = VikRequest::getVar('cid', array()); |
| 9459 |
if (count($ids)) { |
| 9460 |
foreach ($ids as $d){ |
| 9461 |
$q = "DELETE FROM `#__vikrentcar_condtexts` WHERE `id`=".(int)$d.";"; |
| 9462 |
$dbo->setQuery($q); |
| 9463 |
$dbo->execute(); |
| 9464 |
} |
| 9465 |
} |
| 9466 |
$this->cancelcondtext(); |
| 9467 |
} |
| 9468 |
|
| 9469 |
/** |
| 9470 |
* AJAX endpoint to update one template file with the given tag or styles. |
| 9471 |
* A JSON response will be echoed by exiting the process. |
| 9472 |
* |
| 9473 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9474 |
*/ |
| 9475 |
public function condtext_update_tmpl() |
| 9476 |
{ |
| 9477 |
VikRentCar::getConditionalRulesInstance(true); |
| 9478 |
|
| 9479 |
$tagaction = VikRequest::getString('tagaction', '', 'request'); |
| 9480 |
$tag = VikRequest::getString('tag', '', 'request'); |
| 9481 |
$file = VikRequest::getString('file', '', 'request', VIKREQUEST_ALLOWRAW); |
| 9482 |
$newcontent = VikRequest::getString('newcontent', '', 'request', VIKREQUEST_ALLOWRAW); |
| 9483 |
$custom_classes = VikRequest::getVar('custom_classes', array(), 'request', 'array'); |
| 9484 |
|
| 9485 |
$allowed_actions = array( |
| 9486 |
'add', |
| 9487 |
'remove', |
| 9488 |
'styles', |
| 9489 |
'restore', |
| 9490 |
); |
| 9491 |
|
| 9492 |
if (empty($tagaction) || empty($file) || !in_array($tagaction, $allowed_actions)) { |
| 9493 |
VRCHttpDocument::getInstance()->close(500, 'Invalid request submitted'); |
| 9494 |
} |
| 9495 |
|
| 9496 |
if (in_array($tagaction, array('add', 'remove')) && empty($tag)) { |
| 9497 |
VRCHttpDocument::getInstance()->close(500, 'Invalid request submitted - missing tag'); |
| 9498 |
} |
| 9499 |
|
| 9500 |
if (in_array($tagaction, array('add', 'styles')) && empty($newcontent)) { |
| 9501 |
VRCHttpDocument::getInstance()->close(500, 'Invalid request submitted - missing new HTML content'); |
| 9502 |
} |
| 9503 |
|
| 9504 |
if ($tagaction == 'styles' && (!is_array($custom_classes) || !count($custom_classes))) { |
| 9505 |
VRCHttpDocument::getInstance()->close(500, 'No custom CSS classes to parse'); |
| 9506 |
} |
| 9507 |
|
| 9508 |
if ($tagaction == 'restore') { |
| 9509 |
// immediately restore the requested file to avoid script interruptions |
| 9510 |
VikRentCarHelperConditionalRules::restoreTemplateFileCode($file); |
| 9511 |
} |
| 9512 |
|
| 9513 |
// get requested file content |
| 9514 |
$fcontent = VikRentCarHelperConditionalRules::getTemplateFileCode($file); |
| 9515 |
if (empty($fcontent) || !is_string($fcontent)) { |
| 9516 |
VRCHttpDocument::getInstance()->close(404, 'File not found or its code is unreadable'); |
| 9517 |
} |
| 9518 |
|
| 9519 |
if ($tagaction == 'remove') { |
| 9520 |
// remove tag from code content |
| 9521 |
$fcontent = str_replace($tag, '', $fcontent); |
| 9522 |
} elseif ($tagaction == 'add') { |
| 9523 |
// add tag to code content in the same exact position |
| 9524 |
$fcontent = VikRentCarHelperConditionalRules::addTagByComparingSources($tag, $file, $newcontent, $fcontent); |
| 9525 |
} elseif ($tagaction == 'styles') { |
| 9526 |
// apply the same styling rules |
| 9527 |
$fcontent = VikRentCarHelperConditionalRules::addStylesByComparingSources($custom_classes, $file, $newcontent, $fcontent); |
| 9528 |
} |
| 9529 |
|
| 9530 |
// update the file code |
| 9531 |
$res = VikRentCarHelperConditionalRules::writeTemplateFileCode($file, $fcontent); |
| 9532 |
|
| 9533 |
if (!$res) { |
| 9534 |
VRCHttpDocument::getInstance()->close(500, 'Could not update the source code of the template file'); |
| 9535 |
} |
| 9536 |
|
| 9537 |
// parse new HTML content |
| 9538 |
$newhtmls = VikRentCarHelperConditionalRules::getTemplateFilesContents($file); |
| 9539 |
if (!is_array($newhtmls) || !isset($newhtmls[$file])) { |
| 9540 |
VRCHttpDocument::getInstance()->close(404, 'Could not parse new template file content'); |
| 9541 |
} |
| 9542 |
|
| 9543 |
// trigger backup/mirroring, if available |
| 9544 |
if (defined('ABSPATH')) { |
| 9545 |
VikRentCarUpdateManager::storeTemplateContent($file, $newhtmls[$file]); |
| 9546 |
} |
| 9547 |
|
| 9548 |
// build output |
| 9549 |
$output = new stdClass; |
| 9550 |
$output->newhtml = $newhtmls[$file]; |
| 9551 |
$output->log = VikRentCarHelperConditionalRules::getEditingLog(); |
| 9552 |
|
| 9553 |
// output the JSON response and exit |
| 9554 |
VRCHttpDocument::getInstance()->json($output); |
| 9555 |
} |
| 9556 |
|
| 9557 |
/** |
| 9558 |
* AJAX endpoint to render the measurment driver params. |
| 9559 |
* |
| 9560 |
* @return void |
| 9561 |
* |
| 9562 |
* @since 1.15.0 (J) - 1.3.0 (WP) |
| 9563 |
*/ |
| 9564 |
public function loadmeasurmentparams() |
| 9565 |
{ |
| 9566 |
$html = '---------'; |
| 9567 |
$driver_id = VikRequest::getString('driver_id', '', 'request'); |
| 9568 |
if (!empty($driver_id)) { |
| 9569 |
$html = VRCConversionFactory::getInstance()->displayParams($driver_id); |
| 9570 |
} |
| 9571 |
/** |
| 9572 |
* The HTML content is built by an internal method that does not trigger any hook |
| 9573 |
* where third party plugins could interfere. We cannot escape this HTML string, |
| 9574 |
* nor can we convert special chars into HTML entities, as this is the response |
| 9575 |
* of an AJAX request, and the HTML code needs to be displayed accordingly. |
| 9576 |
* If we were to escape the HTML string, then the AJAX response would be useless, |
| 9577 |
* as it would be HTML code converted into text with HTML entities. |
| 9578 |
*/ |
| 9579 |
echo $html; |
| 9580 |
exit; |
| 9581 |
} |
| 9582 |
} |
| 9583 |
|