%@ Language=VBScript %> <% '------------------FOR DEMO USE ONLY---------------------------------- '-------- Copyright by Artem Saveliev artem@savelev.com -------------- '--------------------------------------------------------------------- Server.ScriptTimeout = 600 if cint(session("userlevel"))<3 then Response.Redirect "/admin/index.asp?pgname="&Request.ServerVariables("URL") end if %> <% dim add,remove,references add = false remove = false set con = getcon() con.CommandTimeout = 600 if Request.Form("add") <> "" then add = true elseif Request.Form("remove") <> "" then remove = true end if if add or remove then if Request.Form("reference") <> "" then references = split(Request.Form("reference"),",") for i = 0 to ubound(references) references(i) = "'"&trim(sqlstr(references(i)))&"'" next references = join(references,",") if add then sql = "select gid into #gids from guser join vendorreferral on xcompid=vendorid "&_ "where referral in ("&references&"); "&_ "exec createcrmids; "&_ "insert into crmprequeue select "&session("guserid")&",contactid from #crmids; drop table #gids;" else sql = "delete from crmprequeue where userid = "&session("guserid")&_ " and exists (select crmdata.contactid from crmprequeue Q join crmdata on Q.contactid=crmdata.contactid "&_ "join guser on datatype = 5 and datavalue = gid join master on xcompid = vendor "&_ "join vendorreferral on xcompid=vendorid and referral in ("&references&") "&_ "where Q.userid = "&session("guserid")&" and crmprequeue.contactid=crmdata.contactid and datatype = 5)" end if end if if Request.Form("naics") <> "" then naics = sqlstr(Request.Form("naics")) if add then sql = "select gid into #gids from guser join master on xcompid=vendor "&_ "where naics like '%"&naics&"%'; "&_ "exec createcrmids; "&_ "insert into crmprequeue select "&session("guserid")&",contactid from #crmids; drop table #gids;" else sql = "delete from crmprequeue where userid = "&session("guserid")&_ " and exists (select crmdata.contactid from crmprequeue Q join crmdata on Q.contactid=crmdata.contactid "&_ "join guser on datatype = 5 and datavalue = gid join master on xcompid = vendor "&_ "where Q.userid = "&session("guserid")&" and crmprequeue.contactid=crmdata.contactid and datatype = 5 and naics like '%"&naics&"%')" end if end if if Request.Form("mail") <> "" or Request.Form("startdate") <> "" or Request.Form("enddate") <> "" then if add then sql = "from crmcontactdata where" if Request.Form("mail") <> "" then sql = sql & " contactsubtype in ("&sqlstr(Request.Form("mail"))&") and" if Request.Form("startdate") <> "" then sql = sql & " contactdate > convert(datetime,'" & sqlstr(Request.Form("startdate")) & "') and" if Request.Form("enddate") <> "" then sql = sql & " contactdate < convert(datetime,'" & sqlstr(dateadd("d",1,Request.Form("enddate"))) & "') and" sql = "insert into crmprequeue select " & session("guserid") & ",contactid " & left(sql,len(sql)-3) else sql = "delete crmprequeue from crmprequeue "&_ "join crmcontactdata on crmprequeue.contactid = crmcontactdata.contactid "&_ "where crmprequeue.userid = "&session("guserid") & " and contacttype=1" if Request.Form("mail") <> "" then sql = sql & " and contactsubtype in ("&sqlstr(Request.Form("mail"))&")" if Request.Form("startdate") <> "" then sql = sql & " and contactdate > convert(datetime,'" & sqlstr(Request.Form("startdate")) & "')" if Request.Form("enddate") <> "" then sql = sql & " and contactdate < convert(datetime,'" & sqlstr(dateadd("d",1,Request.Form("enddate"))) & "')" end if end if if Request.Form("curstatus") <> "" then curstatus = split(Request.Form("curstatus"),",") for i = 0 to ubound(curstatus) curstatus(i) = cint(curstatus(i)) next curstatus = join(curstatus,",") if add then sql = "select gid into #gids from guser join master on xcompid=vendor "&_ "where curstatus in ("&curstatus&"); "&_ "exec createcrmids; "&_ "insert into crmprequeue select "&session("guserid")&",contactid from #crmids; drop table #gids;" else sql = "delete from crmprequeue where " &_ "userid = "&session("guserid") & " and " &_ "contactid in (select crmdata.contactid from crmprequeue Q join crmdata on Q.contactid=crmdata.contactid "&_ "join guser on datatype = 5 and datavalue = gid join master on xcompid = vendor "&_ "where Q.userid = "&session("guserid") &" and datatype = 5 and curstatus in ("&curstatus&"))" end if end if if Request.Form("customsite") <> "" then allbuyers = false sites = split(Request.Form("customsite"),",") for i = 0 to ubound(sites) if sites(i) = "0" then allbuyers = true sites(i) = "'"&trim(sqlstr(sites(i)))&"'" next sites = join(sites,",") if add then if allbuyers then sql = "select gid into #gids from guser "&_ "where xtype='buyer'; "&_ "exec createcrmids; "&_ "insert into crmprequeue select "&session("guserid")&",contactid from #crmids; drop table #gids;" else sql = "select gid into #gids from guser join buyerregistration on gid=userid "&_ "where xtype='buyer' and site in ("&sites&"); "&_ "exec createcrmids; "&_ "insert into crmprequeue select "&session("guserid")&",contactid from #crmids; drop table #gids;" end if else if allbuyers then sql = "delete from crmprequeue where userid = "&session("guserid")&_ " and contactid in (select crmdata.contactid from crmprequeue Q join crmdata on Q.contactid=crmdata.contactid join guser on "&_ "datatype = 5 and datavalue = gid "&_ "where Q.userid="&session("guserid")&" and xtype='buyer')" else sql = "delete from crmprequeue where userid = "&session("guserid")&_ " and contactid in (select crmdata.contactid from crmprequeue Q join crmdata on Q.contactid=crmdata.contactid join guser on "&_ "datatype = 5 and datavalue = gid join buyerregistration on gid=buyerregistration.userid "&_ "where Q.userid="&session("guserid")&" and xtype='buyer' and site in ("&sites&"))" end if end if end if if Request.Form("primeid") <> "" then sites = split(Request.Form("primeid"),",") for i = 0 to ubound(sites) sites(i) = clng(sites(i)) next sites = join(sites,",") if add then sql = "select gid into #gids from guser join prime on xcompid=primeid "&_ "where xtype='primeuser' and primeid in ("&sites&"); "&_ "exec createcrmids; "&_ "insert into crmprequeue select "&session("guserid")&",contactid from #crmids; drop table #gids;" else sql = "delete from crmprequeue where userid = "&session("guserid")&_ " and contactid in (select contactid from crmdata join guser on "&_ "datatype = 5 and datavalue = gid join prime on xcompid=primeid "&_ "where xtype='primeuser' and primeid in ("&sites&"))" end if end if if sql <> "" then if add then on error resume next con.execute("create table #crmids (contactid int)") if err > 0 then con.execute("delete * from #crmids") on error goto 0 end if con.execute(sql) if add then con.execute("drop table #crmids") end if con.close() elseif Request.Form("deleteall") <> "" then sql = "delete from crmprequeue where userid="&session("guserid") con.execute(sql) con.close() end if %>
<%header() call items(0) %>