[1119] | 1 | <?php |
---|
| 2 | // +-----------------------------------------------------------------------+ |
---|
[2297] | 3 | // | Piwigo - a PHP based picture gallery | |
---|
| 4 | // +-----------------------------------------------------------------------+ |
---|
[5196] | 5 | // | Copyright(C) 2008-2010 Piwigo Team http://piwigo.org | |
---|
[2297] | 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 | // +-----------------------------------------------------------------------+ |
---|
[1119] | 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 | check_status(ACCESS_ADMINISTRATOR); |
---|
| 31 | |
---|
[5195] | 32 | if (!empty($_POST)) |
---|
| 33 | { |
---|
| 34 | check_pwg_token(); |
---|
| 35 | } |
---|
| 36 | |
---|
[1119] | 37 | // +-----------------------------------------------------------------------+ |
---|
| 38 | // | edit tags | |
---|
| 39 | // +-----------------------------------------------------------------------+ |
---|
| 40 | |
---|
[1571] | 41 | if (isset($_POST['submit']) and !is_adviser()) |
---|
[1119] | 42 | { |
---|
| 43 | $query = ' |
---|
| 44 | SELECT name |
---|
| 45 | FROM '.TAGS_TABLE.' |
---|
| 46 | ;'; |
---|
| 47 | $existing_names = array_from_query($query, 'name'); |
---|
| 48 | |
---|
| 49 | |
---|
| 50 | $current_name_of = array(); |
---|
| 51 | $query = ' |
---|
| 52 | SELECT id, name |
---|
| 53 | FROM '.TAGS_TABLE.' |
---|
| 54 | WHERE id IN ('.$_POST['edit_list'].') |
---|
| 55 | ;'; |
---|
| 56 | $result = pwg_query($query); |
---|
[4325] | 57 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1119] | 58 | { |
---|
| 59 | $current_name_of[ $row['id'] ] = $row['name']; |
---|
| 60 | } |
---|
| 61 | |
---|
| 62 | $updates = array(); |
---|
| 63 | // we must not rename tag with an already existing name |
---|
| 64 | foreach (explode(',', $_POST['edit_list']) as $tag_id) |
---|
| 65 | { |
---|
[2098] | 66 | $tag_name = stripslashes($_POST['tag_name-'.$tag_id]); |
---|
[1119] | 67 | |
---|
| 68 | if ($tag_name != $current_name_of[$tag_id]) |
---|
| 69 | { |
---|
| 70 | if (in_array($tag_name, $existing_names)) |
---|
| 71 | { |
---|
| 72 | array_push( |
---|
| 73 | $page['errors'], |
---|
| 74 | sprintf( |
---|
[5036] | 75 | l10n('Tag "%s" already exists'), |
---|
[1119] | 76 | $tag_name |
---|
| 77 | ) |
---|
| 78 | ); |
---|
| 79 | } |
---|
| 80 | else if (!empty($tag_name)) |
---|
| 81 | { |
---|
| 82 | array_push( |
---|
| 83 | $updates, |
---|
| 84 | array( |
---|
| 85 | 'id' => $tag_id, |
---|
[2098] | 86 | 'name' => addslashes($tag_name), |
---|
[1119] | 87 | 'url_name' => str2url($tag_name), |
---|
| 88 | ) |
---|
| 89 | ); |
---|
| 90 | } |
---|
| 91 | } |
---|
| 92 | } |
---|
| 93 | mass_updates( |
---|
| 94 | TAGS_TABLE, |
---|
| 95 | array( |
---|
| 96 | 'primary' => array('id'), |
---|
| 97 | 'update' => array('name', 'url_name'), |
---|
| 98 | ), |
---|
| 99 | $updates |
---|
| 100 | ); |
---|
| 101 | } |
---|
| 102 | |
---|
| 103 | // +-----------------------------------------------------------------------+ |
---|
| 104 | // | delete tags | |
---|
| 105 | // +-----------------------------------------------------------------------+ |
---|
| 106 | |
---|
[1571] | 107 | if (isset($_POST['delete']) and isset($_POST['tags']) and !is_adviser()) |
---|
[1119] | 108 | { |
---|
| 109 | $query = ' |
---|
| 110 | SELECT name |
---|
| 111 | FROM '.TAGS_TABLE.' |
---|
| 112 | WHERE id IN ('.implode(',', $_POST['tags']).') |
---|
| 113 | ;'; |
---|
| 114 | $tag_names = array_from_query($query, 'name'); |
---|
| 115 | |
---|
| 116 | $query = ' |
---|
| 117 | DELETE |
---|
| 118 | FROM '.IMAGE_TAG_TABLE.' |
---|
| 119 | WHERE tag_id IN ('.implode(',', $_POST['tags']).') |
---|
| 120 | ;'; |
---|
| 121 | pwg_query($query); |
---|
| 122 | |
---|
| 123 | $query = ' |
---|
| 124 | DELETE |
---|
| 125 | FROM '.TAGS_TABLE.' |
---|
| 126 | WHERE id IN ('.implode(',', $_POST['tags']).') |
---|
| 127 | ;'; |
---|
| 128 | pwg_query($query); |
---|
| 129 | |
---|
| 130 | array_push( |
---|
| 131 | $page['infos'], |
---|
[1932] | 132 | l10n_dec( |
---|
[5036] | 133 | 'The following tag was deleted', |
---|
[1932] | 134 | 'The %d following tags were deleted', |
---|
| 135 | count($tag_names)).' : '. |
---|
[1119] | 136 | implode(', ', $tag_names) |
---|
| 137 | ); |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | // +-----------------------------------------------------------------------+ |
---|
| 141 | // | add a tag | |
---|
| 142 | // +-----------------------------------------------------------------------+ |
---|
| 143 | |
---|
[1571] | 144 | if (isset($_POST['add']) and !empty($_POST['add_tag']) and !is_adviser()) |
---|
[1119] | 145 | { |
---|
[2098] | 146 | $tag_name = $_POST['add_tag']; |
---|
[1119] | 147 | |
---|
[1452] | 148 | // does the tag already exists? |
---|
[1119] | 149 | $query = ' |
---|
| 150 | SELECT id |
---|
| 151 | FROM '.TAGS_TABLE.' |
---|
[1717] | 152 | WHERE name = \''.$tag_name.'\' |
---|
[1119] | 153 | ;'; |
---|
| 154 | $existing_tags = array_from_query($query, 'id'); |
---|
| 155 | |
---|
| 156 | if (count($existing_tags) == 0) |
---|
| 157 | { |
---|
| 158 | mass_inserts( |
---|
| 159 | TAGS_TABLE, |
---|
| 160 | array('name', 'url_name'), |
---|
| 161 | array( |
---|
| 162 | array( |
---|
[1717] | 163 | 'name' => $tag_name, |
---|
[1119] | 164 | 'url_name' => str2url($tag_name), |
---|
| 165 | ) |
---|
| 166 | ) |
---|
| 167 | ); |
---|
| 168 | |
---|
| 169 | array_push( |
---|
| 170 | $page['infos'], |
---|
| 171 | sprintf( |
---|
[5036] | 172 | l10n('Tag "%s" was added'), |
---|
[1717] | 173 | stripslashes($tag_name) |
---|
[1119] | 174 | ) |
---|
| 175 | ); |
---|
| 176 | } |
---|
| 177 | else |
---|
| 178 | { |
---|
| 179 | array_push( |
---|
| 180 | $page['errors'], |
---|
| 181 | sprintf( |
---|
[5036] | 182 | l10n('Tag "%s" already exists'), |
---|
[1717] | 183 | stripslashes($tag_name) |
---|
[1119] | 184 | ) |
---|
| 185 | ); |
---|
| 186 | } |
---|
| 187 | } |
---|
| 188 | |
---|
| 189 | // +-----------------------------------------------------------------------+ |
---|
| 190 | // | template init | |
---|
| 191 | // +-----------------------------------------------------------------------+ |
---|
| 192 | |
---|
[2530] | 193 | $template->set_filenames(array('tags' => 'tags.tpl')); |
---|
[1119] | 194 | |
---|
[2277] | 195 | $template->assign( |
---|
[1119] | 196 | array( |
---|
[5195] | 197 | 'F_ACTION' => PHPWG_ROOT_PATH.'admin.php?page=tags', |
---|
| 198 | 'PWG_TOKEN' => get_pwg_token(), |
---|
[1119] | 199 | ) |
---|
| 200 | ); |
---|
| 201 | |
---|
| 202 | // +-----------------------------------------------------------------------+ |
---|
| 203 | // | form creation | |
---|
| 204 | // +-----------------------------------------------------------------------+ |
---|
| 205 | |
---|
[2277] | 206 | $template->assign( |
---|
[1119] | 207 | array( |
---|
| 208 | 'TAG_SELECTION' => get_html_tag_selection( |
---|
| 209 | get_all_tags(), |
---|
| 210 | 'tags' |
---|
| 211 | ), |
---|
| 212 | ) |
---|
| 213 | ); |
---|
| 214 | |
---|
| 215 | if (isset($_POST['edit']) and isset($_POST['tags'])) |
---|
| 216 | { |
---|
[2277] | 217 | $template->assign( |
---|
[1119] | 218 | array( |
---|
[2277] | 219 | 'EDIT_TAGS_LIST' => implode(',', $_POST['tags']), |
---|
[1119] | 220 | ) |
---|
| 221 | ); |
---|
| 222 | |
---|
| 223 | $query = ' |
---|
| 224 | SELECT id, name |
---|
| 225 | FROM '.TAGS_TABLE.' |
---|
| 226 | WHERE id IN ('.implode(',', $_POST['tags']).') |
---|
| 227 | ;'; |
---|
| 228 | $result = pwg_query($query); |
---|
[4325] | 229 | while ($row = pwg_db_fetch_assoc($result)) |
---|
[1119] | 230 | { |
---|
| 231 | $name_of[ $row['id'] ] = $row['name']; |
---|
| 232 | } |
---|
| 233 | |
---|
| 234 | foreach ($_POST['tags'] as $tag_id) |
---|
| 235 | { |
---|
[2277] | 236 | $template->append( |
---|
| 237 | 'tags', |
---|
[1119] | 238 | array( |
---|
| 239 | 'ID' => $tag_id, |
---|
| 240 | 'NAME' => $name_of[$tag_id], |
---|
| 241 | ) |
---|
| 242 | ); |
---|
| 243 | } |
---|
| 244 | } |
---|
| 245 | |
---|
| 246 | // +-----------------------------------------------------------------------+ |
---|
| 247 | // | sending html code | |
---|
| 248 | // +-----------------------------------------------------------------------+ |
---|
| 249 | |
---|
| 250 | $template->assign_var_from_handle('ADMIN_CONTENT', 'tags'); |
---|
| 251 | |
---|
| 252 | ?> |
---|