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.
This commit is contained in:
plegall
2016-12-01 18:13:24 +01:00
parent 5d4ff90cef
commit 7620b47309
3 changed files with 155 additions and 2 deletions

View File

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

View File

@@ -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.= '<br>'.l10n('Numeric identifier : %d', $category['id']);
$template->assign(array(

View File

@@ -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}
<div class="titrePage">
<h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|@translate} {$TABSHEET_TITLE}</h2>
@@ -142,7 +211,7 @@ jQuery(document).ready(function() {
{/if}
{if isset($U_DELETE) }
<li><a class="icon-trash" href="{$U_DELETE}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');">{'delete album'|@translate}</a></li>
<li><a class="icon-trash deleteAlbum" href="#">{'delete album'|@translate}</a></li>
{/if}
</ul>
@@ -200,4 +269,35 @@ jQuery(document).ready(function() {
</fieldset>
</form>
<div style="display:none">
<div class="delete_popin">
<p>
{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}
</p>
{if $NB_IMAGES_RECURSIVE > 0}
<ul>
{if $NB_IMAGES_ASSOCIATED_OUTSIDE > 0}
<li><label><input type="radio" name="photo_deletion_mode" value="force_delete"> delete album and all {$NB_IMAGES_RECURSIVE} photos, even the {$NB_IMAGES_ASSOCIATED_OUTSIDE} associated to other albums</label>
{/if}
<li><label><input type="radio" name="photo_deletion_mode" value="delete_orphans"> delete album and the {$NB_IMAGES_BECOMING_ORPHAN} orphan photos</li>
<li><label><input type="radio" name="photo_deletion_mode" value="no_delete" checked="checked"> delete only album, not photos</li>
</ul>
{/if}
<p class="popin-actions">
<a id="deleteConfirm" class="buttonLike" type="submit" href="{$U_DELETE}"><i class="icon-trash"></i> {'Confirm deletion'|translate}</button>
<a class="icon-cancel-circled close-delete_popin" href="#">{'Cancel'}</a>
</p>
{* $U_DELETE *}
</div>
</div>
</div> {* #catModify *}