Solved

Pass Parameter and Create File on Client

Posted on 1998-11-23
19
354 Views
Last Modified: 2012-08-14
I want my perl program to read data from a cursor (which I already know how to build) and print the rows (which I already know how to do) out to a file on the client C: Drive (I do not know how to do this) and receiving parameters (I do not know how to do this).

Question:  In the while loop what code would I use to:
1.  Open the file on the client C: drive
2.  Receive variables from the calling process (An Array and A Variable) and use this in my subroutine.

    Thanks

Here is the javascript funtion and subroutine it calls, which needs the passed data to print the data to the C; drive:

JAVASCRIPT:
print "<SCRIPT>";
print "function senddata()";
print "{";
print "alert('Sending Data');";
SendToPC();
print "alert('Done Sending Data');";
print "}";
print "</SCRIPT>";

PERL SUBROUTINE:
sub SendToPC
{
# get FYTables, CHDs, sqlselect, sqlwhere from the calling processes (IN a JavaScript Function)
open (REPORTFILE, ">ANNA.TXT");
foreach $FromClause (@FYTables)
{
foreach $Columns (@CHDs)
{
printf (REPORTFILE "$Columns,");
}
$sql = "$sqlselect FROM $FromClause $sqlwhere";
$cursor = $db->prepare($sql) or die "Unable to Execute SQL: $DBI::errstr";
$cursor->execute or die "Unable to Execute SQL: $DBI::errstr" ;
while (@row = $cursor->fetchrow_array)
{foreach $Fields (@row){printf (REPORTFILE "$Fields, ");}
printf (REPORTFILE "\n");
$countit++;
}
printf (REPORTFILE "\n");
printf (REPORTFILE "$FromClause\n");
}
printf (REPORTFILE "REPORT COMPLETE\n");
close (REPORTFILE);
}


    Please Help
    Thanks
     
0
Comment
Question by:akeller
  • 10
  • 9
19 Comments
 

Author Comment

by:akeller
Comment Utility
Please Help.
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
I am confused by what you are trying to do; please clarify and it will help you get an answer.

The best I can figure out, you want a perl CGI program on a web server to write javascript into a page, and when the client browser executes that javascript it is supposed to call a perl CGI program on the web server to query data from a SQL database, and then write the resulting data to a file on C drive of the client.

That, however, is impossible to do just as I stated it, so I am hoping I am wrong.
0
 

Author Comment

by:akeller
Comment Utility
I currently have a perl program that writes data from my oracle database to a document in the form of an HTML TABLE>.  I have added a download button to the document.

I now want to write a JavaScript/Subroutine to reread the oracle data and create an ascii flat file on the clients pc instead of in an HTML Document.  If I can't write it to the client PC I understand.  But, The question would then become what code would I use to write it to the server and send it to the client pc.  The above scripts were started in that direction but I'll have hundreds of users utilizing the server so I will need a solution that gives the file on the server a unique name.  I still need to know how to pass parameters from the JavaScript to the perl Subroutine.  

POINTS INCREASED
FOR EXTRA HELP -- QUESTION DEVIATION
Thanks
Anna
0
 

Author Comment

by:akeller
Comment Utility
Please Help!  Points Increased.
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
Javascript can not easily write to the clients C drive. It can with a signed script and requesting extra privileges, but it's complicated and people tend to get very nervous when something off the net asks to write to their hard drives.

Javascript can also not get data from the server other than by using Java (not recommended) or by loading a new URL.

Let me know if this could work: have your 'download data' button call your same script on the server to re-download the data, only with an extra parameter which tells your script not to put it into a HTML table but instead to write it as straight text. The user can then use browser "save as" to save to a file on their PC.

This is pretty equivalent to but a little simpler than writing to a file on the server and then redirecting the browser to that page.

If this would work I'll go into more detail on how to do it. If not, say why and I'll try to come up with a better way.
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
As an addendum to my suggestion -

Instead of writing the text back to the browser as  straight text, I could also tell you how to change the headers so that Netscape pops up a Save As box automatically, with the proper filename. IE is a little trickier though something similar could probably be done (I don't have IE4 so don't know about it, you'd have to test).
0
 

Author Comment

by:akeller
Comment Utility
I only want the saveas to comeup when the botton is pressed. Can that be done?
How do I get the end of lines in the data without '<br>' tags?  Almost there not quite.  I'm upping the points.

A little more help please.
0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
The button would be part of a form which includes (as <input type=hidden> fields) all the parameters necessary to recreate the data. The form calls your perl CGI script when the user presses the button. The script then returns the data in text form rather than html.

You get end of lines with "\n", as long as the browser sees the file as a text file it will break on just that. The "getting it to see the file as a text file" part is as I said before tricky because it might be browser-specific, since you are trying to do something slightly nonstandard.

For Netscape, you can make the "Save As" box pop up by writing the Content-type header line as:

print "Content-type: application/octet-stream\r\n";

If you just want the data to show up as text in the browser, the header should be
print "Content-type: text/plain\r\n";

For IE, I am not sure if that will work, Microsoft hates to do things the same as Netscape.  Which browser are you testing with? Are you designing for both IE and Netscape, or do you have a captive audience where you know the browser type?


Let me know if this makes sense to you.
0
 

Author Comment

by:akeller
Comment Utility
I get this error:

CGI Error

The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:

HTTP/1.0 200 OK
Content-type: application/octet-stream

Please help!!  Here is the code:

print "HTTP/1.0 200 OK\n";
print "Content-type: application/octet-stream\r\n";
print "<HTML>\n";

0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 6

Expert Comment

by:alamo
Comment Utility
The line you replaced must have ended with \r\n\r\n or \n\n, you need a blank line to signal the server the headers are done. I personally prefer to put
print "\r\n";
on a separate line at the end of the header prints so that if I move things around or add a header I don't get strange errors by forgetting the extra \r\n.

So, do that, after the print Content-type line. Also, take out the print "<HTML>" since your goal is to print simple text not html.
0
 

Author Comment

by:akeller
Comment Utility
Now nothing works in CGI3 (no Data message):
Summary:
1.  GGI1.pl  Form to get data for request, runs CGI2.pl
2.  CGI2.pl  Gets form data and generates TABLE of data from oracle with DOWNLOAD BUTTON.  The following is the form code for the download button:
print "<FORM NAME='DOWNFORM' METHOD='POST' ACTION='CGI3.pl'>";
print "<input type=submit value='Down Load'>";
print "</FORM>";
3.  CGI3.pl Should get data from the CGI2.pl related to scalars and arrays it created from the form  information.  I still don't know how to pass that data from 'CGI2.pl' to 'CGI3.pl'.  When I press the DOWNLOAD button I now get a 'no data' error window.  My CGI3.pl looks like this:

use DBI;
$db = DBI->connect('dbi:Oracle:', q{akeller/akeller@(DESCRIPTION=
  (ADDRESS=(PROTOCOL=TCP)(HOST= 209.22.38.81)(PORT=1601))
  (CONNECT_DATA=(SID=CERPDEV1)))}, "") or die "Unable to connect: $DBI::errstr";
print "HTTP/1.0 200 OK\n";
print "Content-type: application/octet-stream\n\n";
foreach $FromClause (@FYTables)
{
   $sql = "$sqlselect FROM $FromClause $sqlwhere";
   $SQLCntBack = "$sqlcount FROM $FromClause $sqlwhere";
   $cursor = $db->prepare($SQLCntBack) or die "Unable to Execute SQL: $DBI::errstr";
   $cursor->execute or die "Unable to Execute SQL: $DBI::errstr" ;
   @row = $cursor->fetchrow_array or die "<br>FETCH DIED:<br> $DBI::errstr";
   if ($row[0] lt 1)
   {
   print "$FromClause NO DATA for this FY $FromClause Report.\n";
   }else
   {
   $TotalFound = 1;
   print "$FromClause\n";
   }  
   if ($NotAll == 1)
   {
     $AllStmnt = "$sqlselect FROM $FromClause $sqlwhere";
   }  else
   {
     $AllStmnt = "Select ALL from $FromClause $sqlwhere";
   }
   $cursor = $db->prepare($sql) or die "Unable to Execute SQL: $DBI::errstr";
   $cursor->execute or die "Unable to Execute SQL: $DBI::errstr" ;
   print "\n";
   foreach $Columns (@CHDs)
   {
    print "$Columns, ";
   }
   print "\n";
   while (@row = $cursor->fetchrow_array)
   {
      foreach $Fields (@row)
      {
         print "$Fields, ";
      }
      print "\n";
      $countit++;
   }
   print "\n";
   if ($TotalFound eq 0)
   {
      print "NO DATA FOUND\n";
   } else
   {
      print "REPORT COMPLETE\n";
   }
   $cursor->finish;
   $db->disconnect;

}


We are so close.  Please Help.  Points raised as much as possible.
Thanks

0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
It's impractible to pass the actual data from CGI2.pl to CGI2.pl, the way to do it is to pass the parameters the user entered on the first form via hidden fields, and then use the same code in CGI3 as you used in CGI2 to turn the form fields into FYTables, CHDs, sqlselect, sqlwhere, etc.

The idea is that CGI3 will get all the same form values passed to it as CGI2 had, and will use them to get the data again.

You didn't post the original form or the code that interprets the form so I can't give you exact instructions, but here's a simple example of what I mean by hidden fields.

Suppose the original form is generated by CGI1 as:

print "<FORM NAME='ORIGINALFORM' METHOD='POST' ACTION='CGI2.pl'>";
print "Field 1: <input type=text name='field1'><br>\n";
print "Field 2: <input type=text name='field2'><br>\n";
print "<input type=submit value='Show Results'>";
print "</FORM>";

To get the data your CGI2 parses the POST data. Let's assume you build a hash out of the form fields, so that the value of field1 is in $FORM{field1} and the value of field2 is in $FORM{field2}. (This is the best but not the only way to do it).

So CGI2 would then print the download button as:

print "<FORM NAME='DOWNFORM' METHOD='POST' ACTION='CGI3.pl'>";
print "<input type=hidden name='field1' value='$FORM{field1}'>\n";
print "<input type=hidden name='field2' value='$FORM{field2}'>\n";
print "<input type=submit value='Down Load'>";
print "</FORM>";

Now CGI3 will have available to it the same information CGI2 had to generate the report.

Hope this helps, if the part about parsing the form data is unclear post the code you are using now in CGI2 and I'll use it in my example.
0
 

Author Comment

by:akeller
Comment Utility
OK.  I tried this and now get the following in the file that is created on the pc:

CERPTB1>Report Request  Select ALL from CERPTB1  WH
Returning 281 Rows
DBD::Oracle::db prepare failed: ORA-00936: missing expression (DBD: error possibly near <*> indicator at char 9 in 'SELECT  <*>FROM CERPTB1  WH') at W:\Inetpub\CERPS\download.pl line 80.
Unable to Execute SQL: ORA-00936: missing expression (DBD: error possibly near <*> indicator at char 9 in 'SELECT  <*>FROM CERPTB1  WH') at W:\Inetpub\CERPS\download.pl line 80.
Database handle destroyed without explicit disconnect.


CGI2.pl uses the following code to pass the form data to the CGI3.pl (My intent is to pass the full form already passed to CGI2.pl from CGI1.pl :

print "<A NAME=CerpToc><H2>CHOOSE REPORT</H2></A>";
print "<FORM NAME='DOWNFORM' METHOD='POST' ACTION='download.pl'>";
print "<input type=submit value='Down Load'>";
print "<input type=hidden name=field1 value=%frmFlds>";
print "</FORM>";

CGI 3 Looks like this:

$| = 1;
use DBI;
$ENV{ORACLE_HOME} = 'W:\ORANT';
my($db,$cursor,$sql,$countit,$sqlsize,$bitbucket,$sqlselect, $sqlcount,$sqlwhere, $holddates, $NotAll, $SQLCntBack, @CHDs, $WhereStart, $WhereEnd, @FYTables, $CountFound, $TotalFound, $AllStmnt);
$db = DBI->connect('dbi:Oracle:', q{xxxx/xxxx@(DESCRIPTION=
  (ADDRESS=(PROTOCOL=TCP)(HOST= xxx.xx.xx.x1)(PORT=xxxx))
  (CONNECT_DATA=(SID=xxxxx)))}, "") or die "Unable to connect: $DBI::errstr";
if ( !defined $db )
{
print "HTTP/1.0 200 OK\n";
print "Content-type: text/html\n\n";
print "<HTML>\n";
print "<HEAD><TITLE>Invalid Login</TITLE></HEAD>\n";
print "<H1>Invalid Oracle Login</H1>\n";
print "<HR>\n";
print "Login Unsuccessful\n";
print "Cannot connect\n";
print "</BODY>\n";
print "</HTML>\n";
}
else
{
$sqlcount = "SELECT COUNT(*) ";
$sqlselect = "SELECT ";
$sqlwhere = " WHERE ";
$countit = 1;
print "HTTP/1.0 200 OK\n";
print "Content-type: application/octet-stream\n\n";
$NotAll = 0;
my(%frmFlds);
getFormData(\%frmFlds);
$sql = "SELECT * FROM CERPTOC $WhereStart $WhereEnd";
$cursor = $db->prepare($sql) or die "Unable to Get TOC with SQL: $DBI::errstr";
$cursor->execute or die "Unable to Get TOC with SQL: $DBI::errstr";
while (@row = $cursor->fetchrow_array)
{
      push (@FYTables, @row[0]);
}
if ($NotAll == 1)
{
      $sqlsize = length($sqlselect);
      $bitbucket = substr($sqlselect,$sqlsize-2,1);
      $sqlselect = substr($sqlselect,0,$sqlsize-2);
} else
{
      @CHDs = ("FIPC","REG_NUM", "EXP_REIMB", "GA", "TA", "BFY", "EFY","FUND_SYM","SUBHEAD","SOURCE_CLASS","BCN","SUBALLOTMENT","AAA","TYPE_CODE","VOUCHER","PAA","OBJ_CLASS","RPT_OFFICE ","DSSN","CLASS","CD_CODE","RPT_MTH","REG_MTH","DAY_PAID","IBOP","IDA_CODE","SUSP_CODE","COST_CODE","NET_AMOUNT","DOC_NUM","SPINN","ACRN","PAY_TYPE","SUB_TRAN","DISCOUNT_AMT","DIST_CODE","CLIN","FILLER","YORN","ERROR_CD","YYYYMM");
}

$sqlsize = length($sqlwhere);
$bitbucket = substr($sqlwhere,$sqlsize-4,3);
$sqlwhere = substr($sqlwhere,0,$sqlsize-4);
$TotalFound = 0;
foreach $FromClause (@FYTables)
{
   $sql = "$sqlselect FROM $FromClause $sqlwhere";
   $SQLCntBack = "$sqlcount FROM $FromClause $sqlwhere";
   $cursor = $db->prepare($SQLCntBack) or die "Unable to Execute SQL: $DBI::errstr";
   $cursor->execute or die "Unable to Execute SQL: $DBI::errstr" ;
   @row = $cursor->fetchrow_array or die "<br>FETCH DIED:<br> $DBI::errstr";
   if ($row[0] lt 1)
   {
   print "NO DATA  for this FY $FromClause Report.";
   }else
   {
   $TotalFound = 1;
   print "$FromClause";
   }  
if ($NotAll == 1)
{
     $AllStmnt = "$sqlselect FROM $FromClause $sqlwhere";

}  else
{
     $AllStmnt = "Select ALL from $FromClause $sqlwhere";
}
   print ">Report Request  $AllStmnt\n";
   print "Returning @row Rows\n";
   #print "SQL:  $sql";
   #print "AllStmnt: $AllStmnt";
   $cursor = $db->prepare($sql) or die "Unable to Execute SQL: $DBI::errstr";
   $cursor->execute or die "Unable to Execute SQL: $DBI::errstr" ;
    foreach $Columns (@CHDs)
   {
    print "$Columns,";
   }
   print "\n";
   while (@row = $cursor->fetchrow_array)
   {
      foreach $Fields (@row)
      {
         print "$Fields,";
      }
      print "\n";
      $countit++;
   }
}
if ($TotalFound eq 0)
{
print "NO DATA FOUND";
} else
{
print "REPORT COMPLETE";
}
$cursor->finish;
$db->disconnect;
}

sub getFormData
{
    my($hashRef) = shift;
    my($buffer) = "";

    if ($ENV{'REQUEST_METHOD'} eq 'GET')
    {
        $buffer = $ENV{'QUERY_STRING'};
    }
    else
    {
        read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    }

    foreach (split(/&/, $buffer))
    {
        my($key, $value) = split(/=/, $_);
        $key   = decodeURL($key);
        $value = decodeURL($value);
        $value =~ s/(<P>\s*)+/<P>/g;   # compress multiple <P> tags.
        $value =~ s/</&lt;/g;           # turn off all HTML tags.
        $value =~ s/>/&gt;/g;
        $value =~ s/&lt;b&gt;/<b>/ig;    # turn on the bold tag.
        $value =~ s!&lt;/b&gt;!</b>!ig;
        $value =~ s/&lt;i&gt;/<b>/ig;    # turn on the italic tag.
        $value =~ s!&lt;/i&gt;!</b>!ig;
        $value =~ s!\cM!!g;            # Remove unneeded carriage returns.
        $value =~ s!\n\n!<P>!g;        # Convert 2 newlines into paragraph.
        $value =~ s!\n! !g;            # Convert newline into spaces.
        $value =~ s!a-z!A-Z!g;     # Convert newline into spaces.
        $value =~ tr/a-z/A-Z/;
        %{$hashRef}->{$key} = $value;
        #print "<STRONG>Form Fields:</STRONG>  $key HOLDS -> '$value'<br>\n";
        if ($key eq "Document" && $value ne '')
        {
              $sqlwhere = "$sqlwhere DOC_NUM = '$value' and ";
        }
        if ($key eq "Voucher" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        $holddate = substr($value,8,3);
        if ($key eq "FromDate" && $holddate ne '0' )
        {
              $FromDatePulled = substr($value,4,6);
              $WhereStart = "WHERE (START_DATE BETWEEN '$FromDatePulled' ";
              $WhereEnd = " (END_DATE BETWEEN '$FromDatePulled' ";
              $sqlwhere = "$sqlwhere (YYYYMM BETWEEN '$FromDatePulled' and ";
        }
        $holddate = substr($value,6,3);
        if ($key eq "ToDate" && $holddate ne '0')
        {
              $ToDatePulled = substr($value,2,6);
              $WhereStart = "$WhereStart and '$ToDatePulled') or ";
              $WhereEnd = "$WhereEnd and '$ToDatePulled')";
              $sqlwhere = "$sqlwhere '$ToDatePulled') and ";
        }
        if ($key eq "FIPC" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        if ($key eq "REG_NUM" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        if ($key eq "FUND_SYM" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        if ($key eq "SUBHEAD" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        if ($key eq "BCN" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        if ($key eq "AAA" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        if ($key eq "RPT_OFFICE" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        if ($key eq "DSSN" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }
        if ($key eq "COST_CODE" && $value ne '')
        {
              $sqlwhere = "$sqlwhere $key = '$value' and ";
        }

        if ($key eq "CheckAllBox" && $value eq 'ON')
        {
              $sqlselect = "SELECT FIPC, REG_NUM, EXP_REIMB, GA, TA, BFY, EFY, FUND_SYM, SUBHEAD, SOURCE_CLASS, BCN, SUBALLOTMENT, AAA, TYPE_CODE, VOUCHER, PAA, OBJ_CLASS, RPT_OFFICE, DSSN, CLASS, CD_CODE, RPT_MTH, REG_MTH, DAY_PAID, IBOP, IDA_CODE, SUSP_CODE, COST_CODE, TO_CHAR(NET_AMOUNT,'B999999999.99'), DOC_NUM, SPINN, ACRN, PAY_TYPE, SUB_TRAN, TO_CHAR(DISCOUNT_AMT,'B9999999.99'), DIST_CODE, CLIN, FILLER, YORN, ERROR_CD, YYYYMM ";
              $NotAll = 0;
        }
        if ($key eq "FIPC1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect FIPC, ";
              push (@CHDs, "FIPC");
              $NotAll = 1;
        }
        if ($key eq "REG1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect REG_NUM, ";
              push (@CHDs, "REG_NUM");
              $NotAll = 1;
        }
        if ($key eq "GA1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect GA, ";
              push (@CHDs, "GA");
              $NotAll = 1;
        }
        if ($key eq "TA1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect TA, ";
              push (@CHDs, "TA");
              $NotAll = 1;        }
        if ($key eq "BFY1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect BFY, ";
              push (@CHDs, "BFY");
              $NotAll = 1;
        }
        if ($key eq "EFY1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect EFY, ";
              push (@CHDs, "EFY");
              $NotAll = 1;
        }
        if ($key eq "FUND_SYM1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect FUND_SYM, ";
              push (@CHDs, "FUND_SYM");
              $NotAll = 1;
        }
        if ($key eq "SUBHEAD1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect SUBHEAD, ";
              push (@CHDs, "SUBHEAD");
              $NotAll = 1;
        }
        if ($key eq "SOURCE_CLASS" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect SOURCE_CLASS, ";
              push (@CHDs, "SOURCE_CLASS");
              $NotAll = 1;
        }
        if ($key eq "BCN1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect BCN, ";
              push (@CHDs, "BCN");
              $NotAll = 1;
        }
        if ($key eq "SUBALLOTMENT" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect SUBALLOTMENT, ";
              push (@CHDs, "SUBALLOTMENT");
              $NotAll = 1;
        }
        if ($key eq "AAA1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect AAA, ";
              push (@CHDs, "AAA");
              $NotAll = 1;
        }
        if ($key eq "TYPE_CODE" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect TYPE_CODE, ";
              push (@CHDs, "TYPE_CODE");
              $NotAll = 1;
        }
        if ($key eq "VOUCHER" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect VOUCHER, ";
              push (@CHDs, "VOUCHER");
              $NotAll = 1;
        }
        if ($key eq "PAA" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect PAA, ";
              push (@CHDs, "PAA");
              $NotAll = 1;
        }
        if ($key eq "OBJ_CLASS" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect OBJ_CLASS, ";
              push (@CHDs, "OBJ_CLASS");
              $NotAll = 1;
        }
        if ($key eq "RPT_OFFICE1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect RPT_OFFICE, ";
              push (@CHDs, "RPT_OFFICE");
              $NotAll = 1;
        }
        if ($key eq "DSSN1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect DSSN, ";
              push (@CHDs, "DSSN");
              $NotAll = 1;
        }
        if ($key eq "CLASS" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect CLASS, ";
              push (@CHDs, "CLASS");
              $NotAll = 1;
        }
        if ($key eq "CED_CODE" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect CD_CODE, ";
              push (@CHDs, "CD_CODE");
              $NotAll = 1;
        }
        if ($key eq "RPT_MTH" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect RPT_MTH, ";
              push (@CHDs, "RPT_MTH");
              $NotAll = 1;
        }
        if ($key eq "REG_MTH" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect REG_MTH, ";
              push (@CHDs, "REG_MTH");
              $NotAll = 1;
        }
        if ($key eq "PAY_PAID" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect PAY_PAID, ";
              push (@CHDs, "PAY_PAID");
              $NotAll = 1;
        }
        if ($key eq "IBOP" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect IBOP, ";
              push (@CHDs, "IBOP");
              $NotAll = 1;
        }
        if ($key eq "IDACD" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect IDA_CODE, ";
              push (@CHDs, "IDA_CODE");
              $NotAll = 1;
        }
        if ($key eq "SUSP_CODE" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect SUSP_CODE, ";
              push (@CHDs, "SUSP_CODE");
              $NotAll = 1;
        }
        if ($key eq "COST_CODE1" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect COST_CODE, ";
              push (@CHDs, "COST_CODE");
              $NotAll = 1;
        }
        if ($key eq "NET_AMOUNT" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect TO_CHAR(NET_AMOUNT,'B999999999.99'), ";
              push (@CHDs, "NET_AMOUNT");
              $NotAll = 1;
        }
        if ($key eq "DOCUMENT" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect DOC_NUM, ";
              push (@CHDs, "RDOC_NUM");
              $NotAll = 1;
        }
        if ($key eq "SPIIN" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect SPINN, ";
              push (@CHDs, "SPINN");
              $NotAll = 1;
        }
        if ($key eq "ACRN" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect ACRN, ";
              push (@CHDs, "ACRN");
              $NotAll = 1;
        }
        if ($key eq "PAY_TYPE" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect PAY_TYPE, ";
              push (@CHDs, "PAY_TYPE");
              $NotAll = 1;
        }
        if ($key eq "SUB_TRAN" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect SUB_TRAN, ";
              push (@CHDs, "SUB_TRAN");
              $NotAll = 1;
        }
        if ($key eq "DISCOUNT_AMT" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect TO_CHAR(DISCOUNT_AMT,'B9999999.99'), ";
              push (@CHDs, "DISCOUNT_AMT");
              $NotAll = 1;
        }
        if ($key eq "DIST_CODE" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect DIST_CODE, ";
              push (@CHDs, "DIST_CODE");
              $NotAll = 1;
        }
        if ($key eq "CLIN" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect CLIN, ";
              push (@CHDs, "CLIN");
              $NotAll = 1;
        }
        if ($key eq "YORN" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect YORN, ";
              push (@CHDs, "YORN");
              $NotAll = 1;
        }
        if ($key eq "YYYYMM" && $value eq 'ON')
        {
              $sqlselect = "$sqlselect YYYYMM, ";
              push (@CHDs, "YYYYMM");
              $NotAll = 1;
        }
    }
}

sub decodeURL
{
    $_ = shift;
    tr/+/ /;
    s/%(..)/pack('c', hex($1))/eg;
    return($_);
}



HELP!!!!! Points Increased....note (1) The file is starting to create but (2) the form data doesn't seem to be getting there to create the dynamic SQL.

Thanks.

0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
In CGI2,

print "<input type=hidden name=field1 value=%frmFlds>";

won't work for lots of reasons: you can't do that and parse it back out in getFormData unchanged. At the very least the order of the keys will be scrambled (because it was inside a hash), and your code won't build the where clause correctly if the field order changes.

The solution is to build the hidden-field string as you decode it. In CGI2 add a variable $hiddenfields to the my() at the top and change
 print "<input type=hidden name=field1 value=%frmFlds>";
to
 print $hiddenfields;
Also in CGI2, in getFormData, after the line
 %{$hashRef}->{$key} = $value;
add the line
 $hiddenfields .= "<input type=hidden name=$key value='$value'>\n";

This way as CGI2 is decoding the fields it is simultaneously building up a string with the fields to pass to CGI3, which are guaranteed to be identical.
0
 

Author Comment

by:akeller
Comment Utility
WOW This is great!  We get data now but may we raise the points and be so bold as to ask.

1.  The default file name extension is .exe  but we would like it to be .txt .... is that possible. How?

2.  Is processing done before we get the saveas message or after?  If after how can we display a processing .... please wait message?

THIS IS GREAT.  Points Upped.
Once you answer the above questions please lock so I can give you a A+++++++

THansk!!!!

0
 
LVL 6

Expert Comment

by:alamo
Comment Utility
Change the header line

print "Content-type: application/octet-stream\n\n";
to
print "Content-type: application/octet-stream\n";

and add a line after it
print "Content-disposition: filename=\"filename.txt\"\n\n";

This should make netscape default the filename to filename.txtI don't know about IE, you'd have to try it. It's been a while since I had to do this sort of thing myself, there may be a better way now but I don't know it.

The SaveAs pops up when the browser has received the headers- your script doesn't send the headers until it's done processing. If you want the SaveAs box to pop up earlier, try sending the headers at the start of the script. (The web server may still intercept the headers and delay sending them to the browser, you'll have to test).
0
 

Author Comment

by:akeller
Comment Utility
Great JOB! Please have alamo lock so I can give alamo the points.
0
 
LVL 6

Accepted Solution

by:
alamo earned 180 total points
Comment Utility
Thanks, glad I could help!
0
 

Author Comment

by:akeller
Comment Utility
Thanks
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now