<& Template,top=>1 &>

% if ($action eq "add") {

<h3>Item Added</h3>
You have added the following CD to your Shopping Kart:<P>
<& tools/cd_details,id=>$id,cds=>\%cds) &><P>
<a href="kart?action=retrieve">Click here to view your Shopping Kart</a><P>

% } elsif ($action eq "delete") {

<h3>Item Deleted</h3>
You have deleted the following CD from your Shopping Kart:<P>
<& tools/cd_details,id=>$id,cds=>\%cds) &><P>
<a href="kart?action=retrieve">Click here to view your Shopping Kart</a><P>

% } elsif ($action eq "retrieve") {

<h3>Contents of Shopping Kart:</h3>

%   if (scalar @ids > 0) { # items have been added to the kart
%     foreach my $id (@ids) {
        <%$m->comp('tools/cd_details',id=>$id,cds=>\%cds) %> <a href="kart?action=delete&id=<%$id%>">Delete</a><P>
%     }
      <a href="kart?action=purge">Clear your Shopping Kart of all items</a><P>

%   } else {
      <h3>Your shopping Kart is empty!</h3>
%   }

% } elsif ($action eq "purge") {
    <h3>Shopping Kart Reset to 0 items</h3>
% }

<& Template,bottom=>1 &>

<%INIT>
my ($cookie,@ids);
my %cds = %{$m->comp('data/cds')};
if ($action eq "add") {
   $m->comp('tools/cookie_manip',add=>$id);
} elsif ($action eq "delete") {
   $m->comp('tools/cookie_manip',remove=>$id);
} elsif ($action eq "retrieve") {
   $cookie = $m->comp('tools/cookie_manip',retrieve=>1);
   @ids = split ":", $cookie;
} elsif ($action eq "purge") {
   $m->comp('tools/cookie_manip',purge=>1);
}

</%INIT>
<%ARGS>
$id=>undef
$action=>undef
</%ARGS>
