--- loncom/homework/lonhomework.pm 2007/10/31 17:40:00 1.281 +++ loncom/homework/lonhomework.pm 2007/12/24 06:35:18 1.287 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Homework handler # -# $Id: lonhomework.pm,v 1.281 2007/10/31 17:40:00 albertel Exp $ +# $Id: lonhomework.pm,v 1.287 2007/12/24 06:35:18 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -49,11 +49,11 @@ use Apache::matchresponse(); use Apache::chemresponse(); use Apache::drawimage(); use Apache::Constants qw(:common); -use HTML::Entities(); use Apache::loncommon(); use Apache::lonlocal; use Time::HiRes qw( gettimeofday tv_interval ); -use Apache::lonnet(); +use HTML::Entities(); +use File::Copy(); # FIXME - improve commenting @@ -494,19 +494,23 @@ sub check_access { $Apache::lonhomework::history{"resource.$id.solved"}=~/^excused/) { $status = 'CANNOT_ANSWER'; } + if ($status eq 'CANNOT_ANSWER' + && &show_answer_problem_status()) { + $status = 'SHOW_ANSWER'; + } } if ($status eq 'CAN_ANSWER' || $status eq 'CANNOT_ANSWER') { - my $interval=&Apache::lonnet::EXT("resource.$id.interval"); - &Apache::lonxml::debug("looking for interval $interval"); - if ($interval) { - my $first_access=&Apache::lonnet::get_first_access('map'); + my @interval=&Apache::lonnet::EXT("resource.$id.interval"); + &Apache::lonxml::debug("looking for interval @interval"); + if ($interval[0]) { + my $first_access=&Apache::lonnet::get_first_access($interval[1]); &Apache::lonxml::debug("looking for accesstime $first_access"); if (!$first_access) { $status='NOT_YET_VIEWED'; my $due_date = &due_date($id); my $seconds_left = $due_date - time; - if ($seconds_left > $interval || $due_date eq '') { - $seconds_left = $interval; + if ($seconds_left > $interval[0] || $due_date eq '') { + $seconds_left = $interval[0]; } $datemsg=&seconds_to_human_length($seconds_left); } @@ -532,18 +536,19 @@ sub check_access { sub due_date { my ($part_id,$symb,$udom,$uname)=@_; my $date; - my $interval= &Apache::lonnet::EXT("resource.$part_id.interval",$symb, + my @interval= &Apache::lonnet::EXT("resource.$part_id.interval",$symb, $udom,$uname); - &Apache::lonxml::debug("looking for interval $part_id $symb $interval"); + &Apache::lonxml::debug("looking for interval $part_id $symb @interval"); my $due_date= &Apache::lonnet::EXT("resource.$part_id.duedate",$symb, $udom,$uname); &Apache::lonxml::debug("looking for due_date $part_id $symb $due_date"); - if ($interval =~ /\d+/) { - my $first_access=&Apache::lonnet::get_first_access('map',$symb); - &Apache::lonxml::debug("looking for first_access $first_access"); + if ($interval[0] =~ /\d+/) { + my $first_access=&Apache::lonnet::get_first_access($interval[1],$symb); + &Apache::lonxml::debug("looking for first_access $first_access ($interval[1])"); if (defined($first_access)) { - $interval = $first_access+$interval; - $date = ($interval < $due_date)? $interval : $due_date; + my $interval = $first_access+$interval[0]; + $date = (!$due_date || $interval < $due_date) ? $interval + : $due_date; } else { $date = $due_date; } @@ -683,9 +688,9 @@ sub handle_save_or_undo { my $error=0; if ($env{'form.Undo'} eq &mt('undo')) { my $error=0; - if (!copy($file,$filetmp)) { $error=1; } - if ((!$error) && (!copy($filebak,$file))) { $error=1; } - if ((!$error) && (!move($filetmp,$filebak))) { $error=1; } + if (!&File::Copy::copy($file,$filetmp)) { $error=1; } + if ((!$error) && (!&File::Copy::copy($filebak,$file))) { $error=1; } + if ((!$error) && (!&File::Copy::move($filetmp,$filebak))) { $error=1; } if (!$error) { &Apache::lonxml::info("

". &mt("Undid changes, Switched [_1] and [_2]", @@ -882,6 +887,7 @@ sub analyze { sub show_problem_status { return ($show_problem_status eq 'yes' + || $show_problem_status eq 'answer' || $show_problem_status eq ''); } @@ -892,6 +898,10 @@ sub analyze { sub show_no_problem_status { return ($show_problem_status eq 'no_feedback_ever'); } + + sub show_answer_problem_status { + return ($show_problem_status eq 'answer'); + } } sub editxmlmode { @@ -1059,52 +1069,71 @@ sub finished_parsing { undef($Apache::lonhomework::parsing_a_task); } -# with no arg it returns a HTML

'; + $midpoint = int($numfiles/2); + if ($numfiles%2) { + $midpoint ++; + } + } + my $count = 0; + foreach my $file (@files) { + next if ($file->[1] !~ /\S/); + $result .= + '
'."\n"; + $count ++; + if ((!$seconddiv) && ($count >= $midpoint)) { + $result .= '
'."\n".'
'."\n"; + $seconddiv = 1; + } } - if (@allnames && !$result) { - $result="\n'; + if ($numfiles > 0) { + $result .= '
'."\n".''."\n"; } return $result; } sub newproblem { my ($request) = @_; - my $extension=$request->uri; - $extension=~s:^.*\.([\w]+)$:$1:; - &Apache::lonxml::debug("Looking for :$extension:"); - my $templatelist=&get_template_list('',$extension); - if ($env{'form.template'} && - $env{'form.template'} ne "Select a $extension template") { - use File::Copy; - my $file = &get_template_list($env{'form.template'},$extension); + + if ($env{'form.template'}) { + my $file = $env{'form.template'}; my $dest = &Apache::lonnet::filelocation("",$request->uri); - copy($file,$dest); + &File::Copy::copy($file,$dest); &renderpage($request,$dest); - } elsif($env{'form.newfile'} && !$templatelist) { - # I don't like hard-coded filenames but for now, this will work. - use File::Copy; + return; + } + + my ($extension) = ($request->uri =~ m/\.(\w+)$/); + &Apache::lonxml::debug("Looking for :$extension:"); + my $templatelist=&get_template_list($extension); + if ($env{'form.newfile'} && !$templatelist) { + # no templates found my $templatefilename = $request->dir_config('lonIncludes').'/templates/blank.'.$extension; &Apache::lonxml::debug("$templatefilename"); my $dest = &Apache::lonnet::filelocation("",$request->uri); - copy($templatefilename,$dest); + &File::Copy::copy($templatefilename,$dest); &renderpage($request,$dest); } else { my $url=&HTML::Entities::encode($request->uri,'<>&"'); @@ -1112,9 +1141,6 @@ sub newproblem { $shownurl=~s-^/~-/priv/-; my $dest = &Apache::lonnet::filelocation("",$request->uri); my $errormsg; - if ($env{'form.newfile'}) { - $errormsg='

'.&mt('You did not select a template.').'

'."\n"; - } my $instructions; my $start_page = &Apache::loncommon::start_page("Create New $extension"); @@ -1127,16 +1153,17 @@ $errormsg

".&mt("To create a new $extension, select a template from the". - "pull-down menu below. Then click on the \"Create $extension\" button.")." + " list below. Then click on the \"Create $extension\" button.")."

"); if (defined($templatelist)) { - $request->print(""); + $request->print($templatelist); } - $request->print("
"); + $request->print('
'); $request->print("

".&Apache::loncommon::end_page()); } - return ''; + return; } sub update_construct_style {