Gossamer Forum
Home : Products : DBMan : Installation :

DBMan search results in SSI page

Quote Reply
DBMan search results in SSI page
Hi

I have been playing around with SSI and DBMan with the aim of getting the titles of last six items entered into the database to show up on a SSI page and while I've not got it working I have found this out:

If one has JPD's what's new mod one can create a SSI variable for the current date like this:

Code:
<!--#config timefmt="%d-%b-%Y"-->

<!--#set var="DBMAN_DATE" value="${DATE_LOCAL}"-->

And then have the six newest records show up using this:

Code:
<!--#include virtual="/cgi-bin/db.cgi?db=default&uid=default&Date-lt=$DBMAN_DATE&view_records=1&mh=6" -->

However it does not work for records added on the current day :-(

So I've now decided to work with the record ID's - displaying the six highest numbered like this:

Code:
<!--#include virtual="/cgi-bin/db.cgi?db=default&uid=default&keyword=*&mh=6&sb=1&so=ascend&view_records=View+Articles" -->

Now to the point of this post... I want to pull the titles from DBMan into a SSI page but without the HTML headers and footers (but with some of the HTML) and do this with out breaking any other functionality of DBMan.

Could this be done by having a variable in the URI string which is used on the SSI page, say ssi=1, and the not printing some things in sub html_view_success if ssi=1?

I suspect this a daft way of doing it - has anyone else got any good ideas regarding how I could get this working?

Chris




Quote Reply
Re: DBMan search results in SSI page In reply to
You're on your own (or at least with no help from me) regarding SSI. That's one of the many things I know nothing about. Smile

------------------
JPD





Quote Reply
Re: DBMan search results in SSI page In reply to
Wouldn't you just need to create a new subroutine (say sub ssi) that just contains the pertinent information, sending no headers or anything? All SSI will do is include the data delivered by the script, so it shouldn't have any ill-effects?

adam
Quote Reply
Re: DBMan search results in SSI page In reply to
Hi Carol

SSI is actually easy relative to perl - I knew nothing about until a couple of weeks ago :-)

I've worked out a really bad hack for doing this. In sub html_view_success I've stuck this in:

Code:
if ($ENV{'REQUEST_URI'} eq '/news/') {


&html_print_headers;
# Go through each hit and convert the array to hash and send to
# html_record for printing.
print "<ul>";
for (0 .. $numhits - 1) {
print "<li>";
&html_record (&array_to_hash($_, @hits));
print "</li>";
}

print "</ul>";

}

if ($ENV{'REQUEST_URI'} ne '/news/') {

/news/ is the page where I'm calling the DBMan out put with this:

Code:

<!--#include virtual="/cgi-bin/childrenfirst/dbman/db.cgi?db=default&uid=default&keyword=*&mh=6&sb=1&so=ascend&view_records=View+Articles" -->

The only problem with it is that it falls over if the news page is visited as /news/index.shtml rather than /news/

If anyone has any more elegant solutions please let me know!

Quote Reply
Re: DBMan search results in SSI page In reply to
Hi Adam

I posted the above posting before I saw your reply.

A new subroutine is easy :-) but how would I call it?

Chris
Quote Reply
Re: DBMan search results in SSI page In reply to
How about just adding ssi=1 to your calls that are made through SSI. Then in your html routines do something like:

if (! $in{'ssi'}) {
print qq~
<html>
<head>
<title>My page title</title>
<body> ..
~;
}
print qq~
Common stuff..
~;
if (!$in{'ssi'}) {
print qq~
footer stuff, not going if called via ssi.
~;
}

Hope that helps,

Alex
Quote Reply
Re: DBMan search results in SSI page In reply to
Ummmm, I think Carol might be better at explaining this, because I haven't used her record_short mod. Ok, I'll do me best...

You basically just need to duplicate all the modifications you made for record_short, calling them something else, and removing any extra HTML that you don't need. And the print header bit as well, because you'll already have printed it. Aaaaghhh! Carol, help me out here will ya? Smile

Maybe I'd be better off explaining SSI to Carol than the mod to you! Carol, basically an SSI call is just going to return the data that the CGI script generates, only it's into another page.

Anybody following me here?

adam
Quote Reply
Re: DBMan search results in SSI page In reply to
Hi

Thnaks Carol and Adam for looking at this but Alex seems to have come up with a very nice solution :-)

In case anyone else want to try this, here is a working solution.

In sub html_view_success (this assumes that JPD's short mod is in place) change it to this (the HTML can be whatever you want - it's a simpler, non-tables version here):

Code:
sub html_view_success {
# --------------------------------------------------------
# This page displays the results of a successful search.
# You can use the following variables when displaying your
# results:
#
# $numhits - the number of hits in this batch of results.
# $maxhits - the max number of hits displayed.
# $db_total_hits - the total number of hits.
# $db_next_hits - html for displaying the next set of results.

my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);

if ( $db_total_hits == 1 ) {
%rec = &array_to_hash(0, @hits);

&html_print_headers;

print qq|

<html>
<head>
<title>$rec{'Title'}</title>
</head>

<body>

<h1>$rec{'Title'}</h1>

|;

&html_record_long(%rec);

&html_footer;

print qq|

</body>
</html>

|;

return;

}

# detect if ssi=1, and if so don't print the top of the page
if (! $in{'ssi'}) {

&html_print_headers;

print qq|

<html>
<head>
<title>Search Results</title>
</head>

<body>


<h1>Search Results</h1>

<p>Your search returned <strong>$db_total_hits</strong> matches.</p>

|;

if ($db_next_hits) {
print "<p>Pages: $db_next_hits</p>";
}

}

# next line prints the headers here is the call is made via SSI
if ($in{'ssi'}) { &html_print_headers; }

# All of the next section will get printed if ssi=1
# Go through each hit and convert the array to hash and send to
# html_record for printing.
print "<ul>";
for (0 .. $numhits - 1) {
print "<li>";
&html_record (&array_to_hash($_, @hits));
print "</li>";
}
print "</ul>";


# detect if ssi=1, and if so don't print the bottom of the page
if (!$in{'ssi'}) {

if ($db_next_hits) {
print "<p>Pages: $db_next_hits</p>";
}

&html_footer; print qq|

</body>
</html>
|;
}

}


And call the script via a .shtml page like this (you can use whatever you want in this string, the important thing is that you have ssi=1):

Code:
<!--#include virtual="/cgi-bin/dbman/db.cgi?db=default&uid=default&ID=*&sb=0&so=descend&mh=6&view_records=1&ssi=1" -->


Now I think I'd better add this to the list of things I must document for the Resources section of Alex's site :-)

Chris

Quote Reply
Re: DBMan search results in SSI page In reply to
 
Problem solved. The problem is that with the long/short display mod, the long url is built using the ENV Query String, which includes the SSI tag. This ensures the abortion of headers/footers using the mods found in Chris's Newsman code. Solution:

In sub html_record change:

Code:
# create link to full display
$record_number = ((($nh - 1) * $db_max_hits) + $i);

$long_url = $ENV{'QUERY_STRING'};
$long_url =~ s/\&nh=\d+//;
$long_url =~ s/\&mh=\d+//;

$long_url = "$db_script_url?$long_url&nh=$record_number&mh=1";

to

Code:
# create link to full display
$record_number = ((($nh - 1) * $db_max_hits) + $i);

$long_url = $ENV{'QUERY_STRING'};
$long_url =~ s/\&nh=\d+//;
$long_url =~ s/\&mh=\d+//;


if ($in{'ssi'} == 1) { $long_url = "$db_script_url?db=review&uid=default&id=*&view_records=1&nh=$record_number&mh=1"; }
else { $long_url = "$db_script_url?$long_url&nh=$record_number&mh=1"; }

I'm sure there are other ways, but this did the job!


------------------
The Crowe crowe@charter.net
www.lit.org Links Engine for Writing on the net!



Quote Reply
Re: DBMan search results in SSI page In reply to
Small problem.. In the short display, this code works fine. If ssi=1 is detected, no headers. If not, they are displayed.

However, When I go to the long display, no headers are displayed either. I bet its the way the short/long builds the $long url.. but I can't seem to pin point the problem.


Here is my Code for the Short Record Display.


Code:
sub html_record {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.
# This is the "short display" -- the list of records that are returned
# from a search.

my (%rec) = @_;

# create link to full display
$record_number = ((($nh - 1) * $db_max_hits) + $i);

$long_url = $ENV{'QUERY_STRING'};
$long_url =~ s/\&nh=\d+//;
$long_url =~ s/\&mh=\d+//;

# $long_url = "$db_script_url?$db_key=$rec{$db_key}&nh=$record_number&mh=1";
$long_url = "$db_script_url?$long_url&nh=$record_number&mh=1";


# print "<TD>"; # do not remove this! It is necessary to make the records display properly

# Below is where you define what you want to appear for each record in the "short" display.
# You can make this whatever you want, and display as many fields as you would like.
# Choose which of the fields you would like for users to click on to reach the full display
# of records and use that field name in place of "Title" below.
#
# Be sure that you use <a href="$long_url"> for the link to your full record display.

# <-- Start of short display formatting -- >


($db_auto_generate and print &build_html_record(%rec) and return);

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';

$url{'e-mail'} = $rec{'e-mail'};
$url{'e-mail'} =~ s/<\/?B>//g;
$rec{'short_desc'} =~ s/\n/<BR>/g;
$rec{'long_desc'} =~ s/\n/<BR>/g;
$url{'url'} = $rec{'url'};
$url{'url'} =~ s/<\/?B>//g;

print qq|
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=0>|;

print qq|

<TR><TD ALIGN="left" VALIGN="TOP" WIDTH="90%"><$font>
<b><font color=364276>$rec{'title'}</b></font><br>
<b>Rating:</b> <img align="center" src="http://www.fragdot.com/staff/stars/$rec{'rating'}.gif"><br>
<b>$rec{'category'} by: <a href="mailto:$url{'e-mail'}">$rec{'userid'}</a></b> <small>( $rec{'date'} )</small><br>

|;

if ($rec{'url'}) {
print qq|
<b>Related Link:<a href="$url{'url'}">$rec{'url'}</a></b><br><br>
|;
}

print qq|
$rec{'short_desc'}
|;


print qq|
[ <a href="$long_url">Read the Review</a> ]<br><br></font>
|;


sub html_record {
# --------------------------------------------------------
# How a record will be displayed. This is used primarily in
# returning search results and how it is formatted. The record to
# be displayed will be in the %rec hash.
# This is the "short display" -- the list of records that are returned
# from a search.

my (%rec) = @_;

# create link to full display
$record_number = ((($nh - 1) * $db_max_hits) + $i);

$long_url = $ENV{'QUERY_STRING'};
$long_url =~ s/\&nh=\d+//;
$long_url =~ s/\&mh=\d+//;

# $long_url = "$db_script_url?$db_key=$rec{$db_key}&nh=$record_number&mh=1";
$long_url = "$db_script_url?$long_url&nh=$record_number&mh=1";


# print "<TD>"; # do not remove this! It is necessary to make the records display properly

# Below is where you define what you want to appear for each record in the "short" display.
# You can make this whatever you want, and display as many fields as you would like.
# Choose which of the fields you would like for users to click on to reach the full display
# of records and use that field name in place of "Title" below.
#
# Be sure that you use <a href="$long_url"> for the link to your full record display.

# <-- Start of short display formatting -- >


($db_auto_generate and print &build_html_record(%rec) and return);

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';

$url{'e-mail'} = $rec{'e-mail'};
$url{'e-mail'} =~ s/<\/?B>//g;
$rec{'short_desc'} =~ s/\n/<BR>/g;
$rec{'long_desc'} =~ s/\n/<BR>/g;
$url{'url'} = $rec{'url'};
$url{'url'} =~ s/<\/?B>//g;

print qq|
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=0>|;

print qq|

<TR><TD ALIGN="left" VALIGN="TOP" WIDTH="90%"><$font>
<b><font color=364276>$rec{'title'}</b></font><br>
<b>Rating:</b> <img align="center" src="http://www.fragdot.com/staff/stars/$rec{'rating'}.gif"><br>
<b>$rec{'category'} by: <a href="mailto:$url{'e-mail'}">$rec{'userid'}</a></b> <small>( $rec{'date'} )</small><br>

|;

if ($rec{'url'}) {
print qq|
<b>Related Link:<a href="$url{'url'}">$rec{'url'}</a></b><br><br>
|;
}

print qq|
$rec{'short_desc'}
|;


print qq|
[ <a href="$long_url">Read the Review</a> ]<br><br></font>
|;
}



Here is the Long Display Code

Code:

sub html_record_long {
#----------------------------------------------------------------
my (%rec) = @_;

if ($db_total_hits > 1) {

# create links to previous and next records

$next_url = $ENV{'QUERY_STRING'};
$next_url =~ s/\&nh=\d+//;
$next_hit = $nh + 1;
$prev_hit = $nh - 1;


# Below is where you define your form.

# <-- Start of record display -->

($db_auto_generate and print &build_html_record(%rec) and return);

my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#003399';
my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';

$url{'e-mail'} = $rec{'e-mail'};
$url{'e-mail'} =~ s/<\/?B>//g;
$rec{'short_desc'} =~ s/\n/<BR>/g;
$rec{'long_desc'} =~ s/\n/<BR>/g;
$url{'url'} = $rec{'url'};
$url{'url'} =~ s/<\/?B>//g;

print qq|
<TABLE WIDTH="475" CELLPADDING=0 CELLSPACING=0 BORDER=0>|;

print qq|

<TR><TD ALIGN="left" VALIGN="TOP" WIDTH="90%"><$font>
<b><font color=364276>$rec{'title'}</b><br></font>
<b>Rating:</b> <img align="center" src="http://www.fragdot.com/staff/stars/$rec{'rating'}.gif"><br>
<b>$rec{'category'} by: <a href="mailto:$url{'e-mail'}">$rec{'userid'}</a></b> <small><$font>( $rec{'date'} )</small><br>

|;

if ($rec{'url'}) {
print qq|
<b>Related Link: <a href="$url{'url'}">$rec{'url'}</a></b><br><br>
|;
}

print qq|
$rec{'long_desc'}<br><br>
|;


print qq|
<center>
|;

if ($prev_hit) {
$previous = qq~<a href="$db_script_url?$next_url&nh=$prev_hit"><$font>Previous</font></a>~;
}
else { $previous = " "; }

if ($next_hit <= $db_total_hits) {
$next = qq~<a href="$db_script_url?$next_url&nh=$next_hit"><$font>Next</font></a>~;
}
else { $next = " "; }

# create link back to short display
$list_url = $next_url;
$list_url =~ s/\&mh=\d+//;
$mh = $db_max_hits;
$lh = int(($nh-1)/$mh) + 1;
$list = qq~<a href="$db_script_url?$list_url&nh=$lh"><$font>Back to record list</font></a>~;

# print out the links
print qq|
<table width=100%>
<tr><td width=50%>$previous</td>
<td width=50% align=right>$next</td></tr>
<tr><td colspan=2 align=center>$list</td></tr>
<tr><td colspan=2 align=center><$font>Record $nh of $db_total_hits</font></table>
|;
}




# <-- End of record display -->

}


And here is the View Success



Code:

sub html_view_success {
# --------------------------------------------------------
# This page displays the results of a successful search.
# You can use the following variables when displaying your
# results:
#
# $numhits - the number of hits in this batch of results.
# $maxhits - the max number of hits displayed.
# $db_total_hits - the total number of hits.
# $db_next_hits - html for displaying the next set of results.
#

my (@hits) = @_;
my ($numhits) = ($#hits+1) / ($#db_cols+1);
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);
$in{'nh'} ? ($nh = $in{'nh'}) : ($nh = 1);

$page_title = "Search Results";

# detect if ssi=1, and if so don't print the top of the page


if (! $in{'ssi'}) { &html_page_top; }

&html_print_headers;


# Go through each hit and convert the array to hash and send to
# html_record for printing.
if (($db_total_hits == 1) &#0124; &#0124; ($maxhits == 1)) {
&html_record_long(&array_to_hash(0, @hits));
}



else {
if (! $in{'ssi'}) {
print qq|<p><$font>Your search returned <b>$db_total_hits</b> matches.</font>|;
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>"; }
}
$i = 1;
print "<table>";
for (0 .. $numhits - 1) {
print "<tr>";
&html_record (&array_to_hash($_, @hits));
print "</tr>";
++$i;
}
print "</table>";
if (! $in{'ssi'}) {
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>";}
}

}


if (! $in{'ssi'}) {

&html_footer;
&html_page_bottom;
}

}













------------------
The Crowe crowe@charter.net
www.lit.org Links Engine for Writing on the net!