--- loncom/homework/bridgetask.pm 2006/06/20 03:33:55 1.174 +++ loncom/homework/bridgetask.pm 2006/11/06 17:50:17 1.184.2.4 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.174 2006/06/20 03:33:55 albertel Exp $ +# $Id: bridgetask.pm,v 1.184.2.4 2006/11/06 17:50:17 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,14 +43,14 @@ use LONCAPA; BEGIN { - &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','ClosingParagraph')); + &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','GraderNote','ClosingParagraph')); } my %dimension; sub initialize_bridgetask { # id of current Dimension, 0 means that no dimension is current # (inside only) - %Apache::bridgetask::dimension=(); + @Apache::bridgetask::dimension=(); # list of all Dimension ids seen %Apache::bridgetask::top_dimensionlist=(); # list of all current Instance ids @@ -83,12 +83,7 @@ sub proctor_check_auth { } } if ($authenticated) { - my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); - if ( $useslots eq 'map_map') { - &checkin_resource($user,$domain,$slot_name); - } else { - &create_new_version($type,$user,$domain,$slot_name); - } + &check_in($type,$user,$domain,$slot_name); return 1; } } @@ -112,7 +107,8 @@ sub check_in_sequence { my $navmap = Apache::lonnavmaps::navmap->new(); my ($symb) = &Apache::lonxml::whichuser(); my ($map) = &Apache::lonnet::decode_symb($symb); - my @resources = $navmap->retrieveResources($map,undef,1,0); + my @resources = + $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0); my %old_history = %Apache::lonhomework::history; my %old_results = %Apache::lonhomework::results; @@ -148,7 +144,7 @@ sub create_new_version { #setup new version and who did it $Apache::lonhomework::results{'resource.0.version'}=$version; $id = "$version.0"; - if (!defined($user) || defined($domain)) { + if (!defined($user) || !defined($domain)) { $user = $env{'user.name'}; $domain = $env{'user.domain'}; } @@ -156,11 +152,14 @@ sub create_new_version { } elsif ($type eq 'problem') { &Apache::lonxml::debug("authed $slot_name"); } - - if (defined($user) && defined($domain)) { - $Apache::lonhomework::results{"resource.$id.checkedin"}= - $user.':'.$domain; + if (!defined($user) || !defined($domain)) { + $user = $env{'user.name'}; + $domain = $env{'user.domain'}; } + + $Apache::lonhomework::results{"resource.$id.checkedin"}= + $user.':'.$domain; + if (defined($slot_name)) { $Apache::lonhomework::results{"resource.$id.checkedin.slot"}= $slot_name; @@ -327,9 +326,22 @@ sub style { my ($target) = @_; if ($target eq 'web' || $target eq 'webgrade') { - return (< STYLE + if ($env{'browser.type'} eq 'explorer' + && $env{'browser.os'} eq 'win' ) { + if ($env{'browser.version'} < 7) { + $style .= (< +STYLE + } else { + $style .= (< +STYLE + } + } + return $style; } return; } @@ -376,6 +388,8 @@ sub nested_parse { @Apache::scripttag::parser_env = @old_env; if ($args->{'delayed_dim_results'}) { my $dim = &get_dim_id(); + &Apache::lonxml::debug(" tossing out $result "); + &Apache::lonxml::debug(" usining out $dim 's ". $dimension{$dim}{'result'}); return $dimension{$dim}{'result'}; } return $result; @@ -391,8 +405,10 @@ sub submission_time_stamp { my $submissiontime; my $version=$Apache::lonhomework::history{'resource.0.version'}; for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) { - if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) { + if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'}) + && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) { $submissiontime=$Apache::lonhomework::history{$v.':timestamp'}; + last; } } my $result; @@ -403,16 +419,18 @@ sub submission_time_stamp { my ($color,$when)=('#FF6666','after'); if ($diff > 0) { ($color,$when)=('#336600','before'); } my $info; + $diff = abs($diff); if ($diff%60) { $info=($diff%60).' seconds'; } $diff=int($diff/60); if ($diff%60) { $info=($diff%60).' minutes '.$info; } $diff=int($diff/60); if ($diff) { $info=$diff.' hours '.$info; } $result='

'. - &mt('Student submitted [_1] [_2] the deadline. - (Submission was at [_3], end of period was [_4].)', - $info,$when,scalar(localtime($submissiontime)), - scalar(localtime($slot{'endtime'}))). + &mt('Student submitted [_1] [_2] the deadline. '. + '(Submission was at [_3], end of period was [_4].)', + $info,$when, + &Apache::lonlocal::locallocaltime($submissiontime), + &Apache::lonlocal::locallocaltime($slot{'endtime'})). '

'; } return $result; @@ -534,8 +552,8 @@ sub start_Task { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my ($status,$accessmsg,$slot); + &Apache::structuretags::init_problem_globals('Task'); if ($target ne 'webgrade') { - &Apache::structuretags::init_problem_globals('Task'); &Apache::structuretags::initialize_storage(); &Apache::lonhomework::showhash(%Apache::lonhomework::history); if ($env{'request.state'} eq 'construct') { @@ -598,7 +616,7 @@ sub start_Task { ($status,$accessmsg,my $slot_name,$slot) = &Apache::lonhomework::check_slot_access('0','Task'); if ($status eq 'CAN_ANSWER' && $version eq '') { - # CAN_ANSWR mode, and no current version, unproctored access + # CAN_ANSWER mode, and no current version, unproctored access # thus self-checkedin &check_in('Task',undef,undef,$slot_name); &add_to_queue('gradingqueue',{'type' => 'Task', @@ -1062,6 +1080,17 @@ DONEBUTTON &Apache::loncommon::end_page({'discussion' => 1}); } } + + my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); + my %queue_data = ('type' => 'Task', + 'time' => time,); + if (defined($Apache::inputtags::slot_name)) { + $queue_data{'slot'} = $Apache::inputtags::slot_name; + } elsif (defined($Apache::lonhomework::history{"resource.$version.0.checkedin.slot"})) { + $queue_data{'slot'} = $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"}; + } + + if ($target eq 'grade' && !$env{'form.webgrade'} && !$previous) { my $award='SUBMITTED'; &Apache::essayresponse::file_submission("$version.0",'bridgetask', @@ -1084,20 +1113,8 @@ DONEBUTTON &Apache::lonhomework::showhash(%Apache::lonhomework::results); &Apache::structuretags::finalize_storage(); if ($award eq 'SUBMITTED') { - my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); - if ($useslots =~ /^\s*no\s*$/i) { - &add_to_queue('gradingqueue', - {'type' => 'Task', - 'time' => time}); - } elsif (defined($Apache::inputtags::slot_name)) { - &add_to_queue('gradingqueue', - {'type' => 'Task', - 'time' => time, - 'slot' => $Apache::inputtags::slot_name}); - } + &add_to_queue('gradingqueue',\%queue_data); } - } elsif ($Apache::lonhomework::results{'INTERNAL_store'}) { - &Apache::structuretags::finalize_storage(); } if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes' && exists($env{'form.cancel'})) { @@ -1138,28 +1155,13 @@ DONEBUTTON $env{'user.name'}.':'.$env{'user.domain'}; if ($review) { $Apache::lonhomework::results{"resource.$version.0.status"}='review'; - if ($env{'form.queue'} eq 'reviewqueue') { - &check_queue_unlock($env{'form.queue'}); - &Apache::lonxml::debug(" still needs review not changing status."); - } else { - &move_between_queues($env{'form.queue'},'reviewqueue'); - } } elsif ($ungraded) { $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded'; - if ($env{'form.queue'} eq 'reviewqueue' || - $env{'form.queue'} eq 'none' ) { - &Apache::lonxml::debug("moving back."); - &move_between_queues($env{'form.queue'},'gradingqueue'); - } else { - &check_queue_unlock($env{'form.queue'}); - } } elsif ($mandatory_failed) { $Apache::lonhomework::results{"resource.$version.0.status"}='fail'; $Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override'; $Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT'; $Apache::lonhomework::results{"resource.$version.0.awarded"}='0'; - &remove_from_queue($env{'form.queue'}); - my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser(); if ($env{'form.regrade'} ne 'yes') { @@ -1176,8 +1178,6 @@ DONEBUTTON $Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override'; $Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS'; $Apache::lonhomework::results{"resource.$version.0.awarded"}='1'; - &remove_from_queue($env{'form.queue'}); - my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser(); if ($env{'form.regrade'} ne 'yes') { $Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"}= @@ -1201,6 +1201,38 @@ DONEBUTTON } &minimize_storage(); &Apache::structuretags::finalize_storage(); + + # data stored, now handle queue + if ($review) { + if ($env{'form.queue'} eq 'reviewqueue') { + &check_queue_unlock($env{'form.queue'}); + &Apache::lonxml::debug(" still needs review not changing status."); + } else { + if ($env{'form.queue'} ne 'none') { + &move_between_queues($env{'form.queue'},'reviewqueue'); + } else { + &add_to_queue('reviewqueue',\%queue_data); + } + } + } elsif ($ungraded) { + if ($env{'form.queue'} eq 'reviewqueue') { + &Apache::lonxml::debug("moving back."); + &move_between_queues($env{'form.queue'}, + 'gradingqueue'); + } elsif ($env{'form.queue'} eq 'none' ) { + &add_to_queue('gradingqueue',\%queue_data); + } else { + &check_queue_unlock($env{'form.queue'}); + } + } elsif ($mandatory_failed) { + &remove_from_queue($env{'form.queue'}); + } else { + &remove_from_queue($env{'form.queue'}); + } + } + if (exists($Apache::lonhomework::results{'INTERNAL_store'})) { + # instance generation occured and hasn't yet been stored + &Apache::structuretags::finalize_storage(); } } elsif ($target eq 'webgrade') { $result.=""; @@ -1224,7 +1256,12 @@ DONEBUTTON 'Partial Credit Factor'); $result.=&Apache::response::meta_stores_write('status','string', 'Bridge Task Status'); + } elsif ($target eq 'edit') { + &Apache::structuretags::reset_problem_globals('Task'); + undef($Apache::lonhomework::parsing_a_task); + return ('','no'); } + &Apache::structuretags::reset_problem_globals('Task'); undef($Apache::lonhomework::parsing_a_task); return $result; } @@ -1544,7 +1581,6 @@ sub get_queue_counts { foreach my $key (sort(keys(%queue))) { my ($symb,$uname,$udom) = &decode_queue_key($key); if (!defined($classlist->{$uname.':'.$udom})) { next; } - if ($key=~/locked$/) { $locks++; } elsif ($key=~/timestamp$/) { @@ -2141,7 +2177,7 @@ sub get_criteria { } else { my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"}; my $mandatory='Mandatory'; - if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') { + if (&Apache::lonxml::get_param('Mandatory',$parstack,$safeeval) eq 'N') { $mandatory='Optional'; } my $dim_info="
\n"; @@ -2188,33 +2224,6 @@ sub get_criteria { $result.=$dimension{$id}{'result'}; next; } - my $status= &get_criteria('status', $version,$dim,$id); - my $comment=&get_criteria('comment',$version,$dim,$id); - my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N'); - if ($mandatory) { - $mandatory='Mandatory'; - } else { - $mandatory='Optional'; - } - if ($status eq 'fail') { - } elsif ($status eq 'pass') { - } else { - &Apache::lonxml::error("Student viewing a graded bridgetask was shown a status of $status"); - } - my $status_display=$status; - $status_display=~s/^([a-z])/uc($1)/e; - $result.= - '

' - .$mandatory.' Criteria

'; - $result.= - &nested_parse(\$dimension{$dim}{'criteria.'.$id}, - [@_],{'set_dim_id' => $id}); - $result.='

'.$status_display.'

'; - if ($comment) { - $result.='

'. - &mt('Comment: [_1]',$comment).'

'; - } - $result.='
'; } } } @@ -2224,8 +2233,8 @@ sub get_criteria { &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]); $result.= &nested_parse(\$dimension{$dim}{'questiontext'},[@_], - {'set_dim_id' => undef, - 'delay_dim_results' => 1}); + {'set_dim_id' => undef, + 'delayed_dim_results' => 1}); foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}}, @{$dimension{$dim}{'criterias'}} ) { my $type = $dimension{$dim}{'criteria.'.$id.'.type'}; @@ -2262,7 +2271,7 @@ sub get_criteria { $result.=&grading_history($version,$dim,$id); $last_link=$link; } - if (&delay_result()) { + if (&nest()) { &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'}); $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result; undef($result); @@ -2472,6 +2481,7 @@ sub end_InstanceText { sub start_Criteria { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; my $criteria=&Apache::lonxml::get_all_text('/criteria',$parser,$style); + my $result = ''; if ($target eq 'web' || $target eq 'webgrade' || $target eq 'grade') { my $dim = &get_dim_id(); my $id=&get_id($parstack,$safeeval); @@ -2489,14 +2499,64 @@ sub start_Criteria { $dimension{$dim}{'criteria.'.$id.'.mandatory'}= &Apache::lonxml::get_param('Mandatory',$parstack,$safeeval); push(@{$dimension{$dim}{'criterias'}},$id); + + my $version=&get_version(); + my $task_status = + $Apache::lonhomework::history{"resource.$version.0.status"}; + if ($target eq 'web' + && ($task_status eq 'pass' || $task_status eq 'fail')) { + my $status= &get_criteria('status', $version,$dim,$id); + my $comment=&get_criteria('comment',$version,$dim,$id); + my $mandatory=($dimension{$dim}{'criteria.'.$id.'.mandatory'} ne 'N'); + if ($mandatory) { + $mandatory='Mandatory'; + } else { + $mandatory='Optional'; + } + my $status_display=$status; + $status_display=~s/^([a-z])/uc($1)/e; + $result.= + '

' + .$mandatory.' Criteria

'; + $result.= + &nested_parse(\$dimension{$dim}{'criteria.'.$id},[@_]); + $result.='

'.$status_display.'

'; + if ($comment =~ /\w/) { + $result.='

'. + &mt('Comment: [_1]',$comment).'

'; + } + $result.='
'; + } } } - return ''; + return $result; } sub end_Criteria { } +sub start_GraderNote { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + + if ($target eq 'webgrade') { + return '
'. + &mt('Note to graders:').''; + } + my $note=&Apache::lonxml::get_all_text('/gradernote',$parser,$style); + return; +} + +sub end_GraderNote { + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; + + if ($target eq 'webgrade') { + return '
'; + } + return; +} + + + sub proctor_validation_screen { my ($slot) = @_; my (undef,undef,$domain,$user) = &Apache::lonxml::whichuser();