<?php

	include "library.php";

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


			/* get variables */

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

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

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


			/* start page */

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


		/* 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( "Deletion cancelled<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( $pathroot."/photos/photo_".$id."_".$data['photo_number'].".".$data['file_extension'] );
			unlink( $pathroot."/photos/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_activity2 (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( "Data deleted successfully<br><br>" );
	}

	echo show_home_link();

?>