<?php
session_start();
include "conn/config.php";
include "include/class/page.class.php";
//加为好友
if($_GET['ch'] == "join"){
	$id = $_GET['id'];
	$username = $_GET['name'];
	$query = mysql_query("insert into {$total_pr}friends(userid,friendid,friendname) values('$_SESSION[user_id]','$id','$username')");
	if($query){
		header("location:friends.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" />
<title>尘烟博客</title>
</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="search">
         <form action="result_friends.php" method="post">
          <input type="text" class="search_con" name="search_con" />
          <input type="submit" value="查找好友" class="sub" name="sub" />
         </form>
        </div>
        <div class="find_friends_list">
          <ul>
          <?php
		  $sql = mysql_query("select * from {$total_pr}user");
          $total = mysql_num_rows($sql);
          $pagesize = 14;
          
          $page = new page($total,$pagesize,"个用户");
		  
		  $query = mysql_query("select * from {$total_pr}user order by grade {$page->limit}");
		  while($row = mysql_fetch_array($query)){
		  ?>
            <li>
            <a href="index.php?id=<?=$row['id'] ?>"><?=$row['username'] ?></a>
            <?php
            if($_SESSION['user_id'] != $row['id']){
			   $query2 = mysql_query("select * from {$total_pr}friends where friendid='".$row['id']."' and userid='".$_SESSION['user_id']."'");
			   $row2 = mysql_num_rows($query2);
			   if($row2 == 0){
			      echo '<span class="join_f"><a href="find_friends.php?ch=join&name='.$row['username'].'&id='.$row['id'].'">加为好友</a></span>';
			   }
			   else{
				  echo '<span class="join_no">已为好友</span>'; 
			   }
			}
			else{
			   echo '<span class="join_no">不可添加</span>';
			}
		  }
		  ?>
          </ul>
        </div>
        <div class="page">
          <?php echo $page->fpage() ?>
         </div>
     </div>
<!-----左侧边栏结束----->
   </div>
<!-------------主体部分结束----------->
<!-------------尾部内容开始----------->
   <div id="footer">
	  <?php
       include "include/bottom.php";
      ?>
   </div>
<!-------------尾部内容结束----------->
</div>
</body>
</html>