#!/usr/bin/perl

use strict;
use CGI;

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

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

my $cgi = CGI->new;
# $cgi->param('aaa') returns an array of aaa
my $input = $cgi->Vars();
#my $op = $input->{'op'};
my ($permission, $cookieList, $template) = tmpl_read(
    {
        dbh             => $dbh,
        cgi             => $cgi,
        tmplFile        => '_sample_.tmpl',
#        reqPermission   => 'reqPermission1|reqPermission2|etc.',
#        op              => $op,
    }
);

# See User.pm for the list of permissions
#if ($permission && $permission->{'reqPermission1'}) {
#}
#else { # input for login form
#    ##########################
#    # Method one: not recommended
#    $template->param(
#        input => [
#            {name => '', value => $,},
#            {name => '', value => $,},
#        ],
#    );
#
#    ##########################
#    # Method two: recommended
#    my @form_input;
#    foreach my $param (keys %{$input}) {
#        push @form_input, {name =>"$param",value => "$input->{$param}"};
#    }
#    $template->param(
#        input=>\@form_input,
#    );
#}

# Turn on/off search box
#$template->param(
#    search_off      => 1,
#);

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