1 | <?php |
---|
2 | // +-----------------------------------------------------------------------+ |
---|
3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
5 | // | Copyright (C) 2003-2007 PhpWebGallery Team - http://phpwebgallery.net | |
---|
6 | // +-----------------------------------------------------------------------+ |
---|
7 | // | file : $Id: tags.php 2097 2007-09-19 06:47:41Z patdenice $ |
---|
8 | // | last update : $Date: 2007-09-19 06:47:41 +0000 (Wed, 19 Sep 2007) $ |
---|
9 | // | last modifier : $Author: patdenice $ |
---|
10 | // | revision : $Revision: 2097 $ |
---|
11 | // +-----------------------------------------------------------------------+ |
---|
12 | // | This program is free software; you can redistribute it and/or modify | |
---|
13 | // | it under the terms of the GNU General Public License as published by | |
---|
14 | // | the Free Software Foundation | |
---|
15 | // | | |
---|
16 | // | This program is distributed in the hope that it will be useful, but | |
---|
17 | // | WITHOUT ANY WARRANTY; without even the implied warranty of | |
---|
18 | // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
---|
19 | // | General Public License for more details. | |
---|
20 | // | | |
---|
21 | // | You should have received a copy of the GNU General Public License | |
---|
22 | // | along with this program; if not, write to the Free Software | |
---|
23 | // | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
---|
24 | // | USA. | |
---|
25 | // +-----------------------------------------------------------------------+ |
---|
26 | |
---|
27 | if( !defined("PHPWG_ROOT_PATH") ) |
---|
28 | { |
---|
29 | die ("Hacking attempt!"); |
---|
30 | } |
---|
31 | |
---|
32 | include_once(PHPWG_ROOT_PATH.'admin/include/functions.php'); |
---|
33 | check_status(ACCESS_ADMINISTRATOR); |
---|
34 | |
---|
35 | // +-----------------------------------------------------------------------+ |
---|
36 | // | edit tags | |
---|
37 | // +-----------------------------------------------------------------------+ |
---|
38 | |
---|
39 | if (isset($_POST['submit']) and !is_adviser()) |
---|
40 | { |
---|
41 | $query = ' |
---|
42 | SELECT name |
---|
43 | FROM '.TAGS_TABLE.' |
---|
44 | ;'; |
---|
45 | $existing_names = array_from_query($query, 'name'); |
---|
46 | |
---|
47 | |
---|
48 | $current_name_of = array(); |
---|
49 | $query = ' |
---|
50 | SELECT id, name |
---|
51 | FROM '.TAGS_TABLE.' |
---|
52 | WHERE id IN ('.$_POST['edit_list'].') |
---|
53 | ;'; |
---|
54 | $result = pwg_query($query); |
---|
55 | while ($row = mysql_fetch_array($result)) |
---|
56 | { |
---|
57 | $current_name_of[ $row['id'] ] = $row['name']; |
---|
58 | } |
---|
59 | |
---|
60 | $updates = array(); |
---|
61 | // we must not rename tag with an already existing name |
---|
62 | foreach (explode(',', $_POST['edit_list']) as $tag_id) |
---|
63 | { |
---|
64 | $tag_name = stripslashes($_POST['tag_name-'.$tag_id]); |
---|
65 | |
---|
66 | if ($tag_name != $current_name_of[$tag_id]) |
---|
67 | { |
---|
68 | if (in_array($tag_name, $existing_names)) |
---|
69 | { |
---|
70 | array_push( |
---|
71 | $page['errors'], |
---|
72 | sprintf( |
---|
73 | l10n('Tag "%s" already exists'), |
---|
74 | $tag_name |
---|
75 | ) |
---|
76 | ); |
---|
77 | } |
---|
78 | else if (!empty($tag_name)) |
---|
79 | { |
---|
80 | array_push( |
---|
81 | $updates, |
---|
82 | array( |
---|
83 | 'id' => $tag_id, |
---|
84 | 'name' => addslashes($tag_name), |
---|
85 | 'url_name' => str2url($tag_name), |
---|
86 | ) |
---|
87 | ); |
---|
88 | } |
---|
89 | } |
---|
90 | } |
---|
91 | mass_updates( |
---|
92 | TAGS_TABLE, |
---|
93 | array( |
---|
94 | 'primary' => array('id'), |
---|
95 | 'update' => array('name', 'url_name'), |
---|
96 | ), |
---|
97 | $updates |
---|
98 | ); |
---|
99 | } |
---|
100 | |
---|
101 | // +-----------------------------------------------------------------------+ |
---|
102 | // | delete tags | |
---|
103 | // +-----------------------------------------------------------------------+ |
---|
104 | |
---|
105 | if (isset($_POST['delete']) and isset($_POST['tags']) and !is_adviser()) |
---|
106 | { |
---|
107 | $query = ' |
---|
108 | SELECT name |
---|
109 | FROM '.TAGS_TABLE.' |
---|
110 | WHERE id IN ('.implode(',', $_POST['tags']).') |
---|
111 | ;'; |
---|
112 | $tag_names = array_from_query($query, 'name'); |
---|
113 | |
---|
114 | $query = ' |
---|
115 | DELETE |
---|
116 | FROM '.IMAGE_TAG_TABLE.' |
---|
117 | WHERE tag_id IN ('.implode(',', $_POST['tags']).') |
---|
118 | ;'; |
---|
119 | pwg_query($query); |
---|
120 | |
---|
121 | $query = ' |
---|
122 | DELETE |
---|
123 | FROM '.TAGS_TABLE.' |
---|
124 | WHERE id IN ('.implode(',', $_POST['tags']).') |
---|
125 | ;'; |
---|
126 | pwg_query($query); |
---|
127 | |
---|
128 | array_push( |
---|
129 | $page['infos'], |
---|
130 | l10n_dec( |
---|
131 | 'The %d following tag were deleted', |
---|
132 | 'The %d following tags were deleted', |
---|
133 | count($tag_names)).' : '. |
---|
134 | implode(', ', $tag_names) |
---|
135 | ); |
---|
136 | } |
---|
137 | |
---|
138 | // +-----------------------------------------------------------------------+ |
---|
139 | // | add a tag | |
---|
140 | // +-----------------------------------------------------------------------+ |
---|
141 | |
---|
142 | if (isset($_POST['add']) and !empty($_POST['add_tag']) and !is_adviser()) |
---|
143 | { |
---|
144 | $tag_name = $_POST['add_tag']; |
---|
145 | |
---|
146 | // does the tag already exists? |
---|
147 | $query = ' |
---|
148 | SELECT id |
---|
149 | FROM '.TAGS_TABLE.' |
---|
150 | WHERE name = \''.$tag_name.'\' |
---|
151 | ;'; |
---|
152 | $existing_tags = array_from_query($query, 'id'); |
---|
153 | |
---|
154 | if (count($existing_tags) == 0) |
---|
155 | { |
---|
156 | mass_inserts( |
---|
157 | TAGS_TABLE, |
---|
158 | array('name', 'url_name'), |
---|
159 | array( |
---|
160 | array( |
---|
161 | 'name' => $tag_name, |
---|
162 | 'url_name' => str2url($tag_name), |
---|
163 | ) |
---|
164 | ) |
---|
165 | ); |
---|
166 | |
---|
167 | array_push( |
---|
168 | $page['infos'], |
---|
169 | sprintf( |
---|
170 | l10n('Tag "%s" was added'), |
---|
171 | stripslashes($tag_name) |
---|
172 | ) |
---|
173 | ); |
---|
174 | } |
---|
175 | else |
---|
176 | { |
---|
177 | array_push( |
---|
178 | $page['errors'], |
---|
179 | sprintf( |
---|
180 | l10n('Tag "%s" already exists'), |
---|
181 | stripslashes($tag_name) |
---|
182 | ) |
---|
183 | ); |
---|
184 | } |
---|
185 | } |
---|
186 | |
---|
187 | // +-----------------------------------------------------------------------+ |
---|
188 | // | template init | |
---|
189 | // +-----------------------------------------------------------------------+ |
---|
190 | |
---|
191 | $template->set_filenames(array('tags' => 'admin/tags.tpl')); |
---|
192 | |
---|
193 | $template->assign_vars( |
---|
194 | array( |
---|
195 | 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=tags' |
---|
196 | ) |
---|
197 | ); |
---|
198 | |
---|
199 | // +-----------------------------------------------------------------------+ |
---|
200 | // | form creation | |
---|
201 | // +-----------------------------------------------------------------------+ |
---|
202 | |
---|
203 | $template->assign_vars( |
---|
204 | array( |
---|
205 | 'TAG_SELECTION' => get_html_tag_selection( |
---|
206 | get_all_tags(), |
---|
207 | 'tags' |
---|
208 | ), |
---|
209 | ) |
---|
210 | ); |
---|
211 | |
---|
212 | if (isset($_POST['edit']) and isset($_POST['tags'])) |
---|
213 | { |
---|
214 | $template->assign_block_vars( |
---|
215 | 'edit_tags', |
---|
216 | array( |
---|
217 | 'LIST' => implode(',', $_POST['tags']), |
---|
218 | ) |
---|
219 | ); |
---|
220 | |
---|
221 | $query = ' |
---|
222 | SELECT id, name |
---|
223 | FROM '.TAGS_TABLE.' |
---|
224 | WHERE id IN ('.implode(',', $_POST['tags']).') |
---|
225 | ;'; |
---|
226 | $result = pwg_query($query); |
---|
227 | while ($row = mysql_fetch_array($result)) |
---|
228 | { |
---|
229 | $name_of[ $row['id'] ] = $row['name']; |
---|
230 | } |
---|
231 | |
---|
232 | foreach ($_POST['tags'] as $tag_id) |
---|
233 | { |
---|
234 | $template->assign_block_vars( |
---|
235 | 'edit_tags.tag', |
---|
236 | array( |
---|
237 | 'ID' => $tag_id, |
---|
238 | 'NAME' => $name_of[$tag_id], |
---|
239 | ) |
---|
240 | ); |
---|
241 | } |
---|
242 | } |
---|
243 | |
---|
244 | // +-----------------------------------------------------------------------+ |
---|
245 | // | sending html code | |
---|
246 | // +-----------------------------------------------------------------------+ |
---|
247 | |
---|
248 | $template->assign_var_from_handle('ADMIN_CONTENT', 'tags'); |
---|
249 | |
---|
250 | ?> |
---|