<?php

	include "library.php";

	$cxn = start_code( true );

	$cxn_common = db_common_login();



		/* get parameters */

	$requesting_id = val( $_GET, "requestingid" );

//	$conversation_id = val( $_GET, "conversationid" );


		/* check them */

	crash_if_missing( $requesting_id, "requesting_id missing in chat_request", $cxn );

//	crash_if_missing( $conversation_id, "conversation_id missing in chat_request", $cxn );

	$id = val( $_SESSION, "id" );
		
	if ($id != "")
	{
		$query = "SELECT * FROM active_chats WHERE responder_id = ".$id;

		if (query_has_rows( $query, $cxn ))
		{
			$result = run_query( $query, $cxn );
		
			$data = get_row( $result );		

			$conversation_id = $data['id'];
		}
		else
		{
			echo black( "This member is no longer online.<br><br>" );
			
			echo show_home_link();
			
			exit();
		}
	}


	page_header( "Chat Request", $cxn, $cxn_common );

	$query = "SELECT handle, sex FROM profile WHERE id = ".$requesting_id;

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

	$data = get_row( $result );

	$handle = $data['handle'];
	$sex = $data['sex'];
	
	echo black( "You have received a chat request from member ".red( $handle )."<br><br>" );

	if ($sex == "Male")
	{
		echo black( "To respond to this request please go to his profile by clicking the link below.<br><br>" );
		echo black( "If you would like to chat with him please click the 'Accept Chat' button on his profile.<br><br><br>" );
	}
	else
	{
		echo black( "To respond to this request please go to her profile by clicking the link below.<br><br>" );
		echo black( "If you would like to chat with her please click the 'Accept Chat' button on her profile.<br><br><br>" );
	}

	echo show_link( "View Profile", "display_profile.php", "showid", $requesting_id, "returnpoint", "main", "conversationid", $conversation_id );


?>