
yim11
Novice
Jul 27, 2000, 8:40 AM
Post #3 of 5
(1565 views)
|
Here it is, some of the names have been changed to protect the innocent !THANKS! in advance for all your help. -Jim ------Begin Code-------------- #!/usr/bin/perl use DBI; use CGI; use CGI qw(:all); use CGI::Carp qw (fatalsToBrowser confess); my $query = new CGI; $user = $query-> cookie('login'); $password = $query-> cookie('pass'); $dbname="pde"; $dbh=DBI->connect("dbi:Pg:dbname=$dbname",$user,$password) | | sendto_main(); if ( param('search.x') ) { # L I S T I N G print $query->header; print $query ->start_html ( -title=> 'PDE Comments Advanced Queries Page', -BGCOLOR=>'white', -TEXT=>'black', -LINK=>'blue', -VLINK=>'blue', -ALINK=>'blue' ); $searchs=$query->param('searchs'); $statement="select *,oid from comments where subject like '%$searchs%' or catno like '%$searchs%' or contents like '%$searchs%'"; # On is 0 for no parameters 1 for paramters already chosen $statement="$statement ORDER BY catno desc, sent desc"; $sth = $dbh->prepare("$statement"); $rv= $sth->execute( ); my %dat; print $query ->startform(-method=>"POST", -action=>"http://myserver.com/cgi-bin/plain_comments1.pl"); print "<left>\n"; print $query->textfield(-name=>'searchs', -maxlength=>100, -size=>50); print $query->image_button(-name=>'search', -src=>'http://myserver.com/search.gif', -border=>0); print $query->a({href=>'http://myserver.com/search.html'},' Help '),' '; print $query->a({-href=>'http://myserver.com/cgi-bin/advanced_comments.pl'},'Advanced'); print "</left>"; print <<"ENDPRINT"; <center><table WIDTH="100%"> <tr> <td WIDTH="10"></td> <td WIDTH="120"><left><font size=3 color="blue"><B><u>Cat. No.</u></b></font></left></td> <td WIDTH="120"><left><font size=3 color="blue"><B><u>Date</u></b></font></left></td> <td WIDTH="400"><left><font size=3 color="blue"><B><u>Message Subject</u></b></font></left></td> <td WIDTH="200"><left><font size=3 color="blue"><B><u>From</u></b></font></left></td> <td WIDTH="200"><left><font size=3 color="blue"><B><u>To</u></b></font></left></td> </tr> ENDPRINT while ($dat = $sth->fetchrow_hashref) { print " <tr> <td nowrap WIDTH=\"10\"><input TYPE=image NAME=\"$dat->{oid}\" src=\"http://myserver.com/datalist.gif\" border=0></td> <td nowrap WIDTH=\"120\"><left> $dat->{catno} </left></td> <td nowrap WIDTH=\"120\"><left> $dat->{sent} </left></td> <td nowrap WIDTH=\"400\"><left> $dat->{subject} </left></td> <td nowrap WIDTH=\"200\"><left> $dat->{whofrom} </left></td> <td nowrap WIDTH=\"200\"><left> $dat->{sendto} </left></td></tr> "; } print "</table>"; print $query->end_form; print $query -> end_html(); } elsif ( param() ) { # D o c u m e n t s # If the parameter is an oid (i.e. if submit not sent but a param was # then we get the fields from the database for that oid and send that # request all the data for that information so that we can obtain all multiple # row comments. print $query->header; print $query ->start_html ( -title=> 'PDE Comments Advanced Queries Page', -BGCOLOR=>'white', -TEXT=>'black', -LINK=>'blue', -VLINK=>'blue', -ALINK=>'blue' ); @par=$query->param(); $oids=$par[1]; chop($oids); chop($oids); $sth = $dbh->prepare("select * from comments where oid=$oids"); $rv = $sth->execute( ); my %dat; while ($dat = $sth->fetchrow_hashref) { # Fetch the data belonging to that oid and translate it for the full # select. $sth1 = $dbh->prepare("select * from comments where catno='$dat->{catno}' AND sent='$dat->{sent}' AND subject='$dat->{subject}' AND whofrom='$dat->{whofrom}' AND sendto='$dat->{sendto}' order by bin"); $rv1 = $sth1->execute( ); my %data; $i=0; while ($data = $sth1->fetchrow_hashref) { if ($i==0) { $cc=$data->{cc}; $cc=~s',', 'g; $help=$query -> a({-href=>'http://myserver.com/Address_Help.html', -target=>'_new'},'Help'); $sub_table=$query -> table({-border=>0,-width=>'600'}, Tr({-align=>LEFT, -valign=>TOP}, [ td(['Catno:',$data->{catno}]), td(['Date:',$data->{sent}]), td(['To:',$data->{sendto}]), td(['Cc:',$cc]), td(['From:',$data->{whofrom}]), td(['Subject:',$data->{subject}]), ] ) ); $applet_ref="<applet code=PDEMail width=624 height=168 id=applet codebase=java>\n <param name=\"subject\" value=\"$data->{subject}\">\n <param name=\"from\" value=\"$data->{whofrom}\">\n<param name=\"catno\" value=\"$data->{catno}\">\n <param name=\"date\" value=\"$data->{sent}\">\n<param name=\"to\" value=\"$data->{sendto}\">\n <param name=\"cc\" value=\"$data->{cc}\">\n<param name=\"login\" value=\"$user\">\n</applet>"; print $query -> table({-border=>0,-width=>'624'}, Tr({-align=>LEFT, -valign=>TOP}, [ td([$applet_ref]), td({-align=>RIGHT},[$help]), td([$sub_table]) ] ) ); } $contents=$data->{contents}; @ArrayofChars=split('',$contents); $n_elements=@ArrayofChars; for ($xx=0;$xx<$n_elements;$xx++) { if ($xx==0 | | ( ($ArrayofChars[$xx-1] eq "\n") && ($ArrayofChars[$xx] eq "\n") )| | ( ($ArrayofChars[$xx-1] eq "\n") && ($ArrayofChars[$xx+1] eq "\n") )){ $ArrayofChars[$xx]="<P>"; } } $" = ""; print "\n@ArrayofChars"; $i=1; } break; } print $query -> end_html; } else { # F O R M # This section creates the form for processing by the rest of the program print $query->header; print $query ->start_html ( -title=> 'PDE Comments Advanced Queries Page', -BGCOLOR=>'white', -TEXT=>'black', -LINK=>'blue', -VLINK=>'blue', -ALINK=>'blue' ); print $query ->startform(-method=>"POST", -action=>"http://myserver.com/cgi-bin/plain_comments1.pl"); print "<left>\n"; print $query->textfield(-name=>'searchs', -value=>$searchs, -maxlength=>100, -size=>50); print $query->image_button(-name=>'search', -src=>'http://myserver.com/search.gif', -border=>0); print $query->a({href=>'http://myserver.com/search.html'},'Help'),' '; print $query->a({-href=>'http://myserver.com/cgi-bin/advanced_comments.pl'},'Advanced'); print "</left>"; print "<center>"; # # Access the database asking for an unique list of commentators # $sth = $dbh->prepare("select *,oid from comments where sent >('today'::date - '2 days'::timespan)::date and bin=0 order by sent desc limit 50"); $rv= $sth->execute( ); my %dat; print <<"ENDPRINT"; <center><table WIDTH="100%"> <tr> <td WIDTH="10"></td> <td WIDTH="120"><left><font size=3 color="blue"><B><u>Cat. No.</u></b></font></left></td> <td WIDTH="120"><left><font size=3 color="blue"><B><u>Date</u></b></font></left></td> <td WIDTH="400"><left><font size=3 color="blue"><B><u>Message Subject</u></b></font></left></td> <td WIDTH="200"><left><font size=3 color="blue"><B><u>From</u></b></font></left></td> <td WIDTH="200"><left><font size=3 color="blue"><B><u>To</u></b></font></left></td> </tr> ENDPRINT while ($dat = $sth->fetchrow_hashref) { print " <tr> <td nowrap WIDTH=\"10\"><input TYPE=image NAME=\"$dat->{oid}\" src=\"http://myserver.com/datalist.gif\" border=0></td> <td nowrap WIDTH=\"120\"><left> $dat->{catno} </left></td> <td nowrap WIDTH=\"120\"><left> $dat->{sent} </left></td> <td nowrap WIDTH=\"400\"><left> $dat->{subject} </left></td> <td nowrap WIDTH=\"200\"><left> $dat->{whofrom} </left></td> <td nowrap WIDTH=\"200\"><left> $dat->{sendto} </left></td></tr> "; } print "</table>"; # Set up the Parts of the Table print $query-> end_form; print $query -> end_html(); } # Sub Routines Belong HERE! sub sendto_main { # Pushes Illegal access to the main page for login print $query->header(-Refresh=>'0; URL=http://myserver.com/cgi-bin/main.cgi'); print $query ->start_html(); print $query -> end_html; exit; } sub check_permissions { my ($user, $passwd, $page)=@_; my $dbname = "www"; my $dbh1 = DBI->connect("dbi:Pg:dbname=$dbname",$user,$passwd); my $sth1 = $dbh1->prepare("select $page from permissions where username='$user'"); my $rv1 = $sth1->execute( ); } -----------End Code---------------
|