<?php
session_start();
include "conn/config.php";
include "include/class/page.class.php";
//删除好友
if($_GET['con'] == "del"){
	$id = $_GET['id'];
	$query = mysql_query("delete from {$total_pr}friends where friendid='".$id."'");
}
?>
<!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" />
<title>我的好友</title>
<script type="text/javascript">
  //打开扔纸条窗口
  function open_throw(id){
	  window.open("open/throw_paper.php?order=re&id="+id+"","throw_paper","top=300,left=500,width=300,height=160,resizable=no")
  }
  
  //是否删除
  function del(de){
	  if(confirm("您真的要将此好友从您的好友列表中删除吗？") == true){
		  window.location.href = "friends.php?con=del&id="+de+"";
	  }
  }
</script>
</head>

<body>
<div id="wrap">
<!-------------头部开始-------------->
   <div id="header">
	 <?php
      include "include/top.php";
      ?>
   </div>
<!-------------头部结束-------------->
<!-------------主体部分开始----------->
   <div id="content">
<!-----左侧边栏开始----->
     <div id="left">
	 <?php
      include "include/left.php";
     ?>
     </div>
<!-----左侧边栏结束----->
<!-----有部分内容开始----->
     <div id="right">
        <div class="friends_list">
          <div class="title">
            <h2>好友列表<span class="find_f"><a href="find_friends.php">查找好友</a></span></h2>
          </div>
          <div class="list">
              <ul>
              <?php
			  $sql = mysql_query("select * from {$total_pr}friends where userid='".$_SESSION['user_id']."'");
			  $total = mysql_num_rows($sql);
			  $pagesize = 8;
			  
			  $page = new page($total,$pagesize,"个好友");
		  
              $query = mysql_query("select * from {$total_pr}friends where userid='".$_SESSION['user_id']."' order by id desc {$page->limit}");
              $row = mysql_fetch_array($query);
              if($row == false){
                  if($_SESSION['user_id'] == $_SESSION['con_id']){
                     echo '<div class="no_friends">您还没有<a href="find_friends.php">添加</a>任何好友</div>'; 
                  }
                  else{
                     echo '<div class="no_friends">他还没有添加任何好友</div>'; 
                  }
              }
              else{
                do{
              ?>
                <li>
                <span class="name"><a href="index.php?id=<?=$row['friendid'] ?>"><?=$row['friendname'] ?></a></span>
                <span class="del_friend"><a href="javascript:del(<?=$row['friendid'] ?>)">删除好友</a></span>
                <span class="throw_paper"><a href="javascript:open_throw('<?=$row["friendid"] ?>')">扔纸条</a></span>
                </li>
              <?php
              }
              while($row = mysql_fetch_array($query));
              }
              ?>
              </ul>
            </div>
            <div class="page">
              <?php echo $page->fpage() ?>
            </div>
        </div>
     </div>
<!-----左侧边栏结束----->
   </div>
<!-------------主体部分结束----------->
<!-------------尾部内容开始----------->
   <div id="footer">
	  <?php
       include "include/bottom.php";
      ?>
   </div>
<!-------------尾部内容结束----------->
</div>
</body>
</html>