<?php
  ///////////////////////////////////////////////////
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("../lang/".$lang."/".$lang.".php")) {include "../lang/".$lang."/".$lang.".php";}
   else {include "../lang/ru/ru.php";}

  $title = $TEXT['restore-tit'];

  require_once "../config_a.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_adm.php";

  if($result2['administrator'] == 0) {puterror($result2['skin'],$TEXT['error-loginform2']); require_once "../utils/bottom_adm.php"; exit();}

  $search = array("<br /> ");
  $replace = array("\r\n");
  $dis_keys = mysqli_query($dbcnx,"ALTER TABLE DISABLE KEYS");

  if($_FILES['impfl']['size'] > 1024*10*1024) {puterror($result2['skin'],$TEXT['import_err1']); require_once "../utils/bottom_adm.php"; exit();}
    if(!empty($_FILES['impfl']['tmp_name']))
      {
       $handle = file($_FILES['impfl']['tmp_name']);
       $size = filesize($_FILES['impfl']['tmp_name'])/1024;
       $numrows = count($handle);
       $n = 0;

       foreach($handle as $line_num => $line) 
        {
         $line_total = ($line_num + 1);
         $linedump=trim($line);
         if(!($linedump ==''))
         {
          if($line_num > 0)
          {
          $n = ($n+1);
          $linedump = str_replace($search, $replace, $linedump);
          $query = "$linedump";
          $result = mysqli_query($dbcnx,$query);
           if(!$result) {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_adm.php"; exit();}

          }
        }
      }
      }
      unlink($_FILES['impfl']['tmp_name']);

  $en_keys = mysqli_query($dbcnx,"ALTER TABLE ENABLE KEYS");
  //*************************************
  //Информация для лога
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-restore1'];
  $what = $TEXT['log-import2']."(".round($size, 2)." kb), ".$TEXT['log-import3']."(".$numrows."), ".$TEXT['log-restore2']."(".$n.")";
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************
  $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NULL , '$ip' , '$who' , '$doing' , '$what')";
    if(mysqli_query($dbcnx,$query2))
     {
     echo "<html><head>
           <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=../main.php' />
           </head></html>";
     } else {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
  require_once "../utils/bottom_adm.php";
?>