File:  [LON-CAPA] / loncom / interface / lonprintout.pm
Revision 1.6: download - view: text, annotated - select for diffs
Tue Oct 2 14:09:25 2001 UTC (22 years, 7 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
new version (not last one yet)

    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: 
   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
   65: 
   66:     my $choice = $ENV{'form.choice'};
   67:     my $result = '';
   68:     my %mystyle;
   69:     my $filename;
   70: 
   71: 
   72:     if ($choice eq 'Standard LaTeX output for current document') {
   73: 
   74: 	my $file=&Apache::lonnet::filelocation("",'/res/'.$ENV{'request.ambiguous'});
   75: 	my $filecontents=&Apache::lonnet::getfile($file);
   76: 	$result = &Apache::lonxml::xmlparse('tex',$filecontents,'',%mystyle);
   77: 
   78: 	{
   79: 	    my $temp_file;
   80: 	    $filename = "/home/httpd/prtspool/$ENV{'environment.firstname'}$ENV{'environment.lastname'}temp$ENV{'user.login.time'}.tex";
   81: 	    unless ($temp_file = Apache::File->new('>'.$filename)) {
   82: 		$r->log_error("Couldn't open $filename for output $!");
   83: 		return SERVER_ERROR; 
   84: 	    } 
   85: 		print $temp_file $result;
   86: 	}
   87: 
   88:        
   89:     
   90: 
   91:     } elsif ($choice eq 'Standard LaTeX output for the whole sequence') {
   92: 	my $current_file = '/res/'.$ENV{'request.ambiguous'};
   93:         $current_file =~ s/(\/res\/physnet\/physnet)(\/m\d+)\/(.*)/$1$2$2\.sequence/;
   94: 	my $file=&Apache::lonnet::filelocation("",$current_file);
   95: 	my $filecontents=&Apache::lonnet::getfile($file);
   96: 	$result = &Apache::lonxml::xmlparse('tex',$filecontents,'',%mystyle);
   97: 
   98: 	my @number_seq = &content_map($result);
   99: 	$r->print(@number_seq);
  100: 
  101: 
  102: 
  103: 
  104:     }
  105:     
  106: 
  107: $r->print(<<FINALEND);
  108: <meta http-equiv="Refresh" content="0; url=http://bistromath.lite.msu.edu/cgi-bin/printout.pl?$filename">
  109: </body>
  110: </html>
  111: FINALEND
  112: }
  113: 
  114: 
  115: 
  116: 
  117: sub content_map {
  118: #-- find a list of files to publish
  119:     my $map_string = shift;
  120: 
  121:     my @number_seq = ();
  122:     my $startlink = index($map_string,'<link',0);
  123:     while ($startlink != -1) {
  124: 	my $endlink = index($map_string,'</link>',$startlink);
  125: 	my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
  126: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
  127: 	$_ = $chunk;
  128:         m/from=\"(\d+)\"/;
  129: 	push @number_seq,$1;
  130:         m/to=\"(\d+)\"/;
  131: 	push @number_seq,$1;
  132: 	$startlink = index($map_string,'<link from="'.$1.'"',$startlink);
  133:     }
  134: 
  135:     return @number_seq;
  136: 
  137: 
  138: #    my @one = ();
  139: #    my @two = ();
  140: #    my @three = ();
  141: #    my $start = index($map_string,'<link',0);
  142: #    while ($start != -1) {
  143: #	my $finish =  index($map_string,'</link>',$start);
  144: #	my $chunk = substr($map_string,$start,$finish-$start+7);
  145: #	substr($map_string,$start,$finish-$start+7) = '';
  146: #	$_ = $chunk;
  147: #        m/from=\"(\d+)\"/;
  148: #	push @one,$1;
  149: #        m/to=\"(\d+)\"/;
  150: #	push @two,$1;
  151: #	$start = index($map_string,'<link',$start);
  152: #    }
  153: 
  154: 
  155: #    return @three;
  156: #    return $map_string;
  157: }
  158: 
  159: 
  160: sub handler {
  161: 
  162:     my $r = shift;
  163:     $r->content_type('text/html');
  164:     $r->send_http_header;
  165: 
  166: #-- start form
  167:     &headerform($r);
  168: #-- menu for output
  169:     unless ($ENV{'form.phase'}) {
  170: 	&menu_for_output($r);
  171:     }
  172: #-- core part 
  173:     if ($ENV{'form.phase'} eq 'two') {
  174: 	&output_data($r);
  175: 
  176:     }
  177:     return OK;
  178: 
  179: } 
  180: 
  181: 1;
  182: __END__
  183: 
  184: 
  185: #    my $ere;
  186: #    foreach $ere (%ENV) {
  187: #	$r->print(' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n");
  188: #    }

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