source: trunk/admin/cat_list.php @ 1596

Last change on this file since 1596 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
RevLine 
[21]1<?php
[362]2// +-----------------------------------------------------------------------+
[593]3// | PhpWebGallery - a PHP based picture gallery                           |
4// | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net |
[675]5// | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net |
[362]6// +-----------------------------------------------------------------------+
[593]7// | branch        : BSF (Best So Far)
[362]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// +-----------------------------------------------------------------------+
[345]27
[580]28if (!defined('PHPWG_ROOT_PATH'))
[394]29{
[580]30  die('Hacking attempt!');
[394]31}
[798]32
[1072]33include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
34
[580]35// +-----------------------------------------------------------------------+
[1072]36// | Check Access and exit when user status is not ok                      |
37// +-----------------------------------------------------------------------+
38check_status(ACCESS_ADMINISTRATOR);
39
40// +-----------------------------------------------------------------------+
[798]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// +-----------------------------------------------------------------------+
[580]68// |                            initialization                             |
69// +-----------------------------------------------------------------------+
[834]70
[580]71$categories = array();
[834]72
73$base_url = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
[1004]74$navigation = '<a class="" href="'.$base_url.'">';
[834]75$navigation.= $lang['home'];
76$navigation.= '</a>';
77
[580]78// +-----------------------------------------------------------------------+
79// |                    virtual categories management                      |
80// +-----------------------------------------------------------------------+
[1106]81// request to delete a virtual category / not for an adviser
82if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
[68]83{
[659]84  delete_categories(array($_GET['delete']));
[792]85  array_push($page['infos'], $lang['cat_virtual_deleted']);
[659]86  ordering();
87  update_global_rank();
[394]88}
[602]89// request to add a virtual category
[798]90else if (isset($_POST['submitAdd']))
[394]91{
[1064]92  $output_create = create_virtual_category(
93    $_POST['virtual_name'],
94    @$_GET['parent_id']
95    );
96
97  if (isset($output_create['error']))
[580]98  {
[1064]99    array_push($page['errors'], $output_create['error']);
[580]100  }
[1064]101  else
[68]102  {
[1064]103    array_push($page['infos'], $output_create['info']);
[68]104  }
105}
[1066]106// save manual category ordering
[798]107else if (isset($_POST['submitOrder']))
108{
109  asort($_POST['catOrd'], SORT_NUMERIC);
110  save_categories_order(array_keys($_POST['catOrd']));
[1066]111
112  array_push(
113    $page['infos'],
114    l10n('Categories manual order was saved')
115    );
[798]116}
[1066]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  {
[1225]129    $categories[ $row['id'] ] = strtolower($row['name']);
[1066]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
[580]141// +-----------------------------------------------------------------------+
142// |                           Cache management                            |
143// +-----------------------------------------------------------------------+
144$query = '
145SELECT *
146  FROM '.CATEGORIES_TABLE;
147if (!isset($_GET['parent_id']))
[394]148{
[580]149  $query.= '
150  WHERE id_uppercat IS NULL';
[394]151}
152else
153{
[580]154  $query.= '
155  WHERE id_uppercat = '.$_GET['parent_id'];
[394]156}
[580]157$query.= '
158  ORDER BY rank ASC
159;';
[587]160$result = pwg_query($query);
[580]161while ($row = mysql_fetch_assoc($result))
[394]162{
[580]163  $categories[$row['rank']] = $row;
[642]164  $categories[$row['rank']]['nb_subcats'] = 0;
[394]165}
[834]166
[580]167// +-----------------------------------------------------------------------+
168// |                            Navigation path                            |
169// +-----------------------------------------------------------------------+
[834]170
[394]171if (isset($_GET['parent_id']))
172{
[642]173  $navigation.= $conf['level_separator'];
[580]174
[394]175  $current_category = get_cat_info($_GET['parent_id']);
[1131]176
[1064]177  $navigation.= get_cat_display_name(
178    $current_category['name'],
179    $base_url.'&amp;parent_id=',
180    false
181    );
[394]182}
[580]183// +-----------------------------------------------------------------------+
184// |                       template initialization                         |
185// +-----------------------------------------------------------------------+
186$template->set_filenames(array('categories'=>'admin/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
[394]194$template->assign_vars(array(
195  'CATEGORIES_NAV'=>$navigation,
[1004]196  'F_ACTION'=>$form_action,
[1131]197
[394]198  'L_ADD_VIRTUAL'=>$lang['cat_add'],
199  'L_SUBMIT'=>$lang['submit'],
200  'L_STORAGE'=>$lang['storage'],
201  'L_NB_IMG'=>$lang['pictures'],
[622]202  'L_MOVE_UP'=>$lang['up'],
[394]203  'L_EDIT'=>$lang['edit'],
[580]204  'L_DELETE'=>$lang['delete'],
205 ));
[1131]206
[580]207$tpl = array('cat_first','cat_last');
208// +-----------------------------------------------------------------------+
209// |                          Categories display                           |
210// +-----------------------------------------------------------------------+
[647]211
[798]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
[647]239if (count($categories) > 0)
[580]240{
[647]241  $query = '
[642]242SELECT id_uppercat, COUNT(*) AS nb_subcats
243  FROM '. CATEGORIES_TABLE.'
[798]244  WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
[642]245  GROUP BY id_uppercat
246;';
[647]247  $result = pwg_query($query);
248  while ($row = mysql_fetch_array($result))
249  {
[798]250    $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
[647]251  }
[1348]252
253  $template->assign_block_vars('categories', array());
[642]254}
255
256foreach ($categories as $category)
257{
[960]258  // TODO : not used anymore ?
259  //$images_folder = PHPWG_ROOT_PATH.'template/';
260  //$images_folder.= $user['template'].'/admin/images';
[1131]261
[580]262  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
263  $cat_list_url = $base_url.'cat_list';
[1131]264
[580]265  $self_url = $cat_list_url;
[394]266  if (isset($_GET['parent_id']))
[580]267  {
268    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
269  }
[394]270
[580]271  $template->assign_block_vars(
[1348]272    'categories.category',
[580]273    array(
[1082]274      'NAME'       => $category['name'],
275      'ID'         => $category['id'],
276      'RANK'       => $category['rank']*10,
[798]277
[1082]278      'U_JUMPTO'   => make_index_url(
279        array(
280          'category' => $category['id'],
[1131]281          'cat_name' => $category['name'],
[1082]282          )
283        ),
[1131]284
285      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
[1082]286      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
[798]287      )
288    );
[1131]289
[798]290  if (empty($category['dir']))
[21]291  {
[798]292    $template->assign_block_vars(
[1348]293      'categories.category.delete',
[798]294      array(
[1004]295        'URL'=>$self_url.'&amp;delete='.$category['id']
[798]296        )
297      );
[21]298  }
[1131]299
[580]300  if ($category['nb_images'] > 0)
301  {
[798]302    $template->assign_block_vars(
[1348]303      'categories.category.elements',
[798]304      array(
[1004]305        'URL'=>$base_url.'element_set&amp;cat='.$category['id']
[798]306        )
307      );
[21]308  }
[798]309
310  if ('private' == $category['status'])
[394]311  {
[798]312    $template->assign_block_vars(
[1529]313      'categories.category.permissions',
[798]314      array(
[1004]315        'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
[798]316        )
317      );
[394]318  }
[21]319}
[580]320// +-----------------------------------------------------------------------+
321// |                          sending html code                            |
322// +-----------------------------------------------------------------------+
[394]323$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
[362]324?>
Note: See TracBrowser for help on using the repository browser.