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