#!/usr/bin/perl -w

use DBI;
use CGI qw(:standard);
use Tangram;
use Schema qw($schema);

# Connect to the schema.
my $dsn  = "dbi:mysql:database=library";
my $user = "demo";
my $pass = "open_sesame";
my $storage =
    Tangram::Storage->connect($schema, $dsn, $user, $pass);

# Display an HTML document.
print header();
print start_html("Loan Confirmation");
print ("<H1>Loan Confirmation</H1><HR>");

# Get the patron and book ids from the CGI queries.
# Use the load() method to get the object from the
# database.
$patron_id = param('patron');
($patron) = $storage->load($patron_id);

$book_id = param('book');
($book) = $storage->load($book_id);

# Invoke the patron's borrow method,
# and update the patron and book.
#
$patron->borrow( $book );
$storage->update( $patron, $book );

print "The book ", $book->{title};
print " was loaned to ", $patron->{name}, ".";

print end_html();