Annotation of loncom/interface/lonprintout.pm, revision 1.18
1.1 www 1: # The LearningOnline Network
2: # Printout
3: #
1.18 ! sakharuk 4: # $Id: lonprintout.pm,v 1.17 2002/03/20 22:14:30 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">
1.16 sakharuk 61: <h1>What do you want to print? Make a choice.</h1><br />
1.3 sakharuk 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'}">
1.16 sakharuk 71: <input type="radio" name="choice" value="Standard LaTeX output for current document"> Current document
72: (you will print what you see on the screen)<br />
1.10 albertel 73: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence"> Standard LaTeX output for the primary sequence<br />
1.16 sakharuk 74: <input type="radio" name="choice" value="Standard LaTeX output for the top level sequence"> All documents from the top level sequence<br />
75: <br /><hr /><br />
76: <h1>And what page format do you prefer?</h1>
77: <input type="radio" name="layout" value="CBI" checked> CBI <br />
78: <input type="radio" name="layout" value="CAPA"> CAPA <br />
79: <input type="submit" value="Submit your choice">
1.3 sakharuk 80: </form>
81: </body>
82: </html>
83: ENDMENUOUT
84: }
1.2 sakharuk 85:
86:
1.16 sakharuk 87:
88:
1.3 sakharuk 89: sub output_data {
90: my $r = shift;
91: $r->print(<<ENDPART);
92: <html>
93: <head>
94: <title>LON-CAPA output for printing</title>
95: </head>
96: <body bgcolor="FFFFFF">
97: <hr>
98: ENDPART
1.2 sakharuk 99:
1.3 sakharuk 100: my $choice = $ENV{'form.choice'};
1.16 sakharuk 101: my $layout = $ENV{'form.layout'};
102: my $laystyle = 'book';
1.2 sakharuk 103: my $result = '';
104: my %mystyle;
1.6 sakharuk 105: my $filename;
1.5 sakharuk 106:
1.3 sakharuk 107: if ($choice eq 'Standard LaTeX output for current document') {
1.14 albertel 108: my %moreenv;
109: my $currequest=$ENV{'request.filename'};
110: $moreenv{'form.grade_target'}='tex';
111: $moreenv{'request.filename'}=$ENV{'form.url'};
112: &Apache::lonnet::appenv(%moreenv);
113: my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
114: &Apache::lonnet::delenv('form.grade_target');
115: %moreenv = ();
116: $moreenv{'request.filename'}=$currequest;
117: &Apache::lonnet::appenv(%moreenv);
118: $result .= $texversion;
1.16 sakharuk 119:
1.8 sakharuk 120: } elsif ($choice eq 'Standard LaTeX output for the primary sequence') {
1.18 ! sakharuk 121: #-- where is the primary sequence containing file?
! 122: my %moreenv;
! 123: my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
! 124: $_ = $symbolic;
! 125: m/([^_]+)_/;
! 126: my $primary_sequence = '/res/'.$1;
! 127: #-- open and analyses the primary sequence
! 128: my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
! 129: my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
! 130: my @master_seq = &content_map($sequencefilecontents);
! 131: #-- produce an output string
! 132: for (my $i=0;$i<=$#master_seq;$i++) {
! 133: $_ = $master_seq[$i];
! 134: m/\"(.*)\"/;
! 135: $_ = $1;
! 136: my $urlp = $1;
! 137: if (/\.problem/) {
! 138: my %moreenv;
! 139: $moreenv{'form.grade_target'}='tex';
! 140: &Apache::lonnet::appenv(%moreenv);
! 141: my $texversion=&Apache::lonnet::ssi($urlp);
! 142: &Apache::lonnet::delenv('form.grade_target');
! 143: $texversion =~ s!\.gif!\.eps!;
! 144: $result .= $texversion;
1.16 sakharuk 145: }
146: }
1.18 ! sakharuk 147: #-- additional cleanup for output
! 148: my $first_app = index($result,'\documentclass',0);
! 149: $first_app = index($result,'\documentclass',$first_app+5);
! 150: while ($first_app != -1) {
! 151: my $second_app = index($result,'begin{document}',$first_app);
! 152: $first_app = rindex($result,'\end{document}',$first_app);
! 153: substr($result,$first_app,$second_app-$first_app+15) = '\vskip 7 mm';
! 154: $first_app = index($result,'\documentclass',$first_app+5);
1.7 sakharuk 155: }
1.13 sakharuk 156: } elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
157: my @master_seq = ();
158: my $keyword = 0;
159: my $output_seq = '';
1.16 sakharuk 160: #-- where is the main sequence of the course?
1.13 sakharuk 161: my $main_seq = '/res/'.$ENV{'request.course.uri'};
162: my $file=&Apache::lonnet::filelocation("",$main_seq);
163: my $filecontents=&Apache::lonnet::getfile($file);
164: my @file_seq = &content_map($filecontents);
1.16 sakharuk 165: #-- temporary solution (without sequence inside sequence) - have to be generalized
1.13 sakharuk 166:
167:
168:
169:
170: # if (defined @master_seq) {
171: # my $old_value = $#master_seq;
172: # my $total_value = $#master_seq + $#file_seq +2;
173: # for (my $j=0; $j<=$old_value-$keyword+1; $j++) {
174: # $master_seq[$total_value-$j] = $master_seq[$old_value-$j];
175: # }
176: # for (my $j=0; $j<=$#file_seq; $j++){
177: # $master_seq[$keyword+$j] = $file_seq[$j];
178: # }
179: # @file_seq = ();
180: # $keyword = 0;
181: # } else {
182: @master_seq = @file_seq;
183: # @file_seq = ();
184: # }
1.16 sakharuk 185:
1.13 sakharuk 186: #-- checking wether .sequence file is among the set of files
187: # my $current_file = '';
188: # for (my $i=0; $i<=$#file_seq; $i++) {
189: # $_ = $file_seq[$i];
190: # if (m/(.*)\.sequence/) {
191: # $current_file = $_;
192: # $keyword = $i;
193: # last;
194: # }
195: # }
196:
197: #-- produce an output string
198: for (my $i=0;$i<=$#master_seq;$i++) {
199: $_ = $master_seq[$i];
200: m/\"(.*)\"/;
201: $_ = $1;
202: my $urlp = $1;
203: if (/\.problem/) {
204: my %moreenv;
205: $moreenv{'form.grade_target'}='tex';
206: &Apache::lonnet::appenv(%moreenv);
207: my $texversion=&Apache::lonnet::ssi($urlp);
208: &Apache::lonnet::delenv('form.grade_target');
209: $texversion =~ s!\.gif!\.eps!;
210: $result .= $texversion;
211: }
212: }
213: #-- additional cleanup for output
214: my $first_app = index($result,'\documentclass',0);
215: $first_app = index($result,'\documentclass',$first_app+5);
216: while ($first_app != -1) {
217: my $second_app = index($result,'begin{document}',$first_app);
218: $first_app = rindex($result,'\end{document}',$first_app);
219: substr($result,$first_app,$second_app-$first_app+15) = '\vskip 7 mm';
220: $first_app = index($result,'\documentclass',$first_app+5);
221: }
1.7 sakharuk 222: }
1.16 sakharuk 223: #-- corrections for the different page formats
224: if ($layout eq 'CBI') {
225: $result =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{-40pt}\\setlength{\\evensidemargin}{-60pt}\\setlength{\\topmargin}{200pt}\\setlength{\\textwidth}{4\.4in}\\setlength{\\textheight}{6\.8in}\\setlength{\\parindent}{20pt}\\setlength{\\marginparwidth}{90pt}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt} \\begin{document}/;
226: $laystyle = 'album';
227: } elsif ($layout eq 'CAPA') {
228: my $courseidinfo = $ENV{'request.role'};
229: $_ = $courseidinfo;
230: m/.*\/(.*)/;
231: $courseidinfo = $ENV{'course.physnet_'.$1.'.description'};
232: $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass\[twocolumn\]{article}/;
1.17 sakharuk 233: $result =~ s/\\begin{document}/\\textheight 25\.9cm\\oddsidemargin = -0\.57in\\evensidemargin = -0\.57in\\textwidth= 7\.7in\\begin{document}\\voffset=-1\.8cm\\setcounter{page}{1}\\noindent\\fbox{\\textbf{$ENV{'environment.firstname'} $ENV{'environment.lastname'}}}\\hskip 1\.4in $courseidinfo \\vskip 5 mm /;
1.16 sakharuk 234: $result =~ s/\\includegraphics/\\includegraphics\[width=9\.0 cm\]/g;
235: }
1.17 sakharuk 236: #-- LaTeX corrections
237: $result =~ s/^\s+$//gm; #remove empty lines
238: $result =~ s/%/\\%/g; #corrects %
1.7 sakharuk 239: #-- writing .tex file in prtspool
1.16 sakharuk 240: my $temp_file;
241: $filename = "/home/httpd/prtspool/$ENV{'environment.firstname'}$ENV{'environment.lastname'}temp$ENV{'user.login.time'}.tex";
242: unless ($temp_file = Apache::File->new('>'.$filename)) {
243: $r->log_error("Couldn't open $filename for output $!");
244: return SERVER_ERROR;
245: }
246: print $temp_file $result;
1.3 sakharuk 247: $r->print(<<FINALEND);
1.16 sakharuk 248: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle">
1.3 sakharuk 249: </body>
250: </html>
251: FINALEND
252: }
1.2 sakharuk 253:
1.3 sakharuk 254:
1.6 sakharuk 255:
256:
1.3 sakharuk 257: sub content_map {
1.7 sakharuk 258: #-- find a list of files to print
1.3 sakharuk 259: my $map_string = shift;
1.5 sakharuk 260: my @number_seq = ();
1.7 sakharuk 261: my @file_seq = ();
1.5 sakharuk 262: my $startlink = index($map_string,'<link',0);
1.7 sakharuk 263: my $endlink = index($map_string,'</link>',$startlink);
264: my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
265: $_ = $chunk;
266: m/from=\"(\d+)\"/;
267: push @number_seq,$1;
1.5 sakharuk 268: while ($startlink != -1) {
1.7 sakharuk 269: $endlink = index($map_string,'</link>',$startlink);
270: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5 sakharuk 271: substr($map_string,$startlink,$endlink-$startlink+7) = '';
272: $_ = $chunk;
273: m/to=\"(\d+)\"/;
274: push @number_seq,$1;
1.13 sakharuk 275: $startlink = index($map_string,'from="'.$1.'"',$startlink);
1.18 ! sakharuk 276: $startlink = rindex($map_string,'<link ',$startlink);
1.5 sakharuk 277: }
1.7 sakharuk 278: my $stalink = index($map_string,' to="'.$number_seq[0].'"',$startlink);
279: while ($stalink != -1) {
280: $startlink = rindex($map_string,'<link ',$stalink);
281: $endlink = index($map_string,'</link>',$startlink);
282: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
283: substr($map_string,$startlink,$endlink-$startlink+7) = '';
284: $_ = $chunk;
285: m/from=\"(\d+)\"/;
286: unshift @number_seq,$1;
287: $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
288: }
289: for (my $i=0;$i<=$#number_seq;$i++) {
290: $stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
1.13 sakharuk 291: {
292: my $ahed1 = index($map_string,'src="',$stalink);
293: my $ahed2 = index($map_string,'</resource>',$stalink);
294: if ($ahed1 != -1) {
295: if ($ahed1 < $ahed2) {
296: $startlink = $ahed1;
297: } else {
298: $startlink = rindex($map_string,'src="',$stalink);
299: }
300: } else {
301: $startlink = rindex($map_string,'src="',$stalink);
302: }
303:
304: }
1.7 sakharuk 305: $startlink = index($map_string,'"',$startlink);
306: $endlink = index($map_string,'"',$startlink+1);
307: $chunk = substr($map_string,$startlink,$endlink-$startlink+1);
308: push @file_seq,$chunk;
309: }
310: return @file_seq;
311: }
1.5 sakharuk 312:
1.3 sakharuk 313:
314:
315: sub handler {
316:
317: my $r = shift;
318: $r->content_type('text/html');
319: $r->send_http_header;
320:
321: #-- start form
322: &headerform($r);
323: #-- menu for output
1.16 sakharuk 324: unless ($ENV{'form.phase'}) {
1.3 sakharuk 325: &menu_for_output($r);
326: }
1.16 sakharuk 327:
328:
1.3 sakharuk 329: #-- core part
330: if ($ENV{'form.phase'} eq 'two') {
331: &output_data($r);
1.6 sakharuk 332:
1.3 sakharuk 333: }
1.2 sakharuk 334: return OK;
335:
1.1 www 336: }
337:
338: 1;
339: __END__
1.6 sakharuk 340:
341:
1.13 sakharuk 342:
343:
344: #### Test block
1.6 sakharuk 345: # my $ere;
346: # foreach $ere (%ENV) {
1.13 sakharuk 347: # $result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
1.6 sakharuk 348: # }
1.13 sakharuk 349: ####
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>