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

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

updated for Piwigo 2.4
new filters : name, author, level, hits

File size: 8.1 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$template->assign(
137  'options', 
138  array(
139    'tags' => 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    'date' => array(
146      'the_post'      => l10n('Added on'),
147      'before_post'   => l10n('Added before'),
148      'after_post'    => l10n('Added after'),
149      'the_taken'     => l10n('Created on'),
150      'before_taken'  => l10n('Created before'),
151      'after_taken'   => l10n('Created after'),
152      ),
153   
154    'name' => array(
155      'contain'     => l10n('Contains'),
156      'begin'       => l10n('Begins with'),
157      'end'         => l10n('Ends with'),
158      'not_contain' => l10n('Doesn\'t contain'),
159      'not_begin'   => l10n('Doesn\'t begin with'),
160      'not_end'     => l10n('Doesn\'t end with'),
161      ),
162    'author' => array(
163      'is'      => l10n('Is'),
164      'in'      => l10n('Is in'),
165      'not_is'  => l10n('Is not'),
166      'not_in'  => l10n('Is not in'),
167      ),
168    'hit' => array(
169      'less' => l10n('Bellow'),
170      'more' => l10n('Above'),
171      ),
172    'level' => array('level' => 'level'), // second filter not used
173    'limit' => array('limit' => 'limit'), // second filter not used
174    )
175  );
176
177/* get filters for this album */
178$query = '
179SELECT *
180  FROM '.CATEGORY_FILTERS_TABLE.'
181  WHERE category_id = '.$cat_id.'
182  ORDER BY
183    type ASC,
184    cond ASC
185;';
186$result = pwg_query($query);
187
188while ($filter = pwg_db_fetch_assoc($result))
189{
190  // get tags name and id
191  if ($filter['type'] == 'tags')
192  {
193    $query = '
194SELECT
195    id,
196    name
197  FROM '.TAGS_TABLE.'
198  WHERE id IN('.$filter['value'].')
199;';
200    $filter['value'] = get_taglist($query); 
201  }
202 
203  $template->append('filters', array(
204    'TYPE' => $filter['type'],
205    'COND' => $filter['cond'],
206    'VALUE' => $filter['value'],
207  ));
208}
209
210/* all tags */
211$query = '
212SELECT
213    id,
214    name
215  FROM '.TAGS_TABLE.'
216;';
217$all_tags = get_taglist($query);
218
219/* get image number */
220if ($template->get_template_vars('IMAGE_COUNT') == null)
221{
222  $query = '
223SELECT count(1)
224  FROM '.IMAGE_CATEGORY_TABLE.'
225  WHERE
226    category_id = '.$cat_id.'
227    AND smart = true
228';
229
230  list($image_num) = pwg_db_fetch_row(pwg_query($query));
231  $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num));
232}
233
234if (isset($_GET['new_smart']))
235{
236  $template->assign('new_smart', true);
237}
238
239$template->assign(array(
240  'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php',
241  'all_tags' => $all_tags,
242  'level_options' => get_privacy_level_options(),
243  'F_ACTION' => $self_url,
244  'CATEGORIES_NAV' => get_cat_display_name_cache(
245    $category['uppercats'],
246    SMART_ADMIN.'-album&amp;cat_id='
247    ),
248));
249
250$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/album.tpl');
251
252?>
Note: See TracBrowser for help on using the repository browser.