Project

General

Profile

1
#!/usr/bin/perl
2
#
3
#  '$RCSfile$'
4
#  Copyright: 2000 Regents of the University of California 
5
#
6
#   '$Author: jones $'
7
#     '$Date: 2004-01-08 18:57:19 -0800 (Thu, 08 Jan 2004) $'
8
# '$Revision: 2000 $' 
9
# 
10
# This program is free software; you can redistribute it and/or modify
11
# it under the terms of the GNU General Public License as published by
12
# the Free Software Foundation; either version 2 of the License, or
13
# (at your option) any later version.
14
#
15
# This program is distributed in the hope that it will be useful,
16
# but WITHOUT ANY WARRANTY; without even the implied warranty of
17
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
# GNU General Public License for more details.
19
#
20
# You should have received a copy of the GNU General Public License
21
# along with this program; if not, write to the Free Software
22
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
#
24

    
25
#
26
# This is a CGI application for inserting metadata documents into
27
# the Metacat database.  It utilizes the Metacat.pm module for most work.
28
# In this script, we process the form fields passed in from a POST, insert a
29
# metadata document and an ACL document.
30

    
31
use Metacat;
32
use AppConfig qw(:expand :argcount);
33
use XML::LibXML;
34
use XML::LibXSLT;
35
use Template;
36
use Net::SMTP;
37
use CGI qw/:standard :html3/;
38
use strict;
39

    
40
# Global configuration paramters
41
#my $cfgdir = "@install-dir@";
42
#my $cfgdir = "/usr/local/devtools/tomcat/webapps/knb/style/skins";
43
my $cfgdir = "@install-dir@@style-skins-relpath@";
44
my $tmpdir = "@temp-dir@";
45
my $templatesdir = "@install-dir@@style-common-relpath@/templates";
46
my $now = time;
47
my $xslConvDir = "$cfgdir/lib/style/";
48

    
49
# Import all of the HTML form fields as variables
50
import_names('FORM');
51

    
52
# Set up the hash for returning data to the HTML templates
53
my $templateVars = { 'status' => 'success' };
54
my $error = 0;
55
my @errorMessages;
56

    
57
# create a new AppConfig object and load our config parameters
58
# note that this requires the form submission to have a "cfg" paramter
59
# to determine which config file to load
60
my $config = AppConfig->new({
61
    GLOBAL => { ARGCOUNT => ARGCOUNT_ONE, } });
62

    
63
$config->define("metacatUrl");
64
$config->define("username");
65
$config->define("password");
66
$config->define("ldapUrl");
67
$config->define("defaultScope");
68
$config->define("organization");
69
$config->define("orgabbrev");
70
$config->define("orgurl");
71
$config->define("accesspubid");
72
$config->define("accesssysid");
73
$config->define("datasetpubid");
74
$config->define("datasetsysid");
75
$config->define("mailhost");
76
$config->define("sender");
77
$config->define("recipient");
78
$config->define("adminname");
79
if ($FORM::cfg eq 'nceas') {
80
    $config->define("nceas_db");
81
    $config->define("nceas_db_user");
82
    $config->define("nceas_db_password");
83
}
84
$config->define("responseTemplate", { DEFAULT => 'crap.tmpl'} );
85
$config->define("entryFormTemplate", { DEFAULT => 'crap.tmpl'} );
86
$config->define("guideTemplate", { DEFAULT => 'crap.tmpl'} );
87
$config->define("confirmDataTemplate", { DEFAULT => 'crap.tmpl'} );
88
$config->define("deleteDataTemplate", { DEFAULT => 'crap.tmpl'} );
89
$config->define("debug", { DEFAULT => '0'} );
90
$config->define("lat", { ARGCOUNT => ARGCOUNT_HASH} );
91
$config->define("lon", { ARGCOUNT => ARGCOUNT_HASH} );
92

    
93
if (! hasContent($FORM::cfg)) {
94
    $error = "Application misconfigured.  Please contact the administrator.";
95
    push(@errorMessages, $error);
96
} else {
97
    my $cfgfile = $cfgdir . "/" . $FORM::cfg . "/" . $FORM::cfg . ".cfg";
98
    $config->file($cfgfile);
99
}
100

    
101
my $metacatUrl = $config->metacatUrl();
102
my $username = $config->username();
103
my $password = $config->password();
104
my $ldapUrl = $config->ldapUrl();
105
my $defaultScope = $config->defaultScope();
106
my $organization = $config->organization();
107
my $orgabbrev = $config->orgabbrev();
108
my $orgurl = $config->orgurl();
109
my $orgfilter = $organization;
110
   $orgfilter =~ s/ /%20/g;
111
my $responseTemplate = $config->responseTemplate();
112
my $entryFormTemplate = $config->entryFormTemplate();
113
my $deleteDataTemplate = $config->deleteDataTemplate();
114
my $guideTemplate = $config->guideTemplate();
115
my $confirmDataTemplate = $config->confirmDataTemplate();
116
my $accesspubid = $config->accesspubid();
117
my $accesssysid = $config->accesssysid();
118
my $datasetpubid = $config->datasetpubid();
119
my $datasetsysid = $config->datasetsysid();
120
my $mailhost = $config->mailhost();
121
my $sender = $config->sender();
122
my $recipient = $config->recipient();
123
my $adminname = $config->adminname();
124
my $nceas_db;
125
my $nceas_db_user;
126
my $nceas_db_password;
127
if ($FORM::cfg eq 'nceas') {
128
    $nceas_db = $config->nceas_db();
129
    $nceas_db_user = $config->nceas_db_user();
130
    $nceas_db_password = $config->nceas_db_password();
131
}
132
my $debug = $config->debug();
133
my $lat = $config->get('lat');
134
my $lon = $config->get('lon');
135

    
136
# Convert the lat and lon configs into usable data structures
137
my @sitelist;
138
my %siteLatDMS;
139
my %siteLongDMS;
140
foreach my $newsite (keys %$lat) {
141
    my ($latd, $latm, $lats, $latdir) = split(':', $lat->{$newsite});
142
    my ($lond, $lonm, $lons, $londir) = split(':', $lon->{$newsite});
143
    push(@sitelist, $newsite);
144
    $siteLatDMS{$newsite} = [ $latd, $latm, $lats, $latdir ];
145
    $siteLongDMS{$newsite} = [ $lond, $lonm, $lons, $londir ];
146
}
147

    
148
# set some configuration options for the template object
149
my $ttConfig = {
150
             INCLUDE_PATH => $templatesdir, 
151
             INTERPOLATE  => 0,                    
152
             POST_CHOMP   => 1,                   
153
             };
154

    
155
# create an instance of the template processor
156
my $template = Template->new($ttConfig) || die $Template::ERROR, "\n";
157

    
158
print "Content-type: text/html\n\n";
159

    
160
# Set up the template information that is common to all forms
161
$$templateVars{'cfg'} = $FORM::cfg;
162
$$templateVars{'recipient'} = $recipient;
163
$$templateVars{'adminname'} = $adminname;
164
$$templateVars{'organization'} = $organization;
165
$$templateVars{'orgabbrev'} = $orgabbrev;
166
$$templateVars{'orgurl'} = $orgurl;
167
$$templateVars{'orgfilter'} = $orgfilter;
168

    
169
debug("Registry: Initialized");
170
# Process the form based on stage parameter. 
171
if ($FORM::stage =~ "guide") {
172
    # Send back the information on how to fill the form
173
    $$templateVars{'section'} = "Guide on How to Complete Registry Entries";
174
    $template->process( $guideTemplate, $templateVars);
175
    exit(0);
176

    
177
} elsif ($FORM::stage =~ "insert") {
178
    # The user has entered the data. Do data validation and send back data 
179
    # to confirm the data that has been entered. 
180
    toConfirmData();
181
    exit(0);
182

    
183
}elsif ($FORM::dataWrong =~ "No, I want to change it!!" && $FORM::stage =~ "confirmed") {
184
    # The user wants to correct the data that he has entered. 
185
    # Hence show the data again in entryData form. 
186
    confirmDataToReEntryData();
187
    exit(0);
188

    
189
}elsif ($FORM::stage =~ "modify") {
190
    # Modification of a file has been requested. 
191
    # Show the form will all the values filled in.
192
    my @sortedSites;
193
    foreach my $site (sort @sitelist) {
194
        push(@sortedSites, $site);
195
    }
196
    $$templateVars{'siteList'} = \@sortedSites;
197
    $$templateVars{'section'} = "Modification Form";
198
    $$templateVars{'docid'} = $FORM::docid;
199
    modifyData();
200
    exit(0);
201

    
202
}elsif ($FORM::stage =~ "delete_confirm") {
203

    
204
    # Result from deleteData form. 
205
    if($FORM::deleteData =~ "Delete data"){
206
    # delete Data
207
    deleteData(1);    
208
    exit(0);
209
    } else {
210
    # go back to search page. 
211
    exit(0);
212
    }
213

    
214
}elsif ($FORM::stage =~ "delete") {
215
    # Deletion of a file has been requested. 
216
    # Ask for username and password using deleteDataForm
217
    $$templateVars{'docid'} = $FORM::docid;
218
    $template->process( $deleteDataTemplate, $templateVars);
219
    exit(0);
220

    
221
}elsif ($FORM::stage !~ "confirmed") {
222
    # None of the stages have been reached and data is not being confirmed. 
223
    # Hence, send back entry form for entry of data.  
224
    debug("Registry: Sending form");
225
    my @sortedSites;
226
    foreach my $site (sort @sitelist) {
227
        push(@sortedSites, $site);
228
    }
229
    
230
    if ($FORM::cfg eq 'nceas') {
231
        my $projects = getProjectList();
232
        $$templateVars{'projects'} = $projects;
233
        $$templateVars{'wg'} = \@FORM::wg;
234
    }
235

    
236
    $$templateVars{'siteList'} = \@sortedSites;
237
    $$templateVars{'section'} = "Entry Form";
238
    $$templateVars{'docid'} = "";
239
    debug("Registry: Sending form: ready to process template");
240
    $template->process( $entryFormTemplate, $templateVars);
241
    debug("Registry: Sending form: template processed");
242
    exit(0);
243
}
244

    
245
# Confirm stage has been reached. Enter the data into metacat. 
246

    
247
# Initialize some global vars
248
my $latDeg1 = "";
249
my $latMin1 = "";
250
my $latSec1 = "";
251
my $hemisphLat1 = "";
252
my $longDeg1 = "";
253
my $longMin1 = "";
254
my $longSec1 = "";
255
my $hemisphLong1 = "";
256
my $latDeg2 = "";
257
my $latMin2 = "";
258
my $latSec2 = "";
259
my $hemisphLat2 = "";
260
my $longDeg2 = "";
261
my $longMin2 = "";
262
my $longSec2 = "";
263
my $hemisphLong2 = "";
264

    
265
# validate the input form parameters
266
my $invalidParams;
267

    
268
if (! $error) {
269
    $invalidParams = validateParameters(1);
270
    if (scalar(@$invalidParams)) {
271
        $$templateVars{'status'} = 'failure';
272
        $$templateVars{'invalidParams'} = $invalidParams;
273
        $error = 1;
274
    }
275
}
276

    
277

    
278
my $metacat;
279
my $docid;
280
if (! $error) {
281
    # Parameters have been validated and Create the XML document
282

    
283
    my $xmldoc = createXMLDocument();
284

    
285
    # Write out the XML file for debugging purposes
286
    #my $testFile = $tmpdir . "/test.xml";
287

    
288
    # Create a  metacat object
289
    $metacat = Metacat->new();
290
    if ($metacat) {
291
        $metacat->set_options( metacatUrl => $metacatUrl );
292
    } else {
293
        #die "failed during metacat creation\n";
294
        push(@errorMessages, "Failed during metacat creation.");
295
    }
296

    
297
    # Login to metacat
298
    my $userDN = $FORM::username;
299
    my $userOrg = $FORM::organization;
300
    my $userPass = $FORM::password;
301
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
302
    
303
    my $errorMessage = "";
304
    my $response = $metacat->login($dname, $userPass);
305
    if (! $response) {
306
        push(@errorMessages, $metacat->getMessage());
307
        push(@errorMessages, "Failed during login.\n");
308
    }
309

    
310
    debug( "Registry: A");
311
    if ($FORM::docid eq "") {
312
        debug( "Registry: B1");
313
        # document is being inserted 
314
        my $notunique = "NOT_UNIQUE";
315
        while ($notunique eq "NOT_UNIQUE") {
316
            $docid = newAccessionNumber($defaultScope);
317
            
318
            $xmldoc =~ s/docid/$docid/;
319
    
320
            #my $testFile = "/tmp/test.xml";
321
            #open (TFILE,">$testFile") || die ("Cant open xml file...\n");
322
            #print TFILE $xmldoc;
323
            #close(TFILE);
324
    
325
            $notunique = insertMetadata($xmldoc, $docid);
326
            #  if (!$notunique) {
327
            # Write out the XML file for debugging purposes
328
            #my $testFile = $tmpdir . "/test-new.xml";
329
            #open (TFILE,">$testFile") || die ("Cant open xml file...\n");
330
            #print TFILE $newdoc;
331
            #close(TFILE);
332
            #   }
333

    
334
            # The id wasn't unique, so update our lastid file
335
            if ($notunique eq "NOT_UNIQUE") {
336
                debug( "Registry: Updating lastid (B1.1)");
337
                updateLastId($defaultScope);
338
            }
339
        }
340
        debug("Registry: B2");
341
        if ($notunique ne "SUCCESS") {
342
            debug("Registry: NO SUCCESS");
343
            debug("Message is: $notunique");
344
            push(@errorMessages, $notunique);
345
        }
346
        debug("Registry: B3");
347
    } else {
348
        # document is being modified
349
        $docid = $FORM::docid;
350
    
351
        my $x;
352
        my $y;
353
        my $z;
354

    
355
        ($x, $y, $z) = split(/\./, $docid); 
356
        $z++;
357
        $docid = "$x.$y.$z";
358
    
359
        $xmldoc =~ s/docid/$docid/;
360
        
361
        my $response = $metacat->update($docid, $xmldoc);
362

    
363
        if (! $response) {
364
            push(@errorMessages, $metacat->getMessage());
365
            push(@errorMessages, "Failed while updating.\n");  
366
        }
367

    
368
        if (scalar(@errorMessages)) {
369
            debug("Registry: ErrorMessages defined in modify.");
370
            $$templateVars{'status'} = 'failure';
371
            $$templateVars{'errorMessages'} = \@errorMessages;
372
            $error = 1;
373
        }
374

    
375
        #if (! $error) {
376
            #sendNotification($docid, $mailhost, $sender, $recipient);
377
        #}
378
    
379
        # Create our HTML response and send it back
380
        $$templateVars{'function'} = "modified";
381
        $$templateVars{'section'} = "Modification Status";
382
        $template->process( $responseTemplate, $templateVars);
383

    
384
        exit(0);
385
    }
386
}
387

    
388
debug("Registry: C");
389

    
390
if (scalar(@errorMessages)) {
391
    debug("Registry: ErrorMessages defined.");
392
    $$templateVars{'status'} = 'failure';
393
    $$templateVars{'errorMessages'} = \@errorMessages;
394
    $error = 1;
395
}
396

    
397
#if (! $error) {
398
#sendNotification($docid, $mailhost, $sender, $recipient);
399
#}
400

    
401
# Create our HTML response and send it back
402
$$templateVars{'function'} = "submitted";
403
$$templateVars{'section'} = "Submission Status";
404
$template->process( $responseTemplate, $templateVars);
405

    
406
exit(0);
407

    
408

    
409
################################################################################
410
#
411
# Subroutine for updating a metacat id for a given scope to the highest value
412
#
413
################################################################################
414
sub updateLastId {
415
  my $scope = shift;
416

    
417
  my $errormsg = 0;
418
  my $docid = $metacat->getLastId($scope);
419

    
420
  if ($docid =~ /null/) {
421
      # No docids with this scope present, so do nothing
422
  } elsif ($docid) {
423
      # Update the lastid file for this scope
424
      (my $foundScope, my $id, my $rev) = split(/\./, $docid);
425
      debug("Docid is: $docid\n");
426
      debug("Lastid is: $id");
427
      my $scopeFile = $cfgdir . "/" . $FORM::cfg . "/" . $scope . ".lastid";
428
      open(LASTID, ">$scopeFile") or 
429
          die "Failed to open lastid file for writing!";
430
      print LASTID $id, "\n";
431
      close(LASTID);
432
  } else {
433
    $errormsg = $metacat->getMessage();
434
    debug("Error in getLastId: $errormsg");
435
  }
436
}
437

    
438
################################################################################
439
#
440
# Subroutine for inserting a document to metacat
441
#
442
################################################################################
443
sub insertMetadata {
444
  my $xmldoc = shift;
445
  my $docid = shift;
446

    
447
  my $notunique = "SUCCESS";
448
  debug("Registry: Starting insert (D1)");
449
  my $response = $metacat->insert($docid, $xmldoc);
450
  if (! $response) {
451
    debug("Registry: Response gotten (D2)");
452
    my $errormsg = $metacat->getMessage();
453
    debug("Registry: Error is (D3): ".$errormsg);
454
    if ($errormsg =~ /is already in use/) {
455
      $notunique = "NOT_UNIQUE";
456
      #print "Accession number already used: $docid\n";
457
    } elsif ($errormsg =~ /<login>/) {
458
      $notunique = "SUCCESS";
459
    } else {
460
      #print "<p>Dumping error on failure...</p>\n";
461
      #print "<p>", $errormsg, "</p>\n";
462
      #die "Failed during insert\n";
463
      #print "<p>Failed during insert</p>\n";
464
      $notunique = $errormsg;
465
    }
466
  }
467
  debug("Registry: Ending insert (D4)");
468

    
469
  return $notunique;
470
}
471

    
472
################################################################################
473
#
474
# Subroutine for generating a new accession number
475
#  Note: this is not threadsafe, assumes only one running process at a time
476
#  Also: need to check metacat for max id # used in this scope already
477
################################################################################
478
sub newAccessionNumber {
479
  my $scope = shift;
480
    
481
  my $docrev = 1;
482
  my $lastid = 1;
483

    
484
  my $scopeFile = $cfgdir . "/" . $FORM::cfg . "/" . $scope . ".lastid";
485
  if (-e $scopeFile) {
486
    open(LASTID, "<$scopeFile") or die "Failed to generate accession number!";
487
    $lastid = <LASTID>;
488
    chomp($lastid);
489
    $lastid++;
490
    close(LASTID);
491
  }
492
  open(LASTID, ">$scopeFile") or die "Failed to open lastid file for writing!";
493
  print LASTID $lastid, "\n";
494
  close(LASTID);
495

    
496
  my $docroot = "$scope.$lastid.";
497
  my $docid = $docroot . $docrev;
498
  return $docid;
499
}
500

    
501
################################################################################
502
#
503
# Subroutine for generating a new ACL document
504
#
505
################################################################################
506
sub newAccessDocument {
507
  my $aclid = shift;
508
  my $acl = "<?xml version=\"1.0\"?>\n";
509
  $acl .= "<!DOCTYPE acl ";
510
  $acl .= "PUBLIC \"$accesspubid\" \"$accesssysid\">\n";
511
  $acl .= "<acl authSystem=\"ldap://ldap.ecoinformatics.org\" ";
512
  $acl .= "order=\"denyFirst\">\n";
513
  $acl .= "<identifier system=\"knb\">$aclid</identifier>\n";
514
  #$acl .= "<identifier>$aclid</identifier>\n";
515
  $acl .= "<allow><principal>$username</principal>" .
516
          "<permission>all</permission></allow>\n";
517
  #$acl .= "<allow><principal>public</principal>" .
518
  #        "<permission>read</permission></allow>\n";
519
  $acl .= "</acl>\n";
520

    
521
  return $acl;
522
}
523

    
524
################################################################################
525
#
526
# Subroutine for inserting identifers to the metadata document passed to us
527
#
528
################################################################################
529
sub insertIdentifiers {
530
  my $docstring = shift;
531
  my $aclid = shift;
532
  my $docid = shift;
533

    
534
  my $parser = XML::LibXML->new();
535
  my $dom = $parser->parse_string($docstring);
536

    
537
  my $root = $dom->documentElement;
538
  my $name = $root->getName();
539

    
540
  my $addedIdentifier = 0;
541
  my $currentElement = $root->getFirstChild();
542
  $name = $currentElement->getName();
543
  while ("$name" !~ "triple" &&
544
         "$name" !~ "temporalCov" && 
545
         "$name" !~ "geographicCov" && 
546
         "$name" !~ "taxonomicCov"
547
        ) {
548
    if ("$name" =~ "identifier" ||
549
        "$name" =~ "title") {
550
      if (! $addedIdentifier) {
551
      my $idelement = $dom->createElement( "identifier" );
552
        $addedIdentifier = 1;
553
        $idelement->setAttribute("system", "knb");
554
        $idelement->appendTextNode($docid);
555
        $root->insertBefore($idelement, $currentElement);
556
      }
557
    }
558
    $currentElement = $currentElement->getNextSibling();
559
    $name = $currentElement->getName();
560
  }
561
  # Link the document to the access doc
562
  my $element = $dom->createElement( "triple" );
563
  $element->appendTextChild( "subject", $aclid);
564
  $element->appendTextChild( "relationship", 
565
                             "describes access control rules for");
566
  $element->appendTextChild( "object", $docid);
567
  $root->insertBefore($element, $currentElement);
568
  # Link the access doc to the access doc
569
  $element = $dom->createElement( "triple" );
570
  $element->appendTextChild( "subject", $aclid);
571
  $element->appendTextChild( "relationship", 
572
                             "describes access control rules for");
573
  $element->appendTextChild( "object", $aclid);
574
  $root->insertBefore($element, $currentElement);
575

    
576
  return $dom->toString();
577
}
578

    
579
################################################################################
580
# 
581
# Validate the parameters to make sure that required params are provided
582
#
583
################################################################################
584
sub validateParameters {
585
    my $chkUser = shift;
586
    my @invalidParams;
587

    
588
    push(@invalidParams, "Provider's first name is missing.")
589
        unless hasContent($FORM::providerGivenName);
590
    push(@invalidParams, "Provider's last name is missing.")
591
        unless hasContent($FORM::providerSurName);
592
    push(@invalidParams, "Name of site is missing.")
593
        unless (hasContent($FORM::site) || $FORM::site =~ /elect/ ||
594
                $FORM::cfg eq "nceas");
595
    push(@invalidParams, "Data set title is missing.")
596
        unless hasContent($FORM::title);
597
    push(@invalidParams, "Originator's first name is missing.")
598
        unless hasContent($FORM::origNamefirst0);
599
    push(@invalidParams, "Originator's last name is missing.")
600
        unless hasContent($FORM::origNamelast0);
601
    push(@invalidParams, "Abstract is missing.")
602
        unless hasContent($FORM::abstract);
603
    push(@invalidParams, "Beginning year of data set is missing.")
604
        unless hasContent($FORM::beginningYear);
605
    push(@invalidParams, "Geographic description is missing.")
606
        unless (hasContent($FORM::geogdesc));
607

    
608
    # If the "use site" coord. box is checked and if the site is in 
609
    # the longitude hash ...  && ($siteLatDMS{$FORM::site})
610
   
611
    if (($FORM::useSiteCoord) && ($siteLatDMS{$FORM::site}) ) {
612
        
613
        $latDeg1 = $siteLatDMS{$FORM::site}[0];
614
        $latMin1 = $siteLatDMS{$FORM::site}[1];
615
        $latSec1 = $siteLatDMS{$FORM::site}[2];
616
        $hemisphLat1 = $siteLatDMS{$FORM::site}[3];
617
        $longDeg1 = $siteLongDMS{$FORM::site}[0];
618
        $longMin1 = $siteLongDMS{$FORM::site}[1];
619
        $longSec1 = $siteLongDMS{$FORM::site}[2];
620
        $hemisphLong1 = $siteLongDMS{$FORM::site}[3];
621
     
622
    }  else {
623
    
624
        $latDeg1 = $FORM::latDeg1;
625
        $latMin1 = $FORM::latMin1;
626
        $latSec1 = $FORM::latSec1;
627
        $hemisphLat1 = $FORM::hemisphLat1;
628
        $longDeg1 = $FORM::longDeg1;
629
        $longMin1 = $FORM::longMin1;
630
        $longSec1 = $FORM::longSec1;
631
        $hemisphLong1 = $FORM::hemisphLong1;
632
    }
633
    
634
    # Check if latDeg1 and longDeg1 has values if useSiteCoord is used. 
635
    # This check is required because some of the sites dont have lat 
636
    # and long mentioned in the config file. 
637

    
638
    if ($FORM::useSiteCoord) {
639
    push(@invalidParams, "The Data Registry doesn't have latitude and longitude information for the site that you chose. Please go back and enter the spatial information.")
640
        unless(hasContent($latDeg1) && hasContent($longDeg1));
641
    }else{
642
    push(@invalidParams, "Latitude degrees are missing.")
643
        unless hasContent($latDeg1);
644
    push(@invalidParams, "Longitude degrees are missing.")
645
        unless hasContent($longDeg1);
646
    }
647

    
648
    push(@invalidParams, 
649
        "You must provide a method description if you provide a method title.")
650
        if (hasContent($FORM::methodTitle) && ( !(scalar(@FORM::methodPara) > 0) 
651
                || (! hasContent($FORM::methodPara[0]))));
652
    push(@invalidParams, 
653
        "You must provide a method description if you provide a study extent description.")
654
        if (hasContent($FORM::studyExtentDescription) && (!(scalar(@FORM::methodPara) > 0) 
655
                || (! hasContent($FORM::methodPara[0]))));
656
    push(@invalidParams, 
657
        "You must provide both a study extent description and a sampling description, or neither.")
658
        if (
659
                (hasContent($FORM::studyExtentDescription) && !hasContent($FORM::samplingDescription)) ||
660
                (!hasContent($FORM::studyExtentDescription) && hasContent($FORM::samplingDescription))
661
           );
662

    
663
    push(@invalidParams, "Contact first name is missing.")
664
    unless (hasContent($FORM::origNamefirstContact) || 
665
        $FORM::useOrigAddress);
666
    push(@invalidParams, "Contact last name is missing.")
667
    unless (hasContent($FORM::origNamelastContact) || 
668
        $FORM::useOrigAddress);
669
    push(@invalidParams, "Data medium is missing.")
670
    unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/);
671
    
672
    return \@invalidParams;
673
}
674

    
675
################################################################################
676
# 
677
# utility function to determine if a paramter is defined and not an empty string
678
#
679
################################################################################
680
sub hasContent {
681
    my $param = shift;
682

    
683
    my $paramHasContent;
684
    if (!defined($param) || $param eq '') { 
685
        $paramHasContent = 0;
686
    } else {
687
        $paramHasContent = 1;
688
    }
689
    return $paramHasContent;
690
}
691

    
692

    
693
################################################################################
694
# 
695
# Create the XML document from the HTML form input
696
# returns the XML document as a string
697
#
698
################################################################################
699
sub createXMLDocument {
700

    
701
    my $orig  = "";
702
    my $role  = "associatedParty";
703
    my $creat = "";
704
    my $metaP = "";
705
    my $apart = "";
706
    my $cont  = "";
707
    my $publ  = "";
708
    my $dso   = "";
709
    my $gmt = gmtime($now);
710
    my $doc =  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
711

    
712
   $doc .= "<eml:eml\n 
713
                     \t packageId=\"docid\" system=\"knb\"\n 
714
                     \t xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.0\"\n
715
                     \t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n 
716
                     \t xmlns:ds=\"eml://ecoinformatics.org/dataset-2.0.0\"\n 
717
                     \t xmlns:stmml=\"http://www.xml-cml.org/schema/stmml\"\n 
718
                     \t xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.0 eml.xsd\">\n";
719

    
720
    $doc .= "<!-- Person who filled in the catalog entry form: ";
721
    $doc .= "$FORM::providerGivenName $FORM::providerSurName -->\n";
722
    $doc .= "<!-- Form filled out at $gmt GMT -->\n";
723
    $doc .= "<dataset>\n";
724
    
725
    if (hasContent($FORM::identifier)) {
726
        $doc .= "<alternateIdentifier system=\"$FORM::site\">";
727
        $doc .= $FORM::identifier . "</alternateIdentifier>\n";
728
    }
729
    
730
    if (hasContent($FORM::title)) {
731
        $doc .= "<title>$FORM::title</title>\n";
732
    }
733

    
734
    if (hasContent($FORM::origNamelast0)) {
735
    $role = "creator";
736
        $orig .= "<individualName>\n";
737
        $orig .= "<givenName>$FORM::origNamefirst0</givenName>\n";
738
        $orig .= "<surName>$FORM::origNamelast0</surName>\n";
739
        $orig .= "</individualName>\n";
740
    }
741

    
742
    if (hasContent($FORM::origNameOrg)) {
743
        $orig .= "<organizationName>$FORM::origNameOrg</organizationName>\n";
744
    }
745

    
746
    if (hasContent($FORM::origDelivery) || hasContent($FORM::origCity) ||
747
        (hasContent($FORM::origState   ) &&
748
        ($FORM::origState !~ "Select state here.")) ||
749
        hasContent($FORM::origStateOther) ||
750
        hasContent($FORM::origZIP ) || hasContent($FORM::origCountry)) {
751
        $orig .= "<address>\n";
752

    
753
        if (hasContent($FORM::origDelivery)) {
754
            $orig .= "<deliveryPoint>$FORM::origDelivery</deliveryPoint>\n";
755
        }
756
        if (hasContent($FORM::origCity)) {
757
            $orig .= "<city>$FORM::origCity</city>\n";
758
        }
759

    
760
    if (hasContent($FORM::origState) && 
761
            ($FORM::origState !~ "Select state here.")) {
762
            $orig .= "<administrativeArea>$FORM::origState";
763
            $orig .= "</administrativeArea>\n";
764
        } elsif (hasContent($FORM::origStateOther)) {
765
            $orig .= "<administrativeArea>$FORM::origStateOther";
766
            $orig .= "</administrativeArea>\n";
767
        }
768
        if (hasContent($FORM::origZIP)) {
769
            $orig .= "<postalCode>$FORM::origZIP</postalCode>\n";
770
        }
771
        if (hasContent($FORM::origCountry)) {
772
            $orig .= "<country>$FORM::origCountry</country>\n";
773
        }
774
        $orig .= "</address>\n";
775
    }
776

    
777
    if (hasContent($FORM::origPhone)) {
778
        $orig .= "<phone>$FORM::origPhone</phone>\n";
779
    }
780
    if (hasContent($FORM::origFAX)) {
781
        $orig .= "<phone phonetype=\"Fax\">$FORM::origFAX</phone>\n";
782
    }
783
    if (hasContent($FORM::origEmail)) {
784
        $orig .= "<electronicMailAddress>$FORM::origEmail";
785
        $orig .= "</electronicMailAddress>\n";
786
    }
787
    $dso = "<$role>\n$orig</$role>\n";
788
    
789
    $creat .= $dso;
790

    
791
    if ($FORM::useOrigAddress) {
792
        # Add a contact originator like the original with a different role
793
            $cont .= "<contact>\n";
794
        $cont .= $orig;
795
        $cont .= "</contact>\n";
796
    } else {
797
        $cont .= "<contact>\n";
798

    
799
        $cont .= "<individualName>\n";
800
        $cont .= "<givenName>$FORM::origNamefirstContact</givenName>\n";
801
        $cont .= "<surName>$FORM::origNamelastContact</surName>\n";
802
        $cont .= "</individualName>\n";
803
 
804
    if (hasContent($FORM::origNameOrgContact)) {
805
        $cont .= "<organizationName>$FORM::origNameOrgContact</organizationName>\n";
806
    }
807

    
808
        if (hasContent($FORM::origDeliveryContact) || 
809
            hasContent($FORM::origCityContact) ||
810
            (hasContent($FORM::origStateContact) &&
811
            ($FORM::origStateContact !~ "Select state here.")) ||
812
            hasContent($FORM::origStateOtherContact) ||
813
            hasContent($FORM::origZIPContact) || 
814
            hasContent($FORM::origCountryContact)) {
815
            $cont .= "<address>\n";
816
            if (hasContent($FORM::origDeliveryContact)) {
817
                $cont .= "<deliveryPoint>$FORM::origDeliveryContact";
818
                $cont .= "</deliveryPoint>\n";
819
            }
820
            if (hasContent($FORM::origCityContact)) {
821
                $cont .= "<city>$FORM::origCityContact</city>\n";
822
            }
823
            if (hasContent($FORM::origStateContact) && 
824
                ($FORM::origStateContact !~ "Select state here.")) {
825
                $cont .= "<administrativeArea>$FORM::origStateContact";
826
                $cont .= "</administrativeArea>\n";
827
            } elsif (hasContent($FORM::origStateOtherContact)) {
828
                $cont .= "<administrativeArea>$FORM::origStateOtherContact";
829
                $cont .= "</administrativeArea>\n";
830
            }
831
            if (hasContent($FORM::origZIPContact)) {
832
                $cont .= "<postalCode>$FORM::origZIPContact</postalCode>\n";
833
            }
834
            if (hasContent($FORM::origCountryContact)) {
835
                $cont .= "<country>$FORM::origCountryContact</country>\n";
836
            }
837
            $cont .= "</address>\n";
838
        }
839
        if (hasContent($FORM::origPhoneContact)) {
840
            $cont .= "<phone>$FORM::origPhoneContact</phone>\n";
841
        }
842
    if (hasContent($FORM::origFAXContact)) {
843
        $cont .= "<phone phonetype=\"Fax\">$FORM::origFAXContact</phone>\n";
844
    }
845
        if (hasContent($FORM::origEmailContact)) {
846
            $cont .= "<electronicMailAddress>$FORM::origEmailContact";
847
            $cont .= "</electronicMailAddress>\n";
848
        }
849
    $cont .= "</contact>\n";
850
    }
851

    
852
    $metaP .= "<metadataProvider>\n";
853
    $metaP .= "<individualName>\n";
854
    $metaP .= "<givenName>$FORM::providerGivenName</givenName>\n";
855
    $metaP .= "<surName>$FORM::providerSurName</surName>\n";
856
    $metaP .= "</individualName>\n";
857
    $metaP .= "</metadataProvider>\n";
858

    
859
    # Additional originators
860
    foreach my $tmp (param()) {
861
        if ($tmp =~ /origNamelast/){
862
            my $tmp1 = $tmp;
863
            $tmp1 =~ s/origNamelast//; # get the index of the parameter 0 to 10
864
            if ( $tmp1 eq '1' 
865
                 || $tmp1 eq '2'
866
                 || $tmp1 eq '3'
867
                 || $tmp1 eq '4'
868
                 || $tmp1 eq '5'
869
                 || $tmp1 eq '6'
870
                 || $tmp1 eq '7'
871
                 || $tmp1 eq '8'
872
                 || $tmp1 eq '9'
873
                 || $tmp1 eq '10'
874
                 ) {
875
     
876
                # do not generate XML for empty originator fields 
877
                if (hasContent(param("origNamefirst" . $tmp1))) {    
878

    
879
            my $add = "";
880
            $add .= "<individualName>\n";
881
            $add .= "<givenName>";
882
            $add .= param("origNamefirst" . $tmp1);
883
            $add .= "</givenName>\n";
884
            $add .= "<surName>";
885
            $add .= param("origNamelast" . $tmp1);
886
            $add .= "</surName>\n";
887
            $add .= "</individualName>\n";
888
            
889
            if(param("origRole" . $tmp1) eq "Originator"){
890
            $creat .= "<creator>\n";
891
            $creat .= $add;
892
            $creat .= "</creator>\n";
893
            }
894
            elsif(param("origRole" . $tmp1) eq "Metadata Provider"){
895
            $metaP .= "<metadataProvider>\n";
896
            $metaP .= $add;
897
            $metaP .= "</metadataProvider>\n";
898
            }
899
            elsif((param("origRole" . $tmp1) eq "Publisher")  && ($publ eq "")){
900
            $publ .= "<publisher>\n";
901
            $publ .= $add;
902
            $publ .= "</publisher>\n";
903
            }
904
            else{
905
            $apart .= "<associatedParty>\n";
906
            $apart .= $add;
907
            $apart .= "<role>";
908
            $apart .= param("origRole" . $tmp1);
909
            $apart .= "</role>\n";
910
            $apart .= "</associatedParty>\n";
911
            }
912
        }
913
            }
914
        }
915
    }
916

    
917
    $creat .= "<creator>\n";
918
    $creat .= "<organizationName>$FORM::site</organizationName>\n";
919
    $creat .= "</creator>\n";
920

    
921
    $creat .= "<creator>\n";
922
    $creat .= "<organizationName>$organization</organizationName>\n";
923
    $creat .= "</creator>\n";
924

    
925
    if ($FORM::cfg eq 'nceas') {
926
        for (my $i = 0; $i < scalar(@FORM::wg); $i++) {
927
            $creat .= "<creator>\n";
928
            $creat .= "<organizationName>$FORM::wg[$i]</organizationName>\n";
929
            $creat .= "</creator>\n";
930
        }
931
    }
932
    $doc .= $creat;
933
    $doc .= $metaP;
934
    $doc .= $apart;
935

    
936
    $doc .= "<abstract>\n";
937
    $doc .= "<para>$FORM::abstract</para>\n";
938
    $doc .= "</abstract>\n";
939

    
940
    # Keyword information
941
    foreach my $tmp (param()) {
942
        if ($tmp =~ /keyword/) {
943
            my $tmp1 = $tmp;
944
            $tmp1 =~ s/keyword//; # get the index of the parameter 0, ..., 10
945
            if ( $tmp1 =~ /[0-9]/ ){
946
                # don't generate xml for empty keyword fields
947
                # don't generate taxonomic keyword fields, those go in taxonomic coverage
948
                if (hasContent(param($tmp))) {
949
                    $doc .= "<keywordSet>\n";
950
                    $doc .= "<keyword ";
951
                    if (hasContent(param("kwType" . $tmp1)) &&
952
                       (param("kwType" . $tmp1) !~ "none") ) {
953
                         $doc .= "keywordType=\"";
954
                         $doc .= param("kwType" . $tmp1);
955
                         $doc .= "\"";
956
                    }
957
                    $doc .= ">";
958
                    $doc .= param("keyword" . $tmp1);
959
                    $doc .= "</keyword>\n";
960
                    $doc .= "<keywordThesaurus>";
961
                    $doc .= param("kwTh" . $tmp1);
962
                    $doc .= "</keywordThesaurus>\n";
963
                    $doc .= "</keywordSet>\n";
964
                }
965
            }
966
        }
967
    }
968

    
969
    if (hasContent($FORM::addComments)) {
970
        $doc .= "<additionalInfo>\n";
971
        $doc .= "<para>$FORM::addComments</para>\n";
972
        $doc .= "</additionalInfo>\n";
973
    }
974

    
975
    if (hasContent($FORM::useConstraints) || 
976
        hasContent($FORM::useConstraintsOther)) {
977
        $doc .= "<intellectualRights>\n";
978
        if (hasContent($FORM::useConstraints)) {
979
            $doc .= "<para>$FORM::useConstraints</para>\n";
980
        }
981
        if (hasContent($FORM::useConstraintsOther)) {
982
            $doc .= "<para>$FORM::useConstraintsOther</para>\n";
983
        }
984
        $doc .= "</intellectualRights>\n";
985
    }
986

    
987
    
988
    if (hasContent($FORM::url)) {
989
    $doc .= "<distribution>\n";
990
        $doc .= "<online>\n";
991
    $doc .= "<url>$FORM::url</url>\n";
992
    $doc .= "</online>\n";
993
    $doc .= "</distribution>\n";
994
    }
995
    
996
    $doc .= "<distribution>\n";
997
    $doc .= "<offline>\n";
998
    $doc .= "<mediumName>" . "$FORM::dataMedium   $FORM::dataMediumOther";
999
    $doc .= "</mediumName>\n";
1000
    $doc .= "</offline>\n";
1001
    $doc .= "</distribution>\n";
1002
            
1003
    $doc .= "<coverage>\n";
1004
    $doc .= "<temporalCoverage>\n";
1005

    
1006

    
1007
    if (hasContent($FORM::endingYear)) {
1008
    $doc .= "<rangeOfDates>\n";
1009
    if (hasContent($FORM::beginningMonth)) {
1010
        my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1011
             "JUL","AUG","SEP","OCT","NOV","DEC")
1012
        [$FORM::beginningMonth - 1];
1013
        $doc .= "<beginDate>\n";
1014
        $doc .= "<calendarDate>";
1015
        $doc .= "$FORM::beginningYear-$FORM::beginningMonth-$FORM::beginningDay";
1016
        $doc .= "</calendarDate>\n";
1017
        $doc .= "</beginDate>\n";
1018
    } else {
1019
        $doc .= "<beginDate>\n";
1020
        $doc .= "<calendarDate>";
1021
        $doc .= "$FORM::beginningYear";
1022
        $doc .= "</calendarDate>\n";
1023
        $doc .= "</beginDate>\n";
1024
    }
1025

    
1026
    if (hasContent($FORM::endingMonth)) {
1027
        my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1028
             "JUL","AUG","SEP","OCT","NOV","DEC")
1029
        [$FORM::endingMonth - 1];
1030
        $doc .= "<endDate>\n";
1031
        $doc .= "<calendarDate>";
1032
        $doc .= "$FORM::endingYear-$FORM::endingMonth-$FORM::endingDay";
1033
        $doc .= "</calendarDate>\n";
1034
        $doc .= "</endDate>\n";
1035
    } else {
1036
        $doc .= "<endDate>\n";
1037
        $doc .= "<calendarDate>";
1038
        $doc .= "$FORM::endingYear";
1039
        $doc .= "</calendarDate>\n";
1040
        $doc .= "</endDate>\n";
1041
    }
1042
    $doc .= "</rangeOfDates>\n";
1043
    } else {
1044
    $doc .= "<singleDateTime>\n";
1045
    if (hasContent($FORM::beginningMonth)) {
1046
        my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1047
             "JUL","AUG","SEP","OCT","NOV","DEC")
1048
        [$FORM::beginningMonth - 1];
1049
        $doc .= "<calendarDate>";
1050
        $doc .= "$FORM::beginningYear-$FORM::beginningMonth-$FORM::beginningDay";
1051
        $doc .= "</calendarDate>\n";
1052
    } else {
1053
        $doc .= "<calendarDate>";
1054
        $doc .= "$FORM::beginningYear";
1055
        $doc .= "</calendarDate>\n";
1056
    }
1057
    $doc .= "</singleDateTime>\n";
1058
    }
1059

    
1060
    $doc .= "</temporalCoverage>\n";
1061
    
1062
    $doc .= "<geographicCoverage>\n";
1063
    $doc .= "<geographicDescription>$FORM::geogdesc</geographicDescription>\n";
1064
    $doc .= "<boundingCoordinates>\n";
1065

    
1066
    # if the second latitude is missing, then set the second lat/long pair 
1067
    # equal to the first this makes a point appear like a rectangle 
1068
    if ($FORM::latDeg2 == 0 && $FORM::latMin2 == 0 && $FORM::latSec2 == 0) {
1069
    
1070
        $latDeg2 = $latDeg1;
1071
        $latMin2 = $latMin1;
1072
        $latSec2 = $latSec1;
1073
        $hemisphLat2 = $hemisphLat1;
1074
        $longDeg2 = $longDeg1;
1075
        $longMin2 = $longMin1;
1076
        $longSec2 = $longSec1;
1077
        $hemisphLong2 = $hemisphLong1;
1078
    }
1079
    else
1080
    {
1081
        $latDeg2 = $FORM::latDeg2;
1082
        $latMin2 = $FORM::latMin2;
1083
        $latSec2 = $FORM::latSec2;
1084
        $hemisphLat2 = $FORM::hemisphLat2;
1085
        $longDeg2 = $FORM::longDeg2;
1086
        $longMin2 = $FORM::longMin2;
1087
        $longSec2 = $FORM::longSec2;
1088
        $hemisphLong2 = $FORM::hemisphLong2;
1089
    } 
1090
    
1091
   
1092
    my $hemisph;
1093
    $hemisph = ($hemisphLong1 eq "W") ? -1 : 1;
1094
    $doc .= "<westBoundingCoordinate>";
1095
    $doc .= $hemisph * ($longDeg1 + (60*$longMin1+$longSec1)/3600);
1096
    $doc .= "</westBoundingCoordinate>\n";
1097

    
1098
    $hemisph = ($hemisphLong2 eq "W") ? -1 : 1;
1099
    $doc .= "<eastBoundingCoordinate>";
1100
    $doc .= $hemisph * ($longDeg2 + (60*$longMin2+$longSec2)/3600);
1101
    $doc .= "</eastBoundingCoordinate>\n";
1102

    
1103
    $hemisph = ($hemisphLat1 eq "S") ? -1 : 1;
1104
    $doc .= "<northBoundingCoordinate>";
1105
    $doc .= $hemisph * ($latDeg1 + (60*$latMin1+$latSec1)/3600);
1106
    $doc .= "</northBoundingCoordinate>\n";
1107

    
1108
    $hemisph = ($hemisphLat2 eq "S") ? -1 : 1;
1109
    $doc .= "<southBoundingCoordinate>";
1110
    $doc .= $hemisph * ($latDeg2 + (60*$latMin2+$latSec2)/3600);
1111
    $doc .= "</southBoundingCoordinate>\n";
1112

    
1113
    $doc .= "</boundingCoordinates>\n";
1114
    $doc .= "</geographicCoverage>\n";
1115

    
1116
    # Write out the taxonomic coverage fields
1117
    my $foundFirstTaxon = 0;
1118
    foreach my $trn (param()) {
1119
        if ($trn =~ /taxonRankName/) {
1120
            my $taxIndex = $trn;
1121
            $taxIndex =~ s/taxonRankName//; # get the index of the parameter 0, ..., 10
1122
            my $trv = "taxonRankValue".$taxIndex;
1123
            if ( $taxIndex =~ /[0-9]/ ){
1124
                if (hasContent(param($trn)) && hasContent(param($trv))) {
1125
                    if (! $foundFirstTaxon) {
1126
                        $doc .= "<taxonomicCoverage>\n";
1127
                        $foundFirstTaxon = 1;
1128
                        if (hasContent($FORM::taxaAuth)) {
1129
                            $doc .= "<generalTaxonomicCoverage>".$FORM::taxaAuth."</generalTaxonomicCoverage>\n";
1130
                        }
1131
                    }
1132
                    $doc .= "<taxonomicClassification>\n";
1133
                    $doc .= "  <taxonRankName>".param($trn)."</taxonRankName>\n";
1134
                    $doc .= "  <taxonRankValue>".param($trv)."</taxonRankValue>\n";
1135
                    $doc .= "</taxonomicClassification>\n";
1136
                }
1137
            }
1138
        }
1139
    }
1140
    if ($foundFirstTaxon) {
1141
        $doc .= "</taxonomicCoverage>\n";
1142
    }
1143

    
1144
    $doc .= "</coverage>\n";
1145

    
1146
    $doc .= $cont;
1147
    $doc .= $publ;
1148
    
1149
    if ((hasContent($FORM::methodTitle)) || scalar(@FORM::methodsPara) > 0) {
1150
        my $methods = "<methods><methodStep><description><section>\n";
1151
        if (hasContent($FORM::methodTitle)) {
1152
            $methods .= "<title>$FORM::methodTitle</title>\n";
1153
        }
1154
        for (my $i = 0; $i < scalar(@FORM::methodPara); $i++) {
1155
            $methods .= "<para>$FORM::methodPara[$i]</para>\n";
1156
        }
1157
        $methods .= "</section></description></methodStep>\n";
1158
        if (hasContent($FORM::studyExtentDescription)) {
1159
            $methods .= "<sampling><studyExtent><description>\n";
1160
            $methods .= "<para>$FORM::studyExtentDescription</para>\n";
1161
            $methods .= "</description></studyExtent>\n";
1162
            $methods .= "<samplingDescription>\n";
1163
            $methods .= "<para>$FORM::samplingDescription</para>\n";
1164
            $methods .= "</samplingDescription>\n";
1165
            $methods .= "</sampling>\n";
1166
        }
1167
        $methods .= "</methods>\n";
1168
        $doc .= $methods;
1169
    }
1170

    
1171
    $doc .= "<access authSystem=\"knb\" order=\"denyFirst\">\n";
1172
    $doc .= "<allow>\n";
1173
    $doc .= "<principal>uid=obfsadmin,o=LTER,dc=ecoinformatics,dc=org</principal>\n";
1174
    $doc .= "<permission>all</permission>\n";
1175
    $doc .= "</allow>\n";
1176
    $doc .= "<allow>\n";
1177
    $doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n";
1178
    $doc .= "<permission>all</permission>\n";
1179
    $doc .= "</allow>\n";
1180
    $doc .= "<allow>\n";
1181
    $doc .= "<principal>public</principal>\n";
1182
    $doc .= "<permission>read</permission>\n";
1183
    $doc .= "</allow>\n";
1184
    $doc .= "</access>\n";
1185
    
1186
    $doc .= "</dataset>\n</eml:eml>\n";
1187

    
1188
    return $doc;
1189
}
1190

    
1191

    
1192
################################################################################
1193
# 
1194
# send an email message notifying the moderator of a new submission 
1195
#
1196
################################################################################
1197
sub sendNotification {
1198
    my $identifier = shift;
1199
    my $mailhost = shift;
1200
    my $sender = shift;
1201
    my $recipient = shift;
1202

    
1203
    my $smtp = Net::SMTP->new($mailhost);
1204
    $smtp->mail($sender);
1205
    $smtp->to($recipient);
1206

    
1207
    my $message = <<"    ENDOFMESSAGE";
1208
    To: $recipient
1209
    From: $sender
1210
    Subject: New data submission
1211
    
1212
    Data was submitted to the data registry.  
1213
    The identifying information for the new data set is:
1214

    
1215
    Identifier: $identifier
1216
    Title: $FORM::title
1217
    Submitter: $FORM::providerGivenName $FORM::providerSurName
1218

    
1219
    Please review the submmission and grant public read access if appropriate.
1220
    Thanks
1221
    
1222
    ENDOFMESSAGE
1223
    $message =~ s/^[ \t\r\f]+//gm;
1224

    
1225
    $smtp->data($message);
1226
    $smtp->quit;
1227
}
1228

    
1229

    
1230
################################################################################
1231
# 
1232
# read the eml document and send back a form with values filled in. 
1233
#
1234
################################################################################
1235
sub modifyData {
1236
    
1237
    # create metacat instance
1238
    my $metacat;
1239
    my $docid = $FORM::docid;
1240
    my $httpMessage;
1241
    my $doc;
1242
    my $xmldoc;
1243
    my $findType;
1244
    my $parser = XML::LibXML->new();
1245
    my @fileArray;
1246
    my $pushDoc;
1247
    my $alreadyInArray;
1248
    my $node;
1249
    my $response; 
1250
    my $element;
1251
    my $tempfile;
1252

    
1253
    $metacat = Metacat->new();
1254
    if ($metacat) {
1255
        $metacat->set_options( metacatUrl => $metacatUrl );
1256
    } else {
1257
        #die "failed during metacat creation\n";
1258
        push(@errorMessages, "Failed during metacat creation.");
1259
    }
1260
    
1261
    $httpMessage = $metacat->read($docid);
1262
    $doc = $httpMessage->content();
1263
    $xmldoc = $parser->parse_string($doc);
1264

    
1265
    #$tempfile = $xslConvDir.$docid;
1266
    #push (@fileArray, $tempfile);
1267

    
1268
    if ($xmldoc eq "") {
1269
        $error ="Error in parsing the eml document";
1270
        push(@errorMessages, $error);
1271
    } else {
1272
        $findType = $xmldoc->findnodes('//dataset/identifier');
1273
        if ($findType->size() > 0) {
1274
            # This is a eml beta6 document
1275
            # Read the documents mentioned in triples also
1276
        
1277
            $findType = $xmldoc->findnodes('//dataset/triple');
1278
            if ($findType->size() > 0) {
1279
                foreach $node ($findType->get_nodelist) {
1280
                    $pushDoc = findValue($node, 'subject');
1281
            
1282
                    # If the file is already in @fileArray then do not add it 
1283
                    $alreadyInArray = 0;
1284
                    foreach $element (@fileArray) {
1285
                        $tempfile = $tmpdir."/".$pushDoc;
1286
                        if ($element eq $pushDoc) {
1287
                            $alreadyInArray = 1;
1288
                        }
1289
                    }
1290
            
1291
                    if (!$alreadyInArray) {
1292
                        $tempfile = $tmpdir."/".$pushDoc;
1293
                        $response = "";
1294
                        $response = $metacat->read($pushDoc);    
1295
                        if (! $response) {
1296
                            # could not read
1297
                            #push(@errorMessages, $response);
1298
                            push(@errorMessages, $metacat->getMessage());
1299
                            push(@errorMessages, "Failed during reading.\n");
1300
                        } else {
1301
                            my $xdoc = $response->content();
1302
                            #$tempfile = $xslConvDir.$pushDoc;
1303
                            open (TFILE,">$tempfile") || 
1304
                                die ("Cant open xml file... $tempfile\n");
1305
                            print TFILE $xdoc;
1306
                            close(TFILE);
1307
                            push (@fileArray, $tempfile);
1308
                        }
1309
                    }
1310
                }
1311
            }
1312

    
1313
            # Read the main document. 
1314

    
1315
            $tempfile = $tmpdir."/".$docid; #= $xslConvDir.$docid;
1316
            open (TFILE,">$tempfile") || die ("Cant open xml file...\n");
1317
            print TFILE $doc;
1318
            close(TFILE);
1319
        
1320
            # Transforming beta6 to eml 2
1321
            my $xslt;
1322
            my $triplesheet;
1323
            my $results;
1324
            my $stylesheet;
1325
            my $resultsheet;
1326
        
1327
            $xslt = XML::LibXSLT->new();
1328
            #$tempfile = $xslConvDir."triple_info.xsl";
1329
            $tempfile = $tmpdir."/"."triple_info.xsl";
1330
    
1331
            $triplesheet = $xslt->parse_stylesheet_file($tempfile);
1332

    
1333
            #$results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1334
            $results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1335

    
1336
            #$tempfile = $xslConvDir."emlb6toeml2.xsl";
1337
            $tempfile = $tmpdir."/"."emlb6toeml2.xsl";
1338
            $stylesheet = $xslt->parse_stylesheet_file($tempfile);
1339
            $resultsheet = $stylesheet->transform($results);
1340
        
1341
            #$tempfile = "/usr/local/apache2/htdocs/xml/test.xml";;
1342
            #open (TFILE,">$tempfile") || die ("Cant open xml file...\n");
1343
            #print TFILE $stylesheet->output_string($resultsheet);
1344
            #close(TFILE);
1345

    
1346
            getFormValuesFromEml2($resultsheet);
1347
            
1348
            # Delete the files written earlier. 
1349
            unlink @fileArray;
1350

    
1351
        } else {
1352
            getFormValuesFromEml2($xmldoc);
1353
        }
1354
    }   
1355
    
1356
    if (scalar(@errorMessages)) {
1357
        # if any errors, print them in the response template 
1358
        $$templateVars{'status'} = 'failure';
1359
        $$templateVars{'errorMessages'} = \@errorMessages;
1360
        $error = 1;
1361
        $$templateVars{'function'} = "modification";
1362
        $$templateVars{'section'} = "Modification Status";
1363
        $template->process( $responseTemplate, $templateVars); 
1364
    } else {
1365
        $$templateVars{'form'} = 're_entry';
1366
        $template->process( $entryFormTemplate, $templateVars);
1367
    }
1368
}
1369

    
1370
################################################################################
1371
# 
1372
# Parse an EML 2.0.0 file and extract the metadata into perl variables for 
1373
# processing and returning to the template processor
1374
#
1375
################################################################################
1376
sub getFormValuesFromEml2 {
1377
    
1378
    my $doc = shift;
1379
    my $results;
1380
    my $error;
1381
    my $node;
1382
    my $tempResult;
1383
    my $tempNode;
1384
    my $aoCount = 1;
1385
    my $foundDSO;
1386

    
1387
    # find out the tag <alternateIdentifier>. 
1388
    $results = $doc->findnodes('//dataset/alternateIdentifier');
1389
    if ($results->size() > 1) {
1390
        errMoreThanOne("alternateIdentifier");
1391
    } else {
1392
        foreach $node ($results->get_nodelist) {
1393
            $$templateVars{'identifier'} = findValue($node, '../alternateIdentifier');
1394
        }
1395
    }
1396

    
1397
    # find out the tag <title>. 
1398
    $results = $doc->findnodes('//dataset/title');
1399
    if ($results->size() > 1) {
1400
        errMoreThanOne("title");
1401
    } elsif ($results->size() < 1) {
1402
        $error ="Following tag not found: title. Please use Morpho to edit this document";
1403
        push(@errorMessages, $error."\n");
1404
        #if ($DEBUG == 1){ print $error;}
1405
    } else {
1406
        foreach $node ($results->get_nodelist) {
1407
            $$templateVars{'title'} = findValue($node, '../title');
1408
        }
1409
    }
1410

    
1411
    # find out the tag <creator>. 
1412
    $results = $doc->findnodes('//dataset/creator/individualName');
1413
    debug("Registry: Creators: ".$results->size());
1414
    if ($results->size() > 11) {
1415
        errMoreThanN("creator/individualName");
1416
    } else {
1417
        foreach $node ($results->get_nodelist) {
1418
            dontOccur($node, "../positionName|../onlineURL|../userId", 
1419
              "positionName, onlineURL, userId");
1420
        
1421
            dontOccur($node, "./saluation", "saluation");                
1422
        
1423
            debug("Registry: Checking a creator in loop 1...");
1424
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1425
            if($tempResult->size > 0) {
1426
                if($foundDSO == 0) {
1427
                    $foundDSO = 1;
1428
     
1429
                    debug("Registry: Recording a creator in loop 1...");
1430
                    $$templateVars{'origNamefirst0'} = findValue($node, 'givenName');
1431
                    $$templateVars{'origNamelast0'} = findValue($node, 'surName');
1432
            
1433
                    my $tempResult2 = $node->findnodes('../address');
1434
                    if ($tempResult2->size > 1) {
1435
                        errMoreThanOne("address");
1436
                    } else {
1437
                        foreach my $tempNode2 ($tempResult2->get_nodelist) {
1438
                            $$templateVars{'origDelivery'} = findValue($tempNode2, 'deliveryPoint');
1439
                            $$templateVars{'origCity'} = findValue($tempNode2, 'city');
1440
                            $$templateVars{'origState'} = findValue($tempNode2, 'administrativeArea');
1441
                            $$templateVars{'origZIP'} = findValue($tempNode2, 'postalCode');
1442
                            $$templateVars{'origCountry'} = findValue($tempNode2, 'country');
1443
                        }
1444
                    }
1445
            
1446
                    my $tempResult3 = $node->findnodes('../phone');
1447
                    if ($tempResult3->size > 2) {
1448
                        errMoreThanN("phone");
1449
                    } else {
1450
                        foreach my $tempNode2 ($tempResult3->get_nodelist) {
1451
                            if ($tempNode2->hasAttributes()) {
1452
                                my @attlist = $tempNode2->attributes();
1453
                                if ($attlist[0]->value eq "Fax") {
1454
                                    $$templateVars{'origFAX'} = $tempNode2->textContent();
1455
                                } else {
1456
                                    $$templateVars{'origPhone'} = $tempNode2->textContent();
1457
                                }
1458
                            } else {
1459
                                $$templateVars{'origPhone'} = $tempNode2->textContent();
1460
                            }
1461
                        }
1462
                    }
1463
                    $$templateVars{'origEmail'} = findValue($node, '../electronicMailAddress');
1464
                    $$templateVars{'origNameOrg'} = findValue($node, '../organizationName');
1465
                } else {
1466
                    errMoreThanN("address, phone and electronicMailAddress");
1467
                }
1468
            }
1469
        }
1470
        foreach $node ($results->get_nodelist) {
1471
            debug("Registry: Checking a creator in loop 2...");
1472
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1473
            if ($tempResult->size == 0) {
1474
                if ($foundDSO == 0) {
1475
                    debug("Registry: Recording a creator in loop 2 block A...");
1476
                    $foundDSO = 1;
1477
                    $$templateVars{'origNamefirst0'} = findValue($node, 'givenName');
1478
                    $$templateVars{'origNamelast0'} = findValue($node, 'surName');
1479
                    $$templateVars{'origNameOrg'} = findValue($node, '../organizationName');
1480
                } else {
1481
                    debug("Registry: Recording a creator in loop 2 block B...");
1482
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($node, './givenName');
1483
                    $$templateVars{"origNamelast$aoCount"} =  findValue($node, './surName');
1484
                    $$templateVars{"origRole$aoCount"} = "Originator";
1485
                    $aoCount++;
1486
                }
1487
            }
1488
        }
1489
    }
1490

    
1491
    $results = $doc->findnodes('//dataset/creator/organizationName');
1492
    my $wgroups = $doc->findnodes("//dataset/creator/organizationName[contains(text(),'(NCEAS ')]");
1493
    debug("Registry: Number Org: ".$results->size());
1494
    debug("Registry:  Number WG: ".$wgroups->size());
1495
    if ($results->size() - $wgroups->size() > 3) {
1496
        errMoreThanN("creator/organizationName");    
1497
    } else {
1498
        foreach $node ($results->get_nodelist) {
1499
            my $tempValue = findValue($node,'../organizationName');
1500
            $tempResult = $node->findnodes('../individualName');
1501
            if ($tempResult->size == 0 && $tempValue ne $organization) {
1502
                $$templateVars{'site'} = $tempValue;
1503
            }
1504
        }
1505
        if ($FORM::cfg == 'nceas') {
1506
            my @wg;
1507
            foreach $node ($results->get_nodelist) {
1508
                my $tempValue = findValue($node,'../organizationName');
1509
                $wg[scalar(@wg)] = $tempValue;
1510
            }
1511
            my $projects = getProjectList();
1512
            $$templateVars{'projects'} = $projects;
1513
            $$templateVars{'wg'} = \@wg;
1514
        }
1515
    }
1516

    
1517
    $results = $doc->findnodes('//dataset/metadataProvider');
1518
    if ($results->size() > 11) {
1519
        errMoreThanN("metadataProvider");    
1520
    } else {
1521
        foreach $node ($results->get_nodelist) {
1522
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1523
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in metadataProvider");
1524
        
1525
            $tempResult = $node->findnodes('./individualName');
1526
            if ($tempResult->size > 1) {
1527
                errMoreThanOne("metadataProvider/indvidualName");
1528
            } else {
1529
                foreach $tempNode ($tempResult->get_nodelist) {
1530
                    if ($$templateVars{'providerGivenName'} ne "") {
1531
                        $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1532
                        $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1533
                        $$templateVars{"origRole$aoCount"} = "Metadata Provider";
1534
                        $aoCount++;
1535
                    } else {
1536
                        $$templateVars{'providerGivenName'} =  findValue($tempNode, './givenName');
1537
                        $$templateVars{'providerSurName'} =  findValue($tempNode, './surName');
1538
                    }
1539
                }
1540
            }
1541
        }
1542
    }
1543

    
1544
    $results = $doc->findnodes('//dataset/associatedParty');
1545
    if ($results->size() > 10) {
1546
        errMoreThanN("associatedParty");
1547
    } else {
1548
        foreach $node ($results->get_nodelist) {
1549
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1550
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty");
1551
       
1552
            $tempResult = $node->findnodes('./individualName');
1553
            if ($tempResult->size > 1) {
1554
                errMoreThanOne("associatedParty/indvidualName");
1555
            } else {
1556
                foreach $tempNode ($tempResult->get_nodelist) {
1557
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1558
                    $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1559
                    $$templateVars{"origRole$aoCount"} = findValue($tempNode, '../role');
1560
                    $aoCount++;           
1561
                }
1562
            }
1563
        }
1564
    }
1565

    
1566
    $results = $doc->findnodes('//dataset/publisher');
1567
    if ($results->size() > 10) {
1568
        errMoreThanN("publisher");
1569
    } else {
1570
        foreach $node ($results->get_nodelist) {
1571
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1572
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty");
1573
       
1574
            $tempResult = $node->findnodes('./individualName');
1575
            if ($tempResult->size > 1) {
1576
                errMoreThanOne("publisher/indvidualName");
1577
            } else {
1578
                foreach $tempNode ($tempResult->get_nodelist) {
1579
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1580
                    $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1581
                    $$templateVars{"origRole$aoCount"} = "Publisher";
1582
                    $aoCount++;           
1583
                }
1584
            }
1585
        }
1586
    }
1587

    
1588
    if ($aoCount > 11) {
1589
        errMoreThanN("Additional Originators");
1590
    } 
1591

    
1592
    dontOccur($doc, "./pubDate", "pubDate");
1593
    dontOccur($doc, "./language", "language");
1594
    dontOccur($doc, "./series", "series");
1595

    
1596
    $results = $doc->findnodes('//dataset/abstract');
1597
    if ($results->size() > 1) {
1598
        errMoreThanOne("abstract");
1599
    } else {
1600
        foreach my $node ($results->get_nodelist) {
1601
            dontOccur($node, "./section", "section");
1602
            $$templateVars{'abstract'} = findValueNoChild($node, "para");
1603
        }
1604
    }
1605

    
1606
    $results = $doc->findnodes('//dataset/keywordSet');
1607
    if ($results->size() > 10) {
1608
        errMoreThanN("keywordSet");
1609
    } else {
1610
        my $count = 0;
1611
        foreach $node ($results->get_nodelist) {
1612
            $tempResult = $node->findnodes('./keyword');
1613
            if ($tempResult->size() > 1) {
1614
                errMoreThanOne("keyword");
1615
            } else {
1616
                foreach $tempNode ($tempResult->get_nodelist) {
1617
                    $$templateVars{"keyword$count"} = $tempNode->textContent();
1618
                    if ($tempNode->hasAttributes()) {
1619
                        my @attlist = $tempNode->attributes();
1620
                        $$templateVars{"kwType$count"} = $attlist[0]->value;
1621
                    }  
1622
                 } 
1623
            }
1624
            $$templateVars{"kwTh$count"} = findValue($node, "keywordThesaurus");
1625
            $count++;
1626
        }
1627
    
1628
        while ($count<11) {
1629
            $$templateVars{"kwType$count"} = "none";
1630
            $$templateVars{"kwTh$count"} = "none";
1631
            $count++;
1632
        }
1633
    }
1634

    
1635
    $results = $doc->findnodes('//dataset/additionalInfo');
1636
    if ($results->size() > 1) {
1637
        errMoreThanOne("additionalInfo");
1638
    } else {
1639
        foreach $node ($results->get_nodelist) {
1640
            dontOccur($node, "./section", "section");
1641
            $$templateVars{'addComments'} = findValueNoChild($node, "para");
1642
        }
1643
    }
1644

    
1645
    $$templateVars{'useConstraints'} = "";
1646
    $results = $doc->findnodes('//dataset/intellectualRights');
1647
    if ($results->size() > 1) {
1648
        errMoreThanOne("intellectualRights");
1649
    } else {
1650
        foreach $node ($results->get_nodelist) {
1651
            dontOccur($node, "./section", "section in intellectualRights");
1652

    
1653
            $tempResult = $node->findnodes("para");
1654
            if ($tempResult->size > 2) {
1655
                   errMoreThanN("para");
1656
            } else {
1657
                foreach $tempNode ($tempResult->get_nodelist) {
1658
                    my $childNodes = $tempNode->childNodes;
1659
                    if ($childNodes->size() > 1) {
1660
                        $error ="The tag para in intellectualRights has children which cannot be shown using the form. Please use Morpho to edit this document";    
1661
                        push(@errorMessages, $error);
1662
                        #if ($DEBUG == 1){ print $error."\n";}
1663
                    } else {
1664
                        #print $tempNode->nodeName().":".$tempNode->textContent();
1665
                        #print "\n";
1666
                        if ($$templateVars{'useConstraints'} eq "") {
1667
                            $$templateVars{'useConstraints'} = $tempNode->textContent();
1668
                        } else {
1669
                            $$templateVars{'useConstraintsOther'} = $tempNode->textContent();
1670
                        }
1671
                    }
1672
                }
1673
            }
1674
        }
1675
    }
1676

    
1677
    $results = $doc->findnodes('//dataset/distribution/online');
1678
    if ($results->size() > 1) {
1679
        errMoreThanOne("distribution/online");
1680
    } else {
1681
        foreach my $tempNode ($results->get_nodelist){
1682
            $$templateVars{'url'} = findValue($tempNode, "url");
1683
            dontOccur($tempNode, "./connection", "/distribution/online/connection");
1684
            dontOccur($tempNode, "./connectionDefinition", "/distribution/online/connectionDefinition");
1685
        }
1686
    }
1687

    
1688
    $results = $doc->findnodes('//dataset/distribution/offline');
1689
    if ($results->size() > 1) {
1690
        errMoreThanOne("distribution/online");
1691
    } else {
1692
        foreach my $tempNode ($results->get_nodelist) {
1693
            $$templateVars{'dataMedium'} = findValue($tempNode, "mediumName");
1694
            dontOccur($tempNode, "./mediumDensity", "/distribution/offline/mediumDensity");
1695
            dontOccur($tempNode, "./mediumDensityUnits", "/distribution/offline/mediumDensityUnits");
1696
            dontOccur($tempNode, "./mediumVolume", "/distribution/offline/mediumVolume");
1697
            dontOccur($tempNode, "./mediumFormat", "/distribution/offline/mediumFormat");
1698
            dontOccur($tempNode, "./mediumNote", "/distribution/offline/mediumNote");
1699
        }
1700
    }
1701

    
1702
    dontOccur($doc, "./inline", "//dataset/distribution/inline");
1703

    
1704
    $results = $doc->findnodes('//dataset/coverage');
1705
    if ($results->size() > 1) {
1706
        errMoreThanOne("coverage");
1707
    } else {
1708
        foreach $node ($results->get_nodelist) {
1709
            dontOccur($node, "./temporalCoverage/rangeOfDates/beginDate/time|./temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale|./temporalCoverage/rangeOfDates/endDate/time|./temporalCoverage/rangeOfDates/endDate/alternativeTimeScale|./taxonomicCoverage/taxonomicSystem|./taxonomicCoverage/taxonomicClassification/commonName|./taxonomicCoverage/taxonomicClassification/taxonomicClassification|./geographicCoverage/datasetGPolygon|./geographicCoverage/boundingCoordinates/boundingAltitudes", "temporalCoverage/rangeOfDates/beginDate/time, /temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale, /temporalCoverage/rangeOfDates/endDate/time, /temporalCoverage/rangeOfDates/endDate/alternativeTimeScale, /taxonomicCoverage/taxonomicSystem, /taxonomicCoverage/taxonomicClassification/commonName, /taxonomicCoverage/taxonomicClassification/taxonomicClassification, /geographicCoverage/datasetGPolygon, /geographicCoverage/boundingCoordinates/boundingAltitudes");
1710

    
1711
            $tempResult = $node->findnodes('./temporalCoverage');
1712
            if ($tempResult->size > 1) {
1713
                   errMoreThanOne("temporalCoverage");
1714
            } else {
1715
                foreach $tempNode ($tempResult->get_nodelist) {
1716
                    my $x;
1717
                    my $y;
1718
                    my $z;
1719
                    my $tempdate = findValue($tempNode, "rangeOfDates/beginDate/calendarDate");
1720
                    ($x, $y, $z) = split("-", $tempdate); 
1721
                    $$templateVars{'beginningYear'} = $x;
1722
                    $$templateVars{'beginningMonth'} = $y;
1723
                    $$templateVars{'beginningDay'} = $z;
1724
    
1725
                    $tempdate = findValue($tempNode, "rangeOfDates/endDate/calendarDate");
1726
                    ($x, $y, $z) = split("-", $tempdate);
1727
                    $$templateVars{'endingYear'} = $x;
1728
                    $$templateVars{'endingMonth'} = $y;
1729
                    $$templateVars{'endingDay'} = $z;
1730
                
1731
                    $tempdate = "";
1732
                    $tempdate = findValue($tempNode, "singleDateTime/calendarDate");
1733
                    if($tempdate ne ""){
1734
                        ($x, $y, $z) = split("-", $tempdate);
1735
                        $$templateVars{'beginningYear'} = $x;
1736
                        $$templateVars{'beginningMonth'} = $y;
1737
                        $$templateVars{'beginningDay'} = $z;
1738
                    }  
1739
                }
1740
            }
1741

    
1742
            $tempResult = $node->findnodes('./geographicCoverage');
1743
            if ($tempResult->size > 1) {
1744
                errMoreThanOne("geographicCoverage");
1745
            } else {
1746
                foreach $tempNode ($tempResult->get_nodelist) {
1747
                    my $geogdesc = findValue($tempNode, "geographicDescription");
1748
                    debug("Registry: geogdesc from xml is: $geogdesc");
1749
                    $$templateVars{'geogdesc'} = $geogdesc;
1750
                    my $coord = findValue($tempNode, "boundingCoordinates/westBoundingCoordinate");
1751
                    if ($coord > 0) {
1752
                        #print "+";
1753
                        $$templateVars{'hemisphLong1'} = "E";
1754
                    } else {
1755
                        #print "-";
1756
                        eval($coord = $coord * -1);
1757
                        $$templateVars{'hemisphLong1'} = "W";
1758
                    }
1759
                    eval($$templateVars{'longDeg1'} = int($coord));
1760
                    eval($coord = ($coord - int($coord))*60);
1761
                    eval($$templateVars{'longMin1'} = int($coord));
1762
                    eval($coord = ($coord - int($coord))*60);
1763
                    eval($$templateVars{'longSec1'} = int($coord));
1764
                    
1765
                    $coord = findValue($tempNode, "boundingCoordinates/southBoundingCoordinate");
1766
                    if ($coord > 0) {
1767
                        #print "+";
1768
                        $$templateVars{'hemisphLat2'} = "N";
1769
                    } else {
1770
                        #print "-";
1771
                        eval($coord = $coord * -1);
1772
                        $$templateVars{'hemisphLat2'} = "S";
1773
                    }
1774
                    eval($$templateVars{'latDeg2'} = int($coord));
1775
                    eval($coord = ($coord - int($coord))*60);
1776
                    eval($$templateVars{'latMin2'} = int($coord));
1777
                    eval($coord = ($coord - int($coord))*60);
1778
                    eval($$templateVars{'latSec2'} = int($coord));
1779
        
1780
                    $coord = findValue($tempNode, "boundingCoordinates/northBoundingCoordinate");
1781
                    if ($coord > 0) {
1782
                        #print "+";
1783
                        $$templateVars{'hemisphLat1'} = "N";
1784
                    } else {
1785
                        #print "-";
1786
                        eval($coord = $coord * -1);
1787
                        $$templateVars{'hemisphLat1'} = "S";
1788
                    }
1789
                    eval($$templateVars{'latDeg1'} = int($coord));
1790
                    eval($coord = ($coord - int($coord))*60);
1791
                    eval($$templateVars{'latMin1'} = int($coord));
1792
                    eval($coord = ($coord - int($coord))*60);
1793
                    eval($$templateVars{'latSec1'} = int($coord));
1794
        
1795
                    $coord = findValue($tempNode, "boundingCoordinates/eastBoundingCoordinate");
1796
                    if ($coord > 0) {
1797
                        #print "+";
1798
                        $$templateVars{'hemisphLong2'} = "E";
1799
                    } else {
1800
                        #print "-";
1801
                        eval($coord = $coord * -1);
1802
                        $$templateVars{'hemisphLong2'} = "W";
1803
                    }
1804
                    eval($$templateVars{'longDeg2'} = int($coord));
1805
                    eval($coord = ($coord - int($coord))*60);
1806
                    eval($$templateVars{'longMin2'} = int($coord));
1807
                    eval($coord = ($coord - int($coord))*60);
1808
                    eval($$templateVars{'longSec2'} = int($coord));
1809
                }
1810
            }
1811

    
1812
            $tempResult = $node->findnodes('./taxonomicCoverage/taxonomicClassification');
1813
            my $taxonIndex = 0;
1814
            foreach $tempNode ($tempResult->get_nodelist) {
1815
                $taxonIndex++;
1816
                my $taxonRankName = findValue($tempNode, "taxonRankName");
1817
                my $taxonRankValue = findValue($tempNode, "taxonRankValue");
1818
                $$templateVars{"taxonRankName".$taxonIndex} = $taxonRankName;
1819
                $$templateVars{"taxonRankValue".$taxonIndex} = $taxonRankValue;
1820
            }
1821
            $$templateVars{'taxaCount'} = $taxonIndex;
1822
            my $taxaAuth = findValue($node, "./taxonomicCoverage/generalTaxonomicCoverage");
1823
            $$templateVars{'taxaAuth'} = $taxaAuth;
1824
        }
1825
    }
1826
    dontOccur($doc, "./purpose", "purpose");
1827
    dontOccur($doc, "./maintenance", "maintnance");
1828

    
1829
    $results = $doc->findnodes('//dataset/contact/individualName');
1830
    if ($results->size() > 1) {
1831
        errMoreThanOne("contact/individualName");
1832
    } else {
1833
        foreach $node ($results->get_nodelist) {
1834
            dontOccur($node, "../positionName|../onlineURL|../userId", 
1835
              "positionName, onlineURL, userId in contact tag");
1836
            dontOccur($node, "./saluation", "saluation in contact tag");                
1837
        
1838
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1839
            if ($tempResult->size > 0) {
1840
                $$templateVars{'origNamefirstContact'} = findValue($node, 'givenName');
1841
                $$templateVars{'origNamelastContact'} = findValue($node, 'surName');
1842
    
1843
                my $tempResult2 = $node->findnodes('../address');
1844
                if ($tempResult2->size > 1) {
1845
                    errMoreThanOne("address");
1846
                } else {
1847
                    foreach my $tempNode2 ($tempResult2->get_nodelist) {
1848
                        $$templateVars{'origDeliveryContact'} = findValue($tempNode2, 'deliveryPoint');
1849
                        $$templateVars{'origCityContact'} = findValue($tempNode2, 'city');
1850
                        $$templateVars{'origStateContact'} = findValue($tempNode2, 'administrativeArea');
1851
                        $$templateVars{'origZIPContact'} = findValue($tempNode2, 'postalCode');
1852
                        $$templateVars{'origCountryContact'} = findValue($tempNode2, 'country');
1853
                    }
1854
                }
1855
            
1856
                my $tempResult3 = $node->findnodes('../phone');
1857
                if ($tempResult3->size > 2) {
1858
                    errMoreThanN("phone");
1859
                } else {
1860
                    foreach my $tempNode2 ($tempResult3->get_nodelist) {
1861
                        if ($tempNode2->hasAttributes()) {
1862
                            my @attlist = $tempNode2->attributes();
1863
                            if ($attlist[0]->value eq "Fax") {
1864
                                $$templateVars{'origFAXContact'} = $tempNode2->textContent();
1865
                            } else {
1866
                                $$templateVars{'origPhoneContact'} = $tempNode2->textContent();
1867
                            }
1868
                        } else {
1869
                            $$templateVars{'origPhoneContact'} = $tempNode2->textContent();
1870
                        }
1871
                    }
1872
                }
1873
                $$templateVars{'origEmailContact'} = findValue($node, '../electronicMailAddress');
1874
                $$templateVars{'origNameOrgContact'} = findValue($node, '../organizationName');
1875
            } else {
1876
                $$templateVars{'origNamefirstContact'} = findValue($node, 'givenName');
1877
                $$templateVars{'origNamelastContact'} = findValue($node, 'surName');
1878
                $$templateVars{'origNameOrgContact'} = findValue($node, '../organizationName');
1879
            }
1880
        }
1881
    }
1882
    
1883
    $results = $doc->findnodes(
1884
            '//dataset/methods/methodStep/description/section');
1885
    debug("Registry: Number methods: ".$results->size());
1886
    if ($results->size() > 1) {
1887
        errMoreThanN("methods/methodStep/description/section");    
1888
    } else {
1889

    
1890
        my @methodPara;
1891
        foreach $node ($results->get_nodelist) {
1892
            my @children = $node->childNodes;
1893
            for (my $i = 0; $i < scalar(@children); $i++) {
1894
                debug("Registry: Method child loop ($i)");
1895
                my $child = $children[$i];
1896
                if ($child->nodeName eq 'title') {
1897
                    my $title = $child->textContent();
1898
                    debug("Registry: Method title ($title)");
1899
                    $$templateVars{'methodTitle'} = $title;
1900
                } elsif ($child->nodeName eq 'para') {
1901
                    my $para = $child->textContent();
1902
                    debug("Registry: Method para ($para)");
1903
                    $methodPara[scalar(@methodPara)] = $para;
1904
                }
1905
            }
1906
        }
1907
        if (scalar(@methodPara) > 0) {
1908
            $$templateVars{'methodPara'} = \@methodPara;
1909
        }
1910
    }
1911

    
1912
    $results = $doc->findnodes(
1913
            '//dataset/methods/sampling/studyExtent/description/para');
1914
    if ($results->size() > 1) {
1915
        errMoreThanN("methods/sampling/studyExtent/description/para");    
1916
    } else {
1917
        foreach $node ($results->get_nodelist) {
1918
            my $studyExtentDescription = $node->textContent();
1919
            $$templateVars{'studyExtentDescription'} = $studyExtentDescription;
1920
        }
1921
    }
1922

    
1923
    $results = $doc->findnodes(
1924
            '//dataset/methods/sampling/samplingDescription/para');
1925
    if ($results->size() > 1) {
1926
        errMoreThanN("methods/sampling/samplingDescription/para");    
1927
    } else {
1928
        foreach $node ($results->get_nodelist) {
1929
            my $samplingDescription = $node->textContent();
1930
            $$templateVars{'samplingDescription'} = $samplingDescription;
1931
        }
1932
    }
1933

    
1934
    dontOccur($doc, "//methodStep/citation", "methodStep/citation");
1935
    dontOccur($doc, "//methodStep/protocol", "methodStep/protocol");
1936
    dontOccur($doc, "//methodStep/instrumentation", "methodStep/instrumentation");
1937
    dontOccur($doc, "//methodStep/software", "methodStep/software");
1938
    dontOccur($doc, "//methodStep/subStep", "methodStep/subStep");
1939
    dontOccur($doc, "//methodStep/dataSource", "methodStep/dataSource");
1940
    dontOccur($doc, "//methods/qualityControl", "methods/qualityControl");
1941

    
1942
    dontOccur($doc, "//methods/sampling/spatialSamplingUnits", "methods/sampling/spatialSamplingUnits");
1943
    dontOccur($doc, "//methods/sampling/citation", "methods/sampling/citation");
1944
    dontOccur($doc, "./pubPlace", "pubPlace");
1945
    dontOccur($doc, "./project", "project");
1946
    
1947
    dontOccur($doc, "./dataTable", "dataTable");
1948
    dontOccur($doc, "./spatialRaster", "spatialRaster");
1949
    dontOccur($doc, "./spatialVector", "spatialVector");
1950
    dontOccur($doc, "./storedProcedure", "storedProcedure");
1951
    dontOccur($doc, "./view", "view");
1952
    dontOccur($doc, "./otherEntity", "otherEntity");
1953
    dontOccur($doc, "./references", "references");
1954
    
1955
    dontOccur($doc, "//citation", "citation");
1956
    dontOccur($doc, "//software", "software");
1957
    dontOccur($doc, "//protocol", "protocol");
1958
    dontOccur($doc, "//additionalMetadata", "additionalMetadata");    
1959
}
1960

    
1961
################################################################################
1962
# 
1963
# Delete the eml file that has been requested for deletion. 
1964
#
1965
################################################################################
1966
sub deleteData {
1967
    my $deleteAll = shift;
1968
    
1969
    # create metacat instance
1970
    my $metacat;
1971
    my $docid = $FORM::docid;
1972
    
1973
    $metacat = Metacat->new();
1974
    if ($metacat) {
1975
        $metacat->set_options( metacatUrl => $metacatUrl );
1976
    } else {
1977
        #die "failed during metacat creation\n";
1978
        push(@errorMessages, "Failed during metacat creation.");
1979
    }
1980

    
1981
    # Login to metacat
1982
    my $userDN = $FORM::username;
1983
    my $userOrg = $FORM::organization;
1984
    my $userPass = $FORM::password;
1985
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
1986
    
1987
    my $errorMessage = "";
1988
    my $response = $metacat->login($dname, $userPass);
1989

    
1990
    if (! $response) {
1991
    # Could not login
1992
        push(@errorMessages, $metacat->getMessage());
1993
        push(@errorMessages, "Failed during login.\n");
1994

    
1995
    } else {
1996
    #Able to login - try to delete the file    
1997

    
1998
    my $parser;
1999
    my @fileArray;
2000
    my $httpMessage;
2001
    my $xmldoc;
2002
    my $doc;
2003
    my $pushDoc;
2004
    my $alreadyInArray;
2005
    my $findType;
2006
        my $node;
2007
    my $response; 
2008
    my $element;
2009

    
2010
    push (@fileArray, $docid);
2011
    $parser = XML::LibXML->new();
2012

    
2013
        $httpMessage = $metacat->read($docid);
2014
    $doc = $httpMessage->content();    
2015
    $xmldoc = $parser->parse_string($doc);
2016

    
2017
    if ($xmldoc eq "") {
2018
        $error ="Error in parsing the eml document";
2019
        push(@errorMessages, $error);
2020
    } else {
2021

    
2022
        $findType = $xmldoc->findnodes('//dataset/identifier');
2023
        if($findType->size() > 0){
2024
        # This is a eml beta6 document
2025
        # Delete the documents mentioned in triples also
2026
        
2027
        $findType = $xmldoc->findnodes('//dataset/triple');
2028
        if($findType->size() > 0){
2029
            foreach $node ($findType->get_nodelist){
2030
            $pushDoc = findValue($node, 'subject');
2031
            
2032
            # If the file is already in the @fileArray then do not add it 
2033
            $alreadyInArray = 0;
2034
            foreach $element (@fileArray){
2035
                if($element eq $pushDoc){
2036
                $alreadyInArray = 1;
2037
                }
2038
            }
2039
            
2040
            if(!$alreadyInArray){
2041
                # If not already in array then delete the file. 
2042
                push (@fileArray, $pushDoc);
2043
                $response = $metacat->delete($pushDoc);
2044
                
2045
                if (! $response) {
2046
                # Could not delete
2047
                #push(@errorMessages, $response);
2048
                push(@errorMessages, $metacat->getMessage());
2049
                push(@errorMessages, "Failed during deleting $pushDoc. Please check if you are authorized to delete this document.\n");
2050
                }
2051
            }
2052
            }
2053
        }
2054
        }
2055
    }
2056
    
2057
    # Delete the main document. 
2058
    if($deleteAll){
2059
        $response = $metacat->delete($docid);  
2060
        if (! $response) {
2061
        # Could not delete
2062
        #push(@errorMessages, $response);
2063
        push(@errorMessages, $metacat->getMessage());
2064
        push(@errorMessages, "Failed during deleting $docid. Please check if you are authorized to delete this document.\n");
2065
        }
2066
    }
2067
    }
2068
    
2069
    if (scalar(@errorMessages)) {
2070
    # If any errors, print them in the response template 
2071
    $$templateVars{'status'} = 'failure';
2072
    $$templateVars{'errorMessages'} = \@errorMessages;
2073
    $error = 1;
2074
    }
2075
    
2076
    # Process the response template
2077
    if($deleteAll){
2078

    
2079
    $$templateVars{'function'} = "deleted";
2080
    $$templateVars{'section'} = "Deletion Status";
2081
    $template->process( $responseTemplate, $templateVars);
2082
    }
2083
}
2084

    
2085

    
2086
################################################################################
2087
# 
2088
# Do data validation and send the data to confirm data template.
2089
#
2090
################################################################################
2091
sub toConfirmData{
2092
    # Check if any invalid parameters
2093
 
2094
    my $invalidParams;
2095
    if (! $error) {
2096
    $invalidParams = validateParameters(0);
2097
    if (scalar(@$invalidParams)) {
2098
        $$templateVars{'status'} = 'failure';
2099
        $$templateVars{'invalidParams'} = $invalidParams;
2100
        $error = 1;
2101
    }
2102
    }
2103

    
2104
    if (! $error) {
2105
    # If no errors, then print out data in confirm Data template
2106

    
2107
    $$templateVars{'providerGivenName'} = $FORM::providerGivenName;
2108
    $$templateVars{'providerSurName'} = $FORM::providerSurName;
2109
    if($FORM::site eq "Select your station here."){
2110
        $$templateVars{'site'} = "";
2111
    }else{
2112
        $$templateVars{'site'} = $FORM::site;
2113
    }
2114
    if($FORM::cfg eq "nceas"){
2115
        $$templateVars{'wg'} = \@FORM::wg;
2116
    }
2117
    $$templateVars{'identifier'} = $FORM::identifier;
2118
    $$templateVars{'title'} = $FORM::title;
2119
    $$templateVars{'origNamefirst0'} = $FORM::origNamefirst0;
2120
    $$templateVars{'origNamelast0'} = $FORM::origNamelast0;
2121
    $$templateVars{'origNameOrg'} = $FORM::origNameOrg;
2122
    # $$templateVars{'origRole0'} = $FORM::origRole0;
2123
    $$templateVars{'origDelivery'} = $FORM::origDelivery;
2124
    $$templateVars{'origCity'} = $FORM::origCity;
2125
    if($FORM::origState eq "Select State Here."){
2126
        $$templateVars{'origState'} = "";
2127
    }else{
2128
        $$templateVars{'origState'} = $FORM::origState;
2129
    }
2130
    $$templateVars{'origStateOther'} = $FORM::origStateOther;
2131
    $$templateVars{'origZIP'} = $FORM::origZIP;
2132
    $$templateVars{'origCountry'} = $FORM::origCountry;
2133
    $$templateVars{'origPhone'} = $FORM::origPhone;
2134
    $$templateVars{'origFAX'} = $FORM::origFAX;
2135
    $$templateVars{'origEmail'} = $FORM::origEmail;
2136
    $$templateVars{'useOrigAddress'} = $FORM::useOrigAddress;
2137
    if($FORM::useOrigAddress eq "on"){
2138
        $$templateVars{'origNamefirstContact'} = $FORM::origNamefirst0;
2139
        $$templateVars{'origNamelastContact'} = $FORM::origNamelast0;
2140
        $$templateVars{'origNameOrgContact'} = $FORM::origNameOrg;
2141
        $$templateVars{'origDeliveryContact'} = $FORM::origDelivery; 
2142
        $$templateVars{'origCityContact'} = $FORM::origCity;
2143
        if($FORM::origState eq "Select State Here."){
2144
        $$templateVars{'origStateContact'} = "";
2145
        }else{
2146
        $$templateVars{'origStateContact'} = $FORM::origState;
2147
        }
2148
        $$templateVars{'origStateOtherContact'} = $FORM::origStateOther;
2149
        $$templateVars{'origZIPContact'} = $FORM::origZIP;
2150
        $$templateVars{'origCountryContact'} = $FORM::origCountry;
2151
        $$templateVars{'origPhoneContact'} = $FORM::origPhone;
2152
        $$templateVars{'origFAXContact'} = $FORM::origFAX;
2153
        $$templateVars{'origEmailContact'} = $FORM::origEmail;
2154
    }else{
2155
        $$templateVars{'origNamefirstContact'} = $FORM::origNamefirstContact;
2156
        $$templateVars{'origNamelastContact'} = $FORM::origNamelastContact;
2157
        $$templateVars{'origNameOrgContact'} = $FORM::origNameOrgContact;
2158
        $$templateVars{'origDeliveryContact'} = $FORM::origDeliveryContact; 
2159
        $$templateVars{'origCityContact'} = $FORM::origCityContact;
2160
        if($FORM::origStateContact eq "Select State Here."){
2161
        $$templateVars{'origStateContact'} = "";
2162
        }else{
2163
        $$templateVars{'origStateContact'} = $FORM::origStateContact;
2164
        }
2165
        $$templateVars{'origStateOtherContact'} = $FORM::origStateOtherContact;
2166
        $$templateVars{'origZIPContact'} = $FORM::origZIPContact;
2167
        $$templateVars{'origCountryContact'} = $FORM::origCountryContact;
2168
        $$templateVars{'origPhoneContact'} = $FORM::origPhoneContact;
2169
        $$templateVars{'origFAXContact'} = $FORM::origFAXContact;
2170
        $$templateVars{'origEmailContact'} = $FORM::origEmailContact;    
2171
    }
2172
    $$templateVars{'origNamefirst1'} = $FORM::origNamefirst1;
2173
    $$templateVars{'origNamelast1'} = $FORM::origNamelast1;
2174
    if($FORM::origNamefirst1 eq "" && $FORM::origNamelast1 eq ""){
2175
        $$templateVars{'origRole1'} = "";
2176
    }else{
2177
        $$templateVars{'origRole1'} = $FORM::origRole1;
2178
    }
2179
    $$templateVars{'origNamefirst2'} = $FORM::origNamefirst2;
2180
    $$templateVars{'origNamelast2'} = $FORM::origNamelast2;
2181
    if($FORM::origNamefirst2 eq "" && $FORM::origNamelast2 eq ""){
2182
        $$templateVars{'origRole2'} = "";
2183
    }else{
2184
        $$templateVars{'origRole2'} = $FORM::origRole2;
2185
    }
2186
    $$templateVars{'origNamefirst3'} = $FORM::origNamefirst3;
2187
    $$templateVars{'origNamelast3'} = $FORM::origNamelast3;
2188
    if($FORM::origNamefirst3 eq "" && $FORM::origNamelast3 eq ""){
2189
        $$templateVars{'origRole3'} = "";
2190
    }else{
2191
        $$templateVars{'origRole3'} = $FORM::origRole3;
2192
    }
2193
    $$templateVars{'origNamefirst4'} = $FORM::origNamefirst4;
2194
    $$templateVars{'origNamelast4'} = $FORM::origNamelast4;
2195
    if($FORM::origNamefirst4 eq "" && $FORM::origNamelast4 eq ""){
2196
        $$templateVars{'origRole4'} = "";
2197
    }else{
2198
        $$templateVars{'origRole4'} = $FORM::origRole4;
2199
    }
2200
    $$templateVars{'origNamefirst5'} = $FORM::origNamefirst5;
2201
    $$templateVars{'origNamelast5'} = $FORM::origNamelast5;
2202
    if($FORM::origNamefirst5 eq "" && $FORM::origNamelast5 eq ""){
2203
        $$templateVars{'origRole5'} = "";
2204
    }else{
2205
        $$templateVars{'origRole5'} = $FORM::origRole5;
2206
    }
2207
    $$templateVars{'origNamefirst6'} = $FORM::origNamefirst6;
2208
    $$templateVars{'origNamelast6'} = $FORM::origNamelast6;
2209
    if($FORM::origNamefirst6 eq "" && $FORM::origNamelast6 eq ""){
2210
        $$templateVars{'origRole6'} = "";
2211
    }else{
2212
        $$templateVars{'origRole6'} = $FORM::origRole6;
2213
    }
2214
    $$templateVars{'origNamefirst7'} = $FORM::origNamefirst7;
2215
    $$templateVars{'origNamelast7'} = $FORM::origNamelast7;
2216
    if($FORM::origNamefirst7 eq "" && $FORM::origNamelast7 eq ""){
2217
        $$templateVars{'origRole7'} = "";
2218
    }else{
2219
        $$templateVars{'origRole7'} = $FORM::origRole7;
2220
    }
2221
    $$templateVars{'origNamefirst8'} = $FORM::origNamefirst8;
2222
    $$templateVars{'origNamelast8'} = $FORM::origNamelast8;
2223
    if($FORM::origNamefirst8 eq "" && $FORM::origNamelast8 eq ""){
2224
        $$templateVars{'origRole8'} = "";
2225
    }else{
2226
        $$templateVars{'origRole8'} = $FORM::origRole8;
2227
    }
2228
    $$templateVars{'origNamefirst9'} = $FORM::origNamefirst9;
2229
    $$templateVars{'origNamelast9'} = $FORM::origNamelast9;
2230
    if($FORM::origNamefirst9 eq "" && $FORM::origNamelast9 eq ""){
2231
        $$templateVars{'origRole9'} = "";
2232
    }else{
2233
        $$templateVars{'origRole9'} = $FORM::origRole9;
2234
    }
2235
    $$templateVars{'origNamefirst10'} = $FORM::origNamefirst10;
2236
    $$templateVars{'origNamelast10'} = $FORM::origNamelast10;
2237
    if($FORM::origNamefirst10 eq "" && $FORM::origNamelast10 eq ""){
2238
        $$templateVars{'origRole10'} = "";
2239
    }else{
2240
        $$templateVars{'origRole10'} = $FORM::origRole10;
2241
    }
2242
    $$templateVars{'abstract'} = $FORM::abstract;
2243
    $$templateVars{'keyword0'} = $FORM::keyword0;
2244
    $$templateVars{'kwType0'} = $FORM::kwType0;
2245
    $$templateVars{'kwTh0'} = $FORM::kwTh0;
2246
    $$templateVars{'kwType1'} = $FORM::kwType1;
2247
    $$templateVars{'keyword1'} = $FORM::keyword1;
2248
    $$templateVars{'kwTh1'} = $FORM::kwTh1;
2249
    $$templateVars{'kwType2'} = $FORM::kwType2;
2250
    $$templateVars{'keyword2'} = $FORM::keyword2;
2251
    $$templateVars{'kwTh2'} = $FORM::kwTh2;
2252
    $$templateVars{'kwType3'} = $FORM::kwType3;
2253
    $$templateVars{'keyword3'} = $FORM::keyword3;
2254
    $$templateVars{'kwTh3'} = $FORM::kwTh3;
2255
    $$templateVars{'kwType4'} = $FORM::kwType4;
2256
    $$templateVars{'keyword4'} = $FORM::keyword4;
2257
    $$templateVars{'kwTh4'} = $FORM::kwTh4;
2258
    $$templateVars{'kwType5'} = $FORM::kwType5;
2259
    $$templateVars{'keyword5'} = $FORM::keyword5;
2260
    $$templateVars{'kwTh5'} = $FORM::kwTh5;
2261
    $$templateVars{'kwType6'} = $FORM::kwType6;
2262
    $$templateVars{'keyword6'} = $FORM::keyword6;
2263
    $$templateVars{'kwTh6'} = $FORM::kwTh6;
2264
    $$templateVars{'kwType7'} = $FORM::kwType7;
2265
    $$templateVars{'keyword7'} = $FORM::keyword7;
2266
    $$templateVars{'kwTh7'} = $FORM::kwTh7;
2267
    $$templateVars{'kwType8'} = $FORM::kwType8;
2268
    $$templateVars{'keyword8'} = $FORM::keyword8;
2269
    $$templateVars{'kwTh8'} = $FORM::kwTh8;
2270
    $$templateVars{'kwType9'} = $FORM::kwType9;
2271
    $$templateVars{'keyword9'} = $FORM::keyword9;
2272
    $$templateVars{'kwTh9'} = $FORM::kwTh9;
2273
    $$templateVars{'addComments'} = $FORM::addComments;
2274
    $$templateVars{'useConstraints'} = $FORM::useConstraints;
2275
    $$templateVars{'useConstraintsOther'} = $FORM::useConstraintsOther;
2276
    $$templateVars{'url'} = $FORM::url;
2277
    if($FORM::dataMedium eq "Select type of medium here."){
2278
        $$templateVars{'dataMedium'} = "";
2279
    }else{
2280
        $$templateVars{'dataMedium'} = $FORM::dataMedium;
2281
    }    
2282
    $$templateVars{'dataMediumOther'} = $FORM::dataMediumOther;
2283
    $$templateVars{'beginningYear'} = $FORM::beginningYear;
2284
    $$templateVars{'beginningMonth'} = $FORM::beginningMonth;
2285
    $$templateVars{'beginningDay'} = $FORM::beginningDay;
2286
    $$templateVars{'endingYear'} = $FORM::endingYear;
2287
    $$templateVars{'endingMonth'} = $FORM::endingMonth;
2288
    $$templateVars{'endingDay'} = $FORM::endingDay;
2289
    $$templateVars{'geogdesc'} = $FORM::geogdesc;
2290
    $$templateVars{'useSiteCoord'} = $FORM::useSiteCoord;
2291
    $$templateVars{'latDeg1'} = $FORM::latDeg1;
2292
    $$templateVars{'latMin1'} = $FORM::latMin1;
2293
    $$templateVars{'latSec1'} = $FORM::latSec1;
2294
    $$templateVars{'hemisphLat1'} = $FORM::hemisphLat1;
2295
    $$templateVars{'longDeg1'} = $FORM::longDeg1;
2296
    $$templateVars{'longMin1'} = $FORM::longMin1;
2297
    $$templateVars{'longSec1'} = $FORM::longSec1;
2298
    $$templateVars{'hemisphLong1'} = $FORM::hemisphLong1;
2299
    $$templateVars{'latDeg2'} = $FORM::latDeg2;
2300
    $$templateVars{'latMin2'} = $FORM::latMin2;
2301
    $$templateVars{'latSec2'} = $FORM::latSec2;
2302
    $$templateVars{'hemisphLat2'} = $FORM::hemisphLat2;
2303
    $$templateVars{'longDeg2'} = $FORM::longDeg2;
2304
    $$templateVars{'longMin2'} = $FORM::longMin2;
2305
    $$templateVars{'longSec2'} = $FORM::longSec2;
2306
    $$templateVars{'hemisphLong2'} = $FORM::hemisphLong2;
2307

    
2308
    $$templateVars{'taxaCount'} = $FORM::taxaCount;
2309
    foreach my $trn (param()) {
2310
        if ($trn =~ /taxonRankName/) {
2311
            my $taxIndex = $trn;
2312
            $taxIndex =~ s/taxonRankName//; # get the index of the parameter 0, ..., 10
2313
            my $trv = "taxonRankValue".$taxIndex;
2314
            if ( $taxIndex =~ /[0-9]/ ){
2315
                if (hasContent(param($trn)) && hasContent(param($trv))) {
2316
                    debug("Registry processing taxon: $trn = ".param($trn)." $trv = ".param($trv));
2317
                    $$templateVars{$trn} = param($trn);
2318
                    $$templateVars{$trv} = param($trv);
2319
                }
2320
            }
2321
        }
2322
    }
2323
    $$templateVars{'taxaAuth'} = $FORM::taxaAuth;
2324

    
2325
    $$templateVars{'methodTitle'} = $FORM::methodTitle;
2326
    $$templateVars{'methodPara'} = \@FORM::methodPara;
2327
    $$templateVars{'studyExtentDescription'} = $FORM::studyExtentDescription;
2328
    $$templateVars{'samplingDescription'} = $FORM::samplingDescription;
2329
    $$templateVars{'docid'} = $FORM::docid;
2330

    
2331
    $$templateVars{'section'} = "Confirm Data";
2332
    $template->process( $confirmDataTemplate, $templateVars);
2333

    
2334
    } else{    
2335
    # Errors from validation function. print the errors out using the response template
2336
    if (scalar(@errorMessages)) {
2337
        $$templateVars{'status'} = 'failure';
2338
        $$templateVars{'errorMessages'} = \@errorMessages;
2339
        $error = 1;
2340
    }
2341
        # Create our HTML response and send it back
2342
    $$templateVars{'function'} = "submitted";
2343
    $$templateVars{'section'} = "Submission Status";
2344
    $template->process( $responseTemplate, $templateVars);
2345
    }
2346
}
2347

    
2348

    
2349
################################################################################
2350
# 
2351
# From confirm Data template - user wants to make some changes.
2352
#
2353
################################################################################
2354
sub confirmDataToReEntryData{
2355
    my @sortedSites;
2356
    foreach my $site (sort @sitelist) {
2357
        push(@sortedSites, $site);
2358
    }
2359

    
2360
    $$templateVars{'siteList'} = \@sortedSites;
2361
    $$templateVars{'section'} = "Re-Entry Form";
2362

    
2363
    $$templateVars{'providerGivenName'} = $FORM::providerGivenName;
2364
    $$templateVars{'providerSurName'} = $FORM::providerSurName;
2365
    $$templateVars{'site'} = $FORM::site;
2366
    if ($FORM::cfg eq "nceas") {
2367
        my $projects = getProjectList();
2368
        $$templateVars{'projects'} = $projects;
2369
        $$templateVars{'wg'} = \@FORM::wg;
2370
    }
2371
    $$templateVars{'identifier'} = $FORM::identifier;
2372
    $$templateVars{'title'} = $FORM::title;
2373
    $$templateVars{'origNamefirst0'} = $FORM::origNamefirst0;
2374
    $$templateVars{'origNamelast0'} = $FORM::origNamelast0;
2375
    $$templateVars{'origNameOrg'} = $FORM::origNameOrg;
2376
 #   $$templateVars{'origRole0'} = $FORM::origRole0;
2377
    $$templateVars{'origDelivery'} = $FORM::origDelivery;
2378
    $$templateVars{'origCity'} = $FORM::origCity;
2379
    $$templateVars{'origState'} = $FORM::origState;
2380
    $$templateVars{'origStateOther'} = $FORM::origStateOther;
2381
    $$templateVars{'origZIP'} = $FORM::origZIP;
2382
    $$templateVars{'origCountry'} = $FORM::origCountry;
2383
    $$templateVars{'origPhone'} = $FORM::origPhone;
2384
    $$templateVars{'origFAX'} = $FORM::origFAX;
2385
    $$templateVars{'origEmail'} = $FORM::origEmail;
2386
    if ($FORM::useSiteCoord ne "") {
2387
        $$templateVars{'useOrigAddress'} = "CHECKED";
2388
    }else{
2389
        $$templateVars{'useOrigAddress'} = $FORM::useOrigAddress;
2390
    }
2391
    $$templateVars{'origNamefirstContact'} = $FORM::origNamefirstContact;
2392
    $$templateVars{'origNamelastContact'} = $FORM::origNamelastContact;
2393
    $$templateVars{'origNameOrgContact'} = $FORM::origNameOrgContact;
2394
    $$templateVars{'origDeliveryContact'} = $FORM::origDeliveryContact; 
2395
    $$templateVars{'origCityContact'} = $FORM::origCityContact;
2396
    $$templateVars{'origStateContact'} = $FORM::origStateContact;
2397
    $$templateVars{'origStateOtherContact'} = $FORM::origStateOtherContact;
2398
    $$templateVars{'origZIPContact'} = $FORM::origZIPContact;
2399
    $$templateVars{'origCountryContact'} = $FORM::origCountryContact;
2400
    $$templateVars{'origPhoneContact'} = $FORM::origPhoneContact;
2401
    $$templateVars{'origFAXContact'} = $FORM::origFAXContact;
2402
    $$templateVars{'origEmailContact'} = $FORM::origEmailContact;    
2403
    $$templateVars{'origNamefirst1'} = $FORM::origNamefirst1;
2404
    $$templateVars{'origNamelast1'} = $FORM::origNamelast1;
2405
    $$templateVars{'origRole1'} = $FORM::origRole1;
2406
    $$templateVars{'origNamefirst2'} = $FORM::origNamefirst2;
2407
    $$templateVars{'origNamelast2'} = $FORM::origNamelast2;
2408
    $$templateVars{'origRole2'} = $FORM::origRole2;
2409
    $$templateVars{'origNamefirst3'} = $FORM::origNamefirst3;
2410
    $$templateVars{'origNamelast3'} = $FORM::origNamelast3;
2411
    $$templateVars{'origRole3'} = $FORM::origRole3;
2412
    $$templateVars{'origNamefirst4'} = $FORM::origNamefirst4;
2413
    $$templateVars{'origNamelast4'} = $FORM::origNamelast4;
2414
    $$templateVars{'origRole4'} = $FORM::origRole4;
2415
    $$templateVars{'origNamefirst5'} = $FORM::origNamefirst5;
2416
    $$templateVars{'origNamelast5'} = $FORM::origNamelast5;
2417
    $$templateVars{'origRole5'} = $FORM::origRole5;
2418
    $$templateVars{'origNamefirst6'} = $FORM::origNamefirst6;
2419
    $$templateVars{'origNamelast6'} = $FORM::origNamelast6;
2420
    $$templateVars{'origRole6'} = $FORM::origRole6;
2421
    $$templateVars{'origNamefirst7'} = $FORM::origNamefirst7;
2422
    $$templateVars{'origNamelast7'} = $FORM::origNamelast7;
2423
    $$templateVars{'origRole7'} = $FORM::origRole7;
2424
    $$templateVars{'origNamefirst8'} = $FORM::origNamefirst8;
2425
    $$templateVars{'origNamelast8'} = $FORM::origNamelast8;
2426
    $$templateVars{'origRole8'} = $FORM::origRole8;
2427
    $$templateVars{'origNamefirst9'} = $FORM::origNamefirst9;
2428
    $$templateVars{'origNamelast9'} = $FORM::origNamelast9;
2429
    $$templateVars{'origRole9'} = $FORM::origRole9;
2430
    $$templateVars{'origNamefirst10'} = $FORM::origNamefirst10;
2431
    $$templateVars{'origNamelast10'} = $FORM::origNamelast10;
2432
    $$templateVars{'origRole10'} = $FORM::origRole10;
2433
    $$templateVars{'abstract'} = $FORM::abstract;
2434
    $$templateVars{'keyword0'} = $FORM::keyword0;
2435
    $$templateVars{'kwType0'} = $FORM::kwType0;
2436
    $$templateVars{'kwTh0'} = $FORM::kwTh0;
2437
    $$templateVars{'kwType1'} = $FORM::kwType1;
2438
    $$templateVars{'keyword1'} = $FORM::keyword1;
2439
    $$templateVars{'kwTh1'} = $FORM::kwTh1;
2440
    $$templateVars{'kwType2'} = $FORM::kwType2;
2441
    $$templateVars{'keyword2'} = $FORM::keyword2;
2442
    $$templateVars{'kwTh2'} = $FORM::kwTh2;
2443
    $$templateVars{'kwType3'} = $FORM::kwType3;
2444
    $$templateVars{'keyword3'} = $FORM::keyword3;
2445
    $$templateVars{'kwTh3'} = $FORM::kwTh3;
2446
    $$templateVars{'kwType4'} = $FORM::kwType4;
2447
    $$templateVars{'keyword4'} = $FORM::keyword4;
2448
    $$templateVars{'kwTh4'} = $FORM::kwTh4;
2449
    $$templateVars{'kwType5'} = $FORM::kwType5;
2450
    $$templateVars{'keyword5'} = $FORM::keyword5;
2451
    $$templateVars{'kwTh5'} = $FORM::kwTh5;
2452
    $$templateVars{'kwType6'} = $FORM::kwType6;
2453
    $$templateVars{'keyword6'} = $FORM::keyword6;
2454
    $$templateVars{'kwTh6'} = $FORM::kwTh6;
2455
    $$templateVars{'kwType7'} = $FORM::kwType7;
2456
    $$templateVars{'keyword7'} = $FORM::keyword7;
2457
    $$templateVars{'kwTh7'} = $FORM::kwTh7;
2458
    $$templateVars{'kwType8'} = $FORM::kwType8;
2459
    $$templateVars{'keyword8'} = $FORM::keyword8;
2460
    $$templateVars{'kwTh8'} = $FORM::kwTh8;
2461
    $$templateVars{'kwType9'} = $FORM::kwType9;
2462
    $$templateVars{'keyword9'} = $FORM::keyword9;
2463
    $$templateVars{'kwTh9'} = $FORM::kwTh9;
2464
    $$templateVars{'addComments'} = $FORM::addComments;
2465
    $$templateVars{'useConstraints'} = $FORM::useConstraints;
2466
    $$templateVars{'useConstraintsOther'} = $FORM::useConstraintsOther;
2467
    $$templateVars{'url'} = $FORM::url;
2468
    $$templateVars{'dataMedium'} = $FORM::dataMedium;
2469
    $$templateVars{'dataMediumOther'} = $FORM::dataMediumOther;
2470
    $$templateVars{'beginningYear'} = $FORM::beginningYear;
2471
    $$templateVars{'beginningMonth'} = $FORM::beginningMonth;
2472
    $$templateVars{'beginningDay'} = $FORM::beginningDay;
2473
    $$templateVars{'endingYear'} = $FORM::endingYear;
2474
    $$templateVars{'endingMonth'} = $FORM::endingMonth;
2475
    $$templateVars{'endingDay'} = $FORM::endingDay;
2476
    $$templateVars{'geogdesc'} = $FORM::geogdesc;
2477
    if($FORM::useSiteCoord ne ""){
2478
    $$templateVars{'useSiteCoord'} = "CHECKED";
2479
    }else{
2480
    $$templateVars{'useSiteCoord'} = "";
2481
    }
2482
    $$templateVars{'latDeg1'} = $FORM::latDeg1;
2483
    $$templateVars{'latMin1'} = $FORM::latMin1;
2484
    $$templateVars{'latSec1'} = $FORM::latSec1;
2485
    $$templateVars{'hemisphLat1'} = $FORM::hemisphLat1;
2486
    $$templateVars{'longDeg1'} = $FORM::longDeg1;
2487
    $$templateVars{'longMin1'} = $FORM::longMin1;
2488
    $$templateVars{'longSec1'} = $FORM::longSec1;
2489
    $$templateVars{'hemisphLong1'} = $FORM::hemisphLong1;
2490
    $$templateVars{'latDeg2'} = $FORM::latDeg2;
2491
    $$templateVars{'latMin2'} = $FORM::latMin2;
2492
    $$templateVars{'latSec2'} = $FORM::latSec2;
2493
    $$templateVars{'hemisphLat2'} = $FORM::hemisphLat2;
2494
    $$templateVars{'longDeg2'} = $FORM::longDeg2;
2495
    $$templateVars{'longMin2'} = $FORM::longMin2;
2496
    $$templateVars{'longSec2'} = $FORM::longSec2;
2497
    $$templateVars{'hemisphLong2'} = $FORM::hemisphLong2;
2498
    $$templateVars{'taxaCount'} = $FORM::taxaCount;
2499
    foreach my $trn (param()) {
2500
        if ($trn =~ /taxonRankName/) {
2501
            my $taxIndex = $trn;
2502
            $taxIndex =~ s/taxonRankName//; # get the index of the parameter 0, ..., 10
2503
            my $trv = "taxonRankValue".$taxIndex;
2504
            if ( $taxIndex =~ /[0-9]/ ){
2505
                if (hasContent(param($trn)) && hasContent(param($trv))) {
2506
                    debug("Registry processing taxon: $trn = ".param($trn)." $trv = ".param($trv));
2507
                    $$templateVars{$trn} = param($trn);
2508
                    $$templateVars{$trv} = param($trv);
2509
                }
2510
            }
2511
        }
2512
    }
2513
    $$templateVars{'taxaAuth'} = $FORM::taxaAuth;
2514
    $$templateVars{'methodTitle'} = $FORM::methodTitle;
2515
    $$templateVars{'methodPara'} = \@FORM::methodPara;
2516
    $$templateVars{'studyExtentDescription'} = $FORM::studyExtentDescription;
2517
    $$templateVars{'samplingDescription'} = $FORM::samplingDescription;
2518
    $$templateVars{'docid'} = $FORM::docid;
2519

    
2520
    $$templateVars{'form'} = 're_entry';
2521
    $template->process( $entryFormTemplate, $templateVars);
2522
}
2523

    
2524

    
2525
################################################################################
2526
# 
2527
# check if there is multiple occurence of the given tag and find its value.
2528
#
2529
################################################################################
2530

    
2531
sub findValue {
2532
    my $node = shift;
2533
    my $value = shift;
2534
    my $result;
2535
    my $tempNode;
2536

    
2537
    $result = $node->findnodes("./$value");
2538
    if ($result->size > 1) {
2539
        errMoreThanOne("$value");
2540
    } else {
2541
        foreach $tempNode ($result->get_nodelist){
2542
            #print $tempNode->nodeName().":".$tempNode->textContent();
2543
            #print "\n";
2544
            return $tempNode->textContent();
2545
        }
2546
    }
2547
}
2548

    
2549

    
2550
################################################################################
2551
# 
2552
# check if given tags has any children. if not return the value
2553
#
2554
################################################################################
2555
sub findValueNoChild {
2556
    my $node = shift;
2557
    my $value = shift;
2558
    my $tempNode;
2559
    my $childNodes;
2560
    my $result;
2561
    my $error;
2562

    
2563
    $result = $node->findnodes("./$value");
2564
    if($result->size > 1){
2565
       errMoreThanOne("$value");
2566
    } else {
2567
        foreach $tempNode ($result->get_nodelist) {
2568
            $childNodes = $tempNode->childNodes;
2569
            if ($childNodes->size() > 1) {
2570
                $error ="The tag $value has children which cannot be shown using the form. Please use Morpho to edit this document";    
2571
                push(@errorMessages, $error);
2572
                #if ($DEBUG == 1){ print $error."\n";}
2573
            } else {
2574
                #print $tempNode->nodeName().":".$tempNode->textContent();
2575
                #print "\n";
2576
                return $tempNode->textContent();
2577
            }
2578
        }
2579
    }
2580
}
2581

    
2582

    
2583
################################################################################
2584
# 
2585
# check if given tags are children of given node.
2586
#
2587
################################################################################
2588
sub dontOccur {
2589
    my $node = shift;
2590
    my $value = shift;
2591
    my $errVal = shift;
2592

    
2593
    my $result = $node->findnodes("$value");
2594
    if($result->size > 0){
2595
        $error ="One of the following tags found: $errVal. Please use Morpho to edit this document";
2596
        push(@errorMessages, $error."\n");
2597
        #if ($DEBUG == 1){ print $error;}
2598
    } 
2599
}
2600

    
2601

    
2602
################################################################################
2603
# 
2604
# print out error for more than one occurence of a given tag
2605
#
2606
################################################################################
2607
sub errMoreThanOne {
2608
    my $value = shift;
2609
    my $error ="More than one occurence of the tag $value found. Please use Morpho to edit this document";
2610
    push(@errorMessages, $error."\n");
2611
    # if ($DEBUG == 1){ print $error;}
2612
}
2613

    
2614

    
2615
################################################################################
2616
# 
2617
# print out error for more than given number of occurences of a given tag
2618
#
2619
################################################################################
2620
sub errMoreThanN {
2621
    my $value = shift;
2622
    my $error ="More occurences of the tag $value found than that can be shown in the form. Please use Morpho to edit this document";
2623
    push(@errorMessages, $error);
2624
    #if ($DEBUG == 1){ print $error."\n";}
2625
}
2626

    
2627

    
2628
################################################################################
2629
# 
2630
# convert coord to degrees, minutes and seconds form. 
2631
#
2632
################################################################################
2633
#sub convertCoord {
2634
#    my $wx = shift;
2635
#    print $deg." ".$min." ".$sec;
2636
#    print "\n";
2637
#}
2638

    
2639

    
2640
################################################################################
2641
# 
2642
# print debugging messages to stderr
2643
#
2644
################################################################################
2645
sub debug {
2646
    my $msg = shift;
2647
    
2648
    if ($debug) {
2649
        print STDERR "$msg\n";
2650
    }
2651
}
2652

    
2653
################################################################################
2654
# 
2655
# get the list of projects
2656
#
2657
################################################################################
2658
sub getProjectList {
2659
    
2660
    use NCEAS::AdminDB;
2661
    my $admindb = NCEAS::AdminDB->new();
2662
    $admindb->connect($nceas_db, $nceas_db_user, $nceas_db_password);
2663
    my $projects = $admindb->getProjects();
2664
    #my $projects = getTestProjectList();
2665
    return $projects;
2666
}
2667

    
2668
################################################################################
2669
# 
2670
# get a test list of projects for use only in testing where the NCEAS
2671
# admin db is not available.
2672
#
2673
################################################################################
2674
sub getTestProjectList {
2675
    # This block is for testing only!  Remove for production use
2676
    my @row1;
2677
    $row1[0] = 6000; $row1[1] = 'Andelman'; $row1[2] = 'Sandy'; $row1[3] = 'The very long and windy path to an apparent ecological conclusion: statistics lie';
2678
    my @row2; 
2679
    $row2[0] = 7000; $row2[1] = 'Bascompte'; $row2[2] = 'Jordi'; $row2[3] = 'Postdoctoral Fellow';
2680
    my @row3; 
2681
    $row3[0] = 7001; $row3[1] = 'Hackett'; $row3[2] = 'Edward'; $row3[3] = 'Sociology rules the world';
2682
    my @row4; 
2683
    $row4[0] = 7002; $row4[1] = 'Jones'; $row4[2] = 'Matthew'; $row4[3] = 'Informatics rules the world';
2684
    my @row5; 
2685
    $row5[0] = 7003; $row5[1] = 'Schildhauer'; $row5[2] = 'Mark'; $row5[3] = 'Excel rocks my world, assuming a, b, and c';
2686
    my @row6; 
2687
    $row6[0] = 7004; $row6[1] = 'Rogers'; $row6[2] = 'Bill'; $row6[3] = 'Graduate Intern';
2688
    my @row7; 
2689
    $row7[0] = 7005; $row7[1] = 'Zedfried'; $row7[2] = 'Karl'; $row7[3] = 'A multivariate analysis of thing that go bump in the night';
2690
    my @projects;
2691
    $projects[0] = \@row1;
2692
    $projects[1] = \@row2;
2693
    $projects[2] = \@row3;
2694
    $projects[3] = \@row4;
2695
    $projects[4] = \@row5;
2696
    $projects[5] = \@row6;
2697
    $projects[6] = \@row7;
2698
    return \@projects;
2699
}
    (1-1/1)