<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/cms4j" prefix="cms4j" %>

<%@ page import = "cn.com.dekn.cms.util.*,cn.com.dekn.common.util.*" %>

<%
/***********************************
* CSS样式 参数初始化
***********************************/
//当前页颜色
String CSS = StrUtil.getNotNullStringValue(request.getParameter("CSS"),"pagination");


//当前页颜色
String CSS_CURR_PAGE = StrUtil.getNotNullStringValue(request.getParameter("CSS_CURR_PAGE"),"currentpage");

//无效的颜色
String CSS_DISABLE_PAGE = StrUtil.getNotNullStringValue(request.getParameter("CSS_DISABLE_PAGE"),"disablepage");

//上下页
String CSS_NEXT_PREV_PAGE = StrUtil.getNotNullStringValue(request.getParameter("CSS_NEXT_PREV_PAGE"),"nextpage");


/***********************************
* 其它代码逻辑
***********************************/

	//当前页数
	int PN = StrUtil.getNotNullIntValue(request.getParameter("pn"),1);
	int PAGE_COUNT = StrUtil.getNotNullIntValue((String)request.getAttribute("PAGE_COUNT"),1);
	int ROW_COUNT = StrUtil.getNotNullIntValue((String)request.getAttribute("ROW_COUNT"),1);
	int PAGE_SIZE = StrUtil.getNotNullIntValue((String)request.getAttribute("PAGE_SIZE"),1);
	
	
	
	//分页缓存最终存放的URL
	String pageCachedURL = request.getParameter("pageCachedURL");
	
	//第一页的URL（缓存后的）
	String firstPageCachedURL = request.getParameter("firstPageCachedURL");
	
	//静态化规则中配置的分页数
	int cachePageCount = StrUtil.getNotNullIntValue(request.getParameter("cachePageCount"));
	
	//当前的页号
	int CURRENT_PAGE_NUM = StrUtil.getNotNullIntValue((String)request.getAttribute("CURRENT_PAGE_NUM"),0);
	
	String FIRST_PAGE_URL = "";
	String PREV_PAGE_URL = "";
	String NEXT_PAGE_URL = "";
	String LAST_PAGE_URL = "";
	
	if(null != pageCachedURL && !pageCachedURL.equals("")){
		//取得网站的上下文
		String context = cn.com.dekn.cms.syscfg.vo.SiteConfig.getInstance("root").getCONTEXT_PATH();
		if(null != context && !context.equals("/")){
			pageCachedURL = context + pageCachedURL;
			firstPageCachedURL = context + firstPageCachedURL;
		}
	
		FIRST_PAGE_URL = firstPageCachedURL;
		
		if(((String)request.getAttribute("PREV_PAGE")).equals("1")){
			PREV_PAGE_URL = firstPageCachedURL;
		}else if(CURRENT_PAGE_NUM<=cachePageCount+1){
	 		PREV_PAGE_URL = StrUtil.replaceAll(pageCachedURL,"$pn",(String)request.getAttribute("PREV_PAGE"));
		}else{
			PREV_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("PREV_PAGE"));
		}
		
		if(((String)request.getAttribute("NEXT_PAGE")).equals("1")){
			NEXT_PAGE_URL = firstPageCachedURL;
		}else if(CURRENT_PAGE_NUM<cachePageCount||cachePageCount==PAGE_COUNT){
	 		NEXT_PAGE_URL = StrUtil.replaceAll(pageCachedURL,"$pn",(String)request.getAttribute("NEXT_PAGE"));
		}else{
			NEXT_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("NEXT_PAGE"));
		}
		
		if(((String)request.getAttribute("LAST_PAGE")).equals("1")){
			LAST_PAGE_URL = firstPageCachedURL;
		}else if(cachePageCount>=PAGE_COUNT){
	 		LAST_PAGE_URL = StrUtil.replaceAll(pageCachedURL,"$pn",(String)request.getAttribute("LAST_PAGE"));
		}else{
			LAST_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("LAST_PAGE"));
		}
	 	
	 	
	}else{
		FIRST_PAGE_URL = URLUtil.addParam(request,"pn","1");
		PREV_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("PREV_PAGE"));
		NEXT_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("NEXT_PAGE"));
		LAST_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("LAST_PAGE"));
	}
	

int k = 0;
int i = 1;
if(PN >= 6){
	i = PN - 5;
}
			
%>

<span style="display:none" id="htmlPageCount"><%=PAGE_COUNT%></span>
<div class="<%=CSS%>">
<ul>
<% if(PN > 1){ %>
	<li class="<%=CSS_NEXT_PREV_PAGE%>"><a href="<%=PREV_PAGE_URL%>">上一页</a></li>
	<% if(PN > 6) {%>
		<li><a href="<%=FIRST_PAGE_URL%>">1</a></li>
		<li>..</li>
	<% } %>
<% } %>

<%
for(;i<=PAGE_COUNT && k <= 10 ;i++,k++){
%>

<% if(i == PN) { %>
	<li class="<%=CSS_CURR_PAGE%>"><%=i%></li>
<% }else{ %>
	<li><a href="<%=URLUtil.addParam(request,"pn",String.valueOf(i))%>"><%=i%></a></li>
<% } %>

<%
}
%>

<% if(PN < PAGE_COUNT){ %>
	<% if(PAGE_COUNT - 6 > PN){ %>
		<li>..</li>
		<li><a href="<%=URLUtil.addParam(request,"pn",String.valueOf(PAGE_COUNT))%>"><%=PAGE_COUNT%></a></li>
	<% } %>
	<li class="<%=CSS_NEXT_PREV_PAGE%>"><a href="<%=NEXT_PAGE_URL%>">下一页</a></li>
<% } %>

</ul>
</div>