version 1.28, 2003/05/14 18:58:21
|
version 1.40, 2003/06/23 20:39:18
|
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; |
|
|
# 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. |
Line 467 sub declareVar {
|
Line 478 sub declareVar {
|
} |
} |
} |
} |
|
|
|
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 { |
my $self = shift; |
my $self = shift; |
$self->{STATE} = shift; |
$self->{STATE} = shift; |
Line 549 sub display {
|
Line 570 sub display {
|
HEADER |
HEADER |
if (!$state->overrideForm()) { $result.="<form name='helpform' method='POST'>"; } |
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 568 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 684 sub addElement {
|
Line 730 sub addElement {
|
push @{$self->{ELEMENTS}}, $element; |
push @{$self->{ELEMENTS}}, $element; |
} |
} |
|
|
use Data::Dumper; |
|
sub render { |
sub render { |
my $self = shift; |
my $self = shift; |
my @results = (); |
my @results = (); |
Line 734 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<validator tag> |
|
|
|
Some elements that accepts user input can contain a "validator" tag that, |
|
when surrounded by "sub { my $helper = shift; my $state = shift; my $element = shift; my $val = shift " |
|
and "}", where "$val" is the value the user entered, will form a subroutine |
|
that when called will verify whether the given input is valid or not. If it |
|
is valid, the routine will return a false value. If invalid, the routine |
|
will return an error message to be displayed for the user. |
|
|
|
Consult the documentation for each element to see whether it supports this |
|
tag. |
|
|
|
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 { |
&Apache::lonhelper::register('Apache::lonhelper::element', |
&Apache::lonhelper::register('Apache::lonhelper::element', |
('nextstate', 'finalcode', |
('nextstate', 'finalcode', |
'defaultvalue')); |
'defaultvalue', 'validator')); |
} |
} |
|
|
# Because we use the param hash, this is often a sufficent |
# Because we use the param hash, this is often a sufficent |
Line 804 sub start_defaultvalue {
|
Line 867 sub start_defaultvalue {
|
|
|
sub end_defaultvalue { return ''; } |
sub end_defaultvalue { return ''; } |
|
|
|
sub start_validator { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
|
|
$paramHash->{VALIDATOR} = &Apache::lonxml::get_all_text('/validator', |
|
$parser); |
|
$paramHash->{VALIDATOR} = 'sub { my $helper = shift; my $state = shift; my $element = shift; my $val = shift;' . |
|
$paramHash->{VALIDATOR} . '}'; |
|
return ''; |
|
} |
|
|
|
sub end_validator { return ''; } |
|
|
sub preprocess { |
sub preprocess { |
return 1; |
return 1; |
} |
} |
Line 820 sub overrideForm {
|
Line 899 sub overrideForm {
|
return 0; |
return 0; |
} |
} |
|
|
|
sub getValue { |
|
my $self = shift; |
|
return $helper->{VARS}->{$self->{'variable'}}; |
|
} |
|
|
1; |
1; |
|
|
package Apache::lonhelper::message; |
package Apache::lonhelper::message; |
Line 1104 BUTTONS
|
Line 1188 BUTTONS
|
if (defined($self->{DEFAULT_VALUE})) { |
if (defined($self->{DEFAULT_VALUE})) { |
$checkedChoicesFunc = eval ($self->{DEFAULT_VALUE}); |
$checkedChoicesFunc = eval ($self->{DEFAULT_VALUE}); |
die 'Error in default value code for variable ' . |
die 'Error in default value code for variable ' . |
{'variable'} . ', Perl said:' . $@ if $@; |
$self->{'variable'} . ', Perl said: ' . $@ if $@; |
} else { |
} else { |
$checkedChoicesFunc = sub { return ''; }; |
$checkedChoicesFunc = sub { return ''; }; |
} |
} |
Line 1419 variable stores the results. It also tak
|
Line 1503 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 1480 sub start_resource {
|
Line 1567 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 1634 BUTTONS
|
Line 1722 BUTTONS
|
$col .= "checked "; |
$col .= "checked "; |
$checked = 1; |
$checked = 1; |
} |
} |
|
if ($multichoice) { # all resources start checked; see bug 1174 |
|
$col .= "checked "; |
|
$checked = 1; |
|
} |
$col .= "value='" . |
$col .= "value='" . |
HTML::Entities::encode(&$valueFunc($resource)) |
HTML::Entities::encode(&$valueFunc($resource)) |
. "' /></td>"; |
. "' /></td>"; |
Line 1648 BUTTONS
|
Line 1740 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 1682 package Apache::lonhelper::student;
|
Line 1775 package Apache::lonhelper::student;
|
Student elements display a choice of students enrolled in the current |
Student elements display a choice of students enrolled in the current |
course. Currently it is primitive; this is expected to evolve later. |
course. Currently it is primitive; this is expected to evolve later. |
|
|
Student elements take two attributes: "variable", which means what |
Student elements take three attributes: "variable", which means what |
it usually does, and "multichoice", which if true allows the user |
it usually does, "multichoice", which if true allows the user |
to select multiple students. |
to select multiple students, and "coursepersonnel" which if true |
|
adds the course personnel to the top of the student selection. |
|
|
=cut |
=cut |
|
|
Line 1714 sub start_student {
|
Line 1808 sub start_student {
|
$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->{'coursepersonnel'} = $token->[2]{'coursepersonnel'}; |
if (defined($token->[2]{'nextstate'})) { |
if (defined($token->[2]{'nextstate'})) { |
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; |
$paramHash->{NEXTSTATE} = $token->[2]{'nextstate'}; |
} |
} |
Line 1760 BUTTONS
|
Line 1855 BUTTONS
|
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
} |
} |
|
|
# Load up the students |
my $choices = []; |
my $choices = &Apache::loncoursedata::get_classlist(); |
|
my @keys = keys %{$choices}; |
# Load up the non-students, if necessary |
|
if ($self->{'coursepersonnel'}) { |
|
my %coursepersonnel = Apache::lonnet::get_course_adv_roles(); |
|
for (sort keys %coursepersonnel) { |
|
for my $role (split /,/, $coursepersonnel{$_}) { |
|
# extract the names so we can sort them |
|
my @people; |
|
|
|
for (split /,/, $role) { |
|
push @people, [split /:/, $role]; |
|
} |
|
|
|
@people = sort { $a->[0] cmp $b->[0] } @people; |
|
|
|
for my $person (@people) { |
|
push @$choices, [join(':', @$person), $person->[0], '', $_]; |
|
} |
|
} |
|
} |
|
} |
|
|
# Constants |
# Constants |
my $section = Apache::loncoursedata::CL_SECTION(); |
my $section = Apache::loncoursedata::CL_SECTION(); |
my $fullname = Apache::loncoursedata::CL_FULLNAME(); |
my $fullname = Apache::loncoursedata::CL_FULLNAME(); |
|
|
|
# Load up the students |
|
my $classlist = &Apache::loncoursedata::get_classlist(); |
|
my @keys = keys %{$classlist}; |
# Sort by: Section, name |
# Sort by: Section, name |
@keys = sort { |
@keys = sort { |
if ($choices->{$a}->[$section] ne $choices->{$b}->[$section]) { |
if ($classlist->{$a}->[$section] ne $classlist->{$b}->[$section]) { |
return $choices->{$a}->[$section] cmp $choices->{$b}->[$section]; |
return $classlist->{$a}->[$section] cmp $classlist->{$b}->[$section]; |
} |
} |
return $choices->{$a}->[$fullname] cmp $choices->{$b}->[$fullname]; |
return $classlist->{$a}->[$fullname] cmp $classlist->{$b}->[$fullname]; |
} @keys; |
} @keys; |
|
|
|
# username, fullname, section, type |
|
for (@keys) { |
|
push @$choices, [$_, $classlist->{$_}->[$fullname], |
|
$classlist->{$_}->[$section], 'Student']; |
|
} |
|
|
|
my $name = $self->{'coursepersonnel'} ? 'Name' : 'Student Name'; |
my $type = 'radio'; |
my $type = 'radio'; |
if ($self->{'multichoice'}) { $type = 'checkbox'; } |
if ($self->{'multichoice'}) { $type = 'checkbox'; } |
$result .= "<table cellspacing='2' cellpadding='2' border='0'>\n"; |
$result .= "<table cellspacing='2' cellpadding='2' border='0'>\n"; |
$result .= "<tr><td></td><td align='center'><b>Student Name</b></td>". |
$result .= "<tr><td></td><td align='center'><b>$name</b></td>". |
"<td align='center'><b>Section</b></td></tr>"; |
"<td align='center'><b>Section</b></td>" . |
|
"<td align='center'><b>Role</b></td></tr>"; |
|
|
my $checked = 0; |
my $checked = 0; |
foreach (@keys) { |
for my $choice (@$choices) { |
$result .= "<tr><td><input type='$type' name='" . |
$result .= "<tr><td><input type='$type' name='" . |
$self->{'variable'} . '.forminput' . "'"; |
$self->{'variable'} . '.forminput' . "'"; |
|
|
Line 1792 BUTTONS
|
Line 1917 BUTTONS
|
$checked = 1; |
$checked = 1; |
} |
} |
$result .= |
$result .= |
" value='" . HTML::Entities::encode($_ . ':' . $choices->{$_}->[$section]) |
" value='" . HTML::Entities::encode($choice->[0] . ':' . $choice->[2]) |
. "' /></td><td>" |
. "' /></td><td>" |
. HTML::Entities::encode($choices->{$_}->[$fullname]) |
. HTML::Entities::encode($choice->[1]) |
. "</td><td align='center'>" |
. "</td><td align='center'>" |
. HTML::Entities::encode($choices->{$_}->[$section]) |
. HTML::Entities::encode($choice->[2]) |
. "</td></tr>\n"; |
. "</td>\n<td>" |
|
. HTML::Entities::encode($choice->[3]) . "</td></tr>\n"; |
} |
} |
|
|
$result .= "</table>\n\n"; |
$result .= "</table>\n\n"; |
Line 1861 no strict;
|
Line 1987 no strict;
|
@ISA = ("Apache::lonhelper::element"); |
@ISA = ("Apache::lonhelper::element"); |
use strict; |
use strict; |
|
|
|
use Apache::lonpubdir; # for getTitleString |
|
|
BEGIN { |
BEGIN { |
&Apache::lonhelper::register('Apache::lonhelper::files', |
&Apache::lonhelper::register('Apache::lonhelper::files', |
('files', 'filechoice', 'filefilter')); |
('files', 'filechoice', 'filefilter')); |
Line 2017 BUTTONS
|
Line 2145 BUTTONS
|
$color = ''; |
$color = ''; |
} |
} |
|
|
|
# Get the title |
|
my $title = Apache::lonpubdir::getTitleString($fileName); |
|
|
# Netscape 4 is stupid and there's nowhere to put the |
# Netscape 4 is stupid and there's nowhere to put the |
# information on the input tag that the file is Published, |
# information on the input tag that the file is Published, |
# Unpublished, etc. In *real* browsers we can just say |
# Unpublished, etc. In *real* browsers we can just say |
Line 2043 BUTTONS
|
Line 2174 BUTTONS
|
if (!$self->{'multichoice'} && $choices == 0) { |
if (!$self->{'multichoice'} && $choices == 0) { |
$result .= ' checked'; |
$result .= ' checked'; |
} |
} |
$result .= "/></td><td bgcolor='$color'>" . $file . |
$result .= "/></td><td bgcolor='$color'>" . $file . "</td>" . |
"</td><td bgcolor='$color'>$status</td></tr>\n"; |
"<td bgcolor='$color'>$title</td>" . |
|
"<td bgcolor='$color'>$status</td>" . "</tr>\n"; |
$choices++; |
$choices++; |
} |
} |
} |
} |
Line 2183 sub end_section {
|
Line 2315 sub end_section {
|
} |
} |
1; |
1; |
|
|
|
package Apache::lonhelper::string; |
|
|
|
=pod |
|
|
|
=head2 Element: string |
|
|
|
string elements provide a string entry field for the user. string elements |
|
take the usual 'variable' and 'nextstate' parameters. string elements |
|
also pass through 'maxlength' and 'size' attributes to the input tag. |
|
|
|
string honors the defaultvalue tag, if given. |
|
|
|
string honors the validation function, if given. |
|
|
|
=cut |
|
|
|
no strict; |
|
@ISA = ("Apache::lonhelper::element"); |
|
use strict; |
|
|
|
BEGIN { |
|
&Apache::lonhelper::register('Apache::lonhelper::string', |
|
('string')); |
|
} |
|
|
|
sub new { |
|
my $ref = Apache::lonhelper::element->new(); |
|
bless($ref); |
|
} |
|
|
|
# CONSTRUCTION: Construct the message element from the XML |
|
sub start_string { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
|
|
$paramHash->{'variable'} = $token->[2]{'variable'}; |
|
$helper->declareVar($paramHash->{'variable'}); |
|
$paramHash->{'nextstate'} = $token->[2]{'nextstate'}; |
|
$paramHash->{'maxlength'} = $token->[2]{'maxlength'}; |
|
$paramHash->{'size'} = $token->[2]{'size'}; |
|
|
|
return ''; |
|
} |
|
|
|
sub end_string { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
Apache::lonhelper::string->new(); |
|
return ''; |
|
} |
|
|
|
sub render { |
|
my $self = shift; |
|
my $result = ''; |
|
|
|
if (defined $self->{ERROR_MSG}) { |
|
$result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
|
} |
|
|
|
$result .= '<input type="string" name="' . $self->{'variable'} . '.forminput"'; |
|
|
|
if (defined($self->{'size'})) { |
|
$result .= ' size="' . $self->{'size'} . '"'; |
|
} |
|
if (defined($self->{'maxlength'})) { |
|
$result .= ' maxlength="' . $self->{'maxlength'} . '"'; |
|
} |
|
|
|
if (defined($self->{DEFAULT_VALUE})) { |
|
my $valueFunc = eval($self->{DEFAULT_VALUE}); |
|
die 'Error in default value code for variable ' . |
|
$self->{'variable'} . ', Perl said: ' . $@ if $@; |
|
$result .= ' value="' . &$valueFunc($helper, $self) . '"'; |
|
} |
|
|
|
$result .= ' />'; |
|
|
|
return $result; |
|
} |
|
|
|
# If a NEXTSTATE was given, switch to it |
|
sub postprocess { |
|
my $self = shift; |
|
|
|
if (defined($self->{VALIDATOR})) { |
|
my $validator = eval($self->{VALIDATOR}); |
|
die 'Died during evaluation of evaulation code; Perl said: ' . $@ if $@; |
|
my $invalid = &$validator($helper, $state, $self, $self->getValue()); |
|
if ($invalid) { |
|
$self->{ERROR_MSG} = $invalid; |
|
return 0; |
|
} |
|
} |
|
|
|
if (defined($self->{'nextstate'})) { |
|
$helper->changeState($self->{'nextstate'}); |
|
} |
|
|
|
return 1; |
|
} |
|
|
|
1; |
|
|
package Apache::lonhelper::general; |
package Apache::lonhelper::general; |
|
|
=pod |
=pod |
Line 2327 tag. It goes through all the states and
|
Line 2568 tag. It goes through all the states and
|
snippets and collecting the results. Finally, it takes the user out of the |
snippets and collecting the results. Finally, it takes the user out of the |
helper, going to a provided page. |
helper, going to a provided page. |
|
|
|
If the parameter "restartCourse" is true, this will override the buttons and |
|
will make a "Finish Helper" button that will re-initialize the course for them, |
|
which is useful for the Course Initialization helper so the users never see |
|
the old values taking effect. |
|
|
=cut |
=cut |
|
|
no strict; |
no strict; |
Line 2343 sub new {
|
Line 2589 sub new {
|
bless($ref); |
bless($ref); |
} |
} |
|
|
sub start_final { return ''; } |
sub start_final { |
|
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
|
|
|
if ($target ne 'helper') { |
|
return ''; |
|
} |
|
|
|
$paramHash->{'restartCourse'} = $token->[2]{'restartCourse'}; |
|
|
|
return ''; |
|
} |
|
|
sub end_final { |
sub end_final { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
Line 2384 sub render {
|
Line 2640 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; |
} |
} |
Line 2398 sub render {
|
Line 2654 sub render {
|
} |
} |
} |
} |
|
|
if (scalar(@results) == 0) { |
my $result; |
return ''; |
|
} |
|
|
|
my $result = "<ul>\n"; |
if (scalar(@results) != 0) { |
for my $re (@results) { |
$result .= "<ul>\n"; |
$result .= ' <li>' . $re . "</li>\n"; |
for my $re (@results) { |
|
$result .= ' <li>' . $re . "</li>\n"; |
|
} |
|
|
|
if (!@results) { |
|
$result .= ' <li>No changes were made to current settings.</li>'; |
|
} |
|
|
|
$result .= '</ul>'; |
|
} |
|
|
|
if ($self->{'restartCourse'}) { |
|
$result .= "<center>\n" . |
|
"<form action='/adm/roles' method='post' target='loncapaclient'>\n" . |
|
"<input type='button' onclick='history.go(-1)' value='<- Previous' />" . |
|
"<input type='hidden' name='orgurl' value='/adm/menu' />" . |
|
"<input type='hidden' name='selectrole' value='1' />\n" . |
|
"<input type='hidden' name='" . $ENV{'request.role'} . |
|
"' value='1' />\n<input type='submit' value='Finish Course Initialization' />\n" . |
|
"</form></center>"; |
} |
} |
return $result . '</ul>'; |
|
|
return $result; |
|
} |
|
|
|
sub overrideForm { |
|
my $self = shift; |
|
return $self->{'restartCourse'}; |
} |
} |
|
|
1; |
1; |
Line 2453 sub render {
|
Line 2732 sub render {
|
# FIXME: Unify my designators with the standard ones |
# FIXME: Unify my designators with the standard ones |
my %dateTypeHash = ('open_date' => "Opening Date", |
my %dateTypeHash = ('open_date' => "Opening Date", |
'due_date' => "Due Date", |
'due_date' => "Due Date", |
'answer_date' => "Answer Date"); |
'answer_date' => "Answer Date", |
|
'tries' => 'Number of Tries' |
|
); |
my %parmTypeHash = ('open_date' => "0_opendate", |
my %parmTypeHash = ('open_date' => "0_opendate", |
'due_date' => "0_duedate", |
'due_date' => "0_duedate", |
'answer_date' => "0_answerdate"); |
'answer_date' => "0_answerdate", |
|
'tries' => '0_maxtries' ); |
|
|
my $affectedResourceId = ""; |
my $affectedResourceId = ""; |
my $parm_name = $parmTypeHash{$vars->{ACTION_TYPE}}; |
my $parm_name = $parmTypeHash{$vars->{ACTION_TYPE}}; |
Line 2476 sub render {
|
Line 2758 sub render {
|
my $navmap = Apache::lonnavmaps::navmap->new( |
my $navmap = Apache::lonnavmaps::navmap->new( |
$ENV{"request.course.fn"}.".db", |
$ENV{"request.course.fn"}.".db", |
$ENV{"request.course.fn"}."_parms.db", 0, 0); |
$ENV{"request.course.fn"}."_parms.db", 0, 0); |
my $res = $navmap->getById($vars->{RESOURCE_ID}); |
my $res = $navmap->getByMapPc($vars->{RESOURCE_ID}); |
my $title = $res->compTitle(); |
my $title = $res->compTitle(); |
$symb = $res->symb(); |
$symb = $res->symb(); |
$navmap->untieHashes(); |
$navmap->untieHashes(); |
Line 2502 sub render {
|
Line 2784 sub render {
|
$result .= '<p>Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.<ul>'; |
$result .= '<p>Confirm that this information is correct, then click "Finish Wizard" to complete setting the parameter.<ul>'; |
|
|
# Print the type of manipulation: |
# Print the type of manipulation: |
$result .= '<li>Setting the <b>' . $dateTypeHash{$vars->{ACTION_TYPE}} |
$result .= '<li>Setting the <b>' . $dateTypeHash{$vars->{ACTION_TYPE}} . '</b>'; |
. "</b></li>\n"; |
if ($vars->{ACTION_TYPE} eq 'tries') { |
|
$result .= ' to <b>' . $vars->{TRIES} . '</b>'; |
|
} |
|
$result .= "</li>\n"; |
if ($vars->{ACTION_TYPE} eq 'due_date' || |
if ($vars->{ACTION_TYPE} eq 'due_date' || |
$vars->{ACTION_TYPE} eq 'answer_date') { |
$vars->{ACTION_TYPE} eq 'answer_date') { |
# for due dates, we default to "date end" type entries |
# for due dates, we default to "date end" type entries |
Line 2520 sub render {
|
Line 2805 sub render {
|
"value='" . $vars->{PARM_DATE} . "' />\n"; |
"value='" . $vars->{PARM_DATE} . "' />\n"; |
$result .= "<input type='hidden' name='pres_type' " . |
$result .= "<input type='hidden' name='pres_type' " . |
"value='date_start' />\n"; |
"value='date_start' />\n"; |
} |
} elsif ($vars->{ACTION_TYPE} eq 'tries') { |
|
$result .= "<input type='hidden' name='pres_value' " . |
|
"value='" . $vars->{TRIES} . "' />\n"; |
|
} |
|
|
$result .= $resourceString; |
$result .= $resourceString; |
|
|
Line 2550 sub render {
|
Line 2838 sub render {
|
} |
} |
|
|
# Print value |
# Print value |
$result .= "<li>to <b>" . ctime($vars->{PARM_DATE}) . "</b> (" . |
if ($vars->{ACTION_TYPE} ne 'tries') { |
Apache::lonnavmaps::timeToHumanString($vars->{PARM_DATE}) |
$result .= "<li>to <b>" . ctime($vars->{PARM_DATE}) . "</b> (" . |
. ")</li>\n"; |
Apache::lonnavmaps::timeToHumanString($vars->{PARM_DATE}) |
|
. ")</li>\n"; |
|
} |
|
|
# print pres_marker |
# print pres_marker |
$result .= "\n<input type='hidden' name='pres_marker'" . |
$result .= "\n<input type='hidden' name='pres_marker'" . |
" value='$affectedResourceId&$parm_name&$level' />\n"; |
" value='$affectedResourceId&$parm_name&$level' />\n"; |