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-07 15:13:11 -0800 (Wed, 07 Jan 2004) $'
8
# '$Revision: 1993 $' 
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 choose. 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
    push(@invalidParams, 
653
        "You must provide a method description if you provide a study extent description.")
654
        if (hasContent($FORM::studyExtentDescription) && !(scalar(@FORM::methodPara) > 0));
655
    push(@invalidParams, 
656
        "You must provide both a study extent description and a sampling description, or neither.")
657
        unless (hasContent($FORM::studyExtentDescription) && hasContent($FORM::samplingDescription));
658

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

    
675
    return \@invalidParams;
676
}
677

    
678
################################################################################
679
# 
680
# Validate the parameters username and password.
681
#
682
################################################################################
683
sub validateUserPass {
684
    my $userDN = $FORM::username;
685
    my $userOrg = $FORM::organization;
686
    my $userPass = $FORM::password;
687
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
688

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

    
700

    
701
################################################################################
702
# 
703
# utility function to determine if a paramter is defined and not an empty string
704
#
705
################################################################################
706
sub hasContent {
707
    my $param = shift;
708

    
709
    my $paramHasContent;
710
    if (!defined($param) || $param eq '') { 
711
        $paramHasContent = 0;
712
    } else {
713
        $paramHasContent = 1;
714
    }
715
    return $paramHasContent;
716
}
717

    
718

    
719
################################################################################
720
# 
721
# Create the XML document from the HTML form input
722
# returns the XML document as a string
723
#
724
################################################################################
725
sub createXMLDocument {
726

    
727
    my $orig  = "";
728
    my $role  = "associatedParty";
729
    my $creat = "";
730
    my $metaP = "";
731
    my $apart = "";
732
    my $cont  = "";
733
    my $publ  = "";
734
    my $dso   = "";
735
    my $gmt = gmtime($now);
736
    my $doc =  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
737

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

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

    
760
    if (hasContent($FORM::origNamelast0)) {
761
    $role = "creator";
762
        $orig .= "<individualName>\n";
763
        $orig .= "<givenName>$FORM::origNamefirst0</givenName>\n";
764
        $orig .= "<surName>$FORM::origNamelast0</surName>\n";
765
        $orig .= "</individualName>\n";
766
    }
767

    
768
    if (hasContent($FORM::origNameOrg)) {
769
        $orig .= "<organizationName>$FORM::origNameOrg</organizationName>\n";
770
    }
771

    
772
    if (hasContent($FORM::origDelivery) || hasContent($FORM::origCity) ||
773
        (hasContent($FORM::origState   ) &&
774
        ($FORM::origState !~ "Select state here.")) ||
775
        hasContent($FORM::origStateOther) ||
776
        hasContent($FORM::origZIP ) || hasContent($FORM::origCountry)) {
777
        $orig .= "<address>\n";
778

    
779
        if (hasContent($FORM::origDelivery)) {
780
            $orig .= "<deliveryPoint>$FORM::origDelivery</deliveryPoint>\n";
781
        }
782
        if (hasContent($FORM::origCity)) {
783
            $orig .= "<city>$FORM::origCity</city>\n";
784
        }
785

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

    
803
    if (hasContent($FORM::origPhone)) {
804
        $orig .= "<phone>$FORM::origPhone</phone>\n";
805
    }
806
    if (hasContent($FORM::origFAX)) {
807
        $orig .= "<phone phonetype=\"Fax\">$FORM::origFAX</phone>\n";
808
    }
809
    if (hasContent($FORM::origEmail)) {
810
        $orig .= "<electronicMailAddress>$FORM::origEmail";
811
        $orig .= "</electronicMailAddress>\n";
812
    }
813
    $dso = "<$role>\n$orig</$role>\n";
814
    
815
    $creat .= $dso;
816

    
817
    if ($FORM::useOrigAddress) {
818
        # Add a contact originator like the original with a different role
819
            $cont .= "<contact>\n";
820
        $cont .= $orig;
821
        $cont .= "</contact>\n";
822
    } else {
823
        $cont .= "<contact>\n";
824

    
825
        $cont .= "<individualName>\n";
826
        $cont .= "<givenName>$FORM::origNamefirstContact</givenName>\n";
827
        $cont .= "<surName>$FORM::origNamelastContact</surName>\n";
828
        $cont .= "</individualName>\n";
829
 
830
    if (hasContent($FORM::origNameOrgContact)) {
831
        $cont .= "<organizationName>$FORM::origNameOrgContact</organizationName>\n";
832
    }
833

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

    
878
    $metaP .= "<metadataProvider>\n";
879
    $metaP .= "<individualName>\n";
880
    $metaP .= "<givenName>$FORM::providerGivenName</givenName>\n";
881
    $metaP .= "<surName>$FORM::providerSurName</surName>\n";
882
    $metaP .= "</individualName>\n";
883
    $metaP .= "</metadataProvider>\n";
884

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

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

    
943
    $creat .= "<creator>\n";
944
    $creat .= "<organizationName>$FORM::site</organizationName>\n";
945
    $creat .= "</creator>\n";
946

    
947
    $creat .= "<creator>\n";
948
    $creat .= "<organizationName>$organization</organizationName>\n";
949
    $creat .= "</creator>\n";
950

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

    
962
    $doc .= "<abstract>\n";
963
    $doc .= "<para>$FORM::abstract</para>\n";
964
    $doc .= "</abstract>\n";
965

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

    
995
    if (hasContent($FORM::addComments)) {
996
        $doc .= "<additionalInfo>\n";
997
        $doc .= "<para>$FORM::addComments</para>\n";
998
        $doc .= "</additionalInfo>\n";
999
    }
1000

    
1001
    if (hasContent($FORM::useConstraints) || 
1002
        hasContent($FORM::useConstraintsOther)) {
1003
        $doc .= "<intellectualRights>\n";
1004
        if (hasContent($FORM::useConstraints)) {
1005
            $doc .= "<para>$FORM::useConstraints</para>\n";
1006
        }
1007
        if (hasContent($FORM::useConstraintsOther)) {
1008
            $doc .= "<para>$FORM::useConstraintsOther</para>\n";
1009
        }
1010
        $doc .= "</intellectualRights>\n";
1011
    }
1012

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

    
1032

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

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

    
1086
    $doc .= "</temporalCoverage>\n";
1087
    
1088
    $doc .= "<geographicCoverage>\n";
1089
    $doc .= "<geographicDescription>$FORM::geogdesc</geographicDescription>\n";
1090
    $doc .= "<boundingCoordinates>\n";
1091

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

    
1124
    $hemisph = ($hemisphLong2 eq "W") ? -1 : 1;
1125
    $doc .= "<eastBoundingCoordinate>";
1126
    $doc .= $hemisph * ($longDeg2 + (60*$longMin2+$longSec2)/3600);
1127
    $doc .= "</eastBoundingCoordinate>\n";
1128

    
1129
    $hemisph = ($hemisphLat1 eq "S") ? -1 : 1;
1130
    $doc .= "<northBoundingCoordinate>";
1131
    $doc .= $hemisph * ($latDeg1 + (60*$latMin1+$latSec1)/3600);
1132
    $doc .= "</northBoundingCoordinate>\n";
1133

    
1134
    $hemisph = ($hemisphLat2 eq "S") ? -1 : 1;
1135
    $doc .= "<southBoundingCoordinate>";
1136
    $doc .= $hemisph * ($latDeg2 + (60*$latMin2+$latSec2)/3600);
1137
    $doc .= "</southBoundingCoordinate>\n";
1138

    
1139
    $doc .= "</boundingCoordinates>\n";
1140
    $doc .= "</geographicCoverage>\n";
1141

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

    
1170
    $doc .= "</coverage>\n";
1171

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

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

    
1214
    return $doc;
1215
}
1216

    
1217

    
1218
################################################################################
1219
# 
1220
# send an email message notifying the moderator of a new submission 
1221
#
1222
################################################################################
1223
sub sendNotification {
1224
    my $identifier = shift;
1225
    my $mailhost = shift;
1226
    my $sender = shift;
1227
    my $recipient = shift;
1228

    
1229
    my $smtp = Net::SMTP->new($mailhost);
1230
    $smtp->mail($sender);
1231
    $smtp->to($recipient);
1232

    
1233
    my $message = <<"    ENDOFMESSAGE";
1234
    To: $recipient
1235
    From: $sender
1236
    Subject: New data submission
1237
    
1238
    Data was submitted to the data registry.  
1239
    The identifying information for the new data set is:
1240

    
1241
    Identifier: $identifier
1242
    Title: $FORM::title
1243
    Submitter: $FORM::providerGivenName $FORM::providerSurName
1244

    
1245
    Please review the submmission and grant public read access if appropriate.
1246
    Thanks
1247
    
1248
    ENDOFMESSAGE
1249
    $message =~ s/^[ \t\r\f]+//gm;
1250

    
1251
    $smtp->data($message);
1252
    $smtp->quit;
1253
}
1254

    
1255

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

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

    
1291
    #$tempfile = $xslConvDir.$docid;
1292
    #push (@fileArray, $tempfile);
1293

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

    
1339
            # Read the main document. 
1340

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

    
1359
            #$results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1360
            $results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1361

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

    
1372
            getFormValuesFromEml2($resultsheet);
1373
            
1374
            # Delete the files written earlier. 
1375
            unlink @fileArray;
1376

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

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

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

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

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

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

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

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

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

    
1614
    if ($aoCount > 11) {
1615
        errMoreThanN("Additional Originators");
1616
    } 
1617

    
1618
    dontOccur($doc, "./pubDate", "pubDate");
1619
    dontOccur($doc, "./language", "language");
1620
    dontOccur($doc, "./series", "series");
1621

    
1622
    $results = $doc->findnodes('//dataset/abstract');
1623
    if ($results->size() > 1) {
1624
        errMoreThanOne("abstract");
1625
    } else {
1626
        foreach my $node ($results->get_nodelist) {
1627
            dontOccur($node, "./section", "section");
1628
            $$templateVars{'abstract'} = findValueNoChild($node, "para");
1629
        }
1630
    }
1631

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

    
1661
    $results = $doc->findnodes('//dataset/additionalInfo');
1662
    if ($results->size() > 1) {
1663
        errMoreThanOne("additionalInfo");
1664
    } else {
1665
        foreach $node ($results->get_nodelist) {
1666
            dontOccur($node, "./section", "section");
1667
            $$templateVars{'addComments'} = findValueNoChild($node, "para");
1668
        }
1669
    }
1670

    
1671
    $$templateVars{'useConstraints'} = "";
1672
    $results = $doc->findnodes('//dataset/intellectualRights');
1673
    if ($results->size() > 1) {
1674
        errMoreThanOne("intellectualRights");
1675
    } else {
1676
        foreach $node ($results->get_nodelist) {
1677
            dontOccur($node, "./section", "section in intellectualRights");
1678

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

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

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

    
1728
    dontOccur($doc, "./inline", "//dataset/distribution/inline");
1729

    
1730
    $results = $doc->findnodes('//dataset/coverage');
1731
    if ($results->size() > 1) {
1732
        errMoreThanOne("coverage");
1733
    } else {
1734
        foreach $node ($results->get_nodelist) {
1735
            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");
1736

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

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

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

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

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

    
1938
    $results = $doc->findnodes(
1939
            '//dataset/methods/sampling/studyExtent/description/para');
1940
    if ($results->size() > 1) {
1941
        errMoreThanN("methods/sampling/studyExtent/description/para");    
1942
    } else {
1943
        foreach $node ($results->get_nodelist) {
1944
            my $studyExtentDescription = $node->textContent();
1945
            $$templateVars{'studyExtentDescription'} = $studyExtentDescription;
1946
        }
1947
    }
1948

    
1949
    $results = $doc->findnodes(
1950
            '//dataset/methods/sampling/samplingDescription/para');
1951
    if ($results->size() > 1) {
1952
        errMoreThanN("methods/sampling/samplingDescription/para");    
1953
    } else {
1954
        foreach $node ($results->get_nodelist) {
1955
            my $samplingDescription = $node->textContent();
1956
            $$templateVars{'samplingDescription'} = $samplingDescription;
1957
        }
1958
    }
1959

    
1960
    dontOccur($doc, "//methodStep/citation", "methodStep/citation");
1961
    dontOccur($doc, "//methodStep/protocol", "methodStep/protocol");
1962
    dontOccur($doc, "//methodStep/instrumentation", "methodStep/instrumentation");
1963
    dontOccur($doc, "//methodStep/software", "methodStep/software");
1964
    dontOccur($doc, "//methodStep/subStep", "methodStep/subStep");
1965
    dontOccur($doc, "//methodStep/dataSource", "methodStep/dataSource");
1966
    dontOccur($doc, "//methods/qualityControl", "methods/qualityControl");
1967

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

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

    
2007
    # Login to metacat
2008
    my $userDN = $FORM::username;
2009
    my $userOrg = $FORM::organization;
2010
    my $userPass = $FORM::password;
2011
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
2012
    
2013
    my $errorMessage = "";
2014
    my $response = $metacat->login($dname, $userPass);
2015

    
2016
    if (! $response) {
2017
    # Could not login
2018
        push(@errorMessages, $metacat->getMessage());
2019
        push(@errorMessages, "Failed during login.\n");
2020

    
2021
    } else {
2022
    #Able to login - try to delete the file    
2023

    
2024
    my $parser;
2025
    my @fileArray;
2026
    my $httpMessage;
2027
    my $xmldoc;
2028
    my $doc;
2029
    my $pushDoc;
2030
    my $alreadyInArray;
2031
    my $findType;
2032
        my $node;
2033
    my $response; 
2034
    my $element;
2035

    
2036
    push (@fileArray, $docid);
2037
    $parser = XML::LibXML->new();
2038

    
2039
        $httpMessage = $metacat->read($docid);
2040
    $doc = $httpMessage->content();    
2041
    $xmldoc = $parser->parse_string($doc);
2042

    
2043
    if ($xmldoc eq "") {
2044
        $error ="Error in parsing the eml document";
2045
        push(@errorMessages, $error);
2046
    } else {
2047

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

    
2105
    $$templateVars{'function'} = "deleted";
2106
    $$templateVars{'section'} = "Deletion Status";
2107
    $template->process( $responseTemplate, $templateVars);
2108
    }
2109
}
2110

    
2111

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

    
2130
    if (! $error) {
2131
    # If no errors, then print out data in confirm Data template
2132

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

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

    
2351
    $$templateVars{'methodTitle'} = $FORM::methodTitle;
2352
    $$templateVars{'methodPara'} = \@FORM::methodPara;
2353
    $$templateVars{'studyExtentDescription'} = $FORM::studyExtentDescription;
2354
    $$templateVars{'samplingDescription'} = $FORM::samplingDescription;
2355
    $$templateVars{'docid'} = $FORM::docid;
2356

    
2357
    $$templateVars{'section'} = "Confirm Data";
2358
    $template->process( $confirmDataTemplate, $templateVars);
2359

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

    
2374

    
2375
################################################################################
2376
# 
2377
# From confirm Data template - user wants to make some changes.
2378
#
2379
################################################################################
2380
sub confirmDataToReEntryData{
2381
    my @sortedSites;
2382
    foreach my $site (sort @sitelist) {
2383
        push(@sortedSites, $site);
2384
    }
2385

    
2386
    $$templateVars{'siteList'} = \@sortedSites;
2387
    $$templateVars{'section'} = "Re-Entry Form";
2388

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

    
2546
    $$templateVars{'form'} = 're_entry';
2547
    $template->process( $entryFormTemplate, $templateVars);
2548
}
2549

    
2550

    
2551
################################################################################
2552
# 
2553
# check if there is multiple occurence of the given tag and find its value.
2554
#
2555
################################################################################
2556

    
2557
sub findValue {
2558
    my $node = shift;
2559
    my $value = shift;
2560
    my $result;
2561
    my $tempNode;
2562

    
2563
    $result = $node->findnodes("./$value");
2564
    if ($result->size > 1) {
2565
        errMoreThanOne("$value");
2566
    } else {
2567
        foreach $tempNode ($result->get_nodelist){
2568
            #print $tempNode->nodeName().":".$tempNode->textContent();
2569
            #print "\n";
2570
            return $tempNode->textContent();
2571
        }
2572
    }
2573
}
2574

    
2575

    
2576
################################################################################
2577
# 
2578
# check if given tags has any children. if not return the value
2579
#
2580
################################################################################
2581
sub findValueNoChild {
2582
    my $node = shift;
2583
    my $value = shift;
2584
    my $tempNode;
2585
    my $childNodes;
2586
    my $result;
2587
    my $error;
2588

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

    
2608

    
2609
################################################################################
2610
# 
2611
# check if given tags are children of given node.
2612
#
2613
################################################################################
2614
sub dontOccur {
2615
    my $node = shift;
2616
    my $value = shift;
2617
    my $errVal = shift;
2618

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

    
2627

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

    
2640

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

    
2653

    
2654
################################################################################
2655
# 
2656
# convert coord to degrees, minutes and seconds form. 
2657
#
2658
################################################################################
2659
#sub convertCoord {
2660
#    my $wx = shift;
2661
#    print $deg." ".$min." ".$sec;
2662
#    print "\n";
2663
#}
2664

    
2665

    
2666
################################################################################
2667
# 
2668
# print debugging messages to stderr
2669
#
2670
################################################################################
2671
sub debug {
2672
    my $msg = shift;
2673
    
2674
    if ($debug) {
2675
        print STDERR "$msg\n";
2676
    }
2677
}
2678

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

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