File:  [LON-CAPA] / loncom / interface / lonprintout.pm
Revision 1.56: download - view: text, annotated - select for diffs
Fri Sep 6 17:46:13 2002 UTC (21 years, 9 months ago) by sakharuk
Branches: MAIN
CVS tags: HEAD
Small correction for printing assignments for the students (Ed wanted).

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

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