<?php
  ///////////////////////////////////////////////////
  //2010 (C)
  //Карпухин Павел
  ///////////////////////////////////////////////////

  $lang = substr($_SERVER["HTTP_ACCEPT_LANGUAGE"], 0,2);
  if(is_file ("lang/".$lang.".php")) include "lang/".$lang.".php";
     else include "lang/ru.php";

  $title=$titlepage=$TEXT['menu-btn17'];

  require_once "config.php";
  require_once "utils/top_zayavka_otv.php";

  if(empty($_POST['zay_id'])) puterror($TEXT['error-supp6']);
  if(strlen($_POST['zay_id'])>11) puterror($TEXT['error-supp7']);
  if(empty($_POST['description'])) puterror($TEXT['error-supp2']);
  if(strlen($_POST['description'])>20000) puterror($TEXT['error-supp3']);
  if(empty($_POST['kod'])) puterror($TEXT['error-supp9']);
  if(strlen($_POST['kod'])>300) puterror($TEXT['error-supp8']);
  $_POST['zay_id'] = rep($_POST['zay_id']);
  $_POST['description'] = rep($_POST['description']);
  $_POST['kod'] = rep($_POST['kod']);

  $passwd = md5($_POST['kod']);

        $query7 = "SELECT `kod` FROM `tbl_supp_zayavka` WHERE `zay_id` = '".$_POST['zay_id']."'";
           $zay_tmp7 = mysql_query($query7);
              if(!$zay_tmp7) puterror($TEXT['error-tbl26']);
                 $zay7 = mysql_fetch_array($zay_tmp7,MYSQL_ASSOC);
                    $zay_pass = $zay7['kod'];

   if($passwd !== $zay_pass) puterror($TEXT['error-supp9']);

  $query = "UPDATE `tbl_supp_zayavka` SET `problema` = '".$_POST['description']."' WHERE `zay_id`='".$_POST['zay_id']."'";
  if(mysql_query($query))
  {
        $query5 = "SELECT `zay_id`, `usr_id` FROM `tbl_supp_zayavka` WHERE `zay_id` = '".$_POST['zay_id']."'";
           $zay_tmp = mysql_query($query5);
              if(!$zay_tmp) puterror($TEXT['error-tbl26']);
                 $zay = mysql_fetch_array($zay_tmp,MYSQL_ASSOC);

         $query6 = "SELECT `familiya`, `name`, `otchestvo` FROM `tbl_users` WHERE `user_id` = '".$zay['usr_id']."'";
           $usr_tmp = mysql_query($query6);
              if(!$usr_tmp) puterror($TEXT['error-tbl2']);
                 $usr = mysql_fetch_array($usr_tmp,MYSQL_ASSOC);
                    $usr_name = $usr['familiya']." ".$usr['name']." ".$usr['otchestvo'];
                     $zay_num = $_POST['zay_id'];
        //*************************************
        $ip = $_SERVER['REMOTE_ADDR'];
        $doing = $TEXT['error-supp10'];
        $what = $TEXT['support1'].$_POST['zay_id'];
        $who = $usr_name;
        //*************************************
    $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=zayavka_otv.php' />
                   </head></html>";
           } else puterror($TEXT['error-log']);
  } else puterror($TEXT['error-tbl26']);
  require_once "utils/bottom_search.php";
?>