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 | |
---|
24 | if(!defined("PHPWG_ROOT_PATH")) die ("Hacking attempt!"); |
---|
25 | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | // | Basic checks | |
---|
28 | // +-----------------------------------------------------------------------+ |
---|
29 | |
---|
30 | check_status(ACCESS_ADMINISTRATOR); |
---|
31 | |
---|
32 | check_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&cat_id='.$_GET['cat_id']; |
---|
36 | |
---|
37 | $query = ' |
---|
38 | SELECT * |
---|
39 | FROM '.CATEGORIES_TABLE.' |
---|
40 | WHERE id = '.$_GET['cat_id'].' |
---|
41 | ;'; |
---|
42 | $category = pwg_db_fetch_assoc(pwg_query($query)); |
---|
43 | |
---|
44 | if (!isset($category['id'])) |
---|
45 | { |
---|
46 | die("unknown album"); |
---|
47 | } |
---|
48 | |
---|
49 | // +-----------------------------------------------------------------------+ |
---|
50 | // | Tabs | |
---|
51 | // +-----------------------------------------------------------------------+ |
---|
52 | |
---|
53 | include_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 |
---|
63 | if ($category['dir'] != NULL) |
---|
64 | { |
---|
65 | die("physical album"); |
---|
66 | } |
---|
67 | |
---|
68 | // +-----------------------------------------------------------------------+ |
---|
69 | // | Save Filters | |
---|
70 | // +-----------------------------------------------------------------------+ |
---|
71 | |
---|
72 | if (isset($_POST['submitFilters'])) |
---|
73 | { |
---|
74 | // test if it was a Smart Album |
---|
75 | $query = ' |
---|
76 | SELECT 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 = ' |
---|
105 | INSERT 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 | 'author' => array( |
---|
165 | 'name' => l10n('Author'), |
---|
166 | 'options' => array( |
---|
167 | 'is' => l10n('Is'), |
---|
168 | 'in' => l10n('Is in'), |
---|
169 | 'not_is' => l10n('Is not'), |
---|
170 | 'not_in' => l10n('Is not in'), |
---|
171 | ), |
---|
172 | ), |
---|
173 | 'hit' => array( |
---|
174 | 'name' => l10n('Hits'), |
---|
175 | 'options' => array( |
---|
176 | 'less' => l10n('Bellow'), |
---|
177 | 'more' => l10n('Above'), |
---|
178 | ), |
---|
179 | ), |
---|
180 | 'rating_score' => array( |
---|
181 | 'name' => l10n('Rating score'), |
---|
182 | 'options' => array( |
---|
183 | 'less' => l10n('Bellow'), |
---|
184 | 'more' => l10n('Above'), |
---|
185 | ), |
---|
186 | ), |
---|
187 | 'level' => array( |
---|
188 | 'name' => l10n('Privacy level'), |
---|
189 | 'options' => array(), |
---|
190 | ), |
---|
191 | 'limit' => array( |
---|
192 | 'name' => l10n('Max. number of photos'), |
---|
193 | 'options' => array(), |
---|
194 | ), |
---|
195 | ); |
---|
196 | $template->assign('options', $options); |
---|
197 | |
---|
198 | /* get filters for this album */ |
---|
199 | $query = ' |
---|
200 | SELECT * |
---|
201 | FROM '.CATEGORY_FILTERS_TABLE.' |
---|
202 | WHERE category_id = '.$cat_id.' |
---|
203 | ORDER BY |
---|
204 | type ASC, |
---|
205 | cond ASC |
---|
206 | ;'; |
---|
207 | $result = pwg_query($query); |
---|
208 | |
---|
209 | while ($filter = pwg_db_fetch_assoc($result)) |
---|
210 | { |
---|
211 | // get tags name and id |
---|
212 | if ($filter['type'] == 'tags') |
---|
213 | { |
---|
214 | $query = ' |
---|
215 | SELECT |
---|
216 | id, |
---|
217 | name |
---|
218 | FROM '.TAGS_TABLE.' |
---|
219 | WHERE id IN('.$filter['value'].') |
---|
220 | ;'; |
---|
221 | $filter['value'] = get_taglist($query); |
---|
222 | } |
---|
223 | |
---|
224 | $template->append('filters', array( |
---|
225 | 'TYPE' => $filter['type'], |
---|
226 | 'COND' => $filter['cond'], |
---|
227 | 'VALUE' => $filter['value'], |
---|
228 | 'CAPTION' => $options[ $filter['type'] ]['name'], |
---|
229 | )); |
---|
230 | } |
---|
231 | |
---|
232 | /* all tags */ |
---|
233 | $query = ' |
---|
234 | SELECT |
---|
235 | id, |
---|
236 | name |
---|
237 | FROM '.TAGS_TABLE.' |
---|
238 | ;'; |
---|
239 | $all_tags = get_taglist($query); |
---|
240 | |
---|
241 | /* get image number */ |
---|
242 | if ($template->get_template_vars('IMAGE_COUNT') == null) |
---|
243 | { |
---|
244 | $query = ' |
---|
245 | SELECT count(1) |
---|
246 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
247 | WHERE |
---|
248 | category_id = '.$cat_id.' |
---|
249 | AND smart = true |
---|
250 | '; |
---|
251 | |
---|
252 | list($image_num) = pwg_db_fetch_row(pwg_query($query)); |
---|
253 | $template->assign('IMAGE_COUNT', l10n_dec('%d photo', '%d photos', $image_num)); |
---|
254 | } |
---|
255 | |
---|
256 | if (isset($_GET['new_smart'])) |
---|
257 | { |
---|
258 | $template->assign('new_smart', true); |
---|
259 | } |
---|
260 | |
---|
261 | $template->assign(array( |
---|
262 | 'COUNT_SCRIPT_URL' => SMART_PATH.'include/count_images.php', |
---|
263 | 'all_tags' => $all_tags, |
---|
264 | 'level_options' => get_privacy_level_options(), |
---|
265 | 'F_ACTION' => $self_url, |
---|
266 | 'CATEGORIES_NAV' => get_cat_display_name_cache( |
---|
267 | $category['uppercats'], |
---|
268 | SMART_ADMIN.'-album&cat_id=' |
---|
269 | ), |
---|
270 | )); |
---|
271 | |
---|
272 | $template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/album.tpl'); |
---|
273 | |
---|
274 | ?> |
---|