<?php
	session_start();
	include('database.php');
	DB_connexion(); 
	
	if(!isset($_SESSION['logged']) )
	{		header ('Location: interdiction.php');
	}
	
	if($_SESSION['logged']== "no")
	{
		header ('Location: interdiction.php');
	}
	
////////////////////////////////////////////////////////////////	
	if(!empty($_POST) )
	{
		$_SESSION['sauvegarde_formulaire'] = $_POST ;
     
		$page_actuelle = $_SERVER['PHP_SELF'] ;
		if(!empty($_SERVER['QUERY_STRING']))
		{
			$page_actuelle .= '?' . $_SERVER['QUERY_STRING'] ;
		}
     
		header('Location: ' . $page_actuelle);
		exit;
	}
	
	if(isset($_SESSION['sauvegarde_formulaire']))
	{
		$_POST = $_SESSION['sauvegarde_formulaire'] ;
		unset($_SESSION['sauvegarde_formulaire']);		
	}	
////////////////////////////////////////////////////////////////	

	$score_defaut = 1000;
	
	if( isset($_POST['valide_form']) && $_POST['valide_form'] == "ok" )
	  {
			if (!empty($_POST["liste"]))
			{	$score_defaut = $_POST["score_defaut"];
				$tableau = $_POST["liste"];
				foreach ( $tableau as $key )
				{   $sql = "UPDATE joueurs SET score = '".$score_defaut."' WHERE nom = '".$key."' " ;
					$res = mysql_query($sql);
					//echo $key." - ";
				}
				$_SESSION['message'] = "ok";
			}
			
			$score_defaut = $_POST['score_defaut'];
	  }
	
?>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr" dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Description" content="Site perso,cours,ouvrages" />
<meta name="Keywords" content="WEBSITE perso " />
<meta name="Distribution" content="Global" />
<meta name="Robots" content="" />
<meta http-equiv="Content-Language" content="fr" />
<meta name="rating" content="general" />
<meta name="author" content="Patrice DELPY" />
<meta name="copyright" content="Copyright 2013" />
<meta name="generator" content="Patoche" />
<title>Patoche WEBSITE - 2013 - Template du site - en cours de développemment ...</title>

<!---------------------------------------------------------->	
<?php
		include('include_css_template_commun.php');
		include('include_css.php');
		include('css_tools_skill.php');
		include('include_javascript.php');
?> 


<style type="text/css">
#bloc_gestion { float: left;
					width: 831px; 
					padding: 50px 50px 25px 50px;
					}	
					
#navigation_tournoi{
					float: left;
					width: 910px; //885
					padding: 10px 0px 0px 10px;
					text-align: center;
		}

label
{   
	display: block;
	width: 150px;
	float: left;
	//padding: 28px;
}

select
{
width: 100px;
display: inline-block;
}

input {
 display: inline-block;
		}
		
input.bouton {
    width: 200px;
}		
		
</style>

<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>


<script type="text/javascript">
function call_update()
{
	 //ajax_routine(); 
	 scruter();
	 setTimeout("call_update()", 1000); //appelle la fonction 1 fois par  seconde
}

function scruter()
{
				var xhr = getXhr()
				// On défini ce qu'on va faire quand on aura la réponse
				xhr.onreadystatechange = function()
				{
					// On ne fait quelque chose que si on a tout reçu et que le serveur est ok
					if(xhr.readyState == 4 && xhr.status == 200)
					{
						//alert(xhr.responseText);
						retour = xhr.responseText;
						
						if(retour == 0)
						{  	
							
									
							$(function()
							{
									$( "#message_expiration" ).dialog({
									modal: true,
									title: "Infos",
									buttons: {
												Ok: function()
												{
													$( this ).dialog( "close" );
													 document.location.href = "logout_expire.php";
												}
											 }
										});
							});
							
							
						}
	
						
						
					}
				}
					
				xhr.open("GET","session_timeout.php",true);
				xhr.send(null);
}

function getXhr()
{
    var xhr = null; 
	if(window.XMLHttpRequest) // Firefox et autres
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject)
	{ // Internet Explorer 
	   try {
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
		   } catch (e) 
		   {
				xhr = new ActiveXObject("Microsoft.XMLHTTP");
		   }
	}
	else { // XMLHttpRequest non supporté par le navigateur 
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
			xhr = false; 
		 } 

	return xhr;
}

function active_sauver()
{
	document.getElementById('send').disabled = false;
	document.getElementById('valide_form').value="ok";
}

function edition_db()
{
	window.location.href = "edition_DB.php";
}


function fct_effacer()
{	
			
		$(function()
					{
								$( "#message_purger_tables" ).dialog({
								modal: true,
								title: "Infos",
								buttons: {
											Oui: function()
											{
												$( this ).dialog( "close" );
												//start();
												purger_tables();
													
											},
											Non: function()
											{
												$( this ).dialog( "close" );
													
											}
										 }
									});
					});
		
	 	//return false;


} 


function fct_regenerer_chessmaster()
{	
			
		$(function()
					{
								$( "#message_regenerer_chessmaster" ).dialog({
								modal: true,
								title: "Infos",
								buttons: {
											Oui: function()
											{
												$( this ).dialog( "close" );
												//start();
												regenerer_chessmaster();
													
											},
											Non: function()
											{
												$( this ).dialog( "close" );
													
											}
										 }
									});
					});
		
	 	//return false;


} 

function purger_tables()
{
	window.location.href = "purger_tables.php";
}


function regenerer_chessmaster()
{
	window.location.href = "regenerer_chessmaster02.php";
}


function sauvegarde_db()
{
	window.location.href = "backup.php";
}

/*
function setButtonState()
{
   
	var etat = document.getElementById("option").checked;
	
	if(etat == true)
	  { document.getElementById('send').disabled = false;
		document.getElementById('valide_form').value="ok";
	  }
	if(etat == false)
	  { document.getElementById('send').disabled = true;
		document.getElementById('valide_form').value="";
	  }  
	  
	
	var xmlhttp;
	if(window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}

	xmlhttp.onreadystatechange=function()
		{
			if (xmlhttp.readyState==4 && xmlhttp.status==200)
			{
				document.getElementById("bloc_selection").innerHTML=xmlhttp.responseText;
				
			}
		}
		
	url='validate.php?statut='+etat;
	//xmlhttp.open("GET","validate.php",true);
	xmlhttp.open("GET",url,true);
	xmlhttp.send();
 
}

/*
var mois = new Array("Janvier","Fevrier","Mars","Avril","Mai","Juin","Juillet","Aout","Septembre","Octobre","Novembre","Decembre");
var jours = new Array("Dimanche","Lundi","Mardi","Mercredi","Jeudi","Vendredi","Samedi");
date_du_jours = new Date () ;
annee = date_du_jours.getYear();
if (annee < 1000)
annee+=1900
Date = date_du_jours.getDate();

function setdate()
{
document.title="Patoche WEBSITE - 2014 - site en cours de développemment ...bienvenue le : "+jours[date_du_jours.getDay()]+" "+Date+" "+mois[date_du_jours.getMonth()]+" "+annee+""
}
if (document.all)
setdate()
else if (document.getElementById)
window.onload=setdate
*/

</script>

<!---------------------------------------------------------->	
</head>

<body>
<!---------------------------------------------------------->	
	<div class="main"> <!-- main -->
<!---------------------------------------------------------->	

          <div class="header">
                <div class="balise_titre">Patoche</div>
                <div class="balise_citation">
                &quot;Etre conscient que l'on est ignorant est un grand pas vers le savoir&quot;
                </div>
          </div> 
 
          <div class="banniere"></div>  

<!---------------------------------------------------------->
<?php
/*	include("include_barre_login.php");
	echo '<div id="box_icon">';
	include("debug_connexion_membre.php");
	echo '</div>';
	include("include_menu.php");*/
	
	echo '<div id="box_infos">';
			include("include_menu.php");
			
			echo '<div id="box_icon2">';
			include("connexion_membre.php");
			echo	'</div>';
			
			echo '<div id="box_icon3">';
			include("include_barre_login.php");
			echo	'</div>';

	echo	'</div>';
	$_SESSION['page_active'] = basename (__FILE__ );
?>
		

<!---------------------------------------------------------->	
            <div class="contenu"> <!-- contenu -->
<!---------------------------------------------------------->	
	
			<div class="barre_vide"></div>
			
			<div id="navigation_tournoi">
				<ul id="menu_horiz">
				<li class="tournoi_back_tag"><a href="tournoi.php" title="Retour au menu principal">Retour</a></li>		
				<li class="tournoi_joueur_tag"><a href="ajouter_joueur.php" title="aller à la section">Nouveau</a></li>
				<!--<li class="tournoi_partie_tag"><a href="partie.php" title="aller à la section">Partie</a></li>-->
				<!--<li class="tournoi_classement_tag"><a href="classement.php" title="aller à la section">classement</a></li>-->
				<li class="tournoi_liste_joueurs_tag"><a href="liste_joueurs.php" title="aller à la section">Joueurs</a></li>
				<!--<li class="tournoi_stats_tag"><a href="historique.php" title="aller à la section">Historique</a></li>-->
				<li class="tournoi_securite_tag_selected"><a href="admin.php" title="aller à la section">Admin</a></li>
				</ul>
			</div>
			
			
			<div id="bloc_gestion"> 
			
			
			<form method="POST" action="import_csv.php" enctype="multipart/form-data">
			<!-- On limite le fichier à 100Ko -->
			<input type="hidden" name="MAX_FILE_SIZE" value="100000">
			Fichier : <input type="file" name="fichier" size="30">
			<br>
			<br>
			<input type="submit" style="width:150px" name="envoyer" value="Charger le fichier">
			<br>
			<br>
			<input type="button"  style="width:150px" name="envoyer" value="Edition des parties" onclick="edition_db()">
			
			<br>
			<br>
			<input type="button"  style="width:150px" name="Purger les tables" value="Purger les tables" onclick="fct_effacer()">
		
			<br>
			<br>
			<input type="button"  style="width:150px" name="Regénérer chessmaster" value="Regénérer chessmaster" onclick="fct_regenerer_chessmaster()">
			
		
			
			<br>
			<br>
			<input type="button"  style="width:150px" name="envoyer" value="Sauvegarde" onclick="sauvegarde_db()">
			
			<div id="message_expiration" style="display: none">
			<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			La session a expirée. Veuillez vous reconnecter.
			</p>
			</div>	
			
		
			</form>
			
			</div>
 
			</div>	
			
			
			<div id="message_purger_tables" style="display: none">
			<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			Voulez-vous vraiment supprimer toutes les tables (purger) !.
			</p>
			</div>
			
			<div id="message_regenerer_chessmaster" style="display: none">
			<p>
			<span class="ui-icon ui-icon-circle-check" style="float:left; margin:0 7px 50px 0;"></span>
			Voulez-vous vraiment regénérer la table chessmaster !.
			</p>
			</div>
			
			<br/>
			<br/>
			<br/>
			<br/>
			<br/>

<!---------------------------------------------------------->	
<?php			
    include('include_pied_page.php');
	include('include_publicite.php');
?>
<!---------------------------------------------------------->	
			</div>  <!-- contenu -->
<!---------------------------------------------------------->	
	</div>   <!-- main -->
<!---------------------------------------------------------->	
	
	<script type="text/javascript">
		call_update();
	</script>

</body>
</html>


