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