--- loncom/interface/lonprintout.pm 2002/07/16 20:30:53 1.38 +++ loncom/interface/lonprintout.pm 2002/09/11 20:18:08 1.61 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.38 2002/07/16 20:30:53 www Exp $ +# $Id: lonprintout.pm,v 1.61 2002/09/11 20:18:08 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,10 +43,16 @@ use strict; use Apache::Constants qw(:common :http); use Apache::lonxml; use Apache::lonnet; +use Apache::loncommon; use Apache::inputtags; +use Apache::grades; use Apache::edit; use Apache::File(); use POSIX qw(strftime); +use GDBM_File; + + +my %hash; sub headerform { @@ -59,31 +65,43 @@ sub headerform {
$ENV{'form.postdata'}

-

What do you want to print? Make a choice.


ENDHEADER } sub menu_for_output { my $r = shift; + my ($title_for_single_resource,$title_for_sequence) = &details_for_menu; + if ($title_for_single_resource ne '') {$title_for_single_resource = '"'.$title_for_single_resource.'"';} + if ($title_for_sequence ne '') {$title_for_sequence = '"'.$title_for_sequence.'"';} $r->print(<What do you want to print? Make a choice.
- Current document + Current document $title_for_single_resource (you will print what you see on the screen)
- All problems from the primary sequence
- The whole primary sequence (problems plus all html and xml files)
- All problems from the top level sequence
-
ENDMENUOUT1 - my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'}); - $subdirtoprint =~ s/\/[^\/]+$//; - if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') { + if ((not $ENV{'request.role'}=~m/^au\./) and (not $ENV{'request.role'}=~m/^ca\./)) { $r->print(< All problems from current subdirectory (where this particular problem is)
+ All problems from the primary sequence $title_for_sequence
+ The whole primary sequence $title_for_sequence (problems plus all html and xml files)
ENDMENUOUT2 -} - $r->print(<print(< All problems from the top level sequence
+
+ Print assignment $title_for_sequence (all problems from the primary sequence) for group of students

+ENDMENUOUT6 + } + my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'}); + $subdirtoprint =~ s/\/[^\/]+$//; + if (&Apache::lonnet::allowed('bre',$subdirtoprint) eq 'F') { + $r->print(< All problems from current subdirectory (where this particular problem is)
+ENDMENUOUT4 + } + $r->print(<

And what page format do you prefer?

@@ -94,21 +112,214 @@ ENDMENUOUT2 +
  - Number of columns: + Number of columns: + + Paper size (format [width x height]):

+ENDMENUOUT5 +} + + +sub problem_choice_menu { + my $r = shift; + my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'}); + $subdirtoprint =~ s/\/[^\/]+$//; + my @list_of_files = (); + if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) { + $subdirtoprint =~ s/^[^~]*~(\w+)\//\/home\/$1\/public_html\//; + } else { + $subdirtoprint =~ s/.*(\/res\/)/$1/; + } + my @content_directory = (); + if ($ENV{'request.role'}=~m/^au\./ or $ENV{'request.role'}=~m/^ca\./) { + @content_directory = &Apache::lonnet::dirlist($subdirtoprint,$ENV{'user.domain'}, $ENV{'user.name'},''); + } else { + @content_directory = &Apache::lonnet::dirlist($subdirtoprint); + } + for (my $iy=0;$iy<=$#content_directory;$iy++) { + my @tempo_array = split(/&/,$content_directory[$iy]); + if ($tempo_array[0] =~ m/^[^\.]+\.(problem|exam|quiz|assess|survey|form|library)$/) { + push(@list_of_files,$tempo_array[0]); + } + } + $subdirtoprint =~ s/\/$//; + for (my $i=0;$i<=$#list_of_files;$i++) { + $list_of_files[$i] = $subdirtoprint.'/'.$list_of_files[$i]; + } + $r->print(< + + + +

Mark problems which you want to print

+ +  + +

+ENDMENUOUT1 + my $i; + foreach my $file (@list_of_files) { + $r->print('
'. + $file); + $i++; + } + $r->print(< + + + +ENDMENUOUT2 +} + + +sub additional_class_menu { + my $r = shift; + $r->print(< + + + +

Mark students which assignments you want to print

+ENDMENUOUT1 + my %courselist=&Apache::lonnet::dump( + 'classlist', + $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, + $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + my $now=time; + $r->print(< + function checkall() { + for (i=0; i +  + +  + +

+ENDDISHEADER + my $i = 0; + foreach (sort keys %courselist) { + my ($end,$start)=split(/\:/,$courselist{$_}); + my $active=1; + if (($end) && ($now>$end)) { $active=0; } + if ($active) { + my ($sname,$sdom)=split(/\:/,$_); + my %reply=&Apache::lonnet::get('environment', + ['firstname','middlename','lastname','generation'], + $sdom,$sname); + my $section=&Apache::lonnet::usection + ($sdom,$sname,$ENV{'request.course.id'}); + $r->print( + '
'. + $reply{'firstname'}.' '. + $reply{'middlename'}.' '. + $reply{'lastname'}.' '. + $reply{'generation'}. + ' ('.$_.') '.$section); + $i++; + } + } + $r->print(< + + + +ENDMENUOUT2 +} + + +sub additional_print_menu { + my $r = shift; + my $what_to_print = ''; + for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) { + $what_to_print .= ''; + } + for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) { + $what_to_print .= ''; + } + $r->print(< + + + + + +Define page layout parameters:
+Width:
+Height:
+Left margin:
+ + -ENDMENUOUT3 +ENDMENUOUT } - - sub output_data { my $r = shift; $r->print(<|) / \$$1\$ /g; #corrects < or > $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g; $result =~ s/{\\par }\s*\\\\/\\\\/gm; $result =~ s/\\\\\s+\[/ \[/g; $result =~ s/θ/\$\\theta\$/g; #converts theta from html into tex - $result =~ s/\b_+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g; + $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g; #conversion of html characters to LaTeX equivalents if ($result =~ m/&(\w+|#\d+);/) { $result = &character_chart($result); } + $result =~ s/(\\end{tabular})\s*\\vskip 0 mm/$1/g; + $result =~ s/(\\begin{enumerate})\s*\\noindent/$1/g; #-- writing .tex file in prtspool my $temp_file; my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex"; @@ -298,89 +586,110 @@ ENDPART } print $temp_file $result; $r->print(< + FINALEND } + +sub coming_from_hash { + + my $mainsequence = shift; + my @resourcelist = (); + my $mapstart = $hash{'map_start_'.$mainsequence}; + my $mapfinish = $hash{'map_finish_'.$mainsequence}; + my $current_resource = $mapstart; + while ($current_resource ne $mapfinish) { + if (not $hash{'src_'.$current_resource}=~/\.sequence$/) { + push @resourcelist,$hash{'src_'.$current_resource}; + } else { + push @resourcelist,&coming_from_hash($hash{'src_'.$current_resource}); + } + $current_resource = $hash{'goesto_'.$hash{'to_'.$current_resource}}; + } + return @resourcelist; +} + + sub character_chart { my $result = shift; - $result =~ s/ //g; - $result =~ s/ //g; - $result =~ s/ //g; - $result =~ s/ / /g; - $result =~ s/!/!/g; - $result =~ s/"/"/g; - $result =~ s/"/"/g; #" - $result =~ s/#/\\#/g; - $result =~ s/$/\\\$/g; - $result =~ s/%/\\%/g; - $result =~ s/&/\\&/g; + $result =~ s/�?0?7;//g; + $result =~ s/�?0?9;//g; + $result =~ s/�?10;//g; + $result =~ s/�?13;//g; + $result =~ s/�?32;/ /g; + $result =~ s/�?33;/!/g; + $result =~ s/�?34;/"/g; + $result =~ s/"/"/g; + $result =~ s/�?35;/\\#/g; +# $result =~ s/�?36;/\\\$/g; + $result =~ s/�?37;/\\%/g; + $result =~ s/�?38;/\\&/g; $result =~ s/&/\\&/g; - $result =~ s/'/'/g; - $result =~ s/(/(/g; - $result =~ s/)/)/g; - $result =~ s/*/\*/g; - $result =~ s/+/\+/g; - $result =~ s/,/,/g; - $result =~ s/-/-/g; - $result =~ s/./\./g; - $result =~ s///\//g; - $result =~ s/0/0/g; - $result =~ s/1/1/g; - $result =~ s/2/2/g; - $result =~ s/3/3/g; - $result =~ s/4/4/g; - $result =~ s/5/5/g; - $result =~ s/6/6/g; - $result =~ s/7/7/g; - $result =~ s/8/8/g; - $result =~ s/9/9/g; - $result =~ s/:/:/g; - $result =~ s/;/;/g; - $result =~ s/</\$<\$/g; + $result =~ s/�?39;/'/g; + $result =~ s/�?40;/(/g; + $result =~ s/�?41;/)/g; + $result =~ s/�?42;/\*/g; + $result =~ s/�?43;/\+/g; + $result =~ s/�?44;/,/g; + $result =~ s/�?45;/-/g; + $result =~ s/�?46;/\./g; + $result =~ s/�?47;/\//g; + $result =~ s/�?48;/0/g; + $result =~ s/�?49;/1/g; + $result =~ s/�?50;/2/g; + $result =~ s/�?51;/3/g; + $result =~ s/�?52;/4/g; + $result =~ s/�?53;/5/g; + $result =~ s/�?54;/6/g; + $result =~ s/�?55;/7/g; + $result =~ s/�?56;/8/g; + $result =~ s/�?57;/9/g; + $result =~ s/�?58;/:/g; + $result =~ s/�?59;/;/g; + $result =~ s/�?60;/\$<\$/g; $result =~ s/</\$<\$/g; - $result =~ s/=/\$=\$/g; - $result =~ s/>/\$>\$/g; + $result =~ s/�?61;/\$=\$/g; + $result =~ s/�?62;/\$>\$/g; $result =~ s/>/\$>\$/g; - $result =~ s/?/?/g; -# $result =~ s/@//g; - $result =~ s/A/A/g; - $result =~ s/B/B/g; - $result =~ s/C/C/g; - $result =~ s/D/D/g; - $result =~ s/E/E/g; - $result =~ s/F/F/g; - $result =~ s/G/G/g; - $result =~ s/H/H/g; - $result =~ s/I/I/g; - $result =~ s/J/J/g; - $result =~ s/K/K/g; - $result =~ s/L/L/g; - $result =~ s/M/M/g; - $result =~ s/N/N/g; - $result =~ s/O/O/g; - $result =~ s/P/P/g; - $result =~ s/Q/Q/g; - $result =~ s/R/R/g; - $result =~ s/S/S/g; - $result =~ s/T/T/g; - $result =~ s/U/U/g; - $result =~ s/V/V/g; - $result =~ s/W/W/g; - $result =~ s/X/X/g; - $result =~ s/Y/Y/g; - $result =~ s/Z/Z/g; - $result =~ s/[/[/g; - $result =~ s/\/\\/g; - $result =~ s/]/]/g; -# $result =~ s/^//g; -# $result =~ s/_//g; - $result =~ s/`/`/g; - $result =~ s/a/a/g; - $result =~ s/b/b/g; - $result =~ s/c/c/g; + $result =~ s/�?63;/?/g; +# $result =~ s/�?64;//g; + $result =~ s/�?65;/A/g; + $result =~ s/�?66;/B/g; + $result =~ s/�?67;/C/g; + $result =~ s/�?68;/D/g; + $result =~ s/�?69;/E/g; + $result =~ s/�?70;/F/g; + $result =~ s/�?71;/G/g; + $result =~ s/�?72;/H/g; + $result =~ s/�?73;/I/g; + $result =~ s/�?74;/J/g; + $result =~ s/�?75;/K/g; + $result =~ s/�?76;/L/g; + $result =~ s/�?77;/M/g; + $result =~ s/�?78;/N/g; + $result =~ s/�?79;/O/g; + $result =~ s/�?80;/P/g; + $result =~ s/�?81;/Q/g; + $result =~ s/�?82;/R/g; + $result =~ s/�?83;/S/g; + $result =~ s/�?84;/T/g; + $result =~ s/�?85;/U/g; + $result =~ s/�?86;/V/g; + $result =~ s/�?87;/W/g; + $result =~ s/�?88;/X/g; + $result =~ s/�?89;/Y/g; + $result =~ s/�?90;/Z/g; + $result =~ s/�?91;/[/g; + $result =~ s/�?92;/\\/g; + $result =~ s/�?93;/]/g; +# $result =~ s/�?94;//g; +# $result =~ s/�?95;//g; + $result =~ s/�?96;/`/g; + $result =~ s/�?97;/a/g; + $result =~ s/�?98;/b/g; + $result =~ s/�?99;/c/g; $result =~ s/d/d/g; $result =~ s/e/e/g; $result =~ s/f/f/g; @@ -464,8 +773,8 @@ sub character_chart { # $result =~ s/®//g; # $result =~ s/¯//g; # $result =~ s/¯//g; - $result =~ s/°/\$^\\{\\circ\\}\$/g; - $result =~ s/°/\$^\\{\\circ\\}\$/g; + $result =~ s/°/\$^{\\circ}\$/g; + $result =~ s/°/\$^{\\circ}\$/g; $result =~ s/±/\$\\pm\$/g; $result =~ s/±/\$\\pm\$/g; $result =~ s/²/\$^2\$/g; @@ -627,6 +936,9 @@ sub character_chart { return $result; } + +#'"` + sub additional_cleanup { my $result = shift; my $first_app = index($result,'\documentclass',0); @@ -673,10 +985,10 @@ sub content_map { $_ = $chunk; m/to=\"(\d+)\"/; push @number_seq,$1; - $startlink = index($map_string,'from="'.$1.'"',$startlink); + $startlink = index($map_string,'from="'.$1.'"',0); $startlink = rindex($map_string,'',$startlink); @@ -712,12 +1024,30 @@ sub content_map { } +sub details_for_menu { + + my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}}; + my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'}); + $symbolic =~ m/([^_]+)_/; + my $primary_sequence = '/res/'.$1; + my $name_of_sequence = $hash{'title_'.$hash{'ids_'.$primary_sequence}}; + + return $name_of_resourse,$name_of_sequence; + +} + sub handler { my $r = shift; $r->content_type('text/html'); $r->send_http_header; + $r->print(&Apache::loncommon::bodytag("Printing")); + + if ($ENV{'request.course.id'}) { + my $fn=$ENV{'request.course.fn'}; + tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER(),0640); + } #-- start form &headerform($r); @@ -725,14 +1055,34 @@ sub handler { unless ($ENV{'form.phase'}) { &menu_for_output($r); } +#-- additional menu for class printing + if ($ENV{'form.phase'} eq 'two') { + if($ENV{'form.choice'} eq 'All class print') { + &additional_class_menu($r); + } elsif($ENV{'form.choice'} eq 'Subdirectory print') { + &problem_choice_menu($r); + } else { + $ENV{'form.phase'} = 'three'; + } + } +#-- additional menu for page layout (one column case) + if ($ENV{'form.phase'} eq 'three') { + if($ENV{'form.numberofcolumns'} == 1) { + &additional_print_menu($r); + } else { + $ENV{'form.phase'} = 'four'; + } + } #-- core part - if ($ENV{'form.phase'} eq 'two') { + if ($ENV{'form.phase'} eq 'four') { &output_data($r); - } + } + untie %hash; return OK; - + } + 1; __END__