Annotation of loncom/interface/lonprintout.pm, revision 1.196
1.1 www 1: # The LearningOnline Network
2: # Printout
3: #
1.196 ! sakharuk 4: # $Id: lonprintout.pm,v 1.195 2003/06/24 14:56:16 sakharuk Exp $
1.11 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 www 28: # (Internal Server Error Handler
29: #
30: # (Login Screen
31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
32: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
33: #
34: # 3/1/1 Gerd Kortemeyer)
35: #
36: # 3/1 Gerd Kortemeyer
37: #
1.3 sakharuk 38: # 9/17 Alex Sakharuk
39: #
1.1 www 40: package Apache::lonprintout;
41:
42: use strict;
1.10 albertel 43: use Apache::Constants qw(:common :http);
1.2 sakharuk 44: use Apache::lonxml;
45: use Apache::lonnet;
1.54 sakharuk 46: use Apache::loncommon;
1.13 sakharuk 47: use Apache::inputtags;
1.54 sakharuk 48: use Apache::grades;
1.13 sakharuk 49: use Apache::edit;
1.5 sakharuk 50: use Apache::File();
1.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;
289: $result =~ s/&(pi|\#960);/\$\\pi \$/g;
290: $result =~ s/&(rho|\#961);/\$\\rho \$/g;
291: $result =~ s/&(sigma|\#963);/\$\\sigma \$/g;
292: $result =~ s/&(tau|\#964);/\$\\tau \$/g;
293: $result =~ s/&(upsilon|\#965);/\$\\upsilon \$/g;
294: $result =~ s/&(phi|\#966);/\$\\phi \$/g;
295: $result =~ s/&(chi|\#967);/\$\\chi \$/g;
296: $result =~ s/&(psi|\#968);/\$\\psi \$/g;
297: $result =~ s/&(omega|\#969);/\$\\omega \$/g;
298: $result =~ s/&(Gamma|\#915);/\$\\Gamma \$/g;
299: $result =~ s/&(Delta|\#916);/\$\\Delta \$/g;
300: $result =~ s/&(Theta|\#920);/\$\\Theta \$/g;
301: $result =~ s/&(Lambda|\#923);/\$\\Lambda \$/g;
302: $result =~ s/&(Xi|\#926);/\$\\Xi \$/g;
303: $result =~ s/&(Pi|\#928);/\$\\Pi \$/g;
304: $result =~ s/&(Sigma|\#931);/\$\\Sigma \$/g;
305: $result =~ s/&(Upsilon|\#933);/\$\\Upsilon \$/g;
306: $result =~ s/&(Phi|\#934);/\$\\Phi \$/g;
307: $result =~ s/&(Psi|\#936);/\$\\Psi \$/g;
308: $result =~ s/&(Omega|\#937);/\$\\Omega \$/g;
1.37 sakharuk 309: return $result;
310: }
1.41 sakharuk 311:
312:
1.177 sakharuk 313: sub page_format {
1.140 sakharuk 314: #
315: #Correspondence between $papersize variable and real paper format:
316: # 0 - "Letter [8 1/2x11 in]"
317: # 1 - "Legal [8 1/2x14 in]"
318: # 2 - "Ledger/Tabloid [11x17 in]"
319: # 3 - "Executive [7 1/2x10 in]"
320: # 4 - "A2 [420x594 mm]"
321: # 5 - "A3 [297x420 mm]"
322: # 6 - "A4 [210x297 mm]"
323: # 7 - "A5 [148x210 mm]"
324: # 8 - "A6 [105x148 mm]"
325: #
326: my ($papersize,$layout,$numberofcolumns) = @_;
327: my ($textwidth,$textheight,$oddoffset,$evenoffset) = (0,0,0,0);
328: if ($papersize eq '0') {
329: if ($layout eq 'book') {
330: if ($numberofcolumns == 1) {
1.190 sakharuk 331: $textwidth = '7.1 in'; #'18 cm';
332: $textheight = '10.2 in'; #'25.9 cm';
1.140 sakharuk 333: $oddoffset = '-0.57 in';
334: $evenoffset = '-0.57 in';
335: } elsif ($numberofcolumns == 2) {
1.190 sakharuk 336: $textwidth = '3.66 in'; #'93 mm';
337: $textheight = '10.2 in'; #'25.9 cm';
1.140 sakharuk 338: $oddoffset = '-0.57 in';
339: $evenoffset = '-0.57 in';
340: }
341: } elsif ($layout eq 'album') {
342: if ($numberofcolumns eq '1') {
343: $textwidth = '8.8 in';
344: $textheight = '6.8 in';
345: $oddoffset = '-40 pt';
346: $evenoffset = '-60 pt';
347: } elsif ($numberofcolumns == 2) {
348: $textwidth = '4.2 in';
349: $textheight = '6.8 in';
350: $oddoffset = '-40 pt';
351: $evenoffset = '-60 pt';
352: }
353: }
354: # } elsif($papersize eq '1') {
355: # } elsif($papersize eq '2') {
356: # } elsif($papersize eq '3'/) {
357: } elsif($papersize eq '6') {
358: if ($layout eq 'book') {
359: if ($numberofcolumns == 1) {
360: $textwidth = '18 cm';
361: $textheight = '28 cm';
362: $oddoffset = '-0.57 in';
363: $evenoffset = '-0.57 in';
364: } elsif ($numberofcolumns == 2) {
365: $textwidth = '96 mm';
366: $textheight = '2 cm';
367: $oddoffset = '-0.57 in';
368: $evenoffset = '-0.57 in';
369: }
370: } elsif ($layout eq 'album') {
371: if ($numberofcolumns eq '1') {
372: $textwidth = '8.5 in';
373: $textheight = '7.7 in';
374: $oddoffset = '-40 pt';
375: $evenoffset = '-60 pt';
376: } elsif ($numberofcolumns == 2) {
377: $textwidth = '3.9 in';
378: $textheight = '7.7 in';
379: $oddoffset = '-40 pt';
380: $evenoffset = '-60 pt';
381: }
382: }
383: # } elsif($papersize eq '5') {
384: # } elsif($papersize eq '4') {
385: # } elsif($papersize eq '7') {
386: # } elsif($papersize eq '8') {
1.76 sakharuk 387: }
1.140 sakharuk 388: return $textwidth,$textheight,$oddoffset,$evenoffset;
389: }
1.76 sakharuk 390:
391:
1.126 albertel 392: sub get_name {
393: my ($uname,$udom)=@_;
394: if (!defined($uname)) { $uname=$ENV{'user.name'}; }
395: if (!defined($udom)) { $uname=$ENV{'user.domain'}; }
396: my $plainname=&Apache::loncommon::plainname($uname,$udom);
397: if ($plainname=~/^\s*$/) { $plainname=$uname; }
398: return &Apache::lonxml::latex_special_symbols($plainname,undef,undef,
399: 'header');
400: }
401:
1.177 sakharuk 402:
1.76 sakharuk 403: sub page_format_transformation {
1.104 sakharuk 404: my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment) = @_;
405: my ($textwidth,$textheight,$oddoffset,$evenoffset);
1.101 sakharuk 406: $assignment=~s/_/ /g;
1.104 sakharuk 407: if ($numberofcolumns != 1) {
408: ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns);
409: } else {
410: ($textwidth,$textheight,$oddoffset,$evenoffset) = ($ENV{'form.width'},$ENV{'form.height'},$ENV{'form.leftmargin'},$ENV{'form.leftmargin'});
411: }
1.126 albertel 412: my $name = &get_name();
413: if ($name =~ /^\s*$/) {
414: $name=&Apache::lonxml::latex_special_symbols($ENV{'user.name'},undef,
415: undef,'header');
416: }
1.113 sakharuk 417: my $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'','','header');
1.140 sakharuk 418: if ($layout eq 'album') {
419: $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}\\setlength{\\topmargin}{200pt}\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\parindent}{20pt}\\setlength{\\marginparwidth}{90pt}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm} \\begin{document}\\setcounter{page}{1}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fbox{\\textbf{$name}} \\hfill $courseidinfo} \\vskip 5 mm /;
420: } elsif ($layout eq 'book') {
421: if ($choice ne 'All class print') {
1.190 sakharuk 422: $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 423: } else {
1.190 sakharuk 424: $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 425: }
426: }
427: return $text;
428: }
429:
430:
1.33 sakharuk 431: sub page_cleanup {
432: my $result = shift;
1.65 sakharuk 433:
434: $result =~ m/\\end{document}(\d*)$/;
1.34 sakharuk 435: my $number_of_columns = $1;
1.33 sakharuk 436: my $insert = '{';
1.34 sakharuk 437: for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1.33 sakharuk 438: $insert .= '}';
1.65 sakharuk 439: $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
1.34 sakharuk 440: $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
441: return $result,$number_of_columns;
1.7 sakharuk 442: }
1.5 sakharuk 443:
1.3 sakharuk 444:
1.60 sakharuk 445: sub details_for_menu {
446:
447: my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}};
448: my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'});
1.63 albertel 449: my ($map,$id,$resource)=split(/___/,$symbolic);
1.123 albertel 450: $map=&Apache::lonnet::clutter($map);
1.102 sakharuk 451: my $name_of_sequence;
1.123 albertel 452: $name_of_sequence = $hash{'title_'.$hash{'ids_'.$map}};
1.63 albertel 453: if ($name_of_sequence =~ /^\s*$/) {
1.123 albertel 454: $map =~ m|([^/]+)$|;
455: $name_of_sequence = $1;
1.63 albertel 456: }
1.123 albertel 457: my $name_of_map = $hash{'title_'.$hash{'ids_'.&Apache::lonnet::clutter($ENV{'request.course.uri'})}};
1.63 albertel 458: if ($name_of_map =~ /^\s*$/) {
1.123 albertel 459: $ENV{'request.course.uri'} =~ m|([^/]+)$|;
460: $name_of_map = $1;
461: }
1.63 albertel 462: return ($name_of_resourse,$name_of_sequence,$name_of_map);
1.60 sakharuk 463:
1.76 sakharuk 464: }
465:
466:
467: sub latex_corrections {
468:
469: my ($number_of_columns,$result) = @_;
470:
1.185 sakharuk 471: # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
1.76 sakharuk 472: $result =~ s/\$number_of_columns/$number_of_columns/g;
1.91 sakharuk 473: $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/;
474: $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
475: $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g;
1.76 sakharuk 476: #-- LaTeX corrections
477: my $first_comment = index($result,'<!--',0);
478: while ($first_comment != -1) {
479: my $end_comment = index($result,'-->',$first_comment);
480: substr($result,$first_comment,$end_comment-$first_comment+3) = '';
481: $first_comment = index($result,'<!--',$first_comment);
482: }
483: $result =~ s/^\s+$//gm; #remove empty lines
1.94 sakharuk 484: $result =~ s/(\s)(\s+)/$1/g; #removes more than one empty space
1.76 sakharuk 485: $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
486: $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
487: $result =~ s/{\\par }\s*\\\\/\\\\/gm;
488: $result =~ s/\\\\\s+\[/ \[/g;
489: $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
490: #conversion of html characters to LaTeX equivalents
491: if ($result =~ m/&(\w+|#\d+);/) {
492: $result = &character_chart($result);
493: }
494: $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
495: $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
496:
497: return $result;
1.60 sakharuk 498: }
499:
1.3 sakharuk 500:
1.177 sakharuk 501: sub output_data {
1.184 sakharuk 502: my ($r,$helper,$rparmhash) = @_;
503: my %parmhash = %$rparmhash;
1.187 www 504: my $bodytag=&Apache::loncommon::bodytag('Preparing Printout');
1.140 sakharuk 505: $r->print(<<ENDPART);
506: <html>
507: <head>
508: <title>LON-CAPA output for printing</title>
509: </head>
1.187 www 510: $bodytag
511: Please stand by while processing your print request, this may take some time ...
1.140 sakharuk 512: ENDPART
513:
514: my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
515: my ($result,$selectionmade) = ('','');
516: my $number_of_columns = 1; #used only for pages to determine the width of the cell
517: my @temporary_array=split /\|/,$format_from_helper;
518: my ($laystyle,$numberofcolumns,$papersize)=@temporary_array;
519: if ($laystyle eq 'L') {
520: $laystyle='album';
521: } else {
522: $laystyle='book';
523: }
1.177 sakharuk 524: my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$laystyle,$numberofcolumns);
1.140 sakharuk 525: my $assignment = $ENV{'form.assignment'};
526: my $LaTeXwidth;
1.190 sakharuk 527: if ($textwidth=~/(\d+\.?\d*)\s*cm/) {
1.140 sakharuk 528: $LaTeXwidth = $1*10;
1.190 sakharuk 529: } elsif ($textwidth=~/(\d+\.?\d*)\s*mm/) {
1.140 sakharuk 530: $LaTeXwidth = $1;
1.190 sakharuk 531: } elsif ($textwidth=~/(\d+\.?\d*)\s*in/) {
1.140 sakharuk 532: $LaTeXwidth = $1*25.4;
533: }
534: $LaTeXwidth.=' mm';
1.153 sakharuk 535:
1.140 sakharuk 536: if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {
1.143 sakharuk 537: #-- single document - problem, page, html, xml, ...
538: my $currentURL;
1.162 sakharuk 539: if ($helper->{'VARS'}->{'construction'} ne '1') {
1.185 sakharuk 540: #prints published resource
1.153 sakharuk 541: $currentURL=$helper->{'VARS'}->{'postdata'};
1.143 sakharuk 542: } else {
1.185 sakharuk 543: #prints resource from the construction space
1.162 sakharuk 544: $currentURL=$helper->{'VARS'}->{'filename'};
545: $currentURL=~s/\/home\//\/~/;
546: $currentURL=~s/public_html\///;
1.143 sakharuk 547: }
1.140 sakharuk 548: $selectionmade = 1;
1.143 sakharuk 549: if ($currentURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
1.162 sakharuk 550: my %moreenv;
551: $moreenv{'request.filename'}=$currentURL;
1.166 albertel 552: my %form;
553: $form{'grade_target'}='tex';
554: $form{'textwidth'}=$LaTeXwidth;
1.169 albertel 555: my $rndseed=time;
556: $form{'rndseed'}=$rndseed;
1.162 sakharuk 557: &Apache::lonnet::appenv(%moreenv);
1.168 albertel 558: my $texversion=&Apache::lonnet::ssi($currentURL,%form);
1.165 sakharuk 559: &Apache::lonnet::delenv('form.counter');
1.166 albertel 560: &Apache::lonnet::delenv('request.filename');
1.163 sakharuk 561: if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
1.166 albertel 562: my %form;
563: $form{'grade_target'}='answer';
1.167 albertel 564: $form{'answer_output_mode'}='tex';
1.169 albertel 565: $form{'rndseed'}=$rndseed;
1.166 albertel 566: my $answer=&Apache::lonnet::ssi($currentURL,%form);
1.170 sakharuk 567: $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
1.163 sakharuk 568: }
1.162 sakharuk 569: $result .= $texversion;
570: if ($currentURL=~m/\.page\s*$/) {
571: ($result,$number_of_columns) = &page_cleanup($result);
572: }
573: } else {
1.140 sakharuk 574: # $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: ';
575: # if ($ENV{'form.url'}=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) {
576: # $result.=$1;
577: # } else {
578: # $result.=$ENV{'form.url'};
579: # }
580: # $result.=' \end{document}'
1.162 sakharuk 581: }
1.142 sakharuk 582: } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or
583: ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
584: ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')) {
1.141 sakharuk 585: #-- produce an output string
1.193 sakharuk 586: my %form=();
587: $form{'grade_target'}='tex';
588: $form{'textwidth'}=$LaTeXwidth;
589: $form{'problem_split'}=$parmhash{'problem_stream_switch'};
1.141 sakharuk 590: my $flag_latex_header_remove = 'NO';
591: my $flag_page_in_sequence = 'NO';
592: my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
1.193 sakharuk 593: my $prevassignment='';
1.141 sakharuk 594: for (my $i=0;$i<=$#master_seq;$i++) {
595: $master_seq[$i]=~/___\d+___(.*)$/;
596: my $urlp='/res/'.$1;
597: if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') {
1.142 sakharuk 598: $selectionmade = 2;
599: } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {
600: $selectionmade = 3;
601: } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') {
602: $selectionmade = 4;
1.141 sakharuk 603: }
1.166 albertel 604: $form{'symb'}=$master_seq[$i];
1.193 sakharuk 605: $master_seq[$i]=~/\/([^\/]+)\.sequence_/;
606: my $assignment=' '.$1.' ';
1.141 sakharuk 607: #&Apache::lonnet::logthis("Trying to get $urlp with symb $master_seq[$i]");
1.166 albertel 608: my $texversion=&Apache::lonnet::ssi($urlp,%form);
1.141 sakharuk 609: if ($urlp=~/\.page$/) {
610: ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
611: if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;}
612: $texversion =~ s/\\end{document}\d*/\\end{document}/;
613: $flag_page_in_sequence = 'YES';
614: }
615: if ($flag_latex_header_remove ne 'NO') {
616: $texversion = &latex_header_footer_remove($texversion);
617: } else {
618: $texversion =~ s/\\end{document}//;
1.171 sakharuk 619: }
620: if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
621: my %form;
622: $form{'grade_target'}='answer';
623: $form{'answer_output_mode'}='tex';
624: my $answer=&Apache::lonnet::ssi($urlp,%form);
625: $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
1.141 sakharuk 626: }
1.193 sakharuk 627: # $result .= $texversion;
628: if (($selectionmade == 4) and ($assignment ne $prevassignment) and ($i>1)) {
629: my $name = &get_name();
630: if ($name =~ /^\s*$/) {
631: $name=&Apache::lonxml::latex_special_symbols($ENV{'user.name'},undef,
632: undef,'header');
633: }
634: my $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'','','header');
635: $prevassignment=$assignment;
636: $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}} - '.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip -5 mm ';
637: }
638: $result .= $texversion;
1.141 sakharuk 639: $flag_latex_header_remove = 'YES';
640: }
641: &Apache::lonnet::delenv('form.counter');
642: if ($flag_page_in_sequence eq 'YES') {$result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;}
643: $result .= '\end{document}';
1.150 sakharuk 644: } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') {
645: #-- prints assignments for whole class or for selected students
646: $selectionmade=5;
647: my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'};
648: my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
649: #loop over students
650: my $flag_latex_header_remove = 'NO';
651: my %moreenv;
652: $moreenv{'form.textwidth'}=$LaTeXwidth;
653: &Apache::lonnet::appenv(%moreenv);
654: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1);
655: foreach my $person (@students) {
656: my $current_output = '';
1.140 sakharuk 657: # my ($usersection,$username,$userdomain) = split /:/,$person;
1.150 sakharuk 658: my ($username,$userdomain) = split /:/,$person;
659: my $fullname = &get_name($username,$userdomain);
1.196 ! sakharuk 660:
! 661: if ($parmhash{'anonimous_quiz'}=~/yes/) {$fullname=' ';} #put here something reasonable for annonimous exams or quiz
1.150 sakharuk 662: #goes through all resources, checks if they are available for current student, and produces output
663: foreach my $curresline (@master_seq) {
664: if ($curresline=~ m/\.(problem|exam|quiz|assess|survey|form|library)$/) {
665: my ($map,$id,$res_url) = split(/___/,$curresline);
666: if (&Apache::lonnet::allowed('bre',$res_url)) {
667: my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,
668: $ENV{'request.course.id'},'tex');
669: if ($flag_latex_header_remove eq 'YES') {
670: $rendered = &latex_header_footer_remove($rendered);
671: } else {
672: $rendered =~ s/\\end{document}//;
1.173 sakharuk 673: }
674: if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
675: my %form;
676: $form{'answer_output_mode'}='tex';
1.193 sakharuk 677: my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$ENV{'request.course.id'},%form);
1.173 sakharuk 678: $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/;
1.150 sakharuk 679: }
680: $current_output .= $rendered;
681: }
682: $flag_latex_header_remove = 'YES';
683: }
684: }
685: my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
686: if ($current_output=~/\\documentclass/) {
1.180 sakharuk 687: $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 688: } else {
689: my $blanspages = '';
690: for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blanspages.='\clearpage\strut\clearpage';}
1.181 sakharuk 691: $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 692: }
693: $result .= $current_output;
694: &Apache::lonnet::delenv('form.counter');
695: &Apache::lonxml::init_counter();
696: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
697: 'last student '.$fullname);
698: }
699: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
700: $result .= '\end{document}';
701: &Apache::lonnet::delenv('form.textwidth');
1.151 sakharuk 702: } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') {
703: #prints selected problems from the subdirectory
704: $selectionmade = 6;
705: my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
1.154 sakharuk 706: @list_of_files=sort @list_of_files;
1.175 sakharuk 707: my $flag_latex_header_remove = 'NO';
708: my $rndseed=time;
1.151 sakharuk 709: for (my $i=0;$i<=$#list_of_files;$i++) {
1.152 sakharuk 710: my $urlp = $list_of_files[$i];
711: if ($urlp=~/\//) {
1.166 albertel 712: my %form;
713: $form{'grade_target'}='tex';
714: $form{'textwidth'}=$LaTeXwidth;
1.175 sakharuk 715: $form{'rndseed'}=$rndseed;
1.152 sakharuk 716: if ($urlp =~ m|/home/([^/]+)/public_html|) {
717: $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
718: } else {
719: $urlp =~ s|^/home/httpd/html||;
720: }
1.166 albertel 721: my $texversion=&Apache::lonnet::ssi($urlp,%form);
1.174 sakharuk 722: if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
723: my %form;
724: $form{'grade_target'}='answer';
725: $form{'answer_output_mode'}='tex';
726: $form{'rndseed'}=$rndseed;
727: my $answer=&Apache::lonnet::ssi($urlp,%form);
728: $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
729: }
1.151 sakharuk 730: #this chunck is responsible for printing the path to problem
1.152 sakharuk 731: my $newurlp = '';
732: my $HowMany = length($urlp)*2;
733: if ($HowMany > $LaTeXwidth) {
734: my @temporrary = split '/',$urlp;
735: my $HowManyNew = 0;
736: for (my $ii=0;$ii<=$#temporrary;$ii++) {
737: if ($temporrary[$ii] ne '') {
738: $HowManyNew += length($temporrary[$ii])*2;
739: if ($HowManyNew < $LaTeXwidth ) {
740: $newurlp .= '/'.$temporrary[$ii];
741: } else {
742: $HowManyNew = 0;
743: $newurlp .= '|\vskip -1 mm \noindent \verb|';
744: $ii--;
745: }
746: }
747: }
748: }
749: $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/;
750: if ($flag_latex_header_remove ne 'NO') {
751: $texversion = &latex_header_footer_remove($texversion);
752: } else {
753: $texversion =~ s/\\end{document}//;
754: }
755: $result .= $texversion;
756: }
757: $flag_latex_header_remove = 'YES';
1.151 sakharuk 758: }
1.175 sakharuk 759: if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\typeout)/ RANDOM SEED IS $rndseed $1/;}
1.152 sakharuk 760: $result .= '\end{document}';
1.140 sakharuk 761: }
762: #-------------------------------------------------------- corrections for the different page formats
1.177 sakharuk 763: $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'});
1.140 sakharuk 764: $result = &latex_corrections($number_of_columns,$result);
1.190 sakharuk 765: #changes page's parameters for the one column output
1.195 sakharuk 766: if ($numberofcolumns == 1) {
767: $result =~ s/\\textwidth= 9cm/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
768: $result =~ s/\\textheight 25\.9cm/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
769: $result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
770: $result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
771: }
1.140 sakharuk 772: #-- writing .tex file in prtspool
773: my $temp_file;
774: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
775: unless ($temp_file = Apache::File->new('>'.$filename)) {
776: $r->log_error("Couldn't open $filename for output $!");
777: return SERVER_ERROR;
778: }
779: print $temp_file $result;
780:
1.143 sakharuk 781: #<meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns&$selectionmade">
1.140 sakharuk 782: $r->print(<<FINALEND);
783: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns&$selectionmade">
784: </body>
785: </html>
786: FINALEND
787: }
788:
789:
790:
1.3 sakharuk 791: sub handler {
792:
793: my $r = shift;
1.131 bowersj2 794: my $helper;
1.114 bowersj2 795:
1.150 sakharuk 796: # my $loaderror=&Apache::lonnet::overloaderror($r);
797: # if ($loaderror) { return $loaderror; }
798: # $loaderror=
799: # &Apache::lonnet::overloaderror($r,
800: # $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
801: # if ($loaderror) { return $loaderror; }
1.67 www 802:
1.177 sakharuk 803: my $result = printHelper($r);
804: if (!ref($result)) {
805: return $result;
1.60 sakharuk 806: }
1.177 sakharuk 807: $helper = $result;
808:
809: # my $key;
810: # foreach $key (keys %{$helper->{'VARS'}}) {
811: # $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'<-<br />');
812: # }
813: # return OK;
1.184 sakharuk 814:
815: my %parmhash=&Apache::lonnet::coursedescription($ENV{'request.course.id'});
816:
817:
818: &output_data($r,$helper,\%parmhash);
1.2 sakharuk 819: return OK;
1.60 sakharuk 820: }
1.2 sakharuk 821:
1.131 bowersj2 822: use Apache::lonhelper;
1.130 sakharuk 823:
1.131 bowersj2 824: sub printHelper {
1.115 bowersj2 825: my $r = shift;
826:
827: if ($ENV{'request.course.id'}) {
1.131 bowersj2 828: my $fn=$ENV{'request.course.fn'};
829: tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640);
1.115 bowersj2 830: }
831:
832: if ($r->header_only) {
1.131 bowersj2 833: if ($ENV{'browser.mathml'}) {
834: $r->content_type('text/xml');
835: } else {
836: $r->content_type('text/html');
837: }
838: $r->send_http_header;
839: return OK;
1.115 bowersj2 840: }
841:
1.131 bowersj2 842: # Send header, nocache
1.115 bowersj2 843: if ($ENV{'browser.mathml'}) {
1.131 bowersj2 844: $r->content_type('text/xml');
1.115 bowersj2 845: } else {
1.131 bowersj2 846: $r->content_type('text/html');
1.115 bowersj2 847: }
848: &Apache::loncommon::no_cache($r);
849: $r->send_http_header;
850: $r->rflush();
851:
1.131 bowersj2 852: # Unfortunately, this helper is so complicated we have to
853: # write it by hand
854:
855: Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING});
856:
1.176 bowersj2 857: my $helper = Apache::lonhelper::helper->new("Printing Helper");
1.146 bowersj2 858: $helper->declareVar('symb');
1.156 bowersj2 859: $helper->declareVar('postdata');
860: $helper->declareVar('filename');
861: $helper->declareVar('construction');
1.178 sakharuk 862: $helper->declareVar('assignment');
1.131 bowersj2 863:
864: # This will persistently load in the data we want from the
865: # very first screen.
1.156 bowersj2 866: # Detect whether we're coming from construction space
867: if ($ENV{'form.postdata'} =~ /http:\/\// ) {
1.188 bowersj2 868: $ENV{'form.postdata'} =~ /http:\/\/[^\/]+\/~([^\/]+)\/(.*)/;
1.156 bowersj2 869: $helper->{VARS}->{'filename'} = "/home/$1/public_html/$2";
870: $helper->{VARS}->{'construction'} = 1;
871: } else {
872: if ($ENV{'form.postdata'}) {
873: $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($ENV{'form.postdata'});
874: }
875: if ($ENV{'form.symb'}) {
876: $helper->{VARS}->{'symb'} = $ENV{'form.symb'};
877: }
878: if ($ENV{'form.url'}) {
879: $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
880: }
1.157 bowersj2 881: }
1.156 bowersj2 882:
1.146 bowersj2 883: if ($ENV{'form.symb'}) {
884: $helper->{VARS}->{'symb'} = $ENV{'form.symb'};
885: }
886: if ($ENV{'form.url'}) {
1.140 sakharuk 887: $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'});
1.153 sakharuk 888:
1.140 sakharuk 889: }
1.146 bowersj2 890:
1.115 bowersj2 891: my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu;
1.178 sakharuk 892: if ($sequenceTitle ne '') {$helper->{VARS}->{'assignment'}=$sequenceTitle;}
1.140 sakharuk 893:
1.156 bowersj2 894:
1.146 bowersj2 895: # Extract map
896: my $symb = $helper->{VARS}->{'symb'};
1.156 bowersj2 897: my ($map, $id, $url);
898: my $subdir;
899:
900: # Get the resource name from construction space
901: if ($helper->{VARS}->{'construction'}) {
902: $resourceTitle = substr($helper->{VARS}->{'filename'},
903: rindex($helper->{VARS}->{'filename'}, '/')+1);
904: $subdir = substr($helper->{VARS}->{'filename'},
905: 0, rindex($helper->{VARS}->{'filename'}, '/') + 1);
906: } else {
907: ($map, $id, $url) = split(/___/, $symb);
908: $helper->{VARS}->{'postdata'} = Apache::lonnet::clutter($url);
1.146 bowersj2 909:
1.156 bowersj2 910: if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
911: my $url = $helper->{VARS}->{'postdata'};
912: $resourceTitle = substr($url, rindex($url, '/') + 1);
913: }
914: $subdir = &Apache::lonnet::filelocation("", $url);
1.128 bowersj2 915: }
1.115 bowersj2 916:
1.192 bowersj2 917: my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
918:
1.131 bowersj2 919: Apache::lonhelper::registerHelperTags();
1.119 bowersj2 920:
1.131 bowersj2 921: # "Delete everything after the last slash."
1.119 bowersj2 922: $subdir =~ s|/[^/]+$||;
1.162 sakharuk 923: if (not $helper->{VARS}->{'construction'}) {
924: $subdir='/home/httpd/html/res/'.$subdir;
1.153 sakharuk 925: }
1.189 bowersj2 926: # "Remove all duplicate slashes."
927: $subdir =~ s|/+|/|g;
1.119 bowersj2 928:
1.131 bowersj2 929: # What can be printed is a very dynamic decision based on
930: # lots of factors. So we need to dynamically build this list.
931: # To prevent security leaks, states are only added to the wizard
932: # if they can be reached, which ensures manipulating the form input
933: # won't allow anyone to reach states they shouldn't have permission
934: # to reach.
935:
936: # printChoices is tracking the kind of printing the user can
937: # do, and will be used in a choices construction later.
938: # In the meantime we will be adding states and elements to
939: # the helper by hand.
940: my $printChoices = [];
941: my $paramHash;
1.130 sakharuk 942:
1.156 bowersj2 943: if ($resourceTitle) {
944: push @{$printChoices}, ["<b>$resourceTitle</b> (prints what you just saw on the screen)", 'current_document', 'PAGESIZE'];
945: }
946:
1.187 www 947: # $r->print($helper->{VARS}->{'postdata'});
1.130 sakharuk 948:
1.131 bowersj2 949: # If we're in a sequence...
1.162 sakharuk 950: if ($helper->{'VARS'}->{'construction'} ne '1') {
1.131 bowersj2 951: # Allow problems from sequence
1.155 sakharuk 952: push @{$printChoices}, ["Problem(s) from <b>$sequenceTitle</b>", 'map_problems', 'CHOOSE_PROBLEMS'];
1.131 bowersj2 953: # Allow all resources from sequence
1.155 sakharuk 954: push @{$printChoices}, ["Everything (problem(s), page(s), html/xml file(s)) from <b>$sequenceTitle</b>", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
1.130 sakharuk 955:
1.192 bowersj2 956: my $isProblem = '$res->is_problem()';
957: $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
1.131 bowersj2 958: my $isProblemOrMap = '$res->is_problem() || $res->is_map()';
1.192 bowersj2 959: my $isNotMap = '!$res->is_map()';
960: $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
961: my $symb = '$res->symb()';
1.131 bowersj2 962: my $helperFragment = <<HELPERFRAGMENT;
1.155 sakharuk 963: <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">
964: <message>(mark them then click "next" button) <br /></message>
1.144 bowersj2 965: <resource variable="RESOURCES" multichoice="1" toponly='1'>
966: <nextstate>PAGESIZE</nextstate>
1.192 bowersj2 967: <filterfunc>return $isProblem;</filterfunc>
1.131 bowersj2 968: <mapurl>$map</mapurl>
1.192 bowersj2 969: <valuefunc>return $symb;</valuefunc>
1.131 bowersj2 970: </resource>
971: </state>
972:
1.155 sakharuk 973: <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">
974: <message>(mark them then click "next" button) <br /></message>
1.144 bowersj2 975: <resource variable="RESOURCES" multichoice="1" toponly='1'>
976: <nextstate>PAGESIZE</nextstate>
1.145 bowersj2 977: <filterfunc>return $isNotMap;</filterfunc>
1.131 bowersj2 978: <mapurl>$map</mapurl>
1.192 bowersj2 979: <valuefunc>return $symb;</valuefunc>
1.131 bowersj2 980: </resource>
981: </state>
982: HELPERFRAGMENT
1.121 bowersj2 983:
1.131 bowersj2 984: &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
1.121 bowersj2 985: }
986:
987: # If the user is priviledged, allow them to print all
988: # problems in the course, optionally for selected students
1.131 bowersj2 989: 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 990: push @{$printChoices}, ['<b>Problems</b> in this course', 'all_problems', 'ALL_PROBLEMS'];
1.131 bowersj2 991: push @{$printChoices}, ["Problems from <b>$sequenceTitle</b> for selected students", 'problems_for_students', 'CHOOSE_STUDENTS'];
992:
1.192 bowersj2 993: my $isProblem = '$res->is_problem()';
994: $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
995: my $isProblemOrMap = '($res->is_problem() || $res->is_map())';
996: $isProblemOrMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
997: my $symb = '$res->symb()';
1.131 bowersj2 998: &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
1.155 sakharuk 999: <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
1000: <message>(mark them then click "next" button) <br /></message>
1.172 bowersj2 1001: <resource variable="RESOURCES" multichoice="1" suppressEmptySequences='1'>
1.144 bowersj2 1002: <nextstate>PAGESIZE</nextstate>
1.192 bowersj2 1003: <filterfunc>return $isProblemOrMap;</filterfunc>
1004: <choicefunc>return $isProblem;</choicefunc>
1005: <valuefunc>return $symb;</valuefunc>
1.132 bowersj2 1006: </resource>
1007: </state>
1008:
1.155 sakharuk 1009: <state name="CHOOSE_STUDENTS" title="Choose Students whose assignments you want to print">
1.144 bowersj2 1010: <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
1.155 sakharuk 1011: <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
1.147 bowersj2 1012: <resource variable="RESOURCES" multichoice="1">
1013: <filterfunc>return $isProblem</filterfunc>
1.148 bowersj2 1014: <mapurl>$map</mapurl>
1.147 bowersj2 1015: <valuefunc>return $symb</valuefunc>
1016: </resource>
1.155 sakharuk 1017: <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
1.149 bowersj2 1018: <choices variable="EMPTY_PAGES">
1.193 sakharuk 1019: <choice computer='0'>Start each student\'s assignment on a new page (add a pagefeed after each assignment)</choice>
1020: <choice computer='1'>Add one empty page after each student\'s assignment</choice>
1021: <choice computer='2'>Add two empty pages after each student\'s assignment</choice>
1.149 bowersj2 1022: </choices>
1.131 bowersj2 1023: </state>
1024: CHOOSE_STUDENTS
1.121 bowersj2 1025: }
1026:
1027: # FIXME: That RE should come from a library somewhere.
1.194 sakharuk 1028: 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 1029: push @{$printChoices}, ["Problems from current subdirectory <b>$subdir</b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
1.131 bowersj2 1030:
1031: my $f = '$filename';
1.139 bowersj2 1032: my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
1.155 sakharuk 1033: <state name="CHOOSE_FROM_SUBDIR" title="Select File(s) from <b><small>$subdir</small></b> to print">
1034: <message>(mark them then click "next" button) <br /></message>
1.138 bowersj2 1035: <files variable="FILES" multichoice='1'>
1.144 bowersj2 1036: <nextstate>PAGESIZE</nextstate>
1.138 bowersj2 1037: <filechoice>return '$subdir';</filechoice>
1.139 bowersj2 1038: CHOOSE_FROM_SUBDIR
1039:
1040: $xmlfrag .= <<'CHOOSE_FROM_SUBDIR';
1041: <filefilter>return $filename =~
1042: m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/;
1.131 bowersj2 1043: </filefilter>
1.138 bowersj2 1044: </files>
1.131 bowersj2 1045: </state>
1046: CHOOSE_FROM_SUBDIR
1.139 bowersj2 1047: &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
1.131 bowersj2 1048: }
1049:
1050: # Generate the first state, to select which resources get printed.
1.155 sakharuk 1051: Apache::lonhelper::state->new("START", "What do you want to print? Make a choice.");
1.131 bowersj2 1052: $paramHash = Apache::lonhelper::getParamHash();
1.155 sakharuk 1053: $paramHash->{MESSAGE_TEXT} = "";
1.131 bowersj2 1054: Apache::lonhelper::message->new();
1055: $paramHash = Apache::lonhelper::getParamHash();
1056: $paramHash->{'variable'} = 'PRINT_TYPE';
1.137 bowersj2 1057: $helper->declareVar('PRINT_TYPE');
1.131 bowersj2 1058: $paramHash->{CHOICES} = $printChoices;
1059: Apache::lonhelper::choices->new();
1.161 bowersj2 1060:
1.170 sakharuk 1061: if (($ENV{'request.role.adv'} and &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) or
1062: ($helper->{VARS}->{'construction'} eq '1')) {
1.161 bowersj2 1063: $paramHash = Apache::lonhelper::getParamHash();
1.162 sakharuk 1064: $paramHash->{MESSAGE_TEXT} = "<br /><big><b><i>Next option is available only for advanced users:</i></b></big><br />";
1.161 bowersj2 1065: Apache::lonhelper::message->new();
1066: $paramHash = Apache::lonhelper::getParamHash();
1.162 sakharuk 1067: $paramHash->{'variable'} = 'ANSWER_TYPE';
1068: $helper->declareVar('ANSWER_TYPE');
1.161 bowersj2 1069: $paramHash->{CHOICES} = [
1.163 sakharuk 1070: ['Print without answer', 'yes'],
1071: ['Print with answers', 'no'] ];
1.161 bowersj2 1072: Apache::lonhelper::choices->new();
1073: }
1074:
1.131 bowersj2 1075: Apache::lonprintout::page_format_state->new("FORMAT");
1076:
1.144 bowersj2 1077: # Generate the PAGESIZE state which will offer the user the margin
1078: # choices if they select one column
1079: Apache::lonhelper::state->new("PAGESIZE", "Set Margins");
1080: Apache::lonprintout::page_size_state->new('pagesize', 'FORMAT', 'FINAL');
1081:
1082:
1.131 bowersj2 1083: $helper->process();
1084:
1085: # MANUAL BAILOUT CONDITION:
1086: # If we're in the "final" state, bailout and return to handler
1087: if ($helper->{STATE} eq 'FINAL') {
1088: return $helper;
1089: }
1.130 sakharuk 1090:
1.131 bowersj2 1091: $r->print($helper->display());
1.130 sakharuk 1092:
1.131 bowersj2 1093: Apache::lonhelper::unregisterHelperTags();
1.115 bowersj2 1094:
1095: untie %hash;
1096:
1097: return OK;
1098: }
1099:
1.1 www 1100:
1101: 1;
1.119 bowersj2 1102:
1103: package Apache::lonprintout::page_format_state;
1104:
1105: =pod
1106:
1.131 bowersj2 1107: =head1 Helper element: page_format_state
1108:
1109: See lonhelper.pm documentation for discussion of the helper framework.
1.119 bowersj2 1110:
1.131 bowersj2 1111: Apache::lonprintout::page_format_state is an element that gives the
1112: user an opportunity to select the page layout they wish to print
1113: with: Number of columns, portrait/landscape, and paper size. If you
1114: want to change the paper size choices, change the @paperSize array
1115: contents in this package.
1.119 bowersj2 1116:
1.131 bowersj2 1117: page_format_state is always directly invoked in lonprintout.pm, so there
1118: is no tag interface. You actually pass parameters to the constructor.
1.119 bowersj2 1119:
1120: =over 4
1121:
1.131 bowersj2 1122: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
1.119 bowersj2 1123:
1124: =back
1125:
1126: =cut
1127:
1.131 bowersj2 1128: use Apache::lonhelper;
1.119 bowersj2 1129:
1130: no strict;
1.131 bowersj2 1131: @ISA = ("Apache::lonhelper::element");
1.119 bowersj2 1132: use strict;
1133:
1134: my $maxColumns = 2;
1135: my @paperSize = ("Letter [8 1/2x11 in]", "Legal [8 1/2x14 in]",
1136: "Ledger/Tabloid [11x17 in]", "Executive [7 1/2x10 in]",
1137: "A2 [420x594 mm]", "A3 [297x420 mm]", "A4 [210x297 mm]",
1138: "A5 [148x210 mm]", "A6 [105x148 mm]" );
1139:
1140: # Tentative format: Orientation (L = Landscape, P = portrait) | Colnum |
1141: # Paper type
1142:
1143: sub new {
1.131 bowersj2 1144: my $self = Apache::lonhelper::element->new();
1.119 bowersj2 1145:
1.135 bowersj2 1146: shift;
1147:
1.131 bowersj2 1148: $self->{'variable'} = shift;
1.134 bowersj2 1149: my $helper = Apache::lonhelper::getHelper();
1.135 bowersj2 1150: $helper->declareVar($self->{'variable'});
1.131 bowersj2 1151: bless($self);
1.119 bowersj2 1152: return $self;
1153: }
1154:
1155: sub render {
1156: my $self = shift;
1.131 bowersj2 1157: my $helper = Apache::lonhelper::getHelper();
1.119 bowersj2 1158: my $result = '';
1.131 bowersj2 1159: my $var = $self->{'variable'};
1.119 bowersj2 1160:
1161: $result .= <<STATEHTML;
1162:
1.155 sakharuk 1163: <p><big><i><b>What page format do you prefer?</b></i></big></p>
1.119 bowersj2 1164: <table cellpadding="3">
1165: <tr>
1.155 sakharuk 1166: <td align="center"><b>Page layout</b></td>
1167: <td align="center"><b>Number of columns</b></td>
1.131 bowersj2 1168: <td align="center"><b>Paper type</b></td>
1.119 bowersj2 1169: </tr>
1170: <tr>
1171: <td>
1.155 sakharuk 1172: <input type="radio" name="${var}.layout" value="L" /> Landscape<br />
1173: <input type="radio" name="${var}.layout" value="P" checked='1' /> Portrait
1.119 bowersj2 1174: </td>
1.155 sakharuk 1175: <td align="center">
1.119 bowersj2 1176: <select name="${var}.cols">
1177: STATEHTML
1178:
1179: my $i;
1180: for ($i = 1; $i <= $maxColumns; $i++) {
1.144 bowersj2 1181: if ($i == 2) {
1.119 bowersj2 1182: $result .= "<option value='$i' selected>$i</option>\n";
1183: } else {
1184: $result .= "<option value='$i'>$i</option>\n";
1185: }
1186: }
1187:
1188: $result .= "</select></td><td>\n";
1189: $result .= "<select name='${var}.paper'>\n";
1190:
1191: $i = 0;
1192: foreach (@paperSize) {
1.144 bowersj2 1193: if ($i == 0) {
1.131 bowersj2 1194: $result .= "<option selected value='$i'>" . $paperSize[$i] . "</option>\n";
1.119 bowersj2 1195: } else {
1.131 bowersj2 1196: $result .= "<option value='$i'>" . $paperSize[$i] . "</option>\n";
1.119 bowersj2 1197: }
1198: $i++;
1199: }
1200:
1201: $result .= "</select></td></tr></table>";
1202: return $result;
1.135 bowersj2 1203: }
1204:
1205: sub postprocess {
1206: my $self = shift;
1207:
1208: my $var = $self->{'variable'};
1.136 bowersj2 1209: my $helper = Apache::lonhelper->getHelper();
1.135 bowersj2 1210: $helper->{VARS}->{$var} =
1.136 bowersj2 1211: $ENV{"form.$var.layout"} . '|' . $ENV{"form.$var.cols"} . '|' .
1212: $ENV{"form.$var.paper"};
1.135 bowersj2 1213: return 1;
1.119 bowersj2 1214: }
1215:
1216: 1;
1.144 bowersj2 1217:
1218: package Apache::lonprintout::page_size_state;
1219:
1220: =pod
1221:
1222: =head1 Helper element: page_size_state
1223:
1224: See lonhelper.pm documentation for discussion of the helper framework.
1225:
1226: Apache::lonprintout::page_size_state is an element that gives the
1227: user the opportunity to further refine the page settings if they
1228: select a single-column page.
1229:
1230: page_size_state is always directly invoked in lonprintout.pm, so there
1231: is no tag interface. You actually pass parameters to the constructor.
1232:
1233: =over 4
1234:
1235: =item * B<new>(varName): varName is where the print information will be stored in the format FIXME.
1236:
1237: =back
1238:
1239: =cut
1240:
1241: use Apache::lonhelper;
1242:
1243: no strict;
1244: @ISA = ("Apache::lonhelper::element");
1245: use strict;
1246:
1247:
1248:
1249: sub new {
1250: my $self = Apache::lonhelper::element->new();
1251:
1252: shift; # disturbs me (probably prevents subclassing) but works (drops
1253: # package descriptor)... - Jeremy
1254:
1255: $self->{'variable'} = shift;
1256: my $helper = Apache::lonhelper::getHelper();
1257: $helper->declareVar($self->{'variable'});
1258:
1259: # The variable name of the format element, so we can look into
1260: # $helper->{VARS} to figure out whether the columns are one or two
1261: $self->{'formatvar'} = shift;
1262:
1263: # The state to transition to after selection, or after discovering
1264: # the cols are not set to 1
1265: $self->{NEXTSTATE} = shift;
1266: bless($self);
1267: return $self;
1268: }
1269:
1270: sub render {
1271: my $self = shift;
1272: my $helper = Apache::lonhelper::getHelper();
1273: my $result = '';
1274: my $var = $self->{'variable'};
1275:
1276: if (defined $self->{ERROR_MSG}) {
1277: $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />';
1278: }
1279:
1280: $result .= <<ELEMENTHTML;
1281:
1282: <p>How should the column be formatted?</p>
1283:
1284: <table cellpadding='3'>
1285: <tr>
1286: <td align='right'><b>Width</b>:</td>
1287: <td align='left'><input type='text' name='$var.width' value='18' size='4'></td>
1288: <td align='left'>
1289: <select name='$var.widthunit'>
1290: <option>cm</option><option>in</option>
1291: </select>
1292: </td>
1293: </tr>
1294: <tr>
1295: <td align='right'><b>Height</b>:</td>
1296: <td align='left'><input type='text' name="$var.height" value="25.9" size='4'></td>
1297: <td align='left'>
1298: <select name='$var.heightunit'>
1299: <option>cm</option><option>in</option>
1300: </select>
1301: </td>
1302: </tr>
1303: <tr>
1304: <td align='right'><b>Left margin</b>:</td>
1305: <td align='left'><input type='text' name='$var.lmargin' value='-1.5' size='4'></td>
1306: <td align='left'>
1.186 bowersj2 1307: <select name='$var.lmarginunit'>
1.144 bowersj2 1308: <option>cm</option><option>in</option>
1309: </select>
1310: </td>
1311: </tr>
1312: </table>
1313:
1314: <p>Hint: Some instructors like to leave scratch space for the student by
1315: making the width much smaller then the width of the page.</p>
1316:
1317: ELEMENTHTML
1318:
1319: return $result;
1320: }
1321:
1322: # If the user didn't select 1 column, skip this state.
1323: sub preprocess {
1324: my $self = shift;
1325: my $helper = Apache::lonhelper::getHelper();
1326:
1327: my $format = $helper->{VARS}->{$self->{'formatvar'}};
1328: if (substr($format, 2, 1) ne '1') {
1329: $helper->changeState($self->{NEXTSTATE});
1330: }
1331:
1332: return 1;
1333: }
1334:
1335: sub postprocess {
1336: my $self = shift;
1337:
1338: my $var = $self->{'variable'};
1339: my $helper = Apache::lonhelper->getHelper();
1340: my $width = $helper->{VARS}->{$var .'.width'} = $ENV{"form.${var}.width"};
1341: my $height = $helper->{VARS}->{$var .'.height'} = $ENV{"form.${var}.height"};
1342: my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $ENV{"form.${var}.lmargin"};
1343: $helper->{VARS}->{$var .'.widthunit'} = $ENV{"form.${var}.widthunit"};
1344: $helper->{VARS}->{$var .'.heightunit'} = $ENV{"form.${var}.heightunit"};
1345: $helper->{VARS}->{$var .'.lmarginunit'} = $ENV{"form.${var}.lmarginunit"};
1346:
1347: my $error = '';
1348:
1349: # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed
1350: # by an optional period, followed by digits, ending the string
1351:
1352: if ($width !~ /^-?[0-9]+(\.[0-9]*)?$/) {
1353: $error .= "Invalid width; please type only a number.<br />\n";
1354: }
1355: if ($height !~ /^-?[0-9]+(\.[0-9]*)?$/) {
1356: $error .= "Invalid height; please type only a number.<br />\n";
1357: }
1358: if ($lmargin !~ /^-?[0-9]+(\.[0-9]*)?$/) {
1359: $error .= "Invalid left margin; please type only a number.<br />\n";
1360: }
1361:
1362: if (!$error) {
1363: Apache::lonhelper::getHelper()->changeState($self->{NEXTSTATE});
1364: return 1;
1365: } else {
1366: $self->{ERROR_MSG} = $error;
1367: return 0;
1368: }
1369: }
1370:
1371:
1.119 bowersj2 1372:
1.1 www 1373: __END__
1.6 sakharuk 1374:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>