source: trunk/admin/cat_list.php @ 5933

Last change on this file since 5933 was 5933, checked in by nikrou, 14 years ago

Feature 1620 : add triggers on admin side for categories and batch mode.

  • Property svn:eol-style set to LF
File size: 9.1 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']));
[5021]90  array_push($page['infos'], l10n('Virtual category deleted'));
[659]91  update_global_rank();
[5193]92  redirect(get_root_url().'admin.php?page=cat_list');
[394]93}
[602]94// request to add a virtual category
[798]95else if (isset($_POST['submitAdd']))
[394]96{
[1064]97  $output_create = create_virtual_category(
98    $_POST['virtual_name'],
99    @$_GET['parent_id']
100    );
101
102  if (isset($output_create['error']))
[580]103  {
[1064]104    array_push($page['errors'], $output_create['error']);
[580]105  }
[1064]106  else
[68]107  {
[1064]108    array_push($page['infos'], $output_create['info']);
[68]109  }
110}
[1066]111// save manual category ordering
[798]112else if (isset($_POST['submitOrder']))
113{
114  asort($_POST['catOrd'], SORT_NUMERIC);
115  save_categories_order(array_keys($_POST['catOrd']));
[1066]116
117  array_push(
118    $page['infos'],
119    l10n('Categories manual order was saved')
120    );
[798]121}
[1066]122// sort categories alpha-numerically
123else if (isset($_POST['submitOrderAlphaNum']))
124{
125  $query = '
126SELECT id, name
127  FROM '.CATEGORIES_TABLE.'
128  WHERE id_uppercat '.
129    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
130;';
131  $result = pwg_query($query);
[4325]132  while ($row = pwg_db_fetch_assoc($result))
[1066]133  {
[1225]134    $categories[ $row['id'] ] = strtolower($row['name']);
[1066]135  }
136
137  asort($categories, SORT_REGULAR);
138  save_categories_order(array_keys($categories));
139
140  array_push(
141    $page['infos'],
142    l10n('Categories ordered alphanumerically')
143    );
144}
[5079]145// sort categories alpha-numerically reverse
146else if (isset($_POST['submitOrderAlphaNumReverse']))
147{
148  $query = '
149SELECT id, name
150  FROM '.CATEGORIES_TABLE.'
151  WHERE id_uppercat '.
152    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
153;';
154  $result = pwg_query($query);
155  while ($row = pwg_db_fetch_assoc($result))
156  {
157    $categories[ $row['id'] ] = strtolower($row['name']);
158  }
[1066]159
[5079]160  arsort($categories, SORT_REGULAR);
161  save_categories_order(array_keys($categories));
162
163  array_push(
164    $page['infos'],
165    l10n('Categories ordered alphanumerically reverse')
166    );
167}
168
[580]169// +-----------------------------------------------------------------------+
170// |                            Navigation path                            |
171// +-----------------------------------------------------------------------+
[834]172
[394]173if (isset($_GET['parent_id']))
174{
[642]175  $navigation.= $conf['level_separator'];
[580]176
[1861]177  $navigation.= get_cat_display_name_from_id(
178    $_GET['parent_id'],
[1064]179    $base_url.'&amp;parent_id=',
180    false
181    );
[394]182}
[580]183// +-----------------------------------------------------------------------+
184// |                       template initialization                         |
185// +-----------------------------------------------------------------------+
[2530]186$template->set_filename('categories', 'cat_list.tpl');
[394]187
[635]188$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
189if (isset($_GET['parent_id']))
190{
191  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
192}
193
[2223]194$template->assign(array(
[394]195  'CATEGORIES_NAV'=>$navigation,
[1004]196  'F_ACTION'=>$form_action,
[5195]197  'PWG_TOKEN' => get_pwg_token(),
[580]198 ));
[1131]199
[580]200// +-----------------------------------------------------------------------+
201// |                          Categories display                           |
202// +-----------------------------------------------------------------------+
[647]203
[798]204$categories = array();
205
206$query = '
[2324]207SELECT id, name, permalink, dir, rank, status
[798]208  FROM '.CATEGORIES_TABLE;
209if (!isset($_GET['parent_id']))
210{
211  $query.= '
212  WHERE id_uppercat IS NULL';
213}
214else
215{
216  $query.= '
217  WHERE id_uppercat = '.$_GET['parent_id'];
218}
219$query.= '
220  ORDER BY rank ASC
221;';
[2324]222$categories = hash_from_query($query, 'id');
[798]223
[2324]224// get the categories containing images directly
225$categories_with_images = array();
226if ( count($categories) )
[580]227{
[647]228  $query = '
[2324]229SELECT DISTINCT category_id
230  FROM '.IMAGE_CATEGORY_TABLE.'
231  WHERE category_id IN ('.implode(',', array_keys($categories)).')';
232  $categories_with_images = array_flip( array_from_query($query, 'category_id') );
[642]233}
234
[2223]235$template->assign('categories', array());
[2324]236$base_url = get_root_url().'admin.php?page=';
[642]237foreach ($categories as $category)
238{
[580]239  $cat_list_url = $base_url.'cat_list';
[1131]240
[580]241  $self_url = $cat_list_url;
[394]242  if (isset($_GET['parent_id']))
[580]243  {
244    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
245  }
[394]246
[2223]247  $tpl_cat =
[580]248    array(
[2433]249      'NAME'       => 
250        trigger_event(
251          'render_category_name',
252          $category['name'],
253          'admin_cat_list'
254          ),
[1082]255      'ID'         => $category['id'],
256      'RANK'       => $category['rank']*10,
[798]257
[1082]258      'U_JUMPTO'   => make_index_url(
259        array(
[1861]260          'category' => $category
[1082]261          )
262        ),
[1131]263
264      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
[1082]265      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
[2306]266
[2223]267      'IS_VIRTUAL' => empty($category['dir'])
[798]268    );
[1131]269
[798]270  if (empty($category['dir']))
[21]271  {
[2223]272    $tpl_cat['U_DELETE'] = $self_url.'&amp;delete='.$category['id'];
[5195]273    $tpl_cat['U_DELETE'].= '&amp;pwg_token='.get_pwg_token();
[21]274  }
[1131]275
[2324]276  if ( array_key_exists($category['id'], $categories_with_images) )
[580]277  {
[2223]278    $tpl_cat['U_MANAGE_ELEMENTS']=
279      $base_url.'element_set&amp;cat='.$category['id'];
[21]280  }
[798]281
282  if ('private' == $category['status'])
[394]283  {
[2223]284    $tpl_cat['U_MANAGE_PERMISSIONS']=
285      $base_url.'cat_perm&amp;cat='.$category['id'];
[394]286  }
[2223]287  $template->append('categories', $tpl_cat);
[21]288}
[5933]289
290trigger_action('loc_end_cat_list');
291
[580]292// +-----------------------------------------------------------------------+
293// |                          sending html code                            |
294// +-----------------------------------------------------------------------+
[394]295$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
[362]296?>
Note: See TracBrowser for help on using the repository browser.