#!/usr/bin/perl

use strict;
use CGI;

use Opals::Context;
use Opals::Template qw(
    tmpl_read
    tmpl_write
    tmpl_preference
);

use Time::localtime;

use Opals::User qw(
    user_list
    user_getInformationById
);

use Opals::Eq_Circulation qw(
    circ_getItemInfo
);

my $dbh = Opals::Context->dbh();
END { $dbh->disconnect(); }

my $cgi = CGI->new;
my $input = $cgi->Vars();
my ($permission, $cookie, $template) = tmpl_read(
    {
        dbh             => $dbh,
        cgi             => $cgi,
        tmplFile        => 'eqmnt/reserveNotice.tmpl',
#        reqPermission   => 'reqPermission1|reqPermission2|etc.',
    }
);

my $syspref     = tmpl_preference($dbh);
my @cookieList  = ($cookie);
my $libName     = $template->param('libname');
my $today       = $template->param('today');
    
    my ($uid, $barcode);
    $uid        = $input->{'uid'};
    $barcode    = $input->{'barcode'};
    my $itemInfo    = circ_getItemInfo($dbh, $barcode);
    getUserInfo($dbh, $uid);
    $template->param(
        libName     => $libName,
        today       => $today,
        #itemInfo    => $itemInfo,
        barcode     => $barcode,
    );
    $template->param($itemInfo);
tmpl_write($dbh, $cgi, \@cookieList, $template);

sub getUserInfo{
    my ($dbh, $uid) = @_;
    my ($userInfo, $guardian) = user_getInformationById($dbh, $uid);
    
    $template->param(
        user_uid        =>$userInfo->{'uid'},
        user_barcode    =>$userInfo->{'userbarcode'},
        user_username   =>$userInfo->{'username'},
        user_firstname  =>$userInfo->{'firstname'},
        user_lastname   =>$userInfo->{'lastname'},
        homeroom        =>$userInfo->{'homeroom'},
        teacher         =>$userInfo->{'teacher'},
        grade           =>$userInfo->{'grade'},
        notes           =>$userInfo->{'notes'},
    );
    $template->param(hidden => $userInfo->{'uid'});
}


