Index: extensions/SmartAlbums/admin/album.php
===================================================================
--- extensions/SmartAlbums/admin/album.php	(revision 17665)
+++ extensions/SmartAlbums/admin/album.php	(revision 17677)
@@ -162,4 +162,13 @@
       ),
     ),
+  'album' => array(
+    'name' => l10n('Album'),
+    'options' => array(
+      'all'   => l10n('All these albums'),
+      'one'   => l10n('One of these albums'),
+      'none'  => l10n('None of these albums'),
+      'only'  => l10n('Only these albums'),
+      ),
+    ),
   'author' => array(
     'name' => l10n('Author'),
@@ -220,4 +229,8 @@
 ;';
     $filter['value'] = get_taglist($query); 
+  }
+  else if ($filter['type'] == 'album')
+  {
+    $filter['value'] = explode(',', $filter['value']); 
   }
   
@@ -237,5 +250,16 @@
   FROM '.TAGS_TABLE.'
 ;';
-$all_tags = get_taglist($query);
+$template->assign('all_tags', get_taglist($query));
+
+/* all albums */
+$query = '
+SELECT 
+    id, 
+    name, 
+    uppercats, 
+    global_rank
+  FROM '.CATEGORIES_TABLE.'
+;';
+display_select_cat_wrapper($query, array(), 'all_albums');
 
 /* get image number */
@@ -254,4 +278,6 @@
 }
 
+
+/* template vars */
 if (isset($_GET['new_smart']))
 {
@@ -261,5 +287,4 @@
 $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,
Index: extensions/SmartAlbums/admin/template/album.tpl
===================================================================
--- extensions/SmartAlbums/admin/template/album.tpl	(revision 17665)
+++ extensions/SmartAlbums/admin/template/album.tpl	(revision 17677)
@@ -1,7 +1,11 @@
 {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'}
+{combine_css path="themes/default/js/plugins/chosen.css"}
+{combine_script id='jquery.chosen' load='footer' path='themes/default/js/plugins/chosen.jquery.min.js'}
+
+{footer_script require='jquery.tokeninput,jquery.chosen'}
 var lang = new Array();
 var options = new Array();
@@ -13,8 +17,11 @@
 {/foreach}
 
+lang['Select albums...'] = '{'Select albums...'|@translate}';
 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}";
+{capture assign="option_content"}{html_options options=$all_albums selected=0}{/capture}
+options['album_options'] = "{$option_content|escape:javascript}";
 
 {literal}
@@ -58,13 +65,20 @@
     ' <span class="filter-value">';
   
-  if (type == 'tags')
+  if (type == 'tags') {
     content+= ' <select name="filters['+ i +'][value]" class="tagSelect"></select>';
-  else if (type == 'level')
+  }
+  else if (type == 'album') {
+    content+= ' <select name="filters['+ i +'][value][]" class="albumSelect" multiple="multiple" data-placeholder="'+ lang['Select albums...'] +'">'+ options['album_options'] +'</select>';
+  }
+  else if (type == 'level') {
     content+= ' <select name="filters['+ i +'][value]">'+ options['level_options'] +'</select>';
-  else
+  }
+  else {
     content+= ' <input type="text" name="filters['+ i +'][value]" size="30"/>';
-  
-  if (type == 'author')
+  }
+  
+  if (type == 'author') {
     content+= ' <i>'+ lang['For "Is (not) in", separate each author by a comma'] +'</i>';
+  }
     
   content+= '</span>';
@@ -100,4 +114,6 @@
     }
   );
+  
+  jQuery(".albumSelect").chosen();
 }
 
@@ -160,4 +176,8 @@
             {/foreach}
             </select>
+          {elseif $filter.TYPE == 'album'}
+            <select name="filters[{$i}][value][]" class="albumSelect" multiple="multiple" data-placeholder="{'Select albums...'|@translate}">
+              {html_options options=$all_albums selected=$filter.VALUE}
+            </select>
           {elseif $filter.TYPE == 'level'}
             <select name="filters[{$i}][value]">
@@ -185,4 +205,5 @@
           <option value="date">{'Date'|@translate}</option>
           <option value="name">{'Photo name'|@translate}</option>
+          <option value="album">{'Album'|@translate}</option>
           <option value="author">{'Author'|@translate}</option>
           <option value="hit">{'Hits'|@translate}</option>
Index: extensions/SmartAlbums/admin/template/style.css
===================================================================
--- extensions/SmartAlbums/admin/template/style.css	(revision 17665)
+++ extensions/SmartAlbums/admin/template/style.css	(revision 17677)
@@ -60,2 +60,20 @@
   border-radius:4px;
 }
+
+.albumSelect {
+  width:600px;
+}
+  .chzn-container {
+    font-size:12px !important;
+  }
+  .chzn-choices li {
+    margin-bottom:1px !important;
+    padding: 3px 20px 3px 5px !important;
+    border-bottom-style:solid !important;
+  }
+  .search-field {
+    border-width:0px !important;
+  }
+  .chzn-choices .search-field input {
+    padding-bottom:1px !important;
+  }
Index: extensions/SmartAlbums/include/count_images.php
===================================================================
--- extensions/SmartAlbums/include/count_images.php	(revision 17665)
+++ extensions/SmartAlbums/include/count_images.php	(revision 17677)
@@ -11,9 +11,4 @@
 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']))
Index: extensions/SmartAlbums/include/functions.inc.php
===================================================================
--- extensions/SmartAlbums/include/functions.inc.php	(revision 17665)
+++ extensions/SmartAlbums/include/functions.inc.php	(revision 17677)
@@ -254,4 +254,77 @@
       }
       
+      // album
+      case 'album':
+      {
+        switch ($filter['cond'])
+        {
+          // search images existing in all albums
+          case 'all':
+          {
+            $albums_arr = explode(',', $filter['value']);
+            foreach($albums_arr as $value)
+            {
+              $sub_query = '
+      SELECT image_id 
+        FROM '.IMAGE_CATEGORY_TABLE.'
+        WHERE category_id = '.$value.'
+      ';
+              $where[] = 'i.id IN ('.$sub_query.')';
+            }
+            
+            break;
+          }
+          // search images existing in one of these albums
+          case 'one':
+          {
+            $sub_query = '
+      SELECT image_id
+        FROM '.IMAGE_CATEGORY_TABLE.'
+        WHERE category_id IN('.$filter['value'].')
+      ';
+            $where[] = 'i.id IN ('.$sub_query.')';
+            
+            break;
+          }
+          // exclude images existing in one of these albums
+          case 'none':
+          {
+            $sub_query = '
+      SELECT image_id
+        FROM '.IMAGE_CATEGORY_TABLE.'
+        WHERE category_id IN('.$filter['value'].')
+      ';
+            $where[] = 'i.id NOT IN ('.$sub_query.')';
+            
+            break;
+          }
+          // exclude images existing on other albums, and search images existing in all albums
+          case 'only':
+          {
+            $sub_query = '
+      SELECT image_id
+        FROM '.IMAGE_CATEGORY_TABLE.'
+        WHERE category_id NOT IN('.$filter['value'].')
+      ';
+            $where[] = 'i.id NOT IN ('.$sub_query.')';
+            
+            $albums_arr = explode(',', $filter['value']);
+            foreach($albums_arr as $value)
+            {
+              $sub_query = '
+      SELECT image_id 
+        FROM '.IMAGE_CATEGORY_TABLE.'
+        WHERE category_id = '.$value.'
+      ';
+              $where[] = 'i.id IN ('.$sub_query.')';
+            }
+            
+            break;
+          }
+        }
+        
+        break;
+      }
+      
       // author
       case 'author':
@@ -398,4 +471,17 @@
       $error = true;
       array_push($page['errors'], l10n('Name is empty'));
+    }
+  }
+  # album
+  else if ($filter['type'] == 'album')
+  {
+    if (@$filter['value'] == null)
+    {
+      $error = true;
+      array_push($page['errors'], l10n('No album selected'));
+    }
+    else
+    {
+      $filter['value'] = implode(',', $filter['value']);
     }
   }
Index: extensions/SmartAlbums/language/en_UK/plugin.lang.php
===================================================================
--- extensions/SmartAlbums/language/en_UK/plugin.lang.php	(revision 17665)
+++ extensions/SmartAlbums/language/en_UK/plugin.lang.php	(revision 17677)
@@ -8,4 +8,8 @@
 $lang['None of these tags'] = 'None of these tags';
 $lang['Only these tags'] = 'Only these tags';
+$lang['All these albums'] = 'All these albums';
+$lang['One of these albums'] = 'One of these albums';
+$lang['None of these albums'] = 'None of these albums';
+$lang['Only these albums'] = 'Only these albums';
 $lang['Added on'] = 'Added on';
 $lang['Added before'] = 'Added before';
@@ -33,4 +37,5 @@
 $lang['All SmartAlbums'] = 'All SmartAlbums';
 $lang['No tag selected'] = 'No tag selected';
+$lang['No album selected'] = 'No album selected';
 $lang['Date string is malformed'] = 'Date string is malformed';
 $lang['Name is empty'] = 'Name is empty';
Index: extensions/SmartAlbums/language/fr_FR/plugin.lang.php
===================================================================
--- extensions/SmartAlbums/language/fr_FR/plugin.lang.php	(revision 17665)
+++ extensions/SmartAlbums/language/fr_FR/plugin.lang.php	(revision 17677)
@@ -8,4 +8,8 @@
 $lang['None of these tags'] = 'Aucun des tags';
 $lang['Only these tags'] = 'Seulement les tags';
+$lang['All these albums'] = 'Tous les albums';
+$lang['One of these albums'] = 'Un des albums';
+$lang['None of these albums'] = 'Aucun des albums';
+$lang['Only these albums'] = 'Seulement les albums';
 $lang['Added on'] = 'Ajouté le';
 $lang['Added before'] = 'Ajouté avant le';
@@ -33,4 +37,5 @@
 $lang['All SmartAlbums'] = 'Tous les  SmartAlbums';
 $lang['No tag selected'] = 'Aucun tag sélectionné';
+$lang['No album selected'] = 'Aucun album sélectionné';
 $lang['Date string is malformed'] = 'Date incorrecte';
 $lang['Name is empty'] = 'Le nom est vide';
