From 8ea9a0fc7eed0522e20da26d38b2db1e5c81fdf0 Mon Sep 17 00:00:00 2001 From: Daniel Cebrian Date: Wed, 15 Feb 2023 16:41:14 +0100 Subject: [PATCH] #9073 added system system for edit images in edit tip --- .../godmode/setup/welcome_tips.php | 6 +++ .../include/class/TipsWindow.class.php | 48 +++++++++++++++++-- .../include/javascript/tipsWindow.js | 12 +++++ .../include/styles/tips_window.css | 7 +++ 4 files changed, 68 insertions(+), 5 deletions(-) diff --git a/pandora_console/godmode/setup/welcome_tips.php b/pandora_console/godmode/setup/welcome_tips.php index 531d47bf3a..c558404925 100644 --- a/pandora_console/godmode/setup/welcome_tips.php +++ b/pandora_console/godmode/setup/welcome_tips.php @@ -88,8 +88,14 @@ if ($view === 'create' || $view === 'edit') { case 'edit': $idTip = get_parameter('idTip', ''); + $imagesToDelete = get_parameter('images_to_delete', ''); if (empty($idTip) === false) { if (count($errors) === 0) { + if (empty($imagesToDelete) === false) { + $imagesToDelete = json_decode(io_safe_output($imagesToDelete), true); + $tipsWindow->deleteImagesFromTip($idTip, $imagesToDelete); + } + if (count($files) > 0) { $uploadImages = $tipsWindow->uploadImages($files); } diff --git a/pandora_console/include/class/TipsWindow.class.php b/pandora_console/include/class/TipsWindow.class.php index 4ff765e9b2..93efe47a2a 100644 --- a/pandora_console/include/class/TipsWindow.class.php +++ b/pandora_console/include/class/TipsWindow.class.php @@ -251,13 +251,28 @@ class TipsWindow return false; } - $sql = sprintf('SELECT filename, path FROM twelcome_tip_file WHERE twelcome_tip_file = %s', $idTip); + $sql = sprintf('SELECT id, filename, path FROM twelcome_tip_file WHERE twelcome_tip_file = %s', $idTip); return db_get_all_rows_sql($sql); } + public function deleteImagesFromTip($idTip, $imagesToRemove) + { + foreach ($imagesToRemove as $id => $image) { + unlink($image); + db_process_sql_delete( + 'twelcome_tip_file', + [ + 'id' => $id, + 'twelcome_tip_file' => $idTip, + ] + ); + } + } + + public function setShowTipsAtStartup() { global $config; @@ -527,7 +542,6 @@ class TipsWindow $table->data = []; $table->data[0][0] = __('Images'); - $table->data[0][1] = html_print_input_hidden('number_images', 0, true); $table->data[0][1] .= html_print_div(['id' => 'inputs_images'], true); $table->data[0][1] .= html_print_button(__('Add image'), 'button_add_image', false, '', '', true); $table->data[1][0] = __('Language'); @@ -581,6 +595,29 @@ class TipsWindow } } + $outputImagesTip = ''; + if (empty($files) === false) { + foreach ($files as $key => $value) { + $namePath = $value['path'].$value['filename']; + $imageTip = html_print_image($namePath, true); + $imageTip .= html_print_input_image( + 'delete_image_tip', + 'images/delete.png', + '', + '', + true, + ['onclick' => 'deleteImage(this, \''.$value['id'].'\', \''.$namePath.'\')'] + ); + $outputImagesTip .= html_print_div( + [ + 'class' => 'image-tip', + 'content' => $imageTip, + ], + true + ); + } + } + $table = new stdClass(); $table->width = '100%'; $table->class = 'databox filters'; @@ -589,8 +626,9 @@ class TipsWindow $table->data = []; $table->data[0][0] = __('Images'); - $table->data[0][1] = html_print_input_hidden('number_images', 0, true); + $table->data[0][1] .= $outputImagesTip; $table->data[0][1] .= html_print_div(['id' => 'inputs_images'], true); + $table->data[0][1] .= html_print_input_hidden('images_to_delete', '{}', true); $table->data[0][1] .= html_print_button(__('Add image'), 'button_add_image', false, '', '', true); $table->data[1][0] = __('Language'); $table->data[1][1] = html_print_select_from_sql( @@ -744,8 +782,8 @@ class TipsWindow $imagesOk = []; foreach ($files as $key => $file) { $name = str_replace(' ', '_', $file['name']); - $name = str_replace('.', uniqid().'.', $file['name']); - $r = move_uploaded_file($file['tmp_name'], $dir.'/'.$name); + $name = str_replace('.', uniqid().'.', $name); + move_uploaded_file($file['tmp_name'], $dir.'/'.$name); $imagesOk[] = $name; } diff --git a/pandora_console/include/javascript/tipsWindow.js b/pandora_console/include/javascript/tipsWindow.js index 05b569abca..6794af3679 100644 --- a/pandora_console/include/javascript/tipsWindow.js +++ b/pandora_console/include/javascript/tipsWindow.js @@ -14,6 +14,9 @@ $(document).ready(function() { ); $("#inputs_images").append(div_image); }); + $("#image-delete_image_tip1").on("click", function(e) { + e.preventDefault(); + }); }); $(".carousel .images").ready(function() { activeCarousel(); @@ -38,6 +41,15 @@ $("#checkbox_tips_startup").ready(function() { }); }); }); + +function deleteImage(e, id, path) { + var imagesToDelete = JSON.parse($("#hidden-images_to_delete").val()); + imagesToDelete[id] = path; + $("#hidden-images_to_delete").val(JSON.stringify(imagesToDelete)); + $(e) + .parent() + .remove(); +} function activeCarousel() { if ($(".carousel .images img").length > 1) { $(".carousel .images").bxSlider({ controls: true }); diff --git a/pandora_console/include/styles/tips_window.css b/pandora_console/include/styles/tips_window.css index db1c852bc0..fec79aff69 100644 --- a/pandora_console/include/styles/tips_window.css +++ b/pandora_console/include/styles/tips_window.css @@ -183,3 +183,10 @@ span.disable { text-align: center; display: flex; } +.image-tip { + display: flex; + align-items: center; +} +.image-tip img { + max-width: 350px; +}