<?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 todo WHERE user_id=:id");
	$stmt->execute(array(':id' => $id));
	$rows = $stmt->fetchAll(pdo::FETCH_ASSOC);
	$stuff = array();
	foreach ($rows as $row) {
		$stuff[] = array(
			"todo_id" => $row["todo_id"],
			"todo_title" => $row["todo_title"],
			"todo_desc" => $row["todo_desc"],
			"todo_todo" => $row["todo_todo"],
			"todo_color" => $row["todo_color"],
		);
	}
	$extract = array("objectz" => $stuff);
	echo(json_encode($extract, JSON_PRETTY_PRINT));
}
?>