<!--#include file="../common/conn.asp"-->
<%
'检查用户权限
call checkuser(",")
%>
<%
	if GetVariable("action")="save" then
		EditCode=False
		StepLeng=4
		MatchStr=String(StepLeng,"_")
		PostId=GetVariable("id")
		ParentCode=GetFormVariable("txtcode")
		If IsNumeric(PostId) And PostId<>"" And PostId<>"0" Then
			IsChange=True
		Else
			IsChange=False
		End If
		If IsChange Then
			SourCode=conn.execute("select c_code from " & GetVariable("TableName") & " where id="&PostId)(0)
			If Cstr(ParentCode)<>Cstr(conn.execute("select left(c_code,len(c_code)-4) from " & GetVariable("TableName") & " where id="&PostId)(0)) Then EditCode=True
		Else
			EditCode=True
		End If
		If EditCode Then 
			Sql="Select Top 1 c_code from "& GetVariable("TableName") & " where c_code like '"&ParentCode&MatchStr&"' and mn_id="&GetVariable("mnid")&" order by c_code desc"
			'Response.Write sql
			'response.end
			Set rs=conn.execute(sql)
			If rs.eof Then
				TypeCode=ParentCode&String(StepLeng-1,"0")&"1"
			Else
				SelfCode=int(right(rs(0),StepLeng))+1
				SelfCode=right(String(StepLeng-1,"0")&SelfCode,StepLeng)
				TypeCode=ParentCode&SelfCode
			End If
			Set rs=Nothing
		End If
		
		If EditCode and IsChange Then 
			SQL="update "& GetVariable("TableName") & " Set c_code='"&TypeCode&"'+Right(c_code,Len(c_code)-"&Len(SourCode)&") Where c_Code like '"&SourCode&"%'"
			'response.write sql
			'response.flush
			conn.execute(sql)
		End If

		if Not IsChange then
			'添加类别
			strSQL="Insert Into " & GetVariable("TableName") & "(c_name,c_code,c_index,c_parent,mn_id) Values("
			strSQL=strSQL & "'" & GetFormVariable("txtName") & "',"
			strSQL=strSQL & "'" & TypeCode & "',"
			strSQL=strSQL & "" & GetFormVariable("txtIndex") & ","
			strSQL=strSQL & "" & GetVariable("parent") & ","
			strSQL=strSQL & "" & GetVariable("mnid") & ")"
		else
			'保存类别
			strSQL="Update " & GetVariable("TableName") & " Set "
			strSQL=strSQL & "c_name='" & GetFormVariable("txtName") & "',"
			If EditCode then strSQL=strSQL & "c_code='" & TypeCode & "',"
			strSQL=strSQL & "c_index=" & GetFormVariable("txtIndex") & " "
			strSQL=strSQL & " Where id=" & GetVariable("id")
		end if
		conn.execute strSQL,0,1
		'response.Write(strSQL)
		response.Write("<script language='javascript'>window.opener.location=window.opener.location.pathname+'"&"?parent="&GetVariable("parent")&"&TableName="&GetVariable("TableName")&"&mnid="&GetQueryString("mnid")&"';window.close()</script>")
		response.End()

	end if
%>
<%
code=""
if GetVariable("id")="" then
	btValue=" 添 加 "
	strIndex=GetVariable("index")
	strClassName=""
else
	btValue=" 修 改 "
	strSQL="Select * From " & GetVariable("TableName") & " Where id=" & GetVariable("id")
	rs.open strSQL,conn,1,1
	strIndex=trim(rs("c_index"))
	strClassName=trim(rs("c_name"))
	Code=trim(rs("c_code"))
end if
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>编辑类别属性</title>
<STYLE type="text/css">
td			{font-size:9pt;line-height:140%}
A:active	{COLOR: #FFFFFF;}
A:visited	{COLOR: #333333; TEXT-DECORATION: none}
A:hover		{COLOR: #000033;TEXT-DECORATION: none}
A:link		{COLOR: #333333; TEXT-DECORATION: none}
</STYLE>
<script language="JavaScript">
function checkform(theform){
	if(theform.txtName.value==""){
		alert("请填写类别名称！　")
		return false;
	}
	
	if(theform.txtIndex.value==""){
		alert("请填写类别序号！　")
		return false;
	}
}
</script>
</head>
<body leftmargin="0" topmargin="0" BodyBegin>
<form name="form1" method="post" action="?parent=<%=GetVariable("parent")%>&action=save&id=<%=GetVariable("id")%>&TableName=<%=GetVariable("TableName")%>&mnid=<%=GetQueryString("mnid")%>" onSubmit="return checkform(this)">
  <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#336600">
    <tr> 
      <td width="100%" bgcolor="#669900"><strong><font color="#FFFFFF">编辑类别属性</font></strong></td>
    </tr>
    <tr align="center" bgcolor="#F9F9F9"> 
      <td>
<table width="80%" border="0">
          <tr>
            <td height="30" align="right">所属分类：</td>
            <td height="30"><select name=txtcode id="txtcode">
                <option value="">根栏目</option>
                <%Sql="select id,c_name,c_code from " & GetVariable("TableName") & " where mn_id="&GetVariable("mnid")&" order by c_code"
        set rs=conn.execute(sql)
        Do While Not rs.eof
		if not (left(trim(rs(2)),len(trim(code)))=trim(code) and Code<>"") then
			Level=(Len(rs(2))/4-1)*3
			Response.Write "<option value="""&rs(2)&""""
			If Code<>"" Then 
				If Left(Code,Len(Code)-4)=rs(2) Then Response.Write " selected"
			End If
			Response.Write ">"
			If Len(rs(2))>4 Then Response.Write "├"
			Response.Write String(Level,"-")
			Response.Write rs(1)&"</option>"
		end if
			rs.movenext
		Loop
		rs.close%>
              </select></td>
          </tr>
          <tr> 
            <td height="30" align="right">类别名称：</td>
            <td height="30"> <input name="txtName" type="text" id="txtName" value="<%=strClassName%>" size="15" maxlength="30"></td>
          </tr>
          <tr style="display:none"> 
            <td height="30" align="right">序　号：</td>
            <td height="30"> <input name="txtIndex" type="text" id="txtIndex" value="<%=strIndex%>" size="5" maxlength="2"> 
              <font color="#FF0000">[从0算起]</font></td>
          </tr>
          <tr align="center"> 
            <td height="40" colspan="2"> <input type="submit" name="Submit" value="<%=btValue%>"> 
              <input type="button" name="Submit2" value=" 取 消 " onClick="window.close()"> 
            </td>
          </tr>
        </table> </td>
    </tr>
    <tr> 
      <td bgcolor="#669900">&nbsp;</td>
    </tr>
  </table>
  <iframe name="BackFrame" width="0" height="0" src="about:blank"></iframe>
</form>
</body>
</html>
