--- loncom/homework/structuretags.pm 2005/11/08 21:09:08 1.318 +++ loncom/homework/structuretags.pm 2005/11/09 12:04:23 1.319 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.318 2005/11/08 21:09:08 albertel Exp $ +# $Id: structuretags.pm,v 1.319 2005/11/09 12:04:23 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -661,74 +661,8 @@ sub start_problem { } } } elsif ($target eq 'tex') { - my $startminipage = ''; - if (not $env{'form.problem_split'}=~/yes/) { - $startminipage = '\begin{minipage}{\textwidth}'; - } - my $id = $Apache::inputtags::part; - my $weight = &Apache::lonnet::EXT("resource.$id.weight"); - my $packages=&Apache::lonnet::metadata($env{'request.uri'},'packages'); - my @packages = split /,/,$packages; - my $allow_print_points = 0; - foreach my $partial_key (@packages) { - if ($partial_key=~m/^part_0$/) { - $allow_print_points=1; - } - } - my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); - if (defined($maxtries) && $maxtries < 0) { $allow_print_points=0; } - if (lc($env{'course.'.$env{'request.course.id'}. - '.disableexampointprint'}) eq 'yes') { - $allow_print_points=0; - } - my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header'); - my $begin_doc='\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource

"'.$name_of_resourse.'"

located in
'.$env{'request.uri'}.'
STAMPOFPASSEDRESOURCEEND} \noindent '; - my $toc_line='\vskip 1 mm\noindent '.$startminipage. - '\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}'; - - # Figure out what the due date is and if we need to print - # it in the problem header. We have been logging the - # last due date written to file. - - my $duetime = &Apache::lonnet::EXT("resource.$id.duedate"); - my $duedate = POSIX::strftime("%c",localtime($duetime)); - my $temp_file; - my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due"; - - # Figure out what the last printed due date is or set it - # to the epoch if no duedates have been printed. - - my $due_file_content = 0; # If the file does not yet exist, time is the epoch. - if (-e $filename) { - $temp_file = Apache::File->new($filename); - my @due_file = <$temp_file>; - $due_file_content = $due_file[$#due_file]; - chomp $due_file_content; - } - - # comparisons of the absolute times - if ($due_file_content != $duetime) { - $temp_file = Apache::File->new('>'.$filename); - print $temp_file "$duetime\n"; - if (not $env{'request.symb'} =~ m/\.page_/) { - if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') { - $result .= $begin_doc. - '\textit{Due date: '.$duedate.'} '.$toc_line; - } else { - $result .= $begin_doc.$toc_line; - if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $result .= '\fbox{\textit{'.$weight.' pt}}';} - } - } else { - $result .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\'; - } - } else { - if (not $env{'request.symb'} =~ m/\.page_/) { - $result .= $begin_doc.$toc_line; - if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $result .= '\fbox{\textit{'.$weight.' pt}}';} - } else { - $result .= '\vskip 1mm \\\\\\\\'; - } - } + $result .= 'INSERTTEXFRONTMATTERHERE'; + } } elsif ($target eq 'edit') { $result.=$head_tag_start."".$body_tag_start.$form_tag_start. @@ -751,6 +685,94 @@ sub end_problem { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; my $result= &Apache::lonxml::endredirection(); # started in &start_problem + # Figure out the front matter which was too deeply coupled for me to easily + # unravel and replace the INSERTTEXFRONTMATTERHERE in result with it. + # note that we do this in end_problem because whether or not we display + # due dates depends on whether due dates have already been displayed in the problem parts. + + if ($target eq 'tex') { + my $frontmatter = ''; + my $startminipage = ''; + if (not $env{'form.problem_split'}=~/yes/) { + $startminipage = '\begin{minipage}{\textwidth}'; + } + my $id = $Apache::inputtags::part; + my $weight = &Apache::lonnet::EXT("resource.$id.weight"); + my $packages=&Apache::lonnet::metadata($env{'request.uri'},'packages'); + my @packages = split /,/,$packages; + my $allow_print_points = 0; + foreach my $partial_key (@packages) { + if ($partial_key=~m/^part_0$/) { + $allow_print_points=1; + } + } + my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries"); + if (defined($maxtries) && $maxtries < 0) { $allow_print_points=0; } + if (lc($env{'course.'.$env{'request.course.id'}. + '.disableexampointprint'}) eq 'yes') { + $allow_print_points=0; + } + my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header'); + my $begin_doc='\begin{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource

"'.$name_of_resourse.'"

located in
'.$env{'request.uri'}.'
STAMPOFPASSEDRESOURCEEND} \noindent '; + my $toc_line='\vskip 1 mm\noindent '.$startminipage. + '\addcontentsline{toc}{subsection}{'.$name_of_resourse.'}'; + + # Figure out what the due date is and if we need to print + # it in the problem header. We have been logging the + # last due date written to file. + + my $duetime = &Apache::lonnet::EXT("resource.$id.duedate"); + my $duedate = POSIX::strftime("%c",localtime($duetime)); + my $temp_file; + my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.due"; + + # Figure out what the last printed due date is or set it + # to the epoch if no duedates have been printed. + + my $due_file_content = 0; # If the file does not yet exist, time is the epoch. + if (-e $filename) { + $temp_file = Apache::File->new($filename); + my @due_file = <$temp_file>; + $due_file_content = $due_file[$#due_file]; + chomp $due_file_content; + } + + # We display the due date iff it is not the same as the last + # duedate in problem header ($due_file_content), and + # none of our parts displayed a duedate. + # + my $parts_with_displayduedate; + if (defined $Apache::outputtags::showonce{'displayduedate'}) { + $parts_with_displayduedate = + scalar(@{$Apache::outputtags::showonce{'displayduedate'}}); + } else { + $parts_with_displayduedate = 0; + } + if (($due_file_content != $duetime) && ($parts_with_displayduedate == 0) ) { + $temp_file = Apache::File->new('>'.$filename); + print $temp_file "$duetime\n"; + if (not $env{'request.symb'} =~ m/\.page_/) { + if(not $duedate=~m/1969/ and $Apache::lonhomework::type ne 'exam') { + $frontmatter .= $begin_doc. + '\textit{Due date: '.$duedate.'} '.$toc_line; + } else { + $frontmatter.= $begin_doc.$toc_line; + if ($Apache::lonhomework::type eq 'exam' and $allow_print_points==1) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';} + } + } else { + $frontmatter .= '\vskip 1mm\textit{Due date: '.$duedate.'} \\\\\\\\'; + } + } else { + if (not $env{'request.symb'} =~ m/\.page_/) { + $frontmatter .= $begin_doc.$toc_line; + if (($Apache::lonhomework::type eq 'exam') and ($allow_print_points==1)) { $frontmatter .= '\fbox{\textit{'.$weight.' pt}}';} + } else { + $frontmatter .= '\vskip 1mm \\\\\\\\'; + } + } + $result =~ s/INSERTTEXFRONTMATTERHERE/$frontmatter/; + } + my $status=$Apache::inputtags::status['-1']; if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex') {