--- loncom/interface/lonprintout.pm 2002/12/23 19:11:33 1.100 +++ loncom/interface/lonprintout.pm 2005/02/09 19:53:55 1.343.2.3 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.100 2002/12/23 19:11:33 albertel Exp $ +# $Id: lonprintout.pm,v 1.343.2.3 2005/02/09 19:53:55 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -25,17 +25,6 @@ # # http://www.lon-capa.org/ # -# (Internal Server Error Handler -# -# (Login Screen -# 5/21/99,5/22,5/25,5/26,5/31,6/2,6/10,7/12,7/14, -# 1/14/00,5/29,5/30,6/1,6/29,7/1,11/9 Gerd Kortemeyer) -# -# 3/1/1 Gerd Kortemeyer) -# -# 3/1 Gerd Kortemeyer -# -# 9/17 Alex Sakharuk # package Apache::lonprintout; @@ -49,1285 +38,2293 @@ use Apache::grades; use Apache::edit; use Apache::File(); use Apache::lonnavmaps; +use Apache::lonratedt; use POSIX qw(strftime); -use GDBM_File; +use Apache::lonlocal; - -my %hash; my $LaTeXwidth = 0; -sub headerform { - my $r = shift; - $r->print(< - -LON-CAPA output for printing - - -
-ENDHEADER - if ($ENV{'form.postdata'}=~m|^/res/|) { - $r->print(<Path to current document: $ENV{'form.postdata'}

-ENDHEADER1 +# Compare two students by name. The students are in the form +# returned by the helper: +# user:domain:section:last, first:status +# This is a helper function for the perl sort built-in therefore: +# Implicit Inputs: +# $a - The first element to compare (global) +# $b - The second element to compare (global) +# Returns: +# -1 - $a < $b +# 0 - $a == $b +# +1 - $a > $b +# Note that the initial comparison is done on the last names with the +# first names only used to break the tie. +# +# +sub compare_names { + # First split the names up into the primary fields. + + my ($u1, $d1, $s1, $n1, $stat1) = split(/:/, $a); + my ($u2, $d2, $s2, $n2, $stat2) = split(/:/, $b); + + # Now split the last name and first name of each n: + # + + my ($l1,$f1) = split(/,/, $n1); + my ($l2,$f2) = split(/,/, $n2); + + # We don't bother to remove the leading/trailing whitespace from the + # firstname, unless the last names compare identical. + + if($l1 lt $l2) { + return -1; + } + if($l1 gt $l2) { + return 1; } -} + # Break the tie on the first name, but there are leading (possibly trailing + # whitespaces to get rid of first + # + $f1 =~ s/^\s+//; # Remove leading... + $f1 =~ s/\s+$//; # Trailing spaces from first 1... + + $f2 =~ s/^\s+//; + $f2 =~ s/\s+$//; # And the same for first 2... -sub menu_for_output { - my $r = shift; - my ($title_for_single_resource,$title_for_sequence,$title_for_main_map) = &details_for_menu; - my $assignment = $title_for_sequence; - 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.'"';} - if ($title_for_main_map ne '') {$title_for_main_map = '"'.$title_for_main_map.'"';} - $ENV{'form.postdata'} =~ s|http://[^/]+||; - my $subdir_to_print = $ENV{'form.postdata'}; - $subdir_to_print =~ m/\/([^\/]+)$/; - $subdir_to_print =~ s/\Q$1\E//; - $r->print(<What do you want to print? Make a choice.
- - - - Current document $title_for_single_resource -(prints what you just saw on the screen)
-ENDMENUOUT1 - if ($ENV{'form.postdata'}=~/\/res\//) { - $r->print(< Problem(s) from $title_for_sequence
- Problem(s) plus page(s) or html/xml file(s) from $title_for_sequence
-ENDMENUOUT2 - } - if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($ENV{'form.postdata'}=~/\/res\//)) { - $r->print(< All problems in this course (warning: this may be time consuming)
-
- All problems from $title_for_sequence for selected students

-ENDMENUOUT6 + if($f1 lt $f2) { + return -1; } - my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'}); - $subdirtoprint =~ s/\/[^\/]+$//; - 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)/)) { - $r->print(< Problems from current subdirectory $subdir_to_print
-ENDMENUOUT4 - } - $r->print(<



-

And what page format do you prefer?

- - - - - - - -
- Landscape
- Portrait
-
  - Number of columns: - - Paper size (format [width x height]): -
-
- -ENDMENUOUT5 + if($f1 gt $f2) { + return 1; + } + + # Must be the same name. + + return 0; +} + +sub latex_header_footer_remove { + my $text = shift; + $text =~ s/\\end{document}//; + $text =~ s/\\documentclass([^&]*)\\begin{document}//; + return $text; } -sub sequence_content_menu { - my ($key_to,$r) = @_; - my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'}); - my @sequence = split('___',$symbolic); - my $primary_sequence = '/res/'.$sequence[0]; - my @master_seq = &coming_from_hash($primary_sequence,$sequence[0]); - my @master_seq_view = @master_seq; - for (my $i=0;$i<=$#master_seq_view;$i++) { - $master_seq_view[$i]=~/\/([^\/]+)$/; - $master_seq_view[$i]=$1; - } - $r->print(< - - - - - -

Mark item(s) which you want to print

- -  - -

-ENDMENUOUT1 - my $inc=0; - for (my $i=0;$i<=$#master_seq_view;$i++) { - if ($key_to==1 && $master_seq_view[$i]=~/\.(problem|exam|quiz|assess|survey|form|library)$/) { - $r->print('
'."\n". - $master_seq_view[$i]); - $inc++; - } elsif ($key_to==0 && $master_seq_view[$i]=~/\.(problem|exam|quiz|assess|survey|form|library|xml|htm|html|page)$/) { - $r->print('
'. - $master_seq_view[$i]); - $inc++; - } + ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin); + my $name = &get_name(); + my $courseidinfo = &get_course(); + if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } + my $topmargintoinsert = ''; + if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';} + my $fancypagestatement=''; + if ($numberofcolumns eq '2') { + $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}"; + } else { + $fancypagestatement="\\rhead{}\\chead{}\\lhead{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}"; } - $r->print(< - - - -ENDMENUOUT2 + if ($layout eq 'album') { + $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\n\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\n\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\n\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /; + } elsif ($layout eq 'book') { + if ($choice ne 'All class print') { + $text =~ s/\\begin{document}/\\textheight $textheight\\oddsidemargin = $evenoffset\\evensidemargin = $evenoffset $topmargintoinsert\n\\textwidth= $textwidth\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\n\\renewcommand{\\ref}{\\keephidden\}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\\pagestyle{fancy}$fancypagestatement\\begin{document}\n\\voffset=-0\.8 cm\\setcounter{page}{1}\n/; + } else { + $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1} \\vskip 5 mm\n /; + } + if ($papersize eq 'a4') { + $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/; + } + } + if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;} + if ($indexlist eq 'yes') { + $text=~s/(\\begin{document})/\\makeindex $1/; + $text=~s/(\\end{document})/\\strut\\\\\\strut\\printindex $1/; + } + return $text; +} + +sub page_cleanup { + my $result = shift; + + $result =~ m/\\end{document}(\d*)$/; + my $number_of_columns = $1; + my $insert = '{'; + for (my $id=1;$id<=$number_of_columns;$id++) { $insert .='l'; } + $insert .= '}'; + $result =~ s/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g; + $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g; + return $result,$number_of_columns; } -sub problem_choice_menu { - my $r = shift; - my $subdirtoprint = &Apache::lonnet::filelocation("",$ENV{'form.url'}); - $subdirtoprint =~ s/\/[^\/]+$//; - my @list_of_files = (); - my @content_directory = (); - if ($subdirtoprint =~ m|/home/([^/]+)/public_html|) { - #localmachine CSTR space - my $user=$1; - my $domain=$Apache::lonnet::perlvar{'lonDefDomain'}; - @content_directory = &Apache::lonnet::dirlist($subdirtoprint, - $domain, $user,''); - } else { - @content_directory = &Apache::lonnet::dirlist($subdirtoprint); +sub details_for_menu { + my ($helper)=@_; + my $postdata=$ENV{'form.postdata'}; + if (!$postdata) { $postdata=$helper->{VARS}{'postdata'}; } + my $name_of_resource = &Apache::lonnet::gettitle($postdata); + my $symbolic = &Apache::lonnet::symbread($postdata); + my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic); + $map=&Apache::lonnet::clutter($map); + my $name_of_sequence = &Apache::lonnet::gettitle($map); + if ($name_of_sequence =~ /^\s*$/) { + $map =~ m|([^/]+)$|; + $name_of_sequence = $1; } - 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=0; - foreach my $file (@list_of_files) { - $r->print('
'. - $file); - $i++; + $result =~ s/(\\end{longtable}\s*)(\\strut\\newline\\noindent\\makebox\[\\textwidth\/$number_of_columns\]\[b\]{\\hrulefill})/$2$1/g; + $result =~ s/(\\end{longtable}\s*)\\strut\\newline/$1/g; +#-- LaTeX corrections + my $first_comment = index($result,'',$first_comment); + substr($result,$first_comment,$end_comment-$first_comment+3) = ''; + $first_comment = index($result,'',$first_comment); - substr($result,$first_comment,$end_comment-$first_comment+3) = ''; - $first_comment = index($result,'