--- loncom/homework/lonhomework.pm 2004/12/20 17:24:10 1.189 +++ loncom/homework/lonhomework.pm 2005/01/31 21:57:32 1.196 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.189 2004/12/20 17:24:10 albertel Exp $ +# $Id: lonhomework.pm,v 1.196 2005/01/31 21:57:32 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -115,7 +115,8 @@ sub get_target { } else { return ('web','answer'); } - } elsif ( $ENV{'form.problemmode'} eq &mt('Edit') ) { + } elsif ( $ENV{'form.problemmode'} eq &mt('Edit') || + $ENV{'form.problemmode'} eq 'Edit') { if ( $ENV{'form.submitted'} eq 'edit' ) { if ( $ENV{'form.submit'} eq &mt('Submit Changes and View') ) { return ('modified','web','answer'); @@ -319,7 +320,7 @@ sub check_access { &Apache::lonxml::debug("looking for accesstime $first_access"); if (!$first_access) { $status='NOT_YET_VIEWED'; - $datemsg=' '.$interval.' seconds'; + $datemsg=&seconds_to_human_length($interval); } else { my $newdate=localtime($first_access+$interval); if (time > ($first_access+$interval)) { @@ -347,6 +348,25 @@ sub check_access { return ($status,$datemsg); } +sub seconds_to_human_length { + my ($length)=@_; + + my $seconds=$length%60; $length=int($length/60); + my $minutes=$length%60; $length=int($length/60); + my $hours=$length%24; $length=int($length/24); + my $days=$length; + + my $timestr; + if ($days > 0) { $timestr.=&mt('[quant,_1,day]',$days); } + if ($hours > 0) { $timestr.=($timestr?", ":""). + &mt('[quant,_1,hour]',$hours); } + if ($minutes > 0) { $timestr.=($timestr?", ":""). + &mt('[quant,_1,minute]',$minutes); } + if ($seconds > 0) { $timestr.=($timestr?", ":""). + &mt('[quant,_1,second]',$seconds); } + return $timestr; +} + sub showhash { my (%hash) = @_; &showhashsubset(\%hash,'.'); @@ -357,10 +377,11 @@ sub showarray { my ($array)=@_; my $string="("; foreach my $elm (@{ $array }) { - if (ref($elm)) { - if ($elm =~ /ARRAY/ ) { - $string.=&showarray($elm); - } + if (ref($elm) eq 'ARRAY') { + $string.=&showarray($elm); + } elsif (ref($elm) eq 'HASH') { + $string.= "HASH --- \n
"; + $string.= &showhashsubset($elm,'.'); } else { $string.="$elm," } @@ -374,20 +395,15 @@ sub showhashsubset { my ($hash,$keyre) = @_; my $resultkey; foreach $resultkey (sort keys %$hash) { - if ($resultkey =~ /$keyre/) { - if (ref($$hash{$resultkey})) { - if ($$hash{$resultkey} =~ /ARRAY/ ) { - &Apache::lonxml::debug("$resultkey ---- ". - &showarray($$hash{$resultkey})); - } elsif ($$hash{$resultkey} =~ /HASH/ ) { - &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); - &showhashsubset($$hash{$resultkey},'.'); - } else { - &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); - } - } else { - &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); - } + if ($resultkey !~ /$keyre/) { next; } + if (ref($$hash{$resultkey}) eq 'ARRAY' ) { + &Apache::lonxml::debug("$resultkey ---- ". + &showarray($$hash{$resultkey})); + } elsif (ref($$hash{$resultkey}) eq 'HASH' ) { + &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); + &showhashsubset($$hash{$resultkey},'.'); + } else { + &Apache::lonxml::debug("$resultkey ---- $$hash{$resultkey}"); } } &Apache::lonxml::debug("\n
restored values^
\n"); @@ -423,6 +439,8 @@ sub setupheader { if (!$Apache::lonxml::debug && ($ENV{'REQUEST_METHOD'} eq 'GET')) { &Apache::loncommon::no_cache($request); } +# $request->set_last_modified(&Apache::lonnet::metadata($request->uri, +# 'lastrevisiondate')); $request->send_http_header; return OK if $request->header_only; return '' @@ -798,18 +816,14 @@ sub handler { $Apache::lonxml::debug=$ENV{'user.debug'}; $ENV{'request.uri'}=$request->uri; &setuppermissions(); - &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:"); # some times multiple problemmodes are submitted, need to select # the last one - &Apache::lonxml::debug("Problem Mode ".$ENV{'form.problemmode'}); - if ( defined($ENV{'form.problemmode'}) && - ref($ENV{'form.problemmode'}) ) { - &Apache::lonxml::debug("Problem Mode ".join(",",@$ENV{'form.problemmode'})); + if ( defined($ENV{'form.problemmode'}) && ref($ENV{'form.problemmode'}) ) { my $mode=$ENV{'form.problemmode'}->[-1]; undef $ENV{'form.problemmode'}; $ENV{'form.problemmode'}=$mode; } - &Apache::lonxml::debug("Problem Mode ".$ENV{'form.problemmode'}); + my $file=&Apache::lonnet::filelocation("",$request->uri); #check if we know where we are @@ -821,11 +835,13 @@ sub handler { if ( &Apache::lonnet::mod_perl_version() == 2 ) { &Apache::lonnet::cleanenv(); } - $request->internal_redirect('/adm/ambiguous'); return; + &Apache::lonnet::logthis(&Apache::lonnet::mod_perl_version()); + $request->internal_redirect('/adm/ambiguous'); return OK; } } if (&setupheader($request)) { return OK; } - + &Apache::lonxml::debug("Permissions:$Apache::lonhomework::browse:$Apache::lonhomework::viewgrades:"); + &Apache::lonxml::debug("Problem Mode ".$ENV{'form.problemmode'}); my ($symb) = &Apache::lonxml::whichuser(); &Apache::lonxml::debug('symb is '.$symb); if ($ENV{'request.state'} eq "construct" || $symb eq '') { @@ -846,7 +862,8 @@ sub handler { #&view_or_edit_menu($request); $ENV{'form.problemmode'}='View'; &renderpage($request,$file); - } elsif ($ENV{'form.problemmode'} eq &mt('EditXML')) { + } elsif ($ENV{'form.problemmode'} eq &mt('EditXML') || + $ENV{'form.problemmode'} eq 'EditXML') { &editxmlmode($request,$file); } elsif ($ENV{'form.problemmode'} eq &mt('Calculate answers')) { &analyze($request,$file);