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-10-30 15:42:29 +0000 (Sat, 30 Oct 2004) $ |
---|
10 | // | last modifier : $Author: z0rglub $ |
---|
11 | // | revision : $Revision: 587 $ |
---|
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 | //--------------------------------------------------------- update informations |
---|
34 | $errors = array(); |
---|
35 | // first, we verify whether there is a mistake on the given creation date |
---|
36 | if (isset($_POST['date_creation']) and !empty($_POST['date_creation'])) |
---|
37 | { |
---|
38 | if (!check_date_format($_POST['date_creation'])) |
---|
39 | { |
---|
40 | array_push($errors, $lang['err_date']); |
---|
41 | } |
---|
42 | } |
---|
43 | if (isset($_POST['submit'])) |
---|
44 | { |
---|
45 | $query = 'UPDATE '.IMAGES_TABLE.' 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 = '.$_GET['image_id']; |
---|
84 | $query.= ';'; |
---|
85 | pwg_query($query); |
---|
86 | // make the picture representative of a category ? |
---|
87 | $query = ' |
---|
88 | SELECT DISTINCT(category_id) as category_id,representative_picture_id |
---|
89 | FROM '.IMAGE_CATEGORY_TABLE.' AS ic, '.CATEGORIES_TABLE.' AS c |
---|
90 | WHERE c.id = ic.category_id |
---|
91 | AND image_id = '.$_GET['image_id'].' |
---|
92 | ;'; |
---|
93 | $result = pwg_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 | pwg_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 = ' |
---|
113 | UPDATE '.CATEGORIES_TABLE.' |
---|
114 | SET representative_picture_id = NULL |
---|
115 | WHERE id = '.$row['category_id'].' |
---|
116 | ;'; |
---|
117 | pwg_query($query); |
---|
118 | } |
---|
119 | } |
---|
120 | $associate_or_dissociate = false; |
---|
121 | // associate with a new category ? |
---|
122 | if ($_POST['associate'] != '-1' and $_POST['associate'] != '') |
---|
123 | { |
---|
124 | // does the uppercat id exists in the database ? |
---|
125 | if (!is_numeric($_POST['associate'])) |
---|
126 | { |
---|
127 | array_push($errors, $lang['cat_unknown_id']); |
---|
128 | } |
---|
129 | else |
---|
130 | { |
---|
131 | $query = ' |
---|
132 | SELECT id |
---|
133 | FROM '.CATEGORIES_TABLE.' |
---|
134 | WHERE id = '.$_POST['associate'].' |
---|
135 | ;'; |
---|
136 | if (mysql_num_rows(pwg_query($query)) == 0) |
---|
137 | array_push($errors, $lang['cat_unknown_id']); |
---|
138 | } |
---|
139 | } |
---|
140 | if ($_POST['associate'] != '-1' |
---|
141 | and $_POST['associate'] != '' |
---|
142 | and count($errors) == 0) |
---|
143 | { |
---|
144 | $query = ' |
---|
145 | INSERT INTO '.IMAGE_CATEGORY_TABLE.' |
---|
146 | (category_id,image_id) |
---|
147 | VALUES |
---|
148 | ('.$_POST['associate'].','.$_GET['image_id'].') |
---|
149 | ;'; |
---|
150 | pwg_query($query); |
---|
151 | $associate_or_dissociate = true; |
---|
152 | update_category($_POST['associate']); |
---|
153 | } |
---|
154 | // dissociate any category ? |
---|
155 | // retrieving all the linked categories |
---|
156 | $query = ' |
---|
157 | SELECT DISTINCT(category_id) as category_id |
---|
158 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
159 | WHERE image_id = '.$_GET['image_id'].' |
---|
160 | ;'; |
---|
161 | $result = pwg_query($query); |
---|
162 | while ($row = mysql_fetch_array($result)) |
---|
163 | { |
---|
164 | if (isset($_POST['dissociate-'.$row['category_id']])) |
---|
165 | { |
---|
166 | $query = ' |
---|
167 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
168 | WHERE image_id = '.$_GET['image_id'].' |
---|
169 | AND category_id = '.$row['category_id'].' |
---|
170 | ;'; |
---|
171 | pwg_query($query); |
---|
172 | $associate_or_dissociate = true; |
---|
173 | update_category($row['category_id']); |
---|
174 | } |
---|
175 | } |
---|
176 | if ($associate_or_dissociate) |
---|
177 | { |
---|
178 | synchronize_all_users(); |
---|
179 | } |
---|
180 | } |
---|
181 | |
---|
182 | // retrieving direct information about picture |
---|
183 | $query = ' |
---|
184 | SELECT * |
---|
185 | FROM '.IMAGES_TABLE.' |
---|
186 | WHERE id = '.$_GET['image_id'].' |
---|
187 | ;'; |
---|
188 | $row = mysql_fetch_array(pwg_query($query)); |
---|
189 | |
---|
190 | if (empty($row['name'])) |
---|
191 | { |
---|
192 | $title = str_replace('_', ' ',get_filename_wo_extension($row['file'])); |
---|
193 | } |
---|
194 | else |
---|
195 | { |
---|
196 | $title = $row['name']; |
---|
197 | } |
---|
198 | // Navigation path |
---|
199 | $current_category = get_cat_info($row['storage_category_id']); |
---|
200 | $dir_path = get_cat_display_name($current_category['name'], '->', ''); |
---|
201 | |
---|
202 | $thumbnail_url = get_thumbnail_src($row['file'], |
---|
203 | $row['storage_category_id'], |
---|
204 | @$row['tn_ext']); |
---|
205 | |
---|
206 | $url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id']; |
---|
207 | $url_img .= '&cat='.$row['storage_category_id']; |
---|
208 | $date = isset($_POST['date_creation']) && empty($errors) |
---|
209 | ?$_POST['date_creation']:date_convert_back(@$row['date_creation']); |
---|
210 | |
---|
211 | // retrieving all the linked categories |
---|
212 | $query = ' |
---|
213 | SELECT DISTINCT(category_id) AS category_id,status,visible |
---|
214 | ,representative_picture_id |
---|
215 | FROM '.IMAGE_CATEGORY_TABLE.','.CATEGORIES_TABLE.' |
---|
216 | WHERE image_id = '.$_GET['image_id'].' |
---|
217 | AND category_id = id |
---|
218 | ;'; |
---|
219 | $result = pwg_query($query); |
---|
220 | $categories = ''; |
---|
221 | while ($cat_row = mysql_fetch_array($result)) |
---|
222 | { |
---|
223 | $cat_infos = get_cat_info($cat_row['category_id']); |
---|
224 | $cat_name = get_cat_display_name($cat_infos['name'], ' > ', ''); |
---|
225 | $categories.='<option value="'.$cat_row['category_id'].'">'.$cat_name.'</option>'; |
---|
226 | } |
---|
227 | |
---|
228 | //----------------------------------------------------- template initialization |
---|
229 | $template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl')); |
---|
230 | $template->assign_vars(array( |
---|
231 | 'TITLE_IMG'=>$title, |
---|
232 | 'DIR_IMG'=>$dir_path, |
---|
233 | 'FILE_IMG'=>$row['file'], |
---|
234 | 'TN_URL_IMG'=>$thumbnail_url, |
---|
235 | 'URL_IMG'=>add_session_id($url_img), |
---|
236 | 'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])), |
---|
237 | 'FILE_IMG'=>$row['file'], |
---|
238 | 'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'], |
---|
239 | 'SIZE_IMG'=>@$row['width'].' * '.@$row['height'], |
---|
240 | 'FILESIZE_IMG'=>@$row['filesize'].' KB', |
---|
241 | 'REGISTRATION_DATE_IMG'=> format_date($row['date_available']), |
---|
242 | 'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'], |
---|
243 | 'CREATION_DATE_IMG'=>$date, |
---|
244 | 'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'], |
---|
245 | 'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'], |
---|
246 | 'ASSOCIATED_CATEGORIES'=>$categories, |
---|
247 | |
---|
248 | 'L_UPLOAD_NAME'=>$lang['upload_name'], |
---|
249 | 'L_DEFAULT'=>$lang['default'], |
---|
250 | 'L_FILE'=>$lang['file'], |
---|
251 | 'L_SIZE'=>$lang['size'], |
---|
252 | 'L_FILESIZE'=>$lang['filesize'], |
---|
253 | 'L_REGISTRATION_DATE'=>$lang['registration_date'], |
---|
254 | 'L_AUTHOR'=>$lang['author'], |
---|
255 | 'L_CREATION_DATE'=>$lang['creation_date'], |
---|
256 | 'L_KEYWORDS'=>$lang['keywords'], |
---|
257 | 'L_COMMENT'=>$lang['comment'], |
---|
258 | 'L_CATEGORIES'=>$lang['categories'], |
---|
259 | 'L_DISSOCIATE'=>$lang['dissociate'], |
---|
260 | 'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'], |
---|
261 | 'L_SUBMIT'=>$lang['submit'], |
---|
262 | |
---|
263 | 'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING']) |
---|
264 | )); |
---|
265 | |
---|
266 | //-------------------------------------------------------------- errors display |
---|
267 | if (sizeof($errors) != 0) |
---|
268 | { |
---|
269 | $template->assign_block_vars('errors',array()); |
---|
270 | for ($i = 0; $i < sizeof($errors); $i++) |
---|
271 | { |
---|
272 | $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i])); |
---|
273 | } |
---|
274 | } |
---|
275 | |
---|
276 | // if there are linked category other than the storage category, we show |
---|
277 | // propose the dissociate text |
---|
278 | if (mysql_num_rows($result) > 0) |
---|
279 | { |
---|
280 | //$vtp->addSession($sub, 'dissociate'); |
---|
281 | //$vtp->closeSession($sub, 'dissociate'); |
---|
282 | } |
---|
283 | // associate to another category ? |
---|
284 | // |
---|
285 | // We only show a List Of Values if the number of categories is less than |
---|
286 | // $conf['max_LOV_categories'] |
---|
287 | $query = 'SELECT COUNT(id) AS nb_total_categories'; |
---|
288 | $query.= ' FROM '.CATEGORIES_TABLE.';'; |
---|
289 | $row = mysql_fetch_array(pwg_query($query)); |
---|
290 | if ($row['nb_total_categories'] < $conf['max_LOV_categories']) |
---|
291 | { |
---|
292 | $template->assign_block_vars('associate_LOV',array()); |
---|
293 | $template->assign_block_vars('associate_LOV.associate_cat',array( |
---|
294 | )); |
---|
295 | /*$vtp->addSession($sub, 'associate_LOV'); |
---|
296 | $vtp->addSession($sub, 'associate_cat'); |
---|
297 | $vtp->setVar($sub, 'associate_cat.value', '-1'); |
---|
298 | $vtp->setVar($sub, 'associate_cat.content', ''); |
---|
299 | $vtp->closeSession($sub, 'associate_cat'); |
---|
300 | $page['plain_structure'] = get_plain_structure(true); |
---|
301 | $structure = create_structure('', array()); |
---|
302 | display_categories($structure, ' '); |
---|
303 | $vtp->closeSession($sub, 'associate_LOV');*/ |
---|
304 | } |
---|
305 | |
---|
306 | //----------------------------------------------------------- sending html code |
---|
307 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
308 | ?> |
---|