Annotation of loncom/interface/lonprintout.pm, revision 1.53
1.1 www 1: # The LearningOnline Network
2: # Printout
3: #
1.53 ! albertel 4: # $Id: lonprintout.pm,v 1.52 2002/08/30 20:41:09 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.34 sakharuk 49: use POSIX qw(strftime);
1.52 sakharuk 50: use Apache::loncoursedata;
1.3 sakharuk 51:
52:
53: sub headerform {
1.1 www 54: my $r = shift;
1.3 sakharuk 55: $r->print(<<ENDHEADER);
56: <html>
57: <head>
58: <title>LON-CAPA output for printing</title>
59: </head>
60: <body bgcolor="FFFFFF">
61: <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">
1.38 www 62: <tt>$ENV{'form.postdata'}</tt><p>
1.16 sakharuk 63: <h1>What do you want to print? Make a choice.</h1><br />
1.3 sakharuk 64: ENDHEADER
65: }
66:
1.1 www 67:
1.3 sakharuk 68: sub menu_for_output {
69: my $r = shift;
1.28 sakharuk 70: $r->print(<<ENDMENUOUT1);
1.3 sakharuk 71: <input type="hidden" name="phase" value="two">
1.10 albertel 72: <input type="hidden" name="url" value="$ENV{'form.postdata'}">
1.25 sakharuk 73: <input type="radio" name="choice" value="Standard LaTeX output for current document" checked> Current document
1.16 sakharuk 74: (you will print what you see on the screen)<br />
1.39 sakharuk 75: ENDMENUOUT1
1.48 sakharuk 76: if ((not $ENV{'request.role'}=~m/^au\./) and (not $ENV{'request.role'}=~m/^ca\./)) {
1.52 sakharuk 77: $r->print(<<ENDMENUOUT2);
1.19 sakharuk 78: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence"> All problems from the primary sequence<br />
1.20 sakharuk 79: <input type="radio" name="choice" value="Standard LaTeX output for whole primary sequence"> The whole primary sequence (problems plus all html and xml files)<br />
1.19 sakharuk 80: <input type="radio" name="choice" value="Standard LaTeX output for the top level sequence"> All problems from the top level sequence<br />
1.28 sakharuk 81: <br />
82: ENDMENUOUT2
1.44 sakharuk 83: }
1.52 sakharuk 84: if ($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) {
85: $r->print(<<ENDMENUOUT6);
86: <input type="radio" name="choice" value="All class print"> Print assignment for students in class<br />
87: ENDMENUOUT6
88: }
1.39 sakharuk 89: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
90: $subdirtoprint =~ s/\/[^\/]+$//;
91: if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') {
92: $r->print(<<ENDMENUOUT4);
93: <input type="radio" name="choice" value="Subdirectory print"> All problems from current subdirectory (where this particular problem is)<br />
94: ENDMENUOUT4
95: }
96: $r->print(<<ENDMENUOUT5);
1.16 sakharuk 97: <br /><hr /><br />
98: <h1>And what page format do you prefer?</h1>
1.36 sakharuk 99: <table>
100: <tr>
101: <td>
102: <input type="radio" name="layout" value="CBI"> Landscape <br />
103: <input type="radio" name="layout" value="CAPA" checked> Portrait <br />
104: </td>
105: <td> </td>
106: <td rawspan="2">
1.44 sakharuk 107: Number of columns: <select name="numberofcolumns">
108: <option selected> 1 </option>
109: <option> 2 </option>
110: <option> 3 </option>
111: <option> 4 </option>
112: <option> 5 </option>
113: <option> 6 </option>
114: <option> 7 </option>
115: <option> 8 </option>
116: <option> 9 </option>
117: </select>
1.36 sakharuk 118: </td>
119: </tr>
120: </table>
121: </br>
1.16 sakharuk 122: <input type="submit" value="Submit your choice">
1.52 sakharuk 123: ENDMENUOUT5
124: }
125:
126:
127: sub additional_class_menu {
128: my $r = shift;
129: $r->print(<<ENDMENUOUT1);
130: <input type="hidden" name="url" value="$ENV{'form.url'}">
131: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
132: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
133: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
134: <h1>Mark students which assignments you want to print</h1>
135: ENDMENUOUT1
136: my $c = $r->connection;
137: my %cache;
138: my $courseID=$ENV{'request.course.id'};
139: my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
140: $cache{'ClasslistTimestamp'},
141: $c);
142: foreach (keys(%$classlist)) {
143: if(/^(con_lost|error|no_such_host)/i) {
144: untie(%cache);
145: return "Error getting student data.";
146: }
147: }
148: my $classlistaa = '';
149: foreach my $st (keys(%$classlist)) {
150: $classlistaa .= ' SSS '.$st.' => '.$$classlist{$st}.' FFF '."\r\n";
151: }
152:
153: $r->print(<<ENDMENUOUT2);
154: $classlistaa <br />
155: <input type="hidden" name="phase" value="three">
156: <input type="submit" value="Submit">
157: ENDMENUOUT2
158: }
159:
160:
161: sub additional_print_menu {
162: my $r = shift;
163: $r->print(<<ENDMENUOUT);
164: <input type="hidden" name="url" value="$ENV{'form.url'}">
165: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
166: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
167: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
168: Enter width of the page: <input type="text" name="width" width="10" value="9cm"> <br />
169: <input type="hidden" name="phase" value="four">
170: <input type="submit" value="Submit">
1.3 sakharuk 171: </form>
172: </body>
173: </html>
1.52 sakharuk 174: ENDMENUOUT
1.3 sakharuk 175: }
1.2 sakharuk 176:
177:
1.3 sakharuk 178: sub output_data {
179: my $r = shift;
180: $r->print(<<ENDPART);
181: <html>
182: <head>
183: <title>LON-CAPA output for printing</title>
184: </head>
185: <body bgcolor="FFFFFF">
186: <hr>
187: ENDPART
1.2 sakharuk 188:
1.3 sakharuk 189: my $choice = $ENV{'form.choice'};
1.16 sakharuk 190: my $layout = $ENV{'form.layout'};
1.36 sakharuk 191: my $numberofcolumns = $ENV{'form.numberofcolumns'};
1.16 sakharuk 192: my $laystyle = 'book';
1.2 sakharuk 193: my $result = '';
1.34 sakharuk 194: my $number_of_columns = 1;
1.36 sakharuk 195:
1.3 sakharuk 196: if ($choice eq 'Standard LaTeX output for current document') {
1.36 sakharuk 197: #-- single document - problem, page, html, xml
1.14 albertel 198: my %moreenv;
199: $moreenv{'form.grade_target'}='tex';
1.48 sakharuk 200: if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
201: $ENV{'form.url'}=~s/http:\/\/[^\/]+//;
202: }
1.14 albertel 203: $moreenv{'request.filename'}=$ENV{'form.url'};
204: &Apache::lonnet::appenv(%moreenv);
205: my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
206: &Apache::lonnet::delenv('form.grade_target');
207: $result .= $texversion;
1.29 sakharuk 208: $result = &additional_cleanup($result);
1.40 sakharuk 209: if ($ENV{'form.url'}=~m/\.page\s*$/) {
210: ($result,$number_of_columns) = &page_cleanup($result);
211: }
212: } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or
213: $choice eq 'Standard LaTeX output for whole primary sequence') {
1.36 sakharuk 214: #-- minimal sequence to which the current document belongs
215: #-- where is the primary sequence containing file?
1.18 sakharuk 216: my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
217: $_ = $symbolic;
218: m/([^_]+)_/;
219: my $primary_sequence = '/res/'.$1;
1.36 sakharuk 220: #-- open and analyses the primary sequence
1.18 sakharuk 221: my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
222: my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
223: my @master_seq = &content_map($sequencefilecontents);
1.36 sakharuk 224: #-- produce an output string
1.18 sakharuk 225: for (my $i=0;$i<=$#master_seq;$i++) {
226: $_ = $master_seq[$i];
227: m/\"(.*)\"/;
228: $_ = $1;
1.36 sakharuk 229: my $urlp = $1;
1.20 sakharuk 230: if ($choice eq 'Standard LaTeX output for the primary sequence') {
1.36 sakharuk 231: if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.20 sakharuk 232: my %moreenv;
233: $moreenv{'form.grade_target'}='tex';
234: &Apache::lonnet::appenv(%moreenv);
235: my $texversion=&Apache::lonnet::ssi($urlp);
236: &Apache::lonnet::delenv('form.grade_target');
237: $result .= $texversion;
238: }
1.53 ! albertel 239: } elsif ($urlp =~ /\S+/) {
1.36 sakharuk 240: my %moreenv;
1.18 sakharuk 241: $moreenv{'form.grade_target'}='tex';
242: &Apache::lonnet::appenv(%moreenv);
243: my $texversion=&Apache::lonnet::ssi($urlp);
244: &Apache::lonnet::delenv('form.grade_target');
1.20 sakharuk 245: $result .= $texversion;
1.16 sakharuk 246: }
1.28 sakharuk 247: }
248: $result = &additional_cleanup($result);
1.13 sakharuk 249: } elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
1.47 sakharuk 250: # where is the main sequence of the course?
1.13 sakharuk 251: my $main_seq = '/res/'.$ENV{'request.course.uri'};
252: my $file=&Apache::lonnet::filelocation("",$main_seq);
253: my $filecontents=&Apache::lonnet::getfile($file);
254: my @file_seq = &content_map($filecontents);
1.48 sakharuk 255: for (my $iu=0;$iu<=$#file_seq;$iu++) {
256: $file_seq[$iu]=~s/^"//;
257: $file_seq[$iu]=~s/"$//;
1.49 sakharuk 258: if ($file_seq[$iu]=~m/\S+/) {
259: $file_seq[$iu]=&Apache::lonnet::filelocation("",$file_seq[$iu]);
260: } else {
261: $file_seq[$iu]= 'REMOVE IT PLEASE';
262: }
1.48 sakharuk 263: }
264: my $i=0;
1.49 sakharuk 265: my $limit = $#file_seq;
266: while ($i<=$limit) {
1.48 sakharuk 267: unless ($file_seq[$i]=~m/\.(problem|page)/) {
268: if ($file_seq[$i]=~m/\.sequence/) {
269: my $filecontents=&Apache::lonnet::getfile($file_seq[$i]);
270: my @newfile_seq = &content_map($filecontents);
1.49 sakharuk 271: for (my $iu=0;$iu<=$#newfile_seq;$iu++) {
272: $newfile_seq[$iu]=~s/^"//;
273: $newfile_seq[$iu]=~s/"$//;
274: if ($newfile_seq[$iu]=~m/\S+/) {
275: $newfile_seq[$iu]=&Apache::lonnet::filelocation("",$newfile_seq[$iu]);
276: } else {
277: $newfile_seq[$iu]= 'REMOVE IT PLEASE';
278: }
279: }
280: splice @file_seq,$i,1,@newfile_seq;
281: $i=0;
282: $limit = $#file_seq;
1.48 sakharuk 283: } else {
1.49 sakharuk 284: splice @file_seq,$i,1,'REMOVE IT PLEASE';
1.48 sakharuk 285: }
286: }
287: $i++;
288: }
289: for (my $iu=0;$iu<=$#file_seq;$iu++) {
1.49 sakharuk 290: if ($file_seq[$iu]=~m/REMOVE IT PLEASE/) {
291: splice @file_seq,$iu,1;
292: }
293: }
294: if ($file_seq[-1]=~m/REMOVE IT PLEASE/) {
295: pop @file_seq;
1.48 sakharuk 296: }
1.52 sakharuk 297: #-- produce an output string
1.49 sakharuk 298: for (my $i=0;$i<=$#file_seq;$i++) {
299: my $urlp = $file_seq[$i];
300: $urlp=~s/\/home\/httpd\/html//;
301: if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) {
302: my %moreenv;
303: $moreenv{'form.grade_target'}='tex';
304: &Apache::lonnet::appenv(%moreenv);
305: my $texversion=&Apache::lonnet::ssi($urlp);
306: &Apache::lonnet::delenv('form.grade_target');
307: $result .= $texversion;
308: }
309: }
310: $result = &additional_cleanup($result);
1.52 sakharuk 311: } elsif ($choice eq 'All class print') {
312:
313:
314:
1.31 sakharuk 315: } elsif ($choice eq 'Subdirectory print') {
316: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
317: $subdirtoprint =~ s/\/[^\/]+$//;
318: my @list_of_files = ();
1.48 sakharuk 319: if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
1.45 sakharuk 320: $subdirtoprint =~ s/^[^~]*~(\w+)\//\/home\/$1\/public_html\//;
321: } else {
322: $subdirtoprint =~ s/.*(\/res\/)/$1/;
323: }
1.46 sakharuk 324: my @content_directory = ();
1.48 sakharuk 325: if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
1.46 sakharuk 326: @content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},'');
1.45 sakharuk 327: } else {
1.46 sakharuk 328: @content_directory = &Apache::lonnet::dirlist($subdirtoprint);
329: }
330: for (my $iy=0;$iy<=$#content_directory;$iy++) {
331: my @tempo_array = split(/&/,$content_directory[$iy]);
332: if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) {
333: push(@list_of_files,$tempo_array[0]);
1.28 sakharuk 334: }
1.13 sakharuk 335: }
1.45 sakharuk 336: $subdirtoprint =~ s/\/$//;
1.31 sakharuk 337: for (my $i=0;$i<=$#list_of_files;$i++) {
1.45 sakharuk 338: my $urlp = $subdirtoprint.'/'.$list_of_files[$i];
1.31 sakharuk 339: my %moreenv;
340: $moreenv{'form.grade_target'}='tex';
341: &Apache::lonnet::appenv(%moreenv);
1.48 sakharuk 342: if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
343: $urlp =~ s/\/home\/([^\/]*)\/public_html/\/~$1/;
344: }
1.31 sakharuk 345: my $texversion=&Apache::lonnet::ssi($urlp);
346: &Apache::lonnet::delenv('form.grade_target');
347: $texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;
348: $result .= $texversion;
349: }
350: $result = &additional_cleanup($result);
351:
1.51 sakharuk 352:
1.7 sakharuk 353: }
1.16 sakharuk 354: #-- corrections for the different page formats
1.36 sakharuk 355: if ($layout eq 'CBI' and $numberofcolumns eq '1') {
356: } elsif ($layout eq 'CBI' and $numberofcolumns eq '2') {
1.16 sakharuk 357: $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}/;
358: $laystyle = 'album';
359: } elsif ($layout eq 'CAPA') {
360: my $courseidinfo = $ENV{'request.role'};
361: $_ = $courseidinfo;
362: m/.*\/(.*)/;
363: $courseidinfo = $ENV{'course.physnet_'.$1.'.description'};
1.34 sakharuk 364: # $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass\[twocolumn\]{article}/;
365: $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass{article}/;
366: $result =~ s/\\begin{document}/\\textheight 25\.9cm\\oddsidemargin = -0\.57in\\evensidemargin = -0\.57in\\textwidth= 9cm\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\begin{document}\\voffset=-1\.8cm\\setcounter{page}{1}\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$ENV{'environment.firstname'} $ENV{'environment.lastname'}}}\\hskip 1\.4in $courseidinfo} \\vskip 5 mm /;
1.27 sakharuk 367: $result =~ s/\\includegraphics{/\\includegraphics\[width=9\.0 cm\]{/g;
1.37 sakharuk 368: # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\textwidth\]{/g;
369: # $result =~ s/(\\end{document})/\\newline\\noindent\\makebox\[9.0cm\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Dept\. of Physics and Astronomy, MSU\\makebox\[1.5cm\]\[b\]{\\hfill}LON-CAPA\\copyright MSU GNU\/GPL $1/;
1.50 albertel 370: $result =~ s/(\\end{document})/\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny \\makebox\[1.5cm\]\[b\]{\\hfill}LON-CAPA\\copyright Michigan State University Board of Trustees $1/;
1.37 sakharuk 371: # $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[9\.0cm\]\[b\]{\\hrulefill})/$2$1/g;
372: $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
1.34 sakharuk 373: $result =~ s/(\\end{longtable}\s*)\\newline/$1/g;
1.37 sakharuk 374: $result =~ s/\$number_of_columns/$number_of_columns/g;
1.16 sakharuk 375: }
1.52 sakharuk 376: #changes page's parameters for the one column output
377: if ($ENV{'form.numberofcolumns'} == 1) {
378: $result =~ s/\\textwidth= 9cm/\\textwidth= $ENV{'form.width'}/;
379: }
1.23 sakharuk 380: #-- LaTeX corrections
381: my $first_comment = index($result,'<!--',0);
382: while ($first_comment != -1) {
383: my $end_comment = index($result,'-->',$first_comment);
384: substr($result,$first_comment,$end_comment-$first_comment+3) = '';
385: $first_comment = index($result,'<!--',$first_comment);
386: }
1.17 sakharuk 387: $result =~ s/^\s+$//gm; #remove empty lines
1.20 sakharuk 388: $result =~ s/(\s)+/$1/g; #removes more than one empty space
1.23 sakharuk 389: $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
1.24 sakharuk 390: $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
1.23 sakharuk 391: $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.24 sakharuk 392: $result =~ s/\\\\\s+\[/ \[/g;
393: $result =~ s/θ/\$\\theta\$/g; #converts theta from html into tex
1.41 sakharuk 394: $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
1.37 sakharuk 395: #conversion of html characters to LaTeX equivalents
396: if ($result =~ m/&(\w+|#\d+);/) {
397: $result = &character_chart($result);
398: }
1.42 sakharuk 399: $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
400: $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
1.7 sakharuk 401: #-- writing .tex file in prtspool
1.16 sakharuk 402: my $temp_file;
1.33 sakharuk 403: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
1.16 sakharuk 404: unless ($temp_file = Apache::File->new('>'.$filename)) {
405: $r->log_error("Couldn't open $filename for output $!");
406: return SERVER_ERROR;
407: }
408: print $temp_file $result;
1.3 sakharuk 409: $r->print(<<FINALEND);
1.51 sakharuk 410: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns">
1.3 sakharuk 411: </body>
412: </html>
413: FINALEND
414: }
1.2 sakharuk 415:
1.37 sakharuk 416: sub character_chart {
417: my $result = shift;
1.41 sakharuk 418: $result =~ s/�?0?7;//g;
1.40 sakharuk 419: $result =~ s/�?0?9;//g;
420: $result =~ s/�?10;//g;
421: $result =~ s/�?13;//g;
422: $result =~ s/�?32;/ /g;
423: $result =~ s/�?33;/!/g;
424: $result =~ s/�?34;/"/g;
1.39 sakharuk 425: $result =~ s/"/"/g;
1.40 sakharuk 426: $result =~ s/�?35;/\\#/g;
427: # $result =~ s/�?36;/\\\$/g;
428: $result =~ s/�?37;/\\%/g;
429: $result =~ s/�?38;/\\&/g;
1.37 sakharuk 430: $result =~ s/&/\\&/g;
1.40 sakharuk 431: $result =~ s/�?39;/'/g;
432: $result =~ s/�?40;/(/g;
433: $result =~ s/�?41;/)/g;
434: $result =~ s/�?42;/\*/g;
435: $result =~ s/�?43;/\+/g;
436: $result =~ s/�?44;/,/g;
437: $result =~ s/�?45;/-/g;
438: $result =~ s/�?46;/\./g;
439: $result =~ s/�?47;/\//g;
440: $result =~ s/�?48;/0/g;
441: $result =~ s/�?49;/1/g;
442: $result =~ s/�?50;/2/g;
443: $result =~ s/�?51;/3/g;
444: $result =~ s/�?52;/4/g;
445: $result =~ s/�?53;/5/g;
446: $result =~ s/�?54;/6/g;
447: $result =~ s/�?55;/7/g;
448: $result =~ s/�?56;/8/g;
449: $result =~ s/�?57;/9/g;
450: $result =~ s/�?58;/:/g;
451: $result =~ s/�?59;/;/g;
452: $result =~ s/�?60;/\$<\$/g;
1.37 sakharuk 453: $result =~ s/</\$<\$/g;
1.40 sakharuk 454: $result =~ s/�?61;/\$=\$/g;
455: $result =~ s/�?62;/\$>\$/g;
1.37 sakharuk 456: $result =~ s/>/\$>\$/g;
1.40 sakharuk 457: $result =~ s/�?63;/?/g;
458: # $result =~ s/�?64;//g;
459: $result =~ s/�?65;/A/g;
460: $result =~ s/�?66;/B/g;
461: $result =~ s/�?67;/C/g;
462: $result =~ s/�?68;/D/g;
463: $result =~ s/�?69;/E/g;
464: $result =~ s/�?70;/F/g;
465: $result =~ s/�?71;/G/g;
466: $result =~ s/�?72;/H/g;
467: $result =~ s/�?73;/I/g;
468: $result =~ s/�?74;/J/g;
469: $result =~ s/�?75;/K/g;
470: $result =~ s/�?76;/L/g;
471: $result =~ s/�?77;/M/g;
472: $result =~ s/�?78;/N/g;
473: $result =~ s/�?79;/O/g;
474: $result =~ s/�?80;/P/g;
475: $result =~ s/�?81;/Q/g;
476: $result =~ s/�?82;/R/g;
477: $result =~ s/�?83;/S/g;
478: $result =~ s/�?84;/T/g;
479: $result =~ s/�?85;/U/g;
480: $result =~ s/�?86;/V/g;
481: $result =~ s/�?87;/W/g;
482: $result =~ s/�?88;/X/g;
483: $result =~ s/�?89;/Y/g;
484: $result =~ s/�?90;/Z/g;
485: $result =~ s/�?91;/[/g;
486: $result =~ s/�?92;/\\/g;
487: $result =~ s/�?93;/]/g;
488: # $result =~ s/�?94;//g;
489: # $result =~ s/�?95;//g;
490: $result =~ s/�?96;/`/g;
491: $result =~ s/�?97;/a/g;
492: $result =~ s/�?98;/b/g;
493: $result =~ s/�?99;/c/g;
1.37 sakharuk 494: $result =~ s/d/d/g;
495: $result =~ s/e/e/g;
496: $result =~ s/f/f/g;
497: $result =~ s/g/g/g;
498: $result =~ s/h/h/g;
499: $result =~ s/i/i/g;
500: $result =~ s/j/j/g;
501: $result =~ s/k/k/g;
502: $result =~ s/l/l/g;
503: $result =~ s/m/m/g;
504: $result =~ s/n/n/g;
505: $result =~ s/o/o/g;
506: $result =~ s/p/p/g;
507: $result =~ s/q/q/g;
508: $result =~ s/r/r/g;
509: $result =~ s/s/s/g;
510: $result =~ s/t/t/g;
511: $result =~ s/u/u/g;
512: $result =~ s/v/v/g;
513: $result =~ s/w/w/g;
514: $result =~ s/x/x/g;
515: $result =~ s/y/y/g;
516: $result =~ s/z/z/g;
517: $result =~ s/{/\\{/g;
518: $result =~ s/|/\|/g;
519: $result =~ s/}/\\}/g;
520: $result =~ s/~/\~/g;
521: $result =~ s/‚/,/g;
522: # $result =~ s/ƒ//g;
523: $result =~ s/„/''/g;
524: $result =~ s/…/\$\\ldots\$/g;
525: $result =~ s/†/\$\\dagger\$/g;
526: $result =~ s/‡/\$\\ddagger\$/g;
527: # $result =~ s/ˆ//g;
528: # $result =~ s/‰//g;
529: # $result =~ s/Š//g;
530: $result =~ s/‹/\$<\$/g;
531: # $result =~ s/Œ//g;
532: $result =~ s/‘/`/g;
533: $result =~ s/’/'/g;
534: $result =~ s/“/``/g;
535: $result =~ s/”/''/g;
536: $result =~ s/•/\$\\bullet\$/g;
537: # $result =~ s/–//g;
538: # $result =~ s/—//g;
539: $result =~ s/˜/~/g;
540: # $result =~ s/™//g;
541: # $result =~ s/š//g;
542: $result =~ s/›/\$>\$/g;
543: $result =~ s/œ/\\{\\oe\\}/g;
544: $result =~ s/Ÿ/\\"\\{Y\\}/g;
545: $result =~ s/ //g;
546: $result =~ s/ //g;
547: $result =~ s/¡/!`/g;
548: $result =~ s/¡/!`/g; #`
549: # $result =~ s/¢//g;
550: # $result =~ s/¢//g;
551: $result =~ s/£/\\pounds/g;
552: $result =~ s/£/\\pounds/g;
553: # $result =~ s/¤//g;
554: # $result =~ s/¤//g;
555: # $result =~ s/¥//g;
556: # $result =~ s/¥//g;
557: # $result =~ s/¦//g;
558: # $result =~ s/¦//g;
559: # $result =~ s/§//g;
560: # $result =~ s/§//g;
561: # $result =~ s/¨//g;
562: # $result =~ s/¨//g;
563: $result =~ s/©/\\copyright/g;
564: $result =~ s/©/\\copyright/g;
565: # $result =~ s/ª//g;
566: # $result =~ s/ª//g;
567: # $result =~ s/«//g;
568: # $result =~ s/«//g;
569: $result =~ s/¬/\$\\neg\$/g;
570: $result =~ s/¬/\$\\neg\$/g;
571: # $result =~ s/­//g;
572: # $result =~ s/­//g;
573: # $result =~ s/®//g;
574: # $result =~ s/®//g;
575: # $result =~ s/¯//g;
576: # $result =~ s/¯//g;
1.42 sakharuk 577: $result =~ s/°/\$^{\\circ}\$/g;
578: $result =~ s/°/\$^{\\circ}\$/g;
1.37 sakharuk 579: $result =~ s/±/\$\\pm\$/g;
580: $result =~ s/±/\$\\pm\$/g;
581: $result =~ s/²/\$^2\$/g;
582: $result =~ s/²/\$^2\$/g;
583: $result =~ s/³/\$^3\$/g;
584: $result =~ s/³/\$^3\$/g;
585: # $result =~ s/´//g;
586: # $result =~ s/´//g;
587: $result =~ s/µ/\$\\mu\$/g;
588: $result =~ s/µ/\$\\mu\$/g;
589: $result =~ s/¶/\\P/g;
590: $result =~ s/¶/\\P/g;
591: $result =~ s/·/\$\\cdot\$/g;
592: $result =~ s/·/\$\\cdot\$/g;
593: # $result =~ s/¸//g;
594: # $result =~ s/¸//g;
595: $result =~ s/¹/\$^1\$/g;
596: $result =~ s/¹/\$^1\$/g;
597: # $result =~ s/º//g;
598: # $result =~ s/º//g;
599: # $result =~ s/»//g;
600: # $result =~ s/»//g;
601: # $result =~ s/¼//g;
602: # $result =~ s/¼//g;
603: # $result =~ s/½//g;
604: # $result =~ s/½//g;
605: # $result =~ s/¾//g;
606: # $result =~ s/¾//g;
607: $result =~ s/¿/?`/g;
608: $result =~ s/¿/?`/g;
609: $result =~ s/À/\\`{A}/g;
610: $result =~ s/À/\\`{A}/g;
611: $result =~ s/Á/\\'{A}/g;
612: $result =~ s/Á/\\'{A}/g;
613: $result =~ s/Â/\\^{A}/g;
614: $result =~ s/Â/\\^{A}/g;
615: $result =~ s/Ã/\\~{A}/g;
616: $result =~ s/Ã/\\~{A}/g;
617: $result =~ s/Ä/\\"{A}/g;
618: $result =~ s/Ä/\\"{A}/g;
619: $result =~ s/Å/{\\AA}/g;
620: $result =~ s/Å/{\\AA}/g;
621: $result =~ s/Æ/{\\AE}/g;
622: $result =~ s/Æ/{\\AE}/g;
623: # $result =~ s/Ç//g;
624: # $result =~ s/Ç//g;
625: $result =~ s/È/\\`{E}/g;
626: $result =~ s/È/\\`{E}/g;
627: $result =~ s/É/\\'{E}/g;
628: $result =~ s/É/\\'{E}/g;
629: $result =~ s/Ê/\\^{E}/g;
630: $result =~ s/Ê/\\^{E}/g;
631: $result =~ s/Ë/\\`{E}/g;
632: $result =~ s/Ë/\\`{E}/g;
633: $result =~ s/Ì/\\`{I}/g;
634: $result =~ s/Ì/\\`{I}/g;
635: $result =~ s/Í/\\'{I}/g;
636: $result =~ s/Í/\\'{I}/g;
637: $result =~ s/Î/\\^{I}/g;
638: $result =~ s/Î/\\^{I}/g;
639: $result =~ s/Ï/\\"{I}/g;
640: $result =~ s/Ï/\\"{I}/g;
641: # $result =~ s/Ð//g;
642: # $result =~ s/Ð//g;
643: $result =~ s/Ñ/\\~{N}/g;
644: $result =~ s/Ñ/\\~{N}/g;
645: $result =~ s/Ò/\\`{O}/g;
646: $result =~ s/Ò/\\`{O}/g;
647: $result =~ s/Ó/\\'{O}/g;
648: $result =~ s/Ó/\\'{O}/g;
649: $result =~ s/Ô/\\^{O}/g;
650: $result =~ s/Ô/\\^{O}/g;
651: $result =~ s/Õ/\\~{O}/g;
652: $result =~ s/Õ/\\~{O}/g;
653: $result =~ s/Ö/\\"{O}/g;
654: $result =~ s/Ö/\\"{O}/g;
655: $result =~ s/×/\$\\times\$/g;
656: $result =~ s/×/\$\\times\$/g;
657: $result =~ s/Ø/{\\O}/g;
658: $result =~ s/Ø/{\\O}/g;
659: $result =~ s/Ù/\\`{U}/g;
660: $result =~ s/Ù/\\`{U}/g;
661: $result =~ s/Ú/\\'{U}/g;
662: $result =~ s/Ú/\\'{U}/g;
663: $result =~ s/Û/\\^{U}/g;
664: $result =~ s/Û/\\^{U}/g;
665: $result =~ s/Ü/\\"{U}/g;
666: $result =~ s/Ü/\\"{U}/g;
667: $result =~ s/Ý/\\'{Y}/g;
668: $result =~ s/Ý/\\'{Y}/g;
669: # $result =~ s/Þ//g;
670: # $result =~ s/Þ//g;
671: # $result =~ s/ß//g;
672: # $result =~ s/ß//g;
673: $result =~ s/à/\\`{a}/g;
674: $result =~ s/à/\\`{a}/g;
675: $result =~ s/á/\\'{a}/g;
676: $result =~ s/á/\\'{a}/g;
677: $result =~ s/â/\\^{a}/g;
678: $result =~ s/â/\\^{a}/g;
679: $result =~ s/ã/\\~{a}/g;
680: $result =~ s/ã/\\~{a}/g;
681: $result =~ s/ä/\\"{a}/g;
682: $result =~ s/ä/\\"{a}/g;
683: $result =~ s/å/{\\aa}/g;
684: $result =~ s/å/{\\aa}/g;
685: $result =~ s/æ/{\\ae}/g;
686: $result =~ s/æ/{\\ae}/g;
687: # $result =~ s/ç//g;
688: # $result =~ s/ç//g;
689: $result =~ s/è/\\`{e}/g;
690: $result =~ s/è/\\`{e}/g;
691: $result =~ s/é/\\'{e}/g;
692: $result =~ s/é/\\'{e}/g;
693: $result =~ s/ê/\\^{e}/g;
694: $result =~ s/ê/\\^{e}/g;
695: $result =~ s/ë/\\"{e}/g;
696: $result =~ s/ë/\\"{e}/g;
697: $result =~ s/ì/\\`{i}/g;
698: $result =~ s/ì/\\`{i}/g;
699: $result =~ s/í/\\'{i}/g;
700: $result =~ s/í/\\'{i}/g;
701: $result =~ s/î/\\^{i}/g;
702: $result =~ s/î/\\^{i}/g;
703: $result =~ s/ï/\\"{i}/g;
704: $result =~ s/ï/\\"{i}/g;
705: # $result =~ s/ð//g;
706: # $result =~ s/ð//g;
707: $result =~ s/ñ/\\~{n}/g;
708: $result =~ s/ñ/\\~{n}/g;
709: $result =~ s/ò/\\`{o}/g;
710: $result =~ s/ò/\\`{o}/g;
711: $result =~ s/ó/\\'{o}/g;
712: $result =~ s/ó/\\'{o}/g;
713: $result =~ s/ô/\\^{o}/g;
714: $result =~ s/ô/\\^{o}/g;
715: $result =~ s/õ/\\~{o}/g;
716: $result =~ s/õ/\\~{o}/g;
717: $result =~ s/ö/\\"{o}/g;
718: $result =~ s/ö/\\"{o}/g;
719: $result =~ s/÷/\$\\div\$/g;
720: $result =~ s/÷/\$\\div\$/g;
721: $result =~ s/ø/{\\o}/g;
722: $result =~ s/ø/{\\o}/g;
723: $result =~ s/ù/\\`{u}/g;
724: $result =~ s/ù/\\`{u}/g;
725: $result =~ s/ú/\\'{u}/g;
726: $result =~ s/ú/\\'{u}/g;
727: $result =~ s/û/\\^{u}/g;
728: $result =~ s/û/\\^{u}/g;
729: $result =~ s/ü/\\"{u}/g;
730: $result =~ s/ü/\\"{u}/g;
731: $result =~ s/ý/\\'{y}/g;
732: $result =~ s/ý/\\'{y}/g;
733: # $result =~ s/þ//g;
734: # $result =~ s/þ//g;
735: $result =~ s/ÿ/\\"{y}/g;
736: $result =~ s/ÿ/\\"{y}/g;
737: return $result;
738: }
1.41 sakharuk 739:
740:
741: #'"`
1.37 sakharuk 742:
1.28 sakharuk 743: sub additional_cleanup {
744: my $result = shift;
745: my $first_app = index($result,'\documentclass',0);
746: $first_app = index($result,'\documentclass',$first_app+5);
747: while ($first_app != -1) {
748: my $second_app = index($result,'begin{document}',$first_app);
749: $first_app = rindex($result,'\end{document}',$first_app);
750: substr($result,$first_app,$second_app-$first_app+15) = '\vskip 3 mm';
751: $first_app = index($result,'\documentclass',$first_app+5);
752: }
753: return $result;
754: }
1.33 sakharuk 755: sub page_cleanup {
756: my $result = shift;
757: $_ = $result;
758: m/\\end{document}(\d*)$/;
1.34 sakharuk 759: my $number_of_columns = $1;
1.33 sakharuk 760: my $insert = '{';
1.34 sakharuk 761: for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33 sakharuk 762: $insert .= '}';
1.34 sakharuk 763: $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE/$1$insert/g;
764: $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
765: $result =~ s/(\\vskip\s*\d+\s*mm)/}\\\\\\parbox{\\minipagewidth}{/g;
1.35 sakharuk 766: $result =~ s/\\parbox{\\minipagewidth}{}\s*\\\\\s*(\\parbox{\\minipagewidth})/$1/g;
1.37 sakharuk 767: $result =~ s/\\parbox{\\minipagewidth}{\s*\\\\\\\\/\\parbox{\\minipagewidth}{/g;
1.34 sakharuk 768: return $result,$number_of_columns;
1.33 sakharuk 769: }
1.6 sakharuk 770:
1.3 sakharuk 771: sub content_map {
1.7 sakharuk 772: #-- find a list of files to print
1.3 sakharuk 773: my $map_string = shift;
1.5 sakharuk 774: my @number_seq = ();
1.7 sakharuk 775: my @file_seq = ();
1.5 sakharuk 776: my $startlink = index($map_string,'<link',0);
1.7 sakharuk 777: my $endlink = index($map_string,'</link>',$startlink);
778: my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
779: $_ = $chunk;
780: m/from=\"(\d+)\"/;
781: push @number_seq,$1;
1.5 sakharuk 782: while ($startlink != -1) {
1.7 sakharuk 783: $endlink = index($map_string,'</link>',$startlink);
784: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5 sakharuk 785: substr($map_string,$startlink,$endlink-$startlink+7) = '';
786: $_ = $chunk;
787: m/to=\"(\d+)\"/;
788: push @number_seq,$1;
1.44 sakharuk 789: $startlink = index($map_string,'from="'.$1.'"',0);
1.18 sakharuk 790: $startlink = rindex($map_string,'<link ',$startlink);
1.5 sakharuk 791: }
1.45 sakharuk 792: my $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
1.7 sakharuk 793: while ($stalink != -1) {
794: $startlink = rindex($map_string,'<link ',$stalink);
795: $endlink = index($map_string,'</link>',$startlink);
796: $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
797: substr($map_string,$startlink,$endlink-$startlink+7) = '';
798: $_ = $chunk;
799: m/from=\"(\d+)\"/;
800: unshift @number_seq,$1;
801: $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
802: }
803: for (my $i=0;$i<=$#number_seq;$i++) {
804: $stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
1.13 sakharuk 805: {
806: my $ahed1 = index($map_string,'src="',$stalink);
807: my $ahed2 = index($map_string,'</resource>',$stalink);
808: if ($ahed1 != -1) {
809: if ($ahed1 < $ahed2) {
810: $startlink = $ahed1;
811: } else {
812: $startlink = rindex($map_string,'src="',$stalink);
813: }
814: } else {
815: $startlink = rindex($map_string,'src="',$stalink);
816: }
817:
818: }
1.7 sakharuk 819: $startlink = index($map_string,'"',$startlink);
820: $endlink = index($map_string,'"',$startlink+1);
821: $chunk = substr($map_string,$startlink,$endlink-$startlink+1);
822: push @file_seq,$chunk;
823: }
824: return @file_seq;
825: }
1.5 sakharuk 826:
1.3 sakharuk 827:
828:
829: sub handler {
830:
831: my $r = shift;
832: $r->content_type('text/html');
833: $r->send_http_header;
834:
835: #-- start form
836: &headerform($r);
837: #-- menu for output
1.16 sakharuk 838: unless ($ENV{'form.phase'}) {
1.3 sakharuk 839: &menu_for_output($r);
840: }
1.52 sakharuk 841: #-- additional menu for class printing
842: if ($ENV{'form.phase'} eq 'two') {
843: if($ENV{'form.choice'} eq 'All class print') {
844: &additional_class_menu($r);
845: } else {
846: $ENV{'form.phase'} = 'three';
847: }
848: }
849: #-- additional menu for page layout (one column case)
850: if ($ENV{'form.phase'} eq 'three') {
851: if($ENV{'form.numberofcolumns'} == 1) {
852: &additional_print_menu($r);
853: } else {
854: $ENV{'form.phase'} = 'four';
855: }
856: }
1.3 sakharuk 857: #-- core part
1.52 sakharuk 858: if ($ENV{'form.phase'} eq 'four') {
1.3 sakharuk 859: &output_data($r);
860: }
1.2 sakharuk 861: return OK;
862:
1.1 www 863: }
864:
865: 1;
866: __END__
1.6 sakharuk 867:
868:
1.13 sakharuk 869:
870:
871: #### Test block
1.6 sakharuk 872: # my $ere;
873: # foreach $ere (%ENV) {
1.13 sakharuk 874: # $result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
1.6 sakharuk 875: # }
1.13 sakharuk 876: ####
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>