#!/usr/bin/perl

#use utf8;
use strict;
use CGI;

use Opals::Context;
use Opals::Template qw(
    tmpl_read
    tmpl_write
);
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 ($permission, $cookie, $template) = tmpl_read(
        {
            dbh             => $dbh,
            cgi             => $cgi,
            tmplFile        => 'login.tmpl',
        }
);

$template->param(
    active_home => 1,
    username    => $input->{'username'},
);
$template->param(authenticateBySID=>checkIfAuthBySID($dbh));

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

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

#------------------------------------------------------------------------------
sub checkIfAuthBySID{
    my ($dbh)=@_;
    my $sth = $dbh->prepare(<<_STH_);
select * 
from    opl_category 
where   authenticateBySID='1' limit 1
        
_STH_
    $sth->execute();
    my $row = $sth->fetchrow_hashref;
    $sth->finish;
    return ($row?1:0);

}
