# Copyright 2002-2009 Interchange Development Group and others
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.  See the LICENSE file for details.

UserTag run-profile Order   check cgi profile name
UserTag run-profile addAttr
UserTag run-profile Version 1.7
UserTag run-profile Routine <<EOR
sub {
	my ($check, $cgi, $profile, $name, $opt) = @_;
#::logDebug("call check $check");
	my $ref;
	my $pname = $name;

	if ($opt->{ref}) {
		if (ref($opt->{ref}) eq 'HASH') {
			$ref = $opt->{ref};
		}
		else {
			# error message
			::logError("Invalid ref parameter provided for profile %s", $pname || $check);
		}
	}
	elsif ($cgi) {
		$ref = \%CGI::values;
	}
	else {
		$ref = $::Values;
	}

	unless ($pname) {
	    # check scratch for profile if none specified
	    $profile = $Scratch->{"profile_$check"} unless $profile;

    #::logDebug("PROFILE(" . $Tag->var('MV_PAGE',1) . "):***$profile***");
	    # test passes if no profile exists
	    return 1 if ! $profile;

	    $opt->{no_error} = 1 unless defined $opt->{no_error};

	    $pname = 'tmp_profile.' . $Vend::Session->{id};
    #Debug("running check $check, pname=$pname profile=$profile");
	    $profile .= "\n&fatal=1\n";
	    $profile = "&noerror=1\n$profile" if $opt->{no_error};
	    $profile = "&overwrite=1\n$profile" if $opt->{overwrite_error};
	    $::Scratch->{$pname} = $profile;
	}

	my ($status) = ::check_order($pname, $ref);

	delete $::Scratch->{$pname} unless $name;

	return is_yes($opt->{hide}) ? undef : $status;
}
EOR
