File: D:/web/homefly/vsadmin/inc/incsearch.asp
<%
Dim sSQL,rs,rs2,alldata,cnn,useEuro,rowcounter,success,Count,startlink,endlink,weburl,CurPage,iNumOfPages,netnav,subCats,lasttsid,sText,index,sJoin,aText,aFields(3),aOption()
showcategories=FALSE
gotcriteria=FALSE
Redim aOption(2,maxprodopts)
netnav = true
if instr(Request.ServerVariables("HTTP_USER_AGENT"), "compatible") > 0 OR instr(Request.ServerVariables("HTTP_USER_AGENT"), "Gecko") > 0 then netnav = false
function atb(size)
if netnav then
atb = CInt(size / 2 + 1)
else
atb = size
end if
end function
Function writepagebar(CurPage, iNumPages)
Dim sLink, i, sStr, startPage, endPage
sLink = "<a href='"&request.servervariables("url")&"?scat="&request("scat")&"&stext="&replace(request("stext")," ","+")&"&stype="&request("stype")&"&sprice="&replace(request("sprice")," ","+")&"&pg="
startPage = Max(1,CInt(Int(CDbl(CurPage)/10.0)*10))
endPage = Min(iNumPages,CInt(Int(CDbl(CurPage)/10.0)*10)+10)
if CurPage > 1 then
sStr = sLink & "1" & "'><b><font face='Verdana'>«</font></b></a> " & sLink & CurPage-1 & "'>"&xxPrev&"</a> | "
else
sStr = "<b><font face='Verdana'>«</font></b> "&xxPrev&" | "
end if
for i=startPage to endPage
if i=CurPage then
sStr = sStr & i & " | "
else
sStr = sStr & sLink & i & "'>"
if i=startPage AND i > 1 then sStr=sStr&"..."
sStr = sStr & i
if i=endPage AND i < iNumPages then sStr=sStr&"..."
sStr = sStr & "</a> | "
end if
next
if CurPage < iNumPages then
writepagebar = sStr & sLink & CurPage+1 & "'>"&xxNext&"</a> " & sLink & iNumPages & "'><b><font face='Verdana'>»</font></b></a>"
else
writepagebar = sStr & " "&xxNext&" <b><font face='Verdana'>»</font></b>"
end if
End function
Set rs = Server.CreateObject("ADODB.RecordSet")
Set rs2 = Server.CreateObject("ADODB.RecordSet")
Set cnn=Server.CreateObject("ADODB.Connection")
cnn.open sDSN
sSQL = "SELECT adminEmail,adminStoreURL,adminProdsPerPage,adminSubCats,countryLCID,countryCurrency,countryTax,adminStockManage,currRate1,currSymbol1,currRate2,currSymbol2,currRate3,currSymbol3,currConvUser,currConvPw,currLastUpdate FROM admin INNER JOIN countries ON admin.adminCountry=countries.countryID WHERE adminID=1"
rs.Open sSQL,cnn,0,1
countryCurrency = rs("countryCurrency")
useEuro = (countryCurrency="EUR")
useStockManagement = rs("adminStockManage")<>0
adminProdsPerPage = rs("adminProdsPerPage")
if rs("countryLCID")<>0 then Session.LCID = rs("countryLCID")
subCats=(Int(rs("adminSubCats"))=1)
countryTax=cDbl(rs("countryTax"))
currRate1=cDbl(rs("currRate1"))
currSymbol1=trim(rs("currSymbol1"))
currRate2=cDbl(rs("currRate2"))
currSymbol2=trim(rs("currSymbol2"))
currRate3=cDbl(rs("currRate3"))
currSymbol3=trim(rs("currSymbol3"))
currConvUser=rs("currConvUser")
currConvPw=rs("currConvPw")
currLastUpdate=rs("currLastUpdate")
rs.Close
Call checkCurrencyRates(currConvUser,currConvPw,currLastUpdate,currRate1,currSymbol1,currRate2,currSymbol2,currRate3,currSymbol3)
if subCats then
sSQL = "SELECT DISTINCT sectionID,sectionName,tsID,tsName FROM topsections INNER JOIN sections ON sections.topSection=topsections.tsID ORDER BY tsName,sectionName"
else
sSQL = "SELECT DISTINCT sectionID,sectionName FROM sections ORDER BY sectionName"
end if
rs.Open sSQL,cnn,0,1
if rs.eof or rs.bof then
success=false
else
alldata=rs.getrows
success=true
end if
rs.Close
if Request.Form("posted")="1" OR Request.QueryString("pg")<>"" then
if request("scat")<>"" then
sSQL = "SELECT DISTINCT products.pId,pName,pPrice FROM multiSections RIGHT JOIN (products LEFT OUTER JOIN sections ON products.pSection=sections.sectionID) ON products.pId=multiSections.pId WHERE pDisplay <> 0 "
gotcriteria=true
if Left(request("scat"),2)="ts" then
sectionids="0"
rs.Open "SELECT sectionID FROM sections where topSection=" & Right(request("scat"),Len(request("scat"))-2),cnn,0,1
do while NOT rs.EOF
sectionids = sectionids & "," & rs("sectionID")
rs.MoveNext
loop
rs.Close
sSQL = sSQL & "AND (topSection="&Right(request("scat"),Len(request("scat"))-2)&" OR multiSections.pSection IN (" & sectionids & ")) "
else
sSQL = sSQL & "AND (products.pSection="&Right(request("scat"),Len(request("scat"))-2)&" OR multiSections.pSection="&Right(request("scat"),Len(request("scat"))-2)&") "
end if
else
sSQL = "SELECT products.pId,pName,pPrice FROM products LEFT OUTER JOIN sections ON products.pSection=sections.sectionID WHERE pDisplay <> 0 "
end if
if Trim(request("sPrice"))<>"" AND IsNumeric(Trim(request("sPrice"))) then
gotcriteria=true
sSQL = sSQL & "AND pPrice<="&replace(request("sPrice"),"$","")&" "
end if
if Trim(request("stext"))<>"" then
gotcriteria=true
sText = replace(Trim(request("stext")),"'","''")
aText = Split(sText)
aFields(0)="products.pId"
aFields(1)="pName"
aFields(2)="pDescription"
aFields(3)="pLongDescription"
if request("stype")="exact" then
sSQL=sSQL & "AND (products.pId LIKE '%"&sText&"%' OR pName LIKE '%"&sText&"%' OR pDescription LIKE '%"&sText&"%' OR pLongDescription LIKE '%"&sText&"%') "
else
sJoin="AND "
if request("stype")="any" then sJoin="OR "
sSQL=sSQL & "AND ("
for index=0 to 3
sSQL=sSQL & "("
for rowcounter=0 to UBOUND(aText)
sSQL=sSQL & aFields(index) & " LIKE '%"&aText(rowcounter)&"%' "
if rowcounter<UBOUND(aText) then sSQL=sSQL & sJoin
next
sSQL=sSQL & ") "
if index < UBOUND(aFields) then sSQL=sSQL & "OR "
next
sSQL=sSQL & ") "
end if
end if
if sortBy=2 then
sSortBy = " ORDER BY products.pId"
elseif sortBy=3 then
sSortBy = " ORDER BY pPrice"
elseif sortBy=4 then
sSortBy = " ORDER BY pPrice DESC"
elseif sortBy=5 then
sSortBy = ""
else
sSortBy = " ORDER BY pName"
end if
if NOT gotcriteria then sSQL = "SELECT products.pId FROM products WHERE pDisplay<>0"
rs.CursorLocation = 3 ' adUseClient
rs.CacheSize = adminProdsPerPage
rs.Open sSQL & sSortBy, cnn
if rs.eof or rs.bof then
success=false
iNumOfPages=0
else
success=true
rs.MoveFirst
rs.PageSize = adminProdsPerPage
If Request.QueryString("pg") = "" Then
CurPage = 1
Else
CurPage = Int(Request.QueryString("pg"))
End If
iNumOfPages = Int((rs.RecordCount + (adminProdsPerPage-1)) / adminProdsPerPage)
rs.AbsolutePage = CurPage
end if
Count = 0
if NOT rs.EOF then
prodlist = ""
addcomma=""
Do While Not rs.EOF And Count < rs.PageSize
prodlist = prodlist & addcomma & "'" & rs("pId") & "'"
rs.MoveNext
Count = Count + 1
addcomma=","
loop
rs.Close
Count = 0
sSQL = "SELECT pId,pName,pImage,pPrice,pListPrice,pSection,pSell,pInStock,pLargeImage,topSection,pDescription,pLongDescription FROM products LEFT OUTER JOIN sections ON products.pSection=sections.sectionID WHERE pId IN (" & prodlist & ")" & sSortBy
rs.Open sSQL, cnn, 0, 1
end if
end if
%>
<br>
<table border="0" cellspacing="0" cellpadding="0" width="<%=maintablewidth%>" bgcolor="#B1B1B1" align="center">
<form method="post" action="search.asp">
<tr>
<td width="100%">
<input type="hidden" name="posted" value="1">
<table width="100%" border="0" bordercolor="#B1B1B1" cellspacing="1" cellpadding="3" bgcolor="#B1B1B1">
<tr>
<td align="center" colspan="4" bgcolor="#EBEBEB">
<b><%=xxSrchPr%></b>
</td>
</tr>
<tr>
<td width="25%" align="right" bgcolor="#EBEBEB"><%=xxSrchFr%>:</td>
<td width="25%" bgcolor="#FFFFFF"><input type="text" name="stext" size="<%=atb(20)%>" value="<%=request("stext")%>"></td>
<td width="25%" align="right" bgcolor="#EBEBEB"><%=xxSrchMx%>:</td>
<td width="25%" bgcolor="#FFFFFF"><input type="text" name="sprice" size="<%=atb(10)%>" value="<%=request("sprice")%>"></td>
</tr>
<tr>
<td width="25%" align="right" bgcolor="#EBEBEB"><%=xxSrchTp%>:</td>
<td width="25%" bgcolor="#FFFFFF"><select name="stype" size="1">
<option value=""><%=xxSrchAl%></option>
<option value="any" <% if request("stype")="any" then response.write "selected"%>><%=xxSrchAn%></option>
<option value="exact" <% if request("stype")="exact" then response.write "selected"%>><%=xxSrchEx%></option>
</select>
</td>
<td width="25%" align="right" bgcolor="#EBEBEB"><%=xxSrchCt%>:</td>
<td width="25%" bgcolor="#FFFFFF">
<select name="scat" size="1">
<option value=""><%=xxSrchAC%></option>
<%
lasttsid = -1
FOR rowcounter=0 TO ubound(alldata,2)
if subCats then
if lasttsid <> alldata(2,rowcounter) then
lasttsid = alldata(2,rowcounter)
response.write "<option value='ts"&alldata(2,rowcounter)&"'"
if Left(request("scat"),2)="ts" then
if Int(Right(request("scat"),Len(request("scat"))-2))=alldata(2,rowcounter) then response.write " selected"
end if
response.write ">"&alldata(3,rowcounter)&"</option>"
end if
end if
response.write "<option value='ms"&alldata(0,rowcounter)&"'"
if Left(request("scat"),2)="ms" then
if Int(Right(request("scat"),Len(request("scat"))-2))=alldata(0,rowcounter) then response.write " selected"
end if
response.write "> » "&alldata(1,rowcounter)&"</option>"
next
%>
</select>
</td>
</tr>
<tr>
<td bgcolor="#EBEBEB"> </td>
<td bgcolor="#FFFFFF" colspan="3"><table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td bgcolor="#FFFFFF" width="66%" align="center"><input type="submit" value="<%=xxSearch%>"></td>
<td bgcolor="#FFFFFF" width="34%" height="26" align="right" valign="bottom"><img src="images/tablebr.gif"></td>
</tr>
</table></td>
</tr>
</table>
</td>
</tr>
</form>
</table>
<%
if request.form("posted")="1" OR Request.QueryString("pg")<>"" then
%>
<table border="0" cellspacing="<%=maintablespacing%>" cellpadding="<%=maintablepadding%>" width="<%=maintablewidth%>" bgcolor="<%=maintablebg%>" align="center">
<%
if rs.EOF then
%>
<tr>
<td align="center">
<p> </p>
<p><b><%=xxSrchNM%></b></p>
<p> </p>
</td>
</tr>
<%
else
%>
<tr>
<td width="100%">
<% if usesearchbodyformat=2 then %>
<!--#include file="incproductbody2.asp"-->
<% else %>
<!--#include file="incproductbody.asp"-->
<% end if %>
</td>
</tr>
<%
end if
%>
</table>
<%
rs.Close
end if
cnn.Close
%>