<?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['menu-btn34-title'];

  require_once "../config_sams.php";
  require_once "../utils/functions.php";
  require_once "../utils/top_sams.php";

  if(is_file ("../lang/".$lang."/trans.php")) {require_once "../lang/".$lang."/trans.php";}
     else {require_once "../lang/ru/trans.php";}

  if(strlen($_POST['descr'])>255) {puterror($result2['skin'],$TEXT['error-addr3']); require_once "../utils/bottom_sams.php"; exit();}
  if(strlen($_POST['a'])>5) {puterror($result2['skin'],$TEXT['error-srv15']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['ipclnt'])>15) {puterror($result2['skin'],$TEXT['error-addr5']); require_once "../utils/bottom_adm.php"; exit();}
  $_POST['changemaker1'] = rep($_POST['changemaker1']);
  $_POST['changemaker2'] = rep($_POST['changemaker2']);

  $descr = trim(translate($_POST['descr']));
  $delimiter="_";
  $line = explode($delimiter,$descr,3);
  $family = substr(trim($line[0]), 0,50);
  $name = substr(trim($line[1]), 0,50);
  $soname = substr(trim($line[2]), 0,50);

  $_POST['ipclnt'] = trim($_POST['ipclnt']);

//function disabled by php > 5.5.3
////import_request_variables("gP", "in_");
// before using only ->  while(list($id,$value) = @each($in_ip))

 while(list($id2,$value2) = each($_POST)) {
  if($id2 == "ip") {
   while(list($id,$value) = each($value2)) {
     if($id > 0 && $value == 'on')
       {
       $query3 = "SELECT `ip` FROM squidctrl.squidusers WHERE `id`= '".$id."'";
        $result3 = mysqli_query($dbcnx,$query3);
         if(!$result3) {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_sams.php"; exit();}
          $result4 = mysqli_fetch_array($result3,MYSQLI_ASSOC);

       if($_POST['ipclnt'] !== $result4['ip']) {$ipclnt = ", `ip` = '".$_POST['ipclnt']."', `nick` = '".$_POST['ipclnt']."' ";}
        else {$ipclnt = "";}

       $query = "UPDATE squidctrl.squidusers SET `name` = '".$name."', `family` = '".$family."' ,`soname` = '".$soname."' $ipclnt WHERE `id`= '".$id."'";
       $result = mysqli_query($dbcnx,$query);
        if(!$result) {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_sams.php"; exit();}

       if($ipclnt !== "")
        {
         $query_ip2 = "UPDATE squidlog.cache SET `user` = '".$_POST['ipclnt']."', `ipaddr` = '".$_POST['ipclnt']."' WHERE `ipaddr` = '".$result4['ip']."' ";
         $result_ip2 = mysqli_query($dbcnx,$query_ip2);
          if(!$result_ip2) {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_sams.php"; exit();}

         $query_ip3 = "UPDATE squidlog.cachesum SET `user` = '".$_POST['ipclnt']."' WHERE `user` = '".$result4['ip']."' ";
         $result_ip3 = mysqli_query($dbcnx,$query_ip3);
          if(!$result_ip3) {puterror($result2['skin'],mysqli_error($dbcnx)); require_once "../utils/bottom_sams.php"; exit();}
        }
       }
      }
     }
    }
   if($_POST['a'] == "1")
   {
    echo "<html><head>
             <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=../podset/index.php?a=".$_POST['a']."' />
             </head></html>";
   }
   elseif($_POST['a'] == "2")
    {
      echo "<html><head>
                <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
                </head></html>";
    }
    elseif($_POST['a'] == "3")
    {
      echo "<html><head>
                <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=../podset/newoneform.php?a=".$_POST['a']."&amp;descr=".$_POST['descr']."&amp;pods_id=".$_POST['pods_id']."' />
                </head></html>";
    }
    else {
        echo "<html><head>
                <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php?descr=".$_POST['descr']."' />
                </head></html>";
    }

require_once "../utils/bottom_sams.php";
?>