'.
+ '';
+ my $loop = 0;
+ while ($loop < 2) {
+ $gradeTable.=' No. Select '.
+ ''.&nameUserString('header').' Section/Group ';
+ if ($env{'form.showgrading'} eq 'yes'
+ && $submitonly ne 'queued'
+ && $submitonly ne 'all') {
+ foreach (sort(@$partlist)) {
+ my $display_part=&get_display_part((split(/_/))[0],$symb);
+ $gradeTable.=' Part: '.$display_part.
+ ' Status ';
+ }
+ } elsif ($submitonly eq 'queued') {
+ $gradeTable.=' '.&mt('Queue Status').' ';
+ }
+ $loop++;
+# $gradeTable.=' ' if ($loop%2 ==1);
+ }
+ $gradeTable.=' '."\n";
+
+ my $ctr = 0;
+ 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);
+
+ my %status = ();
+
+ if ($submitonly eq 'queued') {
+ my %queue_status =
+ &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
+ $udom,$uname);
+ next if (!defined($queue_status{'gradingqueue'}));
+ $status{'gradingqueue'} = $queue_status{'gradingqueue'};
+ }
+
+ if ($env{'form.showgrading'} eq 'yes'
+ && $submitonly ne 'queued'
+ && $submitonly ne 'all') {
+ (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist);
+ my $submitted = 0;
+ my $graded = 0;
+ my $incorrect = 0;
+ foreach (keys(%status)) {
+ $submitted = 1 if ($status{$_} ne 'nothing');
+ $graded = 1 if ($status{$_} =~ /^ungraded/);
+ $incorrect = 1 if ($status{$_} =~ /^incorrect/);
+
+ my ($foo,$partid,$foo1) = split(/\./,$_);
+ if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
+ $submitted = 0;
+ my ($part)=split(/\./,$partid);
+ $gradeTable.=' ';
+ }
+ }
+
+ next if (!$submitted && ($submitonly eq 'yes' ||
+ $submitonly eq 'incorrect' ||
+ $submitonly eq 'graded'));
+ next if (!$graded && ($submitonly eq 'graded'));
+ next if (!$incorrect && $submitonly eq 'incorrect');
+ }
+
+ $ctr++;
+ my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
+ my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()];
+ if ( $perm{'vgr'} eq 'F' ) {
+ $gradeTable.='' if ($ctr%2 ==1);
+ $gradeTable.=''.$ctr.' '.
+ ' '."\n".''.
+ &nameUserString(undef,$$fullname{$student},$uname,$udom).
+ ' '.$section.'/'.$group.' '."\n";
+
+ if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
+ foreach (sort keys(%status)) {
+ next if (/^resource.*?submitted_by$/);
+ $gradeTable.=' '.$status{$_}.' '."\n";
+ }
+ }
+# $gradeTable.=' ' if ($ctr%2 ==1);
+ $gradeTable.=' '."\n" if ($ctr%2 ==0);
+ }
+ }
+ if ($ctr%2 ==1) {
+ $gradeTable.=' ';
+ if ($env{'form.showgrading'} eq 'yes'
+ && $submitonly ne 'queued'
+ && $submitonly ne 'all') {
+ foreach (@$partlist) {
+ $gradeTable.=' ';
+ }
+ } elsif ($submitonly eq 'queued') {
+ $gradeTable.=' ';
+ }
+ $gradeTable.='';
+ }
- if ($counter == 0) {
- $request->print(<
'."\n".
+ ' " />'."\n";
+ if ($ctr == 0) {
+ my $num_students=(scalar(keys(%$fullname)));
+ if ($num_students eq 0) {
+ $gradeTable=' There are no students currently enrolled. ';
+ } else {
+ 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=' '.
+ 'No '.$submissions.' found for this resource for any students. ('.$num_students.
+ ' students checked for '.$submissions.') ';
+ }
+ } elsif ($ctr == 1) {
+ $gradeTable =~ s/type=checkbox/type=checkbox checked/;
+ }
+ $gradeTable.=&show_grading_menu_form($symb);
+ $request->print($gradeTable);
+ return '';
+}
+
+#---- Called from the listStudents routine
+
+sub check_script {
+ my ($form, $type)=@_;
+ my $chkallscript=''."\n";
+ return $chkallscript;
+}
+
+sub check_buttons {
+ my $buttons.=' ';
+ $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 = &Apache::loncommon::get_env_multiple('form.stuinfo');
+ my $total = scalar(@stuchecked)-1;
+
+ 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++;
+ }
+ return '';
+}
+
+#------------------------------------------------------------------------------------
+#
+#-------------------------- Next few routines handles grading by student, essentially
+# handles essay response type problem/part
+#
+#--- Javascript to handle the submission page functionality ---
+sub sub_page_js {
+ my $request = shift;
+ $request->print(<
- function updateRadio(radioButton,formtextbox,formsel,wgt) {
- var pts = formtextbox.value;
- var resetbox =false;
- if (isNaN(pts) || pts < 0) {
- alert("A number equal or greater than 0 is expected. Entered value = "+pts);
+ function updateRadio(formname,id,weight) {
+ var gradeBox = formname["GD_BOX"+id];
+ var radioButton = formname["RADVAL"+id];
+ var oldpts = formname["oldpts"+id].value;
+ var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
+ gradeBox.value = pts;
+ var resetbox = false;
+ if (isNaN(pts) || pts < 0) {
+ alert("A number equal or greater than 0 is expected. Entered value = "+pts);
+ for (var i=0; i weight) {
+ var resp = confirm("You entered a value ("+pts+
+ ") greater than the weight for the part. Accept?");
+ if (resp == false) {
+ gradeBox.value = oldpts;
+ return;
+ }
+ }
+
for (var i=0; i
+SUBJAVASCRIPT
+}
+
+#--- javascript for essay type problem --
+sub sub_page_kw_js {
+ my $request = shift;
+ my $iconpath = $request->dir_config('lonIconsURL');
+ &commonJSfunctions($request);
+
+ my $inner_js_msg_central=<
+ function checkInput() {
+ opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);
+ var nmsg = opener.document.SCORE.savemsgN.value;
+ var usrctr = document.msgcenter.usrctr.value;
+ var newval = opener.document.SCORE["newmsg"+usrctr];
+ newval.value = opener.checkEntities(document.msgcenter.newmsg.value);
+
+ var msgchk = "";
+ if (document.msgcenter.subchk.checked) {
+ msgchk = "msgsub,";
+ }
+ var includemsg = 0;
+ for (var i=1; i<=nmsg; i++) {
+ var opnmsg = opener.document.SCORE["savemsg"+i];
+ var frmmsg = document.msgcenter["msg"+i];
+ opnmsg.value = opener.checkEntities(frmmsg.value);
+ var showflg = opener.document.SCORE["shownOnce"+i];
+ showflg.value = "1";
+ var chkbox = document.msgcenter["msgn"+i];
+ if (chkbox.checked) {
+ msgchk += "savemsg"+i+",";
+ includemsg = 1;
+ }
+ }
+ if (document.msgcenter.newmsgchk.checked) {
+ msgchk += "newmsg"+usrctr;
+ includemsg = 1;
+ }
+ imgformname = opener.document.SCORE["mailicon"+usrctr];
+ imgformname.src = "$iconpath/"+((includemsg) ? "mailto.gif" : "mailbkgrd.gif");
+ var includemsg = opener.document.SCORE["includemsg"+usrctr];
+ includemsg.value = msgchk;
+
+ self.close()
- function updateSelect(formsel,pts,wgt) {
- if (pts == 0) {
- formsel[1].selected = true;
}
- if (pts > 0 && pts < wgt) {
- formsel[4].selected = true;
+
+INNERJS
+
+ my $inner_js_highlight_central=<
+ function updateChoice(flag) {
+ opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);
+ opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);
+ opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);
+ opener.document.SCORE.refresh.value = "on";
+ if (opener.document.SCORE.keywords.value!=""){
+ opener.document.SCORE.submit();
+ }
+ self.close()
}
- if (pts == wgt) {
- formsel[0].selected = true;
+
+INNERJS
+
+ my $start_page_msg_central =
+ &Apache::loncommon::start_page('Message Central',$inner_js_msg_central,
+ {'js_ready' => 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\.//;
+ $request->print(<
+
+//===================== Show list of keywords ====================
+ function keywords(formname) {
+ var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
+ if (nret==null) return;
+ formname.keywords.value = nret;
+
+ if (formname.keywords.value != "") {
+ formname.refresh.value = "on";
+ formname.submit();
}
return;
}
- function keywords(keyform) {
- var keywds = keyform.value;
- var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",keywds);
- if (nret==null) return;
- keyform.value = nret;
+//===================== Script to view submitted by ==================
+ function viewSubmitter(submitter) {
+ document.SCORE.refresh.value = "on";
+ document.SCORE.NCT.value = "1";
+ document.SCORE.unamedom0.value = submitter;
+ document.SCORE.submit();
return;
}
@@ -413,115 +1395,130 @@ sub submission {
else return;
var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
if (cleantxt=="") {
- alert("Select a word or group of words from document and then click this link.");
+ alert("Please select a word or group of words from document and then click this link.");
return;
}
- var nret = prompt("Add selection to keyword list?",cleantxt);
+ var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
if (nret==null) return;
- var curlist = document.SCORE.keywords.value;
- document.SCORE.keywords.value = curlist+" "+nret;
+ document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
+ if (document.SCORE.keywords.value != "") {
+ document.SCORE.refresh.value = "on";
+ document.SCORE.submit();
+ }
return;
}
//====================== Script for composing message ==============
+ // preload images
+ img1 = new Image();
+ img1.src = "$iconpath/mailbkgrd.gif";
+ img2 = new Image();
+ img2.src = "$iconpath/mailto.gif";
+
function msgCenter(msgform,usrctr,fullname) {
var Nmsg = msgform.savemsgN.value;
savedMsgHeader(Nmsg,usrctr,fullname);
var subject = msgform.msgsub.value;
- displaySubject(subject);
+ var msgchk = document.SCORE["includemsg"+usrctr].value;
+ re = /msgsub/;
+ var shwsel = "";
+ if (re.test(msgchk)) { shwsel = "checked" }
+ subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
+ displaySubject(checkEntities(subject),shwsel);
for (var i=1; i<=Nmsg; i++) {
- var message = eval("document.SCORE.savemsg"+i+".value");
- displaySavedMsg(i,message);
+ var testmsg = "savemsg"+i+",";
+ re = new RegExp(testmsg,"g");
+ shwsel = "";
+ if (re.test(msgchk)) { shwsel = "checked" }
+ var message = document.SCORE["savemsg"+i].value;
+ message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
+ displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
+ //any < is already converted to <, etc. However, only once!!
}
- newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
- newMsg(newmsg);
+ newmsg = document.SCORE["newmsg"+usrctr].value;
+ shwsel = "";
+ re = /newmsg/;
+ if (re.test(msgchk)) { shwsel = "checked" }
+ newMsg(newmsg,shwsel);
msgTail();
return;
}
-function savedMsgHeader(Nmsg,usrctr,fullname) {
- var height = 30*Nmsg+250;
+ function checkEntities(strx) {
+ if (strx.length == 0) return strx;
+ var orgStr = ["&", "<", ">", '"'];
+ 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";
if (height > 600) {
height = 600;
scrollbar = "yes";
}
- pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',width=600,height='+height);
- pWin.document.write("");
- pWin.document.write("Message Central ");
-
- pWin.document.write("
SUBJAVASCRIPT
}
- (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
- my ($uname,$udom) = &finduser($ENV{'form.student'});
- if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
-
- 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 $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
-#
-# header info
- if ($counter == 0) {
- $request->print(' Submission Record '.
- ' Resource: '.$url.' ');
- }
+sub get_increment {
+ my $increment = $env{'form.increment'};
+ if ($increment != 1 && $increment != .5 && $increment != .25 &&
+ $increment != .1) {
+ $increment = 1;
+ }
+ return $increment;
+}
+
+#--- 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 $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
+ 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 '' ?
+ '' : &compute_points($$record{'resource.'.$partid.'.awarded'},$wgt));
+ my $result=' '."\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.=''."\n";
+ $result.=&handback_box($symb,$uname,$udom,$counter,$partid,$record);
+ return $result;
+}
+
+sub handback_box {
+ my ($symb,$uname,$udom,$counter,$partid,$record) = @_;
+ my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ my (@respids);
+ my @part_response_id = &flatten_responseType($responseType);
+ foreach my $part_response_id (@part_response_id) {
+ my ($part,$resp) = @{ $part_response_id };
+ if ($part eq $partid) {
+ push(@respids,$resp);
+ }
+ }
+ my $result;
+ foreach my $respid (@respids) {
+ my $prefix = $counter.'_'.$partid.'_'.$respid.'_';
+ my $files=&get_submitted_files($udom,$uname,$partid,$respid,$record);
+ next if (!@$files);
+ my $file_counter = 1;
+ foreach my $file (@$files) {
+ if ($file =~ /\/portfolio\//) {
+ my ($file_path, $file_disp) = ($file =~ m|(.+/)(.+)$|);
+ my ($name,$version,$ext) = &file_name_version_ext($file_disp);
+ $file_disp = "$name.$ext";
+ $file = $file_path.$file_disp;
+ $result.=&mt('Return commented version of [_1] to student.',
+ ''.$file_disp.' ');
+ $result.=' '."\n";
+ $result.=' ';
+ $result.='(File will be uploaded when you click on Save & Next below.) ';
+ $file_counter++;
+ }
+ }
+ }
+ return $result;
+}
+
+sub show_problem {
+ my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode,$form) = @_;
+ my $rendered;
+ my %form = ((ref($form) eq 'HASH')? %{$form} : ());
+ &Apache::lonxml::remember_problem_counter();
+ if ($mode eq 'both' or $mode eq 'text') {
+ $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
+ $env{'request.course.id'},
+ undef,\%form);
+ }
+ if ($removeform) {
+ $rendered=~s|||g;
+ $rendered=~s|( ]*name\s*=\s*"?)(\w+)("?)|$1would_have_been_$2$3|g;
+ }
+ my $companswer;
+ if ($mode eq 'both' or $mode eq 'answer') {
+ &Apache::lonxml::restore_problem_counter();
+ $companswer=
+ &Apache::loncommon::get_student_answers($symb,$uname,$udom,
+ $env{'request.course.id'},
+ %form);
+ }
+ if ($removeform) {
+ $companswer=~s|||g;
+ $companswer=~s|name="submit"|name="would_have_been_submit"|g;
+ }
+ $rendered=
+ ''.
+ $rendered.
+ '
';
+ $companswer=
+ ''.
+ $companswer.
+ '
';
+ my $result;
+ if ($mode eq 'both') {
+ $result=$rendered.$companswer;
+ } elsif ($mode eq 'text') {
+ $result=$rendered;
+ } elsif ($mode eq 'answer') {
+ $result=$companswer;
+ }
+ $result=''.$result.'
';
+ 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 ($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.' in section '.$usec.' in course id '.
+ $env{'request.course.id'}.') ');
+ $request->print(&show_grading_menu_form($symb));
+ return;
+ }
+
+ 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'};
+ if ($env{'form.handgrade'} eq 'yes' && &files_exist($request, $symb)) {
+ &download_all_link($request, $symb);
+ }
+ $request->print(' Submission Record '."\n".
+ ' Resource: '.$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.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') {
+ %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';
+ }
+ my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
+ my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status'));
+ $request->print('';
- $request->print($endform);
- }
- return '';
+
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
+ my ($partlist,$handgrade,$responseType) = &response_type($symb);
+
+ # Display student info
+ $request->print(($counter == 0 ? '' : ' '));
+ my $result='';
+
+ $result.=''."\n");
+ # print student answer/submission
+ # Options are (1) Handgaded 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)$/) {
+ my ($string,$timestamp)= &get_last_submission(\%record);
+
+ my $lastsubonly;
+
+ if ($$timestamp eq '') {
+ $lastsubonly.='
'.$$string[0].'
';
+ } else {
+ $lastsubonly = '
Date Submitted: '.$$timestamp."\n";
+
+ my %seenparts;
+ my @part_response_id = &flatten_responseType($responseType);
+ foreach my $part (@part_response_id) {
+ next if ($env{'form.lastSub'} eq 'hdgrade'
+ && $$handgrade{$$part[0].'_'.$$part[1]} ne 'yes');
+
+ my ($partid,$respid) = @{ $part };
+ my $display_part=&get_display_part($partid,$symb);
+ if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
+ if (exists($seenparts{$partid})) { next; }
+ $seenparts{$partid}=1;
+ my $submitby='
Part: '.$display_part.
+ '
Collaborative submission by: '.
+ '
'.
+ $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.' ';
+ $request->print($submitby);
+ next;
+ }
+ my $responsetype = $responseType->{$partid}->{$respid};
+ if (!exists($record{"resource.$partid.$respid.submission"})) {
+ $lastsubonly.="\n".'
Part: '.
+ $display_part.' ( ID '.$respid.
+ ' ) '.
+ ''.&mt('Nothing submitted - no attempts').'
';
+ next;
+ }
+ foreach my $submission (@$string) {
+ my ($partid,$respid) = ($submission =~ /^resource\.([^\.]*)\.([^\.]*)\.submission/);
+ if (join('_',@{$part}) ne ($partid.'_'.$respid)) { next; }
+ my ($ressub,$subval) = split(/:/,$submission,2);
+ # Similarity check
+ my $similar='';
+ if($env{'form.checkPlag'}){
+ my ($oname,$odom,$ocrsid,$oessay,$osim)=
+ &most_similar($uname,$udom,$subval,\%old_essays);
+ if ($osim) {
+ $osim=int($osim*100.0);
+ my %old_course_desc =
+ &Apache::lonnet::coursedescription($ocrsid,
+ {'one_time' => 1});
+
+ $similar="
".
+ &mt('Essay is [_1]% similar to an essay by [_2] ([_3]:[_4]) in course [_5] (course id [_6]:[_7])',
+ $osim,
+ &Apache::loncommon::plainname($oname,$odom),
+ $oname,$odom,
+ $old_course_desc{'description'},
+ $old_course_desc{'num'},
+ $old_course_desc{'domain'}).
+ ' '.
+ &keywords_highlight($oessay).
+ ' ';
+ }
+ }
+ my $order=&get_order($partid,$respid,$symb,$uname,$udom);
+ if ($env{'form.lastSub'} eq 'lastonly' ||
+ ($env{'form.lastSub'} eq 'hdgrade' &&
+ $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
+ my $display_part=&get_display_part($partid,$symb);
+ $lastsubonly.='
Part: '.
+ $display_part.'
( ID '.$respid.
+ ' ) ';
+ my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
+ if (@$files) {
+ $lastsubonly.='
'.&mt('Like all files provided by users, this file may contain virusses').' ';
+ my $file_counter = 0;
+ foreach my $file (@$files) {
+ $file_counter++;
+ &Apache::lonnet::allowuploaded('/adm/grades',$file);
+ $lastsubonly.='
'.$file.'';
+ }
+ $lastsubonly.='
';
+ }
+ $lastsubonly.='
'.&mt('Submitted Answer:').' '.
+ &cleanRecord($subval,$responsetype,$symb,$partid,
+ $respid,\%record,$order);
+ if ($similar) {$lastsubonly.="
$similar\n";}
+ $lastsubonly.='
';
+ }
+ }
+ }
+ $lastsubonly.='
'."\n";
+ }
+ $request->print($lastsubonly);
+ } elsif ($env{'form.lastSub'} eq 'datesub') {
+ my (undef,$responseType,undef,$parts) = &showResourceInfo($symb);
+ $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
+ } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
+ $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
+ $env{'request.course.id'},
+ $last,'.submission',
+ 'Apache::grades::keywords_highlight'));
+ }
+
+ $request->print('
'."\n");
+ # return if view submission with no grading option
+ if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
+ my $toGrade.='
'."\n" if (&canmodify($usec));
+ $toGrade.='
'."\n";
+ if (($env{'form.command'} eq 'submission') ||
+ ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
+ $toGrade.=''.&show_grading_menu_form($symb);
+ }
+ $request->print($toGrade);
+ return;
+ } else {
+ $request->print(''."\n");
+ }
+
+ # essay grading message center
+ if ($env{'form.handgrade'} eq 'yes') {
+ my $result='';
+
+ $result.='
';
+ 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.'.';
+ }
+ $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
+ $result.='
'."\n".
+ '
'."\n";
+ $result.='
'.
+ &mt('Compose message to student').(scalar(@$col_fullnames) >= 1 ? 's' : '').' ('.
+ &mt('incl. grades').' )'.
+ '
'."\n".
+ '
('.
+ &mt('Message will be sent when you click on Save & Next below.').")\n";
+ $result.='
';
+ $request->print($result);
+ }
+
+ my %seen = ();
+ my @partlist;
+ my @gradePartRespid;
+ my @part_response_id = &flatten_responseType($responseType);
+ $request->print(''.
+
+ ''.
+ '
');
+ 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{$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('
');
+
+ $request->print('');
+ if ($perm{'vgr'}) {
+ $request->print(
+ &Apache::loncommon::track_student_link(&mt('View recent activity'),
+ $uname,$udom,'check'));
+ }
+ if ($perm{'opa'}) {
+ $request->print(
+ &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
+ $uname,$udom,$symb,'check'));
+ }
+ $request->print('
');
+
+ $result=' '."\n";
+ $result.=' '."\n" if ($counter == 0);
+ my $ctr = 0;
+ while ($ctr < scalar(@partlist)) {
+ $result.=' '."\n";
+ $ctr++;
+ }
+ $request->print($result.''."\n");
+
+# Done with printing info for one student
+
+ $request->print('');#LC_grade_show_user_body
+ $request->print('');#LC_grade_show_user
+
+
+ # print end of form
+ if ($counter == $total) {
+ my $endform='';
+ $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.=$fullname->{$name}.' ';
+ }
+ $result.=' '."\n";
+ my ($part)=split(/\./,$part);
+ $result.=' '.
+ "\n";
+ }
+ if (scalar(@bad_collaborators) > 0) {
+ $result.='';
+ $result.=&mt('This student has submitted [quant,_1,invalid collaborator]: [_2]',scalar(@bad_collaborators),join(', ',@bad_collaborators));
+ $result .= '
';
+ }
+ if (scalar(@bad_collaborators > $ncol)) {
+ $result .= '';
+ $result .= &mt('This student has submitted too many '.
+ 'collaborators. Maximum is [_1].',$ncol);
+ $result .= '
';
+ }
+ }
+ return ($result,$fullname,\@col_fullnames);
+}
+
+#--- Retrieve the last submission for all the parts
sub get_last_submission {
- my ($symb,$username,$domain,$course)=@_;
- if ($symb) {
- my (%returnhash)=&Apache::lonnet::restore($symb,$course,$domain,$username);
- if ($returnhash{'version'}) {
+ my ($returnhash)=@_;
+ my (@string,$timestamp);
+ if ($$returnhash{'version'}) {
my %lasthash=();
- my $version;
- for ($version=1;$version<=$returnhash{'version'};$version++) {
- foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
- $lasthash{$_}=$returnhash{$version.':'.$_};
- }
- }
- foreach ((keys %lasthash)) {
- if ($_ =~ /\.submission$/) {return $lasthash{$_}}
+ my ($version);
+ for ($version=1;$version<=$$returnhash{'version'};$version++) {
+ foreach my $key (sort(split(/\:/,
+ $$returnhash{$version.':keys'}))) {
+ $lasthash{$key}=$$returnhash{$version.':'.$key};
+ $timestamp =
+ scalar(localtime($$returnhash{$version.':timestamp'}));
+ }
+ }
+ foreach my $key (keys(%lasthash)) {
+ next if ($key !~ /\.submission$/);
+
+ my ($partid,$foo) = split(/submission$/,$key);
+ my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
+ 'Draft Copy ' : '';
+ push(@string, join(':', $key, $draft.$lasthash{$key}));
}
- return '';
}
- }
+ if (!@string) {
+ $string[0] =
+ 'Nothing submitted - no attempts. ';
+ }
+ return (\@string,\$timestamp);
}
+#--- High light keywords, with style choosen by user.
sub keywords_highlight {
- my $string = shift;
- (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)));
- my %keyhash = &Apache::lonnet::get
- ('nohist_handgrade',[$symb.'_keywords'],
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
- my @keylist = split(/[,\s+]/,$keyhash{$symb.'_keywords'});
- foreach my $word (@keylist) {
- next if ($word eq '');
- $string =~ s/\b$word(\b|\.)/\$word\<\/font\>/gi;
- }
- return $string;
+ my $string = shift;
+ my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
+ my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
+ (my $styleoff = $styleon) =~ s/\\<\//;
+ my @keylist = split(/[,\s+]/,$env{'form.keywords'});
+ foreach my $keyword (@keylist) {
+ $string =~ s/\b\Q$keyword\E(\b|\.)/$styleon$keyword$styleoff<\/font>/gi;
+ }
+ return $string;
}
+#--- Called from submission routine
sub processHandGrade {
- my ($request) = shift;
- my $url = $ENV{'form.url'};
- my $symb = $ENV{'form.symb'};
- my $button = $ENV{'form.gradeOpt'};
- my $ngrade = $ENV{'form.NCT'};
- my $ntstu = $ENV{'form.NTSTU'};
- my $keywords= $ENV{'form.keywords'};
- my $newmsg0 = $ENV{'form.newmsg0'};
- print "newmsg0=$newmsg0 ";
- my $newmsg1 = $ENV{'form.newmsg1'};
- print "newmsg1=$newmsg1 ";
- my $oldmsg1 = $ENV{'form.savemsg1'};
- print "oldmsg1=$oldmsg1 ";
- my $oldmsg2 = $ENV{'form.savemsg2'};
- print "oldmsg1=$oldmsg2 ";
- my $oldmsg3 = $ENV{'form.savemsg3'};
- print "oldmsg1=$oldmsg3 ";
- my $oldmsg4 = $ENV{'form.savemsg4'};
- print "oldmsg1=$oldmsg4 ";
- my $messages = $ENV{'form.includemsg0'};
- print "messages=$messages ";
- if ($keywords ne '') {
- my $crsname = $ENV{'course.'.$ENV{'request.course.id'}.'.num'};
- my $crsdom = $ENV{'course.'.$ENV{'request.course.id'}.'.domain'};
-# my $putresult = &Apache::lonnet::put
-# ('nohist_handgrade',{$symb.'_keywords' => $keywords},
-# $crsdom,$crsname);
- }
- my (@parts) = sort(&getpartlist($url));
+ my ($request) = shift;
+ my $symb = &get_symb($request);
+ my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
+ my $button = $env{'form.gradeOpt'};
+ my $ngrade = $env{'form.NCT'};
+ my $ntstu = $env{'form.NTSTU'};
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+ if ($button eq 'Save & Next') {
+ my $ctr = 0;
+ while ($ctr < $ngrade) {
+ my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
+ my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$symb,$uname,$udom,$ctr);
+ if ($errorflag eq 'no_score') {
+ $ctr++;
+ next;
+ }
+ if ($errorflag eq 'not_allowed') {
+ $request->print("Not allowed to modify grades for $uname:$udom ");
+ $ctr++;
+ next;
+ }
+ my $includemsg = $env{'form.includemsg'.$ctr};
+ my ($subject,$message,$msgstatus) = ('','','');
+ my $restitle = &Apache::lonnet::gettitle($symb);
+ my ($feedurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$uname,$udom);
+ my $messagetail;
+ if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
+ $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
+ unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
+ $subject.=' ['.$restitle.']';
+ my (@msgnum) = split(/,/,$includemsg);
+ foreach (@msgnum) {
+ $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
+ }
+ $message =&Apache::lonfeedback::clear_out_html($message);
+ if ($env{'form.withgrades'.$ctr}) {
+ $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
+ $messagetail = " for $env{'form.probTitle'} ";
+ }
+ $msgstatus =
+ &Apache::lonmsg::user_normal_msg($uname,$udom,$subject,
+ $message.$messagetail,
+ undef,$feedurl,undef,
+ undef,undef,$showsymb,
+ $restitle);
+ $request->print(' '.&mt('Sending message to [_1]:[_2]',$uname,$udom).': '.
+ $msgstatus);
+ }
+ if ($env{'form.collaborator'.$ctr}) {
+ my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
+ foreach my $collabstr (@collabstrs) {
+ my ($part,@collaborators) = split(/:/,$collabstr);
+ foreach my $collaborator (@collaborators) {
+ my ($errorflag,$pts,$wgt) =
+ &saveHandGrade($request,$symb,$collaborator,$udom,$ctr,
+ $env{'form.unamedom'.$ctr},$part);
+ if ($errorflag eq 'not_allowed') {
+ $request->print("".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")." ");
+ next;
+ } elsif ($message ne '') {
+ my ($baseurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$collaborator,
+ $udom);
+ if ($env{'form.withgrades'.$ctr}) {
+ $messagetail = " for $env{'form.probTitle'} ";
+ }
+ $msgstatus =
+ &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message.$messagetail,undef,$baseurl,undef,undef,undef,$showsymb,$restitle);
+ }
+ }
+ }
+ }
+ $ctr++;
+ }
+ }
- if ($button eq 'Save & Next') {
- my $ctr = 0;
- while ($ctr < $ENV{'form.NCT'}) {
- my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
- &saveHandGrade($url,$symb,$uname,$udom,$ctr,@parts);
- if ($ENV{'form.collaborator'.$ctr}) {
- my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
- foreach (@collaborators) {
- &saveHandGrade($url,$symb,$_,$udom,$ctr,@parts);
- }
- }
- $ctr++;
- }
- }
- my $firststu = $ENV{'form.unamedom0'};
- my $laststu = $ENV{'form.unamedom'.($ngrade-1)};
+ if ($env{'form.handgrade'} eq 'yes') {
+ # Keywords sorted in alphabatical order
+ my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
+ my %keyhash = ();
+ $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
+ $env{'form.keywords'} =~ s/^\s+|\s+$//;
+ my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
+ $env{'form.keywords'} = join(' ',@keywords);
+ $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
+ $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
+ $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
+ $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
+ $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
+
+ # message center - Order of message gets changed. Blank line is eliminated.
+ # New messages are saved in env for the next student.
+ # All messages are saved in nohist_handgrade.db
+ my ($ctr,$idx) = (1,1);
+ while ($ctr <= $env{'form.savemsgN'}) {
+ if ($env{'form.savemsg'.$ctr} ne '') {
+ $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
+ $idx++;
+ }
+ $ctr++;
+ }
+ $ctr = 0;
+ while ($ctr < $ngrade) {
+ if ($env{'form.newmsg'.$ctr} ne '') {
+ $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
+ $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
+ $idx++;
+ }
+ $ctr++;
+ }
+ $env{'form.savemsgN'} = --$idx;
+ $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
+ my $putresult = &Apache::lonnet::put
+ ('nohist_handgrade',\%keyhash,$cdom,$cnum);
+ }
+ # Called by Save & Refresh from Highlight Attribute Window
+ my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
+ if ($env{'form.refresh'} eq 'on') {
+ my ($ctr,$total) = (0,0);
+ while ($ctr < $ngrade) {
+ $total++ if $env{'form.unamedom'.$ctr} ne '';
+ $ctr++;
+ }
+ $env{'form.NTSTU'}=$ngrade;
+ $ctr = 0;
+ while ($ctr < $total) {
+ my $processUser = $env{'form.unamedom'.$ctr};
+ ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
+ $env{'form.fullname'} = $$fullname{$processUser};
+ &submission($request,$ctr,$total-1);
+ $ctr++;
+ }
+ return '';
+ }
- my ($classlist) = &getclasslist($ENV{'form.section'},'0');
+# Go directly to grade student - from submission or link from chart page
+ if ($button eq 'Grade Student') {
+ (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($symb);
+ my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
+ ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
+ $env{'form.fullname'} = $$fullname{$processUser};
+ &submission($request,0,0);
+ return '';
+ }
- my (@nextlist,@prevlist);
- my ($nextflg,$prevflg,$ctr,$ctprev) = (0,0,0,0);
- foreach my $student ( sort(@{ $$classlist{$ENV{'form.section'}} }) ) {
- my ($uname,$udom) = split(/:/,$student);
- if ($nextflg == 1 && $button =~ /Next$/) {
- push @nextlist,$uname if ($ctr < $ntstu);
- $ctr++;
- }
- $nextflg = 1 if ($student eq $laststu);
- $prevflg = 1 if ($student eq $firststu);
- if ($prevflg == 0 && $button eq 'Previous') {
- push @prevlist,$uname;
- $ctprev++;
- }
- }
- if ($button eq 'Previous') {
- if ($ctprev <= $ntstu) {
- @nextlist = @prevlist;
- } else {
- my $idx = 0;
- my $start = $ctprev - $ntstu;
- while ($idx < $ntstu) {
- $nextlist[$idx] = $prevlist[$start+$idx];
- $idx++;
- }
- }
- }
- $ctr = 0;
- my $total = scalar(@nextlist)-1;
- foreach my $student (@nextlist) {
- $ENV{'form.student'} = $student;
- &submission($request,$ctr,$total);
- $ctr++;
- }
+ # Get the next/previous one or group of students
+ my $firststu = $env{'form.unamedom0'};
+ my $laststu = $env{'form.unamedom'.($ngrade-1)};
+ my $ctr = 2;
+ while ($laststu eq '') {
+ $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
+ $ctr++;
+ $laststu = $firststu if ($ctr > $ngrade);
+ }
- return 'The End';
+ my (@parsedlist,@nextlist);
+ my ($nextflg) = 0;
+ foreach (sort
+ {
+ if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
+ return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
+ }
+ return $a cmp $b;
+ } (keys(%$fullname))) {
+ if ($nextflg == 1 && $button =~ /Next$/) {
+ push @parsedlist,$_;
+ }
+ $nextflg = 1 if ($_ eq $laststu);
+ if ($button eq 'Previous') {
+ last if ($_ eq $firststu);
+ push @parsedlist,$_;
+ }
+ }
+ $ctr = 0;
+ @parsedlist = reverse @parsedlist if ($button eq 'Previous');
+ my ($partlist) = &response_type($symb);
+ foreach my $student (@parsedlist) {
+ my $submitonly=$env{'form.submitonly'};
+ my ($uname,$udom) = split(/:/,$student);
+
+ if ($submitonly eq 'queued') {
+ my %queue_status =
+ &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
+ $udom,$uname);
+ next if (!defined($queue_status{'gradingqueue'}));
+ }
+
+ if ($submitonly =~ /^(yes|graded|incorrect)$/) {
+# my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
+ my %status=&student_gradeStatus($symb,$udom,$uname,$partlist);
+ my $submitted = 0;
+ my $ungraded = 0;
+ my $incorrect = 0;
+ foreach (keys(%status)) {
+ $submitted = 1 if ($status{$_} ne 'nothing');
+ $ungraded = 1 if ($status{$_} =~ /^ungraded/);
+ $incorrect = 1 if ($status{$_} =~ /^incorrect/);
+ my ($foo,$partid,$foo1) = split(/\./,$_);
+ if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
+ $submitted = 0;
+ }
+ }
+ next if (!$submitted && ($submitonly eq 'yes' ||
+ $submitonly eq 'incorrect' ||
+ $submitonly eq 'graded'));
+ next if (!$ungraded && ($submitonly eq 'graded'));
+ next if (!$incorrect && $submitonly eq 'incorrect');
+ }
+ push @nextlist,$student if ($ctr < $ntstu);
+ last if ($ctr == $ntstu);
+ $ctr++;
+ }
+
+ $ctr = 0;
+ my $total = scalar(@nextlist)-1;
+
+ foreach (sort @nextlist) {
+ my ($uname,$udom,$submitter) = split(/:/);
+ $env{'form.student'} = $uname;
+ $env{'form.userdom'} = $udom;
+ $env{'form.fullname'} = $$fullname{$_};
+ &submission($request,$ctr,$total);
+ $ctr++;
+ }
+ if ($total < 0) {
+ my $the_end = 'LON-CAPA User Message '."\n";
+ $the_end.='Message: No more students for this section or class. '."\n";
+ $the_end.='Click on the button below to return to the grading menu. '."\n";
+ $the_end.=&show_grading_menu_form($symb);
+ $request->print($the_end);
+ }
+ return '';
}
+#---- Save the score and award for each student, if changed
sub saveHandGrade {
- my ($url,$symb,$stuname,$domain,$newflg,@parts) = @_;
- my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
- my %newrecord;
-
- foreach my $part (@parts) {
- my ($temp,$part,$type)=split(/_/,$part);
- my $oldscore=$record{"resource.$part.$type"};
- my $newscore;
- if ($type eq 'awarded' && $newflg >= 0) {
- my $pts = ($ENV{'form.GRADE_BOX'.$newflg} ne '' ?
- $ENV{'form.GRADE_BOX'.$newflg} : $ENV{'form.RADVAL'.$newflg});
- my $wgt = $ENV{'form.WGT'.$newflg};
-# my $sel = $ENV{'form.GRADE_SEL'.$newflg};
- $newscore = $pts/$wgt if ($wgt != 0);
- }
- if ($type eq 'solved') {
- $newscore = $ENV{'form.GRADE_SEL'.$newflg} if ($newflg >= 0);
- my $update=0;
- if ($newscore eq 'nothing' ) {
- if ($oldscore ne '') {
- $update=1;
- $newscore = '';
- }
- } elsif ($oldscore !~ m/^$newscore/) {
- $update=1;
- if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
- if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
- if ($newscore eq 'excused') { $newscore = 'excused'; }
- if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
- if ($newscore eq 'partial') { $newscore = 'correct_partially_by_override'; }
- }
- if ($update) { $newrecord{"resource.$part.$type"}=$newscore; }
- } else {
- if ($oldscore ne $newscore) {
- $newrecord{"resource.$part.$type"}=$newscore;
- }
+ my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
+ my @version_parts;
+ my $usec = &Apache::lonnet::getsection($domain,$stuname,
+ $env{'request.course.id'});
+ if (!&canmodify($usec)) { return('not_allowed'); }
+ my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
+ my @parts_graded;
+ my %newrecord = ();
+ my ($pts,$wgt) = ('','');
+ my %aggregate = ();
+ my $aggregateflag = 0;
+ my @parts = split(/:/,$env{'form.partlist'.$newflg});
+ foreach my $new_part (@parts) {
+ #collaborator ($submi may vary for different parts
+ if ($submitter && $new_part ne $part) { next; }
+ my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
+ if ($dropMenu eq 'excused') {
+ if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
+ $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
+ if (exists($record{'resource.'.$new_part.'.awarded'})) {
+ $newrecord{'resource.'.$new_part.'.awarded'} = '';
+ }
+ $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
+ }
+ } elsif ($dropMenu eq 'reset status'
+ && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
+ foreach my $key (keys (%record)) {
+ if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
+ }
+ $newrecord{'resource.'.$new_part.'.regrader'}=
+ "$env{'user.name'}:$env{'user.domain'}";
+ my $totaltries = $record{'resource.'.$part.'.tries'};
+
+ my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
+ [$new_part]);
+ my $aggtries =$totaltries;
+ if ($last_resets{$new_part}) {
+ $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
+ $new_part);
+ }
+
+ my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
+ if ($aggtries > 0) {
+ &decrement_aggs($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
+ $aggregateflag = 1;
+ }
+ } elsif ($dropMenu eq '') {
+ $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
+ $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
+ $env{'form.RADVAL'.$newflg.'_'.$new_part});
+ if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
+ next;
+ }
+ $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
+ $env{'form.WGT'.$newflg.'_'.$new_part};
+ my $partial= $pts/$wgt;
+ if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
+ #do not update score for part if not changed.
+ &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord);
+ next;
+ } else {
+ push @parts_graded, $new_part;
+ }
+ if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
+ $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
+ }
+ my $reckey = 'resource.'.$new_part.'.solved';
+ if ($partial == 0) {
+ if ($record{$reckey} ne 'incorrect_by_override') {
+ $newrecord{$reckey} = 'incorrect_by_override';
+ }
+ } else {
+ if ($record{$reckey} ne 'correct_by_override') {
+ $newrecord{$reckey} = 'correct_by_override';
+ }
+ }
+ if ($submitter &&
+ ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
+ $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
+ }
+ $newrecord{'resource.'.$new_part.'.regrader'}=
+ "$env{'user.name'}:$env{'user.domain'}";
+ }
+ # unless problem has been graded, set flag to version the submitted files
+ unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
+ $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
+ $dropMenu eq 'reset status')
+ {
+ push (@version_parts,$new_part);
+ }
}
- }
- if ( scalar(keys(%newrecord)) > 0 ) {
- $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
-# while (my ($k,$v) = each %newrecord) {
-# print "k=$k:v=$v: \n";
-# }
-# print "symb=$symb,courseid=$ENV{'request.course.id'},dom=$domain,name=$stuname ";
-# &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'},$domain,$stuname);
- }
- return '';
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+
+ if (%newrecord) {
+ if (@version_parts) {
+ my @changed_keys = &version_portfiles(\%record, \@parts_graded,
+ $env{'request.course.id'}, $symb, $domain, $stuname, \@version_parts);
+ @newrecord{@changed_keys} = @record{@changed_keys};
+ foreach my $new_part (@version_parts) {
+ &handback_files($request,$symb,$stuname,$domain,$newflg,
+ $new_part,\%newrecord);
+ }
+ }
+ &Apache::lonnet::cstore(\%newrecord,$symb,
+ $env{'request.course.id'},$domain,$stuname);
+ &check_and_remove_from_queue(\@parts,\%record,\%newrecord,$symb,
+ $cdom,$cnum,$domain,$stuname);
+ }
+ if ($aggregateflag) {
+ &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
+ $cdom,$cnum);
+ }
+ return ('',$pts,$wgt);
}
-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 check_and_remove_from_queue {
+ my ($parts,$record,$newrecord,$symb,$cdom,$cnum,$domain,$stuname) = @_;
+ my @ungraded_parts;
+ foreach my $part (@{$parts}) {
+ if ( $record->{ 'resource.'.$part.'.awarded'} eq ''
+ && $record->{ 'resource.'.$part.'.solved' } ne 'excused'
+ && $newrecord->{'resource.'.$part.'.awarded'} eq ''
+ && $newrecord->{'resource.'.$part.'.solved' } ne 'excused'
+ ) {
+ push(@ungraded_parts, $part);
+ }
+ }
+ if ( !@ungraded_parts ) {
+ &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
+ $cnum,$domain,$stuname);
+ }
}
-sub show_grading_menu_form {
- my ($symb,$url)=@_;
- my $result.=''."\n";
- return $result;
-}
-
-sub gradingmenu {
- my ($request) = @_;
- my ($symb,$url)=&get_symb_and_url($request);
- if (!$symb) {return '';}
- my $allkeys = &Apache::lonnet::metadata($url,'keys');
- my $handgrade = ($allkeys =~ /parameter_.*?_handgrade/ ? 'yes' : 'no');
- my ($responsetype,$foo) = split(/_/,&Apache::lonnet::metadata($url,'packages'));
-
- my $result=' Select a Grading Method ';
- $result.='';
- $result.='Resource: '.
- ''.$url.' ';
- $result.='Type: '.
- ''.$responsetype.' Handgrade: '.$handgrade.' ';
- $result.='
';
-
- $result.=&view_edit_entire_class_form($symb,$url).' ';
- $result.=&upcsvScores_form($symb,$url).' ';
- $result.=&viewGradeaStu_form($symb,$url,$responsetype,$handgrade).' ';
- $result.=&verifyReceipt_form($symb,$url);
- return $result;
-}
-
-sub view_edit_entire_class_form {
- my ($symb,$url)=@_;
- my $result.=''."\n";
- $result.=''."\n";
- $result.=' View/Grade Entire Class '."\n";
- $result.=''."\n";
- $result.=''."\n";
- $result.='
'."\n";
- $result.='
'."\n";
- return $result;
+sub handback_files {
+ my ($request,$symb,$stuname,$domain,$newflg,$new_part,$newrecord) = @_;
+ my $portfolio_root = &propath($domain,$stuname).'/userfiles/portfolio';
+ my ($partlist,$handgrade,$responseType) = &response_type($symb);
+
+ my @part_response_id = &flatten_responseType($responseType);
+ foreach my $part_response_id (@part_response_id) {
+ my ($part_id,$resp_id) = @{ $part_response_id };
+ my $part_resp = join('_',@{ $part_response_id });
+ if (($env{'form.'.$newflg.'_'.$part_resp.'_returndoc1'}) && ($new_part == $part_id)) {
+ # if multiple files are uploaded names will be 'returndoc2','returndoc3'
+ my $file_counter = 1;
+ my $file_msg;
+ while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) {
+ my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'};
+ my ($directory,$answer_file) =
+ ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter} =~ /^(.*?)([^\/]*)$/);
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($answer_file);
+ my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/);
+ my @dir_list = &Apache::lonnet::dirlist($portfolio_path,$domain,$stuname,$portfolio_root);
+ my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+ # fix file name
+ my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/);
+ my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain,
+ $newflg.'_'.$part_resp.'_returndoc'.$file_counter,
+ $save_file_name);
+ if ($result !~ m|^/uploaded/|) {
+ $request->print('An error occurred ('.$result.
+ ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.' ');
+ } else {
+ # mark the file as read only
+ my @files = ($save_file_name);
+ my @what = ($symb,$env{'request.course.id'},'handback');
+ &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what);
+ if (exists($$newrecord{"resource.$new_part.$resp_id.handback"})) {
+ $$newrecord{"resource.$new_part.$resp_id.handback"}.=',';
+ }
+ $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name;
+ $file_msg.= "\n".''.$save_file_name." ";
+
+ }
+ $request->print(" ".$fname." will be the uploaded file name");
+ $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter});
+ $file_counter++;
+ }
+ my $subject = "File Handed Back by Instructor ";
+ my $message = "A file has been returned that was originally submitted in reponse to: ";
+ $message .= "".&Apache::lonnet::gettitle($symb)." ";
+ $message .= ' The returned file(s) are named: '. $file_msg;
+ $message .= " and can be found in your portfolio space.";
+ my ($feedurl,$showsymb) =
+ &get_feedurl_and_symb($symb,$domain,$stuname);
+ my $restitle = &Apache::lonnet::gettitle($symb);
+ my $msgstatus =
+ &Apache::lonmsg::user_normal_msg($stuname,$domain,$subject.
+ ' (File Returned) ['.$restitle.']',$message,undef,
+ $feedurl,undef,undef,undef,$showsymb,$restitle);
+ }
+ }
+ return;
}
-sub upcsvScores_form {
- my ($symb,$url) = @_;
- if (!$symb) {return '';}
- my $result.=''."\n";
- $result.=''."\n";
- $result.='
'."\n";
- return $result;
-}
-
-sub viewGradeaStu_form {
- my ($symb,$url,$response,$handgrade) = @_;
- my ($classlist,$sections) = &getclasslist('all','0');
- my $result.=''."\n";
- $result.=''."\n";
- $result.=' View/Grade an Individual Student\'s Submission '."\n";
- $result.=''."\n";
- $result.=''."\n";
- $result.='
'."\n";
- $result.='
'."\n";
- return $result;
-}
-
-sub verifyReceipt_form {
- my ($symb,$url) = @_;
- my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
- my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
- my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
-
- my $result.=''."\n";
- $result.=''."\n";
- $result.=' Verify a Submission Receipt Issued by this Server '."\n";
- $result.=''."\n";
- $result.='';
- $result.='
'."\n";
- $result.='
'."\n";
- return $result;
+sub get_feedurl_and_symb {
+ my ($symb,$uname,$udom) = @_;
+ my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb);
+ $url = &Apache::lonnet::clutter($url);
+ my $encrypturl=&Apache::lonnet::EXT('resource.0.encrypturl',
+ $symb,$udom,$uname);
+ if ($encrypturl =~ /^yes$/i) {
+ &Apache::lonenc::encrypted(\$url,1);
+ &Apache::lonenc::encrypted(\$symb,1);
+ }
+ return ($url,$symb);
+}
+
+sub get_submitted_files {
+ my ($udom,$uname,$partid,$respid,$record) = @_;
+ my @files;
+ if ($$record{"resource.$partid.$respid.portfiles"}) {
+ my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
+ foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
+ push(@files,$file_url.$file);
+ }
+ }
+ if ($$record{"resource.$partid.$respid.uploadedurl"}) {
+ push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
+ }
+ return (\@files);
+}
+
+# ----------- Provides number of tries since last reset.
+sub get_num_tries {
+ my ($record,$last_reset,$part) = @_;
+ my $timestamp = '';
+ my $num_tries = 0;
+ if ($$record{'version'}) {
+ for (my $version=$$record{'version'};$version>=1;$version--) {
+ if (exists($$record{$version.':resource.'.$part.'.solved'})) {
+ $timestamp = $$record{$version.':timestamp'};
+ if ($timestamp > $last_reset) {
+ $num_tries ++;
+ } else {
+ last;
+ }
+ }
+ }
+ }
+ return $num_tries;
+}
+
+# ----------- Determine decrements required in aggregate totals
+sub decrement_aggs {
+ my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
+ my %decrement = (
+ attempts => 0,
+ users => 0,
+ correct => 0
+ );
+ $decrement{'attempts'} = $aggtries;
+ if ($solvedstatus =~ /^correct/) {
+ $decrement{'correct'} = 1;
+ }
+ if ($aggtries == $totaltries) {
+ $decrement{'users'} = 1;
+ }
+ foreach my $type (keys (%decrement)) {
+ $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
+ }
+ return;
+}
+
+# ----------- Determine timestamps for last reset of aggregate totals for parts
+sub get_last_resets {
+ my ($symb,$courseid,$partids) =@_;
+ my %last_resets;
+ my $cdom = $env{'course.'.$courseid.'.domain'};
+ my $cname = $env{'course.'.$courseid.'.num'};
+ my @keys;
+ foreach my $part (@{$partids}) {
+ push(@keys,"$symb\0$part\0resettime");
+ }
+ my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
+ $cdom,$cname);
+ foreach my $part (@{$partids}) {
+ $last_resets{$part}=$results{"$symb\0$part\0resettime"};
+ }
+ return %last_resets;
+}
+
+# ----------- Handles creating versions for portfolio files as answers
+sub version_portfiles {
+ my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
+ my $version_parts = join('|',@$v_flag);
+ my @returned_keys;
+ my $parts = join('|', @$parts_graded);
+ my $portfolio_root = &propath($domain,$stu_name).
+ '/userfiles/portfolio';
+ foreach my $key (keys(%$record)) {
+ my $new_portfiles;
+ if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
+ my @versioned_portfiles;
+ my @portfiles = split(/\s*,\s*/,$$record{$key});
+ foreach my $file (@portfiles) {
+ &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
+ my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($answer_file);
+ my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
+ my $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
+ my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
+ if ($new_answer ne 'problem getting file') {
+ push(@versioned_portfiles, $directory.$new_answer);
+ &Apache::lonnet::mark_as_readonly($domain,$stu_name,
+ [$directory.$new_answer],
+ [$symb,$env{'request.course.id'},'graded']);
+ }
+ }
+ $$record{$key} = join(',',@versioned_portfiles);
+ push(@returned_keys,$key);
+ }
+ }
+ return (@returned_keys);
+}
+
+sub get_next_version {
+ my ($answer_name, $answer_ext, $dir_list) = @_;
+ my $version;
+ foreach my $row (@$dir_list) {
+ my ($file) = split(/\&/,$row,2);
+ my ($file_name,$file_version,$file_ext) =
+ &file_name_version_ext($file);
+ if (($file_name eq $answer_name) &&
+ ($file_ext eq $answer_ext)) {
+ # gets here if filename and extension match, regardless of version
+ if ($file_version ne '') {
+ # a versioned file is found so save it for later
+ if ($file_version > $version) {
+ $version = $file_version;
+ }
+ }
+ }
+ }
+ $version ++;
+ return($version);
+}
+
+sub version_selected_portfile {
+ my ($domain,$stu_name,$directory,$file_name,$version) = @_;
+ my ($answer_name,$answer_ver,$answer_ext) =
+ &file_name_version_ext($file_name);
+ my $new_answer;
+ $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
+ if($env{'form.copy'} eq '-1') {
+ $new_answer = 'problem getting file';
+ } else {
+ $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
+ my $copy_result = &Apache::lonnet::finishuserfileupload(
+ $stu_name,$domain,'copy',
+ '/portfolio'.$directory.$new_answer);
+ }
+ return ($new_answer);
+}
+
+sub file_name_version_ext {
+ my ($file)=@_;
+ my @file_parts = split(/\./, $file);
+ my ($name,$version,$ext);
+ if (@file_parts > 1) {
+ $ext=pop(@file_parts);
+ if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
+ $version=pop(@file_parts);
+ }
+ $name=join('.',@file_parts);
+ } else {
+ $name=join('.',@file_parts);
+ }
+ return($name,$version,$ext);
+}
+
+#--------------------------------------------------------------------------------------
+#
+#-------------------------- Next few routines handles grading by section or whole class
+#
+#--- Javascript to handle grading by section or whole class
+sub viewgrades_js {
+ my ($request) = shift;
+
+ $request->print(<
+ function writePoint(partid,weight,point) {
+ var radioButton = document.classgrade["RADVAL_"+partid];
+ var textbox = document.classgrade["TEXTVAL_"+partid];
+ if (point == "textval") {
+ point = document.classgrade["TEXTVAL_"+partid].value;
+ if (isNaN(point) || parseFloat(point) < 0) {
+ alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
+ var resetbox = false;
+ for (var i=0; i parseFloat(weight)) {
+ var resp = confirm("You entered a value ("+parseFloat(point)+
+ ") greater than the weight for the part. Accept?");
+ if (resp == false) {
+ textbox.value = "";
+ return;
+ }
+ }
+ for (var i=0; i parseFloat(weight)) {
+ var resp = confirm("You entered a value ("+parseFloat(point)+
+ ") greater than the weight of the part. Accept?");
+ if (resp == false) {
+ textbox.value = "";
+ return;
+ }
+ }
+ selval[0].selected = true;
+ }
+
+ function changeOneScore(partid,user) {
+ var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
+ if (selval[1].selected || selval[2].selected) {
+ document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
+ if (selval[2].selected) {
+ document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
+ }
+ }
+ }
+
+ function resetEntry(numpart) {
+ for (ctpart=0;ctpart
+VIEWJAVASCRIPT
}
+#--- show scores for a section or whole class w/ option to change/update a score
sub viewgrades {
- my ($request) = @_;
- my $result='';
+ my ($request) = shift;
+ &viewgrades_js($request);
- #get resource reference
- my ($symb,$url)=&get_symb_and_url($request);
- if (!$symb) {return '';}
- #get classlist
- my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
- #print "Found $cdom:$cnum ";
- my ($classlist) = &getclasslist('all','0');
- my $headerclr = '"#ccffff"';
- my $cellclr = '"#ffffcc"';
-
- #get list of parts for this problem
- my (@parts) = sort(&getpartlist($url));
-
- $request->print ("Manual Grading ");
-
- #start the form
- $result = '';
- $result.=&show_grading_menu_form($symb,$url);
- return $result;
+ &build_section_inputs().
+ ' '."\n".
+ ' '."\n".
+ ' '."\n";
+
+ my $sectionClass;
+ my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section'));
+ if ($env{'form.section'} eq 'all') {
+ $sectionClass='Class ';
+ } elsif ($env{'form.section'} eq 'none') {
+ $sectionClass=&mt('Students in no Section').'';
+ } else {
+ $sectionClass=&mt('Students in Section(s) [_1]',$section_display).'';
+ }
+ $result.=''.&mt('Assign Common Grade To [_1]',$sectionClass);
+ $result.= ' '."\n".
+ '';
+ #radio buttons/text box for assigning points for a section or class.
+ #handles different parts of a problem
+ my ($partlist,$handgrade,$responseType) = &response_type($symb);
+ my %weight = ();
+ my $ctsparts = 0;
+ $result.=''.'
'.'
'."\n".
+ ' ';
+ $result.=' ';
+
+ #table listing all the students in a section/class
+ #header of table
+ $result.= 'Assign Grade to Specific Students in '.$sectionClass;
+ $result.= ' '."\n".
+ ' No. '.
+ ''.&nameUserString('header')." \n";
+ my (@parts) = sort(&getpartlist($symb));
+ 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
+ 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/) {
+ $result.='Score Part: '.$display_part.
+ ' (weight = '.$weight{$partid}.') '."\n";
+ next;
+ } else {
+ $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
+ }
+ $display =~ s|Problem Status|Grade Status |;
+ $result.=''.$display.' '."\n";
+ }
+ $result.=' ';
+
+ my %last_resets =
+ &get_last_resets($symb,$env{'request.course.id'},\@partids);
+
+ #get info for each student
+ #list all the students - with points and grade status
+ my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
+ my $ctr = 0;
+ foreach (sort
+ {
+ if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
+ return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
+ }
+ return $a cmp $b;
+ } (keys(%$fullname))) {
+ $ctr++;
+ $result.=&viewstudentgrade($symb,$env{'request.course.id'},
+ $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
+ }
+ $result.='
';
+ $result.=' '."\n";
+ $result.=' '."\n";
+ if (scalar(%$fullname) eq 0) {
+ my $colspan=3+scalar(@parts);
+ 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);
+ return $result;
}
+#--- call by previous routine to display each student
+sub viewstudentgrade {
+ my ($symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
+ my ($uname,$udom) = split(/:/,$student);
+ my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
+ my %aggregates = ();
+ my $result=''.
+ ' '.
+ "\n".$ctr.' '.
+ ''.$fullname.' '.
+ '('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).') '."\n";
+ $student=~s/:/_/; # colon doen't work in javascript for names
+ foreach my $apart (@$parts) {
+ my ($part,$type) = &split_part_type($apart);
+ my $score=$record{"resource.$part.$type"};
+ $result.='';
+ my ($aggtries,$totaltries);
+ unless (exists($aggregates{$part})) {
+ $totaltries = $record{'resource.'.$part.'.tries'};
+
+ $aggtries = $totaltries;
+ if ($$last_resets{$part}) {
+ $aggtries = &get_num_tries(\%record,$$last_resets{$part},
+ $part);
+ }
+ $result.=' '."\n";
+ $result.=' '."\n";
+ $aggregates{$part} = 1;
+ }
+ if ($type eq 'awarded') {
+ my $pts = $score eq '' ? '' : &compute_points($score,$$weight{$part});
+ $result.=' '."\n";
+ $result.=' '."\n";
+ } elsif ($type eq 'solved') {
+ my ($status,$foo)=split(/_/,$score,2);
+ $status = 'nothing' if ($status eq '');
+ $result.=' '."\n";
+ $result.=' '."\n";
+ $result.= (($status eq 'excused') ? ' excused '
+ : ' excused ')."\n";
+ $result.='reset status ';
+ $result.=" \n";
+ } else {
+ $result.=' '.
+ "\n";
+ $result.=' '."\n";
+ }
+ }
+ $result.=' ';
+ return $result;
+}
+
+#--- change scores for all the students in a section/class
+# record does not get update if unchanged
sub editgrades {
- my ($request) = @_;
- my $result='';
+ my ($request) = @_;
- my $symb=$ENV{'form.symb'};
- if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; }
- my $url=$ENV{'form.url'};
- #get classlist
-# my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
- #print "Found $cdom:$cnum ";
- my ($classlist) = &getclasslist('all','0');
-
- #get list of parts for this problem
- my (@parts) = &getpartlist($url);
-
- $result.='