[LON-CAPA-cvs] cvs: loncom /interface lonprintout.pm

albertel lon-capa-cvs@mail.lon-capa.org
Tue, 23 Mar 2004 01:34:17 -0000


This is a MIME encoded message

--albertel1080005657
Content-Type: text/plain

albertel		Mon Mar 22 20:34:17 2004 EDT

  Modified files:              
    /loncom/interface	lonprintout.pm 
  Log:
  - refactored the printing routine for students into a sepearte subroutine
  - add options for printing anonymous 
  
  
--albertel1080005657
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20040322203417.txt"

Index: loncom/interface/lonprintout.pm
diff -u loncom/interface/lonprintout.pm:1.283 loncom/interface/lonprintout.pm:1.284
--- loncom/interface/lonprintout.pm:1.283	Fri Mar 19 16:54:48 2004
+++ loncom/interface/lonprintout.pm	Mon Mar 22 20:34:17 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.283 2004/03/19 21:54:48 albertel Exp $
+# $Id: lonprintout.pm,v 1.284 2004/03/23 01:34:17 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -974,12 +974,16 @@
 	&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' ||
@@ -1000,72 +1004,20 @@
 	 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;
@@ -1236,6 +1188,68 @@
 }
 
 
+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 +1487,7 @@
     # problems in the course, optionally for selected students
     if ($userPriviledged && ($helper->{VARS}->{'postdata'}=~/\/res\//)) { 
         push @{$printChoices}, ['<b>Problems</b> from <b>entire course</b>', 'all_problems', 'ALL_PROBLEMS'];
-	if ($helper->{VARS}->{'assignment'}) {
-	    push @{$printChoices}, ["<b>Problems</b> from <b><i>$sequenceTitle</i></b> for <b>selected students</b>", 'problems_for_students', 'CHOOSE_STUDENTS'];
-	}
-        &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
+         &Apache::lonxml::xmlparse($r, 'helper', <<ALL_PROBLEMS);
   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
     <message>(mark them then click "next" button) <br /></message>
     <resource variable="RESOURCES" multichoice="1"
@@ -1485,12 +1496,16 @@
       <filterfunc>return $isProblemOrMap;</filterfunc>
       <choicefunc>return $isProblem;</choicefunc>
       <valuefunc>return $symbFilter;</valuefunc>
-      </resource>
-    </state>
+    </resource>
+  </state>
+ALL_PROBLEMS
 
-  <state name="CHOOSE_STUDENTS" title="Select Students and Resources">
-    <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
-    <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
+	if ($helper->{VARS}->{'assignment'}) {
+	    push @{$printChoices}, ["<b>Problems</b> from <b><i>$sequenceTitle</i></b> for <b>selected students</b>", 'problems_for_students', 'CHOOSE_STUDENTS'];
+	    push @{$printChoices}, ["<b>Problems</b> from <b><i>$sequenceTitle</i></b> for <b>anonymous students</b>", 'problems_for_anonymous', 'CHOOSE_ANON1'];
+	}
+	my $resource_selector=<<RESOURCE_SELECTOR;
+   <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
     <resource variable="RESOURCES" multichoice="1" addstatus="1">
       <filterfunc>return $isProblem;</filterfunc>
       <mapurl>$map</mapurl>
@@ -1502,22 +1517,34 @@
       <choice computer='1'>Add one empty page/column after each student\'s assignment</choice>
       <choice computer='2'>Add two empty pages/column after each student\'s assignment</choice>
       <choice computer='3'>Add three empty pages/column after each student\'s assignment</choice>
-      </choices>
-    </state>
+    </choices>
+    <message><hr width='33%' /><b>Number of assignments printed at the same time: </b></message>
+    <string variable="NUMBER_TO_PRINT" maxlength="5" size="5"><defaultvalue>"all"</defaultvalue></string>
+RESOURCE_SELECTOR
+
+        &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
+  <state name="CHOOSE_STUDENTS" title="Select Students and Resources">
+      <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
+    $resource_selector
+  </state>
 CHOOSE_STUDENTS
+        &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);
+  <state name="CHOOSE_ANON1" title="Select Students and Resources">
+    <message><hr width='33%' /><b>How many Anonymous exams to print?</b></message>
+    <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>
+    <message><hr width='33%' /></message>
+    $resource_selector
+  </state>
+CHOOSE_ANON1
 
-	addMessage("<hr width='33%' /><b>Number of assignments printed at the same time: </b>");
-        $paramHash = Apache::lonhelper::getParamHash();
-	$paramHash->{'variable'} = 'NUMBER_TO_PRINT';   
-	$helper->declareVar('NUMBER_TO_PRINT');         
-	addMessage("<input type='text' name='NUMBER_TO_PRINT.forminput' size='3' value='all' /><hr width='33%' />");
 
 	if ($helper->{VARS}->{'assignment'}) {
 	    push @{$printChoices}, ["<b>Resources</b> from <b><i>$sequenceTitle</i></b> for <b>selected students</b>", 'resources_for_students', 'CHOOSE_STUDENTS1'];
+	    push @{$printChoices}, ["<b>Resources</b> from <b><i>$sequenceTitle</i></b> for <b>anonymous students</b>", 'resources_for_anonymous', 'CHOOSE_ANON2'];
 	}
-	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS1);
-  <state name="CHOOSE_STUDENTS1" title="Select Students and Resources">
-    <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
+	    
+
+	$resource_selector=<<RESOURCE_SELECTOR;
     <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
     <resource variable="RESOURCES" multichoice="1" addstatus="1">
       <filterfunc>return $isNotMap;</filterfunc>
@@ -1530,15 +1557,26 @@
       <choice computer='1'>Add one empty page/column after each student\'s assignment</choice>
       <choice computer='2'>Add two empty pages/column after each student\'s assignment</choice>
       <choice computer='3'>Add three empty pages/column after each student\'s assignment</choice>
-      </choices>
+    </choices>
+    <message><hr width='33%' /><b>Number of assignments printed at the same time: </b></message>
+    <string variable="NUMBER_TO_PRINT" maxlength="5" size="5"><defaultvalue>"all"</defaultvalue></string>
+RESOURCE_SELECTOR
+
+	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS1);
+  <state name="CHOOSE_STUDENTS1" title="Select Students and Resources">
+    <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
+    $resource_selector
     </state>
 CHOOSE_STUDENTS1
 
- 	addMessage("<hr width='33%' /><b>Number of assignments printed at the same time: </b>");
-        $paramHash = Apache::lonhelper::getParamHash();
-	$paramHash->{'variable'} = 'NUMBER_TO_PRINT';   
-	$helper->declareVar('NUMBER_TO_PRINT');         
-	addMessage("<input type='text' name='NUMBER_TO_PRINT.forminput' size='3' value='all' /><hr width='33%' />");
+	&Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON2);
+  <state name="CHOOSE_ANON2" title="Select Students and Resources">
+    <message><hr width='33%' /><b>How many Anonymous exams to print?</b></message>
+    <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>
+    <message><hr width='33%' /></message>
+    $resource_selector
+  </state>
+CHOOSE_ANON2
     }
 
     # FIXME: That RE should come from a library somewhere.

--albertel1080005657--