source: trunk/admin/cat_list.php @ 5762

Last change on this file since 5762 was 5196, checked in by plg, 15 years ago

increase copyright year to 2010

  • Property svn:eol-style set to LF
File size: 9.0 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die('Hacking attempt!');
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36if (!empty($_POST) or isset($_GET['delete']))
37{
38  check_pwg_token();
39}
40
41// +-----------------------------------------------------------------------+
42// |                               functions                               |
43// +-----------------------------------------------------------------------+
44
45/**
46 * save the rank depending on given categories order
47 *
48 * The list of ordered categories id is supposed to be in the same parent
49 * category
50 *
51 * @param array categories
52 * @return void
53 */
54function save_categories_order($categories)
55{
56  $current_rank = 0;
57  $datas = array();
58  foreach ($categories as $id)
59  {
60    array_push($datas, array('id' => $id, 'rank' => ++$current_rank));
61  }
62  $fields = array('primary' => array('id'), 'update' => array('rank'));
63  mass_updates(CATEGORIES_TABLE, $fields, $datas);
64
65  update_global_rank();
66}
67
68// +-----------------------------------------------------------------------+
69// |                            initialization                             |
70// +-----------------------------------------------------------------------+
71
72check_input_parameter('parent_id', $_GET, false, PATTERN_ID);
73
74$categories = array();
75
76$base_url = get_root_url().'admin.php?page=cat_list';
77$navigation = '<a href="'.$base_url.'">';
78$navigation.= l10n('Home');
79$navigation.= '</a>';
80
81// +-----------------------------------------------------------------------+
82// |                    virtual categories management                      |
83// +-----------------------------------------------------------------------+
84// request to delete a virtual category / not for an adviser
85if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
86{
87  delete_categories(array($_GET['delete']));
88  array_push($page['infos'], l10n('Virtual category deleted'));
89  update_global_rank();
90  redirect(get_root_url().'admin.php?page=cat_list');
91}
92// request to add a virtual category
93else if (isset($_POST['submitAdd']))
94{
95  $output_create = create_virtual_category(
96    $_POST['virtual_name'],
97    @$_GET['parent_id']
98    );
99
100  if (isset($output_create['error']))
101  {
102    array_push($page['errors'], $output_create['error']);
103  }
104  else
105  {
106    array_push($page['infos'], $output_create['info']);
107  }
108}
109// save manual category ordering
110else if (isset($_POST['submitOrder']))
111{
112  asort($_POST['catOrd'], SORT_NUMERIC);
113  save_categories_order(array_keys($_POST['catOrd']));
114
115  array_push(
116    $page['infos'],
117    l10n('Categories manual order was saved')
118    );
119}
120// sort categories alpha-numerically
121else if (isset($_POST['submitOrderAlphaNum']))
122{
123  $query = '
124SELECT id, name
125  FROM '.CATEGORIES_TABLE.'
126  WHERE id_uppercat '.
127    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
128;';
129  $result = pwg_query($query);
130  while ($row = pwg_db_fetch_assoc($result))
131  {
132    $categories[ $row['id'] ] = strtolower($row['name']);
133  }
134
135  asort($categories, SORT_REGULAR);
136  save_categories_order(array_keys($categories));
137
138  array_push(
139    $page['infos'],
140    l10n('Categories ordered alphanumerically')
141    );
142}
143// sort categories alpha-numerically reverse
144else if (isset($_POST['submitOrderAlphaNumReverse']))
145{
146  $query = '
147SELECT id, name
148  FROM '.CATEGORIES_TABLE.'
149  WHERE id_uppercat '.
150    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
151;';
152  $result = pwg_query($query);
153  while ($row = pwg_db_fetch_assoc($result))
154  {
155    $categories[ $row['id'] ] = strtolower($row['name']);
156  }
157
158  arsort($categories, SORT_REGULAR);
159  save_categories_order(array_keys($categories));
160
161  array_push(
162    $page['infos'],
163    l10n('Categories ordered alphanumerically reverse')
164    );
165}
166
167// +-----------------------------------------------------------------------+
168// |                            Navigation path                            |
169// +-----------------------------------------------------------------------+
170
171if (isset($_GET['parent_id']))
172{
173  $navigation.= $conf['level_separator'];
174
175  $navigation.= get_cat_display_name_from_id(
176    $_GET['parent_id'],
177    $base_url.'&amp;parent_id=',
178    false
179    );
180}
181// +-----------------------------------------------------------------------+
182// |                       template initialization                         |
183// +-----------------------------------------------------------------------+
184$template->set_filename('categories', 'cat_list.tpl');
185
186$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
187if (isset($_GET['parent_id']))
188{
189  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
190}
191
192$template->assign(array(
193  'CATEGORIES_NAV'=>$navigation,
194  'F_ACTION'=>$form_action,
195  'PWG_TOKEN' => get_pwg_token(),
196 ));
197
198// +-----------------------------------------------------------------------+
199// |                          Categories display                           |
200// +-----------------------------------------------------------------------+
201
202$categories = array();
203
204$query = '
205SELECT id, name, permalink, dir, rank, status
206  FROM '.CATEGORIES_TABLE;
207if (!isset($_GET['parent_id']))
208{
209  $query.= '
210  WHERE id_uppercat IS NULL';
211}
212else
213{
214  $query.= '
215  WHERE id_uppercat = '.$_GET['parent_id'];
216}
217$query.= '
218  ORDER BY rank ASC
219;';
220$categories = hash_from_query($query, 'id');
221
222// get the categories containing images directly
223$categories_with_images = array();
224if ( count($categories) )
225{
226  $query = '
227SELECT DISTINCT category_id
228  FROM '.IMAGE_CATEGORY_TABLE.'
229  WHERE category_id IN ('.implode(',', array_keys($categories)).')';
230  $categories_with_images = array_flip( array_from_query($query, 'category_id') );
231}
232
233$template->assign('categories', array());
234$base_url = get_root_url().'admin.php?page=';
235foreach ($categories as $category)
236{
237  $cat_list_url = $base_url.'cat_list';
238
239  $self_url = $cat_list_url;
240  if (isset($_GET['parent_id']))
241  {
242    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
243  }
244
245  $tpl_cat =
246    array(
247      'NAME'       => 
248        trigger_event(
249          'render_category_name',
250          $category['name'],
251          'admin_cat_list'
252          ),
253      'ID'         => $category['id'],
254      'RANK'       => $category['rank']*10,
255
256      'U_JUMPTO'   => make_index_url(
257        array(
258          'category' => $category
259          )
260        ),
261
262      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
263      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
264
265      'IS_VIRTUAL' => empty($category['dir'])
266    );
267
268  if (empty($category['dir']))
269  {
270    $tpl_cat['U_DELETE'] = $self_url.'&amp;delete='.$category['id'];
271    $tpl_cat['U_DELETE'].= '&amp;pwg_token='.get_pwg_token();
272  }
273
274  if ( array_key_exists($category['id'], $categories_with_images) )
275  {
276    $tpl_cat['U_MANAGE_ELEMENTS']=
277      $base_url.'element_set&amp;cat='.$category['id'];
278  }
279
280  if ('private' == $category['status'])
281  {
282    $tpl_cat['U_MANAGE_PERMISSIONS']=
283      $base_url.'cat_perm&amp;cat='.$category['id'];
284  }
285  $template->append('categories', $tpl_cat);
286}
287// +-----------------------------------------------------------------------+
288// |                          sending html code                            |
289// +-----------------------------------------------------------------------+
290$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
291?>
Note: See TracBrowser for help on using the repository browser.