<?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['podset-title'];
  $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();}

  $button = $TEXT['btn_save'];
  $action = "edit.php";

  if(strlen($_GET['pods_id'])>5) {puterror($result2['skin'],$TEXT['error-podset6']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['a'])>5) {puterror($result2['skin'],$TEXT['error-srv15']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['etazh_id'])>5) {puterror($result2['skin'],$TEXT['error-etazh6']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['house_id'])>5) {puterror($result2['skin'],$TEXT['error-house6']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['obor_id'])>5) {puterror($result2['skin'],$TEXT['error-oborud6']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['srv_ch'])>5) {puterror($result2['skin'],$TEXT['error-srv15']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['house_ch'])>5) {puterror($result2['skin'],$TEXT['error-srv15']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['etazh_ch'])>5) {puterror($result2['skin'],$TEXT['error-srv15']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['obor_ch'])>5) {puterror($result2['skin'],$TEXT['error-srv15']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_GET['podset'])>15) {puterror($result2['skin'],$TEXT['error-podset2']); require_once "../utils/bottom_adm.php"; exit();}
  $_GET['pods_id'] = rep($_GET['pods_id']);
  $_GET['a'] = rep($_GET['a']);
  $_GET['etazh_id'] = rep($_GET['etazh_id']);
  $_GET['house_id'] = rep($_GET['house_id']);
  $_GET['obor_id'] = rep($_GET['obor_id']);
  $_GET['podset'] = rep($_GET['podset']);

  if(!empty($_GET['podset'])) {$pods_ch = $_GET['podset'];}
   else {$pods_ch = "";}

  $old_pods_id = $_GET['pods_id'];

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

      $addr = explode($delimiter,$result_podset['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 = $oct_result1.".".$oct_result2.".".$oct_result3.".".$oct_result4;
?>
<form enctype='multipart/form-data' action=<?php echo $action; ?> method=post>
<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 FROM `tbl_srv` 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_podset['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['tbl-house']; ?></td>
    <td><select name="house_id">
    <?php
        $query2 = "SELECT * FROM `tbl_house` ORDER BY `house`";
        $srv_tmp2 = mysqli_query($dbcnx,$query2);
          if(!$srv_tmp2) {puterror($result2['skin'],$TEXT['error-tbl10']); require_once "../utils/bottom_adm.php"; exit();}
              while($house = mysqli_fetch_array($srv_tmp2,MYSQLI_ASSOC))
                {
                  if($house['house_id'] == $result_podset['house_id'])
                   {
                    $house = "<option selected value=".$house['house_id'].">".$house['house'];
                   }
                   else {$house = "<option value=".$house['house_id'].">".$house['house'];}
                 echo $house;
                }
    ?>
    </select></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['tbl-etazh']; ?></td>
    <td><select name="etazh_id">
    <?php
        $query3 = "SELECT * FROM `tbl_etazh` ORDER BY `etazh`";
        $srv_tmp3 = mysqli_query($dbcnx,$query3);
          if(!$srv_tmp3) {puterror($result2['skin'],$TEXT['error-tbl11']); require_once "../utils/bottom_adm.php"; exit();}
              while($etazh = mysqli_fetch_array($srv_tmp3,MYSQLI_ASSOC))
                {
                  if($etazh['etazh_id'] == $result_podset['etazh_id'])
                   {
                   $etazh = "<option selected value=".$etazh['etazh_id'].">".$etazh['etazh'];
                   }
                   else {$etazh = "<option value=".$etazh['etazh_id'].">".$etazh['etazh'];}
                 echo $etazh;
                }
    ?>
    </select></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['tbl-oborud']; ?></td>
    <td><select name="obor_id">
    <?php
        $query4 = "SELECT * FROM `tbl_oborud` ORDER BY `oborud`";
        $srv_tmp4 = mysqli_query($dbcnx,$query4);
          if(!$srv_tmp4) {puterror($result2['skin'],$TEXT['error-tbl12']); require_once "../utils/bottom_adm.php"; exit();}
              while($oborud = mysqli_fetch_array($srv_tmp4,MYSQLI_ASSOC))
                {
                  if($oborud['obor_id'] == $result_podset['obor_id'])
                   {
                   $oborud = "<option selected value=".$oborud['obor_id'].">".$oborud['oborud'];
                   }
                   else {$oborud = "<option value=".$oborud['obor_id'].">".$oborud['oborud'];}
                 echo $oborud;
                }
    ?>
    </select></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['srvpar-hostname']; ?></td><td>
 <select name=opthstnm>
   <option value='0' <?php if($result_podset['opthstnm'] == "0") {echo "selected";} ?>><?php echo $TEXT['srvpar-vikl']; ?>
   <option value='1' <?php if($result_podset['opthstnm'] == "1") {echo "selected";} ?>><?php echo $TEXT['srvpar-vkl']; ?>
 </select>
</td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['podset-name']; ?></td><td class="bold_it"><input size=30 maxlength=30 class="input" type=text name=podset value='<?php echo $podset; ?>' /></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['addr-prefix']; ?></td><td class="bold_it"><input size=20 maxlength=255 class="input" type=text name=prefix value='<?php echo $result_podset['prefix']; ?>' /></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['podset-begin']; ?></td><td><textarea cols=48 rows=5 name=begin_subn ><?php echo $result_podset['begin_subn']; ?></textarea></td></tr>
<tr><td class="bold_it_page"><?php echo $TEXT['podset-end']; ?></td><td><textarea cols=48 rows=5 name=end_subn ><?php echo $result_podset['end_subn']; ?></textarea></td></tr>
<tr><td>
<input type="hidden" name="a" value="<?php echo $a; ?>" />
<input type="hidden" name="house_ch" value="<?php echo $_GET['house_ch']; ?>" />
<input type="hidden" name="etazh_ch" value="<?php echo $_GET['etazh_ch']; ?>" />
<input type="hidden" name="obor_ch" value="<?php echo $_GET['obor_ch']; ?>" />
<input type="hidden" name="pods_ch" value="<?php echo $pods_ch; ?>" />
</td><td>
<input class="button2" type=submit value='<?php echo $button; ?>'>
<input type=hidden name=pods_id value='<?php echo $old_pods_id; ?>'>
</td></tr>
</table>
</form>
<?php
require_once "../utils/bottom_adm.php";
?>