[2] | 1 | <?php |
---|
| 2 | /*************************************************************************** |
---|
[14] | 3 | * infos_images.php * |
---|
| 4 | * ------------------ * |
---|
[57] | 5 | * application : PhpWebGallery 1.3 <http://phpwebgallery.net> * |
---|
| 6 | * author : Pierrick LE GALL <pierrick@z0rglub.com> * |
---|
[2] | 7 | * * |
---|
[57] | 8 | * $Id: infos_images.php 61 2003-08-30 15:54:37Z z0rglub $ |
---|
| 9 | * * |
---|
[2] | 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 | ***************************************************************************/ |
---|
[14] | 19 | |
---|
| 20 | include_once( './include/isadmin.inc.php' ); |
---|
| 21 | include_once( '../template/'.$user['template'].'/htmlfunctions.inc.php' ); |
---|
| 22 | //-------------------------------------------------------------- initialization |
---|
| 23 | check_cat_id( $_GET['cat_id'] ); |
---|
| 24 | if ( isset( $page['cat'] ) ) |
---|
| 25 | { |
---|
| 26 | //--------------------------------------------------- update individual options |
---|
| 27 | $query = 'SELECT id,file'; |
---|
| 28 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
[61] | 29 | $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
| 30 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
[14] | 31 | $query.= ';'; |
---|
| 32 | $result = mysql_query( $query ); |
---|
| 33 | $i = 1; |
---|
| 34 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 35 | { |
---|
| 36 | $name = 'name-'.$row['id']; |
---|
| 37 | $author = 'author-'.$row['id']; |
---|
| 38 | $comment = 'comment-'.$row['id']; |
---|
| 39 | $date_creation = 'date_creation-'.$row['id']; |
---|
[33] | 40 | $keywords = 'keywords-'.$row['id']; |
---|
[14] | 41 | if ( isset( $_POST[$name] ) ) |
---|
| 42 | { |
---|
| 43 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
[33] | 44 | |
---|
| 45 | $query.= ' SET name = '; |
---|
[14] | 46 | if ( $_POST[$name] == '' ) |
---|
[33] | 47 | $query.= 'NULL'; |
---|
[14] | 48 | else |
---|
[33] | 49 | $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES )."'"; |
---|
| 50 | |
---|
| 51 | $query.= ', author = '; |
---|
[14] | 52 | if ( $_POST[$author] == '' ) |
---|
[33] | 53 | $query.= 'NULL'; |
---|
[14] | 54 | else |
---|
[33] | 55 | $query.= "'".htmlentities($_POST[$author],ENT_QUOTES)."'"; |
---|
| 56 | |
---|
| 57 | $query.= ', comment = '; |
---|
[14] | 58 | if ( $_POST[$comment] == '' ) |
---|
[33] | 59 | $query.= 'NULL'; |
---|
[14] | 60 | else |
---|
[33] | 61 | $query.= "'".htmlentities($_POST[$comment],ENT_QUOTES)."'"; |
---|
| 62 | |
---|
| 63 | $query.= ', date_creation = '; |
---|
[14] | 64 | if ( check_date_format( $_POST[$date_creation] ) ) |
---|
[33] | 65 | $query.= "'".date_convert( $_POST[$date_creation] )."'"; |
---|
[14] | 66 | else if ( $_POST[$date_creation] == '' ) |
---|
[33] | 67 | $query.= 'NULL'; |
---|
| 68 | |
---|
| 69 | $query.= ', keywords = '; |
---|
| 70 | $keywords_array = get_keywords( $_POST[$keywords] ); |
---|
| 71 | if ( count( $keywords_array ) == 0 ) |
---|
| 72 | $query.= 'NULL'; |
---|
| 73 | else |
---|
[14] | 74 | { |
---|
[61] | 75 | $query.= "'"; |
---|
[33] | 76 | foreach ( $keywords_array as $i => $keyword ) { |
---|
| 77 | if ( $i > 0 ) $query.= ','; |
---|
| 78 | $query.= $keyword; |
---|
| 79 | } |
---|
[61] | 80 | $query.= "'"; |
---|
[14] | 81 | } |
---|
[33] | 82 | |
---|
[14] | 83 | $query.= ' WHERE id = '.$row['id']; |
---|
| 84 | $query.= ';'; |
---|
| 85 | mysql_query( $query ); |
---|
| 86 | } |
---|
[61] | 87 | // add link to another category |
---|
| 88 | if ( $_POST['check-'.$row['id']] == 1 ) |
---|
| 89 | { |
---|
| 90 | $query = 'INSERT INTO '.PREFIX_TABLE.'image_category'; |
---|
| 91 | $query.= ' (image_id,category_id) VALUES'; |
---|
| 92 | $query.= ' ('.$row['id'].','.$_POST['associate'].')'; |
---|
| 93 | $query.= ';'; |
---|
| 94 | mysql_query( $query ); |
---|
| 95 | } |
---|
[14] | 96 | } |
---|
[61] | 97 | update_category( $_POST['associate'] ); |
---|
[14] | 98 | //------------------------------------------------------ update general options |
---|
| 99 | if ( $_POST['use_common_author'] == 1 ) |
---|
| 100 | { |
---|
[61] | 101 | $query = 'SELECT image_id'; |
---|
| 102 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
| 103 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
| 104 | $result = mysql_query( $query ); |
---|
| 105 | while ( $row = mysql_fetch_array( $result ) ) |
---|
[14] | 106 | { |
---|
[61] | 107 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
| 108 | if ( $_POST['author_cat'] == '' ) |
---|
| 109 | { |
---|
| 110 | $query.= ' SET author = NULL'; |
---|
| 111 | } |
---|
| 112 | else |
---|
| 113 | { |
---|
| 114 | $query.= ' SET author = '; |
---|
| 115 | $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES )."'"; |
---|
| 116 | } |
---|
| 117 | $query.= ' WHERE id = '.$row['image_id']; |
---|
| 118 | $query.= ';'; |
---|
| 119 | mysql_query( $query ); |
---|
[14] | 120 | } |
---|
| 121 | } |
---|
| 122 | if ( $_POST['use_common_date_creation'] == 1 ) |
---|
| 123 | { |
---|
| 124 | if ( check_date_format( $_POST['date_creation_cat'] ) ) |
---|
| 125 | { |
---|
| 126 | $date = date_convert( $_POST['date_creation_cat'] ); |
---|
[61] | 127 | $query = 'SELECT image_id'; |
---|
| 128 | $query.= ' FROM '.PREFIX_TABLE.'image_category'; |
---|
| 129 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
| 130 | $result = mysql_query( $query ); |
---|
| 131 | while ( $row = mysql_fetch_array( $result ) ) |
---|
[14] | 132 | { |
---|
[61] | 133 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
| 134 | if ( $_POST['date_creation_cat'] == '' ) |
---|
| 135 | { |
---|
| 136 | $query.= ' SET date_creation = NULL'; |
---|
| 137 | } |
---|
| 138 | else |
---|
| 139 | { |
---|
| 140 | $query.= " SET date_creation = '".$date."'"; |
---|
| 141 | } |
---|
| 142 | $query.= ' WHERE id = '.$row['image_id']; |
---|
| 143 | $query.= ';'; |
---|
| 144 | mysql_query( $query ); |
---|
[14] | 145 | } |
---|
| 146 | } |
---|
| 147 | else |
---|
| 148 | { |
---|
[26] | 149 | echo $lang['err_date']; |
---|
[14] | 150 | } |
---|
| 151 | } |
---|
[40] | 152 | if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '' ) |
---|
[33] | 153 | { |
---|
[40] | 154 | $query = 'SELECT id,keywords'; |
---|
| 155 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
[61] | 156 | $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
| 157 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
[40] | 158 | $query.= ';'; |
---|
| 159 | $result = mysql_query( $query ); |
---|
| 160 | while ( $row = mysql_fetch_array( $result ) ) |
---|
[33] | 161 | { |
---|
[40] | 162 | $specific_keywords = explode( ',', $row['keywords'] ); |
---|
| 163 | $common_keywords = get_keywords( $_POST['keywords_cat'] ); |
---|
| 164 | // first possiblity : adding the given keywords to all the pictures |
---|
| 165 | if ( $_POST['common_keywords'] == 'add' ) |
---|
| 166 | { |
---|
| 167 | $keywords = array_merge( $specific_keywords, $common_keywords ); |
---|
| 168 | $keywords = array_unique( $keywords ); |
---|
[33] | 169 | } |
---|
[40] | 170 | // second possiblity : removing the given keywords from all pictures |
---|
| 171 | // (without deleting the other specific keywords |
---|
| 172 | if ( $_POST['common_keywords'] == 'remove' ) |
---|
| 173 | { |
---|
| 174 | $keywords = array_diff( $specific_keywords, $common_keywords ); |
---|
| 175 | } |
---|
| 176 | // cleaning the keywords array, sometimes, an empty value still remain |
---|
| 177 | $keywords = array_remove( $keywords, '' ); |
---|
| 178 | // updating the picture with new keywords array |
---|
| 179 | $query = 'UPDATE '.PREFIX_TABLE.'images'; |
---|
| 180 | $query.= ' SET keywords = '; |
---|
| 181 | if ( count( $keywords ) == 0 ) |
---|
| 182 | { |
---|
| 183 | $query.= 'NULL'; |
---|
| 184 | } |
---|
| 185 | else |
---|
| 186 | { |
---|
| 187 | $query.= '"'; |
---|
| 188 | $i = 0; |
---|
| 189 | foreach ( $keywords as $keyword ) { |
---|
| 190 | if ( $i++ > 0 ) $query.= ','; |
---|
| 191 | $query.= $keyword; |
---|
| 192 | } |
---|
| 193 | $query.= '"'; |
---|
| 194 | } |
---|
| 195 | $query.= ' WHERE id = '.$row['id']; |
---|
| 196 | $query.= ';'; |
---|
| 197 | mysql_query( $query ); |
---|
[33] | 198 | } |
---|
| 199 | } |
---|
[14] | 200 | //--------------------------------------------------------- form initialization |
---|
| 201 | $page['nb_image_page'] = 5; |
---|
| 202 | |
---|
| 203 | if( !isset( $_GET['start'] ) |
---|
| 204 | or !is_numeric( $_GET['start'] ) |
---|
| 205 | or ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) |
---|
| 206 | { |
---|
| 207 | $page['start'] = 0; |
---|
| 208 | } |
---|
| 209 | else |
---|
| 210 | { |
---|
| 211 | $page['start'] = $_GET['start']; |
---|
| 212 | } |
---|
| 213 | |
---|
| 214 | if ( is_numeric( $_GET['num'] ) and $_GET['num'] >= 0 ) |
---|
| 215 | { |
---|
[15] | 216 | $page['start'] = |
---|
| 217 | floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page']; |
---|
[14] | 218 | } |
---|
| 219 | // retrieving category information |
---|
[61] | 220 | $page['plain_structure'] = get_plain_structure(); |
---|
[14] | 221 | $result = get_cat_info( $page['cat'] ); |
---|
| 222 | $cat['name'] = $result['name']; |
---|
| 223 | $cat['nb_images'] = $result['nb_images']; |
---|
| 224 | //----------------------------------------------------- template initialization |
---|
| 225 | $sub = $vtp->Open('../template/'.$user['template'].'/admin/infos_image.vtp'); |
---|
| 226 | $tpl = array( 'infoimage_general','author','infoimage_useforall','submit', |
---|
| 227 | 'infoimage_creation_date','infoimage_detailed','thumbnail', |
---|
| 228 | 'infoimage_title','infoimage_comment', |
---|
[48] | 229 | 'infoimage_creation_date','keywords', |
---|
[40] | 230 | 'infoimage_addtoall','infoimage_removefromall', |
---|
[61] | 231 | 'infoimage_keyword_separation','infoimage_associate' ); |
---|
[14] | 232 | templatize_array( $tpl, 'lang', $sub ); |
---|
[61] | 233 | $vtp->setGlobalVar( $sub, 'user_template', $user['template'] ); |
---|
[14] | 234 | //------------------------------------------------------------------------ form |
---|
| 235 | $url = './admin.php?page=infos_images&cat_id='.$page['cat']; |
---|
| 236 | $url.= '&start='.$page['start']; |
---|
| 237 | $vtp->setVar( $sub, 'form_action', add_session_id( $url ) ); |
---|
| 238 | $page['navigation_bar'] = create_navigation_bar( |
---|
| 239 | $url, $cat['nb_images'],$page['start'], $page['nb_image_page'], '' ); |
---|
| 240 | $vtp->setVar( $sub, 'navigation_bar', $page['navigation_bar'] ); |
---|
| 241 | $cat_name = get_cat_display_name( $cat['name'], ' - ', 'font-style:italic;'); |
---|
| 242 | $vtp->setVar( $sub, 'cat_name', $cat_name ); |
---|
| 243 | |
---|
[61] | 244 | $array_cat_directories = array(); |
---|
| 245 | |
---|
[33] | 246 | $query = 'SELECT id,file,comment,author,tn_ext,name,date_creation,keywords'; |
---|
[61] | 247 | $query.= ',storage_category_id,category_id'; |
---|
[14] | 248 | $query.= ' FROM '.PREFIX_TABLE.'images'; |
---|
[61] | 249 | $query.= ' LEFT JOIN '.PREFIX_TABLE.'image_category ON id = image_id'; |
---|
| 250 | $query.= ' WHERE category_id = '.$page['cat']; |
---|
[14] | 251 | $query.= $conf['order_by']; |
---|
| 252 | $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page']; |
---|
| 253 | $query.= ';'; |
---|
| 254 | $result = mysql_query( $query ); |
---|
| 255 | while ( $row = mysql_fetch_array( $result ) ) |
---|
| 256 | { |
---|
| 257 | $vtp->addSession( $sub, 'picture' ); |
---|
| 258 | $vtp->setVar( $sub, 'picture.id', $row['id'] ); |
---|
| 259 | $vtp->setVar( $sub, 'picture.filename', $row['file'] ); |
---|
| 260 | $vtp->setVar( $sub, 'picture.name', $row['name'] ); |
---|
| 261 | $vtp->setVar( $sub, 'picture.author', $row['author'] ); |
---|
| 262 | $vtp->setVar( $sub, 'picture.comment', $row['comment'] ); |
---|
[33] | 263 | $vtp->setVar( $sub, 'picture.keywords', $row['keywords'] ); |
---|
[14] | 264 | $vtp->setVar( $sub, 'picture.date_creation', |
---|
| 265 | date_convert_back( $row['date_creation'] ) ); |
---|
| 266 | $file = get_filename_wo_extension( $row['file'] ); |
---|
| 267 | $vtp->setVar( $sub, 'picture.default_name', $file ); |
---|
| 268 | // creating url to thumbnail |
---|
[61] | 269 | if ( $array_cat_directories[$row['storage_category_id']] == '' ) |
---|
| 270 | { |
---|
| 271 | $array_cat_directories[$row['storage_category_id']] = |
---|
| 272 | get_complete_dir( $row['storage_category_id'] ); |
---|
[14] | 273 | } |
---|
[61] | 274 | $thumbnail_url = $array_cat_directories[$row['storage_category_id']]; |
---|
| 275 | if ( preg_match( '/^\.\/galleries/', $thumbnail_url ) ) |
---|
[14] | 276 | { |
---|
[61] | 277 | $thumbnail_url = '.'.$thumbnail_url; |
---|
[14] | 278 | } |
---|
| 279 | $thumbnail_url.= 'thumbnail/'; |
---|
[19] | 280 | $thumbnail_url.= $conf['prefix_thumbnail'].$file.".".$row['tn_ext']; |
---|
[14] | 281 | $vtp->setVar( $sub, 'picture.thumbnail_url', $thumbnail_url ); |
---|
[26] | 282 | $url = '../picture.php?cat='.$_GET['cat_id'].'&image_id='.$row['id']; |
---|
| 283 | $vtp->setVar( $sub, 'picture.url', add_session_id( $url ) ); |
---|
[14] | 284 | $vtp->closeSession( $sub, 'picture' ); |
---|
| 285 | } |
---|
[61] | 286 | $structure = create_structure( '', array() ); |
---|
| 287 | display_categories( $structure, ' ' ); |
---|
[14] | 288 | } |
---|
| 289 | //----------------------------------------------------------- sending html code |
---|
| 290 | $vtp->Parse( $handle , 'sub', $sub ); |
---|
[2] | 291 | ?> |
---|