Project

General

Profile

« Previous | Next » 

Revision 1977

Added by Matt Jones about 21 years ago

Modifications that allow working group entries to be put in as creators, and
a whole bunch of re-formatting for horribly formatted code that I need to
read to finish this thing up.

View differences:

src/perl/register-dataset.cgi
204 204

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

  
215 215
}elsif ($FORM::stage =~ "delete") {
......
311 311
debug( "Registry: A");
312 312
    if ($FORM::docid eq "") {
313 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/;
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 320
    
321 321
            #my $testFile = "/usr/local/apache2/htdocs/xml/test.xml";
322 322
            #open (TFILE,">$testFile") || die ("Cant open xml file...\n");
323 323
            #print TFILE $xmldoc;
324 324
            #close(TFILE);
325 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
	        #   }
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 334

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

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

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

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

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

  
384
	    exit(0);
384
        exit(0);
385 385
    }
386 386
}
387 387

  
......
630 630
    # and long mentioned in the config file. 
631 631

  
632 632
    if ($FORM::useSiteCoord) {
633
	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.")
634
	    unless(hasContent($latDeg1) && hasContent($longDeg1));
633
    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.")
634
        unless(hasContent($latDeg1) && hasContent($longDeg1));
635 635
    }else{
636
	push(@invalidParams, "Latitude degrees are missing.")
637
	    unless hasContent($latDeg1);
638
	push(@invalidParams, "Longitude degrees are missing.")
639
	    unless hasContent($longDeg1);
636
    push(@invalidParams, "Latitude degrees are missing.")
637
        unless hasContent($latDeg1);
638
    push(@invalidParams, "Longitude degrees are missing.")
639
        unless hasContent($longDeg1);
640 640
    }
641 641

  
642 642
    push(@invalidParams, "Contact first name is missing.")
643
	unless (hasContent($FORM::origNamefirstContact) || 
644
		$FORM::useOrigAddress);
643
    unless (hasContent($FORM::origNamefirstContact) || 
644
        $FORM::useOrigAddress);
645 645
    push(@invalidParams, "Contact last name is missing.")
646
	unless (hasContent($FORM::origNamelastContact) || 
647
		$FORM::useOrigAddress);
646
    unless (hasContent($FORM::origNamelastContact) || 
647
        $FORM::useOrigAddress);
648 648
    push(@invalidParams, "Data medium is missing.")
649
	unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/);
649
    unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/);
650 650
    
651 651
    if($chkUser){
652
	my $errorUserPass = validateUserPass();
653
	if($errorUserPass ne ""){
654
	    push(@invalidParams, $errorUserPass);
655
	}
652
    my $errorUserPass = validateUserPass();
653
    if($errorUserPass ne ""){
654
        push(@invalidParams, $errorUserPass);
656 655
    }
656
    }
657 657

  
658 658
    return \@invalidParams;
659 659
}
......
741 741
    }
742 742

  
743 743
    if (hasContent($FORM::origNamelast0)) {
744
	$role = "creator";
744
    $role = "creator";
745 745
        $orig .= "<individualName>\n";
746 746
        $orig .= "<givenName>$FORM::origNamefirst0</givenName>\n";
747 747
        $orig .= "<surName>$FORM::origNamelast0</surName>\n";
......
766 766
            $orig .= "<city>$FORM::origCity</city>\n";
767 767
        }
768 768

  
769
	if (hasContent($FORM::origState) && 
769
    if (hasContent($FORM::origState) && 
770 770
            ($FORM::origState !~ "Select state here.")) {
771 771
            $orig .= "<administrativeArea>$FORM::origState";
772 772
            $orig .= "</administrativeArea>\n";
......
800 800
    if ($FORM::useOrigAddress) {
801 801
        # Add a contact originator like the original with a different role
802 802
            $cont .= "<contact>\n";
803
	    $cont .= $orig;
804
	    $cont .= "</contact>\n";
803
        $cont .= $orig;
804
        $cont .= "</contact>\n";
805 805
    } else {
806 806
        $cont .= "<contact>\n";
807 807

  
......
810 810
        $cont .= "<surName>$FORM::origNamelastContact</surName>\n";
811 811
        $cont .= "</individualName>\n";
812 812
 
813
	if (hasContent($FORM::origNameOrgContact)) {
814
	    $cont .= "<organizationName>$FORM::origNameOrgContact</organizationName>\n";
815
	}
813
    if (hasContent($FORM::origNameOrgContact)) {
814
        $cont .= "<organizationName>$FORM::origNameOrgContact</organizationName>\n";
815
    }
816 816

  
817 817
        if (hasContent($FORM::origDeliveryContact) || 
818 818
            hasContent($FORM::origCityContact) ||
......
848 848
        if (hasContent($FORM::origPhoneContact)) {
849 849
            $cont .= "<phone>$FORM::origPhoneContact</phone>\n";
850 850
        }
851
	if (hasContent($FORM::origFAXContact)) {
852
	    $cont .= "<phone phonetype=\"Fax\">$FORM::origFAXContact</phone>\n";
853
	}
851
    if (hasContent($FORM::origFAXContact)) {
852
        $cont .= "<phone phonetype=\"Fax\">$FORM::origFAXContact</phone>\n";
853
    }
854 854
        if (hasContent($FORM::origEmailContact)) {
855 855
            $cont .= "<electronicMailAddress>$FORM::origEmailContact";
856 856
            $cont .= "</electronicMailAddress>\n";
857 857
        }
858
	$cont .= "</contact>\n";
858
    $cont .= "</contact>\n";
859 859
    }
860 860

  
861 861
    $metaP .= "<metadataProvider>\n";
......
885 885
                # do not generate XML for empty originator fields 
886 886
                if (hasContent(param("origNamefirst" . $tmp1))) {    
887 887

  
888
		    my $add = "";
889
		    $add .= "<individualName>\n";
890
		    $add .= "<givenName>";
891
		    $add .= param("origNamefirst" . $tmp1);
892
		    $add .= "</givenName>\n";
893
		    $add .= "<surName>";
894
		    $add .= param("origNamelast" . $tmp1);
895
		    $add .= "</surName>\n";
896
		    $add .= "</individualName>\n";
897
		    
898
		    if(param("origRole" . $tmp1) eq "Originator"){
899
			$creat .= "<creator>\n";
900
			$creat .= $add;
901
			$creat .= "</creator>\n";
902
		    }
903
		    elsif(param("origRole" . $tmp1) eq "Metadata Provider"){
904
			$metaP .= "<metadataProvider>\n";
905
			$metaP .= $add;
906
			$metaP .= "</metadataProvider>\n";
907
		    }
908
		    elsif((param("origRole" . $tmp1) eq "Publisher")  && ($publ eq "")){
909
			$publ .= "<publisher>\n";
910
			$publ .= $add;
911
			$publ .= "</publisher>\n";
912
		    }
913
		    else{
914
			$apart .= "<associatedParty>\n";
915
			$apart .= $add;
916
			$apart .= "<role>";
917
			$apart .= param("origRole" . $tmp1);
918
			$apart .= "</role>\n";
919
			$apart .= "</associatedParty>\n";
920
		    }
921
		}
888
            my $add = "";
889
            $add .= "<individualName>\n";
890
            $add .= "<givenName>";
891
            $add .= param("origNamefirst" . $tmp1);
892
            $add .= "</givenName>\n";
893
            $add .= "<surName>";
894
            $add .= param("origNamelast" . $tmp1);
895
            $add .= "</surName>\n";
896
            $add .= "</individualName>\n";
897
            
898
            if(param("origRole" . $tmp1) eq "Originator"){
899
            $creat .= "<creator>\n";
900
            $creat .= $add;
901
            $creat .= "</creator>\n";
922 902
            }
903
            elsif(param("origRole" . $tmp1) eq "Metadata Provider"){
904
            $metaP .= "<metadataProvider>\n";
905
            $metaP .= $add;
906
            $metaP .= "</metadataProvider>\n";
907
            }
908
            elsif((param("origRole" . $tmp1) eq "Publisher")  && ($publ eq "")){
909
            $publ .= "<publisher>\n";
910
            $publ .= $add;
911
            $publ .= "</publisher>\n";
912
            }
913
            else{
914
            $apart .= "<associatedParty>\n";
915
            $apart .= $add;
916
            $apart .= "<role>";
917
            $apart .= param("origRole" . $tmp1);
918
            $apart .= "</role>\n";
919
            $apart .= "</associatedParty>\n";
920
            }
923 921
        }
922
            }
923
        }
924 924
    }
925 925

  
926 926
    $creat .= "<creator>\n";
......
931 931
    $creat .= "<organizationName>$organization</organizationName>\n";
932 932
    $creat .= "</creator>\n";
933 933

  
934
    if ($FORM::cfg eq 'nceas') {
935
        for (my $i = 0; $i < scalar(@FORM::wg); $i++) {
936
            $creat .= "<creator>\n";
937
            $creat .= "<organizationName>$FORM::wg[$i]</organizationName>\n";
938
            $creat .= "</creator>\n";
939
        }
940
    }
934 941
    $doc .= $creat;
935 942
    $doc .= $metaP;
936 943
    $doc .= $apart;
......
988 995

  
989 996
    
990 997
    if (hasContent($FORM::url)) {
991
	$doc .= "<distribution>\n";
998
    $doc .= "<distribution>\n";
992 999
        $doc .= "<online>\n";
993
	$doc .= "<url>$FORM::url</url>\n";
994
	$doc .= "</online>\n";
995
	$doc .= "</distribution>\n";
1000
    $doc .= "<url>$FORM::url</url>\n";
1001
    $doc .= "</online>\n";
1002
    $doc .= "</distribution>\n";
996 1003
    }
997 1004
    
998 1005
    $doc .= "<distribution>\n";
......
1007 1014

  
1008 1015

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

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

  
1062 1069
    $doc .= "</temporalCoverage>\n";
1063 1070
    
......
1246 1253
    $doc = $httpMessage->content();
1247 1254
    $xmldoc = $parser->parse_string($doc);
1248 1255

  
1249
#    $tempfile = $xslConvDir.$docid;
1250
#    push (@fileArray, $tempfile);
1256
    #$tempfile = $xslConvDir.$docid;
1257
    #push (@fileArray, $tempfile);
1251 1258

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

  
1296
	    # Read the main document. 
1304
            # Read the main document. 
1297 1305

  
1298
	    $tempfile = $tmpdir."/".$docid; #= $xslConvDir.$docid;
1299
	    open (TFILE,">$tempfile") || die ("Cant open xml file...\n");
1300
	    print TFILE $doc;
1301
	    close(TFILE);
1302
	    
1303
	    # Transforming beta6 to eml 2
1304
	    my $xslt;
1305
	    my $triplesheet;
1306
	    my $results;
1307
	    my $stylesheet;
1308
	    my $resultsheet;
1309
	    
1310
	    $xslt = XML::LibXSLT->new();
1311
#	    $tempfile = $xslConvDir."triple_info.xsl";
1312
	    $tempfile = $tmpdir."/"."triple_info.xsl";
1306
            $tempfile = $tmpdir."/".$docid; #= $xslConvDir.$docid;
1307
            open (TFILE,">$tempfile") || die ("Cant open xml file...\n");
1308
            print TFILE $doc;
1309
            close(TFILE);
1310
        
1311
            # Transforming beta6 to eml 2
1312
            my $xslt;
1313
            my $triplesheet;
1314
            my $results;
1315
            my $stylesheet;
1316
            my $resultsheet;
1317
        
1318
            $xslt = XML::LibXSLT->new();
1319
            #$tempfile = $xslConvDir."triple_info.xsl";
1320
            $tempfile = $tmpdir."/"."triple_info.xsl";
1321
    
1322
            $triplesheet = $xslt->parse_stylesheet_file($tempfile);
1313 1323

  
1314
	    $triplesheet = $xslt->parse_stylesheet_file($tempfile);
1324
            #$results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1325
            $results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1315 1326

  
1316
#	    $results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1317
	    $results = $triplesheet->transform($xmldoc, packageDir => "\'$tmpdir/\'", packageName => "\'$docid\'");
1327
            #$tempfile = $xslConvDir."emlb6toeml2.xsl";
1328
            $tempfile = $tmpdir."/"."emlb6toeml2.xsl";
1329
            $stylesheet = $xslt->parse_stylesheet_file($tempfile);
1330
            $resultsheet = $stylesheet->transform($results);
1331
        
1332
            #$tempfile = "/usr/local/apache2/htdocs/xml/test.xml";;
1333
            #open (TFILE,">$tempfile") || die ("Cant open xml file...\n");
1334
            #print TFILE $stylesheet->output_string($resultsheet);
1335
            #close(TFILE);
1318 1336

  
1319
#	    $tempfile = $xslConvDir."emlb6toeml2.xsl";
1320
	    $tempfile = $tmpdir."/"."emlb6toeml2.xsl";
1321
	    $stylesheet = $xslt->parse_stylesheet_file($tempfile);
1322
	    $resultsheet = $stylesheet->transform($results);
1323
	    
1324
	    #$tempfile = "/usr/local/apache2/htdocs/xml/test.xml";;
1325
	    #open (TFILE,">$tempfile") || die ("Cant open xml file...\n");
1326
	    #print TFILE $stylesheet->output_string($resultsheet);
1327
	    #close(TFILE);
1337
            getFormValuesFromEml2($resultsheet);
1338
            
1339
            # Delete the files written earlier. 
1340
            unlink @fileArray;
1328 1341

  
1329
	    getFormValuesFromEml2($resultsheet);
1330
	    
1331
	    # Delete the files written earlier. 
1332
	    unlink @fileArray;
1333

  
1334
	} else {
1335
	    getFormValuesFromEml2($xmldoc);
1336
	}
1342
        } else {
1343
            getFormValuesFromEml2($xmldoc);
1344
        }
1337 1345
    }   
1338 1346
    
1339 1347
    if (scalar(@errorMessages)) {
1340
	# if any errors, print them in the response template 
1341
	$$templateVars{'status'} = 'failure';
1342
	$$templateVars{'errorMessages'} = \@errorMessages;
1343
	$error = 1;
1344
	$$templateVars{'function'} = "modification";
1345
	$$templateVars{'section'} = "Modification Status";
1346
	$template->process( $responseTemplate, $templateVars); 
1348
    # if any errors, print them in the response template 
1349
    $$templateVars{'status'} = 'failure';
1350
    $$templateVars{'errorMessages'} = \@errorMessages;
1351
    $error = 1;
1352
    $$templateVars{'function'} = "modification";
1353
    $$templateVars{'section'} = "Modification Status";
1354
    $template->process( $responseTemplate, $templateVars); 
1347 1355
    } else {
1348 1356
        $$templateVars{'form'} = 're_entry';
1349
	$template->process( $entryFormTemplate, $templateVars);
1357
        $template->process( $entryFormTemplate, $templateVars);
1350 1358
    }
1351 1359
    
1352 1360
    # process the response template
......
1354 1362

  
1355 1363

  
1356 1364

  
1365
################################################################################
1366
# 
1367
# Parse an EML 2.0.0 file and extract the metadata into perl variables for 
1368
# processing and returning to the template processor
1369
#
1370
################################################################################
1357 1371
sub getFormValuesFromEml2 {
1358 1372
    
1359 1373
    my $doc = shift;
......
1367 1381

  
1368 1382
    # find out the tag <alternateIdentifier>. 
1369 1383
    $results = $doc->findnodes('//dataset/alternateIdentifier');
1370
    if($results->size() > 1){
1371
	errMoreThanOne("alternateIdentifier");
1384
    if ($results->size() > 1) {
1385
        errMoreThanOne("alternateIdentifier");
1372 1386
    } else {
1373
	foreach $node ($results->get_nodelist){
1374
	    $$templateVars{'identifier'} = findValue($node, '../alternateIdentifier');
1375
	}
1387
        foreach $node ($results->get_nodelist) {
1388
            $$templateVars{'identifier'} = findValue($node, '../alternateIdentifier');
1389
        }
1376 1390
    }
1377 1391

  
1378 1392
    # find out the tag <title>. 
1379 1393
    $results = $doc->findnodes('//dataset/title');
1380
    if($results->size() > 1){
1381
	errMoreThanOne("title");
1382
    } elsif($results->size() < 1){
1383
	$error ="Following tag not found: title. Please use Morpho to edit this document";
1384
	push(@errorMessages, $error."\n");
1385
	#if ($DEBUG == 1){ print $error;}
1394
    if ($results->size() > 1) {
1395
        errMoreThanOne("title");
1396
    } elsif ($results->size() < 1) {
1397
        $error ="Following tag not found: title. Please use Morpho to edit this document";
1398
        push(@errorMessages, $error."\n");
1399
        #if ($DEBUG == 1){ print $error;}
1386 1400
    } else {
1387
	foreach $node ($results->get_nodelist){
1388
	$$templateVars{'title'} = findValue($node, '../title');
1389
	}
1401
        foreach $node ($results->get_nodelist) {
1402
            $$templateVars{'title'} = findValue($node, '../title');
1403
        }
1390 1404
    }
1391 1405

  
1392 1406
    # find out the tag <creator>. 
1393 1407
    $results = $doc->findnodes('//dataset/creator/individualName');
1394
    if($results->size() > 11){
1395
	errMoreThanN("creator/individualName");
1408
    if ($results->size() > 11) {
1409
        errMoreThanN("creator/individualName");
1396 1410
    } else {
1397
	foreach $node ($results->get_nodelist){
1398
	    dontOccur($node, "../positionName|../onlineURL|../userId", 
1399
		      "positionName, onlineURL, userId");
1400
	    
1401
	    dontOccur($node, "./saluation", "saluation");			    
1402
	    
1403
	    $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1404
	    if($tempResult->size > 0){
1405
		if($foundDSO == 0){
1406
		    $foundDSO = 1;
1411
        foreach $node ($results->get_nodelist) {
1412
            dontOccur($node, "../positionName|../onlineURL|../userId", 
1413
              "positionName, onlineURL, userId");
1414
        
1415
            dontOccur($node, "./saluation", "saluation");                
1416
        
1417
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1418
            if($tempResult->size > 0) {
1419
                if($foundDSO == 0) {
1420
                    $foundDSO = 1;
1407 1421
     
1408
		    $$templateVars{'origNamefirst0'} = findValue($node, 'givenName');
1409
		    $$templateVars{'origNamelast0'} = findValue($node, 'surName');
1410
			
1411
		    my $tempResult2 = $node->findnodes('../address');
1412
		    if($tempResult2->size > 1){
1413
			errMoreThanOne("address");
1414
		    } else {
1415
			foreach my $tempNode2 ($tempResult2->get_nodelist){
1416
			    $$templateVars{'origDelivery'} = findValue($tempNode2, 'deliveryPoint');
1417
			    $$templateVars{'origCity'} = findValue($tempNode2, 'city');
1418
			    $$templateVars{'origState'} = findValue($tempNode2, 'administrativeArea');
1419
			    $$templateVars{'origZIP'} = findValue($tempNode2, 'postalCode');
1420
			    $$templateVars{'origCountry'} = findValue($tempNode2, 'country');
1421
			}
1422
		    }
1423
		    
1424
		    my $tempResult3 = $node->findnodes('../phone');
1425
		    if($tempResult3->size > 2){
1426
			errMoreThanN("phone");
1427
		    } else {
1428
			foreach my $tempNode2 ($tempResult3->get_nodelist){
1429
			    if($tempNode2->hasAttributes()){
1430
				my @attlist = $tempNode2->attributes();
1431
				if($attlist[0]->value eq "Fax"){
1432
				    $$templateVars{'origFAX'} = $tempNode2->textContent();
1433
				} else {
1434
				    $$templateVars{'origPhone'} = $tempNode2->textContent();
1435
				}
1436
			    } else{
1437
				$$templateVars{'origPhone'} = $tempNode2->textContent();
1438
			    }
1439
			}
1440
		    }
1441
		    $$templateVars{'origEmail'} = findValue($node, '../electronicMailAddress');
1442
		    $$templateVars{'origNameOrg'} = findValue($node, '../organizationName');
1443
		} else {
1444
		    errMoreThanN("address, phone and electronicMailAddress");
1445
		}
1446
	    }
1447
	}
1448
	foreach $node ($results->get_nodelist){
1449
	    $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress');
1450
	    if($tempResult->size == 0){
1451
		if($foundDSO == 0){
1452
		    $foundDSO = 1;
1453
		    $$templateVars{'origNamefirst0'} = findValue($node, 'givenName');
1454
		    $$templateVars{'origNamelast0'} = findValue($node, 'surName');
1455
		    $$templateVars{'origNameOrg'} = findValue($node, '../organizationName');
1456
		} else {
1457
		    $$templateVars{"origNamefirst$aoCount"} =  findValue($node, './givenName');
1458
		    $$templateVars{"origNamelast$aoCount"} =  findValue($node, './surName');
1459
		    $$templateVars{"origRole$aoCount"} = "Originator";
1460
		    $aoCount++;
1461
		}
1462
	    }
1463
	}
1422
                    $$templateVars{'origNamefirst0'} = findValue($node, 'givenName');
1423
                    $$templateVars{'origNamelast0'} = findValue($node, 'surName');
1424
            
1425
                    my $tempResult2 = $node->findnodes('../address');
1426
                    if ($tempResult2->size > 1) {
1427
                        errMoreThanOne("address");
1428
                    } else {
1429
                        foreach my $tempNode2 ($tempResult2->get_nodelist) {
1430
                            $$templateVars{'origDelivery'} = findValue($tempNode2, 'deliveryPoint');
1431
                            $$templateVars{'origCity'} = findValue($tempNode2, 'city');
1432
                            $$templateVars{'origState'} = findValue($tempNode2, 'administrativeArea');
1433
                            $$templateVars{'origZIP'} = findValue($tempNode2, 'postalCode');
1434
                            $$templateVars{'origCountry'} = findValue($tempNode2, 'country');
1435
                        }
1436
                    }
1437
            
1438
                    my $tempResult3 = $node->findnodes('../phone');
1439
                    if ($tempResult3->size > 2) {
1440
                        errMoreThanN("phone");
1441
                    } else {
1442
                        foreach my $tempNode2 ($tempResult3->get_nodelist) {
1443
                            if ($tempNode2->hasAttributes()) {
1444
                                my @attlist = $tempNode2->attributes();
1445
                                if ($attlist[0]->value eq "Fax") {
1446
                                    $$templateVars{'origFAX'} = $tempNode2->textContent();
1447
                                } else {
1448
                                    $$templateVars{'origPhone'} = $tempNode2->textContent();
1449
                                }
1450
                            } else {
1451
                                $$templateVars{'origPhone'} = $tempNode2->textContent();
1452
                            }
1453
                        }
1454
                    }
1455
                    $$templateVars{'origEmail'} = findValue($node, '../electronicMailAddress');
1456
                    $$templateVars{'origNameOrg'} = findValue($node, '../organizationName');
1457
                } else {
1458
                    errMoreThanN("address, phone and electronicMailAddress");
1459
                }
1460
            }
1461
        }
1462
        foreach $node ($results->get_nodelist) {
1463
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress');
1464
            if ($tempResult->size == 0) {
1465
                if ($foundDSO == 0) {
1466
                    $foundDSO = 1;
1467
                    $$templateVars{'origNamefirst0'} = findValue($node, 'givenName');
1468
                    $$templateVars{'origNamelast0'} = findValue($node, 'surName');
1469
                    $$templateVars{'origNameOrg'} = findValue($node, '../organizationName');
1470
                } else {
1471
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($node, './givenName');
1472
                    $$templateVars{"origNamelast$aoCount"} =  findValue($node, './surName');
1473
                    $$templateVars{"origRole$aoCount"} = "Originator";
1474
                    $aoCount++;
1475
                }
1476
            }
1477
        }
1464 1478
    }
1465 1479

  
1466 1480
    $results = $doc->findnodes('//dataset/creator/organizationName');
1467
    if($results->size() > 3){
1468
	errMoreThanN("creator/organizationName");	
1481
    if ($results->size() > 3) {
1482
        errMoreThanN("creator/organizationName");    
1469 1483
    } else {
1470
	foreach $node ($results->get_nodelist){
1484
        foreach $node ($results->get_nodelist) {
1471 1485

  
1472
	    my $tempValue = findValue($node,'../organizationName');
1473
	    $tempResult = $node->findnodes('../individualName');
1474
	    if($tempResult->size == 0 && $tempValue ne $organization){
1475
		$$templateVars{'site'} = $tempValue;
1476
	    }
1477
	}
1486
            my $tempValue = findValue($node,'../organizationName');
1487
            $tempResult = $node->findnodes('../individualName');
1488
            if ($tempResult->size == 0 && $tempValue ne $organization) {
1489
                $$templateVars{'site'} = $tempValue;
1490
            }
1491
        }
1478 1492
    }
1479 1493

  
1480 1494
    $results = $doc->findnodes('//dataset/metadataProvider');
1481
    if($results->size() > 11){
1482
	errMoreThanN("metadataProvider");	
1495
    if ($results->size() > 11) {
1496
        errMoreThanN("metadataProvider");    
1483 1497
    } else {
1484
	foreach $node ($results->get_nodelist){
1485
	    dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1486
		      "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in metadataProvider");
1487
	    
1488
	    $tempResult = $node->findnodes('./individualName');
1489
	    if($tempResult->size > 1){
1490
		errMoreThanOne("metadataProvider/indvidualName");
1491
	    }else{
1492
		foreach $tempNode ($tempResult->get_nodelist){
1493
		    if($$templateVars{'providerGivenName'} ne ""){
1494
			$$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1495
			$$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1496
			$$templateVars{"origRole$aoCount"} = "Metadata Provider";
1497
			$aoCount++;
1498
		    } else {
1499
			$$templateVars{'providerGivenName'} =  findValue($tempNode, './givenName');
1500
			$$templateVars{'providerSurName'} =  findValue($tempNode, './surName');
1501
		    }
1502
		}
1503
	    }
1504
	}
1498
        foreach $node ($results->get_nodelist) {
1499
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1500
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in metadataProvider");
1501
        
1502
            $tempResult = $node->findnodes('./individualName');
1503
            if ($tempResult->size > 1) {
1504
                errMoreThanOne("metadataProvider/indvidualName");
1505
            } else {
1506
                foreach $tempNode ($tempResult->get_nodelist) {
1507
                    if ($$templateVars{'providerGivenName'} ne "") {
1508
                        $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1509
                        $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1510
                        $$templateVars{"origRole$aoCount"} = "Metadata Provider";
1511
                        $aoCount++;
1512
                    } else {
1513
                        $$templateVars{'providerGivenName'} =  findValue($tempNode, './givenName');
1514
                        $$templateVars{'providerSurName'} =  findValue($tempNode, './surName');
1515
                    }
1516
                }
1517
            }
1518
        }
1505 1519
    }
1506 1520

  
1507

  
1508 1521
    $results = $doc->findnodes('//dataset/associatedParty');
1509
    if($results->size() > 10){
1510
	errMoreThanN("associatedParty");
1522
    if ($results->size() > 10) {
1523
        errMoreThanN("associatedParty");
1511 1524
    } else {
1512
	foreach $node ($results->get_nodelist){
1513
	    dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1514
		      "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty");
1515
	   
1516
	    $tempResult = $node->findnodes('./individualName');
1517
	    if($tempResult->size > 1){
1518
		errMoreThanOne("associatedParty/indvidualName");
1519
	    }else{
1520
		foreach $tempNode ($tempResult->get_nodelist){
1521
		    $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1522
		    $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1523
		    $$templateVars{"origRole$aoCount"} = findValue($tempNode, '../role');
1524
		    $aoCount++;		   
1525
		}
1526
	    }
1527
	}
1525
        foreach $node ($results->get_nodelist) {
1526
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1527
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty");
1528
       
1529
            $tempResult = $node->findnodes('./individualName');
1530
            if ($tempResult->size > 1) {
1531
                errMoreThanOne("associatedParty/indvidualName");
1532
            } else {
1533
                foreach $tempNode ($tempResult->get_nodelist) {
1534
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1535
                    $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1536
                    $$templateVars{"origRole$aoCount"} = findValue($tempNode, '../role');
1537
                    $aoCount++;           
1538
                }
1539
            }
1540
        }
1528 1541
    }
1529 1542

  
1530 1543
    $results = $doc->findnodes('//dataset/publisher');
1531
    if($results->size() > 10){
1532
	errMoreThanN("publisher");
1544
    if ($results->size() > 10) {
1545
        errMoreThanN("publisher");
1533 1546
    } else {
1534
	foreach $node ($results->get_nodelist){
1535
	    dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
1536
		      "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in associatedParty");
1537
	   
1538
	    $tempResult = $node->findnodes('./individualName');
1539
	    if($tempResult->size > 1){
1540
		errMoreThanOne("publisher/indvidualName");
1541
	    }else{
1542
		foreach $tempNode ($tempResult->get_nodelist){
1543
		    $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1544
		    $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1545
		    $$templateVars{"origRole$aoCount"} = "Publisher";
1546
		    $aoCount++;		   
1547
		}
1548
	    }
1549
	}
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 associatedParty");
1550
       
1551
            $tempResult = $node->findnodes('./individualName');
1552
            if ($tempResult->size > 1) {
1553
                errMoreThanOne("publisher/indvidualName");
1554
            } else {
1555
                foreach $tempNode ($tempResult->get_nodelist) {
1556
                    $$templateVars{"origNamefirst$aoCount"} =  findValue($tempNode, './givenName');
1557
                    $$templateVars{"origNamelast$aoCount"} =  findValue($tempNode, './surName');
1558
                    $$templateVars{"origRole$aoCount"} = "Publisher";
1559
                    $aoCount++;           
1560
                }
1561
            }
1562
        }
1550 1563
    }
1551 1564

  
1552
    if($aoCount > 11){
1553
	errMoreThanN("Additional Originators");
1565
    if ($aoCount > 11) {
1566
        errMoreThanN("Additional Originators");
1554 1567
    } 
1555 1568

  
1556 1569
    dontOccur($doc, "./pubDate", "pubDate");
1557 1570
    dontOccur($doc, "./language", "language");
1558 1571
    dontOccur($doc, "./series", "series");
1559
    
1560 1572

  
1561 1573
    $results = $doc->findnodes('//dataset/abstract');
1562
    if($results->size() > 1){
1563
	errMoreThanOne("abstract");
1574
    if ($results->size() > 1) {
1575
        errMoreThanOne("abstract");
1564 1576
    } else {
1565
	foreach my $node ($results->get_nodelist){
1566
	    dontOccur($node, "./section", "section");
1567
	    $$templateVars{'abstract'} = findValueNoChild($node, "para");
1568
	}
1577
        foreach my $node ($results->get_nodelist) {
1578
            dontOccur($node, "./section", "section");
1579
            $$templateVars{'abstract'} = findValueNoChild($node, "para");
1580
        }
1569 1581
    }
1570 1582

  
1571 1583
    $results = $doc->findnodes('//dataset/keywordSet');
1572
    if($results->size() > 10){
1573
	errMoreThanN("keywordSet");
1584
    if ($results->size() > 10) {
1585
        errMoreThanN("keywordSet");
1574 1586
    } else {
1575
	my $count = 0;
1576
	foreach $node ($results->get_nodelist){
1577
	    $tempResult = $node->findnodes('./keyword');
1578
	    if($tempResult->size() > 1){
1579
		errMoreThanOne("keyword");
1580
	    } else {
1581
		foreach $tempNode ($tempResult->get_nodelist){
1582
		    $$templateVars{"keyword$count"} = $tempNode->textContent();
1583
		    if($tempNode->hasAttributes()){
1584
			my @attlist = $tempNode->attributes();
1585
			$$templateVars{"kwType$count"} = $attlist[0]->value;
1586
		    }  
1587
	 	} 
1588
	    }
1589
	    $$templateVars{"kwTh$count"} = findValue($node, "keywordThesaurus");
1590
	    $count++;
1591
	}
1592
	
1593
	while($count<11){
1594
	    $$templateVars{"kwType$count"} = "none";
1595
	    $$templateVars{"kwTh$count"} = "none";
1596
	    $count++;
1597
	}
1587
        my $count = 0;
1588
        foreach $node ($results->get_nodelist) {
1589
            $tempResult = $node->findnodes('./keyword');
1590
            if ($tempResult->size() > 1) {
1591
                errMoreThanOne("keyword");
1592
            } else {
1593
                foreach $tempNode ($tempResult->get_nodelist) {
1594
                    $$templateVars{"keyword$count"} = $tempNode->textContent();
1595
                    if ($tempNode->hasAttributes()) {
1596
                        my @attlist = $tempNode->attributes();
1597
                        $$templateVars{"kwType$count"} = $attlist[0]->value;
1598
                    }  
1599
                 } 
1600
            }
1601
            $$templateVars{"kwTh$count"} = findValue($node, "keywordThesaurus");
1602
            $count++;
1603
        }
1604
    
1605
        while ($count<11) {
1606
            $$templateVars{"kwType$count"} = "none";
1607
            $$templateVars{"kwTh$count"} = "none";
1608
            $count++;
1609
        }
1598 1610
    }
1599 1611

  
1600

  
1601 1612
    $results = $doc->findnodes('//dataset/additionalInfo');
1602
    if($results->size() > 1){
1603
	errMoreThanOne("additionalInfo");
1613
    if ($results->size() > 1) {
1614
        errMoreThanOne("additionalInfo");
1604 1615
    } else {
1605
	foreach $node ($results->get_nodelist){
1606
	    dontOccur($node, "./section", "section");
1607
	    $$templateVars{'addComments'} = findValueNoChild($node, "para");
1608
	}
1616
        foreach $node ($results->get_nodelist) {
1617
            dontOccur($node, "./section", "section");
1618
            $$templateVars{'addComments'} = findValueNoChild($node, "para");
1619
        }
1609 1620
    }
1610 1621

  
1611 1622
    $$templateVars{'useConstraints'} = "";
1612 1623
    $results = $doc->findnodes('//dataset/intellectualRights');
1613
    if($results->size() > 1){
1614
	errMoreThanOne("intellectualRights");
1624
    if ($results->size() > 1) {
1625
        errMoreThanOne("intellectualRights");
1615 1626
    } else {
1616
	foreach $node ($results->get_nodelist){
1617
	    dontOccur($node, "./section", "section in intellectualRights");
1627
        foreach $node ($results->get_nodelist) {
1628
            dontOccur($node, "./section", "section in intellectualRights");
1618 1629

  
1619
	    $tempResult = $node->findnodes("para");
1620
	    if($tempResult->size > 2){
1621
	   	errMoreThanN("para");
1622
	    } else {
1623
		foreach $tempNode ($tempResult->get_nodelist){
1624
		    my $childNodes = $tempNode->childNodes;
1625
		    if($childNodes->size() > 1){
1626
			$error ="The tag para in intellectualRights has children which cannot be shown using the form. Please use Morpho to edit this document";	
1627
			push(@errorMessages, $error);
1628
			#if ($DEBUG == 1){ print $error."\n";}
1629
		    }else{
1630
			#print $tempNode->nodeName().":".$tempNode->textContent();
1631
			#print "\n";
1632
			if($$templateVars{'useConstraints'} eq ""){
1633
			    $$templateVars{'useConstraints'} = $tempNode->textContent();
1634
			} else {
1635
			    $$templateVars{'useConstraintsOther'} = $tempNode->textContent();
1636
			}
1637
		    }
1638
		}
1639
	    }
1640
	}
1630
            $tempResult = $node->findnodes("para");
1631
            if ($tempResult->size > 2) {
1632
                   errMoreThanN("para");
1633
            } else {
1634
                foreach $tempNode ($tempResult->get_nodelist) {
1635
                    my $childNodes = $tempNode->childNodes;
1636
                    if ($childNodes->size() > 1) {
1637
                        $error ="The tag para in intellectualRights has children which cannot be shown using the form. Please use Morpho to edit this document";    
1638
                        push(@errorMessages, $error);
1639
                        #if ($DEBUG == 1){ print $error."\n";}
1640
                    } else {
1641
                        #print $tempNode->nodeName().":".$tempNode->textContent();
1642
                        #print "\n";
1643
                        if ($$templateVars{'useConstraints'} eq "") {
1644
                            $$templateVars{'useConstraints'} = $tempNode->textContent();
1645
                        } else {
1646
                            $$templateVars{'useConstraintsOther'} = $tempNode->textContent();
1647
                        }
1648
                    }
1649
                }
1650
            }
1651
        }
1641 1652
    }
1642 1653

  
1643

  
1644 1654
    $results = $doc->findnodes('//dataset/distribution/online');
1645
    if($results->size() > 1){
1646
	errMoreThanOne("distribution/online");
1655
    if ($results->size() > 1) {
1656
        errMoreThanOne("distribution/online");
1647 1657
    } else {
1648
	foreach my $tempNode ($results->get_nodelist){
1649
	    $$templateVars{'url'} = findValue($tempNode, "url");
1650
	    dontOccur($tempNode, "./connection", "/distribution/online/connection");
1651
	    dontOccur($tempNode, "./connectionDefinition", "/distribution/online/connectionDefinition");
1652
	}
1658
        foreach my $tempNode ($results->get_nodelist){
1659
            $$templateVars{'url'} = findValue($tempNode, "url");
1660
            dontOccur($tempNode, "./connection", "/distribution/online/connection");
1661
            dontOccur($tempNode, "./connectionDefinition", "/distribution/online/connectionDefinition");
1662
        }
1653 1663
    }
1654 1664

  
1655

  
1656 1665
    $results = $doc->findnodes('//dataset/distribution/offline');
1657
    if($results->size() > 1){
1658
	errMoreThanOne("distribution/online");
1666
    if ($results->size() > 1) {
1667
        errMoreThanOne("distribution/online");
1659 1668
    } else {
1660
	foreach my $tempNode ($results->get_nodelist){
1661
	    $$templateVars{'dataMedium'} = findValue($tempNode, "mediumName");
1662
	    dontOccur($tempNode, "./mediumDensity", "/distribution/offline/mediumDensity");
1663
	    dontOccur($tempNode, "./mediumDensityUnits", "/distribution/offline/mediumDensityUnits");
1664
	    dontOccur($tempNode, "./mediumVolume", "/distribution/offline/mediumVolume");
1665
	    dontOccur($tempNode, "./mediumFormat", "/distribution/offline/mediumFormat");
1666
	    dontOccur($tempNode, "./mediumNote", "/distribution/offline/mediumNote");
1667
	}
1669
        foreach my $tempNode ($results->get_nodelist) {
1670
            $$templateVars{'dataMedium'} = findValue($tempNode, "mediumName");
1671
            dontOccur($tempNode, "./mediumDensity", "/distribution/offline/mediumDensity");
1672
            dontOccur($tempNode, "./mediumDensityUnits", "/distribution/offline/mediumDensityUnits");
1673
            dontOccur($tempNode, "./mediumVolume", "/distribution/offline/mediumVolume");
1674
            dontOccur($tempNode, "./mediumFormat", "/distribution/offline/mediumFormat");
1675
            dontOccur($tempNode, "./mediumNote", "/distribution/offline/mediumNote");
1676
        }
1668 1677
    }
1669 1678

  
1670 1679
    dontOccur($doc, "./inline", "//dataset/distribution/inline");
1671 1680

  
1672

  
1673 1681
    $results = $doc->findnodes('//dataset/coverage');
1674
    if($results->size() > 1){
1675
	errMoreThanOne("coverage");
1682
    if ($results->size() > 1) {
1683
        errMoreThanOne("coverage");
1676 1684
    } else {
1677
	foreach $node ($results->get_nodelist){
1678
	    dontOccur($node, "./temporalCoverage/rangeOfDates/beginDate/time|./temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale|./temporalCoverage/rangeOfDates/endDate/time|./temporalCoverage/rangeOfDates/endDate/alternativeTimeScale|./taxonomicCoverage|./geographicCoverage/datasetGPolygon|./geographicCoverage/boundingCoordinates/boundingAltitudes", "temporalCoverage/rangeOfDates/beginDate/time, /temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale, /temporalCoverage/rangeOfDates/endDate/time, /temporalCoverage/rangeOfDates/endDate/alternativeTimeScale, /taxonomicCoverage, /geographicCoverage/datasetGPolygon, /geographicCoverage/boundingCoordinates/boundingAltitudes");
1685
        foreach $node ($results->get_nodelist) {
1686
            dontOccur($node, "./temporalCoverage/rangeOfDates/beginDate/time|./temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale|./temporalCoverage/rangeOfDates/endDate/time|./temporalCoverage/rangeOfDates/endDate/alternativeTimeScale|./taxonomicCoverage|./geographicCoverage/datasetGPolygon|./geographicCoverage/boundingCoordinates/boundingAltitudes", "temporalCoverage/rangeOfDates/beginDate/time, /temporalCoverage/rangeOfDates/beginDate/alternativeTimeScale, /temporalCoverage/rangeOfDates/endDate/time, /temporalCoverage/rangeOfDates/endDate/alternativeTimeScale, /taxonomicCoverage, /geographicCoverage/datasetGPolygon, /geographicCoverage/boundingCoordinates/boundingAltitudes");
1679 1687

  
1680
	    $tempResult = $node->findnodes('./temporalCoverage');
1681
	    if($tempResult->size > 1){
1682
	       	errMoreThanOne("temporalCoverage");
1683
	    }else{
1684
		foreach $tempNode ($tempResult->get_nodelist){
1685
		    my $x;
1686
		    my $y;
1687
		    my $z;
1688
		    my $tempdate = findValue($tempNode, "rangeOfDates/beginDate/calendarDate");
1689
		    ($x, $y, $z) = split("-", $tempdate); 
1690
		    $$templateVars{'beginningYear'} = $x;
1691
		    $$templateVars{'beginningMonth'} = $y;
1692
		    $$templateVars{'beginningDay'} = $z;
1688
            $tempResult = $node->findnodes('./temporalCoverage');
1689
            if ($tempResult->size > 1) {
1690
                   errMoreThanOne("temporalCoverage");
1691
            } else {
1692
                foreach $tempNode ($tempResult->get_nodelist) {
1693
                    my $x;
1694
                    my $y;
1695
                    my $z;
1696
                    my $tempdate = findValue($tempNode, "rangeOfDates/beginDate/calendarDate");
1697
                    ($x, $y, $z) = split("-", $tempdate); 
1698
                    $$templateVars{'beginningYear'} = $x;
1699
                    $$templateVars{'beginningMonth'} = $y;
1700
                    $$templateVars{'beginningDay'} = $z;
1701
    
1702
                    $tempdate = findValue($tempNode, "rangeOfDates/endDate/calendarDate");
1703
                    ($x, $y, $z) = split("-", $tempdate);
1704
                    $$templateVars{'endingYear'} = $x;
1705
                    $$templateVars{'endingMonth'} = $y;
1706
                    $$templateVars{'endingDay'} = $z;
1707
                
1708
                    $tempdate = "";
1709
                    $tempdate = findValue($tempNode, "singleDateTime/calendarDate");
1710
                    if($tempdate ne ""){
1711
                        ($x, $y, $z) = split("-", $tempdate);
1712
                        $$templateVars{'beginningYear'} = $x;
1713
                        $$templateVars{'beginningMonth'} = $y;
1714
                        $$templateVars{'beginningDay'} = $z;
1715
                    }  
1716
                }
1717
            }
1693 1718

  
1694
		    $tempdate = findValue($tempNode, "rangeOfDates/endDate/calendarDate");
1695
		    ($x, $y, $z) = split("-", $tempdate);
1696
		    $$templateVars{'endingYear'} = $x;
1697
		    $$templateVars{'endingMonth'} = $y;
1698
		    $$templateVars{'endingDay'} = $z;
1699
		    
1700
		    $tempdate = "";
1701
		    $tempdate = findValue($tempNode, "singleDateTime/calendarDate");
1702
		    if($tempdate ne ""){
1703
			($x, $y, $z) = split("-", $tempdate);
1704
			$$templateVars{'beginningYear'} = $x;
1705
			$$templateVars{'beginningMonth'} = $y;
1706
			$$templateVars{'beginningDay'} = $z;
1707
		    }  
1708
		}
1709
	    }
1710

  
1711
	    $tempResult = $node->findnodes('./geographicCoverage');
1712
	    if($tempResult->size > 1){
1713
		errMoreThanOne("geographicCoverage");
1714
	    }else{
1715
		foreach $tempNode ($tempResult->get_nodelist){
1716

  
1717
		    my $coord;
1718

  
1719
		    $coord = findValue($tempNode, "boundingCoordinates/westBoundingCoordinate");
1720
		    if($coord > 0){
1721
			#print "+";
1722
			$$templateVars{'hemisphLong1'} = "E";
1723
		    } else {
1724
			#print "-";
1725
			eval($coord = $coord * -1);
1726
			$$templateVars{'hemisphLong1'} = "W";
1727
		    }
1728
		    eval($$templateVars{'longDeg1'} = int($coord));
1729
		    eval($coord = ($coord - int($coord))*60);
1730
		    eval($$templateVars{'longMin1'} = int($coord));
1731
		    eval($coord = ($coord - int($coord))*60);
1732
		    eval($$templateVars{'longSec1'} = int($coord));
1733
		    
1734

  
1735
		    $coord = findValue($tempNode, "boundingCoordinates/southBoundingCoordinate");
1736
		    if($coord > 0){
1737
			#print "+";
1738
			$$templateVars{'hemisphLat2'} = "N";
1739
		    } else {
1740
			#print "-";
1741
			eval($coord = $coord * -1);
1742
			$$templateVars{'hemisphLat2'} = "S";
1743
		    }
1744
		    eval($$templateVars{'latDeg2'} = int($coord));
1745
		    eval($coord = ($coord - int($coord))*60);
1746
		    eval($$templateVars{'latMin2'} = int($coord));
1747
		    eval($coord = ($coord - int($coord))*60);
1748
		    eval($$templateVars{'latSec2'} = int($coord));
1749

  
1750

  
1751
		    $coord = findValue($tempNode, "boundingCoordinates/northBoundingCoordinate");
1752
		    if($coord > 0){
1753
			#print "+";
1754
			$$templateVars{'hemisphLat1'} = "N";
1755
		    } else {
1756
			#print "-";
1757
			eval($coord = $coord * -1);
1758
			$$templateVars{'hemisphLat1'} = "S";
1759
		    }
1760
		    eval($$templateVars{'latDeg1'} = int($coord));
1761
		    eval($coord = ($coord - int($coord))*60);
1762
		    eval($$templateVars{'latMin1'} = int($coord));
1763
		    eval($coord = ($coord - int($coord))*60);
1764
		    eval($$templateVars{'latSec1'} = int($coord));
1765

  
1766

  
1767
		    $coord = findValue($tempNode, "boundingCoordinates/eastBoundingCoordinate");
1768
		    if($coord > 0){
1769
			#print "+";
1770
			$$templateVars{'hemisphLong2'} = "E";
1771
		    } else {
1772
			#print "-";
1773
			eval($coord = $coord * -1);
1774
			$$templateVars{'hemisphLong2'} = "W";
1775
		    }
1776
		    eval($$templateVars{'longDeg2'} = int($coord));
1777
		    eval($coord = ($coord - int($coord))*60);
1778
		    eval($$templateVars{'longMin2'} = int($coord));
1779
		    eval($coord = ($coord - int($coord))*60);
1780
		    eval($$templateVars{'longSec2'} = int($coord));
1781
		}
1782
	    }
1783
	}
1719
            $tempResult = $node->findnodes('./geographicCoverage');
1720
            if ($tempResult->size > 1) {
1721
                errMoreThanOne("geographicCoverage");
1722
            } else {
1723
                foreach $tempNode ($tempResult->get_nodelist) {
1724
                    my $coord;
1725
                    $coord = findValue($tempNode, "boundingCoordinates/westBoundingCoordinate");
1726
                    if ($coord > 0) {
1727
                        #print "+";
1728
                        $$templateVars{'hemisphLong1'} = "E";
1729
                    } else {
1730
                        #print "-";
1731
                        eval($coord = $coord * -1);
1732
                        $$templateVars{'hemisphLong1'} = "W";
1733
                    }
1734
                    eval($$templateVars{'longDeg1'} = int($coord));
1735
                    eval($coord = ($coord - int($coord))*60);
1736
                    eval($$templateVars{'longMin1'} = int($coord));
1737
                    eval($coord = ($coord - int($coord))*60);
1738
                    eval($$templateVars{'longSec1'} = int($coord));
1739
                    
1740
                    $coord = findValue($tempNode, "boundingCoordinates/southBoundingCoordinate");
1741
                    if ($coord > 0) {
1742
                        #print "+";
1743
                        $$templateVars{'hemisphLat2'} = "N";
1744
                    } else {
1745
                        #print "-";
1746
                        eval($coord = $coord * -1);
1747
                        $$templateVars{'hemisphLat2'} = "S";
1748
                    }
1749
                    eval($$templateVars{'latDeg2'} = int($coord));
1750
                    eval($coord = ($coord - int($coord))*60);
1751
                    eval($$templateVars{'latMin2'} = int($coord));
1752
                    eval($coord = ($coord - int($coord))*60);
1753
                    eval($$templateVars{'latSec2'} = int($coord));
1754
        
1755
                    $coord = findValue($tempNode, "boundingCoordinates/northBoundingCoordinate");
1756
                    if ($coord > 0) {
1757
                        #print "+";
1758
                        $$templateVars{'hemisphLat1'} = "N";
1759
                    } else {
1760
                        #print "-";
1761
                        eval($coord = $coord * -1);
1762
                        $$templateVars{'hemisphLat1'} = "S";
1763
                    }
1764
                    eval($$templateVars{'latDeg1'} = int($coord));
1765
                    eval($coord = ($coord - int($coord))*60);
1766
                    eval($$templateVars{'latMin1'} = int($coord));
1767
                    eval($coord = ($coord - int($coord))*60);
1768
                    eval($$templateVars{'latSec1'} = int($coord));
1769
        
1770
                    $coord = findValue($tempNode, "boundingCoordinates/eastBoundingCoordinate");
1771
                    if ($coord > 0) {
1772
                        #print "+";
1773
                        $$templateVars{'hemisphLong2'} = "E";
1774
                    } else {
1775
                        #print "-";
1776
                        eval($coord = $coord * -1);
1777
                        $$templateVars{'hemisphLong2'} = "W";
1778
                    }
1779
                    eval($$templateVars{'longDeg2'} = int($coord));
1780
                    eval($coord = ($coord - int($coord))*60);
1781
                    eval($$templateVars{'longMin2'} = int($coord));
1782
                    eval($coord = ($coord - int($coord))*60);
1783
                    eval($$templateVars{'longSec2'} = int($coord));
1784
                }
1785
            }
1786
        }
1784 1787
    }
1785

  
1786 1788
    dontOccur($doc, "./purpose", "purpose");
1787 1789
    dontOccur($doc, "./maintenance", "maintnance");
1788 1790

  
1789

  
1790 1791
    $results = $doc->findnodes('//dataset/contact/individualName');
1791
    if($results->size() > 1){
1792
	errMoreThanOne("contact/individualName");
1792
    if ($results->size() > 1) {
1793
        errMoreThanOne("contact/individualName");
1793 1794
    } else {
1794
	foreach $node ($results->get_nodelist){
1795
	    dontOccur($node, "../positionName|../onlineURL|../userId", 
1796
		      "positionName, onlineURL, userId in contact tag");
1797
	    
1798
	    dontOccur($node, "./saluation", "saluation in contact tag");			    
1799
	    
1800
	    $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1801
	    if($tempResult->size > 0){
1802
		
1803
		$$templateVars{'origNamefirstContact'} = findValue($node, 'givenName');
1804
		$$templateVars{'origNamelastContact'} = findValue($node, 'surName');
1805
	
1806
		my $tempResult2 = $node->findnodes('../address');
1807
		if($tempResult2->size > 1){
1808
		    errMoreThanOne("address");
1809
		} else {
1810
		    foreach my $tempNode2 ($tempResult2->get_nodelist){
1811
			$$templateVars{'origDeliveryContact'} = findValue($tempNode2, 'deliveryPoint');
1812
			$$templateVars{'origCityContact'} = findValue($tempNode2, 'city');
1813
			$$templateVars{'origStateContact'} = findValue($tempNode2, 'administrativeArea');
1814
			$$templateVars{'origZIPContact'} = findValue($tempNode2, 'postalCode');
1815
			$$templateVars{'origCountryContact'} = findValue($tempNode2, 'country');
1816
		    }
1817
		}
1818
		
1819
		my $tempResult3 = $node->findnodes('../phone');
1820
		if($tempResult3->size > 2){
1821
		    errMoreThanN("phone");
1822
		} else {
1823
		    foreach my $tempNode2 ($tempResult3->get_nodelist){
1824
			if($tempNode2->hasAttributes()){
1825
			    my @attlist = $tempNode2->attributes();
1826
			    if($attlist[0]->value eq "Fax"){
1827
				$$templateVars{'origFAXContact'} = $tempNode2->textContent();
1828
			    } else {
1829
				$$templateVars{'origPhoneContact'} = $tempNode2->textContent();
1830
			    }
1831
			}else{
1832
			    $$templateVars{'origPhoneContact'} = $tempNode2->textContent();
1833
			}
1834
		    }
1835
		}
1836
		$$templateVars{'origEmailContact'} = findValue($node, '../electronicMailAddress');
1837
		$$templateVars{'origNameOrgContact'} = findValue($node, '../organizationName');
1838
	    } else {
1839
		$$templateVars{'origNamefirstContact'} = findValue($node, 'givenName');
1840
		$$templateVars{'origNamelastContact'} = findValue($node, 'surName');
1841
		$$templateVars{'origNameOrgContact'} = findValue($node, '../organizationName');
1842
	    }
1843
	}
1795
        foreach $node ($results->get_nodelist) {
1796
            dontOccur($node, "../positionName|../onlineURL|../userId", 
1797
              "positionName, onlineURL, userId in contact tag");
1798
            dontOccur($node, "./saluation", "saluation in contact tag");                
1799
        
1800
            $tempResult = $node->findnodes('../address|../phone|../electronicmailAddress|../organizationName');
1801
            if ($tempResult->size > 0) {
1802
                $$templateVars{'origNamefirstContact'} = findValue($node, 'givenName');
1803
                $$templateVars{'origNamelastContact'} = findValue($node, 'surName');
1804
    
1805
                my $tempResult2 = $node->findnodes('../address');
1806
                if ($tempResult2->size > 1) {
1807
                    errMoreThanOne("address");
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff