--- loncom/interface/lonhelper.pm 2003/04/30 18:40:49 1.14 +++ loncom/interface/lonhelper.pm 2003/05/07 18:13:13 1.20 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.14 2003/04/30 18:40:49 bowersj2 Exp $ +# $Id: lonhelper.pm,v 1.20 2003/05/07 18:13:13 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -149,7 +149,11 @@ of the information used is persistent be and -maintain code. 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 +before parsing XML fragments and B +when you are done. See lonprintout.pm for examples of this usage in the +printHelper subroutine. =cut @@ -462,7 +466,7 @@ sub process { # Phase 2: Preprocess current 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 # to an undefined state. @@ -473,10 +477,11 @@ sub process { # Phase 3: While the current state is different from the previous state, # keep processing. - while ( $startState ne $self->{STATE} ) + while ( $startState ne $self->{STATE} && + defined($self->{STATES}->{$self->{STATE}}) ) { $startState = $self->{STATE}; - $state = $self->{STATES}{$startState}; + $state = $self->{STATES}->{$startState}; $state->preprocess(); } @@ -495,6 +500,11 @@ sub display { my $result = ""; + if (!defined($state)) { + $result = "Error: state '$state' not defined!"; + return $result; + } + # Phase 4: Display. my $stateTitle = $state->title(); my $bodytag = &Apache::loncommon::bodytag("$self->{TITLE}",'',''); @@ -987,22 +997,25 @@ sub render { if ($self->{'multichoice'}) { $result .= < - function checkall(value) { - for (i=0; i SCRIPT $buttons = < - - + +
  BUTTONS } - if (defined $self->{ERRO_MSG}) { + if (defined $self->{ERROR_MSG}) { $result .= '
' . $self->{ERROR_MSG} . '
'; } @@ -1295,7 +1308,10 @@ the user can manipulate the folders. takes the standard variable attribute to control what helper 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 @@ -1356,6 +1372,7 @@ sub start_resource { $paramHash->{'variable'} = $token->[2]{'variable'}; $helper->declareVar($paramHash->{'variable'}); $paramHash->{'multichoice'} = $token->[2]{'multichoice'}; + $paramHash->{'toponly'} = $token->[2]{'toponly'}; return ''; } @@ -1455,10 +1472,35 @@ sub render { my $var = $self->{'variable'}; my $curVal = $helper->{VARS}->{$var}; + my $buttons = ''; + + if ($self->{'multichoice'}) { + $result = < + function checkall(value, checkName) { + for (i=0; i +SCRIPT + $buttons = <   + + +
  +BUTTONS + } + if (defined $self->{ERROR_MSG}) { $result .= '
' . $self->{ERROR_MSG} . '

'; } + $result .= $buttons; + my $filterFunc = $self->{FILTER_FUNC}; my $choiceFunc = $self->{CHOICE_FUNC}; my $valueFunc = $self->{VALUE_FUNC}; @@ -1491,7 +1533,7 @@ sub render { } }; - $ENV{'form.condition'} = 1; + $ENV{'form.condition'} = !$self->{'toponly'}; $result .= &Apache::lonnavmaps::render( { 'cols' => [$renderColFunc, Apache::lonnavmaps::resource()], @@ -1500,6 +1542,8 @@ sub render { 'resource_no_folder_link' => 1, 'iterator_map' => $mapUrl } ); + + $result .= $buttons; return $result; } @@ -1586,21 +1630,25 @@ sub render { my $self = shift; my $result = ''; my $buttons = ''; + my $var = $self->{'variable'}; if ($self->{'multichoice'}) { $result = < - function checkall(value) { - for (i=0; i SCRIPT $buttons = < - - + +
BUTTONS } @@ -1641,7 +1689,7 @@ BUTTONS $checked = 1; } $result .= - " value='" . HTML::Entities::encode($_) + " value='" . HTML::Entities::encode($_ . ':' . $choices->{$_}->[$section]) . "' />" . HTML::Entities::encode($choices->{$_}->[$fullname]) . "" @@ -1791,20 +1839,20 @@ sub render { if ($self->{'multichoice'}) { $result = < - function checkall(value) { - for (i=0; i SCRIPT - my $buttons = <   - - + +
  BUTTONS } @@ -1828,7 +1876,7 @@ BUTTONS $result .= '
' . $self->{ERROR_MSG} . '

'; } - $result .= ''; + $result .= '
'; # Keeps track if there are no choices, prints appropriate error # if there are none. @@ -1845,14 +1893,16 @@ BUTTONS } my $fileName = $subdir .'/'. $file; if (&$filterFunc($file)) { - $result .= '\n"; + $result .= "/>\n"; $choices++; } } @@ -1868,6 +1918,37 @@ BUTTONS 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 { my $self = shift; my $result = $ENV{'form.' . $self->{'variable'} . '.forminput'};
' . + (my $status, my $color) = @{fileState($subdir, $file)}; + $result .= '
" . "{'multichoice'} && $choices == 0) { $result .= ' checked'; } - $result .= "/>" . $file . "
" . $file . + "$status