<% Option Explicit %>
<!--#include file="../../Inc/Cls_DB.asp" -->
<!--#include file="../../Inc/Const.asp" -->
<%
Dim DBC,Conn
Set DBC=new DataBaseClass
Set Conn=DBC.OpenConnection
Set DBC=Nothing
%>
<!--#include file="../../Inc/Session.asp" -->
<!--#include file="../../Inc/CheckPopedom.asp" -->
<%
if Not JudgePopedomTF(Session("Name"),"P0302") then Call ReturnError()
Dim LableID,RsLableObj,SQLStr,LableName,LableDescription,LableContent,Operation,LableType,BigTypeID
LableID = Request("ID")
BigTypeID = Request("BigTypeID")
if BigTypeID <> "" then
	if BigTypeID < 0 OR BigTypeID = "" then
		BigTypeID = "0"
	else
		BigTypeID = BigTypeID
	end if
end if
Operation = Request.Form("Operation")
if LableID <> "" then
	if Operation = "Modify" then
		LableName = Request.Form("LableName")
		LableDescription = Request.Form("Description")
		LableContent = Request.Form("LableContent")
		LableType = Request.Form("LableType")
	else
		Set RsLableObj = CreateObject("ADODB.RecordSet")
		SQLStr = "Select * From Lable where ID="&LableID&""
		RsLableObj.Open SQLStr,Conn,1,3
		if Not RsLableObj.Eof then
			LableName = RsLableObj("LableName")
			LableDescription = RsLableObj("Description")
			LableContent = RsLableObj("LableContent")
			LableType = CStr(RsLableObj("Type"))
		else
			LableName = ""
			LableDescription = ""
			LableContent = ""
			LableType = ""
		end if
		Set RslableObj = Nothing
	end if
else
	LableName = Request.Form("LableName")
	LableDescription = Request.Form("Description")
	LableContent = Request.Form("LableContent")
	if Request.Form("LableType") = "" then
		LableType = BigTypeID
	else
		LableType = Request.Form("LableType")
	end if
end if
if Operation = "Modify" then SaveLable LableID
Sub SaveLable(EditLableID)
	Dim RsTemp,EditSql,RsCheckObj,CheckSql
	if Replace(Replace(Request.form("LableName"),"{FS_",""),"}","") = "" then
		Alert "请填写标签名称"
		Exit Sub
	else
		if EditLableID = "" then
			CheckSql = "Select * from Lable where LableName='" & Request.form("LableName") & "'"
		else
			CheckSql = "Select * from Lable where LableName='" & Request.form("LableName") & "' and ID<>" & EditLableID
		end if
		Set RsCheckObj = Conn.Execute(CheckSql)
		if Not RsCheckObj.Eof then
			Alert "标签名已经存在"
			Set RsCheckObj = Nothing
			Exit Sub
		end if
		Set RsCheckObj = Nothing
	end if
	On Error Resume Next
	Set RsTemp = Server.CreateObject("ADODB.recordset")
	if EditLableID = "" then
		EditSql = "Select * from Lable where 1=0"
		RsTemp.Open EditSql,Conn,3,3
		RsTemp.AddNew
	else
		EditSql = "Select * from Lable where ID=" & LableID
		RsTemp.Open EditSql,Conn,3,3
		if RsTemp.Eof then AlertAndCloseWindow "修改的标签不存在"
	end if
	RsTemp("LableName") = Request.form("LableName")
	RsTemp("LableContent") = Request.form("LableContent")
	RsTemp("Description") = Request.form("Description")
	if Request.form("LableType") <> "" then
		RsTemp("Type") = CInt(Request.form("LableType"))
	else
		RsTemp("Type") = 0
	end if
	RsTemp.UpDate
	RsTemp.Close
	Set RsTemp = Nothing
	if err.Number=0 then
		CloseWindow
	else
		if LableID <> "" then
			AlertAndCloseWindow "修改失败"
		else
			AlertAndCloseWindow "添加失败"
		end if
	end if
End Sub
Sub CloseWindow()
%>
<script language="javascript">
	dialogArguments.location.reload();
	window.close();
</script>
<%
End Sub
Sub Alert(ErrorStr)
%>
<script language="javascript">
	alert ('<% = ErrorStr %>')
</script>
<%
End Sub
Sub AlertAndCloseWindow(ErrorStr)
	Set Conn = Nothing
%>
<script language="javascript">
	alert ('<% = ErrorStr %>')
	dialogArguments.location.reload();
	window.close();
</script>
<%
End Sub
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建标签</title>
</head>
<script language="javascript" event="onerror(msg, url, line)" for="window">return true;</script>
<link href="../Inc/ModeWindow.css" rel="stylesheet">
<body scroll=no bgcolor="#FFFFFF" topmargin="0" leftmargin="0">
<div align="center">
  <table width="96%" height="100%" border="0" cellpadding="0" cellspacing="0">
    <form name=LableForm method=post action="" >
      <tr> 
        <td  height="20" id="LableNameArea"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
            <tr> 
              <td width="100"><div align="center"><font size=2.5>标签名称</font></div></td>
              <td><input value="<% = Replace(Replace(LableName,"{FS_",""),"}","") %>" name="LableName" style="width:100%;"> 
              </td>
            </tr>
          </table></td>
      </tr>
      <tr> 
        <td height="20" id="DescriptionArea"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
            <tr> 
              <td width="100" height="16">
<div align="center"><font size=2.5>标签描述</font></div></td>
              <td><input name="Description" type="text" style="width:100%;" value="<% = LableDescription %>"></td>
            </tr>
          </table></td>
      </tr>
      <tr>
        <td height="32" id="LableTypeArea"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td width="100"><div align="center">标签分类</div></td>
              <td><select name="LableType">
			  	<option <% if BigTypeID = "0" then Response.Write("Selected") %> value="0">根类型</option>
			  	<%
				Dim LableTypeObj
				Set LableTypeObj = Conn.Execute("Select * from LableType")
				do while Not LableTypeObj.Eof
				%>
				<option <% if LableType = CStr(LableTypeObj("ID")) then Response.Write("Selected") %> value="<% = LableTypeObj("ID") %>"><% = LableTypeObj("TypeName") %></option>
				<%
					LableTypeObj.MoveNext
				Loop
				Set LableTypeObj = Nothing
				%>
                </select></td>
            </tr>
          </table></td>
      </tr>
      <tr> 
        <td height="64" id="BtnArea"> <iframe id="LableListWindow" src="LableList.asp" scrolling="no" width="100%" height="100%" frameborder="0"></iframe></td>
      </tr>
      <tr> 
        <td colspan="2" align="center"><iframe id="Editer" src="../Editer/LableEditer.asp" scrolling="no" width="100%" height="100%" frameborder="0"></iframe></td>
      </tr>
      <tr height="160" id="LableContentArea"> 
        <td><textarea onBlur="SetHTML();" onFocus="SetCode();" name="LableContent" style="width:100%;Height:160;"><% = LableContent %></textarea></td>
      </tr>
      <tr> 
        <td  height="50" colspan="2" align="center" valign="top" id="SubmitArea">
<input type="hidden" name="ID" value="<% = LableID %>"> 
          <input type=hidden name=operation value=Modify> <input name="按钮" type="button" value=" 确  定 " onClick="AddLableHead()" class=Anbutc> 
          <input type="reset" value=" 取  消 " onclick="window.close()" class=Anbutc>
        </td>
      </tr>
    </form>
  </table>
</div>
</body>
</html>
<%
Set Conn = Nothing
%>
<script language="JavaScript">
setTimeout('SetHTML();',1000);
var BodyHeight=document.body.clientHeight;
var EditAreaHeight=BodyHeight-document.all.LableNameArea.height-document.all.LableContentArea.height-document.all.DescriptionArea.height-document.all.BtnArea.height-document.all.SubmitArea.height-document.all.LableTypeArea.height;
var CodeWindowHeight=document.all.LableContentArea.height;
function AddLableHead()
{
	if (CheckAdminForm())
	{
		SetCode();
		document.LableForm.LableName.value='{FS_'+document.LableForm.LableName.value+'}';
		document.LableForm.submit();
	}
}
function CheckAdminForm()
{
	var ErrorCode='';
	if (document.LableForm.LableName.value=='') ErrorCode=ErrorCode+'标签名称不能为空！\n';
	if (ErrorCode!='') 
	{
		alert(ErrorCode);
		return false
	}
	else return true;
}
function SetHTML()
{
	frames["Editer"].EditArea.document.body.innerHTML=document.all.LableContent.value;
	frames["Editer"].ShowTableBorders();
}
function SetCode()
{
	document.all.LableContent.value=frames["Editer"].EditArea.document.body.innerHTML;
	frames["Editer"].ShowTableBorders();
}
</script>
