Diff for /loncom/interface/lonprintout.pm between versions 1.560.2.3 and 1.571

version 1.560.2.3, 2009/09/08 10:53:15 version 1.571, 2010/02/03 22:21:35
Line 1 Line 1
 #  #
 #  Issues:  
 #   - Need to get the state flow for selected problems/resources for students  
 #     correct  
 #   - Need to do the CODEd stuff.  
 #   - Need to regularize and figure out for each case who puts on the latex  
 #     front matter and make sure it gets done.  
 #  
 #  
   
 # The LearningOnline Network  # The LearningOnline Network
 # Printout  # Printout
 #  #
Line 99  sub generate_student_chooser { Line 90  sub generate_student_chooser {
  $sort_choice,    $sort_choice, 
  $variable,    $variable, 
  $next_state) = @_;   $next_state) = @_;
   
     my $result = <<CHOOSE_STUDENTS;      my $result = <<CHOOSE_STUDENTS;
   <state name="$this_state" title="Select Students and Resources">    <state name="$this_state" title="Select Students and Resources">
       <message><b>Select sorting order of printout</b> </message>        <message><b>Select sorting order of printout</b> </message>
Line 155  sub generate_resource_chooser { Line 145  sub generate_resource_chooser {
  $value_func,   $value_func,
  $start_new_option)  = @_;   $start_new_option)  = @_;
   
       
     my $result = <<CHOOSE_RESOURCES;      my $result = <<CHOOSE_RESOURCES;
 <state name="$this_state" title="$prompt_text">  <state name="$this_state" title="$prompt_text">
     <resource variable="$variable" $resource_options      <resource variable="$variable" $resource_options
Line 163  sub generate_resource_chooser { Line 152  sub generate_resource_chooser {
       <nextstate>$next_state</nextstate>        <nextstate>$next_state</nextstate>
       <filterfunc>return $filter;</filterfunc>        <filterfunc>return $filter;</filterfunc>
 CHOOSE_RESOURCES  CHOOSE_RESOURCES
     if ($value_func ne '') {      if ($choice_func ne '') {
  $result .= "<choicefunc>return $choice_func;</choicefunc>";   $result .= "<choicefunc>return $choice_func;</choicefunc>";
     }      }
     if ($top_url ne '') {      if ($top_url ne '') {
Line 178  CHOOSE_RESOURCES Line 167  CHOOSE_RESOURCES
   
     return $result;      return $result;
 }  }
   #
   #   Generate the helper XML for a code choice helper dialog:
   #
   # Paramters:
   #   $helper       - Reference to the helper.
   #   $state        - Name of the state for the chooser.
   #   $next_state   - Name fo the state to follow the chooser.
   #   $bubble_types - Populates the bubble sheet type dropt down.
   #   $code_selections - Provides set of code choices that have been used
   #   $saved_codes  - Provides the list of saved codes.
   #
   # Returns;
   #   The Xml of the code chooser.
   #
   sub generate_code_selector {
       my ($helper,
    $state,
    $next_state,
    $bubble_types,
    $code_selections,
    $saved_codes) = @_; # Unpack the parameters.
   
       my $result = <<CHOOSE_ANON1;
     <state name="$state" title="Specify CODEd Assignments">
       <nextstate>$next_state</nextstate>
       <message><h4>Fill out one of the forms below</h4></message>
       <message><br /><hr /> <br /></message>
       <message><h3>Generate new CODEd Assignments</h3></message>
       <message><table><tr><td><b>Number of CODEd assignments to print:</b></td><td></message>
       <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5">
          <validator>
    if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) &&
       !\$helper->{'VARS'}{'REUSE_OLD_CODES'}                &&
               !\$helper->{'VARS'}{'SINGLE_CODE'}                    &&
       !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
       return "You need to specify the number of assignments to print";
    }
    return undef;
          </validator>
       </string>
       <message></td></tr><tr><td></message>
       <message><b>Names to save the CODEs under for later:</b></message>
       <message></td><td></message>
       <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
       <message></td></tr><tr><td></message>
       <message><b>Bubble sheet type:</b></message>
       <message></td><td></message>
       <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
       $bubble_types
       </dropdown>
       <message></td></tr><tr><td colspan="2"></td></tr><tr><td></message>
       <message></td></tr><tr><td></table></message>
       <message><br /><hr /><h3>Print a Specific CODE </h3><br /><table></message>
       <message><tr><td><b>Enter a CODE to print:</b></td><td></message>
       <string variable="SINGLE_CODE" size="10">
           <validator>
      if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}           &&
         !\$helper->{'VARS'}{'REUSE_OLD_CODES'}                 &&
         !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
         return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},
         \$helper->{'VARS'}{'CODE_OPTION'});
      } else {
          return undef; # Other forces control us.
      }
           </validator>
       </string>
       <message></td></tr><tr><td></message>
           $code_selections
       <message></td></tr></table></message>
       <message><hr /><h3>Reprint a Set of Saved CODEs</h3><table><tr><td></message>
       <message><b>Select saved CODEs:</b></message>
       <message></td><td></message>
       <dropdown variable="REUSE_OLD_CODES">
           $saved_codes
       </dropdown>
       <message></td></tr></table></message>
     </state>
   CHOOSE_ANON1
   
      return $result;
   }
   
 #-----------------------------------------------------------------------  #-----------------------------------------------------------------------
   
Line 430  sub printf_style_subst { Line 499  sub printf_style_subst {
 sub format_page_header {  sub format_page_header {
     my ($width, $format, $assignment, $course, $student, $section) = @_;      my ($width, $format, $assignment, $course, $student, $section) = @_;
   
       
   
     $width = &recalcto_mm($width); # Get width in mm.      $width = &recalcto_mm($width); # Get width in mm.
       my $chars_per_line = int($width/1.6);   # Character/textline.
   
     #  Default format?      #  Default format?
   
     if ($format eq '') {      if ($format eq '') {
Line 445  sub format_page_header { Line 517  sub format_page_header {
  #   but only truncate the course.   #   but only truncate the course.
  # - Allow the assignment to be 2 lines (wrapped).   # - Allow the assignment to be 2 lines (wrapped).
  #   #
  my $chars_per_line = $width/2; # Character/textline.  
   
   
   
   
  my $name_length    = int($chars_per_line *3 /4);   my $name_length    = int($chars_per_line *3 /4);
  my $sec_length     = int($chars_per_line / 5);   my $sec_length     = int($chars_per_line / 5);
Line 483  sub format_page_header { Line 554  sub format_page_header {
         my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout ');          my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout ');
         $format =~ s/\\\\\s\\\\\s/$testPrintout/;          $format =~ s/\\\\\s\\\\\s/$testPrintout/;
     }      }
           #
       #  We're going to trust LaTeX to break lines appropriately, but
       #  we'll truncate anything that's more than 3 lines worth of
       # text.  This is also assuming (which will probably end badly)
       # nobody's going to embed LaTeX control sequences in the title
       # header or rather that those control sequences won't get broken
       # by the stuff below.
       #
       my $total_length = 3*$chars_per_line;
       if (length($format) > $total_length) {
    $format = substr($format, 0, $total_length);
       }
   
   
     return $format;      return $format;
           
Line 1194  sub page_format_transformation { Line 1277  sub page_format_transformation {
   
     if ($selectionmade eq '4') {      if ($selectionmade eq '4') {
  if ($choice eq 'all_problems') {   if ($choice eq 'all_problems') {
     $assignment='Problems from the Whole Course';              $assignment=&mt('Problems from the Whole Course');
  } else {   } else {
     $assignment='Resources from the Whole Course';              $assignment=&mt('Resources from the Whole Course');
  }   }
     } else {      } else {
  $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');   $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');
Line 1470  sub print_page_in_course { Line 1553  sub print_page_in_course {
   
     # First is the overall page description.  This is then followed by the       # First is the overall page description.  This is then followed by the 
     # components of the page. Each of which must be printed independently.      # components of the page. Each of which must be printed independently.
   
     my $the_page = shift(@page_resources);       my $the_page = shift(@page_resources); 
   
   
     foreach my $resource (@page_resources) {      foreach my $resource (@page_resources) {
  my $resource_src   = $resource->src(); # Essentially the URL of the resource.   my $resource_src   = $resource->src(); # Essentially the URL of the resource.
  $result           .= $resource->title() . '\\\\';   $result           .= $resource->title() . '\\\\';
Line 1673  sub recently_generated { Line 1756  sub recently_generated {
 #    A reference to a page break hash.  #    A reference to a page break hash.
 #  #
 #  #
 use Data::Dumper;  # use Data::Dumper;
 #sub dump_helper_vars {  # sub dump_helper_vars {
 #    my ($helper) = @_;  #    my ($helper) = @_;
 #    my $helpervars = Dumper($helper->{'VARS'});  #    my $helpervars = Dumper($helper->{'VARS'});
 #    &Apache::lonnet::logthis("Dump of helper vars:\n $helpervars");  #    &Apache::lonnet::logthis("Dump of helper vars:\n $helpervars");
Line 1689  sub get_page_breaks  { Line 1772  sub get_page_breaks  {
     }      }
     return %page_breaks;      return %page_breaks;
 }  }
   # 
   #   Returns text to insert for any extra vskip prior to the resource.
   #   Parameters:
   #     helper   - Reference to the helper object driving the printout.
   #     resource - Identifies the resource about to be printed.
   #
   #   This is done as follows:
   #    POSSIBLE_RESOURCES has the list of possible resources.
   #    EXTRASPACE         has the list of extra space values.
   #    EXTRASPACE_UNITS   is the set of resources for which the units are
   #                       mm. All others are 'in'.
   #    
   #    The resource is found in the POSSIBLE_RESOURCES to get the index
   #    of the EXTRASPACE value.
   #
   #   In order to speed this up for lengthy printouts, the first time,
   #   POSSIBLE_RESOURCES is turned into a look up hash and
   #   EXTRASPACE is turned into an array.
   #
   
   
   my %possible_resources;
   my %extraspace_mm;
   my @extraspace;
   my $skips_loaded       = 0;
   
   #  Function to load the skips hash and array
   
   sub load_skips {
   
       my ($helper)  = @_;
   
       #  If this is the first time, unrap the resources and extra spaces:
   
       if (!$skips_loaded) {
    @extraspace = (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE'}));
    my @resource_list = (split(/\|\|\|/, $helper->{'VARS'}->{'POSSIBLE_RESOURCES'}));
    my $i = 0;
    foreach my $resource (@resource_list) {
       $possible_resources{$resource} = $i;
       $i++;
    }
    foreach my $mm_resource (split(/\|\|\|/, $helper->{'VARS'}->{'EXTRASPACE_UNITS'})) {
       $extraspace_mm{$mm_resource} = 1;
    }
    $skips_loaded = 1;
       }
   }
   
   sub get_extra_vspaces {
       my ($helper, $resource) = @_;
   
       &load_skips($helper);
   
       #  Lookup the resource in the possible resources hash.. that is the index
       # into the extraspace array that gives us either an empty string or
       # the number of mm to skip:
   
       my $index = $possible_resources{$resource};
       my $skip  = $extraspace[$index];
   
       my $result = '';
       if ($skip ne '') {
    my $units = 'in';
    if (defined($extraspace_mm{$resource})) {
       $units = 'mm';
    }
    $result = '\vskip '.$skip.' '.$units;
       }
   
   
       return $result;
   
   
   }
   
   #
   #  The resource chooser part of the helper needs more than just
   #  the value of the extraspaces var to recover the value into a text
   #  field option.  This sub produces the required format for the saved var:
   #  specifically 
   #    ||| separated fields of the form resourcename=value
   #
   #  Parameters:
   #    $helper     - Refers to the helper we are configuring
   #  Implicit input:
   #     $helper->{'VARS'}->{'EXTRASPACE'}  - the spaces helper var has the text field
   #                                          value.
   #     $helper->{'VARS'}->{'EXTRASPACE_UNITS'} - units for the skips (checkboxes).
   #     $helper->{'VARS'}->{'POSSIBLE_RESOURCES'}  - has the list of resources. |||
   #                                          separated of course.
   #  Implicit outputs:
   #     $env{'form.extraspace'}
   #     $env{'form.extraspace_units'}
   #
   sub set_form_extraspace {
       my ($helper) = @_;
   
       # the most convenient way to do this is to drive from the skips arrays/hash.
       # may not be the fastest, but this is once per print request so it's not so
       # speed critical:
   
       &load_skips($helper);
   
       my $result = '';
   
       foreach my $resource (keys(%possible_resources)) {
    my $vskip = $extraspace[$possible_resources{$resource}];
    $result  .= $resource .'=' . $vskip . '|||';
       }
   
       $env{'form.extraspace'}  = $result;
       $env{'form.extraspace_units'} = $helper->{'VARS'}->{'EXTRASPACE_UNITS'};
       return $result;
       
   }
   
 #  Output a sequence (recursively if neeed)  #  Output a sequence (recursively if neeed)
 #  from construction space.  #  from construction space.
Line 1860  ENDPART Line 2059  ENDPART
     # indexed by symb and contains 1's for each break.      # indexed by symb and contains 1's for each break.
   
     $env{'form.pagebreaks'}  = $helper->{'VARS'}->{'FINISHPAGE'};      $env{'form.pagebreaks'}  = $helper->{'VARS'}->{'FINISHPAGE'};
       &set_form_extraspace($helper);
     $env{'form.lastprinttype'} = $helper->{'VARS'}->{'PRINT_TYPE'};       $env{'form.lastprinttype'} = $helper->{'VARS'}->{'PRINT_TYPE'}; 
     &Apache::loncommon::store_course_settings('print',      &Apache::loncommon::store_course_settings('print',
       {'pagebreaks'    => 'scalar',        {'pagebreaks'    => 'scalar',
          'extraspace'    => 'scalar',
          'extraspace_units' => 'scalar',
        'lastprinttype' => 'scalar'});         'lastprinttype' => 'scalar'});
   
     my %page_breaks  = &get_page_breaks($helper);      my %page_breaks  = &get_page_breaks($helper);
   
     my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};      my $format_from_helper = $helper->{'VARS'}->{'FORMAT'};
Line 2025  ENDPART Line 2226  ENDPART
   
   
     $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;      $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
 #    $result .= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});  
     $result .= &print_construction_sequence($currentURL, $helper, %form,      $result .= &print_construction_sequence($currentURL, $helper, %form,
     $LaTeXwidth);      $LaTeXwidth);
     $result .= '\end{document}';        $result .= '\end{document}';  
Line 2037  ENDPART Line 2237  ENDPART
  $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};   $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
  if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;}   if ($currentURL=~/\/syllabus$/) {$currentURL=~s/\/res//;}
  $resources_printed .= $currentURL.':';   $resources_printed .= $currentURL.':';
  my $texversion=&ssi_with_retries($currentURL, $ssi_retry_count, %form);   my $texversion = &ssi_with_retries($currentURL, $ssi_retry_count, %form);
  if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {   if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
     my $annotation = &annotate($currentURL);      my $annotation = &annotate($currentURL);
     $texversion    =~ s/(\\end{document})/$annotation$1/;      $texversion    =~ s/(\\end{document})/$annotation$1/;
Line 2070  ENDPART Line 2270  ENDPART
   
                 
  } else {   } else {
     &Apache::lonnet::logthis("Unsupported type handler");  
     $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'},      $result.=&unsupported($currentURL,$helper->{'VARS'}->{'LATEX_TYPE'},
   $helper->{'VARS'}->{'symb'});    $helper->{'VARS'}->{'symb'});
  }   }
Line 2091  ENDPART Line 2290  ENDPART
  } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or   } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
  ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page'))   ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page'))
  {   {
     &Apache::lonnet::logthis("Selectionmade => 3");  
     $selectionmade = 3;      $selectionmade = 3;
  } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')    } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') 
  ) {   ) {
Line 2131  ENDPART Line 2329  ENDPART
     $result.="\\newpage\n";      $result.="\\newpage\n";
  }   }
     }      }
     my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);      $result .= &get_extra_vspaces($helper, $master_seq[$i]);
       my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
     $urlp=&Apache::lonnet::clutter($urlp);      $urlp=&Apache::lonnet::clutter($urlp);
     $form{'symb'}=$master_seq[$i];      $form{'symb'}=$master_seq[$i];
   
     &Apache::lonnet::logthis("Element $i Sequence $sequence Middle $middle_thingy URLP $urlp");  
     my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #title of the assignment which contains this problem      my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #title of the assignment which contains this problem
   
     if ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;}      if ($selectionmade==7) {$helper->{VARS}->{'assignment'}=$assignment;}
Line 2143  ENDPART Line 2341  ENDPART
     my $texversion='';      my $texversion='';
     if ($urlp!~m|^/adm/|      if ($urlp!~m|^/adm/|
  && $urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {   && $urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/) {
  &Apache::lonnet::logthis("Problem");  
  $resources_printed .= $urlp.':';   $resources_printed .= $urlp.':';
  &Apache::lonxml::remember_problem_counter();   &Apache::lonxml::remember_problem_counter();
  &Apache::lonnet::logthis("Fetching tex for $urlp");   if ($flag_latex_header_remove eq 'NO') {
  my $debug = Dumper(%form);      $texversion.=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});  # RF
  &Apache::lonnet::logthis("Form: $debug");      $flag_latex_header_remove = 'YES';
    }
  $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);   $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);
  &Apache::lonnet::logthis("texversion so far: $texversion");  
  if ($urlp=~/\.page$/) {   if ($urlp=~/\.page$/) {
     &Apache::lonnet::("Special page actions");  
     ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);      ($texversion,my $number_of_columns_page) = &page_cleanup($texversion);
     if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;}       if ($number_of_columns_page > $number_of_columns) {$number_of_columns=$number_of_columns_page;} 
     $texversion =~ s/\\end{document}\d*/\\end{document}/;      $texversion =~ s/\\end{document}\d*/\\end{document}/;
Line 2175  ENDPART Line 2370  ENDPART
  $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;   $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
     } else {      } else {
  if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {   if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library)$/) {
     &Apache::lonnet::logthis("problem printing");  
     $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});      $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
     $texversion =~ s/\\begin{document}//;      $texversion =~ s/\\begin{document}//;
     my $title = &Apache::lonnet::gettitle($master_seq[$i]);      my $title = &Apache::lonnet::gettitle($master_seq[$i]);
Line 2221  ENDPART Line 2415  ENDPART
     }      }
  }   }
  $result .= $texversion;   $result .= $texversion;
  &Apache::lonnet::logthis("About to set rem header true with $result");  
  $flag_latex_header_remove = 'YES';      $flag_latex_header_remove = 'YES';   
     } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) {       } elsif ($urlp=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { 
  $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};   $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
  if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;}   if ($urlp=~/\/syllabus$/) {$urlp=~s/\/res//;}
  $resources_printed .= $urlp.':';   $resources_printed .= $urlp.':';
  my $texversion=&ssi_with_retries($urlp, $ssi_retry_count, %form);   my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);
  if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {   if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
     my $annotation = &annotate($urlp);      my $annotation = &annotate($urlp);
     $texversion =~ s/(\\end{document)/$annotation$1/;      $texversion =~ s/(\\end{document)/$annotation$1/;
Line 2278  ENDPART Line 2471  ENDPART
  }   }
  $result .= '\end{document}';   $result .= '\end{document}';
      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||       } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||
         ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students_from_page') ||
       ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems_students') ||        ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems_students') ||
       ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')){        ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_students')){
   
Line 2285  ENDPART Line 2479  ENDPART
      #-- prints assignments for whole class or for selected students         #-- prints assignments for whole class or for selected students  
  my $type;   my $type;
  if (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||   if (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students') ||
        ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_students_from_page') ||
      ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems_students') ) {       ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems_students') ) {
      $selectionmade=5;       $selectionmade=5;
      $type='problems';       $type='problems';
Line 2324  ENDPART Line 2519  ENDPART
  my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};   my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
   
  #loop over students   #loop over students
  my $flag_latex_header_remove = 'NO';  
     my $flag_latex_header_remove = 'NO';
  my %moreenv;   my %moreenv;
          $moreenv{'instructor_comments'}='hide';           $moreenv{'instructor_comments'}='hide';
  $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);   $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
Line 2372  ENDPART Line 2568  ENDPART
  &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);   &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
  $result .= $print_array[0].'  \end{document}';   $result .= $print_array[0].'  \end{document}';
      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||       } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||
         ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon_page') ||
       ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon')  ) {         ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon')  ) { 
  my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};   my $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
  my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};   my $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
Line 2727  sub print_resources { Line 2924  sub print_resources {
     #   so we will just rely on prntout.pl to strip  ENDOFSTUDENTSTAMP from the      #   so we will just rely on prntout.pl to strip  ENDOFSTUDENTSTAMP from the
     #   postscript.  Each ENDOFSTUDENTSTAMP will go on a line by itself.      #   postscript.  Each ENDOFSTUDENTSTAMP will go on a line by itself.
     #      #
       my $syllabus_first = 0;
   
     foreach my $curresline (@{$master_seq})  {      foreach my $curresline (@{$master_seq})  {
  if (defined $page_breaks{$curresline}) {   if (defined $page_breaks{$curresline}) {
     if($i != 0) {      if($i != 0) {
  $current_output.= "\\newpage\n";   $current_output.= "\\newpage\n";
     }      }
  }   }
    $current_output .= &get_extra_vspaces($helper, $curresline);
  $i++;   $i++;
   
  if ( !($type eq 'problems' &&    if ( !($type eq 'problems' && 
Line 2747  sub print_resources { Line 2944  sub print_resources {
     &Apache::lonxml::remember_problem_counter();          &Apache::lonxml::remember_problem_counter();    
   
     my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);      my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
   
     if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||      if(($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
        ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {         ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) {
  #   Use a copy of the hash so we don't pervert it on future loop passes.   #   Use a copy of the hash so we don't pervert it on future loop passes.
Line 2775  sub print_resources { Line 2971  sub print_resources {
     $rendered = $header.$body;      $rendered = $header.$body;
  }   }
     }      }
   
     if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {      if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
  my $url = &Apache::lonnet::clutter($res_url);   my $url = &Apache::lonnet::clutter($res_url);
  my $annotation = &annotate($url);   my $annotation = &annotate($url);
  $rendered =~  s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/;   $rendered =~  s/(\\keephidden{ENDOFPROBLEM})/$annotation$1/;
     }      }
       my $junk;
     if ($remove_latex_header eq 'YES') {      if ($remove_latex_header eq 'YES') {
  $rendered = &latex_header_footer_remove($rendered);   $rendered = &latex_header_footer_remove($rendered);
     } else {      } else {
Line 2788  sub print_resources { Line 2984  sub print_resources {
     }      }
     $current_output .= $rendered;          $current_output .= $rendered;    
  } elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) {   } elsif ($res_url=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) {
       if ($i == 1) {
    $syllabus_first = 1;
       }
     $printed .= $curresline.':';      $printed .= $curresline.':';
     my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);      my $rendered = &get_student_view_with_retries($curresline,$ssi_retry_count,$username,$userdomain,$env{'request.course.id'},'tex',$moreenv);
     if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {      if ($helper->{'VARS'}->{'PRINT_ANNOTATIONS'} eq 'yes') {
Line 2832  sub print_resources { Line 3031  sub print_resources {
     my $header_start = ($columns_in_format == 1) ? '\lhead'      my $header_start = ($columns_in_format == 1) ? '\lhead'
                                          : '\fancyhead[LO]';                                           : '\fancyhead[LO]';
     $header_line = $header_start.'{'.$header_line.'}';      $header_line = $header_start.'{'.$header_line.'}';
     if ($current_output=~/\\documentclass/) {      if ($current_output=~/\\documentclass/ && (!$syllabus_first)) {
  $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$namepostfix}\\vskip 5 mm /;   $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent$header_line$namepostfix}\\vskip 5 mm /;
       } elsif ($syllabus_first) {
   
    $current_output =~ s/\\\\ Last updated:/Last updated:/
     } else {      } else {
  my $blankpages =    my $blankpages = 
     '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'};      '\clearpage\strut\clearpage'x$helper->{'VARS'}->{'EMPTY_PAGES'};
Line 2977  sub printHelper { Line 3179  sub printHelper {
     $helper->declareVar('PRINT_TYPE');      $helper->declareVar('PRINT_TYPE');
     $helper->declareVar("showallfoils");      $helper->declareVar("showallfoils");
     $helper->declareVar("STUDENTS");      $helper->declareVar("STUDENTS");
       $helper->declareVar("EXTRASPACE");
   
         
   
   
     #  The page breaks can get loaded initially from the course environment:      #  The page breaks and extra spaces
       #  can get loaded initially from the course environment:
     # But we only do this in the initial state so that they are allowed to change.      # But we only do this in the initial state so that they are allowed to change.
     #      #
   
     # $helper->{VARS}->{FINISHPAGE} = '';  
           
     &Apache::loncommon::restore_course_settings('print',      &Apache::loncommon::restore_course_settings('print',
  {'pagebreaks'  => 'scalar',   {'pagebreaks'  => 'scalar',
    'extraspace'  => 'scalar',
    'extraspace_units' => 'scalar',
          'lastprinttype' => 'scalar'});           'lastprinttype' => 'scalar'});
           
     # This will persistently load in the data we want from the      # This will persistently load in the data we want from the
Line 2999  sub printHelper { Line 3203  sub printHelper {
  if (!defined ($env{"form.CURRENT_STATE"})) {   if (!defined ($env{"form.CURRENT_STATE"})) {
           
     $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};      $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
       $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'};
       $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'};
  } else {   } else {
     my $state = $env{"form.CURRENT_STATE"};      my $state = $env{"form.CURRENT_STATE"};
     if ($state eq "START") {      if ($state eq "START") {
  $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};   $helper->{VARS}->{FINISHPAGE} = $env{'form.pagebreaks'};
    $helper->{VARS}->{EXTRASPACE} = $env{'form.extraspace'};
    $helper->{VARS}->{EXTRASPACE_UNITS} = $env{'form.extraspace_units'};
   
     }      }
  }   }
   
Line 3063  sub printHelper { Line 3272  sub printHelper {
  } else {   } else {
     $url = $helper->{VARS}->{'postdata'};      $url = $helper->{VARS}->{'postdata'};
     $is_published=1; # From resource space.      $is_published=1; # From resource space.
     &Apache::lonnet::logthis("Resource url $url");  
  }   }
  $url = &Apache::lonnet::clutter($url);   $url = &Apache::lonnet::clutter($url);
         if (!$resourceTitle) { # if the resource doesn't have a title, use the filename          if (!$resourceTitle) { # if the resource doesn't have a title, use the filename
Line 3122  sub printHelper { Line 3330  sub printHelper {
     if ($perm{'pav'}) {      if ($perm{'pav'}) {
  $start_new_option =    $start_new_option = 
     "<option text='".&mt('Start new page<br />before selected').      "<option text='".&mt('Start new page<br />before selected').
     "' variable='FINISHPAGE' />";      "' variable='FINISHPAGE' />".
       "<option text='".&mt('Extra space<br />before selected').
       "' variable='EXTRASPACE' type='text' />" .
       "<option " .
       "' variable='POSSIBLE_RESOURCES' type='hidden' />".
       "<option text='".&mt('Space units<br />check for mm').
       "' variable='EXTRASPACE_UNITS' type='checkbox' />"
       ;
       
   
     }      }
   
     # If not construction space user can print the components of a page:      # If not construction space user can print the components of a page:
Line 3133  sub printHelper { Line 3350  sub printHelper {
  my $varspostdata = $helper->{VARS}->{'postdata'};   my $varspostdata = $helper->{VARS}->{'postdata'};
  my $varsassignment = $helper->{VARS}->{'assignment'};   my $varsassignment = $helper->{VARS}->{'assignment'};
  my $page_navmap         = Apache::lonnavmaps::navmap->new();   my $page_navmap         = Apache::lonnavmaps::navmap->new();
  my @page_resources      = $page_navmap->retrieveResources($url);   if (defined($page_navmap)) {
  if(defined($page_resources[0])) {      my @page_resources      = $page_navmap->retrieveResources($url);
  $page_ispage       = $page_resources[0]->is_page();      if(defined($page_resources[0])) {
  $page_title     = $page_resources[0]->title();   $page_ispage       = $page_resources[0]->is_page();
  my $resourcesymb   = $page_resources[0]->symb();   $page_title     = $page_resources[0]->title();
  my ($pagemap, $pageid, $pageurl) = &Apache::lonnet::decode_symb($symb);   my $resourcesymb   = $page_resources[0]->symb();
  if ($page_ispage) {   my ($pagemap, $pageid, $pageurl) = &Apache::lonnet::decode_symb($symb);
     push @{$printChoices},    if ($page_ispage) {
     [&mt('Selected [_1]Problems[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'),       push @{$printChoices}, 
      'map_problems_in_page',       [&mt('Selected [_1]Problems[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'), 
      'CHOOSE_PROBLEMS_PAGE'];       'map_problems_in_page', 
     push @{$printChoices},        'CHOOSE_PROBLEMS_PAGE'];
          [&mt('Selected [_1]Resources[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'),       push @{$printChoices}, 
   'map_resources_in_page',       [&mt('Selected [_1]Resources[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'), 
   'CHOOSE_RESOURCES_PAGE'];       'map_resources_in_page', 
  }       'CHOOSE_RESOURCES_PAGE'];
    }
         my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS_PAGE',          my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS_PAGE',
  'Select Problem(s) to print',   'Select Problem(s) to print',
  "multichoice='1' toponly='1', addstatus='1' closeallpages='1'",   "multichoice='1' toponly='1' addstatus='1' closeallpages='1'",
  'RESOURCES',   'RESOURCES',
  'PAGESIZE',   'PAGESIZE',
  $url,   $url,
Line 3174  sub printHelper { Line 3392  sub printHelper {
   
  &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);   &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
   
     }      }
    }
     }      }
   
     if (($helper->{'VAR'}->{'construction'} ne '1' ) &&      if (($helper->{'VAR'}->{'construction'} ne '1' ) &&
Line 3189  sub printHelper { Line 3408  sub printHelper {
         push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from folder [_3]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>'),           push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from folder [_3]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>'), 
  'map_problems_pages',    'map_problems_pages', 
  'CHOOSE_PROBLEMS_HTML'];   'CHOOSE_PROBLEMS_HTML'];
  &Apache::lonnet::logthis("Map url : $map");  
         my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS',          my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS',
  'Select Problem(s) to print',   'Select Problem(s) to print',
  'multichoice="1" toponly="1" addstatus="1" closeallpages="1"',   'multichoice="1" toponly="1" addstatus="1" closeallpages="1"',
Line 3248  ALL_PROBLEMS Line 3466  ALL_PROBLEMS
       'RESOURCES',        'RESOURCES',
       'PAGESIZE',        'PAGESIZE',
       '',        '',
       $isNotMap,,$symbFilter,        $isNotMap,'',$symbFilter,
       $start_new_option) .        $start_new_option) .
    &generate_resource_chooser('ALL_PROBLEMS_STUDENTS',     &generate_resource_chooser('ALL_PROBLEMS_STUDENTS',
       'Select Problem(s) to print',        'Select Problem(s) to print',
Line 3256  ALL_PROBLEMS Line 3474  ALL_PROBLEMS
       'RESOURCES',        'RESOURCES',
       'STUDENTS1',        'STUDENTS1',
       '',        '',
       $isProblemOrMap, , $symbFilter,        $isProblemOrMap,'' , $symbFilter,
       $start_new_option) .        $start_new_option) .
      $suffixXml       $suffixXml
    );     );
Line 3269  ALL_PROBLEMS Line 3487  ALL_PROBLEMS
     if ($page_ispage) {      if ($page_ispage) {
  push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]selected people[_5]',   push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]selected people[_5]',
     '<b>', '</b>', '<b><i>'.$page_title.'</i></b>', '<b>', '</b>'),      '<b>', '</b>', '<b><i>'.$page_title.'</i></b>', '<b>', '</b>'),
  'problems_for_students', 'CHOOSE_STUDENTS'];   'problems_for_students_from_page', 'CHOOSE_TGT_STUDENTS_PAGE'];
  push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]CODEd assignments[_5]',   push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from page [_3] for [_4]CODEd assignments[_5]',
     '<b>', '</b>', '<b><i>'.$page_title.'</i></b>', '<b>', '</b>'),      '<b>', '</b>', '<b><i>'.$page_title.'</i></b>', '<b>', '</b>'),
  'problems_for_anon', 'CHOOSE_ANON1'];   'problems_for_anon_page', 'CHOOSE_ANON1_PAGE'];
     }      }
     push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]',      push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]',
  '<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'),    '<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'), 
Line 3299  ALL_PROBLEMS Line 3517  ALL_PROBLEMS
   'multichoice="1" addstatus="1" closeallpages="1"',    'multichoice="1" addstatus="1" closeallpages="1"',
   'RESOURCES',     'RESOURCES', 
   'PRINT_FORMATTING',    'PRINT_FORMATTING',
   '',    $map,
   $isProblem, , $symbFilter,    $isProblem, '', $symbFilter,
   $start_new_option);    $start_new_option);
  $resource_selector .=  <<RESOURCE_SELECTOR;   $resource_selector .=  <<RESOURCE_SELECTOR;
     <state name="PRINT_FORMATTING" title="How should results be printed?">      <state name="PRINT_FORMATTING" title="How should results be printed?">
Line 3322  ALL_PROBLEMS Line 3540  ALL_PROBLEMS
     </choices>      </choices>
     </state>      </state>
 RESOURCE_SELECTOR  RESOURCE_SELECTOR
           $resource_selector .= &generate_resource_chooser('CHOOSE_STUDENTS_PAGE',
    'Select Problem(s) to print',
    "multichoice='1' addstatus='1' closeallpages ='1'",
    'RESOURCES',
    'PRINT_FORMATTING',
    $url,
    $isProblem, '',  $symbFilter,
    $start_new_option);
   
 # Generate student choosers.  
   
   # Generate student choosers.
   
   
   
           &Apache::lonxml::xmlparse($r, 'helper',
     &generate_student_chooser('CHOOSE_TGT_STUDENTS_PAGE',
       'student_sort',
       'STUDENTS',
       'CHOOSE_STUDENTS_PAGE'));
  &Apache::lonxml::xmlparse($r, 'helper',    &Apache::lonxml::xmlparse($r, 'helper', 
   &generate_student_chooser('CHOOSE_STUDENTS',    &generate_student_chooser('CHOOSE_STUDENTS',
     'student_sort',      'student_sort',
Line 3391  RESOURCE_SELECTOR Line 3622  RESOURCE_SELECTOR
  if ($codechoice eq '') {   if ($codechoice eq '') {
     $codechoice='<choice computer="default">Default</choice>';      $codechoice='<choice computer="default">Default</choice>';
  }   }
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);   my $anon1 = &generate_code_selector($helper, 
   <state name="CHOOSE_ANON1" title="Specify CODEd Assignments">      'CHOOSE_ANON1',
     <nextstate>SELECT_PROBLEMS</nextstate>      'SELECT_PROBLEMS',
     <message><h4>Fill out one of the forms below</h4></message>      $codechoice,
     <message><br /><hr /> <br /></message>      $code_selection,
     <message><h3>Generate new CODEd Assignments</h3></message>      $namechoice) . $resource_selector;
     <message><table><tr><td><b>Number of CODEd assignments to print:</b></td><td></message>      
     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5">      
        <validator>          &Apache::lonxml::xmlparse($r, 'helper',$anon1);
  if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) < 1) &&  
     !\$helper->{'VARS'}{'REUSE_OLD_CODES'}                &&   my $anon_page = &generate_code_selector($helper,
             !\$helper->{'VARS'}{'SINGLE_CODE'}                    &&   'CHOOSE_ANON1_PAGE',
     !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {   'SELECT_PROBLEMS_PAGE',
     return "You need to specify the number of assignments to print";   $codechoice,
  }   $code_selection,
  return undef;   $namechoice) .
        </validator>   &generate_resource_chooser('SELECT_PROBLEMS_PAGE',
     </string>     'Select Problem(s) to print',
     <message></td></tr><tr><td></message>     "multichoice='1' addstatus='1' closeallpages ='1'",
     <message><b>Names to save the CODEs under for later:</b></message>     'RESOURCES',
     <message></td><td></message>     'PRINT_FORMATTING',
     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />     $url,
     <message></td></tr><tr><td></message>     $isProblem, '',  $symbFilter,
     <message><b>Bubble sheet type:</b></message>     $start_new_option);
     <message></td><td></message>   &Apache::lonxml::xmlparse($r, 'helper', $anon_page);
     <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">  
     $codechoice  
     </dropdown>  
     <message></td></tr><tr><td colspan="2"></td></tr><tr><td></message>  
     <message></td></tr><tr><td></table></message>  
     <message><br /><hr /><h3>Print a Specific CODE </h3><br /><table></message>  
     <message><tr><td><b>Enter a CODE to print:</b></td><td></message>  
     <string variable="SINGLE_CODE" size="10">  
         <validator>  
    if(!\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}           &&  
       !\$helper->{'VARS'}{'REUSE_OLD_CODES'}                 &&  
       !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {  
       return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},  
       \$helper->{'VARS'}{'CODE_OPTION'});  
    } else {  
        return undef; # Other forces control us.  
    }  
         </validator>  
     </string>  
     <message></td></tr><tr><td></message>  
         $code_selection  
     <message></td></tr></table></message>  
     <message><hr /><h3>Reprint a Set of Saved CODEs</h3><table><tr><td></message>  
     <message><b>Select saved CODEs:</b></message>  
     <message></td><td></message>  
     <dropdown variable="REUSE_OLD_CODES">  
         $namechoice  
     </dropdown>  
     <message></td></tr></table></message>  
   </state>  
   $resource_selector  
 CHOOSE_ANON1  
   
   
  if ($helper->{VARS}->{'assignment'}) {   if ($helper->{VARS}->{'assignment'}) {

Removed from v.1.560.2.3  
changed lines
  Added in v.1.571


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>