Annotation of loncom/interface/lonnavmaps.pm, revision 1.47

1.2       www         1: # The LearningOnline Network with CAPA
                      2: # Navigate Maps Handler
1.1       www         3: #
1.47    ! bowersj2    4: # $Id: lonnavmaps.pm,v 1.46 2002/09/02 19:35:31 bowersj2 Exp $
1.20      albertel    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
1.2       www        28: # (Page Handler
1.1       www        29: #
1.2       www        30: # (TeX Content Handler
1.1       www        31: #
1.2       www        32: # 05/29/00,05/30 Gerd Kortemeyer)
                     33: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
                     34: # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)
1.1       www        35: #
1.17      www        36: # 3/1/1,6/1,17/1,29/1,30/1,2/8,9/21,9/24,9/25 Gerd Kortemeyer
1.21      www        37: # YEAR=2002
                     38: # 1/1 Gerd Kortemeyer
                     39: #
1.2       www        40: 
1.1       www        41: package Apache::lonnavmaps;
                     42: 
                     43: use strict;
1.2       www        44: use Apache::Constants qw(:common :http);
                     45: use Apache::lonnet();
1.18      albertel   46: use Apache::loncommon();
1.2       www        47: use HTML::TokeParser;
                     48: use GDBM_File;
                     49: 
                     50: # -------------------------------------------------------------- Module Globals
                     51: my %hash;
                     52: my @rows;
                     53: 
1.10      www        54: #
                     55: # These cache hashes need to be independent of user, resource and course
                     56: # (user and course can/should be in the keys)
                     57: #
                     58: 
                     59: my %courserdatas;
                     60: my %userrdatas;
                     61: 
                     62: #
                     63: # These global hashes are dependent on user, course and resource, 
                     64: # and need to be initialized every time when a sheet is calculated
                     65: #
                     66: my %courseopt;
                     67: my %useropt;
                     68: my %parmhash;
                     69: 
1.47    ! bowersj2   70: # This parameter keeps track of whether obtaining the user's information
        !            71: # failed, which the colorizer in astatus can use
        !            72: my $networkFailedFlag = 0;
        !            73: 
1.2       www        74: # ------------------------------------------------------------------ Euclid gcd
                     75: 
                     76: sub euclid {
                     77:     my ($e,$f)=@_;
                     78:     my $a; my $b; my $r;
                     79:     if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
                     80:     while ($r!=0) {
                     81: 	$a=$b; $b=$r;
                     82:         $r=$a%$b;
                     83:     }
                     84:     return $b;
                     85: }
                     86: 
1.10      www        87: # --------------------------------------------------------------------- Parmval
                     88: 
                     89: # -------------------------------------------- Figure out a cascading parameter
                     90: #
                     91: # For this function to work
                     92: #
                     93: # * parmhash needs to be tied
                     94: # * courseopt and useropt need to be initialized for this user and course
                     95: #
                     96: 
                     97: sub parmval {
                     98:     my ($what,$symb)=@_;
                     99:     my $cid=$ENV{'request.course.id'};
                    100:     my $csec=$ENV{'request.course.sec'};
                    101:     my $uname=$ENV{'user.name'};
                    102:     my $udom=$ENV{'user.domain'};
                    103: 
                    104:     unless ($symb) { return ''; }
                    105:     my $result='';
                    106: 
                    107:     my ($mapname,$id,$fn)=split(/\_\_\_/,$symb);
                    108: 
                    109: # ----------------------------------------------------- Cascading lookup scheme
1.24      albertel  110:     my $rwhat=$what;
                    111:     $what=~s/^parameter\_//;
                    112:     $what=~s/\_/\./;
                    113: 
                    114:     my $symbparm=$symb.'.'.$what;
                    115:     my $mapparm=$mapname.'___(all).'.$what;
                    116:     my $usercourseprefix=$uname.'_'.$udom.'_'.$cid;
                    117: 
                    118:     my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what;
                    119:     my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm;
                    120:     my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm;
                    121: 
                    122:     my $courselevel= $usercourseprefix.'.'.$what;
                    123:     my $courselevelr=$usercourseprefix.'.'.$symbparm;
                    124:     my $courselevelm=$usercourseprefix.'.'.$mapparm;
                    125: 
                    126: # ---------------------------------------------------------- first, check user
                    127:     if ($uname) {
                    128: 	if ($useropt{$courselevelr}) { return $useropt{$courselevelr}; }
                    129: 	if ($useropt{$courselevelm}) { return $useropt{$courselevelm}; }
                    130: 	if ($useropt{$courselevel}) { return $useropt{$courselevel}; }
                    131:     }
1.10      www       132: 
1.24      albertel  133: # ------------------------------------------------------- second, check course
                    134:     if ($csec) {
                    135: 	if ($courseopt{$seclevelr}) { return $courseopt{$seclevelr}; }
1.25      albertel  136:         if ($courseopt{$seclevelm}) { return $courseopt{$seclevelm}; }
1.10      www       137:         if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; }
1.24      albertel  138:     }
1.10      www       139: 
1.24      albertel  140:     if ($courseopt{$courselevelr}) { return $courseopt{$courselevelr}; }
                    141:     if ($courseopt{$courselevelm}) { return $courseopt{$courselevelm}; }
                    142:     if ($courseopt{$courselevel}) { return $courseopt{$courselevel}; }
1.10      www       143: 
1.24      albertel  144: # ----------------------------------------------------- third, check map parms
1.10      www       145: 
1.24      albertel  146:     my $thisparm=$parmhash{$symbparm};
                    147:     if ($thisparm) { return $thisparm; }
1.10      www       148: 
1.24      albertel  149: # ----------------------------------------------------- fourth , check default
1.10      www       150: 
1.25      albertel  151:     my $default=&Apache::lonnet::metadata($fn,$rwhat.'.default');
                    152:     if ($default) { return $default}
                    153: 
                    154: # --------------------------------------------------- fifth , cascade up parts
                    155: 
                    156:     my ($space,@qualifier)=split(/\./,$rwhat);
                    157:     my $qualifier=join('.',@qualifier);
                    158:     unless ($space eq '0') {
                    159: 	my ($part,$id)=split(/\_/,$space);
                    160: 	if ($id) {
                    161: 	    my $partgeneral=&parmval($part.".$qualifier",$symb);
                    162: 	    if ($partgeneral) { return $partgeneral; }
                    163: 	} else {
                    164: 	    my $resourcegeneral=&parmval("0.$qualifier",$symb);
                    165: 	    if ($resourcegeneral) { return $resourcegeneral; }
                    166: 	}
                    167:     }
                    168:     return '';
1.10      www       169: }
                    170: 
                    171: 
                    172: 
1.9       www       173: # ------------------------------------------------------------- Find out status
1.25      albertel  174: # return codes
                    175: # tcode (timecode)
                    176: # 1: will open later
                    177: # 2: is open and not past due yet
                    178: # 3: is past due date
                    179: # 4: due in the next 24 hours
                    180: #
                    181: # code (curent solved status)
                    182: # 1: not attempted
                    183: # 2: attempted but wrong, or incorrect by instructor
                    184: # 3: solved or correct by instructor
1.29      albertel  185: # 4: partially correct (one or more parts correct)
                    186: # "excused" needs to be supported, but is not yet.
1.9       www       187: sub astatus {
                    188:     my $rid=shift;
1.29      albertel  189:     my $code=0;
1.9       www       190:     my $ctext='';
                    191:     $rid=~/(\d+)\.(\d+)/;
1.10      www       192:     my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
1.24      albertel  193: 	&Apache::lonnet::declutter($hash{'src_'.$rid});
1.15      www       194:     my %duedate=();
                    195:     my %opendate=();
                    196:     my %answerdate=();
1.25      albertel  197:     # need to always check part 0's open/due/answer status
                    198:     foreach (sort(split(/\,/,&Apache::lonnet::metadata($hash{'src_'.$rid},'keys')))) {
1.15      www       199:         if ($_=~/^parameter\_(.*)\_opendate$/) {
                    200: 	    my $part=$1;
                    201:             $duedate{$part}=&parmval($part.'.duedate',$symb);
                    202:             $opendate{$part}=&parmval($part.'.opendate',$symb);
                    203:             $answerdate{$part}=&parmval($part.'.answerdate',$symb);
                    204:         }
1.25      albertel  205:     }
1.11      www       206:     my $now=time;
                    207:     my $tcode=0;
1.16      www       208: 
                    209:     my %returnhash=&Apache::lonnet::restore($symb);
                    210: 
1.25      albertel  211:     foreach (sort(keys(%opendate))) {
1.24      albertel  212: 	my $duedate=$duedate{$_};
                    213: 	my $opendate=$opendate{$_};
                    214: 	my $answerdate=$answerdate{$_};
                    215: 	my $preface='';
                    216: 	unless ($_ eq '0') { $preface=' Part: '.$_.' '; }
                    217: 	if ($opendate) {
1.25      albertel  218: 	    if ($now<$duedate || (!$duedate)) {
                    219: 		unless ($tcode==4) { $tcode=2; }
                    220: 		if ($duedate) {
                    221: 		    $ctext.=$preface.'Due: '.localtime($duedate);
                    222: 		} else {
                    223: 		    $ctext.=$preface.'No Due Date';
                    224: 		}
                    225: 		if ($now<$opendate) {
                    226: 		    unless ($tcode) { $tcode=1; }
1.24      albertel  227: 		    $ctext.=$preface.'Open: '.localtime($opendate);
                    228: 		}
1.25      albertel  229: 		if ($duedate && $duedate-$now<86400) {
1.24      albertel  230: 		    $tcode=4;
                    231: 		    $ctext.=$preface.'Due: '.localtime($duedate);
                    232: 		}
                    233: 	    } else {
                    234: 		unless (($tcode==4) || ($tcode eq 2)) { $tcode=3; }
1.25      albertel  235: 		if ($now<$answerdate) {
1.24      albertel  236: 		    $ctext.='Answer: '.localtime($duedate);
                    237: 		}
                    238: 	    }
                    239: 	} else {
                    240: 	    unless (($tcode==2) || ($tcode==4)) { $tcode=1; }
                    241: 	}
                    242: 	
                    243: 	my $status=$returnhash{'resource.'.$_.'.solved'};
1.25      albertel  244: 	
1.24      albertel  245: 	if ($status eq 'correct_by_student') {
1.30      albertel  246: 	    if ($code==0||$code==3) { $code=3; } else { $code=4; }
1.24      albertel  247: 	    $ctext.=' solved';
                    248: 	} elsif ($status eq 'correct_by_override') {
1.30      albertel  249: 	    if ($code==0||$code==3) { $code=3; } else { $code=4; }
1.24      albertel  250: 	    $ctext.=' override';
                    251: 	} elsif ($status eq 'incorrect_attempted') {
1.29      albertel  252: 	    if ($code!=4 && $code!=3) { $code=2; }
                    253: 	    if ($code==3) { $code=4; }
1.24      albertel  254: 	    $ctext.=' ('.
                    255: 		($returnhash{'resource.'.$_.'.tries'}?
1.25      albertel  256: 		 $returnhash{'resource.'.$_.'.tries'}:'0');
                    257: 	    my $numtries = &parmval($_.'.maxtries',$symb);
                    258: 	    if ($numtries) { $ctext.='/'.$numtries.' tries'; }
                    259: 	    $ctext.=')';
1.24      albertel  260: 	} elsif ($status eq 'incorrect_by_override') {
1.29      albertel  261: 	    if ($code!=4 && $code!=3) { $code=2; }
                    262: 	    if ($code==3) { $code=4; }
1.24      albertel  263: 	    $ctext.=' override';
                    264: 	} elsif ($status eq 'excused') {
1.30      albertel  265: 	    if ($code==0||$code==3) { $code=3; } else { $code=4; }
1.24      albertel  266: 	    $ctext.=' excused';
1.29      albertel  267: 	} else {
                    268: 	    if ($code==0) { $code=1; }
1.24      albertel  269: 	}
1.25      albertel  270:     }
1.16      www       271: 
1.11      www       272:     return 'p'.$code.$tcode.'"'.$ctext.'"';
1.9       www       273: }
                    274: 
1.2       www       275: 
1.31      albertel  276: sub addresource {
1.32      albertel  277:     my ($resource,$sofar,$rid,$showtypes,$indent,$linkid)=@_;
1.31      albertel  278:     if ($showtypes eq 'problems') {
                    279: 	if ($resource!~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    280: 	    return;
1.32      albertel  281: 	}
1.31      albertel  282:     }
                    283:     my $brepriv=&Apache::lonnet::allowed('bre',$resource);
                    284:     if ($hash{'src_'.$rid}) {
1.37      www       285: 	if (($brepriv eq '2') || ($brepriv eq 'F')) {
1.31      albertel  286: 	    my $pprefix='';
                    287: 	    if ($resource=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    288: 		$pprefix=&astatus($rid);
1.28      albertel  289: 	    }
1.32      albertel  290: 	    $$sofar++;
                    291: 	    if ($indent) { $pprefix='i'.$indent.','.$pprefix; }
                    292: 	    if ($linkid) { $pprefix='l'.$linkid.','.$pprefix; }
                    293: 	    if (defined($rows[$$sofar])) {
                    294: 		$rows[$$sofar].='&'.$pprefix.$rid;
1.28      albertel  295: 	    } else {
1.32      albertel  296: 		$rows[$$sofar]=$pprefix.$rid;
1.28      albertel  297: 	    }
1.31      albertel  298: 	}
                    299:     }
                    300: }
                    301: 
                    302: sub followlinks () {
1.32      albertel  303:     my ($rid,$sofar,$beenhere,$further,$showtypes,$indent,$linkid)=@_;
1.31      albertel  304:     my $mincond=1;
                    305:     my $next='';
                    306:     foreach (split(/\,/,$hash{'to_'.$rid})) {
                    307: 	my $thiscond=
                    308: 	    &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
                    309: 	if ($thiscond>=$mincond) {
                    310: 	    if ($next) {
                    311: 		$next.=','.$_.':'.$thiscond;
                    312: 	    } else {
                    313: 		$next=$_.':'.$thiscond;
1.28      albertel  314: 	    }
1.31      albertel  315: 	    if ($thiscond>$mincond) { $mincond=$thiscond; }
                    316: 	}
                    317:     }
1.32      albertel  318:     my $col=0;
                    319:     &Apache::lonxml::debug("following links -$next-");
1.31      albertel  320:     foreach (split(/\,/,$next)) {
1.32      albertel  321: 	my ($nextlinkid,$condval)=split(/\:/,$_);
1.31      albertel  322: 	if ($condval>=$mincond) {
1.32      albertel  323: 	    my $now=&tracetable($sofar,$hash{'goesto_'.$nextlinkid},
                    324: 				$beenhere,$showtypes,$indent,$linkid);
                    325: 	    if ($now>$further) {		
                    326: 		if ($col>0) {
                    327: 		    my $string;
                    328: 		    for(my $i=0;$i<$col;$i++) { $string.='&'; }
                    329: 		    for(my $i=$further+1;$now-1>$i;$i++) {
                    330: 			$rows[$i]=$string.$rows[$i];
                    331: 		    }
                    332: 		}
                    333: 		$further=$now;
                    334: 	    }
1.31      albertel  335: 	}
1.32      albertel  336: 	$col++;
1.31      albertel  337:     }
                    338:     return $further;
                    339: }
                    340: # ------------------------------------------------------------ Build page table
                    341: 
                    342: sub tracetable {
1.32      albertel  343:     my ($sofar,$rid,$beenhere,$showtypes,$indent,$linkid)=@_;
                    344:     my $newshowtypes=$showtypes;
1.31      albertel  345:     my $further=$sofar;
1.44      www       346: # $Apache::lonxml::debug=1;
1.32      albertel  347:     &Apache::lonxml::debug("$rid ; $linkid ; $sofar ; $beenhere ; ".$hash{'src_'.$rid});
                    348:     if ($beenhere=~/\&$rid\&/) { return $further; }
                    349:     $beenhere.=$rid.'&';
1.31      albertel  350: 
                    351:     if (defined($hash{'is_map_'.$rid})) {
                    352: 	$sofar++;
                    353: 	my $tprefix='';
                    354: 	if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
                    355: 	    eq 'sequence') {
                    356: 	    $tprefix='h';
                    357: 	} elsif ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
                    358: 		 eq 'page') {
1.32      albertel  359: 	    $tprefix='j';
                    360: 	    if ($indent) { $tprefix='i'.$indent.','.$tprefix; }
1.33      albertel  361: 	    if ($linkid) { $tprefix='l'.$linkid.','.$tprefix; }
1.32      albertel  362: 	    $newshowtypes='problems';
                    363: 	    $indent++;
1.33      albertel  364: 	    #if in a .page continue to link the encompising .page
                    365: 	    if (!$linkid) { $linkid=$rid; }
1.31      albertel  366: 	}
                    367: 	if (defined($rows[$sofar])) {
                    368: 	    $rows[$sofar].='&'.$tprefix.$rid;
1.28      albertel  369: 	} else {
1.31      albertel  370: 	    $rows[$sofar]=$tprefix.$rid;
                    371: 	}
                    372: 	if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
                    373: 	    (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
                    374: 	    my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
1.32      albertel  375: 	    $sofar=&tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
1.33      albertel  376: 			       '&'.$frid.'&',$newshowtypes,$indent,$linkid);
1.32      albertel  377: 	    &addresource($hash{'src_'.$frid},\$sofar,$frid,$newshowtypes,
1.33      albertel  378: 			 $indent,$linkid);
                    379: 	    if ($tprefix =~ /j$/) { $indent--; $linkid=''; }
1.28      albertel  380: 	}
1.31      albertel  381:     } else {
1.32      albertel  382: 	&addresource($hash{'src_'.$rid},\$sofar,$rid,$showtypes,
                    383: 		     $indent,$linkid);
1.31      albertel  384:     }
                    385: 
                    386:     if (defined($hash{'to_'.$rid})) {
1.32      albertel  387: 	$further=&followlinks($rid,$sofar,$beenhere,$further,$showtypes,
                    388: 			      $indent,$linkid);
1.2       www       389:     }
1.31      albertel  390: 
1.2       www       391:     return $further;
                    392: }
                    393: 
                    394: # ================================================================ Main Handler
1.1       www       395: 
                    396: sub handler {
1.28      albertel  397:     my $r=shift;
1.2       www       398: 
                    399: 
                    400: # ------------------------------------------- Set document type for header only
                    401: 
1.28      albertel  402:     if ($r->header_only) {
                    403: 	if ($ENV{'browser.mathml'}) {
                    404: 	    $r->content_type('text/xml');
                    405: 	} else {
                    406: 	    $r->content_type('text/html');
                    407: 	}
                    408: 	$r->send_http_header;
                    409: 	return OK;
                    410:     }
                    411:     my $requrl=$r->uri;
                    412:     my $hashtied;
1.2       www       413: # ----------------------------------------------------------------- Tie db file
1.28      albertel  414:     my $fn;
                    415:     if ($ENV{'request.course.fn'}) {
                    416: 	$fn=$ENV{'request.course.fn'};
                    417: 	if (-e "$fn.db") {
1.40      albertel  418: 	    if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) &&
1.28      albertel  419: 		(tie(%parmhash,'GDBM_File',
                    420: 		     $ENV{'request.course.fn'}.'_parms.db',
1.40      albertel  421: 		     &GDBM_READER(),0640))) {
1.28      albertel  422: 		$hashtied=1;
                    423: 	    }
                    424: 	}
                    425:     }
                    426:     if (!$hashtied) {
                    427: 	$ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    428: 	return HTTP_NOT_ACCEPTABLE; 
                    429:     }
                    430: 
1.2       www       431: # ------------------------------------------------------------------- Hash tied
1.28      albertel  432: 
                    433:     if ($ENV{'browser.mathml'}) {
                    434: 	$r->content_type('text/xml');
                    435:     } else {
                    436: 	$r->content_type('text/html');
                    437:     }
                    438:     &Apache::loncommon::no_cache($r);
                    439:     $r->send_http_header;
                    440: 
1.42      www       441:     my $firstres=$hash{'map_start_'.
                    442:            &Apache::lonnet::clutter($ENV{'request.course.uri'})};
                    443:     my $lastres=$hash{'map_finish_'.
                    444:            &Apache::lonnet::clutter($ENV{'request.course.uri'})};
1.28      albertel  445:     if (!(($firstres) && ($lastres))) {
                    446: 	$r->print('<html><body>Coursemap undefined.</body></html>');
                    447:     } else {
                    448: 
1.2       www       449: # ----------------------------------------------------------------- Render page
1.10      www       450: # -------------------------------------------------------------- Set parameters
                    451: 
                    452: 
                    453: # ---------------------------- initialize coursedata and userdata for this user
1.28      albertel  454: 	undef %courseopt;
                    455: 	undef %useropt;
1.10      www       456: 
1.28      albertel  457: 	my $uname=$ENV{'user.name'};
                    458: 	my $udom=$ENV{'user.domain'};
                    459: 	my $uhome=$ENV{'user.home'};
                    460: 	my $cid=$ENV{'request.course.id'};
                    461: 	my $chome=$ENV{'course.'.$cid.'.home'};
                    462: 	my ($cdom,$cnum)=split(/\_/,$cid);
1.10      www       463: 
1.28      albertel  464: 	my $userprefix=$uname.'_'.$udom.'_';
1.47    ! bowersj2  465: 	
1.28      albertel  466: 	unless ($uhome eq 'no_host') { 
1.10      www       467: # -------------------------------------------------------------- Get coursedata
1.28      albertel  468: 	    unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
                    469: 		my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
                    470: 						 ':resourcedata',$chome);
                    471: 		if ($reply!~/^error\:/) {
                    472: 		    $courserdatas{$cid}=$reply;
                    473: 		    $courserdatas{$cid.'.last_cache'}=time;
                    474: 		}
1.47    ! bowersj2  475: 		else
        !           476: 		{
        !           477: 		    $networkFailedFlag = 1;
        !           478: 		}
1.28      albertel  479: 	    }
                    480: 	    foreach (split(/\&/,$courserdatas{$cid})) {
                    481: 		my ($name,$value)=split(/\=/,$_);
                    482: 		$courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
                    483: 		    &Apache::lonnet::unescape($value);
                    484: 	    }
1.10      www       485: # --------------------------------------------------- Get userdata (if present)
1.28      albertel  486: 	    unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
                    487: 		my $reply=&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
                    488: 		if ($reply!~/^error\:/) {
                    489: 		    $userrdatas{$uname.'___'.$udom}=$reply;
                    490: 		    $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
                    491: 		}
                    492: 	    }
                    493: 	    foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
                    494: 		my ($name,$value)=split(/\=/,$_);
                    495: 		$useropt{$userprefix.&Apache::lonnet::unescape($name)}=
                    496: 		    &Apache::lonnet::unescape($value);
                    497: 	    }
                    498: 	}
                    499: 
                    500: 	@rows=();
                    501: 
1.44      www       502: 	&tracetable(0,$firstres,'&','',0);
1.2       www       503: 
                    504: # ------------------------------------------------------------------ Page parms
                    505: 
1.28      albertel  506: 	my $j;
                    507: 	my $i;
                    508: 	my $lcm=1;
                    509: 	my $contents=0;
1.2       www       510: 
                    511: # ---------------------------------------------- Go through table to get layout
                    512: 
1.28      albertel  513: 	for ($i=0;$i<=$#rows;$i++) {
                    514: 	    if ($rows[$i]) {
1.32      albertel  515: 		&Apache::lonxml::debug("Row $i is:".$rows[$i]);
1.28      albertel  516: 		$contents++;
                    517: 		my @colcont=split(/\&/,$rows[$i]);
                    518: 		$lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
                    519: 	    } 
                    520: 	}
1.5       www       521: 
1.2       www       522: 
1.28      albertel  523: 	unless ($contents) {
                    524: 	    $r->print('<html><body>Empty Map.</body></html>');
                    525: 	} else {
1.10      www       526: 
1.2       www       527: # ------------------------------------------------------------------ Build page
                    528: 
1.28      albertel  529: 	    my $currenturl=$ENV{'form.postdata'};
                    530: 	    $currenturl=~s/^http\:\/\///;
                    531: 	    $currenturl=~s/^[^\/]+//;
1.13      www       532: 
1.2       www       533: # ---------------------------------------------------------------- Send headers
                    534: 
1.28      albertel  535: 	    my $date=localtime;
                    536: 	    my $now=time;
1.21      www       537: # ----------------------------------------- Get email status and discussiontime
                    538: 
1.28      albertel  539: 	    my %emailstatus=&Apache::lonnet::dump('email_status');
                    540: 	    my $logouttime=$emailstatus{'logout'};
                    541: 	    my $courseleave=$emailstatus{'logout_'.$ENV{'request.course.id'}};
                    542: 	    my $lastcheck=($courseleave>$logouttime?$courseleave:$logouttime);
                    543: 
                    544: 	    my %discussiontimes=&Apache::lonnet::dump('discussiontimes',
                    545: 							  $cdom,$cnum);
                    546: 
                    547: 	    my %feedback=();
                    548: 	    my %error=();
                    549: 	    foreach my $msgid (split(/\&/,&Apache::lonnet::reply('keys:'.
                    550: 								 $ENV{'user.domain'}.':'.
                    551: 								 $ENV{'user.name'}.':nohist_email',
                    552: 								 $ENV{'user.home'}))) {
                    553: 		$msgid=&Apache::lonnet::unescape($msgid);
                    554: 		my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
                    555: 		if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
                    556: 		    my ($what,$url)=($1,$2);
                    557: 		    my %status=
                    558: 			&Apache::lonnet::get('email_status',[$msgid]);
                    559: 		    if ($status{$msgid}=~/^error\:/) { 
                    560: 			$status{$msgid}=''; 
                    561: 		    }
                    562: 			
                    563: 		    if (($status{$msgid} eq 'new') || 
                    564: 			(!$status{$msgid})) { 
                    565: 			if ($what eq 'Error') {
                    566: 			    $error{$url}.=','.$msgid; 
                    567: 			} else {
                    568: 			    $feedback{$url}.=','.$msgid;
                    569: 			}
                    570: 		    }
                    571: 		}
                    572: 	    }
1.22      www       573: # ----------------------------------------------------------- Start Page Output
1.43      www       574:             my $bodytagadd='';
                    575: 	    $r->print(
                    576:                    '<html><head><title>Navigate Course Map</title></head>');
1.28      albertel  577: 	    if (($currenturl=~/^\/res/) &&
                    578: 		($currenturl!~/^\/res\/adm/)) {
1.43      www       579: 		$bodytagadd='onLoad="window.location.hash='."'curloc'".'"';
1.28      albertel  580: 	    }
1.43      www       581: 	    $r->print(&Apache::loncommon::bodytag('Navigate Course Map','',
                    582:                                                   $bodytagadd));
                    583: 	    $r->print('<script>window.focus();</script>');
1.41      albertel  584: 	    my $desc=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                    585: 	    if (defined($desc)) { $r->print("<h2>$desc</h2>\n"); }
                    586: 	    $r->print("<h3>$date</h3>\n");
1.28      albertel  587: 	    $r->rflush();
                    588: 	    $r->print('<img src="/adm/lonMisc/chat.gif"> New discussion since '.
                    589: 		      localtime($lastcheck).
                    590: 		      '<br><img src="/adm/lonMisc/feedback.gif"> New message (click to open)<p>'); 
                    591: 	    if (($currenturl=~/^\/res/) &&
                    592: 		($currenturl!~/^\/res\/adm/)) {
                    593: 		$r->print('<a href="#curloc">Current Location</a><p>');
                    594: 	    }
1.47    ! bowersj2  595: 
        !           596: 	    # Handle a network error
        !           597: 
        !           598: 	    if ($networkFailedFlag)
        !           599: 	    {
        !           600: 		$r->print('<H2>LON-CAPA network failure.</H2>'."\n");
        !           601: 		$r->print("<p>LON-CAPA's network is having difficulties, some problem" .
        !           602: 			  " information, such as due dates, will not be available.");
        !           603: 	    }
1.13      www       604: # ----------------------------------------------------- The little content list
1.28      albertel  605: 	    for ($i=0;$i<=$#rows;$i++) {
                    606: 		if ($rows[$i]) {
                    607: 		    my @colcont=split(/\&/,$rows[$i]);
                    608: 		    my $avespan=$lcm/($#colcont+1);
                    609: 		    for ($j=0;$j<=$#colcont;$j++) {
                    610: 			my $rid=$colcont[$j];
                    611: 			if ($rid=~/^h(.+)/) {
                    612: 			    $rid=$1;
                    613: 			    $r->print('&nbsp;&nbsp;&nbsp;<a href="#'.
                    614: 				      $rid.'">'.$hash{'title_'.$rid}.
                    615: 				      '</a><br>');
                    616: 			}
                    617: 		    }
                    618: 		}
                    619: 	    }
1.2       www       620: # ----------------------------------------------------------------- Start table
1.28      albertel  621: 	    $r->print('<hr><table cols="'.$lcm.'" border="0">');
                    622: 	    for ($i=0;$i<=$#rows;$i++) {
                    623: 		if ($rows[$i]) {
                    624: 		    $r->print("\n<tr>");
                    625: 		    my @colcont=split(/\&/,$rows[$i]);
                    626: 		    my $avespan=$lcm/($#colcont+1);
1.45      bowersj2  627: 
                    628: 		    # for each item I wish to print on this row...
1.28      albertel  629: 		    for ($j=0;$j<=$#colcont;$j++) {
1.32      albertel  630: 			my $indent;my $indentstr;
                    631: 			my $linkid;
1.28      albertel  632: 			my $rid=$colcont[$j];
1.36      www       633:                         $rid=~/(\d+)\.(\d+)$/;
                    634: 			my $src=
                    635: 			   &Apache::lonnet::declutter($hash{'src_'.$1.'.'.$2});
                    636: 			my $symb=
                    637: 	  &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.$src;
1.32      albertel  638: 			my $add='<td>';
1.28      albertel  639: 			my $adde='</td>';
                    640: 			my $hwk='<font color="#223322">';
                    641: 			my $hwke='</font>';
1.32      albertel  642: 			if ($rid=~/^l(\d+\.\d+),(.+)/) { $linkid=$1; $rid=$2; }
                    643: 			if ($rid=~/^i(\d+),(.+)/) { $indent=$1; $rid=$2; }
1.28      albertel  644: 			if ($rid=~/^h(.+)/) {
                    645: 			    $rid=$1;
                    646: 			    $add='<th bgcolor="#AAFF55"><a name="'.$rid.'">';
                    647: 			    $adde='</th>';
1.36      www       648:                             if (($ENV{'user.adv'}) && 
                    649: 				($parmhash{$symb.'.0.parameter_randompick'})) {
                    650:                                $adde=' (randomly select '.
                    651: 				   $parmhash{$symb.'.0.parameter_randompick'}.
                    652:                                    ')</th>';
                    653:                             }
1.28      albertel  654: 			}
1.32      albertel  655: 			if ($rid=~/^j(.+)/) { $rid=$1; }
1.28      albertel  656: 			if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) {
                    657: 			    # sub astatus describes what code/tcode mean
                    658: 			    my $code=$1;
                    659: 			    my $tcode=$2;
                    660: 			    my $ctext=$3;
                    661: 			    $rid=$4;
1.47    ! bowersj2  662: 			    
        !           663: 			    # will open later
        !           664: 			    if ($tcode eq '1') { 
1.28      albertel  665: 				$add='<td bgcolor="#AAAAAA">';
                    666: 			    }
1.47    ! bowersj2  667: 
        !           668: 			    # solved/correct
1.28      albertel  669: 			    if ($code eq '3') {
                    670: 				$add='<td bgcolor="#AAFFAA">';
1.47    ! bowersj2  671: 			    } elsif ($code eq '4') { # partially correct
1.30      albertel  672: 				$add='<td bgcolor="#E0FFAA">';
1.28      albertel  673: 			    } else {
1.47    ! bowersj2  674: 				# not attempted
        !           675: 				
        !           676: 				# we end up here on network failure, so pick a neutral
        !           677: 				# color if the network failed instead of bright red.
        !           678: 				if ( $networkFailedFlag )
        !           679: 				{
        !           680: 				    $add = '<td bgcolor="#AAAAAA">';
        !           681: 				}
        !           682: 				else
        !           683: 				{
        !           684: 				    $add='<td bgcolor="#FFAAAA">';
        !           685: 				}
        !           686: 
        !           687: 				if ($tcode eq '2') { # open, not past due
1.28      albertel  688: 				    $add='<td bgcolor="#FFFFAA">';
                    689: 				}
1.47    ! bowersj2  690: 
        !           691: 				if ($tcode eq '4') { # due in next 24 hours
1.28      albertel  692: 				    $add='<td bgcolor="#FFFF33">';
                    693: 				    $adde='</td>';
                    694: 				}
                    695: 			    }
                    696: 			    $hwk='<font color="#888811"><b>';
                    697: 			    $hwke='</b></font>';
                    698: 			    if ($code eq '1') {
                    699: 				$hwke='</b> ('.$ctext.')</font>';
                    700: 			    }
1.30      albertel  701: 			    if ($code eq '2' || $code eq '4') {
1.28      albertel  702: 				$hwk='<font color="#992222"><b>';
                    703: 				$hwke='</b> ('.$ctext.')</font>';
                    704: 			    }
                    705: 			    if ($code eq '3') {
                    706: 				$hwk='<font color="#229922"><b>';
                    707: 				$hwke='</b> ('.$ctext.')</font>';
1.47    ! bowersj2  708: 			    }
        !           709: 			    if ($networkFailedFlag) 
        !           710: 			    {
        !           711: 				$hwke='</b> (status unavailable)</font>';
1.28      albertel  712: 			    }
                    713: 			}
1.33      albertel  714: 			if ($rid && $hash{'src_'.$rid} eq $currenturl) {
1.28      albertel  715: 			    $add=$add.'<a name="curloc"></a>'.
                    716: 				'<font color=red size=+2><b>&gt; </b></font>';
                    717: 			    $adde=
                    718: 				'<font color=red size=+2><b> &lt;</b></font>'.$adde;
                    719: 			}
                    720: 			if ($discussiontimes{$symb}>$lastcheck) {
                    721: 			    $adde=
                    722: 				'<img border=0 src="/adm/lonMisc/chat.gif">'.
                    723: 				    $adde;
                    724: 			}
                    725: 			if ($error{$src}) {
                    726: 			    foreach (split(/\,/,$error{$src})) {
                    727: 				if ($_) {
                    728: 				    $adde=
                    729: 					'&nbsp;<a href="/adm/email?display='.
                    730: 					    &Apache::lonnet::escape($_).
                    731: 						'"><img src="/adm/lonMisc/bomb.gif" border=0></a>'
                    732: 						    .$adde;
                    733: 				}
                    734: 			    }
                    735: 			}
                    736: 			if ($feedback{$src}) {
                    737: 			    foreach (split(/\,/,$feedback{$src})) {
                    738: 				if ($_) {
                    739: 				    $adde=
                    740: 					'&nbsp;<a href="/adm/email?display='.
                    741: 					    &Apache::lonnet::escape($_).
                    742: 						'"><img src="/adm/lonMisc/feedback.gif" border=0></a>'
                    743: 						    .$adde;
                    744: 				}
                    745: 			    }
                    746: 			}
1.32      albertel  747: 			if ($indent) {
                    748: 			    my $is="&nbsp;&nbsp;";
                    749: 			    for(my $i=-1;$i<$indent;$i++) { $indentstr.=$is; }
                    750: 			}
                    751: 			if (!$linkid) { $linkid=$rid; }
1.38      www       752:                         if ($hash{'randomout_'.$rid}) {
                    753:                             $adde=' <i>(hidden)</i>'.$adde;
                    754:                         }
1.33      albertel  755: 			$r->print($add.$indentstr);
                    756: 			if ($rid) {
1.34      www       757: 			    $r->print('<a href="'.$hash{'src_'.$linkid}.
1.39      www       758:                                       (($hash{'src_'.$linkid}=~/\?/)?'&':'?').
                    759:                                       'symb='.&Apache::lonnet::escape($symb)
1.35      www       760:                                        .'">'.
1.33      albertel  761: 				      $hwk.$hash{'title_'.$rid}.$hwke.'</a>');
                    762: 			}
                    763: 			$r->print($adde);
1.28      albertel  764: 		    }
                    765: 		    $r->print('</tr>');
                    766: 		}
                    767: 	    }
                    768: 	    $r->print("\n</table>");
                    769: 	    $r->print('</body></html>');
1.2       www       770: # -------------------------------------------------------------------- End page
1.28      albertel  771: 	}                  
1.2       www       772: # ------------------------------------------------------------- End render page
1.28      albertel  773:     }
1.2       www       774: # ------------------------------------------------------------------ Untie hash
1.28      albertel  775:     unless (untie(%hash)) {
                    776: 	&Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    777: 				 "Could not untie coursemap $fn (browse).</font>"); 
                    778:     }
                    779:     unless (untie(%parmhash)) {
                    780: 	&Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    781: 				 "Could not untie parmhash (browse).</font>"); 
                    782:     }
                    783:     return OK;
1.2       www       784: }
1.1       www       785: 
                    786: 1;
                    787: __END__
1.2       www       788: 
                    789: 
                    790: 
                    791: 
                    792: 
                    793: 
                    794: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>