<% Option Explicit %>
<!--#include file="../../Inc/Const.asp" -->
<!--#include file="../../Inc/Cls_DB.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 StyleID,RsStyleObj,SQLStr,StyleName,StyleContent,Operation
StyleID = Request("ID")
Operation = Request.Form("Operation")
if StyleID <> "" then
	if Operation = "Modify" then
		StyleName = Request.Form("StyleName")
		StyleContent = Request.Form("StyleContent")
	else
		Set RsStyleObj = CreateObject("ADODB.RecordSet")
		SQLStr = "Select * From DownListStyle where ID=" & StyleID & ""
		RsStyleObj.Open SQLStr,Conn,1,3
		if Not RsStyleObj.Eof then
			StyleName = RsStyleObj("Name")
			StyleContent = RsStyleObj("Content")
		else
			StyleName = ""
			StyleContent = ""
		end if
		Set RsStyleObj = Nothing
	end if
else
	StyleName = Request.Form("StyleName")
	StyleContent = Request.Form("StyleContent")
end if
if Operation = "Modify" then SaveStyle StyleID
Sub SaveStyle(EditStyleID)
	Dim RsTemp,EditSql,RsCheckObj,CheckSql
	if Request.form("StyleName") = "" then
		Alert "请填写样式名称"
		Exit Sub
	else
		if EditStyleID = "" then
			CheckSql = "Select * from DownListStyle where Name='" & Request.form("StyleName") & "'"
		else
			CheckSql = "Select * from DownListStyle where Name='" & Request.form("StyleName") & "' and ID<>" & EditStyleID
		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 EditStyleID = "" then
		EditSql = "Select * from DownListStyle where 1=0"
		RsTemp.Open EditSql,Conn,3,3
		RsTemp.AddNew
	else
		EditSql = "Select * from DownListStyle where ID=" & StyleID
		RsTemp.Open EditSql,Conn,3,3
		if RsTemp.Eof then AlertAndCloseWindow "修改的标签不存在"
	end if
	RsTemp("Name") = Request.form("StyleName")
	RsTemp("Content") = Request.form("StyleContent")
	RsTemp.UpDate
	RsTemp.Close
	Set RsTemp = Nothing
	if err.Number=0 then
		CloseWindow
	else
		if StyleID <> "" 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>
<script src="../JS/PublicJS.js" language="JavaScript"></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=StyleForm method=post action="" >
      <tr> 
        <td  height="30" id="StyleNameArea"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
            <tr> 
              <td width="60">
<div align="center"><font size=2.5>样式名称</font></div></td>
              <td><input value="<% = StyleName %>" name="StyleName" style="width:100%;">
              </td>
            </tr>
          </table></td>
      </tr>
      <tr> 
        <td  height="30" id="StyleNameArea"> <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
            <tr> 
              <td width="60">
<div align="center"><font size=2.5>插入字段</font></div></td>
              <td> <select style="width:82%;" name="FieldList">
			  		<option value="" selected>选择插入的字段</option>
			  		<option value="{DownLoad_Name}">下载名称</option>
			  		<option value="{DownLoad_Version}">版本</option>
			  		<option value="{DownLoad_Types}">下载类型</option>
			  		<option value="{DownLoad_ClickNum}">下载次数</option>
			  		<option value="{DownLoad_Property}">下载性质</option>
			  		<option value="{DownLoad_Language}">语言</option>
			  		<option value="{DownLoad_Accredit}">授权</option>
			  		<option value="{DownLoad_FileSize}">文件大小</option>
			  		<option value="{DownLoad_Appraise}">评价</option>
			  		<option value="{DownLoad_SystemType}">系统平台</option>
			  		<option value="{DownLoad_EMail}">联系人EMAIL</option>
			  		<option value="{DownLoad_ProviderUrl}">提供者Url地址</option>
			  		<option value="{DownLoad_Provider}">开发商</option>
			  		<option value="{DownLoad_Pic}">显示图片</option>
			  		<option value="{DownLoad_Description}">简介</option>
			  		<option value="{DownLoad_PassWord}">解压密码</option>
			  		<option value="{DownLoad_AddTime}">添加时间</option>
			  		<option value="{DownLoad_EditTime}">修改时间</option>
                </select>
                <input name="Submitfff" type="button" id="Submitfff" onClick="InsertField();" value="插入字段" style="color=#FF0000"> 
              </td>
            </tr>
          </table></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="StyleContentArea"> 
        <td height="100">
<textarea onBlur="SetHTML();" onFocus="SetCode();" name="StyleContent" style="width:100%;Height:100;"><% = StyleContent %></textarea></td>
      </tr>
      <tr> 
        <td colspan="2"  height="50" align="center" id="SubmitArea"><input type="hidden" name="ID" value="<% = StyleID %>"> 
          <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;
var CodeWindowHeight=document.all.StyleContentArea.height;
function AddLableHead()
{	
	if (CheckAdminForm())
	{
		SetCode();
		document.StyleForm.submit();
	}
}
function CheckAdminForm()
{
	var ErrorCode='';
	if (document.StyleForm.StyleName.value=='') ErrorCode=ErrorCode+'样式名称不能为空！\n';
	if (ErrorCode!='') 
	{
		alert(ErrorCode);
		return false
	}
	else return true;
}
function SetHTML()
{
	frames["Editer"].EditArea.document.body.innerHTML=document.all.StyleContent.value;
	frames["Editer"].ShowTableBorders();
}
function SetCode()
{	
	document.all.StyleContent.value=frames["Editer"].EditArea.document.body.innerHTML;		
	frames["Editer"].ShowTableBorders();	
}
function InsertField()
{
	var ReturnValue=document.all.FieldList.value;
	frames["Editer"].EditArea.focus();
	if (ReturnValue!='') frames["Editer"].InsertHTMLStr(ReturnValue);
}
</script>
