<?php

	include "library.php";

	$cxn = start_code();

    exit_if_search_bot();

    exit_if_session_expired( $cxn );


			/* get variables */

	$email_id = val( $_GET, "emailid" );


		/* start the page  */

	page_header( "View Email", $cxn, true );


		/* check id */

	crash_if_missing( $email_id, "id blank in view email", $cxn );


		/* view the email */
		
	$query = "SELECT * FROM message WHERE id = ".$email_id;

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

	$data = get_row( $result );


    $query2 = "UPDATE message SET has_been_opened = 'yes' WHERE id = ".$email_id;
    
    $result2 = run_query( $query2, $cxn );
    
    
	echo "<br><br>";

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

	echo "<tr><td width='10%'>&nbsp;</td><td width='50%'>&nbsp</td></tr>";

    $subject = $data['subject'];
    
    if (strpos( $subject, "(" ) !== false)
        $subject = substr( $subject, 0, strpos( $subject, "(" ) );


	show_field( "Subject&nbsp;&nbsp;", $subject, true );

	echo "<tr><td>&nbsp;</td></tr>";
	
	show_field( "Message&nbsp;&nbsp;", $data['message'], true );

	echo "</table>";



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




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


?>