Diff for /loncom/interface/lonprintout.pm between versions 1.568.2.4 and 1.568.4.4

version 1.568.2.4, 2010/04/01 23:38:26 version 1.568.4.4, 2010/12/05 19:46:04
Line 494  sub printf_style_subst { Line 494  sub printf_style_subst {
 #     %a    - Assignment name.  #     %a    - Assignment name.
 #     %c    - Course name.  #     %c    - Course name.
 #     %n    - Student name.  #     %n    - Student name.
   #     %s    - The section if it is supplied.
 #  #
 sub format_page_header {  sub format_page_header {
     my ($width, $format, $assignment, $course, $student) = @_;      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/2);   # Character/textline.      my $chars_per_line = int($width/1.6);   # Character/textline.
   
     #  Default format?      #  Default format?
   
Line 515  sub format_page_header { Line 518  sub format_page_header {
  # - Allow the assignment to be 2 lines (wrapped).   # - Allow the assignment to be 2 lines (wrapped).
  #   #
   
         my $firstline = "$student $course";  
         if (length($firstline) > $chars_per_line) {  
             my $lastchar = $chars_per_line - length($student) - 1;  
             if ($lastchar > 0) {  
                 $course = substr($course, 0, $lastchar);  
             } else {            # Nothing left of course:  
                 $course = '';  
             }  
         }  
         if (length($assignment) > $chars_per_line) {  
             $assignment = substr($assignment, 0, $chars_per_line);  
         }  
   
         $format =  "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";   my $name_length    = int($chars_per_line *3 /4);
    my $sec_length     = int($chars_per_line / 5);
   
    $format  = "%$name_length".'n';
   
    if ($section) {
       $format .=  ' - Sec: '."%$sec_length".'s';
    }
   
    $format .= '\\\\%c \\\\ %a';
           
   
     } else {  
         # An open question is how to handle long user formatted page headers...  
         # A possible future is to support e.g. %na so that the user can control  
         # the truncation of the elements that can appear in the header.  
         #  
         $format =  &printf_style_subst("a", $format, $assignment);  
         $format =  &printf_style_subst("c", $format, $course);  
         $format =  &printf_style_subst("n", $format, $student);  
   
         # If the user put %'s in the format string, they  must be escaped  
         # to \% else LaTeX will think they are comments and terminate  
         # the line.. which is bad!!!  
     }      }
       # An open question is how to handle long user formatted page headers...
       # A possible future is to support e.g. %na so that the user can control
       # the truncation of the elements that can appear in the header.
       #
       $format =  &printf_style_subst("a", $format, $assignment);
       $format =  &printf_style_subst("c", $format, $course);
       $format =  &printf_style_subst("n", $format, $student);
       $format =  &printf_style_subst("s", $format, $section);
           
       
       # If the user put %'s in the format string, they  must be escaped
       # to \% else LaTeX will think they are comments and terminate
       # the line.. which is bad!!!
       
       # If the user has role author, $course and $assignment are empty so
       # there is '\\ \\ ' in the page header. That's cause a error in LaTeX
       if($format =~ /\\\\\s\\\\\s/) {
           #TODO find sensible caption for page header
           my $testPrintout = '\\\\'.&mt('Construction Space').' \\\\'.&mt('Test-Printout ');
           $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 1240  sub get_course { Line 1265  sub get_course {
     my $courseidinfo;      my $courseidinfo;
     if (defined($env{'request.course.id'})) {      if (defined($env{'request.course.id'})) {
  $courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header');   $courseidinfo = &Apache::lonxml::latex_special_symbols(&unescape($env{'course.'.$env{'request.course.id'}.'.description'}),'header');
    my $sec = $env{'request.course.sec'};
       
     }      }
     return $courseidinfo;      return $courseidinfo;
 }  }
Line 1262  sub page_format_transformation { Line 1289  sub page_format_transformation {
   
     my $name = &get_name();      my $name = &get_name();
     my $courseidinfo = &get_course();      my $courseidinfo = &get_course();
     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }  
     my $header_text  = $parmhash{'print_header_format'};      my $header_text  = $parmhash{'print_header_format'};
     $header_text     = &format_page_header($textwidth, $header_text, $assignment,      $header_text     = &format_page_header($textwidth, $header_text, $assignment,
    $courseidinfo, $name);     $courseidinfo, $name);
Line 1283  sub page_format_transformation { Line 1309  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\}/;      $text =~ s/(\\begin{document})/$1\\special{papersize=210mm,297mm}/;
  }   }
     }      }
     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 1555  sub print_page_in_course { Line 1581  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{'pdfFormFields'} = 'no';      $form{'pdfFormFiels'} = $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 1864  sub print_construction_sequence { Line 1890  sub print_construction_sequence {
 }  }
   
 sub output_data {  sub output_data {
     my ($r,$helper,$rparmhash) = @_;      my ($r,$helper,$rparmhash,$is_custom) = @_;
     my %parmhash = %$rparmhash;      my %parmhash = %$rparmhash;
     $ssi_error = 0; # This will be set nonzero by failing ssi's.      $ssi_error = 0; # This will be set nonzero by failing ssi's.
     $resources_printed = '';      $resources_printed = '';
Line 1905  ENDPART Line 1931  ENDPART
                   {'href' => '',                    {'href' => '',
                    'text' => 'Preparing Printout'}];                     'text' => 'Preparing Printout'}];
   
       if ($is_custom) {
           $brcrum = [{'href' => '',
                      'text' => 'Preparing Printout'}];
       }
   
     my $start_page  = &Apache::loncommon::start_page('Preparing Printout',      my $start_page  = &Apache::loncommon::start_page('Preparing Printout',
                                                      $js,                                                       $js,
                                                      {'bread_crumbs' => $brcrum,});                                                       {'bread_crumbs' => $brcrum,});
Line 1946  ENDPART Line 1977  ENDPART
     my %form;      my %form;
     $form{'grade_target'} = 'tex';      $form{'grade_target'} = 'tex';
     $form{'textwidth'}    = &get_textwidth($helper, $LaTeXwidth);      $form{'textwidth'}    = &get_textwidth($helper, $LaTeXwidth);
     $form{'pdfFormFields'} = 'no';      $form{'pdfFormFields'} = $pdfFormFields;
   
     # If form.showallfoils is set, then request all foils be shown:      # If form.showallfoils is set, then request all foils be shown:
     # privilege will be enforced both by not allowing the       # privilege will be enforced both by not allowing the 
Line 1966  ENDPART Line 1997  ENDPART
  &Apache::lonnet::delenv('construct.style');   &Apache::lonnet::delenv('construct.style');
     }      }
   
   
     if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {      if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'current_document') {
       #-- single document - problem, page, html, xml, ...        #-- single document - problem, page, html, xml, ...
  my ($currentURL,$cleanURL);   my ($currentURL,$cleanURL);
Line 2256  ENDPART Line 2286  ENDPART
  if (($selectionmade == 4) and ($assignment ne $prevassignment)) {   if (($selectionmade == 4) and ($assignment ne $prevassignment)) {
     my $name = &get_name();      my $name = &get_name();
     my $courseidinfo = &get_course();      my $courseidinfo = &get_course();
     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }  
     $prevassignment=$assignment;      $prevassignment=$assignment;
     my $header_text = $parmhash{'print_header_format'};      my $header_text = $parmhash{'print_header_format'};
     $header_text    = &format_page_header($textwidth, $header_text,      $header_text    = &format_page_header($textwidth, $header_text,
Line 2879  sub print_resources { Line 2908  sub print_resources {
   
   
     my $courseidinfo = &get_course();      my $courseidinfo = &get_course();
     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }  
     if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}  
     my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');      my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
     my $header_line =      my $header_line =
  &format_page_header($LaTeXwidth, $parmhash{'print_header_format'},   &format_page_header($LaTeXwidth, $parmhash{'print_header_format'},
     $currentassignment, $courseidinfo, $fullname);      $currentassignment, $courseidinfo, $fullname, $usersection);
     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.'}';
Line 2915  sub handler { Line 2942  sub handler {
           
     &init_perm();      &init_perm();
   
       my ($helper,$is_custom);
       if ((&Apache::loncommon::needs_gci_custom()) &&
           ($env{'request.role.domain'} =~ /^\w+citest$/)) {
           if ($r->header_only) {
               if ($env{'browser.mathml'}) {
                   &Apache::loncommon::content_type($r,'text/xml');
               } else {
                   &Apache::loncommon::content_type($r,'text/html');
               }
               $r->send_http_header;
               return OK;
           }
           # Send header, nocache
           if ($env{'browser.mathml'}) {
               &Apache::loncommon::content_type($r,'text/xml');
           } else {
               &Apache::loncommon::content_type($r,'text/html');
           }
           &Apache::loncommon::no_cache($r);
           $r->send_http_header;
           $r->rflush();
   
           my ($navmap_error,$resources,@master_seq);
     my $helper = printHelper($r);          my $navmap = Apache::lonnavmaps::navmap->new();
     if (!ref($helper)) {          if (!defined($navmap)) {
  return $helper;              my $brcrum = [{'href' => '',
                              'text' => 'Preparing Printout'}];
   
               my $start_page  =
                   &Apache::loncommon::start_page('Preparing Printout','',
                                                  {'bread_crumbs' => $brcrum,});
               my $endpage = &Apache::loncommon::end_page();
   
               my $navmap_error = '<span class="LC_error">'.&mt('An error occurred retrieving information about the course.').'<br />'.&mt('It is recommended that you re-select the concept test by clicking on the "Review Questions" tab and then clicking on the "Manage Tests" tab again.').'</span>';
               $r->print($start_page.$navmap_error.$endpage);
               return OK;
           } else {
               my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
               my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
               my $sequence = &Apache::loncommon::get_citest_map($cdom);
               my @allres;
               if ($sequence) {
                   @allres=$navmap->retrieveResources('/uploaded/'.$cdom.'/'.$cnum.'/'.$sequence);
               }
               foreach my $resource (@allres) {
                   next if ($resource->is_map());
                   my $symb = $resource->symb();
                   push(@master_seq,$symb);
               }
               $resources = join('|||',@master_seq);
               my ($sequence,$middle_thingy,$urlp) =
                   &Apache::lonnet::decode_symb($master_seq[0]);
   
               my $assignment = &Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header');
   
               $helper = {
                      VARS => {
                               ANON_CODE_STORAGE_NAME => '',
                               ANSWER_TYPE => 'yes',
                               CODE_OPTION => '',
                               EMPTY_PAGES => '',
                               FINISHPAGE => '',
                               FORMAT => 'P|1|letter|no',
                               LATEX_TYPE => 'batchmode',
                               NUMBER_TO_PRINT_TOTAL => '',
                               PRINT_ANNOTATIONS => 'no',
                               PRINT_DISCUSSIONS => 'no',
                               PRINT_TYPE => 'map_problems',
                               RESOURCES => $resources,
                               REUSE_OLD_CODES => '',
                               SEQUENCE => '',
                               SINGLE_CODE => '',
                               SPLIT_PDFS => '',
                               STUDENTS => '',
                               TABLE_CONTENTS => 'no',
                               TABLE_INDEX => 'no',
                               assignment => $assignment,
                               construction => '',
                               curseed => '',
                               filename => '',
                               fontsize => 'normalsize',
                               pagesize => '',
                               'pagesize.height' => '9.8',
                               'pagesize.heightunit' => 'in',
                               'pagesize.lmargin' => '-0.57',
                               'pagesize.lmarginunit' => 'in',
                               'pagesize.width' => '7.1',
                               'pagesize.widthunit' => 'in',
                               postdata => $urlp,
                               probstatus => '',
                               showallfoils => '',
                               student_sort => '',
                               style_file => '',
                               symb => $master_seq[0],
                              }
                            };
               $env{'form.assignment'} = $assignment;
               $is_custom = 1;
           }
       } else {
           $helper = printHelper($r);
           if (!ref($helper)) {
               return $helper;
           }
     }      }
      
   
     %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});      %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
    
   
   
   
     #  If a figure conversion queue file exists for this user.domain      #  If a figure conversion queue file exists for this user.domain
Line 2934  sub handler { Line 3057  sub handler {
   
     my $conversion_queuefile = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";      my $conversion_queuefile = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
     if(-e $conversion_queuefile) {      if(-e $conversion_queuefile) {
  unlink $conversion_queuefile;          unlink $conversion_queuefile;
     }      }
       
   
     &output_data($r,$helper,\%parmhash);  
       &output_data($r,$helper,\%parmhash,$is_custom);
     return OK;      return OK;
 }   }
   
 use Apache::lonhelper;  use Apache::lonhelper;
   
Line 4007  sub render { Line 4130  sub render {
     my $PaperType=&mt('Paper type');      my $PaperType=&mt('Paper type');
     my $landscape=&mt('Landscape');      my $landscape=&mt('Landscape');
     my $portrait=&mt('Portrait');      my $portrait=&mt('Portrait');
       my $pdfFormLabel=&mt('PDF-Formfields');
       my $with=&mt('with Formfields');
       my $without=&mt('without Formfields');
           
   
     $result.='<h3>'.&mt('Layout Options').'</h3>'      $result.='<h3>'.&mt('Layout Options').'</h3>'
Line 4015  sub render { Line 4141  sub render {
             .'<th>'.$PageLayout.'</th>'              .'<th>'.$PageLayout.'</th>'
             .'<th>'.$NumberOfColumns.'</th>'              .'<th>'.$NumberOfColumns.'</th>'
             .'<th>'.$PaperType.'</th>'              .'<th>'.$PaperType.'</th>'
               .'<th>'.$pdfFormLabel.'</th>'
             .&Apache::loncommon::end_data_table_header_row()              .&Apache::loncommon::end_data_table_header_row()
             .&Apache::loncommon::start_data_table_row()              .&Apache::loncommon::start_data_table_row()
     .'<td>'      .'<td>'
Line 4054  sub render { Line 4181  sub render {
     }      }
     $result .= <<HTML;      $result .= <<HTML;
         </select>          </select>
         <hidden name="${var}.pdfFormFields" value="no" />      </td>
       <td align='center'>
           <select name='${var}.pdfFormFields'>
               <option selected="selected" value="no">$without</option>
               <option value="yes">$with</option>
           </select>
     </td>      </td>
 HTML  HTML
     $result.=&Apache::loncommon::end_data_table_row()      $result.=&Apache::loncommon::end_data_table_row()

Removed from v.1.568.2.4  
changed lines
  Added in v.1.568.4.4


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