--- loncom/interface/lonprintout.pm 2003/05/02 13:39:04 1.141 +++ loncom/interface/lonprintout.pm 2003/05/12 18:47:07 1.162 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.141 2003/05/02 13:39:04 sakharuk Exp $ +# $Id: lonprintout.pm,v 1.162 2003/05/12 18:47:07 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1349,34 +1349,7 @@ ENDPART $laystyle='book'; } my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format_new($papersize,$laystyle,$numberofcolumns); - - - - -# my $choice = $ENV{'form.choice'}; -# my $layout = $ENV{'form.layout'}; -# my $numberofcolumns = $ENV{'form.numberofcolumns'}; -# my $papersize = $ENV{'form.papersize'}; -# my $laystyle = 'book'; my $assignment = $ENV{'form.assignment'}; -# if ($choice eq 'Subdirectory print') { -# if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';} -# if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';} -# if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;} -# } -# if (($choice eq 'Standard LaTeX output for current document') && -# ($ENV{'form.url'}=~m|^/~|)) { -# if ($ENV{'form.layout'} eq '') {$layout = 'CAPA';} -# if ($ENV{'form.papersize'} eq '') {$papersize = 'Letter [8 1/2x11 in]';} -# if ($ENV{'form.numberofcolumns'} eq '') {$numberofcolumns = 2;} -# } - - -# my ($textwidth,$textheight,$oddoffset,$evenoffset) = &page_format($papersize,$layout,$numberofcolumns); -# if ($numberofcolumns == 1) { -# $textwidth=$ENV{'form.width'}; -# $textheight=$ENV{'form.height'}; -# } my $LaTeXwidth; if ($textwidth=~/(\d+)\s*cm/) { $LaTeXwidth = $1*10; @@ -1386,27 +1359,33 @@ ENDPART $LaTeXwidth = $1*25.4; } $LaTeXwidth.=' mm'; - - + if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') { - #-- single document - problem, page, html, xml, ... + #-- single document - problem, page, html, xml, ... + my $currentURL; + if ($helper->{'VARS'}->{'construction'} ne '1') { + #prins published resource + $currentURL=$helper->{'VARS'}->{'postdata'}; + } else { + #prins resource from the construction space + $currentURL=$helper->{'VARS'}->{'filename'}; + $currentURL=~s/\/home\//\/~/; + $currentURL=~s/public_html\///; + } $selectionmade = 1; - if ($helper->{'VARS'}->{'url'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { - my %moreenv; - $moreenv{'form.grade_target'}='tex'; - if (&Apache::lonnet::allowed('bre',$helper->{'VARS'}->{'url'})) { - $helper->{'VARS'}->{'url'}=~s/http:\/\/[^\/]+//; - } - $moreenv{'request.filename'}=$helper->{'VARS'}->{'url'}; - $moreenv{'form.textwidth'}=$LaTeXwidth; - &Apache::lonnet::appenv(%moreenv); - my $texversion=&Apache::lonnet::ssi($helper->{'VARS'}->{'url'}); - &Apache::lonnet::delenv('form.grade_target','form.textwidth','form.counter'); - $result .= $texversion; - if ($helper->{'VARS'}->{'url'}=~m/\.page\s*$/) { - ($result,$number_of_columns) = &page_cleanup($result); - } - } else { + if ($currentURL=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) { + my %moreenv; + $moreenv{'form.grade_target'}='tex'; + $moreenv{'request.filename'}=$currentURL; + $moreenv{'form.textwidth'}=$LaTeXwidth; + &Apache::lonnet::appenv(%moreenv); + my $texversion=&Apache::lonnet::ssi($currentURL); + &Apache::lonnet::delenv('form.grade_target','form.textwidth','form.counter'); + $result .= $texversion; + if ($currentURL=~m/\.page\s*$/) { + ($result,$number_of_columns) = &page_cleanup($result); + } + } else { # $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: '; # if ($ENV{'form.url'}=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) { # $result.=$1; @@ -1414,27 +1393,23 @@ ENDPART # $result.=$ENV{'form.url'}; # } # $result.=' \end{document}' - } - - - } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') { + } + } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') or + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or + ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')) { #-- produce an output string my $flag_latex_header_remove = 'NO'; my $flag_page_in_sequence = 'NO'; my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; - -# foreach my $key (@master_seq) { -# $r->print(' '.$key.'
'); -# } -# return OK; - for (my $i=0;$i<=$#master_seq;$i++) { $master_seq[$i]=~/___\d+___(.*)$/; my $urlp='/res/'.$1; if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') { - $selectionmade = 2; -# } elsif ($choice eq 'Standard LaTeX output for whole primary sequence') { -# $selectionmade = 3; + $selectionmade = 2; + } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') { + $selectionmade = 3; + } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') { + $selectionmade = 4; } my %moreenv; $moreenv{'form.grade_target'}='tex'; @@ -1460,158 +1435,106 @@ ENDPART &Apache::lonnet::delenv('form.counter'); if ($flag_page_in_sequence eq 'YES') {$result =~ s/\\usepackage{calc}/\\usepackage{calc}\\usepackage{longtable}/;} $result .= '\end{document}'; -# } elsif ($choice eq 'Standard LaTeX output for the top level sequence') { -# # where is the main sequence of the course? -# $selectionmade = 4; -# my $main_seq=&Apache::lonnet::clutter($ENV{'request.course.uri'}); -# my @file_seq = &coming_from_hash($main_seq); -# for (my $i=0;$i<=$#file_seq;$i++) { -# my ($path,$title,$symb) = split /&&/,$file_seq[$i]; -# $file_seq[$i] = $path.'&&'.$symb; -# } -# my $flag_latex_header_remove = 'NO'; -# #-- produce an output string -# for (my $i=0;$i<=$#file_seq;$i++) { -# if (not $file_seq[$i]=~/^&&/) { -# my ($urlp,$symb) = split /&&/, $file_seq[$i]; -# $urlp=~s/\/home\/httpd\/html//; -# if ($urlp=~m/\.(problem|exam|quiz|assess|survey|form|library)/) { -# my %moreenv; -# $moreenv{'form.grade_target'}='tex'; -# $moreenv{'form.textwidth'}=$LaTeXwidth; -# &Apache::lonnet::appenv(%moreenv); -# my $texversion=&Apache::lonnet::ssi($urlp,('symb'=>$symb)); -# &Apache::lonnet::delenv('form.grade_target','form.textwidth'); -# if ($flag_latex_header_remove ne 'NO') { -# $texversion = &latex_header_footer_remove($texversion); -# } else { -# $texversion =~ s/\\end{document}//; -# } -# $result .= $texversion; -# $flag_latex_header_remove = 'YES'; -# } -# } -# } -# $result .= '\end{document}'; -# } elsif ($choice eq 'All class print') { -# #-- prints assignments for whole class or for selected students -# $selectionmade = 5; -# my @students = (); -# for (my $i=0; $i<$ENV{'form.numberofstudents'};$i++) { -# if ($ENV{'form.whomtoprint'.$i}=~/:/) { -# push @students,$ENV{'form.whomtoprint'.$i}; -# } -# } -# #where is the primary sequence containing current resource (the same for all students)? -# my $symbolic = &Apache::lonnet::symbread($ENV{'form.url'}); -# my @sequence = split('___',$symbolic); -# my $primary_sequence; -# -# $primary_sequence=&Apache::lonnet::clutter($sequence[0]); -# my @master_seq = &coming_from_hash($primary_sequence); -# for (my $i=0;$i<=$#master_seq;$i++) { -# my ($path,$title,$symb) = split /&&/,$master_seq[$i]; -# $master_seq[$i] = $path.'&&'.$symb; -# } -# #loop over students -# my $flag_latex_header_remove = 'NO'; -# my %moreenv; -# $moreenv{'form.textwidth'}=$LaTeXwidth; -# &Apache::lonnet::appenv(%moreenv); -# my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1); -# foreach my $person (@students) { -# my $current_output = ''; + } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') { + #-- prints assignments for whole class or for selected students + $selectionmade=5; + my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'}; + my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; + #loop over students + my $flag_latex_header_remove = 'NO'; + my %moreenv; + $moreenv{'form.textwidth'}=$LaTeXwidth; + &Apache::lonnet::appenv(%moreenv); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1); + foreach my $person (@students) { + my $current_output = ''; # my ($usersection,$username,$userdomain) = split /:/,$person; -# my $fullname = &get_name($username,$userdomain); -# #goes through all resources, checks if they are available for current student, and produces output -# foreach my $curresline (@master_seq) { -# my ($curres,$symb) = split /&&/, $curresline; -# if ($curres=~ m/\.(problem|exam|quiz|assess|survey|form|library)/) { -# my ($map,$id,$res_url) = split(/___/,$symb); -# if (&Apache::lonnet::allowed('bre',$res_url)) { -# my $rendered = &Apache::loncommon::get_student_view($symb,$username,$userdomain, -# $ENV{'request.course.id'},'tex'); -# if ($flag_latex_header_remove eq 'YES') { -# $rendered = &latex_header_footer_remove($rendered); -# } else { -# $rendered =~ s/\\end{document}//; -# } -# $current_output .= $rendered; -# } -# $flag_latex_header_remove = 'YES'; -# } -# } -# my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'}; -# if ($current_output=~/\\documentclass/) { -# $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\vskip 3 mm /; -# } else { -# my $blanspages = ''; -# for (my $j=0;$j<$ENV{'form.addedpages'};$j++) {$blanspages.='\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 \\vskip 3mm'.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}} - '.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}\hskip 1.4in } \vskip 5 mm '.$current_output; -# } -# $result .= $current_output; -# &Apache::lonnet::delenv('form.counter'); -# &Apache::lonxml::init_counter(); -# &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, -# 'last student '.$fullname); -# } -# &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); -# $result .= '\end{document}'; -# &Apache::lonnet::delenv('form.textwidth'); -# } elsif ($choice eq 'Subdirectory print') { -# #prints selected problems from the subdirectory -# $selectionmade = 6; -# my @list_of_files = (); -# for (my $i=0; $i<$ENV{'form.numberofproblems'};$i++) { -# if ($ENV{'form.whattoprint'.$i}=~/^\//) { -# push @list_of_files,$ENV{'form.whattoprint'.$i}; -# } -# } -# my $flag_latex_header_remove = 'NO'; -# for (my $i=0;$i<=$#list_of_files;$i++) { -# my $urlp = $list_of_files[$i]; -# if ($urlp=~/\//) { -# my %moreenv; -# $moreenv{'form.grade_target'}='tex'; -# $moreenv{'form.textwidth'}=$LaTeXwidth; -# &Apache::lonnet::appenv(%moreenv); -# if ($urlp =~ m|/home/([^/]+)/public_html|) { -# $urlp =~ s|/home/([^/]*)/public_html|/~$1|; -# } else { -# $urlp =~ s|^/home/httpd/html||; -# } -# my $texversion=&Apache::lonnet::ssi($urlp); -# &Apache::lonnet::delenv('form.grade_target','form.textwidth'); -# #this chunck is responsible for printing the path to problem -# my $newurlp = ''; -# my $HowMany = length($urlp)*2; -# if ($HowMany > $LaTeXwidth) { -# my @temporrary = split '/',$urlp; -# my $HowManyNew = 0; -# for (my $ii=0;$ii<=$#temporrary;$ii++) { -# if ($temporrary[$ii] ne '') { -# $HowManyNew += length($temporrary[$ii])*2; -# if ($HowManyNew < $LaTeXwidth ) { -# $newurlp .= '/'.$temporrary[$ii]; -# } else { -# $HowManyNew = 0; -# $newurlp .= '|\vskip -1 mm \noindent \verb|'; -# $ii--; -# } -# } -# } -# } -# $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/; -# if ($flag_latex_header_remove ne 'NO') { -# $texversion = &latex_header_footer_remove($texversion); -# } else { -# $texversion =~ s/\\end{document}//; -# } -# $result .= $texversion; -# } -# $flag_latex_header_remove = 'YES'; -# } -# $result .= '\end{document}'; + my ($username,$userdomain) = split /:/,$person; + my $fullname = &get_name($username,$userdomain); + #goes through all resources, checks if they are available for current student, and produces output + foreach my $curresline (@master_seq) { + if ($curresline=~ m/\.(problem|exam|quiz|assess|survey|form|library)$/) { + my ($map,$id,$res_url) = split(/___/,$curresline); + if (&Apache::lonnet::allowed('bre',$res_url)) { + my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain, + $ENV{'request.course.id'},'tex'); + if ($flag_latex_header_remove eq 'YES') { + $rendered = &latex_header_footer_remove($rendered); + } else { + $rendered =~ s/\\end{document}//; + } + $current_output .= $rendered; + } + $flag_latex_header_remove = 'YES'; + } + } + my $courseidinfo = $ENV{'course.'.$ENV{'request.course.id'}.'.description'}; + if ($current_output=~/\\documentclass/) { + $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm}\\usepackage{fancyhdr}\\pagestyle{fancy}\\rhead{}\\chead{} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}} - $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}\\vskip 3 mm /; + } else { + my $blanspages = ''; + for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blanspages.='\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 \\vskip 3mm'.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}} - '.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}\hskip 1.4in } \vskip 5 mm '.$current_output; + } + $result .= $current_output; + &Apache::lonnet::delenv('form.counter'); + &Apache::lonxml::init_counter(); + &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, + 'last student '.$fullname); + } + &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); + $result .= '\end{document}'; + &Apache::lonnet::delenv('form.textwidth'); + } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') { + #prints selected problems from the subdirectory + $selectionmade = 6; + my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'}; + @list_of_files=sort @list_of_files; + my $flag_latex_header_remove = 'NO'; + for (my $i=0;$i<=$#list_of_files;$i++) { + my $urlp = $list_of_files[$i]; + if ($urlp=~/\//) { + my %moreenv; + $moreenv{'form.grade_target'}='tex'; + $moreenv{'form.textwidth'}=$LaTeXwidth; + &Apache::lonnet::appenv(%moreenv); + if ($urlp =~ m|/home/([^/]+)/public_html|) { + $urlp =~ s|/home/([^/]*)/public_html|/~$1|; + } else { + $urlp =~ s|^/home/httpd/html||; + } + my $texversion=&Apache::lonnet::ssi($urlp); + &Apache::lonnet::delenv('form.grade_target','form.textwidth'); + #this chunck is responsible for printing the path to problem + my $newurlp = ''; + my $HowMany = length($urlp)*2; + if ($HowMany > $LaTeXwidth) { + my @temporrary = split '/',$urlp; + my $HowManyNew = 0; + for (my $ii=0;$ii<=$#temporrary;$ii++) { + if ($temporrary[$ii] ne '') { + $HowManyNew += length($temporrary[$ii])*2; + if ($HowManyNew < $LaTeXwidth ) { + $newurlp .= '/'.$temporrary[$ii]; + } else { + $HowManyNew = 0; + $newurlp .= '|\vskip -1 mm \noindent \verb|'; + $ii--; + } + } + } + } + $texversion =~ s/(\\begin{minipage}{\\textwidth})/$1 {\\small\\noindent\\verb|$newurlp\|\\vskip 0 mm}/; + if ($flag_latex_header_remove ne 'NO') { + $texversion = &latex_header_footer_remove($texversion); + } else { + $texversion =~ s/\\end{document}//; + } + $result .= $texversion; + } + $flag_latex_header_remove = 'YES'; + } + $result .= '\end{document}'; } #-------------------------------------------------------- corrections for the different page formats $result = &page_format_transformation_new($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'}); @@ -1635,7 +1558,7 @@ ENDPART } print $temp_file $result; - +# $r->print(< @@ -1657,13 +1580,14 @@ sub handler { return $result; } $helper = $result; - + + - my $key; -# foreach $key (keys %{$helper->{'VARS'}}) { -# $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'
'); -# } -# return OK; + my $key; + foreach $key (keys %{$helper->{'VARS'}}) { + $r->print(' '.$key.'->'.$helper->{'VARS'}->{$key}.'<-
'); + } + return OK; &output_data_new($r,$helper); @@ -1675,12 +1599,12 @@ sub handler { return OK; } - my $loaderror=&Apache::lonnet::overloaderror($r); - if ($loaderror) { return $loaderror; } - $loaderror= - &Apache::lonnet::overloaderror($r, - $ENV{'course.'.$ENV{'request.course.id'}.'.home'}); - if ($loaderror) { return $loaderror; } +# my $loaderror=&Apache::lonnet::overloaderror($r); +# if ($loaderror) { return $loaderror; } +# $loaderror= +# &Apache::lonnet::overloaderror($r, +# $ENV{'course.'.$ENV{'request.course.id'}.'.home'}); +# if ($loaderror) { return $loaderror; } $r->content_type('text/html'); $r->send_http_header; @@ -1764,37 +1688,72 @@ sub printHelper { Apache::loncommon::get_unprocessed_cgi($ENV{QUERY_STRING}); my $helper = Apache::lonhelper::helper->new("Printing Wizard"); + $helper->declareVar('symb'); + $helper->declareVar('postdata'); + $helper->declareVar('filename'); + $helper->declareVar('construction'); # This will persistently load in the data we want from the # very first screen. - if (defined($ENV{'form.postdata'})) { - $helper->{VARS}->{'postdata'} = $ENV{'form.postdata'}; - } - if (defined($ENV{'form.symb'})) { - $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + # Detect whether we're coming from construction space + if ($ENV{'form.postdata'} =~ /http:\/\// ) { + $ENV{'form.postdata'} =~ /http:\/\/[a-zA-Z.]+\/~([a-zA-Z0-9]+)\/(.*)/; + $helper->{VARS}->{'filename'} = "/home/$1/public_html/$2"; + $helper->{VARS}->{'construction'} = 1; + } else { + if ($ENV{'form.postdata'}) { + $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($ENV{'form.postdata'}); + } + if ($ENV{'form.symb'}) { + $helper->{VARS}->{'symb'} = $ENV{'form.symb'}; + } + if ($ENV{'form.url'}) { + $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + } } - if (defined($ENV{'form.url'})) { - $helper->{VARS}->{'url'} = $helper->{VARS}->{'postdata'}; + + if ($ENV{'form.symb'}) { + $helper->{VARS}->{'symb'} = $ENV{'form.symb'}; } + if ($ENV{'form.url'}) { + $helper->{VARS}->{'symb'} = &Apache::lonnet::symbread($helper->{VARS}->{'postdata'}); + } + my ($resourceTitle,$sequenceTitle,$mapTitle) = &details_for_menu; $helper->{VARS}->{'assignment'} = $sequenceTitle; - if (!$resourceTitle) { # if the resource doesn't have a title, use the filename - my $url = $helper->{VARS}->{'postdata'}; - $resourceTitle = substr($url, rindex($url, '/') + 1); - } - - Apache::lonhelper::registerHelperTags(); - + # Extract map my $symb = $helper->{VARS}->{'symb'}; - my ($map, $id, $url) = split(/__/, $symb); + my ($map, $id, $url); + my $subdir; + + # Get the resource name from construction space + if ($helper->{VARS}->{'construction'}) { + $resourceTitle = substr($helper->{VARS}->{'filename'}, + rindex($helper->{VARS}->{'filename'}, '/')+1); + $subdir = substr($helper->{VARS}->{'filename'}, + 0, rindex($helper->{VARS}->{'filename'}, '/') + 1); + } else { + ($map, $id, $url) = split(/___/, $symb); + $helper->{VARS}->{'postdata'} = Apache::lonnet::clutter($url); + + if (!$resourceTitle) { # if the resource doesn't have a title, use the filename + my $url = $helper->{VARS}->{'postdata'}; + $resourceTitle = substr($url, rindex($url, '/') + 1); + } + $subdir = &Apache::lonnet::filelocation("", $url); + } - my $subdir = &Apache::lonnet::filelocation("", $helper->{VARS}->{'postdata'}); + Apache::lonhelper::registerHelperTags(); # "Delete everything after the last slash." $subdir =~ s|/[^/]+$||; + if (not $helper->{VARS}->{'construction'}) { + $subdir='/home/httpd/html/res/'.$subdir; + } + # What can be printed is a very dynamic decision based on # lots of factors. So we need to dynamically build this list. @@ -1809,38 +1768,40 @@ sub printHelper { # the helper by hand. my $printChoices = []; my $paramHash; - # We can always print the current screen. - push @{$printChoices}, ["$resourceTitle (exactly what was on the screen)", 'current_document', 'FINAL']; + if ($resourceTitle) { + push @{$printChoices}, ["$resourceTitle (prints what you just saw on the screen)", 'current_document', 'PAGESIZE']; + } + + $r->print($helper->{VARS}->{'postdata'}); # If we're in a sequence... - if ($helper->{VARS}->{'postdata'} =~ /\/res\//) { + if ($helper->{'VARS'}->{'construction'} ne '1') { # Allow problems from sequence - push @{$printChoices}, ["Problems from $sequenceTitle", 'map_problems', 'CHOOSE_PROBLEMS']; + push @{$printChoices}, ["Problem(s) from $sequenceTitle", 'map_problems', 'CHOOSE_PROBLEMS']; # Allow all resources from sequence - push @{$printChoices}, ["Problems and pages from $sequenceTitle", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML']; + push @{$printChoices}, ["Everything (problem(s), page(s), html/xml file(s)) from $sequenceTitle", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML']; my $isProblem = '$res->is_problem();'; my $isProblemOrMap = '$res->is_problem() || $res->is_map()'; my $isNotMap = '!$res->is_map();'; my $symb = '$res->symb();'; my $helperFragment = < - Select problems to print: - - FINAL - return $isProblemOrMap - return $isProblem + + (mark them then click "next" button)
+ + PAGESIZE + return $isProblem $map return $symb
- - Select resources to print: - - FINAL - return $isNotMap; + + (mark them then click "next" button)
+ + PAGESIZE + return $isNotMap; $map return $symb @@ -1853,40 +1814,53 @@ HELPERFRAGMENT # If the user is priviledged, allow them to print all # problems in the course, optionally for selected students if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($helper->{VARS}->{'postdata'}=~/\/res\//)) { - push @{$printChoices}, ['All problems in course (may take a lot of time)', 'all_problems', 'ALL_PROBLEMS']; + push @{$printChoices}, ['Problems in this course', 'all_problems', 'ALL_PROBLEMS']; push @{$printChoices}, ["Problems from $sequenceTitle for selected students", 'problems_for_students', 'CHOOSE_STUDENTS']; my $isProblem = '$res->is_problem();'; my $isProblemOrMap = '$res->is_problem() || $res->is_map()'; my $symb = '$res->symb();'; &Apache::lonxml::xmlparse($r, 'helper', < - Select problems to print: + + (mark them then click "next" button)
- FINAL + PAGESIZE return $isProblemOrMap return $isProblem return $symb
- - Select the students you wish to print the problems for: - + + (do not forget to select assignment itself - make another selection below)
+ +
Select resources for the assignment
+ + return $isProblem + $map + return $symb + +
How should the results be printed?
+ + Print students assignments without separations (as uniform flow) + Start student assignment from new page (add pagefeed after each student) + Add one emty page after each student assignment + Add two emty page after each student assignment +
CHOOSE_STUDENTS } # 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)/)) { - push @{$printChoices}, ["Problems from $subdir", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR']; + 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'}) { + push @{$printChoices}, ["Problems from current subdirectory $subdir", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR']; my $f = '$filename'; my $xmlfrag = < - Select problems you wish to print from $subdir + + (mark them then click "next" button)
- FINAL + PAGESIZE return '$subdir'; CHOOSE_FROM_SUBDIR @@ -1901,17 +1875,37 @@ CHOOSE_FROM_SUBDIR } # Generate the first state, to select which resources get printed. - Apache::lonhelper::state->new("START", "Selecting Resources to Print"); + Apache::lonhelper::state->new("START", "What do you want to print? Make a choice."); $paramHash = Apache::lonhelper::getParamHash(); - $paramHash->{MESSAGE_TEXT} = "What do you want to print?"; + $paramHash->{MESSAGE_TEXT} = ""; Apache::lonhelper::message->new(); $paramHash = Apache::lonhelper::getParamHash(); $paramHash->{'variable'} = 'PRINT_TYPE'; $helper->declareVar('PRINT_TYPE'); $paramHash->{CHOICES} = $printChoices; Apache::lonhelper::choices->new(); + + if ($ENV{'request.role.adv'}) { + $paramHash = Apache::lonhelper::getParamHash(); + $paramHash->{MESSAGE_TEXT} = "
Next option is available only for advanced users:
"; + Apache::lonhelper::message->new(); + $paramHash = Apache::lonhelper::getParamHash(); + $paramHash->{'variable'} = 'ANSWER_TYPE'; + $helper->declareVar('ANSWER_TYPE'); + $paramHash->{CHOICES} = [ + ['Print without answer', '1'], + ['Print with answers', '0'] ]; + Apache::lonhelper::choices->new(); + } + Apache::lonprintout::page_format_state->new("FORMAT"); + # Generate the PAGESIZE state which will offer the user the margin + # choices if they select one column + Apache::lonhelper::state->new("PAGESIZE", "Set Margins"); + Apache::lonprintout::page_size_state->new('pagesize', 'FORMAT', 'FINAL'); + + $helper->process(); # MANUAL BAILOUT CONDITION: @@ -1989,31 +1983,28 @@ sub render { my $helper = Apache::lonhelper::getHelper(); my $result = ''; my $var = $self->{'variable'}; - my $curVal = $helper->{VARS}->{$var}; - - my ($layout, $cols, $paper) = split(/\|/, $curVal); $result .= <How should the printing be formatted?

+

What page format do you prefer?

- - + + -
LayoutColumnsPage layoutNumber of columns Paper type
- Landscape
- Portrait + Landscape
+ Portrait
+ + + + + + + + + + + + + + + + +
Width: + +
Height: + +
Left margin: + +
+ +

Hint: Some instructors like to leave scratch space for the student by +making the width much smaller then the width of the page.

+ +ELEMENTHTML + + return $result; +} + +# If the user didn't select 1 column, skip this state. +sub preprocess { + my $self = shift; + my $helper = Apache::lonhelper::getHelper(); + + my $format = $helper->{VARS}->{$self->{'formatvar'}}; + if (substr($format, 2, 1) ne '1') { + $helper->changeState($self->{NEXTSTATE}); + } + + return 1; +} + +sub postprocess { + my $self = shift; + + my $var = $self->{'variable'}; + my $helper = Apache::lonhelper->getHelper(); + my $width = $helper->{VARS}->{$var .'.width'} = $ENV{"form.${var}.width"}; + my $height = $helper->{VARS}->{$var .'.height'} = $ENV{"form.${var}.height"}; + my $lmargin = $helper->{VARS}->{$var .'.lmargin'} = $ENV{"form.${var}.lmargin"}; + $helper->{VARS}->{$var .'.widthunit'} = $ENV{"form.${var}.widthunit"}; + $helper->{VARS}->{$var .'.heightunit'} = $ENV{"form.${var}.heightunit"}; + $helper->{VARS}->{$var .'.lmarginunit'} = $ENV{"form.${var}.lmarginunit"}; + + my $error = ''; + + # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed + # by an optional period, followed by digits, ending the string + + if ($width !~ /^-?[0-9]+(\.[0-9]*)?$/) { + $error .= "Invalid width; please type only a number.
\n"; + } + if ($height !~ /^-?[0-9]+(\.[0-9]*)?$/) { + $error .= "Invalid height; please type only a number.
\n"; + } + if ($lmargin !~ /^-?[0-9]+(\.[0-9]*)?$/) { + $error .= "Invalid left margin; please type only a number.
\n"; + } + + if (!$error) { + Apache::lonhelper::getHelper()->changeState($self->{NEXTSTATE}); + return 1; + } else { + $self->{ERROR_MSG} = $error; + return 0; + } +} + + + __END__