<?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['addr-change-param'];
  $delimiter = ".";

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

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

  if(empty($_POST['ip_id'])) {puterror($result2['skin'],$TEXT['error-addr21']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['ip_id'])>15) {puterror($result2['skin'],$TEXT['error-addr22']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['ip_id2'])>15) {puterror($result2['skin'],$TEXT['error-addr22']); require_once "../utils/bottom_adm.php"; exit();}


//  if(empty($_POST['ip_id2']))
//  {
//function disabled by php > 5.5.3
////import_request_variables("gP", "in_");
// before using only ->  while(list($id,$value) = @each($in_ip))
//  while(list($id2,$value2) = each($_POST)) {
//  if ($id2 == "ip") {
//   while(list($id,$value) = each($value2)) {
//     if($id > 0 && $value == 'on')
//     {
     if(!empty($_POST['ip_id2'])){
     foreach($_POST['ip_id2'] as $checked){
      $_POST['ip_id2'] = $checked;
     }
      } else {echo "...";}
//     }
//    }
//   }
//  }
// }
  if(empty($_POST['ip_id2'])) {puterror($result2['skin'],$TEXT['error-addr21']); require_once "../utils/bottom_adm.php"; exit();}

  $_POST['ip_id'] = rep($_POST['ip_id']);
  $_POST['ip_id2'] = rep($_POST['ip_id2']);

  $query_iskh = "SELECT `hw`, `ip_addr`, `descr`, `name`, `vkl_ip`, `pods_id` FROM `tbl_ip` WHERE `ip_id`='".$_POST['ip_id']."' ";
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
      $result_iskh2 = mysqli_fetch_array($result_iskh,MYSQLI_ASSOC);

      $addr = explode($delimiter,$result_iskh2['ip_addr'],4);
       $oct1 = substr($addr['0'],0,1);
        if($oct1 == '0')
         {
          $oct_res1 = substr($addr['0'],1,1); exit();
          if($oct_res1 == '0')
           {
         $oct_result1 = substr($addr['0'],2,3);
           } else {$oct_result1 = substr($addr['0'],1,3);}
         } else {$oct_result1 = $addr['0'];}

       $oct2 = substr($addr['1'],0,1);
        if($oct2 == '0')
         {
          $oct_res2 = substr($addr['1'],1,1);
           if($oct_res2 == '0')
            {
            $oct_result2 = substr($addr['1'],2,3);
            } else {$oct_result2 = substr($addr['1'],1,3);}
         } else {$oct_result2 = $addr['1'];}

       $oct3 = substr($addr['2'],0,1);
        if($oct3 == '0')
         {
         $oct_res3 = substr($addr['2'],1,1);
          if($oct_res3 == '0')
           {
           $oct_result3 = substr($addr['2'],2,3);
           } else {$oct_result3 = substr($addr['2'],1,3);}
         } else {$oct_result3 = $addr['2'];}

        $oct4 = substr($addr['3'],0,1);
         if($oct4 == '0')
          {
          $oct_res4 = substr($addr['3'],1,1);
           if($oct_res4 == '0')
            {
            $oct_result4 = substr($addr['3'],2,3);
            } else {$oct_result4 = substr($addr['3'],1,3);}
          } else {$oct_result4 = $addr['3'];}
        $ip_addres = $oct_result1.".".$oct_result2.".".$oct_result3.".".$oct_result4;

  $query_dest = "SELECT `hw`, `ip_addr`, `descr`, `name`, `vkl_ip`, `pods_id` FROM `tbl_ip` WHERE `ip_id`='".$_POST['ip_id2']."' LIMIT 1";
  $result_dest = mysqli_query($dbcnx,$query_dest);
  if(!$result_dest) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
      $result_dest2 = mysqli_fetch_array($result_dest,MYSQLI_ASSOC);

       $addr2 = explode($delimiter,$result_dest2['ip_addr'],4);
       $oct12 = substr($addr2['0'],0,1);
        if($oct12 == '0')
         {
          $oct_res12 = substr($addr2['0'],1,1);
          if($oct_res12 == '0')
           {
         $oct_result12 = substr($addr2['0'],2,3);
           } else {$oct_result12 = substr($addr2['0'],1,3);}
         } else {$oct_result12 = $addr2['0'];}

       $oct22 = substr($addr2['1'],0,1);
        if($oct22 == '0')
         {
          $oct_res22 = substr($addr2['1'],1,1);
           if($oct_res22 == '0')
            {
            $oct_result22 = substr($addr2['1'],2,3);
            } else {$oct_result22 = substr($addr2['1'],1,3);}
         } else {$oct_result22 = $addr2['1'];}

       $oct32 = substr($addr2['2'],0,1);
        if($oct32 == '0')
         {
         $oct_res32 = substr($addr2['2'],1,1);
          if($oct_res32 == '0')
           {
           $oct_result32 = substr($addr2['2'],2,3);
           } else {$oct_result32 = substr($addr2['2'],1,3);}
         } else {$oct_result32 = $addr2['2'];}

        $oct42 = substr($addr2['3'],0,1);
         if($oct42 == '0')
          {
          $oct_res42 = substr($addr2['3'],1,1);
           if($oct_res42 == '0')
            {
            $oct_result42 = substr($addr2['3'],2,3);
            } else {$oct_result42 = substr($addr2['3'],1,3);}
          } else {$oct_result42 = $addr2['3'];}
        $ip_addres2 = $oct_result12.".".$oct_result22.".".$oct_result32.".".$oct_result42;

     if($_POST['name'] !== "on" && $_POST['hw'] !== "on" && $_POST['descr'] !== "on") {puterror($result2['skin'],$TEXT['error-addr23']); require_once "../utils/bottom_adm.php"; exit();}

     elseif($_POST['name'] == "on" && $_POST['hw'] == "on" && $_POST['descr'] == "on")
      {
       $dest = " `name` = '".$result_dest2['name']."', `hw` = '".$result_dest2['hw']."', `descr` = '".$result_dest2['descr']."', `vkl_ip` = '".$result_dest2['vkl_ip']."', `pods_id` = '".$result_dest2['pods_id']."' ";
       $src = " `name` = '".$result_iskh2['name']."', `hw` = '".$result_iskh2['hw']."', `descr` = '".$result_iskh2['descr']."', `vkl_ip` = '".$result_iskh2['vkl_ip']."', `pods_id` = '".$result_iskh2['pods_id']."' ";
       $dest_tmp = " `name` = 'temp56yuzdsd', `hw` = 'temp565yuzdsd', `descr` = 'temp5655yuzdsd' ";
      }

     elseif($_POST['name'] == "on" && $_POST['hw'] == "on" && $_POST['descr'] !== "on")
      {
       $dest = " `name` = '".$result_dest2['name']."', `hw` = '".$result_dest2['hw']."', `vkl_ip` = '".$result_dest2['vkl_ip']."', `pods_id` = '".$result_dest2['pods_id']."' ";
       $src = " `name` = '".$result_iskh2['name']."', `hw` = '".$result_iskh2['hw']."', `vkl_ip` = '".$result_iskh2['vkl_ip']."', `pods_id` = '".$result_iskh2['pods_id']."' ";
       $dest_tmp = " `name` = 'temp56yuzdsd', `hw` = 'temp565yuzdsd' ";
      }

     elseif($_POST['name'] == "on" && $_POST['hw'] !== "on" && $_POST['descr'] == "on")
      {
       $dest = " `name` = '".$result_dest2['name']."', `descr` = '".$result_dest2['descr']."', `vkl_ip` = '".$result_dest2['vkl_ip']."', `pods_id` = '".$result_dest2['pods_id']."' ";
       $src = " `name` = '".$result_iskh2['name']."', `descr` = '".$result_iskh2['descr']."', `vkl_ip` = '".$result_iskh2['vkl_ip']."', `pods_id` = '".$result_iskh2['pods_id']."' ";
       $dest_tmp = " `name` = 'temp56yuzdsd', `descr` = 'temp565yuzdsd' ";
      }

     elseif($_POST['name'] !== "on" && $_POST['hw'] == "on" && $_POST['descr'] == "on")
      {
       $dest = " `hw` = '".$result_dest2['hw']."', `descr` = '".$result_dest2['descr']."', `vkl_ip` = '".$result_dest2['vkl_ip']."', `pods_id` = '".$result_dest2['pods_id']."' ";
       $src = " `hw` = '".$result_iskh2['hw']."', `descr` = '".$result_iskh2['descr']."', `vkl_ip` = '".$result_iskh2['vkl_ip']."', `pods_id` = '".$result_iskh2['pods_id']."' ";
       $dest_tmp = " `hw` = 'temp56yuzdsd', `descr` = 'temp565yuzdsd' ";
      }

     elseif($_POST['name'] == "on" && $_POST['hw'] !== "on" && $_POST['descr'] !== "on")
      {
       $dest = " `name` = '".$result_dest2['name']."', `vkl_ip` = '".$result_dest2['vkl_ip']."', `pods_id` = '".$result_dest2['pods_id']."' ";
       $src = " `name` = '".$result_iskh2['name']."', `vkl_ip` = '".$result_iskh2['vkl_ip']."', `pods_id` = '".$result_iskh2['pods_id']."' ";
       $dest_tmp = " `name` = 'temp56yuzdsd' ";
      }

     elseif($_POST['name'] !== "on" && $_POST['hw'] !== "on" && $_POST['descr'] == "on")
      {
       $dest = " `descr` = '".$result_dest2['descr']."', `vkl_ip` = '".$result_dest2['vkl_ip']."', `pods_id` = '".$result_dest2['pods_id']."' ";
       $src = " `descr` = '".$result_iskh2['descr']."', `vkl_ip` = '".$result_iskh2['vkl_ip']."', `pods_id` = '".$result_iskh2['pods_id']."' ";
       $dest_tmp = " `descr` = 'temp56yuzdsd' ";
      }

     elseif($_POST['name'] !== "on" && $_POST['hw'] == "on" && $_POST['descr'] !== "on")
      {
       $dest = " `hw` = '".$result_dest2['hw']."', `vkl_ip` = '".$result_dest2['vkl_ip']."', `pods_id` = '".$result_dest2['pods_id']."' ";
       $src = " `hw` = '".$result_iskh2['hw']."', `vkl_ip` = '".$result_iskh2['vkl_ip']."', `pods_id` = '".$result_iskh2['pods_id']."' ";
       $dest_tmp = " `hw` = 'temp56yuzdsd' ";
      }

  //*************************************
  //Информация для лога
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-addr3'];
  $what = $TEXT['log-addr19']." &laquo;".$ip_addres."&raquo; &#8810;&equiv;&#8811; &laquo;".$ip_addres2."&raquo;";
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************
 $querytmp = "UPDATE `tbl_ip` SET ".$dest_tmp." WHERE `ip_id`='".$_POST['ip_id2']."'";
 if(mysqli_query($dbcnx,$querytmp))
 {
  $query = "UPDATE `tbl_ip` SET ".$dest." WHERE `ip_id`='".$_POST['ip_id']."'";
  if(mysqli_query($dbcnx,$query))
  {
   $query2 = "UPDATE `tbl_ip` SET ".$src." WHERE `ip_id`='".$_POST['ip_id2']."'";
   if(mysqli_query($dbcnx,$query2))
   {
    $query3 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
     if(mysqli_query($dbcnx,$query3))
      {
       echo "<html><head>
             <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
             </head></html>";
      } else {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
   } else {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_adm.php"; exit();}
  } else {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_adm.php"; exit();}
 } else {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_adm.php"; exit();}
  require_once "../utils/bottom_adm.php";
?>