<?php

##############################################################################
# guide.php3                                                                 #
#                                                                            #
# Copyright ViralGames SARL 2000                                             #
##############################################################################

include("config.php3");
include($BIB."bib_generic.php3");
include($BIB."bib_showGames.php3"); 
include($BIB."bib_drapeaux.php3");
#include($BIB."bib_exploitation.php3");
$sess = open_page($sessid);

$REDIRECT_PAGE = base64_encode("actu_stats.php3?sessid=".$sessid."&type_classement=3");

// les différentes compétitions
	$types_classement[0]['Id'] = 1;
	$types_classement[0]['Name'] = "Classement de L1";

	$types_classement[1]['Id'] = 2;
	$types_classement[1]['Name'] = "Classement de L2";

//	$types_classement[2]['Id'] = 3;
//	$types_classement[2]['Name'] = "Calendrier";

	$param_url = "type_classement";

if ($type_classement == "")
	$type_classement = $types_classement[0]['Id'];


// les façons de classer les équipes
$TABLE_SORTING[0][Name] = "Pts";
$TABLE_SORTING[0][Tooltip] = "Points";
$TABLE_SORTING[0][SQL] = "ORDER BY Points DESC, ButsDifference DESC, Joues DESC, ButsPour DESC";
$TABLE_SORTING[0][Row] = "Points";

$TABLE_SORTING[1][Name] = "J.";
$TABLE_SORTING[1][Tooltip] = "Matchs joués";
$TABLE_SORTING[1][SQL] = "ORDER BY Joues DESC, Gagnes DESC, Nuls DESC, Perdus ASC";
$TABLE_SORTING[1][Row] = "Joues";

$TABLE_SORTING[2][Name] = "G.";
$TABLE_SORTING[2][Tooltip] = "Matchs gagnés";
$TABLE_SORTING[2][SQL] = "ORDER BY Gagnes DESC, Joues DESC, Nuls DESC, Perdus ASC";
$TABLE_SORTING[2][Row] = "Gagnes";

$TABLE_SORTING[3][Name] = "N.";
$TABLE_SORTING[3][Tooltip] = "Matchs nuls";
$TABLE_SORTING[3][SQL] = "ORDER BY Nuls DESC, Joues DESC, Gagnes DESC, Perdus ASC";
$TABLE_SORTING[3][Row] = "Nuls";

$TABLE_SORTING[4][Name] = "P.";
$TABLE_SORTING[4][Tooltip] = "Matchs perdus";
$TABLE_SORTING[4][SQL] = "ORDER BY Perdus ASC, Joues DESC, Gagnes DESC, Nuls ASC";
$TABLE_SORTING[4][Row] = "Perdus";

$TABLE_SORTING[5][Name] = "bp";
$TABLE_SORTING[5][Tooltip] = "Buts pour";
$TABLE_SORTING[5][SQL] = "ORDER BY ButsPour DESC, Joues DESC, ButsContre ASC ";
$TABLE_SORTING[5][Row] = "ButsPour";

$TABLE_SORTING[6][Name] = "bc";
$TABLE_SORTING[6][Tooltip] = "Buts contre";
$TABLE_SORTING[6][SQL] = "ORDER BY ButsPour DESC, Joues DESC, ButsContre ASC ";
$TABLE_SORTING[6][Row] = "ButsContre";

$TABLE_SORTING[7][Name] = "diff";
$TABLE_SORTING[7][Tooltip] = "Différence de buts";
$TABLE_SORTING[7][SQL] = "ORDER BY ButsDifference DESC, Joues DESC, ButsPour DESC, ButsContre ASC";
$TABLE_SORTING[7][Row] = "ButsDifference";

if ($sorting == "")
{
	$sorting = 0;
}

function show_titles($color2, $color4, $type_classement, $sorting)
{
	global $sess, $STATS_PAGE_MODULE, $IMAGES_DIR;
	global $TABLE_SORTING;
	?>
    <tr bgcolor="<?php echo $color2?>"> 
       <td height=12 class="smallBoldDark" align=right colspan=<?php echo 2+ count($TABLE_SORTING)?> >  
         <br style=font-size:4px>
       </td>
     </tr>
    <tr bgcolor="<?php echo $color2?>" height=12> 
       <td class="smallBoldDark" align=center colspan=2 width=40></td>
<?php
	for ($i = 0 ; $i < count($TABLE_SORTING) ; $i++)
	{
       echo "<td class=smallBoldDark align=center colspan=1 >";
		if ($sorting == $i)
			echo "<img src=\"".$IMAGES_DIR."fleche_bas.gif\">";
		echo "</td>";
	}
?>
    <tr bgcolor=<?php echo $color4?> height=15> 
       <td class="smallBoldDark" align=center colspan=2 width=100>Equipe</td>
<?php
	for ($i = 0 ; $i < count($TABLE_SORTING) ; $i++)
	{
		echo "<td width=22 class=smallBoldDark align=right>";
/*		if ($sorting == $i)
			echo $TABLE_SORTING[$i][Name];
		else
	*/
			echo "<a onMouseover=\"showtip(this,event,'".addslashes($TABLE_SORTING[$i][Tooltip])."')\" onMouseout=\"hidetip()\" class=smallDarkLink href=\"".$sess->link3($STATS_PAGE_MODULE, "type_classement=".$type_classement."&visu=visu&sorting=".$i."&name=".urlencode($name))."\">".$TABLE_SORTING[$i][Name]."</a>";
       echo "&nbsp;</td>";
	 }
	 ?>
     </tr>
    <tr bgcolor="<?php echo $color2?>"> 
       <td height=4 class="smallBoldDark" align=right colspan=<?php echo 2+ count($TABLE_SORTING)?>>  
         <br style=font-size:4px>
       </td>
     </tr>
	<?php
}

function show_line($j, $rowscore, $color, $sorting)
{
	global $IMAGES_DIR, $sess;
	global $TABLE_SORTING, $BG_COLOR_FOND_4, $BG_COLOR_FOND_13, $BG_COLOR_FOND_1, $BG_COLOR_FOND_15, $BG_COLOR_FOND_8;
	global $Equipe1, $Equipe2;
	
		if ($Equipe1 == $rowscore['Id'])
		{
			$texte_prefixe = "(<font color=".$BG_COLOR_FOND_15.">1</font>N2)&nbsp;";
		}
		elseif  ($Equipe2 == $rowscore['Id'])
		{
			$texte_prefixe = "(1N<font color=".$BG_COLOR_FOND_15.">2</font>)&nbsp;";
		}
		else
		{
			$texte_prefixe = "";
		}
		

?>
	            <td height=12 bgcolor="<?php echo $color?>" class="smallDark" align=right><?php 
					echo $texte_prefixe.$j.".&nbsp;";
	              	# la variation est stockée en inverse de classement
					if ($TABLE_SORTING[0] == $sorting)
					{
		              	$variation_tab = explode(",".$rowscore['Progression']);
						$count_variation_tab = count($variation_tab);
						if ($count_variation_tab  <= 0 )
						{
							$variation = 0;
		            	  	$string_variation = "-";
						}
						else
						{
							$variation = $variation_tab[$count_variation_tab-1] - $j;
		            	  	$string_variation = "(".$variation.")";
						}

		              	if ($variation<0)
		              	{
		              		echo "<font size=1 color=D02F2F>".$string_variation."</font>";
		              		echo ' <img src="'.$IMAGES_DIR.'fleches/FRouge.gif">';
		              	}
		              	elseif ($variation>0)
		              	{
		              		echo "<font size=1 color=70BF3F>+".$string_variation."</font>";
		              		echo ' <img src="'.$IMAGES_DIR.'fleches/FVerte.gif">';
		              	}
		              	else
		              	{
		              		echo "( - )";
		              	}
					}
	              ?></td>
	            <td bgcolor="<?php echo $color?>" class="smallDark" align=left> 
				&nbsp;<?php echo $rowscore['Name']; ?>&nbsp;
	            </td>
				<?php
				for ($i = 0 ; $i < count($TABLE_SORTING) ; $i++)
				{
				?>
	            <td align=right class="smallDark" bgcolor="<?php echo $color?>" > 
			         <?php
					 	if ($i == count($TABLE_SORTING)-1)
						{
							if ($rowscore[$TABLE_SORTING[$i][Row]] < 0)
								echo "<font size=1 color=".$BG_COLOR_FOND_1.">".$rowscore[$TABLE_SORTING[$i][Row]]."</font>";
							else
								echo "<font size=1 color=".$BG_COLOR_FOND_1.">+".$rowscore[$TABLE_SORTING[$i][Row]]."</font>";
						}
						else
		                	echo $rowscore[$TABLE_SORTING[$i][Row]] ?>&nbsp;
	            </td>
				<?php
				}
}

function showScores($color1, $color2, $color3, $color4, $type_classement, $sorting)
{
	global $MAX_SCORES, $IMAGES_DIR, $FRUIT_LIST, $INVISIBLE_FRUIT;
	global $rank, $sess;
	global $TABLE_SORTING;
	global $Equipe1, $Equipe2;

	$SQLSorting = $TABLE_SORTING[$sorting][SQL];
	
	$query = "SELECT *".
		" FROM Classement_Clubs WHERE ContainerId='".$type_classement."' ".$SQLSorting;

	//debug($query);
	$rowscores = main_db_query($query);
		
	$i = 0;

	echo "<table height=300 valign=top width=\"100%\" border=0 cellpadding=0 cellspacing=1>  ";
	show_titles($color2, $color4, $type_classement, $sorting);

	while ($rowscore = db_fetch_array($rowscores))
	{
		$i++;
	  	$color = ($i % 2 == 1)?$color1:$color2;

		if (($Equipe1 == $rowscore['Id']) || ($Equipe2 == $rowscore['Id']))
		{
			$color = $color4;
		}

		echo "<tr onmouseover=\"setPointer(this, '".$color3."', '".$color."');\" onmouseout=\"setPointer(this, '".$color."', '".$color."');\">";
        $fruit = $IMAGES_DIR.$FRUIT_LIST[intval($rowscore[Fruit])];
		
	    show_line($i, $rowscore, $color, $SQLSorting);
		echo "</tr>";
	}
	echo "</table>";
}

$title = "Classements";
include("actu_stats_module.inc");
close_page($sess);

?>

