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

  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['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']))
   {
    $podset_fltr="&amp;podset=".$_GET['podset']."";
   }
   else
   {
    $podset_fltr="";
   }

  if($_GET['house_ch'] == "on")
   {
    $house_fltr="&amp;house_ch=on&amp;house_id=".$_GET['house_id']."";
   }
   else
   {
    $house_fltr="";
   }

  if($_GET['etazh_ch'] == "on")
   {
   $etazh_fltr="&amp;etazh_ch=on&amp;etazh_id=".$_GET['etazh_id']."";
   }
   else
   {
    $etazh_fltr="";
   }

  if($_GET['obor_ch'] == "on")
   {
    $obor_fltr="&amp;obor_ch=on&amp;obor_id=".$_GET['obor_id']."";
   }
   else
   {
    $obor_fltr="";
   }

  //*************************************
  //Информация для лога
  $query10 = "SELECT `podset` 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;

  //Вводим переменные
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-podset2'];
  $what = $podset.$TEXT['log-id'].$_GET['pods_id'];
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************

  $query = "DELETE FROM `tbl_podset` WHERE `pods_id`='".$_GET['pods_id']."' LIMIT 1";
  if(mysqli_query($dbcnx,$query))
  {
    $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=index.php?a=".$_GET['a']."".$house_fltr."".$etazh_fltr."".$obor_fltr."".$podset_fltr."' />
                   </head></html>";
           } else {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
  } else {puterror($result2['skin'],$TEXT['error-podset7']); require_once "../utils/bottom_adm.php"; exit();}
require_once "../utils/bottom_adm.php";
?>