source: trunk/admin/cat_list.php @ 29

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

template as user_template for displaying pictures in the template

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 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$vtp->setGlobalVar( $sub, 'user_template',   $user['template'] );
29//---------------------------------------------------------------  rank updates
30if ( 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 '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'categories';
62  $query.= ' SET rank = '.$new_rank;
63  $query.= ' WHERE id = '.$_GET['up'];
64  $query.= ';';
65  mysql_query( $query );
66  $query = 'UPDATE '.PREFIX_TABLE.'categories';
67  $query.= ' SET rank = '.$rank;
68  $query.= ' WHERE id = '.$replaced_cat;
69  $query.= ';';
70  mysql_query( $query );
71}
72if ( 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 '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'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 '.PREFIX_TABLE.'categories';
104  $query.= ' SET rank = '.$new_rank;
105  $query.= ' WHERE id = '.$_GET['down'];
106  $query.= ';';
107  mysql_query( $query );
108  $query = 'UPDATE '.PREFIX_TABLE.'categories';
109  $query.= ' SET rank = '.$rank;
110  $query.= ' WHERE id = '.$replaced_cat;
111  $query.= ';';
112  mysql_query( $query );
113}
114//------------------------------------------------------------------ reordering
115function ordering( $id_uppercat )
116{
117  $rank = 1;
118               
119  $query = 'SELECT id';
120  $query.= ' FROM '.PREFIX_TABLE.'categories';
121  if ( !is_numeric( $id_uppercat ) )
122  {
123    $query.= ' WHERE id_uppercat IS NULL';
124  }
125  else
126  {
127    $query.= ' WHERE id_uppercat = '.$id_uppercat;
128  }
129  $query.= ' ORDER BY rank ASC, dir ASC';
130  $query.= ';';
131  $result = mysql_query( $query );
132  while ( $row = mysql_fetch_array( $result ) )
133  {
134    $query = 'UPDATE '.PREFIX_TABLE.'categories';
135    $query.= ' SET rank = '.$rank;
136    $query.= ' WHERE id = '.$row['id'];
137    $query.= ';';
138    mysql_query( $query );
139    $rank++;
140    ordering( $row['id'] );
141  }
142}
143       
144ordering( 'NULL' );
145//----------------------------------------------------affichage de la page
146function display_cat_manager( $id_uppercat, $indent,
147                              $uppercat_visible, $level )
148{
149  global $lang,$conf,$sub,$vtp;
150               
151  // searching the min_rank and the max_rank of the category
152  $query = 'SELECT MIN(rank) AS min, MAX(rank) AS max';
153  $query.= ' FROM '.PREFIX_TABLE.'categories';
154  if ( !is_numeric( $id_uppercat ) )
155  {
156    $query.= ' WHERE id_uppercat IS NULL';
157  }
158  else
159  {
160    $query.= ' WHERE id_uppercat = '.$id_uppercat;
161  }
162  $query.= ';';
163  $result = mysql_query( $query );
164  $row    = mysql_fetch_array( $result );
165  $min_rank = $row['min'];
166  $max_rank = $row['max'];
167               
168  // will we use <th> or <td> lines ?
169  $td    = 'td';
170  $class = '';
171  if ( $level > 0 )
172  {
173    $class = 'row'.$level;
174  }
175  else
176  {
177    $td = 'th';
178  }
179               
180  $query = 'SELECT id,name,dir,nb_images,status,rank,site_id,visible';
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';
191  $query.= ';';
192  $result = mysql_query( $query );
193  while ( $row = mysql_fetch_array( $result ) )
194  {
195    $subcat_visible = true;
196
197    $vtp->addSession( $sub, 'cat' );
198    $vtp->setVar( $sub, 'cat.td', $td );
199    $vtp->setVar( $sub, 'cat.class', $class );
200    $vtp->setVar( $sub, 'cat.indent', $indent );
201    if ( $row['name'] == '' )
202    {
203      $name = str_replace( '_', ' ', $row['dir'] );
204    }
205    else
206    {
207      $name = $row['name'];
208    }
209    $vtp->setVar( $sub, 'cat.name', $name );
210    $vtp->setVar( $sub, 'cat.dir', $row['dir'] );
211    if ( $row['visible'] == 'false' or !$uppercat_visible )
212    {
213      $subcat_visible = false;
214      $vtp->setVar( $sub, 'cat.invisible', $lang['cat_invisible'] );
215    }
216    if ( $row['status'] == 'private' )
217    {
218      $vtp->setVar( $sub, 'cat.private', $lang['private'] );
219    }
220    $vtp->setVar( $sub, 'cat.nb_picture', $row['nb_images'] );
221    $url = add_session_id( './admin.php?page=cat_modify&amp;cat='.$row['id'] );
222    $vtp->setVar( $sub, 'cat.edit_url', $url );
223    if ( $row['rank'] != $min_rank )
224    {
225      $vtp->addSession( $sub, 'up' );
226      $url = add_session_id( './admin.php?page=cat&amp;up='.$row['id'] );
227      $vtp->setVar( $sub, 'up.up_url', $url );
228      $vtp->closeSession( $sub, 'up' );
229    }
230    else
231    {
232      $vtp->addSession( $sub, 'no_up' );
233      $vtp->closeSession( $sub, 'no_up' );
234    }
235    if ( $row['rank'] != $max_rank )
236    {
237      $vtp->addSession( $sub, 'down' );
238      $url = add_session_id( './admin.php?page=cat&amp;down='.$row['id'] );
239      $vtp->setVar( $sub, 'down.down_url', $url );
240      $vtp->closeSession( $sub, 'down' );
241    }
242    else
243    {
244      $vtp->addSession( $sub, 'no_down' );
245      $vtp->closeSession( $sub, 'no_down' );
246    }
247    if ( $row['nb_images'] > 0 )
248    {
249      $vtp->addSession( $sub, 'image_info' );
250      $url = add_session_id( './admin.php?page=infos_images&amp;cat_id='
251                             .$row['id'] );
252      $vtp->setVar( $sub, 'image_info.image_info_url', $url );
253      $vtp->closeSession( $sub, 'image_info' );
254    }
255    else
256    {
257      $vtp->addSession( $sub, 'no_image_info' );
258      $vtp->closeSession( $sub, 'no_image_info' );
259    }
260    if ( $row['status'] == 'private' )
261    {
262      $vtp->addSession( $sub, 'permission' );
263      $url=add_session_id('./admin.php?page=cat_perm&amp;cat_id='.$row['id']);
264      $vtp->setVar( $sub, 'permission.url', $url );
265      $vtp->closeSession( $sub, 'permission' );
266    }
267    else
268    {
269      $vtp->addSession( $sub, 'no_permission' );
270      $vtp->closeSession( $sub, 'no_permission' );
271    }
272    if ( $row['site_id'] == 1 )
273    {
274      $vtp->addSession( $sub, 'update' );
275      $url = add_session_id('./admin.php?page=update&amp;update='.$row['id']);
276      $vtp->setVar( $sub, 'update.update_url', $url );
277      $vtp->closeSession( $sub, 'update' );
278    }
279    else
280    {
281      $vtp->addSession( $sub, 'no_update' );
282      $vtp->closeSession( $sub, 'no_update' );
283    }
284
285    $vtp->closeSession( $sub, 'cat' );
286
287    display_cat_manager( $row['id'], $indent.str_repeat( '&nbsp', 4 ),
288                         $subcat_visible, $level + 1 );
289  }
290}
291display_cat_manager( 'NULL', str_repeat( '&nbsp', 4 ), true, 0 );
292//----------------------------------------------------------- sending html code
293$vtp->Parse( $handle , 'sub', $sub );
294?>
Note: See TracBrowser for help on using the repository browser.