<?php
// include database and object files
include_once '../config/init.php';	// contains $db
include_once '../objects/db_user.php';
include_once '../config/error.php';

// set user property values
$user = new User($db);

// ensure username is passed in $_POST parameters
if (isset($_POST['username']))
	$user->username = $_POST['username'];
else trigger_error( missing_parameter_error("username") );

// read other $_POST parameters
$user->password = base64_encode($_POST['password']);
$user->created = date('Y-m-d H:i:s');
$user->lastConnection = date('Y-m-d H:i:s');

// create the user
if ($user->signup())
{
	// once signed up, read info from DB to retrieve default values for all fields
	//$user->load();	// automatically called in $user->signup()
	$user_arr = $user->getResultArray(true, "Signup_OK");
	print_r(json_encode($user_arr));	// OK
}
else trigger_error("Username_Already_Exists");
?>