Index: /extensions/Prune_History/admin/PH_admin.php
===================================================================
--- /extensions/Prune_History/admin/PH_admin.php	(revision 14853)
+++ /extensions/Prune_History/admin/PH_admin.php	(revision 14854)
@@ -18,8 +18,10 @@
 $page['global'] = array();
 $range = array();
+$dump_download = '';
 
-// +-----------------------------------------------------------------------+
-// |                      Getting plugin version                           |
-// +-----------------------------------------------------------------------+
+
+// +-------------------------------------------------------------------+
+// |                      Get plugin version and name                  |
+// +-------------------------------------------------------------------+
 $plugin =  PHInfos(PH_PATH);
 $version = $plugin['version'];
@@ -45,4 +47,58 @@
 }
 
+
+// +--------------------------------------------------------------------+
+// |                     Saving history tables                          |
+// +--------------------------------------------------------------------+
+if (isset($_POST['save']))
+{
+  $dump_download = (isset($_POST['dump_download'])) ? 'true' : 'false';
+    
+  if(PH_dump($dump_download) and $dump_download == 'false')
+  {
+    array_push($page['infos'], l10n('PH_Dump_OK'));
+  }
+  else
+  {
+    array_push($page['errors'], l10n('PH_Dump_NOK'));
+  }
+}
+
+
+// +--------------------------------------------------------------------+
+// |             Restoring backed up history tables                     |
+// +--------------------------------------------------------------------+
+if (isset($_POST['restore']))
+{
+  $Backup_File = PH_PATH.'/include/backup/PH_Historybackup.sql';
+
+  if (file_exists($Backup_File) and $file = file($Backup_File, FILE_IGNORE_NEW_LINES) and !empty($file))
+  {
+    // Check backup file version
+    // -------------------------
+    if ($file[0] == "-- ".$version." --")
+    {
+      $restore = PH_Restore_backup_file();
+      if(empty($restore))
+      {
+        array_push($page['infos'], l10n('PH_Restoration_OK'));
+      }
+      else
+      {
+        array_push($page['errors'], l10n('PH_Restoration_NOK'));
+      }
+    }
+    else array_push($page['errors'], l10n('PH_Bad_version_backup'));
+  }
+  else
+  {
+    array_push($page['errors'], l10n('PH_No_Backup_File'));
+  }
+}
+
+
+// +--------------------------------------------------------------------+
+// |                      Manual prune settings                         |
+// +--------------------------------------------------------------------+
 $conf_PH = unserialize($conf['PruneHistory']);
 
@@ -87,4 +143,5 @@
 }
 
+
 // +-----------------------------------------------------------------------+
 // |                           templates init                              |
@@ -104,4 +161,5 @@
     'PH_NAME'                    => $name,
     'PH_VERSION'                 => $version,
+    'PH_DUMP_DOWNLOAD'           => $dump_download,
 		'PH_AUTOPRUNE_TRUE'          => $conf_PH[1]=='true' ? 'checked="checked"' : '' ,
 		'PH_AUTOPRUNE_FALSE'         => $conf_PH[1]=='false' ? 'checked="checked"' : '' ,
@@ -119,4 +177,5 @@
 );
 
+
 // +-----------------------------------------------------------------------+
 // |                           templates display                           |
Index: /extensions/Prune_History/admin/template/PH_admin.tpl
===================================================================
--- /extensions/Prune_History/admin/template/PH_admin.tpl	(revision 14853)
+++ /extensions/Prune_History/admin/template/PH_admin.tpl	(revision 14854)
@@ -26,5 +26,5 @@
 </div>
 
-<fieldset>
+<fieldset class="save">
   <ul>
     <li>
@@ -32,4 +32,27 @@
         {'PH_ManualPrune_title'|@translate}
       </label>
+
+      <fieldset class="save">
+      <div style="text-align: center; text-transform: uppercase;">
+      <label class="cluetip" title="{'PH_Save_Title'|translate}|{'PH_Save_Title_d'|translate}">
+        {'PH_Save_Title'|@translate}
+      </label>
+      </div>
+      <form method="post" action="" class="general">
+        <p>
+          {'PH_Dump_Download'|@translate}&nbsp;
+            <input type="checkbox" name="dump_download" value="true" {$PH_DUMP_DOWNLOAD}><br><br>
+            <input class="submit" type="submit" value="{'PH_Save'|@translate}" name="save" {$TAG_INPUT_ENABLED}>
+        </p>
+      </form>
+      <br>
+      <form method="post" action="" class="general">
+        <p>
+          {'PH_Restore'|@translate}<br><br>
+            <input class="submit" type="submit" value="{'PH_Restore_File'|@translate}" name="restore" {$TAG_INPUT_ENABLED}>
+        </p>
+      </form>
+      </fieldset>
+
       <br><br>
       <form method="post" name="prune" action="" class="general">
@@ -77,4 +100,5 @@
           </li>
         </ul>
+
         <p>
           <input class="submit" type="submit" value="{'PH_Prune'|@translate}" name="prune" {$TAG_INPUT_ENABLED}>
@@ -132,5 +156,5 @@
   jQuery('#theAdminPage #the_page').addClass('{$themeconf.name}');
 	jQuery(".infos").fadeOut(800).fadeIn(1200).fadeOut(400).fadeIn(800).fadeOut(400);
-	jQuery(".errors").fadeOut(200).fadeIn(200).fadeOut(300).fadeIn(300).fadeOut(400).fadeIn(400); 
+	jQuery(".errors").fadeOut(400).fadeIn(400).fadeOut(400).fadeIn(400).fadeOut(400).fadeIn(400); 
 });
 </script>
Index: /extensions/Prune_History/admin/template/ph.css
===================================================================
--- /extensions/Prune_History/admin/template/ph.css	(revision 14853)
+++ /extensions/Prune_History/admin/template/ph.css	(revision 14854)
@@ -15,2 +15,12 @@
     margin-bottom: 0.5em;
 }
+
+.save P, .save FIELDSET {
+    display: block;
+    float: right;
+    margin-left: 1em;
+    padding-bottom: 0;
+    padding-left: 0;
+    padding-right: 0;
+    padding-top: 0;
+}
Index: /extensions/Prune_History/include/functions.inc.php
===================================================================
--- /extensions/Prune_History/include/functions.inc.php	(revision 14853)
+++ /extensions/Prune_History/include/functions.inc.php	(revision 14854)
@@ -1,4 +1,31 @@
 <?php
-/* Function called from main.inc.php to get the plugin version and name */
+/**
+ * Plugin administration menu
+ */
+function PH_admin_menu($menu)
+{
+  // Retreive plugin name
+  $plugin =  PHInfos(PH_PATH);
+  $name = $plugin['name'];
+  
+  array_push($menu,
+    array(
+      'NAME' => $name,
+      'URL' => get_root_url().'admin.php?page=plugin-'.basename(PH_PATH)
+    )
+  );
+
+  return $menu;
+}
+
+
+/**
+ * Function to retreive some plugin information like version and name
+ * stored in main.inc.php file
+ * 
+ * @param : Path to plugin
+ * 
+ * @return : Array of retreived information
+ */
 function PHInfos($dir)
 {
@@ -46,9 +73,9 @@
 
 
-/* *************************************** */
-/* Update plugin version in conf table     */
-/* Used everytime a new version is updated */
-/* even if no database upgrade is needed   */
-/* *************************************** */
+/**
+ * Function to update plugin version number in config table
+ * Used everytime a new version is updated even if no database
+ * upgrade is needed
+ */
 function PH_version_update()
 {
@@ -190,9 +217,7 @@
 
 /**
- * Automatic prune function
- * 
- * @param : Start and stop range to prune
- * 
- * @return : boolean
+ * Automatic prune function called from 'login_success' trigger
+ * in main.inc.php file
+ * 
  */
 function history_autoprune()
@@ -236,4 +261,170 @@
 }
 
+
+/**
+ * PH specific database dump
+ * Creates an SQL dump of history table for safety before manual prune
+ * 
+ * @returns  : Boolean to manage appropriate message display
+ * 
+ */
+function PH_dump($download)
+{
+  global $conf;
+
+  $plugin =  PluginInfos(PH_PATH);
+  $version = $plugin['version'];
+
+  // Initial backup folder creation and file initialisation
+  // ------------------------------------------------------
+  if (!is_dir(PH_PATH.'/include/backup'))
+    mkdir(PH_PATH.'/include/backup');
+
+  $Backup_File = PH_PATH.'/include/backup/PH_Historybackup.sql';
+
+  $fp = fopen($Backup_File, 'w');
+
+  // Writing plugin version
+  $insertions = "-- ".$version." --\n\n";
+  fwrite($fp, $insertions);
+
+  // Saving History table
+  // --------------------
+  $ListTables = array(HISTORY_TABLE);
+  $j=0;
+  
+  while($j < count($ListTables))
+  {
+    $sql = 'SHOW CREATE TABLE '.$ListTables[$j];
+    $res = pwg_query($sql);
+
+    if ($res)
+    {
+      $insertions = "-- -------------------------------------------------------\n";
+      $insertions .= "-- Create ".$ListTables[$j]." table\n";
+      $insertions .= "-- ------------------------------------------------------\n\n";
+
+      $insertions .= "DROP TABLE IF EXISTS ".$ListTables[$j].";\n\n";
+
+      $array = mysql_fetch_array($res);
+      $array[1] .= ";\n\n";
+      $insertions .= $array[1];
+
+      $req_table = pwg_query('SELECT * FROM '.$ListTables[$j]) or die(mysql_error());
+      $nb_fields = mysql_num_fields($req_table);
+      while ($line = mysql_fetch_array($req_table))
+      {
+        $insertions .= 'INSERT INTO '.$ListTables[$j].' VALUES (';
+        for ($i=0; $i<$nb_fields; $i++)
+        {
+          $insertions .= '\'' . pwg_db_real_escape_string($line[$i]) . '\', ';
+        }
+        $insertions = substr($insertions, 0, -2);
+        $insertions .= ");\n";
+      }
+      $insertions .= "\n\n";
+    }
+
+    fwrite($fp, $insertions);    
+    $j++;
+  }
+
+  fclose($fp);
+
+  // Download generated dump file
+  // ----------------------------
+  if ($download == 'true')
+  {
+    if (@filesize($Backup_File))
+    {
+      $http_headers = array(
+        'Content-Length: '.@filesize($Backup_File),
+        'Content-Type: text/x-sql',
+        'Content-Disposition: attachment; filename="PH_Historybackup.sql";',
+        'Content-Transfer-Encoding: binary',
+        );
+
+      foreach ($http_headers as $header)
+      {
+        header($header);
+      }
+
+      @readfile($Backup_File);
+      exit();
+    }
+  }
+
+  return true;
+}
+
+
+/**
+ * PH_Restore_backup_file
+ * Restore backup history table
+ * 
+ * @returns : Boolean
+ */
+function PH_Restore_backup_file() 
+{
+  global $prefixeTable, $dblayer, $conf;
+  
+  define('DEFAULT_PREFIX_TABLE', 'piwigo_');
+  
+  $Backup_File = PH_PATH.'/include/backup/PH_Historybackup.sql';
+
+  // Restore sql backup file - DROP TABLE queries are executed
+  // ---------------------------------------------------------
+  UAM_execute_sqlfile(
+    $Backup_File,
+    DEFAULT_PREFIX_TABLE,
+    $prefixeTable,
+    $dblayer
+  );
+}
+
+
+/**
+ * loads an sql file and executes all queries / Based on Piwigo's original install file
+ *
+ * Before executing a query, $replaced is... replaced by $replacing. This is
+ * useful when the SQL file contains generic words.
+ *
+ * @param string filepath
+ * @param string replaced
+ * @param string replacing
+ * @return void
+ */
+function PH_execute_sqlfile($filepath, $replaced, $replacing, $dblayer)
+{
+  $sql_lines = file($filepath);
+  $query = '';
+  foreach ($sql_lines as $sql_line)
+  {
+    $sql_line = trim($sql_line);
+    if (preg_match('/(^--|^$)/', $sql_line))
+    {
+      continue;
+    }
+    
+    $query.= ' '.$sql_line;
+    
+    // if we reached the end of query, we execute it and reinitialize the
+    // variable "query"
+    if (preg_match('/;$/', $sql_line))
+    {
+      $query = trim($query);
+      $query = str_replace($replaced, $replacing, $query);
+      if ('mysql' == $dblayer)
+      {
+        if (preg_match('/^(CREATE TABLE .*)[\s]*;[\s]*/im', $query, $matches))
+        {
+          $query = $matches[1].' DEFAULT CHARACTER SET utf8'.';';
+        }
+      }
+      pwg_query($query);
+      $query = '';
+    }
+  }
+}
 
 
Index: /extensions/Prune_History/language/en_UK/description.txt
===================================================================
--- /extensions/Prune_History/language/en_UK/description.txt	(revision 14853)
+++ /extensions/Prune_History/language/en_UK/description.txt	(revision 14854)
@@ -1,1 +1,1 @@
-Manual prune and background process which cleans your history table on regular basis.
+Manual and automatic pruning of the history table.
Index: /extensions/Prune_History/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/Prune_History/language/en_UK/plugin.lang.php	(revision 14854)
+++ /extensions/Prune_History/language/en_UK/plugin.lang.php	(revision 14854)
@@ -0,0 +1,51 @@
+<?php
+$lang['PH_ManualPrune_title'] = 'Manual Prune';
+$lang['PH_ManualPrune_title_d'] = 'This feature allows you to delete history entries based on a range of dates. Choose a start date and end date of treatment and run.<br><br>
+<b style=&quot;color: red;&quot;>Warning: The history data will be irretrievably deleted!</b> You can backup and restore history table by using the functions in the right frame.<br><br>
+Note: The history summary is not affected by pruning.';
+
+$lang['PH_Save_Title'] = 'Safety backup';
+$lang['PH_Save_Title_d'] = 'Because pruning is final and irreversible, it is advisable to save your history table before beginning pruning. By default, the table is saved in a file on the server and can be restored from there.<br><br>
+But it is also possible to download the backup file to keep it out of your gallery. In this case, the restoration must be done via your database management tool (usually phpMyAdmin).';
+
+$lang['PH_Dump_Download'] = 'To download the backup file, check this box:';
+$lang['PH_Restore'] = 'To restore a backup of your history table.<br>Only the saved file on the server is taken into account.';
+$lang['PH_Save'] = 'Backup history';
+$lang['PH_Restore_File'] = 'Restore history';
+$lang['PH_Dump_OK'] = 'The backup was successful!';
+$lang['PH_Dump_NOK'] = 'The backup failed!';
+$lang['PH_Restoration_OK'] = 'Restoration successful!';
+$lang['PH_Restoration_NOK'] = 'Restoration failed!';
+$lang['PH_Bad_version_backup'] = 'Wrong plugin version! The backup you are trying to restore is outdated or has been created with an older version of the plugin.';
+$lang['PH_No_Backup_File'] = 'No backup file found to restore!';
+
+$lang['PH_AutoPrune_title'] = 'Automatic Prune';
+$lang['PH_AutoPrune_title_d'] = 'If you enable automatic pruning, it will be triggered automatically at each user login on the gallery (including an administrator or webmaster) and based on the conservation settings.<br><br>
+<b style=&quot;color: red;&quot;>Use with caution! Pruned data will not be recoverable!</b>';
+
+$lang['PH_AutoPrune_false'] = 'Disable (default)';
+$lang['PH_AutoPrune_true'] = 'Enable';
+$lang['Start_Date'] = 'Start date';
+
+$lang['PH_AutoRange_title'] = 'keep the history up to:';
+$lang['PH_AutoRange_title_d'] = 'Please configure your History <b>conservation</b> criterion for automatic pruning. Several choices are possible:<br><br>
+- Keep x days<br>
+- Keep x months<br>
+- Keep x years<br><br>
+For example: If you want to keep a historical depth of 3 months, you can set up three months or 91 days.<br><br>
+Note: The history summary is not affected by auto pruning.';
+
+$lang['PH_save_config'] = 'Settings saved!';
+$lang['PH_Prune'] = 'Run manual pruning';
+$lang['PH_submit'] = 'Save settings';
+
+$lang['PH_Prune_Done'] = 'Manual pruning done!';
+$lang['PH_Prune_Error'] = 'Error manual pruning! Check your date range.';
+
+$lang['range'][1] = 'Day(s)';
+$lang['range'][2] = 'Month(s)';
+$lang['range'][3] = 'Year(s)';
+
+$lang['PH_Support'] = 'The official support on this plugin is only on these Piwigo forum topic:<br>
+<a href="http://piwigo.org/forum/viewtopic.php?id=" onclick="window.open(this.href);return false;">English forum - http://piwigo.org/forum/viewtopic.php?id=</a>';
+?>
Index: /extensions/Prune_History/language/fr_FR/description.txt
===================================================================
--- /extensions/Prune_History/language/fr_FR/description.txt	(revision 14853)
+++ /extensions/Prune_History/language/fr_FR/description.txt	(revision 14854)
@@ -1,1 +1,1 @@
-Elaguage manuel et tâche de fond pour nettoyer la table historique.
+Elaguage manuel et automatique de la table historique.
Index: /extensions/Prune_History/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/Prune_History/language/fr_FR/plugin.lang.php	(revision 14853)
+++ /extensions/Prune_History/language/fr_FR/plugin.lang.php	(revision 14854)
@@ -1,9 +1,39 @@
 <?php
 $lang['PH_ManualPrune_title'] = 'Elagage manuel';
+$lang['PH_ManualPrune_title_d'] = 'Cette fonction permet de supprimer des entrées dans l\'historique en fonction d\'une plage de dates. Choisissez une date de début et une date de fin de traitement et exécutez.<br><br>
+<b style=&quot;color: red;&quot;>Attention : Les données de l\'historique seront alors irrémédiablement supprimées !</b> Vous pouvez sauvegarder préalablement et restaurer la table d\'historique en utilisant les fonctions dans le cadre de droite.<br><br>
+Note : Le récapiltulatif de l\'historique n\'est pas affecté par l\'élagage.';
+
+$lang['PH_Save_Title'] = 'Sauvegarde de sécurité';
+$lang['PH_Save_Title_d'] = 'L\'élagage étant définitif et irréversible, il est vivement conseillé de sauvegarder votre table d\'historique avant de lancer un élagage. Par défaut, la table est sauvegardée dans un fichier sur le serveur et peut être restaurée depuis cet emplacement.<br><br>
+Mais il est aussi possible de télécharger le fichier de sauvegarde pour le conserver en dehors de votre galerie. Dans ce cas, la restauration devra se faire via votre outil de gestion de base de données (généralement PhpMyAdmin).';
+
+$lang['PH_Dump_Download'] = 'Pour télécharger le fichier de sauvegarde, cochez cette case:';
+$lang['PH_Restore'] = 'Pour restaurer une sauvegarde de votre table d\'historique.<br>Seul le fichier sauvegardé sur le serveur est pris en compte.';
+$lang['PH_Save'] = 'Sauvegarder l\'historique';
+$lang['PH_Restore_File'] = 'Restaurer l\'historique';
+$lang['PH_Dump_OK'] = 'La sauvegarde a réussi !';
+$lang['PH_Dump_NOK'] = 'La sauvegarde a échoué !';
+$lang['PH_Restoration_OK'] = 'Restauration réussie !';
+$lang['PH_Restoration_NOK'] = 'Restauration échouée !';
+$lang['PH_Bad_version_backup'] = 'Mauvaise version du plugin ! La sauvegarde que vous tentez de restaurer est obsolète ou a été créée avec une ancienne version du plugin.';
+$lang['PH_No_Backup_File'] = 'Aucun fichier de sauvegarde trouvé pour la restauration !';
+
 $lang['PH_AutoPrune_title'] = 'Elagage automatique';
-$lang['PH_AutoPrune_false'] = 'Désactiver';
+$lang['PH_AutoPrune_title_d'] = 'Si vous activez l\'élagage automatique, celui-ci se déclenchera automatiquement en fonction du critère de conservation à chaque connexion d\'un utilisateur sur la galerie (y compris un administrateur ou le webmaster).<br><br>
+<b style=&quot;color: red;&quot;>A utiliser avec précaution ! Les données élaguées ne seront pas récupérables en cas d\'erreur !</b>';
+
+$lang['PH_AutoPrune_false'] = 'Désactiver (par défaut)';
 $lang['PH_AutoPrune_true'] = 'Activer';
 $lang['Start_Date'] = 'Date de début';
+
 $lang['PH_AutoRange_title'] = 'Ne conserver un historique que sur :';
+$lang['PH_AutoRange_title_d'] = 'Configurez ici votre critère <b>de conservation</b> de l\'historique pour l\'élagage automatique. Plusieurs choix sont possibles :<br><br>
+- Conserver x jours<br>
+- Conserver x mois<br>
+- Conserver x années<br><br>
+Par exemple : Si vous ne souhaitez conserver qu\'une profondeur d\'historique de 3 mois,  vous pouvez paramétrer 3 mois ou 91 jours.<br><br>
+Note : Le récapiltulatif de l\'historique n\'est pas affecté par l\'élagage automatique.';
+
 $lang['PH_save_config'] = 'Configuration enregistrée !';
 $lang['PH_Prune'] = 'Exécuter l\'élagage manuel';
@@ -16,3 +46,6 @@
 $lang['range'][2] = 'Mois';
 $lang['range'][3] = 'Année(s)';
+
+$lang['PH_Support'] = 'Le support officiel sur ce plugin se fait exclusivement sur ce fil du forum FR de Piwigo:<br>
+<a href="http://fr.piwigo.org/forum/viewtopic.php?id=" onclick="window.open(this.href);return false;">Forum français - http://fr.piwigo.org/forum/viewtopic.php?id=</a>';
 ?>
Index: /extensions/Prune_History/main.inc.php
===================================================================
--- /extensions/Prune_History/main.inc.php	(revision 14853)
+++ /extensions/Prune_History/main.inc.php	(revision 14854)
@@ -2,5 +2,5 @@
 /*
 Plugin Name: Prune History
-Version: 1.0.0-beta1
+Version: 1.0.0
 Description: Based on original History_cleanup plugin from VDigital, this plugin allows to manually or automatically prune history table according to configurable criteria
 Plugin URI: http://piwigo.org/ext/extension_view.php?eid=
@@ -8,4 +8,6 @@
 Author URI: http://www.infernoweb.net
 */
+
+/* See release history and changes in changelog.txt file */
 
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
@@ -23,26 +25,10 @@
 $conf_PH = unserialize($conf['PruneHistory']);
 
-/* Plugin admin */
+
+/* Plugin administration */
 add_event_handler('get_admin_plugin_menu_links', 'PH_admin_menu');
 
-function PH_admin_menu($menu)
-{
-// +-----------------------------------------------------------------------+
-// |                      Getting plugin name                              |
-// +-----------------------------------------------------------------------+
-  $plugin =  PHInfos(PH_PATH);
-  $name = $plugin['name'];
-  
-  array_push($menu,
-    array(
-      'NAME' => $name,
-      'URL' => get_root_url().'admin.php?page=plugin-'.basename(PH_PATH)
-    )
-  );
 
-  return $menu;
-}
-
-// Prune automation on user login
+/* Prune automation on user login */
 if (isset($conf_PH[1]) and $conf_PH[1] == 'true')
 {
Index: /extensions/Prune_History/maintain.inc.php
===================================================================
--- /extensions/Prune_History/maintain.inc.php	(revision 14853)
+++ /extensions/Prune_History/maintain.inc.php	(revision 14854)
@@ -26,4 +26,6 @@
   $defaultPH[0] = $version;                                  // Prune History version
   $defaultPH[1] = 'false';                                   // Enable automated prune
+  $defaultPH[2] = '0';                                       // Range
+  $defaultPH[3] = '0';                                       // Value (Year, month, day)
 
   // Create Prune History conf if not already exists
