source: trunk/admin/cat_list.php @ 2223

Last change on this file since 2223 was 2223, checked in by rvelices, 16 years ago
  • migrate many templates to smarty
  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 8.4 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-2008 PhpWebGallery Team - http://phpwebgallery.net |
6// +-----------------------------------------------------------------------+
7// | file          : $Id: cat_list.php 2223 2008-02-28 02:41:48Z rvelices $
8// | last update   : $Date: 2008-02-28 02:41:48 +0000 (Thu, 28 Feb 2008) $
9// | last modifier : $Author: rvelices $
10// | revision      : $Revision: 2223 $
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.= l10n('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'], l10n('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_filename('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(array(
166  'CATEGORIES_NAV'=>$navigation,
167  'F_ACTION'=>$form_action,
168 ));
169
170// +-----------------------------------------------------------------------+
171// |                          Categories display                           |
172// +-----------------------------------------------------------------------+
173
174$categories = array();
175
176$query = '
177SELECT id, name, permalink, dir, rank, nb_images, status
178  FROM '.CATEGORIES_TABLE;
179if (!isset($_GET['parent_id']))
180{
181  $query.= '
182  WHERE id_uppercat IS NULL';
183}
184else
185{
186  $query.= '
187  WHERE id_uppercat = '.$_GET['parent_id'];
188}
189$query.= '
190  ORDER BY rank ASC
191;';
192$result = pwg_query($query);
193while ($row = mysql_fetch_array($result))
194{
195  $categories[$row['id']] = $row;
196  // by default, let's consider there is no sub-categories. This will be
197  // calculated after.
198  $categories[$row['id']]['nb_subcats'] = 0;
199}
200
201if (count($categories) > 0)
202{
203  $query = '
204SELECT id_uppercat, COUNT(*) AS nb_subcats
205  FROM '. CATEGORIES_TABLE.'
206  WHERE id_uppercat IN ('.implode(',', array_keys($categories)).')
207  GROUP BY id_uppercat
208;';
209  $result = pwg_query($query);
210  while ($row = mysql_fetch_array($result))
211  {
212    $categories[$row['id_uppercat']]['nb_subcats'] = $row['nb_subcats'];
213  }
214}
215
216$template->assign('categories', array());
217foreach ($categories as $category)
218{
219  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
220  $cat_list_url = $base_url.'cat_list';
221
222  $self_url = $cat_list_url;
223  if (isset($_GET['parent_id']))
224  {
225    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
226  }
227
228  $tpl_cat =
229    array(
230      'NAME'       => $category['name'],
231      'ID'         => $category['id'],
232      'RANK'       => $category['rank']*10,
233
234      'U_JUMPTO'   => make_index_url(
235        array(
236          'category' => $category
237          )
238        ),
239
240      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
241      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
242     
243      'IS_VIRTUAL' => empty($category['dir'])
244    );
245
246  if (empty($category['dir']))
247  {
248    $tpl_cat['U_DELETE'] = $self_url.'&amp;delete='.$category['id'];
249  }
250
251  if ($category['nb_images'] > 0)
252  {
253    $tpl_cat['U_MANAGE_ELEMENTS']=
254      $base_url.'element_set&amp;cat='.$category['id'];
255  }
256
257  if ('private' == $category['status'])
258  {
259    $tpl_cat['U_MANAGE_PERMISSIONS']=
260      $base_url.'cat_perm&amp;cat='.$category['id'];
261  }
262  $template->append('categories', $tpl_cat);
263}
264// +-----------------------------------------------------------------------+
265// |                          sending html code                            |
266// +-----------------------------------------------------------------------+
267$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
268?>
Note: See TracBrowser for help on using the repository browser.