--- loncom/interface/lonprintout.pm	2003/06/19 15:46:42	1.191
+++ loncom/interface/lonprintout.pm	2003/06/24 20:21:05	1.196
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Printout
 #
-# $Id: lonprintout.pm,v 1.191 2003/06/19 15:46:42 bowersj2 Exp $
+# $Id: lonprintout.pm,v 1.196 2003/06/24 20:21:05 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -583,9 +583,14 @@ ENDPART
              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')) { 
         #-- produce an output string
+	my %form=();	   
+	$form{'grade_target'}='tex';
+	$form{'textwidth'}=$LaTeXwidth;
+	$form{'problem_split'}=$parmhash{'problem_stream_switch'};
 	my $flag_latex_header_remove = 'NO';
 	my $flag_page_in_sequence = 'NO';
 	my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
+	my $prevassignment='';
 	for (my $i=0;$i<=$#master_seq;$i++) {
 	    $master_seq[$i]=~/___\d+___(.*)$/;
 	    my $urlp='/res/'.$1;
@@ -596,11 +601,9 @@ ENDPART
 	    } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') {
 		$selectionmade = 4;
 	    }
-	    my %form;	   
-	    $form{'grade_target'}='tex';
-	    $form{'textwidth'}=$LaTeXwidth;
 	    $form{'symb'}=$master_seq[$i];
-            $form{'problem_split'}=$parmhash{'problem_stream_switch'};
+	    $master_seq[$i]=~/\/([^\/]+)\.sequence_/;
+	    my $assignment=' '.$1.' ';
 	    #&Apache::lonnet::logthis("Trying to get $urlp with symb $master_seq[$i]");
 	    my $texversion=&Apache::lonnet::ssi($urlp,%form);
 	    if ($urlp=~/\.page$/) {
@@ -621,7 +624,18 @@ ENDPART
 		my $answer=&Apache::lonnet::ssi($urlp,%form);
 		$texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
 	    }
-	    $result .= $texversion;         
+#	    $result .= $texversion;
+	    if (($selectionmade == 4) and ($assignment ne $prevassignment) and ($i>1)) {
+		my $name = &get_name();
+		if ($name =~ /^\s*$/) {
+		    $name=&Apache::lonxml::latex_special_symbols($ENV{'user.name'},undef,
+								 undef,'header');
+		}
+		my $courseidinfo = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::unescape($ENV{'course.'.$ENV{'request.course.id'}.'.description'}),'','','header');
+		$prevassignment=$assignment;
+		$result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}} - '.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip -5 mm ';
+	    }
+	    $result .= $texversion;
 	    $flag_latex_header_remove = 'YES';   
 	}
 	&Apache::lonnet::delenv('form.counter');
@@ -643,6 +657,8 @@ ENDPART
 #	    my ($usersection,$username,$userdomain) = split /:/,$person;
 	    my ($username,$userdomain) = split /:/,$person;
 	    my $fullname = &get_name($username,$userdomain);
+
+	    if ($parmhash{'anonimous_quiz'}=~/yes/) {$fullname=' ';} #put here something reasonable for annonimous exams or quiz
             #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)$/) {
@@ -658,8 +674,7 @@ ENDPART
 			if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
 			    my %form;
 			    $form{'answer_output_mode'}='tex';
-			    my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,
-										      $ENV{'request.course.id'},%form);
+			    my $ansrendered = &Apache::loncommon::get_student_answers($curresline,$username,$userdomain,$ENV{'request.course.id'},%form);
 			    $rendered=~s/(\\keephidden{ENDOFPROBLEM})/$ansrendered$1/;
 			}
 			$current_output .= $rendered;
@@ -748,12 +763,12 @@ ENDPART
     $result = &page_format_transformation($papersize,$laystyle,$numberofcolumns,$helper->{'VARS'}->{'PRINT_TYPE'},$result,$helper->{VARS}->{'assignment'});
     $result = &latex_corrections($number_of_columns,$result);
     #changes page's parameters for the one column output 
-#    if ($numberofcolumns == 1) {
-#	$result =~ s/\\textwidth= 9cm/\\textwidth= $ENV{'form.width'}/;
-#	$result =~ s/\\textheight 25\.9cm/\\textheight $ENV{'form.height'}/;
-#	$result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $ENV{'form.leftmargin'}/;
-#	$result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $ENV{'form.leftmargin'}/;
-#    }
+    if ($numberofcolumns == 1) {
+	$result =~ s/\\textwidth= 9cm/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
+	$result =~ s/\\textheight 25\.9cm/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
+	$result =~ s/\\evensidemargin = -0\.57in/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
+	$result =~ s/\\oddsidemargin = -0\.57in/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
+    }
 #-- writing .tex file in prtspool 
     my $temp_file;
     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
@@ -899,6 +914,8 @@ sub printHelper {
         $subdir = &Apache::lonnet::filelocation("", $url);
     }
 
+    my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
+
     Apache::lonhelper::registerHelperTags();
 
     # "Delete everything after the last slash."
@@ -936,18 +953,20 @@ sub printHelper {
         # Allow all resources from sequence
         push @{$printChoices}, ["Everything (problem(s), page(s), html/xml file(s)) from <b>$sequenceTitle</b>", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
 
-        my $isProblem = '$res->is_problem();';
+        my $isProblem = '$res->is_problem()';
+	$isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
         my $isProblemOrMap = '$res->is_problem() || $res->is_map()';
-        my $isNotMap = '!$res->is_map();';
-        my $symb = '$res->symb();';
+        my $isNotMap = '!$res->is_map()';
+	$isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
+        my $symb = '$res->symb()';
         my $helperFragment = <<HELPERFRAGMENT;
   <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">
     <message>(mark them then click "next" button) <br /></message>
     <resource variable="RESOURCES" multichoice="1" toponly='1'>
       <nextstate>PAGESIZE</nextstate>
-      <filterfunc>return $isProblem</filterfunc>
+      <filterfunc>return $isProblem;</filterfunc>
       <mapurl>$map</mapurl>
-      <valuefunc>return $symb</valuefunc>
+      <valuefunc>return $symb;</valuefunc>
       </resource>
     </state>
 
@@ -957,7 +976,7 @@ sub printHelper {
       <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isNotMap;</filterfunc>
       <mapurl>$map</mapurl>
-      <valuefunc>return $symb</valuefunc>
+      <valuefunc>return $symb;</valuefunc>
       </resource>
     </state>
 HELPERFRAGMENT
@@ -971,17 +990,19 @@ HELPERFRAGMENT
         push @{$printChoices}, ['<b>Problems</b> in this course', 'all_problems', 'ALL_PROBLEMS'];
         push @{$printChoices}, ["Problems from <b>$sequenceTitle</b> 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();';
+        my $isProblem = '$res->is_problem()';
+	$isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
+        my $isProblemOrMap = '($res->is_problem() || $res->is_map())';
+	$isProblemOrMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
+        my $symb = '$res->symb()';
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
     <message>(mark them then click "next" button) <br /></message>
     <resource variable="RESOURCES" multichoice="1" suppressEmptySequences='1'>
       <nextstate>PAGESIZE</nextstate>
-      <filterfunc>return $isProblemOrMap</filterfunc>
-      <choicefunc>return $isProblem</choicefunc>
-      <valuefunc>return $symb</valuefunc>
+      <filterfunc>return $isProblemOrMap;</filterfunc>
+      <choicefunc>return $isProblem;</choicefunc>
+      <valuefunc>return $symb;</valuefunc>
       </resource>
     </state>
 
@@ -995,16 +1016,16 @@ HELPERFRAGMENT
       </resource>
     <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
     <choices variable="EMPTY_PAGES">
-      <choice computer='0'>Start each student's assignment on a new page (add a pagefeed after each assignment)</choice>
-      <choice computer='1'>Add one empty page after each student's assignment</choice>
-      <choice computer='2'>Add two empty pages after each student's assignment</choice>
+      <choice computer='0'>Start each student\'s assignment on a new page (add a pagefeed after each assignment)</choice>
+      <choice computer='1'>Add one empty page after each student\'s assignment</choice>
+      <choice computer='2'>Add two empty pages after each student\'s assignment</choice>
       </choices>
     </state>
 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)/)) or defined $helper->{'VARS'}->{'construction'}) {    
+    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'}) {    
         push @{$printChoices}, ["Problems from current subdirectory <b>$subdir</b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
         
         my $f = '$filename';