#!/usr/bin/perl

#use utf8;
use strict;
use CGI;

use Opals::Context;
use Date::Calc::Object qw(
    :all
);
use Time::localtime;

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

use Opals::Locale qw(
    loc_getMsgFile
    loc_write
);
use Opals::Date qw(

);
use Opals::HTMLComponents qw(
    hc_getQuickUserEntryFormHTML
);

################################################################################
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        => 'circ/loan.tmpl',
            reqPermission   => 'circ_loan',
        }
);
my $syspref          = tmpl_preference($dbh);
my $chargeFine       = $syspref->{'charge_overdue'};
my $chargeDamage     = $syspref->{'charge_damage'};
my $chargeLost       = $syspref->{'charge_lost'};
my $validateBc       = $syspref->{'validateBarcode'}; 
my $barcodeType      = $syspref->{'barcodeType'}; 
my $slipPrinter        = (defined $syspref->{'slipPrinter'} && $syspref->{'slipPrinter'} >0) ?1: 0; 
my $circulationSound = $syspref->{'circulationSound'};
my $loginuid         = $template->param('curUserId');

my @cookieList = (@$cookie);
my $tm = localtime;
my $todayStr = sprintf("%04d-%02d-%02d", $tm->year+1900, ($tm->mon)+1, $tm->mday);
my $dFirst = Opals::Context->preference('dateFirst');
my $dLast  = Opals::Context->preference('dateLast');


if ($permission && $permission->{'circ_loan'}) 
{   
    $template->param(
                 circulation => 1,
                 circulationSound => $circulationSound,
                 loan        => 1,
                 hlpUrl     => Opals::Constant->getHlpUrl('loan')
                 );

    if($slipPrinter){
        $template->param(slipPrinter   => $slipPrinter,);
    }
}#if ($permission && $permission->{'circ_loan'})

my $qeUserForm =hc_getQuickUserEntryFormHTML($dbh);
    $template->param(qeUserForm=>$qeUserForm);


my $qeMsgMap            =loc_getMsgFile('circ/quickItemAjaxFrm.msg');
my $userqeMsgMap        =loc_getMsgFile('circ/quickUserAjaxFrm.msg');
my $userSelPanMsgMap    =loc_getMsgFile('circ/userSelPan.msg');
my $finePanMsgMap       =loc_getMsgFile('circ/fine.msg');
my $confirmMsgMap       =loc_getMsgFile('circ/confirmDlg.msg');

loc_write($template,$qeMsgMap);
loc_write($template,$userqeMsgMap);
loc_write($template,$userSelPanMsgMap);
loc_write($template,$finePanMsgMap);
loc_write($template,$confirmMsgMap);

tmpl_write($dbh, $cgi, \@cookieList, $template);


################################################################################

