File:
[LON-CAPA] /
loncom /
interface /
lonprintout.pm
Revision
1.105:
download - view:
text,
annotated -
select for diffs
Thu Jan 23 20:19:38 2003 UTC (21 years, 7 months ago) by
sakharuk
Branches:
MAIN
CVS tags:
version_0_6_2,
HEAD
1. Restored the natural order in printing the content of primary sequence. All problems now are printing in the same order as they appear in the sequence (not ion alphabetical order). I had a conversation with Ed and he agreed with me that it is absolutely unresonable to sort problems fron the sequence in alphabetical order (I don't remember who's desire was to sort problems in sequence).
2. Item four from the primary printing menu now works for the courses constructed using docs. It was tested by me on three courses - everything looks fine. Nevertheless, I would be really glad to receive any critical notes or just notes that other courses can be printed eather.
1: # The LearningOnline Network
2: # Printout
3: #
4: # $Id: lonprintout.pm,v 1.105 2003/01/23 20:19:38 sakharuk Exp $
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: #
28: # (Internal Server Error Handler
29: #
30: # (Login Screen
31: # 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14,
32: # 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer)
33: #
34: # 3/1/1 Gerd Kortemeyer)
35: #
36: # 3/1 Gerd Kortemeyer
37: #
38: # 9/17 Alex Sakharuk
39: #
40: package Apache::lonprintout;
41:
42: use strict;
43: use Apache::Constants qw(:common :http);
44: use Apache::lonxml;
45: use Apache::lonnet;
46: use Apache::loncommon;
47: use Apache::inputtags;
48: use Apache::grades;
49: use Apache::edit;
50: use Apache::File();
51: use Apache::lonnavmaps;
52: use POSIX qw(strftime);
53: use GDBM_File;
54:
55:
56: my %hash;
57: my $LaTeXwidth = 0;
58:
59: sub headerform {
60: my $r = shift;
61: $r->print(<<ENDHEADER);
62: <html>
63: <head>
64: <title>LON-CAPA output for printing</title>
65: </head>
66: <body bgcolor="FFFFFF">
67: <form method="post" enctype="multipart/form-data" action="/adm/printout" name="printform">
68: ENDHEADER
69:
70: if ($ENV{'form.postdata'}=~m|^/res/|) {
71: $r->print(<<ENDHEADER1);
72: <b>Path to current document: </b><tt>$ENV{'form.postdata'}</tt><p>
73: ENDHEADER1
74: }
75: }
76:
77:
78: sub menu_for_output {
79: my $r = shift;
80: my ($title_for_single_resource,$title_for_sequence,$title_for_main_map) = &details_for_menu;
81: my $assignment = $title_for_sequence;
82: if ($title_for_single_resource ne '') {$title_for_single_resource = '"'.$title_for_single_resource.'"';}
83: if ($title_for_sequence ne '') {$title_for_sequence = '"'.$title_for_sequence.'"';}
84: if ($title_for_main_map ne '') {$title_for_main_map = '"'.$title_for_main_map.'"';}
85: $ENV{'form.postdata'} =~ s|http://[^/]+||;
86: my $subdir_to_print = $ENV{'form.postdata'};
87: $subdir_to_print =~ m/\/([^\/]+)$/;
88: $subdir_to_print =~ s/\Q$1\E//;
89: $r->print(<<ENDMENUOUT1);
90: <h1>What do you want to print? Make a choice.</h1><br />
91: <input type="hidden" name="phase" value="two">
92: <input type="hidden" name="url" value="$ENV{'form.postdata'}">
93: <input type="hidden" name="assignment" value="$assignment">
94: <input type="radio" name="choice" value="Standard LaTeX output for current document" checked> Current document <b>$title_for_single_resource</b>
95: (prints what you just saw on the screen)<br />
96: ENDMENUOUT1
97: if ($ENV{'form.postdata'}=~/\/res\//) {
98: $r->print(<<ENDMENUOUT2);
99: <input type="radio" name="choice" value="Standard LaTeX output for the primary sequence"> Problem(s) from <b>$title_for_sequence</b><br />
100: <input type="radio" name="choice" value="Standard LaTeX output for whole primary sequence"> Problem(s) plus page(s) or html/xml file(s) from <b>$title_for_sequence</b><br />
101: ENDMENUOUT2
102: }
103: if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($ENV{'form.postdata'}=~/\/res\//)) {
104: $r->print(<<ENDMENUOUT6);
105: <input type="radio" name="choice" value="Standard LaTeX output for the top level sequence"> All problems in this course (<b>warning:</b> this may be time consuming) <br />
106: <br />
107: <input type="radio" name="choice" value="All class print"> All problems from <b>$title_for_sequence</b> for selected students<br /><br />
108: ENDMENUOUT6
109: }
110: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
111: $subdirtoprint =~ s/\/[^\/]+$//;
112: if ((&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') and ($ENV{'form.postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) {
113: $r->print(<<ENDMENUOUT4);
114: <input type="radio" name="choice" value="Subdirectory print"> Problems from current subdirectory <b>$subdir_to_print</b><br />
115: ENDMENUOUT4
116: }
117: $r->print(<<ENDMENUOUT5);
118: <br /><hr /><br />
119: <h1>And what page format do you prefer?</h1>
120: <table>
121: <tr>
122: <td>
123: <input type="radio" name="layout" value="CBI"> Landscape <br />
124: <input type="radio" name="layout" value="CAPA" checked> Portrait <br />
125: </td>
126: <td> </td>
127: <td rawspan="2">
128: Number of columns: <select name="numberofcolumns">
129: <option> 1 </option>
130: <option selected> 2 </option>
131: </select>
132: </td>
133: <td rawspan="2">
134: Paper size (format [width x height]): <select name="papersize">
135: <option selected> Letter [8 1/2x11 in] </option>
136: <option> Legal [8 1/2x14 in] </option>
137: <option> Ledger/Tabloid [11x17 in] </option>
138: <option> Executive [7 1/2x10 in] </option>
139: <option> A2 [420x594 mm] </option>
140: <option> A3 [297x420 mm] </option>
141: <option> A4 [210x297 mm] </option>
142: <option> A5 [148x210 mm] </option>
143: <option> A6 [105x148 mm] </option>
144: </select>
145: </td>
146: </tr>
147: </table>
148: </br>
149: <input type="submit" value="Submit your choice">
150: ENDMENUOUT5
151: }
152:
153:
154: sub sequence_content_menu {
155: my ($key_to,$r) = @_;
156: my $primary_sequence;
157: my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
158: my @sequence = split('___',$symbolic);
159: if ($sequence[0]=~/^uploaded/) {$primary_sequence = '/'.$sequence[0];}
160: else {$primary_sequence = '/res/'.$sequence[0];}
161: my @master_seq = &coming_from_hash($primary_sequence,$sequence[0]);
162: my @master_seq_view = @master_seq;
163: @master_seq = @master_seq;
164: for (my $i=0;$i<=$#master_seq_view;$i++) {
165: $master_seq_view[$i]=~/\/([^\/]+)$/;
166: $master_seq_view[$i]=$1;
167: }
168: $r->print(<<ENDMENUOUT1);
169: <input type="hidden" name="url" value="$ENV{'form.url'}">
170: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
171: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
172: <input type="hidden" name="papersize" value="$ENV{'form.papersize'}">
173: <input type="hidden" name="assignment" value="$ENV{'form.assignment'}">
174: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
175: <h1>Mark item(s) which you want to print</h1>
176: <script>
177: function checkall() {
178: for (i=0; i<document.forms.printform.elements.length; i++) {
179: if
180: (document.forms.printform.elements[i].name.indexOf('whatfile')==0) {
181: document.forms.printform.elements[i].checked=true;
182: }
183: }
184: }
185: function uncheckall() {
186: for (i=0; i<document.forms.printform.elements.length; i++) {
187: if
188: (document.forms.printform.elements[i].name.indexOf('whatfile')==0) {
189: document.forms.printform.elements[i].checked=false;
190: }
191: }
192: }
193: </script>
194: <input type=button onClick="checkall()" value="Check All">
195: <input type=button onClick="uncheckall()" value="Uncheck">
196: <p>
197: ENDMENUOUT1
198: my $inc=0;
199: for (my $i=0;$i<=$#master_seq_view;$i++) {
200: if ($key_to==1 && $master_seq_view[$i]=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
201: $r->print('<br /><input type=checkbox name="whatfile'.$inc.'" value="'.$master_seq[$i].'"> '."\n".
202: $master_seq_view[$i]);
203: $inc++;
204: } elsif ($key_to==0 && $master_seq_view[$i]=~/\.(problem|exam|quiz|assess|survey|form|library|xml|htm|html|page)$/) {
205: $r->print('<br /><input type=checkbox name="whatfile'.$inc.'" value="'.$master_seq[$i].'"> '.
206: $master_seq_view[$i]);
207: $inc++;
208: }
209: }
210: $r->print(<<ENDMENUOUT2);
211: <br />
212: <input type="hidden" name="numberoffiles" value="$inc">
213: <input type="hidden" name="phase" value="three">
214: <input type="submit" value="Submit">
215: ENDMENUOUT2
216:
217: }
218:
219:
220: sub problem_choice_menu {
221: my $r = shift;
222: my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'});
223: $subdirtoprint =~ s/\/[^\/]+$//;
224: my @list_of_files = ();
225: my @content_directory = ();
226: if ($subdirtoprint =~ m|/home/([^/]+)/public_html|) {
227: #localmachine CSTR space
228: my $user=$1;
229: my $domain=$Apache::lonnet::perlvar{'lonDefDomain'};
230: @content_directory = &Apache::lonnet::dirlist($subdirtoprint,
231: $domain, $user,'');
232: } else {
233: @content_directory = &Apache::lonnet::dirlist($subdirtoprint);
234: }
235: for (my $iy=0;$iy<=$#content_directory;$iy++) {
236: my @tempo_array = split(/&/,$content_directory[$iy]);
237: if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) {
238: push(@list_of_files,$tempo_array[0]);
239: }
240: }
241: $subdirtoprint =~ s/\/$//;
242: for (my $i=0;$i<=$#list_of_files;$i++) {
243: $list_of_files[$i] = $subdirtoprint.'/'.$list_of_files[$i];
244: }
245: $r->print(<<ENDMENUOUT1);
246: <input type="hidden" name="url" value="$ENV{'form.url'}">
247: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
248: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
249: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
250: <h1>Mark problems which you want to print</h1>
251: <script>
252: function checkall() {
253: for (i=0; i<document.forms.printform.elements.length; i++) {
254: if
255: (document.forms.printform.elements[i].name.indexOf('whattoprint')==0) {
256: document.forms.printform.elements[i].checked=true;
257: }
258: }
259: }
260:
261:
262: function uncheckall() {
263: for (i=0; i<document.forms.printform.elements.length; i++) {
264: if
265: (document.forms.printform.elements[i].name.indexOf('whattoprint')==0) {
266: document.forms.printform.elements[i].checked=false;
267: }
268: }
269: }
270: </script>
271: <input type=button onClick="checkall()" value="Check All">
272: <input type=button onClick="uncheckall()" value="Uncheck">
273: <p>
274: ENDMENUOUT1
275: my $i=0;
276: foreach my $file (sort @list_of_files) {
277: $r->print('<br /><input type=checkbox name="whattoprint'.$i.'" value="'.$file.'"> '.
278: $file);
279: $i++;
280: }
281: $r->print(<<ENDMENUOUT2);
282: <br />
283: <input type="hidden" name="papersize" value="$ENV{'form.papersize'}">
284: <input type="hidden" name="numberofproblems" value="$i">
285: <input type="hidden" name="phase" value="three">
286: <input type="submit" value="Submit">
287: ENDMENUOUT2
288: }
289:
290:
291: sub additional_class_menu {
292: my $r = shift;
293: $r->print(<<ENDMENUOUT1);
294: <input type="hidden" name="url" value="$ENV{'form.url'}">
295: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
296: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
297: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
298: <input type="hidden" name="assignment" value="$ENV{'form.assignment'}">
299: <h1>Select student(s) whose assignment you want to print</h1>
300: ENDMENUOUT1
301: my %courselist=&Apache::lonnet::dump(
302: 'classlist',
303: $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
304: $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
305: my $now=time;
306: $r->print(<<ENDDISHEADER);
307: <script>
308: function checkall() {
309: for (i=0; i<document.forms.printform.elements.length; i++) {
310: if
311: (document.forms.printform.elements[i].name.indexOf('whomtoprint')==0) {
312: document.forms.printform.elements[i].checked=true;
313: }
314: }
315: }
316:
317: function checksec() {
318: for (i=0; i<document.forms.printform.elements.length; i++) {
319: if
320: (document.forms.printform.elements[i].value.indexOf
321: (document.forms.printform.chksec.value)==0) {
322: document.forms.printform.elements[i].checked=true;
323: }
324: }
325: }
326:
327: function uncheckall() {
328: for (i=0; i<document.forms.printform.elements.length; i++) {
329: if
330: (document.forms.printform.elements[i].name.indexOf('whomtoprint')==0) {
331: document.forms.printform.elements[i].checked=false;
332: }
333: }
334: }
335: </script>
336: <input type=button onClick="checkall()" value="Check All">
337: <input type=button onClick="checksec()" value="Type Section/Group then click">
338: <input type=text size=5 name=chksec>
339: <input type=button onClick="uncheckall()" value="Uncheck">
340: <p>
341: ENDDISHEADER
342: my $i = 0;
343: foreach (sort keys %courselist) {
344: my ($end,$start)=split(/\:/,$courselist{$_});
345: my $active=1;
346: if (($end) && ($now>$end)) { $active=0; }
347: if ($active) {
348: my ($sname,$sdom)=split(/\:/,$_);
349: my %reply=&Apache::lonnet::get('environment',
350: ['firstname','middlename','lastname','generation'],
351: $sdom,$sname);
352: my $section=&Apache::lonnet::usection
353: ($sdom,$sname,$ENV{'request.course.id'});
354: $r->print(
355: '<br /><input type=checkbox name="whomtoprint'.$i.'" value="'.$section.':'.$_.'"> '.
356: $reply{'firstname'}.' '.
357: $reply{'middlename'}.' '.
358: $reply{'lastname'}.' '.
359: $reply{'generation'}.
360: ' ('.$_.') '.$section);
361: $i++;
362: }
363: }
364: $r->print(<<ENDMENUOUT2);
365: <br />Number of blank pages to add: <select name="addedpages"><option selected>0</option>
366: <option>1</option>
367: <option>2</option>
368: <option>3</option>
369: </select>
370: <br />
371: <input type="hidden" name="papersize" value="$ENV{'form.papersize'}">
372: <input type="hidden" name="numberofstudents" value="$i">
373: <input type="hidden" name="phase" value="three">
374: <input type="submit" value="Submit">
375: ENDMENUOUT2
376: }
377:
378:
379: sub additional_print_menu {
380: my $r = shift;
381: my $what_to_print = '';
382: for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
383: $what_to_print .= '<input type="hidden" name="whomtoprint'.$i.'" value="'.$ENV{'form.whomtoprint'.$i}.'">';
384: }
385: for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) {
386: $what_to_print .= '<input type="hidden" name="whattoprint'.$i.'" value="'.$ENV{'form.whattoprint'.$i}.'">';
387: }
388: for (my $i=0; $i<$ENV{'form.numberoffiles'};$i++) {
389: $what_to_print .= '<input type="hidden" name="whatfile'.$i.'" value="'.$ENV{'form.whatfile'.$i}.'">';
390: }
391: $r->print(<<ENDMENUOUT);
392: $what_to_print
393: <input type="hidden" name="url" value="$ENV{'form.url'}">
394: <input type="hidden" name="choice" value="$ENV{'form.choice'}">
395: <input type="hidden" name="layout" value="$ENV{'form.layout'}">
396: <input type="hidden" name="papersize" value="$ENV{'form.papersize'}">
397: <input type="hidden" name="numberofstudents" value="$ENV{'form.numberofstudents'}">
398: <input type="hidden" name="numberofproblems" value="$ENV{'form.numberofproblems'}">
399: <input type="hidden" name="numberoffiles" value="$ENV{'form.numberoffiles'}">
400: <input type="hidden" name="numberofcolumns" value="$ENV{'form.numberofcolumns'}">
401: <input type="hidden" name="assignment" value="$ENV{'form.assignment'}">
402: <input type="hidden" name="addedpages" value="$ENV{'form.addedpages'}">
403: Define one column layout parameters: <br />
404: <b>Width</b>: <input type="text" name="width" width="8" value="9cm"> <br />
405: <b>Height</b>: <input type="text" name="height" width="8" value="25.9cm"> <br />
406: <b>Left margin</b>: <input type="text" name="leftmargin" width="8" value="-0.57in"> <br />
407: <input type="hidden" name="phase" value="four">
408: <input type="submit" value="Submit">
409: </form>
410: </body>
411: </html>
412: ENDMENUOUT
413: }
414:
415:
416: sub output_data {
417: my $r = shift;
418: $r->print(<<ENDPART);
419: <html>
420: <head>
421: <title>LON-CAPA output for printing</title>
422: </head>
423: <body bgcolor="FFFFFF">
424: <hr>
425: ENDPART
426:
427: my $choice = $ENV{'form.choice'};
428: my $layout = $ENV{'form.layout'};
429: my $numberofcolumns = $ENV{'form.numberofcolumns'};
430: my $papersize = $ENV{'form.papersize'};
431: my $laystyle = 'book';
432: my $assignment = $ENV{'form.assignment'};
433: if ($choice eq 'Subdirectory print') {
434: if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';}
435: if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';}
436: if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;}
437: }
438: if (($choice eq 'Standard LaTeX output for current document') &&
439: ($ENV{'form.url'}=~m|^/~|)) {
440: if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';}
441: if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';}
442: if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;}
443: }
444: my $result = '';
445: my $number_of_columns = 1; #used only for pages to determine the width of the cell
446: my $selectionmade = '';
447: my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns);
448: if ($numberofcolumns == 1) {
449: $textwidth=$ENV{'form.width'};
450: $textheight=$ENV{'form.height'};
451: }
452: my $LaTeXwidth;
453: if ($textwidth=~/(\d+\s*cm)/) {
454: $LaTeXwidth = $1*10;
455: } elsif ($textwidth=~/(\d+\s*mm)/) {
456: $LaTeXwidth = $1;
457: }
458: if ($choice eq 'Standard LaTeX output for current document') {
459: #-- single document - problem, page, html, xml
460: $selectionmade = 1;
461: if ($ENV{'form.url'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
462: my %moreenv;
463: $moreenv{'form.grade_target'}='tex';
464: if (&Apache::lonnet::allowed('bre',$ENV{'form.url'})) {
465: $ENV{'form.url'}=~s/http:\/\/[^\/]+//;
466: }
467: $moreenv{'request.filename'}=$ENV{'form.url'};
468: $moreenv{'form.textwidth'}=$LaTeXwidth;
469: &Apache::lonnet::appenv(%moreenv);
470: my $texversion=&Apache::lonnet::ssi($ENV{'form.url'});
471: &Apache::lonnet::delenv('form.grade_target','form.textwidth','form.counter');
472: $result .= $texversion;
473: if ($ENV{'form.url'}=~m/\.page\s*$/) {
474: ($result,$number_of_columns) = &page_cleanup($result);
475: }
476: } else {
477: $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: ';
478: if ($ENV{'form.url'}=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) {
479: $result.=$1;
480: } else {
481: $result.=$ENV{'form.url'};
482: }
483: $result.=' \end{document}'
484: }
485: } elsif ($choice eq 'Standard LaTeX output for the primary sequence' or
486: $choice eq 'Standard LaTeX output for whole primary sequence') {
487: #-- minimal sequence to which the current document belongs
488: #-- where is the primary sequence containing file?
489: my @master_seq = ();
490: for (my $i=0; $i<$ENV{'form.numberoffiles'};$i++) {
491: if ($ENV{'form.whatfile'.$i}=~/\S/) {
492: push @master_seq,$ENV{'form.whatfile'.$i};
493: }
494: }
495: #-- produce an output string
496: my $flag_latex_header_remove = 'NO';
497: my $flag_page_in_sequence = 'NO';
498: for (my $i=0;$i<=$#master_seq;$i++) {
499: my ($urlp,$symb) = split /&&/, $master_seq[$i];
500: if ($choice eq 'Standard LaTeX output for the primary sequence') {
501: $selectionmade = 2;
502: } elsif ($choice eq 'Standard LaTeX output for whole primary sequence') {
503: $selectionmade = 3;
504: }
505: my %moreenv;
506: $moreenv{'form.grade_target'}='tex';
507: $moreenv{'form.textwidth'}=$LaTeXwidth;
508: &Apache::lonnet::appenv(%moreenv);
509: #&Apache::lonnet::logthis("Trying to get $urlp with symb $symb");
510: my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$symb));
511: &Apache::lonnet::delenv('form.grade_target','form.textwidth');
512: if ($urlp =~ m/\.page/) {
513: ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
514: if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;}
515: $texversion =~ s/\\end{document}\d*/\\end{document}/;
516: $flag_page_in_sequence = 'YES';
517: }
518: if ($flag_latex_header_remove ne 'NO') {
519: $texversion = &latex_header_footer_remove($texversion);
520: } else {
521: $texversion =~ s/\\end{document}//;
522: }
523: $result .= $texversion;
524: $flag_latex_header_remove = 'YES';
525: }
526: &Apache::lonnet::delenv('form.counter');
527: if ($flag_page_in_sequence eq 'YES') {$result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;}
528: $result .= '\end{document}';
529: } elsif ($choice eq 'Standard LaTeX output for the top level sequence') {
530: # where is the main sequence of the course?
531: $selectionmade = 4;
532: my $main_seq;
533: if ($ENV{'request.course.uri'}=~/\/?uploaded\//) {
534: $main_seq = $ENV{'request.course.uri'};
535: } else {
536: $main_seq = '/res/'.$ENV{'request.course.uri'};
537: }
538: my @file_seq = &coming_from_hash_whole($main_seq);
539: my $flag_latex_header_remove = 'NO';
540: #-- produce an output string
541: for (my $i=0;$i<=$#file_seq;$i++) {
542: if (not $file_seq[$i]=~/^&&/) {
543: my ($urlp,$symb) = split /&&/, $file_seq[$i];
544: $urlp=~s/\/home\/httpd\/html//;
545: if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) {
546: my %moreenv;
547: $moreenv{'form.grade_target'}='tex';
548: $moreenv{'form.textwidth'}=$LaTeXwidth;
549: &Apache::lonnet::appenv(%moreenv);
550: my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$symb));
551: &Apache::lonnet::delenv('form.grade_target','form.textwidth');
552: if ($flag_latex_header_remove ne 'NO') {
553: $texversion = &latex_header_footer_remove($texversion);
554: } else {
555: $texversion =~ s/\\end{document}//;
556: }
557: $result .= $texversion;
558: $flag_latex_header_remove = 'YES';
559: }
560: }
561: }
562: $result .= '\end{document}';
563: } elsif ($choice eq 'All class print') {
564: #-- prints assignments for whole class or for selected students
565: $selectionmade = 5;
566: my @students = ();
567: for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) {
568: if ($ENV{'form.whomtoprint'.$i}=~/:/) {
569: push @students,$ENV{'form.whomtoprint'.$i};
570: }
571: }
572: #where is the primary sequence containing current resource (the same for all students)?
573: my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'});
574: my @sequence = split('___',$symbolic);
575: my $primary_sequence = '/res/'.$sequence[0];
576: my @master_seq = &coming_from_hash($primary_sequence,$sequence[0]);
577: #loop over students
578: my $flag_latex_header_remove = 'NO';
579: my %moreenv;
580: $moreenv{'form.textwidth'}=$LaTeXwidth;
581: &Apache::lonnet::appenv(%moreenv);
582: foreach my $person (@students) {
583: my $current_output = '';
584: my ($usersection,$username,$userdomain) = split /:/,$person;
585: my $fullname = &Apache::grades::get_fullname($username,$userdomain);
586: #goes through all resources, checks if they are available for current student, and produces output
587: foreach my $curresline (@master_seq) {
588: my ($curres,$symb) = split /&&/, $curresline;
589: if ($curres=~ m/\.(problem|exam|quiz|assess|survey|form|library)/) {
590: my ($map,$id,$res_url) = split(/___/,$symb);
591: if (&Apache::lonnet::allowed('bre',$res_url)) {
592: my $rendered = &Apache::loncommon::get_student_view($symb,$username,$userdomain,
593: $ENV{'request.course.id'},'tex');
594: if ($flag_latex_header_remove eq 'YES') {
595: $rendered = &latex_header_footer_remove($rendered);
596: } else {
597: $rendered =~ s/\\end{document}//;
598: }
599: $current_output .= $rendered;
600: }
601: $flag_latex_header_remove = 'YES';
602: }
603: }
604: if ($current_output=~/\\documentclass/) {
605: my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
606: $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm}\\setlength{\\headheight}{1cm}\\setlength{\\headsep}{0.5cm}\\pagestyle{myheadings}\\markboth{}{{$courseidinfo - $assignment}}\\begin{document}\\noindent\\textit{\\textbf{$fullname}}\\vskip 3 mm /;
607: } else {
608: my $blanspages = '';
609: for (my $j=0;$j<$ENV{'form.addedpages'};$j++) {$blanspages.='\clearpage\strut\clearpage';}
610: $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 } \\vskip 3mm'.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\textit{\textbf{'.$fullname.'}}\hskip 1.4in } \vskip 5 mm '.$current_output;
611: }
612: $result .= $current_output;
613: &Apache::lonnet::delenv('form.counter');
614: }
615: $result .= '\end{document}';
616: &Apache::lonnet::delenv('form.textwidth');
617: } elsif ($choice eq 'Subdirectory print') {
618: #prints selected problems from the subdirectory
619: $selectionmade = 6;
620: my @list_of_files = ();
621: for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) {
622: if ($ENV{'form.whattoprint'.$i}=~/^\//) {
623: push @list_of_files,$ENV{'form.whattoprint'.$i};
624: }
625: }
626: my $flag_latex_header_remove = 'NO';
627: for (my $i=0;$i<=$#list_of_files;$i++) {
628: my $urlp = $list_of_files[$i];
629: if ($urlp=~/\//) {
630: my %moreenv;
631: $moreenv{'form.grade_target'}='tex';
632: $moreenv{'form.textwidth'}=$LaTeXwidth;
633: &Apache::lonnet::appenv(%moreenv);
634: if ($urlp =~ m|/home/([^/]+)/public_html|) {
635: $urlp =~ s|/home/([^/]*)/public_html|/~$1|;
636: }
637: my $texversion=&Apache::lonnet::ssi($urlp);
638: &Apache::lonnet::delenv('form.grade_target','form.textwidth');
639: #this chunck is responsible for printing the path to problem
640: my $newurlp = '';
641: my $HowMany = length($urlp)*2;
642: if ($HowMany > $LaTeXwidth) {
643: my @temporrary = split '/',$urlp;
644: my $HowManyNew = 0;
645: for (my $ii=0;$ii<=$#temporrary;$ii++) {
646: if ($temporrary[$ii] ne '') {
647: $HowManyNew += length($temporrary[$ii])*2;
648: if ($HowManyNew < $LaTeXwidth ) {
649: $newurlp .= '/'.$temporrary[$ii];
650: } else {
651: $HowManyNew = 0;
652: $newurlp .= '|\vskip -1 mm \noindent \verb|';
653: $ii--;
654: }
655: }
656: }
657: }
658: $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/;
659: if ($flag_latex_header_remove ne 'NO') {
660: $texversion = &latex_header_footer_remove($texversion);
661: } else {
662: $texversion =~ s/\\end{document}//;
663: }
664: $result .= $texversion;
665: }
666: $flag_latex_header_remove = 'YES';
667: }
668: $result .= '\end{document}';
669: }
670: #-------------------------------------------------------- corrections for the different page formats
671: $result = &page_format_transformation($papersize,$layout,$numberofcolumns,$choice,$result,$assignment);
672: if ($layout eq 'CBI') {
673: $laystyle = 'album';
674: }
675: $result = &latex_corrections($number_of_columns,$result);
676: #changes page's parameters for the one column output
677: if ($ENV{'form.numberofcolumns'} == 1) {
678: $result =~ s/\\textwidth= 9cm/\\textwidth= $ENV{'form.width'}/;
679: $result =~ s/\\textheight 25\.9cm/\\textheight $ENV{'form.height'}/;
680: $result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $ENV{'form.leftmargin'}/;
681: $result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $ENV{'form.leftmargin'}/;
682: }
683: #-- writing .tex file in prtspool
684: my $temp_file;
685: my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
686: unless ($temp_file = Apache::File->new('>'.$filename)) {
687: $r->log_error("Couldn't open $filename for output $!");
688: return SERVER_ERROR;
689: }
690: print $temp_file $result;
691: $r->print(<<FINALEND);
692: <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$filename&$laystyle&$numberofcolumns&$selectionmade">
693: </body>
694: </html>
695: FINALEND
696: }
697:
698:
699: sub coming_from_hash_whole {
700:
701: my $mainsequence = shift;
702: my @resourcelist = ();
703: my $mapid = $hash{'map_pc_'.$mainsequence};
704: my $mapstart = $hash{'map_start_'.$mainsequence};
705: my $mapfinish = $hash{'map_finish_'.$mainsequence};
706: my $current_resource = $mapstart;
707: while ($current_resource ne $mapfinish) {
708: if ($hash{'src_'.$current_resource}=~/\.sequence$/) {
709: push @resourcelist,&coming_from_hash_whole($hash{'src_'.$current_resource});
710: } else {
711: my $presymb;
712: if ($mainsequence =~ /\/res\/(.*)$/) {$presymb = $1;}
713: elsif ($mainsequence =~ /\/?(uploaded\/(.*))$/) {$presymb = $1;}
714: my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
715: if ($rid=~/,/) {
716: my @rid = split /,/, $rid;
717: foreach my $rid_element (@rid) {
718: if ($rid_element =~ m/^$mapid\.(\d*)/) {
719: $rid = $1;
720: last;
721: }
722: }
723: } else {
724: $rid =~ m/^$mapid\.(\d*)/;
725: $rid = $1;
726: }
727: $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
728: my $symb = $presymb.'___'.$rid.'___'.$1;
729: push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb;
730: }
731: $current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}};
732: }
733: return @resourcelist;
734: }
735:
736:
737: sub coming_from_hash {
738:
739: my ($mainsequence,$symb) = @_;
740: my @resourcelist = ();
741: my $mapid = $hash{'map_pc_'.$mainsequence};
742: my $mapstart = $hash{'map_start_'.$mainsequence};
743: my $mapfinish = $hash{'map_finish_'.$mainsequence};
744: my ($presymb);
745: if ($symb) {
746: ($presymb)=split(/___/,$symb);
747: } else {
748: $presymb=$mainsequence;
749: $presymb=~s|^/res/||;
750: }
751: $presymb = $presymb.'___';
752: my $current_resource = $mapstart;
753: while ($current_resource ne $mapfinish) {
754: if (not $hash{'src_'.$current_resource}=~/\.sequence$/) {
755: my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
756: if ($rid=~/,/) {
757: my @rid = split /,/, $rid;
758: foreach my $rid_element (@rid) {
759: if ($rid_element =~ m/^$mapid\.(\d*)/) {
760: $rid = $1;
761: last;
762: }
763: }
764: } else {
765: $rid =~ m/^$mapid\.(\d*)/;
766: $rid = $1;
767: }
768: $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
769: $symb = $presymb.$rid.'___'.$1;
770: push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb;
771: } else {
772: push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource});
773: }
774: $current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}};
775: }
776: #needs if final resource in the map (type="finish") contains something
777: if (not $hash{'src_'.$current_resource}=~/\.sequence$/) {
778: my $rid = $hash{'ids_'.$hash{'src_'.$current_resource}};
779: if ($rid=~/,/) {
780: my @rid = split /,/, $rid;
781: foreach my $rid_element (@rid) {
782: if ($rid_element =~ m/^$mapid\.(\d*)/) {
783: $rid = $1;
784: last;
785: }
786: }
787: } else {
788: $rid =~ m/^$mapid\.(\d*)/;
789: $rid = $1;
790: }
791: $hash{'src_'.$current_resource} =~ m/\/res\/(.*)$/;
792: $symb = $presymb.$rid.'___'.$1;
793: push @resourcelist,$hash{'src_'.$current_resource}.'&&'.$symb;
794: } else {
795: push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource});
796: }
797: return @resourcelist;
798: }
799:
800:
801: sub latex_header_footer_remove {
802: my $text = shift;
803: $text =~ s/\\end{document}//;
804: $text =~ s/\\documentclass([^&]*)\\begin{document}//;
805: return $text;
806: }
807:
808:
809: sub character_chart {
810: my $result = shift;
811: $result =~ s/�?0?7;//g;
812: $result =~ s/�?0?9;//g;
813: $result =~ s/�?10;//g;
814: $result =~ s/�?13;//g;
815: $result =~ s/�?32;/ /g;
816: $result =~ s/�?33;/!/g;
817: $result =~ s/�?34;/"/g;
818: $result =~ s/"/"/g; #"
819: $result =~ s/�?35;/\\#/g;
820: # $result =~ s/�?36;/\\\$/g;
821: $result =~ s/�?37;/\\%/g;
822: $result =~ s/�?38;/\\&/g;
823: $result =~ s/&/\\&/g;
824: $result =~ s/�?39;/'/g;
825: $result =~ s/�?40;/(/g;
826: $result =~ s/�?41;/)/g;
827: $result =~ s/�?42;/\*/g;
828: $result =~ s/�?43;/\+/g;
829: $result =~ s/�?44;/,/g;
830: $result =~ s/�?45;/-/g;
831: $result =~ s/�?46;/\./g;
832: $result =~ s/�?47;/\//g;
833: $result =~ s/�?48;/0/g;
834: $result =~ s/�?49;/1/g;
835: $result =~ s/�?50;/2/g;
836: $result =~ s/�?51;/3/g;
837: $result =~ s/�?52;/4/g;
838: $result =~ s/�?53;/5/g;
839: $result =~ s/�?54;/6/g;
840: $result =~ s/�?55;/7/g;
841: $result =~ s/�?56;/8/g;
842: $result =~ s/�?57;/9/g;
843: $result =~ s/�?58;/:/g;
844: $result =~ s/�?59;/;/g;
845: $result =~ s/�?60;/\$<\$/g;
846: $result =~ s/</\$<\$/g;
847: $result =~ s/�?61;/\$=\$/g;
848: $result =~ s/�?62;/\$>\$/g;
849: $result =~ s/>/\$>\$/g;
850: $result =~ s/�?63;/?/g;
851: # $result =~ s/�?64;//g;
852: $result =~ s/�?65;/A/g;
853: $result =~ s/�?66;/B/g;
854: $result =~ s/�?67;/C/g;
855: $result =~ s/�?68;/D/g;
856: $result =~ s/�?69;/E/g;
857: $result =~ s/�?70;/F/g;
858: $result =~ s/�?71;/G/g;
859: $result =~ s/�?72;/H/g;
860: $result =~ s/�?73;/I/g;
861: $result =~ s/�?74;/J/g;
862: $result =~ s/�?75;/K/g;
863: $result =~ s/�?76;/L/g;
864: $result =~ s/�?77;/M/g;
865: $result =~ s/�?78;/N/g;
866: $result =~ s/�?79;/O/g;
867: $result =~ s/�?80;/P/g;
868: $result =~ s/�?81;/Q/g;
869: $result =~ s/�?82;/R/g;
870: $result =~ s/�?83;/S/g;
871: $result =~ s/�?84;/T/g;
872: $result =~ s/�?85;/U/g;
873: $result =~ s/�?86;/V/g;
874: $result =~ s/�?87;/W/g;
875: $result =~ s/�?88;/X/g;
876: $result =~ s/�?89;/Y/g;
877: $result =~ s/�?90;/Z/g;
878: $result =~ s/�?91;/[/g;
879: $result =~ s/�?92;/\\/g;
880: $result =~ s/�?93;/]/g;
881: # $result =~ s/�?94;//g;
882: # $result =~ s/�?95;//g;
883: $result =~ s/�?96;/`/g;
884: $result =~ s/�?97;/a/g;
885: $result =~ s/�?98;/b/g;
886: $result =~ s/�?99;/c/g;
887: $result =~ s/d/d/g;
888: $result =~ s/e/e/g;
889: $result =~ s/f/f/g;
890: $result =~ s/g/g/g;
891: $result =~ s/h/h/g;
892: $result =~ s/i/i/g;
893: $result =~ s/j/j/g;
894: $result =~ s/k/k/g;
895: $result =~ s/l/l/g;
896: $result =~ s/m/m/g;
897: $result =~ s/n/n/g;
898: $result =~ s/o/o/g;
899: $result =~ s/p/p/g;
900: $result =~ s/q/q/g;
901: $result =~ s/r/r/g;
902: $result =~ s/s/s/g;
903: $result =~ s/t/t/g;
904: $result =~ s/u/u/g;
905: $result =~ s/v/v/g;
906: $result =~ s/w/w/g;
907: $result =~ s/x/x/g;
908: $result =~ s/y/y/g;
909: $result =~ s/z/z/g;
910: $result =~ s/{/\\{/g;
911: $result =~ s/|/\|/g;
912: $result =~ s/}/\\}/g;
913: $result =~ s/~/\~/g;
914: $result =~ s/‚/,/g;
915: # $result =~ s/ƒ//g;
916: $result =~ s/„/''/g;
917: $result =~ s/…/\$\\ldots\$/g;
918: $result =~ s/†/\$\\dagger\$/g;
919: $result =~ s/‡/\$\\ddagger\$/g;
920: # $result =~ s/ˆ//g;
921: # $result =~ s/‰//g;
922: # $result =~ s/Š//g;
923: $result =~ s/‹/\$<\$/g;
924: # $result =~ s/Œ//g;
925: $result =~ s/‘/`/g;
926: $result =~ s/’/'/g;
927: $result =~ s/“/``/g;
928: $result =~ s/”/''/g;
929: $result =~ s/•/\$\\bullet\$/g;
930: # $result =~ s/–//g;
931: # $result =~ s/—//g;
932: $result =~ s/˜/~/g;
933: # $result =~ s/™//g;
934: # $result =~ s/š//g;
935: $result =~ s/›/\$>\$/g;
936: $result =~ s/œ/\\{\\oe\\}/g;
937: $result =~ s/Ÿ/\\"\\{Y\\}/g;
938: $result =~ s/ //g;
939: $result =~ s/ //g;
940: $result =~ s/¡/!`/g;
941: $result =~ s/¡/!`/g; #`
942: # $result =~ s/¢//g;
943: # $result =~ s/¢//g;
944: $result =~ s/£/\\pounds/g;
945: $result =~ s/£/\\pounds/g;
946: # $result =~ s/¤//g;
947: # $result =~ s/¤//g;
948: # $result =~ s/¥//g;
949: # $result =~ s/¥//g;
950: # $result =~ s/¦//g;
951: # $result =~ s/¦//g;
952: # $result =~ s/§//g;
953: # $result =~ s/§//g;
954: # $result =~ s/¨//g;
955: # $result =~ s/¨//g;
956: $result =~ s/©/\\copyright/g;
957: $result =~ s/©/\\copyright/g;
958: # $result =~ s/ª//g;
959: # $result =~ s/ª//g;
960: # $result =~ s/«//g;
961: # $result =~ s/«//g;
962: $result =~ s/¬/\$\\neg\$/g;
963: $result =~ s/¬/\$\\neg\$/g;
964: # $result =~ s/­//g;
965: # $result =~ s/­//g;
966: # $result =~ s/®//g;
967: # $result =~ s/®//g;
968: # $result =~ s/¯//g;
969: # $result =~ s/¯//g;
970: $result =~ s/°/\$^{\\circ}\$/g;
971: $result =~ s/°/\$^{\\circ}\$/g;
972: $result =~ s/±/\$\\pm\$/g;
973: $result =~ s/±/\$\\pm\$/g;
974: $result =~ s/²/\$^2\$/g;
975: $result =~ s/²/\$^2\$/g;
976: $result =~ s/³/\$^3\$/g;
977: $result =~ s/³/\$^3\$/g;
978: # $result =~ s/´//g;
979: # $result =~ s/´//g;
980: $result =~ s/µ/\$\\mu\$/g;
981: $result =~ s/µ/\$\\mu\$/g;
982: $result =~ s/¶/\\P/g;
983: $result =~ s/¶/\\P/g;
984: $result =~ s/·/\$\\cdot\$/g;
985: $result =~ s/·/\$\\cdot\$/g;
986: # $result =~ s/¸//g;
987: # $result =~ s/¸//g;
988: $result =~ s/¹/\$^1\$/g;
989: $result =~ s/¹/\$^1\$/g;
990: # $result =~ s/º//g;
991: # $result =~ s/º//g;
992: # $result =~ s/»//g;
993: # $result =~ s/»//g;
994: # $result =~ s/¼//g;
995: # $result =~ s/¼//g;
996: # $result =~ s/½//g;
997: # $result =~ s/½//g;
998: # $result =~ s/¾//g;
999: # $result =~ s/¾//g;
1000: $result =~ s/¿/?`/g;
1001: $result =~ s/¿/?`/g; #`
1002: $result =~ s/À/\\`{A}/g;
1003: $result =~ s/À/\\`{A}/g; #`
1004: $result =~ s/Á/\\'{A}/g;
1005: $result =~ s/Á/\\'{A}/g; #'
1006: $result =~ s/Â/\\^{A}/g;
1007: $result =~ s/Â/\\^{A}/g;
1008: $result =~ s/Ã/\\~{A}/g;
1009: $result =~ s/Ã/\\~{A}/g;
1010: $result =~ s/Ä/\\"{A}/g;
1011: $result =~ s/Ä/\\"{A}/g; #"
1012: $result =~ s/Å/{\\AA}/g;
1013: $result =~ s/Å/{\\AA}/g;
1014: $result =~ s/Æ/{\\AE}/g;
1015: $result =~ s/Æ/{\\AE}/g;
1016: # $result =~ s/Ç//g;
1017: # $result =~ s/Ç//g;
1018: $result =~ s/È/\\`{E}/g;
1019: $result =~ s/È/\\`{E}/g; #`
1020: $result =~ s/É/\\'{E}/g; #'
1021: $result =~ s/É/\\'{E}/g; #'
1022: $result =~ s/Ê/\\^{E}/g;
1023: $result =~ s/Ê/\\^{E}/g;
1024: $result =~ s/Ë/\\`{E}/g;
1025: $result =~ s/Ë/\\`{E}/g; #`
1026: $result =~ s/Ì/\\`{I}/g;
1027: $result =~ s/Ì/\\`{I}/g; #`
1028: $result =~ s/Í/\\'{I}/g;
1029: $result =~ s/Í/\\'{I}/g; #'
1030: $result =~ s/Î/\\^{I}/g;
1031: $result =~ s/Î/\\^{I}/g;
1032: $result =~ s/Ï/\\"{I}/g;
1033: $result =~ s/Ï/\\"{I}/g; #"
1034: # $result =~ s/Ð//g;
1035: # $result =~ s/Ð//g;
1036: $result =~ s/Ñ/\\~{N}/g;
1037: $result =~ s/Ñ/\\~{N}/g;
1038: $result =~ s/Ò/\\`{O}/g;
1039: $result =~ s/Ò/\\`{O}/g; #`
1040: $result =~ s/Ó/\\'{O}/g;
1041: $result =~ s/Ó/\\'{O}/g; #'
1042: $result =~ s/Ô/\\^{O}/g;
1043: $result =~ s/Ô/\\^{O}/g;
1044: $result =~ s/Õ/\\~{O}/g;
1045: $result =~ s/Õ/\\~{O}/g;
1046: $result =~ s/Ö/\\"{O}/g;
1047: $result =~ s/Ö/\\"{O}/g; #"
1048: $result =~ s/×/\$\\times\$/g;
1049: $result =~ s/×/\$\\times\$/g;
1050: $result =~ s/Ø/{\\O}/g;
1051: $result =~ s/Ø/{\\O}/g;
1052: $result =~ s/Ù/\\`{U}/g;
1053: $result =~ s/Ù/\\`{U}/g; #`
1054: $result =~ s/Ú/\\'{U}/g; #'
1055: $result =~ s/Ú/\\'{U}/g; #'
1056: $result =~ s/Û/\\^{U}/g;
1057: $result =~ s/Û/\\^{U}/g;
1058: $result =~ s/Ü/\\"{U}/g; #"
1059: $result =~ s/Ü/\\"{U}/g; #"
1060: $result =~ s/Ý/\\'{Y}/g;
1061: $result =~ s/Ý/\\'{Y}/g; #'
1062: # $result =~ s/Þ//g;
1063: # $result =~ s/Þ//g;
1064: # $result =~ s/ß//g;
1065: # $result =~ s/ß//g;
1066: $result =~ s/à/\\`{a}/g;
1067: $result =~ s/à/\\`{a}/g; #`
1068: $result =~ s/á/\\'{a}/g;
1069: $result =~ s/á/\\'{a}/g; #'
1070: $result =~ s/â/\\^{a}/g;
1071: $result =~ s/â/\\^{a}/g;
1072: $result =~ s/ã/\\~{a}/g;
1073: $result =~ s/ã/\\~{a}/g;
1074: $result =~ s/ä/\\"{a}/g;
1075: $result =~ s/ä/\\"{a}/g; #"
1076: $result =~ s/å/{\\aa}/g;
1077: $result =~ s/å/{\\aa}/g;
1078: $result =~ s/æ/{\\ae}/g;
1079: $result =~ s/æ/{\\ae}/g;
1080: # $result =~ s/ç//g;
1081: # $result =~ s/ç//g;
1082: $result =~ s/è/\\`{e}/g;
1083: $result =~ s/è/\\`{e}/g; #`
1084: $result =~ s/é/\\'{e}/g;
1085: $result =~ s/é/\\'{e}/g; #'
1086: $result =~ s/ê/\\^{e}/g;
1087: $result =~ s/ê/\\^{e}/g;
1088: $result =~ s/ë/\\"{e}/g;
1089: $result =~ s/ë/\\"{e}/g; #"
1090: $result =~ s/ì/\\`{i}/g;
1091: $result =~ s/ì/\\`{i}/g; #`
1092: $result =~ s/í/\\'{i}/g;
1093: $result =~ s/í/\\'{i}/g; #'
1094: $result =~ s/î/\\^{i}/g;
1095: $result =~ s/î/\\^{i}/g;
1096: $result =~ s/ï/\\"{i}/g;
1097: $result =~ s/ï/\\"{i}/g; #"
1098: # $result =~ s/ð//g;
1099: # $result =~ s/ð//g;
1100: $result =~ s/ñ/\\~{n}/g;
1101: $result =~ s/ñ/\\~{n}/g;
1102: $result =~ s/ò/\\`{o}/g;
1103: $result =~ s/ò/\\`{o}/g; #`
1104: $result =~ s/ó/\\'{o}/g;
1105: $result =~ s/ó/\\'{o}/g; #'
1106: $result =~ s/ô/\\^{o}/g;
1107: $result =~ s/ô/\\^{o}/g;
1108: $result =~ s/õ/\\~{o}/g;
1109: $result =~ s/õ/\\~{o}/g;
1110: $result =~ s/ö/\\"{o}/g;
1111: $result =~ s/ö/\\"{o}/g; #"
1112: $result =~ s/÷/\$\\div\$/g;
1113: $result =~ s/÷/\$\\div\$/g;
1114: $result =~ s/ø/{\\o}/g;
1115: $result =~ s/ø/{\\o}/g;
1116: $result =~ s/ù/\\`{u}/g;
1117: $result =~ s/ù/\\`{u}/g; #`
1118: $result =~ s/ú/\\'{u}/g;
1119: $result =~ s/ú/\\'{u}/g; #'
1120: $result =~ s/û/\\^{u}/g;
1121: $result =~ s/û/\\^{u}/g;
1122: $result =~ s/ü/\\"{u}/g;
1123: $result =~ s/ü/\\"{u}/g; #"
1124: $result =~ s/ý/\\'{y}/g;
1125: $result =~ s/ý/\\'{y}/g; #'
1126: # $result =~ s/þ//g;
1127: # $result =~ s/þ//g;
1128: $result =~ s/ÿ/\\"{y}/g;
1129: $result =~ s/ÿ/\\"{y}/g; #"
1130: $result =~ s/θ/\$\\theta\$/g; #converts theta from html into tex
1131: return $result;
1132: }
1133:
1134:
1135: sub page_format {
1136: my ($papersize,$layout,$numberofcolumns) = @_;
1137: my ($textwidth,$textheight,$oddoffset,$evenoffset) = (0,0,0,0);
1138: if ($papersize=~/Letter/) {
1139: if ($layout eq 'CAPA') {
1140: if ($numberofcolumns == 1) {
1141: $textwidth = '18 cm';
1142: $textheight = '25.9 cm';
1143: $oddoffset = '-0.57 in';
1144: $evenoffset = '-0.57 in';
1145: } elsif ($numberofcolumns == 2) {
1146: $textwidth = '93 mm';
1147: $textheight = '25.9 cm';
1148: $oddoffset = '-0.57 in';
1149: $evenoffset = '-0.57 in';
1150: }
1151: } elsif ($layout eq 'CBI') {
1152: if ($numberofcolumns eq '1') {
1153: $textwidth = '8.8 in';
1154: $textheight = '6.8 in';
1155: $oddoffset = '-40 pt';
1156: $evenoffset = '-60 pt';
1157: } elsif ($numberofcolumns == 2) {
1158: $textwidth = '4.2 in';
1159: $textheight = '6.8 in';
1160: $oddoffset = '-40 pt';
1161: $evenoffset = '-60 pt';
1162: }
1163: }
1164: # } elsif($papersize=~/Legal/) {
1165: # } elsif($papersize=~/Ledger/) {
1166: # } elsif($papersize=~/Executive/) {
1167: } elsif($papersize=~/A4/) {
1168: if ($layout eq 'CAPA') {
1169: if ($numberofcolumns == 1) {
1170: $textwidth = '18 cm';
1171: $textheight = '28 cm';
1172: $oddoffset = '-0.57 in';
1173: $evenoffset = '-0.57 in';
1174: } elsif ($numberofcolumns == 2) {
1175: $textwidth = '96 mm';
1176: $textheight = '2 cm';
1177: $oddoffset = '-0.57 in';
1178: $evenoffset = '-0.57 in';
1179: }
1180: } elsif ($layout eq 'CBI') {
1181: if ($numberofcolumns eq '1') {
1182: $textwidth = '8.5 in';
1183: $textheight = '7.7 in';
1184: $oddoffset = '-40 pt';
1185: $evenoffset = '-60 pt';
1186: } elsif ($numberofcolumns == 2) {
1187: $textwidth = '3.9 in';
1188: $textheight = '7.7 in';
1189: $oddoffset = '-40 pt';
1190: $evenoffset = '-60 pt';
1191: }
1192: }
1193: # } elsif($papersize=~/A3/) {
1194: # } elsif($papersize=~/A2/) {
1195: # } elsif($papersize=~/A5/) {
1196: # } elsif($papersize=~/A6/) {
1197: }
1198: return $textwidth,$textheight,$oddoffset,$evenoffset;
1199: }
1200:
1201:
1202: sub page_format_transformation {
1203: my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment) = @_;
1204: my ($textwidth,$textheight,$oddoffset,$evenoffset);
1205: $assignment=~s/_/ /g;
1206: if ($numberofcolumns != 1) {
1207: ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns);
1208: } else {
1209: ($textwidth,$textheight,$oddoffset,$evenoffset) = ($ENV{'form.width'},$ENV{'form.height'},$ENV{'form.leftmargin'},$ENV{'form.leftmargin'});
1210: }
1211: my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1212: if ($layout eq 'CBI') {
1213: $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{$ENV{'environment.firstname'} $ENV{'environment.lastname'}}} \\hfill $courseidinfo} \\vskip 5 mm /;
1214: } elsif ($layout eq 'CAPA') {
1215: if ($choice ne 'All class print') {
1216: $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\}\\setlength{\\topmargin}{1cm}\\setlength{\\headheight}{1cm}\\setlength{\\headsep}{0.5cm}\\markboth{}{\\textbf{$ENV{'environment.firstname'} $ENV{'environment.lastname'}} $courseidinfo - $assignment}\\pagestyle{myheadings}\\begin{document}\\voffset=-1\.8cm\\setcounter{page}{1}/;
1217: } else {
1218: $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\}\\begin{document}\\voffset=-1\.8cm\\setcounter{page}{1} \\vskip 5 mm /;
1219: }
1220: }
1221: return $text;
1222: }
1223:
1224:
1225: sub page_cleanup {
1226: my $result = shift;
1227:
1228: $result =~ m/\\end{document}(\d*)$/;
1229: my $number_of_columns = $1;
1230: my $insert = '{';
1231: for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; }
1232: $insert .= '}';
1233: $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g;
1234: $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g;
1235: return $result,$number_of_columns;
1236: }
1237:
1238:
1239: sub details_for_menu {
1240:
1241: my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}};
1242: my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'});
1243: my ($map,$id,$resource)=split(/___/,$symbolic);
1244: my $name_of_sequence;
1245: if ($map=~/^uploaded/) {
1246: $name_of_sequence = $hash{'title_'.$hash{'ids_/'.$map}};
1247: } else {
1248: $name_of_sequence = $hash{'title_'.$hash{'ids_/res/'.$map}};
1249: }
1250: if ($name_of_sequence =~ /^\s*$/) {
1251: $map =~ m|([^/]+)$|;
1252: $name_of_sequence = $1;
1253: }
1254: my $name_of_map = $hash{'title_'.$hash{'ids_/res/'.$ENV{'request.course.uri'}}};
1255: if ($name_of_map =~ /^\s*$/) {
1256: $ENV{'request.course.uri'} =~ m|([^/]+)$|;
1257: $name_of_map = $1;
1258: }
1259: return ($name_of_resourse,$name_of_sequence,$name_of_map);
1260:
1261: }
1262:
1263:
1264: sub latex_corrections {
1265:
1266: my ($number_of_columns,$result) = @_;
1267:
1268: $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g;
1269: $result =~ s/\$number_of_columns/$number_of_columns/g;
1270: $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/;
1271: $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g;
1272: $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g;
1273: #-- LaTeX corrections
1274: my $first_comment = index($result,'<!--',0);
1275: while ($first_comment != -1) {
1276: my $end_comment = index($result,'-->',$first_comment);
1277: substr($result,$first_comment,$end_comment-$first_comment+3) = '';
1278: $first_comment = index($result,'<!--',$first_comment);
1279: }
1280: $result =~ s/^\s+$//gm; #remove empty lines
1281: $result =~ s/(\s)(\s+)/$1/g; #removes more than one empty space
1282: $result =~ s/\\\\\s*\\vskip/\\vskip/gm;
1283: $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g;
1284: $result =~ s/{\\par }\s*\\\\/\\\\/gm;
1285: $result =~ s/\\\\\s+\[/ \[/g;
1286: $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g;
1287: #conversion of html characters to LaTeX equivalents
1288: if ($result =~ m/&(\w+|#\d+);/) {
1289: $result = &character_chart($result);
1290: }
1291: $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g;
1292: $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g;
1293:
1294: return $result;
1295: }
1296:
1297:
1298: sub handler {
1299:
1300: my $r = shift;
1301:
1302: my $loaderror=&Apache::lonnet::overloaderror($r);
1303: if ($loaderror) { return $loaderror; }
1304: $loaderror=
1305: &Apache::lonnet::overloaderror($r,
1306: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
1307: if ($loaderror) { return $loaderror; }
1308:
1309: $r->content_type('text/html');
1310: $r->send_http_header;
1311: $r->print(&Apache::loncommon::bodytag("Printing"));
1312:
1313: if ($ENV{'request.course.id'}) {
1314: my $fn=$ENV{'request.course.fn'};
1315: tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640);
1316: }
1317:
1318: #-- start form
1319: &headerform($r);
1320: #-- menu for output
1321: unless ($ENV{'form.phase'}) {
1322: &menu_for_output($r);
1323: }
1324: #-- additional menu for class printing
1325: if ($ENV{'form.phase'} eq 'two') {
1326: if($ENV{'form.choice'} eq 'Standard LaTeX output for whole primary sequence') {
1327: &sequence_content_menu(0,$r);
1328: } elsif($ENV{'form.choice'} eq 'Standard LaTeX output for the primary sequence') {
1329: &sequence_content_menu(1,$r);
1330: } elsif($ENV{'form.choice'} eq 'All class print') {
1331: &additional_class_menu($r);
1332: } elsif($ENV{'form.choice'} eq 'Subdirectory print') {
1333: &problem_choice_menu($r);
1334: } else {
1335: $ENV{'form.phase'} = 'three';
1336: }
1337: }
1338: #-- additional menu for page layout (one column case)
1339: if ($ENV{'form.phase'} eq 'three') {
1340: if($ENV{'form.numberofcolumns'} == 1) {
1341: &additional_print_menu($r);
1342: } else {
1343: $ENV{'form.phase'} = 'four';
1344: }
1345: }
1346: #-- core part
1347: if ($ENV{'form.phase'} eq 'four') {
1348: &output_data($r);
1349: }
1350: untie %hash;
1351: return OK;
1352:
1353: }
1354:
1355:
1356: 1;
1357: __END__
1358:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>