bazz
02-16-2005, 06:33 PM
below is the code. When I add the sub put_header containg the line print "Location: $Header"; the rest of the subs stop printing so that my page only has the header in it.
if I remove the header the content prints out, however, if I manage to get it to print the sub put_footer, I also lose the content. What thing stupid am I doing wrong?
#!/usr/bin/perl -w
#
#
# Print the HTML content header; set global names
#
$Root = $ENV{"DOCUMENT_ROOT"};
$Path = $ENV{"PATH_INFO"};
$Referer = $ENV{"HTTP_REFERER"};
$Request = $ENV{"REQUEST_URI"};
$Method = $ENV{"REQUEST_METHOD"};
$Query = $ENV{"QUERY_STRING"};
$Path =~ s/[^a-zA-Z0-9\.]//g;
$MenuName= $Path;
$MenuName=~ s/\_/ /g; # my changes to try to entitle the menu
if ($Path eq "") {
$Path = "ALL";
}
#################################
#MY AMENDMENT
###############################
$Directory = $Request;
chomp ($Directory);
($vars1,$vars2,$vars3,$vars4,$vars5) = split(/\//,$Directory);
#That splits to give vars like these?
#$vars2 = cgi-bin
#$vars3 = ClientName
#$vars4 = MenuType
#$vars5 = file.pl
#################################
#establish incoming domain and split to get name
###############################
$Domain = $Referer;
chomp ($Domain);
($ref1,$ref2,$ref3) = split(/\//,$Domain);
#That splits to give vars like these?
#$ref3 = cms.thechrissystem.com
##################################
#split domain name into it components
##################################
chomp ($ref3);
($dom1,$dom2,$dom3) = split(/\./,$ref3);
#$dom1 = cms
#$dom2 = thechrissystem
#$dom3 = com
###################################
#Set headers and footers
###################################
$Header = "/headers_and_footers/$vars3/header.htm";
$Footer = "/headers_and_footers/$vars3/footer.htm";
#$client = $dom2;
#if (-e "/headers_and_footers/$client/header.htm")
#{
#$Header = "/headers_and_footers/$client/header.htm";
#$Footer = "/headers_and_footers/$client/footer.htm";
#}
#else
#{
#sub put_headers {
#
#printContent-type: text/html;
#print "file not available";
#}
#}
###############################
#END OF MY AMENDMENT
###############################
#$Files = `ls $Root/cgi-bin/a_default/Meal_Menus/files/$Path/*`;
#$Files = `ls $Root/$vars2/$vars3/$vars4/files/$Path/*`;
$Action = "View";
$Fdir = "$Root/$vars2/$vars3/$vars4/files/ALL";
$Base = "NOFILE";
#
# Call processing functions
#
&get_posts;
&put_header;
&open_file;
&put_file;
&close_file;
&put_trailer;
&put_footer;
#
# Retrieve postings
#
sub get_posts {
if ($Method eq "POST") {
while (<>) {
@Posts = split(/&/);
&parse_posts;
}
} else {
$Query = $Request;
$Query =~ s/\/cgi-bin\/$vars3\/$vars4\/publicdetail.pl\///;
@Posts = split(/&/,$Query);
&parse_posts;
$FDir="$Root/cgi-bin/$vars3/$vars4/files/$Path";
$File="$FDir/$Base";
}
}
#
# Parse postings
#
sub parse_posts {
foreach $PostItem (@Posts) {
($PostKey,$PostVal) = split(/=/,$PostItem);
$PostVal =~ s/\+/_/g;
$PostVal =~ s/%(..)/pack("c",hex($1))/ge;
$PostVal =~ s/\n//g;
if ($PostKey eq "action") {
$Action = $PostVal;
} elsif ($PostKey eq "file") {
$File = $PostVal;
$File =~ s/ /_/g;
} elsif ($PostKey eq "fdir") {
$Fdir = $PostVal;
$Fdir =~ s/ /_/g;
} elsif ($PostKey eq "base") {
$Base = $PostVal;
} elsif ($PostKey eq "path") {
$Path = $PostVal;
}
}
}
sub put_header {
print "Location: $Header\n\n";
}
#
# Open the data file
#
sub open_file {
if (!open (DAT,"< $File")) {
print "<H3>This file does not exist!</H3>\n";
&put_trailer;
exit;
}
}
#
# Display the file
#
sub put_file {
#
# Set defaults
#
$Date = "00/00/1900";
$Price = "";
$Availability = "";
$Title = "Unknown";
$Reference = "No reference";
$Summary = "";
$Body = "";
#
# Extract all data from the file
#
while (($Line = <DAT>)) {
chop $Line;
($Keyword,$Value) = split(/:/,$Line);
if ($Keyword eq "Date") {
$Date = $Value;
} elsif ($Keyword eq "Title") {
$Title = $Value;
} elsif ($Keyword eq "Availability") {
$Availability = $Value;
} elsif ($Keyword eq "Price") {
$Price = $Value;
} elsif ($Keyword eq "Reference") {
$Reference = $Value;
} elsif ($Keyword eq "Summary") {
$Summary = $Summary . $Value . "<BR>\n";
} elsif ($Keyword eq "Body") {
$Body = $Body . $Value . "<BR>\n";
}
}
chop $Summary;
chop $Body;
#
# Generate the item table
#
print "<table class=table>\n";
print "<tr><td class=headings_td>Name</td><td class=title_td>$Title</td><td class=price_td>$Price</td></tr>\n";
print "<tr><td class=headings_td>Description</td><td class=normal_td>$Summary</td><td class=normal_td></td></tr>\n";
print "<tr><td class=headings_td>Additional Info</td><td class=normal_td>$Body</td><td class=normal_td></td></tr>\n";
#
# Close the item table
#
print "</table>\n";
}
#
# Close the data file
#
sub close_file {
close DAT;
}
#
# Print the trailer block
#
sub put_trailer {
print <<ENDPR;
<a href="/$vars2/$vars3/$vars4/publicindex.pl/$Path">back to menu</a>
</BODY>
</HTML>
ENDPR
}
sub put_footer {
print "Location: $Footer\n\n";
}
#
# Display key data
#
sub put_keys {
print "<PRE>";
print "Root = $Root\n";
print "Path = $Path\n";
print "Referer = $Referer\n";
print "Request = $Request\n";
print "Method = $Method\n";
print "Query = $Query\n";
print "File = $File\n";
print "Fdir = $Fdir\n";
print "Base = $Base\n";
print "</PRE>\n";
print "<HR>\n";
}
Bazz
if I remove the header the content prints out, however, if I manage to get it to print the sub put_footer, I also lose the content. What thing stupid am I doing wrong?
#!/usr/bin/perl -w
#
#
# Print the HTML content header; set global names
#
$Root = $ENV{"DOCUMENT_ROOT"};
$Path = $ENV{"PATH_INFO"};
$Referer = $ENV{"HTTP_REFERER"};
$Request = $ENV{"REQUEST_URI"};
$Method = $ENV{"REQUEST_METHOD"};
$Query = $ENV{"QUERY_STRING"};
$Path =~ s/[^a-zA-Z0-9\.]//g;
$MenuName= $Path;
$MenuName=~ s/\_/ /g; # my changes to try to entitle the menu
if ($Path eq "") {
$Path = "ALL";
}
#################################
#MY AMENDMENT
###############################
$Directory = $Request;
chomp ($Directory);
($vars1,$vars2,$vars3,$vars4,$vars5) = split(/\//,$Directory);
#That splits to give vars like these?
#$vars2 = cgi-bin
#$vars3 = ClientName
#$vars4 = MenuType
#$vars5 = file.pl
#################################
#establish incoming domain and split to get name
###############################
$Domain = $Referer;
chomp ($Domain);
($ref1,$ref2,$ref3) = split(/\//,$Domain);
#That splits to give vars like these?
#$ref3 = cms.thechrissystem.com
##################################
#split domain name into it components
##################################
chomp ($ref3);
($dom1,$dom2,$dom3) = split(/\./,$ref3);
#$dom1 = cms
#$dom2 = thechrissystem
#$dom3 = com
###################################
#Set headers and footers
###################################
$Header = "/headers_and_footers/$vars3/header.htm";
$Footer = "/headers_and_footers/$vars3/footer.htm";
#$client = $dom2;
#if (-e "/headers_and_footers/$client/header.htm")
#{
#$Header = "/headers_and_footers/$client/header.htm";
#$Footer = "/headers_and_footers/$client/footer.htm";
#}
#else
#{
#sub put_headers {
#
#printContent-type: text/html;
#print "file not available";
#}
#}
###############################
#END OF MY AMENDMENT
###############################
#$Files = `ls $Root/cgi-bin/a_default/Meal_Menus/files/$Path/*`;
#$Files = `ls $Root/$vars2/$vars3/$vars4/files/$Path/*`;
$Action = "View";
$Fdir = "$Root/$vars2/$vars3/$vars4/files/ALL";
$Base = "NOFILE";
#
# Call processing functions
#
&get_posts;
&put_header;
&open_file;
&put_file;
&close_file;
&put_trailer;
&put_footer;
#
# Retrieve postings
#
sub get_posts {
if ($Method eq "POST") {
while (<>) {
@Posts = split(/&/);
&parse_posts;
}
} else {
$Query = $Request;
$Query =~ s/\/cgi-bin\/$vars3\/$vars4\/publicdetail.pl\///;
@Posts = split(/&/,$Query);
&parse_posts;
$FDir="$Root/cgi-bin/$vars3/$vars4/files/$Path";
$File="$FDir/$Base";
}
}
#
# Parse postings
#
sub parse_posts {
foreach $PostItem (@Posts) {
($PostKey,$PostVal) = split(/=/,$PostItem);
$PostVal =~ s/\+/_/g;
$PostVal =~ s/%(..)/pack("c",hex($1))/ge;
$PostVal =~ s/\n//g;
if ($PostKey eq "action") {
$Action = $PostVal;
} elsif ($PostKey eq "file") {
$File = $PostVal;
$File =~ s/ /_/g;
} elsif ($PostKey eq "fdir") {
$Fdir = $PostVal;
$Fdir =~ s/ /_/g;
} elsif ($PostKey eq "base") {
$Base = $PostVal;
} elsif ($PostKey eq "path") {
$Path = $PostVal;
}
}
}
sub put_header {
print "Location: $Header\n\n";
}
#
# Open the data file
#
sub open_file {
if (!open (DAT,"< $File")) {
print "<H3>This file does not exist!</H3>\n";
&put_trailer;
exit;
}
}
#
# Display the file
#
sub put_file {
#
# Set defaults
#
$Date = "00/00/1900";
$Price = "";
$Availability = "";
$Title = "Unknown";
$Reference = "No reference";
$Summary = "";
$Body = "";
#
# Extract all data from the file
#
while (($Line = <DAT>)) {
chop $Line;
($Keyword,$Value) = split(/:/,$Line);
if ($Keyword eq "Date") {
$Date = $Value;
} elsif ($Keyword eq "Title") {
$Title = $Value;
} elsif ($Keyword eq "Availability") {
$Availability = $Value;
} elsif ($Keyword eq "Price") {
$Price = $Value;
} elsif ($Keyword eq "Reference") {
$Reference = $Value;
} elsif ($Keyword eq "Summary") {
$Summary = $Summary . $Value . "<BR>\n";
} elsif ($Keyword eq "Body") {
$Body = $Body . $Value . "<BR>\n";
}
}
chop $Summary;
chop $Body;
#
# Generate the item table
#
print "<table class=table>\n";
print "<tr><td class=headings_td>Name</td><td class=title_td>$Title</td><td class=price_td>$Price</td></tr>\n";
print "<tr><td class=headings_td>Description</td><td class=normal_td>$Summary</td><td class=normal_td></td></tr>\n";
print "<tr><td class=headings_td>Additional Info</td><td class=normal_td>$Body</td><td class=normal_td></td></tr>\n";
#
# Close the item table
#
print "</table>\n";
}
#
# Close the data file
#
sub close_file {
close DAT;
}
#
# Print the trailer block
#
sub put_trailer {
print <<ENDPR;
<a href="/$vars2/$vars3/$vars4/publicindex.pl/$Path">back to menu</a>
</BODY>
</HTML>
ENDPR
}
sub put_footer {
print "Location: $Footer\n\n";
}
#
# Display key data
#
sub put_keys {
print "<PRE>";
print "Root = $Root\n";
print "Path = $Path\n";
print "Referer = $Referer\n";
print "Request = $Request\n";
print "Method = $Method\n";
print "Query = $Query\n";
print "File = $File\n";
print "Fdir = $Fdir\n";
print "Base = $Base\n";
print "</PRE>\n";
print "<HR>\n";
}
Bazz