#!/usr/bin/perl

#use utf8;
use strict;
use CGI;

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

use Opals::Permission qw(

    permission_getList

);

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

my $cgi = CGI->new;
my $input = $cgi->Vars();
my $op = $input->{'op'};
my ($permission, $cookie, $template) = tmpl_read(
        {
            dbh             => $dbh,
            cgi             => $cgi,
            tmplFile        => 'util/brwrtype.tmpl',
            reqPermission   => 'pref_edit',
        }
);

($op) || ($op = 'view');

    ListUsers($dbh, $template);    
    $template->param(ViewUser => 1);
    my $pList = permission_getList($dbh);
    $template->param(pList => $pList);
    

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

sub ListUsers {
    my ($dbh, $template) = @_;
    
    my $queryTotal = $dbh->prepare("select count(*) from opl_user_tmp where categorycode=?");
    my $query = $dbh->prepare("select * from opl_category_tmp order by catid");
    $query->execute();
    my @arrUser = ();
    my $count = 0;
    while (my $rec = $query->fetchrow_hashref) {
        $queryTotal->execute($rec->{'catid'});
        my ($totaluser) = $queryTotal->fetchrow_array;
        $queryTotal->finish;

        $rec->{'totaluser'} = $totaluser;
        $rec->{'odd'} = ($count%2 ? 1:0);
        if ( $rec->{'catid'} == 1 ) { $rec->{'default'} = 1; }
        if ( $rec->{'catid'} > 10) {$rec->{'removable'} = 1;}
        push @arrUser, $rec;
        $count++;
    }
    $query->finish;
    $template->param(listuser => \@arrUser);
}
########################################


