diff --git a/modules/hotelreservationsystem/controllers/admin/AdminHotelHeaderImageController.php b/modules/hotelreservationsystem/controllers/admin/AdminHotelHeaderImageController.php index 3e0b5a372..3fdfc64db 100644 --- a/modules/hotelreservationsystem/controllers/admin/AdminHotelHeaderImageController.php +++ b/modules/hotelreservationsystem/controllers/admin/AdminHotelHeaderImageController.php @@ -29,18 +29,18 @@ class AdminHotelHeaderImageController extends ModuleAdminController { public function __construct() { - $this->table = 'htl_header_image'; - $this->className = 'HotelHeaderImage'; - $this->bootstrap = true; + $this->table = 'htl_header_image'; + $this->className = 'HotelHeaderImage'; + $this->bootstrap = true; $this->identifier = 'id_header_image'; - $this->lang = true; + $this->lang = true; parent::__construct(); $this->bulk_actions = array( 'delete' => array( - 'text' => $this->l('Delete selected'), + 'text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected images? This cannot be undone.'), - 'icon' => 'icon-trash', + 'icon' => 'icon-trash', ), ); } @@ -63,24 +63,21 @@ class AdminHotelHeaderImageController extends ModuleAdminController public function renderView() { $this->meta_title = $this->l('Header Image Configuration'); - $mediaType = (int)Tools::getValue( - 'QLO_HEADER_MEDIA_TYPE', - (int)(Configuration::get('QLO_HEADER_MEDIA_TYPE') ?: HotelHeaderImage::MEDIA_TYPE_IMAGE) - ); - $languages = Language::getLanguages(false); + $mediaType = (int)Tools::getValue('QLO_HEADER_MEDIA_TYPE', (int)(Configuration::get('QLO_HEADER_MEDIA_TYPE') ?: HotelHeaderImage::MEDIA_TYPE_IMAGE)); + $languages = Language::getLanguages(false); $defaultLangId = (int)Configuration::get('PS_LANG_DEFAULT'); $imageItems = HotelHeaderImage::getItems(null, $defaultLangId, true); $shopId = (int)$this->context->shop->id; foreach ($imageItems as &$item) { $item['tag_lines_json'] = json_encode((object)$item['tag_lines']); - $srcPath = _PS_IMG_DIR_.'hotel_header_media/'.$item['name']; + $srcPath = _PS_IMG_DIR_.'hotel_header_media/'.$item['name']; $cacheName = 'htl_header_image_mini_'.(int)$item['id_header_image'].'_'.$shopId.'.jpg'; $item['thumb'] = ImageManager::thumbnail($srcPath, $cacheName, 45, 'jpg', false); } unset($item); - $videoItem = HotelHeaderImage::getVideoConfig(); + $videoItem = HotelHeaderImage::getVideoConfig(); $videoMimeType = 'video/mp4'; if ($videoItem) { if ($videoItem['source_type'] === 'upload') { @@ -93,47 +90,57 @@ class AdminHotelHeaderImageController extends ModuleAdminController $videoMimeType = isset($mimeMap[$ext]) ? $mimeMap[$ext] : 'video/mp4'; } + $sourceType = Tools::getValue('source_type', $videoItem ? $videoItem['source_type'] : 'upload'); + $videoUrlValue = Tools::getValue( + 'video_url', + ($videoItem && $videoItem['source_type'] === 'url') ? $videoItem['name'] : '' + ); + $showVideoUrlPreview = ($sourceType === 'url' && $videoUrlValue && Validate::isAbsoluteUrl($videoUrlValue)); + Media::addJsDef(array( - 'qloHmCurrentIndex' => self::$currentIndex, - 'qloHmToken' => $this->token, - 'qloHmMediaType' => $mediaType, + 'qloHmCurrentIndex' => self::$currentIndex, + 'qloHmToken' => $this->token, + 'qloHmMediaType' => $mediaType, 'qloHmMediaTypeImage' => HotelHeaderImage::MEDIA_TYPE_IMAGE, 'qloHmMediaTypeVideo' => HotelHeaderImage::MEDIA_TYPE_VIDEO, - 'qloHmMaxUpload' => Tools::getMaxUploadSize((int)Configuration::get('PS_LIMIT_UPLOAD_IMAGE_VALUE') * 1024 * 1024), + 'qloHmMaxUpload' => Tools::getMaxUploadSize((int)Configuration::get('PS_LIMIT_UPLOAD_IMAGE_VALUE') * 1024 * 1024), 'qloHmMaxVideoUpload' => Tools::getMaxUploadSize(), - 'qloHmDefaultLangId' => $defaultLangId, - 'qloHmI18n' => array( - 'noFileSelected' => $this->l('Please select at least one image file.'), - 'deleteFailed' => $this->l('Delete failed.'), - 'requestFailed' => $this->l('Request failed.'), - 'imageUploadedSuccess'=> $this->l('Image uploaded successfully.'), + 'qloHmDefaultLangId' => $defaultLangId, + 'qloHmI18n' => array( + 'noFileSelected' => $this->l('Please select at least one image file.'), + 'deleteFailed' => $this->l('Delete failed.'), + 'requestFailed' => $this->l('Request failed.'), + 'imageUploadedSuccess' => $this->l('Image uploaded successfully.'), 'imageUpdatedSuccess' => $this->l('Image updated successfully.'), - 'uploadFailed' => $this->l('Upload failed.'), - 'updateFailed' => $this->l('Update failed.'), - 'editLabel' => $this->l('Edit'), - 'deleteImageLabel' => $this->l('Delete this image'), - 'fileTooLarge' => $this->l('File exceeds the maximum allowed upload size.'), + 'uploadFailed' => $this->l('Upload failed.'), + 'updateFailed' => $this->l('Update failed.'), + 'editLabel' => $this->l('Edit'), + 'deleteImageLabel' => $this->l('Delete this image'), + 'fileTooLarge' => $this->l('File exceeds the maximum allowed upload size.'), ), )); $this->tpl_view_vars = array( - 'mediaType' => $mediaType, - 'imageItems' => $imageItems, - 'videoItem' => $videoItem, + 'mediaType' => $mediaType, + 'imageItems' => $imageItems, + 'videoItem' => $videoItem, 'videoMimeType' => $videoMimeType, - 'config' => array( - 'QLO_HEADER_MEDIA_TYPE' => $mediaType, - 'QLO_HEADER_SLIDER_NAV_TYPE' => (int)Tools::getValue('QLO_HEADER_SLIDER_NAV_TYPE', (int)(Configuration::get('QLO_HEADER_SLIDER_NAV_TYPE') ?: HotelHeaderImage::NAV_TYPE_DOTS)), + 'sourceType' => $sourceType, + 'videoUrlValue' => $videoUrlValue, + 'showVideoUrlPreview' => $showVideoUrlPreview, + 'config' => array( + 'QLO_HEADER_MEDIA_TYPE' => $mediaType, + 'QLO_HEADER_SLIDER_NAV_TYPE' => (int)Tools::getValue('QLO_HEADER_SLIDER_NAV_TYPE', (int)(Configuration::get('QLO_HEADER_SLIDER_NAV_TYPE') ?: HotelHeaderImage::NAV_TYPE_DOTS)), 'QLO_HEADER_SLIDER_AUTO_PLAY' => (int)Tools::getValue('QLO_HEADER_SLIDER_AUTO_PLAY', (int)Configuration::get('QLO_HEADER_SLIDER_AUTO_PLAY')), - 'QLO_HEADER_SLIDER_INTERVAL' => (int)Tools::getValue('QLO_HEADER_SLIDER_INTERVAL', (int)Configuration::get('QLO_HEADER_SLIDER_INTERVAL') ?: 5000), + 'QLO_HEADER_SLIDER_INTERVAL' => Tools::getValue('QLO_HEADER_SLIDER_INTERVAL', (int)Configuration::get('QLO_HEADER_SLIDER_INTERVAL') ?: 5000), 'QLO_HEADER_SLIDER_ANIM_TYPE' => (int)Tools::getValue('QLO_HEADER_SLIDER_ANIM_TYPE', (int)(Configuration::get('QLO_HEADER_SLIDER_ANIM_TYPE') ?: HotelHeaderImage::ANIM_TYPE_SLIDE)), - 'QLO_HOTEL_NAME_ENABLE' => (int)Tools::getValue('QLO_HOTEL_NAME_ENABLE', (int)Configuration::get('QLO_HOTEL_NAME_ENABLE')), - 'QLO_HEADER_CONTENT_ALIGN' => (int)Tools::getValue('QLO_HEADER_CONTENT_ALIGN', (int)(Configuration::get('QLO_HEADER_CONTENT_ALIGN') ?: HotelHeaderImage::CONTENT_ALIGN_CENTER)), + 'QLO_HOTEL_NAME_ENABLE' => (int)Tools::getValue('QLO_HOTEL_NAME_ENABLE', (int)Configuration::get('QLO_HOTEL_NAME_ENABLE')), + 'QLO_HEADER_CONTENT_ALIGN' => (int)Tools::getValue('QLO_HEADER_CONTENT_ALIGN', (int)(Configuration::get('QLO_HEADER_CONTENT_ALIGN') ?: HotelHeaderImage::CONTENT_ALIGN_CENTER)), ), - 'languages' => $languages, + 'languages' => $languages, 'defaultLangId' => $defaultLangId, - 'imgBaseUrl' => $this->context->link->getMediaLink(_PS_IMG_.'hotel_header_media/'), - 'maxUpload' => Tools::formatBytes(Tools::getMaxUploadSize()), + 'imgBaseUrl' => $this->context->link->getMediaLink(_PS_IMG_.'hotel_header_media/'), + 'maxUpload' => Tools::formatBytes(Tools::getMaxUploadSize()), 'maxImageUpload' => Tools::formatBytes(Tools::getMaxUploadSize((int)Configuration::get('PS_LIMIT_UPLOAD_IMAGE_VALUE') * 1024 * 1024)), ); @@ -150,9 +157,9 @@ class AdminHotelHeaderImageController extends ModuleAdminController protected function processBulkDelete() { - $ids = Tools::getValue($this->table.'Box', array()); + $ids = Tools::getValue($this->table.'Box', array()); $activeImages = HotelHeaderImage::getItems(1); - $activeIds = array_column($activeImages, 'id_header_image'); + $activeIds = array_column($activeImages, 'id_header_image'); $activeToDelete = array_intersect(array_map('intval', (array)$ids), array_map('intval', $activeIds)); if (count($activeIds) - count($activeToDelete) < 1) { @@ -163,25 +170,9 @@ class AdminHotelHeaderImageController extends ModuleAdminController parent::processBulkDelete(); } - protected function processBulkDisableSelection() - { - $ids = Tools::getValue($this->table.'Box', array()); - $activeImages = HotelHeaderImage::getItems(1); - $activeIds = array_column($activeImages, 'id_header_image'); - $activeToDisable = array_intersect(array_map('intval', (array)$ids), array_map('intval', $activeIds)); - - if (count($activeIds) - count($activeToDisable) < 1) { - $this->errors[] = $this->l('At least one image must remain active.'); - return; - } - - parent::processBulkDisableSelection(); - } - protected function processSaveSettings() { $mediaType = (int)Tools::getValue('QLO_HEADER_MEDIA_TYPE', HotelHeaderImage::MEDIA_TYPE_IMAGE); - $autoPlay = (int)(bool)Tools::getValue('QLO_HEADER_SLIDER_AUTO_PLAY', 1); $previousMediaType = (int)Configuration::get('QLO_HEADER_MEDIA_TYPE'); if (!in_array($mediaType, array(HotelHeaderImage::MEDIA_TYPE_IMAGE, HotelHeaderImage::MEDIA_TYPE_VIDEO))) { @@ -189,11 +180,13 @@ class AdminHotelHeaderImageController extends ModuleAdminController return; } - $existingVideo = HotelHeaderImage::getVideoConfig(); + $sourceType = Tools::getValue('source_type', 'upload'); + $existingVideo = HotelHeaderImage::getVideoConfig(); + $hasMatchingExistingVideo = ($existingVideo && $existingVideo['source_type'] === $sourceType); $hasNewVideoFile = isset($_FILES['header_video_file']) && !empty($_FILES['header_video_file']['size']); - $hasNewVideoUrl = (Tools::getValue('source_type', '') === 'url' && trim(Tools::getValue('video_url', '')) !== ''); + $hasNewVideoUrl = ($sourceType === 'url' && trim(Tools::getValue('video_url', '')) !== ''); - if ($mediaType === HotelHeaderImage::MEDIA_TYPE_VIDEO && !$existingVideo && !$hasNewVideoFile && !$hasNewVideoUrl) { + if ($mediaType === HotelHeaderImage::MEDIA_TYPE_VIDEO && !$hasMatchingExistingVideo && !$hasNewVideoFile && !$hasNewVideoUrl) { $this->errors[] = $this->l('Please upload or link a video before switching the header to Video mode.'); return; } @@ -201,21 +194,35 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->errors[] = $this->l('Please add at least one active image before switching the header to Image mode.'); return; } - if ($autoPlay) { - $interval = Tools::getValue('QLO_HEADER_SLIDER_INTERVAL', 5000); - if ((string)$interval !== '' && (!Validate::isUnsignedInt($interval) || (int)$interval < 500)) { - $this->errors[] = $this->l('Auto Slide Interval must be at least 500 milliseconds.'); - return; - } - } + $autoPlay = 0; + $interval = 0; + $navType = HotelHeaderImage::NAV_TYPE_DOTS; + $animType = HotelHeaderImage::ANIM_TYPE_SLIDE; + $contentAlign = HotelHeaderImage::CONTENT_ALIGN_CENTER; - $navType = (int)Tools::getValue('QLO_HEADER_SLIDER_NAV_TYPE', HotelHeaderImage::NAV_TYPE_DOTS); - if (!in_array($navType, array(HotelHeaderImage::NAV_TYPE_DOTS, HotelHeaderImage::NAV_TYPE_ARROWS, HotelHeaderImage::NAV_TYPE_BOTH))) { - $navType = HotelHeaderImage::NAV_TYPE_DOTS; - } - $animType = (int)Tools::getValue('QLO_HEADER_SLIDER_ANIM_TYPE', HotelHeaderImage::ANIM_TYPE_SLIDE); - if (!in_array($animType, array(HotelHeaderImage::ANIM_TYPE_SLIDE, HotelHeaderImage::ANIM_TYPE_FADE, HotelHeaderImage::ANIM_TYPE_ZOOM, HotelHeaderImage::ANIM_TYPE_BLUR))) { - $animType = HotelHeaderImage::ANIM_TYPE_SLIDE; + if ($mediaType === HotelHeaderImage::MEDIA_TYPE_IMAGE) { + $autoPlay = (int)(bool)Tools::getValue('QLO_HEADER_SLIDER_AUTO_PLAY', 1); + if ($autoPlay) { + $interval = Tools::getValue('QLO_HEADER_SLIDER_INTERVAL', 5000); + if (!Validate::isUnsignedInt($interval) || (int)$interval < 500) { + $this->errors[] = $this->l('Auto Slide Interval must be at least 500 milliseconds.'); + return; + } + $interval = (int)$interval; + } + + $navType = (int)Tools::getValue('QLO_HEADER_SLIDER_NAV_TYPE', HotelHeaderImage::NAV_TYPE_DOTS); + if (!in_array($navType, array(HotelHeaderImage::NAV_TYPE_DOTS, HotelHeaderImage::NAV_TYPE_ARROWS, HotelHeaderImage::NAV_TYPE_BOTH))) { + $navType = HotelHeaderImage::NAV_TYPE_DOTS; + } + $animType = (int)Tools::getValue('QLO_HEADER_SLIDER_ANIM_TYPE', HotelHeaderImage::ANIM_TYPE_SLIDE); + if (!in_array($animType, array(HotelHeaderImage::ANIM_TYPE_SLIDE, HotelHeaderImage::ANIM_TYPE_FADE, HotelHeaderImage::ANIM_TYPE_ZOOM, HotelHeaderImage::ANIM_TYPE_BLUR))) { + $animType = HotelHeaderImage::ANIM_TYPE_SLIDE; + } + $contentAlign = (int)Tools::getValue('QLO_HEADER_CONTENT_ALIGN', HotelHeaderImage::CONTENT_ALIGN_CENTER); + if (!in_array($contentAlign, array(HotelHeaderImage::CONTENT_ALIGN_LEFT, HotelHeaderImage::CONTENT_ALIGN_CENTER, HotelHeaderImage::CONTENT_ALIGN_RIGHT))) { + $contentAlign = HotelHeaderImage::CONTENT_ALIGN_CENTER; + } } if ($mediaType === HotelHeaderImage::MEDIA_TYPE_VIDEO) { @@ -241,20 +248,18 @@ class AdminHotelHeaderImageController extends ModuleAdminController } } - $contentAlign = (int)Tools::getValue('QLO_HEADER_CONTENT_ALIGN', HotelHeaderImage::CONTENT_ALIGN_CENTER); - if (!in_array($contentAlign, array(HotelHeaderImage::CONTENT_ALIGN_LEFT, HotelHeaderImage::CONTENT_ALIGN_CENTER, HotelHeaderImage::CONTENT_ALIGN_RIGHT))) { - $contentAlign = HotelHeaderImage::CONTENT_ALIGN_CENTER; - } - if (!count($this->errors)) { - Configuration::updateValue('QLO_HEADER_MEDIA_TYPE', $mediaType); - Configuration::updateValue('QLO_HOTEL_NAME_ENABLE', (int)(bool)Tools::getValue('QLO_HOTEL_NAME_ENABLE', 0)); - Configuration::updateValue('QLO_HEADER_CONTENT_ALIGN', $contentAlign); - Configuration::updateValue('QLO_HEADER_SLIDER_NAV_TYPE', $navType); - Configuration::updateValue('QLO_HEADER_SLIDER_AUTO_PLAY', $autoPlay); - if ($autoPlay) { - Configuration::updateValue('QLO_HEADER_SLIDER_INTERVAL', (int)Tools::getValue('QLO_HEADER_SLIDER_INTERVAL', 5000)); - Configuration::updateValue('QLO_HEADER_SLIDER_ANIM_TYPE', $animType); + Configuration::updateValue('QLO_HEADER_MEDIA_TYPE', $mediaType); + + if ($mediaType === HotelHeaderImage::MEDIA_TYPE_IMAGE) { + Configuration::updateValue('QLO_HOTEL_NAME_ENABLE', (int)(bool)Tools::getValue('QLO_HOTEL_NAME_ENABLE', 0)); + Configuration::updateValue('QLO_HEADER_CONTENT_ALIGN', $contentAlign); + Configuration::updateValue('QLO_HEADER_SLIDER_NAV_TYPE', $navType); + Configuration::updateValue('QLO_HEADER_SLIDER_AUTO_PLAY', $autoPlay); + if ($autoPlay) { + Configuration::updateValue('QLO_HEADER_SLIDER_INTERVAL', $interval); + Configuration::updateValue('QLO_HEADER_SLIDER_ANIM_TYPE', $animType); + } } Tools::redirectAdmin(self::$currentIndex.'&conf=4&token='.$this->token); } @@ -263,10 +268,10 @@ class AdminHotelHeaderImageController extends ModuleAdminController protected function processSaveVideo() { $sourceType = Tools::getValue('source_type', 'upload'); - $videoUrl = trim(Tools::getValue('video_url', '')); - $file = isset($_FILES['header_video_file']) ? $_FILES['header_video_file'] : null; + $videoUrl = trim(Tools::getValue('video_url', '')); + $file = isset($_FILES['header_video_file']) ? $_FILES['header_video_file'] : null; $hasNewFile = ($file && isset($file['error']) && $file['error'] === UPLOAD_ERR_OK && $file['size'] > 0); - $hasNewUrl = ($sourceType === 'url' && $videoUrl !== ''); + $hasNewUrl = ($sourceType === 'url' && $videoUrl !== ''); if ($sourceType === 'url' && $videoUrl === '') { $this->errors[] = $this->l('Please enter a video URL.'); @@ -277,14 +282,13 @@ class AdminHotelHeaderImageController extends ModuleAdminController return; } if ($hasNewFile) { - $allowedExts = array('mp4', 'webm', 'ogg'); + $allowedExts = array('mp4', 'webm', 'ogg'); $allowedMimes = array('video/mp4', 'video/webm', 'video/ogg', 'video/x-matroska'); $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); if (!in_array($ext, $allowedExts)) { $this->errors[] = $this->l('Only .mp4, .webm, and .ogg video formats are allowed.'); return; } - // Use actual disk size — $_FILES['size'] is user-supplied and can be spoofed. if (filesize($file['tmp_name']) > Tools::getMaxUploadSize()) { $this->errors[] = $this->l('Video file exceeds the maximum allowed upload size.'); return; @@ -293,7 +297,7 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->errors[] = $this->l('Server cannot verify file type. Please enable the fileinfo PHP extension.'); return; } - $finfo = finfo_open(FILEINFO_MIME_TYPE); + $finfo = finfo_open(FILEINFO_MIME_TYPE); $detectedMime = finfo_file($finfo, $file['tmp_name']); finfo_close($finfo); if (!in_array($detectedMime, $allowedMimes)) { @@ -343,17 +347,15 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->ajaxDie(json_encode($response)); } - $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); - $isGif = ($ext === 'gif'); + $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)); + $isGif = ($ext === 'gif'); $outExt = $isGif ? 'gif' : 'jpg'; do { $uniqueName = bin2hex(random_bytes(16)).'.'.$outExt; } while (file_exists(_PS_IMG_DIR_.'hotel_header_media/'.$uniqueName)); $destPath = _PS_IMG_DIR_.'hotel_header_media/'.$uniqueName; - $saved = $isGif - ? (bool)move_uploaded_file($file['tmp_name'], $destPath) - : (bool)ImageManager::resize($file['tmp_name'], $destPath); + $saved = $isGif ? (bool)move_uploaded_file($file['tmp_name'], $destPath) : (bool)ImageManager::resize($file['tmp_name'], $destPath); if (!$saved) { $response['errors'][] = $this->l('Failed to save image file.'); @@ -374,12 +376,12 @@ class AdminHotelHeaderImageController extends ModuleAdminController } } - $tagLineColor = Tools::getValue('tag_line_color', '#ffffff'); + $tagLineColor = Tools::getValue('tag_line_color', '#ffffff'); if (!preg_match('/^#[0-9a-fA-F]{6}$/', $tagLineColor)) { $response['errors'][] = $this->l('Invalid tag line color. Use a 6-digit hex value (e.g. #ffffff).'); $this->ajaxDie(json_encode($response)); } - $tagLineFontSize = (int)Tools::getValue('tag_line_font_size', 16); + $tagLineFontSize = (int)Tools::getValue('tag_line_font_size', 16); if ($tagLineFontSize < 8 || $tagLineFontSize > 72) { $response['errors'][] = $this->l('Tag line font size must be between 8 and 72 pixels.'); $this->ajaxDie(json_encode($response)); @@ -390,13 +392,13 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->ajaxDie(json_encode($response)); } - $objImage = new HotelHeaderImage(); - $objImage->name = $uniqueName; - $objImage->position = $objImage->getHigherPosition(); - $objImage->active = (int)(bool)Tools::getValue('active', 1); - $objImage->tag_line = $tagLineByLang; - $objImage->tag_line_color = $tagLineColor; - $objImage->tag_line_font_size = $tagLineFontSize; + $objImage = new HotelHeaderImage(); + $objImage->name = $uniqueName; + $objImage->position = $objImage->getHigherPosition(); + $objImage->active = (int)(bool)Tools::getValue('active', 1); + $objImage->tag_line = $tagLineByLang; + $objImage->tag_line_color = $tagLineColor; + $objImage->tag_line_font_size = $tagLineFontSize; $objImage->tag_line_font_weight = $tagLineFontWeight; if (!$objImage->save()) { @@ -407,16 +409,28 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->ajaxDie(json_encode($response)); } - $defaultLangId = (int)Configuration::get('PS_LANG_DEFAULT'); - $response['success'] = true; - $response['id'] = (int)$objImage->id; - $response['active'] = (int)$objImage->active; - $response['imgUrl'] = $this->context->link->getMediaLink(_PS_IMG_.'hotel_header_media/'.$uniqueName); - $response['tag_line'] = isset($tagLineByLang[$defaultLangId]) ? $tagLineByLang[$defaultLangId] : ''; - $response['tag_lines_json'] = json_encode((object)$tagLineByLang); - $response['tag_line_color'] = $tagLineColor; - $response['tag_line_font_size'] = $tagLineFontSize; - $response['tag_line_font_weight'] = $tagLineFontWeight; + $defaultLangId = (int)Configuration::get('PS_LANG_DEFAULT'); + $this->context->smarty->assign(array( + 'img' => array( + 'id_header_image' => (int)$objImage->id, + 'name' => $uniqueName, + 'tag_line' => isset($tagLineByLang[$defaultLangId]) ? $tagLineByLang[$defaultLangId] : '', + 'tag_lines_json' => json_encode((object)$tagLineByLang), + 'tag_line_color' => $tagLineColor, + 'tag_line_font_size' => $tagLineFontSize, + 'tag_line_font_weight' => $tagLineFontWeight, + 'active' => (int)$objImage->active, + ), + 'position' => count(HotelHeaderImage::getItems(null)), + 'current' => self::$currentIndex, + 'token' => $this->token, + 'imgBaseUrl' => $this->context->link->getMediaLink(_PS_IMG_.'hotel_header_media/'), + )); + + $response['success'] = true; + $response['data']['image_row'] = $this->context->smarty->fetch( + _PS_MODULE_DIR_.$this->module->name.'/views/templates/admin/hotel_header_image/_partials/htl-header-image-row.tpl' + ); $this->ajaxDie(json_encode($response)); } @@ -470,23 +484,23 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->ajaxDie(json_encode($response)); } - $objImage->tag_line = $tagLineByLang; - $objImage->tag_line_color = $tagLineColor; - $objImage->tag_line_font_size = $tagLineFontSize; + $objImage->tag_line = $tagLineByLang; + $objImage->tag_line_color = $tagLineColor; + $objImage->tag_line_font_size = $tagLineFontSize; $objImage->tag_line_font_weight = $tagLineFontWeight; if (!$objImage->save()) { $response['errors'][] = $this->l('Failed to update image.'); $this->ajaxDie(json_encode($response)); } - $defaultLangId = (int)Configuration::get('PS_LANG_DEFAULT'); - $response['success'] = true; - $response['active'] = (int)$objImage->active; - $response['confirmations'] = $this->l('Image updated successfully.'); - $response['tag_line'] = isset($tagLineByLang[$defaultLangId]) ? $tagLineByLang[$defaultLangId] : ''; - $response['tag_lines_json'] = json_encode((object)$tagLineByLang); - $response['tag_line_color'] = $tagLineColor; - $response['tag_line_font_size'] = $tagLineFontSize; + $defaultLangId = (int)Configuration::get('PS_LANG_DEFAULT'); + $response['success'] = true; + $response['active'] = (int)$objImage->active; + $response['confirmations'] = $this->l('Image updated successfully.'); + $response['tag_line'] = isset($tagLineByLang[$defaultLangId]) ? $tagLineByLang[$defaultLangId] : ''; + $response['tag_lines_json'] = json_encode((object)$tagLineByLang); + $response['tag_line_color'] = $tagLineColor; + $response['tag_line_font_size'] = $tagLineFontSize; $response['tag_line_font_weight'] = $tagLineFontWeight; $this->ajaxDie(json_encode($response)); } @@ -520,7 +534,7 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->ajaxDie(json_encode($response)); } - $response['success'] = true; + $response['success'] = true; $response['confirmations'] = $this->l('Image deleted successfully.'); $this->ajaxDie(json_encode($response)); } @@ -535,7 +549,7 @@ class AdminHotelHeaderImageController extends ModuleAdminController } HotelHeaderImage::deleteVideoConfig(); - $response['success'] = true; + $response['success'] = true; $response['confirmations'] = $this->l('Video deleted successfully.'); $this->ajaxDie(json_encode($response)); } @@ -543,7 +557,7 @@ class AdminHotelHeaderImageController extends ModuleAdminController public function ajaxProcessToggleImageActive() { $response = array('errors' => array(), 'success' => false); - $id = (int)Tools::getValue('id_header_image'); + $id = (int)Tools::getValue('id_header_image'); $active = (int)(bool)Tools::getValue('active'); if (!$id) { @@ -571,7 +585,7 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->ajaxDie(json_encode($response)); } - $response['success'] = true; + $response['success'] = true; $response['confirmations'] = $this->l('The status has been successfully updated.'); $this->ajaxDie(json_encode($response)); } @@ -583,70 +597,123 @@ class AdminHotelHeaderImageController extends ModuleAdminController $this->ajaxDie(json_encode(array('success' => false))); } - $sanitizedIds = array_values(array_filter(array_map('intval', $ids), function ($id) { - return $id > 0; - })); - if (count($sanitizedIds) !== count($ids)) { - $this->ajaxDie(json_encode(array('success' => false, 'errors' => array($this->l('Invalid image IDs.'))))); - } - - if ($sanitizedIds) { - $validRows = Db::getInstance()->executeS( - 'SELECT `id_header_image` FROM `'._DB_PREFIX_.'htl_header_image` - WHERE `id_header_image` IN ('.implode(',', $sanitizedIds).')' - ); - if (!$validRows || count($validRows) !== count($sanitizedIds)) { + foreach ($ids as $position => $id) { + $objImage = new HotelHeaderImage((int)$id); + if (!Validate::isLoadedObject($objImage)) { $this->ajaxDie(json_encode(array('success' => false, 'errors' => array($this->l('One or more image IDs are invalid.'))))); } - } - - foreach ($sanitizedIds as $position => $id) { - Db::getInstance()->execute( - 'UPDATE `'._DB_PREFIX_.'htl_header_image` - SET `position` = '.(int)$position.' - WHERE `id_header_image` = '.(int)$id - ); + $objImage->position = (int)$position; + $objImage->update(); } $this->ajaxDie(json_encode(array( - 'success' => true, + 'success' => true, 'confirmations' => $this->l('The selected images have successfully been moved.'), ))); } - public function ajaxProcessBulkUpdateTagLines() + public function ajaxProcessBulkUpdateImages() { - $response = array('errors' => array(), 'success' => false); - $languages = Language::getLanguages(false); - $tagLineByLang = array(); - foreach ($languages as $lang) { - $tagLineByLang[$lang['id_lang']] = trim(Tools::getValue('tag_line_'.$lang['id_lang'], '')); + $response = array('errors' => array(), 'success' => false); + + $ids = array_values(array_unique(array_filter(array_map('intval', (array)Tools::getValue('id_header_image', array()))))); + if (!$ids) { + $response['errors'][] = $this->l('No images selected.'); + $this->ajaxDie(json_encode($response)); } - foreach ($tagLineByLang as $tagLineValue) { - if (!Validate::isGenericName($tagLineValue)) { - $response['errors'][] = $this->l('Invalid tag line. Characters < > = { } are not allowed.'); + + $activeVal = Tools::getValue('active', ''); + if ($activeVal !== '' && !in_array($activeVal, array('0', '1'))) { + $response['errors'][] = $this->l('Invalid status selected.'); + $this->ajaxDie(json_encode($response)); + } + + if ($activeVal === '0') { + $activeImages = HotelHeaderImage::getItems(1); + $activeIds = array_map('intval', array_column($activeImages, 'id_header_image')); + $activeToDisable = array_intersect($ids, $activeIds); + if (count($activeIds) - count($activeToDisable) < 1) { + $response['errors'][] = $this->l('At least one image must remain active.'); $this->ajaxDie(json_encode($response)); } } - $ids = Db::getInstance()->executeS( - 'SELECT `id_header_image` FROM `'._DB_PREFIX_.'htl_header_image`' - ); - if (!$ids) { - $response['errors'][] = $this->l('No images found.'); + $updateTagline = (bool)Tools::getValue('update_tagline', false); + $tagLineByLang = array(); + if ($updateTagline) { + foreach (Language::getLanguages(false) as $lang) { + $tagLineByLang[$lang['id_lang']] = trim(Tools::getValue('tag_line_'.$lang['id_lang'], '')); + } + foreach ($tagLineByLang as $tagLineValue) { + if (!Validate::isGenericName($tagLineValue)) { + $response['errors'][] = $this->l('Invalid tag line. Characters < > = { } are not allowed.'); + $this->ajaxDie(json_encode($response)); + } + } + } + + $tagLineColor = trim(Tools::getValue('tag_line_color', '')); + if ($tagLineColor !== '' && !preg_match('/^#[0-9a-fA-F]{6}$/', $tagLineColor)) { + $response['errors'][] = $this->l('Invalid tag line color. Use a 6-digit hex value (e.g. #ffffff).'); $this->ajaxDie(json_encode($response)); } - foreach ($ids as $row) { - $objImage = new HotelHeaderImage((int)$row['id_header_image']); - $objImage->tag_line = $tagLineByLang; - $objImage->save(); + $tagLineFontSize = (int)Tools::getValue('tag_line_font_size', 0); + if ($tagLineFontSize !== 0 && ($tagLineFontSize < 8 || $tagLineFontSize > 72)) { + $response['errors'][] = $this->l('Tag line font size must be between 8 and 72 pixels.'); + $this->ajaxDie(json_encode($response)); } - $defaultLangId = (int)Configuration::get('PS_LANG_DEFAULT'); - $response['success'] = true; - $response['tag_line'] = isset($tagLineByLang[$defaultLangId]) ? $tagLineByLang[$defaultLangId] : ''; - $response['tag_lines_json'] = json_encode((object)$tagLineByLang); - $response['confirmations'] = $this->l('Tag line updated for all images.'); + $tagLineFontWeight = Tools::getValue('tag_line_font_weight', ''); + if ($tagLineFontWeight !== '' && !in_array($tagLineFontWeight, array('300', '400', '600', '700'))) { + $response['errors'][] = $this->l('Invalid tag line font weight.'); + $this->ajaxDie(json_encode($response)); + } + + $defaultLangId = (int)Configuration::get('PS_LANG_DEFAULT'); + $updatedRows = array(); + foreach ($ids as $id) { + $objImage = new HotelHeaderImage($id); + if (!Validate::isLoadedObject($objImage)) { + continue; + } + + if ($activeVal !== '') { + $objImage->active = (int)$activeVal; + } + if ($updateTagline) { + $objImage->tag_line = $tagLineByLang; + } + if ($tagLineColor !== '') { + $objImage->tag_line_color = $tagLineColor; + } + if ($tagLineFontSize !== 0) { + $objImage->tag_line_font_size = $tagLineFontSize; + } + if ($tagLineFontWeight !== '') { + $objImage->tag_line_font_weight = $tagLineFontWeight; + } + $objImage->save(); + + $currentTagLines = is_array($objImage->tag_line) ? $objImage->tag_line : array(); + $updatedRows[] = array( + 'id' => (int)$objImage->id, + 'active' => (int)$objImage->active, + 'tag_line' => isset($currentTagLines[$defaultLangId]) ? $currentTagLines[$defaultLangId] : '', + 'tag_lines_json' => json_encode((object)$currentTagLines), + 'tag_line_color' => $objImage->tag_line_color, + 'tag_line_font_size' => $objImage->tag_line_font_size, + 'tag_line_font_weight' => $objImage->tag_line_font_weight, + ); + } + + if (!$updatedRows) { + $response['errors'][] = $this->l('No valid images were updated.'); + $this->ajaxDie(json_encode($response)); + } + + $response['success'] = true; + $response['data']['rows'] = $updatedRows; + $response['confirmations'] = $this->l('Selected images updated successfully.'); $this->ajaxDie(json_encode($response)); } diff --git a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css index 8d2e77818..563021a43 100644 --- a/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css +++ b/modules/hotelreservationsystem/views/css/HotelReservationAdmin.css @@ -624,45 +624,6 @@ p.room_cat_data background: #000; } -.qlo-video-url-preview { - padding: 14px 16px; - background: #f5f5f5; - border: 1px solid #ddd; - border-radius: 4px; - margin-bottom: 0; - word-break: break-all; - font-size: 13px; - color: #444; -} - -.qlo-video-url-preview .icon-link { - margin-right: 6px; - color: #5bc0de; - font-size: 14px; -} - -.wk-inline-hint { - display: inline-block; - margin: 6px 0 0 10px; - font-size: 12px; - vertical-align: middle; -} - -@keyframes wkSlideInLeft { - from { - opacity: 0; - transform: translateX(-16px); - } - to { - opacity: 1; - transform: translateX(0); - } -} - -.qlo-anim-slide-left { - animation: wkSlideInLeft 0.22s ease forwards; -} - .qlo-img-thumb { width: 120px; height: 75px; @@ -681,82 +642,9 @@ p.room_cat_data vertical-align: middle !important; } -.wk-row-placeholder { - background: #eef6ff !important; - border: 1px dashed #99c0e0 !important; -} - -.wk-row-placeholder td { - padding: 0 !important; - height: 85px; -} - - -/* ---- File list in add-image form ---- */ -.qlo-files-list { - list-style: none; - padding: 0; - margin: 8px 0 0; - max-width: 520px; -} -.qlo-files-list li { - display: flex; - align-items: center; - gap: 8px; - padding: 6px 10px; - border: 1px solid #e0e0e0; - border-radius: 3px; - margin-bottom: 5px; - background: #f9f9f9; - font-size: 13px; -} -.qlo-files-list li:first-child { - margin-top: 5px; -} -.qlo-files-list li:last-child { - margin-bottom: 0; -} -.qlo-files-list .qlo-file-name { - flex: 1; - min-width: 0; - white-space: nowrap; - overflow: hidden; - text-overflow: ellipsis; - font-weight: 500; - color: #333; -} -.qlo-files-list .qlo-file-size { - font-size: 11px; - color: #999; - white-space: nowrap; - flex-shrink: 0; -} -.qlo-files-list .qlo-remove-file { - flex-shrink: 0; - padding: 3px 8px; - line-height: 1; - font-size: 13px; - color: #999; - border-color: #ccc; - background: #fff; -} -.qlo-files-list .qlo-remove-file:hover, -.qlo-files-list .qlo-remove-file:focus { - color: #c0392b; - border-color: #c0392b; - background: #fff5f5; -} - -/* ---- Edit preview image in form ---- */ #qlo-img-edit-thumb { max-width: 160px; max-height: 100px; object-fit: cover; border-radius: 3px; } - -/* ---- Inline multilingual input (inside input-group-btn) ---- */ -.wk-inline-lang-input { - border-top-left-radius: 0 !important; - border-bottom-left-radius: 0 !important; -} diff --git a/modules/hotelreservationsystem/views/js/HotelHeaderImageAdmin.js b/modules/hotelreservationsystem/views/js/HotelHeaderImageAdmin.js index 2d6c04189..8457ffad5 100644 --- a/modules/hotelreservationsystem/views/js/HotelHeaderImageAdmin.js +++ b/modules/hotelreservationsystem/views/js/HotelHeaderImageAdmin.js @@ -72,56 +72,42 @@ $(document).ready(function () { $(document).on('change', 'input[name="QLO_HEADER_SLIDER_AUTO_PLAY"]', function () { if ($(this).val() === '1') { - $('#qlo-slide-interval-group, #qlo-slide-anim-group').show(); + $('#qlo-slide-interval-group, #qlo-slide-anim-group').show(200); } else { - $('#qlo-slide-interval-group, #qlo-slide-anim-group').hide(); + $('#qlo-slide-interval-group, #qlo-slide-anim-group').hide(200); } }); - $(document).on('change', '#qlo-img-form-file', function () { - renderFileListHm(this.files); - }); - - $(document).on('click', '.qlo-remove-file', function () { - var removeIdx = parseInt($(this).data('index'), 10); - var fileInput = document.getElementById('qlo-img-form-file'); - if (!fileInput || !fileInput.files) { return; } - try { - var dt = new DataTransfer(); - for (var i = 0; i < fileInput.files.length; i++) { - if (i !== removeIdx) { dt.items.add(fileInput.files[i]); } - } - fileInput.files = dt.files; - } catch (_e) { - } - renderFileListHm(fileInput.files); - }); - - function renderFileListHm(files) { - var $list = $('#qlo-img-files-list').empty(); - if (!files || !files.length) { $list.hide(); return; } - $list.show(); - for (var i = 0; i < files.length; i++) { - (function (idx, file) { - var size = file.size < 1048576 - ? (file.size / 1024).toFixed(1) + ' KB' - : (file.size / 1048576).toFixed(1) + ' MB'; - var $li = $( - '
{l s='Milliseconds between slides. Min: 500. Example: 5000 = 5 s.' mod='hotelreservationsystem'}
@@ -128,19 +128,17 @@