<!--#include file="../../fy.Function.asp"-->
<!--#include file="../../../fy_inc/cls_pageview.asp"-->
<!doctype html>
<html>
<head>
<meta charset="gb2312">
<title>变量系统管理</title>
<link rel="stylesheet" type="text/css" href="../../css/base.css">
<link rel="stylesheet" type="text/css" href="../../css/content.css">
<script type="text/javascript" src="../../../fy_inc/js/swfobject.js"></script>
<SCRIPT LANGUAGE='JavaScript'>
var fyuser="<%=fycms.strToAsc(RSQL(Trim(Request.Cookies(fycmsN)("AdminName"))))%>";
var fypass="<%=fycms.strToAsc(RSQL(Trim(Request.Cookies(fycmsN)("AdminPassword"))))%>";
</SCRIPT>
<!--#include file="../../../editor/index.asp"-->
<%=writejs("../../../")%>
</head>
<body>
<div class="content"> 
	<div class="breadnav">当前位置：<a href="#">后台首页</a> >> 模型管理</div>
    <div class="opers">
	<a href="index.asp" class="btn<%If request("Action")="" Then echo " btn_primary" %>">管理首页</a>
	<a href="index.asp?Action=add" class="btn<%If request("Action")="add" Then echo " btn_primary" %>">新建变量</a>
	<a href="edit.asp?Action=fuckdz" class="btn">修改全部变量内容</a>
    </div>
   <% 
	If Not fycms.fycms_QXYZ(0,"variables","") Then   Call fycms.Alert("对不起，你没有操作权限！","") 
	Set FsoObj = CreateObject(fycms.FsoName) 
Dim vname,vtype,vcontent,variablesname,vid,vdescription
Dim FileObj,FolderObj,SubFolderObj,FsoItem,FileExtName,xml
 dim FsoObj,Action,ID,ShowErr
	Action = Request("Action")
	ID = Request("ID")
	Select Case Action
			Case "add","edit" 
				Call edit()
			Case "saveedit","saveadd"
				Call saveedit()
			Case "del"
				Call del()
			Case Else
				Call Main()
	End Select
	
	Sub Del()
   	 	Call fycms.DeleteFile(fycms.ThisTheme&"/variables/"&fycms.s("vid")&".xml")
		Set conn=nothing
	 	Call fycms.ActErr("删除成功","Sys_fy/variables/Index.asp","")
 		Response.End
    End Sub
 

	Sub saveedit()


		Dim FilePath
	    If action="saveadd" Then 
			If fycms.s("vid")="" Then die "请输入变量id"
		FilePath=fycms.ThisTheme&"/variables/"&fycms.s("vid")&".xml"
		Else 
		FilePath=fycms.ThisTheme&"/variables/"&fycms.s("vid")&".xml"
		End If 











 'On Error Resume Next
 	Dim XmlDoc,Root,xRoot
	Set XmlDoc = Server.CreateObject("Microsoft.XMLDOM")
		XmlDoc.async = False
		XmlDoc.ValidateOnParse=False
		Set Root = XmlDoc.createProcessingInstruction("xml","version='1.0' encoding='gb2312' standalone='yes'")
		XmlDoc.appendChild(Root)
		Set xRoot = XmlDoc.appendChild(XmlDoc.CreateElement("fycmsv"))
			xRoot.setAttribute "version","1.0"
		Set xRoot = Nothing

		'写入文件信息
 		Dim ThemeAuthor,ThemeSource 
		Dim XMLcdata

		Set vid = XmlDoc.SelectSingleNode("//fycmsv").AppendChild(XmlDoc.CreateElement("vid"))
			vid.Text = Request.Form("vid")
		Set vid=Nothing

		Set vname = XmlDoc.SelectSingleNode("//fycmsv").AppendChild(XmlDoc.CreateElement("vname"))
			vname.Text = Request.Form("vname")
		Set vname=Nothing

		Set vtype = XmlDoc.SelectSingleNode("//fycmsv").AppendChild(XmlDoc.CreateElement("vtype"))
			vtype.Text = Request.Form("vtype")
		Set vtype=Nothing

		Dim CThemeDescription

		
	 

		Set vdescription = XmlDoc.SelectSingleNode("//fycmsv").AppendChild(XmlDoc.CreateElement("vdescription"))
		Set XMLcdata = XmlDoc.createNode("cdatasection", "","")
			 XMLcdata.NodeValue = Request.Form("vdescription")
		Set CThemeDescription = vdescription.AppendChild(XMLcdata)
		Set CThemeDescription = Nothing





 
		Set vcontent = XmlDoc.SelectSingleNode("//fycmsv").AppendChild(XmlDoc.CreateElement("vcontent"))
		Set XMLcdata = XmlDoc.createNode("cdatasection", "","")
			 XMLcdata.NodeValue = Request.Form("vcontent")
		Set CThemeDescription = vcontent.AppendChild(XMLcdata)
		Set CThemeDescription = Nothing
		Set XMLcdata = Nothing
		Set vcontent=Nothing
 		XmlDoc.Save(Server.mappath(FilePath))
		Set Root = Nothing
	Set XmlDoc = Nothing
 
 





		Call fycms.ActErr("修改成功","Sys_fy/variables/Index.asp","")
	End Sub	

	sub Main()
 
 
  
%> <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
      <th>变量名称</th>
	  <th>变量类型</th>
	  <th>变量值</th>
	  <th>参数说明</th>
	  </tr>
    </thead>
	<%
 
	If Not  FsoObj.fileexists(Server.mappath(fycms.ThisTheme&"/variables/")) then 
		Call fycms.CreateFolder(fycms.ThisTheme&"/variables/")
	End if

 
Set FolderObj = FsoObj.GetFolder(Server.MapPath(fycms.ThisTheme&"/variables/"))
Set SubFolderObj = FolderObj.SubFolders
Set FileObj = FolderObj.Files

for each FsoItem In FileObj
	FileExtName = LCase(Mid(FsoItem.name,InstrRev(FsoItem.name,".")+1))
  	if FileExtName="xml" Then
		variablesname=Split(FsoItem.name,".")(0) 
   			Set XML=fycms.NoAppGetXMLFromFile(server.MapPath(fycms.actsys&fycms.SysThemePath&"/"&fycms.NowTheme&"/variables/"&variablesname&".xml"))
		
			If IsObject(XML) And XML.readyState=4 Then
 				If XML.parseError.errorCode <> 0 Then 
				Else 
				vid = XML.documentElement.selectSingleNode("vid").text
				vname = XML.documentElement.selectSingleNode("vname").text
				vtype = XML.documentElement.selectSingleNode("vtype").text
				vcontent = XML.documentElement.selectSingleNode("vcontent").Text
				vdescription = XML.documentElement.selectSingleNode("vdescription").Text
				
  				End If 
			Set XML=Nothing
		  End If 
	%>
    <tr>
      <td ><%=vname%></td>
      <td >
	  
<%
Select Case vtype
	Case "1"
		echo "文本"
	Case "2"
		echo "文件上传"
	Case "3"
		echo "布尔(Y/N)"
	Case "4"
		echo "多行文本"
	Case "5"
		echo "编辑器文本"
	Case Else
		echo "文本"
End Select 

%></td>
      <td>[v:<%=vid%>]</td>
       <td>
	   <a href="edit.asp?vid=<%=vid%>">修改内容</a>  
	   <a href="?action=edit&vid=<%=vid%>">修改属性</a>  
      <a href="?Action=del&vid=<%=vid%>"  onClick="return confirm('确认删除此变量吗?此操作不可恢复')">删除 </a>
      </td>
    </tr>
	  <%
  	end if
next
%>    </table>
 

  <% end sub
	sub edit()
	Dim DiyPath,Rs,content,filedisabled,frmAction,tempurl
	IF Action = "edit" Then
 
    			Set XML=fycms.NoAppGetXMLFromFile(server.MapPath(fycms.actsys&fycms.SysThemePath&"/"&fycms.NowTheme&"/variables/"&fycms.s("vid")&".xml"))
 		
			If IsObject(XML) And XML.readyState=4 Then
 				If XML.parseError.errorCode <> 0 Then 
				Else 
					vid = XML.documentElement.selectSingleNode("vid").text
					vname = XML.documentElement.selectSingleNode("vname").text
					vtype = XML.documentElement.selectSingleNode("vtype").text
					vcontent = XML.documentElement.selectSingleNode("vcontent").Text
					vdescription = XML.documentElement.selectSingleNode("vdescription").Text
   				End If 
			Set XML=Nothing
		  End If 



				If vdescription <> "" Then vdescription=Server.HTMLEncode(vdescription)



 		frmAction		= "edit"
		filedisabled="disabled"

	Else
		frmAction = "add"
	End IF
  %>


    <form name="form1" method="post" action="Index.asp">
    <div class="divtable"> 
        <dl>
            <dt>变量名称:</dt>
            <dd>
                <input name="vname" type="text"  class="Ainput" value="<%= vname %>" size="50">
             </dd>
         </dl>
        
        <dl>
            <dt>变量ID:</dt>
            <dd>
               <input name="vid" type="text"  class="Ainput"   value="<%= vid %>" size="50">必须英文,模版调用
             </dd>
         </dl>
 
        <dl>
            <dt>变量类型:</dt>
            <dd>
               <label for="vtype1"><input type="radio" name="vtype" id="vtype1"  value="1" Checked/>
        文本</label>
        <label for="vtype2"><input type="radio" name="vtype" id="vtype2" value="2"  <%If vtype="2" Then echo "Checked" %>   />
        文件</label>
        <label for="vtype3"><input type="radio" name="vtype" id="vtype3" value="3"  <%If vtype="3" Then echo "Checked" %>   />
        布尔(Y/N)</label>
        <label for="vtype4"><input type="radio" name="vtype" id="vtype4" value="4"  <%If vtype="4" Then echo "Checked" %>  />
        多行文本</label>  
        <label for="vtype5"><input type="radio" name="vtype" id="vtype5" value="5"  <%If vtype="5" Then echo "Checked" %>  />
        编辑器文本</label> 
             </dd>
         </dl>
 
        <dl>
            <dt>描述:</dt>
            <dd>
               <textarea name="vdescription" id="vdescription" cols="50" rows="10"><%=vdescription%></textarea>
             </dd>
         </dl>
 <input type="hidden" name="vcontent" id="vcontent" value="<%=Server.HTMLEncode(vcontent)%>">
        <dl>
            <dt>内容预览:</dt>
            <dd>
			<%=Server.HTMLEncode(vcontent)%>
             </dd>
         </dl>
 
 
            <dl>  <dt></dt>
             <dd>
				<input type=button onclick=CheckForm() class="btn btn_primary"  name=Submit1 value="  保存  " />
				<input name="Submit2" type="reset" class="btn btn_primary" value="  重置  ">
				<input name="Action" type="hidden" id="Action" value="save<%=frmAction%>">
				<input name="ID" type="hidden" id="ID" value="<%=id%>">
				<input name="files" type="hidden"  value="<%=fycms.s("file")%>">
            </dd>
         </dl>
        
    </div>
    </form>




 


<script language="javascript">
 
function CheckForm()
{ var form=document.form1;
	 
	    <%if vtype="6" then echo checkeditpost(0,1)%>
 	    form.submit();
        return true;
	}</script>  
	<%end sub
CloseConn %>
</div>
</body>
</html>
