<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<!--#include file="inc/function.asp" -->
<HTML>
<HEAD>
<TITLE>标签修改</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb2312">
<style>
body,td,input,textarea {font-size:9pt}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
</style>
<link href="style/global.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="/js/jquery-1.5.1.min.js"></script>
<script type="text/javascript">
function getField(tbl,fid){
	var htm='';
	if(tbl==1){
		var h=$('#fields_article').html();
		$('#fields').html(h);
	}else if(tbl==2){
		var h=$('#fields_download').html();
		$('#fields').html(h);
	}else{
		$.ajax({ 
				url:'module_getfieds.asp?id='+tbl,      //异步方法
				type: 'get', 
				dataType: 'xml', 
				timeout: 1000,                            //延迟1秒执行
				error: function(){                        //返回失败后
					alert('Error loading XML document'); 
				}, 
				success: function(xml){              //返回成功
				 var tb=$(xml).find("table").text();
				 $(xml).find("field").each(function(){         //找到根节点
						 var id=$(this).children("id").text();
						 var n=$(this).children("FName").text();
						 var t=$(this).children("FTitle").text();
						 htm=htm+'<a href="javascript:ss(\''+tb+'\',\''+n+'\')">'+t+'</a> ';					 
				 });
				 $('#fields').html('字段：'+htm);
			 } 
			});
	}
}
function ss(t,n){
	var v=$('#fields')[0].value;
	if(v==undefined) v='';
	v=v+','+n;
	$('#fields')[0].value=v;
	$('#content')[0].value='select '+v.substring(1)+' from '+t+'';
}

function ch(v){
	var pattern = /^[a-zA-Z0-9_\$]+$/; 
	var r=pattern.test(v.value);
	if(!r){
		alert('只能填写英文、数字和下划线');
		v.focus();
	}
}
</script>
</HEAD>
<BODY>
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p04")
'''''''''''''''''''''''''''''''''''''''''''''''
'获得大类
dim first,id,classid,labelArr
dim i
'获得参数
%>
<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>
<%
dim act,TempName,TempContent,newsclass,demons,catalogName
act=request.QueryString("act")
if(act="modi") then
	id=Cint(request("id"))
	newsclass=Cint(request.Form("newsclass"))
	TempName=trim(request.Form("tempname"))
	if(len(TempName)<1) then
		response.Write("<script>alert(""标签名称不能为空!"");history.back();</script>")
		response.End()
	end if
	demons=request.Form("demons")
	TempContent =Request.Form("content")
	if(len(TempContent)<1) then
		response.Write("<script>alert(""标签内容不能为空!"");history.back();</script>")
		response.End()
	end if
	call Modilabel()
	response.Write("成功修改标签~!")
	response.Write("<br><input type=button value='继续修改' onclick='history.go(-2)'> &nbsp;")
else
	id=cint(request("id"))	
	set rs=server.CreateObject("adodb.recordset")
	sql="select labelname,content,demons,classid,ftype from label where id="&id
	rs.open sql,conn,3,1
	if not rs.eof then
		labelArr=rs.GetRows()
		rs.close
		set rs=nothing
	else
		response.Write("没有记录")
		rs.close
		set rs=nothing
		response.End()
	end if	
%>
<FORM method="POST" name="form1" action="label_modi.asp?act=modi" style="margin:0 0 0 0; " onSubmit="document.form1.content.value=doc_html.Composition.document.body.innerHTML">
  <TABLE width="100%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
<TR bgcolor="#F5F5F5">
  <TD><div align="center">所 属 类 别：</div></TD>
  <TD><select name="newsclass" >
  <%
  	if(labelArr(3,0)=0) then
  		response.Write("<option value=""0"">所有</option>")
	else
		catalogName=getCatalogName(labelArr(3,0))
		response.Write("<option value="&labelArr(3,0)&">"&catalogName&"</option>"&Chr(10))
	end if
  %>    
    </select>
	&nbsp;&nbsp;<a href="#" onClick="addParentOption();">＋</a>
	</TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">标 签 标 题：</div></TD>
  <TD><input name="tempname" type="text" size="60" value="<%=labelArr(0,0)%>" onBlur="ch(this)"></TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD><div align="center">标 签 作 用：</div></TD>
  <TD><textarea name="demons" cols="40" rows="3" id="demons"><%=labelArr(2,0)%></textarea></TD>
</TR>
<TR bgcolor="#F5F5F5">
	<TD><div align="center">标 签 内 容：</div></TD>
	<TD>		
  	<%
		if(labelArr(4,0)=0) then
		%>
		<textarea name="content" id="content" cols="80" rows="20" style="display:none; "><%=labelArr(1,0)%></textarea>		
		<textarea name="tempcontent" style="display:none; "><%=labelArr(1,0)%></textarea>		
		<iframe src="editor/editor.htm" id="doc_html" name="doc_html" width="100%" height="325"></iframe>
    <%
		else
		%>
    模型：
    <select name="moduleid" id="moduleid" onChange="getField(this.options[this.selectedIndex].value,'')">
    	<option value="0">选择</option>
			<%
			set rs=server.createobject("adodb.recordset")
			rs.open "select id,Title from t_module",conn,3,1
			while not rs.eof
				response.Write("<option value="""&rs(0)&""">"&rs(1)&"</option>")
				rs.movenext
			wend
			rs.close
			set rs=nothing
			%>
    </select>
    <div id="fields"></div>
    <br />
    在此输入查询的Sql语句：<br>
    <textarea rows="12" name="content" id="content" cols="70"><%=labelArr(1,0)%></textarea><input type="button" value="测试Sql" onClick="popupWindow('sql_test.asp?sql='+escape(document.form1.content.value),'sql_test',true)" />
    <%
		end if
		%>
	  </TD>
</TR>
<TR bgcolor="#F5F5F5">
	<TD align=right>&nbsp;	  </TD>
    <TD align=right><div align="left">
				<input name="fields" type="hidden" id="fields" value=" ">
        <input type="hidden" name="id" value="<%=id%>">
        <input type=submit name=b1 value="提交">
        <input type=reset name=b2 value="重填">
    </div></TD>
</TR>
</TABLE>
</FORM>
<%
end if
sub Modilabel
	set rs=server.createobject("adodb.recordset")
	rs.open "select * from label where labelname='"&TempName&"' and id<>"&id,conn,3,1
	if not rs.eof then
		response.Write("<script>alert(""该标签已存在!"");history.back();</script>")
		response.End()
	end if
	rs.close
	sql="select * from label where id="&id
	rs.open sql,conn,3,3	
	rs("classid")=newsclass
	rs("labelname")=TempName
	rs("demons")=demons
	rs("content")=TempContent
	rs("moditime")=now
	rs.update
	rs.close
	set rs=nothing
end sub
function GetFields(t)
	dim rs,ret
	set rs=server.createobject("adodb.recordset")
	rs.open "select top 1 * from "&t,conn,3,1
	for i=0 to rs.fields.count-1		
		ret=ret&"<a href=""javascript:ss('"&t&"','"&rs(i).name&"')"">"&rs(i).name&"</a> "&chr(13)
	next
	rs.close
	set rs=nothing
	GetFields=ret
end function
%>
<div id="fields_article" style="display:none;">
	<%=GetFields("news")%>
</div>

<div id="fields_download" style="display:none;">
	<%=GetFields("t_download_soft")%>
</div>
<script language="JavaScript">
function addParentOption()
{
	var arr = showModalDialog("tree_container.asp", "", "dialogWidth:410px; dialogHeight:420px; status:0");
  	if (arr != null){  
   		document.form1.newsclass.options[0]=new Option(arr[1],arr[0]);
  	}
	
}
function popupWindow(mypage, myname, w, h, scroll) {
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable'
	win = window.open(mypage, myname, winprops)
	if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
}
</script>
</BODY>
</HTML>
<%
call connclose()
%>