SET FOREIGN_KEY_CHECKS=0;
#----------------------------
# Table structure for sessions
#----------------------------
CREATE TABLE `sessions` (
`id` varchar(32) NOT NULL default '',
`a_session` text NOT NULL,
UNIQUE KEY `id` (`id`)
) TYPE=MyISAM;
####
my $config = { DSN => 'DBI:mysql:session',
MySQLunm => 'ipsofalco',
MySQLpwd => 'ipsoquango',
};
my $dbh = &createDBconnection( $config->{DSN}, $config->{MySQLunm}, $config->{MySQLpwd} );
# Get a CGI object, it will be filled if a form was
#submitted and will have a cookie in teh header
#if one had been set.
my $q = new CGI;
#Initialize the session, if their is a cookie in the
#CGI object then the CGISESSID will be the value of an
#existing session, otherwise it creates a new session
my $session = new CGI::Session("driver:MySQL", $q, {Handle=>$dbh});
#$rdcookie is the value of the cookie that was already
# in the header read=past tense in this case.
my $rdcookie = $q->cookie("CGISESSID");
#$id is the session id (an MD5 hash) of the session.
my $id = $session->id();
# Set cookie with new expire time
my $cookie = $q->cookie(-name=>'CGISESSID', -value=>$session->id, -expires=>'+1d');
####
sub addItemCart {
my ($cgi, $session, $orderitem) = @_;
my $orderitem = &getItemForCart($cgi, $session);
# get current cart contents
my $cart = $session->param("CART") || [];
# add selected item
push @{$cart}, $orderitem;
# update the CART in the session
$session->param( "CART", $cart );
$session->flush();
return displayCart($cgi, $session);
}
####
sub clrCart {
my ($cgi, $session) = @_;
$session->clear(["CART"]);
$session->flush();
return &displayCart($cgi, $session);
}