1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | picture_modify.php | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | application : PhpWebGallery <http://phpwebgallery.net> | |
---|
6 | // | branch : BSF (Best So Far) | |
---|
7 | // +-----------------------------------------------------------------------+ |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2004-08-31 23:05:19 +0000 (Tue, 31 Aug 2004) $ |
---|
10 | // | last modifier : $Author: gweltas $ |
---|
11 | // | revision : $Revision: 509 $ |
---|
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 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
29 | { |
---|
30 | die ("Hacking attempt!"); |
---|
31 | } |
---|
32 | include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' ); |
---|
33 | |
---|
34 | //--------------------------------------------------------- update informations |
---|
35 | $errors = array(); |
---|
36 | // first, we verify whether there is a mistake on the given creation date |
---|
37 | if ( isset( $_POST['date_creation'] ) and !empty($_POST['date_creation'])) |
---|
38 | { |
---|
39 | if ( !check_date_format( $_POST['date_creation'] ) ) |
---|
40 | array_push( $errors, $lang['err_date'] ); |
---|
41 | } |
---|
42 | if ( isset( $_POST['submit'] ) ) |
---|
43 | { |
---|
44 | $query = 'UPDATE '.IMAGES_TABLE.' SET name = '; |
---|
45 | if ( $_POST['name'] == '' ) |
---|
46 | $query.= 'NULL'; |
---|
47 | else |
---|
48 | $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES )."'"; |
---|
49 | |
---|
50 | $query.= ', author = '; |
---|
51 | if ( $_POST['author'] == '' ) |
---|
52 | $query.= 'NULL'; |
---|
53 | else |
---|
54 | $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'"; |
---|
55 | |
---|
56 | $query.= ', comment = '; |
---|
57 | if ( $_POST['comment'] == '' ) |
---|
58 | $query.= 'NULL'; |
---|
59 | else |
---|
60 | $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'"; |
---|
61 | |
---|
62 | $query.= ', date_creation = '; |
---|
63 | if ( check_date_format( $_POST['date_creation'] ) ) |
---|
64 | $query.= "'".date_convert( $_POST['date_creation'] )."'"; |
---|
65 | else if ( $_POST['date_creation'] == '' ) |
---|
66 | $query.= 'NULL'; |
---|
67 | |
---|
68 | $query.= ', keywords = '; |
---|
69 | $keywords_array = get_keywords( $_POST['keywords'] ); |
---|
70 | if ( count( $keywords_array ) == 0 ) |
---|
71 | $query.= 'NULL'; |
---|
72 | else |
---|
73 | { |
---|
74 | $query.= "'"; |
---|
75 | foreach ( $keywords_array as $i => $keyword ) { |
---|
76 | if ( $i > 0 ) $query.= ','; |
---|
77 | $query.= $keyword; |
---|
78 | } |
---|
79 | $query.= "'"; |
---|
80 | } |
---|
81 | |
---|
82 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
83 | $query.= ';'; |
---|
84 | mysql_query( $query ); |
---|
85 | // make the picture representative of a category ? |
---|
86 | $query = 'SELECT DISTINCT(category_id) as category_id'; |
---|
87 | $query.= ',representative_picture_id'; |
---|
88 | $query.= ' FROM '.IMAGE_CATEGORY_TABLE.' AS ic'; |
---|
89 | $query.= ', '.CATEGORIES_TABLE.' AS c'; |
---|
90 | $query.= ' WHERE c.id = ic.category_id'; |
---|
91 | $query.= ' AND image_id = '.$_GET['image_id']; |
---|
92 | $query.= ';'; |
---|
93 | $result = mysql_query( $query ); |
---|
94 | while ( $row = mysql_fetch_array( $result ) ) |
---|
95 | { |
---|
96 | // if the user ask the picture to be the representative picture of its |
---|
97 | // category, the category is updated in the database (without wondering |
---|
98 | // if this picture was already the representative one) |
---|
99 | if ( isset($_POST['representative-'.$row['category_id']]) ) |
---|
100 | { |
---|
101 | $query = 'UPDATE '.CATEGORIES_TABLE; |
---|
102 | $query.= ' SET representative_picture_id = '.$_GET['image_id']; |
---|
103 | $query.= ' WHERE id = '.$row['category_id']; |
---|
104 | $query.= ';'; |
---|
105 | mysql_query( $query ); |
---|
106 | } |
---|
107 | // if the user ask this picture to be not any more the representative, |
---|
108 | // we have to set the representative_picture_id of this category to NULL |
---|
109 | else if ( isset( $row['representative_picture_id'] ) |
---|
110 | and $row['representative_picture_id'] == $_GET['image_id'] ) |
---|
111 | { |
---|
112 | $query = 'UPDATE '.CATEGORIES_TABLE; |
---|
113 | $query.= ' SET representative_picture_id = NULL'; |
---|
114 | $query.= ' WHERE id = '.$row['category_id']; |
---|
115 | $query.= ';'; |
---|
116 | mysql_query( $query ); |
---|
117 | } |
---|
118 | } |
---|
119 | $associate_or_dissociate = false; |
---|
120 | // associate with a new category ? |
---|
121 | if ( $_POST['associate'] != '-1' and $_POST['associate'] != '' ) |
---|
122 | { |
---|
123 | // does the uppercat id exists in the database ? |
---|
124 | if ( !is_numeric( $_POST['associate'] ) ) |
---|
125 | { |
---|
126 | array_push( $errors, $lang['cat_unknown_id'] ); |
---|
127 | } |
---|
128 | else |
---|
129 | { |
---|
130 | $query = 'SELECT id FROM '.CATEGORIES_TABLE; |
---|
131 | $query.= ' WHERE id = '.$_POST['associate']; |
---|
132 | $query.= ';'; |
---|
133 | if ( mysql_num_rows( mysql_query( $query ) ) == 0 ) |
---|
134 | array_push( $errors, $lang['cat_unknown_id'] ); |
---|
135 | } |
---|
136 | } |
---|
137 | if ( $_POST['associate'] != '-1' |
---|
138 | and $_POST['associate'] != '' |
---|
139 | and count( $errors ) == 0 ) |
---|
140 | { |
---|
141 | $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE; |
---|
142 | $query.= ' (category_id,image_id) VALUES '; |
---|
143 | $query.= '('.$_POST['associate'].','.$_GET['image_id'].')'; |
---|
144 | $query.= ';'; |
---|
145 | mysql_query( $query); |
---|
146 | $associate_or_dissociate = true; |
---|
147 | update_category( $_POST['associate'] ); |
---|
148 | } |
---|
149 | // dissociate any category ? |
---|
150 | // retrieving all the linked categories |
---|
151 | $query = 'SELECT DISTINCT(category_id) as category_id FROM '.IMAGE_CATEGORY_TABLE; |
---|
152 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
153 | $query.= ';'; |
---|
154 | $result = mysql_query( $query ); |
---|
155 | while ( $row = mysql_fetch_array( $result ) ) |
---|
156 | { |
---|
157 | if ( isset($_POST['dissociate-'.$row['category_id']]) ) |
---|
158 | { |
---|
159 | $query = 'DELETE FROM '.IMAGE_CATEGORY_TABLE; |
---|
160 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
161 | $query.= ' AND category_id = '.$row['category_id']; |
---|
162 | $query.= ';'; |
---|
163 | mysql_query( $query ); |
---|
164 | $associate_or_dissociate = true; |
---|
165 | update_category( $row['category_id'] ); |
---|
166 | } |
---|
167 | } |
---|
168 | if ( $associate_or_dissociate ) |
---|
169 | { |
---|
170 | synchronize_all_users(); |
---|
171 | } |
---|
172 | } |
---|
173 | |
---|
174 | // retrieving direct information about picture |
---|
175 | $query = 'SELECT * FROM '.IMAGES_TABLE; |
---|
176 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
177 | $query.= ';'; |
---|
178 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
179 | |
---|
180 | $title = empty($row['name'])?str_replace( '_',' ',get_filename_wo_extension($row['file']) ):$row['name']; |
---|
181 | // Navigation path |
---|
182 | $current_category = get_cat_info($row['storage_category_id']); |
---|
183 | $dir_path = get_cat_display_name($current_category['name'], '->', ''); |
---|
184 | |
---|
185 | $thumbnail_url = get_complete_dir( $row['storage_category_id'] ); |
---|
186 | $file_wo_ext = get_filename_wo_extension( $row['file'] ); |
---|
187 | $thumbnail_url.= '/thumbnail/'; |
---|
188 | $thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext']; |
---|
189 | $url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id']; |
---|
190 | $url_img .= '&cat='.$row['storage_category_id']; |
---|
191 | $date = isset($_POST['date_creation']) && empty($errors) |
---|
192 | ?$_POST['date_creation']:date_convert_back($row['date_creation']); |
---|
193 | |
---|
194 | // retrieving all the linked categories |
---|
195 | $query = 'SELECT DISTINCT(category_id) as category_id,status,visible'; |
---|
196 | $query.= ',representative_picture_id'; |
---|
197 | $query.= ' FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE; |
---|
198 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
199 | $query.= ' AND category_id = id;'; |
---|
200 | $result = mysql_query( $query ); |
---|
201 | $categories = ''; |
---|
202 | while ( $cat_row = mysql_fetch_array( $result ) ) |
---|
203 | { |
---|
204 | $cat_infos = get_cat_info( $cat_row['category_id'] ); |
---|
205 | $cat_name = get_cat_display_name( $cat_infos['name'], ' > ', '' ); |
---|
206 | $categories.='<option value="'.$cat_row['category_id'].'">'.$cat_name.'</option>'; |
---|
207 | } |
---|
208 | |
---|
209 | //----------------------------------------------------- template initialization |
---|
210 | $template->set_filenames( array('picture_modify'=>'admin/picture_modify.tpl') ); |
---|
211 | $template->assign_vars(array( |
---|
212 | 'TITLE_IMG'=>$title, |
---|
213 | 'DIR_IMG'=>$dir_path, |
---|
214 | 'FILE_IMG'=>$row['file'], |
---|
215 | 'TN_URL_IMG'=>$thumbnail_url, |
---|
216 | 'URL_IMG'=>add_session_id( $url_img ), |
---|
217 | 'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:$row['name'], |
---|
218 | 'DEFAULT_NAME_IMG'=>str_replace( '_',' ',get_filename_wo_extension($row['file']) ), |
---|
219 | 'FILE_IMG'=>$row['file'], |
---|
220 | 'SIZE_IMG'=>$row['width'].' * '.$row['height'], |
---|
221 | 'FILESIZE_IMG'=>$row['filesize'].' KB', |
---|
222 | 'REGISTRATION_DATE_IMG'=> format_date($row['date_available']), |
---|
223 | 'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:$row['author'], |
---|
224 | 'CREATION_DATE_IMG'=>$date, |
---|
225 | 'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:$row['keywords'], |
---|
226 | 'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:$row['comment'], |
---|
227 | 'ASSOCIATED_CATEGORIES'=>$categories, |
---|
228 | |
---|
229 | 'L_UPLOAD_NAME'=>$lang['upload_name'], |
---|
230 | 'L_DEFAULT'=>$lang['default'], |
---|
231 | 'L_FILE'=>$lang['file'], |
---|
232 | 'L_SIZE'=>$lang['size'], |
---|
233 | 'L_FILESIZE'=>$lang['filesize'], |
---|
234 | 'L_REGISTRATION_DATE'=>$lang['registration_date'], |
---|
235 | 'L_AUTHOR'=>$lang['author'], |
---|
236 | 'L_CREATION_DATE'=>$lang['creation_date'], |
---|
237 | 'L_KEYWORDS'=>$lang['keywords'], |
---|
238 | 'L_COMMENT'=>$lang['comment'], |
---|
239 | 'L_CATEGORIES'=>$lang['categories'], |
---|
240 | 'L_DISSOCIATE'=>$lang['dissociate'], |
---|
241 | 'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'], |
---|
242 | 'L_SUBMIT'=>$lang['submit'], |
---|
243 | |
---|
244 | 'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING']) |
---|
245 | )); |
---|
246 | |
---|
247 | //-------------------------------------------------------------- errors display |
---|
248 | if ( sizeof( $errors ) != 0 ) |
---|
249 | { |
---|
250 | $template->assign_block_vars('errors',array()); |
---|
251 | for ( $i = 0; $i < sizeof( $errors ); $i++ ) |
---|
252 | { |
---|
253 | $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i])); |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | // if there are linked category other than the storage category, we show |
---|
258 | // propose the dissociate text |
---|
259 | if ( mysql_num_rows( $result ) > 0 ) |
---|
260 | { |
---|
261 | //$vtp->addSession( $sub, 'dissociate' ); |
---|
262 | //$vtp->closeSession( $sub, 'dissociate' ); |
---|
263 | } |
---|
264 | // associate to another category ? |
---|
265 | // |
---|
266 | // We only show a List Of Values if the number of categories is less than |
---|
267 | // $conf['max_LOV_categories'] |
---|
268 | $query = 'SELECT COUNT(id) AS nb_total_categories'; |
---|
269 | $query.= ' FROM '.CATEGORIES_TABLE.';'; |
---|
270 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
271 | if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] ) |
---|
272 | { |
---|
273 | $template->assign_block_vars('associate_LOV',array()); |
---|
274 | $template->assign_block_vars('associate_LOV.associate_cat',array( |
---|
275 | )); |
---|
276 | /*$vtp->addSession( $sub, 'associate_LOV' ); |
---|
277 | $vtp->addSession( $sub, 'associate_cat' ); |
---|
278 | $vtp->setVar( $sub, 'associate_cat.value', '-1' ); |
---|
279 | $vtp->setVar( $sub, 'associate_cat.content', '' ); |
---|
280 | $vtp->closeSession( $sub, 'associate_cat' ); |
---|
281 | $page['plain_structure'] = get_plain_structure( true ); |
---|
282 | $structure = create_structure( '', array() ); |
---|
283 | display_categories( $structure, ' ' ); |
---|
284 | $vtp->closeSession( $sub, 'associate_LOV' );*/ |
---|
285 | } |
---|
286 | |
---|
287 | //----------------------------------------------------------- sending html code |
---|
288 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
289 | ?> |
---|