Well, ok, but this is a very large script.  I've distilled it down to about
245 lines.

#!/usr/bin/perl - w

#---------------------------------------------------------------------------
----#
# Put any 'use' or 'require' statements here
#---------------------------------------------------------------------------
----#
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
#---------------------------------------------------------------------------
----#

#---------------------------------------------------------------------------
----#
# Variable Declarations -
#---------------------------------------------------------------------------
----#
#-- SCALAR
VARIABLES -----------------------------------------------------------#
my ($key,$value,$redirect_url,$x);
#-- FLAG
VARIABLES -------------------------------------------------------------#
my $retVal;
#-- OBJECT
VARIABLES -----------------------------------------------------------#
my %h_self;
# Designate whether debugging is set-up
$h_self{debug} = 0;
# The page header
$h_self{page_header} = qq[Content-Type: text/html\n\n];
#-- ARRAY
VARIABLES ------------------------------------------------------------#
#-- HASH
VARIABLES -------------------------------------------------------------#
# Variables pertinant to this script
my %FORM;
my %LOGIN;
my %CONFIG_INFO;
my %CUST_INFO;
my %REG_INFO;
#---------------------------------------------------------------------------
----#

#---------------------------------------------------------------------------
----#
# Start the script processing
#---------------------------------------------------------------------------
----#
$|++;           # Speed up pipe operations
eval (&main);   # Use the main function
1;              # Return value if nothing else goes right

sub main
    {
    #
Debugging ----------------------------------------------------------------#
    print $h_self{page_header} if $h_self{debug};

#---------------------------------------------------------------------------
#

    # Create objects
    CreateObjects();    # THIS EXECUTES

    # Create the database connection. Will exit if there is an error.
    CreateDatabaseConnection(); # THIS EXECUTES

    # Get configuration data.
    GetConfigData('dg_sc_config');      # THIS EXECUTES

    # Get the form data
    GetFormVars();      # THIS EXECUTES

    # Branch based on cmd
    # THIS BLOCK EXECUTES
    if ($FORM{cmd} eq 'login')
        {
        if (ValidateForm())
            {
            if (DoLogin())
                {
                SetLoginCookie();
                $FORM{cmd} = 'config_manager';
                }
            else{$FORM{cmd} = '';}
            }
        else{$FORM{cmd} = '';}
        }

        # THIS BLOCK EXECUTES
    if (!$LOGIN{auth_level}){GetLoginCookie();}

    # Check for authorization level and branch based on command
    # THIS BLOCK EXECUTES
    if ($LOGIN{auth_level})
        {
        my $auth = $LOGIN{auth_level};
        # Administrators
        if ($auth >= 10)
            {
            if ($FORM{cmd} eq 'config_manager'){;}
            # Save changes to configuration settings
            elsif ($FORM{cmd} eq 'save_changes' && $FORM{form_name} =~
m/config/)
                {if (SaveChanges()){$FORM{cmd} = 'confirm_config_changes';}}
            }
        else {$LOGIN{auth_level} = 0;}
        }
    else {$LOGIN{auth_level} = 0;}

    PrintAdminPage();
    }   #end main

# Various methods defined here....

sub PrintAdminPage
    {
    # THIS BLOCK EXECUTES
    if (!$h_self{debug} && !$h_self{header_printed})
        {
        print $h_self{page_header};
        $h_self{header_printed} = 1;
        }

    my ($content,$heading);
    my $title = qq[Design Group Shopping Cart Administrator - ];

    #
Debugging ----------------------------------------------------------------#
    print qq[<b>\$FORM{cmd} is $FORM{cmd} and \$LOGIN{auth_level} is
$LOGIN{auth_level}</b><br />] if $h_self{debug};

#---------------------------------------------------------------------------
#

    # Configuration Screens
    # THE SCRIPT BRANCHES CORRECTLY
    elsif($FORM{cmd} eq 'config_manager')
        {
        $heading = qq[Configuration Manager];
        $FORM{form_name} = 'form_sc_config_manager';
        GetConfigTableInfo();
        $content = GetConfigManagerScreen($heading);
        }
    elsif ($FORM{cmd} eq 'edit_email_config')
        {
        $heading = qq[Edit Email Configuration Settings];
        $FORM{form_name} = 'form_sc_edit_email_config';
        GetConfigTableInfo();
        $content = GetConfigEditScreen($heading);
        }
    elsif ($FORM{cmd} eq 'edit_dir_config')
        {
        $heading = qq[Edit Directory Configuration Settings];
        $FORM{form_name} = 'form_sc_edit_dir_config';
        GetConfigTableInfo();
        $content = GetConfigEditScreen($heading);
        }
    elsif ($FORM{cmd} eq 'edit_gateway_config')
        {
        $heading = qq[Edit Payment Gateway Configuration Settings];
        $FORM{form_name} = 'form_sc_edit_gateway_config';
        GetConfigTableInfo();
        $content = GetConfigEditScreen($heading);
        }
    elsif ($FORM{cmd} eq 'confirm_config_changes')
        {
        $heading = qq[Configuration Changes Confirmation];
        $content = GetConfirmConfigScreen();
        }

#WHEN THE CONFIGURATION CHANGES ARE SAVED, THE DATA IS SAVED TO THE
DATABASE.
#HOWEVER, THIS "HERE DOCUMENT" DOES NOT PRINT TO SCREEN.  INSTEAD, THE USER
#IS PROMPTED TO EITHER SAVE OR OPEN A FILE DOWNLOAD OF THE .CGI SCRIPT.  IF
#THE FILE IS SAVED, IT DOES CREATE THE HTML, BUT IT IS IN A FILE NAMED
#dgCartAdmin.cgi.  THE STRANGE THING IS THAT IF ONE OF THE OTHER COMMANDS
ARE
#SENT IN THE SCRIPT, THIS "HERE DOCUMENT" PRINTS EXACTLY AS IT SHOULD.
print<<HTML;
<html>
<head>
<title>$title$heading</title>
<meta http-equiv="content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="content-language" content="en-US">
<link rel="stylesheet" type="text/css"
href="$h_self{cfg_sc_web_dir_unsec}stylesheets/styles.css">
<script src="$h_self{cfg_sc_web_dir_unsec}scripts/dgWindowManager.js"
language="JavaScript"></script>
<script src="$h_self{cfg_sc_web_dir_unsec}scripts/dgImageManager.js"
language="JavaScript"></script>
<style>
#hidden_cmd {width:1px;height:1px;}
</style>
<script language="javascript">
<!-- Hide from older browsers
var cmd;

function setCmd(cmd)
    {
    document.all.hidden_cmd.innerHTML='<input type="hidden" name="cmd"
value="' + cmd + '">';
    }
// Stop Hiding -->
</script>
</head>

<body>
<center>

<a name="top"></a>

<table name="Header" width="755" height="100" cellpadding="1"
cellspacing="1" bgcolor="skyblue" class="thinborder_red">
    <tr valign="middle">
        <td height="100" width="149" align="center">
            <a href="http://www.uponthemountain.com"; target="_top"
class="img_lnk"><img src="$h_self{cfg_sc_web_dir_unsec}images/logo.gif"
height="75" width="75" alt="Up On The Moutain Design Group" border="0"></a>
        </td>
        <td width="450" align="center">
            <span style="font-family:'Times New
Roman';font-size:20pt;font-weight:bold;color:darkslategray;">Up On The
Mountain Design Group<br />Shopping Cart Administrator</span>
        </td>
        <td width="149" align="center" valign="middle">&nbsp;</td>
    </tr>
</table>

<table width="755" cellpadding="1" cellspacing="0" border="0"
bgcolor="azure" class="rl_thinborder_red">
    <tr>
        <td width="150" align="center" valign="top"
class="r_thinborder_red">
<!-- Begin Left Nav
Section ---------------------------------------------------->
            <table width="148" cellpadding="1" cellspacing="0" border="0"
bgcolor="azure" >
                <tr><td width="148" height="5"></td></tr>
                <tr><td align="center" valign="middle"
background="$h_self{cfg_sc_web_dir_unsec}images/button.gif" height="25"><a
href="$h_self{cfg_sc_cgi_dir_unsec}dgCartAdmin.cgi?cmd=config_manager"
class="nav">Configuration Manager</a></td></tr>
                <tr><td height="5"></td></tr>
                <tr><td align="center" valign="middle"
background="$h_self{cfg_sc_web_dir_unsec}images/button.gif" height="25"><a
href="$h_self{cfg_sc_cgi_dir_unsec}dgCartAdmin.cgi?cmd=account_manager"
class="nav">Account Manager</a></td></tr>
                <tr><td height="5"></td></tr>
                <tr><td align="center" valign="middle"
background="$h_self{cfg_sc_web_dir_unsec}images/button.gif" height="25"><a
href="$h_self{cfg_sc_cgi_dir_unsec}dgCartAdmin.cgi?cmd=item_manager"
class="nav">Item Manager</a></td></tr>
                <tr><td height="5"></td></tr>
                <tr><td align="center" valign="middle"
background="$h_self{cfg_sc_web_dir_unsec}images/button.gif" height="25"><a
href="$h_self{cfg_sc_cgi_dir_unsec}dgCartAdmin.cgi?cmd=template_manager"
class="nav">Template Manager</a></td></tr>
                <tr><td height="5"></td></tr>
                <tr><td align="center" valign="middle"
background="$h_self{cfg_sc_web_dir_unsec}images/button.gif" height="25"><a
href="$h_self{cfg_sc_cgi_dir_unsec}dgCartAdmin.cgi?cmd=this"
class="nav">This</a></td></tr>
             </table>
<!-- End Left Nav
Section ------------------------------------------------------>
        </td>
        <td width="600" height="400" valign="top" align="center">
        <form name="$FORM{form_name}"
action="$h_self{cfg_sc_cgi_dir_unsec}dgCartAdmin.cgi" method="POST">
        <input type="hidden" name="form_name" value="$FORM{form_name}">
        <input type="hidden" name="referer" value="$FORM{referer}">
        $content
        <span id="hidden_cmd"></span>
        </form>
        </td>
    </tr>
</table>

<!-- Begin Footer
Section ------------------------------------------------------>
<table width="755" cellpadding="1" cellspacing="0" border="0"
bgcolor="black" class="thinborder_red">
    <tr>
        <td width="750" align="center" class="centerfooter">
            &copy;&nbsp;2000 Up On The Mountain Design Group<br>
            <a href="mailto:$h_self{cfg_email_web_err}";
class="footer">$h_self{cfg_email_web_err}</a>
        </td>
    </tr>
</table>
<!-- End Footer
Section -------------------------------------------------------->

</center>
</body>
</html>
HTML
    }

-----Original Message-----
From: Charles K. Clarkson [mailto:[EMAIL PROTECTED]
Sent: Saturday, September 13, 2003 8:00 PM
To: 'Ron Goral'; 'Perl Beginners'
Subject: RE: Browser wants to do a file download on a CGI script


Ron Goral <[EMAIL PROTECTED]> wrote:

: the error does not occur until the script calls itself
: to save some settings to a database.  When I open or
: save the file that is being downloaded, it is the HTML
: that is supposed to display in the next step of the
: script.

    Sounds like we'll need to see the code to provide
assistance.


Charles K. Clarkson
--
Head Bottle Washer,
Clarkson Energy Homes, Inc.
Mobile Home Specialists
254 968-8328




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to