Posts filed under 'Programming'

osCommerce - CRE Loaded - Remove Google Ad in the footer

If you want to remove the Google Ads that CRE Loaded adds to the footer, and ahem.. hides them so well..  edit this file: 

/includes/javascript/cart_links.js.php

Comment out or delete the last four lines before the end php tag (?>).   I won’t write out the entire code, as my blogging software (WordPress) is a little funky with the code I wanted to paste.

Comment out the lines (pseudo-code):

//echo 'table...'
//echo ‘td…’
//echo include(’http://creloaded.com/cre_google.js’);
//echo ‘/td
 

You’ll see the include statement getting the Google Ads from creloaded.com. 

Better yet! Get your own Google Ads on there.

If you do it right, you can integrate the ads well enough so it looks to be in place.

33 comments July 11th, 2006

osCommerce - How to make a dealer only site

I was running myself stupid searching for a way to make osCommerce into a dealer only site.  I didn’t need much, I just wanted users that weren’t logged in to not be able to see much.  I wanted unauthenticated users to only be able to see the login page (of course), the FAQ, Contact page, and a few information pages.

There are other osCommerce contributions that feature different pricing per customer and stuff like that.  But I think there are a lot of people like me that just needed to restrict access to the prices, product info and such.

I’ve got a bit of a caveat.  I am running CRE Loaded 6.2.  I’m sure it’s fairly simple to find the file this code should be in with a standard osCommerce install.

Here are the modifications:

In file [/templates/Original/header.php]:

at about line 18, just after this line of code:

if (DOWN_FOR_MAINTENANCE_HEADER_OFF =='false') {

 

Add this code:

//CUSTOM FOR DEALER ONLY SITE!!
if (!tep_session_is_registered('customer_id')) {
 switch($_SERVER['REQUEST_URI']) {
  case '/login.php':
  case '/login.php?action=process';
  case '/contact_us.php':
  case '/links.php':
  case '/information.php?info_id=1':
  case '/information.php?info_id=2':
  case '/information.php?info_id=3':
  case '/login.php':   
  case '/password_forgotten.php':   
   break;
  default:
   header('Location: /login.php');
   break;
 }

You’ll likely want to modify the list of ‘allowable’ files, but this should be a great start if you want simple dealer only or a dealer portal osCommerce application.

2 comments July 7th, 2006

Class to create thumbnail images (VB.Net, GDI.Net)

A class written in VB.Net using GDI.net to create thumbnail images and stream or save them as JPG.

Public Class JPGThumbnail
 
    Private Enum Method
        File
        Stream
    End Enum
 
    Private Sub New()
    End Sub
 
    Public Shared Sub CreateThumbnail(ByVal InputFilePath As String, _
                ByVal intMaxLen As Integer, _
                ByVal OutputStream As IO.Stream)
        CreateThumbnail(InputFilePath, intMaxLen, Method.Stream, , OutputStream)
    End Sub

    Public Shared Sub CreateThumbnail(ByVal InputFilePath As String, _
                    ByVal intMaxLen As Integer, _
                    ByVal OutputFilePath As String)
        CreateThumbnail(InputFilePath, intMaxLen, Method.File, OutputFilePath)
    End Sub
 
    Private Shared Sub CreateThumbnail(ByVal InputFilePath As String, _
                    ByVal intMaxLen As Integer, _
                    ByVal ThumbnailMethod As Method, _
                    Optional ByVal OutputFilePath As String = "", _
                    Optional ByVal OutputStream As IO.Stream = Nothing)
        Dim fileInfo As New IO.FileInfo(InputFilePath)
 
        If fileInfo.Exists() Then
 
            Dim bmp As System.Drawing.Bitmap
            Dim bmpThumb As System.Drawing.Bitmap
 
            Try
                bmp = New System.Drawing.Bitmap(InputFilePath)
                Dim intWidth As Integer = bmp.Width
                Dim intHeight As Integer = bmp.Height
                Dim intThumbWidth As Integer
                Dim intThumbHeight As Integer
 
                If intWidth > intHeight Then
                    intThumbWidth = intMaxLen
                    intThumbHeight = (intHeight / intWidth) * intMaxLen
                Else
                    intThumbHeight = intMaxLen
                    intThumbWidth = (intWidth / intHeight) * intMaxLen
                End If
 
                Dim thumbSize As New Drawing.Size(intThumbWidth, intThumbHeight)
                bmpThumb = New System.Drawing.Bitmap(bmp, thumbSize)
 
                If intMaxLen >= intHeight Or intMaxLen >= intWidth Then
                    ‘ Save the original
                    If ThumbnailMethod = Method.File Then
                        bmp.Save(OutputFilePath, System.Drawing.Imaging.ImageFormat.Jpeg)
                    Else
                        bmp.Save(OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
                    End If
                Else
                    ‘ Save the thumbnail version
                    If ThumbnailMethod = Method.File Then
                        bmpThumb.Save(OutputFilePath, System.Drawing.Imaging.ImageFormat.Jpeg)
                    Else
                        bmpThumb.Save(OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg)
                    End If
 
                End If
 
            Catch ex As Exception
                Throw
                ‘WriteErrorMsg(OutputFilePath)
            Finally
                ‘clean-up…
                bmp.Dispose()
                bmpThumb.Dispose()
            End Try
 

        Else
            Throw New ApplicationException(”Input file [” & InputFilePath & ”] does not exist.”)
        End If
 
    End Sub

    ‘* This can be used to return an image even in an error condition, if that’s what you want.
    ‘Private Shared Sub WriteErrorMsg(ByVal OutputFilePath As String)
 
    ‘    Dim bmp As New System.Drawing.Bitmap(100, 100, System.Drawing.Imaging.PixelFormat.Format16bppRgb565)
    ‘    ’ Get the underlying Graphics object.
    ‘    Dim gr As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(bmp)
    ‘    ’ Clear its background.
    ‘    gr.Clear(System.Drawing.Color.WhiteSmoke)
 
    ‘    ’ create a font
    ‘    Dim fnt As New System.Drawing.Font(”Arial”, 8, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point)
 
    ‘    gr.DrawString(”Not”, fnt, System.Drawing.Brushes.Blue, 36, 30)
    ‘    gr.DrawString(”Available”, fnt, System.Drawing.Brushes.Blue, 23, 50)
 
    ‘    Dim penRect As New System.Drawing.Pen(Color.LightBlue, 2)
    ‘    gr.DrawRectangle(penRect, 1, 1, 98, 98)
 
    ‘    ’ Release resources.
    ‘    fnt.Dispose()
    ‘    gr.Dispose()
 
    ‘    bmp.Save(OutputFilePath, System.Drawing.Imaging.ImageFormat.Jpeg)
    ‘    bmp.Dispose()
    ‘End Sub
 

End Class

Note: ‘Code to make use of it…
JPGThumbnail.CreateThumbnail(”C:\DCP02396.JPG”, 100, “C:\DCP02396_small.JPG”)
Dim outputStream As New IO.FileStream(”C:\DCP02396_small2.jpg”, IO.FileMode.CreateNew)
JPGThumbnail.CreateThumbnail(”C:\DCP02396.JPG”, 100, outputStream)
outputStream.Flush()
outputStream.Close()

1 comment January 22nd, 2006

VB Script to list all running processes including the folder they are running from

Every wonder about all those processes in the Task Manager list of processes are? This is a quick and dirty way of getting a list of those processes, the file they’re running, and a number of other attributes.

I find it very useful to know the path and filename that is creating the processes in the list.

This is one way.. like I said, quick and dirty.. to detect and possibly help remove spyware, adware, and malware in general.  It’s also useful to help debug system performance issues.

On Error Resume Next
Dim LOG_FILE
Dim strYear, strMonth, strDay, intChangedNotes
strYear = Year(Now())
strMonth = Month(Now())
strDay = Day(Now())
LOG_FILE = "Processes_" & strYear & PadLeftZero(strMonth, 2) & PadLeftZero(strDay, 2) & ".txt"

s = ""
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_Process",,48)
For Each objItem in colItems
s = s & vbCrLf & "-------------------------------------" & vbCrLf
s = s & "Caption: " & objItem.Caption & vbcrlf
s = s & "ExecutablePath: " & objItem.ExecutablePath & vbcrlf
s = s & "ProcessId: " & objItem.ProcessId & vbcrlf
s = s & "ParentProcessId: " & objItem.ParentProcessId & vbcrlf
s = s & "WorkingSetSize: " & objItem.WorkingSetSize & vbcrlf
s = s & "Mem Usage: " & objItem.WorkingSetSize/1024 & " K" & vbcrlf
s = s & vbCrLf & vbCrLf
Next

WriteToFile s, LOG_FILE

WScript.Echo "Done."

Function PadLeftZero(ByVal istrExpression, ByVal iintMaxLen)

PadLeftZero = PadLeft(istrExpression, "0", iintMaxLen)

End Function

Public Function PadLeft(ByVal istrSource, ByVal istrPadChar, ByVal iintMaxLen)
' Append istrSource to the end of a string of istrPadChar and return
' a string no longer than iintMaxLen.
PadLeft = Right(String(iintMaxLen, Left(istrPadChar, 1)) & istrSource, iintMaxLen)
End Function

Sub WriteToFile(istrNote, istrLogFile)
Const ForReading = 1, ForWriting = 2, ForAppending = 8

dim objFSO
dim objFile
dim objTS

set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(istrLogFile, ForWriting, True)
objTS.WriteLine istrNote
objTS.Close
set objTS = Nothing
set objFSO = Nothing
End Sub

Note: This script writes the results to a file, but you could just as easily do a WScript.Echo of each process you're interested in.

Note: This script writes the results to a file, but you could just as easily do a WScript.Echo of each process you're interested in.

 

2 comments January 20th, 2006

Attach a file to an email with VBScript

A VBScript that sends an email with a file attachment.   I’ve used this in Windows 2000 (Win2K) and Windows XP Pro (XP Pro) environments.eg. Drag a file from explorer onto the icon for this script and it will send that file as an attachment to the email address you specify.

eg. Or.. incorporate it into an automated process by passing the filename and email address as parameters. This is useful if you want to send a file with a scheduled task or job.

Dim oArgs, i, sSubject, sBody, sEmail
Dim fromEmail, fileName, toEmail, smtpServer
 

smtpServer = ""
fromEmail = "Daemon@domain.com"

Set oArgs = WScript.Arguments

If oArgs.Count < 1 Then
     WScript.Echo "Drag a file onto this icon to email it." & vbcrlf & vbcrlf & "You will be prompted for an email address to send to."
     WScript.Quit
End If

fileName = oArgs(0)

If oArgs.Count <> 2 Then
     toEmail = InputBox(”Please type in the recipient’s email:”, “Send to?”, “;@domain.com”)
Else
     toEmail = oArgs(1)
End If

if fileName <> “” and fromEmail <> “” and toEmail <> “” then

     sSubject = “File from [” & fromEmail & “]”
     sBody = “See attached file [” & GetFilenameOnly(fileName) & “]”
     sEmail = toEmail
     
     MailMe_CDOSys sSubject, sBody, sEmail, fileName
     If oArgs.Count <> 2 Then WScript.Echo “Mail sent…”

else
     If oArgs.Count <> 2 Then WScript.Echo “Incorrect parameters.. no email sent”

end if

Sub MailMe_CDOSYS (s, b, email, attachment)
     On Error Resume Next
     Dim o
     Set o = CreateObject(”CDO.Message”)
     o.From = fromEmail
     o.Sender = “MailMeAttachment”
     o.To = email
     o.Subject = s
     o.AddAttachment fileName
     o.TextBody = b
     o.DNSOptions = 0
     o.ConfigurationFields(”http://schemas.microsoft.com/cdo/configuration/smtpserver”).Value = smtpServer
     o.ConfigurationFields(”http://schemas.microsoft.com/cdo/configuration/sendusing”).Value = 2     ’send using network
     o.ConfigurationFields(”http://schemas.microsoft.com/cdo/configuration/SMTPConnectionTimeout”).Value = 30
     o.ConfigurationFields(”http://schemas.microsoft.com/cdo/configuration/SMTPServerPort”).Value = 25
     o.ConfigurationFields(”http://schemas.microsoft.com/cdo/configuration/SMTPAuthenticate”).Value = 0
     o.Configuration.Fields.Update
     o.Fields.Update
     o.send
     Set o = Nothing
End Sub

Function GetFilenameOnly(s)
     Dim sRet, iLast
     iLast = InStrRev(s, “\”)
     sRet = Right(s, len(s)-iLast)
     GetFilenameOnly = sRet
End Function

Add comment January 19th, 2006

VB Script / Windows Script function used to log to the application event log

Here is a very useful set of functions if you want to log to the application event log in Windows.  I’ve used it on scheduled scripts, jobs, HTA (HTML Application).

You can call the LogEvent function with a string that you want to place in the application event log.  This defaults as an information event.  You can optionally call the LogEvent_ex, LogEventAudit, or LogEventAuditFail functions to specify a different event type.  Enjoy!

Sub LogEvent (sNote)
     LogEvent_Ex 4, sNote
end sub

Sub LogEventAudit (sNote)
     LogEvent_Ex 8, sNote
End Sub

Sub LogEventAuditFail (sNote)
     LogEvent_Ex 16, sNote
End Sub

Sub LogEvent_Ex(i, sNote)
     ‘*Constants:
     ‘     1=Error
     ‘     2=Warning
     ‘     4=Information
     ‘     8=Audit Success
     ‘     16=Audit Failure

     dim ws
     set ws = CreateObject(”WScript.Shell”)
     ws.LogEvent i, sNote
     set ws = Nothing
End Sub

Add comment January 17th, 2006

Indexing Service Details (as HTML report)

This script generates an HTML report sent by email of the status and health of specified MS Indexing Service catalogs using a COM object in VBScript.

MS Content Index Service (CISVC) can be accessed through the object Microsoft.ISAdm.

Download the script to generate the CISVC report

Add comment January 16th, 2006

Time Lapse movie generator (MakeAVI 0.12)

Want to take a bunch of web cam images and create a time lapse movie? Here’s the app for you.. it’s Open Source (GPL).

I didn’t write the app to begin with, I’ve only fixed a bug/issue with how it was getting the list of files.

MakeAVI converts a series of images into an AVI movie.  This is the source code and compiled applicataion for a fixed version.  The fix is for the number of photos that can be opened, there was a fixed buffer for the file names.

It works very well..

Download the Source Code

Download the compiled Application

2 comments September 16th, 2005


Calendar

August 2008
M T W T F S S
« May    
 123
45678910
11121314151617
18192021222324
25262728293031

Posts by Month

Posts by Category