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

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

merge r6265 from trunk to branch 2.1

Correct text alignement in .infos, .errors
30px => 53px

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