<%@ page contentType="text/html; charset=UTF-8" language="java" errorPage="" %>
<%@ page import="java.util.*"%>
<%@ page import="tot.search.IndexWebHander"%>
<%@ include file="../inc/common.jsp"%>
<%@ include file="inc/session.jsp"%>
<%
String act=RequestUtil.getString(request,"act");
%> 
<!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">

<fmt:bundle basename="resources.totcms_i18n">

<head>
<meta HTTP-EQUIV="content-type" CONTENT="text/html; charset=UTF-8">
<title>index manager</title>
<link href="style/global.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style4 {
	color: #FFFFFF;
	font-weight: bold;
}
.style5 {color: #FF6600}
-->
</style>
<LINK media=screen href="js/dhtmlgoodies_calendar.css" rel=stylesheet></LINK>
<SCRIPT src="js/dhtmlgoodies_calendar.js" type=text/javascript></SCRIPT>
</head>
<script>
function checkDate(obj){
	var reg = /^(\d{1,4})(-|\/)(\d{1,2})\2(\d{1,2})$/; 
	if(obj.FromDate.value=="" || obj.FromDate.value.match(reg)==null){
		alert("<fmt:message key="totcms.admin.searchindex.js.datetxt" />:0000-00-00");	
		obj.FromDate.focus();
		return false;
	}
	if(obj.ToDate.value=="" || obj.ToDate.value.match(reg)==null){
		alert("<fmt:message key="totcms.admin.searchindex.js.datetxt" />:0000-00-00");	
		obj.ToDate.focus();
		return false;
	}
}
function checkInt(obj){
	var reg = /^(\d{1,10})$/; 
	if(obj.FromId.value=="" || obj.FromId.value.match(reg)==null){
		alert("<fmt:message key="totcms.admin.searchindex.js.inttxt" />");	
		obj.FromId.focus();
		return false;
	}
	if(obj.ToId.value=="" || obj.ToId.value.match(reg)==null){
		alert("<fmt:message key="totcms.admin.searchindex.js.inttxt" />");	
		obj.ToId.focus();
		return false;
	}
}
function goUrl(frm)
{
	var gourl ="?";
	gourl += "page=" + (frm.page.value);
     var hid=parseInt(frm.hid.value);
	 if(parseInt(frm.page.value)>hid||frm.page.value<=0){
	 alert("1-"+hid);
	 return false;
	 }
	window.location.href=gourl;
}
function ContraSel(form) {
	for (var i=0;i<form.elements.length;i++){
		var e = form.elements[i];
		if (e.name == 'articleid')
		e.checked=!e.checked;
	}
}
</script>
</head>
<body>
<%@ include file="top.jsp"%>
<%
if(act!=null && act.equals("do")){
	String bytype=RequestUtil.getString(request,"bytype");
	if(bytype!=null && bytype.equals("date")){
		int num=IndexWebHander.addIndexByDate(request);
		out.print("<br><br><p align=\"center\">Success add Article Index:"+num+"</p>");
	}else if(bytype!=null && bytype.equals("id")){
		int num=IndexWebHander.addIndexById(request);
		out.print("<br><br><p align=\"center\">Success add Article Index:"+num+"</p>");
	}else if(bytype!=null && bytype.equals("bat")){
		String runtype=RequestUtil.getString(request,"runtype");		
		if(runtype!=null){
			int num=IndexWebHander.runIndexByBat(request,runtype);
			out.print("<br><br><p align=\"center\">Success! The number of affected:"+num+"<br></p>");
		}		
	}	
}
else{	
%>
<div align="center">
<br />
</div>
<form action="?act=do&bytype=bat" method="post" enctype="application/x-www-form-urlencoded">
<table width="98%" height="25" border="0" align="center" cellpadding="2" cellspacing="1" class="black_border">
  <tr>
    <td height="20" colspan="3" bgcolor="#FFFFFF"><span class="style3">
          <fmt:message key="totcms.admin.article.manage" />
    </span></td>
  </tr>
  <tr>
    <td height="20" bgcolor="#9AEBE4"><div align="center" class="style2">ID</div></td>
    <td height="20" bgcolor="#9AEBE4"><div align="center" class="style2"><fmt:message key="totcms.common.title" /></div></td>
    <td bgcolor="#9AEBE4"><div align="center" class="style2"><fmt:message key="totcms.common.datetime" /></div></td>
    </tr>
  <%
  int CurrentPage=0;
  CurrentPage=RequestUtil.getInt(request,"page");
  if(CurrentPage<1) CurrentPage=1;
	int PageSize=20;
	int TotalNum=0;
	int PageNum=0;
  TotalNum=DaoFactory.getArticleDAO().getTotalCount(0);
  PageNum=(TotalNum-1+PageSize)/PageSize;
  ArrayList list=(ArrayList)DaoFactory.getArticleDAO().getArticleList_Limit(0,CurrentPage,PageSize);
  int iti=0;
  String bgcolor="";
  for (Iterator iter = list.iterator(); iter.hasNext(); ) {
  	DataField df=(DataField)iter.next();
	String id=df.getFieldValue("id");
	int isoutlink=Integer.parseInt(df.getFieldValue("IsOutLink"));
	if(iti%2==0) bgcolor="#FFFFFF";
	else bgcolor="#F0E1D2";
  %>
  <tr>
    <td width="111" bgcolor="<%=bgcolor%>"><div align="center"><%=id%>
      <input name="articleid" type="checkbox" id="articleid" value="<%=id%>" />
    </div></td>
    <td width="646" bgcolor="<%=bgcolor%>">&nbsp;
	<a href="<%if(isoutlink==1) out.print(df.getFieldValue("OutLinkUrl")); else out.print(Sysconfig.getContextPath()+df.getFieldValue("SavePath"));%>" target="_blank">
	<%=df.getFieldValue("Title")%>	</a></td>
    <td width="200" bgcolor="<%=bgcolor%>"><div align="center"><%=df.getFieldValue("ModiTime")%></div></td>
    </tr>
  <%
  		iti++;
  	}
  %>
  <tr>
    <td colspan="3" valign="top" bgcolor="#F4F3F0"><div align="center">
      <select name="runtype">
        <option value="add"><fmt:message key="totcms.admin.searchindex.addindex" /></option>
        <option value="update"><fmt:message key="totcms.admin.searchindex.updateindex" /></option>
        <option value="delete"><fmt:message key="totcms.admin.searchindex.deleteindex" /></option>
      </select>
      <input class="Button" type="button" name="chksel" value="<fmt:message key="totcms.common.antielection" />" onclick="ContraSel(this.form)" />
      <input type="submit" name="Submit2" value="<fmt:message key="totcms.common.run" />=&gt;" />
</div></td>
  </tr>  
</table>
</form>
 <form>
          <div align="center"><%=CurrentPage%>/<%=PageNum%>&nbsp;&nbsp;<fmt:message key="totcms.common.total" />:<%=TotalNum%>&nbsp;&nbsp;
              <%if(CurrentPage>1){%>
              <a href="?page=<%=CurrentPage-1%>"><fmt:message key="totcms.common.previous" /></a>&nbsp;&nbsp;
              <%}else{%>
            <fmt:message key="totcms.common.previous" />&nbsp;&nbsp;
            <%}%>
            <%if(CurrentPage>=PageNum){%>
            <fmt:message key="totcms.common.next" />
            <%}else{%>
            <a href="?page=<%=CurrentPage+1%>"><fmt:message key="totcms.common.next" /></a>
            <%}%>
            <fmt:message key="totcms.common.go" />
            <input type="hidden" name="hid" value="<%=PageNum%>" />
            <input name="page" type="text" size="2" />
            <input type="button" name="Button2" onclick="goUrl(this.form)" value="<fmt:message key="totcms.common.submit" />" style="font-size:12px " />
          </div>
      </form>
<%}%>
</fmt:bundle>
</body>
</html>