<?php

	include "library.php";

	$cxn = start_code();
	
	$cxn_common = db_common_login();



			/* get variables */

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


			/* start page */

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


		/* check parameters */

	crash_if_missing( $id, "id missing in remove_from_inbox", $cxn );


		/* search each message */

	$query = "SELECT id as message_id FROM message WHERE receiver_id = ".$id." AND show_in_inbox = 'yes'";

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

	$count = 0;

	for ($i=0; $i < query_num_rows($result); $i++)
	{
		$data = get_row( $result );

		if (val( $_POST, "id".$data['message_id'] ) == "on")
		{
			run_query( "UPDATE message SET show_in_inbox = 'no' WHERE id = ".$data['message_id'], $cxn );
			$count++;
		}
	}

	if ($count == 0)
		echo black( "No messages were selected<br><br>" );
	else
	if ($count == 1)
		echo black( "Message removed<br><br>" );
	else
		echo black( "Messages removed<br><br>" );

	echo show_link( "Return", "mailboxes.php", "box", "inbox" );

?>