<?php
session_start();
include "../conn/config.php";
if($_SESSION['user_id'] == ""){
	echo "<script type='text/javascript'>alert('请先登陆再评论！');window.close();opener.location.href = 'login.php';</script>";
}
  
if($_GET['order'] == "com"){
	  $id = $_GET['id'];
}
  
if($_POST['sub']){ 
  $content = trim($_POST['con']);
  $comid = $_SESSION['user_id'];
  $receiveid = $_SESSION['con_id'];
  $date = date("Y-m-d H:i:s");
  
  //判断字数
  if($content == ""){
	  echo '<script type="text/javascript">alert("评论不能为空！");history.back();</script>';
  }
  elseif(strlen($content) > 400){
	  echo '<script type="text/javascript">alert("评论字数不d能超过200！");history.back();</script>';
  }
  
  $query = mysql_query("select * from {$total_pr}user where id='".$_SESSION['user_id']."'");
  while($row = mysql_fetch_assoc($query)){
	$user = $row['username'];  
  }
  
  //写入数据库
  $query = mysql_query("insert into {$total_pr}img_comment(img_id,content,comid,comname,receiveid,status,date) values ('$id','$content','$comid','$user','$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/comment.css" />
<title>图片评论</title>
<script type="text/javascript">
  function che(){
	 if(form.con.value == ""){
		 alert("评论不能为空！");
		 form.con.focus();
		 return false;
	 }  
	 
	 if(form.con.length > 200){
		 alert("评论字数不能超过200！");
		 form.con.focus();
		 return false;
	 }
	 
	 return true;
  }
</script>
</head>

<body>
  <div class="com">
    <?php
	  $query = mysql_query("select tname from {$total_pr}picture where id='".$id."'");
	  while($row = mysql_fetch_assoc($query)){
		  $name = $row['tname'];
	  }
	?>
    <div class="title">
      对图片<span class="t"><?=$name ?></span>的评论：
    </div>
    <div class="pro">文章字数不能超过200</div>
    <form method="post" name="form" onsubmit="return che()">
        <textarea name="con" class="con"></textarea>
      <input type="submit" name="sub" class="sub" value="提交评论" />
      <input type="reset" name="re" class="re" value="重写评论" />
    </form>
  </div>
</body>
</html>