Index: extensions/header_manager/admin.php
===================================================================
--- extensions/header_manager/admin.php	(revision 15854)
+++ extensions/header_manager/admin.php	(revision 15854)
@@ -0,0 +1,34 @@
+<?php
+if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
+
+global $template, $page;
+load_language('plugin.lang', HEADER_MANAGER_PATH);
+
+if (!file_exists(HEADER_MANAGER_DIR)) 
+{
+  mkdir(HEADER_MANAGER_DIR, 0755);
+}
+
+
+// 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();
+
+// 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->assign_var_from_handle('ADMIN_CONTENT', 'header_manager');
+
+?>
Index: extensions/header_manager/admin/add.php
===================================================================
--- extensions/header_manager/admin/add.php	(revision 15854)
+++ extensions/header_manager/admin/add.php	(revision 15854)
@@ -0,0 +1,143 @@
+<?php
+if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
+
+// cancel crop
+if (isset($_POST['cancel_crop']))
+{
+  $banner = get_banner($_POST['picture_file']);
+  @unlink($banner['PATH']);
+  @unlink($banner['THUMB']);
+}
+// apply crop and redirect
+else if (isset($_POST['submit_crop']))
+{
+  include_once(HEADER_MANAGER_PATH . 'include/banner.class.php');
+  
+  $banner = get_banner($_POST['picture_file']);
+  $img = new banner_image($banner['PATH']);
+  $crop = get_crop_display(array('width'=>$img->get_width(), 'height'=>$img->get_height()));
+  
+  $img->banner_resize(
+    $banner['PATH'],
+    $_POST['x'],
+    $_POST['y'], 
+    $_POST['x2'],
+    $_POST['y2'],
+    $crop['display_width'],
+    $crop['display_height']
+    );
+  $img->destroy();
+  
+  $img = new banner_image($banner['PATH']);
+  $img->pwg_resize(
+    $banner['THUMB'],
+    230, 70, 80,
+    false, true, true, false
+    );
+  $img->destroy();
+  
+  $_SESSION['page_infos'][] = l10n('Banner added');
+  pwg_set_session_var('added_banner', $_POST['picture_file']);
+  
+  redirect(HEADER_MANAGER_ADMIN);
+}
+
+// copy picture from gallery
+if (isset($_POST['upload_gallery_image']))
+{
+  $query = '
+SELECT
+    file,
+    path, 
+    coi, 
+    width, 
+    height
+  FROM '.IMAGES_TABLE.'
+  WHERE id = '. (int)@$_POST['picture_id'] .'
+;';
+  $result = pwg_query($query);
+  
+  if (!pwg_db_num_rows($result))
+  {
+    array_push($page['errors'], l10n('Unknown picture id'));
+  }
+  else
+  {
+    $picture = pwg_db_fetch_assoc($result);
+    
+    copy(PHPWG_ROOT_PATH . $picture['path'], HEADER_MANAGER_DIR . $picture['file']);
+    
+    define('IN_CROP', true);
+  }
+}
+// upload new picture
+else if (isset($_POST['upload_new_image']))
+{
+  $file = $_FILES['new_image'];
+  
+  if ($file['error'] > 0) 
+  {
+    array_push($page['errors'], l10n('Unknown upload error'));
+  }
+  else if ( !in_array($file['type'], array('image/jpeg','image/png','image/gif')) )
+  {
+    array_push($page['errors'], l10n('Incorrect file type,').' '.sprintf(l10n('Allowed file types: %s.'), 'jpg, png, gif'));
+  }
+  
+  if (count($page['errors']) == 0)
+  {
+    move_uploaded_file($file['tmp_name'], HEADER_MANAGER_DIR . $file['name']);
+    
+    list($width, $height) = getimagesize(HEADER_MANAGER_DIR . $file['name']);
+    $picture = array(
+      'file' => $file['name'],
+      'width' => $width,
+      'height' => $height,
+      );
+      
+    define('IN_CROP', true);
+  }
+}
+
+// croping template
+if (defined('IN_CROP'))
+{
+  // save default size configuration
+  $conf['header_manager']['width'] = intval($_POST['width']);
+  $conf['header_manager']['height'] = intval($_POST['height']);
+  conf_update_param('header_manager', serialize($conf['header_manager']));
+    
+  $picture['banner_src'] = HEADER_MANAGER_DIR . $picture['file'];
+  
+  $template->assign(array(
+    'IN_CROP' => true,
+    'picture' => $picture,
+    'crop' => get_crop_display($picture),
+    ));
+}
+// upload form
+else
+{
+  include_once(PHPWG_ROOT_PATH . 'admin/include/functions_upload.inc.php');
+  
+  $upload_max_filesize = min(
+    get_ini_size('upload_max_filesize'),
+    get_ini_size('post_max_size')
+    );
+    
+  $upload_max_filesize_shorthand = 
+    ($upload_max_filesize == get_ini_size('upload_max_filesize')) ?
+    get_ini_size('upload_max_filesize', false) :
+    get_ini_size('post_max_filesize', false);
+    
+  $template->assign(array(
+    'upload_max_filesize' => $upload_max_filesize,
+    'upload_max_filesize_shorthand' => $upload_max_filesize_shorthand,
+    'BANNER_WIDTH' => $conf['header_manager']['width'],
+    'BANNER_HEIGHT' => $conf['header_manager']['height'],
+    ));
+}
+
+$template->set_filename('header_manager', dirname(__FILE__).'/template/add.tpl');
+
+?>
Index: extensions/header_manager/admin/config.php
===================================================================
--- extensions/header_manager/admin/config.php	(revision 15854)
+++ extensions/header_manager/admin/config.php	(revision 15854)
@@ -0,0 +1,65 @@
+<?php
+if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
+
+// change banner to last uploaded
+if ( pwg_get_session_var('added_banner')!==null and $conf['header_manager']['image']!='random' )
+{
+  $conf['header_manager']['image'] = pwg_get_session_var('added_banner');
+  conf_update_param('header_manager', serialize($conf['header_manager']));
+  pwg_unset_session_var('added_banner');
+}
+
+// save config
+if (isset($_POST['save_config']))
+{
+  if ($_POST['display'] == 'with_text')
+  {
+    conf_update_param('page_banner', $_POST['conf_page_banner']);
+    $conf['page_banner'] = $_POST['conf_page_banner'];
+  }
+  
+  $conf['header_manager']['image'] = $_POST['image'];
+  $conf['header_manager']['display'] = $_POST['display'];
+  conf_update_param('header_manager', serialize($conf['header_manager']));
+  
+  array_push($page['infos'], l10n('Information data registered in database'));
+}
+
+// delete banner
+if (isset($_GET['delete_banner']))
+{
+  $banner = get_banner($_GET['delete_banner']);
+  if ( $banner !== false or @unlink($banner['PATH']) )
+  {
+    @unlink($banner['THUMB']);
+    
+    if ($conf['header_manager']['image'] == $_GET['delete_banner'])
+    {
+      $conf['header_manager']['image'] = 'random';
+      conf_update_param('header_manager', serialize($conf['header_manager']));
+    }
+    
+    array_push($page['infos'], l10n('Banner deleted'));
+  }
+  else
+  {
+    array_push($page['warnings'], l10n('File/directory read error').' : ' . HEADER_MANAGER_DIR . $_GET['delete_banner']);
+  }
+}
+
+// config template
+if (get_banner($conf['header_manager']['image']) === false)
+{
+  $conf['header_manager']['image'] = 'random';
+}
+
+$template->assign(array(
+  'banners' => list_banners(true),
+  'CONF_PAGE_BANNER' => htmlspecialchars($conf['page_banner']),
+  'BANNER_IMAGE' => $conf['header_manager']['image'],
+  'BANNER_DISPLAY' => $conf['header_manager']['display'],
+  ));
+
+$template->set_filename('header_manager', dirname(__FILE__).'/template/config.tpl');
+
+?>
Index: extensions/header_manager/admin/index.php
===================================================================
--- extensions/header_manager/admin/index.php	(revision 15854)
+++ extensions/header_manager/admin/index.php	(revision 15854)
@@ -0,0 +1,30 @@
+<?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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/header_manager/admin/template/add.tpl
===================================================================
--- extensions/header_manager/admin/template/add.tpl	(revision 15854)
+++ extensions/header_manager/admin/template/add.tpl	(revision 15854)
@@ -0,0 +1,114 @@
+{combine_css path=$HEADER_MANAGER_PATH|@cat:"admin/template/style.css"}
+
+<div class="titrePage" style="float:right;margin-top:-2em;">
+	<h2>Header Manager</h2>
+</div>
+
+{if $IN_CROP}
+{combine_css path="themes/default/js/plugins/jquery.Jcrop.css"}
+{combine_script id='jquery.jcrop' load='footer' require='jquery' path='themes/default/js/plugins/jquery.Jcrop.min.js'}
+
+{footer_script require="jquery"}
+var jcrop_api;
+
+jQuery("#jcrop").Jcrop({ldelim}
+    boxWidth: {$crop.display_width}, 
+    boxHeight: {$crop.display_height},
+    setSelect: [{$crop.l}, {$crop.t}, {$crop.r}, {$crop.b}],
+    onChange: jOnChange,
+    onRelease: jOnRelease
+	},
+  function(){ldelim}
+    jcrop_api = this;
+  });
+  
+function jOnChange(sel) {ldelim}
+	jQuery("input[name='x']").val(sel.x);
+	jQuery("input[name='y']").val(sel.y);
+	jQuery("input[name='x2']").val(sel.x2);
+	jQuery("input[name='y2']").val(sel.y2);
+  
+  jQuery("#width").html(sel.x2-sel.x);
+  jQuery("#height").html(sel.y2-sel.y);
+}
+  
+function jOnRelease() {ldelim}
+	jcrop_api.setSelect([{$crop.l}, {$crop.t}, {$crop.r}, {$crop.b}]);
+}
+{/footer_script}
+
+<form method="post" action="">
+<fieldset>
+  <legend>{'Crop banner image'|@translate}</legend>
+  {'Choose the part of the image you want to use as your header.'|@translate}<br>
+  
+  <img id="jcrop" src="{$picture.banner_src}" width="{$crop.display_width}" height="{$crop.display_height}">
+  
+  <ul>
+    <li><b>{'Width'|@translate}:</b> <span id="width"></span>px</li>
+    <li><b>{'Height'|@translate}:</b> <span id="height"></span>px</li>
+  </ul>
+  
+  <input type="hidden" name="x">
+  <input type="hidden" name="y">
+  <input type="hidden" name="x2">
+  <input type="hidden" name="y2">
+  <input type="hidden" name="picture_file" value="{$picture.file}">
+  
+  <input type="submit" name="submit_crop" value="{'Submit'|@translate}">
+  <input type="submit" name="cancel_crop" value="{'Cancel'|@translate}">
+</fieldset>
+</form>
+
+{else}
+{footer_script require="jquery"}
+jQuery(".showInfo").tipTip({ldelim}
+    delay: 0,
+    fadeIn: 200,
+    fadeOut: 200,
+    maxWidth: '300px',
+  });
+{/footer_script}
+
+<form method="post" action="" ENCTYPE="multipart/form-data">
+  <fieldset>
+    <legend>{'Default banner size'|@translate}</legend>
+    
+    <label>
+      {'Width'|@translate}:
+      <input type="text" name="width" size="4" value="{$BANNER_WIDTH}">px
+    </label>
+    <br>
+    <br>
+    <label>
+      {'Height'|@translate}:
+      <input type="text" name="height" size="4" value="{$BANNER_HEIGHT}">px
+    </label>
+    <br>
+    <br>
+    <i>{'For MontBlancXL and BlancMontXL, advised size is 900&times;190.'|@translate}</i>
+  </fieldset>
+  
+  <fieldset>
+    <legend>{'Select an image'|@translate}</legend>
+    {'You can upload a custom header image or select one from your gallery. On the next screen you will be able to crop the image.'|@translate}
+    <br><br>
+    
+    <b>{'Choose an image from your computer'|@translate}</b>
+    <blockquote>
+      {'Maximum file size: %sB.'|@translate|@sprintf:$upload_max_filesize_shorthand} {'Allowed file types: %s.'|@translate|@sprintf:'jpg, png, gif'}<br>
+      <input type="file" name="new_image">
+      <input type="hidden" name="MAX_FILE_SIZE" value="{$upload_max_filesize}">
+      <input type="submit" name="upload_new_image" value="{'Upload'|@translate}" class="submit">
+    </blockquote>
+    
+    <b>{'or choose a picture from the gallery'|@translate}</b>
+    <blockquote>
+      {'Picture id.'|@translate} <a class="showInfo" title="{'The numeric identifier can be found on the picture edition page, near the thumbnail.'|@translate}">i</a>
+      <input type="text" name="picture_id" size="5">
+      <input type="submit" name="upload_gallery_image" value="{'Use'|@translate}" class="submit">
+    </blockquote>
+  </fieldset>
+</form>
+
+{/if}
Index: extensions/header_manager/admin/template/config.tpl
===================================================================
--- extensions/header_manager/admin/template/config.tpl	(revision 15854)
+++ extensions/header_manager/admin/template/config.tpl	(revision 15854)
@@ -0,0 +1,59 @@
+{combine_css path=$HEADER_MANAGER_PATH|@cat:"admin/template/style.css"}
+
+{footer_script require="jquery"}{literal}
+jQuery("input[name='display']").change(function() {
+  jQuery(".display-help:not(#"+ jQuery(this).val() +")").slideUp();
+  jQuery("#"+ jQuery(this).val()).slideDown();
+});
+{/literal}{/footer_script}
+
+<div class="titrePage" style="float:right;margin-top:-2em;">
+	<h2>Header Manager</h2>
+</div>
+
+<form method="post" action="{$CONFIG_URL}" class="properties">
+  <fieldset>
+    <legend>{'Display'|@translate}</legend>
+    
+    <label><input type="radio" name="display" value="image_only" {if $BANNER_DISPLAY=='image_only'}checked="checked"{/if}> {'Image only'|@translate}</label><br>
+    
+    <label><input type="radio" name="display" value="with_title" {if $BANNER_DISPLAY=='with_title'}checked="checked"{/if}> {'Gallery title above image'|@translate}</label><br>
+    <div class="display-help" id="with_title" {if $BANNER_DISPLAY!='with_title'}style="display:none;"{/if}>
+      <i>{'You can customize the display by adding CSS rules to'|@translate}</i>
+      <span style="font-family:monospace;font-size:14px;color:#000;background:#eee;padding:0 2px;">#<span style="color:#09f;font-weight:bold;">theHeader</span> <span style="color:#00f;">div</span>.<span style="color:#f00;">banner</span></span>
+    </div>
+    
+    <label><input type="radio" name="display" value="with_text" {if $BANNER_DISPLAY=='with_text'}checked="checked"{/if}> {'With text'|@translate}</label><br>
+    <div class="display-help" id="with_text" {if $BANNER_DISPLAY!='with_text'}style="display:none;"{/if}>
+      <textarea rows="5" cols="50" class="description" name="conf_page_banner">{$CONF_PAGE_BANNER}</textarea><br>
+      <i>{'Put <b>%header_manager%</b> where you want to display the image.'|@translate}</i>
+    </div>
+  </fieldset>
+  
+  <fieldset id="batchManagerGlobal">
+    <legend>{'Banner'|@translate}</legend>
+    
+  {if $banners}
+    <div class="banner-radio" style="display:block;">
+      <input type="radio" name="image" value="random" id="banner-random"{if $BANNER_IMAGE=='random'}checked="checked"{/if}>
+      <label for="banner-random"><b>{'Random'|@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>
+        <a href="{$CONFIG_URL}&amp;delete_banner={$image.NAME}" class="removeFilter" title="{'Delete'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');"><span>[x]</span></a>
+      </span>
+      <label for="banner-{$image.NAME}"><img src="{$image.THUMB}" alt="{$image.NAME}"></label> 
+    </div>
+    {/foreach}
+  {else}
+    {'No banner added yet'|@translate}
+  {/if}
+    
+    <br><br>
+    <a href="{$ADD_IMAGE_URL}">{'Add a banner'|@translate}</a>
+  </fieldset>
+
+  <p><input type="submit" name="save_config" value="{'Submit'|@translate}" class="submit"></p>
+</form>
Index: extensions/header_manager/admin/template/index.php
===================================================================
--- extensions/header_manager/admin/template/index.php	(revision 15854)
+++ extensions/header_manager/admin/template/index.php	(revision 15854)
@@ -0,0 +1,30 @@
+<?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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/header_manager/admin/template/style.css
===================================================================
--- extensions/header_manager/admin/template/style.css	(revision 15854)
+++ extensions/header_manager/admin/template/style.css	(revision 15854)
@@ -0,0 +1,16 @@
+.banner-radio {
+  display:inline-block;
+  margin:5px 0 0 20px;
+}
+.banner-radio .actions {
+  display:inline-block;
+  vertical-align:80%;
+  text-align:center;
+}
+.showInfo {
+  position:static;
+  display:inline-block;
+  padding:1px 6px;
+  width:auto;
+  font-size:0.8em;
+}
Index: extensions/header_manager/include/banner.class.php
===================================================================
--- extensions/header_manager/include/banner.class.php	(revision 15854)
+++ extensions/header_manager/include/banner.class.php	(revision 15854)
@@ -0,0 +1,72 @@
+<?php
+if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
+
+include_once(PHPWG_ROOT_PATH . 'admin/include/image.class.php');
+
+/**
+ * class derivated from pwg_image, with special function for banner creation
+ */
+class banner_image extends pwg_image
+{
+  function banner_resize($destination_filepath, $x, $y, $x2, $y2, $width, $height)
+  {
+    global $conf;
+    $starttime = get_moment();
+
+    // width/height
+    $source_width  = $this->image->get_width();
+    $source_height = $this->image->get_height();
+
+    $resize_dimensions = array(
+      'width' => $width,
+      'height'=> $height,
+      'crop' => array(
+        'width' => $x2-$x,
+        'height' => $y2-$y,
+        'x' => $x,
+        'y' => $y,
+        ),
+      );
+    
+    // maybe resizing/croping is useless ?
+    if ( $resize_dimensions['crop']['width'] == $source_width and $resize_dimensions['crop']['height'] == $source_height )
+    {
+      // the image doesn't need any resize! We just copy it to the destination
+      copy($this->source_filepath, $destination_filepath);
+      return $this->get_resize_result($destination_filepath, $resize_dimensions['width'], $resize_dimensions['height'], $starttime);
+    }
+    
+    $this->image->set_compression_quality(90);
+    $this->image->strip();
+    
+    // resize to what is displayed on crop screen
+    if ($source_width > $conf['header_manager']['width'])
+    {
+      $this->image->resize($resize_dimensions['width'], $source_height*$resize_dimensions['width']/$source_width);
+    }
+    
+    // crop
+    $this->image->crop($resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $resize_dimensions['crop']['x'], $resize_dimensions['crop']['y']);
+    
+    // save
+    $this->image->write($destination_filepath);
+
+    // everything should be OK if we are here!
+    return $this->get_resize_result($destination_filepath, $resize_dimensions['crop']['width'], $resize_dimensions['crop']['height'], $starttime);
+  }
+  
+  private function get_resize_result($destination_filepath, $width, $height, $time=null)
+  {
+    return array(
+      'source'      => $this->source_filepath,
+      'destination' => $destination_filepath,
+      'width'       => $width,
+      'height'      => $height,
+      'size'        => floor(filesize($destination_filepath) / 1024).' KB',
+      'time'        => $time ? number_format((get_moment() - $time) * 1000, 2, '.', ' ').' ms' : null,
+      'library'     => $this->library,
+    );
+  }
+}
+
+?>
Index: extensions/header_manager/include/functions.inc.php
===================================================================
--- extensions/header_manager/include/functions.inc.php	(revision 15854)
+++ extensions/header_manager/include/functions.inc.php	(revision 15854)
@@ -0,0 +1,113 @@
+<?php
+if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
+
+/**
+ * give a list of available banners
+ * @param: bool delete_orphans (from unachieved cropping process)
+ */
+function list_banners($delete_orphans=false)
+{
+  $dir = scandir(HEADER_MANAGER_DIR);
+  $banners = array();
+  
+  foreach ($dir as $file)
+  {
+    if ( in_array($file, array('.','..','index.php','.svn')) ) continue;
+    if ( !in_array(strtolower(get_extension($file)), array('jpg','jpeg','png','gif')) ) continue;
+    if ( strpos($file, '-thumbnail')!==false ) continue;
+
+    array_push($banners, get_banner($file));
+    
+    if ( $delete_orphans and !file_exists($banners[ count($banners)-1 ]['THUMB']) )
+    {
+      @unlink($banners[ count($banners)-1 ]['PATH']);
+      array_pop($banners);
+    }
+  }
+  
+  return $banners;
+}
+
+/**
+ * get full size and thumbnail urls and size for a banner
+ * @param: string filename
+ */
+function get_banner($file)
+{
+  if (file_exists(HEADER_MANAGER_DIR . $file))
+  {
+    return array(
+      'NAME' => $file,
+      'PATH' => HEADER_MANAGER_DIR . $file,
+      'THUMB' => HEADER_MANAGER_DIR . get_filename_wo_extension($file) . '-thumbnail.'. get_extension($file),
+      'SIZE' => getimagesize(HEADER_MANAGER_DIR . $file),
+      );
+  }
+  else
+  {
+    return false;
+  }
+}
+
+/**
+ * get properties of the jCrop window
+ * @param: array picture(width, height[, coi])
+ * @return: array crop(display_width, display_height, l, r, t, b, coi(x, y))
+ */
+function get_crop_display($picture)
+{
+  global $conf;
+  
+  // find coi
+  if (!empty($picture['coi']))
+  {
+    $picture['coi'] = array(
+      'l' => char_to_fraction($picture['coi'][0])*$picture['width'],
+      't' => char_to_fraction($picture['coi'][1])*$picture['height'],
+      'r' => char_to_fraction($picture['coi'][2])*$picture['width'],
+      'b' => char_to_fraction($picture['coi'][3])*$picture['height'],
+      );
+  }
+  else
+  {
+    $picture['coi'] = array(
+      'l' => 0,
+      't' => 0,
+      'r' => $picture['width'],
+      'b' => $picture['height'],
+      );
+  }
+  $crop['coi']['x'] = ($picture['coi']['r']+$picture['coi']['l'])/2;
+  $crop['coi']['y'] = ($picture['coi']['b']+$picture['coi']['t'])/2;
+  
+  // define default crop frame
+  if ($picture['width'] > $conf['header_manager']['width'])
+  {
+    $crop['display_width'] = $conf['header_manager']['width'];
+    $crop['display_height'] = round($picture['height']*$crop['display_width']/$picture['width']);
+    
+    $crop['coi']['x'] = round($crop['coi']['x']*$crop['display_width']/$picture['width']);
+    $crop['coi']['y'] = round($crop['coi']['y']*$crop['display_height']/$picture['height']);
+    
+    $crop['l'] = 0;
+    $crop['r'] = $conf['header_manager']['width'];
+    $crop['t'] = max(0, $crop['coi']['y']-$conf['header_manager']['height']/2);
+    $crop['b'] = min($crop['display_height'], $crop['t']+$conf['header_manager']['height']);
+  }
+  else
+  {
+    $crop['display_width'] = $picture['width'];
+    $crop['display_height'] = $picture['height'];
+    
+    $adapted_crop_height = round($conf['header_manager']['height']*$picture['width']/$conf['header_manager']['width']);
+    
+    $crop['l'] = 0;
+    $crop['r'] = $picture['width'];
+    $crop['t'] = max(0, $crop['coi']['y']-$adapted_crop_height/2);
+    $crop['b'] = min($crop['display_height'], $crop['t']+$adapted_crop_height);
+  }
+  
+  return $crop;
+}
+
+?>
Index: extensions/header_manager/include/header_manager.inc.php
===================================================================
--- extensions/header_manager/include/header_manager.inc.php	(revision 15854)
+++ extensions/header_manager/include/header_manager.inc.php	(revision 15854)
@@ -0,0 +1,77 @@
+<?php
+if (!defined('HEADER_MANAGER_PATH')) die('Hacking attempt!');
+
+/**
+ * add personal banner to page banner
+ */
+function header_manager_render($page_banner)
+{
+  global $conf, $user, $template;
+  
+  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 (!file_exists($banner['PATH'])) return $page_banner;
+  }
+  
+  // for MontBlancXL and BlancMontXL the banner is displayed as background of the header
+  if ( in_array($user['theme'], array('blancmontxl','montblancxl')) )
+  {
+    $template->append('head_elements',
+'<style type="text/css">
+#theHeader { background: transparent url('.$banner['PATH'].') center bottom no-repeat; }
+</style>'
+      );
+
+    if ($conf['header_manager']['display'] == 'image_only')
+    {
+      $page_banner = null;
+    }
+    else
+    {
+      $page_banner = str_replace('%header_manager%', null, $page_banner);
+    }
+  }
+  // no support for Kardon (not enough space)
+  else if ($user['theme'] != 'kardon')
+  {
+    $template->append('head_elements',
+'<style type="text/css">
+#theHeader div.banner { background:transparent url('.$banner['PATH'].') center center no-repeat;height:'.$banner['SIZE'][1].'px;line-height:'.($banner['SIZE'][1]-12).'px;font-size:2.5em;color:#fff;text-shadow:0 0 5px #000; }
+</style>'
+      );
+    
+    $banner_img = '<div class="banner">'.($conf['header_manager']['display']=='with_title' ? $conf['gallery_title'] : '&nbsp;').'</div>';
+    
+    if ($conf['header_manager']['display'] == 'with_text')
+    {
+      $page_banner = str_replace('%header_manager%', $banner_img, $page_banner);
+    }
+    else
+    {
+      $page_banner = '<a href="'.get_gallery_home_url().'">'.$banner_img.'</a>';
+    }
+  }
+
+  return $page_banner;
+}
+
+/**
+ * Header Manager admin link
+ */
+function header_manager_admin_menu($menu) 
+{
+  array_push($menu, array(
+    'NAME' => 'Header Manager',
+    'URL' => HEADER_MANAGER_ADMIN,
+  ));
+  return $menu;
+}
+
+?>
Index: extensions/header_manager/include/index.php
===================================================================
--- extensions/header_manager/include/index.php	(revision 15854)
+++ extensions/header_manager/include/index.php	(revision 15854)
@@ -0,0 +1,30 @@
+<?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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/header_manager/index.php
===================================================================
--- extensions/header_manager/index.php	(revision 15854)
+++ extensions/header_manager/index.php	(revision 15854)
@@ -0,0 +1,30 @@
+<?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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/header_manager/language/en_UK/description.txt
===================================================================
--- extensions/header_manager/language/en_UK/description.txt	(revision 15854)
+++ extensions/header_manager/language/en_UK/description.txt	(revision 15854)
@@ -0,0 +1,1 @@
+Header Manager allows to simply manage gallery banners. You can upload a picture from your computer or use a picture already in the gallery.
Index: extensions/header_manager/language/en_UK/index.php
===================================================================
--- extensions/header_manager/language/en_UK/index.php	(revision 15854)
+++ extensions/header_manager/language/en_UK/index.php	(revision 15854)
@@ -0,0 +1,30 @@
+<?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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/header_manager/language/en_UK/plugin.lang.php
===================================================================
--- extensions/header_manager/language/en_UK/plugin.lang.php	(revision 15854)
+++ extensions/header_manager/language/en_UK/plugin.lang.php	(revision 15854)
@@ -0,0 +1,33 @@
+<?php
+
+// crop page
+$lang['Crop banner image'] = 'Crop banner image';
+$lang['Choose the part of the image you want to use as your header.'] = 'Choose the part of the image you want to use as your header.';
+$lang['Banner added'] = 'Banner added';
+$lang['Incorrect file type,'] = 'Incorrect file type,';
+
+// upload page
+$lang['Default banner size'] = 'Default banner size';
+$lang['Select an image'] = 'Select an image';
+$lang['You can upload a custom header image or select one from your gallery. On the next screen you will be able to crop the image.'] = 'You can upload a custom header image or select one from your gallery. On the next screen you will be able to crop the image.';
+$lang['Choose an image from your computer'] = 'Choose an image from your computer';
+$lang['or choose a picture from the gallery'] = 'or choose a picture from the gallery';
+$lang['Use'] = 'Use';
+$lang['Banner deleted'] = 'Banner deleted';
+$lang['Unknown picture id'] = 'Unknown picture id';
+$lang['Picture id.'] = 'Picture id.';
+$lang['The numeric identifier can be found on the picture edition page, near the thumbnail.'] = 'The numeric identifier can be found on the picture edition page, near the thumbnail.';
+$lang['For MontBlancXL and BlancMontXL, advised size is 900&times;190.'] = 'For MontBlancXL and BlancMontXL, advised size is 900&times;190.';
+
+// config page
+$lang['Image only'] = 'Image only';
+$lang['Gallery title above image'] = 'Gallery title above image';
+$lang['With text'] = 'With text';
+$lang['You can customize the display by adding CSS rules to'] = 'You can customize the display by adding CSS rules to';
+$lang['Put <b>%header_manager%</b> where you want to display the image.'] = 'Put <b>%header_manager%</b> where you want to display the image.';
+$lang['Banner'] = 'Banner';
+$lang['Random'] = 'Random';
+$lang['No banner added yet'] = 'No banner added yet';
+$lang['Add a banner'] = 'Add a banner';
+
+?>
Index: extensions/header_manager/language/fr_FR/description.txt
===================================================================
--- extensions/header_manager/language/fr_FR/description.txt	(revision 15854)
+++ extensions/header_manager/language/fr_FR/description.txt	(revision 15854)
@@ -0,0 +1,1 @@
+Header Manager permet de gérer facilement la bannière de la galerie. Vous pouvez télécharger une image depuis votre ordinateur ou utiliser une photo déjà présente sur la galerie.
Index: extensions/header_manager/language/fr_FR/index.php
===================================================================
--- extensions/header_manager/language/fr_FR/index.php	(revision 15854)
+++ extensions/header_manager/language/fr_FR/index.php	(revision 15854)
@@ -0,0 +1,30 @@
+<?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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/header_manager/language/fr_FR/plugin.lang.php
===================================================================
--- extensions/header_manager/language/fr_FR/plugin.lang.php	(revision 15854)
+++ extensions/header_manager/language/fr_FR/plugin.lang.php	(revision 15854)
@@ -0,0 +1,33 @@
+<?php
+
+// crop page
+$lang['Crop banner image'] = 'Recadrer la bannière';
+$lang['Choose the part of the image you want to use as your header.'] = 'Choississez la zone de l\'image à utiliser comme bannière.';
+$lang['Banner added'] = 'Bannière ajoutée';
+$lang['Incorrect file type,'] = 'Type de fichier incorrect';
+
+// upload page
+$lang['Default banner size'] = 'Taille par défaut de la banière';
+$lang['Select an image'] = 'Sélectionner une image';
+$lang['You can upload a custom header image or select one from your gallery. On the next screen you will be able to crop the image.'] = 'Vous pouvez télécharger une bannière personnalisée ou utiliser une photo de votre galerie. Sur l\'écran suivant il vous sera proposé de recadrer votre image.';
+$lang['Choose an image from your computer'] = 'Choisir une image stockée sur l\'ordinateur';
+$lang['or choose a picture from the gallery'] = 'ou choisir une photo de la galerie';
+$lang['Use'] = 'Utiliser';
+$lang['Banner deleted'] = 'Bannière supprimée';
+$lang['Unknown picture id'] = 'Identifiant inconnu';
+$lang['Picture id.'] = 'Id. de la photo';
+$lang['The numeric identifier can be found on the picture edition page, near the thumbnail.'] = 'L\'identifiant numérique peut être trouvé sur la page d\'édition, à côté de la miniature.';
+$lang['For MontBlancXL and BlancMontXL, advised size is 900&times;190.'] = 'Pour les thèmes MontBlancXL et BlancMontXL, la taille conseillée est de 900&times;190.';
+
+// config page
+$lang['Image only'] = 'Image seule';
+$lang['Gallery title above image'] = 'Titre de la gallerie au dessus de l\'image';
+$lang['With text'] = 'Image et texte';
+$lang['You can customize the display by adding CSS rules to'] = 'Vous pouvez personnaliser l\'affichage en ajoutant des règles CSS à';
+$lang['Put <b>%header_manager%</b> where you want to display the image.'] = 'Ajoutez <b>%header_manager%</b> à l\'endroit où vous voulez voir apparaître votre image.';
+$lang['Banner'] = 'Bannière';
+$lang['Random'] = 'Aléatoire';
+$lang['No banner added yet'] = 'Aucune bannière ajoutée';
+$lang['Add a banner'] = 'Ajouter une bannière';
+
+?>
Index: extensions/header_manager/language/index.php
===================================================================
--- extensions/header_manager/language/index.php	(revision 15854)
+++ extensions/header_manager/language/index.php	(revision 15854)
@@ -0,0 +1,30 @@
+<?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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+// Recursive call
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: extensions/header_manager/main.inc.php
===================================================================
--- extensions/header_manager/main.inc.php	(revision 15854)
+++ extensions/header_manager/main.inc.php	(revision 15854)
@@ -0,0 +1,35 @@
+<?php 
+/*
+Plugin Name: Header Manager
+Version: auto
+Description: Header Manager allows to simply manage gallery banners. You can upload a picture from your computer or use a picture already in the gallery.
+Plugin URI: http://piwigo.org/ext/extension_view.php?eid=608
+Author: Mistic
+Author URI: http://www.strangeplanet.fr
+*/
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+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/');
+
+add_event_handler('init', 'header_manager_init');
+
+function header_manager_init()
+{
+  global $conf;
+  $conf['header_manager'] = unserialize($conf['header_manager']);
+    
+  include(HEADER_MANAGER_PATH . 'include/functions.inc.php');
+  include(HEADER_MANAGER_PATH . 'include/header_manager.inc.php');
+  
+  add_event_handler('render_page_banner', 'header_manager_render');
+
+  if (defined('IN_ADMIN'))
+  {
+    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 15854)
+++ extensions/header_manager/maintain.inc.php	(revision 15854)
@@ -0,0 +1,42 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+define('HEADER_MANAGER_DIR', PWG_LOCAL_DIR . 'banners/');
+
+define(
+  'header_manager_default_config', 
+  serialize(array(
+    'width' => 1000,
+    'height' => 150,
+    'image' => 'random',
+    'display' => 'image_only'
+    ))
+  );
+  
+
+function plugin_install() 
+{
+  conf_update_param('header_manager', header_manager_default_config);
+  mkdir(HEADER_MANAGER_DIR, 0755);
+}
+
+function plugin_activate()
+{
+  global $conf;
+
+  if (empty($conf['header_manager']))
+  {
+    conf_update_param('header_manager', header_manager_default_config);
+  }
+  if (!file_exists(HEADER_MANAGER_DIR)) 
+  {
+    mkdir(HEADER_MANAGER_DIR, 0755);
+  }
+}
+
+function plugin_uninstall() 
+{
+  pwg_query('DELETE FROM `'. CONFIG_TABLE .'` WHERE param = "header_manager" LIMIT 1;');
+}
+
+?>
