Diff for /loncom/interface/lonprintout.pm between versions 1.448 and 1.467

version 1.448, 2006/06/30 01:06:22 version 1.467, 2006/07/24 22:13:58
Line 46  use lib '/home/httpd/lib/perl/'; Line 46  use lib '/home/httpd/lib/perl/';
 use LONCAPA;  use LONCAPA;
   
 my %perm;  my %perm;
   my %parmhash;
   my $resources_printed;
   
   
   # Format a header according to a format.  
   # 
   
   # Substitutions:
   #     %a    - Assignment name.
   #     %c    - Course name.
   #     %n    - Student name.
   #
   sub format_page_header {
       my ($format, $assignment, $course, $student) = @_;
       
       #  Default format?
   
       if ($format eq '') {
    $format =  "\\textbf{$student} $course \\hfill \\thepage \\\\ \\textit{$assignment}";
   
       } else {
    $format =~ s/%a/$assignment/g;
    $format =~ s/%c/$course/g;
    $format =~ s/%n/$student/g;
       }
       
   
       return $format;
       
   }
   
 #  #
 #   Convert a numeric code to letters  #   Convert a numeric code to letters
Line 597  my %page_formats= Line 627  my %page_formats=
      '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm']       '2' => ['3.66 in','9.8 in', '-0.57 in','-0.57 in','0.7 cm']
  },   },
  'album' => {   'album' => {
      '1' => [ '8.8 in', '6.8 in','-40 pt in',  '-60 pt','1 cm'],       '1' => [ '8.8 in', '6.8 in','-0.55 in',  '-0.83 in','1 cm'],
      '2' => [ '4.4 in', '6.8 in','-0.5 in', '-1.5 in','3.5 in']       '2' => [ '4.4 in', '6.8 in','-0.5 in', '-1.5 in','3.5 in']
  },   },
      },       },
Line 653  my %page_formats= Line 683  my %page_formats=
      },       },
      'a4' => {       'a4' => {
  'book' => {   'book' => {
      '1' => ['176 mm','272 mm','-40 pt in','-60 pt','-0.5 in'],       '1' => ['17.6 cm','27.2 cm','-0.55  in','-0.83 in','-0.5 in'],
      '2' => [ '91 mm','272 mm','-40 pt in','-60 pt','-0.5 in']       '2' => [ '9.1 cm','27.2 cm','-0.55  in','-0.83 in','-0.5 in']
  },   },
  'album' => {   'album' => {
      '1' => ['8.5 in','7.7 in','-40 pt in','-60 pt','0 in'],       '1' => ['8.5 in','7.7 in','-0.55 in','-0.83 in','0 in'],
      '2' => ['3.9 in','7.7 in','-40 pt in','-60 pt','0 in']       '2' => ['3.9 in','7.7 in','-0.55 in','-0.83 in','0 in']
  },   },
      },       },
      'a5' => {       'a5' => {
Line 702  sub get_name { Line 732  sub get_name {
     if (!defined($udom)) { $udom=$env{'user.domain'}; }      if (!defined($udom)) { $udom=$env{'user.domain'}; }
     my $plainname=&Apache::loncommon::plainname($uname,$udom);      my $plainname=&Apache::loncommon::plainname($uname,$udom);
     if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; }      if ($plainname=~/^\s*$/) { $plainname=$uname.'@'.$udom; }
    #  $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header');     $plainname=&Apache::lonxml::latex_special_symbols($plainname,'header');
     $plainname = &escape_LaTeX($plainname);  
     return $plainname;      return $plainname;
 }  }
   
Line 718  sub get_course { Line 747  sub get_course {
 sub page_format_transformation {  sub page_format_transformation {
     my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_;       my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist,$selectionmade) = @_; 
     my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);      my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);
   
     if ($selectionmade eq '4') {      if ($selectionmade eq '4') {
  $assignment='Problems from the Whole Course';   $assignment='Problems from the Whole Course';
     } else {      } else {
  $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');   $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');
     }      }
     ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);      ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);
   
   
     my $name = &get_name();      my $name = &get_name();
     my $courseidinfo = &get_course();      my $courseidinfo = &get_course();
     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }      if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
       my $header_text  = $parmhash{'print_header_format'};
       $header_text     = &format_page_header($header_text, $assignment,
      $courseidinfo, $name);
     my $topmargintoinsert = '';      my $topmargintoinsert = '';
     if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';}      if ($topmargin ne '0') {$topmargintoinsert='\setlength{\topmargin}{'.$topmargin.'}';}
     my $fancypagestatement='';      my $fancypagestatement='';
     if ($numberofcolumns eq '2') {      if ($numberofcolumns eq '2') {
  $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}";   $fancypagestatement="\\fancyhead{}\\fancyhead[LO]{$header_text}";
     } else {      } else {
  $fancypagestatement="\\rhead{}\\chead{}\\lhead{\\textbf{$name} $courseidinfo \\hfill \\thepage \\\\ \\textit{$assignment}}";   $fancypagestatement="\\rhead{}\\chead{}\\lhead{$header_text}";
     }      }
     if ($layout eq 'album') {      if ($layout eq 'album') {
     $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\n\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\n\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\n\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /;      $text =~ s/\\begin{document}/\\setlength{\\oddsidemargin}{$oddoffset}\\setlength{\\evensidemargin}{$evenoffset}$topmargintoinsert\n\\setlength{\\textwidth}{$textwidth}\\setlength{\\textheight}{$textheight}\\setlength{\\textfloatsep}{8pt plus 2\.0pt minus 4\.0pt}\n\\newlength{\\minipagewidth}\\setlength{\\minipagewidth}{\\textwidth\/\$number_of_columns-0\.2cm}\\usepackage{fancyhdr}\\addtolength{\\headheight}{\\baselineskip}\n\\pagestyle{fancy}$fancypagestatement\\begin{document}\\voffset=-0\.8 cm\\setcounter{page}{1}\n /;
Line 1021  sub get_page_breaks  { Line 1056  sub get_page_breaks  {
     return %page_breaks;      return %page_breaks;
 }  }
   
   #  Output a sequence (recursively if neeed)
   #  from construction space.
   # Parameters:
   #    url     = URL of the sequence to print.
   #    helper  - Reference to the helper hash.
   #    form    - Copy of the format hash.
   #    LaTeXWidth
   # Returns:
   #   Text to add to the printout.
   #   NOTE if the first element of the outermost sequence
   #   is itself a sequence, the outermost caller may need to
   #   prefix the latex with the page headers stuff.
   #
   sub print_construction_sequence {
       my ($currentURL, $helper, %form, $LaTeXwidth) = @_;
       my $result;
       my $rndseed=time;
       if ($helper->{'VARS'}->{'curseed'}) {
    $rndseed=$helper->{'VARS'}->{'curseed'};
       }
       my $errtext=&Apache::lonratedt::mapread($currentURL);
       # 
       #  These make this all support recursing for subsequences.
       #
       my @order    = @Apache::lonratedt::order;
       my @resources = @Apache::lonratedt::resources; 
       for (my $member=0;$member<=$#order;$member++) {
    $resources[$order[$member]]=~/^([^:]*):([^:]*):/;
    my $urlp=$2;
    if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
       my $texversion='';
       if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {
    $form{'problem_split'}=$parmhash{'problem_stream_switch'};
    $form{'suppress_tries'}=$parmhash{'suppress_tries'};
    $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
    $form{'rndseed'}=$rndseed;
    $resources_printed .=$urlp.':';
    $texversion=&Apache::lonnet::ssi($urlp,%form);
       }
       if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||
    ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) && 
          ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) {
    #  Don't permanently modify %$form...
    my %answerform = %form;
    $answerform{'grade_target'}='answer';
    $answerform{'answer_output_mode'}='tex';
    $answerform{'rndseed'}=$rndseed;
    $answerform{'problem_split'}=$parmhash{'problem_stream_switch'};
    if ($urlp=~/\/res\//) {$env{'request.state'}='published';}
    $resources_printed .= $urlp.':';
    my $answer=&Apache::lonnet::ssi($urlp,%answerform);
    if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
       $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
    } else {
       # If necessary, encapsulate answer in minipage:
       
       $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
       my $body ='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}).'}\vskip 0 mm ';
       $body.=&path_to_problem($urlp,$LaTeXwidth);
       $body.='\vskip 1 mm '.$answer.'\end{document}';
       $body = &encapsulate_minipage($body);
       $texversion.=$body;
    }
       }
       $texversion = &latex_header_footer_remove($texversion);
   
       if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
    $texversion=&IndexCreation($texversion,$urlp);
       }
       if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URL'} eq 'yes') {
    $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;
       }
       $result.=$texversion;
   
    } elsif ($urlp=~/\.(sequence|page)$/) {
       
       # header:
   
       $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent ';
   
       # IF sequence, recurse:
       
       if ($urlp =~ /\.sequence$/) {
    my $sequence_url = $urlp;
    my $domain       = $env{'user.domain'}; # Constr. space only on local
    my $user         = $env{'user.name'};
   
    $sequence_url    =~ s/^\/res\/$domain/\/home/;
    $sequence_url    =~ s/^(\/home\/$user)/$1\/public_html/;
   # $sequence_url    =~ s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
    $result .= &print_construction_sequence($sequence_url, 
    $helper, %form, 
    $LaTeXwidth);
       }
    }  
       }
       if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;}
       return $result;
   }
   
 sub output_data {  sub output_data {
     my ($r,$helper,$rparmhash) = @_;      my ($r,$helper,$rparmhash) = @_;
     my %parmhash = %$rparmhash;      my %parmhash = %$rparmhash;
     my $resources_printed = '';      $resources_printed = '';
     my $js = <<ENDPART;      my $js = <<ENDPART;
 <script type="text/javascript">  <script type="text/javascript">
     var editbrowser;      var editbrowser;
Line 1198  ENDPART Line 1333  ENDPART
         } elsif ($cleanURL!~m|^/adm/|          } elsif ($cleanURL!~m|^/adm/|
  && $currentURL=~/\.sequence$/ && $helper->{'VARS'}->{'construction'} eq '1') {   && $currentURL=~/\.sequence$/ && $helper->{'VARS'}->{'construction'} eq '1') {
             #printing content of sequence from the construction space              #printing content of sequence from the construction space
     my $flag_latex_header_remove = 'NO';   
     my $rndseed=time;  
     if ($helper->{'VARS'}->{'curseed'}) {  
  $rndseed=$helper->{'VARS'}->{'curseed'};  
     }  
     $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;      $currentURL=~s|\/~([^\/]+)\/|\/home\/$1\/public_html\/|;
     my $errtext=&Apache::lonratedt::mapread($currentURL);      $result .= &print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});
     for (my $member=0;$member<=$#Apache::lonratedt::order;$member++) {      $result .= &print_construction_sequence($currentURL, $helper, %form,
  $Apache::lonratedt::resources[$Apache::lonratedt::order[$member]]=~/^([^:]*):([^:]*):/;      $LaTeXwidth);
  my $urlp=$2;      $result .= '\end{document}';  
  if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {      if (!($result =~ /\\begin\{document\}/)) {
     my $texversion='';   $result = &print_latex_header() . $result;
     if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') {  
  $form{'problem_split'}=$parmhash{'problem_stream_switch'};  
  $form{'suppress_tries'}=$parmhash{'suppress_tries'};  
  $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};  
  $form{'rndseed'}=$rndseed;  
  $resources_printed .=$urlp.':';  
  $texversion=&Apache::lonnet::ssi($urlp,%form);  
     }  
     if((($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') ||  
        ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'only')) &&   
        ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|page)$/)) {  
  #  Don't permanently modify %$form...  
  my %answerform = %form;  
  $answerform{'grade_target'}='answer';  
  $answerform{'answer_output_mode'}='tex';  
  $answerform{'rndseed'}=$rndseed;  
  $answerform{'problem_split'}=$parmhash{'problem_stream_switch'};  
                         if ($urlp=~/\/res\//) {$env{'request.state'}='published';}  
  $resources_printed .= $urlp.':';  
  my $answer=&Apache::lonnet::ssi($urlp,%answerform);  
  if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {  
     $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;  
  } else {  
     # If necessary, encapsulate answer in minipage:  
   
     $texversion=&print_latex_header($helper->{'VARS'}->{'LATEX_TYPE'});  
     my $body ='\vskip 0 mm \noindent\textbf{'.&Apache::lonnet::gettitle($helper->{'VARS'}->{'symb'}).'}\vskip 0 mm ';  
     $body.=&path_to_problem($urlp,$LaTeXwidth);  
     $body.='\vskip 1 mm '.$answer.'\end{document}';  
     $body = &encapsulate_minipage($body);  
     $texversion.=$body;  
  }  
     }  
     if ($flag_latex_header_remove ne 'NO') {  
  $texversion = &latex_header_footer_remove($texversion);  
     } else {  
  $texversion =~ s/\\end{document}//;  
     }  
     if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {  
  $texversion=&IndexCreation($texversion,$urlp);  
     }  
     if ($helper->{'VARS'}->{'CONSTR_RESOURSE_URpL'} eq 'yes') {  
  $texversion=~s/(\\addcontentsline\{toc\}\{subsection\}\{[^\}]*\})/$1 URL: \\verb|$urlp| \\strut\\\\\\strut /;  
     }  
     $result.=$texversion;  
     $flag_latex_header_remove = 'YES';  
  } elsif ($urlp=~/\.(sequence|page)$/) {  
     $result.='\strut\newline\noindent Sequence/page '.$urlp.'\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent ';  
  }    
     }      }
     if ($helper->{VARS}->{'construction'} eq '1') {$result=~s/(\\begin{document})/$1 \\fbox\{RANDOM SEED IS $rndseed\} /;}      # End construction space sequence.
     $result .= '\end{document}';     
  } elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) {    } elsif ($cleanURL=~/\/(smppg|syllabus|aboutme|bulletinboard)$/) { 
  $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//;}
Line 1372  ENDPART Line 1452  ENDPART
     my $courseidinfo = &get_course();      my $courseidinfo = &get_course();
     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }      if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
     $prevassignment=$assignment;      $prevassignment=$assignment;
       my $header_text = $parmhash{'print_header_format'};
       $header_text    = &format_page_header($header_text,
     $assignment, 
     $courseidinfo, 
     $name);
     if ($numberofcolumns eq '1') {      if ($numberofcolumns eq '1') {
  $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm ';   $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$header_text.'}} \vskip 5 mm ';
     } else {      } else {
  $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{\\textit{\\textbf{'.$name.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$assignment.'}}} \vskip 5 mm ';   $result .='\newpage \noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$header_text.'}} \vskip 5 mm ';
     }      }
  }   }
  $result .= $texversion;   $result .= $texversion;
Line 1562  ENDPART Line 1647  ENDPART
  }   }
  my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};   my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
  my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'});   my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'});
    &adjust_number_to_print($helper);
  my $number_per_page=$helper->{'VARS'}->{'NUMBER_TO_PRINT'};   my $number_per_page=$helper->{'VARS'}->{'NUMBER_TO_PRINT'};
  if ($number_per_page eq '0' || $number_per_page eq 'all') {   if ($number_per_page eq '0' || $number_per_page eq 'all') {
      $number_per_page=$num_todo;       $number_per_page=$num_todo;
Line 1673  ENDPART Line 1759  ENDPART
        $selectionmade,          $selectionmade, 
        $helper->{'VARS'}->{'ANSWER_TYPE'});         $helper->{'VARS'}->{'ANSWER_TYPE'});
     }      }
       #if ($numberofcolumns == 1) {
     $result =~ s/\\textwidth\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;   $result =~ s/\\textwidth\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textwidth= $helper->{'VARS'}->{'pagesize.width'} $helper->{'VARS'}->{'pagesize.widthunit'} /;
     $result =~ s/\\textheight\s*=?\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;   $result =~ s/\\textheight\s*=?\s*-?\d*\.?\d*\s*(cm|mm|in)/\\textheight $helper->{'VARS'}->{'pagesize.height'} $helper->{'VARS'}->{'pagesize.heightunit'} /;
     $result =~ s/\\evensidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;   $result =~ s/\\evensidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\evensidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
     $result =~ s/\\oddsidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;   $result =~ s/\\oddsidemargin\s*=\s*-?\d*\.?\d*\s*(cm|mm|in)/\\oddsidemargin= $helper->{'VARS'}->{'pagesize.lmargin'} $helper->{'VARS'}->{'pagesize.lmarginunit'} /;
       #}
   
 #-- writing .tex file in prtspool   #-- writing .tex file in prtspool 
     my $temp_file;      my $temp_file;
Line 1903  sub print_resources { Line 1989  sub print_resources {
     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }      if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
     if ($usersection ne '') {$courseidinfo.=' - Sec. '.$usersection}      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 $HeaderLine = $parmhash{'print_header_format'};
       $HeaderLine = format_page_header($HeaderLine, $currentassignment, $courseidinfo, $fullname);
     if ($current_output=~/\\documentclass/) {      if ($current_output=~/\\documentclass/) {
  if ($columns_in_format == 1) {   if ($columns_in_format == 1) {
     $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /;      $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\lhead{$HeaderLine$namepostfix}}\\vskip 5 mm /;
  } else {   } else {
         $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fancyhead[LO]{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}$namepostfix}}\\vskip 5 mm /;          $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\parbox{\\minipagewidth}{\\noindent\\fancyhead[LO]{$HeaderLine$namepostfix}}\\vskip 5 mm /;
   
  }   }
     } else {      } else {
  my $blankpages = '';   my $blankpages = '';
  for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blankpages.='\clearpage\strut\clearpage';}   for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blankpages.='\clearpage\strut\clearpage';}
  if ($columns_in_format == 1) {   if ($columns_in_format == 1) {
     $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output;      $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{'.$HeaderLine.'}'.$namepostfix.'} \vskip 5 mm '.$current_output;
  } else {   } else {
    $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}'.$namepostfix.'}} \vskip 5 mm '.$current_output;     $current_output = '\strut\vspace*{-6 mm}\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\vspace*{-2 mm}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blankpages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\fancyhead[LO]{'.$HeaderLine.'}'.$namepostfix.'} \vskip 5 mm '.$current_output;
  }   }
     }      }
     #      #
Line 1941  sub handler { Line 2029  sub handler {
     }      }
         
   
     my %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});      %parmhash=&Apache::lonnet::coursedescription($env{'request.course.id'});
     
   
   
Line 1976  sub init_perm { Line 2064  sub init_perm {
  $perm{'pav'}=&Apache::lonnet::allowed('pav',   $perm{'pav'}=&Apache::lonnet::allowed('pav',
   $env{'request.course.id'}.'/'.$env{'request.course.sec'});    $env{'request.course.id'}.'/'.$env{'request.course.sec'});
     }      }
     $perm{'pfo'}=&Apache::lonnet::allowed('pav',$env{'request.course.id'});      $perm{'pfo'}=&Apache::lonnet::allowed('pfo',$env{'request.course.id'});
     if (!$perm{'pfo'}) {      if (!$perm{'pfo'}) {
  $perm{'pfo'}=&Apache::lonnet::allowed('pfo',   $perm{'pfo'}=&Apache::lonnet::allowed('pfo',
   $env{'request.course.id'}.'/'.$env{'request.course.sec'});    $env{'request.course.id'}.'/'.$env{'request.course.sec'});
Line 2138  sub printHelper { Line 2226  sub printHelper {
     my $paramHash;      my $paramHash;
   
     if ($resourceTitle) {      if ($resourceTitle) {
         push @{$printChoices}, ["<b><i>$resourceTitle</i></b> (".&mt('what you just saw on the screen').")", 'current_document', 'PAGESIZE'];          push @{$printChoices}, ["<b><i>$resourceTitle</i></b> (".&mt('the resource you just saw on the screen').")", 'current_document', 'PAGESIZE'];
     }      }
   
     # Useful filter strings      # Useful filter strings
Line 2153  sub printHelper { Line 2241  sub printHelper {
   
     $helper->declareVar('SEQUENCE');      $helper->declareVar('SEQUENCE');
   
       # If we're in a sequence...
   
       my $start_new_option;
       if ($perm{'pav'}) {
    $start_new_option = 
       "<option text='".&mt('Start new page<br />before selected').
       "' variable='FINISHPAGE' />";
       }
   
     # If we're in a sequence...  
     if (($helper->{'VARS'}->{'construction'} ne '1') &&      if (($helper->{'VARS'}->{'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}, ["<b>".&mt('Problems')."</b> ".&mt('in')." <b><i>$sequenceTitle</i></b>", 'map_problems', 'CHOOSE_PROBLEMS'];          push @{$printChoices}, [&mt('Selected <b>Problems</b> in folder <b><i>[_1]</i></b>',$sequenceTitle), 'map_problems', 'CHOOSE_PROBLEMS'];
         # Allow all resources from sequence          # Allow all resources from sequence
         push @{$printChoices}, ["<b>".&mt('Resources')."</b> ".&mt('in')." <b><i>$sequenceTitle</i></b>", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];          push @{$printChoices}, [&mt('Selected <b>Resources</b> in folder <b><i>[_1]</i></b>',$sequenceTitle), 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
   
         my $helperFragment = <<HELPERFRAGMENT;          my $helperFragment = <<HELPERFRAGMENT;
   <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">    <state name="CHOOSE_PROBLEMS" title="Select Problem(s) to print">
     <message>(mark them then click "next" button) <br /></message>  
     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"      <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
               closeallpages="1">                closeallpages="1">
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblem;</filterfunc>        <filterfunc>return $isProblem;</filterfunc>
       <mapurl>$map</mapurl>        <mapurl>$map</mapurl>
       <valuefunc>return $symbFilter;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       <option text='Newpage' variable='FINISHPAGE' />        $start_new_option
       </resource>        </resource>
     </state>      </state>
   
   <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">    <state name="CHOOSE_PROBLEMS_HTML" title="Select Resource(s) to print">
     <message>(mark them then click "next" button) <br /></message>  
     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"      <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
               closeallpages="1">                closeallpages="1">
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isNotMap;</filterfunc>        <filterfunc>return $isNotMap;</filterfunc>
       <mapurl>$map</mapurl>        <mapurl>$map</mapurl>
       <valuefunc>return $symbFilter;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       <option text='Newpage' variable='FINISHPAGE' />        $start_new_option
       </resource>        </resource>
     </state>      </state>
 HELPERFRAGMENT  HELPERFRAGMENT
Line 2199  HELPERFRAGMENT Line 2291  HELPERFRAGMENT
     if ($perm{'pfo'} &&       if ($perm{'pfo'} && 
         ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) {           ($helper->{VARS}->{'postdata'}=~/\/res\// || $helper->{VARS}->{'postdata'}=~/\/(syllabus|smppg|aboutme|bulletinboard)$/)) { 
   
         push @{$printChoices}, ['<b>Problems</b> from <b>entire course</b>', 'all_problems', 'ALL_PROBLEMS'];          push @{$printChoices}, ['Selected <b>Problems</b> from <b>entire course</b>', 'all_problems', 'ALL_PROBLEMS'];
  push @{$printChoices}, ['<b>Resources</b> from <b>entire course</b>', 'all_resources', 'ALL_RESOURCES'];   push @{$printChoices}, ['Selected <b>Resources</b> from <b>entire course</b>', 'all_resources', 'ALL_RESOURCES'];
          &Apache::lonxml::xmlparse($r, 'helper', <<ALL_PROBLEMS);           &Apache::lonxml::xmlparse($r, 'helper', <<ALL_PROBLEMS);
   <state name="ALL_PROBLEMS" title="Select Problem(s) to print">    <state name="ALL_PROBLEMS" title="Select Problem(s) to print">
     <message>(mark them then click "next" button) <br /></message>  
     <resource variable="RESOURCES" toponly='0' multichoice="1"      <resource variable="RESOURCES" toponly='0' multichoice="1"
  suppressEmptySequences='0' addstatus="1" closeallpages="1">   suppressEmptySequences='0' addstatus="1" closeallpages="1">
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblemOrMap;</filterfunc>        <filterfunc>return $isProblemOrMap;</filterfunc>
       <choicefunc>return $isNotMap;</choicefunc>        <choicefunc>return $isNotMap;</choicefunc>
       <valuefunc>return $symbFilter;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       <option text='Newpage' variable='FINISHPAGE' />        $start_new_option
     </resource>      </resource>
   </state>    </state>
   <state name="ALL_RESOURCES" title="Select Resource(s) to print">    <state name="ALL_RESOURCES" title="Select Resource(s) to print">
     <message>(Mark them then click "next" button) <br /> </message>  
     <resource variable="RESOURCES" toponly='0' multichoice='1'      <resource variable="RESOURCES" toponly='0' multichoice='1'
               suppressEmptySequences='0' addstatus='1' closeallpages='1'>                suppressEmptySequences='0' addstatus='1' closeallpages='1'>
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isNotMap; </filterfunc>        <filterfunc>return $isNotMap; </filterfunc>
       <valuefunc>return $symbFilter;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       <option text='NewPage' variable='FINISHPAGE' />        $start_new_option
     </resource>      </resource>
   </state>    </state>
 ALL_PROBLEMS  ALL_PROBLEMS
   
  if ($helper->{VARS}->{'assignment'}) {   if ($helper->{VARS}->{'assignment'}) {
     push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('from')." <b><i>$sequenceTitle</i></b> ".&mt('for')." <b>".&mt('selected students')."</b>", 'problems_for_students', 'CHOOSE_STUDENTS'];      push @{$printChoices}, [&mt("Selected <b>Problems</b> from folder <b><i>[_1]</i></b> for <b>selected students</b>",$sequenceTitle), 'problems_for_students', 'CHOOSE_STUDENTS'];
     push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('from')." <b><i>$sequenceTitle</i></b> ".&mt('for')." <b>".&mt('anonymous students')."</b>", 'problems_for_anon', 'CHOOSE_ANON1'];      push @{$printChoices}, [&mt("Selected <b>Problems</b> from folder <b><i>[_1]</i></b> for <b>anonymous students</b>",$sequenceTitle), 'problems_for_anon', 'CHOOSE_ANON1'];
  }   }
   
  # resource_selector will hold a few states that:   # resource_selector will hold a few states that:
Line 2248  ALL_PROBLEMS Line 2338  ALL_PROBLEMS
       <filterfunc>return $isProblem;</filterfunc>        <filterfunc>return $isProblem;</filterfunc>
       <mapurl>$map</mapurl>        <mapurl>$map</mapurl>
       <valuefunc>return $symbFilter;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       <option text='New Page' variable='FINISHPAGE' />        $start_new_option
       </resource>        </resource>
     </state>      </state>
     <state name="PRINT_FORMATTING" title="How should results be printed?">      <state name="PRINT_FORMATTING" title="How should results be printed?">
Line 2265  ALL_PROBLEMS Line 2355  ALL_PROBLEMS
        <choice computer="all">All assignments in a single PDF file</choice>         <choice computer="all">All assignments in a single PDF file</choice>
        <choice computer="sections">Each PDF contains exactly one section</choice>         <choice computer="sections">Each PDF contains exactly one section</choice>
        <choice computer="oneper">Each PDF contains exactly one assignment</choice>         <choice computer="oneper">Each PDF contains exactly one assignment</choice>
        <choice computer="usenumber" relatedvalue="NUMBER_TO_PRINT" relateddefault="all">         <choice computer="usenumber" relatedvalue="NUMBER_TO_PRINT">
             Specify Number:</choice>              Specify the number of assignments per PDF:</choice>
     </choices>      </choices>
     </state>      </state>
 RESOURCE_SELECTOR  RESOURCE_SELECTOR
Line 2304  CHOOSE_STUDENTS Line 2394  CHOOSE_STUDENTS
     }      }
  }   }
   
  my $code_selection = "<choice></choice>\n";   my $code_selection;
  foreach my $code (sort {uc($a) cmp uc($b)} (keys(%codes_to_print))) {   foreach my $code (sort {uc($a) cmp uc($b)} (keys(%codes_to_print))) {
     my $choice  = $code;      my $choice  = $code;
     if ($code =~ /^[A-Z]+$/) { # Alpha code      if ($code =~ /^[A-Z]+$/) { # Alpha code
Line 2316  CHOOSE_STUDENTS Line 2406  CHOOSE_STUDENTS
     $code_selection .='         $code_selection .='   
     <message><b>Choose single code from list</b></message>      <message><b>Choose single code from list</b></message>
  <message></td><td></message>   <message></td><td></message>
  <choices variable="CODE_SELECTED_FROM_LIST" multichoice="0" allowempty="0">   <dropdown variable="CODE_SELECTED_FROM_LIST" multichoice="0" allowempty="0">
                     <choice></choice>
                   <exec>                    <exec>
                      push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}});                       push(@{$state->{CHOICES}},@{$helper->{DATA}{ALL_CODE_CHOICES}});
                   </exec>                    </exec>
  </choices>   </dropdown>
     <message></td></tr><tr><td colspan="2"><hr width=\'33%\' /></td></tr><tr><td></message>      <message></td></tr><tr><td colspan="2"><hr width=\'33%\' /></td></tr><tr><td></message>
             '.$/;              '.$/;
   
Line 2397  CHOOSE_ANON1 Line 2488  CHOOSE_ANON1
   
   
  if ($helper->{VARS}->{'assignment'}) {   if ($helper->{VARS}->{'assignment'}) {
     push @{$printChoices}, ["<b>".&mt('Resources')."</b> ".&mt('from')." <b><i>$sequenceTitle</i></b> ".&mt('for')." <b>".&mt('selected students')."</b>", 'resources_for_students', 'CHOOSE_STUDENTS1'];      push @{$printChoices}, [&mt("Selected <b>Resources</b> from folder <b><i>[_1]</i></b> for <b>selected students</b>",$sequenceTitle), 'resources_for_students', 'CHOOSE_STUDENTS1'];
     push @{$printChoices}, ["<b>".&mt('Resources')."</b> ".&mt('from')." <b><i>$sequenceTitle</i></b> ".&mt('for')." <b>".&mt('anonymous students')."</b>", 'resources_for_anon', 'CHOOSE_ANON2'];      push @{$printChoices}, [&mt("Selected <b>Resources</b> from folder <b><i>[_1]</i></b> for <b>anonymous students</b>",$sequenceTitle), 'resources_for_anon', 'CHOOSE_ANON2'];
  }   }
           
   
Line 2411  CHOOSE_ANON1 Line 2502  CHOOSE_ANON1
       <filterfunc>return $isNotMap;</filterfunc>        <filterfunc>return $isNotMap;</filterfunc>
       <mapurl>$map</mapurl>        <mapurl>$map</mapurl>
       <valuefunc>return $symbFilter;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       <option text='Newpage' variable='FINISHPAGE' />        $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">
Line 2429  CHOOSE_ANON1 Line 2520  CHOOSE_ANON1
        <choice computer="all">All assignments in a single PDF file</choice>         <choice computer="all">All assignments in a single PDF file</choice>
        <choice computer="sections">Each PDF contains exactly one section</choice>         <choice computer="sections">Each PDF contains exactly one section</choice>
        <choice computer="oneper">Each PDF contains exactly one assignment</choice>         <choice computer="oneper">Each PDF contains exactly one assignment</choice>
        <choice computer="usenumber" relatedvalue="NUMBER_TO_PRINT" relateddefault="all">         <choice computer="usenumber" relatedvalue="NUMBER_TO_PRINT">
            Specify Number:</choice>             Specify the number of assignments per PDF:</choice>
     </choices>      </choices>
     </state>      </state>
 RESOURCE_SELECTOR  RESOURCE_SELECTOR
Line 2504  CHOOSE_ANON2 Line 2595  CHOOSE_ANON2
   
     # FIXME: That RE should come from a library somewhere.      # FIXME: That RE should come from a library somewhere.
     if ((((&Apache::lonnet::allowed('bre',$subdir) eq 'F') and ($helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) or defined $helper->{'VARS'}->{'construction'}) and $perm{'pav'} and $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/') {          if ((((&Apache::lonnet::allowed('bre',$subdir) eq 'F') and ($helper->{VARS}->{'postdata'}=~/\.(problem|exam|quiz|assess|survey|form|library|page|xml|html|htm|xhtml|xhtm)/)) or defined $helper->{'VARS'}->{'construction'}) and $perm{'pav'} and $subdir ne $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/') {    
         push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('from current subdirectory')." <b><i>$subdir</i></b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];          push @{$printChoices}, [&mt("Selected <b>Problems</b> from current subdirectory <b><i>[_1]</i></b>",$subdir), 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
   
         my $f = '$filename';          my $f = '$filename';
         my $xmlfrag = <<CHOOSE_FROM_SUBDIR;          my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
   <state name="CHOOSE_FROM_SUBDIR" title="Select File(s) from <b><small>$subdir</small></b> to print">    <state name="CHOOSE_FROM_SUBDIR" title="Select File(s) from <b><small>$subdir</small></b> to print">
     <message>(mark them then click "next" button) <br /></message>  
     <files variable="FILES" multichoice='1'>      <files variable="FILES" multichoice='1'>
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filechoice>return '$subdir';</filechoice>        <filechoice>return '$subdir';</filechoice>
Line 2530  CHOOSE_FROM_SUBDIR Line 2621  CHOOSE_FROM_SUBDIR
     # Allow the user to select any sequence in the course, feed it to      # Allow the user to select any sequence in the course, feed it to
     # another resource selector for that sequence      # another resource selector for that sequence
     if (!$helper->{VARS}->{'construction'}) {      if (!$helper->{VARS}->{'construction'}) {
  push @$printChoices, ["<b>Resources</b> from <b>selected sequence</b> in course",   push @$printChoices, ["Selected <b>Resources</b> from <b>selected folder</b> in course",
       'select_sequences', 'CHOOSE_SEQUENCE'];        'select_sequences', 'CHOOSE_SEQUENCE'];
  my $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'};   my $escapedSequenceName = $helper->{VARS}->{'SEQUENCE'};
  #Escape apostrophes and backslashes for Perl   #Escape apostrophes and backslashes for Perl
Line 2552  CHOOSE_FROM_SUBDIR Line 2643  CHOOSE_FROM_SUBDIR
     <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"      <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1"
               closeallpages="1">                closeallpages="1">
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblem</filterfunc>        <filterfunc>return $isNotMap</filterfunc>
       <mapurl evaluate='1'>return '$escapedSequenceName';</mapurl>        <mapurl evaluate='1'>return '$escapedSequenceName';</mapurl>
       <valuefunc>return $symbFilter;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       <option text='Newpage' variable='FINISHPAGE' />        $start_new_option
       </resource>        </resource>
     </state>      </state>
 CHOOSE_FROM_ANY_SEQUENCE  CHOOSE_FROM_ANY_SEQUENCE
Line 2881  sub new { Line 2972  sub new {
     # $helper->{VARS} to figure out whether the columns are one or two      # $helper->{VARS} to figure out whether the columns are one or two
     $self->{'formatvar'} = shift;      $self->{'formatvar'} = shift;
   
     # The state to transition to after selection, or after discovering  
     # the cols are not set to 1  
     $self->{NEXTSTATE} = shift;      $self->{NEXTSTATE} = shift;
     bless($self);      bless($self);
   
     return $self;      return $self;
 }  }
   
Line 2894  sub render { Line 2985  sub render {
     my $result = '';      my $result = '';
     my $var = $self->{'variable'};      my $var = $self->{'variable'};
   
   
   
     if (defined $self->{ERROR_MSG}) {      if (defined $self->{ERROR_MSG}) {
         $result .= '<br /><font color="#FF0000">' . $self->{ERROR_MSG} . '</font><br />';          $result .= '<br /><span class="LC_error">' . $self->{ERROR_MSG} . '</span><br />';
     }      }
   
     my $width = 18;  
     my $format = $helper->{VARS}->{$self->{'formatvar'}};      my $format = $helper->{VARS}->{$self->{'formatvar'}};
     if (substr($format, 2, 1) ne '1') {  
  $width = 9;      # Use format to get sensible defaults for the margins:
   
   
       my ($laystyle, $cols, $papersize) = split(/\|/, $format);
       ($papersize)                      = split(/ /, $papersize);
   
   
       if ($laystyle eq 'L') {
    $laystyle = 'album';
       } else {
    $laystyle = 'book';
       }
   
   
       my %size;
       ($size{'width_and_units'},
        $size{'height_and_units'},
        $size{'margin_and_units'})=
    &Apache::lonprintout::page_format($papersize, $laystyle, $cols);
       
       foreach my $dimension ('width','height','margin') {
    ($size{$dimension},$size{$dimension.'_unit'}) =
       split(/ +/, $size{$dimension.'_and_units'},2);
          
    foreach my $unit ('cm','in') {
       $size{$dimension.'_options'} .= '<option ';
       if ($size{$dimension.'_unit'} eq $unit) {
    $size{$dimension.'_options'} .= 'selected="selected" ';
       }
       $size{$dimension.'_options'} .= '>'.$unit.'</option>';
    }
     }      }
   
     $result .= <<ELEMENTHTML;      $result .= <<ELEMENTHTML;
   
 <p>How should the column be formatted?</p>  
   
   <p>How should each column be formatted?</p>
   
 <table cellpadding='3'>  <table cellpadding='3'>
   <tr>    <tr>
     <td align='right'><b>Width</b>:</td>      <td align='right'><b>Width</b>:</td>
     <td align='left'><input type='text' name='$var.width' value='$width' size='4'></td>      <td align='left'><input type='text' name='$var.width' value="$size{'width'}" size='4' /></td>
     <td align='left'>      <td align='left'>
       <select name='$var.widthunit'>        <select name='$var.widthunit'>
         <option>cm</option><option>in</option>        $size{'width_options'}
       </select>        </select>
     </td>      </td>
   </tr>    </tr>
   <tr>    <tr>
     <td align='right'><b>Height</b>:</td>      <td align='right'><b>Height</b>:</td>
     <td align='left'><input type='text' name="$var.height" value="25.9" size='4'></td>      <td align='left'><input type='text' name="$var.height" value="$size{'height'}" size='4' /></td>
     <td align='left'>      <td align='left'>
       <select name='$var.heightunit'>        <select name='$var.heightunit'>
         <option>cm</option><option>in</option>        $size{'height_options'}
       </select>        </select>
     </td>      </td>
   </tr>    </tr>
   <tr>    <tr>
     <td align='right'><b>Left margin</b>:</td>      <td align='right'><b>Left margin</b>:</td>
     <td align='left'><input type='text' name='$var.lmargin' value='-1.5' size='4'></td>      <td align='left'><input type='text' name='$var.lmargin' value="$size{'margin'}" size='4' /></td>
     <td align='left'>      <td align='left'>
       <select name='$var.lmarginunit'>        <select name='$var.lmarginunit'>
         <option>cm</option><option>in</option>        $size{'margin_options'}
       </select>        </select>
     </td>      </td>
   </tr>    </tr>
 </table>  </table>
   
 <p>Hint: Some instructors like to leave scratch space for the student by  <!--<p>Hint: Some instructors like to leave scratch space for the student by
 making the width much smaller than the width of the page.</p>  making the width much smaller than the width of the page.</p>-->
   
 ELEMENTHTML  ELEMENTHTML
   
Line 2952  sub preprocess { Line 3076  sub preprocess {
     my $helper = Apache::lonhelper::getHelper();      my $helper = Apache::lonhelper::getHelper();
   
     my $format = $helper->{VARS}->{$self->{'formatvar'}};      my $format = $helper->{VARS}->{$self->{'formatvar'}};
 #    if (substr($format, 2, 1) ne '1') {  
 #        $helper->changeState($self->{NEXTSTATE});      #  If the user does not have 'pav' privilege, set default widths and
 #    }      #  on to the next state right away.
       #
       if (!$perm{'pav'}) {
    my $var = $self->{'variable'};
    my $format = $helper->{VARS}->{$self->{'formatvar'}};
   
    my ($laystyle, $cols, $papersize) = split(/\|/, $format);
    ($papersize)                      = split(/ /, $papersize);
   
   
    if ($laystyle eq 'L') {
       $laystyle = 'album';
    } else {
       $laystyle = 'book';
    }
    #  Figure out some good defaults for the print out and set them:
   
    my %size;
    ($size{'width'},
    $size{'height'},
    $size{'lmargin'})=
        &Apache::lonprintout::page_format($papersize, $laystyle, $cols);
   
    foreach my $dim ('width', 'height', 'lmargin') {
       my ($value, $units) = split(/ /, $size{$dim});
       
       &Apache::lonnet::logthis("$dim : $value : $units");
       
       $helper->{VARS}->{"$var.".$dim}      = $value;
       $helper->{VARS}->{"$var.".$dim.'unit'} = $units;
       
    }
   
   
    # Transition to the next state
   
    $helper->changeState($self->{NEXTSTATE});
       }
         
     return 1;      return 1;
 }  }
Line 2976  sub postprocess { Line 3137  sub postprocess {
     # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed       # /^-?[0-9]+(\.[0-9]*)?$/ -> optional minus, at least on digit, followed 
     # by an optional period, followed by digits, ending the string      # by an optional period, followed by digits, ending the string
   
     if ($width !~  /^-?[0-9]+(\.[0-9]*)?$/) {      if ($width !~  /^-?[0-9]*(\.[0-9]*)?$/) {
         $error .= "Invalid width; please type only a number.<br />\n";          $error .= "Invalid width; please type only a number.<br />\n";
     }      }
     if ($height !~  /^-?[0-9]+(\.[0-9]*)?$/) {      if ($height !~  /^-?[0-9]*(\.[0-9]*)?$/) {
         $error .= "Invalid height; please type only a number.<br />\n";          $error .= "Invalid height; please type only a number.<br />\n";
     }      }
     if ($lmargin !~  /^-?[0-9]+(\.[0-9]*)?$/) {      if ($lmargin !~  /^-?[0-9]*(\.[0-9]*)?$/) {
         $error .= "Invalid left margin; please type only a number.<br />\n";          $error .= "Invalid left margin; please type only a number.<br />\n";
     }      }
   

Removed from v.1.448  
changed lines
  Added in v.1.467


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