--- loncom/homework/structuretags.pm 2005/06/03 18:17:57 1.292
+++ loncom/homework/structuretags.pm 2005/11/08 21:09:08 1.318
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: structuretags.pm,v 1.292 2005/06/03 18:17:57 raeburn Exp $
+# $Id: structuretags.pm,v 1.318 2005/11/08 21:09:08 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -74,8 +74,7 @@ sub body_tag_start {
'onunload="'.&Apache::lonmenu::unloadevents().'" ';
if ($env{'browser.imagesuppress'} eq 'on') { $background=''; }
if ($background) {
- $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
- $background;
+ &Apache::lonxml::extlink($background);
$body_tag_start.='background="'.$background.'" ';
} else {
if (($bgcolor) && ($env{'browser.blackwhite'} ne 'on')) {
@@ -88,11 +87,10 @@ sub body_tag_start {
$body_tag_start.=' style="font-size: x-large;" ';
}
$body_tag_start.='>'.&Apache::lonmenu::menubuttons(undef,$target,1);
+
+ &Apache::lontexconvert::jsMath_reset();
if ($env{'environment.texengine'} eq 'jsMath') {
- $body_tag_start.=''."\n".
- ''."\n";
+ $body_tag_start.=&Apache::lontexconvert::jsMath_header();
}
return $body_tag_start;
}
@@ -117,16 +115,24 @@ sub page_start {
&Apache::lonxml::fontsettings();
}
my $body_tag_start;
- if (!defined($found{'body'}) && $env{'request.state'} eq 'construct'
- && $env{'environment.remote'} eq 'off') {
- $body_tag_start=&Apache::loncommon::bodytag();
- $body_tag_start.=&Apache::lonxml::message_location();
+ if (!defined($found{'body'}) && $env{'request.state'} eq 'construct') {
+ if ($env{'environment.remote'} eq 'off') {
+ if ($target eq 'web' || $target eq 'edit') {
+ $body_tag_start=&Apache::loncommon::bodytag();
+ $body_tag_start.=&Apache::lonxml::message_location();
+ }
+ } else {
+ if ($target eq 'web' || $target eq 'edit') {
+ $body_tag_start=&Apache::loncommon::bodytag(undef,undef,undef,1);
+ $body_tag_start.=&Apache::lonxml::message_location();
+ }
+ }
} elsif (!defined($found{'body'})) {
my $background=&Apache::lonxml::get_param('background',$parstack,
$safeeval);
my $bgcolor=&Apache::lonxml::get_param('bgcolor',$parstack,
$safeeval);
- $body_tag_start=&body_tag_start($background,$bgcolor);
+ $body_tag_start=&body_tag_start($target,$background,$bgcolor);
if ( ($target eq 'web' || $target eq 'webgrade')
&& $env{'request.state'} ne 'construct') {
my ($symb,undef,undef,undef,$publicuser)=
@@ -175,6 +181,8 @@ sub setup_rndseed {
my ($symb)=&Apache::lonxml::whichuser();
if ($env{'request.state'} eq "construct" || $symb eq '' ||
$Apache::lonhomework::history{'resource.CODE'}) {
+ &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
+ ['rndseed']);
$rndseed=$env{'form.rndseed'};
if (!$rndseed) {
$rndseed=$Apache::lonhomework::history{'rndseed'};
@@ -192,7 +200,7 @@ sub setup_rndseed {
delete($env{'form.newrandomization'});
}
if (defined($rndseed) && $rndseed ne int($rndseed)) {
- $rndseed=join(',',&Math::Random::random_seed_from_phrase($rndseed));
+ $rndseed=join(':',&Apache::lonnet::digest($rndseed));
}
if ($Apache::lonhomework::history{'resource.CODE'}) {
$rndseed=&Apache::lonnet::rndseed();
@@ -245,9 +253,11 @@ sub option {
sub problem_web_to_edit_header {
my ($rndseed)=@_;
- my $result.='
-
-
+ my $result.='';
+ if (!$Apache::lonhomework::parsing_a_task) {
+ $result .= '';
+ }
+ $result .= '
@@ -255,11 +265,17 @@ sub problem_web_to_edit_header {
$rndseed.'"
onchange="javascript:document.lonhomework.changerandseed.click()" />
';
- $result.="
+ if (!$Apache::lonhomework::parsing_a_task) {
+ $result.="
Problem Status:
";
- my $numtoanalyze=$env{'form.numtoanalyze'};
- if (!$numtoanalyze) { $numtoanalyze=20; }
- $result.= ' for
+ my $numtoanalyze=$env{'form.numtoanalyze'};
+ if (!$numtoanalyze) { $numtoanalyze=20; }
+ $result.= ' for
'.&mt('versions of this problem').
'.'.&Apache::loncommon::help_open_topic("Analyze_Problem",
'',undef,undef,300).
'';
+ }
return $result;
}
@@ -373,9 +390,9 @@ sub store_aggregates {
if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) {
$aggregate{$symb."\0".$part."\0users"} = 1;
} else {
- my $last_reset = &get_last_reset($symb,$cdomain,$cname,$part);
+ my (undef,$last_reset) = &Apache::grades::get_last_resets($symb,$env{'request.course.id'},[$part]);
if ($last_reset) {
- if (&get_num_tries($last_reset,$part) == 0) {
+ if (&Apache::grades::get_num_tries(\%Apache::lonhomework::history,$last_reset,$part) == 0) {
$aggregate{$symb."\0".$part."\0users"} = 1;
}
}
@@ -388,43 +405,6 @@ sub store_aggregates {
}
}
-# ----------- Timestamp of last reset of aggregates
-sub get_last_reset {
- my ($symb,$cdomain,$cname,$part) =@_;
- my $last_reset = '';
- my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',$cdomain,$cname);
- if ($resethash{'version'}) {
- for (my $version=$resethash{'version'};$version>=1;$version--) {
- if (exists($resethash{$version.':'.$part."\0".'prev_attempts'})) {
- $last_reset = $resethash{$version.':timestamp'};
- last;
- }
- }
- }
- return $last_reset;
-}
-
-# ----------- Provides number of tries since last reset of aggregates
-sub get_num_tries {
- my ($last_reset,$part) = @_;
- my $timestamp = '';
- my $num_tries = 0;
- if ($Apache::lonhomework::history{'version'}) {
- for (my $version=$Apache::lonhomework::history{'version'};$version>=1;$version--) {
- if (exists($Apache::lonhomework::history{$version.':resource.'.$part.'.solved'})) {
- $timestamp = $Apache::lonhomework::history{$version.':timestamp'};
- if ($timestamp > $last_reset) {
- $num_tries ++;
- } else {
- last;
- }
- }
- }
- }
- return $num_tries;
-}
-
-
sub checkout_msg {
my %lt=&Apache::lonlocal::texthash(
'resource'=>'The resource needs to be checked out',
@@ -462,16 +442,26 @@ ENDCHECKOUT
sub init_problem_globals {
my ($type)=@_;
#initialize globals
+ # For problems, we start out in part 0 (outside a tag).
+ # and part 0 is used to describe the main body of the
+ #
if ($type eq 'problem') {
$Apache::inputtags::part='0';
@Apache::inputtags::partlist=('0');
$Apache::lonhomework::problemstatus=&get_problem_status('0');
$Apache::lonhomework::ignore_response_errors=0;
+
} elsif ($type eq 'library') {
$Apache::inputtags::part='';
@Apache::inputtags::partlist=();
$Apache::lonhomework::problemstatus='';
$Apache::lonhomework::ignore_response_errors=1;
+
+ } elsif ($type eq 'Task') {
+ $Apache::inputtags::part='0';
+ @Apache::inputtags::partlist=('0');
+ $Apache::lonhomework::problemstatus='';
+ $Apache::lonhomework::ignore_response_errors=1;
}
@Apache::inputtags::responselist = ();
@Apache::inputtags::importlist = ();
@@ -522,6 +512,12 @@ sub get_problem_status {
sub start_problem {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ # We'll use the redirection to fix up printing of duedates.
+ &Apache::lonxml::startredirection();
+
+ # Problems don't nest and we don't allow more than one in
+ # a .problem file.
+ #
if ( $Apache::inputtags::part ne '' ||
$Apache::lonhomework::parsing_a_problem) {
&Apache::lonxml::error('Only one <problem> allowed in a .problem file');
@@ -559,6 +555,7 @@ sub start_problem {
&Apache::lonxml::debug("Using default type, problem, :$uri:");
}
}
+ $Apache::lonhomework::default_type = $Apache::lonhomework::type;
#added vars to the scripting enviroment
my $expression='$external::part=\''.$Apache::inputtags::part.'\';';
@@ -601,11 +598,12 @@ sub start_problem {
value="'.$env{'form.username'}.'" />';
if ($env{'user.adv'}) {
$form_tag_start.=
- ' '.&mt(' Show All Foils');
+ $form_tag_start.= ' />'.&mt(' Show All Foils').
+ '';
}
$form_tag_start.='';
}
@@ -679,27 +677,45 @@ sub start_problem {
}
my $maxtries = &Apache::lonnet::EXT("resource.$id.maxtries");
if (defined($maxtries) && $maxtries < 0) { $allow_print_points=0; }
- my $duedate = &Apache::lonnet::EXT("resource.$id.duedate");
- $duedate = POSIX::strftime("%c",localtime($duedate));
+ 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);
- } else {
- $temp_file = Apache::File->new('>>'.$filename);
- }
- my @due_file_content = <$temp_file>;
- my $due_file_content = $due_file_content[$#due_file_content];
- chomp $due_file_content;
- my $name_of_resourse= &Apache::lonxml::latex_special_symbols(&get_resource_name($parstack,$safeeval),'header');
- if ($due_file_content ne $duedate) {
+ 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 "$duedate\n";
+ 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{document} \typeout{STAMPOFPASSEDRESOURCESTART Resource