[61] | 1 | <?php |
---|
[362] | 2 | // +-----------------------------------------------------------------------+ |
---|
[593] | 3 | // | PhpWebGallery - a PHP based picture gallery | |
---|
| 4 | // | Copyright (C) 2002-2003 Pierrick LE GALL - pierrick@phpwebgallery.net | |
---|
[675] | 5 | // | Copyright (C) 2003-2005 PhpWebGallery Team - http://phpwebgallery.net | |
---|
[362] | 6 | // +-----------------------------------------------------------------------+ |
---|
[593] | 7 | // | branch : BSF (Best So Far) |
---|
[362] | 8 | // | file : $RCSfile$ |
---|
| 9 | // | last update : $Date: 2005-01-07 23:10:51 +0000 (Fri, 07 Jan 2005) $ |
---|
| 10 | // | last modifier : $Author: plg $ |
---|
| 11 | // | revision : $Revision: 675 $ |
---|
| 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 | // +-----------------------------------------------------------------------+ |
---|
[61] | 27 | |
---|
[575] | 28 | if(!defined("PHPWG_ROOT_PATH")) |
---|
[509] | 29 | { |
---|
[575] | 30 | die ("Hacking attempt!"); |
---|
[509] | 31 | } |
---|
[575] | 32 | include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); |
---|
[61] | 33 | //--------------------------------------------------------- update informations |
---|
| 34 | $errors = array(); |
---|
| 35 | // first, we verify whether there is a mistake on the given creation date |
---|
[575] | 36 | if (isset($_POST['date_creation']) and !empty($_POST['date_creation'])) |
---|
[61] | 37 | { |
---|
[575] | 38 | if (!check_date_format($_POST['date_creation'])) |
---|
| 39 | { |
---|
| 40 | array_push($errors, $lang['err_date']); |
---|
| 41 | } |
---|
[61] | 42 | } |
---|
[575] | 43 | if (isset($_POST['submit'])) |
---|
[61] | 44 | { |
---|
[509] | 45 | $query = 'UPDATE '.IMAGES_TABLE.' SET name = '; |
---|
[575] | 46 | if ($_POST['name'] == '') |
---|
[61] | 47 | $query.= 'NULL'; |
---|
| 48 | else |
---|
[575] | 49 | $query.= "'".htmlentities($_POST['name'], ENT_QUOTES)."'"; |
---|
[61] | 50 | |
---|
| 51 | $query.= ', author = '; |
---|
[575] | 52 | if ($_POST['author'] == '') |
---|
[61] | 53 | $query.= 'NULL'; |
---|
| 54 | else |
---|
| 55 | $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'"; |
---|
| 56 | |
---|
| 57 | $query.= ', comment = '; |
---|
[575] | 58 | if ($_POST['comment'] == '') |
---|
[61] | 59 | $query.= 'NULL'; |
---|
| 60 | else |
---|
| 61 | $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'"; |
---|
| 62 | |
---|
| 63 | $query.= ', date_creation = '; |
---|
[575] | 64 | if (check_date_format($_POST['date_creation'])) |
---|
| 65 | $query.= "'".date_convert($_POST['date_creation'])."'"; |
---|
| 66 | else if ($_POST['date_creation'] == '') |
---|
[61] | 67 | $query.= 'NULL'; |
---|
| 68 | |
---|
| 69 | $query.= ', keywords = '; |
---|
[575] | 70 | $keywords_array = get_keywords($_POST['keywords']); |
---|
| 71 | if (count($keywords_array) == 0) |
---|
[61] | 72 | $query.= 'NULL'; |
---|
| 73 | else |
---|
| 74 | { |
---|
| 75 | $query.= "'"; |
---|
[575] | 76 | foreach ($keywords_array as $i => $keyword) { |
---|
| 77 | if ($i > 0) $query.= ','; |
---|
[61] | 78 | $query.= $keyword; |
---|
| 79 | } |
---|
| 80 | $query.= "'"; |
---|
| 81 | } |
---|
| 82 | |
---|
| 83 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
| 84 | $query.= ';'; |
---|
[587] | 85 | pwg_query($query); |
---|
[635] | 86 | } |
---|
| 87 | // associate the element to other categories than its storage category |
---|
| 88 | if (isset($_POST['associate']) |
---|
| 89 | and isset($_POST['cat_dissociated']) |
---|
| 90 | and count($_POST['cat_dissociated']) > 0) |
---|
| 91 | { |
---|
| 92 | $datas = array(); |
---|
| 93 | foreach ($_POST['cat_dissociated'] as $category_id) |
---|
[133] | 94 | { |
---|
[635] | 95 | array_push($datas, array('image_id' => $_GET['image_id'], |
---|
| 96 | 'category_id' => $category_id)); |
---|
[133] | 97 | } |
---|
[635] | 98 | mass_inserts(IMAGE_CATEGORY_TABLE, array('image_id', 'category_id'), $datas); |
---|
| 99 | |
---|
| 100 | update_category($_POST['cat_dissociated']); |
---|
| 101 | } |
---|
| 102 | // dissociate the element from categories (but not from its storage category) |
---|
| 103 | if (isset($_POST['dissociate']) |
---|
| 104 | and isset($_POST['cat_associated']) |
---|
| 105 | and count($_POST['cat_associated']) > 0) |
---|
| 106 | { |
---|
[575] | 107 | $query = ' |
---|
| 108 | DELETE FROM '.IMAGE_CATEGORY_TABLE.' |
---|
| 109 | WHERE image_id = '.$_GET['image_id'].' |
---|
[635] | 110 | AND category_id IN ('.implode(',',$_POST['cat_associated'] ).') |
---|
| 111 | '; |
---|
| 112 | pwg_query($query); |
---|
| 113 | update_category($_POST['cat_associated']); |
---|
[61] | 114 | } |
---|
[640] | 115 | // elect the element to represent the given categories |
---|
| 116 | if (isset($_POST['elect']) |
---|
| 117 | and isset($_POST['cat_dismissed']) |
---|
| 118 | and count($_POST['cat_dismissed']) > 0) |
---|
| 119 | { |
---|
| 120 | $datas = array(); |
---|
| 121 | foreach ($_POST['cat_dismissed'] as $category_id) |
---|
| 122 | { |
---|
| 123 | array_push($datas, |
---|
| 124 | array('id' => $category_id, |
---|
| 125 | 'representative_picture_id' => $_GET['image_id'])); |
---|
| 126 | } |
---|
| 127 | $fields = array('primary' => array('id'), |
---|
| 128 | 'update' => array('representative_picture_id')); |
---|
| 129 | mass_updates(CATEGORIES_TABLE, $fields, $datas); |
---|
| 130 | } |
---|
| 131 | // dismiss the element as representant of the given categories |
---|
| 132 | if (isset($_POST['dismiss']) |
---|
| 133 | and isset($_POST['cat_elected']) |
---|
| 134 | and count($_POST['cat_elected']) > 0) |
---|
| 135 | { |
---|
| 136 | set_random_representant($_POST['cat_elected']); |
---|
| 137 | } |
---|
[61] | 138 | |
---|
| 139 | // retrieving direct information about picture |
---|
[575] | 140 | $query = ' |
---|
[635] | 141 | SELECT i.*, c.uppercats |
---|
| 142 | FROM '.IMAGES_TABLE.' AS i |
---|
| 143 | INNER JOIN '.CATEGORIES_TABLE.' AS c ON i.storage_category_id = c.id |
---|
| 144 | WHERE i.id = '.$_GET['image_id'].' |
---|
[575] | 145 | ;'; |
---|
[587] | 146 | $row = mysql_fetch_array(pwg_query($query)); |
---|
[345] | 147 | |
---|
[635] | 148 | $storage_category_id = $row['storage_category_id']; |
---|
| 149 | |
---|
[575] | 150 | if (empty($row['name'])) |
---|
| 151 | { |
---|
| 152 | $title = str_replace('_', ' ',get_filename_wo_extension($row['file'])); |
---|
| 153 | } |
---|
| 154 | else |
---|
| 155 | { |
---|
| 156 | $title = $row['name']; |
---|
| 157 | } |
---|
[509] | 158 | // Navigation path |
---|
[606] | 159 | $thumbnail_url = get_thumbnail_src($row['path'], @$row['tn_ext']); |
---|
[577] | 160 | |
---|
[509] | 161 | $url_img = PHPWG_ROOT_PATH.'picture.php?image_id='.$_GET['image_id']; |
---|
| 162 | $url_img .= '&cat='.$row['storage_category_id']; |
---|
| 163 | $date = isset($_POST['date_creation']) && empty($errors) |
---|
[635] | 164 | ?$_POST['date_creation']:date_convert_back(@$row['date_creation']); |
---|
[642] | 165 | |
---|
| 166 | $url = PHPWG_ROOT_PATH.'admin.php?page=cat_modify&cat_id='; |
---|
[635] | 167 | $storage_category = get_cat_display_name_cache($row['uppercats'], |
---|
[642] | 168 | $url, |
---|
[635] | 169 | false); |
---|
[509] | 170 | //----------------------------------------------------- template initialization |
---|
[575] | 171 | $template->set_filenames(array('picture_modify'=>'admin/picture_modify.tpl')); |
---|
[509] | 172 | $template->assign_vars(array( |
---|
| 173 | 'TITLE_IMG'=>$title, |
---|
[635] | 174 | 'STORAGE_CATEGORY_IMG'=>$storage_category, |
---|
| 175 | 'PATH_IMG'=>$row['path'], |
---|
[509] | 176 | 'FILE_IMG'=>$row['file'], |
---|
| 177 | 'TN_URL_IMG'=>$thumbnail_url, |
---|
[575] | 178 | 'URL_IMG'=>add_session_id($url_img), |
---|
| 179 | 'DEFAULT_NAME_IMG'=>str_replace('_',' ',get_filename_wo_extension($row['file'])), |
---|
| 180 | 'FILE_IMG'=>$row['file'], |
---|
[579] | 181 | 'NAME_IMG'=>isset($_POST['name'])?$_POST['name']:@$row['name'], |
---|
| 182 | 'SIZE_IMG'=>@$row['width'].' * '.@$row['height'], |
---|
| 183 | 'FILESIZE_IMG'=>@$row['filesize'].' KB', |
---|
[509] | 184 | 'REGISTRATION_DATE_IMG'=> format_date($row['date_available']), |
---|
[579] | 185 | 'AUTHOR_IMG'=>isset($_POST['author'])?$_POST['author']:@$row['author'], |
---|
[509] | 186 | 'CREATION_DATE_IMG'=>$date, |
---|
[579] | 187 | 'KEYWORDS_IMG'=>isset($_POST['keywords'])?$_POST['keywords']:@$row['keywords'], |
---|
| 188 | 'COMMENT_IMG'=>isset($_POST['comment'])?$_POST['comment']:@$row['comment'], |
---|
[509] | 189 | |
---|
| 190 | 'L_UPLOAD_NAME'=>$lang['upload_name'], |
---|
| 191 | 'L_DEFAULT'=>$lang['default'], |
---|
| 192 | 'L_FILE'=>$lang['file'], |
---|
| 193 | 'L_SIZE'=>$lang['size'], |
---|
| 194 | 'L_FILESIZE'=>$lang['filesize'], |
---|
| 195 | 'L_REGISTRATION_DATE'=>$lang['registration_date'], |
---|
| 196 | 'L_AUTHOR'=>$lang['author'], |
---|
| 197 | 'L_CREATION_DATE'=>$lang['creation_date'], |
---|
| 198 | 'L_KEYWORDS'=>$lang['keywords'], |
---|
[649] | 199 | 'L_COMMENT'=>$lang['description'], |
---|
[509] | 200 | 'L_CATEGORIES'=>$lang['categories'], |
---|
| 201 | 'L_DISSOCIATE'=>$lang['dissociate'], |
---|
| 202 | 'L_INFOIMAGE_ASSOCIATE'=>$lang['infoimage_associate'], |
---|
| 203 | 'L_SUBMIT'=>$lang['submit'], |
---|
[635] | 204 | 'L_RESET'=>$lang['reset'], |
---|
[646] | 205 | 'L_CAT_ASSOCIATED'=>$lang['infoimage_associated'], |
---|
| 206 | 'L_CAT_DISSOCIATED'=>$lang['infoimage_dissociated'], |
---|
[635] | 207 | 'L_PATH'=>$lang['path'], |
---|
| 208 | 'L_STORAGE_CATEGORY'=>$lang['storage_category'], |
---|
[640] | 209 | 'L_REPRESENTS'=>$lang['represents'], |
---|
| 210 | 'L_DOESNT_REPRESENT'=>$lang['doesnt_represent'], |
---|
[509] | 211 | |
---|
| 212 | 'F_ACTION'=>add_session_id(PHPWG_ROOT_PATH.'admin.php?'.$_SERVER['QUERY_STRING']) |
---|
[575] | 213 | )); |
---|
[509] | 214 | |
---|
| 215 | //-------------------------------------------------------------- errors display |
---|
[635] | 216 | if (count($errors) != 0) |
---|
[509] | 217 | { |
---|
| 218 | $template->assign_block_vars('errors',array()); |
---|
[635] | 219 | foreach ($errors as $error) |
---|
[61] | 220 | { |
---|
[635] | 221 | $template->assign_block_vars('errors.error',array('ERROR'=>$error)); |
---|
[61] | 222 | } |
---|
[509] | 223 | } |
---|
[61] | 224 | |
---|
| 225 | // associate to another category ? |
---|
[635] | 226 | $query = ' |
---|
| 227 | SELECT id,name,uppercats,global_rank |
---|
| 228 | FROM '.CATEGORIES_TABLE.' |
---|
| 229 | INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = category_id |
---|
| 230 | WHERE image_id = '.$_GET['image_id'].' |
---|
| 231 | AND id != '.$storage_category_id.' |
---|
| 232 | ;'; |
---|
| 233 | display_select_cat_wrapper($query,array(),'associated_option'); |
---|
| 234 | |
---|
| 235 | $result = pwg_query($query); |
---|
| 236 | $associateds = array($storage_category_id); |
---|
| 237 | while ($row = mysql_fetch_array($result)) |
---|
[345] | 238 | { |
---|
[635] | 239 | array_push($associateds, $row['id']); |
---|
[345] | 240 | } |
---|
[635] | 241 | $query = ' |
---|
| 242 | SELECT id,name,uppercats,global_rank |
---|
| 243 | FROM '.CATEGORIES_TABLE.' |
---|
| 244 | WHERE id NOT IN ('.implode(',', $associateds).') |
---|
| 245 | ;'; |
---|
| 246 | display_select_cat_wrapper($query,array(),'dissociated_option'); |
---|
[640] | 247 | // representing |
---|
| 248 | $query = ' |
---|
| 249 | SELECT id,name,uppercats,global_rank |
---|
| 250 | FROM '.CATEGORIES_TABLE.' |
---|
| 251 | WHERE representative_picture_id = '.$_GET['image_id'].' |
---|
| 252 | ;'; |
---|
| 253 | display_select_cat_wrapper($query,array(),'elected_option'); |
---|
| 254 | |
---|
| 255 | $query = ' |
---|
| 256 | SELECT id,name,uppercats,global_rank |
---|
| 257 | FROM '.CATEGORIES_TABLE.' |
---|
| 258 | WHERE id IN ('.implode(',', $associateds).') |
---|
| 259 | AND representative_picture_id != '.$_GET['image_id'].' |
---|
| 260 | ;'; |
---|
| 261 | display_select_cat_wrapper($query,array(),'dismissed_option'); |
---|
[61] | 262 | //----------------------------------------------------------- sending html code |
---|
[509] | 263 | $template->assign_var_from_handle('ADMIN_CONTENT', 'picture_modify'); |
---|
[362] | 264 | ?> |
---|