--- loncom/homework/bridgetask.pm 2005/05/13 15:34:50 1.24
+++ loncom/homework/bridgetask.pm 2006/11/13 21:23:19 1.202
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.24 2005/05/13 15:34:50 albertel Exp $
+# $Id: bridgetask.pm,v 1.202 2006/11/13 21:23:19 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,46 +36,54 @@ use Apache::File();
use Apache::lonmenu;
use Apache::lonlocal;
use Apache::lonxml;
+use Apache::slotrequest();
use Time::HiRes qw( gettimeofday tv_interval );
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
BEGIN {
- &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
+ &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','GraderNote','ClosingParagraph'));
}
+my %dimension;
+my $top = 'top';
+
sub initialize_bridgetask {
# id of current Dimension, 0 means that no dimension is current
# (inside only)
- $Apache::bridgetask::dimension='';
- # list of all Dimension ids seen
- @Apache::bridgetask::dimensionlist=();
- # mandatory attribute of all Dimensions seen
- %Apache::bridgetask::dimensionmandatory=();
+ @Apache::bridgetask::dimension=();
# list of all current Instance ids
- @Apache::bridgetask::instance=();
+ %Apache::bridgetask::instance=();
# list of all Instance ids seen in this problem
@Apache::bridgetask::instancelist=();
# key of queud user data that we are currently grading
$Apache::bridgetask::queue_key='';
+ undef(%dimension);
}
sub proctor_check_auth {
- my ($slot_name,$slot)=@_;
+ my ($slot_name,$slot,$type)=@_;
my $user=$env{'form.proctorname'};
my $domain=$env{'form.proctordomain'};
my @allowed=split(",",$slot->{'proctor'});
foreach my $possible (@allowed) {
- my ($puser,$pdom)=(split('@',$possible));
+ my ($puser,$pdom)=(split(':',$possible));
if ($puser eq $user && $pdom eq $domain) {
- my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
- if ($authhost ne 'no_host') {
- my $version=
- $Apache::lonhomework::results{'resource.version'}=
- $Apache::lonhomework::history{'resource.version'}++;
- $Apache::lonhomework::results{"resource.$version.checkedin"}=
- $user.'@'.$domain;
- $Apache::lonhomework::results{"resource.$version.checkedin.slot"}=
- $slot_name;
+ my $authenticated=0;
+ if ( $slot->{'secret'} =~ /\S/ &&
+ $env{'form.proctorpassword'} eq $slot->{'secret'} ) {
+ $authenticated=1;
+ } else {
+
+ my $authhost=&Apache::lonnet::authenticate($puser,$env{'form.proctorpassword'},$pdom);
+ if ($authhost ne 'no_host') {
+ $authenticated=1;
+ }
+ }
+ if ($authenticated) {
+ &check_in($type,$user,$domain,$slot_name);
return 1;
}
}
@@ -83,80 +91,574 @@ 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::lonnet::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=
+ $Apache::lonhomework::history{'resource.0.version'};
+ $version++;
+ &Apache::lonxml::debug("Making version $version");
+ #clean out all current results
+ foreach my $key (keys(%Apache::lonhomework::history)) {
+ if ($key=~/^resource\.0\./) {
+ $Apache::lonhomework::results{$key}='';
+ }
+ }
+
+ #setup new version and who did it
+ $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)) {
+ $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;
+ }
+}
+
+sub get_version {
+ my ($version,$previous);
+ if ($env{'form.previousversion'} &&
+ $env{'form.previousversion'} ne 'current' &&
+ defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
+ $version=$env{'form.previousversion'};
+ $previous=1;
+ } else {
+ if (defined($Apache::lonhomework::results{'resource.0.version'})) {
+ $version=$Apache::lonhomework::results{'resource.0.version'};
+ } elsif (defined($Apache::lonhomework::history{'resource.0.version'})) {
+ $version=$Apache::lonhomework::history{'resource.0.version'};
+ }
+ $previous=0;
+ }
+ if (wantarray) {
+ return ($version,$previous);
+ }
+ return $version;
+}
+
sub add_previous_version_button {
+ my ($status)=@_;
my $result;
- $result.=&mt(' Show a previously done version: [_1]','
-Pick one
- ');
+ if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
+ return '';
+ }
+ if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
+ $status ne 'NEEDS_CHECKIN') {
+ return '';
+ }
+ my $version=&get_version();
+ if ($env{'form.previousversion'} ne '' &&
+ $env{'form.previousversion'} eq $version) {
+ $result.="".&mt("Showing previous version [_1]",$version).
+ " \n";
+ }
+ my @to_show;
+ foreach my $test_version (1..$Apache::lonhomework::history{'resource.0.version'}) {
+ if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.0.status'})) {
+ push(@to_show,$test_version);
+ }
+ }
+ my $list=''.
+ join(" \n",@to_show).
+ " \n";
+ $list.=''.&mt('Current').' ';
+ $result.='";
return $result;
}
sub add_grading_button {
- my $result;
- $result.=' '."\n";
+ $sec_select .= "\tall \n";
+ foreach my $sec (sort {lc($a) cmp lc($b)} (keys(%sections))) {
+ $sec_select .= "\t$sec \n";
+ }
+ $sec_select .= "\tnone \n\n";
+
+ my $result="\n\t".' ';
- $result.=' ';
+ $result.="\n\t".' ';
+ if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
+ my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
+ $result.="\n\t".''."\n\t\t".'';
+ $result.="\n\t\t\t".'Specify a section: '.
+ "\n\t\t\t".''.$sec_select."\n\t\t\t".' ';
+ $result.="\n\t\t\t".''.' ';
+
+ $result.= "\n\t\t\t\t".&mt("[_1] entries, [_2] ready, [_3] being graded",$entries,$ready,$locks).' '."\n\t\t".' '."\n";
+
+ ($entries,$ready,$locks)=&get_queue_counts('reviewqueue');
+ $result.="\n\t\t".''.
+ "\n\t\t\t".''.
+ "\n\t\t\t\t".' ';
+ $result.=&mt("[_1] entries, [_2] ready, [_3] being graded",
+ $entries,$ready,$locks).' '."\n\t\t".' '."\n";
+ $result.="\n\t\t".''.
+ "\n\t\t\t".''.
+ "\n\t\t\t\t".' '
+ ."\n\t\t".' '
+ ."\n\t".'
'."\n";
+ $result.="\n\t".''.
+ "\n\t\t".' ';
+ $result.= "\n\t\t".' ';
+ $result.=&Apache::loncommon::select_dom_form($env{'user.domain'},
+ 'gradingdomain');
+ $result.=' '.
+ &Apache::loncommon::selectstudent_link('gradesubmission',
+ 'gradinguser',
+ 'gradingdomain');
+ $result.=&Apache::loncommon::studentbrowser_javascript();
+ $result.= '
'."\n";
+ }
return $result;
}
sub add_request_another_attempt_button {
+ my ($text)=@_;
+ if (!$text) { $text="Request another attempt"; }
+ my $result;
+ my $symb=&Apache::lonnet::symbread();
+ # not a slot access based resource
+ my $useslots = &Apache::lonnet::EXT("resource.0.useslots",$symb);
+ if ($useslots =~ /^\s*no\s*$/i) {
+ return '';
+ }
+
+ my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
+ my $action='get_reservation';
+ if ($slot_name) {
+ $text="Change reservation.";
+ $action='change_reservation';
+ my $description=&Apache::slotrequest::get_description($slot_name,
+ $slot);
+ $result.=(< Will be next available: $description
+STUFF
+ }
+ if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
+ $symb=&escape($symb);
+ $result.=
+ "\n\t".''."\n";
+ return $result;
+}
+
+sub preserve_grade_info {
+ my $result;
+ # if we are viewing someone else preserve that info
+ if (defined $env{'form.grade_symb'}) {
+ foreach my $field ('symb','courseid','domain','username') {
+ $result .= ' '."\n";
+ }
+ }
+ return $result;
+}
+
+sub style {
+ my ($target) = @_;
+ if ($target eq 'web'
+ || $target eq 'webgrade') {
+ my $style = (<
+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;
+}
+
+sub show_task {
+ my ($status,$previous)=@_;
+ if (!$previous && (
+ ( $status eq 'CLOSED' ) ||
+ ( $status eq 'BANNED') ||
+ ( $status eq 'UNAVAILABLE') ||
+ ( $status eq 'NOT_IN_A_SLOT') ||
+ ( $status eq 'NEEDS_CHECKIN') ||
+ ( $status eq 'WAITING_FOR_GRADE') ||
+ ( $status eq 'INVALID_ACCESS') ||
+ ( &get_version() eq ''))) {
+ return 0;
+ }
+ if ($env{'form.donescreen'}) { return 0; }
+ 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 '';
+}
+
+sub submission_time_stamp {
+ my ($symb,$courseid,$udom,$uname)=&Apache::lonnet::whichuser();
+ 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'})
+ && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) {
+ $submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
+ last;
+ }
+ }
+ my $result;
+ if ($submissiontime) {
+ my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
+ my %slot=&Apache::lonnet::get_slot($slot_name);
+ my $diff = $slot{'endtime'} - $submissiontime;
+ 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,
+ &Apache::lonlocal::locallocaltime($submissiontime),
+ &Apache::lonlocal::locallocaltime($slot{'endtime'})).
+ '
';
+ }
+ return $result;
+}
+
+sub file_list {
+ my ($files,$uname,$udom) = @_;
+ if (!defined($uname) || !defined($udom)) {
+ (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
+ }
+ my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
+
+ my $file_list="\n";
+ foreach my $partial_file (split(',',$files)) {
+ my $file=$file_url.$partial_file;
+ $file=~s|/+|/|g;
+ &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
+ $file_list.=' '.$file.
+ ' '."\n";
+ }
+ $file_list.=" \n";
+ return $file_list;
+}
+
+sub grade_mode {
+ if ($env{'form.regrade'} || $env{'form.regradeaspecificsubmission'}) {
+ return 'regrade';
+ }
+ return 'queue_grade';
+}
+
+sub webgrade_standard_info {
+ my ($version)=&get_version();
+
+ my $file_list = &file_list($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"});
+
+ my %lt=('done' => 'Next Item',
+ 'stop' => 'Quit Grading',
+ 'fail' => 'Fail Rest',
+ 'cancel' => 'Cancel',
+ );
+ %lt=&Apache::lonlocal::texthash(%lt);
+
+ my $result=<
+INFO
+
+ if (&grade_mode() eq 'regrade') {
+ $result.=<
+INFO
+ }
+
+ $result.=<
+
+
+
+ $file_list
+INFO
+ return $result;
+}
+
+sub done_screen {
+ my ($version) = @_;
+ my $title=&Apache::lonnet::gettitle();
+ my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
+ my (undef,undef,$domain,$user)= &Apache::lonnet::whichuser();
+ my $files = '';
+ my $subject = "Submission message for $title";
+ my ($message_status,$comment_status);
+ my $setting = $env{'course.'.$env{'request.course.id'}.'.task_messages'};
+ $setting =~ s/^\s*(\S*)\s*$/$1/;
+ $setting = lc($setting);
+ if ($setting eq 'only_student'
+ || $setting eq 'student_and_user_notes_screen') {
+ $message_status =
+ &Apache::lonmsg::user_normal_msg($user,$domain,$subject,$msg);
+ $message_status = ''.&mt('Message sent to user: [_1]',
+ $message_status).'
';
+ }
+ if ($setting eq 'student_and_user_notes_screen') {
+ $comment_status =
+ &Apache::lonmsg::store_instructor_comment($subject.' '.
+ $msg,$user,$domain);
+ $comment_status = ''.&mt('Message sent to instructor: [_1]',
+ $comment_status).'
';
+ }
+ return <$title
+ Files submitted: $files
+ You are now done with this Bridge Task
+
+ Logout
+ Change to a different course
+$message_status
+$comment_status
+DONESCREEN
+
}
sub start_Task {
- my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my ($status,$accessmsg,$slot);
+ &Apache::structuretags::init_problem_globals('Task');
if ($target ne 'webgrade') {
&Apache::structuretags::initialize_storage();
&Apache::lonhomework::showhash(%Apache::lonhomework::history);
+ if ($env{'request.state'} eq 'construct') {
+ &Apache::structuretags::setup_rndseed($safeeval);
+ }
}
$Apache::lonhomework::parsing_a_task=1;
- #should get back a or the neccesary stuff to start XML/MathML
- my ($result,$head_tag_start,$body_tag_start,$form_tag_start)=
- &Apache::structuretags::page_start($target,$token,$tagstack,$parstack,$parser,$safeeval);
-
- if ($target eq 'web') {
- $body_tag_start.=&add_previous_version_button();
- if ($Apache::lonhomework::modifygrades) {
- $body_tag_start.='";
+ $result.=$uri.'">'.&add_grading_button()."\n";
+ my $symb=&Apache::lonnet::symbread();
+ if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
+ $result.='';
+ my $target_id =
+ &Apache::lonstathelpers::make_target_id({symb => $symb,
+ part => '0'});
+ $result.='';
+ }
}
}
- if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
- $target eq 'tex') {
- my $version=$Apache::lonhomework::history{'resource.version'};
+ if ($target eq 'web' && $env{'request.state'} eq 'construct') {
+ $form_tag_start.=&Apache::structuretags::problem_web_to_edit_header($env{'form.rndseed'});
+ }
+ if ($target eq 'web'
+ || ($target eq 'grade' && !$env{'form.webgrade'})
+ || $target eq 'answer'
+ || $target eq 'tex') {
+ my ($version,$previous)=&get_version();
($status,$accessmsg,my $slot_name,$slot) =
- &Apache::lonhomework::check_task_access('0');
+ &Apache::lonhomework::check_slot_access('0','Task');
+ if ($status eq 'CAN_ANSWER' && $version eq '') {
+ # 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});
+ ($version,$previous)=&get_version();
+ }
+
push(@Apache::inputtags::status,$status);
$Apache::inputtags::slot_name=$slot_name;
my $expression='$external::datestatus="'.$status.'";';
- $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.solved"}.'";';
+ $expression.='$external::gradestatus="'.$Apache::lonhomework::history{"resource.$version.0.solved"}.'";';
&Apache::run::run($expression,$safeeval);
&Apache::lonxml::debug("Got $status");
- if (( $status eq 'CLOSED' ) ||
- ( $status eq 'BANNED') ||
- ( $status eq 'UNAVAILABLE') ||
- ( $status eq 'NOT_IN_A_SLOT') ||
- ( $status eq 'NEEDS_CHECKIN') ||
- ( $status eq 'WAITING_FOR_GRADE') ||
- ( $status eq 'INVALID_ACCESS')) {
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
+ $result.=&add_previous_version_button($status);
+ if (!&show_task($status,$previous)) {
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
if ( $target eq "web" ) {
- $result.= $head_tag_start.''.$body_tag_start;
+ if ($env{'request.state'} eq 'construct') {
+ $result.=$form_tag_start;
+ }
my $msg;
if ($status eq 'UNAVAILABLE') {
$msg.=''.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').' ';
} elsif ($status eq 'NOT_IN_A_SLOT') {
$msg.=''.&mt('You are not currently signed up to work at this time and/or place.').' ';
+ $msg.=&add_request_another_attempt_button("Sign up for time to work.");
} elsif ($status eq 'NEEDS_CHECKIN') {
$msg.=''.&mt('You need the Proctor to validate you.').
' '.&proctor_validation_screen($slot);
} elsif ($status eq 'WAITING_FOR_GRADE') {
$msg.=''.&mt('Your submission is in the grading queue.').' ';
+ } elsif ($env{'form.donescreen'}) {
+ $result .= &done_screen($version);
} elsif ($status ne 'NOT_YET_VIEWED') {
$msg.=''.&mt('Not open to be viewed').' ';
}
@@ -173,62 +675,130 @@ sub start_Task {
}
} elsif ($target eq 'grade' && !$env{'form.webgrade'}) {
if ($status eq 'NEEDS_CHECKIN') {
- if (&proctor_check_auth($slot_name,$slot)) {
- #FIXME immeadiatly add this to the grading queue
- # with slot->{'endtime'} for when grading can
- # begin on this resource
- # FIXME I think the above is done by default,
- # need to check that
- # failure doesn't do this.
- }
+ if(&proctor_check_auth($slot_name,$slot,'Task')
+ && defined($Apache::inputtags::slot_name)) {
+ my $result=
+ &add_to_queue('gradingqueue',
+ {'type' => 'Task',
+ 'time' => time,
+ 'slot' =>
+ $Apache::inputtags::slot_name});
+ &Apache::lonxml::debug("add_to_queue said $result");
+ }
}
}
} elsif ($target eq 'web') {
- my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
- $result.="$head_tag_start$name
- $body_tag_start \n $form_tag_start".
- ' ';
- # if we are viewing someone else preserve that info
- if (defined $env{'form.grade_symb'}) {
- foreach my $field ('symb','courseid','domain','username') {
- $result .= ' '."\n";
- }
- }
- if ($Apache::lonhomework::history{'resource.status'} eq 'fail') {
- $result.=''.&mt('Did not pass').' ';
- $result.=&request_another_attempt_button();
- }
- if ($Apache::lonhomework::history{'resource.status'} eq 'pass') {
- $result.=''.&mt('Passed').' ';
- }
+
+ $result.=&preserve_grade_info();
+ $result.=&internal_location();
+ $result.=$form_tag_start."\t".
+ ' ';
+ &Apache::lonxml::startredirection();
}
} elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
$target eq 'webgrade') {
+ my $webgrade='yes';
if ($target eq 'webgrade') {
- $result.=$head_tag_start.$body_tag_start.$form_tag_start;
- $result.=' ';
- $result.=&show_queue();
+ $result.= "\n".''."\n".
+ '';
+ #$result.='
Review'.&show_queue('reviewqueue');
+ #$result.='
Grade'.&show_queue('gradingqueue');
}
- my $todo=&get_from_queue();
+
+ my ($todo,$status_code,$msg)=&get_key_todo($target);
+
if ($todo) {
&setup_env_for_other_user($todo,$safeeval);
my ($symb,$uname,$udom)=&decode_queue_key($todo);
$result.="\n".'
Found '.
&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'
';
- $result.='
';
+ $form_tag_start.=
+ '
';
$Apache::bridgetask::queue_key=$todo;
&Apache::structuretags::initialize_storage();
&Apache::lonhomework::showhash(%Apache::lonhomework::history);
- $result.="\n".'
';
+ if ($target eq 'webgrade' && $status_code eq 'selected') {
+ $form_tag_start.=
+ ' ';
+ }
} else {
if ($target eq 'webgrade') {
- $result.="\n".
- '';
+ $result.="\n";
+ my $back=''.
+ &mt('Return to resource').'
';
+ if ($status_code eq 'stop') {
+ $result.=''.&mt("Stopped grading.").' '.$back;
+ } elsif ($status_code eq 'cancel') {
+ $result.=''.&mt("Cancelled grading.").' '.$back;
+ } elsif ($status_code eq 'never_versioned') {
+ $result.=''.
+ &mt("Requested user has never accessed the task.").
+ ' '.$back;
+ } elsif ($status_code =~ /still_open:(.*)/) {
+ my $date = &Apache::lonlocal::locallocaltime($1);
+ $result.=''.
+ &mt("Task is still open, will close at [_1].",$date).
+ ' '.$back;
+ } elsif ($status_code eq 'lock_failed') {
+ $result.=''.&mt("Failed to lock the requested record.")
+ .' '.$back;
+ } elsif ($status_code eq 'unlock') {
+ $result.=''.&mt("Unlocked the requested record.")
+ .' '.$back;
+ $result.=&show_queue($env{'form.queue'},1);
+ } elsif ($status_code eq 'show_list') {
+ $result.=&show_queue($env{'form.queue'},1);
+ } elsif ($status_code eq 'select_user') {
+ $result.=&select_user();
+ } elsif ($status_code eq 'unable') {
+ $result.=''.&mt("Unable to aqcuire a user to grade.").' '.$back;
+ } elsif ($status_code eq 'not_allowed') {
+ $result.=''.&mt('Not allowed to grade the requested user.').' '.$msg.' '.$back;
+ } else {
+ $result.=''.&mt("No user to be graded.").' '.$back;
+ }
+ }
+ $webgrade='no';
+ }
+ if (!$todo || $env{'form.cancel'}) {
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser,$style);
+ }
+ if ($target eq 'webgrade' && defined($env{'form.queue'})) {
+ if ($webgrade eq 'yes') {
+ $result.=&submission_time_stamp();
+ }
+ $result.=$form_tag_start;
+ $result.=' ';
+ $result.=' ';
+ if ($env{'form.regrade'}) {
+ $result.=' ';
+ }
+ if ($env{'form.chosensections'}) {
+ my @chosen_sections=
+ &Apache::loncommon::get_env_multiple('form.chosensections');
+ foreach my $sec (@chosen_sections) {
+ $result.=' ';
+ }
}
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
+ if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
}
+ if ($target eq 'webgrade') {
+ $result.="\n".'';
+ &Apache::lonxml::startredirection();
+ }
+ } elsif ($target eq 'edit') {
+ $result.=$form_tag_start.
+ &Apache::structuretags::problem_edit_header();
+ $Apache::lonxml::warnings_error_header=
+ &mt("Editor Errors - these errors might not effect the running of the problem, but they will likely cause problems with further use of the Edit mode. Please use the EditXML mode to fix these errors.")."
";
+ my $temp=&Apache::edit::insertlist($target,$token);
+ $result.=$temp;
} else {
# page_start returned a starting result, delete it if we don't need it
$result = '';
@@ -236,48 +806,334 @@ sub start_Task {
return $result;
}
+sub get_task_end_time {
+ my ($queue_entry,$symb,$udom,$uname) = @_;
+
+ my $end_time;
+ if (my $slot = &slotted_access($queue_entry)) {
+ my %slot_data=&Apache::lonnet::get_slot($slot);
+ $end_time = $slot_data{'endtime'};
+ } else {
+ $end_time = &Apache::lonhomework::due_date('0',$symb,
+ $udom,$uname);
+ }
+ return $end_time;
+}
+
+sub get_key_todo {
+ my ($target)=@_;
+ my $todo;
+
+ if (defined($env{'form.reviewasubmission'})) {
+ &Apache::lonxml::debug("review a submission....");
+ $env{'form.queue'}='reviewqueue';
+ return (undef,'show_list');
+ }
+
+ if (defined($env{'form.reviewagrading'})) {
+ &Apache::lonxml::debug("review a grading....");
+ $env{'form.queue'}='gradingqueue';
+ return (undef,'show_list');
+ }
+
+ if (defined($env{'form.regradeasubmission'})) {
+ &Apache::lonxml::debug("regrade a grading....");
+ $env{'form.queue'}='none';
+ return (undef,'select_user');
+ }
+
+
+ my $me=$env{'user.name'}.':'.$env{'user.domain'};
+
+ #need to try both queues..
+ if (defined($env{'form.regradeaspecificsubmission'}) &&
+ defined($env{'form.gradinguser'}) &&
+ defined($env{'form.gradingdomain'}) ) {
+ my ($symb,$cid)=&Apache::lonnet::whichuser();
+ my $cnum = $env{'course.'.$cid.'.num'};
+ my $cdom = $env{'course.'.$cid.'.domain'};
+ my $uname = $env{'form.gradinguser'};
+ my $udom = $env{'form.gradingdomain'};
+
+ my $gradingkey=&encode_queue_key($symb,$udom,$uname);
+
+ my $queue;
+
+ if (&in_queue('gradingqueue',$symb,$cdom,$cnum,$udom,$uname)) {
+ $env{'form.queue'} = $queue = 'gradingqueue';
+ } elsif (&in_queue('reviewqueue' ,$symb,$cdom,$cnum,$udom,$uname)) {
+ $env{'form.queue'} = $queue = 'reviewqueue';
+ }
+
+ if (!$queue) {
+ $env{'form.queue'} = $queue = 'none';
+ #not queued so doing either a re or pre grade
+ my %status = &Apache::lonnet::restore($symb,$cid,$udom,$uname);
+ if ($status{'resource.0.version'} < 1) {
+ return (undef,'never_versioned');
+ }
+ return ($gradingkey);
+ }
+
+ if ($queue) {
+ my $queue_entry = &get_queue_data($queue,$udom,$uname);
+
+ my $end_time = &get_task_end_time($queue_entry,$symb,
+ $udom,$uname);
+ if ($end_time > time) {
+ return (undef,"still_open:$end_time");
+ }
+ }
+
+ my $who=&queue_key_locked($queue,$gradingkey);
+ if ($who eq $me) {
+ #already have the lock
+ $env{'form.gradingkey'}=&escape($gradingkey);
+ &Apache::lonxml::debug("already locked");
+ return ($gradingkey);
+ }
+
+ if (!defined($who)) {
+ if (&lock_key($queue,$gradingkey)) {
+ &Apache::lonxml::debug("newly locked");
+ return ($gradingkey);
+ } else {
+ return (undef,'lock_failed');
+ }
+ }
+
+ #otherwise (defined($who) && $who ne $me) some else has it...
+ return (undef,'not_allowed',
+ &mt('Another user ([_1]) currently has the record for [_2] locked.',
+ $who,$env{'form.gradinguser'}.':'.$env{'form.gradingdomain'}));
+ }
+
+
+ my $queue=$env{'form.queue'};
+
+ if (!defined($queue)) {
+ $env{'form.queue'}=$queue='gradingqueue';
+ }
+
+ my $gradingkey=&unescape($env{'form.gradingkey'});
+
+ if ($env{'form.queue'} eq 'none') {
+ if (defined($env{'form.gradingkey'})) {
+ if ($target eq 'webgrade') {
+ if ($env{'form.stop'}) {
+ return (undef,'stop');
+ } elsif ($env{'form.cancel'}) {
+ return (undef,'cancel');
+ } elsif ($env{'form.next'}) {
+ return (undef,'select_user');
+ }
+ }
+ return ($gradingkey,'selected');
+ } else {
+ return (undef,'select_user');
+ }
+ }
+ if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
+ && !defined($env{'form.gradingaction'})
+ && $env{'form.queuemode'} eq 'selected') {
+
+ my $who=&queue_key_locked($queue,$gradingkey);
+ if ($who eq $me) {
+ &Apache::lonxml::debug("Found a key was given to me");
+ return ($gradingkey,'selected');
+ } else {
+ return (undef,'show_list');
+ }
+
+ }
+
+ if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
+ if ($env{'form.gradingaction'} eq 'resume') {
+ delete($env{'form.gradingaction'});
+ &Apache::lonxml::debug("Resuming a key");
+ return ($gradingkey);
+ } elsif ($env{'form.gradingaction'} eq 'unlock') {
+ &Apache::lonxml::debug("Unlocking a key ".
+ &check_queue_unlock($queue,$gradingkey,1));
+ return (undef,'unlock');
+ } elsif ($env{'form.gradingaction'} eq 'select') {
+ &Apache::lonxml::debug("Locking a key");
+ if (&lock_key($queue,$gradingkey)) {
+ &Apache::lonxml::debug("Success $queue");
+ return ($gradingkey);
+ }
+ &Apache::lonxml::debug("Failed $queue");
+ return (undef,'lock_failed');
+ }
+ }
+
+ if ($env{'form.queuemode'} ne 'selected') {
+ # don't get something new from the queue if they hit the stop button
+ if (!(($env{'form.cancel'} || $env{'form.stop'})
+ && $target eq 'webgrade')
+ && !$env{'form.gradingaction'}) {
+ &Apache::lonxml::debug("Getting anew $queue");
+ return (&get_from_queue($queue));
+ } else {
+ return (undef,'stop');
+ }
+ }
+ return (undef,undef)
+}
+
+sub minimize_storage {
+ foreach my $key (keys(%Apache::lonhomework::results)) {
+ if ($key =~ /regrader$/) { next; }
+ if ($Apache::lonhomework::results{$key} eq
+ $Apache::lonhomework::history{$key}) {
+ delete($Apache::lonhomework::results{$key});
+ }
+ }
+}
+
sub end_Task {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result='';
my $status=$Apache::inputtags::status['-1'];
- my $version=$Apache::lonhomework::history{'resource.version'};
+ my ($version,$previous)=&get_version();
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
$target eq 'tex') {
- if (
- (($target eq 'web') && ($env{'request.state'} ne 'construct')) ||
- ($target eq 'answer') || ($target eq 'tex')
- ) {
+ if ($target eq 'web' || $target eq 'answer' || $target eq 'tex') {
if ($target eq 'web') {
- if ($status eq 'CAN_ANSWER') {
+ if (&show_task($status,$previous)) {
+ $result.=&Apache::lonxml::endredirection();
+ }
+ if ($status eq 'CAN_ANSWER' && !$previous &&
+ !$env{'form.donescreen'}) {
$result.="\n".'
'.
- &Apache::inputtags::file_selector($version,
+ &Apache::inputtags::file_selector("$version.0",
"bridgetask","*",
- 'portfolioonly').
+ 'portfolioonly',
+ '
+'.&mt('Submit Portfolio Files for Grading').'
+'.&mt('Indicate the files from your portfolio to be evaluated in grading this task.').'
').
"
";
+ }
+ if (!$previous && $status ne 'SHOW_ANSWER' &&
+ &show_task($status,$previous)) {
$result.=&Apache::inputtags::gradestatus('0');
}
- }
- if ($target eq 'web' || $target eq 'webgrade') {
- $result.=&Apache::lonxml::xmlend().'