Index: extensions/add_index/admin/main_page.php
===================================================================
--- extensions/add_index/admin/main_page.php	(revision 5361)
+++ extensions/add_index/admin/main_page.php	(revision 12801)
@@ -1,9 +1,6 @@
 <?php
 // +-----------------------------------------------------------------------+
-// | Piwigo - a PHP based picture gallery                                  |
-// +-----------------------------------------------------------------------+
-// | 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 |
+// | Add Index - a Piwigo Plugin                                           |
+// | Copyright (C) 2019-2011 Piwigo team                                   |
 // +-----------------------------------------------------------------------+
 // | This program is free software; you can redistribute it and/or modify  |
@@ -51,7 +48,7 @@
  * @return array
  */
-function get_add_index_directories($path, $recursive = true)
-{
-  $dirs = array();
+function get_add_index_directories($path)
+{
+  $dirs = array($path);
 
   if (is_dir($path))
@@ -68,9 +65,5 @@
            )
         {
-          array_push($dirs, $path.'/'.$node);
-          if ($recursive)
-          {
-            $dirs = array_merge($dirs, get_add_index_directories($path.'/'.$node));
-          }
+          $dirs = array_merge($dirs, get_add_index_directories($path.'/'.$node));
         }
       }
@@ -87,7 +80,5 @@
 $index_file_src=$conf['add_index_source_directory_path'].$conf['add_index_filename'];
 $overwrite_file=isset($_GET['overwrite']);
-$site_id = (isset($_GET['site_id']) and is_numeric($_GET['site_id']) 
-            ? $_GET['site_id'] 
-            : 0);
+$site_id=((isset($_GET['site_id']) and is_numeric($_GET['site_id'])) ? $_GET['site_id'] : 0);
 
 // Init values
@@ -96,7 +87,13 @@
 $count_skip = 0;
 $count_error = 0;
+$dir_list=array();
 
 if (@file_exists($index_file_src))
 {
+  if (empty($site_id))
+  {
+    $dir_list[] = $conf['upload_dir'];
+  }
+
   $query = '
 select
@@ -120,39 +117,44 @@
     while (list($galleries_url) = mysql_fetch_row($result))
     {
-      if (!url_is_remote($galleries_url))
+      $dir_list[] = $galleries_url;
+    }
+  }
+
+  foreach ($dir_list as $galleries_url)
+  {
+    //~ echo $galleries_url.'<BR>';
+    if (!url_is_remote($galleries_url))
+    {
+      foreach (get_add_index_directories($galleries_url) as $dir_galleries)
       {
-        //echo $galleries_url.'<BR>';
-        foreach (get_add_index_directories($galleries_url) as $dir_galleries)
+        $file_dest = str_replace('//', '/', $dir_galleries.'/'.$conf['add_index_filename']);
+        if ($overwrite_file or !@file_exists($file_dest))
         {
-          $file_dest = str_replace('//', '/', $dir_galleries.'/'.$conf['add_index_filename']);
-          if ($overwrite_file or !@file_exists($file_dest))
+          if (copy($index_file_src, $file_dest))
           {
-            if (copy($index_file_src, $file_dest))
-            {
-              array_push($add_index_results,
-                sprintf(l10n('add_index_file_copied'), $file_dest));
-              $count_copy++;
-            }
-            else
-            {
-              array_push($page['errors'],
-                sprintf(l10n('add_index_file_not_copied'), $file_dest));
-              $count_error++;
-            }
+            array_push($add_index_results,
+              sprintf(l10n('add_index_file_copied'), $file_dest));
+            $count_copy++;
           }
           else
           {
-            $count_skip++;
+            array_push($page['errors'],
+              sprintf(l10n('add_index_file_not_copied'), $file_dest));
+            $count_error++;
           }
         }
+        else
+        {
+          $count_skip++;
+        }
       }
-      else
+    }
+    else
+    {
+      if (!empty($site_id))
       {
-        if (!empty($site_id))
-        {
-          array_push($page['errors'],
-            sprintf(l10n('add_index_not_local_site'), 
-              $galleries_url, $site_id));
-        }
+        array_push($page['errors'],
+          sprintf(l10n('add_index_not_local_site'), 
+            $galleries_url, $site_id));
       }
     }
