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

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

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

$username = "";
$password = "";
$email = "";
$matricule = "";
$phone  = "";
$phoneDad = "";
$tokenId = "";

if(isset($_POST['message'])){
	$message = $_POST['message'];
}
if(isset($_POST['email'])){
	$email = $_POST['email'];
}
if(isset($_POST['matricule'])){
    $matricule = $_POST['matricule'];
}
if(isset($_POST['phone'])){
	$phone = $_POST['phone'];
}
if(isset($_POST['phoneDad'])){
	$phoneDad = $_POST['phoneDad'];
}

$query = "select emailp  from tabetudiant where matricule = :matricule Limit 1";
$statement = $bdd->prepare($query);
$statement->bindParam(':matricule', $matricule, PDO::PARAM_STR);
$statement->execute();
$tab1=$statement->fetch(PDO::FETCH_ASSOC);
$emailp		 	= $tab1['emailp'] ;//adressepersonnelle du parent

$admin_email = "iitech@iitech-benin.net";
$subject = 'Création de compte GestStudent';
//send email
$retour1 = mail($email, "$subject", $message, "From:" . $admin_email);
$retour2 = mail($emailp, "$subject", $message, "From:" . $admin_email);

if($retour1 && $retour2) {
    $json['success'] = 0;	
    echo json_encode($json);
}else{
    $json['success'] = 1;	
    echo json_encode($json);
}
?>