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

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

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