So far the script is working fine with the print in the main() which is a
run_mode. It only the problem while showing the graph. I'm not sure if there
is another way of doing this. I am attaching a complete scripts for you
guy's o look and understand as what exactly I am trying to do here and guide
me as to how should I proceed.

This script is making a connection to the database, runs a query and prints
the result set back on the web page. Earlier this was just printing the text
info and now I am trying to include the graph as well for the data returned
from the database. The text part is still working fine with all the changes,
its just the graph which dosn't showup.

Thanks for all your time and help once again.
Bal.

package perfmonpvt;
use base 'CGI::Application';
use strict;
use Sybase::CTlib;

   sub setup {
        my $self = shift;
        $self->start_mode('mode1');
        $self->run_modes(
                'mode1' => 'showsrvrs',
                'mode2' => 'showdetails'
        );
   }

   sub teardown {
        my $self = shift;
   }

   sub showsrvrs {
        my $self = shift;
        # Get CGI query object
        my $q = $self->query();
        my $dbh = Sybase::CTlib->ct_connect('User', 'Password', 'DBServer');
## Connect to the DB Server.
        $dbh->ct_sql('use perfmondb'); ## Get into the database.

if($dbh eq undef) ## Check to see if the connection to DB is OK.
{
print $q->blockquote("<h1>Connection to server failed. </h1>");
print $q->blockquote("This could be due to an invalid Login
Name,Password,Server Name.");
print $q->blockquote("If you feel all of these are correct, then pls check
of the server is running and your login is not locked.");
print $q->blockquote("Still if you can't connect, Pls check you interfaces
of sql.ini files.");
exit 0;
}
        my @srvrs;
        my $app= $dbh->ct_sql('select Name from Servers');

foreach my $row (@$app) {
     foreach my $col (@$row) {
         push(@srvrs,$col);
     }
}

        my $output = '';
        $output .= $q->start_html(-title => 'Sysmon Details');
        $output .= $q->blockquote($q->strong("<h1>Check Sysmon
Details</h1>"));
        $output .= $q->start_form();
        {
          local($") = '';
        $output .= $q->blockquote("Select Server      : ",
$q->popup_menu(-name=> 'srv', -values =>\@srvrs));
        }
        {
          local($") = '';
        $output .= $q->blockquote("Select Item(s)     : ",
$q->checkbox_group(-name=> 'opt', -values =>['CPU
Busy','Deadlocks','TPS','IUD','Switches','Locks','Spinlock'],
        
-default => 'CPU Busy'
        
));
        }
        {
          local($") = '';
        $output .= $q->blockquote("Start Date         : ",
$q->textfield(-name=> 'sdt'));
        }
        {
          local($") = '';
        $output .= $q->blockquote("End Date           : ",
$q->textfield(-name=> 'edt'));
        }
        {
          local($") = '';
        $output .= $q->hidden(-name => 'rm', -value => 'mode2', -override=>1
);
        }
        {
          local($") = '';
        $output .= $q->submit("View Report");
        }
        $output .= $q->end_form();
        $output .= $q->end_html();
        return $output;
   }


sub showdetails {
        my $self = shift;
        #Get CGI query object
        my $q = $self->query();
        my $srv = $q->param("srv");
        my @opt = $q->param("opt");
        my $sdt = $q->param("sdt");
        my $edt = $q->param("edt");
        my $block = "";

foreach my $o (@opt)
{
        $block = "$block"." '$o',";
}
        $block = substr($block, 0, length($block) - 1);

        my $cmde = "exec perfmondb..proc_sysmon_crosstab
'$srv','$sdt','$edt', $block " ;

        my $dbh = Sybase::CTlib->ct_connect('perfmon', 'perfmon_ps',
'SYB_NJ6'); ## Connect to the server.

        print "Content-type:text/html \n\n";
        print $q->start_html(-title => 'Sysmon Details');

        if($dbh eq undef)
        {
        print $q->blockquote("<h1>Connection to server failed. </h1>");
        print $q->blockquote("This could be due to an invalid Login
Name,Password,Server Name.");
        print $q->blockquote("If you feel all of these are correct, then pls
check of the server is running and your login is not locked.");
        print $q->blockquote("Still if you can't connect, Pls check you
interfaces of sql.ini files.");
        exit 0;
        }
        $dbh->ct_sql("use perfmondb");
        my $data = $dbh->ct_sql($cmde); ## Execute the SQL cmd on the DB.

        print $q->blockquote("<h1>Check Sysmon Details</h1>");
        print $q->blockquote("Selected Server   : $srv");
        print $q->blockquote("Selected Report   : $block");
        print $q->start_form();
        print $q->hidden(-name => 'rm', -value => 'mode1', -override=>1);
        print $q->submit("Next Report");
        print $q->end_form();

print<<"_END_";                 ## Start Printing the Table.
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=1>
  <TBODY>
  <TR>
_END_
;
my $h = 1 ;
my $row;


foreach my $kv (@names) { 

print<<"_END_"; ## Print the Column Headers.
<TD>
<P align=center><STRONG>$kv &nbsp;</STRONG></P></TD>
_END_
;

print<<"_END_";
</TR>
_END_
;
}


foreach my $row (@$data) {
    foreach my $col (@$row) {
print<<"_END_" ; ## Print the column data
<TD>
<P align=left>$col</P></TD>
_END_
;
    }
print<<"_END_";
</TR><TR>
_END_
;
}
print<<"_END_";
</TR>
_END_
;


print<<"_END_";
</TR>
</TBODY></TABLE>
_END_
; ### End the Table here.

showgraph(); ## New line to display the graph.

print $q->end_html(); ## End the HTML.

}

sub showgraph{ ### New Sub  for showing the graph.

  use GD::Graph;
  use CGI qw(:standard);
  use GD::Graph::bars;

  my $self = shift;
  my $q = $self->query();

  die "Can't open the data file\n" unless open(DF,"<c:/temp/grph.txt");

  my @data = ( 
    ["1st","2nd","3rd","4th","5th","6th","7th", "8th", "9th"],
    [    1,    2,    5,    6,    3,  1.5,    1,     3,     4],
    [ sort { $a <=> $b } (1, 2, 5, 6, 3, 1.5, 1, 3, 4) ]
  );

  my $graph = GD::Graph::bars->new(400, 300);

  my $graph->set( 
      x_label           => 'X Label',
      y_label           => 'Y label',
      title             => 'Some simple graph'
  );

  my $gd = $graph->plot(\@data);

  my $format = $graph->export_format;
  $self->header_props({-type=>'image/png'});
  #  print header("image/$format");
  #  binmode STDOUT;
  #  print $graph->plot(\@data)->$format();
  return $graph->plot(\@data)->$format();

}

1;

-----Original Message-----
From: Brett Sanger [mailto:[EMAIL PROTECTED]]
Sent: Monday, April 15, 2002 9:33 AM
To: Sabherwal, Balvinder (MBS)
Cc: [EMAIL PROTECTED]
Subject: RE: [cgiapp] RE: Help!!


> The changed code is as below:
> sub main {
> .....

I'm assuming main is the run_mode being called.  If not, you'll need to
show us more code.

> showgraph();
>
> print $q->end_html();

This looks to be the problem.  you should not be printing anything.  Think
of CGI::App as doing something like:

my $q = new CGI:
my $text = Your::Module::Runmode();
print $q->header() unless $module_set_header_props;
print $text;

Thus, YOUR module shouldn't print ANYTHING.  You should stick anything you
would normally print into a scalar and return it (or a reference to it).

In your code showgraph() returns a value, which main then ignores, and
main() prints some html.

Main should be like:

main {
my $self= shift;
my $q = $self->query();
.....
my $text = showgraph();
$text .= $q->end_html();
return \$text;
}

Again, assuming main() is your run_mode.


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to