<!--#include file="../ACT.Function.asp"-->
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>1</title>
<link href="../Images/css1/css.css" rel="stylesheet" type="text/css">
</head>
<body>
<% 	
	Dim ID,Action,LabelRS,LabelName,LabelContent,SQLStr,Description,ShowErr,LabelC,SQL,LabelContentArr
	dim labeltype, PageStyle,ProjectUnit
		Action = Request.QueryString("Action")
	  Set LabelRS = Server.CreateObject("Adodb.Recordset")
		If Action = "EditLabel" Then
			ID = actcms.ChkNumeric(Request.QueryString("ID"))
			Set LabelRS = Server.CreateObject("Adodb.Recordset")
			SQLStr = "SELECT * FROM Label_ACT Where ID=" & ID & ""
			LabelRS.Open SQLStr, Conn, 1, 1
			LabelName = Replace(Replace(LabelRS("LabelName"), "{ACTSQL_", ""), "}", "")
			Description = LabelRS("Description")
			LabelContent = Replace(Replace(LabelRS("LabelContent"), "{$ACTSQL(", ""), ")}", "")
			LabelContent = Replace(LabelContent, """", "") 
			LabelContentArr = Split(LabelContent, "§")
			labeltype=LabelContentArr(0)
			ProjectUnit=LabelContentArr(1)
			PageStyle=LabelContentArr(2)
			SQL=LabelContentArr(3)
			LabelContent=LabelRS("Description")
			LabelRS.Close
		Else
		  If LabelContent="" Then LabelContent="[loop=10]请在此输入循环内容[/loop]"
			ProjectUnit="篇"
			labeltype=0
		End If
		
		
		
		Select Case Request.Form("Action")
		 Case "AddNewSubmit"
			LabelName = Replace(Replace(Trim(Request.Form("LabelName")), """", ""), "'", "")
			labeltype=Request.Form("labeltype")
			SQL = Trim(Request.Form("Sql"))
			ProjectUnit=Request.Form("ProjectUnit")
			PageStyle=ACTCMS.ChkNumeric(Request("PageStyle"))
			LabelC=labeltype&"§"&ProjectUnit&"§"&PageStyle&"§"&SQL
			LabelContent=Request.Form("LabelContent")
			If LabelName = "" Then
			  Response.Redirect("../Error.asp?Errs="&Server.URLEncode("<li>标签名称不能为空!</li>")&"&ErrorUrl=")
			  Response.End
			End If
			If LabelContent = "" Then
			  Response.Redirect("../Error.asp?Errs="&Server.URLEncode("<li>标签内容不能为空!</li>")&"&ErrorUrl=")
			  Response.End
			End If
			LabelName = "{ACTSQL_" & LabelName & "}"
			LabelRS.Open "Select LabelName From Label_ACT Where LabelName='" & LabelName & "'", Conn, 1, 1
			If Not LabelRS.EOF Then
			  Response.Redirect("../Error.asp?Errs="&Server.URLEncode("<li>标签名称已经存在!</li>")&"&ErrorUrl=")
			  LabelRS.Close
			  Conn.Close
			  Set LabelRS = Nothing
			  Set Conn = Nothing
			  Set ClsMain = Nothing
			  Response.End
			Else
				LabelRS.Close
				LabelRS.Open "Select * From Label_ACT", Conn, 1, 3
				LabelRS.AddNew
				 'LabelRS("ID") = ID
				 LabelRS("LabelName") = LabelName
				 LabelRS("LabelContent") = LabelC
				 LabelRS("Description") = LabelContent
				 LabelRS("AddDate") = Now
				 LabelRS("LabelFlag") = 1
				 LabelRS("LabelType") = 3
				 LabelRS.Update
			     ShowErr = "<li>添加标签成功! </li>&nbsp;&nbsp;&nbsp;&nbsp;<a href=Label_Admin.asp?Type=3><b><font color=red>返回管理首页</font></b></a></li>"
				 Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl=")
			End If
		Case "EditSubmit"
			ID = actcms.ChkNumeric(Trim(Request.Form("ID")))
			LabelName = Replace(Replace(Trim(Request.Form("LabelName")), """", ""), "'", "")
			labeltype=Request.Form("labeltype")
			SQL = Trim(Request.Form("Sql"))
			ProjectUnit=Request.Form("ProjectUnit")
			PageStyle=ACTCMS.ChkNumeric(Request("PageStyle"))
			LabelC=labeltype&"§"&ProjectUnit&"§"&PageStyle&"§"&SQL
			LabelContent=Request.Form("LabelContent")
			If LabelName = "" Then
			  Response.Redirect("../Error.asp?Errs="&Server.URLEncode("<li>标签名称不能为空!</li>")&"&ErrorUrl=")
			  Response.End
			End If
			If LabelContent = "" Then
			  Response.Redirect("../Error.asp?Errs="&Server.URLEncode("<li>标签内容不能为空!</li>")&"&ErrorUrl=")
			  Response.End
			End If
			LabelName = "{ACTSQL_" & LabelName & "}"
			LabelRS.Open "Select LabelName From Label_ACT Where ID <>" & ID & " AND LabelName='" & LabelName & "'", Conn, 1, 1
			If Not LabelRS.EOF Then
			  Response.Redirect("../Error.asp?Errs="&Server.URLEncode("<li>标签名称已经存在!</li>")&"&ErrorUrl=")
			  Response.End
			Else
				LabelRS.Close
				LabelRS.Open "Select * From Label_ACT Where ID=" & ID & "", Conn, 1, 3
				 LabelRS("LabelName") = LabelName
				 LabelRS("LabelContent") = LabelC
				 LabelRS("Description") = LabelContent
				 LabelRS("AddDate") = Now
				 LabelRS.Update
			     ShowErr = "<li>标签修改成功! </li>&nbsp;&nbsp;&nbsp;&nbsp;<a href=Label_Admin.asp?Type=3><b><font color=red>返回管理首页</font></b></a></li>"
				 Response.Redirect("../Error.asp?Errs="&Server.URLEncode(ShowErr)&"&ErrorUrl=")
			End If
		End Select
		
		

 %>
 
<form name="ahhfchhs" method="post" action="">
<% 
			If Action = "Add" Or Action = "" Then Response.Write "<input type='hidden' name='Action' value='AddNewSubmit'>"
			If Action = "EditLabel" Then Response.Write "<input type='hidden' name='Action' value='EditSubmit'>"
			
 %>
 <input type="hidden" name="ID" value="<%= ID %>"> 
  <table width="98%" border="0" align="center" cellpadding="2" cellspacing="1" class="table">
    <tr>
      <td colspan="2" align="center" class="bg_tr">创建自由标签</td>
    </tr>
    <tr>
      <td width="16%" align="right"><strong>标签名称：</strong></td>
      <td width="84%">
        <input value="<%= LabelName %>" name="LabelName" style="width:200;" />      </td>
    </tr>
    <tr>
      <td align="right"><strong>标签类型：</strong></td>
      <td>
	  
<input  <% IF labeltype = 0 Then Response.Write "Checked" %>  onclick='labeltypeS(this.value);'  type="radio" id="labeltype1"  name="labeltype" value="0">
        <label for="labeltype1">普通标签</label>
        <input  <% IF labeltype = 1 Then Response.Write "Checked" %>  onclick='labeltypeS(this.value);' type="radio" id="labeltype2"  name="labeltype" value="1"> 
      <label for="labeltype2">分页标签</label>
			
	  <table border="0" id="pagearea"
	  <% IF labeltype = 0 Then Response.Write "style=""display:none""" %>
	  >
			 <tr><td>
			 分页项目单位：<input type="text" value="<%= ProjectUnit %>"name="ProjectUnit" size="6"> 
			 如：篇、组、个、部等</td><td width="250"> <%=actcms.ReturnPageStyle(PageStyle) %>	  </td>
			 </tr>
			 </table>
	  
	  
	  </td>
    </tr>
    <tr>
      <td align="right"><strong>查询语句</strong>：</td>
      <td><textarea name="Sql" cols="80" rows="5" id="Sql"><%= Sql %></textarea></td>
    </tr>
    <tr>
      <td align="right"><strong>标签内容</strong>：</td>
      <td>&nbsp;</td>
    </tr>
    <tr>
      <td colspan="2" align="center"><textarea name="LabelContent" cols="95%" rows="20" id="LabelContent"><%=LabelContent%></textarea></td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td><input type=button class="ACT_btn" onclick=CheckInfo()  name=Submit value=" 保 存 " />
	  					<input type="reset" class="ACT_btn" name="Submit2" value="  重置  " /></td>
    </tr>
  </table>
</form>
</body> 

	   <SCRIPT language=javascript>
		  function labeltypeS(num)
		  {
		   if (num==1) 
		   {
			document.all.pagearea.style.display='';
			}
		   else
		   {
			document.all.pagearea.style.display='none';
		   }
		  }
		  		function CheckInfo()
		{
		  if(document.ahhfchhs.LabelName.value=="")
			{
			  alert("标签名称不能为空！");
			  document.ahhfchhs.LabelName.focus();
			  return false;
			}
			if(document.ahhfchhs.LabelContent.value=="")
			{
			  alert("标签内容不能为空！");
			  document.ahhfchhs.LabelContent.focus();
			  return false;
			}
			ahhfchhs.Submit.value="正在提交数据,请稍等...";
		ahhfchhs.Submit.disabled=true;	
		ahhfchhs.Submit2.disabled=true;	
	    ahhfchhs.submit();
        return true;
		}
		</script>
</html>