source: trunk/admin/cat_list.php @ 25489

Last change on this file since 25489 was 25425, checked in by mistic100, 10 years ago

delete replace_space function, modify get_cat_display_name_* functions

  • Property svn:eol-style set to LF
File size: 9.9 KB
Line 
1<?php
2// +-----------------------------------------------------------------------+
3// | Piwigo - a PHP based photo gallery                                    |
4// +-----------------------------------------------------------------------+
5// | Copyright(C) 2008-2013 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
36trigger_action('loc_begin_cat_list');
37
38if (!empty($_POST) or isset($_GET['delete']))
39{
40  check_pwg_token();
41}
42
43// +-----------------------------------------------------------------------+
44// |                               functions                               |
45// +-----------------------------------------------------------------------+
46
47/**
48 * save the rank depending on given categories order
49 *
50 * The list of ordered categories id is supposed to be in the same parent
51 * category
52 *
53 * @param array categories
54 * @return void
55 */
56function save_categories_order($categories)
57{
58  $current_rank_for_id_uppercat = array();
59  $current_rank = 0;
60 
61  $datas = array();
62  foreach ($categories as $category)
63  {
64    if (is_array($category))
65    {
66      $id = $category['id'];
67      $id_uppercat = $category['id_uppercat'];
68
69      if (!isset($current_rank_for_id_uppercat[$id_uppercat]))
70      {
71        $current_rank_for_id_uppercat[$id_uppercat] = 0;
72      }
73      $current_rank = ++$current_rank_for_id_uppercat[$id_uppercat];
74    }
75    else
76    {
77      $id = $category;
78      $current_rank++;
79    }
80   
81    $datas[] = array('id' => $id, 'rank' => $current_rank);
82  }
83  $fields = array('primary' => array('id'), 'update' => array('rank'));
84  mass_updates(CATEGORIES_TABLE, $fields, $datas);
85
86  update_global_rank();
87}
88
89// +-----------------------------------------------------------------------+
90// |                            initialization                             |
91// +-----------------------------------------------------------------------+
92
93check_input_parameter('parent_id', $_GET, false, PATTERN_ID);
94
95$categories = array();
96
97$base_url = get_root_url().'admin.php?page=cat_list';
98$navigation = '<a href="'.$base_url.'">';
99$navigation.= l10n('Home');
100$navigation.= '</a>';
101
102// +-----------------------------------------------------------------------+
103// | tabs                                                                  |
104// +-----------------------------------------------------------------------+
105
106$page['tab'] = 'list';
107include(PHPWG_ROOT_PATH.'admin/include/albums_tab.inc.php');
108
109// +-----------------------------------------------------------------------+
110// |                    virtual categories management                      |
111// +-----------------------------------------------------------------------+
112// request to delete a virtual category
113if (isset($_GET['delete']) and is_numeric($_GET['delete']))
114{
115  delete_categories(array($_GET['delete']));
116  $_SESSION['page_infos'] = array(l10n('Virtual album deleted'));
117  update_global_rank();
118
119  $redirect_url = get_root_url().'admin.php?page=cat_list';
120  if (isset($_GET['parent_id']))
121  {
122    $redirect_url.= '&parent_id='.$_GET['parent_id'];
123  } 
124  redirect($redirect_url);
125}
126// request to add a virtual category
127else if (isset($_POST['submitAdd']))
128{
129  $output_create = create_virtual_category(
130    $_POST['virtual_name'],
131    @$_GET['parent_id']
132    );
133
134  if (isset($output_create['error']))
135  {
136    $page['errors'][] = $output_create['error'];
137  }
138  else
139  {
140    $page['infos'][] = $output_create['info'];
141  }
142}
143// save manual category ordering
144else if (isset($_POST['submitManualOrder']))
145{
146  asort($_POST['catOrd'], SORT_NUMERIC);
147  save_categories_order(array_keys($_POST['catOrd']));
148
149  $page['infos'][] = l10n('Album manual order was saved');
150}
151else if (isset($_POST['submitAutoOrder']))
152{
153  $query = '
154SELECT id
155  FROM '.CATEGORIES_TABLE.'
156  WHERE id_uppercat '.
157    (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).'
158;';
159  $category_ids = array_from_query($query, 'id');
160
161  if (isset($_POST['recursive']))
162  {
163    $category_ids = get_subcat_ids($category_ids);
164  }
165 
166  $categories = array();
167  $names = array();
168  $id_uppercats = array();
169 
170  $query = '
171SELECT id, name, id_uppercat
172  FROM '.CATEGORIES_TABLE.'
173  WHERE id IN ('.implode(',', $category_ids).')
174;';
175  $result = pwg_query($query);
176  while ($row = pwg_db_fetch_assoc($result))
177  {
178    $categories[] = array(
179      'id' => $row['id'],
180      'id_uppercat' => $row['id_uppercat'],
181      );
182    $names[] = $row['name'];
183  }
184
185  array_multisort(
186    $names,
187    SORT_REGULAR,
188    'asc' == $_POST['ascdesc'] ? SORT_ASC : SORT_DESC,
189    $categories
190    );
191  save_categories_order($categories);
192
193  $page['infos'][] = l10n('Albums automatically sorted');
194}
195
196// +-----------------------------------------------------------------------+
197// |                            Navigation path                            |
198// +-----------------------------------------------------------------------+
199
200if (isset($_GET['parent_id']))
201{
202  $navigation.= $conf['level_separator'];
203
204  $navigation.= get_cat_display_name_from_id(
205    $_GET['parent_id'],
206    $base_url.'&amp;parent_id='
207    );
208}
209// +-----------------------------------------------------------------------+
210// |                       template initialization                         |
211// +-----------------------------------------------------------------------+
212$template->set_filename('categories', 'cat_list.tpl');
213
214$form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list';
215if (isset($_GET['parent_id']))
216{
217  $form_action.= '&amp;parent_id='.$_GET['parent_id'];
218}
219
220$template->assign(array(
221  'CATEGORIES_NAV'=>$navigation,
222  'F_ACTION'=>$form_action,
223  'PWG_TOKEN' => get_pwg_token(),
224 ));
225
226// +-----------------------------------------------------------------------+
227// |                          Categories display                           |
228// +-----------------------------------------------------------------------+
229
230$categories = array();
231
232$query = '
233SELECT id, name, permalink, dir, rank, status
234  FROM '.CATEGORIES_TABLE;
235if (!isset($_GET['parent_id']))
236{
237  $query.= '
238  WHERE id_uppercat IS NULL';
239}
240else
241{
242  $query.= '
243  WHERE id_uppercat = '.$_GET['parent_id'];
244}
245$query.= '
246  ORDER BY rank ASC
247;';
248$categories = hash_from_query($query, 'id');
249
250// get the categories containing images directly
251$categories_with_images = array();
252if ( count($categories) )
253{
254  $query = '
255SELECT DISTINCT category_id
256  FROM '.IMAGE_CATEGORY_TABLE.'
257  WHERE category_id IN ('.implode(',', array_keys($categories)).')';
258  $categories_with_images = array_flip( array_from_query($query, 'category_id') );
259}
260
261$template->assign('categories', array());
262$base_url = get_root_url().'admin.php?page=';
263
264if (isset($_GET['parent_id']))
265{
266  $template->assign(
267    'PARENT_EDIT',
268    $base_url.'album-'.$_GET['parent_id']
269    );
270}
271
272foreach ($categories as $category)
273{
274  $cat_list_url = $base_url.'cat_list';
275
276  $self_url = $cat_list_url;
277  if (isset($_GET['parent_id']))
278  {
279    $self_url.= '&amp;parent_id='.$_GET['parent_id'];
280  }
281
282  $tpl_cat =
283    array(
284      'NAME'       => 
285        trigger_event(
286          'render_category_name',
287          $category['name'],
288          'admin_cat_list'
289          ),
290      'ID'         => $category['id'],
291      'RANK'       => $category['rank']*10,
292
293      'U_JUMPTO'   => make_index_url(
294        array(
295          'category' => $category
296          )
297        ),
298
299      'U_CHILDREN' => $cat_list_url.'&amp;parent_id='.$category['id'],
300      'U_EDIT'     => $base_url.'album-'.$category['id'],
301
302      'IS_VIRTUAL' => empty($category['dir'])
303    );
304
305  if (empty($category['dir']))
306  {
307    $tpl_cat['U_DELETE'] = $self_url.'&amp;delete='.$category['id'];
308    $tpl_cat['U_DELETE'].= '&amp;pwg_token='.get_pwg_token();
309  }
310  else
311  {
312    if ($conf['enable_synchronization'])
313    {
314      $tpl_cat['U_SYNC'] = $base_url.'site_update&amp;site=1&amp;cat_id='.$category['id'];
315    }
316  }
317
318  if ( array_key_exists($category['id'], $categories_with_images) )
319  {
320    $tpl_cat['U_MANAGE_ELEMENTS']=
321      $base_url.'batch_manager&amp;filter=album-'.$category['id'];
322  }
323
324  $template->append('categories', $tpl_cat);
325}
326
327trigger_action('loc_end_cat_list');
328
329// +-----------------------------------------------------------------------+
330// |                          sending html code                            |
331// +-----------------------------------------------------------------------+
332$template->assign_var_from_handle('ADMIN_CONTENT', 'categories');
333?>
Note: See TracBrowser for help on using the repository browser.