diff --git a/admin/cat_modify.php b/admin/cat_modify.php index 5527bd44f..eb7b195bc 100644 --- a/admin/cat_modify.php +++ b/admin/cat_modify.php @@ -411,7 +411,7 @@ if ($category['has_images'] or !empty($category['representative_picture_id'])) } // can the admin choose to set a new random representant ? - $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images']) ? true : false; + $tpl_representant['ALLOW_SET_RANDOM'] = ($category['has_images'] ? true : false); // can the admin delete the current representant ? if ( diff --git a/admin/themes/default/template/cat_modify.tpl b/admin/themes/default/template/cat_modify.tpl index 094d25672..1e8aa6540 100644 --- a/admin/themes/default/template/cat_modify.tpl +++ b/admin/themes/default/template/cat_modify.tpl @@ -78,7 +78,11 @@ jQuery(document).ready(function() { var data = jQuery.parseJSON(data); if (data.stat == 'ok') { jQuery(".albumThumbnailImage").hide(); - jQuery(".albumThumbnailRandom").show(); + if (jQuery(".albumThumbnailActions").data('random_allowed') == '') { + jQuery(".deleteRepresentative").hide(); + } else { + jQuery(".albumThumbnailRandom").show(); + } } else { alert("error on "+method); @@ -176,13 +180,16 @@ jQuery(document).ready(function() {
-+
+ {assign var="action_separator" value=""} {if $representant.ALLOW_SET_RANDOM } {'Refresh'|@translate} + {assign var="action_separator" value="|"} {/if} {if isset($representant.ALLOW_DELETE) } - | {'Delete'|translate} + {$action_separator} + {'Delete'|translate} {/if}
{/if} diff --git a/include/ws_functions/pwg.categories.php b/include/ws_functions/pwg.categories.php index 37b05664b..2eab7b654 100644 --- a/include/ws_functions/pwg.categories.php +++ b/include/ws_functions/pwg.categories.php @@ -703,7 +703,7 @@ UPDATE '. USER_CACHE_CATEGORIES_TABLE .' * API method * * Deletes the album thumbnail. Only possible if - * $conf['allow_random_representative'] + * $conf['allow_random_representative'] or if the album has no direct photos. * * @param mixed[] $params * @option int category_id @@ -724,7 +724,14 @@ SELECT id return new PwgError(404, 'category_id not found'); } - if (!$conf['allow_random_representative']) + $query = ' +SELECT COUNT(*) + FROM '.IMAGE_CATEGORY_TABLE.' + WHERE category_id = '.$params['category_id'].' +;'; + list($nb_images) = pwg_db_fetch_row(pwg_query($query)); + + if (!$conf['allow_random_representative'] and $nb_images != 0) { return new PwgError(401, 'not permitted'); }