source: branches/2.1/admin/cat_list.php @ 23479

Last change on this file since 23479 was 8167, checked in by plg, 14 years ago

bug 2031 fixed: redirection after category deletion preserves the current
node in the category tree.

+ the confirmation message is displayed after redirect, thanks to session

  • Property svn:eol-style set to LF
File size: 9.2 KB
RevLine 
[21]1<?php
[362]2// +-----------------------------------------------------------------------+
[2297]3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
[5196]5// | Copyright(C) 2008-2010 Piwigo Team                  http://piwigo.org |
[2297]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// +-----------------------------------------------------------------------+
[345]23
[580]24if (!defined('PHPWG_ROOT_PATH'))
[394]25{
[580]26  die('Hacking attempt!');
[394]27}
[798]28
[1072]29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
[580]31// +-----------------------------------------------------------------------+
[1072]32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
[5933]36trigger_action('loc_begin_cat_list');
37
[5195]38if (!empty($_POST) or isset($_GET['delete']))
39{
40  check_pwg_token();
41}
42
[1072]43// +-----------------------------------------------------------------------+
[798]44// |                               functions                               |
45// +-----------------------------------------------------------------------+
46
47/**
48 * save the rank depending on given categories order
49 *
50 * The list of ordered categories id is supposed to be in the same parent
51 * category
52 *
53 * @param array categories
54 * @return void
55 */
56function save_categories_order($categories)
57{
58  $current_rank = 0;
59  $datas = array();
60  foreach ($categories as $id)
61  {
62    array_push($datas, array('id' => $id, 'rank' => ++$current_rank));
63  }
64  $fields = array('primary' => array('id'), 'update' => array('rank'));
65  mass_updates(CATEGORIES_TABLE, $fields, $datas);
66
[2306]67  update_global_rank();
[798]68}
69
70// +-----------------------------------------------------------------------+
[580]71// |                            initialization                             |
72// +-----------------------------------------------------------------------+
[834]73
[5195]74check_input_parameter('parent_id', $_GET, false, PATTERN_ID);
75
[580]76$categories = array();
[834]77
[2306]78$base_url = get_root_url().'admin.php?page=cat_list';
79$navigation = '<a href="'.$base_url.'">';
[5021]80$navigation.= l10n('Home');
[834]81$navigation.= '</a>';
82
[580]83// +-----------------------------------------------------------------------+
84// |                    virtual categories management                      |
85// +-----------------------------------------------------------------------+
[1106]86// request to delete a virtual category / not for an adviser
87if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
[68]88{
[659]89  delete_categories(array($_GET['delete']));
[8167]90  $_SESSION['page_infos'] = array(l10n('Virtual category deleted'));
[659]91  update_global_rank();
[8167]92
93  $redirect_url = get_root_url().'admin.php?page=cat_list';
94  if (isset($_GET['parent_id']))
95  {
96    $redirect_url.= '&parent_id='.$_GET['parent_id'];
97  } 
98  redirect($redirect_url);
[394]99}
[602]100// request to add a virtual category
[798]101else if (isset($_POST['submitAdd']))
[394]102{
[1064]103  $output_create = create_virtual_category(
104    $_POST['virtual_name'],
105    @$_GET['parent_id']
106    );
107
108  if (isset($output_create['error']))
[580]109  {
[1064]110    array_push($page['errors'], $output_create['error']);
[580]111  }
[1064]112  else
[68]113  {
[1064]114    array_push($page['infos'], $output_create['info']);
[68]115  }
116}
[1066]117// save manual category ordering
[798]118else if (isset($_POST['submitOrder']))
119{
120  asort($_POST['catOrd'], SORT_NUMERIC);
121  save_categories_order(array_keys($_POST['catOrd']));
[1066]122
123  array_push(
124    $page['infos'],
125    l10n('Categories manual order was saved')
126    );
[798]127}
[1066]128// sort categories alpha-numerically
129else if (isset($_POST['submitOrderAlphaNum']))
130{
131  $query = '
132SELECT id, name
133  FROM '.CATEGORIES_TABLE.'
134  WHERE id_uppercat '.
135    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
136;';
137  $result = pwg_query($query);
[4325]138  while ($row = pwg_db_fetch_assoc($result))
[1066]139  {
[1225]140    $categories[ $row['id'] ] = strtolower($row['name']);
[1066]141  }
142
143  asort($categories, SORT_REGULAR);
144  save_categories_order(array_keys($categories));
145
146  array_push(
147    $page['infos'],
148    l10n('Categories ordered alphanumerically')
149    );
150}
[5079]151// sort categories alpha-numerically reverse
152else if (isset($_POST['submitOrderAlphaNumReverse']))
153{
154  $query = '
155SELECT id, name
156  FROM '.CATEGORIES_TABLE.'
157  WHERE id_uppercat '.
158    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
159;';
160  $result = pwg_query($query);
161  while ($row = pwg_db_fetch_assoc($result))
162  {
163    $categories[ $row['id'] ] = strtolower($row['name']);
164  }
[1066]165
[5079]166  arsort($categories, SORT_REGULAR);
167  save_categories_order(array_keys($categories));
168
169  array_push(
170    $page['infos'],
171    l10n('Categories ordered alphanumerically reverse')
172    );
173}
174
[580]175// +-----------------------------------------------------------------------+
176// |                            Navigation path                            |
177// +-----------------------------------------------------------------------+
[834]178
[394]179if (isset($_GET['parent_id']))
180{
[642]181  $navigation.= $conf['level_separator'];
[580]182
[1861]183  $navigation.= get_cat_display_name_from_id(
184    $_GET['parent_id'],
[1064]185    $base_url.'&amp;parent_id=',
186    false
187    );
[394]188}
[580]189// +-----------------------------------------------------------------------+
190// |                       template initialization                         |
191// +-----------------------------------------------------------------------+
[2530]192$template->set_filename('categories', 'cat_list.tpl');
[394]193
[635]194$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
195if (isset($_GET['parent_id']))
196{
197  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
198}
199
[2223]200$template->assign(array(
[394]201  'CATEGORIES_NAV'=>$navigation,
[1004]202  'F_ACTION'=>$form_action,
[5195]203  'PWG_TOKEN' => get_pwg_token(),
[580]204 ));
[1131]205
[580]206// +-----------------------------------------------------------------------+
207// |                          Categories display                           |
208// +-----------------------------------------------------------------------+
[647]209
[798]210$categories = array();
211
212$query = '
[2324]213SELECT id, name, permalink, dir, rank, status
[798]214  FROM '.CATEGORIES_TABLE;
215if (!isset($_GET['parent_id']))
216{
217  $query.= '
218  WHERE id_uppercat IS NULL';
219}
220else
221{
222  $query.= '
223  WHERE id_uppercat = '.$_GET['parent_id'];
224}
225$query.= '
226  ORDER BY rank ASC
227;';
[2324]228$categories = hash_from_query($query, 'id');
[798]229
[2324]230// get the categories containing images directly
231$categories_with_images = array();
232if ( count($categories) )
[580]233{
[647]234  $query = '
[2324]235SELECT DISTINCT category_id
236  FROM '.IMAGE_CATEGORY_TABLE.'
237  WHERE category_id IN ('.implode(',', array_keys($categories)).')';
238  $categories_with_images = array_flip( array_from_query($query, 'category_id') );
[642]239}
240
[2223]241$template->assign('categories', array());
[2324]242$base_url = get_root_url().'admin.php?page=';
[642]243foreach ($categories as $category)
244{
[580]245  $cat_list_url = $base_url.'cat_list';
[1131]246
[580]247  $self_url = $cat_list_url;
[394]248  if (isset($_GET['parent_id']))
[580]249  {
250    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
251  }
[394]252
[2223]253  $tpl_cat =
[580]254    array(
[2433]255      'NAME'       => 
256        trigger_event(
257          'render_category_name',
258          $category['name'],
259          'admin_cat_list'
260          ),
[1082]261      'ID'         => $category['id'],
262      'RANK'       => $category['rank']*10,
[798]263
[1082]264      'U_JUMPTO'   => make_index_url(
265        array(
[1861]266          'category' => $category
[1082]267          )
268        ),
[1131]269
270      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
[1082]271      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
[2306]272
[2223]273      'IS_VIRTUAL' => empty($category['dir'])
[798]274    );
[1131]275
[798]276  if (empty($category['dir']))
[21]277  {
[2223]278    $tpl_cat['U_DELETE'] = $self_url.'&amp;delete='.$category['id'];
[5195]279    $tpl_cat['U_DELETE'].= '&amp;pwg_token='.get_pwg_token();
[21]280  }
[1131]281
[2324]282  if ( array_key_exists($category['id'], $categories_with_images) )
[580]283  {
[2223]284    $tpl_cat['U_MANAGE_ELEMENTS']=
285      $base_url.'element_set&amp;cat='.$category['id'];
[21]286  }
[798]287
288  if ('private' == $category['status'])
[394]289  {
[2223]290    $tpl_cat['U_MANAGE_PERMISSIONS']=
291      $base_url.'cat_perm&amp;cat='.$category['id'];
[394]292  }
[2223]293  $template->append('categories', $tpl_cat);
[21]294}
[5933]295
296trigger_action('loc_end_cat_list');
297
[580]298// +-----------------------------------------------------------------------+
299// |                          sending html code                            |
300// +-----------------------------------------------------------------------+
[394]301$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
[362]302?>
Note: See TracBrowser for help on using the repository browser.