source: trunk/admin/cat_list.php @ 394

Last change on this file since 394 was 394, checked in by gweltas, 20 years ago
  • Template migration
  • Admin Control Panel migration
  • Category management
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 10.1 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-03-26 17:08:09 +0000 (Fri, 26 Mar 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 394 $
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  delete_category( $_GET['delete'] );
42  synchronize_all_users();
43}
44elseif ( isset( $_POST['submit'] ) )
45{
46  // is the given category name only containing blank spaces ?
47  if ( preg_match( '/^\s*$/', $_POST['virtual_name'] ) )
48    array_push( $errors, $lang['cat_error_name'] );
49       
50  if ( !count( $errors ))
51  {
52    // we have then to add the virtual category
53        $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; 
54    $query = 'INSERT INTO '.CATEGORIES_TABLE;
55    $query.= ' (name,id_uppercat,rank) VALUES ';
56    $query.= " ('".$_POST['virtual_name']."',".$parent_id.",".$_POST['rank'].")";
57    $query.= ';';
58    mysql_query( $query );
59    synchronize_all_users();
60  }
61}
62
63// Cache management
64
65$query = 'SELECT * FROM '.CATEGORIES_TABLE;
66if ( !isset($_GET['parent_id']))
67{
68  $query.= ' WHERE id_uppercat IS NULL';
69}
70else
71{
72  $query.= ' WHERE id_uppercat = '.$_GET['parent_id'];
73}
74$query.= ' ORDER BY rank ASC';
75$query.= ';';
76$result = mysql_query( $query );
77while ( $row = mysql_fetch_assoc( $result ) )
78{
79  $categories[$row['rank']]=$row;
80}
81
82// Navigation path
83if (isset($_GET['parent_id']))
84{
85  $current_category = get_cat_info($_GET['parent_id']);
86  $url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&amp;parent_id=';
87  $navigation = '<a class="" href="'.add_session_id(PHPWG_ROOT_PATH.'admin.php?page=cat_list').'">';
88  $navigation.= $lang['gallery_index'].'</a>-&gt;';
89  $navigation.= get_cat_display_name($current_category['name'], '-&gt;', $url);
90}
91
92//---------------------------------------------------------------  rank updates
93$current_rank=0;
94if ( isset( $_GET['up'] ) && is_numeric( $_GET['up'] ))
95{
96  // 1. searching the id of the category just above at the same level
97  while (list ($id,$current) = each($categories))
98  {
99    if ($current['id'] == $_GET['up'])
100        {
101          $current_rank = $current['rank'];
102          break;
103    }
104  }
105  if ($current_rank>1)
106  {
107    // 2. Exchanging ranks between the two categories
108    $query = 'UPDATE '.CATEGORIES_TABLE;
109    $query.= ' SET rank = '.($current_rank-1);
110    $query.= ' WHERE id = '.$_GET['up'];
111    $query.= ';';
112    mysql_query( $query );
113    $query = 'UPDATE '.CATEGORIES_TABLE;
114    $query.= ' SET rank = '.$current_rank;
115    $query.= ' WHERE id = '.$categories[($current_rank-1)]['id'];
116    $query.= ';';
117    mysql_query( $query );
118        // 3. Updating the cache array
119        $categories[$current_rank]=$categories[($current_rank-1)];
120        $categories[($current_rank-1)] = $current;
121  }
122  else
123  {
124    // 2. Updating the rank of our category to be after the previous max rank
125    $query = 'UPDATE '.CATEGORIES_TABLE;
126    $query.= ' SET rank = '.(count($categories) + 1);
127    $query.= ' WHERE id = '.$_GET['up'];
128    $query.= ';';
129    mysql_query( $query );
130    $query = 'UPDATE '.CATEGORIES_TABLE;
131    $query.= ' SET rank = rank-1';
132        $query.= ' WHERE id_uppercat ';
133        $query.= empty($_GET['parent_id'])?'IS NULL':('= '.$_GET['parent_id']);
134        $query.= ';';
135    mysql_query( $query );
136        // 3. Updating the cache array
137        array_push($categories, $current);
138        array_shift($categories);
139  }
140}
141elseif ( isset( $_GET['down'] ) && is_numeric( $_GET['down'] ) )
142{
143  // 1. searching the id of the category just above at the same level
144  while (list ($id,$current) = each($categories))
145  {
146    if ($current['id'] == $_GET['down'])
147        {
148          $current_rank = $current['rank'];
149          break;
150        }
151  }
152  if ($current_rank < count($categories))
153  {
154    // 2. Exchanging ranks between the two categories
155    $query = 'UPDATE '.CATEGORIES_TABLE;
156    $query.= ' SET rank = '.($current_rank+1);
157    $query.= ' WHERE id = '.$_GET['down'];
158    $query.= ';';
159    mysql_query( $query );
160    $query = 'UPDATE '.CATEGORIES_TABLE;
161    $query.= ' SET rank = '.$current_rank;
162    $query.= ' WHERE id = '.$categories[($current_rank+1)]['id'];
163    $query.= ';';
164    mysql_query( $query );
165        // 3. Updating the cache array
166        $categories[$current_rank]=$categories[($current_rank+1)];
167        $categories[($current_rank+1)] = $current;
168  }
169  else 
170  {
171    // 2. updating the rank of our category to be the first one
172    $query = 'UPDATE '.CATEGORIES_TABLE;
173    $query.= ' SET rank = 0';
174    $query.= ' WHERE id = '.$_GET['down'];
175    $query.= ';';
176    mysql_query( $query );
177    $query = 'UPDATE '.CATEGORIES_TABLE;
178    $query.= ' SET rank = (rank+1)';
179        $query.= ' WHERE id_uppercat ';
180        $query.= empty($_GET['parent_id'])?'IS NULL':('= '.$_GET['parent_id']);
181        $query.= ';';
182    mysql_query( $query );
183        // 3. Updating the cache array
184        array_unshift($categories, $current);
185        array_pop($categories);
186  }
187}
188reset($categories);
189
190//----------------------------------------------------- template initialization
191$template->set_filenames( array('categories'=>'admin/cat_list.tpl') );
192
193$template->assign_vars(array(
194  'CATEGORIES_NAV'=>$navigation,
195  'NEXT_RANK'=>count($categories)+1,
196 
197  'L_ADD_VIRTUAL'=>$lang['cat_add'],
198  'L_SUBMIT'=>$lang['submit'],
199  'L_STORAGE'=>$lang['storage'],
200  'L_NB_IMG'=>$lang['pictures'],
201  'L_MOVE_UP'=>$lang['cat_up'],
202  'L_MOVE_DOWN'=>$lang['cat_down'],
203  'L_EDIT'=>$lang['edit'],
204  'L_INFO_IMG'=>$lang['cat_image_info'],
205  'L_DELETE'=>$lang['delete']
206  ));
207 
208$tpl = array( 'cat_first','cat_last');
209                         
210//-------------------------------------------------------------- errors display
211if ( sizeof( $errors ) != 0 )
212{
213  $template->assign_block_vars('errors',array());
214  for ( $i = 0; $i < sizeof( $errors ); $i++ )
215  {
216    $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i]));
217  }
218}
219//----------------------------------------------------------- Categories display
220while (list ($id,$category) = each($categories))
221{
222
223  if ($category['status'] == 'private')
224  {
225    $category_image = '<img src="'.PHPWG_ROOT_PATH.'template/'.$user['template'].'/admin/images/icon_folder_lock.gif"
226          width="46" height="25" alt="'.$lang['cat_private'].'" title="'.$lang['cat_private'].'"/>';
227  }
228  elseif (empty($category['dir']))
229  {
230    $category_image = '<img src="'.PHPWG_ROOT_PATH.'template/'.$user['template'].'/admin/images/icon_folder_link.gif"
231          width="46" height="25" alt="'.$lang['cat_virtual'].'" title="'.$lang['cat_virtual'].'"/>';
232  }
233  else
234  {
235        // May be should we have to introduce a computed field in the table to avoid this query
236    $query = 'SELECT COUNT(id) as sub_cats FROM ' . CATEGORIES_TABLE . ' WHERE id_uppercat = '.$category['id'];
237    $result = mysql_fetch_array(mysql_query( $query ));
238        $category_image = ($result['sub_cats']) ? 
239          '<img src="'.PHPWG_ROOT_PATH.'template/'.$user['template'].'/admin/images/icon_subfolder.gif" width="46" height="25" alt="" />' : 
240          '<img src="'.PHPWG_ROOT_PATH.'template/'.$user['template'].'/admin/images/icon_folder.gif" width="46" height="25" alt="" />';
241  }
242 
243  if ( !isset( $category['dir'] ) ) $category['dir'] = '';
244  $simple_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list&amp;';
245  $url = $simple_url;
246  if (isset($_GET['parent_id']))
247    $url = $simple_url.'parent_id='.$_GET['parent_id'].'&amp;';
248
249  $template->assign_block_vars('category' ,array(
250    'CATEGORY_IMG'=>$category_image,
251    'CATEGORY_NAME'=>$category['name'],
252        'CATEGORY_DIR'=>$category['dir'],
253        'CATEGORY_NB_IMG'=>$category['nb_images'],
254       
255        'U_CATEGORY'=>add_session_id( $simple_url.'parent_id='.$category['id']),
256        'U_MOVE_UP'=>add_session_id( $url.'up='.$category['id'] ),
257        'U_MOVE_DOWN'=>add_session_id( $url.'down='.$category['id'] ),
258        'U_CAT_EDIT'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=cat_modify&amp;cat_id='.$row['id'] ),
259        'U_CAT_DELETE'=>add_session_id( $url.'delete='.$category['id'] ),
260        'U_INFO_IMG'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=infos_images&amp;cat_id='.$row['id'] ),
261        'U_CAT_UPDATE'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=update&amp;update='.$row['id'] )
262        ));
263       
264  if ( !empty($category['dir']))
265  {
266    $template->assign_block_vars('category.storage' ,array());
267  }
268  else
269  {
270        $template->assign_block_vars('category.virtual' ,array());
271  }
272  $url = add_session_id( './admin.php?page=cat_modify&amp;cat='.$row['id'] );
273  if ( $category['nb_images'] > 0 )
274  {
275    $template->assign_block_vars('category.image_info' ,array());
276  }
277  else
278  {
279    $template->assign_block_vars('category.no_image_info' ,array()); 
280  }
281}
282
283//----------------------------------------------------------- sending html code
284$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
285?>
Note: See TracBrowser for help on using the repository browser.