<?php

	include "library.php";

	$cxn = start_code();


	
			/* get variables */

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

	$newaccount = val( $_GET, "newaccount" );
	
	
	$_SESSION['newaccount'] = $newaccount;
	
			
		/* check parameters */

	crash_if_missing( $newaccount, "newaccount missing in edit_account", $cxn );


	
		/* if the user is not logged in them direct them to the login page then back to here */

	if ($newaccount == "false" && $id == "")
	{
		$_SESSION['nextpage'] = url_encode( "edit_account.php", "newaccount", $newaccount );

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

		exit();
	}



		/* this form edit window operates in three modes - a blank screen for a new
		account, editing retrieved data for editing a account, and editting the previously
		entered data after a validation error
		*/

		/* set the validation error flag  */

	if (val( $_SESSION, 'validation_error' ) == "true")
		$validation_error = "true";
	else
		$validation_error = "false";	/* blank or set to false */

//	$_SESSION['validation_error'] = "false";

	
		/* start the page */


	if ($newaccount == "true")
		page_header( "Create account", $cxn );
	else
		page_header( "Edit account", $cxn );


	initialise_screen_data( $id, $newaccount, "pbfs_account", "account", $validation_error,  $screen_data, $screen_data_error, $cxn );


	if (val( $_SESSION, "validation_errors" ) != "")
		echo red( "<b>Please correct the errors below</b><br><br>".$_SESSION['validation_errors']."<br><br>" );



	form_start( "save_account_go.php" );


	generate_screen_fields_one_pane( $newaccount, "pbfs_account", "false", $screen_data, $screen_data_error, $cxn );
			

	echo "</table><table width='100%'><td width='15%'></td><td width='20%'></td><td width='65%'></td></tr>";


	echo "<tr><td></td><td align='center'><br><br>";
	
	show_green_button_submit( "Save", 80 );
	
	echo "</td></tr>";	

	echo "<tr><td></td><td align='center'><br><br>";


	if ($newaccount == "false")
		show_green_button( "Delete account", 160, "delete_account.php" );		


	echo "</td></tr>";

	form_end();

?>