(.*)(\s)*/i){
$pub = $1;
$found = "yes"; $done = "no";
if ($pub =~/(\s)*(.*)<\/publisher>/i){ # take out end tag
$pub = $2;
$find = "doc";
# print "pub is found, looking for DOC\n";
if ($pub =~ /(\s)*(.*)(\s)*/){ #remove leading/ending spaces
$pub = $2;
}
$done = "yes";
push (@pub, $pub);
}
}
$find = "doc";
}
}
if ($find eq "doc"){
$find = "rights";
}
if (($done eq "yes") && ($find eq "rights")){
if ($_ =~ /(.*)<\/p>( )*?<\/availability>/i){
push (@rts, $1);
$rights = $1;
$done = "yes";
}
$find = "date";
}
if (($done eq "yes")&&($find eq "date")){
if($_ =~ /author>( )*?(.*)<\/date>/i){
$working = $2;
while ($working =~/(.*)">.*/){
$working = $1;
}
$dat = $working;
}
if (!$dat){
if ($_ =~ /author>( )*?.*<\/date>/i){
$working = $2;
while ($working =~/(.*)">.*/){
$working = $1;
}
$dat = $working;
}
# this for no authors
elsif ($_ =~ /title>( )*?.*<\/date>/i){
$working = $2;
while ($working =~/(.*)">.*/){
$working = $1;
}
$dat = $working;
}
}
push (@date, $dat);
$find = "des";
}
if (($done eq "yes") && ($find eq "des")){
$working = $_;
if ($working =~ /.*(.*)(\s)*<\/note>( *)?( *)?(.*)<\/xref>(.*)/i){
$working = $1." ".$2.$3;
}
$found = "yes"; $done = "yes";
#print "found this des:\n$working\n";
$working =~ s/ {3,}/ /g; # correct for overspacing in document
$working =~ s//"/ig;
$working =~ s/<\/HI>/"/ig;
if ($working){ push (@descr, $working);}
#next;
}
$find = "sub";
}
if ($find eq "sub"){
$work = "";
if ($_ =~ /(\s)*?(\s)*?(\s)*?(.*)(\s)*?<\/keywords>(\s)*?<\/textClass>(\s)*?<\/profileDesc>/i){
$work = $4;
}
if ($work =~ /- (.*)<\/item>/i){
$wk = $1;
while ($wk =~ /(.*)<\/item>( )*?
- (.+)/i){
push (@subject, $3);
$wk = $1;
}
push (@subject, $wk);
#next;
}
$find = "nada";
}
# change this; we needed to tweak our output on publisher and contributor
if (!@pub){
push (@pub, "University of Tennessee Special Collections Library");
}
push (@contrib, "University of Tennessee Special Collections Library, Knoxville");
if ($rights =~ /(.*) McClung Museum(.*)/){
push (@contrib, "Frank H. McClung Museum (Knoxville, Tenn.)");
}
if ($rights =~ /(.*)McClung Historical Collection(.*)/){
push (@contrib, "Knox County Public Library (Knoxville, Tenn.)");
}
if ($rights =~ /.*Memphis Public Library.*/){
push (@contrib, "Memphis Public Library (Memphis, Tenn.)");
}
if ($rights =~ /.*Tennessee State Library.*/){
push (@contrib, "Tennessee State Library and Archives (Nashville, Tenn.)");
}
# this is where you put in your identifier link, where you have the item online
$id = "http://anasazi.lib.utk.edu/cgi/t/text/text-idx?c=tdh;view=text;rgn=main;idno=$spc_id";
# print "check identifier link: $id\n";
push (@ids, $id);
# our default language is English, and these files were text/html files with
# tiff images
push (@lang , "en");
@type = ("Image", "Text");
@format = ("Image/tiff", "Text/html");
$check = 0;
print "\nHere are all the fields for the record that you entered:\n\n";
if(@title){print "title:"; foreach(@title){print " ".$_."\n";}}
else {$check ++;}
if(@creator){print "\ncreator:"; foreach(@creator){print " ".$_."\n";}}
else {$check ++;}
if(@subject){print "\nsubject:"; foreach(@subject){print " ".$_."\n";}}
else {$check ++;}
if(@descr){print "\ndescription:"; foreach(@descr){print " ".$_."\n";}}
else {$check ++;}
if(@pub){print "\npublisher:"; foreach(@pub){print " ".$_."\n";}}
else {$check ++;}
if(@contrib){print "\ncontributor:"; foreach(@contrib){print " ".$_."\n";}}
else {$check ++;}
if(@date){print "\ndate:"; foreach(@date){print " ".$_."\n";}}
else {$check ++;}
if(@type){print "\ntype:"; foreach(@type){print " ".$_."\n";}}
else {$check ++;}
if(@format){print "\nformat:"; foreach(@format){print " ".$_."\n";}}
else {$check ++;}
if(@ids){print "\nidentifier:"; foreach(@ids){print " ".$_."\n";}}
else {$check ++;}
if(@source){print "\nsource:"; foreach(@source){print " ".$_."\n";}}
else {$check ++;}
if(@lang){print "\nlanguage:"; foreach(@lang){print " ".$_."\n";}}
else {$check ++;}
if(@rel){print "\nrelation:"; foreach(@rel){print " ".$_."\n";}}
else {$check ++;}
if(@cov){print "\ncoverage:"; foreach(@cov){print " ".$_."\n";}}
else {$check ++;}
if(@rts){print "\nrights:"; foreach(@rts){print " ".$_."\n";}}
else {$check ++;}
if ($check == 15){
print "Sorry, we cannot enter a record with no DC values.\n";
exit;
}
print "\nIf all this is correct, type y\n";
print "TO ABORT THIS RECORD AND EXIT, type x\n";
chop($ok = );
while ($ok ne "y" && $ok ne "x"){
print "Please type y or or x:\n";
chop($ok = );
}
if ($ok eq "x"){
print "\nBye-Bye!!\n";
exit;
}
print "got here\n";
$mydate = &getDate;
$thisone = $dbh->quote($thisone);
$mydate = $dbh->quote($mydate);
$dbh = DBI->connect ("dbi:mysql:dcedit", $username, $password)
or die "Can't connect to Mysql database: ",$DBI::errstr,"\n";
$h->{PrintError} = 1;
$h->{RaiseError} = 1;
print "inserting $name as $thisone\n";
$sth = $dbh->prepare("insert into dc (id,netid,oai_date) values($thisone,$netid,$mydate)")
or die "dc: unable to insert $name, $thisone : ",$dbh->errstr(),"\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
# NOTE: THIS IS SET FOR SET 10, TDH!!!
$sth = $dbh->prepare("insert into set2dc (id,setid,dcid) values(0,'10',$thisone)")
or print "set2dc: unable to insert $name, $thisone : ",$dbh->errstr(),"\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
# collecting entire xml file for text blob in database
$all = "";
print THIS $meta_header.$udc_blurb;
foreach(@title){
print THIS " $_\n";
$title = $dbh->quote($_);
$sth = $dbh->prepare("insert into title (id, data, dcid) values (0, $title, $thisone)")
or print "title: unable to insert $name, $thisone : ",$dbh->errstr(),"\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@creator){
print THIS " $_\n";
$creator = $dbh->quote($_);
$sth = $dbh->prepare("insert into creator (id, data, dcid) values (0, $creator, $thisone)")
or print "creator: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@subject){
print THIS " $_\n";
$subject = $dbh->quote($_);
$sth = $dbh->prepare("insert into subject (id, data, dcid) values (0, $subject, $thisone)")
or print "subject: unable to insert $name, $thisone : ",$dbh->errstr(),"\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@descr){
print THIS " $_\n";
$description = $dbh->quote($_);
$sth = $dbh->prepare("insert into description (id, data, dcid) values (0, $description, $thisone)")
or print "description: unable to insert $name, $thisone : ",$dbh->errstr(),"\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@pub){
print THIS " $_\n";
$publisher = $dbh->quote($_);
$sth = $dbh->prepare("insert into publisher (id, data, dcid) values (0, $publisher, $thisone)")
or print "publisher: unable to insert $name, $thisone : ",$dbh->errstr(),"\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@contrib){
print THIS " $_\n";
$contributor = $dbh->quote($_);
$sth = $dbh->prepare("insert into contributor (id, data, dcid) values (0, $contributor, $thisone)")
or print "contributor: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@date){
print THIS " $_\n";
$date = $dbh->quote($_);
$sth = $dbh->prepare("insert into date (id, data, dcid) values (0, $date, $thisone)")
or print "date: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@type){
print THIS " $_\n";
$type = $dbh->quote($_);
$sth = $dbh->prepare("insert into type (id, data, dcid) values (0, $type, $thisone)")
or print "type: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@format){
print THIS " $_\n";
$format = $dbh->quote($_);
$sth = $dbh->prepare("insert into format (id, data, dcid) values (0, $format, $thisone)")
or print "format: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@ids){
print THIS " $_\n";
$id = $dbh->quote($_);
$sth = $dbh->prepare("insert into identifier (id, data, dcid) values (0, $id, $thisone)")
or print "identifier: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@source){
print THIS " $_\n";
$source = $dbh->quote($_);
$sth = $dbh->prepare("insert into source (id, data, dcid) values (0, $source, $thisone)")
or print "source: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@lang){
print THIS " $_\n";
$language = $dbh->quote($_);
$sth = $dbh->prepare("insert into language (id, data, dcid) values (0, $language, $thisone)")
or print "language: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@rel){
print THIS " $_\n";
$relation = $dbh->quote($_);
$sth = $dbh->prepare("insert into relation (id, data, dcid) values (0, $relation, $thisone)")
or print "relation: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@cov){
print THIS " $_\n";
$coverage = $dbh->quote($_);
$sth = $dbh->prepare("insert into coverage (id, data, dcid) values (0, $coverage, $thisone)")
or print "coverage: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
foreach(@rts){
print THIS " $_\n";
$rights = $dbh->quote($_);
$sth = $dbh->prepare("insert into rights (id, data, dcid) values (0, $rights,$thisone)")
or print "rights: unable to insert $name, $thisone : $dbh->errstr()\n";
$sth->execute()
or die "Can't execute SQL statement: ", $sth->errstr(),"\n";
$sth->finish();
}
print THIS $meta_footer;
close (THIS);
close (THAT);
$dbh->disconnect
or warn "Disconnection failed: $DBI::errstr\n";
} # end of if this file name fits 2 letters 3 numbers
} # end of looking through this directory
closedir(DIR);
exit;
sub getDate{ # gets time from the epoch, GMT time
@when = split(/ +/, `date -u`);
($mymonth, $myday, $time, $myyear) = (@when)[1,2,3,5];
($hour, $min, $sec) = split (':', $time);
chop($myyear); #lose the newline
# month must be in numbers, 0-11 !!!!!
if ($mymonth eq "Jan"){$mymonth = "00";}
elsif ($mymonth eq "Feb"){$mymonth = "01";}
elsif ($mymonth eq "Mar"){$mymonth = "02";}
elsif ($mymonth eq "Apr"){$mymonth = "03";}
elsif ($mymonth eq "May"){$mymonth = "04";}
elsif ($mymonth eq "Jun"){$mymonth = "05";}
elsif ($mymonth eq "Jul"){$mymonth = "06";}
elsif ($mymonth eq "Aug"){$mymonth = "07";}
elsif ($mymonth eq "Sep"){$mymonth = "08";}
elsif ($mymonth eq "Oct"){$mymonth = "09";}
elsif ($mymonth eq "Nov"){$mymonth = "10";}
else{$mymonth = "11";}
#$olddate = `date -u`;
#print " date: $olddate\n";
#print " month: $mymonth\n day: $myday\n year: $myyear\n hour: $hour\n minute: $min\n second: $sec\n";
$mydate = timegm($sec, $min, $hour, $myday, $mymonth, $myyear);
print "time: $mydate\n";
$mydate;
}