[LON-CAPA-cvs] cvs: loncom /interface lonnavmaps.pm

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 11 Feb 2002 18:59:36 -0000


albertel		Mon Feb 11 13:59:36 2002 EDT

  Modified files:              
    /loncom/interface	lonnavmaps.pm 
  Log:
  - parmval now cascades up looking for parameters
  - multipart problems work much better
  - if no due date is set it properly makes things yellow
  - <blink> removed
  
  
Index: loncom/interface/lonnavmaps.pm
diff -u loncom/interface/lonnavmaps.pm:1.24 loncom/interface/lonnavmaps.pm:1.25
--- loncom/interface/lonnavmaps.pm:1.24	Mon Feb 11 13:32:22 2002
+++ loncom/interface/lonnavmaps.pm	Mon Feb 11 13:59:36 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Navigate Maps Handler
 #
-# $Id: lonnavmaps.pm,v 1.24 2002/02/11 18:32:22 albertel Exp $
+# $Id: lonnavmaps.pm,v 1.25 2002/02/11 18:59:36 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -129,7 +129,7 @@
 # ------------------------------------------------------- second, check course
     if ($csec) {
 	if ($courseopt{$seclevelr}) { return $courseopt{$seclevelr}; }
-	if ($courseopt{$seclevelm}) { return $courseopt{$seclevelm}; }
+        if ($courseopt{$seclevelm}) { return $courseopt{$seclevelm}; }
         if ($courseopt{$seclevel}) { return $courseopt{$seclevel}; }
     }
 
@@ -144,13 +144,41 @@
 
 # ----------------------------------------------------- fourth , check default
 
-    return &Apache::lonnet::metadata($fn,$rwhat.'.default');
+    my $default=&Apache::lonnet::metadata($fn,$rwhat.'.default');
+    if ($default) { return $default}
+
+# --------------------------------------------------- fifth , cascade up parts
+
+    my ($space,@qualifier)=split(/\./,$rwhat);
+    my $qualifier=join('.',@qualifier);
+    unless ($space eq '0') {
+	my ($part,$id)=split(/\_/,$space);
+	if ($id) {
+	    my $partgeneral=&parmval($part.".$qualifier",$symb);
+	    if ($partgeneral) { return $partgeneral; }
+	} else {
+	    my $resourcegeneral=&parmval("0.$qualifier",$symb);
+	    if ($resourcegeneral) { return $resourcegeneral; }
+	}
+    }
+    return '';
 }
 
 
 
 # ------------------------------------------------------------- Find out status
-
+# return codes
+# tcode (timecode)
+# 1: will open later
+# 2: is open and not past due yet
+# 3: is past due date
+# 4: due in the next 24 hours
+#
+# code (curent solved status)
+# 1: not attempted
+# 2: attempted but wrong, or incorrect by instructor
+# 3: solved or correct by instructor
+# "excused" needs to be supported, but is not yet. Could be code=4.
 sub astatus {
     my $rid=shift;
     my $code=1;
@@ -158,45 +186,49 @@
     $rid=~/(\d+)\.(\d+)/;
     my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
 	&Apache::lonnet::declutter($hash{'src_'.$rid});
-
+    $Apache::lonxml::debug=1;
     my %duedate=();
     my %opendate=();
     my %answerdate=();
-    map {
+    # need to always check part 0's open/due/answer status
+    foreach (sort(split(/\,/,&Apache::lonnet::metadata($hash{'src_'.$rid},'keys')))) {
         if ($_=~/^parameter\_(.*)\_opendate$/) {
 	    my $part=$1;
             $duedate{$part}=&parmval($part.'.duedate',$symb);
             $opendate{$part}=&parmval($part.'.opendate',$symb);
             $answerdate{$part}=&parmval($part.'.answerdate',$symb);
         }
-    } sort split(/\,/,&Apache::lonnet::metadata($hash{'src_'.$rid},'keys'));
-
+    }
     my $now=time;
     my $tcode=0;
 
     my %returnhash=&Apache::lonnet::restore($symb);
 
-    map {
+    foreach (sort(keys(%opendate))) {
 	my $duedate=$duedate{$_};
 	my $opendate=$opendate{$_};
 	my $answerdate=$answerdate{$_};
 	my $preface='';
 	unless ($_ eq '0') { $preface=' Part: '.$_.' '; }
 	if ($opendate) {
-	    if ($now<$duedate) {
-		unless ($tcode==4) { $tcode=2; } 
-		$ctext.=$preface.'Due: '.localtime($duedate);
-		if ($now<$opendate) { 
-		    unless ($tcode) { $tcode=1; } 
+	    if ($now<$duedate || (!$duedate)) {
+		unless ($tcode==4) { $tcode=2; }
+		if ($duedate) {
+		    $ctext.=$preface.'Due: '.localtime($duedate);
+		} else {
+		    $ctext.=$preface.'No Due Date';
+		}
+		if ($now<$opendate) {
+		    unless ($tcode) { $tcode=1; }
 		    $ctext.=$preface.'Open: '.localtime($opendate);
 		}
-		if ($duedate-$now<86400) {
+		if ($duedate && $duedate-$now<86400) {
 		    $tcode=4;
 		    $ctext.=$preface.'Due: '.localtime($duedate);
 		}
 	    } else {
 		unless (($tcode==4) || ($tcode eq 2)) { $tcode=3; }
-		if ($now<$answerdate) {  
+		if ($now<$answerdate) {
 		    $ctext.='Answer: '.localtime($duedate);
 		}
 	    }
@@ -205,7 +237,7 @@
 	}
 	
 	my $status=$returnhash{'resource.'.$_.'.solved'};
-
+	
 	if ($status eq 'correct_by_student') {
 	    unless ($code==2) { $code=3; }
 	    $ctext.=' solved';
@@ -216,8 +248,10 @@
 	    $code=2;
 	    $ctext.=' ('.
 		($returnhash{'resource.'.$_.'.tries'}?
-		 $returnhash{'resource.'.$_.'.tries'}:'0').'/'.
-                     &parmval($_.'.maxtries',$symb).' tries)';
+		 $returnhash{'resource.'.$_.'.tries'}:'0');
+	    my $numtries = &parmval($_.'.maxtries',$symb);
+	    if ($numtries) { $ctext.='/'.$numtries.' tries'; }
+	    $ctext.=')';
 	} elsif ($status eq 'incorrect_by_override') {
 	    $code=2;
 	    $ctext.=' override';
@@ -225,8 +259,7 @@
 	    unless ($code==2) { $code=3; }
 	    $ctext.=' excused';
 	}
-
-    } sort keys %opendate;
+    }
 
     return 'p'.$code.$tcode.'"'.$ctext.'"';
 }
@@ -340,7 +373,6 @@
        $r->send_http_header;
        return OK;
    }
-
   my $requrl=$r->uri;
 # ----------------------------------------------------------------- Tie db file
   if ($ENV{'request.course.fn'}) {
@@ -551,6 +583,7 @@
                                   $adde='</th>';
                               }
                             if ($rid=~/^p(\d)(\d)\"([\w\: \(\)\/\,]*)\"(.+)/) {
+				# sub astatus describes what code/tcode mean
                                   my $code=$1;
                                   my $tcode=$2;
                                   my $ctext=$3;
@@ -566,8 +599,8 @@
                                          $add='<td bgcolor="#FFFFAA">';
                                       }
                                       if ($tcode eq '4') {
-                                         $add='<td bgcolor="#FFFF33"><blink>';
-                                         $adde='</blink></td>';
+                                         $add='<td bgcolor="#FFFF33">';
+                                         $adde='</td>';
                                       }
                                   }
                                   $hwk='<font color="#888811"><b>';