Changeset 570 for trunk/admin/infos_images.php
- Timestamp:
- Oct 23, 2004, 10:58:10 AM (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/admin/infos_images.php
r509 r570 26 26 // +-----------------------------------------------------------------------+ 27 27 28 if( !defined("PHPWG_ROOT_PATH"))28 if(!defined("PHPWG_ROOT_PATH")) 29 29 { 30 30 die ("Hacking attempt!"); 31 31 } 32 include_once( PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php' ); 33 //-------------------------------------------------------------- initialization 34 $page['nb_image_page'] = 5; 35 36 check_cat_id( $_GET['cat_id'] ); 37 32 include_once(PHPWG_ROOT_PATH.'admin/include/isadmin.inc.php'); 33 // +-----------------------------------------------------------------------+ 34 // | initialization | 35 // +-----------------------------------------------------------------------+ 36 check_cat_id($_GET['cat_id']); 38 37 $errors = array(); 39 38 40 if ( isset( $page['cat'] ))39 if (isset($page['cat'])) 41 40 { 42 //--------------------------------------------------- update individual options 43 if ( isset( $_POST['submit'] ) ) 44 { 45 if ( isset( $_POST['associate'] ) and $_POST['associate'] != '' ) 41 // +-----------------------------------------------------------------------+ 42 // | update individual options | 43 // +-----------------------------------------------------------------------+ 44 if (isset($_POST['submit'])) 45 { 46 if (isset($_POST['associate']) and $_POST['associate'] != '') 46 47 { 47 48 // does the uppercat id exists in the database ? 48 if ( !is_numeric( $_POST['associate'] ))49 { 50 array_push( $errors, $lang['cat_unknown_id']);49 if (!is_numeric($_POST['associate'])) 50 { 51 array_push($errors, $lang['cat_unknown_id']); 51 52 } 52 53 else … … 55 56 $query.= ' WHERE id = '.$_POST['associate']; 56 57 $query.= ';'; 57 if ( mysql_num_rows( mysql_query( $query ) ) == 0)58 array_push( $errors, $lang['cat_unknown_id']);58 if (mysql_num_rows(mysql_query($query)) == 0) 59 array_push($errors, $lang['cat_unknown_id']); 59 60 } 60 61 } … … 66 67 $query.= ' WHERE category_id = '.$page['cat']; 67 68 $query.= ';'; 68 $result = mysql_query( $query);69 while ( $row = mysql_fetch_array( $result ))69 $result = mysql_query($query); 70 while ($row = mysql_fetch_array($result)) 70 71 { 71 72 $name = 'name-'.$row['id']; … … 74 75 $date_creation = 'date_creation-'.$row['id']; 75 76 $keywords = 'keywords-'.$row['id']; 76 if ( isset( $_POST[$name] ))77 if (isset($_POST[$name])) 77 78 { 78 79 $query = 'UPDATE '.IMAGES_TABLE.' SET name = '; 79 if ( $_POST[$name] == '')80 $query.= 'NULL'; 81 else 82 $query.= "'".htmlentities( $_POST[$name], ENT_QUOTES)."'";80 if ($_POST[$name] == '') 81 $query.= 'NULL'; 82 else 83 $query.= "'".htmlentities($_POST[$name], ENT_QUOTES)."'"; 83 84 84 85 $query.= ', author = '; 85 if ( $_POST[$author] == '')86 if ($_POST[$author] == '') 86 87 $query.= 'NULL'; 87 88 else … … 89 90 90 91 $query.= ', comment = '; 91 if ( $_POST[$comment] == '')92 if ($_POST[$comment] == '') 92 93 $query.= 'NULL'; 93 94 else … … 95 96 96 97 $query.= ', date_creation = '; 97 if ( check_date_format( $_POST[$date_creation] ))98 $query.= "'".date_convert( $_POST[$date_creation])."'";99 else if ( $_POST[$date_creation] == '')98 if (check_date_format($_POST[$date_creation])) 99 $query.= "'".date_convert($_POST[$date_creation])."'"; 100 else if ($_POST[$date_creation] == '') 100 101 $query.= 'NULL'; 101 102 102 103 $query.= ', keywords = '; 103 104 104 $keywords_array = get_keywords( $_POST[$keywords]);105 if ( count( $keywords_array ) == 0) $query.= 'NULL';106 else $query.= "'".implode( ',', $keywords_array)."'";105 $keywords_array = get_keywords($_POST[$keywords]); 106 if (count($keywords_array) == 0) $query.= 'NULL'; 107 else $query.= "'".implode(',', $keywords_array)."'"; 107 108 108 109 $query.= ' WHERE id = '.$row['id']; 109 110 $query.= ';'; 110 mysql_query( $query);111 mysql_query($query); 111 112 } 112 113 // add link to another category 113 if ( isset( $_POST['check-'.$row['id']] ) and count( $errors ) == 0)114 if (isset($_POST['check-'.$row['id']]) and count($errors) == 0) 114 115 { 115 116 $query = 'INSERT INTO '.IMAGE_CATEGORY_TABLE; … … 117 118 $query.= ' ('.$row['id'].','.$_POST['associate'].')'; 118 119 $query.= ';'; 119 mysql_query( $query);120 mysql_query($query); 120 121 $associate = true; 121 122 } 122 123 } 123 if ( isset( $_POST['associate'] )) update_category( $_POST['associate'] ); 124 if ( $associate ) synchronize_all_users(); 125 //------------------------------------------------------ update general options 126 if ( isset( $_POST['use_common_author'] ) ) 124 if (isset($_POST['associate'])) update_category($_POST['associate']); 125 if ($associate) synchronize_all_users(); 126 // +-----------------------------------------------------------------------+ 127 // | update general options | 128 // +-----------------------------------------------------------------------+ 129 if (isset($_POST['use_common_author'])) 127 130 { 128 131 $query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE; 129 132 $query.= ' WHERE category_id = '.$page['cat']; 130 $result = mysql_query( $query);131 while ( $row = mysql_fetch_array( $result ))133 $result = mysql_query($query); 134 while ($row = mysql_fetch_array($result)) 132 135 { 133 136 $query = 'UPDATE '.IMAGES_TABLE; 134 if ( $_POST['author_cat'] == '')137 if ($_POST['author_cat'] == '') 135 138 { 136 139 $query.= ' SET author = NULL'; … … 139 142 { 140 143 $query.= ' SET author = '; 141 $query.= "'".htmlentities( $_POST['author_cat'], ENT_QUOTES)."'";144 $query.= "'".htmlentities($_POST['author_cat'], ENT_QUOTES)."'"; 142 145 } 143 146 $query.= ' WHERE id = '.$row['image_id']; 144 147 $query.= ';'; 145 mysql_query( $query);146 } 147 } 148 if ( isset( $_POST['use_common_date_creation'] ))149 { 150 if ( check_date_format( $_POST['date_creation_cat'] ))151 { 152 $date = date_convert( $_POST['date_creation_cat']);148 mysql_query($query); 149 } 150 } 151 if (isset($_POST['use_common_date_creation'])) 152 { 153 if (check_date_format($_POST['date_creation_cat'])) 154 { 155 $date = date_convert($_POST['date_creation_cat']); 153 156 $query = 'SELECT image_id FROM '.IMAGE_CATEGORY_TABLE; 154 157 $query.= ' WHERE category_id = '.$page['cat']; 155 $result = mysql_query( $query);156 while ( $row = mysql_fetch_array( $result ))158 $result = mysql_query($query); 159 while ($row = mysql_fetch_array($result)) 157 160 { 158 161 $query = 'UPDATE '.IMAGES_TABLE; 159 if ( $_POST['date_creation_cat'] == '')162 if ($_POST['date_creation_cat'] == '') 160 163 { 161 164 $query.= ' SET date_creation = NULL'; … … 167 170 $query.= ' WHERE id = '.$row['image_id']; 168 171 $query.= ';'; 169 mysql_query( $query);172 mysql_query($query); 170 173 } 171 174 } 172 175 else 173 176 { 174 array_push( $errors, $lang['err_date']);175 } 176 } 177 if ( isset( $_POST['common_keywords'] ) and $_POST['keywords_cat'] != '')177 array_push($errors, $lang['err_date']); 178 } 179 } 180 if (isset($_POST['common_keywords']) and $_POST['keywords_cat'] != '') 178 181 { 179 182 $query = 'SELECT id,keywords FROM '.IMAGES_TABLE; … … 181 184 $query.= ' WHERE category_id = '.$page['cat']; 182 185 $query.= ';'; 183 $result = mysql_query( $query);184 while ( $row = mysql_fetch_array( $result ))185 { 186 if ( !isset( $row['keywords'] )) $specific_keywords = array();187 else $specific_keywords = explode( ',', $row['keywords']);186 $result = mysql_query($query); 187 while ($row = mysql_fetch_array($result)) 188 { 189 if (!isset($row['keywords'])) $specific_keywords = array(); 190 else $specific_keywords = explode(',', $row['keywords']); 188 191 189 $common_keywords = get_keywords( $_POST['keywords_cat']);192 $common_keywords = get_keywords($_POST['keywords_cat']); 190 193 // first possiblity : adding the given keywords to all the pictures 191 if ( $_POST['common_keywords'] == 'add')192 { 193 $keywords = array_merge( $specific_keywords, $common_keywords);194 $keywords = array_unique( $keywords);194 if ($_POST['common_keywords'] == 'add') 195 { 196 $keywords = array_merge($specific_keywords, $common_keywords); 197 $keywords = array_unique($keywords); 195 198 } 196 199 // second possiblity : removing the given keywords from all pictures 197 200 // (without deleting the other specific keywords 198 if ( $_POST['common_keywords'] == 'remove')199 { 200 $keywords = array_diff( $specific_keywords, $common_keywords);201 if ($_POST['common_keywords'] == 'remove') 202 { 203 $keywords = array_diff($specific_keywords, $common_keywords); 201 204 } 202 205 // cleaning the keywords array, sometimes, an empty value still remain 203 $keywords = array_remove( $keywords, '');206 $keywords = array_remove($keywords, ''); 204 207 // updating the picture with new keywords array 205 208 $query = 'UPDATE '.IMAGES_TABLE.' SET keywords = '; 206 if ( count( $keywords ) == 0)209 if (count($keywords) == 0) 207 210 { 208 211 $query.= 'NULL'; … … 212 215 $query.= '"'; 213 216 $i = 0; 214 foreach ( $keywords as $keyword) {215 if ( $i++ > 0) $query.= ',';217 foreach ($keywords as $keyword) { 218 if ($i++ > 0) $query.= ','; 216 219 $query.= $keyword; 217 220 } … … 220 223 $query.= ' WHERE id = '.$row['id']; 221 224 $query.= ';'; 222 mysql_query( $query ); 223 } 224 } 225 } 226 //--------------------------------------------------------- form initialization 227 if( !isset( $_GET['start'] ) 228 || !is_numeric( $_GET['start'] ) 229 || ( is_numeric( $_GET['start'] ) and $_GET['start'] < 0 ) ) 225 mysql_query($query); 226 } 227 } 228 } 229 // +-----------------------------------------------------------------------+ 230 // | form initialization | 231 // +-----------------------------------------------------------------------+ 232 if (!isset($_GET['start']) 233 or !is_numeric($_GET['start']) 234 or (is_numeric($_GET['start']) and $_GET['start'] < 0)) 230 235 { 231 236 $page['start'] = 0; … … 236 241 } 237 242 238 if ( isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0)239 { 240 $ page['start'] =241 floor( $_GET['num'] / $page['nb_image_page'] ) * $page['nb_image_page'];243 if (isset($_GET['num']) and is_numeric($_GET['num']) and $_GET['num'] >= 0) 244 { 245 $max = $conf['info_nb_elements_page']; 246 $page['start'] = floor($_GET['num'] / $max) * $max; 242 247 } 243 248 // Navigation path … … 247 252 248 253 $form_action = PHPWG_ROOT_PATH.'admin.php?page=infos_images&cat_id='.$_GET['cat_id']; 249 if( 254 if($page['start']) 250 255 { 251 256 $form_action.= '&start='.$_GET['start']; 252 257 } 253 258 254 $nav_bar = create_navigation_bar( 255 $form_action, $current_category['nb_images'],$page['start'], $page['nb_image_page'], '' ); 256 257 //----------------------------------------------------- template initialization 258 $template->set_filenames( array('infos_images'=>'admin/infos_images.tpl') ); 259 $template->assign_vars(array( 260 'CATEGORY'=>$category_path, 261 'NAV_BAR'=>$nav_bar, 259 $nav_bar = create_navigation_bar($form_action, 260 $current_category['nb_images'], 261 $page['start'], 262 $conf['info_nb_elements_page'], 263 ''); 264 // +-----------------------------------------------------------------------+ 265 // | template initialization | 266 // +-----------------------------------------------------------------------+ 267 $template->set_filenames(array('infos_images'=>'admin/infos_images.tpl')); 268 $template->assign_vars( 269 array( 270 'CATEGORY'=>$category_path, 271 'NAV_BAR'=>$nav_bar, 272 273 'L_INFOS_TITLE'=>$lang['infoimage_general'], 274 'L_AUTHOR'=>$lang['author'], 275 'L_INFOS_OVERALL_USE'=>$lang['infoimage_useforall'], 276 'L_INFOS_CREATION_DATE'=>$lang['infoimage_creation_date'], 277 'L_KEYWORD'=>$lang['keywords'], 278 'L_KEYWORD_SEPARATION'=>$lang['infoimage_keyword_separation'], 279 'L_INFOS_ADDTOALL'=>$lang['infoimage_addtoall'], 280 'L_INFOS_REMOVEFROMALL'=>$lang['infoimage_removefromall'], 281 'L_INFOS_DETAIL'=>$lang['infoimage_detailed'], 282 'L_THUMBNAIL'=>$lang['thumbnail'], 283 'L_INFOS_IMG'=>$lang['infoimage_title'], 284 'L_INFOS_COMMENT'=>$lang['comment'], 285 'L_INFOS_ASSOCIATE'=>$lang['infoimage_associate'], 286 'L_SUBMIT'=>$lang['submit'], 287 288 'F_ACTION'=>add_session_id($form_action) 289 )); 290 // +-----------------------------------------------------------------------+ 291 // | errors display | 292 // +-----------------------------------------------------------------------+ 293 if (count($errors) != 0) 294 { 295 $template->assign_block_vars('errors',array()); 296 foreach ($errors as $error) 297 { 298 $template->assign_block_vars('errors.error',array('ERROR'=>$error)); 299 } 300 } 301 // +-----------------------------------------------------------------------+ 302 // | form | 303 // +-----------------------------------------------------------------------+ 304 $array_cat_directories = array(); 305 306 $pic_mod_base_url = PHPWG_ROOT_PATH.'admin.php'; 307 $pic_mod_base_url = '?page=picture_modify&image_id='; 262 308 263 'L_INFOS_TITLE'=>$lang['infoimage_general'], 264 'L_AUTHOR'=>$lang['author'], 265 'L_INFOS_OVERALL_USE'=>$lang['infoimage_useforall'], 266 'L_INFOS_CREATION_DATE'=>$lang['infoimage_creation_date'], 267 'L_KEYWORD'=>$lang['keywords'], 268 'L_KEYWORD_SEPARATION'=>$lang['infoimage_keyword_separation'], 269 'L_INFOS_ADDTOALL'=>$lang['infoimage_addtoall'], 270 'L_INFOS_REMOVEFROMALL'=>$lang['infoimage_removefromall'], 271 'L_INFOS_DETAIL'=>$lang['infoimage_detailed'], 272 'L_THUMBNAIL'=>$lang['thumbnail'], 273 'L_INFOS_IMG'=>$lang['infoimage_title'], 274 'L_INFOS_COMMENT'=>$lang['comment'], 275 'L_INFOS_ASSOCIATE'=>$lang['infoimage_associate'], 276 'L_SUBMIT'=>$lang['submit'], 277 278 'F_ACTION'=>add_session_id($form_action) 279 )); 280 281 //-------------------------------------------------------------- errors display 282 if ( sizeof( $errors ) != 0 ) 283 { 284 $template->assign_block_vars('errors',array()); 285 for ( $i = 0; $i < sizeof( $errors ); $i++ ) 286 { 287 $template->assign_block_vars('errors.error',array('ERROR'=>$errors[$i])); 288 } 289 } 290 //------------------------------------------------------------------------ form 291 292 $array_cat_directories = array(); 293 294 $query = 'SELECT * FROM '.IMAGES_TABLE; 295 $query.= ' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id'; 296 $query.= ' WHERE category_id = '.$page['cat']; 297 $query.= $conf['order_by']; 298 $query.= ' LIMIT '.$page['start'].','.$page['nb_image_page']; 299 $query.= ';'; 300 $result = mysql_query( $query ); 301 while ( $row = mysql_fetch_array( $result ) ) 302 { 303 if ( !isset( $array_cat_directories[$row['storage_category_id']] ) ) 309 $query = ' 310 SELECT * 311 FROM '.IMAGES_TABLE.' INNER JOIN '.IMAGE_CATEGORY_TABLE.' ON id = image_id 312 WHERE category_id = '.$page['cat'].' 313 '.$conf['order_by'].' 314 LIMIT '.$page['start'].','.$conf['info_nb_elements_page'].' 315 ;'; 316 $result = mysql_query($query); 317 while ($row = mysql_fetch_array($result)) 318 { 319 if (!isset($array_cat_directories[$row['storage_category_id']])) 304 320 { 305 321 $array_cat_directories[$row['storage_category_id']] = 306 get_complete_dir( $row['storage_category_id']);322 get_complete_dir($row['storage_category_id']); 307 323 } 308 324 $thumbnail_url = $array_cat_directories[$row['storage_category_id']]; 309 325 $thumbnail_url.= 'thumbnail/'; 310 $thumbnail_url.= $conf['prefix_thumbnail'].get_filename_wo_extension( $row['file'] ).".".$row['tn_ext']; 311 312 $template->assign_block_vars('picture' ,array( 313 'ID_IMG'=>$row['id'], 314 'URL_IMG'=>add_session_id( PHPWG_ROOT_PATH.'admin.php?page=picture_modify&image_id='.$row['id'] ), 315 'TN_URL_IMG'=>$thumbnail_url, 316 'FILENAME_IMG'=>$row['file'], 317 'DEFAULTNAME_IMG'=>get_filename_wo_extension( $row['file'] ), 318 'NAME_IMG'=>$row['name'], 319 'AUTHOR_IMG'=>$row['author'], 320 'DATE_IMG'=>date_convert_back( $row['date_creation'] ), 321 'KEYWORDS_IMG'=>$row['keywords'], 322 'COMMENT_IMG'=>$row['comment'] 323 )); 326 $thumbnail_url.= $conf['prefix_thumbnail']; 327 $thumbnail_url.= get_filename_wo_extension($row['file']); 328 $thumbnail_url.= '.'.$row['tn_ext']; 329 330 // some fields are nullable in the images table 331 $nullables = array('name','author','keywords','date_creation','comment'); 332 foreach ($nullables as $field) 333 { 334 if (isset($row[$field])) 335 { 336 $$field = $row[$field]; 337 } 338 else 339 { 340 $$field = ''; 341 } 342 } 343 344 $template->assign_block_vars( 345 'picture', 346 array( 347 'ID_IMG'=>$row['id'], 348 'URL_IMG'=>add_session_id($pic_mod_base_url.$row['id']), 349 'TN_URL_IMG'=>$thumbnail_url, 350 'FILENAME_IMG'=>$row['file'], 351 'DEFAULTNAME_IMG'=>get_filename_wo_extension($row['file']), 352 'NAME_IMG'=>$name, 353 'DATE_IMG'=>date_convert_back($date_creation), 354 'AUTHOR_IMG'=>$author, 355 'KEYWORDS_IMG'=>$keywords, 356 'COMMENT_IMG'=>$comment 357 )); 324 358 } 325 359 … … 330 364 $query = 'SELECT COUNT(id) AS nb_total_categories'; 331 365 $query.= ' FROM '.CATEGORIES_TABLE.';'; 332 $row = mysql_fetch_array( mysql_query( $query ));333 if ( $row['nb_total_categories'] < $conf['max_LOV_categories'])334 { 335 /*$vtp->addSession( $sub, 'associate_LOV');336 $page['plain_structure'] = get_plain_structure( true);337 $structure = create_structure( '', array());338 display_categories( $structure, ' ');339 $vtp->closeSession( $sub, 'associate_LOV');*/366 $row = mysql_fetch_array(mysql_query($query)); 367 if ($row['nb_total_categories'] < $conf['max_LOV_categories']) 368 { 369 /*$vtp->addSession($sub, 'associate_LOV'); 370 $page['plain_structure'] = get_plain_structure(true); 371 $structure = create_structure('', array()); 372 display_categories($structure, ' '); 373 $vtp->closeSession($sub, 'associate_LOV');*/ 340 374 } 341 375 // else, we only display a small text field, we suppose the administrator … … 343 377 else 344 378 { 345 //$vtp->addSession( $sub, 'associate_text');346 //$vtp->closeSession( $sub, 'associate_text');379 //$vtp->addSession($sub, 'associate_text'); 380 //$vtp->closeSession($sub, 'associate_text'); 347 381 } 348 382 }
Note: See TracChangeset
for help on using the changeset viewer.