--- loncom/interface/lonnavmaps.pm 2002/09/24 03:48:18 1.53
+++ loncom/interface/lonnavmaps.pm 2004/08/10 20:52:03 1.274
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# $Id: lonnavmaps.pm,v 1.53 2002/09/24 03:48:18 bowersj2 Exp $
+# $Id: lonnavmaps.pm,v 1.274 2004/08/10 20:52:03 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -25,1071 +25,1876 @@
#
# http://www.lon-capa.org/
#
-# (Page Handler
-#
-# (TeX Content Handler
-#
-# 05/29/00,05/30 Gerd Kortemeyer)
-# 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
-# 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)
-#
-# 3/1/1,6/1,17/1,29/1,30/1,2/8,9/21,9/24,9/25 Gerd Kortemeyer
-# YEAR=2002
-# 1/1 Gerd Kortemeyer
-#
+###
package Apache::lonnavmaps;
use strict;
use Apache::Constants qw(:common :http);
-use Apache::lonnet();
use Apache::loncommon();
-use HTML::TokeParser;
-use GDBM_File;
-
-# -------------------------------------------------------------- Module Globals
-my %hash;
-my @rows;
-
-#
-# These cache hashes need to be independent of user, resource and course
-# (user and course can/should be in the keys)
-#
-
-my %courserdatas;
-my %userrdatas;
+use Apache::lonmenu();
+use Apache::lonlocal;
+use POSIX qw (floor strftime);
+use Data::Dumper; # for debugging, not always used
+
+# symbolic constants
+sub SYMB { return 1; }
+sub URL { return 2; }
+sub NOTHING { return 3; }
+
+# Some data
+
+my $resObj = "Apache::lonnavmaps::resource";
+
+# Keep these mappings in sync with lonquickgrades, which uses the colors
+# instead of the icons.
+my %statusIconMap =
+ (
+ $resObj->CLOSED => '',
+ $resObj->OPEN => 'navmap.open.gif',
+ $resObj->CORRECT => 'navmap.correct.gif',
+ $resObj->INCORRECT => 'navmap.wrong.gif',
+ $resObj->ATTEMPTED => 'navmap.ellipsis.gif',
+ $resObj->ERROR => ''
+ );
+
+my %iconAltTags =
+ ( 'navmap.correct.gif' => 'Correct',
+ 'navmap.wrong.gif' => 'Incorrect',
+ 'navmap.open.gif' => 'Open' );
+
+# Defines a status->color mapping, null string means don't color
+my %colormap =
+ ( $resObj->NETWORK_FAILURE => '',
+ $resObj->CORRECT => '',
+ $resObj->EXCUSED => '#3333FF',
+ $resObj->PAST_DUE_ANSWER_LATER => '',
+ $resObj->PAST_DUE_NO_ANSWER => '',
+ $resObj->ANSWER_OPEN => '#006600',
+ $resObj->OPEN_LATER => '',
+ $resObj->TRIES_LEFT => '',
+ $resObj->INCORRECT => '',
+ $resObj->OPEN => '',
+ $resObj->NOTHING_SET => '',
+ $resObj->ATTEMPTED => '',
+ $resObj->ANSWER_SUBMITTED => ''
+ );
+# And a special case in the nav map; what to do when the assignment
+# is not yet done and due in less then 24 hours
+my $hurryUpColor = "#FF0000";
+
+sub launch_win {
+ my ($mode,$script)=@_;
+ my $result;
+ if ($script ne 'no') {
+ $result.='';
+ }
+ if ($mode eq 'link') {
+ $result.=''
+ .&mt("Launch navigation in separate window")." ";
+ }
+ return $result;
+}
+
+sub close {
+ if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
+ return(<
+window.status='Accessing Nav Control';
+menu=window.open("/adm/rat/empty.html","loncapanav",
+ "height=600,width=400,scrollbars=1");
+window.status='Closing Nav Control';
+menu.close();
+window.status='Done.';
+
+ENDCLOSE
+}
+
+sub update {
+ if ($ENV{'environment.remotenavmap'} ne 'on') { return ''; }
+ if (!$ENV{'request.course.id'}) { return ''; }
+ if ($ENV{'REQUEST_URI'}=~m|^/adm/navmaps|) { return ''; }
+ return(<
+
+ENDUPDATE
+}
-#
-# These global hashes are dependent on user, course and resource,
-# and need to be initialized every time when a sheet is calculated
-#
-my %courseopt;
-my %useropt;
-my %parmhash;
+sub handler {
+ my $r = shift;
+ real_handler($r);
+}
-# This parameter keeps track of whether obtaining the user's information
-# failed, which the colorizer in astatus can use
-my $networkFailedFlag = 0;
+sub real_handler {
+ my $r = shift;
-# ------------------------------------------------------------------ Euclid gcd
+ # Handle header-only request
+ if ($r->header_only) {
+ if ($ENV{'browser.mathml'}) {
+ &Apache::loncommon::content_type($r,'text/xml');
+ } else {
+ &Apache::loncommon::content_type($r,'text/html');
+ }
+ $r->send_http_header;
+ return OK;
+ }
-sub euclid {
- my ($e,$f)=@_;
- my $a; my $b; my $r;
- if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
- while ($r!=0) {
- $a=$b; $b=$r;
- $r=$a%$b;
+ # Send header, don't cache this page
+ if ($ENV{'browser.mathml'}) {
+ &Apache::loncommon::content_type($r,'text/xml');
+ } else {
+ &Apache::loncommon::content_type($r,'text/html');
}
- return $b;
-}
+ &Apache::loncommon::no_cache($r);
+ $r->send_http_header;
-# --------------------------------------------------------------------- Parmval
+ if ($ENV{QUERY_STRING} eq 'collapseExternal') {
+ &Apache::lonnet::put('environment',{'remotenavmap' => 'off'});
+ &Apache::lonnet::appenv('environment.remotenavmap' => 'off');
+ $r->print(<<"ENDSUBM");
+
+
+
+
+
+
+ENDSUBM
+ return;
+ }
+ if ($ENV{QUERY_STRING} eq 'launchExternal') {
+ &Apache::lonnet::put('environment',{'remotenavmap' => 'on'});
+ &Apache::lonnet::appenv('environment.remotenavmap' => 'on');
+ }
-# -------------------------------------------- Figure out a cascading parameter
-#
-# For this function to work
-#
-# * parmhash needs to be tied
-# * courseopt and useropt need to be initialized for this user and course
-#
+ # Create the nav map
+ my $navmap = Apache::lonnavmaps::navmap->new();
-sub parmval {
- my ($what,$symb)=@_;
- my $cid=$ENV{'request.course.id'};
- my $csec=$ENV{'request.course.sec'};
- my $uname=$ENV{'user.name'};
- my $udom=$ENV{'user.domain'};
+ if (!defined($navmap)) {
+ my $requrl = $r->uri;
+ $ENV{'user.error.msg'} = "$requrl:bre:0:0:Course not initialized";
+ return HTTP_NOT_ACCEPTABLE;
+ }
- unless ($symb) { return ''; }
- my $result='';
+ $r->print("\n");
+ $r->print("".&mt('Navigate Course Contents')."");
+# ------------------------------------------------------------ Get query string
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['register','sort']);
+
+# ----------------------------------------------------- Force menu registration
+ my $addentries='';
+ my $more_unload;
+ if ($ENV{'environment.remotenavmap'} eq 'on') {
+ $r->print('');
+# FIXME need to be smarter to only catch window close events
+# $more_unload="collapse()"
+ }
+ if ($ENV{'form.register'}) {
+ $addentries=' onLoad="'.&Apache::lonmenu::loadevents().
+ '" onUnload="'.&Apache::lonmenu::unloadevents().';'.
+ $more_unload.'"';
+ $r->print(&Apache::lonmenu::registerurl(1));
+ } else {
+ $addentries=' onUnload="'.$more_unload.'"';
+ }
- my ($mapname,$id,$fn)=split(/\_\_\_/,$symb);
+ # Header
+ $r->print(''.
+ &Apache::loncommon::bodytag('Navigate Course Contents','',
+ $addentries,'','',$ENV{'form.register'}));
+ $r->print(''.
+ &Apache::loncommon::help_open_menu('','Navigation Screen','Navigation_Screen','',undef,'RAT'));
+
+ $r->rflush();
+
+ # Check that it's defined
+ if (!($navmap->courseMapDefined())) {
+ $r->print('Coursemap undefined.' .
+ '