--- loncom/interface/lonprintout.pm 2004/03/15 22:32:37 1.282
+++ loncom/interface/lonprintout.pm 2004/03/23 16:17:48 1.285
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Printout
#
-# $Id: lonprintout.pm,v 1.282 2004/03/15 22:32:37 albertel Exp $
+# $Id: lonprintout.pm,v 1.285 2004/03/23 16:17:48 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -170,7 +170,7 @@ sub character_chart {
$result =~ s/&\#153;/\\texttrademark /g;
$result =~ s/&\#156;/\\oe/g;
$result =~ s/&\#159;/\\\"Y/g;
- $result =~ s/&(\#160|nbsp);//g;
+ $result =~ s/&(\#160|nbsp);/~/g;
$result =~ s/&(\#161|iexcl);/!\`/g;
$result =~ s/&(\#162|cent);/\\textcent /g;
$result =~ s/&(\#163|pound);/\\pounds /g;
@@ -661,6 +661,16 @@ sub recalcto_mm {
return $LaTeXwidth;
}
+sub get_textwidth {
+ my ($helper,$LaTeXwidth)=@_;
+ if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
+ $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
+ $moreenv{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'});
+ } else {
+ $moreenv{'textwidth'}=$LaTeXwidth;
+ }
+}
+
sub output_data {
my ($r,$helper,$rparmhash) = @_;
my %parmhash = %$rparmhash;
@@ -740,12 +750,7 @@ ENDPART
}
my %form;
$form{'grade_target'}='tex';
- if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
- $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
- $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'});
- } else {
- $form{'textwidth'}=$LaTeXwidth;
- }
+ $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
$form{'problem_split'}=$parmhash{'problem_stream_switch'};
$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
if ($helper->{'VARS'}->{'curseed'}) {
@@ -810,12 +815,7 @@ ENDPART
if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
my %form;
$form{'grade_target'}='tex';
- if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
- $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
- $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'});
- } else {
- $form{'textwidth'}=$LaTeXwidth;
- }
+ $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
$form{'problem_split'}=$parmhash{'problem_stream_switch'};
$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
$form{'rndseed'}=$rndseed;
@@ -861,12 +861,7 @@ ENDPART
} elsif ($currentURL=~/\/smppg$/) {
my %form;
$form{'grade_target'}='tex';
- if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
- $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
- $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'});
- } else {
- $form{'textwidth'}=$LaTeXwidth;
- }
+ $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
my $texversion=&Apache::lonnet::ssi($currentURL,%form);
$result .= $texversion;
@@ -888,12 +883,7 @@ ENDPART
#-- produce an output string
my %form=();
$form{'grade_target'}='tex';
- if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
- $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
- $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'});
- } else {
- $form{'textwidth'}=$LaTeXwidth;
- }
+ $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
$form{'problem_split'}=$parmhash{'problem_stream_switch'};
$form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
my $flag_latex_header_remove = 'NO';
@@ -974,12 +964,16 @@ 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 (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') || ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')) {
+ } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')){
#-- prints assignments for whole class or for selected students
+ my $type;
if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') {
$selectionmade=5;
+ $type='problems';
} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students') {
$selectionmade=8;
+ $type='resources';
}
my @students=split /\|\|\|/, $helper->{'VARS'}->{'STUDENTS'};
if ($helper->{'VARS'}->{'NUMBER_TO_PRINT'} eq '0' ||
@@ -990,82 +984,25 @@ ENDPART
#loop over students
my $flag_latex_header_remove = 'NO';
my %moreenv;
- if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
- $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
- $moreenv{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'});
- } else {
- $moreenv{'textwidth'}=$LaTeXwidth;
- }
+ $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1);
my $student_counter=-1;
foreach my $person (@students) {
$student_counter++;
- my $current_output = '';
- my ($username,$userdomain,$usersection) = split /:/,$person;
- my $fullname = &get_name($username,$userdomain);
-
- if ($parmhash{'anonymous_quiz'}=~/yes/) {$fullname=' ';} #put here something reasonable for anonymous exams or quiz
- #goes through all resources, checks if they are available for current student, and produces output
- &Apache::lonnet::delenv('form.counter');
- &Apache::lonxml::init_counter();
- foreach my $curresline (@master_seq) {
- if ((($curresline=~ m/\.(problem|exam|quiz|assess|survey|form|library)$/) && ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students')) || ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')) {
- 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/;
- } 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 ($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 = &get_course();
- if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
- if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}
- my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
- if ($current_output=~/\\documentclass/) {
- $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}}\\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 '.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}}} \vskip -5 mm '.$current_output;
- }
- $print_array[int($student_counter/$helper->{'VARS'}->{'NUMBER_TO_PRINT'})].=$current_output;
- $student_names[int($student_counter/$helper->{'VARS'}->{'NUMBER_TO_PRINT'})].=$person.':'.$fullname.'_END_';
- &Apache::lonnet::delenv('form.counter');
- &Apache::lonxml::init_counter();
- &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
- &mt('last student').' '.$fullname);
- }
- &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
- $result .= $print_array[0].' \end{document}';
+ 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);
+ $print_array[$i].=$output;
+ $student_names[$i].=$person.':'.$fullname.'_END_';
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,&mt('last student').' '.$fullname);
+ $flag_latex_header_remove = 'YES';
+ }
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+ $result .= $print_array[0].' \end{document}';
+ } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon') ||
+ ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon') ) {
+ $selectionmade="Seems to be useless";
+ my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
+
} elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') {
#prints selected problems from the subdirectory
$selectionmade = 6;
@@ -1082,12 +1019,7 @@ ENDPART
if ($urlp=~/\//) {
my %form;
$form{'grade_target'}='tex';
- if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ &&
- $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) {
- $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'});
- } else {
- $form{'textwidth'}=$LaTeXwidth;
- }
+ $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
$form{'rndseed'}=$rndseed;
if ($urlp =~ m|/home/([^/]+)/public_html|) {
$urlp =~ s|/home/([^/]*)/public_html|/~$1|;
@@ -1236,6 +1168,68 @@ FINALEND
}
+sub print_resources {
+ my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header)=@_;
+ my $current_output = '';
+ my ($username,$userdomain,$usersection) = split /:/,$person;
+ my $fullname = &get_name($username,$userdomain);
+
+ #goes through all resources, checks if they are available for
+ #current student, and produces output
+ &Apache::lonnet::delenv('form.counter');
+ &Apache::lonxml::init_counter();
+ foreach my $curresline (@{$master_seq}) {
+ if ( !($type eq 'problems' &&
+ ($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/;
+ } 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 =~ s/\\end{document}//;
+ }
+ $current_output .= $rendered;
+ }
+ $remove_latex_header = 'YES';
+ }
+ }
+ my $courseidinfo = &get_course();
+ if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
+ if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}
+ my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
+ if ($current_output=~/\\documentclass/) {
+ $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}}\\vskip 3 mm /;
+ } 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;
+ }
+ return ($current_output,$fullname);
+
+}
sub handler {
@@ -1473,10 +1467,7 @@ HELPERFRAGMENT
# problems in the course, optionally for selected students
if ($userPriviledged && ($helper->{VARS}->{'postdata'}=~/\/res\//)) {
push @{$printChoices}, ['Problems from entire course', 'all_problems', 'ALL_PROBLEMS'];
- if ($helper->{VARS}->{'assignment'}) {
- push @{$printChoices}, ["Problems from $sequenceTitle for selected students", 'problems_for_students', 'CHOOSE_STUDENTS'];
- }
- &Apache::lonxml::xmlparse($r, 'helper', <
(mark them then click "next" button)
return $isProblemOrMap;
return $isProblem;
return $symbFilter;
-
-
+
+
+ALL_PROBLEMS
-
-
-
Select resources for the assignment
+ if ($helper->{VARS}->{'assignment'}) {
+ push @{$printChoices}, ["Problems from $sequenceTitle for selected students", 'problems_for_students', 'CHOOSE_STUDENTS'];
+ push @{$printChoices}, ["Problems from $sequenceTitle for anonymous students", 'problems_for_anonymous', 'CHOOSE_ANON1'];
+ }
+ my $resource_selector=<
Select resources for the assignment
return $isProblem;
$map
@@ -1502,22 +1497,34 @@ HELPERFRAGMENT
Add one empty page/column after each student\'s assignment
Add two empty pages/column after each student\'s assignment
Add three empty pages/column after each student\'s assignment
-
-
+
+
Number of assignments printed at the same time:
+ "all"
+RESOURCE_SELECTOR
+
+ &Apache::lonxml::xmlparse($r, 'helper', <
+
+ $resource_selector
+
CHOOSE_STUDENTS
+ &Apache::lonxml::xmlparse($r, 'helper', <
+
How many Anonymous exams to print?
+
+
+ $resource_selector
+
+CHOOSE_ANON1
- addMessage("
Number of assignments printed at the same time: ");
- $paramHash = Apache::lonhelper::getParamHash();
- $paramHash->{'variable'} = 'NUMBER_TO_PRINT';
- $helper->declareVar('NUMBER_TO_PRINT');
- addMessage("
");
if ($helper->{VARS}->{'assignment'}) {
push @{$printChoices}, ["Resources from $sequenceTitle for selected students", 'resources_for_students', 'CHOOSE_STUDENTS1'];
+ push @{$printChoices}, ["Resources from $sequenceTitle for anonymous students", 'resources_for_anonymous', 'CHOOSE_ANON2'];
}
- &Apache::lonxml::xmlparse($r, 'helper', <
-
+
+
+ $resource_selector=<
Select resources for the assignment
return $isNotMap;
@@ -1530,15 +1537,26 @@ CHOOSE_STUDENTS
Add one empty page/column after each student\'s assignment
Add two empty pages/column after each student\'s assignment
Add three empty pages/column after each student\'s assignment
-
+
+
Number of assignments printed at the same time:
+ "all"
+RESOURCE_SELECTOR
+
+ &Apache::lonxml::xmlparse($r, 'helper', <
+
+ $resource_selector
CHOOSE_STUDENTS1
- addMessage("
Number of assignments printed at the same time: ");
- $paramHash = Apache::lonhelper::getParamHash();
- $paramHash->{'variable'} = 'NUMBER_TO_PRINT';
- $helper->declareVar('NUMBER_TO_PRINT');
- addMessage("
");
+ &Apache::lonxml::xmlparse($r, 'helper', <
+
How many Anonymous exams to print?
+
+
+ $resource_selector
+
+CHOOSE_ANON2
}
# FIXME: That RE should come from a library somewhere.