Index: /extensions/SmartAlbums/admin.php
===================================================================
--- /extensions/SmartAlbums/admin.php	(revision 16103)
+++ /extensions/SmartAlbums/admin.php	(revision 16104)
@@ -4,22 +4,28 @@
 global $conf, $template, $page;
 
-load_language('plugin.lang', SMART_PATH);
-if (!is_array($conf['SmartAlbums'])) $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
+$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'cat_list';
 
-include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
-$page['tab'] = (isset($_GET['tab'])) ? $_GET['tab'] : $page['tab'] = 'albums';
-  
-$tabsheet = new tabsheet();
-$tabsheet->add('albums', l10n('All SmartAlbums'), SMART_ADMIN.'-albums');
-$tabsheet->add('config', l10n('Configuration'),   SMART_ADMIN.'-config');
-$tabsheet->select($page['tab']);
-$tabsheet->assign();
+if ($page['tab'] == 'album')
+{
+  include(SMART_PATH . 'admin/album.php');
+}
+else
+{
+  include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
+  $tabsheet = new tabsheet();
+  $tabsheet->add('cat_list', l10n('All SmartAlbums'), SMART_ADMIN.'-cat_list');
+  $tabsheet->add('config', l10n('Configuration'), SMART_ADMIN.'-config');
+  $tabsheet->select($page['tab']);
+  $tabsheet->assign();
 
-$template->assign(array(
-  'SMART_PATH' => SMART_PATH,
-));
+  $template->assign(array(
+    'SMART_PATH' => SMART_PATH,
+  ));
 
-include(SMART_PATH.'admin/'.$page['tab'].'.inc.php');
-$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/admin/template/'.$page['tab'].'.tpl');
+  include(SMART_PATH . 'admin/'.$page['tab'].'.php');
+}
+
+$template->assign('SMART_PATH', SMART_PATH);
+
 $template->assign_var_from_handle('ADMIN_CONTENT', 'SmartAlbums_content');
 
Index: /extensions/SmartAlbums/admin/album.php
===================================================================
--- /extensions/SmartAlbums/admin/album.php	(revision 16104)
+++ /extensions/SmartAlbums/admin/album.php	(revision 16104)
@@ -0,0 +1,252 @@
+<?php
+// +-----------------------------------------------------------------------+
+// | Piwigo - a PHP based photo gallery                                    |
+// +-----------------------------------------------------------------------+
+// | Copyright(C) 2008-2012 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  |
+// | 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.                                                                  |
+// +-----------------------------------------------------------------------+
+
+if(!defined("PHPWG_ROOT_PATH")) die ("Hacking attempt!");
+
+// +-----------------------------------------------------------------------+
+// | Basic checks                                                          |
+// +-----------------------------------------------------------------------+
+
+check_status(ACCESS_ADMINISTRATOR);
+
+check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
+
+$admin_album_base_url = get_root_url().'admin.php?page=album-'.$_GET['cat_id'];
+$self_url = SMART_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'];
+
+$query = '
+SELECT *
+  FROM '.CATEGORIES_TABLE.'
+  WHERE id = '.$_GET['cat_id'].'
+;';
+$category = pwg_db_fetch_assoc(pwg_query($query));
+
+if (!isset($category['id']))
+{
+  die("unknown album");
+}
+
+// +-----------------------------------------------------------------------+
+// | Tabs                                                                  |
+// +-----------------------------------------------------------------------+
+
+include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
+$tabsheet = new tabsheet();
+$tabsheet->add('properties', l10n('Properties'), $admin_album_base_url.'-properties');
+$tabsheet->add('sort_order', l10n('Manage photo ranks'), $admin_album_base_url.'-sort_order');
+$tabsheet->add('permissions', l10n('Permissions'), $admin_album_base_url.'-permissions');
+$tabsheet->add('notification', l10n('Notification'), $admin_album_base_url.'-notification');
+$tabsheet->add('smartalbum', 'SmartAlbum', $self_url);
+$tabsheet->select('smartalbum');
+$tabsheet->assign();
+
+
+$cat_id = $_GET['cat_id'];
+
+// category must be virtual
+if ($category['dir'] != NULL)
+{
+  die("physical album");
+}
+
+// +-----------------------------------------------------------------------+
+// | Save Filters                                                          |
+// +-----------------------------------------------------------------------+
+
+if (isset($_POST['submitFilters']))
+{
+  // test if it was a Smart Album
+  $query = '
+SELECT DISTINCT category_id 
+  FROM '.CATEGORY_FILTERS_TABLE.' 
+  WHERE category_id = '.$cat_id.'
+;';
+  $was_smart = pwg_db_num_rows(pwg_query($query));
+  
+  /* this album is no longer a SmartAlbum */
+  if ( $was_smart AND !isset($_POST['is_smart']) )
+  {
+    pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;');
+    pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
+    set_random_representant(array($cat_id));
+    invalidate_user_cache();
+  }
+  /* no filter selected */
+  else if ( isset($_POST['is_smart']) AND empty($_POST['filters']) )
+  {
+    array_push($page['errors'], l10n('No filter selected'));
+  }
+  /* everything is fine */
+  else if ( isset($_POST['is_smart']) )
+  {
+    pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
+    
+    foreach ($_POST['filters'] as $filter)
+    {
+      if (($filter = smart_check_filter($filter)) != false)
+      {
+        $query = '
+INSERT IGNORE INTO '.CATEGORY_FILTERS_TABLE.' 
+  VALUES(
+    '.$cat_id.', 
+    "'.$filter['type'].'", 
+    "'.$filter['cond'].'", 
+    "'.$filter['value'].'"
+  )
+;';
+      pwg_query($query);
+      }
+    }
+    
+    $associated_images = smart_make_associations($cat_id);
+    $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
+    
+    array_push($page['infos'], sprintf('%d photos associated to the album %s', count($associated_images), ''));
+    
+    define('SMART_NOT_UPDATE', 1);
+    invalidate_user_cache();
+  }
+}
+
+// +-----------------------------------------------------------------------+
+// | Display page                                                          |
+// +-----------------------------------------------------------------------+
+
+/* select options, for html_options */
+$template->assign(
+  'options', 
+  array(
+    'tags' => array(
+      'all'   => l10n('All these tags'),
+      'one'   => l10n('One of these tags'),
+      'none'  => l10n('None of these tags'),
+      'only'  => l10n('Only these tags'),
+      ),
+    'date' => array(
+      'the_post'      => l10n('Added on'),
+      'before_post'   => l10n('Added before'),
+      'after_post'    => l10n('Added after'),
+      'the_taken'     => l10n('Created on'),
+      'before_taken'  => l10n('Created before'),
+      'after_taken'   => l10n('Created after'),
+      ),
+    
+    'name' => array(
+      'contain'     => l10n('Contains'),
+      'begin'       => l10n('Begins with'),
+      'end'         => l10n('Ends with'),
+      'not_contain' => l10n('Doesn\'t contain'),
+      'not_begin'   => l10n('Doesn\'t begin with'),
+      'not_end'     => l10n('Doesn\'t end with'),
+      ),
+    'author' => array(
+      'is'      => l10n('Is'),
+      'in'      => l10n('Is in'),
+      'not_is'  => l10n('Is not'),
+      'not_in'  => l10n('Is not in'),
+      ),
+    'hit' => array(
+      'less' => l10n('Bellow'),
+      'more' => l10n('Above'),
+      ),
+    'level' => array('level' => 'level'), // second filter not used
+    'limit' => array('limit' => 'limit'), // second filter not used
+    )
+  );
+
+/* get filters for this album */
+$query = '
+SELECT * 
+  FROM '.CATEGORY_FILTERS_TABLE.' 
+  WHERE category_id = '.$cat_id.' 
+  ORDER BY 
+    type ASC, 
+    cond ASC
+;';
+$result = pwg_query($query);
+
+while ($filter = pwg_db_fetch_assoc($result))
+{
+  // get tags name and id
+  if ($filter['type'] == 'tags')
+  {
+    $query = '
+SELECT
+    id,
+    name
+  FROM '.TAGS_TABLE.'
+  WHERE id IN('.$filter['value'].')
+;';
+    $filter['value'] = get_taglist($query); 
+  }
+  
+  $template->append('filters', array(
+    'TYPE' => $filter['type'],
+    'COND' => $filter['cond'],
+    'VALUE' => $filter['value'],
+  ));
+}
+
+/* all tags */
+$query = '
+SELECT
+    id,
+    name
+  FROM '.TAGS_TABLE.'
+;';
+$all_tags = get_taglist($query);
+
+/* get image number */
+if ($template->get_template_vars('IMAGE_COUNT') == null)
+{
+  $query = '
+SELECT count(1) 
+  FROM '.IMAGE_CATEGORY_TABLE.' 
+  WHERE 
+    category_id = '.$cat_id.' 
+    AND smart = true
+';
+
+  list($image_num) = pwg_db_fetch_row(pwg_query($query));
+  $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num));
+}
+
+if (isset($_GET['new_smart']))
+{
+  $template->assign('new_smart', true);
+}
+
+$template->assign(array(
+  'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php',
+  'all_tags' => $all_tags,
+  'level_options' => get_privacy_level_options(),
+  'F_ACTION' => $self_url,
+  'CATEGORIES_NAV' => get_cat_display_name_cache(
+    $category['uppercats'],
+    SMART_ADMIN.'-album&amp;cat_id='
+    ),
+));
+
+$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/album.tpl');
+
+?>
Index: tensions/SmartAlbums/admin/albums.inc.php
===================================================================
--- /extensions/SmartAlbums/admin/albums.inc.php	(revision 16103)
+++ 	(revision )
@@ -1,179 +1,0 @@
-<?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-if (isset($_GET['hide_messages']))
-{
-  $conf['SmartAlbums']['show_list_messages'] = false;
-  conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
-}
-
-// +-----------------------------------------------------------------------+
-// |                            initialization                             |
-// +-----------------------------------------------------------------------+
-$base_url = get_root_url().'admin.php?page=';
-$self_url = SMART_ADMIN.'-albums';
-
-$categories = array();
-$query = '
-SELECT id, name, permalink, dir, rank, status
-  FROM '.CATEGORIES_TABLE.' AS cat
-  INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
-    ON cf.category_id = cat.id
-  ORDER BY rank ASC
-;';
-$categories = hash_from_query($query, 'id');
-
-// +-----------------------------------------------------------------------+
-// |                    virtual categories management                      |
-// +-----------------------------------------------------------------------+
-// request to delete a album
-if (isset($_GET['delete']) and is_numeric($_GET['delete']))
-{
-  delete_categories(array($_GET['delete']));
-  $_SESSION['page_infos'] = array(l10n('SmartAlbum deleted'));
-  update_global_rank();
-  redirect($self_url);
-}
-// request to add a album
-else if (isset($_POST['submitAdd']))
-{
-  $output_create = create_virtual_category(
-    $_POST['virtual_name'],
-    @$_POST['parent_id']
-    );
-
-  if (isset($output_create['error']))
-  {
-    array_push($page['errors'], $output_create['error']);
-  }
-  else
-  {
-    $_SESSION['page_infos'] = array(l10n('SmartAlbum added'));
-    $redirect_url = $base_url.'cat_modify&amp;cat_id='.$output_create['id'].'&amp;new_smart';
-    redirect($redirect_url);
-  }
-}
-// request to regeneration
-else if (isset($_GET['smart_generate']))
-{
-  /* regenerate photo list | all (sub) categories */
-  if ($_GET['smart_generate'] == 'all')
-  {
-    foreach ($categories as $category)
-    {
-      $associated_images = smart_make_associations($category['id']);
-      array_push(
-        $page['infos'], 
-        sprintf(
-          l10n('%d photos associated to album %s'), 
-          count($associated_images), 
-          '&laquo;'.trigger_event(
-            'render_category_name',
-            $category['name'],
-            'admin_cat_list'
-            ).'&raquo;'
-          )
-        );
-    }
-  }
-  /* regenerate photo list | one category */
-  else
-  {
-    $associated_images = smart_make_associations($_GET['smart_generate']);    
-    array_push(
-      $page['infos'], 
-      sprintf(
-        l10n('%d photos associated to album %s'), 
-        count($associated_images), 
-        '&laquo;'.trigger_event(
-          'render_category_name',
-          $categories[$_GET['smart_generate']]['name'],
-          'admin_cat_list'
-          ).'&raquo;'
-        )
-      );
-  }
-  
-  define('SMART_NOT_UPDATE', 1);
-  invalidate_user_cache();
-}
-
-// +-----------------------------------------------------------------------+
-// |                       template initialization                         |
-// +-----------------------------------------------------------------------+
-$template->assign(array(
-  'F_ACTION' => $self_url,
-  'PWG_TOKEN' => get_pwg_token(),
- ));
- 
-// retrieve all existing categories for album creation
-$query = '
-SELECT id,name,uppercats,global_rank
-  FROM '.CATEGORIES_TABLE.'
-;';
-
-display_select_cat_wrapper(
-  $query,
-  null,
-  'category_options'
-  );
-  
-if ($conf['SmartAlbums']['show_list_messages'])
-{
-  array_push($page['warnings'], l10n('Only SmartAlbums are displayed on this page'));
-  array_push($page['warnings'], l10n('To order albums please go the main albums management page'));
-  array_push($page['warnings'], '<a href="'.$self_url.'&hide_messages">['.l10n('Don\'t show this message again').']</a>');
-}
-
-// +-----------------------------------------------------------------------+
-// |                          Categories display                           |
-// +-----------------------------------------------------------------------+
-
-// get the categories containing images directly 
-$categories_with_images = array();
-if ( count($categories) )
-{
-  $query = '
-SELECT DISTINCT category_id 
-  FROM '.IMAGE_CATEGORY_TABLE.'
-  WHERE category_id IN ('.implode(',', array_keys($categories)).')';
-  $categories_with_images = array_flip( array_from_query($query, 'category_id') );
-}
-
-$template->assign('categories', array());
-
-foreach ($categories as $category)
-{
-  $tpl_cat =
-    array(
-      'NAME'       => get_cat_display_name_from_id($category['id'], $base_url.'cat_modify&amp;cat_id='),
-      'ID'         => $category['id'],
-      'RANK'       => $category['rank']*10,
-
-      'U_JUMPTO'   => make_index_url(
-        array(
-          'category' => $category
-          )
-        ),
-
-      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
-      'U_DELETE'   => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
-      'U_SMART'    => $self_url.'&amp;smart_generate='.$category['id'],
-    );
-
-  if ( array_key_exists($category['id'], $categories_with_images) )
-  {
-    $tpl_cat['U_MANAGE_ELEMENTS'] =
-      $base_url.'batch_manager&amp;cat='.$category['id'];
-  }
-
-  if ('private' == $category['status'])
-  {
-    $tpl_cat['U_MANAGE_PERMISSIONS'] =
-      $base_url.'cat_perm&amp;cat='.$category['id'];
-  }
-  
-  $template->append('categories', $tpl_cat);
-}
-
-?>
Index: /extensions/SmartAlbums/admin/cat_list.php
===================================================================
--- /extensions/SmartAlbums/admin/cat_list.php	(revision 16104)
+++ /extensions/SmartAlbums/admin/cat_list.php	(revision 16104)
@@ -0,0 +1,169 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+if (isset($_GET['hide_messages']))
+{
+  $conf['SmartAlbums']['show_list_messages'] = false;
+  conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
+}
+
+// +-----------------------------------------------------------------------+
+// |                            initialization                             |
+// +-----------------------------------------------------------------------+
+$base_url = get_root_url() . 'admin.php?page=';
+$self_url = SMART_ADMIN . '-cat_list';
+
+$categories = array();
+$query = '
+SELECT 
+    id,
+    name,
+    permalink,
+    dir,
+    rank,
+    status
+  FROM '.CATEGORIES_TABLE.' AS cat
+  INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
+    ON cf.category_id = cat.id
+  ORDER BY rank ASC
+;';
+$categories = hash_from_query($query, 'id');
+
+// +-----------------------------------------------------------------------+
+// |                    virtual categories management                      |
+// +-----------------------------------------------------------------------+
+// request to delete a album
+if (isset($_GET['delete']) and is_numeric($_GET['delete']))
+{
+  delete_categories(array($_GET['delete']));
+  $_SESSION['page_infos'] = array(l10n('SmartAlbum deleted'));
+  update_global_rank();
+  redirect($self_url);
+}
+// request to add a album
+else if (isset($_POST['submitAdd']))
+{
+  $output_create = create_virtual_category(
+    $_POST['virtual_name'],
+    @$_POST['parent_id']
+    );
+
+  if (isset($output_create['error']))
+  {
+    array_push($page['errors'], $output_create['error']);
+  }
+  else
+  {
+    $_SESSION['page_infos'] = array(l10n('SmartAlbum added'));
+    $redirect_url = SMART_ADMIN . '-album&amp;cat_id='.$output_create['id'].'&amp;new_smart';
+    redirect($redirect_url);
+  }
+}
+// request to regeneration
+else if (isset($_GET['smart_generate']))
+{
+  /* regenerate photo list | all categories */
+  if ($_GET['smart_generate'] == 'all')
+  {
+    foreach ($categories as $category)
+    {
+      $associated_images = smart_make_associations($category['id']);
+      array_push($page['infos'], 
+        sprintf(l10n('%d photos associated to album %s'), 
+          count($associated_images), 
+          '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
+          )
+        );
+    }
+  }
+  /* regenerate photo list | one category */
+  else
+  {
+    $associated_images = smart_make_associations($_GET['smart_generate']);    
+    array_push($page['infos'], 
+      sprintf(l10n('%d photos associated to album %s'), 
+        count($associated_images), 
+        '&laquo;'.trigger_event('render_category_name', $categories[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
+        )
+      );
+  }
+  
+  define('SMART_NOT_UPDATE', 1);
+  invalidate_user_cache();
+}
+
+// +-----------------------------------------------------------------------+
+// |                       template initialization                         |
+// +-----------------------------------------------------------------------+
+$template->assign(array(
+  'F_ACTION' => $self_url,
+  'PWG_TOKEN' => get_pwg_token(),
+ ));
+ 
+// retrieve all existing categories for album creation
+$query = '
+SELECT id,name,uppercats,global_rank
+  FROM '.CATEGORIES_TABLE.'
+;';
+
+display_select_cat_wrapper(
+  $query,
+  null,
+  'category_options'
+  );
+  
+if ($conf['SmartAlbums']['show_list_messages'])
+{
+  array_push($page['warnings'], l10n('Only SmartAlbums are displayed on this page'));
+  array_push($page['warnings'], sprintf(l10n('To order albums please go the main albums <a href="%s">management page</a>'), $base_url.'cat_list'));
+  array_push($page['warnings'], '<a href="'.$self_url.'&hide_messages">['.l10n('Don\'t show this message again').']</a>');
+}
+
+// +-----------------------------------------------------------------------+
+// |                          Categories display                           |
+// +-----------------------------------------------------------------------+
+
+// get the categories containing images directly 
+$categories_with_images = array();
+if ( count($categories) )
+{
+  $query = '
+SELECT DISTINCT category_id 
+  FROM '.IMAGE_CATEGORY_TABLE.'
+  WHERE category_id IN ('.implode(',', array_keys($categories)).')';
+  $categories_with_images = array_flip( array_from_query($query, 'category_id') );
+}
+
+$template->assign('categories', array());
+
+foreach ($categories as $category)
+{
+  $tpl_cat =
+    array(
+      'NAME'       => get_cat_display_name_from_id($category['id'], $base_url.'album-'),
+      'ID'         => $category['id'],
+      'RANK'       => $category['rank']*10,
+
+      'U_JUMPTO'   => make_index_url(
+        array(
+          'category' => $category
+          )
+        ),
+
+      'U_EDIT'     => $base_url.'album-'.$category['id'],
+      'U_DELETE'   => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
+      'U_SMART'    => $self_url.'&amp;smart_generate='.$category['id'],
+    );
+
+  if ( array_key_exists($category['id'], $categories_with_images) )
+  {
+    $tpl_cat['U_MANAGE_ELEMENTS'] =
+      $base_url.'batch_manager&amp;cat='.$category['id'];
+  }
+  
+  $template->append('categories', $tpl_cat);
+}
+
+$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/cat_list.tpl');
+
+?>
Index: tensions/SmartAlbums/admin/config.inc.php
===================================================================
--- /extensions/SmartAlbums/admin/config.inc.php	(revision 16103)
+++ 	(revision )
@@ -1,17 +1,0 @@
-<?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-// Enregistrement de la configuration
-if (isset($_POST['submit']))
-{
-  $conf['SmartAlbums']['update_on_upload'] = isset($_POST['update_on_upload']);
-  
-  conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
-  array_push($page['infos'], l10n('Information data registered in database'));
-}
-
-$template->assign(array(
-  'update_on_upload' => $conf['SmartAlbums']['update_on_upload'],
-));
-
-?>
Index: /extensions/SmartAlbums/admin/config.php
===================================================================
--- /extensions/SmartAlbums/admin/config.php	(revision 16104)
+++ /extensions/SmartAlbums/admin/config.php	(revision 16104)
@@ -0,0 +1,19 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+// Enregistrement de la configuration
+if (isset($_POST['submit']))
+{
+  $conf['SmartAlbums']['update_on_upload'] = isset($_POST['update_on_upload']);
+  
+  conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
+  array_push($page['infos'], l10n('Information data registered in database'));
+}
+
+$template->assign(array(
+  'update_on_upload' => $conf['SmartAlbums']['update_on_upload'],
+));
+
+$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/config.tpl');
+
+?>
Index: /extensions/SmartAlbums/admin/index.php
===================================================================
--- /extensions/SmartAlbums/admin/index.php	(revision 16103)
+++ /extensions/SmartAlbums/admin/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?php
-// +-----------------------------------------------------------------------+
-// | Piwigo - a PHP based photo gallery                                    |
-// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 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  |
-// | 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 );
Index: /extensions/SmartAlbums/admin/template/album.tpl
===================================================================
--- /extensions/SmartAlbums/admin/template/album.tpl	(revision 16104)
+++ /extensions/SmartAlbums/admin/template/album.tpl	(revision 16104)
@@ -0,0 +1,204 @@
+{combine_css path=$SMART_PATH|@cat:"admin/template/style.css"}
+{include file='include/datepicker.inc.tpl'}
+{combine_script id='jquery.tokeninput' load='async' require='jquery' path='themes/default/js/plugins/jquery.tokeninput.js'}
+
+{footer_script require='jquery.tokeninput'}
+var lang = new Array();
+var options = new Array();
+
+{foreach from=$options item=details key=mode}
+  lang['{$mode}_filter'] = '{$mode|cat:'_filter'|@translate|escape:javascript}';
+  {capture assign="option_content"}{html_options options=$details}{/capture}
+  options['{$mode}'] = "{$option_content|escape:javascript}";
+{/foreach}
+
+lang['For "Is (not) in", separate each author by a comma'] = '{'For "Is (not) in", separate each author by a comma'|@translate|escape:javascript}';
+lang['remove this filter'] = '{'remove this filter'|@translate|escape:javascript}';
+{capture assign="option_content"}{html_options options=$level_options selected=0}{/capture}
+options['level_options'] = "{$option_content|escape:javascript}";
+
+{literal}
+$('#addFilter').change(function() {
+  add_filter($(this).attr('value'));
+  $(this).attr('value', '-1');
+});
+  
+$('#removeFilters').click(function() {
+  $('#filterList li').each(function() {
+    $(this).remove();
+  });
+  return false;
+});
+
+$('input[name="is_smart"]').change(function() {
+  $('#SmartAlbum_options').toggle();
+  $('input[name="countImages"]').toggle();
+  $('.count_images_wrapper').toggle();
+});
+
+$('input[name="countImages"]').click(function() {
+  countImages($("#smart"));
+  return false;
+});
+
+
+function add_filter(type) {
+  // add line
+  $('<li class="filter_'+ type +'" id="filter_'+ i +'"></li>').appendTo('#filterList');
+  
+  //set content
+  content = 
+    ' <span class="filter-title">'+
+      ' <a href="#" class="removeFilter" title="'+ lang['remove this filter'] +'"><span>[x]</span></a>'+
+      ' <input type="hidden" name="filters['+ i +'][type]" value="'+ type +'"/>&nbsp;'+ lang[type +'_filter'] +
+    '</span>'+
+    ' <span class="filter-cond">'+
+      ' <select name="filters['+ i +'][cond]">'+ options[type] +'</select>'+
+    '</span>'+
+    ' <span class="filter-value">';
+  
+  if (type == 'tags')
+    content+= ' <select name="filters['+ i +'][value]" class="tagSelect"></select>';
+  else if (type == 'level')
+    content+= ' <select name="filters['+ i +'][value]">'+ options['level_options'] +'</select>';
+  else
+    content+= ' <input type="text" name="filters['+ i +'][value]" size="30"/>';
+  
+  if (type == 'author')
+    content+= ' <i>'+ lang['For "Is (not) in", separate each author by a comma'] +'</i>';
+    
+  content+= '</span>';
+  
+  $('#filter_'+ i).html(content);
+  
+  // reinit handlers
+  init_jquery_handlers();
+  i++;
+}
+
+function init_jquery_handlers() {  
+  $('.removeFilter').click(function() {
+    $(this).parents('li').remove();
+    return false;
+  });
+
+  $('.filter_date input[type="text"]').each(function() {
+    $(this).datepicker({dateFormat:'yy-mm-dd', firstDay:1});
+  });
+  
+  jQuery(".tagSelect").tokenInput(
+  {/literal}
+    [{foreach from=$all_tags item=tag name=tags}{ldelim}"name":"{$tag.name|@escape:'javascript'}","id":"{$tag.id}"{rdelim}{if !$smarty.foreach.tags.last},{/if}{/foreach}],
+    {ldelim}
+      hintText: '{'Type in a search term'|@translate}',
+      noResultsText: '{'No results'|@translate}',
+      searchingText: '{'Searching...'|@translate}',
+      animateDropdown: false,
+      preventDuplicates: true,
+      allowCreation: false
+  {literal}
+    }
+  );
+}
+
+function countImages(form) {
+{/literal}
+  jQuery.post("{$COUNT_SCRIPT_URL}", 'cat_id={$CAT_ID}&'+form.serialize(),
+{literal}
+    function success(data) {
+      jQuery('.count_images_wrapper').html(data);
+    }
+  );
+}
+
+function doBlink(obj,start,finish) { 
+  jQuery(obj).fadeOut(400).fadeIn(400); 
+  if(start!=finish) { 
+    doBlink(obj,start+1,finish);
+  } else {
+    jQuery(obj).fadeOut(400);
+  }
+}
+  
+init_jquery_handlers();
+{/literal}
+{if isset($new_smart)}doBlink('.new_smart', 0, 3);{/if}
+{/footer_script}
+
+<div class="titrePage">
+  <h2><span style="letter-spacing:0">{$CATEGORIES_NAV}</span> &#8250; {'Edit album'|@translate} [SmartAlbum]</h2>
+</div>
+
+<div id="batchManagerGlobal">
+<form action="{$F_ACTION}" method="POST" id="smart">
+  <p style="text-align:left;"><label><input type="checkbox" name="is_smart" {if isset($filters) OR isset($new_smart)}checked="checked"{/if}/> {'This album is a SmartAlbum'|@translate}</label></p>
+
+  <fieldset id="SmartAlbum_options" style="margin-top:1em;{if !isset($filters) AND !isset($new_smart)}display:none;{/if}">
+    <legend>{'Filters'|@translate}</legend>
+      
+    <ul id="filterList">
+      {counter start=0 assign=i}
+      {foreach from=$filters item=filter}
+        <li class="filter_{$filter.TYPE}" id="filter_{$i}">
+          <span class="filter-title">
+            <a href="#" class="removeFilter" title="{'remove this filter'|@translate}"><span>[x]</span></a>
+            <input type="hidden" name="filters[{$i}][type]" value="{$filter.TYPE}"/>
+            {$filter.TYPE|cat:'_filter'|@translate}
+          </span>
+          
+          <span class="filter-cond">
+            <select name="filters[{$i}][cond]">
+              {html_options options=$options[$filter.TYPE] selected=$filter.COND}
+            </select>
+          </span>
+          
+          <span class="filter-value">
+          {if $filter.TYPE == 'tags'}
+            <select name="filters[{$i}][value]" class="tagSelect">
+            {foreach from=$filter.VALUE item=tag}
+              <option value="{$tag.id}" class="selected">{$tag.name}</option>
+            {/foreach}
+            </select>
+          {elseif $filter.TYPE == 'level'}
+            <select name="filters[{$i}][value]">
+              {html_options options=$level_options selected=$filter.VALUE}
+            </select>
+          {else}
+            <input type="text" name="filters[{$i}][value]" value="{$filter.VALUE}" size="30"/>
+          {/if}
+          {if $filter.TYPE == 'author'}
+            <i>{'For "Is (not) in", separate each author by a comma'|@translate}</i>
+          {/if}
+          </span>
+        </li>
+        {counter}
+      {/foreach}
+      
+      {footer_script}var i={$i};{/footer_script}
+    </ul>
+
+    <p class="actionButtons">
+        <select id="addFilter">
+          <option value="-1">{'Add a filter'|@translate}</option>
+          <option disabled="disabled">------------------</option>
+          <option value="tags">{'tags_filter'|@translate}</option>
+          <option value="date">{'date_filter'|@translate}</option>
+          <option value="name">{'name_filter'|@translate}</option>
+          <option value="author">{'author_filter'|@translate}</option>
+          <option value="hit">{'hit_filter'|@translate}</option>
+          <option value="level">{'level_filter'|@translate}</option>
+          <option value="limit">{'limit_filter'|@translate}</option>
+        </select>
+        <a id="removeFilters">{'Remove all filters'|@translate}</a>
+        {if isset($new_smart)}<span class="new_smart">{'Add filters here'|@translate}</span>{/if}
+    </p>
+  </fieldset>
+
+  <p class="actionButtons" id="applyFilterBlock">
+    <input class="submit" type="submit" value="{'Submit'|@translate}" name="submitFilters"/>
+    <input class="submit" type="submit" value="{'Count'|@translate}" name="countImages" {if !isset($filters) AND !isset($new_smart)}style="display:none;"{/if}/>
+    <span class="count_images_wrapper" {if !isset($filters) AND !isset($new_smart)}style="display:none;"{/if}><span class="count_image">{$IMAGE_COUNT}</span></span>
+  </p>
+
+</form>
+</div>
Index: tensions/SmartAlbums/admin/template/albums.tpl
===================================================================
--- /extensions/SmartAlbums/admin/template/albums.tpl	(revision 16103)
+++ 	(revision )
@@ -1,70 +1,0 @@
-<div class="titrePage">
-	<h2>SmartAlbums</h2>
-</div>
-
-<h3>
-  <a href="{$F_ACTION}">{'All SmartAlbums'|@translate}</a>
-  {if count($categories)>9 }
-  <a href="#EoP" class="button" style="border:0;">
-  <img src="{$themeconf.admin_icon_dir}/page_end.png" title="{'Page end'|@translate}" class="button" alt="page_end" style="margin-bottom:-0.6em;"></a>
-  {/if}
-</h3>
-
-<form id="addVirtual" action="{$F_ACTION}" method="post">
-  <fieldset>
-    <legend>{'Add a SmartAlbum'|@translate}</legend>
-  
-    <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
-    {'Album name'|@translate} : <input type="text" name="virtual_name">
-    {'Parent album'|@translate} :
-    <select class="categoryDropDown" name="parent_id">
-      <option value="0">------------</option>
-      {html_options options=$category_options}
-    </select>
-    <input class="submit" type="submit" value="{'Submit'|@translate}" name="submitAdd">
-  
-  </fieldset>
-</form>
-
-{if count($categories) }
-<form id="categoryOrdering" action="{$F_ACTION}" method="post">
-  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
-
-  <ul class="categoryUl">
-
-    {foreach from=$categories item=category}
-    <li class="categoryLi virtual_cat" id="cat_{$category.ID}">
-      <!-- category {$category.ID} -->
-      <ul class="categoryActions">
-        {if cat_admin_access($category.ID)}
-        <li><a href="{$category.U_JUMPTO}" title="{'jump to album'|@translate}"><img src="{$themeconf.admin_icon_dir}/category_jump-to.png" class="button" alt="{'jump to album'|@translate}"></a></li>
-        {/if}
-        <li><a href="{$category.U_EDIT}" title="{'edit album'|@translate}"><img src="{$themeconf.admin_icon_dir}/category_edit.png" class="button" alt="{'edit'|@translate}"></a></li>
-        {if isset($category.U_MANAGE_ELEMENTS) }
-        <li><a href="{$category.U_MANAGE_ELEMENTS}" title="{'manage album photos'|@translate}"><img src="{$themeconf.admin_icon_dir}/category_elements.png" class="button" alt="{'Photos'|@translate}"></a></li>
-        {/if}
-        {if isset($category.U_MANAGE_PERMISSIONS) }
-        <li><a href="{$category.U_MANAGE_PERMISSIONS}" title="{'edit album permissions'|@translate}" ><img src="{$themeconf.admin_icon_dir}/category_permissions.png" class="button" alt="{'Permissions'|@translate}"></a></li>
-        {/if}
-        <li><a href="{$category.U_SMART}" title="{'Regenerate photos list of this SmartAlbum'|@translate}"><img src="{$themeconf.admin_icon_dir}/synchronize.png" class="button" alt="{'Regenerate photos list of this SmartAlbum'|@translate}"></a></li>
-        {if isset($category.U_DELETE) }
-        <li><a href="{$category.U_DELETE}" title="{'delete album'|@translate}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');"><img src="{$themeconf.admin_icon_dir}/category_delete.png" class="button" alt="{'delete album'|@translate}"></a></li>
-        {/if}
-      </ul>
-
-      <p>
-        <strong>{$category.NAME}</strong>
-      </p>
-
-    </li>
-    {/foreach}
-  </ul>
-</form>
-{/if}
-
-<form method="post" action="{$F_ACTION}&amp;smart_generate=all">
-  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
-  <p><input class="submit" type="submit" value="{'Regenerate photos list of all SmartAlbums'|@translate}"></p>
-</form>
-
-<a name="EoP"></a>
Index: /extensions/SmartAlbums/admin/template/cat_list.tpl
===================================================================
--- /extensions/SmartAlbums/admin/template/cat_list.tpl	(revision 16104)
+++ /extensions/SmartAlbums/admin/template/cat_list.tpl	(revision 16104)
@@ -0,0 +1,81 @@
+{footer_script require='jquery.ui.sortable'}{literal}
+jQuery(document).ready(function(){
+  jQuery("#addAlbumOpen").click(function(){
+    jQuery("#createAlbum").toggle();
+    jQuery("input[name=virtual_name]").focus();
+    jQuery("#autoOrder").hide();
+  });
+
+  jQuery("#addAlbumClose").click(function(){
+    jQuery("#createAlbum").hide();
+  });
+});
+{/literal}{/footer_script}
+
+{* è *}
+
+<div class="titrePage">
+	<h2>SmartAlbums</h2>
+</div>
+
+<form id="categoryOrdering" action="{$F_ACTION}" method="post">
+<input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
+
+<p class="showCreateAlbum">
+  <span id="notManualOrder">
+    <a href="#" id="addAlbumOpen">{'create a new SmartAlbum'|@translate}</a>
+    | <a href="{$F_ACTION}&amp;smart_generate=all">{'Regenerate photos list of all SmartAlbums'|@translate}</a>
+  </span>
+</p>
+
+<fieldset id="createAlbum" style="display:none;">
+  <legend>{'create a new SmartAlbum'|@translate}</legend>
+  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
+
+  <p>
+    <strong>{'Album name'|@translate}</strong> :
+    <input type="text" name="virtual_name">
+  </p>
+  <p>
+    <strong>{'Parent album'|@translate}</strong>  :
+    <select class="categoryDropDown" name="parent_id">
+      <option value="0">------------</option>
+      {html_options options=$category_options}
+    </select>
+  </p>
+  <p class="actionButtons">
+    <input class="submit" type="submit" value="{'Create'|@translate}" name="submitAdd">
+    <a href="#" id="addAlbumClose">{'Cancel'|@translate}</a>
+  </p>
+</fieldset>
+
+{if count($categories) }
+
+  <ul class="categoryUl">
+
+    {foreach from=$categories item=category}
+    <li class="categoryLi virtual_cat" id="cat_{$category.ID}">
+      <!-- category {$category.ID} -->
+      <p class="albumTitle">
+        <strong><a href="{$category.U_CHILDREN}" title="{'manage sub-albums'|@translate}">{$category.NAME}</a></strong>
+        <img src="{$SMART_PATH}admin/template/lightning.png">
+      </p>
+
+      <p class="albumActions">
+        <a href="{$category.U_EDIT}">{'Edit'|@translate}</a>
+        | <a href="{$category.U_SMART}">{'Regenerate photos list of this SmartAlbum'|@translate}</a>
+        {if isset($category.U_MANAGE_ELEMENTS) }
+        | <a href="{$category.U_MANAGE_ELEMENTS}">{'manage album photos'|@translate}</a>
+        {/if}
+        {if isset($category.U_DELETE) }
+        | <a href="{$category.U_DELETE}" onclick="return confirm('{'Are you sure?'|@translate|@escape:javascript}');">{'delete album'|@translate}</a>
+        {/if}
+        {if cat_admin_access($category.ID)}
+        | <a href="{$category.U_JUMPTO}">{'jump to album'|@translate} ?</a>
+        {/if}
+      </p>
+    </li>
+    {/foreach}
+  </ul>
+{/if}
+</form>
Index: /extensions/SmartAlbums/admin/template/config.tpl
===================================================================
--- /extensions/SmartAlbums/admin/template/config.tpl	(revision 16103)
+++ /extensions/SmartAlbums/admin/template/config.tpl	(revision 16104)
@@ -11,5 +11,5 @@
           <span class="property">{'Update albums on file upload'|@translate}</span>
           <input type="checkbox" name="update_on_upload" value="true" {if $update_on_upload}checked="checked"{/if}/>
-          {'(can cause slowdowns on admin pages)'|@translate}
+          {'(can cause slowdowns)'|@translate}
         </label>
 			</li>
Index: /extensions/SmartAlbums/admin/template/index.php
===================================================================
--- /extensions/SmartAlbums/admin/template/index.php	(revision 16103)
+++ /extensions/SmartAlbums/admin/template/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?php
-// +-----------------------------------------------------------------------+
-// | Piwigo - a PHP based photo gallery                                    |
-// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 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  |
-// | 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 );
Index: /extensions/SmartAlbums/admin/template/style.css
===================================================================
--- /extensions/SmartAlbums/admin/template/style.css	(revision 16104)
+++ /extensions/SmartAlbums/admin/template/style.css	(revision 16104)
@@ -0,0 +1,61 @@
+.token-input-list {
+  display:inline-block;
+  vertical-align:bottom;
+}
+#batchManagerGlobal #filterList li.token-input-token {
+  margin-bottom:0px !important;
+  padding-top:0;
+}
+#batchManagerGlobal #filterList li.token-input-input-token {
+  margin-bottom:-3px !important; 
+}
+
+.new_smart {
+  color:#00AA00;
+  background-color:#C2F5C2;
+  font-weight:bold;
+  padding:3px 10px;
+  border-radius:4px;
+}
+
+#filterList li {
+  padding:2px;
+  border-bottom:1px dotted rgba(100, 100, 100, 0.5);
+}
+#filterList li span {
+  display:inline-block;
+}
+#filterList li span * {
+  vertical-align:middle;
+}
+
+.filter-title {
+  padding-left:10px;
+  width:220px;
+}
+.filter-title:after {
+  content:" :";
+}
+.filter-cond {
+  width:220px;
+}
+
+.filter_limit .filter-cond, .filter_level .filter-cond {
+  display:none !important;
+}
+
+.filter_error {
+  background-color: #FFD5DC;
+  color: #FF2222;
+  padding:3px 10px;
+  font-weight:bold;
+  border-radius:4px;
+}
+
+.count_image {
+  color:#00AA00;
+  background-color:#C2F5C2;
+  font-weight:bold;
+  padding:3px 10px;
+  border-radius:4px;
+}
Index: /extensions/SmartAlbums/include/cat_list.php
===================================================================
--- /extensions/SmartAlbums/include/cat_list.php	(revision 16104)
+++ /extensions/SmartAlbums/include/cat_list.php	(revision 16104)
@@ -0,0 +1,111 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+/**
+ * Add a link into categories list to regenerate associations
+ */
+$smart_count = 0;
+
+function smart_cat_list()
+{
+  global $template, $page, $smart_count;
+
+  $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&amp;parent_id='.$_GET['parent_id'] : null);
+  
+  /* get categories with smart filters */
+  $query = '
+SELECT DISTINCT id, name 
+  FROM '.CATEGORIES_TABLE.' AS c
+    INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
+      ON c.id = cf.category_id';
+  if (!isset($_GET['parent_id']))
+  {
+    // $query.= '
+    // WHERE id_uppercat IS NULL';
+  }
+  else
+  {
+    $query .= '
+  WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\'';
+  }
+  $query .= '
+;';
+  
+  $smart_cats = hash_from_query($query, 'id'); 
+  $smart_count = count($smart_cats);
+  
+  if (isset($_GET['smart_generate']))
+  {
+    /* regenerate photo list | all (sub) categories */
+    if ($_GET['smart_generate'] == 'all')
+    {
+      foreach ($smart_cats as $category)
+      {
+        $associated_images = smart_make_associations($category['id']);
+        array_push($page['infos'], 
+          sprintf(l10n('%d photos associated to album %s'), 
+            count($associated_images), 
+            '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
+            )
+          );
+      }
+    }
+    /* regenerate photo list | one category */
+    else
+    {
+      $associated_images = smart_make_associations($_GET['smart_generate']);    
+      array_push($page['infos'], 
+        sprintf(l10n('%d photos associated to album %s'), 
+          count($associated_images), 
+          '&laquo;'.trigger_event('render_category_name', $smart_cats[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
+          )
+        );
+    }
+    
+    define('SMART_NOT_UPDATE', 1);
+    invalidate_user_cache();
+  }
+  
+  // create regenerate link
+  $tpl_cat = array();
+  foreach ($smart_cats as $cat => $name)
+  {
+    $tpl_cat[$cat] = $self_url.'&amp;smart_generate='.$cat;
+  }
+  $tpl_cat['all'] = $self_url.'&amp;smart_generate=all';
+  
+  $template->assign(array(
+    'SMART_URL' => $tpl_cat,
+    'SMART_PATH' => SMART_PATH,
+  ));
+  
+  $template->set_prefilter('categories', 'smart_cat_list_prefilter');
+}
+
+
+function smart_cat_list_prefilter($content, &$smarty)
+{
+  global $smart_count;
+  
+  $search[0] = '{if isset($category.U_MANAGE_ELEMENTS) }';
+  $replacement[0] = $search[0].'
+{if isset($SMART_URL[$category.ID])}
+| <a href="{$SMART_URL[$category.ID]}">{\'Regenerate photos list of this SmartAlbum\'|@translate}</a>
+{/if}';
+
+  if ($smart_count > 0)
+  {
+    $search[1] = '<a href="#" id="autoOrderOpen">{\'apply automatic sort order\'|@translate}</a>';
+    $replacement[1] = $search[1].'
+| <a href="{$SMART_URL.all}">{\'Regenerate photos list of all SmartAlbums\'|@translate}</a>';
+  }
+  
+  $search[2] = '{$category.NAME}</a></strong>';
+  $replacement[2] = $search[2].'
+{if isset($SMART_URL[$category.ID])}
+<img src="'.SMART_PATH.'admin/template/lightning.png">
+{/if}';
+
+  return str_replace($search, $replacement, $content);
+}
+
+?>
Index: /extensions/SmartAlbums/include/count_images.php
===================================================================
--- /extensions/SmartAlbums/include/count_images.php	(revision 16103)
+++ /extensions/SmartAlbums/include/count_images.php	(revision 16104)
@@ -6,7 +6,14 @@
 define('PHPWG_ROOT_PATH','./../../../');
 define('IN_ADMIN', true);
+
 include_once(PHPWG_ROOT_PATH.'include/common.inc.php');
+
+if (!is_admin()) die('Hacking attempt!');
+
 include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
 include_once(SMART_PATH.'include/functions.inc.php');
+
+load_language('plugin.lang', SMART_PATH);
+$conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
 
 if (isset($_POST['filters']))
@@ -22,4 +29,9 @@
       array_push($filters, $filter);
     }
+    else
+    {
+      echo '<span class="filter_error">'.$page['errors'][ count($page['errors'])-1 ].'</span>';
+      exit;
+    }
   }
 
@@ -31,5 +43,5 @@
 }
 
-echo l10n_dec('%d photo', '%d photos', count($associated_images));
+echo '<span class="count_image">'.l10n_dec('%d photo', '%d photos', count($associated_images)).'</span>';
 
 ?>
Index: /extensions/SmartAlbums/include/functions.inc.php
===================================================================
--- /extensions/SmartAlbums/include/functions.inc.php	(revision 16103)
+++ /extensions/SmartAlbums/include/functions.inc.php	(revision 16104)
@@ -36,5 +36,5 @@
   }
   
-  // represantant, try to not overwrite if still in images list
+  // representant, try to not overwrite if still in images list
   $query = '
 SELECT representative_picture_id
@@ -46,8 +46,5 @@
   if ( !in_array($rep_id, $images) )
   {
-    if (!function_exists('set_random_representant'))
-    {
-      include(PHPWG_ROOT_PATH.'admin/include/functions.php');
-    }
+    include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
     set_random_representant(array($cat_id));
   }
@@ -64,6 +61,4 @@
 {
   global $conf;
-    
-  if (!is_array($conf['SmartAlbums'])) $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
   
   if ( defined('SMART_NOT_UPDATE') OR !$conf['SmartAlbums']['update_on_upload'] ) return;
@@ -94,8 +89,6 @@
 
   /* get filters */
-  if ($filters == null)
-  {
-    $filters = array();
-    
+  if ($filters === null)
+  {
     $query = '
 SELECT * 
@@ -106,6 +99,7 @@
     $result = pwg_query($query);
     
-    if (!pwg_db_num_rows($result)) return $filters;
+    if (!pwg_db_num_rows($result)) return array();
     
+    $filters = array();
     while ($row = pwg_db_fetch_assoc($result))
     {
@@ -117,96 +111,202 @@
     }
   }
+  else if (!count($filters))
+  {
+    return array();
+  }
     
   /* build constrains */
   ## generate 'join', 'where' arrays and 'limit' string to create the SQL query
-  ## inspired by PicsEngine by Michael Villar
+  ## inspired by PicsEngine 3 by Michael Villar
   $i_tags = 1;
   foreach ($filters as $filter)
   {
-    // tags
-    if ($filter['type'] == 'tags')
-    {
-      if($filter['cond'] == "all")
-      {
-        $tags_arr = explode(',', $filter['value']);
+    switch ($filter['type'])
+    {
+      // tags
+      case 'tags':
+      {
+        switch ($filter['cond'])
+        {
+          // search images which have all tags
+          case 'all':
+          {
+            $tags_arr = explode(',', $filter['value']);
+            foreach($tags_arr as $value)
+            {
+              $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
+              $where[] = 'it'.$i_tags.'.tag_id = '.$value;
+              $i_tags++;
+            }
+            
+            break;
+          }
+          // search images which tags are in the list
+          case 'one':
+          {
+            $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
+            $where[] = 'it'.$i_tags.'.tag_id IN ('.$filter['value'].')';
+            $i_tags++;
+            
+            break;
+          }
+          // exclude images which tags are in the list
+          case 'none':
+          {
+            $sub_query = '
+      SELECT it'.$i_tags.'.image_id
+        FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.'
+        WHERE 
+          it'.$i_tags.'.image_id = i.id AND
+          it'.$i_tags.'.tag_id IN ('.$filter['value'].')
+        GROUP BY it'.$i_tags.'.image_id
+      ';
+            $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
+            $where[] = 'NOT EXISTS ('.$sub_query.')';
+            $i_tags++;
+            
+            break;
+          }
+          // exclude images which tags are not in the list and search images which have all tags
+          case 'only':
+          {
+            $sub_query = '
+      SELECT it'.$i_tags.'.image_id
+        FROM '.IMAGE_TAG_TABLE.' AS it'.$i_tags.'
+        WHERE 
+          it'.$i_tags.'.image_id = i.id AND
+          it'.$i_tags.'.tag_id NOT IN ('.$filter['value'].')
+        GROUP BY it'.$i_tags.'.image_id
+      ';
+            $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
+            $where[] = 'NOT EXISTS ('.$sub_query.')';
+            $i_tags++;
+            
+            $tags_arr = explode(',', $filter['value']);
+            foreach($tags_arr as $value)
+            {
+              $join[] = IMAGE_TAG_TABLE.' AS it'.$i_tags.' ON i.id = it'.$i_tags.'.image_id';
+              $where[] = 'it'.$i_tags.'.tag_id = '.$value;
+              $i_tags++;
+            }
+            
+            break;
+          }
+        }
         
-        foreach($tags_arr as $value)
-        {
-          $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
-          $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
-          $i_tags++;
-        }
-      }
-      else if ($filter['cond'] == 'one') 
-      {
-        $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
-        $where[] = 'it_'.$i_tags.'.tag_id IN ('.$filter['value'].')';
-        $i_tags++;
-      }
-      else if ($filter['cond'] == 'none') 
-      {
-        $sub_query = '
-      SELECT it_'.$i_tags.'.image_id
-        FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.'
-        WHERE 
-          it_'.$i_tags.'.image_id = i.id AND
-          it_'.$i_tags.'.tag_id IN ('.$filter['value'].')
-        GROUP BY it_'.$i_tags.'.image_id
-    ';
-        $where[] = 'NOT EXISTS ('.$sub_query.')';
-        $i_tags++;
-      }
-      else if ($filter['cond'] == 'only') 
-      {
-        $sub_query = '
-      SELECT it_'.$i_tags.'.image_id
-        FROM '.IMAGE_TAG_TABLE.' AS it_'.$i_tags.'
-        WHERE 
-          it_'.$i_tags.'.image_id = i.id AND
-          it_'.$i_tags.'.tag_id NOT IN ('.$filter['value'].')
-        GROUP BY it_'.$i_tags.'.image_id
-    ';
-        $where[] = 'NOT EXISTS ('.$sub_query.')';
+        break;
+      }
+    
+      // date
+      case 'date':
+      {
+        switch ($filter['cond'])
+        {
+          case 'the_post':
+            $where[] = 'date_available BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"';
+            break;
+          case 'before_post':
+            $where[] = 'date_available < "'.$filter['value'].' 00:00:00"';
+            break;
+          case 'after_post':
+            $where[] = 'date_available > "'.$filter['value'].' 23:59:59"';
+            break;
+          case 'the_taken':
+            $where[] = 'date_creation BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"';
+            break;
+          case 'before_taken':
+            $where[] = 'date_creation < "'.$filter['value'].' 00:00:00"';
+            break;
+          case 'after_taken':
+            $where[] = 'date_creation > "'.$filter['value'].' 23:59:59"';
+            break;
+        }
+        
+        break;
+      }
       
-        $i_tags++;
-        $tags_arr = explode(',', $filter['value']);
+      // name
+      case 'name':
+      {
+        switch ($filter['cond'])
+        {
+          case 'contain':
+            $where[] = 'name LIKE "%'.$filter['value'].'%"';
+            break;
+          case 'begin':
+            $where[] = 'name LIKE "'.$filter['value'].'%"';
+            break;
+          case 'end':
+            $where[] = 'name LIKE "%'.$filter['value'].'"';
+            break;
+          case 'not_contain':
+            $where[] = 'name NOT LIKE "%'.$filter['value'].'%"';
+            break;
+          case 'not_begin':
+            $where[] = 'name NOT LIKE "'.$filter['value'].'%"';
+            break;
+          case 'not_end':
+            $where[] = 'name NOT LIKE "%'.$filter['value'].'"';
+            break;
+        }
         
-        foreach($tags_arr as $value)
-        {
-          $join[] = IMAGE_TAG_TABLE.' AS it_'.$i_tags.' ON i.id = it_'.$i_tags.'.image_id';
-          $where[] = 'it_'.$i_tags.'.tag_id = '.$value;
-          $i_tags++;
-        }
-      }        
-    }
-    // date
-    else if ($filter['type'] == 'date')
-    {
-      switch ($filter['cond'])
-      {
-        case 'the':
-          $where[] = 'date_available BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"';
-          break;
-        case 'before':
-          $where[] = 'date_available < "'.$filter['value'].' 00:00:00"';
-          break;
-        case 'after':
-          $where[] = 'date_available > "'.$filter['value'].' 23:59:59"';
-          break;
-        case 'the_crea':
-          $where[] = 'date_creation BETWEEN "'.$filter['value'].' 00:00:00" AND "'.$filter['value'].' 23:59:59"';
-          break;
-        case 'before_crea':
-          $where[] = 'date_creation < "'.$filter['value'].' 00:00:00"';
-          break;
-        case 'after_crea':
-          $where[] = 'date_creation > "'.$filter['value'].' 23:59:59"';
-          break;
-      }
-    }
-    // limit
-    else if ($filter['type'] == 'limit')
-    {
-      $limit = '0, '.$filter['value'];
+        break;
+      }
+      
+      // author
+      case 'author':
+      {
+        switch ($filter['cond'])
+        {
+          case 'is':
+            if ($filter['value'] != 'NULL') $filter['value'] = '"'.$filter['value'].'"';
+            $where[] = 'author = '.$filter['value'].'';
+            break;
+          case 'not_is':
+            if ($filter['value'] != 'NULL') $filter['value'] = '"'.$filter['value'].'"';
+            $where[] = 'author != '.$filter['value'].'';
+            break;
+          case 'in':
+            $filter['value'] = '"'.str_replace(',', '","', $filter['value']).'"';
+            $where[] = 'author IN('.$filter['value'].')';
+            break;
+          case 'not_in':
+            $filter['value'] = '"'.str_replace(',', '","', $filter['value']).'"';
+            $where[] = 'author NOT IN('.$filter['value'].')';
+            break;
+        }
+        
+        break;
+      }
+      
+      // hit
+      case 'hit':
+      {
+        switch ($filter['cond'])
+        {
+          case 'less':
+            $where[] = 'hit < '.$filter['value'].'';
+            break;
+          case 'more':
+            $where[] = 'hit >= '.$filter['value'].'';
+            break;
+        }
+        
+        break;
+      }
+      
+      // level
+      case 'level':
+      {
+        $where[] = 'level = '.$filter['value'].'';
+        break;
+      }
+      
+      // limit
+      case 'limit':
+      {
+        $limit = '0, '.$filter['value'];
+        break;
+      }
     }
   }
@@ -219,30 +319,21 @@
     if (isset($join))
     {
-      foreach ($join as $query)
-      {
-        $MainQuery .= '
-    LEFT JOIN '.$query;
-      }
+      $MainQuery.= '
+    LEFT JOIN '.implode("\n    LEFT JOIN ", $join);
     }
     if (isset($where))
     {
-      $MainQuery .= '
-  WHERE';
-      $i = 0;
-      foreach ($where as $query)
-      {
-        if ($i != 0) $MainQuery .= ' AND';
-        $MainQuery .= '
-    '.$query;
-        $i++;
-      }
-    }
-
-    $MainQuery .= '
+      $MainQuery.= '
+  WHERE
+    '.implode("\n    AND ", $where);
+    }
+
+  $MainQuery.= '
   GROUP BY i.id
- '.$conf['order_by'].'
+  '.$conf['order_by'].'
   '.(isset($limit) ? "LIMIT ".$limit : null).'
 ;';
 
+  // file_put_contents(SMART_PATH.'query.sql', $MainQuery);
   return array_from_query($MainQuery, 'id');
 }
@@ -256,6 +347,9 @@
 function smart_check_filter($filter)
 {
-  global $limit_is_set, $page;
+  global $page, $limit_is_set, $level_is_set;
   $error = false;
+  
+  if (!isset($limit_is_set)) $limit_is_set = false;
+  if (!isset($level_is_set)) $level_is_set = false;
   
   # tags
@@ -281,4 +375,48 @@
     }
   }
+  # name
+  else if ($filter['type'] == 'name')
+  {
+    if (empty($filter['value']))
+    {
+      $error = true;
+      array_push($page['errors'], l10n('Name is empty'));
+    }
+  }
+  # author
+  else if ($filter['type'] == 'author')
+  {
+    if (empty($filter['value']))
+    {
+      $error = true;
+      array_push($page['errors'], l10n('Author is empty'));
+    }
+    else
+    {
+      $filter['value'] = preg_replace('#([ ]?),([ ]?)#', ',', $filter['value']);
+    }
+  }
+  # hit
+  else if ($filter['type'] == 'hit')
+  {
+    if (!preg_match('#([0-9]{1,})#', $filter['value']))
+    {
+      $error = true;
+      array_push($page['errors'], l10n('Hits must be an integer'));
+    }
+  }
+  # level
+  else if ($filter['type'] == 'level')
+  {
+    if ($level_is_set == true) // only one level is allowed, first is saved
+    {
+      $error = true;
+      array_push($page['errors'], l10n('You can\'t use more than one level filter'));
+    }
+    else
+    {
+      $level_is_set = true;
+    }
+  }
   # limit
   else if ($filter['type'] == 'limit')
@@ -292,5 +430,5 @@
     {
       $error = true;
-      array_push($page['errors'], l10n('You can\'t use more than one limit'));
+      array_push($page['errors'], l10n('You can\'t use more than one limit filter'));
     }
     else
@@ -374,3 +512,4 @@
   }
 }
+
 ?>
Index: /extensions/SmartAlbums/include/index.php
===================================================================
--- /extensions/SmartAlbums/include/index.php	(revision 16103)
+++ /extensions/SmartAlbums/include/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?php
-// +-----------------------------------------------------------------------+
-// | Piwigo - a PHP based photo gallery                                    |
-// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 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  |
-// | 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 );
Index: tensions/SmartAlbums/include/init_cat_list.php
===================================================================
--- /extensions/SmartAlbums/include/init_cat_list.php	(revision 16103)
+++ 	(revision )
@@ -1,122 +1,0 @@
-<?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-/**
- * Add a link into categories list to regenerate associations
- */
-$smart_count = 0;
-
-function smart_cat_list()
-{
-  global $template, $page, $smart_count;
-
-  $self_url = get_root_url().'admin.php?page=cat_list'.(isset($_GET['parent_id']) ? '&amp;parent_id='.$_GET['parent_id'] : null);
-  
-  /* get categories with smart filters */
-  $query = '
-SELECT DISTINCT id, name 
-  FROM '.CATEGORIES_TABLE.' AS c
-    INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
-      ON c.id = cf.category_id';
-  if (!isset($_GET['parent_id']))
-  {
-    // $query.= '
-    // WHERE id_uppercat IS NULL';
-  }
-  else
-  {
-    $query .= '
-  WHERE uppercats LIKE \'%'.$_GET['parent_id'].'%\'';
-  }
-  $query .= '
-;';
-  
-  $smart_cats = hash_from_query($query, 'id'); 
-  $smart_count = count($smart_cats);
-  
-  if (isset($_GET['smart_generate']))
-  {
-    /* regenerate photo list | all (sub) categories */
-    if ($_GET['smart_generate'] == 'all')
-    {
-      foreach ($smart_cats as $category)
-      {
-        $associated_images = smart_make_associations($category['id']);
-        array_push(
-          $page['infos'], 
-          sprintf(
-            l10n('%d photos associated to album %s'), 
-            count($associated_images), 
-            '&laquo;'.trigger_event(
-              'render_category_name',
-              $category['name'],
-              'admin_cat_list'
-              ).'&raquo;'
-            )
-          );
-      }
-    }
-    /* regenerate photo list | one category */
-    else
-    {
-      $associated_images = smart_make_associations($_GET['smart_generate']);    
-      array_push(
-        $page['infos'], 
-        sprintf(
-          l10n('%d photos associated to album %s'), 
-          count($associated_images), 
-          '&laquo;'.trigger_event(
-            'render_category_name',
-            $smart_cats[$_GET['smart_generate']]['name'],
-            'admin_cat_list'
-            ).'&raquo;'
-          )
-        );
-    }
-    
-    define('SMART_NOT_UPDATE', 1);
-    invalidate_user_cache();
-  }
-  
-  // create regenerate link
-  $tpl_cat = array();
-  foreach ($smart_cats as $cat => $name)
-  {
-    $tpl_cat[$cat] = $self_url.'&amp;smart_generate='.$cat;
-  }
-  $tpl_cat['all'] = $self_url.'&amp;smart_generate=all';
-  
-  $template->assign(array(
-    'SMART_URL' => $tpl_cat,
-    'SMART_PATH' => SMART_PATH,
-  ));
-  
-  $template->set_prefilter('categories', 'smart_cat_list_prefilter');
-}
-
-
-function smart_cat_list_prefilter($content, &$smarty)
-{
-  global $smart_count;
-  
-  $search[0] = '{if isset($category.U_SYNC) }';
-  $replacement[0] = '
-{if isset($SMART_URL[$category.ID])}
-        <li><a href="{$SMART_URL[$category.ID]}" title="{\'Regenerate photos list of this SmartAlbum\'|@translate}"><img src="{$ROOT_URL}{$themeconf.admin_icon_dir}/synchronize.png" class="button" alt="{\'Regenerate photos list of this SmartAlbum\'|@translate}"></a></li>
-{/if}'
-.$search[0];
-
-  if ($smart_count > 0)
-  {
-    $search[1] = '</ul>
-</form>';
-    $replacement[1] = $search[1].'
-<form method="post" action="{$SMART_URL.all}">
-  <input type="hidden" name="pwg_token" value="{$PWG_TOKEN}">
-  <p><input class="submit" type="submit" value="{\'Regenerate photos list of all SmartAlbums\'|@translate}"></p>
-</form>';
-  }
-
-  return str_replace($search, $replacement, $content);
-}
-
-?>
Index: tensions/SmartAlbums/include/init_cat_modify.php
===================================================================
--- /extensions/SmartAlbums/include/init_cat_modify.php	(revision 16103)
+++ 	(revision )
@@ -1,163 +1,0 @@
-<?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-/**
- * Add the SmartAlbums configuration tool to virtual cats' configuration page
- */
- 
-function smart_cat_modify()
-{
-  global $template, $page;
-  
-  $cat_id = $_GET['cat_id'];
-  list($cat_dir) = pwg_db_fetch_row(pwg_query('SELECT dir FROM '.CATEGORIES_TABLE.' WHERE id = '.$cat_id.';'));
-  
-  // category must be virtual
-  if ($cat_dir != NULL)
-  {
-    return;
-  }
-  
-  /* SAVE FILTERS */
-  if (isset($_POST['submitFilters']))
-  {
-    // test if it was a Smart Album
-    $result = pwg_query('SELECT DISTINCT category_id FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
-    $was_smart = pwg_db_num_rows($result);
-    
-    /* this album is no longer a SmartAlbum */
-    if ($was_smart AND !isset($_POST['is_smart']))
-    {
-      pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;');
-      pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
-      set_random_representant(array($cat_id));
-    }
-    /* no filter selected */
-    else if (isset($_POST['is_smart']) AND !isset($_POST['filters']))
-    {
-      array_push($page['errors'], l10n('No filter selected'));
-    }
-    /* everything is fine */
-    else if (isset($_POST['is_smart']) AND count($_POST['filters']) > 0)
-    {
-      pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
-      
-      $limit_is_set = false;
-      foreach ($_POST['filters'] as $filter)
-      {
-        if (($filter = smart_check_filter($filter)) != false)
-        {
-          $query = '
-INSERT INTO '.CATEGORY_FILTERS_TABLE.' 
-  VALUES(
-    '.$cat_id.', 
-    "'.$filter['type'].'", 
-    "'.$filter['cond'].'", 
-    "'.$filter['value'].'"
-  )
-;';
-        pwg_query($query);
-        }
-      }
-      
-      $associated_images = smart_make_associations($cat_id);
-      $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
-      
-      array_push(
-          $page['infos'], 
-          sprintf(
-            l10n('%d photos associated to album %s'), 
-            count($associated_images), 
-            ''
-            )
-          );
-      
-      define('SMART_NOT_UPDATE', 1);
-      invalidate_user_cache();
-    }
-  }
-      
-  /* select options, for html_options */
-  $template->assign(
-    'options', 
-    array(
-      'tags' => array(
-        'all' => l10n('All these tags'),
-        'one' => l10n('One of these tags'),
-        'none' => l10n('None of these tags'),
-        'only' => l10n('Only these tags'),
-        ),
-      'date' => array(
-        'the' => l10n('Added on'),
-        'before' => l10n('Added before'),
-        'after' => l10n('Added after'),
-        'the_crea' => l10n('Created on'),
-        'before_crea' => l10n('Created before'),
-        'after_crea' => l10n('Created after'),
-        ),
-      'limit' => array('limit' => 'limit'), // second filter not used
-      // TODO : new filter by album
-      )
-    );
-  
-  /* get filters for this album */
-  $filters = pwg_query('SELECT * FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.' ORDER BY type ASC, cond ASC;');
-  while ($filter = pwg_db_fetch_assoc($filters))
-  {
-    // get tags name and id
-    if ($filter['type'] == 'tags')
-    {
-      $query = '
-SELECT
-    id,
-    name
-  FROM '.TAGS_TABLE.'
-  WHERE id IN('.$filter['value'].')
-;';
-      $filter['value'] = get_taglist($query); 
-    }
-    
-    $template->append('filters', array(
-      'TYPE' => $filter['type'],
-      'COND' => $filter['cond'],
-      'VALUE' => $filter['value'],
-    ));
-  }
-  
-  /* all tags */
-  $query = '
-SELECT
-    id,
-    name
-  FROM '.TAGS_TABLE.'
-;';
-  $tags = get_taglist($query);
-  
-  /* get image number */
-  if ($template->get_template_vars('IMAGE_COUNT') == null)
-  {
-    list($image_num) = pwg_db_fetch_row(pwg_query('SELECT count(*) FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;'));
-    $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num));
-  }
-  
-  if (isset($_GET['new_smart']))
-  {
-    $template->assign('new_smart', true);
-  }
-  
-  $template->assign(array(
-    'SMART_PATH' => SMART_PATH,
-    'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php',
-    'tags' => $tags,
-  )); 
-  $template->set_prefilter('categories', 'smart_cat_modify_prefilter');
-}
-
-
-function smart_cat_modify_prefilter($content, &$smarty)
-{
-  $search = '<form action="{$F_ACTION}" method="POST" id="catModify">';
-  $replacement = file_get_contents(SMART_PATH.'template/cat_modify.tpl')."\n".$search;
-  return str_replace($search, $replacement, $content);
-}
-
-?>
Index: tensions/SmartAlbums/include/init_page_items.php
===================================================================
--- /extensions/SmartAlbums/include/init_page_items.php	(revision 16103)
+++ 	(revision )
@@ -1,97 +1,0 @@
-<?php
-if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
-
-/**
- * Remove form $page['items'] picture that musn't be displayed
- *
- * here we get all pictures that current user could see 
- * if SmartAlbums doesn't exist, and make intersect with pictures
- * actually displayed
- */
-function smart_init_page_items()
-{
-  global $user, $page, $conf;
-
-  if (
-    ('categories' == $page['section']) and
-    (!isset($page['chronology_field'])) and
-    (
-      (isset($page['category'])) or
-      (isset($page['flat']))
-    )
-  ) {
-  
-    $query = '
-SELECT DISTINCT(cat.id) AS id
-  FROM '.CATEGORIES_TABLE.' AS cat
-    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS img
-    ON img.category_id = cat.id
-  WHERE img.smart = "true"
-;';
-    $smart_albums = array_from_query($query, 'id');
-      
-    if (count($smart_albums) > 0 and !is_admin())
-    {
-      // add SmartAlbums to forbidden categories
-      $user['forbidden_categories_old'] = $user['forbidden_categories'];
-      $user['forbidden_categories'] = explode(',', $user['forbidden_categories']);
-      $user['forbidden_categories'] = array_unique(array_merge($user['forbidden_categories'], $smart_albums));
-      $user['forbidden_categories'] = implode(',', $user['forbidden_categories']);
-    
-      if ( isset($page['category']) )
-      {
-        $query = '
-SELECT id
-  FROM '.CATEGORIES_TABLE.'
-  WHERE
-    '.get_sql_condition_FandF(
-      array(
-        'forbidden_categories' => 'id',
-        'visible_categories' => 'id',
-        )
-      );
-        $subcat_ids = array_from_query($query, 'id');
-        $subcat_ids[] = 0;
-        $where_sql = 'category_id IN ('.implode(',',$subcat_ids).')';
-        // remove categories from forbidden because just checked above
-        $forbidden = get_sql_condition_FandF(
-          array( 
-            'visible_images' => 'id'
-            ),
-          'AND'
-          );
-      }
-      else
-      {
-        $where_sql = '1=1';
-        $forbidden = get_sql_condition_FandF(
-          array(
-            'forbidden_categories' => 'category_id',
-            'visible_categories' => 'category_id',
-            'visible_images' => 'id'
-            ),
-          'AND'
-          );
-      }
-
-      // Main query
-      $query = '
-SELECT DISTINCT(image_id)
-  FROM '.IMAGE_CATEGORY_TABLE.'
-    INNER JOIN '.IMAGES_TABLE.' ON id = image_id
-  WHERE
-    '.$where_sql.'
-'.$forbidden.'
-  '.$conf['order_by'].'
-;';
-
-      $page['items_wo_sa'] = array_from_query($query, 'image_id');
-      $page['items'] = array_intersect($page['items'], $page['items_wo_sa']);
-      
-      // restore forbidden categories
-      $user['forbidden_categories'] = $user['forbidden_categories_old'];
-    }
-  }
-}
-
-?>
Index: /extensions/SmartAlbums/include/page_items.php
===================================================================
--- /extensions/SmartAlbums/include/page_items.php	(revision 16104)
+++ /extensions/SmartAlbums/include/page_items.php	(revision 16104)
@@ -0,0 +1,97 @@
+<?php
+if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
+
+/**
+ * Remove picture that musn't be displayed from $page['items']
+ *
+ * here we get all pictures that current user could see 
+ * if SmartAlbums doesn't exist, and make intersect with pictures
+ * actually displayed
+ */
+function smart_init_page_items()
+{
+  global $user, $page, $conf;
+
+  if (
+    ('categories' == $page['section']) and
+    (!isset($page['chronology_field'])) and
+    (
+      (isset($page['category'])) or
+      (isset($page['flat']))
+    )
+  ) {
+  
+    $query = '
+SELECT DISTINCT(cat.id) AS id
+  FROM '.CATEGORIES_TABLE.' AS cat
+    INNER JOIN '.IMAGE_CATEGORY_TABLE.' AS img
+    ON img.category_id = cat.id
+  WHERE img.smart = "true"
+;';
+    $smart_albums = array_from_query($query, 'id');
+      
+    if (count($smart_albums) > 0 and !is_admin())
+    {
+      // add SmartAlbums to forbidden categories
+      $user['forbidden_categories_old'] = $user['forbidden_categories'];
+      $user['forbidden_categories'] = explode(',', $user['forbidden_categories']);
+      $user['forbidden_categories'] = array_unique(array_merge($user['forbidden_categories'], $smart_albums));
+      $user['forbidden_categories'] = implode(',', $user['forbidden_categories']);
+    
+      if ( isset($page['category']) )
+      {
+        $query = '
+SELECT id
+  FROM '.CATEGORIES_TABLE.'
+  WHERE
+    '.get_sql_condition_FandF(
+      array(
+        'forbidden_categories' => 'id',
+        'visible_categories' => 'id',
+        )
+      );
+        $subcat_ids = array_from_query($query, 'id');
+        $subcat_ids[] = 0;
+        $where_sql = 'category_id IN ('.implode(',',$subcat_ids).')';
+        // remove categories from forbidden because just checked above
+        $forbidden = get_sql_condition_FandF(
+          array( 
+            'visible_images' => 'id'
+            ),
+          'AND'
+          );
+      }
+      else
+      {
+        $where_sql = '1=1';
+        $forbidden = get_sql_condition_FandF(
+          array(
+            'forbidden_categories' => 'category_id',
+            'visible_categories' => 'category_id',
+            'visible_images' => 'id'
+            ),
+          'AND'
+          );
+      }
+
+      // Main query
+      $query = '
+SELECT DISTINCT(image_id)
+  FROM '.IMAGE_CATEGORY_TABLE.'
+    INNER JOIN '.IMAGES_TABLE.' ON id = image_id
+  WHERE
+    '.$where_sql.'
+'.$forbidden.'
+  '.$conf['order_by'].'
+;';
+
+      $page['items_wo_sa'] = array_from_query($query, 'image_id');
+      $page['items'] = array_intersect($page['items'], $page['items_wo_sa']);
+      
+      // restore forbidden categories
+      $user['forbidden_categories'] = $user['forbidden_categories_old'];
+    }
+  }
+}
+
+?>
Index: /extensions/SmartAlbums/index.php
===================================================================
--- /extensions/SmartAlbums/index.php	(revision 16103)
+++ /extensions/SmartAlbums/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?php
-// +-----------------------------------------------------------------------+
-// | Piwigo - a PHP based photo gallery                                    |
-// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 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  |
-// | 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 );
Index: /extensions/SmartAlbums/language/ca_ES/index.php
===================================================================
--- /extensions/SmartAlbums/language/ca_ES/index.php	(revision 16104)
+++ /extensions/SmartAlbums/language/ca_ES/index.php	(revision 16104)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/SmartAlbums/language/cs_CZ/index.php
===================================================================
--- /extensions/SmartAlbums/language/cs_CZ/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/cs_CZ/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/language/de_DE/index.php
===================================================================
--- /extensions/SmartAlbums/language/de_DE/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/de_DE/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/language/en_UK/index.php
===================================================================
--- /extensions/SmartAlbums/language/en_UK/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/en_UK/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/language/en_UK/plugin.lang.php
===================================================================
--- /extensions/SmartAlbums/language/en_UK/plugin.lang.php	(revision 16103)
+++ /extensions/SmartAlbums/language/en_UK/plugin.lang.php	(revision 16104)
@@ -1,10 +1,7 @@
 <?php
 
-$lang['%d photos associated to album %s'] = '%d photos associated to album %s';
 $lang['No filter selected'] = 'No filter selected';
-$lang['No tag selected'] = 'No tag selected';
-$lang['Date string is malformed'] = 'Date string is malformed';
-$lang['Limit must be an integer'] = 'Limit must be an integer';
-$lang['You can\'t use more than one limit'] = 'You can\'t use more than one limit';
+$lang['%d photo'] = '%d photo';
+$lang['%d photos'] = '%d photos';
 $lang['All these tags'] = 'All these tags';
 $lang['One of these tags'] = 'One of these tags';
@@ -14,26 +11,50 @@
 $lang['Added before'] = 'Added before';
 $lang['Added after'] = 'Added after';
-$lang['Created on'] = 'Created on';
 $lang['Created before'] = 'Created before';
 $lang['Created after'] = 'Created after';
-$lang['%d photo'] = '%d photo';
-$lang['%d photos'] = '%d photos';
-$lang['tags filter'] = 'tags filter';
-$lang['date filter'] = 'date filter';
-$lang['limit filter'] = 'limit filter';
-$lang['Add filters here'] = 'Add filters here';
-$lang['This album is a SmartAlbum'] = 'This album is a SmartAlbum';
-$lang['Count'] = 'Count';
-$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['(can cause slowdowns on admin pages)'] = '(can cause slowdowns on admin pages)';
-$lang['All SmartAlbums'] = 'All SmartAlbums';
-$lang['Add a SmartAlbum'] = 'Add a SmartAlbum';
+$lang['Contains'] = 'Contains';
+$lang['Begins with'] = 'Begins with';
+$lang['Ends with'] = 'Ends with';
+$lang['Doesn\'t contain'] = 'Doesn\'t contain';
+$lang['Doesn\'t begin with'] = 'Doesn\'t begin with';
+$lang['Doesn\'t end with'] = 'Doesn\'t end with';
+$lang['Is'] = 'Is';
+$lang['Is in'] = 'Is in';
+$lang['Is not'] = 'Is not';
+$lang['Is not in'] = 'Is not in';
+$lang['Bellow'] = 'Bellow';
+$lang['Above'] = 'Above';
 $lang['SmartAlbum deleted'] = 'SmartAlbum deleted';
 $lang['SmartAlbum added'] = 'SmartAlbum added';
+$lang['%d photos associated to album %s'] = '%d photos associated to album %s';
 $lang['Only SmartAlbums are displayed on this page'] = 'Only SmartAlbums are displayed on this page';
-$lang['To order albums please go the main albums management page'] = 'To order albums please go the main albums <a href="admin.php?page=cat_list">management page</a>';
+$lang['To order albums please go the main albums <a href="%s">management page</a>'] = 'To order albums please go the main albums <a href="%s">management page</a>';
 $lang['Don\'t show this message again'] = 'Don\'t show this message again';
+$lang['All SmartAlbums'] = 'All SmartAlbums';
+$lang['No tag selected'] = 'No tag selected';
+$lang['Date string is malformed'] = 'Date string is malformed';
+$lang['Name is empty'] = 'Name is empty';
+$lang['Author is empty'] = 'Author is empty';
+$lang['Hits must be an integer'] = 'Hits must be an integer';
+$lang['Limit must be an integer'] = 'Limit must be an integer';
+$lang['You can\'t use more than one limit filter'] = 'You can\'t use more than one limit filter';
+$lang['You can\'t use more than one level filter'] = 'You can\'t use more than one level filter';
+$lang['tags_filter'] = 'Tags';
+$lang['date_filter'] = 'Date';
+$lang['name_filter'] = 'Photo name';
+$lang['author_filter'] = 'Author';
+$lang['hit_filter'] = 'Hits';
+$lang['level_filter'] = 'Level';
+$lang['limit_filter'] = 'Max. number of photos';
+$lang['For "Is (not) in", separate each author by a comma'] = 'For "Is (not) in", separate each author by a comma';
+$lang['limit_filter'] = 'Max. number of photos';
+$lang['This album is a SmartAlbum'] = 'This album is a SmartAlbum';
+$lang['Add filters here'] = 'Add filters here';
+$lang['Count'] = 'Count';
+$lang['create a new SmartAlbum'] = 'create a new SmartAlbum';
+$lang['Regenerate photos list of all SmartAlbums'] = 'Regenerate photos list of all SmartAlbums';
+$lang['Regenerate photos list of this SmartAlbum'] = 'Regenerate photos list of this SmartAlbum';
+$lang['Update albums on file upload'] = 'Update albums on file upload';
+$lang['(can cause slowdowns)'] = '(can cause slowdowns)';
 
 ?>
Index: /extensions/SmartAlbums/language/es_ES/index.php
===================================================================
--- /extensions/SmartAlbums/language/es_ES/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/es_ES/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/language/fr_FR/index.php
===================================================================
--- /extensions/SmartAlbums/language/fr_FR/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/fr_FR/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/language/fr_FR/plugin.lang.php
===================================================================
--- /extensions/SmartAlbums/language/fr_FR/plugin.lang.php	(revision 16103)
+++ /extensions/SmartAlbums/language/fr_FR/plugin.lang.php	(revision 16104)
@@ -1,10 +1,7 @@
 <?php
 
-$lang['%d photos associated to album %s'] = '%d photos associées à l\'album %s';
 $lang['No filter selected'] = 'Aucun filtre sélectionné';
-$lang['No tag selected'] = 'Aucun tag sélectionné';
-$lang['Date string is malformed'] = 'La date n\'est pas correcte';
-$lang['Limit must be an integer'] = 'La limite doit être un entier';
-$lang['You can\'t use more than one limit'] = 'Vous ne pouvez utiliser qu\'une seule limite';
+$lang['%d photo'] = '%d photo';
+$lang['%d photos'] = '%d photos';
 $lang['All these tags'] = 'Tous les tags';
 $lang['One of these tags'] = 'Un des tags';
@@ -14,26 +11,49 @@
 $lang['Added before'] = 'Ajouté avant le';
 $lang['Added after'] = 'Ajouté après le';
-$lang['Created on'] = 'Créé le';
 $lang['Created before'] = 'Créé avant le';
 $lang['Created after'] = 'Créé après le';
-$lang['%d photo'] = '%d photo';
-$lang['%d photos'] = '%d photos';
-$lang['tags filter'] = 'filtrer par tags';
-$lang['date filter'] = 'filtrer par date';
-$lang['limit filter'] = 'nombre max. d\'éléments';
-$lang['Add filters here'] = 'Ajoutez des filtres ici';
-$lang['This album is a SmartAlbum'] = 'Cet album est un SmartAlbum';
-$lang['Count'] = 'Compter';
-$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['(can cause slowdowns on admin pages)'] = '(peut causer des ralentissements)';
-$lang['All SmartAlbums'] = 'Tous les SmartAlbums';
-$lang['Add a SmartAlbum'] = 'Ajouter un SmartAlbum';
+$lang['Contains'] = 'Contient';
+$lang['Begins with'] = 'Commence par';
+$lang['Ends with'] = 'Fini par';
+$lang['Doesn\'t contain'] = 'Ne contient pas';
+$lang['Doesn\'t begin with'] = 'Ne commence pas par';
+$lang['Doesn\'t end with'] = 'Ne fini pas par';
+$lang['Is'] = 'Est';
+$lang['Is in'] = 'Est dans';
+$lang['Is not'] = 'N\'est pas';
+$lang['Is not in'] = 'N\'est pas dans';
+$lang['Bellow'] = 'Moins que';
+$lang['Above'] = 'Plus que';
 $lang['SmartAlbum deleted'] = 'SmartAlbum supprimé';
 $lang['SmartAlbum added'] = 'SmartAlbum ajouté';
+$lang['%d photos associated to album %s'] = '%d photos associées à l\'album %s';
 $lang['Only SmartAlbums are displayed on this page'] = 'Seuls les SmartAlbums sont affichés sur cette page';
-$lang['To order albums please go the main albums management page'] = 'Pour ordonner les albums veuillez vous rendre sur la page principale de <a href="admin.php?page=cat_list">gestion des albums</a>';
+$lang['To order albums please go the main albums <a href="%s">management page</a>'] = 'Pour trier les SmartAlbums veuillez vous rendre sur la page principale de <a href="%s">gestion des albums</a>';
 $lang['Don\'t show this message again'] = 'Ne plus afficher ce message';
+$lang['All SmartAlbums'] = 'AlTous les  SmartAlbums';
+$lang['No tag selected'] = 'Aucun tag sélectionné';
+$lang['Date string is malformed'] = 'Date incorrecte';
+$lang['Name is empty'] = 'Le nom est vide';
+$lang['Author is empty'] = 'L\'auteur est vide';
+$lang['Hits must be an integer'] = 'Le nombre de vues doit être un entier';
+$lang['Limit must be an integer'] = 'La nombre d\'éléments doit être un entier';
+$lang['You can\'t use more than one limit filter'] = 'Vous ne pouvez choisir qu\'une seule limite de nombre d\'éléments';
+$lang['You can\'t use more than one level filter'] = 'Vous ne pouvez choisir qu\'un seul niveau de confidentialité';
+$lang['tags_filter'] = 'Tags';
+$lang['date_filter'] = 'Date';
+$lang['name_filter'] = 'Nom de la photo';
+$lang['author_filter'] = 'Auteur';
+$lang['hit_filter'] = 'Nombre de vues';
+$lang['level_filter'] = 'Niveau de confidentialité';
+$lang['limit_filter'] = 'Nombre max. d\'éléments';
+$lang['For "Is (not) in", separate each author by a comma'] = 'Pour "Est/N\'est pas dans", séparez chaque auteur par une virgule';
+$lang['This album is a SmartAlbum'] = 'Cet album est un SmartAlbum';
+$lang['Add filters here'] = 'Ajoutez des filtres ici';
+$lang['Count'] = 'Compter';
+$lang['create a new SmartAlbum'] = 'créer un nouveau SmartAlbum';
+$lang['Regenerate photos list of all SmartAlbums'] = 'Régénérer les photos de tous les SmartAlbums';
+$lang['Regenerate photos list of this SmartAlbum'] = 'Régénérer les photos de ce SmartAlbum';
+$lang['Update albums on file upload'] = 'Mettre à jour les albums après la mise en ligne d\'un fichier';
+$lang['(can cause slowdowns)'] = '(peut causer des ralentissements)';
 
 ?>
Index: /extensions/SmartAlbums/language/index.php
===================================================================
--- /extensions/SmartAlbums/language/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/language/it_IT/index.php
===================================================================
--- /extensions/SmartAlbums/language/it_IT/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/it_IT/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?php
-// +-----------------------------------------------------------------------+
-// | Piwigo - a PHP based photo gallery                                    |
-// +-----------------------------------------------------------------------+
-// | Copyright(C) 2008-2011 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  |
-// | 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 );
Index: /extensions/SmartAlbums/language/lv_LV/index.php
===================================================================
--- /extensions/SmartAlbums/language/lv_LV/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/lv_LV/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/language/nl_NL/index.php
===================================================================
--- /extensions/SmartAlbums/language/nl_NL/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/nl_NL/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/language/pl_PL/index.php
===================================================================
--- /extensions/SmartAlbums/language/pl_PL/index.php	(revision 16104)
+++ /extensions/SmartAlbums/language/pl_PL/index.php	(revision 16104)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/SmartAlbums/language/pt_PT/index.php
===================================================================
--- /extensions/SmartAlbums/language/pt_PT/index.php	(revision 16104)
+++ /extensions/SmartAlbums/language/pt_PT/index.php	(revision 16104)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/SmartAlbums/language/ru_RU/index.php
===================================================================
--- /extensions/SmartAlbums/language/ru_RU/index.php	(revision 16104)
+++ /extensions/SmartAlbums/language/ru_RU/index.php	(revision 16104)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/SmartAlbums/language/sk_SK/index.php
===================================================================
--- /extensions/SmartAlbums/language/sk_SK/index.php	(revision 16104)
+++ /extensions/SmartAlbums/language/sk_SK/index.php	(revision 16104)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/SmartAlbums/language/uk_UA/index.php
===================================================================
--- /extensions/SmartAlbums/language/uk_UA/index.php	(revision 16104)
+++ /extensions/SmartAlbums/language/uk_UA/index.php	(revision 16104)
@@ -0,0 +1,7 @@
+<?php
+$url = '../';
+header( 'Request-URI: '.$url );
+header( 'Content-Location: '.$url );
+header( 'Location: '.$url );
+exit();
+?>
Index: /extensions/SmartAlbums/language/vi_VN/index.php
===================================================================
--- /extensions/SmartAlbums/language/vi_VN/index.php	(revision 16103)
+++ /extensions/SmartAlbums/language/vi_VN/index.php	(revision 16104)
@@ -1,26 +1,3 @@
 <?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 |
-// +-----------------------------------------------------------------------+
-// | 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 );
Index: /extensions/SmartAlbums/main.inc.php
===================================================================
--- /extensions/SmartAlbums/main.inc.php	(revision 16103)
+++ /extensions/SmartAlbums/main.inc.php	(revision 16104)
@@ -12,8 +12,7 @@
 global $prefixeTable;
 
-define('SMART_DIR', basename(dirname(__FILE__)));
-define('SMART_PATH', PHPWG_PLUGINS_PATH.SMART_DIR.'/');
-define('CATEGORY_FILTERS_TABLE', $prefixeTable.'category_filters');
-define('SMART_ADMIN', get_root_url().'admin.php?page=plugin-' . SMART_DIR);
+define('SMART_PATH', PHPWG_PLUGINS_PATH . basename(dirname(__FILE__)) . '/');
+define('CATEGORY_FILTERS_TABLE', $prefixeTable . 'category_filters');
+define('SMART_ADMIN', get_root_url() . 'admin.php?page=plugin-' . basename(dirname(__FILE__)));
 
 add_event_handler('invalidate_user_cache', 'smart_make_all_associations');
@@ -23,26 +22,43 @@
 {
   add_event_handler('loc_end_section_init', 'smart_init_page_items');
-  include_once(SMART_PATH.'include/init_page_items.php');
+  include_once(SMART_PATH.'include/page_items.php');
 }
 else if (script_basename() == 'admin')
 {
+  global $conf;
+  
   load_language('plugin.lang', SMART_PATH);
-  
-  add_event_handler('loc_begin_cat_modify', 'smart_cat_modify'); 
-  include_once(SMART_PATH.'include/init_cat_modify.php');
-  
+  $conf['SmartAlbums'] = unserialize($conf['SmartAlbums']);
+    
   add_event_handler('loc_begin_cat_list', 'smart_cat_list');
-  include_once(SMART_PATH.'include/init_cat_list.php');
+  include_once(SMART_PATH.'include/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' => SMART_ADMIN,
-      )
-    );
-		return $menu;
-	}
+  function smart_admin_menu($menu) 
+  {
+    array_push($menu, array(
+        'NAME' => 'SmartAlbums',
+        'URL' => SMART_ADMIN,
+      ));
+    return $menu;
+  }
+    
+  add_event_handler('loc_begin_admin_page', 'smart_add_admin_album_tab');
+  function smart_add_admin_album_tab()
+  {
+    global $page, $template;
+    if ($page['page'] != 'album') return;
+    
+    $template->set_prefilter('tabsheet', 'smart_add_admin_album_tab_prefilter');
+  }
+  function smart_add_admin_album_tab_prefilter($content)
+  {
+    $search = '{/foreach}';
+    $add = '
+  <li class="{if false}selected_tab{else}normal_tab{/if}">
+    <a href="'.SMART_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'].'"><span>SmartAlbum</span></a>
+  </li>';
+    return str_replace($search, $search.$add, $content);
+  }
 }
 
Index: /extensions/SmartAlbums/maintain.inc.php
===================================================================
--- /extensions/SmartAlbums/maintain.inc.php	(revision 16103)
+++ /extensions/SmartAlbums/maintain.inc.php	(revision 16104)
@@ -2,11 +2,17 @@
 if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
 
+global $prefixeTable;
+define('smart_table', $prefixeTable . 'category_filters');
+
+define('smart_default_config', serialize(array(
+    'update_on_upload' => false,
+    'show_list_messages' => true,
+    )));
+
 function plugin_install() 
 {
-	global $prefixeTable;
-
   /* create table to store filters */
 	pwg_query(
-'CREATE TABLE IF NOT EXISTS `' . $prefixeTable . 'category_filters` (
+'CREATE TABLE IF NOT EXISTS `' . smart_table . '` (
   `category_id` smallint(5) unsigned NOT NULL,
   `type` varchar(16) NOT NULL,
@@ -20,17 +26,5 @@
       
   /* config parameter */
-  pwg_query('
-INSERT INTO `' . CONFIG_TABLE . '`
-  VALUES (
-    \'SmartAlbums\', 
-    \''.serialize(array(
-        'update_on_upload' => false,
-        'show_list_messages' => true,
-        )
-      ).'\',
-    \'Configuration for SmartAlbums plugin\'
-  )
-;');
-
+  conf_update_param('SmartAlbums', smart_default_config);
 }
 
@@ -41,26 +35,28 @@
   if (!isset($conf['SmartAlbums']))
   {
-    pwg_query('
-INSERT INTO `' . CONFIG_TABLE . '`
-  VALUES (
-    \'SmartAlbums\', 
-    \''.serialize(array(
-        'update_on_upload' => false,
-        'show_list_messages' => true,
-        )
-      ).'\',
-    \'Configuration for SmartAlbums plugin\'
-  )
-;');
+    conf_update_param('SmartAlbums', smart_default_config);
+  }
+  
+  /* some filters renamed in 1.2 */
+  $name_changes = array(
+    'the' => 'the_post',
+    'before' => 'before_post',
+    'after' => 'after_post',
+    'the_crea' => 'the_taken',
+    'before_crea' => 'before_taken',
+    'after_crea' => 'after_taken',
+    );
+  foreach ($name_changes as $old => $new)
+  {
+    pwg_query('UPDATE TABLE ' . smart_table . ' SET cond = "'.$new.'" WHERE cond = "'.$old.'";');
   }
 }
 
 function plugin_uninstall() 
-{
-	global $prefixeTable;
-  
-  pwg_query('DROP TABLE `' . $prefixeTable . 'category_filters`;');
+{  
+  pwg_query('DROP TABLE `' . smart_table . '`;');
   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\' LIMIT 1;');
 }
+
 ?>
