source: branches/1.7/admin/cat_list.php @ 27218

Last change on this file since 27218 was 2432, checked in by patdenice, 16 years ago

Add triggers for category name (render_category_name).
Add strip_tags for ALT attribute on category thumbnail.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 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 2432 2008-07-12 14:27:22Z patdenice $
8// | last update   : $Date: 2008-07-12 14:27:22 +0000 (Sat, 12 Jul 2008) $
9// | last modifier : $Author: patdenice $
10// | revision      : $Revision: 2432 $
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();
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.= l10n('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'], l10n('cat_virtual_deleted'));
85  update_global_rank();
86}
87// request to add a virtual category
88else if (isset($_POST['submitAdd']))
89{
90  $output_create = create_virtual_category(
91    $_POST['virtual_name'],
92    @$_GET['parent_id']
93    );
94
95  if (isset($output_create['error']))
96  {
97    array_push($page['errors'], $output_create['error']);
98  }
99  else
100  {
101    array_push($page['infos'], $output_create['info']);
102  }
103}
104// save manual category ordering
105else if (isset($_POST['submitOrder']))
106{
107  asort($_POST['catOrd'], SORT_NUMERIC);
108  save_categories_order(array_keys($_POST['catOrd']));
109
110  array_push(
111    $page['infos'],
112    l10n('Categories manual order was saved')
113    );
114}
115// sort categories alpha-numerically
116else if (isset($_POST['submitOrderAlphaNum']))
117{
118  $query = '
119SELECT id, name
120  FROM '.CATEGORIES_TABLE.'
121  WHERE id_uppercat '.
122    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
123;';
124  $result = pwg_query($query);
125  while ($row = mysql_fetch_assoc($result))
126  {
127    $categories[ $row['id'] ] = strtolower($row['name']);
128  }
129
130  asort($categories, SORT_REGULAR);
131  save_categories_order(array_keys($categories));
132
133  array_push(
134    $page['infos'],
135    l10n('Categories ordered alphanumerically')
136    );
137}
138
139// +-----------------------------------------------------------------------+
140// |                            Navigation path                            |
141// +-----------------------------------------------------------------------+
142
143if (isset($_GET['parent_id']))
144{
145  $navigation.= $conf['level_separator'];
146
147  $navigation.= get_cat_display_name_from_id(
148    $_GET['parent_id'],
149    $base_url.'&amp;parent_id=',
150    false
151    );
152}
153// +-----------------------------------------------------------------------+
154// |                       template initialization                         |
155// +-----------------------------------------------------------------------+
156$template->set_filenames(array('categories'=>'admin/cat_list.tpl'));
157
158$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
159if (isset($_GET['parent_id']))
160{
161  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
162}
163
164$template->assign_vars(array(
165  'CATEGORIES_NAV'=>$navigation,
166  'F_ACTION'=>$form_action,
167
168  'L_ADD_VIRTUAL'=>l10n('cat_add'),
169  'L_SUBMIT'=>l10n('submit'),
170  'L_STORAGE'=>l10n('storage'),
171  'L_NB_IMG'=>l10n('pictures'),
172  'L_MOVE_UP'=>l10n('up'),
173  'L_EDIT'=>l10n('edit'),
174  'L_DELETE'=>l10n('delete'),
175 ));
176
177$tpl = array('cat_first','cat_last');
178// +-----------------------------------------------------------------------+
179// |                          Categories display                           |
180// +-----------------------------------------------------------------------+
181
182$categories = array();
183
184$query = '
185SELECT id, name, permalink, dir, rank, nb_images, status
186  FROM '.CATEGORIES_TABLE;
187if (!isset($_GET['parent_id']))
188{
189  $query.= '
190  WHERE id_uppercat IS NULL';
191}
192else
193{
194  $query.= '
195  WHERE id_uppercat = '.$_GET['parent_id'];
196}
197$query.= '
198  ORDER BY rank ASC
199;';
200$result = pwg_query($query);
201while ($row = mysql_fetch_array($result))
202{
203  $categories[$row['id']] = $row;
204  // by default, let's consider there is no sub-categories. This will be
205  // calculated after.
206  $categories[$row['id']]['nb_subcats'] = 0;
207}
208
209if (count($categories) > 0)
210{
211  $query = '
212SELECT id_uppercat, COUNT(*) AS nb_subcats
213  FROM '. CATEGORIES_TABLE.'
214  WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
215  GROUP BY id_uppercat
216;';
217  $result = pwg_query($query);
218  while ($row = mysql_fetch_array($result))
219  {
220    $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
221  }
222
223  $template->assign_block_vars('categories', array());
224}
225
226foreach ($categories as $category)
227{
228  // TODO : not used anymore ?
229  //$images_folder = PHPWG_ROOT_PATH.'template/';
230  //$images_folder.= $user['template'].'/admin/images';
231
232  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
233  $cat_list_url = $base_url.'cat_list';
234
235  $self_url = $cat_list_url;
236  if (isset($_GET['parent_id']))
237  {
238    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
239  }
240
241  $template->assign_block_vars(
242    'categories.category',
243    array(
244      'NAME'       => 
245        trigger_event(
246          'render_category_name',
247          $category['name'],
248          'admin_cat_list'
249          ),
250      'ID'         => $category['id'],
251      'RANK'       => $category['rank']*10,
252
253      'U_JUMPTO'   => make_index_url(
254        array(
255          'category' => $category
256          )
257        ),
258
259      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
260      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
261      )
262    );
263
264  if (empty($category['dir']))
265  {
266    $template->assign_block_vars(
267      'categories.category.delete',
268      array(
269        'URL'=>$self_url.'&amp;delete='.$category['id']
270        )
271      );
272    $template->assign_block_vars(
273      'categories.category.virtual',
274      array(
275        'CLASS' => 'virtual_cat',
276        )
277      );
278  }
279
280  if ($category['nb_images'] > 0)
281  {
282    $template->assign_block_vars(
283      'categories.category.elements',
284      array(
285        'URL'=>$base_url.'element_set&amp;cat='.$category['id']
286        )
287      );
288  }
289
290  if ('private' == $category['status'])
291  {
292    $template->assign_block_vars(
293      'categories.category.permissions',
294      array(
295        'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
296        )
297      );
298  }
299}
300// Add a link to Page bottom only if needed (10 or more categories)
301if ( isset($category['rank']) and $category['rank'] > 9 )
302{
303  $template->assign_block_vars('eop_link', array('ICON'=>'Displayed'));
304}
305// +-----------------------------------------------------------------------+
306// |                          sending html code                            |
307// +-----------------------------------------------------------------------+
308$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
309?>
Note: See TracBrowser for help on using the repository browser.