--- loncom/interface/lonhelper.pm 2003/10/09 14:28:09 1.53
+++ loncom/interface/lonhelper.pm 2011/11/05 22:42:14 1.186
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.53 2003/10/09 14:28:09 sakharuk Exp $
+# $Id: lonhelper.pm,v 1.186 2011/11/05 22:42:14 www 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,12 @@ 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
@@ -230,7 +235,7 @@ my $paramHash;
# In the debugger, this means that breakpoints are ignored until you step into
# a function and get out of what must be a "faked up scope" in the Apache->
# mod_perl connection. In this code, it was manifesting itself in the existence
-# of two seperate file-scoped $helper variables, one set to the value of the
+# of two separate file-scoped $helper variables, one set to the value of the
# helper in the helper constructor, and one referenced by the handler on the
# "$helper->process()" line. Using the debugger, one could actually
# see the two different $helper variables, as hashes at completely
@@ -255,7 +260,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,21 +268,13 @@ sub real_handler {
# Send header, don't cache this page
- if ($r->header_only) {
- if ($ENV{'browser.mathml'}) {
- $r->content_type('text/xml; charset=UTF-8');
- } else {
- $r->content_type('text/html; charset=UTF-8');
- }
- $r->send_http_header;
- return OK;
- }
- if ($ENV{'browser.mathml'}) {
- $r->content_type('text/xml');
+ if ($env{'browser.mathml'}) {
+ &Apache::loncommon::content_type($r,'text/xml');
} else {
- $r->content_type('text/html');
+ &Apache::loncommon::content_type($r,'text/html');
}
$r->send_http_header;
+ return OK if $r->header_only;
$r->rflush();
# Discard result, we just want the objects that get created by the
@@ -286,7 +283,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;
}
@@ -342,7 +339,8 @@ sub start_state {
}
Apache::lonhelper::state->new($token->[2]{'name'},
- $token->[2]{'title'});
+ $token->[2]{'title'},
+ $token->[2]{'help'});
return '';
}
@@ -371,6 +369,8 @@ use HTML::Entities();
use Apache::loncommon;
use Apache::File;
use Apache::lonlocal;
+use Apache::lonnet;
+use LONCAPA;
sub new {
my $proto = shift;
@@ -382,16 +382,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
@@ -424,16 +424,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
{
@@ -462,11 +462,11 @@ sub _saveVars {
my $self = shift;
my $result = "";
$result .= '\n";
+ HTML::Entities::encode($self->{STATE},'<>&"') . "\" />\n";
$result .= '\n";
$result .= '\n";
+ HTML::Entities::encode($self->{RETURN_PAGE},'<>&"') . "\" />\n";
return $result;
}
@@ -476,9 +476,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);
}
@@ -493,12 +492,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};
}
}
}
@@ -510,7 +509,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 {
@@ -532,7 +531,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();
}
@@ -572,7 +571,7 @@ sub process {
# 4: Render the current state to the screen as an HTML page.
sub display {
my $self = shift;
-
+ my $footer = shift;
my $state = $self->{STATES}{$self->{STATE}};
my $result = "";
@@ -583,88 +582,86 @@ sub display {
}
# Phase 4: Display.
- my $stateTitle = &mt($state->title());
- my $helperTitle = &mt($self->{TITLE});
- my $bodytag = &Apache::loncommon::bodytag($helperTitle,'','');
- 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:");
+ my $stateTitle=&mt($state->title());
+ my $stateHelp= $state->help();
+ my $browser_searcher_js =
+ '';
+
+ # Breadcrumbs
+ my $brcrum = [{'href' => '',
+ 'text' => 'Helper'}];
+ # FIXME: Dynamically add context sensitive breadcrumbs
+ # depending on the caller,
+ # e.g. printing, parametrization, etc.
+ # FIXME: Add breadcrumbs to reflect current helper state
+
+ $result .= &Apache::loncommon::start_page($self->{TITLE},
+ $browser_searcher_js,
+ {'bread_crumbs' => $brcrum,});
- $result .= <
-
-
- $loncapaHelper: $helperTitle
-
- $bodytag
-HEADER
- if (!$state->overrideForm()) { $result.="
-