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

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

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