<!--#include file="../include/Conn.jsp"-->
<!--#include file="../Include/Char.jsp" -->
<!--#include file="Admin_IsLogin.jsp" -->
<%
'Define Variable 
dim i
dim rs
dim mGrade,m_SQL,mFlag,mBgColor
'initialization 
mFlag=true'add


if request("action")="canal" then
  m_SQL = "update CityCard_League set template_id='0' WHERE companyid=" &Request.QueryString("canal_id")
  conn.execute m_SQL
  Response.write "<script>location.replace('Admin_AgioLeague2_tem.jsp?action=IsDelete&pageno="&Request.Querystring("pageno")&"')</script>"
end if

'生成静态网页！！！
On Error Resume Next
        '定义数组设定模板生成文件
  Dim mTemplatePath,mTemplateAllPath
  Dim mNewsContent,mAllPath,mFileName,mPathDir
  dim temnum(6)
  temnum(0)="index.html"
  temnum(1)="about.html"
  temnum(2)="products.html"
  temnum(3)="news.html"
  temnum(4)="gbook.html"
  temnum(5)="contact.html"
 ' temnum(6)="index.htm"
 
If Request("active")="sheng" then 
   m_temID = trim(request("temid"))
   if request.form("box").count < 1 then
      response.write "<script>alert('对不起,请选择商家！');history.back();</Script>"
   end if
   
  for each league_id in Request.form("box")
     
      Set rs_html=Server.CreateObject("Adodb.RecordSet")
      mSql = "Select * from citycard_league where companyid="&league_id 
	   rs_html.open mSql,conn,3,3
	 mTitle=rs_html("name")

      '开始循环生成静态网页
	  dim n
    for n=0 to 5
    'Create Html
	       mTemplatePath=temnum(n)

	       Set fso = CreateObject("Scripting.FileSystemObject")
           mTemplateAllPath = Server.MapPath("../jubao/Template/"+m_temID+"/"+mTemplatePath)
	      If fso.FileExists(mTemplateAllPath) then
	       Set objStream = fso.OpenTextFile(mTemplateAllPath)
	      Else
	       Call Msgbox("对不起，该模板文件 "&mTemplatePath&" 找不到，\n请先创建该类别的模板文件!",1)
	      End if
		    mNewsContent=""
			'相关数据转化
				m_SQL = "SELECT F_Value FROM T_AreaType WHERE F_ID = "&rs_html("cityid")
				Set rst = conn.Execute(m_SQL)
				if Not rst.Eof then
				mcity=rst(0)
				end if
				rst.close
			  if rs_html("startbusinesstime")=rs_html("endbusinesstime") then
	          mbusinesstime="24小时营业"
              else
	          mbusinesstime=rs_html("startbusinesstime")&"至"&rs_html("endbusinesstime")
              end if
			  select case rs_html("grade")
			  case "1"
			  m_gradeimage="icon_common.gif"
			  case "2"
			  m_gradeimage="icon_copper.gif"
			  case "3"
			  m_gradeimage="icon_general.gif"
			  case "4"
			  m_gradeimage="icon_golden.gif"			 
			  end select
			  dim anid
			  anid=split(rs_html("iscard"),",")
			  if anid(0)="1" then
			  m_cardcontent=rs_html("agio")
			  else
			  m_cardcontent="非消费卡加盟商"
			  end if
			  
			  if anid(1)="1" then
			  m_telcontent="平台开发中......"
			  else
			  m_telcontent="非手机短信加盟商"
			  end if
			  if rs_html("email")<>"" then
			  m_email=rs_html("email")
			  else
			  m_email="  "
			  end if
			  if rs_html("linkman")<>"" then
			  m_linkman=rs_html("linkman")
			  else
			  m_linkman="  "
			  end if
   			  if rs_html("tbtj")<>"" then
			  m_tbtj=rs_html("tbtj")
			  else
			  m_tbtj="  "
			  end if
			     if rs_html("post")<>"" then
			  m_post=rs_html("post")
			  else
			  m_post="  "
			  end if
			  '----------------------------------------------------------------------
			  
	        Do While not objStream.AtEndOfStream
 	        mNewsContent = mNewsContent & objStream.ReadLine
	        mNewsContent = replace(mNewsContent,"[league_id]",rs_html("companyid"))
	        mNewsContent = replace(mNewsContent,"[league_name]",rs_html("name"))
			mNewsContent = replace(mNewsContent,"[league_content]",rs_html("content"))
			mNewsContent = replace(mNewsContent,"[league_address]",rs_html("address"))
			mNewsContent = replace(mNewsContent,"[league_traffic]",rs_html("traffic"))
			mNewsContent = replace(mNewsContent,"[league_address]",rs_html("address"))
			mNewsContent = replace(mNewsContent,"[league_postcode]",m_post)
			mNewsContent = replace(mNewsContent,"[league_city]",mcity)
			mNewsContent = replace(mNewsContent,"[league_tel]",rs_html("tel"))
			mNewsContent = replace(mNewsContent,"[league_consume]",rs_html("consume"))
			mNewsContent = replace(mNewsContent,"[league_car]",rs_html("car"))
			mNewsContent = replace(mNewsContent,"[league_businesstime]",mbusinesstime)
			mNewsContent = replace(mNewsContent,"[league_tbtj]",m_tbtj)
			mNewsContent = replace(mNewsContent,"[league_website]",rs_html("website"))
			mNewsContent = replace(mNewsContent,"[league_PayClass]",rs_html("payclass"))
			mNewsContent = replace(mNewsContent,"[league_hits]",rs_html("hits"))
			mNewsContent = replace(mNewsContent,"[league_grade_gif]",m_gradeimage)
			mNewsContent = replace(mNewsContent,"[league_agiocontent]",rs_html("agiocontent"))
			mNewsContent = replace(mNewsContent,"[league_grade_card]",m_cardcontent)
			mNewsContent = replace(mNewsContent,"[league_grade_tel]",m_telcontent)
			mNewsContent = replace(mNewsContent,"[league_tel]",rs_html("tel"))			
			mNewsContent = replace(mNewsContent,"[league_mail]",m_email)
			mNewsContent = replace(mNewsContent,"[league_linkman]",m_linkman)
	          '  mNewsContent = replace(mNewsContent,"[league_Consume]",rs_html("Consume"))
	  
	       Loop
	         objStream.Close
    'Create BigFolder
	         folderPath = Server.MapPath("../jubao")
             mPathDir = folderPath & "\" & league_id
	         If Not fso.FolderExists(mPathDir) Then
	         Set f = fso.CreateFolder(mPathDir)
	         Set f=nothing
	         end if
    'Create SmallFolder
  '  mPathDir = folderPath & "\" & mBigFolder&"\"& mSmallFolder
	'If Not fso.FolderExists(mPathDir) Then
'	  Set f = fso.CreateFolder(mPathDir)
	'  Set f=nothing
'	end if
	'Create FileName
	      mFileName=temnum(n)      '生成后的文件名
	      mPathDir = folderPath & "\"&league_id
	      Set objHtml = fso.CreateTextFile(mPathDir+"\"+mFileName)
	      objHtml.WriteLine mNewsContent
	      objHtml.close
	      set fso=nothing
		
		next
			'
		   rs_html("Template_id")=m_temID
		   rs_html.update
		  
		 rs_html.close
		 set rs_html=nothing	
  	  
   next
response.write "<script language='javascript'>alert('商家静态网页批量生成完成！');</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';
}
function CheckAll()
{     
  for (var k=0;k<document.form2.elements.length;k++)
    {
      var e = document.form2.elements[k];
      if (e.name != 'allbox')
	e.checked = document.form2.allbox.checked;
    }
}
</SCRIPT>
<script language="javascript">
function CheckData(){
  if (document.form1.txtUserName.value=="")
   {
    alert("对不起,用户名不能为空，请输入！");
	document.form1.txtUserName.focus();
	return false;
   }
}
</script></head>
<body text="#000000" >
<table width="100%" height="1"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td></td>
  </tr>
</table>
<TABLE width=100% height=95% border=1 align="center" cellPadding=0 
cellSpacing=0 borderColor=#7c96b8 borderColorDark=#ffffff>
  <TBODY>
    <TR> 
      <TD align=center valign="top">
        <%
      admin_flag=",5|2|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
      %>
        <table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#dde1ec">
          <tr><form name="frmSearch" method="post" action="Admin_AgioLeague2_tem.jsp">
              <td height="35" align="center" bgcolor="#FFFFFF"> <font color="#FF0000">注：点击 
                <input type="button" name="Submit2" value="确定生成静态网页">
                后请稍等片刻即可完成</font> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;请输入关键字 
                <input type="text" name="Keywords" class="text"> 
				<select name="TradeType" class="text">
			  <%
			   Response.write "<option value='-1'>所有类别</option>"
			   m_SQL = "SELECT F_ID,F_Value FROM T_TradeType ORDER BY F_ID "
			   Set rs = conn.Execute(m_SQL)
			   Do While Not rs.Eof
			     Response.write "<option value='"&rs(0)&"'>"&rs(1)&"</option>"
				 rs.MoveNext
			   Loop
			   rs.Close
			   %>
                </select>
				<input name="btnSearch" type="submit"  value="搜索"> </td>
            </form>
          </tr>
        </table> 
        <table width="100%" border="0" cellspacing="1" cellpadding="0" align="center">
          <tr style="cursor:hand" onMouseOut="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='#EBEEF6'"  bgcolor="#dde1ec" align="center"> 
            <td width="6%" height="11">&nbsp;</td>
            <td width="9%"><font color="#666666"><b>级别</b></font></td>
            <td width="13%"><font color="#666666"><b>用户名</b></font></td>
            <td width="35%" bgcolor="#dde1ec"><font color="#666666"><b>商家名称</b></font></td>
            <td width="12%" bgcolor="#dde1ec"><strong><b><font color="#666666">模板ID</font></b></strong></td>
            <td width="9%"><strong><font color="#666666">地区</font></strong></td>
            <td width="11%"><font color="#666666"><b>所属分类</b></font></td>
            <td width="5%"><font color="#666666"><b>推荐</b>&nbsp;</font></td>
          </tr>
        </table>
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#ebeef6">
          <form name="form2" method="post" action="">
            <%  
	Keywords = Trim(Request("keywords"))
	TradeType = Trim(Request("TradeType"))
	Set rs=Server.createobject("Adodb.RecordSet")
    pageno=request.querystring("pageno")
    pmcount=20 
    m_SQL = "SELECT * FROM CityCard_League WHERE (iscard='0,0' and ischecked=1)"
	if TradeType <> "" and TradeType <> "-1" then
      m_SQL = m_SQL + " AND hangyeid="&TradeType
	end if

    m_SQL = m_SQL +" and (name like  '%" & Keywords & "%'"
	m_SQL = m_SQL +" or address like  '%" & Keywords & "%'"
	m_SQL = m_SQL +" or username like  '%" & Keywords & "%')"

	m_SQl = m_SQL + " order by companyid desc,cityid desc"
	rs.open m_SQL,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("companyid"))=Trim(mBgColor) then mColor= "D6DFFF" else mColor= "ffffff"
 if Trim(rs("ischecked"))="1" then onColor= "#EBEEF6" else onColor= "#FF9797"
 amid=split(rs("iscard"),",")
%>
            <tr bgcolor="<%=mColor%>"   onmouseout="this.style.backgroundColor=''" onMouseOver="this.style.backgroundColor='<%=onColor%>'" > 
              <td width="6%" align="center"><a href="#" onClick="javascript:window.open('careate_template.jsp?ID=<%=rs("companyid")%>','gouwu','width=500,height=500,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');" title="点击设置模板..."> 
                </a> <input name="box" type="checkbox" id="box" value="<%=rs("companyid")%>" > 
              </td>
              <td width="9%" align="center"><a href="#" onClick="javascript:window.open('careate_template.jsp?ID=<%=rs("companyid")%>','gouwu','width=500,height=500,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes');" title="点击设置模板..."> 
                <%
			m_SQL = "SELECT F_Value FROM citycard_grade Where F_ID=" & rs("grade")
			Set rst = conn.Execute(m_SQL)
			if not rst.Eof then
			%>
                <%=rst(0)%> 
                <% end if
			rst.close
			set rst=nothing
			%>
                </a></td>
              <td width="13%" align="center" ><a href="../CardManage/Login.jsp?ID=<%=rs("companyid")%>" target="_blank"><%=rs("username")%></A></td>
              <td width="35%"> <a target='_blank' href="../jubao/Show.jsp?ID=<%=rs("companyid")%>"> 
                <%=rs("name")%> </a><font color="#FF0000">(<%=rs("Agio")%>)</font></td>
                <td width="12%" align="center"> 
                <% if rs("template_id")<>0 then %>
                <%=rs("template_id")%> [<a href="admin_agioleague2_tem.jsp?canal_id=<%=rs("companyid")%>&action=canal"><font color="#FF0000"><strong>取消</strong></font></a>] 
                <% else %>
                <strong>未使用</strong> 
                <% end if %>
              </td>
              <td width="9%" align="center" > <%
			m_SQL = "SELECT F_Value FROM T_TradeType Where F_ID=" & rs("hangyeid")
			Set rst = conn.Execute(m_SQL)
			if not rst.Eof then Response.Write rst(0)
			rst.Close
			%> </td>
              <td width="11%" align="center" > <%
			m_SQL = "SELECT F_Value FROM T_AreaType Where F_ID=" & rs("cityid")
			Set rst = conn.Execute(m_SQL)
			if not rst.Eof then Response.Write rst(0)
			rst.Close
			%> </td>
              <td width="5%" align="center" > <%=rs("tuijian")%> </td>
            </tr>
            <%
 rs.movenext
 re=re+1
 rc=rc-1
 loop
 end if
%>
            <tr bgcolor="<%=mColor%>"> 
              <td height="35" colspan="10" align="center">请选择网页模板： 
                <select name="temid">
                  <%			   
			   m_SQL = "select * from citycard_template where f_path<>'' "
			   Set rst = conn.Execute(m_SQL)
			   Do While Not rst.Eof
			     Response.write "<option value='"&rst("f_id")&"'>"&rst("f_name")&"["&rst("f_id")&"]"&"</option>"
				 rst.MoveNext
			   Loop
			   rst.Close
			   %>
                </select> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                <input type="submit" name="Submit" value="确定生成静态网页"> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
                <input type="checkbox" name="allbox" value="Check All" onClick="CheckAll();">
                全选 
                <input name="active" type="hidden" id="active" value="sheng"></td>
            </tr>
          </form>
        </table> 
        <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="FFFFFF">
          <tr> 
            <td width="35%" 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="65%" align="right"> 
<%
if pageno="" then pageno=1
if pageno>1 then
   response.write "<a href='Admin_AgioLeague2_tem.jsp?keywords="&Keywords&"&TradeType="&TradeType&"'> <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_AgioLeague2_tem.jsp?pageno="&pageno-1&"&keywords="&Keywords&"&TradeType="&TradeType&"'><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_AgioLeague2_tem.jsp?pageno="&pno&"&keywords="&Keywords&"&TradeType="&TradeType&"'>"&pno&"</a></b>"
 end if
next
response.write "&nbsp"

if int(pageno) < int(rs.pagecount) then
  response.write "<a href='Admin_AgioLeague2_tem.jsp?pageno="&pageno+1&"&keywords="&Keywords&"&TradeType="&TradeType&"'><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_AgioLeague2_tem.jsp?pageno="&mpage&"&keywords="&Keywords&"&TradeType="&TradeType&"'><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>
        <strong><font color=red> </font></strong> </TD>
    </TR>
  </TBODY>
</TABLE>
</body>
</html>
<%
 CloseDatabase
%>
