<?php

	include "library.php";

	$cxn = start_code();

	$cxn_common = db_common_login();


	
			/* get variables */

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

	$newprofile = val( $_GET, "newprofile" );
	
	
	$_SESSION['newprofile'] = $newprofile;
	

		/* check parameters */

	crash_if_missing( $newprofile, "newprofile missing in edit_profile", $cxn );

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

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

	    jump_to_page( val( $_SESSION, "login_page" ) );		/* must happen before print output */

		exit();
	}

	
    if (val( $_SERVER, "HTTPS" ) != "on")
	{
	    jump_to_page( url_encode( "https://chatcity1.net/edit_profile.php", "newprofile", $newprofile ) );		/* must happen before print output */

		exit();
	}
    

		/* this form edit window operates in three modes - a blank screen for a new
		profile, editing retrieved data for editing a profile, 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";


	$on_load = "";
	
		/* start the page */

	page_header( "Your Profile", $cxn, $cxn_common, $on_load );			
	

	initialise_screen_data( $id, $newprofile, "chat_city_profile", "profile", $validation_error,  $screen_data, $screen_data_error, $cxn, $cxn_common );


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



	form_start( "https://chatcity1.net/save_profile_go.php" );

//	form_start( "save_profile_go.php" );


	
	write_yellow_input_boxes();
	

	
//	echo "<form action='".url_encode( "save_all_data_go.php", "formname", $form_name, "tabletitle", $table_title, "newrecord", $newrecord  )."' method='POST'><table>\n";

	generate_screen_fields_one_pane( $newprofile, "chat_city_profile", "false", $screen_data, $screen_data_error, $cxn, $cxn_common );
			

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

	if (! low_res_screen())
		echo "<tr><td></td><td align='center'><br><br>";
	else
		echo "<tr><td colspan='3' align='center'><br><br>";
	
	show_green_button_submit( "Save", 80 );
	
	echo "</td></tr>";	


	if (! low_res_screen())
		echo "<tr><td></td><td align='center'><br><br>";
	else
		echo "<tr><td colspan='3' align='center'><br><br>";

	if ($newprofile == "false")
		show_green_button( "Delete Profile", 135, "delete_profile.php" );		


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

	form_end();

    echo "<br>";
    
?>