<?php

	include "library.php";

	$cxn = start_code();
	

			/* get variables */

	$listing_id = val( $_SESSION, "listing_id" );

	$photo_number = val( $_GET, "photonumber" );


	page_header( "", $cxn );
	

		/* check the parameters  */

	crash_if_missing( $listing_id, "listing_id is not set in set primary photo", $cxn );

	crash_if_missing( $photo_number, "photo number is not set in set primary photo", $cxn );

		/* get the file extension */

	$query = "UPDATE photos SET primary_photo = 'no' WHERE listing_id = ".$listing_id;

	$result = run_query( $query, $cxn );

	$query = "UPDATE photos SET primary_photo = 'yes' WHERE listing_id = ".$listing_id." AND photo_number = ".$photo_number;

	$result = run_query( $query, $cxn );

	echo black( "Photo successfully set as your primary photo<br><br>" );

	echo show_link( "Return", "manage_photos.php", "listing_id", $listing_id );

?>

