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

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

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

//强制指定翻页的主页面URL。因为有的时候，静态化时，如果这个静态化的页面URL，不带任何参数，则翻页地址会生成lxq.jsp&pn=12这样错误的URL，所以这里强制指定一个URL
//（这种现象只有在静态化页面没有任何URL参数时才会发生）
String PAGE_URL = StrUtil.getNotNullStringValue(request.getParameter("PAGE_URL"),"");
/***********************************
* 其它代码逻辑
***********************************/

	//当前页数
	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"),0);
	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{
			if(PAGE_URL.equals("")){
				PREV_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("PREV_PAGE"));
			}else{
				PREV_PAGE_URL = PAGE_URL + "?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{
			if(PAGE_URL.equals("")){
				NEXT_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("NEXT_PAGE"));
			}else{
				NEXT_PAGE_URL = PAGE_URL + "?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{
			if(PAGE_URL.equals("")){
				LAST_PAGE_URL = URLUtil.addParam(request,"pn",(String)request.getAttribute("LAST_PAGE"));
			}else{
				LAST_PAGE_URL = PAGE_URL + "?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"));
	}
	

%>


<table width="100%"  border="0" cellpadding="0" cellspacing="0">
  <tr class="<%=CSS%>">
	<td height="30" align="right"><span style="display:none" id="htmlPageCount"><%=PAGE_COUNT%></span>共有<%=ROW_COUNT%>条信息 页次: <%=PN%>/<%=PAGE_COUNT%> 【<a href="<%=FIRST_PAGE_URL%>"><span class="<%=CSS%>">第一页</span></a>】【<a href="<%=PREV_PAGE_URL%>"><span class="<%=CSS%>">上一页</span></a>】 【<a href="<%=NEXT_PAGE_URL%>"><span class="<%=CSS%>">下一页</span></a>】 【<a href="<%=LAST_PAGE_URL%>"><span class="<%=CSS%>">最末页</span></a>】</td>
  </tr>
</table>