<?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-title-edit'];
  $button = $TEXT['btn_save'];
  $action = "edit.php";

  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['ip_id'])) {puterror($result2['skin'],$TEXT['error-addr21']); 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['ip_id'] = rep ($_GET['ip_id']);
  $delimiter = ".";

  $query_iskh = "SELECT * FROM `tbl_ip` WHERE `ip_id`='".$_GET['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);
      $old_ip_id = $_GET['ip_id'];

      if($result_iskh2['vkl_ip'] == 1) {$vkl = "checked";}
       else {$vkl = "";}

      $addr = explode($delimiter,$result_iskh2['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;
?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table align="center" border="0" width="50%">
 <tr><td>
<table align="center" >
<tr><td class="bold_it_page"><?php echo $TEXT['srv-name']; ?></td>
    <td><select name="srv_id">
    <?php
        $query1 = "SELECT srv_id, name, descr, autorit 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'])
                   {
                   $chk = "<option selected value=".$srv['srv_id'].">".$srv['name']."(".$srv['descr'].")";
                   }
                 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 size=20 maxlength=255 type=text name=name value='<?php echo $result_iskh2['name']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-descr']; ?></td><td><input size=20 maxlength=255 type=text name=descr value='<?php echo $result_iskh2['descr']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-ip-addr']; ?>*</td><td><input 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 size=20 maxlength=17 type=text name=hw value='<?php echo $result_iskh2['hw']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-vkl']; ?></td><td><input type=checkbox name=vkl_ip <?php echo $vkl; ?>></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-to-sams']; ?></td><td><input type=checkbox name=sams_ch ></td></tr>
<tr><td></td><td>
<input class="button" type=submit value='<?php echo $button; ?>' />
<input type=hidden name=ip_id value='<?php echo $old_ip_id; ?>' />
</td></tr>
</table>
</td>
</tr>
</table>
</form>
<?php
  require_once "../utils/bottom_adm.php";
?>