<?php
session_start();
include "../conn/config.php";

//验证是否是给自己打招呼
if($_SESSION['user_id'] == $_SESSION['con_id']){
	echo '<script type="text/javascript">alert("您难道要和自己打招呼吗？");window.close();</script>';
}

//验证写入数据库
if($_POST['sub']){
	$hello = $_POST['hello'];
	$sendid = $_SESSION['user_id'];
	$receiveid = $_SESSION['con_id'];
	$date = date("Y-m-d H:i:s");
	switch($hello){
		case "":
		     echo '<script type="text/javascript">alert("您还没选择表情呢！");history.back();</script>';
	    break;
		case wx:
		     $hello = "微笑";
			 $loca = "../images/hello/wx.gif";
	    break;
		case yb:
		     $hello = "拥抱";
			 $loca = "../images/hello/yb.gif";
	    break;
		case yw:
		     $hello = "依偎";
			 $loca = "../images/hello/yw.gif";
	    break;
		case fw:
		     $hello = "飞吻";
			 $loca = "../images/hello/fw.gif";
		break;
		case jy:
		     $hello = "加油";
			 $loca = "../images/hello/jy.gif";
		break;
		case cyx:
		     $hello = "踩一下";
			 $loca = "../images/hello/cyx.gif";
		break;
		case dyx:
		     $hello = "电一下";
			 $loca = "../images/hello/dyx.gif";
		break;
		case gyq:
		     $hello = "给一拳";
			 $loca = "../images/hello/gyq.gif";
		break;
		case nyy:
		     $hello = "挠痒痒";
			 $loca = "../images/hello/nyy.gif";
		break;
		case pmy:
		     $hello = "抛媚眼";
			 $loca = "../images/hello/pmy.gif";
		break;
		case wgs:
		     $hello = "握个手";
			 $loca = "../images/hello/wgs.gif";
		break;
		case yyk:
		     $hello = "咬一口";
			 $loca = "../images/hello/yyk.gif";
		break;
		case ppjb:
		     $hello = "拍拍肩膀";
			 $loca = "../images/hello/ppjb.gif";
		break;
	}
	
	//获取发送者昵称
	$query = mysql_query("select username from {$total_pr}user where id='".$sendid."'");
	while($rows = mysql_fetch_assoc($query)){
	   $sendname = $rows['username'];	
    }
	
	$query = mysql_query("insert into {$total_pr}hello (face,loca,sendid,sendname,receiveid,status,date) values ('$hello','$loca','$sendid','$sendname','$receiveid','0','$date')");
	
	if($query){
		echo '<script type="text/javascript">alert("纸条发送成功了！");</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/hello.css" />
<title>打招呼</title>
<script type="text/javascript">
  //验证是否选择表情
  function check(){
	  var f = document.forms;
	  var v = 0;
	  for(var i=0;i<f.hello.length;i++){
		  if(f.hello[i].checked){
			 v = myform.hello[i].value;
		  }
		  
		  if(v == 0){
			alert("您还没选择表情呢！");
			return false;
		  }
		  else{
			return true;  
		  }
		  
	  }
  }
</script>
</head>

<body>
  <div id="hello">
    <?php
	  $query = mysql_query("select username from {$total_pr}user where id='".$_SESSION['con_id']."' ");
	  while($row = mysql_fetch_assoc($query)){
		$con = $row['username'];  
	  }
	?>
    <div class="who">向&nbsp;<span class="name"><?=$con ?></span>&nbsp;打招呼</div>
    <form method="post" onsubmit="return check()">
    <div class="face">
       <ul>
         <li>
           <input type="radio" name="hello" value="wx" />
           <img src="../images/hello/wx.gif" />
           <span class="font">微笑</span>
         </li>
         <li>
           <input type="radio" name="hello" value="yb" />
           <img src="../images/hello/yb.gif" />
           <span class="font">拥抱</span>
         </li>
         <li>
           <input type="radio" name="hello" value="yw" />
           <img src="../images/hello/yw.gif" />
           <span class="font">依偎</span>
         </li>
         <li>
           <input type="radio" name="hello" value="fw" />
           <img src="../images/hello/fw.gif" />
           <span class="font">飞吻</span>
         </li>
         <li>
           <input type="radio" name="hello" value="jy" />
           <img src="../images/hello/jy.gif" />
           <span class="font">加油</span>
         </li>
         <li>
           <input type="radio" name="hello" value="cyx"/>
           <img src="../images/hello/cyx.gif" />
           <span class="font">踩一下</span>
         </li>
         <li>
           <input type="radio" name="hello" value="dyx"/>
           <img src="../images/hello/dyx.gif" />
           <span class="font">电一下</span>
         </li>
         <li>
           <input type="radio" name="hello" value="gyq" />
           <img src="../images/hello/gyq.gif" />
           <span class="font">给一拳</span>
         </li>
         <li>
           <input type="radio" name="hello" value="nyy"/>
           <img src="../images/hello/nyy.gif" />
           <span class="font">挠痒痒</span>
         </li>
         <li>
           <input type="radio" name="hello" value="pmy"/>
           <img src="../images/hello/pmy.gif" />
           <span class="font">抛媚眼</span>
         </li>
         <li>
           <input type="radio" name="hello" value="wgs"/>
           <img src="../images/hello/wgs.gif" />
           <span class="font">握个手</span>
         </li>
         <li>
           <input type="radio" name="hello" value="yyk"/>
           <img src="../images/hello/yyk.gif" />
           <span class="font">咬一口</span>
         </li>
         <li>
           <input type="radio" name="hello" value="ppjb"/>
           <img src="../images/hello/ppjb.gif" />
           <span class="font">拍拍肩膀</span>
         </li>
       </ul>
    </div>
    <div class="sub">
      <input type="submit" name="sub" class="s" value="打招呼过去喽^_^" />
      <input type="button" class="eixt" value="算了，懒得和他说" onclick="window.close();" />
    </div>
    </form>
  </div>
</body>
</html>

