version 1.13, 2003/04/30 15:18:36
|
version 1.20, 2003/05/07 18:13:13
|
Line 149 of the information used is persistent be
|
Line 149 of the information used is persistent be
|
and -maintain code. |
and -maintain code. |
|
|
It is possible to do some of the work with an XML fragment parsed by |
It is possible to do some of the work with an XML fragment parsed by |
lonxml; again, see lonprintout.pm for an example. |
lonxml; again, see lonprintout.pm for an example. In that case it is |
|
imperative that you call B<Apache::lonhelper::registerHelperTags()> |
|
before parsing XML fragments and B<Apache::lonhelper::unregisterHelperTags()> |
|
when you are done. See lonprintout.pm for examples of this usage in the |
|
printHelper subroutine. |
|
|
=cut |
=cut |
|
|
Line 202 sub handler {
|
Line 206 sub handler {
|
my $file; |
my $file; |
read $fh, $file, 100000000; |
read $fh, $file, 100000000; |
|
|
Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); |
|
|
|
# Send header, don't cache this page |
# Send header, don't cache this page |
if ($r->header_only) { |
if ($r->header_only) { |
if ($ENV{'browser.mathml'}) { |
if ($ENV{'browser.mathml'}) { |
Line 324 sub new {
|
Line 326 sub new {
|
$self->{STATE} = "START"; |
$self->{STATE} = "START"; |
} |
} |
|
|
|
Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); |
|
|
$self->{TOKEN} = $ENV{'form.TOKEN'}; |
$self->{TOKEN} = $ENV{'form.TOKEN'}; |
# If a token was passed, we load that in. Otherwise, we need to create a |
# If a token was passed, we load that in. Otherwise, we need to create a |
# new storage file |
# new storage file |
Line 462 sub process {
|
Line 466 sub process {
|
|
|
# Phase 2: Preprocess current state |
# Phase 2: Preprocess current state |
my $startState = $self->{STATE}; |
my $startState = $self->{STATE}; |
my $state = $self->{STATES}{$startState}; |
my $state = $self->{STATES}->{$startState}; |
|
|
# For debugging, print something here to determine if you're going |
# For debugging, print something here to determine if you're going |
# to an undefined state. |
# to an undefined state. |
Line 473 sub process {
|
Line 477 sub process {
|
|
|
# Phase 3: While the current state is different from the previous state, |
# Phase 3: While the current state is different from the previous state, |
# keep processing. |
# keep processing. |
while ( $startState ne $self->{STATE} ) |
while ( $startState ne $self->{STATE} && |
|
defined($self->{STATES}->{$self->{STATE}}) ) |
{ |
{ |
$startState = $self->{STATE}; |
$startState = $self->{STATE}; |
$state = $self->{STATES}{$startState}; |
$state = $self->{STATES}->{$startState}; |
$state->preprocess(); |
$state->preprocess(); |
} |
} |
|
|
Line 495 sub display {
|
Line 500 sub display {
|
|
|
my $result = ""; |
my $result = ""; |
|
|
|
if (!defined($state)) { |
|
$result = "<font color='#ff0000'>Error: state '$state' not defined!</font>"; |
|
return $result; |
|
} |
|
|
# Phase 4: Display. |
# Phase 4: Display. |
my $stateTitle = $state->title(); |
my $stateTitle = $state->title(); |
my $bodytag = &Apache::loncommon::bodytag("$self->{TITLE}",'',''); |
my $bodytag = &Apache::loncommon::bodytag("$self->{TITLE}",'',''); |
Line 506 sub display {
|
Line 516 sub display {
|
</head> |
</head> |
$bodytag |
$bodytag |
HEADER |
HEADER |
if (!$state->overrideForm()) { $result.="<form name='wizform' method='GET'>"; } |
if (!$state->overrideForm()) { $result.="<form name='helpform' method='GET'>"; } |
$result .= <<HEADER; |
$result .= <<HEADER; |
<table border="0"><tr><td> |
<table border="0"><tr><td> |
<h2><i>$stateTitle</i></h2> |
<h2><i>$stateTitle</i></h2> |
Line 740 sub process_multiple_choices {
|
Line 750 sub process_multiple_choices {
|
my $formname = shift; |
my $formname = shift; |
my $var = shift; |
my $var = shift; |
|
|
my $formvalue = $ENV{'form.' . $formname}; |
# Must extract values from data directly, as there |
if ($formvalue) { |
# may be more then one. |
# Must extract values from querystring directly, as there |
my @values; |
# may be more then one. |
for my $formparam (split (/&/, $ENV{QUERY_STRING})) { |
my @values; |
my ($name, $value) = split(/=/, $formparam); |
for my $formparam (split (/&/, $ENV{QUERY_STRING})) { |
if ($name ne $formname) { |
my ($name, $value) = split(/=/, $formparam); |
next; |
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); |
$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; |
return; |
} |
} |
Line 990 sub render {
|
Line 997 sub render {
|
if ($self->{'multichoice'}) { |
if ($self->{'multichoice'}) { |
$result .= <<SCRIPT; |
$result .= <<SCRIPT; |
<script> |
<script> |
function checkall(value) { |
function checkall(value, checkName) { |
for (i=0; i<document.forms.wizform.elements.length; i++) { |
for (i=0; i<document.forms.helpform.elements.length; i++) { |
document.forms.wizform.elements[i].checked=value; |
ele = document.forms.helpform.elements[i]; |
|
if (ele.name == checkName + '.forminput') { |
|
document.forms.helpform.elements[i].checked=value; |
|
} |
} |
} |
} |
} |
</script> |
</script> |
SCRIPT |
SCRIPT |
$buttons = <<BUTTONS; |
$buttons = <<BUTTONS; |
<br /> |
<br /> |
<input type="button" onclick="checkall(true)" value="Select All" /> |
<input type="button" onclick="checkall(true, '$var')" value="Select All" /> |
<input type="button" onclick="checkall(false)" value="Unselect All" /> |
<input type="button" onclick="checkall(false, '$var')" value="Unselect All" /> |
<br /> |
<br /> |
BUTTONS |
BUTTONS |
} |
} |
Line 1298 the user can manipulate the folders.
|
Line 1308 the user can manipulate the folders.
|
|
|
<resource> takes the standard variable attribute to control what helper |
<resource> takes the standard variable attribute to control what helper |
variable stores the results. It also takes a "multichoice" attribute, |
variable stores the results. It also takes a "multichoice" attribute, |
which controls whether the user can select more then one resource. |
which controls whether the user can select more then one resource. The |
|
"toponly" attribute controls whether the resource display shows just the |
|
resources in that sequence, or recurses into all sub-sequences, defaulting |
|
to false. |
|
|
B<SUB-TAGS> |
B<SUB-TAGS> |
|
|
Line 1358 sub start_resource {
|
Line 1371 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->{'toponly'} = $token->[2]{'toponly'}; |
return ''; |
return ''; |
} |
} |
|
|
Line 1434 sub start_mapurl {
|
Line 1449 sub start_mapurl {
|
|
|
my $contents = Apache::lonxml::get_all_text('/mapurl', |
my $contents = Apache::lonxml::get_all_text('/mapurl', |
$parser); |
$parser); |
$paramHash->{MAP_URL} = eval $contents; |
$paramHash->{MAP_URL} = $contents; |
} |
} |
|
|
sub end_mapurl { return ''; } |
sub end_mapurl { return ''; } |
Line 1457 sub render {
|
Line 1472 sub render {
|
my $var = $self->{'variable'}; |
my $var = $self->{'variable'}; |
my $curVal = $helper->{VARS}->{$var}; |
my $curVal = $helper->{VARS}->{$var}; |
|
|
|
my $buttons = ''; |
|
|
|
if ($self->{'multichoice'}) { |
|
$result = <<SCRIPT; |
|
<script> |
|
function checkall(value, checkName) { |
|
for (i=0; i<document.forms.helpform.elements.length; i++) { |
|
ele = document.forms.helpform.elements[i]; |
|
if (ele.name == checkName + '.forminput') { |
|
document.forms.helpform.elements[i].checked=value; |
|
} |
|
} |
|
} |
|
</script> |
|
SCRIPT |
|
$buttons = <<BUTTONS; |
|
<br /> |
|
<input type="button" onclick="checkall(true, '$var')" value="Select All Resources" /> |
|
<input type="button" onclick="checkall(false, '$var')" value="Unselect All Resources" /> |
|
<br /> |
|
BUTTONS |
|
} |
|
|
if (defined $self->{ERROR_MSG}) { |
if (defined $self->{ERROR_MSG}) { |
$result .= '<font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
$result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
} |
} |
|
|
|
$result .= $buttons; |
|
|
my $filterFunc = $self->{FILTER_FUNC}; |
my $filterFunc = $self->{FILTER_FUNC}; |
my $choiceFunc = $self->{CHOICE_FUNC}; |
my $choiceFunc = $self->{CHOICE_FUNC}; |
my $valueFunc = $self->{VALUE_FUNC}; |
my $valueFunc = $self->{VALUE_FUNC}; |
my $mapUrl = $self->{MAP_URL}; |
my $mapUrl = $self->{MAP_URL}; |
|
my $multichoice = $self->{'multichoice'}; |
|
|
# Create the composite function that renders the column on the nav map |
# Create the composite function that renders the column on the nav map |
# have to admit any language that lets me do this can't be all bad |
# have to admit any language that lets me do this can't be all bad |
Line 1472 sub render {
|
Line 1513 sub render {
|
my $checked = 0; |
my $checked = 0; |
my $renderColFunc = sub { |
my $renderColFunc = sub { |
my ($resource, $part, $params) = @_; |
my ($resource, $part, $params) = @_; |
|
|
|
my $inputType; |
|
if ($multichoice) { $inputType = 'checkbox'; } |
|
else {$inputType = 'radio'; } |
|
|
if (!&$choiceFunc($resource)) { |
if (!&$choiceFunc($resource)) { |
return '<td> </td>'; |
return '<td> </td>'; |
} else { |
} else { |
my $col = "<td><input type='radio' name='${var}.forminput' "; |
my $col = "<td><input type='$inputType' name='${var}.forminput' "; |
if (!$checked) { |
if (!$checked && !$multichoice) { |
$col .= "checked "; |
$col .= "checked "; |
$checked = 1; |
$checked = 1; |
} |
} |
Line 1488 sub render {
|
Line 1533 sub render {
|
} |
} |
}; |
}; |
|
|
$ENV{'form.condition'} = 1; |
$ENV{'form.condition'} = !$self->{'toponly'}; |
$result .= |
$result .= |
&Apache::lonnavmaps::render( { 'cols' => [$renderColFunc, |
&Apache::lonnavmaps::render( { 'cols' => [$renderColFunc, |
Apache::lonnavmaps::resource()], |
Apache::lonnavmaps::resource()], |
Line 1497 sub render {
|
Line 1542 sub render {
|
'resource_no_folder_link' => 1, |
'resource_no_folder_link' => 1, |
'iterator_map' => $mapUrl } |
'iterator_map' => $mapUrl } |
); |
); |
|
|
|
$result .= $buttons; |
|
|
return $result; |
return $result; |
} |
} |
|
|
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'}}) { |
|
$self->{ERROR_MSG} = 'You must choose at least one resource to continue.'; |
|
return 0; |
|
} |
|
|
if (defined($self->{NEXTSTATE})) { |
if (defined($self->{NEXTSTATE})) { |
$helper->changeState($self->{NEXTSTATE}); |
$helper->changeState($self->{NEXTSTATE}); |
} |
} |
Line 1572 sub render {
|
Line 1630 sub render {
|
my $self = shift; |
my $self = shift; |
my $result = ''; |
my $result = ''; |
my $buttons = ''; |
my $buttons = ''; |
|
my $var = $self->{'variable'}; |
|
|
if ($self->{'multichoice'}) { |
if ($self->{'multichoice'}) { |
$result = <<SCRIPT; |
$result = <<SCRIPT; |
<script> |
<script> |
function checkall(value) { |
function checkall(value, checkName) { |
for (i=0; i<document.forms.wizform.elements.length; i++) { |
for (i=0; i<document.forms.helpform.elements.length; i++) { |
document.forms.wizform.elements[i].checked=value; |
ele = document.forms.helpform.elements[i]; |
|
if (ele.name == checkName + '.forminput') { |
|
document.forms.helpform.elements[i].checked=value; |
|
} |
} |
} |
} |
} |
</script> |
</script> |
SCRIPT |
SCRIPT |
$buttons = <<BUTTONS; |
$buttons = <<BUTTONS; |
<br /> |
<br /> |
<input type="button" onclick="checkall(true)" value="Select All" /> |
<input type="button" onclick="checkall(true, '$var')" value="Select All Students" /> |
<input type="button" onclick="checkall(false)" value="Unselect All" /> |
<input type="button" onclick="checkall(false, '$var')" value="Unselect All Students" /> |
<br /> |
<br /> |
BUTTONS |
BUTTONS |
} |
} |
Line 1627 BUTTONS
|
Line 1689 BUTTONS
|
$checked = 1; |
$checked = 1; |
} |
} |
$result .= |
$result .= |
" value='" . HTML::Entities::encode($_) |
" value='" . HTML::Entities::encode($_ . ':' . $choices->{$_}->[$section]) |
. "' /></td><td>" |
. "' /></td><td>" |
. HTML::Entities::encode($choices->{$_}->[$fullname]) |
. HTML::Entities::encode($choices->{$_}->[$fullname]) |
. "</td><td align='center'>" |
. "</td><td align='center'>" |
Line 1777 sub render {
|
Line 1839 sub render {
|
if ($self->{'multichoice'}) { |
if ($self->{'multichoice'}) { |
$result = <<SCRIPT; |
$result = <<SCRIPT; |
<script> |
<script> |
function checkall(value) { |
function checkall(value, checkName) { |
for (i=0; i<document.forms.wizform.elements.length; i++) { |
for (i=0; i<document.forms.helpform.elements.length; i++) { |
ele = document.forms.wizform.elements[i]; |
ele = document.forms.helpform.elements[i]; |
if (ele.type == "checkbox") { |
if (ele.name == checkName + '.forminput') { |
document.forms.wizform.elements[i].checked=value; |
document.forms.helpform.elements[i].checked=value; |
} |
} |
} |
} |
} |
} |
</script> |
</script> |
SCRIPT |
SCRIPT |
my $buttons = <<BUTTONS; |
$buttons = <<BUTTONS; |
<br /> |
<br /> |
<input type="button" onclick="checkall(true)" value="Select All" /> |
<input type="button" onclick="checkall(true, '$var')" value="Select All Files" /> |
<input type="button" onclick="checkall(false)" value="Unselect All" /> |
<input type="button" onclick="checkall(false, '$var')" value="Unselect All Files" /> |
<br /> |
<br /> |
BUTTONS |
BUTTONS |
} |
} |
Line 1814 BUTTONS
|
Line 1876 BUTTONS
|
$result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
$result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br /><br />'; |
} |
} |
|
|
$result .= '<table border="0" cellpadding="1" cellspacing="1">'; |
$result .= '<table border="0" cellpadding="2" cellspacing="0">'; |
|
|
# Keeps track if there are no choices, prints appropriate error |
# Keeps track if there are no choices, prints appropriate error |
# if there are none. |
# if there are none. |
Line 1831 BUTTONS
|
Line 1893 BUTTONS
|
} |
} |
my $fileName = $subdir .'/'. $file; |
my $fileName = $subdir .'/'. $file; |
if (&$filterFunc($file)) { |
if (&$filterFunc($file)) { |
$result .= '<tr><td align="right">' . |
(my $status, my $color) = @{fileState($subdir, $file)}; |
|
$result .= '<tr><td align="right"' . " bgcolor='$color'>" . |
"<input type='$type' name='" . $var |
"<input type='$type' name='" . $var |
. ".forminput' value='" . HTML::Entities::encode($fileName) . |
. ".forminput' value='" . HTML::Entities::encode($fileName) . |
"'"; |
"'"; |
if (!$self->{'multichoice'} && $choices == 0) { |
if (!$self->{'multichoice'} && $choices == 0) { |
$result .= ' checked'; |
$result .= ' checked'; |
} |
} |
$result .= "/></td><td>" . $file . "</td></tr>\n"; |
$result .= "/></td><td bgcolor='$color'>" . $file . |
|
"</td><td bgcolor='$color'>$status</td></tr>\n"; |
$choices++; |
$choices++; |
} |
} |
} |
} |
Line 1854 BUTTONS
|
Line 1918 BUTTONS
|
return $result; |
return $result; |
} |
} |
|
|
|
# Determine the state of the file: Published, unpublished, modified. |
|
# Return the color it should be in and a label as a two-element array |
|
# reference. |
|
# Logic lifted from lonpubdir.pm, even though I don't know that it's still |
|
# the most right thing to do. |
|
|
|
sub fileState { |
|
my $constructionSpaceDir = shift; |
|
my $file = shift; |
|
|
|
my $docroot = $Apache::lonnet::perlvar{'lonDocRoot'}; |
|
my $subdirpart = $constructionSpaceDir; |
|
$subdirpart =~ s/^\/home\/$ENV{'user.name'}\/public_html//; |
|
my $resdir = $docroot . '/res/' . $ENV{'user.domain'} . '/' . $ENV{'user.name'} . |
|
$subdirpart; |
|
|
|
my @constructionSpaceFileStat = stat($constructionSpaceDir . '/' . $file); |
|
my @resourceSpaceFileStat = stat($resdir . '/' . $file); |
|
if (!@resourceSpaceFileStat) { |
|
return ['Unpublished', '#FFCCCC']; |
|
} |
|
|
|
my $constructionSpaceFileModified = $constructionSpaceFileStat[9]; |
|
my $resourceSpaceFileModified = $resourceSpaceFileStat[9]; |
|
|
|
if ($constructionSpaceFileModified > $resourceSpaceFileModified) { |
|
return ['Modified', '#FFFFCC']; |
|
} |
|
return ['Published', '#CCFFCC']; |
|
} |
|
|
sub postprocess { |
sub postprocess { |
my $self = shift; |
my $self = shift; |
my $result = $ENV{'form.' . $self->{'variable'} . '.forminput'}; |
my $result = $ENV{'form.' . $self->{'variable'} . '.forminput'}; |
Line 2130 sub render {
|
Line 2225 sub render {
|
'due_date' => "0_duedate", |
'due_date' => "0_duedate", |
'answer_date' => "0_answerdate"); |
'answer_date' => "0_answerdate"); |
|
|
my $result = "<form name='wizform' method='get' action='/adm/parmset'>\n"; |
my $result = "<form name='helpform' method='get' action='/adm/parmset'>\n"; |
$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>'; |
my $affectedResourceId = ""; |
my $affectedResourceId = ""; |
my $parm_name = $parmTypeHash{$vars->{ACTION_TYPE}}; |
my $parm_name = $parmTypeHash{$vars->{ACTION_TYPE}}; |