#!/usr/bin/perl

#use utf8;
use strict;
use CGI;

use Opals::Context;

use Time::localtime;

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

use Opals::Locale qw(
    loc_getMsgFile
    loc_write
);

use Opals::HTMLComponents qw(
    hc_getQuickUserEntryFormHTML
);

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

my $syspref = tmpl_preference($dbh);
my $cgi = CGI->new;
my $input = $cgi->Vars();
my ($permission, $cookie, $template) = tmpl_read(
        {
            dbh             => $dbh,
            cgi             => $cgi,
            tmplFile        => 'circ/return.tmpl',
            reqPermission   => 'circ_return',
        }
);
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 $circulationSound = $syspref->{'circulationSound'};
my $loginuid         = $template->param('curUserId');
my $quickMode        = $input->{'quickMode'};

if($quickMode && $quickMode eq 'true'){
    $template->param(quickMode=>$quickMode,
                     hlpUrl     => Opals::Constant->getHlpUrl('quickReturn'));
}
else{
    $template->param(hlpUrl     => Opals::Constant->getHlpUrl('return') );
}

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



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,
                 return        => 1);

         
}#if ($permission && $permission->{'circ_loan'})
    
    my $retuenPanelMsgMap   =loc_getMsgFile('circ/returnPanel.msg');
    my $finePanMsgMap       =loc_getMsgFile('circ/fine.msg');
    my $userSelPanMsgMap    =loc_getMsgFile('circ/userSelPan.msg');
    
    loc_write($template,$retuenPanelMsgMap);
    loc_write($template,$finePanMsgMap);
    loc_write($template,$userSelPanMsgMap);

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



