radical hacks DBASE Last Modified + Size Hack sent in this excellent hack!

"When updating your database, isn't it a pain to have to manually edit HTML so users can see when the last update was, or how many items are in your database?

This hack inserts these values into your HTML automatically, on as many pages as you wish. It uses the same technique that inserts the correct cart id and page file name into your HTML, for the obligatory hidden variables on every page.

THINGS YOU HAVE TO CHANGE:

*1) in your setup.file: Add the following variable declaration...

@STATSONPAGES=("../yourpage1.htm",
    "../yourpage2.htm",
    "../yourpage3.htm",
    "../yourpage4.htm");

This new array contains the paths + filenames of the HTML pages you want to display the stats on. I'll explain later why we need this.

*2) in all of the HTML files listed in @STATSONPAGES:

Insert the following code where you want the stats to appear...

<B>%%howbigsdb%% Items - Database updated
%%data_lastmod%%.</b>

This introduces two new special tag sequences; %%howbigsdb%% -- how big is the database, i.e. how many records are in it. %%data_lastmod%% -- when the database was last modified.

*3) in webstore.cgi, around ln 2094, underneath the (unique) line ...

s/%%page%%/$form_data{'page'}/g;

...insert the following:

# -----------------START JPW: 060599

    # for each page we want stats on

foreach $dir (@STATSONPAGES) {

    # check to if current page is one of them

    # The above if check is v important cos we
    # dont want to waste time gathering the stats
    # every time a page is served.  Hence our new
    # array of pages we want stats
    # on, @STATSONPAGES, definied in the setup file.

        if (($form_data{'page'}) =~ /^$dir/) { 

    # grab data_file details using perl 'stat'

        ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
            $atime,$mtime,$ctime,$blksize,$blocks)
                = stat($sc_data_file_path); 
    
    # &timetostr is a NEW ROUTINE...

        local ($datalmod) = &timetostr($mtime); 

    # date string inserted, now we get size of dbase

        s/%%data_lastmod%%/$datalmod/g;

        local($howbigsdb,$line);

    # we'll use this variable for counting with

        $howbigsdb = 0; 
        open(DATAVIRTUAL, "$sc_data_file_path") ||
        &file_open_error("$sc_data_file_path",

    # read in datafile line by line

                "Read Database",__VIRTUAL__,__LINE__); 

    # for each line increment our counter by one

        while($line = <DATAVIRTUAL> ) {$howbigsdb++;} 
        close (DATAVIRTUAL);

    # insert the number of records/lines in dbase into HTML page.

        s/%%howbigsdb%%/$howbigsdb/g; 

        } # end if stats required
 } # end foreach STATSONPAGES

# -----------------END JPW

This modifies the display_page Subroutine, which filters the HTML pages through the script to insert the essential %%cart_id%% and %%page%% values in our hidden Form fields. I basically copied this technique to check for the new tag sequences %%howbigsdb%% and %%data_lastmod%% .

My new chunk calls a new, neat little routine called timetostr which converts Unix time formats into much nicer strings like: Mon 10 Jan 1999.

This routine was copied from ice-form.pl, part of the (excellent) text-index based (and very quick) CGI compliant ICE search engine, ICE Version 1.5 beta 3 rev1 (C) Christian Neuss (ice@isa.informatik.th-darmstadt.de). See http://www.informatik.tu-darmstadt.de/~neuss/ice/ice.html.

[BTW guys, i havent checked with the author if its ok to use this routine, but it looks pretty 'generic' to me]

*4) Stick the following routine right at the very end of web_store.cgi

#########################################
#               timetostr               #
#########################################
# JPW NEW ROUTINE 060599 -- converts
# stat() results into a nice string

sub timetostr{
  local($time)=@_;
  local(@timeEntries)=localtime($time);
  local($mday) = $timeEntries[3];
  local($mon) = $timeEntries[4];
  local($year) = $timeEntries[5];
  local($wday) = $timeEntries[6];
  local($weekday)=(Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$wday];
  local($month)=(Jan,Feb,Mar,Apr,May,Jun,
            Jul,Aug,Sep,Oct,Nov,Dec)[$mon];
  local($result)="$weekday $mday $month $year";
  $result;
}
# end timetostr sunroutine

And that's it!