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

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

add rating_score filter

File size: 8.6 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->add('properties', l10n('Properties'), $admin_album_base_url.'-properties');
56$tabsheet->add('sort_order', l10n('Manage photo ranks'), $admin_album_base_url.'-sort_order');
57$tabsheet->add('permissions', l10n('Permissions'), $admin_album_base_url.'-permissions');
58$tabsheet->add('notification', l10n('Notification'), $admin_album_base_url.'-notification');
59$tabsheet->add('smartalbum', 'SmartAlbum', $self_url);
60$tabsheet->select('smartalbum');
61$tabsheet->assign();
62
63
64$cat_id = $_GET['cat_id'];
65
66// category must be virtual
67if ($category['dir'] != NULL)
68{
69  die("physical album");
70}
71
72// +-----------------------------------------------------------------------+
73// | Save Filters                                                          |
74// +-----------------------------------------------------------------------+
75
76if (isset($_POST['submitFilters']))
77{
78  // test if it was a Smart Album
79  $query = '
80SELECT DISTINCT category_id
81  FROM '.CATEGORY_FILTERS_TABLE.'
82  WHERE category_id = '.$cat_id.'
83;';
84  $was_smart = pwg_db_num_rows(pwg_query($query));
85 
86  /* this album is no longer a SmartAlbum */
87  if ( $was_smart AND !isset($_POST['is_smart']) )
88  {
89    pwg_query('DELETE FROM '.IMAGE_CATEGORY_TABLE.' WHERE category_id = '.$cat_id.' AND smart = true;');
90    pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
91    set_random_representant(array($cat_id));
92    invalidate_user_cache();
93  }
94  /* no filter selected */
95  else if ( isset($_POST['is_smart']) AND empty($_POST['filters']) )
96  {
97    array_push($page['errors'], l10n('No filter selected'));
98  }
99  /* everything is fine */
100  else if ( isset($_POST['is_smart']) )
101  {
102    pwg_query('DELETE FROM '.CATEGORY_FILTERS_TABLE.' WHERE category_id = '.$cat_id.';');
103   
104    foreach ($_POST['filters'] as $filter)
105    {
106      if (($filter = smart_check_filter($filter)) != false)
107      {
108        $query = '
109INSERT IGNORE INTO '.CATEGORY_FILTERS_TABLE.'
110  VALUES(
111    '.$cat_id.',
112    "'.$filter['type'].'",
113    "'.$filter['cond'].'",
114    "'.$filter['value'].'"
115  )
116;';
117      pwg_query($query);
118      }
119    }
120   
121    $associated_images = smart_make_associations($cat_id);
122    $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', count($associated_images)));
123   
124    array_push($page['infos'], sprintf('%d photos associated to the album %s', count($associated_images), ''));
125   
126    define('SMART_NOT_UPDATE', 1);
127    invalidate_user_cache();
128  }
129}
130
131// +-----------------------------------------------------------------------+
132// | Display page                                                          |
133// +-----------------------------------------------------------------------+
134
135/* select options, for html_options */
136$options = array(
137  'tags' => array(
138    'name' => l10n('Tags'),
139    'options' => array(
140      'all'   => l10n('All these tags'),
141      'one'   => l10n('One of these tags'),
142      'none'  => l10n('None of these tags'),
143      'only'  => l10n('Only these tags'),
144      ),
145    ),
146  'date' => array(
147    'name' => l10n('Date'),
148    'options' => array(
149      'the_post'      => l10n('Added on'),
150      'before_post'   => l10n('Added before'),
151      'after_post'    => l10n('Added after'),
152      'the_taken'     => l10n('Created on'),
153      'before_taken'  => l10n('Created before'),
154      'after_taken'   => l10n('Created after'),
155      ),
156    ),
157  'name' => array(
158    'name' => l10n('Photo name'),
159    'options' => array(
160      'contain'     => l10n('Contains'),
161      'begin'       => l10n('Begins with'),
162      'end'         => l10n('Ends with'),
163      'not_contain' => l10n('Doesn\'t contain'),
164      'not_begin'   => l10n('Doesn\'t begin with'),
165      'not_end'     => l10n('Doesn\'t end with'),
166      ),
167    ),
168  'author' => array(
169    'name' => l10n('Author'),
170    'options' => array(
171      'is'      => l10n('Is'),
172      'in'      => l10n('Is in'),
173      'not_is'  => l10n('Is not'),
174      'not_in'  => l10n('Is not in'),
175      ),
176    ),
177  'hit' => array(
178    'name' => l10n('Hits'),
179    'options' => array(
180      'less' => l10n('Bellow'),
181      'more' => l10n('Above'),
182      ),
183    ),
184  'rating_score' => array(
185    'name' => l10n('Rating score'),
186    'options' => array(
187      'less' => l10n('Bellow'),
188      'more' => l10n('Above'),
189      ),
190    ),
191  'level' => array(
192    'name' => l10n('Privacy level'),
193    'options' => array(),
194    ),
195  'limit' => array(
196    'name' => l10n('Max. number of photos'),
197    'options' => array(),
198    ),
199  );
200$template->assign('options', $options);
201
202/* get filters for this album */
203$query = '
204SELECT *
205  FROM '.CATEGORY_FILTERS_TABLE.'
206  WHERE category_id = '.$cat_id.'
207  ORDER BY
208    type ASC,
209    cond ASC
210;';
211$result = pwg_query($query);
212
213while ($filter = pwg_db_fetch_assoc($result))
214{
215  // get tags name and id
216  if ($filter['type'] == 'tags')
217  {
218    $query = '
219SELECT
220    id,
221    name
222  FROM '.TAGS_TABLE.'
223  WHERE id IN('.$filter['value'].')
224;';
225    $filter['value'] = get_taglist($query); 
226  }
227 
228  $template->append('filters', array(
229    'TYPE' => $filter['type'],
230    'COND' => $filter['cond'],
231    'VALUE' => $filter['value'],
232    'CAPTION' => $options[ $filter['type'] ]['name'],
233  ));
234}
235
236/* all tags */
237$query = '
238SELECT
239    id,
240    name
241  FROM '.TAGS_TABLE.'
242;';
243$all_tags = get_taglist($query);
244
245/* get image number */
246if ($template->get_template_vars('IMAGE_COUNT') == null)
247{
248  $query = '
249SELECT count(1)
250  FROM '.IMAGE_CATEGORY_TABLE.'
251  WHERE
252    category_id = '.$cat_id.'
253    AND smart = true
254';
255
256  list($image_num) = pwg_db_fetch_row(pwg_query($query));
257  $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num));
258}
259
260if (isset($_GET['new_smart']))
261{
262  $template->assign('new_smart', true);
263}
264
265$template->assign(array(
266  'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php',
267  'all_tags' => $all_tags,
268  'level_options' => get_privacy_level_options(),
269  'F_ACTION' => $self_url,
270  'CATEGORIES_NAV' => get_cat_display_name_cache(
271    $category['uppercats'],
272    SMART_ADMIN.'-album&amp;cat_id='
273    ),
274));
275
276$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/album.tpl');
277
278?>
Note: See TracBrowser for help on using the repository browser.