source: trunk/admin/cat_list.php @ 1072

Last change on this file since 1072 was 1072, checked in by rub, 19 years ago

Step 2 improvement issue 0000301:

o Add and use Functions Check of status
o Restricted Access for user generic

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.5 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-03-09 22:46:28 +0000 (Thu, 09 Mar 2006) $
10// | last modifier : $Author: rub $
11// | revision      : $Revision: 1072 $
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
82if (isset($_GET['delete']) and is_numeric($_GET['delete']))
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'] ] = $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
254foreach ($categories as $category)
255{
256  // TODO : not used anymore ?
257  //$images_folder = PHPWG_ROOT_PATH.'template/';
258  //$images_folder.= $user['template'].'/admin/images';
259 
260  $base_url = PHPWG_ROOT_PATH.'admin.php?page=';
261  $cat_list_url = $base_url.'cat_list';
262 
263  $self_url = $cat_list_url;
264  if (isset($_GET['parent_id']))
265  {
266    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
267  }
268
269  $template->assign_block_vars(
270    'category',
271    array(
272      'NAME'=>$category['name'],
273      'ID'=>$category['id'],
274      'RANK'=>$category['rank']*10,
275
276      'U_JUMPTO'=>PHPWG_ROOT_PATH.'category.php?cat='.$category['id'],
277      'U_CHILDREN'=>$cat_list_url.'&amp;parent_id='.$category['id'],     
278      'U_EDIT'=>$base_url.'cat_modify&amp;cat_id='.$category['id']
279      )
280    );
281 
282  if (empty($category['dir']))
283  {
284    $template->assign_block_vars(
285      'category.delete',
286      array(
287        'URL'=>$self_url.'&amp;delete='.$category['id']
288        )
289      );
290  }
291 
292  if ($category['nb_images'] > 0)
293  {
294    $template->assign_block_vars(
295      'category.elements',
296      array(
297        'URL'=>$base_url.'element_set&amp;cat='.$category['id']
298        )
299      );
300  }
301
302  if ('private' == $category['status'])
303  {
304    $template->assign_block_vars(
305      'category.permissions',
306      array(
307        'URL'=>$base_url.'cat_perm&amp;cat='.$category['id']
308        )
309      );
310  }
311}
312// +-----------------------------------------------------------------------+
313// |                          sending html code                            |
314// +-----------------------------------------------------------------------+
315$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
316?>
Note: See TracBrowser for help on using the repository browser.