[comment]
	Because the checklist has to determine whether all pages are
	complete before we ever get to the table-editor tags on each
	individual page, we collect the wizard form profiles into one
	place here.

	The exceptions are sub-pages that don't appear in the checklist,
	whose profiles are created from the convenient "check.varname"
	attributes passed to the table-editor tag.

	I wouldn't recommend using the 'mandatory' check here; it works
	as expected when checking on 'back' and 'next' submits, but will
	always fail on the checklist. That's the way it's supposed to
	work, but it's easy to forget since these profiles are doing
	double duty.
[/comment]

[set profile_company]
	company=required
	domainname=required
	address=required
	city=required
	state=regex [A-Z][A-Z]
	zip=required
	country=regex [A-Z][A-Z]
[/set]

[set profile_email]
	mailorderto=email
	emailinfo=email
	emailservice=email
[/set]

[seti profile_groupindex]
	[scratch profile_company]
	[scratch profile_email]
[/seti]

[set profile_tax]
	taxlocation=required
	taxrate=required
[/set]

[set profile_ship]
	shipmethod=required
[/set]

[set profile_pay]
	paygate=required
[/set]

[set profile_security]
	adminuser=required
	adminpass=required
	shopuser=required
	shoppass=required
[/set]

[seti profile_grouppolicy]
	[scratch profile_tax]
	[scratch profile_ship]
	[scratch profile_pay]
	[scratch profile_security]
[/seti]

[set profile_products]
	did_products=required
[/set]

[set profile_index]
	indextext=required
[/set]

[set profile_about]
	abouttext=required
[/set]

[seti profile_groupcontent]
	[scratch profile_index]
	[scratch profile_about]
[/seti]

[set profile_finalize]
	finalized=required
[/set]

[set profile_preview]
	site_created=required
[/set]

[set profile_launch]
	orderstart=required
[/set]

[set profile_save_values]
[perl]
	my $fn = "upload/$Session->{username}.wizard";

	my $status = $Tag->log( {
			file => $fn,
			create => 1,
			type => 'text',
			body => $Tag->uneval( { ref => $Values } ),
	});
	if($status) {
		$Scratch->{ui_message} = errmsg(
									"%s values saved successfully.",
									$Config->{CatalogName},
								 );
	}
	else {
		$Scratch->{ui_failure} = errmsg(
									"%s values save failed: %s",
									$Config->{CatalogName},
									$!,
								 );
	}
	return;
[/perl]
[/set]

[set profile_get_values]
[calc]
	$Scratch->{wizard_fn} = "upload/$Session->{username}.wizard";
	$wizard_values = '';
[/calc]
[calc]
	$wizard_values = [file name="[scratch wizard_fn]"];
	return;
[/calc]
[perl]
	if(! $wizard_values or ! ref $wizard_values) {
		$Session->{ui_failure} =
			errmsg("No saved values for %s.", $Config->{CatalogName});
		return;
	}

	my $ref = {};
	my $something_to_save;
	for (keys %$wizard_values) {
		$ref->{$_} = $Values->{$_}
			and $something_to_save++;
		$Values->{$_} = $wizard_values->{$_};
	}

	$Session->{wizard_undo} = [] unless $Session->{wizard_undo};
	push @{ $Session->{wizard_undo} }, $ref if $something_to_save;

	return;
[/perl]
[/set]
