<?php
include($BIB."bib_constants.php3");
include_once($BIB."bib_exploitation.php3");


function getKTabFromRows(&$rows, &$tab1, &$tab2)
{
	while($row = db_fetch_array($rows))
	{
		$tab1[$row['MatchId']] = $row['Bet'];
		$tab2[$row['MatchId']] = $row['Amount'];
	}
}

# fonction de comparaison de 2 nombres
# IN : a et b
# OUT : 0 si a=b, 1 si a>b, 2 si a<b
function cmp_score($a,$b)
{
	if ($a==$b)
		return 0;
	
	if ($a>$b)
		return 1;
	else
		return 2;
}


function calcule_gain_prono($Result,$Bet,$Amount,$rate1,$rate2)
{
	# si on a le meme resultat, score exact, on sort avec rate1
	if ($Result == $Bet)
	{
		return $Amount*$rate1;
	}
	
	# on etudie le result
	$tabResult = explode("-",$Result);
	$ResultType = cmp_score($tabResult[0],$tabResult[1]);

	# on etudie le Bet
	$tabBet = explode("-",$Bet);
	$BetType = cmp_score($tabBet[0],$tabBet[1]);

	# s'il a le gagnant, on sort avec rate2
	# sinon il perd $Amount
	if ($BetType==$ResultType)
		return $Amount*$rate2;
	else
		return $Amount*(-1);
}


function showResultats($query, $ContainerId, $border_color)
{
	global $date, $player, $sess,$BET_PAGE, $IMAGES_DIR, $READ_COMMENT_PAGE;
	global $BG_COLOR_FOND_1, $BG_COLOR_FOND_4, $BG_COLOR_FOND_8, $BG_COLOR_FOND_3, $BG_COLOR_FOND_7, $BG_COLOR_FOND_13, $BG_COLOR_FOND_10;
	global $REDIRECT_PAGE;

	$tour = db_fetch_array(main_db_query ("SELECT * FROM Tours WHERE ShowTime<'".$date."' AND EndTime>'".$date."'"));
	$endSession = false;
	$rowbets = main_db_query($query);
	$nb_paris = 0;
	$monContainer = null;
/*
		echo "<tr >\n";
			echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td class=smallBoldDark colspan=1></td>\n";
			echo "<td class=smallBoldDark colspan=1>Match</td>\n";
			echo "<td class=smallBoldDark colspan=1 align=left>Score</td>\n";
			echo "<td class=smallBoldDark colspan=1>Mon résultat</td>\n";
			echo "<td class=smallBoldDark align=right colspan=1>Points&nbsp;&nbsp;</td>\n";
			echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";
*/
		echo "<tr >\n";
			echo "<td height=1 width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td colspan=5 align=center class=smallDark>";
				print_ligne($border_color, 420);
				echo "<br style=font-size:4px>";
			echo "</td >";
			echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";
		
	while ($bet = db_fetch_array($rowbets))
	{
		$nb_paris++;
			if ($bet[Bet] != "0") 
				 $pari = $bet[Bet];

			if ($bet[Result]!="0")
			{
				$gain = calcule_gain_prono($bet[Result],$bet[Bet],1,$bet[Rate1],$bet[Rate2]);
				$gain_points = calcule_gain_prono($bet[Result],$bet[Bet],$bet[Amount],$bet[Rate1],$bet[Rate2]);
				if ($gain_points > 0)
					$gain_points = "+".$gain_points;
				
				$gain_suffixe = "</font>";
				if ( $gain == $bet[Rate1])
				{
					$gain_points_prefixe = "<font color=".$BG_COLOR_FOND_1."><b>";
					$gain_prefixe = $gain_points_prefixe."Perfect";
					$gain_suffixe = "</b>".$gain_suffixe;
				}
				elseif ($gain == $bet['Rate2'])
				{
					$gain_points_prefixe = "<font color=".$BG_COLOR_FOND_4.">";
					$gain_prefixe = $gain_points_prefixe."Correct";
				}
				else
				{
					$gain_points_prefixe = "<font color="."#FF7777".">";
					$gain_prefixe = $gain_points_prefixe."Echec";
				}

				$gain = $gain_prefixe."&nbsp;(".$pari.")</font>";
				$gain_points = $gain_points_prefixe.$gain_points."</font>";
			}	
			else
			{
				$gain_points_prefixe = "<font color="."#9F9F9F".">";
				$gain_prefixe = $gain_points_prefixe;
				$gain = $gain_prefixe."-".$gain_suffixe;
				$gain_points = $gain_prefixe.$gain_suffixe;
			}

			
			# on détecte la fin d'une session pour bien séparer les résultats
			if (!$endSession)
			{
				if (time_diff($tour['ShowTime'] , $bet["Date"]) < 0)
				{
					# si c'est dès la première ligne, on considère qu'on n'affiche pas
					# le changement de session
					if ($i > 1)
					{
						echo "<tr>";
						echo "<td height=1 width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
						echo "<td colspan=5 class=whiteBoldTitle><font size=1>Fin de Session</font></td></tr>";
						echo "<td height=1 width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
						echo "</tr>";
					}
					$endSession = true;
				}
			}

			$name = "&nbsp;<img src=\"".$IMAGES_DIR.$bet['Image']."\" onMouseover=\"showtip(this,event,'".$bet['Name']."')\" onMouseout=\"hidetip()\">";
			//echo $bet['Image']."x";
			//"<font color=".$font_color.">".$bet[Name]."</font>";
			
		if( $monContainer != $bet[Container] )
		{
			$monContainer = $bet[Container];
			$containeur = "<table class='minibloc' id='green' style='width:180px;'><th id='head1'></th><th id='head2'><span style='color:#f2c000;font-size:10px'>".stripslashes(stripslashes($monContainer))."</span></th><th id='head3'></th></table>";
			echo "			<tr><td><br></td></tr>			<tr>
				<td width=\"1\" bgcolor=\"". $border_color ."\"><img src=\"".$IMAGES_DIR ."Tree/spacer.gif\"></td>
				<td  width=30 class='smallDark' colspan=3>
				$containeur
				</td>
				</tr>";
		}
			
			?> 
			<tr>
				<td width="1" bgcolor="<?php echo $border_color?>"><img src="<?php echo $IMAGES_DIR?>Tree/spacer.gif"></td>
				<td  width=30 class="smallDark">
					<?php echo $name ?>
				</td>
				<td  width=250 class="smallDark" >
					<?php
						$the_bet = "$bet[Team1] - $bet[Team2]";
						//echo $the_bet;
						echo "<a class=smallDarkLink ".$link_tooltip." href=\"".$sess->link3($BET_PAGE, "MatchId=".$bet[MatchId]."&ContainerId=".$ContainerId."&redirect_page=".$REDIRECT_PAGE)."\" target=_top>";
						echo $the_bet."</a>\n";
					?>
				</td>
				<td  width=30 class=smallDark align=left>
					<?php
						if ($bet[Result]=="0")
							echo "?";
						else
							echo $bet[Result];
					?>
				</td>
				<td width=100  class=smallDark nowrap>
					<?php 
					echo $gain;
					?>
				</td>
				<td width=100 nowrap align=right class=smallDark>
					<?php 
					echo $gain_points;
					?>&nbsp;
				</td>
				<td width="1" bgcolor="<?php echo $border_color?>"><img src="<?php echo $IMAGES_DIR?>Tree/spacer.gif"></td>
			</tr>
<?php
	}
	if ($nb_paris > 0)
		return true;
	else
		return false;
}


// affiche les matchs renvoyés par la requête $query, et renvoie le nombre de matchs
// qui ont été affichés
// size = la taille de la police utilisée
// $nbMatchsToShow = le nombre de matchs à afficher
function showMatchs($query, $ContainerId, $border_color)
{
	global $player, $sess,$BET_PAGE, $IMAGES_DIR, $READ_COMMENT_PAGE, $BG_COLOR_FOND_3, $BG_COLOR_FOND_14, $BG_COLOR_FOND_8, $BG_COLOR_FOND_15, $BG_COLOR_FOND_13, $BG_COLOR_FOND_7, $BG_COLOR_FOND_12, $BG_COLOR_FOND_4, $BG_COLOR_FOND_9;
	global $REDIRECT_PAGE,$ORIGIN,$ORIGINE_M6;

	$current_european_date = date("d/m/Y H:i:s", my_local_time());
	$current_european_date = substr($current_european_date,0,10);
	$date = date("Y-m-d H:i:s", my_local_time());
	if (($player['Id'] == "") && ($sess->memberid != -1))
		$player = getplayer($sess->memberid);
	
	# $matchs = main_db_query($query);
	#################### PATCH SEREI ###########################
	$matchs = unserialize(base64_decode(getExploitationFile("afficher_container_".$ContainerId)));
	#$matchs = unserialize(getExploitationFile("afficher_patch", true));
	$nbMatchsPatch = count($matchs);
	########################################################
	
	$cpt = 0;
	
	################ OPTIM #################
	$tabAllBets = array();
	if ($sess->memberid != -1)
	{
		$rowsAllBets = main_db_query("SELECT MatchId, Bet, Amount FROM Paris WHERE PlayerId='".$player[Id]."' AND Done = 0");
		getKTabFromRows($rowsAllBets, $tabAllBets, $tabAllAmounts);
	}

	$monContainer = "";
	################ TITRES DE COLONNES #################
		
	# on affiche chacun des matchs renvoyés par la requête
	#################### PATCH SEREI ###########################
	for($rPatch = 0; $rPatch < $nbMatchsPatch; $rPatch++)
	########################################################
	#while($mon_match = db_fetch_array($matchs))
	{
		$mon_match = $matchs[$rPatch];
	
		$match_title = $mon_match[Team1]." - ".$mon_match[Team2];


		$matchTime = time_diff($date, $mon_match[Date]);

		$match_pronostic = "";
		if ($tabAllBets[$mon_match[MatchId]] != "")
		{
			$match_pronostic = "(".$tabAllBets[$mon_match[MatchId]].")";
			/*if ($matchTime < -7200)
			{
				$match_pronostic = "<font color=#9F9F9F>".$match_pronostic."</font>";
			}*/
		}

		$couleurmatch='#9F9F9F';
		if ($matchTime < -7200)
		{
			$border_color='';
			$matchDate = "<font color=#9F9F9F>résultat en attente</font>";
		}
		# pdt le match (2h) on met le live
		elseif ($matchTime < 0){
			$couleurmatch='#ff9933';
			$matchDate = "<img border=0 align=absmiddle border=0 src='".$IMAGES_DIR."Icones/mini_live.gif'>";
			}
		else
		{
			if ($current_european_date==date_mysql($mon_match[Date]))
			{
				$couleurmatch='#FF0000';
				$border_color='';
				$matchDate = "<font color=$couleurmatch>le <b>".date("d/m", strtotime($mon_match[Date]))." ".C_AGRAVE." ".time_mysql($mon_match[Date])."</b></font>";
			}
			else
			{
				if( $match_pronostic != "" )
					$couleurmatch='#008000';
				else
					$couleurmatch='#0000FF';
				$border_color='';
				$matchDate = "<font color=$couleurmatch>le ".date("d/m", strtotime($mon_match[Date]))." ".C_AGRAVE." ".time_mysql($mon_match[Date])."</font>";
			}
		}			
					
		if ( $monContainer != $mon_match[Container])
		{
			$row = db_fetch_row( main_db_query("SELECT Name FROM Containers WHERE Id='".$mon_match[Container]."'") );
			$containeur = "<table class='minibloc' id='black' style='width:180px;'><th id='head1'></th><th id='head2'><span style='color:#f2c000;font-size:10px'>".stripslashes(stripslashes($row[0]))."</span></th><th id='head3'></th></table>";
			echo "<tr><td>&nbsp;</td></tr><tr bgcolor=#00ff000>\n";
			echo "<tr><td colspan=7 class=boldDarkGreen style='padding-left:5px;'>".$containeur."</td></tr>\n";
			$monContainer = $mon_match[Container];
		}
		
		if( $match_pronostic != "" )
		{
			$border_color = '#eaeaea';
			echo "<tr bgcolor=#eaeaea>\n";
		}
		else
			echo "<tr >\n";

		echo "<td width=\"15\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td width=20 class=smallDark bgcolor=".$border_color.">&nbsp;<img src=\"".$IMAGES_DIR.$mon_match['Image']."\" onMouseover=\"showtip(this,event,'".addslashes($mon_match['Name'])."')\" onMouseout=\"hidetip()\"></td>\n";
		echo "<td width=190 class=smallDark bgcolor=".$border_color.">\n";
				
		$link_tooltip = "onMouseover=\"showtip(this,event,'".addslashes($mon_match['Name'])."')\" onMouseout=\"hidetip()\"";
		if ($matchTime < 0)
		{
			if( $matchTime < -7200 )
				$match_title = "<font color=#9F9F9F>".$match_title."</font>";
			else
				$match_title = "<font color=$couleurmatch>".$match_title."</font>";
			echo "<a class=smallDarkLink ".$link_tooltip." href=\"".$sess->link3($BET_PAGE, "MatchId=".$mon_match[MatchId]."&ContainerId=".$ContainerId."&redirect_page=".$REDIRECT_PAGE)."\" target=_top>";
			echo $match_title."</a>\n";
		}
		else
		{
			$match_title = "<font color=$couleurmatch>".$match_title."</font>";
			echo "<a class=smallDarkLink ".$link_tooltip." href=\"".$sess->link3($BET_PAGE, "MatchId=".$mon_match[MatchId]."&ContainerId=".$ContainerId."&redirect_page=".$REDIRECT_PAGE)."\" target=_top>";
			echo $match_title."</a>\n";
		}

		
		# on regarde si ce match donne droit à un cadeau spécifique
		if ($mon_match[Cadeau]==1)
		{
			echo "<img src=\"".$IMAGES_DIR."gift.gif\">&nbsp";
		}

		echo "</td>\n";
		//echo "</td>\n";

		echo "<td width=140 class=smallDark bgcolor=".$border_color.">".$matchDate;
		echo "</td>\n";
		echo "<td class=smallDark valign=left align=left bgcolor=".$border_color.">";
		if ($tabAllAmounts[$mon_match[MatchId]] > 0)
		{
			$link_mise_tooltip = "onMouseover=\"showtip_gauche(this,event,'Vous avez misé ".$tabAllAmounts[$mon_match[MatchId]]." points')\" onMouseout=\"hidetip()\"";
//			echo "<a href=\"#\" ".$link_mise_tooltip."><img border=0 src=\"".$IMAGES_DIR."Icones/picto_mise.gif\"></a>&nbsp;";
			echo "<font color=$couleurmatch>points misés: ".$tabAllAmounts[$mon_match[MatchId]]."</font>";
		}
		else
		{
			echo "<img border=0 src=\"".$IMAGES_DIR."Tree/spacer.gif\" width=27 height=0>&nbsp;";
		}
		echo "</td>\n";

		
		//Picto ParierMrBookmaker
		//echo "<td class=smallDark >";
			
		//echo "</td>\n";
		
		echo "<td class=smallDark width=90 bgcolor=".$border_color.">\n";
		$match_pronostic = ( $match_pronostic )? "<font color=$couleurmatch>score : ".$match_pronostic."</font>": "<font color=$couleurmatch></font>";
		echo $match_pronostic;
//		echo "<img src=\"".$IMAGES_DIR."triangleorange.gif\">&nbsp;";
//		echo "<a class=boldLink href=".$sess->link3($READ_COMMENT_PAGE, "&match=".$mon_match[MatchId]).">";
//		echo C_LESAVIS;
//		echo "</a>&nbsp;\n";
		echo "</td>\n";
		
		echo "<td class=smallDark valign=middle align=center bgcolor=".$border_color."></td>\n";
		
		echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";

		echo "<tr>\n";
		echo "<td width=\"1\"><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td colspan=5 class=smallDark height=1><img src=\"".$IMAGES_DIR."spacer.gif\" ></td>\n";
		echo "<td width=\"1\"><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";
	
		$cpt++;
    }
	return $cpt;
}


// affiche un onglet
function print_onglet($r, $ContainerId, $largeur_onglet, $container, $COULEUR_ONGLET_SELECTIONNE, $COULEUR_ONGLET_NON_SELECTIONNE, $COULEUR_ONGLET_SELECTIONNE, $COULEUR_CADRE_TABLEAU,$REDIRECT_PAGE)
{
	global $sess, $IMAGES_DIR, $BET_PAGE, $CURRENT_PAGE, $PHP_SELF;
	global $param_url;
	
	//echo $REDIRECT_PAGE;
	
	if ($param_url == "")
		$param_url = "ContainerId";
	
	$cur_titre =   "<font color="."#005F3F".">".stripslashes($container[Name])."</font>";
	if ($ContainerId == $container[Id])
	{
		// c'est l'onglet sélectionné
		$containerIndice = $r;
	
		$cur_titre =   "<b>".$cur_titre."</b>";
	
		$cur_bottomcolor = $COULEUR_ONGLET_SELECTIONNE;
		$cur_bordercolor = $COULEUR_ONGLET_NON_SELECTIONNE;
		$cur_bgcolor = $COULEUR_ONGLET_SELECTIONNE;
	}
	else
	{
		// c'est un onglet non sélectionné
		$cur_titre =  "<a class=ongletLink href=\"".$sess->link3($PHP_SELF, $param_url."=".$container[Id])."&redirect_page=".$REDIRECT_PAGE."\">\n".$cur_titre."</a>";
	
		$cur_bgcolor = $COULEUR_ONGLET_NON_SELECTIONNE;
		$cur_bottomcolor = $COULEUR_CADRE_TABLEAU;
		$cur_bordercolor = $COULEUR_ONGLET_NON_SELECTIONNE;
	}

	$cur_titre =  "&nbsp;".$cur_titre."&nbsp;\n";
	$cur_bordercolor = $COULEUR_CADRE_TABLEAU;
	
	echo "<td width=".$largeur_onglet." align=center valign=bottom >";
		// on met le contenu d'un titre d'onglet 
		echo "<table width=100% border=0 cellpadding=0 cellspacing=0>";
		echo "<tr>";
			echo "<td colspan=3 width=1 bgcolor=".$cur_bordercolor."><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
			if ($r < $nbContainers)
				echo "<td colspan=1 width=1 ><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
		echo "</tr>";
		echo "<tr>";
			echo "<td colspan=1 width=1 bgcolor=".$cur_bordercolor."><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
			echo "<td nowrap colspan=1 class=smallDark valign=middle align=center bgcolor=".$cur_bgcolor.">";
			echo $cur_titre;
			echo "</td>";
			echo "<td colspan=1 width=1 bgcolor=".$cur_bordercolor."><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
			if ($r < $nbContainers)
				echo "<td colspan=1 width=1 ><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
		echo "</tr>";
		echo "<tr>";
			echo "<td colspan=1 height=1 bgcolor=".$cur_bordercolor."><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
			echo "<td colspan=1 height=1 bgcolor=".$cur_bottomcolor."><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
			echo "<td colspan=1 height=1 bgcolor=".$cur_bordercolor."><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
			if ($r < $nbContainers)
				echo "<td colspan=1 height=1 bgcolor=".$cur_bordercolor."><img src=\"".$IMAGES_DIR."spacer.gif\"></td>";
		echo "</tr>";
		echo "</table>";
	echo "</td>";
}

// affiche un onglet
function print_onglet2($r, $ContainerId, $largeur_onglet, $container, $COULEUR_ONGLET_SELECTIONNE, $COULEUR_ONGLET_NON_SELECTIONNE, $COULEUR_ONGLET_SELECTIONNE, $COULEUR_CADRE_TABLEAU,$REDIRECT_PAGE)
{
	global $sess, $IMAGES_DIR, $BET_PAGE, $CURRENT_PAGE, $PHP_SELF;
	global $param_url;
	
	//echo $REDIRECT_PAGE;
	
	if ($param_url == "")
		$param_url = "ContainerId";
	
	if ($ContainerId == $container[Id])
	{
		// c'est l'onglet sélectionné
		$containerIndice = $r;
	
		$cur_titre =   "<font color='#045d14' style='font-size:11px;'>".stripslashes($container[Name])."</font>";
		$cur_titre =   "<b>".$cur_titre."</b>";
	
		$cur_bottomcolor = $COULEUR_ONGLET_SELECTIONNE;
		$cur_bordercolor = $COULEUR_ONGLET_NON_SELECTIONNE;
		$cur_bgcolor = $COULEUR_ONGLET_SELECTIONNE;
		
		$couleur_onglet = "lime2";
	}
	else
	{
		$cur_titre =   "<font color='#FFFFFF'>".stripslashes($container[Name])."</font>";
		// c'est un onglet non sélectionné
		$cur_titre =  "<a class='ongletLink' href=\"".$sess->link3($PHP_SELF, $param_url."=".$container[Id])."&redirect_page=".$REDIRECT_PAGE."\">\n".$cur_titre."</a>";
	
		$cur_bgcolor = $COULEUR_ONGLET_NON_SELECTIONNE;
		$cur_bottomcolor = $COULEUR_CADRE_TABLEAU;
		$cur_bordercolor = $COULEUR_ONGLET_NON_SELECTIONNE;

		$couleur_onglet = "green";
	}

	$cur_titre =  "&nbsp;".$cur_titre."&nbsp;\n";
	$cur_bordercolor = $COULEUR_CADRE_TABLEAU;
	
	echo "<td width=".$largeur_onglet." align=center valign=bottom >";
		// on met le contenu d'un titre d'onglet 
		echo "<table width=100% border=0 cellpadding=0 cellspacing=0>";
		echo "<tr><td align=center>";
		echo "<table class='minibloc' id='".$couleur_onglet."' cellpadding=0 cellspacing=0 style='width:".($largeur_onglet-2)."px;'><th id='head1'></th><th id='head2'><span style='color:#FFF;font-size:10px'>".$cur_titre."</span></th><th id='head3'></th></table></td>";
		echo "</tr>";

		echo "</table>";
	echo "</td>";
}


// affiche le tableau des matchs sur lesquels on peut parier
function afficher_paris($type,$ContainerId, $date, $nbMatchsToShow = 10, $COULEUR_ONGLET_SELECTIONNE = "#FFFFFF", $COULEUR_ONGLET_NON_SELECTIONNE = "#E0F5CC", $COULEUR_CADRE_TABLEAU =  "#66CC00", $width = 440, $height=150, $CURRENT_PAGE, $is_resultats = false, $autorise_impression = false)
{
	global $sess, $player, $IMAGES_DIR, $CONTAINER_ALL, $CHOOSE_BET_PAGE, $MY_BETS_PAGE;
	global $TYPE_ETAT,$REDIRECT_PAGE,$ORIGIN,$ORIGINE_KTF,$CURRENT_PAGE,$ARCHIVES_DIR;
	
/*
	$COULEUR_ONGLET_SELECTIONNE = "#FFFFFF";
	$COULEUR_ONGLET_NON_SELECTIONNE = "#E0F5CC";
	$COULEUR_CADRE_TABLEAU = "#66CC00";
*/
	$containers = main_db_query ("SELECT * FROM Containers WHERE ShowTime<'".$date."'  AND EndTime>'".$date."'");
//	echo $query;
	$nbContainers = db_num_rows ($containers); // +1 pour le container "all"

	// on affiche le tableau des onglets représentant les containers
	$largeur_onglet = floor($width / $nbContainers) ;


	echo "<table width=".$width." border=0 CELLSPACING=0 CELLPADDING=0>\n";
		echo "<tr>\n";
		$r = 0;

		$largeur_en_cours = 0;
//		echo "largeur : ".$width.", ".$largeur_onglet."<br>";
		while ($container = db_fetch_array($containers))
		{
			$r++;
/*			if ($r == $nbContainers)
				$cur_largeur_onglet = ($width - $largeur_en_cours);
			else
*/				$cur_largeur_onglet = $largeur_onglet;
			//if ($is_resultats == true && $type== 1)
			if ( 0 )
			{
				print_onglet($r, $ContainerId, $width, $container, $COULEUR_ONGLET_SELECTIONNE, $COULEUR_ONGLET_NON_SELECTIONNE, $COULEUR_ONGLET_SELECTIONNE, $COULEUR_CADRE_TABLEAU, $REDIRECT_PAGE);
			}
			$largeur_en_cours += $largeur_onglet;
		}
$COULEUR_CADRE_TABLEAU = '#FFFFFF';
		echo "</tr>\n";


	echo "</table>\n";
	

	// on affiche les matchs du container sélectionné
	echo "<table width=".$width." height=".$height." border=0 bordercolor=#FFFFFF cellspacing=0 cellpadding=0 bgcolor=".$COULEUR_ONGLET_SELECTIONNE.">\n";

		$strContainer =  ($ContainerId == $CONTAINER_ALL) ? "" : " AND Container = '".$ContainerId."' ";
		
		// juste pour l'espace
		echo "<tr >\n";
			echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td height=7 colspan=5><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";

		if ($is_resultats == false)
		{
			#$prerowbets ="SELECT Matchs.MatchId, Team1, Team2, Matchs.Result, Matchs.ShowTime AS ShowTime, Matchs.Category AS Category, Matchs.Date, (Matchs.Date<'".$date."') AS Closed, Name, Image FROM Matchs LEFT JOIN Categories ON Categories.CategoryId=Matchs.Category WHERE (Matchs.Result='0' OR Matchs.etat='".$TYPE_ETAT['WAIT']."')  AND Matchs.ShowTime<'".$date."' AND Categories.ShowTime<'".$date."' ".$strContainer." ORDER BY Matchs.Date ASC LIMIT 0,".$nbMatchsToShow;
			$prerowbets ="SELECT Matchs.MatchId, Team1, Team2, Matchs.Result, Matchs.ShowTime AS ShowTime, Matchs.Category AS Category, Matchs.Date, (Matchs.Date<'".$date."') AS Closed, Name, Image FROM Matchs LEFT JOIN Categories ON Categories.CategoryId=Matchs.Category WHERE (Matchs.Result='0' OR Matchs.etat='".$TYPE_ETAT['WAIT']."')  AND Matchs.ShowTime<'".$date."' AND Categories.ShowTime<'".$date."' ".$strContainer." LIMIT 0,".$nbMatchsToShow;

			switch( $type )
			{
				case 2:
					$ok = showMatchs2($prerowbets, $ContainerId, $COULEUR_CADRE_TABLEAU);
					break;
				case 3:
					$ok = showMatchsHome($prerowbets, $ContainerId, $COULEUR_CADRE_TABLEAU);
					break;
				case 1:
				default:
					$ok = showMatchs($prerowbets, $ContainerId, $COULEUR_CADRE_TABLEAU);
			}
		}
		else
		{
				/*
				$prerowbets = "SELECT Paris.*, Matchs.Result, Matchs.Team1, Matchs.Team2, Matchs.Rate1, Matchs.Rate2, Categories.Name, Matchs.Result, Matchs.MatchId, Matchs.Date AS Date, Categories.Name AS Name, Categories.Image AS Image FROM Paris ".
							" LEFT JOIN Matchs ON Matchs.MatchId=Paris.MatchId ".
							" LEFT JOIN Categories ON Matchs.Category=Categories.CategoryId ".
							" WHERE Paris.Done!='0' AND PlayerId='".$player[Id]."' $strContainer ORDER BY Paris.Date DESC LIMIT 0, ".$nbMatchsToShow;
				*/		
				$prerowbets = "SELECT Paris.PlayerId, Paris.Bet, Paris.MatchId, Paris.Amount, Paris.Done, Matchs.Result, Matchs.Team1, Matchs.Team2, Matchs.Rate1, Matchs.Rate2, Categories.Name, Matchs.Result, Matchs.MatchId, Matchs.Date AS Date, Containers.Name AS Container, Categories.Image AS Image FROM Paris ".
							" LEFT JOIN Matchs ON Matchs.MatchId=Paris.MatchId ".
							" LEFT JOIN Categories ON Matchs.Category=Categories.CategoryId ".
							" LEFT JOIN Containers ON Containers.Id=Categories.Container ".
							" WHERE Paris.Done!='0' AND PlayerId='".$player[Id]."' $strContainer ORDER BY Matchs.Date DESC LIMIT 0, ".$nbMatchsToShow;				
							
			if( $type== 1 )
				$ok = showResultats($prerowbets, $ContainerId, $COULEUR_CADRE_TABLEAU,$REDIRECT_PAGE);
			else
				$ok = showResultats2($prerowbets, $ContainerId, $COULEUR_CADRE_TABLEAU,$REDIRECT_PAGE);
		}
		if ($ok==0)
		{
			echo "<tr>\n";
				echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
				echo "<td class=smallDark align=center colspan=5>".C_AUCUNPARIS."<br></td>\n";
				echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "</tr>\n";
		}
		
		//PROMO GOOGLE ADSENES !!!!!! 
		if($ok <= 20 && $ORIGIN == $ORIGINE_KTF && $CHOOSE_BET_PAGE == $CURRENT_PAGE)
		{
			echo "<tr >\n";
				echo "<td height=1 width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
				echo "<td colspan=5 align=center class=smallDark>";
					echo "<br>";
					include($ARCHIVES_DIR."pub_prono.html");
					echo "<br style=font-size:4px>";
				echo "</td >";
				echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "</tr>\n";
		}
	//FIN PROMO GOOGLE ADSENES !!!!!!	
		
		
		// juste pour l'espace
		echo "<tr >\n";
			echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td height=100% colspan=5><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";

		
/*		echo "<tr >\n";
			echo "<td height=1 width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td colspan=5 align=center class=smallDark>";
				print_ligne($COULEUR_CADRE_TABLEAU, $width);
				echo "<br style=font-size:4px>";
			echo "</td >";
			echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";
*/
			if ($is_resultats)
				$target_all_pronos = $MY_BETS_PAGE;
			else
				$target_all_pronos = $CHOOSE_BET_PAGE;
		// il n'y a pas tous les pronos
		echo "<tr >\n";
			echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td valign=bottom colspan=10 align=right class=smallDark>";
				if ($nbMatchsToShow < 30 )
				{
						if (!$is_resultats){
							echo "<img align=\"absmiddle\" border=0 src=\"".$IMAGES_DIR."triangleorange.gif\">&nbsp;";
							echo "<a class=smallDarkLink href=\"".$sess->link3($target_all_pronos, "ContainerId=".$ContainerId)."\" target=_top>";
							echo "Tous les pronostics";
						}
						if ($is_resultats && $type==2){
							echo "<img align=\"absmiddle\" border=0 src=\"".$IMAGES_DIR."triangleorange.gif\">&nbsp;";
							echo "<a class=smallDarkLink href=\"".$sess->link3($target_all_pronos, "ContainerId=".$ContainerId)."\" target=_top>";
							echo "Tous mes résultats";
						}
				}
			echo "</td >";
//			echo "<td width=\"1\" bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";


echo "<tr height=1>\n";
	echo "<td align=right colspan=6 bgcolor=".$COULEUR_CADRE_TABLEAU."><img src=".$IMAGES_DIR."Tree/spacer.gif></td>\n";
echo "</tr>\n";
	
echo "</table>\n";
	
}




function showResultats2($query, $ContainerId, $border_color)
{
	global $date, $player, $sess,$BET_PAGE, $IMAGES_DIR, $READ_COMMENT_PAGE;
	global $BG_COLOR_FOND_1, $BG_COLOR_FOND_4, $BG_COLOR_FOND_8, $BG_COLOR_FOND_3, $BG_COLOR_FOND_7, $BG_COLOR_FOND_13, $BG_COLOR_FOND_10;
	global $REDIRECT_PAGE;

	$tour = db_fetch_array(main_db_query ("SELECT * FROM Tours WHERE ShowTime<'".$date."' AND EndTime>'".$date."'"));
	$endSession = false;
	$rowbets = main_db_query($query);
	$nb_paris = 0;


		echo "<tr >\n";
			echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td class=smallBoldDark colspan=1 ></td>\n";
			echo "<td class=smallBoldDark colspan=1 style='padding:1px;'>Match&nbsp;</td>\n";
			echo "<td class=smallBoldDark colspan=1 align=left style='padding:1px;'>Score&nbsp;</td>\n";
			echo "<td class=smallBoldDark colspan=1 style='padding:1px;'>Mon&nbsp;résultat&nbsp;</td>\n";
			echo "<td class=smallBoldDark align=right colspan=1 style='padding:1px;'>Points&nbsp;</td>\n";
			echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";
		echo "<tr >\n";
			echo "<td height=1 width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
			echo "<td colspan=5 align=center class=smallDark>";
				print_ligne($border_color, 285);
				echo "<br style=font-size:4px>";
			echo "</td >";
			echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";
		
	while ($bet = db_fetch_array($rowbets))
	{
		$nb_paris++;
			if ($bet[Bet] != "0") 
				 $pari = $bet[Bet];

			if ($bet[Result]!="0")
			{
				$gain = calcule_gain_prono($bet[Result],$bet[Bet],1,$bet[Rate1],$bet[Rate2]);
				$gain_points = calcule_gain_prono($bet[Result],$bet[Bet],$bet[Amount],$bet[Rate1],$bet[Rate2]);
				if ($gain_points > 0)
					$gain_points = "+".$gain_points;
				
				$gain_suffixe = "</font>";
				if ( $gain == $bet[Rate1])
				{
					$gain_points_prefixe = "<font color=".$BG_COLOR_FOND_1.">";
					$gain_prefixe = $gain_points_prefixe."Perfect";
					$gain_suffixe = "".$gain_suffixe;
				}
				elseif ($gain == $bet['Rate2'])
				{
					$gain_points_prefixe = "<font color=".$BG_COLOR_FOND_4.">";
					$gain_prefixe = $gain_points_prefixe."Correct";
				}
				else
				{
					$gain_points_prefixe = "<font color="."#FF7777".">";
					$gain_prefixe = $gain_points_prefixe."Echec";
				}

				$gain = $gain_prefixe."&nbsp;(".$pari.")</font>";
				$gain_points = $gain_points_prefixe.$gain_points."</font>";
			}	
			else
			{
				$gain_points_prefixe = "<font color="."#9F9F9F".">";
				$gain_prefixe = $gain_points_prefixe;
				$gain = $gain_prefixe."-".$gain_suffixe;
				$gain_points = $gain_prefixe.$gain_suffixe;
			}

			
			# on détecte la fin d'une session pour bien séparer les résultats
			if (!$endSession)
			{
				if (time_diff($tour['ShowTime'] , $bet["Date"]) < 0)
				{
					# si c'est dès la première ligne, on considère qu'on n'affiche pas
					# le changement de session
					if ($i > 1)
					{
						echo "<tr>";
						echo "<td height=1 width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
						echo "<td colspan=5 class=whiteBoldTitle><font size=1>Fin de Session</font></td></tr>";
						echo "<td height=1 width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
						echo "</tr>";
					}
					$endSession = true;
				}
			}

			$name = "&nbsp;<img src=\"".$IMAGES_DIR.$bet['Image']."\" onMouseover=\"showtip(this,event,'".$bet['Name']."')\" onMouseout=\"hidetip()\">";
			//echo $bet['Image']."x";
			//"<font color=".$font_color.">".$bet[Name]."</font>";
			
?> 
			<tr>
				<td width="1" bgcolor="<?php echo $border_color?>"><img src="<?php echo $IMAGES_DIR?>Tree/spacer.gif"></td>
				<td  width=30 class="smallDark">
					<?php echo $name ?>
				</td>
				<td  width=180 class="smallDark" >
					<?php
						$the_bet = "$bet[Team1] - $bet[Team2]";
						//echo $the_bet;
						echo "<a class=smallDarkLink ".$link_tooltip." href=\"".$sess->link3($BET_PAGE, "MatchId=".$bet[MatchId]."&ContainerId=".$ContainerId."&redirect_page=".$REDIRECT_PAGE)."\" target=_top>";
						echo $the_bet."</a>\n";
					?>
				</td>
				<td  width=30 class=smallDark align=center>
					<?php
						if ($bet[Result]=="0")
							echo "?";
						else
							echo $bet[Result];
					?>
				</td>
				<td width=65  class=smallDark nowrap>
					<?php 
					echo $gain;
					?>
				</td>
				<td width=35 nowrap align=right class=smallDark>
					<?php 
					echo $gain_points;
					?>&nbsp;
				</td>
				<td width="1" bgcolor="<?php echo $border_color?>"><img src="<?php echo $IMAGES_DIR?>Tree/spacer.gif"></td>
			</tr>
<?php
	}
	if ($nb_paris > 0)
		return true;
	else
		return false;
}


// affiche les matchs renvoyés par la requête $query, et renvoie le nombre de matchs
// qui ont été affichés
// size = la taille de la police utilisée
// $nbMatchsToShow = le nombre de matchs à afficher
function showMatchs2($query, $ContainerId, $border_color)
{
	global $player, $sess,$BET_PAGE, $IMAGES_DIR, $READ_COMMENT_PAGE, $BG_COLOR_FOND_3, $BG_COLOR_FOND_14, $BG_COLOR_FOND_8, $BG_COLOR_FOND_15, $BG_COLOR_FOND_13, $BG_COLOR_FOND_7, $BG_COLOR_FOND_12, $BG_COLOR_FOND_4, $BG_COLOR_FOND_9;
	global $REDIRECT_PAGE,$ORIGIN,$ORIGINE_M6;
		
	$current_european_date = date("d/m/Y H:i:s", my_local_time());
	$current_european_date = substr($current_european_date,0,10);
	$date = date("Y-m-d H:i:s", my_local_time());
	if (($player['Id'] == "") && ($sess->memberid != -1))
		$player = getplayer($sess->memberid);
	
	# $matchs = main_db_query($query);
	#################### PATCH SEREI ###########################
	$matchs = unserialize(base64_decode(getExploitationFile("afficher_container_".$ContainerId)));
	#$matchs = unserialize(getExploitationFile("afficher_patch", true));
	$nbMatchsPatch = count($matchs);
	########################################################
	
	
	$cpt = 0;
	
	################ OPTIM #################
	$tabAllBets = array();
	if ($sess->memberid != -1)
	{
		$rowsAllBets = main_db_query("SELECT MatchId, Bet, Amount FROM Paris WHERE PlayerId='".$player[Id]."' AND Done = 0");
		getKTabFromRows($rowsAllBets, $tabAllBets, $tabAllAmounts);
	}

	################ TITRES DE COLONNES #################
		
	# on affiche chacun des matchs renvoyés par la requête
	#################### PATCH SEREI ###########################
	for($rPatch = 0; $rPatch < $nbMatchsPatch; $rPatch++)
	########################################################
	#while($mon_match = db_fetch_array($matchs))
	{
		$mon_match = $matchs[$rPatch];
	
		$match_title = $mon_match[Team1]." - ".$mon_match[Team2];


		$matchTime = time_diff($date, $mon_match[Date]);

		$match_pronostic = "";
		if ($tabAllBets[$mon_match[MatchId]] != "")
		{
			$match_pronostic = "(".$tabAllBets[$mon_match[MatchId]].")";
			if ($matchTime < -7200)
				$match_pronostic = "<font color=#9F9F9F>".$match_pronostic."</font>";
		}

		if ($matchTime < -7200)
		{
			$matchDate = "<font color=#9F9F9F>résultat en attente</font>";
		}
		# pdt le match (2h) on met le live
		elseif ($matchTime < 0)
		{
			$matchDate = "<img border=0 align=absmiddle border=0 src='".$IMAGES_DIR."Icones/mini_live.gif'>";
			$couleurmatch='#ff9933';
		}
		else
		{
			if ($current_european_date==date_mysql($mon_match[Date]))
			{
				$couleurmatch='#ff0000';
				if(	$match_pronostic )
					$border_color='#eaeaea';
				else
					$border_color='';
				$matchDate = "<font color=$couleurmatch>le <b>".date("d/m", strtotime($mon_match[Date]))." ".C_AGRAVE." ".time_mysql($mon_match[Date])."</b></font>";
			}
			else
			{
				if(	$match_pronostic ){
					$couleurmatch='#008000';
					$border_color='#eaeaea';
				}else{
					$couleurmatch='#0000FF';
					$border_color='';
				}
				$matchDate = "<font color=$couleurmatch>le ".date("d/m", strtotime($mon_match[Date]))." ".C_AGRAVE." ".time_mysql($mon_match[Date])."</font>";
			}
		}			

		echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td width=20 class=smallDark bgcolor=".$border_color.">&nbsp;<img src=\"".$IMAGES_DIR.$mon_match['Image']."\" onMouseover=\"showtip(this,event,'".addslashes($mon_match['Name'])."')\" onMouseout=\"hidetip()\"></td>\n";
		echo "<td class=smallDark bgcolor=".$border_color.">\n";
				

		$link_tooltip = "onMouseover=\"showtip(this,event,'".addslashes($mon_match['Name'])."')\" onMouseout=\"hidetip()\"";
		if ($matchTime < 0)
		{
			if( $matchTime < -7200 )
				$match_title = "<font color=#9F9F9F>".$match_title."</font>";
			else
				$match_title = "<font color=$couleurmatch>".$match_title."</font>";
			echo "<a class=smallDarkLink ".$link_tooltip." href=\"".$sess->link3($BET_PAGE, "MatchId=".$mon_match[MatchId]."&ContainerId=".$ContainerId."&redirect_page=".$REDIRECT_PAGE)."\" target=_top>";
			echo $match_title."</a>\n";
		}
		else
		{
			$match_title = "<font color=$couleurmatch>".$match_title."</font>";
			echo "<a class=smallDarkLink ".$link_tooltip." href=\"".$sess->link3($BET_PAGE, "MatchId=".$mon_match[MatchId]."&ContainerId=".$ContainerId."&redirect_page=".$REDIRECT_PAGE)."\" target=_top>";
			echo $match_title."</a>\n";
		}

		
		# on regarde si ce match donne droit à un cadeau spécifique
		if ($mon_match[Cadeau]==1)
		{
			echo "<img src=\"".$IMAGES_DIR."gift.gif\">&nbsp";
		}

		echo "</td>\n";

		echo "<td class=smallDark bgcolor=".$border_color.">".$matchDate;
		echo "</td>\n";
		
		echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";

		echo "<tr>\n";
		echo "<td width=\"1\"><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td colspan=5 class=smallDark height=1><img src=\"".$IMAGES_DIR."spacer.gif\" ></td>\n";
		echo "<td width=\"1\"><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";
	
		$cpt++;
    }
	return $cpt;
}


// affiche les matchs renvoyés par la requête $query, et renvoie le nombre de matchs
// qui ont été affichés
// size = la taille de la police utilisée
// $nbMatchsToShow = le nombre de matchs à afficher
function showMatchsHome($query, $ContainerId, $border_color)
{
	global $player, $sess,$BET_PAGE, $IMAGES_DIR, $READ_COMMENT_PAGE, $BG_COLOR_FOND_3, $BG_COLOR_FOND_14, $BG_COLOR_FOND_8, $BG_COLOR_FOND_15, $BG_COLOR_FOND_13, $BG_COLOR_FOND_7, $BG_COLOR_FOND_12, $BG_COLOR_FOND_4, $BG_COLOR_FOND_9;
	global $REDIRECT_PAGE,$ORIGIN,$ORIGINE_M6;
	
	$current_european_date = date("d/m/Y H:i:s", my_local_time());
	$current_european_date = substr($current_european_date,0,10);
	$date = date("Y-m-d H:i:s", my_local_time());
	if (($player['Id'] == "") && ($sess->memberid != -1))
		$player = getplayer($sess->memberid);
	
	# $matchs = main_db_query($query);
	#################### PATCH SEREI ###########################
	$matchs = unserialize(base64_decode(getExploitationFile("afficher_container_".$ContainerId)));
	#$matchs = unserialize(getExploitationFile("afficher_patch", true));
	$nbMatchsPatch = count($matchs);
	########################################################
	
	
	$cpt = 0;
	
	################ OPTIM #################
	$tabAllBets = array();
	if ($sess->memberid != -1)
	{
		$rowsAllBets = main_db_query("SELECT MatchId, Bet, Amount FROM Paris WHERE PlayerId='".$player[Id]."' AND Done = 0");
		getKTabFromRows($rowsAllBets, $tabAllBets, $tabAllAmounts);
	}

	################ TITRES DE COLONNES #################
		
	# on affiche chacun des matchs renvoyés par la requête
	#################### PATCH SEREI ###########################
	for($rPatch = 0; $rPatch < $nbMatchsPatch; $rPatch++)
	########################################################
	#while($mon_match = db_fetch_array($matchs))
	{
		$mon_match = $matchs[$rPatch];
	
		$match_title = $mon_match[Team1]." - ".$mon_match[Team2];


		$matchTime = time_diff($date, $mon_match[Date]);

		$match_pronostic = "";
		if ($tabAllBets[$mon_match[MatchId]] != "")
		{
			$match_pronostic = "(".$tabAllBets[$mon_match[MatchId]].")";
			if ($matchTime < -7200)
				$match_pronostic = "<font color=#9F9F9F>".$match_pronostic."</font>";
		}

		if ($matchTime < -7200)
		{
			$matchDate = "<font color=#9F9F9F>résultat en attente</font>";
		}
		# pdt le match (2h) on met le live
		elseif ($matchTime < 0)
		{
			$matchDate = "<img border=0 align=absmiddle border=0 src='".$IMAGES_DIR."Icones/mini_live.gif'>";
			$couleurmatch='#ff9933';
		}
		else
		{
			if ($current_european_date==date_mysql($mon_match[Date]))
			{
				$couleurmatch='#ff0000';
				$matchDate = "<font color=$couleurmatch>le <b>".date("d/m", strtotime($mon_match[Date]))." ".C_AGRAVE." ".time_mysql($mon_match[Date])."</b></font>";
			}
			else
			{
				$couleurmatch='#0000FF';
				$matchDate = "<font color=$couleurmatch>le ".date("d/m", strtotime($mon_match[Date]))." ".C_AGRAVE." ".time_mysql($mon_match[Date])."</font>";
			}
		}			

		if(	$border_color=='#eaeaea' )
			$border_color='';
		else
			$border_color='#eaeaea';

			echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td width=20 class=smallDark bgcolor=".$border_color.">&nbsp;<img src=\"".$IMAGES_DIR.$mon_match['Image']."\" onMouseover=\"showtip(this,event,'".addslashes($mon_match['Name'])."')\" onMouseout=\"hidetip()\"></td>\n";
		echo "<td class=smallDark bgcolor=".$border_color.">\n";
				

		$link_tooltip = "onMouseover=\"showtip(this,event,'".addslashes($mon_match['Name'])."')\" onMouseout=\"hidetip()\"";
		if ($matchTime < 0)
		{
			if( $matchTime < -7200 )
				$match_title = "<font color=#9F9F9F>".$match_title."</font>";
			else
				$match_title = "<font color=$couleurmatch>".$match_title."</font>";
			echo "<a class=smallDarkLink ".$link_tooltip." href=\"".$sess->link3($BET_PAGE, "MatchId=".$mon_match[MatchId]."&ContainerId=".$ContainerId."&redirect_page=".$REDIRECT_PAGE)."\" target=_top>";
			echo $match_title."</a>\n";
		}
		else
		{
			$match_title = "<font color=$couleurmatch>".$match_title."</font>";
			echo "<a class=smallDarkLink ".$link_tooltip." href=\"".$sess->link3($BET_PAGE, "MatchId=".$mon_match[MatchId]."&ContainerId=".$ContainerId."&redirect_page=".$REDIRECT_PAGE)."\" target=_top>";
			echo $match_title."</a>\n";
		}

		
		# on regarde si ce match donne droit à un cadeau spécifique
		if ($mon_match[Cadeau]==1)
		{
			echo "<img src=\"".$IMAGES_DIR."gift.gif\">&nbsp";
		}

		echo "</td>\n";

		echo "<td class=smallDark bgcolor=".$border_color.">".$matchDate;
		echo "</td>\n";
		
		echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td width=\"0\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td width=\"0\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td width=\"1\" bgcolor=".$border_color."><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";

		echo "<tr>\n";
		echo "<td width=\"1\"><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "<td colspan=5 class=smallDark height=1><img src=\"".$IMAGES_DIR."spacer.gif\" ></td>\n";
		echo "<td width=\"1\"><img src=\"".$IMAGES_DIR."Tree/spacer.gif\"></td>\n";
		echo "</tr>\n";
	
		$cpt++;
    }
	return $cpt;
}

?>