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