<!--#include file="../../lib/base.asp"-->
<!--#include file="../../theme/admin_leo/config.asp"-->
<!--#include file="../../lib/cmd.asp"-->
<%
''' eYcMs 在线客服生成插件
''' ==================================================================

'注释：插件是否安装
is_plug_install "eycms.plug.onlinekefu"

'注释：管理权限检查
is_plug_login

'注释：定义插件模板路径
dim plug_theme,plug_theme_set
plug_theme="module/plug_kefu/list.html"
plug_theme_set="module/plug_kefu/set.html"

dim act:act=lcase(eycms.fget("act",0))
select case act
	case "setting":load plug_theme_set
	case "set":setdb
	case "edit":editdb
	case else:load plug_theme
end select

sub editdb()
	dim t0,t1,t2,t3,qid,mdesc,mface,mcolor,ncolor
	t0=eycms.enhtml(eycms.fpost("t0",0))&","
	t1=eycms.enhtml(eycms.fpost("t1",0))&","
	t2=eycms.enhtml(eycms.fpost("t2",0))&","
	t3=eycms.enhtml(eycms.fpost("t3",0))&","
	t0=replace(t0," ","")
	t1=replace(t1," ","")
	t2=replace(t2," ","")
	t3=replace(t3," ","")
	dim str:str=""
	str=str&"<?xml version=""1.0"" encoding=""GB2312""?>"&vbcrlf
	str=str&"<xml>"&vbcrlf
	str=str&"<qqlist>"&vbcrlf
	mdesc=split(t1,",")
	qid=split(t2,",")
	mface=split(t0,",")
	mcolor=split(t3,",")
	if ubound(mdesc)>=0 then
	dim i
	for i=0 to ubound(mdesc)
		If eycms.strlen(qid(i))>0 then
			ncolor=mcolor(i)
			if ncolor="" Then ncolor="#000000"
			str=str&"<qq>"&vbcrlf
			str=str&"	<qid>"&qid(i)&"</qid>"&vbcrlf
			str=str&"	<dis>"&mdesc(i)&"</dis>"&vbcrlf
			str=str&"	<face>"&mface(i)&"</face>"&vbcrlf
			str=str&"	<color>"&ncolor&"</color>"&vbcrlf
			str=str&"	<id>"&i&"</id>"&vbcrlf
			str=str&"	<type>"&mface(i)&"</type>"&vbcrlf
			str=str&"</qq>"&vbcrlf
		End if
	next
	end if
	str=str&"</qqlist>"&vbcrlf
	str=str&"</xml>"
	eycms.newfile webroot&"plug/kefu/",site_root&".xml",str,"GB2312"
	create_js
	eycms.ajaxjson "保存成功",1
end sub

sub setdb()
	On error Resume next
	dim sfile, xml
	if not eycms.isfile(webroot&"plug/kefu/"&site_root&"_set.xml") Then
		eycms.copyfile webroot&"plug/kefu/info.xml",webroot&"plug/kefu/"&site_root&"_set.xml"
	end if
	sfile = server.MapPath(webroot&"plug/kefu/"&site_root&"_set.xml")
	set xml = server.createObject("Microsoft.XMLdOM")
	xml.Load (sfile)
	dim items
	set items = xml.selectsinglenode("xml/qqinfo/qqset")
	if not isnull(items) Then
		items.childnodes(0).Text = htmlencode(request.form("sitename"))
		items.childnodes(1).Text = htmlencode(request.form("siteskin"))
		items.childnodes(2).Text = htmlencode(request.form("siteshowx"))
		items.childnodes(3).Text = htmlencode(request.form("siteshowy"))
		items.childnodes(4).Text = htmlencode(request.form("sitearea"))
		items.childnodes(5).Text = htmlencode(request.form("siteid"))
		xml.save (sfile)
		set items = nothing
		set xml = nothing
		create_js
		eycms.ajaxjson "保存成功",1
	else
		eycms.ajaxjson "保存失败",0
	end if
end Sub

function htmlencode(ByVal reString)
  Dim str
  str = reString
  str = Replace(str, "&", "&amp;")
  str = Replace(str, ">", "&gt;")
  str = Replace(str, "<", "&lt;")
  htmlencode = str
end Function

function getType(t0)
	select case t0
	case 1
		getType = "Msn"
	case 2
		getType = "skype"
	case 3
		getType = "淘宝旺旺"
	case else
		getType = "QQ"
	end select
end function

function getskin(t0)
	select case t0
	case 1
		getskin = "blue"
	case 2
		getskin = "yellow"
	case 3
		getskin = "green"
	case 4
		getskin = "orange"
	case 5
		getskin = "gray"
	case 6
		getskin = "white"
	case else
		getskin = "blue"
	end select
end Function

sub create_js()
	dim tmpstr,Jurl,mylink,myclass
	Jurl=webroot & "plug/kefu"
	dim sfile, xml, rootsite, Allnodesnum
	if eycms.isfile(webroot&"plug/kefu/"&site_root&"_set.xml") Then
		sfile = server.MapPath(""&webroot&"plug/kefu/"&site_root&"_set.xml")
	else
		sfile = server.MapPath(""&webroot&"plug/kefu/info.xml")
	end if
	set xml = server.createObject("Microsoft.XMLdOM")
	xml.Load (sfile)
	set rootsite = xml.documentelement.selectsinglenode("qqinfo")
	dim sitename, siteskin
	sitename = rootsite.childnodes.item(0).childnodes.item(0).Text
	siteskin = rootsite.childnodes.item(0).childnodes.item(1).Text
	dim startX, startY, sarea, siteid, showed
	startX = rootsite.childnodes.item(0).childnodes.item(2).Text
	startY = rootsite.childnodes.item(0).childnodes.item(3).Text
	sarea = rootsite.childnodes.item(0).childnodes.item(4).Text
	siteid = rootsite.childnodes.item(0).childnodes.item(5).Text
	set rootsite = nothing
	set xml = nothing
	If siteid=0 Then showed="false" Else showed="true"
	sfile = server.MapPath(""&webroot&"plug/kefu/"&site_root&".xml")
	set xml = server.createObject("Microsoft.freeThreadedXMLdOM")
	xml.Load (sfile)
	set rootsite = xml.documentelement.selectsinglenode("qqlist")
	Allnodesnum = rootsite.childnodes.length - 1
	dim icount, iqcount, Qqnum
	for iqcount = 0 To Allnodesnum
		Qqnum = Qqnum & rootsite.childnodes.item(iqcount).childnodes.item(0).Text & ":"
	next
	myclass=""
	If sarea="left" Then myclass="show_btn_left"
	tmpstr = "function loadjscssfile(filename,filetype){" & vbcrLf & _
	"    if(filetype == ""js""){" & vbcrLf & _
	"        var fileref = document.createElement('script');" & vbcrLf & _
	"        fileref.setAttribute(""type"",""text/javascript"");" & vbcrLf & _
	"        fileref.setAttribute(""src"",filename);" & vbcrLf & _
	"    }else if(filetype == ""css""){" & vbcrLf & _
	"        var fileref = document.createElement('link');" & vbcrLf & _
	"        fileref.setAttribute(""rel"",""stylesheet"");" & vbcrLf & _
	"        fileref.setAttribute(""type"",""text/css"");" & vbcrLf & _
	"        fileref.setAttribute(""href"",filename);" & vbcrLf & _
	"    }" & vbcrLf & _
	"   if(typeof fileref != ""undefined""){" & vbcrLf & _
	"        document.getElementsByTagName(""head"")[0].appendChild(fileref);" & vbcrLf & _
	"    }" & vbcrLf & _
	"}" & vbcrLf & _
	"function onlineqq(qq){" & vbcrLf & _
	"   var tempSrc='"&webroot&"plug/kefu/wpa.asp?rantime='+Math.random()+'&qq='+qq;" & vbcrLf & _
	"	var oldscript=document.getElementById('onlinQQJs');" & vbcrLf & _
	"	var newscript=document.createElement('script');" & vbcrLf & _
	"	newscript.setAttribute('type','text/javascript'); " & vbcrLf & _
	"	newscript.setAttribute('id', 'onlinQQJs');" & vbcrLf & _
	"	newscript.setAttribute('src',tempSrc);" & vbcrLf & _
	"	if(oldscript == null){" & vbcrLf & _
	"		document.body.appendChild(newscript);}" & vbcrLf & _
	"	else{" & vbcrLf & _
	"		oldscript.parentNode.replaceChild(newscript, oldscript);" & vbcrLf & _
	"	}" & vbcrLf & _
	"	return false;" & vbcrLf & _
	"}" & vbcrLf & _
	"loadjscssfile(webroot+""plug/kefu/css/jquery.fixed.1.5.1.js"",""js"");" & vbcrLf & _
	"loadjscssfile(webroot+""plug/kefu/css/service.css"",""css"");" & vbcrLf & _
	"$(window).load(function(){" & vbcrLf & _
	"	$(""#fixedBox"").fix({" & vbcrLf & _
	"		position 		: """&sarea&"""," & vbcrLf & _
	"		horizontal  	: "&startX&",		" & vbcrLf & _
	"		vertical    	: "&startY&",      " & vbcrLf & _
	"		halfTop     	: false,	" & vbcrLf & _
	"		minStatue 		: "&showed&",	" & vbcrLf & _
	"		hideCloseBtn 	: false,	" & vbcrLf & _
	"		skin 			: """&getskin(siteskin)&""",	" & vbcrLf & _ 
	"		showBtnWidth 	: 28,       " & vbcrLf & _
	"		contentBoxWidth : 154, 		" & vbcrLf & _
	"		durationTime 	: 1000		" & vbcrLf & _
	"	});" & vbcrLf & _
	"});" & vbcrLf & _
	"var shtml;" & vbcrLf & _
	"shtml='<div class=\""fixed_box\"" id=\""fixedBox\"">';" & vbcrLf & _
	"shtml+='    <div class=\""content_box\"">';" & vbcrLf & _
	"shtml+='        <div class=\""content_inner\"">';" & vbcrLf & _
	"shtml+='        	<div class=\""close_btn\""><a title=\""关闭\""><span>关闭</span></a></div>';" & vbcrLf & _
	"shtml+='            <div class=\""content_title\""><span>客服中心</span></div>';" & vbcrLf & _
	"shtml+='            <div class=\""content_list\"">';" & vbcrLf & _
	"shtml+='                <div class=\""qqserver\"">';" & vbcrLf

	for icount = 0 To Allnodesnum
		if cint(rootsite.childnodes.item(icount).childnodes.item(5).Text) = 1 then
			mylink="<a href=""msnim:chat?contact=" & rootsite.childnodes.item(icount).childnodes.item(0).Text & """ target=""blank""><img src=""" & Jurl & "/qqface/" & rootsite.childnodes.item(icount).childnodes.item(2).Text & ".gif"" border=""0"">&nbsp;<span style=""color:" & rootsite.childnodes.item(icount).childnodes.item(3).Text & ";"">" & rootsite.childnodes.item(icount).childnodes.item(1).Text & "</span></a>"
		elseif cint(rootsite.childnodes.item(icount).childnodes.item(5).Text) = 2 then
			mylink="<a href=""callto://" & rootsite.childnodes.item(icount).childnodes.item(0).Text & """ target=""blank""><img src=""" & Jurl & "/qqface/" & rootsite.childnodes.item(icount).childnodes.item(2).Text & ".gif"" border=""0"">&nbsp;<span style=""color:" & rootsite.childnodes.item(icount).childnodes.item(3).Text & ";"" target=""blank"">" & rootsite.childnodes.item(icount).childnodes.item(1).Text & "</span></a>"
		elseif cint(rootsite.childnodes.item(icount).childnodes.item(5).Text) = 3 then
			mylink="<a href=""http://www.taobao.com/webww/ww.php?ver=3&touid=" & rootsite.childnodes.item(icount).childnodes.item(0).Text & "siteid=" & sitename & "&status=2&charset=utf-8"" target=""blank""><img border=""0"" src=""http://amos.im.alisoft.com/online.aw?v=2&uid=" & rootsite.childnodes.item(icount).childnodes.item(0).Text & "&site=cntaobao&s=2&charset=utf-8"" />&nbsp;<span style=""color:" & rootsite.childnodes.item(icount).childnodes.item(3).Text & ";"">" & rootsite.childnodes.item(icount).childnodes.item(1).Text & "</span></a>"
		else
			mylink="<a href=""javascript:;"" onclick=""javascript:onlineqq(\'" & rootsite.childnodes.item(icount).childnodes.item(0).Text & "\');""><img border=""0"" src=""http://wpa.qq.com/pa?p=2:" & rootsite.childnodes.item(icount).childnodes.item(0).Text & ":45"">&nbsp;<span style=""color:" & rootsite.childnodes.item(icount).childnodes.item(3).Text & ";"">" & rootsite.childnodes.item(icount).childnodes.item(1).Text & "</span></a>"
		end If
		
		tmpstr = tmpstr & "shtml+='                    <p>"&mylink&"</p>';" & vbcrLf
	next

	tmpstr = tmpstr & "shtml+='                </div>';" & vbcrLf & _
	"shtml+='                <hr>';" & vbcrLf & _
	"shtml+='                <div class=\""phoneserver\"">';" & vbcrLf & _
	"shtml+='                    <h5>客户服务热线</h5>';" & vbcrLf & _
	"shtml+='                    <p>"&eycms.getsys("my_xztel")&"</p>';" & vbcrLf & _
	"shtml+='                </div>';" & vbcrLf & _
	"shtml+='                <hr>';" & vbcrLf & _
	"shtml+='                <div class=\""msgserver\"">';" & vbcrLf & _
	"shtml+='                    <p><a href=\"""&eycms.gurl("plug/book.asp","")&"\"">给我们留言</a></p>';" & vbcrLf & _
	"shtml+='                </div>';" & vbcrLf & _
	"shtml+='            </div>';" & vbcrLf & _
	"shtml+='            <div class=\""content_bottom\""></div>';" & vbcrLf & _
	"shtml+='        </div>';" & vbcrLf & _
	"shtml+='    </div>';" & vbcrLf & _
	"shtml+='    <div class=\""show_btn "&myclass&"\""><span>展开客服</span></div>';" & vbcrLf & _
	"shtml+='</div>';" & vbcrLf & _
	"$(document).ready(function(){" & vbcrLf & _
	"    $('body').append(shtml);" & vbcrLf & _
	"});"
	eycms.newfile "",site_root&".js",tmpstr,"utf-8"
end sub

eycms.db.dbclose
%>