<?php
$tRenc = v('PM_tRenc');
if ( sizeof($tRenc) == 0 ){
	?><p><?php echo __('com.txt.aucun_match_prevu'); ?></p><?php
} else {
	?>

	<table cellspacing="20" align="center" width="<?php echo sizeof($tRenc)==1?60:100; ?>%" >
	<tr>
		
		<?php
		foreach ($tRenc as $etat=>$renc){
			if ( sizeof($renc) == 0 || $etat == 2 ){continue; }
			?><td class="pageLesMatchsCol">
				<h2><?php echo zk_etat_match($etat); ?></h2>
				<table class="listeMatchs blocListeMatchs pageLesMatchs table-css table-css-noborder" id="ListeMatchsLadder" border="0" cellspacing="0" cellpadding="0" align="center">
		

						
			<?php
			$ancien_etat = null;
			$ancien_tour = null;
			$changement_tour = false;
			$alterne = false;
			foreach ($renc as $UN_MAT){
				$changement_tour = false;
				if ( $ancien_tour == null ){
					$changement_tour = true;
					$ancien_tour = $UN_MAT['MAT_TOUR'];
				} else if ( $ancien_tour != $UN_MAT['MAT_TOUR'] ){
					$changement_tour = true;
					$ancien_tour = $UN_MAT['MAT_TOUR'];
				}
				if ( $etat == 1 ){
					$c1 = $UN_MAT['EQI_S1']!=''&&$UN_MAT['EQI_S2']!=''?($UN_MAT['EQI_S1']==$UN_MAT['EQI_S2']?'egalite':($UN_MAT['EQI_S1']>$UN_MAT['EQI_S2']?'gagnant':'perdant')):'';
					$c2 = $UN_MAT['EQI_S1']!=''&&$UN_MAT['EQI_S2']!=''?($UN_MAT['EQI_S1']==$UN_MAT['EQI_S2']?'egalite':($UN_MAT['EQI_S1']<$UN_MAT['EQI_S2']?'gagnant':'perdant')):'';
				} else {
					$c1 = null;
					$c2 = null;
				}
				$eq1 = array('EQI_CLE'=>$UN_MAT['EQI_CLE1'],'EQI_TAG'=>$UN_MAT['EQI_TAG1'],'EQI_NOM'=>$UN_MAT['EQI_NOM1'],'EQI_LOGO'=>$UN_MAT['EQI_LOGO1']);
				$eq2 = array('EQI_CLE'=>$UN_MAT['EQI_CLE2'],'EQI_TAG'=>$UN_MAT['EQI_TAG2'],'EQI_NOM'=>$UN_MAT['EQI_NOM2'],'EQI_LOGO'=>$UN_MAT['EQI_LOGO2']);
				
				if ( $changement_tour ){
					?>
					<tr>
					<td colspan="6" class="sep-matchs tac"><?php echo __('com.txt.jour'); echo ' '.$UN_MAT['MAT_TOUR']; ?></td>
					</tr>
					<?php	
				}
				
				?>
				<tr>
					<td><?php echo href(img('icons/calendar.png'),array('controleur'=>'Tournoi','action'=>'Rencontre','params'=>$UN_MAT['TNS_CLE'].'-'.$UN_MAT['MAT_CLE'].'-'.$UN_MAT['EQI_CLE1'].'-'.$UN_MAT['EQI_CLE2'],'class'=>'equipe','class'=>'ajax'),false,false,false); ?></td>
					<td class="date"><?php echo date_et_time_fr($UN_MAT['MAT_DATE']);?></td>
					<td class="tac"><?php echo zk_eq_tn($eq1);?></td>
					<?php
					if ( $etat >= 1 ){
						?>
						<td class="score <?php echo $c1; ?>"><?php echo $UN_MAT['EQI_S1'];?></td>
						<td class="score <?php echo $c2; ?>"><?php echo $UN_MAT['EQI_S2'];?></td>
						<?php
					} else { 
						?>
						<td colspan="2" class="tac"><?php echo __('com.table.vs'); ?></td>
						<?php
					}
					?>
					<td class="tac"><?php echo zk_eq_tn($eq2);?></td>
				</tr>
				<?php

			}
			?>
		</table>
		</td>
		<?php
		}
		?>
		</tr>
	</table>
	
	<?php
}
?>