Project

General

Profile

« Previous | Next » 

Revision 5311

Added by daigle over 14 years ago

Merge 1.9.2 changes back into the trunk

View differences:

register-dataset.cgi
1 1
#!/usr/bin/env perl
2 2
#
3 3
#  '$RCSfile$'
4
#  Copyright: 2000 Regents of the University of California 
4
#  Copyright: 2000 Regents of the University of California
5 5
#
6 6
#   '$Author$'
7 7
#     '$Date$'
8
# '$Revision$' 
9
# 
8
# '$Revision$'
9
#
10 10
# This program is free software; you can redistribute it and/or modify
11 11
# it under the terms of the GNU General Public License as published by
12 12
# the Free Software Foundation; either version 2 of the License, or
......
43 43
use File::Basename;
44 44
use strict;
45 45

  
46
#debug("running register-dataset.cgi");
47

  
46 48
# Global configuration paramters
47
my $cgiDir = $ENV{'SCRIPT_FILENAME'};
49
my $cgiDir           = $ENV{'SCRIPT_FILENAME'};
48 50
my $workingDirectory = ".";
49
if ($cgiDir ne "") {
50
    my $workingDirectory = dirname($cgiDir);
51
if ( $cgiDir ne "" ) {
52
	my $workingDirectory = dirname($cgiDir);
51 53
}
52 54
my $metacatProps = "${workingDirectory}/../WEB-INF/metacat.properties";
53
my $properties = new Config::Properties();
54
unless (open (METACAT_PROPERTIES, $metacatProps)) {
55
    print "Content-type: text/html\n\n";
56
    print "Unable to locate Metacat properties. Working directory is set as '$workingDirectory', is this correct?";
57
    exit();
55
my $properties   = new Config::Properties();
56
unless ( open( METACAT_PROPERTIES, $metacatProps ) ) {
57
	print "Content-type: text/html\n\n";
58
	print
59
"Unable to locate Metacat properties. Working directory is set as '$workingDirectory', is this correct?";
60
	exit();
58 61
}
59 62

  
60 63
$properties->load(*METACAT_PROPERTIES);
61 64

  
62 65
# local directory configuration
63
my $skinsDir = "${workingDirectory}/../style/skins";
66
my $skinsDir     = "${workingDirectory}/../style/skins";
64 67
my $templatesDir = abs_path("${workingDirectory}/../style/common/templates");
65
my $tempDir = $properties->getProperty('application.tempDir');
66
my $dataDir = $properties->getProperty('application.datafilepath');
68
my $tempDir      = $properties->getProperty('application.tempDir');
69
my $dataDir      = $properties->getProperty('application.datafilepath');
67 70

  
68 71
# url configuration
69
my $server = $properties->splitToTree(qr/\./, 'server');
72
my $server = $properties->splitToTree( qr/\./, 'server' );
70 73
my $contextUrl = 'http://' . $properties->getProperty('server.name');
71
if ($properties->getProperty('server.httpPort') ne '80') {
72
    $contextUrl = $contextUrl . ':' . $properties->getProperty('server.httpPort');
74
if ( $properties->getProperty('server.httpPort') ne '80' ) {
75
	$contextUrl =
76
	  $contextUrl . ':' . $properties->getProperty('server.httpPort');
73 77
}
74
$contextUrl = $contextUrl . '/' .  $properties->getProperty('application.context');
78
$contextUrl =
79
  $contextUrl . '/' . $properties->getProperty('application.context');
75 80

  
76 81
my $metacatUrl = $contextUrl . "/metacat";
77
my $cgiPrefix = "/" . $properties->getProperty('application.context') . "/cgi-bin";
78
my $styleSkinsPath = $contextUrl . "/style/skins";
82
my $cgiPrefix =
83
  "/" . $properties->getProperty('application.context') . "/cgi-bin";
84
my $styleSkinsPath  = $contextUrl . "/style/skins";
79 85
my $styleCommonPath = $contextUrl . "/style/common";
80 86

  
81 87
my $now = time;
......
85 91

  
86 92
# Must have a config to use Metacat
87 93
my $skinName = "";
88
if (hasContent($FORM::cfg)) {
89
    $skinName = $FORM::cfg;
90
} elsif (hasContent($ARGV[0])) {
91
    $skinName = $ARGV[0];
92
} else {
93
    debug("No configuration set.");
94
    print "Content-type: text/html\n\n";
95
    'Registry Error: The registry requires a skin name to continue.';
96
    exit();
94
if ( hasContent($FORM::cfg) ) {
95
	$skinName = $FORM::cfg;
97 96
}
97
elsif ( hasContent( $ARGV[0] ) ) {
98
	$skinName = $ARGV[0];
99
}
100
else {
101
	debug("No configuration set.");
102
	print "Content-type: text/html\n\n";
103
	'Registry Error: The registry requires a skin name to continue.';
104
	exit();
105
}
98 106

  
99 107
# Metacat isn't initialized, the registry will fail in strange ways.
100
if (!hasContent($metacatUrl)) {
101
    debug("No Metacat.");
102
    print "Content-type: text/html\n\n";
103
    'Registry Error: Metacat is not initialized! Make sure' .
104
        ' MetacatUrl is set correctly in ' .  $skinName . '.properties';
105
    exit();
108
if ( !hasContent($metacatUrl) ) {
109
	debug("No Metacat.");
110
	print "Content-type: text/html\n\n";
111
	'Registry Error: Metacat is not initialized! Make sure'
112
	  . ' MetacatUrl is set correctly in '
113
	  . $skinName
114
	  . '.properties';
115
	exit();
106 116
}
107 117

  
108 118
# Set up the hash for returning data to the HTML templates
......
111 121
my @errorMessages;
112 122

  
113 123
my $skinProperties = new Config::Properties();
114
if (! hasContent($skinName)) {
115
    $error = "Application misconfigured.  Please contact the administrator.";
116
    push(@errorMessages, $error);
117
} else {
118
    my $skinProps = "$skinsDir/$skinName/$skinName.properties";
119
    unless (open (SKIN_PROPERTIES, $skinProps)) {
120
        print "Content-type: text/html\n\n";
121
        print "Unable to locate skin properties at $skinProps.  Is this path correct?";
122
        exit();
123
    }
124
    $skinProperties->load(*SKIN_PROPERTIES);
124
if ( !hasContent($skinName) ) {
125
	$error = "Application misconfigured.  Please contact the administrator.";
126
	push( @errorMessages, $error );
125 127
}
128
else {
129
	my $skinProps = "$skinsDir/$skinName/$skinName.properties";
130
	unless ( open( SKIN_PROPERTIES, $skinProps ) ) {
131
		print "Content-type: text/html\n\n";
132
		print "Unable to locate skin properties at $skinProps.  Is this path correct?";
133
		exit();
134
	}
135
	$skinProperties->load(*SKIN_PROPERTIES);
136
}
126 137

  
127 138
# replacements for appconfig values using properties
128 139
my $moderators = $properties->getProperty('auth.moderators');
129
my $config = $skinProperties->splitToTree(qr/\./, 'registry.config');
130
my $templates = $skinProperties->splitToTree(qr/\./, 'registry.templates');
131
my $modules = $skinProperties->splitToTree(qr/\./, 'registry.modules');
132
my $required = $skinProperties->splitToTree(qr/\./, 'registry.required');
133
my $spatial = $skinProperties->splitToTree(qr/\./, 'registry.spatial');
134
my $show = $skinProperties->splitToTree(qr/\./, 'registry.show');
140
my $config     = $skinProperties->splitToTree( qr/\./, 'registry.config' );
141
my $templates  = $skinProperties->splitToTree( qr/\./, 'registry.templates' );
142
my $modules    = $skinProperties->splitToTree( qr/\./, 'registry.modules' );
143
my $required   = $skinProperties->splitToTree( qr/\./, 'registry.required' );
144
my $spatial    = $skinProperties->splitToTree( qr/\./, 'registry.spatial' );
145
my $show       = $skinProperties->splitToTree( qr/\./, 'registry.show' );
135 146

  
136 147
# set stderr printing if configured
137 148
my $debug_enabled = $config->{'debug'};
138 149
if ($FORM::debug) {
139
    $debug_enabled = $FORM::debug;
150
	$debug_enabled = $FORM::debug;
140 151
}
141 152

  
142 153
# skin owner credentials
......
144 155
my $adminPassword = $config->{'password'};
145 156

  
146 157
# contains sender, recipient, admin, mailhost
147
my $skinEmail = $skinProperties->splitToTree(qr/\./, 'email');
148
my $email = $properties->splitToTree(qr/\./, 'email');
158
my $skinEmail = $skinProperties->splitToTree( qr/\./, 'email' );
159
my $email = $properties->splitToTree( qr/\./, 'email' );
149 160

  
150 161
# override email properties with skin-based ones
151 162
my @emailData = keys(%$email);
152 163
foreach my $d (@emailData) {
153
    if (%$skinEmail->{$d}) {
154
        $email->{$d} = %$skinEmail->{$d};
155
    }
164
	if ( %$skinEmail->{$d} ) {
165
		$email->{$d} = %$skinEmail->{$d};
166
	}
156 167
}
157 168

  
158 169
# convert the lat and lon configs into usable data structures
......
160 171
my %siteLatDMS;
161 172
my %siteLongDMS;
162 173

  
163
while (my ($key, $value) = each (%$spatial)) {
164
    my ($name, $lon, $lat) = split(/\|/, $value);
165
    my ($latd, $latm, $lats, $latdir) = split(/\|/, $lat);
166
    my ($lond, $lonm, $lons, $londir) = split(/\|/, $lon);
167
    push(@sitelist, $name);
168
    $siteLatDMS{$name} = [ $latd, $latm, $lats, $latdir ];
169
    $siteLongDMS{$name} = [ $lond, $lonm, $lons, $londir ];
174
while ( my ( $key, $value ) = each(%$spatial) ) {
175
	my ( $name, $lon, $lat ) = split( /\|/, $value );
176
	my ( $latd, $latm, $lats, $latdir ) = split( /\|/, $lat );
177
	my ( $lond, $lonm, $lons, $londir ) = split( /\|/, $lon );
178
	push( @sitelist, $name );
179
	$siteLatDMS{$name}  = [ $latd, $latm, $lats, $latdir ];
180
	$siteLongDMS{$name} = [ $lond, $lonm, $lons, $londir ];
170 181
}
171 182

  
172 183
# set some configuration options for the template object
173 184
my $ttConfig = {
174
             INCLUDE_PATH => $templatesDir,
175
             INTERPOLATE  => 0,                    
176
             POST_CHOMP   => 1,
177
             DEBUG        => 1,
178
             };
185
	INCLUDE_PATH => $templatesDir,
186
	INTERPOLATE  => 0,
187
	POST_CHOMP   => 1,
188
	DEBUG        => 1,
189
};
179 190

  
180 191
# create an instance of the template processor
181 192
my $template = Template->new($ttConfig) || die $Template::ERROR, "\n";
193

  
182 194
#print "Content-type: text/html\n\n";
183 195
#print "Is debug enabled? `$debug_enabled`";
184 196
#use Data::Dumper;
......
186 198
#exit;
187 199
# Set up the template information that is common to all forms
188 200

  
189
$$templateVars{'contextUrl'} = $contextUrl;
190
$$templateVars{'styleSkinsPath'} = $styleSkinsPath;
201
$$templateVars{'contextUrl'}      = $contextUrl;
202
$$templateVars{'styleSkinsPath'}  = $styleSkinsPath;
191 203
$$templateVars{'styleCommonPath'} = $styleCommonPath;
192
$$templateVars{'cgiPrefix'} = $cgiPrefix;
193
$$templateVars{'metacatUrl'} = $metacatUrl;
194
$$templateVars{'cfg'} = $skinName;
195
$$templateVars{'email'} = $email;
196
$$templateVars{'templates'} = $templates;
197
$$templateVars{'required'} = $required;
198
$$templateVars{'config'} = $config;
204
$$templateVars{'cgiPrefix'}       = $cgiPrefix;
205
$$templateVars{'metacatUrl'}      = $metacatUrl;
206
$$templateVars{'cfg'}             = $skinName;
207
$$templateVars{'email'}           = $email;
208
$$templateVars{'templates'}       = $templates;
209
$$templateVars{'required'}        = $required;
210
$$templateVars{'config'}          = $config;
199 211

  
200 212
debug("Initialized -- stage set: $FORM::stage");
201 213

  
202
# Process the form based on stage parameter. 
203
if ($FORM::stage =~ "loginform") {
204
    print "Content-type: text/html\n\n";
205
    # Send back the login form.....
206
    my $session = CGI::Session->load() or die CGI::Session->errstr();
214
# Process the form based on stage parameter.
215
if ( $FORM::stage =~ "loginform" ) {
216
	print "Content-type: text/html\n\n";
207 217

  
208
    if ($FORM::submission eq 'true') {
209
        $$templateVars{'message'} = 'You must login to view your submissions.';
210
    }
218
	# Send back the login form.....
219
	my $session = CGI::Session->load() or die CGI::Session->errstr();
211 220

  
212
    if (!$session->is_empty) {
213
        # session found ... delete the session....
214
        $session->delete();
215
    }
221
	if ( $FORM::submission eq 'true' ) {
222
		$$templateVars{'message'} = 'You must login to view your submissions.';
223
	}
216 224

  
217
    $template->process($templates->{'login'}, $templateVars);
218
    exit();
219
} elsif ($FORM::stage =~ "logout") {
220
    handleLogoutRequest();
221
    exit();
222
} elsif ($FORM::stage =~ "login") {
223
    handleLoginRequest();
224
    exit();
225
} elsif ($FORM::stage =~ "mod_accept") {
226
    handleModAccept();
227
    exit();
228
} elsif ($FORM::stage =~ "mod_decline") {
229
    handleModDecline();
230
    exit();
231
} elsif ($FORM::stage =~ "mod_revise") {
232
    handleModRevise();
233
    exit();
234
} elsif ($FORM::stage =~ "read") {
235
    handleRead();
236
    exit();
237
} elsif ($FORM::stage =~ "review_frame") {
238
    handleReviewFrame();
239
    exit();
225
	if ( !$session->is_empty ) {
226

  
227
		# session found ... delete the session....
228
		$session->delete();
229
	}
230

  
231
	$template->process( $templates->{'login'}, $templateVars );
232
	exit();
240 233
}
234
elsif ( $FORM::stage =~ "logout" ) {
235
	handleLogoutRequest();
236
	exit();
237
}
238
elsif ( $FORM::stage =~ "login" ) {
239
	handleLoginRequest();
240
	exit();
241
}
242
elsif ( $FORM::stage =~ "mod_accept" ) {
243
	handleModAccept();
244
	exit();
245
}
246
elsif ( $FORM::stage =~ "mod_decline" ) {
247
	handleModDecline();
248
	exit();
249
}
250
elsif ( $FORM::stage =~ "mod_revise" ) {
251
	handleModRevise();
252
	exit();
253
}
254
elsif ( $FORM::stage =~ "read" ) {
255
	handleRead();
256
	exit();
257
}
258
elsif ( $FORM::stage =~ "review_frame" ) {
259
	handleReviewFrame();
260
	exit();
261
}
241 262

  
242 263
print "Content-type: text/html\n\n";
243 264

  
244
if ($FORM::stage =~ "guide") {
245
    # Send back the information on how to fill the form
246
    $$templateVars{'section'} = "Guide on How to Complete Registry Entries";
247
    $template->process($templates->{'guide'}, $templateVars);
248
    exit();
265
if ( $FORM::stage =~ "guide" ) {
249 266

  
250
} elsif ($FORM::stage =~ "insert") {
251
    # The user has entered the data. Do data validation and send back data 
252
    # to confirm the data that has been entered. 
253
    toConfirmData();
254
    exit();
267
	# Send back the information on how to fill the form
268
	$$templateVars{'section'} = "Guide on How to Complete Registry Entries";
269
	$template->process( $templates->{'guide'}, $templateVars );
270
	exit();
255 271

  
256
} elsif ($FORM::dataWrong =~ "No, go back to editing" && $FORM::stage =~ "confirmed") {
257
    # The user wants to correct the data that he has entered. 
258
    # Hence show the data again in entryData form. 
259
    confirmDataToReEntryData();
260
    exit();
272
}
273
elsif ( $FORM::stage =~ "insert" ) {
261 274

  
262
} elsif ($FORM::stage =~ "modify") {
263
    # Modification of a file has been requested. 
264
    # check if the user is logged in...
265
    my $session = CGI::Session->load() or die CGI::Session->errstr();
266
    if ($session->is_empty) {
267
        # no session found ... redirect to login page template
268
        $$templateVars{'message'} = 'You must login to modify your dataset.';
269
        $template->process($templates->{'login'}, $templateVars);
270
    } else {
271
        # Show the form will all the values filled in.
272
        my @sortedSites;
273
        foreach my $site (sort @sitelist) {
274
            push(@sortedSites, $site);
275
        }
276
        $$templateVars{'siteList'} = \@sortedSites;
277
        $$templateVars{'section'} = "Modification Form";
278
        my ($foundScope, $id, $rev) = split(/\./, $FORM::docid);
279
        if (! $rev) {
280
        	my $metacat = Metacat->new($metacatUrl);
281
        	my $lastRev = $metacat->getLastRevision($FORM::docid);
282
        	$$templateVars{'docid'} = $FORM::docid . "." . $lastRev
283
        } else {
284
        	$$templateVars{'docid'} = $FORM::docid;
285
        }
286
        modifyData();
287
    }
288
    exit();
275
	# The user has entered the data. Do data validation and send back data
276
	# to confirm the data that has been entered.
277
	toConfirmData();
278
	exit();
289 279

  
290
} elsif ($FORM::stage =~ "delete_confirm") {
280
}
281
elsif ($FORM::dataWrong =~ "No, go back to editing"
282
	&& $FORM::stage =~ "confirmed" )
283
{
291 284

  
292
    # Result from deleteData form. 
293
    if ($FORM::deleteData =~ "Delete document") {
294
        # delete Data
295
        deleteData(1);
296
        exit();
297
    } else {
298
        $$templateVars{'status'} = "Cancel";
299
        $$templateVars{'function'} = "cancel";
300
        $template->process($templates->{'response'}, $templateVars);
301
        exit();
302
    }
285
	# The user wants to correct the data that he has entered.
286
	# Hence show the data again in entryData form.
287
	confirmDataToReEntryData();
288
	exit();
303 289

  
304
} elsif ($FORM::stage =~ "delete") {
305
    # Deletion of a file has been requested. 
306
    # Ask for username and password using deleteDataForm
307
    $$templateVars{'docid'} = $FORM::docid;
308
    $template->process($templates->{'deleteData'}, $templateVars);
309
    exit();
290
}
291
elsif ( $FORM::stage =~ "modify" ) {
292
	#debug("in modify stage");
293
	# Modification of a file has been requested.
294
	# check if the user is logged in...
295
	my $session = CGI::Session->load() or die CGI::Session->errstr();
296
	if ( $session->is_empty ) {
310 297

  
311
} elsif ($FORM::stage !~ "confirmed") {
312
    # None of the stages have been reached and data is not being confirmed. 
298
		# no session found ... redirect to login page template
299
		$$templateVars{'message'} = 'You must login to modify your dataset.';
300
		$template->process( $templates->{'login'}, $templateVars );
301
	}
302
	else {
313 303

  
314
    # check if the user is logged in...
315
    my $session = CGI::Session->load() or die CGI::Session->errstr();
316
    if ($session->is_empty) {
317
        # no session found ... redirect to login page template
318
        $$templateVars{'showInstructions'} = 'true';
319
        $$templateVars{'message'} = 'You must login to register your dataset.';
320
        $template->process($templates->{'login'}, $templateVars);
321
    } else {
304
		# Show the form will all the values filled in.
305
		my @sortedSites;
306
		foreach my $site ( sort @sitelist ) {
307
			push( @sortedSites, $site );
308
		}
309
		$$templateVars{'siteList'} = \@sortedSites;
310
		$$templateVars{'section'}  = "Modification Form";
311
		my ( $foundScope, $id, $rev ) = split( /\./, $FORM::docid );
312
		if ( !$rev ) {
313
			my $metacat = Metacat->new($metacatUrl);
314
			my $lastRev = $metacat->getLastRevision($FORM::docid);
315
			$$templateVars{'docid'} = $FORM::docid . "." . $lastRev;
316
		}
317
		else {
318
			$$templateVars{'docid'} = $FORM::docid;
319
		}
320
		modifyData();
321
	}
322
	exit();
322 323

  
323
        # Hence, send back entry form for entry of data.  
324
        debug("Sending form");
325
        my @sortedSites;
326
        foreach my $site (sort @sitelist) {
327
            push(@sortedSites, $site);
328
        }
324
}
325
elsif ( $FORM::stage =~ "delete_confirm" ) {
329 326

  
330
        if ($skinName eq 'nceas') {
331
            my $projects = getProjectList($properties);
332
            $$templateVars{'projects'} = $projects;
333
            $$templateVars{'wg'} = \@FORM::wg;
334
        }
327
	# Result from deleteData form.
328
	if ( $FORM::deleteData =~ "Delete document" ) {
335 329

  
336
        $$templateVars{'modules'} = $modules;
337
        $$templateVars{'required'} = $required;
338
        $$templateVars{'templates'} = $templates;
339
        $$templateVars{'show'} = $show;
340
        $$templateVars{'site'} = $config->{'site'};
330
		# delete Data
331
		deleteData(1);
332
		exit();
333
	}
334
	else {
335
		$$templateVars{'status'}   = "Cancel";
336
		$$templateVars{'function'} = "cancel";
337
		$template->process( $templates->{'response'}, $templateVars );
338
		exit();
339
	}
341 340

  
342
        $$templateVars{'siteList'} = \@sortedSites;
343
        $$templateVars{'section'} = "Entry Form";
344
        $$templateVars{'docid'} = "";
345
        debug("Sending form: ready to process template");
346
        $template->process($templates->{'entry'}, $templateVars);
347
        debug("Sending form: template processed");
348
   }
349
   exit();
350 341
}
342
elsif ( $FORM::stage =~ "delete" ) {
351 343

  
352
# Confirm stage has been reached. Enter the data into metacat. 
344
	# Deletion of a file has been requested.
345
	# Ask for username and password using deleteDataForm
346
	$$templateVars{'docid'} = $FORM::docid;
347
	$template->process( $templates->{'deleteData'}, $templateVars );
348
	exit();
353 349

  
350
}
351
elsif ( $FORM::stage !~ "confirmed" ) {
352

  
353
	# None of the stages have been reached and data is not being confirmed.
354

  
355
	# check if the user is logged in...
356
	my $session = CGI::Session->load() or die CGI::Session->errstr();
357
	if ( $session->is_empty ) {
358

  
359
		# no session found ... redirect to login page template
360
		$$templateVars{'showInstructions'} = 'true';
361
		$$templateVars{'message'} = 'You must login to register your dataset.';
362
		$template->process( $templates->{'login'}, $templateVars );
363
	}
364
	else {
365

  
366
		# Hence, send back entry form for entry of data.
367
		debug("Sending form");
368
		my @sortedSites;
369
		foreach my $site ( sort @sitelist ) {
370
			push( @sortedSites, $site );
371
		}
372

  
373
		if ( $skinName eq 'nceas' ) {
374
			my $projects = getProjectList($properties);
375
			$$templateVars{'projects'} = $projects;
376
			$$templateVars{'wg'}       = \@FORM::wg;
377
		}
378

  
379
		$$templateVars{'modules'}   = $modules;
380
		$$templateVars{'required'}  = $required;
381
		$$templateVars{'templates'} = $templates;
382
		$$templateVars{'show'}      = $show;
383
		$$templateVars{'site'}      = $config->{'site'};
384

  
385
		$$templateVars{'siteList'} = \@sortedSites;
386
		$$templateVars{'section'}  = "Entry Form";
387
		$$templateVars{'docid'}    = "";
388
		debug("Sending form: ready to process template");
389
		$template->process( $templates->{'entry'}, $templateVars );
390
		debug("Sending form: template processed");
391
	}
392
	exit();
393
}
394

  
395
# Confirm stage has been reached. Enter the data into metacat.
396

  
354 397
# Initialize some global vars
355
my $latDeg1 = "";
356
my $latMin1 = "";
357
my $latSec1 = "";
358
my $hemisphLat1 = "";
359
my $longDeg1 = "";
360
my $longMin1 = "";
361
my $longSec1 = "";
398
my $latDeg1      = "";
399
my $latMin1      = "";
400
my $latSec1      = "";
401
my $hemisphLat1  = "";
402
my $longDeg1     = "";
403
my $longMin1     = "";
404
my $longSec1     = "";
362 405
my $hemisphLong1 = "";
363
my $latDeg2 = "";
364
my $latMin2 = "";
365
my $latSec2 = "";
366
my $hemisphLat2 = "";
367
my $longDeg2 = "";
368
my $longMin2 = "";
369
my $longSec2 = "";
406
my $latDeg2      = "";
407
my $latMin2      = "";
408
my $latSec2      = "";
409
my $hemisphLat2  = "";
410
my $longDeg2     = "";
411
my $longMin2     = "";
412
my $longSec2     = "";
370 413
my $hemisphLong2 = "";
371
my $modUsername = "";
372
my $modPassword = "";
414
my $modUsername  = "";
415
my $modPassword  = "";
373 416

  
374 417
# validate the input form parameters
375 418
my $invalidParams;
376 419

  
377
if (! $error) {
378
    $invalidParams = validateParameters(1);
379
    if (scalar(@$invalidParams)) {
380
        $$templateVars{'status'} = 'failure';
381
        $$templateVars{'invalidParams'} = $invalidParams;
382
        $error = 1;
383
    }
420
if ( !$error ) {
421
	$invalidParams = validateParameters(1);
422
	if ( scalar(@$invalidParams) ) {
423
		$$templateVars{'status'}        = 'failure';
424
		$$templateVars{'invalidParams'} = $invalidParams;
425
		$error                          = 1;
426
	}
384 427
}
385 428

  
429
my $docid;
386 430

  
387
my $docid;
388 431
# Create a metacat object
389 432
my $metacat = Metacat->new($metacatUrl);
390 433

  
391
if (! $error) {
392
    # Login to metacat
393
    my ($username, $password) = getCredentials();
394
    my $response = $metacat->login($username, $password);
395
    my $errorMessage = "";
434
if ( !$error ) {
396 435

  
397
    # Parameters have been validated and Create the XML document
398
    my $xmldoc = createXMLDocument();
399
    
400
    my $xmldocWithDocID = $xmldoc;
401
    my $errorMessage = "";
436
	# Login to metacat
437
	my ( $username, $password ) = getCredentials();
438
	my $response = $metacat->login( $username, $password );
439
	my $errorMessage = "";
402 440

  
403
    if (! $response) {
404
        debug("No response from Metacat");
405
        push(@errorMessages, $metacat->getMessage());
406
        push(@errorMessages, "Failed during login.\n");
407
        $$templateVars{'status'} = 'login_failure';
408
        $$templateVars{'errorMessages'} = \@errorMessages;
409
        $$templateVars{'docid'} = $docid;
410
        $$templateVars{'cfg'} = $skinName;
411
        $$templateVars{'function'} = "submitted";
412
        $$templateVars{'section'} = "Submission Status";
413
        $template->process($templates->{'response'}, $templateVars);
414
        exit();
415
    } else {
441
	# Parameters have been validated and Create the XML document
442
	my $xmldoc = createXMLDocument();
416 443

  
417
    if ($config->{'adminIsDocOwner'} eq 'true') {
418
        debug("adminIsDocOwner is set.");
419
        $response = $metacat->login($adminUsername, $adminPassword);
420
        if (! $response) {
421
            push(@errorMessages, $metacat->getMessage());
422
            push(@errorMessages, "Failed during login for admin.\n");
423
            $$templateVars{'status'} = 'login_failure';
424
            $$templateVars{'errorMessages'} = \@errorMessages;
425
            $$templateVars{'docid'} = $docid;
426
            $$templateVars{'cfg'} = $skinName;
427
            $$templateVars{'function'} = "submitted";
428
            $$templateVars{'section'} = "Submission Status";
429
            $template->process($templates->{'response'}, $templateVars);
430
            exit();
431
        }
432
    }
444
	my $xmldocWithDocID = $xmldoc;
445
	my $errorMessage    = "";
433 446

  
434
        debug("A");
435
        if ($FORM::docid eq "") {
436
            debug("B1");
437
            # document is being inserted 
438
            my $docStatus = "INCOMPLETE";
439
            while ($docStatus eq "INCOMPLETE") {
440
                $docid = newAccessionNumber($config->{'scope'}, $metacat);
447
	if ( !$response ) {
448
		debug("No response from Metacat");
449
		push( @errorMessages, $metacat->getMessage() );
450
		push( @errorMessages, "Failed during login.\n" );
451
		$$templateVars{'status'}        = 'login_failure';
452
		$$templateVars{'errorMessages'} = \@errorMessages;
453
		$$templateVars{'docid'}         = $docid;
454
		$$templateVars{'cfg'}           = $skinName;
455
		$$templateVars{'function'}      = "submitted";
456
		$$templateVars{'section'}       = "Submission Status";
457
		$template->process( $templates->{'response'}, $templateVars );
458
		exit();
459
	}
460
	else {
441 461

  
442
                $xmldocWithDocID =~ s/docid/$docid/;
443
                debugDoc($xmldocWithDocID);
444
                $docStatus = insertMetadata($xmldocWithDocID, $docid);
445
            }
446
            debug("B2");
447
            if ($docStatus ne "SUCCESS") {
448
                debug("NO SUCCESS");
449
                debug("Message is: $docStatus");
450
                push(@errorMessages, $docStatus);
451
            } else {
452
                deleteRemovedData();
453
            }
462
		if ( $config->{'adminIsDocOwner'} eq 'true' ) {
463
			debug("adminIsDocOwner is set.");
464
			$response = $metacat->login( $adminUsername, $adminPassword );
465
			if ( !$response ) {
466
				push( @errorMessages, $metacat->getMessage() );
467
				push( @errorMessages, "Failed during login for admin.\n" );
468
				$$templateVars{'status'}        = 'login_failure';
469
				$$templateVars{'errorMessages'} = \@errorMessages;
470
				$$templateVars{'docid'}         = $docid;
471
				$$templateVars{'cfg'}           = $skinName;
472
				$$templateVars{'function'}      = "submitted";
473
				$$templateVars{'section'}       = "Submission Status";
474
				$template->process( $templates->{'response'}, $templateVars );
475
				exit();
476
			}
477
		}
454 478

  
455
            debug("B3");
456
        } else {
457
            debug("M1");
479
		debug("A");
480
		if ( $FORM::docid eq "" ) {
481
			debug("B1");
458 482

  
459
            # document is being modified
460
            $docid = incrementRevision($FORM::docid);
483
			# document is being inserted
484
			my $docStatus = "INCOMPLETE";
485
			while ( $docStatus eq "INCOMPLETE" ) {
486
				$docid = newAccessionNumber( $config->{'scope'}, $metacat );
461 487

  
462
            $xmldoc =~ s/docid/$docid/;
463
            debugDoc($xmldoc);
488
				$xmldocWithDocID =~ s/docid/$docid/;
489
				debugDoc($xmldocWithDocID);
490
				$docStatus = insertMetadata( $xmldocWithDocID, $docid );
491
			}
492
			debug("B2");
493
			if ( $docStatus ne "SUCCESS" ) {
494
				debug("NO SUCCESS");
495
				debug("Message is: $docStatus");
496
				push( @errorMessages, $docStatus );
497
			}
498
			else {
499
				deleteRemovedData();
500
			}
464 501

  
465
            my $response = $metacat->update($docid, $xmldoc);
502
			debug("B3");
503
		}
504
		else {
505
			debug("M1");
466 506

  
467
            if (! $response) {
468
                push(@errorMessages, $metacat->getMessage());
469
                push(@errorMessages, "Failed while updating.\n");  
470
            } 
471
                     
472
            debug("M2, $docid");
473
            if (scalar(@errorMessages)) {
474
                debug("Errors defined in modify.");
507
			# document is being modified
508
			$docid = incrementRevision($FORM::docid);
475 509

  
476
                $$templateVars{'docid'} = $FORM::docid;
477
                copyFormToTemplateVars();
478
                $$templateVars{'status'} = 'failure';
479
                $$templateVars{'errorMessages'} = \@errorMessages;
480
                $error = 1;
481
            } else {
482
                deleteRemovedData();
483
                $$templateVars{'docid'} = $docid;
484
                $$templateVars{'cfg'} = $skinName;
485
            }
510
			$xmldoc =~ s/docid/$docid/;
511
			debugDoc($xmldoc);
486 512

  
487
            # Create our HTML response and send it back
488
            $$templateVars{'function'} = "modified";
489
            $$templateVars{'section'} = "Modification Status";
490
            $template->process($templates->{'response'}, $templateVars);
513
			my $response = $metacat->update( $docid, $xmldoc );
491 514

  
492
            exit();
493
        }
494
    }
515
			if ( !$response ) {
516
				push( @errorMessages, $metacat->getMessage() );
517
				push( @errorMessages, "Failed while updating.\n" );
518
			}
519

  
520
			debug("M2, $docid");
521
			if ( scalar(@errorMessages) ) {
522
				debug("Errors defined in modify.");
523

  
524
				$$templateVars{'docid'} = $FORM::docid;
525
				copyFormToTemplateVars();
526
				$$templateVars{'status'}        = 'failure';
527
				$$templateVars{'errorMessages'} = \@errorMessages;
528
				$error                          = 1;
529
			}
530
			else {
531
				deleteRemovedData();
532
				$$templateVars{'docid'} = $docid;
533
				$$templateVars{'cfg'}   = $skinName;
534
			}
535

  
536
			# Create our HTML response and send it back
537
			$$templateVars{'function'} = "modified";
538
			$$templateVars{'section'}  = "Modification Status";
539
			$template->process( $templates->{'response'}, $templateVars );
540

  
541
			# send a notification email to the moderator
542
			if ( hasContent($FORM::cfg) && $FORM::cfg eq 'esa' ) {
543
				my $title               = "";
544
				my $contactEmailAddress = "";
545
				my $contactName         = "";
546
				my $parser              = XML::LibXML->new();
547
				my $parsedDoc           = $parser->parse_string($xmldoc);
548
				$FORM::function = 'modified';
549

  
550
				my $findNodes = $parsedDoc->findnodes('//dataset/title');
551
				if ( $findNodes->size() > 0 ) {
552

  
553
					# found title
554
					my $node = '';
555
					foreach $node ( $findNodes->get_nodelist ) {
556
						$title = findValue( $node, '../title' );
557
					}
558
				}
559

  
560
				$findNodes = $parsedDoc->findnodes('//dataset/contact');
561
				if ( $findNodes->size() > 0 ) {
562

  
563
					# found contact email address
564
					my $node = '';
565
					foreach $node ( $findNodes->get_nodelist ) {
566
						my $surName =
567
						  findValue( $node, 'individualName/surName' );
568
						my $givenName =
569
						  findValue( $node, 'individualName/givenName' );
570
						my $organizationName =
571
						  findValue( $node, 'organizationName' );
572

  
573
						if ( $surName ne '' ) {
574
							$contactName = $givenName . ' ' . $surName;
575
						}
576
						else {
577
							$contactName = $organizationName;
578
						}
579
					}
580
				}
581

  
582
				$FORM::docid = $docid;
583

  
584
				modSendNotification( $title, $contactEmailAddress, $contactName,
585
					"Document $docid modification review pending" );
586
			}
587
			exit();
588
		}
589
	}
590

  
591
	if ( hasContent($FORM::cfg) && $FORM::cfg eq 'esa' ) {
592
		my $title               = "";
593
		my $contactEmailAddress = "";
594
		my $contactName         = "";
595
		my $parser              = XML::LibXML->new();
596
		my $parsedDoc           = $parser->parse_string($xmldoc);
597

  
598
		my $findNodes = $parsedDoc->findnodes('//dataset/title');
599
		if ( $findNodes->size() > 0 ) {
600

  
601
			# found title
602
			my $node = '';
603
			foreach $node ( $findNodes->get_nodelist ) {
604
				$title = findValue( $node, '../title' );
605
			}
606
		}
607

  
608
		$findNodes = $parsedDoc->findnodes('//dataset/contact');
609
		if ( $findNodes->size() > 0 ) {
610

  
611
			# found contact email address
612
			my $node = '';
613
			foreach $node ( $findNodes->get_nodelist ) {
614
				$contactEmailAddress = findValue( $node, 'electronicMailAddress' );
615
				my $surName   = findValue( $node, 'individualName/surName' );
616
				my $givenName = findValue( $node, 'individualName/givenName' );
617
				my $organizationName = findValue( $node, 'organizationName' );
618

  
619
				if ( $surName ne '' ) {
620
					$contactName = $givenName . ' ' . $surName;
621
				}
622
				else {
623
					$contactName = $organizationName;
624
				}
625
			}
626
		}
627
		$FORM::docid = $docid;
628

  
629
		modSendNotification( $title, $contactEmailAddress, $contactName,
630
			"Document $docid review pending" );
631
	}
495 632
}
496 633

  
497 634
debug("C");
498 635

  
499
if (scalar(@errorMessages)) {
500
    debug("ErrorMessages defined.");
501
    $$templateVars{'docid'} = $FORM::docid;
502
    copyFormToTemplateVars();
503
    $$templateVars{'status'} = 'failure';
504
    $$templateVars{'errorMessages'} = \@errorMessages;
505
    $error = 1;
506
} else {
507
    $$templateVars{'docid'} = $docid;
508
    $$templateVars{'cfg'} = $skinName;
509
    # delete the remaining file objects from disk
510
    for (my $fileNum = 0; $fileNum <= $FORM::upCount; $fileNum++) {
511
        my $fn = 'uploadname_' . $fileNum;
512
        if (hasContent(param($fn))) {
513
            deleteFile(param($fn));
514
        }
515
    }
516
    
636
if ( scalar(@errorMessages) ) {
637
	debug("ErrorMessages defined.");
638
	$$templateVars{'docid'} = $FORM::docid;
639
	copyFormToTemplateVars();
640
	$$templateVars{'status'}        = 'failure';
641
	$$templateVars{'errorMessages'} = \@errorMessages;
642
	$error                          = 1;
517 643
}
644
else {
645
	$$templateVars{'docid'} = $docid;
646
	$$templateVars{'cfg'}   = $skinName;
518 647

  
648
	# delete the remaining file objects from disk
649
	for ( my $fileNum = 0 ; $fileNum <= $FORM::upCount ; $fileNum++ ) {
650
		my $fn = 'uploadname_' . $fileNum;
651
		if ( hasContent( param($fn) ) ) {
652
			deleteFile( param($fn) );
653
		}
654
	}
655

  
656
}
657

  
519 658
# Create our HTML response and send it back
520 659
$$templateVars{'function'} = "submitted";
521
$$templateVars{'section'} = "Submission Status";
660
$$templateVars{'section'}  = "Submission Status";
522 661

  
523
$template->process($templates->{'response'}, $templateVars);
662
$template->process( $templates->{'response'}, $templateVars );
524 663

  
525 664
exit();
526 665

  
......
530 669
#
531 670
################################################################################
532 671
sub insertMetadata {
533
  my $xmldoc = shift;
534
  my $docid = shift;
672
	my $xmldoc = shift;
673
	my $docid  = shift;
535 674

  
536
  debug("Trying to insert the following document");
537
  my $docStatus = "SUCCESS";
538
  debug("Starting insert (D1)");
675
	debug("Trying to insert the following document");
676
	my $docStatus = "SUCCESS";
677
	debug("Starting insert (D1)");
539 678

  
540
  my $response = $metacat->insert($docid, $xmldoc);
541
  if (! $response) {
542
    debug("Response gotten (D2)");
543
    my $errormsg = $metacat->getMessage();i
544
    debug("Error is (D3): " . $errormsg);
545
    if ($errormsg =~ /is already in use/) {
546
        $docStatus = "INCOMPLETE";
547
    } elsif ($errormsg =~ /<login>/) {
548
        $docStatus = "SUCCESS";
549
    } else { 
550
        $docStatus = $errormsg;
551
    }
552
  }
553
  debug("Ending insert (D4)");
679
	my $response = $metacat->insert( $docid, $xmldoc );
680
	if ( !$response ) {
681
		debug("Response gotten (D2)");
682
		my $errormsg = $metacat->getMessage();
683
		i debug( "Error is (D3): " . $errormsg );
684
		if ( $errormsg =~ /is already in use/ ) {
685
			$docStatus = "INCOMPLETE";
686
		}
687
		elsif ( $errormsg =~ /<login>/ ) {
688
			$docStatus = "SUCCESS";
689
		}
690
		else {
691
			$docStatus = $errormsg;
692
		}
693
	}
694
	debug("Ending insert (D4)");
554 695

  
555
  return $docStatus;
696
	return $docStatus;
556 697
}
557 698

  
558 699
################################################################################
......
562 703
#  Also: need to check metacat for max id # used in this scope already
563 704
################################################################################
564 705
sub newAccessionNumber {
565
    my $scope = shift;
566
    my $metacat = shift;
567
    my $errormsg = 0;
706
	my $scope    = shift;
707
	my $metacat  = shift;
708
	my $errormsg = 0;
568 709

  
569
    my $docid = $metacat->getLastId($scope);
570
    if (!$docid) {
571
        $docid = "$scope.1.1";
572
        debug("Error in newAccessionNumber: " . $metacat->getMessage());
573
    } else {
574
        my ($foundScope, $id, $rev) = split(/\./, $docid);
575
        $id++;
576
        $docid = "$scope.$id.1";
577
    }
578
    debug("Metcat handed us a new docid: $docid");
579
    return $docid;
710
	my $docid = $metacat->getLastId($scope);
711
	if ( !$docid ) {
712
		$docid = "$scope.1.1";
713
		debug( "Error in newAccessionNumber: " . $metacat->getMessage() );
714
	}
715
	else {
716
		my ( $foundScope, $id, $rev ) = split( /\./, $docid );
717
		$id++;
718
		$docid = "$scope.$id.1";
719
	}
720
	debug("Metcat handed us a new docid: $docid");
721
	return $docid;
580 722
}
581 723

  
582 724
sub incrementRevision {
583
    my $initDocid = shift;
584
    my $docid = '';
585
    if (!$initDocid) {
586
        debug("No docid entered.");
587
    } else {
588
        my ($scope, $id, $rev) = split(/\./, $initDocid);
589
        $rev++;
590
        $docid = "$scope.$id.$rev";
591
    }
592
    return $docid;
725
	my $initDocid = shift;
726
	my $docid     = '';
727
	if ( !$initDocid ) {
728
		debug("No docid entered.");
729
	}
730
	else {
731
		my ( $scope, $id, $rev ) = split( /\./, $initDocid );
732
		$rev++;
733
		$docid = "$scope.$id.$rev";
734
	}
735
	return $docid;
593 736
}
594 737

  
595 738
################################################################################
596
# 
739
#
597 740
# Validate the parameters to make sure that required params are provided
598 741
#
599 742
################################################################################
600 743
sub validateParameters {
601
    my $chkUser = shift;
602
    my @invalidParams;
744
	my $chkUser = shift;
745
	my @invalidParams;
603 746

  
604
    push(@invalidParams, "Name of the Project is not selected in the form.")
605
        if (scalar(@FORM::wg) == 0 && $required->{'wgList'} eq 'true');
606
    push(@invalidParams, "First name of person entering the form is missing.")
607
        unless hasContent($FORM::providerGivenName);
608
    push(@invalidParams, "Last name of person entering the form is missing.")
609
        unless hasContent($FORM::providerSurName);
610
    push(@invalidParams, "Dataset title is missing.")
611
        unless hasContent($FORM::title);
612
    push(@invalidParams, ucfirst($config->{'site'})." name is missing.")
613
        unless ((hasContent($FORM::site) && !($FORM::site =~ /^Select/)) ||
614
                $skinName eq "nceas");
615
    push(@invalidParams, "First name of principal data set owner is missing.")
616
        unless hasContent($FORM::origNamefirst0);
617
    push(@invalidParams, "Last name of principal data set owner is missing.")
618
        unless hasContent($FORM::origNamelast0);
619
    push(@invalidParams, "Dataset abstract is missing.")
620
        unless hasContent($FORM::abstract);
621
    if ($modules->{'temporal'} eq 'true') {
622
        push(@invalidParams, "Year of start date is missing.")
623
            unless (hasContent($FORM::beginningYear) || $required->{'temporal'} ne 'true');
624
        push(@invalidParams, "Year of stop date has been specified but year of start date is missing.")
625
            if ((!hasContent($FORM::beginningYear)) && hasContent($FORM::endingYear));
626
    }
627
    push(@invalidParams, "Geographic description is missing.")
628
        unless (hasContent($FORM::geogdesc) || $required->{'spatial'} ne 'true');
747
	push( @invalidParams, "Name of the Project is not selected in the form." )
748
	  if ( scalar(@FORM::wg) == 0 && $required->{'wgList'} eq 'true' );
749
	push( @invalidParams, "First name of person entering the form is missing." )
750
	  unless hasContent($FORM::providerGivenName);
751
	push( @invalidParams, "Last name of person entering the form is missing." )
752
	  unless hasContent($FORM::providerSurName);
753
	push( @invalidParams, "Dataset title is missing." )
754
	  unless hasContent($FORM::title);
755
	push( @invalidParams, ucfirst( $config->{'site'} ) . " name is missing." )
756
	  unless ( ( hasContent($FORM::site) && !( $FORM::site =~ /^Select/ ) )
757
		|| $skinName eq "nceas" );
758
	push( @invalidParams, "First name of principal data set owner is missing." )
759
	  unless hasContent($FORM::origNamefirst0);
760
	push( @invalidParams, "Last name of principal data set owner is missing." )
761
	  unless hasContent($FORM::origNamelast0);
762
	push( @invalidParams, "Dataset abstract is missing." )
763
	  unless hasContent($FORM::abstract);
629 764

  
630
    if ($FORM::beginningMonth eq "MM") {
631
        $FORM::beginningMonth = "";
632
    }
633
    if ($FORM::beginningDay eq "DD") {
634
        $FORM::beginningDay = "";
635
    }
636
    if ($FORM::endingMonth eq "MM") {
637
        $FORM::endingMonth = "";
638
    }
639
    if ($FORM::endingDay eq "DD") {
640
        $FORM::endingDay = "";
641
    }
765
	if ( $modules->{'temporal'} eq 'true' ) {
766
		push( @invalidParams, "Year of start date is missing." )
767
		  unless ( hasContent($FORM::beginningYear)
768
			|| $required->{'temporal'} ne 'true' );
769
		push( @invalidParams,
770
"Year of stop date has been specified but year of start date is missing."
771
		  )
772
		  if ( ( !hasContent($FORM::beginningYear) )
773
			&& hasContent($FORM::endingYear) );
774
	}
775
	push( @invalidParams, "Geographic description is missing." )
776
	  unless ( hasContent($FORM::geogdesc)
777
		|| $required->{'spatial'} ne 'true' );
642 778

  
643
    if (hasContent($FORM::beginningYear) && !($FORM::beginningYear =~ /[0-9]{4}/)) {
644
        push(@invalidParams, "Invalid year of start date specified.")
645
    }
779
	if ( $FORM::beginningMonth eq "MM" ) {
780
		$FORM::beginningMonth = "";
781
	}
782
	if ( $FORM::beginningDay eq "DD" ) {
783
		$FORM::beginningDay = "";
784
	}
785
	if ( $FORM::endingMonth eq "MM" ) {
786
		$FORM::endingMonth = "";
787
	}
788
	if ( $FORM::endingDay eq "DD" ) {
789
		$FORM::endingDay = "";
790
	}
646 791

  
647
    if (hasContent($FORM::endingYear) && !($FORM::endingYear =~ /[0-9]{4}/)) {
648
        push(@invalidParams, "Invalid year of stop date specified.")
649
    }
792
	if ( hasContent($FORM::beginningYear)
793
		&& !( $FORM::beginningYear =~ /[0-9]{4}/ ) )
794
	{
795
		push( @invalidParams, "Invalid year of start date specified." );
796
	}
650 797

  
651
    # If the "use site" coord. box is checked and if the site is in 
652
    # the longitude hash ...  && ($siteLatDMS{$FORM::site})
798
	if ( hasContent($FORM::endingYear) && !( $FORM::endingYear =~ /[0-9]{4}/ ) )
799
	{
800
		push( @invalidParams, "Invalid year of stop date specified." );
801
	}
653 802

  
654
    if ($modules->{'spatial'} eq 'true') {
655
        if (($FORM::useSiteCoord) && ($siteLatDMS{$FORM::site})) {
656
            $latDeg1 = $siteLatDMS{$FORM::site}[0];
657
            $latMin1 = $siteLatDMS{$FORM::site}[1];
658
            $latSec1 = $siteLatDMS{$FORM::site}[2];
659
            $hemisphLat1 = $siteLatDMS{$FORM::site}[3];
660
            $longDeg1 = $siteLongDMS{$FORM::site}[0];
661
            $longMin1 = $siteLongDMS{$FORM::site}[1];
662
            $longSec1 = $siteLongDMS{$FORM::site}[2];
663
            $hemisphLong1 = $siteLongDMS{$FORM::site}[3];
664
        }  else {
665
            $latDeg1 = $FORM::latDeg1;
666
            $latMin1 = $FORM::latMin1;
667
            $latSec1 = $FORM::latSec1;
668
            $hemisphLat1 = $FORM::hemisphLat1;
669
            $longDeg1 = $FORM::longDeg1;
670
            $longMin1 = $FORM::longMin1;
671
            $longSec1 = $FORM::longSec1;
672
            $hemisphLong1 = $FORM::hemisphLong1;
673
        }
803
	# If the "use site" coord. box is checked and if the site is in
804
	# the longitude hash ...  && ($siteLatDMS{$FORM::site})
674 805

  
675
        if ($latDeg1 > 90 || $latDeg1 < 0) {
676
            push(@invalidParams, "Invalid first latitude degrees specified.");
677
        }
678
        if ($latMin1 > 59 || $latMin1 < 0) {
679
            push(@invalidParams, "Invalid first latitude minutes specified.");
680
        }
681
        if ($latSec1 > 59 || $latSec1 < 0) {
682
            push(@invalidParams, "Invalid first latitude seconds specified.");
683
        }
684
        if ($longDeg1 > 180 || $longDeg1 < 0) {
685
            push(@invalidParams, "Invalid first longitude degrees specified.");
686
        }
687
        if ($longMin1 > 59 || $longMin1 < 0) {
688
            push(@invalidParams, "Invalid first longitude minutes specified.");
689
        }
690
        if ($longSec1 > 59 || $longSec1 < 0) {
691
            push(@invalidParams, "Invalid first longitude seconds specified.");
692
        }
806
	if ( $modules->{'spatial'} eq 'true' ) {
807
		if ( ($FORM::useSiteCoord) && ( $siteLatDMS{$FORM::site} ) ) {
808
			$latDeg1      = $siteLatDMS{$FORM::site}[0];
809
			$latMin1      = $siteLatDMS{$FORM::site}[1];
810
			$latSec1      = $siteLatDMS{$FORM::site}[2];
811
			$hemisphLat1  = $siteLatDMS{$FORM::site}[3];
812
			$longDeg1     = $siteLongDMS{$FORM::site}[0];
813
			$longMin1     = $siteLongDMS{$FORM::site}[1];
814
			$longSec1     = $siteLongDMS{$FORM::site}[2];
815
			$hemisphLong1 = $siteLongDMS{$FORM::site}[3];
816
		}
817
		else {
818
			$latDeg1      = $FORM::latDeg1;
819
			$latMin1      = $FORM::latMin1;
820
			$latSec1      = $FORM::latSec1;
821
			$hemisphLat1  = $FORM::hemisphLat1;
822
			$longDeg1     = $FORM::longDeg1;
823
			$longMin1     = $FORM::longMin1;
824
			$longSec1     = $FORM::longSec1;
825
			$hemisphLong1 = $FORM::hemisphLong1;
826
		}
693 827

  
694
        if (hasContent($FORM::latDeg2) && ($FORM::latDeg2 > 90 || $FORM::latDeg2 < 0)) {
695
            push(@invalidParams, "Invalid second latitude degrees specified.");
696
        }
697
        if (hasContent($FORM::latMin2) && ($FORM::latMin2 > 59 || $FORM::latMin2 < 0)) {
698
            push(@invalidParams, "Invalid second latitude minutes specified.");
699
        }
700
        if (hasContent($FORM::latSec2) && ($FORM::latSec2 > 59 || $FORM::latSec2 < 0)) {
701
            push(@invalidParams, "Invalid second latitude seconds specified.");
702
        }
703
        if (hasContent($FORM::latDeg2) && ($FORM::longDeg2 > 180 || $FORM::longDeg2 < 0)) {
704
            push(@invalidParams, "Invalid second longitude degrees specified.");
705
        }
706
        if (hasContent($FORM::latMin2) && ($FORM::longMin2 > 59 || $FORM::longMin2 < 0)) {
707
            push(@invalidParams, "Invalid second longitude minutes specified.");
708
        }
709
        if (hasContent($FORM::latSec2) && ($FORM::longSec2 > 59 || $FORM::longSec2 < 0)) {
710
            push(@invalidParams, "Invalid second longitude seconds specified.");
711
        }
712
    }
828
		if ( $latDeg1 > 90 || $latDeg1 < 0 ) {
829
			push( @invalidParams, "Invalid first latitude degrees specified." );
830
		}
831
		if ( $latMin1 > 59 || $latMin1 < 0 ) {
832
			push( @invalidParams, "Invalid first latitude minutes specified." );
833
		}
834
		if ( $latSec1 > 59 || $latSec1 < 0 ) {
835
			push( @invalidParams, "Invalid first latitude seconds specified." );
836
		}
837
		if ( $longDeg1 > 180 || $longDeg1 < 0 ) {
838
			push( @invalidParams,
839
				"Invalid first longitude degrees specified." );
840
		}
841
		if ( $longMin1 > 59 || $longMin1 < 0 ) {
842
			push( @invalidParams,
843
				"Invalid first longitude minutes specified." );
844
		}
845
		if ( $longSec1 > 59 || $longSec1 < 0 ) {
846
			push( @invalidParams,
847
				"Invalid first longitude seconds specified." );
848
		}
713 849

  
714
    # Check if latDeg1 and longDeg1 has values if useSiteCoord is used. 
715
    # This check is required because some of the sites dont have lat 
716
    # and long mentioned in the config file. 
850
		if ( hasContent($FORM::latDeg2)
851
			&& ( $FORM::latDeg2 > 90 || $FORM::latDeg2 < 0 ) )
852
		{
853
			push( @invalidParams,
854
				"Invalid second latitude degrees specified." );
855
		}
856
		if ( hasContent($FORM::latMin2)
857
			&& ( $FORM::latMin2 > 59 || $FORM::latMin2 < 0 ) )
858
		{
859
			push( @invalidParams,
860
				"Invalid second latitude minutes specified." );
861
		}
862
		if ( hasContent($FORM::latSec2)
863
			&& ( $FORM::latSec2 > 59 || $FORM::latSec2 < 0 ) )
864
		{
865
			push( @invalidParams,
866
				"Invalid second latitude seconds specified." );
867
		}
868
		if ( hasContent($FORM::latDeg2)
869
			&& ( $FORM::longDeg2 > 180 || $FORM::longDeg2 < 0 ) )
870
		{
871
			push( @invalidParams,
872
				"Invalid second longitude degrees specified." );
873
		}
874
		if ( hasContent($FORM::latMin2)
875
			&& ( $FORM::longMin2 > 59 || $FORM::longMin2 < 0 ) )
876
		{
877
			push( @invalidParams,
878
				"Invalid second longitude minutes specified." );
879
		}
880
		if ( hasContent($FORM::latSec2)
881
			&& ( $FORM::longSec2 > 59 || $FORM::longSec2 < 0 ) )
882
		{
883
			push( @invalidParams,
884
				"Invalid second longitude seconds specified." );
885
		}
886
	}
717 887

  
888
	# Check if latDeg1 and longDeg1 has values if useSiteCoord is used.
889
	# This check is required because some of the sites dont have lat
890
	# and long mentioned in the config file.
718 891

  
719
    if ($modules->{'spatial'} eq 'true' && $required->{'spatial'} eq 'true') {
720
        if ($FORM::useSiteCoord) {
721
            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.")
722
                unless(hasContent($latDeg1) && hasContent($longDeg1));
723
        } else {
724
            push(@invalidParams, "Latitude degrees are missing.")
725
                unless (hasContent($latDeg1) || $required->{'spatial'} ne 'true');
726
            push(@invalidParams, "Longitude degrees are missing.")
727
                unless (hasContent($longDeg1) || $required->{'spatial'} ne 'true');
728
        }
729
        push(@invalidParams, 
730
            "You must provide a geographic description if you provide latitude and longitude information.")
731
            if ((hasContent($latDeg1) || (hasContent($longDeg1))) && (!hasContent($FORM::geogdesc)));
732
    }
892
	if ( $modules->{'spatial'} eq 'true' && $required->{'spatial'} eq 'true' ) {
893
		if ($FORM::useSiteCoord) {
894
			push( @invalidParams,
895
"The Data Registry doesn't have latitude and longitude information for the site that you chose. Please go back and enter the spatial information."
896
			) unless ( hasContent($latDeg1) && hasContent($longDeg1) );
897
		}
898
		else {
899
			push( @invalidParams, "Latitude degrees are missing." )
900
			  unless ( hasContent($latDeg1)
901
				|| $required->{'spatial'} ne 'true' );
902
			push( @invalidParams, "Longitude degrees are missing." )
903
			  unless ( hasContent($longDeg1)
904
				|| $required->{'spatial'} ne 'true' );
905
		}
906
		push( @invalidParams,
907
"You must provide a geographic description if you provide latitude and longitude information."
908
		  )
909
		  if ( ( hasContent($latDeg1) || ( hasContent($longDeg1) ) )
910
			&& ( !hasContent($FORM::geogdesc) ) );
911
	}
733 912

  
734
    if ($modules->{'method'} eq 'true') {
735
    push (@invalidParams, 
736
        "You must provide a method description if you provide a method title.")
737
        if (hasContent($FORM::methodTitle) && (!(scalar(@FORM::methodPara) > 0) 
738
            || (! hasContent($FORM::methodPara[0]))));
739
    push(@invalidParams, 
740
        "You must provide a method description if you provide an extent of study description.")
741
        if (hasContent($FORM::studyExtentDescription) && (!(scalar(@FORM::methodPara) > 0) 
742
            || (! hasContent($FORM::methodPara[0]))));
743
    push(@invalidParams, 
744
        "You must provide both an extent of study description and a sampling description, or neither.")
745
        if ((hasContent($FORM::studyExtentDescription) && !hasContent($FORM::samplingDescription)) ||
746
            (!hasContent($FORM::studyExtentDescription) && hasContent($FORM::samplingDescription)));
747
    }
748
    
749
    if ($modules->{'upload'} eq 'true') {
750
        for (my $upNum = 0; $upNum <= $FORM::upCount; $upNum++) {
751
            my $upn = "upload_$upNum";
752
            if (hasContent(param($upn)) && !grep {$_ eq ("uploadname_$upNum")} @FORM::deletefile) {
753
                push(@invalidParams, "Must select a permission for file " . param("uploadname_$upNum"))
754
                if (!hasContent(param("uploadperm_$upNum")));
755
            }
756
        }
757
    }
758
 
759
    push(@invalidParams, "First name of data set contact is missing.")
760
    unless (hasContent($FORM::origNamefirstContact) || 
761
        $FORM::useOrigAddress);
762
    push(@invalidParams, "Last name of data set contact is missing.")
763
    unless (hasContent($FORM::origNamelastContact) || 
764
        $FORM::useOrigAddress);
765
    if ($required->{'contactEmailAddress'} eq 'true') {
766
        if ($FORM::useOrigAddress) {
767
        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.")
768
            unless (hasContent($FORM::origEmail));
769
        } else {
770
            push(@invalidParams, "Email address of data set contact is missing.")
771
                unless (hasContent($FORM::origEmailContact));
772
        }
773
    }
913
	if ( $modules->{'method'} eq 'true' ) {
914
		push( @invalidParams,
915
"You must provide a method description if you provide a method title."
916
		  )
917
		  if (
918
			hasContent($FORM::methodTitle)
919
			&& (  !( scalar(@FORM::methodPara) > 0 )
920
				|| ( !hasContent( $FORM::methodPara[0] ) ) )
921
		  );
922
		push( @invalidParams,
923
"You must provide a method description if you provide an extent of study description."
924
		  )
925
		  if (
926
			hasContent($FORM::studyExtentDescription)
927
			&& (  !( scalar(@FORM::methodPara) > 0 )
928
				|| ( !hasContent( $FORM::methodPara[0] ) ) )
929
		  );
930
		push( @invalidParams,
931
"You must provide both an extent of study description and a sampling description, or neither."
932
		  )
933
		  if (
934
			(
935
				hasContent($FORM::studyExtentDescription)
936
				&& !hasContent($FORM::samplingDescription)
937
			)
938
			|| (  !hasContent($FORM::studyExtentDescription)
939
				&& hasContent($FORM::samplingDescription) )
940
		  );
941
	}
774 942

  
775
    # check required distribution elements
776
    push(@invalidParams, "Data medium is required.")
777
    unless (hasContent($FORM::dataMedium));
778
    if ($FORM::dataMedium eq 'other') {
779
        push(@invalidParams, "Must enter custom data medium when 'other' is selected.")
780
        unless (hasContent($FORM::dataMediumOther));
781
    }
782
    push(@invalidParams, "Usage rights are required.")
783
    unless (hasContent($FORM::useConstraints));
784
    if ($FORM::useConstraints eq 'other') {
785
        push(@invalidParams, "Must enter custom usage rights when 'other' is selected.")
786
        unless (hasContent($FORM::useConstraintsOther));
787
    }
943
	if ( $modules->{'upload'} eq 'true' ) {
944
		for ( my $upNum = 0 ; $upNum <= $FORM::upCount ; $upNum++ ) {
945
			my $upn = "upload_$upNum";
946
			if ( hasContent( param($upn) )
947
				&& !grep { $_ eq ("uploadname_$upNum") } @FORM::deletefile )
948
			{
949
				push( @invalidParams,
950
					"Must select a permission for file "
951
					  . param("uploadname_$upNum") )
952
				  if ( !hasContent( param("uploadperm_$upNum") ) );
953
			}
954
		}
955
	}
788 956

  
789
    return \@invalidParams;
957
	push( @invalidParams, "First name of data set contact is missing." )
958
	  unless ( hasContent($FORM::origNamefirstContact)
959
		|| $FORM::useOrigAddress );
960
	push( @invalidParams, "Last name of data set contact is missing." )
961
	  unless ( hasContent($FORM::origNamelastContact)
962
		|| $FORM::useOrigAddress );
963
	if ( $required->{'contactEmailAddress'} eq 'true' ) {
964
		if ($FORM::useOrigAddress) {
965
			push( @invalidParams,
966
"Email address of data set owner is missing. This is required as it will be used as contact email address as specified by you."
967
			) unless ( hasContent($FORM::origEmail) );
968
		}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff