source: trunk/admin/cat_list.php @ 21

Last change on this file since 21 was 21, checked in by z0rglub, 21 years ago

* empty log message *

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
1<?php
2/***************************************************************************
3 *                                  cat.php                                *
4 *                            -------------------                          *
5 *   application          : PhpWebGallery 1.3                              *
6 *   website              : http://www.phpwebgallery.net                   *
7 *   author               : Pierrick LE GALL <pierrick@z0rglub.com>        *
8 *                                                                         *
9 ***************************************************************************/
10
11/***************************************************************************
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 ***************************************************************************/
18include_once( './include/isadmin.inc.php' );
19//----------------------------------------------------- template initialization
20$sub = $vtp->Open( '../template/'.$user['template'].'/admin/cat_list.vtp' );
21// language
22$vtp->setGlobalVar( $sub, 'cat_edit',        $lang['cat_edit'] );
23$vtp->setGlobalVar( $sub, 'cat_up',          $lang['cat_up'] );
24$vtp->setGlobalVar( $sub, 'cat_down',        $lang['cat_down'] );
25$vtp->setGlobalVar( $sub, 'cat_image_info',  $lang['cat_image_info'] );
26$vtp->setGlobalVar( $sub, 'cat_permission',  $lang['cat_permission'] );
27$vtp->setGlobalVar( $sub, 'cat_update',      $lang['cat_update'] );
28//---------------------------------------------------------------  rank updates
29if ( isset( $_GET['up'] ) && is_numeric( $_GET['up'] ) )
30{
31  // 1. searching level (id_uppercat)
32  //    and rank of the category to move
33  $query = 'SELECT id_uppercat,rank';
34  $query.= ' FROM '.PREFIX_TABLE.'categories';
35  $query.= ' WHERE id = '.$_GET['up'];
36  $query.= ';';
37  $row = mysql_fetch_array( mysql_query( $query ) );
38  $level = $row['id_uppercat'];
39  $rank  = $row['rank'];
40  // 2. searching the id and the rank of the category
41  //    just above at the same level
42  $query = 'SELECT id,rank';
43  $query.= ' FROM '.PREFIX_TABLE.'categories';
44  $query.= ' WHERE rank < '.$rank;
45  if ( $level == '' )
46  {
47    $query.= ' AND id_uppercat IS NULL';
48  }
49  else
50  {
51    $query.= ' AND id_uppercat = '.$level;
52  }
53  $query.= ' ORDER BY rank DESC';
54  $query.= ' LIMIT 0,1';
55  $query.= ';';
56  $row = mysql_fetch_array( mysql_query( $query ) );
57  $new_rank     = $row['rank'];
58  $replaced_cat = $row['id'];
59  // 3. exchanging ranks between the two categories
60  $query = 'UPDATE '.PREFIX_TABLE.'categories';
61  $query.= ' SET rank = '.$new_rank;
62  $query.= ' WHERE id = '.$_GET['up'];
63  $query.= ';';
64  mysql_query( $query );
65  $query = 'UPDATE '.PREFIX_TABLE.'categories';
66  $query.= ' SET rank = '.$rank;
67  $query.= ' WHERE id = '.$replaced_cat;
68  $query.= ';';
69  mysql_query( $query );
70}
71if ( isset( $_GET['down'] ) && is_numeric( $_GET['down'] ) )
72{
73  // 1. searching level (id_uppercat)
74  //    and rank of the category to move
75  $query = 'SELECT id_uppercat,rank';
76  $query.= ' FROM '.PREFIX_TABLE.'categories';
77  $query.= ' WHERE id = '.$_GET['down'];
78  $query.= ';';
79  $row = mysql_fetch_array( mysql_query( $query ) );
80  $level = $row['id_uppercat'];
81  $rank  = $row['rank'];
82  // 2. searching the id and the rank of the category
83  //    just below at the same level
84  $query = 'SELECT id,rank';
85  $query.= ' FROM '.PREFIX_TABLE.'categories';
86  $query.= ' WHERE rank > '.$rank;
87  if ( $level == '' )
88  {
89    $query.= ' AND id_uppercat is null';
90  }
91  else
92  {
93    $query.= ' AND id_uppercat = '.$level;
94  }
95  $query.= ' ORDER BY rank ASC';
96  $query.= ' LIMIT 0,1';
97  $query.= ';';
98  $row = mysql_fetch_array( mysql_query( $query ) );
99  $new_rank     = $row['rank'];
100  $replaced_cat = $row['id'];
101  // 3. exchanging ranks between the two categories
102  $query = 'UPDATE '.PREFIX_TABLE.'categories';
103  $query.= ' SET rank = '.$new_rank;
104  $query.= ' WHERE id = '.$_GET['down'];
105  $query.= ';';
106  mysql_query( $query );
107  $query = 'UPDATE '.PREFIX_TABLE.'categories';
108  $query.= ' SET rank = '.$rank;
109  $query.= ' WHERE id = '.$replaced_cat;
110  $query.= ';';
111  mysql_query( $query );
112}
113//------------------------------------------------------------------ reordering
114function ordering( $id_uppercat )
115{
116  $rank = 1;
117               
118  $query = 'SELECT id';
119  $query.= ' FROM '.PREFIX_TABLE.'categories';
120  if ( !is_numeric( $id_uppercat ) )
121  {
122    $query.= ' WHERE id_uppercat IS NULL';
123  }
124  else
125  {
126    $query.= ' WHERE id_uppercat = '.$id_uppercat;
127  }
128  $query.= ' ORDER BY rank ASC, dir ASC';
129  $query.= ';';
130  $result = mysql_query( $query );
131  while ( $row = mysql_fetch_array( $result ) )
132  {
133    $query = 'UPDATE '.PREFIX_TABLE.'categories';
134    $query.= ' SET rank = '.$rank;
135    $query.= ' WHERE id = '.$row['id'];
136    $query.= ';';
137    mysql_query( $query );
138    $rank++;
139    ordering( $row['id'] );
140  }
141}
142       
143ordering( 'NULL' );
144//----------------------------------------------------affichage de la page
145function display_cat_manager( $id_uppercat, $indent,
146                              $uppercat_visible, $level )
147{
148  global $lang,$conf,$sub,$vtp;
149               
150  // searching the min_rank and the max_rank of the category
151  $query = 'SELECT MIN(rank) AS min, MAX(rank) AS max';
152  $query.= ' FROM '.PREFIX_TABLE.'categories';
153  if ( !is_numeric( $id_uppercat ) )
154  {
155    $query.= ' WHERE id_uppercat IS NULL';
156  }
157  else
158  {
159    $query.= ' WHERE id_uppercat = '.$id_uppercat;
160  }
161  $query.= ';';
162  $result = mysql_query( $query );
163  $row    = mysql_fetch_array( $result );
164  $min_rank = $row['min'];
165  $max_rank = $row['max'];
166               
167  // will we use <th> or <td> lines ?
168  $td    = 'td';
169  $class = '';
170  if ( $level > 0 )
171  {
172    $class = 'row'.$level;
173  }
174  else
175  {
176    $td = 'th';
177  }
178               
179  $query = 'SELECT id,name,dir,nb_images,status,rank,site_id,visible';
180  $query.= ' FROM '.PREFIX_TABLE.'categories';
181  if ( !is_numeric( $id_uppercat ) )
182  {
183    $query.= ' WHERE id_uppercat IS NULL';
184  }
185  else
186  {
187    $query.= ' WHERE id_uppercat = '.$id_uppercat;
188  }
189  $query.= ' ORDER BY rank ASC';
190  $query.= ';';
191  $result = mysql_query( $query );
192  while ( $row = mysql_fetch_array( $result ) )
193  {
194    $subcat_visible = true;
195
196    $vtp->addSession( $sub, 'cat' );
197    $vtp->setVar( $sub, 'cat.td', $td );
198    $vtp->setVar( $sub, 'cat.class', $class );
199    $vtp->setVar( $sub, 'cat.indent', $indent );
200    if ( $row['name'] == '' )
201    {
202      $name = str_replace( '_', ' ', $row['dir'] );
203    }
204    else
205    {
206      $name = $row['name'];
207    }
208    $vtp->setVar( $sub, 'cat.name', $name );
209    $vtp->setVar( $sub, 'cat.dir', $row['dir'] );
210    if ( $row['visible'] == 'false' or !$uppercat_visible )
211    {
212      $subcat_visible = false;
213      $vtp->setVar( $sub, 'cat.invisible', $lang['cat_invisible'] );
214    }
215    if ( $row['status'] == 'private' )
216    {
217      $vtp->setVar( $sub, 'cat.private', $lang['private'] );
218    }
219    $vtp->setVar( $sub, 'cat.nb_picture', $row['nb_images'] );
220    $url = add_session_id( './admin.php?page=cat_modify&amp;cat='.$row['id'] );
221    $vtp->setVar( $sub, 'cat.edit_url', $url );
222    if ( $row['rank'] != $min_rank )
223    {
224      $vtp->addSession( $sub, 'up' );
225      $url = add_session_id( './admin.php?page=cat&amp;up='.$row['id'] );
226      $vtp->setVar( $sub, 'up.up_url', $url );
227      $vtp->closeSession( $sub, 'up' );
228    }
229    else
230    {
231      $vtp->addSession( $sub, 'no_up' );
232      $vtp->closeSession( $sub, 'no_up' );
233    }
234    if ( $row['rank'] != $max_rank )
235    {
236      $vtp->addSession( $sub, 'down' );
237      $url = add_session_id( './admin.php?page=cat&amp;down='.$row['id'] );
238      $vtp->setVar( $sub, 'down.down_url', $url );
239      $vtp->closeSession( $sub, 'down' );
240    }
241    else
242    {
243      $vtp->addSession( $sub, 'no_down' );
244      $vtp->closeSession( $sub, 'no_down' );
245    }
246    if ( $row['nb_images'] > 0 )
247    {
248      $vtp->addSession( $sub, 'image_info' );
249      $url = add_session_id( './admin.php?page=infos_images&amp;cat_id='
250                             .$row['id'] );
251      $vtp->setVar( $sub, 'image_info.image_info_url', $url );
252      $vtp->closeSession( $sub, 'image_info' );
253    }
254    else
255    {
256      $vtp->addSession( $sub, 'no_image_info' );
257      $vtp->closeSession( $sub, 'no_image_info' );
258    }
259    if ( $row['status'] == 'private' )
260    {
261      $vtp->addSession( $sub, 'permission' );
262      $url=add_session_id('./admin.php?page=cat_perm&amp;cat_id='.$row['id']);
263      $vtp->setVar( $sub, 'permission.url', $url );
264      $vtp->closeSession( $sub, 'permission' );
265    }
266    else
267    {
268      $vtp->addSession( $sub, 'no_permission' );
269      $vtp->closeSession( $sub, 'no_permission' );
270    }
271    if ( $row['site_id'] == 1 )
272    {
273      $vtp->addSession( $sub, 'update' );
274      $url = add_session_id('./admin.php?page=update&amp;update='.$row['id']);
275      $vtp->setVar( $sub, 'update.update_url', $url );
276      $vtp->closeSession( $sub, 'update' );
277    }
278    else
279    {
280      $vtp->addSession( $sub, 'no_update' );
281      $vtp->closeSession( $sub, 'no_update' );
282    }
283
284    $vtp->closeSession( $sub, 'cat' );
285
286    display_cat_manager( $row['id'], $indent.str_repeat( '&nbsp', 4 ),
287                         $subcat_visible, $level + 1 );
288  }
289}
290display_cat_manager( 'NULL', str_repeat( '&nbsp', 4 ), true, 0 );
291//----------------------------------------------------------- sending html code
292$vtp->Parse( $handle , 'sub', $sub );
293?>
Note: See TracBrowser for help on using the repository browser.