Gossamer Forum
Home : Products : DBMan : Customization :

"Printable" record page not maintaining formatting

Quote Reply
"Printable" record page not maintaining formatting
Hi there!

I have a implemented the short/long mod to DBMan. In addition, I created a "printable" version of the record that rearranges the graphics and text to print better.

My problem is that for some reason the printable version does not automatically format the text (line breaks, etc), so it long fields appear as one ugly block.

My printable version is created through a new subroutine called sub html_printable in the .pl file. I can't seem to figure out how records are passed to "sub build_html_record" in db.cgi for formatting? Anyone know of a good place to start looking?

Quote Reply
Re: "Printable" record page not maintaining format In reply to
Are you letting dbman autogenerate the pages? in default.cfg:
# Auto generate the html forms (1 = Yes, 0 = No).
$db_auto_generate = 0;

many folks doN't let dbman build the records for them. since the html output is pretty bland. If you are autogenerating I suggest to change the above like I have then look at html.pl and then you can change the html to pretty much however you want.

JPdeni also has a friendlier version available. I like the way she has set up her html.pl It's very easy to read.

anyway the the sub html_record_long and sub html_record_short are the places that I started with first.

good luck and sorry I was off the mark

**************************************
on the pages in between ...
Quote Reply
Re: "Printable" record page not maintaining format In reply to
I need to make a clarification I think. DBMan is *not* autogenerating the HTML for me. I do not want the pages to autogenerate, my problem is in the output of the data. Imagine a two column table, with the field name (Name) on the left, and the field contents (Bob Smith) on the right. When you go to the long version of the record, line breaks and things that were entered in the field at the time of input are present. Example:

This is some lovely text.
Don't you just love my text?
I think this is the most beautiful text the world has ever seen!!

Don't you agree?
[/red]

When you go to the "printable" version however, it looks like this:


This is some lovely text.Don't you just love my text?I think this is the most beautiful text the world has ever seen!!Don't you agree?


How is it that the first long version knows when to put in the line breaks (I imagine it searches for hard carriage return symbols and converts them to line breaks) and the "printable" version does not?

Quote Reply
Re: "Printable" record page not maintaining format In reply to
I guess I was off the mark, :-)

How much did you change from the long_html to the printable_html ? I wonder if the problem is in your html coding... if the printable isn't long why don't you post it.

good luck

**************************************
on the pages in between ...
Quote Reply
Re: "Printable" record page not maintaining format In reply to
As requested, here is sub html_printable:

Code:

sub html_printable {
#----------------------------------------------------------------
# A printer friendly version of the long record form

my (%rec) = @_;
%rec = &get_record($in{$db_key});


$page_title = "Printer Friendly Version";

### The top of the page should go here
print "Content-type:text/html\n\n";

print qq|
<html>
<head>
<title>Jobs\@Colorado State University - Printer Friendly Format</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">


<table width=460 summary="This table is used for formatting only.">
<tr>
<td>
<div align=center>
<img src="$image_location/print_header.jpg" width="650" height="90" alt="Printable page top banner">
</div>
|;
### End top of page


### <-- Start of record display -->
$rec{'categories'} =~ s/\|/, /g;
my $font_color = 'Font face="Verdana, Arial, Helvetica" Size=2 Color=#000000';

print qq|
<table border="0" cellspacing="0" cellpadding="3" bordercolor="#999999" align="left" width="100%" summary="This table is similar to the detailed single job table, but it is formatted differently so that it prints better. The data is arranged in two columns, the first column has the heading (title, salary, etc...) and the second column contains the data.">
|;


### *:
if ($rec{'expire'} eq "No")
{
$rec{'killdate'} = "Applications will be accepted for this position until it is filled.";
} # close if


### ID:
if ($per_admin)
{
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP" width="20%"><$font_color><b>ID:</b></td>
<td width="80%"><$font>$rec{'ID'}</td>
</tr>
|;
} # close if


### Posted By:
if ($per_admin)
{
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP" width="20%"><$font_color><b>Posted By:</b></td>
<td width="80%"><$font>$rec{'author'}</td>
</tr>
|;
} # close if


### Title:
if ($rec{'title'} ne "no value") {
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP"><$font_color><b>Title:</b></td>
<td><$font>$rec{'title'}</td>
</tr>
|;
}


### Official Title:
if ($rec{'offtitle'} ne "no value") {
if (($db_uid =~ "staff") or ($per_admin) or ($db_uid =~ "hrs"))
{
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP"><$font_color><b>Official Title:</b></td>
<td><$font>$rec{'offtitle'}</td>
</tr>
|;
} # close if
}

### Class Code:
if ($rec{'classcode'} ne "no value") {
if (($db_uid =~ "staff") or ($per_admin) or ($db_uid =~ "hrs"))
{
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP"><$font_color><b>Class Code:</b></td>
<td><$font>$rec{'classcode'}</td>
</tr>
|;
} # close if
}

### Position Number:
if ($rec{'posnum'} ne "no value") {
if (($db_uid =~ "staff") or ($per_admin) or ($db_uid =~ "hrs"))
{
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP"><$font_color><b>Position Number:</b></td>
<td><$font>$rec{'posnum'}</td>
</tr>
|;
} # close if
}


### CSU Grade:
if ($rec{'csugrade'} ne "no value") {
if (($db_uid =~ "staff") or ($per_admin) or ($db_uid =~ "hrs"))
{
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP"><$font_color><b>CSU Grade:</b></td>
<td><$font>$rec{'csugrade'}</td>
</tr>
|;
} # close if
}

### State Grade:
if ($rec{'stategrade'} ne "no value") {
if (($db_uid =~ "staff") or ($per_admin) or ($db_uid =~ "hrs"))
{
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP"><$font_color><b>State Grade:</b></td>
<td><$font>$rec{'stategrade'}</td>
</tr>
|;
} # close if
}

### Job Classification:
print qq|
<tr align="left" valign="top">
<td align="Right" valign="TOP"><$font_color><b>Employment Type:</b></td>
<td><$font>$rec{'class'}
|;

if ($rec{'class2'} ne "no value") {
print qq|
- $rec{'class2'}
|;
}

print qq|
</td>
</tr>
|;


# ### Job Classification 2:
# if ($rec{'class2'} ne "no value") {
# if (($db_uid =~ "staff") or ($per_admin) or ($db_uid =~ "hrs"))
# {
# print qq|
# <tr align="left" valign="top">
# <td align="Right" valign="TOP"><$font_color><b>State Classified Status:</b></td>
# <td><$font>$rec{'class2'}</td>
# </tr>
# |;
# } # close if
# }


if ($rec{'college'} ne "no value") {
### College/Categories:
print qq|
<tr align="left" valign="top">
|;

if (($db_uid =~ "faculty") or ($per_admin))
{
print qq|
<td align="Right" valign="TOP"><$font_color><b>College:</b></td>
<td><$font>
|;

if ($rec{'college'} eq "Other")
{
print "$rec{'collegeother'}</td>";
} # close if
else
{
print "$rec{'college'}</td>";
} # close elsif
} # close if
}

else
{
if ($per_add)
{
print qq|
<td align="Right" valign="TOP"><$font_color><b>Categories:</b></td>
<td><$font>$rec{'categories'}</td>
|;
}
} # close else


print qq|
</tr>

### The bottom of the page should go here
print qq|
</table></tr></td>
</body>
</html>
|;
### End bottom of page

} # close html_printable


Quote Reply
Re: "Printable" record page not maintaining format In reply to
i think u need to change the following at the top of the code....

my (%rec) = @_;
$rec{'YOUR FIELD NAME HERE'}=~s/\n/<BR>/g;
%rec = &get_record($in{$db_key});

It should add line breaks to the field you name......

Quote Reply
Re: "Printable" record page not maintaining format In reply to
Thanks! That worked :) I had to move the YOUR FIELD NAME HERE line below the others though, like this:

Code:
my (%rec) = @_;
%rec = &get_record($in{$db_key});
$rec{'YOUR FIELD NAME HERE'}=~s/\n/<BR>/g;

A couple of questions though...
Is there any way to apply this to all fields instead of one?
In db.cgi in sub build_html_record, in addition to inserting line breaks, it also recognizes and formats URL's and e-mail addresses. Do I have to recreate this whole process manually within the printable subroutine?

Quote Reply
Re: "Printable" record page not maintaining format In reply to
Why do you have

my (%rec) = @_;

and

%rec = &get_record($in{$db_key});

You are either using %rec passed from another routine or you are using &get_record to populate %rec - you don't want both.

For all fields use:

Code:
foreach (keys %rec) {
s/\n/<BR>/g;
}
Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: "Printable" record page not maintaining format In reply to
That was redundant, thanks for pointing it out, I have fixed that. It still doesn't solve my problem with webpage and email formatting though.

Quote Reply
Re: "Printable" record page not maintaining format In reply to
The foreach code above should.

Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: "Printable" record page not maintaining format In reply to
That code had no effect when I put it into my printable subrouting. I am using:

%rec = &get_record($in{$db_key});

to call up the record, does the foreach loop above need to be restructured because of this?

Quote Reply
Re: "Printable" record page not maintaining format In reply to
Sorry try:

Code:
foreach (keys %rec) {
$rec{$_} =~ s/\n/<BR>/g;
}
Mods:http://wiredon.net/gt/download.shtml
Installations:http://wiredon.net/gt/
Quote Reply
Re: "Printable" record page not maintaining format In reply to
That worked! Thanks everyone for your help :) May the force be with you, or something.