#============================================================ # EnqueteObject #============================================================ package EnqueteObject; use Common; @ISA = qw(Common); #公開したいサブルーチン @EXPORT = qw($ModuleName $ModuleExplanation $EnqueteDirectory $EnqueteTemplateDirectory ); # @DBList @CheckBlankList #@EXPORT_OK = qw(); use strict; use CGI::FormCSVConfig; #========================================== # 大域変数 #========================================== our $ModuleName = "EnqueteObject"; our $ModuleExplanation = "EnqueteObject"; #========================================== # 登録 #========================================== #============================================================ # コンストラクタ、デストラクタ #============================================================ 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) = @_; return {}; } sub BuildReplaceHash { my ($this, $App, $pParams, $charcode) = @_; $charcode = $pParams->{WebCharCode} if(!defined $charcode); $this->GetParameterHash($App, $pParams) if(!defined $pParams->{CSVConfigPath}); my ($pConfig, $pFormItem, $pHash) = $this->ReadCSVConfig($App, $pParams, $pParams->{CSVConfigPath}); #$App->print("2: [$pParams->{CSVConfigPath}]: pDBList: $pConfig->{pFormCSVDBList}\n"); if(!defined $pParams) { # $App->H3("Error: Can not read [$CSVConfigPath].\n"); return {}; } #$App->print("p: $pConfig, $pFormItem, $pHash: $pConfig->{EnqueteName}\n"); Utils::MergeHash($pHash, $pConfig); Utils::MergeHash($pHash, $pFormItem); Utils::MergeHash($pHash, $pParams); return $pHash; } #========================================== # 関数 #========================================== #sub EnqueteTemplateDirectory { return $pParams->{EnqueteTemplateDirectory}; } sub DBInfo { my ($this, $App, $pParams) = @_; my $pHash = $this->BuildReplaceHash($App, $pParams); my $DBName = Deps::MakePath($pParams->{EnqueteDirectory}, $pHash->{EnqueteDBName}, 0); my $DBTableName = $pHash->{EnqueteDBTable}; return ($pHash->{EnqueteDBMName}, $DBName, $DBTableName); # return ($pHash->{EnqueteDBMName}, $pHash->{EnqueteDBName}, $pHash->{EnqueteDBTable}); } sub GetTemplatePath { my ($this, $App, $pParams, $filename) = @_; my $lang = ($pParams->{Language})? $pParams->{Language} : 'jp'; $filename =~ s/{LanguageCode}/$lang/g; my $path = Deps::MakePath($pParams->{EnqueteTemplateDirectory}, $filename, 0); if(!-f $path) { $App->H3("Error in ${ModuleName}::GetTemplatePath: Can not read [$path].\n"); return; } return $path; } sub ReadCSVConfig { my ($this, $App, $pParams, $CSVConfigPath) = @_; return () if(!-e $CSVConfigPath); #$App->print("Config: [$pParams->{FormConfig}]\n"); if(defined $this->{pFormCSVConfig}) { $this->{pFormCSVConfig}->BuildReplaceHash($pParams); return ($this->{pFormCSVConfigConfig}, $this->{pFormCSVConfigFormItem}, $this->{pFormCSVConfigHash}); } my $fc = new FormCSVConfig; my ($pConfig, $pFormItem, $pHash, $pLabelHash, $pDBList) = $fc->ReadCSVFile($CSVConfigPath, $pParams); if(!defined $pHash) { # $App->H3("Error: Can not read [$CSVConfigPath].\n"); return {}; } my @AddDBList = Utils::Split("[\\s,;:]+", $pConfig->{AddDBList}); my @DelDBList = Utils::Split("[\\s,;:]+", $pConfig->{DeleteDBList}); my @CheckBlankList = Utils::Split("[\\s,;:]+", $pConfig->{CheckBlankList}); push(@$pDBList, qw(IsRegistered RegistrationDate LastUpdateTime LastLogonTime IPAddress)); @$pDBList = Utils::MergeList(@$pDBList, @AddDBList); @$pDBList = Utils::DeleteItemFromList($pDBList, \@DelDBList); $this->{pFormCSVConfig} = $fc; $this->{pFormCSVConfigConfig} = $pConfig; $this->{pFormCSVConfigFormItem} = $pFormItem; $this->{pFormCSVConfigHash} = $pHash; $this->{pFormCSVLabelHash} = $pLabelHash; $this->{pFormCSVDBList} = $pDBList; $this->{pFormCSVCheckBlankList} = \@CheckBlankList; $fc->{pFormCSVConfigFormItem} = $pFormItem; $fc->{pFormCSVConfigHash} = $pHash; $fc->{pFormCSVLabelHash} = $pLabelHash; $fc->{pFormCSVDBList} = $pDBList; #$App->print("0: pFormCSVConfig=$fc\n"); #$App->print("0: pDBList=$pDBList\n"); $fc->{pFormCSVCheckBlankList} = \@CheckBlankList; return ($pConfig, $pFormItem, $pHash, 1); } sub OpenDB { my ($this, $App, $pParams, $IsPrint, $DBMName0, $DBServer0, $DBUser0, $DBPassword0, $DBName0) = @_; $IsPrint = 0 if(!defined $IsPrint); $this->GetParameterHash($App, $pParams) if(!defined $pParams->{CSVConfigPath}); my ($pConfig, $pFormItem, $pHash) = $this->ReadCSVConfig($App, $pParams, $pParams->{CSVConfigPath}); $DBMName0 = $pConfig->{EnqueteDBMName} if(!defined $DBMName0); $DBServer0 = $pConfig->{EnqueteDBServer} if(!defined $DBServer0); $DBUser0 = $pConfig->{EnqueteDBUser} if(!defined $DBUser0); $DBPassword0 = $pConfig->{EnqueteDBPassword} if(!defined $DBPassword0); $DBName0 = Deps::MakePath($pParams->{EnqueteDirectory}, $pConfig->{EnqueteDBName}, 0) if(!defined $DBName0); $DBName0 = $pParams->{EnqueteDBName} if(!defined $DBName0); my $DBTableName = $pConfig->{EnqueteDBTable}; #$App->H3("OpenDB: $DBMName0:$DBName0:$DBTableName\n") if($IsPrint); my $DB = $this->{DB} = new SQLDB($DBMName0); return undef if(!$DB); $DB->SetApplication($App); $DB->SetDBCharCode($App->SQLCharCode()); $DB->SetSourceCharCode($App->WebCharCode()); $DB->Open($DBServer0, $DBUser0, $DBPassword0, $DBName0, undef, 0, 0); return $DB; } sub nHit { my ($this) = @_; return -1 if(!$this->{DB}); return $this->{DB}->nHit(); } sub GetNextHit { my ($this) = @_; return undef if(!$this->{DB}); return $this->{DB}->GetNextHit(); } sub SearchData { my ($this, $App, $pParams, $condition, $vars, $DBTableName0) = @_; return undef if(!$this->{DB}); if(!defined $DBTableName0) { my ($pConfig, $pFormItem, $pHash) = $this->ReadCSVConfig($App, $pParams, $pParams->{CSVConfigPath}); $DBTableName0 = $pConfig->{EnqueteDBTable}; } my $DB = $this->{DB}; my $ret = $DB->Search($DBTableName0, $condition, $vars); return -1 if($ret <= 0); return $DB->rows(); } 1;