--- loncom/homework/bridgetask.pm 2006/11/06 17:50:17 1.184.2.4
+++ loncom/homework/bridgetask.pm 2017/06/21 19:55:00 1.264.4.1
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.184.2.4 2006/11/06 17:50:17 albertel Exp $
+# $Id: bridgetask.pm,v 1.264.4.1 2017/06/21 19:55:00 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
@@ -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);
+ if ($check =~ /^error:/) {
+ return 0;
+ }
return 1;
}
}
@@ -95,9 +98,13 @@ 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);
+ my $result = &check_in_sequence($user,$domain,$slot_name);
+ if ($result =~ /^error: /) {
+ return $result;
+ }
} else {
&create_new_version($type,$user,$domain,$slot_name);
+ &Apache::structuretags::finalize_storage();
}
return 1;
}
@@ -105,7 +112,10 @@ sub check_in {
sub check_in_sequence {
my ($user,$domain,$slot_name) = @_;
my $navmap = Apache::lonnavmaps::navmap->new();
- my ($symb) = &Apache::lonxml::whichuser();
+ if (!defined($navmap)) {
+ return 'error: ';
+ }
+ my ($symb) = &Apache::lonnet::whichuser();
my ($map) = &Apache::lonnet::decode_symb($symb);
my @resources =
$navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
@@ -189,6 +199,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 +239,10 @@ sub add_previous_version_button {
}
sub add_grading_button {
- my (undef,$cid)=&Apache::lonxml::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 +251,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 +362,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 ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
$symb=&escape($symb);
- $result.='';
+ $text.'" />'."\n\t".
+ ''."\n";
return $result;
}
@@ -353,6 +427,7 @@ sub show_task {
( $status eq 'BANNED') ||
( $status eq 'UNAVAILABLE') ||
( $status eq 'NOT_IN_A_SLOT') ||
+ ( $status eq 'NOT_YET_VIEWED') ||
( $status eq 'NEEDS_CHECKIN') ||
( $status eq 'WAITING_FOR_GRADE') ||
( $status eq 'INVALID_ACCESS') ||
@@ -372,6 +447,13 @@ sub nest {
}
}
+sub start_delay {
+ push(@delay,1);
+}
+sub end_delay {
+ pop(@delay);
+}
+
sub nested_parse {
my ($str,$env,$args) = @_;
my @old_env = @Apache::scripttag::parser_env;
@@ -401,7 +483,7 @@ sub internal_location {
}
sub submission_time_stamp {
- my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser();
+ 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--) {
@@ -439,7 +521,7 @@ sub submission_time_stamp {
sub file_list {
my ($files,$uname,$udom) = @_;
if (!defined($uname) || !defined($udom)) {
- (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
+ (undef,undef,$udom,$uname) = &Apache::lonnet::whichuser();
}
my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio/';
@@ -448,7 +530,7 @@ sub file_list {
my $file=$file_url.$partial_file;
$file=~s|/+|/|g;
&Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
- $file_list.='
';
}
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 {
@@ -682,8 +797,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();
}
@@ -691,24 +806,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.=
'';
@@ -728,6 +844,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.").
@@ -774,26 +895,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 = '';
@@ -819,6 +956,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,12 +987,19 @@ sub get_key_todo {
if (defined($env{'form.regradeaspecificsubmission'}) &&
defined($env{'form.gradinguser'}) &&
defined($env{'form.gradingdomain'}) ) {
- my ($symb,$cid)=&Apache::lonxml::whichuser();
+ 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;
@@ -919,6 +1069,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');
}
@@ -964,13 +1116,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)
@@ -1000,32 +1156,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.=' ';
#$result.='{$student}[&Apache::loncoursedata::CL_SECTION()];
- if (! grep($section,@{ $sections })) {
+ if (! grep {$_ eq $section} (@{ $sections })) {
delete($classlist->{$student});
}
}
@@ -1437,18 +1687,19 @@ sub get_limited_classlist {
sub show_queue {
my ($queue,$with_selects)=@_;
my $result;
- my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
+ my ($symb,$cid,$udom,$uname)=&Apache::lonnet::whichuser();
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
- my @chosen_sections=
- &Apache::loncommon::get_env_multiple('form.chosensections');
+ my @chosen_sections = &get_allowed_sections();
my $classlist = &get_limited_classlist(\@chosen_sections);
if (!(grep(/^all$/,@chosen_sections))) {
- $result.='
Showing only sections '.join(', ',@chosen_sections).
- '.
".
+ $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()];
@@ -1516,9 +1773,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'));
@@ -1533,7 +1797,7 @@ sub show_queue {
$result.=(<