<?php
include("../config.php3");
include($BIB."bib_generic.php3");


///SUPPRIME LES MEMBERS SANS PLAYERS

# pas de timeout possible quelle que soit l'action effectuée
set_time_limit($TIME_LIMIT);

# le script continue une fois qu'il est lancé,
# quel que soit l'état de la connection après
ignore_user_abort(true); 


function cleanfield($field)
{
	$order   = array("\r\n", "\n", "\r");
	$replace = " ";
	
	return str_replace($order, $replace, $field);
	
}


?>

<html>
<head></head>
<link rel="stylesheet" href="admin.css">
<body rightmargin=0>
<div align=center class=trTitle>Extraction des Email</div>
<br>

<?php
if(!isset($endtime))
	$endtime = date("Y-m-d H:i:s");
if(!isset($starttime))
	$starttime = "2000-07-25 20:41:50";
?>
<b>1- EXTRACTION PAR DATE D'INSCRIPTION</b>
<form name="" method="post">
	Dates au format : AAAA-mm-jj H:m:s
	<br/>
	Date de début : <input type="text" name="starttime" value="<?php echo $starttime;?>">
	<br/>
	Date de fin : <input type="text" name="endtime" value="<?php echo $endtime;?>">
	<br/>
	Optin Newsletter: <input type="checkbox" name="acceptNews" value="1" <?php if($acceptNews==1) echo "CHECKED";?> />
	<br/>
	Optin Partenaire: <input type="checkbox" name="acceptPartenaires" value="1" <?php if($acceptPartenaires==1) echo "CHECKED";?> />
	<br/>
	<input type="hidden" name="send" value="x"> 
	<input type="submit" name="extraire" value="extraire">
</form>
<?php
if($send)
{
	$NOW = date("Ymd-His",strtotime($starttime))."_to_".date("Ymd-His",strtotime($endtime));
	$count = 0;
	$line = "";

	$addq ="";
	if($acceptPartenaires == 1)
	{
		$addq =" AND acceptPartenaires=1 ";
	}
	if($acceptNews == 1)
	{
		$addq =" AND acceptNews=1 ";
	}
	
	$query_select = "SELECT Email FROM Members WHERE IsOff=0 ".$addq." AND Members.Time BETWEEN '".$starttime."' AND '".$endtime."'  ORDER BY Id ASC";

	$members = main_db_query($query_select);
	
	while($member = db_fetch_assoc($members))
	{
		$line .= $member["Email"]."\n";	
		$count++;
	}


	$filename = "extract-email".$NOW.".csv";
	$fd = fopen($GAME_DIR."Adm/exploitation/".$filename, "w");
	fwrite($fd, $line);
	fclose($fd);

	echo $count." emails extraits : <a href='exploitation/".$filename."' target='_blank'><u>clic-droit enregistrer sous</u></a>";

}
?>

<br/>
<hr/>
<br/>
<?php
if(!isset($endtime))
	$endtime = date("Y-m-d H:i:s");
if(!isset($starttime))
	$starttime = "2008-06-13 12:00:00";
?>
<b>2- EXTRACTION PAR DATE DE DERNIERE ACTIVITE</b>
<form name="" method="post">
	Dates au format : AAAA-mm-jj H:m:s
	<br/>
	Date de début : <input type="text" name="starttime" value="<?php echo $starttime;?>">
	<br/>
	Date de fin : <input type="text" name="endtime" value="<?php echo $endtime;?>">
	<br/>
	Optin Newsletter: <input type="checkbox" name="acceptNews" value="1" <?php if($acceptNews==1) echo "CHECKED";?> />
	<br/>
	Optin Partenaire: <input type="checkbox" name="acceptPartenaires" value="1" <?php if($acceptPartenaires==1) echo "CHECKED";?> />
	<br/>
	<input type="hidden" name="send2" value="x"> 
	<input type="submit" name="extraire" value="extraire">
</form>
<?php
if($send2)
{
	$NOW = date("Ymd-His",strtotime($starttime))."_to_".date("Ymd-His",strtotime($endtime));
	$count = 0;
	$line = "";

	$addq ="";
	if($acceptPartenaires == 1)
	{
		$addq =" AND acceptPartenaires=1 ";
	}
	if($acceptNews == 1)
	{
		$addq =" AND acceptNews=1 ";
	}
	
	$query_select = "SELECT Email FROM Members LEFT JOIN Players ON Players.MemberId=Members.Id WHERE IsOff=0 ".$addq." AND Players.LastConnect BETWEEN '".$starttime."' AND '".$endtime."'  ORDER BY Members.Id ASC";

	$members = main_db_query($query_select);
	
	while($member = db_fetch_assoc($members))
	{
		$line .= $member["Email"]."\n";	
		$count++;
	}


	$filename = "extract-email".$NOW.".csv";
	$fd = fopen($GAME_DIR."Adm/exploitation/".$filename, "w");
	fwrite($fd, $line);
	fclose($fd);

	echo $count." emails extraits : <a href='exploitation/".$filename."' target='_blank'><u>clic-droit enregistrer sous</u></a>";

}
?>

</body>
</html>




