source: trunk/admin/cat_list.php @ 496

Last change on this file since 496 was 496, checked in by gweltas, 20 years ago
  • Deletion of obsolete functions in the administrative part
  • Repair of virtual category management
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// |                             cat_list.php                              |
4// +-----------------------------------------------------------------------+
5// | application   : PhpWebGallery <http://phpwebgallery.net>              |
6// | branch        : BSF (Best So Far)                                     |
7// +-----------------------------------------------------------------------+
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-08-25 22:25:58 +0000 (Wed, 25 Aug 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 496 $
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// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28if( !defined("PHPWG_ROOT_PATH") )
29{
30        die ("Hacking attempt!");
31}
32include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' );
33
34$errors = array();
35$categories=array();
36$navigation=$lang['gallery_index'];
37
38//---------------------------------------------------  virtual categories
39if ( isset( $_GET['delete'] ) && is_numeric( $_GET['delete'] ) )
40{
41  $to_delete_categories = array();
42  array_push($to_delete_categories,$_GET['delete']);
43  delete_categories( $to_delete_categories );
44}
45elseif ( isset( $_POST['submit'] ) )
46{
47  // is the given category name only containing blank spaces ?
48  if ( preg_match( '/^\s*$/', $_POST['virtual_name'] ) )
49    array_push( $errors, $lang['cat_error_name'] );
50       
51  if ( !count( $errors ))
52  {
53    $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; 
54    // As we don't create a virtual category every day, let's do (far) too much queries
55    if ($parent_id!='NULL')
56    {
57          $query = 'SELECT uppercats FROM '.CATEGORIES_TABLE;
58      $query.= ' WHERE id="'.$parent_id.'";';
59          $parent_uppercats = array_pop(mysql_fetch_array( mysql_query( $query )));
60        }
61       
62        // we have then to add the virtual category
63    $query = 'INSERT INTO '.CATEGORIES_TABLE;
64    $query.= ' (name,id_uppercat,rank) VALUES ';
65    $query.= " ('".$_POST['virtual_name']."',".$parent_id.",".$_POST['rank'].");";
66        mysql_query( $query );
67       
68        // And last we update the uppercats
69        $query = 'SELECT MAX(id) FROM '.CATEGORIES_TABLE.';';
70        $my_id = array_pop(mysql_fetch_array( mysql_query( $query )));
71        $query = 'UPDATE '.CATEGORIES_TABLE.' SET uppercats = "';
72        if (!empty($parent_uppercats))
73    {
74      $query.= $parent_uppercats.',';
75    }
76        $query.= $my_id;
77        $query.= '" WHERE id = '.$my_id.';';
78        mysql_query( $query );   
79  }
80}
81
82// Cache management
83
84$query = 'SELECT * FROM '.CATEGORIES_TABLE;
85if ( !isset($_GET['parent_id']))
86{
87  $query.= ' WHERE id_uppercat IS NULL';
88}
89else
90{
91  $query.= ' WHERE id_uppercat = '.$_GET['parent_id'];
92}
93$query.= ' ORDER BY rank ASC';
94$query.= ';';
95$result = mysql_query( $query );
96while ( $row = mysql_fetch_assoc( $result ) )
97{
98  $categories[$row['rank']]=$row;
99}
100
101// Navigation path
102if (isset($_GET['parent_id']))
103{
104  $current_category = get_cat_info($_GET['parent_id']);
105  $url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&amp;parent_id=';
106  $navigation = '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.'admin.php?page=cat_list').'">';
107  $navigation.= $lang['gallery_index'].'</a>-&gt;';
108  $navigation.= get_cat_display_name($current_category['name'], '-&gt;', $url);
109}
110
111//---------------------------------------------------------------  rank updates
112$current_rank=0;
113if ( isset( $_GET['up'] ) && is_numeric( $_GET['up'] ))
114{
115  // 1. searching the id of the category just above at the same level
116  while (list ($id,$current) = each($categories))
117  {
118    if ($current['id'] == $_GET['up'])
119        {
120          $current_rank = $current['rank'];
121          break;
122    }
123  }
124  if ($current_rank>1)
125  {
126    // 2. Exchanging ranks between the two categories
127    $query = 'UPDATE '.CATEGORIES_TABLE;
128    $query.= ' SET rank = '.($current_rank-1);
129    $query.= ' WHERE id = '.$_GET['up'];
130    $query.= ';';
131    mysql_query( $query );
132    $query = 'UPDATE '.CATEGORIES_TABLE;
133    $query.= ' SET rank = '.$current_rank;
134    $query.= ' WHERE id = '.$categories[($current_rank-1)]['id'];
135    $query.= ';';
136    mysql_query( $query );
137        // 3. Updating the cache array
138        $categories[$current_rank]=$categories[($current_rank-1)];
139        $categories[($current_rank-1)] = $current;
140  }
141  else
142  {
143    // 2. Updating the rank of our category to be after the previous max rank
144    $query = 'UPDATE '.CATEGORIES_TABLE;
145    $query.= ' SET rank = '.(count($categories) + 1);
146    $query.= ' WHERE id = '.$_GET['up'];
147    $query.= ';';
148    mysql_query( $query );
149    $query = 'UPDATE '.CATEGORIES_TABLE;
150    $query.= ' SET rank = rank-1';
151        $query.= ' WHERE id_uppercat ';
152        $query.= empty($_GET['parent_id'])?'IS NULL':('= '.$_GET['parent_id']);
153        $query.= ';';
154    mysql_query( $query );
155        // 3. Updating the cache array
156        array_push($categories, $current);
157        array_shift($categories);
158  }
159}
160elseif ( isset( $_GET['down'] ) && is_numeric( $_GET['down'] ) )
161{
162  // 1. searching the id of the category just above at the same level
163  while (list ($id,$current) = each($categories))
164  {
165    if ($current['id'] == $_GET['down'])
166        {
167          $current_rank = $current['rank'];
168          break;
169        }
170  }
171  if ($current_rank < count($categories))
172  {
173    // 2. Exchanging ranks between the two categories
174    $query = 'UPDATE '.CATEGORIES_TABLE;
175    $query.= ' SET rank = '.($current_rank+1);
176    $query.= ' WHERE id = '.$_GET['down'];
177    $query.= ';';
178    mysql_query( $query );
179    $query = 'UPDATE '.CATEGORIES_TABLE;
180    $query.= ' SET rank = '.$current_rank;
181    $query.= ' WHERE id = '.$categories[($current_rank+1)]['id'];
182    $query.= ';';
183    mysql_query( $query );
184        // 3. Updating the cache array
185        $categories[$current_rank]=$categories[($current_rank+1)];
186        $categories[($current_rank+1)] = $current;
187  }
188  else 
189  {
190    // 2. updating the rank of our category to be the first one
191    $query = 'UPDATE '.CATEGORIES_TABLE;
192    $query.= ' SET rank = 0';
193    $query.= ' WHERE id = '.$_GET['down'];
194    $query.= ';';
195    mysql_query( $query );
196    $query = 'UPDATE '.CATEGORIES_TABLE;
197    $query.= ' SET rank = (rank+1)';
198        $query.= ' WHERE id_uppercat ';
199        $query.= empty($_GET['parent_id'])?'IS NULL':('= '.$_GET['parent_id']);
200        $query.= ';';
201    mysql_query( $query );
202        // 3. Updating the cache array
203        array_unshift($categories, $current);
204        array_pop($categories);
205  }
206}
207reset($categories);
208
209//----------------------------------------------------- template initialization
210$template->set_filenames( array('categories'=>'admin/cat_list.tpl') );
211
212$template->assign_vars(array(
213  'CATEGORIES_NAV'=>$navigation,
214  'NEXT_RANK'=>count($categories)+1,
215 
216  'L_ADD_VIRTUAL'=>$lang['cat_add'],
217  'L_SUBMIT'=>$lang['submit'],
218  'L_STORAGE'=>$lang['storage'],
219  'L_NB_IMG'=>$lang['pictures'],
220  'L_MOVE_UP'=>$lang['cat_up'],
221  'L_MOVE_DOWN'=>$lang['cat_down'],
222  'L_EDIT'=>$lang['edit'],
223  'L_INFO_IMG'=>$lang['cat_image_info'],
224  'L_DELETE'=>$lang['delete']
225  ));
226 
227$tpl = array( 'cat_first','cat_last');
228                         
229//-------------------------------------------------------------- errors display
230if ( sizeof( $errors ) != 0 )
231{
232  $template->assign_block_vars('errors',array());
233  for ( $i = 0; $i < sizeof( $errors ); $i++ )
234  {
235    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
236  }
237}
238//----------------------------------------------------------- Categories display
239while (list ($id,$category) = each($categories))
240{
241
242  if ($category['visible'] == 'false')
243  {
244    $category_image = '<img src="'.PHPWG_ROOT_PATH.'template/'.$user['template'].'/admin/images/icon_folder_lock.gif"
245          alt="'.$lang['cat_private'].'" title="'.$lang['cat_private'].'"/>';
246  }
247  elseif (empty($category['dir']))
248  {
249    $category_image = '<img src="'.PHPWG_ROOT_PATH.'template/'.$user['template'].'/admin/images/icon_folder_link.gif"
250          alt="'.$lang['cat_virtual'].'" title="'.$lang['cat_virtual'].'"/>';
251  }
252  else
253  {
254        // May be should we have to introduce a computed field in the table to avoid this query
255    $query = 'SELECT COUNT(id) as sub_cats FROM ' . CATEGORIES_TABLE . ' WHERE id_uppercat = '.$category['id'];
256    $result = mysql_fetch_array(mysql_query( $query ));
257        $category_image = ($result['sub_cats']) ? 
258          '<img src="'.PHPWG_ROOT_PATH.'template/'.$user['template'].'/admin/images/icon_subfolder.gif" alt="" />' : 
259          '<img src="'.PHPWG_ROOT_PATH.'template/'.$user['template'].'/admin/images/icon_folder.gif" alt="" />';
260  }
261 
262  if ( !isset( $category['dir'] ) ) $category['dir'] = '';
263  $simple_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&amp;';
264  $url = $simple_url;
265  if (isset($_GET['parent_id']))
266    $url = $simple_url.'parent_id='.$_GET['parent_id'].'&amp;';
267
268  $template->assign_block_vars('category' ,array(
269    'CATEGORY_IMG'=>$category_image,
270    'CATEGORY_NAME'=>$category['name'],
271        'CATEGORY_DIR'=>$category['dir'],
272        'CATEGORY_NB_IMG'=>$category['nb_images'],
273       
274        'U_CATEGORY'=>add_session_id( $simple_url.'parent_id='.$category['id']),
275        'U_MOVE_UP'=>add_session_id( $url.'up='.$category['id'] ),
276        'U_MOVE_DOWN'=>add_session_id( $url.'down='.$category['id'] ),
277        'U_CAT_EDIT'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$category['id'] ),
278        'U_CAT_DELETE'=>add_session_id( $url.'delete='.$category['id'] ),
279        'U_INFO_IMG'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=infos_images&amp;cat_id='.$category['id'] ),
280        'U_CAT_UPDATE'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=update&amp;update='.$category['id'] )
281        ));
282       
283  if ( !empty($category['dir']))
284  {
285    $template->assign_block_vars('category.storage' ,array());
286  }
287  else
288  {
289        $template->assign_block_vars('category.virtual' ,array());
290  }
291  $url = add_session_id( PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat='.$row['id'] );
292  if ( $category['nb_images'] > 0 )
293  {
294    $template->assign_block_vars('category.image_info' ,array());
295  }
296  else
297  {
298    $template->assign_block_vars('category.no_image_info' ,array()); 
299  }
300}
301
302//----------------------------------------------------------- sending html code
303$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
304?>
Note: See TracBrowser for help on using the repository browser.