Index: /extensions/SmartAlbums/admin.php
===================================================================
--- /extensions/SmartAlbums/admin.php	(revision 11376)
+++ /extensions/SmartAlbums/admin.php	(revision 11376)
@@ -0,0 +1,30 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+global $conf, $template;
+load_language('plugin.lang', SMART_PATH);
+if (!is_array($conf['SmartAlbums'])) $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
+
+
+// Enregistrement de la configuration
+if (isset($_POST['submit']))
+{
+	$conf['SmartAlbums'] = array(
+    'update_on_upload' => $_POST['update_on_upload'], 
+    'update_on_login' => $_POST['update_on_login'], 
+    );    
+	
+  conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
+	array_push($page['infos'], l10n('Information data registered in database'));
+}
+
+$template->assign(array(
+  'SMART_PATH' => SMART_PATH,
+	'update_on_upload' => $conf['SmartAlbums']['update_on_upload'],
+	'update_on_login' => $conf['SmartAlbums']['update_on_login'],
+));
+	
+$template->set_filename('SmartAlbums_conf', dirname(__FILE__).'/template/admin.tpl');
+$template->assign_var_from_handle('ADMIN_CONTENT', 'SmartAlbums_conf');
+
+?>
Index: /extensions/SmartAlbums/include/functions.inc.php
===================================================================
--- /extensions/SmartAlbums/include/functions.inc.php	(revision 11375)
+++ /extensions/SmartAlbums/include/functions.inc.php	(revision 11376)
@@ -30,7 +30,49 @@
   }
   
+  if (!function_exists('set_rendom_representant'))
+  {
+    include(PHPWG_ROOT_PATH.'admin/include/functions.php');
+  }
   set_random_representant(array($cat_id));
   
   return $images;
+}
+
+
+/*
+ * Make associations for all SmartAlbums
+ * Called with invalidate_user_cache and/or on admin login
+ * @param string login (not mandatory)
+ */
+function smart_make_all_associations($login = false)
+{
+  global $conf;
+    
+  if (!is_array($conf['SmartAlbums'])) $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
+  
+  if ( !$login AND !defined('SMART_NOT_UPDATE') AND $conf['SmartAlbums']['update_on_upload'] != 'false' )
+    continue;
+  else if ( is_string($login) AND is_admin() AND $conf['SmartAlbums']['update_on_login'] != 'false' )
+    continue;
+  else
+    return;
+  
+  /* get categories with smart filters */
+  $query = '
+SELECT DISTINCT id
+  FROM '.CATEGORIES_TABLE.' AS c
+    INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
+    ON c.id = cf.category_id
+;';
+  
+  /* regenerate photo list */
+  $smart_cats = array_from_query($query, 'id');
+  array_map('smart_make_associations', $smart_cats);
+  
+  if (is_string($login))
+  {
+    define('SMART_NOT_UPDATE', 1);
+    invalidate_user_cache();
+  }
 }
 
Index: /extensions/SmartAlbums/include/init_cat_list.php
===================================================================
--- /extensions/SmartAlbums/include/init_cat_list.php	(revision 11375)
+++ /extensions/SmartAlbums/include/init_cat_list.php	(revision 11376)
@@ -9,5 +9,5 @@
 {
   global $template, $page, $smart_count;
-  include_once(SMART_PATH.'include/functions.inc.php');
+
   $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&amp;parent_id='.$_GET['parent_id'] : null);
   
@@ -70,5 +70,6 @@
     }
     
-    invalidate_user_cache(true);
+    define('SMART_NOT_UPDATE', 1);
+    invalidate_user_cache();
   }
   
Index: /extensions/SmartAlbums/include/init_cat_modify.php
===================================================================
--- /extensions/SmartAlbums/include/init_cat_modify.php	(revision 11375)
+++ /extensions/SmartAlbums/include/init_cat_modify.php	(revision 11376)
@@ -8,5 +8,4 @@
 {
   global $template, $page;
-  include_once(SMART_PATH.'include/functions.inc.php');
   
   $cat_id = $_GET['cat_id'];
@@ -62,6 +61,8 @@
       
       $associated_images = smart_make_associations($cat_id);
-      invalidate_user_cache(true);
       $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
+      
+      define('SMART_NOT_UPDATE', 1);
+      invalidate_user_cache();
     }
   }
Index: /extensions/SmartAlbums/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/SmartAlbums/language/en_UK/plugin.lang.php	(revision 11375)
+++ /extensions/SmartAlbums/language/en_UK/plugin.lang.php	(revision 11376)
@@ -23,4 +23,6 @@
 $lang['Regenerate photos list of this SmartAlbum'] = 'Regenerate photos list of this SmartAlbum';
 $lang['Regenerate photos list of all SmartAlbums'] = 'Regenerate photos list of all SmartAlbums';
+$lang['Update albums on file upload'] = 'Update albums on file upload';
+$lang['Update albums when an admin logins'] = 'Update albums when an admin logins';
 
 ?>
Index: /extensions/SmartAlbums/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/SmartAlbums/language/fr_FR/plugin.lang.php	(revision 11375)
+++ /extensions/SmartAlbums/language/fr_FR/plugin.lang.php	(revision 11376)
@@ -23,4 +23,6 @@
 $lang['Regenerate photos list of this SmartAlbum'] = 'Régénérer les photos de ce SmartAlbum';
 $lang['Regenerate photos list of all SmartAlbums'] = 'Régénérer les photos de tous les SmartAlbums';
+$lang['Update albums on file upload'] = 'Mettre à jour les albums après la mise en ligne d\'un fichier';
+$lang['Update albums when an admin logins'] = 'Mettre à jour les albums quand un admin se connecte';
 
 ?>
Index: /extensions/SmartAlbums/main.inc.php
===================================================================
--- /extensions/SmartAlbums/main.inc.php	(revision 11375)
+++ /extensions/SmartAlbums/main.inc.php	(revision 11376)
@@ -16,4 +16,8 @@
 define('CATEGORY_FILTERS_TABLE', $prefixeTable.'category_filters');
 
+add_event_handler('invalidate_user_cache', 'smart_make_all_associations');
+add_event_handler('login_success', 'smart_make_all_associations');
+include_once(SMART_PATH.'include/functions.inc.php');
+
 if (script_basename() == 'index')
 {
@@ -30,4 +34,13 @@
   add_event_handler('loc_begin_cat_list', 'smart_cat_list');
   include_once(SMART_PATH.'include/init_cat_list.php');
+  
+  add_event_handler('get_admin_plugin_menu_links', 'smart_admin_menu');
+	function smart_admin_menu($menu) 
+	{
+		array_push($menu, array(
+			'NAME' => 'SmartAlbums',
+			'URL' => get_root_url().'admin.php?page=plugin-' . SMART_DIR));
+		return $menu;
+	}
 }
 
Index: /extensions/SmartAlbums/maintain.inc.php
===================================================================
--- /extensions/SmartAlbums/maintain.inc.php	(revision 11375)
+++ /extensions/SmartAlbums/maintain.inc.php	(revision 11376)
@@ -2,5 +2,6 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
-function plugin_install() {
+function plugin_install() 
+{
 	global $prefixeTable;
 
@@ -16,17 +17,51 @@
   
   /* add a collumn to image_category_table */
-  pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM("true", "false") NOT NULL DEFAULT "false";');
+  pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` ADD `smart` ENUM(\'true\', \'false\') NOT NULL DEFAULT \'false\';');
       
   /* config parameter */
-  // pwg_query("INSERT INTO `" . CONFIG_TABLE . "`
-    // VALUES ('SmartAlbums', '', 'Configuration for SmartAlbums plugin');");
+  pwg_query('
+INSERT INTO `' . CONFIG_TABLE . '`
+  VALUES (
+    \'SmartAlbums\', 
+    \''.serialize(array(
+        'update_on_upload' => false,
+        'update_on_login' => false,
+        )
+      ).'\',
+    \'Configuration for SmartAlbums plugin\'
+  )
+;');
+
 }
 
-function plugin_uninstall() {
+function plugin_activate()
+{
+  global $conf;
+  
+  if (!isset($conf['SmartAlbums']))
+  {
+    pwg_query('
+INSERT INTO `' . CONFIG_TABLE . '`
+  VALUES (
+    \'SmartAlbums\', 
+    \''.serialize(array(
+        'update_on_upload' => false,
+        'update_on_login' => false,
+        )
+      ).'\',
+    \'Configuration for SmartAlbums plugin\'
+  )
+;');
+  }
+  
+}
+
+function plugin_uninstall() 
+{
 	global $prefixeTable;
   
   pwg_query('DROP TABLE `' . $prefixeTable . 'category_filters`;');
   pwg_query('ALTER TABLE `' . IMAGE_CATEGORY_TABLE . '` DROP `smart`;');
-  pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = "SmartAlbums";');
+  pwg_query('DELETE FROM `' . CONFIG_TABLE . '` WHERE param = \'SmartAlbums\';');
 }
 ?>
Index: /extensions/SmartAlbums/template/admin.tpl
===================================================================
--- /extensions/SmartAlbums/template/admin.tpl	(revision 11376)
+++ /extensions/SmartAlbums/template/admin.tpl	(revision 11376)
@@ -0,0 +1,23 @@
+<div class="titrePage">
+	<h2>SmartAlbums</h2>
+</div>
+
+<form method="post" action="" class="properties" ENCTYPE="multipart/form-data"> 
+	<fieldset>
+		<legend>{'Configuration'|@translate}</legend>	  
+		<ul>			
+			<li>
+				<span class="property">{'Update albums on file upload'|@translate}</span>
+				<label><input type="radio" name="update_on_upload" value="true" {if $update_on_upload == 'true'}checked="checked"{/if}/> {'Yes'|@translate}</label>
+				<label><input type="radio" name="update_on_upload" value="false" {if $update_on_upload == 'false'}checked="checked"{/if}/> {'No'|@translate}</label>
+			</li>
+			<li>
+				<span class="property">{'Update albums when an admin logins'|@translate}</span>
+				<label><input type="radio" name="update_on_login" value="true" {if $update_on_login == 'true'}checked="checked"{/if}/> {'Yes'|@translate}</label>
+				<label><input type="radio" name="update_on_login" value="false" {if $update_on_login == 'false'}checked="checked"{/if}/> {'No'|@translate}</label>
+			</li>   
+		</ul>
+	</fieldset>
+		
+	<p><input class="submit" type="submit" value="{'Submit'|@translate}" name="submit" /></p>
+</form>
