--- loncom/interface/lonhelper.pm 2003/05/14 18:58:21 1.28 +++ loncom/interface/lonhelper.pm 2003/05/16 20:44:43 1.32 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # .helper XML handler to implement the LON-CAPA helper # -# $Id: lonhelper.pm,v 1.28 2003/05/14 18:58:21 bowersj2 Exp $ +# $Id: lonhelper.pm,v 1.32 2003/05/16 20:44:43 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,7 +53,10 @@ Each state contains one or more state el messages, resource selections, or date queries. 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 @@ -257,10 +260,17 @@ sub real_handler { # xml parsing &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(); $r->print($helper->display()); - return OK; + return OK; } sub registerHelperTags { @@ -284,7 +294,7 @@ sub start_helper { registerHelperTags(); - Apache::lonhelper::helper->new($token->[2]{'title'}); + Apache::lonhelper::helper->new($token->[2]{'title'}, $token->[2]{'requiredpriv'}); return ''; } @@ -343,6 +353,7 @@ sub new { my $self = {}; $self->{TITLE} = shift; + $self->{REQUIRED_PRIV} = shift; # If there is a state from the previous form, use that. If there is no # state, use the start state parameter. @@ -467,6 +478,16 @@ 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 { my $self = shift; $self->{STATE} = shift; @@ -549,17 +570,41 @@ sub display { HEADER if (!$state->overrideForm()) { $result.="
"; } $result .= < + @@ -590,7 +636,6 @@ FOOTER # Handle writing out the vars to the file my $file = Apache::File->new('>'.$self->{FILENAME}); - print $file $self->_varsInFile(); return $result; } @@ -684,7 +729,6 @@ sub addElement { push @{$self->{ELEMENTS}}, $element; } -use Data::Dumper; sub render { my $self = shift; my @results = (); @@ -734,6 +778,12 @@ some setting accidentally. Again, see the course initialization helper for examples. +B + +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 BEGIN { @@ -820,6 +870,11 @@ sub overrideForm { return 0; } +sub getValue { + my $self = shift; + return $helper->{VARS}->{$self->{'variable'}}; +} + 1; package Apache::lonhelper::message; @@ -1419,7 +1474,10 @@ variable stores the results. It also tak 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. +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 @@ -1480,6 +1538,7 @@ sub start_resource { $paramHash->{'variable'} = $token->[2]{'variable'}; $helper->declareVar($paramHash->{'variable'}); $paramHash->{'multichoice'} = $token->[2]{'multichoice'}; + $paramHash->{'suppressEmptySequences'} = $token->[2]{'suppressEmptySequences'}; $paramHash->{'toponly'} = $token->[2]{'toponly'}; return ''; } @@ -1648,6 +1707,7 @@ BUTTONS 'showParts' => 0, 'filterFunc' => $filterFunc, 'resource_no_folder_link' => 1, + 'suppressEmptySequences' => $self->{'suppressEmptySequences'}, 'iterator_map' => $mapUrl } ); @@ -1861,6 +1921,8 @@ no strict; @ISA = ("Apache::lonhelper::element"); use strict; +use Apache::lonpubdir; # for getTitleString + BEGIN { &Apache::lonhelper::register('Apache::lonhelper::files', ('files', 'filechoice', 'filefilter')); @@ -2017,6 +2079,9 @@ BUTTONS $color = ''; } + # Get the title + my $title = Apache::lonpubdir::getTitleString($fileName); + # Netscape 4 is stupid and there's nowhere to put the # information on the input tag that the file is Published, # Unpublished, etc. In *real* browsers we can just say @@ -2043,8 +2108,9 @@ BUTTONS if (!$self->{'multichoice'} && $choices == 0) { $result .= ' checked'; } - $result .= "/>\n"; + $result .= "/>" . + "" . + "" . "\n"; $choices++; } } @@ -2384,13 +2450,13 @@ sub render { for my $element (@{$state->{ELEMENTS}}) { if (defined($element->{FINAL_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); die 'Error while executing final code for element with var ' . $element->{'variable'} . ', Perl said: ' . $@ if $@; - my $result = &$code($helper); + my $result = &$code($helper, $element); if ($result) { push @results, $result; }

$stateTitle

HEADER + $result .= "
"; + if (!$state->overrideForm()) { $result .= $self->_saveVars(); } - $result .= $state->render() . "

 

"; + $result .= $state->render(); + + $result .= "
"; + + # 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 .= '  '; + } + if ($self->{DONE}) { + my $returnPage = $self->{RETURN_PAGE}; + $result .= "End Helper"; + } + else { + $result .= 'overrideForm()) { - $result .= '
'; if ($self->{STATE} ne $self->{START_STATE}) { #$result .= '  '; } @@ -568,17 +613,18 @@ HEADER $result .= "End Helper"; } else { - $result .= '{VARS}}) { # $result .= "|$key| -> " . $self->{VARS}->{$key} . "
"; #} + $result .= "
"; + $result .= <
" . $file . - "$status
" . $file . "$title$status