| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2026 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
// import Joomla view library |
| 15 |
jimport('joomla.application.component.view'); |
| 16 |
|
| 17 |
/** |
| 18 |
* VikBooking manage quotation admin View. |
| 19 |
* |
| 20 |
* @since 1.18.8 (J) - 1.8.8 (WP) |
| 21 |
*/ |
| 22 |
class VikBookingViewManagequote extends JViewVikBooking |
| 23 |
{ |
| 24 |
public function display($tpl = null) |
| 25 |
{ |
| 26 |
// set the toolbar |
| 27 |
$this->addToolBar(); |
| 28 |
|
| 29 |
$app = JFactory::getApplication(); |
| 30 |
|
| 31 |
// access quote model |
| 32 |
$quoteModel = VBOMvcModel::getInstance('quote'); |
| 33 |
|
| 34 |
// get environment data |
| 35 |
$quoteId = $app->input->getUInt('quote_id', 0); |
| 36 |
$sessionId = $app->input->getUInt('session_id', 0); |
| 37 |
$chatSessionId = null; |
| 38 |
|
| 39 |
// recover existing values |
| 40 |
$quote = $quoteId ? ($quoteModel->loadBookingRecords(0, 0, ['filters' => ['id' => $quoteId]])[0] ?? null) : null; |
| 41 |
$customer = (array) $app->input->get('customer', [], 'array'); |
| 42 |
$inquiry = (array) $app->input->get('inquiry', [], 'array'); |
| 43 |
|
| 44 |
if ($sessionId && ($session = (new VBOChatSessionModel)->getItem($sessionId))) { |
| 45 |
// recover customer and inquiry data from chat session |
| 46 |
$customer = array_merge($customer, [ |
| 47 |
'name' => $session->name, |
| 48 |
'email' => $session->email, |
| 49 |
'phone' => $session->phone, |
| 50 |
]); |
| 51 |
|
| 52 |
// set chat session ID |
| 53 |
$chatSessionId = $session->id; |
| 54 |
|
| 55 |
if (empty($customer['first_name']) && !empty($customer['name'])) { |
| 56 |
// normalize customer name |
| 57 |
$nameParts = explode(' ', $customer['name']); |
| 58 |
$customer['first_name'] = (string) array_shift($nameParts); |
| 59 |
$customer['last_name'] = implode(' ', $nameParts); |
| 60 |
} |
| 61 |
|
| 62 |
if (!empty($customer['phone']) && !preg_match('/^\+/', $customer['phone'])) { |
| 63 |
// pre-pend plus character to phone number |
| 64 |
$customer['phone'] = '+' . $customer['phone']; |
| 65 |
} |
| 66 |
|
| 67 |
// recover inquiry information |
| 68 |
$inquiry = $session->metadata['query'] ?? []; |
| 69 |
} |
| 70 |
|
| 71 |
// load preferred quote message templates |
| 72 |
$prefMessages = $quoteModel->getItems( |
| 73 |
// clauses |
| 74 |
[ |
| 75 |
'preferred' => 1, |
| 76 |
], |
| 77 |
// start |
| 78 |
0, |
| 79 |
// lim |
| 80 |
30, |
| 81 |
// cols |
| 82 |
[ |
| 83 |
'id', |
| 84 |
'name', |
| 85 |
'subject', |
| 86 |
'message', |
| 87 |
'notes', |
| 88 |
'created_on', |
| 89 |
], |
| 90 |
// ordering |
| 91 |
[ |
| 92 |
'created_on' => 'DESC', |
| 93 |
] |
| 94 |
); |
| 95 |
|
| 96 |
// set template properties |
| 97 |
$this->quote = $quote; |
| 98 |
$this->customer = $customer; |
| 99 |
$this->inquiry = $inquiry; |
| 100 |
$this->chatSessionId = $chatSessionId; |
| 101 |
$this->prefMessages = $prefMessages; |
| 102 |
|
| 103 |
// display the template |
| 104 |
parent::display($tpl); |
| 105 |
} |
| 106 |
|
| 107 |
/** |
| 108 |
* Sets the toolbar. |
| 109 |
*/ |
| 110 |
protected function addToolBar() |
| 111 |
{ |
| 112 |
JToolBarHelper::title(JText::translate('VBO_QUOTE_MNG_TITLE'), 'vikbooking'); |
| 113 |
JToolBarHelper::custom('quote-apply', 'save', 'save', JText::translate('VBSAVE'), false); |
| 114 |
JToolBarHelper::custom('quote-see-all', 'list', 'list', JText::translate('VBO_SEE_ALL'), false); |
| 115 |
JToolBarHelper::cancel('canceldash', JText::translate('VBANNULLA')); |
| 116 |
} |
| 117 |
} |
| 118 |
|