<?php
// required headers
header("Access-Control-Allow-Origin: *");
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");
  
// include database and object files
include_once '../config/database.php';
include_once '../objects/identite.php';
  
// get database connection
$database = new Database();
$db = $database->getConnection();
  
// prepare product object
$identite = new Identite($db);
  
// get id of product to be edited
$data = json_decode(file_get_contents("php://input"));
  
// set ID property of product to be edited
$identite->id = $data->id;
  
// set product property values
$identite->login = $data->login;
$identite->password = $data->password;
$identite->pseudo = $data->pseudo;
$identite->age = $data->age;
$identite->poids = $data->poids;
$identite->taille = $data->taille;
$identite->sexe = $data->sexe;
$identite->niveaudusport = $data->niveaudusport;
  
// update the product
if($identite->update()){
  
    // set response code - 200 ok
    http_response_code(200);
  
    // tell the user
    echo json_encode(array("message" => "Les modifications ont été prises en compte."));
}
  
// if unable to update the product, tell the user
else{
  
    // set response code - 503 service unavailable
    http_response_code(503);
  
    // tell the user
    echo json_encode(array("message" => "Impossible de mettre à jour"));
}
?>
