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