package PerlDynamic; use strict; #use warnings; use Carp; use FileHandle; use lib "."; use Querier qw($col_delim); #-----------------------------------------------# # INITIAL SETUP # #-----------------------------------------------# BEGIN { use Exporter(); our($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); $VERSION = sprintf "%d.%03d", q$Revision: 1.14 $ =~ /(\d+)/g; @ISA = qw(Exporter); @EXPORT = qw($session $ppages $linkpages $outlinePasteboard); %EXPORT_TAGS = (); # your exported package globals go here, # as well as any optionally exported functions @EXPORT_OK = qw( $row $value $pdq_status $datatype $rownum @fieldnames $queryname $nopdq $outlinePasteboard ); } our @EXPORT_OK; our $session; our $ppages; our $linkpages; our $outlinePasteboard; our ($row, $value, $pdq_status, $datatype, $rownum, @fieldnames, $queryname, $nopdq); #---------------------------------------------------------------------------# # Source html documents are parsed by this script. Where the special tag # # "perldynamic" is encountered, attribute values beginning with certain # # characters will be translated according to the following rules: # # $ - refers to a scalar in the current namespace # # @ - refers to an array in the current namespace # # % - refers to a hash in the current namespace # # & - refers to a subroutine in the current namespace # # # - refers to a session (form) parameter set via CGI.pm to the # # $session object, and maintained via a caching mechanism like that offered # # by Cacher.pl # #---------------------------------------------------------------------------# our $empty_field_text = ''; our $empty_text1 = 'None Supplied.'; our $empty_text2 = 'All Items.'; our $field_not_available = 'Not Yet Available.'; our $userflag; $userflag = pack("C",183); # flags user added choices to select lists, a small dot our $tok = ''; our %datehash = ( 'Y' => { label => 'Year', size => 4, }, 'M' => { label => 'Mon', size => 2, }, 'D' => { label => 'Day', size => 2, } ); #---------------------------------------------------# # file scope variables needed to make outlines work # #---------------------------------------------------# our $outlinedivcounter = 0; our $_openicon = '/images/ofolder.gif'; # default value our $_closeicon = '/images/folder.gif'; # default value our @_outlineExpand = (); our $_cboxid; our @_outlineIDary; our $_expandParent; #======================================================= sub SetEmptyText1 { $empty_field_text = $empty_text1; } #======================================================= sub SetEmptyText2 { $empty_field_text = $empty_text2; } #===================================================# sub ClearEmptyText { $empty_field_text = ''; } #==================================================# # Print the content of the html page, # # processing lines with 'perldynamic' to convert # # variables into their current values # # 1st parameter contains name of html input template# # 2nd (optional) parameter contains where to print # # the HTML output. STDOUT if omitted. # # Both input and output can be strings # #--------------------------------------------------# sub printBody { my ($htmlSource, $outputref) = @_; my @nestfiles = (); $session->param('htmlSource', $htmlSource); my $inputref; my $outputstring = ''; $outputref = \*STDOUT unless $outputref; if ($htmlSource =~ / tag # #---------------------------------------------------# # &output($outputref,"\n") # if $tok =~ /^]+)/i) { my $target = $2; my $newname; #-----------------------------------------------# # save the current state of things on the stack # #-----------------------------------------------# my %stack = (); $stack{recsep} = $/; $stack{inputref} = $inputref; $stack{tagtype} = $1; $stack{outputref} = $outputref; #-----------------------------------------------# # targets can be perl variables... # #-----------------------------------------------# if ($target =~ /^\$/) { my $tstr = evalInMain($target); $inputref = \$tstr; } #-----------------------------------------------# # ... or files (sometimes in session vars) # #-----------------------------------------------# else { if ($target =~ /^\#/) { substqueryref(\$target); $target = evalInMain($target); $target .= ".html"; } #-----------------------------------------------# # Check for file first in $ppages directory # #-----------------------------------------------# $newname = "$ppages/$target"; $inputref = new FileHandle "$newname", "r"; #-----------------------------------------------# # If not found, check $linkpages directory # #-----------------------------------------------# if (!$inputref) { $newname = "$linkpages/$target"; $inputref = new FileHandle "$newname", "r"; } unless ($inputref) { &output($outputref,qq/Can't find include file "$newname" in either \$ppages: ($ppages) or \$linkpages ($linkpages): $!\n/); return; } } $/ = "<"; # beginning of tag if ($stack{tagtype} =~ /REWRITE/i) { #-----------------------------------------------# # redirect print output to a string, which # # is then stored to the Cacher as a checkpoint # # called $target under the current sessionnum. # # The tagline is replaced with a program which # # will retrieve the string from the Cacher. # #-----------------------------------------------# my $ssn = $session->param('SessionNumber'); $newname = qq!./CachedHTML.cgi?SessionNumber=$ssn&HTMLString=$target!; $stack{target} = $target; $tok =~ s/$target/$newname/; $tok =~ s/REWRITE\s+//i; &output($outputref,$tok); $outputref = \$outputstring; } push(@nestfiles,\%stack); if($target eq 'prevnextbuttons.sgml') { my $stuff = 0; } } #---------------------------------------------------# # dynamically substitute for tokens containing the # # special 'perldynamic' identifier # #---------------------------------------------------# elsif ($tok =~ /(\"; } else { ($_tok,$$inputref) = split(">",$$inputref,2); $_tok = "<" . $_tok . ">"; $/ = "<"; } } else # ref($inputref) eq 'FileHandle' { if ($inputref->eof()) { return undef; } $_tok = <$inputref>; if ($/ eq "<") { chop $_tok; $/ = ">"; } else { $_tok = "<" . $_tok; $/ = "<"; } } } $_tok; } #==================================================================== sub processDynamicToken { my ($tagline, $inputref, $outputref) = @_; my ($text, $val); #--------------------------------------------------# # remove "perldynamic" or "pd" # #--------------------------------------------------# $tagline =~ s/perldynamic\s*//i; $tagline =~ s/\/g; my $attrs = parseTagline(\$tagline); # returns ptr to hash #--------------------------------------------------# # ONCLICK processing # #--------------------------------------------------# if ($tagline =~ /onclick='([^']+)'/i) { my $onclick = &processOnClick($1); $tagline =~ s/onclick='([^']+)'/onclick='$onclick'/; } elsif ($tagline =~ /onclick="([^"]+)"/i) { my $onclick = &processOnClick($1); $tagline =~ s/onclick="([^"]+)"/onclick="$onclick"/; } #--------------------------------------------------# # ... ... blocks # # The is optional # #--------------------------------------------------# if (exists($attrs->{if})) { my $pat = $attrs->{if}; unless (processPattern($pat)) { # skip til matching .... blocks # #---------------------------------------------------# if (my $pat=matchparam(\$tagline,'IFNOT','&#$')) { #-----------------------------------------------# # # references become query->reference # #-----------------------------------------------# if ($pat =~ /^#/) { substqueryref(\$pat); } if (evalInMain($pat)) { do { $tok = &getNextToken($inputref); } while ($tok !~ /^ # # (if checkboxes are present, and some are pre- # # selected, then the outline will expand as needed# # to show the preselections) # # # #---------------------------------------------------# elsif ($tagline =~ /^{source}); my $cboxname; my $cboxid = ''; if (ref($source) !~ /HASH|ARRAY/) { &output($outputref, "Error($tagline): expecting source=(source hash or array)"); return; } if (exists($attrs->{checkboxname})) { $cboxname= $attrs->{checkboxname}; } if (exists($attrs->{closeicon})) { $_closeicon = processPattern($attrs->{closeicon}); } if (exists($attrs->{openicon})) { $_openicon = processPattern($attrs->{openicon}); } if (exists($attrs->{expandlevels})) { @_outlineExpand = evalInMain($attrs->{expandlevels}); } else { @_outlineExpand = (); } # get terminal html (the content template of the OUTLINE tag) my $terminalhtml; while (defined($tok)) { $tok = &getNextToken($inputref); last if $tok =~ /<\/OUTLINE/i; $terminalhtml .= $tok; }; &output($outputref,qq!
!); $outlinedivcounter = ($outlinedivcounter+1) & 0x7FF; #-------------------------------# # set global array containing # # selected checkbox values # #-------------------------------# @_outlineIDary = $session->param($cboxname); my ($childex,$childhtml) = &BuildOutlineHTML($source,$terminalhtml,0,$cboxname,$cboxid); &output($outputref,qq! $childhtml
!); } #---------------------------------------------------# # DATE tags # # format= # # [readonly[ [value=$&#]> # # Formats: e.g. M/Y M/D/Y D-M-Y # # if readonly is set, display is static, otherwise # # # # if value is set, takes value as specified, other- # # wise takes value as # # #---------------------------------------------------# elsif ($tagline =~ /^{name}; my $format = 'M/Y'; my $readonly = 0; my @overridevals = (); if (exists($attrs->{value})) { my $override = evalInMain($attrs->{value}); @overridevals = split(/\D/,$override); } if (exists($attrs->{readonly})) { $readonly = 1; } if (exists($attrs->{format})) { $format = $attrs->{format}; if ($format !~ /[MDYmdy](\W[MDYmdy]){0,2}/) { &output($outputref,"Error($tagline): expecting format=(e.g)M/D/Y"); return; } } my @fary = split(/(\W)/,$format); my @vals = (); my @labels = (); my @sizes = (); my @svars = (); for (@fary) { if (/[MDYmdy]/) { my $uc = "\U$_"; my $var = $datehash{$uc}->{label}; my $svar = $name . '_' . $var; push(@vals,@overridevals ? shift(@overridevals) : ($session->param($svar) ? $session->param($svar) : '')); push(@labels,$var); push(@sizes,$datehash{$uc}->{size}); push(@svars,$svar); } else { push(@vals,$_); } } my $html = < HTML for (@labels) { $html .= <$_ HTML } $html .= < HTML for (my $i=0; $i<@vals; ) { my $size = shift(@sizes); my $svar = shift(@svars); my $str = $readonly ? qq! $vals[$i] ! : qq! $vals[$i+1] !; $html .= < $str HTML $i += 2; } $html .= < HTML &output($outputref,$html); } #---------------------------------------------------# # blocks # #---------------------------------------------------# elsif ($tagline =~ /^