--- loncom/interface/lonprintout.pm 2004/05/03 17:51:11 1.298 +++ loncom/interface/lonprintout.pm 2004/07/15 15:53:30 1.315 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.298 2004/05/03 17:51:11 sakharuk Exp $ +# $Id: lonprintout.pm,v 1.315 2004/07/15 15:53:30 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -421,13 +421,13 @@ sub page_format { } elsif($papersize eq '6') { if ($layout eq 'book') { if ($numberofcolumns == 1) { - $textwidth = '18 cm'; - $textheight = '28 cm'; + $textwidth = '176 mm'; + $textheight = '254 mm'; $oddoffset = '-0.57 in'; $evenoffset = '-0.57 in'; } elsif ($numberofcolumns == 2) { - $textwidth = '96 mm'; - $textheight = '2 cm'; + $textwidth = '91 mm'; + $textheight = '254 mm'; $oddoffset = '-0.57 in'; $evenoffset = '-0.57 in'; } @@ -472,9 +472,13 @@ sub get_course { } sub page_format_transformation { - my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist) = @_; + my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin); - $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header'); + if ($selectionmade eq '4') { + $assignment='Problems from the Whole Course'; + } else { + $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header'); + } ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin); my $name = &get_name(); my $courseidinfo = &get_course(); @@ -540,7 +544,7 @@ sub latex_corrections { # $result =~ s/\\includegraphics{/\\includegraphics\[width=\\minipagewidth\]{/g; $result =~ s/\$number_of_columns/$number_of_columns/g; - $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/; + $result =~ s/(\\end{document})/\\strut\\vspace\*{-4 mm}\\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/; $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 @@ -555,8 +559,7 @@ sub latex_corrections { $result =~ s/\\\\\s*\\vskip/\\vskip/gm; $result =~ s/\\\\\s*\\noindent\s*(\\\\)+/\\\\\\noindent /g; $result =~ s/{\\par }\s*\\\\/\\\\/gm; - $result =~ s/\\\\\s+\[/ \[/g; - $result =~ s/\b__+\b/\\makebox\[1 cm\]\[b\]{\\hrulefill}/g; + $result =~ s/\\\\\s+\[/ \[/g; #conversion of html characters to LaTeX equivalents if ($result =~ m/&(\w+|#\d+);/) { $result = &character_chart($result); @@ -674,11 +677,10 @@ sub get_textwidth { sub unsupported { - my $currentURL=shift; - my $result.='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: '; - if ($currentURL=~/\/(aboutme|syllabus|bulletinboard)$/) { - $result.='\textbf{'.$1.'}'; - } elsif ($currentURL=~/\/ext\//) { + my ($currentURL,$mode)=@_; + if ($mode ne '') {$mode='\\'.$mode} + my $result.= &print_latex_header($mode); + if ($currentURL=~/\/ext\//) { $result.=' \strut \\\\ THIS IS EXTERNAL RESOURCE WITH URL \strut \\\\ '.$currentURL.' '; } else { $result.=$currentURL; @@ -754,7 +756,6 @@ ENDPART } $selectionmade = 1; if ($currentURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { - &Apache::lonnet::logthis("II AMAM IN A WRONG PLACE"); my $rndseed=time; my $texversion=''; if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') { @@ -771,7 +772,10 @@ ENDPART $form{'grade_target'}='tex'; $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; + $form{'suppress_tries'}=$parmhash{'suppress_tries'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; + $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'}; + if ($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') {$form{'problem_split'}='yes';} if ($helper->{'VARS'}->{'curseed'}) { $rndseed=$helper->{'VARS'}->{'curseed'}; } @@ -836,6 +840,7 @@ ENDPART $form{'grade_target'}='tex'; $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; + $form{'suppress_tries'}=$parmhash{'suppress_tries'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; $form{'rndseed'}=$rndseed; $texversion=&Apache::lonnet::ssi($urlp,%form); @@ -877,7 +882,7 @@ ENDPART } if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;} $result .= '\end{document}'; - } elsif ($currentURL=~/\/(smppg|syllabus)$/) { + } elsif ($currentURL=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { my %form; $form{'grade_target'}='tex'; $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); @@ -886,8 +891,7 @@ ENDPART my $texversion=&Apache::lonnet::ssi($currentURL,%form); $result .= $texversion; } else { - &Apache::lonnet::logthis("IIII AMAM IN A WRONG PLACE"); - $result.=&unsupported($currentURL); + $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'}); } } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or @@ -907,7 +911,10 @@ ENDPART $form{'grade_target'}='tex'; $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; + $form{'suppress_tries'}=$parmhash{'suppress_tries'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; + $form{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'}; + if ($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') {$form{'problem_split'}='yes';} my $flag_latex_header_remove = 'NO'; my $flag_page_in_sequence = 'NO'; my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; @@ -948,7 +955,7 @@ ENDPART if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/; } else { - if ($urlp=~/\.(problem|exam|quiz|library)$/) { + if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) { $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); $texversion.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($urlp).'}\vskip 0 mm '; $texversion.=&path_to_problem ($urlp,$LaTeXwidth); @@ -975,8 +982,22 @@ ENDPART } $result .= $texversion; $flag_latex_header_remove = 'YES'; + } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { + my %form; + $form{'grade_target'}='tex'; + $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); + $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; + if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;} + my $texversion=&Apache::lonnet::ssi($urlp,%form); + if ($flag_latex_header_remove ne 'NO') { + $texversion = &latex_header_footer_remove($texversion); + } else { + $texversion =~ s/\\end{document}/\\vskip 0\.5mm\\noindent\\makebox\[\\textwidth\/\$number_of_columns\]\[b\]\{\\hrulefill\}/; + } + $result .= $texversion; + $flag_latex_header_remove = 'YES'; } else { - $texversion=&unsupported($urlp); + $texversion=&unsupported($urlp,$helper->{'VARS'}->{'LATEX_TYPE'}); if ($flag_latex_header_remove ne 'NO') { $texversion = &latex_header_footer_remove($texversion); } else { @@ -1010,9 +1031,16 @@ ENDPART my $flag_latex_header_remove = 'NO'; my %moreenv; $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); + $moreenv{'print_discussions'}=$helper->{'VARS'}->{'PRINT_DISCUSSIONS'}; + if ($helper->{'VARS'}->{'PRINT_DISCUSSIONS'} eq 'yes') {$moreenv{'problem_split'}='yes';} my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1); my $student_counter=-1; foreach my $person (@students) { + my $duefile="/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout.due"; + if (-e $duefile) { + my $temp_file = Apache::File->new('>>'.$duefile); + print $temp_file "1969\n"; + } $student_counter++; my $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'}); my ($output,$fullname)=&print_resources($r,$helper,$person,$type,\%moreenv,\@master_seq,$flag_latex_header_remove); @@ -1038,7 +1066,7 @@ ENDPART } my $flag_latex_header_remove = 'NO'; my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth)); - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline'); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline','75'); my $seed=time+($$<<16)+($$); my @allcodes; if ($old_name) { @@ -1046,6 +1074,7 @@ ENDPART @allcodes=split(',',$result{$old_name}); } else { my %allcodes; + srand($seed); for (my $i=0;$i<$num_todo;$i++) { $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,'6'); } @@ -1092,7 +1121,7 @@ ENDPART if ($urlp =~ m|/home/([^/]+)/public_html|) { $urlp =~ s|/home/([^/]*)/public_html|/~$1|; } else { - $urlp =~ s|^/home/httpd/html||; + $urlp =~ s|^$Apache::lonnet::perlvar{'lonDocRoot'}||; } my $texversion=&Apache::lonnet::ssi($urlp,%form); if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || @@ -1144,7 +1173,7 @@ ENDPART $result .= '\end{document}'; } #-------------------------------------------------------- corrections for the different page formats - $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'}); + $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'},$helper->{'VARS'}->{'TABLE_CONTENTS'},$helper->{'VARS'}->{'TABLE_INDEX'},$selectionmade); $result = &latex_corrections($number_of_columns,$result); for (my $i=1;$i<=$#print_array;$i++) {$print_array[$i] = &latex_corrections($number_of_columns,$print_array[$i]);} #changes page's parameters for the one column output @@ -1220,6 +1249,7 @@ ENDPART &Apache::lonnet::appenv('cgi.'.$identifier.'.file' => $filename, 'cgi.'.$identifier.'.layout' => $laystyle, 'cgi.'.$identifier.'.numcol' => $numberofcolumns, + 'cgi.'.$identifier.'.paper' => $papersize, 'cgi.'.$identifier.'.selection' => $selectionmade, 'cgi.'.$identifier.'tableofcontents' => $helper->{'VARS'}->{'TABLE_CONTENTS'}, 'cgi.'.$identifier.'tableofindex' => $helper->{'VARS'}->{'TABLE_INDEX'}, @@ -1247,7 +1277,6 @@ sub num_to_letters { sub get_CODE { my ($all_codes,$num,$seed,$size)=@_; my $max='1'.'0'x$size; - srand($seed); my $newcode; while(1) { $newcode=sprintf("%06d",int(rand($max))); @@ -1275,35 +1304,59 @@ sub print_resources { ($curresline!~ m/\.(problem|exam|quiz|assess|survey|form|library)$/)) ) { my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline); if (&Apache::lonnet::allowed('bre',$res_url)) { - my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$ENV{'request.course.id'},'tex',$moreenv); - my $lonidsdir=$r->dir_config('lonIDsDir'); - my $envfile=$ENV{'user.environment'}; - $envfile=~/\/([^\/]+)\.id$/; - $envfile=$1; - &Apache::lonnet::transfer_profile_to_env($lonidsdir,$envfile); - my $current_counter=$ENV{'form.counter'}; - if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || - ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { - my %form; - $form{'answer_output_mode'}='tex'; - $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; - my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$ENV{'request.course.id'},%form); - &Apache::lonnet::appenv(('form.counter' => $current_counter)); - if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { - $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/; + if ($res_url=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { + my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$ENV{'request.course.id'},'tex',$moreenv); + my $lonidsdir=$r->dir_config('lonIDsDir'); + my $envfile=$ENV{'user.environment'}; + $envfile=~/\/([^\/]+)\.id$/; + $envfile=$1; + &Apache::lonnet::transfer_profile_to_env($lonidsdir,$envfile); + my $current_counter=$ENV{'form.counter'}; + if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') || + ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) { + my %form; + $form{'answer_output_mode'}='tex'; + $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; + my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$ENV{'request.course.id'},%form); + &Apache::lonnet::appenv(('form.counter' => $current_counter)); + if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') { + $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/; + } else { + $rendered=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); + $rendered.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($curresline).'}\vskip 0 mm '; + $rendered.=&path_to_problem ($curresline,$LaTeXwidth); + $rendered.='\vskip 1 mm '.$ansrendered; + } + } + if ($remove_latex_header eq 'YES') { + $rendered = &latex_header_footer_remove($rendered); } else { - $rendered=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'}); - $rendered.='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($curresline).'}\vskip 0 mm '; - $rendered.=&path_to_problem ($curresline,$LaTeXwidth); - $rendered.='\vskip 1 mm '.$ansrendered; + $rendered =~ s/\\end{document}//; } - } - if ($remove_latex_header eq 'YES') { - $rendered = &latex_header_footer_remove($rendered); + $current_output .= $rendered; + } elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { + my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,$ENV{'request.course.id'},'tex',$moreenv); + my $lonidsdir=$r->dir_config('lonIDsDir'); + my $envfile=$ENV{'user.environment'}; + $envfile=~/\/([^\/]+)\.id$/; + $envfile=$1; + &Apache::lonnet::transfer_profile_to_env($lonidsdir,$envfile); + my $current_counter=$ENV{'form.counter'}; + if ($remove_latex_header eq 'YES') { + $rendered = &latex_header_footer_remove($rendered); + } else { + $rendered =~ s/\\end{document}//; + } + $current_output .= $rendered.'\vskip 0.5mm\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\strut \vskip 0 mm \strut '; } else { - $rendered =~ s/\\end{document}//; + my $rendered = &unsupported($res_url,$helper->{'VARS'}->{'LATEX_TYPE'}); + if ($remove_latex_header ne 'NO') { + $rendered = &latex_header_footer_remove($rendered); + } else { + $rendered =~ s/\\end{document}//; + } + $current_output .= $rendered; } - $current_output .= $rendered; } $remove_latex_header = 'YES'; } @@ -1317,7 +1370,7 @@ sub print_resources { } else { my $blankpages = ''; for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blankpages.='\clearpage\strut\clearpage';} - $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 }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}}} \vskip -5 mm '.$current_output; + $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}}} \vskip -5 mm '.$current_output; } return ($current_output,$fullname); @@ -1484,7 +1537,7 @@ sub printHelper { # "Delete everything after the last slash." $subdir =~ s|/[^/]+$||; if (not $helper->{VARS}->{'construction'}) { - $subdir='/home/httpd/html/res/'.$subdir; + $subdir=$Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$subdir; } # "Remove all duplicate slashes." $subdir =~ s|/+|/|g; @@ -1561,7 +1614,8 @@ HELPERFRAGMENT # If the user is priviledged, allow them to print all # problems in the course, optionally for selected students - if ($userPriviledged && ($helper->{VARS}->{'postdata'}=~/\/res\//)) { + if ($userPriviledged && + ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) { push @{$printChoices}, ['Problems from entire course', 'all_problems', 'ALL_PROBLEMS']; &Apache::lonxml::xmlparse($r, 'helper', < @@ -1683,7 +1737,7 @@ CHOOSE_ANON2 } # FIXME: That RE should come from a library somewhere. - if ((((&Apache::lonnet::allowed('bre',$subdir) eq 'F') and ($helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) or defined $helper->{'VARS'}->{'construction'}) and $ENV{'request.role.adv'} and $subdir ne '/home/httpd/html/res/') { + if ((((&Apache::lonnet::allowed('bre',$subdir) eq 'F') and ($helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) or defined $helper->{'VARS'}->{'construction'}) and $ENV{'request.role.adv'} and $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/') { push @{$printChoices}, ["".&mt('Problems')." ".&mt('from current subdirectory')." $subdir", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR']; my $f = '$filename'; @@ -1810,6 +1864,15 @@ CHOOSE_FROM_ANY_SEQUENCE ['Yes', 'yes'] ]; Apache::lonhelper::dropdown->new(); addMessage(""); + addMessage("Print Discussions: "); + $paramHash = Apache::lonhelper::getParamHash(); + $paramHash->{'variable'} = 'PRINT_DISCUSSIONS'; + $helper->declareVar('PRINT_DISCUSSIONS'); + $paramHash->{CHOICES} = [ + ['No', 'no'], + ['Yes', 'yes'] ]; + Apache::lonhelper::dropdown->new(); + addMessage(""); } if ($helper->{'VARS'}->{'construction'}) { @@ -1956,9 +2019,12 @@ STATEHTML $result .= "\n"; $result .= "