--- loncom/homework/bridgetask.pm 2006/06/13 21:34:28 1.171 +++ loncom/homework/bridgetask.pm 2006/11/06 16:03:45 1.184.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.171 2006/06/13 21:34:28 albertel Exp $ +# $Id: bridgetask.pm,v 1.184.2.1 2006/11/06 16:03:45 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -50,7 +50,7 @@ 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,7 +83,7 @@ sub proctor_check_auth { } } if ($authenticated) { - &create_new_version($type,$user,$domain,$slot_name); + &check_in($type,$user,$domain,$slot_name); return 1; } } @@ -91,8 +91,43 @@ sub proctor_check_auth { return 0; } +sub check_in { + my ($type,$user,$domain,$slot_name) = @_; + my $useslots = &Apache::lonnet::EXT("resource.0.useslots"); + if ( $useslots eq 'map_map') { + &check_in_sequence($user,$domain,$slot_name); + } else { + &create_new_version($type,$user,$domain,$slot_name); + } + return 1; +} + +sub check_in_sequence { + my ($user,$domain,$slot_name) = @_; + my $navmap = Apache::lonnavmaps::navmap->new(); + my ($symb) = &Apache::lonxml::whichuser(); + my ($map) = &Apache::lonnet::decode_symb($symb); + my @resources = + $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0); + my %old_history = %Apache::lonhomework::history; + my %old_results = %Apache::lonhomework::results; + + foreach my $res (@resources) { + &Apache::lonxml::debug("doing ".$res->src); + &Apache::structuretags::initialize_storage($res->symb); + my $type = ($res->is_task()) ? 'Task' : 'problem'; + &create_new_version($type,$user,$domain,$slot_name); + &Apache::structuretags::finalize_storage($res->symb); + } + + %Apache::lonhomework::history = %old_history; + %Apache::lonhomework::results = %old_results; +} + sub create_new_version { my ($type,$user,$domain,$slot_name) = @_; + + my $id = '0'; if ($type eq 'Task') { # increment version my $version= @@ -107,28 +142,27 @@ sub create_new_version { } #setup new version and who did it - $Apache::lonhomework::results{'resource.0.version'}=$version; - if (defined($user) && defined($domain)) { - $Apache::lonhomework::results{"resource.$version.0.checkedin"}= - $user.':'.$domain; - } else { - $Apache::lonhomework::results{"resource.$version.0.checkedin"}= - $env{'user.name'}.':'.$env{'user.domain'}; - } - if (defined($slot_name)) { - $Apache::lonhomework::results{"resource.$version.0.checkedin.slot"}= - $slot_name; + $Apache::lonhomework::results{'resource.0.version'}=$version; + $id = "$version.0"; + if (!defined($user) || !defined($domain)) { + $user = $env{'user.name'}; + $domain = $env{'user.domain'}; } + } elsif ($type eq 'problem') { &Apache::lonxml::debug("authed $slot_name"); - if (defined($user) && defined($domain)) { - $Apache::lonhomework::results{"resource.0.checkedin"}= - $user.':'.$domain; - } - if (defined($slot_name)) { - $Apache::lonhomework::results{"resource.0.checkedin.slot"}= - $slot_name; - } + } + 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; } } @@ -316,6 +350,38 @@ sub show_task { return 1; } +my @delay; +sub nest { + if (@delay) { + return $delay[-1]; + } else { + return; + } +} + +sub nested_parse { + my ($str,$env,$args) = @_; + my @old_env = @Apache::scripttag::parser_env; + @Apache::scripttag::parser_env = @$env; + if (exists($args->{'set_dim_id'})) { + &enable_dimension_parsing($args->{'set_dim_id'}); + } + push(@delay,(($args->{'delayed_dim_results'})? 1 : 0)); + my $result = &Apache::scripttag::xmlparse($$str); + pop(@delay); + if (exists($args->{'set_dim_id'})) { + &disable_dimension_parsing(); + } + @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; +} + sub internal_location { my ($id)=@_; return ''; @@ -326,8 +392,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; @@ -338,16 +406,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; @@ -469,8 +539,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') { @@ -533,7 +603,9 @@ sub start_Task { ($status,$accessmsg,my $slot_name,$slot) = &Apache::lonhomework::check_slot_access('0','Task'); if ($status eq 'CAN_ANSWER' && $version eq '') { - &create_new_version('Task',undef,undef,$slot_name); + # 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', 'time' => time, 'slot' => $slot_name}); @@ -995,6 +1067,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', @@ -1017,20 +1100,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'})) { @@ -1075,14 +1146,20 @@ DONEBUTTON &check_queue_unlock($env{'form.queue'}); &Apache::lonxml::debug(" still needs review not changing status."); } else { - &move_between_queues($env{'form.queue'},'reviewqueue'); + if ($env{'form.queue'} ne 'none') { + &move_between_queues($env{'form.queue'},'reviewqueue'); + } else { + &add_to_queue('reviewqueue',\%queue_data); + } } } elsif ($ungraded) { $Apache::lonhomework::results{"resource.$version.0.status"}='ungraded'; - if ($env{'form.queue'} eq 'reviewqueue' || - $env{'form.queue'} eq 'none' ) { + if ($env{'form.queue'} eq 'reviewqueue') { &Apache::lonxml::debug("moving back."); - &move_between_queues($env{'form.queue'},'gradingqueue'); + &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'}); } @@ -1135,6 +1212,10 @@ DONEBUTTON &minimize_storage(); &Apache::structuretags::finalize_storage(); } + 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.=""; #$result.=' undef}); my $task_status = $Apache::lonhomework::history{"resource.$version.0.status"}; - if ($task_status eq 'pass' || $task_status eq 'fail') { + if ($task_status ne 'pass' && $task_status ne 'fail') { + foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}}, + @{$dimension{$dim}{'criterias'}}) { + my $type = $dimension{$dim}{'criteria.'.$id.'.type'}; + &Apache::lonxml::debug("$id is $type"); + if ($type eq 'dimension') { + $result.= + &nested_parse(\$dimension{$dim}{'criteria.'.$id}, + [@_],{'set_dim_id' => $id}); + } + } + } else { my $dim_status=$Apache::lonhomework::history{"resource.$version.0.$dim.status"}; my $mandatory='Mandatory'; if ($Apache::bridgetask::dimensionmandatory{$dim} eq 'N') { @@ -2095,10 +2225,11 @@ sub get_criteria { $result.= '

' .$mandatory.' Criteria

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

'.$status_display.'

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

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

'; } @@ -2106,24 +2237,22 @@ sub get_criteria { } } } - if (exists($dimension{$dim}{'nested'})) { - $dimension{$dim}{'result'}=$result; - undef($result); - } } elsif ($target eq 'webgrade') { # in case of any side effects that we need - @Apache::scripttag::parser_env = @_; - &Apache::scripttag::xmlparse($dimension{$dim}{'intro'}); - @Apache::scripttag::parser_env = @_; - &Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'}); - @Apache::scripttag::parser_env = @_; - &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'}); + &nested_parse(\$dimension{$dim}{'intro'},[@_]); + &nested_parse(\$dimension{$dim}{$instance.'.text'},[@_]); + $result.= + &nested_parse(\$dimension{$dim}{'questiontext'},[@_], + {'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'}; if ($type eq 'dimension') { # dimensional 'criteria' don't get assigned grades - $result.=$dimension{$id}{'result'}; + $result.= + &nested_parse(\$dimension{$dim}{'criteria.'.$id}, + [@_],{'set_dim_id' => $id}); next; } @@ -2131,10 +2260,10 @@ sub get_criteria { my $status= &get_criteria('status',$version,$dim,$id); $result.='
'."\n". '
'."\n"; - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'criteria.'.$id}); + $result.= + &nested_parse(\$dimension{$dim}{'criteria.'.$id},[@_]); + $result.='
'."\n". - #$dimension{$dim}{'criteria.'.$id}. '
'."\n". ''."\n". ''."\n". @@ -2152,8 +2281,9 @@ sub get_criteria { $result.=&grading_history($version,$dim,$id); $last_link=$link; } - if (exists($dimension{$dim}{'nested'})) { - $dimension{$dim}{'result'}=$result; + if (&nest()) { + &Apache::lonxml::debug(" for $dim stashing results into ".$dimension{$dim}{'nested'}); + $dimension{$dimension{$dim}{'nested'}}{'result'}.=$result; undef($result); } } elsif ($target eq 'grade' && $env{'form.webgrade'}) { @@ -2162,12 +2292,11 @@ sub get_criteria { my $ungraded=0; my $review=0; - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{'intro'}); - @Apache::scripttag::parser_env = @_; - $result.=&Apache::scripttag::xmlparse($dimension{$dim}{$instance.'.text'}); - @Apache::scripttag::parser_env = @_; - &Apache::scripttag::xmlparse($dimension{$dim}{'questiontext'}); + $result .= &nested_parse(\$dimension{$dim}{'intro'},[@_]); + $result .= &nested_parse(\$dimension{$dim}{$instance.'.text'}, + [@_]); + $result .= &nested_parse(\$dimension{$dim}{'questiontext'}, + [@_],{'set_dim_id' => undef}); foreach my $id (@{$dimension{$dim}{$instance.'.criterias'}}, @{$dimension{$dim}{'criterias'}}) { @@ -2178,6 +2307,10 @@ sub get_criteria { # dimensional 'criteria' don't get assigned grades $Apache::lonhomework::results{"resource.$version.0.$dim.$id.status"}=$env{'form.HWVAL_'.$link}; $Apache::lonhomework::results{"resource.$version.0.$dim.$id.comment"}=$env{'form.HWVAL_comment_'.$link}; + } else { + $result .= + &nested_parse(\$dimension{$dim}{'criteria.'.$id}, + [@_],{'set_dim_id' => $id}); } my $status= &get_criteria('status',$version,$dim,$id); @@ -2223,6 +2356,7 @@ sub get_criteria { # any other targets no output undef($result); } + &disable_dimension_parsing(); pop(@Apache::bridgetask::dimension); return $result; }