1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * infos_images.php * |
---|
4 | * ------------------ * |
---|
5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
7 | * * |
---|
8 | * $Id: infos_images.php 138 2003-09-20 08:00:38Z 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 | include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' ); |
---|
22 | //-------------------------------------------------------------- initialization |
---|
23 | check_cat_id( $_GET['cat_id'] ); |
---|
24 | if ( isset( $page['cat'] ) ) |
---|
25 | { |
---|
26 | //--------------------------------------------------- update individual options |
---|
27 | $query = 'SELECT id,file'; |
---|
28 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
29 | $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
30 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
31 | $query.= ';'; |
---|
32 | $result = mysql_query( $query ); |
---|
33 | $i = 1; |
---|
34 | while ( $row = mysql_fetch_array( $result ) ) |
---|
35 | { |
---|
36 | $name = 'name-'.$row['id']; |
---|
37 | $author = 'author-'.$row['id']; |
---|
38 | $comment = 'comment-'.$row['id']; |
---|
39 | $date_creation = 'date_creation-'.$row['id']; |
---|
40 | $keywords = 'keywords-'.$row['id']; |
---|
41 | if ( isset( $_POST[$name] ) ) |
---|
42 | { |
---|
43 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
44 | |
---|
45 | $query.= ' SET name = '; |
---|
46 | if ( $_POST[$name] == '' ) |
---|
47 | $query.= 'NULL'; |
---|
48 | else |
---|
49 | $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'"; |
---|
50 | |
---|
51 | $query.= ', author = '; |
---|
52 | if ( $_POST[$author] == '' ) |
---|
53 | $query.= 'NULL'; |
---|
54 | else |
---|
55 | $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'"; |
---|
56 | |
---|
57 | $query.= ', comment = '; |
---|
58 | if ( $_POST[$comment] == '' ) |
---|
59 | $query.= 'NULL'; |
---|
60 | else |
---|
61 | $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'"; |
---|
62 | |
---|
63 | $query.= ', date_creation = '; |
---|
64 | if ( check_date_format( $_POST[$date_creation] ) ) |
---|
65 | $query.= "'".date_convert( $_POST[$date_creation] )."'"; |
---|
66 | else if ( $_POST[$date_creation] == '' ) |
---|
67 | $query.= 'NULL'; |
---|
68 | |
---|
69 | $query.= ', keywords = '; |
---|
70 | $keywords_array = get_keywords( $_POST[$keywords] ); |
---|
71 | if ( count( $keywords_array ) == 0 ) |
---|
72 | $query.= 'NULL'; |
---|
73 | else |
---|
74 | { |
---|
75 | $query.= "'"; |
---|
76 | foreach ( $keywords_array as $i => $keyword ) { |
---|
77 | if ( $i > 0 ) $query.= ','; |
---|
78 | $query.= $keyword; |
---|
79 | } |
---|
80 | $query.= "'"; |
---|
81 | } |
---|
82 | |
---|
83 | $query.= ' WHERE id = '.$row['id']; |
---|
84 | $query.= ';'; |
---|
85 | mysql_query( $query ); |
---|
86 | } |
---|
87 | // add link to another category |
---|
88 | if ( $_POST['check-'.$row['id']] == 1 ) |
---|
89 | { |
---|
90 | $query = 'INSERT INTO '.PREFIX_TABLE.'image_category'; |
---|
91 | $query.= ' (image_id,category_id) VALUES'; |
---|
92 | $query.= ' ('.$row['id'].','.$_POST['associate'].')'; |
---|
93 | $query.= ';'; |
---|
94 | mysql_query( $query ); |
---|
95 | } |
---|
96 | } |
---|
97 | update_category( $_POST['associate'] ); |
---|
98 | //------------------------------------------------------ update general options |
---|
99 | if ( $_POST['use_common_author'] == 1 ) |
---|
100 | { |
---|
101 | $query = 'SELECT image_id'; |
---|
102 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
103 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
104 | $result = mysql_query( $query ); |
---|
105 | while ( $row = mysql_fetch_array( $result ) ) |
---|
106 | { |
---|
107 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
108 | if ( $_POST['author_cat'] == '' ) |
---|
109 | { |
---|
110 | $query.= ' SET author = NULL'; |
---|
111 | } |
---|
112 | else |
---|
113 | { |
---|
114 | $query.= ' SET author = '; |
---|
115 | $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'"; |
---|
116 | } |
---|
117 | $query.= ' WHERE id = '.$row['image_id']; |
---|
118 | $query.= ';'; |
---|
119 | mysql_query( $query ); |
---|
120 | } |
---|
121 | } |
---|
122 | if ( $_POST['use_common_date_creation'] == 1 ) |
---|
123 | { |
---|
124 | if ( check_date_format( $_POST['date_creation_cat'] ) ) |
---|
125 | { |
---|
126 | $date = date_convert( $_POST['date_creation_cat'] ); |
---|
127 | $query = 'SELECT image_id'; |
---|
128 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
129 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
130 | $result = mysql_query( $query ); |
---|
131 | while ( $row = mysql_fetch_array( $result ) ) |
---|
132 | { |
---|
133 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
134 | if ( $_POST['date_creation_cat'] == '' ) |
---|
135 | { |
---|
136 | $query.= ' SET date_creation = NULL'; |
---|
137 | } |
---|
138 | else |
---|
139 | { |
---|
140 | $query.= " SET date_creation = '".$date."'"; |
---|
141 | } |
---|
142 | $query.= ' WHERE id = '.$row['image_id']; |
---|
143 | $query.= ';'; |
---|
144 | mysql_query( $query ); |
---|
145 | } |
---|
146 | } |
---|
147 | else |
---|
148 | { |
---|
149 | echo $lang['err_date']; |
---|
150 | } |
---|
151 | } |
---|
152 | if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' ) |
---|
153 | { |
---|
154 | $query = 'SELECT id,keywords'; |
---|
155 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
156 | $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
157 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
158 | $query.= ';'; |
---|
159 | $result = mysql_query( $query ); |
---|
160 | while ( $row = mysql_fetch_array( $result ) ) |
---|
161 | { |
---|
162 | $specific_keywords = explode( ',', $row['keywords'] ); |
---|
163 | $common_keywords = get_keywords( $_POST['keywords_cat'] ); |
---|
164 | // first possiblity : adding the given keywords to all the pictures |
---|
165 | if ( $_POST['common_keywords'] == 'add' ) |
---|
166 | { |
---|
167 | $keywords = array_merge( $specific_keywords, $common_keywords ); |
---|
168 | $keywords = array_unique( $keywords ); |
---|
169 | } |
---|
170 | // second possiblity : removing the given keywords from all pictures |
---|
171 | // (without deleting the other specific keywords |
---|
172 | if ( $_POST['common_keywords'] == 'remove' ) |
---|
173 | { |
---|
174 | $keywords = array_diff( $specific_keywords, $common_keywords ); |
---|
175 | } |
---|
176 | // cleaning the keywords array, sometimes, an empty value still remain |
---|
177 | $keywords = array_remove( $keywords, '' ); |
---|
178 | // updating the picture with new keywords array |
---|
179 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
180 | $query.= ' SET keywords = '; |
---|
181 | if ( count( $keywords ) == 0 ) |
---|
182 | { |
---|
183 | $query.= 'NULL'; |
---|
184 | } |
---|
185 | else |
---|
186 | { |
---|
187 | $query.= '"'; |
---|
188 | $i = 0; |
---|
189 | foreach ( $keywords as $keyword ) { |
---|
190 | if ( $i++ > 0 ) $query.= ','; |
---|
191 | $query.= $keyword; |
---|
192 | } |
---|
193 | $query.= '"'; |
---|
194 | } |
---|
195 | $query.= ' WHERE id = '.$row['id']; |
---|
196 | $query.= ';'; |
---|
197 | mysql_query( $query ); |
---|
198 | } |
---|
199 | } |
---|
200 | //--------------------------------------------------------- form initialization |
---|
201 | $page['nb_image_page'] = 5; |
---|
202 | |
---|
203 | if( !isset( $_GET['start'] ) |
---|
204 | or !is_numeric( $_GET['start'] ) |
---|
205 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
206 | { |
---|
207 | $page['start'] = 0; |
---|
208 | } |
---|
209 | else |
---|
210 | { |
---|
211 | $page['start'] = $_GET['start']; |
---|
212 | } |
---|
213 | |
---|
214 | if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 ) |
---|
215 | { |
---|
216 | $page['start'] = |
---|
217 | floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page']; |
---|
218 | } |
---|
219 | // retrieving category information |
---|
220 | $page['plain_structure'] = get_plain_structure(); |
---|
221 | $result = get_cat_info( $page['cat'] ); |
---|
222 | $cat['name'] = $result['name']; |
---|
223 | $cat['nb_images'] = $result['nb_images']; |
---|
224 | //----------------------------------------------------- template initialization |
---|
225 | $sub = $vtp->Open('../template/'.$user['template'].'/admin/infos_image.vtp'); |
---|
226 | $tpl = array( 'infoimage_general','author','infoimage_useforall','submit', |
---|
227 | 'infoimage_creation_date','infoimage_detailed','thumbnail', |
---|
228 | 'infoimage_title','infoimage_comment', |
---|
229 | 'infoimage_creation_date','keywords', |
---|
230 | 'infoimage_addtoall','infoimage_removefromall', |
---|
231 | 'infoimage_keyword_separation','infoimage_associate' ); |
---|
232 | templatize_array( $tpl, 'lang', $sub ); |
---|
233 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
234 | //------------------------------------------------------------------------ form |
---|
235 | $url = './admin.php?page=infos_images&cat_id='.$page['cat']; |
---|
236 | $url.= '&start='.$page['start']; |
---|
237 | $vtp->setVar( $sub, 'form_action', add_session_id( $url ) ); |
---|
238 | $page['navigation_bar'] = create_navigation_bar( |
---|
239 | $url, $cat['nb_images'],$page['start'], $page['nb_image_page'], '' ); |
---|
240 | $vtp->setVar( $sub, 'navigation_bar', $page['navigation_bar'] ); |
---|
241 | $cat_name = get_cat_display_name( $cat['name'], ' - ', 'font-style:italic;'); |
---|
242 | $vtp->setVar( $sub, 'cat_name', $cat_name ); |
---|
243 | |
---|
244 | $array_cat_directories = array(); |
---|
245 | |
---|
246 | $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation,keywords'; |
---|
247 | $query.= ',storage_category_id,category_id'; |
---|
248 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
249 | $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
250 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
251 | $query.= $conf['order_by']; |
---|
252 | $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page']; |
---|
253 | $query.= ';'; |
---|
254 | $result = mysql_query( $query ); |
---|
255 | while ( $row = mysql_fetch_array( $result ) ) |
---|
256 | { |
---|
257 | $vtp->addSession( $sub, 'picture' ); |
---|
258 | $vtp->setVar( $sub, 'picture.id', $row['id'] ); |
---|
259 | $vtp->setVar( $sub, 'picture.filename', $row['file'] ); |
---|
260 | $vtp->setVar( $sub, 'picture.name', $row['name'] ); |
---|
261 | $vtp->setVar( $sub, 'picture.author', $row['author'] ); |
---|
262 | $vtp->setVar( $sub, 'picture.comment', $row['comment'] ); |
---|
263 | $vtp->setVar( $sub, 'picture.keywords', $row['keywords'] ); |
---|
264 | $vtp->setVar( $sub, 'picture.date_creation', |
---|
265 | date_convert_back( $row['date_creation'] ) ); |
---|
266 | $file = get_filename_wo_extension( $row['file'] ); |
---|
267 | $vtp->setVar( $sub, 'picture.default_name', $file ); |
---|
268 | // creating url to thumbnail |
---|
269 | if ( $array_cat_directories[$row['storage_category_id']] == '' ) |
---|
270 | { |
---|
271 | $array_cat_directories[$row['storage_category_id']] = |
---|
272 | get_complete_dir( $row['storage_category_id'] ); |
---|
273 | } |
---|
274 | $thumbnail_url = $array_cat_directories[$row['storage_category_id']]; |
---|
275 | if ( preg_match( '/^\.\/galleries/', $thumbnail_url ) ) |
---|
276 | { |
---|
277 | $thumbnail_url = '.'.$thumbnail_url; |
---|
278 | } |
---|
279 | $thumbnail_url.= 'thumbnail/'; |
---|
280 | $thumbnail_url.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; |
---|
281 | $vtp->setVar( $sub, 'picture.thumbnail_url', $thumbnail_url ); |
---|
282 | $url = './admin.php?page=picture_modify&image_id='.$row['id']; |
---|
283 | $vtp->setVar( $sub, 'picture.url', add_session_id( $url ) ); |
---|
284 | $vtp->closeSession( $sub, 'picture' ); |
---|
285 | } |
---|
286 | $structure = create_structure( '', array() ); |
---|
287 | display_categories( $structure, ' ' ); |
---|
288 | } |
---|
289 | //----------------------------------------------------------- sending html code |
---|
290 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
291 | ?> |
---|