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