#!/usr/bin/perl -w
#chart.pl
use strict;
use CGI qw(:standard);
use CGI::Carp qw(fatalsToBrowser);
use CGI::Session;
use Apache::Session::MySQL;
use DBI;
use Template;
use 5.010;
use rightplacedb;
use webdb;
use Data::Dumper;
$| =1;
print "content-type: text/html\n\n";
my $dbh = webdb::connect() or die "Cannot connect to database $@\n";
my $cookie;
my %session;
my $template;
my $sess_id = cookie('CUSTOMER_ID');
print "session id : $sess_id
";
tie %session, "Apache::Session::MySQL",$sess_id,
{
Handle => $dbh,
LockHandle => $dbh
};
my $page = param('t_shirt');
my $id = param('id');
my $price = param('price');
given ($page) {
when ($page eq 'add_to_chart')
{
if (exists $session{$id}) {
# update the quanity of the items
$session{'$id'}{'price'} = $price;
}
else
{
$session{$id} = $id;
$session{'$id'}{'price'} = $price;
}
print "
check the price $session{'$id'}{'price'}";
print "
the : $session{'item_code'}";
my $array = $session{'item_code'};
my @selected_item = @$array;
push(@selected_item,$id);
print "
before database : @selected_item
";
$session{'item_code'} = \@selected_item;
print "
the : $session{'item_code'}";
my $bag_id = $session{'item_code'};
print "
my bag contains : @$bag_id
";
$template = '/home/romy/public_html/rightplace/template/src/mybag.html';
$dbh->disconnect();
}
default {
$template = '/home/romy/public_html/rightplace/template/src/entry.html';
}
}
untie(%session);
my $vars = {
position => $id,
Brands => $price,
};
my $tt = Template->new ({
INCLUDE_PATH => [
'/home/romy/public_html/rightplace/template/src/',
'/home/romy/public_html/rightplace/template/lib/',
],
WRAPPER => 'wrapper',
ABSOLUTE => 1,
RELATIVE => 1,
});
$tt->process($template,$vars)|| die "Failed to execute the template $tt->error() \n";