<?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
$bdd1 = connect("iitech_universite");


// 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'])){
	$login = $_POST['login'];
}
if(isset($_POST['phone'])){
	$phone = $_POST['phone'];
}
if(isset($_POST['phoneDad'])){
	$phoneDad = $_POST['phoneDad'];
}

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

$query = "select email, 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);
$email		 	= $tab1['email'] ;//adressepersonnelle de l'étudiant
$emailp		 	= $tab1['emailp'] ;//adressepersonnelle du parent

$expediteur   = 'iitech@iitech-benin.net'; // L'email de l'exp&eacute;diteur.

//$message= "Bonjour, <br /><br />GestStudent mobile account reset. <br /><br />Username : $login. <br /><br />Mot de passe : $code.<br /><br />With best and warm regards.";
//$message    = str_replace('<br />', "\n", $message);// message trait&eacute; pour les sauts de ligne
$to         = "$email";// e-mail du destinataire
$to2         = "$emailp";// e-mail du destinataire
$subject   = 'Mise a jour de votre mot de passe GestStudent';
$headers   = 'From: '.$expediteur."\r\n";   // en-tête de l'e-mail
mail($to, $subject, $message, $headers);					
mail($to2, $subject, $message, $headers);					

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