--- loncom/interface/Attic/lonchart.pm 2002/06/28 19:34:12 1.45 +++ loncom/interface/Attic/lonchart.pm 2002/07/01 21:12:06 1.49 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonchart.pm,v 1.45 2002/06/28 19:34:12 stredwic Exp $ +# $Id: lonchart.pm,v 1.49 2002/07/01 21:12:06 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -55,20 +55,24 @@ use Apache::loncommon(); use HTML::TokeParser; use GDBM_File; -#my $jr; +my $jr; # ----- FORMAT PRINT DATA ---------------------------------------------- sub FormatStudentInformation { - my ($cache,$name,$studentInformation,$spacePadding)=@_; + my ($cache,$name,$studentInformation,$reselected,$spacePadding)=@_; my $Str='
'; - foreach (@$studentInformation) { - my $data=$cache->{$name.':'.$_}; + for(my $index=0; $index<(scalar @$studentInformation); $index++) { + if(!&ShouldShowColumn($reselected, 'heading', $index)) { + next; + } + my $data=$cache->{$name.':'.$studentInformation->[$index]}; $Str .= $data; my @dataLength=split(//,$data); my $length=scalar @dataLength; - $Str .= (' 'x($cache->{$_.'Length'}-$length)); + $Str .= (' 'x($cache->{$studentInformation->[$index].'Length'}- + $length)); $Str .= $spacePadding; } @@ -76,7 +80,7 @@ sub FormatStudentInformation { } sub FormatStudentData { - my ($name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_; + my ($reselected,$name,$coid,$studentInformation,$spacePadding,$ChartDB)=@_; my ($sname,$sdom) = split(/\:/,$name); my $Str; my %CacheData; @@ -87,7 +91,7 @@ sub FormatStudentData { # Handle Student information ------------------------------------------ # Handle user data $Str=&FormatStudentInformation(\%CacheData, $name, $studentInformation, - $spacePadding); + $reselected, $spacePadding); # Handle errors if($CacheData{$name.':error'} =~ /environment/) { @@ -116,6 +120,10 @@ sub FormatStudentData { my $problemsSolved = 0; my $numberOfParts = 0; foreach my $sequence (split(/\:/,$CacheData{'orderedSequences'})) { + if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) { + next; + } + my $characterCount=0; foreach my $problemID (split(/\:/,$CacheData{$sequence.':problems'})) { my $problem = $CacheData{$problemID.':problem'}; @@ -215,10 +223,14 @@ sub FormatStudentData { } sub CreateTableHeadings { - my ($CacheData,$studentInformation,$headings,$spacePadding)=@_; + my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_; my $Str=''."\n"; return $Ptr; } @@ -393,6 +496,7 @@ sub ProcessTopResourceMap { my ($currentSequence, $currentResourceID, $lastResourceID); $currentResourceID=$hash{'ids_/res/'.$ENV{'request.course.uri'}}; + push(@currentResource, $currentResourceID); $lastResourceID=-1; $currentSequence=-1; my $topLevelSequenceNumber = $currentSequence; @@ -466,8 +570,6 @@ sub ProcessTopResourceMap { if($currentResourceID eq $lastResourceID) { #pop off last resource of sequence $currentResourceID=pop(@currentResource); - #pop to get last resource in previous sequence - $currentResourceID=pop(@currentResource); $lastResourceID=pop(@finishResource); if(defined($CacheData{$currentSequence.':problems'})) { @@ -482,9 +584,12 @@ sub ProcessTopResourceMap { $hash{'title_'.$currentResourceID}; my $totalProblems=0; - foreach (split(/\:/,$CacheData{$currentSequence. + foreach my $currentProblem (split(/\:/, + $CacheData{$currentSequence. ':problems'})) { - foreach ($CacheData{$currentSequence.':'.$_.':parts'}) { + foreach (split(/\:/,$CacheData{$currentSequence.':'. + $currentProblem. + ':parts'})) { $totalProblems++; } } @@ -519,10 +624,9 @@ sub ProcessTopResourceMap { foreach (split(/\,/,$hash{'to_'.$currentResourceID})) { push(@nextResources, $hash{'goesto_'.$_}); } - pop(@currentResource); push(@currentResource, @nextResources); - # Set the next resource to be popped(processed) - $currentResourceID=$currentResource[-1]; + # Set the next resource to be processed + $currentResourceID=pop(@currentResource); } unless (untie(%hash)) { @@ -635,7 +739,8 @@ sub ProcessClassList { my %CacheData; if(tie(%CacheData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) { foreach my $name (keys(%$classlist)) { - if($name =~ /\:section/ || $name =~ /\:studentInformation/) { + if($name =~ /\:section/ || $name =~ /\:studentInformation/ || + $name eq '') { next; } if($c->aborted()) { @@ -650,8 +755,6 @@ sub ProcessClassList { $name,$courseID,$c); } - $CacheData{'NamesOfStudents'}=join(":::",@names); -# $CacheData{'NamesOfStudents'}=&Apache::lonnet::arrayref2str(\@names); untie(%CacheData); } @@ -730,12 +833,10 @@ sub ProcessFullName { } sub SortStudents { - my ($CacheData)=@_; - my @students = split(/:::/,$CacheData->{'NamesOfStudents'}); -# my @students=&Apache::lonnet::str2array($CacheData->{'NamesOfStudents'}); + my ($students,$CacheData)=@_; my @sorted1Students=(); - foreach (@students) { + foreach (@$students) { my ($end,$start)=split(/\:/,$CacheData->{$_.':date'}); my $active=1; my $now=time; @@ -772,7 +873,7 @@ sub SortStudents { } my @order = (); - foreach my $key (sort keys(%sortData)) { + foreach my $key (sort(keys(%sortData))) { push (@order,$sortData{$key}); } @@ -825,6 +926,11 @@ sub ExtractStudentData { foreach my $key (keys (%$courseData)) { $CacheData{$name.':'.$key}=$courseData->{$key}; } + if(defined($CacheData{'NamesOfStudents'})) { + $CacheData{'NamesOfStudents'}.=':::'.$name; + } else { + $CacheData{'NamesOfStudents'}=$name; + } } untie(%CacheData); } @@ -832,6 +938,31 @@ sub ExtractStudentData { return; } +sub ShouldShowColumn { + my ($reselected,$type,$value)=@_; + + if($ENV{'form.sort'} eq 'Recalculate Chart') { + return 1; + } + + if(defined($ENV{'form.'.$type.$value})) { + return 1; + } + + return &CheckForStringInArray($reselected, $type.$value); +} + +sub CheckForStringInArray { + my ($inputArray,$checkString)=@_; + foreach (@$inputArray) { +# $jr->print('a:'.$_.' b:'.$checkString.''; for(my $index=0; $index<(scalar @$headings); $index++) { + if(!&ShouldShowColumn($reselected, 'heading', $index)) { + next; + } + my $data=$$headings[$index]; $Str .= $data; @@ -230,7 +242,12 @@ sub CreateTableHeadings { } foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) { - $Str .= $CacheData->{$sequence.':title'}; + if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) { + next; + } + + my $name = $CacheData->{$sequence.':title'}; + $Str .= $name; my @titleLength=split(//,$CacheData->{$sequence.':title'}); my $leftover=$CacheData->{$sequence.':columnWidth'}- (scalar @titleLength); @@ -244,6 +261,92 @@ sub CreateTableHeadings { return $Str; } +sub CreateColumnSelectionBox { + my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_; + + my $missing=0; + my $notThere='
Select column to view:
'; + my $name; + $notThere .= '  '; + $notThere .= '
'; + } else { + $notThere=''; + } + + return $notThere; +} + +sub CreateColumnSelectors { + my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_; + + my $found=0; + my ($name, $length, $position); + my $present=''; + for(my $index=0; $index<(scalar @$headings); $index++) { + if(!&ShouldShowColumn($reselected, 'heading', $index)) { + next; + } + $name = $headings->[$index]; + $length=$CacheData->{$$studentInformation[$index].'Length'}; + $position=int($length/2); + $present .= (' 'x($position)); + $present .= ''; + $position+=2; + $present .= (' 'x($length-$position)); + $present .= $spacePadding; + $found++; + } + + foreach my $sequence (split(/\:/,$CacheData->{'orderedSequences'})) { + if(!&ShouldShowColumn($reselected, 'sequence', $sequence)) { + next; + } + $name = $CacheData->{$sequence.':title'}; + $length=$CacheData->{$sequence.':columnWidth'}; + $position=int($length/2); + $present .= (' 'x($position)); + $present .= ''; + $position+=2; + $present .= (' 'x($length-$position)); + $present .= $spacePadding; + $found++; + } + + if($found) { + $present .= ''; + $present = $present; + } else { + $present = ''; + } + + return $present.''."\n";; +} + sub CreateForm { my $OpSel1=''; my $OpSel2=''; @@ -254,6 +357,12 @@ sub CreateForm { else { $OpSel1 = 'selected'; } my $Ptr = '