<?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( "Jobseeker 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 *, year(date_of_birth) as dob_year, dayofyear(date_of_birth) as dob_dayofyear, datediff(current_date(), last_login) as days_since_login FROM jobseeker_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['visibility'] == 'hidden' && $stats_screen == "true")
		{
			echo black( "This member's profile is currently hidden." );
			exit();
		}

		if ($data['visibility'] == 'hidden' &&	$show_id != $id)
		{
			echo black( "This member's profile is currently hidden." );
			exit();
		}

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

		if ($data['locked'] == 'yes')
		{
			echo black( "This member's account is currently locked." );
			exit();
		}

		$first_name = $data['first_name'];
		$username = $data['username'];
		$hours_per_week = $data['hours_per_week'];
		$skills = $data['skills'];
		$comments = $data['comments'];
		$city = $data['city'];
		$state = $data['state'];


		$age = calc_person_age( $data['dob_dayofyear'], $data['dob_year'] );


		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>";


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

		
		if ($color_scheme != 2)		/* black screen background */
		{
			if (! low_res_screen())		
				echo "<td width='55%' valign='top'>";
			else
				echo "<td width='95%' colspan=3>";
		}
		else
		{
			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( $first_name, $username, $hours_per_week, $skills, $comments, $city, $state, $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_jobseeker_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( $first_name, $username, $hours_per_week, $skills, $comments, $city, $state, $cxn )
	{
	
		if (! low_res_screen())
			echo "<br>";
		
	
		if ($color_scheme != 2)		/* black screen background */
		{
			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;'>";
		}
		else
		{
			if (! low_res_screen())		
				echo "<table cellspacing='4' style='border: 1px solid #bbbbbb;'>";
			else
				echo "<table width='100%' cellspacing='4' style='border: 1px solid #bbbbbb;'>";
		}


		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( "Name", $first_name );
		
		show_field( "Hours per week sought", $hours_per_week );
		
		show_field( "Skills and Experience", $skills );
		
		show_field( "Comments", $comments );
		
		show_field( "City", $city );
		
		show_field( "State", $state );


		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>";

?>