+'.&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;
+}
-# ----- These first few routines are general use routines.----
#
-# --- Retrieve the parts that matches stores_\d+ from the metadata file.---
+# --- Retrieve the parts 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);
+ 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 @parts;
+ return @stores;
}
# --- 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);
+sub get_symb {
+ my ($request,$silent) = @_;
+ my $symb=$env{'form.symb'};
+ unless ($symb) {
+ (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
+ $symb = &Apache::lonnet::symbread($url);
+ if ($symb eq '') {
+ if (!$silent) {
+ $request->print(&mt("Unable to handle ambiguous references: [_1].",$url));
+ return ();
+ }
+ }
+ }
+ &Apache::lonenc::check_decrypt(\$symb);
+ return ($symb);
}
-# --- 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/});
+#--- 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;
- }
+ 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 \@partlist,\%handgrade;
+ return $display;
}
#--- 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');
+ my ($symb,$probTitle,$checkboxes,$res_error) = @_;
+ my $result = '
'.&mt('Current Resource').': '.$probTitle.'
'."\n";
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,$res_error);
+ if (ref($res_error)) {
+ if ($$res_error) {
+ return;
+ }
+ }
+ $result.=&Apache::loncommon::start_data_table()
+ .&Apache::loncommon::start_data_table_header_row();
+ if ($checkboxes) {
+ $result.='
';
+ }
+ $result.='
'.&mt('Problem Part').'
'
+ .'
'.&mt('Res. ID').'
'
+ .'
'.&mt('Type').'
'
+ .&Apache::loncommon::end_data_table_header_row();
+ my %resptype = ();
my $hdgrade='no';
- for (sort keys(%$handgrade)) {
- my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
- my $partID = (split(/_/))[0];
- $resptype{$partID} = $responsetype;
- $hdgrade = $handgrade if ($handgrade eq 'yes');
- $result.='
Part '.$partID.'
'.
- '
Type: '.$responsetype.'
';
-# '
Handgrade: '.$handgrade.'
';
+ my %partsseen;
+ foreach my $partID (sort(keys(%$responseType))) {
+ foreach my $resID (sort(keys(%{ $responseType->{$partID} }))) {
+ my $handgrade=$$handgrade{$partID.'_'.$resID};
+ my $responsetype = $responseType->{$partID}->{$resID};
+ $hdgrade = $handgrade if ($handgrade eq 'yes');
+ $result.=&Apache::loncommon::start_data_table_row();
+ if ($checkboxes) {
+ if (exists($partsseen{$partID})) {
+ $result.="
'
+ .&Apache::loncommon::end_data_table_row();
+ }
+ }
+ $result.=&Apache::loncommon::end_data_table();
+ return $result,$responseType,$hdgrade,$partlist,$handgrade;
+}
+
+sub reset_caches {
+ &reset_analyze_cache();
+ &reset_perm();
+ &reset_old_essays();
+}
+
+{
+ 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,$type,$trial,$rndseed,$bubbles_per_row)=@_;
+ my $key = "$symb\0$uname\0$udom";
+ if ($type eq 'randomizetry') {
+ if ($trial ne '') {
+ $key .= "\0".$trial;
+ }
+ }
+ 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 ($bubbles_per_row ne '') {
+ $form{'bubbles_per_row'} = $bubbles_per_row;
+ }
+ if ($type eq 'randomizetry') {
+ $form{'grade_questiontype'} = $type;
+ if ($rndseed ne '') {
+ $form{'grade_rndseed'} = $rndseed;
+ }
+ }
+ 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,$type,$trial,$rndseed)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed);
+ return $analyze->{"$partid.$respid.shown"};
+ }
+
+ sub get_radiobutton_correct_foil {
+ my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed);
+ my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed);
+ if (ref($foils) eq 'ARRAY') {
+ foreach my $foil (@{$foils}) {
+ if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
+ return $foil;
+ }
+ }
+ }
+ }
+
+ sub scantron_partids_tograde {
+ my ($resource,$cid,$uname,$udom,$check_for_randomlist,$bubbles_per_row) = @_;
+ 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,
+ undef,undef,undef,$bubbles_per_row);
+ 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);
}
- $result.='
'."\n";
- return $result,\%resptype,$hdgrade,$partlist,$handgrade;
+
}
#--- 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,$symb) = @_;
- 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).'
'.
- '
';
- }
- if ($response eq 'essay') {
- if (! exists ($ENV{'form.'.$symb})) {
+ my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
+ $uname,$udom,$type,$trial,$rndseed) = @_;
+ 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').'
'.
+ $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,$type,$trial,$rndseed);
+ 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'});
+ $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.
- }
- return &keywords_highlight($answer);
+ 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 '
';
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 $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- 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'} = &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 ($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 ($symb) = &get_symb($request);
+ 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'}.')');
+ $request->print(&show_grading_menu_form($symb));
return;
}
- $ENV{'form.lastSub'} = ($ENV{'form.lastSub'} eq '' ? 'datesub' : $ENV{'form.lastSub'});
- my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
- my $checkIcon = '';
# 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 $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');
+ $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
+ &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
+ if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
+ &download_all_link($request, $symb);
}
+ $request->print('
'.&mt('Submission Record').'
'."\n".
+ '
'.&mt('Resource: [_1]',$env{'form.probTitle'}).'
'."\n");
# 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
+
+ # kwclr is the only variable that is guaranteed not to be 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'});
+ $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';
- }
- my $overRideScore = $ENV{'form.overRideScore'} eq '' ? 'no' : $ENV{'form.overRideScore'};
-
- $request->print('
'."\n".
+ 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';
+ }
+ my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
+ my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
+ $request->print('
KEYWORDS
#
# Load the other essays for similarity check
#
- my $essayurl=&Apache::lonnet::declutter($url);
- my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
- $apath=&Apache::lonnet::escape($apath);
+ my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
+ my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
+ $apath=&escape($apath);
$apath=~s/\W/\_/gs;
- %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
+ &init_old_essays($symb,$apath,$adom,$aname);
}
}
- if ($ENV{'form.vProb'} eq 'all') {
- $request->print('
') if ($counter > 0);
- $request->print(&show_problem($request,$symb,$uname,$udom,1,1));
+# This is where output for one specific student would start
+ my $add_class = ($counter%2) ? ' LC_grade_show_user_odd_row' : '';
+ $request->print(
+ "\n\n"
+ .'
';
- $result .= 'This student has submitted too many '.
- 'collaborators. Maximum is '.$ncol.'.';
- $result .= '
';
- }
- }
+ my $fullname;
+ my $col_fullnames = [];
+ if ($env{'form.handgrade'} eq 'yes') {
+ (my $sub_result,$fullname,$col_fullnames)=
+ &check_collaborators($symb,$uname,$udom,\%record,$handgrade,
+ $counter);
+ $result.=$sub_result;
}
$request->print($result."\n");
# print student answer/submission
- # Options are (1) Handgaded submission only
+ # Options are (1) Handgraded submission only
# (2) Last submission, includes submission that is not handgraded
# (for multi-response type part)
# (3) Last submission plus the parts info
# (4) The whole record for this student
- if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
- if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) {
- my $submitby=''.
- 'Collaborative submission by: '.
- ''.
- $$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.'';
- $request->print($submitby);
- } else {
- my ($string,$timestamp)= &get_last_submission (\%record);
- my $lastsubonly=''.
- ($$timestamp eq '' ? '' : 'Date Submitted: '.
- $$timestamp)."
\n";
- if ($$timestamp eq '') {
- $lastsubonly.='
'.$$string[0];
- } else {
- for my $part (sort keys(%$handgrade)) {
- my ($responsetype,$foo) = split(/:/,$$handgrade{$part});
- my ($partid,$respid) = split(/_/,$part);
- if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) {
- $lastsubonly.='
Part '.
- $partid.' ( ID '.$respid.
- ' ) Nothing submitted - no attempts
';
- } else {
- foreach (@$string) {
- my ($partid,$respid) = /^resource\.(\w+)\.(\w+)\.submission/;
- if ($part eq ($partid.'_'.$respid)) {
- my ($ressub,$subval) = split(/:/,$_,2);
- # Similarity check
- my $similar='';
- my ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval);
- if ($osim) {
- $osim=int($osim*100.0);
- $similar='
Essay is '.$osim.
- '% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom).
- '
'.
- &keywords_highlight($oessay).'
';
- }
- $lastsubonly.='
Part '.
- $partid.' ( ID '.$respid.
- ' ) '.
- ($record{"resource.$partid.$respid.uploadedurl"}?
- ' File uploaded by student '.
- 'Like all files provided by users, '.
- 'this file may contain virusses ':'').
- 'Submitted Answer: '.($responsetype =~ /^(essay|option)$/ ?
- '
';
+ next;
+ }
+ foreach my $submission (@$string) {
+ my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
+ if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
+ my ($ressub,$hide,$subval) = split(/:/,$submission,3);
+ # Similarity check
+ my $similar='';
+ my ($type,$trial,$rndseed);
+ if ($hide eq 'rand') {
+ $type = 'randomizetry';
+ $trial = $record{"resource.$partid.tries"};
+ $rndseed = $record{"resource.$partid.rndseed"};
+ }
+ if($env{'form.checkPlag'}){
+ my ($oname,$odom,$ocrsid,$oessay,$osim)=
+ &most_similar($uname,$udom,$symb,$subval);
+ if ($osim) {
+ $osim=int($osim*100.0);
+ my %old_course_desc =
+ &Apache::lonnet::coursedescription($ocrsid,
+ {'one_time' => 1});
+
+ if ($hide eq 'anon') {
+ $similar=''.&mt("Essay was found to be similar to another essay submitted for this assignment.").' '.
+ &mt('As the current submission is for an anonymous survey, no other details are available.').'';
+ } else {
+ $similar="
".
+ &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
+ $osim,
+ &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
+ $old_course_desc{'description'},
+ $old_course_desc{'num'},
+ $old_course_desc{'domain'}).
+ '
'.&show_grading_menu_form($symb);
+ }
+ $request->print($toGrade);
return;
+ } else {
+ $request->print(''."\n");
}
# essay grading message center
- if ($ENV{'form.handgrade'} eq 'yes') {
- my ($lastname,$givenn) = split(/,/,$ENV{'form.fullname'});
+ if ($env{'form.handgrade'} eq 'yes') {
+ my $result='
';
+
+ $result.='
'.
+ &mt('Send Message').'
';
+ my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
my $msgfor = $givenn.' '.$lastname;
- if (scalar(@col_fullnames) > 0) {
- my $lastone = pop @col_fullnames;
- $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
+ if (scalar(@$col_fullnames) > 0) {
+ my $lastone = pop(@$col_fullnames);
+ $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.';
}
$msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
-# $result.='
'."\n".
- $result=''."\n".
+ $result.=''."\n".
''."\n";
$result.=' '.
- 'Compose Message to student'.(scalar(@col_fullnames) >= 1 ? 's' : '').' '.
- ''.
+ &mt('Compose message to student'.(scalar(@$col_fullnames) >= 1 ? 's' : '')).')'.
+ ' '."\n".
- ' (Message will be sent when you click on Save & Next below.)'."\n"
- if ($ENV{'form.handgrade'} eq 'yes');
+ ' ('.
+ &mt('Message will be sent when you click on Save & Next below.').")\n";
+ $result.='';
$request->print($result);
}
my %seen = ();
my @partlist;
- for (sort keys(%$handgrade)) {
- my ($partid,$respid) = split(/_/);
+ my @gradePartRespid;
+ my @part_response_id = &flatten_responseType($responseType);
+ $request->print(
+ '
'
+ .'
'.&mt('Assign Grades').'
'
+ );
+ $request->print(&gradeBox_start());
+ foreach my $part_response_id (@part_response_id) {
+ my ($partid,$respid) = @{ $part_response_id };
+ my $part_resp = join('_',@{ $part_response_id });
next if ($seen{$partid} > 0);
$seen{$partid}++;
- next if ($$handgrade{$_} =~ /:no$/ && $ENV{'form.lastSub'} =~ /^(hdgrade)$/);
- push @partlist,$partid;
-
+ next if ($$handgrade{$part_resp} ne 'yes'
+ && $env{'form.lastSub'} eq 'hdgrade');
+ push(@partlist,$partid);
+ push(@gradePartRespid,$partid.'.'.$respid);
$request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
}
+ $request->print(&gradeBox_end()); #
+ $request->print('');
+
+ $request->print('
');
+ $request->print('
');
+
$result=''."\n";
+ $result.=''."\n" if ($counter == 0);
my $ctr = 0;
while ($ctr < scalar(@partlist)) {
$result.=''."\n";
$ctr++;
}
- $request->print($result.'
'."\n");
+ $request->print($result.''."\n");
+
+# Done with printing info for one student
+
+ $request->print('
');#LC_grade_show_user
+
# print end of form
if ($counter == $total) {
- my $endform='
'."\n";
- $endform.=' '."\n";
+ my $endform='
'."\n";
+ $endform.=' '."\n";
my $ntstu =''."\n";
- my $nsel = ($ENV{'form.NTSTU'} ne '' ? $ENV{'form.NTSTU'} : '1');
- $ntstu =~ s/
';
- $endform.=&show_grading_menu_form($symb,$url);
+ my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
+ $ntstu =~ s/
';
+ $endform.=&show_grading_menu_form($symb);
$request->print($endform);
}
return '';
}
+sub check_collaborators {
+ my ($symb,$uname,$udom,$record,$handgrade,$counter) = @_;
+ my ($result,@col_fullnames);
+ my ($classlist,undef,$fullname) = &getclasslist('all','0');
+ foreach my $part (keys(%$handgrade)) {
+ my $ncol = &Apache::lonnet::EXT('resource.'.$part.
+ '.maxcollaborators',
+ $symb,$udom,$uname);
+ next if ($ncol <= 0);
+ $part =~ s/\_/\./g;
+ next if ($record->{'resource.'.$part.'.collaborators'} eq '');
+ my (@good_collaborators, @bad_collaborators);
+ foreach my $possible_collaborator
+ (split(/[,;\s]+/,$record->{'resource.'.$part.'.collaborators'})) {
+ $possible_collaborator =~ s/[\$\^\(\)]//g;
+ next if ($possible_collaborator eq '');
+ my ($co_name,$co_dom) = split(/:/,$possible_collaborator);
+ $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
+ next if ($co_name eq $uname && $co_dom eq $udom);
+ # Doing this grep allows 'fuzzy' specification
+ my @matches = grep(/^\Q$co_name\E:\Q$co_dom\E$/i,
+ keys(%$classlist));
+ if (! scalar(@matches)) {
+ push(@bad_collaborators, $possible_collaborator);
+ } else {
+ push(@good_collaborators, @matches);
+ }
+ }
+ if (scalar(@good_collaborators) != 0) {
+ $result.=' '.&mt('Collaborators:').'';
+ foreach my $name (@good_collaborators) {
+ my ($lastname,$givenn) = split(/,/,$$fullname{$name});
+ push(@col_fullnames, $givenn.' '.$lastname);
+ $result.='
'."\n";
#view individual student submission form - called using Javascript viewOneStudent
- $result.=&jscriptNform($url,$symb);
+ $result.=&jscriptNform($symb);
#beginning of class grading form
+ my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
$result.= '
Assign Common Grade To ';
- if ($ENV{'form.section'} eq 'all') {
- $result.='Class
';
- } elsif ($ENV{'form.section'} eq 'no') {
- $result.='Students in no Section ';
+ &build_section_inputs().
+ ''."\n".
+ ''."\n".
+ ''."\n";
+
+ my ($common_header,$specific_header);
+ if ($env{'form.section'} eq 'all') {
+ $common_header = &mt('Assign Common Grade to Class');
+ $specific_header = &mt('Assign Grade to Specific Students in Class');
+ } elsif ($env{'form.section'} eq 'none') {
+ $common_header = &mt('Assign Common Grade to Students in no Section');
+ $specific_header = &mt('Assign Grade to Specific Students in no Section');
} else {
- $result.='Students in Section '.$ENV{'form.section'}.'';
+ my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
+ $common_header = &mt('Assign Common Grade to Students in Section(s) [_1]',$section_display);
+ $specific_header = &mt('Assign Grade to Specific Students in Section(s) [_1]',$section_display);
}
- $result.= '
'."\n".
- '
';
+ $result.= '
'.$common_header.'
'.&Apache::loncommon::start_data_table();
#radio buttons/text box for assigning points for a section or class.
#handles different parts of a problem
- my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
+ my $res_error;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb,\$res_error);
+ if ($res_error) {
+ return &navmap_errormsg();
+ }
my %weight = ();
my $ctsparts = 0;
- $result.='
';
my %seen = ();
- for (sort keys(%$handgrade)) {
- my ($partid,$respid) = split (/_/,$_,2);
+ my @part_response_id = &flatten_responseType($responseType);
+ foreach my $part_response_id (@part_response_id) {
+ my ($partid,$respid) = @{ $part_response_id };
+ my $part_resp = join('_',@{ $part_response_id });
next if $seen{$partid};
$seen{$partid}++;
- my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
+ my $handgrade=$$handgrade{$part_resp};
my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
$weight{$partid} = $wgt eq '' ? '1' : $wgt;
- $result.=''."\n";
- $result.=''."\n";
- $result.='
Part '.$partid.' Point:
';
- $result.='
';
+ my $display_part=&get_display_part($partid,$symb);
+ my $radio.='
';
my $ctr = 0;
while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
- $result.= '
'."\n".
+ $result.=&Apache::loncommon::end_data_table()."\n".
'';
- $result.='';
+ $result.='';
#table listing all the students in a section/class
#header of table
- $result.= '
Assign Grade to Specific Students in ';
- if ($ENV{'form.section'} eq 'all') {
- $result.='the Class
\n";
+ my $partserror;
+ my (@parts) = sort(&getpartlist($symb,\$partserror));
+ if ($partserror) {
+ return &navmap_errormsg();
+ }
+ my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
+ my @partids = ();
foreach my $part (@parts) {
my $display=&Apache::lonnet::metadata($url,$part.'.display');
- $display =~ s/^Number of Attempts/Tries/; # makes the column narrower
+ my $narrowtext = &mt('Tries');
+ $display =~ s|^Number of Attempts|$narrowtext |; # makes the column narrower
if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
+ my ($partid) = &split_part_type($part);
+ push(@partids,$partid);
+ my $display_part=&get_display_part($partid,$symb);
if ($display =~ /^Partial Credit Factor/) {
- my ($partid) = &split_part_type($part);
- $result.='
Score Part '.$partid.' (weight = '.
- $weight{$partid}.')
'."\n";
+ $result.=''."\n";
if (scalar(%$fullname) eq 0) {
my $colspan=3+scalar(@parts);
- $result='There are no students in section "'.$ENV{'form.section'}.
- '" with enrollment status "'.$ENV{'form.Status'}.'" to modify or grade.';
+ my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
+ my $stu_status = join(' or ',&Apache::loncommon::get_env_multiple('form.Status'));
+ $result=''.
+ &mt('There are no students in section(s) [_1] with enrollment status [_2] to modify or grade.',
+ $section_display, $stu_status).
+ '';
}
- $result.=&show_grading_menu_form($symb,$url);
+ $result.=&show_grading_menu_form($symb);
return $result;
}
#--- call by previous routine to display each student
sub viewstudentgrade {
- my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_;
+ my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
my ($uname,$udom) = split(/:/,$student);
- $student=~s/:/_/;
my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
- my $result='
'.
+ my %aggregates = ();
+ my $result=&Apache::loncommon::start_data_table_row().'
';
+ $result.=&Apache::loncommon::end_data_table_row();
return $result;
}
@@ -2208,144 +3876,224 @@ sub viewstudentgrade {
sub editgrades {
my ($request) = @_;
- my $symb=$ENV{'form.symb'};
- my $url =$ENV{'form.url'};
- my $title='
'."\n".
- &show_grading_menu_form ($symb,$url);
- my $msg = 'Number of records updated = '.$rec_update.
- ' for '.$count.' student'.($count <= 1 ? '' : 's').'. '.
- 'Total number of students = '.$ENV{'form.total'}.' ';
+ if (@noupdate) {
+# my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
+ my $numcols=scalar(@partid)*4+2;
+ $result .= &Apache::loncommon::start_data_table_row('LC_empty_row').
+ '
'.
+ &mt('No Changes Occurred For the Students Below').
+ '
'.
+ &mt('Number of records updated = [_1] for [quant,_2,student].',
+ $rec_update,$count).' '.
+ ''.&mt('Total number of students = [_1]',$env{'form.total'}).
+ '
';
return $title.$msg.$result;
}
@@ -2353,7 +4101,7 @@ sub split_part_type {
my ($partstr) = @_;
my ($temp,@allparts)=split(/_/,$partstr);
my $type=pop(@allparts);
- my $part=join('.',@allparts);
+ my $part=join('_',@allparts);
return ($part,$type);
}
@@ -2368,24 +4116,26 @@ sub split_part_type {
#
#--- Javascript to handle csv upload
sub csvupload_javascript_reverse_associate {
+ my $error1=&mt('You need to specify the username or the student/employee ID');
+ my $error2=&mt('You need to specify at least one grading field');
return(<2) { foundsomething=1; }
- }
- if (founduname==0 || founddomain==0) {
- alert('You need to specify at both the username and domain');
- return;
+ if (tw==1) { foundID=1; }
+ if (tw==2) { founduname=1; }
+ if (tw>3) { foundsomething=1; }
+ }
+ if (founduname==0 && foundID==0) {
+ alert('$error1');
+ return;
}
if (foundsomething==0) {
- alert('You need to specify at least one grading field');
- return;
+ alert('$error2');
+ return;
}
vf.submit();
}
@@ -2441,58 +4193,71 @@ ENDPICK
}
sub csvuploadmap_header {
- my ($request,$symb,$url,$datatoken,$distotal)= @_;
+ my ($request,$symb,$datatoken,$distotal)= @_;
my $javascript;
- if ($ENV{'form.upfile_associate'} eq 'reverse') {
+ if ($env{'form.upfile_associate'} eq 'reverse') {
$javascript=&csvupload_javascript_reverse_associate();
} else {
$javascript=&csvupload_javascript_forward_associate();
}
- my ($result) = &showResourceInfo($url,$ENV{'form.probTitle'});
-
+ my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
+ my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
+ my $ignore=&mt('Ignore First Line');
+ $symb = &Apache::lonenc::check_encrypt($symb);
$request->print(<
-
Uploading Class Grades
+
Uploading Class Grades
$result
-
+
Identify fields
Total number of records found in file: $distotal
Enter as many fields as you can. The system will inform you and bring you back
to this page if the data selected is insufficient to run your class.
-
+
+
-
-
+
+
+ value="$env{'form.upfile_associate'}" />
-
-
-
-
+
+
+
ENDPICK
- $request->print(&show_grading_menu_form($symb,$url));
return '';
}
sub csvupload_fields {
- my ($url) = @_;
- my (@parts) = &getpartlist($url);
- my @fields=(['username','Student Username'],['domain','Student Domain']);
+ my ($symb,$errorref) = @_;
+ my (@parts) = &getpartlist($symb,$errorref);
+ if (ref($errorref)) {
+ if ($$errorref) {
+ return;
+ }
+ }
+
+ my @fields=(['ID','Student/Employee ID'],
+ ['username','Student Username'],
+ ['domain','Student Domain']);
+ my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
foreach my $part (sort(@parts)) {
my @datum;
my $display=&Apache::lonnet::metadata($url,$part.'.display');
my $name=$part;
if (!$display) { $display = $name; }
@datum=($name,$display);
+ if ($name=~/^stores_(.*)_awarded/) {
+ push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
+ }
push(@fields,\@datum);
}
return (@fields);
@@ -2500,77 +4265,93 @@ sub csvupload_fields {
sub csvuploadmap_footer {
my ($request,$i,$keyfields) =@_;
+ my $buttontext = &mt('Assign Grades');
$request->print(<
-
+
ENDPICK
}
-sub upcsvScores_form {
- my ($request) = shift;
- my ($symb,$url)=&get_symb_and_url($request);
- if (!$symb) {return '';}
+sub checkforfile_js {
+ my $alertmsg = &mt('Please use the browse button to select a file from your local directory.');
my $result =<
function checkUpload(formname) {
if (formname.upfile.value == "") {
- alert("Please use the browse button to select a file from your local directory.");
+ alert("$alertmsg");
return false;
}
formname.submit();
}
CSVFORMJS
- $ENV{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
- my ($table) = &showResourceInfo($url,$ENV{'form.probTitle'});
+ return $result;
+}
+
+sub upcsvScores_form {
+ my ($request) = shift;
+ my ($symb)=&get_symb($request);
+ if (!$symb) {return '';}
+ my $result=&checkforfile_js();
+ $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
+ my ($table) = &showResourceInfo($symb,$env{'form.probTitle'});
$result.=$table;
- $result.='
'."\n";
- $result.='
'."\n";
- $result.=' Specify a file containing the class scores for current resource'.
- '.
'."\n";
- $result.='
'."\n";
+ $result.='
'."\n";
+ $result.='
'."\n";
+ $result.=' '.&mt('Specify a file containing the class scores for current resource.').
+ '
'."\n";
+ $result.='
'."\n";
+ my $upload=&mt("Upload Scores");
my $upfile_select=&Apache::loncommon::upfile_select_html();
+ my $ignore=&mt('Ignore First Line');
+ $symb = &Apache::lonenc::check_encrypt($symb);
$result.=<
-
-
-
+
+
$upfile_select
-
-
+
+
ENDUPFORM
- $result.='
'."\n";
+ $result.=&Apache::loncommon::help_open_topic("Course_Convert_To_CSV",
+ &mt("How do I create a CSV file from a spreadsheet"))
+ .'
'."\n";
$result.='
'."\n";
- $result.=&show_grading_menu_form($symb,$url);
+ $result.=&show_grading_menu_form($symb);
return $result;
}
sub csvuploadmap {
my ($request)= @_;
- my ($symb,$url)=&get_symb_and_url($request);
+ my ($symb)=&get_symb($request);
if (!$symb) {return '';}
my $datatoken;
- if (!$ENV{'form.datatoken'}) {
+ if (!$env{'form.datatoken'}) {
$datatoken=&Apache::loncommon::upfile_store($request);
} else {
- $datatoken=$ENV{'form.datatoken'};
+ $datatoken=$env{'form.datatoken'};
&Apache::loncommon::load_tmp_file($request);
}
my @records=&Apache::loncommon::upfile_record_sep();
- &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
+ if ($env{'form.noFirstLine'}) { shift(@records); }
+ &csvuploadmap_header($request,$symb,$datatoken,$#records+1);
my ($i,$keyfields);
if (@records) {
- my @fields=&csvupload_fields($url);
-
- if ($ENV{'form.upfile_associate'} eq 'reverse') {
+ my $fieldserror;
+ my @fields=&csvupload_fields($symb,\$fieldserror);
+ if ($fieldserror) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
+ if ($env{'form.upfile_associate'} eq 'reverse') {
&Apache::loncommon::csv_print_samples($request,\@records);
$i=&Apache::loncommon::csv_print_select_table($request,\@records,
\@fields);
@@ -2580,47 +4361,123 @@ sub csvuploadmap {
unshift(@fields,['none','']);
$i=&Apache::loncommon::csv_samples_select_table($request,\@records,
\@fields);
- my %sone=&Apache::loncommon::record_sep($records[0]);
- $keyfields=join(',',sort(keys(%sone)));
+ foreach my $rec (@records) {
+ my %temp = &Apache::loncommon::record_sep($rec);
+ if (%temp) {
+ $keyfields=join(',',sort(keys(%temp)));
+ last;
+ }
+ }
}
}
&csvuploadmap_footer($request,$i,$keyfields);
- $request->print(&show_grading_menu_form($symb,$url));
+ $request->print(&show_grading_menu_form($symb));
return '';
}
-sub csvuploadassign {
+sub csvuploadoptions {
my ($request)= @_;
- my ($symb,$url)=&get_symb_and_url($request);
- if (!$symb) {return '';}
- &Apache::loncommon::load_tmp_file($request);
- my @gradedata = &Apache::loncommon::upfile_record_sep();
- my @keyfields = split(/\,/,$ENV{'form.keyfields'});
- my %fields=();
- for (my $i=0; $i<=$ENV{'form.nfields'}; $i++) {
- if ($ENV{'form.upfile_associate'} eq 'reverse') {
- if ($ENV{'form.f'.$i} ne 'none') {
- $fields{$keyfields[$i]}=$ENV{'form.f'.$i};
+ my ($symb)=&get_symb($request);
+ my $checked=(($env{'form.noFirstLine'})?'1':'0');
+ my $ignore=&mt('Ignore First Line');
+ $request->print(<
+
Uploading Class Grade Options
+
+
+
+
+
+ENDPICK
+ my %fields=&get_fields();
+ if (!defined($fields{'domain'})) {
+ my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
+ $request->print("\n
Users are in domain: ".$domform."
\n");
+ }
+ foreach my $key (sort(keys(%env))) {
+ if ($key !~ /^form\.(.*)$/) { next; }
+ my $cleankey=$1;
+ if ($cleankey eq 'command') { next; }
+ $request->print(''."\n");
+ }
+ # FIXME do a check for any duplicated user ids...
+ # FIXME do a check for any invalid user ids?...
+ $request->print('
+'."\n");
+ $request->print(&show_grading_menu_form($symb));
+ return '';
+}
+
+sub get_fields {
+ my %fields;
+ my @keyfields = split(/\,/,$env{'form.keyfields'});
+ for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
+ if ($env{'form.upfile_associate'} eq 'reverse') {
+ if ($env{'form.f'.$i} ne 'none') {
+ $fields{$keyfields[$i]}=$env{'form.f'.$i};
}
} else {
- if ($ENV{'form.f'.$i} ne 'none') {
- $fields{$ENV{'form.f'.$i}}=$keyfields[$i];
+ if ($env{'form.f'.$i} ne 'none') {
+ $fields{$env{'form.f'.$i}}=$keyfields[$i];
}
}
}
+ return %fields;
+}
+
+sub csvuploadassign {
+ my ($request)= @_;
+ my ($symb)=&get_symb($request);
+ if (!$symb) {return '';}
+ my $error_msg = '';
+ &Apache::loncommon::load_tmp_file($request);
+ my @gradedata = &Apache::loncommon::upfile_record_sep();
+ if ($env{'form.noFirstLine'}) { shift(@gradedata); }
+ my %fields=&get_fields();
$request->print('
Assigning Grades
');
- my $courseid=$ENV{'request.course.id'};
+ my $courseid=$env{'request.course.id'};
my ($classlist) = &getclasslist('all',0);
my @notallowed;
my @skipped;
+ my @warnings;
my $countdone=0;
foreach my $grade (@gradedata) {
my %entries=&Apache::loncommon::record_sep($grade);
+ my $domain;
+ if ($entries{$fields{'domain'}}) {
+ $domain=$entries{$fields{'domain'}};
+ } else {
+ $domain=$env{'form.default_domain'};
+ }
+ $domain=~s/\s//g;
my $username=$entries{$fields{'username'}};
- my $domain=$entries{$fields{'domain'}};
+ $username=~s/\s//g;
+ if (!$username) {
+ my $id=$entries{$fields{'ID'}};
+ $id=~s/\s//g;
+ my %ids=&Apache::lonnet::idget($domain,$id);
+ $username=$ids{$id};
+ }
if (!exists($$classlist{"$username:$domain"})) {
- push(@skipped,"$username:$domain");
+ my $id=$entries{$fields{'ID'}};
+ $id=~s/\s//g;
+ if ($id) {
+ push(@skipped,"$id:$domain");
+ } else {
+ push(@skipped,"$username:$domain");
+ }
next;
}
my $usec=$classlist->{"$username:$domain"}[5];
@@ -2628,34 +4485,82 @@ sub csvuploadassign {
push(@notallowed,"$username:$domain");
next;
}
+ my %points;
my %grades;
foreach my $dest (keys(%fields)) {
- if ($dest eq 'username' || $dest eq 'domain') { next; }
- if ($entries{$fields{$dest}} eq '') { next; }
- my $store_key=$dest;
- $store_key=~s/^stores/resource/;
- $store_key=~s/_/\./g;
- $grades{$store_key}=$entries{$fields{$dest}};
- }
- $grades{"resource.regrader"}="$ENV{'user.name'}:$ENV{'user.domain'}";
- &Apache::lonnet::cstore(\%grades,$symb,$ENV{'request.course.id'},
- $domain,$username);
- $request->print('.');
- $request->rflush();
- $countdone++;
+ if ($dest eq 'ID' || $dest eq 'username' ||
+ $dest eq 'domain') { next; }
+ if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
+ if ($dest=~/stores_(.*)_points/) {
+ my $part=$1;
+ my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
+ $symb,$domain,$username);
+ if ($wgt) {
+ $entries{$fields{$dest}}=~s/\s//g;
+ my $pcr=$entries{$fields{$dest}} / $wgt;
+ my $award=($pcr == 0) ? 'incorrect_by_override'
+ : 'correct_by_override';
+ if ($pcr>1) {
+ push(@warnings,&mt("[_1]: point value larger than weight","$username:$domain"));
+ }
+ $grades{"resource.$part.awarded"}=$pcr;
+ $grades{"resource.$part.solved"}=$award;
+ $points{$part}=1;
+ } else {
+ $error_msg = " " .
+ &mt("Some point values were assigned"
+ ." for problems with a weight "
+ ."of zero. These values were "
+ ."ignored.");
+ }
+ } else {
+ if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
+ if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
+ my $store_key=$dest;
+ $store_key=~s/^stores/resource/;
+ $store_key=~s/_/\./g;
+ $grades{$store_key}=$entries{$fields{$dest}};
+ }
+ }
+ if (! %grades) {
+ push(@skipped,&mt("[_1]: no data to save","$username:$domain"));
+ } else {
+ $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
+ my $result=&Apache::lonnet::cstore(\%grades,$symb,
+ $env{'request.course.id'},
+ $domain,$username);
+ if ($result eq 'ok') {
+ $request->print('.');
+# Remove from grading queue
+ &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'},
+ $domain,$username);
+ } else {
+ $request->print("
".
+ &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]",
+ "$username:$domain",$result)."
");
+ }
+ $request->rflush();
+ $countdone++;
+ }
+ }
+ $request->print(' '.&Apache::lonhtmlcommon::confirm_success(&mt("Saved scores for [quant,_1,student]",$countdone),$countdone==0));
+ if (@warnings) {
+ $request->print(' '.&Apache::lonhtmlcommon::confirm_success(&mt('Warnings generated for the following saved scores:'),1).' ');
+ $request->print(join(', ',@warnings));
}
- $request->print(" Stored $countdone students\n");
if (@skipped) {
- $request->print('
Skipped Students
');
- foreach my $student (@skipped) { $request->print("$student \n"); }
+ $request->print(' '.&Apache::lonhtmlcommon::confirm_success(&mt('No scores stored for the following username(s):'),1).' ');
+ $request->print(join(', ',@skipped));
}
if (@notallowed) {
- $request->print('
Students Not Allowed to Modify
');
- foreach my $student (@notallowed) { $request->print("$student \n"); }
+ $request->print(' '.&Apache::lonhtmlcommon::confirm_success(&mt('Modification of scores not allowed for the following username(s):'),1).' ');
+ $request->print(join(', ',@notallowed));
}
$request->print(" \n");
- $request->print(&show_grading_menu_form($symb,$url));
- return '';
+ $request->print(&show_grading_menu_form($symb));
+ return $error_msg;
}
#------------- end of section for handling csv file upload ---------
#
@@ -2667,44 +4572,54 @@ sub csvuploadassign {
sub pickStudentPage {
my ($request) = shift;
+ my $alertmsg = &mt('Please select the student you wish to grade.');
$request->print(<
function checkPickOne(formname) {
if (radioSelection(formname.student) == null) {
- alert("Please select the student you wish to grade.");
+ alert("$alertmsg");
return;
}
- var ptr = pullDownSelection(formname.selectpage);
- formname.page.value = eval("formname.page"+ptr+".value");
- formname.title.value = eval("formname.title"+ptr+".value");
+ ptr = pullDownSelection(formname.selectpage);
+ formname.page.value = formname["page"+ptr].value;
+ formname.title.value = formname["title"+ptr].value;
formname.submit();
}
LISTJAVASCRIPT
&commonJSfunctions($request);
- 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 ($symb) = &get_symb($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 $result='
'.
- 'Manual Grading by Page or Sequence
';
+ my $result='
'.
+ &mt('Manual Grading by Page or Sequence').'
';
$result.='
'."\n";
- $result.=' Problems from:'."\n";
- my ($titles,$symbx) = &getSymbMap($request);
- my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/);
+ my $map_error;
+ my ($titles,$symbx) = &getSymbMap($map_error);
+ if ($map_error) {
+ $request->print(&navmap_errormsg());
+ return;
+ }
+ my ($curpage) =&Apache::lonnet::decode_symb($symb);
+# my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
+# my $type=($curpage =~ /\.(page|sequence)/);
+ my $select = ''."\n";
my $ctr=0;
foreach (@$titles) {
my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
- $result.=''."\n";
$ctr++;
}
- $result.= ''." \n";
+ $select.= '';
+ $result.=' '.&mt('Problems from').': '.$select." \n";
+
$ctr=0;
foreach (@$titles) {
my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
@@ -2715,79 +4630,99 @@ LISTJAVASCRIPT
$result.=''."\n".
''."\n";
- $result.=' View Problems Text: no '."\n".
- ' yes '." \n";
-
- $result.=' Submission Details: '.
- ' none'."\n".
- ' by dates and submissions'."\n".
- ' all details'."\n";
-
- $result.=''."\n".
- ''."\n".
+ my $options =
+ ''."\n".
+ ''." \n";
+ $result.=' '.&mt('View Problem Text').': '.$options;
+
+ $options =
+ ''."\n".
+ ''."\n".
+ ''."\n";
+ $result.=' '.&mt('Submissions').': '.$options;
+
+ $result.=&build_section_inputs();
+ my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
+ $result.=''."\n".
''."\n".
- ''."\n".
- ''."\n".
- ''." \n";
+ ''."\n".
+ ''." \n";
+
+ $result.=' '.&mt('Use CODE').': '."\n";
$result.=' '."\n";
+ 'onclick="javascript:checkPickOne(this.form);" value="'.&mt('Next').' →" /> '."\n";
$request->print($result);
- my $studentTable.=' Select a student you wish to grade '.
- '
'.
- '
'.
- '
Fullname (username)
'.
- '
Fullname (username)
'.
- '
Fullname (username)
'.
- '
Fullname (username)
';
+ my $studentTable.=' '.&mt('Select a student you wish to grade and then click on the Next button.').' '.
+ &Apache::loncommon::start_data_table().
+ &Apache::loncommon::start_data_table_header_row().
+ '
'.&mt('No.').'
'.
+ '
'.&nameUserString('header').'
'.
+ '
'.&mt('No.').'
'.
+ '
'.&nameUserString('header').'
'.
+ &Apache::loncommon::end_data_table_header_row();
my (undef,undef,$fullname) = &getclasslist($getsec,'1');
my $ptr = 1;
- foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
+ foreach my $student (sort
+ {
+ if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
+ return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
+ }
+ return $a cmp $b;
+ } (keys(%$fullname))) {
my ($uname,$udom) = split(/:/,$student);
- $studentTable.=($ptr%4 == 1 ? '
'.
+ &Apache::loncommon::end_data_table_header_row();
- $studentTable.=' Note: Problems graded correct by the computer are marked with a '.$checkIcon.
- ' symbol.'."\n".
- '
';
- $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
- my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
- 'The scores were changed for '.
- $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
+ $studentTable.=&Apache::loncommon::end_data_table();
+ $studentTable.=&show_grading_menu_form($env{'form.symb'});
+ my $grademsg=($changeflag == 0 ? &mt('No score was changed or updated.') :
+ &mt('The scores were changed for [quant,_1,problem].',
+ $changeflag));
$request->print($grademsg.$studentTable);
return '';
@@ -3075,29 +5204,103 @@ sub updateGradeByPage {
#
#-------------------------------------------------------------------
-#--------------------Scantron Grading-----------------------------------
+#-------------------- Bubblesheet (Scantron) Grading -------------------
#
#------ start of section for handling grading by page/sequence ---------
+=pod
+
+=head1 Bubble sheet grading routines
+
+ For this documentation:
+
+ 'scanline' refers to the full line of characters
+ from the file that we are parsing that represents one entire sheet
+
+ 'bubble line' refers to the data
+ representing the line of bubbles that are on the physical bubblesheet
+
+
+The overall process is that a scanned in bubblesheet data is uploaded
+into a course. When a user wants to grade, they select a
+sequence/folder of resources, a file of bubblesheet info, and pick
+one of the predefined configurations for what each scanline looks
+like.
+
+Next each scanline is checked for any errors of either 'missing
+bubbles' (it's an error because it may have been mis-scanned
+because too light bubbling), 'double bubble' (each bubble line should
+have no more than one letter picked), invalid or duplicated CODE,
+invalid student/employee ID
+
+If the CODE option is used that determines the randomization of the
+homework problems, either way the student/employee ID is looked up into a
+username:domain.
+
+During the validation phase the instructor can choose to skip scanlines.
+
+After the validation phase, there are now 3 bubblesheet files
+
+ scantron_original_filename (unmodified original file)
+ scantron_corrected_filename (file where the corrected information has replaced the original information)
+ scantron_skipped_filename (contains the exact text of scanlines that where skipped)
+
+Also there is a separate hash nohist_scantrondata that contains extra
+correction information that isn't representable in the bubblesheet
+file (see &scantron_getfile() for more information)
+
+After all scanlines are either valid, marked as valid or skipped, then
+foreach line foreach problem in the picked sequence, an ssi request is
+made that simulates a user submitting their selected letter(s) against
+the homework problem.
+
+=over 4
+
+
+
+=item defaultFormData
+
+ Returns html hidden inputs used to hold context/default values.
+
+ Arguments:
+ $symb - $symb of the current resource
+
+=cut
+
sub defaultFormData {
- my ($symb,$url)=@_;
- return '
- '."\n".
- ''."\n".
- ''."\n".
- ''."\n";
+ my ($symb)=@_;
+ return ''."\n".
+ ''."\n".
+ ''."\n";
}
+
+=pod
+
+=item getSequenceDropDown
+
+ Return html dropdown of possible sequences to grade
+
+ Arguments:
+ $symb - $symb of the current resource
+ $map_error - ref to scalar which will container error if
+ $navmap object is unavailable in &getSymbMap().
+
+=cut
+
sub getSequenceDropDown {
- my ($request,$symb)=@_;
+ my ($symb,$map_error)=@_;
my $result=''."\n";
- my ($titles,$symbx) = &getSymbMap($request);
- my ($curpage,$type,$mapId) = ($symb =~ /(.*?\.(page|sequence))___(\d+)___/);
+ my ($titles,$symbx) = &getSymbMap($map_error);
+ if (ref($map_error)) {
+ return if ($$map_error);
+ }
+ my ($curpage)=&Apache::lonnet::decode_symb($symb);
my $ctr=0;
foreach (@$titles) {
my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
$result.=''."\n";
$ctr++;
}
@@ -3105,88 +5308,492 @@ sub getSequenceDropDown {
return $result;
}
+my %bubble_lines_per_response; # no. bubble lines for each response.
+ # key is zero-based index - 0, 1, 2 ...
+
+my %first_bubble_line; # First bubble line no. for each bubble.
+
+my %subdivided_bubble_lines; # no. bubble lines for optionresponse,
+ # matchresponse or rankresponse, where
+ # an individual response can have multiple
+ # lines
+
+my %responsetype_per_response; # responsetype for each response
+
+my %masterseq_id_responsenum; # src_id (e.g., 12.3_0.11 etc.) for each
+ # numbered response. Needed when randomorder
+ # or randompick are in use. Key is ID, value
+ # is response number.
+
+# Save and restore the bubble lines array to the form env.
+
+
+sub save_bubble_lines {
+ foreach my $line (keys(%bubble_lines_per_response)) {
+ $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line};
+ $env{"form.scantron.first_bubble_line.$line"} =
+ $first_bubble_line{$line};
+ $env{"form.scantron.sub_bubblelines.$line"} =
+ $subdivided_bubble_lines{$line};
+ $env{"form.scantron.responsetype.$line"} =
+ $responsetype_per_response{$line};
+ }
+ foreach my $resid (keys(%masterseq_id_responsenum)) {
+ my $line = $masterseq_id_responsenum{$resid};
+ $env{"form.scantron.residpart.$line"} = $resid;
+ }
+}
+
+
+sub restore_bubble_lines {
+ my $line = 0;
+ %bubble_lines_per_response = ();
+ %masterseq_id_responsenum = ();
+ while ($env{"form.scantron.bubblelines.$line"}) {
+ my $value = $env{"form.scantron.bubblelines.$line"};
+ $bubble_lines_per_response{$line} = $value;
+ $first_bubble_line{$line} =
+ $env{"form.scantron.first_bubble_line.$line"};
+ $subdivided_bubble_lines{$line} =
+ $env{"form.scantron.sub_bubblelines.$line"};
+ $responsetype_per_response{$line} =
+ $env{"form.scantron.responsetype.$line"};
+ my $id = $env{"form.scantron.residpart.$line"};
+ $masterseq_id_responsenum{$id} = $line;
+ $line++;
+ }
+}
+
+=pod
+
+=item scantron_filenames
+
+ Returns a list of the scantron files in the current course
+
+=cut
+
+sub scantron_filenames {
+ my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
+ my $getpropath = 1;
+ my ($dirlist,$listerror) = &Apache::lonnet::dirlist('userfiles',$cdom,
+ $cname,$getpropath);
+ my @possiblenames;
+ if (ref($dirlist) eq 'ARRAY') {
+ foreach my $filename (sort(@{$dirlist})) {
+ ($filename)=split(/&/,$filename);
+ if ($filename!~/^scantron_orig_/) { next ; }
+ $filename=~s/^scantron_orig_//;
+ push(@possiblenames,$filename);
+ }
+ }
+ return @possiblenames;
+}
+
+=pod
+
+=item scantron_uploads
+
+ Returns html drop-down list of scantron files in current course.
+
+ Arguments:
+ $file2grade - filename to set as selected in the dropdown
+
+=cut
+
sub scantron_uploads {
- if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
+ my ($file2grade) = @_;
my $result= '';
- opendir(DIR,$Apache::lonnet::perlvar{'lonScansDir'});
- my @files=sort(readdir(DIR));
- foreach my $filename (@files) {
- if ($filename eq '.' or $filename eq '..') { next; }
- $result.="\n";
+ $result.="";
+ foreach my $filename (sort(&scantron_filenames())) {
+ $result.="\n";
}
- closedir(DIR);
$result.="";
return $result;
}
+=pod
+
+=item scantron_scantab
+
+ Returns html drop down of the scantron formats in the scantronformat.tab
+ file.
+
+=cut
+
sub scantron_scantab {
- my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
my $result=''."\n";
- foreach my $line (<$fh>) {
- my ($name,$descrip)=split(/:/,$line);
- if ($name =~ /^\#/) { next; }
- $result.=''."\n";
+ $result.=''."\n";
+ my @lines = &get_scantronformat_file();
+ if (@lines > 0) {
+ foreach my $line (@lines) {
+ next if (($line =~ /^\#/) || ($line eq ''));
+ my ($name,$descrip)=split(/:/,$line);
+ $result.=''."\n";
+ }
}
$result.=''."\n";
+ return $result;
+}
+
+=pod
+
+=item get_scantronformat_file
+
+ Returns an array containing lines from the scantron format file for
+ the domain of the course.
+
+ If a url for a custom.tab file is listed in domain's configuration.db,
+ lines are from this file.
+
+ Otherwise, if a default.tab has been published in RES space by the
+ domainconfig user, lines are from this file.
+
+ Otherwise, fall back to getting lines from the legacy file on the
+ local server: /home/httpd/lonTabs/default_scantronformat.tab
+
+=cut
+
+sub get_scantronformat_file {
+ my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my %domconfig = &Apache::lonnet::get_dom('configuration',['scantron'],$cdom);
+ my $gottab = 0;
+ my @lines;
+ if (ref($domconfig{'scantron'}) eq 'HASH') {
+ if ($domconfig{'scantron'}{'scantronformat'} ne '') {
+ my $formatfile = &Apache::lonnet::getfile($Apache::lonnet::perlvar{'lonDocRoot'}.$domconfig{'scantron'}{'scantronformat'});
+ if ($formatfile ne '-1') {
+ @lines = split("\n",$formatfile,-1);
+ $gottab = 1;
+ }
+ }
+ }
+ if (!$gottab) {
+ my $confname = $cdom.'-domainconfig';
+ my $default = $Apache::lonnet::perlvar{'lonDocRoot'}.'/res/'.$cdom.'/'.$confname.'/default.tab';
+ my $formatfile = &Apache::lonnet::getfile($default);
+ if ($formatfile ne '-1') {
+ @lines = split("\n",$formatfile,-1);
+ $gottab = 1;
+ }
+ }
+ if (!$gottab) {
+ my @domains = &Apache::lonnet::current_machine_domains();
+ if (grep(/^\Q$cdom\E$/,@domains)) {
+ my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
+ @lines = <$fh>;
+ close($fh);
+ } else {
+ my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab');
+ @lines = <$fh>;
+ close($fh);
+ }
+ }
+ return @lines;
+}
+
+=pod
+
+=item scantron_CODElist
+
+ Returns html drop down of the saved CODE lists from current course,
+ generated from earlier printings.
+
+=cut
+
+sub scantron_CODElist {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
+ my $namechoice='';
+ foreach my $name (sort {uc($a) cmp uc($b)} @names) {
+ if ($name =~ /^error: 2 /) { next; }
+ if ($name =~ /^type\0/) { next; }
+ $namechoice.='';
+ }
+ $namechoice=''.$namechoice.'';
+ return $namechoice;
+}
+
+=pod
+=item scantron_CODEunique
+
+ Returns the html for "Each CODE to be used once" radio.
+
+=cut
+
+sub scantron_CODEunique {
+ my $result='
+
+
+
+
+ ';
return $result;
}
+=pod
+
+=item scantron_selectphase
+
+ Generates the initial screen to start the bubblesheet process.
+ Allows for - starting a grading run.
+ - downloading existing scan data (original, corrected
+ or skipped info)
+
+ - uploading new scan data
+
+ Arguments:
+ $r - The Apache request object
+ $file2grade - name of the file that contain the scanned data to score
+
+=cut
+
sub scantron_selectphase {
- my ($r) = @_;
- my ($symb,$url)=&get_symb_and_url($r);
+ my ($r,$file2grade) = @_;
+ my ($symb)=&get_symb($r);
if (!$symb) {return '';}
- my $sequence_selector=&getSequenceDropDown($r,$symb);
- my $default_form_data=&defaultFormData($symb,$url);
- my $grading_menu_button=&show_grading_menu_form($symb,$url);
- my $file_selector=&scantron_uploads();
+ my $map_error;
+ my $sequence_selector=&getSequenceDropDown($symb,\$map_error);
+ if ($map_error) {
+ $r->print(' '.&navmap_errormsg().' ');
+ return;
+ }
+ my $default_form_data=&defaultFormData($symb);
+ my $grading_menu_button=&show_grading_menu_form($symb);
+ my $file_selector=&scantron_uploads($file2grade);
my $format_selector=&scantron_scantab();
+ my $CODE_selector=&scantron_CODElist();
+ my $CODE_unique=&scantron_CODEunique();
my $result;
- $result.= <
-
- $default_form_data
-