Project

General

Profile

« Previous | Next » 

Revision 4577

Added by walbridge about 16 years ago

CODE FORMATTING ONLY: Fix all the inconsistencies I found within the script to follow the standards used within 80% of the code: No tabs, 'if (eval) {' operator spacing, four spaces indentation, replace exit(0) with exit().

View differences:

register-dataset.cgi
54 54
unless (open (METACAT_PROPERTIES, $metacatProps)) {
55 55
    print "Content-type: text/html\n\n";
56 56
    print "Unable to locate Metacat properties. Working directory is set as '$workingDirectory', is this correct?";
57
    exit(0);
57
    exit();
58 58
}
59 59

  
60 60
$properties->load(*METACAT_PROPERTIES);
......
116 116
    unless (open (SKIN_PROPERTIES, $skinProps)) {
117 117
        print "Content-type: text/html\n\n";
118 118
        print "Unable to locate skin properties at $skinProps.  Is this path correct?";
119
        exit(0);
119
        exit();
120 120
    }
121 121
    $skinProperties->load(*SKIN_PROPERTIES);
122 122
}
......
147 147
my %siteLatDMS;
148 148
my %siteLongDMS;
149 149

  
150
while ( my ($key, $value) = each (%$spatial)) {
150
while (my ($key, $value) = each (%$spatial)) {
151 151
    my ($name, $lon, $lat) = split(/\|/, $value);
152 152
    my ($latd, $latm, $lats, $latdir) = split(/\|/, $lat);
153 153
    my ($lond, $lonm, $lons, $londir) = split(/\|/, $lon);
......
192 192
    # Send back the login form.....
193 193
    my $session = CGI::Session->load() or die CGI::Session->errstr();
194 194

  
195
    if($FORM::submission eq 'true'){
196
    	$$templateVars{'message'} = 'You must login to view your submissions.';
197
    }	
195
    if ($FORM::submission eq 'true') {
196
        $$templateVars{'message'} = 'You must login to view your submissions.';
197
    }
198 198

  
199
    if ( $session->is_empty ) {
200
	# no session found ... redirect to login page template
201
        $template->process( $templates->{'login'}, $templateVars);
199
    if ($session->is_empty) {
200
    # no session found ... redirect to login page template
201
        $template->process($templates->{'login'}, $templateVars);
202 202
    } else {
203
	# session found ... delete the session....
204
	$session->delete();
205
	$template->process( $templates->{'login'}, $templateVars);
203
        # session found ... delete the session....
204
        $session->delete();
205
        $template->process($templates->{'login'}, $templateVars);
206 206
    }
207
	exit(0);
207
    exit();
208 208
} elsif ($FORM::stage =~ "logout") {
209
	handleLogoutRequest();
210
  	exit(0);
209
    handleLogoutRequest();
210
    exit();
211 211
} elsif ($FORM::stage =~ "login") {
212
	handleLoginRequest();
213
  	exit(0);
212
    handleLoginRequest();
213
    exit();
214 214
} elsif ($FORM::stage =~ "mod_accept") {
215
	handleModAccept();
216
  	exit(0);
215
    handleModAccept();
216
    exit();
217 217
} elsif ($FORM::stage =~ "mod_decline") {
218
	handleModDecline();
219
  	exit(0);
218
    handleModDecline();
219
    exit();
220 220
} elsif ($FORM::stage =~ "mod_revise") {
221
	handleModRevise();
222
  	exit(0);
221
    handleModRevise();
222
    exit();
223 223
} elsif ($FORM::stage =~ "read") {
224
	handleRead();
225
	exit(0);
226
} elsif ($FORM::stage =~ "review_frame"){
227
 	handleReviewFrame();	
228
	exit(0);
229
} 
224
    handleRead();
225
    exit();
226
} elsif ($FORM::stage =~ "review_frame") {
227
    handleReviewFrame();
228
    exit();
229
}
230 230

  
231 231
print "Content-type: text/html\n\n";
232 232

  
233 233
if ($FORM::stage =~ "guide") {
234 234
    # Send back the information on how to fill the form
235 235
    $$templateVars{'section'} = "Guide on How to Complete Registry Entries";
236
    $template->process( $template->{'guide'}, $templateVars);
237
    exit(0);
236
    $template->process($template->{'guide'}, $templateVars);
237
    exit();
238 238

  
239 239
} elsif ($FORM::stage =~ "insert") {
240 240
    # The user has entered the data. Do data validation and send back data 
241 241
    # to confirm the data that has been entered. 
242 242
    toConfirmData();
243
    exit(0);
243
    exit();
244 244

  
245
}elsif ($FORM::dataWrong =~ "No, go back to editing" && $FORM::stage =~ "confirmed") {
245
} elsif ($FORM::dataWrong =~ "No, go back to editing" && $FORM::stage =~ "confirmed") {
246 246
    # The user wants to correct the data that he has entered. 
247 247
    # Hence show the data again in entryData form. 
248 248
    confirmDataToReEntryData();
249
    exit(0);
249
    exit();
250 250

  
251
}elsif ($FORM::stage =~ "modify") {
251
} elsif ($FORM::stage =~ "modify") {
252 252
    # Modification of a file has been requested. 
253 253
    # check if the user is logged in...
254 254
    my $session = CGI::Session->load() or die CGI::Session->errstr();
255
    if ( $session->is_empty ) {
255
    if ($session->is_empty) {
256 256
        # no session found ... redirect to login page template
257
    	$$templateVars{'message'} = 'You must login to modify your dataset.';
258
        $template->process( $templates->{'login'}, $templateVars);
257
        $$templateVars{'message'} = 'You must login to modify your dataset.';
258
        $template->process($templates->{'login'}, $templateVars);
259 259
    } else {
260
    	# Show the form will all the values filled in.
261
    	my @sortedSites;
262
    	foreach my $site (sort @sitelist) {
263
        	push(@sortedSites, $site);
264
    	}
265
    	$$templateVars{'siteList'} = \@sortedSites;
266
    	$$templateVars{'section'} = "Modification Form";
267
    	$$templateVars{'docid'} = $FORM::docid;
268
    	modifyData();
260
        # Show the form will all the values filled in.
261
        my @sortedSites;
262
        foreach my $site (sort @sitelist) {
263
            push(@sortedSites, $site);
264
        }
265
        $$templateVars{'siteList'} = \@sortedSites;
266
        $$templateVars{'section'} = "Modification Form";
267
        $$templateVars{'docid'} = $FORM::docid;
268
        modifyData();
269 269
    }
270
    exit(0);
270
    exit();
271 271

  
272
}elsif ($FORM::stage =~ "delete_confirm") {
272
} elsif ($FORM::stage =~ "delete_confirm") {
273 273

  
274 274
    # Result from deleteData form. 
275
    if($FORM::deleteData =~ "Delete document"){
276
    # delete Data
277
    deleteData(1);    
278
    exit(0);
275
    if ($FORM::deleteData =~ "Delete document") {
276
        # delete Data
277
        deleteData(1);
278
        exit();
279 279
    } else {
280
    $$templateVars{'status'} = "Cancel";
281
    $$templateVars{'function'} = "cancel";
282
    $template->process( $templates->{'response'}, $templateVars);
283
    exit(0);
280
        $$templateVars{'status'} = "Cancel";
281
        $$templateVars{'function'} = "cancel";
282
        $template->process($templates->{'response'}, $templateVars);
283
        exit();
284 284
    }
285 285

  
286
}elsif ($FORM::stage =~ "delete") {
286
} elsif ($FORM::stage =~ "delete") {
287 287
    # Deletion of a file has been requested. 
288 288
    # Ask for username and password using deleteDataForm
289 289
    $$templateVars{'docid'} = $FORM::docid;
290
    $template->process( $templates->{'deleteData'}, $templateVars);
291
    exit(0);
290
    $template->process($templates->{'deleteData'}, $templateVars);
291
    exit();
292 292

  
293
}elsif ($FORM::stage !~ "confirmed") {
293
} elsif ($FORM::stage !~ "confirmed") {
294 294
    # None of the stages have been reached and data is not being confirmed. 
295
    
295

  
296 296
    # check if the user is logged in...
297 297
    my $session = CGI::Session->load() or die CGI::Session->errstr();
298
    if ( $session->is_empty ) {
298
    if ($session->is_empty) {
299 299
        # no session found ... redirect to login page template
300 300
        $$templateVars{'showInstructions'} = 'true';
301 301
        $$templateVars{'message'} = 'You must login to register your dataset.';
302 302
        debug($templates->{'login'});
303
        $template->process( $templates->{'login'}, $templateVars);
303
        $template->process($templates->{'login'}, $templateVars);
304 304
    } else {
305 305

  
306
    	# Hence, send back entry form for entry of data.  
307
    	debug("Registry: Sending form");
308
    	my @sortedSites;
309
    	foreach my $site (sort @sitelist) {
310
        	push(@sortedSites, $site);
311
    	}
306
        # Hence, send back entry form for entry of data.  
307
        debug("Registry: Sending form");
308
        my @sortedSites;
309
        foreach my $site (sort @sitelist) {
310
            push(@sortedSites, $site);
311
        }
312 312

  
313
    	if ($skinName eq 'nceas') {
314
        	my $projects = getProjectList($properties);
315
        	$$templateVars{'projects'} = $projects;
316
        	$$templateVars{'wg'} = \@FORM::wg;
317
    	}
318
        
313
        if ($skinName eq 'nceas') {
314
            my $projects = getProjectList($properties);
315
            $$templateVars{'projects'} = $projects;
316
            $$templateVars{'wg'} = \@FORM::wg;
317
        }
318

  
319 319
        $$templateVars{'modules'} = $modules;
320 320
        $$templateVars{'required'} = $required;
321 321
        $$templateVars{'templates'} = $templates;
......
326 326
        $$templateVars{'section'} = "Entry Form";
327 327
        $$templateVars{'docid'} = "";
328 328
        debug("Registry: Sending form: ready to process template");
329
        $template->process( $templates->{'entry'}, $templateVars);
329
        $template->process($templates->{'entry'}, $templateVars);
330 330
        debug("Registry: Sending form: template processed");
331 331
   }
332
   exit(0);
332
   exit();
333 333
}
334 334

  
335 335
# Confirm stage has been reached. Enter the data into metacat. 
......
393 393
        $$templateVars{'cfg'} = $skinName;
394 394
        $$templateVars{'function'} = "submitted";
395 395
        $$templateVars{'section'} = "Submission Status";
396
        $template->process( $templates->{'response'}, $templateVars);
397
        exit(0);
396
        $template->process($templates->{'response'}, $templateVars);
397
        exit();
398 398
    } else {
399 399

  
400
    if($config->{'adminIsDocOwner'} eq 'true'){
400
    if ($config->{'adminIsDocOwner'} eq 'true') {
401 401
        debug("Registry: adminIsDocOwner is set.");
402 402
        $response = $metacat->login($username, $password);
403 403
        if (! $response) {
......
409 409
            $$templateVars{'cfg'} = $skinName;
410 410
            $$templateVars{'function'} = "submitted";
411 411
            $$templateVars{'section'} = "Submission Status";
412
            $template->process( $templates->{'response'}, $templateVars);
413
            exit(0);
412
            $template->process($templates->{'response'}, $templateVars);
413
            exit();
414 414
        }
415 415
    }
416 416

  
417
        debug( "Registry: A");
417
        debug("Registry: A");
418 418
        if ($FORM::docid eq "") {
419
            debug( "Registry: B1");
419
            debug("Registry: B1");
420 420
            # document is being inserted 
421 421
            my $docStatus = "INCOMPLETE";
422 422
            while ($docStatus eq "INCOMPLETE") {
......
472 472
            # Create our HTML response and send it back
473 473
            $$templateVars{'function'} = "modified";
474 474
            $$templateVars{'section'} = "Modification Status";
475
            $template->process( $templates->{'response'}, $templateVars);
475
            $template->process($templates->{'response'}, $templateVars);
476 476

  
477
            exit(0);
477
            exit();
478 478
        }
479 479
    }
480 480
}
......
505 505
$$templateVars{'function'} = "submitted";
506 506
$$templateVars{'section'} = "Submission Status";
507 507

  
508
$template->process( $templates->{'response'}, $templateVars);
508
$template->process($templates->{'response'}, $templateVars);
509 509

  
510
exit(0);
510
exit();
511 511

  
512 512
################################################################################
513 513
#
......
590 590
        unless hasContent($FORM::origNamelast0);
591 591
    push(@invalidParams, "Dataset abstract is missing.")
592 592
        unless hasContent($FORM::abstract);
593
    if($modules->{'temporal'} eq 'true'){
594
	push(@invalidParams, "Year of start date is missing.")
595
	    unless (hasContent($FORM::beginningYear) || $required->{'temporal'} ne 'true');
596
	push(@invalidParams, "Year of stop date has been specified but year of start date is missing.")
597
	    if ((!hasContent($FORM::beginningYear)) && hasContent($FORM::endingYear));
593
    if ($modules->{'temporal'} eq 'true') {
594
        push(@invalidParams, "Year of start date is missing.")
595
            unless (hasContent($FORM::beginningYear) || $required->{'temporal'} ne 'true');
596
        push(@invalidParams, "Year of stop date has been specified but year of start date is missing.")
597
            if ((!hasContent($FORM::beginningYear)) && hasContent($FORM::endingYear));
598 598
    }
599 599
    push(@invalidParams, "Geographic description is missing.")
600 600
        unless (hasContent($FORM::geogdesc) || $required->{'spatial'} ne 'true');
601 601

  
602
    if($FORM::beginningMonth eq "MM"){
603
	#if (hasContent($FORM::beginningYear)){
604
	#    $FORM::beginningMonth = "01";
605
	#} else {
606
	    $FORM::beginningMonth = "";
607
	#}
602
    if ($FORM::beginningMonth eq "MM") {
603
        $FORM::beginningMonth = "";
608 604
    }
609
    if($FORM::beginningDay eq "DD"){
610
	#if (hasContent($FORM::beginningYear)){
611
	#    $FORM::beginningDay = "01";
612
	#} else {
613
	    $FORM::beginningDay = "";
614
	#}
605
    if ($FORM::beginningDay eq "DD") {
606
        $FORM::beginningDay = "";
615 607
    }
616
    if($FORM::endingMonth eq "MM"){
617
	#if (hasContent($FORM::endingYear)){
618
	#    $FORM::endingMonth = "01";
619
	#} else {
620
	    $FORM::endingMonth = "";
621
	#}
622
    }    
623
    if($FORM::endingDay eq "DD"){
624
	#if (hasContent($FORM::endingYear)){
625
	#    $FORM::endingDay = "01";
626
	#} else {
627
	    $FORM::endingDay = "";
628
	#}
608
    if ($FORM::endingMonth eq "MM") {
609
        $FORM::endingMonth = "";
629 610
    }
611
    if ($FORM::endingDay eq "DD") {
612
        $FORM::endingDay = "";
613
    }
630 614

  
631
    if (hasContent($FORM::beginningYear) && !($FORM::beginningYear =~ /[0-9]{4}/)){
632
	push(@invalidParams, "Invalid year of start date specified.")
615
    if (hasContent($FORM::beginningYear) && !($FORM::beginningYear =~ /[0-9]{4}/)) {
616
        push(@invalidParams, "Invalid year of start date specified.")
633 617
    }
634 618

  
635
    if (hasContent($FORM::endingYear) && !($FORM::endingYear =~ /[0-9]{4}/)){
636
	push(@invalidParams, "Invalid year of stop date specified.")
619
    if (hasContent($FORM::endingYear) && !($FORM::endingYear =~ /[0-9]{4}/)) {
620
        push(@invalidParams, "Invalid year of stop date specified.")
637 621
    }
638
    
622

  
639 623
    # If the "use site" coord. box is checked and if the site is in 
640 624
    # the longitude hash ...  && ($siteLatDMS{$FORM::site})
641
    
642
    if($modules->{'spatial'} eq 'true'){
643
	if (($FORM::useSiteCoord) && ($siteLatDMS{$FORM::site}) ) {
644
        
645
	    $latDeg1 = $siteLatDMS{$FORM::site}[0];
646
	    $latMin1 = $siteLatDMS{$FORM::site}[1];
647
	    $latSec1 = $siteLatDMS{$FORM::site}[2];
648
	    $hemisphLat1 = $siteLatDMS{$FORM::site}[3];
649
	    $longDeg1 = $siteLongDMS{$FORM::site}[0];
650
	    $longMin1 = $siteLongDMS{$FORM::site}[1];
651
	    $longSec1 = $siteLongDMS{$FORM::site}[2];
652
	    $hemisphLong1 = $siteLongDMS{$FORM::site}[3];
653
	    
654
	}  else {
655
	    
656
	    $latDeg1 = $FORM::latDeg1;
657
	    $latMin1 = $FORM::latMin1;
658
	    $latSec1 = $FORM::latSec1;
659
	    $hemisphLat1 = $FORM::hemisphLat1;
660
	    $longDeg1 = $FORM::longDeg1;
661
	    $longMin1 = $FORM::longMin1;
662
	    $longSec1 = $FORM::longSec1;
663
	    $hemisphLong1 = $FORM::hemisphLong1;
664
	}
665 625

  
666
	if($latDeg1 > 90 || $latDeg1 < 0){
667
	    push(@invalidParams, "Invalid first latitude degrees specified.");
668
	}
669
	if($latMin1 > 59 || $latMin1 < 0){
670
	    push(@invalidParams, "Invalid first latitude minutes specified.");
671
	}
672
	if($latSec1 > 59 || $latSec1 < 0){
673
	    push(@invalidParams, "Invalid first latitude seconds specified.");
674
	}
675
	if($longDeg1 > 180 || $longDeg1 < 0){
676
	    push(@invalidParams, "Invalid first longitude degrees specified.");
677
	}
678
	if($longMin1 > 59 || $longMin1 < 0){
679
	    push(@invalidParams, "Invalid first longitude minutes specified.");
680
	}
681
	if($longSec1 > 59 || $longSec1 < 0){
682
	    push(@invalidParams, "Invalid first longitude seconds specified.");
683
	}
626
    if ($modules->{'spatial'} eq 'true') {
627
        if (($FORM::useSiteCoord) && ($siteLatDMS{$FORM::site})) {
628
            $latDeg1 = $siteLatDMS{$FORM::site}[0];
629
            $latMin1 = $siteLatDMS{$FORM::site}[1];
630
            $latSec1 = $siteLatDMS{$FORM::site}[2];
631
            $hemisphLat1 = $siteLatDMS{$FORM::site}[3];
632
            $longDeg1 = $siteLongDMS{$FORM::site}[0];
633
            $longMin1 = $siteLongDMS{$FORM::site}[1];
634
            $longSec1 = $siteLongDMS{$FORM::site}[2];
635
            $hemisphLong1 = $siteLongDMS{$FORM::site}[3];
636
        }  else {
637
            $latDeg1 = $FORM::latDeg1;
638
            $latMin1 = $FORM::latMin1;
639
            $latSec1 = $FORM::latSec1;
640
            $hemisphLat1 = $FORM::hemisphLat1;
641
            $longDeg1 = $FORM::longDeg1;
642
            $longMin1 = $FORM::longMin1;
643
            $longSec1 = $FORM::longSec1;
644
            $hemisphLong1 = $FORM::hemisphLong1;
645
        }
684 646

  
685
	if(hasContent($FORM::latDeg2) && ($FORM::latDeg2 > 90 || $FORM::latDeg2 < 0)){
686
	    push(@invalidParams, "Invalid second latitude degrees specified.");
687
	}
688
	if(hasContent($FORM::latMin2) && ($FORM::latMin2 > 59 || $FORM::latMin2 < 0)){
689
	    push(@invalidParams, "Invalid second latitude minutes specified.");
690
	}
691
	if(hasContent($FORM::latSec2) && ($FORM::latSec2 > 59 || $FORM::latSec2 < 0)){
692
	    push(@invalidParams, "Invalid second latitude seconds specified.");
693
	}
694
	if(hasContent($FORM::latDeg2) && ($FORM::longDeg2 > 180 || $FORM::longDeg2 < 0)){
695
	    push(@invalidParams, "Invalid second longitude degrees specified.");
696
	}
697
	if(hasContent($FORM::latMin2) && ($FORM::longMin2 > 59 || $FORM::longMin2 < 0)){
698
	    push(@invalidParams, "Invalid second longitude minutes specified.");
699
	}
700
	if(hasContent($FORM::latSec2) && ($FORM::longSec2 > 59 || $FORM::longSec2 < 0)){
701
	    push(@invalidParams, "Invalid second longitude seconds specified.");
702
	}
647
        if ($latDeg1 > 90 || $latDeg1 < 0) {
648
            push(@invalidParams, "Invalid first latitude degrees specified.");
649
        }
650
        if ($latMin1 > 59 || $latMin1 < 0) {
651
            push(@invalidParams, "Invalid first latitude minutes specified.");
652
        }
653
        if ($latSec1 > 59 || $latSec1 < 0) {
654
            push(@invalidParams, "Invalid first latitude seconds specified.");
655
        }
656
        if ($longDeg1 > 180 || $longDeg1 < 0) {
657
            push(@invalidParams, "Invalid first longitude degrees specified.");
658
        }
659
        if ($longMin1 > 59 || $longMin1 < 0) {
660
            push(@invalidParams, "Invalid first longitude minutes specified.");
661
        }
662
        if ($longSec1 > 59 || $longSec1 < 0) {
663
            push(@invalidParams, "Invalid first longitude seconds specified.");
664
        }
665

  
666
        if (hasContent($FORM::latDeg2) && ($FORM::latDeg2 > 90 || $FORM::latDeg2 < 0)) {
667
            push(@invalidParams, "Invalid second latitude degrees specified.");
668
        }
669
        if (hasContent($FORM::latMin2) && ($FORM::latMin2 > 59 || $FORM::latMin2 < 0)) {
670
            push(@invalidParams, "Invalid second latitude minutes specified.");
671
        }
672
        if (hasContent($FORM::latSec2) && ($FORM::latSec2 > 59 || $FORM::latSec2 < 0)) {
673
            push(@invalidParams, "Invalid second latitude seconds specified.");
674
        }
675
        if (hasContent($FORM::latDeg2) && ($FORM::longDeg2 > 180 || $FORM::longDeg2 < 0)) {
676
            push(@invalidParams, "Invalid second longitude degrees specified.");
677
        }
678
        if (hasContent($FORM::latMin2) && ($FORM::longMin2 > 59 || $FORM::longMin2 < 0)) {
679
            push(@invalidParams, "Invalid second longitude minutes specified.");
680
        }
681
        if (hasContent($FORM::latSec2) && ($FORM::longSec2 > 59 || $FORM::longSec2 < 0)) {
682
            push(@invalidParams, "Invalid second longitude seconds specified.");
683
        }
703 684
    }
704
    
685

  
705 686
    # Check if latDeg1 and longDeg1 has values if useSiteCoord is used. 
706 687
    # This check is required because some of the sites dont have lat 
707 688
    # and long mentioned in the config file. 
708 689

  
709 690

  
710
    if($modules->{'spatial'} eq 'true' && $required->{'spatial'} eq 'true'){
711
	if ($FORM::useSiteCoord ) {
712
	    push(@invalidParams, "The Data Registry doesn't have latitude and longitude information for the site that you chose. Please go back and enter the spatial information.")
713
		unless(hasContent($latDeg1) && hasContent($longDeg1));
714
	}else{
715
	    push(@invalidParams, "Latitude degrees are missing.")
716
		unless (hasContent($latDeg1) || $required->{'spatial'} ne 'true');
717
	    push(@invalidParams, "Longitude degrees are missing.")
718
		unless (hasContent($longDeg1) || $required->{'spatial'} ne 'true');
719
	}
720
	push(@invalidParams, 
721
	     "You must provide a geographic description if you provide latitude and longitude information.")
722
	    if ((hasContent($latDeg1) || (hasContent($longDeg1))) && (!hasContent($FORM::geogdesc)));
691
    if ($modules->{'spatial'} eq 'true' && $required->{'spatial'} eq 'true') {
692
        if ($FORM::useSiteCoord) {
693
            push(@invalidParams, "The Data Registry doesn't have latitude and longitude information for the site that you chose. Please go back and enter the spatial information.")
694
                unless(hasContent($latDeg1) && hasContent($longDeg1));
695
        } else {
696
            push(@invalidParams, "Latitude degrees are missing.")
697
                unless (hasContent($latDeg1) || $required->{'spatial'} ne 'true');
698
            push(@invalidParams, "Longitude degrees are missing.")
699
                unless (hasContent($longDeg1) || $required->{'spatial'} ne 'true');
700
        }
701
        push(@invalidParams, 
702
            "You must provide a geographic description if you provide latitude and longitude information.")
703
            if ((hasContent($latDeg1) || (hasContent($longDeg1))) && (!hasContent($FORM::geogdesc)));
723 704
    }
724 705

  
725
    if($modules->{'method'} eq 'true'){
726
	push(@invalidParams, 
727
	     "You must provide a method description if you provide a method title.")
728
	    if (hasContent($FORM::methodTitle) && ( !(scalar(@FORM::methodPara) > 0) 
729
						    || (! hasContent($FORM::methodPara[0]))));
730
	push(@invalidParams, 
731
	     "You must provide a method description if you provide an extent of study description.")
732
	    if (hasContent($FORM::studyExtentDescription) && (!(scalar(@FORM::methodPara) > 0) 
733
							      || (! hasContent($FORM::methodPara[0]))));
734
	push(@invalidParams, 
735
	     "You must provide both an extent of study description and a sampling description, or neither.")
736
	    if (
737
                (hasContent($FORM::studyExtentDescription) && !hasContent($FORM::samplingDescription)) ||
738
                (!hasContent($FORM::studyExtentDescription) && hasContent($FORM::samplingDescription))
739
		);
706
    if ($modules->{'method'} eq 'true') {
707
    push (@invalidParams, 
708
        "You must provide a method description if you provide a method title.")
709
        if (hasContent($FORM::methodTitle) && (!(scalar(@FORM::methodPara) > 0) 
710
            || (! hasContent($FORM::methodPara[0]))));
711
    push(@invalidParams, 
712
        "You must provide a method description if you provide an extent of study description.")
713
        if (hasContent($FORM::studyExtentDescription) && (!(scalar(@FORM::methodPara) > 0) 
714
            || (! hasContent($FORM::methodPara[0]))));
715
    push(@invalidParams, 
716
        "You must provide both an extent of study description and a sampling description, or neither.")
717
        if ((hasContent($FORM::studyExtentDescription) && !hasContent($FORM::samplingDescription)) ||
718
            (!hasContent($FORM::studyExtentDescription) && hasContent($FORM::samplingDescription)));
740 719
    }
741 720

  
742 721
    push(@invalidParams, "First name of data set contact is missing.")
......
745 724
    push(@invalidParams, "Last name of data set contact is missing.")
746 725
    unless (hasContent($FORM::origNamelastContact) || 
747 726
        $FORM::useOrigAddress);
748
    if($required->{'contactEmailAddress'} eq 'true'){
749
        if($FORM::useOrigAddress){
750
    		push(@invalidParams, "Email address of data set owner is missing. This is required as it will be used as contact email address as specified by you.")
751
    			unless (hasContent($FORM::origEmail));
752
	} else {
753
    		push(@invalidParams, "Email address of data set contact is missing.")
754
    			unless (hasContent($FORM::origEmailContact));
755
	}
727
    if ($required->{'contactEmailAddress'} eq 'true') {
728
        if ($FORM::useOrigAddress) {
729
        push(@invalidParams, "Email address of data set owner is missing. This is required as it will be used as contact email address as specified by you.")
730
            unless (hasContent($FORM::origEmail));
731
        } else {
732
            push(@invalidParams, "Email address of data set contact is missing.")
733
                unless (hasContent($FORM::origEmailContact));
734
        }
756 735
    }
757
    
758
    # scw: commented these out, don't seem to be matched to cfg setting
759
    #push(@invalidParams, "Data medium is missing.")
760
    #unless (hasContent($FORM::dataMedium) || $FORM::dataMedium =~ /elect/);
761
    #push(@invalidParams, "Usage rights are missing.")
762
    #unless (hasContent($FORM::useConstraints));
763
    
736

  
764 737
    return \@invalidParams;
765 738
}
766 739

  
......
798 771
 
799 772
    my $returnVal = "";
800 773
    
801
    foreach (split(//,$val)){
802
	my $var = unpack "C*", $_; 
803
	
804
	if($var<128 && $var>31){
805
	    $returnVal=$returnVal.$_;
806
	} elsif ($var<32){
807
	    if($var == 10){
808
		$returnVal=$returnVal.$_;
809
	    }
810
	    if($var == 13){
811
		$returnVal=$returnVal.$_;
812
	    }
813
	    if($var == 9){
814
		$returnVal=$returnVal.$_;
815
	    }
816
	} else { 
817
	    #$returnVal=$returnVal."&#".$var.";";
818
	    $returnVal=$returnVal.$_;
819
	}
774
    foreach (split(//,$val)) {
775
        my $var = unpack "C*", $_; 
776

  
777
        if ($var < 128 && $var > 31) {
778
            $returnVal = $returnVal.$_;
779
        } elsif ($var < 32) {
780
            if ($var == 10) {
781
                $returnVal = $returnVal.$_;
782
            }
783
            if ($var == 13) {
784
                $returnVal = $returnVal.$_;
785
            }
786
            if ($var == 9) {
787
                $returnVal = $returnVal.$_;
788
            }
789
        } else { 
790
            $returnVal=$returnVal.$_;
791
        }
820 792
    }
821
    
822
    #$returnVal =~ s/&/%26/g;    
793

  
823 794
    return $returnVal;
824 795
}
825 796

  
......
839 810

  
840 811
    my $returnVal = "";
841 812

  
842
    foreach (split(//,$val)){
813
    foreach (split(//,$val)) {
843 814
        my $var = unpack "C*", $_;
844 815

  
845
        if($var<128 && $var>31){
816
        if($var < 128 && $var > 31) {
846 817
            $returnVal=$returnVal.$_;
847
        } elsif ($var<32){
848
            if($var == 10){
818
        } elsif ($var < 32) {
819
            if($var == 10) {
849 820
                $returnVal=$returnVal.$_;
850 821
            }
851
            if($var == 13){
822
            if ($var == 13) {
852 823
                $returnVal=$returnVal.$_;
853 824
            }
854
            if($var == 9){
825
            if ($var == 9) {
855 826
                $returnVal=$returnVal.$_;
856 827
            }
857 828
        } else {
......
919 890
    my $fileSize = stat($outFile)->size;
920 891
    if ($fileSize == 0) {
921 892
        push(@errorMessages, "file $fileName is zero bytes!");
922
        debug( "Registry: file $fileName is zero bytes!");
893
        debug("Registry: file $fileName is zero bytes!");
923 894
    }
924 895

  
925 896
    # Now the file is on disk, send the object to Metacat
926 897
    my $session = CGI::Session->load();
927
    if ( $session->is_empty ) {
898
    if ($session->is_empty) {
928 899
        push(@errorMessages, "Must be logged in to upload files.");
929
        debug( "Not logged in, cannot upload files.");
900
        debug("Not logged in, cannot upload files.");
930 901
        return 0;
931 902
    }
932 903

  
933 904
    my $docid = newAccessionNumber($config->{'scope'});
934 905
    my $uploadReturn = uploadData($outFile, $docid);
935 906
    if (!$uploadReturn) {
936
        debug( "Registry: uploading the data failed.");
907
        debug("Registry: uploading the data failed.");
937 908
    }
938 909

  
939 910
    my $entityid = $fileHash."001";
......
974 945
    my $fileSize = stat($outFile)->size;
975 946
    if ($fileSize == 0) {
976 947
        push(@errorMessages, "file $fileName is zero bytes!");
977
        debug( "Registry: file $fileName is zero bytes!");
948
        debug("Registry: file $fileName is zero bytes!");
978 949
    }
979 950

  
980 951
    # file is in Metacat, generate the pertinent EML elements
......
1148 1119
    foreach my $origName (param()) {
1149 1120
        my $origNum = $origName;
1150 1121
        $origNum =~ s/origNamelast//; # get the index of the parameter 0 to 10
1151
        if ( $origNum =~ /^([0-9]+)$/) {
1122
        if ($origNum =~ /^([0-9]+)$/) {
1152 1123
            # do not generate EML for empty originator fields
1153 1124
            if (hasContent(param("origNamefirst" . $origNum))) {
1154 1125
                my $first = normalize(param("origNamefirst" . $origNum));
......
1202 1173
    my $entityList = "";
1203 1174

  
1204 1175
    my $access = fileAccessElement(\%entityObjects);
1205
    while ( my ($docid, $data) = each(%entityObjects) ) {
1176
    while (my ($docid, $data) = each(%entityObjects)) {
1206 1177
        my $entityStub = qq|<otherEntity id="$data->{'entityid'}" scope="document">
1207 1178
            <entityName>$data->{'fileName'}</entityName>
1208 1179
            <physical scope="document">
......
1243 1214
        'private' => 'deny',
1244 1215
    );
1245 1216

  
1246
    while ( my ($docid, $data) = each(%entityObjects) ) {
1217
    while (my ($docid, $data) = each(%entityObjects)) {
1247 1218
        my $defaultAccess = $accessRoles{$data->{'filePerm'}};
1248 1219
        $accessList = qq|
1249 1220
                <access authSystem="knb" order="denyFirst">
......
1267 1238
    foreach my $kwName (param()) {
1268 1239
        my $kwNum = $kwName;
1269 1240
        $kwNum =~ s/keyword//; # get the index of the parameter 0, ..., 10
1270
        if ( $kwNum =~ /^([0-9]+)$/ ){
1241
        if ($kwNum =~ /^([0-9]+)$/) {
1271 1242
            # don't generate xml for empty keyword fields
1272 1243
            # don't generate taxonomic keyword fields, those go in taxonomic coverage
1273 1244
            if (hasContent(param($kwName))) {
......
1656 1627
            my $taxIndex = $trn;
1657 1628
            $taxIndex =~ s/taxonRankName//; # get the index of the parameter 0, ..., 10
1658 1629
            my $trv = "taxonRankValue".$taxIndex;
1659
            if ( $taxIndex =~ /[0-9]+/ ){
1630
            if ($taxIndex =~ /[0-9]+/) {
1660 1631
                if (hasContent(param($trn)) && hasContent(param($trv))) {
1661
                    if (! $foundFirstTaxon) {
1632
                    if (!$foundFirstTaxon) {
1662 1633
                        $cov .= "<taxonomicCoverage>\n";
1663 1634
                        $foundFirstTaxon = 1;
1664 1635
                        if (hasContent($FORM::taxaAuth)) {
......
1735 1706
        $access .= allowElement(getUsername(), 'read', 'write'); 
1736 1707
    }
1737 1708

  
1738
    if($config->{'publicReadable'} eq "true"){
1709
    if ($config->{'publicReadable'} eq "true") {
1739 1710
        $access .= allowElement('public', 'read');
1740 1711
    }
1741 1712
    $access .= "</access>\n";
......
1762 1733
        $username = "uid=$FORM::username,o=$FORM::organization,dc=ecoinformatics,dc=org";    
1763 1734
    } else {
1764 1735
        my $session = CGI::Session->load();
1765
        if ( !$session->is_empty ) {
1736
        if (!$session->is_empty) {
1766 1737
            $username = $session->param("username");
1767 1738
        }
1768 1739
    }
......
1789 1760
    my $tempfile;
1790 1761

  
1791 1762
    my $session = CGI::Session->load();
1792
    if ( !$session->is_empty ) {
1763
    if (!$session->is_empty) {
1793 1764
        my $username = $session->param("username");
1794 1765
        my $password = $session->param("password");
1795 1766
        $metacat->login($username, $password);
......
1804 1775
        $error ="Error in parsing the eml document";
1805 1776
        push(@errorMessages, $error);
1806 1777
    } elsif ($doc=~ /<error/) {
1807
        if ( $doc=~ /public/){
1778
        if ($doc=~ /public/) {
1808 1779
            $error ="Error in reading the eml document. Please check if you are logged in.";
1809 1780
            push(@errorMessages, $error);
1810 1781
        } else {
......
1822 1793
    return $xmldoc;
1823 1794
}   
1824 1795

  
1825
    
1796

  
1826 1797
################################################################################
1827 1798
# 
1828 1799
# read the eml document and send back a form with values filled in. 
......
1842 1813
        $error = 1;
1843 1814
        $$templateVars{'function'} = "modification";
1844 1815
        $$templateVars{'section'} = "Modification Status";
1845
        $template->process( $templates->{'response'}, $templateVars); 
1816
        $template->process($templates->{'response'}, $templateVars); 
1846 1817
    } else {
1847 1818
        $$templateVars{'form'} = 're_entry';
1848
        $template->process( $templates->{'entry'}, $templateVars);
1819
        $template->process($templates->{'entry'}, $templateVars);
1849 1820
    }
1850 1821
}
1851 1822

  
......
1927 1898
    } elsif ($results->size() < 1) {
1928 1899
        $error ="Following tag not found: title. Please use Morpho to edit this document";
1929 1900
        push(@errorMessages, $error."\n");
1930
        #if ($DEBUG == 1){ print $error;}
1931 1901
    } else {
1932 1902
        foreach $node ($results->get_nodelist) {
1933 1903
            $$templateVars{'title'} = findValue($node, '../title');
......
2038 2008

  
2039 2009
    $results = $doc->findnodes('//dataset/metadataProvider');
2040 2010
    foreach $node ($results->get_nodelist) {
2041
            dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
2011
        dontOccur($node, "./organizationName|./positionName|./onlineURL|./userId|./electronicMailAddress|./phone|./address", 
2042 2012
                "organizationName, positionName, onlineURL, userId, electronicMailAddress, phone, address in metadataProvider");
2043 2013
        
2044
	    $tempResult = $node->findnodes('./individualName');
2014
        $tempResult = $node->findnodes('./individualName');
2045 2015
            if ($tempResult->size > 1) {
2046 2016
                errMoreThanOne("metadataProvider/indvidualName");
2047 2017
            } else {
......
2141 2111
        $count++;
2142 2112
    }
2143 2113
    $$templateVars{'keyCount'} = $count;
2144
    if($count > 0 ){
2114
    if ($count > 0) {
2145 2115
       $$templateVars{'hasKeyword'} = "true";
2146 2116
    }
2147 2117

  
......
2172 2142
                    if ($childNodes->size() > 1) {
2173 2143
                        $error ="The tag para in intellectualRights has children which cannot be shown using the form. Please use Morpho to edit this document";    
2174 2144
                        push(@errorMessages, $error);
2175
                        #if ($DEBUG == 1){ print $error."\n";}
2176 2145
                    } else {
2177 2146
                        #print $tempNode->nodeName().":".$tempNode->textContent();
2178 2147
                        #print "\n";
......
2191 2160
    if ($results->size() > 1) {
2192 2161
        errMoreThanOne("distribution/online");
2193 2162
    } else {
2194
        foreach my $tempNode ($results->get_nodelist){
2163
        foreach my $tempNode ($results->get_nodelist) {
2195 2164
            $$templateVars{'url'} = findValue($tempNode, "url");
2196 2165
            dontOccur($tempNode, "./connection", "/distribution/online/connection");
2197 2166
            dontOccur($tempNode, "./connectionDefinition", "/distribution/online/connectionDefinition");
......
2204 2173
    } else {
2205 2174
        foreach my $tempNode ($results->get_nodelist) {
2206 2175
            my $temp = findValue($tempNode, "mediumName");
2207
            if(substr($temp, 0, 5) eq "other"){
2176
            if (substr($temp, 0, 5) eq "other") {
2208 2177
                $$templateVars{'dataMedium'} = substr($temp, 0, 5);
2209 2178
                $$templateVars{'dataMediumOther'} = substr($temp, 5);
2210 2179
            } else {
......
2240 2209
                    $$templateVars{'beginningYear'} = $x;
2241 2210
                    $$templateVars{'beginningMonth'} = $y;
2242 2211
                    $$templateVars{'beginningDay'} = $z;
2243
    
2212

  
2244 2213
                    $tempdate = findValue($tempNode, "rangeOfDates/endDate/calendarDate");
2245 2214
                    ($x, $y, $z) = split("-", $tempdate);
2246 2215
                    $$templateVars{'endingYear'} = $x;
......
2249 2218

  
2250 2219
                    $tempdate = "";
2251 2220
                    $tempdate = findValue($tempNode, "singleDateTime/calendarDate");
2252
                    if($tempdate ne ""){
2221
                    if ($tempdate ne "") {
2253 2222
                        ($x, $y, $z) = split("-", $tempdate);
2254 2223
                        $$templateVars{'beginningYear'} = $x;
2255 2224
                        $$templateVars{'beginningMonth'} = $y;
2256 2225
                        $$templateVars{'beginningDay'} = $z;
2257
                    }  
2258
		    
2259
		    $$templateVars{'hasTemporal'} = "true";
2226
                    }
2227

  
2228
                    $$templateVars{'hasTemporal'} = "true";
2260 2229
                }
2261 2230
            }
2262 2231

  
......
2491 2460
        if ($principal eq 'public' && $permission ne 'read') { $accessError = 1; }
2492 2461
        if ($principal eq $username && $permission ne 'all') { $accessError = 2; }
2493 2462
        if ($principal ne 'public' && $principal ne $username && $principal ne $moderators && $permission ne 'all') { $accessError = 3; }
2494
        if ($accessError == 3){
2463
        if ($accessError == 3) {
2495 2464
            my $session = CGI::Session->load();
2496
            if ( !$session->is_empty ) {
2465
            if (!$session->is_empty) {
2497 2466
                my $username = $session->param("username");
2498 2467
                my $password = $session->param("password");
2499
                if($principal eq $username){
2468
                if ($principal eq $username) {
2500 2469
                    $accessError = 0;
2501 2470
                }
2502 2471
            }
......
2531 2500
    dontOccur($doc, "//protocol", "protocol");
2532 2501
    $results = $doc->findnodes(
2533 2502
            '//additionalMetadata/moderatorComment');
2534
    if($results->size == 0){
2535
        dontOccur($doc, "//additionalMetadata", "additionalMetadata");    
2503
    if ($results->size == 0) {
2504
        dontOccur($doc, "//additionalMetadata", "additionalMetadata");
2536 2505
    }
2537 2506
}
2538 2507

  
......
2591 2560
    } else {
2592 2561

  
2593 2562
        $findType = $xmldoc->findnodes('//dataset/identifier');
2594
        if($findType->size() > 0){
2595
        # This is a eml beta6 document
2596
        # Delete the documents mentioned in triples also
2597
        
2598
        $findType = $xmldoc->findnodes('//dataset/triple');
2599
        if($findType->size() > 0){
2600
            foreach $node ($findType->get_nodelist){
2601
            $pushDoc = findValue($node, 'subject');
2602
            
2603
            # If the file is already in the @fileArray then do not add it 
2604
            $alreadyInArray = 0;
2605
            foreach $element (@fileArray){
2606
                if($element eq $pushDoc){
2607
                $alreadyInArray = 1;
2563
        if ($findType->size() > 0) {
2564
            # This is a eml beta6 document
2565
            # Delete the documents mentioned in triples also
2566

  
2567
            $findType = $xmldoc->findnodes('//dataset/triple');
2568
            if ($findType->size() > 0) {
2569
                foreach $node ($findType->get_nodelist) {
2570
                    $pushDoc = findValue($node, 'subject');
2571

  
2572
                    # If the file is already in the @fileArray then do not add it 
2573
                    $alreadyInArray = 0;
2574
                    foreach $element (@fileArray) {
2575
                        if ($element eq $pushDoc) {
2576
                            $alreadyInArray = 1;
2577
                        }
2578
                    }
2579

  
2580
                    if (!$alreadyInArray) {
2581
                        # If not already in array then delete the file. 
2582
                        push (@fileArray, $pushDoc);
2583
                        $response = $metacat->delete($pushDoc);
2584
                        
2585
                        if (!$response) {
2586
                            # Could not delete
2587
                            push(@errorMessages, $metacat->getMessage());
2588
                            push(@errorMessages, "Failed during deleting $pushDoc. Please check if you are authorized to delete this document.\n");
2589
                        }
2590
                    }
2608 2591
                }
2609 2592
            }
2610
            
2611
            if(!$alreadyInArray){
2612
                # If not already in array then delete the file. 
2613
                push (@fileArray, $pushDoc);
2614
                $response = $metacat->delete($pushDoc);
2615
                
2616
                if (! $response) {
2617
                # Could not delete
2618
                #push(@errorMessages, $response);
2619
                push(@errorMessages, $metacat->getMessage());
2620
                push(@errorMessages, "Failed during deleting $pushDoc. Please check if you are authorized to delete this document.\n");
2621
                }
2622
            }
2623
            }
2624 2593
        }
2625
        }
2626 2594
    }
2627
    
2595

  
2628 2596
    # Delete the main document. 
2629
    if($deleteAll){
2630
        $response = $metacat->delete($docid);  
2597
    if ($deleteAll) {
2598
        $response = $metacat->delete($docid);
2631 2599
        if (! $response) {
2632
        # Could not delete
2633
        #push(@errorMessages, $response);
2634
        push(@errorMessages, $metacat->getMessage());
2635
        push(@errorMessages, "Failed during deleting $docid. Please check if you are authorized to delete this document.\n");
2600
            # Could not delete
2601
            push(@errorMessages, $metacat->getMessage());
2602
            push(@errorMessages, "Failed during deleting $docid. Please check if you are authorized to delete this document.\n");
2636 2603
        }
2637 2604
    }
2638 2605
    }
2639
    
2606

  
2640 2607
    if (scalar(@errorMessages)) {
2641
    # If any errors, print them in the response template 
2642
    $$templateVars{'status'} = 'failure';
2643
    $$templateVars{'errorMessages'} = \@errorMessages;
2644
    $error = 1;
2608
        # If any errors, print them in the response template 
2609
        $$templateVars{'status'} = 'failure';
2610
        $$templateVars{'errorMessages'} = \@errorMessages;
2611
        $error = 1;
2645 2612
    }
2646
    
2613

  
2647 2614
    # Process the response template
2648
    if($deleteAll){
2649

  
2650
    $$templateVars{'function'} = "deleted";
2651
    $$templateVars{'section'} = "Deletion Status";
2652
    $template->process( $templates->{'response'}, $templateVars);
2615
    if ($deleteAll) {
2616
        $$templateVars{'function'} = "deleted";
2617
        $$templateVars{'section'} = "Deletion Status";
2618
        $template->process($templates->{'response'}, $templateVars);
2653 2619
    }
2654 2620
}
2655 2621

  
......
2662 2628
    #debug("Registry: handling login request");
2663 2629
    # Check if a session already exists
2664 2630
    my $session = CGI::Session->load() or die CGI::Session->errstr();
2665
    if ( $session->is_empty ) {
2631
    if ($session->is_empty) {
2666 2632
        # no session found ... check if the login is correct
2667
		my $username = $FORM::username;
2668
		my $password = $FORM::password;
2669
   
2633
        my $username = $FORM::username;
2634
        my $password = $FORM::password;
2635

  
2670 2636
        my $metacat = Metacat->new($metacatUrl);
2671 2637
        my $returnVal = $metacat->login($username,$password);
2672 2638
        debug("Registry: Login was $returnVal for login attempt to $metacatUrl, with $username");
2673
        if($returnVal > 0){
2639
        if ($returnVal > 0) {
2674 2640
            # valid username and passwd
2675 2641
            # create a new session and store username and passswd
2676 2642
            $session = new CGI::Session();
2677 2643

  
2678 2644
            $session->param('username', $username);
2679 2645
            $session->param('password', $password);
2680
    
2681
            if($returnVal == 2 || $returnVal == 4){
2646

  
2647
            if ($returnVal == 2 || $returnVal == 4) {
2682 2648
                # is a moderator. store this information in the session
2683 2649
                $session->param('moderator', 'true'); 
2684 2650
            }
......
2703 2669
            $$templateVars{'errorMessages'} = \@errorMessages;
2704 2670
            $$templateVars{'cfg'} = $skinName;
2705 2671
            $$templateVars{'section'} = "Login Status";
2706
            $template->process( $templates->{'response'}, $templateVars);
2672
            $template->process($templates->{'response'}, $templateVars);
2707 2673
        }
2708 2674

  
2709
    exit(0);
2675
        exit();
2710 2676
    } else {
2711 2677
        # session found ... redirect to index page
2712 2678
        my $url = "$skinsDir/$skinName/index.html";
2713 2679
        redirect($url);
2714
        exit(0);
2680
        exit();
2715 2681
   }
2716 2682
}
2717 2683

  
......
2722 2688
################################################################################
2723 2689
sub handleLogoutRequest(){
2724 2690
    print "Content-type: text/html\n\n";
2725
	# Check if the session exists
2726
	debug("Stage is logout");
2691
    # Check if the session exists
2692
    debug("Stage is logout");
2727 2693
    my $session = CGI::Session->load();
2728
    if ( $session->is_empty || $session->is_expired) {
2694
    if ($session->is_empty || $session->is_expired) {
2729 2695
        # no session found ... send back to index.html page ... 
2730 2696
        debug("Session empty or not found");
2731 2697
        my $url = "$skinsDir/$skinName/index.html";
......
2759 2725
    my $userPass = $FORM::password;
2760 2726
    my $dname = "uid=$userDN,o=$userOrg,dc=ecoinformatics,dc=org";
2761 2727

  
2762
    if($FORM::userLoggedIn eq 'true'){
2728
    if ($FORM::userLoggedIn eq 'true') {
2763 2729
        my $session = CGI::Session->load();
2764
        if (!( $session->is_empty || $session->is_expired)) {
2730
        if (!($session->is_empty || $session->is_expired)) {
2765 2731
            $dname = $session->param("username");
2766 2732
            $userPass = $session->param("password");
2767 2733
        }
......
2783 2749

  
2784 2750
    # Check if the session exists
2785 2751
    my $session = CGI::Session->load();
2786
    if ( $session->is_empty || $session->is_expired) {
2752
    if ($session->is_empty || $session->is_expired) {
2787 2753
        # no session found ... send back to index.html page ... 
2788 2754
        processResultTemplate($stage, 'failure', "Moderator is not logged in.\n");
2789 2755
        $returnValue = -1;
......
2791 2757

  
2792 2758
    # check if logged in user is moderator
2793 2759
    my $moderator = $session->param("moderator");
2794
    if ( $moderator ne 'true') {
2760
    if ($moderator ne 'true') {
2795 2761
        # no session found ... send back to index.html page ... 
2796 2762
        debug("Logged in user is not moderator");
2797 2763
        processResultTemplate($stage, 'failure', "Logged in user is not moderator.\n");
2798 2764
        $returnValue = -1;
2799
    } 
2765
    }
2800 2766

  
2801
    if($returnValue eq 1){
2767
    if ($returnValue eq 1) {
2802 2768
        $modUsername = $session->param("username");
2803 2769
        $modPassword = $session->param("password");
2804 2770
    }
......
2814 2780

  
2815 2781
    # Check if the session exists
2816 2782
    my $session = CGI::Session->load();
2817
        if ( $session->is_empty || $session->is_expired) {
2818
            # no session found ... send back the regular read page ...
2819
       	    my $url = "$skinsDir/$skinName/index.html";
2820
       	    redirect($url);
2821
        } else {
2822
       	    my $htmldoc = "";
2823
       	    $htmldoc .= "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Frameset//EN\" \"http://www.w3.org/TR/html4/frameset.dtd\">";
2824
       	    $htmldoc .= "<html><head><title>Dataset Description: ".$docid."</title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>";
2825
       	    $htmldoc .= "<frameset rows=\"150,*\" cols=\"*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">";
2826
       	    $htmldoc .= "<frame src=\"$skinsDir/$skinName/header.jsp\" marginwidth=\"40\" name=\"topFrame\" scrolling=\"NO\" noresize>";
2827
       	    $htmldoc .= "<frameset cols=\"200,*\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">";
2828
       	    $htmldoc .= "<body></body><frame src=\"$cgiUrl?cfg=$skinName&stage=review_frame&docid=".$docid."\" name=\"rightFrame\" scrolling=\"NO\" noresize></frame>";
2829
       	    $htmldoc .= "<frame src=\"". $metacatUrl ."?action=read&qformat=".$skinName."&docid=".$docid."&insertTemplate=0\" name=\"mainFrame\">";
2830
            $htmldoc .= "</frameset></frameset></html>";
2783
    if ($session->is_empty || $session->is_expired) {
2784
        # no session found ... send back the regular read page ...
2785
        my $url = "$skinsDir/$skinName/index.html";
2786
        redirect($url);
2787
    } else {
2788
        my $htmldoc = qq|<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
2789
        <html><head><title>Dataset Description: $docid</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
2790
          <frameset rows="150,*" cols="*" frameborder="NO" border="0" framespacing="0">
2791
            <frame src="$skinsDir/$skinName/header.jsp" marginwidth="40" name="topFrame" scrolling="NO" noresize>
2792
            <frameset cols="200,*" frameborder="NO" border="0" framespacing="0">
2793
              <body></body><frame src="$cgiUrl?cfg=$skinName&stage=review_frame&docid="$docid"" name="rightFrame" scrolling="NO" noresize></frame>
2794
              <frame src="$metacatUrl?action=read&qformat=$skinName&docid=$docid&insertTemplate=0" name="mainFrame">
2795
            </frameset>
2796
          </frameset>
2797
        </html>
2798
|;
2799
        print $htmldoc;    
2800
    }
2801
}
2831 2802

  
2832
       	    print $htmldoc;	
2833
	}
2834
} 
2835

  
2836 2803
sub handleReviewFrame {
2837
	print "Content-type: text/html\n\n";
2838
	my $session = CGI::Session->load();
2839
        if ( $session->is_empty || $session->is_expired) {
2840
		return;
2841
	}
2804
    print "Content-type: text/html\n\n";
2805
    my $session = CGI::Session->load();
2806
        if ($session->is_empty || $session->is_expired) {
2807
        return;
2808
    }
2842 2809

  
2843
	my $moderator = $session->param("moderator");
2810
    my $moderator = $session->param("moderator");
2844 2811

  
2845
	$$templateVars{'reviewdocid'} = getReviewHistoryHTML($session->param("username"),  $session->param("password"));
2846
	$$templateVars{'docid'} = $FORM::docid;
2847
	if ( $moderator eq 'true') {
2848
		$$templateVars{'isModerator'} = "true";
2849
	}
2850
	$template->process( $templates->{'getReviews'}, $templateVars);
2812
    $$templateVars{'reviewdocid'} = getReviewHistoryHTML($session->param("username"),  $session->param("password"));
2813
    $$templateVars{'docid'} = $FORM::docid;
2814
    if ($moderator eq 'true') {
2815
        $$templateVars{'isModerator'} = "true";
2816
    }
2817
    $template->process($templates->{'getReviews'}, $templateVars);
2851 2818
}
2852 2819

  
2853 2820
sub getReviewHistoryHTML {
2854
	my $username = shift;
2855
	my $password = shift;
2821
    my $username = shift;
2822
    my $password = shift;
2856 2823

  
2857 2824
    my $metacat = Metacat->new($metacatUrl);
2858
	$metacat->login($username, $password);
2859
    	my $parser = XML::LibXML->new();
2860
        my $docid = $FORM::docid;
2861
        my ($x, $y, $z) = split(/\./, $docid);
2862
        my $docidWithoutRev = $x.".".$y;
2863
        my $reviewDocumentId = '';
2864
        my $response = $metacat->squery("<pathquery><querytitle>Moderator-Search</querytitle><querygroup operator='INTERSECT'><queryterm searchmode='contains' casesensitive='false'><value>$docidWithoutRev</value><pathexpr>/reviewHistory/review/packageId</pathexpr></queryterm></querygroup></pathquery>");
2865
        my $doc = $response->content();
2866
        my $xmldoc = $parser->parse_string($doc);
2867
	my $reviewHTML = '';
2825
    $metacat->login($username, $password);
2826
    my $parser = XML::LibXML->new();
2827
    my $docid = $FORM::docid;
2828
    my ($x, $y, $z) = split(/\./, $docid);
2829
    my $docidWithoutRev = $x.".".$y;
2830
    my $reviewDocumentId = '';
2831
    my $response = $metacat->squery("<pathquery><querytitle>Moderator-Search</querytitle><querygroup operator='INTERSECT'><queryterm searchmode='contains' casesensitive='false'><value>$docidWithoutRev</value><pathexpr>/reviewHistory/review/packageId</pathexpr></queryterm></querygroup></pathquery>");
2832
    my $doc = $response->content();
2833
    my $xmldoc = $parser->parse_string($doc);
2834
    my $reviewHTML = '';
2868 2835

  
2869
        if ($xmldoc eq "" || $doc=~ /<error/) {
2870
                # not able to parse
2871
                return " Unable to search for review for the docid:".$docid;
2872
        } else {
2873
            my $findNodes = $xmldoc->findnodes('//resultset/document');
2874
            if($findNodes->size() > 0){
2875
                # found contact email address
2876
                my $node = '';
2877
                foreach $node ($findNodes->get_nodelist) {
2878
                    $reviewDocumentId = findValue($node,'docid');
2879
                }
2836
    if ($xmldoc eq "" || $doc=~ /<error/) {
2837
        # not able to parse
2838
        return " Unable to search for review for the docid:".$docid;
2839
    } else {
2840
        my $findNodes = $xmldoc->findnodes('//resultset/document');
2841
        if ($findNodes->size() > 0) {
2842
            # found contact email address
2843
            my $node = '';
2844
            foreach $node ($findNodes->get_nodelist) {
2845
                $reviewDocumentId = findValue($node,'docid');
2880 2846
            }
2881
	}
2882
	return $reviewDocumentId;
2847
        }
2848
    }
2849
    return $reviewDocumentId;
2883 2850
}
2884 2851

  
2885 2852
################################################################################
......
2897 2864
    debug("Stage is mod_accept");
2898 2865

  
2899 2866
    my $isMod = isModerator("accept");
2900
    if($isMod < 0){
2901
    	return;
2867
    if ($isMod < 0) {
2868
        return;
2902 2869
    }
2903 2870
    # change the access rules
2904 2871
    ## create the access block
......
2909 2876
    $accessblock .= "<permission>all</permission>\n";
2910 2877
    $accessblock .= "</allow>\n";
2911 2878

  
2912
    foreach(split(":",$moderators)){
2879
    foreach (split(":",$moderators)) {
2913 2880
        $accessblock .= "<allow>\n";
2914 2881
        $accessblock .= "<principal>".$_."</principal>\n";
2915 2882
        $accessblock .= "<permission>all</permission>\n";
......
2931 2898
    # Log into metacat
2932 2899
    my $response = $metacat->login($modUsername, $modPassword);
2933 2900

  
2934
    if (! $response) {
2901
    if (!$response) {
2935 2902
        # Could not login
2936 2903
        $errorMessage = $errorMessage." Failed during moderator login.";
2937 2904

  
......
2942 2909
        my $docFromMetacat = $response->content();
2943 2910
        my $xmldoc = $parser->parse_string($docFromMetacat);
2944 2911

  
2945
	if ($xmldoc eq "" || $docFromMetacat=~ /<error/) {
2946
                # not able to parse
2947
                $errorMessage = $errorMessage." Error in reading the following docid:".$docid;
2912
        if ($xmldoc eq "" || $docFromMetacat=~ /<error/) {
2913
            # not able to parse
2914
            $errorMessage = $errorMessage." Error in reading the following docid:".$docid;
2948 2915
        } else {
2949
		my ($emldoc, $temp) = split('<access authSystem=', $docFromMetacat);
2950
		$emldoc .= $accessblock;
2951
    		$emldoc .= "</dataset>\n</eml:eml>\n";
2916
            my ($emldoc, $temp) = split('<access authSystem=', $docFromMetacat);
2917
            $emldoc .= $accessblock;
2918
            $emldoc .= "</dataset>\n</eml:eml>\n";
2952 2919

  
2953
    		#debug("Document created by handleModAccept is " . $emldoc);
2954
    		# update the document
2955
    		my $docid = $FORM::docid;
2956
    
2957
    		my $x;
2958
    		my $y;
2959
    		my $z;
2960
        
2961
    		($x, $y, $z) = split(/\./, $docid); 
2962
    		$z++;
2963
    		my $newDocid = "$x.$y.$z";
2964
    
2965
    		$emldoc =~ s/packageId=\"$docid\"/packageId=\"$newDocid\"/;
2966
   		$response = $metacat->update($newDocid, $emldoc);
2920
            #debug("Document created by handleModAccept is " . $emldoc);
2921
            # update the document
2922
            my $docid = $FORM::docid;
2967 2923

  
2968
    		if (! $response) {
2969
        		debug("Error while updating in handleModAccept.");
2970
    			#push(@errorMessages, $metacat->getMessage());
2971
        		$errorMessage = $errorMessage." Failed while updating the document with new access rules.";  
2972
		}
2924
            my $x;
2925
            my $y;
2926
            my $z;
2973 2927

  
2974
		# get the contact email address from the 
2975
   		$xmldoc = $parser->parse_string($emldoc);
2928
            ($x, $y, $z) = split(/\./, $docid); 
2929
            $z++;
2930
            my $newDocid = "$x.$y.$z";
2976 2931

  
2977
   		if ($xmldoc eq "" || $xmldoc=~ /<error/) {
2978
			# not able to parse
2979
       			$errorMessage = $errorMessage." Error in reading the docid:".$docid;
2980
		} else {
2981
	    		my $findNodes = $xmldoc->findnodes('//dataset/contact');
2982
	    		if($findNodes->size() > 0){
2983
				# found contact email address
2984
				my $node = '';
2985
				foreach $node ($findNodes->get_nodelist) {
2986
					$contactEmailAddress = findValue($node,'electronicMailAddress');
2987
					my $surName = findValue($node,'individualName/surName');
2988
					my $givenName = findValue($node,'individualName/givenName');
2989
					my $organizationName = findValue($node,'organizaitionName');
2990
	
2991
					if($surName ne ''){
2992
						$contactName = $givenName.' '.$surName;
2993
					} else {
2994
						$contactName = $organizationName;
2995
					}
2996
				}
2997
			} else {
2998
				$contactEmailAddress = '';
2999
			}
3000
    			$findNodes = $xmldoc->findnodes('//dataset/title');
3001
			if($findNodes->size() > 0){
3002
				# found title
3003
				my $node = '';
3004
				foreach $node ($findNodes->get_nodelist) {
3005
					$title = findValue($node,'../title');
3006
				}
3007
			} else {
3008
				$title = '';
3009
			}
2932
            $emldoc =~ s/packageId=\"$docid\"/packageId=\"$newDocid\"/;
2933
            $response = $metacat->update($newDocid, $emldoc);
3010 2934

  
3011
			$findNodes = $xmldoc->findnodes('//dataset/access/allow');
3012
			if($findNodes->size() > 0){
3013
			# found title
3014
                                my $node = '';
3015
                                foreach $node ($findNodes->get_nodelist) {
3016
                                        my $perm = findValue($node,'permission');
3017
					if($perm ne 'all'){
3018
						$userDN = findValue($node,'principal');
3019
					}
3020
                                }
2935
            if (! $response) {
2936
                debug("Error while updating in handleModAccept.");
2937
                #push(@errorMessages, $metacat->getMessage());
2938
                $errorMessage = $errorMessage." Failed while updating the document with new access rules.";  
2939
            }
2940

  
2941
            # get the contact email address from the 
2942
            $xmldoc = $parser->parse_string($emldoc);
2943

  
2944
            if ($xmldoc eq "" || $xmldoc=~ /<error/) {
2945
                # not able to parse
2946
                $errorMessage = $errorMessage." Error in reading the docid:".$docid;
2947
            } else {
2948
                my $findNodes = $xmldoc->findnodes('//dataset/contact');
2949
                if ($findNodes->size() > 0) {
2950
                    # found contact email address
2951
                    my $node = '';
2952
                    foreach $node ($findNodes->get_nodelist) {
2953
                        $contactEmailAddress = findValue($node,'electronicMailAddress');
2954
                        my $surName = findValue($node,'individualName/surName');
2955
                        my $givenName = findValue($node,'individualName/givenName');
2956
                        my $organizationName = findValue($node,'organizaitionName');
2957

  
2958
                        if ($surName ne '') {
2959
                            $contactName = $givenName.' '.$surName;
3021 2960
                        } else {
3022
                                $userDN = '';
2961
                            $contactName = $organizationName;
3023 2962
                        }
2963
                    }
2964
                } else {
2965
                    $contactEmailAddress = '';
2966
                }
2967
                $findNodes = $xmldoc->findnodes('//dataset/title');
2968
                if ($findNodes->size() > 0) {
2969
                    # found title
2970
                    my $node = '';
2971
                    foreach $node ($findNodes->get_nodelist) {
2972
                        $title = findValue($node,'../title');
2973
                    }
2974
                } else {
2975
                    $title = '';
2976
                }
3024 2977

  
3025
		}	
3026
	}
2978
                $findNodes = $xmldoc->findnodes('//dataset/access/allow');
2979
                if ($findNodes->size() > 0) {
2980
                    # found title
2981
                    my $node = '';
2982
                    foreach $node ($findNodes->get_nodelist) {
2983
                        my $perm = findValue($node,'permission');
2984
                        if ($perm ne 'all') {
2985
                            $userDN = findValue($node,'principal');
2986
                        }
2987
                    }
2988
                } else {
2989
                    $userDN = '';
2990
                }
2991
            }
2992
        }
3027 2993
    }
2994

  
3028 2995
    # send notification to the user and the moderator
3029 2996
    if ($errorMessage eq '') {
3030
    	mod_sendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Accepted');
3031
        if($FORM::review ne ''){
3032
                $errorMessage = mod_storeReview('accept', $metacat, $userDN);
3033
                if ($errorMessage ne '') {
3034
                        processResultTemplate('accept', 'failure', $errorMessage);
3035
                        return;
3036
                }
2997
        modSendNotification($title, $contactEmailAddress, $contactName, 'Document '.$FORM::docid.' Accepted');
2998
        if ($FORM::review ne '') {
2999
            $errorMessage = modStoreReview('accept', $metacat, $userDN);
3000
            if ($errorMessage ne '') {
3001
                processResultTemplate('accept', 'failure', $errorMessage);
3002
                return;
3003
            }
3037 3004
        }
3038
    	# send notifications
3039
	processResultTemplate('accept', 'success', $errorMessage);		
3005
        # send notifications
3006
        processResultTemplate('accept', 'success', $errorMessage);
3040 3007
    } else {
3041
	processResultTemplate('accept', 'failure', $errorMessage);		
3008
        processResultTemplate('accept', 'failure', $errorMessage);
3042 3009
    }
3043 3010
}
3044 3011

  
......
3057 3024

  
3058 3025
    debug("Stage is mod_decline");
3059 3026

  
3060
    if(isModerator('decline')<0){
3061
    	return;
3027
    if (isModerator('decline') < 0) {
3028
        return;
3062 3029
    }
3063 3030

  
3064 3031
    # variables for contact information
......
3074 3041
        #push(@errorMessages, $metacat->getMessage());
3075 3042
        $errorMessage = $errorMessage." Failed during moderator login.";
3076 3043
    } else {
3077
		# read the document and get the contact name and address
3078
	my $parser = XML::LibXML->new();
3079
    	my $docid = $FORM::docid;
3044
        # read the document and get the contact name and address
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff