Skip to content

Commit

Permalink
feature 1514: make the "deactivate" action inactive if there is no ac…
Browse files Browse the repository at this point in the history
…tive

theme left.

bug fixed: when setting the default theme, make sure at least one user will
be updated.

git-svn-id: http://piwigo.org/svn/trunk@5382 68402e56-0260-453c-a942-63ccdbb3a9ee
  • Loading branch information
plegall committed Mar 26, 2010
1 parent 6d00630 commit b8a9773
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
19 changes: 18 additions & 1 deletion admin/include/themes.class.php
Expand Up @@ -117,6 +117,16 @@ function perform_action($action, $theme_id)
break;
}

// you can't deactivate the last theme
if (count($this->db_themes_by_id) <= 1)
{
array_push(
$errors,
l10n('Impossible to deactivate this theme, you need at least one theme.')
);
break;
}

if ($theme_id == get_default_theme())
{
// find a random theme to replace
Expand Down Expand Up @@ -227,6 +237,8 @@ function get_children_themes($theme_id)

function set_default_theme($theme_id)
{
global $conf;

// first we need to know which users are using the current default theme
$default_theme = get_default_theme();

Expand All @@ -236,7 +248,12 @@ function set_default_theme($theme_id)
FROM '.USER_INFOS_TABLE.'
WHERE theme = "'.$default_theme.'"
;';
$user_ids = array_from_query($query, 'user_id');
$user_ids = array_unique(
array_merge(
array_from_query($query, 'user_id'),
array($conf['guest_id'], $conf['default_user_id'])
)
);

// $user_ids can't be empty, at least the default user has the default
// theme
Expand Down
6 changes: 6 additions & 0 deletions admin/themes/default/template/themes_installed.tpl
Expand Up @@ -13,7 +13,13 @@
<div class="themeName">{$theme.name}{if $theme.is_default} <em>({'default'|@translate})</em>{/if}</div>
<div class="themeShot"><img src="{$theme.screenshot}"></div>
<div class="themeActions">

{if $theme.deactivable}
<a href="{$deactivate_baseurl}{$theme.id}" title="{'Forbid this theme to users'|@translate}">{'Deactivate'|@translate}</a>
{else}
<span title="{$theme.deactivate_tooltip}">{'Deactivate'|@translate}</span>
{/if}

{if not $theme.is_default}
| <a href="{$set_default_baseurl}{$theme.id}" title="{'Set as default theme for unregistered and new users'|@translate}">{'Default'|@translate}</a>
{/if}
Expand Down
8 changes: 8 additions & 0 deletions admin/themes_installed.php
Expand Up @@ -77,6 +77,14 @@

if (in_array($theme_id, $db_theme_ids))
{
$fs_theme['deactivable'] = true;

if (count($db_theme_ids) <= 1)
{
$fs_theme['deactivable'] = false;
$fs_theme['deactivate_tooltip'] = l10n('Impossible to deactivate this theme, you need at least one theme.');
}

if ($theme_id == $default_theme)
{
$fs_theme['is_default'] = true;
Expand Down
1 change: 1 addition & 0 deletions language/en_UK/admin.lang.php
Expand Up @@ -758,4 +758,5 @@
$lang['Select:'] = 'Select:';
$lang['None'] = 'None';
$lang['Invert'] = 'Invert';
$lang['Impossible to deactivate this theme, you need at least one theme.'] = 'Impossible to deactivate this theme, you need at least one theme.';
?>
1 change: 1 addition & 0 deletions language/fr_FR/admin.lang.php
Expand Up @@ -763,4 +763,5 @@
$lang['Select:'] = 'Sélectionner:';
$lang['None'] = 'Rien';
$lang['Invert'] = 'Inverser';
$lang['Impossible to deactivate this theme, you need at least one theme.'] = 'Impossible de désactiver ce thème, il doit rester au moins un thème activé.';
?>

0 comments on commit b8a9773

Please sign in to comment.