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

1.1       www         1: # The LearningOnline Network
                      2: # Printout
                      3: #
1.337   ! albertel    4: # $Id: lonprintout.pm,v 1.336 2004/11/13 09:27:47 albertel 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.3       sakharuk   28: #
1.1       www        29: package Apache::lonprintout;
                     30: 
                     31: use strict;
1.10      albertel   32: use Apache::Constants qw(:common :http);
1.2       sakharuk   33: use Apache::lonxml;
                     34: use Apache::lonnet;
1.54      sakharuk   35: use Apache::loncommon;
1.13      sakharuk   36: use Apache::inputtags;
1.54      sakharuk   37: use Apache::grades;
1.13      sakharuk   38: use Apache::edit;
1.5       sakharuk   39: use Apache::File();
1.68      sakharuk   40: use Apache::lonnavmaps;
1.227     sakharuk   41: use Apache::lonratedt;
1.34      sakharuk   42: use POSIX qw(strftime);
1.255     www        43: use Apache::lonlocal;
1.60      sakharuk   44: 
1.76      sakharuk   45: my $LaTeXwidth = 0;
1.3       sakharuk   46: 
1.2       sakharuk   47: 
1.71      sakharuk   48: sub latex_header_footer_remove {
                     49:     my $text = shift;
                     50:     $text =~ s/\\end{document}//;
                     51:     $text =~ s/\\documentclass([^&]*)\\begin{document}//;
                     52:     return $text;
                     53: }
                     54: 
                     55: 
1.37      sakharuk   56: sub character_chart {
                     57:     my $result = shift;	
1.116     sakharuk   58:     $result =~ s/&\#0?0?(7|9);//g;
                     59:     $result =~ s/&\#0?(10|13);//g;
                     60:     $result =~ s/&\#0?32;/ /g;
                     61:     $result =~ s/&\#0?33;/!/g;
                     62:     $result =~ s/&(\#0?34|quot);/\"/g;
                     63:     $result =~ s/&\#0?35;/\\\#/g;
                     64:     $result =~ s/&\#0?36;/\\\$/g;
                     65:     $result =~ s/&\#0?37;/\\%/g; 
                     66:     $result =~ s/&(\#0?38|amp);/\\&/g; 
                     67:     $result =~ s/&\#(0?39|146);/\'/g;
                     68:     $result =~ s/&\#0?40;/(/g;
                     69:     $result =~ s/&\#0?41;/)/g;
                     70:     $result =~ s/&\#0?42;/\*/g;
                     71:     $result =~ s/&\#0?43;/\+/g;
                     72:     $result =~ s/&\#(0?44|130);/,/g;
                     73:     $result =~ s/&\#0?45;/-/g;
                     74:     $result =~ s/&\#0?46;/\./g;
                     75:     $result =~ s/&\#0?47;/\//g;
                     76:     $result =~ s/&\#0?48;/0/g;
                     77:     $result =~ s/&\#0?49;/1/g;
                     78:     $result =~ s/&\#0?50;/2/g;
                     79:     $result =~ s/&\#0?51;/3/g;
                     80:     $result =~ s/&\#0?52;/4/g;
                     81:     $result =~ s/&\#0?53;/5/g;
                     82:     $result =~ s/&\#0?54;/6/g;
                     83:     $result =~ s/&\#0?55;/7/g;
                     84:     $result =~ s/&\#0?56;/8/g;
                     85:     $result =~ s/&\#0?57;/9/g;
1.269     albertel   86:     $result =~ s/&\#0?58;/:/g;
1.116     sakharuk   87:     $result =~ s/&\#0?59;/;/g;
                     88:     $result =~ s/&(\#0?60|lt|\#139);/\$<\$/g;
1.281     sakharuk   89:     $result =~ s/&\#0?61;/\\ensuremath\{=\}/g;
                     90:     $result =~ s/&(\#0?62|gt|\#155);/\\ensuremath\{>\}/g;
1.116     sakharuk   91:     $result =~ s/&\#0?63;/\?/g;
                     92:     $result =~ s/&\#0?65;/A/g;
                     93:     $result =~ s/&\#0?66;/B/g;
                     94:     $result =~ s/&\#0?67;/C/g;
                     95:     $result =~ s/&\#0?68;/D/g;
                     96:     $result =~ s/&\#0?69;/E/g;
                     97:     $result =~ s/&\#0?70;/F/g;
                     98:     $result =~ s/&\#0?71;/G/g;
                     99:     $result =~ s/&\#0?72;/H/g;
                    100:     $result =~ s/&\#0?73;/I/g;
                    101:     $result =~ s/&\#0?74;/J/g;
                    102:     $result =~ s/&\#0?75;/K/g;
                    103:     $result =~ s/&\#0?76;/L/g;
                    104:     $result =~ s/&\#0?77;/M/g;
                    105:     $result =~ s/&\#0?78;/N/g;
                    106:     $result =~ s/&\#0?79;/O/g;
                    107:     $result =~ s/&\#0?80;/P/g;
                    108:     $result =~ s/&\#0?81;/Q/g;
                    109:     $result =~ s/&\#0?82;/R/g;
                    110:     $result =~ s/&\#0?83;/S/g;
                    111:     $result =~ s/&\#0?84;/T/g;
                    112:     $result =~ s/&\#0?85;/U/g;
                    113:     $result =~ s/&\#0?86;/V/g;
                    114:     $result =~ s/&\#0?87;/W/g;
                    115:     $result =~ s/&\#0?88;/X/g;
                    116:     $result =~ s/&\#0?89;/Y/g;
                    117:     $result =~ s/&\#0?90;/Z/g;
                    118:     $result =~ s/&\#0?91;/[/g;
1.281     sakharuk  119:     $result =~ s/&\#0?92;/\\ensuremath\{\\setminus\}/g;
1.116     sakharuk  120:     $result =~ s/&\#0?93;/]/g;
1.281     sakharuk  121:     $result =~ s/&\#(0?94|136);/\\ensuremath\{\\wedge\}/g;
1.116     sakharuk  122:     $result =~ s/&\#(0?95|138|154);/\\underline{\\makebox[2mm]{\\strut}}/g;
                    123:     $result =~ s/&\#(0?96|145);/\`/g;
                    124:     $result =~ s/&\#0?97;/a/g;
                    125:     $result =~ s/&\#0?98;/b/g;
                    126:     $result =~ s/&\#0?99;/c/g;
                    127:     $result =~ s/&\#100;/d/g;
                    128:     $result =~ s/&\#101;/e/g;
                    129:     $result =~ s/&\#102;/f/g;
                    130:     $result =~ s/&\#103;/g/g;
                    131:     $result =~ s/&\#104;/h/g;
                    132:     $result =~ s/&\#105;/i/g;
                    133:     $result =~ s/&\#106;/j/g;
                    134:     $result =~ s/&\#107;/k/g;
                    135:     $result =~ s/&\#108;/l/g;
                    136:     $result =~ s/&\#109;/m/g;
                    137:     $result =~ s/&\#110;/n/g;
                    138:     $result =~ s/&\#111;/o/g;
                    139:     $result =~ s/&\#112;/p/g;
                    140:     $result =~ s/&\#113;/q/g;
                    141:     $result =~ s/&\#114;/r/g;
                    142:     $result =~ s/&\#115;/s/g;
                    143:     $result =~ s/&\#116;/t/g;
                    144:     $result =~ s/&\#117;/u/g;
                    145:     $result =~ s/&\#118;/v/g;
                    146:     $result =~ s/&\#119;/w/g;
                    147:     $result =~ s/&\#120;/x/g;
                    148:     $result =~ s/&\#121;/y/g;
                    149:     $result =~ s/&\#122;/z/g;
                    150:     $result =~ s/&\#123;/\\{/g;
                    151:     $result =~ s/&\#124;/\|/g;
                    152:     $result =~ s/&\#125;/\\}/g;
                    153:     $result =~ s/&\#126;/\~/g;
                    154:     $result =~ s/&\#131;/\\textflorin /g;
                    155:     $result =~ s/&\#132;/\"/g;
1.281     sakharuk  156:     $result =~ s/&\#133;/\\ensuremath\{\\ldots\}/g;
                    157:     $result =~ s/&\#134;/\\ensuremath\{\\dagger\}/g;
                    158:     $result =~ s/&\#135;/\\ensuremath\{\\ddagger\}/g;
1.116     sakharuk  159:     $result =~ s/&\#137;/\\textperthousand /g;
                    160:     $result =~ s/&\#140;/{\\OE}/g;
                    161:     $result =~ s/&\#147;/\`\`/g;
                    162:     $result =~ s/&\#148;/\'\'/g;
1.281     sakharuk  163:     $result =~ s/&\#149;/\\ensuremath\{\\bullet\}/g;
1.116     sakharuk  164:     $result =~ s/&\#150;/--/g;
                    165:     $result =~ s/&\#151;/---/g;
1.281     sakharuk  166:     $result =~ s/&\#152;/\\ensuremath\{\\sim\}/g;
1.116     sakharuk  167:     $result =~ s/&\#153;/\\texttrademark /g;
                    168:     $result =~ s/&\#156;/\\oe/g;
                    169:     $result =~ s/&\#159;/\\\"Y/g;
1.283     albertel  170:     $result =~ s/&(\#160|nbsp);/~/g;
1.116     sakharuk  171:     $result =~ s/&(\#161|iexcl);/!\`/g;
                    172:     $result =~ s/&(\#162|cent);/\\textcent /g;
                    173:     $result =~ s/&(\#163|pound);/\\pounds /g; 
                    174:     $result =~ s/&(\#164|curren);/\\textcurrency /g;
                    175:     $result =~ s/&(\#165|yen);/\\textyen /g;
                    176:     $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g;
                    177:     $result =~ s/&(\#167|sect);/\\textsection /g;
                    178:     $result =~ s/&(\#168|uml);/\\texthighdieresis /g;
                    179:     $result =~ s/&(\#169|copy);/\\copyright /g;
                    180:     $result =~ s/&(\#170|ordf);/\\textordfeminine /g;
1.281     sakharuk  181:     $result =~ s/&(\#172|not);/\\ensuremath\{\\neg\}/g;
1.116     sakharuk  182:     $result =~ s/&(\#173|shy);/ - /g;
                    183:     $result =~ s/&(\#174|reg);/\\textregistered /g;
1.281     sakharuk  184:     $result =~ s/&(\#175|macr);/\\ensuremath\{^{-}\}/g;
                    185:     $result =~ s/&(\#176|deg);/\\ensuremath\{^{\\circ}\}/g;
                    186:     $result =~ s/&(\#177|plusmn);/\\ensuremath\{\\pm\}/g;
                    187:     $result =~ s/&(\#178|sup2);/\\ensuremath\{^2\}/g;
                    188:     $result =~ s/&(\#179|sup3);/\\ensuremath\{^3\}/g;
1.116     sakharuk  189:     $result =~ s/&(\#180|acute);/\\textacute /g;
1.281     sakharuk  190:     $result =~ s/&(\#181|micro);/\\ensuremath\{\\mu\}/g;
1.116     sakharuk  191:     $result =~ s/&(\#182|para);/\\P/g;
1.281     sakharuk  192:     $result =~ s/&(\#183|middot);/\\ensuremath\{\\cdot\}/g;
1.116     sakharuk  193:     $result =~ s/&(\#184|cedil);/\\c{\\strut}/g;
1.281     sakharuk  194:     $result =~ s/&(\#185|sup1);/\\ensuremath\{^1\}/g;
1.116     sakharuk  195:     $result =~ s/&(\#186|ordm);/\\textordmasculine /g;
                    196:     $result =~ s/&(\#188|frac14);/\\textonequarter /g;
                    197:     $result =~ s/&(\#189|frac12);/\\textonehalf /g;
                    198:     $result =~ s/&(\#190|frac34);/\\textthreequarters /g;
                    199:     $result =~ s/&(\#191|iquest);/?\`/g;   
                    200:     $result =~ s/&(\#192|Agrave);/\\\`{A}/g;  
                    201:     $result =~ s/&(\#193|Aacute);/\\\'{A}/g; 
                    202:     $result =~ s/&(\#194|Acirc);/\\^{A}/g;
                    203:     $result =~ s/&(\#195|Atilde);/\\~{A}/g;
                    204:     $result =~ s/&(\#196|Auml);/\\\"{A}/g; 
                    205:     $result =~ s/&(\#197|Aring);/{\\AA}/g;
                    206:     $result =~ s/&(\#198|AElig);/{\\AE}/g;
                    207:     $result =~ s/&(\#199|Ccedil);/\\c{c}/g;
                    208:     $result =~ s/&(\#200|Egrave);/\\\`{E}/g;  
                    209:     $result =~ s/&(\#201|Eacute);/\\\'{E}/g;    
                    210:     $result =~ s/&(\#202|Ecirc);/\\^{E}/g;
                    211:     $result =~ s/&(\#203|Euml);/\\\"{E}/g;
                    212:     $result =~ s/&(\#204|Igrave);/\\\`{I}/g;
                    213:     $result =~ s/&(\#205|Iacute);/\\\'{I}/g;    
                    214:     $result =~ s/&(\#206|Icirc);/\\^{I}/g;
                    215:     $result =~ s/&(\#207|Iuml);/\\\"{I}/g;    
                    216:     $result =~ s/&(\#209|Ntilde);/\\~{N}/g;
                    217:     $result =~ s/&(\#210|Ograve);/\\\`{O}/g;
                    218:     $result =~ s/&(\#211|Oacute);/\\\'{O}/g;
                    219:     $result =~ s/&(\#212|Ocirc);/\\^{O}/g;
                    220:     $result =~ s/&(\#213|Otilde);/\\~{O}/g;
                    221:     $result =~ s/&(\#214|Ouml);/\\\"{O}/g;    
1.281     sakharuk  222:     $result =~ s/&(\#215|times);/\\ensuremath\{\\times\}/g;
1.116     sakharuk  223:     $result =~ s/&(\#216|Oslash);/{\\O}/g;
                    224:     $result =~ s/&(\#217|Ugrave);/\\\`{U}/g;    
                    225:     $result =~ s/&(\#218|Uacute);/\\\'{U}/g;
                    226:     $result =~ s/&(\#219|Ucirc);/\\^{U}/g;
                    227:     $result =~ s/&(\#220|Uuml);/\\\"{U}/g;
                    228:     $result =~ s/&(\#221|Yacute);/\\\'{Y}/g;
1.329     sakharuk  229:     $result =~ s/&(\#223|szlig);/{\\ss}/g;
1.116     sakharuk  230:     $result =~ s/&(\#224|agrave);/\\\`{a}/g;
                    231:     $result =~ s/&(\#225|aacute);/\\\'{a}/g;
                    232:     $result =~ s/&(\#226|acirc);/\\^{a}/g;
                    233:     $result =~ s/&(\#227|atilde);/\\~{a}/g;
                    234:     $result =~ s/&(\#228|auml);/\\\"{a}/g;
                    235:     $result =~ s/&(\#229|aring);/{\\aa}/g;
                    236:     $result =~ s/&(\#230|aelig);/{\\ae}/g;
                    237:     $result =~ s/&(\#231|ccedil);/\\c{c}/g;
                    238:     $result =~ s/&(\#232|egrave);/\\\`{e}/g;
                    239:     $result =~ s/&(\#233|eacute);/\\\'{e}/g;
                    240:     $result =~ s/&(\#234|ecirc);/\\^{e}/g;
                    241:     $result =~ s/&(\#235|euml);/\\\"{e}/g;
                    242:     $result =~ s/&(\#236|igrave);/\\\`{i}/g;
                    243:     $result =~ s/&(\#237|iacute);/\\\'{i}/g;
                    244:     $result =~ s/&(\#238|icirc);/\\^{i}/g;
                    245:     $result =~ s/&(\#239|iuml);/\\\"{i}/g;
1.281     sakharuk  246:     $result =~ s/&(\#240|eth);/\\ensuremath\{\\partial\}/g;
1.116     sakharuk  247:     $result =~ s/&(\#241|ntilde);/\\~{n}/g;
                    248:     $result =~ s/&(\#242|ograve);/\\\`{o}/g;
                    249:     $result =~ s/&(\#243|oacute);/\\\'{o}/g;
                    250:     $result =~ s/&(\#244|ocirc);/\\^{o}/g;
                    251:     $result =~ s/&(\#245|otilde);/\\~{o}/g;
                    252:     $result =~ s/&(\#246|ouml);/\\\"{o}/g;
1.281     sakharuk  253:     $result =~ s/&(\#247|divide);/\\ensuremath\{\\div\}/g;
1.116     sakharuk  254:     $result =~ s/&(\#248|oslash);/{\\o}/g;
                    255:     $result =~ s/&(\#249|ugrave);/\\\`{u}/g; 
                    256:     $result =~ s/&(\#250|uacute);/\\\'{u}/g;
                    257:     $result =~ s/&(\#251|ucirc);/\\^{u}/g;
                    258:     $result =~ s/&(\#252|uuml);/\\\"{u}/g;
                    259:     $result =~ s/&(\#253|yacute);/\\\'{y}/g;
                    260:     $result =~ s/&(\#255|yuml);/\\\"{y}/g;
1.281     sakharuk  261:     $result =~ s/&\#952;/\\ensuremath\{\\theta\}/g;
1.117     sakharuk  262: #Greek Alphabet
1.281     sakharuk  263:     $result =~ s/&(alpha|\#945);/\\ensuremath\{\\alpha\}/g;
                    264:     $result =~ s/&(beta|\#946);/\\ensuremath\{\\beta\}/g;
                    265:     $result =~ s/&(gamma|\#947);/\\ensuremath\{\\gamma\}/g;
                    266:     $result =~ s/&(delta|\#948);/\\ensuremath\{\\delta\}/g;
                    267:     $result =~ s/&(epsilon|\#949);/\\ensuremath\{\\epsilon\}/g;
                    268:     $result =~ s/&(zeta|\#950);/\\ensuremath\{\\zeta\}/g;
                    269:     $result =~ s/&(eta|\#951);/\\ensuremath\{\\eta\}/g;
                    270:     $result =~ s/&(theta|\#952);/\\ensuremath\{\\theta\}/g;
                    271:     $result =~ s/&(iota|\#953);/\\ensuremath\{\\iota\}/g;
                    272:     $result =~ s/&(kappa|\#954);/\\ensuremath\{\\kappa\}/g;
                    273:     $result =~ s/&(lambda|\#955);/\\ensuremath\{\\lambda\}/g;
                    274:     $result =~ s/&(mu|\#956);/\\ensuremath\{\\mu\}/g;
                    275:     $result =~ s/&(nu|\#957);/\\ensuremath\{\\nu\}/g;
                    276:     $result =~ s/&(xi|\#958);/\\ensuremath\{\\xi\}/g;
1.199     sakharuk  277:     $result =~ s/&(omicron|\#959);/o/g;
1.281     sakharuk  278:     $result =~ s/&(pi|\#960);/\\ensuremath\{\\pi\}/g;
                    279:     $result =~ s/&(rho|\#961);/\\ensuremath\{\\rho\}/g;
                    280:     $result =~ s/&(sigma|\#963);/\\ensuremath\{\\sigma\}/g;
                    281:     $result =~ s/&(tau|\#964);/\\ensuremath\{\\tau\}/g;
                    282:     $result =~ s/&(upsilon|\#965);/\\ensuremath\{\\upsilon\}/g;
                    283:     $result =~ s/&(phi|\#966);/\\ensuremath\{\\phi\}/g;
                    284:     $result =~ s/&(chi|\#967);/\\ensuremath\{\\chi\}/g;
                    285:     $result =~ s/&(psi|\#968);/\\ensuremath\{\\psi\}/g;
                    286:     $result =~ s/&(omega|\#969);/\\ensuremath\{\\omega\}/g;
                    287:     $result =~ s/&(thetasym|\#977);/\\ensuremath\{\\vartheta\}/g;
                    288:     $result =~ s/&(piv|\#982);/\\ensuremath\{\\varpi\}/g;
1.199     sakharuk  289:     $result =~ s/&(Alpha|\#913);/A/g;
                    290:     $result =~ s/&(Beta|\#914);/B/g;
1.281     sakharuk  291:     $result =~ s/&(Gamma|\#915);/\\ensuremath\{\\Gamma\}/g;
                    292:     $result =~ s/&(Delta|\#916);/\\ensuremath\{\\Delta\}/g;
1.199     sakharuk  293:     $result =~ s/&(Epsilon|\#917);/E/g;
                    294:     $result =~ s/&(Zeta|\#918);/Z/g;
                    295:     $result =~ s/&(Eta|\#919);/H/g;
1.281     sakharuk  296:     $result =~ s/&(Theta|\#920);/\\ensuremath\{\\Theta\}/g;
1.199     sakharuk  297:     $result =~ s/&(Iota|\#921);/I/g;
                    298:     $result =~ s/&(Kappa|\#922);/K/g;
1.281     sakharuk  299:     $result =~ s/&(Lambda|\#923);/\\ensuremath\{\\Lambda\}/g;
1.199     sakharuk  300:     $result =~ s/&(Mu|\#924);/M/g;
                    301:     $result =~ s/&(Nu|\#925);/N/g;
1.281     sakharuk  302:     $result =~ s/&(Xi|\#926);/\\ensuremath\{\\Xi\}/g;
1.199     sakharuk  303:     $result =~ s/&(Omicron|\#927);/O/g;
1.281     sakharuk  304:     $result =~ s/&(Pi|\#928);/\\ensuremath\{\\Pi\}/g;
1.199     sakharuk  305:     $result =~ s/&(Rho|\#929);/P/g;
1.281     sakharuk  306:     $result =~ s/&(Sigma|\#931);/\\ensuremath\{\\Sigma\}/g;
1.199     sakharuk  307:     $result =~ s/&(Tau|\#932);/T/g;
1.281     sakharuk  308:     $result =~ s/&(Upsilon|\#933);/\\ensuremath\{\\Upsilon\}/g;
                    309:     $result =~ s/&(Phi|\#934);/\\ensuremath\{\\Phi\}/g;
1.199     sakharuk  310:     $result =~ s/&(Chi|\#935);/X/g;
1.281     sakharuk  311:     $result =~ s/&(Psi|\#936);/\\ensuremath\{\\Psi\}/g;
                    312:     $result =~ s/&(Omega|\#937);/\\ensuremath\{\\Omega\}/g;
1.199     sakharuk  313: #Arrows (extended HTML 4.01)
1.281     sakharuk  314:     $result =~ s/&(larr|\#8592);/\\ensuremath\{\\leftarrow\}/g;
                    315:     $result =~ s/&(uarr|\#8593);/\\ensuremath\{\\uparrow\}/g;
                    316:     $result =~ s/&(rarr|\#8594);/\\ensuremath\{\\rightarrow\}/g;
                    317:     $result =~ s/&(darr|\#8595);/\\ensuremath\{\\downarrow\}/g;
                    318:     $result =~ s/&(harr|\#8596);/\\ensuremath\{\\leftrightarrow\}/g;
                    319:     $result =~ s/&(lArr|\#8656);/\\ensuremath\{\\Leftarrow\}/g;
                    320:     $result =~ s/&(uArr|\#8657);/\\ensuremath\{\\Uparrow\}/g;
                    321:     $result =~ s/&(rArr|\#8658);/\\ensuremath\{\\Rightarrow\}/g;
                    322:     $result =~ s/&(dArr|\#8659);/\\ensuremath\{\\Downarrow\}/g;
                    323:     $result =~ s/&(hArr|\#8660);/\\ensuremath\{\\Leftrightarrow\}/g;
1.199     sakharuk  324: #Mathematical Operators (extended HTML 4.01)
1.281     sakharuk  325:     $result =~ s/&(forall|\#8704);/\\ensuremath\{\\forall\}/g;
                    326:     $result =~ s/&(part|\#8706);/\\ensuremath\{\\partial\}/g;
                    327:     $result =~ s/&(exist|\#8707);/\\ensuremath\{\\exists\}/g;
                    328:     $result =~ s/&(empty|\#8709);/\\ensuremath\{\\emptyset\}/g;
                    329:     $result =~ s/&(nabla|\#8711);/\\ensuremath\{\\nabla\}/g;
                    330:     $result =~ s/&(isin|\#8712);/\\ensuremath\{\\in\}/g;
                    331:     $result =~ s/&(notin|\#8713);/\\ensuremath\{\\notin\}/g;
                    332:     $result =~ s/&(ni|\#8715);/\\ensuremath\{\\ni\}/g;
                    333:     $result =~ s/&(prod|\#8719);/\\ensuremath\{\\prod\}/g;
                    334:     $result =~ s/&(sum|\#8721);/\\ensuremath\{\\sum\}/g;
                    335:     $result =~ s/&(minus|\#8722);/\\ensuremath\{-\}/g;
                    336:     $result =~ s/&(lowast|\#8727);/\\ensuremath\{*\}/g;
                    337:     $result =~ s/&(radic|\#8730);/\\ensuremath\{\\surd\}/g;
                    338:     $result =~ s/&(prop|\#8733);/\\ensuremath\{\\propto\}/g;
                    339:     $result =~ s/&(infin|\#8734);/\\ensuremath\{\\infty\}/g;
                    340:     $result =~ s/&(ang|\#8736);/\\ensuremath\{\\angle\}/g;
                    341:     $result =~ s/&(and|\#8743);/\\ensuremath\{\\wedge\}/g;
                    342:     $result =~ s/&(or|\#8744);/\\ensuremath\{\\vee\}/g;
                    343:     $result =~ s/&(cap|\#8745);/\\ensuremath\{\\cap\}/g;
                    344:     $result =~ s/&(cup|\#8746);/\\ensuremath\{\\cup\}/g;
                    345:     $result =~ s/&(int|\#8747);/\\ensuremath\{\\int\}/g;
                    346:     $result =~ s/&(sim|\#8764);/\\ensuremath\{\\sim\}/g;
                    347:     $result =~ s/&(cong|\#8773);/\\ensuremath\{\\cong\}/g;
                    348:     $result =~ s/&(asymp|\#8776);/\\ensuremath\{\\approx\}/g;
                    349:     $result =~ s/&(ne|\#8800);/\\ensuremath\{\\not=\}/g;
                    350:     $result =~ s/&(equiv|\#8801);/\\ensuremath\{\\equiv\}/g;
                    351:     $result =~ s/&(le|\#8804);/\\ensuremath\{\\leq\}/g;
                    352:     $result =~ s/&(ge|\#8805);/\\ensuremath\{\\geq\}/g;
                    353:     $result =~ s/&(sub|\#8834);/\\ensuremath\{\\subset\}/g;
                    354:     $result =~ s/&(sup|\#8835);/\\ensuremath\{\\supset\}/g;
                    355:     $result =~ s/&(nsub|\#8836);/\\ensuremath\{\\not\\subset\}/g;
                    356:     $result =~ s/&(sube|\#8838);/\\ensuremath\{\\subseteq\}/g;
                    357:     $result =~ s/&(supe|\#8839);/\\ensuremath\{\\supseteq\}/g;
                    358:     $result =~ s/&(oplus|\#8853);/\\ensuremath\{\\oplus\}/g;
                    359:     $result =~ s/&(otimes|\#8855);/\\ensuremath\{\\otimes\}/g;
                    360:     $result =~ s/&(perp|\#8869);/\\ensuremath\{\\perp\}/g;
                    361:     $result =~ s/&(sdot|\#8901);/\\ensuremath\{\\cdot\}/g;
1.199     sakharuk  362: #Geometric Shapes (extended HTML 4.01)
1.281     sakharuk  363:     $result =~ s/&(loz|\#9674);/\\ensuremath\{\\Diamond\}/g;
1.199     sakharuk  364: #Miscellaneous Symbols (extended HTML 4.01)
1.281     sakharuk  365:     $result =~ s/&(spades|\#9824);/\\ensuremath\{\\spadesuit\}/g;
                    366:     $result =~ s/&(clubs|\#9827);/\\ensuremath\{\\clubsuit\}/g;
                    367:     $result =~ s/&(hearts|\#9829);/\\ensuremath\{\\heartsuit\}/g;
                    368:     $result =~ s/&(diams|\#9830);/\\ensuremath\{\\diamondsuit\}/g;
1.37      sakharuk  369:     return $result;
                    370: }
1.41      sakharuk  371: 
                    372: 
1.327     albertel  373:                   #width, height, oddsidemargin, evensidemargin, topmargin
                    374: my %page_formats=
                    375:     ('letter' => {
                    376: 	 'book' => {
                    377: 	     '1' => [ '7.1 in','10.2 in', '-0.57 in','-0.57 in','0 in'],
                    378: 	     '2' => ['3.66 in','10.2 in', '-0.57 in','-0.57 in','0 in']
                    379: 	 },
                    380: 	 'album' => {
                    381: 	     '1' => [ '8.8 in', '6.8 in','-40 pt in',  '-60 pt','0 in'],
                    382: 	     '2' => [ '4.4 in', '6.8 in','-0.5 in', '-1.5 in','3.5 in']
                    383: 	 },
                    384:      },
                    385:      'legal' => {
                    386: 	 'book' => {
                    387: 	     '1' => ['7.1 in','13 in',,'-0.57 in','-0.57 in','-0.5 in'],
                    388: 	     '2' => ['3.16 in','13 in','-0.57 in','-0.57 in','-0.5 in']
                    389: 	 },
                    390: 	 'album' => {
                    391: 	     '1' => [],
                    392: 	     '2' => []
                    393:           },
                    394:      },
                    395:      'tabloid' => {
                    396: 	 'book' => {
                    397: 	     '1' => ['9.8 in','16 in','-0.57 in','-0.57 in','-0.5 in'],
                    398: 	     '2' => ['4.9 in','16 in','-0.57 in','-0.57 in','-0.5 in']
                    399: 	 },
                    400: 	 'album' => {
                    401: 	     '1' => [],
                    402: 	     '2' => []
                    403:           },
                    404:      },
                    405:      'executive' => {
                    406: 	 'book' => {
                    407: 	     '1' => ['6.8 in','9 in','-0.57 in','-0.57 in','1.2 in'],
                    408: 	     '2' => ['3.1 in','9 in','-0.57 in','-0.57 in','1.2 in']
                    409: 	 },
                    410: 	 'album' => {
                    411: 	     '1' => [],
                    412: 	     '2' => []
                    413:           },
                    414:      },
                    415:      'a2' => {
                    416: 	 'book' => {
                    417: 	     '1' => [],
                    418: 	     '2' => []
                    419: 	 },
                    420: 	 'album' => {
                    421: 	     '1' => [],
                    422: 	     '2' => []
                    423:           },
                    424:      },
                    425:      'a3' => {
                    426: 	 'book' => {
                    427: 	     '1' => [],
                    428: 	     '2' => []
                    429: 	 },
                    430: 	 'album' => {
                    431: 	     '1' => [],
                    432: 	     '2' => []
                    433:           },
                    434:      },
                    435:      'a4' => {
                    436: 	 'book' => {
                    437: 	     '1' => ['176 mm','272 mm','-40 pt in','-60 pt','-0.5 in'],
                    438: 	     '2' => [ '91 mm','272 mm','-40 pt in','-60 pt','-0.5 in']
                    439: 	 },
                    440: 	 'album' => {
                    441: 	     '1' => ['8.5 in','7.7 in','-40 pt in','-60 pt','0 in'],
                    442: 	     '2' => ['3.9 in','7.7 in','-40 pt in','-60 pt','0 in']
                    443: 	 },
                    444:      },
                    445:      'a5' => {
                    446: 	 'book' => {
                    447: 	     '1' => [],
                    448: 	     '2' => []
                    449: 	 },
                    450: 	 'album' => {
                    451: 	     '1' => [],
                    452: 	     '2' => []
                    453:           },
                    454:      },
                    455:      'a6' => {
                    456: 	 'book' => {
                    457: 	     '1' => [],
                    458: 	     '2' => []
                    459: 	 },
                    460: 	 'album' => {
                    461: 	     '1' => [],
                    462: 	     '2' => []
                    463:           },
                    464:      },
                    465:      );
                    466: 
1.177     sakharuk  467: sub page_format {
1.140     sakharuk  468: #
1.326     sakharuk  469: #Supported paper format: "Letter [8 1/2x11 in]",      "Legal [8 1/2x14 in]",
                    470: #                        "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
                    471: #                        "A2 [420x594 mm]",           "A3 [297x420 mm]",
                    472: #                        "A4 [210x297 mm]",           "A5 [148x210 mm]",
                    473: #                        "A6 [105x148 mm]"
1.140     sakharuk  474: # 
                    475:     my ($papersize,$layout,$numberofcolumns) = @_; 
1.327     albertel  476:     return @{$page_formats{$papersize}->{$layout}->{$numberofcolumns}};
1.140     sakharuk  477: }
1.76      sakharuk  478: 
                    479: 
1.126     albertel  480: sub get_name {
                    481:     my ($uname,$udom)=@_;
                    482:     if (!defined($uname)) { $uname=$ENV{'user.name'}; }
1.212     albertel  483:     if (!defined($udom)) { $udom=$ENV{'user.domain'}; }
1.126     albertel  484:     my $plainname=&Apache::loncommon::plainname($uname,$udom);
1.213     albertel  485:     if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; }
                    486:     $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header');
                    487:     return $plainname;
1.126     albertel  488: }
                    489: 
1.213     albertel  490: sub get_course {
                    491:     my $courseidinfo;
                    492:     if (defined($ENV{'request.course.id'})) {
                    493: 	$courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'header');
                    494:     }
                    495:     return $courseidinfo;
                    496: }
1.177     sakharuk  497: 
1.76      sakharuk  498: sub page_format_transformation {
1.312     sakharuk  499:     my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; 
1.202     sakharuk  500:     my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);
1.312     sakharuk  501:     if ($selectionmade eq '4') {
                    502: 	$assignment='Problems from the Whole Course';
                    503:     } else {
                    504: 	$assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');
                    505:     }
1.261     sakharuk  506:     ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);
1.126     albertel  507:     my $name = &get_name();
1.213     albertel  508:     my $courseidinfo = &get_course();
                    509:     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
1.319     sakharuk  510:     my $topmargintoinsert = '';
                    511:     if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';}
1.325     sakharuk  512:     my $fancypagestatement='';
                    513:     if ($numberofcolumns eq '2') {
                    514: 	$fancypagestatement="\\fancyhead{}\\fancyhead[LO]{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}";
                    515:     } else {
                    516: 	$fancypagestatement="\\rhead{}\\chead{}\\lhead{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}";
                    517:     }
1.140     sakharuk  518:     if ($layout eq 'album') {
1.334     albertel  519: 	    $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1} /;
1.140     sakharuk  520:     } elsif ($layout eq 'book') {
                    521: 	if ($choice ne 'All class print') { 
1.334     albertel  522: 	    $text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}/;
1.140     sakharuk  523: 	} else {
1.319     sakharuk  524: 	    $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset $topmargintoinsert\\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 /;
                    525: 	}
1.326     sakharuk  526: 	if ($papersize eq 'a4') {
1.319     sakharuk  527: 	    $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/;
1.140     sakharuk  528: 	}
                    529:     }
1.214     sakharuk  530:     if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
                    531:     if ($indexlist eq 'yes') {
                    532: 	$text=~s/(\\begin{document})/\\makeindex $1/;
                    533: 	$text=~s/(\\end{document})/\\strut\\\\\\strut\\printindex $1/;
                    534:     }
1.140     sakharuk  535:     return $text;
                    536: }
                    537: 
                    538: 
1.33      sakharuk  539: sub page_cleanup {
                    540:     my $result = shift;	
1.65      sakharuk  541:  
                    542:     $result =~ m/\\end{document}(\d*)$/;
1.34      sakharuk  543:     my $number_of_columns = $1;
1.33      sakharuk  544:     my $insert = '{';
1.34      sakharuk  545:     for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33      sakharuk  546:     $insert .= '}';
1.65      sakharuk  547:     $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
1.34      sakharuk  548:     $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
                    549:     return $result,$number_of_columns;
1.7       sakharuk  550: }
1.5       sakharuk  551: 
1.3       sakharuk  552: 
1.60      sakharuk  553: sub details_for_menu {
1.335     albertel  554:     my ($helper)=@_;
                    555:     my $postdata=$ENV{'form.postdata'};
                    556:     if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; }
                    557:     my $name_of_resource = &Apache::lonnet::gettitle($postdata);
                    558:     my $symbolic = &Apache::lonnet::symbread($postdata);
1.233     www       559:     my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic);
1.123     albertel  560:     $map=&Apache::lonnet::clutter($map);
1.269     albertel  561:     my $name_of_sequence = &Apache::lonnet::gettitle($map);
1.63      albertel  562:     if ($name_of_sequence =~ /^\s*$/) {
1.123     albertel  563: 	$map =~ m|([^/]+)$|;
                    564: 	$name_of_sequence = $1;
1.63      albertel  565:     }
1.269     albertel  566:     my $name_of_map = &Apache::lonnet::gettitle($ENV{'request.course.uri'});
1.63      albertel  567:     if ($name_of_map =~ /^\s*$/) {
1.123     albertel  568: 	$ENV{'request.course.uri'} =~ m|([^/]+)$|;
                    569: 	$name_of_map = $1;
                    570:     }
1.335     albertel  571:     return ($name_of_resource,$name_of_sequence,$name_of_map);
1.76      sakharuk  572: }
                    573: 
                    574: 
                    575: sub latex_corrections {
                    576: 
1.316     sakharuk  577:     my ($number_of_columns,$result,$selectionmade) = @_;
1.76      sakharuk  578: 
1.185     sakharuk  579: #    $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
1.76      sakharuk  580:     $result =~ s/\$number_of_columns/$number_of_columns/g;
1.316     sakharuk  581:     if ($selectionmade ne '1') {
                    582: 	$result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\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/;
                    583:     } else {
                    584: 	$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/;
                    585:     }
1.91      sakharuk  586:     $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
                    587:     $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g;
1.76      sakharuk  588: #-- LaTeX corrections     
                    589:     my $first_comment = index($result,'<!--',0);
                    590:     while ($first_comment != -1) {
                    591: 	my $end_comment = index($result,'-->',$first_comment);
                    592: 	substr($result,$first_comment,$end_comment-$first_comment+3) = '';
                    593: 	$first_comment = index($result,'<!--',$first_comment);
                    594:     }
                    595:     $result =~ s/^\s+$//gm; #remove empty lines
1.94      sakharuk  596:     $result =~ s/(\s)(\s+)/$1/g; #removes more than one empty space
1.76      sakharuk  597:     $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
                    598:     $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
                    599:     $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1.313     sakharuk  600:     $result =~ s/\\\\\s+\[/ \[/g;
1.76      sakharuk  601:     #conversion of html characters to LaTeX equivalents
                    602:     if ($result =~ m/&(\w+|#\d+);/) {
                    603: 	$result = &character_chart($result);
                    604:     }
                    605:     $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
                    606:     $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
                    607: 
                    608:     return $result;
1.60      sakharuk  609: }
                    610: 
1.3       sakharuk  611: 
1.214     sakharuk  612: sub index_table {
                    613:     my $currentURL = shift;
                    614:     my $insex_string='';
                    615:     $currentURL=~s/\.([^\/+])$/\.$1\.meta/;
                    616:     $insex_string=&Apache::lonnet::metadata($currentURL,'keywords');
                    617:     return $insex_string;
                    618: }
                    619: 
                    620: 
1.215     sakharuk  621: sub IndexCreation {
                    622:     my ($texversion,$currentURL)=@_;
                    623:     my @key_words=split(/,/,&index_table($currentURL));
                    624:     my $chunk='';
                    625:     my $st=index $texversion,'\addcontentsline{toc}{subsection}{';
                    626:     if ($st>0) {
                    627: 	for (my $i=0;$i<3;$i++) {$st=(index $texversion,'}',$st+1);}
                    628: 	$chunk=substr($texversion,0,$st+1);
                    629: 	substr($texversion,0,$st+1)=' ';
                    630:     }
                    631:     foreach my $key_word (@key_words) {
                    632: 	if ($key_word=~/\S+/) {
                    633: 	    $texversion=~s/\b($key_word)\b/$1 \\index{$key_word} /i;
                    634: 	}
                    635:     }			
                    636:     if ($st>0) {substr($texversion,0,1)=$chunk;}
                    637:     return $texversion;
                    638: }
                    639: 
1.242     sakharuk  640: sub print_latex_header {
                    641:     my $mode=shift;
                    642:     my $output='\documentclass[letterpaper]{article}';
                    643:     if ($mode eq 'batchmode') {
                    644: 	$output.='\batchmode';
                    645:     }
                    646:     $output.='\newcommand{\keephidden}[1]{}\renewcommand{\deg}{$^{\circ}$}'.
                    647: 	     '\usepackage{longtable}\usepackage{textcomp}\usepackage{makeidx}'.
                    648: 	     '\usepackage[dvips]{graphicx}\usepackage{epsfig}\usepackage{calc}'.
                    649: 	     '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}'.
                    650: 	     '\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}'.
                    651: 	     '\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}'.
                    652: 	     '\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}'.
                    653: 	     '\setlength{\abovedisplayshortskip}{-0.04in}'.
                    654: 	     '\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'.
                    655: 	     '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large'.
                    656: 	     '\textbf{Index}} \newline \setlength{\rightmargin}{0in}'.
                    657: 	     '\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}'.
                    658: 	     '\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}'.
                    659: 	     '\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}'.
                    660: 	     '\setlength{\abovedisplayshortskip}{-0.04in}'.
                    661: 	     '\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}\begin{document}';
                    662:     return $output;	     
                    663: }
                    664: 
                    665: sub path_to_problem {
1.328     albertel  666:     my ($urlp,$colwidth)=@_;
1.242     sakharuk  667:     my $newurlp = '';
1.328     albertel  668:     $colwidth=~s/\s*mm\s*$//;
                    669: #characters average about 2 mm in width
                    670:     if (length($urlp)*2 > $LaTeXwidth) {
                    671: 	my @elements = split '/',$urlp;
                    672: 	my $curlength=0;
                    673: 	foreach my $element (@elements) {
                    674: 	    if ($curlength+(length($element)*2) > $colwidth) {
                    675: 		$newurlp .=  '|\vskip -1 mm \noindent \verb|';
                    676: 		$curlength=0;
                    677: 	    } else {
                    678: 		$curlength+=length($element)*2;
1.242     sakharuk  679: 	    }
1.328     albertel  680: 	    $newurlp.='/'.$element;
1.242     sakharuk  681: 	}
1.253     sakharuk  682:     } else {
                    683: 	$newurlp=$urlp;
1.242     sakharuk  684:     }
                    685:     return '{\small\noindent\verb|'.$newurlp.'|\vskip 0 mm}';
                    686: }
1.215     sakharuk  687: 
1.275     sakharuk  688: sub recalcto_mm {
                    689:     my $textwidth=shift;
                    690:     my $LaTeXwidth;
                    691:     if ($textwidth=~/(\d+\.?\d*)\s*cm/) {
                    692: 	$LaTeXwidth = $1*10;
                    693:     } elsif ($textwidth=~/(\d+\.?\d*)\s*mm/) {
                    694: 	$LaTeXwidth = $1;
                    695:     } elsif ($textwidth=~/(\d+\.?\d*)\s*in/) {
                    696: 	$LaTeXwidth = $1*25.4;
                    697:     }
                    698:     $LaTeXwidth.=' mm';
                    699:     return $LaTeXwidth;
                    700: }
                    701: 
1.285     albertel  702: sub get_textwidth {
                    703:     my ($helper,$LaTeXwidth)=@_;
1.286     albertel  704:     my $textwidth=$LaTeXwidth;
1.285     albertel  705:     if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
                    706: 	$helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
1.286     albertel  707: 	$textwidth=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.
                    708: 				$helper->{'VARS'}->{'pagesize.widthunit'});
1.285     albertel  709:     }
1.286     albertel  710:     return $textwidth;
1.285     albertel  711: }
                    712: 
1.296     sakharuk  713: 
                    714: sub unsupported {
1.307     sakharuk  715:     my ($currentURL,$mode)=@_;
                    716:     if ($mode ne '') {$mode='\\'.$mode}
1.308     sakharuk  717:     my $result.= &print_latex_header($mode);
1.301     sakharuk  718:     if ($currentURL=~/\/ext\//) {
1.296     sakharuk  719: 	$result.=' \strut \\\\ THIS IS EXTERNAL RESOURCE WITH URL \strut \\\\ '.$currentURL.' ';
                    720:     } else {
                    721: 	$result.=$currentURL;
                    722:     }
1.297     sakharuk  723:     $result.= '\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill} \end{document}';
1.296     sakharuk  724:     return $result;
                    725: }
                    726: 
                    727: 
1.177     sakharuk  728: sub output_data {
1.184     sakharuk  729:     my ($r,$helper,$rparmhash) = @_;
                    730:     my %parmhash = %$rparmhash;
1.187     www       731:     my $bodytag=&Apache::loncommon::bodytag('Preparing Printout');
1.140     sakharuk  732:     $r->print(<<ENDPART);
                    733: <html>
1.264     sakharuk  734: <script type="text/javascript" language="Javascript" >
                    735:     var editbrowser;
                    736:     function openbrowser(formname,elementname,only,omit) {
                    737:         var url = '/res/?';
                    738:         if (editbrowser == null) {
                    739:             url += 'launch=1&';
                    740:         }
                    741:         url += 'catalogmode=interactive&';
                    742:         url += 'mode=parmset&';
                    743:         url += 'form=' + formname + '&';
                    744:         if (only != null) {
                    745:             url += 'only=' + only + '&';
                    746:         } 
                    747:         if (omit != null) {
                    748:             url += 'omit=' + omit + '&';
                    749:         }
                    750:         url += 'element=' + elementname + '';
                    751:         var title = 'Browser';
                    752:         var options = 'scrollbars=1,resizable=1,menubar=0';
                    753:         options += ',width=700,height=600';
                    754:         editbrowser = open(url,title,options,'1');
                    755:         editbrowser.focus();
                    756:     }
                    757: </script>
1.140     sakharuk  758: <head>
                    759: <title>LON-CAPA output for printing</title>
                    760: </head>
1.187     www       761: $bodytag
                    762: Please stand by while processing your print request, this may take some time ...
1.140     sakharuk  763: ENDPART
                    764: 
                    765:     my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
                    766:     my ($result,$selectionmade) = ('','');
                    767:     my $number_of_columns = 1; #used only for pages to determine the width of the cell
                    768:     my @temporary_array=split /\|/,$format_from_helper;
                    769:     my ($laystyle,$numberofcolumns,$papersize)=@temporary_array;
                    770:     if ($laystyle eq 'L') {
                    771: 	$laystyle='album';
                    772:     } else {
                    773: 	$laystyle='book';
                    774:     }
1.177     sakharuk  775:     my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns);
1.140     sakharuk  776:     my $assignment =  $ENV{'form.assignment'};
1.275     sakharuk  777:     my $LaTeXwidth=&recalcto_mm($textwidth); 
1.272     sakharuk  778:     my @print_array=();
1.274     sakharuk  779:     my @student_names=();
1.153     sakharuk  780:     
1.140     sakharuk  781:     if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {
1.143     sakharuk  782:       #-- single document - problem, page, html, xml, ...
                    783: 	my $currentURL;
1.162     sakharuk  784: 	if ($helper->{'VARS'}->{'construction'} ne '1') {
1.185     sakharuk  785:             #prints published resource
1.153     sakharuk  786: 	    $currentURL=$helper->{'VARS'}->{'postdata'};
1.143     sakharuk  787: 	} else {
1.185     sakharuk  788:             #prints resource from the construction space
1.240     albertel  789: 	    $currentURL='/'.$helper->{'VARS'}->{'filename'};
1.206     sakharuk  790: 	    if ($currentURL=~/([^?]+)/) {$currentURL=$1;}
1.143     sakharuk  791: 	}
1.140     sakharuk  792: 	$selectionmade = 1;
1.143     sakharuk  793: 	if ($currentURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.169     albertel  794: 	    my $rndseed=time;
1.242     sakharuk  795: 	    my $texversion='';
                    796: 	    if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
                    797: 		my %moreenv;
                    798: 		$moreenv{'request.filename'}=$currentURL;
1.265     sakharuk  799: 		if ($helper->{'VARS'}->{'style_file'}=~/\w/) {
                    800: 		    $moreenv{'construct.style'}=$helper->{'VARS'}->{'style_file'};
                    801: 		    my $dom = $ENV{'user.domain'};
                    802: 		    my $user = $ENV{'user.name'};
                    803: 		    my $put_result = &Apache::lonnet::put('environment',{'construct.style'=>$helper->{'VARS'}->{'style_file'}},$dom,$user);
                    804: 		}
1.242     sakharuk  805: 		my %form;
1.290     sakharuk  806:                 if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';}
1.242     sakharuk  807: 		$form{'grade_target'}='tex';
1.285     albertel  808: 		$form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.242     sakharuk  809: 		$form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310     sakharuk  810: 		$form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.242     sakharuk  811: 		$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.309     sakharuk  812: 		$form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
                    813: 		if ($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') {$form{'problem_split'}='yes';}
1.242     sakharuk  814: 		if ($helper->{'VARS'}->{'curseed'}) {
                    815: 		    $rndseed=$helper->{'VARS'}->{'curseed'};
                    816: 		}
                    817: 		$form{'rndseed'}=$rndseed;
                    818: 		&Apache::lonnet::appenv(%moreenv);
                    819: 		&Apache::lonnet::delenv('form.counter');
                    820: 		&Apache::lonxml::init_counter();
1.275     sakharuk  821: 		$texversion.=&Apache::lonnet::ssi($currentURL,%form);
1.242     sakharuk  822: 		&Apache::lonnet::delenv('form.counter');
                    823: 		&Apache::lonnet::delenv('request.filename');
1.230     albertel  824: 	    }
1.242     sakharuk  825: 	    if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
                    826: 	       ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.166     albertel  827: 		my %form;
                    828: 		$form{'grade_target'}='answer';
1.167     albertel  829: 		$form{'answer_output_mode'}='tex';
1.169     albertel  830: 		$form{'rndseed'}=$rndseed;
1.166     albertel  831: 		my $answer=&Apache::lonnet::ssi($currentURL,%form);
1.242     sakharuk  832: 		if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                    833: 		    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
                    834: 		} else {
                    835: 		    $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
1.245     sakharuk  836: 		    if ($helper->{'VARS'}->{'construction'} ne '1') {
                    837: 			$texversion.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}).'}\vskip 0 mm ';
                    838: 			$texversion.=&path_to_problem ($currentURL,$LaTeXwidth);
                    839: 		    } else {
                    840: 			$texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';
                    841: 			my $URLpath=$currentURL;
                    842: 			$URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;
                    843: 			$texversion.=&path_to_problem ($URLpath,$LaTeXwidth);
                    844: 		    }
1.242     sakharuk  845: 		    $texversion.='\vskip 1 mm '.$answer.'\end{document}';
                    846: 		}
1.163     sakharuk  847: 	    }
1.214     sakharuk  848: 	    if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
1.215     sakharuk  849: 		$texversion=&IndexCreation($texversion,$currentURL);
1.214     sakharuk  850: 	    }
1.219     sakharuk  851: 	    if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
                    852: 		$texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
                    853: 
                    854: 	    }
1.162     sakharuk  855: 	    $result .= $texversion;
                    856: 	    if ($currentURL=~m/\.page\s*$/) {
                    857: 		($result,$number_of_columns) = &page_cleanup($result);
                    858: 	    }
1.227     sakharuk  859:         } elsif ($currentURL=~/\.sequence$/ && $helper->{'VARS'}->{'construction'} eq '1') {
                    860:             #printing content of sequence from the construction space	
                    861: 	    my $flag_latex_header_remove = 'NO'; 
                    862: 	    my $rndseed=time;
1.231     albertel  863: 	    if ($helper->{'VARS'}->{'curseed'}) {
                    864: 		$rndseed=$helper->{'VARS'}->{'curseed'};
                    865: 	    }
1.227     sakharuk  866: 	    $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
                    867: 	    my $errtext=&Apache::lonratedt::mapread($currentURL);
                    868: 	    for (my $member=0;$member<=$#Apache::lonratedt::order;$member++) {
                    869: 		$Apache::lonratedt::resources[$Apache::lonratedt::order[$member]]=~/^([^:]*):([^:]*):/;
                    870: 		my $urlp=$2;
                    871: 		if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
1.245     sakharuk  872: 		    my $texversion='';
                    873: 		    if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
                    874: 			my %form;
                    875: 			$form{'grade_target'}='tex';
1.285     albertel  876: 			$form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.245     sakharuk  877: 			$form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310     sakharuk  878: 			$form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.245     sakharuk  879: 			$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
                    880: 			$form{'rndseed'}=$rndseed;
                    881: 			$texversion=&Apache::lonnet::ssi($urlp,%form);
                    882: 		    }
1.249     sakharuk  883: 		    if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
                    884: 		       ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && 
                    885: 		       ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) {
1.227     sakharuk  886: 			my %form;
                    887: 			$form{'grade_target'}='answer';
                    888: 			$form{'answer_output_mode'}='tex';
                    889: 			$form{'rndseed'}=$rndseed;
1.232     sakharuk  890:                         if ($urlp=~/\/res\//) {$ENV{'request.state'}='published';}
1.227     sakharuk  891: 			my $answer=&Apache::lonnet::ssi($urlp,%form);
1.245     sakharuk  892: 			if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                    893: 			    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
                    894: 			} else {
                    895: 			    $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
                    896: 			    $texversion.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}).'}\vskip 0 mm ';
                    897: 			    $texversion.=&path_to_problem ($currentURL,$LaTeXwidth);
                    898: 			    $texversion.='\vskip 1 mm '.$answer.'\end{document}';
                    899: 			}
1.227     sakharuk  900: 		    }
                    901: 		    if ($flag_latex_header_remove ne 'NO') {
                    902: 			$texversion = &latex_header_footer_remove($texversion);
                    903: 		    } else {
                    904: 			$texversion =~ s/\\end{document}//;
                    905: 		    }
                    906: 		    if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
                    907: 			$texversion=&IndexCreation($texversion,$urlp);
                    908: 		    }
1.232     sakharuk  909: 		    if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URpL'} eq 'yes') {
1.227     sakharuk  910: 			$texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
                    911: 		    }
                    912: 		    $result.=$texversion;
                    913: 		    $flag_latex_header_remove = 'YES';
                    914: 		} elsif ($urlp=~/\.(sequence|page)$/) {
1.229     sakharuk  915: 		    $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent ';
1.227     sakharuk  916: 		}  
                    917: 	    }
1.228     sakharuk  918: 	    if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;}
1.227     sakharuk  919: 	    $result .= '\end{document}';   
1.301     sakharuk  920: 	} elsif ($currentURL=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { 
1.258     sakharuk  921: 		my %form;
                    922: 		$form{'grade_target'}='tex';
1.285     albertel  923: 		$form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.258     sakharuk  924: 		$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.298     sakharuk  925: 		if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;}
1.258     sakharuk  926: 		my $texversion=&Apache::lonnet::ssi($currentURL,%form);
                    927: 		$result .= $texversion;
1.162     sakharuk  928: 	} else {
1.307     sakharuk  929: 	    $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'});
1.162     sakharuk  930: 	}
1.142     sakharuk  931:     } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or
                    932:              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
1.252     sakharuk  933:              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') or
                    934: 	     ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences')) { 
1.141     sakharuk  935:         #-- produce an output string
1.296     sakharuk  936: 	if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') {
                    937: 	    $selectionmade = 2;
                    938: 	} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {
                    939: 	    $selectionmade = 3;
                    940: 	} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') {
                    941: 	    $selectionmade = 4;
                    942: 	} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'select_sequences') {
                    943: 	    $selectionmade = 7;
                    944: 	}
1.193     sakharuk  945: 	my %form=();	   
                    946: 	$form{'grade_target'}='tex';
1.285     albertel  947: 	$form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.193     sakharuk  948: 	$form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.310     sakharuk  949: 	$form{'suppress_tries'}=$parmhash{'suppress_tries'};
1.203     sakharuk  950: 	$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.309     sakharuk  951: 	$form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
                    952: 	if ($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') {$form{'problem_split'}='yes';}
1.141     sakharuk  953: 	my $flag_latex_header_remove = 'NO';
                    954: 	my $flag_page_in_sequence = 'NO';
                    955: 	my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.193     sakharuk  956: 	my $prevassignment='';
1.270     sakharuk  957: 	&Apache::lonnet::delenv('form.counter');
1.201     sakharuk  958: 	&Apache::lonxml::init_counter();
1.141     sakharuk  959: 	for (my $i=0;$i<=$#master_seq;$i++) {
1.236     albertel  960: 	    my (undef,undef,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
1.237     albertel  961: 	    $urlp=&Apache::lonnet::clutter($urlp);
1.166     albertel  962: 	    $form{'symb'}=$master_seq[$i];
1.236     albertel  963: 	    my ($sequence)=&Apache::lonnet::decode_symb($master_seq[$i]);
                    964: 	    my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #tittle of the assignment which contains this problem
1.267     sakharuk  965: 	    if ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;}
1.247     sakharuk  966: 	    if ($i==0) {$prevassignment=$assignment;}
1.141     sakharuk  967: 	    #&Apache::lonnet::logthis("Trying to get $urlp with symb $master_seq[$i]");
1.297     sakharuk  968: 	    my $texversion='';
1.296     sakharuk  969: 	    if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.297     sakharuk  970: 		$texversion.=&Apache::lonnet::ssi($urlp,%form);
1.296     sakharuk  971: 		if ($urlp=~/\.page$/) {
                    972: 		    ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
                    973: 		    if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;} 
                    974: 		    $texversion =~ s/\\end{document}\d*/\\end{document}/;
                    975: 		    $flag_page_in_sequence = 'YES';
                    976: 		} 
                    977: 		my $lonidsdir=$r->dir_config('lonIDsDir');
                    978: 		my $envfile=$ENV{'user.environment'};
                    979: 		$envfile=~/\/([^\/]+)\.id$/;
                    980: 		$envfile=$1;
                    981: 		&Apache::lonnet::transfer_profile_to_env($lonidsdir,$envfile);
                    982: 		my $current_counter=$ENV{'form.counter'};
                    983: 		if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
                    984: 		   ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
                    985: 		    my %form;
                    986: 		    $form{'grade_target'}='answer';
                    987: 		    $form{'answer_output_mode'}='tex';
                    988: 		    my $answer=&Apache::lonnet::ssi($urlp,%form);
                    989: 		    &Apache::lonnet::appenv(('form.counter' => $current_counter));
                    990: 		    if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                    991: 			$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
1.249     sakharuk  992: 		    } else {
1.307     sakharuk  993: 			if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
1.296     sakharuk  994: 			    $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
                    995: 			    $texversion.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($urlp).'}\vskip 0 mm ';
                    996: 			    $texversion.=&path_to_problem ($urlp,$LaTeXwidth);
                    997: 			    $texversion.='\vskip 1 mm '.$answer;
                    998: 			} else {
                    999: 			    $texversion='';
                   1000: 			}
1.249     sakharuk 1001: 		    }
1.246     sakharuk 1002: 		}
1.296     sakharuk 1003: 		if ($flag_latex_header_remove ne 'NO') {
                   1004: 		    $texversion = &latex_header_footer_remove($texversion);
                   1005: 		} else {
                   1006: 		    $texversion =~ s/\\end{document}//;
                   1007: 		}
                   1008: 		if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
                   1009: 		    $texversion=&IndexCreation($texversion,$urlp);
                   1010: 		}
                   1011: 		if (($selectionmade == 4) and ($assignment ne $prevassignment)) {
                   1012: 		    my $name = &get_name();
                   1013: 		    my $courseidinfo = &get_course();
                   1014: 		    if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
                   1015: 		    $prevassignment=$assignment;
1.334     albertel 1016: 		    $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm ';
1.296     sakharuk 1017: 		}
                   1018: 		$result .= $texversion;
                   1019: 		$flag_latex_header_remove = 'YES';   
1.301     sakharuk 1020: 	    } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { 
                   1021: 		my %form;
                   1022: 		$form{'grade_target'}='tex';
                   1023: 		$form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
                   1024: 		$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
                   1025: 		if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;}
                   1026: 		my $texversion=&Apache::lonnet::ssi($urlp,%form);
                   1027: 		if ($flag_latex_header_remove ne 'NO') {
                   1028: 		    $texversion = &latex_header_footer_remove($texversion);
                   1029: 		} else {
                   1030: 		    $texversion =~ s/\\end{document}/\\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/\$number_of_columns\]\[b\]\{\\hrulefill\}/;
                   1031: 		}
                   1032: 		$result .= $texversion;
                   1033: 		$flag_latex_header_remove = 'YES'; 
1.141     sakharuk 1034: 	    } else {
1.307     sakharuk 1035: 		$texversion=&unsupported($urlp,$helper->{'VARS'}->{'LATEX_TYPE'});
1.297     sakharuk 1036: 		if ($flag_latex_header_remove ne 'NO') {
                   1037: 		    $texversion = &latex_header_footer_remove($texversion);
                   1038: 		} else {
                   1039: 		    $texversion =~ s/\\end{document}//;
                   1040: 		}
                   1041: 		$result .= $texversion;
                   1042: 		$flag_latex_header_remove = 'YES';   
1.296     sakharuk 1043: 	    }	    
1.331     albertel 1044: 	    if (&Apache::loncommon::connection_aborted($r)) { last; }
1.141     sakharuk 1045: 	}
                   1046: 	&Apache::lonnet::delenv('form.counter');
                   1047: 	if ($flag_page_in_sequence eq 'YES') {$result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;}	
                   1048: 	$result .= '\end{document}';
1.284     albertel 1049:      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||
                   1050: 	      ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')){
1.150     sakharuk 1051:      #-- prints assignments for whole class or for selected students  
1.284     albertel 1052: 	 my $type;
1.254     sakharuk 1053: 	 if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') {
                   1054: 	     $selectionmade=5;
1.284     albertel 1055: 	     $type='problems';
1.254     sakharuk 1056: 	 } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students') {
                   1057: 	     $selectionmade=8;
1.284     albertel 1058: 	     $type='resources';
1.254     sakharuk 1059: 	 }
1.150     sakharuk 1060: 	 my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'};
1.278     albertel 1061:          if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0' ||
                   1062: 	     $helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq 'all' ) {
                   1063: 	     $helper->{'VARS'}->{'NUMBER_TO_PRINT'}=$#students+1;
                   1064: 	 }
1.150     sakharuk 1065: 	 my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
                   1066: 	 #loop over students
                   1067: 	 my $flag_latex_header_remove = 'NO'; 
                   1068: 	 my %moreenv;
1.330     sakharuk 1069:          $moreenv{'instructor_comments'}='hide';
1.285     albertel 1070: 	 $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.309     sakharuk 1071: 	 $moreenv{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'};
                   1072: 	 if ($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') {$moreenv{'problem_split'}='yes';}
1.318     albertel 1073: 	 my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1,'inline','75');
1.272     sakharuk 1074: 	 my $student_counter=-1;
1.150     sakharuk 1075: 	 foreach my $person (@students) {
1.311     sakharuk 1076:              my $duefile="/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.due";
                   1077: 	     if (-e $duefile) {
                   1078: 		 my $temp_file = Apache::File->new('>>'.$duefile);
                   1079: 		 print $temp_file "1969\n";
                   1080: 	     }
1.272     sakharuk 1081: 	     $student_counter++;
1.284     albertel 1082: 	     my $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'});
                   1083: 	     my ($output,$fullname)=&print_resources($r,$helper,$person,$type,\%moreenv,\@master_seq,$flag_latex_header_remove);
                   1084: 	     $print_array[$i].=$output;
                   1085: 	     $student_names[$i].=$person.':'.$fullname.'_END_';
                   1086: 	     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,&mt('last student').' '.$fullname);
                   1087: 	     $flag_latex_header_remove = 'YES';
1.331     albertel 1088: 	     if (&Apache::loncommon::connection_aborted($r)) { last; }
1.284     albertel 1089: 	 }
                   1090: 	 &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                   1091: 	 $result .= $print_array[0].'  \end{document}';
                   1092:      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||
                   1093: 	      ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon')  ) { 
1.292     albertel 1094: 	 my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                   1095: 	 my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
1.288     albertel 1096: 	 my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'};
                   1097: 	 my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'};
1.292     albertel 1098: 	 my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'};
1.288     albertel 1099: 	 my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
                   1100: 	 my $seed=time+($$<<16)+($$);
1.292     albertel 1101: 	 my @allcodes;
                   1102: 	 if ($old_name) {
                   1103: 	     my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum);
                   1104: 	     @allcodes=split(',',$result{$old_name});
1.336     albertel 1105: 	     $num_todo=scalar(@allcodes);
1.292     albertel 1106: 	 } else {
                   1107: 	     my %allcodes;
1.299     albertel 1108: 	     srand($seed);
1.292     albertel 1109: 	     for (my $i=0;$i<$num_todo;$i++) {
                   1110: 		 $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,'6');
                   1111: 	     }
                   1112: 	     if ($code_name) {
                   1113: 		 &Apache::lonnet::put('CODEs',
                   1114: 				      {$code_name =>join(',',keys(%allcodes))},
                   1115: 				      $cdom,$cnum);
                   1116: 	     }
                   1117: 	     @allcodes=keys(%allcodes);
                   1118: 	 }
1.336     albertel 1119: 	 my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
                   1120: 	 my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'});
                   1121: 	 my $number_per_page=$helper->{'VARS'}->{'NUMBER_TO_PRINT'};
                   1122: 	 if ($number_per_page eq '0' || $number_per_page eq 'all') {
                   1123: 	     $number_per_page=$num_todo;
                   1124: 	 }
                   1125: 	 my $flag_latex_header_remove = 'NO'; 
                   1126: 	 my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline','75');
1.295     albertel 1127: 	 my $count=0;
1.292     albertel 1128: 	 foreach my $code (sort(@allcodes)) {
1.295     albertel 1129: 	     my $file_num=int($count/$number_per_page);
1.292     albertel 1130: 	     $moreenv{'CODE'}=&num_to_letters($code);
1.288     albertel 1131: 	     my ($output,$fullname)=
                   1132: 		 &print_resources($r,$helper,'anonymous',$type,\%moreenv,
                   1133: 				  \@master_seq,$flag_latex_header_remove);
1.295     albertel 1134: 	     $print_array[$file_num].=$output;
1.288     albertel 1135: 	     &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                   1136: 				       &mt('last assignment').' '.$fullname);
                   1137: 	     $flag_latex_header_remove = 'YES';
1.295     albertel 1138: 	     $count++;
1.331     albertel 1139: 	     if (&Apache::loncommon::connection_aborted($r)) { last; }
1.288     albertel 1140: 	 }
                   1141: 	 &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                   1142: 	 $result .= $print_array[0].'  \end{document}';
                   1143:      } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') {      
1.151     sakharuk 1144:     #prints selected problems from the subdirectory 
                   1145: 	$selectionmade = 6;
                   1146:         my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
1.154     sakharuk 1147: 	@list_of_files=sort @list_of_files;
1.175     sakharuk 1148: 	my $flag_latex_header_remove = 'NO'; 
                   1149: 	my $rndseed=time;
1.230     albertel 1150: 	if ($helper->{'VARS'}->{'curseed'}) {
                   1151: 	    $rndseed=$helper->{'VARS'}->{'curseed'};
                   1152: 	}
1.151     sakharuk 1153: 	for (my $i=0;$i<=$#list_of_files;$i++) {
1.152     sakharuk 1154: 	    my $urlp = $list_of_files[$i];
1.253     sakharuk 1155: 	    $urlp=~s|//|/|;
1.152     sakharuk 1156: 	    if ($urlp=~/\//) {
1.166     albertel 1157: 		my %form;
                   1158: 		$form{'grade_target'}='tex';
1.285     albertel 1159: 		$form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
1.175     sakharuk 1160: 		$form{'rndseed'}=$rndseed;
1.152     sakharuk 1161: 		if ($urlp =~ m|/home/([^/]+)/public_html|) {
                   1162: 		    $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
                   1163: 		} else {
1.302     sakharuk 1164: 		    $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||;
1.152     sakharuk 1165: 		}
1.166     albertel 1166: 		my $texversion=&Apache::lonnet::ssi($urlp,%form);
1.251     sakharuk 1167: 		if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
1.253     sakharuk 1168: 		   ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.174     sakharuk 1169: 		    my %form;
                   1170: 		    $form{'grade_target'}='answer';
                   1171: 		    $form{'answer_output_mode'}='tex';
1.203     sakharuk 1172: 		    $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.174     sakharuk 1173: 		    $form{'rndseed'}=$rndseed;
                   1174: 		    my $answer=&Apache::lonnet::ssi($urlp,%form);
1.251     sakharuk 1175: 		    if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                   1176: 			$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
                   1177: 		    } else {
1.253     sakharuk 1178: 			$texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
                   1179: 			if ($helper->{'VARS'}->{'construction'} ne '1') {
                   1180: 			    $texversion.='\vskip 0 mm \noindent ';
                   1181: 			    $texversion.=&path_to_problem ($urlp,$LaTeXwidth);
                   1182: 			} else {
                   1183: 			    $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';
                   1184: 			    my $URLpath=$urlp;
                   1185: 			    $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;
                   1186: 			    $texversion.=&path_to_problem ($URLpath,$LaTeXwidth);
                   1187: 			}
                   1188: 			$texversion.='\vskip 1 mm '.$answer.'\end{document}';
1.251     sakharuk 1189: 		    }
1.174     sakharuk 1190: 		}
1.151     sakharuk 1191:                 #this chunck is responsible for printing the path to problem
1.253     sakharuk 1192: 		my $newurlp=$urlp;
                   1193: 		if ($newurlp=~/~/) {$newurlp=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;}
                   1194: 		$newurlp=&path_to_problem($newurlp,$LaTeXwidth);
1.242     sakharuk 1195: 		$texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 $newurlp/;
1.152     sakharuk 1196: 		if ($flag_latex_header_remove ne 'NO') {
                   1197: 		    $texversion = &latex_header_footer_remove($texversion);
                   1198: 		} else {
                   1199: 		    $texversion =~ s/\\end{document}//;
1.216     sakharuk 1200: 		}
                   1201: 		if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
                   1202: 		    $texversion=&IndexCreation($texversion,$urlp);
1.152     sakharuk 1203: 		}
1.219     sakharuk 1204: 		if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
                   1205: 		    $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
                   1206: 		    
                   1207: 		}
1.152     sakharuk 1208: 		$result .= $texversion;
                   1209: 	    }
                   1210: 	    $flag_latex_header_remove = 'YES';  
1.151     sakharuk 1211: 	}
1.175     sakharuk 1212: 	if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\typeout)/ RANDOM SEED IS $rndseed $1/;}
1.152     sakharuk 1213: 	$result .= '\end{document}';      	
1.140     sakharuk 1214:     }
                   1215: #-------------------------------------------------------- corrections for the different page formats
1.312     sakharuk 1216:     $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$selectionmade);
1.316     sakharuk 1217:     $result = &latex_corrections($number_of_columns,$result,$selectionmade);
                   1218:     for (my $i=1;$i<=$#print_array;$i++) {$print_array[$i] = &latex_corrections($number_of_columns,$print_array[$i],$selectionmade);}
1.190     sakharuk 1219:     #changes page's parameters for the one column output 
1.195     sakharuk 1220:     if ($numberofcolumns == 1) {
1.261     sakharuk 1221: 	$result =~ s/\\textwidth\s*=\s*\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
                   1222: 	$result =~ s/\\textheight\s*=\s*\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
                   1223: 	$result =~ s/\\evensidemargin\s*=\s*\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
                   1224: 	$result =~ s/\\oddsidemargin\s*=\s*\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
1.195     sakharuk 1225:     }
1.140     sakharuk 1226: #-- writing .tex file in prtspool 
                   1227:     my $temp_file;
1.277     albertel 1228:     my $identifier = &Apache::loncommon::get_cgi_id();
                   1229:     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".$identifier.".tex";
                   1230:     if (!($#print_array>0)) { 
                   1231: 	unless ($temp_file = Apache::File->new('>'.$filename)) {
                   1232: 	    $r->log_error("Couldn't open $filename for output $!");
                   1233: 	    return SERVER_ERROR; 
                   1234: 	}
                   1235: 	print $temp_file $result;
                   1236: 	my $begin=index($result,'\begin{document}',0);
                   1237: 	my $inc=substr($result,0,$begin+16);
                   1238:     } else {
                   1239: 	my $begin=index($result,'\begin{document}',0);
                   1240: 	my $inc=substr($result,0,$begin+16);
                   1241:         for (my $i=0;$i<=$#print_array;$i++) {
                   1242: 	    if ($i==0) {
                   1243: 		$print_array[$i]=$result;
                   1244: 	    } else {
                   1245: 		my $anobegin=index($print_array[$i],'\setcounter{page}',0);
                   1246: 		substr($print_array[$i],0,$anobegin)='';
                   1247: 		$print_array[$i]=$inc.$print_array[$i].'\end{document}';
                   1248: 	    }
1.272     sakharuk 1249: 	    my $temp_file;
1.273     sakharuk 1250: 	    my $newfilename=$filename;
1.277     albertel 1251: 	    my $num=$i+1;
                   1252: 	    $newfilename =~s/\.tex$/_$num\.tex/; 
1.272     sakharuk 1253: 	    unless ($temp_file = Apache::File->new('>'.$newfilename)) {
                   1254: 		$r->log_error("Couldn't open $newfilename for output $!");
                   1255: 		return SERVER_ERROR; 
                   1256: 	    }
                   1257: 	    print $temp_file $print_array[$i];
                   1258: 	}
                   1259:     }
1.274     sakharuk 1260:     my $student_names='';
                   1261:     if ($#print_array>0) {
                   1262: 	for (my $i=0;$i<=$#print_array;$i++) {
                   1263: 	    $student_names.=$student_names[$i].'_ENDPERSON_';
                   1264: 	}
1.277     albertel 1265:     } else {
1.278     albertel 1266: 	if ($#student_names>-1) {
                   1267: 	    $student_names=$student_names[0].'_ENDPERSON_';
                   1268: 	} else {
                   1269: 	    my $fullname = &get_name($ENV{'user.name'},$ENV{'user.domain'});
                   1270: 	    $student_names=join(':',$ENV{'user.name'},$ENV{'user.domain'},
                   1271: 				$ENV{'request.course.sec'},$fullname).
                   1272: 				    '_ENDPERSON_'.'_END_';
                   1273: 	}
1.274     sakharuk 1274:     }
                   1275: 
1.276     sakharuk 1276:     my $URLback=''; #link to original document
                   1277:     if ($helper->{'VARS'}->{'construction'} ne '1') {
                   1278: 	#prints published resource
                   1279: 	$URLback=$helper->{'VARS'}->{'postdata'};
                   1280:     } else {
                   1281: 	#prints resource from the construction space
                   1282: 	$URLback='/'.$helper->{'VARS'}->{'filename'};
1.279     albertel 1283: 	if ($URLback=~/([^?]+)/) {
                   1284: 	    $URLback=$1;
                   1285: 	    $URLback=~s|^/~|/priv/|;
                   1286: 	}
1.276     sakharuk 1287:     }
1.256     sakharuk 1288: 
1.257     sakharuk 1289:     &Apache::lonnet::appenv('cgi.'.$identifier.'.file'   => $filename,
                   1290:                             'cgi.'.$identifier.'.layout'  => $laystyle,
                   1291:                             'cgi.'.$identifier.'.numcol'  => $numberofcolumns,
1.303     sakharuk 1292: 			    'cgi.'.$identifier.'.paper'  => $papersize,
1.257     sakharuk 1293:                             'cgi.'.$identifier.'.selection' => $selectionmade,
                   1294: 			    'cgi.'.$identifier.'tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'},
                   1295: 			    'cgi.'.$identifier.'tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'},
1.272     sakharuk 1296: 			    'cgi.'.$identifier.'role' => $ENV{'request.role.adv'},
1.274     sakharuk 1297:                             'cgi.'.$identifier.'numberoffiles' => $#print_array,
1.276     sakharuk 1298:                             'cgi.'.$identifier.'studentnames' => $student_names,
                   1299:                             'cgi.'.$identifier.'backref' => $URLback,);
1.256     sakharuk 1300:  
1.140     sakharuk 1301: $r->print(<<FINALEND);
1.317     albertel 1302: <br />
1.288     albertel 1303: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$identifier" />
1.317     albertel 1304: <a href="/cgi-bin/printout.pl?$identifier">Continue</a>
1.140     sakharuk 1305: </body>
                   1306: </html>
                   1307: FINALEND
                   1308: }
                   1309: 
1.288     albertel 1310: sub num_to_letters {
                   1311:     my ($num) = @_;
                   1312:     my @nums= split('',$num);
                   1313:     my @num_to_let=('A'..'Z');
                   1314:     my $word;
                   1315:     foreach my $digit (@nums) { $word.=$num_to_let[$digit]; }
                   1316:     return $word;
                   1317: }
                   1318: 
                   1319: sub get_CODE {
                   1320:     my ($all_codes,$num,$seed,$size)=@_;
                   1321:     my $max='1'.'0'x$size;
                   1322:     my $newcode;
                   1323:     while(1) {
1.293     albertel 1324: 	$newcode=sprintf("%06d",int(rand($max)));
1.288     albertel 1325: 	if (!exists($$all_codes{$newcode})) {
                   1326: 	    $$all_codes{$newcode}=1;
                   1327: 	    return &num_to_letters($newcode);
                   1328: 	}
                   1329:     }
                   1330: }
1.140     sakharuk 1331: 
1.284     albertel 1332: sub print_resources {
                   1333:     my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header)=@_;
                   1334:     my $current_output = ''; 
                   1335:     my ($username,$userdomain,$usersection) = split /:/,$person;
                   1336:     my $fullname = &get_name($username,$userdomain);
1.323     sakharuk 1337:     my $namepostfix;
1.288     albertel 1338:     if ($person =~ 'anon') {
1.323     sakharuk 1339: 	$namepostfix="\\\\Name: ";
1.288     albertel 1340: 	$fullname = "CODE - ".$moreenv->{'CODE'};
                   1341:     }
1.284     albertel 1342:     #goes through all resources, checks if they are available for 
                   1343:     #current student, and produces output   
                   1344:     &Apache::lonnet::delenv('form.counter');
                   1345:     &Apache::lonxml::init_counter();
                   1346:     foreach my $curresline (@{$master_seq})  {
                   1347: 	if ( !($type eq 'problems' && 
                   1348: 	       ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library)$/)) ) {
                   1349: 	    my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline);
                   1350: 	    if (&Apache::lonnet::allowed('bre',$res_url)) {
1.305     sakharuk 1351: 		if ($res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
                   1352: 		    my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$ENV{'request.course.id'},'tex',$moreenv);
                   1353: 		    my $lonidsdir=$r->dir_config('lonIDsDir');
                   1354: 		    my $envfile=$ENV{'user.environment'};
                   1355: 		    $envfile=~/\/([^\/]+)\.id$/;
                   1356: 		    $envfile=$1;
                   1357: 		    &Apache::lonnet::transfer_profile_to_env($lonidsdir,$envfile);
                   1358: 		    my $current_counter=$ENV{'form.counter'};
                   1359: 		    if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
                   1360: 		       ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
1.332     albertel 1361: 			$moreenv->{'answer_output_mode'}='tex';
                   1362: 			$moreenv->{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
                   1363: 			my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$ENV{'request.course.id'},%{$moreenv});
1.305     sakharuk 1364: 			&Apache::lonnet::appenv(('form.counter' => $current_counter));
                   1365: 			if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                   1366: 			    $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/;
                   1367: 			} else {
                   1368: 			    $rendered=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
                   1369: 			    $rendered.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($curresline).'}\vskip 0 mm ';
                   1370: 			    $rendered.=&path_to_problem ($curresline,$LaTeXwidth);
                   1371: 			    $rendered.='\vskip 1 mm '.$ansrendered;
                   1372: 			}
                   1373: 		    }
                   1374: 		    if ($remove_latex_header eq 'YES') {
                   1375: 			$rendered = &latex_header_footer_remove($rendered);
                   1376: 		    } else {
                   1377: 			$rendered =~ s/\\end{document}//;
                   1378: 		    }
                   1379: 		    $current_output .= $rendered;		    
                   1380: 		} elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) {
                   1381: 		    my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$ENV{'request.course.id'},'tex',$moreenv);
                   1382: 		    my $lonidsdir=$r->dir_config('lonIDsDir');
                   1383: 		    my $envfile=$ENV{'user.environment'};
                   1384: 		    $envfile=~/\/([^\/]+)\.id$/;
                   1385: 		    $envfile=$1;
                   1386: 		    &Apache::lonnet::transfer_profile_to_env($lonidsdir,$envfile);
                   1387: 		    my $current_counter=$ENV{'form.counter'};
                   1388: 		    if ($remove_latex_header eq 'YES') {
                   1389: 			$rendered = &latex_header_footer_remove($rendered);
1.284     albertel 1390: 		    } else {
1.305     sakharuk 1391: 			$rendered =~ s/\\end{document}//;
1.284     albertel 1392: 		    }
1.305     sakharuk 1393: 		    $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\strut \vskip 0 mm \strut ';
1.284     albertel 1394: 		} else {
1.307     sakharuk 1395: 		    my $rendered = &unsupported($res_url,$helper->{'VARS'}->{'LATEX_TYPE'});
1.305     sakharuk 1396: 		    if ($remove_latex_header ne 'NO') {
                   1397: 			$rendered = &latex_header_footer_remove($rendered);
                   1398: 		    } else {
                   1399: 			$rendered =~ s/\\end{document}//;
                   1400: 		    }
                   1401: 		    $current_output .= $rendered;
1.284     albertel 1402: 		}
                   1403: 	    }
                   1404: 	    $remove_latex_header = 'YES';
                   1405: 	}
1.331     albertel 1406: 	if (&Apache::loncommon::connection_aborted($r)) { last; }
1.284     albertel 1407:     }
                   1408:     my $courseidinfo = &get_course();
                   1409:     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
                   1410:     if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}
                   1411:     my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
                   1412:     if ($current_output=~/\\documentclass/) {
1.334     albertel 1413: 	$current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /;
1.284     albertel 1414:     } else {
                   1415: 	my $blankpages = '';
                   1416: 	for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blankpages.='\clearpage\strut\clearpage';}
1.334     albertel 1417: 	$current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output;
1.284     albertel 1418:     }
                   1419:     return ($current_output,$fullname);
                   1420: 
                   1421: }
1.140     sakharuk 1422: 
1.3       sakharuk 1423: sub handler {
                   1424: 
                   1425:     my $r = shift;
1.131     bowersj2 1426:     my $helper;
1.114     bowersj2 1427: 
1.150     sakharuk 1428: #    my $loaderror=&Apache::lonnet::overloaderror($r);
                   1429: #    if ($loaderror) { return $loaderror; }
                   1430: #    $loaderror=
                   1431: #       &Apache::lonnet::overloaderror($r,
                   1432: #         $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
                   1433: #    if ($loaderror) { return $loaderror; }
1.67      www      1434: 
1.177     sakharuk 1435:     my $result = printHelper($r);
                   1436:     if (!ref($result)) {
                   1437: 	return $result;
1.60      sakharuk 1438:     }
1.177     sakharuk 1439:     $helper = $result;
                   1440:    
                   1441: #	my $key; 
                   1442: #	foreach $key (keys %{$helper->{'VARS'}}) {
                   1443: #	    $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'<-<br />');
                   1444: #	}
1.264     sakharuk 1445: #	foreach $key (keys %ENV) {
                   1446: #	    $r->print(' '.$key.'->'.$ENV{$key}.'<-<br />');
                   1447: #	}
1.177     sakharuk 1448: #	return OK;
1.184     sakharuk 1449: 
                   1450:     my %parmhash=&Apache::lonnet::coursedescription($ENV{'request.course.id'});
                   1451:     
1.207     sakharuk 1452: #	my $key; 
1.200     sakharuk 1453: #	foreach $key (keys %parmhash) {
                   1454: #	    $r->print(' '.$key.'->'.$parmhash{$key}.'<-<br />');
                   1455: #	}
                   1456: #	return OK;
1.184     sakharuk 1457: 
                   1458:     &output_data($r,$helper,\%parmhash);
1.2       sakharuk 1459:     return OK;
1.60      sakharuk 1460: } 
1.2       sakharuk 1461: 
1.131     bowersj2 1462: use Apache::lonhelper;
1.130     sakharuk 1463: 
1.223     bowersj2 1464: sub addMessage {
                   1465:     my $text = shift;
                   1466:     my $paramHash = Apache::lonhelper::getParamHash();
                   1467:     $paramHash->{MESSAGE_TEXT} = $text;
                   1468:     Apache::lonhelper::message->new();
                   1469: }
                   1470: 
1.238     bowersj2 1471: use Data::Dumper;
                   1472: 
1.131     bowersj2 1473: sub printHelper {
1.115     bowersj2 1474:     my $r = shift;
                   1475: 
                   1476:     if ($r->header_only) {
1.131     bowersj2 1477:         if ($ENV{'browser.mathml'}) {
1.241     www      1478:             &Apache::loncommon::content_type($r,'text/xml');
1.131     bowersj2 1479:         } else {
1.241     www      1480:             &Apache::loncommon::content_type($r,'text/html');
1.131     bowersj2 1481:         }
                   1482:         $r->send_http_header;
                   1483:         return OK;
1.115     bowersj2 1484:     }
                   1485: 
1.131     bowersj2 1486:     # Send header, nocache
1.115     bowersj2 1487:     if ($ENV{'browser.mathml'}) {
1.241     www      1488:         &Apache::loncommon::content_type($r,'text/xml');
1.115     bowersj2 1489:     } else {
1.241     www      1490:         &Apache::loncommon::content_type($r,'text/html');
1.115     bowersj2 1491:     }
                   1492:     &Apache::loncommon::no_cache($r);
                   1493:     $r->send_http_header;
                   1494:     $r->rflush();
                   1495: 
1.131     bowersj2 1496:     # Unfortunately, this helper is so complicated we have to
                   1497:     # write it by hand
                   1498: 
                   1499:     Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
                   1500:     
1.176     bowersj2 1501:     my $helper = Apache::lonhelper::helper->new("Printing Helper");
1.146     bowersj2 1502:     $helper->declareVar('symb');
1.156     bowersj2 1503:     $helper->declareVar('postdata');    
1.290     sakharuk 1504:     $helper->declareVar('curseed'); 
                   1505:     $helper->declareVar('probstatus');   
1.156     bowersj2 1506:     $helper->declareVar('filename');
                   1507:     $helper->declareVar('construction');
1.178     sakharuk 1508:     $helper->declareVar('assignment');
1.262     sakharuk 1509:     $helper->declareVar('style_file');
1.131     bowersj2 1510:     
                   1511:     # This will persistently load in the data we want from the
                   1512:     # very first screen.
1.156     bowersj2 1513:     # Detect whether we're coming from construction space
1.208     www      1514:     if ($ENV{'form.postdata'}=~/^(?:http:\/\/[^\/]+\/|\/|)\~([^\/]+)\/(.*)$/) {
1.235     bowersj2 1515:         $helper->{VARS}->{'filename'} = "~$1/$2";
1.156     bowersj2 1516:         $helper->{VARS}->{'construction'} = 1;
                   1517:     } else {
                   1518:         if ($ENV{'form.postdata'}) {
                   1519:             $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($ENV{'form.postdata'});
                   1520:         }
                   1521:         if ($ENV{'form.symb'}) {
                   1522:             $helper->{VARS}->{'symb'} = $ENV{'form.symb'};
                   1523:         }
                   1524:         if ($ENV{'form.url'}) {
                   1525:             $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
                   1526:         }
1.157     bowersj2 1527:     }
1.156     bowersj2 1528: 
1.146     bowersj2 1529:     if ($ENV{'form.symb'}) {
                   1530:         $helper->{VARS}->{'symb'} = $ENV{'form.symb'};
                   1531:     }
                   1532:     if ($ENV{'form.url'}) {
1.140     sakharuk 1533:         $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
1.153     sakharuk 1534: 
1.140     sakharuk 1535:     }
1.146     bowersj2 1536:     
1.335     albertel 1537:     my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu($helper);
1.178     sakharuk 1538:     if ($sequenceTitle ne '') {$helper->{VARS}->{'assignment'}=$sequenceTitle;}
1.140     sakharuk 1539: 
1.156     bowersj2 1540:     
1.146     bowersj2 1541:     # Extract map
                   1542:     my $symb = $helper->{VARS}->{'symb'};
1.156     bowersj2 1543:     my ($map, $id, $url);
                   1544:     my $subdir;
                   1545: 
                   1546:     # Get the resource name from construction space
                   1547:     if ($helper->{VARS}->{'construction'}) {
                   1548:         $resourceTitle = substr($helper->{VARS}->{'filename'}, 
                   1549:                                 rindex($helper->{VARS}->{'filename'}, '/')+1);
                   1550:         $subdir = substr($helper->{VARS}->{'filename'},
                   1551:                          0, rindex($helper->{VARS}->{'filename'}, '/') + 1);
                   1552:     } else {
1.233     www      1553:         ($map, $id, $url) = &Apache::lonnet::decode_symb($symb);
1.156     bowersj2 1554:         $helper->{VARS}->{'postdata'} = Apache::lonnet::clutter($url);
1.146     bowersj2 1555: 
1.156     bowersj2 1556:         if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
1.238     bowersj2 1557:             my $postdata = $helper->{VARS}->{'postdata'};
                   1558:             $resourceTitle = substr($postdata, rindex($postdata, '/') + 1);
1.156     bowersj2 1559:         }
                   1560:         $subdir = &Apache::lonnet::filelocation("", $url);
1.128     bowersj2 1561:     }
1.230     albertel 1562:     if (!$helper->{VARS}->{'curseed'} && $ENV{'form.curseed'}) {
                   1563: 	$helper->{VARS}->{'curseed'}=$ENV{'form.curseed'};
                   1564:     }
1.290     sakharuk 1565:     if (!$helper->{VARS}->{'probstatus'} && $ENV{'form.problemtype'}) {
                   1566: 	$helper->{VARS}->{'probstatus'}=$ENV{'form.problemtype'};
                   1567:     }
1.115     bowersj2 1568: 
1.192     bowersj2 1569:     my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
1.235     bowersj2 1570:     my $userPriviledged = ($ENV{'request.role'}=~m/^cc\./ or
                   1571: 			   $ENV{'request.role'}=~m/^in\./ or
                   1572: 			   $ENV{'request.role'}=~m/^ta\./);
1.192     bowersj2 1573: 
1.131     bowersj2 1574:     Apache::lonhelper::registerHelperTags();
1.119     bowersj2 1575: 
1.131     bowersj2 1576:     # "Delete everything after the last slash."
1.119     bowersj2 1577:     $subdir =~ s|/[^/]+$||;
1.162     sakharuk 1578:     if (not $helper->{VARS}->{'construction'}) {
1.302     sakharuk 1579: 	$subdir=$Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$subdir;
1.153     sakharuk 1580:     }
1.189     bowersj2 1581:     # "Remove all duplicate slashes."
                   1582:     $subdir =~ s|/+|/|g;
1.119     bowersj2 1583: 
1.131     bowersj2 1584:     # What can be printed is a very dynamic decision based on
                   1585:     # lots of factors. So we need to dynamically build this list.
                   1586:     # To prevent security leaks, states are only added to the wizard
                   1587:     # if they can be reached, which ensures manipulating the form input
                   1588:     # won't allow anyone to reach states they shouldn't have permission
                   1589:     # to reach.
                   1590: 
                   1591:     # printChoices is tracking the kind of printing the user can
                   1592:     # do, and will be used in a choices construction later.
                   1593:     # In the meantime we will be adding states and elements to
                   1594:     # the helper by hand.
                   1595:     my $printChoices = [];
                   1596:     my $paramHash;
1.130     sakharuk 1597: 
1.240     albertel 1598:     if ($resourceTitle) {
1.291     sakharuk 1599:         push @{$printChoices}, ["<b><i>$resourceTitle</i></b> (".&mt('what you just saw on the screen').")", 'current_document', 'PAGESIZE'];
1.156     bowersj2 1600:     }
                   1601: 
1.238     bowersj2 1602:     # Useful filter strings
1.287     albertel 1603:     my $isProblem = '($res->is_problem()||$res->contains_problem) ';
1.238     bowersj2 1604:     $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
1.287     albertel 1605:     my $isProblemOrMap = '$res->is_problem() || $res->contains_problem() || $res->is_sequence()';
                   1606:     my $isNotMap = '!$res->is_sequence()';
1.238     bowersj2 1607:     $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
                   1608:     my $isMap = '$res->is_map()';
                   1609:     my $symbFilter = '$res->symb()';
                   1610:     my $urlValue = '$res->src()';
                   1611: 
                   1612:     $helper->declareVar('SEQUENCE');
                   1613: 
                   1614:     # Useful for debugging: Dump the help vars
                   1615:     #$r->print(Dumper($helper->{VARS}));
                   1616:     #$r->print($map);
                   1617: 
1.131     bowersj2 1618:     # If we're in a sequence...
1.235     bowersj2 1619:     if (($helper->{'VARS'}->{'construction'} ne '1') &&
1.243     bowersj2 1620: 	$helper->{VARS}->{'postdata'} &&
                   1621: 	$helper->{VARS}->{'assignment'}) {
1.131     bowersj2 1622:         # Allow problems from sequence
1.291     sakharuk 1623:         push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('in')." <b><i>$sequenceTitle</i></b>", 'map_problems', 'CHOOSE_PROBLEMS'];
1.131     bowersj2 1624:         # Allow all resources from sequence
1.291     sakharuk 1625:         push @{$printChoices}, ["<b>".&mt('Resources')."</b> ".&mt('in')." <b><i>$sequenceTitle</i></b>", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
1.130     sakharuk 1626: 
1.131     bowersj2 1627:         my $helperFragment = <<HELPERFRAGMENT;
1.155     sakharuk 1628:   <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">
                   1629:     <message>(mark them then click "next" button) <br /></message>
1.287     albertel 1630:     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
                   1631:               closeallpages="1">
1.144     bowersj2 1632:       <nextstate>PAGESIZE</nextstate>
1.192     bowersj2 1633:       <filterfunc>return $isProblem;</filterfunc>
1.131     bowersj2 1634:       <mapurl>$map</mapurl>
1.238     bowersj2 1635:       <valuefunc>return $symbFilter;</valuefunc>
1.131     bowersj2 1636:       </resource>
                   1637:     </state>
                   1638: 
1.155     sakharuk 1639:   <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">
                   1640:     <message>(mark them then click "next" button) <br /></message>
1.287     albertel 1641:     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
                   1642:               closeallpages="1">
1.144     bowersj2 1643:       <nextstate>PAGESIZE</nextstate>
1.145     bowersj2 1644:       <filterfunc>return $isNotMap;</filterfunc>
1.131     bowersj2 1645:       <mapurl>$map</mapurl>
1.238     bowersj2 1646:       <valuefunc>return $symbFilter;</valuefunc>
1.131     bowersj2 1647:       </resource>
                   1648:     </state>
                   1649: HELPERFRAGMENT
1.121     bowersj2 1650: 
1.326     sakharuk 1651: 	&Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
1.121     bowersj2 1652:     }
                   1653: 
                   1654:     # If the user is priviledged, allow them to print all 
                   1655:     # problems in the course, optionally for selected students
1.306     sakharuk 1656:     if ($userPriviledged && 
                   1657:         ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) { 
1.254     sakharuk 1658:         push @{$printChoices}, ['<b>Problems</b> from <b>entire course</b>', 'all_problems', 'ALL_PROBLEMS'];
1.284     albertel 1659:          &Apache::lonxml::xmlparse($r, 'helper', <<ALL_PROBLEMS);
1.155     sakharuk 1660:   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
                   1661:     <message>(mark them then click "next" button) <br /></message>
1.287     albertel 1662:     <resource variable="RESOURCES" toponly='0' multichoice="1"
                   1663: 	suppressEmptySequences='0' addstatus="1" closeallpages="1">
1.144     bowersj2 1664:       <nextstate>PAGESIZE</nextstate>
1.192     bowersj2 1665:       <filterfunc>return $isProblemOrMap;</filterfunc>
1.287     albertel 1666:       <choicefunc>return $isNotMap;</choicefunc>
1.238     bowersj2 1667:       <valuefunc>return $symbFilter;</valuefunc>
1.284     albertel 1668:     </resource>
                   1669:   </state>
                   1670: ALL_PROBLEMS
1.132     bowersj2 1671: 
1.284     albertel 1672: 	if ($helper->{VARS}->{'assignment'}) {
1.291     sakharuk 1673: 	    push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('from')." <b><i>$sequenceTitle</i></b> ".&mt('for')." <b>".&mt('selected students')."</b>", 'problems_for_students', 'CHOOSE_STUDENTS'];
                   1674: 	    push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('from')." <b><i>$sequenceTitle</i></b> ".&mt('for')." <b>".&mt('anonymous students')."</b>", 'problems_for_anon', 'CHOOSE_ANON1'];
1.284     albertel 1675: 	}
                   1676: 	my $resource_selector=<<RESOURCE_SELECTOR;
                   1677:    <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
1.287     albertel 1678:     <resource variable="RESOURCES" multichoice="1" addstatus="1" 
                   1679:               closeallpages="1">
1.254     sakharuk 1680:       <filterfunc>return $isProblem;</filterfunc>
1.148     bowersj2 1681:       <mapurl>$map</mapurl>
1.254     sakharuk 1682:       <valuefunc>return $symbFilter;</valuefunc>
1.147     bowersj2 1683:       </resource>
1.155     sakharuk 1684:     <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
1.149     bowersj2 1685:     <choices variable="EMPTY_PAGES">
1.204     sakharuk 1686:       <choice computer='0'>Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)</choice>
                   1687:       <choice computer='1'>Add one empty page/column after each student\'s assignment</choice>
                   1688:       <choice computer='2'>Add two empty pages/column after each student\'s assignment</choice>
                   1689:       <choice computer='3'>Add three empty pages/column after each student\'s assignment</choice>
1.284     albertel 1690:     </choices>
                   1691:     <message><hr width='33%' /><b>Number of assignments printed at the same time: </b></message>
                   1692:     <string variable="NUMBER_TO_PRINT" maxlength="5" size="5"><defaultvalue>"all"</defaultvalue></string>
                   1693: RESOURCE_SELECTOR
                   1694: 
                   1695:         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
                   1696:   <state name="CHOOSE_STUDENTS" title="Select Students and Resources">
                   1697:       <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
                   1698:     $resource_selector
                   1699:   </state>
1.131     bowersj2 1700: CHOOSE_STUDENTS
1.292     albertel 1701: 
                   1702: 	my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
                   1703: 	my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
                   1704:         my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
                   1705: 	my $namechoice='<choice></choice>';
1.337   ! albertel 1706: 	foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.294     albertel 1707: 	    if ($name =~ /^error: 2 /) { next; }
1.292     albertel 1708: 	    $namechoice.='<choice computer="'.$name.'">'.$name.'</choice>';
                   1709: 	}
1.284     albertel 1710:         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);
                   1711:   <state name="CHOOSE_ANON1" title="Select Students and Resources">
1.288     albertel 1712:     <nextstate>PAGESIZE</nextstate>
1.287     albertel 1713:     <message><hr width='33%' /><b>Number of anonymous assignments to print?</b></message>
1.284     albertel 1714:     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>
1.292     albertel 1715:     <message><br /><b>Names to store the CODEs under for later:</b></message>
1.288     albertel 1716:     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
1.292     albertel 1717:     <message><hr width='33%' /></message>
                   1718:     <message><b>Reprint a set of saved CODEs:</b></message>
                   1719:     <dropdown variable="REUSE_OLD_CODES">
                   1720:         $namechoice
                   1721:     </dropdown>
1.284     albertel 1722:     <message><hr width='33%' /></message>
                   1723:     $resource_selector
                   1724:   </state>
                   1725: CHOOSE_ANON1
1.254     sakharuk 1726: 
1.272     sakharuk 1727: 
1.254     sakharuk 1728: 	if ($helper->{VARS}->{'assignment'}) {
1.291     sakharuk 1729: 	    push @{$printChoices}, ["<b>".&mt('Resources')."</b> ".&mt('from')." <b><i>$sequenceTitle</i></b> ".&mt('for')." <b>".&mt('selected students')."</b>", 'resources_for_students', 'CHOOSE_STUDENTS1'];
                   1730: 	    push @{$printChoices}, ["<b>".&mt('Resources')."</b> ".&mt('from')." <b><i>$sequenceTitle</i></b> ".&mt('for')." <b>".&mt('anonymous students')."</b>", 'resources_for_anon', 'CHOOSE_ANON2'];
1.254     sakharuk 1731: 	}
1.284     albertel 1732: 	    
                   1733: 
                   1734: 	$resource_selector=<<RESOURCE_SELECTOR;
1.254     sakharuk 1735:     <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
1.287     albertel 1736:     <resource variable="RESOURCES" multichoice="1" addstatus="1" 
                   1737:               closeallpages="1">
1.254     sakharuk 1738:       <filterfunc>return $isNotMap;</filterfunc>
                   1739:       <mapurl>$map</mapurl>
                   1740:       <valuefunc>return $symbFilter;</valuefunc>
                   1741:       </resource>
                   1742:     <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
                   1743:     <choices variable="EMPTY_PAGES">
                   1744:       <choice computer='0'>Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)</choice>
                   1745:       <choice computer='1'>Add one empty page/column after each student\'s assignment</choice>
                   1746:       <choice computer='2'>Add two empty pages/column after each student\'s assignment</choice>
                   1747:       <choice computer='3'>Add three empty pages/column after each student\'s assignment</choice>
1.284     albertel 1748:     </choices>
                   1749:     <message><hr width='33%' /><b>Number of assignments printed at the same time: </b></message>
                   1750:     <string variable="NUMBER_TO_PRINT" maxlength="5" size="5"><defaultvalue>"all"</defaultvalue></string>
                   1751: RESOURCE_SELECTOR
                   1752: 
                   1753: 	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS1);
                   1754:   <state name="CHOOSE_STUDENTS1" title="Select Students and Resources">
                   1755:     <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
                   1756:     $resource_selector
1.254     sakharuk 1757:     </state>
                   1758: CHOOSE_STUDENTS1
                   1759: 
1.284     albertel 1760: 	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON2);
                   1761:   <state name="CHOOSE_ANON2" title="Select Students and Resources">
1.294     albertel 1762:     <nextstate>PAGESIZE</nextstate>
                   1763:     <message><hr width='33%' /><b>Number of anonymous assignments to print?</b></message>
1.284     albertel 1764:     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>
1.294     albertel 1765:     <message><br /><b>Names to store the CODEs under for later:</b></message>
                   1766:     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
                   1767:     <message><hr width='33%' /></message>
                   1768:     <message><b>Reprint a set of saved CODEs:</b></message>
                   1769:     <dropdown variable="REUSE_OLD_CODES">
                   1770:         $namechoice
                   1771:     </dropdown>
1.284     albertel 1772:     <message><hr width='33%' /></message>
                   1773:     $resource_selector
                   1774:   </state>
                   1775: CHOOSE_ANON2
1.121     bowersj2 1776:     }
                   1777: 
                   1778:     # FIXME: That RE should come from a library somewhere.
1.302     sakharuk 1779:     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'}) and $ENV{'request.role.adv'} and $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/') {    
1.291     sakharuk 1780:         push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('from current subdirectory')." <b><i>$subdir</i></b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
1.238     bowersj2 1781: 
1.131     bowersj2 1782:         my $f = '$filename';
1.139     bowersj2 1783:         my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
1.155     sakharuk 1784:   <state name="CHOOSE_FROM_SUBDIR" title="Select File(s) from <b><small>$subdir</small></b> to print">
                   1785:     <message>(mark them then click "next" button) <br /></message>
1.138     bowersj2 1786:     <files variable="FILES" multichoice='1'>
1.144     bowersj2 1787:       <nextstate>PAGESIZE</nextstate>
1.138     bowersj2 1788:       <filechoice>return '$subdir';</filechoice>
1.139     bowersj2 1789: CHOOSE_FROM_SUBDIR
                   1790:         
1.238     bowersj2 1791:         # this is broken up because I really want interpolation above,
                   1792:         # and I really DON'T want it below
1.139     bowersj2 1793:         $xmlfrag .= <<'CHOOSE_FROM_SUBDIR';
1.225     bowersj2 1794:       <filefilter>return Apache::lonhelper::files::not_old_version($filename) &&
                   1795: 	  $filename =~ m/\.(problem|exam|quiz|assess|survey|form|library)$/;
1.131     bowersj2 1796:       </filefilter>
1.138     bowersj2 1797:       </files>
1.131     bowersj2 1798:     </state>
                   1799: CHOOSE_FROM_SUBDIR
1.139     bowersj2 1800:         &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.131     bowersj2 1801:     }
1.238     bowersj2 1802: 
                   1803:     # Allow the user to select any sequence in the course, feed it to
                   1804:     # another resource selector for that sequence
1.239     bowersj2 1805:     if (!$helper->{VARS}->{'construction'}) {
1.254     sakharuk 1806: 	push @$printChoices, ["<b>Resources</b> from <b>selected sequence</b> in course",
1.249     sakharuk 1807: 			      'select_sequences', 'CHOOSE_SEQUENCE'];
1.244     bowersj2 1808: 	my $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'};
                   1809: 	#Escape apostrophes and backslashes for Perl
                   1810: 	$escapedSequenceName =~ s/\\/\\\\/g;
                   1811: 	$escapedSequenceName =~ s/'/\\'/g;
1.239     bowersj2 1812: 	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_FROM_ANY_SEQUENCE);
1.238     bowersj2 1813:   <state name="CHOOSE_SEQUENCE" title="Select Sequence To Print From">
                   1814:     <message>Select the sequence to print resources from:</message>
                   1815:     <resource variable="SEQUENCE">
                   1816:       <nextstate>CHOOSE_FROM_ANY_SEQUENCE</nextstate>
                   1817:       <filterfunc>return \$res->is_sequence;</filterfunc>
                   1818:       <valuefunc>return $urlValue;</valuefunc>
                   1819:       </resource>
                   1820:     </state>
                   1821:   <state name="CHOOSE_FROM_ANY_SEQUENCE" title="Select Resources To Print">
                   1822:     <message>(mark desired resources then click "next" button) <br /></message>
1.287     albertel 1823:     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
                   1824:               closeallpages="1">
1.238     bowersj2 1825:       <nextstate>PAGESIZE</nextstate>
                   1826:       <filterfunc>return $isProblem</filterfunc>
1.244     bowersj2 1827:       <mapurl evaluate='1'>return '$escapedSequenceName';</mapurl>
1.238     bowersj2 1828:       <valuefunc>return $symbFilter;</valuefunc>
                   1829:       </resource>
                   1830:     </state>
                   1831: CHOOSE_FROM_ANY_SEQUENCE
1.239     bowersj2 1832: }
1.131     bowersj2 1833: 
                   1834:     # Generate the first state, to select which resources get printed.
1.223     bowersj2 1835:     Apache::lonhelper::state->new("START", "Select Printing Options:");
1.131     bowersj2 1836:     $paramHash = Apache::lonhelper::getParamHash();
1.155     sakharuk 1837:     $paramHash->{MESSAGE_TEXT} = "";
1.131     bowersj2 1838:     Apache::lonhelper::message->new();
                   1839:     $paramHash = Apache::lonhelper::getParamHash();
                   1840:     $paramHash->{'variable'} = 'PRINT_TYPE';
1.137     bowersj2 1841:     $helper->declareVar('PRINT_TYPE');
1.131     bowersj2 1842:     $paramHash->{CHOICES} = $printChoices;
                   1843:     Apache::lonhelper::choices->new();
1.161     bowersj2 1844: 
1.223     bowersj2 1845:     my $startedTable = 0; # have we started an HTML table yet? (need
                   1846:                           # to close it later)
                   1847: 
1.170     sakharuk 1848:     if (($ENV{'request.role.adv'} and &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) or 
                   1849: 	($helper->{VARS}->{'construction'} eq '1')) {
1.242     sakharuk 1850: 	addMessage("<hr width='33%' /><table><tr><td align='right'>Print: </td><td>");
1.161     bowersj2 1851:         $paramHash = Apache::lonhelper::getParamHash();
1.162     sakharuk 1852: 	$paramHash->{'variable'} = 'ANSWER_TYPE';   
                   1853: 	$helper->declareVar('ANSWER_TYPE');         
1.161     bowersj2 1854:         $paramHash->{CHOICES} = [
1.242     sakharuk 1855:                                    ['Without Answers', 'yes'],
                   1856:                                    ['With Answers', 'no'],
1.289     sakharuk 1857:                                    ['Only Answers', 'only'],
                   1858:                                    ['As Exam Problem', 'exam']
                   1859:                                 ];
1.210     sakharuk 1860:         Apache::lonhelper::dropdown->new();
1.223     bowersj2 1861: 	addMessage("</td></tr>");
                   1862: 	$startedTable = 1;
1.161     bowersj2 1863:     }
1.209     sakharuk 1864: 
1.203     sakharuk 1865:     if ($ENV{'request.role.adv'}) {
1.223     bowersj2 1866: 	if (!$startedTable) {
                   1867: 	    addMessage("<hr width='33%' /><table><tr><td align='right'>LaTeX mode: </td><td>");
                   1868: 	    $startedTable = 1;
                   1869: 	} else {
                   1870: 	    addMessage("<tr><td align='right'>LaTeX mode: </td><td>");
                   1871: 	}
1.203     sakharuk 1872:         $paramHash = Apache::lonhelper::getParamHash();
                   1873: 	$paramHash->{'variable'} = 'LATEX_TYPE';   
                   1874: 	$helper->declareVar('LATEX_TYPE');  
                   1875: 	if ($helper->{VARS}->{'construction'} eq '1') {       
                   1876: 	    $paramHash->{CHOICES} = [
1.223     bowersj2 1877: 				     ['standard LaTeX mode', 'standard'], 
                   1878: 				     ['LaTeX batchmode', 'batchmode'], ];
1.203     sakharuk 1879: 	} else {
                   1880: 	    $paramHash->{CHOICES} = [
1.223     bowersj2 1881: 				     ['LaTeX batchmode', 'batchmode'],
                   1882: 				     ['standard LaTeX mode', 'standard'] ];
1.203     sakharuk 1883: 	}
1.210     sakharuk 1884:         Apache::lonhelper::dropdown->new();
1.218     sakharuk 1885:  
1.223     bowersj2 1886: 	addMessage("</td></tr><tr><td align='right'>Print Table of Contents: </td><td>");
1.209     sakharuk 1887:         $paramHash = Apache::lonhelper::getParamHash();
                   1888: 	$paramHash->{'variable'} = 'TABLE_CONTENTS';   
                   1889: 	$helper->declareVar('TABLE_CONTENTS');         
                   1890:         $paramHash->{CHOICES} = [
1.223     bowersj2 1891:                                    ['No', 'no'],
                   1892:                                    ['Yes', 'yes'] ];
1.210     sakharuk 1893:         Apache::lonhelper::dropdown->new();
1.223     bowersj2 1894: 	addMessage("</td></tr>");
1.214     sakharuk 1895:         
1.220     sakharuk 1896: 	if (not $helper->{VARS}->{'construction'}) {
1.223     bowersj2 1897: 	    addMessage("<tr><td align='right'>Print Index: </td><td>");
1.220     sakharuk 1898: 	    $paramHash = Apache::lonhelper::getParamHash();
                   1899: 	    $paramHash->{'variable'} = 'TABLE_INDEX';   
                   1900: 	    $helper->declareVar('TABLE_INDEX');         
                   1901: 	    $paramHash->{CHOICES} = [
1.223     bowersj2 1902: 				     ['No', 'no'],
                   1903: 				     ['Yes', 'yes'] ];
1.220     sakharuk 1904: 	    Apache::lonhelper::dropdown->new();
1.223     bowersj2 1905: 	    addMessage("</td></tr>");
1.309     sakharuk 1906: 	    addMessage("<tr><td align='right'>Print Discussions: </td><td>");
                   1907: 	    $paramHash = Apache::lonhelper::getParamHash();
                   1908: 	    $paramHash->{'variable'} = 'PRINT_DISCUSSIONS';   
                   1909: 	    $helper->declareVar('PRINT_DISCUSSIONS');         
                   1910: 	    $paramHash->{CHOICES} = [
                   1911: 				     ['No', 'no'],
                   1912: 				     ['Yes', 'yes'] ];
                   1913: 	    Apache::lonhelper::dropdown->new();
                   1914: 	    addMessage("</td></tr>");
1.220     sakharuk 1915: 	}
1.219     sakharuk 1916: 
1.230     albertel 1917: 	if ($helper->{'VARS'}->{'construction'}) { 
1.265     sakharuk 1918: 	    my $stylevalue=$ENV{'construct.style'};
                   1919: 	    my $xmlfrag .= <<"RNDSEED";
1.290     sakharuk 1920: 	    <message><tr><td align='right'>Use random seed:  </td><td></message>
1.230     albertel 1921: 	    <string variable="curseed" size="15" maxlength="15">
                   1922: 		<defaultvalue>
                   1923: 	            return $helper->{VARS}->{'curseed'};
                   1924: 	        </defaultvalue>
1.262     sakharuk 1925: 	    </string>
1.264     sakharuk 1926: 	     <message></td></tr><tr><td align="right">Use style file:</td><td></message>
1.265     sakharuk 1927:              <message><input type="text" size="40" name="style_file_value" value="$stylevalue"  />&nbsp; <a href="javascript:openbrowser('helpform','style_file','sty')">Select style file</a> </td><td></message>
1.230     albertel 1928:              <message></td></tr></message>
                   1929: RNDSEED
                   1930:             &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.264     sakharuk 1931: 	    $helper->{'VARS'}->{'style_file'}=$ENV{'form.style_file_value'};
1.219     sakharuk 1932: 	}
1.223     bowersj2 1933:     }
1.264     sakharuk 1934: 
                   1935: 
                   1936: 
1.218     sakharuk 1937: 
1.223     bowersj2 1938:     if ($startedTable) {
                   1939: 	addMessage("</table>");
1.215     sakharuk 1940:     }
1.161     bowersj2 1941: 
1.131     bowersj2 1942:     Apache::lonprintout::page_format_state->new("FORMAT");
                   1943: 
1.144     bowersj2 1944:     # Generate the PAGESIZE state which will offer the user the margin
                   1945:     # choices if they select one column
                   1946:     Apache::lonhelper::state->new("PAGESIZE", "Set Margins");
                   1947:     Apache::lonprintout::page_size_state->new('pagesize', 'FORMAT', 'FINAL');
                   1948: 
                   1949: 
1.131     bowersj2 1950:     $helper->process();
                   1951: 
                   1952:     # MANUAL BAILOUT CONDITION:
                   1953:     # If we're in the "final" state, bailout and return to handler
                   1954:     if ($helper->{STATE} eq 'FINAL') {
                   1955:         return $helper;
                   1956:     }    
1.130     sakharuk 1957: 
1.131     bowersj2 1958:     $r->print($helper->display());
1.130     sakharuk 1959: 
1.333     albertel 1960:     &Apache::lonhelper::unregisterHelperTags();
1.115     bowersj2 1961: 
                   1962:     return OK;
                   1963: }
                   1964: 
1.1       www      1965: 
                   1966: 1;
1.119     bowersj2 1967: 
                   1968: package Apache::lonprintout::page_format_state;
                   1969: 
                   1970: =pod
                   1971: 
1.131     bowersj2 1972: =head1 Helper element: page_format_state
                   1973: 
                   1974: See lonhelper.pm documentation for discussion of the helper framework.
1.119     bowersj2 1975: 
1.131     bowersj2 1976: Apache::lonprintout::page_format_state is an element that gives the 
                   1977: user an opportunity to select the page layout they wish to print 
                   1978: with: Number of columns, portrait/landscape, and paper size. If you 
                   1979: want to change the paper size choices, change the @paperSize array 
                   1980: contents in this package.
1.119     bowersj2 1981: 
1.131     bowersj2 1982: page_format_state is always directly invoked in lonprintout.pm, so there
                   1983: is no tag interface. You actually pass parameters to the constructor.
1.119     bowersj2 1984: 
                   1985: =over 4
                   1986: 
1.131     bowersj2 1987: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
1.119     bowersj2 1988: 
                   1989: =back
                   1990: 
                   1991: =cut
                   1992: 
1.131     bowersj2 1993: use Apache::lonhelper;
1.119     bowersj2 1994: 
                   1995: no strict;
1.131     bowersj2 1996: @ISA = ("Apache::lonhelper::element");
1.119     bowersj2 1997: use strict;
1.266     sakharuk 1998: use Apache::lonlocal;
1.119     bowersj2 1999: 
                   2000: my $maxColumns = 2;
1.326     sakharuk 2001: my @paperSize = ("letter [8 1/2x11 in]", "legal [8 1/2x14 in]", 
1.327     albertel 2002:                  "tabloid (ledger) [11x17 in]", "executive [7 1/2x10 in]",
1.326     sakharuk 2003:                  "a2 [420x594 mm]", "a3 [297x420 mm]", "a4 [210x297 mm]", 
                   2004:                  "a5 [148x210 mm]", "a6 [105x148 mm]" );
1.119     bowersj2 2005: 
                   2006: # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum |
                   2007: #                   Paper type
                   2008: 
                   2009: sub new { 
1.131     bowersj2 2010:     my $self = Apache::lonhelper::element->new();
1.119     bowersj2 2011: 
1.135     bowersj2 2012:     shift;
                   2013: 
1.131     bowersj2 2014:     $self->{'variable'} = shift;
1.134     bowersj2 2015:     my $helper = Apache::lonhelper::getHelper();
1.135     bowersj2 2016:     $helper->declareVar($self->{'variable'});
1.131     bowersj2 2017:     bless($self);
1.119     bowersj2 2018:     return $self;
                   2019: }
                   2020: 
                   2021: sub render {
                   2022:     my $self = shift;
1.131     bowersj2 2023:     my $helper = Apache::lonhelper::getHelper();
1.119     bowersj2 2024:     my $result = '';
1.131     bowersj2 2025:     my $var = $self->{'variable'};
1.266     sakharuk 2026:     my $PageLayout=&mt('Page layout');
                   2027:     my $NumberOfColumns=&mt('Number of columns');
                   2028:     my $PaperType=&mt('Paper type');
1.119     bowersj2 2029:     $result .= <<STATEHTML;
                   2030: 
1.223     bowersj2 2031: <hr width="33%" />
1.119     bowersj2 2032: <table cellpadding="3">
                   2033:   <tr>
1.266     sakharuk 2034:     <td align="center"><b>$PageLayout</b></td>
                   2035:     <td align="center"><b>$NumberOfColumns</b></td>
                   2036:     <td align="center"><b>$PaperType</b></td>
1.119     bowersj2 2037:   </tr>
                   2038:   <tr>
                   2039:     <td>
1.155     sakharuk 2040:       <input type="radio" name="${var}.layout" value="L" /> Landscape<br />
                   2041:       <input type="radio" name="${var}.layout" value="P" checked='1'  /> Portrait
1.119     bowersj2 2042:     </td>
1.155     sakharuk 2043:     <td align="center">
1.119     bowersj2 2044:       <select name="${var}.cols">
                   2045: STATEHTML
                   2046: 
                   2047:     my $i;
                   2048:     for ($i = 1; $i <= $maxColumns; $i++) {
1.144     bowersj2 2049:         if ($i == 2) {
1.119     bowersj2 2050:             $result .= "<option value='$i' selected>$i</option>\n";
                   2051:         } else {
                   2052:             $result .= "<option value='$i'>$i</option>\n";
                   2053:         }
                   2054:     }
                   2055: 
                   2056:     $result .= "</select></td><td>\n";
                   2057:     $result .= "<select name='${var}.paper'>\n";
                   2058: 
1.304     sakharuk 2059:     my %parmhash=&Apache::lonnet::coursedescription($ENV{'request.course.id'});
                   2060:     my $DefaultPaperSize=$parmhash{'default_paper_size'};
                   2061:     if ($DefaultPaperSize eq '') {$DefaultPaperSize='letter';}
1.119     bowersj2 2062:     $i = 0;
                   2063:     foreach (@paperSize) {
1.326     sakharuk 2064: 	$_=~/(\w+)/;
                   2065: 	my $papersize=$1;
1.304     sakharuk 2066:         if ($paperSize[$i]=~/$DefaultPaperSize/) {
1.326     sakharuk 2067:             $result .= "<option selected value='$papersize'>" . $paperSize[$i] . "</option>\n";
1.119     bowersj2 2068:         } else {
1.326     sakharuk 2069:             $result .= "<option value='$papersize'>" . $paperSize[$i] . "</option>\n";
1.119     bowersj2 2070:         }
                   2071:         $i++;
                   2072:     }
                   2073:     $result .= "</select></td></tr></table>";
                   2074:     return $result;
1.135     bowersj2 2075: }
                   2076: 
                   2077: sub postprocess {
                   2078:     my $self = shift;
                   2079: 
                   2080:     my $var = $self->{'variable'};
1.136     bowersj2 2081:     my $helper = Apache::lonhelper->getHelper();
1.135     bowersj2 2082:     $helper->{VARS}->{$var} = 
1.136     bowersj2 2083:         $ENV{"form.$var.layout"} . '|' . $ENV{"form.$var.cols"} . '|' .
                   2084:         $ENV{"form.$var.paper"};
1.135     bowersj2 2085:     return 1;
1.119     bowersj2 2086: }
                   2087: 
                   2088: 1;
1.144     bowersj2 2089: 
                   2090: package Apache::lonprintout::page_size_state;
                   2091: 
                   2092: =pod
                   2093: 
                   2094: =head1 Helper element: page_size_state
                   2095: 
                   2096: See lonhelper.pm documentation for discussion of the helper framework.
                   2097: 
                   2098: Apache::lonprintout::page_size_state is an element that gives the 
                   2099: user the opportunity to further refine the page settings if they
                   2100: select a single-column page.
                   2101: 
                   2102: page_size_state is always directly invoked in lonprintout.pm, so there
                   2103: is no tag interface. You actually pass parameters to the constructor.
                   2104: 
                   2105: =over 4
                   2106: 
                   2107: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
                   2108: 
                   2109: =back
                   2110: 
                   2111: =cut
                   2112: 
                   2113: use Apache::lonhelper;
                   2114: 
                   2115: no strict;
                   2116: @ISA = ("Apache::lonhelper::element");
                   2117: use strict;
                   2118: 
                   2119: 
                   2120: 
                   2121: sub new { 
                   2122:     my $self = Apache::lonhelper::element->new();
                   2123: 
                   2124:     shift; # disturbs me (probably prevents subclassing) but works (drops
                   2125:            # package descriptor)... - Jeremy
                   2126: 
                   2127:     $self->{'variable'} = shift;
                   2128:     my $helper = Apache::lonhelper::getHelper();
                   2129:     $helper->declareVar($self->{'variable'});
                   2130: 
                   2131:     # The variable name of the format element, so we can look into 
                   2132:     # $helper->{VARS} to figure out whether the columns are one or two
                   2133:     $self->{'formatvar'} = shift;
                   2134: 
                   2135:     # The state to transition to after selection, or after discovering
                   2136:     # the cols are not set to 1
                   2137:     $self->{NEXTSTATE} = shift;
                   2138:     bless($self);
                   2139:     return $self;
                   2140: }
                   2141: 
                   2142: sub render {
                   2143:     my $self = shift;
                   2144:     my $helper = Apache::lonhelper::getHelper();
                   2145:     my $result = '';
                   2146:     my $var = $self->{'variable'};
                   2147: 
                   2148:     if (defined $self->{ERROR_MSG}) {
                   2149:         $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />';
                   2150:     }
                   2151: 
                   2152:     $result .= <<ELEMENTHTML;
                   2153: 
                   2154: <p>How should the column be formatted?</p>
                   2155: 
                   2156: <table cellpadding='3'>
                   2157:   <tr>
                   2158:     <td align='right'><b>Width</b>:</td>
                   2159:     <td align='left'><input type='text' name='$var.width' value='18' size='4'></td>
                   2160:     <td align='left'>
                   2161:       <select name='$var.widthunit'>
                   2162:         <option>cm</option><option>in</option>
                   2163:       </select>
                   2164:     </td>
                   2165:   </tr>
                   2166:   <tr>
                   2167:     <td align='right'><b>Height</b>:</td>
                   2168:     <td align='left'><input type='text' name="$var.height" value="25.9" size='4'></td>
                   2169:     <td align='left'>
                   2170:       <select name='$var.heightunit'>
                   2171:         <option>cm</option><option>in</option>
                   2172:       </select>
                   2173:     </td>
                   2174:   </tr>
                   2175:   <tr>
                   2176:     <td align='right'><b>Left margin</b>:</td>
                   2177:     <td align='left'><input type='text' name='$var.lmargin' value='-1.5' size='4'></td>
                   2178:     <td align='left'>
1.186     bowersj2 2179:       <select name='$var.lmarginunit'>
1.144     bowersj2 2180:         <option>cm</option><option>in</option>
                   2181:       </select>
                   2182:     </td>
                   2183:   </tr>
                   2184: </table>
                   2185: 
                   2186: <p>Hint: Some instructors like to leave scratch space for the student by
1.280     albertel 2187: making the width much smaller than the width of the page.</p>
1.144     bowersj2 2188: 
                   2189: ELEMENTHTML
                   2190: 
                   2191:     return $result;
                   2192: }
                   2193: 
                   2194: # If the user didn't select 1 column, skip this state.
                   2195: sub preprocess {
                   2196:     my $self = shift;
                   2197:     my $helper = Apache::lonhelper::getHelper();
                   2198: 
                   2199:     my $format = $helper->{VARS}->{$self->{'formatvar'}};
                   2200:     if (substr($format, 2, 1) ne '1') {
                   2201:         $helper->changeState($self->{NEXTSTATE});
                   2202:     }
                   2203:    
                   2204:     return 1;
                   2205: }
                   2206: 
                   2207: sub postprocess {
                   2208:     my $self = shift;
                   2209: 
                   2210:     my $var = $self->{'variable'};
                   2211:     my $helper = Apache::lonhelper->getHelper();
                   2212:     my $width = $helper->{VARS}->{$var .'.width'} = $ENV{"form.${var}.width"}; 
                   2213:     my $height = $helper->{VARS}->{$var .'.height'} = $ENV{"form.${var}.height"}; 
                   2214:     my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $ENV{"form.${var}.lmargin"}; 
                   2215:     $helper->{VARS}->{$var .'.widthunit'} = $ENV{"form.${var}.widthunit"}; 
                   2216:     $helper->{VARS}->{$var .'.heightunit'} = $ENV{"form.${var}.heightunit"}; 
                   2217:     $helper->{VARS}->{$var .'.lmarginunit'} = $ENV{"form.${var}.lmarginunit"}; 
                   2218: 
                   2219:     my $error = '';
                   2220: 
                   2221:     # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed 
                   2222:     # by an optional period, followed by digits, ending the string
                   2223: 
                   2224:     if ($width !~  /^-?[0-9]+(\.[0-9]*)?$/) {
                   2225:         $error .= "Invalid width; please type only a number.<br />\n";
                   2226:     }
                   2227:     if ($height !~  /^-?[0-9]+(\.[0-9]*)?$/) {
                   2228:         $error .= "Invalid height; please type only a number.<br />\n";
                   2229:     }
                   2230:     if ($lmargin !~  /^-?[0-9]+(\.[0-9]*)?$/) {
                   2231:         $error .= "Invalid left margin; please type only a number.<br />\n";
                   2232:     }
                   2233: 
                   2234:     if (!$error) {
                   2235:         Apache::lonhelper::getHelper()->changeState($self->{NEXTSTATE});
                   2236:         return 1;
                   2237:     } else {
                   2238:         $self->{ERROR_MSG} = $error;
                   2239:         return 0;
                   2240:     }
                   2241: }
                   2242: 
                   2243: 
1.119     bowersj2 2244: 
1.1       www      2245: __END__
1.6       sakharuk 2246: 

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