<h2><?php
echo __ ( 'adm.ta.titre' );
?></h2>

<?php
$TNS = v ( 'TNS' );
$etape = v ( 'etape' );

$tournois = getTournoisSpeciaux ();
if ($TNS ['TNS_TYPE'] == 7) {
	array_unshift ( $tournois, array ('nom' => 'aucun', 'value' => '0' ) );
}
$tMontrer = array ('TNS_NOM' => 1, 'TNS_TYPE' => 1, 'TNS_JEU' => 1, 'TNS_NB_J' => 1 );

if ($etape > 1) {
	$tMontrer ['TNS_NOM'] = 0;
	$tMontrer ['TNS_TYPE'] = 0;
	$tMontrer ['TNS_JEU'] = 0;
	$tMontrer ['TNS_NB_J'] = 0;
	$tMontrer ['REG_CLE'] = 1;
	$tMontrer ['TNS_DIR'] = 1;
	$tMontrer ['TNS_NB_M'] = 1;
	$tMontrer ['TNS_NB_T'] = 1;
	$tMontrer ['TNS_MAT_FLAG'] = 1;
	$tMontrer ['TNS_VAL_ADM'] = 1;

	if (p ( 'TNS_TYPE' ) == 2 || p ( 'TNS_TYPE' ) == 3 || p ( 'TNS_TYPE' ) == 4 || p ( 'TNS_TYPE' ) == 7) {
		//$tMontrer['TNS_NB_EQ_EVT'] = 1;
		//$tMontrer['TNS_NB_EQ_TNS'] = 1;
		if (p ( 'TNS_TYPE' ) == 3) {
			unset ( $tMontrer ['TNS_NB_EQ_TNS'] );
			unset ( $tMontrer ['TNS_DIR'] );
		}
	}
	
	if ($etape > 2) {
		if (p ( 'TNS_DIR' ) == '') {
			$tMontrer ['TNS_LB'] = 1;
		}
		if (p ( 'TNS_NB_EQ_TNS' ) == 6) {
			unset ( $tMontrer ['TNS_LB'] );
		}
		$tMontrer ['REG_CLE'] = 0;
		$tMontrer ['TNS_DIR'] = 0;
		$tMontrer ['TNS_NB_M'] = 0;
		$tMontrer ['TNS_NB_T'] = 0;
		$tMontrer ['TNS_MAT_FLAG'] = 0;
        $tMontrer ['TNS_VAL_ADM'] = 0;
		
		if (p ( 'TNS_TYPE' ) == 2 || p ( 'TNS_TYPE' ) == 3 || p ( 'TNS_TYPE' ) == 4 || p ( 'TNS_TYPE' ) == 7) {
			//$tMontrer['TNS_NB_EQ_EVT'] = p('TNS_TYPE')==3?1:0;
			if (p ( 'TNS_TYPE' ) == 2 || p ( 'TNS_TYPE' ) == 3 || p ( 'TNS_TYPE' ) == 4 || p ( 'TNS_TYPE' ) == 7) {
				$tMontrer ['TNS_NB_EQ_TNS'] = 1;
			} else {
				$tMontrer ['TNS_NB_EQ_TNS'] = 0;
			
			}
			$tMontrer ['TNS_DIR'] = 0;
			//$tMontrer['TNS_NB_POU'] = 1;
			

			$tMontrer ['TNS_G'] = 1;
			$tMontrer ['TNS_N'] = 1;
			$tMontrer ['TNS_D'] = 1;
			
			if (p ( 'TNS_TYPE' ) == 3) {
				unset ( $tMontrer ['TNS_NB_EQ_TNS'] );
				unset ( $tMontrer ['TNS_DIR'] );
				unset ( $tMontrer ['TNS_LB'] );
			}
			if (p ( 'TNS_TYPE' ) == 4) {
				//unset($tMontrer['TNS_NB_POU']);
			}
		
		}
		
		if ($etape > 3) {
			//if ( isset($tMontrer['TNS_NB_POU'])) { $tMontrer['TNS_NB_POU'] = 0; }
			if (isset ( $tMontrer ['TNS_LB'] )) {
				$tMontrer ['TNS_LB'] = 0;
			}
			if (isset ( $tMontrer ['TNS_NB_EQ_TNS'] )) {
				$tMontrer ['TNS_NB_EQ_TNS'] = 0;
			}
			//if ( isset($tMontrer['TNS_NB_EQ_EVT'])){ $tMontrer['TNS_NB_EQ_EVT'] = 0; }
			if (isset ( $tMontrer ['TNS_G'] )) {
				$tMontrer ['TNS_G'] = 0;
			}
			if (isset ( $tMontrer ['TNS_N'] )) {
				$tMontrer ['TNS_N'] = 0;
			}
			if (isset ( $tMontrer ['TNS_D'] )) {
				$tMontrer ['TNS_D'] = 0;
			}
		
		} else {
		
		}
	} else {
	
	}
	
	if ($etape > 2 && p ( 'TNS_TYPE' ) != 3) {
		if (p ( 'TNS_DIR' ) == '') {
			$tMontrer ['TNS_NB_EQ_TNS'] = $etape >= 4 ? 0 : 1;
		} else {
			$tMontrer ['TNS_NB_EQ_TNS'] = 0;
		}
	}
	
	if (p ( 'TNS_TYPE' ) == 7 && p ( 'TNS_DIR' ) == 0) {
		unset ( $tMontrer ['TNS_NB_EQ_TNS'] );
	}
}

?>
<form action="<?php
echo php_self ();
?>" method="post"
	name="ajouter_tournoi" id="ajouter_tournoi"><input type="hidden"
	name="etape" value="<?php
	echo $etape;
	?>" />
<table class="table-css table-css-noborder">
	<?php
	if (v ( 'erreur' )) {
		?>
	<tr>
		<td colspan="2" class="erreurs"><?php
		echo display_erreurs ();
		?></td>
	</tr>
	<?php
	}
	?>

	<tr>
		<td colspan="2">
		<h2 align="right"><?php
		echo __ ( 'adm.ta.etape' );
		?> : <?php
		echo $etape;
		echo __ ( 'adm.ta.4' );
		?></h2>
		</td>
	</tr>
	<?php
	if (isset ( $tMontrer ['TNS_NOM'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.nom' );
		?></td>
		<td class="d"><?php
		if (! $tMontrer ['TNS_NOM']) {
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_NOM' ) );
			echo p ( 'TNS_NOM' );
		} else {
			echo form ( 'input', array ('type' => 'text', 'maxlength' => 30, 'name' => 'TNS_NOM' ) );
		}
		?>
		</td>
	</tr>
	<?php
	}
	?>
	<tr>
		<td class="g"><?php
		echo __ ( 'com.txt.type' );
		?></td>
		<td class="d">
			<?php
			$disabled = array ();
			if (! $tMontrer ['TNS_TYPE']) {
				$disabled = array ('disabled' => 'disabled' );
				echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_TYPE' ) );
			}
			echo formSelect ( 'TNS_TYPE', $disabled, v ( 'tTypesTournoi' ) );
			?>
		</td>
	</tr>

	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.nb_j' );
		?></td>
		<td class="d">
		<?php
		if (! $tMontrer ['TNS_JEU']) {
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_NB_J' ) );
		}
		?>
		<select name="TNS_NB_J"
			<?php
			echo ! $tMontrer ['TNS_NB_J'] ? 'disabled="disabled"' : '';
			?>>
			<?php
			for($i = 1; $i <= __TNS_NB_J_MAX; ++ $i) {
				?><option value="<?php
				echo $i;
				?>"
				<?php
				echo $i == $TNS ['TNS_NB_J'] ? 'selected="selected"' : '';
				?>><?php
				echo $i;
				?></option><?php
			}
			?>
		</select></td>
	</tr>

	<tr>
		<td class="g"><?php
		echo __ ( 'com.txt.jeu' );
		?></td>
		<td class="d"><?php
		$disabled = array ();
		if (! $tMontrer ['TNS_JEU']) {
			$disabled = array ('disabled' => 'disabled' );
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_JEU' ) );
		}
		echo formSelect ( 'TNS_JEU', $disabled, v ( 'tJeux' ), false, true );
		?></td>
	</tr>
	
	<?php
	if (isset ( $tMontrer ['TNS_MAT_FLAG'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.gest_eq' );
		?></td>
		<td class="d"><?php
		$disabled = array ();
		if (! $tMontrer ['TNS_MAT_FLAG']) {
			$disabled = array ('disabled' => 'disabled' );
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_MAT_FLAG' ) );
		}
		echo formSelect ( 'TNS_MAT_FLAG', $disabled, v ( 'tMatchFlagsSimplifies' ) );
		?></td>
	</tr>
	<?php
	}
	?>

    <?php
	if (isset ( $tMontrer ['TNS_VAL_ADM'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo 'Validation admin requise pour chaque match';
		?></td>
		<td class="d"><?php
		$disabled = array ();
		if (! $tMontrer ['TNS_VAL_ADM']) {
			$disabled = array ('disabled' => 'disabled' );
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_VAL_ADM' ) );
		}
		echo formSelect ( 'TNS_VAL_ADM', $disabled, v ( 'tOuiNon' ) );
		?></td>
	</tr>
	<?php
	}
	?>

	<?php
	if (isset ( $tMontrer ['TNS_NB_T'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.nb_t' );
		?></td>
		<td class="d"><?php
		$disabled = array ();
		if (! $tMontrer ['TNS_NB_T']) {
			$disabled = array ('disabled' => 'disabled' );
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_NB_T' ) );
		}
		echo formSelect ( 'TNS_NB_T', $disabled, getListeNombre ( 1, 3 ) );
		?></td>
	</tr>
	<?php
	}
	?>
	
	<?php
	if (isset ( $tMontrer ['TNS_NB_M'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.nb_m' );
		?></td>
		<td class="d"><?php
		$disabled = array ();
		if (! $tMontrer ['TNS_NB_M']) {
			$disabled = array ('disabled' => 'disabled' );
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_NB_M' ) );
		}
		echo formSelect ( 'TNS_NB_M', $disabled, getListeNombre ( 1, 10 ) );
		?></td>
	</tr>
	<?php
	}
	?>
	
	
	<?php
	if (isset ( $tMontrer ['REG_CLE'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'com.txt.reglement' );
		?></td>
		<td class="d"><?php
		$disabled = array ();
		if (! $tMontrer ['REG_CLE']) {
			$disabled = array ('disabled' => 'disabled' );
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'REG_CLE' ) );
		}
		echo formSelect ( 'REG_CLE', $disabled, v ( 'ttab_reglements' ) );
		?></td>
	</tr>
	<?php
	}
	?>
	
	
	<?php
	if (isset ( $tMontrer ['TNS_DIR'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.type' );
		?></td>
		<td class="d"><?php
		$disabled = array ();
		//getTournoisSpeciaux
		if (! $tMontrer ['TNS_DIR']) {
			$disabled = array ('disabled' => 'disabled' );
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_DIR' ) );
		}
		echo formSelect ( 'TNS_DIR', $disabled, $tournois );
		?></td>
	</tr>
	<?php
	}
	?>
	
	
	
	<?php
	if (isset ( $tMontrer ['TNS_NB_EQ_EVT'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.nb_eq_part' );
		?></td>
		<td class="d">
			<?php
		if (! $tMontrer ['TNS_NB_EQ_EVT']) {
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_NB_EQ_EVT' ) );
		}
		?>
			<select name="TNS_NB_EQ_EVT"
			<?php
		echo ! $tMontrer ['TNS_NB_EQ_EVT'] ? 'disabled="disabled"' : '';
		?>>
				<?php
		if (p ( 'TNS_TYPE' ) == 3 || p ( 'TNS_TYPE' ) == 4) {
			?><option value="max"
				<?php
			echo $TNS ['TNS_NB_EQ_EVT'] == 'max' ? 'selected="selected"' : '';
			?>><?php
			echo __ ( 'adm.ta.comp.nb_eq_part.toutes' );
			?></option><?php
		}
		
		for($i = 16; $i <= __TNS_NB_EQ_EVT_MAX;) {
			?><option value="<?php
			echo $i;
			?>"
				<?php
			echo $i == $TNS ['TNS_NB_EQ_EVT'] ? 'selected="selected"' : '';
			?>><?php
			echo $i;
			?></option> <?php
			if (p ( 'TNS_TYPE' ) == 3 || p ( 'TNS_TYPE' ) == 4) {
				//Incrémentation par pas de 1
				$i ++;
			} else {
				//Incrémentation
				$i *= 2;
			}
		}
		?>
			</select></td>
	</tr>
	<?php
	}
	?>
	
	<?php
	if (isset ( $tMontrer ['TNS_NB_EQ_TNS'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.nb_eq_fin' );
		?></td>
		<td class="d">
			<?php
		if (! $tMontrer ['TNS_NB_EQ_TNS']) {
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_NB_EQ_TNS' ) );
		}
		?>
			<select name="TNS_NB_EQ_TNS"
			<?php
		echo ! $tMontrer ['TNS_NB_EQ_TNS'] ? 'disabled="disabled"' : '';
		?>>
				<?php
		$nb_eq_tns_dans_for = false;
		for($i = 4; $i <= __TNS_NB_EQ_TNS_MAX; $i *= 2) {
			?><option value="<?php
			echo $i;
			?>"
				<?php
			echo $i == $TNS ['TNS_NB_EQ_TNS'] ? 'selected="selected"' : '';
			?>><?php
			echo $i;
			?></option> <?php
			if (p ( 'TNS_NB_EQ_TNS' ) == $i) {
				$nb_eq_tns_dans_for = true;
			}
		}
		if (! $nb_eq_tns_dans_for && p ( 'TNS_NB_EQ_TNS' ) > 0) {
			?><option value="<?php
			echo intval ( p ( 'TNS_NB_EQ_TNS' ) );
			?>"
				selected="selected"><?php
			echo intval ( p ( 'TNS_NB_EQ_TNS' ) );
			?></option><?php
		}
		?>
			</select></td>
	</tr>
	<?php
	}
	?>
	
	<?php
	if (isset ( $tMontrer ['TNS_G'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.pts.g' );
		?></td>
		<td class="d"><?php
		if (! $tMontrer ['TNS_G']) {
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_G' ) );
			echo p ( 'TNS_G' );
		} else {
			echo form ( 'input', array ('type' => 'text', 'maxlength' => 3, 'name' => 'TNS_G' ) );
		}
		?>
		</td>
	</tr>
	<?php
	}
	?>
	
	<?php
	if (isset ( $tMontrer ['TNS_N'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.pts.n' );
		?></td>
		<td class="d"><?php
		if (! $tMontrer ['TNS_N']) {
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_N' ) );
			echo p ( 'TNS_N' );
		} else {
			echo form ( 'input', array ('type' => 'text', 'maxlength' => 3, 'name' => 'TNS_N' ) );
		}
		?>
		</td>
	</tr>
	<?php
	}
	?>
	
	
	<?php
	if (isset ( $tMontrer ['TNS_D'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.pts.d' );
		?></td>
		<td class="d"><?php
		if (! $tMontrer ['TNS_D']) {
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_D' ) );
			echo p ( 'TNS_D' );
		} else {
			echo form ( 'input', array ('type' => 'text', 'maxlength' => 3, 'name' => 'TNS_D' ) );
		}
		?>
		</td>
	</tr>
	<?php
	}
	?>
	<?php
	if (isset ( $tMontrer ['TNS_NB_POU'] )) {
		$TNS_CHX = v ( 'TNS_CHX' );
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.nb_p' );
		?></td>
		<td class="d">
			<?php
		if (! $tMontrer ['TNS_NB_POU']) {
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_NB_POU' ) );
		}
		?>
			<select name="TNS_NB_POU"
			<?php
		echo ! $tMontrer ['TNS_NB_POU'] ? 'disabled="disabled"' : '';
		?>>
				<?php
		foreach ( $TNS_CHX as $UN_CHX ) {
			if ($UN_CHX ['nb_equipes'] <= 2 || $UN_CHX ['nb_poules'] <= 2) {
				continue;
			}
			?><option value="<?php
			echo $UN_CHX ['nb_poules'];
			?>"
				<?php
			echo $TNS ['TNS_NB_POU'] == $UN_CHX ['nb_poules'] ? 'selected="selected"' : '';
			?>>
					<?php
			echo $UN_CHX ['nb_poules'];
			?> poules de <?php
			echo $UN_CHX ['nb_equipes'];
			?> &eacute;quipes
					</option><?php
		}
		?>
			</select></td>
	</tr>
	<?php
	}
	?>
	
	
	<?php
	if (isset ( $tMontrer ['TNS_LB'] )) {
		?>
	<tr>
		<td class="g"><?php
		echo __ ( 'adm.ta.comp.lb' );
		?></td>
		<td class="d">
			<?php
		$disabled = array ();
		if (! $tMontrer ['TNS_LB']) {
			$disabled = array ('disabled' => 'disabled' );
			echo form ( 'input', array ('type' => 'hidden', 'name' => 'TNS_LB' ) );
		}
		echo formSelect ( 'TNS_LB', $disabled, v ( 'tOuiNon' ) );
		?>
		</td>
	</tr>
	<?php
	}
	?>
	
	<tr>
		<td colspan="2" align="center" style="padding: 15px 0px">
		<?php
		if ($etape > 1) {
			?>
			<input type="submit" name="submit"
			value="<?php
			echo __ ( 'com.action.retour' );
			?>" class="btn" />
			<?php
		}
		?>
			<input type="submit" name="submit"
			value="<?php
			echo $etape == 4 ? __ ( 'com.action.aj' ) : __ ( 'com.action.val' );
			?>"
			class="btn" /></td>
	</tr>


</table>
<p style="text-align: center"><?php
echo __ ( 'adm.ta.txt' );
?></p>

<h2><?php
echo __ ( 'adm.ta.comp.desc' );
?></h2>
<?php
echo runFCKeditor ( 'TNS_DESC', p ( 'TNS_DESC', true),400); ?>

</form>

