#!/usr/bin/perl

#use utf8;
use strict;
use CGI;
use Digest::SHA qw(
    sha1_base64
    sha1_hex
);

use Opals::Context;
use Opals::Template_ajax qw(
    tmpl_read
    tmpl_write
    tmpl_preference
);
use Opals::Pathfinder qw(
    pf_getPfList
    pf_getRecByIdList
);
use JSON;

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

my $cgi      = CGI->new;
my $input    = $cgi->Vars();
my $pfIdList =$input->{"pfIdList"};


my ($status,$errorCode,$errorMsg)    ;
my ($permission, $cookie, $template) = tmpl_read(
    {
        dbh             => $dbh,
        cgi             => $cgi,
        tmplFile        => 'ajax/portlet/getPfList.tmpl',
        
    }
);
my $pfList=[];
if($pfIdList ne ''){
   $pfList=pf_getRecByIdList($dbh,$pfIdList);
}
else{
    $pfList =pf_getPfList($dbh);
}


    my $json = to_json({pfList=>$pfList});
    print "Content-type: text/plain\n\n";
    print $json;


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



