Index: /extensions/autoupdate/autoupdate.php
===================================================================
--- /extensions/autoupdate/autoupdate.php	(revision 6166)
+++ /extensions/autoupdate/autoupdate.php	(revision 6167)
@@ -2,110 +2,229 @@
 
 load_language('plugin.lang', dirname(__FILE__).'/');
-
-if (isset($_GET['action']) and 
-  ($_GET['action'] == 'check_autoupdate' or $_GET['action'] == 'check_upgrade' ))
-{
-  unset($_SESSION['need_update']);
-  unset($_SESSION['plugins_need_update']);
-}
-
-if (isset($_GET['autoupdate']))
-{
-  if ($_GET['autoupdate'] == 'success')
-  {
-    array_push($page['infos'], sprintf(l10n('autoupdate_success'), PHPWG_VERSION));
-  }
-  elseif ($file = $conf['local_data_dir'].'/autoupdate/'.$_GET['autoupdate'].'.zip' and file_exists($file))
-  {
-    include(dirname(__FILE__).'/class.inc.php');
-    include_once(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
-    $autoupdate = new autoupdate();
-    $zip = new PclZip($file);
-    if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH,
-                                PCLZIP_OPT_REMOVE_PATH, $_GET['autoupdate'],
-                                PCLZIP_OPT_SET_CHMOD, 0755,
-                                PCLZIP_OPT_REPLACE_NEWER))
-    {
-      //Check if all files were extracted
-      $error = '';
-      foreach($result as $extract)
-      {
-        if (!in_array($extract['status'], array('ok', 'filtered', 'already_a_directory')))
+include(AUTOUPDATE_PATH.'include/functions.inc.php');
+include(PHPWG_ROOT_PATH.'admin/include/pclzip.lib.php');
+
+/*
+STEP:
+0 = check is needed. If version is latest or check fail, we stay on step 0
+1 = new version on same branch AND new branch are available => user may choose upgrade.
+2 = upgrade on same branch
+3 = upgrade on different branch
+*/
+$step = isset($_GET['step']) ? $_GET['step'] : 0;
+
+// +-----------------------------------------------------------------------+
+// |                                Step 0                                 |
+// +-----------------------------------------------------------------------+
+if ($step == 0)
+{
+  if (preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches)
+    and @fetchRemote(PHPWG_URL.'/download/all_versions.php', $result)
+    and $all_versions = @explode("\n", $result)
+    and is_array($all_versions))
+  {
+    $template->assign('CHECK_VERSION', true);
+
+    $last_version = trim($all_versions[0]);
+
+    if (version_compare(PHPWG_VERSION, $last_version, '<'))
+    {
+      $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $last_version);
+      $actual_branch = $matches[1];
+
+      if ($new_branch == $actual_branch)
+      {
+        $step = 2;
+      }
+      else
+      {
+        $step = 3;
+
+        // Check if new version exists in same branch
+        foreach ($all_versions as $version)
         {
-          // Try to change chmod and extract
-          if (@chmod(PHPWG_ROOT_PATH.$extract['filename'], 0777)
-            and ($res = $zip->extract(PCLZIP_OPT_BY_NAME, $_GET['autoupdate'].'/'.$extract['filename'],
-                                      PCLZIP_OPT_PATH, PHPWG_ROOT_PATH,
-                                      PCLZIP_OPT_REMOVE_PATH, $_GET['autoupdate'],
-                                      PCLZIP_OPT_SET_CHMOD, 0755,
-                                      PCLZIP_OPT_REPLACE_NEWER))
-            and isset($res[0]['status'])
-            and $res[0]['status'] == 'ok')
+          $new_branch = preg_replace('/(\d+\.\d+)\.\d+/', '$1', $version);
+
+          if ($new_branch == $actual_branch)
           {
-            continue;
-          }
-          else
-          {
-            $error .= $extract['filename'].': '.$extract['status']."\n";
+            if (version_compare(PHPWG_VERSION, $version, '<'))
+            {
+              $step = 1;
+            }
+            break;
           }
         }
       }
-
-      if (empty($error))
-      {
-        if (file_exists(PHPWG_ROOT_PATH.'obsolete.list')
-          and $old_files = file(PHPWG_ROOT_PATH.'obsolete.list', FILE_IGNORE_NEW_LINES)
-          and !empty($old_files))
-        {
-          array_push($old_files, 'obsolete.list');
-          foreach($old_files as $old_file)
-          {
-            $path = PHPWG_ROOT_PATH.$old_file;
-            if (is_file($path))
-            {
-              @unlink($path);
-            }
-            elseif (is_dir($path))
-            {
-              $autoupdate->deltree($path);
-            }
-          }
-        }
-        if (preg_match('/\d+\.\d+\.\d+_to_(\d+\.\d+\.\d+)/', $_GET['autoupdate'], $matches))
-        {
-          unset($_SESSION['need_update']);
-          $autoupdate->check_version($matches[1]);
-        }
-        $autoupdate->deltree($conf['local_data_dir'].'/autoupdate');
-        invalidate_user_cache(true);
-        $template->delete_compiled_templates();
-        redirect('admin.php?autoupdate=success');
-      }
-      else
-      {
-        file_put_contents($conf['local_data_dir'].'/autoupdate/log_error.txt', $error);
-        $relative_path = trim(str_replace(dirname(dirname(dirname(__FILE__))), '', $conf['local_data_dir']), '/\\');
-        array_push($page['errors'], sprintf(l10n('autoupdate_extract_fail'), PHPWG_ROOT_PATH.$relative_path.'/autoupdate/log_error.txt'));
-      }
-    }
-    else
-    {
-      $autoupdate->deltree($conf['local_data_dir'].'/autoupdate');
-      array_push($page['errors'], l10n('autoupdate_fail'));
     }
   }
   else
   {
-    @unlink($file);
-    array_push($page['errors'], l10n('autoupdate_fail'));
-  }
-}
-
-if (!isset($_SESSION['need_update']) or !isset($_SESSION['plugins_need_update'])
-  or $_SESSION['need_update'] !== false or $_SESSION['plugins_need_update'] !== array())
-{
-  $template->set_filename('autoupdate_head', realpath(dirname(__FILE__).'/head.tpl'));
-  array_push($header_notes, $template->parse('autoupdate_head', true));
-}
+    $template->assign('CHECK_VERSION', false);
+  }
+}
+
+// +-----------------------------------------------------------------------+
+// |                                Step 1                                 |
+// +-----------------------------------------------------------------------+
+if ($step == 1)
+{
+  $new_versions = array($last_version, $version);
+  $template->assign('new_versions', $new_versions);
+}
+
+// +-----------------------------------------------------------------------+
+// |                                Step 2                                 |
+// +-----------------------------------------------------------------------+
+if ($step == 2)
+{
+  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
+  {
+    upgrade_to($_POST['upgrade_to'], $step);
+  }
+
+  $template->assign('UPGRADE_TO', isset($_GET['to']) ? $_GET['to'] : $last_version);
+}
+
+// +-----------------------------------------------------------------------+
+// |                                Step 3                                 |
+// +-----------------------------------------------------------------------+
+if ($step == 3)
+{
+  if (isset($_POST['saveTemplate']))
+  {
+    $path = $conf['local_data_dir'].'/autoupdate';
+
+    if (@mkgetdir($path)
+      and ($zip = tempnam($path, 'zip'))
+      and ($archive = new pclZip($zip))
+      and ($v_list = $archive->add(PHPWG_ROOT_PATH.'template', PCLZIP_OPT_REMOVE_PATH, PHPWG_ROOT_PATH))
+      and is_array($v_list)
+      and !empty($v_list))
+    {
+      $http_headers = array(
+        'Content-Length: '.@filesize($zip),
+        'Content-Type: application/zip',
+        'Content-Disposition: attachment; filename="template.zip";',
+        'Content-Transfer-Encoding: binary',
+        );
+
+      foreach ($http_headers as $header) {
+        header($header);
+      }
+
+      @readfile($zip);
+      autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
+      exit();
+    }
+
+    array_push($page['errors'], l10n('Unable to send template directory.'));
+  }
+
+  if (isset($_POST['dumpDatabase']))
+  {
+    if (version_compare(PHPWG_VERSION, '2.1', '<'))
+    {
+      global $cfgBase;
+      $conf['db_base'] = $cfgBase;
+    }
+
+    include(AUTOUPDATE_PATH.'include/mysqldump.php');
+
+    $path = $conf['local_data_dir'].'/autoupdate';
+
+    if (@mkgetdir($path)
+      and ($backupFile = tempnam($path, 'sql'))
+      and ($dumper = new MySQLDump($conf['db_base'],$backupFile,false,false)))
+    {
+      $tablesStructure = array(
+        CATEGORIES_TABLE,
+        COMMENTS_TABLE,
+        CONFIG_TABLE,
+        FAVORITES_TABLE,
+        GROUP_ACCESS_TABLE,
+        GROUPS_TABLE,
+        HISTORY_TABLE,
+        HISTORY_SUMMARY_TABLE,
+        IMAGE_CATEGORY_TABLE,
+        IMAGES_TABLE,
+        SESSIONS_TABLE,
+        SITES_TABLE,
+        USER_ACCESS_TABLE,
+        USER_GROUP_TABLE,
+        USERS_TABLE,
+        USER_INFOS_TABLE,
+        USER_FEED_TABLE,
+        WAITING_TABLE,
+        RATE_TABLE,
+        USER_CACHE_TABLE,
+        USER_CACHE_CATEGORIES_TABLE,
+        CADDIE_TABLE,
+        UPGRADE_TABLE,
+        SEARCH_TABLE,
+        USER_MAIL_NOTIFICATION_TABLE,
+        TAGS_TABLE,
+        IMAGE_TAG_TABLE,
+        PLUGINS_TABLE,
+        OLD_PERMALINKS_TABLE,
+        );
+
+      $tablesData = $tablesStructure;
+
+      if (!isset($_POST['includeHistory']))
+      {
+        unset($tablesData[6]);
+      }
+
+      foreach ($tablesStructure as $table)
+      {
+        $dumper->getTableStructure($table); 
+      }
+      foreach ($tablesData as $table)
+      {
+        $dumper->getTableData($table); 
+      }
+    }
+
+    if (@filesize($backupFile))
+    {
+      $http_headers = array(
+        'Content-Length: '.@filesize($backupFile),
+        'Content-Type: text/x-sql',
+        'Content-Disposition: attachment; filename="database.sql";',
+        'Content-Transfer-Encoding: binary',
+        );
+
+      foreach ($http_headers as $header) {
+        header($header);
+      }
+
+      @readfile($backupFile);
+      autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
+      exit();
+    }
+
+    array_push($page['errors'], l10n('Unable to dump database.'));
+  }
+
+  if (isset($_POST['submit']) and isset($_POST['upgrade_to']))
+  {
+    upgrade_to($_POST['upgrade_to'], $step);
+  }
+
+  $template->assign('UPGRADE_TO', isset($_GET['to']) ? $_GET['to'] : $last_version);
+}
+
+// +-----------------------------------------------------------------------+
+// |                        Process template                               |
+// +-----------------------------------------------------------------------+
+
+$template->assign(array(
+  'STEP' => $step,
+  'AU_URL' => get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php'),
+  )
+);
+
+$template->set_filename('plugin_admin_content', realpath(AUTOUPDATE_PATH.'template/autoupdate.tpl'));
+$template->assign_var_from_handle('ADMIN_CONTENT', 'plugin_admin_content');
 
 ?>
Index: /extensions/autoupdate/include/functions.inc.php
===================================================================
--- /extensions/autoupdate/include/functions.inc.php	(revision 6167)
+++ /extensions/autoupdate/include/functions.inc.php	(revision 6167)
@@ -0,0 +1,312 @@
+<?php
+
+function autoupdate_deltree($path)
+{
+  if (is_dir($path))
+  {
+    $fh = opendir($path);
+    while ($file = readdir($fh))
+    {
+      if ($file != '.' and $file != '..')
+      {
+        $pathfile = $path . '/' . $file;
+        if (is_dir($pathfile))
+        {
+          autoupdate_deltree($pathfile);
+        }
+        else
+        {
+          @unlink($pathfile);
+        }
+      }
+    }
+    closedir($fh);
+    return @rmdir($path);
+  }
+}
+
+function autoupdate_add_index($path)
+{
+  if (is_dir($path))
+  {
+    $fh = opendir($path);
+    while ($file = readdir($fh))
+    {
+      if ($file != '.' and $file != '..')
+      {
+        $pathfile = $path . '/' . $file;
+        if (is_dir($pathfile))
+        {
+          autoupdate_add_index($pathfile);
+        }
+      }
+    }
+    $fp = @fopen($path.'/index.php', 'w');
+    @fwrite($fp, AU_DEFAULT_INDEX);
+    @fclose($fp);
+    closedir($fh);
+  }
+}
+
+function process_obsolete_list($file)
+{
+  if (file_exists(PHPWG_ROOT_PATH.$file)
+    and $old_files = file(PHPWG_ROOT_PATH.$file, FILE_IGNORE_NEW_LINES)
+    and !empty($old_files))
+  {
+    array_push($old_files, $file);
+    foreach($old_files as $old_file)
+    {
+      $path = PHPWG_ROOT_PATH.$old_file;
+      if (is_file($path))
+      {
+        @unlink($path);
+      }
+      elseif (is_dir($path))
+      {
+        autoupdate_deltree($path);
+      }
+    }
+  }
+}
+
+function move_local_files($dir)
+{
+  global $page, $cfgBase, $cfgUser, $cfgPassword, $cfgHote, $prefixeTable;
+
+  if ((!is_dir($dir) and !mkdir($dir, 0777))
+    or (!is_dir($dir.'/config') and !mkdir($dir.'/config'))
+    or (!is_dir($dir.'/css') and !mkdir($dir.'/css'))
+    or (!is_dir($dir.'/language') and !mkdir($dir.'/language')))
+  {
+    autoupdate_deltree($dir);
+    array_push($page['errors'], l10n('Unable to write new local directory.'));
+    return;
+  }
+
+  // Add index.php
+  autoupdate_add_index($dir);
+
+  // mysql.inc.php
+  $file = PHPWG_ROOT_PATH.'include/mysql.inc.php';
+  if (is_readable($file))
+  {
+    $file_content = '<?php
+$conf[\'dblayer\'] = \'mysql\';
+$conf[\'db_base\'] = \''.$cfgBase.'\';
+$conf[\'db_user\'] = \''.$cfgUser.'\';
+$conf[\'db_password\'] = \''.$cfgPassword.'\';
+$conf[\'db_host\'] = \''.$cfgHote.'\';
+
+$prefixeTable = \''.$prefixeTable.'\';
+
+define(\'PHPWG_INSTALLED\', true);';
+    if (defined('PWG_CHARSET'))
+    {
+      $file_content.= '
+define(\'PWG_CHARSET\', \'utf-8\');
+define(\'DB_CHARSET\', \'utf8\');
+define(\'DB_COLLATE\', \'\');';
+    }
+    $file_content.= '
+?>';
+    $new_config_file = $dir.'/config/database.inc.php';
+
+    if (!($fp = @fopen($new_config_file, 'w'))
+      or !@fwrite($fp, $file_content)
+      or !@fclose($fp))
+    {
+      array_push($page['errors'], l10n('Unable to write new local directory.'));
+      return;
+    }
+    @chmod($new_config_file, 0755);
+  }
+
+  // config_local.inc.php
+  $file = PHPWG_ROOT_PATH.'include/config_local.inc.php';
+  if (is_readable($file))
+  {
+    copy($file, $dir.'/config/config.inc.php');
+    @chmod($file, 0755);
+  }
+
+  // languages
+  $language_dir = opendir(PHPWG_ROOT_PATH.'language');
+  while ($file = readdir($language_dir))
+  {
+    $path = PHPWG_ROOT_PATH.'language/'.$file;
+    if (!is_link($path) and is_dir($path) and is_readable($path.'/local.lang.php'))
+    {
+      $content = file_get_contents($path.'/local.lang.php');
+      $langdef = explode('.',$file);
+      if (count($langdef)>1)
+      {
+        $content = utf8_encode($content);
+      }
+      $filename = $dir.'/language/'.$langdef[0].'.lang.php';
+      $fp = @fopen($filename, 'w');
+      @fwrite($fp, $content);
+      @fclose($fp);
+      @chmod($filename, 0755);
+    }
+  }
+  closedir($language_dir);
+
+  // template-common/local-layout.css
+  $file = PHPWG_ROOT_PATH.'template-common/local-layout.css';
+  if (is_readable($file))
+  {
+    copy($file, $dir.'/css/rules.css');
+    @chmod($file, 0755);
+  }
+
+  // template/xxx/local-layout.css
+  $known_templates = array(
+    'yoga'     => 'default',
+    'floPure'  => 'Pure_default',
+    'floOs'    => 'OS_default',
+    'gally'    => 'gally-default',
+    'simple'   => 'simple',
+  );
+
+  foreach ($known_templates as $old_tpl => $new_tpl)
+  {
+    $file = PHPWG_ROOT_PATH.'template/'.$old_tpl.'/local-layout.css';
+    if (is_readable($file))
+    {
+      copy($file, $dir.'/css/'.$new_tpl.'-rules.css');
+      @chmod($file, 0755);
+    }
+  }
+}
+
+function upgrade_to($upgrade_to, &$step)
+{
+  global $page, $conf, $template;
+
+  if (!version_compare($_POST['upgrade_to'], PHPWG_VERSION, '>'))
+  {
+    redirect(get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php'));
+  }
+
+  if ($step == 2)
+  {
+    preg_match('/(\d+\.\d+)\.(\d+)/', PHPWG_VERSION, $matches);
+    $code =  $matches[1].'.x_to_'.$_POST['upgrade_to'];
+    $dl_code = str_replace(array('.', '_'), '', $code);
+    $remove_path = $code;
+    $obsolete_list = 'obsolete.list';
+  }
+  else
+  {
+    $code = $_POST['upgrade_to'];
+    $dl_code = $code;
+    $remove_path = version_compare($code, '2.0.8', '>=') ? 'piwigo' : 'piwigo-'.$code;
+    $obsolete_list = PHPWG_ROOT_PATH.'install/obsolete.list';
+
+    if (version_compare(PHPWG_VERSION, '2.1', '<'))
+    {
+      move_local_files(PHPWG_ROOT_PATH.'local');
+    }
+  }
+
+  if (empty($page['errors']))
+  {
+    $path = $conf['local_data_dir'].'/autoupdate';
+    $filename = $path.'/'.$code.'.zip';
+    @mkgetdir($path);
+
+    $chunk_num = 0;
+    $end = false;
+    $zip = @fopen($filename, 'w');
+    while (!$end)
+    {
+      $chunk_num++;
+      if (@fetchRemote(PHPWG_URL.'/download/dlcounter.php?code='.$dl_code.'&chunk_num='.$chunk_num, $result)
+        and $input = @unserialize($result))
+      {
+        if (0 == $input['remaining'])
+        {
+          $end = true;
+        }
+        @fwrite($zip, base64_decode($input['data']));
+      }
+      else
+      {
+        $end = true;
+      }
+    }
+    @fclose($zip);
+
+    if (@filesize($filename))
+    {
+      $zip = new PclZip($filename);
+      if ($result = $zip->extract(PCLZIP_OPT_PATH, PHPWG_ROOT_PATH,
+                                  PCLZIP_OPT_REMOVE_PATH, $remove_path,
+                                  PCLZIP_OPT_SET_CHMOD, 0755,
+                                  PCLZIP_OPT_REPLACE_NEWER))
+      {
+        //Check if all files were extracted
+        $error = '';
+        foreach($result as $extract)
+        {
+          if (!in_array($extract['status'], array('ok', 'filtered', 'already_a_directory')))
+          {
+            // Try to change chmod and extract
+            if (@chmod(PHPWG_ROOT_PATH.$extract['filename'], 0777)
+              and ($res = $zip->extract(PCLZIP_OPT_BY_NAME, $remove_path.'/'.$extract['filename'],
+                                        PCLZIP_OPT_PATH, PHPWG_ROOT_PATH,
+                                        PCLZIP_OPT_REMOVE_PATH, $remove_path,
+                                        PCLZIP_OPT_SET_CHMOD, 0755,
+                                        PCLZIP_OPT_REPLACE_NEWER))
+              and isset($res[0]['status'])
+              and $res[0]['status'] == 'ok')
+            {
+              continue;
+            }
+            else
+            {
+              $error .= $extract['filename'].': '.$extract['status']."\n";
+            }
+          }
+        }
+
+        if (empty($error))
+        {
+          process_obsolete_list($obsolete_list);
+          autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
+          invalidate_user_cache(true);
+          $template->delete_compiled_templates();
+          if ($step == 2)
+          {
+            array_push($page['infos'], sprintf(l10n('autoupdate_success'), $upgrade_to));
+            $template->assign('CHECK_VERSION', true);
+            $step = 0;
+          }
+          else
+          {
+            redirect(PHPWG_ROOT_PATH.'upgrade.php?now=');
+          }
+        }
+        else
+        {
+          file_put_contents($conf['local_data_dir'].'/autoupdate/log_error.txt', $error);
+          $relative_path = trim(str_replace(dirname(dirname(dirname(dirname(__FILE__)))), '', $conf['local_data_dir']), '/\\');
+          array_push($page['errors'], sprintf(l10n('autoupdate_extract_fail'), PHPWG_ROOT_PATH.$relative_path.'/autoupdate/log_error.txt'));
+        }
+      }
+      else
+      {
+        autoupdate_deltree($conf['local_data_dir'].'/autoupdate');
+        array_push($page['errors'], l10n('autoupdate_fail'));
+      }
+    }
+    else
+    {
+      array_push($page['errors'], l10n('Piwigo cannot retrieve upgrade file from server'));
+    }
+  }
+}
+
+define('AU_DEFAULT_INDEX', file_get_contents(AUTOUPDATE_PATH.'index.php'));
+?>
Index: /extensions/autoupdate/include/functions_remote.inc.php
===================================================================
--- /extensions/autoupdate/include/functions_remote.inc.php	(revision 6167)
+++ /extensions/autoupdate/include/functions_remote.inc.php	(revision 6167)
@@ -0,0 +1,108 @@
+<?php
+
+function autoupdate_check_version($version=PHPWG_VERSION)
+{
+  global $conf;
+
+  if (!isset($_SESSION['need_update']))
+  {
+    $_SESSION['need_update'] = null;
+
+    if (preg_match('/(\d+\.\d+)\.(\d+)/', $version, $matches)
+      and @fetchRemote(PHPWG_URL.'/download/all_versions.php', $result))
+    {
+      $all_versions = @explode("\n", $result);
+      $new_version = trim($all_versions[0]);
+      $_SESSION['need_update'] = version_compare($version, $new_version, '<');
+    }
+  }
+
+  if ($_SESSION['need_update'])
+  {
+    return l10n('A new version of Piwigo is available.').'<br>'
+          . '<a href="admin.php?page=plugin&amp;section=autoupdate%2Fautoupdate.php">'.l10n('Click here to upgrade automatically').'</a>';
+  }
+  else
+  {
+    // Gallery is up to date
+    // Check plugins upgrade
+    include_once(PHPWG_ROOT_PATH.'admin/include/plugins.class.php');
+    $plugins = new plugins();
+    $ignore_list = unserialize($conf['autoupdate_ignore_list']);
+
+    if (!isset($_SESSION['plugins_need_update']))
+    {
+      $_SESSION['plugins_need_update'] = null;
+      autoupdate_check_plugins_upgrade($plugins, $ignore_list);
+    }
+    elseif (!empty($_SESSION['plugins_need_update']))
+    {
+      // Check if plugins have been upgraded since last check
+      foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
+      {
+        if (isset($_SESSION['plugins_need_update'][$plugin_id])
+          and $plugins->plugin_version_compare($fs_plugin['version'], $_SESSION['plugins_need_update'][$plugin_id]))
+        {
+          // Plugin have been updated
+          autoupdate_check_plugins_upgrade($plugins, $ignore_list);
+        }
+      }
+    }
+
+    if (!empty($_SESSION['plugins_need_update']))
+    {
+      return l10n('Some upgrades are available for you plugins').'<br>'
+        . '<a href="admin.php?page=plugins_update">'.l10n('Click here see upgrade plugins page').'</a>';
+    }
+  }
+
+  if ($_SESSION['need_update'] === false and $_SESSION['plugins_need_update'] === array())
+  {
+    return l10n('Gallery and plugins are up to date');
+  }
+  else
+  {
+    return l10n('Unable to check upgrades...')
+      . '<br><a href="admin.php?action=check_autoupdate">'
+      . l10n('Click here to check upgrades now') . '</a>';
+  }
+}
+
+function autoupdate_check_plugins_upgrade($plugins, $ignore_list)
+{
+  if ($plugins->get_server_plugins())
+  {
+    $new_ignore_list = array();
+    $_SESSION['plugins_need_update'] = array();
+
+    foreach($plugins->fs_plugins as $plugin_id => $fs_plugin)
+    {
+      if (isset($fs_plugin['extension']) and isset($plugins->server_plugins[$fs_plugin['extension']]))
+      {
+        $plugin_info = $plugins->server_plugins[$fs_plugin['extension']];
+
+        if (!$plugins->plugin_version_compare($fs_plugin['version'], $plugin_info['revision_name']))
+        {
+          if (in_array($fs_plugin['name'], $ignore_list))
+          {
+            array_push($new_ignore_list, $fs_plugin['name']);
+          }
+          else
+          {
+            $_SESSION['plugins_need_update'][$plugin_id] = $plugin_info['revision_name'];
+          }
+        }
+      }
+    }
+
+    // Update ignore list in database
+    $query = '
+UPDATE '.CONFIG_TABLE.'
+SET value = "'.addslashes(serialize($new_ignore_list)).'"
+WHERE param = "autoupdate_ignore_list"
+;';
+    pwg_query($query);
+  }
+}
+
+?>
Index: /extensions/autoupdate/include/index.php
===================================================================
--- /extensions/autoupdate/include/index.php	(revision 6167)
+++ /extensions/autoupdate/include/index.php	(revision 6167)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | 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/autoupdate/include/mysqldump.php
===================================================================
--- /extensions/autoupdate/include/mysqldump.php	(revision 6167)
+++ /extensions/autoupdate/include/mysqldump.php	(revision 6167)
@@ -0,0 +1,417 @@
+<?php
+/**
+* Dump MySQL database
+*
+* Here is an inline example:
+* <code>
+* $connection = @mysql_connect($dbhost,$dbuser,$dbpsw);
+* $dumper = new MySQLDump($dbname,'filename.sql',false,false);
+* $dumper->doDump();
+* </code>
+*
+* Special thanks to:
+* - Andrea Ingaglio <andrea@coders4fun.com> helping in development of all class code
+* - Dylan Pugh for precious advices halfing the size of the output file and for helping in debug
+*
+* @name    MySQLDump
+* @author  Daniele Viganò - CreativeFactory.it <daniele.vigano@creativefactory.it>
+* @version 2.20 - 02/11/2007
+* @license http://opensource.org/licenses/gpl-license.php GNU Public License
+*/
+
+class MySQLDump {
+	/**
+	* @access private
+	*/
+	var $database = null;
+
+	/**
+	* @access private
+	*/
+	var $compress = false;
+
+	/**
+	* @access private
+	*/
+	var $hexValue = false;
+
+  /**
+	* The output filename
+	* @access private
+	*/
+	var $filename = null;
+
+	/**
+	* The pointer of the output file
+	* @access private
+	*/
+	var $file = null;
+
+	/**
+	* @access private
+	*/
+	var $isWritten = false;
+
+	/**
+	* Class constructor
+	* @param string $db The database name
+	* @param string $filepath The file where the dump will be written
+	* @param boolean $compress It defines if the output file is compress (gzip) or not
+	* @param boolean $hexValue It defines if the outup values are base-16 or not
+	*/
+	function MYSQLDump($db = null, $filepath = 'dump.sql', $compress = false, $hexValue = false){
+		$this->compress = $compress;
+		if ( !$this->setOutputFile($filepath) )
+			return false;
+		return $this->setDatabase($db);
+	}
+
+	/**
+	* Sets the database to work on
+	* @param string $db The database name
+	*/
+	function setDatabase($db){
+		$this->database = $db;
+		if ( !@mysql_select_db($this->database) )
+			return false;
+		return true;
+  }
+
+	/**
+	* Returns the database where the class is working on
+	* @return string
+	*/
+  function getDatabase(){
+		return $this->database;
+	}
+
+	/**
+	* Sets the output file type (It can be made only if the file hasn't been already written)
+	* @param boolean $compress If it's true, the output file will be compressed
+	*/
+	function setCompress($compress){
+		if ( $this->isWritten )
+			return false;
+		$this->compress = $compress;
+		$this->openFile($this->filename);
+		return true;
+  }
+
+	/**
+	* Returns if the output file is or not compressed
+	* @return boolean
+	*/
+  function getCompress(){
+		return $this->compress;
+	}
+
+	/**
+	* Sets the output file
+	* @param string $filepath The file where the dump will be written
+	*/
+	function setOutputFile($filepath){
+		if ( $this->isWritten )
+			return false;
+		$this->filename = $filepath;
+		$this->file = $this->openFile($this->filename);
+		return $this->file;
+  }
+
+  /**
+	* Returns the output filename
+	* @return string
+	*/
+  function getOutputFile(){
+		return $this->filename;
+	}
+
+	/**
+	* Writes to file the $table's structure
+	* @param string $table The table name
+	*/
+  function getTableStructure($table){
+		if ( !$this->setDatabase($this->database) )
+			return false;
+		// Structure Header
+		$structure = "-- \n";
+		$structure .= "-- Table structure for table `{$table}` \n";
+		$structure .= "-- \n\n";
+		// Dump Structure
+		$structure .= 'DROP TABLE IF EXISTS `'.$table.'`;'."\n";
+		$structure .= "CREATE TABLE `".$table."` (\n";
+		$records = @mysql_query('SHOW FIELDS FROM `'.$table.'`');
+		if ( @mysql_num_rows($records) == 0 )
+			return false;
+		while ( $record = mysql_fetch_assoc($records) ) {
+			$structure .= '`'.$record['Field'].'` '.$record['Type'];
+			if ( !empty($record['Default']) )
+				$structure .= ' DEFAULT \''.$record['Default'].'\'';
+			if ( @strcmp($record['Null'],'YES') != 0 )
+				$structure .= ' NOT NULL';
+			if ( !empty($record['Extra']) )
+				$structure .= ' '.$record['Extra'];
+			$structure .= ",\n";
+		}
+		$structure = @ereg_replace(",\n$", null, $structure);
+
+		// Save all Column Indexes
+		$structure .= $this->getSqlKeysTable($table);
+		$structure .= "\n)";
+
+		//Save table engine
+		$records = @mysql_query("SHOW TABLE STATUS LIKE '".$table."'");
+
+		if ( $record = @mysql_fetch_assoc($records) ) {
+			if ( !empty($record['Engine']) )
+				$structure .= ' ENGINE='.$record['Engine'];
+			if ( !empty($record['Auto_increment']) )
+				$structure .= ' AUTO_INCREMENT='.$record['Auto_increment'];
+		}
+
+		$structure .= ";\n\n-- --------------------------------------------------------\n\n";
+		$this->saveToFile($this->file,$structure);
+	}
+
+	/**
+	* Writes to file the $table's data
+	* @param string $table The table name
+	* @param boolean $hexValue It defines if the output is base 16 or not
+	*/
+	function getTableData($table,$hexValue = true) {
+		if ( !$this->setDatabase($this->database) )
+			return false;
+		// Header
+		$data = "-- \n";
+		$data .= "-- Dumping data for table `$table` \n";
+		$data .= "-- \n\n";
+
+		$records = mysql_query('SHOW FIELDS FROM `'.$table.'`');
+		$num_fields = @mysql_num_rows($records);
+		if ( $num_fields == 0 )
+			return false;
+		// Field names
+		$selectStatement = "SELECT ";
+		$insertStatement = "INSERT INTO `$table` (";
+		$hexField = array();
+		for ($x = 0; $x < $num_fields; $x++) {
+			$record = @mysql_fetch_assoc($records);
+			if ( ($hexValue) && ($this->isTextValue($record['Type'])) ) {
+				$selectStatement .= 'HEX(`'.$record['Field'].'`)';
+				$hexField [$x] = true;
+			}
+			else
+				$selectStatement .= '`'.$record['Field'].'`';
+			$insertStatement .= '`'.$record['Field'].'`';
+			$insertStatement .= ", ";
+			$selectStatement .= ", ";
+		}
+		$insertStatement = @substr($insertStatement,0,-2).') VALUES';
+		$selectStatement = @substr($selectStatement,0,-2).' FROM `'.$table.'`';
+
+		$records = @mysql_query($selectStatement);
+		$num_rows = @mysql_num_rows($records);
+		$num_fields = @mysql_num_fields($records);
+		// Dump data
+		if ( $num_rows > 0 ) {
+			$data .= $insertStatement;
+			for ($i = 0; $i < $num_rows; $i++) {
+				$record = @mysql_fetch_assoc($records);
+				$data .= ' (';
+				for ($j = 0; $j < $num_fields; $j++) {
+					$field_name = @mysql_field_name($records, $j);
+					if ( @$hexField[$j] && (@strlen($record[$field_name]) > 0) )
+						$data .= "0x".$record[$field_name];
+					else
+						$data .= "'".@str_replace('\"','"',@mysql_escape_string($record[$field_name]))."'";
+					$data .= ',';
+				}
+				$data = @substr($data,0,-1).")";
+				$data .= ( $i < ($num_rows-1) ) ? ',' : ';';
+				$data .= "\n";
+				//if data in greather than 1MB save
+				if (strlen($data) > 1048576) {
+					$this->saveToFile($this->file,$data);
+					$data = '';
+				}
+			}
+			$data .= "\n-- --------------------------------------------------------\n\n";
+			$this->saveToFile($this->file,$data);
+		}
+	}
+
+  /**
+	* Writes to file all the selected database tables structure
+	* @return boolean
+	*/
+	function getDatabaseStructure(){
+		$records = @mysql_query('SHOW TABLES');
+		if ( @mysql_num_rows($records) == 0 )
+			return false;
+    $structure = '';
+		while ( $record = @mysql_fetch_row($records) ) {
+			$structure .= $this->getTableStructure($record[0]);
+		}
+		return true;
+  }
+
+	/**
+	* Writes to file all the selected database tables data
+	* @param boolean $hexValue It defines if the output is base-16 or not
+	*/
+	function getDatabaseData($hexValue = true){
+		$records = @mysql_query('SHOW TABLES');
+		if ( @mysql_num_rows($records) == 0 )
+			return false;
+		while ( $record = @mysql_fetch_row($records) ) {
+			$this->getTableData($record[0],$hexValue);
+		}
+  }
+
+	/**
+	* Writes to file the selected database dump
+	*/
+	function doDump() {
+		$this->saveToFile($this->file,"SET FOREIGN_KEY_CHECKS = 0;\n\n");
+		$this->getDatabaseStructure();
+		$this->getDatabaseData($this->hexValue);
+		$this->saveToFile($this->file,"SET FOREIGN_KEY_CHECKS = 1;\n\n");
+		$this->closeFile($this->file);
+		return true;
+	}
+	
+	/**
+	* @deprecated Look at the doDump() method
+	*/
+	function writeDump($filename) {
+		if ( !$this->setOutputFile($filename) )
+			return false;
+		$this->doDump();
+    $this->closeFile($this->file);
+    return true;
+	}
+
+	/**
+	* @access private
+	*/
+	function getSqlKeysTable ($table) {
+		$primary = "";
+		$unique = array();
+		$index = array();
+		$fulltext = array();
+		$results = mysql_query("SHOW KEYS FROM `{$table}`");
+		if ( @mysql_num_rows($results) == 0 )
+			return false;
+		while($row = mysql_fetch_object($results)) {
+			if (($row->Key_name == 'PRIMARY') AND ($row->Index_type == 'BTREE')) {
+				if ( $primary == "" )
+					$primary = "  PRIMARY KEY  (`{$row->Column_name}`";
+				else
+					$primary .= ", `{$row->Column_name}`";
+			}
+			if (($row->Key_name != 'PRIMARY') AND ($row->Non_unique == '0') AND ($row->Index_type == 'BTREE')) {
+				if ( (empty($unique)) OR (empty($unique[$row->Key_name])) )
+					$unique[$row->Key_name] = "  UNIQUE KEY `{$row->Key_name}` (`{$row->Column_name}`";
+				else
+					$unique[$row->Key_name] .= ", `{$row->Column_name}`";
+			}
+			if (($row->Key_name != 'PRIMARY') AND ($row->Non_unique == '1') AND ($row->Index_type == 'BTREE')) {
+				if ( (empty($index)) OR (empty($index[$row->Key_name])) )
+					$index[$row->Key_name] = "  KEY `{$row->Key_name}` (`{$row->Column_name}`";
+				else
+					$index[$row->Key_name] .= ", `{$row->Column_name}`";
+			}
+			if (($row->Key_name != 'PRIMARY') AND ($row->Non_unique == '1') AND ($row->Index_type == 'FULLTEXT')) {
+				if ( (empty($fulltext)) OR (empty($fulltext[$row->Key_name])) )
+					$fulltext[$row->Key_name] = "  FULLTEXT `{$row->Key_name}` (`{$row->Column_name}`";
+				else
+					$fulltext[$row->Key_name] .= ", `{$row->Column_name}`";
+			}
+		}
+		$sqlKeyStatement = '';
+		// generate primary, unique, key and fulltext
+		if ( $primary != "" ) {
+			$sqlKeyStatement .= ",\n";
+			$primary .= ")";
+			$sqlKeyStatement .= $primary;
+		}
+		if (!empty($unique)) {
+			foreach ($unique as $keyName => $keyDef) {
+				$sqlKeyStatement .= ",\n";
+				$keyDef .= ")";
+				$sqlKeyStatement .= $keyDef;
+
+			}
+		}
+		if (!empty($index)) {
+			foreach ($index as $keyName => $keyDef) {
+				$sqlKeyStatement .= ",\n";
+				$keyDef .= ")";
+				$sqlKeyStatement .= $keyDef;
+			}
+		}
+		if (!empty($fulltext)) {
+			foreach ($fulltext as $keyName => $keyDef) {
+				$sqlKeyStatement .= ",\n";
+				$keyDef .= ")";
+				$sqlKeyStatement .= $keyDef;
+			}
+		}
+		return $sqlKeyStatement;
+	}
+
+  /**
+	* @access private
+	*/
+	function isTextValue($field_type) {
+		switch ($field_type) {
+			case "tinytext":
+			case "text":
+			case "mediumtext":
+			case "longtext":
+			case "binary":
+			case "varbinary":
+			case "tinyblob":
+			case "blob":
+			case "mediumblob":
+			case "longblob":
+				return True;
+				break;
+			default:
+				return False;
+		}
+	}
+	
+	/**
+	* @access private
+	*/
+	function openFile($filename) {
+		$file = false;
+		if ( $this->compress )
+			$file = @gzopen($filename, "w9");
+		else
+			$file = @fopen($filename, "w");
+		return $file;
+	}
+
+  /**
+	* @access private
+	*/
+	function saveToFile($file, $data) {
+		if ( $this->compress )
+			@gzwrite($file, $data);
+		else
+			@fwrite($file, $data);
+		$this->isWritten = true;
+	}
+
+  /**
+	* @access private
+	*/
+	function closeFile($file) {
+		if ( $this->compress )
+			@gzclose($file);
+		else
+			@fclose($file);
+	}
+}
+?>
Index: /extensions/autoupdate/index.php
===================================================================
--- /extensions/autoupdate/index.php	(revision 6166)
+++ /extensions/autoupdate/index.php	(revision 6167)
@@ -1,12 +1,9 @@
 <?php
 // +-----------------------------------------------------------------------+
-// | PhpWebGallery - a PHP based picture gallery                           |
-// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
-// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// | Piwigo - a PHP based picture gallery                                  |
 // +-----------------------------------------------------------------------+
-// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
-// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
-// | last modifier : $Author: rub $
-// | revision      : $Revision: 1912 $
+// | Copyright(C) 2008-2010 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  |
Index: /extensions/autoupdate/main.inc.php
===================================================================
--- /extensions/autoupdate/main.inc.php	(revision 6166)
+++ /extensions/autoupdate/main.inc.php	(revision 6167)
@@ -11,20 +11,39 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-if (script_basename() == 'admin') add_event_handler('get_admin_plugin_menu_links', 'check_for_auto_upgrade');
+define('AUTOUPDATE_PATH' , PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+
+if (script_basename() == 'admin')
+ add_event_handler('get_admin_plugin_menu_links', 'check_for_auto_upgrade');
 
 function check_for_auto_upgrade($plugin_menu_links)
 {
-  global $template, $page, $conf, $header_notes;
+  global $template, $page, $conf, $header_notes, $prefixeTable;
 
   if ($page['page'] == 'intro')
   {
-    include(dirname(__FILE__).'/autoupdate.php');
+    if (isset($_GET['action']) and 
+      ($_GET['action'] == 'check_autoupdate' or $_GET['action'] == 'check_upgrade' ))
+    {
+      unset($_SESSION['need_update']);
+      unset($_SESSION['plugins_need_update']);
+    }
+
+    if (!isset($_SESSION['need_update']) or !isset($_SESSION['plugins_need_update'])
+      or $_SESSION['need_update'] !== false or $_SESSION['plugins_need_update'] !== array())
+    {
+      $template->set_filename('autoupdate_head', realpath(AUTOUPDATE_PATH.'template/head.tpl'));
+      array_push($header_notes, $template->parse('autoupdate_head', true));
+    }
   }
 
-  if ($page['page'] == 'plugins_update')
+  if ($page['page'] == 'plugins_update' and method_exists('template', 'set_prefilter'))
   {
     include(dirname(__FILE__).'/plugins_update.php');
   }
 
+  array_push($plugin_menu_links, array(
+      'NAME' => 'Piwigo AutoUpgrade',
+      'URL' => get_admin_plugin_menu_link(AUTOUPDATE_PATH . '/autoupdate.php')));
+
   return $plugin_menu_links;
 }
Index: /extensions/autoupdate/maintain.inc.php
===================================================================
--- /extensions/autoupdate/maintain.inc.php	(revision 6166)
+++ /extensions/autoupdate/maintain.inc.php	(revision 6167)
@@ -3,11 +3,14 @@
 function plugin_activate()
 {
-  global $prefixeTable;
+  global $prefixeTable, $conf;
 
-  $query = '
+  if (!isset($conf['autoupdate_ignore_list']))
+  {
+    $query = '
 INSERT INTO ' . CONFIG_TABLE . ' (param,value,comment)
 VALUES ("autoupdate_ignore_list" , "'.addslashes(serialize(array())).'" , "Ignored plugin list for Piwigo Auto Update plugin");';
 
-  pwg_query($query);
+    pwg_query($query);
+  }
 }
 
Index: /extensions/autoupdate/plugins_update.php
===================================================================
--- /extensions/autoupdate/plugins_update.php	(revision 6166)
+++ /extensions/autoupdate/plugins_update.php	(revision 6167)
@@ -5,6 +5,9 @@
 function autoupdate_plugins_update_filter($content, &$smarty)
 {
-  $search = '<a href="{$plugin.URL_DOWNLOAD}">{\'plugins_download\'|@translate}</a>';
-  $replacement = '  <a href="{$plugin.URL_DOWNLOAD}">{\'plugins_download\'|@translate}</a><br>
+  $l_key = version_compare(PHPWG_VERSION, '2.1', '<') ? 'plugins_download' : 'Download file';
+
+  $search = '<a href="{$plugin.URL_DOWNLOAD}">{\''.$l_key.'\'|@translate}</a>';
+
+  $replacement = '  <a href="{$plugin.URL_DOWNLOAD}">{\''.$l_key.'\'|@translate}</a><br>
     <a href="#" onClick="autoupdate_ignore(\'{$plugin.EXT_NAME}\', true, {$smarty.foreach.plugins_loop.index}); return false;" id="au_ignore_{$smarty.foreach.plugins_loop.index}_true" {if $plugin.EXT_NAME|@in_array:$AU_IGNORE_LIST}style="display: none;"{/if}>{\'Don\\\'t notify on admin homepage\'|@translate}</a>
     <a href="#" onClick="autoupdate_ignore(\'{$plugin.EXT_NAME}\', false, {$smarty.foreach.plugins_loop.index}); return false;" id="au_ignore_{$smarty.foreach.plugins_loop.index}_false" {if !$plugin.EXT_NAME|@in_array:$AU_IGNORE_LIST}style="display: none;"{/if}>{\'Notify on admin homepage\'|@translate}</a>';
@@ -18,5 +21,5 @@
   jQuery.post(
     "'.PHPWG_ROOT_PATH.'plugins/autoupdate/remote.php",
-    { "autoupdate_ignore[]": [name, bool] },
+    { "autoupdate_ignore'.(version_compare(PHPWG_VERSION, '2.1', '<') ? '[]' : '').'": [name, bool] },
     function(data) {
       if (data == "ok") {
@@ -30,5 +33,4 @@
 ';
 
-//$template->delete_compiled_templates();
 $template->block_html_head('', $script_head, $smarty, $repeat);
 $template->set_prefilter('plugins', 'autoupdate_plugins_update_filter');
Index: /extensions/autoupdate/remote.php
===================================================================
--- /extensions/autoupdate/remote.php	(revision 6166)
+++ /extensions/autoupdate/remote.php	(revision 6167)
@@ -5,4 +5,5 @@
 include_once( PHPWG_ROOT_PATH.'include/common.inc.php' );
 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
+include_once(PHPWG_ROOT_PATH.'admin/include/functions_plugins.inc.php');
 
 check_status(ACCESS_ADMINISTRATOR);
@@ -12,4 +13,5 @@
   and count($_POST['autoupdate_ignore']) == 2)
 {
+  // Add or remove plugin from ignore list
   $ignore = unserialize($conf['autoupdate_ignore_list']);
   $ignore = array_flip($ignore);
@@ -43,11 +45,10 @@
 else
 {
+  // Check if gallery or plugins are up to date
   load_language('plugin.lang', dirname(__FILE__).'/');
   header('Content-Type: text/html; charset=UTF-8');
 
-  include(dirname(__FILE__).'/class.inc.php');
-  $autoupdate = new autoupdate();
-
-  echo $autoupdate->check_version();
+  include(AUTOUPDATE_PATH.'include/functions_remote.inc.php');
+  echo autoupdate_check_version();
 }
 
Index: /extensions/autoupdate/template/autoupdate.tpl
===================================================================
--- /extensions/autoupdate/template/autoupdate.tpl	(revision 6167)
+++ /extensions/autoupdate/template/autoupdate.tpl	(revision 6167)
@@ -0,0 +1,61 @@
+<div class="titrePage">
+{if $STEP < 2}
+<h2>Piwigo AutoUpgrade</h2>
+{else}
+<h2>{'Upgrade to Piwigo %s'|@translate|@sprintf:$UPGRADE_TO}</h2>
+{/if}
+</div>
+
+{if $STEP == 0}
+  {if $CHECK_VERSION}
+    <p>{'You are running the latest version of Piwigo.'|@translate}</p>
+  {else}  
+    <p>{'Check for upgrade failed for unknown reasons.'|@translate}</p>
+  {/if}
+{/if}
+
+{if $STEP == 1}
+<p>{'2 upgrades are available'|@translate}</p>
+<p>
+<ul>
+  <li><a href="{$AU_URL}&amp;step=2&amp;to={$new_versions.1}">{'Upgrade to Piwigo %s'|@translate|@sprintf:$new_versions.1}</a>: {'This is a minor upgrade, with only bug corrections'|@translate}</li>
+  <li><a href="{$AU_URL}&amp;step=3&amp;to={$new_versions.0}">{'Upgrade to Piwigo %s'|@translate|@sprintf:$new_versions.0}</a>: {'This is a major upgrade, with <a href="http://piwigo.org/releases/%s">new exciting features</a>. Some themes and plugins may be not available yet.'|@translate|@sprintf:$new_versions.0}</li>
+</ul>
+</p>
+{/if}
+
+{if $STEP == 2}
+<form action="" method="post">
+<p style="text-align:left; margin-left:20px;">
+  {'A new version of Piwigo is available.'}<br>
+  {'This is a minor upgrade, with only bug corrections'|@translate}
+</p>
+<p>
+  <input type="hidden" name="upgrade_to" value="{$UPGRADE_TO}">
+  <input type="submit" name="submit" value="{'Upgrade to Piwigo %s'|@translate|@sprintf:$UPGRADE_TO}" onClick="return confirm('{'autoupdate_alert'|@translate}');">
+</p>
+</form>
+{/if}
+
+{if $STEP == 3}
+<form action="" method="post">
+<p style="text-align:left; margin-left:20px;">
+  {'A new version of Piwigo is available.'}<br>
+  {'This is a major upgrade, with <a href="http://piwigo.org/releases/%s">new exciting features</a>. Some themes and plugins may be not available yet.'|@translate|@sprintf:$UPGRADE_TO}
+</p>
+<input type="hidden" name="upgrade_to" value="{$UPGRADE_TO}">
+<fieldset style="text-align:left;">
+  <legend>{'Save template directory'|@translate}</legend>
+  <p><input type="submit" name="saveTemplate" value="{'Save template directory'|@translate}"></p>
+</fieldset>
+<fieldset>
+  <legend>{'Dump Database'|@translate}</legend>
+  <p><input type="checkbox" name="includeHistory"> &nbsp; {'Include history table'|@translate}</p>
+  <p><input type="submit" name="dumpDatabase" value="{'Dump Database'|@translate|@sprintf:$UPGRADE_TO}"></p>
+</fieldset>
+<fieldset>
+  <legend>{'Upgrade to Piwigo %s'|@translate|@sprintf:$UPGRADE_TO}</legend>
+  <p><input type="submit" name="submit" value="{'Upgrade to Piwigo %s'|@translate|@sprintf:$UPGRADE_TO}"></p>
+</fieldset>
+</form>
+{/if}
Index: /extensions/autoupdate/template/head.tpl
===================================================================
--- /extensions/autoupdate/template/head.tpl	(revision 6167)
+++ /extensions/autoupdate/template/head.tpl	(revision 6167)
@@ -0,0 +1,25 @@
+{html_head}
+<script type="text/javascript">
+var mess_error = '{'Unable to check upgrades...'|@translate}<br><a href="admin.php?action=check_autoupdate">{'Click here to check upgrades now'|@translate}</a>';
+
+window.onload = function () {ldelim}
+  jQuery.ajax({ldelim}
+    type: 'GET',
+    url: '{$ROOT_URL|@cat:"plugins/autoupdate/remote.php"}',
+    dataType: 'text',
+    timeout: 10000,  // 10 sec timeout
+    success: function (data) {ldelim}
+      var reg = new RegExp("(warning|notice)","i");
+      if (data.match(reg)) {ldelim}
+        data = mess_error;
+      }
+      jQuery('#autoupdate').html(data);
+    },
+    error: function() {ldelim}
+     jQuery('#autoupdate').html(mess_error);
+    }
+  });
+}
+</script>
+{/html_head}
+<p id="autoupdate"><img src="plugins/autoupdate/template/ajax-loader.gif"> &nbsp; {'Checking upgrades for gallery and plugins...'|@translate}</p>
Index: /extensions/autoupdate/template/index.php
===================================================================
--- /extensions/autoupdate/template/index.php	(revision 6167)
+++ /extensions/autoupdate/template/index.php	(revision 6167)
@@ -0,0 +1,33 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | PhpWebGallery - a PHP based picture gallery                           |
+// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
+// | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net |
+// +-----------------------------------------------------------------------+
+// | file          : $Id: index.php 1912 2007-03-16 06:30:07Z rub $
+// | last update   : $Date: 2007-03-16 07:30:07 +0100 (ven, 16 mar 2007) $
+// | last modifier : $Author: rub $
+// | revision      : $Revision: 1912 $
+// +-----------------------------------------------------------------------+
+// | 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();
+?>
