<?php
  session_start();
  include "../conn/config.php";
  
  if($_POST['sub']){
	  //接收参数
	  $content = trim($_POST['content']);
	  $sendid = $_SESSION['user_id'];
	  if($_GET['order'] == "re"){
	     $receiveid = $_GET['id'];
	  }
	  $date = date("Y-m-d H:i:s");
	  
	  //判断参数
	  if($content == ""){
		  echo '<script type="text/javascript">alert("纸条内容不能为空！");histroy.back();</script>';
	  }
	  
	  if(strlen($content) > 140){
		  echo '<script type="text/javascript">alert("纸条内容字数不能超过140！");histroy.back();</script>';
	  }
	  
	  
	  $query = mysql_query("select username from {$total_pr}user where id='".$sendid."'");
	  while($row = mysql_fetch_assoc($query)){
		  $sendname = $row['username'];
	  }
	  
	  //写入数据库
	  $query = mysql_query("insert into {$total_pr}paper (content,sendid,sendname,receiveid,status,date) values ('$content','$sendid','$sendname','$receiveid','0','$date')");
	  
	  if($query){
		  echo '<script type="text/javascript">alert("纸条扔出去啦！^_^");window.close();</script>';
	  }
  } 
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link type="text/css" rel="stylesheet" href="../css/throw.css" />
<title>扔纸条</title>
<script type="text/javascript">
   function check_paper(paper){
	   if(paper.content.value == ""){
		   alert("纸条内容不能为空！");
		   paper.content.focus();
		   return false;
	   }
	   
	   return true;
   }
</script>
</head>

<body>  
  <div class="throw_paper">
    <form action="" method="post" onsubmit="return check_paper(this)">
       <h3>扔纸条</h3>
       <div class="throw_con">
              <textarea class="textarea" name="content"></textarea><br />
              <div class="throw_button">
                 <input type="submit" name="sub" class="sub" value="扔出" />
                 <span class="pro">内容在140字以内</span>
                 <input type="reset" name="re" class="re" value="重写" />
              </div>         
       </div>
     </form>
  </div>
</body>
</html>