diff --git a/admin/batch_manager_unit.php b/admin/batch_manager_unit.php index f16226fe8..a63e5ea03 100644 --- a/admin/batch_manager_unit.php +++ b/admin/batch_manager_unit.php @@ -96,6 +96,40 @@ SELECT id, date_creation invalidate_user_cache(); } +//collection +$collection = array(); +if (isset($_POST['nb_photos_deleted'])) +{ + check_input_parameter('nb_photos_deleted', $_POST, false, '/^\d+$/'); + + // let's fake a collection (we don't know the image_ids so we use "null", we only + // care about the number of items here) + $collection = array_fill(0, $_POST['nb_photos_deleted'], null); +} +else if (isset($_POST['setSelected'])) +{ + // Here we don't use check_input_parameter because preg_match has a limit in + // the repetitive pattern. Found a limit to 3276 but may depend on memory. + // + // check_input_parameter('whole_set', $_POST, false, '/^\d+(,\d+)*$/'); + // + // Instead, let's break the input parameter into pieces and check pieces one by one. + $collection = explode(',', $_POST['whole_set']); + + foreach ($collection as $id) + { + if (!preg_match('/^\d+$/', $id)) + { + fatal_error('[Hacking attempt] the input parameter "whole_set" is not valid'); + } + } +} +else if (isset($_POST['selection'])) +{ + $collection = $_POST['selection']; +} + + // +-----------------------------------------------------------------------+ // | template init | // +-----------------------------------------------------------------------+ @@ -108,12 +142,127 @@ $base_url = PHPWG_ROOT_PATH.'admin.php'; $template->assign( array( 'U_ELEMENTS_PAGE' => $base_url.get_query_string_diff(array('display','start')), - 'F_ACTION' => $base_url.get_query_string_diff(array()), 'level_options' => get_privacy_level_options(), 'ADMIN_PAGE_TITLE' => l10n('Batch Manager'), 'PWG_TOKEN' => get_pwg_token(), ) ); + //prefilter + $prefilters = array( + array('ID' => 'caddie', 'NAME' => l10n('Caddie')), + array('ID' => 'favorites', 'NAME' => l10n('Your favorites')), + array('ID' => 'last_import', 'NAME' => l10n('Last import')), + array('ID' => 'no_album', 'NAME' => l10n('With no album').' ('.l10n('Orphans').')'), + array('ID' => 'no_tag', 'NAME' => l10n('With no tag')), + array('ID' => 'duplicates', 'NAME' => l10n('Duplicates')), + array('ID' => 'all_photos', 'NAME' => l10n('All')) + ); + + if ($conf['enable_synchronization']) + { + $prefilters[] = array('ID' => 'no_virtual_album', 'NAME' => l10n('With no virtual album')); + $prefilters[] = array('ID' => 'no_sync_md5sum', 'NAME' => l10n('With no checksum')); + } + + function UC_name_compare($a, $b) + { + return strcmp(strtolower($a['NAME']), strtolower($b['NAME'])); + } + + $prefilters = trigger_change('get_batch_manager_prefilters', $prefilters); + + // Sort prefilters by localized name. + usort($prefilters, function ($a, $b) { + return strcmp(strtolower($a['NAME']), strtolower($b['NAME'])); + }); + + $template->assign( + array( + 'conf_checksum_compute_blocksize' => $conf['checksum_compute_blocksize'], + 'prefilters' => $prefilters, + 'filter' => $_SESSION['bulk_manager_filter'], + 'selection' => $collection, + 'all_elements' => $page['cat_elements_id'], + 'START' => $page['start'], + 'U_DISPLAY'=>$base_url.get_query_string_diff(array('display')), + 'F_ACTION'=>$base_url.get_query_string_diff(array('cat','start','tag','filter')), + ) + ); + + if (isset($page['no_md5sum_number'])) + { + $template->assign( + array( + 'NB_NO_MD5SUM' => $page['no_md5sum_number'], + ) + ); + } else { + $template->assign('NB_NO_MD5SUM', ''); + } + + + // privacy level + foreach ($conf['available_permission_levels'] as $level) + { + $level_options[$level] = l10n(sprintf('Level %d', $level)); + + if (0 == $level) + { + $level_options[$level] = l10n('Everybody'); + } + } + $template->assign( + array( + 'filter_level_options'=> $level_options, + 'filter_level_options_selected' => isset($_SESSION['bulk_manager_filter']['level']) + ? $_SESSION['bulk_manager_filter']['level'] + : 0, + ) + ); + + // tags + $filter_tags = array(); + + if (!empty($_SESSION['bulk_manager_filter']['tags'])) + { + $query = ' + SELECT + id, + name + FROM '.TAGS_TABLE.' + WHERE id IN ('.implode(',', $_SESSION['bulk_manager_filter']['tags']).') + ;'; + + $filter_tags = get_taglist($query); + } + + $template->assign('filter_tags', $filter_tags); + + // in the filter box, which category to select by default + $selected_category = array(); + + if (isset($_SESSION['bulk_manager_filter']['category'])) + { + $selected_category = array($_SESSION['bulk_manager_filter']['category']); + } + else + { + // we need to know the category in which the last photo was added + $query = ' + SELECT category_id + FROM '.IMAGE_CATEGORY_TABLE.' + ORDER BY image_id DESC + LIMIT 1 + ;'; + $result = pwg_query($query); + if (pwg_db_num_rows($result) > 0) + { + $row = pwg_db_fetch_assoc($result); + $selected_category[] = $row['category_id']; + } + } + + $template->assign('filter_category_selected', $selected_category); // +-----------------------------------------------------------------------+ // | global mode thumbnails | diff --git a/admin/themes/default/js/batchManagerUnit.js b/admin/themes/default/js/batchManagerUnit.js index 2228e2cc9..5c04993c8 100644 --- a/admin/themes/default/js/batchManagerUnit.js +++ b/admin/themes/default/js/batchManagerUnit.js @@ -1,4 +1,73 @@ +/* ********** Filters*/ +function filter_enable(filter) { + /* show the filter*/ + $("#"+filter).show(); + + /* check the checkbox to declare we use this filter */ + $("input[type=checkbox][name="+filter+"_use]").prop("checked", true); + + /* forbid to select this filter in the addFilter list */ + $("#addFilter").find("a[data-value="+filter+"]").addClass("disabled", "disabled"); + + /* hide the no filter message */ + $('.noFilter').hide(); + $('.addFilter-button').removeClass('highlight'); +} + +function filter_disable(filter) { + /* hide the filter line */ + $("#"+filter).hide(); + + /* uncheck the checkbox to declare we do not use this filter */ + $("input[name="+filter+"_use]").prop("checked", false); + + /* give the possibility to show it again */ + $("#addFilter").find("a[data-value="+filter+"]").removeClass("disabled"); + + /* show the no filter message if no filter selected */ + if ($('#filterList li:visible').length == 0) { + $('.noFilter').show(); + $('.addFilter-button').addClass('highlight'); + } + +} + $(document).ready(function () { + +$(".removeFilter").addClass("icon-cancel-circled"); + +$(".removeFilter").click(function () { + var filter = $(this).parent('li').attr("id"); + filter_disable(filter); + + return false; +}); + +$("#addFilter a").on('click', function () { + var filter = $(this).attr("data-value"); + filter_enable(filter); +}); + +$("#removeFilters").click(function() { + $("#filterList li").each(function() { + var filter = $(this).attr("id"); + filter_disable(filter); + }); + return false; +}); + +$('[data-slider=widths]').pwgDoubleSlider(sliders.widths); +$('[data-slider=heights]').pwgDoubleSlider(sliders.heights); +$('[data-slider=ratios]').pwgDoubleSlider(sliders.ratios); +$('[data-slider=filesizes]').pwgDoubleSlider(sliders.filesizes); + +$(document).mouseup(function (e) { + e.stopPropagation(); + if (!$(event.target).hasClass('addFilter-button')) { + $('.addFilter-dropdown').slideUp(); + } +}); + // Detect unsaved changes on any inputs var user_interacted = false; @@ -10,129 +79,18 @@ $(document).ready(function () { var pictureId = $(this).parents("fieldset").data("image_id"); if (user_interacted == true) { showUnsavedLocalBadge(pictureId); - updateUnsavedGlobalBadge(); + } }); - $('.icon-cancel-circled, .item-add').on('click', function() { + $('.related-categories-container .remove-item').on('click', function() { + user_interacted = true; var pictureId = $(this).parents("fieldset").data("image_id"); showUnsavedLocalBadge(pictureId); - updateUnsavedGlobalBadge(); + }); - function updateUnsavedGlobalBadge() { - var visibleLocalUnsavedCount = $(".local-unsaved-badge").filter(function() { - return $(this).css('display') === 'block'; - }).length; - - if (visibleLocalUnsavedCount > 0) { - $(".global-unsaved-badge").css('display', 'block'); - $("#unsaved-count").text(visibleLocalUnsavedCount); - } else { - $(".global-unsaved-badge").css('display', 'none'); - $("#unsaved-count").text(''); - } - } - - function showUnsavedLocalBadge(pictureId) { - hideSuccesLocalBadge(pictureId); - hideErrorLocalBadge(pictureId); - $("#picture-" + pictureId + " .local-unsaved-badge").css('display', 'block'); - } - - function hideUnsavedLocalBadge(pictureId) { - $("#picture-" + pictureId + " .local-unsaved-badge").css('display', 'none'); - } - - $(window).on('beforeunload', function() { - if (user_interacted) { - return "You have unsaved changes, are you sure you want to leave this page?"; - } - }); - //Error badge - function showErrorLocalBadge(pictureId) { - $("#picture-" + pictureId + " .local-error-badge").css('display', 'block'); -} - function hideErrorLocalBadge(pictureId) { - $("#picture-" + pictureId + " .local-error-badge").css('display', 'none'); -} - - //Succes badge - function updateSuccesGlobalBadge() { - var visibleLocalSuccesCount = $(".local-succes-badge").filter(function() { - return $(this).css('display') === 'block'; - }).length; - - if (visibleLocalSuccesCount > 0) { - showSuccesGlobalBadge() - } else { - hideSuccesGlobalBadge() - } -} - - function showSuccesLocalBadge(pictureId) { - var badge = $("#picture-" + pictureId + " .local-succes-badge"); - badge.css({ - 'display': 'block', - 'opacity': 1 - }); - - setTimeout(() => { - badge.fadeOut(1000, function() { - badge.css('display', 'none'); - }); - }, 3000); -} - -function hideSuccesLocalBadge(pictureId) { - $("#picture-" + pictureId + " .local-succes-badge").css('display', 'none'); -} - -function showSuccesGlobalBadge() { - var badge = $(".global-succes-badge"); - badge.css({ - 'display': 'block', - 'opacity': 1 - }); - - setTimeout(() => { - badge.fadeOut(1000, function() { - badge.css('display', 'none'); - }); - }, 3000); -} - -function hideSuccesGlobalBadge() { - $("global-succes-badge").css('display', 'none'); -} - -function disableLocalButton(pictureId) { - $("#picture-" + pictureId + " .action-save-picture").addClass("disabled"); - - $("#picture-" + pictureId + " .action-save-picture i").removeClass("icon-floppy").addClass("icon-spin6 animate-spin"); -} - -function enableLocalButton(pictureId) { - $("#picture-" + pictureId + " .action-save-picture").removeClass("disabled"); - - $("#picture-" + pictureId + " .action-save-picture i").removeClass("icon-spin6 animate-spin").addClass("icon-floppy"); -} - -function disableGlobalButton() { - $(".action-save-global").addClass("disabled"); - - $(".action-save-global i").removeClass("icon-floppy").addClass("icon-spin6 animate-spin"); -} - -function enableGlobalButton() { - $(".action-save-global").removeClass("disabled"); - - $(".action-save-global i").removeClass("icon-spin6 animate-spin").addClass("icon-floppy"); -} - - - // DELETE $('.action-delete-picture').on('click', function(event) { var $fieldset = $(this).parents("fieldset"); @@ -213,80 +171,7 @@ function enableGlobalButton() { saveAllChanges(); }); - function saveChanges(pictureId) { - if ($("#picture-" + pictureId + " .local-unsaved-badge").css('display') === 'block') { - disableGlobalButton(); - disableLocalButton(pictureId) - console.log("Saving changes for " + pictureId); - // Retrieve Infos - var name = $("#name-" + pictureId).val(); - var author = $("#author-" + pictureId).val(); - var date_creation = $("#date_creation-" + pictureId).val(); - var comment = $("#description-" + pictureId).val(); - var level = $("#level-" + pictureId + " option:selected").val(); - - // Get Categories - var categories = []; - $("#picture-" + pictureId + " .remove-item").each(function() { - categories.push($(this).attr("id")); - }); - var categoriesStr = categories.join(';'); - - // Get Tags - var tags = []; - $("#tags-" + pictureId + " option").each(function() { - var tagId = $(this).val().replace(/~~/g, ''); - tags.push(tagId); - }); - var tagsStr = tags.join(','); - - $.ajax({ - url: 'ws.php?format=json', - method: 'POST', - data: { - method: 'pwg.images.setInfo', - image_id: pictureId, - name: name, - author: author, - date_creation: date_creation, - comment: comment, - categories: categoriesStr, - tag_ids: tagsStr, - level: level, - single_value_mode: "replace", - multiple_value_mode: "replace", - pwg_token: jQuery("input[name=pwg_token]").val() - }, - success: function(response) { - console.log(response); - enableLocalButton(pictureId); - enableGlobalButton(); - hideUnsavedLocalBadge(pictureId); - showSuccesLocalBadge(pictureId); - updateUnsavedGlobalBadge(); - updateSuccesGlobalBadge(); - }, - error: function(xhr, status, error) { - enableLocalButton(pictureId); - enableGlobalButton(); - hideUnsavedLocalBadge(pictureId); - showErrorLocalBadge(pictureId); - updateUnsavedGlobalBadge(); - updateSuccesGlobalBadge(); - console.error('Error:', error); - } - }); - } else { - console.log("No changes to save for " + pictureId); - } - } - function saveAllChanges() { - $("fieldset").each(function() { - var pictureId = $(this).data("image_id"); - saveChanges(pictureId); - }); -} //Categories @@ -337,7 +222,7 @@ function fill_results(cats, pictureId) { cats.forEach(cat => { $("#searchResult").append( "