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

  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($_GET['pods_id'])) {puterror($result2['skin'],$TEXT['error-podset5']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['pods_id'])>5) {puterror($result2['skin'],$TEXT['error-podset6']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['ip_id'])>255) {puterror($result2['skin'],$TEXT['error-addr22']); require_once "../utils/bottom_adm.php"; exit();}
  $_GET['pods_id'] = rep($_GET['pods_id']);
  $_GET['ip_id'] = rep($_GET['ip_id']);
  $delimiter = ".";
  $action = "change.php";
  $button = $TEXT['btn_save'];

  $query_iskh = "SELECT `podset`, `srv_id` FROM `tbl_podset` WHERE `pods_id`='".$_GET['pods_id']."' ";
  $result_iskh = mysqli_query($dbcnx,$query_iskh);
  if(!$result_iskh) {puterror($result2['skin'],$TEXT['error-tbl13']); require_once "../utils/bottom_adm.php"; exit();}
      $result_iskh2 = mysqli_fetch_array($result_iskh,MYSQLI_ASSOC);

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

      $addr = explode($delimiter,$result_iskh4['ip_addr'],4);
       $oct1 = substr($addr['0'],0,1);
        if($oct1 == '0')
         {
          $oct_res1 = substr($addr['0'],1,1);
          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;

        if($result_iskh4['descr'] == "") {$descr = "---";}
         else {$descr = $result_iskh4['descr'];}

        if($result_iskh4['vkl_ip'] == '1') {$vkl = "<img alt=".$TEXT['srv-vikluchit']." src='../skins/".$result2['skin']."/vkl.png' />";}
         else {$vkl = "<img alt=".$TEXT['srv-vkluchit']." src='../skins/".$result2['skin']."/vikl.png' />";}

?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table border="0" width="100%" align="center">
<tr class="button2">
<td width="50%" valign="top">
<fieldset>
<legend align="left" title="<?php echo $TEXT['addr-change-who']; ?>"><?php echo $TEXT['addr-change-who']; ?></legend>
<table width="98%">
<tr><td class="bold_it_page"><?php echo $TEXT['srv-name']; ?></td>
    <td><select name="srv_id">
    <?php
        $query1 = "SELECT `srv_id`, `name`, `descr` FROM `tbl_srv` WHERE `vkl` = '1' ORDER BY `name`";
        $srv_tmp = mysqli_query($dbcnx,$query1);
          if(!$srv_tmp) {puterror($result2['skin'],$TEXT['error-tbl1']); require_once "../utils/bottom_adm.php"; exit();}
              while($srv = mysqli_fetch_array($srv_tmp,MYSQLI_ASSOC))
                {
                 if($srv['srv_id'] == $result_iskh2['srv_id'])
                   {
                   if($srv['descr'] == '')
                    {
                     $chk = "<option selected value=".$srv['srv_id'].">".$srv['name'];
                    } else {$chk = "<option selected value=".$srv['srv_id'].">".$srv['name']."(".$srv['descr'].")";}
                   }
                  else
                   {
                     if($srv['descr'] == '')
                    {
                     $chk = "<option value=".$srv['srv_id'].">".$srv['name'];
                    } else {$chk = "<option value=".$srv['srv_id'].">".$srv['name']."(".$srv['descr'].")";}
                   }
                echo $chk;
                }
    ?>
    </select></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-name']; ?></td><td><input readonly size=30 maxlength=255 type=text name=name value='<?php echo $result_iskh4['name']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-descr']; ?></td><td><input readonly size=30 maxlength=255 type=text name=descr value='<?php echo $descr; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-ip-addr']; ?></td><td><input readonly size=20 maxlength=15 type=text name=ip_addr value='<?php echo $ip_addres; ?>' ></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-mac']; ?></td><td><input readonly size=20 maxlength=17 type=text name=hw value='<?php echo $result_iskh4['hw']; ?>' ></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-vkl-tit']; ?></td><td><?php echo $vkl; ?></td></tr>
<tr>
  <td class="bold_it_page" ><?php echo $TEXT['addr-change-what']; ?>:&nbsp;</td>
  <td class="change_addr">
  <input type="checkbox" name="name" />&nbsp;<?php echo $TEXT['addr-name']; ?><br />
  <input type="checkbox" name="hw" />&nbsp;<?php echo $TEXT['addr-mac']; ?><br />
  <input type="checkbox" name="descr" />&nbsp;<?php echo $TEXT['addr-descr']; ?><br />
  <input type="hidden" name="ip_id" value='<?php echo $_GET['ip_id']; ?>' />
  </td>
</tr>
<tr><td><input class="button" type=submit value='<?php echo $button; ?>'></td><td></td></tr>
</table>
</fieldset>
</td>
<td width="50%">
<fieldset>
<legend align="left" title="<?php echo $TEXT['addr-change-dest']; ?>"><?php echo $TEXT['addr-change-dest']; ?></legend>
<table align="right" width="98%" border="0">
    <thead><tr class='tableheadercat'>
            <td><?php echo $TEXT['addr-move-isp']; ?></td>
            <td><?php echo $TEXT['addr-name']; ?></td>
            <td><?php echo $TEXT['addr-ip-addr']; ?></td>
            <td><?php echo $TEXT['addr-mac']; ?></td>
            <td><?php echo $TEXT['addr-move-isp']; ?></td>
            </tr></thead><tbody id='tab'>
<?php
// Выводим список существующих в заданном диапазоне
  $query_iskh_srv = "SELECT `ip_id`, `hw`, `ip_addr`, `descr`, `name`, `vkl_ip` FROM `tbl_ip` WHERE `ip_addr` REGEXP '".$result_iskh2['podset']."' AND `srv_id` = '".$result_iskh2['srv_id']."' AND `ip_id` != '".$_GET['ip_id']."' ORDER BY `vkl_ip`, `ip_addr` ";
  $result_iskh_srv = mysqli_query($dbcnx,$query_iskh_srv);
  if(!$result_iskh_srv) {puterror($result2['skin'],$TEXT['error-tbl2']); require_once "../utils/bottom_adm.php"; exit();}
    if(mysqli_num_rows($result_iskh_srv) > 0)
     {
       while($result_iskh_srv2 = mysqli_fetch_array($result_iskh_srv,MYSQLI_ASSOC))
       {
       $ip_id = $result_iskh_srv2['ip_id'];
       $addr3 = explode($delimiter,$result_iskh_srv2['ip_addr'],4);
       $oct52 = substr($addr3['0'],0,1);
        if($oct52 == '0')
         {
          $oct_res52 = substr($addr3['0'],1,1);
          if($oct_res52 == '0')
           {
         $oct_result52 = substr($addr3['0'],2,3);
           } else {$oct_result52 = substr($addr3['0'],1,3);}
         } else {$oct_result52 = $addr3['0'];}

       $oct62 = substr($addr3['1'],0,1);
        if($oct62 == '0')
         {
          $oct_res62 = substr($addr3['1'],1,1);
           if($oct_res62 == '0')
            {
            $oct_result62 = substr($addr3['1'],2,3);
            } else {$oct_result62 = substr($addr3['1'],1,3);}
         } else {$oct_result62 = $addr3['1'];}

       $oct72 = substr($addr3['2'],0,1);
        if($oct72 == '0')
         {
         $oct_res72 = substr($addr3['2'],1,1);
          if($oct_res72 == '0')
           {
           $oct_result72 = substr($addr3['2'],2,3);
           } else {$oct_result72 = substr($addr3['2'],1,3);}
         } else {$oct_result72 = $addr3['2'];}

        $oct82 = substr($addr3['3'],0,1);
         if($oct82 == '0')
          {
          $oct_res82 = substr($addr3['3'],1,1);
           if($oct_res82 == '0')
            {
            $oct_result82 = substr($addr3['3'],2,3);
            } else {$oct_result82 = substr($addr3['3'],1,3);}
          } else {$oct_result82 = $addr3['3'];}
        $ip_addres3 = $oct_result52.".".$oct_result62.".".$oct_result72.".".$oct_result82;

        if($result_iskh_srv2['vkl_ip'] == '0') {$srv2_vkl = "<img alt=".$TEXT['srv-vkluchit']." src='../skins/".$result2['skin']."/vikl.png' />";}
         else {$srv2_vkl = "<img alt=".$TEXT['srv-vikluchit']." src='../skins/".$result2['skin']."/vkl.png' />";}

        if($ip_id_osn == $ip_id)
        {
 ?>
<tr>
    <td><?php echo $srv2_vkl; ?></td>
    <td class="bold_it" title="<?php echo $result_iskh_srv2['descr']; ?>"><?php echo $result_iskh_srv2['name']; ?></td>
    <td class="bold_it" title="<?php echo $result_iskh_srv2['descr']; ?>"><?php echo $ip_addres3; ?></td>
    <td class="bold_it"><?php echo substr(chunk_split($result_iskh_srv2['hw'],2,":"),0,-1); ?></td>
    <td class="bold_it"><input type="checkbox" name="ip_id2[]" value="<?php echo $ip_id; ?>"></td>
</tr>
<?php
        }
 else
     {
 ?>
<tr>
    <td><?php echo $srv2_vkl; ?></td>
    <td class="tabledata" title="<?php echo $result_iskh_srv2['descr']; ?>"><?php echo $result_iskh_srv2['name']; ?></td>
    <td class="tabledata" title="<?php echo $result_iskh_srv2['descr']; ?>"><?php echo $ip_addres3; ?></td>
    <td class="tabledata"><?php echo substr(chunk_split($result_iskh_srv2['hw'],2,":"),0,-1); ?></td>
    <td class="bold_it"><input type="checkbox" name="ip_id2[]" value="<?php echo $ip_id; ?>"></td>
</tr>
<?php
     }
   }
 }
?>
</tbody>
</table>
</fieldset>
</td></tr>
</table>
</form>
<?php
  require_once "../utils/bottom_adm.php";
?>