<?php

	include "library.php";

	$cxn = start_code();
	
    exit_if_search_bot();


			/* get variables */

	$show_id = val( $_GET, "showid" );

    if ($show_id == "")
    	$show_id = val( $_SESSION, "display_profile_show_id" );


	    // expired session

	if ($show_id == "")
	    exit_if_session_expired( $cxn );

        
        // don't do this until after the 'exit_if_...' as it resets the session-active flag
        
    process_external_entry_point( $cxn );
	    

	$returnpoint = val( $_GET, "returnpoint" );
	
	$startpos = val( $_GET, "startpos" );

	$external = val( $_GET, "external" );

	$stats_screen = val( $_GET, "stats_screen" );


    if ($returnpoint == "")
    	$returnpoint = val( $_SESSION, "display_profile_returnpoint" );

    if ($startpos == "")
    	$startpos = val( $_SESSION, "display_profile_startpos" );

    if ($external == "")
    	$external = val( $_SESSION, "display_profile_external" );

    if ($stats_screen == "")
    	$stats_screen = val( $_SESSION, "display_profile_stats_screen" );


	log_page_view( $cxn );

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


    if ($returnpoint == "")
        $returnpoint = "main";


//	if ($external != "true" && $jobseeker_id == "" && $stats_screen != "true")
//	{
//		$_SESSION['nextpage'] = url_encode( "display_jobseeker_profile.php", "showid", $show_id, "returnpoint", $returnpoint, "startpos", $startpos );
//	
//	    jump_to_page( "jobseeker_login.php" );		/* must happen before print output */
//
//		exit();
//	}

		/* view own profile  */

	if ($show_id == -1)
		$show_id = $jobseeker_id;

	$_SESSION['returnpoint'] = $returnpoint;
	$_SESSION['startpos'] = $startpos;



		/* start the page */

	page_header( "Advertiser Profile", $cxn, true );


		/* check parameters */


	crash_if_missing( $show_id, "show_id missing in display_profile", $cxn );
    	

//	crash_if_missing( $returnpoint, "return point missing in display_profile", $cxn );

	if ($returnpoint == "")		
		$returnpoint = "main";


    show_return_point( $returnpoint, $startpos, $show_id );
    
    echo "<br><br>";
    

	$query = "SELECT * FROM advertiser_profile WHERE id = ".$show_id;

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

	if (query_num_rows($result) == 0)
	{
		crash( "Internal error: id not found", $cxn );
	}
	else
	{
		$data = get_row( $result );

		if ($data['deleted'] == 'yes')
		{
			echo black( "This advertiser's profile has been deleted from the system." );
			exit();
		}

		$username = $data['username'];
		$organisation_name = $data['organisation_name'];
		$advertiser_profile = $data['advertiser_profile'];
		$contact_name = $data['first_name']." ".$data['surname_name'];
		$city = $data['city'];
		$state = $data['state'];
		$postcode = $data['postcode'];



		echo "<table width='100%'>";

		echo "<tr><td width='55%'>";


			// show the first line of the screen which has the photos and the skyscraper ads
			
		show_skyscraper_ads( $cxn );

		echo "<tr>";



		if (! low_res_screen())		
			echo "<td width='55%' valign='top'>";
		else
			echo "<td width='95%' colspan=3>";


		if (low_res_screen())
		{
			echo "</table><table width='100%'>";
		}
		
		
		write_profile_items( $username, $organisation_name, $advertiser_profile, $contact_name, $city, $state, $postcode, $cxn );

		
		echo "<br>";


		if (! low_res_screen())
		{
		    echo "<br>";
		    echo "<br>";
		    echo "<br>";
		    echo "<br>";
		    echo "<br>";
		    echo "<br>";
		    echo "<br>";
			
			show_ads_large_banner_arj();

		    echo "<br>";		
		    echo "<br>";		
		    echo "<br>";		
		    echo "<br>";		
		    echo "<br>";		
		    echo "<br>";		
		    echo "<br>";		
		    echo "<br>";		
		    echo "<br>";		
		}
		else
		    echo "<br>";		

		echo "</td>";


		echo "<td valign='top' align='center'>";
		
		
			// buttons
		
		if (! low_res_screen())
			write_buttons( $id, $show_id, $kiss_reply, $conversation_id, $stats_screen, $cxn );
		

		echo "</td></tr></table>";		
		

//		if (! low_res_screen())
//		{
//			echo "<br><br>";
//			show_ads( $cxn );
//		}
//		else
		
		if (low_res_screen())		
		{
			echo "";
			
//			show_ads_narrow_banner();			
		
		    echo "<table width='100%'><tr><td align='center'>";
		    
			show_ads_large_square();
			
			echo "</td></td></table>";
		}
			
		echo "<br><br><br><br><br>";	// blank space at the bottom of the page so ad is not squashed against the bottom border

	}
	
	
	
		//*****************************************
		//
		// Start of functions
		//
		//*****************************************
		
		
	function write_buttons( $id, $show_id, $show_reply_to_kiss, $conversation_id, $stats_screen, $cxn )
	{
	
		echo "<br>";
		
		if (! low_res_screen())
			$button_width = 130;
		else
			$button_width = 115;
			
			
		echo "<br><br>";


			// send email
			
		show_green_button( "Send Email", $button_width, "send_advertiser_message.php", "sendtoid", $show_id );
			

		echo "<br><br>";


			// remember

//			show_green_button( "Remember", $button_width, "add_to_remembered.php", "rememberedid", $show_id );


		echo "<br><br>";
	}
	


		// write the main profile data in the inner table
		
	function write_profile_items( $username, $organisation_name, $advertiser_profile, $contact_name, $city, $state, $postcode, $cxn )
	{
	
		if (! low_res_screen())
			echo "<br>";
		
	
		if (! low_res_screen())		
			echo "<table cellspacing='4' style='border: 1px solid #bbbbbb; border-radius: 10px; background: ".table_background."; '>";
		else
			echo "<table width='100%' cellspacing='4' style='border: 1px solid #bbbbbb; background: #fcfcfc;'>";


		if (! low_res_screen())
			echo "<tr><td width='14%'></td><td width='40%'></td>";		
		else
			echo "<tr><td width='40%'></td><td width='60%'></td>";

		echo "</td></tr>";

//        if ($days_since_login <= 7)
//            $days_since_login_text = "Within the last week";
//        else
//        if ($days_since_login <= 56)
//        {
//            if (round($days_since_login / 7) == 1)
//                $days_since_login_text = "1 week ago";
//            else
//                $days_since_login_text = round($days_since_login / 7)." weeks ago";
//        }
//        else
//        if ($days_since_login <= 365)
//            $days_since_login_text = round($days_since_login / 31)." months ago";
//        else
//            $days_since_login_text = "More than 12 months ago";


		show_field( "Username", $username );
		
		show_field( "Organisation Name", $organisation_name );

		show_field( "Advertiser profile", $advertiser_profile );

		show_field( "Contact name", $contact_name );
		
		show_field( "City", $city );
		
		show_field( "State", $state );

		show_field( "Postcode", $postcode );


		echo "</table>";
	}	
	
	
	
		// show the first line of the screen which has the photos and the skyscraper ads
		
	function show_skyscraper_ads( $cxn )
	{
		echo "</td>";

		if (! low_res_screen())
		{
			echo "<br>";
			
			echo "</td><td width='20%'></td><td width='200px' valign='top' align='center' rowspan=3>";
			
			show_ads_medium_skyscraper_arj();

//            show_ads_wide_skyscraper();

			echo "</td></tr>";		
		}
		else
		{
			echo "</td><td width='20%'></td><td width='200px' valign='top' align='center' rowspan=3>";
					
			write_buttons( $id, $show_id, $show_reply_to_kiss, $conversation_id, $stats_screen, $cxn );
			
			echo "</td></tr>";		
		}
	}	



    echo "</body>";
	
    echo "</html>";

?>