<?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-btn36-title'];

  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(strlen($_POST['sams'])>1) {puterror($result2['skin'],$TEXT['error-srvpar1']); require_once "../utils/bottom_adm.php"; exit();}
  if(empty($_POST['usrpass'])) {puterror($result2['skin'],$TEXT['error-srvpar3']); require_once "../utils/bottom_adm.php"; exit();}
  if(strlen($_POST['usrpass'])>5) {puterror($result2['skin'],$TEXT['error-srvpar3']); require_once "../utils/bottom_adm.php"; exit();}

  if(isset($_POST['usrpass'])) {$usrpass=trim($_POST['usrpass']);}
    else {$usrpass="";}
     if(empty($usrpass)) {puterror($result2['skin'],$TEXT['error-srvpar4']); require_once "../utils/bottom_adm.php"; exit();}

  $_POST['usrpass'] = rep($_POST['usrpass']);

  $query_iskh4 = "SELECT * FROM `tbl_srvparam` LIMIT 1";
  $result_iskh4 = mysqli_query($dbcnx,$query_iskh4);
  if(!$result_iskh4) {puterror($result2['skin'],$TEXT['error-tbl14']); require_once "../utils/bottom_adm.php"; exit();}
   $result_iskh_many = mysqli_fetch_array($result_iskh4,MYSQLI_ASSOC);

  //*************************************
  //Информация для лога
  if($result_iskh_many['sams'] !== $_POST['sams']) {
      if($result_iskh_many['sams'] == "0") {$log_many_tmp1 = $TEXT['srvpar-vikl'];}
       else {$log_many_tmp1 = $TEXT['srvpar-vkl'];}

       if($_POST['sams'] == "0") {$log_many_tmp2 = $TEXT['srvpar-vikl'];}
       else {$log_many_tmp2 = $TEXT['srvpar-vkl'];}

      $log_sams = $TEXT['log-srvpar1']."&laquo;".$log_many_tmp1."&raquo;".$TEXT['log-nd8']."&laquo;".$log_many_tmp2."&raquo;<br />";
  }
    else {$log_sams = "";}

  if($result_iskh_many['usrpass'] !== $_POST['usrpass']) {$log_usrpass = $TEXT['log-srvpar3']."&laquo;".$result_iskh_many['usrpass']."&raquo;".$TEXT['log-nd8']."&laquo;".$_POST['usrpass']."&raquo;<br />";}
    else {$log_usrpass = "";}

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-srvpar'];
  $what = $log_sams." ".$log_usrpass;
  $who = $result2['familiya']." ".$result2['name'];
  //*************************************

  $query = "UPDATE `tbl_srvparam` SET
  `sams` = '".$_POST['sams']."',
  `usrpass` = ".$_POST['usrpass']."
  WHERE `sp_id`='".$result_iskh_many['sp_id']."'";
  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' />
                </head></html>";
           } else {puterror($result2['skin'],$TEXT['error-log']); require_once "../utils/bottom_adm.php"; exit();}
   } else {puterror($result2['skin'],$TEXT['error-tbl14']); require_once "../utils/bottom_adm.php"; exit();}
  require_once "../utils/bottom_adm.php";
?>