<?php

	include "library.php";

	include forms_library;

	include ad_forms_library;


	$cxn = start_code();

    exit_if_search_bot();

    exit_if_session_expired( $cxn );


	
			/* get variables */

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

	$send_to_id = val( $_GET, "sendtoid" );

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

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

	
		/* if the user is not logged in log them in then back to here */

	if ($jobseeker_id == "")
	{
		$_SESSION['nextpage'] = url_encode( "send_advertiser_message.php", "sendtoid", $send_to_id );

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

		exit();
	}

		/* check id's */


	crash_if_missing( $send_to_id, "Send to id missing in send_message", $cxn );

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


	$ip_address = get_ip_address();	


		/* check visibilty */

	$query = "SELECT * FROM jobseeker_profile WHERE id = ".$jobseeker_id;
	
	$result = run_query( $query, $cxn );

	$data = get_row( $result );

    $sending_email = $data['email_address'];


		/* check for a valid email address */

	if ($data['email_address_valid'] == "no")
	{
		page_header( "", $cxn );
		echo black( "<br>You cannot send messages through the site until your email address" );
    	echo black( " has been verified.<br><br>" );
		echo black( " You must click on the link in the verification email that has arrived in your email inbox. Also check your junk or spam folder.<br><br>" );
		echo black( " Your email address is listed as " );
		echo "<span class='gemail'><b>".$data['email_address']."</span></b><br><br>";
		echo black( " If this is not your correct email address please click on 'Edit My Jobseeker Profile' menu option on the home page and update your email address.<br><br>" );
		echo black( " Please check your inbox or " ).show_link( "click here", "send_jobseeker_verification_email.php", "sendid", $jobseeker_id );
		echo black( " to send the verification email again.<br><br><br>" );

    	show_return_point( $returnpoint, $startpos, $send_to_id );

		echo show_home_link();
		exit();
	}


	if ($data['returned_mail'] == "yes")
	{
		page_header( "", $cxn );
		echo black( "<br>We have received a bounced email indicating that the email address that you have on file in your profile is not valid.<br><br>" );
		echo black( " Please edit your profile from the 'Edit My Jobseeker Profile' menu option on the home page and enter a valid email address that you check regularly.<br><br>" );
		echo black( " Your email address is listed as " );
		echo "<span class='gemail'><b>".$data['email_address']."</span></b><br><br><br>";

		show_return_point( $returnpoint, $startpos, $send_to_id );
		
//		echo show_home_link();
		exit();
	}


	$ip_country = get_ip_country( $cxn );

	$ip_country = str_replace( "'", "", $ip_country );


	page_header( "Send Email", $cxn );

	form_start( "send_advertiser_message_go.php", "send", "yes", "sendtoid", $send_to_id );

	write_yellow_input_boxes();

	if (low_res_screen())
	{
		form_text( "Subject", "subject", 30, "", "true" );

		form_textarea( "Message", "message", 18, 32, "" );

	}
	else
	{
		form_text( "Subject", "subject", 110, "", "true" );

		form_textarea( "Message", "message", 20, 110, "" );
	}

            // prevent sending of bulk emails to members through calling send_message_go.php programmatically
            
    echo "<input type='hidden' name='send_email_system_password' value='1234abcd%^%'>";
    

    if (! low_res_screen())
		echo "<tr><td></td><td align='center'><br><br>";
	else
	    echo "<tr><td align='center'><br>";
	    
	
	show_green_button_submit( "Send", 75 );
	
	echo "</td></tr>";

	form_end();


    echo "<br><br><br><br><br>";


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


?>