<?php

	include "library.php";

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

			/* get variables */

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

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

	$delete = val( $_GET, "delete" );

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


			/* start page */

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


		/* check parameters */

	crash_if_missing( $account_id, "account_id missing in delete_account_go", $cxn );

//	crash_if_missing( $listing_id, "listing_id missing in delete_listing_go", $cxn );

//	crash_if_missing( $delete, "delete missing in delete_profile", $cxn );

//	crash_if_missing( $pathroot, "pathroot missing in delete_profile", $cxn );


	if ($delete == "no")
		echo black( "Deletion cancelled<br><br>" );
	else
	{
			/* delete photos */

//		$result = run_query( "SELECT * FROM listing WHERE listing_id = ".$id, $cxn );

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

//			unlink( $pathroot."/photos/photo_".$id."_".$data['photo_number'].".".$data['file_extension'] );
//			unlink( $pathroot."/photos/photo_".$id."_".$data['photo_number']."_sm.".$data['file_extension'] );
//		}

		run_query( "UPDATE account SET deleted = 'yes' WHERE account_id = ".$account_id, $cxn );
		
//		run_query( "DELETE FROM blocked_list WHERE blocker_id = ".$id, $cxn );
//		run_query( "DELETE FROM blocked_list WHERE blockee_id = ".$id, $cxn );

//		run_query( "DELETE FROM remembered WHERE member_id = ".$id, $cxn );
//		run_query( "DELETE FROM remembered WHERE remembered_id = ".$id, $cxn );

//		run_query( "DELETE FROM message WHERE sender_id = ".$id, $cxn );
//		run_query( "DELETE FROM message WHERE receiver_id = ".$id, $cxn );

//		run_query( "DELETE FROM sys_message WHERE sent_to_id = ".$id, $cxn );

//		$result = run_query( "SELECT handle FROM profile WHERE id = ".$id, $cxn );
//		$data = get_row( $result );
		
//		run_query( "UPDATE profile SET short_intro = '', interests = '', general_comments = '', looking_for = '', deleted = 'yes', locked = 'no' WHERE id = ".$id, $cxn );

//		run_query( "UPDATE profile SET deleted = 'yes' WHERE id = ".$id, $cxn );

//		$_SESSION['id'] = "";

		$query = "INSERT INTO account_activity (account_id, listing_id, event, event_datetime) VALUES (".$account_id.", 0, 'account deleted by member', '".date("Y-m-d H:i:s")."')";

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

		echo black( "Account deleted successfully<br><br>" );
	}

	echo show_home_link();

?>