Project

General

Profile

« Previous | Next » 

Revision 3422

Added by walbridge about 17 years ago

Added submission of data files to the registry. New parameter 'hasUpload' can be set on a per-skin basis to enable the uploading of data objects to be associated with a metadata document. NCEAS skin is using this by default, to be changed in the future for other skins.

Refactored XML creation in register-dataset.cgi to use function stubs, to allow us flexibility in document creation.

View differences:

register-dataset.cgi
36 36
use Net::SMTP;
37 37
use CGI qw/:standard :html3/;
38 38
use CGI::Session;
39
use Digest::SHA1;
40
use File::stat;
41
use File::Basename;
39 42
use strict;
40 43

  
41 44
# Global configuration paramters
......
83 86
$config->define("hasSpatial", { DEFAULT => 'true'} );
84 87
$config->define("hasTaxonomic", { DEFAULT => 'true'} );
85 88
$config->define("hasMethod", { DEFAULT => 'true'} );
89
$config->define("hasUpload", { DEFAULT => 'false'} );
86 90
$config->define("temporalRequired", { DEFAULT => 'true'} );
87 91
$config->define("spatialRequired", { DEFAULT => 'true'} );
88 92
$config->define("contactEmailAddressRequired", { DEFAULT => 'false'} );
......
101 105
$config->define("responseTemplate", { DEFAULT => 'crap.tmpl'} );
102 106
$config->define("entryFormTemplate", { DEFAULT => 'crap.tmpl'} );
103 107
$config->define("guideTemplate", { DEFAULT => 'crap.tmpl'} );
104
$config->define("loginFormTemplate", { DEFAULT => 'crap.tmpl'} );
108
$config->define("loginFormTemplate", { DEFAULT => 'loginForm.tmpl'} );
105 109
$config->define("confirmDataTemplate", { DEFAULT => 'crap.tmpl'} );
106 110
$config->define("deleteDataTemplate", { DEFAULT => 'crap.tmpl'} );
107 111
$config->define("modEmailNotificationTemplate", { DEFAULT => 'crap.tmpl'} );
......
153 157
my $hasSpatial = $config->hasSpatial();
154 158
my $hasTaxonomic = $config->hasTaxonomic();
155 159
my $hasMethod = $config->hasMethod();
160
my $hasUpload = $config->hasUpload();
156 161
my $temporalRequired = $config->temporalRequired();
157 162
my $spatialRequired = $config->spatialRequired();
158 163
my $contactEmailAddressRequired = $config->contactEmailAddressRequired();
......
174 179
my $debug = $config->debug();
175 180
my $lat = $config->get('lat');
176 181
my $lon = $config->get('lon');
177
$debug = 1;
182

  
178 183
# Convert the lat and lon configs into usable data structures
179 184
my @sitelist;
180 185
my %siteLatDMS;
......
206 211
$$templateVars{'orgurl'} = $orgurl;
207 212
$$templateVars{'orgfilter'} = $orgfilter;
208 213

  
209
debug("Registry: Initialized");
214
debug("Registry: Initialized -- stage set: $FORM::stage");
215

  
216
# Must have a config to use Metacat
217
if (!hasContent($FORM::cfg)) {
218
    debug("Registry: No configuration set.");
219
    print "Content-type: text/html\n\n";
220
    $$templateVars{'message'} = 'Error: The registry requires a skin name to continue.';
221
    $template->process( $loginFormTemplate, $templateVars);
222
    exit(0);
223
}
224

  
225
# Metacat isn't initialized, the registry will fail in strange ways.
226
if (!hasContent($metacatUrl)) {
227
    debug("Registry: No Metacat.");
228
    print "Content-type: text/html\n\n";
229
    $$templateVars{'message'} = 'Error: Metacat is not initialized! Make sure' . 
230
        ' MetacatUrl is set correctly in ' .  $FORM::cfg . '.cfg';
231
    $template->process( $loginFormTemplate, $templateVars);
232
    exit(0);
233
}
234

  
210 235
# Process the form based on stage parameter. 
211 236
if ($FORM::stage =~ "loginform") {
212 237
    print "Content-type: text/html\n\n";
......
316 341
    
317 342
    # check if the user is logged in...
318 343
    my $session = CGI::Session->load() or die CGI::Session->errstr();
319
    if ( $session->is_empty  &&  $FORM::cfg =~ 'esa' ) {
344
    if ( $session->is_empty ) {
320 345
        # no session found ... redirect to login page template
321
    	$$templateVars{'showInstructions'} = 'true';
322
    	$$templateVars{'message'} = 'You must login to register your dataset.';
346
        $$templateVars{'showInstructions'} = 'true';
347
        $$templateVars{'message'} = 'You must login to register your dataset.';
323 348
        $template->process( $loginFormTemplate, $templateVars);
324 349
    } else {
325 350

  
......
346 371
    	$$templateVars{'hasSpatial'} = $hasSpatial;
347 372
    	$$templateVars{'hasTaxonomic'} = $hasTaxonomic;
348 373
    	$$templateVars{'hasMethod'} = $hasMethod;
374
      $$templateVars{'hasUpload'} = $hasUpload;
349 375
    	$$templateVars{'temporalRequired'} = $temporalRequired;
350 376
    	$$templateVars{'spatialRequired'} = $spatialRequired;
351 377
    	$$templateVars{'contactEmailAddressRequired'} = $contactEmailAddressRequired;
......
395 421
}
396 422

  
397 423

  
398
my $metacat;
399 424
my $docid;
425
# Create a metacat object
426
my $metacat = Metacat->new($metacatUrl);
427

  
400 428
if (! $error) {
429
    # Login to metacat
430
    my ($dname, $userPass) = getCredentials();
431
    my $response = $metacat->login($dname, $userPass);
432

  
401 433
    # Parameters have been validated and Create the XML document
402

  
403 434
    my $xmldoc = createXMLDocument();
404

  
435
    
405 436
    # Write out the XML file for debugging purposes
406
    #my $testFile = $tmpdir . "/test.xml";
437
    #my $testFile = $tmpdir . "/test-file.xml";
438
    #open (TFILE,">$testFile") || die ("Cant open xml file...\n");
439
    #print TFILE $xmldoc;
440
    #close(TFILE);
407 441

  
408
    # Create a  metacat object
409
    $metacat = Metacat->new();
410
    if ($metacat) {
411
        $metacat->set_options( metacatUrl => $metacatUrl );
412
    } else {
413
        #die "failed during metacat creation\n";
414
        push(@errorMessages, "Failed during metacat creation.");
415
    }
416

  
417
    # Login to metacat
418
    my $userDN = $FORM::username;
419
    my $userOrg = $FORM::organization;
420
    my $userPass = $FORM::password;
421
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
422
    
423
    if($FORM::userLoggedIn eq 'true'){
424
    	my $session = CGI::Session->load();
425
    	if (!( $session->is_empty || $session->is_expired)) {
426
        	$dname = $session->param("username");
427
        	$userPass = $session->param("password");
428
    	}
429
    }
430

  
431 442
    my $xmldocWithDocID = $xmldoc;
432
    
433 443
    my $errorMessage = "";
434
    my $response = $metacat->login($dname, $userPass);
435 444

  
436

  
437 445
    if (! $response) {
446
        debug("No response from Metacat");
438 447
        push(@errorMessages, $metacat->getMessage());
439 448
        push(@errorMessages, "Failed during login.\n");
440 449
        $$templateVars{'status'} = 'login_failure';
......
586 595
################################################################################
587 596
sub updateLastId {
588 597
  my $scope = shift;
598
  $metacat = Metacat->new($metacatUrl);
599
  my $errormsg = 0;
589 600

  
590
  my $errormsg = 0;
591 601
  my $docid = $metacat->getLastId($scope);
592 602

  
593 603
  if ($docid =~ /null/) {
......
598 608
      debug("Docid is: $docid\n");
599 609
      debug("Lastid is: $id");
600 610
      my $scopeFile = $cfgdir . "/" . $FORM::cfg . "/" . $scope . ".lastid";
611
      # FIXME: skins dir isn't generally writeable by the HTTP server, use tmp instead
601 612
      open(LASTID, "+>$scopeFile") or 
602 613
          die "Failed to open lastid file for writing!";
603 614
      print LASTID $id, "\n";
......
620 631
  debug("Trying to insert the following document");
621 632
  my $notunique = "SUCCESS";
622 633
  debug("Registry: Starting insert (D1)");
634

  
635
  #$metacat = Metacat->new($metacatUrl);
623 636
  my $response = $metacat->insert($docid, $xmldoc);
624 637
  if (! $response) {
625 638
    debug("Registry: Response gotten (D2)");
......
663 676
    $lastid++;
664 677
    close(LASTID);
665 678
  }
679
  #debug("scopeFile: $scopeFile");
666 680
  open(LASTID, ">$scopeFile") or die "Failed to open lastid file for writing!";
667 681
  print LASTID $lastid, "\n";
668 682
  close(LASTID);
......
862 876
    			unless (hasContent($FORM::origEmailContact));
863 877
	}
864 878
    }
865
    push(@invalidParams, "Data medium is missing.")
866
    unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/);
867
    push(@invalidParams, "Usage rights are missing.")
868
    unless (hasContent($FORM::useConstraints));
869 879
    
880
    # scw: commented these out, don't seem to be matched to cfg setting
881
    #push(@invalidParams, "Data medium is missing.")
882
    #unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/);
883
    #push(@invalidParams, "Usage rights are missing.")
884
    #unless (hasContent($FORM::useConstraints));
885
    
870 886
    return \@invalidParams;
871 887
}
872 888

  
......
985 1001
    return $val;
986 1002
}
987 1003

  
1004
################################################################################
1005
#
1006
# Upload new file objects into Metacat, if they're present and valid.
1007
#
1008
################################################################################
1009
sub allFileData {
1010
    my %uploadedFiles = ();
1011
    my $fileInfo;
1012
    my $docid;
988 1013

  
1014
    for (my $fileNum = 0; $fileNum <= $FORM::upCount; $fileNum++) {
1015
        my $fn = 'upload_' . $fileNum;
1016
        if (hasContent(param($fn))) {
1017
            debug("Registry: retrieving metadata for file: $fn");
1018
            ($docid, $fileInfo) = fileMetadata($fileNum);
1019
            $uploadedFiles{ $docid } = $fileInfo;
1020
        }
1021
    }
1022

  
1023
    return %uploadedFiles;
1024
}
1025

  
1026
sub fileMetadata {
1027
    my $fileNum = shift;
1028
    my $fileHash = param("upload_$fileNum");
1029
    my $fileName = param("uploadname_$fileNum");
1030
    my $contentType = param("uploadtype_$fileNum");
1031
    my $cleanName = $fileName;
1032

  
1033
    # normalize input filenames; Windows filenames include full paths
1034
    $cleanName =~ s/.*[\/\\](.*)/$1/;
1035

  
1036
    my $outFile = $tmpdir . "/" . $cleanName;
1037
    #debug("Reading file from disk: $outFile");
1038

  
1039
    my $fileSize = stat($outFile)->size;
1040
    if ($fileSize == 0) {
1041
        push(@errorMessages, "file $fileName is zero bytes!");
1042
        debug( "Registry: file $fileName is zero bytes!");
1043
    }
1044

  
1045
    # Now the file is on disk, send the object to Metacat
1046
    my $session = CGI::Session->load();
1047
    if ( $session->is_empty ) {
1048
        push(@errorMessages, "Must be logged in to upload files.");
1049
        debug( "Not logged in, cannot upload files.");
1050
        return 0;
1051
    }
1052

  
1053
    #my ($dname, $userPass) = getCredentials();
1054
    #debug("Logging in with $dname, $userPass");
1055
    #$metacat->login($username, $password);
1056

  
1057
    my $docid = newAccessionNumber($defaultScope);
1058
    my $unique = uploadData($outFile, $docid);
1059
    if (!$unique) {
1060
        debug( "Registry: Updating lastid file");
1061
        updateLastId($defaultScope);
1062
    }
1063

  
1064
    my $entityid = $fileHash."001";
1065
    my $distribid = $fileHash."002";
1066

  
1067
    my $uploadUrl = 'ecogrid://knb/' . $docid;
1068
    # TODO:  should match the object promotion path, so that an
1069
    #        Excel upload results in 'dataTable' in this field
1070
    my $entityType = 'Other';
1071

  
1072
    my %dataInfo = (  'docid'       => $docid,
1073
                      'entityid'    => $entityid,
1074
                      'distribid'   => $distribid,
1075
                      'fileName'    => $cleanName,
1076
                      'fileSize'    => $fileSize,
1077
                      'fileHash'    => $fileHash,
1078
                      'contentType' => $contentType,
1079
                      'url'         => $uploadUrl,
1080
                      'entityType'  => $entityType,
1081
                   );
1082

  
1083
    return ($docid, \%dataInfo);
1084
}
1085

  
1086

  
1087
sub processFile {
1088
    my $fileName = shift;
1089

  
1090
    # test that we actually got a file
1091
    if(!$fileName || cgi_error()) {
1092
        debug("Error receiving file ". cgi_error());
1093
    }
1094
   
1095
    # write file to disk, get SHA1 hash and size
1096
    my ($outFile, $fileHash) = writeFile($fileName);
1097

  
1098
    my $fileSize = stat($outFile)->size;
1099
    if ($fileSize == 0) {
1100
        push(@errorMessages, "file $fileName is zero bytes!");
1101
        debug( "Registry: file $fileName is zero bytes!");
1102
    }
1103

  
1104
    # file is in Metacat, generate the pertinent EML elements
1105
    my $contentType = uploadInfo($fileName)->{'Content-Type'};
1106

  
1107
    my %dataInfo = ( 'fileName'    => $fileName,
1108
                     'fileHash'    => $fileHash,
1109
                     'contentType' => $contentType,
1110
                   );
1111

  
1112
    return \%dataInfo;
1113
}
1114

  
1115
sub writeFile {
1116
    my $fileName = shift;
1117
    my $fileData;
1118
    my $length = 0;
1119
    my $buffer;
1120
    my $cleanName = $fileName;
1121

  
1122
    # normalize input filenames; Windows filenames include full paths
1123
    $cleanName =~ s/.*[\/\\](.*)/$1/;
1124

  
1125
    while (my $bytesRead = read($fileName, $buffer, 4096)) {
1126
        $fileData .= $buffer;
1127
        $length += $bytesRead;
1128
    }
1129

  
1130
    # create SHA1 sum to store file hash
1131
    my $ctx = Digest::SHA1->new;
1132
    $ctx->add($fileData);
1133
    my $digest = $ctx->hexdigest;
1134

  
1135
    my $outputName = $tmpdir . "/" . $cleanName;
1136
    open(OUT,">$outputName") or die "Could not open: $!";
1137
    print OUT $fileData;
1138
    close(OUT);
1139
    debug("Registry: output is: $outputName, length is: $length");
1140

  
1141
    return ($outputName, $digest);
1142
}
1143

  
1144
sub uploadData {
1145
    my $data = shift;
1146
    my $docid = shift;
1147

  
1148
    debug("Registry: Upload -- Starting upload of $docid");
1149
    my $response = $metacat->upload($docid, $data);
1150
    if (!$response) {
1151
        my $uploadMsg = $metacat->getMessage();
1152
        debug("Registry: Upload -- Error is: $uploadMsg");
1153
    } else {
1154
        debug("Registry: Upload -- Success! New docid $docid");
1155
    }
1156
}
1157

  
1158

  
989 1159
################################################################################
990 1160
# 
991 1161
# Create the XML document from the HTML form input
......
993 1163
#
994 1164
################################################################################
995 1165
sub createXMLDocument {
1166
    #FIXME placeholder for $FORM element, should be determined by config
996 1167

  
997
    my $orig  = "";
998
    my $role  = "associatedParty";
999
    my $creat = "";
1000
    my $metaP = "";
1001
    my $apart = "";
1002
    my $cont  = "";
1003
    my $publ  = "";
1004
    my $dso   = "";
1005
    my $gmt = gmtime($now);
1168
    if ($FORM::cfg eq "ebm") {
1169
        return createProjectDocument();
1170
    } else {
1171
        return createDatasetDocument();
1172
    }
1173
}
1006 1174

  
1175
sub createProjectDocument {
1176
    my $doc = EMLStart();
1007 1177

  
1178
    $doc .= titleElement();
1179
    $doc .= creatorNameElement();
1180
    $doc .= creatorElement();
1181

  
1182
    $doc .= pubElement();
1183
    $doc .= setDisplayType('project');
1184
    $doc .= keywordElement();
1185
    $doc .= contactElement();
1186

  
1187
    # putting everything else under project
1188
    $doc .= "<project>";
1189
    $doc .= titleElement();
1190
    my %originators = personnelCreate();
1191
    $doc .= personnelList(\%originators, 'personnel');
1192
    $doc .= abstractElement();
1193
    $doc .= "<studyAreaDescription>\n";
1194
    $doc .= coverageElement();
1195
    $doc .= "</studyAreaDescription>\n";
1196

  
1197
    $doc .= "</project>";
1198
    $doc .= accessElement();
1199
    $doc .= datasetEnd();
1200
    $doc .= EMLEnd();
1201
    return $doc;
1202
}
1203

  
1204
sub createDatasetDocument {
1205
    my $doc = EMLStart();
1206
    $doc .= titleElement();
1207
    $doc .= creatorElement();
1208
    $doc .= contactElement('creator');
1209
    my %originators = personnelCreate();
1210
    $doc .= personnelList(\%originators, 'associatedParty');
1211

  
1212
    $doc .= pubElement();
1213
    $doc .= abstractElement();
1214
#    $doc .= setDisplayType('dataset');
1215
    $doc .= keywordElement();
1216
    $doc .= distributionElement();
1217
    $doc .= coverageElement();
1218
    $doc .= contactElement();
1219
    $doc .= methodsElement();
1220
    $doc .= accessElement();
1221
    my %fileData = allFileData();
1222
    $doc .= entityElement(\%fileData);
1223
    $doc .= datasetEnd();
1224
    $doc .= addMetaElement(\%fileData);
1225
    $doc .= EMLEnd();
1226
}
1227

  
1228
# EML document creation functions
1229

  
1230
sub personnelCreate {
1231
    # TODO: improve flow for personnel, associatedParty
1232
    # element name => objects of that type
1233
    my %orig = (
1234
                'personnel'          => [],
1235
            );
1236

  
1237
    push (@{$orig{personnel}}, [$FORM::providerGivenName, $FORM::providerSurName, 'Metadata Provider']);
1238

  
1239
    # Additional originators
1240
    foreach my $origName (param()) {
1241
        my $origNum = $origName;
1242
        $origNum =~ s/origNamelast//; # get the index of the parameter 0 to 10
1243
        if ( $origNum =~ /^([0-9])$/) {
1244
            # do not generate EML for empty originator fields
1245
            if (hasContent(param("origNamefirst" . $origNum))) {
1246
                my $first = normalize(param("origNamefirst" . $origNum));
1247
                my $last  = normalize(param("origNamelast" . $origNum));
1248
                my $origRole = param("origRole" . $origNum);
1249

  
1250
                push (@{$orig{personnel}}, [$first, $last, $origRole]);
1251
            }
1252
        }
1253
    }
1254
    return %orig
1255
}
1256

  
1257
sub personnelList {
1258
    my ($orig, $type) = @_;
1259
    my %orig = %$orig;
1260

  
1261
    my $elemList = "";
1262
    
1263
    foreach my $v (@{$orig->{'personnel'}}) {
1264
        my ($first, $last, $role) = @$v;
1265
        my $elemRole = $type;
1266
        my $elem = "<individualName>\n";
1267
        $elem .= "<givenName>".normalize($first)."</givenName>\n";
1268
        $elem .= "<surName>".normalize($last)."</surName>\n";
1269
        $elem .= "</individualName>\n";
1270

  
1271
        if ($role eq "Originator") {
1272
            $elemRole = 'creator';
1273
        }
1274
        elsif ($role eq "Metadata Provider") {
1275
            $elemRole = 'metadataProvider';
1276
        }
1277
        elsif ($role eq "Publisher") {
1278
            $elemRole = 'publisher';
1279
        }
1280
        else {
1281
            $elemRole = $type;
1282
        }
1283

  
1284
        if (($elemRole eq 'personnel') && ($FORM::origNameOrgContact) ) {
1285
            $elem .= "<organizationName>$FORM::origNameOrgContact</organizationName>\n";
1286
        }
1287

  
1288
        if (($elemRole eq 'personnel') || ($elemRole eq 'associatedParty') ) {
1289
            $elem .= "<role>".normalize($role)."</role>\n";
1290
        }
1291

  
1292
        $elemList .= "<$elemRole>\n$elem</$elemRole>\n";
1293
    }
1294
    return $elemList;
1295
}
1296

  
1297
sub entityElement() {
1298
    my $entityObjects = shift;
1299
    my %entityObjects = %$entityObjects;
1300
    my $entityList = "";
1301

  
1302
    while ( my ($docid, $data) = each(%entityObjects) ) {
1303
        my $entityStub = qq|<otherEntity id="$data->{'entityid'}" scope="document">
1304
            <entityName>$data->{'fileName'}</entityName>
1305
            <physical scope="document">
1306
                <objectName>$data->{'fileName'}</objectName>
1307
                <size>$data->{'fileSize'}</size>
1308
                <authentication method="SHA1">$data->{'fileHash'}</authentication>
1309
                <dataFormat>
1310
                    <externallyDefinedFormat>
1311
                        <formatName>$data->{'contentType'}</formatName>
1312
                    </externallyDefinedFormat>
1313
                </dataFormat>
1314
                <distribution id="$data->{'distribid'}" scope="document">
1315
                    <online>
1316
                        <url function="download">$data->{'url'}</url>
1317
                    </online>
1318
                </distribution>
1319
            </physical>
1320
            <entityType>$data->{'entityType'}</entityType>
1321
    </otherEntity>
1322
|;
1323
    $entityList .= $entityStub;
1324
    }
1325

  
1326
    return $entityList;
1327
}
1328

  
1329
sub addMetaElement() {
1330
    my $entityObjects = shift;
1331
    my %entityObjects = %$entityObjects;
1332
    my $accessList = "";
1333

  
1334
    while ( my ($docid, $data) = each(%entityObjects) ) {
1335
        my $accessStub = qq|<additionalMetadata>
1336
            <describes>$data->{'distribid'}</describes>
1337
                <access authSystem="knb" order="allowFirst">
1338
                    <deny>
1339
                        <principal>public</principal>
1340
                        <permission>read</permission>
1341
                    </deny>
1342
                </access>
1343
      </additionalMetadata>
1344
    |;
1345
        $accessList .= $accessStub;
1346
    }
1347

  
1348
  return $accessList;
1349
}
1350

  
1351
sub keywordElement() {
1352
    my %kwSet, my $kwList = (), "";
1353

  
1354
    # process the standard keywords
1355
    foreach my $kwName (param()) {
1356
        my $kwNum = $kwName;
1357
        $kwNum =~ s/keyword//; # get the index of the parameter 0, ..., 10
1358
        if ( $kwNum =~ /^([0-9])$/ ){
1359
            # don't generate xml for empty keyword fields
1360
            # don't generate taxonomic keyword fields, those go in taxonomic coverage
1361
            if (hasContent(param($kwName))) {
1362
                my $kwType = param("kwType" . $kwNum);
1363
                my $kwTh   = param("kwTh" . $kwNum);
1364
                my $kw     = param("keyword" . $kwNum);
1365

  
1366
                push(@{$kwSet{$kwTh}}, [$kw, $kwType]);
1367
            }
1368
        }
1369
    }
1370

  
1371
    # output keyword lists
1372
    while ((my $thesaurus, my $a_ref) = each %kwSet) {
1373
        my $kwElem .= "<keywordSet>\n";
1374

  
1375
        foreach my $x (@$a_ref) {
1376
            my ($kw, $kwType) = @$x;
1377
            $kwElem .= "<keyword ";
1378
            if (hasContent($kwType) && $kwType != "None") {
1379
                 $kwElem.= "keywordType=\"".lc($kwType)."\"";
1380
            }
1381
            $kwElem .= ">$kw</keyword>\n";
1382
        }
1383

  
1384
        $kwElem .= "<keywordThesaurus>".normalize($thesaurus)."</keywordThesaurus>\n";
1385
        $kwElem .= "</keywordSet>\n";
1386
        $kwList .= $kwElem;
1387
    }
1388
    return $kwList;
1389
}
1390

  
1391
sub EMLStart() {
1392
    my $gmt = gmtime($now);
1008 1393
    my $doc =  "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n";
1009 1394

  
1010
    $doc .= "<eml:eml\n 
1011
                     \t packageId=\"docid\" system=\"knb\"\n 
1012
                     \t xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.1\"\n
1013
                     \t xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n 
1014
                     \t xmlns:ds=\"eml://ecoinformatics.org/dataset-2.0.1\"\n 
1015
                     \t xmlns:stmml=\"http://www.xml-cml.org/schema/stmml\"\n 
1016
                     \t xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.1 eml.xsd\">\n";
1395
    $doc .= "<eml:eml
1396
                      packageId=\"docid\" system=\"knb\"
1397
                      xmlns:eml=\"eml://ecoinformatics.org/eml-2.0.1\"
1398
                      xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
1399
                      xmlns:ds=\"eml://ecoinformatics.org/dataset-2.0.1\"
1400
                      xmlns:stmml=\"http://www.xml-cml.org/schema/stmml\"
1401
                      xsi:schemaLocation=\"eml://ecoinformatics.org/eml-2.0.1 eml.xsd\">\n";
1017 1402

  
1018 1403
    $doc .= "<!-- Person who filled in the catalog entry form: ";
1019 1404
    $doc .= normalize($FORM::providerGivenName)." ".normalize($FORM::providerSurName)." -->\n";
1020 1405
    $doc .= "<!-- Form filled out at $gmt GMT -->\n";
1021 1406
    $doc .= "<dataset>\n";
1022
    
1407

  
1023 1408
    if (hasContent($FORM::identifier)) {
1024 1409
        $doc .= "<alternateIdentifier system=\"$FORM::site\">";
1025 1410
        $doc .= normalize($FORM::identifier) . "</alternateIdentifier>\n";
1026 1411
    }
1027
    
1412
    return $doc;
1413
}
1414

  
1415
sub EMLEnd() {
1416
    return  "</eml:eml>\n";
1417
}
1418

  
1419
sub datasetEnd() {
1420
    return "</dataset>\n";
1421
}
1422

  
1423
sub setDisplayType {
1424
   my $kwDisp = shift;
1425
   if (!$kwDisp) {
1426
       $kwDisp = 'dataset';
1427
   }
1428
   my $kw = "<keywordSet>\n";
1429
   $kw .= "  <keyword>$kwDisp</keyword>\n";
1430
   $kw .= "  <keywordThesaurus>EMLDisplayType</keywordThesaurus>\n";
1431
   $kw .= "</keywordSet>\n";
1432
   return $kw;
1433
}
1434

  
1435
sub pubElement() {
1436
    #add the publication Date to the eml document.
1437
    my ($Day, $Month, $Year) = (localtime)[3,4,5];
1438

  
1439
    return "<pubDate>".sprintf("%03d-%02d-%02d", $Year + 1900, $Month + 1, $Day)."</pubDate>\n";
1440
}
1441

  
1442
sub titleElement() {
1028 1443
    if (hasContent($FORM::title)) {
1029
        $doc .= "<title>".normalize($FORM::title)."</title>\n";
1444
        return "<title>".normalize($FORM::title)."</title>\n";
1030 1445
    }
1446
}
1031 1447

  
1032
    if (hasContent($FORM::origNamelast0)) {
1033
    $role = "creator";
1034
        $orig .= "<individualName>\n";
1035
        $orig .= "<givenName>".normalize($FORM::origNamefirst0)."</givenName>\n";
1036
        $orig .= "<surName>".normalize($FORM::origNamelast0)."</surName>\n";
1037
        $orig .= "</individualName>\n";
1448
sub abstractElement() {
1449
    return "<abstract>\n<para>".normalize($FORM::abstract)."</para>\n</abstract>\n";
1450
}
1451

  
1452
sub creatorElement() {
1453
    my $creators;
1454
    if ($FORM::cfg eq 'nceas') {
1455
        for (my $i = 0; $i < scalar(@FORM::wg); $i++) {
1456
            $creators .= creatorNode($FORM::wg[$i]);
1457
        }
1458
    } else {
1459
        $creators .= creatorNode($FORM::site);
1038 1460
    }
1461
    if ($FORM::cfg ne 'knb') {
1462
        $creators .= creatorNode();
1463
    }
1039 1464

  
1040
    if (hasContent($FORM::origNameOrg)) {
1041
        $orig .= "<organizationName>".normalize($FORM::origNameOrg)."</organizationName>\n";
1465
    return $creators;
1466
}
1467

  
1468
sub creatorNode {
1469
    my $org = shift;
1470
    my $content = "";
1471

  
1472
    if (!hasContent($org)) {
1473
        $content = $organization;
1474
    } else {
1475
        $content = $org;
1042 1476
    }
1043 1477

  
1044
    if (hasContent($FORM::origDelivery) || hasContent($FORM::origCity) ||
1045
        (hasContent($FORM::origState   ) &&
1046
        ($FORM::origState !~ "Select state here.")) ||
1047
        hasContent($FORM::origStateOther) ||
1048
        hasContent($FORM::origZIP ) || hasContent($FORM::origCountry)) {
1049
        $orig .= "<address>\n";
1478
    return
1479
    "<creator>\n<organizationName>".normalize($content)."</organizationName>\n</creator>\n";
1480
}
1050 1481

  
1051
        if (hasContent($FORM::origDelivery)) {
1052
            $orig .= "<deliveryPoint>".normalize($FORM::origDelivery)."</deliveryPoint>\n";
1053
        }
1054
        if (hasContent($FORM::origCity)) {
1055
            $orig .= "<city>".normalize($FORM::origCity)."</city>\n";
1056
        }
1482
sub creatorNameElement {
1483
    my $role = shift;
1484
    my $creator;
1485
    if (!hasContent($role)) {
1486
        $role ="creator";
1487
    }
1057 1488

  
1058
    if (hasContent($FORM::origState) && 
1059
            ($FORM::origState !~ "Select state here.")) {
1060
            $orig .= "<administrativeArea>".normalize($FORM::origState);
1061
            $orig .= "</administrativeArea>\n";
1062
        } elsif (hasContent($FORM::origStateOther)) {
1063
            $orig .= "<administrativeArea>".normalize($FORM::origStateOther);
1064
            $orig .= "</administrativeArea>\n";
1489
    $creator .= "<individualName>\n";
1490
    $creator .= "<givenName>".normalize($FORM::origNamefirst0)."</givenName>\n";
1491
    $creator .= "<surName>".normalize($FORM::origNamelast0)."</surName>\n";
1492
    $creator .= "</individualName>\n";
1493

  
1494
    return "<$role>\n$creator</$role>\n"
1495
}
1496

  
1497
sub methodsElement() {
1498
    my $methods = "";
1499
    if ((hasContent($FORM::methodTitle)) || scalar(@FORM::methodsPara) > 0 || ($FORM::methodPara[0] ne "")) {
1500
        $methods = "<methods><methodStep><description><section>\n";
1501
        if (hasContent($FORM::methodTitle)) {
1502
            $methods .= "<title>".normalize($FORM::methodTitle)."</title>\n";
1065 1503
        }
1066
        if (hasContent($FORM::origZIP)) {
1067
            $orig .= "<postalCode>".normalize($FORM::origZIP)."</postalCode>\n";
1504
        for (my $i = 0; $i < scalar(@FORM::methodPara); $i++) {
1505
            $methods .= "<para>".normalize($FORM::methodPara[$i])."</para>\n";
1068 1506
        }
1069
        if (hasContent($FORM::origCountry)) {
1070
            $orig .= "<country>".normalize($FORM::origCountry)."</country>\n";
1507
        $methods .= "</section></description></methodStep>\n";
1508
        if (hasContent($FORM::studyExtentDescription)) {
1509
            $methods .= "<sampling><studyExtent><description>\n";
1510
            $methods .= "<para>".normalize($FORM::studyExtentDescription)."</para>\n";
1511
            $methods .= "</description></studyExtent>\n";
1512
            $methods .= "<samplingDescription>\n";
1513
            $methods .= "<para>".normalize($FORM::samplingDescription)."</para>\n";
1514
            $methods .= "</samplingDescription>\n";
1515
            $methods .= "</sampling>\n";
1071 1516
        }
1072
        $orig .= "</address>\n";
1517
        $methods .= "</methods>\n";
1073 1518
    }
1519
    return $methods
1520
}
1074 1521

  
1075
    if (hasContent($FORM::origPhone)) {
1076
        $orig .= "<phone>".normalize($FORM::origPhone)."</phone>\n";
1077
    }
1078
    if (hasContent($FORM::origFAX)) {
1079
        $orig .= "<phone phonetype=\"Fax\">".normalize($FORM::origFAX)."</phone>\n";
1080
    }
1081
    if (hasContent($FORM::origEmail)) {
1082
        $orig .= "<electronicMailAddress>".normalize($FORM::origEmail);
1083
        $orig .= "</electronicMailAddress>\n";
1084
    }
1085
    $dso = "<$role>\n$orig</$role>\n";
1086
    
1087
    if ($FORM::cfg eq 'nceas') {
1088
        for (my $i = 0; $i < scalar(@FORM::wg); $i++) {
1089
            $creat .= "<creator>\n";
1090
            $creat .= "<organizationName>".normalize($FORM::wg[$i])."</organizationName>\n";
1091
            $creat .= "</creator>\n";
1092
        }
1093
    } else {
1094
	    $creat .= "<creator>\n";
1095
	    $creat .= "<organizationName>".normalize($FORM::site)."</organizationName>\n";
1096
	    $creat .= "</creator>\n";
1097
    }
1522
sub contactElement() {
1523
    my $role = shift;
1524
    my $cont = "";
1098 1525

  
1099
    if ($FORM::cfg ne 'knb') {
1100
        $creat .= "<creator>\n";
1101
        $creat .= "<organizationName>".normalize($organization)."</organizationName>\n";
1102
        $creat .= "</creator>\n";
1526
    if (!hasContent($role)) {
1527
        $role = 'contact';
1103 1528
    }
1104 1529

  
1105
    $creat .= $dso;
1530
    $cont .= "<individualName>\n";
1531
    $cont .= "<givenName>".normalize($FORM::origNamefirstContact)."</givenName>\n";
1532
    $cont .= "<surName>".normalize($FORM::origNamelastContact)."</surName>\n";
1533
    $cont .= "</individualName>\n";
1106 1534

  
1107
    if ($FORM::useOrigAddress) {
1108
        # Add a contact originator like the original with a different role
1109
            $cont .= "<contact>\n";
1110
        $cont .= $orig;
1111
        $cont .= "</contact>\n";
1112
    } else {
1113
        $cont .= "<contact>\n";
1114

  
1115
        $cont .= "<individualName>\n";
1116
        $cont .= "<givenName>".normalize($FORM::origNamefirstContact)."</givenName>\n";
1117
        $cont .= "<surName>".normalize($FORM::origNamelastContact)."</surName>\n";
1118
        $cont .= "</individualName>\n";
1119
 
1120 1535
    if (hasContent($FORM::origNameOrgContact)) {
1121 1536
        $cont .= "<organizationName>".normalize($FORM::origNameOrgContact)."</organizationName>\n";
1122 1537
    }
1123 1538

  
1124
        if (hasContent($FORM::origDeliveryContact) || 
1125
            hasContent($FORM::origCityContact) ||
1126
            (hasContent($FORM::origStateContact) &&
1127
            ($FORM::origStateContact !~ "Select state here.")) ||
1128
            hasContent($FORM::origStateOtherContact) ||
1129
            hasContent($FORM::origZIPContact) || 
1130
            hasContent($FORM::origCountryContact)) {
1131
            $cont .= "<address>\n";
1132
            if (hasContent($FORM::origDeliveryContact)) {
1133
                $cont .= "<deliveryPoint>".normalize($FORM::origDeliveryContact);
1134
                $cont .= "</deliveryPoint>\n";
1135
            }
1136
            if (hasContent($FORM::origCityContact)) {
1137
                $cont .= "<city>".normalize($FORM::origCityContact)."</city>\n";
1138
            }
1139
            if (hasContent($FORM::origStateContact) && 
1140
                ($FORM::origStateContact !~ "Select state here.")) {
1141
                $cont .= "<administrativeArea>".normalize($FORM::origStateContact);
1142
                $cont .= "</administrativeArea>\n";
1143
            } elsif (hasContent($FORM::origStateOtherContact)) {
1144
                $cont .= "<administrativeArea>".normalize($FORM::origStateOtherContact);
1145
                $cont .= "</administrativeArea>\n";
1146
            }
1147
            if (hasContent($FORM::origZIPContact)) {
1148
                $cont .= "<postalCode>".normalize($FORM::origZIPContact)."</postalCode>\n";
1149
            }
1150
            if (hasContent($FORM::origCountryContact)) {
1151
                $cont .= "<country>".normalize($FORM::origCountryContact)."</country>\n";
1152
            }
1153
            $cont .= "</address>\n";
1539
    if (hasContent($FORM::origDeliveryContact) ||
1540
        hasContent($FORM::origCityContact) ||
1541
        (hasContent($FORM::origStateContact) &&
1542
        ($FORM::origStateContact !~ "Select state here.")) ||
1543
        hasContent($FORM::origStateOtherContact) ||
1544
        hasContent($FORM::origZIPContact) ||
1545
        hasContent($FORM::origCountryContact)) {
1546
        $cont .= "<address>\n";
1547
        if (hasContent($FORM::origDeliveryContact)) {
1548
            $cont .= "<deliveryPoint>".normalize($FORM::origDeliveryContact);
1549
            $cont .= "</deliveryPoint>\n";
1154 1550
        }
1155
        if (hasContent($FORM::origPhoneContact)) {
1156
            $cont .= "<phone>".normalize($FORM::origPhoneContact)."</phone>\n";
1551
        if (hasContent($FORM::origCityContact)) {
1552
            $cont .= "<city>".normalize($FORM::origCityContact)."</city>\n";
1157 1553
        }
1554
        if (hasContent($FORM::origStateContact) &&
1555
            ($FORM::origStateContact !~ "Select state here.")) {
1556
            $cont .= "<administrativeArea>".normalize($FORM::origStateContact);
1557
            $cont .= "</administrativeArea>\n";
1558
        } elsif (hasContent($FORM::origStateOtherContact)) {
1559
            $cont .= "<administrativeArea>".normalize($FORM::origStateOtherContact);
1560
            $cont .= "</administrativeArea>\n";
1561
        }
1562
        if (hasContent($FORM::origZIPContact)) {
1563
            $cont .= "<postalCode>".normalize($FORM::origZIPContact)."</postalCode>\n";
1564
        }
1565
        if (hasContent($FORM::origCountryContact)) {
1566
            $cont .= "<country>".normalize($FORM::origCountryContact)."</country>\n";
1567
        }
1568
        $cont .= "</address>\n";
1569
    }
1570
    if (hasContent($FORM::origPhoneContact)) {
1571
        $cont .= "<phone>".normalize($FORM::origPhoneContact)."</phone>\n";
1572
    }
1158 1573
    if (hasContent($FORM::origFAXContact)) {
1159 1574
        $cont .= "<phone phonetype=\"Fax\">".normalize($FORM::origFAXContact)."</phone>\n";
1160 1575
    }
1161
        if (hasContent($FORM::origEmailContact)) {
1162
            $cont .= "<electronicMailAddress>".normalize($FORM::origEmailContact);
1163
            $cont .= "</electronicMailAddress>\n";
1164
        }
1165
    $cont .= "</contact>\n";
1576
    if (hasContent($FORM::origEmailContact)) {
1577
        $cont .= "<electronicMailAddress>".normalize($FORM::origEmailContact);
1578
        $cont .= "</electronicMailAddress>\n";
1166 1579
    }
1580
    
1581
    return "<$role>\n$cont</$role>\n";
1582
}
1167 1583

  
1168
    $metaP .= "<metadataProvider>\n";
1169
    $metaP .= "<individualName>\n";
1170
    $metaP .= "<givenName>".normalize($FORM::providerGivenName)."</givenName>\n";
1171
    $metaP .= "<surName>".normalize($FORM::providerSurName)."</surName>\n";
1172
    $metaP .= "</individualName>\n";
1173
    $metaP .= "</metadataProvider>\n";
1584
sub coverageElement(){
1585
    my $cov = "";
1586
    
1587
    # temporal coverage
1588
    if (hasContent($FORM::endingYear)) {
1589
        $cov .= "<temporalCoverage>\n";
1590
        $cov .= "<rangeOfDates>\n";
1591
        if (hasContent($FORM::beginningMonth)) {
1592
            my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1593
                         "JUL","AUG","SEP","OCT","NOV","DEC")
1594
            [$FORM::beginningMonth - 1];
1595
            if (hasContent($FORM::beginningDay)) {
1596
                $cov .= "<beginDate>\n";
1597
                $cov .= "<calendarDate>";
1598
                $cov .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-".normalize($FORM::beginningDay);
1599
                $cov .= "</calendarDate>\n";
1600
                $cov .= "</beginDate>\n";
1601
            } else {
1602
                $cov .= "<beginDate>\n";
1603
                $cov .= "<calendarDate>";
1604
                $cov .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-01";
1605
                $cov .= "</calendarDate>\n";
1606
                $cov .= "</beginDate>\n";
1607
            }
1608
        } else {
1609
            $cov .= "<beginDate>\n";
1610
            $cov .= "<calendarDate>";
1611
            $cov .= normalize($FORM::beginningYear);
1612
            $cov .= "</calendarDate>\n";
1613
            $cov .= "</beginDate>\n";
1614
        }
1174 1615

  
1175
    # Additional originators
1176
    foreach my $tmp (param()) {
1177
        if ($tmp =~ /origNamelast/){
1178
            my $tmp1 = $tmp;
1179
            $tmp1 =~ s/origNamelast//; # get the index of the parameter 0 to 10
1180
            if ( $tmp1 eq '1' 
1181
                 || $tmp1 eq '2'
1182
                 || $tmp1 eq '3'
1183
                 || $tmp1 eq '4'
1184
                 || $tmp1 eq '5'
1185
                 || $tmp1 eq '6'
1186
                 || $tmp1 eq '7'
1187
                 || $tmp1 eq '8'
1188
                 || $tmp1 eq '9'
1189
                 || $tmp1 eq '10'
1190
                 ) {
1191
     
1192
                # do not generate XML for empty originator fields 
1193
                if (hasContent(param("origNamefirst" . $tmp1))) {    
1616
        if (hasContent($FORM::endingMonth)) {
1617
            my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1618
                 "JUL","AUG","SEP","OCT","NOV","DEC")
1619
            [$FORM::endingMonth - 1];
1194 1620

  
1195
            my $add = "";
1196
            $add .= "<individualName>\n";
1197
            $add .= "<givenName>";
1198
            $add .= normalize(param("origNamefirst" . $tmp1));
1199
            $add .= "</givenName>\n";
1200
            $add .= "<surName>";
1201
            $add .= normalize(param("origNamelast" . $tmp1));
1202
            $add .= "</surName>\n";
1203
            $add .= "</individualName>\n";
1204
            
1205
            if(param("origRole" . $tmp1) eq "Originator"){
1206
            $creat .= "<creator>\n";
1207
            $creat .= $add;
1208
            $creat .= "</creator>\n";
1621
            if (hasContent($FORM::endingDay)) {
1622
                $cov .= "<endDate>\n";
1623
                $cov .= "<calendarDate>";
1624
                $cov .= normalize($FORM::endingYear)."-".normalize($FORM::endingMonth)."-".normalize($FORM::endingDay);
1625
                $cov .= "</calendarDate>\n";
1626
                $cov .= "</endDate>\n";
1627
            } else {
1628
                $cov .= "<endDate>\n";
1629
                $cov .= "<calendarDate>";
1630
                $cov .= normalize($FORM::endingYear)."-".normalize($FORM::endingMonth)."-01";
1631
                $cov .= "</calendarDate>\n";
1632
                $cov .= "</endDate>\n";
1209 1633
            }
1210
            elsif(param("origRole" . $tmp1) eq "Metadata Provider"){
1211
            $metaP .= "<metadataProvider>\n";
1212
            $metaP .= $add;
1213
            $metaP .= "</metadataProvider>\n";
1214
            }
1215
            elsif((param("origRole" . $tmp1) eq "Publisher")  && ($publ eq "")){
1216
            $publ .= "<publisher>\n";
1217
            $publ .= $add;
1218
            $publ .= "</publisher>\n";
1219
            }
1220
            else{
1221
            $apart .= "<associatedParty>\n";
1222
            $apart .= $add;
1223
            $apart .= "<role>";
1224
            $apart .= param("origRole" . $tmp1);
1225
            $apart .= "</role>\n";
1226
            $apart .= "</associatedParty>\n";
1227
            }
1634
        } else {
1635
            $cov .= "<endDate>\n";
1636
            $cov .= "<calendarDate>";
1637
            $cov .= normalize($FORM::endingYear);
1638
            $cov .= "</calendarDate>\n";
1639
            $cov .= "</endDate>\n";
1228 1640
        }
1641
        $cov .= "</rangeOfDates>\n";
1642
        $cov .= "</temporalCoverage>\n";
1643
    } else {
1644
        if(hasContent($FORM::beginningYear)) {
1645
            $cov .= "<temporalCoverage>\n";
1646
            $cov .= "<singleDateTime>\n";
1647
            if (hasContent($FORM::beginningMonth)) {
1648
                my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1649
                             "JUL","AUG","SEP","OCT","NOV","DEC")
1650
                [$FORM::beginningMonth - 1];
1651

  
1652
                if (hasContent($FORM::beginningDay)) {
1653
                    $cov .= "<calendarDate>";
1654
                    $cov .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-".normalize($FORM::beginningDay);
1655
                    $cov .= "</calendarDate>\n";
1656
                } else {
1657
                    $cov .= "<calendarDate>";
1658
                    $cov .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-01";
1659
                    $cov .= "</calendarDate>\n";
1660
                }
1661
            } else {
1662
                $cov .= "<calendarDate>";
1663
                $cov .= normalize($FORM::beginningYear);
1664
                $cov .= "</calendarDate>\n";
1229 1665
            }
1666
            $cov .= "</singleDateTime>\n";
1667
            $cov .= "</temporalCoverage>\n";
1230 1668
        }
1231 1669
    }
1232 1670

  
1233
    $doc .= $creat;
1234
    $doc .= $metaP;
1235
    $doc .= $apart;
1671
    # geographic coverage
1672
    if(hasContent($FORM::geogdesc) || ($FORM::latDeg1 < 91 && $FORM::latDeg1 > -1 && $FORM::longDeg1 < 181 && $FORM::longDeg1 > -1)) {
1673
        $cov .= "<geographicCoverage>\n";
1236 1674

  
1237
    # add the publication Date to the eml document. 
1238
    my $Second = "";
1239
    my $Minute = "";
1240
    my $Hour = "";
1241
    my $Day = "";
1242
    my $Month = "";
1243
    my $Year = "";
1244
    my $WeekDay = "";
1245
    my $DayOfYear = "";
1246
    my $IsDST = "";
1247
    ($Second, $Minute, $Hour, $Day, $Month, $Year, $WeekDay, $DayOfYear, $IsDST) = localtime(time) ;
1248
    $Month = $Month + 1;
1249
    if($Month < 10) { 
1250
	$Month = "0".$Month;
1251
    }
1252
    if($Day < 10) { 
1253
	$Day = "0".$Day;  
1254
    } 
1255
    $Year = $Year + 1900; 
1675
        if(hasContent($FORM::geogdesc)) {
1676
            $cov .= "<geographicDescription>".normalize($FORM::geogdesc)."</geographicDescription>\n";
1677
        }
1256 1678

  
1257
    $doc .= "<pubDate>\n";
1258
    $doc .= $Year."-".$Month."-".$Day;
1259
    $doc .= "</pubDate>\n";
1679
        if($latDeg1 < 91 && $latDeg1 > -1 && $longDeg1 < 181 && $longDeg1 > -1) {
1680
            $cov .= "<boundingCoordinates>\n";
1681
            # if the second latitude is missing, then set the second lat/long pair
1682
            # equal to the first this makes a point appear like a rectangle
1683
            if ($FORM::useSiteCoord || ($FORM::latDeg2 eq "" && $FORM::latMin2 eq "" && $FORM::latSec2 eq "")) {
1260 1684

  
1261
    $doc .= "<abstract>\n";
1262
    $doc .= "<para>".normalize($FORM::abstract)."</para>\n";
1263
    $doc .= "</abstract>\n";
1264

  
1265
    # Keyword information
1266
    foreach my $tmp (param()) {
1267
        if ($tmp =~ /keyword/) {
1268
            my $tmp1 = $tmp;
1269
            $tmp1 =~ s/keyword//; # get the index of the parameter 0, ..., 10
1270
            if ( $tmp1 =~ /[0-9]/ ){
1271
                # don't generate xml for empty keyword fields
1272
                # don't generate taxonomic keyword fields, those go in taxonomic coverage
1273
                if (hasContent(param($tmp))) {
1274
                    $doc .= "<keywordSet>\n";
1275
                    $doc .= "<keyword ";
1276
                    if (hasContent(param("kwType" . $tmp1)) &&
1277
                       (param("kwType" . $tmp1) !~ "None") ) {
1278
                         $doc .= "keywordType=\"";
1279
                         $doc .= lc(param("kwType" . $tmp1));
1280
                         $doc .= "\"";
1281
                    }
1282
                    $doc .= ">";
1283
                    $doc .= normalize(param("keyword" . $tmp1));
1284
                    $doc .= "</keyword>\n";
1285
                    $doc .= "<keywordThesaurus>";
1286
                    $doc .= normalize(param("kwTh" . $tmp1));
1287
                    $doc .= "</keywordThesaurus>\n";
1288
                    $doc .= "</keywordSet>\n";
1289
                }
1685
                $latDeg2 = $latDeg1;
1686
                $latMin2 = $latMin1;
1687
                $latSec2 = $latSec1;
1688
                $hemisphLat2 = $hemisphLat1;
1689
                $longDeg2 = $longDeg1;
1690
                $longMin2 = $longMin1;
1691
                $longSec2 = $longSec1;
1692
                $hemisphLong2 = $hemisphLong1;
1290 1693
            }
1291
        }
1292
    }
1694
            else
1695
            {
1696
                $latDeg2 = $FORM::latDeg2;
1697
                $latMin2 = $FORM::latMin2;
1698
                $latSec2 = $FORM::latSec2;
1699
                $hemisphLat2 = $FORM::hemisphLat2;
1700
                $longDeg2 = $FORM::longDeg2;
1701
                $longMin2 = $FORM::longMin2;
1702
                $longSec2 = $FORM::longSec2;
1703
                $hemisphLong2 = $FORM::hemisphLong2;
1704
            }
1293 1705

  
1294
    if (hasContent($FORM::addComments)) {
1295
        $doc .= "<additionalInfo>\n";
1296
        $doc .= "<para>".normalize($FORM::addComments)."</para>\n";
1297
        $doc .= "</additionalInfo>\n";
1298
    }
1706
            my $hemisph;
1707
            $hemisph = ($hemisphLong1 eq "W") ? -1 : 1;
1708
            $cov .= "<westBoundingCoordinate>";
1709
            my $var = $hemisph * ($longDeg1 + (60*$longMin1+$longSec1)/3600);
1710
            $cov .= sprintf("%.4f\n", $var);
1711
            $cov .= "</westBoundingCoordinate>\n";
1299 1712

  
1300
    if (hasContent($FORM::useConstraints) || 
1301
        hasContent($FORM::useConstraintsOther)) {
1302
        $doc .= "<intellectualRights>\n";
1303
        if (hasContent($FORM::useConstraints)) {
1304
            $doc .= "<para>".normalize($FORM::useConstraints)."</para>\n";
1305
        }
1306
        if (hasContent($FORM::useConstraintsOther)) {
1307
            $doc .= "<para>".normalize($FORM::useConstraintsOther)."</para>\n";
1308
        }
1309
        $doc .= "</intellectualRights>\n";
1310
    }
1713
            $hemisph = ($hemisphLong2 eq "W") ? -1 : 1;
1714
            $cov .= "<eastBoundingCoordinate>";
1715
            $var = $hemisph * ($longDeg2 + (60*$longMin2+$longSec2)/3600);
1716
            $cov .= sprintf("%.4f\n", $var);
1717
            $cov .= "</eastBoundingCoordinate>\n";
1311 1718

  
1312
    
1313
    if (hasContent($FORM::url)) {
1314
    $doc .= "<distribution>\n";
1315
        $doc .= "<online>\n";
1316
    $doc .= "<url>".normalize($FORM::url)."</url>\n";
1317
    $doc .= "</online>\n";
1318
    $doc .= "</distribution>\n";
1319
    }
1320
    
1321
    $doc .= "<distribution>\n";
1322
    $doc .= "<offline>\n";
1323
    $doc .= "<mediumName>" . normalize($FORM::dataMedium)." ".normalize($FORM::dataMediumOther);
1324
    $doc .= "</mediumName>\n";
1325
    $doc .= "</offline>\n";
1326
    $doc .= "</distribution>\n";
1327
            
1328
    my $cov = "";
1719
            $hemisph = ($hemisphLat1 eq "S") ? -1 : 1;
1720
            $cov .= "<northBoundingCoordinate>";
1721
            $var = $hemisph * ($latDeg1 + (60*$latMin1+$latSec1)/3600);
1722
            $cov .= sprintf("%.4f\n", $var);
1723
            $cov .= "</northBoundingCoordinate>\n";
1329 1724

  
1330
    if (hasContent($FORM::endingYear)) {
1331
	$cov .= "<temporalCoverage>\n";
1332
	$cov .= "<rangeOfDates>\n";
1333
	if (hasContent($FORM::beginningMonth)) {
1334
	    my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1335
			 "JUL","AUG","SEP","OCT","NOV","DEC")
1336
		[$FORM::beginningMonth - 1];
1337
	    if (hasContent($FORM::beginningDay)) {
1338
	    	$cov .= "<beginDate>\n";
1339
	    	$cov .= "<calendarDate>";
1340
	    	$cov .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-".normalize($FORM::beginningDay);
1341
	    	$cov .= "</calendarDate>\n";
1342
	    	$cov .= "</beginDate>\n";
1343
	    } else {
1344
	    	$cov .= "<beginDate>\n";
1345
	    	$cov .= "<calendarDate>";
1346
	    	$cov .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-01";
1347
	    	$cov .= "</calendarDate>\n";
1348
	    	$cov .= "</beginDate>\n";
1349
	    }
1350
	} else {
1351
	    $cov .= "<beginDate>\n";
1352
	    $cov .= "<calendarDate>";
1353
	    $cov .= normalize($FORM::beginningYear);
1354
	    $cov .= "</calendarDate>\n";
1355
	    $cov .= "</beginDate>\n";
1356
	}
1357
	
1358
	if (hasContent($FORM::endingMonth)) {
1359
	    my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1360
			 "JUL","AUG","SEP","OCT","NOV","DEC")
1361
		[$FORM::endingMonth - 1];
1362
	
1363
	    if (hasContent($FORM::endingDay)) {
1364
	    	$cov .= "<endDate>\n";
1365
	    	$cov .= "<calendarDate>";
1366
	    	$cov .= normalize($FORM::endingYear)."-".normalize($FORM::endingMonth)."-".normalize($FORM::endingDay);
1367
	    	$cov .= "</calendarDate>\n";
1368
	    	$cov .= "</endDate>\n";
1369
	    } else {
1370
	    	$cov .= "<endDate>\n";
1371
	    	$cov .= "<calendarDate>";
1372
	    	$cov .= normalize($FORM::endingYear)."-".normalize($FORM::endingMonth)."-01";
1373
	    	$cov .= "</calendarDate>\n";
1374
	    	$cov .= "</endDate>\n";
1375
	    }
1376
	} else {
1377
	    $cov .= "<endDate>\n";
1378
	    $cov .= "<calendarDate>";
1379
	    $cov .= normalize($FORM::endingYear);
1380
	    $cov .= "</calendarDate>\n";
1381
	    $cov .= "</endDate>\n";
1382
	}
1383
	$cov .= "</rangeOfDates>\n";
1384
	$cov .= "</temporalCoverage>\n";
1385
    } else {
1386
	if(hasContent($FORM::beginningYear)) {
1387
	    $cov .= "<temporalCoverage>\n";
1388
	    $cov .= "<singleDateTime>\n";
1389
	    if (hasContent($FORM::beginningMonth)) {
1390
		my $month = ("JAN","FEB","MAR","APR","MAY","JUN",
1391
			     "JUL","AUG","SEP","OCT","NOV","DEC")
1392
		    [$FORM::beginningMonth - 1];
1393
		
1394
	    	if (hasContent($FORM::beginningDay)) {
1395
		   $cov .= "<calendarDate>";
1396
		   $cov .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-".normalize($FORM::beginningDay);
1397
		   $cov .= "</calendarDate>\n";
1398
		} else {
1399
		   $cov .= "<calendarDate>";
1400
		   $cov .= normalize($FORM::beginningYear)."-".normalize($FORM::beginningMonth)."-01";
1401
		   $cov .= "</calendarDate>\n";
1402
		}
1403
	    } else {
1404
		$cov .= "<calendarDate>";
1405
		$cov .= normalize($FORM::beginningYear);
1406
		$cov .= "</calendarDate>\n";
1407
	    }
1408
	    $cov .= "</singleDateTime>\n";
1409
	    $cov .= "</temporalCoverage>\n";
1410
	}
1411
    }
1412
    
1413
    if(hasContent($FORM::geogdesc) || ($FORM::latDeg1 < 91 && $FORM::latDeg1 > -1 && $FORM::longDeg1 < 181 && $FORM::longDeg1 > -1)) {
1414
	$cov .= "<geographicCoverage>\n";
1725
            $hemisph = ($hemisphLat2 eq "S") ? -1 : 1;
1726
            $cov .= "<southBoundingCoordinate>";
1727
            $var = $hemisph * ($latDeg2 + (60*$latMin2+$latSec2)/3600);
1728
            $cov .= sprintf("%.4f\n", $var);
1729
            $cov .= "</southBoundingCoordinate>\n";
1415 1730

  
1416
	if(hasContent($FORM::geogdesc)) {
1417
	    $cov .= "<geographicDescription>".normalize($FORM::geogdesc)."</geographicDescription>\n";
1418
	}
1419
	
1420
	if($latDeg1 < 91 && $latDeg1 > -1 && $longDeg1 < 181 && $longDeg1 > -1) {
1421
	    $cov .= "<boundingCoordinates>\n";
1422
	    # if the second latitude is missing, then set the second lat/long pair 
1423
	    # equal to the first this makes a point appear like a rectangle 
1424
	    if ($FORM::useSiteCoord || ($FORM::latDeg2 eq "" && $FORM::latMin2 eq "" && $FORM::latSec2 eq "")) {
1425
		
1426
		$latDeg2 = $latDeg1;
1427
		$latMin2 = $latMin1;
1428
		$latSec2 = $latSec1;
1429
		$hemisphLat2 = $hemisphLat1;
1430
		$longDeg2 = $longDeg1;
1431
		$longMin2 = $longMin1;
1432
		$longSec2 = $longSec1;
1433
		$hemisphLong2 = $hemisphLong1;
1434
	    }
1435
	    else
1436
	    {
1437
		$latDeg2 = $FORM::latDeg2;
1438
		$latMin2 = $FORM::latMin2;
1439
		$latSec2 = $FORM::latSec2;
1440
		$hemisphLat2 = $FORM::hemisphLat2;
1441
		$longDeg2 = $FORM::longDeg2;
1442
		$longMin2 = $FORM::longMin2;
1443
		$longSec2 = $FORM::longSec2;
1444
		$hemisphLong2 = $FORM::hemisphLong2;
1445
	    } 
1446
	
1447
	
1448
	    my $hemisph;
1449
	    $hemisph = ($hemisphLong1 eq "W") ? -1 : 1;
1450
	    $cov .= "<westBoundingCoordinate>";
1451
	    my $var = $hemisph * ($longDeg1 + (60*$longMin1+$longSec1)/3600);
1452
	    $cov .= sprintf("%.4f\n", $var);
1453
	    $cov .= "</westBoundingCoordinate>\n";
1454
	    
1455
	    $hemisph = ($hemisphLong2 eq "W") ? -1 : 1;
1456
	    $cov .= "<eastBoundingCoordinate>";
1457
	    $var = $hemisph * ($longDeg2 + (60*$longMin2+$longSec2)/3600);
1458
	    $cov .= sprintf("%.4f\n", $var);
1459
	    $cov .= "</eastBoundingCoordinate>\n";
1460
	    
1461
	    $hemisph = ($hemisphLat1 eq "S") ? -1 : 1;
1462
	    $cov .= "<northBoundingCoordinate>";
1463
	    $var = $hemisph * ($latDeg1 + (60*$latMin1+$latSec1)/3600);
1464
	    $cov .= sprintf("%.4f\n", $var);	   
1465
	    $cov .= "</northBoundingCoordinate>\n";
1466
	    
1467
	    $hemisph = ($hemisphLat2 eq "S") ? -1 : 1;
1468
	    $cov .= "<southBoundingCoordinate>";
1469
	    $var = $hemisph * ($latDeg2 + (60*$latMin2+$latSec2)/3600);
1470
	    $cov .= sprintf("%.4f\n", $var);
1471
	    $cov .= "</southBoundingCoordinate>\n";
1472
	    
1473
	    $cov .= "</boundingCoordinates>\n";
1474
	}
1475
	$cov .= "</geographicCoverage>\n";
1731
            $cov .= "</boundingCoordinates>\n";
1732
        }
1733
        $cov .= "</geographicCoverage>\n";
1476 1734
    }
1477 1735

  
1478
    # Write out the taxonomic coverage fields
1736
    # taxonomic coverage
1479 1737
    my $foundFirstTaxon = 0;
1480 1738
    foreach my $trn (param()) {
1481 1739
        if ($trn =~ /taxonRankName/) {
......
1499 1757
            }
1500 1758
        }
1501 1759
    }
1760

  
1502 1761
    if ($foundFirstTaxon) {
1503 1762
        $cov .= "</taxonomicCoverage>\n";
1504 1763
    }
1505 1764

  
1506
    if($cov ne "" ){
1507
	$doc .= "<coverage>".$cov."</coverage>";
1765
    return "<coverage>\n$cov</coverage>\n"; 
1766
}
1767

  
1768
sub distributionElement() {
1769
    my $dist = "";
1770
    if (hasContent($FORM::addComments)) {
1771
        $dist .= "<additionalInfo>\n";
1772
        $dist .= "<para>".normalize($FORM::addComments)."</para>\n";
1773
        $dist .= "</additionalInfo>\n";
1508 1774
    }
1509
    $doc .= $cont;
1510
    $doc .= $publ;
1511
    
1512
    if ((hasContent($FORM::methodTitle)) || scalar(@FORM::methodsPara) > 0 || ($FORM::methodPara[0] ne "")) {
1513
        my $methods = "<methods><methodStep><description><section>\n";
1514
        if (hasContent($FORM::methodTitle)) {
1515
            $methods .= "<title>".normalize($FORM::methodTitle)."</title>\n";
1775

  
1776
    if (hasContent($FORM::useConstraints) ||
1777
        hasContent($FORM::useConstraintsOther)) {
1778
        $dist .= "<intellectualRights>\n";
1779
        if (hasContent($FORM::useConstraints)) {
1780
            $dist .= "<para>".normalize($FORM::useConstraints)."</para>\n";
1516 1781
        }
1517
        for (my $i = 0; $i < scalar(@FORM::methodPara); $i++) {
1518
            $methods .= "<para>".normalize($FORM::methodPara[$i])."</para>\n";
1782
        if (hasContent($FORM::useConstraintsOther)) {
1783
            $dist .= "<para>".normalize($FORM::useConstraintsOther)."</para>\n";
1519 1784
        }
1520
        $methods .= "</section></description></methodStep>\n";
1521
        if (hasContent($FORM::studyExtentDescription)) {
1522
            $methods .= "<sampling><studyExtent><description>\n";
1523
            $methods .= "<para>".normalize($FORM::studyExtentDescription)."</para>\n";
1524
            $methods .= "</description></studyExtent>\n";
1525
            $methods .= "<samplingDescription>\n";
1526
            $methods .= "<para>".normalize($FORM::samplingDescription)."</para>\n";
1527
            $methods .= "</samplingDescription>\n";
1528
            $methods .= "</sampling>\n";
1529
        }
1530
        $methods .= "</methods>\n";
1531
        $doc .= $methods;
1785
        $dist .= "</intellectualRights>\n";
1532 1786
    }
1533 1787

  
1534
    $doc .= "<access authSystem=\"knb\" order=\"denyFirst\">\n";
1535
    $doc .= "<allow>\n";
1536
    $doc .= "<principal>$username</principal>\n";
1537
    $doc .= "<permission>all</permission>\n";
1538
    $doc .= "</allow>\n";
1539 1788

  
1789
    if (hasContent($FORM::url)) {
1790
        $dist .= "<distribution>\n";
1791
        $dist .= "<online>\n";
1792
        $dist .= "<url>".normalize($FORM::url)."</url>\n";
1793
        $dist .= "</online>\n";
1794
        $dist .= "</distribution>\n";
1795
    }
1796

  
1797
    $dist .= "<distribution>\n";
1798
    $dist .= "<offline>\n";
1799
    $dist .= "<mediumName>" . normalize($FORM::dataMedium)." ".normalize($FORM::dataMediumOther);
1800
    $dist .= "</mediumName>\n";
1801
    $dist .= "</offline>\n";
1802
    $dist .= "</distribution>\n";
1803
    return $dist;
1804
}
1805

  
1806
#
1807
sub accessElement {
1808
    my $access = "";
1809

  
1810
    $access .= "<access authSystem=\"knb\" order=\"denyFirst\">\n";
1811
    $access .= "<allow>\n";
1812
    $access .= "<principal>$username</principal>\n";
1813
    $access .= "<permission>all</permission>\n";
1814
    $access .= "</allow>\n";
1815

  
1540 1816
    if($moderators eq ''){
1541
	if($FORM::username ne ''){
1542
    		$doc .= "<allow>\n";
1543
    		$doc .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n";
1544
    		$doc .= "<permission>all</permission>\n";
1545
    		$doc .= "</allow>\n";
1546
	} else {
1547
		my $session = CGI::Session->load();
1548
    		if ( !$session->is_empty ) {
1549
        		my $username = $session->param("username");
1550
    			$doc .= "<allow>\n";
1551
    			$doc .= "<principal>$username</principal>\n";
1552
    			$doc .= "<permission>all</permission>\n";
1553
    			$doc .= "</allow>\n";
1554
		}
1555
	}
1817
    if($FORM::username ne ''){
1818
            $access .= "<allow>\n";
1819
            $access .= "<principal>uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org</principal>\n";
1820
            $access .= "<permission>all</permission>\n";
1821
            $access .= "</allow>\n";
1556 1822
    } else {
1557
    	foreach(split(":",$moderators)){
1558
    	    $doc .= "<allow>\n";
1559
    	    $doc .= "<principal>".$_."</principal>\n";
1560
    	    $doc .= "<permission>all</permission>\n";
1561
    	    $doc .= "</allow>\n";
1823
        my $session = CGI::Session->load();
1824
            if ( !$session->is_empty ) {
1825
                my $username = $session->param("username");
1826
                $access .= "<allow>\n";
1827
                $access .= "<principal>$username</principal>\n";
1828
                $access .= "<permission>all</permission>\n";
1829
                $access .= "</allow>\n";
1562 1830
        }
1831
    }
1832
    } else {
1833
        foreach(split(":",$moderators)) {
1834
            $access .= "<allow>\n";
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff