<?php

if ( v('err') !== null ){
	$msg = '';
	switch (v('err')){
		case 0:
			$msg = __('adm.err.16');
			break;
		case 1:
			$msg = __('adm.err.17');
			break;
		default:
			$msg = '';
	}
	//On affiche l'erreur et on arrète
	?>
	<h2 class="err"><?php echo $msg; ?></h2>
	<?php
} else {
	//Tout est ok !
	$T_INFOS = v('T_INFOS');
	$T_EQI = $T_INFOS['T_EQI'];
	$T_MAT = $T_INFOS['T_MAT'];
	$_POST['MAT_ETAT'] = $T_MAT['MAT_ETAT'];
	$tPoules = v('tPoules');

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

	if ( eregi("(.*)admin/(.*)",get_referer()) || eregi("(.*)ladder/gestion(.*)",get_referer()) ){
		$url_referer = href('',array('controleur'=>'admin','action'=>'tournoigerer','params'=>$T_MAT['TNS_CLE']),false,true);
		if ( $T_MAT['TNS_TYPE'] == 5 ){
			$url_referer = href('',array('controleur'=>'ladder','action'=>'gestion','params'=>$T_MAT['TNS_CLE']),false,true);
		}
		$url_referer = get_referer();
	} else {
		$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);
		}
	}
	$clos_mais_a_terminer = $T_MAT['MAT_FLAG']==9&&p('MAT_ETAT')==0;
	?>
	<style type="text/css">

        #tabs-feuille #mes-tabs {
            margin-bottom: 0px;
        }

		#rentrerscores label {
            display: inline-block;
        }
		#rentrerscores {
			margin: 10px auto;
			border: 1px solid black;
			font-size: 12px;
			width: 100%;
            line-height: 10px;
		}
		
		#rentrerscores input {
			text-align:center;
		}

        #rentrerscores input[type=text] {
		    line-height: 10px;
            padding: 0px;
            margin: 0px;
        }
		.scores {
			
		}
		
		#rentrerscores tr.une_eq td.nom {
			border-bottom: 1px solid black;
			padding: 0px 5px;
			font-size: 12px;
		}
		#rentrerscores tr.une_eq td.score {
			text-align: center;
			border-bottom: 1px solid black;
		}
		#rentrerscores tr.une_eq td.score input {
			margin: 0 auto;
			width: 40px;
		}
		#rentrerscores tr.une_eq td.score input:focus {
			border:1px inset orange;
			background: yellow;
		}
		
		td.infos {
			padding-left: 10px;
            text-align: center;
		}
		.sai {
			background: #eeeeee;
			padding: 3px;
            text-align: center;
		}
		.sai input {
			position: relative;
			border: 1px ridge black;
			width: 325px;
			margin: 0px 5px;
		}
		td.score input {
			width: 50px;
		}
		td.score {
			width: 50px;
		}
        .manche .score, .total_scores .score {
            width: 30%;
            text-align: center;
            line-height: 20px;
        }
        .manche .edit_score, .total_scores .edit_score {
            width: 100px
        }
		input.date {
			width: 155px;
		}
		input.tier {
			width: 100px;
		}
		input.score {
			width: 30px;
		}
		input.map {
			width: 100px;
		}
		div.jeu {
			margin: 10px 0px;
		}
		div.jeu table {
			width: 100%;
		}
		div.jeu table tr th {
			font-size: 14px;
			font-weight: normal;
			background: #eeeeee;
		}
		tr.aj td {
			font-size: 11px;
			text-align: center;
		}
		tr.details {
			display: none;
		}
		input.radio {
			display: inline;
			width: 20px;
			margin: 0px; padding: 0px;
		}
		#btn-fermer {
			position: absolute;
			top: 6px; right: 6px;
			z-index: 1000;
		
		}
		
		#tabs-score {
			padding: 10px !important;
		}
		
		.ui-state-active a:hover {
			color: orange;
		}
		.ui-state-active a, .ui-state-hover a {
			color: orange !important;
		
		}
		.ui-state-default a {
			
		}
		#box_ui .ui-tabs-panel {
			background: white !important;
			padding: 0px !important;
		}
		
		.blockPage {
			border: 0px none !important;
			background: none !important;
		}
		
		.com-content, #tabs-score {
			/*width: 520px;*/
		}
		
		.com-content {
			background: white;
			height: 400px;
			overflow:hidden; 
			overflow-x: hidden; 
			overflow-y: auto; 
			overflow : -moz-scrollbars-vertical; 
			padding: 10px !important;
		}
		.com-content h2 {
			font-size: 2em;
		}
		.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;
        }
		
	</style>
	
	<div id="tabs-feuille">
		<ul id="mes-tabs" class="nav nav-tabs">
			<li class="active"><a href="#tabs-score" data-toggle="tab"><?php echo __('com.score'); ?></a></li>
			<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>
			<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>
			<?php if ( $T_MAT['TNS_TYPE'] == '1' ) { ?>
            <li><?php echo href('+',array('controleur'=>'tournoi','action'=>'remplacer','params'=>$T_MAT['TNS_CLE'].'-'.$T_MAT['MAT_CLE'].'-'.$T_MAT['EQI_CLE1'].'-'.$T_MAT['EQI_CLE2'], 'data-toggle'=>'tabajax','data-target'=>'#tabs-remplacer')); ?></li>
		    <?php } ?>
        </ul>
        <div class="tab-content" style="background: white">
            <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-remplacer" class="tab-pane"></div>
		<div id="tabs-score" class="tab-pane active">

			<table id="rentrerscores" cellpadding="0" cellspacing="0">
				<colgroup>
					<col class="nom_eq" />
					<col class="scores" />
				</colgroup>
				<tr>
					<td colspan="2" class="sai" style="border-bottom: 1px solid black">
					<input type="text" class="date" disabled="disabled" value="<?php echo __('com.txt.tour'); ?> : <?php echo $T_MAT['MAT_TOUR']; ?>" />
					<input type="text" class="date" disabled="disabled" value="<?php echo __('com.txt.poule'); ?> : <?php echo isset($tPoules[$T_MAT['MAT_POU']])?eregi_replace('poule ','',$tPoules[$T_MAT['MAT_POU']]['nom']):$T_MAT['MAT_POU']; ?>" />
					
					</td>
				</tr>
				<tr>
					<td colspan="2" class="infos"><br /><?php echo __('com.txt.lieu'); ?> :</td>
				</tr>
				<tr>
					<td colspan="2" class="sai"><input type="text" name="MAT_LIEU" id="MAT_LIEU" value="<?php echo $T_MAT['MAT_LIEU']; ?>" /></td>
				</tr>
				<tr>
					<td colspan="2" class="infos"><?php echo __('com.txt.date'); ?> :</td>
				</tr>
				<tr>
					<td colspan="2" align="center"><input type="text" class="date" maxlength="10" id="MAT_DATE" name="MAT_DATE" value="<?php echo $T_MAT['MAT_DATE']; ?>" /><input type="text" class="date" maxlength="8" id="MAT_HEU" name="MAT_HEU" value="<?php echo $T_MAT['MAT_HEU']; ?>" /></td>
					<!--<div id="datepicker" style="margin-top: 10px;"></div>-->
				</tr>
				<tr class="jeu">
					<td colspan="2">
						<div class="jeu" align="center">
							<?php 
							global $cfg_tMatchFlags;
							$_POST['MAT_FLAG'] = $T_MAT['MAT_FLAG'];
							echo formSelect('MAT_FLAG',array("id"=>"MAT_FLAG"),$cfg_tMatchFlags);
							?>
							<?php 
							if ( is_object($T_MAT['MAT_DETAILS']) ){
								echo $T_MAT['MAT_DETAILS']->edit(9,$T_MAT['MAT_FLAG'],zk_equipe($T_EQI['EQ1'],false),zk_equipe($T_EQI['EQ2'],false),true);
							}
							?>
							<div align="center"><input type="image" src="<?php echo WWW_ROOT.'app/layout/'.THEME_ADMIN.'/images/icons/add.png'; ?>" name="ajouter" id="ajouter" /> Ajouter des d&eacute;tails</div>
							<input type="hidden" value="" id="MAT_DETAILS" />
							
							</td>
						</div>
					</td>
				</tr>
				<tr>
					<td colspan="2" class="sai" align="center">
					<input type="radio" id="MAT_ETAT_OFF" name="MAT_ON_OFF" value="0" class="radio" <?php echo p('MAT_ETAT')==0?'checked="checked"':''; ?>/><label for="MAT_ETAT_OFF">en cours</label>
					<input type="radio" id="MAT_ETAT_ON" name="MAT_ON_OFF" value="1" class="radio" <?php echo p('MAT_ETAT')==1?'checked="checked"':''; ?>/><label for="MAT_ETAT_ON" <?php echo $clos_mais_a_terminer?'class="look"':''; ?>> termin&eacute;</label>
					<?php if ( $T_MAT['MAT_TYPE'] == 2 || $T_MAT['MAT_TYPE'] == 3 ) { ?><input type="radio" id="MAT_ETAT_KO" name="MAT_ON_OFF" value="2" class="radio" <?php echo p('MAT_ETAT')==2?'checked="checked"':''; ?>/><label for="MAT_ETAT_KO"> non jou&eacute;</label><?php } ?>
					<input type="hidden" name="MAT_ETAT" id="MAT_ETAT" value="<?php echo p('MAT_ETAT'); ?>" />
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center" style="padding: 5px 0px">
					<form method="post" action="<?php echo href('',array('controleur'=>'Tournoi','action'=>'Rencontre','params'=>v('TNS_CLE').'-'.$T_MAT['MAT_CLE'].'-'.$T_EQI['EQ1']['EQI_CLE'].'-'.$T_EQI['EQ2']['EQI_CLE']),false,true); ?>" target="_blank" style="border: 0px none; margin: 0px; padding: 0px;">
					
					<input type="button" id="BTN_ANNULE" name="BTN_ANNULE" value="" class="annuler" />
					<input type="button" id="BTN_VAL" name="BTN_VAL" class="ok" value="" />
					<input type="hidden" name="impression" value="1" />
					<input type="submit" id="BTN_VAL" name="BTN_VAL" class="imprimer" value="" />
					<?php echo do_action('vues.admin.rentrerscore.boutons')?>
					</form>
					</td>
				</tr>
				<tr>
					<td colspan="2" align="center" style="font-size: 9px;">
					<?php echo __('adm.rentrerscore.txt'); ?>
					</td>
				</tr>
			</table>
		</div>
	</div>
	</div>
	<a href="#fermer" title="Fermer" id="btn-fermer" ><?php echo img('icons/cross.png'); ?></a>

	<script type="text/javascript">

	$(function(){

        var fermerTab = function(){
            if ($.isFunction($("#ajax-content").modal)){
                $("#ajax-content").modal('hide');
            } else {
                $.unblockUI();
            }
        }

        if ($.isFunction($(this).tab)){
        $('#mes-tabs a').click(function (e) {
                    e.preventDefault();
                    $(this).tab('show');
                });
        }
		//$('#datepicker').datepicker({altField: '#MAT_DATE', altFormat: 'dd/mm/yy', defaultDate: new Date ( "<?php echo $T_MAT['MAT_DATE_EN']; ?>" )});
		<?php echo $T_MAT['MAT_DETAILS']->getJsAdmin(); ?>

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

		$('#btn-fermer').click(function(){
            fermerTab();
		});
		
		function maj_infos(){
			prepare();

			<?php
			if ( v('EN_TOURNOI')==1 && $T_MAT['TNS_DIR'] =='' ){ ?>

			if (  $("#MAT_ETAT").val() == 1 && $("#EQI_S1").val() == $("#EQI_S2").val() ){
				alert("<?php echo __('adm.err.18'); ?>");
				return false;
			}
			<?php } ?>

			$.ajax({
				type: "POST",
				url: "<?php echo php_self(); ?>",
				data: "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" ){
                        fermerTab();
						window.location.reload();
						$(location).attr('href',"<?php echo $url_referer; ?>");
					} else {
						alert("ERREUR : "+msg);
					}
				}
			});
		}

		$("#BTN_VAL").live('click',maj_infos);

        if ($.isFunction($("#tabs-feuille").tabs)){
            $("#tabs-feuille").tabs();
        }

		
	});

	</script>
	<?php

}
?>