source: extensions/SmartAlbums/admin/cat_list.php @ 17879

Last change on this file since 17879 was 16104, checked in by mistic100, 12 years ago

updated for Piwigo 2.4
new filters : name, author, level, hits

File size: 5.2 KB
Line 
1<?php
2if (!defined('PHPWG_ROOT_PATH')) die('Hacking attempt!');
3
4if (isset($_GET['hide_messages']))
5{
6  $conf['SmartAlbums']['show_list_messages'] = false;
7  conf_update_param('SmartAlbums', serialize($conf['SmartAlbums']));
8}
9
10// +-----------------------------------------------------------------------+
11// |                            initialization                             |
12// +-----------------------------------------------------------------------+
13$base_url = get_root_url() . 'admin.php?page=';
14$self_url = SMART_ADMIN . '-cat_list';
15
16$categories = array();
17$query = '
18SELECT
19    id,
20    name,
21    permalink,
22    dir,
23    rank,
24    status
25  FROM '.CATEGORIES_TABLE.' AS cat
26  INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
27    ON cf.category_id = cat.id
28  ORDER BY rank ASC
29;';
30$categories = hash_from_query($query, 'id');
31
32// +-----------------------------------------------------------------------+
33// |                    virtual categories management                      |
34// +-----------------------------------------------------------------------+
35// request to delete a album
36if (isset($_GET['delete']) and is_numeric($_GET['delete']))
37{
38  delete_categories(array($_GET['delete']));
39  $_SESSION['page_infos'] = array(l10n('SmartAlbum deleted'));
40  update_global_rank();
41  redirect($self_url);
42}
43// request to add a album
44else if (isset($_POST['submitAdd']))
45{
46  $output_create = create_virtual_category(
47    $_POST['virtual_name'],
48    @$_POST['parent_id']
49    );
50
51  if (isset($output_create['error']))
52  {
53    array_push($page['errors'], $output_create['error']);
54  }
55  else
56  {
57    $_SESSION['page_infos'] = array(l10n('SmartAlbum added'));
58    $redirect_url = SMART_ADMIN . '-album&amp;cat_id='.$output_create['id'].'&amp;new_smart';
59    redirect($redirect_url);
60  }
61}
62// request to regeneration
63else if (isset($_GET['smart_generate']))
64{
65  /* regenerate photo list | all categories */
66  if ($_GET['smart_generate'] == 'all')
67  {
68    foreach ($categories as $category)
69    {
70      $associated_images = smart_make_associations($category['id']);
71      array_push($page['infos'], 
72        sprintf(l10n('%d photos associated to album %s'), 
73          count($associated_images), 
74          '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
75          )
76        );
77    }
78  }
79  /* regenerate photo list | one category */
80  else
81  {
82    $associated_images = smart_make_associations($_GET['smart_generate']);   
83    array_push($page['infos'], 
84      sprintf(l10n('%d photos associated to album %s'), 
85        count($associated_images), 
86        '&laquo;'.trigger_event('render_category_name', $categories[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
87        )
88      );
89  }
90 
91  define('SMART_NOT_UPDATE', 1);
92  invalidate_user_cache();
93}
94
95// +-----------------------------------------------------------------------+
96// |                       template initialization                         |
97// +-----------------------------------------------------------------------+
98$template->assign(array(
99  'F_ACTION' => $self_url,
100  'PWG_TOKEN' => get_pwg_token(),
101 ));
102 
103// retrieve all existing categories for album creation
104$query = '
105SELECT id,name,uppercats,global_rank
106  FROM '.CATEGORIES_TABLE.'
107;';
108
109display_select_cat_wrapper(
110  $query,
111  null,
112  'category_options'
113  );
114 
115if ($conf['SmartAlbums']['show_list_messages'])
116{
117  array_push($page['warnings'], l10n('Only SmartAlbums are displayed on this page'));
118  array_push($page['warnings'], sprintf(l10n('To order albums please go the main albums <a href="%s">management page</a>'), $base_url.'cat_list'));
119  array_push($page['warnings'], '<a href="'.$self_url.'&hide_messages">['.l10n('Don\'t show this message again').']</a>');
120}
121
122// +-----------------------------------------------------------------------+
123// |                          Categories display                           |
124// +-----------------------------------------------------------------------+
125
126// get the categories containing images directly
127$categories_with_images = array();
128if ( count($categories) )
129{
130  $query = '
131SELECT DISTINCT category_id
132  FROM '.IMAGE_CATEGORY_TABLE.'
133  WHERE category_id IN ('.implode(',', array_keys($categories)).')';
134  $categories_with_images = array_flip( array_from_query($query, 'category_id') );
135}
136
137$template->assign('categories', array());
138
139foreach ($categories as $category)
140{
141  $tpl_cat =
142    array(
143      'NAME'       => get_cat_display_name_from_id($category['id'], $base_url.'album-'),
144      'ID'         => $category['id'],
145      'RANK'       => $category['rank']*10,
146
147      'U_JUMPTO'   => make_index_url(
148        array(
149          'category' => $category
150          )
151        ),
152
153      'U_EDIT'     => $base_url.'album-'.$category['id'],
154      'U_DELETE'   => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
155      'U_SMART'    => $self_url.'&amp;smart_generate='.$category['id'],
156    );
157
158  if ( array_key_exists($category['id'], $categories_with_images) )
159  {
160    $tpl_cat['U_MANAGE_ELEMENTS'] =
161      $base_url.'batch_manager&amp;cat='.$category['id'];
162  }
163 
164  $template->append('categories', $tpl_cat);
165}
166
167$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/cat_list.tpl');
168
169?>
Note: See TracBrowser for help on using the repository browser.