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