<?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['grp-srv-copy-title'];

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();}

if(strlen($_POST['srv_id'])>5) {puterror($result2['skin'],$TEXT['error-srv22']); require_once "../utils/bottom_adm.php"; exit();}
if(empty($_POST['srv_id'])) {puterror($result2['skin'],$TEXT['error-srv21']); require_once "../utils/bottom_adm.php"; exit();}
if(strlen($_POST['srv_id2'])>5) {puterror($result2['skin'],$TEXT['error-srv22']); require_once "../utils/bottom_adm.php"; exit();}
if(empty($_POST['srv_id2'])) {puterror($result2['skin'],$TEXT['error-srv21']); require_once "../utils/bottom_adm.php"; exit();}
if($_POST['srv_id'] == $_POST['srv_id2']) {puterror($result2['skin'],$TEXT['grp-srv-error1']); require_once "../utils/bottom_adm.php"; exit();}
if(empty($_POST['ip_id'])) {puterror($result2['skin'],$TEXT['grp-srv-error2']); require_once "../utils/bottom_adm.php"; exit();}
$n = 0;

//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_id'])){
     foreach($_POST['ip_id'] as $checked){
      $query_iskh = "SELECT * FROM `tbl_ip` WHERE `ip_id`= $checked";
       $result_iskh_tmp = mysqli_query($dbcnx,$query_iskh);
        if(!$result_iskh_tmp) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
         $result_iskh = mysqli_fetch_array($result_iskh_tmp,MYSQLI_ASSOC);

      $query_ip = "INSERT INTO tbl_ip (
       `ip_id`,
       `srv_id`,
       `name`,
       `ip_addr`,
       `hw`,
       `descr`,
       `vkl_ip`,
        `data`,
        `state_addr`,
        `last_acc`)
       VALUES (
       NULL,
       '".$_POST['srv_id2']."',
       '".$result_iskh['name']."',
       '".$result_iskh['ip_addr']."',
       '".$result_iskh['hw']."',
       '".$result_iskh['descr']."',
       '".$result_iskh['vkl_ip']."',
        CURRENT_DATE(),
        '0',
        '1970-01-01')";
      $result_ip = mysqli_query($dbcnx,$query_ip);
       if(!$result_ip) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}

     $log_id .= $checked.", ";
     $n++;
     }
      } else {echo "...";}
//     }
//   }
//  }
// }

//*************************************
//Информация для лога
$query3 = "SELECT name, descr FROM `tbl_srv` WHERE `srv_id`='".$_POST['srv_id']."' ";
  $result3 = mysqli_query($dbcnx,$query3);
  if(!$result3) {puterror($result2['skin'],$TEXT['error-tbl1']); require_once "../utils/bottom_adm.php"; exit();}
      $result4 = mysqli_fetch_array($result3,MYSQLI_ASSOC);

$query4 = "SELECT name, descr FROM `tbl_srv` WHERE `srv_id`='".$_POST['srv_id2']."' ";
  $result5 = mysqli_query($dbcnx,$query4);
  if(!$result5) {puterror($result2['skin'],$TEXT['error-tbl1']); require_once "../utils/bottom_adm.php"; exit();}
      $result6 = mysqli_fetch_array($result5,MYSQLI_ASSOC);

$ip = $_SERVER['REMOTE_ADDR'];
$doing = $TEXT['log-grp-copy'];
$what = $TEXT['log-grp-move2']."&laquo;".$result4['name']." (".$result4['descr'].")&raquo; ".$TEXT['log-na-srv']."&laquo;".$result6['name']." (".$result6['descr'].")&raquo; ".$TEXT['log-grp-copy2'].$n.$TEXT['log-grp-zadr3'].$TEXT['log-id'].substr($log_id,0,-2);
$who = $result2['familiya']." ".$result2['name'];
//*************************************
  $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
   if(mysqli_query($dbcnx,$query2))
    {
    echo "<html><head>
          <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=../addresses/index.php?srv_id=".$_POST['srv_id2']."&amp;srv_ch=on' />
          </head></html>";
    } else {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
require_once "../utils/bottom_adm.php";
?>