<?php
$COULEUR_FONT1 = "#000000";
$COULEUR_FOND1 = "#EFEFEF";
$COULEUR_FOND4 = "#FFFFFF";

function build_all_winners($Start,$Stop,$f_out,$borderColor,$color1,$color2)
{
	global $IMAGES_DIR, $BIB, $BG_COLOR_FOND_1;
	
	include($BIB."bib_tables.php3");
		
	# recup toutes les sessions existantes dans la tranche de date donnée
	$winnersSessions = main_db_query("SELECT Session FROM Winners WHERE Date>'".$Start."' AND Date<'".$Stop."' AND Session!='' GROUP BY Session ORDER BY Date DESC");

	ob_start();
	
	while($winnersSession = db_fetch_array($winnersSessions))
	{
		table_ktf_up( $winnersSession["Session"], '100%', 'green',1,'','','#FFFFFF' );
	
		/*
		$msg =
		
		"<table width=95% border=0 cellspacing=0 cellpadding=3><tr><td class=whiteBoldTitle colspan=2 align=center><font size=1>".$winnersSession[Session].
		"</font></td></tr></table>".
		"<table width=95% border=0 bordercolor=".$borderColor." cellspacing=0 cellpadding=3>";
		fwrite($f_out,$msg);
		unset($msg);
		*/
		echo "<table width=100% border=0 bordercolor=".$borderColor." cellspacing=0 cellpadding=3>";
		# recup des cadeaux (on factorise par cadeaux)
		$gifts = main_db_query("SELECT Gift FROM Winners WHERE Date>'".$Start."' AND Date<'".$Stop."' AND Session='".addslashes($winnersSession[Session])."' GROUP BY Gift ORDER BY Ordre ASC");

		$i=0;
		while($gift = db_fetch_array($gifts))
		{
			# recup des gagnants de la session
			$winners = main_db_query("SELECT * FROM Winners".
				" LEFT JOIN Players ON Players.Id=Winners.PlayerId".
				" LEFT JOIN Members ON Members.Id=Players.MemberId".
				" WHERE Date>'".$Start."' AND Date<'".$Stop."' AND Session='".addslashes($winnersSession[Session])."' AND Gift='".addslashes($gift[Gift])."' ORDER BY Ordre ASC");

			$color = (++$i % 2 == 0) ? $color1 : $color2;
			//$msg = "<tr><td class=smallboldDark bgcolor=".$color.">";
			echo "<tr><td class=smallboldDark bgcolor=".$color.">";
			
			while($winner = db_fetch_array($winners))
			{
				/*
				$msg.=$winner[NickName].
					" <span class=smallDark> (".
					$winner[FirstName]." ".$winner[Name].",	".$winner[Town].
					")</span><br>\n";
				*/
				echo $winner[NickName].
					" <span class=smallDark> (".
					$winner[FirstName]." ".substr($winner[Name],0,1).".,	".$winner[Town].
					")</span><br>\n";
			}

			//$msg.="</td><td align=center class=smallboldDark bgcolor=".$color.">".$gift[Gift]."</td></tr>";
			echo "</td><td align=center class=smallboldDark bgcolor=".$color.">".$gift[Gift]."</td></tr>";
			
			//fwrite($f_out,$msg);
			//unset($msg);
		}
		
		//$msg = "</table><br>";
		echo "</table><br>";
		table_ktf_down('',1);
		echo "<br>";
		//unset($msg);
	}
	
	fwrite($f_out,ob_get_contents());
	ob_end_clean();

}
