<%
dim strPlanDate, strAddress, strPeoples

errorMsg = ""
sql = ""
id = 0
if trim(Request("id")) <> "" then
	id = clng(request("id"))
end if
if trim(Request("page")) <> "" then
	iCurrentPage = clng(request("page"))
else
	iCurrentPage = 1
end if
if session("plansCondition") = "" then
	session("plansCondition") = " WHERE 1=1"
end if

set mrs = server.createobject("adodb.recordset")
subaction = Request("subaction")
if subaction = "edit" then
	if  Trim(Request("title")) = "" then
		errorMsg = errorMsg &"请输入标题！<br>"
	end if
	if  Trim(Request("planDate")) = "" then
		errorMsg = errorMsg &"请输入时间！<br>"
	end if
	if  Trim(Request("address")) = "" then
		errorMsg = errorMsg &"请输入地点！<br>"
	end if
	if  Trim(Request("peoples")) = "" then
		errorMsg = errorMsg &"请输入人物！<br>"
	end if
	if Request("status") = "" then
		errorMsg = errorMsg &"请选择状态！<br>"
	end if
    
	if errorMsg = "" then
		if id = 0 then
			sql = "insert into cm_plans(title,content,planDate,address,peoples,postTime,status) values('"& HTMLSpecialChars(Request("title")) &"','"& HTMLSpecialChars(Request("content")) &"','"& HTMLSpecialChars(Request("planDate")) &"','"& HTMLSpecialChars(Request("address")) &"','"& HTMLSpecialChars(Request("peoples")) &"',GetDate(),"& Request("status") &")"
		else
			sql = "update cm_plans set title='"& HTMLSpecialChars(Request("title")) &"',content='"& HTMLSpecialChars(Request("content")) &"',planDate='"& HTMLSpecialChars(Request("planDate")) &"',address='"& HTMLSpecialChars(Request("address")) &"',peoples='"& HTMLSpecialChars(Request("peoples")) &"',status="& Request("status") &" where id="& Request("id")
		end if
		conn.Execute(sql)
		errorMsg = errorMsg &"操作成功！</a><br>"
		id = 0
	end if
elseif subaction = "modify" then
	idList = Split(Trim(Request("SID")),",")
	for i=0 to UBound(idList)
		idList(i) = Trim(idList(i))
		sql = "UPDATE cm_plans SET status="& Request("status"& idList(i)) &" WHERE id="& idList(i)
		conn.Execute(sql)
	next
	errorMsg = errorMsg &"批量修改成功！<br>"
elseif subaction = "delSelect" then
	idList = split(trim(Request("SID")),",")
	for i=0 to UBound(idList)
		idList(i) = Trim(idList(i))
		sql = "delete from cm_plans where id="& idList(i)
		conn.Execute(sql)
	next
	errorMsg = errorMsg &"批量删除成功！<br>"
elseif subaction = "search" then
	session("plansCondition") = " WHERE 1=1"
	session("plansConditionDesc") = ""
	strBeginDate = trim(Request("beginDate"))
	strEndDate = trim(Request("endDate"))

	if Request("keyword") <> "" then
		if Request("searchType") = "0" then
			session("plansCondition") = session("plansCondition") &" AND title like '%"& trim(Request("keyword")) &"%'"
			session("plansConditionDesc") = session("plansConditionDesc") &"关键字="& Request("keyword") &"(包括)"
		else
			session("plansCondition") = session("plansCondition") &" AND title='"& trim(Request("keyword")) &"'"
			session("plansConditionDesc") = session("plansConditionDesc") &"关键字="& Request("keyword") &"(等于)"
		end if
	end if
	if ((strBeginDate <> "") and (strEndDate <> "")) then
		session("plansCondition") = session("plansCondition") &" AND postTime BETWEEN '"& strBeginDate &"' AND '"& strEndDate &"'"
		session("plansConditionDesc") = session("plansConditionDesc") &",发布日期从"& strBeginDate &"至"+ strEndDate
	elseif (strBeginDate <> "") then
		session("plansCondition") = session("plansCondition") &" AND postTime BETWEEN '"& strBeginDate &"' AND '"& now &"'"
		session("plansConditionDesc") = session("plansConditionDesc") &",发布日期从"& strBeginDate &"至今"
	elseif (strEndDate <> "") then
		session("plansCondition") = session("plansCondition") &" AND postTime BETWEEN '1900-01-01' AND '"& strEndDate &"'"
		session("plansConditionDesc") = session("plansConditionDesc") &",发布日期至"& strEndDate
	end if
	if Request("status") <> "0" and Request("status") <> "" then
		session("plansCondition") = session("plansCondition") &" AND status="& trim(Request("status"))
		session("plansConditionDesc") = session("plansConditionDesc") &"状态="& newsStatus(Request("status"))
	end if
	if session("plansConditionDesc") <> "" then
		session("plansConditionDesc") = "<tr><td colspan=""5"">条件："& session("plansConditionDesc") &"</td></tr>"
	end if
end if

if errorMsg <> "" then
	DisplayMessage errorMsg,True
end if
%>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#E5EFE7">
<form method="post" action="functions.asp" name="searchForm">
<input type="hidden" name="action" value="<%=action%>">
<input type="hidden" name="subaction" value="search">
<input type="hidden" name="LOGINID" value="<%=LOGINID%>">
  <tr>
    <td height="4"></td>
  </tr>
  <tr>
    <td nowrap valign="middle">
      <span class="Search">
        <input type="radio" name="searchType" value="0" checked>模糊查询
        <input type="radio" name="searchType" value="1">精确查询
        <input type="text" name="keyword" size="18" maxlength="50" class="ButtonEdit" value="">
        &nbsp;发布日期从
        <input type="text" name="beginDate" class="ButtonEdit" size="10" value="">
        <img style="CURSOR: hand" onClick="getDate(beginDate);" src="tools/images/clock.gif">
        &nbsp;至
        <input type="text" name="endDate" class="ButtonEdit" size="10" value="">
        <img style="CURSOR: hand" onClick="getDate(endDate);" src="tools/images/clock.gif">
        &nbsp;状态
        <select name="status" class="ButtonSelect">
          <option value="0">请选择…</option>
<%
for i=1 to ubound(newsStatus)
	Response.Write "          <option value="""& i &""">"& newsStatus(i) &"</option>"& vbCrLf
next
%>
        </select>
        <input type="image" src="images/IconSearch.gif" border="0">
      </span>
    </td>
  </tr>
  <tr>
    <td height="5"></td>
  </tr>
  <tr>
    <td height="5"><font color="RED"></a></td>
  </tr>
</form>
</table>
<%
if (subaction = "add") or ((id > 0) and (subaction = "preEdit")) then
	if id > 0 then
		sql = "select title,content,planDate,address,peoples,status from cm_plans where id="& id
		rs.Open sql,conn,1,1
		if not rs.EOF then
			strTitle = rs("title")
			strContent = rs("content")
			strPlanDate = rs("planDate")
			strAddress = rs("address")
			strPeoples = rs("peoples")
			iStatus = rs("status")
		end if
		rs.Close
	end if
%>
<br>
<table id="Hedit" width="625" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF" align="center">
<form name="InfoEdit" action="functions.asp" method="post" onSubmit="return checkForm();">
<input type="hidden" name="action" value="<%=action%>">
<input type="hidden" name="subaction" value="edit">
<input type="hidden" name="id" value="<%=id%>">
<input type="hidden" name="LOGINID" value="<%=LOGINID%>">
<input type="hidden" name="iPage" value="<%=iCurrentPage%>">
<input type="hidden" name="content" value="<%=strContent%>">
  <tr class="ListTableHeader">
    <td colspan="2" background="images/TableHeaderBg.gif" nowrap><b>靓影行踪编辑</b></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" width="80">标题：</td>
    <td><input type="text" name="title" value="<%=strTitle%>" size="86" class="ButtonEdit"><font color="RED">*</font></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" width="80">时间：</td>
    <td><input type="text" name="planDate" value="<%=strPlanDate%>" size="86" class="ButtonEdit"><font color="RED">*</font></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" width="80">地点：</td>
    <td><input type="text" name="address" value="<%=strAddress%>" size="86" class="ButtonEdit"><font color="RED">*</font></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" width="80">人物：</td>
    <td><input type="text" name="peoples" value="<%=strPeoples%>" size="86" class="ButtonEdit"><font color="RED">*</font></td>
  </tr>
  <tr class="InputTableRow">
    <td align="right" valign="Top">内容：</td>
    <td bgcolor="#FFFFFF">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr>
          <td align="right" height="22">
            <img src="images/600.gif" height="16" style="cursor:hand" onClick="hss()">
            <img src="images/800.gif" height="16" style="cursor:hand" onClick="hzz()">
            <img src="images/1024.gif" height="16" style="cursor:hand" onClick="hbb()">
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr class="InputTableRow">
    <td bgcolor="#FFFFFF" colspan="2">
      <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
        <tr align="center">
          <td height="1"></td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" >
        <tr valign="top">
          <td height="51">
            <table width="100%" border="0" cellspacing="1" cellpadding="6" bgcolor="#000000">
              <tr align="center" bgcolor="#FFFFFF">
                <td><a href="#" onClick="ck(0)"><img src="images/mainmod1.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(1)"><img src="images/mainmod5.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(2)"><img src="images/mainmod3.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(3)"><img src="images/mainmod4.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(4)"><img src="images/mainmod2.gif" width="80" height="80" border="0"></a></td>
                <td><a href="#" onClick="ck(5)"><img src="images/mainmod6.gif" width="80" height="80" border="0"></a></td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
      <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center" >
        <tr valign="top">
          <td height="377" align="center">
            <script language="javascript" src="Common/zoom.js"></script>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr class="InputTableRow">
    <td align="right">状态：</td>
    <td>
      <select name="status" class="ButtonSelect">
	<%
	for i=1 to ubound(newsStatus)
		Response.Write "        <option value="""& i &""""
		if iStatus = i then
			Response.Write " selected"
		end if
		Response.Write ">"& newsStatus(i) &"</option>"& vbCrLf
	next
	%>
      </select>
    </td>
  </tr>
  <tr class="MainPageBar" height="28">
    <td colspan="2" align="center">
      <input type="submit" name="Submit" value="　提交　" class="ButtonReply">　<input type="button" name="Delete" value="　删除　" class="ButtonReply" onClick="javascript:if(confirm('真的要删除么？')) document.URL='<%=urlParam%>&subaction=del&id=<%=id%>';return false;">　<input type="button" name="Issue" value="　发布　" class="ButtonReset" onClick="javascript:doIssue(<%=id%>)"<% if id = 0 then response.write " disabled" end if%>>　<input type="button" name="Cancel" value="　取消　" class="ButtonReset" onClick="document.URL='<%=urlParam%>'">
    </td>
  </tr>
</form>
</table>
<script language="JavaScript">
<!--
  function checkForm()
  {
    if (document.InfoEdit.title.value.length == 0)
    {
      alert("请输入标题！");
      document.InfoEdit.title.focus();
      return false;
    }
    if (document.InfoEdit.planDate.value.length == 0)
    {
      alert("请输入安排时间！");
      document.InfoEdit.planDate.focus();
      return false;
    }
    if (document.InfoEdit.address.value.length == 0)
    {
      alert("请输入活动地点！");
      document.InfoEdit.address.focus();
      return false;
    }
	if (document.InfoEdit.peoples.value.length == 0)
    {
      alert("请输入人物！");
      document.InfoEdit.peoples.focus();
      return false;
    }

    save();
    return true;
  }
//-->
</script>
<%
end if
%>
<br>
<table width="100%" border="1" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
  <form name="listForm" action="functions.asp" method="post">
  <input type="hidden" name="action" value="<%=action%>">
  <input type="hidden" name="subaction" value="">
  <input type="hidden" name="LOGINID" value="<%=LOGINID%>">
  <input type="hidden" name="iPage" value="<%=iCurrentPage%>">
  <tr class="ListTableHeader">
    <td nowrap background="images/TableHeaderBg.gif" width="24" align="center"><input type="checkBox" name="checkAll" value="on" OnClick="OnCheckAll(this.form)"></td>
    <td nowrap background="images/TableHeaderBg.gif" align="center">标题</td>
    <td nowrap background="images/TableHeaderBg.gif" width="150" align="center">活动时间</td>
    <td nowrap background="images/TableHeaderBg.gif" width="131" align="center">发布时间</td>
    <td nowrap background="images/TableHeaderBg.gif" width="56" align="center">状态</td>
    <td nowrap background="images/TableHeaderBg.gif" width="48" align="center">操作</td>
  </tr>
<%
i = 0
sql = "select id,title,planDate,postTime,status from cm_plans "& session("plansCondition") &" ORDER BY id DESC"
rs.Open sql,conn,1,1
rs.PageSize = iRowsPerPage
iMaxRowCount = rs.RecordCount
if iCurrentPage > Rs.PageCount then
	iCurrentPage = Rs.PageCount
end if
if not (rs.Eof and rs.Bof) then
	if iCurrentPage <> 1 then
		if (iCurrentPage - 1) * iRowsPerPage < Rs.RecordCount then
			Rs.Move (iCurrentPage - 1) * iRowsPerPage
		end if
	end if
	if rs.recordcount mod iRowsPerPage = 0 then
		iMaxPage = rs.RecordCount \ iRowsPerPage
	else
		iMaxPage = rs.RecordCount \ iRowsPerPage+1
	end if
	do while not rs.Eof and i < iRowsPerPage
%>
  <tr class="InputTableRow" id="Row<%=rs("id")%>" onclick="javascript:setRowFocus(this,false,<%=rs("id")%>)">
    <td nowrap align="center"><input type="checkBox" name="SID" value="<%=rs("id")%>"></td>
    <td nowrap>&nbsp;<%=rs("title")%></td>
    <td nowrap align="center">&nbsp;<%=rs("planDate")%></td>
    <td nowrap align="center">&nbsp;<%=rs("postTime")%></td>
    <td nowrap align="center">
      <select name="status<%=rs("id")%>" class="ButtonSelect">
<%
		for j=1 to ubound(newsStatus)
			Response.Write "        <option value="""& j &""""
			if rs("status") = j then
				Response.Write " selected"
			end if
			Response.Write ">"& newsStatus(j) &"</option>"& vbCrLf
		next
%>
      </select>
	</td>
	<td nowrap align="center"><span class="OperateIcon" onclick="javascript:setRowFocus(Row<%=rs("id")%>,false,<%=rs("id")%>);edit('plans',<%=rs("id")%>)" title="修改"><img src="images/IconEdit.gif" border="0" width="16" height="16" alt="修改"></span>&nbsp;<span class="OperateIcon" onclick="javascript:setRowFocus(Row<%=rs("id")%>,false,<%=rs("id")%>);del('plans','<%=rs("id")%>','您正要删除【<%=Replace(rs("title"),"'","\'")%>】。\n本操作将删除该记录。请确认！')" title="删除"><img src="images/IconDelete.gif" border="0" width="16" height="16" alt="删除"></span></td>
  </tr>
<%
		if bFirst = false then
%>
  <script LANGUAGE="javascript">
  <!--
	setRowFocus(Row<%=rs("id")%>,true,<%=rs("id")%>);
  //-->
  </script>
<%
			bFirst = true
		end if
		rs.MoveNext
		i = i + 1
	loop
end if
%>
  </form>
</table>
<!-- #include file="pageRobot.inc.asp" //-->
<script language="javascript">
<!--//
function getDate(target)
{
  myDate = window.showModalDialog("tools/calendar.htm",null,"dialogwidth:155pt;dialogheight:190pt,toolbar=no,status=no,resizable=no");
  target.value = myDate;
  if (target.value == "undefined")
  {
    target.value = "";
  }
  return;
}
//-->
</script>