--- loncom/interface/lonhelper.pm 2004/03/31 05:23:59 1.67
+++ loncom/interface/lonhelper.pm 2006/06/25 21:50:25 1.155
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# .helper XML handler to implement the LON-CAPA helper
#
-# $Id: lonhelper.pm,v 1.67 2004/03/31 05:23:59 albertel Exp $
+# $Id: lonhelper.pm,v 1.155 2006/06/25 21:50:25 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,10 +25,6 @@
#
# http://www.lon-capa.org/
#
-# (Page Handler
-#
-# (.helper handler
-#
=pod
@@ -186,6 +182,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 +255,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 +263,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 +278,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;
}
@@ -371,6 +363,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 +376,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 +418,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
{
@@ -476,9 +470,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);
}
@@ -494,11 +487,11 @@ sub declareVar {
}
my $envname = 'form.' . $var . '.forminput';
- if (defined($ENV{$envname})) {
- if (ref($ENV{$envname})) {
- $self->{VARS}->{$var} = join('|||', @{$ENV{$envname}});
+ 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 +503,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 +525,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();
}
@@ -583,22 +576,20 @@ sub display {
}
# Phase 4: Display.
- my $stateTitle = &mt($state->title());
- my $helperTitle = &mt($self->{TITLE});
- my $bodytag = &Apache::loncommon::bodytag($helperTitle,'','');
+ my $stateTitle=&mt($state->title());
+ 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.="
-