--- loncom/interface/lonprintout.pm 2004/03/23 01:34:17 1.284 +++ loncom/interface/lonprintout.pm 2004/04/07 18:01:19 1.290 @@ -1,7 +1,7 @@ # The LearningOnline Network # Printout # -# $Id: lonprintout.pm,v 1.284 2004/03/23 01:34:17 albertel Exp $ +# $Id: lonprintout.pm,v 1.290 2004/04/07 18:01:19 sakharuk Exp $ # # Copyright Michigan State University Board of Trustees # @@ -661,6 +661,17 @@ sub recalcto_mm { return $LaTeXwidth; } +sub get_textwidth { + my ($helper,$LaTeXwidth)=@_; + my $textwidth=$LaTeXwidth; + if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && + $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { + $textwidth=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '. + $helper->{'VARS'}->{'pagesize.widthunit'}); + } + return $textwidth; +} + sub output_data { my ($r,$helper,$rparmhash) = @_; my %parmhash = %$rparmhash; @@ -739,13 +750,9 @@ ENDPART my $put_result = &Apache::lonnet::put('environment',{'construct.style'=>$helper->{'VARS'}->{'style_file'}},$dom,$user); } my %form; + if ($helper->{'VARS'}->{'probstatus'} eq 'exam') {$form{'problemtype'}='exam';} $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; if ($helper->{'VARS'}->{'curseed'}) { @@ -810,12 +817,7 @@ ENDPART if ($helper->{'VARS'}->{'ANSWER_TYPE'} ne 'only') { my %form; $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; $form{'rndseed'}=$rndseed; @@ -861,12 +863,7 @@ ENDPART } elsif ($currentURL=~/\/smppg$/) { my %form; $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; my $texversion=&Apache::lonnet::ssi($currentURL,%form); $result .= $texversion; @@ -888,12 +885,7 @@ ENDPART #-- produce an output string my %form=(); $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'problem_split'}=$parmhash{'problem_stream_switch'}; $form{'latex_type'}=$helper->{'VARS'}->{'LATEX_TYPE'}; my $flag_latex_header_remove = 'NO'; @@ -994,12 +986,7 @@ ENDPART #loop over students my $flag_latex_header_remove = 'NO'; my %moreenv; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $moreenv{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $moreenv{'textwidth'}=$LaTeXwidth; - } + $moreenv{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Print Status','Class Print Status',$#students+1); my $student_counter=-1; foreach my $person (@students) { @@ -1015,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'}; @@ -1034,12 +1049,7 @@ ENDPART if ($urlp=~/\//) { my %form; $form{'grade_target'}='tex'; - if ($helper->{'VARS'}->{'pagesize.width'}=~/\d+/ && - $helper->{'VARS'}->{'pagesize.widthunit'}=~/\w+/) { - $form{'textwidth'}=&recalcto_mm($helper->{'VARS'}->{'pagesize.width'}.' '.$helper->{'VARS'}->{'pagesize.widthunit'}); - } else { - $form{'textwidth'}=$LaTeXwidth; - } + $form{'textwidth'}=&get_textwidth($helper,$LaTeXwidth); $form{'rndseed'}=$rndseed; if ($urlp =~ m|/home/([^/]+)/public_html|) { $urlp =~ s|/home/([^/]*)/public_html|/~$1|; @@ -1181,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'); @@ -1337,7 +1371,8 @@ sub printHelper { my $helper = Apache::lonhelper::helper->new("Printing Helper"); $helper->declareVar('symb'); $helper->declareVar('postdata'); - $helper->declareVar('curseed'); + $helper->declareVar('curseed'); + $helper->declareVar('probstatus'); $helper->declareVar('filename'); $helper->declareVar('construction'); $helper->declareVar('assignment'); @@ -1397,6 +1432,9 @@ sub printHelper { if (!$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 $userPriviledged = ($ENV{'request.role'}=~m/^cc\./ or @@ -1434,10 +1472,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()'; @@ -1461,7 +1499,8 @@ sub printHelper { my $helperFragment = < (mark them then click "next" button)
- + PAGESIZE return $isProblem; $map @@ -1471,7 +1510,8 @@ sub printHelper { (mark them then click "next" button)
- + PAGESIZE return $isNotMap; $map @@ -1490,11 +1530,11 @@ HELPERFRAGMENT &Apache::lonxml::xmlparse($r, 'helper', < (mark them then click "next" button)
- + PAGESIZE return $isProblemOrMap; - return $isProblem; + return $isNotMap; return $symbFilter;
@@ -1502,11 +1542,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; @@ -1530,8 +1571,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 @@ -1540,13 +1589,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; @@ -1624,7 +1674,8 @@ CHOOSE_FROM_SUBDIR (mark desired resources then click "next" button)
- + PAGESIZE return $isProblem return '$escapedSequenceName'; @@ -1657,7 +1708,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; @@ -1709,7 +1762,7 @@ CHOOSE_FROM_ANY_SEQUENCE if ($helper->{'VARS'}->{'construction'}) { my $stylevalue=$ENV{'construct.style'}; my $xmlfrag .= <<"RNDSEED"; - Use random seed: + Use random seed: return $helper->{VARS}->{'curseed'};