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

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

move update time from categories_table to category_filters_table

File size: 5.1 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    cf.updated
24  FROM '.CATEGORIES_TABLE.' AS cat
25  INNER JOIN '.CATEGORY_FILTERS_TABLE.' AS cf
26    ON cf.category_id = cat.id
27  GROUP BY id
28  ORDER BY global_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$categories_count_images = array();
127if ( count($categories) )
128{
129  $query = '
130SELECT
131    category_id,
132    COUNT(image_id) AS total_images
133  FROM '.IMAGE_CATEGORY_TABLE.'
134  WHERE category_id IN ('.implode(',', array_keys($categories)).')
135  GROUP BY category_id
136;';
137  $categories_count_images = simple_hash_from_query($query, 'category_id', 'total_images');
138}
139
140$template->assign('categories', array());
141
142foreach ($categories as $category)
143{
144  $tpl_cat =
145    array(
146      'NAME'        => get_cat_display_name_from_id($category['id'], $base_url.'album-'),
147      'ID'          => $category['id'],
148      'IMG_COUNT'   => !empty($categories_count_images[ $category['id'] ]) ? $categories_count_images[ $category['id'] ] : 0,
149      'LAST_UPDATE' => format_date($category['updated'], true),
150
151      'U_JUMPTO'    => make_index_url(array('category' => $category)),
152      'U_EDIT'      => SMART_ADMIN.'-album&amp;cat_id='.$category['id'],
153      'U_DELETE'    => $self_url.'&amp;delete='.$category['id'].'&amp;pwg_token='.get_pwg_token(),
154      'U_SMART'     => $self_url.'&amp;smart_generate='.$category['id'],
155    );
156 
157  $template->append('categories', $tpl_cat);
158}
159
160$template->set_filename('SmartAlbums_content', dirname(__FILE__).'/template/cat_list.tpl');
161
162?>
Note: See TracBrowser for help on using the repository browser.