<?php

$T_INFOS = v('T_INFOS');
$T_EQI = $T_INFOS['T_EQI'];
$T_MAT = $T_INFOS['T_MAT'];
$tPoules = v('tPoules');

$EN_TOURNOI = $T_MAT['MAT_TYPE'] == 1;

$url_referer = href('',array('controleur'=>'tournoi','action'=>'voir','params'=>$T_MAT['TNS_CLE']),false,true);
if ( $T_MAT['TNS_TYPE'] == 5 ){
	$url_referer = href('',array('controleur'=>'ladder','action'=>'voir','params'=>$T_MAT['TNS_CLE']),false,true);
}

if ( p('impression') == 1 ){
	$date = $T_MAT['MAT_DATE']=='00/00/0000'?'A d&eacute;finir':$T_MAT['MAT_DATE'];
	$heure = $T_MAT['MAT_HEU']=='00:00:00'?'A d&eacute;finir':$T_MAT['MAT_HEU'];
	$tEqi = v('tEqi');
	$tEqi1 = $tEqi['EQ1'];
	$tEqi2 = $tEqi['EQ2'];

	ob_end_clean();
	loadClass('fpdf');
	$pdf=new FPDF();
	$pdf->AddPage();
	$pdf->Image(DIR_APP_CACHE.'A4_fiche_score_header.jpg',0,10,210,30);
	$pdf->SetFont('Arial','B',16);
	/* Nom tournoi */
	$pdf->SetY(30);
	//$pdf->SetX(50);
	$pdf->Cell(0,10,utf8_decode($T_MAT['TNS_NOM']),0,0,'C');

	/* Infos sur tour, poule, date, heure */
	$pdf->Ln(15);
	$pdf->SetFillColor(225,225,225);
	$pdf->SetFont('Arial','',14);
	$pdf->Cell(0,10,'Tour : '.$T_MAT['MAT_TOUR'].'    Poule : '.$T_MAT['MAT_POU'].'                                    Date : '.$date.'             Heure : '.$heure,0,0,'L',true);

	/* Nom des equipes */
	$pdf->Ln(15);
	$pdf->Cell(90,10,utf8_decode($T_EQI['EQ1']['EQI_NOM']),0,0,'C',1);

	$pdf->SetX(110);
	$pdf->Cell(90,10,utf8_decode($T_EQI['EQ2']['EQI_NOM']),0,0,'C',1);
	$pdf->Ln(15);

	/* Tableau des joueurs */
	$max = sizeof($tEqi1)>=sizeof($tEqi2)?sizeof($tEqi1):sizeof($tEqi2);
	$max = $max>$T_MAT['TNS_NB_J']?$max:$T_MAT['TNS_NB_J'];
	if ( $max > 0 ){
		for($i=0;$i<$max;$i++){
			$tJ1 = isset($tEqi1[$i])?utf8_decode($tEqi1[$i]['JOU_LOGIN']):'';
			$tJ2 = isset($tEqi2[$i])?utf8_decode($tEqi2[$i]['JOU_LOGIN']):'';
			$y = $pdf->GetY();
			$x = $pdf->GetX();

			$pdf->SetY($y+2.5);
			$pdf->SetX($x+2.5);
			$pdf->Cell(5,5,'',1,0,'C');
			$pdf->SetX(112.5);
			$pdf->Cell(5,5,'',1,0,'C');
			$pdf->SetY($y);
			$pdf->SetX(10);

			$pdf->Cell(90,10,$tJ1,1,0,'C');
			$pdf->SetX(110);
			$pdf->Cell(90,10,$tJ2,1,0,'C');
			$pdf->Ln(10);
		}
	}

	$pdf->Ln(5);
	if ( is_object($T_MAT['MAT_DETAILS']) ){
		$o = $T_MAT['MAT_DETAILS'];
		$T = $o->getDetails();
		if ( $T !== null && sizeof($T)>0){
			foreach ($T as $un_terrain){
				if (
				!is_array($un_terrain) || sizeof($un_terrain) == 0 ||
				!isset($un_terrain['t']) || !isset($un_terrain['m'])
				){ continue; }

				$pdf->Cell(80,10,$un_terrain['t'],0,0,'C',1);
				$pdf->Ln(10);

				foreach ($un_terrain['m'] as $i=>$v){
					$pdf->SetFont('Arial','',10);
					$pdf->Cell(20,8,'Round '.($i+1),1,0,'C');
					$pdf->SetX(30);
					$pdf->Cell(85,8,$v[0],1,0,'C');
					$pdf->SetX(115);
					$pdf->Cell(85,8,$v[1],1,0,'C');
					$pdf->Ln(8);
				}
				$pdf->Ln(5);
				$pdf->SetFont('Arial','',14);

			}
		}
	}



	/* Zone signature */
	$pdf->SetFont('Arial','',10);
	$pdf->SetY(225);
	$pdf->SetX(6);
	$largeur_signature = 64;
	$pdf->Cell($largeur_signature,5,'Signature '.utf8_decode($T_EQI['EQ1']['EQI_NOM']),1,0,'C');
	$pdf->SetX(72);
	$pdf->Cell($largeur_signature,5,'Signature Administrateur',1,0,'C');
	$pdf->SetX(138);
	$pdf->Cell($largeur_signature,5,'Signature '.utf8_decode($T_EQI['EQ2']['EQI_NOM']),1,0,'C');

	$pdf->Ln(5);
	$pdf->SetX(6);
	$pdf->Cell($largeur_signature,25,'',1,0,'C');$pdf->SetX(72);
	$pdf->Cell($largeur_signature,25,'',1,0,'C');$pdf->SetX(138);
	$pdf->Cell($largeur_signature,25,'',1,0,'C');

	/* Footer */
	$pdf->Image(DIR_APP_CACHE.'A4_fiche_score_footer.jpg',0,260,210,34.05);

	$pdf->Output();
	die();
}


	?>
	<style type="text/css" media="all">
		
		#rentrerscores {
			margin: 10px auto !important;
			border: 1px solid black;
			font-size: 12px;
			width: 100%;
		}
		
		#rentrerscores input {
			text-align:center;
		}
		
		#tabs-score {
			margin: 10px !important;
}
		
		.scores {
			
		}
		
		#rentrerscores tr.une_eq td.nom {
			border-bottom: 1px solid black;
			padding: 0px 5px;
		}
		#rentrerscores tr.une_eq td.score {
			text-align: center;
			border-bottom: 1px solid black;
		}
		#rentrerscores tr.une_eq td.score input {
			margin: 0 auto;
		}
		#rentrerscores tr.une_eq td.score input:focus {
			border:1px inset orange;
			background: yellow;
		}
		
		td.infos {
			padding-left: 10px;
		}
		.sai {
			background: #eeeeee;
			padding: 3px;
		}
		.sai input {
			position: relative;
			border: 1px ridge black;
			margin: 0px 5px;
		}
		.date_heu input {
			width: 45%;
		}
		input.date {
		
		}
		
		.un_jeu {
			width: 100% !important;
		}
		#btn-fermer {
			position: absolute;
			top: 6px; right: 6px;
			z-index: 1000;
			border: 0px none !important;
		}
		
		.com-content, #tabs-score {
			width: 530px;
		}
		
		.com-content {
			height: 400px;
			overflow:hidden; 
			overflow-x: hidden; 
			overflow-y: auto; 
			overflow : -moz-scrollbars-vertical; 
			padding: 10px !important;
			float: left;
		}

		.com-block {
			text-align: left;
			border-bottom: 1px dashed #ccc;
			font-size: 12px;
			margin-top: 10px;
		}
		
		.com-auteur {
				
		}
		
		.com-date {
			font-style: italic;
		}
		.com-block p {
			padding: 10px;
		}
		.com-content textarea {
			width: 100%;
			height: 40px;
			font-size: 12px !important;
			margin: 10px auto;
		}
		.com-content form {
			text-align: right;
		}
		.com-content input[type=submit] {
			margin: 0px;
		}

.manche {
    border-top: 1px solid #ccc;
    border-bottom: 1px solid #ccc;
}
.manche .premier, .manche .score, .total_scores .premier, .total_scores .score {
    width: 33%;
    text-align: center;
}
.com-content h2 {
    font-weight: 200;
    text-align: center;
    margin: 0px;
    font-size: 2em;
}

    #ajax-content .nav-tabs {
        margin: 0px;
    }
		<?php if ( v('impression') == 1 ) { ?>
		</style>
		<?php echo v('css'); ?>
		<style type="text/css">
		/* Styles pour l'impression */
		tr.nom_equipe td {
			border-bottom: 1px solid black;
			border-top: 1px solid black;
			height: 25px;
			font-size: 14px;
			text-align:center;
			background: #eaeaea;
		}
		td.sai {
			border-right: 1px solid black;
		}
		a img {
			border: 0px none;
		}
		a {
			text-decoration: none;
			color: black;
		}
		table.feuilleMatch {
			width: 400px;
		}
		table.feuilleMatch tr th.map {
			border-bottom: 0px none;
			padding-left: 10px;
		}
		table.feuilleMatch tr th {
			background: #eee;
			border-top: 1px solid black;
			border-bottom: 1px solid black;
		}
		table.feuilleMatch tr td {
			width: 100px;
			height: 20px;
		}
		table.feuilleMatch tr td.j {
			padding-left: 10px;
		}
		table.feuilleMatch tr td.moitie {
			border-left: 1px solid black;
		}
		table.feuilleMatch tr td.check {
			width: 20px !important;
			text-align: center;
		}
		table.feuilleMatch tr td.check input {
			width: 20px;
			margin: 0px; padding: 0px;
		}
		
		td.score input {
		}
		table_details tr td.score {
			
		}
		table_details tr td input.date {
		
		}
		table_details tr td input.tier {
		
		}
		table_details tr td input.score {
		
		}
		table_details tr td input.map {
		
		}
		div.jeu {
			margin: 10px 0px;
		}
		div.jeu table {
			width: 100%;
		}
		div.jeu table tr th {
			font-size: 14px;
			font-weight: normal;
			background: #eeeeee;
		}
		table.un_jeu tr td.score {
			
		}
		tr.aj td {
			font-size: 11px;
			text-align: center;
		}
		tr.details {
			display: none;
		}
		input.radio {
			display: inline;
			width: 20px;
			margin: 0px; padding: 0px;
		}

            .manche .premier, .manche .score {
                width: 33%;
            }

		
		<?php } ?>
		
	</style>
	
	<div id="tabs-feuille">
		<ul id="mes-tabs" class="nav nav-tabs">
			<li class="active"><a href="#tabs-score" data-toggle="tab">score</a></li>
            <?php if ( is_logued() ) { ?>
			<li><?php echo href(sprintf(__('com.nb_com'),v('nbComs')),array('controleur'=>'tabcommentaires','action'=>'match','params'=>$T_MAT['MAT_CLE'],'class'=>'mes-com', 'data-toggle'=>'tabajax','data-target'=>'#tabs-coms')); ?></li>
			<?php } ?>
            <li><?php echo href(__('com.fichiers'),array('controleur'=>'tabfichiers','action'=>'match','params'=>$T_MAT['MAT_CLE'],'class'=>'mes-com', 'data-toggle'=>'tabajax','data-target'=>'#tabs-fichiers')); ?></li>
			<li><?php echo href(ucfirst(__('com.txt.joueurs')),array('controleur'=>'tournoi','action'=>'roster','params'=>$T_MAT['MAT_CLE'],'class'=>'mes-com', 'data-toggle'=>'tabajax','data-target'=>'#tabs-roster')); ?></li>
		</ul>

        <div class="tab-content">
		<div id="tabs-coms" class="tab-pane"></div>
		<div id="tabs-roster" class="tab-pane"></div>
		<div id="tabs-fichiers" class="tab-pane"></div>
		<div id="tabs-score" class="tab-pane active">

	
	<table id="rentrerscores" cellpadding="0" cellspacing="0" border="<?php echo v('impression')==1?'1':'0'; ?>">
		<tr>
			<td colspan="2" class="sai" style="border-bottom: 1px solid black;text-align:center">
			Tour : <?php echo $T_MAT['MAT_TOUR']; ?>&nbsp;-&nbsp;Poule : <?php echo isset($tPoules[$T_MAT['MAT_POU']])?eregi_replace('poule ','',$tPoules[$T_MAT['MAT_POU']]['nom']):$T_MAT['MAT_POU']; ?>
			</td>
		</tr>
		<?php if ( $T_MAT['MAT_ETAT'] == 2 ){ ?>
		
		<tr>
			<td colspan="2" class="sai" >
				<h3><?php echo zk_etat_match($T_MAT['MAT_ETAT']); ?></h3>
			</td>
		</tr>
		<?php } ?>
		<tr>
			<td colspan="2" class="infos"><br /><?php echo __('com.txt.lieu'); ?> :</td>
		</tr>
		<tr>
			<td colspan="2" class="sai" align="center"><?php echo $T_MAT['MAT_LIEU']==''?(v('impression')==1?'':'A d&eacute;finir'):$T_MAT['MAT_LIEU']; ?>&nbsp;</td>
		</tr>
		<tr>
			<td colspan="2" class="infos">Date :</td>
		</tr>
		<tr>
			<td colspan="2" class="sai date_heu" align="center">
			<?php 
			$type = $T_MAT['MAT_ETAT'] != 2 &&
			( $T_MAT['MAT_FLAG'] == 0 && v('peut_gerer_eqi') == 1) ||
			( $T_MAT['MAT_FLAG'] == 1 && v('peut_gerer_eqi') == 2) ||
			( $T_MAT['MAT_FLAG'] == 2 && v('peut_gerer_eqi') == 1)
			?"text":"hidden";
			?><input type="<?php echo $type; ?>" name="MAT_DATE" id="MAT_DATE" value="<?php echo $T_MAT['MAT_DATE']; ?>" /><?php
			?><input type="<?php echo $type; ?>" name="MAT_HEU" id="MAT_HEU" value="<?php echo $T_MAT['MAT_HEU']; ?>" /><?php
			if ( $type == 'hidden' ){
				echo date_et_time_fr($T_MAT['MAT_DATE_ORIGINE']);
			}
			?>
			</td>
		</tr>
		<?php if ( v('impression') == 1 ){ ?>
		
		<tr>
			<td colspan="2" align="center">
			<br />
			<table class="feuilleMatch" cellpadding="0" cellspacing="0">
				<?php $tEqi = v('tEqi');
				$tEqi1 = $tEqi['EQ1'];
				$tEqi2 = $tEqi['EQ2'];
				$max = sizeof($tEqi1)>=sizeof($tEqi2)?sizeof($tEqi1):sizeof($tEqi2);
				if ( $max > 0 ){
					?>
					<tr class="nom_equipe">
						<td class="j"><?php echo zk_equipe($T_EQI['EQ1'],false); ?></td>
						<td class="check">&nbsp;</td>
						<td class="j"><?php echo zk_equipe($T_EQI['EQ2'],false); ?></td>
						<td class="check">&nbsp;</td>
					</tr>
					<?php
					for($i=0;$i<$max;$i++){
						$tJ1 = isset($tEqi1[$i])?pays($tEqi1[$i]['JOU_PAYS']).' '.$tEqi1[$i]['JOU_LOGIN']:'';
						$tJ2 = isset($tEqi2[$i])?pays($tEqi2[$i]['JOU_PAYS']).' '.$tEqi2[$i]['JOU_LOGIN']:'';
						?>
						<tr>
							<td class="j"><?php echo $tJ1; ?></td>
							<td class="check"><?php echo $tJ1==''?'':'<input type="checkbox" />'; ?></td>
							<td class="j moitie"><?php echo $tJ2; ?></td>
							<td class="check"><?php echo $tJ2==''?'':'<input type="checkbox" />'; ?></td>
						</tr>
						<?php
					}
				} ?>
			</table>
			</td>
		</tr>
		
		<?php } ?>
		<tr class="jeu">
			<td colspan="2">
				<div class="jeu" align="center">
					<?php 
					if ( $T_MAT['MAT_DETAILS'] instanceof MatDetails_Modele ){
						$peut_gerer = $T_MAT['MAT_ETAT'] == 2 ? false : v('peut_gerer_eqi');
						echo $T_MAT['MAT_DETAILS']->editSuivantDroits($peut_gerer,$T_MAT['MAT_FLAG'],zk_equipe($T_EQI['EQ1'],false),zk_equipe($T_EQI['EQ2'],false));
					}
					?>
					<input type="hidden" value="" id="MAT_DETAILS" /></td>
				</div>
			</td>
		</tr>
		<tr>
			<td colspan="2">
				
			</td>
		</tr>
		<?php if ( v('impression') != 1 ) { ?>
		
		<?php
		if ( $T_MAT['MAT_ETAT'] == 0 && v('peut_gerer_eqi') ){
			?>
		<tr>
			<td colspan="2" align="center" style="padding: 5px 0px">
			<?php echo zk_match_infos($T_MAT['MAT_FLAG'],v('peut_gerer_eqi')); ?>
			<form method="post" action="<?php echo php_self(); ?>" target="_blank">
			<?php
			echo zk_btn_gerer_match(v('peut_gerer_eqi'),$T_MAT['MAT_FLAG']);
			?>
			<input type="hidden" name="MAT_DETAILS" id="MAT_DETAILS" value="" />
			<input type="hidden" name="majRencontreParEquipe" value="1" />
			</form>
			
			</td>
		</tr>
		<?php
		}
		?>	
		<tr>
			<td colspan="2" align="center" style="padding: 5px 0px">
			<form method="post" action="<?php echo php_self(); ?>" target="_blank">
			<input type="button" id="BTN_ANNULE" name="BTN_ANNULE" value="" class="retour" />
			<input type="hidden" name="impression" value="1" />
			<input type="submit" id="BTN_VAL" name="BTN_VAL" class="imprimer" value="" />
			</form>
			
			</td>
		</tr>
		
		<?php
		} else {
			?>
			<tr>
				<td colspan="2" align="left" style="padding: 5px 5px">
					Signatures
				</td>
			</tr>
			<?php
		}
		?>
	</table>
	</div>
	</div>
	</div>
	<a href="#fermer" title="Fermer" id="btn-fermer" ><?php echo img('icons/cross.png'); ?></a>
	
	<?php if ( v('impression') == 1 ){ ?>
	<script type="text/javascript">
	<!--
	window.print();
	-->
	</script>

	<?php } else { ?>
	<script type="text/javascript">
	<!--

	$(function(){
        $('#mes-tabs a').click(function (e) {
            e.preventDefault();
            $(this).tab('show');
        });

		function edition()
		{
			options = "Width=600,Height=700" ;
			window.open("<?php echo php_self(); ?>", "edition", options ) ;
		}

		<?php
		if ( $T_MAT['MAT_DETAILS'] instanceof MatDetails_Modele ){
			echo $T_MAT['MAT_DETAILS']->getJsUtilisateur();
		}
		?>

		$('#BTN_ANNULE').click(function(){
			closeModal();
		});

		<?php

		if ( v('peut_gerer_eqi') > 0 ){
			if ( $T_MAT['MAT_DETAILS'] instanceof MatDetails_Modele ){
				echo $T_MAT['MAT_DETAILS']->getJsManager();
			}  ?>

			maj_infos = function(from){
				prepare();
				$.ajax({
					type: "POST",
					url: "<?php echo php_self(); ?>",
					data: "FROM="+from+"&EQI_S1="+escape($("#EQI_S1").val())+"&EQI_S2="+escape($("#EQI_S2").val())+"&MAT_DATE="+escape($("#MAT_DATE").val())+"&MAT_HEU="+escape($("#MAT_HEU").val())+"&MAT_LIEU="+escape($("#MAT_LIEU").val())+"&MAT_FLAG="+escape($("#MAT_FLAG").val())+"&MAT_ETAT="+escape($("#MAT_ETAT").val())+$("#MAT_DETAILS").val(),
					success: function(msg){
						if ( jQuery.trim(msg) == "OK" ){
							if (typeof $.unblockUI !== "undefined" && $.unblockUI !== null) {
							    $.unblockUI();
							} else {
							    closeModal();
							}
							$(location).attr('href',"<?php echo $url_referer; ?>");
						} else {
							alert("ERREUR : "+msg);
						}
					}
				});
			}
			<?php
		}
		?>

	});
	-->
	</script>
<?php
	}
?>