--- loncom/interface/lonprintout.pm 2002/09/12 15:25:49 1.63 +++ loncom/interface/lonprintout.pm 2002/09/18 19:41:06 1.69 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.63 2002/09/12 15:25:49 albertel Exp $ +# $Id: lonprintout.pm,v 1.69 2002/09/18 19:41:06 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -48,6 +48,7 @@ use Apache::inputtags; use Apache::grades; use Apache::edit; use Apache::File(); +use Apache::lonnavmaps; use POSIX qw(strftime); use GDBM_File; @@ -87,7 +88,7 @@ sub menu_for_output { Current document $title_for_single_resource -(you will print what you saw on the screen)
+(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(<$symb)); &Apache::lonnet::delenv('form.grade_target'); $result .= $texversion; } @@ -393,7 +392,7 @@ ENDPART my %moreenv; $moreenv{'form.grade_target'}='tex'; &Apache::lonnet::appenv(%moreenv); - my $texversion=&Apache::lonnet::ssi($urlp); + my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$symb)); &Apache::lonnet::delenv('form.grade_target'); $result .= $texversion; } @@ -403,54 +402,10 @@ 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]; + my ($urlp,$symb) = split /&&/, $file_seq[$i]; $urlp=~s/\/home\/httpd\/html//; if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) { my %moreenv; @@ -475,21 +430,18 @@ 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); + my @master_seq = &coming_from_hash($primary_sequence); #loop over students foreach my $person (@students) { my $current_output = ''; my ($usersection,$username,$userdomain) = split /:/,$person; my $fullname = &Apache::grades::get_fullname($username,$userdomain); #goes through all resources, checks if they are available for current student, and produces output - foreach my $curres (@master_seq) { + foreach my $curresline (@master_seq) { + my ($curres,$symb) = split /&&/, $curresline; $curres =~ s/^"//; $curres =~ s/"$//; if ($curres=~/\w+/) { - my $symb = &Apache::lonnet::symbread($curres); my ($map,$id,$res_url) = split(/___/,$symb); if (&Apache::lonnet::allowed('bre',$res_url)) { my $rendered = &Apache::loncommon::get_student_view($symb,$username,$userdomain, @@ -605,17 +557,57 @@ sub coming_from_hash { my $mainsequence = shift; my @resourcelist = (); + my $mapid = $hash{'map_pc_'.$mainsequence}; my $mapstart = $hash{'map_start_'.$mainsequence}; my $mapfinish = $hash{'map_finish_'.$mainsequence}; + my $symb = &Apache::lonnet::symbread($hash{'src_'.$mapstart}); + $symb = m/^([^___]*)___/; + my $presymb = $1.'___'; my $current_resource = $mapstart; while ($current_resource ne $mapfinish) { if (not $hash{'src_'.$current_resource}=~/\.sequence$/) { - push @resourcelist,$hash{'src_'.$current_resource}; + my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}}; + if ($rid=~/,/) { + my @rid = split /,/, $rid; + foreach my $rid_element (@rid) { + if ($rid_element =~ m/^$mapid\.(\d*)/) { + $rid = $1; + last; + } + } + } else { + $rid =~ m/^$mapid\.(\d*)/; + $rid = $1; + } + $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/; + $symb = $presymb.$rid.'___'.$1; + push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb; } else { push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource}); } $current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}}; } + #needs if final resource in the map (type="finish") contains something + if (not $hash{'src_'.$current_resource}=~/\.sequence$/) { + my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}}; + if ($rid=~/,/) { + my @rid = split /,/, $rid; + foreach my $rid_element (@rid) { + if ($rid_element =~ m/^$mapid\.(\d*)/) { + $rid = $1; + last; + } + } + } else { + $rid =~ m/^$mapid\.(\d*)/; + $rid = $1; + } + $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/; + $symb = $presymb.$rid.'___'.$1; + push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb; + } else { + push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource}); + } return @resourcelist; } @@ -959,78 +951,21 @@ sub additional_cleanup { } return $result; } + + sub page_cleanup { my $result = shift; - $_ = $result; - m/\\end{document}(\d*)$/; + + $result =~ m/\\end{document}(\d*)$/; my $number_of_columns = $1; my $insert = '{'; for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; } $insert .= '}'; - $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE/$1$insert/g; + $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g; $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g; - $result =~ s/(\\vskip\s*\d+\s*mm)/}\\\\\\parbox{\\minipagewidth}{/g; - $result =~ s/\\parbox{\\minipagewidth}{}\s*\\\\\s*(\\parbox{\\minipagewidth})/$1/g; - $result =~ s/\\parbox{\\minipagewidth}{\s*\\\\\\\\/\\parbox{\\minipagewidth}{/g; return $result,$number_of_columns; } -sub content_map { -#-- find a list of files to print - my $map_string = shift; - my @number_seq = (); - my @file_seq = (); - my $startlink = index($map_string,'',$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; - } - return @file_seq; -} - sub details_for_menu { @@ -1055,6 +990,14 @@ sub details_for_menu { sub handler { my $r = shift; + + my $loaderror=&Apache::lonnet::overloaderror($r); + if ($loaderror) { return $loaderror; } + $loaderror= + &Apache::lonnet::overloaderror($r, + $ENV{'course.'.$ENV{'request.course.id'}.'.home'}); + if ($loaderror) { return $loaderror; } + $r->content_type('text/html'); $r->send_http_header; $r->print(&Apache::loncommon::bodytag("Printing"));