From 7db96c3b9f3dee2e499a1f064072d5e8007582e1 Mon Sep 17 00:00:00 2001 From: shazar rahman Date: Tue, 7 Jul 2026 10:37:35 +0530 Subject: [PATCH 1/5] Added: Image categorization for Hotel images at back-office Co-authored-by: Name sumit201@webkul.in --- controllers/front/ProductController.php | 4 + .../classes/HotelImage.php | 34 ++- .../classes/HotelImageCategory.php | 89 ++++++ .../classes/HotelReservationSystemDb.php | 19 ++ .../admin/AdminAddHotelController.php | 23 +- .../AdminHotelImageCategoryController.php | 140 +++++++++ modules/hotelreservationsystem/define.php | 1 + .../hotelreservationsystem.php | 3 +- .../views/js/hotelImage.js | 92 ++++-- .../_partials/htl-images-list-row.tpl | 9 +- .../add_hotel/_partials/htl-images-list.tpl | 3 +- .../admin/add_hotel/helpers/form/form.tpl | 110 ++++++- .../_partials/hotel_images.tpl | 7 +- .../hotel-reservation-theme/css/product.css | 274 +++++++++++++++++- themes/hotel-reservation-theme/js/product.js | 201 ++++++++++++- themes/hotel-reservation-theme/product.tpl | 25 ++ 16 files changed, 979 insertions(+), 55 deletions(-) create mode 100644 modules/hotelreservationsystem/classes/HotelImageCategory.php create mode 100644 modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php diff --git a/controllers/front/ProductController.php b/controllers/front/ProductController.php index ef4f509f7..1791c8f3c 100644 --- a/controllers/front/ProductController.php +++ b/controllers/front/ProductController.php @@ -1511,6 +1511,10 @@ class ProductControllerCore extends FrontController $objHotelImage->getImageLink($hotelImage['id'], ImageType::getFormatedName('large')) ); + $hotelImage['small_link'] = $this->context->link->getMediaLink( + $objHotelImage->getImageLink($hotelImage['id'], + ImageType::getFormatedName('medium')) + ); } if (is_array($hotelImages) && count($hotelImages)) { diff --git a/modules/hotelreservationsystem/classes/HotelImage.php b/modules/hotelreservationsystem/classes/HotelImage.php index 1a94b8744..0e153dea7 100644 --- a/modules/hotelreservationsystem/classes/HotelImage.php +++ b/modules/hotelreservationsystem/classes/HotelImage.php @@ -99,7 +99,7 @@ class HotelImage extends ObjectModel * @param [int] $n [number of images per page for paginated images data] * @return [array|boolean] [if data found returns array containing information of the images of the hotel which id is passed] */ - public function getImagesByHotelId($id_hotel, $p = 1, $n = null) + public function getImagesByHotelId($id_hotel, $p = 1, $n = null, $idLang = null) { $p = (int) $p; $n = $n !== null ? (int) $n : $n; // n = null for no pagination @@ -107,9 +107,16 @@ class HotelImage extends ObjectModel $p = 1; } - $sql = 'SELECT * - FROM `'._DB_PREFIX_.'htl_image` - WHERE `id_hotel` = '.(int) $id_hotel. + if (!$idLang) { + $idLang = (int) Context::getContext()->language->id; + } + + $sql = 'SELECT hi.*, hicl.`name` AS `category_name` + FROM `'._DB_PREFIX_.'htl_image` hi + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl + ON (hicl.`id_htl_image_category` = hi.`id_htl_image_category` + AND hicl.`id_lang` = '.(int) $idLang.') + WHERE hi.`id_hotel` = '.(int) $id_hotel. ($n ? ' LIMIT '.(int) (($p - 1) * $n).', '.(int) ($n) : ''); return Db::getInstance()->executeS($sql); @@ -174,11 +181,12 @@ class HotelImage extends ObjectModel ); } - public function uploadHotelImages($images, $idHotel) + public function uploadHotelImages($images, $idHotel, $idHtlImageCategory = 0) { if (isset($images) && $idHotel) { $objHotelHelper = new HotelHelper(); $hotelImages = $images['tmp_name']; + $idHtlImageCategory = (int) $idHtlImageCategory; if (is_array($images['tmp_name'])) { foreach ($hotelImages as $image) { $objHtlImage = new HotelImage(); @@ -189,6 +197,7 @@ class HotelImage extends ObjectModel $objHtlImage->cover = 1; } if ($objHtlImage->save()) { + self::updateImageCategory($objHtlImage->id, $idHtlImageCategory ?: null); if ($path = $objHtlImage->getPathForCreation()) { if (ImageManager::resize( $image, @@ -234,6 +243,7 @@ class HotelImage extends ObjectModel $objHtlImage->cover = 1; } if ($objHtlImage->save()) { + self::updateImageCategory($objHtlImage->id, $idHtlImageCategory ?: null); if ($path = $objHtlImage->getPathForCreation()) { if (ImageManager::resize( $hotelImages, @@ -265,6 +275,8 @@ class HotelImage extends ObjectModel $addedImage = array( 'id' => $objHtlImage->id, 'cover' => $objHtlImage->cover, + 'id_htl_image_category' => $idHtlImageCategory, + 'category_name' => HotelImageCategory::getCategoryName($idHtlImageCategory), 'image_link' => Context::getContext()->link->getMediaLink($objHtlImage->getImageLink($objHtlImage->id)), ); return $addedImage; @@ -312,4 +324,16 @@ class HotelImage extends ObjectModel { return Db::getInstance()->executeS('SELECT * FROM `'._DB_PREFIX_.'htl_image`'); } + + public static function updateImageCategory($idImage, $idHtlImageCategory = null) + { + return Db::getInstance()->update('htl_image', + array( + 'id_htl_image_category' => $idHtlImageCategory ? (int) $idHtlImageCategory : null, + ), + '`id` = '.(int) $idImage, + 0, + true + ); + } } diff --git a/modules/hotelreservationsystem/classes/HotelImageCategory.php b/modules/hotelreservationsystem/classes/HotelImageCategory.php new file mode 100644 index 000000000..4f8f44389 --- /dev/null +++ b/modules/hotelreservationsystem/classes/HotelImageCategory.php @@ -0,0 +1,89 @@ + 'htl_image_category', + 'primary' => 'id_htl_image_category', + 'multilang' => true, + 'fields' => array( + 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isCatalogName', 'required' => true, 'size' => 128), + 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), + 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), + ), + ); + + public static function getImageCategories($idLang = null) + { + if (!$idLang) { + $idLang = (int) Context::getContext()->language->id; + } + + $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT'); + + return Db::getInstance()->executeS( + 'SELECT hic.`id_htl_image_category`, COALESCE(hicl.`name`, hiclDefault.`name`) AS `name` + FROM `'._DB_PREFIX_.'htl_image_category` hic + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl + ON (hicl.`id_htl_image_category` = hic.`id_htl_image_category` + AND hicl.`id_lang` = '.(int) $idLang.') + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hiclDefault + ON (hiclDefault.`id_htl_image_category` = hic.`id_htl_image_category` + AND hiclDefault.`id_lang` = '.(int) $defaultLangId.') + WHERE COALESCE(hicl.`name`, hiclDefault.`name`) IS NOT NULL + ORDER BY `name` ASC' + ); + } + + public static function getCategoryName($idHtlImageCategory, $idLang = null) + { + $idHtlImageCategory = (int) $idHtlImageCategory; + if (!$idHtlImageCategory) { + return ''; + } + + if (!$idLang) { + $idLang = (int) Context::getContext()->language->id; + } + + $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT'); + + return (string) Db::getInstance()->getValue( + 'SELECT COALESCE(hicl.`name`, hiclDefault.`name`) AS `name` + FROM `'._DB_PREFIX_.'htl_image_category` hic + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hicl + ON (hicl.`id_htl_image_category` = hic.`id_htl_image_category` + AND hicl.`id_lang` = '.(int) $idLang.') + LEFT JOIN `'._DB_PREFIX_.'htl_image_category_lang` hiclDefault + ON (hiclDefault.`id_htl_image_category` = hic.`id_htl_image_category` + AND hiclDefault.`id_lang` = '.(int) $defaultLangId.') + WHERE hic.`id_htl_image_category` = '.(int) $idHtlImageCategory + ); + } +} diff --git a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php index ca44a2826..b81a27d78 100644 --- a/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php +++ b/modules/hotelreservationsystem/classes/HotelReservationSystemDb.php @@ -87,10 +87,27 @@ class HotelReservationSystemDb "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_hotel` int(10) unsigned NOT NULL, + `id_htl_image_category` int(10) unsigned DEFAULT NULL, `cover` tinyint(1) NOT NULL DEFAULT '0', + KEY `id_hotel` (`id_hotel`), + KEY `id_htl_image_category` (`id_htl_image_category`), PRIMARY KEY (`id`) ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image_category` ( + `id_htl_image_category` int(10) unsigned NOT NULL AUTO_INCREMENT, + `date_add` datetime NOT NULL, + `date_upd` datetime NOT NULL, + PRIMARY KEY (`id_htl_image_category`) + ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;", + + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_image_category_lang` ( + `id_htl_image_category` int(10) unsigned NOT NULL, + `id_lang` int(10) unsigned NOT NULL, + `name` varchar(128) NOT NULL, + PRIMARY KEY (`id_htl_image_category`, `id_lang`) + ) ENGINE="._MYSQL_ENGINE_." DEFAULT CHARSET=utf8;", + "CREATE TABLE IF NOT EXISTS `"._DB_PREFIX_."htl_branch_features` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `id_hotel` int(10) unsigned NOT NULL, @@ -578,6 +595,8 @@ class HotelReservationSystemDb `'._DB_PREFIX_.'htl_branch_info`, `'._DB_PREFIX_.'htl_branch_info_lang`, `'._DB_PREFIX_.'htl_image`, + `'._DB_PREFIX_.'htl_image_category`, + `'._DB_PREFIX_.'htl_image_category_lang`, `'._DB_PREFIX_.'htl_branch_features`, `'._DB_PREFIX_.'htl_features`, `'._DB_PREFIX_.'htl_features_lang`, diff --git a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php index 868012630..d7cc21171 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminAddHotelController.php @@ -224,6 +224,9 @@ class AdminAddHotelController extends ModuleAdminController } else { $idCountry = Tools::getValue('hotel_country'); } + + $smartyVars['hotelImageCategories'] = HotelImageCategory::getImageCategories((int) $this->context->language->id); + // manage state option $stateOptions = null; if ($idCountry) { @@ -831,10 +834,12 @@ class AdminAddHotelController extends ModuleAdminController $conf = 4; } + $tabParam = Tools::getValue('htl_active_tab') ? '&htl_active_tab='.urlencode(Tools::getValue('htl_active_tab')) : ''; + if (Tools::isSubmit('submitAdd'.$this->table.'AndStay')) { - Tools::redirectAdmin(self::$currentIndex.'&id='.(int) $newIdHotel.'&update'.$this->table.'&conf='.$conf.'&token='.$this->token ); + Tools::redirectAdmin(self::$currentIndex.'&id='.(int) $newIdHotel.'&update'.$this->table.'&conf='.$conf.'&token='.$this->token.$tabParam); } else { - Tools::redirectAdmin(self::$currentIndex.'&conf='.$conf.'&token='.$this->token); + Tools::redirectAdmin(self::$currentIndex.'&conf='.$conf.'&token='.$this->token.$tabParam); } } @@ -886,7 +891,15 @@ class AdminAddHotelController extends ModuleAdminController { $response = array('success' => false); $idHotel = Tools::getValue('id_hotel'); + $idHtlImageCategory = (int) Tools::getValue('id_htl_image_category'); if ($idHotel) { + if ($idHtlImageCategory) { + if (!Validate::isLoadedObject(new HotelImageCategory($idHtlImageCategory))) { + $response['errors'][] = $this->l('Selected image category is invalid.'); + $this->ajaxDie(json_encode($response)); + } + } + $invalidImg = ImageManager::validateUpload( $_FILES['hotel_image'], Tools::getMaxUploadSize() @@ -894,11 +907,15 @@ class AdminAddHotelController extends ModuleAdminController if (!$invalidImg) { // Add Hotel images $objHotelImage = new HotelImage(); - $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'], $idHotel); + $imageDetail = $objHotelImage->uploadHotelImages($_FILES['hotel_image'],$idHotel,$idHtlImageCategory); if ($imageDetail) { $response['success'] = true; $imageDetail['image_link'] = $this->context->link->getMediaLink($objHotelImage->getImageLink($imageDetail['id'],ImageType::getFormatedName('large'))); $imageDetail['image_link_small'] = $this->context->link->getMediaLink($objHotelImage->getImageLink($imageDetail['id'], ImageType::getFormatedName('small'))); + $imageDetail['id_htl_image_category'] = $idHtlImageCategory; + if (!isset($imageDetail['category_name'])) { + $imageDetail['category_name'] = HotelImageCategory::getCategoryName($idHtlImageCategory); + } $response['data']['image_info'] = $imageDetail; // get image row $this->context->smarty->assign(array( diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php new file mode 100644 index 000000000..d35cd573b --- /dev/null +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelImageCategoryController.php @@ -0,0 +1,140 @@ +bootstrap = true; + $this->table = 'htl_image_category'; + $this->className = 'HotelImageCategory'; + $this->identifier = 'id_htl_image_category'; + $this->lang = true; + $this->context = Context::getContext(); + + parent::__construct(); + + $this->_new_list_header_design = true; + $this->addRowAction('edit'); + $this->addRowAction('delete'); + + $this->fields_list = array( + 'id_htl_image_category' => array( + 'title' => $this->l('ID'), + 'align' => 'center', + 'class' => 'fixed-width-xs', + ), + 'name' => array( + 'title' => $this->l('Name'), + 'align' => 'center', + ), + 'date_add' => array( + 'title' => $this->l('Created On'), + 'type' => 'datetime', + 'align' => 'center', + ), + ); + + $this->bulk_actions = array( + 'delete' => array( + 'text' => $this->l('Delete selected'), + 'icon' => 'icon-trash', + 'confirm' => $this->l('Delete selected items?'), + ), + ); + } + + public function initToolbar() + { + parent::initToolbar(); + if (!$this->display || $this->display == 'list') { + $this->page_header_toolbar_btn['new'] = array( + 'href' => self::$currentIndex.'&add'.$this->table.'&token='.$this->token, + 'desc' => $this->l('Add new category'), + ); + } + } + + public function renderForm() + { + if (!$this->loadObject(true)) { + return; + } + + $this->fields_form = array( + 'legend' => array( + 'title' => $this->l('Hotel Image Category'), + 'icon' => 'icon-tags', + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Name'), + 'name' => 'name', + 'required' => true, + 'lang' => true, + 'col' => 4, + 'hint' => $this->l('Enter the name of the hotel image category.'), + ), + ), + 'submit' => array( + 'title' => $this->l('Save'), + ), + 'buttons' => array( + 'save-and-stay' => array( + 'title' => $this->l('Save and stay'), + 'name' => 'submitAdd'.$this->table.'AndStay', + 'type' => 'submit', + 'class' => 'btn btn-default pull-right', + 'icon' => 'process-icon-save', + ), + ), + ); + + return parent::renderForm(); + } + + public function processSave() + { + if (!$this->loadObject(true)) { + return; + } + + $defaultLangId = (int) Configuration::get('PS_LANG_DEFAULT'); + $defaultLanguage = Language::getLanguage($defaultLangId); + $languages = Language::getLanguages(false); + + if (!trim(Tools::getValue('name_'.$defaultLangId))) { + $this->errors[] = $this->l('Category name is required at least in ').$defaultLanguage['name']; + } else { + foreach ($languages as $lang) { + $langName = trim(Tools::getValue('name_'.$lang['id_lang'])); + if ($langName && !Validate::isCatalogName($langName)) { + $this->errors[] = $this->l('Invalid category name in ').$lang['name']; + } + } + } + + return parent::processSave(); + } +} diff --git a/modules/hotelreservationsystem/define.php b/modules/hotelreservationsystem/define.php index e8a7cc909..e7b41db6c 100644 --- a/modules/hotelreservationsystem/define.php +++ b/modules/hotelreservationsystem/define.php @@ -26,6 +26,7 @@ require_once 'classes/HotelRoomType.php'; require_once 'classes/HotelRoomInformation.php'; require_once 'classes/HotelBranchInformation.php'; require_once 'classes/HotelImage.php'; +require_once 'classes/HotelImageCategory.php'; require_once 'classes/HotelFeatures.php'; require_once 'classes/HotelBranchFeatures.php'; require_once 'classes/HotelBookingDetail.php'; diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index 5246337d7..fdd5874c9 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -33,7 +33,7 @@ class HotelReservationSystem extends Module { $this->name = 'hotelreservationsystem'; $this->tab = 'administration'; - $this->version = '1.7.0'; + $this->version = '1.7.1'; $this->author = 'Webkul'; $this->need_instance = 0; $this->bootstrap = true; @@ -523,6 +523,7 @@ class HotelReservationSystem extends Module $this->installTab('AdminHotelFeatures', 'Manage Hotel Features', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminOrderRefundRules', 'Manage Order Refund Rules', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminOrderRefundRequests', 'Manage Order Refund Requests', 'AdminHotelReservationSystemManagement'); + $this->installTab('AdminHotelImageCategory', 'Hotel Image Category', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminHotelConfigurationSetting', 'General Settings', 'AdminHotelReservationSystemManagement'); $this->installTab('AdminHotelBedTypes', 'Bed Types', 'AdminCatalog'); diff --git a/modules/hotelreservationsystem/views/js/hotelImage.js b/modules/hotelreservationsystem/views/js/hotelImage.js index c1fd5f666..ba095fd97 100644 --- a/modules/hotelreservationsystem/views/js/hotelImage.js +++ b/modules/hotelreservationsystem/views/js/hotelImage.js @@ -21,32 +21,62 @@ */ $(document).ready(function () { - $('.htl-img-preview').fancybox({ - width: 'auto', - height: 'auto', - autoSize : false, - maxWidth: 700, - 'hideOnContentClick': false, - }); - - $("#hotel_images").on("change", function(event) { - const files = Array.from(event.target.files); - uploadSelectedImages(files); - }); - - function uploadSelectedImages(files) + function initHotelImagePreview() { - if (files.length == 0) return; // all done - let file = files[0]; - files.splice(0, 1); - createImageUploadRequest(file).then((formData) => { - uploadHotelImages(formData).then(() => { - uploadSelectedImages(files) - }); - }) + $('.htl-img-preview').fancybox({ + width: 'auto', + height: 'auto', + autoSize : false, + maxWidth: 700, + 'hideOnContentClick': false, + }); } - function createImageUploadRequest(file) + initHotelImagePreview(); + + $('body').on('click', '#upload_hotel_images_btn', function(event) { + event.preventDefault(); + var files = Array.from($('#hotel_images')[0].files || []); + var idHtlImageCategory = parseInt($('#id_htl_image_category').val(), 10); + var triggerElement = $(this); + + if (isNaN(idHtlImageCategory) || idHtlImageCategory < 0) { + idHtlImageCategory = 0; + } + + if (!files.length) { + showErrorMessage(imgSelectErrorMsg); + return; + } + + triggerElement.prop('disabled', true).addClass('disabled'); + uploadSelectedImages(files, idHtlImageCategory).then(function() { + $('#hotel_images').val(''); + $('#hotel_images-name').val(''); + showSuccessMessage(imgUploadSuccessMsg); + }, function(errorMsg) { + showErrorMessage(errorMsg || imgUploadErrorMsg); + }).then(function() { + triggerElement.prop('disabled', false).removeClass('disabled'); + }); + }); + + function uploadSelectedImages(files, idHtlImageCategory) + { + if (files.length == 0) { + return Promise.resolve(); + } + + let file = files[0]; + files.splice(0, 1); + return createImageUploadRequest(file, idHtlImageCategory).then((formData) => { + return uploadHotelImages(formData).then(() => { + return uploadSelectedImages(files, idHtlImageCategory); + }); + }); + } + + function createImageUploadRequest(file, idHtlImageCategory) { return new Promise((resolve, reject) => { if (typeof file != 'undefined') { @@ -57,10 +87,13 @@ $(document).ready(function () { var idHotel = $("#id-hotel").val(); formData.append('hotel_image', file); formData.append('id_hotel', idHotel); + formData.append('id_htl_image_category', idHtlImageCategory); formData.append('ajax', true); formData.append('action', 'uploadHotelImages'); resolve(formData); } + } else { + reject(imgUploadErrorMsg); } }); } @@ -79,20 +112,17 @@ $(document).ready(function () { if (response.success) { $('.list-empty-tr').remove(); $("#hotel-image-table tbody").append(response.data.image_row); - showSuccessMessage(imgUploadSuccessMsg); - resolve(imgUploadSuccessMsg); + initHotelImagePreview(); + resolve(response); } else { - if (typeof response.errors != 'undefined') { - showErrorMessage(response.errors); - reject(response.errors); + if (typeof response.errors != 'undefined' && response.errors.length) { + reject(response.errors.join('
')); } else { - showErrorMessage(imgUploadErrorMsg); reject(imgUploadErrorMsg); } } }, error: function(data) { - showErrorMessage(imgUploadErrorMsg); reject(imgUploadErrorMsg); } }); @@ -184,4 +214,4 @@ $(document).ready(function () { showErrorMessage(deleteImgErrorMsg); } }); -}); \ No newline at end of file +}); diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl index 4a28112c7..de398e705 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list-row.tpl @@ -27,6 +27,13 @@ + + {if isset($image.category_name) && $image.category_name} + {$image.category_name|escape:'html':'UTF-8'} + {else} + — + {/if} + {if $image.cover == 1} @@ -39,4 +46,4 @@ - \ No newline at end of file + diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list.tpl index d03600bda..49e7c250a 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/_partials/htl-images-list.tpl @@ -26,6 +26,7 @@ {l s='Image Id' mod='hotelreservationsystem'} {l s='Image' mod='hotelreservationsystem'} + {l s='Category' mod='hotelreservationsystem'} {l s='Cover' mod='hotelreservationsystem'} {l s='Action' mod='hotelreservationsystem'} @@ -47,4 +48,4 @@ {/if} - \ No newline at end of file + diff --git a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl index 978872548..19ea0244b 100644 --- a/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl +++ b/modules/hotelreservationsystem/views/templates/admin/add_hotel/helpers/form/form.tpl @@ -30,6 +30,7 @@
+ {if isset($edit)} {assign var=hook_arg_id_hotel value=$hotel_info.id} {else} @@ -438,11 +439,90 @@ {if isset($hotel_info.id) && $hotel_info.id}
- -
- + {* *} +
+
+
+
+
+ + +
+ + + + + +
+

{l s='You can select multiple images.' mod='hotelreservationsystem'}

+ +
+
+
+ + +
+
+
+

@@ -651,10 +731,11 @@
-{strip} - {addJsDef adminHotelCtrlUrl = $link->getAdminlink('AdminAddHotel')} - {addJsDefL name=imgUploadSuccessMsg}{l s='Image Successfully Uploaded' js=1 mod='hotelreservationsystem'}{/addJsDefL} - {addJsDefL name=imgUploadErrorMsg}{l s='Something went wrong while uploading images. Please try again later !!' js=1 mod='hotelreservationsystem'}{/addJsDefL} + {strip} + {addJsDef adminHotelCtrlUrl = $link->getAdminlink('AdminAddHotel')} + {addJsDefL name=imgUploadSuccessMsg}{l s='Image Successfully Uploaded' js=1 mod='hotelreservationsystem'}{/addJsDefL} + {addJsDefL name=imgSelectErrorMsg}{l s='Please select at least one image before uploading.' js=1 mod='hotelreservationsystem'}{/addJsDefL} + {addJsDefL name=imgUploadErrorMsg}{l s='Something went wrong while uploading images. Please try again later !!' js=1 mod='hotelreservationsystem'}{/addJsDefL} {addJsDefL name=coverImgSuccessMsg}{l s='Cover image changed successfully' js=1 mod='hotelreservationsystem'}{/addJsDefL} {addJsDefL name=coverImgErrorMsg}{l s='Error while changing cover image' js=1 mod='hotelreservationsystem'}{/addJsDefL} @@ -705,6 +786,17 @@ $(document).on('wk.lang.changed', function(e, idLang) { $(window).trigger('resize.autosize'); }); + + // Restore active tab from controller redirect param + var _htlActiveTab = '{if !empty($smarty.get.htl_active_tab)}{$smarty.get.htl_active_tab|escape:'javascript':'UTF-8'}{/if}'; + if (_htlActiveTab && $('a[href="' + _htlActiveTab + '"]').length) { + $('a[href="' + _htlActiveTab + '"]').tab('show'); + } + + // Keep hidden input in sync so active tab survives form submission + $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) { + $('#htl_active_tab').val($(e.target).attr('href')); + }); }); $(".textarea-autosize").autosize(); // After full page load, reinit visible textareas so they start at the correct height diff --git a/themes/hotel-reservation-theme/_partials/hotel_images.tpl b/themes/hotel-reservation-theme/_partials/hotel_images.tpl index 489cd2938..f20e7268a 100644 --- a/themes/hotel-reservation-theme/_partials/hotel_images.tpl +++ b/themes/hotel-reservation-theme/_partials/hotel_images.tpl @@ -24,7 +24,12 @@ {if is_array($hotel_images) && count($hotel_images)} {foreach from=$hotel_images item=hotel_image}
- +
diff --git a/themes/hotel-reservation-theme/css/product.css b/themes/hotel-reservation-theme/css/product.css index cee78c595..7662875e9 100644 --- a/themes/hotel-reservation-theme/css/product.css +++ b/themes/hotel-reservation-theme/css/product.css @@ -44,7 +44,10 @@ a.fancybox-nav { .pb-left-column #image-block img { background: #fbfbfb; border-radius: 4px; - width: 100%; } + width: 100%; + min-height: 420px; + -o-object-fit: cover; + object-fit: cover; } .pb-left-column #image-block #view_full_size .span_link { position: absolute; bottom: 20px; @@ -1770,4 +1773,271 @@ ul.service-product-nav > li:hover { #hotel_rating { display: block; } -} \ No newline at end of file +} + +.htl-full-gallery-modal { + position: fixed; + top: 0; + left: 0; + width: 100%; + height: 100%; + z-index: 10000; +} + +.htl-full-gallery__overlay { + position: absolute; + top: 0; + left: 0; + width: 100%; + height: 100%; + background: rgba(0, 0, 0, 0.92); +} + +.htl-full-gallery__container { + position: relative; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-orient: vertical; + -webkit-box-direction: normal; + -ms-flex-direction: column; + flex-direction: column; + width: 100%; + height: 100%; + padding: 1.5rem; + box-sizing: border-box; +} + +.htl-full-gallery__close { + position: absolute; + top: 0.75rem; + right: 0.75rem; + z-index: 10001; + width: 3.25rem; + height: 3.25rem; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + color: #fff; + font-size: 1.1rem; + border: 2px solid rgba(255,255,255,0.6); + border-radius: 50%; + background: rgba(0,0,0,0.35); + cursor: pointer; + line-height: 1; + transition: background 0.2s, border-color 0.2s; +} + +.htl-full-gallery__close:hover { + background: rgba(0,0,0,0.7); + border-color: #fff; +} + +.htl-full-gallery__header { + text-align: center; + padding-top: 0.25rem; +} + +.htl-full-gallery__hotel-name { + color: #fff; + font-size: 1.6rem; + font-weight: 400; + margin: 0 3rem 0.5rem; + letter-spacing: 0.02em; +} + +.htl-full-gallery__tabs { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + margin-top: 2rem; +} + +.htl-full-gallery__tabs-wrapper { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -ms-flex-wrap: wrap; + flex-wrap: wrap; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + gap: 0.4rem; +} + +.htl-gallery-tab { + font-size: 13px; + padding: 5px 16px; + background: transparent; + border: 1px solid rgba(255,255,255,0.7); + border-radius: 20px; + color: rgba(255,255,255,0.85); + cursor: pointer; + transition: background 0.2s, border-color 0.2s, color 0.2s; + line-height: 1.4; +} + +.htl-gallery-tab:hover { + background: rgba(255,255,255,0.12); + border-color: #fff; + color: #fff; +} + +.htl-gallery-tab.active { + background: #379BF0; + border-color: #379BF0; + color: #fff; +} + +.htl-full-gallery__main { + -webkit-box-flex: 1; + -ms-flex: 1; + flex: 1; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + position: relative; + overflow: hidden; + min-height: 0; +} + +.htl-full-gallery__nav { + position: absolute; + top: 50%; + -webkit-transform: translateY(-50%); + transform: translateY(-50%); + width: 2.75rem; + height: 2.75rem; + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + background: rgba(0,0,0,0.4); + border: 1px solid rgba(255,255,255,0.5); + border-radius: 50%; + color: #fff; + font-size: 1rem; + cursor: pointer; + z-index: 10; + transition: background 0.2s, border-color 0.2s; +} + +.htl-full-gallery__nav:hover { + background: rgba(55,155,240,0.75); + border-color: #379BF0; +} + +.htl-full-gallery__nav--prev { left: 0.75rem; } +.htl-full-gallery__nav--next { right: 0.75rem; } + +.htl-full-gallery__image-container { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-align: center; + -ms-flex-align: center; + align-items: center; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + max-width: calc(100% - 8rem); + max-height: 100%; +} + +.htl-full-gallery__main-image { + max-width: 100%; + max-height: 60vh; + -o-object-fit: contain; + object-fit: contain; + border-radius: 3px; + display: block; + box-shadow: 0 4px 24px rgba(0,0,0,0.5); +} + +.htl-full-gallery__thumbnails { + width: 100%; + padding: 0.5rem 0 0; +} + +.htl-gallery-thumbnails__scroll { + display: -webkit-box; + display: -ms-flexbox; + display: flex; + -webkit-box-pack: center; + -ms-flex-pack: center; + justify-content: center; + gap: 0.35rem; + overflow-x: auto; + padding: 0.4rem 0.5rem; + scroll-behavior: smooth; + -webkit-overflow-scrolling: touch; +} + +.htl-gallery-thumbnails__scroll::-webkit-scrollbar { height: 3px; } +.htl-gallery-thumbnails__scroll::-webkit-scrollbar-track { background: rgba(255,255,255,0.08); } +.htl-gallery-thumbnails__scroll::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.35); border-radius: 2px; } + +.htl-gallery-thumbnail { + -ms-flex-negative: 0; + flex-shrink: 0; + width: 5.5rem; + height: 4rem; + border-radius: 3px; + overflow: hidden; + cursor: pointer; + opacity: 0.5; + -webkit-transition: opacity 0.2s ease, -webkit-transform 0.15s ease; + transition: opacity 0.2s ease, transform 0.15s ease; + border: 2px solid transparent; +} + +.htl-gallery-thumbnail:hover { opacity: 0.8; } + +.htl-gallery-thumbnail.active { + opacity: 1; + border-color: #379BF0; + -webkit-transform: scale(1.08); + transform: scale(1.08); +} + +.htl-gallery-thumbnail img { + width: 100%; + height: 100%; + -o-object-fit: cover; + object-fit: cover; + display: block; +} + +body.gallery-open { overflow: hidden; } + +@media (max-width: 575px) { + .htl-full-gallery__container { padding: 0.6rem; } + .htl-full-gallery__hotel-name { font-size: 1rem; margin: 0 2.5rem 0.4rem; } + .htl-gallery-tab { font-size: 12px; padding: 4px 12px; } + .htl-full-gallery__nav { width: 2rem; height: 2rem; font-size: 0.85rem; } + .htl-full-gallery__nav--prev { left: 0.25rem; } + .htl-full-gallery__nav--next { right: 0.25rem; } + .htl-full-gallery__image-container { max-width: calc(100% - 5rem); } + .htl-full-gallery__main-image { max-height: 45vh; } + .htl-gallery-thumbnail { width: 3rem; height: 2rem; } +} diff --git a/themes/hotel-reservation-theme/js/product.js b/themes/hotel-reservation-theme/js/product.js index b0771177c..12ca94bd4 100644 --- a/themes/hotel-reservation-theme/js/product.js +++ b/themes/hotel-reservation-theme/js/product.js @@ -205,6 +205,7 @@ $(document).ready(function() { } if ($('.room_info_hotel_images_wrap').length) { + hotelImagesGallery.init(); loadHotelImagesByPage(1); } }); @@ -1505,6 +1506,193 @@ var BookingForm = { } } +var hotelImagesGallery = { + modal: null, + images: [], + filteredImages: [], + currentIndex: 0, + currentCategory: 'all', + categories: {}, + loadedSrcs: {}, + + init: function () { + this.modal = $('#htl-img-gallery-modal'); + this.bindEvents(); + }, + + addImages: function (newImages) { + for (var i = 0; i < newImages.length; i++) { + var img = newImages[i]; + if (this.loadedSrcs[img.src]) { continue; } + this.loadedSrcs[img.src] = true; + this.images.push(img); + if (img.categoryId && img.categoryName && !this.categories[img.categoryId]) { + this.categories[img.categoryId] = img.categoryName; + } + } + this.renderCategoryTabs(); + }, + + bindEvents: function () { + var self = this; + + $(document).on('click', '.htl-img-gallery-trigger', function (e) { + e.preventDefault(); + e.stopPropagation(); + var clickedUrl = $(this).data('large-url'); + var startIndex = 0; + for (var i = 0; i < self.images.length; i++) { + if (self.images[i].src === clickedUrl) { + startIndex = i; + break; + } + } + self.open(startIndex); + }); + + this.modal.on('click', '.htl-full-gallery__close, .htl-full-gallery__overlay', function () { + self.close(); + }); + + this.modal.on('click', '.htl-full-gallery__nav--prev', function () { + self.prevImage(); + }); + + this.modal.on('click', '.htl-full-gallery__nav--next', function () { + self.nextImage(); + }); + + $(document).on('keydown', function (e) { + if (!self.modal || !self.modal.is(':visible')) return; + if (e.key === 'Escape') { self.close(); } + else if (e.key === 'ArrowLeft') { self.prevImage(); } + else if (e.key === 'ArrowRight') { self.nextImage(); } + }); + + this.modal.on('click', '.htl-gallery-tab', function () { + var category = $(this).data('category'); + self.filterByCategory(category); + self.modal.find('.htl-gallery-tab').removeClass('active'); + $(this).addClass('active'); + }); + + this.modal.on('click', '.htl-gallery-thumbnail', function () { + var index = parseInt($(this).data('index')); + self.showImage(index); + }); + }, + + open: function (startIndex) { + if (!this.modal || !this.modal.length) return; + this.currentCategory = 'all'; + this.filteredImages = this.images.slice(); + this.modal.find('.htl-gallery-tab').removeClass('active'); + this.modal.find('.htl-gallery-tab[data-category="all"]').addClass('active'); + this.renderThumbnails(); + this.showImage(startIndex || 0); + this.modal.fadeIn(300); + $('body').addClass('gallery-open'); + }, + + close: function () { + if (!this.modal) return; + this.modal.fadeOut(300); + $('body').removeClass('gallery-open'); + }, + + filterByCategory: function (categoryId) { + this.currentCategory = categoryId; + if (categoryId === 'all') { + this.filteredImages = this.images.slice(); + } else { + var targetId = String(categoryId); + this.filteredImages = this.images.filter(function (img) { + return String(img.categoryId) === targetId; + }); + } + this.renderThumbnails(); + if (this.filteredImages.length > 0) { + this.showImage(0); + } + }, + + showImage: function (index) { + if (index < 0 || index >= this.filteredImages.length) return; + this.currentIndex = index; + var image = this.filteredImages[index]; + this.modal.find('#htl-main-image').attr('src', image.src); + this.modal.find('.htl-gallery-thumbnail').removeClass('active'); + this.modal.find('.htl-gallery-thumbnail[data-index="' + index + '"]').addClass('active'); + var thumbContainer = this.modal.find('#htl-gallery-thumbnail'); + var activeThumb = thumbContainer.find('.htl-gallery-thumbnail.active'); + if (activeThumb.length) { + var scrollTarget = activeThumb.position().left + thumbContainer.scrollLeft() - (thumbContainer.width() / 2) + (activeThumb.outerWidth() / 2); + thumbContainer.animate({ scrollLeft: scrollTarget }, 200); + } + }, + + prevImage: function () { + var newIndex = this.currentIndex - 1; + if (newIndex < 0) { newIndex = this.filteredImages.length - 1; } + this.showImage(newIndex); + }, + + nextImage: function () { + var newIndex = this.currentIndex + 1; + if (newIndex >= this.filteredImages.length) { newIndex = 0; } + this.showImage(newIndex); + }, + + renderCategoryTabs: function () { + var self = this; + var tabWrapper = this.modal.find('.htl-full-gallery__tabs-wrapper'); + if (!tabWrapper.length) return; + tabWrapper.empty(); + + var catKeys = Object.keys(this.categories); + var allPhotosLabel = (typeof htl_gallery_all_photos !== 'undefined') ? htl_gallery_all_photos : 'All Photos'; + + var activeCategory = this.currentCategory; + + /* "All Photos" tab is always visible */ + var allTab = $(' + + + + + + {/if} {/block}