source: trunk/admin/cat_list.php @ 1861

Last change on this file since 1861 was 1861, checked in by rvelices, 17 years ago
  • refactoring pagecategory before 1.7 release

pagecategory is not an id anymore, but an associative array of category info
all of pagecat_xxx or pageuppercats merged into one
simplifies calls to make_index_url
give plugins a clean start for page variables for version 1.7

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.9 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-2007 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: cat_list.php 1861 2007-02-27 01:56:16Z rvelices $
8// | last update   : $Date: 2007-02-27 01:56:16 +0000 (Tue, 27 Feb 2007) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 1861 $
11// +-----------------------------------------------------------------------+
12// | This program is free software; you can redistribute it and/or modify  |
13// | it under the terms of the GNU General Public License as published by  |
14// | the Free Software Foundation                                          |
15// |                                                                       |
16// | This program is distributed in the hope that it will be useful, but   |
17// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
18// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
19// | General Public License for more details.                              |
20// |                                                                       |
21// | You should have received a copy of the GNU General Public License     |
22// | along with this program; if not, write to the Free Software           |
23// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
24// | USA.                                                                  |
25// +-----------------------------------------------------------------------+
26
27if (!defined('PHPWG_ROOT_PATH'))
28{
29  die('Hacking attempt!');
30}
31
32include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
33
34// +-----------------------------------------------------------------------+
35// | Check Access and exit when user status is not ok                      |
36// +-----------------------------------------------------------------------+
37check_status(ACCESS_ADMINISTRATOR);
38
39// +-----------------------------------------------------------------------+
40// |                               functions                               |
41// +-----------------------------------------------------------------------+
42
43/**
44 * save the rank depending on given categories order
45 *
46 * The list of ordered categories id is supposed to be in the same parent
47 * category
48 *
49 * @param array categories
50 * @return void
51 */
52function save_categories_order($categories)
53{
54  $current_rank = 0;
55  $datas = array();
56  foreach ($categories as $id)
57  {
58    array_push($datas, array('id' => $id, 'rank' => ++$current_rank));
59  }
60  $fields = array('primary' => array('id'), 'update' => array('rank'));
61  mass_updates(CATEGORIES_TABLE, $fields, $datas);
62
63  update_global_rank(@$_GET['parent_id']);
64}
65
66// +-----------------------------------------------------------------------+
67// |                            initialization                             |
68// +-----------------------------------------------------------------------+
69
70$categories = array();
71
72$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
73$navigation = '<a class="" href="'.$base_url.'">';
74$navigation.= $lang['home'];
75$navigation.= '</a>';
76
77// +-----------------------------------------------------------------------+
78// |                    virtual categories management                      |
79// +-----------------------------------------------------------------------+
80// request to delete a virtual category / not for an adviser
81if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
82{
83  delete_categories(array($_GET['delete']));
84  array_push($page['infos'], $lang['cat_virtual_deleted']);
85  ordering();
86  update_global_rank();
87}
88// request to add a virtual category
89else if (isset($_POST['submitAdd']))
90{
91  $output_create = create_virtual_category(
92    $_POST['virtual_name'],
93    @$_GET['parent_id']
94    );
95
96  if (isset($output_create['error']))
97  {
98    array_push($page['errors'], $output_create['error']);
99  }
100  else
101  {
102    array_push($page['infos'], $output_create['info']);
103  }
104}
105// save manual category ordering
106else if (isset($_POST['submitOrder']))
107{
108  asort($_POST['catOrd'], SORT_NUMERIC);
109  save_categories_order(array_keys($_POST['catOrd']));
110
111  array_push(
112    $page['infos'],
113    l10n('Categories manual order was saved')
114    );
115}
116// sort categories alpha-numerically
117else if (isset($_POST['submitOrderAlphaNum']))
118{
119  $query = '
120SELECT id, name
121  FROM '.CATEGORIES_TABLE.'
122  WHERE id_uppercat '.
123    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
124;';
125  $result = pwg_query($query);
126  while ($row = mysql_fetch_assoc($result))
127  {
128    $categories[ $row['id'] ] = strtolower($row['name']);
129  }
130
131  asort($categories, SORT_REGULAR);
132  save_categories_order(array_keys($categories));
133
134  array_push(
135    $page['infos'],
136    l10n('Categories ordered alphanumerically')
137    );
138}
139
140// +-----------------------------------------------------------------------+
141// |                           Cache management                            |
142// +-----------------------------------------------------------------------+
143$query = '
144SELECT *
145  FROM '.CATEGORIES_TABLE;
146if (!isset($_GET['parent_id']))
147{
148  $query.= '
149  WHERE id_uppercat IS NULL';
150}
151else
152{
153  $query.= '
154  WHERE id_uppercat = '.$_GET['parent_id'];
155}
156$query.= '
157  ORDER BY rank ASC
158;';
159$result = pwg_query($query);
160while ($row = mysql_fetch_assoc($result))
161{
162  $categories[$row['rank']] = $row;
163  $categories[$row['rank']]['nb_subcats'] = 0;
164}
165
166// +-----------------------------------------------------------------------+
167// |                            Navigation path                            |
168// +-----------------------------------------------------------------------+
169
170if (isset($_GET['parent_id']))
171{
172  $navigation.= $conf['level_separator'];
173
174  $navigation.= get_cat_display_name_from_id(
175    $_GET['parent_id'],
176    $base_url.'&amp;parent_id=',
177    false
178    );
179}
180// +-----------------------------------------------------------------------+
181// |                       template initialization                         |
182// +-----------------------------------------------------------------------+
183$template->set_filenames(array('categories'=>'admin/cat_list.tpl'));
184
185$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
186if (isset($_GET['parent_id']))
187{
188  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
189}
190
191$template->assign_vars(array(
192  'CATEGORIES_NAV'=>$navigation,
193  'F_ACTION'=>$form_action,
194
195  'L_ADD_VIRTUAL'=>$lang['cat_add'],
196  'L_SUBMIT'=>$lang['submit'],
197  'L_STORAGE'=>$lang['storage'],
198  'L_NB_IMG'=>$lang['pictures'],
199  'L_MOVE_UP'=>$lang['up'],
200  'L_EDIT'=>$lang['edit'],
201  'L_DELETE'=>$lang['delete'],
202 ));
203
204$tpl = array('cat_first','cat_last');
205// +-----------------------------------------------------------------------+
206// |                          Categories display                           |
207// +-----------------------------------------------------------------------+
208
209$categories = array();
210
211$query = '
212SELECT id, name, dir, rank, nb_images, status
213  FROM '.CATEGORIES_TABLE;
214if (!isset($_GET['parent_id']))
215{
216  $query.= '
217  WHERE id_uppercat IS NULL';
218}
219else
220{
221  $query.= '
222  WHERE id_uppercat = '.$_GET['parent_id'];
223}
224$query.= '
225  ORDER BY rank ASC
226;';
227$result = pwg_query($query);
228while ($row = mysql_fetch_array($result))
229{
230  $categories[$row['id']] = $row;
231  // by default, let's consider there is no sub-categories. This will be
232  // calculated after.
233  $categories[$row['id']]['nb_subcats'] = 0;
234}
235
236if (count($categories) > 0)
237{
238  $query = '
239SELECT id_uppercat, COUNT(*) AS nb_subcats
240  FROM '. CATEGORIES_TABLE.'
241  WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
242  GROUP BY id_uppercat
243;';
244  $result = pwg_query($query);
245  while ($row = mysql_fetch_array($result))
246  {
247    $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
248  }
249
250  $template->assign_block_vars('categories', array());
251}
252
253foreach ($categories as $category)
254{
255  // TODO : not used anymore ?
256  //$images_folder = PHPWG_ROOT_PATH.'template/';
257  //$images_folder.= $user['template'].'/admin/images';
258
259  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
260  $cat_list_url = $base_url.'cat_list';
261
262  $self_url = $cat_list_url;
263  if (isset($_GET['parent_id']))
264  {
265    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
266  }
267
268  $template->assign_block_vars(
269    'categories.category',
270    array(
271      'NAME'       => $category['name'],
272      'ID'         => $category['id'],
273      'RANK'       => $category['rank']*10,
274
275      'U_JUMPTO'   => make_index_url(
276        array(
277          'category' => $category
278          )
279        ),
280
281      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
282      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
283      )
284    );
285
286  if (empty($category['dir']))
287  {
288    $template->assign_block_vars(
289      'categories.category.delete',
290      array(
291        'URL'=>$self_url.'&amp;delete='.$category['id']
292        )
293      );
294    $template->assign_block_vars(
295      'categories.category.virtual',
296      array(
297        'CLASS' => 'virtual_cat',
298        )
299      );
300  }
301
302  if ($category['nb_images'] > 0)
303  {
304    $template->assign_block_vars(
305      'categories.category.elements',
306      array(
307        'URL'=>$base_url.'element_set&amp;cat='.$category['id']
308        )
309      );
310  }
311
312  if ('private' == $category['status'])
313  {
314    $template->assign_block_vars(
315      'categories.category.permissions',
316      array(
317        'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
318        )
319      );
320  }
321}
322// Add a link to Page bottom only if needed (10 or more categories)
323if ( isset($category['rank']) and $category['rank'] > 9 ) 
324{
325  $template->assign_block_vars('eop_link', array('ICON'=>'Displayed'));
326}
327// +-----------------------------------------------------------------------+
328// |                          sending html code                            |
329// +-----------------------------------------------------------------------+
330$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
331?>
Note: See TracBrowser for help on using the repository browser.