<?php
// required headers
header("Access-Control-Allow-Origin: http://localhost/rest-api-authentication-example/");
//header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");
 
// files needed to connect to database
include_once '../config/database.php';
include_once '../objects/consultant.php';
 
// get database connection
$database = new Database();
$db = $database->getConnection();
 
// instantiate product object

 
// get posted data
$data = json_decode(file_get_contents("php://input"));

// set product property values
$consultant = new Consultant($db);
$consultant->firstname = $data->firstname;
$consultant->surname = $data->surname;
$consultant->email = $data->email;
$consultant->celnr = $data->celnr;
$consultant->password = $data->password;
$consultant->town = $data->town;
$consultant->province = $data->province;
$consultant->country = $data->country;
$consultant->biography = $data->biography;
$consultant->photo = $data->photo;

//echo $consultant->create();

//$consultant->create()

// create the consultant
if(
    !empty($consultant->firstname) &&
     !empty($consultant->surname) &&
    !empty($consultant->email) &&
    !empty($consultant->password) &&
    $consultant->create()
){
 
    // set response code
    http_response_code(200);
 
    // display message: consultant was created
    echo json_encode(array("message" => "Consultant was created."));
}
 
// message if unable to create consultant
else{
 
    // set response code
    http_response_code(400);
 
    // display message: unable to create user
    echo json_encode(array("message" => "Unable to create Consultant."));
}
?>