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

1.1       www         1: # The LearningOnline Network
                      2: # Printout
                      3: #
1.214   ! sakharuk    4: # $Id: lonprintout.pm,v 1.213 2003/08/13 19:40:07 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.1       www        28: # (Internal Server Error Handler
                     29: #
                     30: # (Login Screen
                     31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
                     32: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
                     33: #
                     34: # 3/1/1 Gerd Kortemeyer)
                     35: #
                     36: # 3/1 Gerd Kortemeyer
                     37: #
1.3       sakharuk   38: # 9/17 Alex Sakharuk
                     39: #
1.1       www        40: package Apache::lonprintout;
                     41: 
                     42: use strict;
1.10      albertel   43: use Apache::Constants qw(:common :http);
1.2       sakharuk   44: use Apache::lonxml;
                     45: use Apache::lonnet;
1.54      sakharuk   46: use Apache::loncommon;
1.13      sakharuk   47: use Apache::inputtags;
1.54      sakharuk   48: use Apache::grades;
1.13      sakharuk   49: use Apache::edit;
1.5       sakharuk   50: use Apache::File();
1.68      sakharuk   51: use Apache::lonnavmaps;
1.34      sakharuk   52: use POSIX qw(strftime);
1.60      sakharuk   53: use GDBM_File;
                     54: 
                     55: 
                     56: my %hash;
1.76      sakharuk   57: my $LaTeXwidth = 0;
1.3       sakharuk   58: 
1.2       sakharuk   59: 
1.71      sakharuk   60: sub latex_header_footer_remove {
                     61:     my $text = shift;
                     62:     $text =~ s/\\end{document}//;
                     63:     $text =~ s/\\documentclass([^&]*)\\begin{document}//;
                     64:     return $text;
                     65: }
                     66: 
                     67: 
1.37      sakharuk   68: sub character_chart {
                     69:     my $result = shift;	
1.116     sakharuk   70:     $result =~ s/&\#0?0?(7|9);//g;
                     71:     $result =~ s/&\#0?(10|13);//g;
                     72:     $result =~ s/&\#0?32;/ /g;
                     73:     $result =~ s/&\#0?33;/!/g;
                     74:     $result =~ s/&(\#0?34|quot);/\"/g;
                     75:     $result =~ s/&\#0?35;/\\\#/g;
                     76:     $result =~ s/&\#0?36;/\\\$/g;
                     77:     $result =~ s/&\#0?37;/\\%/g; 
                     78:     $result =~ s/&(\#0?38|amp);/\\&/g; 
                     79:     $result =~ s/&\#(0?39|146);/\'/g;
                     80:     $result =~ s/&\#0?40;/(/g;
                     81:     $result =~ s/&\#0?41;/)/g;
                     82:     $result =~ s/&\#0?42;/\*/g;
                     83:     $result =~ s/&\#0?43;/\+/g;
                     84:     $result =~ s/&\#(0?44|130);/,/g;
                     85:     $result =~ s/&\#0?45;/-/g;
                     86:     $result =~ s/&\#0?46;/\./g;
                     87:     $result =~ s/&\#0?47;/\//g;
                     88:     $result =~ s/&\#0?48;/0/g;
                     89:     $result =~ s/&\#0?49;/1/g;
                     90:     $result =~ s/&\#0?50;/2/g;
                     91:     $result =~ s/&\#0?51;/3/g;
                     92:     $result =~ s/&\#0?52;/4/g;
                     93:     $result =~ s/&\#0?53;/5/g;
                     94:     $result =~ s/&\#0?54;/6/g;
                     95:     $result =~ s/&\#0?55;/7/g;
                     96:     $result =~ s/&\#0?56;/8/g;
                     97:     $result =~ s/&\#0?57;/9/g;
                     98:     $result =~ s/&\#0?58;/:/g;
                     99:     $result =~ s/&\#0?59;/;/g;
                    100:     $result =~ s/&(\#0?60|lt|\#139);/\$<\$/g;
                    101:     $result =~ s/&\#0?61;/\$=\$/g;
                    102:     $result =~ s/&(\#0?62|gt|\#155);/\$>\$/g;
                    103:     $result =~ s/&\#0?63;/\?/g;
                    104:     $result =~ s/&\#0?65;/A/g;
                    105:     $result =~ s/&\#0?66;/B/g;
                    106:     $result =~ s/&\#0?67;/C/g;
                    107:     $result =~ s/&\#0?68;/D/g;
                    108:     $result =~ s/&\#0?69;/E/g;
                    109:     $result =~ s/&\#0?70;/F/g;
                    110:     $result =~ s/&\#0?71;/G/g;
                    111:     $result =~ s/&\#0?72;/H/g;
                    112:     $result =~ s/&\#0?73;/I/g;
                    113:     $result =~ s/&\#0?74;/J/g;
                    114:     $result =~ s/&\#0?75;/K/g;
                    115:     $result =~ s/&\#0?76;/L/g;
                    116:     $result =~ s/&\#0?77;/M/g;
                    117:     $result =~ s/&\#0?78;/N/g;
                    118:     $result =~ s/&\#0?79;/O/g;
                    119:     $result =~ s/&\#0?80;/P/g;
                    120:     $result =~ s/&\#0?81;/Q/g;
                    121:     $result =~ s/&\#0?82;/R/g;
                    122:     $result =~ s/&\#0?83;/S/g;
                    123:     $result =~ s/&\#0?84;/T/g;
                    124:     $result =~ s/&\#0?85;/U/g;
                    125:     $result =~ s/&\#0?86;/V/g;
                    126:     $result =~ s/&\#0?87;/W/g;
                    127:     $result =~ s/&\#0?88;/X/g;
                    128:     $result =~ s/&\#0?89;/Y/g;
                    129:     $result =~ s/&\#0?90;/Z/g;
                    130:     $result =~ s/&\#0?91;/[/g;
                    131:     $result =~ s/&\#0?92;/\$\\setminus\$/g;
                    132:     $result =~ s/&\#0?93;/]/g;
                    133:     $result =~ s/&\#(0?94|136);/\$\\wedge\$/g;
                    134:     $result =~ s/&\#(0?95|138|154);/\\underline{\\makebox[2mm]{\\strut}}/g;
                    135:     $result =~ s/&\#(0?96|145);/\`/g;
                    136:     $result =~ s/&\#0?97;/a/g;
                    137:     $result =~ s/&\#0?98;/b/g;
                    138:     $result =~ s/&\#0?99;/c/g;
                    139:     $result =~ s/&\#100;/d/g;
                    140:     $result =~ s/&\#101;/e/g;
                    141:     $result =~ s/&\#102;/f/g;
                    142:     $result =~ s/&\#103;/g/g;
                    143:     $result =~ s/&\#104;/h/g;
                    144:     $result =~ s/&\#105;/i/g;
                    145:     $result =~ s/&\#106;/j/g;
                    146:     $result =~ s/&\#107;/k/g;
                    147:     $result =~ s/&\#108;/l/g;
                    148:     $result =~ s/&\#109;/m/g;
                    149:     $result =~ s/&\#110;/n/g;
                    150:     $result =~ s/&\#111;/o/g;
                    151:     $result =~ s/&\#112;/p/g;
                    152:     $result =~ s/&\#113;/q/g;
                    153:     $result =~ s/&\#114;/r/g;
                    154:     $result =~ s/&\#115;/s/g;
                    155:     $result =~ s/&\#116;/t/g;
                    156:     $result =~ s/&\#117;/u/g;
                    157:     $result =~ s/&\#118;/v/g;
                    158:     $result =~ s/&\#119;/w/g;
                    159:     $result =~ s/&\#120;/x/g;
                    160:     $result =~ s/&\#121;/y/g;
                    161:     $result =~ s/&\#122;/z/g;
                    162:     $result =~ s/&\#123;/\\{/g;
                    163:     $result =~ s/&\#124;/\|/g;
                    164:     $result =~ s/&\#125;/\\}/g;
                    165:     $result =~ s/&\#126;/\~/g;
                    166:     $result =~ s/&\#131;/\\textflorin /g;
                    167:     $result =~ s/&\#132;/\"/g;
                    168:     $result =~ s/&\#133;/\$\\ldots\$/g;
                    169:     $result =~ s/&\#134;/\$\\dagger\$/g;
                    170:     $result =~ s/&\#135;/\$\\ddagger\$/g;
                    171:     $result =~ s/&\#137;/\\textperthousand /g;
                    172:     $result =~ s/&\#140;/{\\OE}/g;
                    173:     $result =~ s/&\#147;/\`\`/g;
                    174:     $result =~ s/&\#148;/\'\'/g;
                    175:     $result =~ s/&\#149;/\$\\bullet\$/g;
                    176:     $result =~ s/&\#150;/--/g;
                    177:     $result =~ s/&\#151;/---/g;
                    178:     $result =~ s/&\#152;/\$\\sim\$/g;
                    179:     $result =~ s/&\#153;/\\texttrademark /g;
                    180:     $result =~ s/&\#156;/\\oe/g;
                    181:     $result =~ s/&\#159;/\\\"Y/g;
1.131     bowersj2  182:     $result =~ s/&(\#160|nbsp);//g;
1.116     sakharuk  183:     $result =~ s/&(\#161|iexcl);/!\`/g;
                    184:     $result =~ s/&(\#162|cent);/\\textcent /g;
                    185:     $result =~ s/&(\#163|pound);/\\pounds /g; 
                    186:     $result =~ s/&(\#164|curren);/\\textcurrency /g;
                    187:     $result =~ s/&(\#165|yen);/\\textyen /g;
                    188:     $result =~ s/&(\#166|brvbar);/\\textbrokenbar /g;
                    189:     $result =~ s/&(\#167|sect);/\\textsection /g;
                    190:     $result =~ s/&(\#168|uml);/\\texthighdieresis /g;
                    191:     $result =~ s/&(\#169|copy);/\\copyright /g;
                    192:     $result =~ s/&(\#170|ordf);/\\textordfeminine /g;
                    193:     $result =~ s/&(\#172|not);/\$\\neg\$/g;
                    194:     $result =~ s/&(\#173|shy);/ - /g;
                    195:     $result =~ s/&(\#174|reg);/\\textregistered /g;
                    196:     $result =~ s/&(\#175|macr);/\$^{-}\$/g;
                    197:     $result =~ s/&(\#176|deg);/\$^{\\circ}\$/g;
                    198:     $result =~ s/&(\#177|plusmn);/\$\\pm\$/g;
                    199:     $result =~ s/&(\#178|sup2);/\$^2\$/g;
                    200:     $result =~ s/&(\#179|sup3);/\$^3\$/g;
                    201:     $result =~ s/&(\#180|acute);/\\textacute /g;
                    202:     $result =~ s/&(\#181|micro);/\$\\mu\$/g;
                    203:     $result =~ s/&(\#182|para);/\\P/g;
                    204:     $result =~ s/&(\#183|middot);/\$\\cdot\$/g;
                    205:     $result =~ s/&(\#184|cedil);/\\c{\\strut}/g;
                    206:     $result =~ s/&(\#185|sup1);/\$^1\$/g;
                    207:     $result =~ s/&(\#186|ordm);/\\textordmasculine /g;
                    208:     $result =~ s/&(\#188|frac14);/\\textonequarter /g;
                    209:     $result =~ s/&(\#189|frac12);/\\textonehalf /g;
                    210:     $result =~ s/&(\#190|frac34);/\\textthreequarters /g;
                    211:     $result =~ s/&(\#191|iquest);/?\`/g;   
                    212:     $result =~ s/&(\#192|Agrave);/\\\`{A}/g;  
                    213:     $result =~ s/&(\#193|Aacute);/\\\'{A}/g; 
                    214:     $result =~ s/&(\#194|Acirc);/\\^{A}/g;
                    215:     $result =~ s/&(\#195|Atilde);/\\~{A}/g;
                    216:     $result =~ s/&(\#196|Auml);/\\\"{A}/g; 
                    217:     $result =~ s/&(\#197|Aring);/{\\AA}/g;
                    218:     $result =~ s/&(\#198|AElig);/{\\AE}/g;
                    219:     $result =~ s/&(\#199|Ccedil);/\\c{c}/g;
                    220:     $result =~ s/&(\#200|Egrave);/\\\`{E}/g;  
                    221:     $result =~ s/&(\#201|Eacute);/\\\'{E}/g;    
                    222:     $result =~ s/&(\#202|Ecirc);/\\^{E}/g;
                    223:     $result =~ s/&(\#203|Euml);/\\\"{E}/g;
                    224:     $result =~ s/&(\#204|Igrave);/\\\`{I}/g;
                    225:     $result =~ s/&(\#205|Iacute);/\\\'{I}/g;    
                    226:     $result =~ s/&(\#206|Icirc);/\\^{I}/g;
                    227:     $result =~ s/&(\#207|Iuml);/\\\"{I}/g;    
                    228:     $result =~ s/&(\#209|Ntilde);/\\~{N}/g;
                    229:     $result =~ s/&(\#210|Ograve);/\\\`{O}/g;
                    230:     $result =~ s/&(\#211|Oacute);/\\\'{O}/g;
                    231:     $result =~ s/&(\#212|Ocirc);/\\^{O}/g;
                    232:     $result =~ s/&(\#213|Otilde);/\\~{O}/g;
                    233:     $result =~ s/&(\#214|Ouml);/\\\"{O}/g;    
                    234:     $result =~ s/&(\#215|times);/\$\\times\$/g;
                    235:     $result =~ s/&(\#216|Oslash);/{\\O}/g;
                    236:     $result =~ s/&(\#217|Ugrave);/\\\`{U}/g;    
                    237:     $result =~ s/&(\#218|Uacute);/\\\'{U}/g;
                    238:     $result =~ s/&(\#219|Ucirc);/\\^{U}/g;
                    239:     $result =~ s/&(\#220|Uuml);/\\\"{U}/g;
                    240:     $result =~ s/&(\#221|Yacute);/\\\'{Y}/g;
                    241:     $result =~ s/&(\#223|szlig);/\\ss/g;
                    242:     $result =~ s/&(\#224|agrave);/\\\`{a}/g;
                    243:     $result =~ s/&(\#225|aacute);/\\\'{a}/g;
                    244:     $result =~ s/&(\#226|acirc);/\\^{a}/g;
                    245:     $result =~ s/&(\#227|atilde);/\\~{a}/g;
                    246:     $result =~ s/&(\#228|auml);/\\\"{a}/g;
                    247:     $result =~ s/&(\#229|aring);/{\\aa}/g;
                    248:     $result =~ s/&(\#230|aelig);/{\\ae}/g;
                    249:     $result =~ s/&(\#231|ccedil);/\\c{c}/g;
                    250:     $result =~ s/&(\#232|egrave);/\\\`{e}/g;
                    251:     $result =~ s/&(\#233|eacute);/\\\'{e}/g;
                    252:     $result =~ s/&(\#234|ecirc);/\\^{e}/g;
                    253:     $result =~ s/&(\#235|euml);/\\\"{e}/g;
                    254:     $result =~ s/&(\#236|igrave);/\\\`{i}/g;
                    255:     $result =~ s/&(\#237|iacute);/\\\'{i}/g;
                    256:     $result =~ s/&(\#238|icirc);/\\^{i}/g;
                    257:     $result =~ s/&(\#239|iuml);/\\\"{i}/g;
                    258:     $result =~ s/&(\#240|eth);/\$\\partial\$/g;
                    259:     $result =~ s/&(\#241|ntilde);/\\~{n}/g;
                    260:     $result =~ s/&(\#242|ograve);/\\\`{o}/g;
                    261:     $result =~ s/&(\#243|oacute);/\\\'{o}/g;
                    262:     $result =~ s/&(\#244|ocirc);/\\^{o}/g;
                    263:     $result =~ s/&(\#245|otilde);/\\~{o}/g;
                    264:     $result =~ s/&(\#246|ouml);/\\\"{o}/g;
                    265:     $result =~ s/&(\#247|divide);/\$\\div\$/g;
                    266:     $result =~ s/&(\#248|oslash);/{\\o}/g;
                    267:     $result =~ s/&(\#249|ugrave);/\\\`{u}/g; 
                    268:     $result =~ s/&(\#250|uacute);/\\\'{u}/g;
                    269:     $result =~ s/&(\#251|ucirc);/\\^{u}/g;
                    270:     $result =~ s/&(\#252|uuml);/\\\"{u}/g;
                    271:     $result =~ s/&(\#253|yacute);/\\\'{y}/g;
                    272:     $result =~ s/&(\#255|yuml);/\\\"{y}/g;
                    273:     $result =~ s/&\#952;/\$\\theta\$/g;
1.117     sakharuk  274: #Greek Alphabet
                    275:     $result =~ s/&(alpha|\#945);/\$\\alpha \$/g;
                    276:     $result =~ s/&(beta|\#946);/\$\\beta \$/g;
                    277:     $result =~ s/&(gamma|\#947);/\$\\gamma \$/g;
                    278:     $result =~ s/&(delta|\#948);/\$\\delta \$/g;
                    279:     $result =~ s/&(epsilon|\#949);/\$\\epsilon \$/g;
                    280:     $result =~ s/&(zeta|\#950);/\$\\zeta \$/g;
                    281:     $result =~ s/&(eta|\#951);/\$\\eta \$/g;
                    282:     $result =~ s/&(theta|\#952);/\$\\theta \$/g;
                    283:     $result =~ s/&(iota|\#953);/\$\\iota \$/g;
                    284:     $result =~ s/&(kappa|\#954);/\$\\kappa \$/g;
                    285:     $result =~ s/&(lambda|\#955);/\$\\lambda \$/g;
                    286:     $result =~ s/&(mu|\#956);/\$\\mu \$/g;
                    287:     $result =~ s/&(nu|\#957);/\$\\nu \$/g;
                    288:     $result =~ s/&(xi|\#958);/\$\\xi \$/g;
1.199     sakharuk  289:     $result =~ s/&(omicron|\#959);/o/g;
1.117     sakharuk  290:     $result =~ s/&(pi|\#960);/\$\\pi \$/g;
                    291:     $result =~ s/&(rho|\#961);/\$\\rho \$/g;
                    292:     $result =~ s/&(sigma|\#963);/\$\\sigma \$/g;
                    293:     $result =~ s/&(tau|\#964);/\$\\tau \$/g;
                    294:     $result =~ s/&(upsilon|\#965);/\$\\upsilon \$/g;
                    295:     $result =~ s/&(phi|\#966);/\$\\phi \$/g;
                    296:     $result =~ s/&(chi|\#967);/\$\\chi \$/g;
                    297:     $result =~ s/&(psi|\#968);/\$\\psi \$/g;
                    298:     $result =~ s/&(omega|\#969);/\$\\omega \$/g;
1.199     sakharuk  299:     $result =~ s/&(thetasym|\#977);/\$\\vartheta \$/g;
                    300:     $result =~ s/&(piv|\#982);/\$\\varpi \$/g;
                    301:     $result =~ s/&(Alpha|\#913);/A/g;
                    302:     $result =~ s/&(Beta|\#914);/B/g;
1.117     sakharuk  303:     $result =~ s/&(Gamma|\#915);/\$\\Gamma \$/g;
                    304:     $result =~ s/&(Delta|\#916);/\$\\Delta \$/g;
1.199     sakharuk  305:     $result =~ s/&(Epsilon|\#917);/E/g;
                    306:     $result =~ s/&(Zeta|\#918);/Z/g;
                    307:     $result =~ s/&(Eta|\#919);/H/g;
1.117     sakharuk  308:     $result =~ s/&(Theta|\#920);/\$\\Theta \$/g;
1.199     sakharuk  309:     $result =~ s/&(Iota|\#921);/I/g;
                    310:     $result =~ s/&(Kappa|\#922);/K/g;
1.117     sakharuk  311:     $result =~ s/&(Lambda|\#923);/\$\\Lambda \$/g;
1.199     sakharuk  312:     $result =~ s/&(Mu|\#924);/M/g;
                    313:     $result =~ s/&(Nu|\#925);/N/g;
1.117     sakharuk  314:     $result =~ s/&(Xi|\#926);/\$\\Xi \$/g;
1.199     sakharuk  315:     $result =~ s/&(Omicron|\#927);/O/g;
1.117     sakharuk  316:     $result =~ s/&(Pi|\#928);/\$\\Pi \$/g;
1.199     sakharuk  317:     $result =~ s/&(Rho|\#929);/P/g;
1.117     sakharuk  318:     $result =~ s/&(Sigma|\#931);/\$\\Sigma \$/g;
1.199     sakharuk  319:     $result =~ s/&(Tau|\#932);/T/g;
1.117     sakharuk  320:     $result =~ s/&(Upsilon|\#933);/\$\\Upsilon \$/g;
                    321:     $result =~ s/&(Phi|\#934);/\$\\Phi \$/g;
1.199     sakharuk  322:     $result =~ s/&(Chi|\#935);/X/g;
1.117     sakharuk  323:     $result =~ s/&(Psi|\#936);/\$\\Psi \$/g;
                    324:     $result =~ s/&(Omega|\#937);/\$\\Omega \$/g;
1.199     sakharuk  325: #Arrows (extended HTML 4.01)
                    326:     $result =~ s/&(larr|\#8592);/\$\\leftarrow \$/g;
                    327:     $result =~ s/&(uarr|\#8593);/\$\\uparrow \$/g;
                    328:     $result =~ s/&(rarr|\#8594);/\$\\rightarrow \$/g;
                    329:     $result =~ s/&(darr|\#8595);/\$\\downarrow \$/g;
                    330:     $result =~ s/&(harr|\#8596);/\$\\leftrightarrow \$/g;
                    331:     $result =~ s/&(lArr|\#8656);/\$\\Leftarrow \$/g;
                    332:     $result =~ s/&(uArr|\#8657);/\$\\Uparrow \$/g;
                    333:     $result =~ s/&(rArr|\#8658);/\$\\Rightarrow \$/g;
                    334:     $result =~ s/&(dArr|\#8659);/\$\\Downarrow \$/g;
                    335:     $result =~ s/&(hArr|\#8660);/\$\\Leftrightarrow \$/g;
                    336: #Mathematical Operators (extended HTML 4.01)
                    337:     $result =~ s/&(forall|\#8704);/\$\\forall \$/g;
                    338:     $result =~ s/&(part|\#8706);/\$\\partial \$/g;
                    339:     $result =~ s/&(exist|\#8707);/\$\\exists \$/g;
                    340:     $result =~ s/&(empty|\#8709);/\$\\emptyset \$/g;
                    341:     $result =~ s/&(nabla|\#8711);/\$\\nabla \$/g;
                    342:     $result =~ s/&(isin|\#8712);/\$\\in \$/g;
                    343:     $result =~ s/&(notin|\#8713);/\$\\notin \$/g;
                    344:     $result =~ s/&(ni|\#8715);/\$\\ni \$/g;
                    345:     $result =~ s/&(prod|\#8719);/\$\\prod \$/g;
                    346:     $result =~ s/&(sum|\#8721);/\$\\sum \$/g;
                    347:     $result =~ s/&(minus|\#8722);/\$-\$/g;
                    348:     $result =~ s/&(lowast|\#8727);/\$*\$/g;
                    349:     $result =~ s/&(radic|\#8730);/\$\\surd \$/g;
                    350:     $result =~ s/&(prop|\#8733);/\$\\propto \$/g;
                    351:     $result =~ s/&(infin|\#8734);/\$\\infty \$/g;
                    352:     $result =~ s/&(ang|\#8736);/\$\\angle \$/g;
                    353:     $result =~ s/&(and|\#8743);/\$\\wedge \$/g;
                    354:     $result =~ s/&(or|\#8744);/\$\\vee \$/g;
                    355:     $result =~ s/&(cap|\#8745);/\$\\cap \$/g;
                    356:     $result =~ s/&(cup|\#8746);/\$\\cup \$/g;
                    357:     $result =~ s/&(int|\#8747);/\$\\int \$/g;
                    358:     $result =~ s/&(sim|\#8764);/\$\\sim \$/g;
                    359:     $result =~ s/&(cong|\#8773);/\$\\cong \$/g;
                    360:     $result =~ s/&(asymp|\#8776);/\$\\approx \$/g;
                    361:     $result =~ s/&(ne|\#8800);/\$\\not= \$/g;
                    362:     $result =~ s/&(equiv|\#8801);/\$\\equiv \$/g;
                    363:     $result =~ s/&(le|\#8804);/\$\\leq \$/g;
                    364:     $result =~ s/&(ge|\#8805);/\$\\geq \$/g;
                    365:     $result =~ s/&(sub|\#8834);/\$\\subset \$/g;
                    366:     $result =~ s/&(sup|\#8835);/\$\\supset \$/g;
                    367:     $result =~ s/&(nsub|\#8836);/\$\\not\\subset \$/g;
                    368:     $result =~ s/&(sube|\#8838);/\$\\subseteq \$/g;
                    369:     $result =~ s/&(supe|\#8839);/\$\\supseteq \$/g;
                    370:     $result =~ s/&(oplus|\#8853);/\$\\oplus \$/g;
                    371:     $result =~ s/&(otimes|\#8855);/\$\\otimes \$/g;
                    372:     $result =~ s/&(perp|\#8869);/\$\\perp \$/g;
                    373:     $result =~ s/&(sdot|\#8901);/\$\\cdot \$/g;
                    374: #Geometric Shapes (extended HTML 4.01)
                    375:     $result =~ s/&(loz|\#9674);/\$\\Diamond \$/g;
                    376: #Miscellaneous Symbols (extended HTML 4.01)
                    377:     $result =~ s/&(spades|\#9824);/\$\\spadesuit \$/g;
                    378:     $result =~ s/&(clubs|\#9827);/\$\\clubsuit \$/g;
                    379:     $result =~ s/&(hearts|\#9829);/\$\\heartsuit \$/g;
                    380:     $result =~ s/&(diams|\#9830);/\$\\diamondsuit \$/g;
1.37      sakharuk  381:     return $result;
                    382: }
1.41      sakharuk  383: 
                    384: 
1.177     sakharuk  385: sub page_format {
1.140     sakharuk  386: #
                    387: #Correspondence between $papersize variable and real paper format:
                    388: # 0 - "Letter [8 1/2x11 in]"
                    389: # 1 - "Legal [8 1/2x14 in]"
                    390: # 2 - "Ledger/Tabloid [11x17 in]"
                    391: # 3 - "Executive [7 1/2x10 in]"
                    392: # 4 - "A2 [420x594 mm]"
                    393: # 5 - "A3 [297x420 mm]"
                    394: # 6 - "A4 [210x297 mm]"
                    395: # 7 - "A5 [148x210 mm]"
                    396: # 8 - "A6 [105x148 mm]"
                    397: # 
                    398:     my ($papersize,$layout,$numberofcolumns) = @_; 
1.202     sakharuk  399:     my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = (0,0,0,0,0);
1.140     sakharuk  400:     if ($papersize eq '0') {
                    401: 	if ($layout eq 'book') {
                    402: 	    if ($numberofcolumns == 1) {
1.190     sakharuk  403: 		$textwidth = '7.1 in';      #'18 cm';
                    404: 		$textheight = '10.2 in';    #'25.9 cm';
1.140     sakharuk  405: 		$oddoffset = '-0.57 in';
                    406: 		$evenoffset = '-0.57 in';
                    407: 	    } elsif ($numberofcolumns == 2) {
1.190     sakharuk  408: 		$textwidth = '3.66 in';     #'93 mm';
                    409: 		$textheight = '10.2 in';    #'25.9 cm';
1.140     sakharuk  410: 		$oddoffset = '-0.57 in';
                    411: 		$evenoffset = '-0.57 in';
                    412: 	    }
                    413: 	} elsif ($layout eq 'album') {
                    414: 	    if ($numberofcolumns eq '1') {
                    415: 		$textwidth = '8.8 in';
                    416: 		$textheight = '6.8 in';
                    417: 		$oddoffset = '-40 pt';
                    418: 		$evenoffset = '-60 pt';
                    419: 	    } elsif ($numberofcolumns == 2) {
1.202     sakharuk  420: 		$textwidth = '4.4 in';
1.140     sakharuk  421: 		$textheight = '6.8 in';
1.202     sakharuk  422: 		$oddoffset = '-0.5 in';
                    423: 		$evenoffset = '-1.5 in';
                    424: 		$topmargin = '3.5 in';
1.140     sakharuk  425: 	    }
                    426: 	}
                    427: #    } elsif($papersize eq '1') {
                    428: #    } elsif($papersize eq '2') {
                    429: #    } elsif($papersize eq '3'/) {
                    430:     } elsif($papersize eq '6') {
                    431: 	if ($layout eq 'book') {
                    432: 	    if ($numberofcolumns == 1) {
                    433: 		$textwidth = '18 cm';
                    434: 		$textheight = '28 cm';
                    435: 		$oddoffset = '-0.57 in';
                    436: 		$evenoffset = '-0.57 in';
                    437: 	    } elsif ($numberofcolumns == 2) {
                    438: 		$textwidth = '96 mm';
                    439: 		$textheight = '2 cm';
                    440: 		$oddoffset = '-0.57 in';
                    441: 		$evenoffset = '-0.57 in';
                    442: 	    }
                    443: 	} elsif ($layout eq 'album') {
                    444: 	    if ($numberofcolumns eq '1') {
                    445: 		$textwidth = '8.5 in';
                    446: 		$textheight = '7.7 in';
                    447: 		$oddoffset = '-40 pt';
                    448: 		$evenoffset = '-60 pt';
                    449: 	    } elsif ($numberofcolumns == 2) {
                    450: 		$textwidth = '3.9 in';
                    451: 		$textheight = '7.7 in';
                    452: 		$oddoffset = '-40 pt';
                    453: 		$evenoffset = '-60 pt';
                    454: 	    }
                    455: 	}
                    456: #    } elsif($papersize eq '5') {
                    457: #    } elsif($papersize eq '4') {
                    458: #    } elsif($papersize eq '7') {
                    459: #    } elsif($papersize eq '8') {
1.76      sakharuk  460:     }
1.202     sakharuk  461:     return $textwidth,$textheight,$oddoffset,$evenoffset,$topmargin;
1.140     sakharuk  462: }
1.76      sakharuk  463: 
                    464: 
1.126     albertel  465: sub get_name {
                    466:     my ($uname,$udom)=@_;
                    467:     if (!defined($uname)) { $uname=$ENV{'user.name'}; }
1.212     albertel  468:     if (!defined($udom)) { $udom=$ENV{'user.domain'}; }
1.126     albertel  469:     my $plainname=&Apache::loncommon::plainname($uname,$udom);
1.213     albertel  470:     if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; }
                    471:     $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header');
                    472:     return $plainname;
1.126     albertel  473: }
                    474: 
1.213     albertel  475: sub get_course {
                    476:     my $courseidinfo;
                    477:     if (defined($ENV{'request.course.id'})) {
                    478: 	$courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'header');
                    479:     }
                    480:     return $courseidinfo;
                    481: }
1.177     sakharuk  482: 
1.76      sakharuk  483: sub page_format_transformation {
1.214   ! sakharuk  484:     my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist) = @_; 
1.202     sakharuk  485:     my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);
1.213     albertel  486:     $assignment=~s/_/ /g;
                    487:     if ($numberofcolumns != 1) {
                    488: 	($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);
                    489:     } else {
                    490: 	($textwidth,$textheight,$oddoffset,$evenoffset) = ($ENV{'form.width'},$ENV{'form.height'},$ENV{'form.leftmargin'},$ENV{'form.leftmargin'});
                    491:     }
1.126     albertel  492:     my $name = &get_name();
1.213     albertel  493:     my $courseidinfo = &get_course();
                    494:     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
1.140     sakharuk  495:     if ($layout eq 'album') {
1.202     sakharuk  496: 	my $topmargintoinsert = '';
                    497: 	if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';}
1.213     albertel  498: 	    $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}\\pagestyle{fancy}\\rhead{}\\chead{}\\lhead{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}} \\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1} /;
1.140     sakharuk  499:     } elsif ($layout eq 'book') {
                    500: 	if ($choice ne 'All class print') { 
1.213     albertel  501: 	    $text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{}\\lhead{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}/;
1.140     sakharuk  502: 	} else {
1.190     sakharuk  503: 	    $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\\setcounter{page}{1}  \\vskip 5 mm /;
1.140     sakharuk  504: 	}
                    505:     }
1.214   ! sakharuk  506:     if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
        !           507:     if ($indexlist eq 'yes') {
        !           508: 	$text=~s/(\\begin{document})/\\makeindex $1/;
        !           509: 	$text=~s/(\\end{document})/\\strut\\\\\\strut\\printindex $1/;
        !           510:     }
1.140     sakharuk  511:     return $text;
                    512: }
                    513: 
                    514: 
1.33      sakharuk  515: sub page_cleanup {
                    516:     my $result = shift;	
1.65      sakharuk  517:  
                    518:     $result =~ m/\\end{document}(\d*)$/;
1.34      sakharuk  519:     my $number_of_columns = $1;
1.33      sakharuk  520:     my $insert = '{';
1.34      sakharuk  521:     for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33      sakharuk  522:     $insert .= '}';
1.65      sakharuk  523:     $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
1.34      sakharuk  524:     $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
                    525:     return $result,$number_of_columns;
1.7       sakharuk  526: }
1.5       sakharuk  527: 
1.3       sakharuk  528: 
1.60      sakharuk  529: sub details_for_menu {
                    530: 
                    531:     my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}};
                    532:     my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'});
1.63      albertel  533:     my ($map,$id,$resource)=split(/___/,$symbolic);
1.123     albertel  534:     $map=&Apache::lonnet::clutter($map);
1.102     sakharuk  535:     my $name_of_sequence;
1.123     albertel  536:     $name_of_sequence = $hash{'title_'.$hash{'ids_'.$map}};
1.63      albertel  537:     if ($name_of_sequence =~ /^\s*$/) {
1.123     albertel  538: 	$map =~ m|([^/]+)$|;
                    539: 	$name_of_sequence = $1;
1.63      albertel  540:     }
1.123     albertel  541:     my $name_of_map = $hash{'title_'.$hash{'ids_'.&Apache::lonnet::clutter($ENV{'request.course.uri'})}};
1.63      albertel  542:     if ($name_of_map =~ /^\s*$/) {
1.123     albertel  543: 	$ENV{'request.course.uri'} =~ m|([^/]+)$|;
                    544: 	$name_of_map = $1;
                    545:     }
1.63      albertel  546:     return ($name_of_resourse,$name_of_sequence,$name_of_map);
1.60      sakharuk  547: 
1.76      sakharuk  548: }
                    549: 
                    550: 
                    551: sub latex_corrections {
                    552: 
                    553:     my ($number_of_columns,$result) = @_;
                    554: 
1.185     sakharuk  555: #    $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
1.76      sakharuk  556:     $result =~ s/\$number_of_columns/$number_of_columns/g;
1.91      sakharuk  557:     $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/;
                    558:     $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
                    559:     $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g;
1.76      sakharuk  560: #-- LaTeX corrections     
                    561:     my $first_comment = index($result,'<!--',0);
                    562:     while ($first_comment != -1) {
                    563: 	my $end_comment = index($result,'-->',$first_comment);
                    564: 	substr($result,$first_comment,$end_comment-$first_comment+3) = '';
                    565: 	$first_comment = index($result,'<!--',$first_comment);
                    566:     }
                    567:     $result =~ s/^\s+$//gm; #remove empty lines
1.94      sakharuk  568:     $result =~ s/(\s)(\s+)/$1/g; #removes more than one empty space
1.76      sakharuk  569:     $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
                    570:     $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
                    571:     $result =~ s/{\\par }\s*\\\\/\\\\/gm;
                    572: 	$result =~ s/\\\\\s+\[/ \[/g;
                    573:     $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
                    574:     #conversion of html characters to LaTeX equivalents
                    575:     if ($result =~ m/&(\w+|#\d+);/) {
                    576: 	$result = &character_chart($result);
                    577:     }
                    578:     $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
                    579:     $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
                    580: 
                    581:     return $result;
1.60      sakharuk  582: }
                    583: 
1.3       sakharuk  584: 
1.214   ! sakharuk  585: sub index_table {
        !           586:     my $currentURL = shift;
        !           587:     my $insex_string='';
        !           588:     $currentURL=~s/\.([^\/+])$/\.$1\.meta/;
        !           589:     $insex_string=&Apache::lonnet::metadata($currentURL,'keywords');
        !           590:     return $insex_string;
        !           591: }
        !           592: 
        !           593: 
1.177     sakharuk  594: sub output_data {
1.184     sakharuk  595:     my ($r,$helper,$rparmhash) = @_;
                    596:     my %parmhash = %$rparmhash;
1.187     www       597:     my $bodytag=&Apache::loncommon::bodytag('Preparing Printout');
1.140     sakharuk  598:     $r->print(<<ENDPART);
                    599: <html>
                    600: <head>
                    601: <title>LON-CAPA output for printing</title>
                    602: </head>
1.187     www       603: $bodytag
                    604: Please stand by while processing your print request, this may take some time ...
1.140     sakharuk  605: ENDPART
                    606: 
                    607:     my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
                    608:     my ($result,$selectionmade) = ('','');
                    609:     my $number_of_columns = 1; #used only for pages to determine the width of the cell
                    610:     my @temporary_array=split /\|/,$format_from_helper;
                    611:     my ($laystyle,$numberofcolumns,$papersize)=@temporary_array;
                    612:     if ($laystyle eq 'L') {
                    613: 	$laystyle='album';
                    614:     } else {
                    615: 	$laystyle='book';
                    616:     }
1.177     sakharuk  617:     my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns);
1.140     sakharuk  618:     my $assignment =  $ENV{'form.assignment'};
                    619:     my $LaTeXwidth; 
1.190     sakharuk  620:     if ($textwidth=~/(\d+\.?\d*)\s*cm/) {
1.140     sakharuk  621: 	$LaTeXwidth = $1*10;
1.190     sakharuk  622:     } elsif ($textwidth=~/(\d+\.?\d*)\s*mm/) {
1.140     sakharuk  623: 	$LaTeXwidth = $1;
1.190     sakharuk  624:     } elsif ($textwidth=~/(\d+\.?\d*)\s*in/) {
1.140     sakharuk  625: 	$LaTeXwidth = $1*25.4;
                    626:     }
                    627:     $LaTeXwidth.=' mm';
1.153     sakharuk  628:     
1.140     sakharuk  629:     if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {
1.143     sakharuk  630:       #-- single document - problem, page, html, xml, ...
                    631: 	my $currentURL;
1.162     sakharuk  632: 	if ($helper->{'VARS'}->{'construction'} ne '1') {
1.185     sakharuk  633:             #prints published resource
1.153     sakharuk  634: 	    $currentURL=$helper->{'VARS'}->{'postdata'};
1.143     sakharuk  635: 	} else {
1.185     sakharuk  636:             #prints resource from the construction space
1.162     sakharuk  637: 	    $currentURL=$helper->{'VARS'}->{'filename'};
                    638: 	    $currentURL=~s/\/home\//\/~/;
                    639: 	    $currentURL=~s/public_html\///;
1.206     sakharuk  640: 	    if ($currentURL=~/([^?]+)/) {$currentURL=$1;}
1.143     sakharuk  641: 	}
1.140     sakharuk  642: 	$selectionmade = 1;
1.143     sakharuk  643: 	if ($currentURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.162     sakharuk  644: 	    my %moreenv;
                    645: 	    $moreenv{'request.filename'}=$currentURL;
1.166     albertel  646: 	    my %form;
                    647: 	    $form{'grade_target'}='tex';
1.200     sakharuk  648: 	    $form{'textwidth'}=$LaTeXwidth;	
1.203     sakharuk  649: 	    $form{'problem_split'}=$parmhash{'problem_stream_switch'};
                    650: 	    $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.169     albertel  651: 	    my $rndseed=time;
                    652: 	    $form{'rndseed'}=$rndseed;
1.162     sakharuk  653: 	    &Apache::lonnet::appenv(%moreenv);
1.201     sakharuk  654: 	    &Apache::lonnet::delenv('form.counter');
                    655: 	    &Apache::lonxml::init_counter();
1.168     albertel  656: 	    my $texversion=&Apache::lonnet::ssi($currentURL,%form);
1.165     sakharuk  657: 	    &Apache::lonnet::delenv('form.counter');
1.166     albertel  658: 	    &Apache::lonnet::delenv('request.filename');
1.163     sakharuk  659: 	    if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.166     albertel  660: 		my %form;
                    661: 		$form{'grade_target'}='answer';
1.167     albertel  662: 		$form{'answer_output_mode'}='tex';
1.169     albertel  663: 		$form{'rndseed'}=$rndseed;
1.166     albertel  664: 		my $answer=&Apache::lonnet::ssi($currentURL,%form);
1.170     sakharuk  665: 		$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
1.163     sakharuk  666: 	    }
1.214   ! sakharuk  667: 	    if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
        !           668: #		my $key_words=&index_table($currentURL);
        !           669: 		my @key_words=split(/,/,&index_table($currentURL));
        !           670: 		foreach my $key_word (@key_words) {
        !           671: 		    if ($key_word=~/\S+/) {
        !           672: 			$texversion=~s/\b($key_word)\b/$1 \\index{$1} /;
        !           673: 		    }
        !           674: 		}
        !           675: #		$texversion=~s/(\\end{document})/\\strut\\\\\\strut {\\large \\textbf{INDEX}}\\strut\\\\\\strut$key_words\\strut\\\\\\strut$1/;
        !           676: 	    }
1.162     sakharuk  677: 	    $result .= $texversion;
                    678: 	    if ($currentURL=~m/\.page\s*$/) {
                    679: 		($result,$number_of_columns) = &page_cleanup($result);
                    680: 	    }
                    681: 	} else {
1.207     sakharuk  682: 	  $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: ';
                    683: 	  if ($currentURL=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) {
                    684: 	      $result.=$1;
                    685: 	  } elsif ($currentURL=~/\/ext\//) {
                    686: 	      $result.=' \strut \\\\ THIS IS EXTERNAL RESOURCE WITH URL \strut \\\\ '.$currentURL.' ';
                    687: 	  } else {
                    688: 	      $result.=$currentURL;
                    689: 	  }
                    690: 	  $result.=' \end{document}'
1.162     sakharuk  691: 	}
1.142     sakharuk  692:     } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or
                    693:              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
                    694:              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')) { 
1.141     sakharuk  695:         #-- produce an output string
1.193     sakharuk  696: 	my %form=();	   
                    697: 	$form{'grade_target'}='tex';
                    698: 	$form{'textwidth'}=$LaTeXwidth;
                    699: 	$form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.203     sakharuk  700: 	$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.141     sakharuk  701: 	my $flag_latex_header_remove = 'NO';
                    702: 	my $flag_page_in_sequence = 'NO';
                    703: 	my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.193     sakharuk  704: 	my $prevassignment='';
1.201     sakharuk  705: 	&Apache::lonnet::delenv('form.counter');
                    706: 	&Apache::lonxml::init_counter();
1.141     sakharuk  707: 	for (my $i=0;$i<=$#master_seq;$i++) {
                    708: 	    $master_seq[$i]=~/___\d+___(.*)$/;
                    709: 	    my $urlp='/res/'.$1;
                    710: 	    if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') {
1.142     sakharuk  711: 		$selectionmade = 2;
                    712: 	    } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {
                    713: 		$selectionmade = 3;
                    714: 	    } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') {
                    715: 		$selectionmade = 4;
1.141     sakharuk  716: 	    }
1.166     albertel  717: 	    $form{'symb'}=$master_seq[$i];
1.198     sakharuk  718: 	    $master_seq[$i]=~/(.*)___\d*___/;
                    719: 	    my $assignment=&Apache::lonnet::gettitle($1); #tittle of the assignment which contains this problem
1.141     sakharuk  720: 	    #&Apache::lonnet::logthis("Trying to get $urlp with symb $master_seq[$i]");
1.166     albertel  721: 	    my $texversion=&Apache::lonnet::ssi($urlp,%form);
1.141     sakharuk  722: 	    if ($urlp=~/\.page$/) {
                    723: 		($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
                    724: 		if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;} 
                    725: 		$texversion =~ s/\\end{document}\d*/\\end{document}/;
                    726: 		$flag_page_in_sequence = 'YES';
                    727: 	    } 
                    728: 	    if ($flag_latex_header_remove ne 'NO') {
                    729: 		$texversion = &latex_header_footer_remove($texversion);
                    730: 	    } else {
                    731: 		$texversion =~ s/\\end{document}//;
1.171     sakharuk  732: 	    }
                    733: 	    if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                    734: 		my %form;
                    735: 		$form{'grade_target'}='answer';
                    736: 		$form{'answer_output_mode'}='tex';
                    737: 		my $answer=&Apache::lonnet::ssi($urlp,%form);
                    738: 		$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
1.141     sakharuk  739: 	    }
1.193     sakharuk  740: #	    $result .= $texversion;
1.198     sakharuk  741: 	    if (($selectionmade == 4) and ($assignment ne $prevassignment) and ($i>=1)) {
1.213     albertel  742: 		my ($name,$courseidinfo) = &get_name;
                    743: 		my $courseidinfo = &get_course();
                    744: 		if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
1.193     sakharuk  745: 		$prevassignment=$assignment;
1.213     albertel  746: 		$result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip -5 mm ';
1.193     sakharuk  747: 	    }
                    748: 	    $result .= $texversion;
1.141     sakharuk  749: 	    $flag_latex_header_remove = 'YES';   
                    750: 	}
                    751: 	&Apache::lonnet::delenv('form.counter');
                    752: 	if ($flag_page_in_sequence eq 'YES') {$result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;}	
                    753: 	$result .= '\end{document}';
1.150     sakharuk  754:      } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') { 
                    755:      #-- prints assignments for whole class or for selected students  
                    756: 	 $selectionmade=5;
                    757: 	 my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'};
                    758: 	 my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
                    759: 	 #loop over students
                    760: 	 my $flag_latex_header_remove = 'NO'; 
                    761: 	 my %moreenv;
                    762: 	 $moreenv{'form.textwidth'}=$LaTeXwidth;
                    763: 	 &Apache::lonnet::appenv(%moreenv);
                    764: 	 my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1);
                    765: 	 foreach my $person (@students) {
                    766: 	    my $current_output = ''; 
1.140     sakharuk  767: #	    my ($usersection,$username,$userdomain) = split /:/,$person;
1.150     sakharuk  768: 	    my ($username,$userdomain) = split /:/,$person;
                    769: 	    my $fullname = &get_name($username,$userdomain);
1.196     sakharuk  770: 
1.197     sakharuk  771: 	    if ($parmhash{'anonymous_quiz'}=~/yes/) {$fullname=' ';} #put here something reasonable for anonymous exams or quiz
1.150     sakharuk  772:             #goes through all resources, checks if they are available for current student, and produces output   
1.201     sakharuk  773: 	    &Apache::lonnet::delenv('form.counter');
                    774: 	    &Apache::lonxml::init_counter();
1.150     sakharuk  775: 	    foreach my $curresline (@master_seq)  {
                    776: 		if ($curresline=~ m/\.(problem|exam|quiz|assess|survey|form|library)$/) {
                    777: 		    my ($map,$id,$res_url) = split(/___/,$curresline);
                    778: 		    if (&Apache::lonnet::allowed('bre',$res_url)) {
                    779: 			my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,
                    780:                                                                         $ENV{'request.course.id'},'tex');
                    781: 			if ($flag_latex_header_remove eq 'YES') {
                    782: 			    $rendered = &latex_header_footer_remove($rendered);
                    783: 			} else {
                    784: 			    $rendered =~ s/\\end{document}//;
1.173     sakharuk  785: 			}
                    786: 			if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                    787: 			    my %form;
                    788: 			    $form{'answer_output_mode'}='tex';
1.203     sakharuk  789: 			    $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.193     sakharuk  790: 			    my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$ENV{'request.course.id'},%form);
1.173     sakharuk  791: 			    $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/;
1.150     sakharuk  792: 			}
                    793: 			$current_output .= $rendered;
                    794: 		    }
                    795: 		    $flag_latex_header_remove = 'YES';
                    796: 		}
                    797: 	    }
1.213     albertel  798: 	    my $courseidinfo = &get_course();
                    799: 	    if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
                    800: 
1.150     sakharuk  801: 	    if ($current_output=~/\\documentclass/) {
1.213     albertel  802: 		$current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$helper->{VARS}->{'assignment'}}}\\vskip 3 mm /;
1.150     sakharuk  803: 	    } else {
                    804: 		my $blanspages = '';
                    805: 		for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blanspages.='\clearpage\strut\clearpage';}
1.213     albertel  806: 		$current_output = '\strut\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$helper->{VARS}->{'assignment'}.'}}} \vskip -5 mm '.$current_output;
1.150     sakharuk  807: 	    }
                    808: 	    $result .= $current_output;
                    809: 	    &Apache::lonnet::delenv('form.counter');	    
                    810: 	    &Apache::lonxml::init_counter(); 
                    811: 	    &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                    812: 						    'last student '.$fullname);
                    813: 	}
                    814: 	&Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
                    815: 	$result .= '\end{document}';
                    816: 	&Apache::lonnet::delenv('form.textwidth');
1.151     sakharuk  817:     } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') {      
                    818:     #prints selected problems from the subdirectory 
                    819: 	$selectionmade = 6;
                    820:         my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
1.154     sakharuk  821: 	@list_of_files=sort @list_of_files;
1.175     sakharuk  822: 	my $flag_latex_header_remove = 'NO'; 
                    823: 	my $rndseed=time;
1.151     sakharuk  824: 	for (my $i=0;$i<=$#list_of_files;$i++) {
1.152     sakharuk  825: 	    my $urlp = $list_of_files[$i];
                    826: 	    if ($urlp=~/\//) {
1.166     albertel  827: 		my %form;
                    828: 		$form{'grade_target'}='tex';
                    829: 		$form{'textwidth'}=$LaTeXwidth;
1.175     sakharuk  830: 		$form{'rndseed'}=$rndseed;
1.152     sakharuk  831: 		if ($urlp =~ m|/home/([^/]+)/public_html|) {
                    832: 		    $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
                    833: 		} else {
                    834: 		    $urlp =~ s|^/home/httpd/html||;
                    835: 		}
1.166     albertel  836: 		my $texversion=&Apache::lonnet::ssi($urlp,%form);
1.174     sakharuk  837: 		if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
                    838: 		    my %form;
                    839: 		    $form{'grade_target'}='answer';
                    840: 		    $form{'answer_output_mode'}='tex';
1.203     sakharuk  841: 		    $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
1.174     sakharuk  842: 		    $form{'rndseed'}=$rndseed;
                    843: 		    my $answer=&Apache::lonnet::ssi($urlp,%form);
                    844: 		    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
                    845: 		}
1.151     sakharuk  846:                 #this chunck is responsible for printing the path to problem
1.152     sakharuk  847: 		my $newurlp = '';
                    848: 		my $HowMany = length($urlp)*2;
                    849: 		if ($HowMany > $LaTeXwidth) {
                    850: 		    my @temporrary = split '/',$urlp;
                    851: 		    my $HowManyNew = 0;
                    852: 		    for (my $ii=0;$ii<=$#temporrary;$ii++) {
                    853: 			if ($temporrary[$ii] ne '') {
                    854: 			    $HowManyNew += length($temporrary[$ii])*2;
                    855: 			    if ($HowManyNew < $LaTeXwidth ) {
                    856: 				$newurlp .=  '/'.$temporrary[$ii];
                    857: 			    } else {
                    858: 				$HowManyNew = 0;
                    859: 				$newurlp .=  '|\vskip -1 mm \noindent \verb|';
                    860: 				$ii--;
                    861: 			    }
                    862: 			}
                    863: 		    }
                    864: 		}
                    865: 		$texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/;
                    866: 		if ($flag_latex_header_remove ne 'NO') {
                    867: 		    $texversion = &latex_header_footer_remove($texversion);
                    868: 		} else {
                    869: 		    $texversion =~ s/\\end{document}//;
                    870: 		}
                    871: 		$result .= $texversion;
                    872: 	    }
                    873: 	    $flag_latex_header_remove = 'YES';  
1.151     sakharuk  874: 	}
1.175     sakharuk  875: 	if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\typeout)/ RANDOM SEED IS $rndseed $1/;}
1.152     sakharuk  876: 	$result .= '\end{document}';      	
1.140     sakharuk  877:     }
                    878: #-------------------------------------------------------- corrections for the different page formats
1.214   ! sakharuk  879:     $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'});
1.140     sakharuk  880:     $result = &latex_corrections($number_of_columns,$result);
1.190     sakharuk  881:     #changes page's parameters for the one column output 
1.195     sakharuk  882:     if ($numberofcolumns == 1) {
                    883: 	$result =~ s/\\textwidth= 9cm/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
                    884: 	$result =~ s/\\textheight 25\.9cm/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
                    885: 	$result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
                    886: 	$result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
                    887:     }
1.214   ! sakharuk  888:     if ($helper->{'VARS'}->{'TABLE_CONTENTS'} eq 'yes') {$selectionmade*=10;}
        !           889:     if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
        !           890: 	if ($selectionmade<10) {$selectionmade*=100;} else {$selectionmade*=10;}
        !           891:     }
1.140     sakharuk  892: #-- writing .tex file in prtspool 
                    893:     my $temp_file;
                    894:     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
                    895:     unless ($temp_file = Apache::File->new('>'.$filename)) {
                    896: 	$r->log_error("Couldn't open $filename for output $!");
                    897: 	return SERVER_ERROR; 
                    898:     } 
                    899:     print $temp_file $result;
                    900: 
                    901: $r->print(<<FINALEND);
                    902: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns&$selectionmade">
                    903: </body>
                    904: </html>
                    905: FINALEND
                    906: }
                    907: 
                    908: 
                    909: 
1.3       sakharuk  910: sub handler {
                    911: 
                    912:     my $r = shift;
1.131     bowersj2  913:     my $helper;
1.114     bowersj2  914: 
1.150     sakharuk  915: #    my $loaderror=&Apache::lonnet::overloaderror($r);
                    916: #    if ($loaderror) { return $loaderror; }
                    917: #    $loaderror=
                    918: #       &Apache::lonnet::overloaderror($r,
                    919: #         $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
                    920: #    if ($loaderror) { return $loaderror; }
1.67      www       921: 
1.177     sakharuk  922:     my $result = printHelper($r);
                    923:     if (!ref($result)) {
                    924: 	return $result;
1.60      sakharuk  925:     }
1.177     sakharuk  926:     $helper = $result;
                    927:    
                    928: #	my $key; 
                    929: #	foreach $key (keys %{$helper->{'VARS'}}) {
                    930: #	    $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'<-<br />');
                    931: #	}
                    932: #	return OK;
1.184     sakharuk  933: 
                    934:     my %parmhash=&Apache::lonnet::coursedescription($ENV{'request.course.id'});
                    935:     
1.207     sakharuk  936: #	my $key; 
1.200     sakharuk  937: #	foreach $key (keys %parmhash) {
                    938: #	    $r->print(' '.$key.'->'.$parmhash{$key}.'<-<br />');
                    939: #	}
                    940: #	return OK;
1.184     sakharuk  941: 
                    942:     &output_data($r,$helper,\%parmhash);
1.2       sakharuk  943:     return OK;
1.60      sakharuk  944: } 
1.2       sakharuk  945: 
1.131     bowersj2  946: use Apache::lonhelper;
1.130     sakharuk  947: 
1.131     bowersj2  948: sub printHelper {
1.115     bowersj2  949:     my $r = shift;
                    950: 
                    951:     if ($ENV{'request.course.id'}) {
1.131     bowersj2  952: 	my $fn=$ENV{'request.course.fn'};
                    953: 	tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640);
1.115     bowersj2  954:     }
                    955: 
                    956:     if ($r->header_only) {
1.131     bowersj2  957:         if ($ENV{'browser.mathml'}) {
                    958:             $r->content_type('text/xml');
                    959:         } else {
                    960:             $r->content_type('text/html');
                    961:         }
                    962:         $r->send_http_header;
                    963:         return OK;
1.115     bowersj2  964:     }
                    965: 
1.131     bowersj2  966:     # Send header, nocache
1.115     bowersj2  967:     if ($ENV{'browser.mathml'}) {
1.131     bowersj2  968:         $r->content_type('text/xml');
1.115     bowersj2  969:     } else {
1.131     bowersj2  970:         $r->content_type('text/html');
1.115     bowersj2  971:     }
                    972:     &Apache::loncommon::no_cache($r);
                    973:     $r->send_http_header;
                    974:     $r->rflush();
                    975: 
1.131     bowersj2  976:     # Unfortunately, this helper is so complicated we have to
                    977:     # write it by hand
                    978: 
                    979:     Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
                    980:     
1.176     bowersj2  981:     my $helper = Apache::lonhelper::helper->new("Printing Helper");
1.146     bowersj2  982:     $helper->declareVar('symb');
1.156     bowersj2  983:     $helper->declareVar('postdata');    
                    984:     $helper->declareVar('filename');
                    985:     $helper->declareVar('construction');
1.178     sakharuk  986:     $helper->declareVar('assignment');
1.131     bowersj2  987:     
                    988:     # This will persistently load in the data we want from the
                    989:     # very first screen.
1.156     bowersj2  990:     # Detect whether we're coming from construction space
1.208     www       991:     if ($ENV{'form.postdata'}=~/^(?:http:\/\/[^\/]+\/|\/|)\~([^\/]+)\/(.*)$/) {
1.156     bowersj2  992:         $helper->{VARS}->{'filename'} = "/home/$1/public_html/$2";
                    993:         $helper->{VARS}->{'construction'} = 1;
                    994:     } else {
                    995:         if ($ENV{'form.postdata'}) {
                    996:             $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($ENV{'form.postdata'});
                    997:         }
                    998:         if ($ENV{'form.symb'}) {
                    999:             $helper->{VARS}->{'symb'} = $ENV{'form.symb'};
                   1000:         }
                   1001:         if ($ENV{'form.url'}) {
                   1002:             $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
                   1003:         }
1.157     bowersj2 1004:     }
1.156     bowersj2 1005: 
1.146     bowersj2 1006:     if ($ENV{'form.symb'}) {
                   1007:         $helper->{VARS}->{'symb'} = $ENV{'form.symb'};
                   1008:     }
                   1009:     if ($ENV{'form.url'}) {
1.140     sakharuk 1010:         $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
1.153     sakharuk 1011: 
1.140     sakharuk 1012:     }
1.146     bowersj2 1013:     
1.115     bowersj2 1014:     my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu;
1.178     sakharuk 1015:     if ($sequenceTitle ne '') {$helper->{VARS}->{'assignment'}=$sequenceTitle;}
1.140     sakharuk 1016: 
1.156     bowersj2 1017:     
1.146     bowersj2 1018:     # Extract map
                   1019:     my $symb = $helper->{VARS}->{'symb'};
1.156     bowersj2 1020:     my ($map, $id, $url);
                   1021:     my $subdir;
                   1022: 
                   1023:     # Get the resource name from construction space
                   1024:     if ($helper->{VARS}->{'construction'}) {
                   1025:         $resourceTitle = substr($helper->{VARS}->{'filename'}, 
                   1026:                                 rindex($helper->{VARS}->{'filename'}, '/')+1);
                   1027:         $subdir = substr($helper->{VARS}->{'filename'},
                   1028:                          0, rindex($helper->{VARS}->{'filename'}, '/') + 1);
                   1029:     } else {
                   1030:         ($map, $id, $url) = split(/___/, $symb);
                   1031:         $helper->{VARS}->{'postdata'} = Apache::lonnet::clutter($url);
1.146     bowersj2 1032: 
1.156     bowersj2 1033:         if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
                   1034:             my $url = $helper->{VARS}->{'postdata'};
                   1035:             $resourceTitle = substr($url, rindex($url, '/') + 1);
                   1036:         }
                   1037:         $subdir = &Apache::lonnet::filelocation("", $url);
1.128     bowersj2 1038:     }
1.115     bowersj2 1039: 
1.192     bowersj2 1040:     my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
                   1041: 
1.131     bowersj2 1042:     Apache::lonhelper::registerHelperTags();
1.119     bowersj2 1043: 
1.131     bowersj2 1044:     # "Delete everything after the last slash."
1.119     bowersj2 1045:     $subdir =~ s|/[^/]+$||;
1.162     sakharuk 1046:     if (not $helper->{VARS}->{'construction'}) {
                   1047: 	$subdir='/home/httpd/html/res/'.$subdir;
1.153     sakharuk 1048:     }
1.189     bowersj2 1049:     # "Remove all duplicate slashes."
                   1050:     $subdir =~ s|/+|/|g;
1.119     bowersj2 1051: 
1.131     bowersj2 1052:     # What can be printed is a very dynamic decision based on
                   1053:     # lots of factors. So we need to dynamically build this list.
                   1054:     # To prevent security leaks, states are only added to the wizard
                   1055:     # if they can be reached, which ensures manipulating the form input
                   1056:     # won't allow anyone to reach states they shouldn't have permission
                   1057:     # to reach.
                   1058: 
                   1059:     # printChoices is tracking the kind of printing the user can
                   1060:     # do, and will be used in a choices construction later.
                   1061:     # In the meantime we will be adding states and elements to
                   1062:     # the helper by hand.
                   1063:     my $printChoices = [];
                   1064:     my $paramHash;
1.130     sakharuk 1065: 
1.156     bowersj2 1066:     if ($resourceTitle) {
                   1067:         push @{$printChoices}, ["<b>$resourceTitle</b> (prints what you just saw on the screen)", 'current_document', 'PAGESIZE'];
                   1068:     }
                   1069: 
1.187     www      1070: #    $r->print($helper->{VARS}->{'postdata'});
1.130     sakharuk 1071: 
1.131     bowersj2 1072:     # If we're in a sequence...
1.162     sakharuk 1073:     if ($helper->{'VARS'}->{'construction'} ne '1') {
1.131     bowersj2 1074:         # Allow problems from sequence
1.155     sakharuk 1075:         push @{$printChoices}, ["Problem(s) from <b>$sequenceTitle</b>", 'map_problems', 'CHOOSE_PROBLEMS'];
1.131     bowersj2 1076:         # Allow all resources from sequence
1.155     sakharuk 1077:         push @{$printChoices}, ["Everything (problem(s), page(s), html/xml file(s)) from <b>$sequenceTitle</b>", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
1.130     sakharuk 1078: 
1.192     bowersj2 1079:         my $isProblem = '$res->is_problem()';
                   1080: 	$isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
1.131     bowersj2 1081:         my $isProblemOrMap = '$res->is_problem() || $res->is_map()';
1.192     bowersj2 1082:         my $isNotMap = '!$res->is_map()';
                   1083: 	$isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
                   1084:         my $symb = '$res->symb()';
1.131     bowersj2 1085:         my $helperFragment = <<HELPERFRAGMENT;
1.155     sakharuk 1086:   <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">
                   1087:     <message>(mark them then click "next" button) <br /></message>
1.144     bowersj2 1088:     <resource variable="RESOURCES" multichoice="1" toponly='1'>
                   1089:       <nextstate>PAGESIZE</nextstate>
1.192     bowersj2 1090:       <filterfunc>return $isProblem;</filterfunc>
1.131     bowersj2 1091:       <mapurl>$map</mapurl>
1.192     bowersj2 1092:       <valuefunc>return $symb;</valuefunc>
1.131     bowersj2 1093:       </resource>
                   1094:     </state>
                   1095: 
1.155     sakharuk 1096:   <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">
                   1097:     <message>(mark them then click "next" button) <br /></message>
1.144     bowersj2 1098:     <resource variable="RESOURCES" multichoice="1" toponly='1'>
                   1099:       <nextstate>PAGESIZE</nextstate>
1.145     bowersj2 1100:       <filterfunc>return $isNotMap;</filterfunc>
1.131     bowersj2 1101:       <mapurl>$map</mapurl>
1.192     bowersj2 1102:       <valuefunc>return $symb;</valuefunc>
1.131     bowersj2 1103:       </resource>
                   1104:     </state>
                   1105: HELPERFRAGMENT
1.121     bowersj2 1106: 
1.131     bowersj2 1107:         &Apache::lonxml::xmlparse($r, 'helper', $helperFragment); 
1.121     bowersj2 1108:     }
                   1109: 
                   1110:     # If the user is priviledged, allow them to print all 
                   1111:     # problems in the course, optionally for selected students
1.131     bowersj2 1112:     if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($helper->{VARS}->{'postdata'}=~/\/res\//)) { 
1.155     sakharuk 1113:         push @{$printChoices}, ['<b>Problems</b> in this course', 'all_problems', 'ALL_PROBLEMS'];
1.131     bowersj2 1114:         push @{$printChoices}, ["Problems from <b>$sequenceTitle</b> for selected students", 'problems_for_students', 'CHOOSE_STUDENTS'];
                   1115: 
1.192     bowersj2 1116:         my $isProblem = '$res->is_problem()';
                   1117: 	$isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
                   1118:         my $isProblemOrMap = '($res->is_problem() || $res->is_map())';
                   1119: 	$isProblemOrMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
                   1120:         my $symb = '$res->symb()';
1.131     bowersj2 1121:         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
1.155     sakharuk 1122:   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
                   1123:     <message>(mark them then click "next" button) <br /></message>
1.172     bowersj2 1124:     <resource variable="RESOURCES" multichoice="1" suppressEmptySequences='1'>
1.144     bowersj2 1125:       <nextstate>PAGESIZE</nextstate>
1.192     bowersj2 1126:       <filterfunc>return $isProblemOrMap;</filterfunc>
                   1127:       <choicefunc>return $isProblem;</choicefunc>
                   1128:       <valuefunc>return $symb;</valuefunc>
1.132     bowersj2 1129:       </resource>
                   1130:     </state>
                   1131: 
1.155     sakharuk 1132:   <state name="CHOOSE_STUDENTS" title="Choose Students whose assignments you want to print">
1.144     bowersj2 1133:     <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
1.155     sakharuk 1134:     <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
1.147     bowersj2 1135:     <resource variable="RESOURCES" multichoice="1">
                   1136:       <filterfunc>return $isProblem</filterfunc>
1.148     bowersj2 1137:       <mapurl>$map</mapurl>
1.147     bowersj2 1138:       <valuefunc>return $symb</valuefunc>
                   1139:       </resource>
1.155     sakharuk 1140:     <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
1.149     bowersj2 1141:     <choices variable="EMPTY_PAGES">
1.204     sakharuk 1142:       <choice computer='0'>Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)</choice>
                   1143:       <choice computer='1'>Add one empty page/column after each student\'s assignment</choice>
                   1144:       <choice computer='2'>Add two empty pages/column after each student\'s assignment</choice>
                   1145:       <choice computer='3'>Add three empty pages/column after each student\'s assignment</choice>
1.149     bowersj2 1146:       </choices>
1.131     bowersj2 1147:     </state>
                   1148: CHOOSE_STUDENTS
1.121     bowersj2 1149:     }
                   1150: 
                   1151:     # FIXME: That RE should come from a library somewhere.
1.194     sakharuk 1152:     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'}) {    
1.155     sakharuk 1153:         push @{$printChoices}, ["Problems from current subdirectory <b>$subdir</b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
1.131     bowersj2 1154:         
                   1155:         my $f = '$filename';
1.139     bowersj2 1156:         my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
1.155     sakharuk 1157:   <state name="CHOOSE_FROM_SUBDIR" title="Select File(s) from <b><small>$subdir</small></b> to print">
                   1158:     <message>(mark them then click "next" button) <br /></message>
1.138     bowersj2 1159:     <files variable="FILES" multichoice='1'>
1.144     bowersj2 1160:       <nextstate>PAGESIZE</nextstate>
1.138     bowersj2 1161:       <filechoice>return '$subdir';</filechoice>
1.139     bowersj2 1162: CHOOSE_FROM_SUBDIR
                   1163:         
                   1164:         $xmlfrag .= <<'CHOOSE_FROM_SUBDIR';
                   1165:       <filefilter>return $filename =~ 
1.205     bowersj2 1166:            m/\.(problem|exam|quiz|assess|survey|form|library)$/;
1.131     bowersj2 1167:       </filefilter>
1.138     bowersj2 1168:       </files>
1.131     bowersj2 1169:     </state>
                   1170: CHOOSE_FROM_SUBDIR
1.139     bowersj2 1171:         &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.131     bowersj2 1172:     }
                   1173: 
                   1174:     # Generate the first state, to select which resources get printed.
1.155     sakharuk 1175:     Apache::lonhelper::state->new("START", "What do you want to print? Make a choice.");
1.131     bowersj2 1176:     $paramHash = Apache::lonhelper::getParamHash();
1.155     sakharuk 1177:     $paramHash->{MESSAGE_TEXT} = "";
1.131     bowersj2 1178:     Apache::lonhelper::message->new();
                   1179:     $paramHash = Apache::lonhelper::getParamHash();
                   1180:     $paramHash->{'variable'} = 'PRINT_TYPE';
1.137     bowersj2 1181:     $helper->declareVar('PRINT_TYPE');
1.131     bowersj2 1182:     $paramHash->{CHOICES} = $printChoices;
                   1183:     Apache::lonhelper::choices->new();
1.161     bowersj2 1184: 
1.170     sakharuk 1185:     if (($ENV{'request.role.adv'} and &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) or 
                   1186: 	($helper->{VARS}->{'construction'} eq '1')) {
1.161     bowersj2 1187:         $paramHash = Apache::lonhelper::getParamHash();
1.210     sakharuk 1188:         $paramHash->{MESSAGE_TEXT} = "<br /><big><b><i>Next option is available only for advanced users:  </i></b></big>";
1.161     bowersj2 1189:         Apache::lonhelper::message->new();
                   1190:         $paramHash = Apache::lonhelper::getParamHash();
1.162     sakharuk 1191: 	$paramHash->{'variable'} = 'ANSWER_TYPE';   
                   1192: 	$helper->declareVar('ANSWER_TYPE');         
1.161     bowersj2 1193:         $paramHash->{CHOICES} = [
1.163     sakharuk 1194:                                    ['Print without answer', 'yes'],
                   1195:                                    ['Print with answers', 'no'] ];
1.210     sakharuk 1196:         Apache::lonhelper::dropdown->new();
1.161     bowersj2 1197:     }
1.209     sakharuk 1198: 
1.203     sakharuk 1199:     if ($ENV{'request.role.adv'}) {
                   1200:         $paramHash = Apache::lonhelper::getParamHash();
1.210     sakharuk 1201:         $paramHash->{MESSAGE_TEXT} = "<br /><big><b><i>Another option available only for advanced users:  </i></b></big>";
1.203     sakharuk 1202:         Apache::lonhelper::message->new();
                   1203:         $paramHash = Apache::lonhelper::getParamHash();
                   1204: 	$paramHash->{'variable'} = 'LATEX_TYPE';   
                   1205: 	$helper->declareVar('LATEX_TYPE');  
                   1206: 	if ($helper->{VARS}->{'construction'} eq '1') {       
                   1207: 	    $paramHash->{CHOICES} = [
                   1208: 				     ['Print in standard LaTeX mode', 'standard'], 
                   1209: 				     ['Print in LaTeX batchmode', 'batchmode'], ];
                   1210: 	} else {
                   1211: 	    $paramHash->{CHOICES} = [
                   1212: 				     ['Print in LaTeX batchmode', 'batchmode'],
                   1213: 				     ['Print in standard LaTeX mode', 'standard'] ];
                   1214: 	}
1.210     sakharuk 1215:         Apache::lonhelper::dropdown->new();
1.203     sakharuk 1216:     } 
1.209     sakharuk 1217: 
                   1218:     
                   1219:         $paramHash = Apache::lonhelper::getParamHash();
1.214   ! sakharuk 1220:         $paramHash->{MESSAGE_TEXT} = "<br /><big><i>Print with <b>Table of Contents:  </i></b></big>";
1.209     sakharuk 1221:         Apache::lonhelper::message->new();
                   1222:         $paramHash = Apache::lonhelper::getParamHash();
                   1223: 	$paramHash->{'variable'} = 'TABLE_CONTENTS';   
                   1224: 	$helper->declareVar('TABLE_CONTENTS');         
                   1225:         $paramHash->{CHOICES} = [
                   1226:                                    ['No', 'no'],
                   1227:                                    ['Yes', 'yes'] ];
1.210     sakharuk 1228:         Apache::lonhelper::dropdown->new();
1.214   ! sakharuk 1229:         
        !          1230:         $paramHash = Apache::lonhelper::getParamHash();
        !          1231:         $paramHash->{MESSAGE_TEXT} = "<br /><big><i>Print with <b>Index:  </i></b></big>";
        !          1232:         Apache::lonhelper::message->new();
        !          1233:         $paramHash = Apache::lonhelper::getParamHash();
        !          1234: 	$paramHash->{'variable'} = 'TABLE_INDEX';   
        !          1235: 	$helper->declareVar('TABLE_INDEX');         
        !          1236:         $paramHash->{CHOICES} = [
        !          1237:                                    ['No', 'no'],
        !          1238:                                    ['Yes', 'yes'] ];
        !          1239:         Apache::lonhelper::dropdown->new();
1.161     bowersj2 1240: 
1.131     bowersj2 1241:     Apache::lonprintout::page_format_state->new("FORMAT");
                   1242: 
1.144     bowersj2 1243:     # Generate the PAGESIZE state which will offer the user the margin
                   1244:     # choices if they select one column
                   1245:     Apache::lonhelper::state->new("PAGESIZE", "Set Margins");
                   1246:     Apache::lonprintout::page_size_state->new('pagesize', 'FORMAT', 'FINAL');
                   1247: 
                   1248: 
1.131     bowersj2 1249:     $helper->process();
                   1250: 
                   1251:     # MANUAL BAILOUT CONDITION:
                   1252:     # If we're in the "final" state, bailout and return to handler
                   1253:     if ($helper->{STATE} eq 'FINAL') {
                   1254:         return $helper;
                   1255:     }    
1.130     sakharuk 1256: 
1.131     bowersj2 1257:     $r->print($helper->display());
1.130     sakharuk 1258: 
1.131     bowersj2 1259:     Apache::lonhelper::unregisterHelperTags();
1.115     bowersj2 1260: 
                   1261:     untie %hash;
                   1262: 
                   1263:     return OK;
                   1264: }
                   1265: 
1.1       www      1266: 
                   1267: 1;
1.119     bowersj2 1268: 
                   1269: package Apache::lonprintout::page_format_state;
                   1270: 
                   1271: =pod
                   1272: 
1.131     bowersj2 1273: =head1 Helper element: page_format_state
                   1274: 
                   1275: See lonhelper.pm documentation for discussion of the helper framework.
1.119     bowersj2 1276: 
1.131     bowersj2 1277: Apache::lonprintout::page_format_state is an element that gives the 
                   1278: user an opportunity to select the page layout they wish to print 
                   1279: with: Number of columns, portrait/landscape, and paper size. If you 
                   1280: want to change the paper size choices, change the @paperSize array 
                   1281: contents in this package.
1.119     bowersj2 1282: 
1.131     bowersj2 1283: page_format_state is always directly invoked in lonprintout.pm, so there
                   1284: is no tag interface. You actually pass parameters to the constructor.
1.119     bowersj2 1285: 
                   1286: =over 4
                   1287: 
1.131     bowersj2 1288: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
1.119     bowersj2 1289: 
                   1290: =back
                   1291: 
                   1292: =cut
                   1293: 
1.131     bowersj2 1294: use Apache::lonhelper;
1.119     bowersj2 1295: 
                   1296: no strict;
1.131     bowersj2 1297: @ISA = ("Apache::lonhelper::element");
1.119     bowersj2 1298: use strict;
                   1299: 
                   1300: my $maxColumns = 2;
                   1301: my @paperSize = ("Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]", 
                   1302:                  "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
                   1303:                  "A2 [420x594 mm]", "A3 [297x420 mm]", "A4 [210x297 mm]", 
                   1304:                  "A5 [148x210 mm]", "A6 [105x148 mm]" );
                   1305: 
                   1306: # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum |
                   1307: #                   Paper type
                   1308: 
                   1309: sub new { 
1.131     bowersj2 1310:     my $self = Apache::lonhelper::element->new();
1.119     bowersj2 1311: 
1.135     bowersj2 1312:     shift;
                   1313: 
1.131     bowersj2 1314:     $self->{'variable'} = shift;
1.134     bowersj2 1315:     my $helper = Apache::lonhelper::getHelper();
1.135     bowersj2 1316:     $helper->declareVar($self->{'variable'});
1.131     bowersj2 1317:     bless($self);
1.119     bowersj2 1318:     return $self;
                   1319: }
                   1320: 
                   1321: sub render {
                   1322:     my $self = shift;
1.131     bowersj2 1323:     my $helper = Apache::lonhelper::getHelper();
1.119     bowersj2 1324:     my $result = '';
1.131     bowersj2 1325:     my $var = $self->{'variable'};
1.119     bowersj2 1326: 
                   1327:     $result .= <<STATEHTML;
                   1328: 
1.155     sakharuk 1329: <p><big><i><b>What page format do you prefer?</b></i></big></p>
1.119     bowersj2 1330: <table cellpadding="3">
                   1331:   <tr>
1.155     sakharuk 1332:     <td align="center"><b>Page layout</b></td>
                   1333:     <td align="center"><b>Number of columns</b></td>
1.131     bowersj2 1334:     <td align="center"><b>Paper type</b></td>
1.119     bowersj2 1335:   </tr>
                   1336:   <tr>
                   1337:     <td>
1.155     sakharuk 1338:       <input type="radio" name="${var}.layout" value="L" /> Landscape<br />
                   1339:       <input type="radio" name="${var}.layout" value="P" checked='1'  /> Portrait
1.119     bowersj2 1340:     </td>
1.155     sakharuk 1341:     <td align="center">
1.119     bowersj2 1342:       <select name="${var}.cols">
                   1343: STATEHTML
                   1344: 
                   1345:     my $i;
                   1346:     for ($i = 1; $i <= $maxColumns; $i++) {
1.144     bowersj2 1347:         if ($i == 2) {
1.119     bowersj2 1348:             $result .= "<option value='$i' selected>$i</option>\n";
                   1349:         } else {
                   1350:             $result .= "<option value='$i'>$i</option>\n";
                   1351:         }
                   1352:     }
                   1353: 
                   1354:     $result .= "</select></td><td>\n";
                   1355:     $result .= "<select name='${var}.paper'>\n";
                   1356: 
                   1357:     $i = 0;
                   1358:     foreach (@paperSize) {
1.144     bowersj2 1359:         if ($i == 0) {
1.131     bowersj2 1360:             $result .= "<option selected value='$i'>" . $paperSize[$i] . "</option>\n";
1.119     bowersj2 1361:         } else {
1.131     bowersj2 1362:             $result .= "<option value='$i'>" . $paperSize[$i] . "</option>\n";
1.119     bowersj2 1363:         }
                   1364:         $i++;
                   1365:     }
                   1366: 
                   1367:     $result .= "</select></td></tr></table>";
                   1368:     return $result;
1.135     bowersj2 1369: }
                   1370: 
                   1371: sub postprocess {
                   1372:     my $self = shift;
                   1373: 
                   1374:     my $var = $self->{'variable'};
1.136     bowersj2 1375:     my $helper = Apache::lonhelper->getHelper();
1.135     bowersj2 1376:     $helper->{VARS}->{$var} = 
1.136     bowersj2 1377:         $ENV{"form.$var.layout"} . '|' . $ENV{"form.$var.cols"} . '|' .
                   1378:         $ENV{"form.$var.paper"};
1.135     bowersj2 1379:     return 1;
1.119     bowersj2 1380: }
                   1381: 
                   1382: 1;
1.144     bowersj2 1383: 
                   1384: package Apache::lonprintout::page_size_state;
                   1385: 
                   1386: =pod
                   1387: 
                   1388: =head1 Helper element: page_size_state
                   1389: 
                   1390: See lonhelper.pm documentation for discussion of the helper framework.
                   1391: 
                   1392: Apache::lonprintout::page_size_state is an element that gives the 
                   1393: user the opportunity to further refine the page settings if they
                   1394: select a single-column page.
                   1395: 
                   1396: page_size_state is always directly invoked in lonprintout.pm, so there
                   1397: is no tag interface. You actually pass parameters to the constructor.
                   1398: 
                   1399: =over 4
                   1400: 
                   1401: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
                   1402: 
                   1403: =back
                   1404: 
                   1405: =cut
                   1406: 
                   1407: use Apache::lonhelper;
                   1408: 
                   1409: no strict;
                   1410: @ISA = ("Apache::lonhelper::element");
                   1411: use strict;
                   1412: 
                   1413: 
                   1414: 
                   1415: sub new { 
                   1416:     my $self = Apache::lonhelper::element->new();
                   1417: 
                   1418:     shift; # disturbs me (probably prevents subclassing) but works (drops
                   1419:            # package descriptor)... - Jeremy
                   1420: 
                   1421:     $self->{'variable'} = shift;
                   1422:     my $helper = Apache::lonhelper::getHelper();
                   1423:     $helper->declareVar($self->{'variable'});
                   1424: 
                   1425:     # The variable name of the format element, so we can look into 
                   1426:     # $helper->{VARS} to figure out whether the columns are one or two
                   1427:     $self->{'formatvar'} = shift;
                   1428: 
                   1429:     # The state to transition to after selection, or after discovering
                   1430:     # the cols are not set to 1
                   1431:     $self->{NEXTSTATE} = shift;
                   1432:     bless($self);
                   1433:     return $self;
                   1434: }
                   1435: 
                   1436: sub render {
                   1437:     my $self = shift;
                   1438:     my $helper = Apache::lonhelper::getHelper();
                   1439:     my $result = '';
                   1440:     my $var = $self->{'variable'};
                   1441: 
                   1442:     if (defined $self->{ERROR_MSG}) {
                   1443:         $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />';
                   1444:     }
                   1445: 
                   1446:     $result .= <<ELEMENTHTML;
                   1447: 
                   1448: <p>How should the column be formatted?</p>
                   1449: 
                   1450: <table cellpadding='3'>
                   1451:   <tr>
                   1452:     <td align='right'><b>Width</b>:</td>
                   1453:     <td align='left'><input type='text' name='$var.width' value='18' size='4'></td>
                   1454:     <td align='left'>
                   1455:       <select name='$var.widthunit'>
                   1456:         <option>cm</option><option>in</option>
                   1457:       </select>
                   1458:     </td>
                   1459:   </tr>
                   1460:   <tr>
                   1461:     <td align='right'><b>Height</b>:</td>
                   1462:     <td align='left'><input type='text' name="$var.height" value="25.9" size='4'></td>
                   1463:     <td align='left'>
                   1464:       <select name='$var.heightunit'>
                   1465:         <option>cm</option><option>in</option>
                   1466:       </select>
                   1467:     </td>
                   1468:   </tr>
                   1469:   <tr>
                   1470:     <td align='right'><b>Left margin</b>:</td>
                   1471:     <td align='left'><input type='text' name='$var.lmargin' value='-1.5' size='4'></td>
                   1472:     <td align='left'>
1.186     bowersj2 1473:       <select name='$var.lmarginunit'>
1.144     bowersj2 1474:         <option>cm</option><option>in</option>
                   1475:       </select>
                   1476:     </td>
                   1477:   </tr>
                   1478: </table>
                   1479: 
                   1480: <p>Hint: Some instructors like to leave scratch space for the student by
                   1481: making the width much smaller then the width of the page.</p>
                   1482: 
                   1483: ELEMENTHTML
                   1484: 
                   1485:     return $result;
                   1486: }
                   1487: 
                   1488: # If the user didn't select 1 column, skip this state.
                   1489: sub preprocess {
                   1490:     my $self = shift;
                   1491:     my $helper = Apache::lonhelper::getHelper();
                   1492: 
                   1493:     my $format = $helper->{VARS}->{$self->{'formatvar'}};
                   1494:     if (substr($format, 2, 1) ne '1') {
                   1495:         $helper->changeState($self->{NEXTSTATE});
                   1496:     }
                   1497:    
                   1498:     return 1;
                   1499: }
                   1500: 
                   1501: sub postprocess {
                   1502:     my $self = shift;
                   1503: 
                   1504:     my $var = $self->{'variable'};
                   1505:     my $helper = Apache::lonhelper->getHelper();
                   1506:     my $width = $helper->{VARS}->{$var .'.width'} = $ENV{"form.${var}.width"}; 
                   1507:     my $height = $helper->{VARS}->{$var .'.height'} = $ENV{"form.${var}.height"}; 
                   1508:     my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $ENV{"form.${var}.lmargin"}; 
                   1509:     $helper->{VARS}->{$var .'.widthunit'} = $ENV{"form.${var}.widthunit"}; 
                   1510:     $helper->{VARS}->{$var .'.heightunit'} = $ENV{"form.${var}.heightunit"}; 
                   1511:     $helper->{VARS}->{$var .'.lmarginunit'} = $ENV{"form.${var}.lmarginunit"}; 
                   1512: 
                   1513:     my $error = '';
                   1514: 
                   1515:     # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed 
                   1516:     # by an optional period, followed by digits, ending the string
                   1517: 
                   1518:     if ($width !~  /^-?[0-9]+(\.[0-9]*)?$/) {
                   1519:         $error .= "Invalid width; please type only a number.<br />\n";
                   1520:     }
                   1521:     if ($height !~  /^-?[0-9]+(\.[0-9]*)?$/) {
                   1522:         $error .= "Invalid height; please type only a number.<br />\n";
                   1523:     }
                   1524:     if ($lmargin !~  /^-?[0-9]+(\.[0-9]*)?$/) {
                   1525:         $error .= "Invalid left margin; please type only a number.<br />\n";
                   1526:     }
                   1527: 
                   1528:     if (!$error) {
                   1529:         Apache::lonhelper::getHelper()->changeState($self->{NEXTSTATE});
                   1530:         return 1;
                   1531:     } else {
                   1532:         $self->{ERROR_MSG} = $error;
                   1533:         return 0;
                   1534:     }
                   1535: }
                   1536: 
                   1537: 
1.119     bowersj2 1538: 
1.1       www      1539: __END__
1.6       sakharuk 1540: 

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