Annotation of loncom/interface/lonprintout.pm, revision 1.8

1.1       www         1: # The LearningOnline Network
                      2: # Printout
                      3: #
                      4: # (Internal Server Error Handler
                      5: #
                      6: # (Login Screen
                      7: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
                      8: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
                      9: #
                     10: # 3/1/1 Gerd Kortemeyer)
                     11: #
                     12: # 3/1 Gerd Kortemeyer
                     13: #
1.3       sakharuk   14: # 9/17 Alex Sakharuk
                     15: #
1.1       www        16: package Apache::lonprintout;
                     17: 
                     18: use strict;
                     19: use Apache::Constants qw(:common);
1.2       sakharuk   20: use Apache::lonxml;
                     21: use Apache::lonnet;
1.5       sakharuk   22: use Apache::File();
1.1       www        23: 
1.3       sakharuk   24: 
                     25: 
                     26: sub headerform {
1.1       www        27:     my $r = shift;
1.3       sakharuk   28:     $r->print(<<ENDHEADER);
                     29: <html>
                     30: <head>
                     31: <title>LON-CAPA output for printing</title>
                     32: </head>
                     33: <body bgcolor="FFFFFF">
                     34: <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">
                     35: <h1>Printout:</h1><br></br>
                     36: ENDHEADER
                     37: }
                     38: 
1.1       www        39: 
1.3       sakharuk   40: sub menu_for_output {
                     41:     my $r = shift;
                     42:     $r->print(<<ENDMENUOUT);
                     43: <input type="hidden" name="phase" value="two">
                     44: <input type="radio" name="choice" value="Standard LaTeX output for current document">  Standard LaTeX output for current document<br></br>
1.8     ! sakharuk   45: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence">  Standard LaTeX output for the primary sequence<br></br>
        !            46: <input type="radio" name="choice" value="Standard LaTeX output for the top level sequence">  Standard LaTeX output for the top level sequence<br></br>
1.3       sakharuk   47: <input type="submit" value="Please make a choice">
                     48: </form>
                     49: </body>
                     50: </html>
                     51: ENDMENUOUT
                     52: }
1.2       sakharuk   53: 
                     54: 
1.3       sakharuk   55: sub output_data {
                     56:     my $r = shift;
                     57:     $r->print(<<ENDPART);
                     58: <html>
                     59: <head>
                     60: <title>LON-CAPA output for printing</title>
                     61: </head>
                     62: <body bgcolor="FFFFFF">
                     63: <hr>
                     64: ENDPART
1.2       sakharuk   65: 
1.3       sakharuk   66:     my $choice = $ENV{'form.choice'};
1.2       sakharuk   67:     my $result = '';
                     68:     my %mystyle;
1.6       sakharuk   69:     my $filename;
1.5       sakharuk   70: 
1.3       sakharuk   71:     if ($choice eq 'Standard LaTeX output for current document') {
                     72: 	my $file=&Apache::lonnet::filelocation("",'/res/'.$ENV{'request.ambiguous'});
                     73: 	my $filecontents=&Apache::lonnet::getfile($file);
                     74: 	$result = &Apache::lonxml::xmlparse('tex',$filecontents,'',%mystyle);
1.8     ! sakharuk   75:     } elsif ($choice eq 'Standard LaTeX output for the primary sequence') {
1.7       sakharuk   76: 	my @master_seq = ();
                     77: 	my $keyword = 0;
                     78: 	my $output_seq = '';
                     79: 	my $current_file = '/res/'.$ENV{'request.ambiguous'};
                     80:         $current_file =~ s/(\/res\/physnet\/physnet)(\/m\d+)\/(.*)/$1$2$2\.sequence/;
                     81: 	while ($current_file ne '') {
                     82: 	    my $file=&Apache::lonnet::filelocation("",$current_file);
                     83: 	    my $filecontents=&Apache::lonnet::getfile($file);
                     84: 	    my @file_seq = &content_map($filecontents);
                     85: 	    if (defined @file_seq) {
                     86: #-- adding an additional array to the master one
                     87: 		if (defined @master_seq) {
                     88:                     my $old_value = $#master_seq;
                     89: 		    my $total_value = $#master_seq + $#file_seq +2;
                     90:                     for (my $j=0; $j<=$old_value-$keyword+1; $j++) {
                     91: 			$master_seq[$total_value-$j] = $master_seq[$old_value-$j];
                     92: 		    }
                     93:                     for (my $j=0; $j<=$#file_seq; $j++){
                     94: 			$master_seq[$keyword+$j] = $file_seq[$j];
                     95: 		    }
                     96: 		    @file_seq = ();
                     97: 		    $keyword = 0;
                     98: 		} else {
                     99: 		    @master_seq = @file_seq;
                    100:                     @file_seq = ();
                    101: 		}
                    102: 	    } 
                    103: #-- checking wether .sequence file is among the set of files
                    104: 	    $current_file = '';
                    105: 	    for (my $i=0; $i<=$#file_seq; $i++) {
                    106: 		$_ = $file_seq[$i];
                    107: 		if (m/(.*)\.sequence/) {
                    108: 		    $current_file = $_;
                    109: 		    $keyword = $i;
                    110: 		    last;
                    111: 		}
                    112: 	    }        
                    113: 	}
                    114: #-- produce an output string
                    115: 	for (my $i=0;$i<=$#master_seq;$i++) {
                    116: 	    $_ = $master_seq[$i];
                    117: 	    m/\"(.*)\"/;
                    118: 	    if (index($1,'-tc.xml',0)==-1) {
                    119: 		my $file=&Apache::lonnet::filelocation("",$1);
                    120: 		my $filecontents=&Apache::lonnet::getfile($file);
                    121: 		$output_seq .= $filecontents;
                    122: 	    }
                    123: 	}
                    124: #-- cleanup of output string (temporary cbi-specific)
                    125: 	$output_seq =~ s/<physnet>//g;
                    126: 	$output_seq =~ s/<\/physnet>//g;
                    127: 	$output_seq = '<physnet>'.$output_seq.' </physnet>';
                    128: #-- final accord
                    129: 	$result = &Apache::lonxml::xmlparse('tex',$output_seq,'',%mystyle);
                    130:     }
                    131: #-- writing .tex file in prtspool 
1.5       sakharuk  132: 	{
                    133: 	    my $temp_file;
1.6       sakharuk  134: 	    $filename = "/home/httpd/prtspool/$ENV{'environment.firstname'}$ENV{'environment.lastname'}temp$ENV{'user.login.time'}.tex";
1.5       sakharuk  135: 	    unless ($temp_file = Apache::File->new('>'.$filename)) {
                    136: 		$r->log_error("Couldn't open $filename for output $!");
                    137: 		return SERVER_ERROR; 
                    138: 	    } 
                    139: 		print $temp_file $result;
1.3       sakharuk  140: 	}
                    141: $r->print(<<FINALEND);
1.6       sakharuk  142: <meta http-equiv="Refresh" content="0; url=http://bistromath.lite.msu.edu/cgi-bin/printout.pl?$filename">
1.3       sakharuk  143: </body>
                    144: </html>
                    145: FINALEND
                    146: }
1.2       sakharuk  147: 
1.3       sakharuk  148: 
1.6       sakharuk  149: 
                    150: 
1.3       sakharuk  151: sub content_map {
1.7       sakharuk  152: #-- find a list of files to print
1.3       sakharuk  153:     my $map_string = shift;
1.5       sakharuk  154:     my @number_seq = ();
1.7       sakharuk  155:     my @file_seq = ();
1.5       sakharuk  156:     my $startlink = index($map_string,'<link',0);
1.7       sakharuk  157:     my $endlink = index($map_string,'</link>',$startlink);
                    158:     my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    159:     $_ = $chunk;
                    160:     m/from=\"(\d+)\"/;
                    161:     push @number_seq,$1;
1.5       sakharuk  162:     while ($startlink != -1) {
1.7       sakharuk  163: 	$endlink = index($map_string,'</link>',$startlink);
                    164: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5       sakharuk  165: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    166: 	$_ = $chunk;
                    167:         m/to=\"(\d+)\"/;
                    168: 	push @number_seq,$1;
                    169: 	$startlink = index($map_string,'<link from="'.$1.'"',$startlink);
                    170:     }
1.7       sakharuk  171:     my $stalink = index($map_string,' to="'.$number_seq[0].'"',$startlink);
                    172:     while ($stalink != -1) {
                    173: 	$startlink = rindex($map_string,'<link ',$stalink);
                    174: 	$endlink = index($map_string,'</link>',$startlink);
                    175: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    176: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    177: 	$_ = $chunk;
                    178:         m/from=\"(\d+)\"/;
                    179: 	unshift @number_seq,$1;
                    180: 	$stalink = index($map_string,' to="'.$number_seq[0].'"',0);
                    181:     }
                    182:     for (my $i=0;$i<=$#number_seq;$i++) {
                    183: 	$stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
                    184: 	$startlink = index($map_string,'src="',$stalink);
                    185: 	$startlink = index($map_string,'"',$startlink);
                    186: 	$endlink = index($map_string,'"',$startlink+1);
                    187: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+1);
                    188: 	push @file_seq,$chunk;
                    189:     }
                    190:     return @file_seq;
                    191: }
1.5       sakharuk  192: 
1.3       sakharuk  193: 
                    194: 
                    195: sub handler {
                    196: 
                    197:     my $r = shift;
                    198:     $r->content_type('text/html');
                    199:     $r->send_http_header;
                    200: 
                    201: #-- start form
                    202:     &headerform($r);
                    203: #-- menu for output
                    204:     unless ($ENV{'form.phase'}) {
                    205: 	&menu_for_output($r);
                    206:     }
                    207: #-- core part 
                    208:     if ($ENV{'form.phase'} eq 'two') {
                    209: 	&output_data($r);
1.6       sakharuk  210: 
1.3       sakharuk  211:     }
1.2       sakharuk  212:     return OK;
                    213: 
1.1       www       214: } 
                    215: 
                    216: 1;
                    217: __END__
1.6       sakharuk  218: 
                    219: 
                    220: #    my $ere;
                    221: #    foreach $ere (%ENV) {
                    222: #	$r->print(' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n");
                    223: #    }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>