--- loncom/interface/lonprintout.pm 2002/09/10 20:14:35 1.59 +++ loncom/interface/lonprintout.pm 2002/09/16 16:36:56 1.66 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.59 2002/09/10 20:14:35 sakharuk Exp $ +# $Id: lonprintout.pm,v 1.66 2002/09/16 16:36:56 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,6 +49,10 @@ use Apache::grades; use Apache::edit; use Apache::File(); use POSIX qw(strftime); +use GDBM_File; + + +my %hash; sub headerform { @@ -60,41 +64,49 @@ sub headerform {
-$ENV{'form.postdata'}

ENDHEADER + if ($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) { + $r->print(<Path to current document: $ENV{'form.postdata'}

+ENDHEADER1 +} } sub menu_for_output { my $r = shift; - my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'}); -# $symbolic =~ m/([^_]+)_/; -# my $primary_sequence = '/res/'.$1; + my ($title_for_single_resource,$title_for_sequence,$title_for_main_map) = &details_for_menu; + if ($title_for_single_resource ne '') {$title_for_single_resource = '"'.$title_for_single_resource.'"';} + if ($title_for_sequence ne '') {$title_for_sequence = '"'.$title_for_sequence.'"';} + if ($title_for_main_map ne '') {$title_for_main_map = '"'.$title_for_main_map.'"';} + my $subdir_to_print = $ENV{'form.postdata'}; + $subdir_to_print =~ m/\/([^\/]+)$/; + $subdir_to_print =~ s/$1//; $r->print(<What do you want to print? Make a choice.
- Current document -(you will print what you see on the screen)
+ Current document $title_for_single_resource +(prints what you just saw on the screen)
ENDMENUOUT1 if ((not $ENV{'request.role'}=~m/^au\./) and (not $ENV{'request.role'}=~m/^ca\./)) { $r->print(< All problems from the primary sequence
- The whole primary sequence (problems plus all html and xml files)
+ All problems from $title_for_sequence
+ All problems plus any html/xml files from $title_for_sequence
ENDMENUOUT2 } if ($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) { $r->print(< All problems from the top level sequence
+ All problems in this course (warning: this may be time consuming)

- Print assignment (all problems from the primary sequence) for group of students

+ All problems from $title_for_sequence for selected students

ENDMENUOUT6 } my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'}); $subdirtoprint =~ s/\/[^\/]+$//; if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') { $r->print(< All problems from current subdirectory (where this particular problem is)
+ Problems from current subdirectory $subdir_to_print
ENDMENUOUT4 } $r->print(< Paper size (format [width x height]):   - +  +

ENDMENUOUT1 my $i; @@ -249,10 +261,10 @@ ENDMENUOUT1 } } -  - +  +   - +

ENDDISHEADER my $i = 0; @@ -348,9 +360,10 @@ ENDPART my $texversion=&Apache::lonnet::ssi($ENV{'form.url'}); &Apache::lonnet::delenv('form.grade_target'); $result .= $texversion; - $result = &additional_cleanup($result); if ($ENV{'form.url'}=~m/\.page\s*$/) { ($result,$number_of_columns) = &page_cleanup($result); + } else { + $result = &additional_cleanup($result); } } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or $choice eq 'Standard LaTeX output for whole primary sequence') { @@ -359,19 +372,13 @@ ENDPART my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'}); $symbolic =~ m/([^_]+)_/; my $primary_sequence = '/res/'.$1; - #-- open and analyses the primary sequence - my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence); - my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file); - my @master_seq = &content_map($sequencefilecontents); + my @master_seq = &coming_from_hash($primary_sequence); #-- produce an output string for (my $i=0;$i<=$#master_seq;$i++) { - $_ = $master_seq[$i]; - m/\"(.*)\"/; - $_ = $1; - my $urlp = $1; + my $urlp = $master_seq[$i]; if ($choice eq 'Standard LaTeX output for the primary sequence') { $selectionmade = 2; - if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) { + if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) { my %moreenv; $moreenv{'form.grade_target'}='tex'; &Apache::lonnet::appenv(%moreenv); @@ -394,51 +401,7 @@ ENDPART # where is the main sequence of the course? $selectionmade = 4; my $main_seq = '/res/'.$ENV{'request.course.uri'}; - my $file=&Apache::lonnet::filelocation("",$main_seq); - my $filecontents=&Apache::lonnet::getfile($file); - my @file_seq = &content_map($filecontents); - for (my $iu=0;$iu<=$#file_seq;$iu++) { - $file_seq[$iu]=~s/^"//; - $file_seq[$iu]=~s/"$//; - if ($file_seq[$iu]=~m/\S+/) { - $file_seq[$iu]=&Apache::lonnet::filelocation("",$file_seq[$iu]); - } else { - $file_seq[$iu]= 'REMOVE IT PLEASE'; - } - } - my $i=0; - my $limit = $#file_seq; - while ($i<=$limit) { - unless ($file_seq[$i]=~m/\.(problem|page)/) { - if ($file_seq[$i]=~m/\.sequence/) { - my $filecontents=&Apache::lonnet::getfile($file_seq[$i]); - my @newfile_seq = &content_map($filecontents); - for (my $iu=0;$iu<=$#newfile_seq;$iu++) { - $newfile_seq[$iu]=~s/^"//; - $newfile_seq[$iu]=~s/"$//; - if ($newfile_seq[$iu]=~m/\S+/) { - $newfile_seq[$iu]=&Apache::lonnet::filelocation("",$newfile_seq[$iu]); - } else { - $newfile_seq[$iu]= 'REMOVE IT PLEASE'; - } - } - splice @file_seq,$i,1,@newfile_seq; - $i=0; - $limit = $#file_seq; - } else { - splice @file_seq,$i,1,'REMOVE IT PLEASE'; - } - } - $i++; - } - for (my $iu=0;$iu<=$#file_seq;$iu++) { - if ($file_seq[$iu]=~m/REMOVE IT PLEASE/) { - splice @file_seq,$iu,1; - } - } - if ($file_seq[-1]=~m/REMOVE IT PLEASE/) { - pop @file_seq; - } + my @file_seq = &coming_from_hash($main_seq); #-- produce an output string for (my $i=0;$i<=$#file_seq;$i++) { my $urlp = $file_seq[$i]; @@ -466,11 +429,8 @@ ENDPART my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'}); $symbolic =~ m/([^_]+)_/; my $primary_sequence = '/res/'.$1; - #opens and analyses the primary sequence file, produces the array of resources - my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence); - my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file); - my @master_seq = &content_map($sequencefilecontents); - #loop over students + my @master_seq = &coming_from_hash($primary_sequence); + #loop over students foreach my $person (@students) { my $current_output = ''; my ($usersection,$username,$userdomain) = split /:/,$person; @@ -591,6 +551,32 @@ $r->print(<',$startlink); - my $chunk = substr($map_string,$startlink,$endlink-$startlink+7); - $_ = $chunk; - m/from=\"(\d+)\"/; - push @number_seq,$1; - while ($startlink != -1) { - $endlink = index($map_string,'',$startlink); - $chunk = substr($map_string,$startlink,$endlink-$startlink+7); - substr($map_string,$startlink,$endlink-$startlink+7) = ''; - $_ = $chunk; - m/to=\"(\d+)\"/; - push @number_seq,$1; - $startlink = index($map_string,'from="'.$1.'"',0); - $startlink = rindex($map_string,'',$startlink); - $chunk = substr($map_string,$startlink,$endlink-$startlink+7); - substr($map_string,$startlink,$endlink-$startlink+7) = ''; - $_ = $chunk; - m/from=\"(\d+)\"/; - unshift @number_seq,$1; - $stalink = index($map_string,' to="'.$number_seq[0].'"',0); - } - for (my $i=0;$i<=$#number_seq;$i++) { - $stalink = index($map_string,' id="'.$number_seq[$i].'"',0); - { - my $ahed1 = index($map_string,'src="',$stalink); - my $ahed2 = index($map_string,'',$stalink); - if ($ahed1 != -1) { - if ($ahed1 < $ahed2) { - $startlink = $ahed1; - } else { - $startlink = rindex($map_string,'src="',$stalink); - } - } else { - $startlink = rindex($map_string,'src="',$stalink); - } - } - $startlink = index($map_string,'"',$startlink); - $endlink = index($map_string,'"',$startlink+1); - $chunk = substr($map_string,$startlink,$endlink-$startlink+1); - push @file_seq,$chunk; +sub details_for_menu { + + my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}}; + my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'}); + my ($map,$id,$resource)=split(/___/,$symbolic); + my $name_of_sequence = $hash{'title_'.$hash{'ids_/res/'.$map}}; + if ($name_of_sequence =~ /^\s*$/) { + $map =~ m|([^/]+)$|; + $name_of_sequence = $1; + } + my $name_of_map = $hash{'title_'.$hash{'ids_/res/'.$ENV{'request.course.uri'}}}; + if ($name_of_map =~ /^\s*$/) { + $ENV{'request.course.uri'} =~ m|([^/]+)$|; + $name_of_map = $1; } - return @file_seq; -} + return ($name_of_resourse,$name_of_sequence,$name_of_map); +} sub handler { @@ -1011,6 +957,11 @@ sub handler { $r->send_http_header; $r->print(&Apache::loncommon::bodytag("Printing")); + if ($ENV{'request.course.id'}) { + my $fn=$ENV{'request.course.fn'}; + tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640); + } + #-- start form &headerform($r); #-- menu for output @@ -1038,11 +989,13 @@ sub handler { #-- core part if ($ENV{'form.phase'} eq 'four') { &output_data($r); - } + } + untie %hash; return OK; - + } + 1; __END__