<?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['menu-btn37'];

  require_once "../config_sams.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_sams.php";

  $delimiter = ";";
  $handle = file("../temp/sams_change_addr.csv");

  putwait($skin_tmp,$TEXT['grp-wait']); require_once "../utils/bottom_sams.php";

  foreach($handle as $line_num => $line)
   {
    $line_total = ($line_num + 1);
    $linedump=trim($line);
    if(!($linedump ==''))
     {
      if($line_num > 0)
        {
         $csv_line = explode($delimiter,$linedump,2);
         $ip_iskh = trim($csv_line[0]);
         $ip_new = trim($csv_line[1]);

         $query = "UPDATE squidctrl.squidusers SET `ip` = '".$ip_new."', `nick` = '".$ip_new."' WHERE `ip`= '".$ip_iskh."'";
          $result = mysqli_query($dbcnx,$query);
           if(!$result) {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_sams.php"; exit();}

         $query_ip2 = "UPDATE squidlog.cache SET `user` = '".$ip_new."', `ipaddr` = '".$ip_new."' WHERE `ipaddr` = '".$ip_iskh."' ";
         $result_ip2 = mysqli_query($dbcnx,$query_ip2);
          if(!$result_ip2) {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_sams.php"; exit();}

         $query_ip3 = "UPDATE squidlog.cachesum SET `user` = '".$ip_new."' WHERE `user` = '".$ip_iskh."' ";
         $result_ip3 = mysqli_query($dbcnx,$query_ip3);
          if(!$result_ip3) {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_sams.php"; exit();}
         }
      }
   }

      echo "<html><head>
                <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=../addresses/index.php' />
                </head></html>";

//require_once "../utils/bottom_sams.php";
?>