1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | branch : BSF (Best So Far) |
---|
8 | // | file : $RCSfile$ |
---|
9 | // | last update : $Date: 2006-01-15 13:49:29 +0000 (Sun, 15 Jan 2006) $ |
---|
10 | // | last modifier : $Author: nikrou $ |
---|
11 | // | revision : $Revision: 1005 $ |
---|
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 | //---------------------------------------------------------------- verification |
---|
34 | if ( !isset( $_GET['cat_id'] ) || !is_numeric( $_GET['cat_id'] ) ) |
---|
35 | { |
---|
36 | $_GET['cat_id'] = '-1'; |
---|
37 | } |
---|
38 | |
---|
39 | $template->set_filenames( array('categories'=>'admin/cat_modify.tpl') ); |
---|
40 | |
---|
41 | //--------------------------------------------------------- form criteria check |
---|
42 | if (isset($_POST['submit'])) |
---|
43 | { |
---|
44 | $data = |
---|
45 | array( |
---|
46 | 'id' => $_GET['cat_id'], |
---|
47 | 'name' => @$_POST['name'], |
---|
48 | 'commentable' => $_POST['commentable'], |
---|
49 | 'uploadable' => |
---|
50 | isset($_POST['uploadable']) ? $_POST['uploadable'] : 'false', |
---|
51 | 'comment' => |
---|
52 | $conf['allow_html_descriptions'] ? |
---|
53 | @$_POST['comment'] : strip_tags(@$_POST['comment']) |
---|
54 | ); |
---|
55 | |
---|
56 | mass_updates( |
---|
57 | CATEGORIES_TABLE, |
---|
58 | array( |
---|
59 | 'primary' => array('id'), |
---|
60 | 'update' => array_diff(array_keys($data), array('id')) |
---|
61 | ), |
---|
62 | array($data) |
---|
63 | ); |
---|
64 | |
---|
65 | set_cat_visible(array($_GET['cat_id']), $_POST['visible']); |
---|
66 | set_cat_status(array($_GET['cat_id']), $_POST['status']); |
---|
67 | |
---|
68 | if (isset($_POST['parent'])) |
---|
69 | { |
---|
70 | move_categories( |
---|
71 | array($_GET['cat_id']), |
---|
72 | $_POST['parent'] |
---|
73 | ); |
---|
74 | } |
---|
75 | |
---|
76 | array_push($page['infos'], $lang['editcat_confirm']); |
---|
77 | } |
---|
78 | else if (isset($_POST['set_random_representant'])) |
---|
79 | { |
---|
80 | set_random_representant(array($_GET['cat_id'])); |
---|
81 | } |
---|
82 | else if (isset($_POST['delete_representant'])) |
---|
83 | { |
---|
84 | $query = ' |
---|
85 | UPDATE '.CATEGORIES_TABLE.' |
---|
86 | SET representative_picture_id = NULL |
---|
87 | WHERE id = '.$_GET['cat_id'].' |
---|
88 | ;'; |
---|
89 | pwg_query($query); |
---|
90 | } |
---|
91 | |
---|
92 | $query = ' |
---|
93 | SELECT * |
---|
94 | FROM '.CATEGORIES_TABLE.' |
---|
95 | WHERE id = '.$_GET['cat_id'].' |
---|
96 | ;'; |
---|
97 | $category = mysql_fetch_array( pwg_query( $query ) ); |
---|
98 | // nullable fields |
---|
99 | foreach (array('comment','dir','site_id', 'id_uppercat') as $nullable) |
---|
100 | { |
---|
101 | if (!isset($category[$nullable])) |
---|
102 | { |
---|
103 | $category[$nullable] = ''; |
---|
104 | } |
---|
105 | } |
---|
106 | |
---|
107 | $category['is_virtual'] = empty($category['dir']) ? true : false; |
---|
108 | |
---|
109 | // Navigation path |
---|
110 | $url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='; |
---|
111 | |
---|
112 | $navigation = get_cat_display_name_cache( |
---|
113 | $category['uppercats'], |
---|
114 | PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id=' |
---|
115 | ); |
---|
116 | |
---|
117 | $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='.$_GET['cat_id']; |
---|
118 | $status = ($category['status']=='public')?'STATUS_PUBLIC':'STATUS_PRIVATE'; |
---|
119 | $lock = ($category['visible']=='true')?'UNLOCKED':'LOCKED'; |
---|
120 | |
---|
121 | if ($category['commentable'] == 'true') |
---|
122 | { |
---|
123 | $commentable = 'COMMENTABLE_TRUE'; |
---|
124 | } |
---|
125 | else |
---|
126 | { |
---|
127 | $commentable = 'COMMENTABLE_FALSE'; |
---|
128 | } |
---|
129 | if ($category['uploadable'] == 'true') |
---|
130 | { |
---|
131 | $uploadable = 'UPLOADABLE_TRUE'; |
---|
132 | } |
---|
133 | else |
---|
134 | { |
---|
135 | $uploadable = 'UPLOADABLE_FALSE'; |
---|
136 | } |
---|
137 | |
---|
138 | //----------------------------------------------------- template initialization |
---|
139 | |
---|
140 | $base_url = PHPWG_ROOT_PATH.'admin.php?page='; |
---|
141 | $cat_list_url = $base_url.'cat_list'; |
---|
142 | |
---|
143 | $self_url = $cat_list_url; |
---|
144 | if (!empty($category['id_uppercat'])) |
---|
145 | { |
---|
146 | $self_url.= '&parent_id='.$category['id_uppercat']; |
---|
147 | } |
---|
148 | |
---|
149 | $template->assign_vars(array( |
---|
150 | 'CATEGORIES_NAV'=>$navigation, |
---|
151 | 'CAT_NAME'=>$category['name'], |
---|
152 | 'CAT_COMMENT'=>$category['comment'], |
---|
153 | |
---|
154 | $status=>'checked="checked"', |
---|
155 | $lock=>'checked="checked"', |
---|
156 | $commentable=>'checked="checked"', |
---|
157 | $uploadable=>'checked="checked"', |
---|
158 | |
---|
159 | 'L_EDIT_NAME'=>$lang['name'], |
---|
160 | 'L_STORAGE'=>$lang['storage'], |
---|
161 | 'L_REMOTE_SITE'=>$lang['remote_site'], |
---|
162 | 'L_EDIT_COMMENT'=>$lang['description'], |
---|
163 | 'L_EDIT_STATUS'=>$lang['conf_access'], |
---|
164 | 'L_STATUS_PUBLIC'=>$lang['public'], |
---|
165 | 'L_STATUS_PRIVATE'=>$lang['private'], |
---|
166 | 'L_EDIT_LOCK'=>$lang['lock'], |
---|
167 | 'L_EDIT_UPLOADABLE'=>$lang['editcat_uploadable'], |
---|
168 | 'L_EDIT_COMMENTABLE'=>$lang['comments'], |
---|
169 | 'L_YES'=>$lang['yes'], |
---|
170 | 'L_NO'=>$lang['no'], |
---|
171 | 'L_SUBMIT'=>$lang['submit'], |
---|
172 | 'L_SET_RANDOM_REPRESENTANT'=>$lang['cat_representant'], |
---|
173 | |
---|
174 | 'U_JUMPTO'=> |
---|
175 | add_session_id(PHPWG_ROOT_PATH.'category.php?cat='.$category['id']), |
---|
176 | 'U_CHILDREN'=> |
---|
177 | add_session_id($cat_list_url.'&parent_id='.$category['id']), |
---|
178 | 'U_HELP' => PHPWG_ROOT_PATH.'/popuphelp.php?page=cat_modify', |
---|
179 | |
---|
180 | 'F_ACTION'=>add_session_id($form_action) |
---|
181 | )); |
---|
182 | |
---|
183 | |
---|
184 | if ('private' == $category['status']) |
---|
185 | { |
---|
186 | $template->assign_block_vars( |
---|
187 | 'permissions', |
---|
188 | array( |
---|
189 | 'URL'=>add_session_id($base_url.'cat_perm&cat='.$category['id']) |
---|
190 | ) |
---|
191 | ); |
---|
192 | } |
---|
193 | |
---|
194 | // manage category elements link |
---|
195 | if ($category['nb_images'] > 0) |
---|
196 | { |
---|
197 | $template->assign_block_vars( |
---|
198 | 'elements', |
---|
199 | array( |
---|
200 | 'URL'=>add_session_id($base_url.'element_set&cat='.$category['id']) |
---|
201 | ) |
---|
202 | ); |
---|
203 | } |
---|
204 | |
---|
205 | // representant management |
---|
206 | if ($category['nb_images'] > 0 |
---|
207 | or !empty($category['representative_picture_id'])) |
---|
208 | { |
---|
209 | $template->assign_block_vars('representant', array()); |
---|
210 | |
---|
211 | // picture to display : the identified representant or the generic random |
---|
212 | // representant ? |
---|
213 | if (!empty($category['representative_picture_id'])) |
---|
214 | { |
---|
215 | $query = ' |
---|
216 | SELECT tn_ext,path |
---|
217 | FROM '.IMAGES_TABLE.' |
---|
218 | WHERE id = '.$category['representative_picture_id'].' |
---|
219 | ;'; |
---|
220 | $row = mysql_fetch_array(pwg_query($query)); |
---|
221 | $src = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
222 | $url = PHPWG_ROOT_PATH.'admin.php?page=picture_modify'; |
---|
223 | $url.= '&image_id='.$category['representative_picture_id']; |
---|
224 | |
---|
225 | $template->assign_block_vars( |
---|
226 | 'representant.picture', |
---|
227 | array( |
---|
228 | 'SRC' => $src, |
---|
229 | 'URL' => $url |
---|
230 | ) |
---|
231 | ); |
---|
232 | } |
---|
233 | else // $category['nb_images'] > 0 |
---|
234 | { |
---|
235 | $template->assign_block_vars('representant.random', array()); |
---|
236 | } |
---|
237 | |
---|
238 | // can the admin choose to set a new random representant ? |
---|
239 | if ($category['nb_images'] > 0) |
---|
240 | { |
---|
241 | $template->assign_block_vars('representant.set_random', array()); |
---|
242 | } |
---|
243 | |
---|
244 | // can the admin delete the current representant ? |
---|
245 | if ( |
---|
246 | ($category['nb_images'] > 0 |
---|
247 | and $conf['allow_random_representative']) |
---|
248 | or |
---|
249 | ($category['nb_images'] == 0 |
---|
250 | and !empty($category['representative_picture_id']))) |
---|
251 | { |
---|
252 | $template->assign_block_vars('representant.delete_representant', array()); |
---|
253 | } |
---|
254 | } |
---|
255 | |
---|
256 | if (!$category['is_virtual']) //!empty($category['dir'])) |
---|
257 | { |
---|
258 | $template->assign_block_vars( |
---|
259 | 'storage', |
---|
260 | array('CATEGORY_DIR'=>preg_replace('/\/$/', |
---|
261 | '', |
---|
262 | get_complete_dir($category['id'])))); |
---|
263 | $template->assign_block_vars('upload' ,array()); |
---|
264 | } |
---|
265 | else |
---|
266 | { |
---|
267 | $template->assign_block_vars( |
---|
268 | 'delete', |
---|
269 | array( |
---|
270 | 'URL'=>add_session_id($self_url.'&delete='.$category['id']) |
---|
271 | ) |
---|
272 | ); |
---|
273 | |
---|
274 | $template->assign_block_vars('move', array()); |
---|
275 | |
---|
276 | // the category can be moved in any category but in itself, in any |
---|
277 | // sub-category |
---|
278 | $unmovables = get_subcat_ids(array($category['id'])); |
---|
279 | |
---|
280 | $blockname = 'move.parent_option'; |
---|
281 | |
---|
282 | $template->assign_block_vars( |
---|
283 | $blockname, |
---|
284 | array( |
---|
285 | 'SELECTED' |
---|
286 | => empty($category['id_uppercat']) ? 'selected="selected"' : '', |
---|
287 | 'VALUE'=> 0, |
---|
288 | 'OPTION' => '------------' |
---|
289 | ) |
---|
290 | ); |
---|
291 | |
---|
292 | $query = ' |
---|
293 | SELECT id,name,uppercats,global_rank |
---|
294 | FROM '.CATEGORIES_TABLE.' |
---|
295 | WHERE id NOT IN ('.implode(',', $unmovables).') |
---|
296 | ;'; |
---|
297 | |
---|
298 | display_select_cat_wrapper( |
---|
299 | $query, |
---|
300 | empty($category['id_uppercat']) ? array() : array($category['id_uppercat']), |
---|
301 | $blockname |
---|
302 | ); |
---|
303 | } |
---|
304 | |
---|
305 | if (is_numeric($category['site_id']) and $category['site_id'] != 1) |
---|
306 | { |
---|
307 | $query = ' |
---|
308 | SELECT galleries_url |
---|
309 | FROM '.SITES_TABLE.' |
---|
310 | WHERE id = '.$category['site_id'].' |
---|
311 | ;'; |
---|
312 | list($galleries_url) = mysql_fetch_array(pwg_query($query)); |
---|
313 | $template->assign_block_vars('server', array('SITE_URL' => $galleries_url)); |
---|
314 | } |
---|
315 | |
---|
316 | //----------------------------------------------------------- sending html code |
---|
317 | $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); |
---|
318 | ?> |
---|