#============================================================ # WebLinkObject #============================================================ package WebLinkObject; use Common; @ISA = qw(Common); #公開したいサブルーチン #@EXPORT = qw(erfc tan); @EXPORT_OK = qw(); use strict; use Template; #========================================== # 大域変数 #========================================== #============================================================ # コンストラクタ、デストラクタ #============================================================ sub new { my ($module) = @_; my $this = {}; bless $this; # $this->SUPER::new(@_); return $this; } sub DESTROY { my $this = shift; $this->SUPER::DESTROY(@_); } sub SetApparatusMode { my ($this,$f)=@_; return $this->{ApparatusMode} = $f; }; #============================================================ # メンバー関数 #============================================================ sub ShowMenu { my ($this, $App, $pParams, $ProgramPath, $BaseOption, $ModuleName, $pMenuTitle, $TryDirectLink) = @_; $TryDirectLink = 1 if(!defined $TryDirectLink); my ($Option, $target) = $App->GetCGIParameters( { Action => "${ModuleName}::ShowPage", PrevAction => $pParams->{Action}, }, [qw(+Action)]); # [qw(Action PrevAction App EMail Password Language ShowAll ExtendedMenu IsChildFrame DBConfigName File Path Year Month Day)]); my ($ret, $link) = ($TryDirectLink)? $this->BuildLink($App, $pParams, 1) : (0, ''); #$App->print("T: $TryDirectLink ret=$ret\n"); if($ret >= 1) { $App->PrintRawHTML($link); } else { $App->PrintRawHTML("{ScriptPath}?$Option\" target=\"$target\">" . $App->mlText(%$pMenuTitle) . " "); } return 1; } sub ShowPage { my ($this, $App, $pParams, $ModuleName) = @_; my ($ret, $link) = $this->BuildLink($App, $pParams); if($ret == 1) { $App->PrintRawHTML($link); } elsif($ret == -1) { $App->H3("Error in ${ModuleName}::ShowPage: Your account [$pParams->{EMail}] is not registered in this Users DB."); $App->PrintRawHTML($link); } elsif($ret == 3) { $App->H3("Your account [$pParams->{EMail}] does not exist in the target User DB."); $App->H3("This account [$pParams->{EMail}] has been added to the target User DB.\n"); $App->PrintRawHTML($link); } elsif($ret == -2) { $App->H3("Your account [$pParams->{EMail}] does not exist in the target User DB."); $App->PrintRawHTML($link); } elsif($ret == 3) { $App->H3("Your password does not match with the target password."); $App->H3("The target password has been changed."); $App->PrintRawHTML($link); } elsif($ret == -3) { $App->H3("Your password does not match with the target password."); $App->PrintRawHTML($link); } } sub BuildGroups { my ($this, $App, $pParams, $MyGroups, $TargetGroups, $DefaultGroups, $pOptionGroups) = @_; return '' if($MyGroups eq ''); my @MyGrs = Utils::Split("\\s*[\|,]\\s*", $MyGroups); my @Total = Utils::Split("\\s*[\|,]\\s*", $TargetGroups); my @a1 = Utils::Split("\\s*[\|,]\\s*", $DefaultGroups); @Total = Utils::MergeList(@Total, @a1); my $LabStr = "研究室"; my $Frontier = "フロンティア"; if($pParams->{SQLCharCode}) { Jcode::convert(\$LabStr, $pParams->{SQLCharCode}); Jcode::convert(\$Frontier, $pParams->{SQLCharCode}); } my %GroupKeys = ( $LabStr => 'HKLab', 'SORST' => 'Project', $Frontier => 'Project', ); foreach my $gr (@MyGrs) { my $opt; foreach my $key (keys %GroupKeys) { if($gr =~ /$key/i) { $opt = $pOptionGroups->{$GroupKeys{$key}}; last if($opt); } } next if(!defined $opt); my @a2 = Utils::Split("\\s*[\|,]\\s*", $opt); @Total = Utils::MergeList(@Total, @a2); } my $ret = ''; foreach my $s (sort @Total) { if($ret eq '') { $ret = $s; } else { $ret .= ",$s"; } } return $ret; } sub BuildPrivileges { my ($this, $App, $pParams, $MyPrivileges, $TargetPrivileges, $DefaultPrivileges, $pOptionPrivileges) = @_; my @MyPrivs = Utils::Split("\\s*[\|,]\\s*", $MyPrivileges); my @Total = Utils::Split("\\s*[\|,]\\s*", $TargetPrivileges); my @a1 = Utils::Split("\\s*[\|,]\\s*", $DefaultPrivileges); @Total = Utils::MergeList(@Total, @a1); foreach my $pr (@MyPrivs) { next if(!defined $pOptionPrivileges->{$pr}); my @a2 = Utils::Split("\\s*[\|,]\\s*", $pOptionPrivileges->{$pr}); @Total = Utils::MergeList(@Total, @a2); } my $ret = ''; foreach my $s (sort @Total) { if($ret eq '') { $ret = $s; } else { $ret .= ",$s"; } } return $ret; } sub GetMyInformation { my ($this, $App, $pParams, $UsersTableName) = @_; my $DB = $App->DB(); return {} if(!$DB); $DB->Search($UsersTableName, "EMail='$pParams->{EMail}' order by sn", ""); my %Hit = $App->DB()->GetNextHit(); return %Hit; } sub GetDB { # my ($this, $App, $pParams, $AppModuleName, $DBConfigName) = @_; my ($this, $App, $pParams, $pDBConfigArray, $DBConfigName) = @_; return $App->MyCGIApplication::OpenDB($DBConfigName, $pDBConfigArray); # my ($DB, $DBConfigName, $DBMName, $DBServer, $DBUser, $DBPassword, $DBName, @TableNames); #eval("use $AppModuleName;" . 'my $ExtApp = new ' . "$AppModuleName;" # .'($DB, $DBConfigName, $DBMName, $DBServer, $DBUser, $DBPassword, $DBName, @TableNames) = $ExtApp->OpenDB($DBConfigName);' # ."no $AppModuleName"); # return ($DB, $DBConfigName, $DBMName, $DBServer, $DBUser, $DBPassword, $DBName, @TableNames); } sub BuildLink { my ($this, $App, $pParams, $ForMenu, $URLTemplate, $pLinkTitle, $pMenuTitle, $URLTemplate, $CreateNewUser, $ChangePassword, $CryptPassword, $ChangePrivileges, $ChangeGroups) = @_; $ChangeGroups = 0 if(!defined $ChangeGroups); my %Hit = $this->GetMyInformation($App, $pParams); if($Hit{Password} eq '') { my $URL = Template->new()->ReplaceByHash($URLTemplate, $pParams, '{', '}', 0, 1, 0, 1); return (-1, "Try this URL: " . $App->mlText(%$pLinkTitle) . "\n"); } my ($DB, $DBConfigName, $DBMName, $DBServer, $DBUser, $DBPassword, $DBName, @TableNames) = $this->GetDB($App, $pParams); return "no DB found" if(!defined $DB); $DB->Search($TableNames[0], "EMail='$pParams->{EMail}' order by sn", ""); my $nHit = $DB->nHit(); $App->print("nHit=$nHit\n"); my %ExtHit = $DB->GetNextHit(); my @DBArray = (); $App->print("ChangePrivileges=$ChangePrivileges, ChangeGroups=$ChangeGroups\n"); if($ChangePrivileges or $nHit == 0) { my $pr = $this->BuildPrivileges($App, $pParams, $pParams->{LogonUserPrivilege}, $ExtHit{Privilege}); @DBArray = (Privilege => $pr); } if($this->{ApparatusMode} and ($ChangeGroups or $nHit == 0)) { $App->print("DB: $DBName\n"); $App->print("Groups: [$Hit{Groups}] [$ExtHit{Apparatus}]\n"); my $gr = $this->BuildGroups($App, $pParams, $Hit{Groups}, $ExtHit{Apparatus}); @DBArray = (@DBArray, Apparatus => $gr); } $App->print("DB: [", join('][', @DBArray), "]\n"); my $ret = 1; if($nHit == 0) { if($CreateNewUser) { $ret = 2; $DB->InsertData($TableNames[0], Name => $Hit{Name}, EMail => $Hit{EMail}, Password => $Hit{Password}, UpdateDate => time(), @DBArray, ); } else { $ret = -2; my $URL = Template->new()->ReplaceByHash($URLTemplate, $pParams, '{', '}', 0, 1, 0, 1); return ($ret, "Try this URL: " . $App->mlText(%$pLinkTitle) . "\n"); } } else { if($Hit{Password} ne $ExtHit{Password}) { if($ChangePassword) { $ret = 3; $DB->UpdateData($TableNames[0], "sn=$ExtHit{sn}", Password => $Hit{Password}, UpdateDate => time(), @DBArray, ); } else { $ret = -3; my $URL = Template->new()->ReplaceByHash($URLTemplate, \%Hit, '{', '}', 0, 1, 0, 1); return ($ret, "Try this URL: " . $App->mlText(%$pLinkTitle) . "\n"); } } if($ChangePrivileges or $ChangeGroups) { $ret = 4; $DB->UpdateData($TableNames[0], "sn=$ExtHit{sn}", UpdateDate => time(), @DBArray, ); } } $Hit{Password} = $App->Crypt($Hit{Password}) if($CryptPassword); my $URL = Template->new()->ReplaceByHash($URLTemplate, \%Hit, '{', '}', 0, 1, 0, 1); if($ForMenu) { return ($ret, "" . $App->mlText(%$pMenuTitle) . "\n"); } return ($ret, "" . $App->mlText(%$pLinkTitle) . "\n"); } 1;