version 1.8, 2003/04/11 18:16:04
|
version 1.11, 2003/04/15 19:10:00
|
Line 283 sub new {
|
Line 283 sub new {
|
$self->{STATES} = {}; |
$self->{STATES} = {}; |
$self->{DONE} = 0; |
$self->{DONE} = 0; |
|
|
|
# Used by various helpers for various things; see lonparm.helper |
|
# for an example. |
|
$self->{DATA} = {}; |
|
|
bless($self, $class); |
bless($self, $class); |
return $self; |
return $self; |
} |
} |
Line 676 use strict;
|
Line 680 use strict;
|
|
|
BEGIN { |
BEGIN { |
&Apache::lonhelper::register('Apache::lonhelper::message', |
&Apache::lonhelper::register('Apache::lonhelper::message', |
('message', 'message_text')); |
('message')); |
} |
} |
|
|
sub new { |
sub new { |
Line 686 sub new {
|
Line 690 sub new {
|
|
|
# CONSTRUCTION: Construct the message element from the XML |
# CONSTRUCTION: Construct the message element from the XML |
sub start_message { |
sub start_message { |
return ''; |
|
} |
|
|
|
sub end_message { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
if ($target ne 'helper') { |
if ($target ne 'helper') { |
return ''; |
return ''; |
} |
} |
Apache::lonhelper::message->new(); |
|
|
$paramHash->{MESSAGE_TEXT} = &Apache::lonxml::get_all_text('/message', |
|
$parser); |
|
|
|
if (defined($token->[2]{'nextstate'})) { |
|
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; |
|
} |
return ''; |
return ''; |
} |
} |
|
|
sub start_message_text { |
sub end_message { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
if ($target ne 'helper') { |
if ($target ne 'helper') { |
return ''; |
return ''; |
} |
} |
|
Apache::lonhelper::message->new(); |
$paramHash->{MESSAGE_TEXT} = &Apache::lonxml::get_all_text('/message_text', |
return ''; |
$parser); |
|
} |
} |
|
|
sub end_message_text { return 1; } |
|
|
|
sub render { |
sub render { |
my $self = shift; |
my $self = shift; |
Line 1608 sub render {
|
Line 1611 sub render {
|
my $var = $self->{'variable'}; |
my $var = $self->{'variable'}; |
|
|
my $subdirFunc = eval('sub {' . $self->{'filechoice'} . '}'); |
my $subdirFunc = eval('sub {' . $self->{'filechoice'} . '}'); |
|
die 'Error in resource filter code for variable ' . |
|
{'variable'} . ', Perl said:' . $@ if $@; |
|
|
my $subdir = &$subdirFunc(); |
my $subdir = &$subdirFunc(); |
|
|
my $filterFunc = $self->{FILTER_FUNC}; |
my $filterFunc = $self->{FILTER_FUNC}; |
Line 1715 sub postprocess {
|
Line 1721 sub postprocess {
|
|
|
1; |
1; |
|
|
|
package Apache::lonhelper::section; |
|
|
|
=pod |
|
|
|
=head2 Element: section |
|
|
|
<section> allows the user to choose one or more sections from the current |
|
course. |
|
|
|
It takes the standard attributes "variable", "multichoice", and |
|
"nextstate", meaning what they do for most other elements. |
|
|
|
=cut |
|
|
|
no strict; |
|
@ISA = ("Apache::lonhelper::choices"); |
|
use strict; |
|
|
|
BEGIN { |
|
&Apache::lonhelper::register('Apache::lonhelper::section', |
|
('section')); |
|
} |
|
|
|
sub new { |
|
my $ref = Apache::lonhelper::choices->new(); |
|
bless($ref); |
|
} |
|
|
|
sub start_section { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
$paramHash->{CHOICES} = []; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
$paramHash->{'variable'} = $token->[2]{'variable'}; |
|
$helper->declareVar($paramHash->{'variable'}); |
|
$paramHash->{'multichoice'} = $token->[2]{'multichoice'}; |
|
if (defined($token->[2]{'nextstate'})) { |
|
$paramHash->{'nextstate'} = $token->[2]{'nextstate'}; |
|
} |
|
|
|
# Populate the CHOICES element |
|
my %choices; |
|
|
|
my $section = Apache::loncoursedata::CL_SECTION(); |
|
my $classlist = Apache::loncoursedata::get_classlist(); |
|
foreach (keys %$classlist) { |
|
my $sectionName = $classlist->{$_}->[$section]; |
|
if (!$sectionName) { |
|
$choices{"No section assigned"} = ""; |
|
} else { |
|
$choices{$sectionName} = $sectionName; |
|
} |
|
} |
|
|
|
for my $sectionName (sort(keys(%choices))) { |
|
push @{$paramHash->{CHOICES}}, [$sectionName, $sectionName]; |
|
} |
|
|
|
} |
|
|
|
sub end_section { return ''; } |
|
|
|
1; |
|
|
package Apache::lonhelper::general; |
package Apache::lonhelper::general; |
|
|
=pod |
=pod |
Line 1745 be able to call methods on it.
|
Line 1818 be able to call methods on it.
|
|
|
BEGIN { |
BEGIN { |
&Apache::lonhelper::register('Apache::lonhelper::general', |
&Apache::lonhelper::register('Apache::lonhelper::general', |
'exec', 'condition', 'clause'); |
'exec', 'condition', 'clause', |
|
'eval'); |
} |
} |
|
|
sub start_exec { |
sub start_exec { |
Line 1759 sub start_exec {
|
Line 1833 sub start_exec {
|
|
|
$code = eval ('sub { my $helper = shift; my $state = shift; ' . |
$code = eval ('sub { my $helper = shift; my $state = shift; ' . |
$code . "}"); |
$code . "}"); |
|
die 'Error in <exec>, Perl said: '. $@ if $@; |
&$code($helper, $paramHash); |
&$code($helper, $paramHash); |
} |
} |
|
|
Line 1796 sub start_clause {
|
Line 1871 sub start_clause {
|
my $clause = Apache::lonxml::get_all_text('/clause', $parser); |
my $clause = Apache::lonxml::get_all_text('/clause', $parser); |
$clause = eval('sub { my $helper = shift; my $state = shift; ' |
$clause = eval('sub { my $helper = shift; my $state = shift; ' |
. $clause . '}'); |
. $clause . '}'); |
|
die 'Error in clause of condition, Perl said: ' . $@ if $@; |
if (!&$clause($helper, $paramHash)) { |
if (!&$clause($helper, $paramHash)) { |
# Discard all text until the /condition. |
# Discard all text until the /condition. |
&Apache::lonxml::get_all_text('/condition', $parser); |
&Apache::lonxml::get_all_text('/condition', $parser); |
Line 1804 sub start_clause {
|
Line 1880 sub start_clause {
|
|
|
sub end_clause { return ''; } |
sub end_clause { return ''; } |
|
|
|
=pod |
|
|
|
=head2 General-purpose tag: <eval> |
|
|
|
The <eval> tag will be evaluated as a subroutine call passed in the |
|
current helper object and state hash as described in <condition> above, |
|
but is expected to return a string to be printed directly to the |
|
screen. This is useful for dynamically generating messages. |
|
|
|
=cut |
|
|
|
# This is basically a type of message. |
|
# Programmatically setting $paramHash->{NEXTSTATE} would work, though |
|
# it's probably bad form. |
|
|
|
sub start_eval { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
|
|
my $program = Apache::lonxml::get_all_text('/eval', $parser); |
|
$program = eval('sub { my $helper = shift; my $state = shift; ' |
|
. $program . '}'); |
|
die 'Error in eval code, Perl said: ' . $@ if $@; |
|
$paramHash->{MESSAGE_TEXT} = &$program($helper, $paramHash); |
|
} |
|
|
|
sub end_eval { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
|
|
Apache::lonhelper::message->new(); |
|
} |
|
|
|
|
|
|
1; |
1; |
|
|
__END__ |
__END__ |