Welcome, Guest ( Customer Panel | Login )




 All Forums
 VPCart Forum
 Add-ons for VP-ASP
 List Products with Missing Images - Freebie
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

StevenWWinters
Starting Member

47 Posts

Posted - January 03 2005 :  20:40:27  Show Profile  Reply with Quote
The code below will display products with missing or default images to allow you to determine what you need to fix. It checks the two standard VPASP images fields and a spare field (pother1) which you could change to something else or delete from the query statement.

Save the text as noimage.asp, make the necessary changes after the line "'===== Make Changes Here =====", and upload to your shop directory.

It has only been used on a shop hosted on Windows and using mysql, but I see no reason it shouldn't work on other platforms/databases.

It may fail for some image references but worked on the ones I tested for. The mappath statement did not respond correctly if the file path began with a period. I used another function to determine the correct path for testing the file existence in that case. If someone knows of a better or method, I'd be interested in seeing it.

Lastly, if you have a very large database with a large number of missing or default images, you will want to place a LIMIT in the SQL query to restrict output.

Enjoy.

Steven W. Winters

==========

<%option explicit%>
<!--#include file="shop$db.asp"-->
<!--#include file="shopfileio.asp"-->
<%
'***************************************************************************
' Display all products with missing images.
' Images are referenced in the 3 fields: cimageurl, extendedimage, pother1.
' References to default images are also displayed so they can be corrected.
' Warning: If you have large number of products with missing or default images
' you will want to place a LIMIT in the SQL statement below.
'
' Steven W. Winters
' December 28, 2004
'*****************************************************************************
Dim dbc

shopopendatabase dbc

HtmlWrapper
ProductsWithNoImages
Response.Write "</body>" & vbCrLF

shopclosedatabase dbc

'***************************************************************************
Sub ProductsWithNoImages
dim sSql, rs
dim i, fso, sFile
dim sNoImage1, sNoImage2, sNoImage3
dim bNoImage1, bNoImage2, bNoImage3
Dim sProdUrl, bShowAll

'===== Make Changes Here =====
bShowAll = False '-- Set to True to display all products.
sProdUrl = "http://www.yourdomain.com/store/shopexd.asp?id="
sNoImage1 = "noimage_s.gif" '-- Name of small default image.
sNoImage2 = "noimage_m.gif" '-- Name of medium default image.
sNoImage3 = "noimage_l.gif" '-- Name of large default image.

'--- Assumes you use pother1 as a 3rd image reference. If you do not, then substitute the name of your
' 3rd image in the SQL statement. If no 3rd image is used, then delete ", pother1" from the SQL
' statement below. Changing the query in any other way may break the code further down.
sSql = "SELECT catalogid, ccode, cname, cimageurl, extendedimage, pother1 FROM products ORDER BY catalogid"

'===== End of Changes ======

response.write "<table border='0' width = '100%' style='border-collapse: collapse'>"
response.write "<tr><td align='center'><font size='6'>Product Image Check</font></td></tr>"
response.write "<tr><td align='center'><font face='Arial' size='3'>"
response.write "--- PRODUCTS WITH MISSING IMAGES ---"
response.write "</font></td></tr>"
response.write "</table><hr>"


set rs=dbc.execute(sSql)

response.write "<table>"

Response.write "<tr>"

For i = 0 To rs.Fields.Count - 1
Response.write "<td align='left'><font size='2'><b>" & rs.Fields(i).Name & "</b></font></td>"
Next

Response.write "<tr>"

set fso = Server.CreateObject("Scripting.FileSystemObject")

Do While Not rs.eof

bNoImage1 = isBadLink(fso, rs(3), sNoImage1)
bNoImage2 = isBadLink(fso, rs(4), sNoImage2)

If rs.Fields.Count = 6 Then '-- If a 3rd image is used, there will be 6 fields in the query.
bNoImage3 = isBadLink(fso, rs(5), sNoImage3)
Else
bNoImage3 = False '-- If not, ignore the test for the 3rd image.
End If

If (bNoImage1 Or bNoImage2 Or bNoImage3) Or bShowAll Then

Response.write "<tr>"

For i = 0 To rs.Fields.Count - 1
Select Case i
Case 3
TDon(bNoImage1)
Case 4
TDon(bNoImage2)
Case 5
TDon(bNoImage3)
Case Else
Response.Write "<td align='left'>"
End Select

Response.Write "<font size='1'>"

Select Case i
Case 0, 1, 2
Response.Write "<a href='" & sProdUrl & rs(0) & "' target='_blank' >"
Response.Write rs(i)
Response.Write "</a>"
Case 3, 4, 5
Response.Write "<a href='" & rs(i) & "' target='_blank'>"
Response.Write rs(i)
Response.Write "</a>"

Case Else
Response.Write rs(i)
End Select

Response.Write "</font></td>"
Next

Response.Write "</tr>"
Response.Write vbCrLf

End If

rs.Movenext
Loop

Response.Write "</table>"

closerecordset rs

End Sub

Function isBadLink(oFS, sFileSpec, sNoImage)
dim sFile
dim sHomePath, sBasePath

sHomePath = server.mappath("/")
sBasePath = oFS.GetAbsolutePathName(".")

isBadLink = False

If LCase(Right(sFileSpec, Len(sNoImage))) = sNoImage Then
isBadLink = True
Exit Function
End If

If IsNull(sFileSpec) Then
isBadLink = True
Exit Function
Else
If Left(sFileSpec,1) = "." Then
sFile = oFS.GetAbsolutePathName(sFileSpec)
sFile = Replace(sFile, sBasePath, sHomePath)
Else
sFile = server.mappath(sFileSpec)
End If

If Not oFS.FileExists (sFile) Then
isBadLink = True
Exit Function
End If
End If
End Function

Sub TDon(bNoImage)
If bNoImage = True Then
Response.Write "<td align='left' bgcolor='#FFFFB0'>"
Else
Response.Write "<td align='left'>"
End If
End Sub

Sub HtmlWrapper()
Response.Write "<html>" & vbCrLF
Response.Write "<head>" & vbCrLF
Response.Write "<meta http-equiv='Content-Type' content='text/html; charset=windows-1252'>" & vbCrLF
Response.Write "<title>Product Image Check</title>" & vbCrLF
Response.Write "<style TYPE='text/css'>" & vbCrLF
Response.Write "<!--" & vbCrLF
Response.Write "}" & vbCrLF
Response.Write "A:link {" & vbCrLF
Response.Write " color: #000000;" & vbCrLF
Response.Write " text-decoration: none;" & vbCrLF
Response.Write "}" & vbCrLF
Response.Write "A:visited {" & vbCrLF
Response.Write " color: #202020;" & vbCrLF
Response.Write " text-decoration: none;" & vbCrLF
Response.Write "}" & vbCrLF
Response.Write "A:active {" & vbCrLF
Response.Write " color: #000000;" & vbCrLF
Response.Write " text-decoration: none;" & vbCrLF
Response.Write "}" & vbCrLF
Response.Write "A:hover {" & vbCrLF
Response.Write " color: #b03030;" & vbCrLF
Response.Write " text-decoration: underline;" & vbCrLF
Response.Write "}" & vbCrLF
Response.Write "-->" & vbCrLF
Response.Write "</style>" & vbCrLF
Response.Write "</head>" & vbCrLF
Response.Write "<body>" & vbCrLF
End Sub
%>





Edited by - StevenWWinters on January 03 2005 20:41:57

Edited by - StevenWWinters on January 03 2005 20:42:56

Edited by - StevenWWinters on January 03 2005 20:44:18

sek
Starting Member

24 Posts

Posted - February 22 2005 :  02:43:25  Show Profile  Reply with Quote
thanks much for sharing

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
Snitz Forums 2000
0 Item(s)
$0.00