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

  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(empty($_GET['srv_id'])) {puterror($result2['skin'],$TEXT['error-srv21']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['srv_id'])>5) {puterror($result2['skin'],$TEXT['error-srv22']); require_once "../utils/bottom_adm.php"; exit();}
  $_GET['srv_id'] = rep ($_GET['srv_id']);

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

     if($result_iskh2['autorit'] == 1) {$autorit = "checked";}
      else {$autorit = "";}
     if($result_iskh2['vkl'] == 1) {$vkl = "checked";}
      else {$vkl = "";}
?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<table align="center" border="0" width="60%">
 <tr><td>
<table align="left" >
<tr><td class="bold_it_page"><?php echo $TEXT['srv-name']; ?>*</td><td><input size=50 maxlength=255 type=text name=name value='<?php echo $result_iskh2['name']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-descr']; ?></td><td><input size=50 maxlength=255 type=text name=descr value='<?php echo $result_iskh2['descr']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-def-lease']; ?>*</td><td><input size=50 maxlength=25 type=text name=def_lease value='<?php echo $result_iskh2['def_lease']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-max-lease']; ?>*</td><td><input size=50 maxlength=25 type=text name=max_lease value='<?php echo $result_iskh2['max_lease']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-ddns-upd']; ?></td><td>
 <select name=ddns_upd_style>
   <option value='none' <?php if ($result_iskh2['ddns_upd_style'] == "none") {echo "selected";} ?>>none
   <option value='ad-hoc' <?php if ($result_iskh2['ddns_upd_style'] == "ad-hoc") {echo "selected";} ?>>ad-hoc
   <option value='interim' <?php if ($result_iskh2['ddns_upd_style'] == "interim") {echo "selected";} ?>>interim
 </select>
</td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-log-facility']; ?></td><td><input size=50 maxlength=255 type=text name=log_facility value='<?php echo $result_iskh2['log_facility']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-options']; ?>*</td><td><textarea cols=48 rows=5 name=opt_ons ><?php echo $result_iskh2['opt_ons']; ?></textarea></td></tr>

<?php
$query_iskh3 = "SELECT pods_id, podset, begin_subn FROM `tbl_podset` WHERE `srv_id`='".$_GET['srv_id']."' AND `begin_subn` !='' ORDER BY `podset`";
  $result_iskh3 = mysqli_query($dbcnx,$query_iskh3);
  if(!$result_iskh3) {puterror($result2['skin'],$TEXT['error-tbl13']); require_once "../utils/bottom_adm.php"; exit();}
   if(mysqli_num_rows($result_iskh3)>0)
   {
    echo "<tr><td class='bold_it_page'>".$TEXT['srv-endopt']."</td><td title='".$TEXT['srv-endopt-title']."'><textarea cols=48 rows=4 name=endopt>".$result_iskh2['end_opt_ons']."</textarea></td></tr>";
    echo "<tr><td class='bold_it_page'>".$TEXT['srv-net']."</td><td>
        <table border='0'>";
    while($result_iskh4 = mysqli_fetch_array($result_iskh3,MYSQLI_ASSOC))
     {
      $addr = explode($delimiter,$result_iskh4['podset'],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'];}
         $podset_show = $oct_result1.".".$oct_result2.".".$oct_result3.".".$oct_result4;
      if($result_iskh4['begin_subn'] !== '' ) {
          $beg = "<img alt='active' src='../skins/".$result2['skin']."/active.png' />";
          $pods = "<a href='../podset/editform.php?pods_id=".$result_iskh4['pods_id']."' target=_blank title='".$TEXT['edit-tit']."'>".$podset_show."</a>";
      }
       else
           {
           $beg = "---";
           $pods = $result_iskh4['podset'];
       }

      echo "<tr><td><span class='upd_bld'>".$pods."</span></td><td>".$beg."</td></tr>";
     }
     echo "</table>
         </td></tr>";
   }
   else
    {
     echo "<tr><td class='bold_it_page'>".$TEXT['srv-net']."*</td><td><textarea cols=48 rows=5 name=subnts >".$result_iskh2['subnts']."</textarea></td></tr>";
    }
?>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-ssh']; ?>*</td><td><input size="5" maxlength=5 type=text name=sshport value='<?php echo $result_iskh2['sshport']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-shablon']; ?></td><td><input size="15" maxlength=15 type=text name=shablon value='<?php echo $result_iskh2['shablon']; ?>'></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-autorize']; ?></td><td><input type=checkbox name=autorit <?php echo $autorit; ?>></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-vkl']; ?></td><td><input type=checkbox name=vkl <?php echo $vkl; ?>></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srv-ping']; ?></td><td>
 <select name=ping_ok>
   <option value='yes' <?php if ($result_iskh2['ping_ok'] == "yes") {echo "selected";} ?>><?php echo $TEXT['addr-vkluchit2']; ?>
   <option value='no' <?php if ($result_iskh2['ping_ok'] == "no") {echo "selected";} ?>><?php echo $TEXT['addr-vikluchit2']; ?>
 </select>
</td></tr>
<tr><td></td><td>
<input class="button2" type=submit value='<?php echo $button; ?>'>
<input type=hidden name=srv_id value='<?php echo $old_srv_id; ?>' />
</td></tr>
</table>
</td>
</tr>
</table>
</form>
<?php
  require_once "../utils/bottom_adm.php";
?>