Annotation of loncom/interface/lonnavmaps.pm, revision 1.48
1.2 www 1: # The LearningOnline Network with CAPA
2: # Navigate Maps Handler
1.1 www 3: #
1.48 ! bowersj2 4: # $Id: lonnavmaps.pm,v 1.47 2002/09/03 20:46:30 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.48 ! bowersj2 467: # ------------------------------------------------- Get coursedata (if present)
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.48 ! bowersj2 475: # check to see if network failed
! 476: elsif ( $reply=~/no.such.host/i || $reply=~/con.*lost/i )
1.47 bowersj2 477: {
478: $networkFailedFlag = 1;
479: }
1.28 albertel 480: }
481: foreach (split(/\&/,$courserdatas{$cid})) {
482: my ($name,$value)=split(/\=/,$_);
483: $courseopt{$userprefix.&Apache::lonnet::unescape($name)}=
484: &Apache::lonnet::unescape($value);
485: }
1.10 www 486: # --------------------------------------------------- Get userdata (if present)
1.28 albertel 487: unless ((time-$userrdatas{$uname.'___'.$udom.'.last_cache'})<240) {
488: my $reply=&Apache::lonnet::reply('dump:'.$udom.':'.$uname.':resourcedata',$uhome);
489: if ($reply!~/^error\:/) {
490: $userrdatas{$uname.'___'.$udom}=$reply;
491: $userrdatas{$uname.'___'.$udom.'.last_cache'}=time;
492: }
493: }
494: foreach (split(/\&/,$userrdatas{$uname.'___'.$udom})) {
495: my ($name,$value)=split(/\=/,$_);
496: $useropt{$userprefix.&Apache::lonnet::unescape($name)}=
497: &Apache::lonnet::unescape($value);
498: }
499: }
500:
501: @rows=();
502:
1.44 www 503: &tracetable(0,$firstres,'&','',0);
1.2 www 504:
505: # ------------------------------------------------------------------ Page parms
506:
1.28 albertel 507: my $j;
508: my $i;
509: my $lcm=1;
510: my $contents=0;
1.2 www 511:
512: # ---------------------------------------------- Go through table to get layout
513:
1.28 albertel 514: for ($i=0;$i<=$#rows;$i++) {
515: if ($rows[$i]) {
1.32 albertel 516: &Apache::lonxml::debug("Row $i is:".$rows[$i]);
1.28 albertel 517: $contents++;
518: my @colcont=split(/\&/,$rows[$i]);
519: $lcm*=($#colcont+1)/euclid($lcm,($#colcont+1));
520: }
521: }
1.5 www 522:
1.2 www 523:
1.28 albertel 524: unless ($contents) {
525: $r->print('<html><body>Empty Map.</body></html>');
526: } else {
1.10 www 527:
1.2 www 528: # ------------------------------------------------------------------ Build page
529:
1.28 albertel 530: my $currenturl=$ENV{'form.postdata'};
531: $currenturl=~s/^http\:\/\///;
532: $currenturl=~s/^[^\/]+//;
1.13 www 533:
1.2 www 534: # ---------------------------------------------------------------- Send headers
535:
1.28 albertel 536: my $date=localtime;
537: my $now=time;
1.21 www 538: # ----------------------------------------- Get email status and discussiontime
539:
1.28 albertel 540: my %emailstatus=&Apache::lonnet::dump('email_status');
541: my $logouttime=$emailstatus{'logout'};
542: my $courseleave=$emailstatus{'logout_'.$ENV{'request.course.id'}};
543: my $lastcheck=($courseleave>$logouttime?$courseleave:$logouttime);
544:
545: my %discussiontimes=&Apache::lonnet::dump('discussiontimes',
546: $cdom,$cnum);
547:
548: my %feedback=();
549: my %error=();
550: foreach my $msgid (split(/\&/,&Apache::lonnet::reply('keys:'.
551: $ENV{'user.domain'}.':'.
552: $ENV{'user.name'}.':nohist_email',
553: $ENV{'user.home'}))) {
554: $msgid=&Apache::lonnet::unescape($msgid);
555: my $plain=&Apache::lonnet::unescape(&Apache::lonnet::unescape($msgid));
556: if ($plain=~/(Error|Feedback) \[([^\]]+)\]/) {
557: my ($what,$url)=($1,$2);
558: my %status=
559: &Apache::lonnet::get('email_status',[$msgid]);
560: if ($status{$msgid}=~/^error\:/) {
561: $status{$msgid}='';
562: }
563:
564: if (($status{$msgid} eq 'new') ||
565: (!$status{$msgid})) {
566: if ($what eq 'Error') {
567: $error{$url}.=','.$msgid;
568: } else {
569: $feedback{$url}.=','.$msgid;
570: }
571: }
572: }
573: }
1.22 www 574: # ----------------------------------------------------------- Start Page Output
1.43 www 575: my $bodytagadd='';
576: $r->print(
577: '<html><head><title>Navigate Course Map</title></head>');
1.28 albertel 578: if (($currenturl=~/^\/res/) &&
579: ($currenturl!~/^\/res\/adm/)) {
1.43 www 580: $bodytagadd='onLoad="window.location.hash='."'curloc'".'"';
1.28 albertel 581: }
1.43 www 582: $r->print(&Apache::loncommon::bodytag('Navigate Course Map','',
583: $bodytagadd));
584: $r->print('<script>window.focus();</script>');
1.41 albertel 585: my $desc=$ENV{'course.'.$ENV{'request.course.id'}.'.description'};
586: if (defined($desc)) { $r->print("<h2>$desc</h2>\n"); }
587: $r->print("<h3>$date</h3>\n");
1.28 albertel 588: $r->rflush();
589: $r->print('<img src="/adm/lonMisc/chat.gif"> New discussion since '.
590: localtime($lastcheck).
591: '<br><img src="/adm/lonMisc/feedback.gif"> New message (click to open)<p>');
592: if (($currenturl=~/^\/res/) &&
593: ($currenturl!~/^\/res\/adm/)) {
594: $r->print('<a href="#curloc">Current Location</a><p>');
595: }
1.47 bowersj2 596:
597: # Handle a network error
598:
599: if ($networkFailedFlag)
600: {
601: $r->print('<H2>LON-CAPA network failure.</H2>'."\n");
602: $r->print("<p>LON-CAPA's network is having difficulties, some problem" .
603: " information, such as due dates, will not be available.");
604: }
1.13 www 605: # ----------------------------------------------------- The little content list
1.28 albertel 606: for ($i=0;$i<=$#rows;$i++) {
607: if ($rows[$i]) {
608: my @colcont=split(/\&/,$rows[$i]);
609: my $avespan=$lcm/($#colcont+1);
610: for ($j=0;$j<=$#colcont;$j++) {
611: my $rid=$colcont[$j];
612: if ($rid=~/^h(.+)/) {
613: $rid=$1;
614: $r->print(' <a href="#'.
615: $rid.'">'.$hash{'title_'.$rid}.
616: '</a><br>');
617: }
618: }
619: }
620: }
1.2 www 621: # ----------------------------------------------------------------- Start table
1.28 albertel 622: $r->print('<hr><table cols="'.$lcm.'" border="0">');
623: for ($i=0;$i<=$#rows;$i++) {
624: if ($rows[$i]) {
625: $r->print("\n<tr>");
626: my @colcont=split(/\&/,$rows[$i]);
627: my $avespan=$lcm/($#colcont+1);
1.45 bowersj2 628:
629: # for each item I wish to print on this row...
1.28 albertel 630: for ($j=0;$j<=$#colcont;$j++) {
1.32 albertel 631: my $indent;my $indentstr;
632: my $linkid;
1.28 albertel 633: my $rid=$colcont[$j];
1.36 www 634: $rid=~/(\d+)\.(\d+)$/;
635: my $src=
636: &Apache::lonnet::declutter($hash{'src_'.$1.'.'.$2});
637: my $symb=
638: &Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.$src;
1.32 albertel 639: my $add='<td>';
1.28 albertel 640: my $adde='</td>';
641: my $hwk='<font color="#223322">';
642: my $hwke='</font>';
1.32 albertel 643: if ($rid=~/^l(\d+\.\d+),(.+)/) { $linkid=$1; $rid=$2; }
644: if ($rid=~/^i(\d+),(.+)/) { $indent=$1; $rid=$2; }
1.28 albertel 645: if ($rid=~/^h(.+)/) {
646: $rid=$1;
647: $add='<th bgcolor="#AAFF55"><a name="'.$rid.'">';
648: $adde='</th>';
1.36 www 649: if (($ENV{'user.adv'}) &&
650: ($parmhash{$symb.'.0.parameter_randompick'})) {
651: $adde=' (randomly select '.
652: $parmhash{$symb.'.0.parameter_randompick'}.
653: ')</th>';
654: }
1.28 albertel 655: }
1.32 albertel 656: if ($rid=~/^j(.+)/) { $rid=$1; }
1.28 albertel 657: if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) {
658: # sub astatus describes what code/tcode mean
659: my $code=$1;
660: my $tcode=$2;
661: my $ctext=$3;
662: $rid=$4;
1.47 bowersj2 663:
664: # will open later
665: if ($tcode eq '1') {
1.28 albertel 666: $add='<td bgcolor="#AAAAAA">';
667: }
1.47 bowersj2 668:
669: # solved/correct
1.28 albertel 670: if ($code eq '3') {
671: $add='<td bgcolor="#AAFFAA">';
1.47 bowersj2 672: } elsif ($code eq '4') { # partially correct
1.30 albertel 673: $add='<td bgcolor="#E0FFAA">';
1.28 albertel 674: } else {
1.47 bowersj2 675: # not attempted
676:
677: # we end up here on network failure, so pick a neutral
678: # color if the network failed instead of bright red.
679: if ( $networkFailedFlag )
680: {
681: $add = '<td bgcolor="#AAAAAA">';
682: }
683: else
684: {
685: $add='<td bgcolor="#FFAAAA">';
686: }
687:
688: if ($tcode eq '2') { # open, not past due
1.28 albertel 689: $add='<td bgcolor="#FFFFAA">';
690: }
1.47 bowersj2 691:
692: if ($tcode eq '4') { # due in next 24 hours
1.28 albertel 693: $add='<td bgcolor="#FFFF33">';
694: $adde='</td>';
695: }
696: }
697: $hwk='<font color="#888811"><b>';
698: $hwke='</b></font>';
699: if ($code eq '1') {
700: $hwke='</b> ('.$ctext.')</font>';
701: }
1.30 albertel 702: if ($code eq '2' || $code eq '4') {
1.28 albertel 703: $hwk='<font color="#992222"><b>';
704: $hwke='</b> ('.$ctext.')</font>';
705: }
706: if ($code eq '3') {
707: $hwk='<font color="#229922"><b>';
708: $hwke='</b> ('.$ctext.')</font>';
1.47 bowersj2 709: }
710: if ($networkFailedFlag)
711: {
712: $hwke='</b> (status unavailable)</font>';
1.28 albertel 713: }
714: }
1.33 albertel 715: if ($rid && $hash{'src_'.$rid} eq $currenturl) {
1.28 albertel 716: $add=$add.'<a name="curloc"></a>'.
717: '<font color=red size=+2><b>> </b></font>';
718: $adde=
719: '<font color=red size=+2><b> <</b></font>'.$adde;
720: }
721: if ($discussiontimes{$symb}>$lastcheck) {
722: $adde=
723: '<img border=0 src="/adm/lonMisc/chat.gif">'.
724: $adde;
725: }
726: if ($error{$src}) {
727: foreach (split(/\,/,$error{$src})) {
728: if ($_) {
729: $adde=
730: ' <a href="/adm/email?display='.
731: &Apache::lonnet::escape($_).
732: '"><img src="/adm/lonMisc/bomb.gif" border=0></a>'
733: .$adde;
734: }
735: }
736: }
737: if ($feedback{$src}) {
738: foreach (split(/\,/,$feedback{$src})) {
739: if ($_) {
740: $adde=
741: ' <a href="/adm/email?display='.
742: &Apache::lonnet::escape($_).
743: '"><img src="/adm/lonMisc/feedback.gif" border=0></a>'
744: .$adde;
745: }
746: }
747: }
1.32 albertel 748: if ($indent) {
749: my $is=" ";
750: for(my $i=-1;$i<$indent;$i++) { $indentstr.=$is; }
751: }
752: if (!$linkid) { $linkid=$rid; }
1.38 www 753: if ($hash{'randomout_'.$rid}) {
754: $adde=' <i>(hidden)</i>'.$adde;
755: }
1.33 albertel 756: $r->print($add.$indentstr);
757: if ($rid) {
1.34 www 758: $r->print('<a href="'.$hash{'src_'.$linkid}.
1.39 www 759: (($hash{'src_'.$linkid}=~/\?/)?'&':'?').
760: 'symb='.&Apache::lonnet::escape($symb)
1.35 www 761: .'">'.
1.33 albertel 762: $hwk.$hash{'title_'.$rid}.$hwke.'</a>');
763: }
764: $r->print($adde);
1.28 albertel 765: }
766: $r->print('</tr>');
767: }
768: }
769: $r->print("\n</table>");
770: $r->print('</body></html>');
1.2 www 771: # -------------------------------------------------------------------- End page
1.28 albertel 772: }
1.2 www 773: # ------------------------------------------------------------- End render page
1.28 albertel 774: }
1.2 www 775: # ------------------------------------------------------------------ Untie hash
1.28 albertel 776: unless (untie(%hash)) {
777: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
778: "Could not untie coursemap $fn (browse).</font>");
779: }
780: unless (untie(%parmhash)) {
781: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
782: "Could not untie parmhash (browse).</font>");
783: }
784: return OK;
1.2 www 785: }
1.1 www 786:
787: 1;
788: __END__
1.2 www 789:
790:
791:
792:
793:
794:
795:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>