Index: /extensions/regenerateThumbnails/admin.php
===================================================================
--- /extensions/regenerateThumbnails/admin.php	(revision 9930)
+++ /extensions/regenerateThumbnails/admin.php	(revision 9931)
@@ -291,5 +291,4 @@
 
 $template->assign('element_set_global_action_tpl', dirname(__FILE__).'\element_set_global_action.tpl');
-$template->assign('redirect_url', get_root_url().'admin.php?page=plugin-'.basename(dirname(__FILE__)));
 $template->set_extent(dirname(__FILE__).'/regenerate_thumbnails.tpl', 'batch_manager_global');
 include(PHPWG_ROOT_PATH.'admin/batch_manager_global.php');
Index: /extensions/regenerateThumbnails/element_set_global_action.php
===================================================================
--- /extensions/regenerateThumbnails/element_set_global_action.php	(revision 9931)
+++ /extensions/regenerateThumbnails/element_set_global_action.php	(revision 9931)
@@ -0,0 +1,114 @@
+<?php
+
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+check_status(ACCESS_ADMINISTRATOR);
+
+global $template, $conf, $page, $pwg_loaded_plugins;
+
+load_language('plugin.lang', REGENERATE_THUMBNAILS_PATH);
+include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
+$upload_form_config = get_upload_form_config();
+
+$template->set_filename('regenerateThumbnails', realpath(REGENERATE_THUMBNAILS_PATH.'element_set_global_action.tpl'));
+
+if (isset($_POST['submit']) and $_POST['selectAction'] == 'regenerateThumbnails')
+{
+  if ($_POST['regenerateThumbnailsSuccess'] != '0')
+    array_push($page['infos'], sprintf(l10n('%s thumbnails have been regenerated'), $_POST['regenerateThumbnailsSuccess']));
+
+  if ($_POST['regenerateThumbnailsError'] != '0')
+    array_push($page['warnings'], sprintf(l10n('%s thumbnails can not be regenerated'), $_POST['regenerateThumbnailsError']));
+
+  // Update configuration
+  $fields = array('thumb_maxwidth', 'thumb_maxheight', 'thumb_quality');
+  foreach ($fields as $field)
+  {
+    if (!isset($upload_form_config[$field]))
+    {
+      continue;
+    }
+    $value = null;
+    if (!empty($_POST[$field]))
+    {
+      $value = $_POST[$field];
+    }
+
+    $min = $upload_form_config[$field]['min'];
+    $max = $upload_form_config[$field]['max'];
+    $pattern = $upload_form_config[$field]['pattern'];
+
+    if (preg_match($pattern, $value) and $value >= $min and $value <= $max)
+    {
+      $conf['upload_form_'.$field] = $value;
+       $updates[] = array(
+        'param' => 'upload_form_'.$field,
+        'value' => $value
+        );
+    }
+    else
+    {
+      array_push(
+        $page['errors'],
+        sprintf(
+          $upload_form_config[$field]['error_message'],
+          $min,
+          $max
+          )
+        );
+    }
+    $form_values[$field] = $value;
+  }
+  if (count($page['errors']) == 0)
+  {
+    mass_updates(
+      CONFIG_TABLE,
+      array(
+        'primary' => array('param'),
+        'update' => array('value')
+        ),
+      $updates
+      );
+  }
+
+  if (isset($pwg_loaded_plugins['square_thumbnails']))
+  {
+    $conf['upload_form_thumb_square'] = isset($_POST['square']);
+    conf_update_param('upload_form_thumb_square', $conf['upload_form_thumb_square']);
+  }
+
+  $template->delete_compiled_templates();
+}
+
+foreach ($upload_form_config as $param_shortname => $param)
+{
+  $param_name = 'upload_form_'.$param_shortname;
+  $form_values[$param_shortname] = $conf[$param_name];
+}
+
+if (isset($pwg_loaded_plugins['square_thumbnails']))
+{
+  load_language('plugin.lang', SQUARE_THUMB_PATH);
+  $template->assign(array('SQUARE' => @$conf['upload_form_thumb_square']));
+}
+
+$redirect_url = get_root_url().'admin.php?page='.$_GET['page'];
+if ($_GET['page'] == 'plugin')
+  $redirect_url .= '-regenerateThumbnails';
+
+$template->assign(array(
+  'upload_form_settings' => $form_values,
+  'all_elements' => $page['cat_elements_id'],
+  'redirect_url' => $redirect_url,
+  )
+);
+
+$template->append('element_set_global_plugins_actions', array(
+  'ID' => 'regenerateThumbnails',
+  'NAME' => l10n('Regenerate Thumbnails'),
+  'CONTENT' => $template->parse('regenerateThumbnails', true),
+  )
+);
+
+$template->set_prefilter('batch_manager_global', 'regenerate_prefilter');
+
+?>
Index: /extensions/regenerateThumbnails/element_set_global_action.tpl
===================================================================
--- /extensions/regenerateThumbnails/element_set_global_action.tpl	(revision 9930)
+++ /extensions/regenerateThumbnails/element_set_global_action.tpl	(revision 9931)
@@ -3,4 +3,5 @@
 
 {footer_script require='jquery.progressBar,jquery.ajaxmanager'}
+var elements = new Array();
 var all_elements = [{','|@implode:$all_elements}];
 var redirect = '{$redirect_url}';
@@ -13,8 +14,25 @@
 });
 
+function progress(val, max, success) {
+  jQuery('#progressBar').progressBar(val, {
+    max: max,
+    textFormat: 'fraction',
+    boxImage: 'plugins/regenerateThumbnails/images/progressbar.gif',
+    barImage: 'plugins/regenerateThumbnails/images/progressbg_orange.gif'
+  });
+  type = success ? 'regenerateThumbnailsSuccess': 'regenerateThumbnailsError'
+  s = jQuery('[name="'+type+'"]').val();
+  jQuery('[name="'+type+'"]').val(++s);
+
+  if (val == max)
+    jQuery('#applyAction').click();
+}
+
 jQuery(document).ready(function() {
   jQuery('#applyAction').click(function() {
     if (jQuery('[name="selectAction"]').val() == 'regenerateThumbnails') {
-      elements = new Array();
+      if (elements.length != 0)
+        return true;
+
       if (jQuery('input[name="setSelected"]').attr('checked'))
         elements = all_elements;
@@ -50,15 +68,6 @@
           },
           dataType: 'json',
-          success: ( function(data) {
-            if (data.stat =='ok')
-              jQuery('#progressBar').progressBar(++todo, {
-                max: progressBar_max,
-                textFormat: 'fraction',
-                boxImage: 'plugins/regenerateThumbnails/images/progressbar.gif',
-                barImage: 'plugins/regenerateThumbnails/images/progressbg_orange.gif'
-              });
-            if (todo == progressBar_max)
-              window.location = redirect;
-          })
+          success: ( function(data) { progress(++todo, progressBar_max, true) }),
+          error: ( function(data) { progress(++todo, progressBar_max, false) })
         });
       }
@@ -112,2 +121,5 @@
 <span class="progressBar" id="progressBar"></span>
 </div>
+
+<input type="hidden" name="regenerateThumbnailsSuccess" value="0">
+<input type="hidden" name="regenerateThumbnailsError" value="0">
Index: /extensions/regenerateThumbnails/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/regenerateThumbnails/language/en_UK/plugin.lang.php	(revision 9930)
+++ /extensions/regenerateThumbnails/language/en_UK/plugin.lang.php	(revision 9931)
@@ -3,5 +3,6 @@
 $lang['Regenerate Thumbnails'] = 'Regenerate Thumbnails';
 $lang['Thumbnails generation in progress...'] = 'Thumbnails generation in progress...';
-$lang['Thumbnails have been regenerated'] = 'Thumbnails have been regenerated';
+$lang['%s thumbnails have been regenerated'] = '%s thumbnails have been regenerated';
+$lang['%s thumbnails can not be regenerated'] = '%s thumbnails can not be regenerated';
 
 ?>
Index: /extensions/regenerateThumbnails/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/regenerateThumbnails/language/fr_FR/plugin.lang.php	(revision 9930)
+++ /extensions/regenerateThumbnails/language/fr_FR/plugin.lang.php	(revision 9931)
@@ -3,5 +3,6 @@
 $lang['Regenerate Thumbnails'] = 'Régénérer les miniatures';
 $lang['Thumbnails generation in progress...'] = 'Génération des miniatures en cours...';
-$lang['Thumbnails have been regenerated'] = 'Les miniatures ont été régénérées.';
+$lang['%s thumbnails have been regenerated'] = '%s miniatures ont été régénérées.';
+$lang['%s thumbnails can not be regenerated'] = '%s miniatures ne peuvent pas être régénérées';
 
 ?>
Index: /extensions/regenerateThumbnails/main.inc.php
===================================================================
--- /extensions/regenerateThumbnails/main.inc.php	(revision 9930)
+++ /extensions/regenerateThumbnails/main.inc.php	(revision 9931)
@@ -38,52 +38,5 @@
 function rg_element_set_global_add_action()
 {
-  global $template, $conf, $page, $pwg_loaded_plugins;
-
-  load_language('plugin.lang', REGENERATE_THUMBNAILS_PATH);
-  include_once(PHPWG_ROOT_PATH.'admin/include/functions_upload.inc.php');
-
-  $template->set_filename('regenerateThumbnails', realpath(REGENERATE_THUMBNAILS_PATH.'element_set_global_action.tpl'));
-
-  if (isset($_SESSION['regeneratedThumbnail']))
-  {
-    $template->delete_compiled_templates();
-    array_push($page['infos'], l10n('Thumbnails have been regenerated'));
-    unset($_SESSION['regeneratedThumbnail']);
-  }
-
-  foreach (get_upload_form_config() as $param_shortname => $param)
-  {
-    $param_name = 'upload_form_'.$param_shortname;
-    $form_values[$param_shortname] = $conf[$param_name];
-  }
-
-  if (isset($pwg_loaded_plugins['square_thumbnails']))
-  {
-    load_language('plugin.lang', SQUARE_THUMB_PATH);
-    $template->assign(array('SQUARE' => @$conf['upload_form_thumb_square']));
-  }
-
-  $redirect_url = get_root_url().'admin.php?page='.$_GET['page'];
-  if ($_GET['page'] == 'plugin')
-    $redirect_url .= '-regenerateThumbnails';
-  
-  $template->assign(array(
-    'upload_form_settings' => $form_values,
-    'all_elements' => $page['cat_elements_id'],
-    'redirect_url' => $redirect_url,
-    )
-  );
-
-  if ($template->get_template_vars('redirect_url') == null)
-    $template->assign('redirect_url', get_root_url().'admin.php?page='.$_GET['page']);
-
-  $template->append('element_set_global_plugins_actions', array(
-    'ID' => 'regenerateThumbnails',
-    'NAME' => l10n('Regenerate Thumbnails'),
-    'CONTENT' => $template->parse('regenerateThumbnails', true),
-    )
-  );
-
-  $template->set_prefilter('batch_manager_global', 'regenerate_prefilter');
+  include(REGENERATE_THUMBNAILS_PATH.'element_set_global_action.php');
 }
 
@@ -142,6 +95,4 @@
     );
 
-  $_SESSION['regeneratedThumbnail'] = true;
-
   return true;
 }
