source: branches/branch-1_7/admin/cat_list.php @ 1936

Last change on this file since 1936 was 1900, checked in by rub, 18 years ago

Apply property svn:eol-style Value: LF

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