diff --git a/admin/include/functions_upload.inc.php b/admin/include/functions_upload.inc.php index 3ea729e1b..46e0fdaf9 100644 --- a/admin/include/functions_upload.inc.php +++ b/admin/include/functions_upload.inc.php @@ -520,8 +520,36 @@ SELECT 'filesize' => $file_infos['filesize'], ); - single_insert(IMAGE_FORMAT_TABLE, $insert); - $format_id = pwg_db_insert_id(IMAGE_FORMAT_TABLE); + + $query = ' +SELECT + format_id + FROM '.IMAGE_FORMAT_TABLE.' + WHERE image_id = '.$format_of.' + AND ext = "'.$format_ext.'" +;'; + + $formats = query2array($query); + if($formats) + { + $set_fields = array( + 'filesize' => $file_infos['filesize'], + ); + $where_fields = array( + 'format_id' => $formats[0]['format_id'], + 'image_id' => $format_of, + 'ext' => $format_ext, + ); + single_update(IMAGE_FORMAT_TABLE, $set_fields, $where_fields); + $format_id = $formats[0]['format_id']; + $add_status = "update"; + } + else + { + single_insert(IMAGE_FORMAT_TABLE, $insert); + $format_id = pwg_db_insert_id(IMAGE_FORMAT_TABLE); + $add_status = "add"; + } pwg_activity('photo', $format_of, 'edit', array('action'=>'add format', 'format_ext'=>$format_ext, 'format_id'=>$format_id)); @@ -530,7 +558,7 @@ SELECT trigger_notify('loc_end_add_format', $format_infos); - return $format_id; + return $add_status; } add_event_handler('upload_file', 'upload_file_pdf'); diff --git a/admin/photos_add_direct.php b/admin/photos_add_direct.php index e66fbbbc7..ea6cdd2f2 100644 --- a/admin/photos_add_direct.php +++ b/admin/photos_add_direct.php @@ -85,6 +85,7 @@ $display_formats = $conf['enable_formats'] && isset($_GET['formats']); $have_formats_original = false; $formats_original_info = array(); +$formats_ext_info = null; // If URL parameter isn't empty if ($display_formats && $_GET['formats']) @@ -109,13 +110,16 @@ SELECT * if (!empty($formats)) { $format_strings = array(); + $formats_exts = array(); foreach ($formats as $format) { $format_strings[] = sprintf('%s (%.2fMB)', $format['ext'], $format['filesize']/1024); + $formats_exts[] = strtolower($format['ext']); } $formats_original_info['formats'] = l10n('Formats: %s', implode(', ', $format_strings)); + $formats_ext_info = json_encode($formats_exts); } $extTab = explode('.',$formats_original_info['file']); @@ -150,7 +154,8 @@ $template->assign(array( 'DISPLAY_FORMATS' => $display_formats, 'HAVE_FORMATS_ORIGINAL' => $have_formats_original, 'FORMATS_ORIGINAL_INFO' => $formats_original_info, - 'SWITCH_MODE_URL' => get_root_url().'admin.php?page=photos_add'.($display_formats ? '':'&formats'), + 'FORMATS_EXT_INFO' => $formats_ext_info, + 'SWITCH_FORMAT_MODE_URL' => get_root_url().'admin.php?page=photos_add'.($display_formats ? '':'&formats'), 'format_ext' => implode(',', $conf['format_ext']), 'str_format_ext' => implode(', ', $conf['format_ext']), )); diff --git a/admin/themes/clear/theme.css b/admin/themes/clear/theme.css index cc5a09900..4fd1c5ef5 100644 --- a/admin/themes/clear/theme.css +++ b/admin/themes/clear/theme.css @@ -665,6 +665,9 @@ a#showPermissions:hover {border-color: #A5A5A5;} .plupload_filelist_footer {background-color: #F5F5F5!important;} li.plupload_delete a {background: url("images/cancel.svg")!important; background-size: cover!important;} li.plupload_delete a:hover {background: url("images/cancelhover.svg")!important; background-size: cover!important;} +li.plupload_delete a span {background: #FFF;} +li.plupload_delete a:hover span {background: #FFF;} +li.plupload_delete a.remove-format:hover{color: #474747;} .addAlbumEmpty {color: #3C3C3C;} #permitAction p {background: #FFF;} @@ -714,6 +717,13 @@ li.plupload_delete a:hover {background: url("images/cancelhover.svg")!important; #batchManagerGlobal .ui-slider-range.ui-widget-header.ui-corner-all {border: 1px solid #ffaf58;} #batchManagerGlobal .font-checkbox.selected {color: #777;} +/* Picture add */ + +.upload-options, .upload-options-content { + background-color: #f5f5f5; + color: #777777; +} + /* Category List */ .categoryContainer { margin: 0; diff --git a/admin/themes/default/js/photos_add_direct.js b/admin/themes/default/js/photos_add_direct.js index 975052ff8..4d361f5d7 100644 --- a/admin/themes/default/js/photos_add_direct.js +++ b/admin/themes/default/js/photos_add_direct.js @@ -16,6 +16,8 @@ const selectedAlbumEdit = $('#selectedAlbumEdit'); const btnAddFiles = $('#addFiles'); const chooseAlbumFirst = $('#chooseAlbumFirst'); const uploaderPhotos = $('#uploader'); +const formatsUpdated = []; +const formats = []; /*-------------- On DOM load @@ -85,6 +87,12 @@ $(function () { return false; }); + $("#uploadOptionsContent").hide(); + $("#uploadOptions").on("click", function(){ + $("#uploadOptionsContent").slideToggle(); + $(".moxie-shim-html5").css("display", "none"); + }) + $("#uploader").pluploadQueue({ // General settings browse_button: 'addFiles', @@ -153,11 +161,37 @@ $(function () { FilesAdded: async function (up, files) { // Création de la liste avec plupload_id : image_name fileNames = {}; + exts = {}; files.forEach((file) => { fileNames[file.id] = file.name; + exts[file.id] = file.name.substr(file.name.lastIndexOf('.') + 1); }); if (formatMode) { + formats.forEach((forms) => { + $("#"+forms[0]+" > .plupload_file_name").append(` + + + + `); + if(formatsUpdated.includes(forms[0])){ + $("#"+forms[0]+" > .plupload_file_name").after(` + + + ${format_update_warning} + + + + + + ${format_remove} + `); + $("#remove_"+forms[0]).on("click", function(){ + up.removeFile(forms[0]); + }); + } + }); + // If no original image is specified if (!haveFormatsOriginal) { const images_search = await new Promise((res, rej) => { @@ -166,8 +200,6 @@ $(function () { url: "ws.php?format=json&method=pwg.images.formats.searchImage", type: "POST", data: { - // category_id: $("select[name=category] option:selected").val(), // id category to modify - category_id: ab.get_selected_albums()[0], filename_list: JSON.stringify(fileNames), }, success: function (result) { @@ -182,8 +214,33 @@ $(function () { files.forEach((f) => { const search = images_search[f.id]; - if (search.status == "found") + if (search.status == "found"){ f.format_of = search.image_id; + formats.push([f.id,f.format_of]); + $("#"+f.id+" > .plupload_file_name").append(` + + + + `); + if (search.format_exist) + { + $("#"+f.id+" > .plupload_file_name").after(` + + + ${format_update_warning} + + + + + + ${format_remove} + `); + formatsUpdated.push(f.id); + $("#remove_"+f.id).on("click", function(){ + up.removeFile(f.id); + }); + } + } else { if (search.status == "multiple") multiple.push(f.name); @@ -218,14 +275,72 @@ $(function () { ...jConfirm_warning_options }) } - } else { //If an original image is specified + } else { + if (imageFormatsExtensions) + { + $forms_exts = JSON.parse(imageFormatsExtensions); + } + else + { + $forms_exts = []; + } files.forEach((f) => { f.format_of = originalImageId; + formats.push([f.id,f.format_of]); + $("#"+f.id+" > .plupload_file_name").append(` + + + + `); + if ($forms_exts.indexOf(exts[f.id]) != -1) + { + $("#"+f.id+" > .plupload_file_name").after(` + + + ${format_update_warning} + + + + + + ${format_remove} + `); + formatsUpdated.push(f.id); + $("#remove_"+f.id).on("click", function(){ + up.removeFile(f.id); + }); + } }) } } }, + FilesRemoved: function(up, file){ + formats.forEach((forms) => { + $("#"+forms[0]+" > .plupload_file_name").append(` + + + + `); + if(formatsUpdated.includes(forms[0])){ + $("#"+forms[0]+" > .plupload_file_name").after(` + + + ${format_update_warning} + + + + + + ${format_remove} + `); + $("#remove_"+forms[0]).on("click", function(){ + up.removeFile(forms[0]); + }); + } + }); + }, + UploadProgress: function (up, file) { $('#uploadingActions .progressbar').width(up.total.percent + '%'); Piecon.setProgress(up.total.percent); @@ -265,6 +380,8 @@ $(function () { options.name = file.name; } + options.update_mode = $('#toggleUpdateMode').is(':checked'); + up.setOption('multipart_params', options); }, @@ -289,6 +406,12 @@ $(function () { // do not remove file, or it will reset the progress bar :-/ // up.removeFile(file); uploadedPhotos.push(parseInt(data.result.image_id)); + if(data.result.add_status=="add"){ + addedPhotos.push(parseInt(data.result.image_id)); + } + else{ + updatedPhotos.push(parseInt(data.result.image_id)); + } if (!formatMode) uploadCategory = data.result.category; }, @@ -322,12 +445,23 @@ $(function () { $("#uploadForm, #permissions, .showFieldset").hide(); - const infoText = formatMode ? - sprintf(formatsUploaded_label, uploadedPhotos.length, [...new Set(files.map(f => f.format_of))].length) - : sprintf(photosUploaded_label, uploadedPhotos.length) + const infoTextAdd = formatMode ? + sprintf(formatsAdded_label, addedPhotos.length, [...new Set(addedPhotos)].length) + : sprintf(photosAdded_label, addedPhotos.length); - $(".infos").append(''); + const infoTextUpdate = formatMode ? + sprintf(formatsUpdated_label, updatedPhotos.length, [...new Set(updatedPhotos)].length) + : sprintf(photosUpdated_label, updatedPhotos.length); + if (addedPhotos.length && updatedPhotos.length) + { + $(".infos").append( ''); + } + else + { + const infoText = addedPhotos.length ? infoTextAdd : infoTextUpdate; + $(".infos").append(''); + } if (!formatMode) { html = sprintf( @@ -357,7 +491,6 @@ $(function () { } } }); - }); /*-------------- diff --git a/admin/themes/default/template/photos_add_direct.tpl b/admin/themes/default/template/photos_add_direct.tpl index 5353923c8..5c0ede7d4 100644 --- a/admin/themes/default/template/photos_add_direct.tpl +++ b/admin/themes/default/template/photos_add_direct.tpl @@ -35,25 +35,32 @@ const formatMode = {if $DISPLAY_FORMATS}true{else}false{/if}; const haveFormatsOriginal = {if $HAVE_FORMATS_ORIGINAL}true{else}false{/if}; const originalImageId = haveFormatsOriginal? '{if isset($FORMATS_ORIGINAL_INFO['id'])} {$FORMATS_ORIGINAL_INFO['id']} {else} -1 {/if}' : -1; +const imageFormatsExtensions = '{$FORMATS_EXT_INFO}'; const nb_albums = {$NB_ALBUMS|escape:javascript}; const chunk_size = '{$chunk_size}kb'; const max_file_size = '{$max_file_size}mb'; +const format_update_warning = "{'This format already exists, it will be overwritten !'|translate}"; +const format_remove = "{'Remove'|translate}"; var pwg_token = '{$pwg_token}'; -var photosUploaded_label = "{'%d photos uploaded'|translate|escape:javascript}"; -var formatsUploaded_label = "{'%d formats uploaded for %d photos'|translate|escape:javascript}"; -var batch_Label = "{'Manage this set of %d photos'|translate|escape:javascript}"; -var albumSummary_label = "{'Album "%s" now contains %d photos'|translate|escape:javascript}"; -var str_format_warning = "{'Error when trying to detect formats'|translate|escape:javascript}"; -var str_ok = "{'Ok'|translate|escape:javascript}"; -var str_format_warning_multiple = "{'There is multiple image in the database with the following names : %s.'|translate|escape:javascript}"; -var str_format_warning_notFound = "{'No picture found with the following name : %s.'|translate|escape:javascript}"; -var str_and_X_others = "{'and %d more'|translate|escape:javascript}"; +const photosAdded_label = "{'%d photos uploaded'|translate|escape:javascript}"; +const photosUpdated_label = "{'%d photos updated'|translate|escape:javascript}"; +const formatsAdded_label = "{'%d formats added for %d photos'|translate|escape:javascript}"; +const formatsUpdated_label = "{'%d formats updated for %d photos'|translate|escape:javascript}"; +const batch_Label = "{'Manage this set of %d photos'|translate|escape:javascript}"; +const albumSummary_label = "{'Album "%s" now contains %d photos'|translate|escape:javascript}"; +const str_format_warning = "{'Error when trying to detect formats'|translate|escape:javascript}"; +const str_ok = "{'Ok'|translate|escape:javascript}"; +const str_format_warning_multiple = "{'There is multiple image in the database with the following names : %s.'|translate|escape:javascript}"; +const str_format_warning_notFound = "{'No picture found with the following name : %s.'|translate|escape:javascript}"; +const str_and_X_others = "{'and %d more'|translate|escape:javascript}"; const str_upload_in_progress = "{'Upload in progress'|translate|escape:javascript}"; const str_drop_album_ab = '{'Drop into album'|@translate|escape:javascript}'; -var file_ext = "{$file_exts}"; -var format_ext = "{$format_ext}"; -var uploadedPhotos = []; -var uploadCategory = null; +const file_ext = "{$file_exts}"; +const format_ext = "{$format_ext}"; +const uploadedPhotos = []; +let uploadCategory = null; +const addedPhotos = []; +const updatedPhotos = []; let related_categories_ids = {$selected_category|json_encode}; {/footer_script} @@ -103,7 +110,7 @@ let related_categories_ids = {$selected_category|json_encode}; {if $ENABLE_FORMATS and $can_upload}
-