--- loncom/interface/lonprintout.pm 2004/03/23 19:36:51 1.286 +++ loncom/interface/lonprintout.pm 2004/04/06 15:47:52 1.289 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.286 2004/03/23 19:36:51 albertel Exp $ +# $Id: lonprintout.pm,v 1.289 2004/04/06 15:47:52 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -750,6 +750,7 @@ ENDPART my $put_result = &Apache::lonnet::put('environment',{'construct.style'=>$helper->{'VARS'}->{'style_file'}},$dom,$user); } my %form; + if ($helper->{'VARS'}->{'ANSWER_TYPE'} eq 'exam') {$form{'problemtype'}='exam';} $form{'grade_target'}='tex'; $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; @@ -1001,10 +1002,38 @@ ENDPART $result .= $print_array[0].' \end{document}'; } elsif (($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_for_anon') || ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'resources_for_anon') ) { - $selectionmade="Seems to be useless"; + my $num_todo=$helper->{'VARS'}->{'NUMBER_TO_PRINT_TOTAL'}; + my $code_name=$helper->{'VARS'}->{'ANON_CODE_STORAGE_NAME'}; + if ($helper->{'VARS'}->{'REMEBER_ANON_CODES'} != 1) { + $code_name=undef; + } my @master_seq=split /\|\|\|/, $helper->{'VARS'}->{'RESOURCES'}; - - } elsif ($helper->{'VARS'}->{'PRINT_TYPE'} eq 'problems_from_directory') { + my ($type) = split(/_/,$helper->{'VARS'}->{'PRINT_TYPE'}); + 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; + for (my $i=0;$i<$num_todo;$i++) { + $moreenv{'CODE'}=&get_CODE(\%allcodes,$i,$seed,'6'); + 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'; + } + if ($code_name) { + my $cdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; + my $cnum = $ENV{'course.'.$ENV{'request.course.id'}.'.num'}; + &Apache::lonnet::put('CODEs', + { $code_name => join(',',keys(%allcodes)) }, + $cdom,$cnum); + } + &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 $selectionmade = 6; my @list_of_files=split /\|\|\|/, $helper->{'VARS'}->{'FILES'}; @@ -1162,19 +1191,43 @@ ENDPART 'cgi.'.$identifier.'backref' => $URLback,); $r->print(< + 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=int(rand($max)); + if (!exists($$all_codes{$newcode})) { + $$all_codes{$newcode}=1; + return &num_to_letters($newcode); + } + } +} sub print_resources { my ($r,$helper,$person,$type,$moreenv,$master_seq,$remove_latex_header)=@_; my $current_output = ''; my ($username,$userdomain,$usersection) = split /:/,$person; my $fullname = &get_name($username,$userdomain); - + if ($person =~ 'anon') { + $fullname = "CODE - ".$moreenv->{'CODE'}; + } #goes through all resources, checks if they are available for #current student, and produces output &Apache::lonnet::delenv('form.counter'); @@ -1415,10 +1468,10 @@ sub printHelper { # $r->print($helper->{VARS}->{'postdata'}); # Useful filter strings - my $isProblem = '$res->is_problem()'; + my $isProblem = '($res->is_problem()||$res->contains_problem) '; $isProblem .= ' && !$res->randomout()' if !$userCanSeeHidden; - my $isProblemOrMap = '$res->is_problem() || $res->is_map()'; - my $isNotMap = '!$res->is_map()'; + my $isProblemOrMap = '$res->is_problem() || $res->contains_problem() || $res->is_sequence()'; + my $isNotMap = '!$res->is_sequence()'; $isNotMap .= ' && !$res->randomout()' if !$userCanSeeHidden; my $isMap = '$res->is_map()'; my $symbFilter = '$res->symb()'; @@ -1442,7 +1495,8 @@ sub printHelper { my $helperFragment = < (mark them then click "next" button)
- + PAGESIZE return $isProblem; $map @@ -1452,7 +1506,8 @@ sub printHelper { (mark them then click "next" button)
- + PAGESIZE return $isNotMap; $map @@ -1471,11 +1526,11 @@ HELPERFRAGMENT &Apache::lonxml::xmlparse($r, 'helper', < (mark them then click "next" button)
- + PAGESIZE return $isProblemOrMap; - return $isProblem; + return $isNotMap; return $symbFilter;
@@ -1483,11 +1538,12 @@ ALL_PROBLEMS if ($helper->{VARS}->{'assignment'}) { push @{$printChoices}, ["Problems from $sequenceTitle for selected students", 'problems_for_students', 'CHOOSE_STUDENTS']; - push @{$printChoices}, ["Problems from $sequenceTitle for anonymous students", 'problems_for_anonymous', 'CHOOSE_ANON1']; + push @{$printChoices}, ["Problems from $sequenceTitle for anonymous students", 'problems_for_anon', 'CHOOSE_ANON1']; } my $resource_selector=<
Select resources for the assignment
- + return $isProblem; $map return $symbFilter; @@ -1511,8 +1567,16 @@ RESOURCE_SELECTOR CHOOSE_STUDENTS &Apache::lonxml::xmlparse($r, 'helper', < -
How many Anonymous exams to print?
+ PAGESIZE +
Number of anonymous assignments to print?
+ + + Should the CODEs used on this printing be remebered for later? + + + Names to store the CODEs under for later: +
$resource_selector @@ -1521,13 +1585,14 @@ CHOOSE_ANON1 if ($helper->{VARS}->{'assignment'}) { push @{$printChoices}, ["Resources from $sequenceTitle for selected students", 'resources_for_students', 'CHOOSE_STUDENTS1']; - push @{$printChoices}, ["Resources from $sequenceTitle for anonymous students", 'resources_for_anonymous', 'CHOOSE_ANON2']; + push @{$printChoices}, ["Resources from $sequenceTitle for anonymous students", 'resources_for_anon', 'CHOOSE_ANON2']; } $resource_selector=<
Select resources for the assignment
- + return $isNotMap; $map return $symbFilter; @@ -1605,7 +1670,8 @@ CHOOSE_FROM_SUBDIR (mark desired resources then click "next" button)
- + PAGESIZE return $isProblem return '$escapedSequenceName'; @@ -1638,7 +1704,9 @@ CHOOSE_FROM_ANY_SEQUENCE $paramHash->{CHOICES} = [ ['Without Answers', 'yes'], ['With Answers', 'no'], - ['Only Answers', 'only'] ]; + ['Only Answers', 'only'], + ['As Exam Problem', 'exam'] + ]; Apache::lonhelper::dropdown->new(); addMessage(""); $startedTable = 1;