Diff for /loncom/interface/lonprintout.pm between versions 1.287 and 1.294

version 1.287, 2004/03/24 22:22:04 version 1.294, 2004/04/26 18:21:26
Line 750  ENDPART Line 750  ENDPART
     my $put_result = &Apache::lonnet::put('environment',{'construct.style'=>$helper->{'VARS'}->{'style_file'}},$dom,$user);      my $put_result = &Apache::lonnet::put('environment',{'construct.style'=>$helper->{'VARS'}->{'style_file'}},$dom,$user);
  }   }
  my %form;   my %form;
                   if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';}
  $form{'grade_target'}='tex';   $form{'grade_target'}='tex';
  $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);   $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth);
  $form{'problem_split'}=$parmhash{'problem_stream_switch'};   $form{'problem_split'}=$parmhash{'problem_stream_switch'};
Line 1001  ENDPART Line 1002  ENDPART
  $result .= $print_array[0].'  \end{document}';   $result .= $print_array[0].'  \end{document}';
      } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||       } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon')     ||
       ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon')  ) {         ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon')  ) { 
  $selectionmade="Seems to be useless";   my $cdom =$ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
    my $cnum =$ENV{'course.'.$ENV{'request.course.id'}.'.num'};
    my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'};
    my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'};
    my $old_name=$helper->{'VARS'}->{'REUSE_OLD_CODES'};
  my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};   my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'};
      my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'});
     } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') {         my $flag_latex_header_remove = 'NO'; 
    my %moreenv = ('textwidth' => &get_textwidth($helper,$LaTeXwidth));
    my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$num_todo,'inline');
    my $seed=time+($$<<16)+($$);
    my @allcodes;
    if ($old_name) {
        my %result=&Apache::lonnet::get('CODEs',[$old_name],$cdom,$cnum);
        @allcodes=split(',',$result{$old_name});
    } else {
        my %allcodes;
        for (my $i=0;$i<$num_todo;$i++) {
    $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,'6');
        }
        if ($code_name) {
    &Apache::lonnet::put('CODEs',
         {$code_name =>join(',',keys(%allcodes))},
         $cdom,$cnum);
        }
        @allcodes=keys(%allcodes);
    }
    my $i=0;
    foreach my $code (sort(@allcodes)) {
        $moreenv{'CODE'}=&num_to_letters($code);
        my ($output,$fullname)=
    &print_resources($r,$helper,'anonymous',$type,\%moreenv,
     \@master_seq,$flag_latex_header_remove);
        $print_array[$i].=$output;
        &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
          &mt('last assignment').' '.$fullname);
        $flag_latex_header_remove = 'YES';
        $i++;
    }
    &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
    $result .= $print_array[0].'  \end{document}';
        } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') {      
     #prints selected problems from the subdirectory       #prints selected problems from the subdirectory 
  $selectionmade = 6;   $selectionmade = 6;
         my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};          my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'};
Line 1162  ENDPART Line 1201  ENDPART
                             'cgi.'.$identifier.'backref' => $URLback,);                              'cgi.'.$identifier.'backref' => $URLback,);
     
 $r->print(<<FINALEND);  $r->print(<<FINALEND);
 <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$identifier">  <meta http-equiv="Refresh" content="0; url=/cgi-bin/printout.pl?$identifier" />
 </body>  </body>
 </html>  </html>
 FINALEND  FINALEND
 }  }
   
   sub num_to_letters {
       my ($num) = @_;
       my @nums= split('',$num);
       my @num_to_let=('A'..'Z');
       my $word;
       foreach my $digit (@nums) { $word.=$num_to_let[$digit]; }
       return $word;
   }
   
   sub get_CODE {
       my ($all_codes,$num,$seed,$size)=@_;
       my $max='1'.'0'x$size;
       srand($seed);
       my $newcode;
       while(1) {
    $newcode=sprintf("%06d",int(rand($max)));
    if (!exists($$all_codes{$newcode})) {
       $$all_codes{$newcode}=1;
       return &num_to_letters($newcode);
    }
       }
   }
   
 sub print_resources {  sub print_resources {
     my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header)=@_;      my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header)=@_;
     my $current_output = '';       my $current_output = ''; 
     my ($username,$userdomain,$usersection) = split /:/,$person;      my ($username,$userdomain,$usersection) = split /:/,$person;
     my $fullname = &get_name($username,$userdomain);      my $fullname = &get_name($username,$userdomain);
           if ($person =~ 'anon') {
    $fullname = "CODE - ".$moreenv->{'CODE'};
       }
     #goes through all resources, checks if they are available for       #goes through all resources, checks if they are available for 
     #current student, and produces output         #current student, and produces output   
     &Apache::lonnet::delenv('form.counter');      &Apache::lonnet::delenv('form.counter');
Line 1318  sub printHelper { Line 1381  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('curseed'); 
       $helper->declareVar('probstatus');   
     $helper->declareVar('filename');      $helper->declareVar('filename');
     $helper->declareVar('construction');      $helper->declareVar('construction');
     $helper->declareVar('assignment');      $helper->declareVar('assignment');
Line 1378  sub printHelper { Line 1442  sub printHelper {
     if (!$helper->{VARS}->{'curseed'} && $ENV{'form.curseed'}) {      if (!$helper->{VARS}->{'curseed'} && $ENV{'form.curseed'}) {
  $helper->{VARS}->{'curseed'}=$ENV{'form.curseed'};   $helper->{VARS}->{'curseed'}=$ENV{'form.curseed'};
     }      }
       if (!$helper->{VARS}->{'probstatus'} && $ENV{'form.problemtype'}) {
    $helper->{VARS}->{'probstatus'}=$ENV{'form.problemtype'};
       }
   
     my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();      my $userCanSeeHidden = Apache::lonnavmaps::advancedUser();
     my $userPriviledged = ($ENV{'request.role'}=~m/^cc\./ or      my $userPriviledged = ($ENV{'request.role'}=~m/^cc\./ or
Line 1409  sub printHelper { Line 1476  sub printHelper {
     my $paramHash;      my $paramHash;
   
     if ($resourceTitle) {      if ($resourceTitle) {
         push @{$printChoices}, ["<b><i>$resourceTitle</i></b> (what you just saw on the screen)", 'current_document', 'PAGESIZE'];          push @{$printChoices}, ["<b><i>$resourceTitle</i></b> (".&mt('what you just saw on the screen').")", 'current_document', 'PAGESIZE'];
     }      }
   
 #    $r->print($helper->{VARS}->{'postdata'});  
   
     # Useful filter strings      # Useful filter strings
     my $isProblem = '($res->is_problem()||$res->contains_problem) ';      my $isProblem = '($res->is_problem()||$res->contains_problem) ';
     $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;      $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden;
Line 1435  sub printHelper { Line 1500  sub printHelper {
  $helper->{VARS}->{'postdata'} &&   $helper->{VARS}->{'postdata'} &&
  $helper->{VARS}->{'assignment'}) {   $helper->{VARS}->{'assignment'}) {
         # Allow problems from sequence          # Allow problems from sequence
         push @{$printChoices}, ["<b>Problems</b> in <b><i>$sequenceTitle</i></b>", 'map_problems', 'CHOOSE_PROBLEMS'];          push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('in')." <b><i>$sequenceTitle</i></b>", 'map_problems', 'CHOOSE_PROBLEMS'];
         # Allow all resources from sequence          # Allow all resources from sequence
         push @{$printChoices}, ["<b>Resources</b> in <b><i>$sequenceTitle</i></b>", 'map_problems_pages', 'CHOOSE_PROBLEMS_HTML'];          push @{$printChoices}, ["<b>".&mt('Resources')."</b> ".&mt('in')." <b><i>$sequenceTitle</i></b>", '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">
Line 1484  HELPERFRAGMENT Line 1549  HELPERFRAGMENT
 ALL_PROBLEMS  ALL_PROBLEMS
   
  if ($helper->{VARS}->{'assignment'}) {   if ($helper->{VARS}->{'assignment'}) {
     push @{$printChoices}, ["<b>Problems</b> from <b><i>$sequenceTitle</i></b> for <b>selected students</b>", 'problems_for_students', 'CHOOSE_STUDENTS'];      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}, ["<b>Problems</b> from <b><i>$sequenceTitle</i></b> for <b>anonymous students</b>", 'problems_for_anonymous', 'CHOOSE_ANON1'];      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'];
  }   }
  my $resource_selector=<<RESOURCE_SELECTOR;   my $resource_selector=<<RESOURCE_SELECTOR;
    <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>
Line 1512  RESOURCE_SELECTOR Line 1577  RESOURCE_SELECTOR
     $resource_selector      $resource_selector
   </state>    </state>
 CHOOSE_STUDENTS  CHOOSE_STUDENTS
   
    my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
    my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
           my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
    my $namechoice='<choice></choice>';
    foreach my $name (@names) {
       if ($name =~ /^error: 2 /) { next; }
       $namechoice.='<choice computer="'.$name.'">'.$name.'</choice>';
    }
         &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);          &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON1);
   <state name="CHOOSE_ANON1" title="Select Students and Resources">    <state name="CHOOSE_ANON1" title="Select Students and Resources">
       <nextstate>PAGESIZE</nextstate>
     <message><hr width='33%' /><b>Number of anonymous assignments to print?</b></message>      <message><hr width='33%' /><b>Number of anonymous assignments to print?</b></message>
     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>      <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>
           <message><br /><b>Names to store the CODEs under for later:</b></message>
       <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
       <message><hr width='33%' /></message>
       <message><b>Reprint a set of saved CODEs:</b></message>
       <dropdown variable="REUSE_OLD_CODES">
           $namechoice
       </dropdown>
     <message><hr width='33%' /></message>      <message><hr width='33%' /></message>
     $resource_selector      $resource_selector
   </state>    </state>
Line 1524  CHOOSE_ANON1 Line 1605  CHOOSE_ANON1
   
   
  if ($helper->{VARS}->{'assignment'}) {   if ($helper->{VARS}->{'assignment'}) {
     push @{$printChoices}, ["<b>Resources</b> from <b><i>$sequenceTitle</i></b> for <b>selected students</b>", 'resources_for_students', 'CHOOSE_STUDENTS1'];      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}, ["<b>Resources</b> from <b><i>$sequenceTitle</i></b> for <b>anonymous students</b>", 'resources_for_anonymous', 'CHOOSE_ANON2'];      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'];
  }   }
           
   
Line 1557  CHOOSE_STUDENTS1 Line 1638  CHOOSE_STUDENTS1
   
  &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON2);   &Apache::lonxml::xmlparse($r, 'helper', <<CHOOSE_ANON2);
   <state name="CHOOSE_ANON2" title="Select Students and Resources">    <state name="CHOOSE_ANON2" title="Select Students and Resources">
     <message><hr width='33%' /><b>How many Anonymous exams to print?</b></message>      <nextstate>PAGESIZE</nextstate>
       <message><hr width='33%' /><b>Number of anonymous assignments to print?</b></message>
     <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>      <string variable="NUMBER_TO_PRINT_TOTAL" maxlength="5" size="5"></string>
       <message><br /><b>Names to store the CODEs under for later:</b></message>
       <string variable="ANON_CODE_STORAGE_NAME" maxlength="50" size="20" />
       <message><hr width='33%' /></message>
       <message><b>Reprint a set of saved CODEs:</b></message>
       <dropdown variable="REUSE_OLD_CODES">
           $namechoice
       </dropdown>
     <message><hr width='33%' /></message>      <message><hr width='33%' /></message>
     $resource_selector      $resource_selector
   </state>    </state>
Line 1567  CHOOSE_ANON2 Line 1656  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 $ENV{'request.role.adv'} and $subdir ne '/home/httpd/html/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 $ENV{'request.role.adv'} and $subdir ne '/home/httpd/html/res/') {    
         push @{$printChoices}, ["<b>Problems</b> from current subdirectory <b><i>$subdir</i></b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];          push @{$printChoices}, ["<b>".&mt('Problems')."</b> ".&mt('from current subdirectory')." <b><i>$subdir</i></b>", 'problems_from_directory', 'CHOOSE_FROM_SUBDIR'];
   
         my $f = '$filename';          my $f = '$filename';
         my $xmlfrag = <<CHOOSE_FROM_SUBDIR;          my $xmlfrag = <<CHOOSE_FROM_SUBDIR;
Line 1644  CHOOSE_FROM_ANY_SEQUENCE Line 1733  CHOOSE_FROM_ANY_SEQUENCE
         $paramHash->{CHOICES} = [          $paramHash->{CHOICES} = [
                                    ['Without Answers', 'yes'],                                     ['Without Answers', 'yes'],
                                    ['With Answers', 'no'],                                     ['With Answers', 'no'],
                                    ['Only Answers', 'only'] ];                                     ['Only Answers', 'only'],
                                      ['As Exam Problem', 'exam']
                                   ];
         Apache::lonhelper::dropdown->new();          Apache::lonhelper::dropdown->new();
  addMessage("</td></tr>");   addMessage("</td></tr>");
  $startedTable = 1;   $startedTable = 1;
Line 1696  CHOOSE_FROM_ANY_SEQUENCE Line 1787  CHOOSE_FROM_ANY_SEQUENCE
  if ($helper->{'VARS'}->{'construction'}) {    if ($helper->{'VARS'}->{'construction'}) { 
     my $stylevalue=$ENV{'construct.style'};      my $stylevalue=$ENV{'construct.style'};
     my $xmlfrag .= <<"RNDSEED";      my $xmlfrag .= <<"RNDSEED";
     <message><tr><td align='right'>Use random seed: </td><td></message>      <message><tr><td align='right'>Use random seed:  </td><td></message>
     <string variable="curseed" size="15" maxlength="15">      <string variable="curseed" size="15" maxlength="15">
  <defaultvalue>   <defaultvalue>
             return $helper->{VARS}->{'curseed'};              return $helper->{VARS}->{'curseed'};

Removed from v.1.287  
changed lines
  Added in v.1.294


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