<?php
session_start();

if (isset($_SESSION["user_id"]) and isset($_SESSION["password"])) {
	$dbhost=$_SESSION["dbhost"];
	$dbuser=$_SESSION["dbuser"];
	$dbpass=$_SESSION["dbpass"];
	
	$id=$_SESSION["user_id"];
	header('Content-Type: application/json; charset=utf-8');

	$pdo=new PDO($dbhost, $dbuser, $dbpass);
	$stmt = $pdo->prepare("SELECT * FROM transfer WHERE receiver_id=:id");
	$stmt->execute(array(':id' => $id));
	$rows = $stmt->fetchAll(pdo::FETCH_ASSOC);
	$stuff = array();
	foreach ($rows as $row) {
		$stuff[] = array(
			"transfer_id" => $row["transfer_id"],
			"sender_id" => $row["sender_id"],
			"sender_name" => $row["sender_name"],
			"sender_fullname" => $row["sender_fullname"],
			"sender_public_key" => $row["sender_public_key"],
			"file_path" => $row["file_path"],
			"file_name" => $row["file_name"],
			"transfer_time" => $row["transfer_time"],
		);
	}
	$extract = array("objectz" => $stuff);
	echo(json_encode($extract, JSON_PRETTY_PRINT));
}
?>