Diff for /loncom/interface/lonprintout.pm between versions 1.592 and 1.601

version 1.592, 2011/06/16 11:59:16 version 1.601, 2011/10/26 02:09:42
Line 123  sub create_incomplete_folder_selstud_hel Line 123  sub create_incomplete_folder_selstud_hel
   
     my $format_chooser = &generate_format_selector($helper,      my $format_chooser = &generate_format_selector($helper,
  'Format of the print job',   'Format of the print job',
  '','CHOOSE_STUDENTS_INCOMPLETE_FORMAT'); # end state.   'CHOOSE_STUDENTS_INCOMPLETE_FORMAT'); # end state.
   
     return $resource_chooser . $student_chooser . $format_chooser;      return $resource_chooser . $student_chooser . $format_chooser;
 }    }  
Line 172  sub create_incomplete_course_helper { Line 172  sub create_incomplete_course_helper {
   
     my $format = &generate_format_selector($helper,      my $format = &generate_format_selector($helper,
    'Format of the print job',     'Format of the print job',
    '',  
    'INCOMPLETE_PROBLEMS_COURSE_FORMAT'); # end state.     'INCOMPLETE_PROBLEMS_COURSE_FORMAT'); # end state.
   
     return $resource_chooser . $people_chooser . $format;      return $resource_chooser . $people_chooser . $format;
Line 356  sub generate_code_selector { Line 355  sub generate_code_selector {
     <message></td><td></message>      <message></td><td></message>
     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />      <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
     <message></td></tr><tr><td></message>      <message></td></tr><tr><td></message>
     <message><b>Bubble sheet type:</b></message>      <message><b>Bubblesheet type:</b></message>
     <message></td><td></message>      <message></td><td></message>
     <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">      <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
     $bubble_types      $bubble_types
Line 395  CHOOSE_ANON1 Line 394  CHOOSE_ANON1
    return $result;     return $result;
 }  }
   
   #  Returns the XML for choosing how assignments are to be formatted 
   #  that text must still be parsed by the helper xml parser.
   # Parameters: 3 (required)
   
   #   helper       - The helper; $helper->{'VARS'}->{'PRINT_TYPE'} used
   #                  to check if splitting PDFs by section can be offered.
   #   title        - Title for the current state. 
   #   this_state   - State name of the chooser.
   
 sub generate_format_selector {  sub generate_format_selector {
     my ($helper,$title,$nextstate, $thisstate) = @_;      my ($helper,$title,$this_state) = @_;
     my $secpdfoption;      my $secpdfoption;
     my $state = 'PRINT_FORMATTING';  
     if ($thisstate) {  
  $state = $thisstate;  
     }  
     unless (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||      unless (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||
             ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon_page') ||              ($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')  ) {
         $secpdfoption =  '<choice computer="sections">Each PDF contains exactly one section</choice>';          $secpdfoption =  '<choice computer="sections">Each PDF contains exactly one section</choice>';
     }      }
     return <<RESOURCE_SELECTOR;      return <<RESOURCE_SELECTOR;
     <state name="$state" title="$title">      <state name="$this_state" title="$title">
     $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>
     <choices variable="EMPTY_PAGES">      <choices variable="EMPTY_PAGES">
       <choice computer='0'>Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)</choice>        <choice computer='0'>Start each student\'s assignment on a new page/column (add a pagefeed after each assignment)</choice>
Line 444  RESOURCE_SELECTOR Line 447  RESOURCE_SELECTOR
 sub incomplete {  sub incomplete {
     my ($username, $domain, $map) = @_;      my ($username, $domain, $map) = @_;
   
     # Manipulate the env so the navmap is made  
     # in the context of the appropriate user:  
   
     my $me         = $env{'user.name'};  
     my $my_domain  = $env{'user.domain'};  
   
     $env{'user.name'} = $username;      my $navmap = Apache::lonnavmaps::navmap->new($username, $domain);
     $env{'user.domain'} = $domain;  
   
     my $navmap = Apache::lonnavmaps::navmap->new();  
           
     $env{'user.name'}   = $me; # Restore user/domain context.  
     $env{'user.domain'} = $my_domain;  
   
     if (defined($navmap)) {      if (defined($navmap)) {
  my $res = $navmap->getResourceByUrl($map);   my $res = $navmap->getResourceByUrl($map);
Line 466  sub incomplete { Line 459  sub incomplete {
  return 1;   return 1;
     }      }
 }  }
   #
   #  When printing for students, the resoures and order of the
   #  resources may need to be altered if there are folders with
   #  random selectiopn or random ordering (or both) enabled.
   #  This sub computes the set of resources to print for a student
   #  modified both by random ordering and selection and filtered
   #  to only those that are in the original set selcted to be printed.
   #
   # Parameters:
   #   $helper - The helper we need $helper->{'VARS'}->{'symb'}
   #            to construct the navmap and the iteration.
   #   $seq   - The original set of resources to print 
   #            (really an array of resource names (array of symb's).
   #   $who   - Student/domain for whome the sequence will be generated.
   #
   # Implicit inputs:
   #   $
   # Returns:
   #   reference to an array of resources that can be passed to
   #   print_resources.
   # 
   sub master_seq_to_person_seq {
       my ($helper, $seq, $who) = @_;
   
   
       my ($username, $userdomain, $usersection) = split(/:/, $who);
   
   
       # Toss the sequence up into a hash so that we have O(1) lookup time.
       # on the items that come out of the user's list of resources.
       #
       
       my %seq_hash = map {$_  => 1} @$seq;
       my @output_seq;
       
       my ($map, $id, $url) = &Apache::lonnet::decode_symb($helper->{VARS}->{'symb'});
       my $navmap           = Apache::lonnavmaps::navmap->new($username, $userdomain);
       my $iterator         = $navmap->getIterator($navmap->firstResource(),
    $navmap->finishResource(),
    {}, 1);
       my %nonResourceItems = (
    $iterator->BEGIN_MAP    => 1,
    $iterator->BEGIN_BRANCH => 1,
    $iterator->END_BRANCH   => 1,
    $iterator->END_MAP      => 1,
    $iterator->FORWARD      => 1,
    $iterator->BACKWARD     => 1
   
       ); # These items are not resources but appear in the midst of iteration.
   
       #  Iterate on the resource..select the items that are randomly selected
       #  and that are in the seq_has.  Presumably the iterator will take care
       # of the random ordering part of the deal.
       #
       my $curres;
       while ($curres = $iterator->next()) {
    #
    #  Only process resources..that are not removed by randomout...
    #  and are selected for printint as well.
    #
    if (! exists $nonResourceItems{$curres} && ! $curres->randomout()) {
       my $symb = $curres->symb();
       if (exists $seq_hash{$symb}) {
    push(@output_seq, $symb);
       }
    }
       }
      
   
       return \@output_seq; # for now.
       
   }
   
   
 # 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 640  sub ssi_with_retries { Line 706  sub ssi_with_retries {
  $ssi_last_error_resource = $resource;   $ssi_last_error_resource = $resource;
  $ssi_last_error          = $response->code . " " . $response->message;   $ssi_last_error          = $response->code . " " . $response->message;
         $content='\section*{!!! An error occurred !!!}';          $content='\section*{!!! An error occurred !!!}';
  &Apache::lonnet::logthis("Error in SSI resource: $resource Error: $ssi_last_error");  
     }      }
   
     return $content;      return $content;
Line 656  sub get_student_view_with_retries { Line 721  sub get_student_view_with_retries {
         $ssi_last_error_resource = $curresline.' for user '.$username.':'.$userdomain;          $ssi_last_error_resource = $curresline.' for user '.$username.':'.$userdomain;
         $ssi_last_error          = $response->code . " " . $response->message;          $ssi_last_error          = $response->code . " " . $response->message;
         $content='\section*{!!! An error occurred !!!}';          $content='\section*{!!! An error occurred !!!}';
         &Apache::lonnet::logthis("Error in SSI (student view) resource: $curresline Error: $ssi_last_error User: $username:$userdomain");  
     }      }
     return $content;      return $content;
   
Line 1865  sub print_page_in_course { Line 1929  sub print_page_in_course {
     } else {      } else {
  $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';   $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';
  my $URLpath=$urlp;   my $URLpath=$urlp;
  $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;   #$URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;
  $texversion.=&path_to_problem($URLpath,$LaTeXwidth);   $texversion.=&path_to_problem($URLpath,$LaTeXwidth);
     }      }
     $texversion.='\vskip 1 mm '.$answer.'\end{document}';      $texversion.='\vskip 1 mm '.$answer.'\end{document}';
Line 1985  sub recently_generated { Line 2049  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'});
Line 2205  sub print_construction_sequence { Line 2269  sub print_construction_sequence {
     # IF sequence, recurse:      # IF sequence, recurse:
           
     if ($urlp =~ /\.sequence$/) {      if ($urlp =~ /\.sequence$/) {
   #
   # FIXME: this does not work for co-authors
  my $sequence_url = $urlp;   my $sequence_url = $urlp;
  my $domain       = $env{'user.domain'}; # Constr. space only on local   my $domain       = $env{'user.domain'}; # Constr. space only on local
  my $user         = $env{'user.name'};   my $user         = $env{'user.name'};
   # FIXME: the substitutions below do not seem to make sense
  $sequence_url    =~ s/^\/res\/$domain/\/home/;   $sequence_url    =~ s/^\/res\/$domain/\/home/;
  $sequence_url    =~ s/^(\/home\/$user)/$1\/public_html/;   $sequence_url    =~ s/^(\/home\/$user)/$1\/public_html/;
 # $sequence_url    =~ s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;  # $sequence_url    =~ s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
Line 2451  ENDPART Line 2517  ENDPART
     } else {      } else {
  $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';   $texversion.='\vskip 0 mm \noindent\textbf{Prints from construction space - there is no title.}\vskip 0 mm ';
  my $URLpath=$cleanURL;   my $URLpath=$cleanURL;
   # FIXME: unclear URL path, not sure when this would occur
  $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;   $URLpath=~s/~([^\/]+)/public_html\/$1\/$1/;
  $texversion.=&path_to_problem($URLpath,$LaTeXwidth);   $texversion.=&path_to_problem($URLpath,$LaTeXwidth);
     }      }
Line 2486  ENDPART Line 2553  ENDPART
  && $currentURL=~/\.(sequence|page)$/ && $helper->{'VARS'}->{'construction'} eq '1') {   && $currentURL=~/\.(sequence|page)$/ && $helper->{'VARS'}->{'construction'} eq '1') {
             #printing content of sequence from the construction space              #printing content of sequence from the construction space
   
   # FIXME: unclear how this would work
     $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;      $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
     $result .= &print_construction_sequence($currentURL, $helper, %form,      $result .= &print_construction_sequence($currentURL, $helper, %form,
     $LaTeXwidth);      $LaTeXwidth);
Line 2840  ENDPART Line 2907  ENDPART
      } else {       } else {
  $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'});   $i=int($student_counter/$helper->{'VARS'}{'NUMBER_TO_PRINT'});
      }       }
        my $actual_seq = master_seq_to_person_seq($helper, \@master_seq, $person);
      my ($output,$fullname, $printed)=&print_resources($r,$helper,       my ($output,$fullname, $printed)=&print_resources($r,$helper,
      $person,$type,       $person,$type,
      \%moreenv,\@master_seq,       \%moreenv,  $actual_seq,
      $flag_latex_header_remove,       $flag_latex_header_remove,
      $LaTeXwidth);       $LaTeXwidth);
      $resources_printed .= ":";       $resources_printed .= ":";
Line 2868  ENDPART Line 2936  ENDPART
   
  my $code_option=$helper->{'VARS'}->{'CODE_OPTION'};   my $code_option=$helper->{'VARS'}->{'CODE_OPTION'};
          my @lines = &Apache::grades::get_scantronformat_file();           my @lines = &Apache::grades::get_scantronformat_file();
  my ($code_type,$code_length)=('letter',6);   my ($code_type,$code_length,$bubbles_per_row)=('letter',6,10);
  foreach my $line (@lines) {   foreach my $line (@lines) {
      my ($name,$type,$length) = (split(/:/,$line))[0,2,4];               chomp($line);
        my ($name,$type,$length,$bubbles_per_item) = 
                    (split(/:/,$line))[0,2,4,17];
      if ($name eq $code_option) {       if ($name eq $code_option) {
  $code_length=$length;   $code_length=$length;
  if ($type eq 'number') { $code_type = 'number'; }   if ($type eq 'number') { $code_type = 'number'; }
                    chomp($bubbles_per_item); 
                    if (($bubbles_per_item ne '') && ($bubbles_per_item > 0)) {
                        $bubbles_per_row = $bubbles_per_item; 
                    }
      }       }
  }   }
  my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));   my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
  $moreenv{'problem_split'}    = $parmhash{'problem_stream_switch'};   $moreenv{'problem_split'}    = $parmhash{'problem_stream_switch'};
          $moreenv{'instructor_comments'}='hide';           $moreenv{'instructor_comments'}='hide';
            $moreenv{'bubbles_per_row'} = $bubbles_per_row;
  my $seed=time+($$<<16)+($$);   my $seed=time+($$<<16)+($$);
  my @allcodes;   my @allcodes;
  if ($old_name) {   if ($old_name) {
Line 3195  sub print_resources { Line 3270  sub print_resources {
     my ($username,$userdomain,$usersection) = split /:/,$person;      my ($username,$userdomain,$usersection) = split /:/,$person;
     my $fullname = &get_name($username,$userdomain);      my $fullname = &get_name($username,$userdomain);
     my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace.      my $namepostfix = "\\\\"; # Both anon and not anon should get the same vspace.
   
     #      #
     # Figure out if we need to filter the output by      # Figure out if we need to filter the output by
     # the incomplete problems for that person      # the incomplete problems for that person
Line 3205  sub print_resources { Line 3281  sub print_resources {
  ($print_type eq 'incomplete_problems_selpeople_course')) {   ($print_type eq 'incomplete_problems_selpeople_course')) {
  $print_incomplete = 1;   $print_incomplete = 1;
     }      }
     if ($person =~ 'anon') {      if ($person eq 'anonymous') {
  $namepostfix .="Name: ";   $namepostfix .="Name: ";
  $fullname = "CODE - ".$moreenv->{'CODE'};   $fullname = "CODE - ".$moreenv->{'CODE'};
     }      }
Line 3354  sub print_resources { Line 3430  sub print_resources {
     # that so we're going to generate a stub that says there are no      # that so we're going to generate a stub that says there are no
     # incomplete resources for the person.      # incomplete resources for the person.
     #      #
     if ($actually_printed == 0) {  
   
       if ($actually_printed == 0) {
  $current_output  = &encapsulate_minipage("\\vskip -10mm \nNo incomplete resources\n \\vskip 100 mm { }\n");   $current_output  = &encapsulate_minipage("\\vskip -10mm \nNo incomplete resources\n \\vskip 100 mm { }\n");
  $current_output = &print_latex_header() . $current_output;   if ($remove_latex_header eq "NO") {
       $current_output = &print_latex_header() . $current_output;
    } else {
       $current_output = &latex_header_footer_remove($current_output);
    }
     }      }
   
     if ($syllabus_first) {      if ($syllabus_first) {
Line 3784  sub printHelper { Line 3863  sub printHelper {
  }   }
   
  push(@{$printChoices},   push(@{$printChoices},
      [&mt('Selected Incomplete  [_1]Problems[_2] from folder [_3]' . $textSuffix,       [&mt('Selected  [_1]Incomplete Problems[_2] from folder [_3]' . $textSuffix,
   '<b>', '</b>',    '<b>', '</b>',
   '<b><i>'. $sequenceTitle . '</b></i>'),    '<b><i>'. $sequenceTitle . '</b></i>'),
       $printSelector,        $printSelector,
Line 3831  sub printHelper { Line 3910  sub printHelper {
  # BZ 5209 - incomplete problems from entire course:   # BZ 5209 - incomplete problems from entire course:
   
  push(@{$printChoices},   push(@{$printChoices},
      [&mtn('Selected incomplete <b>Problems</b> from <b>entire course</b> for selected people'),       [&mtn('Selected <b>Incomplete Problems</b> from <b>entire course</b> for selected people'),
       'incomplete_problems_selpeople_course', 'INCOMPLETE_PROBLEMS_COURSE_RESOURCES']);        'incomplete_problems_selpeople_course', 'INCOMPLETE_PROBLEMS_COURSE_RESOURCES']);
  my $helperFragment = &create_incomplete_course_helper($helper); # Create needed states.   my $helperFragment = &create_incomplete_course_helper($helper); # Create needed states.
   
Line 3923  ALL_PROBLEMS Line 4002  ALL_PROBLEMS
   $map,    $map,
   $isProblem, '', $symbFilter,    $isProblem, '', $symbFilter,
   $start_new_option);    $start_new_option);
         my $secpdfoption;  
         unless (($helper->{'VARS'} eq 'problems_for_anon')     ||  
                 ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon_page') ||  
                 ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon')  ) {  
             $secpdfoption =  '<choice computer="sections">Each PDF contains exactly one section</choice>';  
         }  
  $resource_selector .=  &generate_format_selector($helper,   $resource_selector .=  &generate_format_selector($helper,
                                                          'How should results be printed?').                                                           'How should results be printed?',
                                                            'PRINT_FORMATTING').
                                &generate_resource_chooser('CHOOSE_STUDENTS_PAGE',                                 &generate_resource_chooser('CHOOSE_STUDENTS_PAGE',
  'Select Problem(s) to print',   'Select Problem(s) to print',
  "multichoice='1' addstatus='1' closeallpages ='1'",   "multichoice='1' addstatus='1' closeallpages ='1'",
Line 4064  ALL_PROBLEMS Line 4138  ALL_PROBLEMS
     </state>      </state>
 RESOURCE_SELECTOR  RESOURCE_SELECTOR
   
         my $nextstate = '<nextstate>NUMBER_PER_PDF</nextstate>';   
         $resource_selector .= &generate_format_selector($helper,          $resource_selector .= &generate_format_selector($helper,
                                                         'Format of the print job',                                                          'Format of the print job',
                                                         $nextstate);                                                          'PRINT_FORMATTING');
  &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS1);   &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS1);
   <state name="CHOOSE_STUDENTS1" title="Select Students and Resources">    <state name="CHOOSE_STUDENTS1" title="Select Students and Resources">
     <choices variable='student_sort'>      <choices variable='student_sort'>
Line 4108  CHOOSE_STUDENTS1 Line 4181  CHOOSE_STUDENTS1
     <message></td><td></message>      <message></td><td></message>
     <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />      <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
     <message></td></tr><tr><td></message>      <message></td></tr><tr><td></message>
     <message><b>Bubble sheet type:</b></message>      <message><b>Bubblesheet type:</b></message>
     <message></td><td></message>      <message></td><td></message>
     <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">      <dropdown variable="CODE_OPTION" multichoice="0" allowempty="0">
     $codechoice      $codechoice

Removed from v.1.592  
changed lines
  Added in v.1.601


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