File "debug_insere_partie.php"

Full Path: /home/analogde/www/temp_work/debug_insere_partie.php
File size: 9.31 KB
MIME-type: text/x-php
Charset: utf-8

<?php

	session_start();
	include('correlation.php');
	include('chessmaster.php');
	include('generation_chessmaster.php');

	https://fr.pornhub.com/channels/my-pervy-family/videos?page=3
	
	//include('correlation.php');
	//include('echec_fonctions_communes.php');
	//include('chessmaster.php');

function check_date($data) 
{
    if (date('d-m-Y', strtotime($data)) == $data) 
	{
        return "OK";
    } 
	else 
	{
        return "Erreur";
    }
}

			echo " Debug insere partie ....";
			echo "<br>";

			$flag_validation = false;

			$jour = $_POST['jour'];
			$mois = $_POST['mois'];
			$annee = $_POST['annee'];
			$J1 = $_POST['J1'];
			$J2 = $_POST['J2'];
			$selection_score = $_POST['selection_score'];
			$date_reference = $_POST['date_reference'];
			$option_date = $_POST['option_date'];
			$id_partie = $_POST['id_partie'];

			//inserer_partie.php?id=1&J1=%20AlvaroM&J2=%20StephaneR&score=%201%20-%200&date=%2015/06/2022
			//AlvaroM	1700	StephaneR	1300	1 - 0	15/06/2022
			//2 20 Juillet 2022 RemyS StephaneR Blanc gagne apres 1655244000

			$jour = 20;
			$mois = "Juillet";
			$annee = 2022;
			$J1 = "RemyS";
			$J2 = "StephaneR";
			$selection_score = "Blanc gagne";
			$date_reference = 1655244000;
			$option_date = "apres";
			$id_partie = 2;
			
			
			switch($selection_score)
			{
				case "Blanc gagne":
						$score_blanc = "1";
						$score_noir = "0";
						$flag_validation = true;
						break;

				case "Blanc perd":
						$score_blanc = "0";
						$score_noir = "1";
						$flag_validation = true;
						break;

				case "Noir gagne":
						$score_blanc = "0";
						$score_noir = "1";
						$flag_validation = true;
						break;

				case "Noir perd":
						$score_blanc = "1";
						$score_noir = "0";
						$flag_validation = true;
						break;

				case "Match nul":
						$score_blanc = "0.5";
						$score_noir = "0.5";
						$flag_validation = true;
						break;
			}

			if($flag_validation == true)
			{
					$tab_associatif = array(); 
					$tab_associatif ['Janvier']='1';
					$tab_associatif ['Février']='2';
					$tab_associatif ['Mars']='3';
					$tab_associatif ['Avril']='4';
					$tab_associatif ['Mai']='5';
					$tab_associatif ['Juin']='6';
					$tab_associatif ['Juillet']='7';
					$tab_associatif ['Aôut']='8';
					$tab_associatif ['Septembre']='9';
					$tab_associatif ['Octobre']='10';
					$tab_associatif ['Novembre']='11';
					$tab_associatif ['Décembre']='12';
					$mois = $tab_associatif[$mois];

					$num_jour = intval($jour);
					$num_mois = intval($mois);
					
					if($num_jour < 10)
					{
						$jour = '0' .$jour;
					}
					
					if($num_mois < 10)
					{
						$mois = '0' .$mois;
					}
					
					$date_format = $jour ."-" .$mois ."-" .$annee;

					if(check_date($date_format) == "Erreur") 
					{
						//$message = '<div id="message_traitement" style="display:block">Date non valide.</div>';
						header ('Location: interdiction.php');
					}
					else
					{
						echo "TRACE 1 ";
						echo "<br>";
					
						$timestamp = mktime (0, 0, 0, $mois, $jour, $annee);
						
						echo "time " .$timestamp;
						echo "<br>";
						echo "reference " .$date_reference;
						echo "<br>";
						//echo $_POST['date_reference'];
						//echo $_POST['option_date'];

						if($option_date == "avant")
						{
							//echo $timestamp ." **** " .$_POST['date_reference'];
							if($timestamp <= $date_reference)
							{
								$plage_date = "Ok";
							}	
							else
							{
								$plage_date = "Erreur_avant";
							}
						}	


						if($option_date == "apres")
						{
							//echo $timestamp ." **** " .$_POST['date_reference'];
							if($timestamp >= $date_reference)
							{
								$plage_date = "Ok";
							}	
							else
							{
								$plage_date = "Erreur_apres";
							}
						}	
												

						if($plage_date == "Ok")
						{
							echo "VROOM...";
							//echo " ---> " .$timestamp + " " .$date_reference;
							echo "<br>";
						
							$donnees = array();
							$donnees[0] = $jour ."/" .$mois ."/" .$annee; 
							$donnees[1] = $J1;
							$donnees[2] = $J2;
							$donnees[3] = $score_blanc;
							$donnees[4] = $score_noir;

							$sql = "SELECT * FROM " .$_SESSION['parties'] ." ORDER by date asc"; 
							$results = mysql_query($sql);
							$nb_parties = mysql_num_rows($results);

							while($row = mysql_fetch_assoc($results))
							{
								$blanc = $row['w_name'];
								$noir = $row['b_name'];
								$date = $row['date'];
								$resultat = $row['result'];
								$date_partie = date('d/m/Y', $date);

								if($resultat == 1)
								{
									$_score_blanc = 1;
									$_score_noir = 0;
								}
								if($resultat == 2)
								{
									$_score_blanc = 0;
									$_score_noir = 1;
								}

								if($resultat == 3)
								{
									$_score_blanc = 0.5;
									$_score_noir = 0.5;
								}

								$table_csv[0] = $date_partie;
								$table_csv[1] = $blanc;
								$table_csv[2] = $noir;
								$table_csv[3] = $_score_blanc;
								$table_csv[4] = $_score_noir;
								$table_fichier[] = $table_csv;
							}

							echo " TRACE 2 ";
							echo "<br>";
							
							echo "<pre>";
							print_r($table_fichier);
							echo "</pre>";
							
							
							$nom_fichier = "sauvegarde_insertion.txt";

							$fp = fopen($nom_fichier, 'w'); 

							for ($i=0; $i < $nb_parties; $i++)
							{
								$str_comma_separated = implode(";", $table_fichier[$i]);
								fputs ($fp, $str_comma_separated);
								if($i != $nb_parties - 1)
								fputs($fp, "\n");
							}

							fclose($fp);

							// creation du fichier modifie

							$nom_fichier = "new_insertion.txt";

							if($option_date == "avant")
							{
								$id_position = $id_partie -1;
							}	

							if($option_date == "apres")
							{
								$id_position = $id_partie ;
							}	


							$tab1 = array();
							$tab2 = array();

							$fp = fopen($nom_fichier, 'w'); 
							for ($i=0; $i <= $id_position - 1; $i++)
							{
								$tab1[] = $table_fichier[$i];
							}

							$table[] = $donnees;

							for ($i=$id_position ; $i < $nb_parties; $i++)
							{
								$tab2[] = $table_fichier[$i];
							}

							$tab_global = array_merge($tab1,$table,$tab2);
							
							$fp = fopen($nom_fichier, 'w'); 
							
							for ($i=0; $i < count($tab_global); $i++)
							{
								$str_comma_separated = implode(";", $tab_global[$i]);
								fputs ($fp, $str_comma_separated);

								if($i != count($tab_global) - 1)
								{
									fputs($fp, "\n");
								}
							}

							fclose($fp);
							
							/***********************************/
							
							$str1 = "TRUNCATE TABLE " .$_SESSION['classement'];
							$str2 = "TRUNCATE TABLE " .$_SESSION['evolution'];
							$str3 = "TRUNCATE TABLE " .$_SESSION['parties'];
							$str4 = "TRUNCATE TABLE " .$_SESSION['chessmaster'];
				
							//mysql_query($str1);
							//mysql_query($str2);
							//mysql_query($str3);
							//mysql_query($str4);

							echo "Initialisation de la table classement ....";
							echo "<br>";
	
							$sql = "INSERT INTO `clone_classement_new` (`id`, `joueur`, `elo`, `initial`, `parties`, `prior`, `bonus`, `oldrating`, `gcount`, `wins`, `losses`, `draws`, `active`) VALUES
							(1, 'AlvaroM', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1),
							(2, 'DamienB', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1),
							(3, 'EmileM', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1),
							(4, 'FranckV', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1),
							(5, 'HenriqueF', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1),
							(6, 'PatrickA', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1),
							(7, 'PhilippeA', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1),
							(8, 'RemyS', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1),
							(9, 'StephaneR', 1400, 1400, 0, 0, 0, 0, 0, 0, 0, 0, 1); ";
							//$result = mysql_query($sql);
	
							$sql = "ALTER TABLE clone_chessmaster_new AUTO_INCREMENT = 1";
							//$result = mysql_query($sql);
							
							/***********************************/
							
							$file = fopen ("new_insertion.txt","r");
		
							$indice =  1;	
							while(! feof($file))
							{
								$tmp = fgets($file);
								$tmp = strtolower($tmp);
								//echo $tmp ."<BR>";
								//$tmp = str_to_noaccent($tmp);
								$pieces = explode(";", $tmp);
								$donnees[0] = $pieces[0];
								list($jour, $mois, $annee) = explode('/', $donnees[0]);
								$timestamp = mktime (0, 0, 0, $mois, $jour, $annee);
								$donnees[0] = $timestamp; 
								$donnees[1] = $pieces[1];
								$donnees[2] = $pieces[2];
								$donnees[3] = $pieces[3];
								$donnees[4] = $pieces[4];
								//algo_elo($donnees, "nostatistique", "sql", $indice );
								$indice = $indice + 1;
							}
				
							echo "<br>";
					
							//generer_chessmaster();

							echo "Script executé avec succés";	
							echo "<br>";
				
							//partie insérée dans la database
							echo 1;
						}

						else
						{
							//Date non valide dans la plage définie 
							echo 2 ." " .$timestamp ." " .$date_reference ." " .$option_date;
						}
					}	
			}

			else
			{
				//Erreur dans le traitement
				echo 3;
			}

?>