1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * picture_modify.php * |
---|
4 | * ------------------ * |
---|
5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | * $Id: picture_modify.php 311 2004-01-21 23:33:56Z z0rglub $ |
---|
9 | * * |
---|
10 | ***************************************************************************/ |
---|
11 | |
---|
12 | /*************************************************************************** |
---|
13 | * * |
---|
14 | * This program is free software; you can redistribute it and/or modify * |
---|
15 | * it under the terms of the GNU General Public License as published by * |
---|
16 | * the Free Software Foundation; * |
---|
17 | * * |
---|
18 | ***************************************************************************/ |
---|
19 | |
---|
20 | include_once( './include/isadmin.inc.php' ); |
---|
21 | //--------------------------------------------------------- update informations |
---|
22 | $errors = array(); |
---|
23 | // first, we verify whether there is a mistake on the given creation date |
---|
24 | if ( isset( $_POST['creation_date'] ) and $_POST['creation_date'] != '' ) |
---|
25 | { |
---|
26 | if ( !check_date_format( $_POST['creation_date'] ) ) |
---|
27 | array_push( $errors, $lang['err_date'] ); |
---|
28 | } |
---|
29 | if ( isset( $_POST['submit'] ) ) |
---|
30 | { |
---|
31 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
32 | |
---|
33 | $query.= ' SET name = '; |
---|
34 | if ( $_POST['name'] == '' ) |
---|
35 | $query.= 'NULL'; |
---|
36 | else |
---|
37 | $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES )."'"; |
---|
38 | |
---|
39 | $query.= ', author = '; |
---|
40 | if ( $_POST['author'] == '' ) |
---|
41 | $query.= 'NULL'; |
---|
42 | else |
---|
43 | $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'"; |
---|
44 | |
---|
45 | $query.= ', comment = '; |
---|
46 | if ( $_POST['comment'] == '' ) |
---|
47 | $query.= 'NULL'; |
---|
48 | else |
---|
49 | $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'"; |
---|
50 | |
---|
51 | $query.= ', date_creation = '; |
---|
52 | if ( check_date_format( $_POST['creation_date'] ) ) |
---|
53 | $query.= "'".date_convert( $_POST['creation_date'] )."'"; |
---|
54 | else if ( $_POST['creation_date'] == '' ) |
---|
55 | $query.= 'NULL'; |
---|
56 | |
---|
57 | $query.= ', keywords = '; |
---|
58 | $keywords_array = get_keywords( $_POST['keywords'] ); |
---|
59 | if ( count( $keywords_array ) == 0 ) |
---|
60 | $query.= 'NULL'; |
---|
61 | else |
---|
62 | { |
---|
63 | $query.= "'"; |
---|
64 | foreach ( $keywords_array as $i => $keyword ) { |
---|
65 | if ( $i > 0 ) $query.= ','; |
---|
66 | $query.= $keyword; |
---|
67 | } |
---|
68 | $query.= "'"; |
---|
69 | } |
---|
70 | |
---|
71 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
72 | $query.= ';'; |
---|
73 | mysql_query( $query ); |
---|
74 | // make the picture representative of a category ? |
---|
75 | $query = 'SELECT DISTINCT(category_id) as category_id'; |
---|
76 | $query.= ',representative_picture_id'; |
---|
77 | $query.= ' FROM '.PREFIX_TABLE.'image_category AS ic'; |
---|
78 | $query.= ', '.PREFIX_TABLE.'categories AS c'; |
---|
79 | $query.= ' WHERE c.id = ic.category_id'; |
---|
80 | $query.= ' AND image_id = '.$_GET['image_id']; |
---|
81 | $query.= ';'; |
---|
82 | $result = mysql_query( $query ); |
---|
83 | while ( $row = mysql_fetch_array( $result ) ) |
---|
84 | { |
---|
85 | // if the user ask the picture to be the representative picture of its |
---|
86 | // category, the category is updated in the database (without wondering |
---|
87 | // if this picture was already the representative one) |
---|
88 | if ( isset($_POST['representative-'.$row['category_id']]) ) |
---|
89 | { |
---|
90 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
91 | $query.= ' SET representative_picture_id = '.$_GET['image_id']; |
---|
92 | $query.= ' WHERE id = '.$row['category_id']; |
---|
93 | $query.= ';'; |
---|
94 | mysql_query( $query ); |
---|
95 | } |
---|
96 | // if the user ask this picture to be not any more the representative, |
---|
97 | // we have to set the representative_picture_id of this category to NULL |
---|
98 | else if ( isset( $row['representative_picture_id'] ) |
---|
99 | and $row['representative_picture_id'] == $_GET['image_id'] ) |
---|
100 | { |
---|
101 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
102 | $query.= ' SET representative_picture_id = NULL'; |
---|
103 | $query.= ' WHERE id = '.$row['category_id']; |
---|
104 | $query.= ';'; |
---|
105 | mysql_query( $query ); |
---|
106 | } |
---|
107 | } |
---|
108 | $associate_or_dissociate = false; |
---|
109 | // associate with a new category ? |
---|
110 | if ( $_POST['associate'] != '-1' and $_POST['associate'] != '' ) |
---|
111 | { |
---|
112 | // does the uppercat id exists in the database ? |
---|
113 | if ( !is_numeric( $_POST['associate'] ) ) |
---|
114 | { |
---|
115 | array_push( $errors, $lang['cat_unknown_id'] ); |
---|
116 | } |
---|
117 | else |
---|
118 | { |
---|
119 | $query = 'SELECT id'; |
---|
120 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
121 | $query.= ' WHERE id = '.$_POST['associate']; |
---|
122 | $query.= ';'; |
---|
123 | if ( mysql_num_rows( mysql_query( $query ) ) == 0 ) |
---|
124 | array_push( $errors, $lang['cat_unknown_id'] ); |
---|
125 | } |
---|
126 | } |
---|
127 | if ( $_POST['associate'] != '-1' |
---|
128 | and $_POST['associate'] != '' |
---|
129 | and count( $errors ) == 0 ) |
---|
130 | { |
---|
131 | $query = 'INSERT INTO '.PREFIX_TABLE.'image_category'; |
---|
132 | $query.= ' (category_id,image_id) VALUES '; |
---|
133 | $query.= '('.$_POST['associate'].','.$_GET['image_id'].')'; |
---|
134 | $query.= ';'; |
---|
135 | mysql_query( $query); |
---|
136 | $associate_or_dissociate = true; |
---|
137 | update_category( $_POST['associate'] ); |
---|
138 | } |
---|
139 | // dissociate any category ? |
---|
140 | // retrieving all the linked categories |
---|
141 | $query = 'SELECT DISTINCT(category_id) as category_id'; |
---|
142 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
143 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
144 | $query.= ';'; |
---|
145 | $result = mysql_query( $query ); |
---|
146 | while ( $row = mysql_fetch_array( $result ) ) |
---|
147 | { |
---|
148 | if ( isset($_POST['dissociate-'.$row['category_id']]) ) |
---|
149 | { |
---|
150 | $query = 'DELETE FROM '.PREFIX_TABLE.'image_category'; |
---|
151 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
152 | $query.= ' AND category_id = '.$row['category_id']; |
---|
153 | $query.= ';'; |
---|
154 | mysql_query( $query ); |
---|
155 | $associate_or_dissociate = true; |
---|
156 | update_category( $row['category_id'] ); |
---|
157 | } |
---|
158 | } |
---|
159 | if ( $associate_or_dissociate ) |
---|
160 | { |
---|
161 | synchronize_all_users(); |
---|
162 | } |
---|
163 | } |
---|
164 | //----------------------------------------------------- template initialization |
---|
165 | $sub = $vtp->Open( |
---|
166 | '../template/'.$user['template'].'/admin/picture_modify.vtp' ); |
---|
167 | |
---|
168 | $tpl = array( 'submit','errors_title','picmod_update','picmod_back', |
---|
169 | 'default','file','size','filesize','registration_date', |
---|
170 | 'author','creation_date','keywords','comment', 'upload_name', |
---|
171 | 'dissociate','categories','infoimage_associate', |
---|
172 | 'cat_image_info','category_representative' ); |
---|
173 | templatize_array( $tpl, 'lang', $sub ); |
---|
174 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
175 | //-------------------------------------------------------------- errors display |
---|
176 | if ( count( $errors ) != 0 ) |
---|
177 | { |
---|
178 | $vtp->addSession( $sub, 'errors' ); |
---|
179 | foreach ( $errors as $error ) { |
---|
180 | $vtp->addSession( $sub, 'li' ); |
---|
181 | $vtp->setVar( $sub, 'li.content', $error ); |
---|
182 | $vtp->closeSession( $sub, 'li' ); |
---|
183 | } |
---|
184 | $vtp->closeSession( $sub, 'errors' ); |
---|
185 | } |
---|
186 | //-------------------------------------------- displaying informations and form |
---|
187 | $action = './admin.php?'.$_SERVER['QUERY_STRING']; |
---|
188 | $vtp->setVar( $sub, 'form_action', $action ); |
---|
189 | // retrieving direct information about picture |
---|
190 | $infos = array( 'file','date_available','date_creation','tn_ext','name' |
---|
191 | ,'filesize','width','height','author','comment','keywords' |
---|
192 | ,'storage_category_id' ); |
---|
193 | $query = 'SELECT '. implode( ',', $infos ); |
---|
194 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
195 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
196 | $query.= ';'; |
---|
197 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
198 | |
---|
199 | foreach ( $infos as $info ) { |
---|
200 | if ( !isset( $row[$info] ) ) $row[$info] = ''; |
---|
201 | } |
---|
202 | |
---|
203 | // picture title |
---|
204 | if ( $row['name'] == '' ) |
---|
205 | { |
---|
206 | $title = str_replace( '_',' ',get_filename_wo_extension($row['file']) ); |
---|
207 | } |
---|
208 | else |
---|
209 | { |
---|
210 | $title = $row['name']; |
---|
211 | } |
---|
212 | $vtp->setVar( $sub, 'title', $title ); |
---|
213 | $vtp->setVar( $sub, 'f_file', $row['file'] ); |
---|
214 | $vtp->setVar( $sub, 'f_size', $row['width'].' * '.$row['height'] ); |
---|
215 | $vtp->setVar( $sub, 'f_filesize', $row['filesize'].' KB' ); |
---|
216 | $vtp->setVar( $sub, 'f_registration_date',format_date($row['date_available'])); |
---|
217 | $default_name = str_replace( '_',' ',get_filename_wo_extension($row['file']) ); |
---|
218 | $vtp->setVar( $sub, 'default_name', $default_name ); |
---|
219 | // if this form is displayed after an unsucceeded submit, we have to display |
---|
220 | // the values filled by the user (wright or wrong). |
---|
221 | if ( count( $errors ) > 0 ) |
---|
222 | { |
---|
223 | $name = $_POST['name']; |
---|
224 | $author = $_POST['author']; |
---|
225 | $creation_date = $_POST['creation_date']; |
---|
226 | $keywords = $_POST['keywords']; |
---|
227 | $comment = $_POST['comment']; |
---|
228 | } |
---|
229 | else |
---|
230 | { |
---|
231 | $name = $row['name']; |
---|
232 | $author = $row['author']; |
---|
233 | $creation_date = date_convert_back( $row['date_creation'] ); |
---|
234 | $keywords = $row['keywords']; |
---|
235 | $comment = $row['comment']; |
---|
236 | } |
---|
237 | $vtp->setVar( $sub, 'f_name', $name ); |
---|
238 | $vtp->setVar( $sub, 'f_author', $author ); |
---|
239 | $vtp->setVar( $sub, 'f_creation_date', $creation_date ); |
---|
240 | $vtp->setVar( $sub, 'f_keywords', $keywords ); |
---|
241 | $vtp->setVar( $sub, 'f_comment', $comment ); |
---|
242 | // retrieving directory where picture is stored (for displaying the |
---|
243 | // thumbnail) |
---|
244 | $thumbnail_url = get_complete_dir( $row['storage_category_id'] ); |
---|
245 | $result = get_cat_info( $row['storage_category_id'] ); |
---|
246 | $cat_name = get_cat_display_name( $result['name'], ' > ', '' ); |
---|
247 | $vtp->setVar( $sub, 'dir', $cat_name ); |
---|
248 | if ( $result['site_id'] == 1 ) $thumbnail_url = '.'.$thumbnail_url; |
---|
249 | $file_wo_ext = get_filename_wo_extension( $row['file'] ); |
---|
250 | $thumbnail_url.= '/thumbnail/'; |
---|
251 | $thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext']; |
---|
252 | $vtp->setVar( $sub, 'thumbnail_url', $thumbnail_url ); |
---|
253 | // storage category is linked by default |
---|
254 | $vtp->addSession( $sub, 'linked_category' ); |
---|
255 | $vtp->setVar( $sub, 'linked_category.name', $cat_name ); |
---|
256 | $url = '../picture.php?image_id='.$_GET['image_id']; |
---|
257 | $url.= '&cat='.$row['storage_category_id']; |
---|
258 | $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url)); |
---|
259 | $url = './admin.php?page=infos_images&cat_id='.$row['storage_category_id']; |
---|
260 | $vtp->setVar( $sub, 'linked_category.infos_images_link',add_session_id( $url)); |
---|
261 | if ( $result['status'] == 'private' ) |
---|
262 | { |
---|
263 | $private_string = '<span style="color:red;font-weight:bold;">'; |
---|
264 | $private_string.= $lang['private'].'</span>'; |
---|
265 | $vtp->setVar( $sub, 'linked_category.private', $private_string ); |
---|
266 | } |
---|
267 | if ( !$result['visible'] ) |
---|
268 | { |
---|
269 | $invisible_string = '<span style="color:red;">'; |
---|
270 | $invisible_string.= $lang['cat_invisible'].'</span>'; |
---|
271 | $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string ); |
---|
272 | } |
---|
273 | $vtp->setVar( $sub, 'linked_category.id', $row['storage_category_id'] ); |
---|
274 | if ( $result['representative_picture_id'] == $_GET['image_id'] ) |
---|
275 | { |
---|
276 | $vtp->setVar( $sub, 'linked_category.representative_checked', |
---|
277 | ' checked="checked"' ); |
---|
278 | } |
---|
279 | $vtp->closeSession( $sub, 'linked_category' ); |
---|
280 | // retrieving all the linked categories |
---|
281 | $query = 'SELECT DISTINCT(category_id) as category_id,status,visible'; |
---|
282 | $query.= ',representative_picture_id'; |
---|
283 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
284 | $query.= ','.PREFIX_TABLE.'categories'; |
---|
285 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
286 | $query.= ' AND category_id != '.$row['storage_category_id']; |
---|
287 | $query.= ' AND category_id = id'; |
---|
288 | $query.= ';'; |
---|
289 | $result = mysql_query( $query ); |
---|
290 | while ( $row = mysql_fetch_array( $result ) ) |
---|
291 | { |
---|
292 | $vtp->addSession( $sub, 'linked_category' ); |
---|
293 | $vtp->setVar( $sub, 'linked_category.id', $row['category_id'] ); |
---|
294 | |
---|
295 | $vtp->addSession( $sub, 'checkbox' ); |
---|
296 | $vtp->setVar( $sub, 'checkbox.id', $row['category_id'] ); |
---|
297 | $vtp->closeSession( $sub, 'checkbox' ); |
---|
298 | |
---|
299 | $cat_infos = get_cat_info( $row['category_id'] ); |
---|
300 | $cat_name = get_cat_display_name( $cat_infos['name'], ' > ', '' ); |
---|
301 | $vtp->setVar( $sub, 'linked_category.name', $cat_name ); |
---|
302 | |
---|
303 | $url = '../picture.php?image_id='.$_GET['image_id']; |
---|
304 | $url.= '&cat='.$row['category_id']; |
---|
305 | $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url)); |
---|
306 | |
---|
307 | $url = './admin.php?page=infos_images&cat_id='.$row['category_id']; |
---|
308 | $vtp->setVar( $sub, 'linked_category.infos_images_link', |
---|
309 | add_session_id( $url)); |
---|
310 | |
---|
311 | if ( $row['status'] == 'private' ) |
---|
312 | { |
---|
313 | $private_string = '<span style="color:red;font-weight:bold;">'; |
---|
314 | $private_string.= $lang['private'].'</span>'; |
---|
315 | $vtp->setVar( $sub, 'linked_category.private', $private_string ); |
---|
316 | } |
---|
317 | |
---|
318 | if ( !get_boolean( $row['visible'] ) ) |
---|
319 | { |
---|
320 | $invisible_string = '<span style="color:red;">'; |
---|
321 | $invisible_string.= $lang['cat_invisible'].'</span>'; |
---|
322 | $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string ); |
---|
323 | } |
---|
324 | |
---|
325 | if ( isset( $row['representative_picture_id'] ) |
---|
326 | and $row['representative_picture_id'] == $_GET['image_id'] ) |
---|
327 | { |
---|
328 | $vtp->setVar( $sub, 'linked_category.representative_checked', |
---|
329 | ' checked="checked"' ); |
---|
330 | } |
---|
331 | |
---|
332 | $vtp->closeSession( $sub, 'linked_category' ); |
---|
333 | } |
---|
334 | // if there are linked category other than the storage category, we show |
---|
335 | // propose the dissociate text |
---|
336 | if ( mysql_num_rows( $result ) > 0 ) |
---|
337 | { |
---|
338 | $vtp->addSession( $sub, 'dissociate' ); |
---|
339 | $vtp->closeSession( $sub, 'dissociate' ); |
---|
340 | } |
---|
341 | // associate to another category ? |
---|
342 | // |
---|
343 | // We only show a List Of Values if the number of categories is less than |
---|
344 | // $conf['max_LOV_categories'] |
---|
345 | $query = 'SELECT COUNT(id) AS nb_total_categories'; |
---|
346 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
347 | $query.= ';'; |
---|
348 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
349 | if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] ) |
---|
350 | { |
---|
351 | $vtp->addSession( $sub, 'associate_LOV' ); |
---|
352 | $vtp->addSession( $sub, 'associate_cat' ); |
---|
353 | $vtp->setVar( $sub, 'associate_cat.value', '-1' ); |
---|
354 | $vtp->setVar( $sub, 'associate_cat.content', '' ); |
---|
355 | $vtp->closeSession( $sub, 'associate_cat' ); |
---|
356 | $page['plain_structure'] = get_plain_structure( true ); |
---|
357 | $structure = create_structure( '', array() ); |
---|
358 | display_categories( $structure, ' ' ); |
---|
359 | $vtp->closeSession( $sub, 'associate_LOV' ); |
---|
360 | } |
---|
361 | // else, we only display a small text field, we suppose the administrator |
---|
362 | // knows the id of its category |
---|
363 | else |
---|
364 | { |
---|
365 | $vtp->addSession( $sub, 'associate_text' ); |
---|
366 | $vtp->closeSession( $sub, 'associate_text' ); |
---|
367 | } |
---|
368 | //----------------------------------------------------------- sending html code |
---|
369 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
370 | ?> |
---|