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