Index: /extensions/header_manager/admin.php
===================================================================
--- /extensions/header_manager/admin.php	(revision 16936)
+++ /extensions/header_manager/admin.php	(revision 16937)
@@ -10,24 +10,32 @@
 }
 
+$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : 'config';
 
-// tabsheet
-include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
-$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'config';
-  
-$tabsheet = new tabsheet();
-$tabsheet->add('config', l10n('Configuration'), HEADER_MANAGER_ADMIN . '-config');
-$tabsheet->add('add', l10n('Add a banner'), HEADER_MANAGER_ADMIN . '-add');
-$tabsheet->select($page['tab']);
-$tabsheet->assign();
+if ($page['tab'] == 'album')
+{
+  include(HEADER_MANAGER_PATH . 'admin/album.php');
+}
+else
+{
+  // tabsheet
+  include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');    
+  $tabsheet = new tabsheet();
+  $tabsheet->add('config', l10n('Configuration'), HEADER_MANAGER_ADMIN . '-config');
+  $tabsheet->add('add', l10n('Add a banner'), HEADER_MANAGER_ADMIN . '-add');
+  $tabsheet->select($page['tab']);
+  $tabsheet->assign();
 
-// include page
-include(HEADER_MANAGER_PATH . 'admin/' . $page['tab'] . '.php');
+  // include page
+  include(HEADER_MANAGER_PATH . 'admin/' . $page['tab'] . '.php');
 
-// template
-$template->assign(array(
-  'HEADER_MANAGER_PATH'=> HEADER_MANAGER_PATH,
-  'CONFIG_URL' => HEADER_MANAGER_ADMIN . '-config',
-  'ADD_IMAGE_URL' => HEADER_MANAGER_ADMIN . '-add',
-  ));
+  // template
+  $template->assign(array(
+    'CONFIG_URL' => HEADER_MANAGER_ADMIN . '-config',
+    'ADD_IMAGE_URL' => HEADER_MANAGER_ADMIN . '-add',
+    ));
+}
+
+$template->assign('HEADER_MANAGER_PATH', HEADER_MANAGER_PATH);
+
 $template->assign_var_from_handle('ADMIN_CONTENT', 'header_manager');
 
Index: /extensions/header_manager/admin/album.php
===================================================================
--- /extensions/header_manager/admin/album.php	(revision 16937)
+++ /extensions/header_manager/admin/album.php	(revision 16937)
@@ -0,0 +1,138 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
+// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
+// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
+// +-----------------------------------------------------------------------+
+// | This program is free software; you can redistribute it and/or modify  |
+// | it under the terms of the GNU General Public License as published by  |
+// | the Free Software Foundation                                          |
+// |                                                                       |
+// | This program is distributed in the hope that it will be useful, but   |
+// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
+// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
+// | General Public License for more details.                              |
+// |                                                                       |
+// | You should have received a copy of the GNU General Public License     |
+// | along with this program; if not, write to the Free Software           |
+// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
+// | USA.                                                                  |
+// +-----------------------------------------------------------------------+
+
+if(!defined("PHPWG_ROOT_PATH")) die ("Hacking attempt!");
+
+// +-----------------------------------------------------------------------+
+// | Basic checks                                                          |
+// +-----------------------------------------------------------------------+
+
+check_status(ACCESS_ADMINISTRATOR);
+
+check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
+
+$admin_album_base_url = get_root_url().'admin.php?page=album-'.$_GET['cat_id'];
+$self_url = HEADER_MANAGER_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'];
+
+$query = '
+SELECT *
+  FROM '.CATEGORIES_TABLE.'
+  WHERE id = '.$_GET['cat_id'].'
+;';
+$category = pwg_db_fetch_assoc(pwg_query($query));
+
+if (!isset($category['id']))
+{
+  die("unknown album");
+}
+
+// +-----------------------------------------------------------------------+
+// | Tabs                                                                  |
+// +-----------------------------------------------------------------------+
+
+include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
+$tabsheet = new tabsheet();
+$tabsheet->set_id('album');
+$tabsheet->select('headermanager');
+$tabsheet->assign();
+
+
+$cat_id = $_GET['cat_id'];
+
+
+// +-----------------------------------------------------------------------+
+// | Save Form                                                             |
+// +-----------------------------------------------------------------------+
+if (isset($_POST['save_banner']))
+{
+  if ($_POST['image'] == 'default')
+  {
+    $query = '
+DELETE FROM '.HEADER_MANAGER_TABLE.'
+  WHERE category_id = '.$cat_id.'
+;';
+    pwg_query($query);
+  }
+  else
+  {
+    $query = '
+INSERT INTO '.HEADER_MANAGER_TABLE.'(
+    category_id,
+    image,
+    deep
+  )
+  VALUES (
+    '.$cat_id.',
+    "'.$_POST['image'].'",
+    '.(int)isset($_POST['deep']).'
+  )
+  ON DUPLICATE KEY UPDATE
+    image = "'.$_POST['image'].'",
+    deep = '.(int)isset($_POST['deep']).'
+;';
+    pwg_query($query);
+  }
+}
+
+
+// +-----------------------------------------------------------------------+
+// | Display page                                                          |
+// +-----------------------------------------------------------------------+
+$query = '
+SELECT *
+  FROM '.HEADER_MANAGER_TABLE.'
+  WHERE category_id = '.$cat_id.'
+;';
+$result = pwg_query($query);
+
+if (pwg_db_num_rows($result))
+{
+  $cat_banner = pwg_db_fetch_assoc($result);
+  $banner = get_banner($cat_banner['image']);
+  if ($banner === false)
+  {
+    $cat_banner['image'] = 'default';
+  }
+}
+else
+{
+  $cat_banner = array(
+    'image' => 'default',
+    'deep' => 1,
+    );
+}
+
+$template->assign(array(
+  'banners' => list_banners(true),
+  'BANNER_IMAGE' => $cat_banner['image'],
+  'BANNER_DEEP' => $cat_banner['deep'],
+  'F_ACTION' => $self_url,
+  'CATEGORIES_NAV' => get_cat_display_name_cache(
+    $category['uppercats'],
+    HEADER_MANAGER_ADMIN.'-album&amp;cat_id='
+    ),
+));
+
+$template->set_filename('header_manager', dirname(__FILE__).'/template/album.tpl');
+
+?>
Index: /extensions/header_manager/admin/template/album.tpl
===================================================================
--- /extensions/header_manager/admin/template/album.tpl	(revision 16937)
+++ /extensions/header_manager/admin/template/album.tpl	(revision 16937)
@@ -0,0 +1,30 @@
+{combine_css path=$HEADER_MANAGER_PATH|@cat:"admin/template/style.css"}
+
+<div class="titrePage">
+  <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|@translate} [{'Banner'|@translate}]</h2>
+</div>
+
+<form method="post" action="{$F_ACTION}" class="properties" id="batchManagerGlobal">
+  {if $banners}
+    <div class="banner-radio" style="display:block;">
+      <input type="radio" name="image" value="default" id="banner-default"{if $BANNER_IMAGE=='default'}checked="checked"{/if}>
+      <label for="banner-default"><b>{'Default banner'|@translate}</b></label>
+    </div>
+    {foreach from=$banners item=image}
+    <div class="banner-radio">
+      <span class="actions">
+        <input type="radio" name="image" value="{$image.NAME}" id="banner-{$image.NAME}" {if $BANNER_IMAGE==$image.NAME}checked="checked"{/if}><br>&nbsp;
+      </span>
+      <label for="banner-{$image.NAME}"><img src="{$image.THUMB}" alt="{$image.NAME}"></label> 
+    </div>
+    {/foreach}
+  {else}
+    {'No banner added yet'|@translate}
+  {/if}
+    
+  <p class="actionButtons">
+    <label><input type="checkbox" name="deep" value="1" {if $BANNER_DEEP}checked="checked"{/if}> {'Apply to sub-albums'|@translate}</label>
+    <br><br>
+    <input type="submit" name="save_banner" value="{'Submit'|@translate}" class="submit">
+  </p>
+</form>
Index: /extensions/header_manager/include/header_manager.inc.php
===================================================================
--- /extensions/header_manager/include/header_manager.inc.php	(revision 16936)
+++ /extensions/header_manager/include/header_manager.inc.php	(revision 16937)
@@ -7,16 +7,57 @@
 function header_manager_render($page_banner)
 {
-  global $conf, $user, $template;
+  global $conf, $user, $template, $page;
   
-  if ($conf['header_manager']['image'] == 'random')
+  // search banner for a specific category
+  if (isset($page['category']))
   {
-    $banners = list_banners();
-    if (!count($banners)) return $page_banner;
-    $banner = $banners[ mt_rand(0, count($banners)-1) ];
+    // we use the banner configured for this category
+    // if no banner is configured we use the banner of the first parent category with a "deep" banner
+    // if nothing found we use the default banner
+    $query = '
+SELECT *
+  FROM '.HEADER_MANAGER_TABLE.'
+  WHERE
+    category_id IN ('.$page['category']['uppercats'].')
+    AND (category_id = '.$page['category']['id'].' OR deep = 1)
+;';
+    $cat_banners = hash_from_query($query, 'category_id');
+    
+    if (count($cat_banners))
+    {
+      function uppercats_sort($a, $b)
+      {
+        global $page;
+        $ids = explode(',', $page['category']['uppercats']);
+        return array_search($a['category_id'], $ids) < array_search($b['category_id'], $ids);
+      }
+      usort($cat_banners, 'uppercats_sort');
+      
+      foreach ($cat_banners as $cat_banner)
+      {
+        $cat_banner = get_banner($cat_banner['image']);
+        if ($cat_banner !== false)
+        {
+          $banner = $cat_banner;
+          break;
+        }
+      }
+    }
   }
-  else
+  
+  // use default banner
+  if (!isset($banner))
   {
-    $banner = get_banner($conf['header_manager']['image']);
-    if (!file_exists($banner['PATH'])) return $page_banner;
+    if ($conf['header_manager']['image'] == 'random')
+    {
+      $banners = list_banners();
+      if (!count($banners)) return $page_banner;
+      $banner = $banners[ mt_rand(0, count($banners)-1) ];
+    }
+    else
+    {
+      $banner = get_banner($conf['header_manager']['image']);
+      if ($banner === false) return $page_banner;
+    }
   }
   
@@ -75,3 +116,21 @@
 }
 
+/**
+ * tab on album edition page
+ */
+function header_manager_tab($sheets, $id)
+{
+  if ($id == 'album')
+  {
+    load_language('plugin.lang', HEADER_MANAGER_PATH);
+    
+    $sheets['headermanager'] = array(
+      'caption' => l10n('Banner'),
+      'url' => HEADER_MANAGER_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'],
+      );
+  }
+  
+  return $sheets;
+}
+
 ?>
Index: /extensions/header_manager/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/header_manager/language/en_UK/plugin.lang.php	(revision 16936)
+++ /extensions/header_manager/language/en_UK/plugin.lang.php	(revision 16937)
@@ -31,3 +31,5 @@
 $lang['Add a banner'] = 'Add a banner';
 
+$lang['Default banner'] = 'Default banner';
+
 ?>
Index: /extensions/header_manager/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/header_manager/language/fr_FR/plugin.lang.php	(revision 16936)
+++ /extensions/header_manager/language/fr_FR/plugin.lang.php	(revision 16937)
@@ -31,3 +31,5 @@
 $lang['Add a banner'] = 'Ajouter une bannière';
 
+$lang['Default banner'] = 'Bannière par défaut';
+
 ?>
Index: /extensions/header_manager/main.inc.php
===================================================================
--- /extensions/header_manager/main.inc.php	(revision 16936)
+++ /extensions/header_manager/main.inc.php	(revision 16937)
@@ -11,7 +11,9 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
+global $prefixeTable;
 define('HEADER_MANAGER_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
 define('HEADER_MANAGER_ADMIN', get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
 define('HEADER_MANAGER_DIR', PWG_LOCAL_DIR . 'banners/');
+define('HEADER_MANAGER_TABLE', $prefixeTable . 'category_banner');
 
 add_event_handler('init', 'header_manager_init');
@@ -31,4 +33,5 @@
   if (defined('IN_ADMIN'))
   {
+    add_event_handler('tabsheet_before_select', 'header_manager_tab', EVENT_HANDLER_PRIORITY_NEUTRAL, 2);
     add_event_handler('get_admin_plugin_menu_links', 'header_manager_admin_menu');
   }
Index: /extensions/header_manager/maintain.inc.php
===================================================================
--- /extensions/header_manager/maintain.inc.php	(revision 16936)
+++ /extensions/header_manager/maintain.inc.php	(revision 16937)
@@ -2,5 +2,5 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-define('HEADER_MANAGER_DIR', PWG_LOCAL_DIR . 'banners/');
+define('header_dir', PWG_LOCAL_DIR . 'banners/');
 
 define(
@@ -17,11 +17,22 @@
 function plugin_install() 
 {
+  global $prefixeTable;
+  
+	pwg_query(
+'CREATE TABLE IF NOT EXISTS `' .$prefixeTable . 'category_banner` (
+  `category_id` smallint(5) unsigned NOT NULL,
+  `image` varchar(255) NOT NULL,
+  `deep` tinyint(1) DEFAULT 1,
+  PRIMARY KEY (`category_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8
+;');
+
   conf_update_param('header_manager', header_manager_default_config);
-  mkdir(HEADER_MANAGER_DIR, 0755);
+  mkdir(header_dir, 0755);
 }
 
 function plugin_activate()
 {
-  global $conf;
+  global $conf, $prefixeTable;
 
   if (empty($conf['header_manager']))
@@ -29,12 +40,24 @@
     conf_update_param('header_manager', header_manager_default_config);
   }
-  if (!file_exists(HEADER_MANAGER_DIR)) 
+  if (!file_exists(header_dir)) 
   {
-    mkdir(HEADER_MANAGER_DIR, 0755);
+    mkdir(header_dir, 0755);
   }
+  
+  pwg_query(
+'CREATE TABLE IF NOT EXISTS `' .$prefixeTable . 'category_banner` (
+  `category_id` smallint(5) unsigned NOT NULL,
+  `image` varchar(255) NOT NULL,
+  `deep` tinyint(1) DEFAULT 1,
+  PRIMARY KEY (`category_id`)
+) ENGINE=MyISAM DEFAULT CHARSET=utf8
+;');
 }
 
 function plugin_uninstall() 
 {
+  global $prefixeTable;
+  
+  pwg_query('DROP TABLE `' .$prefixeTable . 'category_banner`;');
   pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "header_manager" LIMIT 1;');
 }
