File:  [LON-CAPA] / loncom / interface / lonprintout.pm
Revision 1.7: download - view: text, annotated - select for diffs
Mon Oct 15 14:50:10 2001 UTC (22 years, 7 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
now prints sequences

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

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