--- loncom/homework/bridgetask.pm 2005/09/21 21:54:20 1.52
+++ loncom/homework/bridgetask.pm 2006/02/20 21:43:16 1.111
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.52 2005/09/21 21:54:20 albertel Exp $
+# $Id: bridgetask.pm,v 1.111 2006/02/20 21:43:16 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -60,7 +60,7 @@ sub initialize_bridgetask {
}
sub proctor_check_auth {
- my ($slot_name,$slot)=@_;
+ my ($slot_name,$slot,$type)=@_;
my $user=$env{'form.proctorname'};
my $domain=$env{'form.proctordomain'};
@@ -68,21 +68,44 @@ sub proctor_check_auth {
foreach my $possible (@allowed) {
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 $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 && $type eq 'Task') {
+ # increment version
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;
+ $Apache::lonhomework::history{'resource.0.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;
+ $Apache::lonhomework::results{"resource.$version.0.checkedin"}=
+ $user.'@'.$domain;
+ $Apache::lonhomework::results{"resource.$version.0.checkedin.slot"}=
+ $slot_name;
+
return 1;
+ } elsif ($authenticated && $type eq 'problem') {
+ &Apache::lonxml::debug("authed $slot_name");
+ $Apache::lonhomework::results{"resource.0.checkedin"}=
+ $user.'@'.$domain;
+ $Apache::lonhomework::results{"resource.0.checkedin.slot"}=
+ $slot_name;
}
}
}
@@ -93,11 +116,11 @@ sub get_version {
my ($version,$previous);
if ($env{'form.previousversion'} &&
$env{'form.previousversion'} ne 'current' &&
- defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
+ defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.0.status'})) {
$version=$env{'form.previousversion'};
$previous=1;
} else {
- $version=$Apache::lonhomework::history{'resource.version'};
+ $version=$Apache::lonhomework::history{'resource.0.version'};
$previous=0;
}
if (wantarray) {
@@ -109,10 +132,10 @@ sub get_version {
sub add_previous_version_button {
my ($status)=@_;
my $result;
- if ($Apache::lonhomework::history{'resource.version'} eq '') {
+ if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
return '';
}
- if ($Apache::lonhomework::history{'resource.version'} < 2 &&
+ if ($Apache::lonhomework::history{'resource.0.version'} < 2 &&
$status ne 'NEEDS_CHECKIN') {
return '';
}
@@ -123,8 +146,8 @@ sub add_previous_version_button {
"\n";
}
my @to_show;
- foreach my $test_version (1..$Apache::lonhomework::history{'resource.version'}) {
- if (defined($Apache::lonhomework::history{'resource.'.$test_version.'.status'})) {
+ 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);
}
}
@@ -144,23 +167,53 @@ sub add_previous_version_button {
}
sub add_grading_button {
+ my (undef,$cid)=&Apache::lonxml::whichuser();
+ my $cnum=$env{'course.'.$cid.'.num'};
+ my $cdom=$env{'course.'.$cid.'.domain'};
+ my %sections;
+ my $numsections=&Apache::loncommon::get_sections($cdom,$cnum,\%sections);
+ my $size=5;
+ if (scalar(keys(%sections)) < 3) {
+ $size=scalar(keys(%sections))+2;
+ }
+ my $sec_select = '\n";
+
my $result=' ';
$result.='';
if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'})) {
my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
- $result.='
'.&mt("Grading Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
+ $result.='
'.&mt("Review Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
- $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'}))).
+ '
';
+ }
+ return $result;
+}
+
+sub webgrade_standard_info {
+ my ($version)=&get_version();
+ my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
+ my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
+ my $file_list="
\n";
+ foreach my $partial_file (split(',',$Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"})) {
+ my $file=$file_url.$partial_file;
+ $file=~s|/+|/|g;
+ &Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
+ $file_list.='
'.&mt('Your submission is in the grading queue.').'
';
+ } elsif ($env{'form.donescreen'}) {
+ my $title=&Apache::lonnet::gettitle();
+ my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
+ my $files='
';
- if (!$previous) {
- $result.=&add_request_another_attempt_button();
- }
- }
- if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
- $result.='
'.&mt('Passed').'
';
- }
+ $result.=&preserve_grade_info();
+ $result.=&internal_location();
$result.=$form_tag_start.
'';
- $result.=&preserve_grade_info();
-
+ &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;
+ $result.=$head_tag_start.''.$body_tag_start;
#$result.=' Review'.&show_queue('reviewqueue');
#$result.=' Grade'.&show_queue('gradingqueue');
}
@@ -321,9 +539,8 @@ sub start_Task {
# Hrrm, vaildation pass should perhaps say 'not_locked'
# perhaps do a search if there is a key that is mine and if
# there isn't reshow the queue....
- my ($todo,$status_code)=&get_key_todo($target);
+ my ($todo,$status_code,$msg)=&get_key_todo($target);
- &Apache::lonnet::logthis("got todo -$todo- stat -$status_code-");
if ($todo) {
&setup_env_for_other_user($todo,$safeeval);
my ($symb,$uname,$udom)=&decode_queue_key($todo);
@@ -335,36 +552,43 @@ sub start_Task {
$Apache::bridgetask::queue_key=$todo;
&Apache::structuretags::initialize_storage();
&Apache::lonhomework::showhash(%Apache::lonhomework::history);
- if ($target eq 'webgrade') {
- #$result.=' After -'.&show_queue($env{'form.queue'});
- $result.="\n".'
';
- if ($status_code eq 'selected') {
- $form_tag_start.=
- '';
- }
+ if ($target eq 'webgrade' && $status_code eq 'selected') {
+ $form_tag_start.=
+ '';
}
} else {
if ($target eq 'webgrade') {
$result.="\n";
+ my $back='
';
if ($status_code eq 'stop') {
- $result.=''.&mt("Stopped grading.").'';
+ $result.=''.&mt("Stopped grading.").''.$back;
} elsif ($status_code eq 'lock_failed') {
- $result.=''.&mt("Failed to lock the request record.").'';
+ $result.=''.&mt("Failed to lock the requested record.")
+ .''.$back;
} elsif ($status_code eq 'unlock') {
- $result.=''.&mt("Unlocked the requested record.").'';
+ $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.").'';
+ $result.=''.&mt("No user to be graded.").''.$back;
}
}
$webgrade='no';
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
+ 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.='';
@@ -374,7 +598,26 @@ sub start_Task {
$result.='';
}
+ if ($env{'form.chosensections'}) {
+ my @chosen_sections=
+ &Apache::loncommon::get_env_multiple('form.chosensections');
+ foreach my $sec (@chosen_sections) {
+ $result.='';
+ }
+ }
+ if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
+ }
+ if ($target eq 'webgrade') {
+ $result.="\n".'
';
}
+ } elsif ($target eq 'edit') {
+ $result.=$head_tag_start."".$body_tag_start.$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 = '';
@@ -387,7 +630,7 @@ sub get_key_todo {
my $todo;
if (defined($env{'form.reviewasubmission'})) {
- &Apache::lonnet::logthis("review a submission....");
+ &Apache::lonxml::debug("review a submission....");
$env{'form.queue'}='reviewqueue';
return (undef,'show_list');
}
@@ -404,6 +647,57 @@ sub get_key_todo {
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::lonxml::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
+ return ($gradingkey);
+ }
+
+ my $who=&queue_key_locked($queue,$gradingkey);
+ if ($who eq $me) {
+ #already have the lock
+ $env{'form.gradingkey'}=&Apache::lonnet::escape($gradingkey);
+ return ($gradingkey);
+ }
+
+ if (!defined($who)) {
+ if (&lock_key($queue,$gradingkey)) {
+ 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)) {
@@ -418,12 +712,12 @@ sub get_key_todo {
if ($env{'form.stop'}) {
return (undef,'stop');
} elsif ($env{'form.next'}) {
- return (undef,'show_list');
+ return (undef,'select_user');
}
}
return ($gradingkey,'selected');
} else {
- return (undef,'show_list');
+ return (undef,'select_user');
}
}
if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
@@ -431,7 +725,6 @@ sub get_key_todo {
&& $env{'form.queuemode'} eq 'selected') {
my $who=&queue_key_locked($queue,$gradingkey);
- my $me=$env{'user.name'}.'@'.$env{'user.domain'};
if ($who eq $me) {
&Apache::lonxml::debug("Found a key was given to me");
return ($gradingkey,'selected');
@@ -474,6 +767,16 @@ sub get_key_todo {
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='';
@@ -481,12 +784,13 @@ sub end_Task {
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' && !$previous) {
+ 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.0",
"bridgetask","*",
@@ -495,7 +799,63 @@ sub end_Task {
'.&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');
+ $result.='';
+ $result.=<
+
+
+
+DONEBUTTON
+ }
+ if (&show_task($status,$previous) &&
+ $Apache::lonhomework::history{"resource.$version.0.status"} =~ /^(pass|fail)$/) {
+ my $bt_status=$Apache::lonhomework::history{"resource.$version.0.status"};
+ my $title=&Apache::lonnet::gettitle();
+
+ my $slot_name=
+ $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
+ my %slot=&Apache::lonnet::get_slot($slot_name);
+ my $start_time=
+ &Apache::lonlocal::locallocaltime($slot{'starttime'});
+
+ my $status = "\n
\n";
+
+ if ($bt_status eq 'pass') {
+ $status.='
You passed the '.$title.' given on '.
+ $start_time.'
';
+ }
+ if ($bt_status eq 'fail') {
+ $status.='
You did not pass the '.$title.' given on '.
+ $start_time.'
';
+ if (!$previous) {
+ $status.=&add_request_another_attempt_button();
+ }
+ }
+ my $man_count=0;
+ my $opt_count=0;
+ my $opt_passed=0;
+ foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
+ if ($Apache::bridgetask::dimensionmandatory{$dim_id}
+ eq 'N') {
+ $opt_count++;
+ if ($Apache::lonhomework::history{"resource.$version.0.$dim_id.status"} eq 'pass') {
+ $opt_passed++;
+ }
+ } else {
+ $man_count++;
+ }
+ }
+ my $opt_req=&Apache::lonxml::get_param('OptionalRequired',
+ $parstack,$safeeval);
+ if ($opt_req !~ /\S/) { $opt_req='0'; }
+ $status.="\n
".&mt('You needed to pass all of the [_1] mandatory components and [_2] of the [_3] optional components, of which you passed [_4].',$man_count,$opt_req,$opt_count,$opt_passed)."
\n";
+
+ my $internal_location=&internal_location();
+ $result=~s/\Q$internal_location\E/$status/;
}
}
if ($target eq 'web' || $target eq 'webgrade') {
@@ -517,12 +877,18 @@ sub end_Task {
$award;
$Apache::lonhomework::results{"resource.0.submission"}=
$Apache::lonhomework::results{"resource.$version.0.submission"}='';
+ } else {
+ delete($Apache::lonhomework::results{"resource.$version.0.bridgetask.portfiles"});
+ $award = '';
}
&Apache::lonhomework::showhash(%Apache::lonhomework::results);
&Apache::structuretags::finalize_storage();
- if ($award eq 'SUBMITTED') {
- &add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
+ if ($award eq 'SUBMITTED'
+ && defined($Apache::inputtags::slot_name)) {
+ &add_to_queue('gradingqueue',[$Apache::inputtags::slot_name]);
}
+ } elsif ($Apache::lonhomework::results{'INTERNAL_store'}) {
+ &Apache::structuretags::finalize_storage();
}
if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
my $optional_required=
@@ -535,7 +901,7 @@ sub end_Task {
&Apache::lonhomework::showhash(%Apache::lonhomework::results);
foreach my $dim_id (@Apache::bridgetask::dimensionlist) {
my $status=
- $Apache::lonhomework::results{"resource.$version.$dim_id.status"};
+ $Apache::lonhomework::results{"resource.$version.0.$dim_id.status"};
my $mandatory=
($Apache::bridgetask::dimensionmandatory{$dim_id} ne 'N');
if ($status eq 'pass') {
@@ -554,10 +920,10 @@ sub end_Task {
$mandatory_failed++;
}
&Apache::lonxml::debug("all dim ".join(':',@Apache::bridgetask::dimensionlist)."results -> m_f $mandatory_failed o_p $optional_passed u $ungraded r $review");
- $Apache::lonhomework::results{'resource.grader'}=
+ $Apache::lonhomework::results{'resource.0.regrader'}=
$env{'user.name'}.'@'.$env{'user.domain'};
if ($review) {
- $Apache::lonhomework::results{"resource.$version.status"}='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.");
@@ -565,7 +931,7 @@ sub end_Task {
&move_between_queues($env{'form.queue'},'reviewqueue');
}
} elsif ($ungraded) {
- $Apache::lonhomework::results{"resource.$version.status"}='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.");
@@ -574,7 +940,7 @@ sub end_Task {
&check_queue_unlock($env{'form.queue'});
}
} elsif ($mandatory_failed) {
- $Apache::lonhomework::results{"resource.$version.status"}='fail';
+ $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';
@@ -592,7 +958,7 @@ sub end_Task {
["$version.0.bridgetask"]);
}
} else {
- $Apache::lonhomework::results{"resource.$version.status"}='pass';
+ $Apache::lonhomework::results{"resource.$version.0.status"}='pass';
$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';
@@ -609,8 +975,8 @@ sub end_Task {
["$version.0.bridgetask"]);
}
}
- $Apache::lonhomework::results{"resource.status"}=
- $Apache::lonhomework::results{"resource.$version.status"};
+ $Apache::lonhomework::results{"resource.0.status"}=
+ $Apache::lonhomework::results{"resource.$version.0.status"};
if (defined($Apache::lonhomework::results{"resource.$version.0.awarded"})) {
$Apache::lonhomework::results{"resource.0.award"}=
$Apache::lonhomework::results{"resource.$version.0.award"};
@@ -619,10 +985,11 @@ sub end_Task {
$Apache::lonhomework::results{"resource.0.solved"}=
$Apache::lonhomework::results{"resource.$version.0.solved"};
}
+ &minimize_storage();
&Apache::structuretags::finalize_storage();
}
} elsif ($target eq 'webgrade') {
- $result.="