1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2011 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") ) |
---|
25 | { |
---|
26 | die ("Hacking attempt!"); |
---|
27 | } |
---|
28 | |
---|
29 | // +-----------------------------------------------------------------------+ |
---|
30 | // | Check Access and exit when user status is not ok | |
---|
31 | // +-----------------------------------------------------------------------+ |
---|
32 | |
---|
33 | check_status(ACCESS_ADMINISTRATOR); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | add/edit birthdate | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | |
---|
39 | if (isset($_POST['submit_add'])) |
---|
40 | { |
---|
41 | check_input_parameter('who', $_POST, false, '/^~~\d+~~$/'); |
---|
42 | |
---|
43 | $tag_id = str_replace('~', '', $_POST['who']); |
---|
44 | |
---|
45 | // does the tag exists? |
---|
46 | $query = ' |
---|
47 | SELECT * |
---|
48 | FROM '.TAGS_TABLE.' |
---|
49 | WHERE id = '.$tag_id.' |
---|
50 | ;'; |
---|
51 | $result = pwg_query($query); |
---|
52 | if (pwg_db_num_rows($result) == 0) |
---|
53 | { |
---|
54 | die('this tag does not exist'); |
---|
55 | } |
---|
56 | |
---|
57 | $who = pwg_db_fetch_assoc($result); |
---|
58 | |
---|
59 | if (!strtotime($_POST['birthdate'])) |
---|
60 | { |
---|
61 | die('hacking attempt: invalid "birthdate" option'); |
---|
62 | } |
---|
63 | |
---|
64 | single_update( |
---|
65 | TAGS_TABLE, |
---|
66 | array('birthdate' => date('Y-m-d H:i:s', strtotime($_POST['birthdate']))), |
---|
67 | array('id' => $who['id']) |
---|
68 | ); |
---|
69 | } |
---|
70 | |
---|
71 | // +-----------------------------------------------------------------------+ |
---|
72 | // | remove birthdate | |
---|
73 | // +-----------------------------------------------------------------------+ |
---|
74 | |
---|
75 | if (isset($_GET['delete'])) |
---|
76 | { |
---|
77 | check_input_parameter('delete', $_GET, false, PATTERN_ID); |
---|
78 | |
---|
79 | $query = ' |
---|
80 | SELECT * |
---|
81 | FROM '.TAGS_TABLE.' |
---|
82 | WHERE id = '.$_GET['delete'].' |
---|
83 | ;'; |
---|
84 | $result = pwg_query($query); |
---|
85 | if (pwg_db_num_rows($result) == 0) |
---|
86 | { |
---|
87 | die('this tag does not exist'); |
---|
88 | } |
---|
89 | |
---|
90 | $tag = pwg_db_fetch_assoc($result); |
---|
91 | $name = trigger_event('render_tag_name', $tag['name']); |
---|
92 | |
---|
93 | $query = ' |
---|
94 | UPDATE '.TAGS_TABLE.' |
---|
95 | SET birthdate = NULL |
---|
96 | WHERE id = '.$_GET['delete'].' |
---|
97 | ;'; |
---|
98 | $result = pwg_query($query); |
---|
99 | |
---|
100 | $_SESSION['page_infos'] = array( |
---|
101 | sprintf( |
---|
102 | l10n('Birthdate removed for %s'), |
---|
103 | $name |
---|
104 | ) |
---|
105 | ); |
---|
106 | redirect(BIRTHDATE_ADMIN); |
---|
107 | } |
---|
108 | |
---|
109 | // +-----------------------------------------------------------------------+ |
---|
110 | // | template init | |
---|
111 | // +-----------------------------------------------------------------------+ |
---|
112 | |
---|
113 | // define template file |
---|
114 | $template->set_filename( |
---|
115 | 'birthdate_content', |
---|
116 | realpath(BIRTHDATE_PATH . 'admin/template/birthdates.tpl') |
---|
117 | ); |
---|
118 | |
---|
119 | // +-----------------------------------------------------------------------+ |
---|
120 | // | prepare form | |
---|
121 | // +-----------------------------------------------------------------------+ |
---|
122 | |
---|
123 | // edit mode? |
---|
124 | if (isset($_GET['edit'])) |
---|
125 | { |
---|
126 | check_input_parameter('edit', $_GET, false, PATTERN_ID); |
---|
127 | |
---|
128 | $query = ' |
---|
129 | UPDATE '.TAGS_TABLE.' |
---|
130 | SET birthdate = NULL |
---|
131 | WHERE id = '.$_GET['edit'].' |
---|
132 | ;'; |
---|
133 | $result = pwg_query($query); |
---|
134 | $row = pwg_db_fetch_assoc($result); |
---|
135 | |
---|
136 | if (isset($row['id'])) |
---|
137 | { |
---|
138 | $category_options_selected = $row['category_id']; |
---|
139 | |
---|
140 | $template->assign( |
---|
141 | array( |
---|
142 | 'edit' => $row['id'], |
---|
143 | 'who_options_selected' => $row['type'], |
---|
144 | 'user_options_selected' => $row['user_id'], |
---|
145 | 'group_options_selected' => $row['group_id'], |
---|
146 | 'recursive' => get_boolean($row['recursive']), |
---|
147 | 'create_subcategories' => get_boolean($row['create_subcategories']), |
---|
148 | 'moderated' => get_boolean($row['moderated']), |
---|
149 | ) |
---|
150 | ); |
---|
151 | } |
---|
152 | } |
---|
153 | else |
---|
154 | { |
---|
155 | $query = ' |
---|
156 | SELECT |
---|
157 | id, |
---|
158 | name |
---|
159 | FROM '.TAGS_TABLE.' |
---|
160 | ;'; |
---|
161 | $tags = get_taglist($query, false); |
---|
162 | |
---|
163 | $template->assign( |
---|
164 | array( |
---|
165 | 'tags' => $tags, |
---|
166 | ) |
---|
167 | ); |
---|
168 | } |
---|
169 | |
---|
170 | // +-----------------------------------------------------------------------+ |
---|
171 | // | birthdate list | |
---|
172 | // +-----------------------------------------------------------------------+ |
---|
173 | |
---|
174 | $query = ' |
---|
175 | SELECT * |
---|
176 | FROM '.TAGS_TABLE.' |
---|
177 | WHERE birthdate IS NOT NULL |
---|
178 | ORDER BY name |
---|
179 | ;'; |
---|
180 | $result = pwg_query($query); |
---|
181 | |
---|
182 | $birthdates = array(); |
---|
183 | $tag_ids = array(); |
---|
184 | $tag_infos = array(); |
---|
185 | |
---|
186 | while ($row = pwg_db_fetch_assoc($result)) |
---|
187 | { |
---|
188 | array_push($birthdates, $row); |
---|
189 | array_push($tag_ids, $row['id']); |
---|
190 | } |
---|
191 | |
---|
192 | if (!empty($tag_ids)) |
---|
193 | { |
---|
194 | $query = ' |
---|
195 | SELECT |
---|
196 | tag_id, |
---|
197 | COUNT(*) AS counter, |
---|
198 | MIN(date_creation) AS min_date, |
---|
199 | MAX(date_creation) AS max_date |
---|
200 | FROM '.IMAGE_TAG_TABLE.' |
---|
201 | JOIN '.IMAGES_TABLE.' ON image_id=id |
---|
202 | WHERE tag_id in ('.implode(',', $tag_ids).') |
---|
203 | GROUP BY tag_id |
---|
204 | ;'; |
---|
205 | $result = pwg_query($query); |
---|
206 | |
---|
207 | while ($row = pwg_db_fetch_assoc($result)) |
---|
208 | { |
---|
209 | $tag_infos[ $row['tag_id'] ] = $row; |
---|
210 | } |
---|
211 | } |
---|
212 | |
---|
213 | foreach ($birthdates as $birthdate) |
---|
214 | { |
---|
215 | $photos_label = l10n('No photo'); |
---|
216 | if (isset($tag_infos[ $birthdate['id'] ])) |
---|
217 | { |
---|
218 | $url = make_index_url(array('tags' => array($birthdate))); |
---|
219 | |
---|
220 | $photos_label = '<a href="'.$url.'" target="_blank">'; |
---|
221 | $photos_label.= l10n_dec('%d photo', '%d photos', $tag_infos[ $birthdate['id'] ]['counter']); |
---|
222 | $photos_label.= '</a> ('; |
---|
223 | |
---|
224 | $from = $tag_infos[ $birthdate['id'] ]['min_date']; |
---|
225 | $to = $tag_infos[ $birthdate['id'] ]['max_date']; |
---|
226 | |
---|
227 | if (date('Y-m-d', strtotime($from)) == date('Y-m-d', strtotime($to))) |
---|
228 | { |
---|
229 | $photos_label.= format_date($from); |
---|
230 | } |
---|
231 | else |
---|
232 | { |
---|
233 | $photos_label.= sprintf( |
---|
234 | l10n('from %s to %s'), |
---|
235 | format_date($from), |
---|
236 | format_date($to) |
---|
237 | ); |
---|
238 | } |
---|
239 | |
---|
240 | $photos_label.= ')'; |
---|
241 | } |
---|
242 | |
---|
243 | $template->append( |
---|
244 | 'birthdates', |
---|
245 | array( |
---|
246 | 'NAME' => $birthdate['name'], |
---|
247 | 'BIRTHDATE' => format_date($birthdate['birthdate'], true), |
---|
248 | 'PHOTOS' => $photos_label, |
---|
249 | 'U_DELETE' => BIRTHDATE_ADMIN.'&delete='.$birthdate['id'], |
---|
250 | 'HIGHLIGHT' => (isset($_POST['who']) and '~~'.$birthdate['id'].'~~' == $_POST['who']) ? true : false, |
---|
251 | 'TAG_ID' => $birthdate['id'], |
---|
252 | 'BIRTHDATE_RAW' => date('Y-m-d H:i', strtotime($birthdate['birthdate'])), |
---|
253 | ) |
---|
254 | ); |
---|
255 | } |
---|
256 | ?> |
---|