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 198 2003-10-12 14:30:46Z 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 | mysql_query( $query ); |
---|
44 | } |
---|
45 | else |
---|
46 | { |
---|
47 | array_push( $errors, $lang['cat_error_name'] ); |
---|
48 | } |
---|
49 | } |
---|
50 | //--------------------------------------------------------------- rank updates |
---|
51 | if ( isset( $_GET['up'] ) and is_numeric( $_GET['up'] ) ) |
---|
52 | { |
---|
53 | // 1. searching level (id_uppercat) |
---|
54 | // and rank of the category to move |
---|
55 | $query = 'SELECT id_uppercat,rank'; |
---|
56 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
57 | $query.= ' WHERE id = '.$_GET['up']; |
---|
58 | $query.= ';'; |
---|
59 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
60 | $level = $row['id_uppercat']; |
---|
61 | $rank = $row['rank']; |
---|
62 | // 2. searching the id and the rank of the category |
---|
63 | // just above at the same level |
---|
64 | $query = 'SELECT id,rank'; |
---|
65 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
66 | $query.= ' WHERE rank < '.$rank; |
---|
67 | if ( $level == '' ) |
---|
68 | { |
---|
69 | $query.= ' AND id_uppercat IS NULL'; |
---|
70 | } |
---|
71 | else |
---|
72 | { |
---|
73 | $query.= ' AND id_uppercat = '.$level; |
---|
74 | } |
---|
75 | $query.= ' ORDER BY rank DESC'; |
---|
76 | $query.= ' LIMIT 0,1'; |
---|
77 | $query.= ';'; |
---|
78 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
79 | $new_rank = $row['rank']; |
---|
80 | $replaced_cat = $row['id']; |
---|
81 | // 3. exchanging ranks between the two categories |
---|
82 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
83 | $query.= ' SET rank = '.$new_rank; |
---|
84 | $query.= ' WHERE id = '.$_GET['up']; |
---|
85 | $query.= ';'; |
---|
86 | mysql_query( $query ); |
---|
87 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
88 | $query.= ' SET rank = '.$rank; |
---|
89 | $query.= ' WHERE id = '.$replaced_cat; |
---|
90 | $query.= ';'; |
---|
91 | mysql_query( $query ); |
---|
92 | } |
---|
93 | if ( isset( $_GET['down'] ) and is_numeric( $_GET['down'] ) ) |
---|
94 | { |
---|
95 | // 1. searching level (id_uppercat) |
---|
96 | // and rank of the category to move |
---|
97 | $query = 'SELECT id_uppercat,rank'; |
---|
98 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
99 | $query.= ' WHERE id = '.$_GET['down']; |
---|
100 | $query.= ';'; |
---|
101 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
102 | $level = $row['id_uppercat']; |
---|
103 | $rank = $row['rank']; |
---|
104 | // 2. searching the id and the rank of the category |
---|
105 | // just below at the same level |
---|
106 | $query = 'SELECT id,rank'; |
---|
107 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
108 | $query.= ' WHERE rank > '.$rank; |
---|
109 | if ( $level == '' ) |
---|
110 | { |
---|
111 | $query.= ' AND id_uppercat IS NULL'; |
---|
112 | } |
---|
113 | else |
---|
114 | { |
---|
115 | $query.= ' AND id_uppercat = '.$level; |
---|
116 | } |
---|
117 | $query.= ' ORDER BY rank ASC'; |
---|
118 | $query.= ' LIMIT 0,1'; |
---|
119 | $query.= ';'; |
---|
120 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
121 | $new_rank = $row['rank']; |
---|
122 | $replaced_cat = $row['id']; |
---|
123 | // 3. exchanging ranks between the two categories |
---|
124 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
125 | $query.= ' SET rank = '.$new_rank; |
---|
126 | $query.= ' WHERE id = '.$_GET['down']; |
---|
127 | $query.= ';'; |
---|
128 | mysql_query( $query ); |
---|
129 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
130 | $query.= ' SET rank = '.$rank; |
---|
131 | $query.= ' WHERE id = '.$replaced_cat; |
---|
132 | $query.= ';'; |
---|
133 | mysql_query( $query ); |
---|
134 | } |
---|
135 | if ( isset( $_GET['last'] ) and is_numeric( $_GET['last'] ) ) |
---|
136 | { |
---|
137 | // 1. searching level (id_uppercat) of the category to move |
---|
138 | $query = 'SELECT id_uppercat,rank'; |
---|
139 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
140 | $query.= ' WHERE id = '.$_GET['last']; |
---|
141 | $query.= ';'; |
---|
142 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
143 | $level = $row['id_uppercat']; |
---|
144 | // 2. searching the highest rank of the categories of the same parent |
---|
145 | $query = 'SELECT MAX(rank) AS max_rank'; |
---|
146 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
147 | $query.= ' WHERE id_uppercat'; |
---|
148 | if ( $level == '' ) $query.= ' IS NULL'; |
---|
149 | else $query.= ' = '.$level; |
---|
150 | $query.= ';'; |
---|
151 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
152 | $max_rank = $row['max_rank']; |
---|
153 | // 3. updating the rank of our category to be after the previous max rank |
---|
154 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
155 | $query.= ' SET rank = '.($max_rank + 1); |
---|
156 | $query.= ' WHERE id = '.$_GET['last']; |
---|
157 | $query.= ';'; |
---|
158 | mysql_query( $query ); |
---|
159 | } |
---|
160 | if ( isset( $_GET['first'] ) and is_numeric( $_GET['first'] ) ) |
---|
161 | { |
---|
162 | // to place our category as first, we simply say that is rank is 0, then |
---|
163 | // reordering will move category ranks correctly (first rank should be 1 |
---|
164 | // and not 0) |
---|
165 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
166 | $query.= ' SET rank = 0'; |
---|
167 | $query.= ' WHERE id = '.$_GET['first']; |
---|
168 | $query.= ';'; |
---|
169 | mysql_query( $query ); |
---|
170 | } |
---|
171 | if ( isset( $_GET['delete'] ) and is_numeric( $_GET['delete'] ) ) |
---|
172 | { |
---|
173 | delete_category( $_GET['delete'] ); |
---|
174 | } |
---|
175 | //------------------------------------------------------------------ reordering |
---|
176 | function ordering( $id_uppercat ) |
---|
177 | { |
---|
178 | $rank = 1; |
---|
179 | |
---|
180 | $query = 'SELECT id'; |
---|
181 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
182 | if ( !is_numeric( $id_uppercat ) ) |
---|
183 | { |
---|
184 | $query.= ' WHERE id_uppercat IS NULL'; |
---|
185 | } |
---|
186 | else |
---|
187 | { |
---|
188 | $query.= ' WHERE id_uppercat = '.$id_uppercat; |
---|
189 | } |
---|
190 | $query.= ' ORDER BY rank ASC, dir ASC'; |
---|
191 | $query.= ';'; |
---|
192 | $result = mysql_query( $query ); |
---|
193 | while ( $row = mysql_fetch_array( $result ) ) |
---|
194 | { |
---|
195 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
196 | $query.= ' SET rank = '.$rank; |
---|
197 | $query.= ' WHERE id = '.$row['id']; |
---|
198 | $query.= ';'; |
---|
199 | mysql_query( $query ); |
---|
200 | $rank++; |
---|
201 | ordering( $row['id'] ); |
---|
202 | } |
---|
203 | } |
---|
204 | ordering( 'NULL' ); |
---|
205 | //-------------------------------------------------------------- errors display |
---|
206 | if ( count( $errors ) != 0 ) |
---|
207 | { |
---|
208 | $vtp->addSession( $sub, 'errors' ); |
---|
209 | foreach ( $errors as $error ) { |
---|
210 | $vtp->addSession( $sub, 'li' ); |
---|
211 | $vtp->setVar( $sub, 'li.content', $error ); |
---|
212 | $vtp->closeSession( $sub, 'li' ); |
---|
213 | } |
---|
214 | $vtp->closeSession( $sub, 'errors' ); |
---|
215 | } |
---|
216 | //---------------------------------------------------------------- page display |
---|
217 | function display_cat_manager( $id_uppercat, $indent, |
---|
218 | $uppercat_visible, $level ) |
---|
219 | { |
---|
220 | global $lang,$conf,$sub,$vtp,$page; |
---|
221 | |
---|
222 | // searching the min_rank and the max_rank of the category |
---|
223 | $query = 'SELECT MIN(rank) AS min, MAX(rank) AS max'; |
---|
224 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
225 | if ( !is_numeric( $id_uppercat ) ) |
---|
226 | { |
---|
227 | $query.= ' WHERE id_uppercat IS NULL'; |
---|
228 | } |
---|
229 | else |
---|
230 | { |
---|
231 | $query.= ' WHERE id_uppercat = '.$id_uppercat; |
---|
232 | } |
---|
233 | $query.= ';'; |
---|
234 | $result = mysql_query( $query ); |
---|
235 | $row = mysql_fetch_array( $result ); |
---|
236 | $min_rank = $row['min']; |
---|
237 | $max_rank = $row['max']; |
---|
238 | |
---|
239 | // will we use <th> or <td> lines ? |
---|
240 | $td = 'td'; |
---|
241 | $class = ''; |
---|
242 | if ( $level > 0 ) $class = 'row'.$level; |
---|
243 | else $td = 'th'; |
---|
244 | |
---|
245 | $query = 'SELECT id,name,dir,nb_images,status,rank,site_id,visible'; |
---|
246 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
247 | if ( !is_numeric( $id_uppercat ) ) |
---|
248 | { |
---|
249 | $query.= ' WHERE id_uppercat IS NULL'; |
---|
250 | } |
---|
251 | else |
---|
252 | { |
---|
253 | $query.= ' WHERE id_uppercat = '.$id_uppercat; |
---|
254 | } |
---|
255 | $query.= ' ORDER BY rank ASC'; |
---|
256 | $query.= ';'; |
---|
257 | $result = mysql_query( $query ); |
---|
258 | while ( $row = mysql_fetch_array( $result ) ) |
---|
259 | { |
---|
260 | $subcat_visible = true; |
---|
261 | |
---|
262 | $vtp->addSession( $sub, 'cat' ); |
---|
263 | $vtp->setVar( $sub, 'cat.td', $td ); |
---|
264 | $vtp->setVar( $sub, 'cat.class', $class ); |
---|
265 | $vtp->setVar( $sub, 'cat.indent', $indent ); |
---|
266 | $vtp->setVar( $sub, 'cat.name', $row['name'] ); |
---|
267 | $vtp->setVar( $sub, 'cat.id', $row['id'] ); |
---|
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 | $vtp->setVar( $sub, 'up.id', $row['id'] ); |
---|
303 | $url = add_session_id( './admin.php?page=cat_list&up='.$row['id'] ); |
---|
304 | $vtp->setVar( $sub, 'up.up_url', $url ); |
---|
305 | $vtp->closeSession( $sub, 'up' ); |
---|
306 | } |
---|
307 | else if ( $min_rank != $max_rank ) |
---|
308 | { |
---|
309 | $vtp->addSession( $sub, 'no_up' ); |
---|
310 | $vtp->setVar( $sub, 'no_up.id', $row['id'] ); |
---|
311 | $url = add_session_id( './admin.php?page=cat_list&last='.$row['id']); |
---|
312 | $vtp->setVar( $sub, 'no_up.last_url', $url ); |
---|
313 | $vtp->closeSession( $sub, 'no_up' ); |
---|
314 | } |
---|
315 | if ( $row['rank'] != $max_rank ) |
---|
316 | { |
---|
317 | $vtp->addSession( $sub, 'down' ); |
---|
318 | $vtp->setVar( $sub, 'down.id', $row['id'] ); |
---|
319 | $url = add_session_id( './admin.php?page=cat_list&down='.$row['id']); |
---|
320 | $vtp->setVar( $sub, 'down.down_url', $url ); |
---|
321 | $vtp->closeSession( $sub, 'down' ); |
---|
322 | } |
---|
323 | else if ( $min_rank != $max_rank ) |
---|
324 | { |
---|
325 | $vtp->addSession( $sub, 'no_down' ); |
---|
326 | $vtp->setVar( $sub, 'no_down.id', $row['id'] ); |
---|
327 | $url = add_session_id('./admin.php?page=cat_list&first='.$row['id']); |
---|
328 | $vtp->setVar( $sub, 'no_down.first_url', $url ); |
---|
329 | $vtp->closeSession( $sub, 'no_down' ); |
---|
330 | } |
---|
331 | if ( $row['nb_images'] > 0 ) |
---|
332 | { |
---|
333 | $vtp->addSession( $sub, 'image_info' ); |
---|
334 | $url = add_session_id( './admin.php?page=infos_images&cat_id=' |
---|
335 | .$row['id'] ); |
---|
336 | $vtp->setVar( $sub, 'image_info.image_info_url', $url ); |
---|
337 | $vtp->closeSession( $sub, 'image_info' ); |
---|
338 | } |
---|
339 | else |
---|
340 | { |
---|
341 | $vtp->addSession( $sub, 'no_image_info' ); |
---|
342 | $vtp->closeSession( $sub, 'no_image_info' ); |
---|
343 | } |
---|
344 | if ( $row['status'] == 'private' ) |
---|
345 | { |
---|
346 | $vtp->addSession( $sub, 'permission' ); |
---|
347 | $url=add_session_id('./admin.php?page=cat_perm&cat_id='.$row['id']); |
---|
348 | $vtp->setVar( $sub, 'permission.url', $url ); |
---|
349 | $vtp->closeSession( $sub, 'permission' ); |
---|
350 | } |
---|
351 | else |
---|
352 | { |
---|
353 | $vtp->addSession( $sub, 'no_permission' ); |
---|
354 | $vtp->closeSession( $sub, 'no_permission' ); |
---|
355 | } |
---|
356 | // you can individually update a category only if it is on the main site |
---|
357 | // and if it's not a virtual category (a category is virtual if there is |
---|
358 | // no directory associated) |
---|
359 | if ( $row['site_id'] == 1 and $row['dir'] != '' ) |
---|
360 | { |
---|
361 | $vtp->addSession( $sub, 'update' ); |
---|
362 | $url = add_session_id('./admin.php?page=update&update='.$row['id']); |
---|
363 | $vtp->setVar( $sub, 'update.update_url', $url ); |
---|
364 | $vtp->closeSession( $sub, 'update' ); |
---|
365 | } |
---|
366 | else |
---|
367 | { |
---|
368 | $vtp->addSession( $sub, 'no_update' ); |
---|
369 | $vtp->closeSession( $sub, 'no_update' ); |
---|
370 | } |
---|
371 | |
---|
372 | $vtp->closeSession( $sub, 'cat' ); |
---|
373 | |
---|
374 | display_cat_manager( $row['id'], $indent.str_repeat( ' ', 4 ), |
---|
375 | $subcat_visible, $level + 1 ); |
---|
376 | } |
---|
377 | } |
---|
378 | display_cat_manager( 'NULL', str_repeat( ' ', 4 ), true, 0 ); |
---|
379 | // add a virtual category ? |
---|
380 | $vtp->addSession( $sub, 'associate_cat' ); |
---|
381 | $vtp->setVar( $sub, 'associate_cat.value', '-1' ); |
---|
382 | $vtp->setVar( $sub, 'associate_cat.content', '' ); |
---|
383 | $vtp->closeSession( $sub, 'associate_cat' ); |
---|
384 | $page['plain_structure'] = get_plain_structure(); |
---|
385 | $structure = create_structure( '', array() ); |
---|
386 | display_categories( $structure, ' ' ); |
---|
387 | //----------------------------------------------------------- sending html code |
---|
388 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
389 | ?> |
---|