1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * cat_list.php * |
---|
4 | * ------------------- * |
---|
5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
6 | * website : http://www.phpwebgallery.net * |
---|
7 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
8 | * * |
---|
9 | * $Id: cat_list.php 68 2003-09-07 10:14:33Z z0rglub $ |
---|
10 | * * |
---|
11 | ***************************************************************************/ |
---|
12 | |
---|
13 | /*************************************************************************** |
---|
14 | * * |
---|
15 | * This program is free software; you can redistribute it and/or modify * |
---|
16 | * it under the terms of the GNU General Public License as published by * |
---|
17 | * the Free Software Foundation; * |
---|
18 | * * |
---|
19 | ***************************************************************************/ |
---|
20 | include_once( './include/isadmin.inc.php' ); |
---|
21 | //----------------------------------------------------- template initialization |
---|
22 | $sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_list.vtp' ); |
---|
23 | $tpl = array( 'cat_edit','cat_up','cat_down','cat_image_info', |
---|
24 | 'cat_permission','cat_update','cat_add','cat_parent','submit', |
---|
25 | 'cat_virtual','delete','cat_first','cat_last' ); |
---|
26 | templatize_array( $tpl, 'lang', $sub ); |
---|
27 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
28 | //--------------------------------------------------- adding a virtual category |
---|
29 | $errors = array(); |
---|
30 | if ( isset( $_POST['submit'] ) ) |
---|
31 | { |
---|
32 | if ( !preg_match( '/^\s*$/', $_POST['virtual_name'] ) ) |
---|
33 | { |
---|
34 | // we have then to add the virtual category |
---|
35 | $query = 'INSERT INTO '.PREFIX_TABLE.'categories'; |
---|
36 | $query.= ' (name,id_uppercat) VALUES '; |
---|
37 | if ( $_POST['associate'] == -1 ) |
---|
38 | { |
---|
39 | $_POST['associate'] = 'NULL'; |
---|
40 | } |
---|
41 | $query.= " ('".$_POST['virtual_name']."',".$_POST['associate'].")"; |
---|
42 | $query.= ';'; |
---|
43 | echo $query; |
---|
44 | mysql_query( $query ); |
---|
45 | } |
---|
46 | else |
---|
47 | { |
---|
48 | array_push( $errors, $lang['cat_error_name'] ); |
---|
49 | } |
---|
50 | } |
---|
51 | //--------------------------------------------------------------- rank updates |
---|
52 | if ( isset( $_GET['up'] ) and is_numeric( $_GET['up'] ) ) |
---|
53 | { |
---|
54 | // 1. searching level (id_uppercat) |
---|
55 | // and rank of the category to move |
---|
56 | $query = 'SELECT id_uppercat,rank'; |
---|
57 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
58 | $query.= ' WHERE id = '.$_GET['up']; |
---|
59 | $query.= ';'; |
---|
60 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
61 | $level = $row['id_uppercat']; |
---|
62 | $rank = $row['rank']; |
---|
63 | // 2. searching the id and the rank of the category |
---|
64 | // just above at the same level |
---|
65 | $query = 'SELECT id,rank'; |
---|
66 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
67 | $query.= ' WHERE rank < '.$rank; |
---|
68 | if ( $level == '' ) |
---|
69 | { |
---|
70 | $query.= ' AND id_uppercat IS NULL'; |
---|
71 | } |
---|
72 | else |
---|
73 | { |
---|
74 | $query.= ' AND id_uppercat = '.$level; |
---|
75 | } |
---|
76 | $query.= ' ORDER BY rank DESC'; |
---|
77 | $query.= ' LIMIT 0,1'; |
---|
78 | $query.= ';'; |
---|
79 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
80 | $new_rank = $row['rank']; |
---|
81 | $replaced_cat = $row['id']; |
---|
82 | // 3. exchanging ranks between the two categories |
---|
83 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
84 | $query.= ' SET rank = '.$new_rank; |
---|
85 | $query.= ' WHERE id = '.$_GET['up']; |
---|
86 | $query.= ';'; |
---|
87 | mysql_query( $query ); |
---|
88 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
89 | $query.= ' SET rank = '.$rank; |
---|
90 | $query.= ' WHERE id = '.$replaced_cat; |
---|
91 | $query.= ';'; |
---|
92 | mysql_query( $query ); |
---|
93 | } |
---|
94 | if ( isset( $_GET['down'] ) and is_numeric( $_GET['down'] ) ) |
---|
95 | { |
---|
96 | // 1. searching level (id_uppercat) |
---|
97 | // and rank of the category to move |
---|
98 | $query = 'SELECT id_uppercat,rank'; |
---|
99 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
100 | $query.= ' WHERE id = '.$_GET['down']; |
---|
101 | $query.= ';'; |
---|
102 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
103 | $level = $row['id_uppercat']; |
---|
104 | $rank = $row['rank']; |
---|
105 | // 2. searching the id and the rank of the category |
---|
106 | // just below at the same level |
---|
107 | $query = 'SELECT id,rank'; |
---|
108 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
109 | $query.= ' WHERE rank > '.$rank; |
---|
110 | if ( $level == '' ) |
---|
111 | { |
---|
112 | $query.= ' AND id_uppercat IS NULL'; |
---|
113 | } |
---|
114 | else |
---|
115 | { |
---|
116 | $query.= ' AND id_uppercat = '.$level; |
---|
117 | } |
---|
118 | $query.= ' ORDER BY rank ASC'; |
---|
119 | $query.= ' LIMIT 0,1'; |
---|
120 | $query.= ';'; |
---|
121 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
122 | $new_rank = $row['rank']; |
---|
123 | $replaced_cat = $row['id']; |
---|
124 | // 3. exchanging ranks between the two categories |
---|
125 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
126 | $query.= ' SET rank = '.$new_rank; |
---|
127 | $query.= ' WHERE id = '.$_GET['down']; |
---|
128 | $query.= ';'; |
---|
129 | mysql_query( $query ); |
---|
130 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
131 | $query.= ' SET rank = '.$rank; |
---|
132 | $query.= ' WHERE id = '.$replaced_cat; |
---|
133 | $query.= ';'; |
---|
134 | mysql_query( $query ); |
---|
135 | } |
---|
136 | if ( isset( $_GET['last'] ) and is_numeric( $_GET['last'] ) ) |
---|
137 | { |
---|
138 | // 1. searching level (id_uppercat) of the category to move |
---|
139 | $query = 'SELECT id_uppercat,rank'; |
---|
140 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
141 | $query.= ' WHERE id = '.$_GET['last']; |
---|
142 | $query.= ';'; |
---|
143 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
144 | $level = $row['id_uppercat']; |
---|
145 | // 2. searching the highest rank of the categories of the same parent |
---|
146 | $query = 'SELECT MAX(rank) AS max_rank'; |
---|
147 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
148 | $query.= ' WHERE id_uppercat'; |
---|
149 | if ( $level == '' ) $query.= ' IS NULL'; |
---|
150 | else $query.= ' = '.$level; |
---|
151 | $query.= ';'; |
---|
152 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
153 | $max_rank = $row['max_rank']; |
---|
154 | // 3. updating the rank of our category to be after the previous max rank |
---|
155 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
156 | $query.= ' SET rank = '.($max_rank + 1); |
---|
157 | $query.= ' WHERE id = '.$_GET['last']; |
---|
158 | $query.= ';'; |
---|
159 | mysql_query( $query ); |
---|
160 | } |
---|
161 | if ( isset( $_GET['first'] ) and is_numeric( $_GET['first'] ) ) |
---|
162 | { |
---|
163 | // to place our category as first, we simply say that is rank is 0, then |
---|
164 | // reordering will move category ranks correctly (first rank should be 1 |
---|
165 | // and not 0) |
---|
166 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
167 | $query.= ' SET rank = 0'; |
---|
168 | $query.= ' WHERE id = '.$_GET['first']; |
---|
169 | $query.= ';'; |
---|
170 | mysql_query( $query ); |
---|
171 | } |
---|
172 | if ( isset( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) ) |
---|
173 | { |
---|
174 | delete_category( $_GET['delete'] ); |
---|
175 | } |
---|
176 | //------------------------------------------------------------------ reordering |
---|
177 | function ordering( $id_uppercat ) |
---|
178 | { |
---|
179 | $rank = 1; |
---|
180 | |
---|
181 | $query = 'SELECT id'; |
---|
182 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
183 | if ( !is_numeric( $id_uppercat ) ) |
---|
184 | { |
---|
185 | $query.= ' WHERE id_uppercat IS NULL'; |
---|
186 | } |
---|
187 | else |
---|
188 | { |
---|
189 | $query.= ' WHERE id_uppercat = '.$id_uppercat; |
---|
190 | } |
---|
191 | $query.= ' ORDER BY rank ASC, dir ASC'; |
---|
192 | $query.= ';'; |
---|
193 | $result = mysql_query( $query ); |
---|
194 | while ( $row = mysql_fetch_array( $result ) ) |
---|
195 | { |
---|
196 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
197 | $query.= ' SET rank = '.$rank; |
---|
198 | $query.= ' WHERE id = '.$row['id']; |
---|
199 | $query.= ';'; |
---|
200 | mysql_query( $query ); |
---|
201 | $rank++; |
---|
202 | ordering( $row['id'] ); |
---|
203 | } |
---|
204 | } |
---|
205 | ordering( 'NULL' ); |
---|
206 | //-------------------------------------------------------------- errors display |
---|
207 | if ( count( $errors ) != 0 ) |
---|
208 | { |
---|
209 | $vtp->addSession( $sub, 'errors' ); |
---|
210 | foreach ( $errors as $error ) { |
---|
211 | $vtp->addSession( $sub, 'li' ); |
---|
212 | $vtp->setVar( $sub, 'li.content', $error ); |
---|
213 | $vtp->closeSession( $sub, 'li' ); |
---|
214 | } |
---|
215 | $vtp->closeSession( $sub, 'errors' ); |
---|
216 | } |
---|
217 | //---------------------------------------------------------------- page display |
---|
218 | function display_cat_manager( $id_uppercat, $indent, |
---|
219 | $uppercat_visible, $level ) |
---|
220 | { |
---|
221 | global $lang,$conf,$sub,$vtp,$page; |
---|
222 | |
---|
223 | // searching the min_rank and the max_rank of the category |
---|
224 | $query = 'SELECT MIN(rank) AS min, MAX(rank) AS max'; |
---|
225 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
226 | if ( !is_numeric( $id_uppercat ) ) |
---|
227 | { |
---|
228 | $query.= ' WHERE id_uppercat IS NULL'; |
---|
229 | } |
---|
230 | else |
---|
231 | { |
---|
232 | $query.= ' WHERE id_uppercat = '.$id_uppercat; |
---|
233 | } |
---|
234 | $query.= ';'; |
---|
235 | $result = mysql_query( $query ); |
---|
236 | $row = mysql_fetch_array( $result ); |
---|
237 | $min_rank = $row['min']; |
---|
238 | $max_rank = $row['max']; |
---|
239 | |
---|
240 | // will we use <th> or <td> lines ? |
---|
241 | $td = 'td'; |
---|
242 | $class = ''; |
---|
243 | if ( $level > 0 ) $class = 'row'.$level; |
---|
244 | else $td = 'th'; |
---|
245 | |
---|
246 | $query = 'SELECT id,name,dir,nb_images,status,rank,site_id,visible'; |
---|
247 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
248 | if ( !is_numeric( $id_uppercat ) ) |
---|
249 | { |
---|
250 | $query.= ' WHERE id_uppercat IS NULL'; |
---|
251 | } |
---|
252 | else |
---|
253 | { |
---|
254 | $query.= ' WHERE id_uppercat = '.$id_uppercat; |
---|
255 | } |
---|
256 | $query.= ' ORDER BY rank ASC'; |
---|
257 | $query.= ';'; |
---|
258 | $result = mysql_query( $query ); |
---|
259 | while ( $row = mysql_fetch_array( $result ) ) |
---|
260 | { |
---|
261 | $subcat_visible = true; |
---|
262 | |
---|
263 | $vtp->addSession( $sub, 'cat' ); |
---|
264 | $vtp->setVar( $sub, 'cat.td', $td ); |
---|
265 | $vtp->setVar( $sub, 'cat.class', $class ); |
---|
266 | $vtp->setVar( $sub, 'cat.indent', $indent ); |
---|
267 | $vtp->setVar( $sub, 'cat.name', $row['name'] ); |
---|
268 | if ( $row['dir'] != '' ) |
---|
269 | { |
---|
270 | $vtp->addSession( $sub, 'storage' ); |
---|
271 | $vtp->setVar( $sub, 'storage.dir', $row['dir'] ); |
---|
272 | $vtp->closeSession( $sub, 'storage' ); |
---|
273 | // category can't be deleted |
---|
274 | $vtp->addSession( $sub, 'no_delete' ); |
---|
275 | $vtp->closeSession( $sub, 'no_delete' ); |
---|
276 | } |
---|
277 | else |
---|
278 | { |
---|
279 | $vtp->addSession( $sub, 'virtual' ); |
---|
280 | $vtp->closeSession( $sub, 'virtual' ); |
---|
281 | // category can be deleted |
---|
282 | $vtp->addSession( $sub, 'delete' ); |
---|
283 | $url = './admin.php?page=cat_list&delete='.$row['id']; |
---|
284 | $vtp->setVar( $sub, 'delete.delete_url', add_session_id( $url ) ); |
---|
285 | $vtp->closeSession( $sub, 'delete' ); |
---|
286 | } |
---|
287 | if ( $row['visible'] == 'false' or !$uppercat_visible ) |
---|
288 | { |
---|
289 | $subcat_visible = false; |
---|
290 | $vtp->setVar( $sub, 'cat.invisible', $lang['cat_invisible'] ); |
---|
291 | } |
---|
292 | if ( $row['status'] == 'private' ) |
---|
293 | { |
---|
294 | $vtp->setVar( $sub, 'cat.private', $lang['private'] ); |
---|
295 | } |
---|
296 | $vtp->setVar( $sub, 'cat.nb_picture', $row['nb_images'] ); |
---|
297 | $url = add_session_id( './admin.php?page=cat_modify&cat='.$row['id'] ); |
---|
298 | $vtp->setVar( $sub, 'cat.edit_url', $url ); |
---|
299 | if ( $row['rank'] != $min_rank ) |
---|
300 | { |
---|
301 | $vtp->addSession( $sub, 'up' ); |
---|
302 | $url = add_session_id( './admin.php?page=cat_list&up='.$row['id'] ); |
---|
303 | $vtp->setVar( $sub, 'up.up_url', $url ); |
---|
304 | $vtp->closeSession( $sub, 'up' ); |
---|
305 | } |
---|
306 | else if ( $min_rank != $max_rank ) |
---|
307 | { |
---|
308 | $vtp->addSession( $sub, 'no_up' ); |
---|
309 | $url = add_session_id( './admin.php?page=cat_list&last='.$row['id']); |
---|
310 | $vtp->setVar( $sub, 'no_up.last_url', $url ); |
---|
311 | $vtp->closeSession( $sub, 'no_up' ); |
---|
312 | } |
---|
313 | if ( $row['rank'] != $max_rank ) |
---|
314 | { |
---|
315 | $vtp->addSession( $sub, 'down' ); |
---|
316 | $url = add_session_id( './admin.php?page=cat_list&down='.$row['id']); |
---|
317 | $vtp->setVar( $sub, 'down.down_url', $url ); |
---|
318 | $vtp->closeSession( $sub, 'down' ); |
---|
319 | } |
---|
320 | else if ( $min_rank != $max_rank ) |
---|
321 | { |
---|
322 | $vtp->addSession( $sub, 'no_down' ); |
---|
323 | $url = add_session_id('./admin.php?page=cat_list&first='.$row['id']); |
---|
324 | $vtp->setVar( $sub, 'no_down.first_url', $url ); |
---|
325 | $vtp->closeSession( $sub, 'no_down' ); |
---|
326 | } |
---|
327 | if ( $row['nb_images'] > 0 ) |
---|
328 | { |
---|
329 | $vtp->addSession( $sub, 'image_info' ); |
---|
330 | $url = add_session_id( './admin.php?page=infos_images&cat_id=' |
---|
331 | .$row['id'] ); |
---|
332 | $vtp->setVar( $sub, 'image_info.image_info_url', $url ); |
---|
333 | $vtp->closeSession( $sub, 'image_info' ); |
---|
334 | } |
---|
335 | else |
---|
336 | { |
---|
337 | $vtp->addSession( $sub, 'no_image_info' ); |
---|
338 | $vtp->closeSession( $sub, 'no_image_info' ); |
---|
339 | } |
---|
340 | if ( $row['status'] == 'private' ) |
---|
341 | { |
---|
342 | $vtp->addSession( $sub, 'permission' ); |
---|
343 | $url=add_session_id('./admin.php?page=cat_perm&cat_id='.$row['id']); |
---|
344 | $vtp->setVar( $sub, 'permission.url', $url ); |
---|
345 | $vtp->closeSession( $sub, 'permission' ); |
---|
346 | } |
---|
347 | else |
---|
348 | { |
---|
349 | $vtp->addSession( $sub, 'no_permission' ); |
---|
350 | $vtp->closeSession( $sub, 'no_permission' ); |
---|
351 | } |
---|
352 | // you can individually update a category only if it is on the main site |
---|
353 | // and if it's not a virtual category (a category is virtual if there is |
---|
354 | // no directory associated) |
---|
355 | if ( $row['site_id'] == 1 and $row['dir'] != '' ) |
---|
356 | { |
---|
357 | $vtp->addSession( $sub, 'update' ); |
---|
358 | $url = add_session_id('./admin.php?page=update&update='.$row['id']); |
---|
359 | $vtp->setVar( $sub, 'update.update_url', $url ); |
---|
360 | $vtp->closeSession( $sub, 'update' ); |
---|
361 | } |
---|
362 | else |
---|
363 | { |
---|
364 | $vtp->addSession( $sub, 'no_update' ); |
---|
365 | $vtp->closeSession( $sub, 'no_update' ); |
---|
366 | } |
---|
367 | |
---|
368 | $vtp->closeSession( $sub, 'cat' ); |
---|
369 | |
---|
370 | display_cat_manager( $row['id'], $indent.str_repeat( ' ', 4 ), |
---|
371 | $subcat_visible, $level + 1 ); |
---|
372 | } |
---|
373 | } |
---|
374 | display_cat_manager( 'NULL', str_repeat( ' ', 4 ), true, 0 ); |
---|
375 | // add a virtual category ? |
---|
376 | $vtp->addSession( $sub, 'associate_cat' ); |
---|
377 | $vtp->setVar( $sub, 'associate_cat.value', '-1' ); |
---|
378 | $vtp->setVar( $sub, 'associate_cat.content', '' ); |
---|
379 | $vtp->closeSession( $sub, 'associate_cat' ); |
---|
380 | $page['plain_structure'] = get_plain_structure(); |
---|
381 | $structure = create_structure( '', array() ); |
---|
382 | display_categories( $structure, ' ' ); |
---|
383 | //----------------------------------------------------------- sending html code |
---|
384 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
385 | ?> |
---|