source: trunk/admin/cat_list.php @ 1064

Last change on this file since 1064 was 1064, checked in by plg, 19 years ago

new feature: source/destination links between categories. Will we keep this
feature? Code is complicated and very few people will understand how it
works...

modification: #images.storage_category_id replaced by
#image_category.is_storage

improvement: many code refactoring to improve readibility

improvement: virtual category creation code was moved to a dedicated
function in order to be called from admin/cat_list.php and
admin/cat_modify.php (create a new destination category)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 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-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-03-04 23:31:46 +0000 (Sat, 04 Mar 2006) $
10// | last modifier : $Author: plg $
11// | revision      : $Revision: 1064 $
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// +-----------------------------------------------------------------------+
35// |                               functions                               |
36// +-----------------------------------------------------------------------+
37
38/**
39 * save the rank depending on given categories order
40 *
41 * The list of ordered categories id is supposed to be in the same parent
42 * category
43 *
44 * @param array categories
45 * @return void
46 */
47function save_categories_order($categories)
48{
49  $current_rank = 0;
50  $datas = array();
51  foreach ($categories as $id)
52  {
53    array_push($datas, array('id' => $id, 'rank' => ++$current_rank));
54  }
55  $fields = array('primary' => array('id'), 'update' => array('rank'));
56  mass_updates(CATEGORIES_TABLE, $fields, $datas);
57
58  update_global_rank(@$_GET['parent_id']);
59}
60
61// +-----------------------------------------------------------------------+
62// |                            initialization                             |
63// +-----------------------------------------------------------------------+
64
65$categories = array();
66
67$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
68$navigation = '<a class="" href="'.$base_url.'">';
69$navigation.= $lang['home'];
70$navigation.= '</a>';
71
72// +-----------------------------------------------------------------------+
73// |                    virtual categories management                      |
74// +-----------------------------------------------------------------------+
75// request to delete a virtual category
76if (isset($_GET['delete']) and is_numeric($_GET['delete']))
77{
78  delete_categories(array($_GET['delete']));
79  array_push($page['infos'], $lang['cat_virtual_deleted']);
80  ordering();
81  update_global_rank();
82}
83// request to add a virtual category
84else if (isset($_POST['submitAdd']))
85{
86  $output_create = create_virtual_category(
87    $_POST['virtual_name'],
88    @$_GET['parent_id']
89    );
90
91  if (isset($output_create['error']))
92  {
93    array_push($page['errors'], $output_create['error']);
94  }
95  else
96  {
97    array_push($page['infos'], $output_create['info']);
98  }
99}
100else if (isset($_POST['submitOrder']))
101{
102  asort($_POST['catOrd'], SORT_NUMERIC);
103  save_categories_order(array_keys($_POST['catOrd']));
104}
105// +-----------------------------------------------------------------------+
106// |                           Cache management                            |
107// +-----------------------------------------------------------------------+
108$query = '
109SELECT *
110  FROM '.CATEGORIES_TABLE;
111if (!isset($_GET['parent_id']))
112{
113  $query.= '
114  WHERE id_uppercat IS NULL';
115}
116else
117{
118  $query.= '
119  WHERE id_uppercat = '.$_GET['parent_id'];
120}
121$query.= '
122  ORDER BY rank ASC
123;';
124$result = pwg_query($query);
125while ($row = mysql_fetch_assoc($result))
126{
127  $categories[$row['rank']] = $row;
128  $categories[$row['rank']]['nb_subcats'] = 0;
129}
130
131// +-----------------------------------------------------------------------+
132// |                            Navigation path                            |
133// +-----------------------------------------------------------------------+
134
135if (isset($_GET['parent_id']))
136{
137  $navigation.= $conf['level_separator'];
138
139  $current_category = get_cat_info($_GET['parent_id']);
140 
141  $navigation.= get_cat_display_name(
142    $current_category['name'],
143    $base_url.'&amp;parent_id=',
144    false
145    );
146}
147// +-----------------------------------------------------------------------+
148// |                       template initialization                         |
149// +-----------------------------------------------------------------------+
150$template->set_filenames(array('categories'=>'admin/cat_list.tpl'));
151
152$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
153if (isset($_GET['parent_id']))
154{
155  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
156}
157
158$template->assign_vars(array(
159  'CATEGORIES_NAV'=>$navigation,
160  'F_ACTION'=>$form_action,
161 
162  'L_ADD_VIRTUAL'=>$lang['cat_add'],
163  'L_SUBMIT'=>$lang['submit'],
164  'L_STORAGE'=>$lang['storage'],
165  'L_NB_IMG'=>$lang['pictures'],
166  'L_MOVE_UP'=>$lang['up'],
167  'L_EDIT'=>$lang['edit'],
168  'L_DELETE'=>$lang['delete'],
169 ));
170 
171$tpl = array('cat_first','cat_last');
172// +-----------------------------------------------------------------------+
173// |                          Categories display                           |
174// +-----------------------------------------------------------------------+
175
176$categories = array();
177
178$query = '
179SELECT id, name, dir, rank, nb_images, status
180  FROM '.CATEGORIES_TABLE;
181if (!isset($_GET['parent_id']))
182{
183  $query.= '
184  WHERE id_uppercat IS NULL';
185}
186else
187{
188  $query.= '
189  WHERE id_uppercat = '.$_GET['parent_id'];
190}
191$query.= '
192  ORDER BY rank ASC
193;';
194$result = pwg_query($query);
195while ($row = mysql_fetch_array($result))
196{
197  $categories[$row['id']] = $row;
198  // by default, let's consider there is no sub-categories. This will be
199  // calculated after.
200  $categories[$row['id']]['nb_subcats'] = 0;
201}
202
203if (count($categories) > 0)
204{
205  $query = '
206SELECT id_uppercat, COUNT(*) AS nb_subcats
207  FROM '. CATEGORIES_TABLE.'
208  WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
209  GROUP BY id_uppercat
210;';
211  $result = pwg_query($query);
212  while ($row = mysql_fetch_array($result))
213  {
214    $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
215  }
216}
217
218foreach ($categories as $category)
219{
220  // TODO : not used anymore ?
221  //$images_folder = PHPWG_ROOT_PATH.'template/';
222  //$images_folder.= $user['template'].'/admin/images';
223 
224  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
225  $cat_list_url = $base_url.'cat_list';
226 
227  $self_url = $cat_list_url;
228  if (isset($_GET['parent_id']))
229  {
230    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
231  }
232
233  $template->assign_block_vars(
234    'category',
235    array(
236      'NAME'=>$category['name'],
237      'ID'=>$category['id'],
238      'RANK'=>$category['rank']*10,
239
240      'U_JUMPTO'=>PHPWG_ROOT_PATH.'category.php?cat='.$category['id'],
241      'U_CHILDREN'=>$cat_list_url.'&amp;parent_id='.$category['id'],     
242      'U_EDIT'=>$base_url.'cat_modify&amp;cat_id='.$category['id']
243      )
244    );
245 
246  if (empty($category['dir']))
247  {
248    $template->assign_block_vars(
249      'category.delete',
250      array(
251        'URL'=>$self_url.'&amp;delete='.$category['id']
252        )
253      );
254  }
255 
256  if ($category['nb_images'] > 0)
257  {
258    $template->assign_block_vars(
259      'category.elements',
260      array(
261        'URL'=>$base_url.'element_set&amp;cat='.$category['id']
262        )
263      );
264  }
265
266  if ('private' == $category['status'])
267  {
268    $template->assign_block_vars(
269      'category.permissions',
270      array(
271        'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
272        )
273      );
274  }
275}
276// +-----------------------------------------------------------------------+
277// |                          sending html code                            |
278// +-----------------------------------------------------------------------+
279$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
280?>
Note: See TracBrowser for help on using the repository browser.