Gossamer Forum
Home : Products : DBMan : Customization :

Re: [njh] Listing the next event in an IFRAME (Code included for db.cgi)

Quote Reply
Re: [njh] Listing the next event in an IFRAME (Code included for db.cgi) In reply to
I've fixed a few bugs:

1) Events on today did not appear
2) The character set and language were not set
3) The last-modified HTTP attribute was not set.

To fix you will need to add this to the top of db.cgi:
Code:
use Time::Local; # NJH

Then modify view_records thus:

Code:
sub view_records {
# --------------------------------------------------------
# This is called when a user is searching the database for
# viewing. All the work is done in query() and the routines just
# checks to see if the search was successful or not and returns
# the user to the appropriate page.

# NJH
if($in{'listnext'}) {
# Suitable for use in an IFRAME

my @match;

my $mostrecent = 0;
my @mostrecentdate;
my $today = &date_to_unix(&get_date(time()));
my $matchdate = 0;

open (DB, "<$db_file_name") or &cgierr("error in search. unable to open database: $db_file_name.\nReason: $!");
if ($db_use_flock) { flock(DB, 1); }
LINE: while (<DB>) {
(/^#/) and next LINE; # Skip comment Lines.
(/^\s*$/) and next LINE; # Skip blank lines.
my $line = $_; chomp ($line); # Remove trailing new line.
my @values = &split_decode($line);

# Ignore any before today, 12 is my date field
my $thisdate = &date_to_unix($values[12]);

if($thisdate >= $today) {
# TODO: time as well as date
if(($matchdate == 0) || ($thisdate < $matchdate)) {
@match = @values;
$matchdate = $thisdate;

# TODO: if there's more than one on
# the same day pick one in random
last LINE if($thisdate == $today);
}
} else {
if(($mostrecent == 0) || ($thisdate > $mostrecent)) {
$mostrecent = $thisdate;
@mostrecentdate = @values;
}
}
}

close DB;

if($matchdate > 0) {
if (!$html_headers_printed) {
# print Last-Modified based on the most recent
# entry
print "Content-type: text/html; charset=ISO-8859-1\n";

if($mostrecent > 0) {
my ($dd, $mmm, $yy) = ($mostrecentdate[12] =~ /(\d+)-([A-Z][a-z][a-z])-(\d+)/);
my %months = (
"Jan" => 0,
"Feb" => 1,
"Mar" => 2,
"Apr" => 3,
"May" => 4,
"Jun" => 5,
"Jul" => 6,
"Aug" => 7,
"Sep" => 8,
"Oct" => 9,
"Nov" => 10,
"Dec" => 11);

my $mm = $mostrecentdate[6]; # mins
my $hh = $mostrecentdate[7]; # hours

$mostrecent = timelocal(0, $mm, $hh, $dd, $months{$mmm}, $yy - 1900);
my $mtime = localtime $mostrecent;
print "Last-Modified: $mtime\n";
}
print "\n";
$html_headers_printed = 1;
if ($ENV{'REQUEST_METHOD'} eq 'HEAD') {
return;
}
}

# Print date, desc and URL
print "<HTML LANG=\"en-GB\"><BODY BGCOLOR=\"#FFFFFF\">";
print "<FONT SIZE=\"2\"><I>";
print "<A HREF=\"$db_script_link_url&view_records=1&ID=$match[0]\" target=\"_top\">";
print "$match[12]</A>: $match[2]<BR>";

print "<A HREF=";

if ($match[9] ne "") {
my $url = $match[9];

$url =~ s/^http:\/\///;

print "\"../bbl2.cgi?redir=$url&address=";
print "$match[11]\" target=\"_top\"";
} else {
print "\"mailto:$match[11]\"";
}
print ">$match[1]</A></FONT></I></BODY></HTML>\n";
}
} else {
my ($status, @hits) = &query("view");
if ($status eq "ok") {
&html_view_success(@hits);
}
else {
&html_view_failure($status);
}
}
}
--
Nigel Horne. Arranger, Composer, Conductor, Typesetter.
Subject Author Views Date
Thread Listing the next event in an IFRAME (Code included) njh 2067 Aug 23, 2002, 7:23 AM
Post Re: [njh] Listing the next event in an IFRAME (Code included for db.cgi)
njh 2001 Aug 28, 2002, 1:29 AM