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

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

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