#!/usr/bin/perl

#use utf8;
use strict;
use CGI;
use Opals::Template qw(
    tmpl_read
    tmpl_write
    tmpl_preference
);
use Opals::Context;
use Opals::Constant;
use Opals::Locale qw(
    loc_getMsgFile
    loc_write
);
use Opals::Utility qw(
    util_resizeImg
);
use Opals::Ebook qw(
    eb_getMarcXmlRid
    eb_getLicenseList
);
use Opals::WebServiceEbookClient qw( 
    wsc_getEbook
);


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        => 'ebook/info.tmpl',
            reqPermission   => 'ebook_mgmt',
        }
);

my $bid         = $input->{'bid'};
my $rdrStyle=$input->{'style'};
if(!$rdrStyle){
    $rdrStyle='simple';
}
if ($permission && $permission->{'ebook_mgmt'}) {
    if($bid){
        my $bookData = wsc_getEbook({bid  =>$bid});
        my $metaData = $bookData->{'metadata'};
        my $licList  = eb_getLicenseList($dbh,$bid);
        my $rid  = eb_getMarcXmlRid($dbh,$bid);
        $template->param(title      =>$metaData->{'title'},
                         author     =>$metaData->{'author'},
                         ISBN       =>$metaData->{'ISBN'},
                         description=>$metaData->{'description'},
                         bookCover  =>$metaData->{'bookCover'},
                         publisher  =>$metaData->{'publisher'},
                         pubDate    =>$metaData->{'pubDate'},
                         language   =>$metaData->{'language'},
                         bid        =>$bid,
                         rid        =>$rid,
                         licList    =>$licList,
                         rdrStyle   =>$rdrStyle
                         
                );
    }

}

#-------------------------------------------------------------
#Thu, Jan 07, 2010 @ 13:50:35 EST
my $msgValMap ={};
my $fileMsgMap            =loc_getMsgFile('ebook.msg',$msgValMap);

loc_write($template,$fileMsgMap);
        
tmpl_write($dbh, $cgi, $cookie, $template);


