Allow admin to upload check-in documents
This commit is contained in:
@@ -3,3 +3,11 @@
|
||||
|
||||
#customization_list
|
||||
border: 0px
|
||||
|
||||
#modal-booking-documents
|
||||
.booking-documents
|
||||
table
|
||||
tbody
|
||||
img
|
||||
max-height: 55px
|
||||
max-width: 55px
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
{**
|
||||
* 2010-2023 Webkul.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* All right is reserved,
|
||||
* Please go through LICENSE.txt file inside our module
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to newer
|
||||
* versions in the future. If you wish to customize this module for your
|
||||
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright 2010-2023 Webkul IN
|
||||
* @license LICENSE.txt
|
||||
*}
|
||||
|
||||
{if is_array($booking_documents) && count($booking_documents)}
|
||||
{foreach from=$booking_documents item=booking_document}
|
||||
<tr>
|
||||
<td class="text-left">{$booking_document.id_htl_booking_document}</td>
|
||||
<td class="text-center">
|
||||
{if $booking_document.file_type == HotelBookingDocument::FILE_TYPE_IMAGE}
|
||||
<a href="{$booking_document.file_link}" target="_blank">
|
||||
<img class="img img-responsive img-thumbnail" src="{$booking_document.file_link}">
|
||||
</a>
|
||||
{elseif $booking_document.file_type == HotelBookingDocument::FILE_TYPE_PDF}
|
||||
<a class="btn btn-default" href="{$link->getAdminLink('AdminBookingDocument')}&action=getDocument&id_document={$booking_document.id_htl_booking_document}">
|
||||
{l s='Download PDF'}
|
||||
</a>
|
||||
{/if}
|
||||
</td>
|
||||
<td class="text-center">
|
||||
<a class="btn btn-default btn-delete-document" data-id-htl-booking-document="{$booking_document.id_htl_booking_document}">
|
||||
<i class="icon icon-trash"></i>
|
||||
</a>
|
||||
</td>
|
||||
</tr>
|
||||
{/foreach}
|
||||
{else}
|
||||
<tr>
|
||||
<td colspan="3" class="text-center">{l s='No documents.'}</td>
|
||||
</tr>
|
||||
{/if}
|
||||
33
admin/themes/default/template/controllers/orders/_errors.tpl
Normal file
33
admin/themes/default/template/controllers/orders/_errors.tpl
Normal file
@@ -0,0 +1,33 @@
|
||||
{**
|
||||
* 2010-2023 Webkul.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* All right is reserved,
|
||||
* Please go through LICENSE.txt file inside our module
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to newer
|
||||
* versions in the future. If you wish to customize this module for your
|
||||
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright 2010-2023 Webkul IN
|
||||
* @license LICENSE.txt
|
||||
*}
|
||||
|
||||
{if isset($errors)}
|
||||
<p>
|
||||
{if count($errors) > 1}
|
||||
{l s='There are %d errors:' sprintf=[count($errors)]}
|
||||
{else}
|
||||
{l s='There is 1 error:'}
|
||||
{/if}
|
||||
</p>
|
||||
<ol>
|
||||
{foreach from=$errors item=error}
|
||||
<li>{$error}</li>
|
||||
{/foreach}
|
||||
</ol>
|
||||
{/if}
|
||||
@@ -275,8 +275,8 @@
|
||||
<tr>
|
||||
<th>{l s='Room No.'}</th>
|
||||
<th>{l s='Hotel Name'}</th>
|
||||
<th>{l s='Date From'}</th>
|
||||
<th>{l s='Date To'}</th>
|
||||
<th>{l s='Duration'}</th>
|
||||
<th>{l s='Documents'}</th>
|
||||
<th>{l s='Order Status'}</th>
|
||||
</tr>
|
||||
{if isset($htl_booking_order_data) && $htl_booking_order_data}
|
||||
@@ -291,10 +291,12 @@
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
{dateFormat date=$data['date_from']}
|
||||
{dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']}
|
||||
</td>
|
||||
<td>
|
||||
{dateFormat date=$data['date_to']}
|
||||
<a class="btn btn-default" onclick="BookingDocumentsModal.init({$data.id|intval}); return false;">
|
||||
{l s='Documents'}
|
||||
</a>
|
||||
</td>
|
||||
<td>
|
||||
<form action="" method="post" class="form-horizontal row room_status_info_form">
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
{**
|
||||
* 2010-2023 Webkul.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* All right is reserved,
|
||||
* Please go through LICENSE.txt file inside our module
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to newer
|
||||
* versions in the future. If you wish to customize this module for your
|
||||
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright 2010-2023 Webkul IN
|
||||
* @license LICENSE.txt
|
||||
*}
|
||||
|
||||
<div class="modal-body text-center">
|
||||
<div class="row">
|
||||
<div class="col-lg-12">
|
||||
<div class="alert alert-danger text-left errors-wrap" style="display: none;"></div>
|
||||
<form class="defaultForm form-horizontal booking-documents" action="#" method="post" enctype="multipart/form-data" novalidate>
|
||||
<input type="hidden" name="id_htl_booking" value="0" id="booking-document-id-htl-booking">
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-left">{l s='ID'}</th>
|
||||
<th class="text-center">{l s='Download/Preview'}</th>
|
||||
<th class="text-center">{l s='Actions'}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
|
||||
<div class="text-left add-new-wrap">
|
||||
<a class="btn btn-default btn-add-new-document">
|
||||
<i class="icon icon-plus"></i>
|
||||
{l s='Add new'}
|
||||
</a>
|
||||
<span></span>
|
||||
</div>
|
||||
<div class="input-file-wrap"></div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{addJsDefL name=txt_booking_document_upload_success}{l s='Document uploaded successfully.' js=1}{/addJsDefL}
|
||||
{addJsDefL name=txt_booking_document_delete_success}{l s='Document deleted successfully.' js=1}{/addJsDefL}
|
||||
@@ -327,6 +327,12 @@ class AdminOrdersControllerCore extends AdminController
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function initModal()
|
||||
{
|
||||
parent::initModal();
|
||||
$this->modals[] = $this->getModalBookingDocuments();
|
||||
}
|
||||
|
||||
public function setMedia()
|
||||
{
|
||||
parent::setMedia();
|
||||
@@ -1637,6 +1643,99 @@ class AdminOrdersControllerCore extends AdminController
|
||||
return parent::renderView();
|
||||
}
|
||||
|
||||
public function getModalBookingDocuments()
|
||||
{
|
||||
$modalContent = $this->context->smarty->fetch('controllers/orders/modal_booking_documents.tpl');
|
||||
|
||||
// set modal details
|
||||
$modal = array(
|
||||
'modal_id' => 'modal-booking-documents',
|
||||
'modal_class' => 'modal-md',
|
||||
'modal_title' => $this->l('Documents'),
|
||||
'modal_content' => $modalContent,
|
||||
'modal_actions' => array(), // required to show Close button
|
||||
);
|
||||
|
||||
return $modal;
|
||||
}
|
||||
|
||||
public function ajaxProcessGetBookingDocuments()
|
||||
{
|
||||
$response = array('status' => false);
|
||||
|
||||
$idHtlBooking = (int) Tools::getValue('id_htl_booking');
|
||||
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
|
||||
if (Validate::isLoadedObject($objHotelBookingDetail)) {
|
||||
$response['html'] = $this->getRenderedBookingDocuments($idHtlBooking);
|
||||
$response['status'] = true;
|
||||
}
|
||||
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
|
||||
public function ajaxProcessUploadBookingDocument()
|
||||
{
|
||||
$response = array('status' => false);
|
||||
|
||||
$idHtlBooking = (int) Tools::getValue('id_htl_booking');
|
||||
|
||||
// validations
|
||||
$objHotelBookingDetail = new HotelBookingDetail($idHtlBooking);
|
||||
if (!Validate::isLoadedObject($objHotelBookingDetail)) {
|
||||
$this->errors[] = $this->l('Booking detail not found.');
|
||||
}
|
||||
|
||||
$objHotelBookingDocument = new HotelBookingDocument();
|
||||
$objHotelBookingDocument->setFileInfoForUploadedDocument('booking_document');
|
||||
if (!count($objHotelBookingDocument->fileInfo)) {
|
||||
$this->errors[] = $this->l('Please upload a document.');
|
||||
} elseif ($objHotelBookingDocument->fileInfo['size'] > Tools::getMaxUploadSize()) {
|
||||
$this->errors[] = $this->l('Uploaded file size is too large.');
|
||||
}
|
||||
|
||||
if (!count($this->errors)) {
|
||||
$objHotelBookingDocument = new HotelBookingDocument();
|
||||
$objHotelBookingDocument->setFileInfoForUploadedDocument('booking_document');
|
||||
$objHotelBookingDocument->id_htl_booking = $idHtlBooking;
|
||||
$objHotelBookingDocument->setFileType();
|
||||
if ($objHotelBookingDocument->save()) {
|
||||
$objHotelBookingDocument->saveDocumentFile();
|
||||
|
||||
$response['html'] = $this->getRenderedBookingDocuments($idHtlBooking);
|
||||
$response['status'] = true;
|
||||
} else {
|
||||
$this->errors[] = $this->l('Document upload failed.');
|
||||
}
|
||||
} else {
|
||||
$this->context->smarty->assign(array(
|
||||
'errors' => $this->errors,
|
||||
));
|
||||
|
||||
$response['errors'] = $this->context->smarty->fetch('controllers/orders/_errors.tpl');
|
||||
$response['status'] = false;
|
||||
}
|
||||
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
|
||||
public function ajaxProcessDeleteBookingDocument()
|
||||
{
|
||||
$response = array('status' => false);
|
||||
|
||||
$idHtlBookingDocument = (int) Tools::getValue('id_htl_booking_document');
|
||||
|
||||
$objHotelBookingDocument = new HotelBookingDocument($idHtlBookingDocument);
|
||||
if (Validate::isLoadedObject($objHotelBookingDocument)) {
|
||||
$idHtlBooking = $objHotelBookingDocument->id_htl_booking;
|
||||
if ($objHotelBookingDocument->delete()) {
|
||||
$response['html'] = $this->getRenderedBookingDocuments($idHtlBooking);
|
||||
$response['status'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
|
||||
public function ajaxProcessUpdateGuestDetails()
|
||||
{
|
||||
$response = array(
|
||||
@@ -1680,6 +1779,25 @@ class AdminOrdersControllerCore extends AdminController
|
||||
$this->ajaxDie(json_encode($response));
|
||||
}
|
||||
|
||||
private function getRenderedBookingDocuments($idHtlBooking)
|
||||
{
|
||||
$bookingDocuments = HotelBookingDocument::getDocumentsByIdHtlBooking($idHtlBooking);
|
||||
|
||||
foreach($bookingDocuments as &$bookingDocument) {
|
||||
if ($bookingDocument['file_type'] == HotelBookingDocument::FILE_TYPE_IMAGE) {
|
||||
$bookingDocument['file_link'] = $this->context->link->getAdminLink('AdminBookingDocument').
|
||||
'&action=getDocument&id_document='.(int) $bookingDocument['id_htl_booking_document'];
|
||||
}
|
||||
}
|
||||
|
||||
$this->context->smarty->assign(array(
|
||||
'link' => $this->context->link,
|
||||
'booking_documents' => $bookingDocuments,
|
||||
));
|
||||
|
||||
return $this->context->smarty->fetch('controllers/orders/_booking_documents.tpl');
|
||||
}
|
||||
|
||||
public function ajaxProcessSearchProducts()
|
||||
{
|
||||
Context::getContext()->customer = new Customer((int)Tools::getValue('id_customer'));
|
||||
|
||||
@@ -1308,3 +1308,154 @@ function checkTotalRefundProductQuantity(it)
|
||||
if (order_discount_price)
|
||||
actualizeTotalRefundVoucher();
|
||||
}
|
||||
|
||||
$(document).on('click', '#modal-booking-documents .booking-documents .btn-add-new-document', function() {
|
||||
BookingDocumentsModal.addNew();
|
||||
BookingDocumentsFile.addNew();
|
||||
});
|
||||
|
||||
$(document).on('change', '.input-booking-document', function(e) {
|
||||
e.preventDefault();
|
||||
if (!this.files.length) {
|
||||
$(this).remove();
|
||||
return;
|
||||
}
|
||||
|
||||
BookingDocumentsFile.updatePreview();
|
||||
BookingDocumentsModal.uploadDocument();
|
||||
});
|
||||
|
||||
$(document).on('click', '#modal-booking-documents .booking-documents .btn-delete-document', function(e) {
|
||||
BookingDocumentsModal.deleteDocument(this);
|
||||
});
|
||||
|
||||
const BookingDocumentsModal = {
|
||||
init: function(idHtlBooking) {
|
||||
BookingDocumentsFile.noDocumentHtml = '<tr><td colspan="3">'+'a'+'</td></tr>';
|
||||
|
||||
$('#modal-booking-documents .booking-documents').find('[name="id_hotel_booking"]').val(idHtlBooking);
|
||||
BookingDocumentsFile.init();
|
||||
BookingDocumentsModal.reset();
|
||||
BookingDocumentsModal.show(idHtlBooking);
|
||||
},
|
||||
reset: function() {
|
||||
$('#modal-booking-documents .booking-documents table tbody').html('');
|
||||
},
|
||||
show: function(idHtlBooking) {
|
||||
$('#modal-booking-documents').modal('show');
|
||||
$('#modal-booking-documents #booking-document-id-htl-booking').attr('value', idHtlBooking);
|
||||
let data = {
|
||||
ajax: true,
|
||||
action: 'getBookingDocuments',
|
||||
id_htl_booking: parseInt(idHtlBooking),
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: admin_order_tab_link,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
success: function(response) {
|
||||
if (response.status) {
|
||||
BookingDocumentsModal.setBodyHtml(response.html);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
setBodyHtml: function(html) {
|
||||
$('#modal-booking-documents .booking-documents table tbody').html(html);
|
||||
},
|
||||
close: function() {
|
||||
$('#modal-booking-documents').modal('hide');
|
||||
},
|
||||
addNew: function() {
|
||||
BookingDocumentsModal.hideErrors();
|
||||
BookingDocumentsModal.disableAddNewButton();
|
||||
},
|
||||
beforeSubmit: function() {
|
||||
BookingDocumentsModal.hideErrors();
|
||||
BookingDocumentsModal.disableAddNewButton();
|
||||
},
|
||||
uploadDocument: function() {
|
||||
BookingDocumentsModal.beforeSubmit();
|
||||
let formData = new FormData($('#modal-booking-documents form.booking-documents').get(0));
|
||||
formData.append('ajax', true);
|
||||
formData.append('action', 'uploadBookingDocument');
|
||||
$.ajax({
|
||||
url: admin_order_tab_link,
|
||||
data: formData,
|
||||
processData: false,
|
||||
contentType: false,
|
||||
type: 'POST',
|
||||
success: function(response) {
|
||||
let jsonResponse = JSON.parse(response);
|
||||
if (jsonResponse.status) {
|
||||
showSuccessMessage(txt_booking_document_upload_success);
|
||||
BookingDocumentsModal.reset();
|
||||
BookingDocumentsFile.resetPreview();
|
||||
BookingDocumentsModal.setBodyHtml(jsonResponse.html);
|
||||
} else {
|
||||
BookingDocumentsModal.showErrors(jsonResponse.errors);
|
||||
}
|
||||
},
|
||||
complete: function() {
|
||||
BookingDocumentsModal.enableAddNewButton();
|
||||
},
|
||||
});
|
||||
},
|
||||
deleteDocument: function($this) {
|
||||
let idHtlBookingDocument = parseInt($($this).attr('data-id-htl-booking-document'));
|
||||
let data = {
|
||||
ajax: true,
|
||||
action: 'deleteBookingDocument',
|
||||
id_htl_booking_document: idHtlBookingDocument,
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
url: admin_order_tab_link,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
dataType: 'JSON',
|
||||
success: function(response) {
|
||||
if (response.status) {
|
||||
BookingDocumentsModal.setBodyHtml(response.html);
|
||||
showSuccessMessage(txt_booking_document_delete_success);
|
||||
}
|
||||
},
|
||||
});
|
||||
},
|
||||
showErrors: function(errors) {
|
||||
$('#modal-booking-documents .errors-wrap').html(errors);
|
||||
$('#modal-booking-documents .errors-wrap').show('slow');
|
||||
},
|
||||
hideErrors: function() {
|
||||
$('#modal-booking-documents .errors-wrap').hide('slow', function() {
|
||||
$('#modal-booking-documents .errors-wrap').html('');
|
||||
});
|
||||
},
|
||||
enableAddNewButton: function() {
|
||||
$('#modal-booking-documents .booking-documents .btn-add-new-document').removeClass('disabled');
|
||||
},
|
||||
disableAddNewButton: function() {
|
||||
$('#modal-booking-documents .booking-documents .btn-add-new-document').addClass('disabled');
|
||||
},
|
||||
}
|
||||
|
||||
const BookingDocumentsFile = {
|
||||
init: function() {
|
||||
BookingDocumentsFile.inputHtml = '<input type="file" accept="image/*, .pdf" class="input-booking-document hidden" name="booking_document">';
|
||||
},
|
||||
resetPreview: function() {
|
||||
$('#modal-booking-documents .booking-documents .add-new-wrap span').html('');
|
||||
},
|
||||
updatePreview: function() {
|
||||
BookingDocumentsFile.resetPreview();
|
||||
let input = $('#modal-booking-documents .booking-documents').find('.input-file-wrap input');
|
||||
let file = $(input).get(0).files[0];
|
||||
$('#modal-booking-documents .booking-documents .add-new-wrap span').html(file.name);
|
||||
},
|
||||
addNew: function() {
|
||||
$('#modal-booking-documents .booking-documents').find('.input-file-wrap').html(BookingDocumentsFile.inputHtml);
|
||||
$('#modal-booking-documents .booking-documents').find('.input-file-wrap input').click();
|
||||
},
|
||||
}
|
||||
|
||||
223
modules/hotelreservationsystem/classes/HotelBookingDocument.php
Normal file
223
modules/hotelreservationsystem/classes/HotelBookingDocument.php
Normal file
@@ -0,0 +1,223 @@
|
||||
<?php
|
||||
/**
|
||||
* 2010-2023 Webkul.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* All right is reserved,
|
||||
* Please go through LICENSE.txt file inside our module
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to newer
|
||||
* versions in the future. If you wish to customize this module for your
|
||||
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright 2010-2023 Webkul IN
|
||||
* @license LICENSE.txt
|
||||
*/
|
||||
|
||||
class HotelBookingDocument extends ObjectModel
|
||||
{
|
||||
public $id_htl_booking_document;
|
||||
public $id_htl_booking;
|
||||
public $file_type;
|
||||
public $file_name;
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
|
||||
const FILE_TYPE_IMAGE = 1;
|
||||
const FILE_TYPE_PDF = 2;
|
||||
|
||||
const DOWNLOAD_FILE_PREFIX = 'checkin_document_';
|
||||
|
||||
protected static $accessRights = 0775;
|
||||
|
||||
public static $definition = array(
|
||||
'table' => 'htl_booking_document',
|
||||
'primary' => 'id_htl_booking_document',
|
||||
'fields' => array(
|
||||
'id_htl_booking' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'file_type' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true),
|
||||
'file_name' => array('type' => self::TYPE_STRING, 'validate' => 'isString'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
),
|
||||
);
|
||||
|
||||
public function __construct($id = null)
|
||||
{
|
||||
$this->file_name = '';
|
||||
parent::__construct($id);
|
||||
|
||||
$this->documentsBaseDir = _PS_MODULE_DIR_.'hotelreservationsystem/documents/booking_guests/';
|
||||
$this->sourceIndexFile = $this->documentsBaseDir.'index.php';
|
||||
}
|
||||
|
||||
public function save($null_values = false, $auto_date = true)
|
||||
{
|
||||
parent::save($null_values, $auto_date);
|
||||
|
||||
$this->documentsBaseDir = _PS_MODULE_DIR_.'hotelreservationsystem/documents/booking_guests/';
|
||||
$this->sourceIndexFile = $this->documentsBaseDir.'index.php';
|
||||
|
||||
if ($this->id) {
|
||||
$this->setFileName();
|
||||
return $this->update();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function getDocumentsByIdHtlBooking($idHtlBooking)
|
||||
{
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT *
|
||||
FROM `'._DB_PREFIX_.'htl_booking_document`
|
||||
WHERE `id_htl_booking` = '.(int) $idHtlBooking
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDocumentsByIdOrder($idOrder)
|
||||
{
|
||||
return Db::getInstance()->executeS(
|
||||
'SELECT hbdo.*
|
||||
FROM `'._DB_PREFIX_.'htl_booking_document` hbdo
|
||||
INNER JOIN `'._DB_PREFIX_.'htl_booking_detail` hbde
|
||||
ON (hbde.`id` = hbdo.`id_htl_booking`)
|
||||
WHERE hbde.`id_order` = '.(int) $idOrder
|
||||
);
|
||||
}
|
||||
|
||||
public function setFileInfoForUploadedDocument($fileName)
|
||||
{
|
||||
$this->fileInfo = Tools::fileAttachment($fileName, false);
|
||||
}
|
||||
|
||||
public function saveDocumentFile()
|
||||
{
|
||||
if (!$this->id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->setDocumentFolder();
|
||||
$this->createDocumentFolder();
|
||||
|
||||
@move_uploaded_file($this->fileInfo['tmp_name'], $this->getDestinationFilePath());
|
||||
}
|
||||
|
||||
public function setDocumentFolder()
|
||||
{
|
||||
if (!isset($this->documentFolder)) {
|
||||
$this->documentFolder = $this->documentsBaseDir.Image::getImgFolderStatic($this->id);
|
||||
}
|
||||
}
|
||||
|
||||
public function createDocumentFolder()
|
||||
{
|
||||
if (!file_exists($this->documentFolder)) {
|
||||
// Trying both methods for setting access rights
|
||||
$mkdir = @mkdir($this->documentFolder, self::$accessRights, true);
|
||||
$chmod = @chmod($this->documentFolder, self::$accessRights);
|
||||
|
||||
// Copy index.php file in the new folder
|
||||
if (($mkdir || $chmod)
|
||||
&& !file_exists($this->documentFolder.'index.php')
|
||||
&& file_exists($this->sourceIndexFile)
|
||||
) {
|
||||
return @copy($this->sourceIndexFile, $this->documentFolder.'index.php');
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDestinationFilePath()
|
||||
{
|
||||
$fileExtension = pathinfo($this->fileInfo['rename'], PATHINFO_EXTENSION);
|
||||
|
||||
return $this->documentFolder.$this->id.'.'.$fileExtension;
|
||||
}
|
||||
|
||||
public function setFileType()
|
||||
{
|
||||
if (ImageManager::isRealImage($this->fileInfo['tmp_name'])) {
|
||||
$this->file_type = self::FILE_TYPE_IMAGE;
|
||||
} elseif ($this->fileInfo['mime'] == 'application/pdf') {
|
||||
$this->file_type = self::FILE_TYPE_PDF;
|
||||
} else {
|
||||
$this->file_type = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public function setFileName()
|
||||
{
|
||||
$fileExtension = pathinfo($this->fileInfo['rename'], PATHINFO_EXTENSION);
|
||||
$this->file_name = $this->id.'.'.$fileExtension;
|
||||
}
|
||||
|
||||
public function getContentType()
|
||||
{
|
||||
$file = $this->getPhysicalPath();
|
||||
|
||||
$contentType = 'application/octet-stream';
|
||||
if (function_exists('finfo_open')) {
|
||||
$fileInfo = @finfo_open(FILEINFO_MIME);
|
||||
$contentType = @finfo_file($fileInfo, $file);
|
||||
@finfo_close($fileInfo);
|
||||
} elseif (function_exists('mime_content_type')) {
|
||||
$contentType = @mime_content_type($file);
|
||||
} elseif (function_exists('exec')) {
|
||||
$contentType = trim(@exec('file -b --mime-type '.escapeshellarg($file)));
|
||||
if (!$contentType) {
|
||||
$contentType = trim(@exec('file --mime '.escapeshellarg($file)));
|
||||
}
|
||||
if (!$contentType) {
|
||||
$contentType = trim(@exec('file -bi '.escapeshellarg($file)));
|
||||
}
|
||||
}
|
||||
|
||||
return $contentType;
|
||||
}
|
||||
|
||||
public function getContentLength()
|
||||
{
|
||||
$file = $this->getPhysicalPath();
|
||||
|
||||
if (Tools::file_exists_cache($file)) {
|
||||
return filesize($file);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getPhysicalPath()
|
||||
{
|
||||
$this->setDocumentFolder();
|
||||
|
||||
return $this->documentFolder.$this->file_name;
|
||||
}
|
||||
|
||||
public function getDownloadFileName()
|
||||
{
|
||||
$objHotelBookingDetail = new HotelBookingDetail($this->id_htl_booking);
|
||||
$fileExtension = pathinfo($this->file_name, PATHINFO_EXTENSION);
|
||||
|
||||
return self::DOWNLOAD_FILE_PREFIX.$this->id_htl_booking_document.'_'.date('YmdHis').'.'.$fileExtension;
|
||||
}
|
||||
|
||||
public function deleteDocumentFolder()
|
||||
{
|
||||
$this->setDocumentFolder();
|
||||
|
||||
return Tools::deleteDirectory($this->documentFolder);
|
||||
}
|
||||
|
||||
public function delete()
|
||||
{
|
||||
$this->deleteDocumentFolder();
|
||||
|
||||
return parent::delete();
|
||||
}
|
||||
}
|
||||
@@ -180,6 +180,16 @@ class HotelReservationSystemDb
|
||||
PRIMARY KEY (`id`)
|
||||
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_document` (
|
||||
`id_htl_booking_document` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id_htl_booking` int(11) NOT NULL,
|
||||
`file_type` tinyint(1) NOT NULL DEFAULT '0',
|
||||
`file_name` varchar(8) NOT NULL DEFAULT '',
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_htl_booking_document`)
|
||||
) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;",
|
||||
|
||||
"CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_booking_demands` (
|
||||
`id_booking_demand` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`id_htl_booking` int(11) NOT NULL,
|
||||
@@ -471,6 +481,7 @@ class HotelReservationSystemDb
|
||||
`'._DB_PREFIX_.'htl_features_lang`,
|
||||
`'._DB_PREFIX_.'htl_cart_booking_data`,
|
||||
`'._DB_PREFIX_.'htl_booking_detail`,
|
||||
`'._DB_PREFIX_.'htl_booking_document`,
|
||||
`'._DB_PREFIX_.'htl_booking_demands`,
|
||||
`'._DB_PREFIX_.'htl_booking_demands_tax`,
|
||||
`'._DB_PREFIX_.'htl_room_status`,
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
/**
|
||||
* 2010-2023 Webkul.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* All right is reserved,
|
||||
* Please go through LICENSE.txt file inside our module
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to newer
|
||||
* versions in the future. If you wish to customize this module for your
|
||||
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright 2010-2023 Webkul IN
|
||||
* @license LICENSE.txt
|
||||
*/
|
||||
|
||||
class AdminBookingDocumentController extends ModuleAdminController
|
||||
{
|
||||
public function processGetDocument()
|
||||
{
|
||||
$idHtlBookingDocument = (int) Tools::getValue('id_document');
|
||||
$objHotelBookingDocument = new HotelBookingDocument($idHtlBookingDocument);
|
||||
if (Validate::isLoadedObject($objHotelBookingDocument)) {
|
||||
Hook::exec('actionDownloadBookingDocument', array('attachment' => &$objHotelBookingDocument));
|
||||
|
||||
$contentType = $objHotelBookingDocument->getContentType();
|
||||
$contentLength = $objHotelBookingDocument->getContentLength();
|
||||
$filePath = $objHotelBookingDocument->getPhysicalPath();
|
||||
$downloadFileName = $objHotelBookingDocument->getDownloadFileName();
|
||||
|
||||
if (Tools::file_exists_cache($filePath)) {
|
||||
if (ob_get_level() && ob_get_length() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
|
||||
header('Content-Transfer-Encoding: binary');
|
||||
header('Content-Type: '.$contentType);
|
||||
header('Content-Length: '.$contentLength);
|
||||
header('Content-Disposition: attachment; filename="'.$downloadFileName.'"');
|
||||
@set_time_limit(0);
|
||||
readfile($filePath);
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
header('HTTP/1.1 404 Not Found');
|
||||
header('Status: 404 Not Found');
|
||||
}
|
||||
|
||||
public function postProcess()
|
||||
{
|
||||
parent::postProcess();
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ require_once 'classes/HotelRoomDisableDates.php';
|
||||
require_once 'classes/HotelBranchRefundRules.php';
|
||||
|
||||
require_once 'classes/HotelSettingsLink.php';
|
||||
require_once 'classes/HotelBookingDocument.php';
|
||||
|
||||
// Web services classes
|
||||
require_once 'classes/WebserviceSpecificManagementQlo.php';
|
||||
1
modules/hotelreservationsystem/documents/.htaccess
Normal file
1
modules/hotelreservationsystem/documents/.htaccess
Normal file
@@ -0,0 +1 @@
|
||||
Deny from all
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 2010-2023 Webkul.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* All right is reserved,
|
||||
* Please go through LICENSE.txt file inside our module
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to newer
|
||||
* versions in the future. If you wish to customize this module for your
|
||||
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright 2010-2023 Webkul IN
|
||||
* @license LICENSE.txt
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
29
modules/hotelreservationsystem/documents/index.php
Normal file
29
modules/hotelreservationsystem/documents/index.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
/**
|
||||
* 2010-2023 Webkul.
|
||||
*
|
||||
* NOTICE OF LICENSE
|
||||
*
|
||||
* All right is reserved,
|
||||
* Please go through LICENSE.txt file inside our module
|
||||
*
|
||||
* DISCLAIMER
|
||||
*
|
||||
* Do not edit or add to this file if you wish to upgrade this module to newer
|
||||
* versions in the future. If you wish to customize this module for your
|
||||
* needs please refer to CustomizationPolicy.txt file inside our module for more information.
|
||||
*
|
||||
* @author Webkul IN
|
||||
* @copyright 2010-2023 Webkul IN
|
||||
* @license LICENSE.txt
|
||||
*/
|
||||
|
||||
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
|
||||
header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT');
|
||||
|
||||
header('Cache-Control: no-store, no-cache, must-revalidate');
|
||||
header('Cache-Control: post-check=0, pre-check=0', false);
|
||||
header('Pragma: no-cache');
|
||||
|
||||
header('Location: ../');
|
||||
exit;
|
||||
@@ -367,6 +367,7 @@ class HotelReservationSystem extends Module
|
||||
$this->installTab('AdminHotelFeaturePricesSettings', 'Advanced Price Rules', false, false);
|
||||
$this->installTab('AdminRoomTypeGlobalDemand', 'Additional Demand Configuration', false, false);
|
||||
$this->installTab('AdminAssignHotelFeatures', 'Assign Hotel Features', false, false);
|
||||
$this->installTab('AdminBookingDocument', 'Booking Documents', false, false);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user