--- loncom/homework/lonhomework.pm 2004/12/17 22:30:30 1.187 +++ loncom/homework/lonhomework.pm 2005/01/11 19:38:53 1.192 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.187 2004/12/17 22:30:30 albertel Exp $ +# $Id: lonhomework.pm,v 1.192 2005/01/11 19:38:53 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,12 +53,31 @@ use HTML::Entities(); use Apache::loncommon(); use Apache::lonlocal; use Time::HiRes qw( gettimeofday tv_interval ); +use Apache::lonnet(); + +# FIXME - improve commenting + BEGIN { &Apache::lonxml::register_insert(); } + +# +# Decides what targets to render for. +# Implicit inputs: +# Various session environment variables: +# request.state - published - is a /res/ resource +# uploaded - is a /uploaded/ resource +# contruct - is a /priv/ resource +# form.grade_target - a form parameter requesting a specific target sub get_target { + &Apache::lonxml::debug("request.state = $ENV{'request.state'}"); + if( defined($ENV{'form.grade_target'})) { + &Apache::lonxml::debug("form.grade_target= $ENV{'form.grade_target'}"); + } else { + &Apache::lonxml::debug("form.grade_target "); + } if (($ENV{'request.state'} eq "published") || ($ENV{'request.state'} eq "uploaded")) { if ( defined($ENV{'form.grade_target'} ) @@ -96,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'); @@ -300,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)) { @@ -328,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,'.'); @@ -384,7 +423,7 @@ sub setuppermissions { $viewgrades = &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}. '/'.$ENV{'request.course.sec'}); } - $Apache::lonhomework::viewgrades = $viewgrades; + $Apache::lonhomework::viewgrades = $viewgrades; # File global variable...dirt. if ($Apache::lonhomework::browse eq 'F' && $ENV{'form.devalidatecourseresdata'} eq 'on') { my (undef,$courseid) = &Apache::lonxml::whichuser(); @@ -608,6 +647,9 @@ sub editxmlmode { return ''; } +# +# Render the page in whatever target desired. +# sub renderpage { my ($request,$file) = @_; @@ -799,7 +841,8 @@ 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; } @@ -824,7 +867,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);