<!--#include file="../fy.Function.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">
</head>
<body>
<div class="content"> 
	<div class="breadnav">当前位置：<a href="#">后台首页</a> >> 模型管理</div>
    <div class="opers">
		<a href="fy.mx.asp?A=Add"  class="btn">添加/修改模型</a> 
		<a href="ModeList.asp?A=1" class="btn <%If fycms.s("A")="1" Then echo " btn_primary" %>">导出内容模型</a>
	    <a href="ModeList.asp?A=2" class="btn <%If fycms.s("A")="2" Then echo " btn_primary" %>">导入内容模型</a>


    </div>
<%
	Dim a,Rs
	If Not fycms.ChkAdmin() Then  Call fycms.Alert("对不起，您没有操作权限！","")
	a=request("A")
	Select Case a
		case "dc"
			call dc()
		case "2"
			call dr()
		case "3"
			call drbc()
		case "dcbc"
			call dcbc()
		Case Else 
			Call main()
	End select

	sub drbc()
		dim ModeName,M_fy,L_fy,MX_fy,i,TCJ_fy,M_Rs,M_RsSql,Sql,ModeID,TableName
		ModeName= request("ModeName")
		M_fy = split(ModeName,"|*|")
 		if ubound(M_fy)<>1 then call fycms.Alert("提交的模型配置参数不正确","")
		MX_fy = Split(M_fy(0),"$|$")'模型配置
		TCJ_fy = Split(M_fy(1),"|||")
		if ubound(MX_fy)<>18 then call fycms.Alert("提交的模型配置参数不正确","")
		
		'echo MX_fy(22)'目录
		'echo MX_fy(2)'表
		'echo MX_fy(0)'模型名称
		
			 IF MX_fy(2) = "" Then
				Call fycms.Alert("数据表为空!",""):Exit Sub
			 End if
			 If Not fycms.ACTEXE("SELECT ModeName FROM Mode_fy Where ModeName='" & MX_fy(0) & "' order by ModeID desc").eof Then
				Call fycms.Alert("系统已存在该模型名称!",""):Exit Sub
			 End if	

			 If Not fycms.ACTEXE("SELECT ModeTable FROM Mode_fy Where ModeTable='" & MX_fy(2) & "' order by ModeID desc").eof Then
				Call fycms.Alert("系统已存在该数据表!",""):Exit Sub
			 End if	
 			 Set M_Rs = Server.CreateObject("adodb.recordset")
			  M_RsSql = "select * from Mode_fy"
			  M_Rs.Open M_RsSql, Conn, 1, 3
			  M_Rs.AddNew
			  M_Rs("ModeName") = MX_fy(0)
			  M_Rs("IFmake") = MX_fy(1)
		 	  M_Rs("ModeTable") = MX_fy(2)
			  TableName= MX_fy(2)
			  M_Rs("AutoPage") = MX_fy(3)
			  M_Rs("directory") = MX_fy(4)
			  M_Rs("UpFilesDir") = MX_fy(5)
 			  M_Rs("ContentExtension") = MX_fy(6)
			  M_Rs("ModeStatus") = MX_fy(7)
			  M_Rs("RefreshFlag") = MX_fy(8)
			  M_Rs("RecyleIF") = MX_fy(9)
			  M_Rs("ACT_DiY") ="§0§0-1-0-1§0§fycms§0§§0§§0§§0§Simple§§§0§0§0§1§0§1§0§"&fycms.fycms_Sys(3)&"templets/article/ClassIndex.htm§"&fycms.fycms_Sys(3)&"templets/article/Class.Htm§"&fycms.fycms_Sys(3)&"templets/article/Content.Htm§"
			  M_Rs("MakeFolderDir") = MX_fy(11)
			  M_Rs("WriteComment") = MX_fy(12)
			  M_Rs("CommentCode") = MX_fy(13)
			  M_Rs("Commentsize") = MX_fy(14)
			  M_Rs("ModeNote") = MX_fy(15)
			  M_Rs("CommentTemp") = MX_fy(16)
			  M_Rs("adminmb") = MX_fy(17)
			  M_Rs("usermb") = MX_fy(18)
 
			  M_Rs.Update
			  ModeID=M_Rs("ModeID") 
			  M_Rs.Close:Set M_Rs = Nothing			
				 Sql="CREATE TABLE "&MX_fy(2)&" ([ID] int IDENTITY (1, 1) NOT NULL CONSTRAINT PrimaryKey PRIMARY KEY,"&_
				"ClassID int Default 0,"&_
				"Title varchar(250),"&_
				"IntactTitle varchar(250),"&_
				"ActLink tinyint,"&_
 				"Intro text,"&_
				"Content text,"&_
				"allpic text,"&_
				"Hits int Default 0,"&_
				"rev tinyint Default 0,"&_
				"ChargeType tinyint Default 0,"&_
				"InfoPurview tinyint Default 0,"&_
				"arrGroupID varchar(250),"&_
				"pinyin varchar(250),"&_
				"ReadPoint  int Default 0,"&_
				"PitchTime  int Default 0,"&_
				"ReadTimes  int Default 0,"&_
				"DividePercent  int Default 0,"&_
				"KeyWords varchar(200),"&_
				"description varchar(200),"&_
 				"CopyFrom varchar(250),"&_
				"addtime datetime,"&_
				"UpTime datetime,"&_
				"publishtime datetime,"&_
				"TemplateUrl varchar(100),"&_
				"FileName varchar(200),"&_
				"isAccept tinyint,"&_
				"delif tinyint Default 0,"&_
				"UserID  int Default 0,"&_
				"ArticleInput varchar(250),"&_
				"Author varchar(250),"&_
				"Slide tinyint Default 0,"&_
				"PicUrl varchar(200),"&_
				"UserIP varchar(200),"&_
				"upIP varchar(200),"&_
				"Ismake tinyint,"&_
				"Digg int Default 0,"&_
				"down int Default 0,"&_
				"ATT SmallInt Default 0,"&_
				"OrderID int Default 10,"&_
				"commentscount int Default 0,"&_
				"IStop tinyint Default 0"&_
				")"
			fycms.ACTEXE(sql)
			Application.Contents.RemoveAll
			 
			 
			 
			 
		dim FieldType,Title,IsNotNull,ISType,Type_Default,Description,FieldName,ColumnType,OrderID
		Dim width,height,Content,Type_Type,FieldRS,FieldSql
		for i=0 to ubound(TCJ_fy)-1
		L_fy = Split(TCJ_fy(i),"@")
		if ubound(L_fy)<>11 then call fycms.Alert("提交的模型配置参数不正确","")
		IF fycms.Chkchars(L_fy(0)) = False  Then
			Call fycms.ActErr("英文名称只能为英文、数字及下划线","Mode/fy.ListM.ASP?A=L&ModeID="&ModeID,"")
		End if
			FieldName=L_fy(0)
			Title=L_fy(1)
			IsNotNull=ChkNumeric(L_fy(2))
			OrderID=L_fy(3)
			Description=L_fy(4)
			FieldType=L_fy(5)
			Type_Default=L_fy(6)
			width=L_fy(7)
			height=L_fy(8)
			Content	=L_fy(9)
			Type_Type=L_fy(10)
			ISType=ChkNumeric(L_fy(11))
		
		Select Case FieldType
			Case "TextType"'单行文本
				ColumnType="varchar(255)"
			Case "MultipleTextType"'多行文本(不支持Html
				 ColumnType="text"
			Case "MultipleHtmlType"'多行文本(支持Html)
				ColumnType="text"
			Case "RadioType"'单选项
				ColumnType="varchar(255)"
			Case "ListBoxType"'多选项
				ColumnType="text"
			Case "NumberType"'数字
				ColumnType="int"'
		   Case "DateType"
				 ColumnType="datetime"'echo "日期时间"
		   Case "NumberType"
				ColumnType="int"'echo "数字"
		   Case else
		     ColumnType="varchar(255)"
		End Select 
		
		 Set FieldRS = Server.CreateObject("ADODB.RECORDSET")
		 FieldSql = "Select * From [Table_fy] Where FieldName='" & FieldName & "' And  fycms=1 and  ModeID=" & ModeID
		 FieldRS.Open FieldSql, conn, 3, 3
		 If FieldRS.EOF And FieldRS.BOF Then
			FieldRS.AddNew
			FieldRS("FieldName")=L_fy(0)
			FieldRS("Title")=L_fy(1)
			FieldRS("IsNotNull")=ChkNumeric(L_fy(2))
			FieldRS("OrderID")=L_fy(3)
			FieldRS("Description")=L_fy(4)
			FieldRS("FieldType")=L_fy(5)
			FieldRS("Type_Default")=L_fy(6)
			FieldRS("width")=ChkNumeric(L_fy(7))
			FieldRS("height")=ChkNumeric(L_fy(8))
			FieldRS("Content")=L_fy(9)
			FieldRS("Type_Type")=ChkNumeric(L_fy(10))
			FieldRS("ISType")=ChkNumeric(L_fy(11))
			FieldRS("ModeID") = ModeID
		  FieldRS.Update
		 Conn.Execute("Alter Table "&TableName&" Add "&L_fy(0)&" "&ColumnType&"")
		 
		 Else
		   Call fycms.Alert("数据库中已存在该字段名称!", "")
		   Exit Sub
		 End If
		next 
		Application.Contents.RemoveAll
		Call fycms.ActErr("导入模型成功","Mode/fy.MX.asp","")
	end sub
	sub dcbc()
	Dim rs,rs1,M_fy,T_fy,modeid,ModePath
	modeid=ChkNumeric(fycms.S("modeid"))
  	Set Rs=server.CreateObject("adodb.recordset") 
	Set Rs1=server.CreateObject("adodb.recordset") 
	Rs.OPen "Select * from Mode_fy where ModeID="&modeid&" ",Conn,1,1
	If Not rs.eof Then 
				M_fy=M_fy&Rs("ModeName")&"$|$"
				M_fy=M_fy&Rs("IFmake")&"$|$"
				M_fy=M_fy&Rs("ModeTable")&"$|$"
				M_fy=M_fy&Rs("AutoPage")&"$|$"
				M_fy=M_fy&Rs("directory")&"$|$"
				M_fy=M_fy&Rs("UpFilesDir")&"$|$"
				M_fy=M_fy&Rs("ContentExtension")&"$|$"
				M_fy=M_fy&Rs("ModeStatus")&"$|$"
				M_fy=M_fy&Rs("RefreshFlag")&"$|$"
				M_fy=M_fy&Rs("RecyleIF")&"$|$"
				M_fy=M_fy&Rs("ACT_DiY")&"$|$"
				M_fy=M_fy&Rs("MakeFolderDir")&"$|$"
				M_fy=M_fy&Rs("WriteComment")&"$|$"
				M_fy=M_fy&Rs("CommentCode")&"$|$"
				M_fy=M_fy&Rs("Commentsize")&"$|$"
				M_fy=M_fy&Rs("ModeNote")&"$|$"
				M_fy=M_fy&Rs("CommentTemp")&"$|$"
				M_fy=M_fy&Rs("usermb")&"$|$"
				M_fy=M_fy&Rs("adminmb")&"|*|"
 	End If 
	rs.close
	Rs1.OPen "Select * from Table_fy where ModeID="&modeid&" ",Conn,1,1
	If Not rs1.eof Then 
		Do While Not rs1.eof 
		T_fy=T_fy&Rs1("FieldName")&"@"
		T_fy=T_fy&Rs1("Title")&"@"
		T_fy=T_fy&Rs1("IsNotNull")&"@"
		T_fy=T_fy&Rs1("OrderID")&"@"
		T_fy=T_fy&Rs1("Description")&"@"
		T_fy=T_fy&Rs1("FieldType")&"@"
		T_fy=T_fy&Rs1("Type_Default")&"@"
		T_fy=T_fy&Rs1("width")&"@"
		T_fy=T_fy&Rs1("height")&"@"
		T_fy=T_fy&Rs1("Content")&"@"
		T_fy=T_fy&Rs1("Type_Type")&"@"
		T_fy=T_fy&Rs1("ISType")&"|||"

		rs1.movenext
		loop
	End If 
	rs1.close
	Call FSOSaveFile(M_fy&T_fy, fycms.actsys&"modemdb.txt")	
	echo "<br><br><br><div align=center>操作完成!<a href=" & fycms.actsys&"modemdb.txt" & ">请点击这里下载</a>(右键目标另存为)  </div><br><br><br><br><br><br><br>"
	end sub 
	
	Function FSOSaveFile(Templetcontent,FileName)
		on error resume next 
		Dim FileFSO,FileType
		 Set FileFSO = Server.CreateObject("ADODB.Stream")
			With FileFSO
			.Type = 2
			.Mode = 3
			.Open
			.Charset = "gb2312"
			.Position = FileFSO.Size
			.WriteText  Templetcontent
			.SaveToFile Server.MapPath(FileName),2
			If Err.Number<>0 Then 
				Err.Clear 
				Exit Function 
			End If 
			.Close
			End With
		Set FileType = nothing
		Set FileFSO = nothing
	End Function
	sub dr()
	
	  %>
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    	<form name="form2" method="post" action="?A=3">
	    <tr>
	      <td class="bg_tr">您现在的位置：<a href="fy.MX.asp">模型管理</a> &gt;&gt; 导入模型 </td>
	      </tr>
	    <tr>
          <td align="center"><textarea name="ModeName" cols="80" rows="20"></textarea></td>
        </tr>
	    <tr>
	      <td align="center" ><strong>将模型代码粘贴到上面的输入框</strong>
          <input name="Submit2" type="submit" class="btn btn_primary" value=" 提交 "></td>
	      </tr>
    	</form>  
	  </table>
<%end sub
	sub dc()
	
	 %>
	
<table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
  <form name="form1" method="post" action="?A=dcbc&modeid=<%=request("modeid")%>">
<tr>
    <td align="center" class="bg_tr">
  目标路径地址:<%=fycms.actsys%>modemdb.txt
  <input name="Submit" type="submit" class="btn btn_primary" value="  导出  ">	</td>
  </tr></form>

</table>

<% end sub

	Sub Main()
	%>	


    <table width="100%" border="0" cellspacing="0" cellpadding="0">
    <thead>
      <tr>
    <th>模型ID</th>
    <th>模型名称</th>
    <th>表名</th>
    <th>描述</th>
    <th>状态</th>
	<th>生成Html</th>
    <th>操作</th>
	  
	  </tr>
    </thead>
   <% 
	  Set Rs =fycms.ACTEXE("SELECT ModeID, ModeName,ModeTable, ModeStatus, IFmake,ModeNote  FROM Mode_fy order by ModeID asc")
	 If Rs.EOF  Then
	 	echo	"<tr><td colspan=""6"" align=""center"">没有记录</td></tr>"
	 Else
		Do While Not Rs.EOF	
	 %><tr>

    <td><%= Rs("ModeID") %></td>
    <td><%= Rs("ModeName") %></td>
    <td><%= Rs("ModeTable") %></td>
    <td><%= Rs("ModeNote") %></td>
    <td><% IF Rs("ModeStatus") = 0 Then echo "<font color=green>正常</font>" else  echo "<font color=red>禁用</font>" %></td>
    <td>
	<% Select Case  Rs("IFmake")
		Case "0" 
			echo "<font color=red>不生成(动态浏览) </font>" 
		Case "1" 
			echo "<font color=green>生成(静态)</font>"
		Case "2"
			echo "<font color=green>伪静态</font>"
	  End Select 
	%>
	</td>
	<td>
	<a href="?A=dc&modeid=<%= Rs("ModeID") %>">导出模型</a></td>
  <% 
		
		Rs.movenext
		Loop
	End if	 %>

      </tr>
    </table>

         
<%End Sub%></div>