--- loncom/homework/bridgetask.pm 2006/10/31 21:29:38 1.188
+++ loncom/homework/bridgetask.pm 2023/01/23 20:31:13 1.273
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.188 2006/10/31 21:29:38 albertel Exp $
+# $Id: bridgetask.pm,v 1.273 2023/01/23 20:31:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,22 +37,22 @@ use Apache::lonmenu;
use Apache::lonlocal;
use Apache::lonxml;
use Apache::slotrequest();
+use Apache::structuretags();
use Time::HiRes qw( gettimeofday tv_interval );
-use lib '/home/httpd/lib/perl/';
use LONCAPA;
BEGIN {
- &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','GraderNote','ClosingParagraph'));
+ &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','CriteriaText','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::top_dimensionlist=();
# list of all current Instance ids
%Apache::bridgetask::instance=();
# list of all Instance ids seen in this problem
@@ -65,6 +65,7 @@ sub initialize_bridgetask {
sub proctor_check_auth {
my ($slot_name,$slot,$type)=@_;
my $user=$env{'form.proctorname'};
+ $user =~ s/^\s+|\s+$//g;
my $domain=$env{'form.proctordomain'};
my @allowed=split(",",$slot->{'proctor'});
@@ -83,7 +84,10 @@ sub proctor_check_auth {
}
}
if ($authenticated) {
- &check_in($type,$user,$domain,$slot_name);
+ my $check = &check_in($type,$user,$domain,$slot_name,$slot->{'iptied'});
+ if ($check =~ /^error:/) {
+ return 0;
+ }
return 1;
}
}
@@ -92,40 +96,82 @@ sub proctor_check_auth {
}
sub check_in {
- my ($type,$user,$domain,$slot_name) = @_;
+ my ($type,$user,$domain,$slot_name,$needsiptied) = @_;
my $useslots = &Apache::lonnet::EXT("resource.0.useslots");
+ my $ip=$ENV{'REMOTE_ADDR'} || $env{'request.host'};
if ( $useslots eq 'map_map') {
- &check_in_sequence($user,$domain,$slot_name);
+ my $result = &check_in_sequence($user,$domain,$slot_name,$ip,$needsiptied);
+ if ($result =~ /^error: /) {
+ return $result;
+ }
} else {
- &create_new_version($type,$user,$domain,$slot_name);
+ my ($symb) = &Apache::lonnet::whichuser();
+ my $result = &create_new_version($type,$user,$domain,$slot_name,$symb,$ip,$needsiptied);
+ if ($result eq 'ok') {
+ &Apache::structuretags::finalize_storage();
+ }
+ return $result;
}
return 1;
}
sub check_in_sequence {
- my ($user,$domain,$slot_name) = @_;
+ my ($user,$domain,$slot_name,$ip,$needsiptied) = @_;
my $navmap = Apache::lonnavmaps::navmap->new();
+ if (!defined($navmap)) {
+ return 'error: No navmap';
+ }
my ($symb) = &Apache::lonnet::whichuser();
my ($map) = &Apache::lonnet::decode_symb($symb);
my @resources =
- $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
+ $navmap->retrieveResources($map, sub { $_[0]->is_problem() || $_[0]->is_tool() },0,0);
my %old_history = %Apache::lonhomework::history;
my %old_results = %Apache::lonhomework::results;
+ my $errorcount;
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);
+ my $type;
+ if ($res->is_task()) {
+ $type = 'Task';
+ } elsif ($res->is_tool) {
+ $type = 'tool';
+ } else {
+ $type = 'problem';
+ }
+ my $result = &create_new_version($type,$user,$domain,$slot_name,$res->symb,$ip,$needsiptied);
+ if ($result eq 'ok') {
+ &Apache::structuretags::finalize_storage($res->symb);
+ } else {
+ $errorcount ++;
+ }
}
%Apache::lonhomework::history = %old_history;
%Apache::lonhomework::results = %old_results;
+ if ($errorcount) {
+ return 'error: IP taken';
+ }
}
sub create_new_version {
- my ($type,$user,$domain,$slot_name) = @_;
+ my ($type,$user,$domain,$slot_name,$symb,$ip,$needsiptied) = @_;
+
+ if ($needsiptied) {
+ my $uniqkey = "$slot_name\0$symb\0$ip";
+ my ($cdom,$cnum);
+ if ($env{'request.course.id'}) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my %hash = (
+ "$slot_name\0$symb\0$ip" => $env{'user.name'}.':'.$env{'user.domain'},
+ );
+ unless (&Apache::lonnet::newput('slot_uniqueips',\%hash,$cdom,$cnum) eq 'ok') {
+ return 'error: IP taken';
+ }
+ }
+ }
my $id = '0';
if ($type eq 'Task') {
@@ -149,7 +195,7 @@ sub create_new_version {
$domain = $env{'user.domain'};
}
- } elsif ($type eq 'problem') {
+ } elsif (($type eq 'problem') || ($type eq 'tool')) {
&Apache::lonxml::debug("authed $slot_name");
}
if (!defined($user) || !defined($domain)) {
@@ -159,11 +205,13 @@ sub create_new_version {
$Apache::lonhomework::results{"resource.$id.checkedin"}=
$user.':'.$domain;
+ $Apache::lonhomework::results{"resource.$id.checkedin.ip"}=$ip;
if (defined($slot_name)) {
$Apache::lonhomework::results{"resource.$id.checkedin.slot"}=
$slot_name;
}
+ return 'ok';
}
sub get_version {
@@ -189,6 +237,10 @@ sub get_version {
sub add_previous_version_button {
my ($status)=@_;
+ my (undef,undef,$udom,$uname)=&Apache::lonnet::whichuser();
+ if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
+ return;
+ }
my $result;
if ($Apache::lonhomework::history{'resource.0.version'} eq '') {
return '';
@@ -225,7 +277,10 @@ sub add_previous_version_button {
}
sub add_grading_button {
- my (undef,$cid)=&Apache::lonnet::whichuser();
+ my (undef,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
+ if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
+ return;
+ }
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
my %sections = &Apache::loncommon::get_sections($cdom,$cnum);
@@ -234,36 +289,56 @@ sub add_grading_button {
if (scalar(keys(%sections)) < 3) {
$size=scalar(keys(%sections))+2;
}
- my $sec_select = '\n";
+
+ my $uri=$env{'request.uri'};
+ if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
+ my $result =
+ '
'."\n";
+ }
+ $result .= ''."\n";
+ return $result;
+}
+
+sub add_slotlist_button {
+ my (undef,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
+ if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
+ return;
+ }
+ my $symb=&Apache::lonnet::symbread();
+ my $result;
+ if (&Apache::lonnet::allowed('mgq',$env{'request.course.id'}) ||
+ &Apache::lonnet::allowed('mgq',$env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
+ $result = '';
+ my $target_id =
+ &Apache::lonstathelpers::make_target_id({symb => $symb,
+ part => '0'});
+ if (!§ion_restricted()) {
+ $result.='';
+ }
}
return $result;
}
sub add_request_another_attempt_button {
my ($text)=@_;
- if (!$text) { $text="Request another attempt"; }
+ my (undef,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
+ if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
+ return;
+ }
+ if (!$text) { $text=&mt('Request another attempt'); }
my $result;
my $symb=&Apache::lonnet::symbread();
# not a slot access based resource
@@ -290,23 +400,25 @@ sub add_request_another_attempt_button {
my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
my $action='get_reservation';
if ($slot_name) {
- $text="Change reservation.";
+ $text=&mt('Change reservation');
$action='change_reservation';
my $description=&Apache::slotrequest::get_description($slot_name,
$slot);
- $result.=(< Will be next available: $description
-STUFF
+ $result.='
'
+ .&mt('Will be next available:')
+ .' '.$description
+ .'
';
}
if ($status eq 'CLOSED' || $status eq 'INVALID_ACCESS') {
$msg.='The problem '.$accessmsg;
}
$result.=$msg.' ';
} elsif ($target eq 'tex') {
- $result.='\begin{document}\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
+ $result.='\noindent \vskip 1 mm \begin{minipage}{\textwidth}\vskip 0 mm';
if ($status eq 'UNAVAILABLE') {
$result.=&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'\vskip 0 mm ';
} else {
@@ -669,8 +841,8 @@ sub start_Task {
} elsif ($target eq 'web') {
$result.=&preserve_grade_info();
- $result.=&internal_location();
- $result.=$form_tag_start.
+ $result.=&internal_location();
+ $result.=$form_tag_start."\t".
'';
&Apache::lonxml::startredirection();
}
@@ -678,24 +850,25 @@ sub start_Task {
$target eq 'webgrade') {
my $webgrade='yes';
if ($target eq 'webgrade') {
+ $result .= '
'."\n";
$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,$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.'
'.
+ &mt('Grading [_1] for [_2] at [_3]',
+ &Apache::lonnet::gettitle($symb),$uname,$udom).'
';
$form_tag_start.=
'';
@@ -715,6 +888,11 @@ sub start_Task {
$result.=''.&mt("Stopped grading.").''.$back;
} elsif ($status_code eq 'cancel') {
$result.=''.&mt("Cancelled grading.").''.$back;
+ } elsif ($status_code eq 'terminated') {
+ $result.= ''.&mt('Terminated grading').' '.
+ ''.
+ &mt('Grading for [_1] has not been saved because of a grading key mismatch.',
+ ''.$env{'form.terminated'}.'').' '.$back;
} elsif ($status_code eq 'never_versioned') {
$result.=''.
&mt("Requested user has never accessed the task.").
@@ -761,26 +939,42 @@ sub start_Task {
$result.='';
}
- if ($env{'form.chosensections'}) {
- my @chosen_sections=
- &Apache::loncommon::get_env_multiple('form.chosensections');
+ if ($env{'form.chosensections'} || §ion_restricted()) {
+ my @chosen_sections = &get_allowed_sections();
foreach my $sec (@chosen_sections) {
$result.='';
}
}
if ($webgrade eq 'yes') { $result.=&webgrade_standard_info(); }
+ } elsif ($target eq 'webgrade'
+ && $env{'request.state'} eq 'construct') {
+ $result.=$form_tag_start;
+ $result.='';
+ $result.=&webgrade_standard_info();
}
if ($target eq 'webgrade') {
$result.="\n".'
';
+ &Apache::lonxml::startredirection();
+ &start_delay();
+ $dimension{$top}{'result'}=$result;
+ undef($result);
}
} 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;
+ $result.= &Apache::edit::text_arg('Required number of passed optional elements to pass the Task:','OptionalRequired',$token,10)." \n";
+ $result.= &Apache::edit::insertlist($target,$token);
+ } elsif ($target eq 'modified') {
+ my $constructtag=
+ &Apache::edit::get_new_args($token,$parstack,$safeeval,
+ 'OptionalRequired');
+ if ($constructtag) {
+ $result = &Apache::edit::rebuild_tag($token);
+ }
} else {
# page_start returned a starting result, delete it if we don't need it
$result = '';
@@ -806,6 +1000,12 @@ sub get_key_todo {
my ($target)=@_;
my $todo;
+ if ($env{'request.state'} eq 'construct') {
+ my ($symb,$cid,$udom,$uname) = &Apache::lonnet::whichuser();
+ my $gradingkey=&encode_queue_key($symb,$udom,$uname);
+ return ($gradingkey);
+ }
+
if (defined($env{'form.reviewasubmission'})) {
&Apache::lonxml::debug("review a submission....");
$env{'form.queue'}='reviewqueue';
@@ -834,9 +1034,16 @@ sub get_key_todo {
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 $uname = &LONCAPA::clean_username($env{'form.gradinguser'});
+ my $udom = &LONCAPA::clean_domain($env{'form.gradingdomain'});
+
+ if (§ion_restricted()) {
+ my $classlist=&get_limited_classlist();
+ if (!&allow_grade_user($classlist->{$uname.':'.$udom})) {
+ return (undef,'not_allowed',
+ &mt("Requested student ([_1]) is in a section you aren't allowed to grade.",$uname.':'.$udom));
+ }
+ }
my $gradingkey=&encode_queue_key($symb,$udom,$uname);
my $queue;
@@ -906,6 +1113,8 @@ sub get_key_todo {
return (undef,'stop');
} elsif ($env{'form.cancel'}) {
return (undef,'cancel');
+ } elsif ($env{'form.terminated'}) {
+ return (undef, 'terminated');
} elsif ($env{'form.next'}) {
return (undef,'select_user');
}
@@ -951,13 +1160,17 @@ sub get_key_todo {
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'})
+ if (!(($env{'form.cancel'} || $env{'form.stop'} || $env{'form.terminated'})
&& $target eq 'webgrade')
&& !$env{'form.gradingaction'}) {
&Apache::lonxml::debug("Getting anew $queue");
return (&get_from_queue($queue));
} else {
- return (undef,'stop');
+ if ($env{'form.terminated'}) {
+ return (undef,'terminated');
+ } else {
+ return (undef,'stop');
+ }
}
}
return (undef,undef)
@@ -987,32 +1200,44 @@ sub end_Task {
}
if ($status eq 'CAN_ANSWER' && !$previous &&
!$env{'form.donescreen'}) {
- $result.="\n".'
'.
+ my ($portheader,$porttext);
+ if ($Apache::lonhomework::history{"resource.$version.0.bridgetask.portfiles"}) {
+ $portheader = &mt('Submit Additional Portfolio Files for Grading');
+ $porttext = &mt('Indicate which additional files from your portfolio are to be evaluated in grading this task.');
+ } else {
+ $portheader = &mt('Submit Portfolio Files for Grading');
+ $porttext = &mt('Indicate the files from your portfolio to be evaluated in grading this task.');
+ }
+ $result.="\n".'
You did not pass the '.$title.' given on '.
- $start_time.'
';
+ $status.='
'
+ .&mt('You did not pass the [_1] given on [_2].',$title,$start_time)
+ .'
';
+ $status.=$question_status;
if (!$previous) {
$status.=&add_request_another_attempt_button();
}
}
- my $man_count=0;
- my $opt_count=0;
- my $opt_passed=0;
- foreach my $dim (keys(%Apache::bridgetask::top_dimensionlist)) {
- if ($Apache::bridgetask::top_dimensionlist{$dim}{'manadatory'}
- eq 'N') {
- $opt_count++;
- if ($Apache::lonhomework::history{"resource.$version.0.$dim.status"} eq 'pass') {
- $opt_passed++;
- }
- } else {
- $man_count++;
+
+ $status.="\n".'
'."\n";
+
+ foreach my $id (@{$dimension{$dim}{'criterias'}}) {
+ my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
+ if ($type eq 'dimension') {
+ $result.=$dimension{$id}{'result'};
+ next;
}
+ my $criteria =
+ &nested_parse(\$dimension{$dim}{'criteria.'.$id},
+ [@_]);
+ $status .= &layout_web_Criteria($dim,$id,$criteria);
}
-
- 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/;
}
$result.="\n
".
+ $result.=
&Apache::loncommon::start_data_table().
&Apache::loncommon::start_data_table_header_row();
- if ($with_selects) { $result.="
Status
"; }
- $result.="
user
data
".
+ if ($with_selects) { $result.='
'.&mt('Status').'
'; }
+ $result.='
'.&mt('User').'
'.&mt('Data').'
'.
&Apache::loncommon::end_data_table_header_row();
foreach my $key (sort(keys(%queue))) {
my ($symb,$uname,$udom) = &decode_queue_key($key);
- if (!defined($classlist->{$uname.':'.$udom})) { next; }
+ next if (!defined($classlist->{$uname.':'.$udom}));
+ next if (!&allow_grade_user($classlist->{$uname.':'.$udom}));
my $section = $classlist->{$uname.':'.$udom}[&Apache::loncoursedata::CL_SECTION()];
@@ -1503,9 +1817,16 @@ sub show_queue {
my $ekey=&escape($key);
my ($action,$description,$status)=('select',&mt('Select'));
if (exists($queue{"$key\0locked"})) {
+ my ($locker,$time) =
+ &get_lock_info($queue{"$key\0locked"});
+ if ($time) {
+ $time =
+ &Apache::lonnavmaps::timeToHumanString($time,
+ 'start');
+ }
my $me=$env{'user.name'}.':'.$env{'user.domain'};
- $status=&mt('Locked by [_1]',$queue{"$key\0locked"});
- if ($me eq $queue{"$key\0locked"}) {
+ $status=&mt('Locked by [_1] [_2]',''.$locker.'',$time);
+ if ($me eq $locker) {
($action,$description)=('resume',&mt('Resume'));
} else {
($action,$description)=('unlock',&mt('Unlock'));
@@ -1520,7 +1841,7 @@ sub show_queue {
$result.=(<