--- loncom/interface/lonhelper.pm 2004/04/27 15:32:45 1.77
+++ loncom/interface/lonhelper.pm 2008/12/06 12:49:18 1.167
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.77 2004/04/27 15:32:45 sakharuk Exp $
+# $Id: lonhelper.pm,v 1.167 2008/12/06 12:49:18 bisitz Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,10 +25,6 @@
#
# http://www.lon-capa.org/
#
-# (Page Handler
-#
-# (.helper handler
-#
=pod
@@ -85,25 +81,28 @@ State tags are also required to have an
human name of the state, and will be displayed as the header on top of
the screen for the user.
+State tags may also optionally have an attribute "help" which should be
+the filename of a help file, this will add a blue ? to the title.
+
=head2 Example Helper Skeleton
An example of the tags so far:
-
+
-Of course this does nothing. In order for the wizard to do something, it is
-necessary to put actual elements into the wizard. Documentation for each
+Of course this does nothing. In order for the helper to do something, it is
+necessary to put actual elements into the helper. Documentation for each
of these elements follows.
=head1 Creating a Helper With Code, Not XML
-In some situations, such as the printing wizard (see lonprintout.pm),
+In some situations, such as the printing helper (see lonprintout.pm),
writing the helper in XML would be too complicated, because of scope
issues or the fact that the code actually outweighs the XML. It is
possible to create a helper via code, though it is a little odd.
@@ -186,6 +185,10 @@ use Apache::Constants qw(:common);
use Apache::File;
use Apache::lonxml;
use Apache::lonlocal;
+use Apache::lonnet;
+use Apache::longroup;
+use Apache::lonselstudent;
+use LONCAPA;
# Register all the tags with the helper, so the helper can
# push and pop them
@@ -255,7 +258,7 @@ sub real_handler {
my $r = shift;
my $uri = shift;
if (!defined($uri)) { $uri = $r->uri(); }
- $ENV{'request.uri'} = $uri;
+ $env{'request.uri'} = $uri;
my $filename = '/home/httpd/html' . $uri;
my $fh = Apache::File->new($filename);
my $file;
@@ -263,7 +266,7 @@ sub real_handler {
# Send header, don't cache this page
- if ($ENV{'browser.mathml'}) {
+ if ($env{'browser.mathml'}) {
&Apache::loncommon::content_type($r,'text/xml');
} else {
&Apache::loncommon::content_type($r,'text/html');
@@ -278,7 +281,7 @@ sub real_handler {
my $allowed = $helper->allowedCheck();
if (!$allowed) {
- $ENV{'user.error.msg'} = $ENV{'request.uri'}.':'.$helper->{REQUIRED_PRIV}.
+ $env{'user.error.msg'} = $env{'request.uri'}.':'.$helper->{REQUIRED_PRIV}.
":0:0:Permission denied to access this helper.";
return HTTP_NOT_ACCEPTABLE;
}
@@ -334,7 +337,8 @@ sub start_state {
}
Apache::lonhelper::state->new($token->[2]{'name'},
- $token->[2]{'title'});
+ $token->[2]{'title'},
+ $token->[2]{'help'});
return '';
}
@@ -363,6 +367,8 @@ use HTML::Entities();
use Apache::loncommon;
use Apache::File;
use Apache::lonlocal;
+use Apache::lonnet;
+use LONCAPA;
sub new {
my $proto = shift;
@@ -374,16 +380,16 @@ sub new {
# If there is a state from the previous form, use that. If there is no
# state, use the start state parameter.
- if (defined $ENV{"form.CURRENT_STATE"})
+ if (defined $env{"form.CURRENT_STATE"})
{
- $self->{STATE} = $ENV{"form.CURRENT_STATE"};
+ $self->{STATE} = $env{"form.CURRENT_STATE"};
}
else
{
$self->{STATE} = "START";
}
- $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
# new storage file
# Tried to use standard Tie'd hashes, but you can't seem to take a
@@ -416,16 +422,16 @@ sub new {
return undef;
}
# Must create the storage
- $self->{TOKEN} = md5_hex($ENV{'user.name'} . $ENV{'user.domain'} .
+ $self->{TOKEN} = md5_hex($env{'user.name'} . $env{'user.domain'} .
time() . rand());
$self->{FILENAME} = $Apache::lonnet::tmpdir . md5_hex($self->{TOKEN});
}
# OK, we now have our persistent storage.
- if (defined $ENV{"form.RETURN_PAGE"})
+ if (defined $env{"form.RETURN_PAGE"})
{
- $self->{RETURN_PAGE} = $ENV{"form.RETURN_PAGE"};
+ $self->{RETURN_PAGE} = $env{"form.RETURN_PAGE"};
}
else
{
@@ -468,9 +474,8 @@ sub _saveVars {
sub _varsInFile {
my $self = shift;
my @vars = ();
- for my $key (keys %{$self->{VARS}}) {
- push @vars, &Apache::lonnet::escape($key) . '=' .
- &Apache::lonnet::escape($self->{VARS}->{$key});
+ for my $key (keys(%{$self->{VARS}})) {
+ push(@vars, &escape($key) . '=' . &escape($self->{VARS}->{$key}));
}
return join ('&', @vars);
}
@@ -485,12 +490,12 @@ sub declareVar {
$self->{VARS}->{$var} = '';
}
- my $envname = 'form.' . $var . '.forminput';
- if (defined($ENV{$envname})) {
- if (ref($ENV{$envname})) {
- $self->{VARS}->{$var} = join('|||', @{$ENV{$envname}});
+ my $envname = 'form.' . $var . '_forminput';
+ if (defined($env{$envname})) {
+ if (ref($env{$envname})) {
+ $self->{VARS}->{$var} = join('|||', @{$env{$envname}});
} else {
- $self->{VARS}->{$var} = $ENV{$envname};
+ $self->{VARS}->{$var} = $env{$envname};
}
}
}
@@ -502,7 +507,7 @@ sub allowedCheck {
return 1;
}
- return Apache::lonnet::allowed($self->{REQUIRED_PRIV}, $ENV{'request.course.id'});
+ return Apache::lonnet::allowed($self->{REQUIRED_PRIV}, $env{'request.course.id'});
}
sub changeState {
@@ -524,7 +529,7 @@ sub process {
# Phase 1: Post processing for state of previous screen (which is actually
# the "current state" in terms of the helper variables), if it wasn't the
# beginning state.
- if ($self->{STATE} ne "START" || $ENV{"form.SUBMIT"} eq &mt("Next ->")) {
+ if ($self->{STATE} ne "START" || $env{"form.SUBMIT"} eq &mt("Next ->")) {
my $prevState = $self->{STATES}{$self->{STATE}};
$prevState->postprocess();
}
@@ -576,25 +581,27 @@ sub display {
# Phase 4: Display.
my $stateTitle=&mt($state->title());
- my $helperTitle = &mt($self->{TITLE});
- my $bodytag = &Apache::loncommon::bodytag($helperTitle,'','');
+ my $stateHelp= $state->help();
+ my $browser_searcher_js =
+ '';
+
+ $result .= &Apache::loncommon::start_page($self->{TITLE},
+ $browser_searcher_js);
+
my $previous = HTML::Entities::encode(&mt("<- Previous"), '<>&"');
my $next = HTML::Entities::encode(&mt("Next ->"), '<>&"');
# FIXME: This should be parameterized, not concatenated - Jeremy
- my $loncapaHelper = &mt("LON-CAPA Helper:");
- $result .= <
-
-
- $loncapaHelper: $helperTitle
-
- $bodytag
-HEADER
+
if (!$state->overrideForm()) { $result.="