<html xmlns="http://www.w3.org/1999/xhtml">
<!--#include file="../Inc/Conn.asp" -->
<!--#include file="../Inc/SK.Session.asp" -->
<!--#include file="../Inc/SK.Funtion.asp" -->
<%if Not (Getconfig("SK_Client")="0" AND (Session("Manager")="1" OR (JudgePopedomTF(Session("UserName"),"SK200000000") AND JudgePopedomTF(Session("UserName"),"SK200000204")))) then Call ReturnError()%>
<%
'导出联系人信息到Excel开始
Response.Buffer = True 
Response.ContentType = "application/vnd.ms-excel" 
SaveFilename=replace(replace(replace(now,":","")," ",""),"/","")
Thead="LinkMan_"
Response.AddHeader "content-disposition", "inline; filename = "&Thead&SaveFilename&".xls"

Response.Write("<table width=""100%"" align=""center"" cellpadding=""3"" cellspacing=""1"" border=""1"">"&VBCrlf)
Response.Write("<tr bgcolor=""#E8E8E8"">"&VBCrlf)
Response.Write("<td width=""4%""><b>关联客户</b></td>")
Response.Write("<td width=""12%""><b>姓名</b></td>")
Response.Write("<td width=""9%""><b>性别</b></td>")
Response.Write("<td width=""9%""><b>年龄</b></td>")
Response.Write("<td width=""9%""><b>生日</b></td>")
Response.Write("<td width=""9%""><b>部门</b></td>")
Response.Write("<td width=""9%""><b>职务</b></td>")
Response.Write("<td width=""5%""><b>办公电话</b></td>")
Response.Write("<td width=""5%""><b>传真</b></td>")
Response.Write("<td width=""15%""><b>手机</b></td>")
Response.Write("<td width=""11%""><b>备用手机</b></td>")
Response.Write("<td width=""6%""><b>家庭电话</b></td>")
Response.Write("<td width=""6%""><b>电子邮件</b></td>")
Response.Write("<td width=""6%""><b>QQ号码</b></td>")
Response.Write("<td width=""6%""><b>Msn</b></td>")
Response.Write("<td width=""6%""><b>ICQ</b></td>")
Response.Write("<td width=""6%""><b>家庭住址</b></td>")
set RsOptions=server.createobject("adodb.recordset")
sqlOptions="SELECT * from SK_ClientOptions where SK_Di=1 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsOptions.Open sqlOptions,conn,1,1
for Optionsi=1 to RsOptions.recordCount
Response.write"<td width=""6%""><b>"&RsOptions("SK_Title")&"</b></td>"
RsOptions.movenext 
next
RsOptions.close
set RsOptions=Nothing
set RsFields=server.createobject("adodb.recordset")
sqlFields="SELECT * from SK_ClientFields where SK_Di=1 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsFields.Open sqlFields,conn,1,1
for Fieldsi=1 to RsFields.recordCount
Response.write"<td width=""6%""><b>"&RsFields("SK_Title")&"</b></td>"
RsFields.movenext 
next 
RsFields.close
set RsFields=Nothing
Response.Write("</tr>"&VBCrlf)

if F("id")="" then
Set RS = Server.CreateObject("ADODB.Recordset")
if Session("Manager")=1 or Session("Manager")=2 then
sql="select * from SK_Linkman where SK_Del=0"
elseif Session("Manager")=3 then
sql="select * from SK_Linkman INNER JOIN SK_SystemUsers ON SK_Linkman.SK_SalesID=SK_SystemUsers.UsersID where SK_Linkman.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&""
elseif Session("Manager")=4 then
sql="select * from SK_Linkman INNER JOIN SK_SystemUsers ON SK_Linkman.SK_SalesID=SK_SystemUsers.UsersID where SK_Linkman.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&""
elseif Session("Manager")=5 then
sql="select * from SK_Linkman INNER JOIN SK_SystemUsers ON SK_Linkman.SK_SalesID=SK_SystemUsers.UsersID where SK_Linkman.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SystemUsers.SK_Dept3="&Session("Dept3")&""
elseif Session("Manager")=6 then
sql="select * from SK_Linkman where SK_Del=0 and SK_SalesID="&Session("UID")&""
end if
RS.Open Sql,Conn,1,1
if rs.bof and rs.eof then Call ReturnError4()
K=0
while not Rs.eof
K=K+1
Response.Write("<tr bgcolor=FFFFFF>"&VBCrlf)
set RsClient=server.createobject("adodb.recordset")
RsClient.open "SELECT * from SK_Client where ClientID="&Rs("SK_ClientID")&"",conn,1,1
if rsClient.bof and rsClient.eof then
Response.Write("<td align=left></td>")
else
Response.Write("<td align=left>"&RsClient("SK_Wname")&"</td>")
end if
RsClient.close
set RsClient=Nothing

Response.Write("<td align=left>"&Rs("SK_LName")&"</td>")
if Rs("Sex")=0 then
Response.Write("<td align=left>女</td>")
else
Response.Write("<td align=left>男</td>")
end if
if Rs("SK_Age")<>"" then
Response.Write("<td align=left>"&Rs("SK_Age")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Birthday")<>"" then
Response.Write("<td align=left>"&Rs("SK_Birthday")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_LDept")<>"" then
Response.Write("<td align=left>"&Rs("SK_LDept")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_LJob")<>"" then
Response.Write("<td align=left>"&Rs("SK_LJob")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Tel")<>"" then
Response.Write("<td align=left>"&Rs("SK_Tel")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Fax")<>"" then
Response.Write("<td align=left>"&Rs("SK_Fax")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Mobile")<>"" then
Response.Write("<td align=left>"&Rs("SK_Mobile")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Mobile1")<>"" then
Response.Write("<td align=left>"&Rs("SK_Mobile1")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Phone")<>"" then
Response.Write("<td align=left>"&Rs("SK_Phone")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Email")<>"" then
Response.Write("<td align=left>"&Rs("SK_Email")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_QQ")<>"" then
Response.Write("<td align=left>"&Rs("SK_QQ")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_OfficeMsn")<>"" then
Response.Write("<td align=left>"&Rs("SK_OfficeMsn")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_ICQ")<>"" then
Response.Write("<td align=left>"&Rs("SK_ICQ")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Address")<>"" then
Response.Write("<td align=left>"&Rs("SK_Address")&"</td>")
else
Response.Write("<td align=left></td>")
end if

set RsOptions=server.createobject("adodb.recordset")
sqlOptions="SELECT * from SK_ClientOptions where SK_Di=1 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsOptions.Open sqlOptions,conn,1,1
for Optionsi=1 to RsOptions.recordCount
Set rsOptionsDetail=Server.CreateObject("ADODB.RecordSet") 
sqlOptionsDetail="SELECT * from SK_ClientOptionsDetail where SK_OptionsID="&RsOptions("FieldID")&" and OptionsDetailID="&rs(""&RsOptions("SK_FieldName")&"")&"" 
rsOptionsDetail.Open sqlOptionsDetail,conn,1,1
if rsOptionsDetail.bof and rsOptionsDetail.eof then
Response.Write("<td align=left></td>")
else
Response.write"<td align=left>"&rsOptionsDetail("SK_OName")&"</td>"
end if
rsOptionsDetail.close
set rsOptionsDetail=Nothing
RsOptions.movenext 
next
RsOptions.close
set RsOptions=Nothing

set RsFields=server.createobject("adodb.recordset")
sqlFields="SELECT * from SK_ClientFields where SK_Di=1 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsFields.Open sqlFields,conn,1,1
for Fieldsi=1 to RsFields.recordCount
if Rs(""&RsFields("SK_FieldName")&"")<>"" then
Response.write"<td align=left>"&Rs(""&RsFields("SK_FieldName")&"")&"</td>"
else
Response.Write("<td align=left></td>")
end if
RsFields.movenext 
next 
RsFields.close
set RsFields=Nothing

Response.Write("</tr>"&VBCrlf)
rs.movenext
wend

elseif F("id")<>"" then '当选择有ID时输出数据开始
str2=split(F("id"),",")
for i=0 to ubound(str2)
Set Rs = Server.CreateObject("ADODB.Recordset")
if Session("Manager")=1 or Session("Manager")=2 then
sql="select * from SK_Linkman where SK_Del=0 and LinkmanID="&trim(str2(i))
elseif Session("Manager")=3 then
sql="select * from SK_Linkman INNER JOIN SK_SystemUsers ON SK_Linkman.SK_SalesID=SK_SystemUsers.UsersID where SK_Linkman.SK_Del=0 and  SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_Linkman.LinkmanID="&trim(str2(i))
elseif Session("Manager")=4 then
sql="select * from SK_Linkman INNER JOIN SK_SystemUsers ON SK_Linkman.SK_SalesID=SK_SystemUsers.UsersID where SK_Linkman.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_Linkman.LinkmanID="&trim(str2(i))
elseif Session("Manager")=5 then
sql="select * from SK_Linkman INNER JOIN SK_SystemUsers ON SK_Linkman.SK_SalesID=SK_SystemUsers.UsersID where SK_Linkman.SK_Del=0 and SK_SystemUsers.SK_Dept1="&Session("Dept1")&" and SK_SystemUsers.SK_Dept2="&Session("Dept2")&" and SK_SystemUsers.SK_Dept3="&Session("Dept3")&" and SK_Linkman.LinkmanID="&trim(str2(i))
elseif Session("Manager")=6 then
sql="select * from SK_Linkman where SK_Del=0 and SK_SalesID="&Session("UID")&" and LinkmanID="&trim(str2(i))
end if
RS.Open Sql,Conn,1,1

Response.Write("<tr bgcolor=FFFFFF>"&VBCrlf)
set RsClient=server.createobject("adodb.recordset")
RsClient.open "SELECT * from SK_Client where ClientID="&Rs("SK_ClientID")&"",conn,1,1
if rsClient.bof and rsClient.eof then
Response.Write("<td align=left></td>")
else
Response.Write("<td align=left>"&RsClient("SK_Wname")&"</td>")
end if
RsClient.close
set RsClient=Nothing

Response.Write("<td align=left>"&Rs("SK_LName")&"</td>")
if Rs("Sex")=0 then
Response.Write("<td align=left>女</td>")
else
Response.Write("<td align=left>男</td>")
end if
if Rs("SK_Age")<>"" then
Response.Write("<td align=left>"&Rs("SK_Age")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Birthday")<>"" then
Response.Write("<td align=left>"&Rs("SK_Birthday")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_LDept")<>"" then
Response.Write("<td align=left>"&Rs("SK_LDept")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_LJob")<>"" then
Response.Write("<td align=left>"&Rs("SK_LJob")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Tel")<>"" then
Response.Write("<td align=left>"&Rs("SK_Tel")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Fax")<>"" then
Response.Write("<td align=left>"&Rs("SK_Fax")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Mobile")<>"" then
Response.Write("<td align=left>"&Rs("SK_Mobile")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Mobile1")<>"" then
Response.Write("<td align=left>"&Rs("SK_Mobile1")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Phone")<>"" then
Response.Write("<td align=left>"&Rs("SK_Phone")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Email")<>"" then
Response.Write("<td align=left>"&Rs("SK_Email")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_QQ")<>"" then
Response.Write("<td align=left>"&Rs("SK_QQ")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_OfficeMsn")<>"" then
Response.Write("<td align=left>"&Rs("SK_OfficeMsn")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_ICQ")<>"" then
Response.Write("<td align=left>"&Rs("SK_ICQ")&"</td>")
else
Response.Write("<td align=left></td>")
end if
if Rs("SK_Address")<>"" then
Response.Write("<td align=left>"&Rs("SK_Address")&"</td>")
else
Response.Write("<td align=left></td>")
end if

set RsOptions=server.createobject("adodb.recordset")
sqlOptions="SELECT * from SK_ClientOptions where SK_Di=1 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsOptions.Open sqlOptions,conn,1,1
for Optionsi=1 to RsOptions.recordCount
Set rsOptionsDetail=Server.CreateObject("ADODB.RecordSet") 
sqlOptionsDetail="SELECT * from SK_ClientOptionsDetail where SK_OptionsID="&RsOptions("FieldID")&" and OptionsDetailID="&rs(""&RsOptions("SK_FieldName")&"")&"" 
rsOptionsDetail.Open sqlOptionsDetail,conn,1,1
if rsOptionsDetail.bof and rsOptionsDetail.eof then
Response.Write("<td align=left></td>")
else
Response.write"<td align=left>"&rsOptionsDetail("SK_OName")&"</td>"
end if
rsOptionsDetail.close
set rsOptionsDetail=Nothing
RsOptions.movenext 
next
RsOptions.close
set RsOptions=Nothing

set RsFields=server.createobject("adodb.recordset")
sqlFields="SELECT * from SK_ClientFields where SK_Di=1 and SK_ShowOnForm=0 Order by SK_OrderID asc"
RsFields.Open sqlFields,conn,1,1
for Fieldsi=1 to RsFields.recordCount
if Rs(""&RsFields("SK_FieldName")&"")<>"" then
Response.write"<td align=left>"&Rs(""&RsFields("SK_FieldName")&"")&"</td>"
else
Response.Write("<td align=left></td>")
end if
RsFields.movenext 
next 
RsFields.close
set RsFields=Nothing

Response.Write("</tr>"&VBCrlf)
next
end if '当选择有ID时输出数据结束

Response.Write("</table>")
Call CloseDB()
'导出联系人到Excel结束
%>