From 7620b473096f1ab7df3db6ca611566f142c36893 Mon Sep 17 00:00:00 2001 From: plegall Date: Thu, 1 Dec 2016 18:13:24 +0100 Subject: [PATCH] feature #153, photo deletion mode when deleting album Administrator can decide to delete all photos (even those associated to another albums) or delete orphan photos or delete no photo at all. --- admin/cat_list.php | 8 +- admin/cat_modify.php | 47 +++++++++ admin/themes/default/template/cat_modify.tpl | 102 ++++++++++++++++++- 3 files changed, 155 insertions(+), 2 deletions(-) diff --git a/admin/cat_list.php b/admin/cat_list.php index 81e7c1804..ce9feaf4a 100644 --- a/admin/cat_list.php +++ b/admin/cat_list.php @@ -192,7 +192,13 @@ include(PHPWG_ROOT_PATH.'admin/include/albums_tab.inc.php'); // request to delete a virtual category if (isset($_GET['delete']) and is_numeric($_GET['delete'])) { - delete_categories(array($_GET['delete'])); + $photo_deletion_mode = 'no_delete'; + if (isset($_GET['photo_deletion_mode'])) + { + $photo_deletion_mode = $_GET['photo_deletion_mode']; + } + delete_categories(array($_GET['delete']), $photo_deletion_mode); + $_SESSION['page_infos'] = array(l10n('Virtual album deleted')); update_global_rank(); invalidate_user_cache(); diff --git a/admin/cat_modify.php b/admin/cat_modify.php index 3e50d8ff5..13886df0e 100644 --- a/admin/cat_modify.php +++ b/admin/cat_modify.php @@ -196,6 +196,42 @@ $query = 'SELECT DISTINCT category_id $result = pwg_query($query); $category['has_images'] = pwg_db_num_rows($result)>0 ? true : false; +// number of sub-categories +$subcat_ids = get_subcat_ids(array($category['id'])); + +$category['nb_subcats'] = count($subcat_ids) - 1; + +// total number of images under this category (including sub-categories) +$query = ' +SELECT + DISTINCT(image_id) + FROM '.IMAGE_CATEGORY_TABLE.' + WHERE category_id IN ('.implode(',', $subcat_ids).') + ;'; +$image_ids_recursive = query2array($query, null, 'image_id'); + +$category['nb_images_recursive'] = count($image_ids_recursive); + +// number of images that would become orphan on album deletion +$category['nb_images_becoming_orphan'] = 0; +$category['nb_images_associated_outside'] = 0; + +if ($category['nb_images_recursive'] > 0) +{ + $query = ' +SELECT + DISTINCT(image_id) + FROM '.IMAGE_CATEGORY_TABLE.' + WHERE category_id NOT IN ('.implode(',', $subcat_ids).') + AND image_id IN ('.implode(',', $image_ids_recursive).') +;'; + $image_ids_associated_outside = query2array($query, null, 'image_id'); + $category['nb_images_associated_outside'] = count($image_ids_associated_outside); + + $image_ids_becoming_orphan = array_diff($image_ids_recursive, $image_ids_associated_outside); + $category['nb_images_becoming_orphan'] = count($image_ids_becoming_orphan); +} + // Navigation path $navigation = get_cat_display_name_cache( $category['uppercats'], @@ -285,6 +321,17 @@ else $intro = l10n('This album contains no photo.'); } +// info for deletion +$template->assign( + array( + 'CATEGORY_FULLNAME' => trim(strip_tags($navigation)), + 'NB_SUBCATS' => $category['nb_subcats'], + 'NB_IMAGES_RECURSIVE' => $category['nb_images_recursive'], + 'NB_IMAGES_BECOMING_ORPHAN' => $category['nb_images_becoming_orphan'], + 'NB_IMAGES_ASSOCIATED_OUTSIDE' => $category['nb_images_associated_outside'], + ) + ); + $intro.= '
'.l10n('Numeric identifier : %d', $category['id']); $template->assign(array( diff --git a/admin/themes/default/template/cat_modify.tpl b/admin/themes/default/template/cat_modify.tpl index 013cf9553..8e451804f 100644 --- a/admin/themes/default/template/cat_modify.tpl +++ b/admin/themes/default/template/cat_modify.tpl @@ -1,3 +1,4 @@ +{include file='include/colorbox.inc.tpl'} {combine_script id='LocalStorageCache' load='footer' path='admin/themes/default/js/LocalStorageCache.js'} {combine_script id='jquery.selectize' load='footer' path='themes/default/js/plugins/selectize.min.js'} @@ -89,10 +90,78 @@ jQuery(document).ready(function() { e.preventDefault(); }); + + jQuery(".deleteAlbum").click(function() { + jQuery.colorbox({ + inline:true, + title:"{'delete album'|translate|escape:javascript}", + href:".delete_popin" + }); + + return false; + }); + + function set_photo_deletion_mode() { + if (jQuery("input[name=photo_deletion_mode]").length > 0) { + var $photo_deletion_mode = jQuery("input[name=photo_deletion_mode]:checked").val(); + jQuery("#deleteConfirm").data("photo_deletion_mode", $photo_deletion_mode); + } + } + + set_photo_deletion_mode(); + + jQuery("input[name=photo_deletion_mode]").change(function() { + set_photo_deletion_mode(); + }); + + jQuery("#deleteConfirm").click(function() { + if (jQuery("input[name=photo_deletion_mode]").length > 0) { + var $href = jQuery(this).attr("href"); + jQuery(this).attr("href", $href+"&photo_deletion_mode="+jQuery(this).data("photo_deletion_mode")); + } + }); + + jQuery(document).on('click', '.close-delete_popin', function(e) { + jQuery('.delete_popin').colorbox.close(); + e.preventDefault(); + }); }); {/footer_script} +{html_style} +.delete_popin { + padding:20px 30px; +} + +.delete_popin p { + margin:0; +} + +.delete_popin ul { + padding:0; + margin:30px 0; +} + +.delete_popin ul li { + list-style-type:none; + margin:10px 0; +} + +.delete_popin .buttonLike i { + font-size:14px; +} + +.delete_popin .buttonLike { + padding:5px; + margin-right:10px; +} + +.delete_popin p.popin-actions { + margin-top:30px; +} +{/html_style} +

{$CATEGORIES_NAV} › {'Edit album'|@translate} {$TABSHEET_TITLE}

@@ -142,7 +211,7 @@ jQuery(document).ready(function() { {/if} {if isset($U_DELETE) } -
  • {'delete album'|@translate}
  • +
  • {'delete album'|@translate}
  • {/if} @@ -200,4 +269,35 @@ jQuery(document).ready(function() { + +
    +
    + +

    +{if $NB_SUBCATS == 0} + {'Delete album "%s".'|translate:$CATEGORY_FULLNAME} +{else} + {'Delete album "%s" and its %d sub-albums.'|translate:$CATEGORIES_NAV:$NB_SUBCATS} +{/if} +

    + +{if $NB_IMAGES_RECURSIVE > 0} +
      + {if $NB_IMAGES_ASSOCIATED_OUTSIDE > 0} +
    • + {/if} +
    • +
    • +
    +{/if} + +

    + {'Confirm deletion'|translate} + {'Cancel'} +

    + +{* $U_DELETE *} +
    +
    +
    {* #catModify *} \ No newline at end of file