<!--#include file="conn.asp"-->
<%
'检查栏目限制个数
strSQL="Select m_lamucount From member Where id=" & trim(Session("UserID"))
Set rs=Server.CreateObject("ADODB.RecordSet")
rs.open strSQL,conn,1,1
	intMaxLamuCount=rs("m_lamucount")
rs.close

'检查目前栏目个数
strSQL="Select id From menu Where m_id=" & trim(Session("UserID"))
Set rs=Server.CreateObject("ADODB.RecordSet")
rs.open strSQL,conn,1,1
	intCurrLamuCount=rs.recordcount
rs.close

if intCurrLamuCount>=intMaxLamuCount and intMaxLamuCount>0 then
	ShowMsg "对不起，栏目个数过多，添加失败！"
End if

if GetVariable("action")="save" then
	On Error Resume Next
	Set fs = Server.CreateObject( Const_ScriptFileSystem )
	NewFile = "home/" & Trim(Session("UserName")) & "/" & Replace(GetFormVariable("txtHref"),".","") & GetFormVariable("txtHref_Ext")
	NewFile = Server.MapPath( NewFile )
	
	'如果文件名已经存在，不允许创建栏目
	if fs.FileExists(NewFile) then
		ShowMsg "已经存在名为：" & Replace(GetFormVariable("txtHref"),".","") & GetFormVariable("txtHref_Ext") & " 的文件，请改用其它的文件名！"
	end if
	
	strSQL="Insert Into menu(m_id,mn_parent,tm_id,mn_index,mn_name,mn_href,mn_target,mn_class,mn_content,mn_enable) Values("
	strSQL=strSQL & "0" & trim(Session("UserID")) & ","
	strSQL=strSQL & "0" & trim(GetVariable("pid")) & ","
	strSQL=strSQL & "0" & GetFormVariable("selLanmu") & ","
	strSQL=strSQL & "0" & GetFormVariable("txtIndex") & ","
	strSQL=strSQL & "'" & GetFormVariable("txtName") & "',"
	strSQL=strSQL & "'" & GetFormVariable("txtHref") & GetFormVariable("txtHref_Ext") & "',"
	strSQL=strSQL & "'" & GetFormVariable("selTarget") & "',"
	strSQL=strSQL & "'" & GetFormVariable("selClass") & "',"
	
	'从模板中取得内容
	rs.open "Select tm_content From Templet_Menu Where id=" & GetFormVariable("selLanmu"),conn,1,1
	strContent=trim(rs("tm_content")) & ""
	rs.close

	strSQL=strSQL & "'" & replace(strContent,"'","") & "',"
	strSQL=strSQL & "0" & GetFormVariable("chkEnable") & ")"
	conn.execute strSQL,0,1
	
	if trim(GetVariable("pid"))="0" then
		response.redirect("Admin_SetMenu.asp")
	else
		response.redirect("Admin_SubMenu.asp?pid=" & GetVariable("pid") & "&menu=" & GetVariable("menu") )
	end if
	Set fs=nothing
end if
strSQL="Select w_templet From website Where m_id=" & trim(Session("UserID"))
Set rs=Server.CreateObject("ADODB.RecordSet")
rs.open strSQL,conn,1,1
strTemplet=trim(rs("w_templet"))
rs.close

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>电子商务自助建站--您理想的助手</title>
<link href="common/styleMain.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="common/JS_CheckForm.js"></script>
<script language="JavaScript">
//检查数据有效性
function checkform(theform){
	if(!CheckEmpty(theform.selLanmu, "栏目类型")) return false;
	if(!CheckEmpty(theform.txtIndex, "栏目序号")) return false;
	if(!CheckEmpty(theform.txtName, "栏目名称")) return false;

	//不能大于指定长度
	if(!CheckMaxLength(theform.txtName, 50, "栏目名称")) return false;

}

function setAttrib(objItem){
	document.form1.txtName.value=objItem.sText;
	document.form1.txtHref.value=objItem.sHref;
	document.form1.txtHref_Ext.value=objItem.sExt;
	document.all.Href_Ext.innerHTML=objItem.sExt;
	SelectValue(document.form1.selClass,objItem.sClass);
	SelectValue(document.form1.selTarget,objItem.sTarget);
	
}


</script>
</head>
<body leftmargin="0" topmargin="0">
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center"><table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/top.asp"-->
          </td>
        </tr>
        <tr> 
          <td height="100%" align="center" valign="top">
<TABLE class=table002 cellSpacing=0 cellPadding=0 border=0>
              <TBODY>
                <TR> 
                  <!--左边开始-->
                  <TD vAlign=top align=right width="20%">
					  <!--#include file="common/left.asp"-->
				  </TD>
                  <!--左边结束-->
                  <TD width="2%" background="images/rowline.gif">&nbsp;</TD>
                  <!--右边开始-->
                  <TD vAlign=top align=middle width="78%">
				  <form name="form1" method="post" action="?pid=<%=GetVariable("pid")%>&action=save&menu=<%=GetVariable("menu")%>" onSubmit="return checkform(this)">
                      <TABLE width="100%" height="100%" border=0 cellPadding=6 cellSpacing=0>
                        <TBODY>
                          <TR> 
                            <TD vAlign=top align=left bgColor=#ffffff><B>网站栏目属性设置</B><BR> 
                              <HR SIZE=1> 
                              <table width="100%" border="0" cellpadding="1" cellspacing="0" bgcolor="#bad2f0">
                                <tr> 
                                  <td bgcolor="#5f8ac5"><font color="#FFFFFF">□ 
                                    添加栏目</font></td>
                                </tr>
                                <tr>
                                  <td height="40" bgcolor="#FFFFFF">＞<font color="#FF0000">添加栏目</font></td>
                                </tr>
                                <tr> 
                                  <td height="250" align="center" bgcolor="#FFFFFF"> 
                                    <table width="70%" border="0" cellspacing="0" cellpadding="5">
                                      <tr> 
                                        <td align="center"><fieldset>
                                          <legend><strong>新栏目属性</strong></legend>
                                          <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                            <tr> 
                                              <td height="13" colspan="3"></td>
                                            </tr>
                                            <tr> 
                                              <td width="21%" align="right">栏目类型：</td>
                                              <td width="55%">
											  <select name="selLanmu" id="selLanmu" onChange="setAttrib(this[this.selectedIndex])">
												  <option value="" sText='' sHref='' sTagert='' sClass='' sExt=''>-选择类型-</option>
												  <%
												  	strSQL="Select * From templet_menu Where t_code='" & strTemplet & "' And l_code In (" & Session("WebLamu") & ") Order by tm_index"
													rSub.open strSQL,conn,1,1
													for i=1 to rSub.recordcount
														response.write "<option value=" & trim(rSub("id")) & " sText='" & trim(rSub("tm_text")) & "' sHref='" & mid(trim(rSub("tm_href")),1,InStrRev(trim(rSub("tm_href")),".")-1) & "' sExt='" & mid(trim(rSub("tm_href")),InStrRev(trim(rSub("tm_href")),".")) & "' sTagert='" & trim(rSub("tm_target")) & "' sClass='" & trim(rSub("tm_class")) & "'>" & trim(rSub("tm_text")) & "</option>"
														rSub.movenext
													next
													rSub.close
													
												  %>
												  <option value="0" sText='' sHref='http://' sTagert='' sClass='' sExt=''>外部连接</option>
                                                </select>
											</td>
                                              <td width="24%"><input type=submit value=" 添 加 " name=Submit></td>
                                            </tr>
                                            <tr> 
                                              <td align="right">栏目序号：</td>
                                              <td><input name="txtIndex" type="text" id="txtIndex" value="<%=GetVariable("index")%>" size="10" maxlength="10"> 
                                                <font color="#666666">[从0算起，≤16]</font></td>
                                              <td><input type=button value=" 取 消 " name=Submit42 onClick="location='Admin_SetMenu.asp'"> 
                                              </td>
                                            </tr>
                                            <tr> 
                                              <td align="right">栏目名称：</td>
                                              <td><input name="txtName" type="text" id="txtName"></td>
                                              <td>&nbsp;</td>
                                            </tr>
                                            <tr> 
                                              <td align="right">链接文件：</td>
                                              <td colspan="2"><input name="txtHref" type="text" id="txtHref" size="10"><span id="Href_Ext"></span> 
                                                <input name="txtHref_Ext" type="hidden" id="txtHref_Ext">
                                                目标： 
                                                <select name="selTarget" id="selTarget">
                                                  <option value="" selected>默认窗口</option>
                                                  <option value="_blank">新窗口</option>
                                                  <option value="_parent">父窗口</option>
                                                  <option value="_self">当前窗口</option>
                                                </select> </td>
                                            </tr>
                                            <tr> 
                                              <td align="right">CSS 样式：</td>
                                              <td colspan="2"> <select name="selClass" id="selClass" onchange="document.all.aPreview.className=this.value">
                                                  <option selected value="">默认样式</option>
                                                  <option value="aBlack">黑色</option>
                                                  <option value="aBlue">蓝色</option>
                                                  <option value="aBrown">褐色</option>
                                                  <option value="aGreen">绿色</option>
                                                  <option value="aGrey">灰色</option>
                                                  <option value="aMagenta">红紫色</option>
                                                  <option value="aOrange">橙色</option>
                                                  <option value="aPurple">紫色</option>
                                                  <option value="aRed">红色</option>
                                                  <option value="aWhite">白色</option>
                                                  <option value="aYellow">黄色</option>
                                                </select>
                                                　 <a href="javascript:;" id="aPreview">效果预览</a></td>
                                            </tr>
                                            <tr> 
                                              <td align="right">&nbsp;</td>
                                              <td colspan="2">是否启用： 
                                                <input name="chkEnable" type="checkbox" id="chkEnable" value="1" Checked></td>
                                            </tr>
                                            <tr align="right"> 
                                              <td height="33" colspan="3">&nbsp;</td>
                                            </tr>
                                          </table>
                                          </fieldset></td>
                                      </tr>
                                    </table></td>
                                </tr>
                              </table></TD>
                          </TR>
                        </TBODY>
                      </TABLE>
                    </form></TD>
                </TR>
              </TBODY>
            </TABLE></td>
        </tr>
        <tr> 
          <td height="0" align="center">
		  <!--#include file="common/bottom.asp"-->
		  </td>
        </tr>
      </table></td>
  </tr>
</table>
</body>
</html>
