--- loncom/interface/lonnavmaps.pm 2001/01/17 17:27:04 1.8
+++ loncom/interface/lonnavmaps.pm 2005/04/11 15:28:55 1.322
@@ -1,280 +1,4780 @@
# The LearningOnline Network with CAPA
# Navigate Maps Handler
#
-# (Page Handler
+# $Id: lonnavmaps.pm,v 1.322 2005/04/11 15:28:55 albertel Exp $
#
-# (TeX Content Handler
+# Copyright Michigan State University Board of Trustees
#
-# 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)
+# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
-# 3/1/1,6/1,17/1 Gerd Kortemeyer
+# LON-CAPA is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# LON-CAPA is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with LON-CAPA; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+# /home/httpd/html/adm/gpl.txt
+#
+# http://www.lon-capa.org/
+#
+###
package Apache::lonnavmaps;
use strict;
-use Apache::Constants qw(:common :http);
-use Apache::lonnet();
-use HTML::TokeParser;
use GDBM_File;
+use Apache::Constants qw(:common :http);
+use Apache::loncommon();
+use Apache::lonmenu();
+use Apache::lonenc();
+use Apache::lonlocal;
+use Apache::lonnet;
+use POSIX qw (floor strftime);
+use Data::Dumper; # for debugging, not always
+use Time::HiRes qw( gettimeofday tv_interval );
+
+# symbolic constants
+sub SYMB { return 1; }
+sub URL { return 2; }
+sub NOTHING { return 3; }
+
+# Some data
-# -------------------------------------------------------------- Module Globals
-my %hash;
-my @rows;
-
-# ------------------------------------------------------------------ Euclid gcd
-
-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;
- }
- return $b;
-}
-
-# ------------------------------------------------------------ Build page table
-
-sub tracetable {
- my ($sofar,$rid,$beenhere)=@_;
- my $further=$sofar;
- unless ($beenhere=~/\&$rid\&/) {
- $beenhere.=$rid.'&';
-
- if (defined($hash{'is_map_'.$rid})) {
- $sofar++;
- my $tprefix='';
- if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
- eq 'sequence') {
- $tprefix='h';
- }
- if (defined($rows[$sofar])) {
- $rows[$sofar].='&'.$tprefix.$rid;
- } else {
- $rows[$sofar]=$tprefix.$rid;
- }
- if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
- (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) &&
- ($tprefix eq 'h')) {
- my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
- $sofar=
- &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
- '&'.$frid.'&');
- $sofar++;
- if ($hash{'src_'.$frid}) {
- my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
- if (($brepriv eq '2') || ($brepriv eq 'F')) {
- my $pprefix='';
- if ($hash{'src_'.$frid}=~/\.problem$/) {
- $pprefix='p1';
- }
- if (defined($rows[$sofar])) {
- $rows[$sofar].='&'.$pprefix.$frid;
- } else {
- $rows[$sofar]=$pprefix.$frid;
- }
- }
- }
- }
- } else {
- $sofar++;
- if ($hash{'src_'.$rid}) {
- my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
- if (($brepriv eq '2') || ($brepriv eq 'F')) {
- my $pprefix='';
- if ($hash{'src_'.$rid}=~/\.problem$/) {
- $pprefix='p1';
- }
- if (defined($rows[$sofar])) {
- $rows[$sofar].='&'.$pprefix.$rid;
- } else {
- $rows[$sofar]=$pprefix.$rid;
- }
- }
- }
- }
-
- if (defined($hash{'to_'.$rid})) {
- my $mincond=1;
- my $next='';
- map {
- my $thiscond=
- &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
- if ($thiscond>=$mincond) {
- if ($next) {
- $next.=','.$_.':'.$thiscond;
- } else {
- $next=$_.':'.$thiscond;
- }
- if ($thiscond>$mincond) { $mincond=$thiscond; }
- }
- } split(/\,/,$hash{'to_'.$rid});
- map {
- my ($linkid,$condval)=split(/\:/,$_);
- if ($condval>=$mincond) {
- my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
- if ($now>$further) { $further=$now; }
- }
- } split(/\,/,$next);
+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,$toplinkitems)=@_;
+ my $result;
+ if ($script ne 'no') {
+ $result.='';
}
- return $further;
+ if ($mode eq 'link') {
+ &add_linkitem($toplinkitems,'launchnav','launch_navmapwin()',
+ "Launch navigation 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
}
-# ================================================================ Main Handler
+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
+}
sub handler {
- my $r=shift;
+ my $r = shift;
+ real_handler($r);
+}
+sub real_handler {
+ my $r = shift;
+ #my $t0=[&gettimeofday()];
+ # 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;
+ }
-# ------------------------------------------- Set document type for header only
+ # 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');
+ }
+ &Apache::loncommon::no_cache($r);
+ $r->send_http_header;
- if ($r->header_only) {
- if ($ENV{'browser.mathml'}) {
- $r->content_type('text/xml');
- } else {
- $r->content_type('text/html');
- }
- $r->send_http_header;
- return OK;
- }
-
- my $requrl=$r->uri;
-# ----------------------------------------------------------------- Tie db file
- if ($ENV{'request.course.fn'}) {
- my $fn=$ENV{'request.course.fn'};
- if (-e "$fn.db") {
- if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
-# ------------------------------------------------------------------- Hash tied
- my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
- my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
- if (($firstres) && ($lastres)) {
-# ----------------------------------------------------------------- Render page
-
- @rows=();
-
- &tracetable(0,$firstres,'&'.$lastres.'&');
- if ($hash{'src_'.$lastres}) {
- my $brepriv=
- &Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
- if (($brepriv eq '2') || ($brepriv eq 'F')) {
- $rows[$#rows+1]=''.$lastres;
- }
- }
-
-# ------------------------------------------------------------------ Page parms
-
- my $j;
- my $i;
- my $lcm=1;
- my $contents=0;
-
-# ---------------------------------------------- Go through table to get layout
-
- for ($i=0;$i<=$#rows;$i++) {
- if ($rows[$i]) {
- $contents++;
- my @colcont=split(/\&/,$rows[$i]);
- $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
- }
- }
-
-
- unless ($contents) {
- $r->content_type('text/html');
- $r->send_http_header;
- $r->print('Empty Map.');
- } else {
-# ------------------------------------------------------------------ Build page
-
-# ---------------------------------------------------------------- Send headers
-
- $r->content_type('text/html');
- $r->send_http_header;
- $r->print(
- 'Navigate LON-CAPA Maps');
-
- $r->print(''.
- ''.
- ''.
- 'Navigate Course Map
');
- $r->rflush();
-# ----------------------------------------------------------------- Start table
- $r->print('');
- for ($i=0;$i<=$#rows;$i++) {
- if ($rows[$i]) {
- $r->print("\n");
- my @colcont=split(/\&/,$rows[$i]);
- my $avespan=$lcm/($#colcont+1);
- for ($j=0;$j<=$#colcont;$j++) {
- my $rid=$colcont[$j];
- my $add=' ';
- my $adde=' | ';
- my $hwk='';
- my $hwke='';
- if ($rid=~/^h(.+)/) {
- $rid=$1;
- $add='';
- $adde=' | ';
- }
- if ($rid=~/^p(\d)(.+)/) {
- my $code=$1;
- $rid=$2;
- $hwk='';
- if ($code eq '2') {
- $hwk='';
- $hwke='';
- }
- if ($code eq '3') {
- $hwk='';
- } elsif ($code eq '4') {
- $hwk='';
- }
- }
- $r->print($add.''.$hwk.
- $hash{'title_'.$rid}.$hwke.''.$adde);
- }
- $r->print('
');
- }
+ my %toplinkitems=();
+ &add_linkitem(\%toplinkitems,'blank','',"Select Action");
+ if ($ENV{QUERY_STRING} eq 'collapseExternal') {
+ &Apache::lonnet::put('environment',{'remotenavmap' => 'off'});
+ &Apache::lonnet::appenv('environment.remotenavmap' => 'off');
+ my $menu=&Apache::lonmenu::reopenmenu();
+ my $navstatus=&Apache::lonmenu::get_nav_status();
+ if ($menu) {
+ $menu=(<