<?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['size-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['size_id'])) puterror2($TEXT['error-size5']);
  if(strlen($_POST['size_id'])>2) puterror2($TEXT['error-size6']);
  if(empty($_POST['size_name'])) puterror2($TEXT['error-size1']);
  if(strlen($_POST['size_name'])>100) puterror2($TEXT['error-size2']);

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

  $_POST['size_name'] = rep($_POST['size_name']);
  $_POST['size_id'] = rep($_POST['size_id']);

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

  //*************************************
  $query1 = "SELECT * FROM `tbl_sizes` WHERE `size_id`='".$_POST['size_id']."' ";
  $result = mysql_query($query1);
      if (!$result) puterror2($TEXT['error-tbl35']);
       $result2 = mysql_fetch_array($result);

  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-size3'];
  $what = $result2['size_name'].$TEXT['log-na'].$_POST['size_name'].$TEXT['log-id'].$_POST['size_id'];
  $who = $result2['fullname'];
  //*************************************

  $query = "UPDATE `tbl_sizes` SET `size_name` = '".$_POST['size_name']."' WHERE `size_id`='".$_POST['size_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-size8']);
  require_once "../util/bottom.php";
?>
