<?
if($_POST['submit'] || $_POST['submit2'])
{
if($_POST['submit'])
	{
	$ms ='ishod';
	$pr = 0;
	}
elseif($_POST['submit2'])
	{
	$ms ='pr';
	$pr = 1;
	}

$me=_pre2($_POST['mess']);
$mess=$me[1];
if(!$mess) $err .= "Введите текст сообщения<br>";

if(!$err)
	{
	if($vizavi===0)
		{
		$autor_komu='Администратор';
		$komu=0;
		}
	else
		{
		$r=mysql_query("SELECT id_akk, contakt FROM akk WHERE id_akk='".$vizavi."'");
		$rr=mysql_fetch_array($r);
		$autor_komu=$rr['contakt'];
		}
	

	$query="INSERT INTO mess (
	ot_kogo,
	autor,
	autor_komu,
	komu,
	mess,
	data,
	pr
	)
	VALUES
	(
	'".$_SESSION['ID_P'][1]."',
	'".$_SESSION['ID_P'][3]."',
	'".$autor_komu."',
	'".$vizavi."',
	'".$mess."',
	NOW(),
	'".$pr."'
	)
	";
	mysql_query($query);
	echo "<HTML><HEAD><meta http-equiv='Refresh' charset='utf-8' content='0; URL=mess_u.php?ms=".$ms."'></HEAD></HTML>";
	exit();
	}

}


if($err) echo '<p><font color=red>'.$err.'</font></p>'; 

?>
<table>
	<tr>
		<td>
		<form method="post" action="" >
			<textarea rows="20" cols="80" name="mess" ><?=stripslashes(htmlspecialchars_decode($mess))?></textarea>
			<input type="hidden" name="vizavi" value="<?=$vizavi?>">
			<br>
			<input type="submit" name="submit" class="submit" value="Отправить">
			<input type="submit" name="submit2" class="submit" value="Положить в папку ИСХОДЯЩИЕ">
		</form>
		</td>
	</tr>
</table>