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

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

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