<?php

function DateFromAge($Age)
{ 	  
  	$year = date("Y");
	$month = date("m");
	$day = date("d");

	return ($year-$Age)."-".$month."-".$day ;
}





include("../config.php3");
include($BIB."bib_generic.php3");
?>
<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Outils de comptable des membres selon les parametres suivants :</div>
<br>


<form>
Min age : <input type="text" name="age_min" value="<? echo $age_min?>">
<br><br>
Max age : <input type="text" name="age_max" value="<? echo $age_max?>">
<br><br>
Sexe : <input type=radio name=sexe value=1>M.<input type=radio name=sexe value=2>F<input type=radio name=sexe value=3>Mlle
<br>  //si non selectionné alors prend tout le monde
<br>
Code Postal : <input type="text" name="zip" value="<? echo $zip?>">
<br><br>
Champ Optin : <input type="text" name="Optin" value="<? echo $Optin?>">
<br>//si pas définit traite tout les non isoff
<br>
<input  type="submit" name="envoyer" value="envoyer">
</form>

<?



if(isset($envoyer))
{
	$an_min = DateFromAge($age_min);
		
	$an_max = DateFromAge($age_max);
	
	$query = "SELECT COUNT(*) AS Total FROM Members LEFT JOIN Players ON Players.MemberId = Members.Id WHERE IsOff=0";
	
	if($Optin)
		$query .= " AND ".$Optin." = 1";
	if($zip)
		$query .= " AND Zip LIKE '".$zip."'";
	if($sexe)
		$query .= " AND Gender = ".$sexe;
	if(!empty($age_min))
		$query .= " AND Birthdate <= '".$an_min."'";
	if(!empty($age_max))
		$query .= " AND Birthdate >= '".$an_max."'";
		
	$row = db_fetch_array(main_db_query($query));
	
	echo $query;
	echo "<b><br>TOTAL >> ".$row["Total"]."</b>";
}