<%@ LANGUAGE = VBScript.Encode %>
<!--#include file="../Include/conn.asp" -->
<!--#include file="../Include/ConnDatabase.asp" -->
<!--#include file="Admin_htmlconfig.asp"-->
<!--#include file="../Include/RemoteImg_save.asp"-->
<%
'=====================================
'天天企业网站管理系统  TianTianCMS
'天天网络科技工作室版权所有
'官方客服中心 http://www.ip126.com
'微信公众号 ip126com
'QQ:530051328 mail:bbfhq@163.com
'=====================================
%>
<HTML xmlns="http://www.w3.org/1999/xhtml">
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=gb2312" />
<TITLE>下载编辑</TITLE>
<link rel="stylesheet" href="Images/Admin.css">
<script language="javascript" src="../Script/Admin.js"></script>
<!--kindeditor编辑器-->
		<link rel="stylesheet" href="../KindEditor/themes/default/default.css" />
		<script charset="utf-8" src="../KindEditor/kindeditor.js"></script>
		<script charset="utf-8" src="../KindEditor/lang/zh_CN.js"></script>
		<script>
		KindEditor.ready(function(K) {
				K.create('#editor_ch', {
					urlType : 'absolute',
					afterBlur: function(){this.sync();},//失去焦点执行this获得值					
					uploadJson : '../KindEditor/asp/upload_json.asp?action=download'
				});
				K.create('#editor_en', {
					urlType : 'absolute',
					afterBlur: function(){this.sync();},//失去焦点执行this获得值					
					uploadJson : '../KindEditor/asp/upload_json.asp?action=download'
				});
		});
	</script>
<!--kindeditor编辑器END-->

<script language = "JavaScript">
function CheckForm()
{
	if (document.editForm.DownNameCH.value.length == 0) {
		alert("中文标题没有填写.");
		document.editForm.DownNameCH.focus();
		return false;
	}
	<%if chinato=1 then%>
	if (document.editForm.DownNameEN.value.length == 0) {
		alert("英文标题没有填写.");
		document.editForm.DownNameEN.focus();
		return false;
	}
	<%end if%>
	if (document.editForm.SeoKeywordsCH.value.length == 0) {
		alert("中文MetaKeywords没有填写.");
		document.editForm.SeoKeywordsCH.focus();
		return false;
	}
	if (document.editForm.SeoDescriptionCH.value.length == 0) {
		alert("中文SeoDescription没有填写.");
		document.editForm.SeoDescriptionCH.focus();
		return false;
	}
	<%if chinato=1 then%>
	if (document.editForm.SeoKeywordsEN.value.length == 0) {
		alert("英文MetaKeywords没有填写.");
		document.editForm.SeoKeywordsEN.focus();
		return false;
	}
	if (document.editForm.SeoDescriptionEN.value.length == 0) {
		alert("英文SeoDescription没有填写.");
		document.editForm.SeoDescriptionEN.focus();
		return false;
	}
	<%end if%>
	if (document.editForm.SortNameCH.value.length == 0) {
		alert("下载类别没有填写.");
		document.editForm.SortNameCH.focus();
		return false;
	}
var editor_ch=KindEditor.create('#editor_ch');
if (editor_ch.isEmpty())
	{
	  alert("请填中文说明！")	  
	  return false
	 }
	<%if chinato=1 then%>
var editor_en=KindEditor.create('#editor_en');
if (editor_en.isEmpty())
	{
	  alert("请填英文说明！")	  
	  return false
	 }
	<%end if%>  
	return true;
}
</script>
</HEAD>
<BODY>
<%
if Instr(session("AdminPurview"),"|16,")=0 then
  response.write ("<br><br><div align=""center""><font style=""color:red; font-size:9pt; "")>您没有管理该模块的权限！</font></div>")
  response.end
end if
dim Result
Result=request.QueryString("Result")
dim ID,ViewFlag,SortNameCH,SortID,SortPath,titlecolor
dim FileSize,FileUrl,CommendFlag,TopFlag,GroupID,GroupIdName,Exclusive,Content,SeoKeywordsCH,SeoKeywordsEN,SeoDescriptionCH,SeoDescriptionEN
ID=request.QueryString("ID")
call DownEdit()
%>
<%dim DownNameCh,DownNameEn,ViewFlagCh,ViewFlagEn,ContentCh,ContentEn%>
<br>
<form name="editForm" method="post" action="DownEdit.asp?Action=SaveEdit&Result=<%=Result%>&ID=<%=ID%>" onSubmit="return CheckForm()">
<table class="tableborder" width="95%" border="0" align="center" cellpadding="3" cellspacing="1">

    <tr>
      <th height="22" colspan="2">【<%If Result = "Add" then%>添加<%ElseIf Result = "Modify" then%>修改<%End If%>下载】</th>
    </tr>
    <tr>
      <td width="20%" align="right" class="forumRow">中文标题：</td>
      <td width="80%" class="forumRowHighlight"><input name="DownNameCH" type="text" id="DownNameCH" style="width: 280" value="<%=DownNameCH%>" maxlength="100">
        是否显示：
        <input name="ViewFlagCH" type="checkbox" value="1" checked <%if ViewFlagCH then response.write ("checked")%>>
        <font color="red">*</font></td>
    </tr>
	<%if chinato=1 then%>
	<tr>
        <td width="20%" align="right" class="forumRow">英文标题：</td>
      <td width="80%" class="forumRowHighlight"><input name="DownNameEN" type="text" id="DownNameEN" style="WIDTH: 280;" value="<%=DownNameEN%>" maxlength="100">&nbsp;是否显示：
          <input name="ViewFlagEn" type="checkbox" value="1" style='HEIGHT: 13px;WIDTH: 13px;' <%if ViewFlagEn then response.write ("checked")%>>
          </td>
    </tr>
	<%End if%>
    <tr>
      <td align="right" class="forumRow">标题颜色：</td>
      <td class="forumRowHighlight"><font face="宋体">
          
          <select name="titlecolor" >
            <option style="COLOR: black" value="0" selected>不使用 </option>
            <option style="background: #000088" value="000088" <% if titlecolor="000088" Then Response.write("Selected") %>> </option>
            <option style="background: #0000ff" value="0000ff" <% if titlecolor="0000ff" Then Response.write("Selected") %>> </option>
            <option style="background: #008800" value="008800" <% if titlecolor="008800" Then Response.write("Selected") %>> </option>
            <option style="background: #008888" value="008888" <% if titlecolor="008888" Then Response.write("Selected") %>> </option>
            <option style="background: #0088ff" value="0088ff" <% if titlecolor="0088ff" Then Response.write("Selected") %>> </option>
            <option style="background: #00a010" value="00a010" <% if titlecolor="00a010" Then Response.write("Selected") %>> </option>
            <option style="background: #1100ff" value="1100ff" <% if titlecolor="1100ff" Then Response.write("Selected") %>> </option>
            <option style="background: #111111" value="111111" <% if titlecolor="111111" Then Response.write("Selected") %>> </option>
            <option style="background: #333333" value="333333" <% if titlecolor="333333" Then Response.write("Selected") %>> </option>
            <option style="background: #50b000" value="50b000" <% if titlecolor="50b000" Then Response.write("Selected") %>> </option>
            <option style="background: #880000" value="880000" <% if titlecolor="880000" Then Response.write("Selected") %>> </option>
            <option style="background: #8800ff" value="8800ff" <% if titlecolor="8800ff" Then Response.write("Selected") %>> </option>
            <option style="background: #888800" value="888800" <% if titlecolor="888800" Then Response.write("Selected") %>> </option>
            <option style="background: #888888" value="888888" <% if titlecolor="888888" Then Response.write("Selected") %>> </option>
            <option style="background: #8888ff" value="8888ff" <% if titlecolor="8888ff" Then Response.write("Selected") %>> </option>
            <option style="background: #aa00cc" value="aa00cc" <% if titlecolor="aa00cc" Then Response.write("Selected") %>> </option>
            <option style="background: #aaaa00" value="aaaa00" <% if titlecolor="aaaa00" Then Response.write("Selected") %>> </option>
            <option style="background: #ccaa00" value="ccaa00" <% if titlecolor="ccaa00" Then Response.write("Selected") %>> </option>
            <option style="background: #ff0000" value="ff0000" <% if titlecolor="ff0000" Then Response.write("Selected") %>> </option>
            <option style="background: #ff0088" value="ff0088" <% if titlecolor="ff0088" Then Response.write("Selected") %>> </option>
            <option style="background: #ff00ff" value="ff00ff" <% if titlecolor="ff00ff" Then Response.write("Selected") %>> </option>
            <option style="background: #ff8800" value="ff8800" <% if titlecolor="ff8800" Then Response.write("Selected") %>> </option>
            <option style="background: #ff0005" value="ff0005" <% if titlecolor="ff0005" Then Response.write("Selected") %>> </option>
            <option style="background: #ff88ff" value="ff88ff" <% if titlecolor="ff88ff" Then Response.write("Selected") %>> </option>
            <option style="background: #ee0005" value="ee0005" <% if titlecolor="ee0005" Then Response.write("Selected") %>> </option>
            <option style="background: #ee01ff" value="ee01ff" <% if titlecolor="ee01ff" Then Response.write("Selected") %>> </option>
            <option style="background: #3388aa" value="3388aa" <% if titlecolor="3388aa" Then Response.write("Selected") %>> </option>
            <option style="background: #000000" value="000000" <% if titlecolor="000000" Then Response.write("Selected") %>> </option>
          </select>
         
        </font></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">中文MetaKeywords：</td>
      <td class="forumRowHighlight"><input name="SeoKeywordsCH" type="text" id="SeoKeywordsCH" style="width: 400" value="<%=SeoKeywordsCH%>" maxlength="250"> <input type="button" name="btn" value="从标题复制" title="复制标题到中文：MetaDescription、MetaKeywords" onClick="CopyWebTitleCH(document.editForm.DownNameCH.value);"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">中文MetaDescription：</td>
      <td class="forumRowHighlight"><input name="SeoDescriptionCH" type="text" id="SeoDescriptionCH" style="width: 400" value="<%=SeoDescriptionCH%>" maxlength="250"></td>
    </tr>
<%if chinato=1 then%>
    <tr>
      <td align="right" class="forumRow">英文MetaKeywords：</td>
      <td class="forumRowHighlight"><input name="SeoKeywordsEN" type="text" id="SeoKeywordsEN" style="width: 400" value="<%=SeoKeywordsEN%>" maxlength="250"> <input type="button" name="btn2" value="从标题复制" title="复制标题到英文：MetaDescription、MetaKeywords" onClick="CopyWebTitleEN(document.editForm.DownNameEN.value);"></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">英文MetaDescription：</td>
      <td class="forumRowHighlight"><input name="SeoDescriptionEN" type="text" id="SeoDescriptionEN" style="width: 400" value="<%=SeoDescriptionEN%>" maxlength="250"></td>
    </tr>
	<%End if%>
    <tr>
      <td align="right" class="forumRow">下载类别：</td>
      <td class="forumRowHighlight"><input name="SortID" type="text" id="SortID" style="width: 18; background-color:#fffff0" value="<%=SortID%>" readonly> <input name="SortPath" type="text" id="SortPath" style="width: 70; background-color:#fffff0" value="<%=SortPath%>" readonly> <input name="SortNameCH" type="text" id="SortNameCH" value="<%=SortNameCH%>" style="width: 180; background-color:#fffff0" readonly> <a href="javaScript:OpenScript('SelectSort.asp?Result=Download',500,500,'')">点此选择类别</a> <font color="red">*</font></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">阅读权限：</td>
      <td class="forumRowHighlight"><select name="GroupID">
          <% call SelectGroup() %>
        </select>
        <input name="Exclusive" type="radio" value="&gt;=" <%if Exclusive="" or Exclusive=">=" then response.write ("checked")%>>
        隶属
        <input type="radio" <%if Exclusive="=" then response.write ("checked")%> name="Exclusive" value="=">
        专属（隶属：权限值≥可查看，专属：权限值＝可查看）</td>
    </tr>
      <tr>
        <td width="20%" align="right" class="forumRow">状　　态：</td>
        <td width="80%" class="forumRowHighlight"><input name="CommendFlag" type="checkbox" style="HEIGHT: 13px;WIDTH: 13px;" value="1" <%if CommendFlag then response.write ("checked")%>>
          &nbsp;推荐&nbsp;<input name="TopFlag" type="checkbox" value="1" style="HEIGHT: 13px;WIDTH: 13px;" <%if TopFlag then response.write ("checked")%>>&nbsp;置顶</td>
      </tr>

  	  <tr>
      <td width="20%" align="right" class="forumRow">下载地址：</td>
      <td width="80%" class="forumRowHighlight"><input name="FileUrl" type="text" id="FileUrl" style="width: 280" value="<%=FileUrl%>" maxlength="100">
	  <iframe style="top:2px" ID="UploadFiles" src="upload_ttkj.asp?PhotoUrlID=3" frameborder=0 scrolling=no width="370" height="21"></iframe><font color="red">*</font></td>
    </tr>
    <tr>
      <td width="20%" align="right" class="forumRow">文件大小：</td>
      <td width="80%" class="forumRowHighlight"><input name="FileSize" type="text" id="FileSize" style="width: 280" value="<%=FileSize%>" maxlength="100">KB <font color="red">*</font></td>
    </tr>
    <tr>
      <td align="right" class="forumRow">中文说明：</td>
      <td class="forumRowHighlight"><textarea id="editor_ch" name="ContentCH" style="width:670px;height:400px;"><%=ContentCH%></textarea></td>
    </tr>
	<%if chinato=1 then%>
	<tr>
      <td align="right" class="forumRow">英文说明：</td>
      <td class="forumRowHighlight"><textarea id="editor_en" name="ContentEN" style="width:670px;height:400px;"><%=ContentEN%></textarea></td>
    </tr>
	<%End if%>
    <tr>
      <td align="right" class="forumRow"></td>
      <td class="forumRowHighlight"><input type="checkbox" name="T_SaveImg" value="1" /> 保存内容中远程图片到本地&nbsp;&nbsp;<input type="checkbox" name="AspJpeg" value="1" checked/>给上传图片加水印&nbsp;&nbsp;（<font color="red">注:<%if Result="Modify" then%>当距发布时间超过<%=Watermark_interval%>分钟时去掉勾确保图片不重复加水印。<%end if%>上传图片等宽度勿超760像素，否则页面变形</font>）</td>
    </tr>
	<tr>
      <td align="right" class="forumRow"></td>
      <td class="forumRowHighlight"><input name="submitSaveEdit" type="submit" id="submitSaveEdit" value="保存"> <input type="button" value="返回上一页" onClick="history.back(-1)"></td>
    </tr>

  </form>

</table>

</BODY>
</HTML>
<%
sub DownEdit()
  dim Action,rsRepeat,rs,sql
  Action=request.QueryString("Action")
  if Action="SaveEdit" Then
  ContentCh=trim(Request.Form("ContentCh"))
  ContentEn=trim(Request.Form("ContentEn"))    
    set rs = server.createobject("adodb.recordset")
    if len(trim(request.Form("DownNameCh")))<1 then
     Call Alert ("中文标题为必填项目！","-1")
      response.end
    end if
    if request.Form("ViewFlagEn")=1 then
      if len(trim(request.Form("DownNameEn")))<1 then
      Call Alert ("英文标题为必填项目！","-1")
      response.end
      end if
    end If
    


    if Result="Add" then '创建下载信息
	  sql="select * from TianTianCMS_Download"
      rs.open sql,conn,1,3
      rs.addnew
      rs("DownNameCh")=trim(Request.Form("DownNameCh"))
      rs("DownNameEn")=trim(Request.Form("DownNameEn"))
	  if Request.Form("ViewFlagCh")=1 then
        rs("ViewFlagCh")=Request.Form("ViewFlagCh")
	  else
        rs("ViewFlagCh")=0
	  end if
	  if Request.Form("ViewFlagEn")=1 then
        rs("ViewFlagEn")=Request.Form("ViewFlagEn")
	  else
        rs("ViewFlagEn")=0
	  end if
	  if Request.Form("SortID")="" and Request.Form("SortPath")="" Then
	   Call Alert ("请选择所属分类！","-1")         
        response.end
	  else
	    rs("SortID")=Request.Form("SortID")
		rs("SortPath")=Request.Form("SortPath")
	  end if
	  if Request.Form("CommendFlag")=1 then
        rs("CommendFlag")=Request.Form("CommendFlag")
	  else
        rs("CommendFlag")=0
	  end If
      if Request.Form("TopFlag")=1 then
		rs("TopFlag")=Request.Form("TopFlag")
      else
		rs("TopFlag")=0
      end if  	  
      GroupIdName=split(Request.Form("GroupID"),"┎╂┚")
	  rs("GroupID")=GroupIdName(0)
	  rs("Exclusive")=trim(Request.Form("Exclusive"))
	  rs("FileSize")=trim(Request.Form("FileSize"))
	  rs("FileUrl")=trim(Request.Form("FileUrl"))
	  rs("ContentCh")=ContentCh
	  rs("ContentEn")=ContentEn
	  rs("SeoKeywordsCH")=trim(Request.Form("SeoKeywordsCH"))
	  rs("SeoDescriptionCH")=trim(Request.Form("SeoDescriptionCH"))
	  rs("SeoKeywordsEN")=trim(Request.Form("SeoKeywordsEN"))
	  rs("SeoDescriptionEN")=trim(Request.Form("SeoDescriptionEN"))
	  rs("titlecolor")=Request.Form("titlecolor")
	  rs("AddTime")=now()
	  rs("UpdateTime")=now()
	  rs.update
	  rs.close
	  set rs=Nothing
	  set rs=server.createobject("adodb.recordset")
	  sql="select top 1 ID from TianTianCMS_Download order by ID desc"
	  rs.open sql,conn,1,1
	  ID=rs("ID")
	  rs.close
	  set rs=Nothing
	  if ISHTML = 1 then
	  call html2("/CH/html/","/CH/",""&DownName&""&Separated&""&ID&"."&HTMLName&"","DownShow.Asp","ID=",ID,"","")
	  if chinato=1 then call html2("/EN/html/","/EN/",""&DownName&""&Separated&""&ID&"."&HTMLName&"","DownShow.Asp","ID=",ID,"","")
	  End If
	end if
	if Result="Modify" then
      sql="select * from TianTianCMS_Download where ID="&ID
      rs.open sql,conn,1,3
      rs("DownNameCh")=trim(Request.Form("DownNameCh"))
      if chinato=1 then rs("DownNameEn")=trim(Request.Form("DownNameEn"))
	  if Request.Form("ViewFlagCh")=1 then
        rs("ViewFlagCh")=Request.Form("ViewFlagCh")
	  else
        rs("ViewFlagCh")=0
	  end if
	  if Request.Form("ViewFlagEn")=1 then
        if chinato=1 then rs("ViewFlagEn")=Request.Form("ViewFlagEn")
	  else
        if chinato=1 then rs("ViewFlagEn")=0
	  end if
	  if Request.Form("SortID")<>"" and Request.Form("SortPath")<>"" then
	    rs("SortID")=Request.Form("SortID")
		rs("SortPath")=Request.Form("SortPath")
	  Else
	  Call Alert ("请选择所属分类！","-1")       
        response.end
	  end if
	  if Request.Form("CommendFlag")=1 then
        rs("CommendFlag")=Request.Form("CommendFlag")
	  else
        rs("CommendFlag")=0
	  end If
      if Request.Form("TopFlag")=1 then
		rs("TopFlag")=Request.Form("TopFlag")
      else
		rs("TopFlag")=0
      end if	  
      GroupIdName=split(Request.Form("GroupID"),"┎╂┚")
	  rs("GroupID")=GroupIdName(0)
	  rs("Exclusive")=trim(Request.Form("Exclusive"))
	  rs("FileSize")=trim(Request.Form("FileSize"))
	  rs("FileUrl")=trim(Request.Form("FileUrl"))
	  rs("ContentCh")=ContentCh
	  if chinato=1 then rs("ContentEn")=ContentEn
	  rs("SeoKeywordsCH")=trim(Request.Form("SeoKeywordsCH"))
	  rs("SeoDescriptionCH")=trim(Request.Form("SeoDescriptionCH"))
	  if chinato=1 then rs("SeoKeywordsEN")=trim(Request.Form("SeoKeywordsEN"))
	  if chinato=1 then rs("SeoDescriptionEN")=trim(Request.Form("SeoDescriptionEN"))
	  rs("titlecolor")=Request.Form("titlecolor")
	  rs("UpdateTime")=now()
	  rs.update
	  rs.close
	  set rs=Nothing
	  if ISHTML = 1 then
	  call html2("/CH/html/","/CH/",""&DownName&""&Separated&""&ID&"."&HTMLName&"","DownShow.Asp","ID=",ID,"","")
	  if chinato=1 then call html2("/EN/html/","/EN/",""&DownName&""&Separated&""&ID&"."&HTMLName&"","DownShow.Asp","ID=",ID,"","")
	  End If
	end if
    if ISHTML = 1 then
    response.write "<script language='javascript'>alert('设置成功，接着生成相关静态页！');location.replace('Admin_htmlindex.asp?htmlsc=Admin_htmldownsort.asp');</script>"
	Else
	response.write "<script language='javascript'>alert('设置成功！');location.replace('DownEdit.asp?Result="&request.QueryString("Result")&"&ID="&id&"');</script>"
	End If
  else
	if Result="Modify" then
      set rs = server.createobject("adodb.recordset")
      sql="select * from TianTianCMS_Download where ID="& ID
      rs.open sql,conn,1,1
      if rs.bof and rs.eof then
        response.write ("<center>数据库记录读取错误！</center>")
        response.end
      end if
	  DownNameCh=rs("DownNameCh")
	  DownNameEn=rs("DownNameEn")
	  ViewFlagCh=rs("ViewFlagCh")
	  ViewFlagEn=rs("ViewFlagEn")
	  SortNameCH=SortText(rs("SortID"))
	  SortID=rs("SortID")
	  SortPath=rs("SortPath")
	  CommendFlag=rs("CommendFlag")
	  TopFlag=rs("TopFlag")
	  GroupID=rs("GroupID")
	  Exclusive=rs("Exclusive")
	  FileSize=rs("FileSize")
	  FileUrl=rs("FileUrl")
      ContentCh=rs("ContentCh")
      ContentEn=rs("ContentEn")
	  SeoKeywordsCH=rs("SeoKeywordsCH")
	  SeoDescriptionCH=rs("SeoDescriptionCH")
	  SeoKeywordsEN=rs("SeoKeywordsEN")
	  SeoDescriptionEN=rs("SeoDescriptionEN")
	  titlecolor=rs("titlecolor")
	  rs.close
      set rs=nothing
    end if
  end if
end sub

sub SelectGroup()
  dim rs,sql
  set rs = server.createobject("adodb.recordset")
  sql="select GroupID,GroupNameCH from TianTianCMS_MemGroup"
  rs.open sql,conn,1,1
  if rs.bof and rs.eof then
    response.write("未设组别")
  end if
  while not rs.eof
    response.write("<option value='"&rs("GroupID")&"┎╂┚"&rs("GroupNameCH")&"'")
    if GroupID=rs("GroupID") then response.write ("selected")
    response.write(">"&rs("GroupNameCH")&"</option>")
    rs.movenext
  wend
  rs.close
  set rs=nothing
end sub

Function SortText(ID)
  Dim rs,sql
  Set rs=server.CreateObject("adodb.recordset")
  sql="Select * From TianTianCMS_DownCategory where ID="&ID
  rs.open sql,conn,1,1
  SortText=rs("SortNameCH")
  rs.close
  set rs=nothing
End Function
%>