source: extensions/SmartAlbums/admin/album.php @ 17677

Last change on this file since 17677 was 17677, checked in by mistic100, 12 years ago

add album filter

File size: 8.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2012 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if(!defined("PHPWG_ROOT_PATH")) die ("Hacking attempt!");
25
26// +-----------------------------------------------------------------------+
27// | Basic checks                                                          |
28// +-----------------------------------------------------------------------+
29
30check_status(ACCESS_ADMINISTRATOR);
31
32check_input_parameter('cat_id', $_GET, false, PATTERN_ID);
33
34$admin_album_base_url = get_root_url().'admin.php?page=album-'.$_GET['cat_id'];
35$self_url = SMART_ADMIN.'-album&amp;cat_id='.$_GET['cat_id'];
36
37$query = '
38SELECT *
39  FROM '.CATEGORIES_TABLE.'
40  WHERE id = '.$_GET['cat_id'].'
41;';
42$category = pwg_db_fetch_assoc(pwg_query($query));
43
44if (!isset($category['id']))
45{
46  die("unknown album");
47}
48
49// +-----------------------------------------------------------------------+
50// | Tabs                                                                  |
51// +-----------------------------------------------------------------------+
52
53include_once(PHPWG_ROOT_PATH.'admin/include/tabsheet.class.php');
54$tabsheet = new tabsheet();
55$tabsheet->set_id('album');
56$tabsheet->select('smartalbum');
57$tabsheet->assign();
58
59
60$cat_id = $_GET['cat_id'];
61
62// category must be virtual
63if ($category['dir'] != NULL)
64{
65  die("physical album");
66}
67
68// +-----------------------------------------------------------------------+
69// | Save Filters                                                          |
70// +-----------------------------------------------------------------------+
71
72if (isset($_POST['submitFilters']))
73{
74  // test if it was a Smart Album
75  $query = '
76SELECT DISTINCT category_id
77  FROM '.CATEGORY_FILTERS_TABLE.'
78  WHERE category_id = '.$cat_id.'
79;';
80  $was_smart = pwg_db_num_rows(pwg_query($query));
81 
82  /* this album is no longer a SmartAlbum */
83  if ( $was_smart AND !isset($_POST['is_smart']) )
84  {
85    pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;');
86    pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
87    set_random_representant(array($cat_id));
88    invalidate_user_cache();
89  }
90  /* no filter selected */
91  else if ( isset($_POST['is_smart']) AND empty($_POST['filters']) )
92  {
93    array_push($page['errors'], l10n('No filter selected'));
94  }
95  /* everything is fine */
96  else if ( isset($_POST['is_smart']) )
97  {
98    pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
99   
100    foreach ($_POST['filters'] as $filter)
101    {
102      if (($filter = smart_check_filter($filter)) != false)
103      {
104        $query = '
105INSERT IGNORE INTO '.CATEGORY_FILTERS_TABLE.'
106  VALUES(
107    '.$cat_id.',
108    "'.$filter['type'].'",
109    "'.$filter['cond'].'",
110    "'.$filter['value'].'"
111  )
112;';
113      pwg_query($query);
114      }
115    }
116   
117    $associated_images = smart_make_associations($cat_id);
118    $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
119   
120    array_push($page['infos'], sprintf('%d photos associated to the album %s', count($associated_images), ''));
121   
122    define('SMART_NOT_UPDATE', 1);
123    invalidate_user_cache();
124  }
125}
126
127// +-----------------------------------------------------------------------+
128// | Display page                                                          |
129// +-----------------------------------------------------------------------+
130
131/* select options, for html_options */
132$options = array(
133  'tags' => array(
134    'name' => l10n('Tags'),
135    'options' => array(
136      'all'   => l10n('All these tags'),
137      'one'   => l10n('One of these tags'),
138      'none'  => l10n('None of these tags'),
139      'only'  => l10n('Only these tags'),
140      ),
141    ),
142  'date' => array(
143    'name' => l10n('Date'),
144    'options' => array(
145      'the_post'      => l10n('Added on'),
146      'before_post'   => l10n('Added before'),
147      'after_post'    => l10n('Added after'),
148      'the_taken'     => l10n('Created on'),
149      'before_taken'  => l10n('Created before'),
150      'after_taken'   => l10n('Created after'),
151      ),
152    ),
153  'name' => array(
154    'name' => l10n('Photo name'),
155    'options' => array(
156      'contain'     => l10n('Contains'),
157      'begin'       => l10n('Begins with'),
158      'end'         => l10n('Ends with'),
159      'not_contain' => l10n('Doesn\'t contain'),
160      'not_begin'   => l10n('Doesn\'t begin with'),
161      'not_end'     => l10n('Doesn\'t end with'),
162      ),
163    ),
164  'album' => array(
165    'name' => l10n('Album'),
166    'options' => array(
167      'all'   => l10n('All these albums'),
168      'one'   => l10n('One of these albums'),
169      'none'  => l10n('None of these albums'),
170      'only'  => l10n('Only these albums'),
171      ),
172    ),
173  'author' => array(
174    'name' => l10n('Author'),
175    'options' => array(
176      'is'      => l10n('Is'),
177      'in'      => l10n('Is in'),
178      'not_is'  => l10n('Is not'),
179      'not_in'  => l10n('Is not in'),
180      ),
181    ),
182  'hit' => array(
183    'name' => l10n('Hits'),
184    'options' => array(
185      'less' => l10n('Bellow'),
186      'more' => l10n('Above'),
187      ),
188    ),
189  'rating_score' => array(
190    'name' => l10n('Rating score'),
191    'options' => array(
192      'less' => l10n('Bellow'),
193      'more' => l10n('Above'),
194      ),
195    ),
196  'level' => array(
197    'name' => l10n('Privacy level'),
198    'options' => array(),
199    ),
200  'limit' => array(
201    'name' => l10n('Max. number of photos'),
202    'options' => array(),
203    ),
204  );
205$template->assign('options', $options);
206
207/* get filters for this album */
208$query = '
209SELECT *
210  FROM '.CATEGORY_FILTERS_TABLE.'
211  WHERE category_id = '.$cat_id.'
212  ORDER BY
213    type ASC,
214    cond ASC
215;';
216$result = pwg_query($query);
217
218while ($filter = pwg_db_fetch_assoc($result))
219{
220  // get tags name and id
221  if ($filter['type'] == 'tags')
222  {
223    $query = '
224SELECT
225    id,
226    name
227  FROM '.TAGS_TABLE.'
228  WHERE id IN('.$filter['value'].')
229;';
230    $filter['value'] = get_taglist($query); 
231  }
232  else if ($filter['type'] == 'album')
233  {
234    $filter['value'] = explode(',', $filter['value']); 
235  }
236 
237  $template->append('filters', array(
238    'TYPE' => $filter['type'],
239    'COND' => $filter['cond'],
240    'VALUE' => $filter['value'],
241    'CAPTION' => $options[ $filter['type'] ]['name'],
242  ));
243}
244
245/* all tags */
246$query = '
247SELECT
248    id,
249    name
250  FROM '.TAGS_TABLE.'
251;';
252$template->assign('all_tags', get_taglist($query));
253
254/* all albums */
255$query = '
256SELECT
257    id,
258    name,
259    uppercats,
260    global_rank
261  FROM '.CATEGORIES_TABLE.'
262;';
263display_select_cat_wrapper($query, array(), 'all_albums');
264
265/* get image number */
266if ($template->get_template_vars('IMAGE_COUNT') == null)
267{
268  $query = '
269SELECT count(1)
270  FROM '.IMAGE_CATEGORY_TABLE.'
271  WHERE
272    category_id = '.$cat_id.'
273    AND smart = true
274';
275
276  list($image_num) = pwg_db_fetch_row(pwg_query($query));
277  $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num));
278}
279
280
281/* template vars */
282if (isset($_GET['new_smart']))
283{
284  $template->assign('new_smart', true);
285}
286
287$template->assign(array(
288  'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php',
289  'level_options' => get_privacy_level_options(),
290  'F_ACTION' => $self_url,
291  'CATEGORIES_NAV' => get_cat_display_name_cache(
292    $category['uppercats'],
293    SMART_ADMIN.'-album&amp;cat_id='
294    ),
295));
296
297$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/album.tpl');
298
299?>
Note: See TracBrowser for help on using the repository browser.