<?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['pho-title'];
  $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(empty($_POST['meropriyatie'])) puterror2($TEXT['error-pho1']);
  if(strlen($_POST['meropriyatie'])>800) puterror2($TEXT['error-pho2']);
  if(empty($_POST['position'])) puterror2($TEXT['error-pho3']);
  if(strlen($_POST['position'])>11) puterror2($TEXT['error-pho4']);
  if(strlen($_POST['org_id'])>11) puterror2($TEXT['error-org1']);
  if(empty($_POST['org_id'])) puterror2($TEXT['error-org10']);

  if($_POST['visible'] == "on") $visible = "show";
    else $visible = "hide";

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

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

  $_POST['meropriyatie'] = rep($_POST['meropriyatie']);
  $_POST['position'] = rep($_POST['position']);
  $_POST['org_id'] = rep($_POST['org_id']);

  //*************************************
  $ip = $_SERVER['REMOTE_ADDR'];
  $doing = $TEXT['log-pho1'];
  $what = $_POST['meropriyatie'];
  $who = $result2['fullname'];
  //*************************************
  $query = "INSERT INTO `tbl_meropriyatiya` ( `mer_id` , `meropriyatie`, `position`, `visible`, `org_id` ) VALUES ( NULL , '".$_POST['meropriyatie']."', '".$_POST['position']."', '$visible', '".$_POST['org_id']."') ";
  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-pho7']);
  require_once "../util/bottom.php";
?>
