source: trunk/admin/cat_list.php @ 608

Last change on this file since 608 was 608, checked in by gweltas, 20 years ago

Categories management icon update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 12.6 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2004 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2004-11-18 15:17:33 +0000 (Thu, 18 Nov 2004) $
10// | last modifier : $Author: gweltas $
11// | revision      : $Revision: 608 $
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// |                            initialization                             |
35// +-----------------------------------------------------------------------+
36$errors = array();
37$infos = array();
38$categories = array();
39$navigation = $lang['home'];
40// +-----------------------------------------------------------------------+
41// |                    virtual categories management                      |
42// +-----------------------------------------------------------------------+
43// request to delete a virtual category
44if (isset($_GET['delete']) and is_numeric($_GET['delete']))
45{
46  $to_delete_categories = array();
47  array_push($to_delete_categories,$_GET['delete']);
48  delete_categories($to_delete_categories);
49  array_push($infos, $lang['cat_virtual_deleted']);
50}
51// request to add a virtual category
52else if (isset($_POST['submit']))
53{
54  // is the given category name only containing blank spaces ?
55  if (preg_match('/^\s*$/', $_POST['virtual_name']))
56  {
57    array_push($errors, $lang['cat_error_name']);
58  }
59       
60  if (!count($errors))
61  {
62    $parent_id = !empty($_GET['parent_id'])?$_GET['parent_id']:'NULL'; 
63    // As we don't create a virtual category every day, let's do (far) too
64    // much queries
65    if ($parent_id != 'NULL')
66    {
67      $query = '
68SELECT uppercats
69  FROM '.CATEGORIES_TABLE.'
70  WHERE id = '.$parent_id.'
71;';
72      $parent_uppercats = array_pop(mysql_fetch_array(pwg_query($query)));
73    }
74       
75    // we have then to add the virtual category
76    $query = '
77INSERT INTO '.CATEGORIES_TABLE.'
78  (name,id_uppercat,rank,site_id)
79  VALUES
80  (\''.$_POST['virtual_name'].'\','.$parent_id.','.$_POST['rank'].',NULL)
81;';
82    pwg_query($query);
83       
84    // And last we update the uppercats
85    $query = '
86SELECT MAX(id)
87  FROM '.CATEGORIES_TABLE.'
88;';
89    $my_id = array_pop(mysql_fetch_array(pwg_query($query)));
90
91    $query = '
92UPDATE '.CATEGORIES_TABLE.'
93  SET uppercats = \'';
94    if (!empty($parent_uppercats))
95    {
96      $query.= $parent_uppercats.',';
97    }
98    $query.= $my_id;
99    $query.= '\'
100  WHERE id = '.$my_id.'
101;';
102    pwg_query($query);
103    array_push($infos, $lang['cat_virtual_added']);
104  }
105}
106// +-----------------------------------------------------------------------+
107// |                           Cache management                            |
108// +-----------------------------------------------------------------------+
109$query = '
110SELECT *
111  FROM '.CATEGORIES_TABLE;
112if (!isset($_GET['parent_id']))
113{
114  $query.= '
115  WHERE id_uppercat IS NULL';
116}
117else
118{
119  $query.= '
120  WHERE id_uppercat = '.$_GET['parent_id'];
121}
122$query.= '
123  ORDER BY rank ASC
124;';
125$result = pwg_query($query);
126while ($row = mysql_fetch_assoc($result))
127{
128  $categories[$row['rank']] = $row;
129}
130// +-----------------------------------------------------------------------+
131// |                            Navigation path                            |
132// +-----------------------------------------------------------------------+
133if (isset($_GET['parent_id']))
134{
135  $separator = ' -&gt; ';
136  $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
137 
138  $navigation = '<a class="" href="'.add_session_id($base_url).'">';
139  $navigation.= $lang['home'];
140  $navigation.= '</a>';
141  $navigation.= $separator;
142
143  $current_category = get_cat_info($_GET['parent_id']);
144  $navigation.= get_cat_display_name($current_category['name'],
145                                     $separator,
146                                     $base_url.'&amp;parent_id=',
147                                     false);
148}
149// +-----------------------------------------------------------------------+
150// |                               rank updates                            |
151// +-----------------------------------------------------------------------+
152$current_rank = 0;
153if (isset($_GET['up']) and is_numeric($_GET['up']))
154{
155  // 1. searching the id of the category just above at the same level
156  while (list ($id,$current) = each($categories))
157  {
158    if ($current['id'] == $_GET['up'])
159    {
160      $current_rank = $current['rank'];
161      break;
162    }
163  }
164  if ($current_rank > 1)
165  {
166    // 2. Exchanging ranks between the two categories
167    $query = '
168UPDATE '.CATEGORIES_TABLE.'
169  SET rank = '.($current_rank-1).'
170  WHERE id = '.$_GET['up'].'
171;';
172    pwg_query($query);
173    $query = '
174UPDATE '.CATEGORIES_TABLE.'
175  SET rank = '.$current_rank.'
176  WHERE id = '.$categories[($current_rank-1)]['id'].'
177;';
178    pwg_query($query);
179    // 3. Updating the cache array
180    $categories[$current_rank] = $categories[($current_rank-1)];
181    $categories[($current_rank-1)] = $current;
182  }
183  else
184  {
185    // 2. Updating the rank of our category to be after the previous max rank
186    $query = '
187UPDATE '.CATEGORIES_TABLE.'
188  SET rank = '.(count($categories) + 1).'
189  WHERE id = '.$_GET['up'].'
190;';
191    pwg_query($query);
192    $query = '
193UPDATE '.CATEGORIES_TABLE.'
194  SET rank = rank-1
195  WHERE id_uppercat ';
196    if (empty($_GET['parent_id']))
197    {
198      $query.= 'IS NULL';
199    }
200    else
201    {
202      $query.= '= '.$_GET['parent_id'];
203    }
204    $query.= '
205;';
206    pwg_query($query);
207    // 3. Updating the cache array
208    array_push($categories, $current);
209    array_shift($categories);
210  }
211}
212else if (isset($_GET['down']) and is_numeric($_GET['down']))
213{
214  // 1. searching the id of the category just above at the same level
215  while (list ($id,$current) = each($categories))
216  {
217    if ($current['id'] == $_GET['down'])
218    {
219      $current_rank = $current['rank'];
220      break;
221    }
222  }
223  if ($current_rank < count($categories))
224  {
225    // 2. Exchanging ranks between the two categories
226    $query = '
227UPDATE '.CATEGORIES_TABLE.'
228  SET rank = '.($current_rank+1).'
229  WHERE id = '.$_GET['down'].'
230;';
231    pwg_query($query);
232    $query = '
233UPDATE '.CATEGORIES_TABLE.'
234  SET rank = '.$current_rank.'
235  WHERE id = '.$categories[($current_rank+1)]['id'].'
236;';
237    pwg_query($query);
238    // 3. Updating the cache array
239    $categories[$current_rank]=$categories[($current_rank+1)];
240    $categories[($current_rank+1)] = $current;
241  }
242  else 
243  {
244    // 2. updating the rank of our category to be the first one
245    $query = '
246UPDATE '.CATEGORIES_TABLE.'
247  SET rank = 0
248  WHERE id = '.$_GET['down'].'
249;';
250    pwg_query($query);
251    $query = '
252UPDATE '.CATEGORIES_TABLE.'
253  SET rank = rank+1
254  WHERE id_uppercat ';
255    if (empty($_GET['parent_id']))
256    {
257      $query.= 'IS NULL';
258    }
259    else
260    {
261      $query.= '= '.$_GET['parent_id'];
262    }
263    $query.= '
264;';
265    pwg_query($query);
266    // 3. Updating the cache array
267    array_unshift($categories, $current);
268    array_pop($categories);
269  }
270}
271reset($categories);
272// +-----------------------------------------------------------------------+
273// |                       template initialization                         |
274// +-----------------------------------------------------------------------+
275$template->set_filenames(array('categories'=>'admin/cat_list.tpl'));
276
277$template->assign_vars(array(
278  'CATEGORIES_NAV'=>$navigation,
279  'NEXT_RANK'=>count($categories)+1,
280 
281  'L_ADD_VIRTUAL'=>$lang['cat_add'],
282  'L_SUBMIT'=>$lang['submit'],
283  'L_STORAGE'=>$lang['storage'],
284  'L_NB_IMG'=>$lang['pictures'],
285  'L_MOVE_UP'=>$lang['cat_up'],
286  'L_MOVE_DOWN'=>$lang['cat_down'],
287  'L_EDIT'=>$lang['edit'],
288  'L_INFO_IMG'=>$lang['cat_image_info'],
289  'L_DELETE'=>$lang['delete'],
290 ));
291 
292$tpl = array('cat_first','cat_last');
293// +-----------------------------------------------------------------------+
294// |                            errors & infos                             |
295// +-----------------------------------------------------------------------+
296if (count($errors) != 0)
297{
298  $template->assign_block_vars('errors',array());
299  foreach ($errors as $error)
300  {
301    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
302  }
303}
304if (count($infos) != 0)
305{
306  $template->assign_block_vars('infos',array());
307  foreach ($infos as $info)
308  {
309    $template->assign_block_vars('infos.info',array('INFO'=>$info));
310  }
311}
312// +-----------------------------------------------------------------------+
313// |                          Categories display                           |
314// +-----------------------------------------------------------------------+
315while (list($id,$category) = each($categories))
316{
317  $images_folder = PHPWG_ROOT_PATH.'template/';
318  $images_folder.= $user['template'].'/admin/images';
319 
320  if ($category['visible'] == 'false')
321  {
322    $image_src = $images_folder.'/icon_folder_lock.gif';
323    $image_alt = $lang['cat_private'];
324    $image_title = $lang['cat_private'];
325  }
326  else if (empty($category['dir']))
327  {
328    $image_src = $images_folder.'/icon_folder_link.gif';
329    $image_alt = $lang['cat_virtual'];
330    $image_title = $lang['cat_virtual'];
331  }
332  else
333  {
334    // (Gweltas) May be should we have to introduce a computed field in the
335    // table to avoid this query -> (z0rglub) no because the number of
336    // sub-categories depends on permissions
337    $query = '
338SELECT COUNT(id) AS nb_sub_cats
339  FROM '. CATEGORIES_TABLE.'
340  WHERE id_uppercat = '.$category['id'].'
341;';
342    $row = mysql_fetch_array(pwg_query($query));
343
344    if ($row['nb_sub_cats'] > 0)
345    {
346      $image_src = $images_folder.'/icon_subfolder.gif';
347    }
348    else
349    {
350      $image_src = $images_folder.'/icon_folder.gif';
351    }
352    $image_alt = '';
353    $image_title = '';
354  }
355
356  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
357  $cat_list_url = $base_url.'cat_list';
358 
359  $self_url = $cat_list_url;
360  if (isset($_GET['parent_id']))
361  {
362    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
363  }
364
365  $template->assign_block_vars(
366    'category',
367    array(
368      'CATEGORY_IMG_SRC'=>$image_src,
369      'CATEGORY_IMG_ALT'=>$image_alt,
370      'CATEGORY_IMG_TITLE'=>$image_title,
371      'CATEGORY_NAME'=>$category['name'],
372      'CATEGORY_DIR'=>@$category['dir'],
373      'CATEGORY_NB_IMG'=>$category['nb_images'],
374     
375      'U_CATEGORY'=>
376      add_session_id($cat_list_url.'&amp;parent_id='.$category['id']),
377     
378      'U_MOVE_UP'=>add_session_id($self_url.'&amp;up='.$category['id']),
379     
380      'U_MOVE_DOWN'=>add_session_id($self_url.'&amp;down='.$category['id']),
381     
382      'U_CAT_EDIT'=>
383      add_session_id($base_url.'cat_modify&amp;cat_id='.$category['id']),
384     
385      'U_CAT_DELETE'=>add_session_id($self_url.'&amp;delete='.$category['id']),
386     
387      'U_INFO_IMG'
388      => add_session_id($base_url.'infos_images&amp;cat_id='.$category['id'])
389      ));
390 
391  if (!empty($category['dir']))
392  {
393    $template->assign_block_vars('category.storage' ,array());
394  }
395  else
396  {
397    $template->assign_block_vars('category.virtual' ,array());
398  }
399 
400  if ($category['nb_images'] > 0)
401  {
402    $template->assign_block_vars('category.image_info' ,array());
403  }
404  else
405  {
406    $template->assign_block_vars('category.no_image_info' ,array()); 
407  }
408}
409// +-----------------------------------------------------------------------+
410// |                          sending html code                            |
411// +-----------------------------------------------------------------------+
412$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
413?>
Note: See TracBrowser for help on using the repository browser.