--- loncom/homework/bridgetask.pm 2005/10/14 16:23:39 1.70
+++ loncom/homework/bridgetask.pm 2007/01/11 19:01:38 1.218
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.70 2005/10/14 16:23:39 albertel Exp $
+# $Id: bridgetask.pm,v 1.218 2007/01/11 19:01:38 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -38,50 +38,52 @@ use Apache::lonlocal;
use Apache::lonxml;
use Apache::slotrequest();
use Time::HiRes qw( gettimeofday tv_interval );
+use lib '/home/httpd/lib/perl/';
+use LONCAPA;
+
BEGIN {
- &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Instance','InstanceText','Criteria','ClosingParagraph'));
+ &Apache::lonxml::register('Apache::bridgetask',('Task','IntroParagraph','Dimension','Question','QuestionText','Setup','Instance','InstanceText','Criteria','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::dimensionlist=();
- # mandatory attribute of all Dimensions seen
- %Apache::bridgetask::dimensionmandatory=();
+ @Apache::bridgetask::dimension=();
# list of all current Instance ids
- @Apache::bridgetask::instance=();
+ %Apache::bridgetask::instance=();
# list of all Instance ids seen in this problem
@Apache::bridgetask::instancelist=();
# key of queud user data that we are currently grading
$Apache::bridgetask::queue_key='';
+ undef(%dimension);
}
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) {
+ &check_in($type,$user,$domain,$slot_name);
return 1;
}
}
@@ -89,15 +91,95 @@ sub proctor_check_auth {
return 0;
}
+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);
+ } else {
+ &create_new_version($type,$user,$domain,$slot_name);
+ &Apache::structuretags::finalize_storage();
+ }
+ return 1;
+}
+
+sub check_in_sequence {
+ my ($user,$domain,$slot_name) = @_;
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ my ($symb) = &Apache::lonnet::whichuser();
+ my ($map) = &Apache::lonnet::decode_symb($symb);
+ my @resources =
+ $navmap->retrieveResources($map, sub { $_[0]->is_problem() },0,0);
+ my %old_history = %Apache::lonhomework::history;
+ my %old_results = %Apache::lonhomework::results;
+
+ 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);
+ }
+
+ %Apache::lonhomework::history = %old_history;
+ %Apache::lonhomework::results = %old_results;
+}
+
+sub create_new_version {
+ my ($type,$user,$domain,$slot_name) = @_;
+
+ my $id = '0';
+ 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;
+ $id = "$version.0";
+ if (!defined($user) || !defined($domain)) {
+ $user = $env{'user.name'};
+ $domain = $env{'user.domain'};
+ }
+
+ } elsif ($type eq 'problem') {
+ &Apache::lonxml::debug("authed $slot_name");
+ }
+ if (!defined($user) || !defined($domain)) {
+ $user = $env{'user.name'};
+ $domain = $env{'user.domain'};
+ }
+
+ $Apache::lonhomework::results{"resource.$id.checkedin"}=
+ $user.':'.$domain;
+
+ if (defined($slot_name)) {
+ $Apache::lonhomework::results{"resource.$id.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 +191,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 +205,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 +214,7 @@ sub add_previous_version_button {
join("\n\n";
$list.='';
- $result.='
+
Will be next available: $description
STUFF
}
if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
- $symb=&Apache::lonnet::escape($symb);
- $result.='';
+ &mt($text).'" />'."\n\t".
+ ''."\n";
return $result;
}
@@ -222,64 +332,27 @@ sub preserve_grade_info {
}
sub style {
- return (<
+ my ($target) = @_;
+ if ($target eq 'web'
+ || $target eq 'webgrade') {
+ my $style = (<
STYLE
-
+ if ($env{'browser.type'} eq 'explorer'
+ && $env{'browser.os'} eq 'win' ) {
+ if ($env{'browser.version'} < 7) {
+ $style .= (<
+STYLE
+ } else {
+ $style .= (<
+STYLE
+ }
+ }
+ return $style;
+ }
+ return;
}
sub show_task {
@@ -291,127 +364,300 @@ sub show_task {
( $status eq 'NOT_IN_A_SLOT') ||
( $status eq 'NEEDS_CHECKIN') ||
( $status eq 'WAITING_FOR_GRADE') ||
- ( $status eq 'INVALID_ACCESS') )) {
+ ( $status eq 'INVALID_ACCESS') ||
+ ( &get_version() eq ''))) {
return 0;
}
if ($env{'form.donescreen'}) { return 0; }
return 1;
}
+my @delay;
+sub nest {
+ if (@delay) {
+ return $delay[-1];
+ } else {
+ return;
+ }
+}
+
+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;
+ @Apache::scripttag::parser_env = @$env;
+ if (exists($args->{'set_dim_id'})) {
+ &enable_dimension_parsing($args->{'set_dim_id'});
+ }
+ push(@delay,(($args->{'delayed_dim_results'})? 1 : 0));
+ my $result = &Apache::scripttag::xmlparse($$str);
+ pop(@delay);
+ if (exists($args->{'set_dim_id'})) {
+ &disable_dimension_parsing();
+ }
+ @Apache::scripttag::parser_env = @old_env;
+ if ($args->{'delayed_dim_results'}) {
+ my $dim = &get_dim_id();
+ &Apache::lonxml::debug(" tossing out $result ");
+ &Apache::lonxml::debug(" usining out $dim 's ". $dimension{$dim}{'result'});
+ return $dimension{$dim}{'result'};
+ }
+ return $result;
+}
+
sub internal_location {
my ($id)=@_;
return '';
}
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.version'};
+ my $version=$Apache::lonhomework::history{'resource.0.version'};
for (my $v=$Apache::lonhomework::history{'version'};$v>0;$v--) {
- if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})) {
+ if (defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.bridgetask.portfiles'})
+ && defined($Apache::lonhomework::history{$v.':resource.'.$version.'.0.tries'})) {
$submissiontime=$Apache::lonhomework::history{$v.':timestamp'};
+ last;
}
}
my $result;
if ($submissiontime) {
- my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.checkedin.slot'};
+ my $slot_name=$Apache::lonhomework::history{'resource.'.$version.'.0.checkedin.slot'};
my %slot=&Apache::lonnet::get_slot($slot_name);
my $diff = $slot{'endtime'} - $submissiontime;
- my ($color,$when)=('red','after');
- if ($diff > 0) { ($color,$when)=('green','before'); }
+ my ($color,$when)=('#FF6666','after');
+ if ($diff > 0) { ($color,$when)=('#336600','before'); }
my $info;
+ $diff = abs($diff);
if ($diff%60) { $info=($diff%60).' seconds'; }
$diff=int($diff/60);
if ($diff%60) { $info=($diff%60).' minutes '.$info; }
$diff=int($diff/60);
if ($diff) { $info=$diff.' hours '.$info; }
$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'}))).
+ &mt('Student submitted [_1] [_2] the deadline. '.
+ '(Submission was at [_3], end of period was [_4].)',
+ $info,$when,
+ &Apache::lonlocal::locallocaltime($submissiontime),
+ &Apache::lonlocal::locallocaltime($slot{'endtime'})).
'
';
}
return $result;
}
-sub webgrade_standard_info {
- my ($version)=&get_version();
- my (undef,undef,$udom,$uname) = &Apache::lonxml::whichuser();
+sub file_list {
+ my ($files,$uname,$udom) = @_;
+ if (!defined($uname) || !defined($udom)) {
+ (undef,undef,$udom,$uname) = &Apache::lonnet::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_list="
\n";
+ foreach my $partial_file (split(',',$files)) {
my $file=$file_url.$partial_file;
$file=~s|/+|/|g;
&Apache::lonnet::allowuploaded('/adm/bridgetask',$file);
- $file_list.='
$file_list
-
INFO
return $result;
}
+sub done_screen {
+ my ($version) = @_;
+ my $title=&Apache::lonnet::gettitle();
+ my @files=split(',',$Apache::lonhomework::history{'resource.'.$version.'.0.bridgetask.portfiles'});
+ my (undef,undef,$domain,$user)= &Apache::lonnet::whichuser();
+ my $files = '
';
+ my $msg;
+ foreach my $file (@files) {
+ my $url="/uploaded/$domain/$user/portfolio$file";
+ if (! &Apache::lonnet::stat_file($url)) {
+ $file = &mt(' Nonexistent file: '.
+ '[_1]',$file);
+ $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 $files='
'."\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);
if ($todo) {
&setup_env_for_other_user($todo,$safeeval);
@@ -487,38 +728,55 @@ DONESCREEN
&Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'';
$form_tag_start.=
'';
+ &escape($todo).'" />';
$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='
You did not pass the '.$title.' given on '.
- $start_time.'.
';
+ $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_id (@Apache::bridgetask::dimensionlist) {
- if ($Apache::bridgetask::dimensionmandatory{$dim_id}
- eq 'N') {
- $opt_count++;
- if ($Apache::lonhomework::history{"resource.$version.$dim_id.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 on the bridge task.',$man_count,$opt_req,$opt_count)."
\n";
my $internal_location=&internal_location();
$result=~s/\Q$internal_location\E/$status/;
}
- }
- if ($target eq 'web' || $target eq 'webgrade') {
- $result.=&Apache::lonxml::xmlend().'