<!--#include file="conn.asp"-->
<%
On Error Resume Next '遇有错误仍继续执行
if Session("WebTplock") then
	response.Redirect("error.asp?msg=" & Server.URLEncode("您的模板已经锁定，不能更换，如果您需要的话，请向您的服务商申请！"))
end if

	if GetVariable("templet")<>"" then
		'检查访问的来源是否合法
		'call checkPrePage()
	
		'更新用户模板
		strSQL="Update website Set w_templet='" & GetVariable("templet") & "'  Where m_id=" & trim(Session("UserID"))
		conn.execute strSQL,0,1
		
		strUserID=trim(Session("UserID"))

		'先删除原来的旧数据
		Set fs = Server.CreateObject( Const_ScriptFileSystem )
		HomeFolder = "home/" & trim(Session("UserName"))
		HomeFolder = Server.MapPath( HomeFolder )
		
		if fs.FolderExists(HomeFolder & "\admin") then
			fs.DeleteFolder HomeFolder & "\admin",true
		end if
				
		if fs.FolderExists(HomeFolder & "\images") then
			fs.DeleteFolder HomeFolder & "\images",true
		end if
		
		fs.DeleteFile HomeFolder & "\*.*",true
				
		response.Redirect("Admin_Templet.asp?action=update")
	end if
%>
<%
strType=GetVariable("typename")
if GetVariable("type")<>"" then	
	strQuery=" And  t_type =" & GetVariable("type")
else
	strQuery=""
	strType="全部模板"
end if

strServer=request.ServerVariables("SERVER_NAME")
if request.ServerVariables("SERVER_PORT")<>"" And request.ServerVariables("SERVER_PORT")<>"80" then
	strServer=strServer & ":" & request.ServerVariables("SERVER_PORT")
end if

strSQL="Select * From Templet  Where t_type In (" & Session("WebTemplet") & ") And (t_server is null Or t_server='' Or t_server='" & strServer & "') " & strQuery & " Order By t_code"
set SearchRS=server.CreateObject ("ADODB.Recordset")
SearchRS.open strSQL,conn,1,1

'分页显示初始化
page=GetVariable("page")
if page="" then
	page=1
else
	page=Cint(page)
end if

Section=GetVariable("section")
if Section="" then
	Section=1
else
	Section=Cint(Section)
end if
'变量赋值

intPageSize=4			'每页显示记录数		
intSectionSize=5		'多少页为一段，像GOOGLE一样
PrevSectionText="<FONT face=webdings>7</FONT>"		'上一段的链接文字
NextSectionText="<FONT face=webdings>8</FONT>"		'下一段的链接文字
PrevPageText="<FONT face=webdings>3</FONT>"			'上页的链接文字	
NextPageText="<FONT face=webdings>4</FONT>"			'下页的链接文字

strPageUrl="?type=" & GetVariable("type") & "&typename=" & GetQueryString("typename")

SearchRS.pagesize=intPageSize
intCount=SearchRS.RecordCount 
intPageCount=SearchRS.pagecount

if intCount<=0 then
	response.Redirect("error.asp?msg=" & Server.URLEncode("很抱歉，您的级别不够，不能使用此类模板，如果您是需要的话，请向您的代理商申请！"))
end if
intSectionCount=(intPageCount - 1) \ intSectionSize + 1
SearchRS.AbsolutePage=page  
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>电子商务自助建站--您理想的助手</title>
<link href="common/styleMain.css" rel="stylesheet" type="text/css">
</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">
                      <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="1" cellpadding="1" cellspacing="1" bgcolor="#bad2f0">
                                <tr> 
                                  <td height="26" bgcolor="#5f8ac5">&nbsp;<a href="?" class=WhiteLink>所有模板</a><font color="#FFFFFF"> |
                                    <%
									strSQL="Select * From templet_class"
									Set rsSub=Server.CreateObject("ADODB.RecordSet")
									rsSub.open strSQL,conn,1,1
									for i=1 to rsSub.recordcount
									%>
                                    <a href="?type=<%=Trim(rsSub("id"))%>&typename=<%=Trim(rsSub("tc_name"))%>" class=WhiteLink><%=Trim(rsSub("tc_name"))%></a> | 
                                    <%
										rsSub.movenext
									next
									rsSub.close
									%>
                                    </font></td>
                                </tr>
                                <tr> 
                                  <td height="400" valign="top" bgcolor="#FFFFFF"> 
                                    <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                      <tr> 
                                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr> 
                                              <td width="13%">＞<strong><%=trim(strType)%></strong></td>
                                              <td width="87%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                  <tr> 
                                                    <td align="right"> 共有 <strong><%=intCount%></strong> 条个模板，页次<%=Page%>/<%=intPageCount%>　 
                                                      <%
			'计算每一段的开始页
			intStarPage=(Section-2) * intSectionSize + 1
			'前一段
			if Section<=1 then
				response.Write(PrevSectionText & " ")
			else
				response.Write("<a href='" & strPageUrl & "&page=" & intStarPage & "&section=" & Section-1 & "'>" & PrevSectionText & "</a> ")
			end if 
			
			'显示页码列表
			response.Write("第")
			intStarPage=(Section-1) * intSectionSize + 1
		    for p=intStarPage to intStarPage + intSectionSize - 1
				if p > intPageCount then exit for
				if p=page then
		    		response.Write("<strong>[" & p & "]</strong> ")
				else
		    		response.Write("<a href='" & strPageUrl & "&page=" & p & "&section=" & Section & "'>[" & p & "]</a> ")
				end if	
		    next
			response.Write("页")
			'后一段
			intStarPage=(Section) * intSectionSize + 1
			if Section>=intSectionCount then
				response.Write(" " & NextSectionText)
			else
				response.Write(" <a href='" & strPageUrl & "&page=" & intStarPage & "&section=" & Section+1 & "'>" & NextSectionText & "</a> ")
			end if 
		  %> <select name="page" size="1" onchange="window.location='<%=strPageUrl & "&section="%>' + (Math.floor((parseInt(this.value)-1)/<%=intSectionSize%>)+1) + '<%="&page="%>' + this.value">
                                                        <option value="<%=page%>" selected>第<%=page%>页</option>
                                                        <%
							for j=1 to intPageCount
			  %>
                                                        <option value="<%=j%>" >第<%=j%>页</option>
                                                        <%
							next
			  %>
                                                      </select>
                                                      　 </td>
                                                  </tr>
                                                </table></td>
                                            </tr>
                                          </table></td>
                                      </tr>
                                      <tr> 
                                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <%
										for i=1 to (intPageSize+1)\2
											if SearchRS.eof then exit for
										%>
                                            <tr align="center"> 
                                              <% 
											for j=1 to 2
												if SearchRS.eof then exit for
											%>
                                              <td width="50%"> <table width="100%" border="0" cellspacing="0" cellpadding="5">
                                                  <tr> 
                                                    <td align="center"><a href="Templet/pic/<%=trim(SearchRS("t_code"))%>.gif" target="_blank" title="<%=trim(SearchRS("t_intro"))%>"><img src="Templet/pic/small/<%=trim(SearchRS("t_code"))%>.gif" space="2" border="1"></a></td>
                                                  </tr>
                                                  <tr> 
                                                    <td align="center"><%=trim(SearchRS("t_name"))%> 
                                                      <input type="button" name="Submit" value="我要这个" onclick="if(confirm('重要警告：\n如果选择新的模板，原来模板的数据将会丢失　\n\n如确实要更改模板，建议您先将数据备份到本地硬盘！　')){location='?templet=<%=trim(SearchRS("t_code"))%>';}"></td>
                                                  </tr>
                                                </table></td>
                                              <%
												SearchRS.movenext
											next
											%>
                                            </tr>
											<%next%>
                                          </table></td>
                                      </tr>
                                      <tr> 
                                        <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                            <tr> 
                                              <td width="13%">＞<strong><%=trim(strType)%></strong></td>
                                              <td width="87%"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                  <tr> 
                                                    <td align="right"> 共有 <strong><%=intCount%></strong> 条个模板，页次<%=Page%>/<%=intPageCount%>　 
                                                      <%
			'计算每一段的开始页
			intStarPage=(Section-2) * intSectionSize + 1
			'前一段
			if Section<=1 then
				response.Write(PrevSectionText & " ")
			else
				response.Write("<a href='" & strPageUrl & "&page=" & intStarPage & "&section=" & Section-1 & "'>" & PrevSectionText & "</a> ")
			end if 
			
			'显示页码列表
			response.Write("第")
			intStarPage=(Section-1) * intSectionSize + 1
		    for p=intStarPage to intStarPage + intSectionSize - 1
				if p > intPageCount then exit for
				if p=page then
		    		response.Write("<strong>[" & p & "]</strong> ")
				else
		    		response.Write("<a href='" & strPageUrl & "&page=" & p & "&section=" & Section & "'>[" & p & "]</a> ")
				end if	
		    next
			response.Write("页")
			'后一段
			intStarPage=(Section) * intSectionSize + 1
			if Section>=intSectionCount then
				response.Write(" " & NextSectionText)
			else
				response.Write(" <a href='" & strPageUrl & "&page=" & intStarPage & "&section=" & Section+1 & "'>" & NextSectionText & "</a> ")
			end if 
		  %> <select name="select" size="1" onchange="window.location='<%=strPageUrl & "&section="%>' + (Math.floor((parseInt(this.value)-1)/<%=intSectionSize%>)+1) + '<%="&page="%>' + this.value">
                                                        <option value="<%=page%>" selected>第<%=page%>页</option>
                                                        <%
							for j=1 to intPageCount
			  %>
                                                        <option value="<%=j%>" >第<%=j%>页</option>
                                                        <%
							next
			  %>
                                                      </select>
                                                      　 </td>
                                                  </tr>
                                                </table></td>
                                            </tr>
                                          </table></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>
