Hi there,
I am trying out O grain's Order Mod but ran across a problem with one of the subroutines. The subroutine is for the html.pl file and is called html_send_addressed_order. It causes the script to stop working and return a DBMan error of "The server has encountered an internal error. Please enable debugging to view". THe script is not running on Windows.
I am not all that great at Perl so if someone could give me a hand that would be great. Thank you so much!
Here is the sub:
sub html_send_addressed_order {
# --------------------------------------------------------
# send the order after adding and checking delivery address
my (%rec) = @_;
$rec{$db_key} =~ s/<?.B>//g;
$rec{$db_key} =~ s/<?.B>//g;
### Check input
$order_error = 0;
unless ($in{'order_name'}) {
$message .= "<LI>You must enter your name.";
$order_error += 1;
}
unless ($in{'order_address'}) {
$message .= "<LI>You must enter your address.";
$order_error += 1;
}
unless ($in{'order_city'}) {
$order_error += 1;
$message .= "<LI>You must enter your postal address.";
}
if (!$in{'order_zipcode'} {
$message .= "<LI>You must enter your zip code. (If not applicable just put '-')";
$order_error += 1;
}
if ($in{'order_zipcode'} eq '-' ) {
$in{'order_zipcode'} = '';
}
if ($order_error > 0) {
$page_title = "The address form has not been filled in correctly";
&html_page_top;
# < -- Start page text -- >
print qq|
<$font>Please correct the following $order_error error(s):<p>
<UL>
$message
</UL>
</font>
|;
# < -- End page text -->
&html_rectify_address_form;
&html_footer;
&html_page_bottom;
}
else {
# Check that the order file is still there ....
if (!open(FILE, "<$orders_dir$in{'order_mail'}.txt")){
$page_title = "Unfortunately the order could not be sent.";
&html_page_top;
print qq|
<$font>The prepared order seems to have disappeared.<br>
Maybe you have already sent or cancelled the order and by mistake used the
browsers back button?
</font>
<P>
|;
&html_order_cleared_footer;
&html_page_bottom;
}
else {
&create_order_header;
&sum_up_order;
open (FILE, ">>$orders_dir$in{'order_mail'}.txt") || &cgierr("Can't open $orders_dir$in{'order_mail'}.txt.");
print FILE "\n\n--------------------------------------------------------\n\n";
print FILE "Totally $total_items of $merchandise - Total sum $currency $total_sum.\n";
print FILE "Shipping: $currency $shipping.\n\n";
print FILE "Grand total: $currency $grand_total";
close (FILE);
&send_order;
$page_title = "The following order has been sent to $shop";
&html_page_top;
open (FILE, "<$orders_dir$in{'order_mail'}.txt") || &cgierr("Can't open $orders_dir$in{'order_mail'}.txt.");
@lines = <FILE>;
close (FILE);
foreach $line (@lines) {
if ($line =~ /^\*/) {
print $line;
print "<br>";
}
else {
print "<$font>";
print $line;
print "</font><br>";
}
}
&html_order_cleared_footer;
&html_page_bottom;
$order_file = "$in{'order_mail'}.txt";
$in{'order_mail'} = '';
if ($auto_delete) {
# NOTE! If you are on a Windows system you will need to find the method
# of deleting/renaming a file and replace rm (delete) and mv (rename)
# with other commands
system('rm',"$orders_dir$order_file");
}
else {
# First append tracing data to file
open (FILE, ">>$orders_dir$order_file") || &cgierr("Can't open $orders_dir$order_file.");
@this_order = <FILE>;
print FILE "\n\nRemote Host: $ENV{REMOTE_HOST}\n";
print FILE "Remote Addr: $ENV{'REMOTE_ADDR'}\n";
$server_time = localtime(time());
print FILE "Server time: $server_time";
close (FILE);
# Then rename the file with a random extension so the user can't use
# the back button in the browser to add more things...
srand;
$extension = rand;
$extension =~ s/0\.//;
$archive_file = "$order_file";
$archive_file =~ s/.txt/_$extension/;
system ('mv',"$orders_dir$order_file","$orders_dir$archive_file");
}
}
}
}
Cheers!
Richard
I am trying out O grain's Order Mod but ran across a problem with one of the subroutines. The subroutine is for the html.pl file and is called html_send_addressed_order. It causes the script to stop working and return a DBMan error of "The server has encountered an internal error. Please enable debugging to view". THe script is not running on Windows.
I am not all that great at Perl so if someone could give me a hand that would be great. Thank you so much!
Here is the sub:
sub html_send_addressed_order {
# --------------------------------------------------------
# send the order after adding and checking delivery address
my (%rec) = @_;
$rec{$db_key} =~ s/<?.B>//g;
$rec{$db_key} =~ s/<?.B>//g;
### Check input
$order_error = 0;
unless ($in{'order_name'}) {
$message .= "<LI>You must enter your name.";
$order_error += 1;
}
unless ($in{'order_address'}) {
$message .= "<LI>You must enter your address.";
$order_error += 1;
}
unless ($in{'order_city'}) {
$order_error += 1;
$message .= "<LI>You must enter your postal address.";
}
if (!$in{'order_zipcode'} {
$message .= "<LI>You must enter your zip code. (If not applicable just put '-')";
$order_error += 1;
}
if ($in{'order_zipcode'} eq '-' ) {
$in{'order_zipcode'} = '';
}
if ($order_error > 0) {
$page_title = "The address form has not been filled in correctly";
&html_page_top;
# < -- Start page text -- >
print qq|
<$font>Please correct the following $order_error error(s):<p>
<UL>
$message
</UL>
</font>
|;
# < -- End page text -->
&html_rectify_address_form;
&html_footer;
&html_page_bottom;
}
else {
# Check that the order file is still there ....
if (!open(FILE, "<$orders_dir$in{'order_mail'}.txt")){
$page_title = "Unfortunately the order could not be sent.";
&html_page_top;
print qq|
<$font>The prepared order seems to have disappeared.<br>
Maybe you have already sent or cancelled the order and by mistake used the
browsers back button?
</font>
<P>
|;
&html_order_cleared_footer;
&html_page_bottom;
}
else {
&create_order_header;
&sum_up_order;
open (FILE, ">>$orders_dir$in{'order_mail'}.txt") || &cgierr("Can't open $orders_dir$in{'order_mail'}.txt.");
print FILE "\n\n--------------------------------------------------------\n\n";
print FILE "Totally $total_items of $merchandise - Total sum $currency $total_sum.\n";
print FILE "Shipping: $currency $shipping.\n\n";
print FILE "Grand total: $currency $grand_total";
close (FILE);
&send_order;
$page_title = "The following order has been sent to $shop";
&html_page_top;
open (FILE, "<$orders_dir$in{'order_mail'}.txt") || &cgierr("Can't open $orders_dir$in{'order_mail'}.txt.");
@lines = <FILE>;
close (FILE);
foreach $line (@lines) {
if ($line =~ /^\*/) {
print $line;
print "<br>";
}
else {
print "<$font>";
print $line;
print "</font><br>";
}
}
&html_order_cleared_footer;
&html_page_bottom;
$order_file = "$in{'order_mail'}.txt";
$in{'order_mail'} = '';
if ($auto_delete) {
# NOTE! If you are on a Windows system you will need to find the method
# of deleting/renaming a file and replace rm (delete) and mv (rename)
# with other commands
system('rm',"$orders_dir$order_file");
}
else {
# First append tracing data to file
open (FILE, ">>$orders_dir$order_file") || &cgierr("Can't open $orders_dir$order_file.");
@this_order = <FILE>;
print FILE "\n\nRemote Host: $ENV{REMOTE_HOST}\n";
print FILE "Remote Addr: $ENV{'REMOTE_ADDR'}\n";
$server_time = localtime(time());
print FILE "Server time: $server_time";
close (FILE);
# Then rename the file with a random extension so the user can't use
# the back button in the browser to add more things...
srand;
$extension = rand;
$extension =~ s/0\.//;
$archive_file = "$order_file";
$archive_file =~ s/.txt/_$extension/;
system ('mv',"$orders_dir$order_file","$orders_dir$archive_file");
}
}
}
}
Cheers!
Richard

