#!/usr/bin/perl
package RVL::Manager;
##LICENSE##
use strict;
use warnings;
use RVL::DB;
#use RVL::ServiceLocator;
use Class::Std::Utils;
{
sub new {
RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
my ($class, $opt) = @_;
my (%hash);
my ($this) = bless( \%hash, $class);
my ($c) = RVL::Config::singleton();
$this->{conf} = $c->getAll();
if (!defined($this->{conf}->{'db'}->{'enabled'}) || $this->{conf}->{'db'}->{'enabled'} eq '1') {
RVL::logMessage('DB Connection', __CONSTANT__::RVL_LOG_DEBUG);
$this->{dbh} = $this->_getDb();
}
if (defined $this->{conf}->{'site'}->{'masterTemplate'}) {
$this->{masterTemplate} = $this->{conf}->{'site'}->{'masterTemplate'};
}
return $this;
}
sub _getDb {
RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
my ($this) = @_;
my ($locator) = new RVL::ServiceLocator;
my $dbh = $locator->get('DB');
if (!$dbh) {
$dbh = RVL::DB::singleton();
$locator->register('DB', $dbh);
}
return $dbh;
}
sub process {
my ($this, $input, $output) = @_;
RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
my ($mgrName) = ref $this;
my ($defaultMgrLoaded) = 0;
${$input}->{action} = 'view' if (!defined ${$input}->{action});
if (!defined $this->{_aActionsMapping}->{ ${$input}->{action} }) {
return RVL::raiseError('The specified method, ' . ${$input}->{action} .
' does not exist', __CONSTANT__::RVL_ERROR_NOMETHOD);
}
if (!defined $this->{conf}) {
return RVL::raiseError('It appears you forgot to fire RVL::Manager\'s '.
'constructor - please add "use base qw(RVL::Manager);" and my ($this) = $class->SUPER::new($opt); in your '.
'new\'s constructor.', __CONSTANT__::RVL_ERROR_NOCLASS);
}
if ( defined $this->{conf}->{$mgrName}->{'requiresAuth'}
&& $this->{conf}->{$mgrName}->{'requiresAuth'} == 1 )
{
}
my ($actionPrefix) = defined ($this->{actionPrefix}) ? $this->{actionPrefix} : '_cmd_';
if (RVL::Error::count() > 0) {
my ($oLastError) = RVL::Error::pop();
$defaultMgrLoaded = 1;
$this->handleError($oLastError, $output);
}
if (!$defaultMgrLoaded) {
# all tests passed, execute relevant method
foreach my $methodName (@{ $this->{ _aActionsMapping }->{ ${$input}->{action} } } ) {
$methodName = $actionPrefix .$methodName;
RVL::logMessage("BEGIN Call: $methodName", __CONSTANT__::RVL_LOG_DEBUG);
$this->$methodName(${$input}, $output);
RVL::logMessage("END Call: $methodName", __CONSTANT__::RVL_LOG_DEBUG);
}
}
}
sub getConfig{
my ($this) = @_;
my ($c) = RVL::Config::singleton();
return $c;
}
sub display{
my ($output) = @_;
RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
# reinstate dynamically added css
if (!${${$output}->{manager}}->isValid()) {
if (defined(${$output}->{aCssFiles}) && @{ ${$output}->{aCssFiles} } > 0) {
# get action
my ($cssFile) = ${$output}->request->get('cssFile');
if (!$cssFile) {
${$output}->addCssFile($cssFile);
}
}
}
}
sub validate{
my ($this, $req, $input) = @_;
}
sub isValid {
my ($this) = @_;
return $this->{validated};
}
sub _cmd_redirectToDefault {
my ($this, $input, $output) = @_;
RVL::logMessage('', __CONSTANT__::RVL_LOG_DEBUG);
if (RVL::Error::count() <= 0) {
my ($req) = RVL::Request::singleton();
my ($params) = '/' . $req->get('moduleName') . '/' . $req->get('managerName');
my ($direct) = "index.cgi?$params";
print RVL::Session::singleton()->header(-location => $direct);
exit;
} else {
${$output}->{template} = 'error.html';
}
}
sub handleError {
my ($this, $error, $output) = @_;
${$output}->{template} = 'error.html';
${$output}->{error} = $error;
}
}
1;
Copyright 2K16 - 2K18 Indonesian Hacker Rulez