<?php
	include "library.php";

	$cxn = start_code();
	

			/* get variables */

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


//	$newlisting = val( $_GET, "newlisting" );
//	$_SESSION['newlisting'] = $newlisting;


		/* check parameters */

//	crash_if_missing( $newlisting, "newlisting missing in edit_profile", $cxn );

	
		/* if the user is not logged in them direct them to the login page then back to here */

//	if ($newlisting == "false" && $account_id == "")
	if ($account_id == "")
	{
//		$_SESSION['nextpage'] = url_encode( "view_my_listings.php", "newlisting", $newlisting );
		$_SESSION['nextpage'] = url_encode( "view_my_listings.php" );

		jump_to_page( "login.php" );		/* must happen before print output */

		exit();
	}

	page_header( "View My Listings", $cxn );

	$query = "SELECT * from listing WHERE account_id = ".$account_id." AND deleted='no'";

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

	if (query_num_rows($result) == 0)
		echo "You have no active listings on the site at this time.";
	else
	{
		echo "<table><tr><td width='10%'>".black( "ID" )."</td><td width='50%'>".black( "Heading" )."</td><td width='10%'>".black( "Action 1" )."</td><td width='10%'>".black( "Action 2" )."</td><td width='10%'>".black( "Action 3" )."</td></tr>";
		
		$num_rows = 0;

		for ($i=0; $i < query_num_rows($result); $i++)
		{
			$this_row = get_row( $result );
			
			$listing_id = $this_row['id'];
			
			echo "<tr><td>".black( $listing_id )."</td><td>";
			
			echo "<b>".black( show_listing_heading($this_row['id'], $this_row['headline_title'], "view_my_listings.php", 0 ) )."</b></td>";
						
			$url = url_encode( "edit_listing.php", "newlisting", "false", "listing_id", $listing_id );
						
			echo "</td><td>".black( "<a href=".$url.">Edit</a>" )."</td>";
			
			$url = url_encode( "delete_listing.php", "listing_id", $listing_id );
						
			echo "</td><td>".black( "<a href=".$url.">Delete</a>" )."</td>";

			$url = url_encode( "manage_photos.php", "listing_id", $listing_id );
						
			echo "</td><td>".black( "<a href=".$url.">Photos</a>" )."</td>";
						
			echo "</tr>";
		}
		
		echo "</table>";
	}
	
	echo "</table><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>";
	
//	show_ads( $cxn );
	
?>