<!--#include file="../inc/config.asp"-->
<!--#include file="../inc/conn.asp"-->
<!-- #include file="inc/Session.asp" -->
<!-- #include file="inc/checkrole.asp" -->
<%
'''''''''''''''''''''''''''''''''''''''''''''''
call checkPrevilege(Session("Name"),"p0000")
'''''''''''''''''''''''''''''''''''''''''''''''
dim act
act=request.QueryString("act")
%>
<html>
<head>
<title>导入其它CMS数据</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
	background-color: #D4D0C8;
}
input{ font-size:12px;}
form{margin:0;}
-->
</style>
<link href="cs.css" rel="stylesheet" type="text/css">
<style type="text/css">
body{font-size:12px;}
<!--
.style3 {color: #FFFFFF;
	font-weight: bold;
}
.style4 {color: #333333}
.style5 {color: #FF0000}
-->
</style>
</head>
<body>
<div id="Layer1" style="position:absolute; display:none; width:285px; height:159px; z-index:1; left: 353px; top: 110px; background-color: #003399; layer-background-color: #99FFFF; border: 1px none #000000;">
  <div align="center">
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <p><font color="#FFFFFF">正在添加到库...</font></p>
  </div>
</div>
<%
response.Flush()
Function getcatalogs(parentid,str)
	Dim Sql,rstemp,TemptempStr,tempStr	
	tempStr=str&"&nbsp;"
	sql="select id,title from catalogs where parentid="&parentid
	Set rstemp = Conn.Execute(Sql)
	do while Not rstemp.Eof
		getcatalogs = getcatalogs &"<option value="&rstemp(0)&">│"&tempStr&"└"&rstemp(1)&"</option>"&Chr(10)
		getcatalogs = getcatalogs & getcatalogs(rstemp(0),tempStr)
		rstemp.MoveNext
	loop
	rstemp.close
	Set rstemp = Nothing
End Function
Function getcatalogoption()
	dim ret
	ret=""
	for i=0 to ubound(first,2)
		ret=ret&"<option value="&first(0,i)&">├"&first(1,i)&"</option>"&Chr(10)
    	ret=ret&getcatalogs(first(0,i),"")
	next
	getcatalogoption=ret
end Function
if(act="do") then
	dim BeginTime,cms_name,dburl,templet,catalogid,ext_sql,run_sql,data_rows,f_content,f_pagepath
	BeginTime=Timer
	'参数获取
	cms_name=request.Form("cms_name")
	dburl=request.Form("dburl")
	templet=Clng(request.Form("templet"))
	catalogid=Clng(request.Form("catalogid"))
	ext_sql=request.Form("ext_sql")
	'连接源库
	'on error resume next
	dim cms_oriconn
	set cms_oriconn=server.CreateObject("adodb.connection") 
	cms_oriconn.open "driver={Microsoft Access Driver (*.mdb)};dbq="&Server.MapPath(dburl)
	if Err.Number <> 0 then
		Response.Write("<script>alert('[无法连接源数据库，请检查源CMS数据库地址路径是否正确!');	</script>")  
        Response.End
	end if
	select case(cms_name)
		case "powereasy"
			run_sql="select ArticleID,Title,TitleFontColor,LinkUrl,Keyword,Content,Author,Editor,CopyFrom,CreateTime,DefaultPicUrl from PE_Article where 1=1"
		case "foosun"
			run_sql="select ID,NewsID,ClassID,NewsTitle,TitleColor,IsURL,URLAddress,Content,isPicNews,Source,Editor,Keywords,Author,SaveNewsPath,FileName,FileExtName,isLock,addtime,NewsSmallPicFile from fs_ns_news where 1=1"
		case "newasp"
			run_sql="select ArticleId,title,OuterLinks,Related,content,Author,username,ComeFrom,WriteTime,ImageUrl from NC_Article where 1=1"
		case "joekoe"
			run_sql="select a_id,a_topic,a_linkurl,sp_keyes,a_remark,a_author,username,a_comto,a_ispic,a_tim,a_pic from db_article where 1=1"
		case "createlive"
			run_sql="select ArticleId,Title,TitleFontColor,IsLink,HtmlFileUrl,Keyword,Content,Author,Editor,CopyFrom,CensorTime,DefaultPicUrl from Cl_Article where 1=1"
		case else
	end select
	if(ext_sql<>"") then
		run_sql=run_sql&" "&ext_sql
	end if
	set rs=server.CreateObject("adodb.recordset")
	rs.open run_sql,cms_oriconn,3,1
	if not rs.eof then
		data_rows=rs.getrows()
	end if
	rs.close
	set rs=nothing
	cms_oriconn.close
	set cms_oriconn=nothing	
	'导入数据到淘特CMS中		
	response.Write("<script>Layer1.style.display='';</script>")
	response.Write("<div align=""center""><textarea style=""width:50%; height:500px;"">"&Chr(10))
	if(isarray(data_rows)) then
		for j=0 to ubound(data_rows,2)
			if(cms_name="foosun") then''''''''''''''''''''''''''''''''''''''''''''''导入foosun数据
				if(data_rows(5,j)=1) then
					f_pagepath=data_rows(6,j)						
				else
					f_pagepath="html"&data_rows(13,j)&data_rows(14,j)&"."&data_rows(15,j)
				end if
				f_content=data_rows(7,j)
				if(f_content<>"") then
					f_content=replace(f_content,"'","''")
				end if
				conn.execute("insert into news(pagepath,title,title_color,isoutlink,keywords,relate_key,content,templetid,parentid,classid,author,news_edit,news_from,imgnews,moditime,photo,checked) values('"&f_pagepath&"','"&data_rows(3,j)&"','"&data_rows(4,j)&"',"&data_rows(5,j)&",'"&data_rows(11,j)&"','"&data_rows(11,j)&"','"&f_content&"',"&templet&","&catalogid&","&catalogid&",'"&data_rows(12,j)&"','"&data_rows(10,j)&"','"&data_rows(9,j)&"',"&cbool(data_rows(8,j))&",'"&data_rows(17,j)&"','"&data_rows(18,j)&"',true)")				
			elseif(cms_name="powereasy") then'''''''''''''''''''''''''''''''''''''''导入powereasy数据
				if(data_rows(3,j)<>"") then
					isoutlink=1
					f_pagepath=data_rows(3,j)
				else
					isoutlink=0
					f_pagepath="html/"&date&"/pe_"&data_rows(0,j)&".htm"
				end if				
				f_content=data_rows(5,j)
				if(f_content<>"") then
					f_content=replace(f_content,"'","''")
				end if
				if(data_rows(10,j)<>"") then
					isimg=true
				else
					isimg=false
				end if
				conn.execute("insert into news(pagepath,title,title_color,isoutlink,keywords,relate_key,content,templetid,parentid,classid,author,news_edit,news_from,imgnews,moditime,photo,checked) values('"&f_pagepath&"','"&data_rows(1,j)&"','"&data_rows(2,j)&"',"&isoutlink&",'"&data_rows(4,j)&"','"&data_rows(4,j)&"','"&f_content&"',"&templet&","&catalogid&","&catalogid&",'"&data_rows(6,j)&"','"&data_rows(7,j)&"','"&data_rows(8,j)&"',"&isimg&",'"&data_rows(9,j)&"','"&data_rows(10,j)&"',true)")
			elseif(cms_name="newasp") then'''''''''''''''''''''''''''''''''''''''导入newasp数据
				if(data_rows(2,j)<>"") then
					isoutlink=1
					f_pagepath=data_rows(2,j)
				else
					isoutlink=0
					f_pagepath="html/"&date&"/nc_"&data_rows(0,j)&".htm"
				end if				
				f_content=data_rows(4,j)
				if(f_content<>"") then
					f_content=replace(f_content,"'","''")
				end if
				if(data_rows(9,j)<>"") then
					isimg=true
				else
					isimg=false
				end if
				conn.execute("insert into news(pagepath,title,title_color,isoutlink,keywords,relate_key,content,templetid,parentid,classid,author,news_edit,news_from,imgnews,moditime,photo,checked) values('"&f_pagepath&"','"&data_rows(1,j)&"','',"&isoutlink&",'"&data_rows(3,j)&"','"&data_rows(3,j)&"','"&f_content&"',"&templet&","&catalogid&","&catalogid&",'"&data_rows(5,j)&"','"&data_rows(6,j)&"','"&data_rows(7,j)&"',"&isimg&",'"&data_rows(8,j)&"','"&data_rows(9,j)&"',true)")	
			elseif(cms_name="joekoe") then'''''''''''''''''''''''''''''''''''''''导入joekoe数据
				if(data_rows(2,j)<>"") then
					isoutlink=1
					f_pagepath=data_rows(2,j)
				else
					isoutlink=0
					f_pagepath="html/"&date&"/jk_"&data_rows(0,j)&".htm"
				end if				
				f_content=data_rows(4,j)
				if(f_content<>"") then
					f_content=replace(f_content,"'","''")
				end if
				
				conn.execute("insert into news(pagepath,title,title_color,isoutlink,keywords,relate_key,content,templetid,parentid,classid,author,news_edit,news_from,imgnews,moditime,photo,checked) values('"&f_pagepath&"','"&data_rows(1,j)&"','',"&isoutlink&",'"&data_rows(3,j)&"','"&data_rows(3,j)&"','"&f_content&"',"&templet&","&catalogid&","&catalogid&",'"&data_rows(5,j)&"','"&data_rows(6,j)&"','"&data_rows(7,j)&"',"&cbool(data_rows(8,j))&",'"&data_rows(9,j)&"','"&data_rows(10,j)&"',true)")
			elseif(cms_name="createlive") then'''''''''''''''''''''''''''''''''''''''导入createlive数据
				if(data_rows(3,j)=true) then
					isoutlink=1
					f_pagepath=data_rows(4,j)
				else
					isoutlink=0
					f_pagepath="html/"&date&"/cl_"&data_rows(0,j)&".htm"
				end if				
				f_content=data_rows(6,j)
				if(f_content<>"") then
					f_content=replace(f_content,"'","''")
				end if
				if(data_rows(11,j)<>"") then
					isimg=true
				else
					isimg=false
				end if
				conn.execute("insert into news(pagepath,title,title_color,isoutlink,keywords,relate_key,content,templetid,parentid,classid,author,news_edit,news_from,imgnews,moditime,photo,checked) values('"&f_pagepath&"','"&data_rows(1,j)&"','',"&isoutlink&",'"&data_rows(5,j)&"','"&data_rows(5,j)&"','"&f_content&"',"&templet&","&catalogid&","&catalogid&",'"&data_rows(7,j)&"','"&data_rows(8,j)&"','"&data_rows(9,j)&"',"&isimg&",'"&data_rows(10,j)&"','"&data_rows(11,j)&"',true)")
			end if	
			response.Write("导入第"&j&"条记录"&Chr(10))			
		next
	end if
	response.Write("</textarea></div>"&Chr(10))
	response.Write("<script>Layer1.style.display='none';</script>")
	set data_rows=nothing
	response.Write("<p align=""center"">成功导入数据到淘特CMS！"&CStr(FormatNumber((Timer-BeginTime)*1000,2))&"毫秒</p>")
else
	'获得大类
	dim first,classid,catalogcache
	classid=Cint(request("classid"))
	dim i
	set rs=server.CreateObject("adodb.recordset")
	sql="select id,title from catalogs where parentid="&classid&" order by id asc"
	rs.open sql,conn,3,1
	if not rs.eof then
		first=rs.GetRows()
		if(ubound(first,2)<0) then
		response.Write("暂时没有分类")
	end if
	else
		response.Write("暂时没有分类,请先添加分类!")
		response.End()
	end if
	rs.close
	set rs=nothing
%>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td><iframe src="right_top.htm" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" height="30" width="100%"></iframe></td>
  </tr>
</table>
<table width="100%"  border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#999999">
  <tr bgcolor="#FF9900">
    <td width="100%" height="22"><div align="center"><span class="style3">◆ 导入其它CMS数据 ◆</span></div></td>
  </tr>
</table>
<fieldset style="margin:5px 50px 5px 50px; border-top:1px solid #ffffff; border-right:1px solid #000000;border-bottom:1px solid #000000;border-left:1px solid #ffffff;">
<form name="form1" method="post" action="?act=do">
	  <legend>设置任务</legend>
	<table width="100%"  border="0" cellpadding="0" cellspacing="1">
  <tr>
    <td width="34%"><div align="right">CMS名称及版本：</div></td>
    <td width="66%">
	<div align="left">
      <select name="cms_name">	  	
		<option value="powereasy">动易2006 Sp6</option>
		<option value="foosun">风讯4.0Sp5</option>
		<option value="newasp">新云3.0</option>
		<option value="joekoe">乔客4.0</option>
		<option value="createlive">创力3.1</option>
	  </select>
    </div></td>
  </tr>  
  <tr>
    <td width="34%"><div align="right">数据库所在路径：</div></td>
    <td width="66%">
	<div align="left" class="style4">
      <input type="text" name="dburl" size="40">
      (请使用相对路径)
      <br>
	  仅支持Access库，如果是sqlserver数据，可以先导出成Access的    </div></td>
    </tr>
  <tr>
    <td><div align="right">设置导入文章所用模板：</div></td>
    <td><div align="left" class="gray">
     <select name="templet">
  <%
  	dim Templetlist
	set rs=server.CreateObject("adodb.recordset")
	sql="select * from templet order by id asc"
	rs.open sql,conn,3,1
	if rs.eof or rs.bof then
		response.Write("<script>alert(""你还没有添加模板!请先添加模板。"");</script>")
		rs.close
		set rs=nothing		
		response.End()
	end if
	Templetlist=rs.GetRows()
	rs.close
	set rs=nothing
	for i=0 to ubound(Templetlist,2)
  %>
    <option value="<%=Templetlist(0,i)%>"><%=Templetlist(2,i)%></option>
	<%
	next
	%>
  </select><br>
	文章发布生成静态时，将以此模板为基础
	 </div></td>
  </tr>  
  <tr>
    <td><div align="right">导入到(哪个栏目)：</div></td>
    <td><div align="left">
      <select name="catalogid">
        <%
	catalogcache=application(CachePrefix&"_catalogoption_"&classid)
	if(catalogcache="" or isempty(catalogcache) or len(catalogcache)<1) then
  		application.Lock()
		application(CachePrefix&"_catalogoption_"&classid)=getcatalogoption()
		application.UnLock()
		response.Write(application(CachePrefix&"_catalogoption_"&classid))
	else
		response.Write(catalogcache)
	end if
	%>
      </select>
    </div></td>
  </tr>
  <tr>
    <td><div align="right">自定义查询条件：</div></td>
    <td>
	<div align="left" class="style4">
      <textarea name="ext_sql" style="width:90%" rows="5"></textarea><br>
		注：系统会自动根据CMS名称构建Sql查询语句，如果你熟悉sql语法并想扩展查询条件的话(如导入指定栏目的数据，指定日期内的数据等),可以在此输入标准sql语句，例子如下：<br>
		and classid='11',and dateDiff('d',date(),f_date)<=7...更多请查询学习相关sql语法    </div></td>
  </tr>
  <tr>
    <td><div align="right"></div></td>
    <td height="50"><div align="left">
      <input type="submit" name="Submit" value="下一步">
    </div></td>
  </tr>
</table>
    <div align="center" class="style5">关于数据库路径的设置说明：你可以将其它CMS数据库复制到淘特CMS所在目录下(假如名字为aa.mdb)，那么在&quot;数据库所在路径&quot;参数上可以使用相对路径为：/aa.mdb，如果将aa.mdb放到tot_dabase目录下，则设置为：/tot_dabase/aa.mdb</div>
</form>
</fieldset>
<%
end if
%>
</body>
</html>
<%
call connclose()
%>
