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

1.2       www         1: # The LearningOnline Network with CAPA
                      2: # Navigate Maps Handler
1.1       www         3: #
1.29    ! albertel    4: # $Id: lonnavmaps.pm,v 1.28 2002/03/15 16:31:10 albertel 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.2       www        70: # ------------------------------------------------------------------ Euclid gcd
                     71: 
                     72: sub euclid {
                     73:     my ($e,$f)=@_;
                     74:     my $a; my $b; my $r;
                     75:     if ($e>$f) { $b=$e; $r=$f; } else { $r=$e; $b=$f; }
                     76:     while ($r!=0) {
                     77: 	$a=$b; $b=$r;
                     78:         $r=$a%$b;
                     79:     }
                     80:     return $b;
                     81: }
                     82: 
1.10      www        83: # --------------------------------------------------------------------- Parmval
                     84: 
                     85: # -------------------------------------------- Figure out a cascading parameter
                     86: #
                     87: # For this function to work
                     88: #
                     89: # * parmhash needs to be tied
                     90: # * courseopt and useropt need to be initialized for this user and course
                     91: #
                     92: 
                     93: sub parmval {
                     94:     my ($what,$symb)=@_;
                     95:     my $cid=$ENV{'request.course.id'};
                     96:     my $csec=$ENV{'request.course.sec'};
                     97:     my $uname=$ENV{'user.name'};
                     98:     my $udom=$ENV{'user.domain'};
                     99: 
                    100:     unless ($symb) { return ''; }
                    101:     my $result='';
                    102: 
                    103:     my ($mapname,$id,$fn)=split(/\_\_\_/,$symb);
                    104: 
                    105: # ----------------------------------------------------- Cascading lookup scheme
1.24      albertel  106:     my $rwhat=$what;
                    107:     $what=~s/^parameter\_//;
                    108:     $what=~s/\_/\./;
                    109: 
                    110:     my $symbparm=$symb.'.'.$what;
                    111:     my $mapparm=$mapname.'___(all).'.$what;
                    112:     my $usercourseprefix=$uname.'_'.$udom.'_'.$cid;
                    113: 
                    114:     my $seclevel= $usercourseprefix.'.['.$csec.'].'.$what;
                    115:     my $seclevelr=$usercourseprefix.'.['.$csec.'].'.$symbparm;
                    116:     my $seclevelm=$usercourseprefix.'.['.$csec.'].'.$mapparm;
                    117: 
                    118:     my $courselevel= $usercourseprefix.'.'.$what;
                    119:     my $courselevelr=$usercourseprefix.'.'.$symbparm;
                    120:     my $courselevelm=$usercourseprefix.'.'.$mapparm;
                    121: 
                    122: # ---------------------------------------------------------- first, check user
                    123:     if ($uname) {
                    124: 	if ($useropt{$courselevelr}) { return $useropt{$courselevelr}; }
                    125: 	if ($useropt{$courselevelm}) { return $useropt{$courselevelm}; }
                    126: 	if ($useropt{$courselevel}) { return $useropt{$courselevel}; }
                    127:     }
1.10      www       128: 
1.24      albertel  129: # ------------------------------------------------------- second, check course
                    130:     if ($csec) {
                    131: 	if ($courseopt{$seclevelr}) { return $courseopt{$seclevelr}; }
1.25      albertel  132:         if ($courseopt{$seclevelm}) { return $courseopt{$seclevelm}; }
1.10      www       133:         if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; }
1.24      albertel  134:     }
1.10      www       135: 
1.24      albertel  136:     if ($courseopt{$courselevelr}) { return $courseopt{$courselevelr}; }
                    137:     if ($courseopt{$courselevelm}) { return $courseopt{$courselevelm}; }
                    138:     if ($courseopt{$courselevel}) { return $courseopt{$courselevel}; }
1.10      www       139: 
1.24      albertel  140: # ----------------------------------------------------- third, check map parms
1.10      www       141: 
1.24      albertel  142:     my $thisparm=$parmhash{$symbparm};
                    143:     if ($thisparm) { return $thisparm; }
1.10      www       144: 
1.24      albertel  145: # ----------------------------------------------------- fourth , check default
1.10      www       146: 
1.25      albertel  147:     my $default=&Apache::lonnet::metadata($fn,$rwhat.'.default');
                    148:     if ($default) { return $default}
                    149: 
                    150: # --------------------------------------------------- fifth , cascade up parts
                    151: 
                    152:     my ($space,@qualifier)=split(/\./,$rwhat);
                    153:     my $qualifier=join('.',@qualifier);
                    154:     unless ($space eq '0') {
                    155: 	my ($part,$id)=split(/\_/,$space);
                    156: 	if ($id) {
                    157: 	    my $partgeneral=&parmval($part.".$qualifier",$symb);
                    158: 	    if ($partgeneral) { return $partgeneral; }
                    159: 	} else {
                    160: 	    my $resourcegeneral=&parmval("0.$qualifier",$symb);
                    161: 	    if ($resourcegeneral) { return $resourcegeneral; }
                    162: 	}
                    163:     }
                    164:     return '';
1.10      www       165: }
                    166: 
                    167: 
                    168: 
1.9       www       169: # ------------------------------------------------------------- Find out status
1.25      albertel  170: # return codes
                    171: # tcode (timecode)
                    172: # 1: will open later
                    173: # 2: is open and not past due yet
                    174: # 3: is past due date
                    175: # 4: due in the next 24 hours
                    176: #
                    177: # code (curent solved status)
                    178: # 1: not attempted
                    179: # 2: attempted but wrong, or incorrect by instructor
                    180: # 3: solved or correct by instructor
1.29    ! albertel  181: # 4: partially correct (one or more parts correct)
        !           182: # "excused" needs to be supported, but is not yet.
1.9       www       183: sub astatus {
                    184:     my $rid=shift;
1.29    ! albertel  185:     my $code=0;
1.9       www       186:     my $ctext='';
                    187:     $rid=~/(\d+)\.(\d+)/;
1.10      www       188:     my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
1.24      albertel  189: 	&Apache::lonnet::declutter($hash{'src_'.$rid});
1.15      www       190:     my %duedate=();
                    191:     my %opendate=();
                    192:     my %answerdate=();
1.25      albertel  193:     # need to always check part 0's open/due/answer status
                    194:     foreach (sort(split(/\,/,&Apache::lonnet::metadata($hash{'src_'.$rid},'keys')))) {
1.15      www       195:         if ($_=~/^parameter\_(.*)\_opendate$/) {
                    196: 	    my $part=$1;
                    197:             $duedate{$part}=&parmval($part.'.duedate',$symb);
                    198:             $opendate{$part}=&parmval($part.'.opendate',$symb);
                    199:             $answerdate{$part}=&parmval($part.'.answerdate',$symb);
                    200:         }
1.25      albertel  201:     }
1.11      www       202:     my $now=time;
                    203:     my $tcode=0;
1.16      www       204: 
                    205:     my %returnhash=&Apache::lonnet::restore($symb);
                    206: 
1.25      albertel  207:     foreach (sort(keys(%opendate))) {
1.24      albertel  208: 	my $duedate=$duedate{$_};
                    209: 	my $opendate=$opendate{$_};
                    210: 	my $answerdate=$answerdate{$_};
                    211: 	my $preface='';
                    212: 	unless ($_ eq '0') { $preface=' Part: '.$_.' '; }
                    213: 	if ($opendate) {
1.25      albertel  214: 	    if ($now<$duedate || (!$duedate)) {
                    215: 		unless ($tcode==4) { $tcode=2; }
                    216: 		if ($duedate) {
                    217: 		    $ctext.=$preface.'Due: '.localtime($duedate);
                    218: 		} else {
                    219: 		    $ctext.=$preface.'No Due Date';
                    220: 		}
                    221: 		if ($now<$opendate) {
                    222: 		    unless ($tcode) { $tcode=1; }
1.24      albertel  223: 		    $ctext.=$preface.'Open: '.localtime($opendate);
                    224: 		}
1.25      albertel  225: 		if ($duedate && $duedate-$now<86400) {
1.24      albertel  226: 		    $tcode=4;
                    227: 		    $ctext.=$preface.'Due: '.localtime($duedate);
                    228: 		}
                    229: 	    } else {
                    230: 		unless (($tcode==4) || ($tcode eq 2)) { $tcode=3; }
1.25      albertel  231: 		if ($now<$answerdate) {
1.24      albertel  232: 		    $ctext.='Answer: '.localtime($duedate);
                    233: 		}
                    234: 	    }
                    235: 	} else {
                    236: 	    unless (($tcode==2) || ($tcode==4)) { $tcode=1; }
                    237: 	}
                    238: 	
                    239: 	my $status=$returnhash{'resource.'.$_.'.solved'};
1.25      albertel  240: 	
1.24      albertel  241: 	if ($status eq 'correct_by_student') {
1.29    ! albertel  242: 	    if ($code==0) { $code=3; } else { $code=4; }
1.24      albertel  243: 	    $ctext.=' solved';
                    244: 	} elsif ($status eq 'correct_by_override') {
1.29    ! albertel  245: 	    if ($code==0) { $code=3; } else { $code=4; }
1.24      albertel  246: 	    $ctext.=' override';
                    247: 	} elsif ($status eq 'incorrect_attempted') {
1.29    ! albertel  248: 	    if ($code!=4 && $code!=3) { $code=2; }
        !           249: 	    if ($code==3) { $code=4; }
1.24      albertel  250: 	    $ctext.=' ('.
                    251: 		($returnhash{'resource.'.$_.'.tries'}?
1.25      albertel  252: 		 $returnhash{'resource.'.$_.'.tries'}:'0');
                    253: 	    my $numtries = &parmval($_.'.maxtries',$symb);
                    254: 	    if ($numtries) { $ctext.='/'.$numtries.' tries'; }
                    255: 	    $ctext.=')';
1.24      albertel  256: 	} elsif ($status eq 'incorrect_by_override') {
1.29    ! albertel  257: 	    if ($code!=4 && $code!=3) { $code=2; }
        !           258: 	    if ($code==3) { $code=4; }
1.24      albertel  259: 	    $ctext.=' override';
                    260: 	} elsif ($status eq 'excused') {
1.29    ! albertel  261: 	    if ($code==0) { $code=3; } else { $code=4; }
1.24      albertel  262: 	    $ctext.=' excused';
1.29    ! albertel  263: 	} else {
        !           264: 	    if ($code==0) { $code=1; }
1.24      albertel  265: 	}
1.25      albertel  266:     }
1.16      www       267: 
1.11      www       268:     return 'p'.$code.$tcode.'"'.$ctext.'"';
1.9       www       269: }
                    270: 
1.2       www       271: # ------------------------------------------------------------ Build page table
                    272: 
                    273: sub tracetable {
                    274:     my ($sofar,$rid,$beenhere)=@_;
                    275:     my $further=$sofar;
                    276:     unless ($beenhere=~/\&$rid\&/) {
1.28      albertel  277: 	$beenhere.=$rid.'&';  
                    278: 	
                    279: 	if (defined($hash{'is_map_'.$rid})) {
                    280: 	    $sofar++;
                    281: 	    my $tprefix='';
                    282: 	    if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}} 
                    283: 		eq 'sequence') { 
                    284: 		$tprefix='h'; 
1.29    ! albertel  285: 	    } else {
        !           286: 		# it's a page we need to grab out the problems only
1.28      albertel  287: 	    }
                    288: 	    if (defined($rows[$sofar])) {
                    289: 		$rows[$sofar].='&'.$tprefix.$rid;
                    290: 	    } else {
                    291: 		$rows[$sofar]=$tprefix.$rid;
                    292: 	    }
                    293: 	    if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
                    294: 		(defined($hash{'map_finish_'.$hash{'src_'.$rid}})) &&
                    295: 		($tprefix eq 'h')) {
                    296: 		my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
                    297: 		$sofar=
                    298: 		    &tracetable($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},
                    299: 				'&'.$frid.'&');
                    300: 		$sofar++;
                    301: 		if ($hash{'src_'.$frid}) {
                    302: 		    my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$frid});
                    303: 		    if (($brepriv eq '2') || ($brepriv eq 'F')) {
                    304: 			my $pprefix='';
                    305: 			if ($hash{'src_'.$frid}=~
                    306: 			    /\.(problem|exam|quiz|assess|survey|form)$/) {
                    307: 			    $pprefix=&astatus($frid);
                    308: 			
                    309: 			}
                    310: 			if (defined($rows[$sofar])) {
                    311: 			    $rows[$sofar].='&'.$pprefix.$frid;
                    312: 			} else {
                    313: 			    $rows[$sofar]=$pprefix.$frid;
                    314: 			}
                    315: 		    }
                    316: 		}
                    317: 	    }
                    318: 	} else {
                    319: 	    $sofar++;
                    320: 	    if ($hash{'src_'.$rid}) {
                    321: 		my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$rid});
                    322: 		if (($brepriv eq '2') || ($brepriv eq 'F')) {
                    323: 		    my $pprefix='';
                    324: 		    if ($hash{'src_'.$rid}=~
                    325: 			/\.(problem|exam|quiz|assess|survey|form)$/) {
                    326: 			$pprefix=&astatus($rid);
                    327: 		    }
                    328: 		    if (defined($rows[$sofar])) {
                    329: 			$rows[$sofar].='&'.$pprefix.$rid;
                    330: 		    } else {
                    331: 			$rows[$sofar]=$pprefix.$rid;
                    332: 		    }
                    333: 		}
                    334: 	    }
                    335: 	}
                    336: 	
                    337: 	if (defined($hash{'to_'.$rid})) {
                    338: 	    my $mincond=1;
                    339: 	    my $next='';
                    340: 	    foreach (split(/\,/,$hash{'to_'.$rid})) {
                    341: 		my $thiscond=
                    342: 		    &Apache::lonnet::directcondval($hash{'condid_'.$hash{'undercond_'.$_}});
                    343: 		if ($thiscond>=$mincond) {
                    344: 		    if ($next) {
                    345: 			$next.=','.$_.':'.$thiscond;
                    346: 		    } else {
                    347: 			$next=$_.':'.$thiscond;
                    348: 		    }
                    349: 		    if ($thiscond>$mincond) { $mincond=$thiscond; }
                    350: 		}
                    351: 	    }
                    352: 	    foreach (split(/\,/,$next)) {
                    353: 		my ($linkid,$condval)=split(/\:/,$_);
                    354: 		if ($condval>=$mincond) {
                    355: 		    my $now=&tracetable($sofar,$hash{'goesto_'.$linkid},$beenhere);
                    356: 		    if ($now>$further) { $further=$now; }
                    357: 		}
                    358: 	    }
                    359: 	}
1.2       www       360:     }
                    361:     return $further;
                    362: }
                    363: 
                    364: # ================================================================ Main Handler
1.1       www       365: 
                    366: sub handler {
1.28      albertel  367:     my $r=shift;
1.2       www       368: 
                    369: 
                    370: # ------------------------------------------- Set document type for header only
                    371: 
1.28      albertel  372:     if ($r->header_only) {
                    373: 	if ($ENV{'browser.mathml'}) {
                    374: 	    $r->content_type('text/xml');
                    375: 	} else {
                    376: 	    $r->content_type('text/html');
                    377: 	}
                    378: 	$r->send_http_header;
                    379: 	return OK;
                    380:     }
                    381:     my $requrl=$r->uri;
                    382:     my $hashtied;
1.2       www       383: # ----------------------------------------------------------------- Tie db file
1.28      albertel  384:     my $fn;
                    385:     if ($ENV{'request.course.fn'}) {
                    386: 	$fn=$ENV{'request.course.fn'};
                    387: 	if (-e "$fn.db") {
                    388: 	    if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) &&
                    389: 		(tie(%parmhash,'GDBM_File',
                    390: 		     $ENV{'request.course.fn'}.'_parms.db',
                    391: 		     &GDBM_READER,0640))) {
                    392: 		$hashtied=1;
                    393: 	    }
                    394: 	}
                    395:     }
                    396:     if (!$hashtied) {
                    397: 	$ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
                    398: 	return HTTP_NOT_ACCEPTABLE; 
                    399:     }
                    400: 
1.2       www       401: # ------------------------------------------------------------------- Hash tied
1.28      albertel  402: 
                    403:     if ($ENV{'browser.mathml'}) {
                    404: 	$r->content_type('text/xml');
                    405:     } else {
                    406: 	$r->content_type('text/html');
                    407:     }
                    408:     &Apache::loncommon::no_cache($r);
                    409:     $r->send_http_header;
                    410: 
                    411:     my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
                    412:     my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
                    413:     if (!(($firstres) && ($lastres))) {
                    414: 	$r->print('<html><body>Coursemap undefined.</body></html>');
                    415:     } else {
                    416: 
1.2       www       417: # ----------------------------------------------------------------- Render page
1.10      www       418: # -------------------------------------------------------------- Set parameters
                    419: 
                    420: 
                    421: # ---------------------------- initialize coursedata and userdata for this user
1.28      albertel  422: 	undef %courseopt;
                    423: 	undef %useropt;
1.10      www       424: 
1.28      albertel  425: 	my $uname=$ENV{'user.name'};
                    426: 	my $udom=$ENV{'user.domain'};
                    427: 	my $uhome=$ENV{'user.home'};
                    428: 	my $cid=$ENV{'request.course.id'};
                    429: 	my $chome=$ENV{'course.'.$cid.'.home'};
                    430: 	my ($cdom,$cnum)=split(/\_/,$cid);
1.10      www       431: 
1.28      albertel  432: 	my $userprefix=$uname.'_'.$udom.'_';
1.10      www       433: 
1.28      albertel  434: 	unless ($uhome eq 'no_host') { 
1.10      www       435: # -------------------------------------------------------------- Get coursedata
1.28      albertel  436: 	    unless ((time-$courserdatas{$cid.'.last_cache'})<240) {
                    437: 		my $reply=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.
                    438: 						 ':resourcedata',$chome);
                    439: 		if ($reply!~/^error\:/) {
                    440: 		    $courserdatas{$cid}=$reply;
                    441: 		    $courserdatas{$cid.'.last_cache'}=time;
                    442: 		}
                    443: 	    }
                    444: 	    foreach (split(/\&/,$courserdatas{$cid})) {
                    445: 		my ($name,$value)=split(/\=/,$_);
                    446: 		$courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
                    447: 		    &Apache::lonnet::unescape($value);
                    448: 	    }
1.10      www       449: # --------------------------------------------------- Get userdata (if present)
1.28      albertel  450: 	    unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
                    451: 		my $reply=&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
                    452: 		if ($reply!~/^error\:/) {
                    453: 		    $userrdatas{$uname.'___'.$udom}=$reply;
                    454: 		    $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
                    455: 		}
                    456: 	    }
                    457: 	    foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
                    458: 		my ($name,$value)=split(/\=/,$_);
                    459: 		$useropt{$userprefix.&Apache::lonnet::unescape($name)}=
                    460: 		    &Apache::lonnet::unescape($value);
                    461: 	    }
                    462: 	}
                    463: 
                    464: 	@rows=();
                    465: 
                    466: 	&tracetable(0,$firstres,'&'.$lastres.'&');
                    467: 	if ($hash{'src_'.$lastres}) {
                    468: 	    my $brepriv=&Apache::lonnet::allowed('bre',$hash{'src_'.$lastres});
                    469: 	    if (($brepriv eq '2') || ($brepriv eq 'F')) {
                    470: 		$rows[$#rows+1]=''.$lastres;
                    471: 	    }
                    472: 	}
1.2       www       473: 
                    474: # ------------------------------------------------------------------ Page parms
                    475: 
1.28      albertel  476: 	my $j;
                    477: 	my $i;
                    478: 	my $lcm=1;
                    479: 	my $contents=0;
1.2       www       480: 
                    481: # ---------------------------------------------- Go through table to get layout
                    482: 
1.28      albertel  483: 	for ($i=0;$i<=$#rows;$i++) {
                    484: 	    if ($rows[$i]) {
                    485: 		$contents++;
                    486: 		my @colcont=split(/\&/,$rows[$i]);
                    487: 		$lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
                    488: 	    } 
                    489: 	}
1.5       www       490: 
1.2       www       491: 
1.28      albertel  492: 	unless ($contents) {
                    493: 	    $r->print('<html><body>Empty Map.</body></html>');
                    494: 	} else {
1.10      www       495: 
1.2       www       496: # ------------------------------------------------------------------ Build page
                    497: 
1.28      albertel  498: 	    my $currenturl=$ENV{'form.postdata'};
                    499: 	    $currenturl=~s/^http\:\/\///;
                    500: 	    $currenturl=~s/^[^\/]+//;
1.13      www       501: 
1.2       www       502: # ---------------------------------------------------------------- Send headers
                    503: 
1.28      albertel  504: 	    my $date=localtime;
                    505: 	    my $now=time;
1.21      www       506: # ----------------------------------------- Get email status and discussiontime
                    507: 
1.28      albertel  508: 	    my %emailstatus=&Apache::lonnet::dump('email_status');
                    509: 	    my $logouttime=$emailstatus{'logout'};
                    510: 	    my $courseleave=$emailstatus{'logout_'.$ENV{'request.course.id'}};
                    511: 	    my $lastcheck=($courseleave>$logouttime?$courseleave:$logouttime);
                    512: 
                    513: 	    my %discussiontimes=&Apache::lonnet::dump('discussiontimes',
                    514: 							  $cdom,$cnum);
                    515: 
                    516: 	    my %feedback=();
                    517: 	    my %error=();
                    518: 	    foreach my $msgid (split(/\&/,&Apache::lonnet::reply('keys:'.
                    519: 								 $ENV{'user.domain'}.':'.
                    520: 								 $ENV{'user.name'}.':nohist_email',
                    521: 								 $ENV{'user.home'}))) {
                    522: 		$msgid=&Apache::lonnet::unescape($msgid);
                    523: 		my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
                    524: 		if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
                    525: 		    my ($what,$url)=($1,$2);
                    526: 		    my %status=
                    527: 			&Apache::lonnet::get('email_status',[$msgid]);
                    528: 		    if ($status{$msgid}=~/^error\:/) { 
                    529: 			$status{$msgid}=''; 
                    530: 		    }
                    531: 			
                    532: 		    if (($status{$msgid} eq 'new') || 
                    533: 			(!$status{$msgid})) { 
                    534: 			if ($what eq 'Error') {
                    535: 			    $error{$url}.=','.$msgid; 
                    536: 			} else {
                    537: 			    $feedback{$url}.=','.$msgid;
                    538: 			}
                    539: 		    }
                    540: 		}
                    541: 	    }
1.22      www       542: # ----------------------------------------------------------- Start Page Output
1.28      albertel  543: 	    $r->print('<html><head><title>Navigate LON-CAPA Maps</title></head>');
                    544: 	    $r->print('<body bgcolor="#FFFFFF"');
                    545: 	    if (($currenturl=~/^\/res/) &&
                    546: 		($currenturl!~/^\/res\/adm/)) {
                    547: 		$r->print(' onLoad="window.location.hash='."'curloc'".'"');
                    548: 	    }
                    549: 	    $r->print('><script>window.focus();</script>'.
                    550: 		      '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
                    551: 		      '<h1>Navigate Course Map</h1>'.
                    552: 		      "<h3>$date</h3>");
                    553: 	    $r->rflush();
                    554: 	    $r->print('<img src="/adm/lonMisc/chat.gif"> New discussion since '.
                    555: 		      localtime($lastcheck).
                    556: 		      '<br><img src="/adm/lonMisc/feedback.gif"> New message (click to open)<p>'); 
                    557: 	    if (($currenturl=~/^\/res/) &&
                    558: 		($currenturl!~/^\/res\/adm/)) {
                    559: 		$r->print('<a href="#curloc">Current Location</a><p>');
                    560: 	    }
1.13      www       561: # ----------------------------------------------------- The little content list
1.28      albertel  562: 	    for ($i=0;$i<=$#rows;$i++) {
                    563: 		if ($rows[$i]) {
                    564: 		    my @colcont=split(/\&/,$rows[$i]);
                    565: 		    my $avespan=$lcm/($#colcont+1);
                    566: 		    for ($j=0;$j<=$#colcont;$j++) {
                    567: 			my $rid=$colcont[$j];
                    568: 			if ($rid=~/^h(.+)/) {
                    569: 			    $rid=$1;
                    570: 			    $r->print('&nbsp;&nbsp;&nbsp;<a href="#'.
                    571: 				      $rid.'">'.$hash{'title_'.$rid}.
                    572: 				      '</a><br>');
                    573: 			}
                    574: 		    }
                    575: 		}
                    576: 	    }
1.2       www       577: # ----------------------------------------------------------------- Start table
1.28      albertel  578: 	    $r->print('<hr><table cols="'.$lcm.'" border="0">');
                    579: 	    for ($i=0;$i<=$#rows;$i++) {
                    580: 		if ($rows[$i]) {
                    581: 		    $r->print("\n<tr>");
                    582: 		    my @colcont=split(/\&/,$rows[$i]);
                    583: 		    my $avespan=$lcm/($#colcont+1);
                    584: 		    for ($j=0;$j<=$#colcont;$j++) {
                    585: 			my $rid=$colcont[$j];
                    586: 			my $add='<td>&nbsp;&nbsp;';
                    587: 			my $adde='</td>';
                    588: 			my $hwk='<font color="#223322">';
                    589: 			my $hwke='</font>';
                    590: 			if ($rid=~/^h(.+)/) {
                    591: 			    $rid=$1;
                    592: 			    $add='<th bgcolor="#AAFF55"><a name="'.$rid.'">';
                    593: 			    $adde='</th>';
                    594: 			}
                    595: 			if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) {
                    596: 			    # sub astatus describes what code/tcode mean
                    597: 			    my $code=$1;
                    598: 			    my $tcode=$2;
                    599: 			    my $ctext=$3;
                    600: 			    $rid=$4;
                    601: 			    if ($tcode eq '1') {
                    602: 				$add='<td bgcolor="#AAAAAA">';
                    603: 			    }
                    604: 			    if ($code eq '3') {
                    605: 				$add='<td bgcolor="#AAFFAA">';
                    606: 			    } else {
                    607: 				$add='<td bgcolor="#FFAAAA">';
                    608: 				if ($tcode eq '2') {
                    609: 				    $add='<td bgcolor="#FFFFAA">';
                    610: 				}
                    611: 				if ($tcode eq '4') {
                    612: 				    $add='<td bgcolor="#FFFF33">';
                    613: 				    $adde='</td>';
                    614: 				}
                    615: 			    }
                    616: 			    $hwk='<font color="#888811"><b>';
                    617: 			    $hwke='</b></font>';
                    618: 			    if ($code eq '1') {
                    619: 				$hwke='</b> ('.$ctext.')</font>';
                    620: 			    }
                    621: 			    if ($code eq '2') {
                    622: 				$hwk='<font color="#992222"><b>';
                    623: 				$hwke='</b> ('.$ctext.')</font>';
                    624: 			    }
                    625: 			    if ($code eq '3') {
1.29    ! albertel  626: 				$hwk='<font color="#229922"><b>';
        !           627: 				$hwke='</b> ('.$ctext.')</font>';
        !           628: 			    }
        !           629: 			    if ($code eq '4') {
1.28      albertel  630: 				$hwk='<font color="#229922"><b>';
                    631: 				$hwke='</b> ('.$ctext.')</font>';
                    632: 			    }
                    633: 			}
                    634: 			if ($hash{'src_'.$rid} eq $currenturl) {
                    635: 			    $add=$add.'<a name="curloc"></a>'.
                    636: 				'<font color=red size=+2><b>&gt; </b></font>';
                    637: 			    $adde=
                    638: 				'<font color=red size=+2><b> &lt;</b></font>'.$adde;
                    639: 			}
                    640: 			my $src=
                    641: 			    &Apache::lonnet::declutter($hash{'src_'.$rid});
                    642: 			$rid=~/^(\d+)\.(\d+)$/;
                    643: 			my $symb=
                    644: 			    &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.$src;
                    645: 			if ($discussiontimes{$symb}>$lastcheck) {
                    646: 			    $adde=
                    647: 				'<img border=0 src="/adm/lonMisc/chat.gif">'.
                    648: 				    $adde;
                    649: 			}
                    650: 			if ($error{$src}) {
                    651: 			    foreach (split(/\,/,$error{$src})) {
                    652: 				if ($_) {
                    653: 				    $adde=
                    654: 					'&nbsp;<a href="/adm/email?display='.
                    655: 					    &Apache::lonnet::escape($_).
                    656: 						'"><img src="/adm/lonMisc/bomb.gif" border=0></a>'
                    657: 						    .$adde;
                    658: 				}
                    659: 			    }
                    660: 			}
                    661: 			if ($feedback{$src}) {
                    662: 			    foreach (split(/\,/,$feedback{$src})) {
                    663: 				if ($_) {
                    664: 				    $adde=
                    665: 					'&nbsp;<a href="/adm/email?display='.
                    666: 					    &Apache::lonnet::escape($_).
                    667: 						'"><img src="/adm/lonMisc/feedback.gif" border=0></a>'
                    668: 						    .$adde;
                    669: 				}
                    670: 			    }
                    671: 			}
                    672: 			$r->print($add.'<a href="'.$hash{'src_'.$rid}.
                    673: 				  '">'.$hwk.
                    674: 				  $hash{'title_'.$rid}.$hwke.'</a>'.$adde);
                    675: 		    }
                    676: 		    $r->print('</tr>');
                    677: 		}
                    678: 	    }
                    679: 	    $r->print("\n</table>");
                    680: 	    $r->print('</body></html>');
1.2       www       681: # -------------------------------------------------------------------- End page
1.28      albertel  682: 	}                  
1.2       www       683: # ------------------------------------------------------------- End render page
1.28      albertel  684:     }
1.2       www       685: # ------------------------------------------------------------------ Untie hash
1.28      albertel  686:     unless (untie(%hash)) {
                    687: 	&Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    688: 				 "Could not untie coursemap $fn (browse).</font>"); 
                    689:     }
                    690:     unless (untie(%parmhash)) {
                    691: 	&Apache::lonnet::logthis("<font color=blue>WARNING: ".
                    692: 				 "Could not untie parmhash (browse).</font>"); 
                    693:     }
                    694:     return OK;
1.2       www       695: }
1.1       www       696: 
                    697: 1;
                    698: __END__
1.2       www       699: 
                    700: 
                    701: 
                    702: 
                    703: 
                    704: 
                    705: 

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