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

//删除图片
if($_GET['con'] == "del"){
	$id = $_GET['id'];
	if($id){
		$query = mysql_query("select tname from {$total_pr}picture where id='".$id."'");
		while($row = mysql_fetch_assoc($query)){
			$name = $row['tname'];
		}
		//删除文件夹中图片
		if(is_file('images/uploads/'.$name)){
		   @unlink('images/uploads/'.$name);
		}
		
		//删除数据库表中资料
	    $query = mysql_query("delete from {$total_pr}picture where id='".$id."'");
		
		if($query){
			header("location:picture.php");
		}
	}
}
?>
<!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/style.css" />
<link type="text/css" rel="stylesheet" href="css/jquery.ui.datepicker.css" />
<link type="text/css" rel="stylesheet" href="css/jquery.ui.theme.css" />
<script type="text/javascript" language="javascript" src="js/jquery-1.5.1.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.ui.datepicker.js"></script>
<script type="text/javascript" language="javascript" src="js/jquery.ui.datepicker-zh-CN.js"></script>
<title>查看图片</title>
<script type="text/javascript">
   //判断是否删除
   function delconfirm(id){
	  if(confirm("您真的要删除这张图片吗？") == true){
		  window.location.href = 'picture_show.php?con=del&id='+id;
      }   
   }
   
   //跳转至评论页面
   function com(id){
	      window.open("open/pic_com.php?order=com&id="+id+"","com","left=400,top=200,width=500,height=300");   
   }
</script>
</head>

<body>
<div id="wrap">
<!-------------头部开始-------------->
   <div id="header">
	 <?php
      include "include/top.php";
      ?>
   </div>
<!-------------头部结束-------------->
<!-------------主体部分开始----------->
   <div id="content">
<!-----左侧边栏开始----->
     <div id="left">
	 <?php
      include "include/left2.php";
     ?>
     </div>
<!-----左侧边栏结束------->
<!-----右部分内容开始----->
     <div id="right">
        <?php
		  $id = $_GET['id'];
		  //查询开始id
		  $query = mysql_query("select id from {$total_pr}picture order by id limit 0,1");
		  while($rows = mysql_fetch_assoc($query)){
		      foreach($rows as $key=>$val){
				  $total_s = $val;
			  }
		  }
		  
		  //查询结束id
		  $query = mysql_query("select id from {$total_pr}picture order by id desc limit 0,1");
		  while($rows = mysql_fetch_assoc($query)){
		      foreach($rows as $key=>$val){
				  $total_e = $val;
			  }
		  }
		  
		  //防手动改地址栏id
		  if(!($id > $total_s) || !($id <= $total_e) || !(is_numeric($id)) ){
			  $id = $total_s;
		  }
		  
		  $query = mysql_query("select * from {$total_pr}picture where id='".$id."'");
		  while($rows = mysql_fetch_array($query)){
		?>
        <div class="pic_show">
          <h2>图片名称:<?=$rows['tname'] ?></h2><br />
          <h5>上传日期：<?=$rows['time'] ?></h5><br />
          <div class="pic_bor">
             <div class="pic">
                <img src="<?=$rows['file'] ?>" />
             </div>
          </div>
          <div class="do">
          <?php
			  if($_SESSION['user_id'] != $_SESSION['con_id']){
				echo '<a class="w_com" href="javascript:com('.$rows['id'].')">评论图片</a>';
			  }
		  ?>
          <a class="see_com" href="see_img_com.php?order=see&amp;id=<?=$rows['id'] ?>">查看评论</a>
          <?php
		   //上一张
		   $query = mysql_query("select id from {$total_pr}picture where id <'".$id."' and userid='".$_SESSION['con_id']."' order by id desc limit 0,1");
		   while($r_pre = mysql_fetch_assoc($query)){
		      $pre = $r_pre['id'];
		   }
		   
		   if($pre >= $total_s && !empty($pre)){
				  echo "<a class='pre' href='picture_show.php?id=".$pre."'>上一张</a>";
		   }
		   else{
			   echo "<span class='pre'>上一张</span>";   
		   }
		   
		   //下一张
		   $query = mysql_query("select id from {$total_pr}picture where id >'".$id."' and userid='".$_SESSION['con_id']."' order by id limit 0,1");
		   while($r_next = mysql_fetch_assoc($query)){
		       $next = $r_next['id'];
		   }
		   
		   if($next <= $total_e && !empty($next)){
			   echo "<a class='next' href='picture_show.php?id=".$next."'>下一张</a>";
			   
		   }
		   else{
			   echo "<span class='next'>下一张</span>";   
		   }
		   //删除
		   if($_SESSION['user_id'] == $_SESSION['con_id']){
			   echo "<a class='del' href='javascript:delconfirm(".$rows['id'].")'>删除图片</a>";
		   }
		  ?>
		  </div>
        </div>
        <?php
		  }
		 ?>
     </div>
<!-----右部分内容结束----->
   </div>
<!-------------主体部分结束----------->
<!-------------尾部内容开始----------->
   <div id="footer">
	  <?php
       include "include/bottom.php";
      ?>
   </div>
<!-------------尾部内容结束----------->
</div>
</body>
</html>