Diff for /loncom/interface/lonprintout.pm between versions 1.55 and 1.193

version 1.55, 2002/09/05 19:35:00 version 1.193, 2003/06/23 19:22:00
Line 45  use Apache::lonxml; Line 45  use Apache::lonxml;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon;  use Apache::loncommon;
 use Apache::inputtags;  use Apache::inputtags;
 use Apache::loncoursedata;  
 use Apache::grades;  use Apache::grades;
 use Apache::edit;  use Apache::edit;
 use Apache::File();  use Apache::File();
   use Apache::lonnavmaps;
 use POSIX qw(strftime);  use POSIX qw(strftime);
   use GDBM_File;
   
   
 sub headerform {  my %hash;
     my $r = shift;  my $LaTeXwidth = 0;
     $r->print(<<ENDHEADER);  
 <html>  
 <head>  sub latex_header_footer_remove {
 <title>LON-CAPA output for printing</title>      my $text = shift;
 </head>      $text =~ s/\\end{document}//;
 <body bgcolor="FFFFFF">      $text =~ s/\\documentclass([^&]*)\\begin{document}//;
 <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">      return $text;
 <tt>$ENV{'form.postdata'}</tt><p>  
 <h1>What do you want to print? Make a choice.</h1><br />  
 ENDHEADER  
 }  }
   
   
 sub menu_for_output {  sub character_chart {
     my $r = shift;      my $result = shift;
     $r->print(<<ENDMENUOUT1);      $result =~ s/&\#0?0?(7|9);//g;
 <input type="hidden" name="phase" value="two">      $result =~ s/&\#0?(10|13);//g;
 <input type="hidden" name="url" value="$ENV{'form.postdata'}">      $result =~ s/&\#0?32;/ /g;
 <input type="radio" name="choice" value="Standard LaTeX output for current document" checked>  Current document      $result =~ s/&\#0?33;/!/g;
 (you will print what you see on the screen)<br />      $result =~ s/&(\#0?34|quot);/\"/g;
 ENDMENUOUT1      $result =~ s/&\#0?35;/\\\#/g;
     if ((not $ENV{'request.role'}=~m/^au\./) and (not $ENV{'request.role'}=~m/^ca\./)) {      $result =~ s/&\#0?36;/\\\$/g;
  $r->print(<<ENDMENUOUT2);      $result =~ s/&\#0?37;/\\%/g; 
 <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence">  All problems from the primary sequence<br />      $result =~ s/&(\#0?38|amp);/\\&/g; 
 <input type="radio" name="choice" value="Standard LaTeX output for whole primary sequence">  The whole primary sequence (problems plus all html and xml files)<br />      $result =~ s/&\#(0?39|146);/\'/g;
 <input type="radio" name="choice" value="Standard LaTeX output for the top level sequence">  All problems from the top level sequence<br />      $result =~ s/&\#0?40;/(/g;
 <br />      $result =~ s/&\#0?41;/)/g;
 ENDMENUOUT2      $result =~ s/&\#0?42;/\*/g;
     }      $result =~ s/&\#0?43;/\+/g;
     if ($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) {       $result =~ s/&\#(0?44|130);/,/g;
  $r->print(<<ENDMENUOUT6);      $result =~ s/&\#0?45;/-/g;
   <input type="radio" name="choice" value="All class print">  Print assignment (all problems from the primary sequence) for group of students<br /><br />      $result =~ s/&\#0?46;/\./g;
 ENDMENUOUT6      $result =~ s/&\#0?47;/\//g;
     }      $result =~ s/&\#0?48;/0/g;
       my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});      $result =~ s/&\#0?49;/1/g;
       $subdirtoprint =~ s/\/[^\/]+$//;      $result =~ s/&\#0?50;/2/g;
       if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') {      $result =~ s/&\#0?51;/3/g;
   $r->print(<<ENDMENUOUT4);      $result =~ s/&\#0?52;/4/g;
   <input type="radio" name="choice" value="Subdirectory print">  All problems from current subdirectory (where this particular problem is)<br />      $result =~ s/&\#0?53;/5/g;
 ENDMENUOUT4      $result =~ s/&\#0?54;/6/g;
       }      $result =~ s/&\#0?55;/7/g;
     $r->print(<<ENDMENUOUT5);      $result =~ s/&\#0?56;/8/g;
 <br /><hr /><br />      $result =~ s/&\#0?57;/9/g;
 <h1>And what page format do you prefer?</h1>      $result =~ s/&\#0?58;/:/g;
 <table>      $result =~ s/&\#0?59;/;/g;
  <tr>      $result =~ s/&(\#0?60|lt|\#139);/\$<\$/g;
    <td>      $result =~ s/&\#0?61;/\$=\$/g;
      <input type="radio" name="layout" value="CBI"> Landscape <br />      $result =~ s/&(\#0?62|gt|\#155);/\$>\$/g;
      <input type="radio" name="layout" value="CAPA" checked>  Portrait <br />      $result =~ s/&\#0?63;/\?/g;
    </td>      $result =~ s/&\#0?65;/A/g;
    <td>&nbsp;</td>      $result =~ s/&\#0?66;/B/g;
    <td rawspan="2">      $result =~ s/&\#0?67;/C/g;
      Number of columns: <select name="numberofcolumns">      $result =~ s/&\#0?68;/D/g;
                          <option selected> 1 </option>      $result =~ s/&\#0?69;/E/g;
                          <option> 2 </option>      $result =~ s/&\#0?70;/F/g;
                          <option> 3 </option>      $result =~ s/&\#0?71;/G/g;
                          <option> 4 </option>      $result =~ s/&\#0?72;/H/g;
                          <option> 5 </option>      $result =~ s/&\#0?73;/I/g;
                          <option> 6 </option>      $result =~ s/&\#0?74;/J/g;
                          <option> 7 </option>      $result =~ s/&\#0?75;/K/g;
                          <option> 8 </option>      $result =~ s/&\#0?76;/L/g;
                          <option> 9 </option>      $result =~ s/&\#0?77;/M/g;
                         </select>       $result =~ s/&\#0?78;/N/g;
    </td>      $result =~ s/&\#0?79;/O/g;
  </tr>      $result =~ s/&\#0?80;/P/g;
 </table>      $result =~ s/&\#0?81;/Q/g;
 </br>       $result =~ s/&\#0?82;/R/g;
 <input type="submit" value="Submit your choice">      $result =~ s/&\#0?83;/S/g;
 ENDMENUOUT5      $result =~ s/&\#0?84;/T/g;
       $result =~ s/&\#0?85;/U/g;
       $result =~ s/&\#0?86;/V/g;
       $result =~ s/&\#0?87;/W/g;
       $result =~ s/&\#0?88;/X/g;
       $result =~ s/&\#0?89;/Y/g;
       $result =~ s/&\#0?90;/Z/g;
       $result =~ s/&\#0?91;/[/g;
       $result =~ s/&\#0?92;/\$\\setminus\$/g;
       $result =~ s/&\#0?93;/]/g;
       $result =~ s/&\#(0?94|136);/\$\\wedge\$/g;
       $result =~ s/&\#(0?95|138|154);/\\underline{\\makebox[2mm]{\\strut}}/g;
       $result =~ s/&\#(0?96|145);/\`/g;
       $result =~ s/&\#0?97;/a/g;
       $result =~ s/&\#0?98;/b/g;
       $result =~ s/&\#0?99;/c/g;
       $result =~ s/&\#100;/d/g;
       $result =~ s/&\#101;/e/g;
       $result =~ s/&\#102;/f/g;
       $result =~ s/&\#103;/g/g;
       $result =~ s/&\#104;/h/g;
       $result =~ s/&\#105;/i/g;
       $result =~ s/&\#106;/j/g;
       $result =~ s/&\#107;/k/g;
       $result =~ s/&\#108;/l/g;
       $result =~ s/&\#109;/m/g;
       $result =~ s/&\#110;/n/g;
       $result =~ s/&\#111;/o/g;
       $result =~ s/&\#112;/p/g;
       $result =~ s/&\#113;/q/g;
       $result =~ s/&\#114;/r/g;
       $result =~ s/&\#115;/s/g;
       $result =~ s/&\#116;/t/g;
       $result =~ s/&\#117;/u/g;
       $result =~ s/&\#118;/v/g;
       $result =~ s/&\#119;/w/g;
       $result =~ s/&\#120;/x/g;
       $result =~ s/&\#121;/y/g;
       $result =~ s/&\#122;/z/g;
       $result =~ s/&\#123;/\\{/g;
       $result =~ s/&\#124;/\|/g;
       $result =~ s/&\#125;/\\}/g;
       $result =~ s/&\#126;/\~/g;
       $result =~ s/&\#131;/\\textflorin /g;
       $result =~ s/&\#132;/\"/g;
       $result =~ s/&\#133;/\$\\ldots\$/g;
       $result =~ s/&\#134;/\$\\dagger\$/g;
       $result =~ s/&\#135;/\$\\ddagger\$/g;
       $result =~ s/&\#137;/\\textperthousand /g;
       $result =~ s/&\#140;/{\\OE}/g;
       $result =~ s/&\#147;/\`\`/g;
       $result =~ s/&\#148;/\'\'/g;
       $result =~ s/&\#149;/\$\\bullet\$/g;
       $result =~ s/&\#150;/--/g;
       $result =~ s/&\#151;/---/g;
       $result =~ s/&\#152;/\$\\sim\$/g;
       $result =~ s/&\#153;/\\texttrademark /g;
       $result =~ s/&\#156;/\\oe/g;
       $result =~ s/&\#159;/\\\"Y/g;
       $result =~ s/&(\#160|nbsp);//g;
       $result =~ s/&(\#161|iexcl);/!\`/g;
       $result =~ s/&(\#162|cent);/\\textcent /g;
       $result =~ s/&(\#163|pound);/\\pounds /g; 
       $result =~ s/&(\#164|curren);/\\textcurrency /g;
       $result =~ s/&(\#165|yen);/\\textyen /g;
       $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g;
       $result =~ s/&(\#167|sect);/\\textsection /g;
       $result =~ s/&(\#168|uml);/\\texthighdieresis /g;
       $result =~ s/&(\#169|copy);/\\copyright /g;
       $result =~ s/&(\#170|ordf);/\\textordfeminine /g;
       $result =~ s/&(\#172|not);/\$\\neg\$/g;
       $result =~ s/&(\#173|shy);/ - /g;
       $result =~ s/&(\#174|reg);/\\textregistered /g;
       $result =~ s/&(\#175|macr);/\$^{-}\$/g;
       $result =~ s/&(\#176|deg);/\$^{\\circ}\$/g;
       $result =~ s/&(\#177|plusmn);/\$\\pm\$/g;
       $result =~ s/&(\#178|sup2);/\$^2\$/g;
       $result =~ s/&(\#179|sup3);/\$^3\$/g;
       $result =~ s/&(\#180|acute);/\\textacute /g;
       $result =~ s/&(\#181|micro);/\$\\mu\$/g;
       $result =~ s/&(\#182|para);/\\P/g;
       $result =~ s/&(\#183|middot);/\$\\cdot\$/g;
       $result =~ s/&(\#184|cedil);/\\c{\\strut}/g;
       $result =~ s/&(\#185|sup1);/\$^1\$/g;
       $result =~ s/&(\#186|ordm);/\\textordmasculine /g;
       $result =~ s/&(\#188|frac14);/\\textonequarter /g;
       $result =~ s/&(\#189|frac12);/\\textonehalf /g;
       $result =~ s/&(\#190|frac34);/\\textthreequarters /g;
       $result =~ s/&(\#191|iquest);/?\`/g;   
       $result =~ s/&(\#192|Agrave);/\\\`{A}/g;  
       $result =~ s/&(\#193|Aacute);/\\\'{A}/g; 
       $result =~ s/&(\#194|Acirc);/\\^{A}/g;
       $result =~ s/&(\#195|Atilde);/\\~{A}/g;
       $result =~ s/&(\#196|Auml);/\\\"{A}/g; 
       $result =~ s/&(\#197|Aring);/{\\AA}/g;
       $result =~ s/&(\#198|AElig);/{\\AE}/g;
       $result =~ s/&(\#199|Ccedil);/\\c{c}/g;
       $result =~ s/&(\#200|Egrave);/\\\`{E}/g;  
       $result =~ s/&(\#201|Eacute);/\\\'{E}/g;    
       $result =~ s/&(\#202|Ecirc);/\\^{E}/g;
       $result =~ s/&(\#203|Euml);/\\\"{E}/g;
       $result =~ s/&(\#204|Igrave);/\\\`{I}/g;
       $result =~ s/&(\#205|Iacute);/\\\'{I}/g;    
       $result =~ s/&(\#206|Icirc);/\\^{I}/g;
       $result =~ s/&(\#207|Iuml);/\\\"{I}/g;    
       $result =~ s/&(\#209|Ntilde);/\\~{N}/g;
       $result =~ s/&(\#210|Ograve);/\\\`{O}/g;
       $result =~ s/&(\#211|Oacute);/\\\'{O}/g;
       $result =~ s/&(\#212|Ocirc);/\\^{O}/g;
       $result =~ s/&(\#213|Otilde);/\\~{O}/g;
       $result =~ s/&(\#214|Ouml);/\\\"{O}/g;    
       $result =~ s/&(\#215|times);/\$\\times\$/g;
       $result =~ s/&(\#216|Oslash);/{\\O}/g;
       $result =~ s/&(\#217|Ugrave);/\\\`{U}/g;    
       $result =~ s/&(\#218|Uacute);/\\\'{U}/g;
       $result =~ s/&(\#219|Ucirc);/\\^{U}/g;
       $result =~ s/&(\#220|Uuml);/\\\"{U}/g;
       $result =~ s/&(\#221|Yacute);/\\\'{Y}/g;
       $result =~ s/&(\#223|szlig);/\\ss/g;
       $result =~ s/&(\#224|agrave);/\\\`{a}/g;
       $result =~ s/&(\#225|aacute);/\\\'{a}/g;
       $result =~ s/&(\#226|acirc);/\\^{a}/g;
       $result =~ s/&(\#227|atilde);/\\~{a}/g;
       $result =~ s/&(\#228|auml);/\\\"{a}/g;
       $result =~ s/&(\#229|aring);/{\\aa}/g;
       $result =~ s/&(\#230|aelig);/{\\ae}/g;
       $result =~ s/&(\#231|ccedil);/\\c{c}/g;
       $result =~ s/&(\#232|egrave);/\\\`{e}/g;
       $result =~ s/&(\#233|eacute);/\\\'{e}/g;
       $result =~ s/&(\#234|ecirc);/\\^{e}/g;
       $result =~ s/&(\#235|euml);/\\\"{e}/g;
       $result =~ s/&(\#236|igrave);/\\\`{i}/g;
       $result =~ s/&(\#237|iacute);/\\\'{i}/g;
       $result =~ s/&(\#238|icirc);/\\^{i}/g;
       $result =~ s/&(\#239|iuml);/\\\"{i}/g;
       $result =~ s/&(\#240|eth);/\$\\partial\$/g;
       $result =~ s/&(\#241|ntilde);/\\~{n}/g;
       $result =~ s/&(\#242|ograve);/\\\`{o}/g;
       $result =~ s/&(\#243|oacute);/\\\'{o}/g;
       $result =~ s/&(\#244|ocirc);/\\^{o}/g;
       $result =~ s/&(\#245|otilde);/\\~{o}/g;
       $result =~ s/&(\#246|ouml);/\\\"{o}/g;
       $result =~ s/&(\#247|divide);/\$\\div\$/g;
       $result =~ s/&(\#248|oslash);/{\\o}/g;
       $result =~ s/&(\#249|ugrave);/\\\`{u}/g; 
       $result =~ s/&(\#250|uacute);/\\\'{u}/g;
       $result =~ s/&(\#251|ucirc);/\\^{u}/g;
       $result =~ s/&(\#252|uuml);/\\\"{u}/g;
       $result =~ s/&(\#253|yacute);/\\\'{y}/g;
       $result =~ s/&(\#255|yuml);/\\\"{y}/g;
       $result =~ s/&\#952;/\$\\theta\$/g;
   #Greek Alphabet
       $result =~ s/&(alpha|\#945);/\$\\alpha \$/g;
       $result =~ s/&(beta|\#946);/\$\\beta \$/g;
       $result =~ s/&(gamma|\#947);/\$\\gamma \$/g;
       $result =~ s/&(delta|\#948);/\$\\delta \$/g;
       $result =~ s/&(epsilon|\#949);/\$\\epsilon \$/g;
       $result =~ s/&(zeta|\#950);/\$\\zeta \$/g;
       $result =~ s/&(eta|\#951);/\$\\eta \$/g;
       $result =~ s/&(theta|\#952);/\$\\theta \$/g;
       $result =~ s/&(iota|\#953);/\$\\iota \$/g;
       $result =~ s/&(kappa|\#954);/\$\\kappa \$/g;
       $result =~ s/&(lambda|\#955);/\$\\lambda \$/g;
       $result =~ s/&(mu|\#956);/\$\\mu \$/g;
       $result =~ s/&(nu|\#957);/\$\\nu \$/g;
       $result =~ s/&(xi|\#958);/\$\\xi \$/g;
       $result =~ s/&(pi|\#960);/\$\\pi \$/g;
       $result =~ s/&(rho|\#961);/\$\\rho \$/g;
       $result =~ s/&(sigma|\#963);/\$\\sigma \$/g;
       $result =~ s/&(tau|\#964);/\$\\tau \$/g;
       $result =~ s/&(upsilon|\#965);/\$\\upsilon \$/g;
       $result =~ s/&(phi|\#966);/\$\\phi \$/g;
       $result =~ s/&(chi|\#967);/\$\\chi \$/g;
       $result =~ s/&(psi|\#968);/\$\\psi \$/g;
       $result =~ s/&(omega|\#969);/\$\\omega \$/g;
       $result =~ s/&(Gamma|\#915);/\$\\Gamma \$/g;
       $result =~ s/&(Delta|\#916);/\$\\Delta \$/g;
       $result =~ s/&(Theta|\#920);/\$\\Theta \$/g;
       $result =~ s/&(Lambda|\#923);/\$\\Lambda \$/g;
       $result =~ s/&(Xi|\#926);/\$\\Xi \$/g;
       $result =~ s/&(Pi|\#928);/\$\\Pi \$/g;
       $result =~ s/&(Sigma|\#931);/\$\\Sigma \$/g;
       $result =~ s/&(Upsilon|\#933);/\$\\Upsilon \$/g;
       $result =~ s/&(Phi|\#934);/\$\\Phi \$/g;
       $result =~ s/&(Psi|\#936);/\$\\Psi \$/g;
       $result =~ s/&(Omega|\#937);/\$\\Omega \$/g;
       return $result;
 }  }
   
   
 sub additional_class_menu {  sub page_format {
     my $r = shift;  #
     $r->print(<<ENDMENUOUT1);  #Correspondence between $papersize variable and real paper format:
 <input type="hidden" name="url" value="$ENV{'form.url'}">  # 0 - "Letter [8 1/2x11 in]"
 <input type="hidden" name="choice" value="$ENV{'form.choice'}">  # 1 - "Legal [8 1/2x14 in]"
 <input type="hidden" name="layout" value="$ENV{'form.layout'}">  # 2 - "Ledger/Tabloid [11x17 in]"
 <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">  # 3 - "Executive [7 1/2x10 in]"
 <h1>Mark students which assignments you want to print</h1>  # 4 - "A2 [420x594 mm]"
 ENDMENUOUT1  # 5 - "A3 [297x420 mm]"
     my $c = $r->connection;      # 6 - "A4 [210x297 mm]"
     my %cache;  # 7 - "A5 [148x210 mm]"
     my $courseID = $ENV{'request.course.id'};  # 8 - "A6 [105x148 mm]"
     my $classlist = &Apache::loncoursedata::DownloadClasslist($courseID,$cache{'ClasslistTimestamp'},$c);  # 
     &Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);          my ($papersize,$layout,$numberofcolumns) = @_; 
     my @all_students = split(':::',$cache{'NamesOfStudents'});      my ($textwidth,$textheight,$oddoffset,$evenoffset) = (0,0,0,0);
     my @active_students = ();      if ($papersize eq '0') {
     foreach my $student (@all_students) {   if ($layout eq 'book') {
  if ($cache{$student.':Status'} eq 'Active') {      if ($numberofcolumns == 1) {
     push @active_students,$student;   $textwidth = '7.1 in';      #'18 cm';
    $textheight = '10.2 in';    #'25.9 cm';
    $oddoffset = '-0.57 in';
    $evenoffset = '-0.57 in';
       } elsif ($numberofcolumns == 2) {
    $textwidth = '3.66 in';     #'93 mm';
    $textheight = '10.2 in';    #'25.9 cm';
    $oddoffset = '-0.57 in';
    $evenoffset = '-0.57 in';
       }
    } elsif ($layout eq 'album') {
       if ($numberofcolumns eq '1') {
    $textwidth = '8.8 in';
    $textheight = '6.8 in';
    $oddoffset = '-40 pt';
    $evenoffset = '-60 pt';
       } elsif ($numberofcolumns == 2) {
    $textwidth = '4.2 in';
    $textheight = '6.8 in';
    $oddoffset = '-40 pt';
    $evenoffset = '-60 pt';
       }
  }   }
   #    } elsif($papersize eq '1') {
   #    } elsif($papersize eq '2') {
   #    } elsif($papersize eq '3'/) {
       } elsif($papersize eq '6') {
    if ($layout eq 'book') {
       if ($numberofcolumns == 1) {
    $textwidth = '18 cm';
    $textheight = '28 cm';
    $oddoffset = '-0.57 in';
    $evenoffset = '-0.57 in';
       } elsif ($numberofcolumns == 2) {
    $textwidth = '96 mm';
    $textheight = '2 cm';
    $oddoffset = '-0.57 in';
    $evenoffset = '-0.57 in';
       }
    } elsif ($layout eq 'album') {
       if ($numberofcolumns eq '1') {
    $textwidth = '8.5 in';
    $textheight = '7.7 in';
    $oddoffset = '-40 pt';
    $evenoffset = '-60 pt';
       } elsif ($numberofcolumns == 2) {
    $textwidth = '3.9 in';
    $textheight = '7.7 in';
    $oddoffset = '-40 pt';
    $evenoffset = '-60 pt';
       }
    }
   #    } elsif($papersize eq '5') {
   #    } elsif($papersize eq '4') {
   #    } elsif($papersize eq '7') {
   #    } elsif($papersize eq '8') {
     }      }
     my $what_to_print = '<table border="1">';          return $textwidth,$textheight,$oddoffset,$evenoffset;
     my $i = 0;  
     foreach my $student (@active_students) {  
  $what_to_print .= '<tr><td><input type="checkbox" name="whomtoprint'.$i.'" value="'.$student.'">'.$cache{$student.':fullname'}.'</td></tr>';  
 # $what_to_print .= '<tr><td><input type="checkbox" name="whomtoprint'.$i.'" value="'.$cache{$student.':fullname'}.'">'.$cache{$student.':fullname'}.'</td></tr>';  
  $i++;  
     }  
     $what_to_print .= '</table>';  
     $r->print(<<ENDMENUOUT2);  
     $what_to_print <br />  
 <input type="hidden" name="numberofstudents" value="$i">  
 <input type="hidden" name="phase" value="three">  
 <input type="submit" value="Submit">  
 ENDMENUOUT2  
 }  }
   
   
 sub additional_print_menu {   sub get_name {
     my $r = shift;      my ($uname,$udom)=@_;
     my $what_to_print = '';      if (!defined($uname)) { $uname=$ENV{'user.name'}; }
     for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {      if (!defined($udom)) { $uname=$ENV{'user.domain'}; }
  $what_to_print .= '<input type="hidden" name="whomtoprint'.$i.'" value="'.$ENV{'form.whomtoprint'.$i}.'">';      my $plainname=&Apache::loncommon::plainname($uname,$udom);
     }      if ($plainname=~/^\s*$/) { $plainname=$uname; }
     $r->print(<<ENDMENUOUT);      return &Apache::lonxml::latex_special_symbols($plainname,undef,undef,
     $what_to_print    'header');
 <input type="hidden" name="url" value="$ENV{'form.url'}">  }
 <input type="hidden" name="choice" value="$ENV{'form.choice'}">  
 <input type="hidden" name="layout" value="$ENV{'form.layout'}">  
 <input type="hidden" name="numberofstudents" value="$ENV{'form.numberofstudents'}">  sub page_format_transformation {
 <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">      my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment) = @_; 
 Enter width of the page: <input type="text" name="width" width="10" value="9cm"> <br />      my ($textwidth,$textheight,$oddoffset,$evenoffset);
 <input type="hidden" name="phase" value="four">   $assignment=~s/_/ /g;
 <input type="submit" value="Submit">          if ($numberofcolumns != 1) {
 </form>            ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns);
 </body>   } else {
 </html>    ($textwidth,$textheight,$oddoffset,$evenoffset) = ($ENV{'form.width'},$ENV{'form.height'},$ENV{'form.leftmargin'},$ENV{'form.leftmargin'});
 ENDMENUOUT   }
       my $name = &get_name();
       if ($name =~ /^\s*$/) {
    $name=&Apache::lonxml::latex_special_symbols($ENV{'user.name'},undef,
        undef,'header');
       }
       my $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'','','header');
       if ($layout eq 'album') {
       $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{$name}} \\hfill  $courseidinfo} \\vskip 5 mm /;
       } elsif ($layout eq 'book') {
    if ($choice ne 'All class print') { 
       $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{$name} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}/;
    } else {
       $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 /;
    }
       }
       return $text;
   }
   
   
   sub page_cleanup {
       my $result = shift;
    
       $result =~ m/\\end{document}(\d*)$/;
       my $number_of_columns = $1;
       my $insert = '{';
       for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
       $insert .= '}';
       $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
       $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
       return $result,$number_of_columns;
   }
   
   
   sub details_for_menu {
   
       my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}};
       my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'});
       my ($map,$id,$resource)=split(/___/,$symbolic);
       $map=&Apache::lonnet::clutter($map);
       my $name_of_sequence;
       $name_of_sequence = $hash{'title_'.$hash{'ids_'.$map}};
       if ($name_of_sequence =~ /^\s*$/) {
    $map =~ m|([^/]+)$|;
    $name_of_sequence = $1;
       }
       my $name_of_map = $hash{'title_'.$hash{'ids_'.&Apache::lonnet::clutter($ENV{'request.course.uri'})}};
       if ($name_of_map =~ /^\s*$/) {
    $ENV{'request.course.uri'} =~ m|([^/]+)$|;
    $name_of_map = $1;
       }
       return ($name_of_resourse,$name_of_sequence,$name_of_map);
   
   }
   
   
   sub latex_corrections {
   
       my ($number_of_columns,$result) = @_;
   
   #    $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
       $result =~ s/\$number_of_columns/$number_of_columns/g;
       $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/;
       $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
       $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g;
   #-- LaTeX corrections     
       my $first_comment = index($result,'<!--',0);
       while ($first_comment != -1) {
    my $end_comment = index($result,'-->',$first_comment);
    substr($result,$first_comment,$end_comment-$first_comment+3) = '';
    $first_comment = index($result,'<!--',$first_comment);
       }
       $result =~ s/^\s+$//gm; #remove empty lines
       $result =~ s/(\s)(\s+)/$1/g; #removes more than one empty space
       $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
       $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
       $result =~ s/{\\par }\s*\\\\/\\\\/gm;
    $result =~ s/\\\\\s+\[/ \[/g;
       $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
       #conversion of html characters to LaTeX equivalents
       if ($result =~ m/&(\w+|#\d+);/) {
    $result = &character_chart($result);
       }
       $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
       $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
   
       return $result;
 }  }
   
   
 sub output_data {  sub output_data {
     my $r = shift;      my ($r,$helper,$rparmhash) = @_;
       my %parmhash = %$rparmhash;
       my $bodytag=&Apache::loncommon::bodytag('Preparing Printout');
     $r->print(<<ENDPART);      $r->print(<<ENDPART);
 <html>  <html>
 <head>  <head>
 <title>LON-CAPA output for printing</title>  <title>LON-CAPA output for printing</title>
 </head>  </head>
 <body bgcolor="FFFFFF">  $bodytag
 <hr>  Please stand by while processing your print request, this may take some time ...
 ENDPART  ENDPART
   
     my $choice = $ENV{'form.choice'};      my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
     my $layout = $ENV{'form.layout'};      my ($result,$selectionmade) = ('','');
     my $numberofcolumns = $ENV{'form.numberofcolumns'};                     my $number_of_columns = 1; #used only for pages to determine the width of the cell
     my $laystyle = 'book';      my @temporary_array=split /\|/,$format_from_helper;
     my $result = '';      my ($laystyle,$numberofcolumns,$papersize)=@temporary_array;
     my $number_of_columns = 1;      if ($laystyle eq 'L') {
     $laystyle='album';
     if ($choice eq 'Standard LaTeX output for current document') {      } else {
       #-- single document - problem, page, html, xml     $laystyle='book';
       my %moreenv;      }
       $moreenv{'form.grade_target'}='tex';      my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns);
       if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {      my $assignment =  $ENV{'form.assignment'};
   $ENV{'form.url'}=~s/http:\/\/[^\/]+//;      my $LaTeXwidth; 
       }      if ($textwidth=~/(\d+\.?\d*)\s*cm/) {
       $moreenv{'request.filename'}=$ENV{'form.url'};   $LaTeXwidth = $1*10;
       &Apache::lonnet::appenv(%moreenv);      } elsif ($textwidth=~/(\d+\.?\d*)\s*mm/) {
       my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});   $LaTeXwidth = $1;
       &Apache::lonnet::delenv('form.grade_target');      } elsif ($textwidth=~/(\d+\.?\d*)\s*in/) {
       $result .= $texversion;   $LaTeXwidth = $1*25.4;
       $result = &additional_cleanup($result);      }
       if ($ENV{'form.url'}=~m/\.page\s*$/) {      $LaTeXwidth.=' mm';
   ($result,$number_of_columns) = &page_cleanup($result);      
       }      if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {
     } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or         #-- single document - problem, page, html, xml, ...
              $choice eq 'Standard LaTeX output for whole primary sequence') {   my $currentURL;
       #-- minimal sequence to which the current document belongs   if ($helper->{'VARS'}->{'construction'} ne '1') {
         #-- where is the primary sequence containing file?              #prints published resource
  my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});      $currentURL=$helper->{'VARS'}->{'postdata'};
  $_ = $symbolic;   } else {
  m/([^_]+)_/;              #prints resource from the construction space
  my $primary_sequence = '/res/'.$1;      $currentURL=$helper->{'VARS'}->{'filename'};
         #-- open and analyses the primary sequence      $currentURL=~s/\/home\//\/~/;
  my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);      $currentURL=~s/public_html\///;
  my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);  
  my @master_seq = &content_map($sequencefilecontents);  
         #-- produce an output string  
  for (my $i=0;$i<=$#master_seq;$i++) {  
     $_ = $master_seq[$i];  
     m/\"(.*)\"/;  
             $_ = $1;  
             my $urlp = $1;  
     if ($choice eq 'Standard LaTeX output for the primary sequence') {  
  if ($urlp =~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {  
     my %moreenv;  
     $moreenv{'form.grade_target'}='tex';  
     &Apache::lonnet::appenv(%moreenv);  
     my $texversion=&Apache::lonnet::ssi($urlp);  
     &Apache::lonnet::delenv('form.grade_target');  
     $result .= $texversion;          
  }  
     } elsif ($urlp =~ /\S+/) {  
  my %moreenv;  
  $moreenv{'form.grade_target'}='tex';  
  &Apache::lonnet::appenv(%moreenv);  
  my $texversion=&Apache::lonnet::ssi($urlp);  
  &Apache::lonnet::delenv('form.grade_target');  
  $result .= $texversion;      
     }  
  }  
  $result = &additional_cleanup($result);  
     }  elsif ($choice eq 'Standard LaTeX output for the top level sequence') {  
         # where is the main sequence of the course?  
  my $main_seq = '/res/'.$ENV{'request.course.uri'};  
  my $file=&Apache::lonnet::filelocation("",$main_seq);  
  my $filecontents=&Apache::lonnet::getfile($file);  
  my @file_seq = &content_map($filecontents);  
  for (my $iu=0;$iu<=$#file_seq;$iu++) {  
     $file_seq[$iu]=~s/^"//;  
     $file_seq[$iu]=~s/"$//;  
     if ($file_seq[$iu]=~m/\S+/) {  
  $file_seq[$iu]=&Apache::lonnet::filelocation("",$file_seq[$iu]);  
     } else {  
  $file_seq[$iu]= 'REMOVE IT PLEASE';  
     }  
  }   }
  my $i=0;   $selectionmade = 1;
         my $limit = $#file_seq;       if ($currentURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
         while ($i<=$limit) {      my %moreenv;
     unless ($file_seq[$i]=~m/\.(problem|page)/) {      $moreenv{'request.filename'}=$currentURL;
  if ($file_seq[$i]=~m/\.sequence/) {      my %form;
     my $filecontents=&Apache::lonnet::getfile($file_seq[$i]);      $form{'grade_target'}='tex';
     my @newfile_seq = &content_map($filecontents);      $form{'textwidth'}=$LaTeXwidth;
     for (my $iu=0;$iu<=$#newfile_seq;$iu++) {      my $rndseed=time;
  $newfile_seq[$iu]=~s/^"//;      $form{'rndseed'}=$rndseed;
                 $newfile_seq[$iu]=~s/"$//;      &Apache::lonnet::appenv(%moreenv);
  if ($newfile_seq[$iu]=~m/\S+/) {      my $texversion=&Apache::lonnet::ssi($currentURL,%form);
     $newfile_seq[$iu]=&Apache::lonnet::filelocation("",$newfile_seq[$iu]);      &Apache::lonnet::delenv('form.counter');
  } else {      &Apache::lonnet::delenv('request.filename');
     $newfile_seq[$iu]= 'REMOVE IT PLEASE';      if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
  }   my %form;
     }   $form{'grade_target'}='answer';
     splice @file_seq,$i,1,@newfile_seq;   $form{'answer_output_mode'}='tex';
     $i=0;   $form{'rndseed'}=$rndseed;
     $limit = $#file_seq;   my $answer=&Apache::lonnet::ssi($currentURL,%form);
  } else {   $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
     splice @file_seq,$i,1,'REMOVE IT PLEASE';  
  }  
     }      }
     $i++;      $result .= $texversion;
  }      if ($currentURL=~m/\.page\s*$/) {
  for (my $iu=0;$iu<=$#file_seq;$iu++) {   ($result,$number_of_columns) = &page_cleanup($result);
     if ($file_seq[$iu]=~m/REMOVE IT PLEASE/) {  
  splice @file_seq,$iu,1;  
     }      }
    } else {
   #  $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: ';
   #  if ($ENV{'form.url'}=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) {
   #      $result.=$1;
   #  } else {
   #      $result.=$ENV{'form.url'};
   #  }
   #  $result.=' \end{document}'
  }   }
  if ($file_seq[-1]=~m/REMOVE IT PLEASE/) {      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or
     pop @file_seq;               ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
  }               ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')) { 
         #-- produce an output string          #-- produce an output string
  for (my $i=0;$i<=$#file_seq;$i++) {   my %form=();   
             my $urlp = $file_seq[$i];   $form{'grade_target'}='tex';
     $urlp=~s/\/home\/httpd\/html//;       $form{'textwidth'}=$LaTeXwidth;
             if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) {   $form{'problem_split'}=$parmhash{'problem_stream_switch'};
  my %moreenv;   my $flag_latex_header_remove = 'NO';
  $moreenv{'form.grade_target'}='tex';   my $flag_page_in_sequence = 'NO';
  &Apache::lonnet::appenv(%moreenv);   my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
  my $texversion=&Apache::lonnet::ssi($urlp);   my $prevassignment='';
  &Apache::lonnet::delenv('form.grade_target');   for (my $i=0;$i<=$#master_seq;$i++) {
  $result .= $texversion;              $master_seq[$i]=~/___\d+___(.*)$/;
     }      my $urlp='/res/'.$1;
  }          if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') {
  $result = &additional_cleanup($result);   $selectionmade = 2;
     } elsif ($choice eq 'All class print') {       } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {
     #-- prints assignments for whole class or for selected students     $selectionmade = 3;
         my (@students,@st_output) = ((),());      } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') {
  for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {   $selectionmade = 4;
     if ($ENV{'form.whomtoprint'.$i}=~/:/) {      }
  push @students,$ENV{'form.whomtoprint'.$i};      $form{'symb'}=$master_seq[$i];
       $master_seq[$i]=~/\/([^\/]+)\.sequence_/;
       my $assignment=' '.$1.' ';
       #&Apache::lonnet::logthis("Trying to get $urlp with symb $master_seq[$i]");
       my $texversion=&Apache::lonnet::ssi($urlp,%form);
       if ($urlp=~/\.page$/) {
    ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
    if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;} 
    $texversion =~ s/\\end{document}\d*/\\end{document}/;
    $flag_page_in_sequence = 'YES';
       } 
       if ($flag_latex_header_remove ne 'NO') {
    $texversion = &latex_header_footer_remove($texversion);
       } else {
    $texversion =~ s/\\end{document}//;
       }
       if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
    my %form;
    $form{'grade_target'}='answer';
    $form{'answer_output_mode'}='tex';
    my $answer=&Apache::lonnet::ssi($urlp,%form);
    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
     }      }
   #    $result .= $texversion;
       if (($selectionmade == 4) and ($assignment ne $prevassignment) and ($i>1)) {
    my $name = &get_name();
    if ($name =~ /^\s*$/) {
       $name=&Apache::lonxml::latex_special_symbols($ENV{'user.name'},undef,
    undef,'header');
    }
    my $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'','','header');
    $prevassignment=$assignment;
    $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}} - '.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip -5 mm ';
       }
       $result .= $texversion;
       $flag_latex_header_remove = 'YES';   
  }   }
  #where is the primary sequence containing current resource (the same for all students)?   &Apache::lonnet::delenv('form.counter');
  my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});   if ($flag_page_in_sequence eq 'YES') {$result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;}
  $symbolic =~ m/([^_]+)_/;   $result .= '\end{document}';
  my $primary_sequence = '/res/'.$1;       } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') { 
  #opens and analyses the primary sequence file, produces the array of resources       #-- prints assignments for whole class or for selected students  
  my $sequence_file=&Apache::lonnet::filelocation("",$primary_sequence);   $selectionmade=5;
  my $sequencefilecontents=&Apache::lonnet::getfile($sequence_file);   my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'};
  my @master_seq = &content_map($sequencefilecontents);   my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
         #loop over students   #loop over students
  foreach my $person (@students) {   my $flag_latex_header_remove = 'NO'; 
    my %moreenv;
    $moreenv{'form.textwidth'}=$LaTeXwidth;
    &Apache::lonnet::appenv(%moreenv);
    my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1);
    foreach my $person (@students) {
     my $current_output = '';       my $current_output = ''; 
   #    my ($usersection,$username,$userdomain) = split /:/,$person;
     my ($username,$userdomain) = split /:/,$person;      my ($username,$userdomain) = split /:/,$person;
     my $fullname = &Apache::grades::get_fullname($username,$userdomain);      my $fullname = &get_name($username,$userdomain);
             #goes through all resources, checks if they are available for current student, and produces output               #goes through all resources, checks if they are available for current student, and produces output   
     foreach my $curres (@master_seq)  {      foreach my $curresline (@master_seq)  {
  $curres =~ s/^"//;   if ($curresline=~ m/\.(problem|exam|quiz|assess|survey|form|library)$/) {
  $curres =~ s/"$//;      my ($map,$id,$res_url) = split(/___/,$curresline);
                 if ($curres=~/\w+/) {  
     my $symb = &Apache::lonnet::symbread($curres);  
     my ($map,$id,$res_url) = split(/___/,$symb);  
     if (&Apache::lonnet::allowed('bre',$res_url)) {      if (&Apache::lonnet::allowed('bre',$res_url)) {
  my $rendered = &Apache::loncommon::get_student_view($symb,$username,$userdomain,   my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,
                                                                         $ENV{'request.course.id'},'tex');                                                                          $ENV{'request.course.id'},'tex');
    if ($flag_latex_header_remove eq 'YES') {
       $rendered = &latex_header_footer_remove($rendered);
    } else {
       $rendered =~ s/\\end{document}//;
    }
    if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
       my %form;
       $form{'answer_output_mode'}='tex';
       my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$ENV{'request.course.id'},%form);
       $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/;
    }
  $current_output .= $rendered;   $current_output .= $rendered;
     }      }
       $flag_latex_header_remove = 'YES';
  }   }
     }      }
     $current_output =~ s/\\begin{document}/\\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$fullname}}\\hskip 1\.4in } \\vskip 5 mm /;      my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
     $result .= $current_output;      if ($current_output=~/\\documentclass/) {
  }   $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$helper->{VARS}->{'assignment'}}}\\vskip 3 mm /;
       } else {
  $result = &additional_cleanup($result);   my $blanspages = '';
    for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blanspages.='\clearpage\strut\clearpage';}
    $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 '.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}} - '.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$helper->{VARS}->{'assignment'}.'}}} \vskip -5 mm '.$current_output;
   
   
   
   
     } elsif ($choice eq 'Subdirectory print') {        
  my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});  
  $subdirtoprint =~ s/\/[^\/]+$//;  
  my @list_of_files = ();  
  if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {  
     $subdirtoprint =~ s/^[^~]*~(\w+)\//\/home\/$1\/public_html\//;  
  } else {  
     $subdirtoprint =~ s/.*(\/res\/)/$1/;  
  }  
  my @content_directory = ();  
  if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {  
     @content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},'');  
  } else {  
     @content_directory = &Apache::lonnet::dirlist($subdirtoprint);  
  }  
  for (my $iy=0;$iy<=$#content_directory;$iy++) {  
     my @tempo_array = split(/&/,$content_directory[$iy]);  
     if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) {  
  push(@list_of_files,$tempo_array[0]);  
     }      }
       $result .= $current_output;
       &Apache::lonnet::delenv('form.counter');    
       &Apache::lonxml::init_counter(); 
       &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
       'last student '.$fullname);
  }   }
  $subdirtoprint =~ s/\/$//;   &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
    $result .= '\end{document}';
    &Apache::lonnet::delenv('form.textwidth');
       } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') {      
       #prints selected problems from the subdirectory 
    $selectionmade = 6;
           my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
    @list_of_files=sort @list_of_files;
    my $flag_latex_header_remove = 'NO'; 
    my $rndseed=time;
  for (my $i=0;$i<=$#list_of_files;$i++) {   for (my $i=0;$i<=$#list_of_files;$i++) {
     my $urlp = $subdirtoprint.'/'.$list_of_files[$i];      my $urlp = $list_of_files[$i];
     my %moreenv;      if ($urlp=~/\//) {
     $moreenv{'form.grade_target'}='tex';   my %form;
     &Apache::lonnet::appenv(%moreenv);   $form{'grade_target'}='tex';
     if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) {    $form{'textwidth'}=$LaTeXwidth;
  $urlp =~ s/\/home\/([^\/]*)\/public_html/\/~$1/;    $form{'rndseed'}=$rndseed;
    if ($urlp =~ m|/home/([^/]+)/public_html|) {
       $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
    } else {
       $urlp =~ s|^/home/httpd/html||;
    }
    my $texversion=&Apache::lonnet::ssi($urlp,%form);
    if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
       my %form;
       $form{'grade_target'}='answer';
       $form{'answer_output_mode'}='tex';
       $form{'rndseed'}=$rndseed;
       my $answer=&Apache::lonnet::ssi($urlp,%form);
       $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
    }
                   #this chunck is responsible for printing the path to problem
    my $newurlp = '';
    my $HowMany = length($urlp)*2;
    if ($HowMany > $LaTeXwidth) {
       my @temporrary = split '/',$urlp;
       my $HowManyNew = 0;
       for (my $ii=0;$ii<=$#temporrary;$ii++) {
    if ($temporrary[$ii] ne '') {
       $HowManyNew += length($temporrary[$ii])*2;
       if ($HowManyNew < $LaTeXwidth ) {
    $newurlp .=  '/'.$temporrary[$ii];
       } else {
    $HowManyNew = 0;
    $newurlp .=  '|\vskip -1 mm \noindent \verb|';
    $ii--;
       }
    }
       }
    }
    $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/;
    if ($flag_latex_header_remove ne 'NO') {
       $texversion = &latex_header_footer_remove($texversion);
    } else {
       $texversion =~ s/\\end{document}//;
    }
    $result .= $texversion;
     }      }
     my $texversion=&Apache::lonnet::ssi($urlp);      $flag_latex_header_remove = 'YES';  
     &Apache::lonnet::delenv('form.grade_target');  
     $texversion =~ s/(\\begin{document})/$1 {\\tiny\\begin{verbatim}$urlp\\end{verbatim}}/;  
     $result .= $texversion;     
  }   }
  $result = &additional_cleanup($result);   if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\typeout)/ RANDOM SEED IS $rndseed $1/;}
    $result .= '\end{document}';      
          
     }  
 #-- corrections for the different page formats  
     if ($layout eq 'CBI' and $numberofcolumns eq '1') {  
     } elsif ($layout eq 'CBI' and $numberofcolumns eq '2') {  
  $result =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{-40pt}\\setlength{\\evensidemargin}{-60pt}\\setlength{\\topmargin}{200pt}\\setlength{\\textwidth}{4\.4in}\\setlength{\\textheight}{6\.8in}\\setlength{\\parindent}{20pt}\\setlength{\\marginparwidth}{90pt}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt} \\begin{document}/;  
         $laystyle = 'album';  
     } elsif ($layout eq 'CAPA') {  
         my $courseidinfo = $ENV{'request.role'};  
         $_ = $courseidinfo;  
         m/.*\/(.*)/;  
         $courseidinfo = $ENV{'course.physnet_'.$1.'.description'};  
 # $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass\[twocolumn\]{article}/;  
  $result =~ s/\\documentclass\[letterpaper\]{article}/\\documentclass{article}/;  
  $result =~ s/\\begin{document}/\\textheight 25\.9cm\\oddsidemargin = -0\.57in\\evensidemargin = -0\.57in\\textwidth= 9cm\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\begin{document}\\voffset=-1\.8cm\\setcounter{page}{1}\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$ENV{'environment.firstname'} $ENV{'environment.lastname'}}}\\hskip 1\.4in $courseidinfo} \\vskip 5 mm /;  
  $result =~ s/\\includegraphics{/\\includegraphics\[width=9\.0 cm\]{/g;  
 # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\textwidth\]{/g;  
 # $result =~ s/(\\end{document})/\\newline\\noindent\\makebox\[9.0cm\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny Dept\. of Physics and Astronomy, MSU\\makebox\[1.5cm\]\[b\]{\\hfill}LON-CAPA\\copyright MSU GNU\/GPL $1/;  
  $result =~ s/(\\end{document})/\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill}\\newline\\noindent\\tiny \\makebox\[1.5cm\]\[b\]{\\hfill}LON-CAPA\\copyright Michigan State University Board of Trustees $1/;  
 #        $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[9\.0cm\]\[b\]{\\hrulefill})/$2$1/g;  
         $result =~ s/(\\end{longtable}\s*)(\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;  
         $result =~ s/(\\end{longtable}\s*)\\newline/$1/g;  
  $result =~ s/\$number_of_columns/$number_of_columns/g;  
     }      }
   #-------------------------------------------------------- corrections for the different page formats
       $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'});
       $result = &latex_corrections($number_of_columns,$result);
     #changes page's parameters for the one column output       #changes page's parameters for the one column output 
     if ($ENV{'form.numberofcolumns'} == 1) {  #    if ($numberofcolumns == 1) {
  $result =~ s/\\textwidth= 9cm/\\textwidth= $ENV{'form.width'}/;  # $result =~ s/\\textwidth= 9cm/\\textwidth= $ENV{'form.width'}/;
     }  # $result =~ s/\\textheight 25\.9cm/\\textheight $ENV{'form.height'}/;
 #-- LaTeX corrections       # $result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $ENV{'form.leftmargin'}/;
     my $first_comment = index($result,'<!--',0);  # $result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $ENV{'form.leftmargin'}/;
     while ($first_comment != -1) {  #    }
  my $end_comment = index($result,'-->',$first_comment);  
  substr($result,$first_comment,$end_comment-$first_comment+3) = '';  
  $first_comment = index($result,'<!--',$first_comment);  
     }  
     $result =~ s/^\s+$//gm; #remove empty lines  
     $result =~ s/(\s)+/$1/g; #removes more than one empty space  
     $result =~ s/\\\\\s*\\vskip/\\vskip/gm;  
     $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;  
     $result =~ s/{\\par }\s*\\\\/\\\\/gm;  
  $result =~ s/\\\\\s+\[/ \[/g;  
     $result =~ s/&#952;/\$\\theta\$/g; #converts theta from html into tex  
     $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;  
     #conversion of html characters to LaTeX equivalents  
     if ($result =~ m/&(\w+|#\d+);/) {  
  $result = &character_chart($result);  
     }  
     $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;  
     $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;  
 #-- writing .tex file in prtspool   #-- writing .tex file in prtspool 
     my $temp_file;      my $temp_file;
     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";      my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
Line 460  ENDPART Line 775  ENDPART
  return SERVER_ERROR;    return SERVER_ERROR; 
     }       } 
     print $temp_file $result;      print $temp_file $result;
   
   #<meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns&$selectionmade">
 $r->print(<<FINALEND);  $r->print(<<FINALEND);
 <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns">  <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns&$selectionmade">
 </body>  </body>
 </html>  </html>
 FINALEND  FINALEND
 }  }
   
 sub character_chart {  
     my $result = shift;  
     $result =~ s/&#0?0?7;//g;  sub handler {
     $result =~ s/&#0?0?9;//g;  
     $result =~ s/&#0?10;//g;      my $r = shift;
     $result =~ s/&#0?13;//g;      my $helper;
     $result =~ s/&#0?32;/ /g;  
     $result =~ s/&#0?33;/!/g;  #    my $loaderror=&Apache::lonnet::overloaderror($r);
     $result =~ s/&#0?34;/"/g;  #    if ($loaderror) { return $loaderror; }
     $result =~ s/&quot;/"/g;   #    $loaderror=
     $result =~ s/&#0?35;/\\#/g;  #       &Apache::lonnet::overloaderror($r,
 #    $result =~ s/&#0?36;/\\\$/g;  #         $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
     $result =~ s/&#0?37;/\\%/g;   #    if ($loaderror) { return $loaderror; }
     $result =~ s/&#0?38;/\\&/g;   
     $result =~ s/&amp;/\\&/g;      my $result = printHelper($r);
     $result =~ s/&#0?39;/'/g;      if (!ref($result)) {
     $result =~ s/&#0?40;/(/g;   return $result;
     $result =~ s/&#0?41;/)/g;      }
     $result =~ s/&#0?42;/\*/g;      $helper = $result;
     $result =~ s/&#0?43;/\+/g;     
     $result =~ s/&#0?44;/,/g;  # my $key; 
     $result =~ s/&#0?45;/-/g;  # foreach $key (keys %{$helper->{'VARS'}}) {
     $result =~ s/&#0?46;/\./g;  #    $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'<-<br />');
     $result =~ s/&#0?47;/\//g;  # }
     $result =~ s/&#0?48;/0/g;  # return OK;
     $result =~ s/&#0?49;/1/g;  
     $result =~ s/&#0?50;/2/g;      my %parmhash=&Apache::lonnet::coursedescription($ENV{'request.course.id'});
     $result =~ s/&#0?51;/3/g;      
     $result =~ s/&#0?52;/4/g;  
     $result =~ s/&#0?53;/5/g;      &output_data($r,$helper,\%parmhash);
     $result =~ s/&#0?54;/6/g;      return OK;
     $result =~ s/&#0?55;/7/g;  } 
     $result =~ s/&#0?56;/8/g;  
     $result =~ s/&#0?57;/9/g;  use Apache::lonhelper;
     $result =~ s/&#0?58;/:/g;  
     $result =~ s/&#0?59;/;/g;  sub printHelper {
     $result =~ s/&#0?60;/\$<\$/g;      my $r = shift;
     $result =~ s/&lt;/\$<\$/g;  
     $result =~ s/&#0?61;/\$=\$/g;      if ($ENV{'request.course.id'}) {
     $result =~ s/&#0?62;/\$>\$/g;   my $fn=$ENV{'request.course.fn'};
     $result =~ s/&gt;/\$>\$/g;   tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640);
     $result =~ s/&#0?63;/?/g;      }
 #    $result =~ s/&#0?64;//g;  
     $result =~ s/&#0?65;/A/g;      if ($r->header_only) {
     $result =~ s/&#0?66;/B/g;          if ($ENV{'browser.mathml'}) {
     $result =~ s/&#0?67;/C/g;              $r->content_type('text/xml');
     $result =~ s/&#0?68;/D/g;          } else {
     $result =~ s/&#0?69;/E/g;              $r->content_type('text/html');
     $result =~ s/&#0?70;/F/g;          }
     $result =~ s/&#0?71;/G/g;          $r->send_http_header;
     $result =~ s/&#0?72;/H/g;          return OK;
     $result =~ s/&#0?73;/I/g;      }
     $result =~ s/&#0?74;/J/g;  
     $result =~ s/&#0?75;/K/g;      # Send header, nocache
     $result =~ s/&#0?76;/L/g;      if ($ENV{'browser.mathml'}) {
     $result =~ s/&#0?77;/M/g;          $r->content_type('text/xml');
     $result =~ s/&#0?78;/N/g;      } else {
     $result =~ s/&#0?79;/O/g;          $r->content_type('text/html');
     $result =~ s/&#0?80;/P/g;      }
     $result =~ s/&#0?81;/Q/g;      &Apache::loncommon::no_cache($r);
     $result =~ s/&#0?82;/R/g;      $r->send_http_header;
     $result =~ s/&#0?83;/S/g;      $r->rflush();
     $result =~ s/&#0?84;/T/g;  
     $result =~ s/&#0?85;/U/g;      # Unfortunately, this helper is so complicated we have to
     $result =~ s/&#0?86;/V/g;      # write it by hand
     $result =~ s/&#0?87;/W/g;  
     $result =~ s/&#0?88;/X/g;      Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
     $result =~ s/&#0?89;/Y/g;      
     $result =~ s/&#0?90;/Z/g;      my $helper = Apache::lonhelper::helper->new("Printing Helper");
     $result =~ s/&#0?91;/[/g;      $helper->declareVar('symb');
     $result =~ s/&#0?92;/\\/g;      $helper->declareVar('postdata');    
     $result =~ s/&#0?93;/]/g;      $helper->declareVar('filename');
 #    $result =~ s/&#0?94;//g;      $helper->declareVar('construction');
 #    $result =~ s/&#0?95;//g;      $helper->declareVar('assignment');
     $result =~ s/&#0?96;/`/g;      
     $result =~ s/&#0?97;/a/g;      # This will persistently load in the data we want from the
     $result =~ s/&#0?98;/b/g;      # very first screen.
     $result =~ s/&#0?99;/c/g;      # Detect whether we're coming from construction space
     $result =~ s/&#100;/d/g;      if ($ENV{'form.postdata'} =~ /http:\/\// ) {
     $result =~ s/&#101;/e/g;          $ENV{'form.postdata'} =~ /http:\/\/[^\/]+\/~([^\/]+)\/(.*)/;
     $result =~ s/&#102;/f/g;          $helper->{VARS}->{'filename'} = "/home/$1/public_html/$2";
     $result =~ s/&#103;/g/g;          $helper->{VARS}->{'construction'} = 1;
     $result =~ s/&#104;/h/g;      } else {
     $result =~ s/&#105;/i/g;          if ($ENV{'form.postdata'}) {
     $result =~ s/&#106;/j/g;              $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($ENV{'form.postdata'});
     $result =~ s/&#107;/k/g;          }
     $result =~ s/&#108;/l/g;          if ($ENV{'form.symb'}) {
     $result =~ s/&#109;/m/g;              $helper->{VARS}->{'symb'} = $ENV{'form.symb'};
     $result =~ s/&#110;/n/g;          }
     $result =~ s/&#111;/o/g;          if ($ENV{'form.url'}) {
     $result =~ s/&#112;/p/g;              $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
     $result =~ s/&#113;/q/g;          }
     $result =~ s/&#114;/r/g;      }
     $result =~ s/&#115;/s/g;  
     $result =~ s/&#116;/t/g;      if ($ENV{'form.symb'}) {
     $result =~ s/&#117;/u/g;          $helper->{VARS}->{'symb'} = $ENV{'form.symb'};
     $result =~ s/&#118;/v/g;      }
     $result =~ s/&#119;/w/g;      if ($ENV{'form.url'}) {
     $result =~ s/&#120;/x/g;          $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
     $result =~ s/&#121;/y/g;  
     $result =~ s/&#122;/z/g;      }
     $result =~ s/&#123;/\\{/g;      
     $result =~ s/&#124;/\|/g;      my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu;
     $result =~ s/&#125;/\\}/g;      if ($sequenceTitle ne '') {$helper->{VARS}->{'assignment'}=$sequenceTitle;}
     $result =~ s/&#126;/\~/g;  
     $result =~ s/&#130;/,/g;      
 #    $result =~ s/&#131;//g;      # Extract map
     $result =~ s/&#132;/''/g;      my $symb = $helper->{VARS}->{'symb'};
     $result =~ s/&#133;/\$\\ldots\$/g;      my ($map, $id, $url);
     $result =~ s/&#134;/\$\\dagger\$/g;      my $subdir;
     $result =~ s/&#135;/\$\\ddagger\$/g;  
 #    $result =~ s/&#136;//g;      # Get the resource name from construction space
 #    $result =~ s/&#137;//g;      if ($helper->{VARS}->{'construction'}) {
 #    $result =~ s/&#138;//g;          $resourceTitle = substr($helper->{VARS}->{'filename'}, 
     $result =~ s/&#139;/\$<\$/g;                                  rindex($helper->{VARS}->{'filename'}, '/')+1);
 #    $result =~ s/&#140;//g;          $subdir = substr($helper->{VARS}->{'filename'},
     $result =~ s/&#145;/`/g;                           0, rindex($helper->{VARS}->{'filename'}, '/') + 1);
     $result =~ s/&#146;/'/g;      } else {
     $result =~ s/&#147;/``/g;          ($map, $id, $url) = split(/___/, $symb);
     $result =~ s/&#148;/''/g;          $helper->{VARS}->{'postdata'} = Apache::lonnet::clutter($url);
     $result =~ s/&#149;/\$\\bullet\$/g;  
 #    $result =~ s/&#150;//g;          if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
 #    $result =~ s/&#151;//g;              my $url = $helper->{VARS}->{'postdata'};
     $result =~ s/&#152;/~/g;              $resourceTitle = substr($url, rindex($url, '/') + 1);
 #    $result =~ s/&#153;//g;          }
 #    $result =~ s/&#154;//g;          $subdir = &Apache::lonnet::filelocation("", $url);
     $result =~ s/&#155;/\$>\$/g;      }
     $result =~ s/&#156;/\\{\\oe\\}/g;  
     $result =~ s/&#159;/\\"\\{Y\\}/g;      my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
     $result =~ s/&#160;//g;  
     $result =~ s/&nbsp;//g;      Apache::lonhelper::registerHelperTags();
     $result =~ s/&#161;/!`/g;  
     $result =~ s/&iexcl;/!`/g; #`      # "Delete everything after the last slash."
 #    $result =~ s/&#162;//g;      $subdir =~ s|/[^/]+$||;
 #    $result =~ s/&cent;//g;      if (not $helper->{VARS}->{'construction'}) {
     $result =~ s/&#163;/\\pounds/g;    $subdir='/home/httpd/html/res/'.$subdir;
     $result =~ s/&pound;/\\pounds/g;      }
 #    $result =~ s/&#164;//g;      # "Remove all duplicate slashes."
 #    $result =~ s/&curren;//g;      $subdir =~ s|/+|/|g;
 #    $result =~ s/&#165;//g;  
 #    $result =~ s/&yen;//g;      # What can be printed is a very dynamic decision based on
 #    $result =~ s/&#166;//g;      # lots of factors. So we need to dynamically build this list.
 #    $result =~ s/&brvbar;//g;      # To prevent security leaks, states are only added to the wizard
 #    $result =~ s/&#167;//g;      # if they can be reached, which ensures manipulating the form input
 #    $result =~ s/&sect;//g;      # won't allow anyone to reach states they shouldn't have permission
 #    $result =~ s/&#168;//g;      # to reach.
 #    $result =~ s/&uml;//g;  
     $result =~ s/&#169;/\\copyright/g;      # printChoices is tracking the kind of printing the user can
     $result =~ s/&copy;/\\copyright/g;      # do, and will be used in a choices construction later.
 #    $result =~ s/&#170;//g;      # In the meantime we will be adding states and elements to
 #    $result =~ s/&ordf;//g;      # the helper by hand.
 #    $result =~ s/&#171;//g;      my $printChoices = [];
 #    $result =~ s/&laquo;//g;      my $paramHash;
     $result =~ s/&#172;/\$\\neg\$/g;  
     $result =~ s/&not;/\$\\neg\$/g;      if ($resourceTitle) {
 #    $result =~ s/&#173;//g;          push @{$printChoices}, ["<b>$resourceTitle</b> (prints what you just saw on the screen)", 'current_document', 'PAGESIZE'];
 #    $result =~ s/&shy;//g;      }
 #    $result =~ s/&#174;//g;  
 #    $result =~ s/&reg;//g;  #    $r->print($helper->{VARS}->{'postdata'});
 #    $result =~ s/&#175;//g;  
 #    $result =~ s/&macr;//g;      # If we're in a sequence...
     $result =~ s/&#176;/\$^{\\circ}\$/g;      if ($helper->{'VARS'}->{'construction'} ne '1') {
     $result =~ s/&deg;/\$^{\\circ}\$/g;          # Allow problems from sequence
     $result =~ s/&#177;/\$\\pm\$/g;          push @{$printChoices}, ["Problem(s) from <b>$sequenceTitle</b>", 'map_problems', 'CHOOSE_PROBLEMS'];
     $result =~ s/&plusmn;/\$\\pm\$/g;          # Allow all resources from sequence
     $result =~ s/&#178;/\$^2\$/g;          push @{$printChoices}, ["Everything (problem(s), page(s), html/xml file(s)) from <b>$sequenceTitle</b>", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
     $result =~ s/&sup2;/\$^2\$/g;  
     $result =~ s/&#179;/\$^3\$/g;          my $isProblem = '$res->is_problem()';
     $result =~ s/&sup3;/\$^3\$/g;   $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
 #    $result =~ s/&#180;//g;          my $isProblemOrMap = '$res->is_problem() || $res->is_map()';
 #    $result =~ s/&acute;//g;          my $isNotMap = '!$res->is_map()';
     $result =~ s/&#181;/\$\\mu\$/g;   $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
     $result =~ s/&micro;/\$\\mu\$/g;          my $symb = '$res->symb()';
     $result =~ s/&#182;/\\P/g;          my $helperFragment = <<HELPERFRAGMENT;
     $result =~ s/&para;/\\P/g;    <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">
     $result =~ s/&#183;/\$\\cdot\$/g;      <message>(mark them then click "next" button) <br /></message>
     $result =~ s/&middot;/\$\\cdot\$/g;      <resource variable="RESOURCES" multichoice="1" toponly='1'>
 #    $result =~ s/&#184;//g;        <nextstate>PAGESIZE</nextstate>
 #    $result =~ s/&cedil;//g;        <filterfunc>return $isProblem;</filterfunc>
     $result =~ s/&#185;/\$^1\$/g;        <mapurl>$map</mapurl>
     $result =~ s/&sup1;/\$^1\$/g;        <valuefunc>return $symb;</valuefunc>
 #    $result =~ s/&#186;//g;        </resource>
 #    $result =~ s/&ordm;//g;      </state>
 #    $result =~ s/&#187;//g;  
 #    $result =~ s/&raquo;//g;    <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">
 #    $result =~ s/&#188;//g;      <message>(mark them then click "next" button) <br /></message>
 #    $result =~ s/&frac14;//g;      <resource variable="RESOURCES" multichoice="1" toponly='1'>
 #    $result =~ s/&#189;//g;        <nextstate>PAGESIZE</nextstate>
 #    $result =~ s/&frac12;//g;        <filterfunc>return $isNotMap;</filterfunc>
 #    $result =~ s/&#190;//g;        <mapurl>$map</mapurl>
 #    $result =~ s/&frac34;//g;        <valuefunc>return $symb;</valuefunc>
     $result =~ s/&#191;/?`/g;        </resource>
     $result =~ s/&iquest;/?`/g;       </state>
     $result =~ s/&#192;/\\`{A}/g;  HELPERFRAGMENT
     $result =~ s/&Agrave;/\\`{A}/g;   
     $result =~ s/&#193;/\\'{A}/g;           &Apache::lonxml::xmlparse($r, 'helper', $helperFragment); 
     $result =~ s/&Aacute;/\\'{A}/g;       }
     $result =~ s/&#194;/\\^{A}/g;  
     $result =~ s/&Acirc;/\\^{A}/g;      # If the user is priviledged, allow them to print all 
     $result =~ s/&#195;/\\~{A}/g;      # problems in the course, optionally for selected students
     $result =~ s/&Atilde;/\\~{A}/g;      if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($helper->{VARS}->{'postdata'}=~/\/res\//)) { 
     $result =~ s/&#196;/\\"{A}/g;           push @{$printChoices}, ['<b>Problems</b> in this course', 'all_problems', 'ALL_PROBLEMS'];
     $result =~ s/&Auml;/\\"{A}/g;           push @{$printChoices}, ["Problems from <b>$sequenceTitle</b> for selected students", 'problems_for_students', 'CHOOSE_STUDENTS'];
     $result =~ s/&#197;/{\\AA}/g;  
     $result =~ s/&Aring;/{\\AA}/g;          my $isProblem = '$res->is_problem()';
     $result =~ s/&#198;/{\\AE}/g;   $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
     $result =~ s/&AElig;/{\\AE}/g;          my $isProblemOrMap = '($res->is_problem() || $res->is_map())';
 #    $result =~ s/&#199;//g;   $isProblemOrMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
 #    $result =~ s/&Ccedil;//g;          my $symb = '$res->symb()';
     $result =~ s/&#200;/\\`{E}/g;          &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
     $result =~ s/&Egrave;/\\`{E}/g;    <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
     $result =~ s/&#201;/\\'{E}/g;      <message>(mark them then click "next" button) <br /></message>
     $result =~ s/&Eacute;/\\'{E}/g;      <resource variable="RESOURCES" multichoice="1" suppressEmptySequences='1'>
     $result =~ s/&#202;/\\^{E}/g;        <nextstate>PAGESIZE</nextstate>
     $result =~ s/&Ecirc;/\\^{E}/g;        <filterfunc>return $isProblemOrMap;</filterfunc>
     $result =~ s/&#203;/\\`{E}/g;        <choicefunc>return $isProblem;</choicefunc>
     $result =~ s/&Euml;/\\`{E}/g;        <valuefunc>return $symb;</valuefunc>
     $result =~ s/&#204;/\\`{I}/g;        </resource>
     $result =~ s/&Igrave;/\\`{I}/g;       </state>
     $result =~ s/&#205;/\\'{I}/g;   
     $result =~ s/&Iacute;/\\'{I}/g;     <state name="CHOOSE_STUDENTS" title="Choose Students whose assignments you want to print">
     $result =~ s/&#206;/\\^{I}/g;      <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
     $result =~ s/&Icirc;/\\^{I}/g;      <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
     $result =~ s/&#207;/\\"{I}/g;       <resource variable="RESOURCES" multichoice="1">
     $result =~ s/&Iuml;/\\"{I}/g;         <filterfunc>return $isProblem</filterfunc>
 #    $result =~ s/&#208;//g;        <mapurl>$map</mapurl>
 #    $result =~ s/&ETH;//g;        <valuefunc>return $symb</valuefunc>
     $result =~ s/&#209;/\\~{N}/g;        </resource>
     $result =~ s/&Ntilde;/\\~{N}/g;      <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
     $result =~ s/&#210;/\\`{O}/g;      <choices variable="EMPTY_PAGES">
     $result =~ s/&Ograve;/\\`{O}/g;         <choice computer='0'>Start each student\'s assignment on a new page (add a pagefeed after each assignment)</choice>
     $result =~ s/&#211;/\\'{O}/g;        <choice computer='1'>Add one empty page after each student\'s assignment</choice>
     $result =~ s/&Oacute;/\\'{O}/g;         <choice computer='2'>Add two empty pages after each student\'s assignment</choice>
     $result =~ s/&#212;/\\^{O}/g;        </choices>
     $result =~ s/&Ocirc;/\\^{O}/g;      </state>
     $result =~ s/&#213;/\\~{O}/g;  CHOOSE_STUDENTS
     $result =~ s/&Otilde;/\\~{O}/g;      }
     $result =~ s/&#214;/\\"{O}/g;  
     $result =~ s/&Ouml;/\\"{O}/g;       # FIXME: That RE should come from a library somewhere.
     $result =~ s/&#215;/\$\\times\$/g;      if (((&Apache::lonnet::allowed('bre',$subdir) eq 'F') and ($helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) or defined $helper->{'VARS'}->{'construction'}) {    
     $result =~ s/&times;/\$\\times\$/g;          push @{$printChoices}, ["Problems from current subdirectory <b>$subdir</b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
     $result =~ s/&#216;/{\\O}/g;          
     $result =~ s/&Oslash;/{\\O}/g;          my $f = '$filename';
     $result =~ s/&#217;/\\`{U}/g;          my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
     $result =~ s/&Ugrave;/\\`{U}/g;    <state name="CHOOSE_FROM_SUBDIR" title="Select File(s) from <b><small>$subdir</small></b> to print">
     $result =~ s/&#218;/\\'{U}/g;      <message>(mark them then click "next" button) <br /></message>
     $result =~ s/&Uacute;/\\'{U}/g;      <files variable="FILES" multichoice='1'>
     $result =~ s/&#219;/\\^{U}/g;        <nextstate>PAGESIZE</nextstate>
     $result =~ s/&Ucirc;/\\^{U}/g;        <filechoice>return '$subdir';</filechoice>
     $result =~ s/&#220;/\\"{U}/g;  CHOOSE_FROM_SUBDIR
     $result =~ s/&Uuml;/\\"{U}/g;          
     $result =~ s/&#221;/\\'{Y}/g;          $xmlfrag .= <<'CHOOSE_FROM_SUBDIR';
     $result =~ s/&Yacute;/\\'{Y}/g;        <filefilter>return $filename =~ 
 #    $result =~ s/&#222;//g;             m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/;
 #    $result =~ s/&THORN;//g;        </filefilter>
 #    $result =~ s/&#223;//g;        </files>
 #    $result =~ s/&szlig;//g;      </state>
     $result =~ s/&#224;/\\`{a}/g;  CHOOSE_FROM_SUBDIR
     $result =~ s/&agrave;/\\`{a}/g;          &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
     $result =~ s/&#225;/\\'{a}/g;      }
     $result =~ s/&aacute;/\\'{a}/g;  
     $result =~ s/&#226;/\\^{a}/g;      # Generate the first state, to select which resources get printed.
     $result =~ s/&acirc;/\\^{a}/g;      Apache::lonhelper::state->new("START", "What do you want to print? Make a choice.");
     $result =~ s/&#227;/\\~{a}/g;      $paramHash = Apache::lonhelper::getParamHash();
     $result =~ s/&atilde;/\\~{a}/g;      $paramHash->{MESSAGE_TEXT} = "";
     $result =~ s/&#228;/\\"{a}/g;      Apache::lonhelper::message->new();
     $result =~ s/&auml;/\\"{a}/g;      $paramHash = Apache::lonhelper::getParamHash();
     $result =~ s/&#229;/{\\aa}/g;      $paramHash->{'variable'} = 'PRINT_TYPE';
     $result =~ s/&aring;/{\\aa}/g;      $helper->declareVar('PRINT_TYPE');
     $result =~ s/&#230;/{\\ae}/g;      $paramHash->{CHOICES} = $printChoices;
     $result =~ s/&aelig;/{\\ae}/g;      Apache::lonhelper::choices->new();
 #    $result =~ s/&#231;//g;  
 #    $result =~ s/&ccedil;//g;      if (($ENV{'request.role.adv'} and &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) or 
     $result =~ s/&#232;/\\`{e}/g;   ($helper->{VARS}->{'construction'} eq '1')) {
     $result =~ s/&egrave;/\\`{e}/g;          $paramHash = Apache::lonhelper::getParamHash();
     $result =~ s/&#233;/\\'{e}/g;          $paramHash->{MESSAGE_TEXT} = "<br /><big><b><i>Next option is available only for advanced users:</i></b></big><br />";
     $result =~ s/&eacute;/\\'{e}/g;          Apache::lonhelper::message->new();
     $result =~ s/&#234;/\\^{e}/g;          $paramHash = Apache::lonhelper::getParamHash();
     $result =~ s/&ecirc;/\\^{e}/g;   $paramHash->{'variable'} = 'ANSWER_TYPE';   
     $result =~ s/&#235;/\\"{e}/g;   $helper->declareVar('ANSWER_TYPE');         
     $result =~ s/&euml;/\\"{e}/g;          $paramHash->{CHOICES} = [
     $result =~ s/&#236;/\\`{i}/g;                                     ['Print without answer', 'yes'],
     $result =~ s/&igrave;/\\`{i}/g;                                     ['Print with answers', 'no'] ];
     $result =~ s/&#237;/\\'{i}/g;          Apache::lonhelper::choices->new();
     $result =~ s/&iacute;/\\'{i}/g;      }
     $result =~ s/&#238;/\\^{i}/g;  
     $result =~ s/&icirc;/\\^{i}/g;      Apache::lonprintout::page_format_state->new("FORMAT");
     $result =~ s/&#239;/\\"{i}/g;  
     $result =~ s/&iuml;/\\"{i}/g;      # Generate the PAGESIZE state which will offer the user the margin
 #    $result =~ s/&#240;//g;      # choices if they select one column
 #    $result =~ s/&eth;//g;      Apache::lonhelper::state->new("PAGESIZE", "Set Margins");
     $result =~ s/&#241;/\\~{n}/g;      Apache::lonprintout::page_size_state->new('pagesize', 'FORMAT', 'FINAL');
     $result =~ s/&ntilde;/\\~{n}/g;  
     $result =~ s/&#242;/\\`{o}/g;  
     $result =~ s/&ograve;/\\`{o}/g;      $helper->process();
     $result =~ s/&#243;/\\'{o}/g;  
     $result =~ s/&oacute;/\\'{o}/g;      # MANUAL BAILOUT CONDITION:
     $result =~ s/&#244;/\\^{o}/g;      # If we're in the "final" state, bailout and return to handler
     $result =~ s/&ocirc;/\\^{o}/g;      if ($helper->{STATE} eq 'FINAL') {
     $result =~ s/&#245;/\\~{o}/g;          return $helper;
     $result =~ s/&otilde;/\\~{o}/g;      }    
     $result =~ s/&#246;/\\"{o}/g;  
     $result =~ s/&ouml;/\\"{o}/g;      $r->print($helper->display());
     $result =~ s/&#247;/\$\\div\$/g;  
     $result =~ s/&divide;/\$\\div\$/g;      Apache::lonhelper::unregisterHelperTags();
     $result =~ s/&#248;/{\\o}/g;  
     $result =~ s/&oslash;/{\\o}/g;      untie %hash;
     $result =~ s/&#249;/\\`{u}/g;   
     $result =~ s/&ugrave;/\\`{u}/g;      return OK;
     $result =~ s/&#250;/\\'{u}/g;  
     $result =~ s/&uacute;/\\'{u}/g;  
     $result =~ s/&#251;/\\^{u}/g;  
     $result =~ s/&ucirc;/\\^{u}/g;  
     $result =~ s/&#252;/\\"{u}/g;  
     $result =~ s/&uuml;/\\"{u}/g;  
     $result =~ s/&#253;/\\'{y}/g;  
     $result =~ s/&yacute;/\\'{y}/g;  
 #    $result =~ s/&#254;//g;  
 #    $result =~ s/&thorn;//g;  
     $result =~ s/&#255;/\\"{y}/g;  
     $result =~ s/&yuml;/\\"{y}/g;  
     return $result;  
 }  }
   
   
 #'"`  1;
   
 sub additional_cleanup {  package Apache::lonprintout::page_format_state;
     my $result = shift;  
     my $first_app = index($result,'\documentclass',0);  =pod
     $first_app = index($result,'\documentclass',$first_app+5);  
     while ($first_app != -1) {  =head1 Helper element: page_format_state
  my $second_app = index($result,'begin{document}',$first_app);  
  $first_app = rindex($result,'\end{document}',$first_app);  See lonhelper.pm documentation for discussion of the helper framework.
  substr($result,$first_app,$second_app-$first_app+15) = '\vskip 3 mm';  
  $first_app = index($result,'\documentclass',$first_app+5);  Apache::lonprintout::page_format_state is an element 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.
   
   page_format_state is always directly invoked in lonprintout.pm, so there
   is no tag interface. You actually pass parameters to the constructor.
   
   =over 4
   
   =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
   
   =back
   
   =cut
   
   use Apache::lonhelper;
   
   no strict;
   @ISA = ("Apache::lonhelper::element");
   use strict;
   
   my $maxColumns = 2;
   my @paperSize = ("Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]", 
                    "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
                    "A2 [420x594 mm]", "A3 [297x420 mm]", "A4 [210x297 mm]", 
                    "A5 [148x210 mm]", "A6 [105x148 mm]" );
   
   # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum |
   #                   Paper type
   
   sub new { 
       my $self = Apache::lonhelper::element->new();
   
       shift;
   
       $self->{'variable'} = shift;
       my $helper = Apache::lonhelper::getHelper();
       $helper->declareVar($self->{'variable'});
       bless($self);
       return $self;
   }
   
   sub render {
       my $self = shift;
       my $helper = Apache::lonhelper::getHelper();
       my $result = '';
       my $var = $self->{'variable'};
   
       $result .= <<STATEHTML;
   
   <p><big><i><b>What page format do you prefer?</b></i></big></p>
   <table cellpadding="3">
     <tr>
       <td align="center"><b>Page layout</b></td>
       <td align="center"><b>Number of columns</b></td>
       <td align="center"><b>Paper type</b></td>
     </tr>
     <tr>
       <td>
         <input type="radio" name="${var}.layout" value="L" /> Landscape<br />
         <input type="radio" name="${var}.layout" value="P" checked='1'  /> Portrait
       </td>
       <td align="center">
         <select name="${var}.cols">
   STATEHTML
   
       my $i;
       for ($i = 1; $i <= $maxColumns; $i++) {
           if ($i == 2) {
               $result .= "<option value='$i' selected>$i</option>\n";
           } else {
               $result .= "<option value='$i'>$i</option>\n";
           }
       }
   
       $result .= "</select></td><td>\n";
       $result .= "<select name='${var}.paper'>\n";
   
       $i = 0;
       foreach (@paperSize) {
           if ($i == 0) {
               $result .= "<option selected value='$i'>" . $paperSize[$i] . "</option>\n";
           } else {
               $result .= "<option value='$i'>" . $paperSize[$i] . "</option>\n";
           }
           $i++;
     }      }
   
       $result .= "</select></td></tr></table>";
     return $result;      return $result;
 }  }
 sub page_cleanup {  
     my $result = shift;  sub postprocess {
     $_ = $result;      my $self = shift;
     m/\\end{document}(\d*)$/;  
     my $number_of_columns = $1;      my $var = $self->{'variable'};
     my $insert = '{';      my $helper = Apache::lonhelper->getHelper();
     for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }      $helper->{VARS}->{$var} = 
     $insert .= '}';          $ENV{"form.$var.layout"} . '|' . $ENV{"form.$var.cols"} . '|' .
     $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE/$1$insert/g;          $ENV{"form.$var.paper"};
     $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;      return 1;
     $result =~ s/(\\vskip\s*\d+\s*mm)/}\\\\\\parbox{\\minipagewidth}{/g;  
     $result =~ s/\\parbox{\\minipagewidth}{}\s*\\\\\s*(\\parbox{\\minipagewidth})/$1/g;  
     $result =~ s/\\parbox{\\minipagewidth}{\s*\\\\\\\\/\\parbox{\\minipagewidth}{/g;  
     return $result,$number_of_columns;  
 }  }
   
 sub content_map {  1;
 #-- find a list of files to print  
     my $map_string = shift;  
     my @number_seq = ();  
     my @file_seq = ();  
     my $startlink = index($map_string,'<link',0);  
     my $endlink = index($map_string,'</link>',$startlink);  
     my $chunk = substr($map_string,$startlink,$endlink-$startlink+7);  
     $_ = $chunk;  
     m/from=\"(\d+)\"/;  
     push @number_seq,$1;  
     while ($startlink != -1) {  
  $endlink = index($map_string,'</link>',$startlink);  
  $chunk = substr($map_string,$startlink,$endlink-$startlink+7);  
  substr($map_string,$startlink,$endlink-$startlink+7) = '';  
  $_ = $chunk;  
         m/to=\"(\d+)\"/;  
  push @number_seq,$1;  
  $startlink = index($map_string,'from="'.$1.'"',0);  
  $startlink = rindex($map_string,'<link ',$startlink);  
     }  
     my $stalink = index($map_string,' to="'.$number_seq[0].'"',0);  
     while ($stalink != -1) {  
  $startlink = rindex($map_string,'<link ',$stalink);  
  $endlink = index($map_string,'</link>',$startlink);  
  $chunk = substr($map_string,$startlink,$endlink-$startlink+7);  
  substr($map_string,$startlink,$endlink-$startlink+7) = '';  
  $_ = $chunk;  
         m/from=\"(\d+)\"/;  
  unshift @number_seq,$1;  
  $stalink = index($map_string,' to="'.$number_seq[0].'"',0);  
     }  
     for (my $i=0;$i<=$#number_seq;$i++) {  
  $stalink = index($map_string,' id="'.$number_seq[$i].'"',0);  
         {      
     my $ahed1 = index($map_string,'src="',$stalink);  
     my $ahed2 = index($map_string,'</resource>',$stalink);  
     if ($ahed1 != -1) {  
  if ($ahed1 < $ahed2) {  
     $startlink = $ahed1;  
  } else {  
     $startlink = rindex($map_string,'src="',$stalink);  
  }  
     } else {  
  $startlink = rindex($map_string,'src="',$stalink);  
     }  
   
  }  package Apache::lonprintout::page_size_state;
  $startlink = index($map_string,'"',$startlink);  
  $endlink = index($map_string,'"',$startlink+1);  =pod
  $chunk = substr($map_string,$startlink,$endlink-$startlink+1);  
  push @file_seq,$chunk;  =head1 Helper element: page_size_state
   
   See lonhelper.pm documentation for discussion of the helper framework.
   
   Apache::lonprintout::page_size_state is an element that gives the 
   user the opportunity to further refine the page settings if they
   select a single-column page.
   
   page_size_state is always directly invoked in lonprintout.pm, so there
   is no tag interface. You actually pass parameters to the constructor.
   
   =over 4
   
   =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
   
   =back
   
   =cut
   
   use Apache::lonhelper;
   
   no strict;
   @ISA = ("Apache::lonhelper::element");
   use strict;
   
   
   
   sub new { 
       my $self = Apache::lonhelper::element->new();
   
       shift; # disturbs me (probably prevents subclassing) but works (drops
              # package descriptor)... - Jeremy
   
       $self->{'variable'} = shift;
       my $helper = Apache::lonhelper::getHelper();
       $helper->declareVar($self->{'variable'});
   
       # The variable name of the format element, so we can look into 
       # $helper->{VARS} to figure out whether the columns are one or two
       $self->{'formatvar'} = shift;
   
       # The state to transition to after selection, or after discovering
       # the cols are not set to 1
       $self->{NEXTSTATE} = shift;
       bless($self);
       return $self;
   }
   
   sub render {
       my $self = shift;
       my $helper = Apache::lonhelper::getHelper();
       my $result = '';
       my $var = $self->{'variable'};
   
       if (defined $self->{ERROR_MSG}) {
           $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />';
     }      }
     return @file_seq;  
       $result .= <<ELEMENTHTML;
   
   <p>How should the column be formatted?</p>
   
   <table cellpadding='3'>
     <tr>
       <td align='right'><b>Width</b>:</td>
       <td align='left'><input type='text' name='$var.width' value='18' size='4'></td>
       <td align='left'>
         <select name='$var.widthunit'>
           <option>cm</option><option>in</option>
         </select>
       </td>
     </tr>
     <tr>
       <td align='right'><b>Height</b>:</td>
       <td align='left'><input type='text' name="$var.height" value="25.9" size='4'></td>
       <td align='left'>
         <select name='$var.heightunit'>
           <option>cm</option><option>in</option>
         </select>
       </td>
     </tr>
     <tr>
       <td align='right'><b>Left margin</b>:</td>
       <td align='left'><input type='text' name='$var.lmargin' value='-1.5' size='4'></td>
       <td align='left'>
         <select name='$var.lmarginunit'>
           <option>cm</option><option>in</option>
         </select>
       </td>
     </tr>
   </table>
   
   <p>Hint: Some instructors like to leave scratch space for the student by
   making the width much smaller then the width of the page.</p>
   
   ELEMENTHTML
   
       return $result;
 }  }
   
   # If the user didn't select 1 column, skip this state.
   sub preprocess {
       my $self = shift;
       my $helper = Apache::lonhelper::getHelper();
   
       my $format = $helper->{VARS}->{$self->{'formatvar'}};
       if (substr($format, 2, 1) ne '1') {
           $helper->changeState($self->{NEXTSTATE});
       }
      
       return 1;
   }
   
   sub postprocess {
       my $self = shift;
   
 sub handler {      my $var = $self->{'variable'};
       my $helper = Apache::lonhelper->getHelper();
       my $width = $helper->{VARS}->{$var .'.width'} = $ENV{"form.${var}.width"}; 
       my $height = $helper->{VARS}->{$var .'.height'} = $ENV{"form.${var}.height"}; 
       my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $ENV{"form.${var}.lmargin"}; 
       $helper->{VARS}->{$var .'.widthunit'} = $ENV{"form.${var}.widthunit"}; 
       $helper->{VARS}->{$var .'.heightunit'} = $ENV{"form.${var}.heightunit"}; 
       $helper->{VARS}->{$var .'.lmarginunit'} = $ENV{"form.${var}.lmarginunit"}; 
   
     my $r = shift;      my $error = '';
     $r->content_type('text/html');  
     $r->send_http_header;  
   
 #-- start form      # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed 
     &headerform($r);      # by an optional period, followed by digits, ending the string
 #-- menu for output  
     unless  ($ENV{'form.phase'}) {      if ($width !~  /^-?[0-9]+(\.[0-9]*)?$/) {
  &menu_for_output($r);          $error .= "Invalid width; please type only a number.<br />\n";
     }  
 #-- additional menu for class printing  
      if ($ENV{'form.phase'} eq 'two') {  
  if($ENV{'form.choice'} eq 'All class print') {  
      &additional_class_menu($r);  
  } else {  
      $ENV{'form.phase'} = 'three';  
  }  
      }  
 #-- additional menu for page layout (one column case)  
     if ($ENV{'form.phase'} eq 'three') {  
  if($ENV{'form.numberofcolumns'} == 1) {  
     &additional_print_menu($r);  
  } else {  
     $ENV{'form.phase'} = 'four';  
  }  
     }      }
 #-- core part       if ($height !~  /^-?[0-9]+(\.[0-9]*)?$/) {
     if ($ENV{'form.phase'} eq 'four') {          $error .= "Invalid height; please type only a number.<br />\n";
  &output_data($r);      }
       if ($lmargin !~  /^-?[0-9]+(\.[0-9]*)?$/) {
           $error .= "Invalid left margin; please type only a number.<br />\n";
     }      }
     return OK;  
   
 }   
   
 1;      if (!$error) {
 __END__          Apache::lonhelper::getHelper()->changeState($self->{NEXTSTATE});
           return 1;
       } else {
           $self->{ERROR_MSG} = $error;
           return 0;
       }
   }
   
   
   
   __END__
   
 #### Test block  
 #    my $ere;  
 #    foreach $ere (%ENV) {  
 # $result .= ' SS '.$ere.' => '.$ENV{$ere}.' FF '."\n\n";  
 #    }  
 ####  

Removed from v.1.55  
changed lines
  Added in v.1.193


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