<?php
//加关注
if($_GET['change'] == "popu"){
   if($_SESSION['user_id'] != $_SESSION['con_id']){
  
	  $id = $_GET['id'];
	  $query = mysql_query("update {$total_pr}user set popularity=popularity+1 where id='".$id."'");
    }
	else{
	  echo '<script type="text/javascript">alert("您不能给自己加关注！");window.close();</script>';	
	}
}

//加好友
if($_GET['change'] == "join"){
   if($_SESSION['user_id'] != $_SESSION['con_id']){
	  $query = mysql_query("select friendid from {$total_pr}friends where userid='".$_SESSION['user_id']."'");
	  while($row = mysql_fetch_assoc($query)){
		  $frid = $row['friendid'];
	  }
	  if($frid != $_SESSION['con_id']){
		$id = $_GET['id'];
		$username = $_GET['username'];
		$query = mysql_query("insert into {$total_pr}friends(userid,friendid,friendname)
		values('$_SESSION[user_id]','$id','$username')");
	  }
	  else{
		echo '<script type="text/javascript">alert("此用户已经是您的好友了！");</script>';  
	  }
   }
   else{
	 echo '<script type="text/javascript">alert("您不能加自己为好友！");window.close();</script>';	
   }
}
?>
<div class="left_user">
   <div class="user_info">
      <?php
		   $query = mysql_query("select * from {$total_pr}user where id='".$_SESSION['con_id']."'");
		   while($row = mysql_fetch_array($query)){
      ?>
	  <div class="user_pic">
        <div class="border">
         <img src="<?=$row['userpic'] ?>" />
        </div>
      </div> 
      <div class="user_mess">
        <input class="s_hello" type="button" value="打招呼" onclick='window.open("open/hello.php","hello","left=500,top=300,width=400,height=300");' />
        <input class="f_join" type="button" value="加好友" onclick="javascript:location.href='index.php?change=join&name=<?php echo $row['username'] ?>&id=<?php echo $row[id] ?>'" />
        <input class="w_mess" type="button" value="写留言" onclick='window.open("open/le_mess.php","le_mess","left=400,top=250,width=500,height=300");' />
        <input class="s_popu" type="button" value="加关注" onclick="javascript:location.href='index.php?change=popu&id=<?php echo $row[id] ?>'" />
      </div>
      <div class="user_instru">
         <ul>
           <li class="grade">博客等级：<span><?=$row['grade'] ?></span></li>
           <li>博客积分：<span><?=$row['point'] ?></span></li>
           <li>博客访问：<span><?=$row['visitnum'] ?></span></li>
           <li>关注人气：<span><?=$row['popularity'] ?></span></li>
         </ul>       
      </div>
	  <?php
		   }
	  ?>
   </div>
   <div id="new_words">
     <div class="words_title">
      <h4>最新博文</h4>
     </div>
 <?php
   $query = mysql_query("select * from {$total_pr}article where userid='".$_SESSION['con_id']."' order by id desc limit 0,8");
   $rows = mysql_fetch_array($query);
   if($rows == false){
	   if($_SESSION['user_id'] == $_SESSION['con_id']){
     	   echo '<div class="left_no_art">您还没有<a href="art_upload.php">发表</a>任何文章</div>'; 
	   }
	   else{
		   echo '<div class="left_no_art">他还没有发表任何文章</div>'; 
	   }
   }
   else{
	 do{
 ?>
 <ul>
   <li><a href="./art_show.php?id=<?php echo $rows['id'] ?>">
    <?php
	 echo substr($rows['title'],0,24);
	 if(strlen($rows['title'])>24){
	   echo "...";	 
	 }
	?>
   </a></li>
 </ul>
 <?php
	 }
	 while($rows = mysql_fetch_array($query));
   }
 ?>
</div>
</div>