<?php
$DB_DATABASE = "";
$prefix = "iitech_";
if(isset($_POST['database'])){
	$DB_DATABASE = $prefix.$_POST['database'];
}

// include db connect class
require_once __DIR__ . '/include/new_db_connect.php';

$DB_DATABASE = "iitech_firebase";

// connecting to db
$bdd = connect($DB_DATABASE);

require_once __DIR__ . '/include/user.php';

$matricule = "";
$tokenId  = "";
$idFiliere = "";
$idEtablissement = "";
$niveau = "";
$annee = "";

if(isset($_POST['matricule'])){
	$matricule = $_POST['matricule'];
}
if(isset($_POST['token'])){
	$token = $_POST['token'];
}


if(isset($_POST['niveau'])){
	$niveau = $_POST['niveau'];
}

if(isset($_POST['annee'])){
	$annee = $_POST['annee'];
}

if(isset($_POST['idFiliere'])){
	$idFiliere = $_POST['idFiliere'];
}

if(isset($_POST['idEtablissement'])){
	$idEtablissement = $_POST['idEtablissement'];
}

// Instance of a User class
$tokenObject = new User();

// Registration of new user
if( !empty($matricule) && !empty($token) ) {

	$json_token = $tokenObject->updateTokenInfoNew($token, $matricule, $idFiliere, $idEtablissement, $annee, $niveau, $bdd);
	
	echo json_encode($json_token);
}
?>