--- loncom/interface/lonprintout.pm 2019/02/21 20:40:12 1.627.2.27 +++ loncom/interface/lonprintout.pm 2012/12/21 18:51:49 1.628 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.627.2.27 2019/02/21 20:40:12 raeburn Exp $ +# $Id: lonprintout.pm,v 1.628 2012/12/21 18:51:49 bisitz Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,6 +27,7 @@ # package Apache::lonprintout; use strict; +use POSIX; use Apache::Constants qw(:common :http); use Apache::lonxml; use Apache::lonnet; @@ -46,6 +47,7 @@ use File::Basename; use HTTP::Response; use LONCAPA::map(); +use POSIX qw(ctime); use Apache::lonlocal; use Carp; use LONCAPA; @@ -147,7 +149,8 @@ sub printable_sequence { # Return: # XML that can be parsed by the helper to drive the state machine. # -sub create_incomplete_folder_selstud_helper { +sub create_incomplete_folder_selstud_helper($helper) +{ my ($helper, $map) = @_; @@ -157,7 +160,7 @@ sub create_incomplete_folder_selstud_hel my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_PEOPLE_SEQ', 'Select problem(s) to print', - 'multichoice="1" toponly="1" addstatus="1" closeallpages="1" modallink="1"', + 'multichoice="1" toponly="1" addstatus="1" closeallpages="1"', 'RESOURCES', 'CHOOSE_STUDENTS_INCOMPLETE', $map, @@ -206,7 +209,7 @@ sub create_incomplete_course_helper { my $resource_chooser = &generate_resource_chooser('INCOMPLETE_PROBLEMS_COURSE_RESOURCES', 'Select problem(s) to print', - 'multichoice = "1" suppressEmptySequences="0" addstatus="1" closeallpagtes="1" modallink="1"', + 'multichoice = "1" suppressEmptySequences="0" addstatus="1" closeallpagtes="1"', 'RESOURCES', 'INCOMPLETE_PROBLEMS_COURSE_STUDENTS', '', @@ -252,7 +255,7 @@ sub create_incomplete_folder_helper { my $resource_chooser = &generate_resource_chooser('CHOOSE_INCOMPLETE_SEQ', 'Select problem(s) to print', - 'multichoice="1", toponly ="1", addstatus="1", closeallpages="1" modallink="1"', + 'multichoice="1", toponly ="1", addstatus="1", closeallpages="1"', 'RESOURCES', 'PAGESIZE', $map, @@ -306,8 +309,7 @@ CHOOSE_STUDENTS # this_state - State name of the chooser. # prompt_text - Text to use to prompt user. # resource_options - Resource tag options e.g. -# "multichoice='1', toponly='1', addstatus='1', -# modallink='1'" +# "multichoice='1', toponly='1', addstatus='1'" # that control the selection and appearance of the # resource selector. # variable - Name of the variable to hold the choice @@ -493,7 +495,7 @@ RESOURCE_SELECTOR # # @return ($open, $close) # -# @note If open/close dates are not defined they will be returned as undef +# @note If open/close dates are not defined they will be retunred as undef # @note It is possible for there to be no overlap in which case -1,-1 # will be returned. # @note The algorithm used is to take the latest open date and the earliest end date. @@ -523,7 +525,7 @@ sub compute_open_window { # If no overlap...both are -1 as promised. - if (($earliest_close ne '') && ($latest_open ne '') + if (defined($earliest_close) && defined($latest_open) && ($earliest_close < $latest_open)) { $latest_open = -1; $earliest_close = -1; @@ -571,14 +573,11 @@ sub printable { # # @return (opendate, closedate) # -# @note If open/close dates are not defined they will be returned as undef +# @note If open/close dates are not defined they will be retunred as undef # @note It is possible for there to be no overlap in which case -1,-1 # will be returned. # @note The algorithm used is to take the latest open date and the earliest end date. -# For consistency with &printable() in lonnavmaps.pm determination of start -# date for printing checks printstartdate param first, then, if not set, -# opendate param, then, if not set, contentopen param. - +# sub get_print_dates { my $res = shift; @@ -597,18 +596,7 @@ sub get_print_dates { foreach my $part (@parts) { my $partopen = $res->parmval('printstartdate', $part); my $partclose = $res->parmval('printenddate', $part); - if (!$partopen) { - $partopen = $res->parmval('opendate',$part); - } - if (!$partopen) { - $partopen = $res->parmval('contentopen',$part); - } - if ($partopen) { - push(@open_dates, $partopen); - } - if ($partclose) { - push(@close_dates, $partclose); - } + push(@open_dates, $partopen); push(@close_dates, $partclose); } @@ -616,6 +604,13 @@ sub get_print_dates { ($open_date, $close_date) = &compute_open_window(\@open_dates, \@close_dates); + if ($open_date) { + $open_date = POSIX::strftime('%D', localtime($open_date)); + } + if ($close_date) { + $close_date = POSIX::strftime('%D', localtime($close_date)); + } + return ($open_date, $close_date); } @@ -702,12 +697,12 @@ sub incomplete { } } # -# When printing for students, the resources and order of the +# When printing for students, the resoures and order of the # resources may need to be altered if there are folders with # random selectiopn or random ordering (or both) enabled. # This sub computes the set of resources to print for a student # modified both by random ordering and selection and filtered -# to only those that are in the original set selected to be printed. +# to only those that are in the original set selcted to be printed. # # Parameters: # $map - The URL of the folder being printed. @@ -718,9 +713,6 @@ sub incomplete { # $who - Student/domain for whome the sequence will be generated. # $code - CODE being printed when printing Problems/Resources # from folder for CODEd assignments -# $nohidemap - If true, parameter in map for hiddenresource will be -# ignored. The user calling the routine should have -# both the pav and vgr privileges if this is set to true). # # Implicit inputs: # $ @@ -729,7 +721,7 @@ sub incomplete { # print_resources. # sub master_seq_to_person_seq { - my ($map, $seq, $who, $code, $nohidemap) = @_; + my ($map, $seq, $who, $code) = @_; my ($username, $userdomain, $usersection) = split(/:/, $who); @@ -740,14 +732,9 @@ sub master_seq_to_person_seq { my %seq_hash = map {$_ => 1} @$seq; my @output_seq; - - my $unhidden; - if ($nohidemap) { - $unhidden = &Apache::lonnet::clutter($map); - } my $navmap = Apache::lonnavmaps::navmap->new($username, $userdomain, - $code,$unhidden); + $code); my ($start,$finish); if ($map) { @@ -767,6 +754,7 @@ sub master_seq_to_person_seq { # Iterate on the resource..select the items that are randomly selected # and that are in the seq_has. Presumably the iterator will take care # of the random ordering part of the deal. + # my $curres; while ($curres = $iterator->next()) { # @@ -847,9 +835,9 @@ sub set_font_size { if ($font_size ne '') { - $text =~ s/\\begin\{document}/\\begin{document}{\\$font_size/; - $text =~ s/\\end\{document}/}\\end{document}/; + $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/; } + $text =~ s/\\end{document}/}\\end{document}/; return $text; @@ -891,7 +879,7 @@ sub include_pdf { my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'}; $file =~ s{(.*)/res/}{$londocroot/res/}; - open(FILE,">>","$Apache::lonnet::perlvar{'lonPrtDir'}/$env{'user.name'}_$env{'user.domain'}_printout.dat"); + open(FILE,">>$Apache::lonnet::perlvar{'lonPrtDir'}/$env{'user.name'}_$env{'user.domain'}_printout.dat"); print FILE ("$file\n"); close (FILE); @@ -926,13 +914,13 @@ sub include_pdf { sub collect_languages { my $doc = shift; my %languages; - while ($doc =~ /\\selectlanguage\{(\w+)}/mg) { + while ($doc =~ /\\selectlanguage{(\w+)}/mg) { $languages{$1} = 1; # allows us to request each language exactly once. } my @lang_list = (keys(%languages)); # List of unique languages if (scalar @lang_list) { my $babel_header = '\usepackage[' . join(',', @lang_list) .']{babel}'. "\n"; - $doc =~ s/\\begin\{document}/$babel_header\\begin{document}/; + $doc =~ s/\\begin{document}/$babel_header\\begin{document}/; } return $doc; } @@ -1060,12 +1048,12 @@ sub printf_style_subst { # %s - The section if it is supplied. # sub format_page_header { - my ($width, $format, $assignment, $course, $student) = @_; + my ($width, $format, $assignment, $course, $student, $section) = @_; $width = &recalcto_mm($width); # Get width in mm. - my $chars_per_line = int($width/2); # Character/textline. + my $chars_per_line = int($width/1.6); # Character/textline. # Default format? @@ -1081,44 +1069,40 @@ sub format_page_header { # - Allow the assignment to be 2 lines (wrapped). # - my $firstline = "$student $course"; - if (length($firstline) > $chars_per_line) { - my $lastchar = $chars_per_line - length($student) - 1; - if ($lastchar > 0) { - $course = substr($course, 0, $lastchar); - } else { # Nothing left of course: - $course = ''; - } - } - if (length($assignment) > $chars_per_line) { - $assignment = substr($assignment, 0, $chars_per_line); - } + - $format = "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}"; + my $name_length = int($chars_per_line *3 /4); + my $sec_length = int($chars_per_line / 5); - } else { - # An open question is how to handle long user formatted page headers... - # A possible future is to support e.g. %na so that the user can control - # the truncation of the elements that can appear in the header. - # - $format = &printf_style_subst("a", $format, $assignment); - $format = &printf_style_subst("c", $format, $course); - $format = &printf_style_subst("n", $format, $student); - - # If the user put %'s in the format string, they must be escaped - # to \% else LaTeX will think they are comments and terminate - # the line.. which is bad!!! + $format = "%$name_length".'n'; - } + if ($section) { + $format .= ' - Sec: '."%$sec_length".'s'; + } - return $format; + $format .= '\\\\%c \\\\ %a'; + + } + # An open question is how to handle long user formatted page headers... + # A possible future is to support e.g. %na so that the user can control + # the truncation of the elements that can appear in the header. + # + $format = &printf_style_subst("a", $format, $assignment); + $format = &printf_style_subst("c", $format, $course); + $format = &printf_style_subst("n", $format, $student); + $format = &printf_style_subst("s", $format, $section); + + + # If the user put %'s in the format string, they must be escaped + # to \% else LaTeX will think they are comments and terminate + # the line.. which is bad!!! # If the user has role author, $course and $assignment are empty so # there is '\\ \\ ' in the page header. That's cause a error in LaTeX if($format =~ /\\\\\s\\\\\s/) { #TODO find sensible caption for page header - my $testPrintout = '\\\\'.&mt('Authoring Space').' \\\\'.&mt('Test-Printout '); + my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout '); $format =~ s/\\\\\s\\\\\s/$testPrintout/; } # @@ -1240,7 +1224,6 @@ sub is_code_valid { my ($code_type, $code_length) = ('letter', 6); # defaults. my @lines = &Apache::grades::get_scantronformat_file(); foreach my $line (@lines) { - next if (($line =~ /^\#/) || ($line eq '')); my ($name, $type, $length) = (split(/:/, $line))[0,2,4]; if($name eq $code_option) { $code_length = $length; @@ -1334,8 +1317,8 @@ sub compare_names { sub latex_header_footer_remove { my $text = shift; - $text =~ s/\\end\{document}//; - $text =~ s/\\documentclass([^&]*)\\begin\{document}//; + $text =~ s/\\end{document}//; + $text =~ s/\\documentclass([^&]*)\\begin{document}//; return $text; } # @@ -1849,6 +1832,8 @@ sub get_course { my $courseidinfo; if (defined($env{'request.course.id'})) { $courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header'); + my $sec = $env{'request.course.sec'}; + } return $courseidinfo; } @@ -1871,7 +1856,6 @@ sub page_format_transformation { my $name = &get_name(); my $courseidinfo = &get_course(); - if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo } my $header_text = $parmhash{'print_header_format'}; $header_text = &format_page_header($textwidth, $header_text, $assignment, $courseidinfo, $name); @@ -1884,12 +1868,12 @@ sub page_format_transformation { $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}"; } 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\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /; + $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\\usepackage{booktabs}\\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\\usepackage{booktabs}\\begin{document}\n\\voffset=-0\.8 cm\\setcounter{page}{1}\n/; + $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\\usepackage{booktabs}\\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{}\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1} \\vskip 5 mm\n /; + $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{}\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1} \\vskip 5 mm\n /; } if ($papersize eq 'a4') { my $papersize_text; @@ -1898,13 +1882,13 @@ sub page_format_transformation { } else { $papersize_text = '\special{papersize=210mm,297mm}'; } - $text =~ s/(\\begin\{document})/$1$papersize_text/; + $text =~ s/(\\begin{document})/$1$papersize_text/; } } 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/; + $text=~s/(\\begin{document})/\\makeindex $1/; + $text=~s/(\\end{document})/\\strut\\\\\\strut\\printindex $1/; } return $text; } @@ -1913,12 +1897,12 @@ sub page_format_transformation { sub page_cleanup { my $result = shift; - $result =~ m/\\end\{document}(\d*)$/; + $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/(\\begin{longtable})INSERTTHEHEADOFLONGTABLE\\endfirsthead\\endhead/$1$insert/g; $result =~ s/&\s*REMOVETHEHEADOFLONGTABLE\\\\/\\\\/g; return $result,$number_of_columns; } @@ -1954,16 +1938,16 @@ my $end_of_student = "\n".'\special{ps:E sub latex_corrections { my ($number_of_columns,$result,$selectionmade,$answer_mode) = @_; -# $result =~ s/\\includegraphics\{/\\includegraphics\[width=\\minipagewidth\]{/g; +# $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g; my $copyright = ©right_line(); if ($selectionmade eq '1' || $answer_mode eq 'only') { - $result =~ s/(\\end\{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/; + $result =~ s/(\\end{document})/\\strut\\vskip 0 mm $copyright $end_of_student $1/; } else { - $result =~ s/(\\end\{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/; + $result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\newline $copyright $end_of_student $1/; } $result =~ s/\$number_of_columns/$number_of_columns/g; - $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; + $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,'