<!--#include file="../include/Conn.jsp"-->
<!--#include file="../Include/Char.jsp" -->
<!--#include file="../Include/md5.jsp" -->
<!--#include file="Admin_IsLogin.jsp" -->
<%
'Define Variable 
dim i
dim rs,rst
dim mTypeName,mGrade,mSql,mFlag,mBgColor
Set rs=Server.CreateObject("Adodb.RecordSet")

'initialization 
mFlag=true'add


'Sort Grade Up
If Request.QueryString("action")="up" then
   mSql="update citycard_template set F_index=F_index+1 where F_ID="&Request.QueryString("SortID")
   conn.execute(mSql)
   mBgColor=Request.QueryString("SortID")
   Response.Redirect "admin_template.jsp?pageno="&Request("pageno")&"&BgColor="&mBgColor
 End if

'Sort Grade Down
If Request.QueryString("action")="down" then
   mSql="update citycard_template set F_index=F_index-1 where F_ID="&Request.QueryString("SortID")
   conn.execute(mSql)
   mBgColor=Request.QueryString("SortID")
   Response.Redirect "admin_template.jsp?pageno="&Request("pageno")&"&BgColor="&mBgColor
 End if


'edit
if request("action")="edit" then 
  mSql="Select * From citycard_template Where F_ID="&Request.QueryString("ModifyID")
  Set rs=Conn.Execute(mSql)
  If not rs.Eof then
    mname=rs("F_name")
    mpath=rs("F_path")
	mpic=rs("f_pic")
'	tem_id=rs("f_id")
  rs.Close
  End if
  mFlag=false
end if

'Insert Records
if request("action")="Insert" then
  mSql="Select * From citycard_template where f_id="&Trim(Request.Form("maxid"))
  rs.open mSql,conn,1,3
  if not rs.eof then
     Response.Write "<script>alert('对不起，该模板ID已存在，请更换后再试！');history.back();</Script>"
	 Response.End()
  else
  rs.AddNew
  rs("F_name")=Trim(Request.Form("name"))
  rs("F_id")=Trim(Request.Form("maxid"))
  rs("F_pic")=Trim(Request.Form("txtImage"))
  rs("F_path")=Trim(Request.Form("path"))
  rs("F_regtime")=now()
  rs("F_index")=0
  rs.update
  '创建目录
  Set fso = CreateObject("Scripting.FileSystemObject")
   folder_Path = Server.MapPath("../jubao/Template")
    m_PathDir = folder_Path & "\" & Trim(Request.Form("maxid"))
   If Not fso.FolderExists(m_PathDir) Then
	  Set f = fso.CreateFolder(m_PathDir)
	  Set f=nothing
	end if

  end if
  rs.close
  
  response.redirect "admin_template.jsp?action=IsInsert&pageno="&Request("pageno")
end if

'Modify Records
if request("action")="editsave" then
  mSql="Select * From citycard_template Where F_ID="&Request.QueryString("ModifyID")
  rs.open mSql,conn,1,3
  rs("F_name")=Trim(Request.Form("name"))
  rs("F_path")=Trim(Request.Form("path"))
  rs("F_pic")=Trim(Request.Form("txtImage"))
  rs.update
    Response.write "<script>alert('修改成功！');location.replace('admin_template.jsp?action=IsModify&pageno="&Request.Querystring("pageno")&"')</script>"
  flag=false
end if

'Delect Records 删除
if request("action")="delete" then
  msql="select * from citycard_template WHERE F_ID=" &Request.QueryString("DeleteID")
  rs.open mSql,conn,1,3
  if not rs.eof then
  ' m_shop_id=rs("f_id")
            if rs("f_pic") <>"" then
	          delfname=server.mappath("..\jubao\Templateupload") & "\"&rs("f_pic")  '删除文件
              set TestFileObject=Server.Createobject("Scripting.FileSystemObject")
              if  TestFileObject.FileExists(delfname) then
               set NewFile=TestFileObject.getfile(delfname)
               Newfile.delete
	          end if
			end if
    '删除文件夹
	   set fso = CreateObject("Scripting.FileSystemObject")
       folder_Path = Server.MapPath("../jubao/Template")
       m_PathDir = folder_Path & "\" & rs("f_id")
       If fso.FolderExists(m_PathDir)=true Then
	   On Error Resume Next
	    Set fc = fso.DeleteFolder(m_PathDir)
	    Set fc=nothing
	    end if
  rs.delete
  rs.update
  end if
  
  Response.write "<script>location.replace('admin_template.jsp?action=IsDelete&pageno="&Request.Querystring("pageno")&"')</script>"
end if


%>

<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="Images/Style.css" rel="stylesheet" type="text/css">
<SCRIPT language="JavaScript">
function jDelete(url)
{
  if((confirm(" 警告:请确定是否删除,删除后不能恢复! "))==true) 
	self.location=url+'&action=delete';
}
</SCRIPT>
<script language="javascript">
function CheckData(){
  if (document.form1.shop_name.value=="")
   {
    alert("商城名称不能为空，请输入！");
	document.form1.shop_name.focus();
	return false;
   }
  if (document.form1.shop_username.value=="")
   {
    alert("用户名不能为空，请输入！");
	document.form1.shop_username.focus();
	return false;
   }
     if (document.form1.shop_password.value=="")
   {
    alert("密码不能为空，请输入！");
	document.form1.shop_password.focus();
	return false;
   }

}
</script>
</head>
<body text="#000000" >

<%
	admin_flag=",0|14|0,"
	if instr(session("flag"),admin_flag)=0 or isnull(session("flag"))=true then
	Response.write "<br><br><br><br><b><font color=red>对不起，您没有管理本页面的权限!</font></B>"
	Response.end
	end if
%>
<br>
<table class=tableBorder width="95%" border="0" align="center" cellpadding="2" cellspacing="1">
  <tr > 
    <th height="22" colspan="6"> 模板列表</span></th>
  </tr>
  <tr > 
    <td width="4%" align="center" class=forumHeaderBackgroundAlternate><b>ID</b></td>
    <td class=forumHeaderBackgroundAlternate width="19%"><b>模板名称</b></td>
    <td width="8%" align="center" class=forumHeaderBackgroundAlternate><strong>排序</strong></td>
    <td width="34%" class=forumHeaderBackgroundAlternate><b>模板路径</b></td>
    <td width="14%" align="center" class=forumHeaderBackgroundAlternate><b>发布时间</b></td>
    <td width="21%" align="center" class=forumHeaderBackgroundAlternate><b>管理</b></td>
  </tr>
  <%  
	Set rs=Server.createobject("Adodb.RecordSet")
    pageno=request("pageno")
    pmcount=16  

	
    mSql="select * from citycard_template where f_path<>''"
	msql=msql&" order by f_id desc"
	
	
	rs.open mSql,conn,1,1
	if rs.eof then
	   'response.write "<br><p  align='center'><font color=red><B> 对不起，数据已清空！</B></font></p>"
    else
    rs.pagesize=pmcount
    mpage=rs.pagecount
    if pageno="" then pageno=1
    if  cint(pageno)<1 or cint(pageno)>mpage then  pageno=1
    rs.absolutepage=pageno

 Dim rc,re
 rc=rs.pagesize
 re=1
 do while not rs.eof and rc>0
 mBgColor=Request.Querystring("BgColor")
 if Trim(rs("F_ID"))=Trim(mBgColor) then mColor= "D6DFFF" else mColor= "ffffff"
%>
  <tr  > 
    <td  class=forumRow width="4%" align="center"><%=rs("F_ID")%></td>
    <td width="19%" class=forumRow ><%=rs("F_name")%> </td>
    <td width="8%" align="center" class=forumRow ><%=rs("F_index")%> [<a href="admin_template.jsp?pageno=<%=Request("pageno")%>&action=up&SortID=<%=rs("F_ID")%>">+</a>][<a href="admin_template.jsp?pageno=<%=Request("pageno")%>&action=down&SortID=<%=rs("F_ID")%>">-</a>]</td>
    <td class=forumRow > <%=rs("F_path")%></td>
    <td align="center" class=forumRow > <%=rs("F_regtime")%></td>
    <td class=forumRow width="21%" align="center" ><a title="添加记录" href='admin_template.jsp?pageno=<%=mPage%>'><font color="#666666">[添加]</font></a><a title="修改记录" href='admin_template.jsp?action=edit&ModifyID=<%=rs("F_ID")%>&BgColor=<%=rs("F_ID")%>&pageno=<%=cstr(pageno)%>'><font color="#666666">[修改]</font></a><a title="请确定是否删除,删除后不能恢复!" href="javascript:jDelete('admin_template.jsp?DeleteID=<%=rs("F_ID")%>&pageno=<%=cstr(pageno)%>')"><font color="#666666">[删除]</font></a></td>
  </tr>
  <%
 rs.movenext
 re=re+1
 rc=rc-1
 loop
 end if
%>
  <tr  > 
    <td class=forumRow align="center" colspan="8"><table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr> 
          <td width="38%" height="22"> &nbsp;共 <font color=red><strong> 
            <% = rs.recordcount%>
            </strong></font> 条记录 当前第 <font color=red><strong> 
            <% = Trim(pageno)%>
            </strong></font>页/共 <font color=red><strong> 
            <% = Trim(mpage)%>
            </strong></font>页 </td>
          <td width="62%" align="right"> <%
if pageno>1 then
   response.write "<a href='admin_template.jsp?txtclass="&m_txtclass&"&txtword="&m_txtword&"'> <img alt='首页' src='Images/boqb02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='首页' src='Images/boqb02.gif' border=0 width='15' height='14'>"
end if

if pageno>1 then
   response.write "<a href='admin_template.jsp?txtclass="&m_txtclass&"&txtword="&m_txtword&"&pageno="&pageno-1&"'><img alt='上一页' src='Images/bob02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='上一页' src='Images/bob02.gif' border=0 width='15' height='14'>"
end if

add=5'数字分页个数+1
if pageno-int(add/2)<=1 then m=1 else m=pageno-int(add/2)
if m+add>mpage then 
   n=mpage
   if mpage-add<=1 then m=1 else m=mpage-add
else
   n=m+add
end if

for pno=m to n
 if pno=cint(pageno) then
   response.write "&nbsp;<font color=red>"&pno&"</font>"
 else
   response.write "<b>&nbsp;<a href='admin_template.jsp?txtclass="&m_txtclass&"&txtword="&m_txtword&"&pageno="&pno&"'>"&pno&"</a></b>"
 end if
next
response.write "&nbsp"

if int(pageno) < int(rs.pagecount) then
  response.write "<a href='admin_template.jsp?txtclass="&m_txtclass&"&txtword="&m_txtword&"&pageno="&pageno+1&"'><img alt='下一页' src='Images/fbob02.gif' border=0 width='15' height='14'></a>"
else 
  response.write "<img alt='下一页' src='Images/fbob02.gif' border=0 width='15' height='14'>"
end if

if int(pageno) < int(rs.pagecount) then
   response.write "<a href='admin_template.jsp?txtclass="&m_txtclass&"&txtword="&m_txtword&"&pageno="&mpage&"'><img alt='末页' src='Images/fboqb02.gif' border=0 width='15' height='14'></a>"
else
   response.write "<img alt='末页' src='Images/fboqb02.gif' border=0 width='15' height='14'>"
end if
Response.write "&nbsp;&nbsp;"
%> </td>
        </tr>
      </table></td>
  </tr>
</table> 
        <%if mFlag=true then'add%>
            <form name="form1" method="post" action="admin_template.jsp?pageno=<%=mpage%>&action=Insert">
  <table class=tableBorder width="95%" border="0" align="center" cellpadding="2" cellspacing="1">
    <tr > 
      <th height="22" colspan="2">功能：新增商城</th>
    </tr>
    <tr> 
      <td class=forumRowHighlight width="12%" height="19">模板名称：</td>
      <td class=forumRow width="88%"><input name="name" type="text"  class='text' id="name" value="" size="22" maxlength="80"></td>
    </tr>
    <tr> 
      <td class=forumRowHighlight>模板路径： </td>
      <td class=forumRow>
	  <%
	  m_maxid=0
	   mSql="select max(f_id) from citycard_template"
	   Set rst=Conn.Execute(mSql)
	   if rst.eof and rst.bof  then
	   m_maxid=1
	   else
	   m_maxid=rst(0)+1
	   end if
	   rst.close
	   set rst=nothing
	  %>
	  <input name="path" type="text" readonly class='text' id="path" value="jubao/Template/<%=m_maxid%>" size="22" maxlength="80">
        <input name="maxid" type="hidden" value="<%=m_maxid%>"> </td>
    </tr>
    <tr> 
      <td valign="middle" class=forumRowHighlight>上传缩略图：</td>
      <td class=forumRow><input name="txtImage" type="text" style="border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" size="36"><input style="width:70;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" type="button" value="上传图片" name="UpImage13" onClick="javascript:window.open('UploadWindows.jsp?Uploadpath=../jubao/Templateupload&ReturnForm=form1&ReturnText=txtImage','upload','top=20,left=30,height=134,width=420,scrollbars=no,resizable=no')"></td>
    </tr>
    <tr> 
      <td class=forumRowHighlight height="40" colspan="2"><input type="submit" name="Submit3" value="提交" class="button"> 
        <input type="reSet" name="Submit22" value="重置" class="button"></td>
    </tr>
  </table>
  </form>
        <%else%>
            <form name="form1" method="post" action="admin_template.jsp?pageno=<%=request("pageno")%>&action=editsave&ModifyID=<%=request("ModifyID")%>" onSubmit="return CheckData()">
  <table class=tableBorder  width="95%" border="0" align="center" cellpadding="2" cellspacing="1">
    <tr > 
      <th height="22" colspan="2">功能：修改记录</th>
    </tr>
    <tr> 
      <td class=forumRowHighlight width="12%" height="19">模板名称：</td>
      <td class=forumRow width="88%"><input name="name" type="text"  class='text' id="name" value="<%=mname%>" size="22" maxlength="80"></td>
    </tr>
    <tr> 
      <td class=forumRowHighlight>模板路径： </td>
      <td class=forumRow><input name="path" type="text" readonly class='text' id="path" value="<%=mpath%>" size="22" maxlength="80">
      </td>
    </tr>
    <tr> 
      <td valign="middle" class=forumRowHighlight>上传缩略图：</td>
      <td class=forumRow><input name="txtImage" type="text" style="border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" value="<%=mpic%>" size="36">
        <input style="width:70;border:1 solid #9a9999; font-size:9pt; background-color:#ffffff" type="button" value="上传图片" name="UpImage132" onClick="javascript:window.open('UploadWindows.jsp?Uploadpath=../jubao/Templateupload&ReturnForm=form1&ReturnText=txtImage','upload','top=20,left=30,height=134,width=420,scrollbars=no,resizable=no')"></td>
    </tr>
    <tr> 
      <td class=forumRowHighlight height="40" colspan="2"><input type="submit" name="Submit32" value="提交" class="button"> 
        <input type="reSet" name="Submit222" value="重置" class="button"></td>
    </tr>
  </table>
            </form>
        <%end if%>

</body>
</html>
<%
 rs.close
 set rs=nothing
 conn.close
 set conn=nothing
%>
