--- loncom/interface/Attic/lonchart.pm 2002/02/19 20:22:00 1.31 +++ loncom/interface/Attic/lonchart.pm 2002/03/02 01:44:00 1.36 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonchart.pm,v 1.31 2002/02/19 20:22:00 minaeibi Exp $ +# $Id: lonchart.pm,v 1.36 2002/03/02 01:44:00 minaeibi Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,7 +25,6 @@ # # http://www.lon-capa.org/ # -# # Homework Performance Chart # # (Navigate Maps Handler @@ -43,7 +42,7 @@ # 9/8 Gerd Kortemeyer # 10/1, 10/19, 11/17, 11/22, 11/24, 11/28 12/18 Behrouz Minaei # YEAR=2002 -# 2/1, 2/6, 2/19 Behrouz Minaei +# 2/1, 2/6, 2/19, 2/28 Behrouz Minaei # ### @@ -64,7 +63,7 @@ my @rowlabels; my @students; my @PreCol; my $r; - + # ------------------------------------------------------------- Find out status sub ExtractStudentData { @@ -225,6 +224,68 @@ sub tracetable { } +sub usection2 { + my ($udom,$unam,$courseid,$ActiveFlag)=@_; + $courseid=~s/\_/\//g; + $courseid=~s/^(\w)/\/$1/; + foreach my $elem(split(/\&/,&Apache::lonnet::reply('dump:'.$udom.':'.$unam.':roles', + &Apache::lonnet::homeserver($unam,$udom)))) { + my ($key,$value)=split(/\=/,$elem); + $key=&Apache::lonnet::unescape($key); + if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) { + my $section=$1; + if ($key eq $courseid.'_st') { $section=''; } + my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value)); + my $now=time; + my $notactive=0; + if ($start) { + if ($now<$start) { $notactive=1; } + } + if ($end) { + if ($now>$end) { $notactive=1; } + } + if ($ActiveFlag == 1) { $notactive=0; } + unless ($notactive) { return $section; } + } + } + return '-1'; +} + + +sub usection { + my ($udom,$unam,$courseid,$ActiveFlag)=@_; + $courseid=~s/\_/\//g; + $courseid=~s/^(\w)/\/$1/; + foreach (split(/\&/,&Apache::lonnet::reply('dump:'. + $udom.':'.$unam.':roles', + &Apache::lonnet::homeserver($unam,$udom)))){ + my ($key,$value)=split(/\=/,$_); + $key=&Apache::lonnet::unescape($key); + if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) { + my $section=$1; + if ($key eq $courseid.'_st') { $section=''; } + my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($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; + } + } + return '-1'; +} + sub BuildChart { # ----------------------- Get first and last resource, see if there is anything my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}}; @@ -243,22 +304,30 @@ sub BuildChart { my ($name,$value)=split(/\=/,$KeyPoint); my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value)); my $active=1; - if (($end) && ($now>$end)) { $active=0; } + my $Status=$ENV{'form.status'}; + $Status = ($Status) ? $Status : 'Active'; + if ( ( ($end) && $now > $end ) && + ( ($Status eq 'Active') ) ) { $active=0; } + + if ( ($Status eq 'Expired') && + ($end == 0 || $now < $end) ) { $active=0; } + if ($active) { my $thisindex=$#students+1; $name=&Apache::lonnet::unescape($name); $students[$thisindex]=$name; my ($sname,$sdom)=split(/\:/,$name); $PreCol[$thisindex]=$sname.':'; - my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid); + my $ssec=&usection($sdom,$sname,$cid,$Status); if ($ssec==-1) { $rowlabels[$thisindex]= 'Data not available: '.$name; - } else { + } + else { my %reply=&Apache::lonnet::idrget($sdom,$sname); my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname. - ':environment:lastname&generation&firstname&middlename', - &Apache::lonnet::homeserver($sname,$sdom)); + ':environment:lastname&generation&firstname&middlename', + &Apache::lonnet::homeserver($sname,$sdom)); #$ssec=(int($ssec)) ? int($ssec) : $ssec; my $sec=sprintf('%3s',$ssec); $rowlabels[$thisindex]=$sec.' '.$reply{$sname}.' '; @@ -306,22 +375,36 @@ sub BuildChart { } sub CreateForm { + my $OpSel1=''; + my $OpSel2=''; + my $OpSel3=''; + my $Status = $ENV{'form.status'}; + if ( $Status eq 'Any' ) { $OpSel3='selected'; } + elsif ($Status eq 'Expired' ) { $OpSel2 = 'selected'; } + else { $OpSel1 = 'selected'; } + my $Ptr = '
'."\n"; $Ptr .= ' Sort by:   '."\n"; $Ptr .= '   '; - $Ptr .= ''."\n"; + $Ptr .= ''."\n"; $Ptr .= '   '; $Ptr .= ''."\n"; $Ptr .= '   '; $Ptr .= ''."\n"; - $Ptr .= '
'; + $Ptr .= '

'; + $Ptr .= ' Student Status:   '."\n". + ' '."\n"; + $Ptr .= '   '; $Ptr .= ''."\n"; $Ptr .= '
'."\n"; $r->print( $Ptr ); } sub CacheChart { - my @list = (); + my %list = (); my $count=0; my $Pos = $ENV{'form.sort'}; @@ -332,11 +415,11 @@ sub CacheChart { foreach my $key( keys %CachData) { my @Temp=split(/\:/,$key); my $Use = $Temp[$Pos]; - $list[$count]=$Use.$key.'*'.$CachData{$key}; + $list{$Use.$key}=$key; $count++; } - @list = sort (@list); + my @order = sort(keys(%list)); $r->print('

'.$count.' students

'); &CreateForm(); @@ -344,8 +427,7 @@ sub CacheChart { $r->print('

');
     for ( my $n; $n < $count; $n++) {
-	my ($dummy, $Line) = split(/\*/,$list[$n]);
-	$r->print($Line.'
'); + $r->print($CachData{$list{$order[$n]}}.'
'); } $r->print('
'); } @@ -459,10 +541,3 @@ sub handler { } 1; __END__ - - - - - - -