#============================================================
# ParametersObject
#============================================================
package ParametersObject;
use Common;
@ISA = qw(Common);
#公開したいサブルーチン
#@EXPORT = qw(erfc tan);
@EXPORT_OK = qw();
use strict;
use JSParams;
use Template;
use MyMail;
#==========================================
# 大域変数
#==========================================
my $ModuleName = "ParametersObject";
my $ModuleExplanation = "Root class of Parameters";
my $Privilege = 'ShowParameters';
sub Name { return $ModuleName; }
sub Explanation { return $ModuleExplanation; }
sub Privileges { return $Privilege; }
#表示しない内部パラメータ
my $DontShowVariablesRegExp = "(^DB|User|Password)";
#============================================================
# コンストラクタ、デストラクタ
#============================================================
sub new
{
my ($module) = @_;
my $this = {};
bless $this;
# $this->SUPER::new(@_);
return $this;
}
sub DESTROY
{
my $this = shift;
$this->SUPER::DESTROY(@_);
}
#============================================================
# メンバー関数
#============================================================
sub GetParameterHash
{
my ($this, $App, $pParams) = @_;
$ModuleName = $pParams->{"Parameters::ModuleName"} if(defined $pParams->{"Parameters::ModuleName"});
$DontShowVariablesRegExp = $pParams->{"Parameters::DontShowVariablesRegExp"} if(defined $pParams->{"Parameters::DontShowVariablesRegExp"});
return {};
}
sub IsOpen
{
my ($this, $App, $pParams, $IsPrint) = @_;
return $App->HasPrivilege($Privilege, $IsPrint);
}
sub ShowMenu
{
my ($this, $App, $pParams, $ProgramPath, $BaseOption) = @_;
return 0 if(defined $App->{pAdminOption});
return if(!$this->IsOpen($App, $pParams, 0));
# return if(!$App->HasPrivilege('ShowParameters', 0));
my ($Option, $target) = $App->GetCGIParameters(
{ PrevAction => $pParams->{Action}, Action => "${ModuleName}::ShowParameterPage" },
[qw(+Action)],
);
$App->PrintRawHTML("{ScriptPath}?$Option\" target=\"$target\">"
. $App->mlText('en' => 'Parameters', 'jp' => '設定・変数') . " ");
}
sub ShowPage
{
my ($this, $App, $pParams) = @_;
if($App->{pAdminOption}) {
$App->{pAdminOption}->ShowSubMenu($App, $pParams);
}
return $this->ShowParameterPage($App, $pParams);
}
sub UpdateData
{
my ($this, $App, $pParams) = @_;
return if(!$this->HasPrivilege('EditParameters'));
}
sub ShowParameterPage
{
my ($this, $App, $pParams) = @_;
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
# $App->ShowMenu($pParams, $pParams->{EMail}, $pParams->{Password});
if( (!$pParams->{DoNotAllowDebugMode} and $pParams->{Debug}) or $App->HasPrivilege('ShowParameters')) {
$this->ShowModules($App, $pParams);
$App->HR();
$this->ShowUserInformation($App, $pParams);
my $db = $App->DB();
if(!$db) {
$App->H2("Error: Can not obtain DB object\n");
return;
}
elsif($db->IsExistTable($pParams->{DBName}, $pParams->{DBVariablesTableName})) {
$App->HR();
$this->ShowDBVars($App, $pParams);
}
$App->HR();
$this->ShowCommandlineParams($App, $pParams);
$App->HR();
$this->ShowTemplateVars($App, $pParams);
$App->HR();
$this->ShowHTMLHeaderParams($App, $pParams);
$App->HR();
$this->ShowParams($App, $pParams);
$App->HR();
$this->ShowEnvVars($App, $pParams);
$App->HR();
$this->DatabaseStructures($App, $pParams);
}
else {
$App->mlPrintRawHTML('en' => "
ShowParameter can be executed under Debug-mode [Debug=$pParams->{Debug}]
",
'jp' => "ShowParametersはデバッグモードでのみ有効です [Debug=$pParams->{Debug}]
");
}
}
sub ShowHTMLHeaderParams
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
$App->H2("HTML Header Variables");
my $pHash = $pParams->{pJScriptPaths};
if($pHash) {
$App->H3(" in JScriptPaths Variable\n");
foreach my $key (sort keys %$pHash) {
$App->PrintRawHTML("$key: $pHash->{$key}
\n");
}
}
my $pArray = $pParams->{pHeaderFiles};
if($pArray) {
$App->H3(" in HeaderFiles Variable\n");
for(my $i = 0 ; $i < @$pArray ; $i++) {
$App->PrintRawHTML("$i: ");
$App->print("$pArray->[$i]\n");
}
}
}
sub ShowTemplateVars
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
my $pHash = $pParams->{pTemplateFileTemplates};
return if(!$pHash);
$App->H2("Template Variables");
#$App->print("pParams=$ph\n");
$App->H3(" in DB Variables");
my $DB = $App->DB();
my $ret = 0;
if($DB) {
$ret = $DB->IsExistTable($pParams->{DBName}, $pParams->{DBVariablesTableName});
}
if($ret) {
my $CanEdit = $App->HasPrivilege('EditParameters', 0);
$DB->Search($pParams->{DBVariablesTableName}, "order by VarName,sn", "");
while(1) {
my %Hash = $DB->GetNextHit();
last if(!defined $Hash{VarName} or $Hash{VarName} eq '');
next if($Hash{VarName} !~ /:/);
$Hash{Value} = Utils::InvalidateHTMLTags($Hash{Value});
if($CanEdit) {
$App->PrintRawHTML("$Hash{sn}: "
."{ScriptPath}?sn=$pParams->{sn}&"
."EMail=$pParams->{EMail}&Password=$pParams->{Password}&"
."Language=$pParams->{Language}&"
."VarSN=$Hash{sn}&PrevAction=$pParams->{Action}&"
."ExtendedMenu=$pParams->{ExtendedMenu}&ShowAll=$pParams->{ShowAll}&"
."Action=${ModuleName}::ShowEditDBVariablePage\" target=\"_self\">$Hash{VarName}: $Hash{Value}
\n");
}
else {
$App->PrintRawHTML("$Hash{VarName}: $Hash{Value}
\n");
}
}
}
$App->H3(" in Deault Parameters");
foreach my $key (sort keys %$pHash) {
$App->PrintRawHTML("$key: $pHash->{$key}
\n");
}
}
sub ShowParams
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
my $pHash = ($App->can('BuildReplaceHash'))? $App->BuildReplaceHash($pParams, undef, $pParams->{sn}, "Abstract", $pParams) : $pParams;
# my $ph = $App->{pParams};
$App->H2("Internal Variables");
#$App->print("pParams=$ph\n");
foreach my $key (sort keys %$pHash) {
next if($key =~ /$DontShowVariablesRegExp/i);
$App->PrintRawHTML("$key: $pHash->{$key}
\n");
}
}
sub ChangeDBVariable
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('EditParameters'));
# return if(!$App->HasPrivilege('ShowParameters', 1));
my $DB = $App->DB();
return if(!$DB);
return if(!$DB->IsExistTable($pParams->{DBName}, $pParams->{DBVariablesTableName}));
# $App->print("Val: $pParams->{VarValue}\n");
# $App->print("SN: $pParams->{VarSN}\n");
if($pParams->{Change}) {
my $ret = $DB->UpdateData($pParams->{DBVariablesTableName}, "sn=$pParams->{VarSN}",
Value => $pParams->{VarValue}
);
if(!$ret) {
$App->H3("Error in ChangeDBVariable: The DB variable [$pParams->{VarName}] was not changed.");
}
else {
my %Hit = $DB->GetNextHit();
$App->H3("The DB variable [$pParams->{VarName}] has been updated.");
}
}
elsif($pParams->{Delete}) {
my $ret = $DB->DeleteData($pParams->{DBVariablesTableName}, "sn=$pParams->{VarSN}");
if(!$ret) {
$App->H3("Error in ChangeDBVariable: The DB variable [$pParams->{VarName}] was not deleted.");
}
else {
my %Hit = $DB->GetNextHit();
$App->H3("The DB variable [$pParams->{VarName}] has been deleted.");
}
}
$App->HR();
$this->ShowDBVars($App, $pParams);
}
sub ShowEditDBVariablePage
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('EditParameters'));
# return if(!$App->HasPrivilege('ShowParameters', 1));
my $DB = $App->DB();
return if(!$DB);
return if(!$DB->IsExistTable($pParams->{DBName}, $pParams->{DBVariablesTableName}));
#http://booking.khlab.msl.titech.ac.jp/cgi-bin/Kamiya.pl?sn=&EMail=tkamiya@lucid.msl.titech.ac.jp&Password=e_cItyl6iHfKhHw3C062W5wQHHtHi4&Language=jp&VarSN=3&PrevAction=Parameters::ShowPage&ExtendedMenu=1&ShowAll=0&Action=Parameters::ShowEditDBVariablePage
$DB->Search($pParams->{DBVariablesTableName}, "sn=$pParams->{VarSN}", "");
my $nHit = $DB->nHit();
# my $nHit = $App->SearchDBVariables("sn=$pParams->{VarSN}", "");
if($nHit <= 0) {
$App->H3("Error in ShowEditDBVariablePage: Variable [$pParams->{VarSN}] is not found.\n");
}
else {
my %Hit = $App->DB()->GetNextHit();
$App->print("VarSN=$pParams->{VarSN} [$Hit{sn}]\n");
my $s = JSParams->new()->GetJSResizableString('.TextAreaText');
$App->PrintRawHTML("$s\n");
print <
(#$Hit{sn}) $Hit{VarName}:
---
EOT
}
$App->HR();
$this->ShowDBVars($App, $pParams);
}
sub ShowDBVars
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
my $DB = $App->DB();
return if(!$DB);
return if(!$DB->IsExistTable($pParams->{DBName}, $pParams->{DBVariablesTableName}));
my $CanEdit = $App->HasPrivilege('EditParameters', 0);
$App->H2("DB Variables");
$DB->Search($pParams->{DBVariablesTableName}, "order by VarName,sn", "");
while(1) {
my %Hash = $DB->GetNextHit();
last if(!defined $Hash{VarName} or $Hash{VarName} eq '');
$Hash{Value} = Utils::InvalidateHTMLTags($Hash{Value});
if($CanEdit) {
$App->PrintRawHTML("$Hash{sn}: "
."{ScriptPath}?sn=$pParams->{sn}&"
."EMail=$pParams->{EMail}&Password=$pParams->{Password}&"
."Language=$pParams->{Language}&"
."VarSN=$Hash{sn}&PrevAction=$pParams->{Action}&"
."ExtendedMenu=$pParams->{ExtendedMenu}&ShowAll=$pParams->{ShowAll}&"
."Action=${ModuleName}::ShowEditDBVariablePage\" target=\"_self\">$Hash{VarName}: $Hash{Value}
\n");
}
else {
$App->PrintRawHTML("$Hash{VarName}: $Hash{Value}
\n");
}
}
}
sub ShowModulesByType
{
my ($this, $App, $pParams, $Type, $pModule) = @_;
return if(!$pModule);
my $pInf = $App->{pModuleInf};
if($pInf) {
$App->BeginTable(1);
$App->BeginTableHeader();
$App->BeginTableRow();
$App->TableCell("File
\n");
# $App->TableCell("Name\n");
$App->TableCell("Menu\n");
$App->TableCell("Explanation\n");
$App->TableCell("Privileges\n");
$App->TableCell("Path\n");
$App->EndTableHeader();
$App->BeginTableBody();
for(my $i = 0 ; $i < @$pInf ; $i++) {
next if($pInf->[$i]{Type} ne $Type);
my $p = $pInf->[$i];
my $ModuleName = $p->{Name};
my $Path = $p->{Path};
my $pm = $App->{"p$ModuleName"};
my $Name = ($pm->can('Name'))? $pm->Name() : '';
my $Explanation = ($pm->can('Explanation'))? $pm->Explanation() : '';
my $Privilege = ($pm->can('Privilege'))? $pm->Privilege() : '';
my $Privileges = ($pm->can('Privileges'))? $pm->Privileges() : '';
$Privileges = "$Privileges,$Privilege";
$Privileges =~ s/^,//;
$Privileges =~ s/,$//;
$Privileges =~ s/,\s*/, /g;
my $OutputMode = $App->GetOutputMode();
$App->SetOutputMode('WriteBuffer');
my $MenuLabel = '';
if($pm->can('ShowMenu')) {
$pm->ShowMenu($App, $pParams);
$MenuLabel = $App->GetBuffer();
}
$App->SetOutputMode($OutputMode);
$App->BeginTableRow();
$App->TableCell("$ModuleName.pm
$Name\n");
# $App->TableCell("$Name\n");
$App->TableCell("$MenuLabel\n");
$App->TableCell("$Explanation\n");
$App->TableCell("$Privileges\n");
$App->TableCell("$Path\n");
$App->EndTableRow();
}
$App->EndTableBody();
$App->EndTable();
}
else {
for(my $i = 0 ; $i < @$pModule ; $i++) {
my $m = $pModule->[$i];
$App->PrintRawHTML("$m
\n");
}
}
}
sub ShowModules
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
my $pInf = $App->{pModuleInf};
$App->H2("Modules");
$App->H3("Admin Modules");
$this->ShowModulesByType($App, $pParams, 'Admin', $App->{pAdminModules});
$App->H3("User Modules");
$this->ShowModulesByType($App, $pParams, 'User', $App->{pUserModules});
$App->H3("NoLogon Modules");
$this->ShowModulesByType($App, $pParams, 'NoLogon', $App->{pNoLogonModules});
}
sub ShowCommandlineParams
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
$App->H2("Commandline Parameters");
my $Args = $App->Args();
my %Arg = $Args->GetArgHash();
foreach my $key (sort keys %Arg) {
$App->PrintRawHTML("$key: $Arg{$key}
\n");
}
}
sub ShowEnvVars
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
$App->H2("Environment Variables");
foreach my $key (sort keys %ENV) {
$App->PrintRawHTML("$key: $ENV{$key}
\n");
}
}
sub DatabaseStructures
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
$App->H2("Database structures");
# Database->new()->ShowDatabases($this, $App->DB());
# Database->new()->ShowTables($this, $App->DB(), $DBRegistersTableName);
my @TableName = $App->{DB}->GetTables($App->{pParams}->{DBName}, 0);
for(my $i = 0 ; $i < @TableName ; $i++) {
$App->PrintRawHTML("\n");
$App->PrintRawHTML(" \n");
$App->PrintRawHTML(" $TableName[$i] | \n");
$App->PrintRawHTML(" | \n");
$App->PrintRawHTML("
\n");
my @FieldName = $App->{DB}->GetFields($TableName[$i], $TableName[$i], 0);
my @FieldType = $App->{DB}->GetFieldTypes($TableName[$i], $TableName[$i], undef, 0);
for(my $j = 0 ; $j < @FieldName ; $j++) {
# $this->print(" $FieldName[$j] $FieldType[$j]\n");
$App->PrintRawHTML(" \n");
$App->PrintRawHTML(" $FieldName[$j] | \n");
$App->PrintRawHTML(" $FieldType[$j] | \n");
$App->PrintRawHTML("
\n");
}
$App->PrintRawHTML("
\n");
}
}
sub ShowUserInformation
{
my ($this, $App, $pParams) = @_;
return if(!$App->HasPrivilege('ShowParameters', 1));
$App->SendNotificationForPrivilegedAccessMail($App, $pParams);
$App->H2("User Information");
$App->ShowUserInformation($App, $pParams) if($App->can('ShowUserInformation'));
}
1;