[61] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
| 3 | * picture_modify.php * |
---|
| 4 | * ------------------ * |
---|
| 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
| 7 | * * |
---|
| 8 | * $Id: picture_modify.php 279 2004-01-15 00:11:00Z gweltas $ |
---|
| 9 | * * |
---|
| 10 | ***************************************************************************/ |
---|
| 11 | |
---|
| 12 | /*************************************************************************** |
---|
| 13 | * * |
---|
| 14 | * This program is free software; you can redistribute it and/or modify * |
---|
| 15 | * it under the terms of the GNU General Public License as published by * |
---|
| 16 | * the Free Software Foundation; * |
---|
| 17 | * * |
---|
| 18 | ***************************************************************************/ |
---|
| 19 | |
---|
| 20 | include_once( './include/isadmin.inc.php' ); |
---|
| 21 | //--------------------------------------------------------- update informations |
---|
| 22 | $errors = array(); |
---|
| 23 | // first, we verify whether there is a mistake on the given creation date |
---|
| 24 | if ( isset( $_POST['creation_date'] ) and $_POST['creation_date'] != '' ) |
---|
| 25 | { |
---|
| 26 | if ( !check_date_format( $_POST['creation_date'] ) ) |
---|
| 27 | array_push( $errors, $lang['err_date'] ); |
---|
| 28 | } |
---|
| 29 | if ( isset( $_POST['submit'] ) ) |
---|
| 30 | { |
---|
| 31 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
| 32 | |
---|
| 33 | $query.= ' SET name = '; |
---|
| 34 | if ( $_POST['name'] == '' ) |
---|
| 35 | $query.= 'NULL'; |
---|
| 36 | else |
---|
| 37 | $query.= "'".htmlentities( $_POST['name'], ENT_QUOTES )."'"; |
---|
| 38 | |
---|
| 39 | $query.= ', author = '; |
---|
| 40 | if ( $_POST['author'] == '' ) |
---|
| 41 | $query.= 'NULL'; |
---|
| 42 | else |
---|
| 43 | $query.= "'".htmlentities($_POST['author'],ENT_QUOTES)."'"; |
---|
| 44 | |
---|
| 45 | $query.= ', comment = '; |
---|
| 46 | if ( $_POST['comment'] == '' ) |
---|
| 47 | $query.= 'NULL'; |
---|
| 48 | else |
---|
| 49 | $query.= "'".htmlentities($_POST['comment'],ENT_QUOTES)."'"; |
---|
| 50 | |
---|
| 51 | $query.= ', date_creation = '; |
---|
| 52 | if ( check_date_format( $_POST['creation_date'] ) ) |
---|
| 53 | $query.= "'".date_convert( $_POST['creation_date'] )."'"; |
---|
| 54 | else if ( $_POST['creation_date'] == '' ) |
---|
| 55 | $query.= 'NULL'; |
---|
| 56 | |
---|
| 57 | $query.= ', keywords = '; |
---|
| 58 | $keywords_array = get_keywords( $_POST['keywords'] ); |
---|
| 59 | if ( count( $keywords_array ) == 0 ) |
---|
| 60 | $query.= 'NULL'; |
---|
| 61 | else |
---|
| 62 | { |
---|
| 63 | $query.= "'"; |
---|
| 64 | foreach ( $keywords_array as $i => $keyword ) { |
---|
| 65 | if ( $i > 0 ) $query.= ','; |
---|
| 66 | $query.= $keyword; |
---|
| 67 | } |
---|
| 68 | $query.= "'"; |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
| 72 | $query.= ';'; |
---|
| 73 | mysql_query( $query ); |
---|
[133] | 74 | // make the picture representative of a category ? |
---|
| 75 | $query = 'SELECT DISTINCT(category_id) as category_id'; |
---|
| 76 | $query.= ',representative_picture_id'; |
---|
| 77 | $query.= ' FROM '.PREFIX_TABLE.'image_category AS ic'; |
---|
| 78 | $query.= ', '.PREFIX_TABLE.'categories AS c'; |
---|
| 79 | $query.= ' WHERE c.id = ic.category_id'; |
---|
| 80 | $query.= ' AND image_id = '.$_GET['image_id']; |
---|
| 81 | $query.= ';'; |
---|
| 82 | $result = mysql_query( $query ); |
---|
| 83 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 84 | { |
---|
| 85 | // if the user ask the picture to be the representative picture of its |
---|
| 86 | // category, the category is updated in the database (without wondering |
---|
| 87 | // if this picture was already the representative one) |
---|
[279] | 88 | if ( isset($_POST['representative-'.$row['category_id']]) ) |
---|
[133] | 89 | { |
---|
| 90 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
| 91 | $query.= ' SET representative_picture_id = '.$_GET['image_id']; |
---|
| 92 | $query.= ' WHERE id = '.$row['category_id']; |
---|
| 93 | $query.= ';'; |
---|
| 94 | mysql_query( $query ); |
---|
| 95 | } |
---|
| 96 | // if the user ask this picture to be not any more the representative, |
---|
| 97 | // we have to set the representative_picture_id of this category to NULL |
---|
| 98 | else if ( $row['representative_picture_id'] == $_GET['image_id'] ) |
---|
| 99 | { |
---|
| 100 | $query = 'UPDATE '.PREFIX_TABLE.'categories'; |
---|
| 101 | $query.= ' SET representative_picture_id = NULL'; |
---|
| 102 | $query.= ' WHERE id = '.$row['category_id']; |
---|
| 103 | $query.= ';'; |
---|
| 104 | mysql_query( $query ); |
---|
| 105 | } |
---|
| 106 | } |
---|
[258] | 107 | $associate_or_dissociate = false; |
---|
[61] | 108 | // associate with a new category ? |
---|
[258] | 109 | if ( $_POST['associate'] != '-1' and $_POST['associate'] != '' ) |
---|
[61] | 110 | { |
---|
[258] | 111 | // does the uppercat id exists in the database ? |
---|
| 112 | if ( !is_numeric( $_POST['associate'] ) ) |
---|
| 113 | { |
---|
| 114 | array_push( $errors, $lang['cat_unknown_id'] ); |
---|
| 115 | } |
---|
| 116 | else |
---|
| 117 | { |
---|
| 118 | $query = 'SELECT id'; |
---|
| 119 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
| 120 | $query.= ' WHERE id = '.$_POST['associate']; |
---|
| 121 | $query.= ';'; |
---|
| 122 | if ( mysql_num_rows( mysql_query( $query ) ) == 0 ) |
---|
| 123 | array_push( $errors, $lang['cat_unknown_id'] ); |
---|
| 124 | } |
---|
| 125 | } |
---|
| 126 | if ( $_POST['associate'] != '-1' |
---|
| 127 | and $_POST['associate'] != '' |
---|
| 128 | and count( $errors ) == 0 ) |
---|
| 129 | { |
---|
[61] | 130 | $query = 'INSERT INTO '.PREFIX_TABLE.'image_category'; |
---|
| 131 | $query.= ' (category_id,image_id) VALUES '; |
---|
| 132 | $query.= '('.$_POST['associate'].','.$_GET['image_id'].')'; |
---|
| 133 | $query.= ';'; |
---|
| 134 | mysql_query( $query); |
---|
[258] | 135 | $associate_or_dissociate = true; |
---|
[61] | 136 | update_category( $_POST['associate'] ); |
---|
| 137 | } |
---|
| 138 | // dissociate any category ? |
---|
| 139 | // retrieving all the linked categories |
---|
| 140 | $query = 'SELECT DISTINCT(category_id) as category_id'; |
---|
| 141 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
| 142 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
| 143 | $query.= ';'; |
---|
| 144 | $result = mysql_query( $query ); |
---|
| 145 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 146 | { |
---|
[279] | 147 | if ( isset($_POST['dissociate-'.$row['category_id']]) ) |
---|
[61] | 148 | { |
---|
| 149 | $query = 'DELETE FROM '.PREFIX_TABLE.'image_category'; |
---|
| 150 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
| 151 | $query.= ' AND category_id = '.$row['category_id']; |
---|
| 152 | $query.= ';'; |
---|
| 153 | mysql_query( $query ); |
---|
[258] | 154 | $associate_or_dissociate = true; |
---|
[61] | 155 | update_category( $row['category_id'] ); |
---|
| 156 | } |
---|
| 157 | } |
---|
[258] | 158 | if ( $associate_or_dissociate ) |
---|
| 159 | { |
---|
| 160 | synchronize_all_users(); |
---|
| 161 | } |
---|
[61] | 162 | } |
---|
| 163 | //----------------------------------------------------- template initialization |
---|
| 164 | $sub = $vtp->Open( |
---|
| 165 | '../template/'.$user['template'].'/admin/picture_modify.vtp' ); |
---|
| 166 | |
---|
| 167 | $tpl = array( 'submit','errors_title','picmod_update','picmod_back', |
---|
| 168 | 'default','file','size','filesize','registration_date', |
---|
| 169 | 'author','creation_date','keywords','comment', 'upload_name', |
---|
| 170 | 'dissociate','categories','infoimage_associate', |
---|
[133] | 171 | 'cat_image_info','category_representative' ); |
---|
[61] | 172 | templatize_array( $tpl, 'lang', $sub ); |
---|
| 173 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
| 174 | //-------------------------------------------------------------- errors display |
---|
| 175 | if ( count( $errors ) != 0 ) |
---|
| 176 | { |
---|
| 177 | $vtp->addSession( $sub, 'errors' ); |
---|
| 178 | foreach ( $errors as $error ) { |
---|
| 179 | $vtp->addSession( $sub, 'li' ); |
---|
| 180 | $vtp->setVar( $sub, 'li.content', $error ); |
---|
| 181 | $vtp->closeSession( $sub, 'li' ); |
---|
| 182 | } |
---|
| 183 | $vtp->closeSession( $sub, 'errors' ); |
---|
| 184 | } |
---|
| 185 | //-------------------------------------------- displaying informations and form |
---|
| 186 | $action = './admin.php?'.$_SERVER['QUERY_STRING']; |
---|
| 187 | $vtp->setVar( $sub, 'form_action', $action ); |
---|
| 188 | // retrieving direct information about picture |
---|
| 189 | $query = 'SELECT file,date_available,date_creation,tn_ext,name,filesize'; |
---|
| 190 | $query.= ',width,height,author,comment,keywords,storage_category_id'; |
---|
| 191 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
| 192 | $query.= ' WHERE id = '.$_GET['image_id']; |
---|
| 193 | $query.= ';'; |
---|
| 194 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 195 | // picture title |
---|
| 196 | if ( $row['name'] == '' ) |
---|
| 197 | { |
---|
| 198 | $title = str_replace( '_',' ',get_filename_wo_extension($row['file']) ); |
---|
| 199 | } |
---|
| 200 | else |
---|
| 201 | { |
---|
| 202 | $title = $row['name']; |
---|
| 203 | } |
---|
| 204 | $vtp->setVar( $sub, 'title', $title ); |
---|
| 205 | $vtp->setVar( $sub, 'f_file', $row['file'] ); |
---|
| 206 | $vtp->setVar( $sub, 'f_size', $row['width'].' * '.$row['height'] ); |
---|
| 207 | $vtp->setVar( $sub, 'f_filesize', $row['filesize'].' KB' ); |
---|
| 208 | $vtp->setVar( $sub, 'f_registration_date',format_date($row['date_available'])); |
---|
| 209 | $default_name = str_replace( '_',' ',get_filename_wo_extension($row['file']) ); |
---|
| 210 | $vtp->setVar( $sub, 'default_name', $default_name ); |
---|
| 211 | // if this form is displayed after an unsucceeded submit, we have to display |
---|
| 212 | // the values filled by the user (wright or wrong). |
---|
| 213 | if ( count( $errors ) > 0 ) |
---|
| 214 | { |
---|
| 215 | $name = $_POST['name']; |
---|
| 216 | $author = $_POST['author']; |
---|
| 217 | $creation_date = $_POST['creation_date']; |
---|
| 218 | $keywords = $_POST['keywords']; |
---|
| 219 | $comment = $_POST['comment']; |
---|
| 220 | } |
---|
| 221 | else |
---|
| 222 | { |
---|
| 223 | $name = $row['name']; |
---|
| 224 | $author = $row['author']; |
---|
| 225 | $creation_date = date_convert_back( $row['date_creation'] ); |
---|
| 226 | $keywords = $row['keywords']; |
---|
| 227 | $comment = $row['comment']; |
---|
| 228 | } |
---|
| 229 | $vtp->setVar( $sub, 'f_name', $name ); |
---|
| 230 | $vtp->setVar( $sub, 'f_author', $author ); |
---|
| 231 | $vtp->setVar( $sub, 'f_creation_date', $creation_date ); |
---|
| 232 | $vtp->setVar( $sub, 'f_keywords', $keywords ); |
---|
| 233 | $vtp->setVar( $sub, 'f_comment', $comment ); |
---|
| 234 | // retrieving directory where picture is stored (for displaying the |
---|
| 235 | // thumbnail) |
---|
| 236 | $thumbnail_url = get_complete_dir( $row['storage_category_id'] ); |
---|
| 237 | $result = get_cat_info( $row['storage_category_id'] ); |
---|
| 238 | $cat_name = get_cat_display_name( $result['name'], ' > ', '' ); |
---|
| 239 | $vtp->setVar( $sub, 'dir', $cat_name ); |
---|
| 240 | if ( $result['site_id'] == 1 ) $thumbnail_url = '.'.$thumbnail_url; |
---|
| 241 | $file_wo_ext = get_filename_wo_extension( $row['file'] ); |
---|
| 242 | $thumbnail_url.= '/thumbnail/'; |
---|
| 243 | $thumbnail_url.= $conf['prefix_thumbnail'].$file_wo_ext.'.'.$row['tn_ext']; |
---|
| 244 | $vtp->setVar( $sub, 'thumbnail_url', $thumbnail_url ); |
---|
| 245 | // storage category is linked by default |
---|
| 246 | $vtp->addSession( $sub, 'linked_category' ); |
---|
| 247 | $vtp->setVar( $sub, 'linked_category.name', $cat_name ); |
---|
| 248 | $url = '../picture.php?image_id='.$_GET['image_id']; |
---|
| 249 | $url.= '&cat='.$row['storage_category_id']; |
---|
| 250 | $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url)); |
---|
| 251 | $url = './admin.php?page=infos_images&cat_id='.$row['storage_category_id']; |
---|
| 252 | $vtp->setVar( $sub, 'linked_category.infos_images_link',add_session_id( $url)); |
---|
| 253 | if ( $result['status'] == 'private' ) |
---|
| 254 | { |
---|
| 255 | $private_string = '<span style="color:red;font-weight:bold;">'; |
---|
| 256 | $private_string.= $lang['private'].'</span>'; |
---|
| 257 | $vtp->setVar( $sub, 'linked_category.private', $private_string ); |
---|
| 258 | } |
---|
| 259 | if ( !$result['visible'] ) |
---|
| 260 | { |
---|
| 261 | $invisible_string = '<span style="color:red;">'; |
---|
| 262 | $invisible_string.= $lang['cat_invisible'].'</span>'; |
---|
| 263 | $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string ); |
---|
| 264 | } |
---|
[133] | 265 | $vtp->setVar( $sub, 'linked_category.id', $row['storage_category_id'] ); |
---|
| 266 | if ( $result['representative_picture_id'] == $_GET['image_id'] ) |
---|
| 267 | { |
---|
| 268 | $vtp->setVar( $sub, 'linked_category.representative_checked', |
---|
| 269 | ' checked="checked"' ); |
---|
| 270 | } |
---|
[61] | 271 | $vtp->closeSession( $sub, 'linked_category' ); |
---|
| 272 | // retrieving all the linked categories |
---|
| 273 | $query = 'SELECT DISTINCT(category_id) as category_id,status,visible'; |
---|
[133] | 274 | $query.= ',representative_picture_id'; |
---|
[61] | 275 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
| 276 | $query.= ','.PREFIX_TABLE.'categories'; |
---|
| 277 | $query.= ' WHERE image_id = '.$_GET['image_id']; |
---|
| 278 | $query.= ' AND category_id != '.$row['storage_category_id']; |
---|
| 279 | $query.= ' AND category_id = id'; |
---|
| 280 | $query.= ';'; |
---|
| 281 | $result = mysql_query( $query ); |
---|
| 282 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 283 | { |
---|
| 284 | $vtp->addSession( $sub, 'linked_category' ); |
---|
[133] | 285 | $vtp->setVar( $sub, 'linked_category.id', $row['category_id'] ); |
---|
[61] | 286 | |
---|
| 287 | $vtp->addSession( $sub, 'checkbox' ); |
---|
| 288 | $vtp->setVar( $sub, 'checkbox.id', $row['category_id'] ); |
---|
| 289 | $vtp->closeSession( $sub, 'checkbox' ); |
---|
| 290 | |
---|
| 291 | $cat_infos = get_cat_info( $row['category_id'] ); |
---|
| 292 | $cat_name = get_cat_display_name( $cat_infos['name'], ' > ', '' ); |
---|
| 293 | $vtp->setVar( $sub, 'linked_category.name', $cat_name ); |
---|
| 294 | |
---|
| 295 | $url = '../picture.php?image_id='.$_GET['image_id']; |
---|
| 296 | $url.= '&cat='.$row['category_id']; |
---|
| 297 | $vtp->setVar( $sub, 'linked_category.url',add_session_id( $url)); |
---|
| 298 | |
---|
| 299 | $url = './admin.php?page=infos_images&cat_id='.$row['category_id']; |
---|
| 300 | $vtp->setVar( $sub, 'linked_category.infos_images_link', |
---|
| 301 | add_session_id( $url)); |
---|
| 302 | |
---|
| 303 | if ( $row['status'] == 'private' ) |
---|
| 304 | { |
---|
| 305 | $private_string = '<span style="color:red;font-weight:bold;">'; |
---|
| 306 | $private_string.= $lang['private'].'</span>'; |
---|
| 307 | $vtp->setVar( $sub, 'linked_category.private', $private_string ); |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | if ( !get_boolean( $row['visible'] ) ) |
---|
| 311 | { |
---|
| 312 | $invisible_string = '<span style="color:red;">'; |
---|
| 313 | $invisible_string.= $lang['cat_invisible'].'</span>'; |
---|
| 314 | $vtp->setVar( $sub, 'linked_category.invisible', $invisible_string ); |
---|
| 315 | } |
---|
| 316 | |
---|
[133] | 317 | if ( $row['representative_picture_id'] == $_GET['image_id'] ) |
---|
| 318 | { |
---|
| 319 | $vtp->setVar( $sub, 'linked_category.representative_checked', |
---|
| 320 | ' checked="checked"' ); |
---|
| 321 | } |
---|
| 322 | |
---|
[61] | 323 | $vtp->closeSession( $sub, 'linked_category' ); |
---|
| 324 | } |
---|
| 325 | // if there are linked category other than the storage category, we show |
---|
| 326 | // propose the dissociate text |
---|
| 327 | if ( mysql_num_rows( $result ) > 0 ) |
---|
| 328 | { |
---|
| 329 | $vtp->addSession( $sub, 'dissociate' ); |
---|
| 330 | $vtp->closeSession( $sub, 'dissociate' ); |
---|
| 331 | } |
---|
| 332 | // associate to another category ? |
---|
[258] | 333 | // |
---|
| 334 | // We only show a List Of Values if the number of categories is less than |
---|
| 335 | // $conf['max_LOV_categories'] |
---|
| 336 | $query = 'SELECT COUNT(id) AS nb_total_categories'; |
---|
| 337 | $query.= ' FROM '.PREFIX_TABLE.'categories'; |
---|
| 338 | $query.= ';'; |
---|
| 339 | $row = mysql_fetch_array( mysql_query( $query ) ); |
---|
| 340 | if ( $row['nb_total_categories'] < $conf['max_LOV_categories'] ) |
---|
| 341 | { |
---|
| 342 | $vtp->addSession( $sub, 'associate_LOV' ); |
---|
| 343 | $vtp->addSession( $sub, 'associate_cat' ); |
---|
| 344 | $vtp->setVar( $sub, 'associate_cat.value', '-1' ); |
---|
| 345 | $vtp->setVar( $sub, 'associate_cat.content', '' ); |
---|
| 346 | $vtp->closeSession( $sub, 'associate_cat' ); |
---|
| 347 | $page['plain_structure'] = get_plain_structure( true ); |
---|
| 348 | $structure = create_structure( '', array() ); |
---|
| 349 | display_categories( $structure, ' ' ); |
---|
| 350 | $vtp->closeSession( $sub, 'associate_LOV' ); |
---|
| 351 | } |
---|
| 352 | // else, we only display a small text field, we suppose the administrator |
---|
| 353 | // knows the id of its category |
---|
| 354 | else |
---|
| 355 | { |
---|
| 356 | $vtp->addSession( $sub, 'associate_text' ); |
---|
| 357 | $vtp->closeSession( $sub, 'associate_text' ); |
---|
| 358 | } |
---|
[61] | 359 | //----------------------------------------------------------- sending html code |
---|
| 360 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
| 361 | ?> |
---|