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 61 2003-08-30 15:54:37Z 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 | //----------------------------------------- categories structure initialization |
---|
22 | $page['plain_structure'] = get_plain_structure(); |
---|
23 | //--------------------------------------------------------- update informations |
---|
24 | $errors = array(); |
---|
25 | // first, we verify whether there is a mistake on the given creation date |
---|
26 | if ( isset( $_POST['creation_date'] ) and $_POST['creation_date'] != '' ) |
---|
27 | { |
---|
28 | if ( !check_date_format( $_POST['creation_date'] ) ) |
---|
29 | array_push( $errors, $lang['err_date'] ); |
---|
30 | } |
---|
31 | if ( isset( $_POST['submit'] ) ) |
---|
32 | { |
---|
33 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
34 | |
---|
35 | $query.= ' SET name = '; |
---|
36 | if ( $_POST['name'] == '' ) |
---|
37 | $query.= 'NULL'; |
---|
38 | else |
---|
39 | $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES )."'"; |
---|
40 | |
---|
41 | $query.= ', author = '; |
---|
42 | if ( $_POST['author'] == '' ) |
---|
43 | $query.= 'NULL'; |
---|
44 | else |
---|
45 | $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'"; |
---|
46 | |
---|
47 | $query.= ', comment = '; |
---|
48 | if ( $_POST['comment'] == '' ) |
---|
49 | $query.= 'NULL'; |
---|
50 | else |
---|
51 | $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'"; |
---|
52 | |
---|
53 | $query.= ', date_creation = '; |
---|
54 | if ( check_date_format( $_POST['creation_date'] ) ) |
---|
55 | $query.= "'".date_convert( $_POST['creation_date'] )."'"; |
---|
56 | else if ( $_POST['creation_date'] == '' ) |
---|
57 | $query.= 'NULL'; |
---|
58 | |
---|
59 | $query.= ', keywords = '; |
---|
60 | $keywords_array = get_keywords( $_POST['keywords'] ); |
---|
61 | if ( count( $keywords_array ) == 0 ) |
---|
62 | $query.= 'NULL'; |
---|
63 | else |
---|
64 | { |
---|
65 | $query.= "'"; |
---|
66 | foreach ( $keywords_array as $i => $keyword ) { |
---|
67 | if ( $i > 0 ) $query.= ','; |
---|
68 | $query.= $keyword; |
---|
69 | } |
---|
70 | $query.= "'"; |
---|
71 | } |
---|
72 | |
---|
73 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
74 | $query.= ';'; |
---|
75 | mysql_query( $query ); |
---|
76 | // associate with a new category ? |
---|
77 | if ( $_POST['associate'] != '-1' ) |
---|
78 | { |
---|
79 | $query = 'INSERT INTO '.PREFIX_TABLE.'image_category'; |
---|
80 | $query.= ' (category_id,image_id) VALUES '; |
---|
81 | $query.= '('.$_POST['associate'].','.$_GET['image_id'].')'; |
---|
82 | $query.= ';'; |
---|
83 | mysql_query( $query); |
---|
84 | update_category( $_POST['associate'] ); |
---|
85 | } |
---|
86 | // dissociate any category ? |
---|
87 | // retrieving all the linked categories |
---|
88 | $query = 'SELECT DISTINCT(category_id) as category_id'; |
---|
89 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
90 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
91 | $query.= ';'; |
---|
92 | $result = mysql_query( $query ); |
---|
93 | while ( $row = mysql_fetch_array( $result ) ) |
---|
94 | { |
---|
95 | if ( $_POST['dissociate-'.$row['category_id']] == 1 ) |
---|
96 | { |
---|
97 | $query = 'DELETE FROM '.PREFIX_TABLE.'image_category'; |
---|
98 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
99 | $query.= ' AND category_id = '.$row['category_id']; |
---|
100 | $query.= ';'; |
---|
101 | mysql_query( $query ); |
---|
102 | update_category( $row['category_id'] ); |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|
106 | //----------------------------------------------------- template initialization |
---|
107 | $sub = $vtp->Open( |
---|
108 | '../template/'.$user['template'].'/admin/picture_modify.vtp' ); |
---|
109 | |
---|
110 | $tpl = array( 'submit','errors_title','picmod_update','picmod_back', |
---|
111 | 'default','file','size','filesize','registration_date', |
---|
112 | 'author','creation_date','keywords','comment', 'upload_name', |
---|
113 | 'dissociate','categories','infoimage_associate', |
---|
114 | 'cat_image_info' ); |
---|
115 | templatize_array( $tpl, 'lang', $sub ); |
---|
116 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
117 | //-------------------------------------------------------------- errors display |
---|
118 | if ( count( $errors ) != 0 ) |
---|
119 | { |
---|
120 | $vtp->addSession( $sub, 'errors' ); |
---|
121 | foreach ( $errors as $error ) { |
---|
122 | $vtp->addSession( $sub, 'li' ); |
---|
123 | $vtp->setVar( $sub, 'li.content', $error ); |
---|
124 | $vtp->closeSession( $sub, 'li' ); |
---|
125 | } |
---|
126 | $vtp->closeSession( $sub, 'errors' ); |
---|
127 | } |
---|
128 | //-------------------------------------------- displaying informations and form |
---|
129 | $action = './admin.php?'.$_SERVER['QUERY_STRING']; |
---|
130 | $vtp->setVar( $sub, 'form_action', $action ); |
---|
131 | // retrieving direct information about picture |
---|
132 | $query = 'SELECT file,date_available,date_creation,tn_ext,name,filesize'; |
---|
133 | $query.= ',width,height,author,comment,keywords,storage_category_id'; |
---|
134 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
135 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
136 | $query.= ';'; |
---|
137 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
138 | // picture title |
---|
139 | if ( $row['name'] == '' ) |
---|
140 | { |
---|
141 | $title = str_replace( '_',' ',get_filename_wo_extension($row['file']) ); |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | $title = $row['name']; |
---|
146 | } |
---|
147 | $vtp->setVar( $sub, 'title', $title ); |
---|
148 | $vtp->setVar( $sub, 'f_file', $row['file'] ); |
---|
149 | $vtp->setVar( $sub, 'f_size', $row['width'].' * '.$row['height'] ); |
---|
150 | $vtp->setVar( $sub, 'f_filesize', $row['filesize'].' KB' ); |
---|
151 | $vtp->setVar( $sub, 'f_registration_date',format_date($row['date_available'])); |
---|
152 | $default_name = str_replace( '_',' ',get_filename_wo_extension($row['file']) ); |
---|
153 | $vtp->setVar( $sub, 'default_name', $default_name ); |
---|
154 | // if this form is displayed after an unsucceeded submit, we have to display |
---|
155 | // the values filled by the user (wright or wrong). |
---|
156 | if ( count( $errors ) > 0 ) |
---|
157 | { |
---|
158 | $name = $_POST['name']; |
---|
159 | $author = $_POST['author']; |
---|
160 | $creation_date = $_POST['creation_date']; |
---|
161 | $keywords = $_POST['keywords']; |
---|
162 | $comment = $_POST['comment']; |
---|
163 | } |
---|
164 | else |
---|
165 | { |
---|
166 | $name = $row['name']; |
---|
167 | $author = $row['author']; |
---|
168 | $creation_date = date_convert_back( $row['date_creation'] ); |
---|
169 | $keywords = $row['keywords']; |
---|
170 | $comment = $row['comment']; |
---|
171 | } |
---|
172 | $vtp->setVar( $sub, 'f_name', $name ); |
---|
173 | $vtp->setVar( $sub, 'f_author', $author ); |
---|
174 | $vtp->setVar( $sub, 'f_creation_date', $creation_date ); |
---|
175 | $vtp->setVar( $sub, 'f_keywords', $keywords ); |
---|
176 | $vtp->setVar( $sub, 'f_comment', $comment ); |
---|
177 | // retrieving directory where picture is stored (for displaying the |
---|
178 | // thumbnail) |
---|
179 | $thumbnail_url = get_complete_dir( $row['storage_category_id'] ); |
---|
180 | $result = get_cat_info( $row['storage_category_id'] ); |
---|
181 | $cat_name = get_cat_display_name( $result['name'], ' > ', '' ); |
---|
182 | $vtp->setVar( $sub, 'dir', $cat_name ); |
---|
183 | if ( $result['site_id'] == 1 ) $thumbnail_url = '.'.$thumbnail_url; |
---|
184 | $file_wo_ext = get_filename_wo_extension( $row['file'] ); |
---|
185 | $thumbnail_url.= '/thumbnail/'; |
---|
186 | $thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext']; |
---|
187 | $vtp->setVar( $sub, 'thumbnail_url', $thumbnail_url ); |
---|
188 | // storage category is linked by default |
---|
189 | $vtp->addSession( $sub, 'linked_category' ); |
---|
190 | $vtp->setVar( $sub, 'linked_category.name', $cat_name ); |
---|
191 | $url = '../picture.php?image_id='.$_GET['image_id']; |
---|
192 | $url.= '&cat='.$row['storage_category_id']; |
---|
193 | $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url)); |
---|
194 | $url = './admin.php?page=infos_images&cat_id='.$row['storage_category_id']; |
---|
195 | $vtp->setVar( $sub, 'linked_category.infos_images_link',add_session_id( $url)); |
---|
196 | if ( $result['status'] == 'private' ) |
---|
197 | { |
---|
198 | $private_string = '<span style="color:red;font-weight:bold;">'; |
---|
199 | $private_string.= $lang['private'].'</span>'; |
---|
200 | $vtp->setVar( $sub, 'linked_category.private', $private_string ); |
---|
201 | } |
---|
202 | if ( !$result['visible'] ) |
---|
203 | { |
---|
204 | $invisible_string = '<span style="color:red;">'; |
---|
205 | $invisible_string.= $lang['cat_invisible'].'</span>'; |
---|
206 | $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string ); |
---|
207 | } |
---|
208 | $vtp->closeSession( $sub, 'linked_category' ); |
---|
209 | // retrieving all the linked categories |
---|
210 | $query = 'SELECT DISTINCT(category_id) as category_id,status,visible'; |
---|
211 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
212 | $query.= ','.PREFIX_TABLE.'categories'; |
---|
213 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
214 | $query.= ' AND category_id != '.$row['storage_category_id']; |
---|
215 | $query.= ' AND category_id = id'; |
---|
216 | $query.= ';'; |
---|
217 | $result = mysql_query( $query ); |
---|
218 | while ( $row = mysql_fetch_array( $result ) ) |
---|
219 | { |
---|
220 | $vtp->addSession( $sub, 'linked_category' ); |
---|
221 | |
---|
222 | $vtp->addSession( $sub, 'checkbox' ); |
---|
223 | $vtp->setVar( $sub, 'checkbox.id', $row['category_id'] ); |
---|
224 | $vtp->closeSession( $sub, 'checkbox' ); |
---|
225 | |
---|
226 | $cat_infos = get_cat_info( $row['category_id'] ); |
---|
227 | $cat_name = get_cat_display_name( $cat_infos['name'], ' > ', '' ); |
---|
228 | $vtp->setVar( $sub, 'linked_category.name', $cat_name ); |
---|
229 | |
---|
230 | $url = '../picture.php?image_id='.$_GET['image_id']; |
---|
231 | $url.= '&cat='.$row['category_id']; |
---|
232 | $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url)); |
---|
233 | |
---|
234 | $url = './admin.php?page=infos_images&cat_id='.$row['category_id']; |
---|
235 | $vtp->setVar( $sub, 'linked_category.infos_images_link', |
---|
236 | add_session_id( $url)); |
---|
237 | |
---|
238 | if ( $row['status'] == 'private' ) |
---|
239 | { |
---|
240 | $private_string = '<span style="color:red;font-weight:bold;">'; |
---|
241 | $private_string.= $lang['private'].'</span>'; |
---|
242 | $vtp->setVar( $sub, 'linked_category.private', $private_string ); |
---|
243 | } |
---|
244 | |
---|
245 | if ( !get_boolean( $row['visible'] ) ) |
---|
246 | { |
---|
247 | $invisible_string = '<span style="color:red;">'; |
---|
248 | $invisible_string.= $lang['cat_invisible'].'</span>'; |
---|
249 | $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string ); |
---|
250 | } |
---|
251 | |
---|
252 | $vtp->closeSession( $sub, 'linked_category' ); |
---|
253 | } |
---|
254 | // if there are linked category other than the storage category, we show |
---|
255 | // propose the dissociate text |
---|
256 | if ( mysql_num_rows( $result ) > 0 ) |
---|
257 | { |
---|
258 | $vtp->addSession( $sub, 'dissociate' ); |
---|
259 | $vtp->closeSession( $sub, 'dissociate' ); |
---|
260 | } |
---|
261 | // associate to another category ? |
---|
262 | $vtp->addSession( $sub, 'associate_cat' ); |
---|
263 | $vtp->setVar( $sub, 'associate_cat.value', '-1' ); |
---|
264 | $vtp->setVar( $sub, 'associate_cat.content', '' ); |
---|
265 | $vtp->closeSession( $sub, 'associate_cat' ); |
---|
266 | $structure = create_structure( '', array() ); |
---|
267 | display_categories( $structure, ' ' ); |
---|
268 | //----------------------------------------------------------- sending html code |
---|
269 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
270 | ?> |
---|