Diff for /loncom/interface/lonprintout.pm between versions 1.220 and 1.238

version 1.220, 2003/08/19 16:02:13 version 1.238, 2003/09/25 18:16:04
Line 49  use Apache::grades; Line 49  use Apache::grades;
 use Apache::edit;  use Apache::edit;
 use Apache::File();  use Apache::File();
 use Apache::lonnavmaps;  use Apache::lonnavmaps;
   use Apache::lonratedt;
 use POSIX qw(strftime);  use POSIX qw(strftime);
 use GDBM_File;  use GDBM_File;
   
Line 483  sub get_course { Line 484  sub get_course {
 sub page_format_transformation {  sub page_format_transformation {
     my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist) = @_;       my ($papersize,$layout,$numberofcolumns,$choice,$text,$assignment,$tableofcontents,$indexlist) = @_; 
     my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);      my ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin);
     $assignment=~s/_/ /g;      $assignment=&Apache::lonxml::latex_special_symbols($assignment,'header');
     if ($numberofcolumns != 1) {      if ($numberofcolumns != 1) {
  ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);   ($textwidth,$textheight,$oddoffset,$evenoffset,$topmargin) = &page_format($papersize,$layout,$numberofcolumns,$topmargin);
     } else {      } else {
Line 530  sub details_for_menu { Line 531  sub details_for_menu {
   
     my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}};      my $name_of_resourse = $hash{'title_'.$hash{'ids_'.$ENV{'form.postdata'}}};
     my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'});      my $symbolic = &Apache::lonnet::symbread($ENV{'form.postdata'});
     my ($map,$id,$resource)=split(/___/,$symbolic);      my ($map,$id,$resource)=&Apache::lonnet::decode_symb($symbolic);
     $map=&Apache::lonnet::clutter($map);      $map=&Apache::lonnet::clutter($map);
     my $name_of_sequence;      my $name_of_sequence;
     $name_of_sequence = $hash{'title_'.$hash{'ids_'.$map}};      $name_of_sequence = $hash{'title_'.$hash{'ids_'.$map}};
Line 669  ENDPART Line 670  ENDPART
     $form{'problem_split'}=$parmhash{'problem_stream_switch'};      $form{'problem_split'}=$parmhash{'problem_stream_switch'};
     $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};      $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
     my $rndseed=time;      my $rndseed=time;
       if ($helper->{'VARS'}->{'curseed'}) {
    $rndseed=$helper->{'VARS'}->{'curseed'};
       }
     $form{'rndseed'}=$rndseed;      $form{'rndseed'}=$rndseed;
     &Apache::lonnet::appenv(%moreenv);      &Apache::lonnet::appenv(%moreenv);
     &Apache::lonnet::delenv('form.counter');      &Apache::lonnet::delenv('form.counter');
Line 695  ENDPART Line 699  ENDPART
     if ($currentURL=~m/\.page\s*$/) {      if ($currentURL=~m/\.page\s*$/) {
  ($result,$number_of_columns) = &page_cleanup($result);   ($result,$number_of_columns) = &page_cleanup($result);
     }      }
           } elsif ($currentURL=~/\.sequence$/ && $helper->{'VARS'}->{'construction'} eq '1') {
               #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\/|;
       my $errtext=&Apache::lonratedt::mapread($currentURL);
       for (my $member=0;$member<=$#Apache::lonratedt::order;$member++) {
    $Apache::lonratedt::resources[$Apache::lonratedt::order[$member]]=~/^([^:]*):([^:]*):/;
    my $urlp=$2;
    if ($urlp=~/\.(problem|exam|quiz|assess|survey|form|library|xml|html|htm|xhtml|xhtm)$/) {
       my %form;
       $form{'grade_target'}='tex';
       $form{'textwidth'}=$LaTeXwidth;
       $form{'problem_split'}=$parmhash{'problem_stream_switch'};
       $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'};
       $form{'rndseed'}=$rndseed;
       my $texversion=&Apache::lonnet::ssi($urlp,%form);
       if($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'no') {
    my %form;
    $form{'grade_target'}='answer';
    $form{'answer_output_mode'}='tex';
    $form{'rndseed'}=$rndseed;
                           if ($urlp=~/\/res\//) {$ENV{'request.state'}='published';}
    ####my $answer=' SSSSSS '.$ENV{'request.state'}.' FFFFFFF ';
    my $answer=&Apache::lonnet::ssi($urlp,%form);
    $texversion=~s/(\\keephidden{ENDOFPROBLEM})/$answer$1/;
       }
       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\} /;}
       $result .= '\end{document}';   
  } else {   } else {
   $result='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: ';    $result.='\documentclass[letterpaper]{article}\usepackage{calc}\begin{document}Printout of this type of document is currently not supported: ';
   if ($currentURL=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) {    if ($currentURL=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) {
       $result.=$1;        $result.=$1;
   } elsif ($currentURL=~/\/ext\//) {    } elsif ($currentURL=~/\/ext\//) {
Line 722  ENDPART Line 775  ENDPART
  &Apache::lonnet::delenv('form.counter');   &Apache::lonnet::delenv('form.counter');
  &Apache::lonxml::init_counter();   &Apache::lonxml::init_counter();
  for (my $i=0;$i<=$#master_seq;$i++) {   for (my $i=0;$i<=$#master_seq;$i++) {
     $master_seq[$i]=~/___\d+___(.*)$/;      my (undef,undef,$urlp)=&Apache::lonnet::decode_symb($master_seq[$i]);
     my $urlp='/res/'.$1;      $urlp=&Apache::lonnet::clutter($urlp);
     if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') {      if ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems') {
  $selectionmade = 2;   $selectionmade = 2;
     } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {      } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'map_problems_pages') {
Line 732  ENDPART Line 785  ENDPART
  $selectionmade = 4;   $selectionmade = 4;
     }      }
     $form{'symb'}=$master_seq[$i];      $form{'symb'}=$master_seq[$i];
     $master_seq[$i]=~/(.*)___\d*___/;      my ($sequence)=&Apache::lonnet::decode_symb($master_seq[$i]);
     my $assignment=&Apache::lonnet::gettitle($1); #tittle of the assignment which contains this problem      my $assignment=&Apache::lonxml::latex_special_symbols(&Apache::lonnet::gettitle($sequence),'header'); #tittle of the assignment which contains this problem
     #&Apache::lonnet::logthis("Trying to get $urlp with symb $master_seq[$i]");      #&Apache::lonnet::logthis("Trying to get $urlp with symb $master_seq[$i]");
     my $texversion=&Apache::lonnet::ssi($urlp,%form);      my $texversion=&Apache::lonnet::ssi($urlp,%form);
     if ($urlp=~/\.page$/) {      if ($urlp=~/\.page$/) {
Line 793  ENDPART Line 846  ENDPART
     &Apache::lonxml::init_counter();      &Apache::lonxml::init_counter();
     foreach my $curresline (@master_seq)  {      foreach my $curresline (@master_seq)  {
  if ($curresline=~ m/\.(problem|exam|quiz|assess|survey|form|library)$/) {   if ($curresline=~ m/\.(problem|exam|quiz|assess|survey|form|library)$/) {
     my ($map,$id,$res_url) = split(/___/,$curresline);      my ($map,$id,$res_url) = &Apache::lonnet::decode_symb($curresline);
     if (&Apache::lonnet::allowed('bre',$res_url)) {      if (&Apache::lonnet::allowed('bre',$res_url)) {
  my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,   my $rendered = &Apache::loncommon::get_student_view($curresline,$username,$userdomain,
                                                                         $ENV{'request.course.id'},'tex');                                                                          $ENV{'request.course.id'},'tex');
Line 816  ENDPART Line 869  ENDPART
     }      }
     my $courseidinfo = &get_course();      my $courseidinfo = &get_course();
     if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }      if (defined($courseidinfo)) { $courseidinfo=' - '.$courseidinfo }
       my $currentassignment=&Apache::lonxml::latex_special_symbols($helper->{VARS}->{'assignment'},'header');
     if ($current_output=~/\\documentclass/) {      if ($current_output=~/\\documentclass/) {
  $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$helper->{VARS}->{'assignment'}}}\\vskip 3 mm /;   $current_output =~ s/\\begin{document}/\\setlength{\\topmargin}{1cm} \\begin{document}\\noindent\\lhead{\\textit{\\textbf{$fullname}}$courseidinfo \\hfill \\thepage \\\\ \\textit{$currentassignment}}\\vskip 3 mm /;
     } else {      } else {
  my $blanspages = '';   my $blanspages = '';
  for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blanspages.='\clearpage\strut\clearpage';}   for (my $j=0;$j<$helper->{'VARS'}->{'EMPTY_PAGES'};$j++) {$blanspages.='\clearpage\strut\clearpage';}
  $current_output = '\strut\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$helper->{VARS}->{'assignment'}.'}}} \vskip -5 mm '.$current_output;   $current_output = '\strut\\newline\\noindent\\makebox[\\textwidth/$number_of_columns][b]{\\hrulefill}\\newline\\noindent{\\tiny Printed from LON-CAPA\\copyright MSU{\\hfill} Licensed under GNU General Public License }\\newpage '.$blanspages.'\setcounter{page}{1}\noindent\parbox{\minipagewidth}{\noindent\\lhead{\\textit{\\textbf{'.$fullname.'}}'.$courseidinfo.' \\hfill \\thepage \\\\ \\textit{'.$currentassignment.'}}} \vskip -5 mm '.$current_output;
     }      }
     $result .= $current_output;      $result .= $current_output;
     &Apache::lonnet::delenv('form.counter');          &Apache::lonnet::delenv('form.counter');    
Line 840  ENDPART Line 893  ENDPART
  @list_of_files=sort @list_of_files;   @list_of_files=sort @list_of_files;
  my $flag_latex_header_remove = 'NO';    my $flag_latex_header_remove = 'NO'; 
  my $rndseed=time;   my $rndseed=time;
    if ($helper->{'VARS'}->{'curseed'}) {
       $rndseed=$helper->{'VARS'}->{'curseed'};
    }
  for (my $i=0;$i<=$#list_of_files;$i++) {   for (my $i=0;$i<=$#list_of_files;$i++) {
     my $urlp = $list_of_files[$i];      my $urlp = $list_of_files[$i];
     if ($urlp=~/\//) {      if ($urlp=~/\//) {
Line 915  ENDPART Line 971  ENDPART
     if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {      if ($helper->{'VARS'}->{'TABLE_INDEX'} eq 'yes') {
  if ($selectionmade<10) {$selectionmade*=100;} else {$selectionmade*=10;}   if ($selectionmade<10) {$selectionmade*=100;} else {$selectionmade*=10;}
     }      }
       if ($ENV{'request.role.adv'}) {$selectionmade*=10000;}
 #-- writing .tex file in prtspool   #-- writing .tex file in prtspool 
     my $temp_file;      my $temp_file;
     my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";      my $filename = "/home/httpd/prtspool/$ENV{'user.name'}_$ENV{'user.domain'}_printout_".time."_".rand(10000000).".tex";
Line 971  sub handler { Line 1028  sub handler {
   
 use Apache::lonhelper;  use Apache::lonhelper;
   
   sub addMessage {
       my $text = shift;
       my $paramHash = Apache::lonhelper::getParamHash();
       $paramHash->{MESSAGE_TEXT} = $text;
       Apache::lonhelper::message->new();
   }
   
   use Data::Dumper;
   
 sub printHelper {  sub printHelper {
     my $r = shift;      my $r = shift;
   
Line 1007  sub printHelper { Line 1073  sub printHelper {
     my $helper = Apache::lonhelper::helper->new("Printing Helper");      my $helper = Apache::lonhelper::helper->new("Printing Helper");
     $helper->declareVar('symb');      $helper->declareVar('symb');
     $helper->declareVar('postdata');          $helper->declareVar('postdata');    
       $helper->declareVar('curseed');    
     $helper->declareVar('filename');      $helper->declareVar('filename');
     $helper->declareVar('construction');      $helper->declareVar('construction');
     $helper->declareVar('assignment');      $helper->declareVar('assignment');
Line 1015  sub printHelper { Line 1082  sub printHelper {
     # very first screen.      # very first screen.
     # Detect whether we're coming from construction space      # Detect whether we're coming from construction space
     if ($ENV{'form.postdata'}=~/^(?:http:\/\/[^\/]+\/|\/|)\~([^\/]+)\/(.*)$/) {      if ($ENV{'form.postdata'}=~/^(?:http:\/\/[^\/]+\/|\/|)\~([^\/]+)\/(.*)$/) {
         $helper->{VARS}->{'filename'} = "/home/$1/public_html/$2";          $helper->{VARS}->{'filename'} = "~$1/$2";
         $helper->{VARS}->{'construction'} = 1;          $helper->{VARS}->{'construction'} = 1;
     } else {      } else {
         if ($ENV{'form.postdata'}) {          if ($ENV{'form.postdata'}) {
Line 1053  sub printHelper { Line 1120  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 {
         ($map, $id, $url) = split(/___/, $symb);          ($map, $id, $url) = &Apache::lonnet::decode_symb($symb);
         $helper->{VARS}->{'postdata'} = Apache::lonnet::clutter($url);          $helper->{VARS}->{'postdata'} = 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 $url = $helper->{VARS}->{'postdata'};              my $postdata = $helper->{VARS}->{'postdata'};
             $resourceTitle = substr($url, rindex($url, '/') + 1);              $resourceTitle = substr($postdata, rindex($postdata, '/') + 1);
         }          }
         $subdir = &Apache::lonnet::filelocation("", $url);          $subdir = &Apache::lonnet::filelocation("", $url);
     }      }
       if (!$helper->{VARS}->{'curseed'} && $ENV{'form.curseed'}) {
    $helper->{VARS}->{'curseed'}=$ENV{'form.curseed'};
       }
   
     my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();      my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
       my $userPriviledged = ($ENV{'request.role'}=~m/^cc\./ or
      $ENV{'request.role'}=~m/^in\./ or
      $ENV{'request.role'}=~m/^ta\./);
   
     Apache::lonhelper::registerHelperTags();      Apache::lonhelper::registerHelperTags();
   
Line 1075  sub printHelper { Line 1148  sub printHelper {
     # "Remove all duplicate slashes."      # "Remove all duplicate slashes."
     $subdir =~ s|/+|/|g;      $subdir =~ s|/+|/|g;
   
       # If it's a ~ directory, convert back to /home/user/public_html
       $subdir =~ s/^~(\w+)\//\/home\/$1\/public_html\//;
   
     # What can be printed is a very dynamic decision based on      # What can be printed is a very dynamic decision based on
     # lots of factors. So we need to dynamically build this list.      # lots of factors. So we need to dynamically build this list.
     # To prevent security leaks, states are only added to the wizard      # To prevent security leaks, states are only added to the wizard
Line 1089  sub printHelper { Line 1165  sub printHelper {
     my $printChoices = [];      my $printChoices = [];
     my $paramHash;      my $paramHash;
   
     if ($resourceTitle) {      if ($resourceTitle && $helper->{VARS}->{'postdata'}) {
         push @{$printChoices}, ["<b>$resourceTitle</b> (prints what you just saw on the screen)", 'current_document', 'PAGESIZE'];          push @{$printChoices}, ["<b>$resourceTitle</b> (what you just saw on the screen)", 'current_document', 'PAGESIZE'];
     }      }
   
 #    $r->print($helper->{VARS}->{'postdata'});  #    $r->print($helper->{VARS}->{'postdata'});
   
       # Useful filter strings
       my $isProblem = '$res->is_problem()';
       $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
       my $isProblemOrMap = '$res->is_problem() || $res->is_map()';
       my $isNotMap = '!$res->is_map()';
       $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;
       my $isMap = '$res->is_map()';
       my $symbFilter = '$res->symb()';
       my $urlValue = '$res->src()';
   
       $helper->declareVar('SEQUENCE');
   
       # Useful for debugging: Dump the help vars
       #$r->print(Dumper($helper->{VARS}));
       #$r->print($map);
   
     # If we're in a sequence...      # If we're in a sequence...
     if ($helper->{'VARS'}->{'construction'} ne '1') {      if (($helper->{'VARS'}->{'construction'} ne '1') &&
    $helper->{VARS}->{'postdata'} && $sequenceTitle) {
         # Allow problems from sequence          # Allow problems from sequence
         push @{$printChoices}, ["Problem(s) from <b>$sequenceTitle</b>", 'map_problems', 'CHOOSE_PROBLEMS'];          push @{$printChoices}, ["<b>Problems</b> in $sequenceTitle", 'map_problems', 'CHOOSE_PROBLEMS'];
         # Allow all resources from sequence          # Allow all resources from sequence
         push @{$printChoices}, ["Everything (problem(s), page(s), html/xml file(s)) from <b>$sequenceTitle</b>", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];          push @{$printChoices}, ["<b>Resources</b> in $sequenceTitle", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];
   
         my $isProblem = '$res->is_problem()';  
  $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;  
         my $isProblemOrMap = '$res->is_problem() || $res->is_map()';  
         my $isNotMap = '!$res->is_map()';  
  $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden;  
         my $symb = '$res->symb()';  
         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>      <message>(mark them then click "next" button) <br /></message>
     <resource variable="RESOURCES" multichoice="1" toponly='1'>      <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1">
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblem;</filterfunc>        <filterfunc>return $isProblem;</filterfunc>
       <mapurl>$map</mapurl>        <mapurl>$map</mapurl>
       <valuefunc>return $symb;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       </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>      <message>(mark them then click "next" button) <br /></message>
     <resource variable="RESOURCES" multichoice="1" toponly='1'>      <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1">
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isNotMap;</filterfunc>        <filterfunc>return $isNotMap;</filterfunc>
       <mapurl>$map</mapurl>        <mapurl>$map</mapurl>
       <valuefunc>return $symb;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       </resource>        </resource>
     </state>      </state>
 HELPERFRAGMENT  HELPERFRAGMENT
Line 1135  HELPERFRAGMENT Line 1222  HELPERFRAGMENT
   
     # If the user is priviledged, allow them to print all       # If the user is priviledged, allow them to print all 
     # problems in the course, optionally for selected students      # problems in the course, optionally for selected students
     if (($ENV{'request.role'}=~m/^cc\./ or $ENV{'request.role'}=~m/^in\./ or $ENV{'request.role'}=~m/^ta\./) and ($helper->{VARS}->{'postdata'}=~/\/res\//)) {       if ($userPriviledged && ($helper->{VARS}->{'postdata'}=~/\/res\//)) { 
         push @{$printChoices}, ['<b>Problems</b> in this course', 'all_problems', 'ALL_PROBLEMS'];          push @{$printChoices}, ['Problems from <b>entire course</b>', 'all_problems', 'ALL_PROBLEMS'];
         push @{$printChoices}, ["Problems from <b>$sequenceTitle</b> for selected students", 'problems_for_students', 'CHOOSE_STUDENTS'];   if ($sequenceTitle) {
       push @{$printChoices}, ["Problems from $sequenceTitle for <b>selected students</b>", 'problems_for_students', 'CHOOSE_STUDENTS'];
         my $isProblem = '$res->is_problem()';   }
  $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;  
         my $isProblemOrMap = '($res->is_problem() || $res->is_map())';  
  $isProblemOrMap .= ' && !$res->randomout()' if !$userCanSeeHidden;  
         my $symb = '$res->symb()';  
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);          &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_STUDENTS);
   <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>      <message>(mark them then click "next" button) <br /></message>
     <resource variable="RESOURCES" multichoice="1" suppressEmptySequences='1'>      <resource variable="RESOURCES" multichoice="1"
    suppressEmptySequences='1' addstatus="1">
       <nextstate>PAGESIZE</nextstate>        <nextstate>PAGESIZE</nextstate>
       <filterfunc>return $isProblemOrMap;</filterfunc>        <filterfunc>return $isProblemOrMap;</filterfunc>
       <choicefunc>return $isProblem;</choicefunc>        <choicefunc>return $isProblem;</choicefunc>
       <valuefunc>return $symb;</valuefunc>        <valuefunc>return $symbFilter;</valuefunc>
       </resource>        </resource>
     </state>      </state>
   
   <state name="CHOOSE_STUDENTS" title="Choose Students whose assignments you want to print">    <state name="CHOOSE_STUDENTS" title="Select Students and Resources">
     <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />      <student multichoice='1' variable="STUDENTS" nextstate="PAGESIZE" />
     <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">      <resource variable="RESOURCES" multichoice="1" addstatus="1">
       <filterfunc>return $isProblem</filterfunc>        <filterfunc>return $isProblem</filterfunc>
       <mapurl>$map</mapurl>        <mapurl>$map</mapurl>
       <valuefunc>return $symb</valuefunc>        <valuefunc>return $symbFilter</valuefunc>
       </resource>        </resource>
     <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 1175  CHOOSE_STUDENTS Line 1260  CHOOSE_STUDENTS
     }      }
   
     # 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 $ENV{'request.role.adv'}) {          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 $ENV{'request.role.adv'} and $subdir ne '/home/httpd/html/res/') {    
         push @{$printChoices}, ["Problems from current subdirectory <b>$subdir</b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];          push @{$printChoices}, ["Problems from current subdirectory <b>$subdir</b>", '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">
Line 1187  CHOOSE_STUDENTS Line 1272  CHOOSE_STUDENTS
       <filechoice>return '$subdir';</filechoice>        <filechoice>return '$subdir';</filechoice>
 CHOOSE_FROM_SUBDIR  CHOOSE_FROM_SUBDIR
                   
           # this is broken up because I really want interpolation above,
           # and I really DON'T want it below
         $xmlfrag .= <<'CHOOSE_FROM_SUBDIR';          $xmlfrag .= <<'CHOOSE_FROM_SUBDIR';
       <filefilter>return $filename =~         <filefilter>return Apache::lonhelper::files::not_old_version($filename) &&
            m/\.(problem|exam|quiz|assess|survey|form|library)$/;    $filename =~ m/\.(problem|exam|quiz|assess|survey|form|library)$/;
       </filefilter>        </filefilter>
       </files>        </files>
     </state>      </state>
Line 1197  CHOOSE_FROM_SUBDIR Line 1284  CHOOSE_FROM_SUBDIR
         &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);          &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
     }      }
   
       # Allow the user to select any sequence in the course, feed it to
       # another resource selector for that sequence
       push @$printChoices, ["Resources from <b>selected sequence</b> in course",
                             'map_problems_pages', 'CHOOSE_SEQUENCE'];
       &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_FROM_ANY_SEQUENCE);
     <state name="CHOOSE_SEQUENCE" title="Select Sequence To Print From">
       <message>Select the sequence to print resources from:</message>
       <resource variable="SEQUENCE">
         <nextstate>CHOOSE_FROM_ANY_SEQUENCE</nextstate>
         <filterfunc>return \$res->is_sequence;</filterfunc>
         <valuefunc>return $urlValue;</valuefunc>
         </resource>
       </state>
     <state name="CHOOSE_FROM_ANY_SEQUENCE" title="Select Resources To Print">
       <message>(mark desired resources then click "next" button) <br /></message>
       <resource variable="RESOURCES" multichoice="1" toponly='1' addstatus="1">
         <nextstate>PAGESIZE</nextstate>
         <filterfunc>return $isProblem</filterfunc>
         <mapurl evaluate='1'>return $helper->{VARS}->{'SEQUENCE'};</mapurl>
         <valuefunc>return $symbFilter;</valuefunc>
         </resource>
       </state>
   CHOOSE_FROM_ANY_SEQUENCE
   
     # Generate the first state, to select which resources get printed.      # Generate the first state, to select which resources get printed.
     Apache::lonhelper::state->new("START", "What do you want to print? Make a choice.");      Apache::lonhelper::state->new("START", "Select Printing Options:");
     $paramHash = Apache::lonhelper::getParamHash();      $paramHash = Apache::lonhelper::getParamHash();
     $paramHash->{MESSAGE_TEXT} = "";      $paramHash->{MESSAGE_TEXT} = "";
     Apache::lonhelper::message->new();      Apache::lonhelper::message->new();
Line 1208  CHOOSE_FROM_SUBDIR Line 1319  CHOOSE_FROM_SUBDIR
     $paramHash->{CHOICES} = $printChoices;      $paramHash->{CHOICES} = $printChoices;
     Apache::lonhelper::choices->new();      Apache::lonhelper::choices->new();
   
       my $startedTable = 0; # have we started an HTML table yet? (need
                             # to close it later)
   
     if (($ENV{'request.role.adv'} and &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) or       if (($ENV{'request.role.adv'} and &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) or 
  ($helper->{VARS}->{'construction'} eq '1')) {   ($helper->{VARS}->{'construction'} eq '1')) {
         $paramHash = Apache::lonhelper::getParamHash();   addMessage("<hr width='33%' /><table><tr><td align='right'>Print With Answers:</td><td>");
         $paramHash->{MESSAGE_TEXT} = "<br /><table><tr><td><big><b><i>Next four options are available only for advanced users:  </i></b></big></td><td>";  
         Apache::lonhelper::message->new();  
         $paramHash = Apache::lonhelper::getParamHash();          $paramHash = Apache::lonhelper::getParamHash();
  $paramHash->{'variable'} = 'ANSWER_TYPE';      $paramHash->{'variable'} = 'ANSWER_TYPE';   
  $helper->declareVar('ANSWER_TYPE');            $helper->declareVar('ANSWER_TYPE');         
         $paramHash->{CHOICES} = [          $paramHash->{CHOICES} = [
                                    ['Print without answer', 'yes'],                                     ['No', 'yes'],
                                    ['Print with answers', 'no'] ];                                     ['Yes', 'no'] ];
         Apache::lonhelper::dropdown->new();          Apache::lonhelper::dropdown->new();
    addMessage("</td></tr>");
    $startedTable = 1;
     }      }
   
     if ($ENV{'request.role.adv'}) {      if ($ENV{'request.role.adv'}) {
         $paramHash = Apache::lonhelper::getParamHash();   if (!$startedTable) {
         $paramHash->{MESSAGE_TEXT} = "</td></tr><tr><td>&nbsp;</td><td>";      addMessage("<hr width='33%' /><table><tr><td align='right'>LaTeX mode: </td><td>");
         Apache::lonhelper::message->new();      $startedTable = 1;
    } else {
       addMessage("<tr><td align='right'>LaTeX mode: </td><td>");
    }
         $paramHash = Apache::lonhelper::getParamHash();          $paramHash = Apache::lonhelper::getParamHash();
  $paramHash->{'variable'} = 'LATEX_TYPE';      $paramHash->{'variable'} = 'LATEX_TYPE';   
  $helper->declareVar('LATEX_TYPE');     $helper->declareVar('LATEX_TYPE');  
  if ($helper->{VARS}->{'construction'} eq '1') {          if ($helper->{VARS}->{'construction'} eq '1') {       
     $paramHash->{CHOICES} = [      $paramHash->{CHOICES} = [
      ['Print in standard LaTeX mode', 'standard'],        ['standard LaTeX mode', 'standard'], 
      ['Print in LaTeX batchmode', 'batchmode'], ];       ['LaTeX batchmode', 'batchmode'], ];
  } else {   } else {
     $paramHash->{CHOICES} = [      $paramHash->{CHOICES} = [
      ['Print in LaTeX batchmode', 'batchmode'],       ['LaTeX batchmode', 'batchmode'],
      ['Print in standard LaTeX mode', 'standard'] ];       ['standard LaTeX mode', 'standard'] ];
  }   }
         Apache::lonhelper::dropdown->new();          Apache::lonhelper::dropdown->new();
     
         $paramHash = Apache::lonhelper::getParamHash();   addMessage("</td></tr><tr><td align='right'>Print Table of Contents: </td><td>");
         $paramHash->{MESSAGE_TEXT} = "</td></tr><tr><td>&nbsp;</td><td>";  
         Apache::lonhelper::message->new();  
         $paramHash = Apache::lonhelper::getParamHash();          $paramHash = Apache::lonhelper::getParamHash();
  $paramHash->{'variable'} = 'TABLE_CONTENTS';      $paramHash->{'variable'} = 'TABLE_CONTENTS';   
  $helper->declareVar('TABLE_CONTENTS');            $helper->declareVar('TABLE_CONTENTS');         
         $paramHash->{CHOICES} = [          $paramHash->{CHOICES} = [
                                    ['Print without Table of Contents', 'no'],                                     ['No', 'no'],
                                    ['Print with Table of Contents', 'yes'] ];                                     ['Yes', 'yes'] ];
         Apache::lonhelper::dropdown->new();          Apache::lonhelper::dropdown->new();
    addMessage("</td></tr>");
                   
  if (not $helper->{VARS}->{'construction'}) {   if (not $helper->{VARS}->{'construction'}) {
     $paramHash = Apache::lonhelper::getParamHash();      addMessage("<tr><td align='right'>Print Index: </td><td>");
     $paramHash->{MESSAGE_TEXT} = "</td></tr><tr><td>&nbsp;</td><td>";  
     Apache::lonhelper::message->new();  
     $paramHash = Apache::lonhelper::getParamHash();      $paramHash = Apache::lonhelper::getParamHash();
     $paramHash->{'variable'} = 'TABLE_INDEX';         $paramHash->{'variable'} = 'TABLE_INDEX';   
     $helper->declareVar('TABLE_INDEX');               $helper->declareVar('TABLE_INDEX');         
     $paramHash->{CHOICES} = [      $paramHash->{CHOICES} = [
      ['Print without Index', 'no'],       ['No', 'no'],
      ['Print with Index', 'yes'] ];       ['Yes', 'yes'] ];
     Apache::lonhelper::dropdown->new();      Apache::lonhelper::dropdown->new();
       addMessage("</td></tr>");
  }   }
   
  if ($helper->{VARS}->{'construction'}) {   if ($helper->{VARS}->{'construction'}) {
     $paramHash = Apache::lonhelper::getParamHash();      addMessage("<tr><td align='right'>Print With URL: </td><td>");
     $paramHash->{MESSAGE_TEXT} = "</td></tr><tr><td>&nbsp;</td><td>";  
     Apache::lonhelper::message->new();  
     $paramHash = Apache::lonhelper::getParamHash();      $paramHash = Apache::lonhelper::getParamHash();
     $paramHash->{'variable'} = 'CONSTR_RESOURSE_URL';         $paramHash->{'variable'} = 'CONSTR_RESOURSE_URL';   
     $helper->declareVar('CONSTR_RESOURSE_URL');               $helper->declareVar('CONSTR_RESOURSE_URL');         
     $paramHash->{CHOICES} = [      $paramHash->{CHOICES} = [
      ['Print without URL', 'no'],       ['No', 'no'],
      ['Print with UTL', 'yes'] ];       ['Yes', 'yes'] ];
     Apache::lonhelper::dropdown->new();      Apache::lonhelper::dropdown->new();
       addMessage("</td></tr>");
    }
    if ($helper->{'VARS'}->{'construction'}) { 
       my $xmlfrag .= <<'RNDSEED';
       <message><tr><td align='right'>Use random seed: </td><td></message>
       <string variable="curseed" size="15" maxlength="15">
    <defaultvalue>
               return $helper->{VARS}->{'curseed'};
           </defaultvalue>
        </string>
                <message></td></tr></message>
   RNDSEED
               &Apache::lonxml::xmlparse($r, 'helper', $xmlfrag);
  }   }
       }
   
         $paramHash = Apache::lonhelper::getParamHash();      if ($startedTable) {
         $paramHash->{MESSAGE_TEXT} = "</td></tr><table>";   addMessage("</table>");
         Apache::lonhelper::message->new();  
     }      }
   
     Apache::lonprintout::page_format_state->new("FORMAT");      Apache::lonprintout::page_format_state->new("FORMAT");
Line 1370  sub render { Line 1496  sub render {
   
     $result .= <<STATEHTML;      $result .= <<STATEHTML;
   
 <p><big><i><b>What page format do you prefer?</b></i></big></p>  <hr width="33%" />
 <table cellpadding="3">  <table cellpadding="3">
   <tr>    <tr>
     <td align="center"><b>Page layout</b></td>      <td align="center"><b>Page layout</b></td>

Removed from v.1.220  
changed lines
  Added in v.1.238


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