<?php
session_start();
include "../conn/config.php";
if($_POST['sub']){
 if($_GET['order'] == "throwAll"){
	 //接收参数
	  $type = $_GET['type'];
	  $idAll = explode("*",$_GET['con']);
	  $idAll_len = count($idAll);
	  $content = trim($_POST['content']);
	  $sendid = $_SESSION['user_id'];
	  $sendname = "管理员";
	  $date = date("Y-m-d H:i:s");
	  
	  //判断参数
	  if($content == ""){
		  echo '<script type="text/javascript">alert("纸条内容不能为空！");histroy.back();</script>';
	  }
	  
	  if(strlen($content) > 280){
		  echo '<script type="text/javascript">alert("纸条内容字数不能超过140！");histroy.back();</script>';
	  }
	  
	  $count = 0;
	  for($i=0;$i<$idAll_len;$i++){
		  $sql = mysql_query("insert into {$total_pr}paper(content,sendid,sendname,receiveid,status,date) values('$content','$sendid','$sendname','".$idAll[$i]."','0','$date') ");
		  $count++;
	  }
	  if($sql){
	   if($count == $idAll_len){
		 echo '<script type="text/javascript">alert("扔给'.$idAll_len.'个用户的纸条已成功发送！");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>