Annotation of loncom/interface/lonprintout.pm, revision 1.55

1.1       www         1: # The LearningOnline Network
                      2: # Printout
                      3: #
1.55    ! sakharuk    4: # $Id: lonprintout.pm,v 1.54 2002/09/05 15:51:07 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::loncoursedata;
                     49: use Apache::grades;
1.13      sakharuk   50: use Apache::edit;
1.5       sakharuk   51: use Apache::File();
1.34      sakharuk   52: use POSIX qw(strftime);
1.3       sakharuk   53: 
                     54: 
                     55: sub headerform {
1.1       www        56:     my $r = shift;
1.3       sakharuk   57:     $r->print(<<ENDHEADER);
                     58: <html>
                     59: <head>
                     60: <title>LON-CAPA output for printing</title>
                     61: </head>
                     62: <body bgcolor="FFFFFF">
                     63: <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">
1.38      www        64: <tt>$ENV{'form.postdata'}</tt><p>
1.16      sakharuk   65: <h1>What do you want to print? Make a choice.</h1><br />
1.3       sakharuk   66: ENDHEADER
                     67: }
                     68: 
1.1       www        69: 
1.3       sakharuk   70: sub menu_for_output {
                     71:     my $r = shift;
1.28      sakharuk   72:     $r->print(<<ENDMENUOUT1);
1.3       sakharuk   73: <input type="hidden" name="phase" value="two">
1.10      albertel   74: <input type="hidden" name="url" value="$ENV{'form.postdata'}">
1.25      sakharuk   75: <input type="radio" name="choice" value="Standard LaTeX output for current document" checked>  Current document
1.16      sakharuk   76: (you will print what you see on the screen)<br />
1.39      sakharuk   77: ENDMENUOUT1
1.48      sakharuk   78:     if ((not $ENV{'request.role'}=~m/^au\./) and (not $ENV{'request.role'}=~m/^ca\./)) {
1.52      sakharuk   79: 	$r->print(<<ENDMENUOUT2);
1.19      sakharuk   80: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence">  All problems from the primary sequence<br />
1.20      sakharuk   81: <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   82: <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   83: <br />
                     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.55    ! sakharuk   88:   <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   89: ENDMENUOUT6
                     90:     }
1.39      sakharuk   91:       my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
                     92:       $subdirtoprint =~ s/\/[^\/]+$//;
                     93:       if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') {
                     94: 	  $r->print(<<ENDMENUOUT4);
                     95:   <input type="radio" name="choice" value="Subdirectory print">  All problems from current subdirectory (where this particular problem is)<br />
                     96: ENDMENUOUT4
                     97:       }
                     98:     $r->print(<<ENDMENUOUT5);
1.16      sakharuk   99: <br /><hr /><br />
                    100: <h1>And what page format do you prefer?</h1>
1.36      sakharuk  101: <table>
                    102:  <tr>
                    103:    <td>
                    104:      <input type="radio" name="layout" value="CBI"> Landscape <br />
                    105:      <input type="radio" name="layout" value="CAPA" checked>  Portrait <br />
                    106:    </td>
                    107:    <td>&nbsp;</td>
                    108:    <td rawspan="2">
1.44      sakharuk  109:      Number of columns: <select name="numberofcolumns">
                    110:                          <option selected> 1 </option>
                    111:                          <option> 2 </option>
                    112:                          <option> 3 </option>
                    113:                          <option> 4 </option>
                    114:                          <option> 5 </option>
                    115:                          <option> 6 </option>
                    116:                          <option> 7 </option>
                    117:                          <option> 8 </option>
                    118:                          <option> 9 </option>
                    119:                         </select> 
1.36      sakharuk  120:    </td>
                    121:  </tr>
                    122: </table>
                    123: </br> 
1.16      sakharuk  124: <input type="submit" value="Submit your choice">
1.52      sakharuk  125: ENDMENUOUT5
                    126: }
                    127: 
                    128: 
                    129: sub additional_class_menu {
                    130:     my $r = shift;
                    131:     $r->print(<<ENDMENUOUT1);
                    132: <input type="hidden" name="url" value="$ENV{'form.url'}">
                    133: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
                    134: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
                    135: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
                    136: <h1>Mark students which assignments you want to print</h1>
                    137: ENDMENUOUT1
                    138:     my $c = $r->connection;    
                    139:     my %cache;
1.54      sakharuk  140:     my $courseID = $ENV{'request.course.id'};
                    141:     my $classlist = &Apache::loncoursedata::DownloadClasslist($courseID,$cache{'ClasslistTimestamp'},$c);
                    142:     &Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);    
                    143:     my @all_students = split(':::',$cache{'NamesOfStudents'});
                    144:     my @active_students = ();
                    145:     foreach my $student (@all_students) {
                    146: 	if ($cache{$student.':Status'} eq 'Active') {
                    147: 	    push @active_students,$student;
                    148: 	}
1.52      sakharuk  149:     }
1.54      sakharuk  150:     my $what_to_print = '<table border="1">';    
                    151:     my $i = 0;
                    152:     foreach my $student (@active_students) {
                    153: 	$what_to_print .= '<tr><td><input type="checkbox" name="whomtoprint'.$i.'" value="'.$student.'">'.$cache{$student.':fullname'}.'</td></tr>';
                    154: #	$what_to_print .= '<tr><td><input type="checkbox" name="whomtoprint'.$i.'" value="'.$cache{$student.':fullname'}.'">'.$cache{$student.':fullname'}.'</td></tr>';
                    155: 	$i++;
1.52      sakharuk  156:     }
1.54      sakharuk  157:     $what_to_print .= '</table>';
1.52      sakharuk  158:     $r->print(<<ENDMENUOUT2);
1.54      sakharuk  159:     $what_to_print <br />
                    160: <input type="hidden" name="numberofstudents" value="$i">
1.52      sakharuk  161: <input type="hidden" name="phase" value="three">
                    162: <input type="submit" value="Submit">
                    163: ENDMENUOUT2
                    164: }
                    165: 
                    166: 
                    167: sub additional_print_menu { 
                    168:     my $r = shift;
1.54      sakharuk  169:     my $what_to_print = '';
                    170:     for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
                    171: 	$what_to_print .= '<input type="hidden" name="whomtoprint'.$i.'" value="'.$ENV{'form.whomtoprint'.$i}.'">';
                    172:     }
1.52      sakharuk  173:     $r->print(<<ENDMENUOUT);
1.54      sakharuk  174:     $what_to_print
1.52      sakharuk  175: <input type="hidden" name="url" value="$ENV{'form.url'}">
                    176: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
                    177: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
1.54      sakharuk  178: <input type="hidden" name="numberofstudents" value="$ENV{'form.numberofstudents'}">
1.52      sakharuk  179: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
                    180: Enter width of the page: <input type="text" name="width" width="10" value="9cm"> <br />
                    181: <input type="hidden" name="phase" value="four">
                    182: <input type="submit" value="Submit">
1.3       sakharuk  183: </form>
                    184: </body>
                    185: </html>
1.52      sakharuk  186: ENDMENUOUT
1.3       sakharuk  187: }
1.2       sakharuk  188: 
                    189: 
1.3       sakharuk  190: sub output_data {
                    191:     my $r = shift;
                    192:     $r->print(<<ENDPART);
                    193: <html>
                    194: <head>
                    195: <title>LON-CAPA output for printing</title>
                    196: </head>
                    197: <body bgcolor="FFFFFF">
                    198: <hr>
                    199: ENDPART
1.2       sakharuk  200: 
1.3       sakharuk  201:     my $choice = $ENV{'form.choice'};
1.16      sakharuk  202:     my $layout = $ENV{'form.layout'};
1.36      sakharuk  203:     my $numberofcolumns = $ENV{'form.numberofcolumns'};               
1.16      sakharuk  204:     my $laystyle = 'book';
1.2       sakharuk  205:     my $result = '';
1.34      sakharuk  206:     my $number_of_columns = 1;
1.36      sakharuk  207:  
1.3       sakharuk  208:     if ($choice eq 'Standard LaTeX output for current document') {
1.36      sakharuk  209:       #-- single document - problem, page, html, xml  
1.14      albertel  210:       my %moreenv;
                    211:       $moreenv{'form.grade_target'}='tex';
1.48      sakharuk  212:       if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
                    213: 	  $ENV{'form.url'}=~s/http:\/\/[^\/]+//;
                    214:       }
1.14      albertel  215:       $moreenv{'request.filename'}=$ENV{'form.url'};
                    216:       &Apache::lonnet::appenv(%moreenv);
                    217:       my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
                    218:       &Apache::lonnet::delenv('form.grade_target');
                    219:       $result .= $texversion;
1.29      sakharuk  220:       $result = &additional_cleanup($result);
1.40      sakharuk  221:       if ($ENV{'form.url'}=~m/\.page\s*$/) {
                    222: 	  ($result,$number_of_columns) = &page_cleanup($result);
                    223:       }
                    224:     } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or 
                    225:              $choice eq 'Standard LaTeX output for whole primary sequence') {
1.36      sakharuk  226:       #-- minimal sequence to which the current document belongs
                    227:         #-- where is the primary sequence containing file?
1.18      sakharuk  228: 	my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
                    229: 	$_ = $symbolic;
                    230: 	m/([^_]+)_/;
                    231: 	my $primary_sequence = '/res/'.$1;
1.36      sakharuk  232:         #-- open and analyses the primary sequence
1.18      sakharuk  233: 	my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
                    234: 	my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
                    235: 	my @master_seq = &content_map($sequencefilecontents);
1.36      sakharuk  236:         #-- produce an output string
1.18      sakharuk  237: 	for (my $i=0;$i<=$#master_seq;$i++) {
                    238: 	    $_ = $master_seq[$i];
                    239: 	    m/\"(.*)\"/;
                    240:             $_ = $1;
1.36      sakharuk  241:             my $urlp = $1;		
1.20      sakharuk  242: 	    if ($choice eq 'Standard LaTeX output for the primary sequence') {
1.36      sakharuk  243: 		if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.20      sakharuk  244: 		    my %moreenv;
                    245: 		    $moreenv{'form.grade_target'}='tex';
                    246: 		    &Apache::lonnet::appenv(%moreenv);
                    247: 		    my $texversion=&Apache::lonnet::ssi($urlp);
                    248: 		    &Apache::lonnet::delenv('form.grade_target');
                    249: 		    $result .= $texversion;        
                    250: 		}
1.53      albertel  251: 	    } elsif ($urlp =~ /\S+/) {
1.36      sakharuk  252: 		my %moreenv;
1.18      sakharuk  253: 		$moreenv{'form.grade_target'}='tex';
                    254: 		&Apache::lonnet::appenv(%moreenv);
                    255: 		my $texversion=&Apache::lonnet::ssi($urlp);
                    256: 		&Apache::lonnet::delenv('form.grade_target');
1.20      sakharuk  257: 		$result .= $texversion;    
1.16      sakharuk  258: 	    }
1.28      sakharuk  259: 	}	
                    260: 	$result = &additional_cleanup($result);
1.13      sakharuk  261:     }  elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
1.47      sakharuk  262:         # where is the main sequence of the course?
1.13      sakharuk  263: 	my $main_seq = '/res/'.$ENV{'request.course.uri'};
                    264: 	my $file=&Apache::lonnet::filelocation("",$main_seq);
                    265: 	my $filecontents=&Apache::lonnet::getfile($file);
                    266: 	my @file_seq = &content_map($filecontents);
1.48      sakharuk  267: 	for (my $iu=0;$iu<=$#file_seq;$iu++) {
                    268: 	    $file_seq[$iu]=~s/^"//;
                    269: 	    $file_seq[$iu]=~s/"$//;
1.49      sakharuk  270: 	    if ($file_seq[$iu]=~m/\S+/) {
                    271: 		$file_seq[$iu]=&Apache::lonnet::filelocation("",$file_seq[$iu]);
                    272: 	    } else {
                    273: 		$file_seq[$iu]= 'REMOVE IT PLEASE';
                    274: 	    }
1.48      sakharuk  275: 	}
                    276: 	my $i=0;
1.49      sakharuk  277:         my $limit = $#file_seq;		    
                    278:         while ($i<=$limit) {	
1.48      sakharuk  279: 	    unless ($file_seq[$i]=~m/\.(problem|page)/) {
                    280: 		if ($file_seq[$i]=~m/\.sequence/) {
                    281: 		    my $filecontents=&Apache::lonnet::getfile($file_seq[$i]);
                    282: 		    my @newfile_seq = &content_map($filecontents);
1.49      sakharuk  283: 		    for (my $iu=0;$iu<=$#newfile_seq;$iu++) {
                    284: 			$newfile_seq[$iu]=~s/^"//;
                    285: 	                $newfile_seq[$iu]=~s/"$//;
                    286: 			if ($newfile_seq[$iu]=~m/\S+/) {
                    287: 			    $newfile_seq[$iu]=&Apache::lonnet::filelocation("",$newfile_seq[$iu]);
                    288: 			} else {
                    289: 			    $newfile_seq[$iu]= 'REMOVE IT PLEASE';
                    290: 			}
                    291: 		    }
                    292: 		    splice @file_seq,$i,1,@newfile_seq;
                    293: 		    $i=0;
                    294: 		    $limit = $#file_seq;
1.48      sakharuk  295: 		} else {
1.49      sakharuk  296: 		    splice @file_seq,$i,1,'REMOVE IT PLEASE';
1.48      sakharuk  297: 		}
                    298: 	    }
                    299: 	    $i++;
                    300: 	}
                    301: 	for (my $iu=0;$iu<=$#file_seq;$iu++) {
1.49      sakharuk  302: 	    if ($file_seq[$iu]=~m/REMOVE IT PLEASE/) {
                    303: 		splice @file_seq,$iu,1;
                    304: 	    }
                    305: 	}
                    306: 	if ($file_seq[-1]=~m/REMOVE IT PLEASE/) {
                    307: 	    pop @file_seq;
1.48      sakharuk  308: 	}
1.52      sakharuk  309:         #-- produce an output string
1.49      sakharuk  310: 	for (my $i=0;$i<=$#file_seq;$i++) {
                    311:             my $urlp = $file_seq[$i];
                    312: 	    $urlp=~s/\/home\/httpd\/html//;	    
                    313:             if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) {
                    314: 		my %moreenv;
                    315: 		$moreenv{'form.grade_target'}='tex';
                    316: 		&Apache::lonnet::appenv(%moreenv);
                    317: 		my $texversion=&Apache::lonnet::ssi($urlp);
                    318: 		&Apache::lonnet::delenv('form.grade_target');
                    319: 		$result .= $texversion;        
                    320: 	    }
                    321: 	}	    
                    322: 	$result = &additional_cleanup($result);
1.52      sakharuk  323:     } elsif ($choice eq 'All class print') { 
1.54      sakharuk  324:     #-- prints assignments for whole class or for selected students  
                    325:         my (@students,@st_output) = ((),());
                    326: 	for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
                    327: 	    if ($ENV{'form.whomtoprint'.$i}=~/:/) {
                    328: 		push @students,$ENV{'form.whomtoprint'.$i};
                    329: 	    }
                    330: 	}
                    331: 	#where is the primary sequence containing current resource (the same for all students)?
                    332: 	my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
                    333: 	$symbolic =~ m/([^_]+)_/;
                    334: 	my $primary_sequence = '/res/'.$1;
                    335: 	#opens and analyses the primary sequence file, produces the array of resources
                    336: 	my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);
                    337: 	my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);
                    338: 	my @master_seq = &content_map($sequencefilecontents);
                    339:         #loop over students
                    340: 	foreach my $person (@students) {
                    341: 	    my $current_output = ''; 
                    342: 	    my ($username,$userdomain) = split /:/,$person;
                    343: 	    my $fullname = &Apache::grades::get_fullname($username,$userdomain);
                    344:             #goes through all resources, checks if they are available for current student, and produces output 
                    345: 	    foreach my $curres (@master_seq)  {
                    346: 		$curres =~ s/^"//;
                    347: 		$curres =~ s/"$//;
                    348:                 if ($curres=~/\w+/) {
                    349: 		    my $symb = &Apache::lonnet::symbread($curres);
                    350: 		    my ($map,$id,$res_url) = split(/___/,$symb);
                    351: 		    if (&Apache::lonnet::allowed('bre',$res_url)) {
                    352: 			my $rendered = &Apache::loncommon::get_student_view($symb,$username,$userdomain,
                    353:                                                                         $ENV{'request.course.id'},'tex');
                    354: 			$current_output .= $rendered;
                    355: 		    }
                    356: 		}
                    357: 	    }
                    358: 	    $current_output =~ s/\\begin{document}/\\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$fullname}}\\hskip 1\.4in } \\vskip 5 mm /;
                    359: 	    $result .= $current_output;
                    360: 	}
                    361: 
                    362: 	$result = &additional_cleanup($result);
                    363: 
                    364: 
                    365: 
1.52      sakharuk  366: 
                    367: 
                    368: 
1.31      sakharuk  369:     } elsif ($choice eq 'Subdirectory print') {      
                    370: 	my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
                    371: 	$subdirtoprint =~ s/\/[^\/]+$//;
                    372: 	my @list_of_files = ();
1.48      sakharuk  373: 	if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
1.45      sakharuk  374: 	    $subdirtoprint =~ s/^[^~]*~(\w+)\//\/home\/$1\/public_html\//;
                    375: 	} else {
                    376: 	    $subdirtoprint =~ s/.*(\/res\/)/$1/;
                    377: 	}
1.46      sakharuk  378: 	my @content_directory = ();
1.48      sakharuk  379: 	if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {
1.46      sakharuk  380: 	    @content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},'');
1.45      sakharuk  381: 	} else {
1.46      sakharuk  382: 	    @content_directory = &Apache::lonnet::dirlist($subdirtoprint);
                    383: 	}
                    384: 	for (my $iy=0;$iy<=$#content_directory;$iy++) {
                    385: 	    my @tempo_array = split(/&/,$content_directory[$iy]);
                    386: 	    if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) {
                    387: 		push(@list_of_files,$tempo_array[0]);
1.28      sakharuk  388: 	    }
1.13      sakharuk  389: 	}
1.45      sakharuk  390: 	$subdirtoprint =~ s/\/$//;
1.31      sakharuk  391: 	for (my $i=0;$i<=$#list_of_files;$i++) {
1.45      sakharuk  392: 	    my $urlp = $subdirtoprint.'/'.$list_of_files[$i];
1.31      sakharuk  393: 	    my %moreenv;
                    394: 	    $moreenv{'form.grade_target'}='tex';
                    395: 	    &Apache::lonnet::appenv(%moreenv);
1.48      sakharuk  396: 	    if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) { 
                    397: 		$urlp =~ s/\/home\/([^\/]*)\/public_html/\/~$1/; 
                    398: 	    }
1.31      sakharuk  399: 	    my $texversion=&Apache::lonnet::ssi($urlp);
                    400: 	    &Apache::lonnet::delenv('form.grade_target');
                    401: 	    $texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;
                    402: 	    $result .= $texversion;   
                    403: 	}
                    404: 	$result = &additional_cleanup($result);
                    405: 	
1.51      sakharuk  406:        	
1.7       sakharuk  407:     }
1.16      sakharuk  408: #-- corrections for the different page formats
1.36      sakharuk  409:     if ($layout eq 'CBI' and $numberofcolumns eq '1') {
                    410:     } elsif ($layout eq 'CBI' and $numberofcolumns eq '2') {
1.16      sakharuk  411: 	$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}/;
                    412:         $laystyle = 'album';
                    413:     } elsif ($layout eq 'CAPA') {
                    414:         my $courseidinfo = $ENV{'request.role'};
                    415:         $_ = $courseidinfo;
                    416:         m/.*\/(.*)/;
                    417:         $courseidinfo = $ENV{'course.physnet_'.$1.'.description'};
1.34      sakharuk  418: #	$result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass\[twocolumn\]{article}/;
                    419: 	$result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass{article}/;
                    420: 	$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  421: 	$result =~ s/\\includegraphics{/\\includegraphics\[width=9\.0 cm\]{/g;
1.37      sakharuk  422: #	$result =~ s/\\includegraphics{/\\includegraphics\[width=\\textwidth\]{/g;
                    423: #	$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  424: 	$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  425: #        $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[9\.0cm\]\[b\]{\\hrulefill})/$2$1/g;
                    426:         $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
1.34      sakharuk  427:         $result =~ s/(\\end{longtable}\s*)\\newline/$1/g;
1.37      sakharuk  428: 	$result =~ s/\$number_of_columns/$number_of_columns/g;
1.16      sakharuk  429:     }
1.52      sakharuk  430:     #changes page's parameters for the one column output 
                    431:     if ($ENV{'form.numberofcolumns'} == 1) {
                    432: 	$result =~ s/\\textwidth= 9cm/\\textwidth= $ENV{'form.width'}/;
                    433:     }
1.23      sakharuk  434: #-- LaTeX corrections     
                    435:     my $first_comment = index($result,'<!--',0);
                    436:     while ($first_comment != -1) {
                    437: 	my $end_comment = index($result,'-->',$first_comment);
                    438: 	substr($result,$first_comment,$end_comment-$first_comment+3) = '';
                    439: 	$first_comment = index($result,'<!--',$first_comment);
                    440:     }
1.17      sakharuk  441:     $result =~ s/^\s+$//gm; #remove empty lines
1.20      sakharuk  442:     $result =~ s/(\s)+/$1/g; #removes more than one empty space
1.23      sakharuk  443:     $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
1.24      sakharuk  444:     $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
1.23      sakharuk  445:     $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.24      sakharuk  446: 	$result =~ s/\\\\\s+\[/ \[/g;
                    447:     $result =~ s/&#952;/\$\\theta\$/g; #converts theta from html into tex
1.41      sakharuk  448:     $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
1.37      sakharuk  449:     #conversion of html characters to LaTeX equivalents
                    450:     if ($result =~ m/&(\w+|#\d+);/) {
                    451: 	$result = &character_chart($result);
                    452:     }
1.42      sakharuk  453:     $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
                    454:     $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
1.7       sakharuk  455: #-- writing .tex file in prtspool 
1.16      sakharuk  456:     my $temp_file;
1.33      sakharuk  457:     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
1.16      sakharuk  458:     unless ($temp_file = Apache::File->new('>'.$filename)) {
                    459: 	$r->log_error("Couldn't open $filename for output $!");
                    460: 	return SERVER_ERROR; 
                    461:     } 
                    462:     print $temp_file $result;
1.3       sakharuk  463: $r->print(<<FINALEND);
1.51      sakharuk  464: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns">
1.3       sakharuk  465: </body>
                    466: </html>
                    467: FINALEND
                    468: }
1.2       sakharuk  469: 
1.37      sakharuk  470: sub character_chart {
                    471:     my $result = shift;	
1.41      sakharuk  472:     $result =~ s/&#0?0?7;//g;
1.40      sakharuk  473:     $result =~ s/&#0?0?9;//g;
                    474:     $result =~ s/&#0?10;//g;
                    475:     $result =~ s/&#0?13;//g;
                    476:     $result =~ s/&#0?32;/ /g;
                    477:     $result =~ s/&#0?33;/!/g;
                    478:     $result =~ s/&#0?34;/"/g;
1.39      sakharuk  479:     $result =~ s/&quot;/"/g; 
1.40      sakharuk  480:     $result =~ s/&#0?35;/\\#/g;
                    481: #    $result =~ s/&#0?36;/\\\$/g;
                    482:     $result =~ s/&#0?37;/\\%/g; 
                    483:     $result =~ s/&#0?38;/\\&/g; 
1.37      sakharuk  484:     $result =~ s/&amp;/\\&/g;
1.40      sakharuk  485:     $result =~ s/&#0?39;/'/g;
                    486:     $result =~ s/&#0?40;/(/g;
                    487:     $result =~ s/&#0?41;/)/g;
                    488:     $result =~ s/&#0?42;/\*/g;
                    489:     $result =~ s/&#0?43;/\+/g;
                    490:     $result =~ s/&#0?44;/,/g;
                    491:     $result =~ s/&#0?45;/-/g;
                    492:     $result =~ s/&#0?46;/\./g;
                    493:     $result =~ s/&#0?47;/\//g;
                    494:     $result =~ s/&#0?48;/0/g;
                    495:     $result =~ s/&#0?49;/1/g;
                    496:     $result =~ s/&#0?50;/2/g;
                    497:     $result =~ s/&#0?51;/3/g;
                    498:     $result =~ s/&#0?52;/4/g;
                    499:     $result =~ s/&#0?53;/5/g;
                    500:     $result =~ s/&#0?54;/6/g;
                    501:     $result =~ s/&#0?55;/7/g;
                    502:     $result =~ s/&#0?56;/8/g;
                    503:     $result =~ s/&#0?57;/9/g;
                    504:     $result =~ s/&#0?58;/:/g;
                    505:     $result =~ s/&#0?59;/;/g;
                    506:     $result =~ s/&#0?60;/\$<\$/g;
1.37      sakharuk  507:     $result =~ s/&lt;/\$<\$/g;
1.40      sakharuk  508:     $result =~ s/&#0?61;/\$=\$/g;
                    509:     $result =~ s/&#0?62;/\$>\$/g;
1.37      sakharuk  510:     $result =~ s/&gt;/\$>\$/g;
1.40      sakharuk  511:     $result =~ s/&#0?63;/?/g;
                    512: #    $result =~ s/&#0?64;//g;
                    513:     $result =~ s/&#0?65;/A/g;
                    514:     $result =~ s/&#0?66;/B/g;
                    515:     $result =~ s/&#0?67;/C/g;
                    516:     $result =~ s/&#0?68;/D/g;
                    517:     $result =~ s/&#0?69;/E/g;
                    518:     $result =~ s/&#0?70;/F/g;
                    519:     $result =~ s/&#0?71;/G/g;
                    520:     $result =~ s/&#0?72;/H/g;
                    521:     $result =~ s/&#0?73;/I/g;
                    522:     $result =~ s/&#0?74;/J/g;
                    523:     $result =~ s/&#0?75;/K/g;
                    524:     $result =~ s/&#0?76;/L/g;
                    525:     $result =~ s/&#0?77;/M/g;
                    526:     $result =~ s/&#0?78;/N/g;
                    527:     $result =~ s/&#0?79;/O/g;
                    528:     $result =~ s/&#0?80;/P/g;
                    529:     $result =~ s/&#0?81;/Q/g;
                    530:     $result =~ s/&#0?82;/R/g;
                    531:     $result =~ s/&#0?83;/S/g;
                    532:     $result =~ s/&#0?84;/T/g;
                    533:     $result =~ s/&#0?85;/U/g;
                    534:     $result =~ s/&#0?86;/V/g;
                    535:     $result =~ s/&#0?87;/W/g;
                    536:     $result =~ s/&#0?88;/X/g;
                    537:     $result =~ s/&#0?89;/Y/g;
                    538:     $result =~ s/&#0?90;/Z/g;
                    539:     $result =~ s/&#0?91;/[/g;
                    540:     $result =~ s/&#0?92;/\\/g;
                    541:     $result =~ s/&#0?93;/]/g;
                    542: #    $result =~ s/&#0?94;//g;
                    543: #    $result =~ s/&#0?95;//g;
                    544:     $result =~ s/&#0?96;/`/g;
                    545:     $result =~ s/&#0?97;/a/g;
                    546:     $result =~ s/&#0?98;/b/g;
                    547:     $result =~ s/&#0?99;/c/g;
1.37      sakharuk  548:     $result =~ s/&#100;/d/g;
                    549:     $result =~ s/&#101;/e/g;
                    550:     $result =~ s/&#102;/f/g;
                    551:     $result =~ s/&#103;/g/g;
                    552:     $result =~ s/&#104;/h/g;
                    553:     $result =~ s/&#105;/i/g;
                    554:     $result =~ s/&#106;/j/g;
                    555:     $result =~ s/&#107;/k/g;
                    556:     $result =~ s/&#108;/l/g;
                    557:     $result =~ s/&#109;/m/g;
                    558:     $result =~ s/&#110;/n/g;
                    559:     $result =~ s/&#111;/o/g;
                    560:     $result =~ s/&#112;/p/g;
                    561:     $result =~ s/&#113;/q/g;
                    562:     $result =~ s/&#114;/r/g;
                    563:     $result =~ s/&#115;/s/g;
                    564:     $result =~ s/&#116;/t/g;
                    565:     $result =~ s/&#117;/u/g;
                    566:     $result =~ s/&#118;/v/g;
                    567:     $result =~ s/&#119;/w/g;
                    568:     $result =~ s/&#120;/x/g;
                    569:     $result =~ s/&#121;/y/g;
                    570:     $result =~ s/&#122;/z/g;
                    571:     $result =~ s/&#123;/\\{/g;
                    572:     $result =~ s/&#124;/\|/g;
                    573:     $result =~ s/&#125;/\\}/g;
                    574:     $result =~ s/&#126;/\~/g;
                    575:     $result =~ s/&#130;/,/g;
                    576: #    $result =~ s/&#131;//g;
                    577:     $result =~ s/&#132;/''/g;
                    578:     $result =~ s/&#133;/\$\\ldots\$/g;
                    579:     $result =~ s/&#134;/\$\\dagger\$/g;
                    580:     $result =~ s/&#135;/\$\\ddagger\$/g;
                    581: #    $result =~ s/&#136;//g;
                    582: #    $result =~ s/&#137;//g;
                    583: #    $result =~ s/&#138;//g;
                    584:     $result =~ s/&#139;/\$<\$/g;
                    585: #    $result =~ s/&#140;//g;
                    586:     $result =~ s/&#145;/`/g;
                    587:     $result =~ s/&#146;/'/g;
                    588:     $result =~ s/&#147;/``/g;
                    589:     $result =~ s/&#148;/''/g;
                    590:     $result =~ s/&#149;/\$\\bullet\$/g;
                    591: #    $result =~ s/&#150;//g;
                    592: #    $result =~ s/&#151;//g;
                    593:     $result =~ s/&#152;/~/g;
                    594: #    $result =~ s/&#153;//g;
                    595: #    $result =~ s/&#154;//g;
                    596:     $result =~ s/&#155;/\$>\$/g;
                    597:     $result =~ s/&#156;/\\{\\oe\\}/g;
                    598:     $result =~ s/&#159;/\\"\\{Y\\}/g;
                    599:     $result =~ s/&#160;//g;
                    600:     $result =~ s/&nbsp;//g;
                    601:     $result =~ s/&#161;/!`/g;
                    602:     $result =~ s/&iexcl;/!`/g; #`
                    603: #    $result =~ s/&#162;//g;
                    604: #    $result =~ s/&cent;//g;
                    605:     $result =~ s/&#163;/\\pounds/g; 
                    606:     $result =~ s/&pound;/\\pounds/g;
                    607: #    $result =~ s/&#164;//g;
                    608: #    $result =~ s/&curren;//g;
                    609: #    $result =~ s/&#165;//g;
                    610: #    $result =~ s/&yen;//g;
                    611: #    $result =~ s/&#166;//g;
                    612: #    $result =~ s/&brvbar;//g;
                    613: #    $result =~ s/&#167;//g;
                    614: #    $result =~ s/&sect;//g;
                    615: #    $result =~ s/&#168;//g;
                    616: #    $result =~ s/&uml;//g;
                    617:     $result =~ s/&#169;/\\copyright/g;
                    618:     $result =~ s/&copy;/\\copyright/g;
                    619: #    $result =~ s/&#170;//g;
                    620: #    $result =~ s/&ordf;//g;
                    621: #    $result =~ s/&#171;//g;
                    622: #    $result =~ s/&laquo;//g;
                    623:     $result =~ s/&#172;/\$\\neg\$/g;
                    624:     $result =~ s/&not;/\$\\neg\$/g;
                    625: #    $result =~ s/&#173;//g;
                    626: #    $result =~ s/&shy;//g;
                    627: #    $result =~ s/&#174;//g;
                    628: #    $result =~ s/&reg;//g;
                    629: #    $result =~ s/&#175;//g;
                    630: #    $result =~ s/&macr;//g;
1.42      sakharuk  631:     $result =~ s/&#176;/\$^{\\circ}\$/g;
                    632:     $result =~ s/&deg;/\$^{\\circ}\$/g;
1.37      sakharuk  633:     $result =~ s/&#177;/\$\\pm\$/g;
                    634:     $result =~ s/&plusmn;/\$\\pm\$/g;
                    635:     $result =~ s/&#178;/\$^2\$/g;
                    636:     $result =~ s/&sup2;/\$^2\$/g;
                    637:     $result =~ s/&#179;/\$^3\$/g;
                    638:     $result =~ s/&sup3;/\$^3\$/g;
                    639: #    $result =~ s/&#180;//g;
                    640: #    $result =~ s/&acute;//g;
                    641:     $result =~ s/&#181;/\$\\mu\$/g;
                    642:     $result =~ s/&micro;/\$\\mu\$/g;
                    643:     $result =~ s/&#182;/\\P/g;
                    644:     $result =~ s/&para;/\\P/g;
                    645:     $result =~ s/&#183;/\$\\cdot\$/g;
                    646:     $result =~ s/&middot;/\$\\cdot\$/g;
                    647: #    $result =~ s/&#184;//g;
                    648: #    $result =~ s/&cedil;//g;
                    649:     $result =~ s/&#185;/\$^1\$/g;
                    650:     $result =~ s/&sup1;/\$^1\$/g;
                    651: #    $result =~ s/&#186;//g;
                    652: #    $result =~ s/&ordm;//g;
                    653: #    $result =~ s/&#187;//g;
                    654: #    $result =~ s/&raquo;//g;
                    655: #    $result =~ s/&#188;//g;
                    656: #    $result =~ s/&frac14;//g;
                    657: #    $result =~ s/&#189;//g;
                    658: #    $result =~ s/&frac12;//g;
                    659: #    $result =~ s/&#190;//g;
                    660: #    $result =~ s/&frac34;//g;
                    661:     $result =~ s/&#191;/?`/g;
                    662:     $result =~ s/&iquest;/?`/g; 
                    663:     $result =~ s/&#192;/\\`{A}/g;
                    664:     $result =~ s/&Agrave;/\\`{A}/g; 
                    665:     $result =~ s/&#193;/\\'{A}/g; 
                    666:     $result =~ s/&Aacute;/\\'{A}/g; 
                    667:     $result =~ s/&#194;/\\^{A}/g;
                    668:     $result =~ s/&Acirc;/\\^{A}/g;
                    669:     $result =~ s/&#195;/\\~{A}/g;
                    670:     $result =~ s/&Atilde;/\\~{A}/g;
                    671:     $result =~ s/&#196;/\\"{A}/g; 
                    672:     $result =~ s/&Auml;/\\"{A}/g; 
                    673:     $result =~ s/&#197;/{\\AA}/g;
                    674:     $result =~ s/&Aring;/{\\AA}/g;
                    675:     $result =~ s/&#198;/{\\AE}/g;
                    676:     $result =~ s/&AElig;/{\\AE}/g;
                    677: #    $result =~ s/&#199;//g;
                    678: #    $result =~ s/&Ccedil;//g;
                    679:     $result =~ s/&#200;/\\`{E}/g;
                    680:     $result =~ s/&Egrave;/\\`{E}/g;
                    681:     $result =~ s/&#201;/\\'{E}/g;
                    682:     $result =~ s/&Eacute;/\\'{E}/g;
                    683:     $result =~ s/&#202;/\\^{E}/g;
                    684:     $result =~ s/&Ecirc;/\\^{E}/g;
                    685:     $result =~ s/&#203;/\\`{E}/g;
                    686:     $result =~ s/&Euml;/\\`{E}/g;
                    687:     $result =~ s/&#204;/\\`{I}/g;
                    688:     $result =~ s/&Igrave;/\\`{I}/g; 
                    689:     $result =~ s/&#205;/\\'{I}/g; 
                    690:     $result =~ s/&Iacute;/\\'{I}/g; 
                    691:     $result =~ s/&#206;/\\^{I}/g;
                    692:     $result =~ s/&Icirc;/\\^{I}/g;
                    693:     $result =~ s/&#207;/\\"{I}/g; 
                    694:     $result =~ s/&Iuml;/\\"{I}/g; 
                    695: #    $result =~ s/&#208;//g;
                    696: #    $result =~ s/&ETH;//g;
                    697:     $result =~ s/&#209;/\\~{N}/g;
                    698:     $result =~ s/&Ntilde;/\\~{N}/g;
                    699:     $result =~ s/&#210;/\\`{O}/g;
                    700:     $result =~ s/&Ograve;/\\`{O}/g; 
                    701:     $result =~ s/&#211;/\\'{O}/g;
                    702:     $result =~ s/&Oacute;/\\'{O}/g; 
                    703:     $result =~ s/&#212;/\\^{O}/g;
                    704:     $result =~ s/&Ocirc;/\\^{O}/g;
                    705:     $result =~ s/&#213;/\\~{O}/g;
                    706:     $result =~ s/&Otilde;/\\~{O}/g;
                    707:     $result =~ s/&#214;/\\"{O}/g;
                    708:     $result =~ s/&Ouml;/\\"{O}/g; 
                    709:     $result =~ s/&#215;/\$\\times\$/g;
                    710:     $result =~ s/&times;/\$\\times\$/g;
                    711:     $result =~ s/&#216;/{\\O}/g;
                    712:     $result =~ s/&Oslash;/{\\O}/g;
                    713:     $result =~ s/&#217;/\\`{U}/g;
                    714:     $result =~ s/&Ugrave;/\\`{U}/g;
                    715:     $result =~ s/&#218;/\\'{U}/g;
                    716:     $result =~ s/&Uacute;/\\'{U}/g;
                    717:     $result =~ s/&#219;/\\^{U}/g;
                    718:     $result =~ s/&Ucirc;/\\^{U}/g;
                    719:     $result =~ s/&#220;/\\"{U}/g;
                    720:     $result =~ s/&Uuml;/\\"{U}/g;
                    721:     $result =~ s/&#221;/\\'{Y}/g;
                    722:     $result =~ s/&Yacute;/\\'{Y}/g;
                    723: #    $result =~ s/&#222;//g;
                    724: #    $result =~ s/&THORN;//g;
                    725: #    $result =~ s/&#223;//g;
                    726: #    $result =~ s/&szlig;//g;
                    727:     $result =~ s/&#224;/\\`{a}/g;
                    728:     $result =~ s/&agrave;/\\`{a}/g;
                    729:     $result =~ s/&#225;/\\'{a}/g;
                    730:     $result =~ s/&aacute;/\\'{a}/g;
                    731:     $result =~ s/&#226;/\\^{a}/g;
                    732:     $result =~ s/&acirc;/\\^{a}/g;
                    733:     $result =~ s/&#227;/\\~{a}/g;
                    734:     $result =~ s/&atilde;/\\~{a}/g;
                    735:     $result =~ s/&#228;/\\"{a}/g;
                    736:     $result =~ s/&auml;/\\"{a}/g;
                    737:     $result =~ s/&#229;/{\\aa}/g;
                    738:     $result =~ s/&aring;/{\\aa}/g;
                    739:     $result =~ s/&#230;/{\\ae}/g;
                    740:     $result =~ s/&aelig;/{\\ae}/g;
                    741: #    $result =~ s/&#231;//g;
                    742: #    $result =~ s/&ccedil;//g;
                    743:     $result =~ s/&#232;/\\`{e}/g;
                    744:     $result =~ s/&egrave;/\\`{e}/g;
                    745:     $result =~ s/&#233;/\\'{e}/g;
                    746:     $result =~ s/&eacute;/\\'{e}/g;
                    747:     $result =~ s/&#234;/\\^{e}/g;
                    748:     $result =~ s/&ecirc;/\\^{e}/g;
                    749:     $result =~ s/&#235;/\\"{e}/g;
                    750:     $result =~ s/&euml;/\\"{e}/g;
                    751:     $result =~ s/&#236;/\\`{i}/g;
                    752:     $result =~ s/&igrave;/\\`{i}/g;
                    753:     $result =~ s/&#237;/\\'{i}/g;
                    754:     $result =~ s/&iacute;/\\'{i}/g;
                    755:     $result =~ s/&#238;/\\^{i}/g;
                    756:     $result =~ s/&icirc;/\\^{i}/g;
                    757:     $result =~ s/&#239;/\\"{i}/g;
                    758:     $result =~ s/&iuml;/\\"{i}/g;
                    759: #    $result =~ s/&#240;//g;
                    760: #    $result =~ s/&eth;//g;
                    761:     $result =~ s/&#241;/\\~{n}/g;
                    762:     $result =~ s/&ntilde;/\\~{n}/g;
                    763:     $result =~ s/&#242;/\\`{o}/g;
                    764:     $result =~ s/&ograve;/\\`{o}/g;
                    765:     $result =~ s/&#243;/\\'{o}/g;
                    766:     $result =~ s/&oacute;/\\'{o}/g;
                    767:     $result =~ s/&#244;/\\^{o}/g;
                    768:     $result =~ s/&ocirc;/\\^{o}/g;
                    769:     $result =~ s/&#245;/\\~{o}/g;
                    770:     $result =~ s/&otilde;/\\~{o}/g;
                    771:     $result =~ s/&#246;/\\"{o}/g;
                    772:     $result =~ s/&ouml;/\\"{o}/g;
                    773:     $result =~ s/&#247;/\$\\div\$/g;
                    774:     $result =~ s/&divide;/\$\\div\$/g;
                    775:     $result =~ s/&#248;/{\\o}/g;
                    776:     $result =~ s/&oslash;/{\\o}/g;
                    777:     $result =~ s/&#249;/\\`{u}/g; 
                    778:     $result =~ s/&ugrave;/\\`{u}/g;
                    779:     $result =~ s/&#250;/\\'{u}/g;
                    780:     $result =~ s/&uacute;/\\'{u}/g;
                    781:     $result =~ s/&#251;/\\^{u}/g;
                    782:     $result =~ s/&ucirc;/\\^{u}/g;
                    783:     $result =~ s/&#252;/\\"{u}/g;
                    784:     $result =~ s/&uuml;/\\"{u}/g;
                    785:     $result =~ s/&#253;/\\'{y}/g;
                    786:     $result =~ s/&yacute;/\\'{y}/g;
                    787: #    $result =~ s/&#254;//g;
                    788: #    $result =~ s/&thorn;//g;
                    789:     $result =~ s/&#255;/\\"{y}/g;
                    790:     $result =~ s/&yuml;/\\"{y}/g;
                    791:     return $result;
                    792: }
1.41      sakharuk  793: 
                    794: 
                    795: #'"`
1.37      sakharuk  796: 
1.28      sakharuk  797: sub additional_cleanup {
                    798:     my $result = shift;	
                    799:     my $first_app = index($result,'\documentclass',0);
                    800:     $first_app = index($result,'\documentclass',$first_app+5);
                    801:     while ($first_app != -1) {
                    802: 	my $second_app = index($result,'begin{document}',$first_app);
                    803: 	$first_app = rindex($result,'\end{document}',$first_app);
                    804: 	substr($result,$first_app,$second_app-$first_app+15) = '\vskip 3 mm';
                    805: 	$first_app = index($result,'\documentclass',$first_app+5);
                    806:     }
                    807:     return $result;
                    808: }
1.33      sakharuk  809: sub page_cleanup {
                    810:     my $result = shift;	
                    811:     $_ = $result;
                    812:     m/\\end{document}(\d*)$/;
1.34      sakharuk  813:     my $number_of_columns = $1;
1.33      sakharuk  814:     my $insert = '{';
1.34      sakharuk  815:     for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33      sakharuk  816:     $insert .= '}';
1.34      sakharuk  817:     $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE/$1$insert/g;
                    818:     $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
                    819:     $result =~ s/(\\vskip\s*\d+\s*mm)/}\\\\\\parbox{\\minipagewidth}{/g;
1.35      sakharuk  820:     $result =~ s/\\parbox{\\minipagewidth}{}\s*\\\\\s*(\\parbox{\\minipagewidth})/$1/g;
1.37      sakharuk  821:     $result =~ s/\\parbox{\\minipagewidth}{\s*\\\\\\\\/\\parbox{\\minipagewidth}{/g;
1.34      sakharuk  822:     return $result,$number_of_columns;
1.33      sakharuk  823: }
1.6       sakharuk  824: 
1.3       sakharuk  825: sub content_map {
1.7       sakharuk  826: #-- find a list of files to print
1.3       sakharuk  827:     my $map_string = shift;
1.5       sakharuk  828:     my @number_seq = ();
1.7       sakharuk  829:     my @file_seq = ();
1.5       sakharuk  830:     my $startlink = index($map_string,'<link',0);
1.7       sakharuk  831:     my $endlink = index($map_string,'</link>',$startlink);
                    832:     my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    833:     $_ = $chunk;
                    834:     m/from=\"(\d+)\"/;
                    835:     push @number_seq,$1;
1.5       sakharuk  836:     while ($startlink != -1) {
1.7       sakharuk  837: 	$endlink = index($map_string,'</link>',$startlink);
                    838: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
1.5       sakharuk  839: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    840: 	$_ = $chunk;
                    841:         m/to=\"(\d+)\"/;
                    842: 	push @number_seq,$1;
1.44      sakharuk  843: 	$startlink = index($map_string,'from="'.$1.'"',0);
1.18      sakharuk  844: 	$startlink = rindex($map_string,'<link ',$startlink);
1.5       sakharuk  845:     }
1.45      sakharuk  846:     my $stalink = index($map_string,' to="'.$number_seq[0].'"',0);
1.7       sakharuk  847:     while ($stalink != -1) {
                    848: 	$startlink = rindex($map_string,'<link ',$stalink);
                    849: 	$endlink = index($map_string,'</link>',$startlink);
                    850: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+7);
                    851: 	substr($map_string,$startlink,$endlink-$startlink+7) = '';
                    852: 	$_ = $chunk;
                    853:         m/from=\"(\d+)\"/;
                    854: 	unshift @number_seq,$1;
                    855: 	$stalink = index($map_string,' to="'.$number_seq[0].'"',0);
                    856:     }
                    857:     for (my $i=0;$i<=$#number_seq;$i++) {
                    858: 	$stalink = index($map_string,' id="'.$number_seq[$i].'"',0);
1.13      sakharuk  859:         {    
                    860: 	    my $ahed1 = index($map_string,'src="',$stalink);
                    861: 	    my $ahed2 = index($map_string,'</resource>',$stalink);
                    862: 	    if ($ahed1 != -1) {
                    863: 		if ($ahed1 < $ahed2) {
                    864: 		    $startlink = $ahed1;
                    865: 		} else {
                    866: 		    $startlink = rindex($map_string,'src="',$stalink);
                    867: 		}
                    868: 	    } else {
                    869: 		$startlink = rindex($map_string,'src="',$stalink);
                    870: 	    }
                    871: 
                    872: 	}
1.7       sakharuk  873: 	$startlink = index($map_string,'"',$startlink);
                    874: 	$endlink = index($map_string,'"',$startlink+1);
                    875: 	$chunk = substr($map_string,$startlink,$endlink-$startlink+1);
                    876: 	push @file_seq,$chunk;
                    877:     }
                    878:     return @file_seq;
                    879: }
1.5       sakharuk  880: 
1.3       sakharuk  881: 
                    882: 
                    883: sub handler {
                    884: 
                    885:     my $r = shift;
                    886:     $r->content_type('text/html');
                    887:     $r->send_http_header;
                    888: 
                    889: #-- start form
                    890:     &headerform($r);
                    891: #-- menu for output
1.16      sakharuk  892:     unless  ($ENV{'form.phase'}) {
1.3       sakharuk  893: 	&menu_for_output($r);
                    894:     }
1.52      sakharuk  895: #-- additional menu for class printing
                    896:      if ($ENV{'form.phase'} eq 'two') {
                    897: 	 if($ENV{'form.choice'} eq 'All class print') {
                    898: 	     &additional_class_menu($r);
                    899: 	 } else {
                    900: 	     $ENV{'form.phase'} = 'three';
                    901: 	 }
                    902:      }
                    903: #-- additional menu for page layout (one column case)
                    904:     if ($ENV{'form.phase'} eq 'three') {
                    905: 	if($ENV{'form.numberofcolumns'} == 1) {
                    906: 	    &additional_print_menu($r);
                    907: 	} else {
                    908: 	    $ENV{'form.phase'} = 'four';
                    909: 	}
                    910:     }
1.3       sakharuk  911: #-- core part 
1.52      sakharuk  912:     if ($ENV{'form.phase'} eq 'four') {
1.3       sakharuk  913: 	&output_data($r);
                    914:     }
1.2       sakharuk  915:     return OK;
                    916: 
1.1       www       917: } 
                    918: 
                    919: 1;
                    920: __END__
1.6       sakharuk  921: 
                    922: 
1.13      sakharuk  923: 
                    924: 
                    925: #### Test block
1.6       sakharuk  926: #    my $ere;
                    927: #    foreach $ere (%ENV) {
1.13      sakharuk  928: #	$result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";
1.6       sakharuk  929: #    }
1.13      sakharuk  930: ####

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>