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

1.1       www         1: # The LearningOnline Network
                      2: # Printout
                      3: #
1.120   ! sakharuk    4: # $Id: lonprintout.pm,v 1.119 2003/02/20 22:11:42 bowersj2 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.68      sakharuk   51: use Apache::lonnavmaps;
1.34      sakharuk   52: use POSIX qw(strftime);
1.60      sakharuk   53: use GDBM_File;
                     54: 
                     55: 
                     56: my %hash;
1.76      sakharuk   57: my $LaTeXwidth = 0;
1.3       sakharuk   58: 
                     59: sub headerform {
1.1       www        60:     my $r = shift;
1.3       sakharuk   61:     $r->print(<<ENDHEADER);
                     62: <html>
                     63: <head>
                     64: <title>LON-CAPA output for printing</title>
                     65: </head>
                     66: <body bgcolor="FFFFFF">
                     67: <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">
                     68: ENDHEADER
1.100     albertel   69: 
                     70:     if ($ENV{'form.postdata'}=~m|^/res/|) {
                     71: 	$r->print(<<ENDHEADER1);
1.62      sakharuk   72: <b>Path to current document: </b><tt>$ENV{'form.postdata'}</tt><p>
                     73: ENDHEADER1
1.100     albertel   74:     }
1.3       sakharuk   75: }
                     76: 
1.1       www        77: 
1.3       sakharuk   78: sub menu_for_output {
                     79:     my $r = shift;
1.62      sakharuk   80:     my ($title_for_single_resource,$title_for_sequence,$title_for_main_map) = &details_for_menu;
1.83      sakharuk   81:     my $assignment = $title_for_sequence;
1.60      sakharuk   82:     if ($title_for_single_resource ne '') {$title_for_single_resource = '"'.$title_for_single_resource.'"';}
                     83:     if ($title_for_sequence ne '') {$title_for_sequence = '"'.$title_for_sequence.'"';}
1.62      sakharuk   84:     if ($title_for_main_map ne '') {$title_for_main_map = '"'.$title_for_main_map.'"';}
1.100     albertel   85:     $ENV{'form.postdata'} =~ s|http://[^/]+||;
1.62      sakharuk   86:     my $subdir_to_print = $ENV{'form.postdata'};
                     87:     $subdir_to_print =~ m/\/([^\/]+)$/;
1.100     albertel   88:     $subdir_to_print =~ s/\Q$1\E//;
1.28      sakharuk   89:     $r->print(<<ENDMENUOUT1);
1.57      sakharuk   90: <h1>What do you want to print? Make a choice.</h1><br />
1.3       sakharuk   91: <input type="hidden" name="phase" value="two">
1.10      albertel   92: <input type="hidden" name="url" value="$ENV{'form.postdata'}">
1.83      sakharuk   93: <input type="hidden" name="assignment" value="$assignment">
1.60      sakharuk   94: <input type="radio" name="choice" value="Standard LaTeX output for current document" checked>  Current document <b>$title_for_single_resource</b>
1.65      sakharuk   95: (prints what you just saw on the screen)<br />
1.39      sakharuk   96: ENDMENUOUT1
1.87      sakharuk   97:     if ($ENV{'form.postdata'}=~/\/res\//) {
1.52      sakharuk   98: 	$r->print(<<ENDMENUOUT2);
1.88      sakharuk   99: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence">  Problem(s) from <b>$title_for_sequence</b><br />
                    100: <input type="radio" name="choice" value="Standard LaTeX output for whole primary sequence">  Problem(s) plus page(s) or html/xml file(s) from <b>$title_for_sequence</b><br />
1.28      sakharuk  101: ENDMENUOUT2
1.44      sakharuk  102:     }
1.87      sakharuk  103:     if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($ENV{'form.postdata'}=~/\/res\//)) { 
1.52      sakharuk  104: 	$r->print(<<ENDMENUOUT6);
1.62      sakharuk  105: <input type="radio" name="choice" value="Standard LaTeX output for the top level sequence">  All problems in this course (<b>warning:</b> this may be time consuming) <br />
1.59      sakharuk  106: <br />
1.63      albertel  107: <input type="radio" name="choice" value="All class print">  All problems from <b>$title_for_sequence</b> for selected students<br /><br />
1.52      sakharuk  108: ENDMENUOUT6
                    109:     }
1.39      sakharuk  110:       my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
                    111:       $subdirtoprint =~ s/\/[^\/]+$//;
1.93      sakharuk  112:       if ((&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') and ($ENV{'form.postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) {
1.39      sakharuk  113: 	  $r->print(<<ENDMENUOUT4);
1.62      sakharuk  114:   <input type="radio" name="choice" value="Subdirectory print">  Problems from current subdirectory <b>$subdir_to_print</b><br />
1.39      sakharuk  115: ENDMENUOUT4
                    116:       }
                    117:     $r->print(<<ENDMENUOUT5);
1.16      sakharuk  118: <br /><hr /><br />
                    119: <h1>And what page format do you prefer?</h1>
1.36      sakharuk  120: <table>
                    121:  <tr>
                    122:    <td>
                    123:      <input type="radio" name="layout" value="CBI"> Landscape <br />
                    124:      <input type="radio" name="layout" value="CAPA" checked>  Portrait <br />
                    125:    </td>
                    126:    <td>&nbsp;</td>
                    127:    <td rawspan="2">
1.44      sakharuk  128:      Number of columns: <select name="numberofcolumns">
1.59      sakharuk  129:                          <option> 1 </option>
                    130:                          <option selected> 2 </option>
1.44      sakharuk  131:                         </select> 
1.36      sakharuk  132:    </td>
1.59      sakharuk  133:    <td rawspan="2">
                    134:      Paper size (format [width x height]): <select name="papersize">
1.62      sakharuk  135:                                             <option selected> Letter [8 1/2x11 in] </option>
                    136:                                             <option> Legal [8 1/2x14 in] </option>
                    137:                                             <option> Ledger/Tabloid [11x17 in] </option>
                    138:                                             <option> Executive [7 1/2x10 in] </option>
1.59      sakharuk  139:                                             <option> A2 [420x594 mm] </option>
                    140:                                             <option> A3 [297x420 mm] </option>
                    141:                                             <option> A4 [210x297 mm] </option>
                    142:                                             <option> A5 [148x210 mm] </option>
                    143:                                             <option> A6 [105x148 mm] </option>
                    144:                                            </select> 
                    145:    </td>
1.36      sakharuk  146:  </tr>
1.112     sakharuk  147: 
1.36      sakharuk  148: </table>
                    149: </br> 
1.16      sakharuk  150: <input type="submit" value="Submit your choice">
1.52      sakharuk  151: ENDMENUOUT5
                    152: }
                    153: 
                    154: 
1.88      sakharuk  155: sub sequence_content_menu {
                    156:     my ($key_to,$r) = @_;
1.101     sakharuk  157:     my $primary_sequence;
1.88      sakharuk  158:     my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
                    159:     my @sequence = split('___',$symbolic);
1.101     sakharuk  160:     if ($sequence[0]=~/^uploaded/) {$primary_sequence = '/'.$sequence[0];} 
                    161:       else {$primary_sequence = '/res/'.$sequence[0];} 
1.112     sakharuk  162:     my @master_seq = &coming_from_hash($primary_sequence);
                    163:     my @titles_master_seq = (); 
                    164:     for (my $i=0;$i<=$#master_seq;$i++) {
                    165: 	my ($path,$title,$symb) = split /&&/,$master_seq[$i];
                    166: 	$master_seq[$i] = $path.'&&'.$symb;
                    167:         push @titles_master_seq,  $title;
                    168:     }
1.105     sakharuk  169:     my @master_seq_view = @master_seq;
1.107     sakharuk  170:     if ($ENV{'user.adv'}) {
1.106     sakharuk  171:       for (my $i=0;$i<=$#master_seq_view;$i++) {
                    172: 	 $master_seq_view[$i]=~/___\d+___(.+)$/;
                    173: 	 $master_seq_view[$i]='/'.$1;
                    174:       }
                    175:     } else {
                    176:       for (my $i=0;$i<=$#master_seq_view;$i++) {
1.107     sakharuk  177:          $master_seq_view[$i]=' ';
1.106     sakharuk  178:       }
1.88      sakharuk  179:     }
                    180:     $r->print(<<ENDMENUOUT1);
                    181: <input type="hidden" name="url" value="$ENV{'form.url'}">
                    182: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
                    183: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
                    184: <input type="hidden" name="papersize" value="$ENV{'form.papersize'}">
1.93      sakharuk  185: <input type="hidden" name="assignment" value="$ENV{'form.assignment'}">
1.88      sakharuk  186: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
                    187: <h1>Mark item(s) which you want to print</h1>
                    188: <script>
                    189:     function checkall() {
                    190: 	for (i=0; i<document.forms.printform.elements.length; i++) {
1.112     sakharuk  191:             if (document.forms.printform.elements[i].name.indexOf('whatfile')==0) {
1.88      sakharuk  192: 	      document.forms.printform.elements[i].checked=true;
                    193:             }
                    194:         }
                    195:     }
                    196:     function uncheckall() {
                    197: 	for (i=0; i<document.forms.printform.elements.length; i++) {
                    198:             if 
                    199:           (document.forms.printform.elements[i].name.indexOf('whatfile')==0) {
                    200: 	      document.forms.printform.elements[i].checked=false;
                    201:             }
                    202:         }
                    203:     }
                    204: </script>
1.120   ! sakharuk  205: <b>
1.88      sakharuk  206: <input type=button onClick="checkall()" value="Check All">&nbsp;
1.106     sakharuk  207: <input type=button onClick="uncheckall()" value="Uncheck">&nbsp;
                    208: <input type="submit" value="Submit">
1.88      sakharuk  209: <p>
                    210: ENDMENUOUT1
                    211:     my $inc=0; 
                    212:     for (my $i=0;$i<=$#master_seq_view;$i++) {
1.106     sakharuk  213:       if ($key_to==1 && $master_seq[$i]=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
                    214: 	$r->print('<br /><input type=checkbox name="whatfile'.$inc.'" value="'.$master_seq[$i].'"> '."\n".'<b>'.
                    215:                   $titles_master_seq[$i].'</b>&nbsp;&nbsp;&nbsp;<small>'.$master_seq_view[$i].'</small>');
1.88      sakharuk  216:         $inc++;
1.106     sakharuk  217:     } elsif ($key_to==0 && $master_seq[$i]=~/\.(problem|exam|quiz|assess|survey|form|library|xml|htm|html|page)$/) {
                    218: 	$r->print('<br /><input type=checkbox name="whatfile'.$inc.'" value="'.$master_seq[$i].'"> '."\n".'<b>'.
                    219:                   $titles_master_seq[$i].'</b>&nbsp;&nbsp;&nbsp;<small>'.$master_seq_view[$i].'</small>');
1.88      sakharuk  220:         $inc++;
                    221:       }
                    222:     }
                    223:     $r->print(<<ENDMENUOUT2);
1.107     sakharuk  224: <br /><br />
1.88      sakharuk  225: <input type="hidden" name="numberoffiles" value="$inc">
                    226: <input type="hidden" name="phase" value="three">
1.107     sakharuk  227: <input type=button onClick="checkall()" value="Check All">&nbsp;
                    228: <input type=button onClick="uncheckall()" value="Uncheck">&nbsp;
1.88      sakharuk  229: <input type="submit" value="Submit">
                    230: ENDMENUOUT2
                    231: 
                    232: }
                    233: 
                    234: 
1.58      sakharuk  235: sub problem_choice_menu {
                    236:     my $r = shift;
                    237:     my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
                    238:     $subdirtoprint =~ s/\/[^\/]+$//;
                    239:     my @list_of_files = ();
                    240:     my @content_directory = ();
1.119     bowersj2  241:     $r->print("Subdir: " . $subdirtoprint . "<br />");
1.100     albertel  242:     if ($subdirtoprint =~ m|/home/([^/]+)/public_html|) {
                    243: 	#localmachine CSTR space
                    244: 	my $user=$1;
                    245: 	my $domain=$Apache::lonnet::perlvar{'lonDefDomain'};
                    246: 	@content_directory = &Apache::lonnet::dirlist($subdirtoprint,
                    247: 						      $domain, $user,'');
1.58      sakharuk  248:     } else {
1.109     sakharuk  249:         #local library server res space (allows to print only from the own library server)
                    250: 	@content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},'');
1.58      sakharuk  251:     }
                    252:     for (my $iy=0;$iy<=$#content_directory;$iy++) {
                    253: 	my @tempo_array = split(/&/,$content_directory[$iy]);
                    254: 	if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) {
                    255: 	    push(@list_of_files,$tempo_array[0]);
                    256: 	}
                    257:     }
                    258:     $subdirtoprint =~ s/\/$//;
                    259:     for (my $i=0;$i<=$#list_of_files;$i++) {
                    260: 	$list_of_files[$i] = $subdirtoprint.'/'.$list_of_files[$i];
                    261:     }
                    262:     $r->print(<<ENDMENUOUT1);
                    263: <input type="hidden" name="url" value="$ENV{'form.url'}">
                    264: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
                    265: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
                    266: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
                    267: <h1>Mark problems which you want to print</h1>
                    268: <script>
                    269:     function checkall() {
                    270: 	for (i=0; i<document.forms.printform.elements.length; i++) {
                    271:             if 
                    272:           (document.forms.printform.elements[i].name.indexOf('whattoprint')==0) {
                    273: 	      document.forms.printform.elements[i].checked=true;
                    274:             }
                    275:         }
                    276:     }
                    277: 
                    278: 
                    279:     function uncheckall() {
                    280: 	for (i=0; i<document.forms.printform.elements.length; i++) {
                    281:             if 
                    282:           (document.forms.printform.elements[i].name.indexOf('whattoprint')==0) {
                    283: 	      document.forms.printform.elements[i].checked=false;
                    284:             }
                    285:         }
                    286:     }
                    287: </script>
1.60      sakharuk  288: <input type=button onClick="checkall()" value="Check All">&nbsp;
1.107     sakharuk  289: <input type=button onClick="uncheckall()" value="Uncheck">&nbsp;
                    290: <input type="submit" value="Submit">
1.58      sakharuk  291: <p>
                    292: ENDMENUOUT1
1.82      sakharuk  293:     my $i=0;
1.102     sakharuk  294:     foreach my $file (sort @list_of_files) {
1.58      sakharuk  295: 	$r->print('<br /><input type=checkbox name="whattoprint'.$i.'" value="'.$file.'"> '.
                    296:                   $file);
                    297: 	$i++;
                    298:     }
                    299:     $r->print(<<ENDMENUOUT2);
1.107     sakharuk  300: <br /><br />
1.88      sakharuk  301: <input type="hidden" name="papersize" value="$ENV{'form.papersize'}">
1.58      sakharuk  302: <input type="hidden" name="numberofproblems" value="$i">
                    303: <input type="hidden" name="phase" value="three">
1.107     sakharuk  304: <input type=button onClick="checkall()" value="Check All">&nbsp;
                    305: <input type=button onClick="uncheckall()" value="Uncheck">&nbsp;
1.58      sakharuk  306: <input type="submit" value="Submit">
                    307: ENDMENUOUT2
                    308: }
                    309: 
                    310: 
1.52      sakharuk  311: sub additional_class_menu {
                    312:     my $r = shift;
                    313:     $r->print(<<ENDMENUOUT1);
                    314: <input type="hidden" name="url" value="$ENV{'form.url'}">
                    315: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
                    316: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
                    317: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
1.83      sakharuk  318: <input type="hidden" name="assignment" value="$ENV{'form.assignment'}">
1.78      sakharuk  319: <h1>Select student(s) whose assignment you want to print</h1>
1.52      sakharuk  320: ENDMENUOUT1
1.57      sakharuk  321:     my %courselist=&Apache::lonnet::dump(
                    322:                    'classlist',
                    323: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                    324: 		   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                    325:     my $now=time;
                    326:     $r->print(<<ENDDISHEADER);
                    327: <script>
                    328:     function checkall() {
                    329: 	for (i=0; i<document.forms.printform.elements.length; i++) {
                    330:             if 
                    331:           (document.forms.printform.elements[i].name.indexOf('whomtoprint')==0) {
                    332: 	      document.forms.printform.elements[i].checked=true;
                    333:             }
                    334:         }
                    335:     }
                    336: 
                    337:     function checksec() {
                    338: 	for (i=0; i<document.forms.printform.elements.length; i++) {
                    339:             if 
                    340:           (document.forms.printform.elements[i].value.indexOf
                    341:            (document.forms.printform.chksec.value)==0) {
                    342: 	      document.forms.printform.elements[i].checked=true;
                    343:             }
                    344:         }
                    345:     }
                    346: 
                    347:     function uncheckall() {
                    348: 	for (i=0; i<document.forms.printform.elements.length; i++) {
                    349:             if 
                    350:           (document.forms.printform.elements[i].name.indexOf('whomtoprint')==0) {
                    351: 	      document.forms.printform.elements[i].checked=false;
                    352:             }
                    353:         }
1.52      sakharuk  354:     }
1.57      sakharuk  355: </script>
1.60      sakharuk  356: <input type=button onClick="checkall()" value="Check All">&nbsp;
1.99      albertel  357: <input type=button onClick="checksec()" value="Type Section/Group then click">
1.57      sakharuk  358: <input type=text size=5 name=chksec>&nbsp;
1.60      sakharuk  359: <input type=button onClick="uncheckall()" value="Uncheck">
1.57      sakharuk  360: <p>
                    361: ENDDISHEADER
1.54      sakharuk  362:     my $i = 0;
1.57      sakharuk  363:     foreach (sort keys %courselist) {
                    364:         my ($end,$start)=split(/\:/,$courselist{$_});
                    365:         my $active=1;
                    366:         if (($end) && ($now>$end)) { $active=0; }
                    367:         if ($active) {
                    368:            my ($sname,$sdom)=split(/\:/,$_);
                    369:            my %reply=&Apache::lonnet::get('environment',
                    370:               ['firstname','middlename','lastname','generation'],
                    371:               $sdom,$sname);
                    372:            my $section=&Apache::lonnet::usection
                    373: 	       ($sdom,$sname,$ENV{'request.course.id'});
                    374:            $r->print(
                    375:         '<br /><input type=checkbox name="whomtoprint'.$i.'" value="'.$section.':'.$_.'"> '.
                    376: 		      $reply{'firstname'}.' '. 
                    377:                       $reply{'middlename'}.' '.
                    378:                       $reply{'lastname'}.' '.
                    379:                       $reply{'generation'}.
                    380:                       ' ('.$_.') '.$section);
                    381: 	   $i++;
                    382:         } 
1.52      sakharuk  383:     }
                    384:     $r->print(<<ENDMENUOUT2);
1.117     sakharuk  385: <br /><br /><br />
                    386: <table><tr><td width=300>Number of blank pages added to each student assignments to print these assignments on physically different sheets (<b>requires manual addjustment</b>): <select name="addedpages"><option selected>0</option>
                    387:                                                                             <option>1</option>
                    388:                                                                             <option>2</option>
                    389:                                                                             <option>3</option>
                    390:                                                   </select></td></tr></table>
1.90      sakharuk  391: <br /> 
1.76      sakharuk  392: <input type="hidden" name="papersize" value="$ENV{'form.papersize'}">
1.54      sakharuk  393: <input type="hidden" name="numberofstudents" value="$i">
1.52      sakharuk  394: <input type="hidden" name="phase" value="three">
                    395: <input type="submit" value="Submit">
                    396: ENDMENUOUT2
                    397: }
                    398: 
                    399: 
                    400: sub additional_print_menu { 
                    401:     my $r = shift;
1.54      sakharuk  402:     my $what_to_print = '';
                    403:     for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
                    404: 	$what_to_print .= '<input type="hidden" name="whomtoprint'.$i.'" value="'.$ENV{'form.whomtoprint'.$i}.'">';
                    405:     }
1.58      sakharuk  406:     for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) {
                    407: 	$what_to_print .= '<input type="hidden" name="whattoprint'.$i.'" value="'.$ENV{'form.whattoprint'.$i}.'">';
                    408:     }
1.88      sakharuk  409:     for (my $i=0; $i<$ENV{'form.numberoffiles'};$i++) {
                    410: 	$what_to_print .= '<input type="hidden" name="whatfile'.$i.'" value="'.$ENV{'form.whatfile'.$i}.'">';
                    411:     }
1.52      sakharuk  412:     $r->print(<<ENDMENUOUT);
1.54      sakharuk  413:     $what_to_print
1.52      sakharuk  414: <input type="hidden" name="url" value="$ENV{'form.url'}">
                    415: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
                    416: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
1.76      sakharuk  417: <input type="hidden" name="papersize" value="$ENV{'form.papersize'}">
1.54      sakharuk  418: <input type="hidden" name="numberofstudents" value="$ENV{'form.numberofstudents'}">
1.58      sakharuk  419: <input type="hidden" name="numberofproblems" value="$ENV{'form.numberofproblems'}">
1.88      sakharuk  420: <input type="hidden" name="numberoffiles" value="$ENV{'form.numberoffiles'}">
1.52      sakharuk  421: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
1.83      sakharuk  422: <input type="hidden" name="assignment" value="$ENV{'form.assignment'}">
1.90      sakharuk  423: <input type="hidden" name="addedpages" value="$ENV{'form.addedpages'}">
1.73      sakharuk  424: Define one column layout parameters: <br />
1.57      sakharuk  425: <b>Width</b>: <input type="text" name="width" width="8" value="9cm"> <br />
                    426: <b>Height</b>: <input type="text" name="height" width="8" value="25.9cm"> <br />
                    427: <b>Left margin</b>: <input type="text" name="leftmargin" width="8" value="-0.57in"> <br />
1.52      sakharuk  428: <input type="hidden" name="phase" value="four">
                    429: <input type="submit" value="Submit">
1.3       sakharuk  430: </form>
                    431: </body>
                    432: </html>
1.52      sakharuk  433: ENDMENUOUT
1.3       sakharuk  434: }
1.2       sakharuk  435: 
                    436: 
1.3       sakharuk  437: sub output_data {
                    438:     my $r = shift;
                    439:     $r->print(<<ENDPART);
                    440: <html>
                    441: <head>
                    442: <title>LON-CAPA output for printing</title>
                    443: </head>
                    444: <body bgcolor="FFFFFF">
                    445: <hr>
                    446: ENDPART
1.2       sakharuk  447: 
1.3       sakharuk  448:     my $choice = $ENV{'form.choice'};
1.16      sakharuk  449:     my $layout = $ENV{'form.layout'};
1.74      sakharuk  450:     my $numberofcolumns = $ENV{'form.numberofcolumns'};  
                    451:     my $papersize = $ENV{'form.papersize'};          
1.16      sakharuk  452:     my $laystyle = 'book';
1.83      sakharuk  453:     my $assignment =  $ENV{'form.assignment'};
1.82      sakharuk  454:     if ($choice eq 'Subdirectory print') {
1.89      sakharuk  455: 	if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';}
                    456: 	if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';}
                    457: 	if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;}
1.82      sakharuk  458:     }
1.100     albertel  459:     if (($choice eq 'Standard LaTeX output for current document') &&
                    460: 	($ENV{'form.url'}=~m|^/~|)) {
1.89      sakharuk  461: 	if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';}
                    462: 	if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';}
                    463: 	if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;}
1.82      sakharuk  464:     }
1.2       sakharuk  465:     my $result = '';
1.71      sakharuk  466:     my $number_of_columns = 1; #used only for pages to determine the width of the cell
1.59      sakharuk  467:     my $selectionmade = '';
1.76      sakharuk  468:     my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns);
1.104     sakharuk  469:     if ($numberofcolumns == 1) {
                    470: 	$textwidth=$ENV{'form.width'};
                    471: 	$textheight=$ENV{'form.height'};
                    472:     }
                    473:     my $LaTeXwidth; 
1.76      sakharuk  474:     if ($textwidth=~/(\d+\s*cm)/) {
                    475: 	$LaTeXwidth = $1*10;
                    476:     } elsif ($textwidth=~/(\d+\s*mm)/) {
                    477: 	$LaTeXwidth = $1;
                    478:     }
1.3       sakharuk  479:     if ($choice eq 'Standard LaTeX output for current document') {
1.109     sakharuk  480:       #-- single document - problem, page, html, xml, ...  
1.59      sakharuk  481:       $selectionmade = 1;
1.92      sakharuk  482:       if ($ENV{'form.url'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
                    483:         my %moreenv;
                    484:         $moreenv{'form.grade_target'}='tex';
                    485:         if (&Apache::lonnet::allowed('bre',$ENV{'form.url'})) {
1.48      sakharuk  486: 	  $ENV{'form.url'}=~s/http:\/\/[^\/]+//;
1.92      sakharuk  487:         }
                    488:         $moreenv{'request.filename'}=$ENV{'form.url'};
                    489:         $moreenv{'form.textwidth'}=$LaTeXwidth;
                    490:         &Apache::lonnet::appenv(%moreenv);
                    491:         my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
                    492:         &Apache::lonnet::delenv('form.grade_target','form.textwidth','form.counter');
                    493:         $result .= $texversion;
                    494:         if ($ENV{'form.url'}=~m/\.page\s*$/) {
1.40      sakharuk  495: 	  ($result,$number_of_columns) = &page_cleanup($result);
1.92      sakharuk  496:         }
1.97      albertel  497:       } else {
                    498: 	  $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: ';
                    499: 	  if ($ENV{'form.url'}=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) {
                    500: 	      $result.=$1;
                    501: 	  } else {
                    502: 	      $result.=$ENV{'form.url'};
                    503: 	  }
                    504: 	  $result.=' \end{document}'
1.40      sakharuk  505:       }
                    506:     } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or 
                    507:              $choice eq 'Standard LaTeX output for whole primary sequence') {
1.36      sakharuk  508:       #-- minimal sequence to which the current document belongs
                    509:         #-- where is the primary sequence containing file?
1.88      sakharuk  510:         my @master_seq = ();
                    511: 	for (my $i=0; $i<$ENV{'form.numberoffiles'};$i++) {
                    512: 	    if ($ENV{'form.whatfile'.$i}=~/\S/) {
                    513: 		push @master_seq,$ENV{'form.whatfile'.$i};
                    514: 	    }
                    515: 	}
1.36      sakharuk  516:         #-- produce an output string
1.71      sakharuk  517: 	my $flag_latex_header_remove = 'NO';
                    518: 	my $flag_page_in_sequence = 'NO';
1.18      sakharuk  519: 	for (my $i=0;$i<=$#master_seq;$i++) {
1.105     sakharuk  520:            my ($urlp,$symb) = split /&&/, $master_seq[$i];
1.20      sakharuk  521: 	    if ($choice eq 'Standard LaTeX output for the primary sequence') {
1.88      sakharuk  522:               $selectionmade = 2;
                    523: 	    } elsif ($choice eq 'Standard LaTeX output for whole primary sequence') {
                    524:               $selectionmade = 3;
1.16      sakharuk  525: 	    }
1.88      sakharuk  526: 	   my %moreenv;
                    527: 	   $moreenv{'form.grade_target'}='tex';
                    528: 	   $moreenv{'form.textwidth'}=$LaTeXwidth;
                    529: 	   &Apache::lonnet::appenv(%moreenv);
1.98      albertel  530: 	   #&Apache::lonnet::logthis("Trying to get $urlp with symb $symb");
1.88      sakharuk  531: 	   my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$symb));
                    532: 	   &Apache::lonnet::delenv('form.grade_target','form.textwidth');
                    533: 	   if ($urlp =~ m/\.page/) {
                    534: 	     ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
                    535: 	     if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;} 
                    536: 	     $texversion =~ s/\\end{document}\d*/\\end{document}/;
                    537: 	     $flag_page_in_sequence = 'YES';
                    538: 	   } 
                    539: 	   if ($flag_latex_header_remove ne 'NO') {
                    540: 	     $texversion = &latex_header_footer_remove($texversion);
                    541: 	   } else {
                    542: 	     $texversion =~ s/\\end{document}//;
                    543: 	   }
                    544: 	   $result .= $texversion;         
                    545: 	   $flag_latex_header_remove = 'YES';   
1.77      sakharuk  546: 	}
                    547: 	&Apache::lonnet::delenv('form.counter');
1.71      sakharuk  548: 	if ($flag_page_in_sequence eq 'YES') {$result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;}	
                    549: 	$result .= '\end{document}';
1.13      sakharuk  550:     }  elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
1.47      sakharuk  551:         # where is the main sequence of the course?
1.59      sakharuk  552: 	$selectionmade = 4;
1.105     sakharuk  553: 	my $main_seq;
                    554: 	if ($ENV{'request.course.uri'}=~/\/?uploaded\//) {
                    555: 	    $main_seq = $ENV{'request.course.uri'};
                    556: 	} else {
                    557: 	    $main_seq = '/res/'.$ENV{'request.course.uri'};
                    558: 	}
1.112     sakharuk  559: 	my @file_seq = &coming_from_hash($main_seq);
                    560: 	for (my $i=0;$i<=$#file_seq;$i++) {
                    561: 	    my ($path,$title,$symb) = split /&&/,$file_seq[$i];
                    562: 	    $file_seq[$i] = $path.'&&'.$symb;
                    563: 	}
1.72      sakharuk  564: 	my $flag_latex_header_remove = 'NO';
1.52      sakharuk  565:         #-- produce an output string
1.49      sakharuk  566: 	for (my $i=0;$i<=$#file_seq;$i++) {
1.105     sakharuk  567: 	   if (not $file_seq[$i]=~/^&&/) {
                    568: 	     my ($urlp,$symb) = split /&&/, $file_seq[$i];
                    569: 	     $urlp=~s/\/home\/httpd\/html//;	    
                    570: 	     if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.49      sakharuk  571: 		my %moreenv;
                    572: 		$moreenv{'form.grade_target'}='tex';
1.76      sakharuk  573: 		$moreenv{'form.textwidth'}=$LaTeXwidth;
1.49      sakharuk  574: 		&Apache::lonnet::appenv(%moreenv);
1.74      sakharuk  575: 		my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$symb));
1.76      sakharuk  576: 		&Apache::lonnet::delenv('form.grade_target','form.textwidth');		    
1.72      sakharuk  577: 		if ($flag_latex_header_remove ne 'NO') {
                    578: 		    $texversion = &latex_header_footer_remove($texversion);
                    579: 		} else {
                    580: 		    $texversion =~ s/\\end{document}//;
                    581: 		}
1.74      sakharuk  582: 		$result .= $texversion;  
                    583: 		$flag_latex_header_remove = 'YES';
1.105     sakharuk  584: 	     }		
                    585: 	   }
1.49      sakharuk  586: 	}	    
1.72      sakharuk  587: 	$result .= '\end{document}';
1.52      sakharuk  588:     } elsif ($choice eq 'All class print') { 
1.54      sakharuk  589:     #-- prints assignments for whole class or for selected students  
1.59      sakharuk  590: 	$selectionmade = 5;
1.73      sakharuk  591:         my @students = ();
1.54      sakharuk  592: 	for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
                    593: 	    if ($ENV{'form.whomtoprint'.$i}=~/:/) {
                    594: 		push @students,$ENV{'form.whomtoprint'.$i};
                    595: 	    }
                    596: 	}
                    597: 	#where is the primary sequence containing current resource (the same for all students)?
                    598: 	my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
1.74      sakharuk  599: 	my @sequence = split('___',$symbolic);
1.112     sakharuk  600: 	my $primary_sequence;
                    601: 	if ($sequence[0]=~/^uploaded/) {$primary_sequence = '/'.$sequence[0];} 
                    602:           else {$primary_sequence = '/res/'.$sequence[0];}  	
                    603: 	my @master_seq = &coming_from_hash($primary_sequence); 
                    604: 	for (my $i=0;$i<=$#master_seq;$i++) {
                    605: 	    my ($path,$title,$symb) = split /&&/,$master_seq[$i];
                    606: 	    $master_seq[$i] = $path.'&&'.$symb;
                    607: 	}
1.72      sakharuk  608:         #loop over students
1.80      sakharuk  609: 	my $flag_latex_header_remove = 'NO'; 
                    610: 	my %moreenv;
                    611: 	$moreenv{'form.textwidth'}=$LaTeXwidth;
                    612: 	&Apache::lonnet::appenv(%moreenv);
1.54      sakharuk  613: 	foreach my $person (@students) {
                    614: 	    my $current_output = ''; 
1.57      sakharuk  615: 	    my ($usersection,$username,$userdomain) = split /:/,$person;
1.118     sakharuk  616: 	    my $fullname = &Apache::grades::get_fullname($username,$userdomain);    
1.72      sakharuk  617:             #goes through all resources, checks if they are available for current student, and produces output   
1.69      sakharuk  618: 	    foreach my $curresline (@master_seq)  {
                    619: 		my ($curres,$symb) = split /&&/, $curresline;
1.73      sakharuk  620:                 if ($curres=~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {
1.54      sakharuk  621: 		    my ($map,$id,$res_url) = split(/___/,$symb);
                    622: 		    if (&Apache::lonnet::allowed('bre',$res_url)) {
                    623: 			my $rendered = &Apache::loncommon::get_student_view($symb,$username,$userdomain,
                    624:                                                                         $ENV{'request.course.id'},'tex');
1.73      sakharuk  625: 			if ($flag_latex_header_remove eq 'YES') {
1.72      sakharuk  626: 			    $rendered = &latex_header_footer_remove($rendered);
                    627: 			} else {
                    628: 			    $rendered =~ s/\\end{document}//;
                    629: 			}
1.54      sakharuk  630: 			$current_output .= $rendered;
                    631: 		    }
1.73      sakharuk  632: 		    $flag_latex_header_remove = 'YES';
1.54      sakharuk  633: 		}
1.72      sakharuk  634: 	    }
1.117     sakharuk  635: 	    my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1.72      sakharuk  636: 	    if ($current_output=~/\\documentclass/) {
1.117     sakharuk  637: 		$current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\vskip 3 mm /;
1.72      sakharuk  638: 	    } else {
1.90      sakharuk  639: 		my $blanspages = '';
                    640: 		for (my $j=0;$j<$ENV{'form.addedpages'};$j++) {$blanspages.='\clearpage\strut\clearpage';}
1.118     sakharuk  641: 		$current_output = '\strut\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage \\vskip 3mm'.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}} - '.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}\hskip 1.4in } \vskip 5 mm '.$current_output;
1.54      sakharuk  642: 	    }
                    643: 	    $result .= $current_output;
1.118     sakharuk  644: 	    &Apache::lonnet::delenv('form.counter');	    
                    645: 	    &Apache::lonxml::init_counter(); 
1.54      sakharuk  646: 	}
1.80      sakharuk  647: 	$result .= '\end{document}';
                    648: 	&Apache::lonnet::delenv('form.textwidth');
1.31      sakharuk  649:     } elsif ($choice eq 'Subdirectory print') {      
1.58      sakharuk  650:     #prints selected problems from the subdirectory 
1.59      sakharuk  651: 	$selectionmade = 6;
1.58      sakharuk  652:         my @list_of_files = ();
                    653: 	for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) {
                    654: 	    if ($ENV{'form.whattoprint'.$i}=~/^\//) {
                    655: 		push @list_of_files,$ENV{'form.whattoprint'.$i};
1.28      sakharuk  656: 	    }
1.72      sakharuk  657: 	}	
                    658: 	my $flag_latex_header_remove = 'NO';  
1.31      sakharuk  659: 	for (my $i=0;$i<=$#list_of_files;$i++) {
1.58      sakharuk  660: 	    my $urlp = $list_of_files[$i];
                    661: 	    if ($urlp=~/\//) {
                    662: 		my %moreenv;
                    663: 		$moreenv{'form.grade_target'}='tex';
1.76      sakharuk  664: 		$moreenv{'form.textwidth'}=$LaTeXwidth;
1.58      sakharuk  665: 		&Apache::lonnet::appenv(%moreenv);
1.100     albertel  666: 		if ($urlp =~ m|/home/([^/]+)/public_html|) {
                    667: 		    $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
1.109     sakharuk  668: 		} else {
                    669: 		    $urlp =~ s|^/home/httpd/html||;
1.58      sakharuk  670: 		}
                    671: 		my $texversion=&Apache::lonnet::ssi($urlp);
1.76      sakharuk  672: 		&Apache::lonnet::delenv('form.grade_target','form.textwidth');
1.83      sakharuk  673:                 #this chunck is responsible for printing the path to problem
                    674: 		my $newurlp = '';
                    675: 		my $HowMany = length($urlp)*2;
                    676: 		if ($HowMany > $LaTeXwidth) {
                    677: 		    my @temporrary = split '/',$urlp;
                    678: 		    my $HowManyNew = 0;
                    679: 		    for (my $ii=0;$ii<=$#temporrary;$ii++) {
                    680: 			if ($temporrary[$ii] ne '') {
                    681: 			    $HowManyNew += length($temporrary[$ii])*2;
                    682: 			    if ($HowManyNew < $LaTeXwidth ) {
                    683: 				$newurlp .=  '/'.$temporrary[$ii];
                    684: 			    } else {
                    685: 				$HowManyNew = 0;
                    686: 				$newurlp .=  '|\vskip -1 mm \noindent \verb|';
                    687: 				$ii--;
                    688: 			    }
                    689: 			}
                    690: 		    }
                    691: 		}
                    692: 		$texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/;
1.72      sakharuk  693: 		if ($flag_latex_header_remove ne 'NO') {
                    694: 		    $texversion = &latex_header_footer_remove($texversion);
                    695: 		} else {
                    696: 		    $texversion =~ s/\\end{document}//;
                    697: 		}
1.58      sakharuk  698: 		$result .= $texversion;
1.72      sakharuk  699: 	    }
                    700: 	    $flag_latex_header_remove = 'YES';  
1.31      sakharuk  701: 	}
1.72      sakharuk  702: 	$result .= '\end{document}';      	
1.7       sakharuk  703:     }
1.74      sakharuk  704: #-------------------------------------------------------- corrections for the different page formats
1.83      sakharuk  705:     $result = &page_format_transformation($papersize,$layout,$numberofcolumns,$choice,$result,$assignment);
1.76      sakharuk  706:     if ($layout eq 'CBI') {
1.16      sakharuk  707:         $laystyle = 'album';
                    708:     }
1.76      sakharuk  709:     $result = &latex_corrections($number_of_columns,$result);
1.52      sakharuk  710:     #changes page's parameters for the one column output 
                    711:     if ($ENV{'form.numberofcolumns'} == 1) {
                    712: 	$result =~ s/\\textwidth= 9cm/\\textwidth= $ENV{'form.width'}/;
1.59      sakharuk  713: 	$result =~ s/\\textheight 25\.9cm/\\textheight $ENV{'form.height'}/;
                    714: 	$result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $ENV{'form.leftmargin'}/;
                    715: 	$result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $ENV{'form.leftmargin'}/;
1.52      sakharuk  716:     }
1.7       sakharuk  717: #-- writing .tex file in prtspool 
1.16      sakharuk  718:     my $temp_file;
1.33      sakharuk  719:     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
1.16      sakharuk  720:     unless ($temp_file = Apache::File->new('>'.$filename)) {
                    721: 	$r->log_error("Couldn't open $filename for output $!");
                    722: 	return SERVER_ERROR; 
                    723:     } 
                    724:     print $temp_file $result;
1.3       sakharuk  725: $r->print(<<FINALEND);
1.59      sakharuk  726: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns&$selectionmade">
1.3       sakharuk  727: </body>
                    728: </html>
                    729: FINALEND
                    730: }
1.61      sakharuk  731: 
                    732: 
1.112     sakharuk  733: sub coming_from_hash {
1.73      sakharuk  734: 
                    735:     my $mainsequence = shift;
                    736:     my @resourcelist = ();
                    737:     my $mapid = $hash{'map_pc_'.$mainsequence};
                    738:     my $mapstart = $hash{'map_start_'.$mainsequence};
                    739:     my $mapfinish = $hash{'map_finish_'.$mainsequence};
                    740:     my $current_resource = $mapstart;
                    741:     while ($current_resource ne $mapfinish) {
                    742: 	if ($hash{'src_'.$current_resource}=~/\.sequence$/) {
1.112     sakharuk  743: 	    push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource});
1.73      sakharuk  744: 	} else {
1.105     sakharuk  745: 	    my $presymb; 
                    746: 	    if ($mainsequence =~ /\/res\/(.*)$/) {$presymb = $1;} 
                    747:               elsif ($mainsequence =~ /\/?(uploaded\/(.*))$/) {$presymb = $1;} 
1.112     sakharuk  748: 	    my $rid = $current_resource;
1.105     sakharuk  749: 	    if ($rid=~/,/) {
1.74      sakharuk  750: 		my @rid = split /,/, $rid;
                    751: 		foreach my $rid_element (@rid) {
                    752: 		    if ($rid_element =~ m/^$mapid\.(\d*)/) {
                    753: 			$rid = $1; 
                    754: 			last;
                    755: 		    }
                    756: 		}
                    757: 	    } else {
1.105     sakharuk  758: 	        $rid =~ m/^$mapid\.(\d*)/;
1.74      sakharuk  759:                 $rid = $1;  
                    760: 	    }
                    761: 	    $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
                    762: 	    my $symb = $presymb.'___'.$rid.'___'.$1;	    
1.112     sakharuk  763: 	    push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$hash{'title_'.$current_resource}.'&&'.$symb;
1.73      sakharuk  764: 	}
1.74      sakharuk  765: 	$current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}};
1.111     sakharuk  766:     } 
                    767:     #needs if final resource in the map (type="finish") contains something
                    768: 	if ($hash{'src_'.$current_resource}=~/\.sequence$/) {
1.112     sakharuk  769: 	    push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource});
1.111     sakharuk  770: 	} else {
                    771: 	    my $presymb; 
                    772: 	    if ($mainsequence =~ /\/res\/(.*)$/) {$presymb = $1;} 
                    773:               elsif ($mainsequence =~ /\/?(uploaded\/(.*))$/) {$presymb = $1;} 
1.112     sakharuk  774: 	    my $rid = $current_resource;
1.111     sakharuk  775: 	    if ($rid=~/,/) {
                    776: 		my @rid = split /,/, $rid;
                    777: 		foreach my $rid_element (@rid) {
                    778: 		    if ($rid_element =~ m/^$mapid\.(\d*)/) {
                    779: 			$rid = $1; 
                    780: 			last;
                    781: 		    }
                    782: 		}
                    783: 	    } else {
                    784: 	        $rid =~ m/^$mapid\.(\d*)/;
                    785:                 $rid = $1;  
                    786: 	    }
                    787: 	    $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
                    788: 	    my $symb = $presymb.'___'.$rid.'___'.$1;	    
1.112     sakharuk  789: 	    push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$hash{'title_'.$current_resource}.'&&'.$symb;
1.61      sakharuk  790: 	}
                    791: 	$current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}};
                    792:     return @resourcelist;
                    793: }
                    794: 
1.2       sakharuk  795: 
1.71      sakharuk  796: sub latex_header_footer_remove {
                    797:     my $text = shift;
                    798:     $text =~ s/\\end{document}//;
                    799:     $text =~ s/\\documentclass([^&]*)\\begin{document}//;
                    800:     return $text;
                    801: }
                    802: 
                    803: 
1.37      sakharuk  804: sub character_chart {
                    805:     my $result = shift;	
1.116     sakharuk  806:     $result =~ s/&\#0?0?(7|9);//g;
                    807:     $result =~ s/&\#0?(10|13);//g;
                    808:     $result =~ s/&\#0?32;/ /g;
                    809:     $result =~ s/&\#0?33;/!/g;
                    810:     $result =~ s/&(\#0?34|quot);/\"/g;
                    811:     $result =~ s/&\#0?35;/\\\#/g;
                    812:     $result =~ s/&\#0?36;/\\\$/g;
                    813:     $result =~ s/&\#0?37;/\\%/g; 
                    814:     $result =~ s/&(\#0?38|amp);/\\&/g; 
                    815:     $result =~ s/&\#(0?39|146);/\'/g;
                    816:     $result =~ s/&\#0?40;/(/g;
                    817:     $result =~ s/&\#0?41;/)/g;
                    818:     $result =~ s/&\#0?42;/\*/g;
                    819:     $result =~ s/&\#0?43;/\+/g;
                    820:     $result =~ s/&\#(0?44|130);/,/g;
                    821:     $result =~ s/&\#0?45;/-/g;
                    822:     $result =~ s/&\#0?46;/\./g;
                    823:     $result =~ s/&\#0?47;/\//g;
                    824:     $result =~ s/&\#0?48;/0/g;
                    825:     $result =~ s/&\#0?49;/1/g;
                    826:     $result =~ s/&\#0?50;/2/g;
                    827:     $result =~ s/&\#0?51;/3/g;
                    828:     $result =~ s/&\#0?52;/4/g;
                    829:     $result =~ s/&\#0?53;/5/g;
                    830:     $result =~ s/&\#0?54;/6/g;
                    831:     $result =~ s/&\#0?55;/7/g;
                    832:     $result =~ s/&\#0?56;/8/g;
                    833:     $result =~ s/&\#0?57;/9/g;
                    834:     $result =~ s/&\#0?58;/:/g;
                    835:     $result =~ s/&\#0?59;/;/g;
                    836:     $result =~ s/&(\#0?60|lt|\#139);/\$<\$/g;
                    837:     $result =~ s/&\#0?61;/\$=\$/g;
                    838:     $result =~ s/&(\#0?62|gt|\#155);/\$>\$/g;
                    839:     $result =~ s/&\#0?63;/\?/g;
                    840:     $result =~ s/&\#0?65;/A/g;
                    841:     $result =~ s/&\#0?66;/B/g;
                    842:     $result =~ s/&\#0?67;/C/g;
                    843:     $result =~ s/&\#0?68;/D/g;
                    844:     $result =~ s/&\#0?69;/E/g;
                    845:     $result =~ s/&\#0?70;/F/g;
                    846:     $result =~ s/&\#0?71;/G/g;
                    847:     $result =~ s/&\#0?72;/H/g;
                    848:     $result =~ s/&\#0?73;/I/g;
                    849:     $result =~ s/&\#0?74;/J/g;
                    850:     $result =~ s/&\#0?75;/K/g;
                    851:     $result =~ s/&\#0?76;/L/g;
                    852:     $result =~ s/&\#0?77;/M/g;
                    853:     $result =~ s/&\#0?78;/N/g;
                    854:     $result =~ s/&\#0?79;/O/g;
                    855:     $result =~ s/&\#0?80;/P/g;
                    856:     $result =~ s/&\#0?81;/Q/g;
                    857:     $result =~ s/&\#0?82;/R/g;
                    858:     $result =~ s/&\#0?83;/S/g;
                    859:     $result =~ s/&\#0?84;/T/g;
                    860:     $result =~ s/&\#0?85;/U/g;
                    861:     $result =~ s/&\#0?86;/V/g;
                    862:     $result =~ s/&\#0?87;/W/g;
                    863:     $result =~ s/&\#0?88;/X/g;
                    864:     $result =~ s/&\#0?89;/Y/g;
                    865:     $result =~ s/&\#0?90;/Z/g;
                    866:     $result =~ s/&\#0?91;/[/g;
                    867:     $result =~ s/&\#0?92;/\$\\setminus\$/g;
                    868:     $result =~ s/&\#0?93;/]/g;
                    869:     $result =~ s/&\#(0?94|136);/\$\\wedge\$/g;
                    870:     $result =~ s/&\#(0?95|138|154);/\\underline{\\makebox[2mm]{\\strut}}/g;
                    871:     $result =~ s/&\#(0?96|145);/\`/g;
                    872:     $result =~ s/&\#0?97;/a/g;
                    873:     $result =~ s/&\#0?98;/b/g;
                    874:     $result =~ s/&\#0?99;/c/g;
                    875:     $result =~ s/&\#100;/d/g;
                    876:     $result =~ s/&\#101;/e/g;
                    877:     $result =~ s/&\#102;/f/g;
                    878:     $result =~ s/&\#103;/g/g;
                    879:     $result =~ s/&\#104;/h/g;
                    880:     $result =~ s/&\#105;/i/g;
                    881:     $result =~ s/&\#106;/j/g;
                    882:     $result =~ s/&\#107;/k/g;
                    883:     $result =~ s/&\#108;/l/g;
                    884:     $result =~ s/&\#109;/m/g;
                    885:     $result =~ s/&\#110;/n/g;
                    886:     $result =~ s/&\#111;/o/g;
                    887:     $result =~ s/&\#112;/p/g;
                    888:     $result =~ s/&\#113;/q/g;
                    889:     $result =~ s/&\#114;/r/g;
                    890:     $result =~ s/&\#115;/s/g;
                    891:     $result =~ s/&\#116;/t/g;
                    892:     $result =~ s/&\#117;/u/g;
                    893:     $result =~ s/&\#118;/v/g;
                    894:     $result =~ s/&\#119;/w/g;
                    895:     $result =~ s/&\#120;/x/g;
                    896:     $result =~ s/&\#121;/y/g;
                    897:     $result =~ s/&\#122;/z/g;
                    898:     $result =~ s/&\#123;/\\{/g;
                    899:     $result =~ s/&\#124;/\|/g;
                    900:     $result =~ s/&\#125;/\\}/g;
                    901:     $result =~ s/&\#126;/\~/g;
                    902:     $result =~ s/&\#131;/\\textflorin /g;
                    903:     $result =~ s/&\#132;/\"/g;
                    904:     $result =~ s/&\#133;/\$\\ldots\$/g;
                    905:     $result =~ s/&\#134;/\$\\dagger\$/g;
                    906:     $result =~ s/&\#135;/\$\\ddagger\$/g;
                    907:     $result =~ s/&\#137;/\\textperthousand /g;
                    908:     $result =~ s/&\#140;/{\\OE}/g;
                    909:     $result =~ s/&\#147;/\`\`/g;
                    910:     $result =~ s/&\#148;/\'\'/g;
                    911:     $result =~ s/&\#149;/\$\\bullet\$/g;
                    912:     $result =~ s/&\#150;/--/g;
                    913:     $result =~ s/&\#151;/---/g;
                    914:     $result =~ s/&\#152;/\$\\sim\$/g;
                    915:     $result =~ s/&\#153;/\\texttrademark /g;
                    916:     $result =~ s/&\#156;/\\oe/g;
                    917:     $result =~ s/&\#159;/\\\"Y/g;
                    918:     $result =~ s/&(\#160|nbsp);//g;
                    919:     $result =~ s/&(\#161|iexcl);/!\`/g;
                    920:     $result =~ s/&(\#162|cent);/\\textcent /g;
                    921:     $result =~ s/&(\#163|pound);/\\pounds /g; 
                    922:     $result =~ s/&(\#164|curren);/\\textcurrency /g;
                    923:     $result =~ s/&(\#165|yen);/\\textyen /g;
                    924:     $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g;
                    925:     $result =~ s/&(\#167|sect);/\\textsection /g;
                    926:     $result =~ s/&(\#168|uml);/\\texthighdieresis /g;
                    927:     $result =~ s/&(\#169|copy);/\\copyright /g;
                    928:     $result =~ s/&(\#170|ordf);/\\textordfeminine /g;
                    929:     $result =~ s/&(\#172|not);/\$\\neg\$/g;
                    930:     $result =~ s/&(\#173|shy);/ - /g;
                    931:     $result =~ s/&(\#174|reg);/\\textregistered /g;
                    932:     $result =~ s/&(\#175|macr);/\$^{-}\$/g;
                    933:     $result =~ s/&(\#176|deg);/\$^{\\circ}\$/g;
                    934:     $result =~ s/&(\#177|plusmn);/\$\\pm\$/g;
                    935:     $result =~ s/&(\#178|sup2);/\$^2\$/g;
                    936:     $result =~ s/&(\#179|sup3);/\$^3\$/g;
                    937:     $result =~ s/&(\#180|acute);/\\textacute /g;
                    938:     $result =~ s/&(\#181|micro);/\$\\mu\$/g;
                    939:     $result =~ s/&(\#182|para);/\\P/g;
                    940:     $result =~ s/&(\#183|middot);/\$\\cdot\$/g;
                    941:     $result =~ s/&(\#184|cedil);/\\c{\\strut}/g;
                    942:     $result =~ s/&(\#185|sup1);/\$^1\$/g;
                    943:     $result =~ s/&(\#186|ordm);/\\textordmasculine /g;
                    944:     $result =~ s/&(\#188|frac14);/\\textonequarter /g;
                    945:     $result =~ s/&(\#189|frac12);/\\textonehalf /g;
                    946:     $result =~ s/&(\#190|frac34);/\\textthreequarters /g;
                    947:     $result =~ s/&(\#191|iquest);/?\`/g;   
                    948:     $result =~ s/&(\#192|Agrave);/\\\`{A}/g;  
                    949:     $result =~ s/&(\#193|Aacute);/\\\'{A}/g; 
                    950:     $result =~ s/&(\#194|Acirc);/\\^{A}/g;
                    951:     $result =~ s/&(\#195|Atilde);/\\~{A}/g;
                    952:     $result =~ s/&(\#196|Auml);/\\\"{A}/g; 
                    953:     $result =~ s/&(\#197|Aring);/{\\AA}/g;
                    954:     $result =~ s/&(\#198|AElig);/{\\AE}/g;
                    955:     $result =~ s/&(\#199|Ccedil);/\\c{c}/g;
                    956:     $result =~ s/&(\#200|Egrave);/\\\`{E}/g;  
                    957:     $result =~ s/&(\#201|Eacute);/\\\'{E}/g;    
                    958:     $result =~ s/&(\#202|Ecirc);/\\^{E}/g;
                    959:     $result =~ s/&(\#203|Euml);/\\\"{E}/g;
                    960:     $result =~ s/&(\#204|Igrave);/\\\`{I}/g;
                    961:     $result =~ s/&(\#205|Iacute);/\\\'{I}/g;    
                    962:     $result =~ s/&(\#206|Icirc);/\\^{I}/g;
                    963:     $result =~ s/&(\#207|Iuml);/\\\"{I}/g;    
                    964:     $result =~ s/&(\#209|Ntilde);/\\~{N}/g;
                    965:     $result =~ s/&(\#210|Ograve);/\\\`{O}/g;
                    966:     $result =~ s/&(\#211|Oacute);/\\\'{O}/g;
                    967:     $result =~ s/&(\#212|Ocirc);/\\^{O}/g;
                    968:     $result =~ s/&(\#213|Otilde);/\\~{O}/g;
                    969:     $result =~ s/&(\#214|Ouml);/\\\"{O}/g;    
                    970:     $result =~ s/&(\#215|times);/\$\\times\$/g;
                    971:     $result =~ s/&(\#216|Oslash);/{\\O}/g;
                    972:     $result =~ s/&(\#217|Ugrave);/\\\`{U}/g;    
                    973:     $result =~ s/&(\#218|Uacute);/\\\'{U}/g;
                    974:     $result =~ s/&(\#219|Ucirc);/\\^{U}/g;
                    975:     $result =~ s/&(\#220|Uuml);/\\\"{U}/g;
                    976:     $result =~ s/&(\#221|Yacute);/\\\'{Y}/g;
                    977:     $result =~ s/&(\#223|szlig);/\\ss/g;
                    978:     $result =~ s/&(\#224|agrave);/\\\`{a}/g;
                    979:     $result =~ s/&(\#225|aacute);/\\\'{a}/g;
                    980:     $result =~ s/&(\#226|acirc);/\\^{a}/g;
                    981:     $result =~ s/&(\#227|atilde);/\\~{a}/g;
                    982:     $result =~ s/&(\#228|auml);/\\\"{a}/g;
                    983:     $result =~ s/&(\#229|aring);/{\\aa}/g;
                    984:     $result =~ s/&(\#230|aelig);/{\\ae}/g;
                    985:     $result =~ s/&(\#231|ccedil);/\\c{c}/g;
                    986:     $result =~ s/&(\#232|egrave);/\\\`{e}/g;
                    987:     $result =~ s/&(\#233|eacute);/\\\'{e}/g;
                    988:     $result =~ s/&(\#234|ecirc);/\\^{e}/g;
                    989:     $result =~ s/&(\#235|euml);/\\\"{e}/g;
                    990:     $result =~ s/&(\#236|igrave);/\\\`{i}/g;
                    991:     $result =~ s/&(\#237|iacute);/\\\'{i}/g;
                    992:     $result =~ s/&(\#238|icirc);/\\^{i}/g;
                    993:     $result =~ s/&(\#239|iuml);/\\\"{i}/g;
                    994:     $result =~ s/&(\#240|eth);/\$\\partial\$/g;
                    995:     $result =~ s/&(\#241|ntilde);/\\~{n}/g;
                    996:     $result =~ s/&(\#242|ograve);/\\\`{o}/g;
                    997:     $result =~ s/&(\#243|oacute);/\\\'{o}/g;
                    998:     $result =~ s/&(\#244|ocirc);/\\^{o}/g;
                    999:     $result =~ s/&(\#245|otilde);/\\~{o}/g;
                   1000:     $result =~ s/&(\#246|ouml);/\\\"{o}/g;
                   1001:     $result =~ s/&(\#247|divide);/\$\\div\$/g;
                   1002:     $result =~ s/&(\#248|oslash);/{\\o}/g;
                   1003:     $result =~ s/&(\#249|ugrave);/\\\`{u}/g; 
                   1004:     $result =~ s/&(\#250|uacute);/\\\'{u}/g;
                   1005:     $result =~ s/&(\#251|ucirc);/\\^{u}/g;
                   1006:     $result =~ s/&(\#252|uuml);/\\\"{u}/g;
                   1007:     $result =~ s/&(\#253|yacute);/\\\'{y}/g;
                   1008:     $result =~ s/&(\#255|yuml);/\\\"{y}/g;
                   1009:     $result =~ s/&\#952;/\$\\theta\$/g;
1.117     sakharuk 1010: #Greek Alphabet
                   1011:     $result =~ s/&(alpha|\#945);/\$\\alpha \$/g;
                   1012:     $result =~ s/&(beta|\#946);/\$\\beta \$/g;
                   1013:     $result =~ s/&(gamma|\#947);/\$\\gamma \$/g;
                   1014:     $result =~ s/&(delta|\#948);/\$\\delta \$/g;
                   1015:     $result =~ s/&(epsilon|\#949);/\$\\epsilon \$/g;
                   1016:     $result =~ s/&(zeta|\#950);/\$\\zeta \$/g;
                   1017:     $result =~ s/&(eta|\#951);/\$\\eta \$/g;
                   1018:     $result =~ s/&(theta|\#952);/\$\\theta \$/g;
                   1019:     $result =~ s/&(iota|\#953);/\$\\iota \$/g;
                   1020:     $result =~ s/&(kappa|\#954);/\$\\kappa \$/g;
                   1021:     $result =~ s/&(lambda|\#955);/\$\\lambda \$/g;
                   1022:     $result =~ s/&(mu|\#956);/\$\\mu \$/g;
                   1023:     $result =~ s/&(nu|\#957);/\$\\nu \$/g;
                   1024:     $result =~ s/&(xi|\#958);/\$\\xi \$/g;
                   1025:     $result =~ s/&(pi|\#960);/\$\\pi \$/g;
                   1026:     $result =~ s/&(rho|\#961);/\$\\rho \$/g;
                   1027:     $result =~ s/&(sigma|\#963);/\$\\sigma \$/g;
                   1028:     $result =~ s/&(tau|\#964);/\$\\tau \$/g;
                   1029:     $result =~ s/&(upsilon|\#965);/\$\\upsilon \$/g;
                   1030:     $result =~ s/&(phi|\#966);/\$\\phi \$/g;
                   1031:     $result =~ s/&(chi|\#967);/\$\\chi \$/g;
                   1032:     $result =~ s/&(psi|\#968);/\$\\psi \$/g;
                   1033:     $result =~ s/&(omega|\#969);/\$\\omega \$/g;
                   1034:     $result =~ s/&(Gamma|\#915);/\$\\Gamma \$/g;
                   1035:     $result =~ s/&(Delta|\#916);/\$\\Delta \$/g;
                   1036:     $result =~ s/&(Theta|\#920);/\$\\Theta \$/g;
                   1037:     $result =~ s/&(Lambda|\#923);/\$\\Lambda \$/g;
                   1038:     $result =~ s/&(Xi|\#926);/\$\\Xi \$/g;
                   1039:     $result =~ s/&(Pi|\#928);/\$\\Pi \$/g;
                   1040:     $result =~ s/&(Sigma|\#931);/\$\\Sigma \$/g;
                   1041:     $result =~ s/&(Upsilon|\#933);/\$\\Upsilon \$/g;
                   1042:     $result =~ s/&(Phi|\#934);/\$\\Phi \$/g;
                   1043:     $result =~ s/&(Psi|\#936);/\$\\Psi \$/g;
                   1044:     $result =~ s/&(Omega|\#937);/\$\\Omega \$/g;
                   1045: 
1.37      sakharuk 1046:     return $result;
                   1047: }
1.41      sakharuk 1048: 
                   1049: 
1.76      sakharuk 1050:     sub page_format {
                   1051: 	my ($papersize,$layout,$numberofcolumns) = @_; 
                   1052: 	my ($textwidth,$textheight,$oddoffset,$evenoffset) = (0,0,0,0);
                   1053: 	if ($papersize=~/Letter/) {
                   1054: 	    if ($layout eq 'CAPA') {
                   1055: 		if ($numberofcolumns == 1) {
                   1056: 		    $textwidth = '18 cm';
                   1057: 		    $textheight = '25.9 cm';
                   1058: 		    $oddoffset = '-0.57 in';
                   1059: 		    $evenoffset = '-0.57 in';
                   1060: 		} elsif ($numberofcolumns == 2) {
1.81      sakharuk 1061: 		    $textwidth = '93 mm';
1.76      sakharuk 1062: 		    $textheight = '25.9 cm';
                   1063: 		    $oddoffset = '-0.57 in';
                   1064: 		    $evenoffset = '-0.57 in';
                   1065: 		}
                   1066: 	    } elsif ($layout eq 'CBI') {
                   1067: 		if ($numberofcolumns eq '1') {
                   1068: 		    $textwidth = '8.8 in';
                   1069: 		    $textheight = '6.8 in';
                   1070: 		    $oddoffset = '-40 pt';
                   1071: 		    $evenoffset = '-60 pt';
                   1072: 		} elsif ($numberofcolumns == 2) {
                   1073: 		    $textwidth = '4.2 in';
                   1074: 		    $textheight = '6.8 in';
                   1075: 		    $oddoffset = '-40 pt';
                   1076: 		    $evenoffset = '-60 pt';
                   1077: 		}
                   1078: 	    }
                   1079: #    } elsif($papersize=~/Legal/) {
                   1080: #    } elsif($papersize=~/Ledger/) {
                   1081: #    } elsif($papersize=~/Executive/) {
                   1082:     } elsif($papersize=~/A4/) {
                   1083: 	    if ($layout eq 'CAPA') {
                   1084: 		if ($numberofcolumns == 1) {
                   1085: 		    $textwidth = '18 cm';
                   1086: 		    $textheight = '28 cm';
                   1087: 		    $oddoffset = '-0.57 in';
                   1088: 		    $evenoffset = '-0.57 in';
                   1089: 		} elsif ($numberofcolumns == 2) {
1.81      sakharuk 1090: 		    $textwidth = '96 mm';
1.76      sakharuk 1091: 		    $textheight = '2 cm';
                   1092: 		    $oddoffset = '-0.57 in';
                   1093: 		    $evenoffset = '-0.57 in';
                   1094: 		}
                   1095: 	    } elsif ($layout eq 'CBI') {
                   1096: 		if ($numberofcolumns eq '1') {
                   1097: 		    $textwidth = '8.5 in';
                   1098: 		    $textheight = '7.7 in';
                   1099: 		    $oddoffset = '-40 pt';
                   1100: 		    $evenoffset = '-60 pt';
                   1101: 		} elsif ($numberofcolumns == 2) {
                   1102: 		    $textwidth = '3.9 in';
                   1103: 		    $textheight = '7.7 in';
                   1104: 		    $oddoffset = '-40 pt';
                   1105: 		    $evenoffset = '-60 pt';
                   1106: 		}
                   1107: 	    }
                   1108: #    } elsif($papersize=~/A3/) {
                   1109: #    } elsif($papersize=~/A2/) {
                   1110: #    } elsif($papersize=~/A5/) {
                   1111: #    } elsif($papersize=~/A6/) {
                   1112: 	}
                   1113: 	return $textwidth,$textheight,$oddoffset,$evenoffset;
                   1114:     }
                   1115: 
                   1116: 
                   1117: sub page_format_transformation {
1.104     sakharuk 1118:     my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment) = @_; 
                   1119:     my ($textwidth,$textheight,$oddoffset,$evenoffset);
1.101     sakharuk 1120: 	$assignment=~s/_/ /g;
1.104     sakharuk 1121:         if ($numberofcolumns != 1) {
                   1122:           ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns);
                   1123: 	} else {
                   1124: 	  ($textwidth,$textheight,$oddoffset,$evenoffset) = ($ENV{'form.width'},$ENV{'form.height'},$ENV{'form.leftmargin'},$ENV{'form.leftmargin'});
                   1125: 	}
1.113     sakharuk 1126:     my $firstname = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'environment.firstname'}),'','','header');
                   1127:     my $lastname = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'environment.lastname'}),'','','header');
                   1128:     my $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'','','header');
1.108     sakharuk 1129:     if ($layout eq 'CBI') {
                   1130: 	    $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}\\setlength{\\topmargin}{200pt}\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\parindent}{20pt}\\setlength{\\marginparwidth}{90pt}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm} \\begin{document}\\setcounter{page}{1}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$firstname $lastname}} \\hfill  $courseidinfo} \\vskip 5 mm /;
                   1131:     } elsif ($layout eq 'CAPA') {
                   1132: 	if ($choice ne 'All class print') { 
1.110     sakharuk 1133: 		$text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{}\\lhead{\\textbf{$firstname $lastname} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}/;
1.108     sakharuk 1134: 	} else {
1.117     sakharuk 1135: 	    $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\\setcounter{page}{1}  \\vskip 5 mm /;
                   1136: 
1.76      sakharuk 1137: 	}
1.108     sakharuk 1138:     }
                   1139:     return $text;
1.76      sakharuk 1140: }
1.68      sakharuk 1141: 
                   1142: 
1.33      sakharuk 1143: sub page_cleanup {
                   1144:     my $result = shift;	
1.65      sakharuk 1145:  
                   1146:     $result =~ m/\\end{document}(\d*)$/;
1.34      sakharuk 1147:     my $number_of_columns = $1;
1.33      sakharuk 1148:     my $insert = '{';
1.34      sakharuk 1149:     for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33      sakharuk 1150:     $insert .= '}';
1.65      sakharuk 1151:     $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
1.34      sakharuk 1152:     $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
                   1153:     return $result,$number_of_columns;
1.7       sakharuk 1154: }
1.5       sakharuk 1155: 
1.3       sakharuk 1156: 
1.60      sakharuk 1157: sub details_for_menu {
                   1158: 
                   1159:     my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}};
                   1160:     my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'});
1.63      albertel 1161:     my ($map,$id,$resource)=split(/___/,$symbolic);
1.102     sakharuk 1162:     my $name_of_sequence;
                   1163:     if ($map=~/^uploaded/) {
                   1164: 	$name_of_sequence = $hash{'title_'.$hash{'ids_/'.$map}};
                   1165:     } else {
                   1166: 	$name_of_sequence = $hash{'title_'.$hash{'ids_/res/'.$map}};
                   1167:     }
1.63      albertel 1168:     if ($name_of_sequence =~ /^\s*$/) {
1.102     sakharuk 1169:      $map =~ m|([^/]+)$|;
1.63      albertel 1170:       $name_of_sequence = $1;
                   1171:     }
1.62      sakharuk 1172:     my $name_of_map = $hash{'title_'.$hash{'ids_/res/'.$ENV{'request.course.uri'}}};
1.63      albertel 1173:     if ($name_of_map =~ /^\s*$/) {
                   1174:       $ENV{'request.course.uri'} =~ m|([^/]+)$|;
                   1175:       $name_of_map = $1;
1.83      sakharuk 1176:     }  
1.63      albertel 1177:     return ($name_of_resourse,$name_of_sequence,$name_of_map);
1.60      sakharuk 1178: 
1.76      sakharuk 1179: }
                   1180: 
                   1181: 
                   1182: sub latex_corrections {
                   1183: 
                   1184:     my ($number_of_columns,$result) = @_;
                   1185: 
1.77      sakharuk 1186:     $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
1.76      sakharuk 1187:     $result =~ s/\$number_of_columns/$number_of_columns/g;
1.91      sakharuk 1188:     $result =~ s/(\\end{document})/\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License  $1/;
                   1189:     $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
                   1190:     $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g;
1.76      sakharuk 1191: #-- LaTeX corrections     
                   1192:     my $first_comment = index($result,'<!--',0);
                   1193:     while ($first_comment != -1) {
                   1194: 	my $end_comment = index($result,'-->',$first_comment);
                   1195: 	substr($result,$first_comment,$end_comment-$first_comment+3) = '';
                   1196: 	$first_comment = index($result,'<!--',$first_comment);
                   1197:     }
                   1198:     $result =~ s/^\s+$//gm; #remove empty lines
1.94      sakharuk 1199:     $result =~ s/(\s)(\s+)/$1/g; #removes more than one empty space
1.76      sakharuk 1200:     $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
                   1201:     $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
                   1202:     $result =~ s/{\\par }\s*\\\\/\\\\/gm;
                   1203: 	$result =~ s/\\\\\s+\[/ \[/g;
                   1204:     $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
                   1205:     #conversion of html characters to LaTeX equivalents
                   1206:     if ($result =~ m/&(\w+|#\d+);/) {
                   1207: 	$result = &character_chart($result);
                   1208:     }
                   1209:     $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
                   1210:     $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
                   1211: 
                   1212:     return $result;
1.60      sakharuk 1213: }
                   1214: 
1.3       sakharuk 1215: 
                   1216: sub handler {
                   1217: 
                   1218:     my $r = shift;
1.114     bowersj2 1219: 
                   1220:     # A hook for me to work without disturbing Alex.
                   1221:     if ($ENV{'form.jeremy'}) {
                   1222:         printWizard($r);
                   1223:         return OK;
                   1224:     }
1.67      www      1225: 
                   1226:     my $loaderror=&Apache::lonnet::overloaderror($r);
                   1227:     if ($loaderror) { return $loaderror; }
                   1228:     $loaderror=
                   1229:        &Apache::lonnet::overloaderror($r,
                   1230:          $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
                   1231:     if ($loaderror) { return $loaderror; }
                   1232: 
1.3       sakharuk 1233:     $r->content_type('text/html');
                   1234:     $r->send_http_header;
1.59      sakharuk 1235:     $r->print(&Apache::loncommon::bodytag("Printing"));
1.3       sakharuk 1236: 
1.60      sakharuk 1237:     if ($ENV{'request.course.id'}) {
                   1238: 	my $fn=$ENV{'request.course.fn'};
                   1239: 	tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640);
                   1240:     }
                   1241: 
1.3       sakharuk 1242: #-- start form
                   1243:     &headerform($r);
                   1244: #-- menu for output
1.16      sakharuk 1245:     unless  ($ENV{'form.phase'}) {
1.3       sakharuk 1246: 	&menu_for_output($r);
                   1247:     }
1.52      sakharuk 1248: #-- additional menu for class printing
                   1249:      if ($ENV{'form.phase'} eq 'two') {
1.88      sakharuk 1250: 	 if($ENV{'form.choice'} eq 'Standard LaTeX output for whole primary sequence') {
                   1251: 	     &sequence_content_menu(0,$r);
                   1252: 	 } elsif($ENV{'form.choice'} eq 'Standard LaTeX output for the primary sequence') {
                   1253: 	     &sequence_content_menu(1,$r);
                   1254: 	 } elsif($ENV{'form.choice'} eq 'All class print') {
1.52      sakharuk 1255: 	     &additional_class_menu($r);
1.58      sakharuk 1256: 	 } elsif($ENV{'form.choice'} eq 'Subdirectory print') {
                   1257: 	     &problem_choice_menu($r);
1.52      sakharuk 1258: 	 } else {
                   1259: 	     $ENV{'form.phase'} = 'three';
                   1260: 	 }
                   1261:      }
                   1262: #-- additional menu for page layout (one column case)
                   1263:     if ($ENV{'form.phase'} eq 'three') {
                   1264: 	if($ENV{'form.numberofcolumns'} == 1) {
                   1265: 	    &additional_print_menu($r);
                   1266: 	} else {
                   1267: 	    $ENV{'form.phase'} = 'four';
                   1268: 	}
                   1269:     }
1.3       sakharuk 1270: #-- core part 
1.52      sakharuk 1271:     if ($ENV{'form.phase'} eq 'four') {
1.3       sakharuk 1272: 	&output_data($r);
1.60      sakharuk 1273:     }	
                   1274:     untie %hash;
1.2       sakharuk 1275:     return OK;
1.60      sakharuk 1276:    
                   1277: } 
1.2       sakharuk 1278: 
1.115     bowersj2 1279: use Apache::lonwizard;
                   1280: 
                   1281: sub printWizard {
                   1282:     my $r = shift;
                   1283: 
                   1284:     if ($ENV{'request.course.id'}) {
                   1285: 	my $fn=$ENV{'request.course.fn'};
                   1286: 	tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640);
                   1287:     }
                   1288: 
                   1289:     if ($r->header_only) {
                   1290:         if ($ENV{'browser.mathml'}) {
                   1291:             $r->content_type('text/xml');
                   1292:         } else {
                   1293:             $r->content_type('text/html');
                   1294:         }
                   1295:         $r->send_http_header;
                   1296:         return OK;
                   1297:     }
                   1298: 
                   1299:     # Send header, nocache
                   1300:     if ($ENV{'browser.mathml'}) {
                   1301:         $r->content_type('text/xml');
                   1302:     } else {
                   1303:         $r->content_type('text/html');
                   1304:     }
                   1305:     &Apache::loncommon::no_cache($r);
                   1306:     $r->send_http_header;
                   1307:     $r->rflush();
                   1308: 
                   1309:     my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu;
                   1310: 
1.119     bowersj2 1311:     my $wizard = Apache::lonwizard->new("Printing Wizard", $ENV{QUERY_STRING});
1.115     bowersj2 1312:     # PRINT_TYPE: What the user wants to print (current docs,
                   1313:     #  whole sequence, etc.
1.119     bowersj2 1314:     $wizard->declareVars(['PRINT_TYPE', 'FORMAT', 'postdata', 'url',
                   1315:                           'symb', 'RESOURCES', 'FILES']);
                   1316: 
                   1317:     # Extract map
                   1318:     my $symb = $wizard->{VARS}->{'symb'};
                   1319:     my ($map, $id, $url) = split(/__/, $symb);
                   1320: 
                   1321:     my $subdir = &Apache::lonnet::filelocation("", $ENV{'form.url'});
                   1322: 
                   1323:     # "Delete everything after the last slash."
                   1324:     $subdir =~ s|/[^/]+$||;
                   1325: 
                   1326:     # This really ought to be in some repository in loncommon or
                   1327:     # something where it can just be grabbed.
                   1328:     my $problemFilter = sub { 
                   1329:         my $name = shift;
                   1330:         return $name =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/;
                   1331:     };
1.115     bowersj2 1332: 
                   1333:     Apache::lonwizard::switch_state->new($wizard, "START", "Selecting Resources to Print", "PRINT_TYPE", [
                   1334:            ['current_document', "<b>$resourceTitle</b> (exactly what was on the screen)", 'CHOOSE_FORMAT'],
1.119     bowersj2 1335:            ['map_problems', "Problems from <b>$sequenceTitle</b>", 'CHOOSE_PROBLEMS'],
                   1336:            ['map_problems_pages', "Problems and pages from <b>$sequenceTitle</b>", 'CHOOSE_PROBLEMS_HTML'],
1.115     bowersj2 1337:            ['problems_for_students', "Problems from <b>$sequenceTitle</b> for selected students", 'CHOOSE_FORMAT'],
1.119     bowersj2 1338:            ['problems_from_directory', "Problems from <b>$subdir</b>", 'CHOOSE_FROM_SUBDIR'] ],
1.115     bowersj2 1339:            "What do you want to print?");
1.119     bowersj2 1340:     Apache::lonwizard::resource_multichoice->new($wizard, "CHOOSE_PROBLEMS", 'Select Problems', "Select problems to print from <b>$sequenceTitle</b>:", '', 'CHOOSE_FORMAT', 'RESOURCES', sub {my $res = shift; return $res->is_problem()}, undef, $map);
                   1341:     Apache::lonwizard::resource_multichoice->new($wizard, "CHOOSE_PROBLEMS_HTML", 'Select Resources', "Select resources to print from <b>$sequenceTitle</b>:", '', "CHOOSE_FORMAT", 'RESOURCES', sub {my $res = shift; return !$res->is_map()}, undef, $map);
                   1342:     Apache::lonwizard::choose_files->new($wizard, "CHOOSE_FROM_SUBDIR", "Select Files","Select problems you wish to print from <b>$subdir</b>:", '', 'CHOOSE_FORMAT', 'FILES', $subdir, $problemFilter);
                   1343:     Apache::lonprintout::page_format_state->new($wizard, "CHOOSE_FORMAT", "Page Format", "FORMAT", "FINAL");
                   1344: 
1.115     bowersj2 1345:     $r->print($wizard->display());
                   1346: 
                   1347:     untie %hash;
                   1348: 
                   1349:     return OK;
                   1350: 
                   1351: }
                   1352: 
1.1       www      1353: 
                   1354: 1;
1.119     bowersj2 1355: 
                   1356: package Apache::lonprintout::page_format_state;
                   1357: 
                   1358: =pod
                   1359: 
                   1360: =head1 Wizard state: page_format_state
                   1361: 
                   1362: See lonwizard.pm documentation for discussion of the wizard framework.
                   1363: 
                   1364: Apache::lonprintout::page_format_state is a state that gives the user an opportunity to select the page layout they wish to print with: Number of columns, portrait/landscape, and paper size. If you want to change the paper size choices, change the @paperSize array contents in this package.
                   1365: 
                   1366: =over 4
                   1367: 
                   1368: =item * B<new>(parentLonWizReference, stateName, stateTitle, varName, nextState): varName is where the print information will be stored in the format FIXME. nextState is the state that follows this one.
                   1369: 
                   1370: =back
                   1371: 
                   1372: =cut
                   1373: 
                   1374: use Apache::lonwizard;
                   1375: 
                   1376: no strict;
                   1377: @ISA = ("Apache::lonwizard::state");
                   1378: use strict;
                   1379: 
                   1380: my $maxColumns = 2;
                   1381: my @paperSize = ("Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]", 
                   1382:                  "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
                   1383:                  "A2 [420x594 mm]", "A3 [297x420 mm]", "A4 [210x297 mm]", 
                   1384:                  "A5 [148x210 mm]", "A6 [105x148 mm]" );
                   1385: 
                   1386: # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum |
                   1387: #                   Paper type
                   1388: 
                   1389: sub new { 
                   1390:     my $proto = shift;
                   1391:     my $class = ref($proto) || $proto;
                   1392:     my $self = bless $proto->SUPER::new(shift, shift, shift);
                   1393: 
                   1394:     $self->{VAR_NAME} = shift;
                   1395:     $self->{NEXT_STATE} = shift;
                   1396:     return $self;
                   1397: }
                   1398: 
                   1399: sub postprocess {
                   1400:     my $self = shift;
                   1401:     my $wizard = $self->{WIZARD};
                   1402: 
                   1403:     # We have to manually collect the value and store it in the 
                   1404:     # wizard variable
                   1405:     my $result = $ENV{'form.' . $self->{VAR_NAME} . '.layout'} . '|';
                   1406:     $result .= $ENV{'form.' . $self->{VAR_NAME} . '.cols'} . '|';
                   1407:     $result .= $ENV{'form.' . $self->{VAR_NAME} . '.paper'};
                   1408:     
                   1409:     $wizard->setVar($self->{VAR_NAME}, $result);
                   1410:     $wizard->changeState($self->{NEXT_STATE});
                   1411: }
                   1412: 
                   1413: sub render {
                   1414:     my $self = shift;
                   1415:     my $wizard = $self->{WIZARD};
                   1416:     my $result = '';
                   1417:     my $var = $self->{VAR_NAME};
                   1418:     my $curVal = $self->{WIZARD}->{VARS}->{$var};
                   1419: 
                   1420:     my ($layout, $cols, $paper) = split(/\|/, $curVal);
                   1421: 
                   1422:     my $landscapeChecked = ($layout ne "L")? '' : 'checked ';
                   1423:     my $portraitChecked = $landscapeChecked ? '' : 'checked ';
                   1424: 
                   1425:     $result .= <<STATEHTML;
                   1426: 
                   1427: <p>How should the printing be formatted?</p>
                   1428: <table cellpadding="3">
                   1429:   <tr>
                   1430:     <td align="center"><b>Layout</b></td>
                   1431:     <td align="center"><b>Columns</b></td>
                   1432:     <td align="center"><b>Paper type</b></td>
                   1433:   </tr>
                   1434:   <tr>
                   1435:     <td>
                   1436:       <input type="radio" name="${var}.layout" value="L" $landscapeChecked> Landscape<br />
                   1437:       <input type="radio" name="${var}.layout" value="P" $portraitChecked> Portrait
                   1438:     </td>
                   1439:     <td>
                   1440:       <select name="${var}.cols">
                   1441: STATEHTML
                   1442: 
                   1443:     my $i;
                   1444:     for ($i = 1; $i <= $maxColumns; $i++) {
                   1445:         if ($i == $cols) {
                   1446:             $result .= "<option value='$i' selected>$i</option>\n";
                   1447:         } else {
                   1448:             $result .= "<option value='$i'>$i</option>\n";
                   1449:         }
                   1450:     }
                   1451: 
                   1452:     $result .= "</select></td><td>\n";
                   1453:     $result .= "<select name='${var}.paper'>\n";
                   1454: 
                   1455:     $i = 0;
                   1456:     foreach (@paperSize) {
                   1457:         if ($paper == $i) {
                   1458:             $result .= "<option selected value='$i'>" . $paperSize[$i] . "</option>\n";
                   1459:         } else {
                   1460:             $result .= "<option value='$i'>" . $paperSize[$i] . "</option>\n";
                   1461:         }
                   1462:         $i++;
                   1463:     }
                   1464: 
                   1465:     $result .= "</select></td></tr></table>";
                   1466:     return $result;
                   1467: }
                   1468: 
                   1469: 1;
                   1470: 
                   1471: package Apache::lonprintout::printwizfinal;
                   1472: 
                   1473: # This is the final state for the print wizard. It is not generally useful,
                   1474: # so it is not perldoc'ed.
                   1475: 
                   1476: no strict;
                   1477: @ISA = ('Apache::lonwizard::state');
                   1478: use strict;
                   1479: 
                   1480: sub new {
                   1481:     my $proto = shift;
                   1482:     my $class = ref($proto) || $proto;
                   1483:     my $self = bless $proto->SUPER::new(shift, shift, shift);
                   1484: 
                   1485:     # All other variables come from the wizard.
                   1486: }
                   1487: 
                   1488: sub render {
                   1489:     my $self = shift;
                   1490:     my $wizard = $self->{WIZARD};
                   1491:     my $wizvars = $wizard->{VARS};
                   1492: 
                   1493:     my $result = '';
                   1494: 
                   1495:     $result .= "<form method='get' action='/adm/printout'>\n";
                   1496: 
                   1497:     # Nope, I'm lost.
                   1498:     $result .= "</form>";
                   1499: }
                   1500: 
                   1501: 1;
                   1502: 
1.1       www      1503: __END__
1.6       sakharuk 1504: 

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