<%
id = 0
if trim(Request("id")) <> "" then
	id = clng(request("id"))
end if

if subaction = "edit" then
	bHome=0:bScroll=0:bPhoto=0
	strStartDate = FormatDateTime(Now, 0)
	strExpDate = trim(Request("newsExpDate"))
	if Request("newsTimeSwitch") = "1" then
		strStartDate = trim(Request("newsTimeSwitchDate")) &" "& Request("newsTimeSwitchHour") &":"& Request("newsTimeSwitchMinute") & ":00"
	end if
	if Request("home") = "1" then
		bHome = 1
	end if
	if Request("roll") = "1" then
		bScroll = 1
	end if
	if Request("photo") = "1" then
		bPhoto = 1
	end if

	if not IsDate(strStartDate) then
		errorMsg = errorMsg & strStartDate &"请检查起始日期是否正确！<br>"
	end if
	if not IsDate(strExpDate) then
		errorMsg = errorMsg & strExpDate  &"请检查到期日期是否正确！<br>"
	end if

	if errorMsg = "" then
		if id > 0 then
			dim SCID
			
			SCID = trim(request("newsClass"))
			if SCID <> "" then
				if Right(SCID,1) = "," then
					SCID = Left(SCID,Len(SCID)-1)
				end if
				sql = "delete from cm_newsMenu where nid="& id &" and cid not in ("& SCID &")"
				conn.execute(sql)

				idList = split(SCID,",")
				for i=0 to ubound(idList)
					idList(i) = trim(idList(i))
					sql = "select id from cm_newsMenu where cid="& idList(i) &" and nid="& id
					set rs = conn.Execute(sql)
					if not rs.EOF then
						sql = "update cm_newsMenu set startDate='"& strStartDate &"',endDate='"& strExpDate &"',isMenu="& bHome &",isRoll="& bScroll &",isPhoto="& bPhoto &" where cid="& idList(i) &" and nid="& id
					else
						sql = "insert into cm_newsMenu(nid,cid,startDate,endDate,isMenu,isRoll,isPhoto) values("& id &","& idList(i) &",'"& strStartDate &"','"& strExpDate &"',"& bHome &","& bScroll &","& bPhoto &")"
					end if
					rs.Close
					conn.Execute(sql)
				next
			else
				errorMsg = "请选择要发布的栏目！"
			end if
			errorMsg = "操作成功！"
		else
			errorMsg = "请选择需要发布的资料！"
		end if
	end if
else
	strStartDate = FormatDateTime(Now, 0)
	strStartDate = Left(strStartDate,InStr(strStartDate," "))
	strExpDate =  "9999-01-01"
end if
if id > 0 then
	sql = "SELECT cid,isMenu FROM cm_newsMenu WHERE nid="& id
	rs.Open sql,conn,1,1
	do while not rs.Eof
		cid = rs("cid") &","
		'cid = rs("cid") &":"
		'if rs("isMenu") then
		'	cid = cid & "1"
		'else
		'	cid = cid & "0"
		'end if
		'cid = cid &";"

		rs.MoveNext
	loop
	rs.Close
end if

if errorMsg <> "" then
	DisplayMessage errorMsg,True
end if
%>
<table width="100%" 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="LOGINID" value="<%=LOGINID%>">
  <input type="hidden" name="id" value="<%=id%>">
  <input type="hidden" name="newsClass" value="<%=cid%>">
  <tr class="ListTableHeader">
    <td background="images/TableHeaderBg.gif" nowrap>新闻资料发布编辑</td>
  </tr>
  <tr class="InputTableRow">
    <td><b>栏目定位：　　　　　　　　　　　　　　　　　栏目</b></td>
  </tr>
  <tr class="InputTableRow" height="350">
    <td>
      <iframe name="newsClassTree" frameborder="0" width="370" height="100%" scrolling="auto" src="issue.asp"></iframe>
    </td>
  </tr>
  <tr class="InputTableRow">
    <td>
      <table border="0" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
        <tr>
          <td width="32"></td>
          <td width="24"></td>
          <td width="68">到期日期：</td>
          <td width="78"><input type="text" name="newsExpDate" class="ButtonEdit" size="10" value="<%=strExpDate%>"></td>
          <td width="20"><img style="CURSOR: hand" onClick="getDate(newsExpDate);" src="tools/images/clock.gif" width="16" height="15"></td>
          <td colspan="4"></td>
        </tr>
        <tr>
          <td width="32"></td>
          <td><input type="checkbox" name="newsTimeSwitch" value="1" onclick="javascript:OnNewsTimeSwitch();"></td>
          <td>定时发布：</td>
          <td><input type="text" name="newsTimeSwitchDate" class="ButtonEdit" size="10" value="<%=strStartDate%>"></td>
          <td><img style="CURSOR: hand" onClick="getDate(newsTimeSwitchDate);" src="tools/images/clock.gif" width="16" height="15"></td>
          <td>
            <select name="newsTimeSwitchHour" class="ButtonSelect">
<%
		for j=0 to 24
			if j < 10 then
				response.write "              <option vlaue=""0"& j &""">0"& j &"</option>"& vbCrLf
			else
				response.write "              <option vlaue="""& j &""">"& j &"</option>"& vbCrLf
			end if
		next	
%>
            </select>
          </td>
          <td>时</td>
          <td>
            <select name="newsTimeSwitchMinute" class="ButtonSelect">
<%
		for j=0 to 60
			if j < 10 then
				response.write "              <option vlaue=""0"& j &""">0"& j &"</option>"& vbCrLf
			else
				response.write "              <option vlaue="""& j &""">"& j &"</option>"& vbCrLf
			end if
		next	
%>
            </select>
          </td>
          <td>分</td>
        </tr>
        <tr>
          <td width="32"></td>
          <td colspan="8">
            <table border="0" cellspacing="0" cellpadding="0" bordercolorlight="#CCE0CF" bordercolordark="#FFFFFF">
              <tr>
                <td width="24"><input type="checkbox" name="home" value="1" onclick="javascript:OnCheckboxHome();"></td>
                <td width="68">首页显示：</td>
                <td width="24"><input type="checkbox" name="roll" value="1"></td>
                <td width="68">滚动</td>
                <td width="24"><input type="checkbox" name="photo" value="1"></td>
                <td width="68">图片</td>
              </tr>
            </table>
          </td>
        </tr>
      </table>
    </td>
  </tr>
  <tr class="MainPageBar" height="28">
    <td colspan="2" align="center">
      <input type="submit" name="Submit" value="　提交　" class="ButtonReply">&nbsp;<input type="button" name="Close" value="　关闭　" class="ButtonReply" onclick="javascript: window.close();">
    </td>
  </tr>
</form>
</table>
<script language="javascript">
<!--//
function checkForm()
{
  return true;
}

function OnNewsTimeSwitch()
{
  with (document.InfoEdit)
  {
    newsTimeSwitchDate.disabled = ! newsTimeSwitch.checked;
    newsTimeSwitchHour.disabled = ! newsTimeSwitch.checked;
    newsTimeSwitchMinute.disabled = ! newsTimeSwitch.checked;
  }
}


function OnCheckboxHome()
{
  with (document.InfoEdit)
  {
    roll.disabled = ! home.checked;
    photo.disabled = ! home.checked;
  }
}

function InitCheckbox()
{
  OnNewsTimeSwitch();
  OnCheckboxHome();
}

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;
}

window.onload = function()
{
	InitCheckbox();
} 
//-->
</script>