#!/usr/bin/perl

#use utf8;
use strict;
use CGI;

use Opals::Context;
use Opals::Template qw(
    tmpl_read
    tmpl_write
    tmpl_rangedPageList
);
use Opals::Circulation qw(
    circ_getRecInfo
);

use Opals::Rating qw(
    cmntRating_getTeacherList
    cmntRating_getComntList
    cmntRating_getAllComntsByRid
    cmntRating_getList2Review
    cmntRating_update
    cmntRating_countComntList
);
use Opals::Locale qw(
    loc_getMsgFile
    loc_write
);

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

my $cgi         = CGI->new;
my $input       = $cgi->Vars();
my $pageNum     = $input->{'pageNum'};
my $pSize       = $input->{'pSize'};
my $sortField   = $input->{'sort'};
my $sortDir     = $input->{'sortDir'};
my $t_firstname = $input->{'t_firstname'};
my $t_lastname  = $input->{'t_lastname'};

if (!$sortDir) {
    $sortDir='asc';
}
if (!$sortField) {
    $sortField ='lastCommentOn ';
    $sortDir   = 'desc';
}

($pageNum  && $pageNum >=1)||($pageNum=1); 
($pSize && $pSize >=1)||($pSize=10);
my $offset= ($pageNum -1) * $pSize ;


my ($permission, $cookie, $template) = tmpl_read(
        {
            dbh             => $dbh,
            cgi             => $cgi,
            tmplFile        => 'rating/reviewUserComment.tmpl',
            reqPermission   => 'rating',
        }
);
   
    my $numOfComnt =0;
    $numOfComnt     = cmntRating_countComntList($dbh);
    my $teacherList = cmntRating_getTeacherList($dbh);
    my($comntLs)    = cmntRating_getComntList($dbh,$offset,$pSize,$sortField,$sortDir,$t_firstname,$t_lastname);
    my $pRange      = 10;
    my @rangedPageList = tmpl_rangedPageList($numOfComnt, $pageNum, $pSize, $pRange);
    my $repuid = $template->param('curUserId');
    $template->param(comntLs     => $comntLs ,
                     numOfComnt  => $numOfComnt ,
                     rangedPageList      => \@rangedPageList,
                     pageNum    => $pageNum,
                     pSize      => $pSize,
                     sortField  => $sortField,
                     sortDir    => $sortDir,
                     repuid     => $repuid,
                     teacherList=> $teacherList,
                     t_firstname=> $t_firstname,
                     t_lastname => $t_lastname ,
                     );
    


#Tue, Jan 12, 2010 @ 10:31:41 EST
my $msgValMap ={};
my $msgMap            =loc_getMsgFile('report/reports.msg',$msgValMap);
loc_write($template,$msgMap);



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