<?php
//Récupération du nom de fichier

for($i=1;$i<20;$i++) {
  if(isset($_POST['fichier'.$i.''])) {
    $fichier = $_POST['fichier'.$i.''];
    break;
  }
}

echo '<h3>'.RESTAUR1.' '.$fichier.'</h3>';

//Application des requêtes
echo '<p><b>'.RESTAUR2.'</b></p>';
$fsql=fopen("./db/backup/".$prefix.'/'.$fichier,"r");
while (!feof($fsql)) {
  $line="";
  while ((substr($line,strlen($line)-1,1)!="\n")&&(!feof($fsql))) { 
    $line.=fgets($fsql,4096);
  }
  $line=rtrim($line);
  $msgend=1;
  if ($line!=""&&substr($line,0,1)!=" "&&substr($line,0,1)!="-"&&substr($line,0,1)!=")") {
    if(isset($line_create)) { unset($line_create); }
    if (substr($line,0,4)=="DROP") {
      $currentTable=substr($line,22,-2);
      $i=0;
      if(substr($currentTable, 0, strpos($currentTable,"_"))==$prefix) {
        echo '<p>'.RESTAUR3.' '.$currentTable.'...'; flush(); ob_flush();
        mysqli_query($bdd,"set names 'utf8'");
        mysqli_query($bdd,$line);
      }
      else {
        echo '<p><b>'.RESTAUR4.' '.$currentTable.'<br>'.RESTAUR5.'</b></p></h2>';
        $msgend=0;
        break;
      }
    } 
    else if(substr($line,0,4)=="CREA") {
      $line_create = $line;
    }
    else {
      mysqli_query($bdd,"set names 'utf8'");
      mysqli_query($bdd,$line);

    }
  }
  else if(isset($line_create)) {
    if(substr($line,-1)!=";") {
      $line_create.=$line;
    }
    else {
      $line_create.=$line;
      mysqli_query($bdd,"set names 'utf8'");
      mysqli_query($bdd,$line_create);
    }
  }
}
fclose($fsql);

if($msgend==1) {
  echo RESTAUR6;
}
?>