#!/usr/bin/perl #use strict; use CGI; my $text_path = "/var/www/vhosts/sharlothallmuseum.org/httpdocs/archives/rosegarden/text"; # this could also be like "/home/sharlotm/text" my $image_path = "/var/www/vhosts/sharlothallmuseum.org/httpdocs/archives/rosegarden/images"; # this could also be like "/home/sharlotm/images" my $co = new CGI; my $SP = ""; my $Show_images_only = ""; my %Image; my @hlines; my ($textFromFile, $fileName, $content) = ""; my $title = "Sharlot Hall Museum - Territorial Women's Rose Garden"; my $HString = ""; my ($line ) = ""; sub error { my( $co, $error_message ) = @_; print $co->header( "text/html" ), $co->start_html( "Error" ), $co->h1( "Error" ), $co->p( "Sorry the following error has occurred: "), $co->p( $co->i( $error_message ) ), $co->end_html; exit; } $SP = $co->param( 'str' ); $Show_images_only = $co->param( 'checkbox' ); if ((!defined $SP) || ( $SP eq "" )) { $SP = "."; $HString = ""; } else { $HString = "$SP"; $HString =~ s/(\W)/sprintf("%%%x", ord($1))/eg; $HString = "\&h=" . $HString; } if (!defined $Show_images_only){ $Show_images_only = ""; } my @name_files = `find $text_path -name "*.txt" -print | sort`; if ( $? ) { error( $co, "cannot find text file names\n"); } my @image_files = `find $image_path -name "*.jpg" -print`; if ( $? ) { error( $co, "cannot find image file names\n"); } foreach $line ( @image_files ) { chomp $line; $line =~ s/^.*\///; $line =~ s/.jpg$//; $Image{$line} = "x"; } print $co->header( "text/html" ), $co->start_html( -title => $title, -bgcolor => "#ffffff" ); print < body,table,tr,td { font-family:verdana; font-size:10pt } .title { font-family:times;font-size:24pt;font-style:italic;font-weight:bold }
Territorial Women's Memorial Rose Garden
EOF my @Srch_Wds = split / /, $SP; my @all_lines; my $all_text = ""; my $NumWords = @Srch_Wds; my $Sword = ""; my $n = 0; my $Fline = ""; my @o_fnames; my @o_text; my $escline = ""; foreach $line ( @name_files ) { chomp $line; $Fline = $line; $Fline =~ s/^.*\///; $Fline =~ s/.txt$//; if ($Image{$Fline} || ( $Show_images_only ne "Photos" )) { $n = 0; chomp $Fline; foreach $Sword ( @Srch_Wds ) { if ( $Fline =~ m/$Sword/i ) { $n++; } } if ( $n == $NumWords ) { push @o_fnames, $Fline; } else { if (open(INFILE, $line)) { @all_lines = ; close (INFILE); $all_text = join('', @all_lines ); $n = 0; foreach $Sword ( @Srch_Wds ) { if ( $all_text =~ m/$Sword/i ) { $n++; } } if ( $n == $NumWords ) { push @o_text, $Fline; } } else { print "

cannot open file $line

\n"; } } } } sub byLastName { $lnf{$a} cmp $lnf{$b}; } my $num_flines = @o_fnames; my $num_text = @o_text; my @names = (); my $num = 0; my $woman = ""; my $t = ""; my @lnf = (); my $excapedText = ""; print "\n"; if ($num_flines) { if($num_flines == 1) { printf STDOUT ("\n

%s was found in the name of this woman

\n
    ", $SP); } else { if ($SP eq "." ) { if ($Show_images_only eq "Photos") { printf STDOUT ("\n

    Information, with photos, available for the following women

    \n
      "); } else { printf STDOUT ("\n

      Information available for the following women

      \n
        "); } } else { printf STDOUT ("\n

        %s was found in the names of these %s women

        \n
          ", $SP, $num_flines); } } foreach $woman (@o_fnames) { @names = split(/\s/,$woman); $num = @names; $lnf{$woman} = "$names[$num-1], "; $t = join(' ',@names[0..$num-2]); $lnf{$woman} .= $t; } @o_fnames = sort byLastName @o_fnames; foreach $woman (@o_fnames) { $escapedText = $woman; $escapedText =~ s/(\W)/sprintf("%%%x", ord($1))/eg; $name = $lnf{$woman}; print "
        • $name\n"; } printf STDOUT ("
        "); } if ($num_text) { if($num_text == 1) { printf STDOUT ("\n

        %s was found in the information of this woman

        \n
          ", $SP); } else { printf STDOUT ("\n

          %s was found in the information on file of these %s women

          \n
            ", $SP, $num_text); } foreach $woman (@o_text) { @names = split(/\s/,$woman); $num = @names; $lnf{$woman} = "$names[$num-1], "; $t = join(' ',@names[0..$num-2]); $lnf{$woman} .= $t; } @o_text = sort byLastName @o_text; foreach $woman (@o_text) { $escapedText = $woman; $escapedText =~ s/(\W)/sprintf("%%%x", ord($1))/eg; $name = $lnf{$woman}; print "
          • $name\n"; } printf STDOUT ("
          "); } if (($num_flines == 0 ) && ($num_text == 0)) { printf STDOUT ("

          NO MATCHES were found regarding %s

          \n", $SP); } print "\n




          "; print <
Additional documentation and photographs may be available in the Sharlot Hall Museum Archives and Library.
EOF print $co->end_html;