source: trunk/admin/cat_list.php @ 2299

Last change on this file since 2299 was 2299, checked in by plg, 17 years ago

Bug fixed: as rvelices notified me by email, my header replacement script was
bugged (r2297 was repeating new and old header).

By the way, I've also removed the replacement keywords. We were using them
because it was a common usage with CVS but it is advised not to use them with
Subversion. Personnaly, it is a problem when I search differences between 2
Piwigo installations outside Subversion.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.3 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008      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
36// +-----------------------------------------------------------------------+
37// |                               functions                               |
38// +-----------------------------------------------------------------------+
39
40/**
41 * save the rank depending on given categories order
42 *
43 * The list of ordered categories id is supposed to be in the same parent
44 * category
45 *
46 * @param array categories
47 * @return void
48 */
49function save_categories_order($categories)
50{
51  $current_rank = 0;
52  $datas = array();
53  foreach ($categories as $id)
54  {
55    array_push($datas, array('id' => $id, 'rank' => ++$current_rank));
56  }
57  $fields = array('primary' => array('id'), 'update' => array('rank'));
58  mass_updates(CATEGORIES_TABLE, $fields, $datas);
59
60  update_global_rank(@$_GET['parent_id']);
61}
62
63// +-----------------------------------------------------------------------+
64// |                            initialization                             |
65// +-----------------------------------------------------------------------+
66
67$categories = array();
68
69$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
70$navigation = '<a class="" href="'.$base_url.'">';
71$navigation.= l10n('home');
72$navigation.= '</a>';
73
74// +-----------------------------------------------------------------------+
75// |                    virtual categories management                      |
76// +-----------------------------------------------------------------------+
77// request to delete a virtual category / not for an adviser
78if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
79{
80  delete_categories(array($_GET['delete']));
81  array_push($page['infos'], l10n('cat_virtual_deleted'));
82  ordering();
83  update_global_rank();
84}
85// request to add a virtual category
86else if (isset($_POST['submitAdd']))
87{
88  $output_create = create_virtual_category(
89    $_POST['virtual_name'],
90    @$_GET['parent_id']
91    );
92
93  if (isset($output_create['error']))
94  {
95    array_push($page['errors'], $output_create['error']);
96  }
97  else
98  {
99    array_push($page['infos'], $output_create['info']);
100  }
101}
102// save manual category ordering
103else if (isset($_POST['submitOrder']))
104{
105  asort($_POST['catOrd'], SORT_NUMERIC);
106  save_categories_order(array_keys($_POST['catOrd']));
107
108  array_push(
109    $page['infos'],
110    l10n('Categories manual order was saved')
111    );
112}
113// sort categories alpha-numerically
114else if (isset($_POST['submitOrderAlphaNum']))
115{
116  $query = '
117SELECT id, name
118  FROM '.CATEGORIES_TABLE.'
119  WHERE id_uppercat '.
120    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
121;';
122  $result = pwg_query($query);
123  while ($row = mysql_fetch_assoc($result))
124  {
125    $categories[ $row['id'] ] = strtolower($row['name']);
126  }
127
128  asort($categories, SORT_REGULAR);
129  save_categories_order(array_keys($categories));
130
131  array_push(
132    $page['infos'],
133    l10n('Categories ordered alphanumerically')
134    );
135}
136
137// +-----------------------------------------------------------------------+
138// |                            Navigation path                            |
139// +-----------------------------------------------------------------------+
140
141if (isset($_GET['parent_id']))
142{
143  $navigation.= $conf['level_separator'];
144
145  $navigation.= get_cat_display_name_from_id(
146    $_GET['parent_id'],
147    $base_url.'&amp;parent_id=',
148    false
149    );
150}
151// +-----------------------------------------------------------------------+
152// |                       template initialization                         |
153// +-----------------------------------------------------------------------+
154$template->set_filename('categories', 'admin/cat_list.tpl');
155
156$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
157if (isset($_GET['parent_id']))
158{
159  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
160}
161
162$template->assign(array(
163  'CATEGORIES_NAV'=>$navigation,
164  'F_ACTION'=>$form_action,
165 ));
166
167// +-----------------------------------------------------------------------+
168// |                          Categories display                           |
169// +-----------------------------------------------------------------------+
170
171$categories = array();
172
173$query = '
174SELECT id, name, permalink, dir, rank, nb_images, status
175  FROM '.CATEGORIES_TABLE;
176if (!isset($_GET['parent_id']))
177{
178  $query.= '
179  WHERE id_uppercat IS NULL';
180}
181else
182{
183  $query.= '
184  WHERE id_uppercat = '.$_GET['parent_id'];
185}
186$query.= '
187  ORDER BY rank ASC
188;';
189$result = pwg_query($query);
190while ($row = mysql_fetch_array($result))
191{
192  $categories[$row['id']] = $row;
193  // by default, let's consider there is no sub-categories. This will be
194  // calculated after.
195  $categories[$row['id']]['nb_subcats'] = 0;
196}
197
198if (count($categories) > 0)
199{
200  $query = '
201SELECT id_uppercat, COUNT(*) AS nb_subcats
202  FROM '. CATEGORIES_TABLE.'
203  WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
204  GROUP BY id_uppercat
205;';
206  $result = pwg_query($query);
207  while ($row = mysql_fetch_array($result))
208  {
209    $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
210  }
211}
212
213$template->assign('categories', array());
214foreach ($categories as $category)
215{
216  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
217  $cat_list_url = $base_url.'cat_list';
218
219  $self_url = $cat_list_url;
220  if (isset($_GET['parent_id']))
221  {
222    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
223  }
224
225  $tpl_cat =
226    array(
227      'NAME'       => $category['name'],
228      'ID'         => $category['id'],
229      'RANK'       => $category['rank']*10,
230
231      'U_JUMPTO'   => make_index_url(
232        array(
233          'category' => $category
234          )
235        ),
236
237      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
238      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
239     
240      'IS_VIRTUAL' => empty($category['dir'])
241    );
242
243  if (empty($category['dir']))
244  {
245    $tpl_cat['U_DELETE'] = $self_url.'&amp;delete='.$category['id'];
246  }
247
248  if ($category['nb_images'] > 0)
249  {
250    $tpl_cat['U_MANAGE_ELEMENTS']=
251      $base_url.'element_set&amp;cat='.$category['id'];
252  }
253
254  if ('private' == $category['status'])
255  {
256    $tpl_cat['U_MANAGE_PERMISSIONS']=
257      $base_url.'cat_perm&amp;cat='.$category['id'];
258  }
259  $template->append('categories', $tpl_cat);
260}
261// +-----------------------------------------------------------------------+
262// |                          sending html code                            |
263// +-----------------------------------------------------------------------+
264$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
265?>
Note: See TracBrowser for help on using the repository browser.