+'.&mt('Unable to retrieve a resource from a server:').'
+'.&mt('Resource:').' '.$ssi_error_resource.'
+'.&mt('Error:').' '.$ssi_error_message.'
+
+
'.
+&mt('It is recommended that you try again later, as this error may mean the server was just temporarily unavailable, or is down for maintenance.').' '.
+&mt('If the error persists, please contact the [_1] for assistance.',$helpurl).
+'
');
+ return;
+}
+
+#
+# --- Retrieve the parts from the metadata file.---
+# Returns an array of everything that the resources stores away
#
-# --- Retrieve the parts that matches stores_\d+ from the metadata file.---
+
sub getpartlist {
- my ($url) = @_;
- my @parts =();
- my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
- foreach my $key (@metakeys) {
- if ( $key =~ m/stores_(\w+)_.*/) {
- push(@parts,$key);
- }
- }
- return @parts;
-}
-
-# --- Get the symbolic name of a problem and the url
-sub get_symb_and_url {
- my ($request) = @_;
- (my $url=$ENV{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
- if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
- return ($symb,$url);
-}
-
-# --- Retrieve the fullname for a user. Return lastname, first middle ---
-# --- Generation is attached next to the lastname if it exists. ---
-sub get_fullname {
- my ($uname,$udom) = @_;
- my %name=&Apache::lonnet::get('environment', ['lastname','generation',
- 'firstname','middlename'],
- $udom,$uname);
- my $fullname;
- my ($tmp) = keys(%name);
- if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
- $fullname = &Apache::loncoursedata::ProcessFullName
- (@name{qw/lastname generation firstname middlename/});
+ my ($symb,$errorref) = @_;
+
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($errorref)) {
+ $$errorref = 'navmap';
+ return;
+ }
+ }
+ my $res = $navmap->getBySymb($symb);
+ my $partlist = $res->parts();
+ my $url = $res->src();
+ my @metakeys = split(/,/,&Apache::lonnet::metadata($url,'keys'));
+
+ my @stores;
+ foreach my $part (@{ $partlist }) {
+ foreach my $key (@metakeys) {
+ if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
+ }
+ }
+ return @stores;
+}
+
+#--- Format fullname, username:domain if different for display
+#--- Use anywhere where the student names are listed
+sub nameUserString {
+ my ($type,$fullname,$uname,$udom) = @_;
+ if ($type eq 'header') {
+ return ' '.&mt('Fullname').' ('.&mt('Username').')';
} else {
- &Apache::lonnet::logthis('grades.pm: no name data for '.$uname.
- '@'.$udom.':'.$tmp);
+ return ' '.$fullname.' ('.$uname.
+ ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')';
}
- return $fullname;
}
#--- Get the partlist and the response type for a given problem. ---
#--- Indicate if a response type is coded handgraded or not. ---
sub response_type {
- my ($url) = shift;
- my $allkeys = &Apache::lonnet::metadata($url,'keys');
- my %seen = ();
- my (@partlist,%handgrade);
- foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
- if (/^\w+response_\w+.*/) {
- my ($responsetype,$part) = split(/_/,$_,2);
- my ($partid,$respid) = split(/_/,$part);
- $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
- $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
- next if ($seen{$partid} > 0);
- $seen{$partid}++;
- push @partlist,$partid;
- }
- }
- return \@partlist,\%handgrade;
-}
-
-#--- Show resource title
-#--- and parts and response type
-sub showResourceInfo {
- my ($url,$probTitle) = @_;
- my $result ='
'.
- '
Current Resource: '.$probTitle.'
'."\n";
- my ($partlist,$handgrade) = &response_type($url);
- my ($resptype,$hdgrade)=('','no');
- for (sort keys(%$handgrade)) {
- my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
- $resptype = $responsetype;
- $hdgrade = $handgrade if ($handgrade eq 'yes');
- $result.='
Part '.(split(/_/))[0].'
'.
- '
Type: '.$responsetype.'
';
-# '
Handgrade: '.$handgrade.'
';
+ my ($symb,$response_error) = @_;
+
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ unless (ref($navmap)) {
+ if (ref($response_error)) {
+ $$response_error = 1;
+ }
+ return;
+ }
+ my $res = $navmap->getBySymb($symb);
+ unless (ref($res)) {
+ $$response_error = 1;
+ return;
+ }
+ my $partlist = $res->parts();
+ my %vPart =
+ map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart'));
+ my (%response_types,%handgrade);
+ foreach my $part (@{ $partlist }) {
+ next if (%vPart && !exists($vPart{$part}));
+
+ my @types = $res->responseType($part);
+ my @ids = $res->responseIds($part);
+ for (my $i=0; $i < scalar(@ids); $i++) {
+ $response_types{$part}{$ids[$i]} = $types[$i];
+ $handgrade{$part.'_'.$ids[$i]} =
+ &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i].
+ '.handgrade',$symb);
+ }
+ }
+ return ($partlist,\%handgrade,\%response_types);
+}
+
+sub flatten_responseType {
+ my ($responseType) = @_;
+ my @part_response_id =
+ map {
+ my $part = $_;
+ map {
+ [$part,$_]
+ } sort(keys(%{ $responseType->{$part} }));
+ } sort(keys(%$responseType));
+ return @part_response_id;
+}
+
+sub get_display_part {
+ my ($partID,$symb)=@_;
+ my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
+ if (defined($display) and $display ne '') {
+ $display.= ' ('
+ .&mt('Part ID: [_1]',$partID).')';
+ } else {
+ $display=$partID;
+ }
+ return $display;
+}
+
+sub reset_caches {
+ &reset_analyze_cache();
+ &reset_perm();
+}
+
+{
+ my %analyze_cache;
+ my %analyze_cache_formkeys;
+
+ sub reset_analyze_cache {
+ undef(%analyze_cache);
+ undef(%analyze_cache_formkeys);
+ }
+
+ sub get_analyze {
+ my ($symb,$uname,$udom,$no_increment,$add_to_hash)=@_;
+ my $key = "$symb\0$uname\0$udom";
+ if (exists($analyze_cache{$key})) {
+ my $getupdate = 0;
+ if (ref($add_to_hash) eq 'HASH') {
+ foreach my $item (keys(%{$add_to_hash})) {
+ if (ref($analyze_cache_formkeys{$key}) eq 'HASH') {
+ if (!exists($analyze_cache_formkeys{$key}{$item})) {
+ $getupdate = 1;
+ last;
+ }
+ } else {
+ $getupdate = 1;
+ }
+ }
+ }
+ if (!$getupdate) {
+ return $analyze_cache{$key};
+ }
+ }
+
+ my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
+ $url=&Apache::lonnet::clutter($url);
+ my %form = ('grade_target' => 'analyze',
+ 'grade_domain' => $udom,
+ 'grade_symb' => $symb,
+ 'grade_courseid' => $env{'request.course.id'},
+ 'grade_username' => $uname,
+ 'grade_noincrement' => $no_increment);
+ if (ref($add_to_hash)) {
+ %form = (%form,%{$add_to_hash});
+ }
+ my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
+ (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
+ my %analyze=&Apache::lonnet::str2hash($subresult);
+ if (ref($add_to_hash) eq 'HASH') {
+ $analyze_cache_formkeys{$key} = $add_to_hash;
+ } else {
+ $analyze_cache_formkeys{$key} = {};
+ }
+ return $analyze_cache{$key} = \%analyze;
+ }
+
+ sub get_order {
+ my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom,$no_increment);
+ return $analyze->{"$partid.$respid.shown"};
+ }
+
+ sub get_radiobutton_correct_foil {
+ my ($partid,$respid,$symb,$uname,$udom)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom);
+ my $foils = &get_order($partid,$respid,$symb,$uname,$udom);
+ if (ref($foils) eq 'ARRAY') {
+ foreach my $foil (@{$foils}) {
+ if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
+ return $foil;
+ }
+ }
+ }
}
- $result.='
'."\n";
- return $result,$resptype,$hdgrade,$partlist,$handgrade;
+
+ sub scantron_partids_tograde {
+ my ($resource,$cid,$uname,$udom,$check_for_randomlist) = @_;
+ my (%analysis,@parts);
+ if (ref($resource)) {
+ my $symb = $resource->symb();
+ my $add_to_form;
+ if ($check_for_randomlist) {
+ $add_to_form = { 'check_parts_withrandomlist' => 1,};
+ }
+ my $analyze = &get_analyze($symb,$uname,$udom,undef,$add_to_form);
+ if (ref($analyze) eq 'HASH') {
+ %analysis = %{$analyze};
+ }
+ if (ref($analysis{'parts'}) eq 'ARRAY') {
+ foreach my $part (@{$analysis{'parts'}}) {
+ my ($id,$respid) = split(/\./,$part);
+ if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
+ push(@parts,$part);
+ }
+ }
+ }
+ }
+ return (\%analysis,\@parts);
+ }
+
}
#--- Clean response type for display
-#--- Currently filters option response type only.
+#--- Currently filters option/rank/radiobutton/match/essay/Task
+# response types only.
sub cleanRecord {
- my ($answer,$response) = @_;
- if ($response eq 'option') {
- my (@IDs,@ans);
- foreach (split(/\&/,&Apache::lonnet::unescape($answer))) {
- my ($optionID,$ans) = split(/=/);
- push @IDs,$optionID.'';
- push @ans,$ans;
- }
- my $grayFont = '';
- return '
'.
- '
Answer
'.
- (join '
',@ans).'
'.
- '
'.$grayFont.'Option ID
'.$grayFont.
- (join '
'.$grayFont,@IDs).'
'.
- '
';
+ my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
+ $uname,$udom) = @_;
+ my $grayFont = '';
+ if ($response =~ /^(option|rank)$/) {
+ my %answer=&Apache::lonnet::str2hash($answer);
+ my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
+ my ($toprow,$bottomrow);
+ foreach my $foil (@$order) {
+ if ($grading{$foil} == 1) {
+ $toprow.='
'.$answer{$foil}.'
';
+ } else {
+ $toprow.='
'.$answer{$foil}.'
';
+ }
+ $bottomrow.='
'.$grayFont.$foil.'
';
+ }
+ return '
'.
+ '
'.&mt('Answer').'
'.$toprow.'
'.
+ '
'.$grayFont.&mt('Option ID').'
'.
+ $grayFont.$bottomrow.'
'.'
';
+ } elsif ($response eq 'match') {
+ my %answer=&Apache::lonnet::str2hash($answer);
+ my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
+ my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
+ my ($toprow,$middlerow,$bottomrow);
+ foreach my $foil (@$order) {
+ my $item=shift(@items);
+ if ($grading{$foil} == 1) {
+ $toprow.='
'.$item.'
';
+ $middlerow.='
'.$grayFont.$answer{$foil}.'
';
+ } else {
+ $toprow.='
'.$item.'
';
+ $middlerow.='
'.$grayFont.$answer{$foil}.'
';
+ }
+ $bottomrow.='
'.$grayFont.$foil.'
';
+ }
+ return '
'.
+ '
'.&mt('Answer').'
'.$toprow.'
'.
+ '
'.$grayFont.&mt('Item ID').'
'.
+ $middlerow.'
'.
+ '
'.$grayFont.&mt('Option ID').'
'.
+ $bottomrow.'
'.'
';
+ } elsif ($response eq 'radiobutton') {
+ my %answer=&Apache::lonnet::str2hash($answer);
+ my ($toprow,$bottomrow);
+ my $correct =
+ &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
+ foreach my $foil (@$order) {
+ if (exists($answer{$foil})) {
+ if ($foil eq $correct) {
+ $toprow.='
'.&mt('true').'
';
+ } else {
+ $toprow.='
'.&mt('true').'
';
+ }
+ } else {
+ $toprow.='
'.&mt('false').'
';
+ }
+ $bottomrow.='
'.$grayFont.$foil.'
';
+ }
+ return '
'.
+ '
'.&mt('Answer').'
'.$toprow.'
'.
+ '
'.$grayFont.&mt('Option ID').'
'.
+ $bottomrow.'
'.'
';
+ } elsif ($response eq 'essay') {
+ if (! exists ($env{'form.'.$symb})) {
+ my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
+
+ my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
+ $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
+ $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
+ $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
+ $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
+ $env{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
+ }
+ $answer =~ s-\n- -g;
+ return '
';
+ my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/,
+ keys(%{$record}));
+ foreach my $grade (sort(@grade)) {
+ my ($dim) = ($grade =~/[.]([^.]+)[.]status$/);
+ $result.= '
'.&mt("Dimension: [_1], status [_2] ",
+ $dim, $record->{$grade}).
+ '
';
+ }
+ $result.='
';
+ return $result;
+ }
+ } elsif ( $response =~ m/(?:numerical|formula)/) {
+ $answer =
+ &Apache::loncommon::format_previous_attempt_value('submission',
+ $answer);
}
return $answer;
}
@@ -161,8 +426,7 @@ sub cleanRecord {
#-- A couple of common js functions
sub commonJSfunctions {
my $request = shift;
- $request->print(<
+ $request->print(&Apache::lonhtmlcommon::scripttag(< 1) {
@@ -186,44 +450,96 @@ sub commonJSfunctions {
}
}
} else {
- if (selectOne.selected) return selectOne.value;
+ // only one value it must be the selected one
+ return selectOne.value;
}
}
-
COMMONJSFUNCTIONS
}
#--- Dumps the class list with usernames,list of sections,
#--- section, ids and fullnames for each user.
sub getclasslist {
- my ($getsec,$filterlist) = @_;
- my $classlist=&Apache::loncoursedata::get_classlist();
+ my ($getsec,$filterlist,$getgroup) = @_;
+ my @getsec;
+ my @getgroup;
+ my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
+ if (!ref($getsec)) {
+ if ($getsec ne '' && $getsec ne 'all') {
+ @getsec=($getsec);
+ }
+ } else {
+ @getsec=@{$getsec};
+ }
+ if (grep(/^all$/,@getsec)) { undef(@getsec); }
+ if (!ref($getgroup)) {
+ if ($getgroup ne '' && $getgroup ne 'all') {
+ @getgroup=($getgroup);
+ }
+ } else {
+ @getgroup=@{$getgroup};
+ }
+ if (grep(/^all$/,@getgroup)) { undef(@getgroup); }
+
+ my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist();
# Bail out if we were unable to get the classlist
return if (! defined($classlist));
+ &Apache::loncoursedata::get_group_memberships($classlist,$keylist);
#
my %sections;
my %fullnames;
- foreach (keys(%$classlist)) {
- # the following undefs are for 'domain', and 'username' respectively.
- my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
- @{$classlist->{$_}};
+ foreach my $student (keys(%$classlist)) {
+ my $end =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
+ my $start =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
+ my $id =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
+ my $section =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
+ my $fullname =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
+ my $status =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
+ my $group =
+ $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
# filter students according to status selected
- if ($filterlist && $ENV{'form.Status'} ne 'Any') {
- if ($ENV{'form.Status'} ne $status) {
- delete ($classlist->{$_});
+ if ($filterlist && (!($stu_status =~ /Any/))) {
+ if (!($stu_status =~ $status)) {
+ delete($classlist->{$student});
next;
}
}
- $section = ($section ne '' ? $section : 'no');
+ # filter students according to groups selected
+ my @stu_groups = split(/,/,$group);
+ if (@getgroup) {
+ my $exclude = 1;
+ foreach my $grp (@getgroup) {
+ foreach my $stu_group (@stu_groups) {
+ if ($stu_group eq $grp) {
+ $exclude = 0;
+ }
+ }
+ if (($grp eq 'none') && !$group) {
+ $exclude = 0;
+ }
+ }
+ if ($exclude) {
+ delete($classlist->{$student});
+ }
+ }
+ $section = ($section ne '' ? $section : 'none');
if (&canview($section)) {
- if ($getsec eq 'all' || $getsec eq $section) {
+ if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
$sections{$section}++;
- $fullnames{$_}=$fullname;
+ if ($classlist->{$student}) {
+ $fullnames{$student}=$fullname;
+ }
} else {
- delete($classlist->{$_});
+ delete($classlist->{$student});
}
} else {
- delete($classlist->{$_});
+ delete($classlist->{$student});
}
}
my %seen = ();
@@ -273,11 +589,11 @@ sub canview {
#--- Retrieve the grade status of a student for all the parts
sub student_gradeStatus {
- my ($url,$symb,$udom,$uname,$partlist) = @_;
- my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
+ my ($symb,$udom,$uname,$partlist) = @_;
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
my %partstatus = ();
foreach (@$partlist) {
- my ($status,$foo) = split(/_/,$record{"resource.$_.solved"},2);
+ my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
$status = 'nothing' if ($status eq '');
$partstatus{$_} = $status;
my $subkey = "resource.$_.submitted_by";
@@ -290,19 +606,18 @@ sub student_gradeStatus {
# Use by verifyscript and viewgrades
# Shows a student's view of problem and submission
sub jscriptNform {
- my ($url,$symb) = @_;
- my $jscript=''."\n";
+ "\n");
$jscript.= '\n";
+}
+
#--- Check whether a receipt number is valid.---
sub verifyreceipt {
- my $request = shift;
+ my ($request,$symb) = @_;
- my $courseid = $ENV{'request.course.id'};
- my $receipt = unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
- $ENV{'form.receipt'};
+ my $courseid = $env{'request.course.id'};
+ my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
+ $env{'form.receipt'};
$receipt =~ s/[^\-\d]//g;
- my $url = $ENV{'form.url'};
- my $symb = $ENV{'form.symb'};
- unless ($symb) {
- $symb = &Apache::lonnet::symbread($url);
- }
- my $title.='
Verifying Submission Receipt '.
- $receipt.'
'."\n".
- 'Resource: '.$ENV{'form.probTitle'}.'
'."\n";
+ my $title.=
+ '
'.
+ &mt('Verifying Receipt Number [_1]',$receipt).
+ '
'."\n";
my ($string,$contents,$matches) = ('','',0);
my (undef,undef,$fullname) = &getclasslist('all','0');
-
- foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
+
+ my $receiptparts=0;
+ if ($env{"course.$courseid.receiptalg"} eq 'receipt2' ||
+ $env{"course.$courseid.receiptalg"} eq 'receipt3') { $receiptparts=1; }
+ my $parts=['0'];
+ if ($receiptparts) {
+ my $res_error;
+ ($parts)=&response_type($symb,\$res_error);
+ if ($res_error) {
+ return &navmap_errormsg();
+ }
+ }
+
+ my $header =
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.
+ &mt('The above receipt number matches the following [quant,_1,student].',$matches).
+ '
'.
+ $header.
$contents.
- '
'."\n";
+ &Apache::loncommon::end_data_table()."\n";
}
- return $string.&show_grading_menu_form($symb,$url);
+ return $string;
}
#--- This is called by a number of programs.
@@ -415,26 +808,28 @@ sub verifyreceipt {
#--- Also called directly when one clicks on the subm button
# on the problem page.
sub listStudents {
- my ($request) = shift;
-
- my ($symb,$url) = &get_symb_and_url($request);
- my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"};
- my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"};
- my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
- my $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'};
-
- my $viewgrade = $ENV{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
- $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
- &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
+ my ($request,$symb) = @_;
- my $result='
'.$viewgrade.
- ' Submissions for a Student or a Group of Students
';
-
- my ($table,$resptype,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$ENV{'form.probTitle'});
- $result.=$table;
-
- $request->print(<
+ my $cdom = $env{"course.$env{'request.course.id'}.domain"};
+ my $cnum = $env{"course.$env{'request.course.id'}.num"};
+ my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
+ my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'};
+ my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
+ my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
+
+ my $result='
'
+ .&mt("$viewgrade Submissions for a Student or a Group of Students")
+ .'
';
+
+ my ($partlist,$handgrade,$responseType) = &response_type($symb
+#,$res_error
+ );
+
+ my %lt = &Apache::lonlocal::texthash (
+ 'multiple' => 'Please select a student or group of students before clicking on the Next button.',
+ 'single' => 'Please select the student before clicking on the Next button.',
+ );
+ $request->print(&Apache::lonhtmlcommon::scripttag(<
LISTJAVASCRIPT
&commonJSfunctions($request);
$request->print($result);
- my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
- my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
- my $gradeTable=''."\n";
+ $gradeTable.=&Apache::loncommon::end_data_table()."\n".
+ ''."\n";
if ($ctr == 0) {
my $num_students=(scalar(keys(%$fullname)));
if ($num_students eq 0) {
- $gradeTable=' There are no students currently enrolled.';
+ $gradeTable=' '.&mt('There are no students currently enrolled.').'';
} else {
- $gradeTable=' '.
- 'No submissions found for this resource for any students. ('.$num_students.
- ' checked for submissions ';
+ my $submissions='submissions';
+ if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
+ if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
+ if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
+ $gradeTable=' '.
+ &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
+ $num_students).
+ ' ';
}
} elsif ($ctr == 1) {
- $gradeTable =~ s/type=checkbox/type=checkbox checked/;
+ $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/;
}
- $gradeTable.=&show_grading_menu_form($symb,$url);
$request->print($gradeTable);
return '';
}
#---- Called from the listStudents routine
+
+sub check_script {
+ my ($form, $type)=@_;
+ my $chkallscript= &Apache::lonhtmlcommon::scripttag('
+ function checkall() {
+ for (i=0; i0) {
+ document.forms.'.$form.'.elements[i].checked=true;
+ }
+ }
+ }
+
+
+ function uncheckall() {
+ for (i=0; i';
+ $buttons.=' ';
+ $buttons.='';
+ $buttons.=' ';
+ return $buttons;
+}
+
# Displays the submissions for one student or a group of students
sub processGroup {
my ($request) = shift;
my $ctr = 0;
- my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
- : ($ENV{'form.stuinfo'}));
+ my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
my $total = scalar(@stuchecked)-1;
- foreach (@stuchecked) {
- my ($uname,$udom,$fullname) = split(/:/);
- $ENV{'form.student'} = $uname;
- $ENV{'form.userdom'} = $udom;
- $ENV{'form.fullname'} = $fullname;
+ foreach my $student (@stuchecked) {
+ my ($uname,$udom,$fullname) = split(/:/,$student);
+ $env{'form.student'} = $uname;
+ $env{'form.userdom'} = $udom;
+ $env{'form.fullname'} = $fullname;
&submission($request,$ctr,$total);
$ctr++;
}
@@ -620,17 +1159,17 @@ sub processGroup {
#--- Javascript to handle the submission page functionality ---
sub sub_page_js {
my $request = shift;
- $request->print(<
+ my $alertmsg = &mt('A number equal or greater than 0 is expected. Entered value = ');
+ $request->print(&Apache::lonhtmlcommon::scripttag(<
SUBJAVASCRIPT
}
@@ -793,18 +1336,91 @@ sub sub_page_kw_js {
my $request = shift;
my $iconpath = $request->dir_config('lonIconsURL');
&commonJSfunctions($request);
- $request->print(<
+
+ my $inner_js_msg_central= &Apache::lonhtmlcommon::scripttag(< 1,
+ 'only_body' => 1,
+ 'bgcolor' =>'#FFFFFF',});
+ my $end_page_msg_central =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
+
+ my $start_page_highlight_central =
+ &Apache::loncommon::start_page('Highlight Central',
+ $inner_js_highlight_central,
+ {'js_ready' => 1,
+ 'only_body' => 1,
+ 'bgcolor' =>'#FFFFFF',});
+ my $end_page_highlight_central =
+ &Apache::loncommon::end_page({'js_ready' => 1});
+
+ my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
+ $docopen=~s/^document\.//;
+ my $alertmsg = &mt('Please select a word or group of words from document and then click this link.');
+ $request->print(&Apache::lonhtmlcommon::scripttag(<", '"'];
+ var newStr = ["&", "<", ">", """];
+ var counter = 0;
+ while (counter < 4) {
+ strx = strReplace(strx,orgStr[counter],newStr[counter]);
+ counter++;
+ }
+ return strx;
+ }
+
+ function strReplace(strx, orgStr, newStr) {
+ return strx.split(orgStr).join(newStr);
+ }
+
function savedMsgHeader(Nmsg,usrctr,fullname) {
var height = 70*Nmsg+250;
var scrollbar = "no";
@@ -880,99 +1513,58 @@ sub sub_page_kw_js {
height = 600;
scrollbar = "yes";
}
-// if (window.pWin) {window.pWin.close(); window.pWin=null}
var xpos = (screen.width-600)/2;
xpos = (xpos < 0) ? '0' : xpos;
var ypos = (screen.height-height)/2-30;
ypos = (ypos < 0) ? '0' : ypos;
- pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
+ pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
pWin.focus();
pDoc = pWin.document;
- pDoc.write("");
- pDoc.write("Message Central");
-
- pDoc.write("
SUBJAVASCRIPT
}
+sub get_increment {
+ my $increment = $env{'form.increment'};
+ if ($increment != 1 && $increment != .5 && $increment != .25 &&
+ $increment != .1) {
+ $increment = 1;
+ }
+ return $increment;
+}
+
+sub gradeBox_start {
+ return (
+ &Apache::loncommon::start_data_table()
+ .&Apache::loncommon::start_data_table_header_row()
+ .'
'.&mt('Part').'
'
+ .'
'.&mt('Points').'
'
+ .'
'
+ .'
'.&mt('Assign Grade').'
'
+ .'
'.&mt('Weight').'
'
+ .'
'.&mt('Grade Status').'
'
+ .&Apache::loncommon::end_data_table_header_row()
+ );
+}
+
+sub gradeBox_end {
+ return (
+ &Apache::loncommon::end_data_table()
+ );
+}
#--- displays the grading box, used in essay type problem and grading by page/sequence
sub gradeBox {
my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
-
- my $checkIcon = '';
-
+ my $checkIcon = '';
my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
- my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
- 'problem weight assigned by computer');
+ my $wgtmsg = ($wgt > 0) ? &mt('(problem weight)')
+ : ''.&mt('problem weight assigned by computer').'';
$wgt = ($wgt > 0 ? $wgt : '1');
my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
- '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
+ '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
my $result=''."\n";
-
- $result.='
'.
- 'Part '.$partid.' Points:
'."\n";
-
+ my $display_part= &get_display_part($partid,$symb);
+ my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+ [$partid]);
+ my $aggtries = $$record{'resource.'.$partid.'.tries'};
+ if ($last_resets{$partid}) {
+ $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
+ }
+ $result.=&Apache::loncommon::start_data_table_row();
my $ctr = 0;
- $result.='
'."\n"; # display radio buttons in a nice table 10 across
- while ($ctr<=$wgt) {
- $result.= '
'.$ctr."
\n";
- $result.=(($ctr+1)%10 == 0 ? '
' : '');
+ my $thisweight = 0;
+ my $increment = &get_increment();
+
+ my $radio.='
'."\n"; # display radio buttons in a nice table 10 across
+ while ($thisweight<=$wgt) {
+ $radio.= '
';
return $result;
}
+sub files_exist {
+ my ($r, $symb) = @_;
+ my @students = &Apache::loncommon::get_env_multiple('form.stuinfo');
+
+ foreach my $student (@students) {
+ my ($uname,$udom,$fullname) = split(/:/,$student);
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},
+ $udom,$uname);
+ my ($string,$timestamp)= &get_last_submission(\%record);
+ foreach my $submission (@$string) {
+ my ($partid,$respid) =
+ ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
+ my $files=&get_submitted_files($udom,$uname,$partid,$respid,
+ \%record);
+ return 1 if (@$files);
+ }
+ }
+ return 0;
+}
+
+sub download_all_link {
+ my ($r,$symb) = @_;
+ my $all_students =
+ join("\n", &Apache::loncommon::get_env_multiple('form.stuinfo'));
+
+ my $parts =
+ join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
+
+ my $identifier = &Apache::loncommon::get_cgi_id();
+ &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
+ 'cgi.'.$identifier.'.symb' => $symb,
+ 'cgi.'.$identifier.'.parts' => $parts,});
+ $r->print(''.
+ &mt('Download All Submitted Documents').'');
+ return
+}
+
+sub build_section_inputs {
+ my $section_inputs;
+ if ($env{'form.section'} eq '') {
+ $section_inputs .= ''."\n";
+ } else {
+ my @sections = &Apache::loncommon::get_env_multiple('form.section');
+ foreach my $section (@sections) {
+ $section_inputs .= ''."\n";
+ }
+ }
+ return $section_inputs;
+}
+
# --------------------------- show submissions of a student, option to grade
sub submission {
- my ($request,$counter,$total) = @_;
+ my ($request,$counter,$total,$symb) = @_;
+ my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
+ $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
+ my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
+ $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
- (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
- my $usec = &Apache::lonnet::getsection($udom,$uname,$ENV{'request.course.id'});
- $ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
-
- my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
- if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
+ my $probtitle=&Apache::lonnet::gettitle($symb);
+ if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
if (!&canview($usec)) {
- $request->print('Unable to view requested student.('.
- $uname.$udom.$usec.$ENV{'request.course.id'}.')');
- $request->print(&show_grading_menu_form($symb,$url));
+ $request->print('Unable to view requested student.('.
+ $uname.':'.$udom.' in section '.$usec.' in course id '.
+ $env{'request.course.id'}.')');
return;
}
- my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
+ if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
+ if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
+ if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
+ my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
+ my $checkIcon = '';
+ my %old_essays;
# header info
if ($counter == 0) {
&sub_page_js($request);
- &sub_page_kw_js($request) if ($ENV{'form.handgrade'} eq 'yes');
- $ENV{'form.probTitle'} = $ENV{'form.probTitle'} eq '' ?
- &Apache::lonnet::gettitle($symb) : $ENV{'form.probTitle'};
-
- $request->print('
Submission Record
'."\n".
- ' Resource: '.$ENV{'form.probTitle'}.''."\n");
-
- if ($ENV{'form.handgrade'} eq 'no') {
- my $checkIcon = '';
- my $checkMark='
Note: Part(s) graded correct by the computer is marked with a '.
- $checkIcon.' symbol.'."\n";
- $request->print($checkMark);
+ &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
+ if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
+ &download_all_link($request, $symb);
}
+ $request->print('
'.&mt('Submission Record').'
');
# option to display problem, only once else it cause problems
# with the form later since the problem has a form.
- if ($ENV{'form.vProb'} eq 'yes' or !$ENV{'form.vProb'}) {
- $request->print(&show_problem($request,$symb,$uname,$udom,0,1));
+ if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
+ my $mode;
+ if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
+ $mode='both';
+ } elsif ($env{'form.vProb'} eq 'yes') {
+ $mode='text';
+ } elsif ($env{'form.vAns'} eq 'yes') {
+ $mode='answer';
+ }
+ &Apache::lonxml::clear_problem_counter();
+ $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
}
-
+
# kwclr is the only variable that is guaranteed to be non blank
# if this subroutine has been called once.
my %keyhash = ();
- if ($ENV{'form.kwclr'} eq '' && $ENV{'form.handgrade'} eq 'yes') {
+ if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
%keyhash = &Apache::lonnet::dump('nohist_handgrade',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-
- my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
- $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
- $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
- $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
- $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
- $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
- $keyhash{$symb.'_subject'} : $ENV{'form.probTitle'};
- $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
-
- }
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
- $request->print('