#============================================================ # MyHTMLApplication #============================================================ package MyHTMLApplication; use MyApplication; @ISA = qw(MyApplication); use strict; use English; use File::Path; use File::Basename; use File::Find; use CGI; use Cwd; #use UTF8Code; use Deps; use Utils; use JFile; use IniFile; use GetArg; use Template; #========================================== # 大域変数 #========================================== my $DefaultSendmail = '/usr/sbin/sendmail'; my $SourceCharCode = Jcode::getcode('月火水木金土日 '); #============================================================ # 静的関数 #============================================================ #============================================================ # 変数等取得関数 #============================================================ sub CSSPath { return shift->{CSSPath}; } sub WebRoot { return shift->{WebRoot}; } sub CGIPath { return shift->{CGIPath}; } #============================================================ # コンストラクタ、デストラクタ #============================================================ BEGIN { } sub new { my ($module, $app) = @_; my $this = {}; bless $this; # $this->SUPER::new(@_); return $this; } sub DESTROY { my $this = shift; # $this->SUPER::DESTROY(@_); } #============================================================ # 継承クラスで定義しなおす関数 #============================================================ #============================================================ # 一般関数 #============================================================ sub MenuMode { return shift->{MenuMode}; } sub SetMenuMode { my ($this, $mode) = @_; return $this->{MenuMode} = $mode; } sub ConvertToHTML { my ($this, $s) = @_; $s =~ s/[\r\n\s]*$//; $s =~ s/\r//g; $s =~ s/^[ \n\s]+/ /g; # $s =~ s/^[ \n\s]+/   /g; $s =~ s/[\n][\n\s]*\[/

[/g; $s =~ s/[\n][\n\s]*\[/
[/g; $s =~ s/[\n][\n\s]*/
 /g; # $s =~ s/[\n][\n\s]*/
   /g; return $s; } sub GetCSSKeys { my ($App, $pParams, $SpanID, $SpanClass) = @_; if($App->MenuMode() eq 'css') { if($SpanID !~ /=/) { $SpanID = "class=\"$SpanID\""; } if($SpanClass !~ /=/) { $SpanClass = "class=\"$SpanClass\""; } return ("", "", "", ""); } return ('', '', '', ''); } sub GetMainMenuKeys { my ($App, $pParams) = @_; my ($MainPre, $MainPos, $pre, $pos) = $App->GetCSSKeys($pParams, "id=\"MainMenu\"", "class=\"MenuItem\""); return ($MainPre, "$MainPos

", $pre, $pos) if($MainPre ne ''); return ($MainPre, $MainPos, $pre, $pos); } sub GetSubMenuKeys { my ($App, $pParams) = @_; my ($MainPre, $MainPos, $pre, $pos) = $App->GetCSSKeys($pParams, "class=\"SubMenu\"", "class=\"MenuItem\""); return ($MainPre, "$MainPos

", $pre, $pos) if($MainPre ne ''); return ($MainPre, $MainPos, $pre, $pos); } sub SetHTMLHeader { my ($this, $Title, $WebCharSet, $LinkTarget, $CSS, %args) = @_; $this->{Title} = $Title; $this->{WebCharSet} = $WebCharSet; $this->{LinkTarget} = $LinkTarget; $this->{CSS} = $CSS; $this->{pHeaderFiles} = $args{-pHeaderFiles}; $this->{pHeaderFiles} = $args{pHeaderFiles} if(!defined $args{-pHeaderFiles}); } sub SetHTMLInitialized { my ($this, $f) = @_; $f = 1 if(!defined $f); return $this->{HTMLInitialized} = $f; } sub ShowBlankPage { my ($this, $title, $charset) = @_; $title = 'Blank page' if(!defined $title); $charset = 'iso-8859-1' if(!defined $charset); $this->InitHTML($title, $charset, '_self'); $this->EndHTML(); } sub IsFrameMode { return (shift->{pFrameModeHash})? 1 : 0; } sub GetFrameMode { my ($this) = @_; return $this->pParams()->{FrameMode} if($this->pParams()->{FrameMode}); my $FrameMode = ''; if($this->{pFrameModeHash}) { if($this->{pFrameModeHash}->{FrameMode} =~ /cols/i) { $FrameMode = 'cols'; } elsif($this->{pFrameModeHash}->{FrameMode} =~ /rows/i) { $FrameMode = 'rows'; } } return $FrameMode; } sub SetFrameMode { my ($this, %args) = @_; $this->SetOutputMode('HTML'); $this->{HTMLInitialized} = 0; $this->{pFrameModeHash} = \%args; $this->pParams()->{FrameMode} = $this->GetFrameMode(); } sub InitHTMLFramePage { my ($this, $WebCharSet, $PrintHTMLHeader, $pHash, %args) = @_; $WebCharSet = 'iso-8859-1' if(!defined $WebCharSet); $PrintHTMLHeader = 1 if(!defined $PrintHTMLHeader); $pHash = $this->{pFrameModeHash} if(!defined $pHash); $pHash->{Title} = 'No title' if(!defined $pHash->{Title}); $pHash->{FrameMode} = "rows='64,*'" if(!defined $pHash->{FrameMode}); $pHash->{Content} = '

This page uses Frame, but your browser does not support it.

\n' if(!defined $pHash->{Content}); Utils::PrintHTMLHeader($WebCharSet) if($PrintHTMLHeader); my $FrameSetOption = ''; $FrameSetOption .= " framespacing=\"$pHash->{framespacing}\"" if(defined $pHash->{framespacing}); $FrameSetOption .= " border=\"$pHash->{border}\"" if(defined $pHash->{border}); $FrameSetOption .= " frameborder=\"$pHash->{frameborder}\"" if(defined $pHash->{frameborder}); my $Frame1Option = ''; $Frame1Option .= " scrolling='$pHash->{Frame1}->{scrolling}'" if(defined $pHash->{Frame1}->{scrolling}); $Frame1Option .= " resize='$pHash->{Frame1}->{resize}'" if(defined $pHash->{Frame1}->{resize}); $Frame1Option .= " target='$pHash->{Frame1}->{target}'" if(defined $pHash->{Frame1}->{target}); my $Frame2Option = ''; $Frame2Option .= " scrolling='$pHash->{Frame2}->{scrolling}'" if(defined $pHash->{Frame2}->{scrolling}); $Frame2Option .= " resize='$pHash->{Frame2}->{resize}'" if(defined $pHash->{Frame2}->{resize}); $Frame2Option .= " target='$pHash->{Frame2}->{target}'" if(defined $pHash->{Frame2}->{target}); my $Frame1Str = "{Frame1}->{name}\" $Frame1Option src=\"$pHash->{Frame1}->{src}\">"; my $Frame2Str = "{Frame2}->{name}\" $Frame2Option src=\"$pHash->{Frame2}->{src}\">"; my $DOCTYPEStr = Utils::GetDOCTYPEStr($args{DOCTYPEKey}); $DOCTYPEStr = '' if($DOCTYPEStr eq ''); print < $pHash->{Title} {FrameMode} $FrameSetOption> $Frame1Str $Frame2Str <body> $pHash->{Content} </body> EOT } sub GetURLServerName { my ($this) = @_; my ($head) = ($ENV{HTTP_REFERER} =~ /^(.*?:\/\/.*?\/)/); $head = $ENV{HTTP_REFERER} if(!defined $head); return $head; } #========================================== # CGIパラメータ文字列の作成 #========================================== sub GetCGIParameters { my ($this, $pModifiedParams, $pKeys, $DefaultTarget, $DefaultFrameTarget, $ForFrame, $phash) = @_; $DefaultTarget = '_self' if(!defined $DefaultTarget); $DefaultFrameTarget = 'Main' if(!defined $DefaultFrameTarget); my $target = ($this->pParams()->{IsChildFrame})? $DefaultFrameTarget : $DefaultTarget; return ($this->BuildCGIOption($pModifiedParams, $pKeys, $ForFrame), $target, $phash); } sub BuildCGIOption { my ($this, $pModifiedParams, $pKeys, $ForFrame, $phash) = @_; $pModifiedParams = {} if(!defined $pModifiedParams); # $pKeys = [qw(Action App EMail Password Language ShowAll ExtendedMenu # PrevAction IsChildFrame FrameMode DBConfigName Year Month Day)] if(!defined $pKeys); my @DefKeys = qw(NextAction App EMail Password Language App ShowAll ExtendedMenu PrevAction DBConfigName Year Month Day UseFrame Keyword1 SearchTarget1 Operator1 Keyword2 SearchTarget2 Order Ascend ShowAccepted ShowPending ShowReconsider ShowTSFTOEOProc ShowTOEOProc ShowReject ValidAbstractOnly ValidProgramOnly LocalOrganizingCommitteeOnly UnsendAbstractAceptanceNoticeOnly); $phash->{URLEncode} = 1 if(!defined $phash->{URLEncode}); $phash->{ConvertCharCode} = $this->pParams()->{WebCharCode} if(!defined $phash->{ConvertCharCode}); my $URLEncode = ($phash->{URLEncode})? 1 : 0; my $ConvertCharCode = ($phash->{ConvertCharCode} ne '')? $phash->{ConvertCharCode} : ''; #$this->print(""); if(!defined $pKeys) { $pKeys = [@DefKeys]; } else { my @Keys; my @DelList; my %Hash; my $UpdateDef = 0; for(my $i = 0 ; $i < @$pKeys ; $i++) { #print "$i: [$pKeys->[$i]]
\n"; if($pKeys->[$i] =~ /^-/) { #print "del $pKeys->[$i]
\n"; $pKeys->[$i] =~ s/^.//; push(@DelList, $pKeys->[$i]); $Hash{$pKeys->[$i]} = 1; $UpdateDef = 1; } elsif($pKeys->[$i] =~ /^\+/) { #print "add $pKeys->[$i]
\n"; $pKeys->[$i] =~ s/^\+//; push(@Keys, $pKeys->[$i]); $Hash{$pKeys->[$i]} = 1; $UpdateDef = 1; } else { #if($pKeys->[$i] =~ /^\+/) { #print "add $pKeys->[$i]
\n"; $pKeys->[$i] =~ s/^\+//; push(@Keys, $pKeys->[$i]); $Hash{$pKeys->[$i]} = 1; # $UpdateDef = 1; } } #print "Upd:$UpdateDef: nDel=", scalar @DelList, "
\n"; if($UpdateDef) { for(my $i = 0 ; $i < @DefKeys ; $i++) { next if($Hash{$DefKeys[$i]}); my $Skip = 0; for(my $j = 0 ; $j < @DelList ; $j++) { #print "$i,$j: $DefKeys[$i] (Del: $DelList[$j])
\n"; if($DefKeys[$i] eq $DelList[$j]) { $Skip = 1; last; } } next if($Skip); push(@Keys, $DefKeys[$i]); $Hash{$DefKeys[$i]} = 1; } $pKeys = [Utils::ExtractUniqueElement(\@Keys)]; } } my %hash; Utils::MergeHash(\%hash, $this->pParams()); Utils::MergeHash(\%hash, $pModifiedParams); my $Option = ''; for(my $i = 0 ; $i < @$pKeys ; $i++) { my $key = $pKeys->[$i]; my $val = $hash{$key}; if(defined $val) { if($ConvertCharCode ne '') { Jcode::convert(\$key, $ConvertCharCode) if(Utils::IsJapanese($key)); Jcode::convert(\$val, $ConvertCharCode) if(Utils::IsJapanese($val)); } if($URLEncode) { $key = Utils::URLEncode($key) if(Utils::IsJapanese($key)); $val = Utils::URLEncode($val) if(Utils::IsJapanese($val)); } if($Option eq '') { if($ForFrame) { $Option = " \n"; } else { $Option = "$key=$hash{$key}"; } } else { if($ForFrame) { $Option .= " \n"; } else { $Option .= "&$key=$val"; } } } } return $Option; } #========================================== # form文字列の作成 #========================================== sub GetClassIDOption { my ($this, %args) = @_; my $option = (defined $args{id})? " id=\"$args{id}\"" : ' '; $option .= (defined $args{class})? " class=\"$args{class}\"" : ' '; $option .= (defined $args{style})? " style=\"$args{style}\"" : ' '; $option =~ s/^\s+/ /; $option =~ s/\s+$//; return $option; } sub BuildLinkOption { my ($this, %args) = @_; my $option = ''; foreach my $key (keys %args) { next if(!defined $key); if($key eq '') { $option .= " $args{$key}"; } else { $option .= " $key=\"$args{$key}\""; } } return $option; } sub OnOffToNum { my ($App, $val) = (@_); return $val if($val =~ /^[\-\+]?\d+$/); return 0 if(!defined $val or uc $val eq 'OFF'); return 1 if(uc $val eq 'ON'); return 0; } sub NumToOnOff { my ($App, $val, $on, $off) = (@_); $on = 'ON' if(!defined $on); $off = 'OFF' if(!defined $off); return $on if($val); return $off; } sub MakeHRefLinkString { my ($App, $pParams, $link, $label, %args) = @_; my $option = $App->BuildLinkOption(%args); my $s = "$label"; return $s; } sub ExecuteCommand { my ($App, $pParams, $cmd, $UsePipe) = @_; if($^O eq 'MSWin32') { $cmd =~ s/\//\\/g; } if(!$UsePipe) { my $ret = system($cmd); #$App->print("ret=$ret\n"); if($ret >= 32) { $cmd =~ s/(passw(or)?d\s*=\s*)(\S+)/$1\*\*\*/sig; $App->print("Error: Exec [$cmd] failed.\n"); return 0; } return 1; } else { if(open(IN, "$cmd |")) { while(1) { my $line = ; last if(!defined $line); Jcode::convert(\$line,'utf8', 'sjis'); $App->print("$line\n"); } close(IN); $cmd =~ s/(passw(or)?d\s*=\s*)(\S+)/$1\*\*\*/sig; $App->print("Execute [$cmd \|] suceeded.\n"); return 1; } else { $cmd =~ s/(passw(or)?d\s*=\s*)(\S+)/$1\*\*\*/sig; $App->print("Error: Open [$cmd \|] failed.\n"); return 0; } } return 1; } sub IsThumbnailFile { my ($App, $fname) = @_; return 1 if($fname =~ /tiny-/i); return 1 if($fname =~ /small\.[a-z]+$/i); return 0; } sub MakeThumbnail { my ($App, $pParams, $Path) = @_; return if($Path =~ /\.(pdf|zip)$/i); my $IsPrint = 0; my $ChangeDir = 1; my $UsePipe = 0; my ($drive, $directory, $filename, $ext1, $lastdir, $filebody) = Deps::SplitFilePath($Path); next if($App->IsThumbnailFile($filename)); $directory =~ s/\\/\//g; $directory = "$drive$directory"; my $pwd = cwd(); if($ChangeDir) { if(chdir($directory)) { $App->print("chdir from [$pwd] to [$directory] suceeded.\n") if($IsPrint); } else { $App->print("chdir from [$pwd] to [$directory] failed.\n") if($IsPrint); return; } } my $mdate = Utils::GetWriteDate($Path); my $date = Utils::BuildDateString($mdate); my $OriginalPath = ($ChangeDir)? $filename : $Path; my $ThumbnailFileName = "tiny-" . $filename; my $ThumbnailPath = ($ChangeDir)? $ThumbnailFileName : Utils::MakePath($directory, $ThumbnailFileName, '/', 0); #$App->print("TP[$ThumbnailFileName][$fname]\n"); if((!-e $ThumbnailPath or $mdate > Utils::GetWriteDate($ThumbnailPath)) ) { # my $width = ($this->{PictureThumbnailWidth} > 0)? $this->{PictureThumbnailWidth} : $pParams->{PictureThumbnailWidth}; my $width = 300; my $op = "\"$OriginalPath\""; my $tp = "\"$ThumbnailPath\""; my $cmd = "\"$pParams->{convertPath}\" -resize $width $op $tp"; #Jcode::convert(\$cmd, $pParams->{FileSystemCharCode}); if($^O eq 'MSWin32') { $cmd =~ s/\//\\/g; } $App->print(" Making thumbnail [$cmd]\n"); if(!$App->ExecuteCommand($pParams, $cmd, $UsePipe)) { $App->print("Error: Execute [$cmd] failed\n"); } } if($ChangeDir) { if(chdir($pwd)) { $App->print("chdir to [$pwd] suceeded.\n") if($IsPrint); } else { $App->print("chdir to [$pwd] failed.\n") if($IsPrint); return; } } } sub MakePDFFirstPageImage { my ($App, $pParams, $Path, %args) = @_; return if($Path !~ /\.pdf$/i); my $IsPrint = 0; my $ChangeDir = 1; my $UsePipe = 0; my $TempPDFName = 'first_page_only.pdf'; my $TempCopyFile = "CopiedTemp.pdf"; my $ImageFileDensity = 192; #my $ghostscriptPath = "D:\\Programs\\gnu\\gs\\gs9.00\\bin"; my $ghostscriptPath = "D:\\Programs\\gnu\\gs\\gs9.05\\bin"; Jcode::convert(\$Path, $pParams->{FileSystemCharCode}); my ($drive, $directory, $filename, $ext1, $lastdir, $filebody) = Deps::SplitFilePath($Path); $directory =~ s/\\/\//g; $directory = "$drive$directory"; my $pwd = cwd(); if($ChangeDir) { if(chdir($directory)) { $App->print("chdir from [$pwd] to [$directory] suceeded.\n") if($IsPrint); } else { $App->print("chdir from [$pwd] to [$directory] failed.\n") if($IsPrint); return; } } if($^O eq 'MSWin32') { $ENV{PATH} = "$ghostscriptPath;$ENV{PATH}"; } my $OriginalFullPath; if(-e $TempPDFName and !unlink($TempPDFName)) { $App->H3("Error in MyHTMLApplication::MakePDFFirstPageImage: Can not delete [$TempPDFName].\n"); return; } if(-e $TempCopyFile and !unlink($TempCopyFile)) { $App->H3("Error in MyHTMLApplication::MakePDFFirstPageImage: Can not delete [$TempCopyFile].\n"); return; } return if(lc $filename eq lc $TempPDFName or lc $filename eq lc $TempCopyFile); my $JPEGFileName = "$filebody.jpg"; return if(-e $JPEGFileName and Utils::GetWriteDate($filename) < Utils::GetWriteDate($JPEGFileName)); my $TempPDFName = ($ChangeDir)? $TempPDFName : Utils::MakePath("$drive$directory", $TempPDFName, '/', 0); if(-e $TempPDFName) { $App->H3("Error in MyHTMLApplication::MakePDFFirstPageImage: Temp file [$TempPDFName] exists.\n"); return; } if(!Utils::CopyFile($filename, $TempCopyFile) or !-f $TempCopyFile) { $App->H3("Error in MyHTMLApplication::MakePDFFirstPageImage: Can not copy [$filename] to [$TempCopyFile]: $!\n"); return; } #$App->print("f[$filename]\n"); my $path = ($ChangeDir)? $TempCopyFile : Utils::MakePath($directory, $TempCopyFile, '/', 0); $path = "\"$path\"" if($path =~ /\s/); my $cmd = "\"$pParams->{pdftkPath}\" A=$path cat A1 output $TempPDFName"; $App->print(" Extracting 1st PDF page for [$filename] by [$cmd]\n"); if(!$App->ExecuteCommand($pParams, $cmd, $UsePipe)) { unlink($TempPDFName); unlink($TempCopyFile); return; } return if(!-e $TempPDFName); $JPEGFileName = "\"$JPEGFileName\"" if($JPEGFileName =~ /\s/); $cmd = "\"$pParams->{convertPath}\" -density $ImageFileDensity $TempPDFName $JPEGFileName"; $App->print(" Converting to JPEG image for [$filename] by [$cmd]\n"); if(!$App->ExecuteCommand($pParams, $cmd, $UsePipe)) { unlink($TempPDFName); unlink($TempCopyFile); return; } unlink($TempPDFName); unlink($TempCopyFile); } sub MakeImageLinkString { my ($App, $pParams, $src, $border, $width, %args) = @_; $border = 0 if(!defined $border); $width = (defined $width)? "width=\"$width\"" : ''; my %imageargs; my @keys = qw(width height class id); foreach my $key (@keys) { $imageargs{$key} = $args{$key} if(defined $args{$key}); } my $option = $App->BuildLinkOption(%imageargs); $option = "$width $option" if($option !~ /width\s*=/i); my $s = ""; return $s; } sub ShowImageHTML { my ($this, $pParams, $Path, $border, $width, %args) = @_; if($this == $pParams) { shift; ($this, $pParams, $Path, $border, $width, %args) = @_; } #$this->print("args ($this, $pParams, $Path, $pParams->{RootPath})\n"); $pParams->{DirPath} = Utils::URLDecode($pParams->{DirPath}) if($pParams->{DirPath} ne ''); $pParams->{Path} = Utils::URLDecode($pParams->{Path}) if($pParams->{Path} ne ''); $Path = Utils::MakePath($pParams->{DirPath}, $pParams->{Path}, '/', 0) if($Path eq ''); $pParams->{NextAction} = 'ShowImage' if($pParams->{NextAction} eq ''); $pParams->{OnlyLoadModules} = '' if($pParams->{OnlyLoadModules} eq ''); #$this->print("Path[$Path]\n"); # my $pDownloadDirs = $pParams->{pDownloadDirs}; # my $iRootDir = $pParams->{iRootDir}; #$this->print("iR[$iRootDir][$pDownloadDirs->[$iRootDir]]\n"); $Path = Utils::ReduceDirectory($Path); Jcode::convert(\$Path, $pParams->{FileSystemCharCode}); $Path = Utils::URLEncode($Path); my ($Option, $target) = $this->GetCGIParameters( { Action => $pParams->{NextAction}, Path => $Path, RootPath => $pParams->{RootPath}, Key => $pParams->{Key}, iRootDir => $pParams->{iRootDir}, NoMenu => 1, }, [qw(DBConfigName EMail Password Action NoMenu OnlyLoadModules Path RootPath Key iRootDir)], "_blank", "_blank", 0); my $ImageSrc = "$pParams->{ScriptPath}?$Option"; #$this->print("IS[$ImageSrc]\n"); my $ImageString = $this->MakeImageLinkString($pParams, $ImageSrc, $border, $width, %args); #$this->print($ImageString); $this->PrintRawHTML($ImageString); } sub ShowImage { my ($this, $pParams, $Path, $pDownloadDirsRegExp) = @_; if($this == $pParams) { shift; ($this, $pParams, $Path) = @_; } #$this->print("args ($this, $pParams, $Path)\n"); $Path = Utils::URLDecode($pParams->{Path}) if($Path eq ''); Jcode::convert(\$Path, $pParams->{FileSystemCharCode}); if(!$this->IsDownloadPermitted($pParams, $Path, $pDownloadDirsRegExp)) { $this->H2("Error in MyHTMLApplication::ShowImage: Showing [$Path] is not permitted\n"); return 0; } my %ImageType = ( jpeg => 'jpg', # tiff => 'tif', tif => 'tiff', ); my ($ext) = ($Path =~ /\.([^\\\/]+?)$/); $ext = lc $ext; #$this->print("path[$Path][$ext]\n"); my $type = ($ImageType{$ext})? $ImageType{$ext} : $ext; #Utils::InitHTML(); if(!open (IMG, $Path)) { $this->H2("Error in MyHTMLApplication::ShowImage: Can not read [$Path]: $!"); return; } binmode(IMG); print "Content-type: image/$type\n\n"; print ; close(IMG); return; } sub MakeInlineImageLinkURL { my ($App, $pParams, $path, $label, $module, %args) = @_; return $App->MakeImageLinkURL0($pParams, 'ShowImage', $path, $label, $module, %args); } sub MakeImageLinkURL { my ($App, $pParams, $path, $label, $module, %args) = @_; return $App->MakeImageLinkURL0($pParams, 'ShowImageHTML', $path, $label, $module, %args); } sub MakeImageLinkURL0 { my ($App, $pParams, $Action0, $path, $label, $module, %args) = @_; $module = '' if(!defined $module); $path =~ s/^file:\/\///i; my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($path); $label = $filename if($label eq ''); #$App->print("wd[$pParams->{WebDocumentRootDir}]\n"); my $code = Jcode::getcode($path); if($pParams->{WebDocumentRootDir} and $code eq 'ascii') { my $RegRoot = Utils::RegExpQuote($pParams->{WebDocumentRootDir}); if($path =~ s/^$RegRoot\/?/\//i) { #$App->print("wd[$pParams->{WebDocumentRoot}][$path]\n"); return ($path, $label); } } my $Action = ($module ne '')? "${module}::$Action0" : $Action0; my ($Option, $target) = $App->GetCGIParameters( { Action => $Action, Path => $path, Key => $pParams->{Key}, iRootDir => $pParams->{iRootDir}, NoMenu => 1, OnlyLoadModules => $module, #'', #'ShowImage', }, [qw(DBConfigName EMail Password Action NoMenu OnlyLoadModules Path Key iRootDir)], "_blank", "_blank", 0); my $url = "$pParams->{ScriptPath}?$Option"; return ($url, $label); } sub MakeImageLink { my ($App, $pParams, $path, $label, $module, %args) = @_; my ($url, $Label) = $App->MakeImageLinkURL($pParams, $path, $label, $module, %args); return $App->MakeImageLinkString($pParams, $url, $args{border}, $args{width}, %args); } sub MakeFileLinkURL { my ($App, $pParams, $DirPath, $FilePath, $Label, $Action, $Option, $WebCharCode, $FileSystemCharCode, %args) = @_; return '' if($DirPath eq '' and $FilePath eq ''); $Action = 'DownloadFile' if($Action eq ''); $args{AllowDirectPath} = 0 if(!defined $args{AllowDirectPath}); #$App->print("D[$DirPath] F[$FilePath]\n"); if($FileSystemCharCode ne '') { Jcode::convert(\$DirPath, $FileSystemCharCode); Jcode::convert(\$FilePath, $FileSystemCharCode); } my $RegExpWebRoot = Utils::RegExpQuote($pParams->{WebDocumentRoot}); my $fullpath = ($DirPath ne '')? Utils::MakePath($DirPath, $FilePath, '/', 0) : $FilePath; #$App->print("D[$DirPath] F[$FilePath] F[$fullpath]\n"); my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($fullpath); $directory =~ s/\\/\//g; if($FilePath eq '') { $FilePath = $filename; $DirPath = "$drive$directory"; } if($Label eq '') { $Label = $filename; # $Label = Utils::URLDecode($filename); #$App->print("l[$Label][$fullpath]\n"); } Jcode::convert(\$Label, $WebCharCode) if($WebCharCode ne ''); #$App->print("d[$DirPath][$FilePath][$fullpath]\n"); my $url; #$App->print("f[$fullpath][$RegExpWebRoot]\n"); my $code = Jcode::getcode($fullpath); if(-e $fullpath and $code eq 'ascii' and $fullpath =~ /^$RegExpWebRoot/) { $url = $fullpath; $url =~ s/^$RegExpWebRoot//i; # $url = Utils::URLEncode($url); # $url =~ s/%2f/\//g; } else { $Option = $App->BuildCGIOption({}, [qw(EMail Password DBConfigName Key iRootDir)],) if($Option eq ''); my $iRootDir; my $DirPath0 = Utils::URLEncode($DirPath); ($iRootDir, $DirPath) = $App->FindDownloadRootDir($pParams, $DirPath); #$App->print(" => $iRootDir [$DirPath][]\n"); $DirPath = Utils::URLEncode($DirPath); $FilePath = Utils::URLEncode($FilePath); if($args{AllowDirectPath}) { $url = "$pParams->{ScriptPath}?Action=$Action&Path=$FilePath&DirPath=$DirPath0&$Option"; } elsif(defined $iRootDir) { # $url = "$pParams->{ScriptPath}?Action=$Action&Path=$FilePath&iRootDir=$iRootDir&$Option"; $url = "$pParams->{ScriptPath}?Action=$Action&Path=$FilePath&iRootDir=$iRootDir&DirPath=$DirPath&$Option"; } else { $url = "$pParams->{ScriptPath}?Action=$Action&Path=$FilePath&DirPath=$DirPath&$Option"; } } #$App->print(" => [$url]\n"); return ($url, $Label); } sub MakeFileLink { my ($App, $pParams, $DirPath, $FilePath, $Label, $Action, $Option, $WebCharCode, $FileSystemCharCode, $target) = @_; $target = '_blank' if($target eq ''); my ($url, $Label) = $App->MakeFileLinkURL($pParams, $DirPath, $FilePath, $Label, $Action, $Option, $WebCharCode, $FileSystemCharCode); return "$Label"; } sub MakeDownloadLink { my ($App, $pParams, $path, $label) = @_; $path =~ s/^file:\/\///i; Jcode::convert(\$path, $pParams->{FileSystemCharCode}); my $RegExpRootDir = Utils::RegExpQuote($pParams->{WebDocumentRootDir}); if($path =~ /^$RegExpRootDir/) { if($path =~ s/^$RegExpRootDir//i) { $path = "/$path" if($path !~ /^\//); Jcode::convert(\$label, $pParams->{FileSystemCharCode}); return "$label" } } $pParams->{NextAction} = "Download" if($pParams->{NextAction} eq ''); $path = Utils::URLEncode($path); my ($Option, $target) = $App->GetCGIParameters( { Action => $pParams->{NextAction}, PrevAction => $pParams->{Action}, Path => $path, ShowParentDirectory => $pParams->{ShowParentDirectory}, ShowDirectory => $pParams->{ShowDirectory}, ShowDate => $pParams->{ShowDate}, ShowFileSize => $pParams->{ShowFileSize}, }, [qw(+Action Path SubMenuFunction UserSN IsChildFrame FrameMode ShowParentDirectory ShowDirectory ShowDate ShowFileSize Key iRootDir)], "_blank", "_blank", 0); return "{ScriptPath}?$Option\" target=\"_blank\">$label" } sub ShowFileLink { my ($App, $pParams, $FilePath, $FileName, $Label, $Action, $Option, $pre, $post, %args) = @_; $pre = '' if(!defined $pre); $post = "
" if(!defined $post); my $Additional = ''; if(-f $FilePath) { my $WriteDateString = Utils::BuildDateString(Utils::GetWriteDate($FilePath)); my ($FileSize, $unit) = Utils::GetFileSize($FilePath, 'auto', "%4.1f"); if($args{NoLogonDownloadKey}) { $App->PrintRawHTML("$pre{ScriptPath}?Action=$Action&$Option\" target=\"_self\">$Label $WriteDateString ($FileSize $unit)
\n"); my $key = $args{NoLogonDownloadKey}; my $PWOption = ''; if($key) { my $pw = $pParams->{"${key}PW"}; $PWOption = " (Password [$pw])"; } my $DLkey = $args{NoLogonDownloadKey} . 'URL'; my $DLVal = $args{$DLkey}; #$App->print("DLKey: $DLkey\n"); #$App->print("DLVal: $DLVal\n"); $App->PrintRawHTML("     {ScriptPath}?" ."Action=NoLogon::DownloadByKey&DownloadKey=$args{NoLogonDownloadKey}&$DLkey=$DLVal" ."\" target=\"_blank\">" . $App->mlText('en' => 'Download by passworded page', 'jp' => 'パスワード付ページからダウンロード') . "$PWOption$post\n"); } else { $App->PrintRawHTML("$pre{ScriptPath}?Action=$Action&$Option\" target=\"_self\">$Label" ." $WriteDateString ($FileSize $unit)$post\n"); } $App->PrintRawHTML("     File path: [$FilePath]
\n"); } } sub PrintFormHiddenParameter { my ($this, $name, $value, $type) = @_; $type = 'hidden' if(!defined $type); $value = $name if(!defined $value); $name = $value if(!defined $name); $this->PrintRawHTML(" \n"); } sub HiddenParameter { my ($App, $pParams, $VarName, $CurVal, %args) = @_; $CurVal = $VarName if(!defined $CurVal); my $option = $App->GetClassIDOption(%args); my $s = " \n"; if(!defined $args{IsPrint} or $args{IsPrint}) { $App->PrintRawHTML("$s\n"); } else { return "$s\n"; } } sub BeginForm { my ($App, $pParams, $ScriptPath, $Method, $Target, $UseUploadFile, %args) = @_; if(ref $pParams ne 'HASH') { ($App, $ScriptPath, $Method, $Target, $UseUploadFile) = @_; $pParams = $App->pParams(); } $Method = 'post' if(!defined $Method); $Target = '_self' if(!defined $Target); $UseUploadFile = 0 if(!defined $UseUploadFile); my $option = $App->GetClassIDOption(%args); if($UseUploadFile) { $App->PrintRawHTML("
\n"); } else { $App->PrintRawHTML("\n"); } } sub BeginForm_old { my ($this, $ScriptPath, $Method, $Target, $ForFileUpload) = @_; $ScriptPath = $this->pParams()->{ScriptPath} if(!defined $ScriptPath); $Method = "post" if(!defined $Method); $Target = "_self" if(!defined $Target); my $Option = ($ForFileUpload)? 'ENCTYPE="multipart/form-data"' : ''; $this->PrintRawHTML("\n"); } sub EndForm { my ($App, $pParams, $pModifiedParams, $pKeys) = @_; if(ref $pModifiedParams ne 'HASH') { shift; return $App->EndForm_old(@_); } if($pParams) { my $Option = $App->BuildCGIOption($pModifiedParams, $pKeys, 1); $App->PrintRawHTML("$Option\n"); } $App->PrintRawHTML("
\n"); } sub EndForm_old { my ($this, $pModifiedParams, $pKeys, $SubmitButtonName, $SubmitButtonValue) = @_; # $SubmitButtonName = 'submit' if(!defined $SubmitButtonName); $SubmitButtonValue = $SubmitButtonName if(!defined $SubmitButtonValue); $this->PrintRawHTML(" \n") if($SubmitButtonName); if($pModifiedParams and $pKeys) { my $HiddenStrs = $this->BuildCGIOption($pModifiedParams, $pKeys, 1); $this->PrintRawHTML($HiddenStrs); } $this->PrintRawHTML("\n"); } sub PrintFormButton { my ($this, $name, $value, $type) = @_; $type = 'submit' if(!defined $type); $value = 'submit' if(!defined $value); $name = 'submit' if(!defined $name); $this->PrintRawHTML(" \n"); } sub Button { my ($App, $pParams, $VarName, $CurVal, %args) = @_; $VarName = 'submit' if(!defined $VarName); $CurVal = $VarName if(!defined $CurVal); my $option = $App->GetClassIDOption(%args); my $s = " \n"; if(!defined $args{IsPrint} or $args{IsPrint}) { $App->PrintRawHTML("$s\n"); } else { return "$s\n"; } } #=========================== # リスト関連 #=========================== sub BeginItem { my ($this, $IsNumbered, %args) = @_; my $option = $this->GetClassIDOption(%args); if($IsNumbered) { $this->PrintRawHTML("\n"); } else { $this->PrintRawHTML("\n"); } $this->pParams()->{ItemIsNumbered} = $IsNumbered if($this->pParams()); } sub EndItem { my ($this, $IsNumbered) = @_; $IsNumbered = $this->pParams()->{ItemIsNumbered} if(!defined $IsNumbered and $this->pParams()); if($IsNumbered) { $this->PrintRawHTML("\n"); } else { $this->PrintRawHTML("\n"); } } sub PrintItem { my ($this, $str) = @_; $this->PrintRawHTML("
  • $str
  • \n"); } sub BeginItemElement { my ($this, $str) = @_; $str = '' if(!defined $str); $this->PrintRawHTML("
  • $str\n"); } sub EndItemElement { my ($this) = @_; $this->PrintRawHTML("
  • \n"); } #========================== # Table関連 #========================== sub BeginTable { my ($this, $border, $nColumns, %args) = @_; $border = 1 if(!defined $border); #$this->print("id=$args{id} / class=$args{class}\n"); my $option = $this->GetClassIDOption(%args); $this->PrintRawHTML("\n"); if($nColumns) { $this->{nColumns} = $nColumns; $this->{iColumn} = 0; } else { delete $this->{nColumns}; } } sub EndTable { my ($this) = @_; $this->PrintRawHTML("
    \n"); $this->EndRow() if($this->{nColumns}); delete $this->{nColumns}; } sub BeginTableHeader { my ($this) = @_; $this->PrintRawHTML(" \n"); } sub EndTableHeader { my ($this) = @_; $this->PrintRawHTML(" \n"); } sub BeginTableBody { my ($this) = @_; $this->PrintRawHTML(" \n"); } sub EndTableBody { my ($this) = @_; $this->PrintRawHTML(" \n"); } sub BeginTableItem { my ($this) = @_; return if($this->{nColumns} == 0); if($this->{iColumn} % $this->{nColumns} == 0) { if($this->{iColumn} > 0) { $this->EndRow(); } $this->BeginRow(); } $this->PrintRawHTML(" \n"); $this->{iColumn}++; } sub EndTableItem { my ($this) = @_; return if($this->{nColumns} == 0); $this->PrintRawHTML(" \n"); # $this->EndRow(); } sub BeginRow { my ($this) = @_; $this->PrintRawHTML(" \n"); $this->{nRow}++; } sub EndRow { my ($this) = @_; return if($this->{nRow} <= 0); $this->PrintRawHTML(" \n"); $this->{nRow}--; } sub BeginTableRow { my ($this, $pRows) = @_; $this->PrintRawHTML(" \n"); } sub EndTableRow { my ($this, $pRows) = @_; $this->PrintRawHTML(" \n"); } sub TableRow { my ($this, $pRows, $format, $idx) = @_; if($idx == 0) { $this->BeginTableHeader() if($idx == 0); $this->PrintRawHTML(" \n"); } else { $this->PrintRawHTML(" \n"); } for(my $i = 0 ; $i < @$pRows ; $i++) { my $Label = $pRows->[$i]; $this->TableCell($Label, undef, undef, undef, $format, $idx); } if($idx == 0) { $this->PrintRawHTML(" \n"); $this->EndTableHeader(); } else { $this->PrintRawHTML(" \n"); } } sub TableRowByArray { my ($this, $pArray, $pHash, $bra, $ket, $format, $idx) = @_; $idx = 1 if(!defined $idx); $bra = '{' if(!defined $bra); $ket = '}' if(!defined $ket); if($idx == 0) { $this->BeginTableHeader() if($idx == 0); $this->PrintRawHTML(" \n"); } else { $this->PrintRawHTML(" \n"); } for(my $i = 0 ; $i < @$pArray ; $i++) { my $Label = $pArray->[$i]; $this->TableCell($Label, $pHash, $bra, $ket, $format, $idx); } if($idx == 0) { $this->PrintRawHTML(" \n"); $this->EndTableHeader(); } else { $this->PrintRawHTML(" \n"); } } sub TableRowByDefinition { my ($this, $pDef, $idx, $pHash, $bra, $ket, $format) = @_; $idx = 1 if(!defined $idx); $bra = '{' if(!defined $bra); $ket = '}' if(!defined $ket); #$this->print("idx0=$idx\n"); if($idx == 0) { $this->BeginTableHeader() if($idx == 0); $this->PrintRawHTML(" \n"); } else { $this->PrintRawHTML(" \n"); } for(my $i = 0 ; $i < @$pDef ; $i++) { #$this->print("$i: idx0=$idx\n"); my $Label = $pDef->[$i]->[$idx]; $this->TableCell($Label, $pHash, $bra, $ket, $format, $idx); } if($idx == 0) { $this->PrintRawHTML(" \n"); $this->EndTableHeader(); } else { $this->PrintRawHTML(" \n"); } } sub TableHeaderCell { my ($this, $Label, $pHash, $bra, $ket, $format, $idx) = @_; $this->TableCell($Label, $pHash, $bra, $ket, $format, 0); } sub TableCell { my ($this, $Label, $pHash, $bra, $ket, $format, $idx) = @_; #$this->print("args=[$Label, $pHash, $bra, $ket, $format, $idx]\n"); $idx = (defined $idx)? $idx : 1; # $idx = (defined $idx)? 1 : 0; my $tag = ($idx == 0)? 'th' : 'td'; #$this->print("tag: $tag: idx=$idx\n"); my $T = new Template; my $align; my ($label, $option) = ($Label =~ /^(.*)::([\w\s\d=\"]+?)$/); $Label = $label if(defined $label); #if($label ne ''); return if(lc $option eq 'none'); #$this->print("Opt: $option [$label] [$Label]\n"); my $OptionStr = ($option =~ /nowrap/i)? ' nowrap' : ''; $OptionStr = " $1" if($option =~ /(colspan.*)$/i); #$this->print("Opt: $OptionStr\n"); if($Label =~ /^(==>|<=>)(.*)$/) { $align = "right" if($1 eq '==>'); $align = "center" if($1 eq '<=>'); $Label = $2; } $Label = $T->ReplaceByHash($Label, $pHash, $bra, $ket) if($pHash); if($format ne '') { my $s = $Label; $Label = $format; $Label =~ s/{text}/$s/g; } if($align ne '') { $this->PrintRawHTML(" <$tag align='$align'$OptionStr>$Label\n"); } else { $this->PrintRawHTML(" <$tag$OptionStr>$Label\n"); } } #========================== # Checkbox/Radiobutton #========================== sub PrintRadioItem { my ($this, $FormName, $Value, $Label, $Checked) = @_; $Checked = ($Checked)? " checked" : ''; $Value = 'ON' if($Value eq ''); $this->PrintRawHTML(" $Label"); } sub Checkbox { my ($App, $VarName, $CurVal, $label, $charcode, %args) = @_; my $s = $App->BuildCheckboxString($VarName, $CurVal, $label, $charcode, %args); if(!defined $args{IsPrint} or $args{IsPrint}) { $App->PrintRawHTML("$s\n"); } else { return "$s\n"; } } sub BuildCheckboxString { my ($App, $VarName, $CurVal, $label, $charcode, %args) = @_; $charcode = $App->PrintCharCode() if(!defined $charcode); Jcode::convert(\$label, $charcode); $CurVal = $App->OnOffToNum($CurVal); my $option = $App->GetClassIDOption(%args); my $checked = ($CurVal)? ' checked' : ''; return "$label"; } sub GetCheckboxListString { my ($this, $pParams, $pArray, $Key) = @_; my $lang = $pParams->{Language}; for(my $i = 0 ; $i < @$pArray ; $i += 3) { if($Key eq $pArray->[$i]) { return $pArray->[$i+1]{$lang}; } } return $Key; } sub GetCheckboxListFormString { my ($this, $pParams, $pArray, $CurVal, $pre, $post, %args) = @_; $pre = '' if(!defined $pre); $post = '
    ' if(!defined $post); my $lang = $pParams->{Language}; my $option = $this->GetClassIDOption(%args); my $s = ''; for(my $i = 0 ; $i < @$pArray ; $i += 3) { my $key = $pArray->[$i]; my $phash = $pArray->[$i+1]; my $DefVal = $pArray->[$i+2]; my $v = $pParams->{$key}; # my $v = (defined $pParams->{$key})? $pParams->{$key} : $DefVal; my $Checked = ($v eq 'ON')? ' checked' : ''; my $val = $pParams->{$key}; #print("GetCheckboxListFormString: $key=$val: check=[$Checked]
    \n"); $s .= "$pre$phash->{$lang}$post\n"; } return $s; } #sub GetCheckboxListFormString #{ # my ($this, $pParams, $pArray, $CurVal) = @_; # my $lang = $pParams->{Language}; # my $s = ''; # for(my $i = 0 ; $i < @$pArray ; $i += 3) { # my $key = $pArray->[$i]; # my $phash = $pArray->[$i+1]; # my $DefVal = $pArray->[$i+2]; # my $v = $pParams->{$key}; ## my $v = (defined $pParams->{$key})? $pParams->{$key} : $DefVal; # my $Checked = ($v eq 'ON')? ' checked' : ''; # my $val = $pParams->{$key}; ##print("GetCheckboxListFormString: $key=$val: check=[$Checked]
    \n"); # $s .= "$phash->{$lang}
    \n"; # } # return $s; #} #sub GetCheckboxListString { # my ($this, $pParams, $pArray, $Key) = @_; # my $lang = $pParams->{Language}; # for(my $i = 0 ; $i < @$pArray ; $i += 3) { # if($Key eq $pArray->[$i]) { # return $pArray->[$i+1]{$lang}; # } # } # return $Key; #} sub PrintCheckbox { my ($this, $FormName, $Value, $Label, $Checked) = @_; $Checked = ($Checked)? " checked" : ''; $Value = 'ON' if($Value eq ''); $this->PrintRawHTML(" $Label"); } sub FillCheckboxParams { my ($this, $pParams, $pArray, $value) = @_; for(my $i = 0 ; $i < @$pArray ; $i += 3) { my $key = $pArray->[$i]; my $phash = $pArray->[$i+1]; my $DefVal = $pArray->[$i+2]; my $v = $pParams->{$key}; if(!defined $pParams->{$key}) { if(defined $value) { $pParams->{$key} = $value } else { $pParams->{$key} = $DefVal } } } } #========================== # Text関連 #========================== sub TextArea { my ($App, $pParams, $VarName, $CurVal, $rows, $cols, %args) = @_; my $option = $App->GetClassIDOption(%args); $option .= ' readonly' if($args{readonly}); $option .= " style=\"$args{style}\"" if($args{style}); my $s = " \n"; if(!defined $args{IsPrint} or $args{IsPrint}) { $App->PrintRawHTML("$s\n"); } else { return "$s\n"; } } sub Textbox { my ($App, $VarName, $Width, $CurVal, $label, $charcode, %args) = @_; my $s = $App->BuildTextboxString($VarName, $Width, $CurVal, $charcode, %args); $s = "$label$s" if($label ne ''); if(!defined $args{IsPrint} or $args{IsPrint}) { $App->PrintRawHTML("$s\n"); } else { return "$s\n"; } } sub BuildTextboxString { my ($App, $VarName, $Width, $CurVal, $charcode, %args) = @_; $charcode = $App->PrintCharCode() if(!defined $charcode); $Width = 30 if(!defined $Width); my $option = $App->GetClassIDOption(%args); $option .= ' readonly' if($args{readonly}); $option .= " style=\"$args{style}\"" if($args{style}); Jcode::convert(\$CurVal, $charcode); return ""; } sub FileSubmitbox { my ($App, $VarName, $Width, $CurVal, $label, $charcode, %args) = @_; my $s = $App->BuildFileSubmitboxString($VarName, $Width, $CurVal, $charcode, %args); $s = "$label$s" if($label ne ''); if(!defined $args{IsPrint} or $args{IsPrint}) { $App->PrintRawHTML("$s\n"); } else { return "$s\n"; } } sub BuildFileSubmitboxString { my ($App, $VarName, $Width, $CurVal, $charcode, %args) = @_; $charcode = $App->PrintCharCode() if(!defined $charcode); $Width = 30 if(!defined $Width); my $option = $App->GetClassIDOption(%args); $option .= ' readonly' if($args{readonly}); $option .= " style=\"$args{style}\"" if($args{style}); Jcode::convert(\$CurVal, $charcode); return ""; } sub PasswordTextbox { my ($App, $VarName, $Width, $CurVal, $label, $charcode, %args) = @_; my $s = $App->BuildPasswordTextboxString($VarName, $Width, $CurVal, $charcode, %args); $s = "$label$s" if($label ne ''); if(!defined $args{IsPrint} or $args{IsPrint}) { $App->PrintRawHTML("$s\n"); } else { return "$s\n"; } } sub BuildPasswordTextboxString { my ($App, $VarName, $Width, $CurVal, $charcode, %args) = @_; $charcode = $App->PrintCharCode() if(!defined $charcode); $Width = 30 if(!defined $Width); my $option = $App->GetClassIDOption(%args); $option .= ' readonly' if($args{readonly}); $option .= " style=\"$args{style}\"" if($args{style}); Jcode::convert(\$CurVal, $charcode); return ""; } #========================================== # option form文字列の作成 #========================================== my @GenderSelection = ( "NotSelected" => {'en' => "Choose if don't mind", 'jp' => "差し支えなければ選択してください"}, "Male" => {'en' => "Male", 'jp' => "男性"}, "Female" => {'en' => "Female", 'jp' => "女性"}, ); sub GetGenderSelectionFormString { my ($App, $pParams, $FormName, $curval, %args) = @_; $FormName = "Gender" if(!defined $FormName); return $App->GetSelectionFormString($pParams, $FormName, $curval, \@GenderSelection, undef, undef, %args); } sub GenderString { my ($App, $pParams, $sel, $code) = @_; my $s = $App->GetStringByArray($pParams, $sel, \@GenderSelection, ''); Jcode::convert(\$s, $code, $SourceCharCode) if($code ne ''); return $s; } sub GetnLanguage { my ($App) = @_; my $pParams = $App->{pParams}; my $lang = $App->Language(); my $pLanguageList = $pParams->{pLanguageList}; my $plist = $pLanguageList->{$lang}; #$App->print("pl: ", join(',', @$plist), "\n"); return int(@$plist / 2); } sub GetLanguageString { my ($App, $lang) = @_; my $pParams = $App->{pParams}; $lang = $App->Language() if($lang eq ''); my $pLanguageList = $pParams->{pLanguageList}; my $plist = $pLanguageList->{$lang}; for(my $i = 0 ; $i < @$plist ; $i += 2) { my $code = $plist->[$i]; my $name = $plist->[$i+1]; return $name if($code eq $lang); } return $lang; } sub GetLanguageSelectFormString { my ($App, %args) = @_; my $pParams = $App->{pParams}; my $lang = $App->Language(); my $pLanguageList = $pParams->{pLanguageList}; my $plist = $pLanguageList->{$lang}; my $option = $App->GetClassIDOption(%args); foreach my $key (keys %args) { next if($key =~ /^(id|class)$/i); $option .= " $key=\"$args{$key}\""; } my $str = "\n"; if($lang eq 'jp') { Jcode::convert(\$str, $pParams->{WebCharCode}, $pParams->{ScriptCharCode}); } return $str; } sub GetLanguageSubMenuItemsString { my ($App, $BaseOption, %args) = @_; #$App->print("B[$BaseOption]\n"); my $pParams = $App->{pParams}; my $lang = $App->Language(); my $pLanguageList = $pParams->{pLanguageList}; my $plist = $pLanguageList->{$lang}; my $str = ''; for(my $i = 0 ; $i < @$plist ; $i += 2) { my $code = $plist->[$i]; my $name = $plist->[$i+1]; #$App->print("$i: $code: $name\n"); my $sel = ($lang eq $code)? ' selected' : ''; $str .= "
  • $name
  • \n"; #$App->print("$i: $code: $name [$str]\n"); } if($lang eq 'jp') { Jcode::convert(\$str, $pParams->{WebCharCode}, $pParams->{ScriptCharCode}); } return $str; # return "
  • dummy
  • \n" . $str; } sub YesNoByLanguage { my ($App, $g) = @_; return $g if($App->Language() eq 'en'); return "はい" if($g =~ /Ye/i); return "いいえ" if($g =~ /No/i); return "選択されていません"; } sub GenderByLanguage { my ($App, $g) = @_; return $g if($App->Language() eq 'en'); return "女性" if($g =~ /female/i); return "男性" if($g =~ /male/i); return "選択されていません"; } sub GetSelectionListStringByArray { my ($this, $pParams, $pArray, $Key) = @_; return '' if($Key eq ''); for(my $i = 0 ; $i < @$pArray ; $i++) { if($Key eq $pArray->[$i]) { return $pArray->[$1]; } } return $Key; } sub GetSelectionListFormStringByArray { my ($this, $pParams, $pArray, $FormName, $CurVal, $pAdditionalSelections) = @_; $CurVal = $pParams->{$FormName} if(!defined $CurVal); my $str = "\n"; return $str; } sub GetFileSelectFormString { my ($App, $pParams, $dir, $fmask, $FormName, $CurVal, $pAdditionalSelections, %args) = @_; my $path = Utils::MakePath($dir, $fmask, '/', 0); my @f = sort glob($path); my @sel; for(my $i = 0 ; $i < @f ; $i++) { my $f = $f[$i]; next if(-d $f); my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($f); #$App->print("$i: $filename\n"); push(@sel, Utils::URLEncode($filename)); push(@sel, $filename); } my $s = $App->GetSelectionListFormStringBySimpleArray($pParams, \@sel, $FormName, Utils::URLEncode($CurVal), $pAdditionalSelections, %args); return $s; } sub GetSelectionListString { my ($this, $pParams, $pArray, $Key) = @_; return '' if($Key eq ''); my $lang = $pParams->{Language}; for(my $i = 0 ; $i < @$pArray ; $i += 2) { #$this->H3("$i: key: $Key (Array[$i] = $pArray->[$i]\n"); if($Key eq $pArray->[$i]) { return $pArray->[$i+1]->{$lang}; } } return $Key; } sub GetSelectionListFormStringBySimpleArray { my ($App, $pParams, $pArray, $FormName, $CurVal, $pAdditionalSelections, %args) = @_; #$App->print("A: $pArray v=$CurVal f=$FormName\n"); my $lang = $pParams->{Language}; $lang = $App->Language() if(!defined $lang); $CurVal = $pParams->{$FormName} if(!defined $CurVal); my $opt = ''; $opt .= " onChange=\"$args{onChange}\"" if($args{onChange}); my $str = "\n"; if($lang eq 'jp') { Jcode::convert(\$str, $pParams->{WebCharCode}, $pParams->{ScriptCharCode}); } return $str; } sub GetSelectionListFormString { my ($App, $pParams, $pArray, $FormName, $CurVal, $pAdditionalSelections, %args) = @_; #$App->print("A: $pArray v=$CurVal f=$FormName\n"); #$App->print("args[", join(',', %args), "]\n"); my $lang = $pParams->{Language}; $lang = $App->Language() if(!defined $lang); $CurVal = $pParams->{$FormName} if(!defined $CurVal); my $opt = ''; $opt .= " onChange=\"$args{onChange}\"" if($args{onChange}); $opt .= " id=\"$args{id}\"" if($args{id}); $opt .= " id=\"$args{class}\"" if($args{class}); my $str = "\n"; if($lang eq 'jp') { Jcode::convert(\$str, $pParams->{WebCharCode}, $pParams->{ScriptCharCode}); } return $str; } #sub GetSelectionFormString_old { sub GetSelectionFormString { my ($App, $pParams, $FormName, $curval, $pSelection, $pPre, $pPost, %args) = @_; $pPre = {} if(!defined $pPre); $pPost = {} if(!defined $pPost); my $lang = $App->Language(); $curval = $pParams->{$FormName} if(!defined $curval); my $option = $App->GetClassIDOption(%args); my $str = "\n"; if($lang eq 'jp' and $pParams->{WebCharCode} ne '' and $pParams->{ScriptCharCode} ne '') { Jcode::convert(\$str, $pParams->{WebCharCode}, $pParams->{ScriptCharCode}); } return $pPre->{$lang} . $str . $pPost->{$lang}; } sub GetStringByArray { my ($App, $pParams, $sel, $pSelection, $default) = @_; my $lang = $App->Language(); for(my $i = 0 ; $i < @$pSelection ; $i += 2) { if($pSelection->[$i] eq $sel) { return $pSelection->[$i+1]->{$lang}; } } return $default; } sub BuildDropdownListboxString { my ($App, $FormName, $CurVal, $pSel, $charcode, $lang, %args) = @_; $charcode = $App->PrintCharCode() if(!defined $charcode); $lang = $App->Language() if(!defined $lang); my $option = $App->GetClassIDOption(%args); my $s = ''; my $Selected = 0; if(@$pSel > 0) { if($charcode) { Jcode::convert(\$CurVal, $charcode); } $s = "\n"; #print("s: [$s]
    \n"); return $s; } sub BuildDropdownListboxStringByArray { my ($App, $FormName, $CurVal, $pSel, $charcode, $lang, %args) = @_; $charcode = $App->PrintCharCode() if(!defined $charcode); $lang = $App->Language() if(!defined $lang); my $s = ''; if(@$pSel > 0) { if($charcode) { # Jcode::convert(\$FormName, $charcode); Jcode::convert(\$CurVal, $charcode); } my $option = $App->GetClassIDOption(%args); $s = "\n"; return $s; } sub BuildFormSelectString0 { my ($App, $FormName, $CurVal, $PreMessage, $PostMessage, $pSel, $charcode, %args) = @_; $charcode = $App->PrintCharCode() if(!defined $charcode); Jcode::convert(\$PreMessage, $charcode); Jcode::convert(\$PostMessage, $charcode); my $s = ''; if(@$pSel > 0) { if($charcode) { Jcode::convert(\$FormName, $charcode); Jcode::convert(\$CurVal, $charcode); Jcode::convert(\$PreMessage, $charcode); Jcode::convert(\$PostMessage, $charcode); for(my $i = 0 ; $i < @$pSel ; $i++) { my $s = $pSel->[$i]; Jcode::convert(\$s, $charcode); $pSel->[$i] = $s; #$App->print("sel $i: $s\n"); } } my $option = $App->GetClassIDOption(%args); $s = "

    \n" . "$PreMessage \n" . " \n" . $PostMessage . "

    \n"; } #print "nP: ", scalar @ASPreferenceSelection, "
    \n"; #print "strPreferenceSelection: $strPreferenceSelection
    \n"; return $s; } sub BuildFormSelectString { my ($App, $FormName, $CurVal, $PreMessage, $PostMessage, $pSel, $charcode, %args) = @_; $charcode = $App->PrintCharCode() if(!defined $charcode); Jcode::convert(\$PreMessage, $charcode); Jcode::convert(\$PostMessage, $charcode); my $s = ''; return '' if(@$pSel <= 0); if($charcode) { Jcode::convert(\$FormName, $charcode); Jcode::convert(\$CurVal, $charcode); Jcode::convert(\$PreMessage, $charcode); Jcode::convert(\$PostMessage, $charcode); for(my $i = 0 ; $i < @$pSel ; $i++) { my $s = $pSel->[$i]; Jcode::convert(\$s, $charcode); $pSel->[$i] = $s; #$App->print("sel $i: $s\n"); } } my $option = $App->GetClassIDOption(%args); $s = "$PreMessage \n" . " \n" . $PostMessage . "\n"; #print "nP: ", scalar @ASPreferenceSelection, "
    \n"; #print "strPreferenceSelection: $strPreferenceSelection
    \n"; return $s; } sub BuildFormSelectString2 { my ($App, $FormName, $CurVal, $PreMessage, $PostMessage, $pSel1, $pSel2, $charcode, %args) = @_; my @List; for(my $i = 0 ; $i < @$pSel1 ; $i++) { $List[$i * 2] = $pSel1->[$i]; $List[$i * 2 + 1] = $pSel2->[$i]; } return $App->BuildFormSelectString($FormName, $CurVal, $PreMessage, $PostMessage, \@List, $charcode, %args); } #========================================== # Print関連 #========================================== sub BeginMenu { my ($this, $IDName) = @_; $IDName = 'MainMenu' if(!defined $IDName); return if($IDName eq ''); if($IDName =~ /=/) { $this->PrintRawHTML("\n"); } else { $this->PrintRawHTML("\n"); } } sub EndMenu { my ($this, $classname) = @_; $this->PrintRawHTML("\n"); } sub BeginDiv { my ($this, $IDName) = @_; if($IDName eq '') { $this->PrintRawHTML("
    \n"); } elsif($IDName =~ /=/) { $this->PrintRawHTML("
    \n"); } else { $this->PrintRawHTML("
    \n"); } } sub EndDiv { my ($this, $classname) = @_; $this->PrintRawHTML("
    \n"); } sub BeginSpan { my ($this, $IDName) = @_; if($IDName eq '') { $this->PrintRawHTML("\n"); } elsif($IDName =~ /=/) { $this->PrintRawHTML("\n"); } else { $this->PrintRawHTML("\n"); } } sub EndSpan { my ($this, $classname) = @_; $this->PrintRawHTML("\n"); } #========================================== # ファイル関係 #========================================== sub UploadFile { my ($App, $pParams, $form, %args) = @_; if(ref $pParams ne 'HASH') { ($App, $form, %args) = @_; $pParams = $App->pParams(); } $form = $App->Args()->CGIForm() if(!defined $form); #print "f[$form]
    \n"; my $FileFieldName = $args{FileFieldName}; $FileFieldName = 'UploadFilePath' if(!defined $FileFieldName); $args{PrintLevel} = 1 if(!defined $args{PrintLevel}); my $fH = $form->upload($FileFieldName); #$App->print("form=$form\n"); #$App->print("fH=[$fH]\n"); #$App->print("path=$pParams->{$FileFieldName}\n"); if(!$fH) { $App->H3("Error in MyHTMLApplication::UploadFile: Can not get handle from the field [$FileFieldName].\n"); return ('', "Cannot get handle"); } # my $UploadFilePath = $args{UploadFilePath}; my $UploadFileMaxSize = $args{UploadFileMaxSize}; my $ServerFileName = $args{ServerFileName}; my $ServerFilePath = $args{ServerFilePath}; my $pTypeOkList = $args{pTypeOkList}; my $pExtOkList = $args{pExtOkList}; my @type_ok = @$pTypeOkList; my @ext_ok = @$pExtOkList; my $max = sprintf("%3.1f", $UploadFileMaxSize / 1024 / 1024); #$App->print("ServerFilePath: $args{ServerFilePath}\n"); if($form->cgi_error) { if($args{PrintLevel}) { $App->mlPrintRawHTML('en' => "

    CGI Form Error: $1

    \n", 'jp' => "

    CGI Form Error: $1

    \n"); } return ('', "CGIFormError:$form->cgi_error"); } if(!defined $fH) { if($args{PrintLevel}) { $App->mlPrintRawHTML('en' => "

    File transfer error.

    \n", 'jp' => "

    ファイルを転送できませんでした。

    \n"); my $exts = join(', ', @ext_ok); $App->mlPrintRawHTML('en' => "

    File extention must be $exts, and the file size must be smaller than $max MB.

    \n", 'jp' => "

    拡張子が$exts以外のファイルや、$max MB より大きいファイルは登録できません

    \n"); } return ('', "TransferError:$max"); } my $inf = $form->uploadInfo($fH); #$App->print("inf=[$inf]\n"); if(!defined $inf) { if($args{PrintLevel}) { $App->mlPrintRawHTML('en' => "

    Can not get Upload Information.

    \n", 'jp' => "

    Can not get Upload Information

    \n"); } return ('', 'CantGetUploadInfo'); } my $mimetype = $inf->{'Content-Type'}; my $size = (stat($fH))[7]; # サイズ制限 if($size > $UploadFileMaxSize) { my $sizestr = Utils::SeparateStringBy($size, ',', 3); if($args{PrintLevel}) { $App->mlPrintRawHTML('en' => "

    The filesize [$sizestr Bytes] is too large [Max: $max MB]

    \n", 'jp' => "

    ファイルサイズ [$sizestr Bytes] が制限 [$max MB] を超えています

    \n"); } return ('', "TooLarge:$sizestr,$max"); } # my $ClientFilePath = $UploadFilePath; my $ClientFilePath = $ServerFilePath; if($ClientFilePath eq '') { if($args{PrintLevel}) { $App->print("Local file name is not obtained [$1].\n"); } return ('', "CantGetLocalFileName:$ClientFilePath"); } # my $parsename = $ClientFilePath; Utils::ConvertDirectorySeparator($ClientFilePath, '\\', '/', 0); my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($ClientFilePath); #$App->print("ClientFilePath: $ClientFilePath"); #$App->print("DirPath: $pParams->{DirPath}\n"); #$App->print("Server File: $ServerFilePath\n"); #$App->print("type: $mimetype\n"); #ファイルタイプのチェック my $ok = 0; if(@type_ok == 0) { $ok = 1; } else { $ok = 0; #フラグのリセット foreach my $pattern (@type_ok){ if($mimetype =~ /^$pattern$/i) { $ok = 1; last; } } } unless ($ok){ #ファイルタイプ、拡張子のチェックがNGの場合 if($args{PrintLevel}) { my $exts = join(', ', @ext_ok); $exts = '*' if($exts eq ''); $App->mlPrintRawHTML('en' => "

    Error: Invalid File Type: The file type must be any of $exts. (type: $ext mime:$mimetype)

    \n", 'jp' => "

    Error: 不明な型のファイルです。ファイルは $exts のいずれかでないといけません。 (type: $ext mime:$mimetype)

    \n"); } return ('', "InvalidFileType:$ext,$mimetype"); } #ファイルタイプでNGになった場合 $ok = 0; #拡張子のチェック if(@ext_ok == 0) { $ok = 1; } foreach my $pattern (@ext_ok) { if($ext =~ /^\.$pattern$/i) { $ok = 1; last; } } unless ($ok){ #ファイルタイプ、拡張子のチェックがNGの場合 if($args{PrintLevel}) { my $exts = join(', ', @ext_ok); $exts = '*' if($exts eq ''); $App->mlPrintRawHTML('en' => "

    Error: Invalid File Type: The file type must be any of $exts. (type: $ext mime:$mimetype)

    \n", 'jp' => "

    Error: 不明な型のファイルです。ファイルは $exts のいずれかでないといけません。 (type: $ext mime:$mimetype)

    \n"); } return ('', "InvalidFileType:$ext,$mimetype"); } #ファイルの保存 unless(open (OUTFILE, ">$ServerFilePath")) { if($args{PrintLevel}) { $App->print("Could not write to [$ServerFilePath].\n"); } return ('', "Error in ConfApp3::UploadFile: SaveError: $ServerFilePath"); } binmode($ClientFilePath); binmode(OUTFILE); my $buffer; while(read($fH, $buffer, 1024)) { print OUTFILE $buffer; } if(close(OUTFILE)) { # $App->H3("$ClientFilePath is saved as $ServerFilePath"); } else { if($args{PrintLevel}) { $App->print("Could not close the file [$ServerFilePath].\n"); } return ('', "CloseFileError:$ServerFilePath"); } return ($ServerFilePath, "OK"); } sub UploadFile_old { my ($App, $form, %args) = @_; #$App->print("F: [$args{FileFieldName}]\n"); if($args{$args{FileFieldName}} eq '') { return ('', "FileNameError: File name not specified"); } my $fH = $form->upload($args{FileFieldName}); if($form->cgi_error) { my $err = $form->cgi_error; $App->print("Error: $err\n") if ($err); return ('', $err); } my $max = sprintf("%3.1f", $args{UploadFileMaxSize} / 1024 / 1024); if(!defined $fH) { return ('', "TransferError:$max"); } my $inf = $form->uploadInfo($fH); return ('', '') if(!defined $inf); my $mimetype = $inf->{'Content-Type'}; my $size = (stat($fH))[7]; # サイズ制限 #$App->print("($size > $args{UploadFileMaxSize})\n"); if($size > $args{UploadFileMaxSize}) { my $sizestr = Utils::SeparateStringBy($size, ',', 3); return ('', "TooLarge:$sizestr,$max"); } my $ClientFilePath = $args{UploadFilePath}; #$App->Args()->GetGetArg($args{FileFieldName}); if($ClientFilePath eq '') { return ('', 'CantGetLocalFileName'); } my $parsename = $ClientFilePath; Utils::ConvertDirectorySeparator($parsename, '\\', '/', 0); my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($parsename); my $ServerFileName = $args{ServerFileName}; my $ServerFile = $args{ServerFilePath}; if($args{FileSystemCharCode} ne '') { Jcode::convert(\$ServerFileName, $args{FileSystemCharCode}); Jcode::convert(\$ServerFile, $args{FileSystemCharCode}); } # $App->HR(); # $App->H3("ClientFilePath: $ClientFilePath"); # $App->print("DirPath: $pParams->{DirPath}\n"); # $App->print("Server File: $ServerFile\n"); # $App->print("type: $mimetype\n"); #ファイルタイプのチェック my $ok = 0; $ok = 0; #フラグのリセット my $p = $args{pTypeOkList}; if(@$p == 0) { $ok = 1; } else { foreach my $pattern (@$p){ if($mimetype =~ /^$pattern$/i) { $ok = 1; last; } } } #$App->print("ok=$ok\n"); unless ($ok){ #ファイルタイプ、拡張子のチェックがNGの場合 my $error = "File type ($mimetype) is not allowed for upload."; return ('', "InvalidFileType:$error"); } #ファイルタイプでNGになった場合 unless ($ok){ #拡張子のチェック my $p = $args{pExtOkList}; if(@$p == 0) { $ok = 1; } else { foreach my $pattern (@$p){ if($ext =~ /^\.$pattern$/i) { $ok = 1; last; } } } } #$App->print("ok=$ok\n"); unless ($ok){ #ファイルタイプ、拡張子のチェックがNGの場合 my $error = "File extension($ext) is not allowed for upload."; return ('', "InvalidFileType:$error"); } if($args{CreateUniqueFileName} and -e $ServerFile) { my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($ServerFile); $directory =~ s/\\/\//g; my $base = Utils::MakePath("$drive$directory", $filebody, '/', 0); #$App->print("b: $base [$drive][$directory]\n"); my $i; for($i = 1 ; $i < 1000 ; $i++) { my $f = "${base}_$i$ext"; if(!-e $f) { $ServerFile = $f; last; } } if($i >= 1000) { print "Can not find unique filename
    \n"; return ('', 'UniqueFileNameError'); } } #ファイルの保存 unless (open (OUTFILE,">$ServerFile")) { print "Can not open $ServerFile: $!
    \n"; return ('', 'SaveError'); } binmode($ClientFilePath); binmode(OUTFILE); my $buffer; while(read($fH, $buffer, 1024)) { print OUTFILE $buffer; } if(close(OUTFILE)) { # $App->H3("$ClientFilePath is saved as $ServerFile"); } else { return ('', 'CloseFileError'); } return ($ServerFile, ''); } sub ConvertAllowedDirArrayToRegExp { my ($App, $pArray) = @_; my @a; for(my $i = 0 ; $i < @$pArray ; $i++) { $a[$i] = "^$pArray->[$i](/[^_].*)?\$"; } return @a; } sub FindDownloadRootDir { my ($App, $pParams, $DirPath, $pDownloadDirsRegExp) = @_; $pDownloadDirsRegExp = $pParams->{pDownloadDirsRegExp} if($pDownloadDirsRegExp eq ''); return (undef, $DirPath) if($pDownloadDirsRegExp eq ''); for(my $i = 0 ; $i < @$pDownloadDirsRegExp ; $i++) { my $pd = $pDownloadDirsRegExp->[$i]; $pd =~ s/\\/\//g; #$App->print("$i [$DirPath][$pd]\n"); if($DirPath =~ /^$pd/i) { $DirPath =~ s/^$pd//; $DirPath =~ s/^\///; #$App->print("$i [$DirPath][$pd]\n"); return ($i, $DirPath); } } return (undef, $DirPath); } sub IsDownloadPermitted { my ($App, $pParams, $Path, $pDownloadDirsRegExp) = @_; $pDownloadDirsRegExp = $pParams->{pDownloadDirsRegExp} if($pDownloadDirsRegExp eq ''); if(!$pDownloadDirsRegExp and $pParams->{pDownloadDirs}) { my @DownloadDirsRegExp = $App->ConvertAllowedDirArrayToRegExp(@{$pParams->{pDownloadDirs}}); $pDownloadDirsRegExp = $pParams->{pDownloadDirsRegExp} = \@DownloadDirsRegExp; } #$App->print("Reg[", join("
    \n", @$pDownloadDirsRegExp), "]\n"); return 0 if($pDownloadDirsRegExp eq ''); my $IsPermitted = 0; for(my $i = 0 ; $i < @$pDownloadDirsRegExp ; $i++) { my $pd = $pDownloadDirsRegExp->[$i]; #$App->print("$i [$pd][$Path]\n"); $pd =~ s/\\/\//g; if($Path =~ /$pd/i) { $IsPermitted = 1; last; } } return 0 if(!$IsPermitted); my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($Path); if(-d $Path) { $lastdir = $filename; $directory = $Path; $filename = $filebody = $ext = ''; } return 1; } sub DownloadBuffer { my ($App, $pParams, $Contents, $DownloadFileName) = @_; my $Args = $App->Args(); my $form = $Args->CGIForm(); Utils::DownloadBuffer($form, $Contents, $DownloadFileName, $App); } sub DownloadFile { my ($App, $LocalPath, $DownloadFileName, $Contents, $pDownloadDirsRegExp) = @_; my $pParams = $App->pParams(); #$App->print("ref: ", $App, " l[$LocalPath] Path[$pParams->{Path}]\n"); if($LocalPath =~ /=HASH\(/) { # if(ref $LocalPath eq 'HASH') { my $a; ($a, $App, $pParams) = @_; #$App->print("ref: ", $App, " Path[$pParams->{Path}]\n"); $LocalPath = ($pParams->{Path} =~ /%/)? Utils::URLDecode($pParams->{Path}) : $pParams->{Path}; $DownloadFileName = ''; $Contents = ''; #$App->print("ref: ", $App, " l[$LocalPath] Path[$pParams->{Path}]\n"); #$App->print("P[$LocalPath]\n"); } if(!-e $LocalPath) { if($pParams->{iRootDir} eq '' and $pParams->{DirPath} ne '') { $LocalPath = Utils::MakePath($pParams->{DirPath}, $LocalPath, '/', 0); } elsif(!-e $LocalPath and $pParams->{pDownloadDirs} and $pParams->{iRootDir} ne '') { my $i = $pParams->{iRootDir}; my $dir = $pParams->{pDownloadDirs}->[$i]; $LocalPath = Utils::MakePath($dir, [$pParams->{DirPath}, $LocalPath], '/', 0); } } #$App->print("Download:[$LocalPath][$pParams->{DirPath}]\n"); return -1 if(!-e $LocalPath); #$LocalPath = 'a' . $LocalPath; if(!$App->IsDownloadPermitted($pParams, $LocalPath, $pDownloadDirsRegExp)) { $App->H2("Error in MyHTMLApplication::DownloadFile: [$LocalPath] is not permitted for download\n"); return 0; } if($DownloadFileName eq '') { my ($drive, $directory, $filename, $ext, $lastdir, $filebody) = Deps::SplitFilePath($LocalPath); $DownloadFileName = $filename; } my $Args = $App->Args(); my $form = $Args->CGIForm(); $App->convert(\$DownloadFileName, 'sjis'); Utils::DownloadFile($form, $LocalPath, $DownloadFileName, $App); return; #$DownloadFileName はアスキー文字で構成されている必要がある。 #日本語が含まれているとうまくいかない可能性が高い my $in = new JFile(); # my $Contents; if($LocalPath ne '' and $LocalPath ne '-') { $Contents = $in->ReadFile($LocalPath, undef, "rb"); if(!defined $Contents) { $App->H2("Error: Can not read [$LocalPath]"); return; } } #$App->print("c: [$Contents]\n"); #my $code = Jcode::getcode($DownloadFileName); #$App->print("code: $code\n"); # $DownloadFileName = Utils::URLEncode($DownloadFileName); my $Length = length $Contents; #$App->print("f: $LocalPath [$Length] bytes\n"); #print "
    length: $Length
    "; #ファイル用のヘッダを書き出し #ブラウザのバージョンや設定によって、期待した動作とならない場合もある print ( $form->header( -Content_Disposition => "attachment; filename=$DownloadFileName", -Content_Length => $Length, -type => "application/octet-stream", ) ); #$DownloadFileName = "a.pdf"; # print "HTTP/1.1 200 OK\n"; # print "Date: Wed, 13 Apr 2005 03:09:44 GMT\n"; # print "Server: Apache/1.3.29 (Unix) PHP/4.2.4-dev mod_ssl/2.8.16 OpenSSL/0.9.7d\n"; # print "Content-length: $Length\n"; # print "Content-disposition: attachment; filename=\"$DownloadFileName\"\n"; ## print "Content-Type: application/octet-stream\n"; # print "Content-Type: application/download; name=\"$DownloadFileName\"\n"; # print "\n"; print($Contents) if($Contents); return 1; } 1;