Updated: All the suggested flow implemented

This commit is contained in:
shazar rahman
2026-08-19 19:25:32 +05:30
parent fc3ecc2027
commit cc352ffd75
5 changed files with 530 additions and 560 deletions

View File

@@ -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));
}