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

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

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

  if(strlen($_POST['ind'])>9) puterror2($TEXT['error-forecast1']);
  if(strlen($_POST['country'])>255) puterror2($TEXT['error-forecast2']);
  if(strlen($_POST['region'])>255) puterror2($TEXT['error-forecast3']);
  if(empty($_POST['station'])) puterror2($TEXT['error-forecast4']);
  if(strlen($_POST['station'])>255) puterror2($TEXT['error-forecast8']);
  if(empty($_POST['dat'])) puterror2($TEXT['error-forecast9']);
  if(strlen($_POST['dat'])>10) puterror2($TEXT['error-forecast10']);
  if(strlen($_POST['tday'])>6) puterror2($TEXT['error-forecast11']);
  if(strlen($_POST['tnight'])>6) puterror2($TEXT['error-forecast12']);
  if(strlen($_POST['prec'])>6) puterror2($TEXT['error-forecast13']);
  if(strlen($_POST['prec_prob'])>6) puterror2($TEXT['error-forecast14']);
  if(strlen($_POST['wind_dir'])>6) puterror2($TEXT['error-forecast15']);
  if(strlen($_POST['wind_speed'])>6) puterror2($TEXT['error-forecast16']);
  if(strlen($_POST['weather_cond'])>255) puterror2($TEXT['error-forecast17']);
  if(strlen($_POST['pday'])>6) puterror2($TEXT['error-forecast18']);
  if(strlen($_POST['pnight'])>6) puterror2($TEXT['error-forecast19']);

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

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

  $_POST['ind'] = rep($_POST['ind']);
  $_POST['country'] = rep($_POST['country']);
  $_POST['region'] = rep($_POST['region']);
  $_POST['station'] = rep($_POST['station']);
  $_POST['dat'] = rep($_POST['dat']);
  $_POST['tday'] = rep($_POST['tday']);
  $_POST['tnight'] = rep($_POST['tnight']);
  $_POST['prec'] = rep($_POST['prec']);
  $_POST['prec_prob'] = rep($_POST['prec_prob']);
  $_POST['wind_dir'] = rep($_POST['wind_dir']);
  $_POST['wind_speed'] = rep($_POST['wind_speed']);
  $_POST['weather_cond'] = rep($_POST['weather_cond']);
  $_POST['pday'] = rep($_POST['pday']);
  $_POST['pnight'] = rep($_POST['pnight']);

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-forecast1'];
  $what = $_POST['station']." ".$_POST['dat'];
  $who = $result2['fullname'];
  //*************************************
  $query = "INSERT INTO tbl_forecast (`ind`, `station`, `country`, `region`, `dat`, `tday`, `tnight`, `prec`, `prec_prob`, `wind_dir`, `wind_speed`, `weather_conditions`, `pday`, `pnight`)
                            VALUES  ('".$_POST['ind']."', '".$_POST['station']."', '".$_POST['country']."', '".$_POST['region']."', '".$_POST['dat']."', '".$_POST['tday']."', '".$_POST['tnight']."', '".$_POST['prec']."', '".$_POST['prec_prob']."', '".$_POST['wind_dir']."', '".$_POST['wind_speed']."', '".$_POST['weather_cond']."', '".$_POST['pday']."', '".$_POST['pnight']."')";
  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-forecast22']);
  require_once "../util/bottom.php";
?>
