$tccell1> 		 $tccell2l>
	 $inph=action VALUE=sendmsg>
	 $inps=submit VALUE='Send message'>
	 $inps=preview VALUE='Preview message'>
	$tblend
$tblstart
	 $postlist
	$tblend
	$fonttag$boardname - Private messages
    ";
  }
  if($action=='sendmsg'){
    $userid=checkusername($username);
    if($userid!=-1 and $subject){
	$subject=str_replace('<','<',$subject);
	$sign=$loguser[signature];
	$head=$loguser[postheader];
	if($user[postbg]) $head="$head";
	$numdays=(ctime()-$loguser[regdate])/86400;
	$message=doreplace($message,$loguser[posts],$numdays,$loguser[name]);
	$rsign=doreplace($sign,$loguser[posts],$numdays,$loguser[name]);
	$rhead=doreplace($head,$loguser[posts],$numdays,$loguser[name]);
	$currenttime=ctime();
	if($submit){
	  $headid=getpostlayoutid($head);
	  $signid=getpostlayoutid($sign);
	  mysql_query("INSERT INTO pmsgs (id,userto,userfrom,date,ip,msgread,headid,signid) VALUES (NULL,$userid,$loguserid,$currenttime,'$userip',0,$headid,$signid)");
	  mysql_query("INSERT INTO pmsgs_text (pid,title,text,tagval) VALUES (".mysql_insert_id().",'$subject','$message','$tagval')") or print mysql_error();
	  print "
		$tccell1>Private message to $username sent successfully!.
		
".redirect('private.php','your private message box...',0).$tblend;
	}else{
	  loadtlayout();
	  $ppost=$loguser;
	  $message = stripslashes($message);
	  $username = stripslashes($username);
	  $subject = stripslashes($subject);
	  $ppost[uid]=$loguserid;
	  $ppost[date]=$currenttime;
	  $ppost[headtext]=$rhead;
	  $ppost[signtext]=$rsign;
	  $ppost[text]=$message;
	  if($isadmin) $ip=$userip;
	  print "
		
		$tccellh>Message preview
		$tblend$tblstart
		".threadpost($ppost,1)."
		$tblend
$tblstart