<!--#include file="../inc/config.asp" -->
<!--#include file="../inc/conn.asp" -->
<!--#include file="inc/function.asp" -->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p18")
'''''''''''''''''''''''''''''''''''''''''''''''
dim id,act,formArr
act=request.querystring("act")
if(request.querystring("id")<>"") then
	id=Clng(request.querystring("id"))
else
	id=0
end if
if(id>0) then
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select itemnames,itemvalues,itemtypes,itemrequired,itemids,formname,formtitle,formdesc,thankmsg,error_textfields,error_buttons,formemail,itemtitles  from t_form where id="&id,conn,3,1
	if not rs.eof then
		formArr=rs.GetRows()
	else
		call alertstr("没有找到记录",1)
	end if
end if
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>自定义表单</title>
<style type="text/css">
<!--
.style1 {	color: #FFFFFF;
	font-weight: bold;
}
form{margin:0px;}
.tdleftpad{padding-left:30px;}
-->
</style>
<SCRIPT src="js/form.js"></SCRIPT>
</head>
<link href="style/global.css" rel="stylesheet">
<script>
var selectedelementNames = new Array(<%if(id>0) then response.write(formArr(0,0)) end if%>);
var selectedElementValues = new Array(<%if(id>0) then response.write(formArr(1,0)) end if%>);
var selectedElementTypes = new Array(<%if(id>0) then response.write(formArr(2,0)) end if%>);
var selectedElementRequired = new Array(<%if(id>0) then response.write(formArr(3,0)) end if%>);
var selectedelementIDs = new Array(<%if(id>0) then response.write(formArr(4,0)) end if%>);
var selectedElementTitles = new Array(<%if(id>0) then response.write(formArr(12,0)) end if%>);
</script>
<%
if(act="do") then
	dim itemnames,itemvalues,itemtypes,itemrequired,itemids,formname,formtitle,formdesc,thankmsg,error_textfields,error_buttons,formemail,itemtitles
	dim tempStr,tempArr,i
	tempStr=request.form("selectedElementTitles")
	tempArr=split(tempStr,"|*|")
	for i=0 to ubound(tempArr)
		itemtitles=itemtitles&"'"&tempArr(i)&"'"
		if(i<ubound(tempArr)) then
			itemtitles=itemtitles&","
		end if
	next
	tempStr=request.form("selectedelementNames")
	tempArr=split(tempStr,"|*|")
	for i=0 to ubound(tempArr)
		itemnames=itemnames&"'"&tempArr(i)&"'"
		if(i<ubound(tempArr)) then
			itemnames=itemnames&","
		end if
	next
	tempStr=request.form("selectedElementValues")
	tempArr=split(tempStr,"|*|")
	for i=0 to ubound(tempArr)
		itemvalues=itemvalues&"'"&tempArr(i)&"'"
		if(i<ubound(tempArr)) then
			itemvalues=itemvalues&","
		end if
	next
	tempStr=request.form("selectedElementTypes")
	tempArr=split(tempStr,"|*|")
	for i=0 to ubound(tempArr)
		itemtypes=itemtypes&"'"&tempArr(i)&"'"
		if(i<ubound(tempArr)) then
			itemtypes=itemtypes&","
		end if
	next
	tempStr=request.form("selectedElementRequired")
	tempArr=split(tempStr,"|*|")
	for i=0 to ubound(tempArr)
		itemrequired=itemrequired&"'"&tempArr(i)&"'"
		if(i<ubound(tempArr)) then
			itemrequired=itemrequired&","
		end if
	next
	tempStr=request.form("selectedelementIDs")
	tempArr=split(tempStr,"|*|")
	for i=0 to ubound(tempArr)
		itemids=itemids&"'"&tempArr(i)&"'"
		if(i<ubound(tempArr)) then
			itemids=itemids&","
		end if
	next
	formname=request.form("formName")
	formtitle=request.form("pageTitle")
	formdesc=request.form("formDescription")
	thankmsg=request.form("formThankYou")
	error_textfields=request.form("formErrorText")
	error_buttons=request.form("formErrorOther")
	formemail=request.form("formEmail")
	set rs=server.CreateObject("adodb.recordset")
	rs.open "select * from t_form where id="&id,conn,3,3
	if(id=0) then
		rs.addnew
	end if
	rs("itemnames")=itemnames
	rs("itemvalues")=itemvalues
	rs("itemtypes")=itemtypes
	rs("itemrequired")=itemrequired
	rs("itemids")=itemids
	rs("formname")=formname
	rs("formtitle")=formtitle
	rs("formdesc")=formdesc
	rs("thankmsg")=thankmsg
	rs("error_textfields")=error_textfields
	rs("error_buttons")=error_buttons
	rs("formemail")=formemail
	rs("itemtitles")=itemtitles
	rs("moditime")=now()
	rs.update
	rs.close
	set rs=nothing
	if(id=0) then
		response.write("<br><br><p align=""center"">成功添加自定义表单!<br><a href=""forms.asp"">继续添加</a><br><br><a href=""forms_manage.asp"">管理</a>")
		response.write("<br><br><a href=""javascript:history.back()"">退回</a></p>")
	else
		response.write("<br><br><p align=""center"">成功修改自定义表单!<br><br><a href=""javascript:history.go(-2)"">继续修改</a><br><br><a href=""forms.asp"">添加新表单</a>")
		response.write("<br><br><a href=""javascript:history.back()"">退回</a></p>")
	end if
else
%>
<body onLoad="editSetup()">
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><iframe src="right_top.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" height="30" width="100%"></iframe></td>
  </tr>
</table>
<table width="100%" height="22"  border="0" cellpadding="0" cellspacing="0" bgcolor="#FF9900" style="border-left:1px solid #000000;border-right:1px solid #000000;border-top:1px solid #000000;">
  <tr>
    <td><div align="center" class="style1">自定义表单</div></td>
  </tr>
</table>
<div align="center" style="border:1px solid #eeeeee;">
  
    <table width="100%" border="0" cellpadding="2" cellspacing="2">
      <tr>
        <td width="63%" valign="top">
		<form action="?act=do&id=<%=id%>" method="post" name="fForm" id="fForm" onSubmit="return checkSubmit()" >
		<fieldset style="OVERFLOW:auto;">
		<legend>添加表单元素</legend>
		<table width="100%" border="0">
          <tr>
            <td><div align="center">
              <p>
                <INPUT style="FONT-SIZE: 12px; WIDTH: 100px" disabled onclick=removeItem() type=button value="删除元素" name=btnRemove>
              </p>
              <p>
                <INPUT style="FONT-SIZE: 12px; WIDTH: 100px" disabled onclick=moveOptionUp() type=button value="向上移动" name=btnUp>
              </p>
              <p>
              <INPUT style="FONT-SIZE: 12px; WIDTH: 100px" disabled onclick=moveOptionDown() type=button value="向下移动" name=btnDown>
</p>
            </div></td>
            <td><div align="center">
              <SELECT style="WIDTH: 130px; HEIGHT: 170px" onchange=elemSelected() size=15 name=fElems>
              </SELECT>
              </div></td>
            <td valign="top"><div align="right"><A 
                  href="javascript:addNewItem()">·增加新元素</A><br>
            </div>
              <TABLE align="center">
                  <TR>
                    <TD>字段类型</TD>
                    <TD><SELECT disabled onchange=updateDesc() name=fldType>
                      <OPTION value="" selected>选择...</OPTION>
                        <OPTION value=1>单行文本域</OPTION>
                        <OPTION value=2>多行多列文本域</OPTION>
                        <OPTION value=3>邮箱文本域</OPTION>
                        <OPTION value=4>数字文本域</OPTION>
                        <OPTION value=5>单选按钮</OPTION>
                        <OPTION value=6>复选按钮</OPTION>
                        <OPTION value=7>列表框</OPTION>
                        <OPTION value=8>日期段</OPTION>
                        <OPTION value=9>时间段</OPTION>
                        <OPTION value=10>取消按钮</OPTION>
                        <OPTION value=11>提交按钮</OPTION>
                    </SELECT></TD>
                  </TR>
				  <TR>
                    <TD>字段标题</TD>
                    <TD><INPUT disabled name=fldTitle></TD>
                  </TR>
                  <TR>
                    <TD>字段名称</TD>
                    <TD><INPUT disabled name=fldName></TD>
                  </TR>
                  <TR>
                    <TD>字段值</TD>
                    <TD><INPUT disabled name=fldValue></TD>
                  </TR>
                  <TR>
                    <TD>是否必填</TD>
                    <TD><INPUT disabled type=checkbox value=true name=fldReq></TD>
                  </TR>
                  <TR>
                    <TD align=right colSpan=2><INPUT disabled onclick=addElem() type=button value="&lt;&lt;-增加" name=btnAdd>
                  <TR>
                      <TD colSpan=2 align=left bgcolor="#F7F7F7">
                    <DIV id=elemDesc></DIV></TD>
                  </TR>
              </TABLE></td>
          </tr>
        </table>
		</fieldset><br>
		<fieldset>
		<legend>表单设置</legend>
		<TABLE width="100%">
            <TR>
              <TD width="48%" class="tdleftpad"><div align="left">表单名称:</div></TD>
              <TD width="52%"><INPUT name=formName value="<%if(id>0) then response.write(formArr(5,0)) end if%>" maxLength=50></TD>
            </TR>
            <TR>
              <TD vAlign=top class="tdleftpad"><div align="left">表单标题:</div></TD>
              <TD><INPUT name=pageTitle value="<%if(id>0) then response.write(formArr(6,0)) end if%>" maxLength=255></TD>
            </TR>
            <TR>
              <TD vAlign=top class="tdleftpad"><div align="left">表单描述:<BR>
                  <SPAN class=bodyTextSmall>(在表单上部显示).</SPAN></div></TD>
              <TD><TEXTAREA onblur=updatePreview() name=formDescription><%if(id>0) then response.write(formArr(7,0)) end if%></TEXTAREA></TD>
            </TR>
            <TR>
              <TD vAlign=top class="tdleftpad"><div align="left">欢迎信息:<BR>
                  <SPAN class=bodyTextSmall>(表单提交时显示)</SPAN></div></TD>
              <TD><TEXTAREA name=formThankYou><%if(id>0) then response.write(formArr(8,0)) else response.write("感谢您的参与!") end if%></TEXTAREA></TD>
            </TR>
            <TR>
              <TD vAlign=top class="tdleftpad"><div align="left">文本域出错提示信息:</div></TD>
              <TD><INPUT maxLength=100 value="<%if(id>0) then response.write(formArr(9,0)) else response.write("请输入信息(TAGNAME)") end if%>" name=formErrorText></TD>
            </TR>
            <TR>
              <TD vAlign=top class="tdleftpad"><div align="left">列表框、单选按钮出错提示信息:</div></TD>
              <TD><INPUT value="<%if(id>0) then response.write(formArr(10,0)) else response.write("请选择(TAGNAME)") end if%>" name=formErrorOther></TD>
            </TR>
            <TR>
              <TD class="tdleftpad"><div align="left">表单动作:</div></TD>
              <TD><INPUT name=formEmail value="<%if(id>0) then response.write(formArr(11,0)) end if%>" maxLength=128></TD>
            </TR>
            <TR>
              <TD colspan="2">
			  <div align="right">
			  	<INPUT type=hidden name=selectedElementTitles>
                <INPUT type=hidden name=selectedelementNames>
                <INPUT type=hidden name=selectedElementValues>
                <INPUT type=hidden name=selectedElementTypes>
                <INPUT type=hidden name=selectedElementRequired>
                <INPUT type=hidden name=selectedelementIDs>
                <INPUT type=hidden name=deletedFormElements>
                <INPUT type=hidden value=true name=submitted>
                <INPUT type=reset value="取 消" name=Cancel>
                <INPUT type=submit value="确 定" name=Submit>
              </div></TD>
            </TR>
          </TABLE>
		</fieldset>
		</form>
		</td>
        <td width="37%" valign="top">
		<fieldset style="OVERFLOW: auto; HEIGHT: 329px">
		<legend>预览</legend>          
        <Form><DIV id=fPrev></DIV></Form>
		</fieldset>
		</td>
      </tr>
    </table>
</div>
<%end if%>
</body>
</html>
<%
call connclose()
%>