<?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 users WHERE name LIKE :name");
	$stmt->execute(array(':name' => '%'.$_POST["name"].'%'));
	$rows = $stmt->fetchAll(pdo::FETCH_ASSOC);
	$stuff = array();
	if (empty($rows)) {
		$stuff[] = array(
			"user_id" => "NO DATA",
			"name" => "NO DATA",
			"fullname" => "NO DATA",
			"email" => "NO DATA",
			"birthday" => "NO DATA",
			"phone" => "NO DATA",
			"address" => "NO DATA",
			"country" => "NO DATA",
			"client_public" => "NO DATA",
		);
	} else {
		foreach ($rows as $row) {
			$stuff[] = array(
				"user_id" => $row["user_id"],
				"name" => $row["name"],
				"fullname" => $row["fullname"],
				"email" => $row["email"],
				"birthday" => $row["birthday"],
				"phone" => $row["phone"],
				"address" => $row["address"],
				"country" => $row["country"],
				"client_public" => $row["client_public"],
			);
		}
	}


	$extract = array("objectz" => $stuff);
	echo(json_encode($extract, JSON_PRETTY_PRINT));
}
?>