--- loncom/interface/Attic/lonchart.pm 2002/07/01 13:59:13 1.47 +++ 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.47 2002/07/01 13:59:13 stredwic Exp $ +# $Id: lonchart.pm,v 1.49 2002/07/01 21:12:06 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -59,16 +59,20 @@ 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 $Str; + my $missing=0; + my $notThere=''; 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,36 +261,90 @@ sub CreateTableHeadings { return $Str; } -sub CreateColumnSelectors { - my ($CacheData,$studentInformation,$headings,$spacePadding)=@_; - my $Str=''; +sub CreateColumnSelectionBox { + my ($CacheData,$studentInformation,$headings,$reselected,$spacePadding)=@_; - $Str .= '
'; + 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'})) { - $Str .= $CacheData->{$sequence.':title'}; - my @titleLength=split(//,$CacheData->{$sequence.':title'}); - my $leftover=$CacheData->{$sequence.':columnWidth'}- - (scalar @titleLength); - $Str .= (' 'x$leftover); - $Str .= $spacePadding; + 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++; } - return $Str; + if($found) { + $present .= ''; + $present = $present; + } else { + $present = ''; + } + + return $present.''."\n";; } sub CreateForm { @@ -286,6 +357,12 @@ sub CreateForm { else { $OpSel1 = 'selected'; } my $Ptr = ''."\n"; return $Ptr; } @@ -668,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()) { @@ -683,8 +755,6 @@ sub ProcessClassList { $name,$courseID,$c); } - $CacheData{'NamesOfStudents'}=join(":::",@names); -# $CacheData{'NamesOfStudents'}=&Apache::lonnet::arrayref2str(\@names); untie(%CacheData); } @@ -763,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; @@ -805,7 +873,7 @@ sub SortStudents { } my @order = (); - foreach my $key (sort keys(%sortData)) { + foreach my $key (sort(keys(%sortData))) { push (@order,$sortData{$key}); } @@ -858,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); } @@ -865,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.'