1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | Piwigo - a PHP based picture gallery | |
---|
4 | // +-----------------------------------------------------------------------+ |
---|
5 | // | Copyright(C) 2008-2009 Piwigo Team http://piwigo.org | |
---|
6 | // | Copyright(C) 2003-2008 PhpWebGallery Team http://phpwebgallery.net | |
---|
7 | // | Copyright(C) 2002-2003 Pierrick LE GALL http://le-gall.net/pierrick | |
---|
8 | // +-----------------------------------------------------------------------+ |
---|
9 | // | This program is free software; you can redistribute it and/or modify | |
---|
10 | // | it under the terms of the GNU General Public License as published by | |
---|
11 | // | the Free Software Foundation | |
---|
12 | // | | |
---|
13 | // | This program is distributed in the hope that it will be useful, but | |
---|
14 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
15 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
16 | // | General Public License for more details. | |
---|
17 | // | | |
---|
18 | // | You should have received a copy of the GNU General Public License | |
---|
19 | // | along with this program; if not, write to the Free Software | |
---|
20 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
21 | // | USA. | |
---|
22 | // +-----------------------------------------------------------------------+ |
---|
23 | |
---|
24 | if (!defined('PHPWG_ROOT_PATH')) |
---|
25 | { |
---|
26 | die('Hacking attempt!'); |
---|
27 | } |
---|
28 | |
---|
29 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
30 | |
---|
31 | // +-----------------------------------------------------------------------+ |
---|
32 | // | Check Access and exit when user status is not ok | |
---|
33 | // +-----------------------------------------------------------------------+ |
---|
34 | check_status(ACCESS_ADMINISTRATOR); |
---|
35 | |
---|
36 | // +-----------------------------------------------------------------------+ |
---|
37 | // | functions | |
---|
38 | // +-----------------------------------------------------------------------+ |
---|
39 | |
---|
40 | /** |
---|
41 | * save the rank depending on given categories order |
---|
42 | * |
---|
43 | * The list of ordered categories id is supposed to be in the same parent |
---|
44 | * category |
---|
45 | * |
---|
46 | * @param array categories |
---|
47 | * @return void |
---|
48 | */ |
---|
49 | function save_categories_order($categories) |
---|
50 | { |
---|
51 | $current_rank = 0; |
---|
52 | $datas = array(); |
---|
53 | foreach ($categories as $id) |
---|
54 | { |
---|
55 | array_push($datas, array('id' => $id, 'rank' => ++$current_rank)); |
---|
56 | } |
---|
57 | $fields = array('primary' => array('id'), 'update' => array('rank')); |
---|
58 | mass_updates(CATEGORIES_TABLE, $fields, $datas); |
---|
59 | |
---|
60 | update_global_rank(); |
---|
61 | } |
---|
62 | |
---|
63 | // +-----------------------------------------------------------------------+ |
---|
64 | // | initialization | |
---|
65 | // +-----------------------------------------------------------------------+ |
---|
66 | |
---|
67 | $categories = array(); |
---|
68 | |
---|
69 | $base_url = get_root_url().'admin.php?page=cat_list'; |
---|
70 | $navigation = '<a href="'.$base_url.'">'; |
---|
71 | $navigation.= l10n('home'); |
---|
72 | $navigation.= '</a>'; |
---|
73 | |
---|
74 | // +-----------------------------------------------------------------------+ |
---|
75 | // | virtual categories management | |
---|
76 | // +-----------------------------------------------------------------------+ |
---|
77 | // request to delete a virtual category / not for an adviser |
---|
78 | if (isset($_GET['delete']) and is_numeric($_GET['delete']) and !is_adviser()) |
---|
79 | { |
---|
80 | delete_categories(array($_GET['delete'])); |
---|
81 | array_push($page['infos'], l10n('cat_virtual_deleted')); |
---|
82 | update_global_rank(); |
---|
83 | } |
---|
84 | // request to add a virtual category |
---|
85 | else if (isset($_POST['submitAdd'])) |
---|
86 | { |
---|
87 | $output_create = create_virtual_category( |
---|
88 | $_POST['virtual_name'], |
---|
89 | @$_GET['parent_id'] |
---|
90 | ); |
---|
91 | |
---|
92 | if (isset($output_create['error'])) |
---|
93 | { |
---|
94 | array_push($page['errors'], $output_create['error']); |
---|
95 | } |
---|
96 | else |
---|
97 | { |
---|
98 | array_push($page['infos'], $output_create['info']); |
---|
99 | } |
---|
100 | } |
---|
101 | // save manual category ordering |
---|
102 | else if (isset($_POST['submitOrder'])) |
---|
103 | { |
---|
104 | asort($_POST['catOrd'], SORT_NUMERIC); |
---|
105 | save_categories_order(array_keys($_POST['catOrd'])); |
---|
106 | |
---|
107 | array_push( |
---|
108 | $page['infos'], |
---|
109 | l10n('Categories manual order was saved') |
---|
110 | ); |
---|
111 | } |
---|
112 | // sort categories alpha-numerically |
---|
113 | else if (isset($_POST['submitOrderAlphaNum'])) |
---|
114 | { |
---|
115 | $query = ' |
---|
116 | SELECT id, name |
---|
117 | FROM '.CATEGORIES_TABLE.' |
---|
118 | WHERE id_uppercat '. |
---|
119 | (!isset($_GET['parent_id']) ? 'IS NULL' : '= '.$_GET['parent_id']).' |
---|
120 | ;'; |
---|
121 | $result = pwg_query($query); |
---|
122 | while ($row = mysql_fetch_assoc($result)) |
---|
123 | { |
---|
124 | $categories[ $row['id'] ] = strtolower($row['name']); |
---|
125 | } |
---|
126 | |
---|
127 | asort($categories, SORT_REGULAR); |
---|
128 | save_categories_order(array_keys($categories)); |
---|
129 | |
---|
130 | array_push( |
---|
131 | $page['infos'], |
---|
132 | l10n('Categories ordered alphanumerically') |
---|
133 | ); |
---|
134 | } |
---|
135 | |
---|
136 | // +-----------------------------------------------------------------------+ |
---|
137 | // | Navigation path | |
---|
138 | // +-----------------------------------------------------------------------+ |
---|
139 | |
---|
140 | if (isset($_GET['parent_id'])) |
---|
141 | { |
---|
142 | $navigation.= $conf['level_separator']; |
---|
143 | |
---|
144 | $navigation.= get_cat_display_name_from_id( |
---|
145 | $_GET['parent_id'], |
---|
146 | $base_url.'&parent_id=', |
---|
147 | false |
---|
148 | ); |
---|
149 | } |
---|
150 | // +-----------------------------------------------------------------------+ |
---|
151 | // | template initialization | |
---|
152 | // +-----------------------------------------------------------------------+ |
---|
153 | $template->set_filename('categories', 'cat_list.tpl'); |
---|
154 | |
---|
155 | $form_action = PHPWG_ROOT_PATH.'admin.php?page=cat_list'; |
---|
156 | if (isset($_GET['parent_id'])) |
---|
157 | { |
---|
158 | $form_action.= '&parent_id='.$_GET['parent_id']; |
---|
159 | } |
---|
160 | |
---|
161 | $template->assign(array( |
---|
162 | 'CATEGORIES_NAV'=>$navigation, |
---|
163 | 'F_ACTION'=>$form_action, |
---|
164 | )); |
---|
165 | |
---|
166 | // +-----------------------------------------------------------------------+ |
---|
167 | // | Categories display | |
---|
168 | // +-----------------------------------------------------------------------+ |
---|
169 | |
---|
170 | $categories = array(); |
---|
171 | |
---|
172 | $query = ' |
---|
173 | SELECT id, name, permalink, dir, rank, status |
---|
174 | FROM '.CATEGORIES_TABLE; |
---|
175 | if (!isset($_GET['parent_id'])) |
---|
176 | { |
---|
177 | $query.= ' |
---|
178 | WHERE id_uppercat IS NULL'; |
---|
179 | } |
---|
180 | else |
---|
181 | { |
---|
182 | $query.= ' |
---|
183 | WHERE id_uppercat = '.$_GET['parent_id']; |
---|
184 | } |
---|
185 | $query.= ' |
---|
186 | ORDER BY rank ASC |
---|
187 | ;'; |
---|
188 | $categories = hash_from_query($query, 'id'); |
---|
189 | |
---|
190 | // get the categories containing images directly |
---|
191 | $categories_with_images = array(); |
---|
192 | if ( count($categories) ) |
---|
193 | { |
---|
194 | $query = ' |
---|
195 | SELECT DISTINCT category_id |
---|
196 | FROM '.IMAGE_CATEGORY_TABLE.' |
---|
197 | WHERE category_id IN ('.implode(',', array_keys($categories)).')'; |
---|
198 | $categories_with_images = array_flip( array_from_query($query, 'category_id') ); |
---|
199 | } |
---|
200 | |
---|
201 | $template->assign('categories', array()); |
---|
202 | $base_url = get_root_url().'admin.php?page='; |
---|
203 | foreach ($categories as $category) |
---|
204 | { |
---|
205 | $cat_list_url = $base_url.'cat_list'; |
---|
206 | |
---|
207 | $self_url = $cat_list_url; |
---|
208 | if (isset($_GET['parent_id'])) |
---|
209 | { |
---|
210 | $self_url.= '&parent_id='.$_GET['parent_id']; |
---|
211 | } |
---|
212 | |
---|
213 | $tpl_cat = |
---|
214 | array( |
---|
215 | 'NAME' => |
---|
216 | trigger_event( |
---|
217 | 'render_category_name', |
---|
218 | $category['name'], |
---|
219 | 'admin_cat_list' |
---|
220 | ), |
---|
221 | 'ID' => $category['id'], |
---|
222 | 'RANK' => $category['rank']*10, |
---|
223 | |
---|
224 | 'U_JUMPTO' => make_index_url( |
---|
225 | array( |
---|
226 | 'category' => $category |
---|
227 | ) |
---|
228 | ), |
---|
229 | |
---|
230 | 'U_CHILDREN' => $cat_list_url.'&parent_id='.$category['id'], |
---|
231 | 'U_EDIT' => $base_url.'cat_modify&cat_id='.$category['id'], |
---|
232 | |
---|
233 | 'IS_VIRTUAL' => empty($category['dir']) |
---|
234 | ); |
---|
235 | |
---|
236 | if (empty($category['dir'])) |
---|
237 | { |
---|
238 | $tpl_cat['U_DELETE'] = $self_url.'&delete='.$category['id']; |
---|
239 | } |
---|
240 | |
---|
241 | if ( array_key_exists($category['id'], $categories_with_images) ) |
---|
242 | { |
---|
243 | $tpl_cat['U_MANAGE_ELEMENTS']= |
---|
244 | $base_url.'element_set&cat='.$category['id']; |
---|
245 | } |
---|
246 | |
---|
247 | if ('private' == $category['status']) |
---|
248 | { |
---|
249 | $tpl_cat['U_MANAGE_PERMISSIONS']= |
---|
250 | $base_url.'cat_perm&cat='.$category['id']; |
---|
251 | } |
---|
252 | $template->append('categories', $tpl_cat); |
---|
253 | } |
---|
254 | // +-----------------------------------------------------------------------+ |
---|
255 | // | sending html code | |
---|
256 | // +-----------------------------------------------------------------------+ |
---|
257 | $template->assign_var_from_handle('ADMIN_CONTENT', 'categories'); |
---|
258 | ?> |
---|