diff --git a/admin/themes/default/sass/controllers/_order.sass b/admin/themes/default/sass/controllers/_order.sass index f0e6929db..c5ccaa579 100644 --- a/admin/themes/default/sass/controllers/_order.sass +++ b/admin/themes/default/sass/controllers/_order.sass @@ -7,4 +7,12 @@ .booking_occupancy .booking_occupancy_wrapper max-height: 250px - overflow-x: auto \ No newline at end of file + overflow-x: auto + +#booking-documents-modal + .documents-list + table + tbody + img + max-height: 55px + max-width: 55px diff --git a/admin/themes/default/template/alerts.tpl b/admin/themes/default/template/alerts.tpl new file mode 100644 index 000000000..2d4e3973e --- /dev/null +++ b/admin/themes/default/template/alerts.tpl @@ -0,0 +1,87 @@ +{* +* 2007-2017 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2017 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{if isset($conf)} +
+
+ + {$conf} +
+
+{/if} +{if isset($errors) && count($errors) && current($errors) != '' && (!isset($disableDefaultErrorOutPut) || $disableDefaultErrorOutPut == false)} +
+
+ + {if count($errors) == 1} + {reset($errors)} + {else } + {l s='%d errors' sprintf=$errors|count} +
+
    + {foreach $errors as $error} +
  1. {$error}
  2. + {/foreach} +
+ {/if} +
+
+{/if} +{if isset($informations) && count($informations) && $informations} +
+
+ +
    + {foreach $informations as $info} +
  • {$info}
  • + {/foreach} +
+
+
+{/if} +{if isset($confirmations) && count($confirmations) && $confirmations} +
+
+ {foreach $confirmations as $conf} + {$conf} + {/foreach} +
+
+{/if} +{if isset($warnings) && count($warnings)} +
+
+ + {if count($warnings) > 1} +

{l s='There are %d warnings:' sprintf=count($warnings)}

+ {/if} +
    + {foreach $warnings as $warning} +
  • {$warning}
  • + {/foreach} +
+
+
+{/if} diff --git a/admin/themes/default/template/controllers/orders/_booking_document_line.tpl b/admin/themes/default/template/controllers/orders/_booking_document_line.tpl new file mode 100644 index 000000000..9411ae1b8 --- /dev/null +++ b/admin/themes/default/template/controllers/orders/_booking_document_line.tpl @@ -0,0 +1,53 @@ +{** + * 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} + + + + {if $booking_document.file_type == HotelBookingDocument::FILE_TYPE_IMAGE} + + {elseif $booking_document.file_type == HotelBookingDocument::FILE_TYPE_PDF} + + {/if} + + + {$booking_document.title} + {dateFormat date=$booking_document.date_add full=1} + + + + + + + + + + {/foreach} +{else} + + +
+ + {l s='No documents uploaded yet.'} +
+ + +{/if} diff --git a/admin/themes/default/template/controllers/orders/_booking_documents_modal.tpl b/admin/themes/default/template/controllers/orders/_booking_documents_modal.tpl new file mode 100644 index 000000000..d62524b3f --- /dev/null +++ b/admin/themes/default/template/controllers/orders/_booking_documents_modal.tpl @@ -0,0 +1,101 @@ +{** + * 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 + *} + + + +{addJsDefL name=txt_booking_document_upload_success}{l s='Document uploaded successfully.' js=1}{/addJsDefL} +{addJsDefL name=txt_booking_document_delete_confirm}{l s='Are you sure?' js=1}{/addJsDefL} +{addJsDefL name=txt_booking_document_delete_success}{l s='Document deleted successfully.' js=1}{/addJsDefL} diff --git a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl index b84467ddd..16e0859ed 100644 --- a/admin/themes/default/template/controllers/orders/helpers/view/view.tpl +++ b/admin/themes/default/template/controllers/orders/helpers/view/view.tpl @@ -275,8 +275,8 @@ {l s='Room No.'} {l s='Hotel Name'} - {l s='Date From'} - {l s='Date To'} + {l s='Duration'} + {l s='Documents'} {l s='Order Status'} {if isset($htl_booking_order_data) && $htl_booking_order_data} @@ -291,10 +291,13 @@ - {dateFormat date=$data['date_from']} + {dateFormat date=$data['date_from']} - {dateFormat date=$data['date_to']} - {dateFormat date=$data['date_to']} + + + {l s='Documents'} {$data.num_checkin_documents} +
diff --git a/admin/themes/default/template/layout.tpl b/admin/themes/default/template/layout.tpl index 7c7f49606..f408041a6 100644 --- a/admin/themes/default/template/layout.tpl +++ b/admin/themes/default/template/layout.tpl @@ -23,68 +23,6 @@ * International Registered Trademark & Property of PrestaShop SA *} {$header} -{if isset($conf)} -
-
- - {$conf} -
-
-{/if} -{if count($errors) && current($errors) != '' && (!isset($disableDefaultErrorOutPut) || $disableDefaultErrorOutPut == false)} - -
-
- - {if count($errors) == 1} - {reset($errors)} - {else } - {l s='%d errors' sprintf=$errors|count} -
-
    - {foreach $errors as $error} -
  1. {$error}
  2. - {/foreach} -
- {/if} -
-
-{/if} -{if isset($informations) && count($informations) && $informations} -
-
- -
    - {foreach $informations as $info} -
  • {$info}
  • - {/foreach} -
-
-
-{/if} -{if isset($confirmations) && count($confirmations) && $confirmations} -
-
- {foreach $confirmations as $conf} - {$conf} - {/foreach} -
-
-{/if} -{if count($warnings)} -
-
- - {if count($warnings) > 1} -

{l s='There are %d warnings:' sprintf=count($warnings)}

- {/if} -
    - {foreach $warnings as $warning} -
  • {$warning}
  • - {/foreach} -
-
-
-{/if} +{include file='./alerts.tpl'} {$page} {$footer} diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index e261e9ae3..6fb4d60c6 100644 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -282,7 +282,12 @@ class AdminOrdersControllerCore extends AdminController Tools::redirectAdmin($this->context->link->getAdminLink('AdminOrders')); } - $this->toolbar_title[] = sprintf($this->l('Order %1$s from %2$s %3$s'), $order->reference, $customer->firstname, $customer->lastname); + if ($idHotel = HotelBookingDetail::getIdHotelByIdOrder($order->id)) { + $objHotelBranchInformation = new HotelBranchInformation($idHotel, $this->context->language->id); + $this->toolbar_title[] = sprintf($this->l('Order %1$s - %2$s'), $order->reference, $objHotelBranchInformation->hotel_name); + } else { + $this->toolbar_title[] = sprintf($this->l('Order %1$s'), $order->reference); + } $this->addMetaTitle($this->toolbar_title[count($this->toolbar_title) - 1]); if ($order->hasBeenShipped()) { @@ -327,6 +332,12 @@ class AdminOrdersControllerCore extends AdminController return $res; } + public function initModal() + { + parent::initModal(); + $this->modals[] = $this->getBookingDocumentsModal(); + } + public function setMedia() { parent::setMedia(); @@ -1540,6 +1551,9 @@ class AdminOrdersControllerCore extends AdminController // get booking information by order $bookingOrderInfo = $objBookingDetail->getBookingDataByOrderId($order->id); + foreach ($bookingOrderInfo as &$bookingOrderRoomInfo) { + $bookingOrderRoomInfo['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($bookingOrderRoomInfo['id']); + } // hotel booking statuses $htlOrderStatus = HotelBookingDetail::getAllHotelOrderStatus(); @@ -1637,6 +1651,115 @@ class AdminOrdersControllerCore extends AdminController return parent::renderView(); } + public function getBookingDocumentsModal() + { + $modalContent = $this->context->smarty->fetch('controllers/orders/_booking_documents_modal.tpl'); + + // set modal details + $modal = array( + 'modal_id' => 'booking-documents-modal', + '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'); + $title = Tools::getValue('title'); + + // validations + $objHotelBookingDetail = new HotelBookingDetail($idHtlBooking); + if (!Validate::isLoadedObject($objHotelBookingDetail)) { + $this->errors[] = $this->l('Booking detail not found.'); + } + + if (!$title) { + $title = '--'; + } else { + if (!Validate::isCatalogName($title)) { + $this->errors[] = $this->l('Please enter a valid Title.'); + } + } + + $objHotelBookingDocument = new HotelBookingDocument(); + $objHotelBookingDocument->setFileInfoForUploadedDocument('booking_document'); + if (!count($objHotelBookingDocument->fileInfo)) { + $this->errors[] = $this->l('Please select a file to upload.'); + } elseif ($objHotelBookingDocument->fileInfo['size'] > Tools::getMaxUploadSize()) { + $this->errors[] = $this->l('Uploaded file size is too large.'); + } elseif(!(ImageManager::isRealImage($objHotelBookingDocument->fileInfo['tmp_name']) + || $objHotelBookingDocument->fileInfo['mime'] == 'application/pdf') + ) { + $this->errors[] = $this->l('Please upload an image or a PDF file only. Allowed image formats: .gif, .jpg, .jpeg and .png'); + } + + if (!count($this->errors)) { + $objHotelBookingDocument = new HotelBookingDocument(); + $objHotelBookingDocument->setFileInfoForUploadedDocument('booking_document'); + $objHotelBookingDocument->id_htl_booking = $idHtlBooking; + $objHotelBookingDocument->title = $title; + $objHotelBookingDocument->setFileType(); + if ($objHotelBookingDocument->save()) { + $objHotelBookingDocument->saveDocumentFile(); + + $response['html'] = $this->getRenderedBookingDocuments($idHtlBooking); + $response['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($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('alerts.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['num_checkin_documents'] = HotelBookingDocument::getCountByIdHtlBooking($idHtlBooking); + $response['status'] = true; + } + } + + $this->ajaxDie(json_encode($response)); + } + public function ajaxProcessUpdateGuestDetails() { $response = array( @@ -1680,6 +1803,19 @@ class AdminOrdersControllerCore extends AdminController $this->ajaxDie(json_encode($response)); } + private function getRenderedBookingDocuments($idHtlBooking) + { + $bookingDocuments = HotelBookingDocument::getDocumentsByIdHtlBooking($idHtlBooking); + + $this->context->smarty->assign(array( + 'link' => $this->context->link, + 'booking_documents' => $bookingDocuments, + 'pdf_icon_link' => $this->context->link->getBaseLink().'modules/hotelreservationsystem/views/img/pdf-icon.jpg', + )); + + return $this->context->smarty->fetch('controllers/orders/_booking_document_line.tpl'); + } + public function ajaxProcessSearchProducts() { Context::getContext()->customer = new Customer((int)Tools::getValue('id_customer')); diff --git a/js/admin/orders.js b/js/admin/orders.js index 6ce53d8b9..40e98533d 100644 --- a/js/admin/orders.js +++ b/js/admin/orders.js @@ -1308,3 +1308,197 @@ function checkTotalRefundProductQuantity(it) if (order_discount_price) actualizeTotalRefundVoucher(); } + +$(document).on('click', '#booking-documents-modal .btn-add-new-document', function() { + BookingDocumentsModal.addNew(); + BookingDocumentsForm.addNew(); +}); + +$(document).on('click', '#booking-documents-modal [data-dismiss="alert"]', function() { + BookingDocumentsModal.hideErrors(); +}); + +$(document).on('change', '.input-booking-document', function(e) { + e.preventDefault(); + + if (!this.files.length) { + $(this).remove(); + return; + } + + BookingDocumentsForm.updatePreview(); +}); + +$(document).on('click', '#form-add-new-document .btn-add-file', function(e) { + e.preventDefault(); + + BookingDocumentsForm.openFileChooser(); +}); + +$(document).on('click', '#form-add-new-document .btn-group-add-new .cancel', function(e) { + e.preventDefault(); + + BookingDocumentsForm.close(); + BookingDocumentsModal.enableAddNewButton(); +}); + +$(document).on('click', '#form-add-new-document .btn-group-add-new .upload', function(e) { + e.preventDefault(); + + BookingDocumentsModal.uploadDocument(); +}); + +$(document).on('click', '#booking-documents-modal .documents-list .btn-delete-document', function(e) { + e.preventDefault(); + + if (confirm(txt_booking_document_delete_confirm)) { + BookingDocumentsModal.deleteDocument(this); + } +}); + +const BookingDocumentsModal = { + init: function(idHtlBooking, $this) { + BookingDocumentsModal.currentTr = $this; + $('#booking-documents-modal .documents-list').find('[name="id_hotel_booking"]').val(idHtlBooking); + BookingDocumentsForm.init(); + BookingDocumentsModal.reset(); + BookingDocumentsModal.show(idHtlBooking); + }, + reset: function() { + $('#booking-documents-modal .documents-list table tbody').html(''); + }, + show: function(idHtlBooking) { + $('#booking-documents-modal').modal('show'); + $('#form-add-new-document').find('[name="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) { + $('#booking-documents-modal .documents-list table tbody').html(html); + }, + close: function() { + $('#booking-documents-modal').modal('hide'); + }, + addNew: function() { + BookingDocumentsModal.hideErrors(); + BookingDocumentsModal.hideAddNewButton(); + }, + beforeSubmit: function(cb) { + BookingDocumentsModal.hideErrors(cb); + }, + uploadDocument: function() { + BookingDocumentsModal.beforeSubmit(function() { + let formData = new FormData($('form#form-add-new-document').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(); + BookingDocumentsForm.reset(); + BookingDocumentsForm.resetPreview(); + BookingDocumentsModal.setBodyHtml(jsonResponse.html); + BookingDocumentsModal.setDocumentsCount(jsonResponse.num_checkin_documents); + } else { + BookingDocumentsModal.showErrors(jsonResponse.errors); + } + }, + }); + }); + }, + deleteDocument: function($this) { + BookingDocumentsModal.hideErrors(); + 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); + BookingDocumentsModal.setDocumentsCount(response.num_checkin_documents); + showSuccessMessage(txt_booking_document_delete_success); + } + }, + }); + }, + showErrors: function(errors) { + $('#booking-documents-modal .errors-wrap').stop().html(errors); + $('#booking-documents-modal .errors-wrap').show(200); + }, + hideErrors: function(cb) { + $('#booking-documents-modal .errors-wrap').hide(200, function() { + $('#booking-documents-modal .errors-wrap').html(''); + if (typeof cb === 'function') { + cb(); + } + }); + }, + enableAddNewButton: function() { + $('#booking-documents-modal .btn-add-new-document').show(200); + }, + hideAddNewButton: function() { + $('#booking-documents-modal .btn-add-new-document').hide(); + }, + setDocumentsCount: function(count) { + $(BookingDocumentsModal.currentTr).find('.count-documents').html(count); + }, +} + +const BookingDocumentsForm = { + init: function() { + BookingDocumentsForm.inputHtml = ''; + }, + reset: function() { + $('#form-add-new-document').get(0).reset(); + }, + resetPreview: function() { + $('#form-add-new-document .file-name').val(''); + }, + updatePreview: function() { + BookingDocumentsForm.resetPreview(); + let input = $('#form-add-new-document').find('.input-file-wrap input'); + let file = $(input).get(0).files[0]; + $('#form-add-new-document .file-name').val(file.name); + }, + addNew: function() { + $('#booking-documents-modal #form-add-new-document').show(200); + $('#form-add-new-document').find('.input-file-wrap').html(BookingDocumentsForm.inputHtml); + }, + openFileChooser: function() { + $('#form-add-new-document').find('.input-file-wrap').html(BookingDocumentsForm.inputHtml); + $('#form-add-new-document').find('.input-file-wrap input').click(); + }, + close: function() { + $('#booking-documents-modal #form-add-new-document').hide(200); + }, +} diff --git a/modules/hotelreservationsystem/classes/HotelBookingDetail.php b/modules/hotelreservationsystem/classes/HotelBookingDetail.php index cfb26c1db..cdac35b20 100644 --- a/modules/hotelreservationsystem/classes/HotelBookingDetail.php +++ b/modules/hotelreservationsystem/classes/HotelBookingDetail.php @@ -1400,6 +1400,13 @@ class HotelBookingDetail extends ObjectModel ); } + public static function getIdHotelByIdOrder($idOrder) + { + return Db::getInstance()->getValue( + 'SELECT `id_hotel` FROM `'._DB_PREFIX_.'htl_booking_detail` WHERE `id_order` = '.(int) $idOrder + ); + } + /** * [updateBookingOrderStatusBYOrderId :: To update the order status of a room in the booking]. * @param [int] $order_id [Id of the order] diff --git a/modules/hotelreservationsystem/classes/HotelBookingDocument.php b/modules/hotelreservationsystem/classes/HotelBookingDocument.php new file mode 100644 index 000000000..89aaebfc1 --- /dev/null +++ b/modules/hotelreservationsystem/classes/HotelBookingDocument.php @@ -0,0 +1,218 @@ + 'htl_booking_document', + 'primary' => 'id_htl_booking_document', + 'fields' => array( + 'id_htl_booking' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedId', 'required' => true), + 'title' => array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName'), + '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'), + ), + ); + + 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); + + 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 getCountByIdHtlBooking($idHtlBooking) + { + return (int) Db::getInstance()->getValue( + 'SELECT COUNT(*) + FROM `'._DB_PREFIX_.'htl_booking_document` + WHERE `id_htl_booking` = '.(int) $idHtlBooking + ); + } + + 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(); + } +} diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index 52f6c66f7..c4da5d106 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -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, + `title` varchar(32) NOT NULL DEFAULT '', + `file_type` tinyint(1) NOT NULL DEFAULT '0', + `file_name` varchar(8) NOT NULL DEFAULT '', + `date_add` 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`, diff --git a/modules/hotelreservationsystem/controllers/admin/AdminBookingDocumentController.php b/modules/hotelreservationsystem/controllers/admin/AdminBookingDocumentController.php new file mode 100644 index 000000000..977babeb2 --- /dev/null +++ b/modules/hotelreservationsystem/controllers/admin/AdminBookingDocumentController.php @@ -0,0 +1,61 @@ + &$objHotelBookingDocument)); + + $contentType = $objHotelBookingDocument->getContentType(); + $contentLength = $objHotelBookingDocument->getContentLength(); + $filePath = $objHotelBookingDocument->getPhysicalPath(); + $downloadFileName = $objHotelBookingDocument->getDownloadFileName(); + $contentDisposition = Tools::getValue('is_preview') ? 'inline' : 'attachment'; + + 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: '.$contentDisposition.'; 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; + } +} diff --git a/modules/hotelreservationsystem/define.php b/modules/hotelreservationsystem/define.php index 8914bf202..e753332df 100644 --- a/modules/hotelreservationsystem/define.php +++ b/modules/hotelreservationsystem/define.php @@ -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'; \ No newline at end of file diff --git a/modules/hotelreservationsystem/documents/.htaccess b/modules/hotelreservationsystem/documents/.htaccess new file mode 100644 index 000000000..14249c50b --- /dev/null +++ b/modules/hotelreservationsystem/documents/.htaccess @@ -0,0 +1 @@ +Deny from all \ No newline at end of file diff --git a/modules/hotelreservationsystem/documents/booking_guests/index.php b/modules/hotelreservationsystem/documents/booking_guests/index.php new file mode 100644 index 000000000..4e62784cb --- /dev/null +++ b/modules/hotelreservationsystem/documents/booking_guests/index.php @@ -0,0 +1,29 @@ +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; } diff --git a/modules/hotelreservationsystem/views/img/pdf-icon.jpg b/modules/hotelreservationsystem/views/img/pdf-icon.jpg new file mode 100644 index 000000000..cabea4af9 Binary files /dev/null and b/modules/hotelreservationsystem/views/img/pdf-icon.jpg differ