--- loncom/homework/grades.pm 2006/03/13 21:10:34 1.334 +++ loncom/homework/grades.pm 2006/06/27 01:39:09 1.365 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.334 2006/03/13 21:10:34 albertel Exp $ +# $Id: grades.pm,v 1.365 2006/06/27 01:39:09 banghart Exp $ # # Copyright Michigan State University Board of Trustees # @@ -36,10 +36,13 @@ use Apache::lonhtmlcommon; use Apache::lonnavmaps; use Apache::lonhomework; use Apache::loncoursedata; -use Apache::lonmsg qw(:user_normal_msg); +use Apache::lonmsg(); use Apache::Constants qw(:common); use Apache::lonlocal; use String::Similarity; +use lib '/home/httpd/lib/perl'; +use LONCAPA; + use POSIX qw(floor); my %oldessays=(); @@ -118,9 +121,10 @@ sub response_type { my %seen = (); my (@partlist,%handgrade,%responseType); foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) { - if (/^\w+response_.*/) { + if (/^\w+response_.*/ || /^Task_/) { my ($responsetype,$part) = split(/_/,$_,2); my ($partid,$respid) = split(/_/,$part); + if ($responsetype eq 'Task') { $respid='0'; } if (&Apache::loncommon::check_if_partid_hidden($partid,$symb)) { next; } @@ -205,9 +209,11 @@ sub get_order { return ($analyze{"$partid.$respid.shown"}); } #--- Clean response type for display -#--- Currently filters option/rank/radiobutton/match/essay response types only. +#--- Currently filters option/rank/radiobutton/match/essay/Task +# response types only. sub cleanRecord { - my ($answer,$response,$symb,$partid,$respid,$record,$order,$version) = @_; + my ($answer,$response,$symb,$partid,$respid,$record,$order,$version, + $uname,$udom) = @_; my $grayFont = '<font color="#999999">'; if ($response =~ /^(option|rank)$/) { my %answer=&Apache::lonnet::str2hash($answer); @@ -288,6 +294,37 @@ sub cleanRecord { my $jme=$record->{$version."resource.$partid.$respid.molecule"}; $result.=&Apache::chemresponse::jme_img($jme,$answer,400); return $result; + } elsif ( $response eq 'Task') { + if ( $answer eq 'SUBMITTED') { + my $files = $record->{$version."resource.$respid.$partid.bridgetask.portfiles"}; + my $result = &Apache::bridgetask::file_list($files,$uname,$udom); + return $result; + } elsif ( grep(/^\Q$version\E.*?\.instance$/, keys(%{$record})) ) { + my @matches = grep(/^\Q$version\E.*?\.instance$/, + keys(%{$record})); + return join('<br />',($version,@matches)); + + + } else { + my $result = + '<p>' + .&mt('Overall result: [_1]', + $record->{$version."resource.$respid.$partid.status"}) + .'</p>'; + + $result .= '<ul>'; + my @grade = grep(/^\Q${version}resource.$respid.$partid.\E[^.]*[.]status$/, + keys(%{$record})); + foreach my $grade (sort(@grade)) { + my ($dim) = ($grade =~/[.]([^.]+)[.]status$/); + $result.= '<li>'.&mt("Dimension: [_1], status [_2] ", + $dim, $record->{$grade}). + '</li>'; + } + $result.='</ul>'; + return $result; + } + } return $answer; } @@ -688,7 +725,14 @@ LISTJAVASCRIPT $gradeTable.='<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only </label>'."\n". '<label><input type="radio" name="lastSub" value="last" /> last submission & parts info </label>'."\n". '<label><input type="radio" name="lastSub" value="datesub" /> by dates and submissions </label>'."\n". - '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n". + '<label><input type="radio" name="lastSub" value="all" /> all details</label><br />'."\n". + ' <b>Grading Increments:</b> <select name="increment">'. + '<option value="1">Whole Points</option>'. + '<option value=".5">Half Points</option>'. + '<option value=".25">Quarter Points</option>'. + '<option value=".1">Tenths of a Point</option>'. + '</select>'. + '<input type="hidden" name="section" value="'.$getsec.'" />'."\n". '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n". '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n". @@ -1101,6 +1145,81 @@ sub sub_page_kw_js { my $request = shift; my $iconpath = $request->dir_config('lonIconsURL'); &commonJSfunctions($request); + + my $inner_js_msg_central=<<INNERJS; + <script text="text/javascript"> + 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() + + } + </script> +INNERJS + + my $inner_js_highlight_central=<<INNERJS; + <script type="text/javascript"> + 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() + } +</script> +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(<<SUBJAVASCRIPT); @@ -1216,51 +1335,7 @@ sub sub_page_kw_js { pWin.focus(); pDoc = pWin.document; pDoc.$docopen; - pDoc.write("<html><head>"); - pDoc.write("<title>Message Central</title>"); - - pDoc.write("<script language=javascript>"); - pDoc.write("function checkInput() {"); - pDoc.write(" opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);"); - pDoc.write(" var nmsg = opener.document.SCORE.savemsgN.value;"); - pDoc.write(" var usrctr = document.msgcenter.usrctr.value;"); - pDoc.write(" var newval = opener.document.SCORE[\\"newmsg\\"+usrctr];"); - pDoc.write(" newval.value = opener.checkEntities(document.msgcenter.newmsg.value);"); - - pDoc.write(" var msgchk = \\"\\";"); - pDoc.write(" if (document.msgcenter.subchk.checked) {"); - pDoc.write(" msgchk = \\"msgsub,\\";"); - pDoc.write(" }"); - pDoc.write(" var includemsg = 0;"); - pDoc.write(" for (var i=1; i<=nmsg; i++) {"); - pDoc.write(" var opnmsg = opener.document.SCORE[\\"savemsg\\"+i];"); - pDoc.write(" var frmmsg = document.msgcenter[\\"msg\\"+i];"); - pDoc.write(" opnmsg.value = opener.checkEntities(frmmsg.value);"); - pDoc.write(" var showflg = opener.document.SCORE[\\"shownOnce\\"+i];"); - pDoc.write(" showflg.value = \\"1\\";"); - pDoc.write(" var chkbox = document.msgcenter[\\"msgn\\"+i];"); - pDoc.write(" if (chkbox.checked) {"); - pDoc.write(" msgchk += \\"savemsg\\"+i+\\",\\";"); - pDoc.write(" includemsg = 1;"); - pDoc.write(" }"); - pDoc.write(" }"); - pDoc.write(" if (document.msgcenter.newmsgchk.checked) {"); - pDoc.write(" msgchk += \\"newmsg\\"+usrctr;"); - pDoc.write(" includemsg = 1;"); - pDoc.write(" }"); - pDoc.write(" imgformname = opener.document.SCORE[\\"mailicon\\"+usrctr];"); - pDoc.write(" imgformname.src = \\"$iconpath/\\"+((includemsg) ? \\"mailto.gif\\" : \\"mailbkgrd.gif\\");"); - pDoc.write(" var includemsg = opener.document.SCORE[\\"includemsg\\"+usrctr];"); - pDoc.write(" includemsg.value = msgchk;"); - - pDoc.write(" self.close()"); - - pDoc.write("}"); - - pDoc.write("<"); - pDoc.write("/script>"); - - pDoc.write("</head><body bgcolor=white>"); + pDoc.write('$start_page_msg_central'); pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">"); pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">"); @@ -1301,7 +1376,7 @@ sub sub_page_kw_js { pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> "); pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />"); pDoc.write("</form>"); - pDoc.write("</body></html>"); + pDoc.write('$end_page_msg_central'); pDoc.close(); } @@ -1347,26 +1422,7 @@ sub sub_page_kw_js { hwdWin.focus(); var hDoc = hwdWin.document; hDoc.$docopen; - hDoc.write("<html><head>"); - hDoc.write("<title>Highlight Central</title>"); - - hDoc.write("<script language=javascript>"); - hDoc.write("function updateChoice(flag) {"); - hDoc.write(" opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);"); - hDoc.write(" opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);"); - hDoc.write(" opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);"); - hDoc.write(" opener.document.SCORE.refresh.value = \\"on\\";"); - hDoc.write(" if (opener.document.SCORE.keywords.value!=\\"\\"){"); - hDoc.write(" opener.document.SCORE.submit();"); - hDoc.write(" }"); - hDoc.write(" self.close()"); - hDoc.write("}"); - - hDoc.write("<"); - hDoc.write("/script>"); - - hDoc.write("</head><body bgcolor=white>"); - + hDoc.write('$start_page_highlight_central'); hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">"); hDoc.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br /><br />"); @@ -1394,7 +1450,7 @@ sub sub_page_kw_js { hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> "); hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br /><br />"); hDoc.write("</form>"); - hDoc.write("</body></html>"); + hDoc.write('$end_page_highlight_central'); hDoc.close(); } @@ -1402,6 +1458,15 @@ sub sub_page_kw_js { SUBJAVASCRIPT } +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) = @_; @@ -1424,13 +1489,16 @@ sub gradeBox { $result.='<table border="0"><tr><td>'. '<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n"; my $ctr = 0; + my $thisweight = 0; + my $increment = &get_increment(); $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across - while ($ctr<=$wgt) { + while ($thisweight<=$wgt) { $result.= '<td><nobr><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '. 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','. - $ctr.')" value="'.$ctr.'" '. - ($score eq $ctr ? 'checked':'').' /> '.$ctr."</label></nobr></td>\n"; + $thisweight.')" value="'.$thisweight.'" '. + ($score eq $thisweight ? 'checked':'').' /> '.$thisweight."</label></nobr></td>\n"; $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : ''); + $thisweight += $increment; $ctr++; } $result.='</tr></table>'; @@ -1483,9 +1551,12 @@ sub handback_box { next if (!@$files); my $file_counter = 1; foreach my $file (@$files) { - my ($file_disp) = ($file =~ m|.+/(.+)$|); + 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.', - '<span class="filename">'.$file_disp.'</span>'); + '<span class="LC_filename">'.$file_disp.'</span>'); $result.='<input type="file" name="'.$prefix.'returndoc'.$file_counter.'" />'."\n"; $result.='<input type="hidden" name="'.$prefix.'origdoc'.$file_counter.'" value="'.$file.'" /><br />'; $file_counter++; @@ -1679,7 +1750,7 @@ KEYWORDS # my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb); my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/); - $apath=&Apache::lonnet::escape($apath); + $apath=&escape($apath); $apath=~s/\W/\_/gs; %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname); } @@ -1841,7 +1912,7 @@ KEYWORDS foreach my $file (@$files) { $file_counter ++; &Apache::lonnet::allowuploaded('/adm/grades',$file); - $lastsubonly.='<br /><a href="'.$file.'" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border="0"> '.$file.'</a>'; + $lastsubonly.='<br /><a href="'.$file.'?rawmode=1" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>'; } $lastsubonly.='<br />'; } @@ -1897,8 +1968,8 @@ KEYWORDS '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n"; $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter. ',\''.$msgfor.'\')"; TARGET=_self>'. - &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a> ('. - &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" />)'. + &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a><label> ('. + &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" /></label>)'. '<img src="'.$request->dir_config('lonIconsURL'). '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n". '<br /> ('. @@ -1958,6 +2029,8 @@ KEYWORDS '<input type="button" value="Next" '. 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> '; $endform.='(Next and Previous (student) do not save the scores.)'."\n" ; + $endform.="<input type='hidden' value='".&get_increment(). + "' name='increment' />"; $endform.='</td><tr></table></form>'; $endform.=&show_grading_menu_form($symb); $request->print($endform); @@ -2034,6 +2107,7 @@ sub processHandGrade { if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) { $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/); unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); } + $subject.=' ['.&Apache::lonnet::declutter($url).']'; my (@msgnum) = split(/,/,$includemsg); foreach (@msgnum) { $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne ''); @@ -2046,8 +2120,8 @@ sub processHandGrade { "?symb=$symb\">$env{'form.probTitle'}</a>"; } $msgstatus = &Apache::lonmsg::user_normal_msg($uname,$udom, - $subject.' ['. - &Apache::lonnet::declutter($url).']',$message); + $subject, + $message); $request->print('<br />'.&mt('Sending message to [_1]@[_2]',$uname,$udom).': '. $msgstatus); } @@ -2060,11 +2134,11 @@ sub processHandGrade { &saveHandGrade($request,$symb,$collaborator,$udom,$ctr, $env{'form.unamedom'.$ctr},$part); if ($errorflag eq 'not_allowed') { - $request->print("<font color=\"red\">Not allowed to modify grades for $collaborator:$udom</font>"); + $request->print("<span class=\"LC_error\">".&mt('Not allowed to modify grades for [_1]',"$collaborator:$udom")."</span>"); next; } else { if ($message ne '') { - $msgstatus = &Apache::lonmsg::user_normal_msg($collaborator,$udom,$env{'form.msgsub'},$message); + $msgstatus = &Apache::lonmsg::user_normal_msg($collaborator,$udom,$subject,$message); } } } @@ -2235,20 +2309,19 @@ sub processHandGrade { #---- Save the score and award for each student, if changed sub saveHandGrade { my ($request,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_; - my @v_flag; + 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 %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 may vary for different 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') { @@ -2257,7 +2330,7 @@ sub saveHandGrade { if (exists($record{'resource.'.$new_part.'.awarded'})) { $newrecord{'resource.'.$new_part.'.awarded'} = ''; } - $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}"; + $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 @@ -2293,6 +2366,7 @@ sub saveHandGrade { 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; @@ -2316,50 +2390,27 @@ sub saveHandGrade { } $newrecord{'resource.'.$new_part.'.regrader'}= "$env{'user.name'}:$env{'user.domain'}"; + &handback_files($request,$symb,$stuname,$domain,$newflg,$new_part,\%newrecord); } - my ($partlist,$handgrade,$responseType) = &response_type($symb); - foreach my $part_resp (sort(keys(%$handgrade))) { - my ($part_id, $resp_id) = split(/_/,$part_resp); - 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; - while ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter}) { - my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'.filename'}; - $newrecord{"resource.$new_part.$resp_id.handback"} = $env{'form.returndocorig'.$file_counter}; - # set the filename to match the submitted file name - $env{'form.'.$newflg.'_'.$part_resp.'_returndoc1.filename'} = $env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter}; - my $result=&Apache::lonnet::userfileupload($newflg.'_'.$part_resp.'_returndoc'.$file_counter,'', - 'portfolio',undef,undef,undef,$stuname,$domain); - if ($result !~ m|^/uploaded/|) { - $request->print('<font color="red"> An errror occured ('.$result. - ') while trying to upload '.&display_file().'</font><br />'); - # $request->print(&done('Back')); - } - $request->print("<br />".$fname." will be the uploaded file name"); - $request->print("<font color=\"red\">Will upload document</font>".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter}); - $file_counter++; - } - } - } - # 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 (@v_flag,$new_part); + push (@version_parts,$new_part); } } my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - if (scalar(keys(%newrecord)) > 0) { - if (scalar(@v_flag)) { - &version_portfiles(\%record, \@parts_graded, $env{'request.course.id'}, $symb, $domain, $stuname, \@v_flag); + 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}; } &Apache::lonnet::cstore(\%newrecord,$symb, $env{'request.course.id'},$domain,$stuname); - my @ungraded_parts; foreach my $part (@parts) { if ( !defined($record{'resource.'.$part.'.awarded'}) @@ -2379,6 +2430,57 @@ sub saveHandGrade { return ('',$pts,$wgt); } +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); + foreach my $part_resp (sort(keys(%$handgrade))) { + my ($part_id, $resp_id) = split(/_/,$part_resp); + 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; + 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('<font color="red"> An errror occured ('.$result. + ') while trying to upload '.$newflg.'_'.$part_resp.'_returndoc'.$file_counter.'</font><br />'); + } else { + # mark the file as read only + my @files = ($save_file_name); + my @what = ($symb,'handback'); + &Apache::lonnet::mark_as_readonly($domain,$stuname,\@files,\@what); + $$newrecord{"resource.$new_part.$resp_id.handback"} = $save_file_name; + my $subject = "File Handed Back by Instructor "; + my $message = "A file has been returned that was originally submitted in reponse to: <br />"; + $message .= "<strong>".&Apache::lonnet::gettitle($symb)."</strong><br />"; + $message .= ' The returned file is named: <br /><strong><a href="/uploaded/'."$domain/$stuname/".$save_file_name.'">'.$save_file_name."</a></strong><br />"; + $message .= " and can be found in your portfolio space."; + my $url = (&Apache::lonnet::decode_symb($symb))[2]; + $url = &Apache::lonnet::declutter($url); + my $msgstatus = &Apache::lonmsg::user_normal_msg($stuname,$domain, + $subject.' (File Returned) ['.$url.']',$message); + } + $request->print("<br />".$fname." will be the uploaded file name"); + $request->print(" ".$env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$file_counter}); + $file_counter++; + } + } + } + return; +} + sub get_submitted_files { my ($udom,$uname,$partid,$respid,$record) = @_; my @files; @@ -2457,40 +2559,39 @@ sub get_last_resets { 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 = &Apache::loncommon::propath($domain, - $stu_name). - '/userfiles/portfolio'; + 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 @v_portfiles; + my @versioned_portfiles; my @portfiles = split(/,/,$$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 $version = 0; 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); - $version = &get_next_version($answer_name, $answer_ext, \@dir_list); + 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(@v_portfiles, $directory.$new_answer); + push(@versioned_portfiles, $directory.$new_answer); &Apache::lonnet::mark_as_readonly($domain,$stu_name, ['/portfolio'.$directory.$new_answer], [$symb,$env{'request.course.id'},'graded']); } - } - $$record{$key} = join(',',@v_portfiles); + $$record{$key} = join(',',@versioned_portfiles); + push(@returned_keys,$key); } } - return 'ok'; + return (@returned_keys); } sub get_next_version { - my ($answer_name, $answer_ext, $dir_list); + my ($answer_name, $answer_ext, $dir_list) = @_; my $version; foreach my $row (@$dir_list) { my ($file) = split(/\&/,$row,2); @@ -3460,6 +3561,7 @@ 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); } @@ -3512,12 +3614,20 @@ sub csvuploadassign { my $part=$1; my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight', $symb,$domain,$username); - $entries{$fields{$dest}}=~s/\s//g; - my $pcr=$entries{$fields{$dest}} / $wgt; - my $award='correct_by_override'; - $grades{"resource.$part.awarded"}=$pcr; - $grades{"resource.$part.solved"}=$award; - $points{$part}=1; + if ($wgt) { + $entries{$fields{$dest}}=~s/\s//g; + my $pcr=$entries{$fields{$dest}} / $wgt; + my $award='correct_by_override'; + $grades{"resource.$part.awarded"}=$pcr; + $grades{"resource.$part.solved"}=$award; + $points{$part}=1; + } else { + $error_msg = "<br />" . + &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;} } @@ -3557,7 +3667,7 @@ sub csvuploadassign { } $request->print("<br />\n"); $request->print(&show_grading_menu_form($symb)); - return ''; + return $error_msg; } #------------- end of section for handling csv file upload --------- # @@ -3842,6 +3952,7 @@ sub displayPage { sub displaySubByDates { my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_; my $isCODE=0; + my $isTask = ($symb =~/\.task$/); if (exists($record->{'resource.CODE'})) { $isCODE=1; } my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'. '<table border="0" width="100%"><tr bgcolor="#e6ffff">'. @@ -3856,8 +3967,17 @@ sub displaySubByDates { if (!exists($$record{'1:timestamp'})) { return '<br /> <font color="red">Nothing submitted - no attempts</font><br />'; } + + my $interaction; for ($version=1;$version<=$$record{'version'};$version++) { my $timestamp = scalar(localtime($$record{$version.':timestamp'})); + if (exists($$record{$version.':resource.0.version'})) { + $interaction = $$record{$version.':resource.0.version'}; + } + + my $where = ($isTask ? "$version:resource.$interaction" + : "$version:resource"); + #&Apache::lonnet::logthis(" got $where"); $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>'; if ($isCODE) { $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>'; @@ -3865,40 +3985,57 @@ sub displaySubByDates { my @versionKeys = split(/\:/,$$record{$version.':keys'}); my @displaySub = (); foreach my $partid (@{$parts}) { - my @matchKey = sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys); + my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys) + : sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys)); + + # next if ($$record{"$version:resource.$partid.solved"} eq ''); my $display_part=&get_display_part($partid,$symb); foreach my $matchKey (@matchKey) { if (exists($$record{$version.':'.$matchKey}) && $$record{$version.':'.$matchKey} ne '') { - my ($responseId)=($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/); + + my ($responseId)= ($isTask ? ($matchKey=~ /^resource\.(.*?)\.\Q$partid\E\.award$/) + : ($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/)); + #&Apache::lonnet::logthis("match $matchKey $responseId (".$$record{$version.':'.$matchKey}); $displaySub[0].='<b>Part:</b> '.$display_part.' '; $displaySub[0].='<font color="#999999">(ID '. $responseId.')</font> <b>'; - if ($$record{"$version:resource.$partid.tries"} eq '') { + if ($$record{"$where.$partid.tries"} eq '') { $displaySub[0].='Trial not counted'; } else { $displaySub[0].='Trial '. - $$record{"$version:resource.$partid.tries"}; + $$record{"$where.$partid.tries"}; } - my $responseType=$responseType->{$partid}->{$responseId}; + my $responseType=($isTask ? 'Task' + : $responseType->{$partid}->{$responseId}); if (!exists($orders{$partid})) { $orders{$partid}={}; } if (!exists($orders{$partid}->{$responseId})) { $orders{$partid}->{$responseId}= &get_order($partid,$responseId,$symb,$uname,$udom); } $displaySub[0].='</b> '. - &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:").'<br />'; + &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />'; } } - if (exists $$record{"$version:resource.$partid.award"}) { + if (exists($$record{"$where.$partid.checkedin"})) { + $displaySub[1].='Checked in by '. + $$record{"$where.$partid.checkedin"}.' into slot '. + $$record{"$where.$partid.checkedin.slot"}. + '<br />'; + } + if (exists $$record{"$where.$partid.award"}) { $displaySub[1].='<b>Part:</b> '.$display_part.' '. - lc($$record{"$version:resource.$partid.award"}).' '. - $mark{$$record{"$version:resource.$partid.solved"}}. + lc($$record{"$where.$partid.award"}).' '. + $mark{$$record{"$where.$partid.solved"}}. '<br />'; } - if (exists $$record{"$version:resource.$partid.regrader"}) { - $displaySub[2].=$$record{"$version:resource.$partid.regrader"}. + if (exists $$record{"$where.$partid.regrader"}) { + $displaySub[2].=$$record{"$where.$partid.regrader"}. + ' (<b>'.&mt('Part').':</b> '.$display_part.')'; + } elsif ($$record{"$version:resource.$partid.regrader"} =~ /\S/) { + $displaySub[2].= + $$record{"$version:resource.$partid.regrader"}. ' (<b>'.&mt('Part').':</b> '.$display_part.')'; } } @@ -4096,7 +4233,7 @@ sub scantron_filenames { my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'}; my $cname=$env{'course.'.$env{'request.course.id'}.'.num'}; my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname, - &Apache::loncommon::propath($cdom,$cname)); + &propath($cdom,$cname)); my @possiblenames; foreach my $filename (sort(@files)) { ($filename)=split(/&/,$filename); @@ -4637,7 +4774,6 @@ sub remember_current_skipped { $to_remember{$i}=1; } } - &Apache::lonnet::logthis('remembering '.join(':',%to_remember)); &scan_data($scan_data,'remember_skipping',join(':',%to_remember)); &scantron_putfile(undef,$scan_data); } @@ -4709,7 +4845,7 @@ $warning <input type="hidden" name="command" value="scantron_validate" /> STUFF } - $r->print("</form><br />".&show_grading_menu_form($symb)."</body></html>"); + $r->print("</form><br />".&show_grading_menu_form($symb)); return ''; } @@ -4810,8 +4946,7 @@ STUFF $r->print(" this scanline saving it for later."); } } - $r->print(" </form><br />".&show_grading_menu_form($symb). - "</body></html>"); + $r->print(" </form><br />".&show_grading_menu_form($symb)); return ''; } @@ -4972,7 +5107,7 @@ sub scantron_validate_sequence { my @resources= $navmap->retrieveResources($map,\&scantron_filter_not_exam,1,0); if (@resources) { - $r->print("<p>".&mt('Some resource in the sequece currently are not set to exam mode. Grading these resources currently may not work correctly.')."</p>"); + $r->print("<p>".&mt('Some resources in the sequence currently are not set to exam mode. Grading these resources currently may not work correctly.')."</p>"); return (1,$currentphase); } } @@ -5126,11 +5261,11 @@ function change_radio(field) { </script> ENDSCRIPT my $href="/adm/pickcode?". - "form=".&Apache::lonnet::escape("scantronupload"). - "&scantron_format=".&Apache::lonnet::escape($env{'form.scantron_format'}). - "&scantron_CODElist=".&Apache::lonnet::escape($env{'form.scantron_CODElist'}). - "&curCODE=".&Apache::lonnet::escape($$scan_record{'scantron.CODE'}). - "&scantron_selectfile=".&Apache::lonnet::escape($env{'form.scantron_selectfile'}); + "form=".&escape("scantronupload"). + "&scantron_format=".&escape($env{'form.scantron_format'}). + "&scantron_CODElist=".&escape($env{'form.scantron_CODElist'}). + "&curCODE=".&escape($$scan_record{'scantron.CODE'}). + "&scantron_selectfile=".&escape($env{'form.scantron_selectfile'}); if ($env{'form.scantron_CODElist'} =~ /\S/) { $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_found' /> <a target='_blank' href='$href'>Select</a> a CODE from the list of all CODEs and use it.</label> Selected CODE is <input readonly='true' type='text' size='8' name='scantron_CODE_selectedvalue' onfocus=\"javascript:change_radio('use_found')\" onchange=\"javascript:change_radio('use_found')\" />"); $r->print("\n<br />"); @@ -5559,7 +5694,6 @@ sub scantron_upload_scantron_data_save { sub valid_file { my ($requested_file)=@_; foreach my $filename (sort(&scantron_filenames())) { - &Apache::lonnet::logthis("$requested_file $filename"); if ($requested_file eq $filename) { return 1; } } return 0; @@ -5815,7 +5949,7 @@ sub handler { if ($#commands > 0) { &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands)); } - &send_header($request); + $request->print(&Apache::loncommon::start_page('Grading')); if ($symb eq '' && $command eq '') { if ($env{'user.adv'}) { if (($env{'form.codeone'}) && ($env{'form.codetwo'}) && @@ -5906,27 +6040,10 @@ sub handler { $request->print("Access Denied ($command)"); } } - &send_footer($request); + $request->print(&Apache::loncommon::end_page()); return ''; } -sub send_header { - my ($request)= @_; - $request->print(&Apache::lontexconvert::header()); -# $request->print(" -#<script> -#remotewindow=open('','homeworkremote'); -#remotewindow.close(); -#</script>"); - $request->print(&Apache::loncommon::bodytag('Grading')); - $request->rflush(); -} - -sub send_footer { - my ($request)= @_; - $request->print('</body></html>'); -} - 1; __END__;