#!/usr/bin/perl

#use utf8;
use strict;
use CGI;

use Opals::Context;


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


my $cgi = CGI->new;
my $input = $cgi->Vars();
my $rId=$input->{'rId'};

my $sth = $dbh->prepare("select thumbnail from eq_images where rId=?");
$sth->execute($rId);
if(my ($img) = $sth->fetchrow_array){
    print $cgi->header(-type => 'image/jpeg' );
    print $img;
}
else{
    print $cgi->header(-type => 'image/jpeg' );
    my $rootDir       = Opals::Context->config('rootDir');
    my $noImgPath = "$rootDir/htdocs/theme/opals/image/nocover_large.png";
    open NOIMG, "<$noImgPath";
    while(<NOIMG>){
        print $_;
    }
    close NOIMG;
}


