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

1.1       www         1: # The LearningOnline Network
                      2: # Printout
                      3: #
1.11    ! albertel    4: # $Id: gplheader.pl,v 1.1 2001/11/29 18:19:27 www Exp $
        !             5: #
        !             6: # Copyright Michigan State University Board of Trustees
        !             7: #
        !             8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !             9: #
        !            10: # LON-CAPA is free software; you can redistribute it and/or modify
        !            11: # it under the terms of the GNU General Public License as published by
        !            12: # the Free Software Foundation; either version 2 of the License, or
        !            13: # (at your option) any later version.
        !            14: #
        !            15: # LON-CAPA is distributed in the hope that it will be useful,
        !            16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            18: # GNU General Public License for more details.
        !            19: #
        !            20: # You should have received a copy of the GNU General Public License
        !            21: # along with LON-CAPA; if not, write to the Free Software
        !            22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            23: #
        !            24: # /home/httpd/html/adm/gpl.txt
        !            25: #
        !            26: # http://www.lon-capa.org/
        !            27: #
1.1       www        28: # (Internal Server Error Handler
                     29: #
                     30: # (Login Screen
                     31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
                     32: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
                     33: #
                     34: # 3/1/1 Gerd Kortemeyer)
                     35: #
                     36: # 3/1 Gerd Kortemeyer
                     37: #
1.3       sakharuk   38: # 9/17 Alex Sakharuk
                     39: #
1.1       www        40: package Apache::lonprintout;
                     41: 
                     42: use strict;
1.10      albertel   43: use Apache::Constants qw(:common :http);
1.2       sakharuk   44: use Apache::lonxml;
                     45: use Apache::lonnet;
1.5       sakharuk   46: use Apache::File();
1.1       www        47: 
1.3       sakharuk   48: 
                     49: 
                     50: sub headerform {
1.1       www        51:     my $r = shift;
1.3       sakharuk   52:     $r->print(<<ENDHEADER);
                     53: <html>
                     54: <head>
                     55: <title>LON-CAPA output for printing</title>
                     56: </head>
                     57: <body bgcolor="FFFFFF">
                     58: <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">
                     59: <h1>Printout:</h1><br></br>
                     60: ENDHEADER
                     61: }
                     62: 
1.1       www        63: 
1.3       sakharuk   64: sub menu_for_output {
                     65:     my $r = shift;
                     66:     $r->print(<<ENDMENUOUT);
                     67: <input type="hidden" name="phase" value="two">
1.10      albertel   68: <input type="hidden" name="url" value="$ENV{'form.postdata'}">
                     69: <input type="radio" name="choice" value="Standard LaTeX output for current document">  Standard LaTeX output for current document<br />
                     70: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence">  Standard LaTeX output for the primary sequence<br />
                     71: <input type="radio" name="choice" value="Standard LaTeX output for the top level sequence">  Standard LaTeX output for the top level sequence<br />
1.3       sakharuk   72: <input type="submit" value="Please make a choice">
                     73: </form>
                     74: </body>
                     75: </html>
                     76: ENDMENUOUT
                     77: }
1.2       sakharuk   78: 
                     79: 
1.3       sakharuk   80: sub output_data {
                     81:     my $r = shift;
                     82:     $r->print(<<ENDPART);
                     83: <html>
                     84: <head>
                     85: <title>LON-CAPA output for printing</title>
                     86: </head>
                     87: <body bgcolor="FFFFFF">
                     88: <hr>
                     89: ENDPART
1.2       sakharuk   90: 
1.3       sakharuk   91:     my $choice = $ENV{'form.choice'};
1.2       sakharuk   92:     my $result = '';
                     93:     my %mystyle;
1.6       sakharuk   94:     my $filename;
1.5       sakharuk   95: 
1.3       sakharuk   96:     if ($choice eq 'Standard LaTeX output for current document') {
1.10      albertel   97:         my $access=&Apache::lonnet::allowed('bre',$ENV{'form.url'});
                     98: 	if (($access ne '2') && ($access ne 'F')) {
                     99: 	  $ENV{'user.error.msg'}="$ENV{'form.url'}:bre:1:1:Access Denied";
                    100: 	  return HTTP_NOT_ACCEPTABLE;
                    101: 	}
                    102: 	my $file=&Apache::lonnet::filelocation("",$ENV{'form.url'});
1.3       sakharuk  103: 	my $filecontents=&Apache::lonnet::getfile($file);
                    104: 	$result = &Apache::lonxml::xmlparse('tex',$filecontents,'',%mystyle);
1.8       sakharuk  105:     } elsif ($choice eq 'Standard LaTeX output for the primary sequence') {
1.7       sakharuk  106: 	my @master_seq = ();
                    107: 	my $keyword = 0;
                    108: 	my $output_seq = '';
                    109: 	my $current_file = '/res/'.$ENV{'request.ambiguous'};
                    110:         $current_file =~ s/(\/res\/physnet\/physnet)(\/m\d+)\/(.*)/$1$2$2\.sequence/;
                    111: 	while ($current_file ne '') {
                    112: 	    my $file=&Apache::lonnet::filelocation("",$current_file);
                    113: 	    my $filecontents=&Apache::lonnet::getfile($file);
                    114: 	    my @file_seq = &content_map($filecontents);
                    115: 	    if (defined @file_seq) {
                    116: #-- adding an additional array to the master one
                    117: 		if (defined @master_seq) {
                    118:                     my $old_value = $#master_seq;
                    119: 		    my $total_value = $#master_seq + $#file_seq +2;
                    120:                     for (my $j=0; $j<=$old_value-$keyword+1; $j++) {
                    121: 			$master_seq[$total_value-$j] = $master_seq[$old_value-$j];
                    122: 		    }
                    123:                     for (my $j=0; $j<=$#file_seq; $j++){
                    124: 			$master_seq[$keyword+$j] = $file_seq[$j];
                    125: 		    }
                    126: 		    @file_seq = ();
                    127: 		    $keyword = 0;
                    128: 		} else {
                    129: 		    @master_seq = @file_seq;
                    130:                     @file_seq = ();
                    131: 		}
                    132: 	    } 
                    133: #-- checking wether .sequence file is among the set of files
                    134: 	    $current_file = '';
                    135: 	    for (my $i=0; $i<=$#file_seq; $i++) {
                    136: 		$_ = $file_seq[$i];
                    137: 		if (m/(.*)\.sequence/) {
                    138: 		    $current_file = $_;
                    139: 		    $keyword = $i;
                    140: 		    last;
                    141: 		}
                    142: 	    }        
                    143: 	}
                    144: #-- produce an output string
                    145: 	for (my $i=0;$i<=$#master_seq;$i++) {
                    146: 	    $_ = $master_seq[$i];
                    147: 	    m/\"(.*)\"/;
                    148: 	    if (index($1,'-tc.xml',0)==-1) {
                    149: 		my $file=&Apache::lonnet::filelocation("",$1);
                    150: 		my $filecontents=&Apache::lonnet::getfile($file);
                    151: 		$output_seq .= $filecontents;
                    152: 	    }
                    153: 	}
                    154: #-- cleanup of output string (temporary cbi-specific)
                    155: 	$output_seq =~ s/<physnet>//g;
                    156: 	$output_seq =~ s/<\/physnet>//g;
                    157: 	$output_seq = '<physnet>'.$output_seq.' </physnet>';
                    158: #-- final accord
                    159: 	$result = &Apache::lonxml::xmlparse('tex',$output_seq,'',%mystyle);
                    160:     }
                    161: #-- writing .tex file in prtspool 
1.5       sakharuk  162: 	{
                    163: 	    my $temp_file;
1.6       sakharuk  164: 	    $filename = "/home/httpd/prtspool/$ENV{'environment.firstname'}$ENV{'environment.lastname'}temp$ENV{'user.login.time'}.tex";
1.5       sakharuk  165: 	    unless ($temp_file = Apache::File->new('>'.$filename)) {
                    166: 		$r->log_error("Couldn't open $filename for output $!");
                    167: 		return SERVER_ERROR; 
                    168: 	    } 
                    169: 		print $temp_file $result;
1.3       sakharuk  170: 	}
                    171: $r->print(<<FINALEND);
1.9       albertel  172: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename">
1.3       sakharuk  173: </body>
                    174: </html>
                    175: FINALEND
                    176: }
1.2       sakharuk  177: 
1.3       sakharuk  178: 
1.6       sakharuk  179: 
                    180: 
1.3       sakharuk  181: sub content_map {
1.7       sakharuk  182: #-- find a list of files to print
1.3       sakharuk  183:     my $map_string = shift;
1.5       sakharuk  184:     my @number_seq = ();
1.7       sakharuk  185:     my @file_seq = ();
1.5       sakharuk  186:     my $startlink = index($map_string,'<link',0);
1.7       sakharuk  187:     my $endlink = index($map_string,'</link>',$startlink);
                    188:     my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    189:     $_ = $chunk;
                    190:     m/from=\"(\d+)\"/;
                    191:     push @number_seq,$1;
1.5       sakharuk  192:     while ($startlink != -1) {
1.7       sakharuk  193: 	$endlink = index($map_string,'</link>',$startlink);
                    194: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5       sakharuk  195: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    196: 	$_ = $chunk;
                    197:         m/to=\"(\d+)\"/;
                    198: 	push @number_seq,$1;
                    199: 	$startlink = index($map_string,'<link from="'.$1.'"',$startlink);
                    200:     }
1.7       sakharuk  201:     my $stalink = index($map_string,' to="'.$number_seq[0].'"',$startlink);
                    202:     while ($stalink != -1) {
                    203: 	$startlink = rindex($map_string,'<link ',$stalink);
                    204: 	$endlink = index($map_string,'</link>',$startlink);
                    205: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    206: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    207: 	$_ = $chunk;
                    208:         m/from=\"(\d+)\"/;
                    209: 	unshift @number_seq,$1;
                    210: 	$stalink = index($map_string,' to="'.$number_seq[0].'"',0);
                    211:     }
                    212:     for (my $i=0;$i<=$#number_seq;$i++) {
                    213: 	$stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
                    214: 	$startlink = index($map_string,'src="',$stalink);
                    215: 	$startlink = index($map_string,'"',$startlink);
                    216: 	$endlink = index($map_string,'"',$startlink+1);
                    217: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+1);
                    218: 	push @file_seq,$chunk;
                    219:     }
                    220:     return @file_seq;
                    221: }
1.5       sakharuk  222: 
1.3       sakharuk  223: 
                    224: 
                    225: sub handler {
                    226: 
                    227:     my $r = shift;
                    228:     $r->content_type('text/html');
                    229:     $r->send_http_header;
                    230: 
                    231: #-- start form
                    232:     &headerform($r);
                    233: #-- menu for output
                    234:     unless ($ENV{'form.phase'}) {
                    235: 	&menu_for_output($r);
                    236:     }
                    237: #-- core part 
                    238:     if ($ENV{'form.phase'} eq 'two') {
                    239: 	&output_data($r);
1.6       sakharuk  240: 
1.3       sakharuk  241:     }
1.2       sakharuk  242:     return OK;
                    243: 
1.1       www       244: } 
                    245: 
                    246: 1;
                    247: __END__
1.6       sakharuk  248: 
                    249: 
                    250: #    my $ere;
                    251: #    foreach $ere (%ENV) {
                    252: #	$r->print(' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n");
                    253: #    }

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