
<?php

// include db connect class

require_once 'include/db_connect2.php';


//fonction permettant de compter le nombre de jours entre deux dates
function nbJours($debut, $fin) {
	//60 secondes X 60 minutes X 24 heures dans une journée
	$nbSecondes= 60*60*24;
	$debut_ts = strtotime($debut);
	$fin_ts   = strtotime($fin);
	$diff     = $fin_ts - $debut_ts;
	return round($diff / $nbSecondes);
} 

$version_number = '';
$ajour          = '';
$depDate        = '';

$version_code = 1;	
try{
	$sql  = 'SELECT * FROM version WHERE version_code = :version_code';
	$statement = $bdd->prepare($sql);
	$statement->bindParam(':version_code', 		$version_code, 		PDO::PARAM_STR);
	$statement->execute();
	$tab=$statement->fetch(PDO::FETCH_ASSOC);
	$version_number = $tab['version_number'];
	$ajour          = $tab['ajour'];
	$depDate        = $tab['depDate'];
}catch(PDOException  $e ){
	echo $e->getMessage( );
}

$t = time();

//Date du premier lancement du logiciel
$dateDepart =  date( "Y-m-d ", $depDate);

$tempsjours = date( "Y-m-d", $t);

$nbJours = nbJours($dateDepart,$tempsjours);

$reste = 30 - $nbJours;

if($reste < 0) $reste = 0;

$tab1 = array('version_number' => "$version_number");
$tab2 = array('ajour' => "$ajour");
$tab3 = array('depDate' => "$reste");

$json['ajourgs'][] = $tab1;
$json['ajourgs'][] = $tab2;
$json['ajourgs'][] = $tab3;

echo json_encode($json); 

?>
