version 1.27, 2003/05/12 19:33:57
|
version 1.31, 2003/05/16 17:20:51
|
Line 53 Each state contains one or more state el
|
Line 53 Each state contains one or more state el
|
messages, resource selections, or date queries. |
messages, resource selections, or date queries. |
|
|
The helper tag is required to have one attribute, "title", which is the name |
The helper tag is required to have one attribute, "title", which is the name |
of the helper itself, such as "Parameter helper". |
of the helper itself, such as "Parameter helper". The helper tag may optionally |
|
have a "requiredpriv" attribute, specifying the priviledge a user must have |
|
to use the helper, or get denied access. See loncom/auth/rolesplain.tab for |
|
useful privs. Default is full access, which is often wrong! |
|
|
=head2 State tags |
=head2 State tags |
|
|
Line 257 sub real_handler {
|
Line 260 sub real_handler {
|
# xml parsing |
# xml parsing |
&Apache::lonxml::xmlparse($r, 'helper', $file); |
&Apache::lonxml::xmlparse($r, 'helper', $file); |
|
|
|
my $allowed = $helper->allowedCheck(); |
|
if (!$allowed) { |
|
$ENV{'user.error.msg'} = $ENV{'request.uri'}.':'.$helper->{REQUIRED_PRIV}. |
|
":0:0:Permission denied to access this helper."; |
|
return HTTP_NOT_ACCEPTABLE; |
|
} |
|
|
$helper->process(); |
$helper->process(); |
|
|
$r->print($helper->display()); |
$r->print($helper->display()); |
return OK; |
return OK; |
} |
} |
|
|
sub registerHelperTags { |
sub registerHelperTags { |
Line 284 sub start_helper {
|
Line 294 sub start_helper {
|
|
|
registerHelperTags(); |
registerHelperTags(); |
|
|
Apache::lonhelper::helper->new($token->[2]{'title'}); |
Apache::lonhelper::helper->new($token->[2]{'title'}, $token->[2]{'requiredpriv'}); |
return ''; |
return ''; |
} |
} |
|
|
Line 343 sub new {
|
Line 353 sub new {
|
my $self = {}; |
my $self = {}; |
|
|
$self->{TITLE} = shift; |
$self->{TITLE} = shift; |
|
$self->{REQUIRED_PRIV} = shift; |
|
|
Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); |
|
|
|
# If there is a state from the previous form, use that. If there is no |
# If there is a state from the previous form, use that. If there is no |
# state, use the start state parameter. |
# state, use the start state parameter. |
if (defined $ENV{"form.CURRENT_STATE"}) |
if (defined $ENV{"form.CURRENT_STATE"}) |
Line 461 sub declareVar {
|
Line 470 sub declareVar {
|
|
|
my $envname = 'form.' . $var . '.forminput'; |
my $envname = 'form.' . $var . '.forminput'; |
if (defined($ENV{$envname})) { |
if (defined($ENV{$envname})) { |
$self->{VARS}->{$var} = $ENV{$envname}; |
if (ref($ENV{$envname})) { |
|
$self->{VARS}->{$var} = join('|||', @{$ENV{$envname}}); |
|
} else { |
|
$self->{VARS}->{$var} = $ENV{$envname}; |
|
} |
|
} |
|
} |
|
|
|
sub allowedCheck { |
|
my $self = shift; |
|
|
|
if (!defined($self->{REQUIRED_PRIV})) { |
|
return 1; |
} |
} |
|
|
|
return Apache::lonnet::allowed($self->{REQUIRED_PRIV}, $ENV{'request.course.id'}); |
} |
} |
|
|
sub changeState { |
sub changeState { |
Line 545 sub display {
|
Line 568 sub display {
|
</head> |
</head> |
$bodytag |
$bodytag |
HEADER |
HEADER |
if (!$state->overrideForm()) { $result.="<form name='helpform' method='GET'>"; } |
if (!$state->overrideForm()) { $result.="<form name='helpform' method='POST'>"; } |
$result .= <<HEADER; |
$result .= <<HEADER; |
<table border="0"><tr><td> |
<table border="0" width='100%'><tr><td> |
<h2><i>$stateTitle</i></h2> |
<h2><i>$stateTitle</i></h2> |
HEADER |
HEADER |
|
|
|
$result .= "<table cellpadding='10' width='100%'><tr><td rowspan='2' valign='top'>"; |
|
|
if (!$state->overrideForm()) { |
if (!$state->overrideForm()) { |
$result .= $self->_saveVars(); |
$result .= $self->_saveVars(); |
} |
} |
$result .= $state->render() . "<p> </p>"; |
$result .= $state->render(); |
|
|
|
$result .= "</td><td valign='top' align='right'>"; |
|
|
|
# Warning: Copy and pasted from below, because it's too much trouble to |
|
# turn this into a subroutine |
|
if (!$state->overrideForm()) { |
|
if ($self->{STATE} ne $self->{START_STATE}) { |
|
#$result .= '<input name="SUBMIT" type="submit" value="<- Previous" /> '; |
|
} |
|
if ($self->{DONE}) { |
|
my $returnPage = $self->{RETURN_PAGE}; |
|
$result .= "<a href=\"$returnPage\">End Helper</a>"; |
|
} |
|
else { |
|
$result .= '<nobr><input name="back" type="button" '; |
|
$result .= 'value="<- Previous" onclick="history.go(-1)" /> '; |
|
$result .= '<input name="SUBMIT" type="submit" value="Next ->" /></nobr>'; |
|
} |
|
} |
|
|
|
$result .= "</td></tr><tr><td valign='bottom' align='right'>"; |
|
|
|
# Warning: Copy and pasted from above, because it's too much trouble to |
|
# turn this into a subroutine |
if (!$state->overrideForm()) { |
if (!$state->overrideForm()) { |
$result .= '<center>'; |
|
if ($self->{STATE} ne $self->{START_STATE}) { |
if ($self->{STATE} ne $self->{START_STATE}) { |
#$result .= '<input name="SUBMIT" type="submit" value="<- Previous" /> '; |
#$result .= '<input name="SUBMIT" type="submit" value="<- Previous" /> '; |
} |
} |
Line 566 HEADER
|
Line 613 HEADER
|
$result .= "<a href=\"$returnPage\">End Helper</a>"; |
$result .= "<a href=\"$returnPage\">End Helper</a>"; |
} |
} |
else { |
else { |
$result .= '<input name="back" type="button" '; |
$result .= '<nobr><input name="back" type="button" '; |
$result .= 'value="<- Previous" onclick="history.go(-1)" /> '; |
$result .= 'value="<- Previous" onclick="history.go(-1)" /> '; |
$result .= '<input name="SUBMIT" type="submit" value="Next ->" />'; |
$result .= '<input name="SUBMIT" type="submit" value="Next ->" /></nobr>'; |
} |
} |
$result .= "</center>\n"; |
|
} |
} |
|
|
#foreach my $key (keys %{$self->{VARS}}) { |
#foreach my $key (keys %{$self->{VARS}}) { |
# $result .= "|$key| -> " . $self->{VARS}->{$key} . "<br />"; |
# $result .= "|$key| -> " . $self->{VARS}->{$key} . "<br />"; |
#} |
#} |
|
|
|
$result .= "</td></tr></table>"; |
|
|
$result .= <<FOOTER; |
$result .= <<FOOTER; |
</td> |
</td> |
</tr> |
</tr> |
Line 689 sub render {
|
Line 737 sub render {
|
for my $element (@{$self->{ELEMENTS}}) { |
for my $element (@{$self->{ELEMENTS}}) { |
push @results, $element->render(); |
push @results, $element->render(); |
} |
} |
|
|
return join("\n", @results); |
return join("\n", @results); |
} |
} |
|
|
Line 701 package Apache::lonhelper::element;
|
Line 750 package Apache::lonhelper::element;
|
|
|
=head2 Element Base Class |
=head2 Element Base Class |
|
|
The Apache::lonhelper::element base class provides support methods for |
The Apache::lonhelper::element base class provides support for elements |
the elements to use, such as a multiple value processer. |
and defines some generally useful tags for use in elements. |
|
|
B<Methods>: |
|
|
|
=over 4 |
|
|
|
=item * process_multiple_choices(formName, varName): Process the form |
|
element named "formName" and place the selected items into the helper |
|
variable named varName. This is for things like checkboxes or |
|
multiple-selection listboxes where the user can select more then |
|
one entry. The selected entries are delimited by triple pipes in |
|
the helper variables, like this: |
|
|
|
CHOICE_1|||CHOICE_2|||CHOICE_3 |
|
|
|
=back |
|
|
|
B<finalcode tag> |
B<finalcode tag> |
|
|
Line 745 some setting accidentally.
|
Line 779 some setting accidentally.
|
|
|
Again, see the course initialization helper for examples. |
Again, see the course initialization helper for examples. |
|
|
|
B<getValue method> |
|
|
|
If the element stores the name of the variable in a 'variable' member, which |
|
the provided ones all do, you can retreive the value of the variable by calling |
|
this method. |
|
|
=cut |
=cut |
|
|
BEGIN { |
BEGIN { |
Line 831 sub overrideForm {
|
Line 871 sub overrideForm {
|
return 0; |
return 0; |
} |
} |
|
|
sub process_multiple_choices { |
sub getValue { |
my $self = shift; |
my $self = shift; |
my $formname = shift; |
return $helper->{VARS}->{$self->{'variable'}}; |
my $var = shift; |
|
|
|
# Must extract values from data directly, as there |
|
# may be more then one. |
|
my @values; |
|
for my $formparam (split (/&/, $ENV{QUERY_STRING})) { |
|
my ($name, $value) = split(/=/, $formparam); |
|
if ($name ne $formname) { |
|
next; |
|
} |
|
$value =~ tr/+/ /; |
|
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; |
|
push @values, $value; |
|
} |
|
$helper->{VARS}->{$var} = join('|||', @values); |
|
|
|
return; |
|
} |
} |
|
|
1; |
1; |
Line 1205 sub postprocess {
|
Line 1228 sub postprocess {
|
return 0; |
return 0; |
} |
} |
|
|
if ($self->{'multichoice'}) { |
if (ref($chosenValue)) { |
$self->process_multiple_choices($self->{'variable'}.'.forminput', |
$helper->{VARS}->{$self->{'variable'}} = join('|||', @$chosenValue); |
$self->{'variable'}); |
|
} |
} |
|
|
if (defined($self->{NEXTSTATE})) { |
if (defined($self->{NEXTSTATE})) { |
Line 1453 variable stores the results. It also tak
|
Line 1475 variable stores the results. It also tak
|
which controls whether the user can select more then one resource. The |
which controls whether the user can select more then one resource. The |
"toponly" attribute controls whether the resource display shows just the |
"toponly" attribute controls whether the resource display shows just the |
resources in that sequence, or recurses into all sub-sequences, defaulting |
resources in that sequence, or recurses into all sub-sequences, defaulting |
to false. |
to false. The "suppressEmptySequences" attribute reflects the |
|
suppressEmptySequences argument to the render routine, which will cause |
|
folders that have all of their contained resources filtered out to also |
|
be filtered out. |
|
|
B<SUB-TAGS> |
B<SUB-TAGS> |
|
|
Line 1514 sub start_resource {
|
Line 1539 sub start_resource {
|
$paramHash->{'variable'} = $token->[2]{'variable'}; |
$paramHash->{'variable'} = $token->[2]{'variable'}; |
$helper->declareVar($paramHash->{'variable'}); |
$helper->declareVar($paramHash->{'variable'}); |
$paramHash->{'multichoice'} = $token->[2]{'multichoice'}; |
$paramHash->{'multichoice'} = $token->[2]{'multichoice'}; |
|
$paramHash->{'suppressEmptySequences'} = $token->[2]{'suppressEmptySequences'}; |
$paramHash->{'toponly'} = $token->[2]{'toponly'}; |
$paramHash->{'toponly'} = $token->[2]{'toponly'}; |
return ''; |
return ''; |
} |
} |
Line 1682 BUTTONS
|
Line 1708 BUTTONS
|
'showParts' => 0, |
'showParts' => 0, |
'filterFunc' => $filterFunc, |
'filterFunc' => $filterFunc, |
'resource_no_folder_link' => 1, |
'resource_no_folder_link' => 1, |
|
'suppressEmptySequences' => $self->{'suppressEmptySequences'}, |
'iterator_map' => $mapUrl } |
'iterator_map' => $mapUrl } |
); |
); |
|
|
Line 1693 BUTTONS
|
Line 1720 BUTTONS
|
sub postprocess { |
sub postprocess { |
my $self = shift; |
my $self = shift; |
|
|
if ($self->{'multichoice'}) { |
|
$self->process_multiple_choices($self->{'variable'}.'.forminput', |
|
$self->{'variable'}); |
|
} |
|
|
|
if ($self->{'multichoice'} && !$helper->{VARS}->{$self->{'variable'}}) { |
if ($self->{'multichoice'} && !$helper->{VARS}->{$self->{'variable'}}) { |
$self->{ERROR_MSG} = 'You must choose at least one resource to continue.'; |
$self->{ERROR_MSG} = 'You must choose at least one resource to continue.'; |
return 0; |
return 0; |
Line 1855 sub postprocess {
|
Line 1877 sub postprocess {
|
return 0; |
return 0; |
} |
} |
|
|
if ($self->{'multichoice'}) { |
|
$self->process_multiple_choices($self->{'variable'}.'.forminput', |
|
$self->{'variable'}); |
|
} |
|
if (defined($self->{NEXTSTATE})) { |
if (defined($self->{NEXTSTATE})) { |
$helper->changeState($self->{NEXTSTATE}); |
$helper->changeState($self->{NEXTSTATE}); |
} |
} |
Line 2143 sub postprocess {
|
Line 2161 sub postprocess {
|
return 0; |
return 0; |
} |
} |
|
|
if ($self->{'multichoice'}) { |
|
$self->process_multiple_choices($self->{'variable'}.'.forminput', |
|
$self->{'variable'}); |
|
} |
|
if (defined($self->{NEXTSTATE})) { |
if (defined($self->{NEXTSTATE})) { |
$helper->changeState($self->{NEXTSTATE}); |
$helper->changeState($self->{NEXTSTATE}); |
} |
} |
Line 2431 sub render {
|
Line 2445 sub render {
|
for my $element (@{$state->{ELEMENTS}}) { |
for my $element (@{$state->{ELEMENTS}}) { |
if (defined($element->{FINAL_CODE})) { |
if (defined($element->{FINAL_CODE})) { |
# Compile the code. |
# Compile the code. |
my $code = 'sub { my $helper = shift; ' . $element->{FINAL_CODE} . |
my $code = 'sub { my $helper = shift; my $element = shift; ' |
'}'; |
. $element->{FINAL_CODE} . '}'; |
$code = eval($code); |
$code = eval($code); |
die 'Error while executing final code for element with var ' . |
die 'Error while executing final code for element with var ' . |
$element->{'variable'} . ', Perl said: ' . $@ if $@; |
$element->{'variable'} . ', Perl said: ' . $@ if $@; |
|
|
my $result = &$code($helper); |
my $result = &$code($helper, $element); |
if ($result) { |
if ($result) { |
push @results, $result; |
push @results, $result; |
} |
} |