I wanted to be able to load the next event from my event database in an IFRAME on my main page. Here is the code to do it if anyone's interested.
Hope this is of help to someone. See www.bandsman.co.uk to see it in action.
Change view_records in db.cgi:
# --------------------------------------------------------
# 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 (njh@bandsman.co.uk)
if($in{'listnext'}) {
# Suitable for use in an IFRAME
if (!$html_headers_printed) {
print "Content-type: text/html\n\n";
$html_headers_printed = 1;
}
my @match;
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]);
($thisdate > $today) or next LINE;
# TODO: time as well as date
if(($matchdate == 0) || ($thisdate < $matchdate)) {
@match = @values;
$matchdate = $thisdate;
}
($thisdate == $today) and last LINE;
}
close DB;
if($matchdate > 0) {
print "<HTML>";
print "<BODY BGCOLOR=\"#FFFFFF\">";
print "<FONT SIZE=\"2\"><I>Next event:<BR>";
# Print date, desc and URL
print "$match[12]: $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\">$match[1]";
} else {
print "mailto:$match[11]\" target=\"_top\">$match[1]";
}
print "</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);
}
}
}
You then need to mark up the page it's to be included in (in my case my index.htm)
<IFRAME src="cgi-bin/events/db.cgi?uid=default&db=events&listnext=1&view_records=1" ALIGN="center" scrolling="no" frameborder="no"></IFRAME>
</P>--
Nigel Horne. Arranger, Composer, Conductor, Typesetter.
Hope this is of help to someone. See www.bandsman.co.uk to see it in action.
Change view_records in db.cgi:
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 (njh@bandsman.co.uk)
if($in{'listnext'}) {
# Suitable for use in an IFRAME
if (!$html_headers_printed) {
print "Content-type: text/html\n\n";
$html_headers_printed = 1;
}
my @match;
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]);
($thisdate > $today) or next LINE;
# TODO: time as well as date
if(($matchdate == 0) || ($thisdate < $matchdate)) {
@match = @values;
$matchdate = $thisdate;
}
($thisdate == $today) and last LINE;
}
close DB;
if($matchdate > 0) {
print "<HTML>";
print "<BODY BGCOLOR=\"#FFFFFF\">";
print "<FONT SIZE=\"2\"><I>Next event:<BR>";
# Print date, desc and URL
print "$match[12]: $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\">$match[1]";
} else {
print "mailto:$match[11]\" target=\"_top\">$match[1]";
}
print "</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);
}
}
}
You then need to mark up the page it's to be included in (in my case my index.htm)
Code:
<P ALIGN="center"><FONT SIZE="2"> <IFRAME src="cgi-bin/events/db.cgi?uid=default&db=events&listnext=1&view_records=1" ALIGN="center" scrolling="no" frameborder="no"></IFRAME>
</P>
Nigel Horne. Arranger, Composer, Conductor, Typesetter.