<?php
  ///////////////////////////////////////////////////
  //2007 (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=$titlepage = $TEXT['bllst-ed-tit'];
  $helppage = "";

  require_once "../../config.php";
  require_once "../../util/top_layer2.php";

  if($result2['administrator'] == 0) puterror3($TEXT['error-loginform4']);

  if(empty($_POST['address'])) puterror3($TEXT['bllst-error1']);
  if(strlen($_POST['address'])>65) puterror3($TEXT['bllst-error2']);
  if(empty($_POST['old_address'])) puterror3($TEXT['bllst-error1']);
  if(strlen($_POST['old_address'])>65) puterror3($TEXT['bllst-error2']);

  if(isset($_POST['address'])) $address=trim($_POST['address']);
    else $address="";
     if (empty($address)) puterror3($TEXT['bllst-error5']);

  if(isset($_POST['old_address'])) $old_address=trim($_POST['old_address']);
    else $old_address="";
     if (empty($old_address)) puterror3($TEXT['bllst-error5']);

  $_POST['address'] = rep($_POST['address']);
  $_POST['old_address'] = rep($_POST['old_address']);

  //*************************************
  $query = "SELECT * FROM `whitelist` WHERE `address`='".$_POST['old_address']."' ";
  $result = mysql_query($query);
  if (!$result) puterror3($TEXT['error-tbl29']);
      $result2 = mysql_fetch_array($result);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-ex-white-ed'];
  $what = $result2['address']." ".$TEXT['log-na']." ".$_POST['address'];
  $who = $result2['fullname'];
  //*************************************
  $query = "UPDATE `whitelist` SET `address` = '".$_POST['address']."' WHERE `address`='".$_POST['old_address']."' LIMIT 1";
  if(mysql_query($query))
  {
    $query2 = "INSERT INTO tbl_logs ( `log_id` , `data` , `ip` , `who` , `doing` , `what` ) VALUES ( NULL , NOW() , '$ip' , '$who' , '$doing' , '$what')";
        if(mysql_query($query2))
           {
             echo "<html><head>
                   <meta HTTP-EQUIV='Refresh' CONTENT='0; URL=index.php' />
                   </head></html>";
           } else puterror3($TEXT['error-log']);
  } else puterror3($TEXT['error-tbl29']);
  require_once "../../util/bottom.php";
?>
