| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage com_vikbooking |
| 5 |
* @author Alessio Gaggii - e4j - Extensionsforjoomla.com |
| 6 |
* @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved. |
| 7 |
* @license GNU General Public License version 2 or later; see LICENSE |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 12 |
|
| 13 |
// import Joomla view library |
| 14 |
jimport('joomla.application.component.view'); |
| 15 |
|
| 16 |
class VikBookingViewTmplfileprew extends JViewVikBooking { |
| 17 |
|
| 18 |
function display($tpl = null) { |
| 19 |
// This view is usually called within a modal box, so it does not require the toolbar or page title |
| 20 |
|
| 21 |
$fpath = VikRequest::getString('path', '', 'request', VIKREQUEST_ALLOWRAW); |
| 22 |
if (!empty($fpath) && !is_file($fpath)) { |
| 23 |
$fpath = urldecode($fpath); |
| 24 |
} |
| 25 |
// list of allowed template files for preview |
| 26 |
$allowed_previews = array( |
| 27 |
'email_tmpl.php', |
| 28 |
); |
| 29 |
$fbase = basename($fpath); |
| 30 |
$htmlpreview = ''; |
| 31 |
if (!is_file($fpath) || !in_array($fbase, $allowed_previews)) { |
| 32 |
throw new Exception("File {$fbase} not found", 404); |
| 33 |
} |
| 34 |
|
| 35 |
// load template file preview |
| 36 |
$dbo = JFactory::getDbo(); |
| 37 |
|
| 38 |
$force_bid = VikRequest::getInt('bid', 0, 'request'); |
| 39 |
|
| 40 |
switch ($fbase) { |
| 41 |
case 'email_tmpl.php': |
| 42 |
// find the last confirmed booking |
| 43 |
$q = "SELECT `id` FROM `#__vikbooking_orders` WHERE `status`='confirmed' AND `closure`=0 ORDER BY `id` DESC LIMIT 1;"; |
| 44 |
$dbo->setQuery($q); |
| 45 |
$dbo->execute(); |
| 46 |
if ($dbo->getNumRows()) { |
| 47 |
$use_bid = !empty($force_bid) ? $force_bid : $dbo->loadResult(); |
| 48 |
$htmlpreview = VikBooking::sendBookingEmail($use_bid, [], false); |
| 49 |
} else { |
| 50 |
$htmlpreview = '<p class="warn">' . JText::translate('VBNOORDERSFOUND') . '</p>'; |
| 51 |
} |
| 52 |
break; |
| 53 |
default: |
| 54 |
break; |
| 55 |
} |
| 56 |
|
| 57 |
$this->fpath = $fpath; |
| 58 |
$this->fbase = $fbase; |
| 59 |
$this->htmlpreview = $htmlpreview; |
| 60 |
|
| 61 |
// Display the template |
| 62 |
parent::display($tpl); |
| 63 |
} |
| 64 |
|
| 65 |
} |
| 66 |
|