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

albertel lon-capa-cvs@mail.lon-capa.org
Mon, 03 Jun 2002 19:28:17 -0000


albertel		Mon Jun  3 15:28:17 2002 EDT

  Modified files:              
    /loncom/interface	lonchart.pm 
  Log:
  - reworked some of the cleanup wok fro BUG#480
  - should find a section for any real students (usection rework)
  - properly handles the results from the name get call
  
  
  
Index: loncom/interface/lonchart.pm
diff -u loncom/interface/lonchart.pm:1.40 loncom/interface/lonchart.pm:1.41
--- loncom/interface/lonchart.pm:1.40	Thu May 30 09:08:34 2002
+++ loncom/interface/lonchart.pm	Mon Jun  3 15:28:17 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonchart.pm,v 1.40 2002/05/30 13:08:34 stredwic Exp $
+# $Id: lonchart.pm,v 1.41 2002/06/03 19:28:17 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -242,31 +242,31 @@
     if($checkForError =~ /^(con_lost|error|no_such_host)/i) {
 	return -1;
     }
-
+    my $cursection='-1';
+    my $oldsection='-1';
+    my $status='Expired';
     foreach my $key (keys (%result)) {
 	my $value = $result{$key};
         if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
             my $section=$1;
             if ($key eq $courseid.'_st') { $section=''; }
 	    my ($dummy,$end,$start)=split(/\_/,$value);
-	    if ( $ActiveFlag ne 'Any' ) {
-		my $now=time;
-		my $notactive=0;
-		if ($start) {
-		    if ($now<$start) { $notactive=1; }
-		}
-		if ($end) {
-		    if ($now>$end) { $notactive=1; }
-		}
-		if ((($ActiveFlag eq 'Expired') && $notactive == 1) || 
-                    (($ActiveFlag eq 'Active') && $notactive == 0 ) ) {
-		    return $section;
-		}
-		else { return '-1'; } 
-	    }
-	    return $section;
+	    my $now=time;
+	    my $notactive=0;
+	    if ($start) { if ($now<$start) { $notactive=1; } }
+	    if ($end) { if ($now>$end) { $notactive=1; } }
+	    if ($notactive == 0) { $status='Active';$cursection=$section;}
+	    if ($notactive == 1) { $oldsection=$section;}
         }
     }
+    if ($status eq $ActiveFlag) {
+      if ($cursection eq '-1') { return $oldsection; }
+      return $cursection;
+    }
+    if ($ActiveFlag eq 'Any') { 
+      if ($cursection eq '-1') { return $oldsection; }
+      return $cursection;
+    }
     return '-1';
 }
 
@@ -287,7 +287,7 @@
 	    $r->print('<h1>Could not access course data</h1>');
 	} else {
 	    my $now=time;
-	    foreach my $name (keys (%classlist)) {
+	    foreach my $name (sort(keys(%classlist))) {
 		my $value=$classlist{$name};
 		my ($end,$start)=split(/\:/,$value);
 		my $active=1;
@@ -308,26 +308,22 @@
 			    'Data not available: '.$name;
 		    } else {
 			my %reply=&Apache::lonnet::idrget($sdom,$sname);
-			my $reply=&Apache::lonnet::get('environment',
+			my %name=&Apache::lonnet::get('environment',
 						       ['lastname','generation'
 						       ,'firstname'
 						       ,'middlename'],
 						       $sdom,$sname);
+			my $name=$name{lastname};
+			if ($name{generation}) {$name.=" $name{generation}";}
+			$name.=',';
+			if ($name{firstname}) {$name.=" $name{firstname}";}
+			if ($name{middlename}) {$name.=" $name{middlename}";}
+			if ($name eq ',') {$name='';}
 			#$ssec=(int($ssec)) ? int($ssec) : $ssec;
 			my $sec=sprintf('%3s',$ssec);
 			$rowlabels[$thisindex]=$sec.' '.$reply{$sname}.' ';
-			$PreCol[$thisindex] .= $reply.':'.$sec;
-			my $i=0;
-			foreach (split(/\&/,$reply)) {
-			    $i++;
-			    if ( $_ ne '') {
-				$rowlabels[$thisindex].=&Apache::lonnet::unescape($_).' ';
-			    }
-			    if ($i == 2) {
-				chop($rowlabels[$thisindex]);
-				$rowlabels[$thisindex].=', ';
-			    }
-			}
+			$PreCol[$thisindex] .= $name.':'.$sec;
+			$rowlabels[$thisindex].=$name.' ';
 		    }
 		}
 	    }