--- loncom/homework/bridgetask.pm 2006/11/07 21:31:22 1.196
+++ loncom/homework/bridgetask.pm 2016/08/31 19:08:18 1.267
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.196 2006/11/07 21:31:22 albertel Exp $
+# $Id: bridgetask.pm,v 1.267 2016/08/31 19:08:18 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,13 +37,13 @@ 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;
@@ -83,7 +83,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,19 +95,31 @@ 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 =
@@ -112,20 +127,43 @@ sub check_in_sequence {
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 $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') {
@@ -159,11 +197,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 +229,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 +269,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 +281,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";
+ 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 +392,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
+ .'
'.
+ &mt('Grading [_1] for [_2] at [_3]',
+ &Apache::lonnet::gettitle($symb),$uname,$udom).'
';
$form_tag_start.=
'';
@@ -724,6 +880,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.").
@@ -770,27 +931,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 = '';
@@ -816,6 +992,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';
@@ -844,9 +1026,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;
@@ -916,6 +1105,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');
}
@@ -961,13 +1152,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)
@@ -997,32 +1192,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".'
';
- my $man_count=0;
- my $man_passed=0;
- my $opt_count=0;
- my $opt_passed=0;
- my $dim = $top;
- foreach my $id (@{$dimension{$dim}{'criterias'}}) {
- my $status = &get_criteria('status',$version,$dim,$id);
- if ($dimension{$dim}{'criteria.'.$id.'.mandatory'}
- eq 'N') {
- $opt_count++;
- if ($status eq 'pass') {
- $opt_passed++;
- }
- } else {
- $man_count++;
- if ($status eq 'pass') { $man_passed++; }
- }
- }
- if ($man_passed eq $man_count) { $man_passed='all'; }
-
- 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";
-
+
+ $status.="\n".'
'."\n";
foreach my $id (@{$dimension{$dim}{'criterias'}}) {
my $type = $dimension{$dim}{'criteria.'.$id.'.type'};
@@ -1095,7 +1289,9 @@ DONEBUTTON
}
$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()];
@@ -1558,9 +1809,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'));
@@ -1575,7 +1833,7 @@ sub show_queue {
$result.=(<