<?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['hostlst-ed'];
  $helppage = "";

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

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

  if(empty($_POST['host'])) puterror3($TEXT['hostlst-error1']);
  if(strlen($_POST['host'])>65) puterror3($TEXT['hostlst-error2']);
  if(empty($_POST['old_hostname'])) puterror3($TEXT['hostlst-error1']);
  if(strlen($_POST['old_hostname'])>65) puterror3($TEXT['hostlst-error2']);
  if(empty($_POST['tip'])) puterror3($TEXT['error-tip1']);
  if(strlen($_POST['tip'])>9) puterror3($TEXT['error-tip2']);

  if(isset($_POST['host'])) $host=trim($_POST['host']);
    else $host="";
     if (empty($host)) puterror3($TEXT['hostlst-error3']);

  if(isset($_POST['old_hostname'])) $old_hostname=trim($_POST['old_hostname']);
    else $old_hostname="";
     if (empty($old_hostname)) puterror3($TEXT['hostlst-error3']);

  $_POST['host'] = rep($_POST['host']);
  $_POST['old_hostname'] = rep($_POST['old_hostname']);
  $_POST['tip'] = rep($_POST['tip']);

  //*************************************
  $query = "SELECT * FROM `hostlists` WHERE `hostname`='".$_POST['old_hostname']."' ";
  $result = mysql_query($query);
  if (!$result) puterror3($TEXT['error-tbl30']);
      $result2 = mysql_fetch_array($result);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-ex-host-ed'];
  $what = $result2['hostname']." (".$result2['type'].")".$TEXT['log-na'].$_POST['host']." (".$_POST['tip'].")";
  $who = $result2['fullname'];
  //*************************************
  $query = "UPDATE `hostlists` SET `hostname` = '".$_POST['host']."', `type` = '".$_POST['tip']."' WHERE `hostname`='".$_POST['old_hostname']."' 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-tbl30']);
  require_once "../../util/bottom.php";
?>
