#!/usr/bin/perl

#use utf8;
use strict;
use CGI;

use Opals::Context;
use Opals::Template_ajax qw(
    tmpl_read
    tmpl_write
);


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

my $cgi      = CGI->new;
my $input = $cgi->Vars();

my $odExemption = $input->{'odExemption'};
$odExemption =~ s/^,+|,+$//g;
$odExemption =~ s/,+/,/g;
my ($permission, $cookie, $template) = tmpl_read(
    {
        dbh             => $dbh,
        cgi             => $cgi,
        tmplFile        => 'ajax/circ/saveODexemption.tmpl',
        reqPermission   => 'circ_loan',
    }
);

if (defined $permission && $permission->{'circ_loan'}) {
    if($odExemption && $odExemption ne ""){
        $dbh->do("update opl_category set ODexempt=if(catid in ($odExemption),1,0);");
    }
    else{
        $dbh->do("update opl_category set ODexempt=0");
    }

}
tmpl_write($dbh, $cgi, $cookie, $template);

#-------------------------------------------------------------------------------


