<?php
$UN_TNS = v('P_TNS');
$T_EQI = v('T_EQI');
$T_RENC = v('T_RENC');
$tPoules = v('tPoules');
$der_tour = '';//$T_RENC[0]['MAT_TOUR'];
$der_poule = '';//$T_RENC[0]['MAT_POU'];

$cpt = 0;
if ($UN_TNS['TNS_TYPE'] == 2 || $UN_TNS['TNS_TYPE'] == 3 || $UN_TNS['TNS_TYPE'] == 4 ){
	$der_renc = array_pop($T_RENC);
	$nb_tour =$der_renc['MAT_TOUR'];
	$T_RENC[key($der_renc)] = $der_renc;
	?><h2 align="center"><?php echo __('com.txt.matchs_aller'); ?></h2><?php
}
?>
<table class="listeMatchs blocListeMatchs pageLesMatchs table-css table-css-noborder" style="width: 60% !important" align="center" cellpadding="0" cellspacing="0" border="0">
<?php
foreach ($T_RENC as $MAT){
	$intervention_admin = false;//$MAT['MAT_FLAG']==4||$MAT['MAT_FLAG']==8;
	$clos_mais_a_terminer = false; //$MAT['MAT_FLAG']==9&&$MAT['MAT_ETAT']==0;
	
	$icon = $MAT['MAT_ETAT']==1?img('icons/tick.png'):img('icons/stop.png');
	$icon = $MAT['MAT_ETAT']==2?img('icons/cross_grey.png'):$icon;
	//$icon = $intervention_admin === false ?$icon:img('icons/error.png');
	//$icon = $clos_mais_a_terminer?img('icons/eye.png'):$icon;
	
	if ( zk_est_alert($MAT['MAT_FLAG'],$MAT['MAT_ETAT']) ){
		$icon = img('icons/error.png');
		$intervention_admin = true;
	}
	if ( zk_est_look($MAT['MAT_FLAG'],$MAT['MAT_ETAT']) ){
		$icon = img('icons/eye.png');
		$clos_mais_a_terminer = true;
	}
	
	if ( $MAT['MAT_TOUR'] != $der_tour ){
		//echo $der_tour==''?'':'</table>';

		if ( ($UN_TNS['TNS_TYPE'] == 2 || $UN_TNS['TNS_TYPE'] == 3 || $UN_TNS['TNS_TYPE'] == 4) && ($MAT['MAT_TOUR']-1) == ($nb_tour/2)){
			echo '</table>
			<table class="listeMatchs blocListeMatchs pageLesMatchs table-css table-css-noborder" style="width: 60% !important" align="center" cellpadding="0" cellspacing="0" border="0">
			<h2 align="center">Matchs retour</h2>';
		}

		?>
		
		<tr><td colspan="6" class="sep-matchs tac"><?php echo __('com.txt.jour'); ?> <?php echo $MAT['MAT_TOUR']; ?></td></tr>
		<?php
		$der_tour = $MAT['MAT_TOUR'];
	}
	if ( sizeof($tPoules)>1 && $MAT['MAT_POU'] != $der_poule ){
		?><td colspan="6" class="poule"><?php echo $tPoules[$MAT['MAT_POU']]['nom']; ?></td><?php
		$der_poule = $MAT['MAT_POU'];
		$cpt=0;
	}
	
	if ( $MAT['MAT_ETAT'] == 1 ){
		$c1 = $MAT['EQI_S1']!=''&&$MAT['EQI_S2']!=''?($MAT['EQI_S1']==$MAT['EQI_S2']?'egalite':($MAT['EQI_S1']>$MAT['EQI_S2']?'gagnant':'perdant')):'';
		$c2 = $MAT['EQI_S1']!=''&&$MAT['EQI_S2']!=''?($MAT['EQI_S1']==$MAT['EQI_S2']?'egalite':($MAT['EQI_S1']<$MAT['EQI_S2']?'gagnant':'perdant')):'';
	} else {
		$c1 = '';
		$c2 = '';
		$MAT['EQI_S1'] = '&nbsp;';
		$MAT['EQI_S2'] = '&nbsp;';
	}
	
	?>
	<tr class="<?php echo $cpt++%2==0?'pair':'impair'; echo ' '; echo ($MAT['MAT_ETAT']==1||$MAT['MAT_ETAT']==2)?'':($MAT['MAT_FLAG']==9?'a_valider':($MAT['EQI_S1']!=0||$MAT['EQI_S2']!=0?'a_valider':'a_jouer')); echo $intervention_admin?' alert':''; echo $clos_mais_a_terminer?' look':''; echo $MAT['MAT_ETAT']==2?'non_joue':''; ?>">
		<td class="small s"><?php echo href($icon,array('controleur'=>'[[controleur]]','action'=>'[[action]]','params'=>'[[params_'.$MAT['TNS_CLE'].'-'.$MAT['MAT_FP'].']]','class'=>'equipe ajax'),false,false,false); ?></td>
		<td class="eq"><?php echo zk_eq_tn($T_EQI[$MAT['EQI_CLE1']],false); ?></td>
		<td class="small s <?php echo $c1; ?>" ><?php echo $MAT['EQI_S1']; ?></td>
		<td class="small s <?php echo $c2; ?>" ><?php echo $MAT['EQI_S2']; ?></td>
		<td class="eq"><?php echo zk_eq_tn($T_EQI[$MAT['EQI_CLE2']],false); ?></td>
	</tr>
	<?php
}
?>
</table>
<div class="clean"></div>
