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