source: trunk/admin/cat_list.php @ 653

Last change on this file since 653 was 647, checked in by plg, 20 years ago
  • bug fixed : in admin/cat_list, next_rank cant' be calculted and query to count sub-categories per sub-categories became false if no sub-categories
  • virtual association come back in admin/infos_images (not only in admin/picture_modify)
  • check_favorites function in admin section becomes check_user_favorites in public section : favorites are checked when user tries to display his favorites. Function was optimized.
  • in function update_category, wrap of long queries due to many categories to update at the same time
  • typo fixed in description of paginate_pages_around configuration parameter
  • bug fixed in new navigation bar : no separation pipe was displayed between next and last when the page displayed was the last
  • sessions.expiration changed of type from int to datetime (a lot easier to read)
  • sessions.ip removed : IP address is no longer used to verify session
  • typo fixed in language/en_UK.iso-8859-1/admin.lang.php on editcat_lock_info language item
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.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-12-18 22:05:30 +0000 (Sat, 18 Dec 2004) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 647 $
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   
64    if ($parent_id != 'NULL')
65    {
66      $query = '
67SELECT id,uppercats,global_rank,visible,status
68  FROM '.CATEGORIES_TABLE.'
69  WHERE id = '.$parent_id.'
70;';
71      $row = mysql_fetch_array(pwg_query($query));
72      $parent = array('id' => $row['id'],
73                      'uppercats' => $row['uppercats'],
74                      'visible' => $row['visible'],
75                      'status' => $row['status'],
76                      'global_rank' => $row['global_rank']);
77    }
78
79    $insert = array();
80    $insert{'name'} = $_POST['virtual_name'];
81    $insert{'rank'} = $_POST['rank'];
82    $insert{'commentable'} = $conf['newcat_default_commentable'];
83    $insert{'uploadable'} = $conf['newcat_default_uploadable'];
84   
85    if (isset($parent))
86    {
87      $insert{'id_uppercat'} = $parent{'id'};
88      // at creation, must a category be visible or not ? Warning : if
89      // the parent category is invisible, the category is automatically
90      // create invisible. (invisible = locked)
91      if ('false' == $parent['visible'])
92      {
93        $insert{'visible'} = 'false';
94      }
95      else
96      {
97        $insert{'visible'} = $conf['newcat_default_visible'];
98      }
99      // at creation, must a category be public or private ? Warning :
100      // if the parent category is private, the category is
101      // automatically create private.
102      if ('private' == $parent['status'])
103      {
104        $insert{'status'} = 'private';
105      }
106      else
107      {
108        $insert{'status'} = $conf['newcat_default_status'];
109      }
110    }
111    else
112    {
113      $insert{'visible'} = $conf['newcat_default_visible'];
114      $insert{'status'} = $conf['newcat_default_status'];
115    }
116
117    $inserts = array($insert);
118   
119    // we have then to add the virtual category
120    $dbfields = array('site_id','name','id_uppercat','rank','commentable',
121                      'uploadable','visible','status');
122    mass_inserts(CATEGORIES_TABLE, $dbfields, $inserts);
123   
124    // And last we update the uppercats
125    $query = '
126SELECT MAX(id)
127  FROM '.CATEGORIES_TABLE.'
128;';
129    $my_id = array_pop(mysql_fetch_array(pwg_query($query)));
130
131    $query = '
132UPDATE '.CATEGORIES_TABLE;
133    if (isset($parent))
134    {
135      $query.= "
136  SET uppercats = CONCAT('".$parent['uppercats']."',',',id)
137    , global_rank = CONCAT('".$parent['global_rank']."','.',rank)";
138    }
139    else
140    {
141      $query.= '
142  SET uppercats = id
143    , global_rank = id';
144    }
145    $query.= '
146  WHERE id = '.$my_id.'
147;';
148    pwg_query($query);
149    array_push($infos, $lang['cat_virtual_added']);
150  }
151}
152// +-----------------------------------------------------------------------+
153// |                           Cache management                            |
154// +-----------------------------------------------------------------------+
155$query = '
156SELECT *
157  FROM '.CATEGORIES_TABLE;
158if (!isset($_GET['parent_id']))
159{
160  $query.= '
161  WHERE id_uppercat IS NULL';
162}
163else
164{
165  $query.= '
166  WHERE id_uppercat = '.$_GET['parent_id'];
167}
168$query.= '
169  ORDER BY rank ASC
170;';
171$result = pwg_query($query);
172while ($row = mysql_fetch_assoc($result))
173{
174  $categories[$row['rank']] = $row;
175  $categories[$row['rank']]['nb_subcats'] = 0;
176}
177// +-----------------------------------------------------------------------+
178// |                            Navigation path                            |
179// +-----------------------------------------------------------------------+
180if (isset($_GET['parent_id']))
181{
182  $base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
183 
184  $navigation = '<a class="" href="'.add_session_id($base_url).'">';
185  $navigation.= $lang['home'];
186  $navigation.= '</a>';
187  $navigation.= $conf['level_separator'];
188
189  $current_category = get_cat_info($_GET['parent_id']);
190  $navigation.= get_cat_display_name($current_category['name'],
191                                     $base_url.'&amp;parent_id=',
192                                     false);
193}
194// +-----------------------------------------------------------------------+
195// |                               rank updates                            |
196// +-----------------------------------------------------------------------+
197$current_rank = 0;
198if (isset($_GET['up']) and is_numeric($_GET['up']))
199{
200  // 1. searching the id of the category just above at the same level
201  while (list ($id,$current) = each($categories))
202  {
203    if ($current['id'] == $_GET['up'])
204    {
205      $current_rank = $current['rank'];
206      break;
207    }
208  }
209  if ($current_rank > 1)
210  {
211    // 2. Exchanging ranks between the two categories
212    $query = '
213UPDATE '.CATEGORIES_TABLE.'
214  SET rank = '.($current_rank-1).'
215  WHERE id = '.$_GET['up'].'
216;';
217    pwg_query($query);
218    $query = '
219UPDATE '.CATEGORIES_TABLE.'
220  SET rank = '.$current_rank.'
221  WHERE id = '.$categories[($current_rank-1)]['id'].'
222;';
223    pwg_query($query);
224    // 3. Updating the cache array
225    $categories[$current_rank] = $categories[($current_rank-1)];
226    $categories[($current_rank-1)] = $current;
227  }
228  else
229  {
230    // 2. Updating the rank of our category to be after the previous max rank
231    $query = '
232UPDATE '.CATEGORIES_TABLE.'
233  SET rank = '.(count($categories) + 1).'
234  WHERE id = '.$_GET['up'].'
235;';
236    pwg_query($query);
237    $query = '
238UPDATE '.CATEGORIES_TABLE.'
239  SET rank = rank-1
240  WHERE id_uppercat ';
241    if (empty($_GET['parent_id']))
242    {
243      $query.= 'IS NULL';
244    }
245    else
246    {
247      $query.= '= '.$_GET['parent_id'];
248    }
249    $query.= '
250;';
251    pwg_query($query);
252    // 3. Updating the cache array
253    array_push($categories, $current);
254    array_shift($categories);
255  }
256  update_global_rank(@$_GET['parent_id']);
257}
258else if (isset($_GET['down']) and is_numeric($_GET['down']))
259{
260  // 1. searching the id of the category just above at the same level
261  while (list ($id,$current) = each($categories))
262  {
263    if ($current['id'] == $_GET['down'])
264    {
265      $current_rank = $current['rank'];
266      break;
267    }
268  }
269  if ($current_rank < count($categories))
270  {
271    // 2. Exchanging ranks between the two categories
272    $query = '
273UPDATE '.CATEGORIES_TABLE.'
274  SET rank = '.($current_rank+1).'
275  WHERE id = '.$_GET['down'].'
276;';
277    pwg_query($query);
278    $query = '
279UPDATE '.CATEGORIES_TABLE.'
280  SET rank = '.$current_rank.'
281  WHERE id = '.$categories[($current_rank+1)]['id'].'
282;';
283    pwg_query($query);
284    // 3. Updating the cache array
285    $categories[$current_rank]=$categories[($current_rank+1)];
286    $categories[($current_rank+1)] = $current;
287  }
288  else 
289  {
290    // 2. updating the rank of our category to be the first one
291    $query = '
292UPDATE '.CATEGORIES_TABLE.'
293  SET rank = 0
294  WHERE id = '.$_GET['down'].'
295;';
296    pwg_query($query);
297    $query = '
298UPDATE '.CATEGORIES_TABLE.'
299  SET rank = rank+1
300  WHERE id_uppercat ';
301    if (empty($_GET['parent_id']))
302    {
303      $query.= 'IS NULL';
304    }
305    else
306    {
307      $query.= '= '.$_GET['parent_id'];
308    }
309    $query.= '
310;';
311    pwg_query($query);
312    // 3. Updating the cache array
313    array_unshift($categories, $current);
314    array_pop($categories);
315  }
316  update_global_rank(@$_GET['parent_id']);
317}
318reset($categories);
319// +-----------------------------------------------------------------------+
320// |                       template initialization                         |
321// +-----------------------------------------------------------------------+
322$template->set_filenames(array('categories'=>'admin/cat_list.tpl'));
323
324$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
325if (isset($_GET['parent_id']))
326{
327  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
328}
329
330if (count($categories) > 0)
331{
332  $next_rank = max(array_keys($categories)) + 1;
333}
334else
335{
336  $next_rank = 1;
337}
338
339$template->assign_vars(array(
340  'CATEGORIES_NAV'=>$navigation,
341  'NEXT_RANK'=>$next_rank,
342  'F_ACTION'=>$form_action,
343 
344  'L_ADD_VIRTUAL'=>$lang['cat_add'],
345  'L_SUBMIT'=>$lang['submit'],
346  'L_STORAGE'=>$lang['storage'],
347  'L_NB_IMG'=>$lang['pictures'],
348  'L_MOVE_UP'=>$lang['up'],
349  'L_MOVE_DOWN'=>$lang['down'],
350  'L_EDIT'=>$lang['edit'],
351  'L_INFO_IMG'=>$lang['cat_image_info'],
352  'L_DELETE'=>$lang['delete'],
353 ));
354 
355$tpl = array('cat_first','cat_last');
356// +-----------------------------------------------------------------------+
357// |                            errors & infos                             |
358// +-----------------------------------------------------------------------+
359if (count($errors) != 0)
360{
361  $template->assign_block_vars('errors',array());
362  foreach ($errors as $error)
363  {
364    $template->assign_block_vars('errors.error',array('ERROR'=>$error));
365  }
366}
367if (count($infos) != 0)
368{
369  $template->assign_block_vars('infos',array());
370  foreach ($infos as $info)
371  {
372    $template->assign_block_vars('infos.info',array('INFO'=>$info));
373  }
374}
375// +-----------------------------------------------------------------------+
376// |                          Categories display                           |
377// +-----------------------------------------------------------------------+
378$ranks = array();
379
380if (count($categories) > 0)
381{
382  foreach ($categories as $category)
383  {
384    $ranks[$category['id']] = $category['rank'];
385  }
386
387  $query = '
388SELECT id_uppercat, COUNT(*) AS nb_subcats
389  FROM '. CATEGORIES_TABLE.'
390  WHERE id_uppercat IN ('.implode(',', array_keys($ranks)).')
391  GROUP BY id_uppercat
392;';
393  $result = pwg_query($query);
394  while ($row = mysql_fetch_array($result))
395  {
396    $categories[$ranks[$row['id_uppercat']]]['nb_subcats']
397      = $row['nb_subcats'];
398  }
399}
400
401foreach ($categories as $category)
402{
403  $images_folder = PHPWG_ROOT_PATH.'template/';
404  $images_folder.= $user['template'].'/admin/images';
405 
406  if ($category['visible'] == 'false')
407  {
408    $image_src = $images_folder.'/icon_folder_lock.gif';
409    $image_alt = $lang['cat_private'];
410    $image_title = $lang['cat_private'];
411  }
412  else if (empty($category['dir']))
413  {
414    $image_src = $images_folder.'/icon_folder_link.gif';
415    $image_alt = $lang['cat_virtual'];
416    $image_title = $lang['cat_virtual'];
417  }
418  else
419  {
420    if ($category['nb_subcats'] > 0)
421    {
422      $image_src = $images_folder.'/icon_subfolder.gif';
423    }
424    else
425    {
426      $image_src = $images_folder.'/icon_folder.gif';
427    }
428    $image_alt = '';
429    $image_title = '';
430  }
431
432  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
433  $cat_list_url = $base_url.'cat_list';
434 
435  $self_url = $cat_list_url;
436  if (isset($_GET['parent_id']))
437  {
438    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
439  }
440
441  $template->assign_block_vars(
442    'category',
443    array(
444      'CATEGORY_IMG_SRC'=>$image_src,
445      'CATEGORY_IMG_ALT'=>$image_alt,
446      'CATEGORY_IMG_TITLE'=>$image_title,
447      'CATEGORY_NAME'=>$category['name'],
448      'CATEGORY_DIR'=>@$category['dir'],
449      'CATEGORY_NB_IMG'=>$category['nb_images'],
450     
451      'U_CATEGORY'=>
452      add_session_id($cat_list_url.'&amp;parent_id='.$category['id']),
453     
454      'U_MOVE_UP'=>add_session_id($self_url.'&amp;up='.$category['id']),
455     
456      'U_MOVE_DOWN'=>add_session_id($self_url.'&amp;down='.$category['id']),
457     
458      'U_CAT_EDIT'=>
459      add_session_id($base_url.'cat_modify&amp;cat_id='.$category['id']),
460     
461      'U_CAT_DELETE'=>add_session_id($self_url.'&amp;delete='.$category['id']),
462     
463      'U_INFO_IMG'
464      => add_session_id($base_url.'infos_images&amp;cat_id='.$category['id'])
465      ));
466 
467  if (!empty($category['dir']))
468  {
469    $template->assign_block_vars('category.storage' ,array());
470  }
471  else
472  {
473    $template->assign_block_vars('category.virtual' ,array());
474  }
475 
476  if ($category['nb_images'] > 0)
477  {
478    $template->assign_block_vars('category.image_info' ,array());
479  }
480  else
481  {
482    $template->assign_block_vars('category.no_image_info' ,array()); 
483  }
484}
485// +-----------------------------------------------------------------------+
486// |                          sending html code                            |
487// +-----------------------------------------------------------------------+
488$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
489?>
Note: See TracBrowser for help on using the repository browser.