source: trunk/admin/cat_list.php @ 1656

Last change on this file since 1656 was 1529, checked in by nikrou, 18 years ago

fix bug 510: missing permission link
svn merge -r1527:1528 from branch 1.6 into trunk

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.7 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | branch        : BSF (Best So Far)
8// | file          : $RCSfile$
9// | last update   : $Date: 2006-08-09 12:34:55 +0000 (Wed, 09 Aug 2006) $
10// | last modifier : $Author: nikrou $
11// | revision      : $Revision: 1529 $
12// +-----------------------------------------------------------------------+
13// | This program is free software; you can redistribute it and/or modify  |
14// | it under the terms of the GNU General Public License as published by  |
15// | the Free Software Foundation                                          |
16// |                                                                       |
17// | This program is distributed in the hope that it will be useful, but   |
18// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
19// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
20// | General Public License for more details.                              |
21// |                                                                       |
22// | You should have received a copy of the GNU General Public License     |
23// | along with this program; if not, write to the Free Software           |
24// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
25// | USA.                                                                  |
26// +-----------------------------------------------------------------------+
27
28if (!defined('PHPWG_ROOT_PATH'))
29{
30  die('Hacking attempt!');
31}
32
33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
35// +-----------------------------------------------------------------------+
36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40// +-----------------------------------------------------------------------+
41// |                               functions                               |
42// +-----------------------------------------------------------------------+
43
44/**
45 * save the rank depending on given categories order
46 *
47 * The list of ordered categories id is supposed to be in the same parent
48 * category
49 *
50 * @param array categories
51 * @return void
52 */
53function save_categories_order($categories)
54{
55  $current_rank = 0;
56  $datas = array();
57  foreach ($categories as $id)
58  {
59    array_push($datas, array('id' => $id, 'rank' => ++$current_rank));
60  }
61  $fields = array('primary' => array('id'), 'update' => array('rank'));
62  mass_updates(CATEGORIES_TABLE, $fields, $datas);
63
64  update_global_rank(@$_GET['parent_id']);
65}
66
67// +-----------------------------------------------------------------------+
68// |                            initialization                             |
69// +-----------------------------------------------------------------------+
70
71$categories = array();
72
73$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
74$navigation = '<a class="" href="'.$base_url.'">';
75$navigation.= $lang['home'];
76$navigation.= '</a>';
77
78// +-----------------------------------------------------------------------+
79// |                    virtual categories management                      |
80// +-----------------------------------------------------------------------+
81// request to delete a virtual category / not for an adviser
82if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
83{
84  delete_categories(array($_GET['delete']));
85  array_push($page['infos'], $lang['cat_virtual_deleted']);
86  ordering();
87  update_global_rank();
88}
89// request to add a virtual category
90else if (isset($_POST['submitAdd']))
91{
92  $output_create = create_virtual_category(
93    $_POST['virtual_name'],
94    @$_GET['parent_id']
95    );
96
97  if (isset($output_create['error']))
98  {
99    array_push($page['errors'], $output_create['error']);
100  }
101  else
102  {
103    array_push($page['infos'], $output_create['info']);
104  }
105}
106// save manual category ordering
107else if (isset($_POST['submitOrder']))
108{
109  asort($_POST['catOrd'], SORT_NUMERIC);
110  save_categories_order(array_keys($_POST['catOrd']));
111
112  array_push(
113    $page['infos'],
114    l10n('Categories manual order was saved')
115    );
116}
117// sort categories alpha-numerically
118else if (isset($_POST['submitOrderAlphaNum']))
119{
120  $query = '
121SELECT id, name
122  FROM '.CATEGORIES_TABLE.'
123  WHERE id_uppercat '.
124    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
125;';
126  $result = pwg_query($query);
127  while ($row = mysql_fetch_assoc($result))
128  {
129    $categories[ $row['id'] ] = strtolower($row['name']);
130  }
131
132  asort($categories, SORT_REGULAR);
133  save_categories_order(array_keys($categories));
134
135  array_push(
136    $page['infos'],
137    l10n('Categories ordered alphanumerically')
138    );
139}
140
141// +-----------------------------------------------------------------------+
142// |                           Cache management                            |
143// +-----------------------------------------------------------------------+
144$query = '
145SELECT *
146  FROM '.CATEGORIES_TABLE;
147if (!isset($_GET['parent_id']))
148{
149  $query.= '
150  WHERE id_uppercat IS NULL';
151}
152else
153{
154  $query.= '
155  WHERE id_uppercat = '.$_GET['parent_id'];
156}
157$query.= '
158  ORDER BY rank ASC
159;';
160$result = pwg_query($query);
161while ($row = mysql_fetch_assoc($result))
162{
163  $categories[$row['rank']] = $row;
164  $categories[$row['rank']]['nb_subcats'] = 0;
165}
166
167// +-----------------------------------------------------------------------+
168// |                            Navigation path                            |
169// +-----------------------------------------------------------------------+
170
171if (isset($_GET['parent_id']))
172{
173  $navigation.= $conf['level_separator'];
174
175  $current_category = get_cat_info($_GET['parent_id']);
176
177  $navigation.= get_cat_display_name(
178    $current_category['name'],
179    $base_url.'&amp;parent_id=',
180    false
181    );
182}
183// +-----------------------------------------------------------------------+
184// |                       template initialization                         |
185// +-----------------------------------------------------------------------+
186$template->set_filenames(array('categories'=>'admin/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_vars(array(
195  'CATEGORIES_NAV'=>$navigation,
196  'F_ACTION'=>$form_action,
197
198  'L_ADD_VIRTUAL'=>$lang['cat_add'],
199  'L_SUBMIT'=>$lang['submit'],
200  'L_STORAGE'=>$lang['storage'],
201  'L_NB_IMG'=>$lang['pictures'],
202  'L_MOVE_UP'=>$lang['up'],
203  'L_EDIT'=>$lang['edit'],
204  'L_DELETE'=>$lang['delete'],
205 ));
206
207$tpl = array('cat_first','cat_last');
208// +-----------------------------------------------------------------------+
209// |                          Categories display                           |
210// +-----------------------------------------------------------------------+
211
212$categories = array();
213
214$query = '
215SELECT id, name, dir, rank, nb_images, status
216  FROM '.CATEGORIES_TABLE;
217if (!isset($_GET['parent_id']))
218{
219  $query.= '
220  WHERE id_uppercat IS NULL';
221}
222else
223{
224  $query.= '
225  WHERE id_uppercat = '.$_GET['parent_id'];
226}
227$query.= '
228  ORDER BY rank ASC
229;';
230$result = pwg_query($query);
231while ($row = mysql_fetch_array($result))
232{
233  $categories[$row['id']] = $row;
234  // by default, let's consider there is no sub-categories. This will be
235  // calculated after.
236  $categories[$row['id']]['nb_subcats'] = 0;
237}
238
239if (count($categories) > 0)
240{
241  $query = '
242SELECT id_uppercat, COUNT(*) AS nb_subcats
243  FROM '. CATEGORIES_TABLE.'
244  WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
245  GROUP BY id_uppercat
246;';
247  $result = pwg_query($query);
248  while ($row = mysql_fetch_array($result))
249  {
250    $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
251  }
252
253  $template->assign_block_vars('categories', array());
254}
255
256foreach ($categories as $category)
257{
258  // TODO : not used anymore ?
259  //$images_folder = PHPWG_ROOT_PATH.'template/';
260  //$images_folder.= $user['template'].'/admin/images';
261
262  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
263  $cat_list_url = $base_url.'cat_list';
264
265  $self_url = $cat_list_url;
266  if (isset($_GET['parent_id']))
267  {
268    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
269  }
270
271  $template->assign_block_vars(
272    'categories.category',
273    array(
274      'NAME'       => $category['name'],
275      'ID'         => $category['id'],
276      'RANK'       => $category['rank']*10,
277
278      'U_JUMPTO'   => make_index_url(
279        array(
280          'category' => $category['id'],
281          'cat_name' => $category['name'],
282          )
283        ),
284
285      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
286      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
287      )
288    );
289
290  if (empty($category['dir']))
291  {
292    $template->assign_block_vars(
293      'categories.category.delete',
294      array(
295        'URL'=>$self_url.'&amp;delete='.$category['id']
296        )
297      );
298  }
299
300  if ($category['nb_images'] > 0)
301  {
302    $template->assign_block_vars(
303      'categories.category.elements',
304      array(
305        'URL'=>$base_url.'element_set&amp;cat='.$category['id']
306        )
307      );
308  }
309
310  if ('private' == $category['status'])
311  {
312    $template->assign_block_vars(
313      'categories.category.permissions',
314      array(
315        'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
316        )
317      );
318  }
319}
320// +-----------------------------------------------------------------------+
321// |                          sending html code                            |
322// +-----------------------------------------------------------------------+
323$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
324?>
Note: See TracBrowser for help on using the repository browser.