sub format_cart_html
{
my ($cart_ref, $show_links) = @_;
my $total_price = 0;
my @row;
my @color;
if (!keys (%{$cart_ref}))
{
return (p ("Shopping cart is empty."));
}
$page .= h3 ({-align=>"center", -style=>"font-family: verdana; font-size: 16pt; color: blue;"}, ("Shopping Cart"));
push (@row, Tr ({-align => "CENTER", -valign=>"TOP", -BGCOLOR=>"silver", -style=>"font-family: verdana; font-size: 10pt;"},
th ({-width=>"80"},("Item")),
th ({-width=>"50"},("Qty")),
th ({-width=>"94"},("Color")),
th ({-width=>"190"},("Description")),
th ({-width=>"94"},("Unit Price")),
th ({-width=>"94"},("Price"))
));
foreach my $item_id (sort (keys (%{$cart_ref})))
{
my $item_ref = $cart_ref->{$item_id};
my $total_item_price = $item_ref->{qty} * $item_ref->{price};
$total_price += $total_item_price;
# generate a link allowing the item to be deleted from the cart
my $url = sprintf ("%s?choice=delete;item_id=%s",
url (), escape ($item_id));
push (@row, start_form(-method=>'GET', -action=>url()),
hidden( -name => "choice", -override => 1, -default => "update" ),
hidden( -name => "item_id", -override => 1, -default => escapeHTML( $item_id )),
Tr ({-valign=>"center", -style=>"font-family: verdana; font-size: 10pt;"},
td ({-align => "center"},(escapeHTML ($item_id))),
td ({-align => "center"},( textfield( -name => "quantity", -size => "1", -override => 1, -value => $item_ref->{qty}))),
td (escapeHTML ($item_ref->{color})),
td (escapeHTML ($item_ref->{description})),
td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $item_ref->{price}))),
td ({-align => "right"}, escapeHTML (sprintf ("%.2f", $total_item_price))),
td (a ({-href => $url}, img ({-src => "../images/delete1.jpg", -border => "0"}))),
td (image_button( -name => "update", -src=>"../images/update1.jpg", -border=>"0" )),
end_form()
));
}
push (@row, Tr ({-align => "CENTER", -valign=>"center", -style=>"font-family: verdana; font-size: 10pt;"},
td ({-colspan => "2"}, ""),
td ({-colspan => "2", -align=>"right", -style=>"font-weight: 700;"}, "Total"),
td ({-align => "right", -style=>"font-weight: 700;"},
escapeHTML (sprintf ("%.2f", $total_price)))
));
return (table ({-align => "CENTER", -border => 0}, @row));
}