<?php

	include "library.php";

	$cxn = start_code();

    exit_if_search_bot();

    exit_if_session_expired( $cxn );



			/* get variables */

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

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

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


			/* start page */

	page_header( "", $cxn );


		/* check parameters */

	crash_if_missing( $id, "id missing in delete_profile", $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( "<br>Deletion cancelled<br><br><br>" );
	else
	{
			/* delete photos */

		$result = run_query( "SELECT * FROM photos WHERE member_id = ".$id, $cxn );

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

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

		run_query( "DELETE FROM photos WHERE member_id = ".$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 (member_id, event, event_datetime) VALUES (".$id.", 'profile deleted by member', '".date("Y-m-d H:i:s")."')";

		$result = run_query( $query, $cxn );
		
		echo black( "<br>Data deleted successfully<br><br><br>" );
	}

	echo show_home_link();




    echo "</body>";

    echo "</html>";

?>