<?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['zhurn-new'];
  $helppage = $TEXT['zhurn-new-help'];

  require_once "../config.php";
  require_once "top.php";
  ?>
  <title><?php echo $title; ?></title>
  <link rel="StyleSheet" type="text/css" href="../utils/grid.css" />
  </head>
  <body>
  <?php
  if(empty($_POST['zh_str_id'])) puterror2($TEXT['error-zhurn1']);
  if(strlen($_POST['zh_str_id'])>11) puterror2($TEXT['error-zhurn2']);
  if(empty($_POST['zhurn_id'])) puterror2($TEXT['error-zhurn11']);
  if(strlen($_POST['zhurn_id'])>11) puterror2($TEXT['error-zhurn12']);
  if(strlen($_POST['otkr'])>1) puterror2($TEXT['error-zhurn12']);
  if(empty($_POST['zh_soobschenie'])) puterror2($TEXT['error-zhurn5']);
  if(strlen($_POST['zh_soobschenie'])>4000) puterror2($TEXT['error-zhurn6']);

  $_POST['zh_str_id'] = rep($_POST['zh_str_id']);
  $_POST['zhurn_id'] = rep($_POST['zhurn_id']);
  $_POST['zh_soobschenie'] = addslashes($_POST['zh_soobschenie']);
  $_POST['otkr'] = rep($_POST['otkr']);

    $query4 = "SELECT zh_tema FROM tbl_bd_zhnaniy WHERE zhurn_id = ".$_POST['zhurn_id']."";
    $tmp4 = mysql_query($query4);
     if(!$tmp4) puterror2(mysql_error());
     $sost4 = mysql_fetch_array($tmp4,MYSQL_ASSOC);
  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-know6'];
  $what = $TEXT['log-know6']." ".$TEXT['log-know5']."&laquo;".$sost4['zh_tema']."&raquo;";
  $who = $result2['fullname'];
  //*************************************
  $query = "INSERT INTO `tbl_know_prim` ( `tr_id` , `zhurn_id`, `login_id`, `zh_primechanie`, `data` ) VALUES ( NULL , '".$_POST['zhurn_id']."', '".$result2['login_id']."', '".$_POST['zh_soobschenie']."', NOW() ) ";
  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=know_view.php?zh_str_id=".$_POST['zh_str_id']."&amp;zhurn_id=".$_POST['zhurn_id']."&amp;otkr=".$_POST['otkr']."' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2(mysql_error());
?>
</body>
</html>