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