1 | <?php |
---|
2 | /*************************************************************************** |
---|
3 | * this file is a part of PhpWebGallery * |
---|
4 | * ------------------- * |
---|
5 | * version : 1.3 * |
---|
6 | * url : http://phpwebgallery.net * |
---|
7 | * help : http://forum.phpwebgallery.net * |
---|
8 | * author : Pierrick LE GALL * |
---|
9 | * * |
---|
10 | ***************************************************************************/ |
---|
11 | |
---|
12 | /*************************************************************************** |
---|
13 | * * |
---|
14 | * This program is free software; you can redistribute it and/or modify * |
---|
15 | * it under the terms of the GNU General Public License as published by * |
---|
16 | * the Free Software Foundation; * |
---|
17 | * * |
---|
18 | ***************************************************************************/ |
---|
19 | include_once( './include/isadmin.inc.php' ); |
---|
20 | //----------------------------------------------------- template initialization |
---|
21 | $sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat.vtp' ); |
---|
22 | // language |
---|
23 | $vtp->setGlobalVar( $sub, 'cat_edit', $lang['cat_edit'] ); |
---|
24 | $vtp->setGlobalVar( $sub, 'cat_up', $lang['cat_up'] ); |
---|
25 | $vtp->setGlobalVar( $sub, 'cat_down', $lang['cat_down'] ); |
---|
26 | $vtp->setGlobalVar( $sub, 'cat_image_info', $lang['cat_image_info'] ); |
---|
27 | $vtp->setGlobalVar( $sub, 'cat_permission', $lang['cat_permission'] ); |
---|
28 | $vtp->setGlobalVar( $sub, 'cat_update', $lang['cat_update'] ); |
---|
29 | //--------------------------------------------------------------- rank updates |
---|
30 | if ( isset( $_GET['up'] ) && is_numeric( $_GET['up'] ) ) |
---|
31 | { |
---|
32 | // 1. searching level (id_uppercat) |
---|
33 | // and rank of the category to move |
---|
34 | $query = 'select id_uppercat,rank'; |
---|
35 | $query.= ' from '.$prefixeTable.'categories'; |
---|
36 | $query.= ' where id = '.$_GET['up']; |
---|
37 | $query.= ';'; |
---|
38 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
39 | $level = $row['id_uppercat']; |
---|
40 | $rank = $row['rank']; |
---|
41 | // 2. searching the id and the rank of the category |
---|
42 | // just above at the same level |
---|
43 | $query = 'select id,rank'; |
---|
44 | $query.= ' from '.$prefixeTable.'categories'; |
---|
45 | $query.= ' where rank < '.$rank; |
---|
46 | if ( $level == '' ) |
---|
47 | { |
---|
48 | $query.= ' and id_uppercat is null'; |
---|
49 | } |
---|
50 | else |
---|
51 | { |
---|
52 | $query.= ' and id_uppercat = '.$level; |
---|
53 | } |
---|
54 | $query.= ' order by rank desc'; |
---|
55 | $query.= ' limit 0,1'; |
---|
56 | $query.= ';'; |
---|
57 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
58 | $new_rank = $row['rank']; |
---|
59 | $replaced_cat = $row['id']; |
---|
60 | // 3. exchanging ranks between the two categories |
---|
61 | $query = 'update '.$prefixeTable.'categories'; |
---|
62 | $query.= ' set rank = '.$new_rank; |
---|
63 | $query.= ' where id = '.$_GET['up']; |
---|
64 | $query.= ';'; |
---|
65 | mysql_query( $query ); |
---|
66 | $query = 'update '.$prefixeTable.'categories'; |
---|
67 | $query.= ' set rank = '.$rank; |
---|
68 | $query.= ' where id = '.$replaced_cat; |
---|
69 | $query.= ';'; |
---|
70 | mysql_query( $query ); |
---|
71 | } |
---|
72 | if ( isset( $_GET['down'] ) && is_numeric( $_GET['down'] ) ) |
---|
73 | { |
---|
74 | // 1. searching level (id_uppercat) |
---|
75 | // and rank of the category to move |
---|
76 | $query = 'select id_uppercat,rank'; |
---|
77 | $query.= ' from '.$prefixeTable.'categories'; |
---|
78 | $query.= ' where id = '.$_GET['down']; |
---|
79 | $query.= ';'; |
---|
80 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
81 | $level = $row['id_uppercat']; |
---|
82 | $rank = $row['rank']; |
---|
83 | // 2. searching the id and the rank of the category |
---|
84 | // just below at the same level |
---|
85 | $query = 'select id,rank'; |
---|
86 | $query.= ' from '.$prefixeTable.'categories'; |
---|
87 | $query.= ' where rank > '.$rank; |
---|
88 | if ( $level == '' ) |
---|
89 | { |
---|
90 | $query.= ' and id_uppercat is null'; |
---|
91 | } |
---|
92 | else |
---|
93 | { |
---|
94 | $query.= ' and id_uppercat = '.$level; |
---|
95 | } |
---|
96 | $query.= ' order by rank asc'; |
---|
97 | $query.= ' limit 0,1'; |
---|
98 | $query.= ';'; |
---|
99 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
100 | $new_rank = $row['rank']; |
---|
101 | $replaced_cat = $row['id']; |
---|
102 | // 3. exchanging ranks between the two categories |
---|
103 | $query = 'update '.$prefixeTable.'categories'; |
---|
104 | $query.= ' set rank = '.$new_rank; |
---|
105 | $query.= ' where id = '.$_GET['down']; |
---|
106 | $query.= ';'; |
---|
107 | mysql_query( $query ); |
---|
108 | $query = 'update '.$prefixeTable.'categories'; |
---|
109 | $query.= ' set rank = '.$rank; |
---|
110 | $query.= ' where id = '.$replaced_cat; |
---|
111 | $query.= ';'; |
---|
112 | mysql_query( $query ); |
---|
113 | } |
---|
114 | //------------------------------------------------------------------ reordering |
---|
115 | function ordering( $id_uppercat ) |
---|
116 | { |
---|
117 | global $prefixeTable; |
---|
118 | |
---|
119 | $rank = 1; |
---|
120 | |
---|
121 | $query = 'select id'; |
---|
122 | $query.= ' from '.$prefixeTable.'categories'; |
---|
123 | if ( !is_numeric( $id_uppercat ) ) |
---|
124 | { |
---|
125 | $query.= ' where id_uppercat is NULL'; |
---|
126 | } |
---|
127 | else |
---|
128 | { |
---|
129 | $query.= ' where id_uppercat = '.$id_uppercat; |
---|
130 | } |
---|
131 | $query.= ' order by rank asc, dir asc'; |
---|
132 | $query.= ';'; |
---|
133 | $result = mysql_query( $query ); |
---|
134 | while ( $row = mysql_fetch_array( $result ) ) |
---|
135 | { |
---|
136 | $query = 'update '.$prefixeTable.'categories'; |
---|
137 | $query.= ' set rank = '.$rank; |
---|
138 | $query.= ' where id = '.$row['id']; |
---|
139 | $query.= ';'; |
---|
140 | mysql_query( $query ); |
---|
141 | $rank++; |
---|
142 | ordering( $row['id'] ); |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | ordering( 'NULL' ); |
---|
147 | //----------------------------------------------------affichage de la page |
---|
148 | function display_cat_manager( $id_uppercat, $indent, |
---|
149 | $uppercat_visible, $level ) |
---|
150 | { |
---|
151 | global $prefixeTable,$lang,$conf,$sub,$vtp; |
---|
152 | |
---|
153 | // searching the min_rank and the max_rank of the category |
---|
154 | $query = 'select min(rank) as min, max(rank) as max'; |
---|
155 | $query.= ' from '.$prefixeTable.'categories'; |
---|
156 | if ( !is_numeric( $id_uppercat ) ) |
---|
157 | { |
---|
158 | $query.= ' where id_uppercat is NULL'; |
---|
159 | } |
---|
160 | else |
---|
161 | { |
---|
162 | $query.= ' where id_uppercat = '.$id_uppercat; |
---|
163 | } |
---|
164 | $query.= ';'; |
---|
165 | $result = mysql_query( $query ); |
---|
166 | $row = mysql_fetch_array( $result ); |
---|
167 | $min_rank = $row['min']; |
---|
168 | $max_rank = $row['max']; |
---|
169 | |
---|
170 | // will we use <th> or <td> lines ? |
---|
171 | $td = 'td'; |
---|
172 | $class = ''; |
---|
173 | if ( $level > 0 ) |
---|
174 | { |
---|
175 | $class = 'row'.$level; |
---|
176 | } |
---|
177 | else |
---|
178 | { |
---|
179 | $td = 'th'; |
---|
180 | } |
---|
181 | |
---|
182 | $query = 'select id,name,dir,nb_images,status,rank,site_id'; |
---|
183 | $query.= ' from '.$prefixeTable.'categories'; |
---|
184 | if ( !is_numeric( $id_uppercat ) ) |
---|
185 | { |
---|
186 | $query.= ' where id_uppercat is NULL'; |
---|
187 | } |
---|
188 | else |
---|
189 | { |
---|
190 | $query.= ' where id_uppercat = '.$id_uppercat; |
---|
191 | } |
---|
192 | $query.= ' order by rank asc'; |
---|
193 | $query.= ';'; |
---|
194 | $result = mysql_query( $query ); |
---|
195 | while ( $row = mysql_fetch_array( $result ) ) |
---|
196 | { |
---|
197 | $subcat_visible = true; |
---|
198 | |
---|
199 | $vtp->addSession( $sub, 'cat' ); |
---|
200 | $vtp->setVar( $sub, 'cat.td', $td ); |
---|
201 | $vtp->setVar( $sub, 'cat.class', $class ); |
---|
202 | $vtp->setVar( $sub, 'cat.indent', $indent ); |
---|
203 | if ( $row['name'] == '' ) |
---|
204 | { |
---|
205 | $name = str_replace( '_', ' ', $row['dir'] ); |
---|
206 | } |
---|
207 | else |
---|
208 | { |
---|
209 | $name = $row['name']; |
---|
210 | } |
---|
211 | $vtp->setVar( $sub, 'cat.name', $name ); |
---|
212 | $vtp->setVar( $sub, 'cat.dir', $row['dir'] ); |
---|
213 | if ( $row['status'] == 'invisible' || !$uppercat_visible ) |
---|
214 | { |
---|
215 | $subcat_visible = false; |
---|
216 | $vtp->setVar( $sub, 'cat.invisible', $lang['cat_invisible'] ); |
---|
217 | } |
---|
218 | $vtp->setVar( $sub, 'cat.nb_picture', $row['nb_images'] ); |
---|
219 | $url = add_session_id( './admin.php?page=edit_cat&cat='.$row['id'] ); |
---|
220 | $vtp->setVar( $sub, 'cat.edit_url', $url ); |
---|
221 | if ( $row['rank'] != $min_rank ) |
---|
222 | { |
---|
223 | $vtp->addSession( $sub, 'up' ); |
---|
224 | $url = add_session_id( './admin.php?page=cat&up='.$row['id'] ); |
---|
225 | $vtp->setVar( $sub, 'up.up_url', $url ); |
---|
226 | $vtp->closeSession( $sub, 'up' ); |
---|
227 | } |
---|
228 | else |
---|
229 | { |
---|
230 | $vtp->addSession( $sub, 'no_up' ); |
---|
231 | $vtp->closeSession( $sub, 'no_up' ); |
---|
232 | } |
---|
233 | if ( $row['rank'] != $max_rank ) |
---|
234 | { |
---|
235 | $vtp->addSession( $sub, 'down' ); |
---|
236 | $url = add_session_id( './admin.php?page=cat&down='.$row['id'] ); |
---|
237 | $vtp->setVar( $sub, 'down.down_url', $url ); |
---|
238 | $vtp->closeSession( $sub, 'down' ); |
---|
239 | } |
---|
240 | else |
---|
241 | { |
---|
242 | $vtp->addSession( $sub, 'no_down' ); |
---|
243 | $vtp->closeSession( $sub, 'no_down' ); |
---|
244 | } |
---|
245 | if ( $row['nb_images'] > 0 ) |
---|
246 | { |
---|
247 | $vtp->addSession( $sub, 'image_info' ); |
---|
248 | $url = add_session_id( './admin.php?page=infos_images&cat_id=' |
---|
249 | .$row['id'] ); |
---|
250 | $vtp->setVar( $sub, 'image_info.image_info_url', $url ); |
---|
251 | $vtp->closeSession( $sub, 'image_info' ); |
---|
252 | } |
---|
253 | else |
---|
254 | { |
---|
255 | $vtp->addSession( $sub, 'no_image_info' ); |
---|
256 | $vtp->closeSession( $sub, 'no_image_info' ); |
---|
257 | } |
---|
258 | $url = add_session_id( './admin.php?page=perm&cat_id='.$row['id'] ); |
---|
259 | $vtp->setVar( $sub, 'cat.permission_url', $url ); |
---|
260 | if ( $row['site_id'] == 1 ) |
---|
261 | { |
---|
262 | $vtp->addSession( $sub, 'update' ); |
---|
263 | $url = add_session_id('./admin.php?page=update&update='.$row['id']); |
---|
264 | $vtp->setVar( $sub, 'update.update_url', $url ); |
---|
265 | $vtp->closeSession( $sub, 'update' ); |
---|
266 | } |
---|
267 | else |
---|
268 | { |
---|
269 | $vtp->addSession( $sub, 'no_update' ); |
---|
270 | $vtp->closeSession( $sub, 'no_update' ); |
---|
271 | } |
---|
272 | |
---|
273 | $vtp->closeSession( $sub, 'cat' ); |
---|
274 | |
---|
275 | display_cat_manager( $row['id'], $indent.str_repeat( ' ', 4 ), |
---|
276 | $subcat_visible, $level + 1 ); |
---|
277 | } |
---|
278 | } |
---|
279 | display_cat_manager( 'NULL', str_repeat( ' ', 4 ), true, 0 ); |
---|
280 | //----------------------------------------------------------- sending html code |
---|
281 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
282 | ?> |
---|