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
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
[5195]36if (!empty($_POST) or isset($_GET['delete']))
37{
38  check_pwg_token();
39}
40
[1072]41// +-----------------------------------------------------------------------+
[798]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
[2306]65  update_global_rank();
[798]66}
67
68// +-----------------------------------------------------------------------+
[580]69// |                            initialization                             |
70// +-----------------------------------------------------------------------+
[834]71
[5195]72check_input_parameter('parent_id', $_GET, false, PATTERN_ID);
73
[580]74$categories = array();
[834]75
[2306]76$base_url = get_root_url().'admin.php?page=cat_list';
77$navigation = '<a href="'.$base_url.'">';
[5021]78$navigation.= l10n('Home');
[834]79$navigation.= '</a>';
80
[580]81// +-----------------------------------------------------------------------+
82// |                    virtual categories management                      |
83// +-----------------------------------------------------------------------+
[1106]84// request to delete a virtual category / not for an adviser
85if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
[68]86{
[659]87  delete_categories(array($_GET['delete']));
[5021]88  array_push($page['infos'], l10n('Virtual category deleted'));
[659]89  update_global_rank();
[5193]90  redirect(get_root_url().'admin.php?page=cat_list');
[394]91}
[602]92// request to add a virtual category
[798]93else if (isset($_POST['submitAdd']))
[394]94{
[1064]95  $output_create = create_virtual_category(
96    $_POST['virtual_name'],
97    @$_GET['parent_id']
98    );
99
100  if (isset($output_create['error']))
[580]101  {
[1064]102    array_push($page['errors'], $output_create['error']);
[580]103  }
[1064]104  else
[68]105  {
[1064]106    array_push($page['infos'], $output_create['info']);
[68]107  }
108}
[1066]109// save manual category ordering
[798]110else if (isset($_POST['submitOrder']))
111{
112  asort($_POST['catOrd'], SORT_NUMERIC);
113  save_categories_order(array_keys($_POST['catOrd']));
[1066]114
115  array_push(
116    $page['infos'],
117    l10n('Categories manual order was saved')
118    );
[798]119}
[1066]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);
[4325]130  while ($row = pwg_db_fetch_assoc($result))
[1066]131  {
[1225]132    $categories[ $row['id'] ] = strtolower($row['name']);
[1066]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}
[5079]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  }
[1066]157
[5079]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
[580]167// +-----------------------------------------------------------------------+
168// |                            Navigation path                            |
169// +-----------------------------------------------------------------------+
[834]170
[394]171if (isset($_GET['parent_id']))
172{
[642]173  $navigation.= $conf['level_separator'];
[580]174
[1861]175  $navigation.= get_cat_display_name_from_id(
176    $_GET['parent_id'],
[1064]177    $base_url.'&amp;parent_id=',
178    false
179    );
[394]180}
[580]181// +-----------------------------------------------------------------------+
182// |                       template initialization                         |
183// +-----------------------------------------------------------------------+
[2530]184$template->set_filename('categories', 'cat_list.tpl');
[394]185
[635]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
[2223]192$template->assign(array(
[394]193  'CATEGORIES_NAV'=>$navigation,
[1004]194  'F_ACTION'=>$form_action,
[5195]195  'PWG_TOKEN' => get_pwg_token(),
[580]196 ));
[1131]197
[580]198// +-----------------------------------------------------------------------+
199// |                          Categories display                           |
200// +-----------------------------------------------------------------------+
[647]201
[798]202$categories = array();
203
204$query = '
[2324]205SELECT id, name, permalink, dir, rank, status
[798]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;';
[2324]220$categories = hash_from_query($query, 'id');
[798]221
[2324]222// get the categories containing images directly
223$categories_with_images = array();
224if ( count($categories) )
[580]225{
[647]226  $query = '
[2324]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') );
[642]231}
232
[2223]233$template->assign('categories', array());
[2324]234$base_url = get_root_url().'admin.php?page=';
[642]235foreach ($categories as $category)
236{
[580]237  $cat_list_url = $base_url.'cat_list';
[1131]238
[580]239  $self_url = $cat_list_url;
[394]240  if (isset($_GET['parent_id']))
[580]241  {
242    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
243  }
[394]244
[2223]245  $tpl_cat =
[580]246    array(
[2433]247      'NAME'       => 
248        trigger_event(
249          'render_category_name',
250          $category['name'],
251          'admin_cat_list'
252          ),
[1082]253      'ID'         => $category['id'],
254      'RANK'       => $category['rank']*10,
[798]255
[1082]256      'U_JUMPTO'   => make_index_url(
257        array(
[1861]258          'category' => $category
[1082]259          )
260        ),
[1131]261
262      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
[1082]263      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
[2306]264
[2223]265      'IS_VIRTUAL' => empty($category['dir'])
[798]266    );
[1131]267
[798]268  if (empty($category['dir']))
[21]269  {
[2223]270    $tpl_cat['U_DELETE'] = $self_url.'&amp;delete='.$category['id'];
[5195]271    $tpl_cat['U_DELETE'].= '&amp;pwg_token='.get_pwg_token();
[21]272  }
[1131]273
[2324]274  if ( array_key_exists($category['id'], $categories_with_images) )
[580]275  {
[2223]276    $tpl_cat['U_MANAGE_ELEMENTS']=
277      $base_url.'element_set&amp;cat='.$category['id'];
[21]278  }
[798]279
280  if ('private' == $category['status'])
[394]281  {
[2223]282    $tpl_cat['U_MANAGE_PERMISSIONS']=
283      $base_url.'cat_perm&amp;cat='.$category['id'];
[394]284  }
[2223]285  $template->append('categories', $tpl_cat);
[21]286}
[580]287// +-----------------------------------------------------------------------+
288// |                          sending html code                            |
289// +-----------------------------------------------------------------------+
[394]290$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
[362]291?>
Note: See TracBrowser for help on using the repository browser.