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

Last change on this file since 27266 was 26442, checked in by mistic100, 11 years ago

update for Piwigo 2.6

File size: 5.0 KB
RevLine 
[11392]1<?php
[26442]2defined('SMART_PATH') or die('Hacking attempt!');
[11392]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// +-----------------------------------------------------------------------+
[16104]13$base_url = get_root_url() . 'admin.php?page=';
14$self_url = SMART_ADMIN . '-cat_list';
[11392]15
16$categories = array();
17$query = '
[26442]18SELECT
[16104]19    id,
20    name,
21    permalink,
22    dir,
[21658]23    cf.updated
[11392]24  FROM '.CATEGORIES_TABLE.' AS cat
25  INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
26    ON cf.category_id = cat.id
[21658]27  GROUP BY id
[21358]28  ORDER BY global_rank ASC
[11392]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  {
[26442]53    $page['errors'][] = $output_create['error'];
[11392]54  }
55  else
56  {
57    $_SESSION['page_infos'] = array(l10n('SmartAlbum added'));
[16104]58    $redirect_url = SMART_ADMIN . '-album&amp;cat_id='.$output_create['id'].'&amp;new_smart';
[11392]59    redirect($redirect_url);
60  }
61}
62// request to regeneration
63else if (isset($_GET['smart_generate']))
64{
[16104]65  /* regenerate photo list | all categories */
[11392]66  if ($_GET['smart_generate'] == 'all')
67  {
68    foreach ($categories as $category)
69    {
70      $associated_images = smart_make_associations($category['id']);
[26442]71
72      $page['infos'][] = l10n(
73        '%d photos associated to album %s',
74        count($associated_images),
75        '&laquo;'.trigger_event('render_category_name', $category['name'], 'admin_cat_list').'&raquo;'
[11392]76        );
77    }
78  }
79  /* regenerate photo list | one category */
80  else
81  {
[26442]82    $associated_images = smart_make_associations($_GET['smart_generate']);
83
84    $page['infos'][] = l10n(
85      '%d photos associated to album %s',
86      count($associated_images),
87      '&laquo;'.trigger_event('render_category_name', $categories[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'&raquo;'
[11392]88      );
89  }
[26442]90
[11392]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 ));
[26442]102
[11392]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(
[26442]110  $query, null,
[11392]111  'category_options'
112  );
[26442]113
[11392]114if ($conf['SmartAlbums']['show_list_messages'])
115{
[26442]116  $page['warnings'][] = l10n('Only SmartAlbums are displayed on this page');
117  $page['warnings'][] = sprintf(l10n('To order albums please go the main albums <a href="%s">management page</a>'), $base_url.'cat_list');
118  $page['warnings'][] = '<a href="'.$self_url.'&hide_messages">['.l10n('Don\'t show this message again').']</a>';
[11392]119}
120
121// +-----------------------------------------------------------------------+
122// |                          Categories display                           |
123// +-----------------------------------------------------------------------+
124
[19446]125$categories_count_images = array();
[26442]126if (count($categories))
[11392]127{
128  $query = '
[26442]129SELECT
130    category_id,
[19446]131    COUNT(image_id) AS total_images
[11392]132  FROM '.IMAGE_CATEGORY_TABLE.'
[19446]133  WHERE category_id IN ('.implode(',', array_keys($categories)).')
134  GROUP BY category_id
135;';
136  $categories_count_images = simple_hash_from_query($query, 'category_id', 'total_images');
[11392]137}
138
139$template->assign('categories', array());
140
141foreach ($categories as $category)
142{
143  $tpl_cat =
144    array(
[19446]145      'NAME'        => get_cat_display_name_from_id($category['id'], $base_url.'album-'),
146      'ID'          => $category['id'],
147      'IMG_COUNT'   => !empty($categories_count_images[ $category['id'] ]) ? $categories_count_images[ $category['id'] ] : 0,
[21658]148      'LAST_UPDATE' => format_date($category['updated'], true),
[11392]149
[19446]150      'U_JUMPTO'    => make_index_url(array('category' => $category)),
151      'U_EDIT'      => SMART_ADMIN.'-album&amp;cat_id='.$category['id'],
152      'U_DELETE'    => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
153      'U_SMART'     => $self_url.'&amp;smart_generate='.$category['id'],
[11392]154    );
[26442]155
[11392]156  $template->append('categories', $tpl_cat);
157}
158
[26442]159$template->set_filename('SmartAlbums_content', realpath(SMART_PATH . 'admin/template/cat_list.tpl'));
Note: See TracBrowser for help on using the repository browser.