Gossamer Forum
Home : Products : DBMan : Customization :

short/long display integration

Quote Reply
short/long display integration
I would like to integrate the short/long display into my existing html.pl file. I have made several modifications to it already, but the method of displaying records hasn't changed all that much from the original code.

Any help on this matter would be appreciated.

Thanks,
Frank
Quote Reply
Re: short/long display integration In reply to
Frank:

I think that unless you are using a fresh copy of the short/long mod and then copying your html_record and html_record_form from one script to another you may be missing some coding.

There may be several places in the script where the coding has been changed. If you want to keep your original html.pl file you may need to go line by line and make comparisons to be sure you have all the necessary changes for using the short/long mod.

Hope this helps Smile
Quote Reply
Re: short/long display integration In reply to
 I am facing the problem that fharris is facing.
I would like to keep my original html.pl and get the short/long display mod integated into my current DBman
Could any one tell me what code do i need to change??
Thanks
Quote Reply
Re: short/long display integration In reply to
The reason I created a whole file for the short/long display was that I couldn't figure out how to tell people to change from one to the other. But I'll give it a shot.

This is how to change the regular html.pl to a short display.

sub html_record_form stays the same

rename sub html_record to sub html_record_long

In sub html_record_long (the one you just renamed) add the following just after

my (%rec) = @_;

Code:
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;

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>
|;
}

Create a new subroutine -- sub html_record

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?$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 -- >

print qq|
<a href="$long_url">$rec{'Title'}</a>
|;

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

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

}

In sub html_view_success, replace

Code:
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}

# Go through each hit and convert the array to hash and send to
# html_record for printing.
for (0 .. $numhits - 1) {
print "<P>";
&html_record (&array_to_hash($_, @hits));
}
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}

with

Code:
if (($db_total_hits == 1) or ($maxhits == 1)) {
&html_record_long(&array_to_hash(0, @hits));
}

else {
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 ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>";}
}

In sub html_delete_form, change

Code:
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
if ($status ne "ok") { # There was an error searching!
print qq|<P><FONT COLOR="RED" SIZE=4>Error: $status</FONT></P>|;
}
else {
print "<P>";
for (0 .. $numhits - 1) {
%tmp = &array_to_hash($_, @hits);
print qq|<TABLE BORDER=0><TR><TD><INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="delete"></TD><TD>|;
&html_record (%tmp);
print qq|</TD></TR></TABLE>\n|;
}
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
}

to

Code:
if ($status ne "ok") { # There was an error searching!
print qq|<P><FONT COLOR="RED" SIZE=4>Error: $status</FONT></P>|;
}
else {
if (($db_total_hits == 1) or ($maxhits == 1)) {
print qq|
<p><$font>
If you would like to delete this record, check the box and then press "Delete Records":</font>|;
%tmp = &array_to_hash(0, @hits);
print qq|<table><tr><td valign=top><INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="delete"></td><td>|;
&html_record_long(&array_to_hash(0, @hits));
print qq|</td></tr></table>
|;
}
else {
print qq|
<p><$font>
Check which records you wish to delete and then press "Delete Records":<br>
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) {
%tmp = &array_to_hash($_, @hits);
print qq|<TR><TD valign=top><INPUT TYPE=CHECKBOX NAME="$tmp{$db_key}" VALUE="delete"></TD>|;
&html_record (%tmp);
print "</tr>";
++$i;
}
print "</table>";
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>"; }
}
}

In sub html_modify_form, change

Code:
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}

# Go through each hit and convert the array to hash and send to
# html_record for printing. Also add a radio button with name=modify
# and value=key.
if ($status ne "ok") { # Error searching database!
print qq|<P><FONT COLOR="RED" SIZE=4>Error: $status</FONT>|;
}
else {
print "<P>";
for (0 .. $numhits - 1) {
%tmp = &array_to_hash($_, @hits);
print qq|<TABLE BORDER=0><TR><TD><INPUT TYPE=RADIO NAME="modify" VALUE="$tmp{$db_key}"></TD><TD>|;
&html_record (%tmp);
print qq|</TD></TR></TABLE>\n|;
}
if ($db_next_hits) {
print "<br><$font>Pages: $db_next_hits</font>";
}
}

to

Code:
if ($status ne "ok") { # Error searching database!
print qq|<P><$font_error>Error: $status</FONT>|;
}
else {
if (($db_total_hits == 1) &#0124; &#0124; ($maxhits == 1)) {
print qq|
<p><$font>
If you would like to modify this record, select the button and then press "Modify Record":</font>
|;
%tmp = &array_to_hash(0, @hits);
print qq|<INPUT TYPE=RADIO NAME="modify" VALUE="$tmp{$db_key}">|;
&html_record_long(&array_to_hash(0, @hits));
}
else {
print qq|
<p><$font>
Check which record you wish to modify and then press "Modify Records":<br>
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) {
%tmp = &array_to_hash($_, @hits);
print qq|<TR><TD valign=top><INPUT TYPE=RADIO NAME="modify" VALUE="$tmp{$db_key}"></TD>|;
&html_record (%tmp);
print "</tr>";
++$i;
}
print "</table>";
if ($db_next_hits) { print "<br><$font>Pages: $db_next_hits</font>"; }
}
}



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






Quote Reply
Re: short/long display integration In reply to
JP- The modification almost works, but there are still some problems.

The short listing seems to display all the record titles, except my random banner ads all show up at the top of the screen, before any records are listed on the page. This was a recent mod we worked on. Still looking into that problem.

The links on the short listing are broken. Whenever I click on them, I end up with a link to something that looks like this:

http://www.cacheweb.com/cwdb/db.cgi?db=default&uid=default&Category=Computers&view_records=1&nh=-4&mh=1

I believe the problem is with the "nh" variable being negative. Not sure why it's always showing up as a negative number.

For instance, this record should be "nh=1" to view the correct record. It shows up as "nh=-9"

http://www.cacheweb.com/cwdb/db.cgi?db=default&uid=default&view_records=1&ID=*&nh=-9&mh=1

I'm suspecting the problem has something to do with this line in sub html_record:

$record_number = ((($nh - 1) * $db_max_hits) + $i);

Anyways, check out this URL to see the problem:

http://www.cacheweb.com/cwdb/db.cgi?db=default&uid=default&view_records=1&ID=*

Thanks,
Frank
Quote Reply
Re: short/long display integration In reply to
Your banners showing up at the wrong place has to do with a problem with tables, probably. I would need to see your html.pl file to know for sure.

I don't know why the &nh= would be negative either. Again, I'll need to see your html.pl file.



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






Quote Reply
Re: short/long display integration In reply to
I just sent you an email with the information to get the html.pl file from my site.

Thanks,
Frank
Quote Reply
Re: short/long display integration In reply to
I got the file.

The reason your banners aren't displaying properly is that you now need to put them in a row.

Change:
Code:
print "<P>";
if (int(rand($random_number)) eq 0) {
$randnumber = int(rand($#banner+1));
print "<A HREF=\"$url[$randnumber]\" target=\"$url[$randnumber]\"><IMG SRC=\"$banner[$randnumber]\" BORDER=0 ALT=\"$url[$randnumber]\"></A><BR>";
}
print "<P>";

to

Code:
if (int(rand($random_number)) eq 0) {
$randnumber = int(rand($#banner+1));
print qq|<td><A HREF="$url[$randnumber]" target="$url[$randnumber]">
<IMG SRC="$banner[$randnumber]" BORDER=0 ALT="$url[$randnumber]"></A></td></tr><tr>|;
}

(I made things a little easier for me to read. Smile )

I went to the site, but you seem to be using the non-short/long display html.pl file. Everything looked fine. Is there a place where I can see the short/long display in action?



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






Quote Reply
Re: short/long display integration In reply to
Hi JPD-

I've moved back the revised html.pl file.

Thanks,
Frank

Quote Reply
Re: short/long display integration In reply to
I left out a change to the short/long display.

In sub html_view_records, after

Code:
my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits);

add

Code:
$in{'nh'} ? ($nh = $in{'nh'}) : ($nh = 1);

That should fix it.


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






Quote Reply
Re: short/long display integration In reply to
That worked perfectly! I appreciate your help with this. Smile

Frank
Quote Reply
Re: short/long display integration In reply to
No problem, Frank. I should probably use this thread to change the mod.

Thanks for testing it out for me. Smile


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