--- loncom/homework/bridgetask.pm 2005/08/09 07:34:51 1.38
+++ loncom/homework/bridgetask.pm 2006/05/23 19:55:40 1.153
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.38 2005/08/09 07:34:51 albertel Exp $
+# $Id: bridgetask.pm,v 1.153 2006/05/23 19:55:40 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,7 +40,7 @@ use Apache::slotrequest();
use Time::HiRes qw( gettimeofday tv_interval );
BEGIN {
- &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
+ &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','Instance','InstanceText','Criteria','ClosingParagraph'));
}
sub initialize_bridgetask {
@@ -60,28 +60,27 @@ 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'};
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;
- foreach my $key (keys(%Apache::lonhomework::history)) {
- if ($key=~/^resource\.0\./) {
- $Apache::lonhomework::results{$key}='';
- }
+ 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) {
+ &create_new_version($type,$user,$domain,$slot_name);
return 1;
}
}
@@ -89,15 +88,60 @@ sub proctor_check_auth {
return 0;
}
+sub create_new_version {
+ my ($type,$user,$domain,$slot_name) = @_;
+ 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;
+ 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;
+ }
+ } 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;
+ }
+ }
+}
+
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'};
+ 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) {
@@ -109,10 +153,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 +167,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);
}
}
@@ -132,7 +176,7 @@ sub add_previous_version_button {
join("\n",@to_show).
" \n";
$list.=''.&mt('Current').' ';
- $result.='
";
my $symb=&Apache::lonnet::symbread();
- $body_tag_start.=''.
- ' '.
- ' '.
- ' '.
- ' ';
-
+ 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' && $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 '') {
+ &create_new_version('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");
- $body_tag_start.=&add_previous_version_button($status);
- 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') )) {
- 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.').' ';
@@ -268,6 +489,31 @@ sub start_Task {
''.&proctor_validation_screen($slot);
} elsif ($status eq 'WAITING_FOR_GRADE') {
$msg.=''.&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 (undef,undef,$domain,$user)=
+ &Apache::lonxml::whichuser();
+ my $files = '';
+ foreach my $file (@files) {
+ my $url="/uploaded/$domain/$user/portfolio$file";
+ if (! &Apache::lonnet::stat_file($url)) {
+ $file = &mt(' Nonexistant file: [_1] ',$file);
+ } else {
+ $file = ''.$file.' ';
+ }
+ $files .= ''.$file.' ';
+ }
+ $files.=' ';
+
+ $result.=<$title
+ Files submitted: $files
+ You are now done with this Bridge Task
+
+ Logout
+ Change to a different course
+DONESCREEN
} elsif ($status ne 'NOT_YET_VIEWED') {
$msg.=''.&mt('Not open to be viewed').' ';
}
@@ -284,52 +530,43 @@ 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";
-
- my ($version,$previous)=&get_version();
- if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
- $result.=''.&mt('Did not pass').' ';
- 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.=' Review'.&show_queue('reviewqueue');
- $result.=' Grade'.&show_queue('gradingqueue');
+ $result.= "\n".''."\n".
+ '';
+ #$result.='
Review'.&show_queue('reviewqueue');
+ #$result.='
Grade'.&show_queue('gradingqueue');
}
# FIXME Blast! still need to reorg this, need to reshow the
# queue being reviewed once done with the grade pass...
# 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);
@@ -341,40 +578,72 @@ 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=''.
+ &mt('Return to resource').'
';
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.=' ';
$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.=' ';
+ }
+ }
+ if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
}
+ if ($target eq 'webgrade') {
+ $result.="\n".'';
+ }
+ } 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 = '';
@@ -387,7 +656,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');
}
@@ -398,6 +667,63 @@ sub get_key_todo {
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::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)) {
@@ -406,12 +732,25 @@ sub get_key_todo {
my $gradingkey=&Apache::lonnet::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.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);
- 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');
@@ -454,6 +793,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='';
@@ -461,22 +810,91 @@ 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","*",
- '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');
+ $result.='';
+ my $action = &Apache::lonenc::check_encrypt($env{'request.uri'});
+ $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 $start_time;
+
+ my $slot_name=
+ $Apache::lonhomework::history{"resource.$version.0.checkedin.slot"};
+ if ($slot_name) {
+ my %slot=&Apache::lonnet::get_slot($slot_name);
+
+ $start_time=$slot{'starttime'}
+ } else {
+ $start_time=
+ &Apache::lonnet::EXT('resource.0.opendate');
+ }
+ $start_time=&Apache::lonlocal::locallocaltime($start_time);
+
+ 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') {
- $result.=&Apache::lonxml::xmlend().'