<?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['tema'])) puterror2($TEXT['error-zhurn3']);
  if(strlen($_POST['tema'])>255) puterror2($TEXT['error-zhurn4']);
  if(empty($_POST['zh_soobschenie'])) puterror2($TEXT['error-zhurn5']);
  if(strlen($_POST['zh_soobschenie'])>70000) puterror2($TEXT['error-zhurn6']);
  if(strlen($_POST['primechanie'])>4000) puterror2($TEXT['error-prim1']);
  if(empty($_POST['position'])) puterror2($TEXT['error-zhurn7']);
  if(strlen($_POST['position'])>6) puterror2($TEXT['error-zhurn8']);
  if(empty($_POST['krit_id'])) puterror2("123".$TEXT['error-zhurn9']);
  if(strlen($_POST['krit_id'])>11) puterror2($TEXT['error-zhurn10']);

  $_POST['zh_str_id'] = rep($_POST['zh_str_id']);
  $_POST['tema'] = rep($_POST['tema']);
  //$_POST['zh_soobschenie'] = addslashes($_POST['zh_soobschenie']);
  $_POST['zh_soobschenie'] = rep2($_POST['zh_soobschenie']);
  $_POST['primechanie'] = rep($_POST['primechanie']);
  $_POST['position'] = rep($_POST['position']);
  $_POST['krit_id'] = rep($_POST['krit_id']);

  $visible = "show";

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-know1'];
  $what = "&laquo;".$_POST['tema']."&raquo;";
  $who = $result2['fullname'];
  //*************************************
  $query = "INSERT INTO `tbl_bd_zhnaniy` ( `zhurn_id` , `krit_id`, `zh_str_id`, `zh_tema`, `zh_soobschenie`, `position`, `visible`, `data`, `login_id`, `primechanie` ) VALUES ( NULL , '".$_POST['krit_id']."', '".$_POST['zh_str_id']."', '".$_POST['tema']."', '".$_POST['zh_soobschenie']."', '".$_POST['position']."' , '$visible', NOW(), '".$result2['login_id']."', '".$_POST['primechanie']."') ";
  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=knowledge.php?zh_str_id=".$_POST['zh_str_id']."' />
                   </head></html>";
           } else puterror2($TEXT['error-log']);
  } else puterror2(mysql_error());
?>
</body>
</html>