<?php
$req3 = "SELECT id,idjoueur FROM matgraph_espio2 WHERE idespionner = $idlogin AND jour=1 ORDER BY id ASC";
$res3 = db_mysql_Query($req3) or die('Erreur SQL! <br>'.$req3.'<br>'.mysql_error());
$num3 = mysql_num_rows($res3);
if ( $num3 > 0 ) {
  While ( $row3 = mysql_fetch_array($res3) ) {
  
$req = "SELECT id,date,jour,idespionner,nbreconnect,planeteespionner FROM matgraph_espio2 WHERE idjoueur = $row3[idjoueur] AND idespionner = $idlogin ORDER BY jour DESC limit 1";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res);
  
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $row[date], $thetime);
$time = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftemps = time() - $time;
$difheure = floor($diftemps / 3600);


While ( $difheure >= 24) {
$date = strftime("%Y-%m-%d %H:%M:%S", $time + (24*3600));
$jour = $row[jour] + 1 ;
$chance_decouvrir_techrare = 5 ;
$requete = "INSERT INTO  matgraph_espio2 VALUES ('', '$date', '0', '$jour', '$idlogin', '$row[idespionner]', '$row[planeteespionner]', '0', '0', '0', '0', '0', '$chance_decouvrir_techrare', '0', '0', '0', '0', '0', '0', '1', '5')";
$resultat = db_mysql_Query($requete)or die('erreur sql<br>'.$requete.'<br>'.mysql_error());
$req = "SELECT id,date,jour,idespionner,nbreconnect,planeteespionner FROM matgraph_espio2 WHERE idjoueur = $row3[idjoueur] AND idespionner = $idlogin AND jour = $row[jour]";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$row = mysql_fetch_array($res);
  
ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})", $row[date], $thetime);
$time = mktime($thetime[4],$thetime[5],$thetime[6],$thetime[2],$thetime[3],$thetime[1]);

$diftemps = time() - $time;
$difheure = floor($diftemps / 3600);

}

if($difheure < 24) {

$difmin = floor($difheure / 60);
if($difmin > 10) {
$nbreconnect = $row[nbreconnect] + 1;
$sql = "UPDATE matgraph_espio2 SET nbreconnect = $nbreconnect WHERE id='$row[id]' ";
$res = db_mysql_Query($sql)or die('erreur sql<br>'.$sql.'<br>'.mysql_error());
}}


$chancereperer = 0;
$req = "SELECT chancereperer FROM matgraph_espio2 WHERE idespionner = $idlogin AND idjoueur = $row3[idjoueur] ORDER BY id ASC";
$res = db_mysql_Query($req) or die('Erreur SQL! <br>'.$req.'<br>'.mysql_error());
$num = mysql_num_rows($res);
if ( $num > 0 ) {
  While ( $row = mysql_fetch_array($res) ) {
$chancereperer+= $row[chancereperer] ;  
}}

$chancereperer+= rand(0,20);
if($chancereperer >= 100) {
// sonde répéré
}

}}
?>