<?php
include("../conn.php");
include_once("../function.php");

$urlzz=$_GET['urlzz'];
if($urlzz==1){
$id=$_GET["id"];
}else{
$id=sqlstr($_SERVER['QUERY_STRING']);
}
if(!is_numeric($id)){
header("Location:../index.php");
exit;//没ID就跳转到登录页面
}
$uinfo=mysql_fetch_array(mysql_query("select * from user where id='$id'"));
$username=$uinfo["name"];
$bt=$username;
include("../head.php");

$sid=sqlstr($_COOKIE["dl"]);
$user=mysql_fetch_array(mysql_query("select * from user where sid='$sid'"));
$uid=$user["id"];
if($id=="" || $uid==$id){
header("Location:/m/diary/all.php");
exit;//没ID就跳转到登录页面
}

if(mysql_fetch_array(mysql_query("select * from att where fid=${uid} and bid=${id}"))){
$attzt='　<a href="outatt.php?id='.$id.'">-取消关注</a>';
}
else{
$attzt='　<a href="addatt.php?id='.$id.'">+关注此人</a>';
}

$qm=$uinfo["qm"];
if(stripos($uinfo["tx"],"http")!==false){
$tx=$uinfo["tx"];
}else{
$tx="/m/img.php?t=http://".$_SERVER['SERVER_NAME'].$uinfo["tx"];
}

$URL_="/image/tx/../../image/tx/";
$f=str_replace($URL_,"",$tx);

$page=sqlstr($_GET['page']);
echo '<div class="hui"><div class="zuo">'.$username.'公开的日记</div><div class="you"><a href="/m/diary/diary.php">流年时刻</a></div></div>';

echo '<div id="main"><div><span class="zuo"><img src="'.$tx.'" alt="头像" height="50" width="50" /></span><span class="you">　<font color="red"><b>'.$uinfo["name"].'</b></font><br/>'.$attzt.'</span></div><br>”'.$qm.'”</div>';
$max=mysql_num_rows(mysql_query("SELECT * FROM diary WHERE diarywriteid='$id' AND diaryzz='1'"));
$p=ceil($max/10);
if(!$page or $page>$p){
$page=1;
}
$low=10*($page-1);//开始查询的条数
$pagesize=10;//每页查询的条数
$rs=mysql_query("SELECT * FROM diary WHERE diarywriteid='$id' AND diaryzz='1' ORDER BY diarytime DESC LIMIT {$low},{$pagesize}");//列出最新公开的日记


while($uinfo=mysql_fetch_array($rs)){

$time=ytime($uinfo['diarytime'])." ".wtime($uinfo['diarytime']); 

$timess=$uinfo["diarytime"];
$htime=htime($timess);
$today=date("d M Y",$timess);
$jt=strtotime($today);
$mt=$jt+86400;
$rws=mysql_fetch_array(mysql_query("SELECT * FROM diary WHERE diarywriteid='$id' AND diaryzz='1' and diarytime>'$jt' and diarytime<'$mt' ORDER BY diarytime DESC LIMIT {$low},{$pagesize}"));
$timem=$rws["4"];

if($timess>$jt and $timess<$timem){

echo '<div id="main"><div class="time">'.$htime .'</div>'.$uinfo["diarytxt"].'</div>';
}else{
echo '<div id="main"> <div class="youlist"><div class="time">'.$time.'</div></div><div class="time">'.$htime.'</div>'.$uinfo["diarytxt"].'</div>';
}


}

echo '<br/><div class="hui"><center>';
if($max){
if($page>1){
$pag=$page-1;
echo '<center><a href="index.php?id='.$id.'&urlzz=1&page='.$pag.'">«更近的</a>　';
} if($page<$p){
$page=$page+1;
echo  '　<a href="index.php?id='.$id.'&urlzz=1&page='.$page.'">更远的»</a>';
}
$pa=$page-1;
echo '</center>';
echo '<div class="zuo">共'.$p.'页/第'.$pa.'页/'.$max.'篇公开日记</div><div class="you"><a href="#C1">顶部</a></div></div>';
}else{
echo '他还没有发布日记哦<br/>';
}

?>
<?php include("../footer.php"); ?>