<?
		
		$iserror = 0;
		$page = (isset($page) && $page > 0) ? $page : 1;
				
		if(!is_numeric($bid) or $bid<1){
				$iserror = 1;
				$url = array();
				$tourl = URL_book_index($url);
				$pagecontent = "<b>提醒：</b><br/>";
				$pagecontent .= "不存在的作品！<br/>";
				$pagecontent .= ">>".backurl()."<br/>";	
		}

		$dirid = intval($bid/1000);
		$cachefilepath = HON6_ROOT."/cache/book/chapter/".$dirid."/".$bid."/".$cid.".cache";
		$txtfilepath = PRO_ROOT."/files/article/txt/".$dirid."/".$bid."/".$cid.".txt";
		
		if(!file_exists($txtfilepath) or !is_numeric($cid) or $cid<1){
				$iserror = 1;
				$url = array("bid"=>$bid);
				$tourl = URL_book_chapter_list($url);
				$pagecontent = "<b>提醒：</b><br/>";
				$pagecontent .= "不存在的章节！<br/>";
				$pagecontent .= ">>".backurl()."<br/>";	
		}
		/**获取页面内容，检查是否有缓存**/
		if($iserror == 0){
				if(!file_exists($cachefilepath)){
					
						check_dir(HON6_ROOT."/cache/book/chapter/".$dirid."/".$bid);
						
						$chapterdata = $db->query_array("select articlename,chaptername,chapterorder,chaptertype from ".JIEQI_DB_PREFIX."_article_chapter where chapterid=".$cid);
						$chapterdata["nextc"] = $db->query_field("select chapterid from ".JIEQI_DB_PREFIX."_article_chapter where chaptertype = 0 and articleid = $bid and chapterid > ".$cid." order by chapterid asc limit 0,1");
						$chapterdata["prevc"] = $db->query_field("select chapterid from ".JIEQI_DB_PREFIX."_article_chapter where chaptertype = 0 and articleid = $bid and chapterid < ".$cid." order by chapterid desc limit 0,1");
						
						if($chapterdata){
							
								/*将动态数据生成缓存文件*/
								if($chapterdata["nextc"] != ""){
										write_cache($cachefilepath,serialize($chapterdata));//写入缓存
								}
								
						}else{
								$url = array("bid"=>$bid);
								$tourl = URL_book_chapter_list($url);
								$pagecontent = "<b>提醒：</b><br/>";
								$pagecontent .= "对不起不存在该章节，正在返回目录！<br/>";
								$pagecontent .= ">>".backurl()."<br/>";	
						}
						
				}else{
						
						require_once($cachefilepath);//加载缓存
						$chapterdata = unserialize($data);//加载缓存
						
				}
				
				$txtcontent = file_get_contents($txtfilepath);
				$txtcontent = iconv("GBK","UTF-8",$txtcontent);
				$txtcontent=str_replace("\n",'<br/>',$txtcontent);
				$txtcontent=str_replace("<br/>",'《br/》',$txtcontent);

		}
		
		/*页面设置*/
		$pagesize = isset($_SESSION["set"]["pagesize"])?intval($_SESSION["set"]["pagesize"]*1000):1000;
		

		
		if($iserror == 0){
			
				$lastvisit = $db -> query_field("select lastvisit from jieqi_article_article where articleid=".$bid);// 获取上次点击时间
				
				$sqli = "";
				if(date("W",$lastvisit)!=date("W"))$sqli .= "weekvisit=0,";
				if(date("m",$lastvisit)!=date("m"))$sqli .= "monthvisit=0,";
				if(date("d",$lastvisit)!=date("d"))$sqli .= "dayvisit=0,";
				
				$db -> query("UPDATE ".JIEQI_DB_PREFIX."_article_article SET {$sqli}lastvisit='".time()."',allvisit=allvisit+1,monthvisit=monthvisit+1,weekvisit=weekvisit+1,dayvisit=dayvisit+1 WHERE articleid=".$bid);
				
				$smartydate = array("pagetitle" => $chapterdata[0]["chaptername"]."-".$chapterdata[0]["articlename"],
													"pagesize" => $pagesize,
													"totalpage" => ceil(mb_strlen($txtcontent,"utf-8")/$pagesize),
													"nextc" => $chapterdata["nextc"],
													"prevc" => $chapterdata["prevc"],
													"page" => $page,
													"txtlen" => mb_strlen($txtcontent,"utf-8"),
													"data" => array("bid"=>$bid,"cid"=>$cid),
													"chapterdata" => $chapterdata,
													"txtcontent" => $txtcontent,
													"bgcolor" => array("","hon6_black","hon6_lv","hon6_feng"),
													);
				$tplpath = "book/chapter.tpl";
				
				if($_SESSION["member"]->uid){
						if($_SESSION["autobookmark"][$bid])unset($_SESSION["autobookmark"][$bid]);
						$_SESSION["autobookmark"][$bid]["cid"] = $cid;
						$_SESSION["autobookmark"][$bid]["date"] = time();
				}
		}else{
				$smartydate = array("pagetitle" => "章节提醒",
													"pagecontent" => $pagecontent,
													"torul" => $tourl,
													"redirecturl" => $tourl,
													);
				$tplpath = "public.tpl";
		}
?>