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