%#-- Begin HTML --#
<%perl>
redirect("/admin/manager/user") unless defined $user_id && defined $pref_id;

my $pref = Bric::Util::Pref->lookup({ id => $pref_id});

redirect("/admin/profile/user/$user_id") unless $pref->get_can_be_overridden;

my $user = Bric::Biz::Person::User->lookup({ id => $user_id});

my $user_pref = $class->lookup({ pref_id => $pref_id, user_id => $user_id });

my $no_edit = $user_id == get_user_id || chk_authz($user, EDIT, 1) ? 0 : 1;

$m->comp('/widgets/wrappers/sharky/header.mc',
         title => "$disp Profile",
	 context =>
         "Admin | Profile | User | &quot;" . $user->get_name .
         "&quot; | $disp | " . $pref->get_name,
);
$m->out(qq{<form method="post" name="user_pref_profile" action="} . $r->uri
        . qq{" onsubmit="return confirmChanges(this)">\n});

$m->comp('/widgets/profile/hidden.mc', value => $pref_id, name => 'pref_id');
$m->comp('/widgets/profile/hidden.mc', value => $user_id, name => 'user_id');

my $name = $pref->get_name;

# Set up the select list data.
my $vals = $pref->get_opts_href;
my $c = scalar keys %$vals;

my $opt_type = $pref->get_opt_type;
my ($size, $cols, $rows, $props);

if ($opt_type eq 'text' || $opt_type eq 'password') {
    $size = 128;
} elsif ($opt_type eq 'radio' || $opt_type eq 'select') {
    $size = ($c > 15) ? 10 : 1;
}

$props = {
    type => $opt_type,
    vals => $vals,
};
$props->{size} = $size if defined $size;
# (these are in case textarea is implemented)
$props->{cols} = $cols if defined $cols;
$props->{rows} = $rows if defined $rows;


$m->comp("/widgets/wrappers/sharky/table_top.mc",
	 caption => $name);

$m->comp('/widgets/profile/displayFormElement.mc', key => 'value',
         readOnly => $no_edit,
         vals => { props => $props,
                   disp => 'Value',
                   value => $user_pref ? $user_pref->get_value : $pref->get_value } );

$m->comp("/widgets/wrappers/sharky/table_bottom.mc");

# Output the form buttons.
$m->out("<br />\n");
$m->comp("/widgets/profile/formButtons.mc", type => $type, section => $widget,
   no_del => 1, no_save => $no_edit, widget => $type );

</%perl>
</form>

<& '/widgets/wrappers/sharky/footer.mc', param => \%ARGS &>
%#-- End HTML --#

%#-- Once Section --#
<%once>;
my $class = 'Bric::Util::UserPref';
my $widget = 'profile';
my $type = 'user_pref';
my $disp = get_disp_name($type);
</%once>

%#-- Args Section --#
<%args>
$user_id
</%args>

<%init>
my $pref_id = $ARGS{id};
</%init>

<%doc>
###############################################################################

=head1 NAME

/admin/profile/user_pref/dhandler - Manages per-user preferences

=head1 VERSION

$LastChangedRevision$

=head1 DATE

$LastChangedDate$

=head1 DESCRIPTION

Simple interface for managing per-user preferences.

</%doc>
