Annotation of loncom/interface/lonprintout.pm, revision 1.13
1.1 www 1: # The LearningOnline Network
2: # Printout
3: #
1.13 ! sakharuk 4: # $Id: lonprintout.pm,v 1.12 2002/01/11 17:06:56 sakharuk 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.13 ! sakharuk 46: use Apache::inputtags;
! 47: use Apache::edit;
1.5 sakharuk 48: use Apache::File();
1.1 www 49:
1.3 sakharuk 50:
51:
52: sub headerform {
1.1 www 53: my $r = shift;
1.3 sakharuk 54: $r->print(<<ENDHEADER);
55: <html>
56: <head>
57: <title>LON-CAPA output for printing</title>
58: </head>
59: <body bgcolor="FFFFFF">
60: <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">
61: <h1>Printout:</h1><br></br>
62: ENDHEADER
63: }
64:
1.1 www 65:
1.3 sakharuk 66: sub menu_for_output {
67: my $r = shift;
68: $r->print(<<ENDMENUOUT);
69: <input type="hidden" name="phase" value="two">
1.10 albertel 70: <input type="hidden" name="url" value="$ENV{'form.postdata'}">
71: <input type="radio" name="choice" value="Standard LaTeX output for current document"> Standard LaTeX output for current document<br />
72: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence"> Standard LaTeX output for the primary sequence<br />
73: <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 74: <input type="submit" value="Please make a choice">
75: </form>
76: </body>
77: </html>
78: ENDMENUOUT
79: }
1.2 sakharuk 80:
81:
1.3 sakharuk 82: sub output_data {
83: my $r = shift;
84: $r->print(<<ENDPART);
85: <html>
86: <head>
87: <title>LON-CAPA output for printing</title>
88: </head>
89: <body bgcolor="FFFFFF">
90: <hr>
91: ENDPART
1.2 sakharuk 92:
1.3 sakharuk 93: my $choice = $ENV{'form.choice'};
1.2 sakharuk 94: my $result = '';
95: my %mystyle;
1.6 sakharuk 96: my $filename;
1.5 sakharuk 97:
1.3 sakharuk 98: if ($choice eq 'Standard LaTeX output for current document') {
1.13 ! sakharuk 99: $_ = $ENV{'form.url'};
! 100: if (/\.problem/) {
! 101: my %moreenv;
! 102: $moreenv{'form.grade_target'}='tex';
! 103: &Apache::lonnet::appenv(%moreenv);
! 104: my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
! 105: &Apache::lonnet::delenv('form.grade_target');
! 106: $texversion =~ s!\.gif!\.eps!;
! 107: $result .= $texversion;
1.12 sakharuk 108: } else {
1.13 ! sakharuk 109: my $file=&Apache::lonnet::filelocation("",$ENV{'form.url'});
! 110: my $filecontents=&Apache::lonnet::getfile($file);
1.12 sakharuk 111: $result = &Apache::lonxml::xmlparse('tex',$filecontents,'',%mystyle);
112: }
1.8 sakharuk 113: } elsif ($choice eq 'Standard LaTeX output for the primary sequence') {
1.7 sakharuk 114: my @master_seq = ();
115: my $keyword = 0;
116: my $output_seq = '';
117: my $current_file = '/res/'.$ENV{'request.ambiguous'};
118: $current_file =~ s/(\/res\/physnet\/physnet)(\/m\d+)\/(.*)/$1$2$2\.sequence/;
119: while ($current_file ne '') {
120: my $file=&Apache::lonnet::filelocation("",$current_file);
121: my $filecontents=&Apache::lonnet::getfile($file);
122: my @file_seq = &content_map($filecontents);
123: if (defined @file_seq) {
124: #-- adding an additional array to the master one
125: if (defined @master_seq) {
126: my $old_value = $#master_seq;
127: my $total_value = $#master_seq + $#file_seq +2;
128: for (my $j=0; $j<=$old_value-$keyword+1; $j++) {
129: $master_seq[$total_value-$j] = $master_seq[$old_value-$j];
130: }
131: for (my $j=0; $j<=$#file_seq; $j++){
132: $master_seq[$keyword+$j] = $file_seq[$j];
133: }
134: @file_seq = ();
135: $keyword = 0;
136: } else {
137: @master_seq = @file_seq;
138: @file_seq = ();
139: }
140: }
141: #-- checking wether .sequence file is among the set of files
142: $current_file = '';
143: for (my $i=0; $i<=$#file_seq; $i++) {
144: $_ = $file_seq[$i];
145: if (m/(.*)\.sequence/) {
146: $current_file = $_;
147: $keyword = $i;
148: last;
149: }
150: }
151: }
152: #-- produce an output string
153: for (my $i=0;$i<=$#master_seq;$i++) {
154: $_ = $master_seq[$i];
155: m/\"(.*)\"/;
156: if (index($1,'-tc.xml',0)==-1) {
157: my $file=&Apache::lonnet::filelocation("",$1);
158: my $filecontents=&Apache::lonnet::getfile($file);
159: $output_seq .= $filecontents;
160: }
161: }
162: #-- cleanup of output string (temporary cbi-specific)
163: $output_seq =~ s/<physnet>//g;
164: $output_seq =~ s/<\/physnet>//g;
165: $output_seq = '<physnet>'.$output_seq.' </physnet>';
166: #-- final accord
167: $result = &Apache::lonxml::xmlparse('tex',$output_seq,'',%mystyle);
1.13 ! sakharuk 168: } elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
! 169:
! 170: #-- where is the main sequence of the course?
! 171:
! 172: my @master_seq = ();
! 173: my $keyword = 0;
! 174: my $output_seq = '';
! 175:
! 176: my $main_seq = '/res/'.$ENV{'request.course.uri'};
! 177: my $file=&Apache::lonnet::filelocation("",$main_seq);
! 178: my $filecontents=&Apache::lonnet::getfile($file);
! 179: my @file_seq = &content_map($filecontents);
! 180:
! 181: #-- temporary solution (without sequence inside sequence) - have to be generalized
! 182:
! 183:
! 184:
! 185:
! 186: # if (defined @master_seq) {
! 187: # my $old_value = $#master_seq;
! 188: # my $total_value = $#master_seq + $#file_seq +2;
! 189: # for (my $j=0; $j<=$old_value-$keyword+1; $j++) {
! 190: # $master_seq[$total_value-$j] = $master_seq[$old_value-$j];
! 191: # }
! 192: # for (my $j=0; $j<=$#file_seq; $j++){
! 193: # $master_seq[$keyword+$j] = $file_seq[$j];
! 194: # }
! 195: # @file_seq = ();
! 196: # $keyword = 0;
! 197: # } else {
! 198: @master_seq = @file_seq;
! 199: # @file_seq = ();
! 200: # }
! 201:
! 202: #-- checking wether .sequence file is among the set of files
! 203: # my $current_file = '';
! 204: # for (my $i=0; $i<=$#file_seq; $i++) {
! 205: # $_ = $file_seq[$i];
! 206: # if (m/(.*)\.sequence/) {
! 207: # $current_file = $_;
! 208: # $keyword = $i;
! 209: # last;
! 210: # }
! 211: # }
! 212:
! 213: #-- produce an output string
! 214: for (my $i=0;$i<=$#master_seq;$i++) {
! 215: $_ = $master_seq[$i];
! 216: m/\"(.*)\"/;
! 217: $_ = $1;
! 218: my $urlp = $1;
! 219: if (/\.problem/) {
! 220: my %moreenv;
! 221: $moreenv{'form.grade_target'}='tex';
! 222: &Apache::lonnet::appenv(%moreenv);
! 223: my $texversion=&Apache::lonnet::ssi($urlp);
! 224: &Apache::lonnet::delenv('form.grade_target');
! 225: $texversion =~ s!\.gif!\.eps!;
! 226: $result .= $texversion;
! 227: }
! 228: }
! 229: #-- additional cleanup for output
! 230: my $first_app = index($result,'\documentclass',0);
! 231: $first_app = index($result,'\documentclass',$first_app+5);
! 232: while ($first_app != -1) {
! 233: my $second_app = index($result,'begin{document}',$first_app);
! 234: $first_app = rindex($result,'\end{document}',$first_app);
! 235: substr($result,$first_app,$second_app-$first_app+15) = '\vskip 7 mm';
! 236: $first_app = index($result,'\documentclass',$first_app+5);
! 237: }
1.7 sakharuk 238: }
239: #-- writing .tex file in prtspool
1.5 sakharuk 240: {
241: my $temp_file;
1.6 sakharuk 242: $filename = "/home/httpd/prtspool/$ENV{'environment.firstname'}$ENV{'environment.lastname'}temp$ENV{'user.login.time'}.tex";
1.5 sakharuk 243: unless ($temp_file = Apache::File->new('>'.$filename)) {
244: $r->log_error("Couldn't open $filename for output $!");
245: return SERVER_ERROR;
246: }
247: print $temp_file $result;
1.3 sakharuk 248: }
249: $r->print(<<FINALEND);
1.9 albertel 250: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename">
1.3 sakharuk 251: </body>
252: </html>
253: FINALEND
254: }
1.2 sakharuk 255:
1.3 sakharuk 256:
1.6 sakharuk 257:
258:
1.3 sakharuk 259: sub content_map {
1.7 sakharuk 260: #-- find a list of files to print
1.3 sakharuk 261: my $map_string = shift;
1.5 sakharuk 262: my @number_seq = ();
1.7 sakharuk 263: my @file_seq = ();
1.5 sakharuk 264: my $startlink = index($map_string,'<link',0);
1.7 sakharuk 265: my $endlink = index($map_string,'</link>',$startlink);
266: my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
267: $_ = $chunk;
268: m/from=\"(\d+)\"/;
269: push @number_seq,$1;
1.5 sakharuk 270: while ($startlink != -1) {
1.7 sakharuk 271: $endlink = index($map_string,'</link>',$startlink);
272: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5 sakharuk 273: substr($map_string,$startlink,$endlink-$startlink+7) = '';
274: $_ = $chunk;
275: m/to=\"(\d+)\"/;
276: push @number_seq,$1;
1.13 ! sakharuk 277: $startlink = index($map_string,'from="'.$1.'"',$startlink);
1.5 sakharuk 278: }
1.7 sakharuk 279: my $stalink = index($map_string,' to="'.$number_seq[0].'"',$startlink);
280: while ($stalink != -1) {
281: $startlink = rindex($map_string,'<link ',$stalink);
282: $endlink = index($map_string,'</link>',$startlink);
283: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
284: substr($map_string,$startlink,$endlink-$startlink+7) = '';
285: $_ = $chunk;
286: m/from=\"(\d+)\"/;
287: unshift @number_seq,$1;
288: $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
289: }
290: for (my $i=0;$i<=$#number_seq;$i++) {
291: $stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
1.13 ! sakharuk 292: {
! 293: my $ahed1 = index($map_string,'src="',$stalink);
! 294: my $ahed2 = index($map_string,'</resource>',$stalink);
! 295: if ($ahed1 != -1) {
! 296: if ($ahed1 < $ahed2) {
! 297: $startlink = $ahed1;
! 298: } else {
! 299: $startlink = rindex($map_string,'src="',$stalink);
! 300: }
! 301: } else {
! 302: $startlink = rindex($map_string,'src="',$stalink);
! 303: }
! 304:
! 305: }
1.7 sakharuk 306: $startlink = index($map_string,'"',$startlink);
307: $endlink = index($map_string,'"',$startlink+1);
308: $chunk = substr($map_string,$startlink,$endlink-$startlink+1);
309: push @file_seq,$chunk;
310: }
311: return @file_seq;
312: }
1.5 sakharuk 313:
1.3 sakharuk 314:
315:
316: sub handler {
317:
318: my $r = shift;
319: $r->content_type('text/html');
320: $r->send_http_header;
321:
322: #-- start form
323: &headerform($r);
324: #-- menu for output
325: unless ($ENV{'form.phase'}) {
326: &menu_for_output($r);
327: }
328: #-- core part
329: if ($ENV{'form.phase'} eq 'two') {
330: &output_data($r);
1.6 sakharuk 331:
1.3 sakharuk 332: }
1.2 sakharuk 333: return OK;
334:
1.1 www 335: }
336:
337: 1;
338: __END__
1.6 sakharuk 339:
340:
1.13 ! sakharuk 341:
! 342:
! 343: #### Test block
1.6 sakharuk 344: # my $ere;
345: # foreach $ere (%ENV) {
1.13 ! sakharuk 346: # $result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
1.6 sakharuk 347: # }
1.13 ! sakharuk 348: ####
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>