<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<html>
<head>
<title>地区管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #FFFFFF;
}
-->
</style>
<link href="style/global.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {color: #FF0000}
.style2 {color: #CCCCCC}
.style3 {color: #FFFFFF;
	font-weight: bold;
}
-->
</style>
<script language="javascript">
function check(obj){
	if(obj.Title.value==""){
		alert("地区名称不能为空!");
		obj.Title.focus();
		obj.Title.select();
		return false;
	}
	if(obj.Title.value==""){
		alert("Title不能为空!");
		obj.Title.focus();
		obj.Title.select();
		return false;
	}
	return true;
}
function goto(frm)
{
	var gourl ="?";
	gourl += "page=" + (frm.page.value);
     var hid=parseInt(frm.hid.value);
	 if(parseInt(frm.page.value)>hid||frm.page.value<=0){
	 alert("错误！请确定你输入的数字在1-"+hid+"之间");
	 return false;
	 }
	window.location.href(gourl);
}
function ConfirmDel()
{
   if(confirm("确认删除？并且不能恢复！确定要删除此信息吗？"))
     return true;
   else
     return false;
	 
}
</script>
</head>

<body>
<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
act=trim(request.QueryString("act"))
if isempty(act) or act="" then
	call InnerKeys_List
elseif(act="add") then
	call InnerKeys_Add
elseif(act="addok") then
	call InnerKeys_AddOk
elseif(act="mod") then
	call InnerKeys_Mod
elseif(act="modok") then
	call InnerKeys_ModOk
end if
%>
<%
Sub InnerKeys_Add
	dim pid,ptitle
	pid=Clng(request.QueryString("pid"))
	if(pid=0) then
		ptitle="根目录"
	else
		set rs=server.createobject("adodb.recordset")
		rs.open "select title from t_area where id="&pid,conn,3,1
		if not rs.eof then
			ptitle=rs(0)
		end if
		rs.close
		set rs=nothing
	end if
%>
<FORM method="POST" name="form1" action="?act=addok" style="margin:0 0 0 0;" onSubmit="return check(this)">
  <TABLE width="100%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
<TR bgcolor="#FF9900">
  <TD height="24" colspan="2"><div align="center" class="style3">添加地区</div></TD>
  </TR>
<TR bgcolor="#F5F5F5">
  <TD width="46%"><div align="right">上级：</div></TD>
  <TD width="54%">
  	<select name="pid">
    	<option value="<%=pid%>"><%=ptitle%></option>
    </select>
  </TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD width="46%"><div align="right">名称：</div></TD>
  <TD width="54%"><input name="Title" type="text" id="Title" size="35"></TD>
</TR>
<TR bgcolor="#F5F5F5">
	<TD align=right>&nbsp;	  </TD>
    <TD align=right><div align="left"> 
    	<input type="hidden" name="furl" value="<%=request.ServerVariables("HTTP_REFERER")%>" />
        <input type=submit name=b1 value="提 交">&nbsp;&nbsp;
        <input type=reset name=b2 value="重 填">       
    </div></TD>
</TR>
</TABLE>
</FORM>
<%
end Sub
Sub InnerKeys_AddOk
	dim title,pid,furl
	furl=request.Form("furl")
	if(furl="") then
		furl="area.asp"
	end if
	title=replace(request.Form("Title"),"'","")
	pid=Clng(request.Form("pid"))
	set rs=server.createobject("adodb.recordset")
	rs.open "select top 1 * from t_area where 1=0",conn,3,3
	rs.addnew
		rs("pid")=pid		
		rs("title")=title	
		rs.update	
		response.Write("<p align=""center"">添加地区成功~!")
		response.Write("<br><a href="""&furl&""">返回</a></p>")
	rs.close
	set rs=nothing
end Sub
Sub InnerKeys_ModOk
	dim id,title,url
	id=Clng(request.QueryString("id"))
	pid=clng(request.Form("pid"))
	title=request.Form("title")
	set rs=server.createobject("adodb.recordset")
	rs.open "select top 1 * from t_area where id="&id,conn,3,3
	if not rs.eof then		
		rs("pid")=pid		
		rs("title")=title	
		rs.update	
		response.Write("<p align=""center"">修改地区成功~!")
		response.Write("<br><a href=""javascript:history.go(-2);"">返回</a></p>")
	end if
	rs.close
	set rs=nothing
	'response.Redirect("area.asp")
end Sub
Sub InnerKeys_Mod
	dim id,rs,pid,title
	id=Clng(request.QueryString("id"))
	set rs=conn.execute("select * from t_area where id="&id)
	if not rs.eof then
		pid=rs("pid")
		title=rs("title")
	end if
	rs.close
	set rs=nothing
%>
<FORM method="POST" name="form1" action="?act=modok&id=<%=id%>" style="margin:0 0 0 0;" onSubmit="return check(this)">
  <TABLE width="100%" border="0" align="center" cellpadding="2" cellspacing="1" bgcolor="#666666">
<TR bgcolor="#FF9900">
  <TD height="24" colspan="2"><div align="center" class="style3">添加地区</div></TD>
  </TR>
<TR bgcolor="#F5F5F5">
  <TD width="46%"><div align="right">上级：</div></TD>
  <TD width="54%">
  <input name="pid" type="text" id="pid" size="35" value="<%=pid%>">
  
  </TD>
</TR>
<TR bgcolor="#F5F5F5">
  <TD width="46%"><div align="right">名称：</div></TD>
  <TD width="54%"><input name="Title" type="text" id="Title" size="35" value="<%=title%>"></TD>
</TR>
<TR bgcolor="#F5F5F5">
	<TD align=right>&nbsp;	  </TD>
    <TD align=right><div align="left"> 
        <input type=submit name=b1 value="提 交">&nbsp;&nbsp;
        <input type=reset name=b2 value="重 填">       
    </div></TD>
</TR>
</TABLE>
</FORM>
<%
	
end Sub
Sub InnerKeys_List
	dim BeginTime,i,currentpage,allrec,totalpage,n,p,pid
	pid=request.QueryString("pid")
	if(pid<>"") then
		pid=Clng(pid)
	else
		pid=0
	end if
	BeginTime=Timer
%>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#999999">
  <tr bgcolor="#FF9900">
    <td height="22" colspan="7"><div align="center"><span class="style3">◆ 管理地区 ◆</span></div></td>
  </tr>
  <tr bgcolor="#EEEEEE">
    <td width="53%" height="22"><div align="center">名称</div></td>
    <td width="16%" align="center">ID</td>
    <td width="11%" align="center">添加</td>    
    <td width="8%"><div align="center">修改</div></td>
    <td width="12%"><div align="center">删除</div></td>
  </tr>
  <tr>
    <td colspan="5" bgcolor="#FFFFFF" style="padding-left:10px; line-height:24px;"><a href="?act=add&pid=0"><strong>添加一级地区</strong></a><a href="area_genjs.asp"> 生成JS调用</a></td>
  </tr>
  <%
		dim fcity
		set rs=server.createobject("adodb.recordset")
		rs.open "select id,title from t_area where pid="&pid,conn,3,1
		if not rs.eof then
			fcity=rs.getrows()
		end if
		rs.close
		set rs=nothing
		if isarray(fcity) then
			for i=0 to ubound(fcity,2)
	%>  
  <tr>
    <td style="padding-left:10px; line-height:24px;" bgcolor="#FFFFFF"><h2><a href="?pid=<%=fcity(0,i)%>"><%=fcity(1,i)%></a> &nbsp;</h2></td>
    <td align="center" bgcolor="#FFFFFF"><%=fcity(0,i)%></td>
    <td align="center" bgcolor="#FFFFFF"><a href="?act=add&pid=<%=fcity(0,i)%>"><strong>添加</strong></a></td>    
    <td bgcolor="#FFFFFF"><div align="center"><a href="?act=mod&id=<%=fcity(0,i)%>">修改</a></div></td>
    <td bgcolor="#FFFFFF"><div align="center"><a href="dele.asp?id=<%=fcity(0,i)%>&table=t_area" onClick="return ConfirmDel()">删除</a></div></td>
  </tr>  
  <%
				set rs=server.createobject("adodb.recordset")
				rs.open "select id,title from t_area where pid="&fcity(0,i),conn,3,1
				while not rs.eof
	%>
  <tr>
    <td style="padding-left:20px; line-height:24px;" bgcolor="#FFFFFF">&nbsp;<%=rs(1)%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs(0)%></td>
    <td align="center" bgcolor="#FFFFFF"><a href="?act=add&pid=<%=rs(0)%>"><strong>添加</strong></a></td>    
    <td bgcolor="#FFFFFF"><div align="center"><a href="?act=mod&id=<%=rs(0)%>">修改</a></div></td>
    <td bgcolor="#FFFFFF"><div align="center"><a href="dele.asp?id=<%=rs(0)%>&table=t_area" onClick="return ConfirmDel()">删除</a></div></td>
  </tr>
  <%
					rs.movenext
				wend
				rs.close
				set rs=nothing
			next
    end if
		set fcity=nothing
  %>
</table>
<%end Sub%>
<table width="100%"  border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td height="40"><div align="center"></div></td>
  </tr>
</table>
</body>
</html>
<%
call connclose()
%>