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

1.1       www         1: # The LearningOnline Network
                      2: # Printout
                      3: #
1.12    ! sakharuk    4: # $Id: lonprintout.pm,v 1.11 2001/12/19 17:17:46 albertel Exp $
1.11      albertel    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);
1.12    ! sakharuk  104:         $_ = $file;
        !           105:         if (/\.problem/) {
        !           106: 	    my $default=&Apache::lonnet::getfile('/home/httpd/html/res/adm/includes/default_homework.lcpm');
        !           107: 	    if ($default == -1) {
        !           108: 		&Apache::lonxml::error("<b>Unable to find <i>default_homework.lcpm</i></b>");
        !           109: 		$default='';
        !           110: 	    }
        !           111: 	    $result = &Apache::lonxml::xmlparse('tex', $filecontents,$default.&Apache::lonhomework::setup_vars('tex'),%mystyle);
        !           112:          
        !           113: 
        !           114: 	} else { 
        !           115: 	    $result = &Apache::lonxml::xmlparse('tex',$filecontents,'',%mystyle);
        !           116: 	} 
        !           117: 
        !           118: 
        !           119: 
        !           120: 
        !           121: 	
        !           122:       
        !           123: #    my $ere;
        !           124: #    foreach $ere (%ENV) {
        !           125: #	$result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
        !           126: #    }
1.8       sakharuk  127:     } elsif ($choice eq 'Standard LaTeX output for the primary sequence') {
1.7       sakharuk  128: 	my @master_seq = ();
                    129: 	my $keyword = 0;
                    130: 	my $output_seq = '';
                    131: 	my $current_file = '/res/'.$ENV{'request.ambiguous'};
                    132:         $current_file =~ s/(\/res\/physnet\/physnet)(\/m\d+)\/(.*)/$1$2$2\.sequence/;
                    133: 	while ($current_file ne '') {
                    134: 	    my $file=&Apache::lonnet::filelocation("",$current_file);
                    135: 	    my $filecontents=&Apache::lonnet::getfile($file);
                    136: 	    my @file_seq = &content_map($filecontents);
                    137: 	    if (defined @file_seq) {
                    138: #-- adding an additional array to the master one
                    139: 		if (defined @master_seq) {
                    140:                     my $old_value = $#master_seq;
                    141: 		    my $total_value = $#master_seq + $#file_seq +2;
                    142:                     for (my $j=0; $j<=$old_value-$keyword+1; $j++) {
                    143: 			$master_seq[$total_value-$j] = $master_seq[$old_value-$j];
                    144: 		    }
                    145:                     for (my $j=0; $j<=$#file_seq; $j++){
                    146: 			$master_seq[$keyword+$j] = $file_seq[$j];
                    147: 		    }
                    148: 		    @file_seq = ();
                    149: 		    $keyword = 0;
                    150: 		} else {
                    151: 		    @master_seq = @file_seq;
                    152:                     @file_seq = ();
                    153: 		}
                    154: 	    } 
                    155: #-- checking wether .sequence file is among the set of files
                    156: 	    $current_file = '';
                    157: 	    for (my $i=0; $i<=$#file_seq; $i++) {
                    158: 		$_ = $file_seq[$i];
                    159: 		if (m/(.*)\.sequence/) {
                    160: 		    $current_file = $_;
                    161: 		    $keyword = $i;
                    162: 		    last;
                    163: 		}
                    164: 	    }        
                    165: 	}
                    166: #-- produce an output string
                    167: 	for (my $i=0;$i<=$#master_seq;$i++) {
                    168: 	    $_ = $master_seq[$i];
                    169: 	    m/\"(.*)\"/;
                    170: 	    if (index($1,'-tc.xml',0)==-1) {
                    171: 		my $file=&Apache::lonnet::filelocation("",$1);
                    172: 		my $filecontents=&Apache::lonnet::getfile($file);
                    173: 		$output_seq .= $filecontents;
                    174: 	    }
                    175: 	}
                    176: #-- cleanup of output string (temporary cbi-specific)
                    177: 	$output_seq =~ s/<physnet>//g;
                    178: 	$output_seq =~ s/<\/physnet>//g;
                    179: 	$output_seq = '<physnet>'.$output_seq.' </physnet>';
                    180: #-- final accord
                    181: 	$result = &Apache::lonxml::xmlparse('tex',$output_seq,'',%mystyle);
                    182:     }
                    183: #-- writing .tex file in prtspool 
1.5       sakharuk  184: 	{
                    185: 	    my $temp_file;
1.6       sakharuk  186: 	    $filename = "/home/httpd/prtspool/$ENV{'environment.firstname'}$ENV{'environment.lastname'}temp$ENV{'user.login.time'}.tex";
1.5       sakharuk  187: 	    unless ($temp_file = Apache::File->new('>'.$filename)) {
                    188: 		$r->log_error("Couldn't open $filename for output $!");
                    189: 		return SERVER_ERROR; 
                    190: 	    } 
                    191: 		print $temp_file $result;
1.3       sakharuk  192: 	}
                    193: $r->print(<<FINALEND);
1.9       albertel  194: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename">
1.3       sakharuk  195: </body>
                    196: </html>
                    197: FINALEND
                    198: }
1.2       sakharuk  199: 
1.3       sakharuk  200: 
1.6       sakharuk  201: 
                    202: 
1.3       sakharuk  203: sub content_map {
1.7       sakharuk  204: #-- find a list of files to print
1.3       sakharuk  205:     my $map_string = shift;
1.5       sakharuk  206:     my @number_seq = ();
1.7       sakharuk  207:     my @file_seq = ();
1.5       sakharuk  208:     my $startlink = index($map_string,'<link',0);
1.7       sakharuk  209:     my $endlink = index($map_string,'</link>',$startlink);
                    210:     my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    211:     $_ = $chunk;
                    212:     m/from=\"(\d+)\"/;
                    213:     push @number_seq,$1;
1.5       sakharuk  214:     while ($startlink != -1) {
1.7       sakharuk  215: 	$endlink = index($map_string,'</link>',$startlink);
                    216: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5       sakharuk  217: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    218: 	$_ = $chunk;
                    219:         m/to=\"(\d+)\"/;
                    220: 	push @number_seq,$1;
                    221: 	$startlink = index($map_string,'<link from="'.$1.'"',$startlink);
                    222:     }
1.7       sakharuk  223:     my $stalink = index($map_string,' to="'.$number_seq[0].'"',$startlink);
                    224:     while ($stalink != -1) {
                    225: 	$startlink = rindex($map_string,'<link ',$stalink);
                    226: 	$endlink = index($map_string,'</link>',$startlink);
                    227: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    228: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    229: 	$_ = $chunk;
                    230:         m/from=\"(\d+)\"/;
                    231: 	unshift @number_seq,$1;
                    232: 	$stalink = index($map_string,' to="'.$number_seq[0].'"',0);
                    233:     }
                    234:     for (my $i=0;$i<=$#number_seq;$i++) {
                    235: 	$stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
                    236: 	$startlink = index($map_string,'src="',$stalink);
                    237: 	$startlink = index($map_string,'"',$startlink);
                    238: 	$endlink = index($map_string,'"',$startlink+1);
                    239: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+1);
                    240: 	push @file_seq,$chunk;
                    241:     }
                    242:     return @file_seq;
                    243: }
1.5       sakharuk  244: 
1.3       sakharuk  245: 
                    246: 
                    247: sub handler {
                    248: 
                    249:     my $r = shift;
                    250:     $r->content_type('text/html');
                    251:     $r->send_http_header;
                    252: 
                    253: #-- start form
                    254:     &headerform($r);
                    255: #-- menu for output
                    256:     unless ($ENV{'form.phase'}) {
                    257: 	&menu_for_output($r);
                    258:     }
                    259: #-- core part 
                    260:     if ($ENV{'form.phase'} eq 'two') {
                    261: 	&output_data($r);
1.6       sakharuk  262: 
1.3       sakharuk  263:     }
1.2       sakharuk  264:     return OK;
                    265: 
1.1       www       266: } 
                    267: 
                    268: 1;
                    269: __END__
1.6       sakharuk  270: 
                    271: 
                    272: #    my $ere;
                    273: #    foreach $ere (%ENV) {
                    274: #	$r->print(' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n");
                    275: #    }

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