Project

General

Profile

« Previous | Next » 

Revision 4357

Added by walbridge about 16 years ago

Further improvements to the registry to properly support the new properties. Removed all variables previously passed around between forms which should always be available canonically from the skin.properties file and replaced with refences to properties value for the skin being used. Removed some cruft from both files, fixed mior issues mentioned in bug #3487.

View differences:

register-dataset.cgi
43 43
use File::Basename;
44 44
use strict;
45 45

  
46
debug("at top...");
46 47
# Global configuration paramters
47 48
my $cgiUrl = $ENV{'SCRIPT_FILENAME'};
48 49
my $workingDirectory = ".";
......
75 76
my $styleSkinsPath = $contextUrl . "/style/skins";
76 77
my $styleCommonPath = $contextUrl . "/style/common";
77 78

  
79
# XXX remove me
80
#print "Content-type: text/html\n\n";
81
#print "skins: $skinsDir, templates: $templatesDir, tempDir: $tempDir, url: $contextUrl";
82
#exit;
78 83
my $now = time;
79 84

  
80 85
# Import all of the HTML form fields as variables
......
123 128

  
124 129
# replacements for appconfig values using properties
125 130
my $moderators = $properties->getProperty('ldap.moderators'); # scw TODO: check if this changes to per-skin
126
my $config = $properties->splitToTree(qr/\./, 'registry.config');
127
my $templates = $properties->splitToTree(qr/\./, 'registry.templates');
128
my $modules = $properties->splitToTree(qr/\./, 'registry.modules');
129
my $required = $properties->splitToTree(qr/\./, 'registry.required');
130
my $spatial = $properties->splitToTree(qr/\./, 'registry.spatial');
131
my $config = $skinProperties->splitToTree(qr/\./, 'registry.config');
132
my $templates = $skinProperties->splitToTree(qr/\./, 'registry.templates');
133
my $modules = $skinProperties->splitToTree(qr/\./, 'registry.modules');
134
my $required = $skinProperties->splitToTree(qr/\./, 'registry.required');
135
my $spatial = $skinProperties->splitToTree(qr/\./, 'registry.spatial');
136
my $show = $skinProperties->splitToTree(qr/\./, 'registry.show');
131 137

  
132 138
# set stderr printing if configured
133 139
my $debug_enabled = $config->{'debug'};
......
138 144
my $username = $config->{'username'};
139 145
my $password = $config->{'password'};
140 146

  
141
# TODO SCW replace these with the proper array versions once the templates work correctly
142
my $showWgList = $required->{'wgList'};
143
my $showOrganization = $required->{'organization'};
144
my $hasKeyword = $required->{'keyword'};
145
my $hasTemporal = $required->{'temporal'};
146
my $hasSpatial = $required->{'spatial'};
147
my $hasTaxonomic = $required->{'taxonomic'};
148
my $hasMethod = $required->{'method'};
149
my $hasUpload = $required->{'upload'};
150

  
151 147
# contains sender, recipient, admin, mailhost
152 148
my $email = $skinProperties->splitToTree(qr/\./, 'email');
153 149

  
154
# set stderr printing if configured
155
my $debug_enabled = $config->{'debug'};
156
if ($FORM::debug) {
157
    $debug_enabled = $FORM::debug;
158
}
159

  
160 150
#Convert the lat and lon configs into usable data structures
161 151
my @sitelist;
162 152
my %siteLatDMS;
......
169 159
    $siteLatDMS{$name} = [ $latd, $latm, $lats, $latdir ];
170 160
    $siteLongDMS{$name} = [ $lond, $lonm, $lons, $londir ];
171 161
}
172
debug("template: $templatesDir\n");
162

  
173 163
# set some configuration options for the template object
174 164
my $ttConfig = {
175 165
             INCLUDE_PATH => $templatesDir,
176 166
             INTERPOLATE  => 0,                    
177 167
             POST_CHOMP   => 1,
178
             #DEBUG        => 'all',
168
             DEBUG        => 1,
179 169
             };
180 170

  
181 171
# create an instance of the template processor
182 172
my $template = Template->new($ttConfig) || die $Template::ERROR, "\n";
183

  
173
#print "Content-type: text/html\n\n";
174
#print "Is debug enabled? `$debug_enabled`";
175
#use Data::Dumper;
176
#print Dumper($config);
177
#exit;
184 178
# Set up the template information that is common to all forms
185 179

  
186 180
# GENERATE ME:
......
325 319
        	$$templateVars{'projects'} = $projects;
326 320
        	$$templateVars{'wg'} = \@FORM::wg;
327 321
    	}
328

  
329
        #$$templateVars{'required'} = $required; 
322
        
323
        $$templateVars{'modules'} = $modules;
324
        $$templateVars{'required'} = $required;
330 325
        $$templateVars{'templates'} = $templates;
331
        $$templateVars{'showSiteList'} = $required->{'siteList'};
326
        $$templateVars{'show'} = $show;
332 327
        $$templateVars{'site'} = $config->{'site'};
333
        $$templateVars{'showWgList'} = $showWgList;
334
        $$templateVars{'showOrganization'} = $showOrganization;
335
        $$templateVars{'hasKeyword'} = $hasKeyword;
336
        $$templateVars{'hasTemporal'} = $hasTemporal;
337
        $$templateVars{'hasSpatial'} = $hasSpatial;
338
        $$templateVars{'hasTaxonomic'} = $hasTaxonomic;
339
        $$templateVars{'hasMethod'} = $hasMethod;
340
        $$templateVars{'hasUpload'} = $hasUpload;
341
        $$templateVars{'temporalRequired'} = $required->{'temporalRequired'};
342
        $$templateVars{'spatialRequired'} = $required->{'spatialRequired'};
343
        $$templateVars{'contactEmailAddressRequired'} = $required->{'contactEmail'};
344 328

  
345 329
        $$templateVars{'siteList'} = \@sortedSites;
346 330
        $$templateVars{'section'} = "Entry Form";
......
687 671
        unless hasContent($FORM::origNamelast0);
688 672
    push(@invalidParams, "Dataset abstract is missing.")
689 673
        unless hasContent($FORM::abstract);
690
    if($FORM::hasTemporal eq 'true'){
674
    if($modules->{'temporal'} eq 'true'){
691 675
	push(@invalidParams, "Year of start date is missing.")
692
	    unless (hasContent($FORM::beginningYear) || $FORM::temporalRequired ne 'true');
676
	    unless (hasContent($FORM::beginningYear) || $required->{'temporal'} ne 'true');
693 677
	push(@invalidParams, "Year of stop date has been specified but year of start date is missing.")
694 678
	    if ((!hasContent($FORM::beginningYear)) && hasContent($FORM::endingYear));
695 679
    }
696 680
    push(@invalidParams, "Geographic description is missing.")
697
        unless (hasContent($FORM::geogdesc) || $FORM::spatialRequired ne 'true');
681
        unless (hasContent($FORM::geogdesc) || $required->{'spatial'} ne 'true');
698 682

  
699 683
    if($FORM::beginningMonth eq "MM"){
700 684
	#if (hasContent($FORM::beginningYear)){
......
736 720
    # If the "use site" coord. box is checked and if the site is in 
737 721
    # the longitude hash ...  && ($siteLatDMS{$FORM::site})
738 722
    
739
    if($FORM::hasSpatial eq 'true'){
723
    if($modules->{'spatial'} eq 'true'){
740 724
	if (($FORM::useSiteCoord) && ($siteLatDMS{$FORM::site}) ) {
741 725
        
742 726
	    $latDeg1 = $siteLatDMS{$FORM::site}[0];
......
804 788
    # and long mentioned in the config file. 
805 789

  
806 790

  
807
    if($FORM::hasSpatial eq 'true' && $FORM::spatialRequired eq 'true'){
791
    if($modules->{'spatial'} eq 'true' && $required->{'spatial'} eq 'true'){
808 792
	if ($FORM::useSiteCoord ) {
809 793
	    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.")
810 794
		unless(hasContent($latDeg1) && hasContent($longDeg1));
811 795
	}else{
812 796
	    push(@invalidParams, "Latitude degrees are missing.")
813
		unless (hasContent($latDeg1) || $FORM::spatialRequired ne 'true');
797
		unless (hasContent($latDeg1) || $required->{'spatial'} ne 'true');
814 798
	    push(@invalidParams, "Longitude degrees are missing.")
815
		unless (hasContent($longDeg1) || $FORM::spatialRequired ne 'true');
799
		unless (hasContent($longDeg1) || $required->{'spatial'} ne 'true');
816 800
	}
817 801
	push(@invalidParams, 
818 802
	     "You must provide a geographic description if you provide latitude and longitude information.")
819 803
	    if ((hasContent($latDeg1) || (hasContent($longDeg1))) && (!hasContent($FORM::geogdesc)));
820 804
    }
821 805

  
822
    if($FORM::hasMethod eq 'true'){
806
    if($modules->{'method'} eq 'true'){
823 807
	push(@invalidParams, 
824 808
	     "You must provide a method description if you provide a method title.")
825 809
	    if (hasContent($FORM::methodTitle) && ( !(scalar(@FORM::methodPara) > 0) 
......
842 826
    push(@invalidParams, "Last name of data set contact is missing.")
843 827
    unless (hasContent($FORM::origNamelastContact) || 
844 828
        $FORM::useOrigAddress);
845
    if($FORM::contactEmailAddressRequired eq 'true'){
829
    if($required->{'contactEmailAddress'} eq 'true'){
846 830
        if($FORM::useOrigAddress){
847 831
    		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.")
848 832
    			unless (hasContent($FORM::origEmail));
......
1563 1547
            $cont .= "<city>".normalize($FORM::origCityContact)."</city>\n";
1564 1548
        }
1565 1549
        if (hasContent($FORM::origStateContact) &&
1566
            ($FORM::origStateContact !=~ /select state/i)) {
1550
            ($FORM::origStateContact !~ /select state/i)) {
1567 1551
            $cont .= "<administrativeArea>".normalize($FORM::origStateContact);
1568 1552
            $cont .= "</administrativeArea>\n";
1569 1553
        } elsif (hasContent($FORM::origStateOtherContact)) {
......
1718 1702
            $hemisph = ($hemisphLong1 eq "W") ? -1 : 1;
1719 1703
            $cov .= "<westBoundingCoordinate>";
1720 1704
            my $var = $hemisph * ($longDeg1 + (60*$longMin1+$longSec1)/3600);
1721
            $cov .= sprintf("%.4f\n", $var);
1705
            $cov .= sprintf("%.4f", $var);
1722 1706
            $cov .= "</westBoundingCoordinate>\n";
1723 1707

  
1724 1708
            $hemisph = ($hemisphLong2 eq "W") ? -1 : 1;
1725 1709
            $cov .= "<eastBoundingCoordinate>";
1726 1710
            $var = $hemisph * ($longDeg2 + (60*$longMin2+$longSec2)/3600);
1727
            $cov .= sprintf("%.4f\n", $var);
1711
            $cov .= sprintf("%.4f", $var);
1728 1712
            $cov .= "</eastBoundingCoordinate>\n";
1729 1713

  
1730 1714
            $hemisph = ($hemisphLat1 eq "S") ? -1 : 1;
1731 1715
            $cov .= "<northBoundingCoordinate>";
1732 1716
            $var = $hemisph * ($latDeg1 + (60*$latMin1+$latSec1)/3600);
1733
            $cov .= sprintf("%.4f\n", $var);
1717
            $cov .= sprintf("%.4f", $var);
1734 1718
            $cov .= "</northBoundingCoordinate>\n";
1735 1719

  
1736 1720
            $hemisph = ($hemisphLat2 eq "S") ? -1 : 1;
1737 1721
            $cov .= "<southBoundingCoordinate>";
1738 1722
            $var = $hemisph * ($latDeg2 + (60*$latMin2+$latSec2)/3600);
1739
            $cov .= sprintf("%.4f\n", $var);
1723
            $cov .= sprintf("%.4f", $var);
1740 1724
            $cov .= "</southBoundingCoordinate>\n";
1741 1725

  
1742 1726
            $cov .= "</boundingCoordinates>\n";
......
2032 2016
    my $foundDSO;
2033 2017

  
2034 2018
    # set variable values
2019
    $$templateVars{'modules'} = $modules;
2035 2020
    $$templateVars{'required'} = $required;
2036
    $$templateVars{'showSiteList'} = $required->{'siteList'};
2021
    $$templateVars{'show'} = $show;
2037 2022
    $$templateVars{'site'} = $config->{'site'};
2038
    #$$templateVars{'showWgList'} = $showWgList;
2039
    $$templateVars{'showOrganization'} = $showOrganization;
2040
    $$templateVars{'hasKeyword'} = $hasKeyword;
2041
    $$templateVars{'hasTemporal'} = $hasTemporal;
2042
    $$templateVars{'hasSpatial'} = $hasSpatial;
2043
    $$templateVars{'hasTaxonomic'} = $hasTaxonomic;
2044
    $$templateVars{'hasMethod'} = $hasMethod;
2045
    $$templateVars{'spatialRequired'} = $required->{'spatialRequired'};
2046
    $$templateVars{'contactEmailAddressRequired'} = $required->{'contactEmail'};
2047
    $$templateVars{'temporalRequired'} = $required->{'temporal'};
2048 2023

  
2049 2024
    # find out the tag <alternateIdentifier>. 
2050 2025
    $results = $doc->findnodes('//dataset/alternateIdentifier');
......
3633 3608
################################################################################
3634 3609
sub toConfirmData{
3635 3610
    # Check if any invalid parameters
3636
 
3611

  
3637 3612
    my $invalidParams;
3638 3613
    if (! $error) {
3639
    	$invalidParams = validateParameters(0);
3640
    	if (scalar(@$invalidParams)) {
3641
        	$$templateVars{'status'} = 'failure';
3642
        	$$templateVars{'invalidParams'} = $invalidParams;
3643
        	$error = 1;
3644
    	}
3614
        $invalidParams = validateParameters(0);
3615
        if (scalar(@$invalidParams)) {
3616
            $$templateVars{'status'} = 'failure';
3617
            $$templateVars{'invalidParams'} = $invalidParams;
3618
            $error = 1;
3619
        }
3645 3620
    }
3646 3621

  
3647 3622
    $$templateVars{'providerGivenName'} = normalizeCD($FORM::providerGivenName);
......
3724 3699
            $$templateVars{"origNamelast".$aoCount} = normalizeCD($aoLNArray->[$i]);
3725 3700
            $$templateVars{"origRole".$aoCount} = normalizeCD($aoRoleArray->[$i]);
3726 3701
            $aoCount++;
3727
        }    
3702
        }
3728 3703
    }
3729 3704

  
3730 3705
    $$templateVars{'aoCount'} = $aoCount;
3731 3706
    $$templateVars{'abstract'} = normalizeCD($FORM::abstract);
3732
   
3733
   
3707

  
3708

  
3734 3709
    my $keywordArray = \@FORM::keyword;
3735 3710
    my $keywordTypeArray = \@FORM::keywordType;
3736 3711
    my $keywordThArray = \@FORM::keywordTh;
3737 3712
    my $keyCount = 1;
3738
   
3713

  
3739 3714
    for(my $i = 0; $i <= $#$keywordArray; $i++){
3740 3715
        if (hasContent($keywordArray->[$i])) {
3741 3716
            debug("Registry processing keyword: keyword = ".$keywordArray->[$i]."
......
3745 3720
            $$templateVars{"kwType".$keyCount} = normalizeCD($keywordTypeArray->[$i]);
3746 3721
            $$templateVars{"kwTh".$keyCount} = normalizeCD($keywordThArray->[$i]);
3747 3722
            $keyCount++;
3748
	}    
3749
    }    
3723
        }
3724
    }
3750 3725
    $$templateVars{'keyCount'} = $keyCount;
3751
    
3726

  
3752 3727
    $$templateVars{'addComments'} = normalizeCD($FORM::addComments);
3753 3728
    $$templateVars{'useConstraints'} = $FORM::useConstraints;
3754 3729
    if($FORM::useConstraints eq "other"){
......
3795 3770
            $$templateVars{"taxonRankName".$taxonCount} = normalizeCD($taxonRankArray->[$i]);
3796 3771
            $$templateVars{"taxonRankValue".$taxonCount} = normalizeCD($taxonNameArray->[$i]);
3797 3772
            $taxonCount++;
3798
	}    
3773
        }
3799 3774
    }
3800 3775

  
3801 3776
    $$templateVars{'taxaCount'} = $taxonCount-1;
......
3817 3792
            }
3818 3793
        }
3819 3794
    }
3820
    
3795

  
3821 3796
    my $uploadCount = 0;
3822 3797
    for (my $fileNum = 0; $fileNum <= $FORM::fileCount; $fileNum++) {
3823 3798
        my $fn = 'file_' . $fileNum;
......
3832 3807
            $$templateVars{"upload_$totalFileNum"} = $fileInfo->{'fileHash'};
3833 3808
            $$templateVars{"uploadname_$totalFileNum"} = $fileInfo->{'fileName'};
3834 3809
            $$templateVars{"uploadtype_$totalFileNum"} = $fileInfo->{'contentType'};
3810
            $$templateVars{"uploadperm_$totalFileNum"} = param("uploadperm_$fileNum");
3835 3811
            $uploadCount++;
3836 3812
        }
3837 3813
    }
3838 3814
    # total uploads are: new uploads - deleted files + original uploads
3839 3815
    $$templateVars{'upCount'} = $uploadCount - $deleteCount + $FORM::upCount;
3840 3816
    $$templateVars{'methodTitle'} = normalizeCD($FORM::methodTitle);
3841
 
3817

  
3842 3818
    my @tempMethodPara;
3843 3819
    for (my $i = 0; $i < scalar(@FORM::methodPara); $i++) {
3844 3820
        $tempMethodPara[$i] = normalizeCD($FORM::methodPara[$i]);
......
3848 3824
    $$templateVars{'samplingDescription'} = normalizeCD($FORM::samplingDescription);
3849 3825
    $$templateVars{'origStateContact'} = $FORM::origState;
3850 3826

  
3851
    $$templateVars{'showSiteList'} = $FORM::showSiteList;
3827
    $$templateVars{'modules'} = $modules;
3828
    $$templateVars{'required'} = $required;
3829
    $$templateVars{'show'} = $show;
3852 3830
    $$templateVars{'site'} = $FORM::site;
3853
    $$templateVars{'showWgList'} = $FORM::showWgList;
3854
    $$templateVars{'showOrganization'} = $FORM::showOrganization;
3855
    $$templateVars{'hasKeyword'} = $FORM::hasKeyword;
3856
    $$templateVars{'hasTemporal'} = $FORM::hasTemporal;
3857
    $$templateVars{'hasSpatial'} = $FORM::hasSpatial;
3858
    $$templateVars{'hasTaxonomic'} = $FORM::hasTaxonomic;
3859
    $$templateVars{'hasMethod'} = $FORM::hasMethod;
3860
    $$templateVars{'hasUpload'} = $FORM::hasUpload;
3861
    $$templateVars{'spatialRequired'} = $FORM::spatialRequired;
3862
    $$templateVars{'contactEmailAddressRequired'} = $FORM::contactEmailAddressRequired;
3863
    $$templateVars{'temporalRequired'} = $FORM::temporalRequired;
3864 3831

  
3865 3832
    $$templateVars{'docid'} = $FORM::docid;
3866 3833

  
3867 3834
    # Check if the session exists
3868 3835
    my $session = CGI::Session->load();
3869 3836
    if ( !($session->is_empty || $session->is_expired)) {
3870
    	$$templateVars{'userLoggedIn'} = 'true';
3837
        $$templateVars{'userLoggedIn'} = 'true';
3871 3838
    }
3872 3839

  
3873 3840
    if (! $error) {
3874
	# If no errors, then print out data in confirm Data template
3875
	$$templateVars{'section'} = "Confirm Data";
3876
	$template->process( $templates->{'confirmData'}, $templateVars);
3841
        # If no errors, then print out data in confirm Data template
3842
        $$templateVars{'section'} = "Confirm Data";
3843
        $template->process( $templates->{'confirmData'}, $templateVars);
3877 3844

  
3878 3845
    } else{    
3879 3846
    # Errors from validation function. print the errors out using the response template
......
4049 4016
    $$templateVars{'methodPara'} = \@FORM::methodPara;
4050 4017
    $$templateVars{'studyExtentDescription'} = $FORM::studyExtentDescription;
4051 4018
    $$templateVars{'samplingDescription'} = $FORM::samplingDescription;
4052
    
4053
    $$templateVars{'showSiteList'} = $FORM::showSiteList;
4019
 
4020
    $$templateVars{'modules'} = $modules; 
4021
    $$templateVars{'required'} = $required;
4022
    $$templateVars{'show'} = $show; 
4054 4023
    $$templateVars{'site'} = $FORM::site;
4055
    $$templateVars{'showWgList'} = $FORM::showWgList;
4056
    $$templateVars{'showOrganization'} = $FORM::showOrganization;
4057
    $$templateVars{'hasKeyword'} = $FORM::hasKeyword;
4058
    $$templateVars{'hasTemporal'} = $FORM::hasTemporal;
4059
    $$templateVars{'hasSpatial'} = $FORM::hasSpatial;
4060
    $$templateVars{'hasTaxonomic'} = $FORM::hasTaxonomic;
4061
    $$templateVars{'hasMethod'} = $FORM::hasMethod;
4062
    $$templateVars{'hasUpload'} = $FORM::hasUpload;
4063 4024
    $$templateVars{'fileCount'} = $FORM::fileCount;
4064

  
4025
  
4065 4026
    my $uploadCount = 0;
4066 4027
    foreach my $upload (param()) {
4067 4028
        if ($upload =~ /upload_/) {
......
4081 4042
    }
4082 4043

  
4083 4044
    $$templateVars{'upCount'} = $uploadCount;
4084
    $$templateVars{'spatialRequired'} = $FORM::spatialRequired;
4085
    $$templateVars{'contactEmailAddressRequired'} = $FORM::contactEmailAddressRequired;
4086
    $$templateVars{'temporalRequired'} = $FORM::temporalRequired;
4087 4045
}
4088 4046

  
4089 4047
################################################################################

Also available in: Unified diff