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

1.2       www         1: # The LearningOnline Network with CAPA
                      2: # Navigate Maps Handler
1.1       www         3: #
1.50    ! www         4: # $Id: lonnavmaps.pm,v 1.49 2002/09/09 16:40:01 www 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
1.49      www       198:     foreach (sort(split(/\,/,&Apache::lonnet::metadata($hash{'src_'.$rid},'allpossiblekeys')))) {
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);
1.49      www       204:             if (&parmval($part.'.opendate.type',$symb) eq 'date_interval') {
                    205: 		$opendate{$part}=$duedate{$part}-$opendate{$part};
                    206:             }
1.50    ! www       207:             if (&parmval($part.'.answerdate.type',$symb) eq 'date_interval') {
1.49      www       208:                 $answerdate{$part}=$duedate{$part}+$answerdate{$part};
                    209:             }
1.15      www       210:         }
1.25      albertel  211:     }
1.11      www       212:     my $now=time;
                    213:     my $tcode=0;
1.16      www       214: 
                    215:     my %returnhash=&Apache::lonnet::restore($symb);
                    216: 
1.25      albertel  217:     foreach (sort(keys(%opendate))) {
1.24      albertel  218: 	my $duedate=$duedate{$_};
                    219: 	my $opendate=$opendate{$_};
                    220: 	my $answerdate=$answerdate{$_};
                    221: 	my $preface='';
                    222: 	unless ($_ eq '0') { $preface=' Part: '.$_.' '; }
                    223: 	if ($opendate) {
1.25      albertel  224: 	    if ($now<$duedate || (!$duedate)) {
                    225: 		unless ($tcode==4) { $tcode=2; }
                    226: 		if ($duedate) {
                    227: 		    $ctext.=$preface.'Due: '.localtime($duedate);
                    228: 		} else {
                    229: 		    $ctext.=$preface.'No Due Date';
                    230: 		}
                    231: 		if ($now<$opendate) {
                    232: 		    unless ($tcode) { $tcode=1; }
1.24      albertel  233: 		    $ctext.=$preface.'Open: '.localtime($opendate);
                    234: 		}
1.25      albertel  235: 		if ($duedate && $duedate-$now<86400) {
1.24      albertel  236: 		    $tcode=4;
                    237: 		    $ctext.=$preface.'Due: '.localtime($duedate);
                    238: 		}
                    239: 	    } else {
                    240: 		unless (($tcode==4) || ($tcode eq 2)) { $tcode=3; }
1.25      albertel  241: 		if ($now<$answerdate) {
1.24      albertel  242: 		    $ctext.='Answer: '.localtime($duedate);
                    243: 		}
                    244: 	    }
                    245: 	} else {
                    246: 	    unless (($tcode==2) || ($tcode==4)) { $tcode=1; }
                    247: 	}
                    248: 	
                    249: 	my $status=$returnhash{'resource.'.$_.'.solved'};
1.25      albertel  250: 	
1.24      albertel  251: 	if ($status eq 'correct_by_student') {
1.30      albertel  252: 	    if ($code==0||$code==3) { $code=3; } else { $code=4; }
1.24      albertel  253: 	    $ctext.=' solved';
                    254: 	} elsif ($status eq 'correct_by_override') {
1.30      albertel  255: 	    if ($code==0||$code==3) { $code=3; } else { $code=4; }
1.24      albertel  256: 	    $ctext.=' override';
                    257: 	} elsif ($status eq 'incorrect_attempted') {
1.29      albertel  258: 	    if ($code!=4 && $code!=3) { $code=2; }
                    259: 	    if ($code==3) { $code=4; }
1.24      albertel  260: 	    $ctext.=' ('.
                    261: 		($returnhash{'resource.'.$_.'.tries'}?
1.25      albertel  262: 		 $returnhash{'resource.'.$_.'.tries'}:'0');
                    263: 	    my $numtries = &parmval($_.'.maxtries',$symb);
                    264: 	    if ($numtries) { $ctext.='/'.$numtries.' tries'; }
                    265: 	    $ctext.=')';
1.24      albertel  266: 	} elsif ($status eq 'incorrect_by_override') {
1.29      albertel  267: 	    if ($code!=4 && $code!=3) { $code=2; }
                    268: 	    if ($code==3) { $code=4; }
1.24      albertel  269: 	    $ctext.=' override';
                    270: 	} elsif ($status eq 'excused') {
1.30      albertel  271: 	    if ($code==0||$code==3) { $code=3; } else { $code=4; }
1.24      albertel  272: 	    $ctext.=' excused';
1.29      albertel  273: 	} else {
                    274: 	    if ($code==0) { $code=1; }
1.24      albertel  275: 	}
1.25      albertel  276:     }
1.16      www       277: 
1.11      www       278:     return 'p'.$code.$tcode.'"'.$ctext.'"';
1.9       www       279: }
                    280: 
1.2       www       281: 
1.31      albertel  282: sub addresource {
1.32      albertel  283:     my ($resource,$sofar,$rid,$showtypes,$indent,$linkid)=@_;
1.31      albertel  284:     if ($showtypes eq 'problems') {
                    285: 	if ($resource!~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    286: 	    return;
1.32      albertel  287: 	}
1.31      albertel  288:     }
                    289:     my $brepriv=&Apache::lonnet::allowed('bre',$resource);
                    290:     if ($hash{'src_'.$rid}) {
1.37      www       291: 	if (($brepriv eq '2') || ($brepriv eq 'F')) {
1.31      albertel  292: 	    my $pprefix='';
                    293: 	    if ($resource=~/\.(problem|exam|quiz|assess|survey|form)$/) {
                    294: 		$pprefix=&astatus($rid);
1.28      albertel  295: 	    }
1.32      albertel  296: 	    $$sofar++;
                    297: 	    if ($indent) { $pprefix='i'.$indent.','.$pprefix; }
                    298: 	    if ($linkid) { $pprefix='l'.$linkid.','.$pprefix; }
                    299: 	    if (defined($rows[$$sofar])) {
                    300: 		$rows[$$sofar].='&'.$pprefix.$rid;
1.28      albertel  301: 	    } else {
1.32      albertel  302: 		$rows[$$sofar]=$pprefix.$rid;
1.28      albertel  303: 	    }
1.31      albertel  304: 	}
                    305:     }
                    306: }
                    307: 
                    308: sub followlinks () {
1.32      albertel  309:     my ($rid,$sofar,$beenhere,$further,$showtypes,$indent,$linkid)=@_;
1.31      albertel  310:     my $mincond=1;
                    311:     my $next='';
                    312:     foreach (split(/\,/,$hash{'to_'.$rid})) {
                    313: 	my $thiscond=
                    314: 	    &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
                    315: 	if ($thiscond>=$mincond) {
                    316: 	    if ($next) {
                    317: 		$next.=','.$_.':'.$thiscond;
                    318: 	    } else {
                    319: 		$next=$_.':'.$thiscond;
1.28      albertel  320: 	    }
1.31      albertel  321: 	    if ($thiscond>$mincond) { $mincond=$thiscond; }
                    322: 	}
                    323:     }
1.32      albertel  324:     my $col=0;
                    325:     &Apache::lonxml::debug("following links -$next-");
1.31      albertel  326:     foreach (split(/\,/,$next)) {
1.32      albertel  327: 	my ($nextlinkid,$condval)=split(/\:/,$_);
1.31      albertel  328: 	if ($condval>=$mincond) {
1.32      albertel  329: 	    my $now=&tracetable($sofar,$hash{'goesto_'.$nextlinkid},
                    330: 				$beenhere,$showtypes,$indent,$linkid);
                    331: 	    if ($now>$further) {		
                    332: 		if ($col>0) {
                    333: 		    my $string;
                    334: 		    for(my $i=0;$i<$col;$i++) { $string.='&'; }
                    335: 		    for(my $i=$further+1;$now-1>$i;$i++) {
                    336: 			$rows[$i]=$string.$rows[$i];
                    337: 		    }
                    338: 		}
                    339: 		$further=$now;
                    340: 	    }
1.31      albertel  341: 	}
1.32      albertel  342: 	$col++;
1.31      albertel  343:     }
                    344:     return $further;
                    345: }
                    346: # ------------------------------------------------------------ Build page table
                    347: 
                    348: sub tracetable {
1.32      albertel  349:     my ($sofar,$rid,$beenhere,$showtypes,$indent,$linkid)=@_;
                    350:     my $newshowtypes=$showtypes;
1.31      albertel  351:     my $further=$sofar;
1.44      www       352: # $Apache::lonxml::debug=1;
1.32      albertel  353:     &Apache::lonxml::debug("$rid ; $linkid ; $sofar ; $beenhere ; ".$hash{'src_'.$rid});
                    354:     if ($beenhere=~/\&$rid\&/) { return $further; }
                    355:     $beenhere.=$rid.'&';
1.31      albertel  356: 
                    357:     if (defined($hash{'is_map_'.$rid})) {
                    358: 	$sofar++;
                    359: 	my $tprefix='';
                    360: 	if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
                    361: 	    eq 'sequence') {
                    362: 	    $tprefix='h';
                    363: 	} elsif ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
                    364: 		 eq 'page') {
1.32      albertel  365: 	    $tprefix='j';
                    366: 	    if ($indent) { $tprefix='i'.$indent.','.$tprefix; }
1.33      albertel  367: 	    if ($linkid) { $tprefix='l'.$linkid.','.$tprefix; }
1.32      albertel  368: 	    $newshowtypes='problems';
                    369: 	    $indent++;
1.33      albertel  370: 	    #if in a .page continue to link the encompising .page
                    371: 	    if (!$linkid) { $linkid=$rid; }
1.31      albertel  372: 	}
                    373: 	if (defined($rows[$sofar])) {
                    374: 	    $rows[$sofar].='&'.$tprefix.$rid;
1.28      albertel  375: 	} else {
1.31      albertel  376: 	    $rows[$sofar]=$tprefix.$rid;
                    377: 	}
                    378: 	if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
                    379: 	    (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
                    380: 	    my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
1.32      albertel  381: 	    $sofar=&tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
1.33      albertel  382: 			       '&'.$frid.'&',$newshowtypes,$indent,$linkid);
1.32      albertel  383: 	    &addresource($hash{'src_'.$frid},\$sofar,$frid,$newshowtypes,
1.33      albertel  384: 			 $indent,$linkid);
                    385: 	    if ($tprefix =~ /j$/) { $indent--; $linkid=''; }
1.28      albertel  386: 	}
1.31      albertel  387:     } else {
1.32      albertel  388: 	&addresource($hash{'src_'.$rid},\$sofar,$rid,$showtypes,
                    389: 		     $indent,$linkid);
1.31      albertel  390:     }
                    391: 
                    392:     if (defined($hash{'to_'.$rid})) {
1.32      albertel  393: 	$further=&followlinks($rid,$sofar,$beenhere,$further,$showtypes,
                    394: 			      $indent,$linkid);
1.2       www       395:     }
1.31      albertel  396: 
1.2       www       397:     return $further;
                    398: }
                    399: 
                    400: # ================================================================ Main Handler
1.1       www       401: 
                    402: sub handler {
1.28      albertel  403:     my $r=shift;
1.2       www       404: 
                    405: 
                    406: # ------------------------------------------- Set document type for header only
                    407: 
1.28      albertel  408:     if ($r->header_only) {
                    409: 	if ($ENV{'browser.mathml'}) {
                    410: 	    $r->content_type('text/xml');
                    411: 	} else {
                    412: 	    $r->content_type('text/html');
                    413: 	}
                    414: 	$r->send_http_header;
                    415: 	return OK;
                    416:     }
                    417:     my $requrl=$r->uri;
                    418:     my $hashtied;
1.2       www       419: # ----------------------------------------------------------------- Tie db file
1.28      albertel  420:     my $fn;
                    421:     if ($ENV{'request.course.fn'}) {
                    422: 	$fn=$ENV{'request.course.fn'};
                    423: 	if (-e "$fn.db") {
1.40      albertel  424: 	    if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640)) &&
1.28      albertel  425: 		(tie(%parmhash,'GDBM_File',
                    426: 		     $ENV{'request.course.fn'}.'_parms.db',
1.40      albertel  427: 		     &GDBM_READER(),0640))) {
1.28      albertel  428: 		$hashtied=1;
                    429: 	    }
                    430: 	}
                    431:     }
                    432:     if (!$hashtied) {
                    433: 	$ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    434: 	return HTTP_NOT_ACCEPTABLE; 
                    435:     }
                    436: 
1.2       www       437: # ------------------------------------------------------------------- Hash tied
1.28      albertel  438: 
                    439:     if ($ENV{'browser.mathml'}) {
                    440: 	$r->content_type('text/xml');
                    441:     } else {
                    442: 	$r->content_type('text/html');
                    443:     }
                    444:     &Apache::loncommon::no_cache($r);
                    445:     $r->send_http_header;
                    446: 
1.42      www       447:     my $firstres=$hash{'map_start_'.
                    448:            &Apache::lonnet::clutter($ENV{'request.course.uri'})};
                    449:     my $lastres=$hash{'map_finish_'.
                    450:            &Apache::lonnet::clutter($ENV{'request.course.uri'})};
1.28      albertel  451:     if (!(($firstres) && ($lastres))) {
                    452: 	$r->print('<html><body>Coursemap undefined.</body></html>');
                    453:     } else {
                    454: 
1.2       www       455: # ----------------------------------------------------------------- Render page
1.10      www       456: # -------------------------------------------------------------- Set parameters
                    457: 
                    458: 
                    459: # ---------------------------- initialize coursedata and userdata for this user
1.28      albertel  460: 	undef %courseopt;
                    461: 	undef %useropt;
1.10      www       462: 
1.28      albertel  463: 	my $uname=$ENV{'user.name'};
                    464: 	my $udom=$ENV{'user.domain'};
                    465: 	my $uhome=$ENV{'user.home'};
                    466: 	my $cid=$ENV{'request.course.id'};
                    467: 	my $chome=$ENV{'course.'.$cid.'.home'};
                    468: 	my ($cdom,$cnum)=split(/\_/,$cid);
1.10      www       469: 
1.28      albertel  470: 	my $userprefix=$uname.'_'.$udom.'_';
1.47      bowersj2  471: 	
1.28      albertel  472: 	unless ($uhome eq 'no_host') { 
1.48      bowersj2  473: # ------------------------------------------------- Get coursedata (if present)
1.28      albertel  474: 	    unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
                    475: 		my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
                    476: 						 ':resourcedata',$chome);
                    477: 		if ($reply!~/^error\:/) {
                    478: 		    $courserdatas{$cid}=$reply;
                    479: 		    $courserdatas{$cid.'.last_cache'}=time;
                    480: 		}
1.48      bowersj2  481: 		# check to see if network failed
                    482: 		elsif ( $reply=~/no.such.host/i || $reply=~/con.*lost/i )
1.47      bowersj2  483: 		{
                    484: 		    $networkFailedFlag = 1;
                    485: 		}
1.28      albertel  486: 	    }
                    487: 	    foreach (split(/\&/,$courserdatas{$cid})) {
                    488: 		my ($name,$value)=split(/\=/,$_);
                    489: 		$courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
                    490: 		    &Apache::lonnet::unescape($value);
                    491: 	    }
1.10      www       492: # --------------------------------------------------- Get userdata (if present)
1.28      albertel  493: 	    unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
                    494: 		my $reply=&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
                    495: 		if ($reply!~/^error\:/) {
                    496: 		    $userrdatas{$uname.'___'.$udom}=$reply;
                    497: 		    $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
                    498: 		}
                    499: 	    }
                    500: 	    foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
                    501: 		my ($name,$value)=split(/\=/,$_);
                    502: 		$useropt{$userprefix.&Apache::lonnet::unescape($name)}=
                    503: 		    &Apache::lonnet::unescape($value);
                    504: 	    }
                    505: 	}
                    506: 
                    507: 	@rows=();
                    508: 
1.44      www       509: 	&tracetable(0,$firstres,'&','',0);
1.2       www       510: 
                    511: # ------------------------------------------------------------------ Page parms
                    512: 
1.28      albertel  513: 	my $j;
                    514: 	my $i;
                    515: 	my $lcm=1;
                    516: 	my $contents=0;
1.2       www       517: 
                    518: # ---------------------------------------------- Go through table to get layout
                    519: 
1.28      albertel  520: 	for ($i=0;$i<=$#rows;$i++) {
                    521: 	    if ($rows[$i]) {
1.32      albertel  522: 		&Apache::lonxml::debug("Row $i is:".$rows[$i]);
1.28      albertel  523: 		$contents++;
                    524: 		my @colcont=split(/\&/,$rows[$i]);
                    525: 		$lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
                    526: 	    } 
                    527: 	}
1.5       www       528: 
1.2       www       529: 
1.28      albertel  530: 	unless ($contents) {
                    531: 	    $r->print('<html><body>Empty Map.</body></html>');
                    532: 	} else {
1.10      www       533: 
1.2       www       534: # ------------------------------------------------------------------ Build page
                    535: 
1.28      albertel  536: 	    my $currenturl=$ENV{'form.postdata'};
                    537: 	    $currenturl=~s/^http\:\/\///;
                    538: 	    $currenturl=~s/^[^\/]+//;
1.13      www       539: 
1.2       www       540: # ---------------------------------------------------------------- Send headers
                    541: 
1.28      albertel  542: 	    my $date=localtime;
                    543: 	    my $now=time;
1.21      www       544: # ----------------------------------------- Get email status and discussiontime
                    545: 
1.28      albertel  546: 	    my %emailstatus=&Apache::lonnet::dump('email_status');
                    547: 	    my $logouttime=$emailstatus{'logout'};
                    548: 	    my $courseleave=$emailstatus{'logout_'.$ENV{'request.course.id'}};
                    549: 	    my $lastcheck=($courseleave>$logouttime?$courseleave:$logouttime);
                    550: 
                    551: 	    my %discussiontimes=&Apache::lonnet::dump('discussiontimes',
                    552: 							  $cdom,$cnum);
                    553: 
                    554: 	    my %feedback=();
                    555: 	    my %error=();
                    556: 	    foreach my $msgid (split(/\&/,&Apache::lonnet::reply('keys:'.
                    557: 								 $ENV{'user.domain'}.':'.
                    558: 								 $ENV{'user.name'}.':nohist_email',
                    559: 								 $ENV{'user.home'}))) {
                    560: 		$msgid=&Apache::lonnet::unescape($msgid);
                    561: 		my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
                    562: 		if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
                    563: 		    my ($what,$url)=($1,$2);
                    564: 		    my %status=
                    565: 			&Apache::lonnet::get('email_status',[$msgid]);
                    566: 		    if ($status{$msgid}=~/^error\:/) { 
                    567: 			$status{$msgid}=''; 
                    568: 		    }
                    569: 			
                    570: 		    if (($status{$msgid} eq 'new') || 
                    571: 			(!$status{$msgid})) { 
                    572: 			if ($what eq 'Error') {
                    573: 			    $error{$url}.=','.$msgid; 
                    574: 			} else {
                    575: 			    $feedback{$url}.=','.$msgid;
                    576: 			}
                    577: 		    }
                    578: 		}
                    579: 	    }
1.22      www       580: # ----------------------------------------------------------- Start Page Output
1.43      www       581:             my $bodytagadd='';
                    582: 	    $r->print(
                    583:                    '<html><head><title>Navigate Course Map</title></head>');
1.28      albertel  584: 	    if (($currenturl=~/^\/res/) &&
                    585: 		($currenturl!~/^\/res\/adm/)) {
1.43      www       586: 		$bodytagadd='onLoad="window.location.hash='."'curloc'".'"';
1.28      albertel  587: 	    }
1.43      www       588: 	    $r->print(&Apache::loncommon::bodytag('Navigate Course Map','',
                    589:                                                   $bodytagadd));
                    590: 	    $r->print('<script>window.focus();</script>');
1.41      albertel  591: 	    my $desc=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
                    592: 	    if (defined($desc)) { $r->print("<h2>$desc</h2>\n"); }
                    593: 	    $r->print("<h3>$date</h3>\n");
1.28      albertel  594: 	    $r->rflush();
                    595: 	    $r->print('<img src="/adm/lonMisc/chat.gif"> New discussion since '.
                    596: 		      localtime($lastcheck).
                    597: 		      '<br><img src="/adm/lonMisc/feedback.gif"> New message (click to open)<p>'); 
                    598: 	    if (($currenturl=~/^\/res/) &&
                    599: 		($currenturl!~/^\/res\/adm/)) {
                    600: 		$r->print('<a href="#curloc">Current Location</a><p>');
                    601: 	    }
1.47      bowersj2  602: 
                    603: 	    # Handle a network error
                    604: 
                    605: 	    if ($networkFailedFlag)
                    606: 	    {
                    607: 		$r->print('<H2>LON-CAPA network failure.</H2>'."\n");
                    608: 		$r->print("<p>LON-CAPA's network is having difficulties, some problem" .
                    609: 			  " information, such as due dates, will not be available.");
                    610: 	    }
1.13      www       611: # ----------------------------------------------------- The little content list
1.28      albertel  612: 	    for ($i=0;$i<=$#rows;$i++) {
                    613: 		if ($rows[$i]) {
                    614: 		    my @colcont=split(/\&/,$rows[$i]);
                    615: 		    my $avespan=$lcm/($#colcont+1);
                    616: 		    for ($j=0;$j<=$#colcont;$j++) {
                    617: 			my $rid=$colcont[$j];
                    618: 			if ($rid=~/^h(.+)/) {
                    619: 			    $rid=$1;
                    620: 			    $r->print('&nbsp;&nbsp;&nbsp;<a href="#'.
                    621: 				      $rid.'">'.$hash{'title_'.$rid}.
                    622: 				      '</a><br>');
                    623: 			}
                    624: 		    }
                    625: 		}
                    626: 	    }
1.2       www       627: # ----------------------------------------------------------------- Start table
1.28      albertel  628: 	    $r->print('<hr><table cols="'.$lcm.'" border="0">');
                    629: 	    for ($i=0;$i<=$#rows;$i++) {
                    630: 		if ($rows[$i]) {
                    631: 		    $r->print("\n<tr>");
                    632: 		    my @colcont=split(/\&/,$rows[$i]);
                    633: 		    my $avespan=$lcm/($#colcont+1);
1.45      bowersj2  634: 
                    635: 		    # for each item I wish to print on this row...
1.28      albertel  636: 		    for ($j=0;$j<=$#colcont;$j++) {
1.32      albertel  637: 			my $indent;my $indentstr;
                    638: 			my $linkid;
1.28      albertel  639: 			my $rid=$colcont[$j];
1.36      www       640:                         $rid=~/(\d+)\.(\d+)$/;
                    641: 			my $src=
                    642: 			   &Apache::lonnet::declutter($hash{'src_'.$1.'.'.$2});
                    643: 			my $symb=
                    644: 	  &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.$src;
1.32      albertel  645: 			my $add='<td>';
1.28      albertel  646: 			my $adde='</td>';
                    647: 			my $hwk='<font color="#223322">';
                    648: 			my $hwke='</font>';
1.32      albertel  649: 			if ($rid=~/^l(\d+\.\d+),(.+)/) { $linkid=$1; $rid=$2; }
                    650: 			if ($rid=~/^i(\d+),(.+)/) { $indent=$1; $rid=$2; }
1.28      albertel  651: 			if ($rid=~/^h(.+)/) {
                    652: 			    $rid=$1;
                    653: 			    $add='<th bgcolor="#AAFF55"><a name="'.$rid.'">';
                    654: 			    $adde='</th>';
1.36      www       655:                             if (($ENV{'user.adv'}) && 
                    656: 				($parmhash{$symb.'.0.parameter_randompick'})) {
                    657:                                $adde=' (randomly select '.
                    658: 				   $parmhash{$symb.'.0.parameter_randompick'}.
                    659:                                    ')</th>';
                    660:                             }
1.28      albertel  661: 			}
1.32      albertel  662: 			if ($rid=~/^j(.+)/) { $rid=$1; }
1.28      albertel  663: 			if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) {
                    664: 			    # sub astatus describes what code/tcode mean
                    665: 			    my $code=$1;
                    666: 			    my $tcode=$2;
                    667: 			    my $ctext=$3;
                    668: 			    $rid=$4;
1.47      bowersj2  669: 			    
                    670: 			    # will open later
                    671: 			    if ($tcode eq '1') { 
1.28      albertel  672: 				$add='<td bgcolor="#AAAAAA">';
                    673: 			    }
1.47      bowersj2  674: 
                    675: 			    # solved/correct
1.28      albertel  676: 			    if ($code eq '3') {
                    677: 				$add='<td bgcolor="#AAFFAA">';
1.47      bowersj2  678: 			    } elsif ($code eq '4') { # partially correct
1.30      albertel  679: 				$add='<td bgcolor="#E0FFAA">';
1.28      albertel  680: 			    } else {
1.47      bowersj2  681: 				# not attempted
                    682: 				
                    683: 				# we end up here on network failure, so pick a neutral
                    684: 				# color if the network failed instead of bright red.
                    685: 				if ( $networkFailedFlag )
                    686: 				{
                    687: 				    $add = '<td bgcolor="#AAAAAA">';
                    688: 				}
                    689: 				else
                    690: 				{
                    691: 				    $add='<td bgcolor="#FFAAAA">';
                    692: 				}
                    693: 
                    694: 				if ($tcode eq '2') { # open, not past due
1.28      albertel  695: 				    $add='<td bgcolor="#FFFFAA">';
                    696: 				}
1.47      bowersj2  697: 
                    698: 				if ($tcode eq '4') { # due in next 24 hours
1.28      albertel  699: 				    $add='<td bgcolor="#FFFF33">';
                    700: 				    $adde='</td>';
                    701: 				}
                    702: 			    }
                    703: 			    $hwk='<font color="#888811"><b>';
                    704: 			    $hwke='</b></font>';
                    705: 			    if ($code eq '1') {
                    706: 				$hwke='</b> ('.$ctext.')</font>';
                    707: 			    }
1.30      albertel  708: 			    if ($code eq '2' || $code eq '4') {
1.28      albertel  709: 				$hwk='<font color="#992222"><b>';
                    710: 				$hwke='</b> ('.$ctext.')</font>';
                    711: 			    }
                    712: 			    if ($code eq '3') {
                    713: 				$hwk='<font color="#229922"><b>';
                    714: 				$hwke='</b> ('.$ctext.')</font>';
1.47      bowersj2  715: 			    }
                    716: 			    if ($networkFailedFlag) 
                    717: 			    {
                    718: 				$hwke='</b> (status unavailable)</font>';
1.28      albertel  719: 			    }
                    720: 			}
1.33      albertel  721: 			if ($rid && $hash{'src_'.$rid} eq $currenturl) {
1.28      albertel  722: 			    $add=$add.'<a name="curloc"></a>'.
                    723: 				'<font color=red size=+2><b>&gt; </b></font>';
                    724: 			    $adde=
                    725: 				'<font color=red size=+2><b> &lt;</b></font>'.$adde;
                    726: 			}
                    727: 			if ($discussiontimes{$symb}>$lastcheck) {
                    728: 			    $adde=
                    729: 				'<img border=0 src="/adm/lonMisc/chat.gif">'.
                    730: 				    $adde;
                    731: 			}
                    732: 			if ($error{$src}) {
                    733: 			    foreach (split(/\,/,$error{$src})) {
                    734: 				if ($_) {
                    735: 				    $adde=
                    736: 					'&nbsp;<a href="/adm/email?display='.
                    737: 					    &Apache::lonnet::escape($_).
                    738: 						'"><img src="/adm/lonMisc/bomb.gif" border=0></a>'
                    739: 						    .$adde;
                    740: 				}
                    741: 			    }
                    742: 			}
                    743: 			if ($feedback{$src}) {
                    744: 			    foreach (split(/\,/,$feedback{$src})) {
                    745: 				if ($_) {
                    746: 				    $adde=
                    747: 					'&nbsp;<a href="/adm/email?display='.
                    748: 					    &Apache::lonnet::escape($_).
                    749: 						'"><img src="/adm/lonMisc/feedback.gif" border=0></a>'
                    750: 						    .$adde;
                    751: 				}
                    752: 			    }
                    753: 			}
1.32      albertel  754: 			if ($indent) {
                    755: 			    my $is="&nbsp;&nbsp;";
                    756: 			    for(my $i=-1;$i<$indent;$i++) { $indentstr.=$is; }
                    757: 			}
                    758: 			if (!$linkid) { $linkid=$rid; }
1.38      www       759:                         if ($hash{'randomout_'.$rid}) {
                    760:                             $adde=' <i>(hidden)</i>'.$adde;
                    761:                         }
1.33      albertel  762: 			$r->print($add.$indentstr);
                    763: 			if ($rid) {
1.34      www       764: 			    $r->print('<a href="'.$hash{'src_'.$linkid}.
1.39      www       765:                                       (($hash{'src_'.$linkid}=~/\?/)?'&':'?').
                    766:                                       'symb='.&Apache::lonnet::escape($symb)
1.35      www       767:                                        .'">'.
1.33      albertel  768: 				      $hwk.$hash{'title_'.$rid}.$hwke.'</a>');
                    769: 			}
                    770: 			$r->print($adde);
1.28      albertel  771: 		    }
                    772: 		    $r->print('</tr>');
                    773: 		}
                    774: 	    }
                    775: 	    $r->print("\n</table>");
                    776: 	    $r->print('</body></html>');
1.2       www       777: # -------------------------------------------------------------------- End page
1.28      albertel  778: 	}                  
1.2       www       779: # ------------------------------------------------------------- End render page
1.28      albertel  780:     }
1.2       www       781: # ------------------------------------------------------------------ Untie hash
1.28      albertel  782:     unless (untie(%hash)) {
                    783: 	&Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    784: 				 "Could not untie coursemap $fn (browse).</font>"); 
                    785:     }
                    786:     unless (untie(%parmhash)) {
                    787: 	&Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    788: 				 "Could not untie parmhash (browse).</font>"); 
                    789:     }
                    790:     return OK;
1.2       www       791: }
1.1       www       792: 
                    793: 1;
                    794: __END__
1.2       www       795: 
                    796: 
                    797: 
                    798: 
                    799: 
                    800: 
                    801: 

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