1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | infos_images.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-02-11 23:20:38 +0000 (Wed, 11 Feb 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 362 $ |
---|
12 | // +-----------------------------------------------------------------------+ |
---|
13 | // | This program is free software; you can redistribute it and/or modify | |
---|
14 | // | it under the terms of the GNU General Public License as published by | |
---|
15 | // | the Free Software Foundation | |
---|
16 | // | | |
---|
17 | // | This program is distributed in the hope that it will be useful, but | |
---|
18 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
19 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
20 | // | General Public License for more details. | |
---|
21 | // | | |
---|
22 | // | You should have received a copy of the GNU General Public License | |
---|
23 | // | along with this program; if not, write to the Free Software | |
---|
24 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
25 | // | USA. | |
---|
26 | // +-----------------------------------------------------------------------+ |
---|
27 | |
---|
28 | include_once( './admin/include/isadmin.inc.php' ); |
---|
29 | include_once( './template/'.$user['template'].'/htmlfunctions.inc.php' ); |
---|
30 | //-------------------------------------------------------------- initialization |
---|
31 | $page['nb_image_page'] = 5; |
---|
32 | |
---|
33 | check_cat_id( $_GET['cat_id'] ); |
---|
34 | |
---|
35 | $errors = array(); |
---|
36 | |
---|
37 | if ( isset( $page['cat'] ) ) |
---|
38 | { |
---|
39 | //--------------------------------------------------- update individual options |
---|
40 | if ( isset( $_POST['submit'] ) ) |
---|
41 | { |
---|
42 | if ( isset( $_POST['associate'] ) and $_POST['associate'] != '' ) |
---|
43 | { |
---|
44 | // does the uppercat id exists in the database ? |
---|
45 | if ( !is_numeric( $_POST['associate'] ) ) |
---|
46 | { |
---|
47 | array_push( $errors, $lang['cat_unknown_id'] ); |
---|
48 | } |
---|
49 | else |
---|
50 | { |
---|
51 | $query = 'SELECT id'; |
---|
52 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
53 | $query.= ' WHERE id = '.$_POST['associate']; |
---|
54 | $query.= ';'; |
---|
55 | if ( mysql_num_rows( mysql_query( $query ) ) == 0 ) |
---|
56 | array_push( $errors, $lang['cat_unknown_id'] ); |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | $associate = false; |
---|
61 | |
---|
62 | $query = 'SELECT id,file'; |
---|
63 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
64 | $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
65 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
66 | $query.= ';'; |
---|
67 | $result = mysql_query( $query ); |
---|
68 | while ( $row = mysql_fetch_array( $result ) ) |
---|
69 | { |
---|
70 | $name = 'name-'.$row['id']; |
---|
71 | $author = 'author-'.$row['id']; |
---|
72 | $comment = 'comment-'.$row['id']; |
---|
73 | $date_creation = 'date_creation-'.$row['id']; |
---|
74 | $keywords = 'keywords-'.$row['id']; |
---|
75 | if ( isset( $_POST[$name] ) ) |
---|
76 | { |
---|
77 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
78 | |
---|
79 | $query.= ' SET name = '; |
---|
80 | if ( $_POST[$name] == '' ) |
---|
81 | $query.= 'NULL'; |
---|
82 | else |
---|
83 | $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'"; |
---|
84 | |
---|
85 | $query.= ', author = '; |
---|
86 | if ( $_POST[$author] == '' ) |
---|
87 | $query.= 'NULL'; |
---|
88 | else |
---|
89 | $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'"; |
---|
90 | |
---|
91 | $query.= ', comment = '; |
---|
92 | if ( $_POST[$comment] == '' ) |
---|
93 | $query.= 'NULL'; |
---|
94 | else |
---|
95 | $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'"; |
---|
96 | |
---|
97 | $query.= ', date_creation = '; |
---|
98 | if ( check_date_format( $_POST[$date_creation] ) ) |
---|
99 | $query.= "'".date_convert( $_POST[$date_creation] )."'"; |
---|
100 | else if ( $_POST[$date_creation] == '' ) |
---|
101 | $query.= 'NULL'; |
---|
102 | |
---|
103 | $query.= ', keywords = '; |
---|
104 | |
---|
105 | $keywords_array = get_keywords( $_POST[$keywords] ); |
---|
106 | if ( count( $keywords_array ) == 0 ) $query.= 'NULL'; |
---|
107 | else $query.= "'".implode( ',', $keywords_array )."'"; |
---|
108 | |
---|
109 | $query.= ' WHERE id = '.$row['id']; |
---|
110 | $query.= ';'; |
---|
111 | mysql_query( $query ); |
---|
112 | } |
---|
113 | // add link to another category |
---|
114 | if ( isset( $_POST['check-'.$row['id']] ) and count( $errors ) == 0 ) |
---|
115 | { |
---|
116 | $query = 'INSERT INTO '.PREFIX_TABLE.'image_category'; |
---|
117 | $query.= ' (image_id,category_id) VALUES'; |
---|
118 | $query.= ' ('.$row['id'].','.$_POST['associate'].')'; |
---|
119 | $query.= ';'; |
---|
120 | mysql_query( $query ); |
---|
121 | $associate = true; |
---|
122 | } |
---|
123 | } |
---|
124 | update_category( $_POST['associate'] ); |
---|
125 | if ( $associate ) synchronize_all_users(); |
---|
126 | //------------------------------------------------------ update general options |
---|
127 | if ( isset( $_POST['use_common_author'] ) ) |
---|
128 | { |
---|
129 | $query = 'SELECT image_id'; |
---|
130 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
131 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
132 | $result = mysql_query( $query ); |
---|
133 | while ( $row = mysql_fetch_array( $result ) ) |
---|
134 | { |
---|
135 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
136 | if ( $_POST['author_cat'] == '' ) |
---|
137 | { |
---|
138 | $query.= ' SET author = NULL'; |
---|
139 | } |
---|
140 | else |
---|
141 | { |
---|
142 | $query.= ' SET author = '; |
---|
143 | $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'"; |
---|
144 | } |
---|
145 | $query.= ' WHERE id = '.$row['image_id']; |
---|
146 | $query.= ';'; |
---|
147 | mysql_query( $query ); |
---|
148 | } |
---|
149 | } |
---|
150 | if ( isset( $_POST['use_common_date_creation'] ) ) |
---|
151 | { |
---|
152 | if ( check_date_format( $_POST['date_creation_cat'] ) ) |
---|
153 | { |
---|
154 | $date = date_convert( $_POST['date_creation_cat'] ); |
---|
155 | $query = 'SELECT image_id'; |
---|
156 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
157 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
158 | $result = mysql_query( $query ); |
---|
159 | while ( $row = mysql_fetch_array( $result ) ) |
---|
160 | { |
---|
161 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
162 | if ( $_POST['date_creation_cat'] == '' ) |
---|
163 | { |
---|
164 | $query.= ' SET date_creation = NULL'; |
---|
165 | } |
---|
166 | else |
---|
167 | { |
---|
168 | $query.= " SET date_creation = '".$date."'"; |
---|
169 | } |
---|
170 | $query.= ' WHERE id = '.$row['image_id']; |
---|
171 | $query.= ';'; |
---|
172 | mysql_query( $query ); |
---|
173 | } |
---|
174 | } |
---|
175 | else |
---|
176 | { |
---|
177 | array_push( $errors, $lang['err_date'] ); |
---|
178 | } |
---|
179 | } |
---|
180 | if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' ) |
---|
181 | { |
---|
182 | $query = 'SELECT id,keywords'; |
---|
183 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
184 | $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
185 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
186 | $query.= ';'; |
---|
187 | $result = mysql_query( $query ); |
---|
188 | while ( $row = mysql_fetch_array( $result ) ) |
---|
189 | { |
---|
190 | if ( !isset( $row['keywords'] ) ) $specific_keywords = array(); |
---|
191 | else $specific_keywords = explode( ',', $row['keywords'] ); |
---|
192 | |
---|
193 | $common_keywords = get_keywords( $_POST['keywords_cat'] ); |
---|
194 | // first possiblity : adding the given keywords to all the pictures |
---|
195 | if ( $_POST['common_keywords'] == 'add' ) |
---|
196 | { |
---|
197 | $keywords = array_merge( $specific_keywords, $common_keywords ); |
---|
198 | $keywords = array_unique( $keywords ); |
---|
199 | } |
---|
200 | // second possiblity : removing the given keywords from all pictures |
---|
201 | // (without deleting the other specific keywords |
---|
202 | if ( $_POST['common_keywords'] == 'remove' ) |
---|
203 | { |
---|
204 | $keywords = array_diff( $specific_keywords, $common_keywords ); |
---|
205 | } |
---|
206 | // cleaning the keywords array, sometimes, an empty value still remain |
---|
207 | $keywords = array_remove( $keywords, '' ); |
---|
208 | // updating the picture with new keywords array |
---|
209 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
210 | $query.= ' SET keywords = '; |
---|
211 | if ( count( $keywords ) == 0 ) |
---|
212 | { |
---|
213 | $query.= 'NULL'; |
---|
214 | } |
---|
215 | else |
---|
216 | { |
---|
217 | $query.= '"'; |
---|
218 | $i = 0; |
---|
219 | foreach ( $keywords as $keyword ) { |
---|
220 | if ( $i++ > 0 ) $query.= ','; |
---|
221 | $query.= $keyword; |
---|
222 | } |
---|
223 | $query.= '"'; |
---|
224 | } |
---|
225 | $query.= ' WHERE id = '.$row['id']; |
---|
226 | $query.= ';'; |
---|
227 | mysql_query( $query ); |
---|
228 | } |
---|
229 | } |
---|
230 | } |
---|
231 | //--------------------------------------------------------- form initialization |
---|
232 | if( !isset( $_GET['start'] ) |
---|
233 | or !is_numeric( $_GET['start'] ) |
---|
234 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
235 | { |
---|
236 | $page['start'] = 0; |
---|
237 | } |
---|
238 | else |
---|
239 | { |
---|
240 | $page['start'] = $_GET['start']; |
---|
241 | } |
---|
242 | |
---|
243 | if ( isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0 ) |
---|
244 | { |
---|
245 | $page['start'] = |
---|
246 | floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page']; |
---|
247 | } |
---|
248 | // retrieving category information |
---|
249 | $result = get_cat_info( $page['cat'] ); |
---|
250 | $cat['name'] = $result['name']; |
---|
251 | $cat['nb_images'] = $result['nb_images']; |
---|
252 | //----------------------------------------------------- template initialization |
---|
253 | $sub = $vtp->Open('./template/'.$user['template'].'/admin/infos_image.vtp'); |
---|
254 | $tpl = array( 'infoimage_general','author','infoimage_useforall','submit', |
---|
255 | 'infoimage_creation_date','infoimage_detailed','thumbnail', |
---|
256 | 'infoimage_title','infoimage_comment', |
---|
257 | 'infoimage_creation_date','keywords', |
---|
258 | 'infoimage_addtoall','infoimage_removefromall', |
---|
259 | 'infoimage_keyword_separation','infoimage_associate', |
---|
260 | 'errors_title' ); |
---|
261 | templatize_array( $tpl, 'lang', $sub ); |
---|
262 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
263 | //-------------------------------------------------------------- errors display |
---|
264 | if ( count( $errors ) != 0 ) |
---|
265 | { |
---|
266 | $vtp->addSession( $sub, 'errors' ); |
---|
267 | foreach ( $errors as $error ) { |
---|
268 | $vtp->addSession( $sub, 'li' ); |
---|
269 | $vtp->setVar( $sub, 'li.content', $error ); |
---|
270 | $vtp->closeSession( $sub, 'li' ); |
---|
271 | } |
---|
272 | $vtp->closeSession( $sub, 'errors' ); |
---|
273 | } |
---|
274 | //------------------------------------------------------------------------ form |
---|
275 | $url = './admin.php?page=infos_images&cat_id='.$page['cat']; |
---|
276 | $url.= '&start='.$page['start']; |
---|
277 | $vtp->setVar( $sub, 'form_action', add_session_id( $url ) ); |
---|
278 | $page['navigation_bar'] = create_navigation_bar( |
---|
279 | $url, $cat['nb_images'],$page['start'], $page['nb_image_page'], '' ); |
---|
280 | $vtp->setVar( $sub, 'navigation_bar', $page['navigation_bar'] ); |
---|
281 | $cat_name = get_cat_display_name( $cat['name'], ' - ', 'font-style:italic;'); |
---|
282 | $vtp->setVar( $sub, 'cat_name', $cat_name ); |
---|
283 | |
---|
284 | $array_cat_directories = array(); |
---|
285 | |
---|
286 | $infos = array( 'id','file','comment','author','tn_ext','name' |
---|
287 | ,'date_creation','keywords','storage_category_id' |
---|
288 | ,'category_id' ); |
---|
289 | |
---|
290 | $query = 'SELECT '.implode( ',', $infos ); |
---|
291 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
292 | $query.= ' INNER JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
293 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
294 | $query.= $conf['order_by']; |
---|
295 | $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page']; |
---|
296 | $query.= ';'; |
---|
297 | $result = mysql_query( $query ); |
---|
298 | while ( $row = mysql_fetch_array( $result ) ) |
---|
299 | { |
---|
300 | foreach ($infos as $info) { if (!isset($row[$info])) $row[$info] = ''; } |
---|
301 | |
---|
302 | $vtp->addSession( $sub, 'picture' ); |
---|
303 | $vtp->setVar( $sub, 'picture.id', $row['id'] ); |
---|
304 | $vtp->setVar( $sub, 'picture.filename', $row['file'] ); |
---|
305 | $vtp->setVar( $sub, 'picture.name', $row['name'] ); |
---|
306 | $vtp->setVar( $sub, 'picture.author', $row['author'] ); |
---|
307 | $vtp->setVar( $sub, 'picture.comment', $row['comment'] ); |
---|
308 | $vtp->setVar( $sub, 'picture.keywords', $row['keywords'] ); |
---|
309 | $vtp->setVar( $sub, 'picture.date_creation', |
---|
310 | date_convert_back( $row['date_creation'] ) ); |
---|
311 | $file = get_filename_wo_extension( $row['file'] ); |
---|
312 | $vtp->setVar( $sub, 'picture.default_name', $file ); |
---|
313 | // creating url to thumbnail |
---|
314 | if ( !isset( $array_cat_directories[$row['storage_category_id']] ) ) |
---|
315 | { |
---|
316 | $array_cat_directories[$row['storage_category_id']] = |
---|
317 | get_complete_dir( $row['storage_category_id'] ); |
---|
318 | } |
---|
319 | $thumbnail_url = $array_cat_directories[$row['storage_category_id']]; |
---|
320 | $thumbnail_url.= 'thumbnail/'; |
---|
321 | $thumbnail_url.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; |
---|
322 | $vtp->setVar( $sub, 'picture.thumbnail_url', $thumbnail_url ); |
---|
323 | $url = './admin.php?page=picture_modify&image_id='.$row['id']; |
---|
324 | $vtp->setVar( $sub, 'picture.url', add_session_id( $url ) ); |
---|
325 | $vtp->closeSession( $sub, 'picture' ); |
---|
326 | } |
---|
327 | // Virtualy associate a picture to a category |
---|
328 | // |
---|
329 | // We only show a List Of Values if the number of categories is less than |
---|
330 | // $conf['max_LOV_categories'] |
---|
331 | $query = 'SELECT COUNT(id) AS nb_total_categories'; |
---|
332 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
333 | $query.= ';'; |
---|
334 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
335 | if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] ) |
---|
336 | { |
---|
337 | $vtp->addSession( $sub, 'associate_LOV' ); |
---|
338 | $page['plain_structure'] = get_plain_structure( true ); |
---|
339 | $structure = create_structure( '', array() ); |
---|
340 | display_categories( $structure, ' ' ); |
---|
341 | $vtp->closeSession( $sub, 'associate_LOV' ); |
---|
342 | } |
---|
343 | // else, we only display a small text field, we suppose the administrator |
---|
344 | // knows the id of its category |
---|
345 | else |
---|
346 | { |
---|
347 | $vtp->addSession( $sub, 'associate_text' ); |
---|
348 | $vtp->closeSession( $sub, 'associate_text' ); |
---|
349 | } |
---|
350 | } |
---|
351 | //----------------------------------------------------------- sending html code |
---|
352 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
353 | ?> |
---|