Gossamer Forum
Home : Products : DBMan : Customization :

new sub routine error...

Quote Reply
new sub routine error...
Frown Hi all,

I have a problem, I tried creating another sub routine in my .pl file and i can't get it to work.

here is a copy of the new sub routine and want to call this sub routine in using the sub html_footer routine.

I can rename this to test.cgi and it runs ok on it own as well

sub html_graph {

#!c:/perl/bin/perl

use perlchartdir;

# The data for the line chart.
my $data0 = [$rec{'23:00'},$rec{'23:00'}];
my $data1 = [$rec{'23:00'},$rec{'23:00'}];
my $data2 = [$rec{'23:00'},$rec{'23:00'}];

# The labels for the line chart.
my $labels = ["0", "", "", "3", "", "", "6", "", "", "9", "", "", "12","", "", "15", "", "", "18", "", "", "21", "", "", "24"];

# Create a XYChart object of size 500 x 300 pixels.
my $c = new XYChart(500, 300);

# Set background color to pale yellow 0xffff80, with a black edge and a 1.
# pixel 3D border.
$c->setBackground(0xffff80, 0x0, 1);

# Set the plotarea at (55, 45) and of size 420 x 210 pixels, with white.
# background. Turn on both horizontal and vertical grid lines with light.
# grey color (0xc0c0c0).
$c->setPlotArea(55, 45, 420, 210, 0xffffff, -1, -1, 0xc0c0c0, -1);

# Add a legend box at (55, 25) (top of the chart) with horizontal layout.
# Use 8 pts Arial font. Set the background and border color to Transparent.
$c->addLegend(55, 25, 0, "", 8)->setBackground($perlchartdir::Transparent);

# Add a title box to the chart using 11 pts Arial Bold Italic font. The text.
# is white (0xffffff) on a dark red (0x800000) background, with a 1 pixel 3D.
# border.
$c->addTitle("Daily Server Load", "arialbi.ttf", 11, 0xffffff)->setBackground(0x800000, -1, 1);

# Add a title to the y axis.
$c->yAxis()->setTitle("MBytes");

# Set the labels on the x axis.
$c->xAxis()->setLabels($labels);

# Add a title to the x axis.
$c->xAxis()->setTitle("Jun 12, 2001");

# Add a line layer to the chart.
my $layer = $c->addLineLayer();

# Set the default line width to 3 pixels.
$layer->setLineWidth(3);

# Add the three data sets to the line layer.
$layer->addDataSet($data0, -1, "Server # 1");
$layer->addDataSet($data1, -1, "Server # 2");
$layer->addDataSet($data2, -1, "Server # 3");

# output the chart in PNG format.
binmode(STDOUT);
print "Content-type: image/png\n\n";
print $c->makeChart2($perlchartdir::PNG);
}

here is a copy of the sub html_footer routine

sub html_footer {
# --------------------------------------------------------
# Print the menu and the footer and logo. It would be nice if you left
# the logo in. ;)
#
# We only print options that the user have permissions for.
#

my $font = 'Font face="Verdana, Arial, Helvetica" Size=2';

print qq!<P align=center><$font>!;
print qq!| <A HREF="$db_script_link_url">Home</A> !;
print qq!| <A HREF="$db_script_link_url&add_form=1">Add</A> ! if ($per_add);
print qq!| <A HREF="$db_script_link_url&view_search=1">View</A> ! if ($per_view);
print qq!| <A HREF="$db_script_link_url&delete_search=1">Delete</A> ! if ($per_del);
print qq!| <A HREF="$db_script_link_url&modify_search=1">Modify</A> ! if ($per_mod);
print qq!| <A HREF="$db_script_link_url&view_records=1&$db_key=*">List All</A> ! if ($per_view);
print qq!| <A HREF="$db_script_link_url&admin_display=1">Admin</A> ! if ($per_admin);
print qq!| <A HREF="$db_script_link_url&whos_online=1">Who's Online</A> ! if ($per_view);
print qq!| <A HREF="$db_script_link_url&logoff=1">Log Off</A> |!;
print qq!</font></p>!;
# Print the Footer -- note: a link (doesn't have to be the graphic) is required unless you purchase
# a license. See: http://gossamer-threads.com/scripts/register/ for more info.
print qq!

print qq|</font></p>|;
&html_footer; print qq|

!;
}



Any help would be greatfull as I really need to get this working..
Quote Reply
Re: [cwilcox] new sub routine error... In reply to
The code outputs data in a binary image format, which cannot be mixed in with the text output of the build script. Also a document can't have two headers.

At best the browser is just going to print a string of strange characters near the bottom of your page.

Try using the code in a separate program and call it via an IMG tag, something like this:-

Code:
<IMG SRC="graph.cgi" WIDTH="500" HEIGHT="300" ALT="Graph">

Potentially you could pass values to it like this:-

Code:
<IMG SRC="graph.cgi?somevalue=1234" WIDTH="500" HEIGHT="300" ALT="Graph">

Though you'd need to adjust your code to read those values. Take a look at a few graphic counter scripts to see examples of that, if you're unsure.

Oh, and you have some problems with the print qq statements near the bottom of the code to do with mismatched | and ! characters.

This is the block that needs fixing:-

Code:
print qq!

print qq|</font></p>|;
&html_footer; print qq|

!;

Unless you really intend to literally print "print qq|</font></p>|; &html_footer; print qq|" to the browser.
Quote Reply
Re: [cwilcox] new sub routine error... In reply to
You can't just copy and paste a script into a subroutine like that. You even left in the shebang line. Also the..

use perlchartdir;

line should be "require"

Change:

print qq!

print qq|</font></p>|;
&html_footer; print qq|

!;

to

print qq|</font></p>|;
&html_footer;
Quote Reply
Re: [wysardry] new sub routine error... In reply to
Thanks for your help,

I tried what you said but I,m having big trouble in passing the information to the from DB to

cgi script. I have tried all that I know (very little) and what I could read on the internet but still no success in passing the variables $rec{'00:00'} ..$rec{'24:00'} to $data0 = [,,,, ]; part of the cgi script.

Can someone pls help me in solving this problem..

CrazyCrazyCrazy