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

//注册session
if($_GET['id']){
$_SESSION['con_id'] = $_GET['id'];
}

//判断是否登陆
if($_SESSION['con_id'] == ""){
	header("location:login.php");
}

//是否访客
if($_SESSION['user_id'] != $_SESSION['con_id']){
	$uid = $_SESSION['con_id'];
	$visitorid = $_SESSION['user_id'];
	$time = date("Y-m-d");
	$query = mysql_query("select * from {$total_pr}user where id='".$visitorid."'");
	while($rows = mysql_fetch_assoc($query)){
		$visitorname = $rows['username'];
		$visitorimg = $rows['userpic'];
	} 
	
	$query = mysql_query("update {$total_pr}user set visitnum=visitnum+1 where id='".$_SESSION['con_id']."'");
	 
    $query = mysql_query("insert into {$total_pr}visited (userid,visitorid,visitor_name,visitor_img,time) values ('$uid','$visitorid','$visitorname','$visitorimg','$time') where id='".$_SESSION['con_id']."'");	
}
    $query = mysql_query("select * from {$total_pr}user where id='".$_SESSION['con_id']."'");
	while($rows = mysql_fetch_assoc($query)){
		$visitnum = $rows['visitnum'];
		$point = $rows['point'];
		$popularity = $rows['popularity'];
    }
	$total_num = $visitnum + $point + $popularity;
	$grade = floor($total_num/50);
	
	mysql_query("update {$total_pr}user set grade='".$grade."' where id='".$_SESSION['con_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" />
<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>
</head>

<body>
<div id="wrap">
<!-------------头部开始-------------->
   <div id="header">
	 <?php
      include "include/top.php";
      ?>
   </div>
<!-------------头部结束-------------->
<!-------------主体部分开始----------->
   <div id="content">
<!-----左侧边栏in开始----->
     <div id="left">
	 <?php
      include "include/left_in.php";
     ?>
     </div>
<!-----左侧边栏in结束----->
<!-----有部分内容开始----->
     <div id="right">
        <div class="article">
         <?php
          $sql = mysql_query("select * from {$total_pr}article where userid='".$_SESSION['con_id']."'");
          $total = mysql_num_rows($sql);
          $pagesize = 2;
          
          $page = new page($total,$pagesize);
          
          $sql = "select * from {$total_pr}article where userid='".$_SESSION['con_id']."' order by id desc {$page->limit} ";
          $result = mysql_query($sql);
          $rows = mysql_fetch_array($result);
		  if($rows == false){
			  if($_SESSION['user_id'] == $_SESSION['con_id']){
			     echo '<div class="no_art">您还没有<a href="art_upload.php">发表</a>任何文章</div>'; 
			  }
			  else{
				 echo '<div class="no_art">他还没有发表任何文章</div>'; 
			  }
		  }
		  else{
			do{
         ?>
           <h2><?=$rows['title'] ?>&nbsp;<span class="date">(<?=$rows['atime'] ?>)</span></h2>
           <div class="article_con">
              <div class="article_con_c">
               <?php
			     echo substr($rows['content'],0,1200);
				 if(strlen($rows['content']) > 1200){
					 echo "..........";
				 }
			   ?>
               </div>
               <div class="article_con_show">
               <span class="read">阅读（<?=$rows['times'] ?>）&nbsp;|
               <?php
			     $query = mysql_query("select id from {$total_pr}art_comment where art_id='".$rows['id']."'");
				 $num = mysql_num_rows($query);
			   ?>
               </span><span class="com">&nbsp;评论（<?=$num ?>）</span>
                <a class="see" href="art_show.php?id=<?php echo $rows[id] ?>">查看全文>></a>
             </div>
           </div>
		   <?php
            }
             while($rows = mysql_fetch_array($result));
            }
           ?>
         </div>
         <div class="page">
          <?php echo $page->fpage() ?>
         </div>
     </div>
<!-----右部分内容结束----->
   </div>
<!-------------主体部分结束----------->
<!-------------尾部内容开始----------->
   <div id="footer">
	  <?php
       include "include/bottom.php";
      ?>
   </div>
<!-------------尾部内容结束----------->
</div>
</body>
</html>