Diff for /loncom/interface/lonprintout.pm between versions 1.560 and 1.578

version 1.560, 2009/08/03 11:01:14 version 1.578, 2010/05/24 09:32:11
Line 1 Line 1
   #
 # The LearningOnline Network  # The LearningOnline Network
 # Printout  # Printout
 #  #
Line 26 Line 27
 #  #
 #  #
 package Apache::lonprintout;  package Apache::lonprintout;
   
 use strict;  use strict;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
 use Apache::lonxml;  use Apache::lonxml;
Line 74  my $ssi_retry_count = 5; # Some arbitrar Line 74  my $ssi_retry_count = 5; # Some arbitrar
   
 my $font_size = 'normalsize'; # Default is normalsize...  my $font_size = 'normalsize'; # Default is normalsize...
   
   #----------------------------  Helper helpers. -------------------------
   
   #  Returns the text needd for a student chooser.
   #  that text must still be parsed by the helper xml parser.
   # Parameters:
   #   this_state   - State name of the chooser.
   #   sort_choice  - variable to hold the sorting choice.
   #   variable     - Name of variable to hold students.
   #   next_state   - State after chooser.
   
   
   sub generate_student_chooser {
       my ($this_state, 
    $sort_choice, 
    $variable, 
    $next_state) = @_;
       my $result = <<CHOOSE_STUDENTS;
     <state name="$this_state" title="Select Students and Resources">
         <message><b>Select sorting order of printout</b> </message>
   
       <choices variable="$sort_choice">
         <choice computer='0'>Sort by section then student</choice>
         <choice computer='1'>Sort by students across sections.</choice>
       </choices>
   
         <message><br /><hr /><br /> </message>
         <student multichoice='1' 
                  variable="$variable" 
                  nextstate="$next_state" 
                  coursepersonnel="1" />
     </state>
   
   CHOOSE_STUDENTS
   
     return $result;
   }
   
   # Generate the text needed for a resource chooser given the top level of
   # the sequence/page
   #
   # Parameters:
   #     this_state    - State name of the chooser.
   #     prompt_text   - Text to use to prompt user.
   #     resource_options - Resource tag options e.g.
   #                        "multichoice='1', toponly='1', addstatus='1'"
   #                     that control the selection and appearance of the
   #                     resource selector.
   #     variable      - Name of the variable to hold the choice
   #     next_state    - Name of the next state the helper should transition
   #                     to
   #     top_url       - Top level URL within which to make the selector.
   #                     If empty the top level sequence is shown.
   #     filter        - How to filter the resources.
   #     value_func    - <valuefunc> function.
   #     choice_func   - If not empty generates a <choicefunc> with this function.
   #     start_new_option 
   #                   - Fragment appended after valuefunc.
   #
   #
   sub generate_resource_chooser {
       my ($this_state,
    $prompt_text,
    $resource_options,
    $variable,
    $next_state,
    $top_url,
    $filter,
    $choice_func,
    $value_func,
    $start_new_option)  = @_;
   
       my $result = <<CHOOSE_RESOURCES;
   <state name="$this_state" title="$prompt_text">
       <resource variable="$variable" $resource_options
                 closeallpages="1">
         <nextstate>$next_state</nextstate>
         <filterfunc>return $filter;</filterfunc>
   CHOOSE_RESOURCES
       if ($choice_func ne '') {
    $result .= "<choicefunc>return $choice_func;</choicefunc>";
       }
       if ($top_url ne '') {
    $result .=  "<mapurl>$top_url</mapurl>";
       }
       $result .= <<CHOOSE_RESOURCES;
         <valuefunc>return $value_func;</valuefunc>
         $start_new_option
         </resource>
       </state>
   CHOOSE_RESOURCES
   
       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";
    }
           if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) >= 1)  &&
                (\$helper->{'VARS'}{'SINGLE_CODE'} ne '') ) {
               return 'Specifying number of codes to print and a specific code is not compatible';
           }
    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'});
     } elsif (\$helper->{'VARS'}{'SINGLE_CODE'} ne ''){
         return 'Specifying a code name is incompatible with specifying number of codes.';
      } 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;
   }
   
   #-----------------------------------------------------------------------
   
   
 # Fetch the contents of a resource, uninterpreted.  # Fetch the contents of a resource, uninterpreted.
 # This is used here to fetch a latex file to be included  # This is used here to fetch a latex file to be included
Line 129  sub set_font_size { Line 313  sub set_font_size {
   
     my ($text) = @_;      my ($text) = @_;
   
     $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/;      # There appear to be cases where the font directive is empty.. in which
       # case the first substituion would  insert a spurious \ oh happy day.
       # as this has been the cause of much mystery and hair pulling _sigh_
   
       if ($font_size ne '') {
   
    $text =~ s/\\begin{document}/\\begin{document}{\\$font_size/;
       }
     $text =~ s/\\end{document}/}\\end{document}/;      $text =~ s/\\end{document}/}\\end{document}/;
     return $text;      return $text;
   
Line 322  sub printf_style_subst { Line 513  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 337  sub format_page_header { Line 531  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 375  sub format_page_header { Line 568  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 1086  sub page_format_transformation { Line 1291  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 1118  sub page_format_transformation { Line 1323  sub page_format_transformation {
     $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1}  \\vskip 5 mm\n /;      $text =~ s/\\pagestyle{fancy}\\rhead{}\\chead{}\s*\\begin{document}/\\textheight = $textheight\\oddsidemargin = $evenoffset\n\\evensidemargin = $evenoffset $topmargintoinsert\\textwidth= $textwidth\\newlength{\\minipagewidth}\n\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\renewcommand{\\ref}{\\keephidden\}\\pagestyle{fancy}\\rhead{}\\chead{}\\usepackage{booktabs}\\begin{document}\\voffset=-0\.8cm\n\\setcounter{page}{1}  \\vskip 5 mm\n /;
  }   }
  if ($papersize eq 'a4') {   if ($papersize eq 'a4') {
     $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/;      my $papersize_text;
       if ($perm{'pav'}) {
    $papersize_text = '\\special{papersize=210mm,297mm}';
       } else {
    $papersize_text = '\special{papersize=210mm,297mm}';
       }
       $text =~ s/(\\begin{document})/$1$papersize_text/;
  }   }
     }      }
     if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}      if ($tableofcontents eq 'yes') {$text=~s/(\\setcounter\{page\}\{1\})/$1 \\tableofcontents\\newpage /;}
Line 1343  sub print_page_in_course { Line 1554  sub print_page_in_course {
   
   
     if ($mode ne '') {$mode='\\'.$mode}      if ($mode ne '') {$mode='\\'.$mode}
     my $result.= &print_latex_header($mode);      my $result   =    &print_latex_header($mode);
     if ($currentURL=~m|^(/adm/wrapper/)?ext/|) {      if ($currentURL=~m|^(/adm/wrapper/)?ext/|) {
  $currentURL=~s|^(/adm/wrapper/)?ext/|http://|;   $currentURL=~s|^(/adm/wrapper/)?ext/|http://|;
  my $title=&Apache::lonnet::gettitle($symb);   my $title=&Apache::lonnet::gettitle($symb);
Line 1362  sub print_page_in_course { Line 1573  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 1379  sub print_page_in_course { Line 1590  sub print_page_in_course {
  }   }
  # these resources go through the XML transformer:   # these resources go through the XML transformer:
   
  elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm\xhtml|xhtm)$/)  {   elsif ($resource_src =~ /\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)$/)  {
     my $urlp = &Apache::lonnet::clutter($resource_src);      my $urlp = &Apache::lonnet::clutter($resource_src);
     my %form;      my %form;
     my %moreenv;      my %moreenv;
Line 1390  sub print_page_in_course { Line 1601  sub print_page_in_course {
   
     $form{'grade_target'}  = 'tex';      $form{'grade_target'}  = 'tex';
     $form{'textwidth'}    = &get_textwidth($helper, $LaTeXwidth);      $form{'textwidth'}    = &get_textwidth($helper, $LaTeXwidth);
     $form{'pdfFormFiels'} = $pdfFormFields; #       $form{'pdfFormFields'} = $pdfFormFields; # 
     $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};          $form{'showallfoils'} = $helper->{'VARS'}->{'showallfoils'};    
           
     $form{'problem_split'}=$parmhash{'problem_stream_switch'};      $form{'problem_split'}=$parmhash{'problem_stream_switch'};
Line 1413  sub print_page_in_course { Line 1624  sub print_page_in_course {
   
     my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);      my $texversion = &ssi_with_retries($urlp, $ssi_retry_count, %form);
   
     # There seems to be an extraneous \vskip 1mm \\\\ :  
   
     $texversion =~ s/^\\vskip 1mm \\\\\\\\//;  
   
     # current document with answers.. no need to encap in minipage      # current document with answers.. no need to encap in minipage
     #  since there's only one answer.      #  since there's only one answer.
Line 1438  sub print_page_in_course { Line 1646  sub print_page_in_course {
  if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {   if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
     $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;      $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
  } else {   } else {
     $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});      $texversion= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
     if ($helper->{'VARS'}->{'construction'} ne '1') {      if ($helper->{'VARS'}->{'construction'} ne '1') {
  my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});   my $title = &Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'});
  $title = &Apache::lonxml::latex_special_symbols($title);   $title = &Apache::lonxml::latex_special_symbols($title);
Line 1473  sub print_page_in_course { Line 1681  sub print_page_in_course {
  $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;   $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$currentURL| \\strut\\\\\\strut /;
   
     }      }
       $texversion = &latex_header_footer_remove($texversion);
   
       # the first remaining line is a comment from londefdef the second
       # line  seems to be an extraneous \vskip 1mm \\\\ :
               # (imperfect removal from header_footer_remove?
   
       $texversion =~ s/\\vskip 1mm \\\\\\\\//;
   
     $result .= $texversion;      $result .= $texversion;
     if ($currentURL=~m/\.page\s*$/) {      if ($currentURL=~m/\.page\s*$/) {
  ($result,$numberofcolumns) = &page_cleanup($result);   ($result,$numberofcolumns) = &page_cleanup($result);
Line 1560  sub recently_generated { Line 1776  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 1576  sub get_page_breaks  { Line 1792  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 1747  ENDPART Line 2079  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 1912  ENDPART Line 2246  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 1924  ENDPART Line 2257  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 1957  ENDPART Line 2290  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'});
  }   }
     } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems')       or      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems')       or
        ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_in_page') or
        ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page') or
              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or               ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
              ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')       or               ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')       or
      ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources')      or # BUGBUG       ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_resources')      or # BUGBUG
Line 1970  ENDPART Line 2304  ENDPART
   
   
         #-- produce an output string          #-- produce an output string
  if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') {   if (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems')  or
       ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_in_page') ) {
     $selectionmade = 2;      $selectionmade = 2;
  } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {   } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') or
    ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_resources_in_page'))
    {
     $selectionmade = 3;      $selectionmade = 3;
  } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems')    } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'all_problems') 
  ) {   ) {
Line 2012  ENDPART Line 2349  ENDPART
     $result.="\\newpage\n";      $result.="\\newpage\n";
  }   }
     }      }
       $result .= &get_extra_vspaces($helper, $master_seq[$i]);
     my ($sequence,$middle_thingy,$urlp)=&Apache::lonnet::decode_symb($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];
   
   
     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 2026  ENDPART Line 2363  ENDPART
  && $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)$/) {
  $resources_printed .= $urlp.':';   $resources_printed .= $urlp.':';
  &Apache::lonxml::remember_problem_counter();   &Apache::lonxml::remember_problem_counter();
    if ($flag_latex_header_remove eq 'NO') {
       $texversion.=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});  # RF
       $flag_latex_header_remove = 'YES';
    }
  $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);   $texversion.=&ssi_with_retries($urlp, $ssi_retry_count, %form);
  if ($urlp=~/\.page$/) {   if ($urlp=~/\.page$/) {
   
     ($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 2100  ENDPART Line 2440  ENDPART
  $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 2151  ENDPART Line 2491  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 2158  ENDPART Line 2499  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 2197  ENDPART Line 2539  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 2245  ENDPART Line 2588  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 2600  sub print_resources { Line 2944  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 2620  sub print_resources { Line 2964  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 2648  sub print_resources { Line 2991  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 2661  sub print_resources { Line 3004  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 2705  sub print_resources { Line 3051  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 2850  sub printHelper { Line 3199  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 2872  sub printHelper { Line 3223  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 2927  sub printHelper { Line 3283  sub printHelper {
         $subdir = substr($helper->{VARS}->{'filename'},          $subdir = substr($helper->{VARS}->{'filename'},
                          0, rindex($helper->{VARS}->{'filename'}, '/') + 1);                           0, rindex($helper->{VARS}->{'filename'}, '/') + 1);
     } else {      } else {
    # From course space:
   
  if ($symb ne '') {   if ($symb ne '') {
     ($map, $id, $url) = &Apache::lonnet::decode_symb($symb);      ($map, $id, $url) = &Apache::lonnet::decode_symb($symb);
     $helper->{VARS}->{'postdata'} =       $helper->{VARS}->{'postdata'} = 
Line 2936  sub printHelper { Line 3294  sub printHelper {
     $is_published=1; # From resource space.      $is_published=1; # From resource space.
  }   }
  $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
             my $postdata = $helper->{VARS}->{'postdata'};              my $postdata = $helper->{VARS}->{'postdata'};
             $resourceTitle = substr($postdata, rindex($postdata, '/') + 1);              $resourceTitle = substr($postdata, rindex($postdata, '/') + 1);
Line 2993  sub printHelper { Line 3350  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:
   
       my $page_ispage;
       my $page_title;
       if (!$helper->{VARS}->{'construction'}) {
    my $varspostdata = $helper->{VARS}->{'postdata'};
    my $varsassignment = $helper->{VARS}->{'assignment'};
    my $page_navmap         = Apache::lonnavmaps::navmap->new();
    if (defined($page_navmap)) {
       my @page_resources      = $page_navmap->retrieveResources($url);
       if(defined($page_resources[0])) {
    $page_ispage       = $page_resources[0]->is_page();
    $page_title     = $page_resources[0]->title();
    my $resourcesymb   = $page_resources[0]->symb();
    my ($pagemap, $pageid, $pageurl) = &Apache::lonnet::decode_symb($symb);
    if ($page_ispage) {
       push @{$printChoices}, 
       [&mt('Selected [_1]Problems[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'), 
        'map_problems_in_page', 
        'CHOOSE_PROBLEMS_PAGE'];
       push @{$printChoices}, 
       [&mt('Selected [_1]Resources[_2] from page [_3]', '<b>', '</b>', '<b><i>'.$page_title.'</i></b>'), 
        'map_resources_in_page', 
        'CHOOSE_RESOURCES_PAGE'];
    }
           my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS_PAGE',
    'Select Problem(s) to print',
    "multichoice='1' toponly='1' addstatus='1' closeallpages='1'",
    'RESOURCES',
    'PAGESIZE',
    $url,
    $isProblem, '',  $symbFilter,
    $start_new_option);
   
   
         $helperFragment .= &generate_resource_chooser('CHOOSE_RESOURCES_PAGE',
       'Select Resource(s) to print',
       'multichoice="1" toponly="1" addstatus="1" closeallpages="1"',
       'RESOURCES',
       'PAGESIZE',
       $url,
       $isNotMap, '', $symbFilter,
       $start_new_option);
   
       
   
   
   
    &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
   
       }
    }
     }      }
   
     if (($helper->{'VARS'}->{'construction'} ne '1' ) &&      if (($helper->{'VAR'}->{'construction'} ne '1' ) &&
  $helper->{VARS}->{'postdata'} &&   $helper->{VARS}->{'postdata'} &&
  $helper->{VARS}->{'assignment'}) {   $helper->{VARS}->{'assignment'}) {
         # Allow problems from sequence          # Allow problems from sequence
         push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>'), 'map_problems', 'CHOOSE_PROBLEMS'];          push @{$printChoices}, 
       [&mt('Selected [_1]Problems[_2] from folder [_3]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>'), 
        'map_problems', 
        'CHOOSE_PROBLEMS'];
         # Allow all resources from sequence          # Allow all resources from sequence
         push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from folder [_3]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>'), 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];          push @{$printChoices}, [&mt('Selected [_1]Resources[_2] from folder [_3]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>'), 
    'map_problems_pages', 
         my $helperFragment = <<HELPERFRAGMENT;   'CHOOSE_PROBLEMS_HTML'];
   <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">          my $helperFragment = &generate_resource_chooser('CHOOSE_PROBLEMS',
     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"   'Select Problem(s) to print',
               closeallpages="1">   'multichoice="1" toponly="1" addstatus="1" closeallpages="1"',
       <nextstate>PAGESIZE</nextstate>   'RESOURCES',
       <filterfunc>return $isProblem;</filterfunc>   'PAGESIZE',
       <mapurl>$map</mapurl>   $map,
       <valuefunc>return $symbFilter;</valuefunc>   $isProblem, '',
       $start_new_option   $symbFilter,
       </resource>   $start_new_option);
     </state>   $helperFragment .= &generate_resource_chooser('CHOOSE_PROBLEMS_HTML',
         'Select Resource(s) to print',
   <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">         'multichoice="1" toponly="1" addstatus="1" closeallpages="1"',
     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"        'RESOURCES',
               closeallpages="1">        'PAGESIZE',
       <nextstate>PAGESIZE</nextstate>        $map,
       <filterfunc>return $isNotMap;</filterfunc>        $isNotMap, '',
       <mapurl>$map</mapurl>        $symbFilter,
       <valuefunc>return $symbFilter;</valuefunc>        $start_new_option);
       $start_new_option  
       </resource>  
     </state>  
 HELPERFRAGMENT  
   
  &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);   &Apache::lonxml::xmlparse($r, 'helper', $helperFragment);
     }      }
   
     # If the user has pfo (print for others) allow them to print all       # If the user has pfo (print for others) allow them to print all 
     # problems and resources  in the entire course, optionally for selected students      # problems and resources  in the entire course, optionally for selected students
       my $post_data = $helper->{VARS}->{'postdata'};
     if ($perm{'pfo'} &&  !$is_published  &&      if ($perm{'pfo'} &&  !$is_published  &&
         ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) {           ($post_data=~/\/res\// || $post_data =~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) { 
   
         push @{$printChoices}, [&mtn('Selected <b>Problems</b> from <b>entire course</b>'), 'all_problems', 'ALL_PROBLEMS'];          push @{$printChoices}, [&mtn('Selected <b>Problems</b> from <b>entire course</b>'), 'all_problems', 'ALL_PROBLEMS'];
  push @{$printChoices}, [&mtn('Selected <b>Resources</b> from <b>entire course</b>'), 'all_resources', 'ALL_RESOURCES'];   push @{$printChoices}, [&mtn('Selected <b>Resources</b> from <b>entire course</b>'), 'all_resources', 'ALL_RESOURCES'];
  push @{$printChoices}, [&mtn('Selected <b>Problems</b> from <b>entire course</b> for <b>selected people</b>'), 'all_problems_students', 'ALL_PROBLEMS_STUDENTS'];   push @{$printChoices}, [&mtn('Selected <b>Problems</b> from <b>entire course</b> for <b>selected people</b>'), 'all_problems_students', 'ALL_PROBLEMS_STUDENTS'];
          &Apache::lonxml::xmlparse($r, 'helper', <<ALL_PROBLEMS);  my $suffixXml = <<ALL_PROBLEMS;
   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">  
     <resource variable="RESOURCES" toponly='0' multichoice="1"  
  suppressEmptySequences='0' addstatus="1" closeallpages="1">  
       <nextstate>PAGESIZE</nextstate>  
       <filterfunc>return $isProblemOrMap;</filterfunc>  
       <choicefunc>return $isNotMap;</choicefunc>  
       <valuefunc>return $symbFilter;</valuefunc>  
       $start_new_option  
     </resource>  
   </state>  
   <state name="ALL_RESOURCES" title="Select Resource(s) to print">  
     <resource variable="RESOURCES" toponly='0' multichoice='1'  
               suppressEmptySequences='0' addstatus='1' closeallpages='1'>  
       <nextstate>PAGESIZE</nextstate>  
       <filterfunc>return $isNotMap; </filterfunc>  
       <valuefunc>return $symbFilter;</valuefunc>  
       $start_new_option  
     </resource>  
   </state>  
   <state name="ALL_PROBLEMS_STUDENTS" title="Select Problem(s) to print">  
     <resource variable="RESOURCES" toponly='0' multichoice="1"  
  suppressEmptySequences='0' addstatus="1" closeallpages="1">  
       <nextstate>STUDENTS1</nextstate>  
       <filterfunc>return $isProblemOrMap;</filterfunc>  
       <choicefunc>return $isNotMap;</choicefunc>  
       <valuefunc>return $symbFilter;</valuefunc>  
       $start_new_option  
     </resource>  
   </state>  
   <state name="STUDENTS1" title="Select People">    <state name="STUDENTS1" title="Select People">
       <message><b>Select sorting order of printout</b> </message>        <message><b>Select sorting order of printout</b> </message>
     <choices variable='student_sort'>      <choices variable='student_sort'>
Line 3078  HELPERFRAGMENT Line 3469  HELPERFRAGMENT
       <message><br /><hr /><br /> </message>        <message><br /><hr /><br /> </message>
       <student multichoice='1' variable="STUDENTS" nextstate="PRINT_FORMATTING" coursepersonnel="1"/>        <student multichoice='1' variable="STUDENTS" nextstate="PRINT_FORMATTING" coursepersonnel="1"/>
   </state>    </state>
   
 ALL_PROBLEMS  ALL_PROBLEMS
            &Apache::lonxml::xmlparse($r, 'helper', 
      &generate_resource_chooser('ALL_PROBLEMS',
         'SelectProblem(s) to print',
         'multichoice="1" suppressEmptySequences="0" addstatus="1" closeallpages="1"',
         'RESOURCES',
         'PAGESIZE',
         '',
         $isProblemOrMap, $isNotMap,
         $symbFilter,
         $start_new_option) .
      &generate_resource_chooser('ALL_RESOURCES',
         'Select Resource(s) to print',
         " toponly='0' multichoice='1' suppressEmptySequences='0' addstatus='1' closeallpages='1'",
         'RESOURCES',
         'PAGESIZE',
         '',
         $isNotMap,'',$symbFilter,
         $start_new_option) .
      &generate_resource_chooser('ALL_PROBLEMS_STUDENTS',
         'Select Problem(s) to print',
         'toponly="0" multichoice="1" suppressEmptySequences="0" addstatus="1" closeallpages="1"',
         'RESOURCES',
         'STUDENTS1',
         '',
         $isProblemOrMap,'' , $symbFilter,
         $start_new_option) .
        $suffixXml
      );
   
  if ($helper->{VARS}->{'assignment'}) {   if ($helper->{VARS}->{'assignment'}) {
     push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'), 'problems_for_students', 'CHOOSE_STUDENTS'];  
     push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]CODEd assignments[_5]','<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'), 'problems_for_anon', 'CHOOSE_ANON1'];      # If we were looking at a page, allow a selection of problems from the page
       # either for selected students or for coded assignments.
   
       if ($page_ispage) {
    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>'),
    'problems_for_students_from_page', 'CHOOSE_TGT_STUDENTS_PAGE'];
    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>'),
    'problems_for_anon_page', 'CHOOSE_ANON1_PAGE'];
       }
       push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]selected people[_5]',
    '<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'), 
       'problems_for_students', 'CHOOSE_STUDENTS'];
       push @{$printChoices}, [&mt('Selected [_1]Problems[_2] from folder [_3] for [_4]CODEd assignments[_5]',
    '<b>','</b>','<b><i>'.$sequenceTitle.'</i></b>','<b>','</b>'), 
       'problems_for_anon', 'CHOOSE_ANON1'];
  }   }
   
  my $randomly_ordered_warning =    my $randomly_ordered_warning = 
Line 3098  ALL_PROBLEMS Line 3532  ALL_PROBLEMS
  #    with one state, and use REGEXPs at inclusion time to set state names   #    with one state, and use REGEXPs at inclusion time to set state names
  #    and next states for better mix and match capability   #    and next states for better mix and match capability
  #   #
  my $resource_selector=<<RESOURCE_SELECTOR;   my $resource_selector= &generate_resource_chooser('SELECT_PROBLEMS',
     <state name="SELECT_PROBLEMS" title="Select resources to print">    'Select resources to print',
     $randomly_ordered_warning    'multichoice="1" addstatus="1" closeallpages="1"',
     'RESOURCES', 
    <nextstate>PRINT_FORMATTING</nextstate>     'PRINT_FORMATTING',
    <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>    $map,
     <resource variable="RESOURCES" multichoice="1" addstatus="1"     $isProblem, '', $symbFilter,
               closeallpages="1">    $start_new_option);
       <filterfunc>return $isProblem;</filterfunc>   $resource_selector .=  <<RESOURCE_SELECTOR;
       <mapurl>$map</mapurl>  
       <valuefunc>return $symbFilter;</valuefunc>  
       $start_new_option  
       </resource>  
     </state>  
     <state name="PRINT_FORMATTING" title="How should results be printed?">      <state name="PRINT_FORMATTING" title="How should results be printed?">
     <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>      <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
     <choices variable="EMPTY_PAGES">      <choices variable="EMPTY_PAGES">
Line 3131  ALL_PROBLEMS Line 3560  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.
   
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);  
   <state name="CHOOSE_STUDENTS" title="Select Students and Resources">  
       <message><b>Select sorting order of printout</b> </message>          &Apache::lonxml::xmlparse($r, 'helper',
     <choices variable='student_sort'>    &generate_student_chooser('CHOOSE_TGT_STUDENTS_PAGE',
       <choice computer='0'>Sort by section then student</choice>      'student_sort',
       <choice computer='1'>Sort by students across sections.</choice>      'STUDENTS',
     </choices>      'CHOOSE_STUDENTS_PAGE'));
       <message><br /><hr /><br /> </message>   &Apache::lonxml::xmlparse($r, 'helper', 
       <student multichoice='1' variable="STUDENTS" nextstate="SELECT_PROBLEMS" coursepersonnel="1"/>    &generate_student_chooser('CHOOSE_STUDENTS',
   </state>      'student_sort',
     $resource_selector      'STUDENTS',
 CHOOSE_STUDENTS      'SELECT_PROBLEMS'));
    &Apache::lonxml::xmlparse($r, 'helper', $resource_selector);
   
  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 3201  CHOOSE_STUDENTS Line 3642  CHOOSE_STUDENTS
  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'}) {
Line 3269  CHOOSE_ANON1 Line 3678  CHOOSE_ANON1
  $resource_selector=<<RESOURCE_SELECTOR;   $resource_selector=<<RESOURCE_SELECTOR;
     <state name="SELECT_RESOURCES" title="Select Resources">      <state name="SELECT_RESOURCES" title="Select Resources">
     $randomly_ordered_warning      $randomly_ordered_warning
   
     <nextstate>PRINT_FORMATTING</nextstate>      <nextstate>PRINT_FORMATTING</nextstate>
     <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>      <message><br /><big><i><b>Select resources for the assignment</b></i></big><br /></message>
     <resource variable="RESOURCES" multichoice="1" addstatus="1"       <resource variable="RESOURCES" multichoice="1" addstatus="1" 
Line 3280  CHOOSE_ANON1 Line 3688  CHOOSE_ANON1
       $start_new_option        $start_new_option
       </resource>        </resource>
     </state>      </state>
   
     <state name="PRINT_FORMATTING" title="Format of the print job">      <state name="PRINT_FORMATTING" title="Format of the print job">
     <nextstate>NUMBER_PER_PDF</nextstate>      <nextstate>NUMBER_PER_PDF</nextstate>
     <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>      <message><br /><big><i><b>How should the results be printed?</b></i></big><br /></message>
Line 3329  CHOOSE_STUDENTS1 Line 3738  CHOOSE_STUDENTS1
     !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {      !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
     return "You need to specify the number of assignments to print";      return "You need to specify the number of assignments to print";
  }   }
           if (((\$helper->{'VARS'}{'NUMBER_TO_PRINT_TOTAL'}+0) >= 1)  &&
                (\$helper->{'VARS'}{'SINGLE_CODE'} ne '') ) {
               return 'Specifying number of codes to print and a specific code is not compatible';
           }
  return undef;   return undef;
        </validator>         </validator>
     </string>      </string>
Line 3352  CHOOSE_STUDENTS1 Line 3765  CHOOSE_STUDENTS1
       !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {        !\$helper->{'VARS'}{'CODE_SELECTED_FROM_LIST'}) {
       return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},        return &Apache::lonprintout::is_code_valid(\$helper->{'VARS'}{'SINGLE_CODE'},
       \$helper->{'VARS'}{'CODE_OPTION'});        \$helper->{'VARS'}{'CODE_OPTION'});
     } elsif (\$helper->{'VARS'}{'SINGLE_CODE'} ne ''){
         return 'Specifying a code name is incompatible specifying number of codes.';
    } else {     } else {
        return undef; # Other forces control us.         return undef; # Other forces control us.
    }     }
Line 3664  FONT_SELECTION Line 4079  FONT_SELECTION
    <choice computer="problem">Homework Problem</choice>     <choice computer="problem">Homework Problem</choice>
    <choice computer="exam">Exam Problem</choice>     <choice computer="exam">Exam Problem</choice>
    <choice computer="survey">Survey question</choice>     <choice computer="survey">Survey question</choice>
                      ,choice computer="anonsurvey"Anonymous survey question</choice>
  </dropdown>   </dropdown>
 PROBTYPE  PROBTYPE
             &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);              &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);

Removed from v.1.560  
changed lines
  Added in v.1.578


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