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

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

  if($result2['user'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['master'] == 1) puterror2($TEXT['error-loginform4']);
  if($result2['manager'] == 1) puterror2($TEXT['error-loginform4']);

  if(empty($_POST['dom_id'])) puterror2($TEXT['error-domain5']);
  if(strlen($_POST['dom_id'])>11) puterror2($TEXT['error-domain6']);
  if(empty($_POST['domain'])) puterror2($TEXT['error-domain1']);
  if(strlen($_POST['domain'])>200) puterror2($TEXT['error-domain2']);

  if(isset($_POST['domain'])) $domain=trim($_POST['domain']);
    else $domain="";
     if (empty($domain)) puterror2($TEXT['error-domain3']);

  $_POST['domain'] = rep($_POST['domain']);
  $_POST['dom_id'] = rep($_POST['dom_id']);

  $query_chk = "SELECT `domain` FROM `tbl_domain` WHERE `domain`='".$_POST['domain']."' ";
     $result_chk = mysql_query($query_chk);
     if (!$result_chk) puterror2($TEXT['error-tbl4']);
       if (mysql_num_rows($result_chk)>0) puterror2($TEXT['global-est']);

  //*************************************
  $query = "SELECT * FROM `tbl_domain` WHERE `dom_id`='".$_POST['dom_id']."' ";
  $result = mysql_query($query);
  if (!$result) puterror2($TEXT['error-tbl5']);
      $result2 = mysql_fetch_array($result);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-domain3'];
  $what = $result2['domain'].$TEXT['log-na'].$_POST['domain'].$TEXT['log-id'].$_POST['dom_id'];
  $who = $result2['fullname'];
  //*************************************
  $query = "UPDATE `tbl_domain` SET `domain` = '".$_POST['domain']."' WHERE `dom_id`='".$_POST['dom_id']."' 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 puterror2($TEXT['error-log']);
  } else puterror2($TEXT['error-domain8']);
  require_once "../util/bottom.php";
?>
