source: branches/gettext/admin/cat_list.php @ 5283

Last change on this file since 5283 was 5079, checked in by Gotcha, 15 years ago

Trunk merge r5076 from bug:1119
bug:1119

  • Property svn:eol-style set to LF
File size: 8.8 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based picture gallery                                  |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2009 Piwigo Team                  http://piwigo.org |
6// | Copyright(C) 2003-2008 PhpWebGallery Team    http://phpwebgallery.net |
7// | Copyright(C) 2002-2003 Pierrick LE GALL   http://le-gall.net/pierrick |
8// +-----------------------------------------------------------------------+
9// | This program is free software; you can redistribute it and/or modify  |
10// | it under the terms of the GNU General Public License as published by  |
11// | the Free Software Foundation                                          |
12// |                                                                       |
13// | This program is distributed in the hope that it will be useful, but   |
14// | WITHOUT ANY WARRANTY; without even the implied warranty of            |
15// | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU      |
16// | General Public License for more details.                              |
17// |                                                                       |
18// | You should have received a copy of the GNU General Public License     |
19// | along with this program; if not, write to the Free Software           |
20// | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
21// | USA.                                                                  |
22// +-----------------------------------------------------------------------+
23
24if (!defined('PHPWG_ROOT_PATH'))
25{
26  die('Hacking attempt!');
27}
28
29include_once(PHPWG_ROOT_PATH.'admin/include/functions.php');
30
31// +-----------------------------------------------------------------------+
32// | Check Access and exit when user status is not ok                      |
33// +-----------------------------------------------------------------------+
34check_status(ACCESS_ADMINISTRATOR);
35
36// +-----------------------------------------------------------------------+
37// |                               functions                               |
38// +-----------------------------------------------------------------------+
39
40/**
41 * save the rank depending on given categories order
42 *
43 * The list of ordered categories id is supposed to be in the same parent
44 * category
45 *
46 * @param array categories
47 * @return void
48 */
49function save_categories_order($categories)
50{
51  $current_rank = 0;
52  $datas = array();
53  foreach ($categories as $id)
54  {
55    array_push($datas, array('id' => $id, 'rank' => ++$current_rank));
56  }
57  $fields = array('primary' => array('id'), 'update' => array('rank'));
58  mass_updates(CATEGORIES_TABLE, $fields, $datas);
59
60  update_global_rank();
61}
62
63// +-----------------------------------------------------------------------+
64// |                            initialization                             |
65// +-----------------------------------------------------------------------+
66
67$categories = array();
68
69$base_url = get_root_url().'admin.php?page=cat_list';
70$navigation = '<a href="'.$base_url.'">';
71$navigation.= l10n('Home');
72$navigation.= '</a>';
73
74// +-----------------------------------------------------------------------+
75// |                    virtual categories management                      |
76// +-----------------------------------------------------------------------+
77// request to delete a virtual category / not for an adviser
78if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser())
79{
80  delete_categories(array($_GET['delete']));
81  array_push($page['infos'], l10n('Virtual category deleted'));
82  update_global_rank();
83}
84// request to add a virtual category
85else if (isset($_POST['submitAdd']))
86{
87  $output_create = create_virtual_category(
88    $_POST['virtual_name'],
89    @$_GET['parent_id']
90    );
91
92  if (isset($output_create['error']))
93  {
94    array_push($page['errors'], $output_create['error']);
95  }
96  else
97  {
98    array_push($page['infos'], $output_create['info']);
99  }
100}
101// save manual category ordering
102else if (isset($_POST['submitOrder']))
103{
104  asort($_POST['catOrd'], SORT_NUMERIC);
105  save_categories_order(array_keys($_POST['catOrd']));
106
107  array_push(
108    $page['infos'],
109    l10n('Categories manual order was saved')
110    );
111}
112// sort categories alpha-numerically
113else if (isset($_POST['submitOrderAlphaNum']))
114{
115  $query = '
116SELECT id, name
117  FROM '.CATEGORIES_TABLE.'
118  WHERE id_uppercat '.
119    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
120;';
121  $result = pwg_query($query);
122  while ($row = pwg_db_fetch_assoc($result))
123  {
124    $categories[ $row['id'] ] = strtolower($row['name']);
125  }
126
127  asort($categories, SORT_REGULAR);
128  save_categories_order(array_keys($categories));
129
130  array_push(
131    $page['infos'],
132    l10n('Categories ordered alphanumerically')
133    );
134}
135// sort categories alpha-numerically reverse
136else if (isset($_POST['submitOrderAlphaNumReverse']))
137{
138  $query = '
139SELECT id, name
140  FROM '.CATEGORIES_TABLE.'
141  WHERE id_uppercat '.
142    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
143;';
144  $result = pwg_query($query);
145  while ($row = pwg_db_fetch_assoc($result))
146  {
147    $categories[ $row['id'] ] = strtolower($row['name']);
148  }
149
150  arsort($categories, SORT_REGULAR);
151  save_categories_order(array_keys($categories));
152
153  array_push(
154    $page['infos'],
155    l10n('Categories ordered alphanumerically reverse')
156    );
157}
158
159// +-----------------------------------------------------------------------+
160// |                            Navigation path                            |
161// +-----------------------------------------------------------------------+
162
163if (isset($_GET['parent_id']))
164{
165  $navigation.= $conf['level_separator'];
166
167  $navigation.= get_cat_display_name_from_id(
168    $_GET['parent_id'],
169    $base_url.'&amp;parent_id=',
170    false
171    );
172}
173// +-----------------------------------------------------------------------+
174// |                       template initialization                         |
175// +-----------------------------------------------------------------------+
176$template->set_filename('categories', 'cat_list.tpl');
177
178$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
179if (isset($_GET['parent_id']))
180{
181  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
182}
183
184$template->assign(array(
185  'CATEGORIES_NAV'=>$navigation,
186  'F_ACTION'=>$form_action,
187 ));
188
189// +-----------------------------------------------------------------------+
190// |                          Categories display                           |
191// +-----------------------------------------------------------------------+
192
193$categories = array();
194
195$query = '
196SELECT id, name, permalink, dir, rank, status
197  FROM '.CATEGORIES_TABLE;
198if (!isset($_GET['parent_id']))
199{
200  $query.= '
201  WHERE id_uppercat IS NULL';
202}
203else
204{
205  $query.= '
206  WHERE id_uppercat = '.$_GET['parent_id'];
207}
208$query.= '
209  ORDER BY rank ASC
210;';
211$categories = hash_from_query($query, 'id');
212
213// get the categories containing images directly
214$categories_with_images = array();
215if ( count($categories) )
216{
217  $query = '
218SELECT DISTINCT category_id
219  FROM '.IMAGE_CATEGORY_TABLE.'
220  WHERE category_id IN ('.implode(',', array_keys($categories)).')';
221  $categories_with_images = array_flip( array_from_query($query, 'category_id') );
222}
223
224$template->assign('categories', array());
225$base_url = get_root_url().'admin.php?page=';
226foreach ($categories as $category)
227{
228  $cat_list_url = $base_url.'cat_list';
229
230  $self_url = $cat_list_url;
231  if (isset($_GET['parent_id']))
232  {
233    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
234  }
235
236  $tpl_cat =
237    array(
238      'NAME'       => 
239        trigger_event(
240          'render_category_name',
241          $category['name'],
242          'admin_cat_list'
243          ),
244      'ID'         => $category['id'],
245      'RANK'       => $category['rank']*10,
246
247      'U_JUMPTO'   => make_index_url(
248        array(
249          'category' => $category
250          )
251        ),
252
253      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
254      'U_EDIT'     => $base_url.'cat_modify&amp;cat_id='.$category['id'],
255
256      'IS_VIRTUAL' => empty($category['dir'])
257    );
258
259  if (empty($category['dir']))
260  {
261    $tpl_cat['U_DELETE'] = $self_url.'&amp;delete='.$category['id'];
262  }
263
264  if ( array_key_exists($category['id'], $categories_with_images) )
265  {
266    $tpl_cat['U_MANAGE_ELEMENTS']=
267      $base_url.'element_set&amp;cat='.$category['id'];
268  }
269
270  if ('private' == $category['status'])
271  {
272    $tpl_cat['U_MANAGE_PERMISSIONS']=
273      $base_url.'cat_perm&amp;cat='.$category['id'];
274  }
275  $template->append('categories', $tpl_cat);
276}
277// +-----------------------------------------------------------------------+
278// |                          sending html code                            |
279// +-----------------------------------------------------------------------+
280$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
281?>
Note: See TracBrowser for help on using the repository browser.