1 | <?php |
---|
2 | defined('SMART_PATH') or die('Hacking attempt!'); |
---|
3 | |
---|
4 | if (isset($_GET['hide_messages'])) |
---|
5 | { |
---|
6 | $conf['SmartAlbums']['show_list_messages'] = false; |
---|
7 | conf_update_param('SmartAlbums', $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 = ' |
---|
18 | SELECT |
---|
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 |
---|
36 | if (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 |
---|
44 | else 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 | $page['errors'][] = $output_create['error']; |
---|
54 | } |
---|
55 | else |
---|
56 | { |
---|
57 | $_SESSION['page_infos'] = array(l10n('SmartAlbum added')); |
---|
58 | $redirect_url = SMART_ADMIN . '-album&cat_id='.$output_create['id'].'&new_smart'; |
---|
59 | redirect($redirect_url); |
---|
60 | } |
---|
61 | } |
---|
62 | // request to regeneration |
---|
63 | else 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 | |
---|
72 | $page['infos'][] = l10n( |
---|
73 | '%d photos associated to album %s', |
---|
74 | count($associated_images), |
---|
75 | '«'.trigger_change('render_category_name', $category['name'], 'admin_cat_list').'»' |
---|
76 | ); |
---|
77 | } |
---|
78 | } |
---|
79 | /* regenerate photo list | one category */ |
---|
80 | else |
---|
81 | { |
---|
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 | '«'.trigger_change('render_category_name', $categories[ $_GET['smart_generate'] ]['name'], 'admin_cat_list').'»' |
---|
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 = ' |
---|
105 | SELECT id,name,uppercats,global_rank |
---|
106 | FROM '.CATEGORIES_TABLE.' |
---|
107 | ;'; |
---|
108 | |
---|
109 | display_select_cat_wrapper( |
---|
110 | $query, null, |
---|
111 | 'category_options' |
---|
112 | ); |
---|
113 | |
---|
114 | if ($conf['SmartAlbums']['show_list_messages']) |
---|
115 | { |
---|
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>'; |
---|
119 | } |
---|
120 | |
---|
121 | // +-----------------------------------------------------------------------+ |
---|
122 | // | Categories display | |
---|
123 | // +-----------------------------------------------------------------------+ |
---|
124 | |
---|
125 | $categories_count_images = array(); |
---|
126 | if (count($categories)) |
---|
127 | { |
---|
128 | $query = ' |
---|
129 | SELECT |
---|
130 | category_id, |
---|
131 | COUNT(image_id) AS total_images |
---|
132 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
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'); |
---|
137 | } |
---|
138 | |
---|
139 | $template->assign('categories', array()); |
---|
140 | |
---|
141 | foreach ($categories as $category) |
---|
142 | { |
---|
143 | $tpl_cat = |
---|
144 | array( |
---|
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, |
---|
148 | 'LAST_UPDATE' => format_date($category['updated'], true), |
---|
149 | |
---|
150 | 'U_JUMPTO' => make_index_url(array('category' => $category)), |
---|
151 | 'U_EDIT' => SMART_ADMIN.'-album&cat_id='.$category['id'], |
---|
152 | 'U_DELETE' => $self_url.'&delete='.$category['id'].'&pwg_token='.get_pwg_token(), |
---|
153 | 'U_SMART' => $self_url.'&smart_generate='.$category['id'], |
---|
154 | ); |
---|
155 | |
---|
156 | $template->append('categories', $tpl_cat); |
---|
157 | } |
---|
158 | |
---|
159 | $template->set_filename('SmartAlbums_content', realpath(SMART_PATH . 'admin/template/cat_list.tpl')); |
---|