"; 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 "
";
				print_r($table_fichier);
				echo "
";
				
				chdir("insertion");
				echo "Sauvegarde de la db .... " .getcwd();
				echo "

"; $fp = fopen($filename, '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); chdir(".."); } /******************************************************/ echo " Debug insere partie ...."; echo "
"; $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']; $id_partie = 2; $jour = 15; $mois = "Juin"; $annee = 2022; //$J1 = "FranckV"; //$J2 = "AlvaroM"; $J1_insert = "RemyS"; $J2_insert = "StephaneR"; $selection_score = "Blanc gagne"; $date_reference = 1655244000; $option_date = "avant"; /********/ $day = date('d-m-Y'); $heure = date("H_i_s"); $infos = $day.'-'.$heure; $fichier_current_DB = "current_db-" .$infos .".txt"; DB_to_file($fichier_current_DB); $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; echo "Format " .$date_format; echo "
"; echo "
"; switch($selection_score) { case "Blanc gagne": $score_blanc = "1"; $score_noir = "0"; break; case "Blanc perd": $score_blanc = "0"; $score_noir = "1"; break; case "Noir gagne": $score_blanc = "0"; $score_noir = "1"; break; case "Noir perd": $score_blanc = "1"; $score_noir = "0"; break; case "Match nul": $score_blanc = "0.5"; $score_noir = "0.5"; break; } /********/ $new_partie = $jour ."/" .$mois ."/" .$annee .";" .$J1_insert .";" .$J2_insert .";" .$score_blanc .";" .$score_noir; echo " >>>>>> " .$new_partie ; echo "

"; chdir("insertion"); echo "Chemin :" .getcwd(); echo "

"; $parties_data = array(); //$file = "backup_auto-23-07-2022-00_12_02.txt"; $nblines = count(file($fichier_current_DB)); echo " Nb de parties avant l'insertion " .$nblines; echo "

"; if ($file = fopen($fichier_current_DB, "r")) { $indice = 0; while(!feof($file)) { $line = fgets($file); $line = str_replace(array("\n", "\r"), '', $line); if( $indice == $id_partie) { if($option_date == "avant") { $date_partie[] = $new_partie; $date_partie[] = $line; } if($option_date == "apres") { $date_partie[] = $line; $date_partie[] = $new_partie; } } else { $date_partie[] = $line; } $indice++; } fclose($file); } $nblines = count($date_partie); echo " Nb de parties aprés l'insertion " .$nblines; echo "
";
			print_r($date_partie);
			echo "
"; /****/ $fichier_insertion = "sauvegarde_insertion.txt"; $fp = fopen($fichier_insertion, 'w'); for ($i=0; $i < count($date_partie); $i++) { fputs ($fp, $date_partie[$i]); fputs($fp, "\n"); } fclose($fp); /***/ /* unlink($fichier_current_DB); unlink($fichier_insertion); chdir(".."); echo "Répertoire current " .getcwd(); /***/ /* $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 "
"; $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 ($fichier,"r"); $indice = 1; while(! feof($file)) { $tmp = fgets($file); $tmp = strtolower($tmp); //echo $tmp ."
"; //$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 "
"; generer_chessmaster(); echo "Script executé avec succés"; echo "
"; //partie insérée dans la database echo 1; */ ?>