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:48:36 -0800 (Thu, 08 Jan 2004) $'
8
# '$Revision: 1999 $' 
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::LDAP;
37
use Net::SMTP;
38
use CGI qw/:standard :html3/;
39
use strict;
40

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
278

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

    
284
    my $xmldoc = createXMLDocument();
285

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

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

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

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

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

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

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

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

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

    
385
        exit(0);
386
    }
387
}
388

    
389
debug("Registry: C");
390

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

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

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

    
407
exit(0);
408

    
409

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

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

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

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

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

    
470
  return $notunique;
471
}
472

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

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

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

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

    
522
  return $acl;
523
}
524

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

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

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

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

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

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

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

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

    
639
    if ($FORM::useSiteCoord) {
640
    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.")
641
        unless(hasContent($latDeg1) && hasContent($longDeg1));
642
    }else{
643
    push(@invalidParams, "Latitude degrees are missing.")
644
        unless hasContent($latDeg1);
645
    push(@invalidParams, "Longitude degrees are missing.")
646
        unless hasContent($longDeg1);
647
    }
648

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

    
664
    push(@invalidParams, "Contact first name is missing.")
665
    unless (hasContent($FORM::origNamefirstContact) || 
666
        $FORM::useOrigAddress);
667
    push(@invalidParams, "Contact last name is missing.")
668
    unless (hasContent($FORM::origNamelastContact) || 
669
        $FORM::useOrigAddress);
670
    push(@invalidParams, "Data medium is missing.")
671
    unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/);
672
    
673
    #if ($chkUser) {
674
        #my $errorUserPass = validateUserPass();
675
        #if ($errorUserPass ne "") {
676
            #push(@invalidParams, $errorUserPass);
677
        #}
678
    #}
679

    
680
    return \@invalidParams;
681
}
682

    
683
################################################################################
684
# 
685
# Validate the parameters username and password.
686
#
687
################################################################################
688
sub validateUserPass {
689
    my $userDN = $FORM::username;
690
    my $userOrg = $FORM::organization;
691
    my $userPass = $FORM::password;
692
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
693

    
694
    my $errorMessage = "";
695
    my $ldap = Net::LDAP->new($ldapUrl) or die "$@";
696
    my $bindresult = $ldap->bind( version => 3, dn => $dname, 
697
                                  password => $userPass );
698
    if ($bindresult->code) {
699
        $errorMessage = "Failed to log into metacat. Please check the username, organization and password entered";
700
        return $errorMessage;
701
    }
702
    return $errorMessage;
703
}
704

    
705

    
706
################################################################################
707
# 
708
# utility function to determine if a paramter is defined and not an empty string
709
#
710
################################################################################
711
sub hasContent {
712
    my $param = shift;
713

    
714
    my $paramHasContent;
715
    if (!defined($param) || $param eq '') { 
716
        $paramHasContent = 0;
717
    } else {
718
        $paramHasContent = 1;
719
    }
720
    return $paramHasContent;
721
}
722

    
723

    
724
################################################################################
725
# 
726
# Create the XML document from the HTML form input
727
# returns the XML document as a string
728
#
729
################################################################################
730
sub createXMLDocument {
731

    
732
    my $orig  = "";
733
    my $role  = "associatedParty";
734
    my $creat = "";
735
    my $metaP = "";
736
    my $apart = "";
737
    my $cont  = "";
738
    my $publ  = "";
739
    my $dso   = "";
740
    my $gmt = gmtime($now);
741
    my $doc =  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
742

    
743
   $doc .= "<eml:eml\n 
744
                     \t packageId=\"docid\" system=\"knb\"\n 
745
                     \t xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.0\"\n
746
                     \t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n 
747
                     \t xmlns:ds=\"eml://ecoinformatics.org/dataset-2.0.0\"\n 
748
                     \t xmlns:stmml=\"http://www.xml-cml.org/schema/stmml\"\n 
749
                     \t xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.0 eml.xsd\">\n";
750

    
751
    $doc .= "<!-- Person who filled in the catalog entry form: ";
752
    $doc .= "$FORM::providerGivenName $FORM::providerSurName -->\n";
753
    $doc .= "<!-- Form filled out at $gmt GMT -->\n";
754
    $doc .= "<dataset>\n";
755
    
756
    if (hasContent($FORM::identifier)) {
757
        $doc .= "<alternateIdentifier system=\"$FORM::site\">";
758
        $doc .= $FORM::identifier . "</alternateIdentifier>\n";
759
    }
760
    
761
    if (hasContent($FORM::title)) {
762
        $doc .= "<title>$FORM::title</title>\n";
763
    }
764

    
765
    if (hasContent($FORM::origNamelast0)) {
766
    $role = "creator";
767
        $orig .= "<individualName>\n";
768
        $orig .= "<givenName>$FORM::origNamefirst0</givenName>\n";
769
        $orig .= "<surName>$FORM::origNamelast0</surName>\n";
770
        $orig .= "</individualName>\n";
771
    }
772

    
773
    if (hasContent($FORM::origNameOrg)) {
774
        $orig .= "<organizationName>$FORM::origNameOrg</organizationName>\n";
775
    }
776

    
777
    if (hasContent($FORM::origDelivery) || hasContent($FORM::origCity) ||
778
        (hasContent($FORM::origState   ) &&
779
        ($FORM::origState !~ "Select state here.")) ||
780
        hasContent($FORM::origStateOther) ||
781
        hasContent($FORM::origZIP ) || hasContent($FORM::origCountry)) {
782
        $orig .= "<address>\n";
783

    
784
        if (hasContent($FORM::origDelivery)) {
785
            $orig .= "<deliveryPoint>$FORM::origDelivery</deliveryPoint>\n";
786
        }
787
        if (hasContent($FORM::origCity)) {
788
            $orig .= "<city>$FORM::origCity</city>\n";
789
        }
790

    
791
    if (hasContent($FORM::origState) && 
792
            ($FORM::origState !~ "Select state here.")) {
793
            $orig .= "<administrativeArea>$FORM::origState";
794
            $orig .= "</administrativeArea>\n";
795
        } elsif (hasContent($FORM::origStateOther)) {
796
            $orig .= "<administrativeArea>$FORM::origStateOther";
797
            $orig .= "</administrativeArea>\n";
798
        }
799
        if (hasContent($FORM::origZIP)) {
800
            $orig .= "<postalCode>$FORM::origZIP</postalCode>\n";
801
        }
802
        if (hasContent($FORM::origCountry)) {
803
            $orig .= "<country>$FORM::origCountry</country>\n";
804
        }
805
        $orig .= "</address>\n";
806
    }
807

    
808
    if (hasContent($FORM::origPhone)) {
809
        $orig .= "<phone>$FORM::origPhone</phone>\n";
810
    }
811
    if (hasContent($FORM::origFAX)) {
812
        $orig .= "<phone phonetype=\"Fax\">$FORM::origFAX</phone>\n";
813
    }
814
    if (hasContent($FORM::origEmail)) {
815
        $orig .= "<electronicMailAddress>$FORM::origEmail";
816
        $orig .= "</electronicMailAddress>\n";
817
    }
818
    $dso = "<$role>\n$orig</$role>\n";
819
    
820
    $creat .= $dso;
821

    
822
    if ($FORM::useOrigAddress) {
823
        # Add a contact originator like the original with a different role
824
            $cont .= "<contact>\n";
825
        $cont .= $orig;
826
        $cont .= "</contact>\n";
827
    } else {
828
        $cont .= "<contact>\n";
829

    
830
        $cont .= "<individualName>\n";
831
        $cont .= "<givenName>$FORM::origNamefirstContact</givenName>\n";
832
        $cont .= "<surName>$FORM::origNamelastContact</surName>\n";
833
        $cont .= "</individualName>\n";
834
 
835
    if (hasContent($FORM::origNameOrgContact)) {
836
        $cont .= "<organizationName>$FORM::origNameOrgContact</organizationName>\n";
837
    }
838

    
839
        if (hasContent($FORM::origDeliveryContact) || 
840
            hasContent($FORM::origCityContact) ||
841
            (hasContent($FORM::origStateContact) &&
842
            ($FORM::origStateContact !~ "Select state here.")) ||
843
            hasContent($FORM::origStateOtherContact) ||
844
            hasContent($FORM::origZIPContact) || 
845
            hasContent($FORM::origCountryContact)) {
846
            $cont .= "<address>\n";
847
            if (hasContent($FORM::origDeliveryContact)) {
848
                $cont .= "<deliveryPoint>$FORM::origDeliveryContact";
849
                $cont .= "</deliveryPoint>\n";
850
            }
851
            if (hasContent($FORM::origCityContact)) {
852
                $cont .= "<city>$FORM::origCityContact</city>\n";
853
            }
854
            if (hasContent($FORM::origStateContact) && 
855
                ($FORM::origStateContact !~ "Select state here.")) {
856
                $cont .= "<administrativeArea>$FORM::origStateContact";
857
                $cont .= "</administrativeArea>\n";
858
            } elsif (hasContent($FORM::origStateOtherContact)) {
859
                $cont .= "<administrativeArea>$FORM::origStateOtherContact";
860
                $cont .= "</administrativeArea>\n";
861
            }
862
            if (hasContent($FORM::origZIPContact)) {
863
                $cont .= "<postalCode>$FORM::origZIPContact</postalCode>\n";
864
            }
865
            if (hasContent($FORM::origCountryContact)) {
866
                $cont .= "<country>$FORM::origCountryContact</country>\n";
867
            }
868
            $cont .= "</address>\n";
869
        }
870
        if (hasContent($FORM::origPhoneContact)) {
871
            $cont .= "<phone>$FORM::origPhoneContact</phone>\n";
872
        }
873
    if (hasContent($FORM::origFAXContact)) {
874
        $cont .= "<phone phonetype=\"Fax\">$FORM::origFAXContact</phone>\n";
875
    }
876
        if (hasContent($FORM::origEmailContact)) {
877
            $cont .= "<electronicMailAddress>$FORM::origEmailContact";
878
            $cont .= "</electronicMailAddress>\n";
879
        }
880
    $cont .= "</contact>\n";
881
    }
882

    
883
    $metaP .= "<metadataProvider>\n";
884
    $metaP .= "<individualName>\n";
885
    $metaP .= "<givenName>$FORM::providerGivenName</givenName>\n";
886
    $metaP .= "<surName>$FORM::providerSurName</surName>\n";
887
    $metaP .= "</individualName>\n";
888
    $metaP .= "</metadataProvider>\n";
889

    
890
    # Additional originators
891
    foreach my $tmp (param()) {
892
        if ($tmp =~ /origNamelast/){
893
            my $tmp1 = $tmp;
894
            $tmp1 =~ s/origNamelast//; # get the index of the parameter 0 to 10
895
            if ( $tmp1 eq '1' 
896
                 || $tmp1 eq '2'
897
                 || $tmp1 eq '3'
898
                 || $tmp1 eq '4'
899
                 || $tmp1 eq '5'
900
                 || $tmp1 eq '6'
901
                 || $tmp1 eq '7'
902
                 || $tmp1 eq '8'
903
                 || $tmp1 eq '9'
904
                 || $tmp1 eq '10'
905
                 ) {
906
     
907
                # do not generate XML for empty originator fields 
908
                if (hasContent(param("origNamefirst" . $tmp1))) {    
909

    
910
            my $add = "";
911
            $add .= "<individualName>\n";
912
            $add .= "<givenName>";
913
            $add .= param("origNamefirst" . $tmp1);
914
            $add .= "</givenName>\n";
915
            $add .= "<surName>";
916
            $add .= param("origNamelast" . $tmp1);
917
            $add .= "</surName>\n";
918
            $add .= "</individualName>\n";
919
            
920
            if(param("origRole" . $tmp1) eq "Originator"){
921
            $creat .= "<creator>\n";
922
            $creat .= $add;
923
            $creat .= "</creator>\n";
924
            }
925
            elsif(param("origRole" . $tmp1) eq "Metadata Provider"){
926
            $metaP .= "<metadataProvider>\n";
927
            $metaP .= $add;
928
            $metaP .= "</metadataProvider>\n";
929
            }
930
            elsif((param("origRole" . $tmp1) eq "Publisher")  && ($publ eq "")){
931
            $publ .= "<publisher>\n";
932
            $publ .= $add;
933
            $publ .= "</publisher>\n";
934
            }
935
            else{
936
            $apart .= "<associatedParty>\n";
937
            $apart .= $add;
938
            $apart .= "<role>";
939
            $apart .= param("origRole" . $tmp1);
940
            $apart .= "</role>\n";
941
            $apart .= "</associatedParty>\n";
942
            }
943
        }
944
            }
945
        }
946
    }
947

    
948
    $creat .= "<creator>\n";
949
    $creat .= "<organizationName>$FORM::site</organizationName>\n";
950
    $creat .= "</creator>\n";
951

    
952
    $creat .= "<creator>\n";
953
    $creat .= "<organizationName>$organization</organizationName>\n";
954
    $creat .= "</creator>\n";
955

    
956
    if ($FORM::cfg eq 'nceas') {
957
        for (my $i = 0; $i < scalar(@FORM::wg); $i++) {
958
            $creat .= "<creator>\n";
959
            $creat .= "<organizationName>$FORM::wg[$i]</organizationName>\n";
960
            $creat .= "</creator>\n";
961
        }
962
    }
963
    $doc .= $creat;
964
    $doc .= $metaP;
965
    $doc .= $apart;
966

    
967
    $doc .= "<abstract>\n";
968
    $doc .= "<para>$FORM::abstract</para>\n";
969
    $doc .= "</abstract>\n";
970

    
971
    # Keyword information
972
    foreach my $tmp (param()) {
973
        if ($tmp =~ /keyword/) {
974
            my $tmp1 = $tmp;
975
            $tmp1 =~ s/keyword//; # get the index of the parameter 0, ..., 10
976
            if ( $tmp1 =~ /[0-9]/ ){
977
                # don't generate xml for empty keyword fields
978
                # don't generate taxonomic keyword fields, those go in taxonomic coverage
979
                if (hasContent(param($tmp))) {
980
                    $doc .= "<keywordSet>\n";
981
                    $doc .= "<keyword ";
982
                    if (hasContent(param("kwType" . $tmp1)) &&
983
                       (param("kwType" . $tmp1) !~ "none") ) {
984
                         $doc .= "keywordType=\"";
985
                         $doc .= param("kwType" . $tmp1);
986
                         $doc .= "\"";
987
                    }
988
                    $doc .= ">";
989
                    $doc .= param("keyword" . $tmp1);
990
                    $doc .= "</keyword>\n";
991
                    $doc .= "<keywordThesaurus>";
992
                    $doc .= param("kwTh" . $tmp1);
993
                    $doc .= "</keywordThesaurus>\n";
994
                    $doc .= "</keywordSet>\n";
995
                }
996
            }
997
        }
998
    }
999

    
1000
    if (hasContent($FORM::addComments)) {
1001
        $doc .= "<additionalInfo>\n";
1002
        $doc .= "<para>$FORM::addComments</para>\n";
1003
        $doc .= "</additionalInfo>\n";
1004
    }
1005

    
1006
    if (hasContent($FORM::useConstraints) || 
1007
        hasContent($FORM::useConstraintsOther)) {
1008
        $doc .= "<intellectualRights>\n";
1009
        if (hasContent($FORM::useConstraints)) {
1010
            $doc .= "<para>$FORM::useConstraints</para>\n";
1011
        }
1012
        if (hasContent($FORM::useConstraintsOther)) {
1013
            $doc .= "<para>$FORM::useConstraintsOther</para>\n";
1014
        }
1015
        $doc .= "</intellectualRights>\n";
1016
    }
1017

    
1018
    
1019
    if (hasContent($FORM::url)) {
1020
    $doc .= "<distribution>\n";
1021
        $doc .= "<online>\n";
1022
    $doc .= "<url>$FORM::url</url>\n";
1023
    $doc .= "</online>\n";
1024
    $doc .= "</distribution>\n";
1025
    }
1026
    
1027
    $doc .= "<distribution>\n";
1028
    $doc .= "<offline>\n";
1029
    $doc .= "<mediumName>" . "$FORM::dataMedium   $FORM::dataMediumOther";
1030
    $doc .= "</mediumName>\n";
1031
    $doc .= "</offline>\n";
1032
    $doc .= "</distribution>\n";
1033
            
1034
    $doc .= "<coverage>\n";
1035
    $doc .= "<temporalCoverage>\n";
1036

    
1037

    
1038
    if (hasContent($FORM::endingYear)) {
1039
    $doc .= "<rangeOfDates>\n";
1040
    if (hasContent($FORM::beginningMonth)) {
1041
        my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1042
             "JUL","AUG","SEP","OCT","NOV","DEC")
1043
        [$FORM::beginningMonth - 1];
1044
        $doc .= "<beginDate>\n";
1045
        $doc .= "<calendarDate>";
1046
        $doc .= "$FORM::beginningYear-$FORM::beginningMonth-$FORM::beginningDay";
1047
        $doc .= "</calendarDate>\n";
1048
        $doc .= "</beginDate>\n";
1049
    } else {
1050
        $doc .= "<beginDate>\n";
1051
        $doc .= "<calendarDate>";
1052
        $doc .= "$FORM::beginningYear";
1053
        $doc .= "</calendarDate>\n";
1054
        $doc .= "</beginDate>\n";
1055
    }
1056

    
1057
    if (hasContent($FORM::endingMonth)) {
1058
        my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1059
             "JUL","AUG","SEP","OCT","NOV","DEC")
1060
        [$FORM::endingMonth - 1];
1061
        $doc .= "<endDate>\n";
1062
        $doc .= "<calendarDate>";
1063
        $doc .= "$FORM::endingYear-$FORM::endingMonth-$FORM::endingDay";
1064
        $doc .= "</calendarDate>\n";
1065
        $doc .= "</endDate>\n";
1066
    } else {
1067
        $doc .= "<endDate>\n";
1068
        $doc .= "<calendarDate>";
1069
        $doc .= "$FORM::endingYear";
1070
        $doc .= "</calendarDate>\n";
1071
        $doc .= "</endDate>\n";
1072
    }
1073
    $doc .= "</rangeOfDates>\n";
1074
    } else {
1075
    $doc .= "<singleDateTime>\n";
1076
    if (hasContent($FORM::beginningMonth)) {
1077
        my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1078
             "JUL","AUG","SEP","OCT","NOV","DEC")
1079
        [$FORM::beginningMonth - 1];
1080
        $doc .= "<calendarDate>";
1081
        $doc .= "$FORM::beginningYear-$FORM::beginningMonth-$FORM::beginningDay";
1082
        $doc .= "</calendarDate>\n";
1083
    } else {
1084
        $doc .= "<calendarDate>";
1085
        $doc .= "$FORM::beginningYear";
1086
        $doc .= "</calendarDate>\n";
1087
    }
1088
    $doc .= "</singleDateTime>\n";
1089
    }
1090

    
1091
    $doc .= "</temporalCoverage>\n";
1092
    
1093
    $doc .= "<geographicCoverage>\n";
1094
    $doc .= "<geographicDescription>$FORM::geogdesc</geographicDescription>\n";
1095
    $doc .= "<boundingCoordinates>\n";
1096

    
1097
    # if the second latitude is missing, then set the second lat/long pair 
1098
    # equal to the first this makes a point appear like a rectangle 
1099
    if ($FORM::latDeg2 == 0 && $FORM::latMin2 == 0 && $FORM::latSec2 == 0) {
1100
    
1101
        $latDeg2 = $latDeg1;
1102
        $latMin2 = $latMin1;
1103
        $latSec2 = $latSec1;
1104
        $hemisphLat2 = $hemisphLat1;
1105
        $longDeg2 = $longDeg1;
1106
        $longMin2 = $longMin1;
1107
        $longSec2 = $longSec1;
1108
        $hemisphLong2 = $hemisphLong1;
1109
    }
1110
    else
1111
    {
1112
        $latDeg2 = $FORM::latDeg2;
1113
        $latMin2 = $FORM::latMin2;
1114
        $latSec2 = $FORM::latSec2;
1115
        $hemisphLat2 = $FORM::hemisphLat2;
1116
        $longDeg2 = $FORM::longDeg2;
1117
        $longMin2 = $FORM::longMin2;
1118
        $longSec2 = $FORM::longSec2;
1119
        $hemisphLong2 = $FORM::hemisphLong2;
1120
    } 
1121
    
1122
   
1123
    my $hemisph;
1124
    $hemisph = ($hemisphLong1 eq "W") ? -1 : 1;
1125
    $doc .= "<westBoundingCoordinate>";
1126
    $doc .= $hemisph * ($longDeg1 + (60*$longMin1+$longSec1)/3600);
1127
    $doc .= "</westBoundingCoordinate>\n";
1128

    
1129
    $hemisph = ($hemisphLong2 eq "W") ? -1 : 1;
1130
    $doc .= "<eastBoundingCoordinate>";
1131
    $doc .= $hemisph * ($longDeg2 + (60*$longMin2+$longSec2)/3600);
1132
    $doc .= "</eastBoundingCoordinate>\n";
1133

    
1134
    $hemisph = ($hemisphLat1 eq "S") ? -1 : 1;
1135
    $doc .= "<northBoundingCoordinate>";
1136
    $doc .= $hemisph * ($latDeg1 + (60*$latMin1+$latSec1)/3600);
1137
    $doc .= "</northBoundingCoordinate>\n";
1138

    
1139
    $hemisph = ($hemisphLat2 eq "S") ? -1 : 1;
1140
    $doc .= "<southBoundingCoordinate>";
1141
    $doc .= $hemisph * ($latDeg2 + (60*$latMin2+$latSec2)/3600);
1142
    $doc .= "</southBoundingCoordinate>\n";
1143

    
1144
    $doc .= "</boundingCoordinates>\n";
1145
    $doc .= "</geographicCoverage>\n";
1146

    
1147
    # Write out the taxonomic coverage fields
1148
    my $foundFirstTaxon = 0;
1149
    foreach my $trn (param()) {
1150
        if ($trn =~ /taxonRankName/) {
1151
            my $taxIndex = $trn;
1152
            $taxIndex =~ s/taxonRankName//; # get the index of the parameter 0, ..., 10
1153
            my $trv = "taxonRankValue".$taxIndex;
1154
            if ( $taxIndex =~ /[0-9]/ ){
1155
                if (hasContent(param($trn)) && hasContent(param($trv))) {
1156
                    if (! $foundFirstTaxon) {
1157
                        $doc .= "<taxonomicCoverage>\n";
1158
                        $foundFirstTaxon = 1;
1159
                        if (hasContent($FORM::taxaAuth)) {
1160
                            $doc .= "<generalTaxonomicCoverage>".$FORM::taxaAuth."</generalTaxonomicCoverage>\n";
1161
                        }
1162
                    }
1163
                    $doc .= "<taxonomicClassification>\n";
1164
                    $doc .= "  <taxonRankName>".param($trn)."</taxonRankName>\n";
1165
                    $doc .= "  <taxonRankValue>".param($trv)."</taxonRankValue>\n";
1166
                    $doc .= "</taxonomicClassification>\n";
1167
                }
1168
            }
1169
        }
1170
    }
1171
    if ($foundFirstTaxon) {
1172
        $doc .= "</taxonomicCoverage>\n";
1173
    }
1174

    
1175
    $doc .= "</coverage>\n";
1176

    
1177
    $doc .= $cont;
1178
    $doc .= $publ;
1179
    
1180
    if ((hasContent($FORM::methodTitle)) || scalar(@FORM::methodsPara) > 0) {
1181
        my $methods = "<methods><methodStep><description><section>\n";
1182
        if (hasContent($FORM::methodTitle)) {
1183
            $methods .= "<title>$FORM::methodTitle</title>\n";
1184
        }
1185
        for (my $i = 0; $i < scalar(@FORM::methodPara); $i++) {
1186
            $methods .= "<para>$FORM::methodPara[$i]</para>\n";
1187
        }
1188
        $methods .= "</section></description></methodStep>\n";
1189
        if (hasContent($FORM::studyExtentDescription)) {
1190
            $methods .= "<sampling><studyExtent><description>\n";
1191
            $methods .= "<para>$FORM::studyExtentDescription</para>\n";
1192
            $methods .= "</description></studyExtent>\n";
1193
            $methods .= "<samplingDescription>\n";
1194
            $methods .= "<para>$FORM::samplingDescription</para>\n";
1195
            $methods .= "</samplingDescription>\n";
1196
            $methods .= "</sampling>\n";
1197
        }
1198
        $methods .= "</methods>\n";
1199
        $doc .= $methods;
1200
    }
1201

    
1202
    $doc .= "<access authSystem=\"knb\" order=\"denyFirst\">\n";
1203
    $doc .= "<allow>\n";
1204
    $doc .= "<principal>uid=obfsadmin,o=LTER,dc=ecoinformatics,dc=org</principal>\n";
1205
    $doc .= "<permission>all</permission>\n";
1206
    $doc .= "</allow>\n";
1207
    $doc .= "<allow>\n";
1208
    $doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n";
1209
    $doc .= "<permission>all</permission>\n";
1210
    $doc .= "</allow>\n";
1211
    $doc .= "<allow>\n";
1212
    $doc .= "<principal>public</principal>\n";
1213
    $doc .= "<permission>read</permission>\n";
1214
    $doc .= "</allow>\n";
1215
    $doc .= "</access>\n";
1216
    
1217
    $doc .= "</dataset>\n</eml:eml>\n";
1218

    
1219
    return $doc;
1220
}
1221

    
1222

    
1223
################################################################################
1224
# 
1225
# send an email message notifying the moderator of a new submission 
1226
#
1227
################################################################################
1228
sub sendNotification {
1229
    my $identifier = shift;
1230
    my $mailhost = shift;
1231
    my $sender = shift;
1232
    my $recipient = shift;
1233

    
1234
    my $smtp = Net::SMTP->new($mailhost);
1235
    $smtp->mail($sender);
1236
    $smtp->to($recipient);
1237

    
1238
    my $message = <<"    ENDOFMESSAGE";
1239
    To: $recipient
1240
    From: $sender
1241
    Subject: New data submission
1242
    
1243
    Data was submitted to the data registry.  
1244
    The identifying information for the new data set is:
1245

    
1246
    Identifier: $identifier
1247
    Title: $FORM::title
1248
    Submitter: $FORM::providerGivenName $FORM::providerSurName
1249

    
1250
    Please review the submmission and grant public read access if appropriate.
1251
    Thanks
1252
    
1253
    ENDOFMESSAGE
1254
    $message =~ s/^[ \t\r\f]+//gm;
1255

    
1256
    $smtp->data($message);
1257
    $smtp->quit;
1258
}
1259

    
1260

    
1261
################################################################################
1262
# 
1263
# read the eml document and send back a form with values filled in. 
1264
#
1265
################################################################################
1266
sub modifyData {
1267
    
1268
    # create metacat instance
1269
    my $metacat;
1270
    my $docid = $FORM::docid;
1271
    my $httpMessage;
1272
    my $doc;
1273
    my $xmldoc;
1274
    my $findType;
1275
    my $parser = XML::LibXML->new();
1276
    my @fileArray;
1277
    my $pushDoc;
1278
    my $alreadyInArray;
1279
    my $node;
1280
    my $response; 
1281
    my $element;
1282
    my $tempfile;
1283

    
1284
    $metacat = Metacat->new();
1285
    if ($metacat) {
1286
        $metacat->set_options( metacatUrl => $metacatUrl );
1287
    } else {
1288
        #die "failed during metacat creation\n";
1289
        push(@errorMessages, "Failed during metacat creation.");
1290
    }
1291
    
1292
    $httpMessage = $metacat->read($docid);
1293
    $doc = $httpMessage->content();
1294
    $xmldoc = $parser->parse_string($doc);
1295

    
1296
    #$tempfile = $xslConvDir.$docid;
1297
    #push (@fileArray, $tempfile);
1298

    
1299
    if ($xmldoc eq "") {
1300
        $error ="Error in parsing the eml document";
1301
        push(@errorMessages, $error);
1302
    } else {
1303
        $findType = $xmldoc->findnodes('//dataset/identifier');
1304
        if ($findType->size() > 0) {
1305
            # This is a eml beta6 document
1306
            # Read the documents mentioned in triples also
1307
        
1308
            $findType = $xmldoc->findnodes('//dataset/triple');
1309
            if ($findType->size() > 0) {
1310
                foreach $node ($findType->get_nodelist) {
1311
                    $pushDoc = findValue($node, 'subject');
1312
            
1313
                    # If the file is already in @fileArray then do not add it 
1314
                    $alreadyInArray = 0;
1315
                    foreach $element (@fileArray) {
1316
                        $tempfile = $tmpdir."/".$pushDoc;
1317
                        if ($element eq $pushDoc) {
1318
                            $alreadyInArray = 1;
1319
                        }
1320
                    }
1321
            
1322
                    if (!$alreadyInArray) {
1323
                        $tempfile = $tmpdir."/".$pushDoc;
1324
                        $response = "";
1325
                        $response = $metacat->read($pushDoc);    
1326
                        if (! $response) {
1327
                            # could not read
1328
                            #push(@errorMessages, $response);
1329
                            push(@errorMessages, $metacat->getMessage());
1330
                            push(@errorMessages, "Failed during reading.\n");
1331
                        } else {
1332
                            my $xdoc = $response->content();
1333
                            #$tempfile = $xslConvDir.$pushDoc;
1334
                            open (TFILE,">$tempfile") || 
1335
                                die ("Cant open xml file... $tempfile\n");
1336
                            print TFILE $xdoc;
1337
                            close(TFILE);
1338
                            push (@fileArray, $tempfile);
1339
                        }
1340
                    }
1341
                }
1342
            }
1343

    
1344
            # Read the main document. 
1345

    
1346
            $tempfile = $tmpdir."/".$docid; #= $xslConvDir.$docid;
1347
            open (TFILE,">$tempfile") || die ("Cant open xml file...\n");
1348
            print TFILE $doc;
1349
            close(TFILE);
1350
        
1351
            # Transforming beta6 to eml 2
1352
            my $xslt;
1353
            my $triplesheet;
1354
            my $results;
1355
            my $stylesheet;
1356
            my $resultsheet;
1357
        
1358
            $xslt = XML::LibXSLT->new();
1359
            #$tempfile = $xslConvDir."triple_info.xsl";
1360
            $tempfile = $tmpdir."/"."triple_info.xsl";
1361
    
1362
            $triplesheet = $xslt->parse_stylesheet_file($tempfile);
1363

    
1364
            #$results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1365
            $results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1366

    
1367
            #$tempfile = $xslConvDir."emlb6toeml2.xsl";
1368
            $tempfile = $tmpdir."/"."emlb6toeml2.xsl";
1369
            $stylesheet = $xslt->parse_stylesheet_file($tempfile);
1370
            $resultsheet = $stylesheet->transform($results);
1371
        
1372
            #$tempfile = "/usr/local/apache2/htdocs/xml/test.xml";;
1373
            #open (TFILE,">$tempfile") || die ("Cant open xml file...\n");
1374
            #print TFILE $stylesheet->output_string($resultsheet);
1375
            #close(TFILE);
1376

    
1377
            getFormValuesFromEml2($resultsheet);
1378
            
1379
            # Delete the files written earlier. 
1380
            unlink @fileArray;
1381

    
1382
        } else {
1383
            getFormValuesFromEml2($xmldoc);
1384
        }
1385
    }   
1386
    
1387
    if (scalar(@errorMessages)) {
1388
        # if any errors, print them in the response template 
1389
        $$templateVars{'status'} = 'failure';
1390
        $$templateVars{'errorMessages'} = \@errorMessages;
1391
        $error = 1;
1392
        $$templateVars{'function'} = "modification";
1393
        $$templateVars{'section'} = "Modification Status";
1394
        $template->process( $responseTemplate, $templateVars); 
1395
    } else {
1396
        $$templateVars{'form'} = 're_entry';
1397
        $template->process( $entryFormTemplate, $templateVars);
1398
    }
1399
}
1400

    
1401
################################################################################
1402
# 
1403
# Parse an EML 2.0.0 file and extract the metadata into perl variables for 
1404
# processing and returning to the template processor
1405
#
1406
################################################################################
1407
sub getFormValuesFromEml2 {
1408
    
1409
    my $doc = shift;
1410
    my $results;
1411
    my $error;
1412
    my $node;
1413
    my $tempResult;
1414
    my $tempNode;
1415
    my $aoCount = 1;
1416
    my $foundDSO;
1417

    
1418
    # find out the tag <alternateIdentifier>. 
1419
    $results = $doc->findnodes('//dataset/alternateIdentifier');
1420
    if ($results->size() > 1) {
1421
        errMoreThanOne("alternateIdentifier");
1422
    } else {
1423
        foreach $node ($results->get_nodelist) {
1424
            $$templateVars{'identifier'} = findValue($node, '../alternateIdentifier');
1425
        }
1426
    }
1427

    
1428
    # find out the tag <title>. 
1429
    $results = $doc->findnodes('//dataset/title');
1430
    if ($results->size() > 1) {
1431
        errMoreThanOne("title");
1432
    } elsif ($results->size() < 1) {
1433
        $error ="Following tag not found: title. Please use Morpho to edit this document";
1434
        push(@errorMessages, $error."\n");
1435
        #if ($DEBUG == 1){ print $error;}
1436
    } else {
1437
        foreach $node ($results->get_nodelist) {
1438
            $$templateVars{'title'} = findValue($node, '../title');
1439
        }
1440
    }
1441

    
1442
    # find out the tag <creator>. 
1443
    $results = $doc->findnodes('//dataset/creator/individualName');
1444
    debug("Registry: Creators: ".$results->size());
1445
    if ($results->size() > 11) {
1446
        errMoreThanN("creator/individualName");
1447
    } else {
1448
        foreach $node ($results->get_nodelist) {
1449
            dontOccur($node, "../positionName|../onlineURL|../userId", 
1450
              "positionName, onlineURL, userId");
1451
        
1452
            dontOccur($node, "./saluation", "saluation");                
1453
        
1454
            debug("Registry: Checking a creator in loop 1...");
1455
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1456
            if($tempResult->size > 0) {
1457
                if($foundDSO == 0) {
1458
                    $foundDSO = 1;
1459
     
1460
                    debug("Registry: Recording a creator in loop 1...");
1461
                    $$templateVars{'origNamefirst0'} = findValue($node, 'givenName');
1462
                    $$templateVars{'origNamelast0'} = findValue($node, 'surName');
1463
            
1464
                    my $tempResult2 = $node->findnodes('../address');
1465
                    if ($tempResult2->size > 1) {
1466
                        errMoreThanOne("address");
1467
                    } else {
1468
                        foreach my $tempNode2 ($tempResult2->get_nodelist) {
1469
                            $$templateVars{'origDelivery'} = findValue($tempNode2, 'deliveryPoint');
1470
                            $$templateVars{'origCity'} = findValue($tempNode2, 'city');
1471
                            $$templateVars{'origState'} = findValue($tempNode2, 'administrativeArea');
1472
                            $$templateVars{'origZIP'} = findValue($tempNode2, 'postalCode');
1473
                            $$templateVars{'origCountry'} = findValue($tempNode2, 'country');
1474
                        }
1475
                    }
1476
            
1477
                    my $tempResult3 = $node->findnodes('../phone');
1478
                    if ($tempResult3->size > 2) {
1479
                        errMoreThanN("phone");
1480
                    } else {
1481
                        foreach my $tempNode2 ($tempResult3->get_nodelist) {
1482
                            if ($tempNode2->hasAttributes()) {
1483
                                my @attlist = $tempNode2->attributes();
1484
                                if ($attlist[0]->value eq "Fax") {
1485
                                    $$templateVars{'origFAX'} = $tempNode2->textContent();
1486
                                } else {
1487
                                    $$templateVars{'origPhone'} = $tempNode2->textContent();
1488
                                }
1489
                            } else {
1490
                                $$templateVars{'origPhone'} = $tempNode2->textContent();
1491
                            }
1492
                        }
1493
                    }
1494
                    $$templateVars{'origEmail'} = findValue($node, '../electronicMailAddress');
1495
                    $$templateVars{'origNameOrg'} = findValue($node, '../organizationName');
1496
                } else {
1497
                    errMoreThanN("address, phone and electronicMailAddress");
1498
                }
1499
            }
1500
        }
1501
        foreach $node ($results->get_nodelist) {
1502
            debug("Registry: Checking a creator in loop 2...");
1503
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1504
            if ($tempResult->size == 0) {
1505
                if ($foundDSO == 0) {
1506
                    debug("Registry: Recording a creator in loop 2 block A...");
1507
                    $foundDSO = 1;
1508
                    $$templateVars{'origNamefirst0'} = findValue($node, 'givenName');
1509
                    $$templateVars{'origNamelast0'} = findValue($node, 'surName');
1510
                    $$templateVars{'origNameOrg'} = findValue($node, '../organizationName');
1511
                } else {
1512
                    debug("Registry: Recording a creator in loop 2 block B...");
1513
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($node, './givenName');
1514
                    $$templateVars{"origNamelast$aoCount"} =  findValue($node, './surName');
1515
                    $$templateVars{"origRole$aoCount"} = "Originator";
1516
                    $aoCount++;
1517
                }
1518
            }
1519
        }
1520
    }
1521

    
1522
    $results = $doc->findnodes('//dataset/creator/organizationName');
1523
    my $wgroups = $doc->findnodes("//dataset/creator/organizationName[contains(text(),'(NCEAS ')]");
1524
    debug("Registry: Number Org: ".$results->size());
1525
    debug("Registry:  Number WG: ".$wgroups->size());
1526
    if ($results->size() - $wgroups->size() > 3) {
1527
        errMoreThanN("creator/organizationName");    
1528
    } else {
1529
        foreach $node ($results->get_nodelist) {
1530
            my $tempValue = findValue($node,'../organizationName');
1531
            $tempResult = $node->findnodes('../individualName');
1532
            if ($tempResult->size == 0 && $tempValue ne $organization) {
1533
                $$templateVars{'site'} = $tempValue;
1534
            }
1535
        }
1536
        if ($FORM::cfg == 'nceas') {
1537
            my @wg;
1538
            foreach $node ($results->get_nodelist) {
1539
                my $tempValue = findValue($node,'../organizationName');
1540
                $wg[scalar(@wg)] = $tempValue;
1541
            }
1542
            my $projects = getProjectList();
1543
            $$templateVars{'projects'} = $projects;
1544
            $$templateVars{'wg'} = \@wg;
1545
        }
1546
    }
1547

    
1548
    $results = $doc->findnodes('//dataset/metadataProvider');
1549
    if ($results->size() > 11) {
1550
        errMoreThanN("metadataProvider");    
1551
    } else {
1552
        foreach $node ($results->get_nodelist) {
1553
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1554
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in metadataProvider");
1555
        
1556
            $tempResult = $node->findnodes('./individualName');
1557
            if ($tempResult->size > 1) {
1558
                errMoreThanOne("metadataProvider/indvidualName");
1559
            } else {
1560
                foreach $tempNode ($tempResult->get_nodelist) {
1561
                    if ($$templateVars{'providerGivenName'} ne "") {
1562
                        $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1563
                        $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1564
                        $$templateVars{"origRole$aoCount"} = "Metadata Provider";
1565
                        $aoCount++;
1566
                    } else {
1567
                        $$templateVars{'providerGivenName'} =  findValue($tempNode, './givenName');
1568
                        $$templateVars{'providerSurName'} =  findValue($tempNode, './surName');
1569
                    }
1570
                }
1571
            }
1572
        }
1573
    }
1574

    
1575
    $results = $doc->findnodes('//dataset/associatedParty');
1576
    if ($results->size() > 10) {
1577
        errMoreThanN("associatedParty");
1578
    } else {
1579
        foreach $node ($results->get_nodelist) {
1580
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1581
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty");
1582
       
1583
            $tempResult = $node->findnodes('./individualName');
1584
            if ($tempResult->size > 1) {
1585
                errMoreThanOne("associatedParty/indvidualName");
1586
            } else {
1587
                foreach $tempNode ($tempResult->get_nodelist) {
1588
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1589
                    $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1590
                    $$templateVars{"origRole$aoCount"} = findValue($tempNode, '../role');
1591
                    $aoCount++;           
1592
                }
1593
            }
1594
        }
1595
    }
1596

    
1597
    $results = $doc->findnodes('//dataset/publisher');
1598
    if ($results->size() > 10) {
1599
        errMoreThanN("publisher");
1600
    } else {
1601
        foreach $node ($results->get_nodelist) {
1602
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1603
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty");
1604
       
1605
            $tempResult = $node->findnodes('./individualName');
1606
            if ($tempResult->size > 1) {
1607
                errMoreThanOne("publisher/indvidualName");
1608
            } else {
1609
                foreach $tempNode ($tempResult->get_nodelist) {
1610
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1611
                    $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1612
                    $$templateVars{"origRole$aoCount"} = "Publisher";
1613
                    $aoCount++;           
1614
                }
1615
            }
1616
        }
1617
    }
1618

    
1619
    if ($aoCount > 11) {
1620
        errMoreThanN("Additional Originators");
1621
    } 
1622

    
1623
    dontOccur($doc, "./pubDate", "pubDate");
1624
    dontOccur($doc, "./language", "language");
1625
    dontOccur($doc, "./series", "series");
1626

    
1627
    $results = $doc->findnodes('//dataset/abstract');
1628
    if ($results->size() > 1) {
1629
        errMoreThanOne("abstract");
1630
    } else {
1631
        foreach my $node ($results->get_nodelist) {
1632
            dontOccur($node, "./section", "section");
1633
            $$templateVars{'abstract'} = findValueNoChild($node, "para");
1634
        }
1635
    }
1636

    
1637
    $results = $doc->findnodes('//dataset/keywordSet');
1638
    if ($results->size() > 10) {
1639
        errMoreThanN("keywordSet");
1640
    } else {
1641
        my $count = 0;
1642
        foreach $node ($results->get_nodelist) {
1643
            $tempResult = $node->findnodes('./keyword');
1644
            if ($tempResult->size() > 1) {
1645
                errMoreThanOne("keyword");
1646
            } else {
1647
                foreach $tempNode ($tempResult->get_nodelist) {
1648
                    $$templateVars{"keyword$count"} = $tempNode->textContent();
1649
                    if ($tempNode->hasAttributes()) {
1650
                        my @attlist = $tempNode->attributes();
1651
                        $$templateVars{"kwType$count"} = $attlist[0]->value;
1652
                    }  
1653
                 } 
1654
            }
1655
            $$templateVars{"kwTh$count"} = findValue($node, "keywordThesaurus");
1656
            $count++;
1657
        }
1658
    
1659
        while ($count<11) {
1660
            $$templateVars{"kwType$count"} = "none";
1661
            $$templateVars{"kwTh$count"} = "none";
1662
            $count++;
1663
        }
1664
    }
1665

    
1666
    $results = $doc->findnodes('//dataset/additionalInfo');
1667
    if ($results->size() > 1) {
1668
        errMoreThanOne("additionalInfo");
1669
    } else {
1670
        foreach $node ($results->get_nodelist) {
1671
            dontOccur($node, "./section", "section");
1672
            $$templateVars{'addComments'} = findValueNoChild($node, "para");
1673
        }
1674
    }
1675

    
1676
    $$templateVars{'useConstraints'} = "";
1677
    $results = $doc->findnodes('//dataset/intellectualRights');
1678
    if ($results->size() > 1) {
1679
        errMoreThanOne("intellectualRights");
1680
    } else {
1681
        foreach $node ($results->get_nodelist) {
1682
            dontOccur($node, "./section", "section in intellectualRights");
1683

    
1684
            $tempResult = $node->findnodes("para");
1685
            if ($tempResult->size > 2) {
1686
                   errMoreThanN("para");
1687
            } else {
1688
                foreach $tempNode ($tempResult->get_nodelist) {
1689
                    my $childNodes = $tempNode->childNodes;
1690
                    if ($childNodes->size() > 1) {
1691
                        $error ="The tag para in intellectualRights has children which cannot be shown using the form. Please use Morpho to edit this document";    
1692
                        push(@errorMessages, $error);
1693
                        #if ($DEBUG == 1){ print $error."\n";}
1694
                    } else {
1695
                        #print $tempNode->nodeName().":".$tempNode->textContent();
1696
                        #print "\n";
1697
                        if ($$templateVars{'useConstraints'} eq "") {
1698
                            $$templateVars{'useConstraints'} = $tempNode->textContent();
1699
                        } else {
1700
                            $$templateVars{'useConstraintsOther'} = $tempNode->textContent();
1701
                        }
1702
                    }
1703
                }
1704
            }
1705
        }
1706
    }
1707

    
1708
    $results = $doc->findnodes('//dataset/distribution/online');
1709
    if ($results->size() > 1) {
1710
        errMoreThanOne("distribution/online");
1711
    } else {
1712
        foreach my $tempNode ($results->get_nodelist){
1713
            $$templateVars{'url'} = findValue($tempNode, "url");
1714
            dontOccur($tempNode, "./connection", "/distribution/online/connection");
1715
            dontOccur($tempNode, "./connectionDefinition", "/distribution/online/connectionDefinition");
1716
        }
1717
    }
1718

    
1719
    $results = $doc->findnodes('//dataset/distribution/offline');
1720
    if ($results->size() > 1) {
1721
        errMoreThanOne("distribution/online");
1722
    } else {
1723
        foreach my $tempNode ($results->get_nodelist) {
1724
            $$templateVars{'dataMedium'} = findValue($tempNode, "mediumName");
1725
            dontOccur($tempNode, "./mediumDensity", "/distribution/offline/mediumDensity");
1726
            dontOccur($tempNode, "./mediumDensityUnits", "/distribution/offline/mediumDensityUnits");
1727
            dontOccur($tempNode, "./mediumVolume", "/distribution/offline/mediumVolume");
1728
            dontOccur($tempNode, "./mediumFormat", "/distribution/offline/mediumFormat");
1729
            dontOccur($tempNode, "./mediumNote", "/distribution/offline/mediumNote");
1730
        }
1731
    }
1732

    
1733
    dontOccur($doc, "./inline", "//dataset/distribution/inline");
1734

    
1735
    $results = $doc->findnodes('//dataset/coverage');
1736
    if ($results->size() > 1) {
1737
        errMoreThanOne("coverage");
1738
    } else {
1739
        foreach $node ($results->get_nodelist) {
1740
            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");
1741

    
1742
            $tempResult = $node->findnodes('./temporalCoverage');
1743
            if ($tempResult->size > 1) {
1744
                   errMoreThanOne("temporalCoverage");
1745
            } else {
1746
                foreach $tempNode ($tempResult->get_nodelist) {
1747
                    my $x;
1748
                    my $y;
1749
                    my $z;
1750
                    my $tempdate = findValue($tempNode, "rangeOfDates/beginDate/calendarDate");
1751
                    ($x, $y, $z) = split("-", $tempdate); 
1752
                    $$templateVars{'beginningYear'} = $x;
1753
                    $$templateVars{'beginningMonth'} = $y;
1754
                    $$templateVars{'beginningDay'} = $z;
1755
    
1756
                    $tempdate = findValue($tempNode, "rangeOfDates/endDate/calendarDate");
1757
                    ($x, $y, $z) = split("-", $tempdate);
1758
                    $$templateVars{'endingYear'} = $x;
1759
                    $$templateVars{'endingMonth'} = $y;
1760
                    $$templateVars{'endingDay'} = $z;
1761
                
1762
                    $tempdate = "";
1763
                    $tempdate = findValue($tempNode, "singleDateTime/calendarDate");
1764
                    if($tempdate ne ""){
1765
                        ($x, $y, $z) = split("-", $tempdate);
1766
                        $$templateVars{'beginningYear'} = $x;
1767
                        $$templateVars{'beginningMonth'} = $y;
1768
                        $$templateVars{'beginningDay'} = $z;
1769
                    }  
1770
                }
1771
            }
1772

    
1773
            $tempResult = $node->findnodes('./geographicCoverage');
1774
            if ($tempResult->size > 1) {
1775
                errMoreThanOne("geographicCoverage");
1776
            } else {
1777
                foreach $tempNode ($tempResult->get_nodelist) {
1778
                    my $geogdesc = findValue($tempNode, "geographicDescription");
1779
                    debug("Registry: geogdesc from xml is: $geogdesc");
1780
                    $$templateVars{'geogdesc'} = $geogdesc;
1781
                    my $coord = findValue($tempNode, "boundingCoordinates/westBoundingCoordinate");
1782
                    if ($coord > 0) {
1783
                        #print "+";
1784
                        $$templateVars{'hemisphLong1'} = "E";
1785
                    } else {
1786
                        #print "-";
1787
                        eval($coord = $coord * -1);
1788
                        $$templateVars{'hemisphLong1'} = "W";
1789
                    }
1790
                    eval($$templateVars{'longDeg1'} = int($coord));
1791
                    eval($coord = ($coord - int($coord))*60);
1792
                    eval($$templateVars{'longMin1'} = int($coord));
1793
                    eval($coord = ($coord - int($coord))*60);
1794
                    eval($$templateVars{'longSec1'} = int($coord));
1795
                    
1796
                    $coord = findValue($tempNode, "boundingCoordinates/southBoundingCoordinate");
1797
                    if ($coord > 0) {
1798
                        #print "+";
1799
                        $$templateVars{'hemisphLat2'} = "N";
1800
                    } else {
1801
                        #print "-";
1802
                        eval($coord = $coord * -1);
1803
                        $$templateVars{'hemisphLat2'} = "S";
1804
                    }
1805
                    eval($$templateVars{'latDeg2'} = int($coord));
1806
                    eval($coord = ($coord - int($coord))*60);
1807
                    eval($$templateVars{'latMin2'} = int($coord));
1808
                    eval($coord = ($coord - int($coord))*60);
1809
                    eval($$templateVars{'latSec2'} = int($coord));
1810
        
1811
                    $coord = findValue($tempNode, "boundingCoordinates/northBoundingCoordinate");
1812
                    if ($coord > 0) {
1813
                        #print "+";
1814
                        $$templateVars{'hemisphLat1'} = "N";
1815
                    } else {
1816
                        #print "-";
1817
                        eval($coord = $coord * -1);
1818
                        $$templateVars{'hemisphLat1'} = "S";
1819
                    }
1820
                    eval($$templateVars{'latDeg1'} = int($coord));
1821
                    eval($coord = ($coord - int($coord))*60);
1822
                    eval($$templateVars{'latMin1'} = int($coord));
1823
                    eval($coord = ($coord - int($coord))*60);
1824
                    eval($$templateVars{'latSec1'} = int($coord));
1825
        
1826
                    $coord = findValue($tempNode, "boundingCoordinates/eastBoundingCoordinate");
1827
                    if ($coord > 0) {
1828
                        #print "+";
1829
                        $$templateVars{'hemisphLong2'} = "E";
1830
                    } else {
1831
                        #print "-";
1832
                        eval($coord = $coord * -1);
1833
                        $$templateVars{'hemisphLong2'} = "W";
1834
                    }
1835
                    eval($$templateVars{'longDeg2'} = int($coord));
1836
                    eval($coord = ($coord - int($coord))*60);
1837
                    eval($$templateVars{'longMin2'} = int($coord));
1838
                    eval($coord = ($coord - int($coord))*60);
1839
                    eval($$templateVars{'longSec2'} = int($coord));
1840
                }
1841
            }
1842

    
1843
            $tempResult = $node->findnodes('./taxonomicCoverage/taxonomicClassification');
1844
            my $taxonIndex = 0;
1845
            foreach $tempNode ($tempResult->get_nodelist) {
1846
                $taxonIndex++;
1847
                my $taxonRankName = findValue($tempNode, "taxonRankName");
1848
                my $taxonRankValue = findValue($tempNode, "taxonRankValue");
1849
                $$templateVars{"taxonRankName".$taxonIndex} = $taxonRankName;
1850
                $$templateVars{"taxonRankValue".$taxonIndex} = $taxonRankValue;
1851
            }
1852
            $$templateVars{'taxaCount'} = $taxonIndex;
1853
            my $taxaAuth = findValue($node, "./taxonomicCoverage/generalTaxonomicCoverage");
1854
            $$templateVars{'taxaAuth'} = $taxaAuth;
1855
        }
1856
    }
1857
    dontOccur($doc, "./purpose", "purpose");
1858
    dontOccur($doc, "./maintenance", "maintnance");
1859

    
1860
    $results = $doc->findnodes('//dataset/contact/individualName');
1861
    if ($results->size() > 1) {
1862
        errMoreThanOne("contact/individualName");
1863
    } else {
1864
        foreach $node ($results->get_nodelist) {
1865
            dontOccur($node, "../positionName|../onlineURL|../userId", 
1866
              "positionName, onlineURL, userId in contact tag");
1867
            dontOccur($node, "./saluation", "saluation in contact tag");                
1868
        
1869
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1870
            if ($tempResult->size > 0) {
1871
                $$templateVars{'origNamefirstContact'} = findValue($node, 'givenName');
1872
                $$templateVars{'origNamelastContact'} = findValue($node, 'surName');
1873
    
1874
                my $tempResult2 = $node->findnodes('../address');
1875
                if ($tempResult2->size > 1) {
1876
                    errMoreThanOne("address");
1877
                } else {
1878
                    foreach my $tempNode2 ($tempResult2->get_nodelist) {
1879
                        $$templateVars{'origDeliveryContact'} = findValue($tempNode2, 'deliveryPoint');
1880
                        $$templateVars{'origCityContact'} = findValue($tempNode2, 'city');
1881
                        $$templateVars{'origStateContact'} = findValue($tempNode2, 'administrativeArea');
1882
                        $$templateVars{'origZIPContact'} = findValue($tempNode2, 'postalCode');
1883
                        $$templateVars{'origCountryContact'} = findValue($tempNode2, 'country');
1884
                    }
1885
                }
1886
            
1887
                my $tempResult3 = $node->findnodes('../phone');
1888
                if ($tempResult3->size > 2) {
1889
                    errMoreThanN("phone");
1890
                } else {
1891
                    foreach my $tempNode2 ($tempResult3->get_nodelist) {
1892
                        if ($tempNode2->hasAttributes()) {
1893
                            my @attlist = $tempNode2->attributes();
1894
                            if ($attlist[0]->value eq "Fax") {
1895
                                $$templateVars{'origFAXContact'} = $tempNode2->textContent();
1896
                            } else {
1897
                                $$templateVars{'origPhoneContact'} = $tempNode2->textContent();
1898
                            }
1899
                        } else {
1900
                            $$templateVars{'origPhoneContact'} = $tempNode2->textContent();
1901
                        }
1902
                    }
1903
                }
1904
                $$templateVars{'origEmailContact'} = findValue($node, '../electronicMailAddress');
1905
                $$templateVars{'origNameOrgContact'} = findValue($node, '../organizationName');
1906
            } else {
1907
                $$templateVars{'origNamefirstContact'} = findValue($node, 'givenName');
1908
                $$templateVars{'origNamelastContact'} = findValue($node, 'surName');
1909
                $$templateVars{'origNameOrgContact'} = findValue($node, '../organizationName');
1910
            }
1911
        }
1912
    }
1913
    
1914
    $results = $doc->findnodes(
1915
            '//dataset/methods/methodStep/description/section');
1916
    debug("Registry: Number methods: ".$results->size());
1917
    if ($results->size() > 1) {
1918
        errMoreThanN("methods/methodStep/description/section");    
1919
    } else {
1920

    
1921
        my @methodPara;
1922
        foreach $node ($results->get_nodelist) {
1923
            my @children = $node->childNodes;
1924
            for (my $i = 0; $i < scalar(@children); $i++) {
1925
                debug("Registry: Method child loop ($i)");
1926
                my $child = $children[$i];
1927
                if ($child->nodeName eq 'title') {
1928
                    my $title = $child->textContent();
1929
                    debug("Registry: Method title ($title)");
1930
                    $$templateVars{'methodTitle'} = $title;
1931
                } elsif ($child->nodeName eq 'para') {
1932
                    my $para = $child->textContent();
1933
                    debug("Registry: Method para ($para)");
1934
                    $methodPara[scalar(@methodPara)] = $para;
1935
                }
1936
            }
1937
        }
1938
        if (scalar(@methodPara) > 0) {
1939
            $$templateVars{'methodPara'} = \@methodPara;
1940
        }
1941
    }
1942

    
1943
    $results = $doc->findnodes(
1944
            '//dataset/methods/sampling/studyExtent/description/para');
1945
    if ($results->size() > 1) {
1946
        errMoreThanN("methods/sampling/studyExtent/description/para");    
1947
    } else {
1948
        foreach $node ($results->get_nodelist) {
1949
            my $studyExtentDescription = $node->textContent();
1950
            $$templateVars{'studyExtentDescription'} = $studyExtentDescription;
1951
        }
1952
    }
1953

    
1954
    $results = $doc->findnodes(
1955
            '//dataset/methods/sampling/samplingDescription/para');
1956
    if ($results->size() > 1) {
1957
        errMoreThanN("methods/sampling/samplingDescription/para");    
1958
    } else {
1959
        foreach $node ($results->get_nodelist) {
1960
            my $samplingDescription = $node->textContent();
1961
            $$templateVars{'samplingDescription'} = $samplingDescription;
1962
        }
1963
    }
1964

    
1965
    dontOccur($doc, "//methodStep/citation", "methodStep/citation");
1966
    dontOccur($doc, "//methodStep/protocol", "methodStep/protocol");
1967
    dontOccur($doc, "//methodStep/instrumentation", "methodStep/instrumentation");
1968
    dontOccur($doc, "//methodStep/software", "methodStep/software");
1969
    dontOccur($doc, "//methodStep/subStep", "methodStep/subStep");
1970
    dontOccur($doc, "//methodStep/dataSource", "methodStep/dataSource");
1971
    dontOccur($doc, "//methods/qualityControl", "methods/qualityControl");
1972

    
1973
    dontOccur($doc, "//methods/sampling/spatialSamplingUnits", "methods/sampling/spatialSamplingUnits");
1974
    dontOccur($doc, "//methods/sampling/citation", "methods/sampling/citation");
1975
    dontOccur($doc, "./pubPlace", "pubPlace");
1976
    dontOccur($doc, "./project", "project");
1977
    
1978
    dontOccur($doc, "./dataTable", "dataTable");
1979
    dontOccur($doc, "./spatialRaster", "spatialRaster");
1980
    dontOccur($doc, "./spatialVector", "spatialVector");
1981
    dontOccur($doc, "./storedProcedure", "storedProcedure");
1982
    dontOccur($doc, "./view", "view");
1983
    dontOccur($doc, "./otherEntity", "otherEntity");
1984
    dontOccur($doc, "./references", "references");
1985
    
1986
    dontOccur($doc, "//citation", "citation");
1987
    dontOccur($doc, "//software", "software");
1988
    dontOccur($doc, "//protocol", "protocol");
1989
    dontOccur($doc, "//additionalMetadata", "additionalMetadata");    
1990
}
1991

    
1992
################################################################################
1993
# 
1994
# Delete the eml file that has been requested for deletion. 
1995
#
1996
################################################################################
1997
sub deleteData {
1998
    my $deleteAll = shift;
1999
    
2000
    # create metacat instance
2001
    my $metacat;
2002
    my $docid = $FORM::docid;
2003
    
2004
    $metacat = Metacat->new();
2005
    if ($metacat) {
2006
        $metacat->set_options( metacatUrl => $metacatUrl );
2007
    } else {
2008
        #die "failed during metacat creation\n";
2009
        push(@errorMessages, "Failed during metacat creation.");
2010
    }
2011

    
2012
    # Login to metacat
2013
    my $userDN = $FORM::username;
2014
    my $userOrg = $FORM::organization;
2015
    my $userPass = $FORM::password;
2016
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
2017
    
2018
    my $errorMessage = "";
2019
    my $response = $metacat->login($dname, $userPass);
2020

    
2021
    if (! $response) {
2022
    # Could not login
2023
        push(@errorMessages, $metacat->getMessage());
2024
        push(@errorMessages, "Failed during login.\n");
2025

    
2026
    } else {
2027
    #Able to login - try to delete the file    
2028

    
2029
    my $parser;
2030
    my @fileArray;
2031
    my $httpMessage;
2032
    my $xmldoc;
2033
    my $doc;
2034
    my $pushDoc;
2035
    my $alreadyInArray;
2036
    my $findType;
2037
        my $node;
2038
    my $response; 
2039
    my $element;
2040

    
2041
    push (@fileArray, $docid);
2042
    $parser = XML::LibXML->new();
2043

    
2044
        $httpMessage = $metacat->read($docid);
2045
    $doc = $httpMessage->content();    
2046
    $xmldoc = $parser->parse_string($doc);
2047

    
2048
    if ($xmldoc eq "") {
2049
        $error ="Error in parsing the eml document";
2050
        push(@errorMessages, $error);
2051
    } else {
2052

    
2053
        $findType = $xmldoc->findnodes('//dataset/identifier');
2054
        if($findType->size() > 0){
2055
        # This is a eml beta6 document
2056
        # Delete the documents mentioned in triples also
2057
        
2058
        $findType = $xmldoc->findnodes('//dataset/triple');
2059
        if($findType->size() > 0){
2060
            foreach $node ($findType->get_nodelist){
2061
            $pushDoc = findValue($node, 'subject');
2062
            
2063
            # If the file is already in the @fileArray then do not add it 
2064
            $alreadyInArray = 0;
2065
            foreach $element (@fileArray){
2066
                if($element eq $pushDoc){
2067
                $alreadyInArray = 1;
2068
                }
2069
            }
2070
            
2071
            if(!$alreadyInArray){
2072
                # If not already in array then delete the file. 
2073
                push (@fileArray, $pushDoc);
2074
                $response = $metacat->delete($pushDoc);
2075
                
2076
                if (! $response) {
2077
                # Could not delete
2078
                #push(@errorMessages, $response);
2079
                push(@errorMessages, $metacat->getMessage());
2080
                push(@errorMessages, "Failed during deleting $pushDoc. Please check if you are authorized to delete this document.\n");
2081
                }
2082
            }
2083
            }
2084
        }
2085
        }
2086
    }
2087
    
2088
    # Delete the main document. 
2089
    if($deleteAll){
2090
        $response = $metacat->delete($docid);  
2091
        if (! $response) {
2092
        # Could not delete
2093
        #push(@errorMessages, $response);
2094
        push(@errorMessages, $metacat->getMessage());
2095
        push(@errorMessages, "Failed during deleting $docid. Please check if you are authorized to delete this document.\n");
2096
        }
2097
    }
2098
    }
2099
    
2100
    if (scalar(@errorMessages)) {
2101
    # If any errors, print them in the response template 
2102
    $$templateVars{'status'} = 'failure';
2103
    $$templateVars{'errorMessages'} = \@errorMessages;
2104
    $error = 1;
2105
    }
2106
    
2107
    # Process the response template
2108
    if($deleteAll){
2109

    
2110
    $$templateVars{'function'} = "deleted";
2111
    $$templateVars{'section'} = "Deletion Status";
2112
    $template->process( $responseTemplate, $templateVars);
2113
    }
2114
}
2115

    
2116

    
2117
################################################################################
2118
# 
2119
# Do data validation and send the data to confirm data template.
2120
#
2121
################################################################################
2122
sub toConfirmData{
2123
    # Check if any invalid parameters
2124
 
2125
    my $invalidParams;
2126
    if (! $error) {
2127
    $invalidParams = validateParameters(0);
2128
    if (scalar(@$invalidParams)) {
2129
        $$templateVars{'status'} = 'failure';
2130
        $$templateVars{'invalidParams'} = $invalidParams;
2131
        $error = 1;
2132
    }
2133
    }
2134

    
2135
    if (! $error) {
2136
    # If no errors, then print out data in confirm Data template
2137

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

    
2339
    $$templateVars{'taxaCount'} = $FORM::taxaCount;
2340
    foreach my $trn (param()) {
2341
        if ($trn =~ /taxonRankName/) {
2342
            my $taxIndex = $trn;
2343
            $taxIndex =~ s/taxonRankName//; # get the index of the parameter 0, ..., 10
2344
            my $trv = "taxonRankValue".$taxIndex;
2345
            if ( $taxIndex =~ /[0-9]/ ){
2346
                if (hasContent(param($trn)) && hasContent(param($trv))) {
2347
                    debug("Registry processing taxon: $trn = ".param($trn)." $trv = ".param($trv));
2348
                    $$templateVars{$trn} = param($trn);
2349
                    $$templateVars{$trv} = param($trv);
2350
                }
2351
            }
2352
        }
2353
    }
2354
    $$templateVars{'taxaAuth'} = $FORM::taxaAuth;
2355

    
2356
    $$templateVars{'methodTitle'} = $FORM::methodTitle;
2357
    $$templateVars{'methodPara'} = \@FORM::methodPara;
2358
    $$templateVars{'studyExtentDescription'} = $FORM::studyExtentDescription;
2359
    $$templateVars{'samplingDescription'} = $FORM::samplingDescription;
2360
    $$templateVars{'docid'} = $FORM::docid;
2361

    
2362
    $$templateVars{'section'} = "Confirm Data";
2363
    $template->process( $confirmDataTemplate, $templateVars);
2364

    
2365
    } else{    
2366
    # Errors from validation function. print the errors out using the response template
2367
    if (scalar(@errorMessages)) {
2368
        $$templateVars{'status'} = 'failure';
2369
        $$templateVars{'errorMessages'} = \@errorMessages;
2370
        $error = 1;
2371
    }
2372
        # Create our HTML response and send it back
2373
    $$templateVars{'function'} = "submitted";
2374
    $$templateVars{'section'} = "Submission Status";
2375
    $template->process( $responseTemplate, $templateVars);
2376
    }
2377
}
2378

    
2379

    
2380
################################################################################
2381
# 
2382
# From confirm Data template - user wants to make some changes.
2383
#
2384
################################################################################
2385
sub confirmDataToReEntryData{
2386
    my @sortedSites;
2387
    foreach my $site (sort @sitelist) {
2388
        push(@sortedSites, $site);
2389
    }
2390

    
2391
    $$templateVars{'siteList'} = \@sortedSites;
2392
    $$templateVars{'section'} = "Re-Entry Form";
2393

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

    
2551
    $$templateVars{'form'} = 're_entry';
2552
    $template->process( $entryFormTemplate, $templateVars);
2553
}
2554

    
2555

    
2556
################################################################################
2557
# 
2558
# check if there is multiple occurence of the given tag and find its value.
2559
#
2560
################################################################################
2561

    
2562
sub findValue {
2563
    my $node = shift;
2564
    my $value = shift;
2565
    my $result;
2566
    my $tempNode;
2567

    
2568
    $result = $node->findnodes("./$value");
2569
    if ($result->size > 1) {
2570
        errMoreThanOne("$value");
2571
    } else {
2572
        foreach $tempNode ($result->get_nodelist){
2573
            #print $tempNode->nodeName().":".$tempNode->textContent();
2574
            #print "\n";
2575
            return $tempNode->textContent();
2576
        }
2577
    }
2578
}
2579

    
2580

    
2581
################################################################################
2582
# 
2583
# check if given tags has any children. if not return the value
2584
#
2585
################################################################################
2586
sub findValueNoChild {
2587
    my $node = shift;
2588
    my $value = shift;
2589
    my $tempNode;
2590
    my $childNodes;
2591
    my $result;
2592
    my $error;
2593

    
2594
    $result = $node->findnodes("./$value");
2595
    if($result->size > 1){
2596
       errMoreThanOne("$value");
2597
    } else {
2598
        foreach $tempNode ($result->get_nodelist) {
2599
            $childNodes = $tempNode->childNodes;
2600
            if ($childNodes->size() > 1) {
2601
                $error ="The tag $value has children which cannot be shown using the form. Please use Morpho to edit this document";    
2602
                push(@errorMessages, $error);
2603
                #if ($DEBUG == 1){ print $error."\n";}
2604
            } else {
2605
                #print $tempNode->nodeName().":".$tempNode->textContent();
2606
                #print "\n";
2607
                return $tempNode->textContent();
2608
            }
2609
        }
2610
    }
2611
}
2612

    
2613

    
2614
################################################################################
2615
# 
2616
# check if given tags are children of given node.
2617
#
2618
################################################################################
2619
sub dontOccur {
2620
    my $node = shift;
2621
    my $value = shift;
2622
    my $errVal = shift;
2623

    
2624
    my $result = $node->findnodes("$value");
2625
    if($result->size > 0){
2626
        $error ="One of the following tags found: $errVal. Please use Morpho to edit this document";
2627
        push(@errorMessages, $error."\n");
2628
        #if ($DEBUG == 1){ print $error;}
2629
    } 
2630
}
2631

    
2632

    
2633
################################################################################
2634
# 
2635
# print out error for more than one occurence of a given tag
2636
#
2637
################################################################################
2638
sub errMoreThanOne {
2639
    my $value = shift;
2640
    my $error ="More than one occurence of the tag $value found. Please use Morpho to edit this document";
2641
    push(@errorMessages, $error."\n");
2642
    # if ($DEBUG == 1){ print $error;}
2643
}
2644

    
2645

    
2646
################################################################################
2647
# 
2648
# print out error for more than given number of occurences of a given tag
2649
#
2650
################################################################################
2651
sub errMoreThanN {
2652
    my $value = shift;
2653
    my $error ="More occurences of the tag $value found than that can be shown in the form. Please use Morpho to edit this document";
2654
    push(@errorMessages, $error);
2655
    #if ($DEBUG == 1){ print $error."\n";}
2656
}
2657

    
2658

    
2659
################################################################################
2660
# 
2661
# convert coord to degrees, minutes and seconds form. 
2662
#
2663
################################################################################
2664
#sub convertCoord {
2665
#    my $wx = shift;
2666
#    print $deg." ".$min." ".$sec;
2667
#    print "\n";
2668
#}
2669

    
2670

    
2671
################################################################################
2672
# 
2673
# print debugging messages to stderr
2674
#
2675
################################################################################
2676
sub debug {
2677
    my $msg = shift;
2678
    
2679
    if ($debug) {
2680
        print STDERR "$msg\n";
2681
    }
2682
}
2683

    
2684
################################################################################
2685
# 
2686
# get the list of projects
2687
#
2688
################################################################################
2689
sub getProjectList {
2690
    
2691
    use NCEAS::AdminDB;
2692
    my $admindb = NCEAS::AdminDB->new();
2693
    $admindb->connect($nceas_db, $nceas_db_user, $nceas_db_password);
2694
    my $projects = $admindb->getProjects();
2695
    #my $projects = getTestProjectList();
2696
    return $projects;
2697
}
2698

    
2699
################################################################################
2700
# 
2701
# get a test list of projects for use only in testing where the NCEAS
2702
# admin db is not available.
2703
#
2704
################################################################################
2705
sub getTestProjectList {
2706
    # This block is for testing only!  Remove for production use
2707
    my @row1;
2708
    $row1[0] = 6000; $row1[1] = 'Andelman'; $row1[2] = 'Sandy'; $row1[3] = 'The very long and windy path to an apparent ecological conclusion: statistics lie';
2709
    my @row2; 
2710
    $row2[0] = 7000; $row2[1] = 'Bascompte'; $row2[2] = 'Jordi'; $row2[3] = 'Postdoctoral Fellow';
2711
    my @row3; 
2712
    $row3[0] = 7001; $row3[1] = 'Hackett'; $row3[2] = 'Edward'; $row3[3] = 'Sociology rules the world';
2713
    my @row4; 
2714
    $row4[0] = 7002; $row4[1] = 'Jones'; $row4[2] = 'Matthew'; $row4[3] = 'Informatics rules the world';
2715
    my @row5; 
2716
    $row5[0] = 7003; $row5[1] = 'Schildhauer'; $row5[2] = 'Mark'; $row5[3] = 'Excel rocks my world, assuming a, b, and c';
2717
    my @row6; 
2718
    $row6[0] = 7004; $row6[1] = 'Rogers'; $row6[2] = 'Bill'; $row6[3] = 'Graduate Intern';
2719
    my @row7; 
2720
    $row7[0] = 7005; $row7[1] = 'Zedfried'; $row7[2] = 'Karl'; $row7[3] = 'A multivariate analysis of thing that go bump in the night';
2721
    my @projects;
2722
    $projects[0] = \@row1;
2723
    $projects[1] = \@row2;
2724
    $projects[2] = \@row3;
2725
    $projects[3] = \@row4;
2726
    $projects[4] = \@row5;
2727
    $projects[5] = \@row6;
2728
    $projects[6] = \@row7;
2729
    return \@projects;
2730
}
    (1-1/1)