Files
resatennis_tyroltenn/www/site_inscription/dessinTableau.php

214 lines
7.5 KiB
PHP
Executable File

<?php
// positionne les matchs dans tableau a deux dimension + une dimension pour les info de match
// nom des joueur,score,heure
function calculTab($tab,$score,$time,$nb_joueur,$nbtour)
{
for($i=0;$i<$nbtour;$i++) // on prend les tour 1 par 1
{
$espace_v=pow(2,$i)-1; // espace en case entre le haut de tableau et le premier match du tour
$espace_i=pow(2,$i+1)-1; // espace en case entre deux match du meme tour
/*echo "tour : ".$i."<br>";
echo "espace en case entre le haut de tableau et le premier match du tour : ".$espace_v."<br>";
echo "espace en case entre deux match du meme tour : ".$espace_i."<br>";*/
$match=0;
while($match<$nb_joueur/2) // on prend les match un par un
{
if($tab[$i][$match*2] and $tab[$i][$match*2+1] and $tab[$i][$match*2]!="NULL" and $tab[$i][$match*2+1]!="NULL") // si joueur pas "NULL"
{
$joueurs[]=$tab[$i][$match*2]; //on recupere les noms
$joueurs[]=$tab[$i][$match*2+1];
$tmp=$score[$i][$match*2]; // on recupere le score correctement formate
$joueurs[]=$tmp; // on copie le score dans les case qui vont bien
$joueurs[]=$time[$i][$match*2]; // on copie l'heure
$result[($espace_v)+($espace_i+1)*$match][$i]=$joueurs; //the truc pour avoir l'emplacement
unset($joueurs);
}
else
{
$result[($espace_v)+($espace_i+1)*$match][$i]="&";
}
//echo "match : ".$match." ".$tab[$i][$match*2]." ".$result[($espace_v)+($espace_i+1)*$match][$i]."<br>";
$match++;
}
}
return $result;
}
/* Crée une ligne vide */
function ligneVide($tab,$nbmatch,$nbtour)
{
for($i=0;$i<$nbmatch;$i++)
{
$vide1=true;
$vide2=true;
for($j=0;$j<$nbtour;$j++)
{
if($tab[$i][$j]!="")
{
$vide1=false;
break;
}
}
if(!$vide1)
$retour[]=$tab[$i];
}
return $retour;
}
// printab affiche le tableau
// result etant le tableau provenant de calculTab,nbmatch le nombre de match (null compris) au premier tour,et nbtour le nombre de tour a affiche
function printTab($result,$nbmatch,$nbtour)
{
echo '<table cellspacing="0" cellpadding="0" border="0" height="110">';
for($i=0;$i<$nbmatch;$i++)
{
$vide=true;
for($j=0;$j<$nbtour;$j++)
{
if($result[$i][$j]!="")
{
$vide=false;
break;
}
}
if(!$vide)
{
echo "<tr>";
for($j=0;$j<$nbtour;$j++) // on prend tout les tour affiche
{
$espace_v=pow(2,$j)-1; // on l'utilise pour retrouver les case voisine et savoir si il faut mettre un coin un trait etc.
echo "<TD>";
if($result[$i][$j]!="" and $result[$i][$j]!="&") // si y a un match
{
echo '<table cellspacing="1" cellpadding="1" width="260" border="1" bgcolor="#FFFFFF">';
echo '<tr height="20" valign="middle">';
if($result[$i][$j][2]=="") // si le match n'a pas de vainqueur (pas joue)
{
$win1="nullmatch";$color1="#000000";
$win2="nullmatch";$color2="#000000";
}
else if($result[$i][$j][2]==1) // si joueur1 vainqueur
{
$win1="winmatch";$color1="#FF0000";
$win2="loosematch";$color2="#000000";
}
else // joueur2 vainqueur
{
$win1="loosematch";$color1="#000000";
$win2="winmatch";$color2="#FF0000";
}
echo '<td class="text" width="200">';
list ($match1,$nom1)=explode("*",$result[$i][$j][0]);
if($nom1=="V") // si c un match dont le joueur 1 est connu
$nom1="";
if ($j>0)
$match1="";
//echo '<img src="images/flags/FR.gif" border="0" align="center" alt="FR">';
echo '<font color=darkgreen><b>'.$match1.'</b><a href=></font><img src="images/next.gif" border="0"></a>'.$nom1;
echo '</td>';
if($result[$i][$j][2]!='')
{
echo '<td class="'.$win1.'" width="60" align="center">';
if($result[$i][$j][2]==1) // si le j1 vainqueur on ecrit les donnees de la case 3
echo "<font color=$color1>".$result[$i][$j][3]."</font>";
else
echo "<font color=$color1>".$result[$i][$j][4]."</font>";
echo '</td>';
}
echo '</tr>';
echo '<tr height="10">';
echo '<td colspan="2" class="info" nowrap>';
list ($match,$horaire)=explode("*",$result[$i][$j][5]);
if ($j != ($nbtour-1))
$match="";
echo $match;
echo '<img src="images/next.gif" border="0" align="center">';
echo '<small>'.$horaire.'</small>';
echo '</td>';
echo '</tr>';
echo '<tr height="20" valign="middle">';
echo '<td class="text" width="200">';
list ($match2,$nom2)=explode("*",$result[$i][$j][1]);
if($nom2=="V") // si c un match dont le joueur 1 est connu
$nom2="";
if ($j>0)
$match2="";
//echo '<img src="images/flags/FR.gif" border="0" align="center" alt="FR">';
echo '<font color=darkgreen><b>'.$match2.'</b></font><a href="" ><img src="images/next.gif" border="0"></a>'.$nom2;
echo '</td>';
if($result[$i][$j][2]!='')
{
echo '<td class="'.$win2.'" width="60" align="center">';
if($result[$i][$j][2]==2)
echo "<font color=$color2>".$result[$i][$j][3]."</font>";
else
echo "<font color=$color2>".$result[$i][$j][4]."</font>";
echo '</td>';
}
echo '</tr>';
echo '</table>';
}
else if ($result[$i][$j]=="&")
{
echo '<img src="images/arbre_ligneH.gif" border="0"align="center" width="260" height="80">';
}
echo "</TD>";
if($j!=$nbtour-1) // si on est pas au dernier tour dessine les dessins de liaison dans une nouvelle colonne
{
echo "<td align=center width=25 valign=middle>";
if($result[$i][$j]!="" && $result[$i+$espace_v+1][$j+1]!="") // si match et la case diagonale vers le bas(avec espace_v pris encompte) y a match aussi alors coin haut
{
//echo '<td background="images/arbre_coinhaut.gif" style="background-repeat: no-repeat;background-position: bottom;"></td>';
echo '<img src="images/arbre_coinhaut.gif" border="0" width="25" height="110" align="center">';
}
else if($result[$i][$j]!="" && $result[$i-$espace_v-1][$j+1]!="")// si match et la case diagonale vers le haut(avec espace_v pris encompte) y a match aussi alors coin bas
{
//echo '<td background="images/arbre_coinbas.gif" style="background-repeat: no-repeat;background-position: top;"></td>';
echo '<img src="images/arbre_coinbas.gif" border="0" align="center" width="25" height="110" >';
}
if (($result[$i][$j+1]!=""))// && ($result[$i-$espace_v-1][$j]!="") && ($result[$i+$espace_v+1][$j]!=""))
echo '<img src="images/arbre_T.gif" border="0"align="center" width="25" height="110">';// background="images/arbre_ligneV.gif"
//if (($result[$i+1][$j+1]!=""))// && ($result[$i-$espace_v-1][$j]=="") && ($result[$i+$espace_v+1][$j]!=""))
// echo '<img src="images/arbre_T.gif" border="0" align="center" width="25" height="80" >';
/*if (($result[$i][$j+1]!="") && ($result[$i-$espace_v-1][$j]!="") && ($result[$i+$espace_v+1][$j]==""))
echo '<img src="images/arbre_T.gif" border="0" align="center" width="25" height="80" >';*/
else
{
$flag=false; // boucle pour ecrire les barre verticale
for($k=0;$k<$espace_v;$k++)
{
if($result[$i-$k-1][$j+1]!="" || $result[$i+$k+1][$j+1]!="")
{
echo '<img src="images/arbre_ligneV.gif" border="0" align="center" width="25" height="110" >';
//echo '<td></td>';
$flag=true;
}
}
if(!$flag)
echo '&nbsp;';
}
echo "</td>";
}
else
echo '<td></TD>';
}
echo "</TR>";
}
}
echo "</TABLE>";
}
$tab_traite=calculTab($tab,$result,$time,$long_premier_tour,$nb_tour);
//$tab_traite=ligneVide($tab_traite,$long_premier_tour,$nb_tour);
echo"<input type='button' value='Imprimer' name='Imprimer' OnClick='javascript:window.print()'>";
printTab($tab_traite,$long_premier_tour,$nb_tour);
?>