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