Annotation of loncom/homework/grades.pm, revision 1.313
1.17 albertel 1: # The LearningOnline Network with CAPA
1.13 albertel 2: # The LON-CAPA Grading handler
1.17 albertel 3: #
1.313 ! banghart 4: # $Id: grades.pm,v 1.312 2006/02/13 22:11:51 banghart Exp $
1.17 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: package Apache::grades;
30: use strict;
31: use Apache::style;
32: use Apache::lonxml;
33: use Apache::lonnet;
1.3 albertel 34: use Apache::loncommon;
1.112 ng 35: use Apache::lonhtmlcommon;
1.68 ng 36: use Apache::lonnavmaps;
1.1 albertel 37: use Apache::lonhomework;
1.55 matthew 38: use Apache::loncoursedata;
1.38 ng 39: use Apache::lonmsg qw(:user_normal_msg);
1.1 albertel 40: use Apache::Constants qw(:common);
1.167 sakharuk 41: use Apache::lonlocal;
1.170 albertel 42: use String::Similarity;
1.87 www 43:
44: my %oldessays=();
1.103 albertel 45: my %perm=();
1.1 albertel 46:
1.68 ng 47: # ----- These first few routines are general use routines.----
1.44 ng 48: #
1.146 albertel 49: # --- Retrieve the parts from the metadata file.---
1.44 ng 50: sub getpartlist {
1.146 albertel 51: my ($url,$symb) = @_;
52: my $partorder = &Apache::lonnet::metadata($url, 'partorder');
53: my @parts;
54: if ($partorder) {
55: for my $part (split (/,/,$partorder)) {
56: if (!&Apache::loncommon::check_if_partid_hidden($part,$symb)) {
57: push(@parts, $part);
58: }
59: }
60: } else {
61: my $metadata = &Apache::lonnet::metadata($url, 'packages');
62: foreach (split(/\,/,$metadata)) {
63: if ($_ =~ /^part_(.*)$/) {
64: if (!&Apache::loncommon::check_if_partid_hidden($1,$symb)) {
65: push(@parts, $1);
66: }
67: }
1.41 ng 68: }
1.16 albertel 69: }
1.146 albertel 70: my @stores;
71: foreach my $part (@parts) {
72: my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
73: foreach my $key (@metakeys) {
74: if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); }
75: }
76: }
77: return @stores;
1.2 albertel 78: }
79:
1.44 ng 80: # --- Get the symbolic name of a problem and the url
81: sub get_symb_and_url {
1.173 albertel 82: my ($request,$silent) = @_;
1.257 albertel 83: (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
84: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.173 albertel 85: if ($symb eq '') {
86: if (!$silent) {
87: $request->print("Unable to handle ambiguous references:$url:.");
88: return ();
89: }
90: }
1.44 ng 91: return ($symb,$url);
1.32 ng 92: }
93:
1.129 ng 94: #--- Format fullname, username:domain if different for display
95: #--- Use anywhere where the student names are listed
96: sub nameUserString {
97: my ($type,$fullname,$uname,$udom) = @_;
98: if ($type eq 'header') {
1.250 albertel 99: return '<b> Fullname </b><font color="#999999">(Username)</font>';
1.129 ng 100: } else {
101: return ' '.$fullname.'<font color="#999999"> ('.$uname.
1.257 albertel 102: ($env{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')</font>';
1.129 ng 103: }
104: }
105:
1.44 ng 106: #--- Get the partlist and the response type for a given problem. ---
107: #--- Indicate if a response type is coded handgraded or not. ---
1.39 ng 108: sub response_type {
1.125 ng 109: my ($url,$symb) = shift;
1.257 albertel 110: $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url))) if ($symb eq '');
1.41 ng 111: my $allkeys = &Apache::lonnet::metadata($url,'keys');
1.154 albertel 112: my %vPart;
113: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
114: $vPart{$partid}=1;
115: }
1.41 ng 116: my %seen = ();
1.147 albertel 117: my (@partlist,%handgrade,%responseType);
1.41 ng 118: foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
1.147 albertel 119: if (/^\w+response_.*/) {
1.41 ng 120: my ($responsetype,$part) = split(/_/,$_,2);
121: my ($partid,$respid) = split(/_/,$part);
1.146 albertel 122: if (&Apache::loncommon::check_if_partid_hidden($partid,$symb)) {
123: next;
124: }
1.154 albertel 125: if (%vPart && !exists($vPart{$partid})) {
126: next;
127: }
1.118 ng 128: $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!!
1.127 ng 129: my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb);
1.147 albertel 130: $handgrade{$part} = ($value eq 'yes' ? 'yes' : 'no');
131: if (!exists($responseType{$partid})) { $responseType{$partid}={}; }
132: $responseType{$partid}->{$respid}=$responsetype;
1.41 ng 133: next if ($seen{$partid} > 0);
134: $seen{$partid}++;
135: push @partlist,$partid;
136: }
137: }
1.147 albertel 138: return \@partlist,\%handgrade,\%responseType;
1.39 ng 139: }
140:
1.207 albertel 141: sub get_display_part {
142: my ($partID,$url,$symb)=@_;
143: if (!defined($symb) || $symb eq '') {
1.257 albertel 144: $symb=$env{'form.symb'};
1.207 albertel 145: if ($symb eq '') { $symb=&Apache::lonnet::symbread($url) }
146: }
147: my $display=&Apache::lonnet::EXT('resource.'.$partID.'.display',$symb);
148: if (defined($display) and $display ne '') {
149: $display.= " (<font color=\"#999900\">id $partID</font>)";
150: } else {
151: $display=$partID;
152: }
153: return $display;
154: }
1.269 raeburn 155:
1.118 ng 156: #--- Show resource title
157: #--- and parts and response type
158: sub showResourceInfo {
1.154 albertel 159: my ($url,$probTitle,$checkboxes) = @_;
160: my $col=3;
161: if ($checkboxes) { $col=4; }
1.118 ng 162: my $result ='<table border="0">'.
1.167 sakharuk 163: '<tr><td colspan="'.$col.'"><font size="+1"><b>'.&mt('Current Resource').': </b>'.
1.154 albertel 164: $probTitle.'</font></td></tr>'."\n";
1.147 albertel 165: my ($partlist,$handgrade,$responseType) = &response_type($url);
1.126 ng 166: my %resptype = ();
1.122 ng 167: my $hdgrade='no';
1.154 albertel 168: my %partsseen;
1.147 albertel 169: for my $part_resID (sort keys(%$handgrade)) {
170: my $handgrade=$$handgrade{$part_resID};
171: my ($partID,$resID) = split(/_/,$part_resID);
172: my $responsetype = $responseType->{$partID}->{$resID};
1.118 ng 173: $hdgrade = $handgrade if ($handgrade eq 'yes');
1.154 albertel 174: $result.='<tr>';
175: if ($checkboxes) {
176: if (exists($partsseen{$partID})) {
177: $result.="<td> </td>";
178: } else {
179: $result.="<td><input type='checkbox' name='vPart' value='$partID' checked='on' /></td>";
180: }
181: $partsseen{$partID}=1;
182: }
1.207 albertel 183: my $display_part=&get_display_part($partID,$url);
184: $result.='<td><b>Part: </b>'.$display_part.' <font color="#999999">'.
1.147 albertel 185: $resID.'</font></td>'.
1.118 ng 186: '<td><b>Type: </b>'.$responsetype.'</td></tr>';
187: # '<td><b>Handgrade: </b>'.$handgrade.'</td></tr>';
188: }
189: $result.='</table>'."\n";
1.147 albertel 190: return $result,$responseType,$hdgrade,$partlist,$handgrade;
1.118 ng 191: }
192:
1.148 albertel 193:
194: sub get_order {
195: my ($partid,$respid,$symb,$uname,$udom)=@_;
196: my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
197: $url=&Apache::lonnet::clutter($url);
198: my $subresult=&Apache::lonnet::ssi($url,
199: ('grade_target' => 'analyze'),
200: ('grade_domain' => $udom),
201: ('grade_symb' => $symb),
202: ('grade_courseid' =>
1.257 albertel 203: $env{'request.course.id'}),
1.148 albertel 204: ('grade_username' => $uname));
1.149 albertel 205: (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
1.148 albertel 206: my %analyze=&Apache::lonnet::str2hash($subresult);
207: return ($analyze{"$partid.$respid.shown"});
208: }
1.118 ng 209: #--- Clean response type for display
1.148 albertel 210: #--- Currently filters option/rank/radiobutton/match/essay response types only.
1.118 ng 211: sub cleanRecord {
1.148 albertel 212: my ($answer,$response,$symb,$partid,$respid,$record,$order,$version) = @_;
213: my $grayFont = '<font color="#999999">';
214: if ($response =~ /^(option|rank)$/) {
215: my %answer=&Apache::lonnet::str2hash($answer);
216: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
217: my ($toprow,$bottomrow);
218: foreach my $foil (@$order) {
219: if ($grading{$foil} == 1) {
220: $toprow.='<td><b>'.$answer{$foil}.' </b></td>';
221: } else {
222: $toprow.='<td><i>'.$answer{$foil}.' </i></td>';
223: }
224: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
225: }
226: return '<blockquote><table border="1">'.
227: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
228: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
229: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
230: } elsif ($response eq 'match') {
231: my %answer=&Apache::lonnet::str2hash($answer);
232: my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"});
233: my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"});
234: my ($toprow,$middlerow,$bottomrow);
235: foreach my $foil (@$order) {
236: my $item=shift(@items);
237: if ($grading{$foil} == 1) {
238: $toprow.='<td><b>'.$item.' </b></td>';
239: $middlerow.='<td><b>'.$grayFont.$answer{$foil}.' </font></b></td>';
240: } else {
241: $toprow.='<td><i>'.$item.' </i></td>';
242: $middlerow.='<td><i>'.$grayFont.$answer{$foil}.' </font></i></td>';
243: }
244: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
1.118 ng 245: }
1.126 ng 246: return '<blockquote><table border="1">'.
1.148 albertel 247: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
248: '<tr valign="top"><td>'.$grayFont.'Item ID</font></td>'.
249: $middlerow.'</tr>'.
250: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
251: $bottomrow.'</tr>'.'</table></blockquote>';
252: } elsif ($response eq 'radiobutton') {
253: my %answer=&Apache::lonnet::str2hash($answer);
254: my ($toprow,$bottomrow);
255: my $correct=($order->[0])+1;
256: for (my $i=1;$i<=$#$order;$i++) {
257: my $foil=$order->[$i];
258: if (exists($answer{$foil})) {
259: if ($i == $correct) {
260: $toprow.='<td><b>true</b></td>';
261: } else {
262: $toprow.='<td><i>true</i></td>';
263: }
264: } else {
265: $toprow.='<td>false</td>';
266: }
267: $bottomrow.='<td>'.$grayFont.$foil.'</font> </td>';
268: }
269: return '<blockquote><table border="1">'.
270: '<tr valign="top"><td>Answer</td>'.$toprow.'</tr>'.
271: '<tr valign="top"><td>'.$grayFont.'Option ID</font></td>'.
272: $grayFont.$bottomrow.'</tr>'.'</table></blockquote>';
273: } elsif ($response eq 'essay') {
1.257 albertel 274: if (! exists ($env{'form.'.$symb})) {
1.122 ng 275: my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 276: $env{'course.'.$env{'request.course.id'}.'.domain'},
277: $env{'course.'.$env{'request.course.id'}.'.num'});
1.122 ng 278:
1.257 albertel 279: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
280: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
281: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
282: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
283: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
284: $env{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob.
1.122 ng 285: }
1.166 albertel 286: $answer =~ s-\n-<br />-g;
287: return '<br /><br /><blockquote><tt>'.&keywords_highlight($answer).'</tt></blockquote>';
1.268 albertel 288: } elsif ( $response eq 'organic') {
289: my $result='Smile representation: "<tt>'.$answer.'</tt>"';
290: my $jme=$record->{$version."resource.$partid.$respid.molecule"};
291: $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
292: return $result;
1.122 ng 293: }
1.118 ng 294: return $answer;
295: }
296:
297: #-- A couple of common js functions
298: sub commonJSfunctions {
299: my $request = shift;
300: $request->print(<<COMMONJSFUNCTIONS);
301: <script type="text/javascript" language="javascript">
302: function radioSelection(radioButton) {
303: var selection=null;
304: if (radioButton.length > 1) {
305: for (var i=0; i<radioButton.length; i++) {
306: if (radioButton[i].checked) {
307: return radioButton[i].value;
308: }
309: }
310: } else {
311: if (radioButton.checked) return radioButton.value;
312: }
313: return selection;
314: }
315:
316: function pullDownSelection(selectOne) {
317: var selection="";
318: if (selectOne.length > 1) {
319: for (var i=0; i<selectOne.length; i++) {
320: if (selectOne[i].selected) {
321: return selectOne[i].value;
322: }
323: }
324: } else {
1.138 albertel 325: // only one value it must be the selected one
326: return selectOne.value;
1.118 ng 327: }
328: }
329: </script>
330: COMMONJSFUNCTIONS
331: }
332:
1.44 ng 333: #--- Dumps the class list with usernames,list of sections,
334: #--- section, ids and fullnames for each user.
335: sub getclasslist {
1.76 ng 336: my ($getsec,$filterlist) = @_;
1.291 albertel 337: my @getsec;
338: if (!ref($getsec)) {
339: if ($getsec ne '' && $getsec ne 'all') {
340: @getsec=($getsec);
341: }
342: } else {
343: @getsec=@{$getsec};
344: }
345: if (grep(/^all$/,@getsec)) { undef(@getsec); }
346:
1.56 matthew 347: my $classlist=&Apache::loncoursedata::get_classlist();
1.49 albertel 348: # Bail out if we were unable to get the classlist
1.56 matthew 349: return if (! defined($classlist));
350: #
351: my %sections;
352: my %fullnames;
1.205 matthew 353: foreach my $student (keys(%$classlist)) {
354: my $end =
355: $classlist->{$student}->[&Apache::loncoursedata::CL_END()];
356: my $start =
357: $classlist->{$student}->[&Apache::loncoursedata::CL_START()];
358: my $id =
359: $classlist->{$student}->[&Apache::loncoursedata::CL_ID()];
360: my $section =
361: $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
362: my $fullname =
363: $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()];
364: my $status =
365: $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()];
1.76 ng 366: # filter students according to status selected
1.257 albertel 367: if ($filterlist && $env{'form.Status'} ne 'Any') {
368: if ($env{'form.Status'} ne $status) {
1.205 matthew 369: delete ($classlist->{$student});
1.76 ng 370: next;
371: }
372: }
1.205 matthew 373: $section = ($section ne '' ? $section : 'none');
1.106 albertel 374: if (&canview($section)) {
1.291 albertel 375: if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
1.103 albertel 376: $sections{$section}++;
1.205 matthew 377: $fullnames{$student}=$fullname;
1.103 albertel 378: } else {
1.205 matthew 379: delete($classlist->{$student});
1.103 albertel 380: }
381: } else {
1.205 matthew 382: delete($classlist->{$student});
1.103 albertel 383: }
1.44 ng 384: }
385: my %seen = ();
1.56 matthew 386: my @sections = sort(keys(%sections));
387: return ($classlist,\@sections,\%fullnames);
1.44 ng 388: }
389:
1.103 albertel 390: sub canmodify {
391: my ($sec)=@_;
392: if ($perm{'mgr'}) {
393: if (!defined($perm{'mgr_section'})) {
394: # can modify whole class
395: return 1;
396: } else {
397: if ($sec eq $perm{'mgr_section'}) {
398: #can modify the requested section
399: return 1;
400: } else {
401: # can't modify the request section
402: return 0;
403: }
404: }
405: }
406: #can't modify
407: return 0;
408: }
409:
410: sub canview {
411: my ($sec)=@_;
412: if ($perm{'vgr'}) {
413: if (!defined($perm{'vgr_section'})) {
414: # can modify whole class
415: return 1;
416: } else {
417: if ($sec eq $perm{'vgr_section'}) {
418: #can modify the requested section
419: return 1;
420: } else {
421: # can't modify the request section
422: return 0;
423: }
424: }
425: }
426: #can't modify
427: return 0;
428: }
429:
1.44 ng 430: #--- Retrieve the grade status of a student for all the parts
431: sub student_gradeStatus {
432: my ($url,$symb,$udom,$uname,$partlist) = @_;
1.257 albertel 433: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.44 ng 434: my %partstatus = ();
435: foreach (@$partlist) {
1.128 ng 436: my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2);
1.44 ng 437: $status = 'nothing' if ($status eq '');
438: $partstatus{$_} = $status;
439: my $subkey = "resource.$_.submitted_by";
440: $partstatus{$subkey} = $record{$subkey} if ($record{$subkey} ne '');
441: }
442: return %partstatus;
443: }
444:
1.45 ng 445: # hidden form and javascript that calls the form
446: # Use by verifyscript and viewgrades
447: # Shows a student's view of problem and submission
448: sub jscriptNform {
449: my ($url,$symb) = @_;
450: my $jscript='<script type="text/javascript" language="javascript">'."\n".
451: ' function viewOneStudent(user,domain) {'."\n".
452: ' document.onestudent.student.value = user;'."\n".
453: ' document.onestudent.userdom.value = domain;'."\n".
454: ' document.onestudent.submit();'."\n".
455: ' }'."\n".
456: '</script>'."\n";
457: $jscript.= '<form action="/adm/grades" method="post" name="onestudent">'."\n".
458: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
459: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.257 albertel 460: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
461: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
462: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.45 ng 463: '<input type="hidden" name="command" value="submission" />'."\n".
464: '<input type="hidden" name="student" value="" />'."\n".
465: '<input type="hidden" name="userdom" value="" />'."\n".
466: '</form>'."\n";
467: return $jscript;
468: }
1.39 ng 469:
1.44 ng 470: #------------------ End of general use routines --------------------
1.87 www 471:
472: #
473: # Find most similar essay
474: #
475:
476: sub most_similar {
477: my ($uname,$udom,$uessay)=@_;
478:
479: # ignore spaces and punctuation
480:
481: $uessay=~s/\W+/ /gs;
482:
1.282 www 483: # ignore empty submissions (occuring when only files are sent)
484:
485: unless ($uessay=~/\w+/) { return ''; }
486:
1.87 www 487: # these will be returned. Do not care if not at least 50 percent similar
1.88 www 488: my $limit=0.6;
1.87 www 489: my $sname='';
490: my $sdom='';
491: my $scrsid='';
492: my $sessay='';
493: # go through all essays ...
494: foreach my $tkey (keys %oldessays) {
495: my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
496: # ... except the same student
1.88 www 497: if (($tname ne $uname) || ($tdom ne $udom)) {
1.87 www 498: my $tessay=$oldessays{$tkey};
499: $tessay=~s/\W+/ /gs;
500: # String similarity gives up if not even limit
1.88 www 501: my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
1.87 www 502: # Found one
503: if ($tsimilar>$limit) {
504: $limit=$tsimilar;
505: $sname=$tname;
1.88 www 506: $sdom=$tdom;
1.87 www 507: $scrsid=$tcrsid;
508: $sessay=$oldessays{$tkey};
509: }
510: }
511: }
1.88 www 512: if ($limit>0.6) {
1.87 www 513: return ($sname,$sdom,$scrsid,$sessay,$limit);
514: } else {
515: return ('','','','',0);
516: }
517: }
518:
1.44 ng 519: #-------------------------------------------------------------------
520:
521: #------------------------------------ Receipt Verification Routines
1.45 ng 522: #
1.44 ng 523: #--- Check whether a receipt number is valid.---
524: sub verifyreceipt {
525: my $request = shift;
526:
1.257 albertel 527: my $courseid = $env{'request.course.id'};
1.184 www 528: my $receipt = &Apache::lonnet::recprefix($courseid).'-'.
1.257 albertel 529: $env{'form.receipt'};
1.44 ng 530: $receipt =~ s/[^\-\d]//g;
1.257 albertel 531: my $url = $env{'form.url'};
532: my $symb = $env{'form.symb'};
1.44 ng 533: unless ($symb) {
534: $symb = &Apache::lonnet::symbread($url);
535: }
536:
1.45 ng 537: my $title.='<h3><font color="#339933">Verifying Submission Receipt '.
538: $receipt.'</h3></font>'."\n".
1.257 albertel 539: '<font size=+1><b>Resource: </b>'.$env{'form.probTitle'}.'</font><br><br>'."\n";
1.44 ng 540:
541: my ($string,$contents,$matches) = ('','',0);
1.56 matthew 542: my (undef,undef,$fullname) = &getclasslist('all','0');
1.177 albertel 543:
544: my $receiptparts=0;
1.257 albertel 545: if ($env{"course.$courseid.receiptalg"} eq 'receipt2') { $receiptparts=1; }
1.177 albertel 546: my $parts=['0'];
547: if ($receiptparts) { ($parts)=&response_type($url,$symb); }
1.294 albertel 548: foreach (sort
549: {
550: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
551: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
552: }
553: return $a cmp $b;
554: } (keys(%$fullname))) {
1.44 ng 555: my ($uname,$udom)=split(/\:/);
1.177 albertel 556: foreach my $part (@$parts) {
557: if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
558: $contents.='<tr bgcolor="#ffffe6"><td> '."\n".
559: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
560: '\')"; TARGET=_self>'.$$fullname{$_}.'</a> </td>'."\n".
561: '<td> '.$uname.' </td>'.
562: '<td> '.$udom.' </td>';
563: if ($receiptparts) {
564: $contents.='<td> '.$part.' </td>';
565: }
566: $contents.='</tr>'."\n";
567:
568: $matches++;
569: }
1.44 ng 570: }
571: }
572: if ($matches == 0) {
573: $string = $title.'No match found for the above receipt.';
574: } else {
1.45 ng 575: $string = &jscriptNform($url,$symb).$title.
1.44 ng 576: 'The above receipt matches the following student'.
577: ($matches <= 1 ? '.' : 's.')."\n".
578: '<table border="0"><tr><td bgcolor="#777777">'."\n".
579: '<table border="0"><tr bgcolor="#e6ffff">'."\n".
580: '<td><b> Fullname </b></td>'."\n".
581: '<td><b> Username </b></td>'."\n".
1.177 albertel 582: '<td><b> Domain </b></td>';
583: if ($receiptparts) {
584: $string.='<td> Problem Part </td>';
585: }
586: $string.='</tr>'."\n".$contents.
1.44 ng 587: '</table></td></tr></table>'."\n";
588: }
1.50 albertel 589: return $string.&show_grading_menu_form($symb,$url);
1.44 ng 590: }
591:
592: #--- This is called by a number of programs.
593: #--- Called from the Grading Menu - View/Grade an individual student
594: #--- Also called directly when one clicks on the subm button
595: # on the problem page.
1.30 ng 596: sub listStudents {
1.41 ng 597: my ($request) = shift;
1.49 albertel 598:
1.72 ng 599: my ($symb,$url) = &get_symb_and_url($request);
1.257 albertel 600: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
601: my $cnum = $env{"course.$env{'request.course.id'}.num"};
602: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
603: my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'};
604:
605: my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View';
606: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
607: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.49 albertel 608:
1.118 ng 609: my $result='<h3><font color="#339933"> '.$viewgrade.
610: ' Submissions for a Student or a Group of Students</font></h3>';
611:
1.257 albertel 612: my ($table,undef,$hdgrade,$partlist,$handgrade) = &showResourceInfo($url,$env{'form.probTitle'},($env{'form.showgrading'} eq 'yes'));
1.49 albertel 613:
1.45 ng 614: $request->print(<<LISTJAVASCRIPT);
615: <script type="text/javascript" language="javascript">
1.110 ng 616: function checkSelect(checkBox) {
617: var ctr=0;
618: var sense="";
619: if (checkBox.length > 1) {
620: for (var i=0; i<checkBox.length; i++) {
621: if (checkBox[i].checked) {
622: ctr++;
623: }
624: }
625: sense = "a student or group of students";
626: } else {
627: if (checkBox.checked) {
628: ctr = 1;
629: }
630: sense = "the student";
631: }
632: if (ctr == 0) {
1.126 ng 633: alert("Please select "+sense+" before clicking on the Next button.");
1.110 ng 634: return false;
635: }
636: document.gradesub.submit();
637: }
638:
639: function reLoadList(formname) {
1.112 ng 640: if (formname.saveStatusOld.value == pullDownSelection(formname.Status)) {return;}
1.110 ng 641: formname.command.value = 'submission';
642: formname.submit();
643: }
1.45 ng 644: </script>
645: LISTJAVASCRIPT
646:
1.118 ng 647: &commonJSfunctions($request);
1.41 ng 648: $request->print($result);
1.39 ng 649:
1.257 albertel 650: my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : '';
1.119 ng 651: my $checklastsub = $checkhdgrade eq '' ? 'checked' : '';
1.154 albertel 652: my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'.
653: "\n".$table.
1.267 albertel 654: ' <b>View Problem Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
655: '<label><input type="radio" name="vProb" value="yes" /> one student </label>'."\n".
656: '<label><input type="radio" name="vProb" value="all" /> all students </label><br />'."\n".
657: ' <b>View Answer: </b><label><input type="radio" name="vAns" value="no" /> no </label>'."\n".
658: '<label><input type="radio" name="vAns" value="yes" /> one student </label>'."\n".
659: '<label><input type="radio" name="vAns" value="all" checked="on" /> all students </label><br />'."\n".
1.49 albertel 660: ' <b>Submissions: </b>'."\n";
1.257 albertel 661: if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) {
1.267 albertel 662: $gradeTable.='<label><input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> essay part only </label>'."\n";
1.49 albertel 663: }
1.110 ng 664:
1.257 albertel 665: my $saveStatus = $env{'form.Status'} eq '' ? 'Active' : $env{'form.Status'};
666: $env{'form.Status'} = $saveStatus;
1.110 ng 667:
1.267 albertel 668: $gradeTable.='<label><input type="radio" name="lastSub" value="lastonly" '.$checklastsub.' /> last submission only </label>'."\n".
669: '<label><input type="radio" name="lastSub" value="last" /> last submission & parts info </label>'."\n".
670: '<label><input type="radio" name="lastSub" value="datesub" /> by dates and submissions </label>'."\n".
671: '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n".
1.45 ng 672: '<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
673: '<input type="hidden" name="submitonly" value="'.$submitonly.'" />'."\n".
1.257 albertel 674: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'" /><br />'."\n".
675: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" /><br />'."\n".
676: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
677: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.48 albertel 678: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
679: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.110 ng 680: '<input type="hidden" name="saveStatusOld" value="'.$saveStatus.'" />'."\n";
681:
1.257 albertel 682: if (exists($env{'form.gradingMenu'}) && exists($env{'form.Status'})) {
683: $gradeTable.='<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n";
1.124 ng 684: } else {
685: $gradeTable.='<b>Student Status:</b> '.
686: &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'<br />';
687: }
1.112 ng 688:
1.126 ng 689: $gradeTable.='To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '.
690: 'next to the student\'s name(s). Then click on the Next button.<br />'."\n".
1.110 ng 691: '<input type="hidden" name="command" value="processGroup" />'."\n";
1.249 albertel 692:
693: # checkall buttons
694: $gradeTable.=&check_script('gradesub', 'stuinfo');
1.110 ng 695: $gradeTable.='<input type="button" '."\n".
1.45 ng 696: 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n".
1.249 albertel 697: 'value="Next->" /> <br />'."\n";
698: $gradeTable.=&check_buttons();
1.267 albertel 699: $gradeTable.='<label><input type="checkbox" name="checkPlag" checked="on" />Check For Plagiarism</label>';
1.249 albertel 700: my ($classlist, undef, $fullname) = &getclasslist($getsec,'1');
1.45 ng 701: $gradeTable.='<table border="0"><tr><td bgcolor="#777777">'.
1.110 ng 702: '<table border="0"><tr bgcolor="#e6ffff">';
703: my $loop = 0;
704: while ($loop < 2) {
1.126 ng 705: $gradeTable.='<td><b> No.</b> </td><td><b> Select </b></td>'.
1.250 albertel 706: '<td>'.&nameUserString('header').' Section/Group</td>';
1.301 albertel 707: if ($env{'form.showgrading'} eq 'yes'
708: && $submitonly ne 'queued'
709: && $submitonly ne 'all') {
1.110 ng 710: foreach (sort(@$partlist)) {
1.207 albertel 711: my $display_part=&get_display_part((split(/_/))[0],$url,$symb);
712: $gradeTable.='<td><b> Part: '.$display_part.
713: ' Status </b></td>';
1.110 ng 714: }
1.301 albertel 715: } elsif ($submitonly eq 'queued') {
716: $gradeTable.='<td><b> '.&mt('Queue Status').' </b></td>';
1.110 ng 717: }
718: $loop++;
1.126 ng 719: # $gradeTable.='<td></td>' if ($loop%2 ==1);
1.41 ng 720: }
1.45 ng 721: $gradeTable.='</tr>'."\n";
1.41 ng 722:
1.45 ng 723: my $ctr = 0;
1.294 albertel 724: foreach my $student (sort
725: {
726: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
727: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
728: }
729: return $a cmp $b;
730: }
731: (keys(%$fullname))) {
1.41 ng 732: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 733:
1.110 ng 734: my %status = ();
1.301 albertel 735:
736: if ($submitonly eq 'queued') {
737: my %queue_status =
738: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
739: $udom,$uname);
740: next if (!defined($queue_status{'gradingqueue'}));
741: $status{'gradingqueue'} = $queue_status{'gradingqueue'};
742: }
743:
744: if ($env{'form.showgrading'} eq 'yes'
745: && $submitonly ne 'queued'
746: && $submitonly ne 'all') {
1.110 ng 747: (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
1.145 albertel 748: my $submitted = 0;
1.164 albertel 749: my $graded = 0;
1.248 albertel 750: my $incorrect = 0;
1.110 ng 751: foreach (keys(%status)) {
1.145 albertel 752: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 753: $graded = 1 if ($status{$_} =~ /^ungraded/);
754: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
755:
1.110 ng 756: my ($foo,$partid,$foo1) = split(/\./,$_);
757: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
1.145 albertel 758: $submitted = 0;
1.150 albertel 759: my ($part)=split(/\./,$partid);
1.110 ng 760: $gradeTable.='<input type="hidden" name="'.
1.150 albertel 761: $student.':'.$part.':submitted_by" value="'.
1.110 ng 762: $status{'resource.'.$partid.'.submitted_by'}.'" />';
763: }
1.41 ng 764: }
1.248 albertel 765:
1.156 albertel 766: next if (!$submitted && ($submitonly eq 'yes' ||
767: $submitonly eq 'incorrect' ||
768: $submitonly eq 'graded'));
1.248 albertel 769: next if (!$graded && ($submitonly eq 'graded'));
770: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 771: }
1.34 ng 772:
1.45 ng 773: $ctr++;
1.249 albertel 774: my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()];
775:
1.104 albertel 776: if ( $perm{'vgr'} eq 'F' ) {
1.110 ng 777: $gradeTable.='<tr bgcolor="#ffffe6">' if ($ctr%2 ==1);
1.126 ng 778: $gradeTable.='<td align="right">'.$ctr.' </td>'.
1.249 albertel 779: '<td align="center"><label><input type=checkbox name="stuinfo" value="'.
780: $student.':'.$$fullname{$student}.':::SECTION'.$section.
781: ') " /> </label></td>'."\n".'<td>'.
782: &nameUserString(undef,$$fullname{$student},$uname,$udom).
783: ' '.$section.'</td>'."\n";
1.110 ng 784:
1.257 albertel 785: if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
1.110 ng 786: foreach (sort keys(%status)) {
787: next if (/^resource.*?submitted_by$/);
1.276 albertel 788: $gradeTable.='<td align="center"> '.$status{$_}.' </td>'."\n";
1.110 ng 789: }
1.41 ng 790: }
1.126 ng 791: # $gradeTable.='<td></td>' if ($ctr%2 ==1);
1.110 ng 792: $gradeTable.='</tr>'."\n" if ($ctr%2 ==0);
1.41 ng 793: }
794: }
1.110 ng 795: if ($ctr%2 ==1) {
1.126 ng 796: $gradeTable.='<td> </td><td> </td><td> </td>';
1.301 albertel 797: if ($env{'form.showgrading'} eq 'yes'
798: && $submitonly ne 'queued'
799: && $submitonly ne 'all') {
1.110 ng 800: foreach (@$partlist) {
801: $gradeTable.='<td> </td>';
802: }
1.301 albertel 803: } elsif ($submitonly eq 'queued') {
804: $gradeTable.='<td> </td>';
1.110 ng 805: }
806: $gradeTable.='</tr>';
807: }
808:
1.249 albertel 809: $gradeTable.='</table></td></tr></table>'."\n".
1.45 ng 810: '<input type="button" '.
811: 'onClick="javascript:checkSelect(this.form.stuinfo);" '.
1.126 ng 812: 'value="Next->" /></form>'."\n";
1.45 ng 813: if ($ctr == 0) {
1.96 albertel 814: my $num_students=(scalar(keys(%$fullname)));
815: if ($num_students eq 0) {
816: $gradeTable='<br /> <font color="red">There are no students currently enrolled.</font>';
817: } else {
1.171 albertel 818: my $submissions='submissions';
819: if ($submitonly eq 'incorrect') { $submissions = 'incorrect submissions'; }
820: if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
1.301 albertel 821: if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
1.96 albertel 822: $gradeTable='<br /> <font color="red">'.
1.171 albertel 823: 'No '.$submissions.' found for this resource for any students. ('.$num_students.
824: ' students checked for '.$submissions.')</font><br />';
1.96 albertel 825: }
1.46 ng 826: } elsif ($ctr == 1) {
827: $gradeTable =~ s/type=checkbox/type=checkbox checked/;
1.45 ng 828: }
1.50 albertel 829: $gradeTable.=&show_grading_menu_form($symb,$url);
1.45 ng 830: $request->print($gradeTable);
1.44 ng 831: return '';
1.10 ng 832: }
833:
1.44 ng 834: #---- Called from the listStudents routine
1.249 albertel 835:
836: sub check_script {
837: my ($form, $type)=@_;
838: my $chkallscript='<script type="text/javascript">
839: function checkall() {
840: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
841: ele = document.forms.'.$form.'.elements[i];
842: if (ele.name == "'.$type.'") {
843: document.forms.'.$form.'.elements[i].checked=true;
844: }
845: }
846: }
847:
848: function checksec() {
849: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
850: ele = document.forms.'.$form.'.elements[i];
851: string = document.forms.'.$form.'.chksec.value;
852: if
853: (ele.value.indexOf(":::SECTION"+string)>0) {
854: document.forms.'.$form.'.elements[i].checked=true;
855: }
856: }
857: }
858:
859:
860: function uncheckall() {
861: for (i=0; i<document.forms.'.$form.'.elements.length; i++) {
862: ele = document.forms.'.$form.'.elements[i];
863: if (ele.name == "'.$type.'") {
864: document.forms.'.$form.'.elements[i].checked=false;
865: }
866: }
867: }
868:
869: </script>'."\n";
870: return $chkallscript;
871: }
872:
873: sub check_buttons {
874: my $buttons.='<input type="button" onclick="checkall()" value="Check All" />';
875: $buttons.='<input type="button" onclick="uncheckall()" value="Uncheck All" /> ';
876: $buttons.='<input type="button" onclick="checksec()" value="Check Section/Group" />';
877: $buttons.='<input type="text" size="5" name="chksec" /> ';
878: return $buttons;
879: }
880:
1.44 ng 881: # Displays the submissions for one student or a group of students
1.34 ng 882: sub processGroup {
1.41 ng 883: my ($request) = shift;
884: my $ctr = 0;
1.155 albertel 885: my @stuchecked = &Apache::loncommon::get_env_multiple('form.stuinfo');
1.41 ng 886: my $total = scalar(@stuchecked)-1;
1.45 ng 887:
1.41 ng 888: foreach (@stuchecked) {
889: my ($uname,$udom,$fullname) = split(/:/);
1.257 albertel 890: $env{'form.student'} = $uname;
891: $env{'form.userdom'} = $udom;
892: $env{'form.fullname'} = $fullname;
1.41 ng 893: &submission($request,$ctr,$total);
894: $ctr++;
895: }
896: return '';
1.35 ng 897: }
1.34 ng 898:
1.44 ng 899: #------------------------------------------------------------------------------------
900: #
901: #-------------------------- Next few routines handles grading by student, essentially
902: # handles essay response type problem/part
903: #
904: #--- Javascript to handle the submission page functionality ---
905: sub sub_page_js {
906: my $request = shift;
907: $request->print(<<SUBJAVASCRIPT);
908: <script type="text/javascript" language="javascript">
1.71 ng 909: function updateRadio(formname,id,weight) {
1.125 ng 910: var gradeBox = formname["GD_BOX"+id];
911: var radioButton = formname["RADVAL"+id];
912: var oldpts = formname["oldpts"+id].value;
1.72 ng 913: var pts = checkSolved(formname,id) == 'update' ? gradeBox.value : oldpts;
1.71 ng 914: gradeBox.value = pts;
915: var resetbox = false;
916: if (isNaN(pts) || pts < 0) {
917: alert("A number equal or greater than 0 is expected. Entered value = "+pts);
918: for (var i=0; i<radioButton.length; i++) {
919: if (radioButton[i].checked) {
920: gradeBox.value = i;
921: resetbox = true;
922: }
923: }
924: if (!resetbox) {
925: formtextbox.value = "";
926: }
927: return;
1.44 ng 928: }
1.71 ng 929:
930: if (pts > weight) {
931: var resp = confirm("You entered a value ("+pts+
932: ") greater than the weight for the part. Accept?");
933: if (resp == false) {
1.125 ng 934: gradeBox.value = oldpts;
1.71 ng 935: return;
936: }
1.44 ng 937: }
1.13 albertel 938:
1.71 ng 939: for (var i=0; i<radioButton.length; i++) {
940: radioButton[i].checked=false;
941: if (pts == i && pts != "") {
942: radioButton[i].checked=true;
943: }
944: }
945: updateSelect(formname,id);
1.125 ng 946: formname["stores"+id].value = "0";
1.41 ng 947: }
1.5 albertel 948:
1.72 ng 949: function writeBox(formname,id,pts) {
1.125 ng 950: var gradeBox = formname["GD_BOX"+id];
1.71 ng 951: if (checkSolved(formname,id) == 'update') {
952: gradeBox.value = pts;
953: } else {
1.125 ng 954: var oldpts = formname["oldpts"+id].value;
1.72 ng 955: gradeBox.value = oldpts;
1.125 ng 956: var radioButton = formname["RADVAL"+id];
1.71 ng 957: for (var i=0; i<radioButton.length; i++) {
958: radioButton[i].checked=false;
1.72 ng 959: if (i == oldpts) {
1.71 ng 960: radioButton[i].checked=true;
961: }
962: }
1.41 ng 963: }
1.125 ng 964: formname["stores"+id].value = "0";
1.71 ng 965: updateSelect(formname,id);
966: return;
1.41 ng 967: }
1.44 ng 968:
1.71 ng 969: function clearRadBox(formname,id) {
970: if (checkSolved(formname,id) == 'noupdate') {
971: updateSelect(formname,id);
972: return;
973: }
1.125 ng 974: gradeSelect = formname["GD_SEL"+id];
1.71 ng 975: for (var i=0; i<gradeSelect.length; i++) {
976: if (gradeSelect[i].selected) {
977: var selectx=i;
978: }
979: }
1.125 ng 980: var stores = formname["stores"+id];
1.71 ng 981: if (selectx == stores.value) { return };
1.125 ng 982: var gradeBox = formname["GD_BOX"+id];
1.71 ng 983: gradeBox.value = "";
1.125 ng 984: var radioButton = formname["RADVAL"+id];
1.71 ng 985: for (var i=0; i<radioButton.length; i++) {
986: radioButton[i].checked=false;
987: }
988: stores.value = selectx;
989: }
1.5 albertel 990:
1.71 ng 991: function checkSolved(formname,id) {
1.125 ng 992: if (formname["solved"+id].value == "correct_by_student" && formname.overRideScore.value == 'no') {
1.118 ng 993: var reply = confirm("This problem has been graded correct by the computer. Do you want to change the score?");
994: if (!reply) {return "noupdate";}
1.120 ng 995: formname.overRideScore.value = 'yes';
1.41 ng 996: }
1.71 ng 997: return "update";
1.13 albertel 998: }
1.71 ng 999:
1000: function updateSelect(formname,id) {
1.125 ng 1001: formname["GD_SEL"+id][0].selected = true;
1.71 ng 1002: return;
1.41 ng 1003: }
1.33 ng 1004:
1.121 ng 1005: //=========== Check that a point is assigned for all the parts ============
1.71 ng 1006: function checksubmit(formname,val,total,parttot) {
1.121 ng 1007: formname.gradeOpt.value = val;
1.71 ng 1008: if (val == "Save & Next") {
1009: for (i=0;i<=total;i++) {
1010: for (j=0;j<parttot;j++) {
1.125 ng 1011: var partid = formname["partid"+i+"_"+j].value;
1.127 ng 1012: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1013: var points = formname["GD_BOX"+i+"_"+partid].value;
1.71 ng 1014: if (points == "") {
1.125 ng 1015: var name = formname["name"+i].value;
1.129 ng 1016: var studentID = (name != '' ? name : formname["unamedom"+i].value);
1017: var resp = confirm("You did not assign a score for "+studentID+
1018: ", part "+partid+". Continue?");
1.71 ng 1019: if (resp == false) {
1.125 ng 1020: formname["GD_BOX"+i+"_"+partid].focus();
1.71 ng 1021: return false;
1022: }
1023: }
1024: }
1025:
1026: }
1027: }
1028:
1029: }
1.121 ng 1030: if (val == "Grade Student") {
1031: formname.showgrading.value = "yes";
1032: if (formname.Status.value == "") {
1033: formname.Status.value = "Active";
1034: }
1035: formname.studentNo.value = total;
1036: }
1.120 ng 1037: formname.submit();
1038: }
1039:
1.71 ng 1040: //======= Check that a score is assigned for all the problems (page/sequence grading only) =========
1041: function checkSubmitPage(formname,total) {
1042: noscore = new Array(100);
1043: var ptr = 0;
1044: for (i=1;i<total;i++) {
1.125 ng 1045: var partid = formname["q_"+i].value;
1.127 ng 1046: if (formname["GD_SEL"+i+"_"+partid][0].selected) {
1.125 ng 1047: var points = formname["GD_BOX"+i+"_"+partid].value;
1048: var status = formname["solved"+i+"_"+partid].value;
1.71 ng 1049: if (points == "" && status != "correct_by_student") {
1050: noscore[ptr] = i;
1051: ptr++;
1052: }
1053: }
1054: }
1055: if (ptr != 0) {
1056: var sense = ptr == 1 ? ": " : "s: ";
1057: var prolist = "";
1058: if (ptr == 1) {
1059: prolist = noscore[0];
1060: } else {
1061: var i = 0;
1062: while (i < ptr-1) {
1063: prolist += noscore[i]+", ";
1064: i++;
1065: }
1066: prolist += "and "+noscore[i];
1067: }
1068: var resp = confirm("You did not assign any score for the following problem"+sense+prolist+". Continue?");
1069: if (resp == false) {
1070: return false;
1071: }
1072: }
1.45 ng 1073:
1.71 ng 1074: formname.submit();
1075: }
1076: </script>
1077: SUBJAVASCRIPT
1078: }
1.45 ng 1079:
1.71 ng 1080: #--- javascript for essay type problem --
1081: sub sub_page_kw_js {
1082: my $request = shift;
1.80 ng 1083: my $iconpath = $request->dir_config('lonIconsURL');
1.118 ng 1084: &commonJSfunctions($request);
1.219 www 1085: my $docopen=&Apache::lonhtmlcommon::javascript_docopen();
1.236 albertel 1086: $docopen=~s/^document\.//;
1.71 ng 1087: $request->print(<<SUBJAVASCRIPT);
1088: <script type="text/javascript" language="javascript">
1.45 ng 1089:
1.44 ng 1090: //===================== Show list of keywords ====================
1.122 ng 1091: function keywords(formname) {
1092: var nret = prompt("Keywords list, separated by a space. Add/delete to list if desired.",formname.keywords.value);
1.44 ng 1093: if (nret==null) return;
1.122 ng 1094: formname.keywords.value = nret;
1.44 ng 1095:
1.122 ng 1096: if (formname.keywords.value != "") {
1.128 ng 1097: formname.refresh.value = "on";
1.122 ng 1098: formname.submit();
1.44 ng 1099: }
1100: return;
1101: }
1102:
1103: //===================== Script to view submitted by ==================
1104: function viewSubmitter(submitter) {
1105: document.SCORE.refresh.value = "on";
1106: document.SCORE.NCT.value = "1";
1107: document.SCORE.unamedom0.value = submitter;
1108: document.SCORE.submit();
1109: return;
1110: }
1111:
1112: //===================== Script to add keyword(s) ==================
1113: function getSel() {
1114: if (document.getSelection) txt = document.getSelection();
1115: else if (document.selection) txt = document.selection.createRange().text;
1116: else return;
1117: var cleantxt = txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," ");
1118: if (cleantxt=="") {
1.46 ng 1119: alert("Please select a word or group of words from document and then click this link.");
1.44 ng 1120: return;
1121: }
1122: var nret = prompt("Add selection to keyword list? Edit if desired.",cleantxt);
1123: if (nret==null) return;
1.127 ng 1124: document.SCORE.keywords.value = document.SCORE.keywords.value+" "+nret;
1.44 ng 1125: if (document.SCORE.keywords.value != "") {
1.127 ng 1126: document.SCORE.refresh.value = "on";
1.44 ng 1127: document.SCORE.submit();
1128: }
1129: return;
1130: }
1131:
1132: //====================== Script for composing message ==============
1.80 ng 1133: // preload images
1134: img1 = new Image();
1135: img1.src = "$iconpath/mailbkgrd.gif";
1136: img2 = new Image();
1137: img2.src = "$iconpath/mailto.gif";
1138:
1.44 ng 1139: function msgCenter(msgform,usrctr,fullname) {
1140: var Nmsg = msgform.savemsgN.value;
1141: savedMsgHeader(Nmsg,usrctr,fullname);
1142: var subject = msgform.msgsub.value;
1.127 ng 1143: var msgchk = document.SCORE["includemsg"+usrctr].value;
1.44 ng 1144: re = /msgsub/;
1145: var shwsel = "";
1146: if (re.test(msgchk)) { shwsel = "checked" }
1.123 ng 1147: subject = (document.SCORE.shownSub.value == 0 ? checkEntities(subject) : subject);
1148: displaySubject(checkEntities(subject),shwsel);
1.44 ng 1149: for (var i=1; i<=Nmsg; i++) {
1.123 ng 1150: var testmsg = "savemsg"+i+",";
1151: re = new RegExp(testmsg,"g");
1.44 ng 1152: shwsel = "";
1153: if (re.test(msgchk)) { shwsel = "checked" }
1.125 ng 1154: var message = document.SCORE["savemsg"+i].value;
1.126 ng 1155: message = (document.SCORE["shownOnce"+i].value == 0 ? checkEntities(message) : message);
1.123 ng 1156: displaySavedMsg(i,message,shwsel); //I do not get it. w/o checkEntities on saved messages,
1157: //any < is already converted to <, etc. However, only once!!
1.44 ng 1158: }
1.125 ng 1159: newmsg = document.SCORE["newmsg"+usrctr].value;
1.44 ng 1160: shwsel = "";
1161: re = /newmsg/;
1162: if (re.test(msgchk)) { shwsel = "checked" }
1163: newMsg(newmsg,shwsel);
1164: msgTail();
1165: return;
1166: }
1167:
1.123 ng 1168: function checkEntities(strx) {
1169: if (strx.length == 0) return strx;
1170: var orgStr = ["&", "<", ">", '"'];
1171: var newStr = ["&", "<", ">", """];
1172: var counter = 0;
1173: while (counter < 4) {
1174: strx = strReplace(strx,orgStr[counter],newStr[counter]);
1175: counter++;
1176: }
1177: return strx;
1178: }
1179:
1180: function strReplace(strx, orgStr, newStr) {
1181: return strx.split(orgStr).join(newStr);
1182: }
1183:
1.44 ng 1184: function savedMsgHeader(Nmsg,usrctr,fullname) {
1.76 ng 1185: var height = 70*Nmsg+250;
1.44 ng 1186: var scrollbar = "no";
1187: if (height > 600) {
1188: height = 600;
1189: scrollbar = "yes";
1190: }
1.118 ng 1191: var xpos = (screen.width-600)/2;
1192: xpos = (xpos < 0) ? '0' : xpos;
1193: var ypos = (screen.height-height)/2-30;
1194: ypos = (ypos < 0) ? '0' : ypos;
1195:
1.206 albertel 1196: pWin = window.open('', 'MessageCenter', 'resizable=yes,toolbar=no,location=no,scrollbars='+scrollbar+',screenx='+xpos+',screeny='+ypos+',width=600,height='+height);
1.76 ng 1197: pWin.focus();
1198: pDoc = pWin.document;
1.219 www 1199: pDoc.$docopen;
1.76 ng 1200: pDoc.write("<html><head>");
1201: pDoc.write("<title>Message Central</title>");
1202:
1203: pDoc.write("<script language=javascript>");
1204: pDoc.write("function checkInput() {");
1.123 ng 1205: pDoc.write(" opener.document.SCORE.msgsub.value = opener.checkEntities(document.msgcenter.msgsub.value);");
1.76 ng 1206: pDoc.write(" var nmsg = opener.document.SCORE.savemsgN.value;");
1207: pDoc.write(" var usrctr = document.msgcenter.usrctr.value;");
1.125 ng 1208: pDoc.write(" var newval = opener.document.SCORE[\\"newmsg\\"+usrctr];");
1.123 ng 1209: pDoc.write(" newval.value = opener.checkEntities(document.msgcenter.newmsg.value);");
1.76 ng 1210:
1211: pDoc.write(" var msgchk = \\"\\";");
1212: pDoc.write(" if (document.msgcenter.subchk.checked) {");
1213: pDoc.write(" msgchk = \\"msgsub,\\";");
1214: pDoc.write(" }");
1.80 ng 1215: pDoc.write(" var includemsg = 0;");
1216: pDoc.write(" for (var i=1; i<=nmsg; i++) {");
1.125 ng 1217: pDoc.write(" var opnmsg = opener.document.SCORE[\\"savemsg\\"+i];");
1218: pDoc.write(" var frmmsg = document.msgcenter[\\"msg\\"+i];");
1.123 ng 1219: pDoc.write(" opnmsg.value = opener.checkEntities(frmmsg.value);");
1.125 ng 1220: pDoc.write(" var showflg = opener.document.SCORE[\\"shownOnce\\"+i];");
1.123 ng 1221: pDoc.write(" showflg.value = \\"1\\";");
1.125 ng 1222: pDoc.write(" var chkbox = document.msgcenter[\\"msgn\\"+i];");
1.76 ng 1223: pDoc.write(" if (chkbox.checked) {");
1224: pDoc.write(" msgchk += \\"savemsg\\"+i+\\",\\";");
1.80 ng 1225: pDoc.write(" includemsg = 1;");
1.76 ng 1226: pDoc.write(" }");
1227: pDoc.write(" }");
1228: pDoc.write(" if (document.msgcenter.newmsgchk.checked) {");
1229: pDoc.write(" msgchk += \\"newmsg\\"+usrctr;");
1.80 ng 1230: pDoc.write(" includemsg = 1;");
1231: pDoc.write(" }");
1.125 ng 1232: pDoc.write(" imgformname = opener.document.SCORE[\\"mailicon\\"+usrctr];");
1.84 ng 1233: pDoc.write(" imgformname.src = \\"$iconpath/\\"+((includemsg) ? \\"mailto.gif\\" : \\"mailbkgrd.gif\\");");
1.125 ng 1234: pDoc.write(" var includemsg = opener.document.SCORE[\\"includemsg\\"+usrctr];");
1.76 ng 1235: pDoc.write(" includemsg.value = msgchk;");
1236:
1237: pDoc.write(" self.close()");
1238:
1239: pDoc.write("}");
1240:
1241: pDoc.write("<");
1242: pDoc.write("/script>");
1243:
1244: pDoc.write("</head><body bgcolor=white>");
1245:
1246: pDoc.write("<form action=\\"inactive\\" name=\\"msgcenter\\">");
1247: pDoc.write("<input value=\\""+usrctr+"\\" name=\\"usrctr\\" type=\\"hidden\\">");
1248: pDoc.write("<font color=\\"green\\" size=+1> Compose Message for \"+fullname+\"</font><br><br>");
1249:
1250: pDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1251: pDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1252: pDoc.write("<td><b>Type</b></td><td><b>Include</b></td><td><b>Message</td></tr>");
1.44 ng 1253: }
1254: function displaySubject(msg,shwsel) {
1.76 ng 1255: pDoc = pWin.document;
1256: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1257: pDoc.write("<td>Subject</td>");
1258: pDoc.write("<td align=\\"center\\"><input name=\\"subchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1259: pDoc.write("<td><input name=\\"msgsub\\" type=\\"text\\" value=\\""+msg+"\\"size=\\"60\\" maxlength=\\"80\\"></td></tr>");
1.44 ng 1260: }
1261:
1.72 ng 1262: function displaySavedMsg(ctr,msg,shwsel) {
1.76 ng 1263: pDoc = pWin.document;
1264: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1265: pDoc.write("<td align=\\"center\\">"+ctr+"</td>");
1266: pDoc.write("<td align=\\"center\\"><input name=\\"msgn"+ctr+"\\" type=\\"checkbox\\"" +shwsel+"></td>");
1267: pDoc.write("<td><textarea name=\\"msg"+ctr+"\\" cols=\\"60\\" rows=\\"3\\">"+msg+"</textarea></td></tr>");
1.44 ng 1268: }
1269:
1270: function newMsg(newmsg,shwsel) {
1.76 ng 1271: pDoc = pWin.document;
1272: pDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1273: pDoc.write("<td align=\\"center\\">New</td>");
1274: pDoc.write("<td align=\\"center\\"><input name=\\"newmsgchk\\" type=\\"checkbox\\"" +shwsel+"></td>");
1275: pDoc.write("<td><textarea name=\\"newmsg\\" cols=\\"60\\" rows=\\"3\\" onchange=\\"javascript:this.form.newmsgchk.checked=true\\" >"+newmsg+"</textarea></td></tr>");
1.44 ng 1276: }
1277:
1278: function msgTail() {
1.76 ng 1279: pDoc = pWin.document;
1280: pDoc.write("</table>");
1281: pDoc.write("</td></tr></table> ");
1282: pDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:checkInput()\\"> ");
1283: pDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
1284: pDoc.write("</form>");
1285: pDoc.write("</body></html>");
1.128 ng 1286: pDoc.close();
1.44 ng 1287: }
1288:
1289: //====================== Script for keyword highlight options ==============
1290: function kwhighlight() {
1291: var kwclr = document.SCORE.kwclr.value;
1292: var kwsize = document.SCORE.kwsize.value;
1293: var kwstyle = document.SCORE.kwstyle.value;
1294: var redsel = "";
1295: var grnsel = "";
1296: var blusel = "";
1297: if (kwclr=="red") {var redsel="checked"};
1298: if (kwclr=="green") {var grnsel="checked"};
1299: if (kwclr=="blue") {var blusel="checked"};
1300: var sznsel = "";
1301: var sz1sel = "";
1302: var sz2sel = "";
1303: if (kwsize=="0") {var sznsel="checked"};
1304: if (kwsize=="+1") {var sz1sel="checked"};
1305: if (kwsize=="+2") {var sz2sel="checked"};
1306: var synsel = "";
1307: var syisel = "";
1308: var sybsel = "";
1309: if (kwstyle=="") {var synsel="checked"};
1310: if (kwstyle=="<i>") {var syisel="checked"};
1311: if (kwstyle=="<b>") {var sybsel="checked"};
1312: highlightCentral();
1313: highlightbody('red','red',redsel,'0','normal',sznsel,'','normal',synsel);
1314: highlightbody('green','green',grnsel,'+1','+1',sz1sel,'<i>','italic',syisel);
1315: highlightbody('blue','blue',blusel,'+2','+2',sz2sel,'<b>','bold',sybsel);
1316: highlightend();
1317: return;
1318: }
1319:
1320: function highlightCentral() {
1.76 ng 1321: // if (window.hwdWin) window.hwdWin.close();
1.118 ng 1322: var xpos = (screen.width-400)/2;
1323: xpos = (xpos < 0) ? '0' : xpos;
1324: var ypos = (screen.height-330)/2-30;
1325: ypos = (ypos < 0) ? '0' : ypos;
1326:
1.206 albertel 1327: hwdWin = window.open('', 'KeywordHighlightCentral', 'resizeable=yes,toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos);
1.76 ng 1328: hwdWin.focus();
1329: var hDoc = hwdWin.document;
1.219 www 1330: hDoc.$docopen;
1.76 ng 1331: hDoc.write("<html><head>");
1332: hDoc.write("<title>Highlight Central</title>");
1333:
1334: hDoc.write("<script language=javascript>");
1335: hDoc.write("function updateChoice(flag) {");
1.118 ng 1336: hDoc.write(" opener.document.SCORE.kwclr.value = opener.radioSelection(document.hlCenter.kwdclr);");
1337: hDoc.write(" opener.document.SCORE.kwsize.value = opener.radioSelection(document.hlCenter.kwdsize);");
1338: hDoc.write(" opener.document.SCORE.kwstyle.value = opener.radioSelection(document.hlCenter.kwdstyle);");
1.76 ng 1339: hDoc.write(" opener.document.SCORE.refresh.value = \\"on\\";");
1340: hDoc.write(" if (opener.document.SCORE.keywords.value!=\\"\\"){");
1341: hDoc.write(" opener.document.SCORE.submit();");
1342: hDoc.write(" }");
1343: hDoc.write(" self.close()");
1344: hDoc.write("}");
1345:
1346: hDoc.write("<");
1347: hDoc.write("/script>");
1348:
1349: hDoc.write("</head><body bgcolor=white>");
1350:
1351: hDoc.write("<form action=\\"inactive\\" name=\\"hlCenter\\">");
1352: hDoc.write("<font color=\\"green\\" size=+1> Keyword Highlight Options</font><br><br>");
1353:
1354: hDoc.write("<table border=0 width=100%><tr><td bgcolor=\\"#777777\\">");
1355: hDoc.write("<table border=0 width=100%><tr bgcolor=\\"#ddffff\\">");
1356: hDoc.write("<td><b>Text Color</b></td><td><b>Font Size</b></td><td><b>Font Style</td></tr>");
1.44 ng 1357: }
1358:
1359: function highlightbody(clrval,clrtxt,clrsel,szval,sztxt,szsel,syval,sytxt,sysel) {
1.76 ng 1360: var hDoc = hwdWin.document;
1361: hDoc.write("<tr bgcolor=\\"#ffffdd\\">");
1362: hDoc.write("<td align=\\"left\\">");
1363: hDoc.write("<input name=\\"kwdclr\\" type=\\"radio\\" value=\\""+clrval+"\\" "+clrsel+"> "+clrtxt+"</td>");
1364: hDoc.write("<td align=\\"left\\">");
1365: hDoc.write("<input name=\\"kwdsize\\" type=\\"radio\\" value=\\""+szval+"\\" "+szsel+"> "+sztxt+"</td>");
1366: hDoc.write("<td align=\\"left\\">");
1367: hDoc.write("<input name=\\"kwdstyle\\" type=\\"radio\\" value=\\""+syval+"\\" "+sysel+"> "+sytxt+"</td>");
1368: hDoc.write("</tr>");
1.44 ng 1369: }
1370:
1371: function highlightend() {
1.76 ng 1372: var hDoc = hwdWin.document;
1373: hDoc.write("</table>");
1374: hDoc.write("</td></tr></table> ");
1375: hDoc.write("<input type=\\"button\\" value=\\"Save\\" onClick=\\"javascript:updateChoice(1)\\"> ");
1376: hDoc.write("<input type=\\"button\\" value=\\"Cancel\\" onClick=\\"self.close()\\"><br><br>");
1377: hDoc.write("</form>");
1378: hDoc.write("</body></html>");
1.128 ng 1379: hDoc.close();
1.44 ng 1380: }
1381:
1382: </script>
1383: SUBJAVASCRIPT
1384: }
1385:
1.71 ng 1386: #--- displays the grading box, used in essay type problem and grading by page/sequence
1387: sub gradeBox {
1388: my ($request,$symb,$uname,$udom,$counter,$partid,$record) = @_;
1389: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
1390: '/check.gif" height="16" border="0" />';
1391: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname);
1392: my $wgtmsg = ($wgt > 0 ? '(problem weight)' :
1393: '<font color="red">problem weight assigned by computer</font>');
1394: $wgt = ($wgt > 0 ? $wgt : '1');
1395: my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ?
1396: '' : $$record{'resource.'.$partid.'.awarded'}*$wgt);
1397: my $result='<input type="hidden" name="WGT'.$counter.'_'.$partid.'" value="'.$wgt.'" />'."\n";
1.207 albertel 1398: my $display_part=&get_display_part($partid,undef,$symb);
1.270 albertel 1399: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
1400: [$partid]);
1401: my $aggtries = $$record{'resource.'.$partid.'.tries'};
1.269 raeburn 1402: if ($last_resets{$partid}) {
1403: $aggtries = &get_num_tries($record,$last_resets{$partid},$partid);
1404: }
1.71 ng 1405: $result.='<table border="0"><tr><td>'.
1.207 albertel 1406: '<b>Part: </b>'.$display_part.' <b>Points: </b></td><td>'."\n";
1.71 ng 1407: my $ctr = 0;
1408: $result.='<table border="0"><tr>'."\n"; # display radio buttons in a nice table 10 across
1409: while ($ctr<=$wgt) {
1.288 albertel 1410: $result.= '<td><nobr><label><input type="radio" name="RADVAL'.$counter.'_'.$partid.'" '.
1.71 ng 1411: 'onclick="javascript:writeBox(this.form,\''.$counter.'_'.$partid.'\','.
1.72 ng 1412: $ctr.')" value="'.$ctr.'" '.
1.288 albertel 1413: ($score eq $ctr ? 'checked':'').' /> '.$ctr."</label></nobr></td>\n";
1.71 ng 1414: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
1415: $ctr++;
1416: }
1417: $result.='</tr></table>';
1418: $result.='</td><td> <b>or</b> </td>'."\n";
1419: $result.='<td><input type="text" name="GD_BOX'.$counter.'_'.$partid.'"'.
1420: ($score ne ''? ' value = "'.$score.'"':'').' size="4" '.
1421: 'onChange="javascript:updateRadio(this.form,\''.$counter.'_'.$partid.'\','.
1422: $wgt.')" /></td>'."\n";
1423: $result.='<td>/'.$wgt.' '.$wgtmsg.
1424: ($$record{'resource.'.$partid.'.solved'} eq 'correct_by_student' ? ' '.$checkIcon : '').
1425: ' </td><td>'."\n";
1426: $result.='<select name="GD_SEL'.$counter.'_'.$partid.'" '.
1427: 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n";
1428: if ($$record{'resource.'.$partid.'.solved'} eq 'excused') {
1429: $result.='<option> </option>'.
1.125 ng 1430: '<option selected="on">excused</option>';
1.71 ng 1431: } else {
1432: $result.='<option selected="on"> </option>'.
1.125 ng 1433: '<option>excused</option>';
1.71 ng 1434: }
1.125 ng 1435: $result.='<option>reset status</option></select>'."\n";
1.71 ng 1436: $result.="  \n";
1437: $result.='<input type="hidden" name="stores'.$counter.'_'.$partid.'" value="" />'."\n".
1438: '<input type="hidden" name="oldpts'.$counter.'_'.$partid.'" value="'.$score.'" />'."\n".
1439: '<input type="hidden" name="solved'.$counter.'_'.$partid.'" value="'.
1.269 raeburn 1440: $$record{'resource.'.$partid.'.solved'}.'" />'."\n".
1441: '<input type="hidden" name="totaltries'.$counter.'_'.$partid.'" value="'.
1442: $$record{'resource.'.$partid.'.tries'}.'" />'."\n".
1443: '<input type="hidden" name="aggtries'.$counter.'_'.$partid.'" value="'.
1444: $aggtries.'" />'."\n";
1.71 ng 1445: $result.='</td></tr></table>'."\n";
1.313 ! banghart 1446: my $files=&get_submitted_files($udom,$uname,$partid,$counter,$record);
! 1447: if (@$files) {
! 1448: my $file_counter = 0;
! 1449: foreach my $file (@$files) {
! 1450: $result.=' Return commented document to student. <input type="file" name="part'.$partid.'_returndoc';
! 1451: $result.=$file_counter.'" />'."\n";
! 1452: $result.='<input type="hidden" name="respid" value="'.$counter.'" />';
! 1453: $result.='<input type="hidden" name="returndocorig'.$file_counter.'" value="'.$file.'" />';
! 1454: }
! 1455: }
! 1456:
! 1457:
1.71 ng 1458: return $result;
1459: }
1.44 ng 1460:
1.58 albertel 1461: sub show_problem {
1.144 albertel 1462: my ($request,$symb,$uname,$udom,$removeform,$viewon,$mode) = @_;
1463: my $rendered;
1464: if ($mode eq 'both' or $mode eq 'text') {
1465: $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
1.257 albertel 1466: $env{'request.course.id'});
1.144 albertel 1467: }
1.58 albertel 1468: if ($removeform) {
1469: $rendered=~s|<form(.*?)>||g;
1470: $rendered=~s|</form>||g;
1471: $rendered=~s|name="submit"|name="would_have_been_submit"|g;
1472: }
1.144 albertel 1473: my $companswer;
1474: if ($mode eq 'both' or $mode eq 'answer') {
1475: $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
1.257 albertel 1476: $env{'request.course.id'});
1.144 albertel 1477: }
1.58 albertel 1478: if ($removeform) {
1479: $companswer=~s|<form(.*?)>||g;
1480: $companswer=~s|</form>||g;
1.144 albertel 1481: $companswer=~s|name="submit"|name="would_have_been_submit"|g;
1.58 albertel 1482: }
1483: my $result.='<table border="0" width="100%"><tr><td bgcolor="#777777">';
1.71 ng 1484: $result.='<table border="0" width="100%">';
1.144 albertel 1485: if ($viewon) {
1486: $result.='<tr><td bgcolor="#e6ffff"><b> ';
1487: if ($mode eq 'both' or $mode eq 'text') {
1488: $result.='View of the problem - ';
1489: } else {
1490: $result.='Correct answer: ';
1491: }
1.257 albertel 1492: $result.=$env{'form.fullname'}.'</b></td></tr>';
1.144 albertel 1493: }
1494: if ($mode eq 'both') {
1495: $result.='<tr><td bgcolor="#ffffff">'.$rendered.'<br />';
1496: $result.='<b>Correct answer:</b><br />'.$companswer;
1497: } elsif ($mode eq 'text') {
1498: $result.='<tr><td bgcolor="#ffffff">'.$rendered;
1499: } elsif ($mode eq 'answer') {
1500: $result.='<tr><td bgcolor="#ffffff">'.$companswer;
1501: }
1.58 albertel 1502: $result.='</td></tr></table>';
1503: $result.='</td></tr></table><br />';
1.71 ng 1504: return $result;
1.58 albertel 1505: }
1506:
1.44 ng 1507: # --------------------------- show submissions of a student, option to grade
1508: sub submission {
1509: my ($request,$counter,$total) = @_;
1510:
1.257 albertel 1511: (my $url=$env{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1512: my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'});
1513: $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student?
1514: my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'});
1515: $env{'form.fullname'} = &Apache::loncommon::plainname($uname,$udom,'lastname') if $env{'form.fullname'} eq '';
1.41 ng 1516:
1.257 albertel 1517: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
1.41 ng 1518: if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
1.104 albertel 1519:
1520: if (!&canview($usec)) {
1.116 ng 1521: $request->print('<font color="red">Unable to view requested student.('.
1.222 albertel 1522: $uname.'@'.$udom.' in section '.$usec.' in course id '.
1.257 albertel 1523: $env{'request.course.id'}.')</font>');
1.104 albertel 1524: $request->print(&show_grading_menu_form($symb,$url));
1525: return;
1526: }
1527:
1.257 albertel 1528: if (!$env{'form.lastSub'}) { $env{'form.lastSub'} = 'datesub'; }
1529: if (!$env{'form.vProb'}) { $env{'form.vProb'} = 'yes'; }
1530: if (!$env{'form.vAns'}) { $env{'form.vAns'} = 'yes'; }
1531: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.122 ng 1532: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
1533: '/check.gif" height="16" border="0" />';
1.41 ng 1534:
1535: # header info
1536: if ($counter == 0) {
1537: &sub_page_js($request);
1.257 albertel 1538: &sub_page_kw_js($request) if ($env{'form.handgrade'} eq 'yes');
1539: $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ?
1540: &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'};
1.76 ng 1541:
1.45 ng 1542: $request->print('<h3> <font color="#339933">Submission Record</font></h3>'."\n".
1.257 albertel 1543: '<font size=+1> <b>Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n");
1.118 ng 1544:
1.257 albertel 1545: if ($env{'form.handgrade'} eq 'no') {
1.118 ng 1546: my $checkMark='<br /><br /> <b>Note:</b> Part(s) graded correct by the computer is marked with a '.
1547: $checkIcon.' symbol.'."\n";
1548: $request->print($checkMark);
1549: }
1.41 ng 1550:
1.44 ng 1551: # option to display problem, only once else it cause problems
1552: # with the form later since the problem has a form.
1.257 albertel 1553: if ($env{'form.vProb'} eq 'yes' or $env{'form.vAns'} eq 'yes') {
1.144 albertel 1554: my $mode;
1.257 albertel 1555: if ($env{'form.vProb'} eq 'yes' && $env{'form.vAns'} eq 'yes') {
1.144 albertel 1556: $mode='both';
1.257 albertel 1557: } elsif ($env{'form.vProb'} eq 'yes') {
1.144 albertel 1558: $mode='text';
1.257 albertel 1559: } elsif ($env{'form.vAns'} eq 'yes') {
1.144 albertel 1560: $mode='answer';
1561: }
1562: $request->print(&show_problem($request,$symb,$uname,$udom,0,1,$mode));
1.41 ng 1563: }
1564:
1.44 ng 1565: # kwclr is the only variable that is guaranteed to be non blank
1566: # if this subroutine has been called once.
1.41 ng 1567: my %keyhash = ();
1.257 albertel 1568: if ($env{'form.kwclr'} eq '' && $env{'form.handgrade'} eq 'yes') {
1.41 ng 1569: %keyhash = &Apache::lonnet::dump('nohist_handgrade',
1.257 albertel 1570: $env{'course.'.$env{'request.course.id'}.'.domain'},
1571: $env{'course.'.$env{'request.course.id'}.'.num'});
1.41 ng 1572:
1.257 albertel 1573: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1574: $env{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
1575: $env{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
1576: $env{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
1577: $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
1578: $env{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
1579: $keyhash{$symb.'_subject'} : $env{'form.probTitle'};
1580: $env{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
1.41 ng 1581: }
1.257 albertel 1582: my $overRideScore = $env{'form.overRideScore'} eq '' ? 'no' : $env{'form.overRideScore'};
1.44 ng 1583:
1.303 banghart 1584: $request->print('<form action="/adm/grades" method="post" name="SCORE" enctype="multipart/form-data">'."\n".
1.41 ng 1585: '<input type="hidden" name="command" value="handgrade" />'."\n".
1.257 albertel 1586: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1587: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.120 ng 1588: '<input type="hidden" name="overRideScore" value="'.$overRideScore.'" />'."\n".
1.257 albertel 1589: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n".
1.41 ng 1590: '<input type="hidden" name="refresh" value="off" />'."\n".
1.120 ng 1591: '<input type="hidden" name="studentNo" value="" />'."\n".
1592: '<input type="hidden" name="gradeOpt" value="" />'."\n".
1.41 ng 1593: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1594: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.257 albertel 1595: '<input type="hidden" name="showgrading" value="'.$env{'form.showgrading'}.'" />'."\n".
1596: '<input type="hidden" name="vProb" value="'.$env{'form.vProb'}.'" />'."\n".
1597: '<input type="hidden" name="vAns" value="'.$env{'form.vAns'}.'" />'."\n".
1598: '<input type="hidden" name="lastSub" value="'.$env{'form.lastSub'}.'" />'."\n".
1599: '<input type="hidden" name="section" value="'.$env{'form.section'}.'">'."\n".
1600: '<input type="hidden" name="submitonly" value="'.$env{'form.submitonly'}.'">'."\n".
1601: '<input type="hidden" name="handgrade" value="'.$env{'form.handgrade'}.'">'."\n".
1.41 ng 1602: '<input type="hidden" name="NCT"'.
1.257 albertel 1603: ' value="'.($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : $total+1).'" />'."\n");
1604: if ($env{'form.handgrade'} eq 'yes') {
1605: $request->print('<input type="hidden" name="keywords" value="'.$env{'form.keywords'}.'" />'."\n".
1606: '<input type="hidden" name="kwclr" value="'.$env{'form.kwclr'}.'" />'."\n".
1607: '<input type="hidden" name="kwsize" value="'.$env{'form.kwsize'}.'" />'."\n".
1608: '<input type="hidden" name="kwstyle" value="'.$env{'form.kwstyle'}.'" />'."\n".
1609: '<input type="hidden" name="msgsub" value="'.$env{'form.msgsub'}.'" />'."\n".
1.123 ng 1610: '<input type="hidden" name="shownSub" value="0" />'."\n".
1.257 albertel 1611: '<input type="hidden" name="savemsgN" value="'.$env{'form.savemsgN'}.'" />'."\n");
1.154 albertel 1612: foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) {
1613: $request->print('<input type="hidden" name="vPart" value="'.$partid.'" />'."\n");
1614: }
1.123 ng 1615: }
1.41 ng 1616:
1617: my ($cts,$prnmsg) = (1,'');
1.257 albertel 1618: while ($cts <= $env{'form.savemsgN'}) {
1.41 ng 1619: $prnmsg.='<input type="hidden" name="savemsg'.$cts.'" value="'.
1.123 ng 1620: (!exists($keyhash{$symb.'_savemsg'.$cts}) ?
1.257 albertel 1621: &Apache::lonfeedback::clear_out_html($env{'form.savemsg'.$cts}) :
1.80 ng 1622: &Apache::lonfeedback::clear_out_html($keyhash{$symb.'_savemsg'.$cts})).
1.123 ng 1623: '" />'."\n".
1624: '<input type="hidden" name="shownOnce'.$cts.'" value="0" />'."\n";
1.41 ng 1625: $cts++;
1626: }
1627: $request->print($prnmsg);
1.32 ng 1628:
1.257 albertel 1629: if ($env{'form.handgrade'} eq 'yes' && $env{'form.showgrading'} eq 'yes') {
1.88 www 1630: #
1631: # Print out the keyword options line
1632: #
1.41 ng 1633: $request->print(<<KEYWORDS);
1.38 ng 1634: <b>Keyword Options:</b>
1.122 ng 1635: <a href="javascript:keywords(document.SCORE)"; TARGET=_self>List</a>
1.38 ng 1636: <a href="#" onMouseDown="javascript:getSel(); return false"
1637: CLASS="page">Paste Selection to List</a>
1638: <a href="javascript:kwhighlight()"; TARGET=_self>Highlight Attribute</a><br /><br />
1639: KEYWORDS
1.88 www 1640: #
1641: # Load the other essays for similarity check
1642: #
1643: my $essayurl=&Apache::lonnet::declutter($url);
1644: my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
1645: $apath=&Apache::lonnet::escape($apath);
1646: $apath=~s/\W/\_/gs;
1647: %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
1.41 ng 1648: }
1649: }
1.44 ng 1650:
1.257 albertel 1651: if ($env{'form.vProb'} eq 'all' or $env{'form.vAns'} eq 'all') {
1.71 ng 1652: $request->print('<br /><br /><br />') if ($counter > 0);
1.144 albertel 1653: my $mode;
1.257 albertel 1654: if ($env{'form.vProb'} eq 'all' && $env{'form.vAns'} eq 'all') {
1.144 albertel 1655: $mode='both';
1.257 albertel 1656: } elsif ($env{'form.vProb'} eq 'all' ) {
1.144 albertel 1657: $mode='text';
1.257 albertel 1658: } elsif ($env{'form.vAns'} eq 'all') {
1.144 albertel 1659: $mode='answer';
1660: }
1661: $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode));
1.58 albertel 1662: }
1.144 albertel 1663:
1.257 albertel 1664: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.147 albertel 1665: my ($partlist,$handgrade,$responseType) = &response_type($url,$symb);
1.41 ng 1666:
1.44 ng 1667: # Display student info
1.41 ng 1668: $request->print(($counter == 0 ? '' : '<br />'));
1.45 ng 1669: my $result='<table border="0" width=100%><tr><td bgcolor="#777777">'."\n".
1670: '<table border="0" width=100%><tr bgcolor="#edffff"><td>'."\n";
1.44 ng 1671:
1.257 albertel 1672: $result.='<b>Fullname: </b>'.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).'<br />'."\n";
1.45 ng 1673: $result.='<input type="hidden" name="name'.$counter.
1.257 albertel 1674: '" value="'.$env{'form.fullname'}.'" />'."\n";
1.41 ng 1675:
1.118 ng 1676: # If any part of the problem is an essay-response (handgraded), then check for collaborators
1.45 ng 1677: my @col_fullnames;
1.56 matthew 1678: my ($classlist,$fullname);
1.257 albertel 1679: if ($env{'form.handgrade'} eq 'yes') {
1.80 ng 1680: ($classlist,undef,$fullname) = &getclasslist('all','0');
1.41 ng 1681: for (keys (%$handgrade)) {
1.44 ng 1682: my $ncol = &Apache::lonnet::EXT('resource.'.$_.
1.57 matthew 1683: '.maxcollaborators',
1684: $symb,$udom,$uname);
1685: next if ($ncol <= 0);
1686: s/\_/\./g;
1687: next if ($record{'resource.'.$_.'.collaborators'} eq '');
1.86 ng 1688: my @goodcollaborators = ();
1689: my @badcollaborators = ();
1690: foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) {
1691: $_ =~ s/[\$\^\(\)]//g;
1692: next if ($_ eq '');
1.80 ng 1693: my ($co_name,$co_dom) = split /\@|:/,$_;
1.86 ng 1694: $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i);
1.80 ng 1695: next if ($co_name eq $uname && $co_dom eq $udom);
1.86 ng 1696: # Doing this grep allows 'fuzzy' specification
1697: my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist;
1698: if (! scalar(@Matches)) {
1699: push @badcollaborators,$_;
1700: } else {
1701: push @goodcollaborators, @Matches;
1702: }
1.80 ng 1703: }
1.86 ng 1704: if (scalar(@goodcollaborators) != 0) {
1.57 matthew 1705: $result.='<b>Collaborators: </b>';
1.86 ng 1706: foreach (@goodcollaborators) {
1707: my ($lastname,$givenn) = split(/,/,$$fullname{$_});
1708: push @col_fullnames, $givenn.' '.$lastname;
1709: $result.=$$fullname{$_}.' ';
1710: }
1.57 matthew 1711: $result.='<br />'."\n";
1.150 albertel 1712: my ($part)=split(/\./,$_);
1.86 ng 1713: $result.='<input type="hidden" name="collaborator'.$counter.
1.150 albertel 1714: '" value="'.$part.':'.(join ':',@goodcollaborators).'" />'.
1715: "\n";
1.86 ng 1716: }
1717: if (scalar(@badcollaborators) > 0) {
1718: $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
1719: $result.='This student has submitted ';
1720: $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators';
1721: $result .= ': '.join(', ',@badcollaborators);
1722: $result .= '</td></tr></table>';
1723: }
1724: if (scalar(@badcollaborators > $ncol)) {
1725: $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
1726: $result .= 'This student has submitted too many '.
1727: 'collaborators. Maximum is '.$ncol.'.';
1728: $result .= '</td></tr></table>';
1729: }
1.41 ng 1730: }
1731: }
1.44 ng 1732: $request->print($result."\n");
1.33 ng 1733:
1.44 ng 1734: # print student answer/submission
1735: # Options are (1) Handgaded submission only
1736: # (2) Last submission, includes submission that is not handgraded
1737: # (for multi-response type part)
1738: # (3) Last submission plus the parts info
1739: # (4) The whole record for this student
1.257 albertel 1740: if ($env{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) {
1.151 albertel 1741: my ($string,$timestamp)= &get_last_submission(\%record);
1742: my $lastsubonly=''.
1743: ($$timestamp eq '' ? '' : '<b>Date Submitted:</b> '.
1744: $$timestamp)."</td></tr>\n";
1745: if ($$timestamp eq '') {
1746: $lastsubonly.='<tr><td bgcolor="#ffffe6">'.$$string[0];
1747: } else {
1748: my %seenparts;
1749: for my $part (sort keys(%$handgrade)) {
1750: my ($partid,$respid) = split(/_/,$part);
1.207 albertel 1751: my $display_part=&get_display_part($partid,$url,$symb);
1.257 albertel 1752: if ($env{"form.$uname:$udom:$partid:submitted_by"}) {
1.151 albertel 1753: if (exists($seenparts{$partid})) { next; }
1754: $seenparts{$partid}=1;
1.207 albertel 1755: my $submitby='<b>Part:</b> '.$display_part.
1756: ' <b>Collaborative submission by:</b> '.
1.151 albertel 1757: '<a href="javascript:viewSubmitter(\''.
1.257 albertel 1758: $env{"form.$uname:$udom:$partid:submitted_by"}.
1.151 albertel 1759: '\')"; TARGET=_self>'.
1.257 albertel 1760: $$fullname{$env{"form.$uname:$udom:$partid:submitted_by"}}.'</a><br />';
1.151 albertel 1761: $request->print($submitby);
1762: next;
1763: }
1764: my $responsetype = $responseType->{$partid}->{$respid};
1765: if (!exists($record{"resource.$partid.$respid.submission"})) {
1.207 albertel 1766: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1767: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1768: ' )</font> '.
1769: '<font color="red">Nothing submitted - no attempts</font><br /><br />';
1770: next;
1771: }
1772: foreach (@$string) {
1773: my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/;
1774: if ($part ne ($partid.'_'.$respid)) { next; }
1775: my ($ressub,$subval) = split(/:/,$_,2);
1776: # Similarity check
1777: my $similar='';
1.257 albertel 1778: if($env{'form.checkPlag'}){
1.151 albertel 1779: my ($oname,$odom,$ocrsid,$oessay,$osim)=
1780: &most_similar($uname,$udom,$subval);
1781: if ($osim) {
1782: $osim=int($osim*100.0);
1783: $similar="<hr /><h3><font color=\"#FF0000\">Essay".
1784: " is $osim% similar to an essay by ".
1785: &Apache::loncommon::plainname($oname,$odom).
1786: '</font></h3><blockquote><i>'.
1787: &keywords_highlight($oessay).
1788: '</i></blockquote><hr />';
1789: }
1.150 albertel 1790: }
1.151 albertel 1791: my $order=&get_order($partid,$respid,$symb,$uname,$udom);
1.257 albertel 1792: if ($env{'form.lastSub'} eq 'lastonly' ||
1793: ($env{'form.lastSub'} eq 'hdgrade' &&
1.151 albertel 1794: $$handgrade{$part} eq 'yes')) {
1.207 albertel 1795: my $display_part=&get_display_part($partid,$url,$symb);
1796: $lastsubonly.='<tr><td bgcolor="#ffffe6"><b>Part:</b> '.
1797: $display_part.' <font color="#999999">( ID '.$respid.
1.151 albertel 1798: ' )</font> ';
1.313 ! banghart 1799: my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
! 1800: # if ($record{"resource.$partid.$respid.portfiles"}) {
! 1801: # my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
! 1802: # foreach my $file (split(',',$record{"resource.$partid.$respid.portfiles"})) {
! 1803: # push(@files,$file_url.$file);
! 1804: # }
! 1805: # }
! 1806: # if ($record{"resource.$partid.$respid.uploadedurl"}) {
! 1807: # push(@files,$record{"resource.$partid.$respid.uploadedurl"});
! 1808: # }
! 1809: if (@$files) {
1.232 albertel 1810: $lastsubonly.='<br /><font color="red" size="1">Like all files provided by users, this file may contain virusses</font><br />';
1.303 banghart 1811: my $file_counter = 0;
1.313 ! banghart 1812: foreach my $file (@$files) {
1.303 banghart 1813: $file_counter ++;
1.232 albertel 1814: &Apache::lonnet::allowuploaded('/adm/grades',$file);
1815: $lastsubonly.='<br /><a href="'.$file.'" target="lonGRDs"><img src="'.&Apache::loncommon::icon($file).'" border=0"> '.$file.'</a>';
1816: }
1.236 albertel 1817: $lastsubonly.='<br />';
1.41 ng 1818: }
1.151 albertel 1819: $lastsubonly.='<b>Submitted Answer: </b>'.
1820: &cleanRecord($subval,$responsetype,$symb,$partid,
1821: $respid,\%record,$order);
1822: if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
1.41 ng 1823: }
1824: }
1825: }
1.151 albertel 1826: }
1827: $lastsubonly.='</td></tr><tr bgcolor="#ffffff"><td>'."\n";
1828: $request->print($lastsubonly);
1.257 albertel 1829: } elsif ($env{'form.lastSub'} eq 'datesub') {
1.122 ng 1830: my (undef,$responseType,undef,$parts) = &showResourceInfo($url);
1.148 albertel 1831: $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
1.257 albertel 1832: } elsif ($env{'form.lastSub'} =~ /^(last|all)$/) {
1.41 ng 1833: $request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
1.257 albertel 1834: $env{'request.course.id'},
1.44 ng 1835: $last,'.submission',
1836: 'Apache::grades::keywords_highlight'));
1.41 ng 1837: }
1.120 ng 1838:
1.121 ng 1839: $request->print('<input type="hidden" name="unamedom'.$counter.'" value="'.$uname.':'
1840: .$udom.'" />'."\n");
1.41 ng 1841:
1.44 ng 1842: # return if view submission with no grading option
1.257 albertel 1843: if ($env{'form.showgrading'} eq '' || (!&canmodify($usec))) {
1.120 ng 1844: my $toGrade.='<input type="button" value="Grade Student" '.
1.121 ng 1845: 'onClick="javascript:checksubmit(this.form,\'Grade Student\',\''
1846: .$counter.'\');" TARGET=_self> '."\n" if (&canmodify($usec));
1.169 albertel 1847: $toGrade.='</td></tr></table></td></tr></table>'."\n";
1.257 albertel 1848: if (($env{'form.command'} eq 'submission') ||
1849: ($env{'form.command'} eq 'processGroup' && $counter == $total)) {
1.169 albertel 1850: $toGrade.='</form>'.&show_grading_menu_form($symb,$url)
1851: }
1.180 albertel 1852: $request->print($toGrade);
1.41 ng 1853: return;
1.180 albertel 1854: } else {
1855: $request->print('</td></tr></table></td></tr></table>'."\n");
1.41 ng 1856: }
1.33 ng 1857:
1.121 ng 1858: # essay grading message center
1.257 albertel 1859: if ($env{'form.handgrade'} eq 'yes') {
1860: my ($lastname,$givenn) = split(/,/,$env{'form.fullname'});
1.118 ng 1861: my $msgfor = $givenn.' '.$lastname;
1862: if (scalar(@col_fullnames) > 0) {
1863: my $lastone = pop @col_fullnames;
1864: $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.';
1865: }
1866: $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript
1.121 ng 1867: $result='<input type="hidden" name="includemsg'.$counter.'" value="" />'."\n".
1868: '<input type="hidden" name="newmsg'.$counter.'" value="" />'."\n";
1869: $result.=' <a href="javascript:msgCenter(document.SCORE,'.$counter.
1.118 ng 1870: ',\''.$msgfor.'\')"; TARGET=_self>'.
1.298 www 1871: &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'</a> ('.
1872: &mt('incl. grades').' <input type="checkbox" name="withgrades'.$counter.'" />)'.
1.118 ng 1873: '<img src="'.$request->dir_config('lonIconsURL').
1874: '/mailbkgrd.gif" width="14" height="10" name="mailicon'.$counter.'" />'."\n".
1.298 www 1875: '<br /> ('.
1876: &mt('Message will be sent when you click on Save & Next below.').")\n";
1.121 ng 1877: $request->print($result);
1.118 ng 1878: }
1.300 albertel 1879: if ($perm{'vgr'}) {
1.297 www 1880: $request->print('<br />'.
1.300 albertel 1881: &Apache::loncommon::track_student_link(&mt('View recent activity'),
1882: $uname,$udom,'check'));
1.297 www 1883: }
1.300 albertel 1884: if ($perm{'opa'}) {
1.297 www 1885: $request->print('<br />'.
1.300 albertel 1886: &Apache::loncommon::pprmlink(&mt('Set/Change parameters'),
1887: $uname,$udom,$symb,'check'));
1.297 www 1888: }
1.41 ng 1889:
1890: my %seen = ();
1891: my @partlist;
1.129 ng 1892: my @gradePartRespid;
1.41 ng 1893: for (sort keys(%$handgrade)) {
1894: my ($partid,$respid) = split(/_/);
1895: next if ($seen{$partid} > 0);
1896: $seen{$partid}++;
1.257 albertel 1897: next if ($$handgrade{$_} =~ /:no$/ && $env{'form.lastSub'} =~ /^(hdgrade)$/);
1.41 ng 1898: push @partlist,$partid;
1.129 ng 1899: push @gradePartRespid,$partid.'.'.$respid;
1.41 ng 1900:
1.71 ng 1901: $request->print(&gradeBox($request,$symb,$uname,$udom,$counter,$partid,\%record));
1.41 ng 1902: }
1.45 ng 1903: $result='<input type="hidden" name="partlist'.$counter.
1904: '" value="'.(join ":",@partlist).'" />'."\n";
1.129 ng 1905: $result.='<input type="hidden" name="gradePartRespid'.
1906: '" value="'.(join ":",@gradePartRespid).'" />'."\n" if ($counter == 0);
1.45 ng 1907: my $ctr = 0;
1908: while ($ctr < scalar(@partlist)) {
1909: $result.='<input type="hidden" name="partid'.$counter.'_'.$ctr.'" value="'.
1910: $partlist[$ctr].'" />'."\n";
1911: $ctr++;
1912: }
1913: $request->print($result.'</td></tr></table></td></tr></table>'."\n");
1.41 ng 1914:
1915: # print end of form
1916: if ($counter == $total) {
1.297 www 1917: my $endform='<table border="0"><tr><td>'."\n";
1.119 ng 1918: $endform.='<input type="button" value="Save & Next" '.
1919: 'onClick="javascript:checksubmit(this.form,\'Save & Next\','.
1920: $total.','.scalar(@partlist).');" TARGET=_self> '."\n";
1921: my $ntstu ='<select name="NTSTU">'.
1922: '<option>1</option><option>2</option>'.
1923: '<option>3</option><option>5</option>'.
1924: '<option>7</option><option>10</option></select>'."\n";
1.257 albertel 1925: my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1');
1.119 ng 1926: $ntstu =~ s/<option>$nsel</<option selected="on">$nsel</;
1927: $endform.=$ntstu.'student(s) ';
1.126 ng 1928: $endform.='<input type="button" value="Previous" '.
1929: 'onClick="javascript:checksubmit(this.form,\'Previous\');" TARGET=_self> '."\n".
1930: '<input type="button" value="Next" '.
1931: 'onClick="javascript:checksubmit(this.form,\'Next\');" TARGET=_self> ';
1932: $endform.='(Next and Previous (student) do not save the scores.)'."\n" ;
1.45 ng 1933: $endform.='</td><tr></table></form>';
1.50 albertel 1934: $endform.=&show_grading_menu_form($symb,$url);
1.41 ng 1935: $request->print($endform);
1936: }
1937: return '';
1.38 ng 1938: }
1939:
1.44 ng 1940: #--- Retrieve the last submission for all the parts
1.38 ng 1941: sub get_last_submission {
1.119 ng 1942: my ($returnhash)=@_;
1.46 ng 1943: my (@string,$timestamp);
1.119 ng 1944: if ($$returnhash{'version'}) {
1.46 ng 1945: my %lasthash=();
1946: my ($version);
1.119 ng 1947: for ($version=1;$version<=$$returnhash{'version'};$version++) {
1948: foreach (sort(split(/\:/,$$returnhash{$version.':keys'}))) {
1949: $lasthash{$_}=$$returnhash{$version.':'.$_};
1950: $timestamp = scalar(localtime($$returnhash{$version.':timestamp'}));
1.46 ng 1951: }
1952: }
1953: foreach ((keys %lasthash)) {
1954: if ($_ =~ /\.submission$/) {
1955: my ($partid,$foo) = split(/submission$/,$_);
1956: my $draft = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
1957: '<font color="red">Draft Copy</font> ' : '';
1958: push @string, (join(':',$_,$draft.$lasthash{$_}));
1.41 ng 1959: }
1960: }
1961: }
1.125 ng 1962: @string = $string[0] eq '' ? '<font color="red">Nothing submitted - no attempts.</font>' : @string;
1.46 ng 1963: return \@string,\$timestamp;
1.38 ng 1964: }
1.35 ng 1965:
1.44 ng 1966: #--- High light keywords, with style choosen by user.
1.38 ng 1967: sub keywords_highlight {
1.44 ng 1968: my $string = shift;
1.257 albertel 1969: my $size = $env{'form.kwsize'} eq '0' ? '' : 'size='.$env{'form.kwsize'};
1970: my $styleon = $env{'form.kwstyle'} eq '' ? '' : $env{'form.kwstyle'};
1.41 ng 1971: (my $styleoff = $styleon) =~ s/\</\<\//;
1.257 albertel 1972: my @keylist = split(/[,\s+]/,$env{'form.keywords'});
1.41 ng 1973: foreach (@keylist) {
1.257 albertel 1974: $string =~ s/\b\Q$_\E(\b|\.)/<font color\=$env{'form.kwclr'} $size\>$styleon$_$styleoff<\/font>/gi;
1.41 ng 1975: }
1976: return $string;
1.38 ng 1977: }
1.36 ng 1978:
1.44 ng 1979: #--- Called from submission routine
1.38 ng 1980: sub processHandGrade {
1.41 ng 1981: my ($request) = shift;
1.257 albertel 1982: my $url = $env{'form.url'};
1983: my $symb = $env{'form.symb'};
1984: my $button = $env{'form.gradeOpt'};
1985: my $ngrade = $env{'form.NCT'};
1986: my $ntstu = $env{'form.NTSTU'};
1.301 albertel 1987: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1988: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1989:
1.44 ng 1990: if ($button eq 'Save & Next') {
1991: my $ctr = 0;
1992: while ($ctr < $ngrade) {
1.257 albertel 1993: my ($uname,$udom) = split(/:/,$env{'form.unamedom'.$ctr});
1.77 ng 1994: my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
1.71 ng 1995: if ($errorflag eq 'no_score') {
1996: $ctr++;
1997: next;
1998: }
1.104 albertel 1999: if ($errorflag eq 'not_allowed') {
2000: $request->print("<font color=\"red\">Not allowed to modify grades for $uname:$udom</font>");
2001: $ctr++;
2002: next;
2003: }
1.257 albertel 2004: my $includemsg = $env{'form.includemsg'.$ctr};
1.44 ng 2005: my ($subject,$message,$msgstatus) = ('','','');
1.62 albertel 2006: if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
1.298 www 2007: $subject = $env{'form.msgsub'} if ($includemsg =~ /msgsub/);
1.295 www 2008: unless ($subject=~/\w/) { $subject=&mt('Grading Feedback'); }
1.44 ng 2009: my (@msgnum) = split(/,/,$includemsg);
2010: foreach (@msgnum) {
1.257 albertel 2011: $message.=$env{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
1.44 ng 2012: }
1.80 ng 2013: $message =&Apache::lonfeedback::clear_out_html($message);
1.298 www 2014: if ($env{'form.withgrades'.$ctr}) {
2015: $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
2016: $message.=" for <a href=\"".
1.80 ng 2017: &Apache::lonnet::clutter($url).
1.257 albertel 2018: "?symb=$symb\">$env{'form.probTitle'}</a>";
1.298 www 2019: }
1.44 ng 2020: $msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
1.298 www 2021: $subject.' ['.
1.295 www 2022: &Apache::lonnet::declutter($url).']',$message);
1.296 www 2023: $request->print('<br />'.&mt('Sending message to [_1]@[_2]',$uname,$udom).': '.
2024: $msgstatus);
1.44 ng 2025: }
1.257 albertel 2026: if ($env{'form.collaborator'.$ctr}) {
1.155 albertel 2027: my @collabstrs=&Apache::loncommon::get_env_multiple("form.collaborator$ctr");
1.150 albertel 2028: foreach my $collabstr (@collabstrs) {
2029: my ($part,@collaborators) = split(/:/,$collabstr);
1.310 banghart 2030: foreach my $collaborator (@collaborators) {
1.150 albertel 2031: my ($errorflag,$pts,$wgt) =
1.310 banghart 2032: &saveHandGrade($request,$url,$symb,$collaborator,$udom,$ctr,
1.257 albertel 2033: $env{'form.unamedom'.$ctr},$part);
1.150 albertel 2034: if ($errorflag eq 'not_allowed') {
1.310 banghart 2035: $request->print("<font color=\"red\">Not allowed to modify grades for $collaborator:$udom</font>");
1.150 albertel 2036: next;
2037: } else {
2038: if ($message ne '') {
1.310 banghart 2039: $msgstatus = &Apache::lonmsg::user_normal_msg($collaborator,$udom,$env{'form.msgsub'},$message);
1.150 albertel 2040: }
1.104 albertel 2041: }
1.44 ng 2042: }
2043: }
2044: }
2045: $ctr++;
2046: }
2047: }
2048:
1.257 albertel 2049: if ($env{'form.handgrade'} eq 'yes') {
1.119 ng 2050: # Keywords sorted in alphabatical order
1.257 albertel 2051: my $loginuser = $env{'user.name'}.':'.$env{'user.domain'};
1.119 ng 2052: my %keyhash = ();
1.257 albertel 2053: $env{'form.keywords'} =~ s/,\s{0,}|\s+/ /g;
2054: $env{'form.keywords'} =~ s/^\s+|\s+$//;
2055: my (@keywords) = sort(split(/\s+/,$env{'form.keywords'}));
2056: $env{'form.keywords'} = join(' ',@keywords);
2057: $keyhash{$symb.'_keywords'} = $env{'form.keywords'};
2058: $keyhash{$symb.'_subject'} = $env{'form.msgsub'};
2059: $keyhash{$loginuser.'_kwclr'} = $env{'form.kwclr'};
2060: $keyhash{$loginuser.'_kwsize'} = $env{'form.kwsize'};
2061: $keyhash{$loginuser.'_kwstyle'} = $env{'form.kwstyle'};
1.119 ng 2062:
2063: # message center - Order of message gets changed. Blank line is eliminated.
1.257 albertel 2064: # New messages are saved in env for the next student.
1.119 ng 2065: # All messages are saved in nohist_handgrade.db
2066: my ($ctr,$idx) = (1,1);
1.257 albertel 2067: while ($ctr <= $env{'form.savemsgN'}) {
2068: if ($env{'form.savemsg'.$ctr} ne '') {
2069: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.savemsg'.$ctr};
1.119 ng 2070: $idx++;
2071: }
2072: $ctr++;
1.41 ng 2073: }
1.119 ng 2074: $ctr = 0;
2075: while ($ctr < $ngrade) {
1.257 albertel 2076: if ($env{'form.newmsg'.$ctr} ne '') {
2077: $keyhash{$symb.'_savemsg'.$idx} = $env{'form.newmsg'.$ctr};
2078: $env{'form.savemsg'.$idx} = $env{'form.newmsg'.$ctr};
1.119 ng 2079: $idx++;
2080: }
2081: $ctr++;
1.41 ng 2082: }
1.257 albertel 2083: $env{'form.savemsgN'} = --$idx;
2084: $keyhash{$symb.'_savemsgN'} = $env{'form.savemsgN'};
1.119 ng 2085: my $putresult = &Apache::lonnet::put
1.301 albertel 2086: ('nohist_handgrade',\%keyhash,$cdom,$cnum);
1.41 ng 2087: }
1.44 ng 2088: # Called by Save & Refresh from Highlight Attribute Window
1.257 albertel 2089: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
2090: if ($env{'form.refresh'} eq 'on') {
1.86 ng 2091: my ($ctr,$total) = (0,0);
2092: while ($ctr < $ngrade) {
1.257 albertel 2093: $total++ if $env{'form.unamedom'.$ctr} ne '';
1.86 ng 2094: $ctr++;
2095: }
1.257 albertel 2096: $env{'form.NTSTU'}=$ngrade;
1.86 ng 2097: $ctr = 0;
2098: while ($ctr < $total) {
1.257 albertel 2099: my $processUser = $env{'form.unamedom'.$ctr};
2100: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2101: $env{'form.fullname'} = $$fullname{$processUser};
1.86 ng 2102: &submission($request,$ctr,$total-1);
1.41 ng 2103: $ctr++;
2104: }
2105: return '';
2106: }
1.36 ng 2107:
1.121 ng 2108: # Go directly to grade student - from submission or link from chart page
1.120 ng 2109: if ($button eq 'Grade Student') {
1.257 albertel 2110: (undef,undef,$env{'form.handgrade'},undef,undef) = &showResourceInfo($url);
2111: my $processUser = $env{'form.unamedom'.$env{'form.studentNo'}};
2112: ($env{'form.student'},$env{'form.userdom'}) = split(/:/,$processUser);
2113: $env{'form.fullname'} = $$fullname{$processUser};
1.120 ng 2114: &submission($request,0,0);
2115: return '';
2116: }
2117:
1.44 ng 2118: # Get the next/previous one or group of students
1.257 albertel 2119: my $firststu = $env{'form.unamedom0'};
2120: my $laststu = $env{'form.unamedom'.($ngrade-1)};
1.119 ng 2121: my $ctr = 2;
1.41 ng 2122: while ($laststu eq '') {
1.257 albertel 2123: $laststu = $env{'form.unamedom'.($ngrade-$ctr)};
1.41 ng 2124: $ctr++;
2125: $laststu = $firststu if ($ctr > $ngrade);
2126: }
1.44 ng 2127:
1.41 ng 2128: my (@parsedlist,@nextlist);
2129: my ($nextflg) = 0;
1.294 albertel 2130: foreach (sort
2131: {
2132: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2133: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2134: }
2135: return $a cmp $b;
2136: } (keys(%$fullname))) {
1.41 ng 2137: if ($nextflg == 1 && $button =~ /Next$/) {
2138: push @parsedlist,$_;
2139: }
2140: $nextflg = 1 if ($_ eq $laststu);
2141: if ($button eq 'Previous') {
2142: last if ($_ eq $firststu);
2143: push @parsedlist,$_;
2144: }
2145: }
2146: $ctr = 0;
2147: @parsedlist = reverse @parsedlist if ($button eq 'Previous');
1.145 albertel 2148: my ($partlist) = &response_type($url);
1.41 ng 2149: foreach my $student (@parsedlist) {
1.257 albertel 2150: my $submitonly=$env{'form.submitonly'};
1.41 ng 2151: my ($uname,$udom) = split(/:/,$student);
1.301 albertel 2152:
2153: if ($submitonly eq 'queued') {
2154: my %queue_status =
2155: &Apache::bridgetask::get_student_status($symb,$cdom,$cnum,
2156: $udom,$uname);
2157: next if (!defined($queue_status{'gradingqueue'}));
2158: }
2159:
1.156 albertel 2160: if ($submitonly =~ /^(yes|graded|incorrect)$/) {
1.257 albertel 2161: # my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname);
1.145 albertel 2162: my %status=&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
2163: my $submitted = 0;
1.248 albertel 2164: my $ungraded = 0;
2165: my $incorrect = 0;
1.145 albertel 2166: foreach (keys(%status)) {
2167: $submitted = 1 if ($status{$_} ne 'nothing');
1.248 albertel 2168: $ungraded = 1 if ($status{$_} =~ /^ungraded/);
2169: $incorrect = 1 if ($status{$_} =~ /^incorrect/);
1.145 albertel 2170: my ($foo,$partid,$foo1) = split(/\./,$_);
2171: if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
2172: $submitted = 0;
2173: }
1.41 ng 2174: }
1.156 albertel 2175: next if (!$submitted && ($submitonly eq 'yes' ||
2176: $submitonly eq 'incorrect' ||
2177: $submitonly eq 'graded'));
1.248 albertel 2178: next if (!$ungraded && ($submitonly eq 'graded'));
2179: next if (!$incorrect && $submitonly eq 'incorrect');
1.41 ng 2180: }
2181: push @nextlist,$student if ($ctr < $ntstu);
1.129 ng 2182: last if ($ctr == $ntstu);
1.41 ng 2183: $ctr++;
2184: }
1.36 ng 2185:
1.41 ng 2186: $ctr = 0;
2187: my $total = scalar(@nextlist)-1;
1.39 ng 2188:
1.41 ng 2189: foreach (sort @nextlist) {
2190: my ($uname,$udom,$submitter) = split(/:/);
1.257 albertel 2191: $env{'form.student'} = $uname;
2192: $env{'form.userdom'} = $udom;
2193: $env{'form.fullname'} = $$fullname{$_};
1.41 ng 2194: &submission($request,$ctr,$total);
2195: $ctr++;
2196: }
2197: if ($total < 0) {
2198: my $the_end = '<h3><font color="red">LON-CAPA User Message</font></h3><br />'."\n";
2199: $the_end.='<b>Message: </b> No more students for this section or class.<br /><br />'."\n";
2200: $the_end.='Click on the button below to return to the grading menu.<br /><br />'."\n";
1.301 albertel 2201: $the_end.=&show_grading_menu_form($symb,$url);
1.41 ng 2202: $request->print($the_end);
2203: }
2204: return '';
1.38 ng 2205: }
1.36 ng 2206:
1.44 ng 2207: #---- Save the score and award for each student, if changed
1.38 ng 2208: sub saveHandGrade {
1.150 albertel 2209: my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
1.262 banghart 2210: my @v_flag;
1.104 albertel 2211: my $usec = &Apache::lonnet::getsection($domain,$stuname,
1.257 albertel 2212: $env{'request.course.id'});
1.104 albertel 2213: if (!&canmodify($usec)) { return('not_allowed'); }
1.257 albertel 2214: my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$domain,$stuname);
1.251 banghart 2215: my @parts_graded;
1.77 ng 2216: my %newrecord = ();
2217: my ($pts,$wgt) = ('','');
1.269 raeburn 2218: my %aggregate = ();
2219: my $aggregateflag = 0;
1.301 albertel 2220:
2221: my @parts = split(/:/,$env{'form.partlist'.$newflg});
2222: foreach my $new_part (@parts) {
1.150 albertel 2223: #collaborator may vary for different parts
1.259 banghart 2224: if ($submitter && $new_part ne $part) { next; }
2225: my $dropMenu = $env{'form.GD_SEL'.$newflg.'_'.$new_part};
1.125 ng 2226: if ($dropMenu eq 'excused') {
1.259 banghart 2227: if ($record{'resource.'.$new_part.'.solved'} ne 'excused') {
2228: $newrecord{'resource.'.$new_part.'.solved'} = 'excused';
2229: if (exists($record{'resource.'.$new_part.'.awarded'})) {
2230: $newrecord{'resource.'.$new_part.'.awarded'} = '';
1.58 albertel 2231: }
1.259 banghart 2232: $newrecord{'resource.'.$new_part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.58 albertel 2233: }
1.125 ng 2234: } elsif ($dropMenu eq 'reset status'
1.259 banghart 2235: && exists($record{'resource.'.$new_part.'.solved'})) { #don't bother if no old records -> no attempts
1.197 albertel 2236: foreach my $key (keys (%record)) {
1.259 banghart 2237: if ($key=~/^resource\.\Q$new_part\E\./) { $newrecord{$key} = ''; }
1.197 albertel 2238: }
1.259 banghart 2239: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2240: "$env{'user.name'}:$env{'user.domain'}";
1.270 albertel 2241: my $totaltries = $record{'resource.'.$part.'.tries'};
2242:
2243: my %last_resets = &get_last_resets($symb,$env{'request.course.id'},
2244: [$new_part]);
2245: my $aggtries =$totaltries;
1.269 raeburn 2246: if ($last_resets{$new_part}) {
1.270 albertel 2247: $aggtries = &get_num_tries(\%record,$last_resets{$new_part},
2248: $new_part);
1.269 raeburn 2249: }
1.270 albertel 2250:
2251: my $solvedstatus = $record{'resource.'.$new_part.'.solved'};
1.269 raeburn 2252: if ($aggtries > 0) {
2253: &decrement($symb,$new_part,\%aggregate,$aggtries,$totaltries,$solvedstatus);
2254: $aggregateflag = 1;
2255: }
1.125 ng 2256: } elsif ($dropMenu eq '') {
1.259 banghart 2257: $pts = ($env{'form.GD_BOX'.$newflg.'_'.$new_part} ne '' ?
2258: $env{'form.GD_BOX'.$newflg.'_'.$new_part} :
2259: $env{'form.RADVAL'.$newflg.'_'.$new_part});
2260: if ($pts eq '' && $env{'form.GD_SEL'.$newflg.'_'.$new_part} eq '') {
1.153 albertel 2261: next;
2262: }
1.259 banghart 2263: $wgt = $env{'form.WGT'.$newflg.'_'.$new_part} eq '' ? 1 :
2264: $env{'form.WGT'.$newflg.'_'.$new_part};
1.41 ng 2265: my $partial= $pts/$wgt;
1.259 banghart 2266: if ($partial eq $record{'resource.'.$new_part.'.awarded'}) {
1.153 albertel 2267: #do not update score for part if not changed.
2268: next;
1.251 banghart 2269: } else {
1.259 banghart 2270: push @parts_graded, $new_part;
1.153 albertel 2271: }
1.259 banghart 2272: if ($record{'resource.'.$new_part.'.awarded'} ne $partial) {
2273: $newrecord{'resource.'.$new_part.'.awarded'} = $partial;
1.153 albertel 2274: }
1.259 banghart 2275: my $reckey = 'resource.'.$new_part.'.solved';
1.41 ng 2276: if ($partial == 0) {
1.153 albertel 2277: if ($record{$reckey} ne 'incorrect_by_override') {
2278: $newrecord{$reckey} = 'incorrect_by_override';
2279: }
1.41 ng 2280: } else {
1.153 albertel 2281: if ($record{$reckey} ne 'correct_by_override') {
2282: $newrecord{$reckey} = 'correct_by_override';
2283: }
2284: }
2285: if ($submitter &&
1.259 banghart 2286: ($record{'resource.'.$new_part.'.submitted_by'} ne $submitter)) {
2287: $newrecord{'resource.'.$new_part.'.submitted_by'} = $submitter;
1.41 ng 2288: }
1.259 banghart 2289: $newrecord{'resource.'.$new_part.'.regrader'}=
1.257 albertel 2290: "$env{'user.name'}:$env{'user.domain'}";
1.41 ng 2291: }
1.310 banghart 2292: if ($env{'form.part'.$new_part.'_returndoc1'}) {
1.311 banghart 2293: # if multiple files are uploaded names will be 'returndoc2','returndoc3'
2294:
1.310 banghart 2295: my $portfolio_root = &Apache::loncommon::propath($domain,
2296: $stuname).
2297: '/userfiles/portfolio';
2298: $request->print('<br>'.$portfolio_root.'<br>');
1.311 banghart 2299:
1.310 banghart 2300: # my $result=&Apache::lonnet::userfileupload('uploaddoc','',
2301: # 'portfolio'.$env{'form.currentpath'});
2302:
2303: my $file_counter = 1;
1.312 banghart 2304: my $respid = $env{'form.respid'};
1.311 banghart 2305: while ($env{'form.part'.$new_part.'_returndoc'.$file_counter}) {
1.310 banghart 2306: my $fname=$env{'form.returndoc'.$file_counter.'.filename'};
1.312 banghart 2307: $newrecord{"resource.$new_part.$respid.handback"} = $env{'form.returndocorig'.$file_counter};
1.310 banghart 2308: $request->print("<br />".$fname." will be the uploaded file name");
2309: $request->print("<font color=\"red\">Will upload document</font>".$env{'form.returndocorig'.$file_counter});
2310: $file_counter++;
2311: }
2312: }
2313:
1.259 banghart 2314: # unless problem has been graded, set flag to version the submitted files
1.305 banghart 2315: unless ($record{'resource.'.$new_part.'.solved'} =~ /^correct_/ ||
2316: $record{'resource.'.$new_part.'.solved'} eq 'incorrect_by_override' ||
2317: $dropMenu eq 'reset status')
2318: {
1.262 banghart 2319: push (@v_flag,$new_part);
1.259 banghart 2320: }
1.41 ng 2321: }
1.301 albertel 2322: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2323: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2324:
1.44 ng 2325: if (scalar(keys(%newrecord)) > 0) {
1.263 banghart 2326: if (scalar(@v_flag)) {
2327: &version_portfiles(\%record, \@parts_graded, $env{'request.course.id'}, $symb, $domain, $stuname, \@v_flag);
1.259 banghart 2328: }
1.44 ng 2329: &Apache::lonnet::cstore(\%newrecord,$symb,
1.257 albertel 2330: $env{'request.course.id'},$domain,$stuname);
1.301 albertel 2331:
2332: my @ungraded_parts;
2333: foreach my $part (@parts) {
2334: if ( !defined($record{'resource.'.$part.'.awarded'})
2335: && !defined($newrecord{'resource.'.$part.'.awarded'}) ) {
2336: push(@ungraded_parts, $part);
2337: }
2338: }
2339: if ( !@ungraded_parts ) {
2340: &Apache::bridgetask::remove_from_queue('gradingqueue',$symb,$cdom,
2341: $cnum,$domain,$stuname);
2342: }
1.41 ng 2343: }
1.269 raeburn 2344: if ($aggregateflag) {
2345: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 2346: $cdom,$cnum);
1.269 raeburn 2347: }
1.301 albertel 2348: return ('',$pts,$wgt);
1.36 ng 2349: }
1.313 ! banghart 2350: sub get_submitted_files {
! 2351: my ($udom,$uname,$partid,$respid,$record) = @_;
! 2352: my @files;
! 2353: if ($$record{"resource.$partid.$respid.portfiles"}) {
! 2354: my $file_url = '/uploaded/'.$udom.'/'.$uname.'/portfolio';
! 2355: foreach my $file (split(',',$$record{"resource.$partid.$respid.portfiles"})) {
! 2356: push(@files,$file_url.$file);
! 2357: }
! 2358: }
! 2359: if ($$record{"resource.$partid.$respid.uploadedurl"}) {
! 2360: push(@files,$$record{"resource.$partid.$respid.uploadedurl"});
! 2361: }
! 2362: return (\@files);
! 2363: }
1.269 raeburn 2364: # ----------- Provides number of tries since last reset.
2365: sub get_num_tries {
2366: my ($record,$last_reset,$part) = @_;
2367: my $timestamp = '';
2368: my $num_tries = 0;
2369: if ($$record{'version'}) {
2370: for (my $version=$$record{'version'};$version>=1;$version--) {
2371: if (exists($$record{$version.':resource.'.$part.'.solved'})) {
2372: $timestamp = $$record{$version.':timestamp'};
2373: if ($timestamp > $last_reset) {
2374: $num_tries ++;
2375: } else {
2376: last;
2377: }
2378: }
2379: }
2380: }
2381: return $num_tries;
2382: }
2383:
2384: # ----------- Determine decrements required in aggregate totals
2385: sub decrement_aggs {
2386: my ($symb,$part,$aggregate,$aggtries,$totaltries,$solvedstatus) = @_;
2387: my %decrement = (
2388: attempts => 0,
2389: users => 0,
2390: correct => 0
2391: );
2392: $decrement{'attempts'} = $aggtries;
2393: if ($solvedstatus =~ /^correct/) {
2394: $decrement{'correct'} = 1;
2395: }
2396: if ($aggtries == $totaltries) {
2397: $decrement{'users'} = 1;
2398: }
2399: foreach my $type (keys (%decrement)) {
2400: $$aggregate{$symb."\0".$part."\0".$type} = -$decrement{$type};
2401: }
2402: return;
2403: }
2404:
2405: # ----------- Determine timestamps for last reset of aggregate totals for parts
2406: sub get_last_resets {
1.270 albertel 2407: my ($symb,$courseid,$partids) =@_;
2408: my %last_resets;
1.269 raeburn 2409: my $cdom = $env{'course.'.$courseid.'.domain'};
2410: my $cname = $env{'course.'.$courseid.'.num'};
1.271 albertel 2411: my @keys;
2412: foreach my $part (@{$partids}) {
2413: push(@keys,"$symb\0$part\0resettime");
2414: }
2415: my %results=&Apache::lonnet::get('nohist_resourcetracker',\@keys,
2416: $cdom,$cname);
2417: foreach my $part (@{$partids}) {
2418: $last_resets{$part}=$results{"$symb\0$part\0resettime"};
1.269 raeburn 2419: }
1.270 albertel 2420: return %last_resets;
1.269 raeburn 2421: }
2422:
1.251 banghart 2423: # ----------- Handles creating versions for portfolio files as answers
2424: sub version_portfiles {
1.306 banghart 2425: my ($record, $parts_graded, $courseid, $symb, $domain, $stu_name, $v_flag) = @_;
1.263 banghart 2426: my $version_parts = join('|',@$v_flag);
1.255 banghart 2427: my $parts = join('|', @$parts_graded);
1.252 banghart 2428: my $portfolio_root = &Apache::loncommon::propath($domain,
1.306 banghart 2429: $stu_name).
1.252 banghart 2430: '/userfiles/portfolio';
1.277 albertel 2431: foreach my $key (keys(%$record)) {
1.259 banghart 2432: my $new_portfiles;
1.263 banghart 2433: if ($key =~ /^resource\.($version_parts)\./ && $key =~ /\.portfiles$/ ) {
1.259 banghart 2434: my @v_portfiles;
1.255 banghart 2435: my @portfiles = split(/,/,$$record{$key});
1.252 banghart 2436: foreach my $file (@portfiles) {
1.306 banghart 2437: &Apache::lonnet::unmark_as_readonly($domain,$stu_name,[$symb,$env{'request.course.id'}],$file);
1.304 albertel 2438: my ($directory,$answer_file) =($file =~ /^(.*?)([^\/]*)$/);
1.252 banghart 2439: my $version = 0;
1.304 albertel 2440: my ($answer_name,$answer_ver,$answer_ext) =
2441: &file_name_version_ext($answer_file);
1.306 banghart 2442: my @dir_list = &Apache::lonnet::dirlist($directory,$domain,$stu_name,$portfolio_root);
1.307 banghart 2443: $version = &get_next_version($answer_name, $answer_ext, \@dir_list);
1.306 banghart 2444: my $new_answer = &version_selected_portfile($domain, $stu_name, $directory, $answer_file, $version);
2445: if ($new_answer ne 'problem getting file') {
1.304 albertel 2446: push(@v_portfiles, $directory.$new_answer);
1.306 banghart 2447: &Apache::lonnet::mark_as_readonly($domain,$stu_name,
2448: ['/portfolio'.$directory.$new_answer],
2449: [$symb,$env{'request.course.id'},'graded']);
1.259 banghart 2450: }
1.306 banghart 2451:
1.252 banghart 2452: }
1.261 albertel 2453: $$record{$key} = join(',',@v_portfiles);
1.251 banghart 2454: }
2455: }
1.259 banghart 2456: return 'ok';
1.305 banghart 2457: }
2458:
1.307 banghart 2459: sub get_next_version {
2460: my ($answer_name, $answer_ext, $dir_list);
2461: my $version;
2462: foreach my $row (@$dir_list) {
2463: my ($file) = split(/\&/,$row,2);
2464: my ($file_name,$file_version,$file_ext) =
2465: &file_name_version_ext($file);
2466: if (($file_name eq $answer_name) &&
2467: ($file_ext eq $answer_ext)) {
2468: # gets here if filename and extension match, regardless of version
2469: if ($file_version ne '') {
2470: # a versioned file is found so save it for later
2471: if ($file_version > $version) {
2472: $version = $file_version;
2473: }
2474: }
2475: }
2476: }
2477: $version ++;
2478: return($version);
2479: }
2480:
1.305 banghart 2481: sub version_selected_portfile {
1.306 banghart 2482: my ($domain,$stu_name,$directory,$file_name,$version) = @_;
2483: my ($answer_name,$answer_ver,$answer_ext) =
2484: &file_name_version_ext($file_name);
2485: my $new_answer;
2486: $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name");
2487: if($env{'form.copy'} eq '-1') {
2488: &Apache::lonnet::logthis('problem getting file '.$file_name);
2489: $new_answer = 'problem getting file';
2490: } else {
2491: $new_answer = $answer_name.'.'.$version.'.'.$answer_ext;
2492: my $copy_result = &Apache::lonnet::finishuserfileupload(
2493: $stu_name,$domain,'copy',
2494: '/portfolio'.$directory.$new_answer);
2495: }
2496: return ($new_answer);
1.251 banghart 2497: }
2498:
1.304 albertel 2499: sub file_name_version_ext {
2500: my ($file)=@_;
2501: my @file_parts = split(/\./, $file);
2502: my ($name,$version,$ext);
2503: if (@file_parts > 1) {
2504: $ext=pop(@file_parts);
2505: if (@file_parts > 1 && $file_parts[-1] =~ /^\d+$/) {
2506: $version=pop(@file_parts);
2507: }
2508: $name=join('.',@file_parts);
2509: } else {
2510: $name=join('.',@file_parts);
2511: }
2512: return($name,$version,$ext);
2513: }
2514:
1.44 ng 2515: #--------------------------------------------------------------------------------------
2516: #
2517: #-------------------------- Next few routines handles grading by section or whole class
2518: #
2519: #--- Javascript to handle grading by section or whole class
1.42 ng 2520: sub viewgrades_js {
2521: my ($request) = shift;
2522:
1.41 ng 2523: $request->print(<<VIEWJAVASCRIPT);
2524: <script type="text/javascript" language="javascript">
1.45 ng 2525: function writePoint(partid,weight,point) {
1.125 ng 2526: var radioButton = document.classgrade["RADVAL_"+partid];
2527: var textbox = document.classgrade["TEXTVAL_"+partid];
1.42 ng 2528: if (point == "textval") {
1.125 ng 2529: point = document.classgrade["TEXTVAL_"+partid].value;
1.109 matthew 2530: if (isNaN(point) || parseFloat(point) < 0) {
2531: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.42 ng 2532: var resetbox = false;
2533: for (var i=0; i<radioButton.length; i++) {
2534: if (radioButton[i].checked) {
2535: textbox.value = i;
2536: resetbox = true;
2537: }
2538: }
2539: if (!resetbox) {
2540: textbox.value = "";
2541: }
2542: return;
2543: }
1.109 matthew 2544: if (parseFloat(point) > parseFloat(weight)) {
2545: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2546: ") greater than the weight for the part. Accept?");
2547: if (resp == false) {
2548: textbox.value = "";
2549: return;
2550: }
2551: }
1.42 ng 2552: for (var i=0; i<radioButton.length; i++) {
2553: radioButton[i].checked=false;
1.109 matthew 2554: if (parseFloat(point) == i) {
1.42 ng 2555: radioButton[i].checked=true;
2556: }
2557: }
1.41 ng 2558:
1.42 ng 2559: } else {
1.125 ng 2560: textbox.value = parseFloat(point);
1.42 ng 2561: }
1.41 ng 2562: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2563: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2564: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2565: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2566: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2567: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2568: if (saveval != "correct") {
2569: scorename.value = point;
1.43 ng 2570: if (selname[0].selected != true) {
2571: selname[0].selected = true;
2572: }
1.42 ng 2573: }
2574: }
1.125 ng 2575: document.classgrade["SELVAL_"+partid][0].selected = true;
1.42 ng 2576: }
2577:
2578: function writeRadText(partid,weight) {
1.125 ng 2579: var selval = document.classgrade["SELVAL_"+partid];
2580: var radioButton = document.classgrade["RADVAL_"+partid];
1.265 www 2581: var override = document.classgrade["FORCE_"+partid].checked;
1.125 ng 2582: var textbox = document.classgrade["TEXTVAL_"+partid];
2583: if (selval[1].selected || selval[2].selected) {
1.42 ng 2584: for (var i=0; i<radioButton.length; i++) {
2585: radioButton[i].checked=false;
2586:
2587: }
2588: textbox.value = "";
2589:
2590: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2591: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2592: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2593: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2594: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2595: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2596: if ((saveval != "correct") || override) {
1.42 ng 2597: scorename.value = "";
1.125 ng 2598: if (selval[1].selected) {
2599: selname[1].selected = true;
2600: } else {
2601: selname[2].selected = true;
2602: if (Number(document.classgrade["GD_"+user+"_"+partid+"_tries"].value))
2603: {document.classgrade["GD_"+user+"_"+partid+"_tries"].value = '0';}
2604: }
1.42 ng 2605: }
2606: }
1.43 ng 2607: } else {
2608: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2609: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2610: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2611: var scorename = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2612: var saveval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2613: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.265 www 2614: if ((saveval != "correct") || override) {
1.125 ng 2615: scorename.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
1.43 ng 2616: selname[0].selected = true;
2617: }
2618: }
2619: }
1.42 ng 2620: }
2621:
2622: function changeSelect(partid,user) {
1.125 ng 2623: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2624: var textbox = document.classgrade["GD_"+user+'_'+partid+"_awarded"];
1.44 ng 2625: var point = textbox.value;
1.125 ng 2626: var weight = document.classgrade["weight_"+partid].value;
1.44 ng 2627:
1.109 matthew 2628: if (isNaN(point) || parseFloat(point) < 0) {
2629: alert("A number equal or greater than 0 is expected. Entered value = "+parseFloat(point));
1.44 ng 2630: textbox.value = "";
2631: return;
2632: }
1.109 matthew 2633: if (parseFloat(point) > parseFloat(weight)) {
2634: var resp = confirm("You entered a value ("+parseFloat(point)+
1.44 ng 2635: ") greater than the weight of the part. Accept?");
2636: if (resp == false) {
2637: textbox.value = "";
2638: return;
2639: }
2640: }
1.42 ng 2641: selval[0].selected = true;
2642: }
2643:
2644: function changeOneScore(partid,user) {
1.125 ng 2645: var selval = document.classgrade["GD_"+user+'_'+partid+"_solved"];
2646: if (selval[1].selected || selval[2].selected) {
2647: document.classgrade["GD_"+user+'_'+partid+"_awarded"].value = "";
2648: if (selval[2].selected) {
2649: document.classgrade["GD_"+user+'_'+partid+"_tries"].value = "0";
2650: }
1.269 raeburn 2651: }
1.42 ng 2652: }
2653:
2654: function resetEntry(numpart) {
2655: for (ctpart=0;ctpart<numpart;ctpart++) {
1.125 ng 2656: var partid = document.classgrade["partid_"+ctpart].value;
2657: var radioButton = document.classgrade["RADVAL_"+partid];
2658: var textbox = document.classgrade["TEXTVAL_"+partid];
2659: var selval = document.classgrade["SELVAL_"+partid];
1.42 ng 2660: for (var i=0; i<radioButton.length; i++) {
2661: radioButton[i].checked=false;
2662:
2663: }
2664: textbox.value = "";
2665: selval[0].selected = true;
2666:
2667: for (i=0;i<document.classgrade.total.value;i++) {
1.125 ng 2668: var user = document.classgrade["ctr"+i].value;
1.289 albertel 2669: user = user.replace(new RegExp(':', 'g'),"_");
1.125 ng 2670: var resetscore = document.classgrade["GD_"+user+"_"+partid+"_awarded"];
2671: resetscore.value = document.classgrade["GD_"+user+"_"+partid+"_awarded_s"].value;
2672: var resettries = document.classgrade["GD_"+user+"_"+partid+"_tries"];
2673: resettries.value = document.classgrade["GD_"+user+"_"+partid+"_tries_s"].value;
2674: var saveselval = document.classgrade["GD_"+user+"_"+partid+"_solved_s"].value;
2675: var selname = document.classgrade["GD_"+user+"_"+partid+"_solved"];
1.42 ng 2676: if (saveselval == "excused") {
1.43 ng 2677: if (selname[1].selected == false) { selname[1].selected = true;}
1.42 ng 2678: } else {
1.43 ng 2679: if (selname[0].selected == false) {selname[0].selected = true};
1.42 ng 2680: }
2681: }
1.41 ng 2682: }
1.42 ng 2683: }
2684:
1.41 ng 2685: </script>
2686: VIEWJAVASCRIPT
1.42 ng 2687: }
2688:
1.44 ng 2689: #--- show scores for a section or whole class w/ option to change/update a score
1.42 ng 2690: sub viewgrades {
2691: my ($request) = shift;
2692: &viewgrades_js($request);
1.41 ng 2693:
1.257 albertel 2694: my ($symb,$url) = ($env{'form.symb'},$env{'form.url'});
1.168 albertel 2695: #need to make sure we have the correct data for later EXT calls,
2696: #thus invalidate the cache
2697: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 2698: $env{'course.'.$env{'request.course.id'}.'.num'},
2699: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 2700: &Apache::lonnet::clear_EXT_cache_status();
2701:
1.167 sakharuk 2702: my $result='<h3><font color="#339933">'.&mt('Manual Grading').'</font></h3>';
1.257 albertel 2703: $result.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font>'."\n";
1.41 ng 2704:
2705: #view individual student submission form - called using Javascript viewOneStudent
1.45 ng 2706: $result.=&jscriptNform($url,$symb);
1.41 ng 2707:
1.44 ng 2708: #beginning of class grading form
1.41 ng 2709: $result.= '<form action="/adm/grades" method="post" name="classgrade">'."\n".
1.106 albertel 2710: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.41 ng 2711: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.38 ng 2712: '<input type="hidden" name="command" value="editgrades" />'."\n".
1.257 albertel 2713: '<input type="hidden" name="section" value="'.$env{'form.section'}.'" />'."\n".
2714: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
2715: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
2716: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.72 ng 2717:
1.126 ng 2718: my $sectionClass;
1.257 albertel 2719: if ($env{'form.section'} eq 'all') {
1.126 ng 2720: $sectionClass='Class </h3>';
1.257 albertel 2721: } elsif ($env{'form.section'} eq 'none') {
1.126 ng 2722: $sectionClass='Students in no Section </h3>';
1.52 albertel 2723: } else {
1.257 albertel 2724: $sectionClass='Students in Section '.$env{'form.section'}.'</h3>';
1.52 albertel 2725: }
1.126 ng 2726: $result.='<h3>Assign Common Grade To '.$sectionClass;
1.52 albertel 2727: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
2728: '<table border=0><tr bgcolor="#ffffdd"><td>';
1.44 ng 2729: #radio buttons/text box for assigning points for a section or class.
2730: #handles different parts of a problem
1.125 ng 2731: my ($partlist,$handgrade) = &response_type($url,$symb);
1.42 ng 2732: my %weight = ();
2733: my $ctsparts = 0;
1.41 ng 2734: $result.='<table border="0">';
1.45 ng 2735: my %seen = ();
1.42 ng 2736: for (sort keys(%$handgrade)) {
1.54 albertel 2737: my ($partid,$respid) = split (/_/,$_,2);
1.45 ng 2738: next if $seen{$partid};
2739: $seen{$partid}++;
1.147 albertel 2740: my $handgrade=$$handgrade{$_};
1.42 ng 2741: my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
2742: $weight{$partid} = $wgt eq '' ? '1' : $wgt;
2743:
1.44 ng 2744: $result.='<input type="hidden" name="partid_'.
2745: $ctsparts.'" value="'.$partid.'" />'."\n";
2746: $result.='<input type="hidden" name="weight_'.
2747: $partid.'" value="'.$weight{$partid}.'" />'."\n";
1.207 albertel 2748: my $display_part=&get_display_part($partid,$url,$symb);
2749: $result.='<tr><td><b>Part:</b> '.$display_part.' <b>Point:</b> </td><td>';
1.42 ng 2750: $result.='<table border="0"><tr>';
1.41 ng 2751: my $ctr = 0;
1.42 ng 2752: while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
1.288 albertel 2753: $result.= '<td><label><input type="radio" name="RADVAL_'.$partid.'" '.
1.54 albertel 2754: 'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
1.288 albertel 2755: ','.$ctr.')" />'.$ctr."</label></td>\n";
1.41 ng 2756: $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
2757: $ctr++;
2758: }
2759: $result.='</tr></table>';
1.44 ng 2760: $result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
1.54 albertel 2761: $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
2762: $partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
1.42 ng 2763: $weight{$partid}.' (problem weight)</td>'."\n";
2764: $result.= '</td><td><select name="SELVAL_'.$partid.'"'.
1.54 albertel 2765: 'onChange="javascript:writeRadText(\''.$partid.'\','.
1.59 albertel 2766: $weight{$partid}.')"> '.
1.42 ng 2767: '<option selected="on"> </option>'.
1.125 ng 2768: '<option>excused</option>'.
1.265 www 2769: '<option>reset status</option></select></td>'.
1.266 albertel 2770: '<td><label><input type="checkbox" name="FORCE_'.$partid.'" /> Override "Correct"</label></td></tr>'."\n";
1.42 ng 2771: $ctsparts++;
1.41 ng 2772: }
1.52 albertel 2773: $result.='</table>'.'</td></tr></table>'.'</td></tr></table>'."\n".
2774: '<input type="hidden" name="totalparts" value="'.$ctsparts.'" />';
1.42 ng 2775: $result.='<input type="button" value="Reset" '.
1.111 ng 2776: 'onClick="javascript:resetEntry('.$ctsparts.');" TARGET=_self>';
1.41 ng 2777:
1.44 ng 2778: #table listing all the students in a section/class
2779: #header of table
1.126 ng 2780: $result.= '<h3>Assign Grade to Specific Students in '.$sectionClass;
1.42 ng 2781: $result.= '<table border=0><tr><td bgcolor="#777777">'."\n".
1.126 ng 2782: '<table border=0><tr bgcolor="#deffff"><td> <b>No.</b> </td>'.
1.129 ng 2783: '<td>'.&nameUserString('header')."</td>\n";
1.146 albertel 2784: my (@parts) = sort(&getpartlist($url,$symb));
1.269 raeburn 2785: my @partids = ();
1.41 ng 2786: foreach my $part (@parts) {
2787: my $display=&Apache::lonnet::metadata($url,$part.'.display');
1.126 ng 2788: $display =~ s|^Number of Attempts|Tries<br />|; # makes the column narrower
1.41 ng 2789: if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
1.207 albertel 2790: my ($partid) = &split_part_type($part);
1.269 raeburn 2791: push(@partids, $partid);
1.207 albertel 2792: my $display_part=&get_display_part($partid,$url,$symb);
1.41 ng 2793: if ($display =~ /^Partial Credit Factor/) {
1.207 albertel 2794: $result.='<td><b>Score Part:</b> '.$display_part.
2795: ' <br /><b>(weight = '.$weight{$partid}.')</b></td>'."\n";
1.41 ng 2796: next;
1.207 albertel 2797: } else {
2798: $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/;
1.41 ng 2799: }
1.53 albertel 2800: $display =~ s|Problem Status|Grade Status<br />|;
1.207 albertel 2801: $result.='<td><b>'.$display.'</td>'."\n";
1.41 ng 2802: }
2803: $result.='</tr>';
1.44 ng 2804:
1.270 albertel 2805: my %last_resets =
2806: &get_last_resets($symb,$env{'request.course.id'},\@partids);
1.269 raeburn 2807:
1.41 ng 2808: #get info for each student
1.44 ng 2809: #list all the students - with points and grade status
1.257 albertel 2810: my (undef,undef,$fullname) = &getclasslist($env{'form.section'},'1');
1.41 ng 2811: my $ctr = 0;
1.294 albertel 2812: foreach (sort
2813: {
2814: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
2815: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
2816: }
2817: return $a cmp $b;
2818: } (keys(%$fullname))) {
1.126 ng 2819: $ctr++;
1.257 albertel 2820: $result.=&viewstudentgrade($url,$symb,$env{'request.course.id'},
1.269 raeburn 2821: $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets);
1.41 ng 2822: }
2823: $result.='</table></td></tr></table>';
2824: $result.='<input type="hidden" name="total" value="'.$ctr.'" />'."\n";
1.126 ng 2825: $result.='<input type="button" value="Save" '.
1.45 ng 2826: 'onClick="javascript:submit();" TARGET=_self /></form>'."\n";
1.96 albertel 2827: if (scalar(%$fullname) eq 0) {
2828: my $colspan=3+scalar(@parts);
1.257 albertel 2829: $result='<font color="red">There are no students in section "'.$env{'form.section'}.
2830: '" with enrollment status "'.$env{'form.Status'}.'" to modify or grade.</font>';
1.96 albertel 2831: }
1.41 ng 2832: $result.=&show_grading_menu_form($symb,$url);
2833: return $result;
2834: }
2835:
1.44 ng 2836: #--- call by previous routine to display each student
1.41 ng 2837: sub viewstudentgrade {
1.269 raeburn 2838: my ($url,$symb,$courseid,$student,$fullname,$parts,$weight,$ctr,$last_resets) = @_;
1.44 ng 2839: my ($uname,$udom) = split(/:/,$student);
2840: my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname);
1.269 raeburn 2841: my %aggregates = ();
1.233 albertel 2842: my $result='<tr bgcolor="#ffffdd"><td align="right">'.
2843: '<input type="hidden" name="ctr'.($ctr-1).'" value="'.$student.'" />'.
2844: "\n".$ctr.' </td><td> '.
1.44 ng 2845: '<a href="javascript:viewOneStudent(\''.$uname.'\',\''.$udom.
1.112 ng 2846: '\')"; TARGET=_self>'.$fullname.'</a> '.
1.257 albertel 2847: '<font color="#999999">('.$uname.($env{'user.domain'} eq $udom ? '' : ':'.$udom).')</font></td>'."\n";
1.281 albertel 2848: $student=~s/:/_/; # colon doen't work in javascript for names
1.63 albertel 2849: foreach my $apart (@$parts) {
2850: my ($part,$type) = &split_part_type($apart);
1.41 ng 2851: my $score=$record{"resource.$part.$type"};
1.276 albertel 2852: $result.='<td align="center">';
1.269 raeburn 2853: my ($aggtries,$totaltries);
2854: unless (exists($aggregates{$part})) {
1.270 albertel 2855: $totaltries = $record{'resource.'.$part.'.tries'};
2856:
2857: $aggtries = $totaltries;
1.269 raeburn 2858: if ($$last_resets{$part}) {
1.270 albertel 2859: $aggtries = &get_num_tries(\%record,$$last_resets{$part},
2860: $part);
2861: }
1.269 raeburn 2862: $result.='<input type="hidden" name="'.
2863: 'GD_'.$student.'_'.$part.'_aggtries" value="'.$aggtries.'" />'."\n";
2864: $result.='<input type="hidden" name="'.
2865: 'GD_'.$student.'_'.$part.'_totaltries" value="'.$totaltries.'" />'."\n";
2866: $aggregates{$part} = 1;
2867: }
1.41 ng 2868: if ($type eq 'awarded') {
1.42 ng 2869: my $pts = $score eq '' ? '' : $score*$$weight{$part};
2870: $result.='<input type="hidden" name="'.
1.89 albertel 2871: 'GD_'.$student.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
1.233 albertel 2872: $result.='<input type="text" name="'.
1.89 albertel 2873: 'GD_'.$student.'_'.$part.'_awarded" '.
2874: 'onChange="javascript:changeSelect(\''.$part.'\',\''.$student.
1.44 ng 2875: '\')" value="'.$pts.'" size="4" /></td>'."\n";
1.41 ng 2876: } elsif ($type eq 'solved') {
2877: my ($status,$foo)=split(/_/,$score,2);
2878: $status = 'nothing' if ($status eq '');
1.89 albertel 2879: $result.='<input type="hidden" name="'.'GD_'.$student.'_'.
1.54 albertel 2880: $part.'_solved_s" value="'.$status.'" />'."\n";
1.233 albertel 2881: $result.=' <select name="'.
1.89 albertel 2882: 'GD_'.$student.'_'.$part.'_solved" '.
2883: 'onChange="javascript:changeOneScore(\''.$part.'\',\''.$student.'\')" >'."\n";
1.125 ng 2884: $result.= (($status eq 'excused') ? '<option> </option><option selected="on">excused</option>'
2885: : '<option selected="on"> </option><option>excused</option>')."\n";
2886: $result.='<option>reset status</option>';
1.126 ng 2887: $result.="</select> </td>\n";
1.122 ng 2888: } else {
2889: $result.='<input type="hidden" name="'.
2890: 'GD_'.$student.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
2891: "\n";
1.233 albertel 2892: $result.='<input type="text" name="'.
1.122 ng 2893: 'GD_'.$student.'_'.$part.'_'.$type.'" '.
2894: 'value="'.$score.'" size="4" /></td>'."\n";
1.41 ng 2895: }
2896: }
2897: $result.='</tr>';
2898: return $result;
1.38 ng 2899: }
2900:
1.44 ng 2901: #--- change scores for all the students in a section/class
2902: # record does not get update if unchanged
1.38 ng 2903: sub editgrades {
1.41 ng 2904: my ($request) = @_;
2905:
1.257 albertel 2906: my $symb=$env{'form.symb'};
2907: my $url =$env{'form.url'};
1.45 ng 2908: my $title='<h3><font color="#339933">Current Grade Status</font></h3>';
1.257 albertel 2909: $title.='<font size=+1><b>Current Resource: </b>'.$env{'form.probTitle'}.'</font><br />'."\n";
2910: $title.='<font size=+1><b>Section: </b>'.$env{'form.section'}.'</font>'."\n";
1.126 ng 2911:
1.44 ng 2912: my $result= '<table border="0"><tr><td bgcolor="#777777">'."\n";
1.129 ng 2913: $result.= '<table border="0"><tr bgcolor="#deffff">'.
2914: '<td rowspan=2 valign="center"> <b>No.</b> </td>'.
2915: '<td rowspan=2 valign="center">'.&nameUserString('header')."</td>\n";
1.43 ng 2916:
2917: my %scoreptr = (
2918: 'correct' =>'correct_by_override',
2919: 'incorrect'=>'incorrect_by_override',
2920: 'excused' =>'excused',
2921: 'ungraded' =>'ungraded_attempted',
2922: 'nothing' => '',
2923: );
1.257 albertel 2924: my ($classlist,undef,$fullname) = &getclasslist($env{'form.section'},'0');
1.34 ng 2925:
1.44 ng 2926: my (@partid);
2927: my %weight = ();
1.54 albertel 2928: my %columns = ();
1.44 ng 2929: my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
1.54 albertel 2930:
1.146 albertel 2931: my (@parts) = sort(&getpartlist($url,$symb));
1.54 albertel 2932: my $header;
1.257 albertel 2933: while ($ctr < $env{'form.totalparts'}) {
2934: my $partid = $env{'form.partid_'.$ctr};
1.44 ng 2935: push @partid,$partid;
1.257 albertel 2936: $weight{$partid} = $env{'form.weight_'.$partid};
1.44 ng 2937: $ctr++;
1.54 albertel 2938: }
2939: foreach my $partid (@partid) {
2940: $header .= '<td align="center"> <b>Old Score</b> </td>'.
2941: '<td align="center"> <b>New Score</b> </td>';
2942: $columns{$partid}=2;
2943: foreach my $stores (@parts) {
2944: my ($part,$type) = &split_part_type($stores);
2945: if ($part !~ m/^\Q$partid\E/) { next;}
2946: if ($type eq 'awarded' || $type eq 'solved') { next; }
2947: my $display=&Apache::lonnet::metadata($url,$stores.'.display');
2948: $display =~ s/\[Part: (\w)+\]//;
1.125 ng 2949: $display =~ s/Number of Attempts/Tries/;
2950: $header .= '<td align="center"> <b>Old '.$display.'</b> </td>'.
2951: '<td align="center"> <b>New '.$display.'</b> </td>';
1.54 albertel 2952: $columns{$partid}+=2;
2953: }
2954: }
2955: foreach my $partid (@partid) {
1.207 albertel 2956: my $display_part=&get_display_part($partid,$url,$symb);
1.54 albertel 2957: $result .= '<td colspan="'.$columns{$partid}.
1.207 albertel 2958: '" align="center"><b>Part:</b> '.$display_part.
2959: ' (Weight = '.$weight{$partid}.')</td>';
1.54 albertel 2960:
1.44 ng 2961: }
2962: $result .= '</tr><tr bgcolor="#deffff">';
1.54 albertel 2963: $result .= $header;
1.44 ng 2964: $result .= '</tr>'."\n";
1.93 albertel 2965: my $noupdate;
1.126 ng 2966: my ($updateCtr,$noupdateCtr) = (1,1);
1.257 albertel 2967: for ($i=0; $i<$env{'form.total'}; $i++) {
1.93 albertel 2968: my $line;
1.257 albertel 2969: my $user = $env{'form.ctr'.$i};
1.281 albertel 2970: my ($uname,$udom)=split(/:/,$user);
1.44 ng 2971: my %newrecord;
2972: my $updateflag = 0;
1.281 albertel 2973: $line .= '<td>'.&nameUserString(undef,$$fullname{$user},$uname,$udom).'</td>';
1.108 albertel 2974: my $usec=$classlist->{"$uname:$udom"}[5];
1.105 albertel 2975: if (!&canmodify($usec)) {
1.126 ng 2976: my $numcols=scalar(@partid)*4+2;
1.105 albertel 2977: $noupdate.=$line."<td colspan=\"$numcols\"><font color=\"red\">Not allowed to modify student</font></td></tr>";
2978: next;
2979: }
1.269 raeburn 2980: my %aggregate = ();
2981: my $aggregateflag = 0;
1.281 albertel 2982: $user=~s/:/_/; # colon doen't work in javascript for names
1.44 ng 2983: foreach (@partid) {
1.257 albertel 2984: my $old_aw = $env{'form.GD_'.$user.'_'.$_.'_awarded_s'};
1.54 albertel 2985: my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
2986: my $old_part = $old_aw eq '' ? '' : $old_part_pcr;
1.257 albertel 2987: my $old_score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
2988: my $awarded = $env{'form.GD_'.$user.'_'.$_.'_awarded'};
1.54 albertel 2989: my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
2990: my $partial = $awarded eq '' ? '' : $pcr;
1.44 ng 2991: my $score;
2992: if ($partial eq '') {
1.257 albertel 2993: $score = $scoreptr{$env{'form.GD_'.$user.'_'.$_.'_solved_s'}};
1.44 ng 2994: } elsif ($partial > 0) {
2995: $score = 'correct_by_override';
2996: } elsif ($partial == 0) {
2997: $score = 'incorrect_by_override';
2998: }
1.257 albertel 2999: my $dropMenu = $env{'form.GD_'.$user.'_'.$_.'_solved'};
1.125 ng 3000: $score = 'excused' if (($dropMenu eq 'excused') && ($score ne 'excused'));
3001:
1.292 albertel 3002: $newrecord{'resource.'.$_.'.regrader'}=
3003: "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3004: if ($dropMenu eq 'reset status' &&
3005: $old_score ne '') { # ignore if no previous attempts => nothing to reset
1.299 albertel 3006: $newrecord{'resource.'.$_.'.tries'} = '';
1.125 ng 3007: $newrecord{'resource.'.$_.'.solved'} = '';
3008: $newrecord{'resource.'.$_.'.award'} = '';
1.299 albertel 3009: $newrecord{'resource.'.$_.'.awarded'} = '';
1.125 ng 3010: $updateflag = 1;
1.269 raeburn 3011: if ($env{'form.GD_'.$user.'_'.$_.'_aggtries'} > 0) {
3012: my $aggtries = $env{'form.GD_'.$user.'_'.$_.'_aggtries'};
3013: my $totaltries = $env{'form.GD_'.$user.'_'.$_.'_totaltries'};
3014: my $solvedstatus = $env{'form.GD_'.$user.'_'.$_.'_solved_s'};
3015: &decrement_aggs($symb,$_,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3016: $aggregateflag = 1;
3017: }
1.139 albertel 3018: } elsif (!($old_part eq $partial && $old_score eq $score)) {
3019: $updateflag = 1;
3020: $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne '';
3021: $newrecord{'resource.'.$_.'.solved'} = $score;
3022: $rec_update++;
1.125 ng 3023: }
3024:
1.93 albertel 3025: $line .= '<td align="center">'.$old_aw.' </td>'.
1.44 ng 3026: '<td align="center">'.$awarded.
3027: ($score eq 'excused' ? $score : '').' </td>';
1.5 albertel 3028:
1.54 albertel 3029:
3030: my $partid=$_;
3031: foreach my $stores (@parts) {
3032: my ($part,$type) = &split_part_type($stores);
3033: if ($part !~ m/^\Q$partid\E/) { next;}
3034: if ($type eq 'awarded' || $type eq 'solved') { next; }
1.257 albertel 3035: my $old_aw = $env{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
3036: my $awarded = $env{'form.GD_'.$user.'_'.$part.'_'.$type};
1.54 albertel 3037: if ($awarded ne '' && $awarded ne $old_aw) {
3038: $newrecord{'resource.'.$part.'.'.$type}= $awarded;
1.257 albertel 3039: $newrecord{'resource.'.$part.'.regrader'}="$env{'user.name'}:$env{'user.domain'}";
1.54 albertel 3040: $updateflag=1;
3041: }
1.93 albertel 3042: $line .= '<td align="center">'.$old_aw.' </td>'.
1.54 albertel 3043: '<td align="center">'.$awarded.' </td>';
3044: }
1.44 ng 3045: }
1.93 albertel 3046: $line.='</tr>'."\n";
1.301 albertel 3047:
3048: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3049: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3050:
1.44 ng 3051: if ($updateflag) {
3052: $count++;
1.257 albertel 3053: &Apache::lonnet::cstore(\%newrecord,$symb,$env{'request.course.id'},
1.89 albertel 3054: $udom,$uname);
1.301 albertel 3055:
3056: if (&Apache::bridgetask::in_queue('gradingqueue',$symb,$cdom,
3057: $cnum,$udom,$uname)) {
3058: # need to figure out if should be in queue.
3059: my %record =
3060: &Apache::lonnet::restore($symb,$env{'request.course.id'},
3061: $udom,$uname);
3062: my $all_graded = 1;
3063: my $none_graded = 1;
3064: foreach my $part (@parts) {
3065: if ( $record{'resource.'.$part.'.awarded'} eq '' ) {
3066: $all_graded = 0;
3067: } else {
3068: $none_graded = 0;
3069: }
3070: }
3071:
3072: if ($all_graded || $none_graded) {
3073: &Apache::bridgetask::remove_from_queue('gradingqueue',
3074: $symb,$cdom,$cnum,
3075: $udom,$uname);
3076: }
3077: }
3078:
1.126 ng 3079: $result.='<tr bgcolor="#ffffde"><td align="right"> '.$updateCtr.' </td>'.$line;
3080: $updateCtr++;
1.93 albertel 3081: } else {
1.126 ng 3082: $noupdate.='<tr bgcolor="#ffffde"><td align="right"> '.$noupdateCtr.' </td>'.$line;
3083: $noupdateCtr++;
1.44 ng 3084: }
1.269 raeburn 3085: if ($aggregateflag) {
3086: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
1.301 albertel 3087: $cdom,$cnum);
1.269 raeburn 3088: }
1.93 albertel 3089: }
3090: if ($noupdate) {
1.126 ng 3091: # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3;
3092: my $numcols=scalar(@partid)*4+2;
1.204 albertel 3093: $result .= '<tr bgcolor="#ffffff"><td align="center" colspan="'.$numcols.'">No Changes Occurred For the Students Below</td></tr><tr bgcolor="#ffffde">'.$noupdate;
1.44 ng 3094: }
1.72 ng 3095: $result .= '</table></td></tr></table>'."\n".
3096: &show_grading_menu_form ($symb,$url);
1.125 ng 3097: my $msg = '<br /><b>Number of records updated = '.$rec_update.
1.44 ng 3098: ' for '.$count.' student'.($count <= 1 ? '' : 's').'.</b><br />'.
1.257 albertel 3099: '<b>Total number of students = '.$env{'form.total'}.'</b><br />';
1.44 ng 3100: return $title.$msg.$result;
1.5 albertel 3101: }
1.54 albertel 3102:
3103: sub split_part_type {
3104: my ($partstr) = @_;
3105: my ($temp,@allparts)=split(/_/,$partstr);
3106: my $type=pop(@allparts);
3107: my $part=join('.',@allparts);
3108: return ($part,$type);
3109: }
3110:
1.44 ng 3111: #------------- end of section for handling grading by section/class ---------
3112: #
3113: #----------------------------------------------------------------------------
3114:
1.5 albertel 3115:
1.44 ng 3116: #----------------------------------------------------------------------------
3117: #
3118: #-------------------------- Next few routines handles grading by csv upload
3119: #
3120: #--- Javascript to handle csv upload
1.27 albertel 3121: sub csvupload_javascript_reverse_associate {
1.246 albertel 3122: my $error1=&mt('You need to specify the username or ID');
3123: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3124: return(<<ENDPICK);
3125: function verify(vf) {
3126: var foundsomething=0;
3127: var founduname=0;
1.243 albertel 3128: var foundID=0;
1.27 albertel 3129: for (i=0;i<=vf.nfields.value;i++) {
3130: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3131: if (i==0 && tw!=0) { foundID=1; }
3132: if (i==1 && tw!=0) { founduname=1; }
3133: if (i!=0 && i!=1 && i!=2 && tw!=0) { foundsomething=1; }
1.27 albertel 3134: }
1.246 albertel 3135: if (founduname==0 && foundID==0) {
3136: alert('$error1');
3137: return;
1.27 albertel 3138: }
3139: if (foundsomething==0) {
1.246 albertel 3140: alert('$error2');
3141: return;
1.27 albertel 3142: }
3143: vf.submit();
3144: }
3145: function flip(vf,tf) {
3146: var nw=eval('vf.f'+tf+'.selectedIndex');
3147: var i;
3148: for (i=0;i<=vf.nfields.value;i++) {
3149: //can not pick the same destination field for both name and domain
3150: if (((i ==0)||(i ==1)) &&
3151: ((tf==0)||(tf==1)) &&
3152: (i!=tf) &&
3153: (eval('vf.f'+i+'.selectedIndex')==nw)) {
3154: eval('vf.f'+i+'.selectedIndex=0;')
3155: }
3156: }
3157: }
3158: ENDPICK
3159: }
3160:
3161: sub csvupload_javascript_forward_associate {
1.246 albertel 3162: my $error1=&mt('You need to specify the username or ID');
3163: my $error2=&mt('You need to specify at least one grading field');
1.27 albertel 3164: return(<<ENDPICK);
3165: function verify(vf) {
3166: var foundsomething=0;
3167: var founduname=0;
1.243 albertel 3168: var foundID=0;
1.27 albertel 3169: for (i=0;i<=vf.nfields.value;i++) {
3170: tw=eval('vf.f'+i+'.selectedIndex');
1.243 albertel 3171: if (tw==1) { foundID=1; }
3172: if (tw==2) { founduname=1; }
3173: if (tw>3) { foundsomething=1; }
1.27 albertel 3174: }
1.246 albertel 3175: if (founduname==0 && foundID==0) {
3176: alert('$error1');
3177: return;
1.27 albertel 3178: }
3179: if (foundsomething==0) {
1.246 albertel 3180: alert('$error2');
3181: return;
1.27 albertel 3182: }
3183: vf.submit();
3184: }
3185: function flip(vf,tf) {
3186: var nw=eval('vf.f'+tf+'.selectedIndex');
3187: var i;
3188: //can not pick the same destination field twice
3189: for (i=0;i<=vf.nfields.value;i++) {
3190: if ((i!=tf) && (eval('vf.f'+i+'.selectedIndex')==nw)) {
3191: eval('vf.f'+i+'.selectedIndex=0;')
3192: }
3193: }
3194: }
3195: ENDPICK
3196: }
3197:
1.26 albertel 3198: sub csvuploadmap_header {
1.41 ng 3199: my ($request,$symb,$url,$datatoken,$distotal)= @_;
3200: my $javascript;
1.257 albertel 3201: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3202: $javascript=&csvupload_javascript_reverse_associate();
3203: } else {
3204: $javascript=&csvupload_javascript_forward_associate();
3205: }
1.45 ng 3206:
1.257 albertel 3207: my ($result) = &showResourceInfo($url,$env{'form.probTitle'});
3208: my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
1.245 albertel 3209: my $ignore=&mt('Ignore First Line');
1.41 ng 3210: $request->print(<<ENDPICK);
1.26 albertel 3211: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.45 ng 3212: <h3><font color="#339933">Uploading Class Grades</font></h3>
3213: $result
1.26 albertel 3214: <hr>
3215: <h3>Identify fields</h3>
3216: Total number of records found in file: $distotal <hr />
3217: Enter as many fields as you can. The system will inform you and bring you back
3218: to this page if the data selected is insufficient to run your class.<hr />
3219: <input type="button" value="Reverse Association" onClick="javascript:this.form.associate.value='Reverse Association';submit(this.form);" />
1.245 albertel 3220: <label><input type="checkbox" name="noFirstLine" $checked />$ignore</label>
1.26 albertel 3221: <input type="hidden" name="associate" value="" />
3222: <input type="hidden" name="phase" value="three" />
3223: <input type="hidden" name="datatoken" value="$datatoken" />
1.257 albertel 3224: <input type="hidden" name="fileupload" value="$env{'form.fileupload'}" />
3225: <input type="hidden" name="upfiletype" value="$env{'form.upfiletype'}" />
1.26 albertel 3226: <input type="hidden" name="upfile_associate"
1.257 albertel 3227: value="$env{'form.upfile_associate'}" />
1.26 albertel 3228: <input type="hidden" name="symb" value="$symb" />
3229: <input type="hidden" name="url" value="$url" />
1.257 albertel 3230: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
3231: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
1.246 albertel 3232: <input type="hidden" name="command" value="csvuploadoptions" />
1.26 albertel 3233: <hr />
3234: <script type="text/javascript" language="Javascript">
3235: $javascript
3236: </script>
3237: ENDPICK
1.118 ng 3238: return '';
1.26 albertel 3239:
3240: }
3241:
3242: sub csvupload_fields {
1.146 albertel 3243: my ($url,$symb) = @_;
3244: my (@parts) = &getpartlist($url,$symb);
1.243 albertel 3245: my @fields=(['ID','Student ID'],
3246: ['username','Student Username'],
3247: ['domain','Student Domain']);
1.41 ng 3248: foreach my $part (sort(@parts)) {
3249: my @datum;
3250: my $display=&Apache::lonnet::metadata($url,$part.'.display');
3251: my $name=$part;
3252: if (!$display) { $display = $name; }
3253: @datum=($name,$display);
1.244 albertel 3254: if ($name=~/^stores_(.*)_awarded/) {
3255: push(@fields,['stores_'.$1.'_points',"Points [Part: $1]"]);
3256: }
1.41 ng 3257: push(@fields,\@datum);
3258: }
3259: return (@fields);
1.26 albertel 3260: }
3261:
3262: sub csvuploadmap_footer {
1.41 ng 3263: my ($request,$i,$keyfields) =@_;
3264: $request->print(<<ENDPICK);
1.26 albertel 3265: </table>
3266: <input type="hidden" name="nfields" value="$i" />
3267: <input type="hidden" name="keyfields" value="$keyfields" />
3268: <input type="button" onClick="javascript:verify(this.form)" value="Assign Grades" /><br />
3269: </form>
3270: ENDPICK
3271: }
3272:
1.283 albertel 3273: sub checkforfile_js {
1.86 ng 3274: my $result =<<CSVFORMJS;
3275: <script type="text/javascript" language="javascript">
3276: function checkUpload(formname) {
3277: if (formname.upfile.value == "") {
3278: alert("Please use the browse button to select a file from your local directory.");
3279: return false;
3280: }
3281: formname.submit();
3282: }
3283: </script>
3284: CSVFORMJS
1.283 albertel 3285: return $result;
3286: }
3287:
3288: sub upcsvScores_form {
3289: my ($request) = shift;
3290: my ($symb,$url)=&get_symb_and_url($request);
3291: if (!$symb) {return '';}
3292: my $result=&checkforfile_js();
1.257 albertel 3293: $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb);
3294: my ($table) = &showResourceInfo($url,$env{'form.probTitle'});
1.118 ng 3295: $result.=$table;
1.86 ng 3296: $result.='<br /><table width=100% border=0><tr><td bgcolor="#777777">'."\n";
3297: $result.='<table width=100% border=0><tr bgcolor="#e6ffff"><td>'."\n";
1.118 ng 3298: $result.=' <b>Specify a file containing the class scores for current resource'.
1.86 ng 3299: '.</b></td></tr>'."\n";
3300: $result.='<tr bgcolor=#ffffe6><td>'."\n";
3301: my $upfile_select=&Apache::loncommon::upfile_select_html();
1.245 albertel 3302: my $ignore=&mt('Ignore First Line');
1.86 ng 3303: $result.=<<ENDUPFORM;
1.106 albertel 3304: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
1.86 ng 3305: <input type="hidden" name="symb" value="$symb" />
3306: <input type="hidden" name="url" value="$url" />
3307: <input type="hidden" name="command" value="csvuploadmap" />
1.257 albertel 3308: <input type="hidden" name="probTitle" value="$env{'form.probTitle'}" />
3309: <input type="hidden" name="saveState" value="$env{'form.saveState'}" />
1.86 ng 3310: $upfile_select
3311: <br /><input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scores" />
1.283 albertel 3312: <label><input type="checkbox" name="noFirstLine" />$ignore</label>
1.86 ng 3313: </form>
3314: ENDUPFORM
3315: $result.='</td></tr></table>'."\n";
3316: $result.='</td></tr></table><br /><br />'."\n";
3317: $result.=&show_grading_menu_form($symb,$url);
3318: return $result;
3319: }
3320:
3321:
1.26 albertel 3322: sub csvuploadmap {
1.41 ng 3323: my ($request)= @_;
3324: my ($symb,$url)=&get_symb_and_url($request);
3325: if (!$symb) {return '';}
1.72 ng 3326:
1.41 ng 3327: my $datatoken;
1.257 albertel 3328: if (!$env{'form.datatoken'}) {
1.41 ng 3329: $datatoken=&Apache::loncommon::upfile_store($request);
1.26 albertel 3330: } else {
1.257 albertel 3331: $datatoken=$env{'form.datatoken'};
1.41 ng 3332: &Apache::loncommon::load_tmp_file($request);
1.26 albertel 3333: }
1.41 ng 3334: my @records=&Apache::loncommon::upfile_record_sep();
1.257 albertel 3335: if ($env{'form.noFirstLine'}) { shift(@records); }
1.41 ng 3336: &csvuploadmap_header($request,$symb,$url,$datatoken,$#records+1);
3337: my ($i,$keyfields);
3338: if (@records) {
1.146 albertel 3339: my @fields=&csvupload_fields($url,$symb);
1.45 ng 3340:
1.257 albertel 3341: if ($env{'form.upfile_associate'} eq 'reverse') {
1.41 ng 3342: &Apache::loncommon::csv_print_samples($request,\@records);
3343: $i=&Apache::loncommon::csv_print_select_table($request,\@records,
3344: \@fields);
3345: foreach (@fields) { $keyfields.=$_->[0].','; }
3346: chop($keyfields);
3347: } else {
3348: unshift(@fields,['none','']);
3349: $i=&Apache::loncommon::csv_samples_select_table($request,\@records,
3350: \@fields);
1.311 banghart 3351: foreach my $rec (@records) {
3352: my %temp = &Apache::loncommon::record_sep($rec);
3353: if (%temp) {
3354: $keyfields=join(',',sort(keys(%temp)));
3355: last;
3356: }
3357: }
1.41 ng 3358: }
3359: }
3360: &csvuploadmap_footer($request,$i,$keyfields);
1.72 ng 3361: $request->print(&show_grading_menu_form($symb,$url));
3362:
1.41 ng 3363: return '';
1.27 albertel 3364: }
3365:
1.246 albertel 3366: sub csvuploadoptions {
1.41 ng 3367: my ($request)= @_;
3368: my ($symb,$url)=&get_symb_and_url($request);
1.257 albertel 3369: my $checked=(($env{'form.noFirstLine'})?'1':'0');
1.246 albertel 3370: my $ignore=&mt('Ignore First Line');
3371: $request->print(<<ENDPICK);
3372: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="gradesupload">
3373: <h3><font color="#339933">Uploading Class Grade Options</font></h3>
3374: <input type="hidden" name="command" value="csvuploadassign" />
1.302 albertel 3375: <!--
1.246 albertel 3376: <p>
3377: <label>
3378: <input type="checkbox" name="show_full_results" />
3379: Show a table of all changes
3380: </label>
3381: </p>
1.302 albertel 3382: -->
1.246 albertel 3383: <p>
3384: <label>
3385: <input type="checkbox" name="overwite_scores" checked="checked" />
3386: Overwrite any existing score
3387: </label>
3388: </p>
3389: ENDPICK
3390: my %fields=&get_fields();
3391: if (!defined($fields{'domain'})) {
1.257 albertel 3392: my $domform = &Apache::loncommon::select_dom_form($env{'request.role.domain'},'default_domain');
1.246 albertel 3393: $request->print("\n<p> Users are in domain: ".$domform."</p>\n");
3394: }
1.257 albertel 3395: foreach my $key (sort(keys(%env))) {
1.246 albertel 3396: if ($key !~ /^form\.(.*)$/) { next; }
3397: my $cleankey=$1;
3398: if ($cleankey eq 'command') { next; }
3399: $request->print('<input type="hidden" name="'.$cleankey.
1.257 albertel 3400: '" value="'.$env{$key}.'" />'."\n");
1.246 albertel 3401: }
3402: # FIXME do a check for any duplicated user ids...
3403: # FIXME do a check for any invalid user ids?...
1.290 albertel 3404: $request->print('<input type="submit" value="Assign Grades" /><br />
3405: <hr /></form>'."\n");
1.246 albertel 3406: $request->print(&show_grading_menu_form($symb,$url));
3407: return '';
3408: }
3409:
3410: sub get_fields {
3411: my %fields;
1.257 albertel 3412: my @keyfields = split(/\,/,$env{'form.keyfields'});
3413: for (my $i=0; $i<=$env{'form.nfields'}; $i++) {
3414: if ($env{'form.upfile_associate'} eq 'reverse') {
3415: if ($env{'form.f'.$i} ne 'none') {
3416: $fields{$keyfields[$i]}=$env{'form.f'.$i};
1.41 ng 3417: }
3418: } else {
1.257 albertel 3419: if ($env{'form.f'.$i} ne 'none') {
3420: $fields{$env{'form.f'.$i}}=$keyfields[$i];
1.41 ng 3421: }
3422: }
1.27 albertel 3423: }
1.246 albertel 3424: return %fields;
3425: }
3426:
3427: sub csvuploadassign {
3428: my ($request)= @_;
3429: my ($symb,$url)=&get_symb_and_url($request);
3430: if (!$symb) {return '';}
3431: &Apache::loncommon::load_tmp_file($request);
3432: my @gradedata = &Apache::loncommon::upfile_record_sep();
1.257 albertel 3433: if ($env{'form.noFirstLine'}) { shift(@gradedata); }
1.246 albertel 3434: my %fields=&get_fields();
1.41 ng 3435: $request->print('<h3>Assigning Grades</h3>');
1.257 albertel 3436: my $courseid=$env{'request.course.id'};
1.97 albertel 3437: my ($classlist) = &getclasslist('all',0);
1.106 albertel 3438: my @notallowed;
1.41 ng 3439: my @skipped;
3440: my $countdone=0;
3441: foreach my $grade (@gradedata) {
3442: my %entries=&Apache::loncommon::record_sep($grade);
1.246 albertel 3443: my $domain;
3444: if ($entries{$fields{'domain'}}) {
3445: $domain=$entries{$fields{'domain'}};
3446: } else {
1.257 albertel 3447: $domain=$env{'form.default_domain'};
1.246 albertel 3448: }
1.243 albertel 3449: $domain=~s/\s//g;
1.41 ng 3450: my $username=$entries{$fields{'username'}};
1.160 albertel 3451: $username=~s/\s//g;
1.243 albertel 3452: if (!$username) {
3453: my $id=$entries{$fields{'ID'}};
1.247 albertel 3454: $id=~s/\s//g;
1.243 albertel 3455: my %ids=&Apache::lonnet::idget($domain,$id);
3456: $username=$ids{$id};
3457: }
1.41 ng 3458: if (!exists($$classlist{"$username:$domain"})) {
1.247 albertel 3459: my $id=$entries{$fields{'ID'}};
3460: $id=~s/\s//g;
3461: if ($id) {
3462: push(@skipped,"$id:$domain");
3463: } else {
3464: push(@skipped,"$username:$domain");
3465: }
1.41 ng 3466: next;
3467: }
1.108 albertel 3468: my $usec=$classlist->{"$username:$domain"}[5];
1.106 albertel 3469: if (!&canmodify($usec)) {
3470: push(@notallowed,"$username:$domain");
3471: next;
3472: }
1.244 albertel 3473: my %points;
1.41 ng 3474: my %grades;
3475: foreach my $dest (keys(%fields)) {
1.244 albertel 3476: if ($dest eq 'ID' || $dest eq 'username' ||
3477: $dest eq 'domain') { next; }
3478: if ($entries{$fields{$dest}} =~ /^\s*$/) { next; }
3479: if ($dest=~/stores_(.*)_points/) {
3480: my $part=$1;
3481: my $wgt =&Apache::lonnet::EXT('resource.'.$part.'.weight',
3482: $symb,$domain,$username);
1.247 albertel 3483: $entries{$fields{$dest}}=~s/\s//g;
1.244 albertel 3484: my $pcr=$entries{$fields{$dest}} / $wgt;
3485: my $award='correct_by_override';
3486: $grades{"resource.$part.awarded"}=$pcr;
3487: $grades{"resource.$part.solved"}=$award;
3488: $points{$part}=1;
3489: } else {
3490: if ($dest=~/stores_(.*)_awarded/) { if ($points{$1}) {next;} }
3491: if ($dest=~/stores_(.*)_solved/) { if ($points{$1}) {next;} }
3492: my $store_key=$dest;
3493: $store_key=~s/^stores/resource/;
3494: $store_key=~s/_/\./g;
3495: $grades{$store_key}=$entries{$fields{$dest}};
3496: }
1.41 ng 3497: }
1.244 albertel 3498: if (! %grades) { push(@skipped,"$username:$domain no data to store"); }
1.257 albertel 3499: $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
1.244 albertel 3500: # &Apache::lonnet::logthis(" storing ".(join('-',%grades)));
1.302 albertel 3501: my $result=&Apache::lonnet::cstore(\%grades,$symb,
3502: $env{'request.course.id'},
3503: $domain,$username);
3504: if ($result eq 'ok') {
3505: $request->print('.');
3506: } else {
3507: $request->print("<p>
3508: <font color='red'>
3509: Failed to store student $username\@$domain.
3510: Message when trying to store was ($result)
3511: </font>
3512: </p>" );
3513: }
1.41 ng 3514: $request->rflush();
3515: $countdone++;
3516: }
3517: $request->print("<br />Stored $countdone students\n");
3518: if (@skipped) {
1.106 albertel 3519: $request->print('<p<font size="+1"><b>Skipped Students</b></font></p>');
3520: foreach my $student (@skipped) { $request->print("$student<br />\n"); }
3521: }
3522: if (@notallowed) {
3523: $request->print('<p><font size="+1" color="red"><b>Students Not Allowed to Modify</b></font></p>');
3524: foreach my $student (@notallowed) { $request->print("$student<br />\n"); }
1.41 ng 3525: }
1.106 albertel 3526: $request->print("<br />\n");
1.41 ng 3527: $request->print(&show_grading_menu_form($symb,$url));
3528: return '';
1.26 albertel 3529: }
1.44 ng 3530: #------------- end of section for handling csv file upload ---------
3531: #
3532: #-------------------------------------------------------------------
3533: #
1.122 ng 3534: #-------------- Next few routines handle grading by page/sequence
1.72 ng 3535: #
3536: #--- Select a page/sequence and a student to grade
1.68 ng 3537: sub pickStudentPage {
3538: my ($request) = shift;
3539:
3540: $request->print(<<LISTJAVASCRIPT);
3541: <script type="text/javascript" language="javascript">
3542:
3543: function checkPickOne(formname) {
1.76 ng 3544: if (radioSelection(formname.student) == null) {
1.68 ng 3545: alert("Please select the student you wish to grade.");
3546: return;
3547: }
1.125 ng 3548: ptr = pullDownSelection(formname.selectpage);
3549: formname.page.value = formname["page"+ptr].value;
3550: formname.title.value = formname["title"+ptr].value;
1.68 ng 3551: formname.submit();
3552: }
3553:
3554: </script>
3555: LISTJAVASCRIPT
1.118 ng 3556: &commonJSfunctions($request);
1.72 ng 3557: my ($symb,$url) = &get_symb_and_url($request);
1.257 albertel 3558: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3559: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3560: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
1.68 ng 3561:
3562: my $result='<h3><font color="#339933"> '.
3563: 'Manual Grading by Page or Sequence</font></h3>';
3564:
1.80 ng 3565: $result.='<form action="/adm/grades" method="post" name="displayPage">'."\n";
1.70 ng 3566: $result.=' <b>Problems from:</b> <select name="selectpage">'."\n";
1.74 albertel 3567: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 3568: my ($curpage) =&Apache::lonnet::decode_symb($symb);
3569: # my ($curpage,$mapId) =&Apache::lonnet::decode_symb($symb);
3570: # my $type=($curpage =~ /\.(page|sequence)/);
1.70 ng 3571: my $ctr=0;
1.68 ng 3572: foreach (@$titles) {
3573: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
1.70 ng 3574: $result.='<option value="'.$ctr.'" '.
1.71 ng 3575: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
3576: '>'.$showtitle.'</option>'."\n";
1.70 ng 3577: $ctr++;
1.68 ng 3578: }
3579: $result.= '</select>'."<br>\n";
1.70 ng 3580: $ctr=0;
3581: foreach (@$titles) {
3582: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
3583: $result.='<input type="hidden" name="page'.$ctr.'" value="'.$$symbx{$_}.'" />'."\n";
3584: $result.='<input type="hidden" name="title'.$ctr.'" value="'.$showtitle.'" />'."\n";
3585: $ctr++;
3586: }
1.72 ng 3587: $result.='<input type="hidden" name="page" />'."\n".
3588: '<input type="hidden" name="title" />'."\n";
1.68 ng 3589:
1.288 albertel 3590: $result.=' <b>View Problems Text: </b><label><input type="radio" name="vProb" value="no" checked="on" /> no </label>'."\n".
3591: '<label><input type="radio" name="vProb" value="yes" /> yes </label>'."<br />\n";
1.72 ng 3592:
1.71 ng 3593: $result.=' <b>Submission Details: </b>'.
1.288 albertel 3594: '<label><input type="radio" name="lastSub" value="none" /> none</label>'."\n".
3595: '<label><input type="radio" name="lastSub" value="datesub" checked /> by dates and submissions</label>'."\n".
3596: '<label><input type="radio" name="lastSub" value="all" /> all details</label>'."\n";
1.72 ng 3597:
1.68 ng 3598: $result.='<input type="hidden" name="section" value="'.$getsec.'" />'."\n".
1.257 albertel 3599: '<input type="hidden" name="Status" value="'.$env{'form.Status'}.'" />'."\n".
1.72 ng 3600: '<input type="hidden" name="command" value="displayPage" />'."\n".
3601: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.80 ng 3602: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.257 albertel 3603: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."<br />\n";
1.72 ng 3604:
1.80 ng 3605: $result.=' <input type="button" '.
1.126 ng 3606: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /><br />'."\n";
1.72 ng 3607:
1.68 ng 3608: $request->print($result);
3609:
1.126 ng 3610: my $studentTable.=' <b>Select a student you wish to grade and then click on the Next button.</b><br>'.
1.68 ng 3611: '<table border="0"><tr><td bgcolor="#777777">'.
3612: '<table border="0"><tr bgcolor="#e6ffff">'.
1.126 ng 3613: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3614: '<td>'.&nameUserString('header').'</td>'.
1.126 ng 3615: '<td align="right"> <b>No.</b></td>'.
1.129 ng 3616: '<td>'.&nameUserString('header').'</td></tr>';
1.68 ng 3617:
1.76 ng 3618: my (undef,undef,$fullname) = &getclasslist($getsec,'1');
1.68 ng 3619: my $ptr = 1;
1.294 albertel 3620: foreach my $student (sort
3621: {
3622: if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
3623: return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
3624: }
3625: return $a cmp $b;
3626: } (keys(%$fullname))) {
1.68 ng 3627: my ($uname,$udom) = split(/:/,$student);
1.126 ng 3628: $studentTable.=($ptr%2 == 1 ? '<tr bgcolor="#ffffe6">' : '</td>');
3629: $studentTable.='<td align="right">'.$ptr.' </td>';
1.288 albertel 3630: $studentTable.='<td> <label><input type="radio" name="student" value="'.$student.'" /> '
3631: .&nameUserString(undef,$$fullname{$student},$uname,$udom)."</label>\n";
1.126 ng 3632: $studentTable.=($ptr%2 == 0 ? '</td></tr>' : '');
1.68 ng 3633: $ptr++;
3634: }
1.126 ng 3635: $studentTable.='</td><td> </td><td> ' if ($ptr%2 == 0);
1.68 ng 3636: $studentTable.='</td></tr></table></td></tr></table>'."\n";
1.126 ng 3637: $studentTable.='<input type="button" '.
3638: 'onClick="javascript:checkPickOne(this.form);"value="Next->" /></form>'."\n";
1.68 ng 3639:
3640: $studentTable.=&show_grading_menu_form($symb,$url);
3641: $request->print($studentTable);
3642:
3643: return '';
3644: }
3645:
3646: sub getSymbMap {
1.74 albertel 3647: my ($request) = @_;
1.132 bowersj2 3648: my $navmap = Apache::lonnavmaps::navmap->new();
1.68 ng 3649:
3650: my %symbx = ();
3651: my @titles = ();
1.117 bowersj2 3652: my $minder = 0;
3653:
3654: # Gather every sequence that has problems.
1.240 albertel 3655: my @sequences = $navmap->retrieveResources(undef, sub { shift->is_map(); },
3656: 1,0,1);
1.117 bowersj2 3657: for my $sequence ($navmap->getById('0.0'), @sequences) {
1.241 albertel 3658: if ($navmap->hasResource($sequence, sub { shift->is_problem(); }, 0) ) {
1.117 bowersj2 3659: my $title = $minder.'.'.$sequence->compTitle();
3660: push @titles, $title; # minder in case two titles are identical
3661: $symbx{$title} = $sequence->symb();
3662: $minder++;
1.241 albertel 3663: }
1.68 ng 3664: }
3665: return \@titles,\%symbx;
3666: }
3667:
1.72 ng 3668: #
3669: #--- Displays a page/sequence w/wo problems, w/wo submissions
1.68 ng 3670: sub displayPage {
3671: my ($request) = shift;
3672:
1.72 ng 3673: my ($symb,$url) = &get_symb_and_url($request);
1.257 albertel 3674: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3675: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3676: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3677: my $pageTitle = $env{'form.page'};
1.103 albertel 3678: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3679: my ($uname,$udom) = split(/:/,$env{'form.student'});
3680: my $usec=$classlist->{$env{'form.student'}}[5];
1.168 albertel 3681:
3682: #need to make sure we have the correct data for later EXT calls,
3683: #thus invalidate the cache
3684: &Apache::lonnet::devalidatecourseresdata(
1.257 albertel 3685: $env{'course.'.$env{'request.course.id'}.'.num'},
3686: $env{'course.'.$env{'request.course.id'}.'.domain'});
1.168 albertel 3687: &Apache::lonnet::clear_EXT_cache_status();
3688:
1.103 albertel 3689: if (!&canview($usec)) {
1.257 albertel 3690: $request->print('<font color="red">Unable to view requested student.('.$env{'form.student'}.')</font>');
1.103 albertel 3691: $request->print(&show_grading_menu_form($symb,$url));
3692: return;
3693: }
1.257 albertel 3694: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
3695: $result.='<h3> Student: '.&nameUserString(undef,$$fullname{$env{'form.student'}},$uname,$udom).
1.129 ng 3696: '</h3>'."\n";
1.71 ng 3697: &sub_page_js($request);
3698: $request->print($result);
3699:
1.132 bowersj2 3700: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3701: my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
1.68 ng 3702: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3703: if (!$map) {
3704: $request->print('<font color="red">Unable to view requested sequence. ('.$resUrl.')</font>');
3705: $request->print(&show_grading_menu_form($symb,$url));
3706: return;
3707: }
1.68 ng 3708: my $iterator = $navmap->getIterator($map->map_start(),
3709: $map->map_finish());
3710:
1.71 ng 3711: my $studentTable='<form action="/adm/grades" method="post" name="gradePage">'."\n".
1.72 ng 3712: '<input type="hidden" name="command" value="gradeByPage" />'."\n".
1.257 albertel 3713: '<input type="hidden" name="fullname" value="'.$$fullname{$env{'form.student'}}.'" />'."\n".
3714: '<input type="hidden" name="student" value="'.$env{'form.student'}.'" />'."\n".
1.72 ng 3715: '<input type="hidden" name="page" value="'.$pageTitle.'" />'."\n".
1.257 albertel 3716: '<input type="hidden" name="title" value="'.$env{'form.title'}.'" />'."\n".
1.72 ng 3717: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
3718: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
1.125 ng 3719: '<input type="hidden" name="overRideScore" value="no" />'."\n".
1.257 albertel 3720: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n";
1.71 ng 3721:
3722: my $checkIcon = '<img src="'.$request->dir_config('lonIconsURL').
3723: '/check.gif" height="16" border="0" />';
3724:
1.118 ng 3725: $studentTable.=' <b>Note:</b> Problems graded correct by the computer are marked with a '.$checkIcon.
3726: ' symbol.'."\n".
1.71 ng 3727: '<table border="0"><tr><td bgcolor="#777777">'.
3728: '<table border="0"><tr bgcolor="#e6ffff">'.
1.118 ng 3729: '<td align="center"><b> Prob. </b></td>'.
1.257 albertel 3730: '<td><b> '.($env{'form.vProb'} eq 'no' ? 'Title' : 'Problem Text').'/Grade</b></td></tr>';
1.71 ng 3731:
1.196 albertel 3732: my ($depth,$question,$prob) = (1,1,1);
1.68 ng 3733: $iterator->next(); # skip the first BEGIN_MAP
3734: my $curRes = $iterator->next(); # for "current resource"
1.101 albertel 3735: while ($depth > 0) {
1.68 ng 3736: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 3737: if($curRes == $iterator->END_MAP) { $depth--; }
1.68 ng 3738:
1.235 albertel 3739: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 3740: my $parts = $curRes->parts();
1.68 ng 3741: my $title = $curRes->compTitle();
1.71 ng 3742: my $symbx = $curRes->symb();
1.196 albertel 3743: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.71 ng 3744: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
3745: $studentTable.='<td valign="top">';
1.257 albertel 3746: if ($env{'form.vProb'} eq 'yes' ) {
1.144 albertel 3747: $studentTable.=&show_problem($request,$symbx,$uname,$udom,1,
3748: undef,'both');
1.71 ng 3749: } else {
1.257 albertel 3750: my $companswer = &Apache::loncommon::get_student_answers($symbx,$uname,$udom,$env{'request.course.id'});
1.80 ng 3751: $companswer =~ s|<form(.*?)>||g;
3752: $companswer =~ s|</form>||g;
1.71 ng 3753: # while ($companswer =~ /(<a href\=\"javascript:newWindow.*?Script Vars<\/a>)/s) { #<a href="javascript:newWindow</a>
1.116 ng 3754: # $companswer =~ s/$1/ /ms;
3755: # $request->print('match='.$1."<br>\n");
1.71 ng 3756: # }
1.116 ng 3757: # $companswer =~ s|<table border=\"1\">|<table border=\"0\">|g;
1.71 ng 3758: $studentTable.=' <b>'.$title.'</b> <br> <b>Correct answer:</b><br>'.$companswer;
3759: }
3760:
1.257 albertel 3761: my %record = &Apache::lonnet::restore($symbx,$env{'request.course.id'},$udom,$uname);
1.125 ng 3762:
1.257 albertel 3763: if ($env{'form.lastSub'} eq 'datesub') {
1.71 ng 3764: if ($record{'version'} eq '') {
3765: $studentTable.='<br /> <font color="red">No recorded submission for this problem</font><br />';
3766: } else {
1.116 ng 3767: my %responseType = ();
3768: foreach my $partid (@{$parts}) {
1.147 albertel 3769: my @responseIds =$curRes->responseIds($partid);
3770: my @responseType =$curRes->responseType($partid);
3771: my %responseIds;
3772: for (my $i=0;$i<=$#responseIds;$i++) {
3773: $responseIds{$responseIds[$i]}=$responseType[$i];
3774: }
3775: $responseType{$partid} = \%responseIds;
1.116 ng 3776: }
1.148 albertel 3777: $studentTable.= &displaySubByDates($symbx,\%record,$parts,\%responseType,$checkIcon,$uname,$udom);
1.147 albertel 3778:
1.71 ng 3779: }
1.257 albertel 3780: } elsif ($env{'form.lastSub'} eq 'all') {
3781: my $last = ($env{'form.lastSub'} eq 'last' ? 'last' : '');
1.71 ng 3782: $studentTable.=&Apache::loncommon::get_previous_attempt($symbx,$uname,$udom,
1.257 albertel 3783: $env{'request.course.id'},
1.71 ng 3784: '','.submission');
3785:
3786: }
1.103 albertel 3787: if (&canmodify($usec)) {
3788: foreach my $partid (@{$parts}) {
3789: $studentTable.=&gradeBox($request,$symbx,$uname,$udom,$question,$partid,\%record);
3790: $studentTable.='<input type="hidden" name="q_'.$question.'" value="'.$partid.'" />'."\n";
3791: $question++;
3792: }
1.196 albertel 3793: $prob++;
1.71 ng 3794: }
3795: $studentTable.='</td></tr>';
1.68 ng 3796:
1.103 albertel 3797: }
1.68 ng 3798: $curRes = $iterator->next();
3799: }
3800:
1.71 ng 3801: $studentTable.='</td></tr></table></td></tr></table>'."\n".
1.125 ng 3802: '<input type="button" value="Save" '.
1.71 ng 3803: 'onClick="javascript:checkSubmitPage(this.form,'.$question.');" TARGET=_self />'.
3804: '</form>'."\n";
3805: $studentTable.=&show_grading_menu_form($symb,$url);
3806: $request->print($studentTable);
3807:
3808: return '';
1.119 ng 3809: }
3810:
3811: sub displaySubByDates {
1.148 albertel 3812: my ($symb,$record,$parts,$responseType,$checkIcon,$uname,$udom) = @_;
1.224 albertel 3813: my $isCODE=0;
3814: if (exists($record->{'resource.CODE'})) { $isCODE=1; }
1.119 ng 3815: my $studentTable='<table border="0" width="100%"><tr><td bgcolor="#777777">'.
3816: '<table border="0" width="100%"><tr bgcolor="#e6ffff">'.
3817: '<td><b>Date/Time</b></td>'.
1.224 albertel 3818: ($isCODE?'<td><b>CODE</b></td>':'').
1.119 ng 3819: '<td><b>Submission</b></td>'.
3820: '<td><b>Status </b></td></tr>';
3821: my ($version);
3822: my %mark;
1.148 albertel 3823: my %orders;
1.119 ng 3824: $mark{'correct_by_student'} = $checkIcon;
1.147 albertel 3825: if (!exists($$record{'1:timestamp'})) {
3826: return '<br /> <font color="red">Nothing submitted - no attempts</font><br />';
3827: }
1.119 ng 3828: for ($version=1;$version<=$$record{'version'};$version++) {
3829: my $timestamp = scalar(localtime($$record{$version.':timestamp'}));
3830: $studentTable.='<tr bgcolor="#ffffff" valign="top"><td>'.$timestamp.'</td>';
1.224 albertel 3831: if ($isCODE) {
3832: $studentTable.='<td>'.$record->{$version.':resource.CODE'}.'</td>';
3833: }
1.119 ng 3834: my @versionKeys = split(/\:/,$$record{$version.':keys'});
3835: my @displaySub = ();
3836: foreach my $partid (@{$parts}) {
1.147 albertel 3837: my @matchKey = sort(grep /^resource\.\Q$partid\E\..*?\.submission$/,@versionKeys);
1.122 ng 3838: # next if ($$record{"$version:resource.$partid.solved"} eq '');
1.207 albertel 3839: my $display_part=&get_display_part($partid,undef,$symb);
1.147 albertel 3840: foreach my $matchKey (@matchKey) {
1.198 albertel 3841: if (exists($$record{$version.':'.$matchKey}) &&
3842: $$record{$version.':'.$matchKey} ne '') {
1.147 albertel 3843: my ($responseId)=($matchKey=~ /^resource\.\Q$partid\E\.(.*?)\.submission$/);
1.207 albertel 3844: $displaySub[0].='<b>Part:</b> '.$display_part.' ';
1.147 albertel 3845: $displaySub[0].='<font color="#999999">(ID '.
1.207 albertel 3846: $responseId.')</font> <b>';
1.147 albertel 3847: if ($$record{"$version:resource.$partid.tries"} eq '') {
3848: $displaySub[0].='Trial not counted';
3849: } else {
3850: $displaySub[0].='Trial '.
3851: $$record{"$version:resource.$partid.tries"};
3852: }
3853: my $responseType=$responseType->{$partid}->{$responseId};
1.148 albertel 3854: if (!exists($orders{$partid})) { $orders{$partid}={}; }
3855: if (!exists($orders{$partid}->{$responseId})) {
3856: $orders{$partid}->{$responseId}=
3857: &get_order($partid,$responseId,$symb,$uname,$udom);
3858: }
1.147 albertel 3859: $displaySub[0].='</b> '.
1.148 albertel 3860: &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:").'<br />';
1.147 albertel 3861: }
3862: }
3863: if (exists $$record{"$version:resource.$partid.award"}) {
1.207 albertel 3864: $displaySub[1].='<b>Part:</b> '.$display_part.' '.
1.147 albertel 3865: lc($$record{"$version:resource.$partid.award"}).' '.
3866: $mark{$$record{"$version:resource.$partid.solved"}}.
3867: '<br />';
3868: }
3869: if (exists $$record{"$version:resource.$partid.regrader"}) {
3870: $displaySub[2].=$$record{"$version:resource.$partid.regrader"}.
1.207 albertel 3871: ' (<b>'.&mt('Part').':</b> '.$display_part.')';
1.147 albertel 3872: }
3873: }
3874: # needed because old essay regrader has not parts info
3875: if (exists $$record{"$version:resource.regrader"}) {
3876: $displaySub[2].=$$record{"$version:resource.regrader"};
3877: }
3878: $studentTable.='<td>'.$displaySub[0].' </td><td>'.$displaySub[1];
3879: if ($displaySub[2]) {
3880: $studentTable.='Manually graded by '.$displaySub[2];
3881: }
3882: $studentTable.=' </td></tr>';
3883:
1.119 ng 3884: }
3885: $studentTable.='</table></td></tr></table>';
3886: return $studentTable;
1.71 ng 3887: }
3888:
3889: sub updateGradeByPage {
3890: my ($request) = shift;
3891:
1.257 albertel 3892: my $cdom = $env{"course.$env{'request.course.id'}.domain"};
3893: my $cnum = $env{"course.$env{'request.course.id'}.num"};
3894: my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'};
3895: my $pageTitle = $env{'form.page'};
1.103 albertel 3896: my ($classlist,undef,$fullname) = &getclasslist($getsec,'1');
1.257 albertel 3897: my ($uname,$udom) = split(/:/,$env{'form.student'});
3898: my $usec=$classlist->{$env{'form.student'}}[5];
1.103 albertel 3899: if (!&canmodify($usec)) {
1.257 albertel 3900: $request->print('<font color="red">Unable to modify requested student.('.$env{'form.student'}.'</font>');
3901: $request->print(&show_grading_menu_form($env{'form.symb'},$env{'form.url'}));
1.103 albertel 3902: return;
3903: }
1.257 albertel 3904: my $result='<h3><font color="#339933"> '.$env{'form.title'}.'</font></h3>';
3905: $result.='<h3> Student: '.&nameUserString(undef,$env{'form.fullname'},$uname,$udom).
1.129 ng 3906: '</h3>'."\n";
1.70 ng 3907:
1.68 ng 3908: $request->print($result);
3909:
1.132 bowersj2 3910: my $navmap = Apache::lonnavmaps::navmap->new();
1.257 albertel 3911: my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
1.71 ng 3912: my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
1.288 albertel 3913: if (!$map) {
3914: $request->print('<font color="red">Unable to grade requested sequence. ('.$resUrl.')</font>');
3915: my ($symb,$url)=&get_symb_and_url($request);
3916: $request->print(&show_grading_menu_form($symb,$url));
3917: return;
3918: }
1.71 ng 3919: my $iterator = $navmap->getIterator($map->map_start(),
3920: $map->map_finish());
1.70 ng 3921:
1.71 ng 3922: my $studentTable='<table border="0"><tr><td bgcolor="#777777">'.
1.68 ng 3923: '<table border="0"><tr bgcolor="#e6ffff">'.
1.125 ng 3924: '<td align="center"><b> Prob. </b></td>'.
1.71 ng 3925: '<td><b> Title </b></td>'.
3926: '<td><b> Previous Score </b></td>'.
3927: '<td><b> New Score </b></td></tr>';
3928:
3929: $iterator->next(); # skip the first BEGIN_MAP
3930: my $curRes = $iterator->next(); # for "current resource"
1.196 albertel 3931: my ($depth,$question,$prob,$changeflag)= (1,1,1,0);
1.101 albertel 3932: while ($depth > 0) {
1.71 ng 3933: if($curRes == $iterator->BEGIN_MAP) { $depth++; }
1.100 bowersj2 3934: if($curRes == $iterator->END_MAP) { $depth--; }
1.71 ng 3935:
3936: if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
1.91 albertel 3937: my $parts = $curRes->parts();
1.71 ng 3938: my $title = $curRes->compTitle();
3939: my $symbx = $curRes->symb();
1.196 albertel 3940: $studentTable.='<tr bgcolor="#ffffe6"><td align="center" valign="top" >'.$prob.
1.71 ng 3941: (scalar(@{$parts}) == 1 ? '' : '<br>('.scalar(@{$parts}).' parts)').'</td>';
3942: $studentTable.='<td valign="top"> <b>'.$title.'</b> </td>';
3943:
3944: my %newrecord=();
3945: my @displayPts=();
1.269 raeburn 3946: my %aggregate = ();
3947: my $aggregateflag = 0;
1.71 ng 3948: foreach my $partid (@{$parts}) {
1.257 albertel 3949: my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
3950: my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
1.71 ng 3951:
1.257 albertel 3952: my $wgt = $env{'form.WGT'.$question.'_'.$partid} != 0 ?
3953: $env{'form.WGT'.$question.'_'.$partid} : 1;
1.71 ng 3954: my $partial = $newpts/$wgt;
3955: my $score;
3956: if ($partial > 0) {
3957: $score = 'correct_by_override';
1.125 ng 3958: } elsif ($newpts ne '') { #empty is taken as 0
1.71 ng 3959: $score = 'incorrect_by_override';
3960: }
1.257 albertel 3961: my $dropMenu = $env{'form.GD_SEL'.$question.'_'.$partid};
1.125 ng 3962: if ($dropMenu eq 'excused') {
1.71 ng 3963: $partial = '';
3964: $score = 'excused';
1.125 ng 3965: } elsif ($dropMenu eq 'reset status'
1.257 albertel 3966: && $env{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists
1.125 ng 3967: $newrecord{'resource.'.$partid.'.tries'} = 0;
3968: $newrecord{'resource.'.$partid.'.solved'} = '';
3969: $newrecord{'resource.'.$partid.'.award'} = '';
3970: $newrecord{'resource.'.$partid.'.awarded'} = 0;
1.257 albertel 3971: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
1.125 ng 3972: $changeflag++;
3973: $newpts = '';
1.269 raeburn 3974:
3975: my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
3976: my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
3977: my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
3978: if ($aggtries > 0) {
3979: &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
3980: $aggregateflag = 1;
3981: }
1.71 ng 3982: }
1.207 albertel 3983: my $display_part=&get_display_part($partid,undef,
3984: $curRes->symb());
1.257 albertel 3985: my $oldstatus = $env{'form.solved'.$question.'_'.$partid};
1.207 albertel 3986: $displayPts[0].=' <b>Part:</b> '.$display_part.' = '.
1.71 ng 3987: (($oldstatus eq 'excused') ? 'excused' : $oldpts).
3988: ' <br>';
1.207 albertel 3989: $displayPts[1].=' <b>Part:</b> '.$display_part.' = '.
1.125 ng 3990: (($score eq 'excused') ? 'excused' : $newpts).
1.71 ng 3991: ' <br>';
3992:
3993: $question++;
1.125 ng 3994: next if ($dropMenu eq 'reset status' || ($newpts == $oldpts && $score ne 'excused'));
3995:
1.71 ng 3996: $newrecord{'resource.'.$partid.'.awarded'} = $partial if $partial ne '';
1.125 ng 3997: $newrecord{'resource.'.$partid.'.solved'} = $score if $score ne '';
1.257 albertel 3998: $newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}"
1.125 ng 3999: if (scalar(keys(%newrecord)) > 0);
1.71 ng 4000:
4001: $changeflag++;
4002: }
4003: if (scalar(keys(%newrecord)) > 0) {
1.257 albertel 4004: &Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
1.71 ng 4005: $udom,$uname);
4006: }
1.269 raeburn 4007: if ($aggregateflag) {
4008: &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
4009: $env{'course.'.$env{'request.course.id'}.'.domain'},
4010: $env{'course.'.$env{'request.course.id'}.'.num'});
4011: }
1.125 ng 4012:
1.71 ng 4013: $studentTable.='<td valign="top">'.$displayPts[0].'</td>'.
4014: '<td valign="top">'.$displayPts[1].'</td>'.
4015: '</tr>';
1.68 ng 4016:
1.196 albertel 4017: $prob++;
1.68 ng 4018: }
1.71 ng 4019: $curRes = $iterator->next();
1.68 ng 4020: }
1.98 albertel 4021:
1.71 ng 4022: $studentTable.='</td></tr></table></td></tr></table>';
1.257 albertel 4023: $studentTable.=&show_grading_menu_form($env{'form.symb'},$env{'form.url'});
1.76 ng 4024: my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
4025: 'The scores were changed for '.
4026: $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
4027: $request->print($grademsg.$studentTable);
1.68 ng 4028:
1.70 ng 4029: return '';
4030: }
4031:
1.72 ng 4032: #-------- end of section for handling grading by page/sequence ---------
4033: #
4034: #-------------------------------------------------------------------
4035:
1.75 albertel 4036: #--------------------Scantron Grading-----------------------------------
4037: #
4038: #------ start of section for handling grading by page/sequence ---------
4039:
1.81 albertel 4040: sub defaultFormData {
4041: my ($symb,$url)=@_;
4042: return '
4043: <input type="hidden" name="symb" value="'.$symb.'" />'."\n".
4044: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.257 albertel 4045: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
4046: '<input type="hidden" name="probTitle" value="'.$env{'form.probTitle'}.'" />'."\n";
1.81 albertel 4047: }
4048:
1.75 albertel 4049: sub getSequenceDropDown {
4050: my ($request,$symb)=@_;
4051: my $result='<select name="selectpage">'."\n";
4052: my ($titles,$symbx) = &getSymbMap($request);
1.137 albertel 4053: my ($curpage)=&Apache::lonnet::decode_symb($symb);
1.75 albertel 4054: my $ctr=0;
4055: foreach (@$titles) {
4056: my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/);
4057: $result.='<option value="'.$$symbx{$_}.'" '.
4058: ($$symbx{$_} =~ /$curpage$/ ? 'selected="on"' : '').
4059: '>'.$showtitle.'</option>'."\n";
4060: $ctr++;
4061: }
4062: $result.= '</select>';
4063: return $result;
4064: }
4065:
1.202 albertel 4066: sub scantron_filenames {
1.257 albertel 4067: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4068: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
1.157 albertel 4069: my @files=&Apache::lonnet::dirlist('userfiles',$cdom,$cname,
1.162 albertel 4070: &Apache::loncommon::propath($cdom,$cname));
1.202 albertel 4071: my @possiblenames;
1.201 albertel 4072: foreach my $filename (sort(@files)) {
1.157 albertel 4073: ($filename)=split(/&/,$filename);
4074: if ($filename!~/^scantron_orig_/) { next ; }
4075: $filename=~s/^scantron_orig_//;
1.202 albertel 4076: push(@possiblenames,$filename);
4077: }
4078: return @possiblenames;
4079: }
4080:
4081: sub scantron_uploads {
1.209 ng 4082: my ($file2grade) = @_;
1.202 albertel 4083: my $result= '<select name="scantron_selectfile">';
4084: $result.="<option></option>";
4085: foreach my $filename (sort(&scantron_filenames())) {
1.209 ng 4086: $result.="<option".($filename eq $file2grade ? ' selected="on"':'').">$filename</option>\n";
1.81 albertel 4087: }
4088: $result.="</select>";
4089: return $result;
4090: }
4091:
1.82 albertel 4092: sub scantron_scantab {
4093: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4094: my $result='<select name="scantron_format">'."\n";
1.191 albertel 4095: $result.='<option></option>'."\n";
1.82 albertel 4096: foreach my $line (<$fh>) {
4097: my ($name,$descrip)=split(/:/,$line);
4098: if ($name =~ /^\#/) { next; }
4099: $result.='<option value="'.$name.'">'.$descrip.'</option>'."\n";
4100: }
4101: $result.='</select>'."\n";
4102:
4103: return $result;
4104: }
4105:
1.186 albertel 4106: sub scantron_CODElist {
1.257 albertel 4107: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4108: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.186 albertel 4109: my @names=&Apache::lonnet::getkeys('CODEs',$cdom,$cnum);
4110: my $namechoice='<option></option>';
1.225 albertel 4111: foreach my $name (sort {uc($a) cmp uc($b)} @names) {
1.191 albertel 4112: if ($name =~ /^error: 2 /) { next; }
1.278 albertel 4113: if ($name =~ /^type\0/) { next; }
1.186 albertel 4114: $namechoice.='<option value="'.$name.'">'.$name.'</option>';
4115: }
4116: $namechoice='<select name="scantron_CODElist">'.$namechoice.'</select>';
4117: return $namechoice;
4118: }
4119:
4120: sub scantron_CODEunique {
4121: my $result='<nobr>
1.272 albertel 4122: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4123: value="yes" checked="checked" /> Yes </label>
1.186 albertel 4124: </nobr>
4125: <nobr>
1.272 albertel 4126: <label><input type="radio" name="scantron_CODEunique"
1.308 albertel 4127: value="no" /> No </label>
1.186 albertel 4128: </nobr>';
4129: return $result;
4130: }
4131:
1.75 albertel 4132: sub scantron_selectphase {
1.209 ng 4133: my ($r,$file2grade) = @_;
1.75 albertel 4134: my ($symb,$url)=&get_symb_and_url($r);
4135: if (!$symb) {return '';}
4136: my $sequence_selector=&getSequenceDropDown($r,$symb);
1.81 albertel 4137: my $default_form_data=&defaultFormData($symb,$url);
4138: my $grading_menu_button=&show_grading_menu_form($symb,$url);
1.209 ng 4139: my $file_selector=&scantron_uploads($file2grade);
1.82 albertel 4140: my $format_selector=&scantron_scantab();
1.186 albertel 4141: my $CODE_selector=&scantron_CODElist();
4142: my $CODE_unique=&scantron_CODEunique();
1.75 albertel 4143: my $result;
1.157 albertel 4144: #FIXME allow instructor to be able to download the scantron file
4145: # and to upload it,
1.75 albertel 4146: $result.= <<SCANTRONFORM;
1.162 albertel 4147: <table width="100%" border="0">
1.75 albertel 4148: <tr>
1.226 albertel 4149: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantron_process">
1.75 albertel 4150: <td bgcolor="#777777">
1.203 albertel 4151: <input type="hidden" name="command" value="scantron_warning" />
1.162 albertel 4152: $default_form_data
1.75 albertel 4153: <table width="100%" border="0">
4154: <tr bgcolor="#e6ffff">
1.174 albertel 4155: <td colspan="2">
4156: <b>Specify file and which Folder/Sequence to grade</b>
1.75 albertel 4157: </td>
4158: </tr>
4159: <tr bgcolor="#ffffe6">
1.174 albertel 4160: <td> Sequence to grade: </td><td> $sequence_selector </td>
1.75 albertel 4161: </tr>
4162: <tr bgcolor="#ffffe6">
1.174 albertel 4163: <td> Filename of scoring office file: </td><td> $file_selector </td>
1.75 albertel 4164: </tr>
1.82 albertel 4165: <tr bgcolor="#ffffe6">
1.174 albertel 4166: <td> Format of data file: </td><td> $format_selector </td>
1.82 albertel 4167: </tr>
1.157 albertel 4168: <tr bgcolor="#ffffe6">
1.186 albertel 4169: <td> Saved CODEs to validate against: </td><td> $CODE_selector</td>
4170: </tr>
4171: <tr bgcolor="#ffffe6">
4172: <td> Each CODE is only to be used once:</td><td> $CODE_unique </td>
4173: </tr>
4174: <tr bgcolor="#ffffe6">
1.187 albertel 4175: <td> Options: </td>
4176: <td>
1.272 albertel 4177: <label><input type="checkbox" name="scantron_options_redo" value="redo_skipped"/> Do only previously skipped records</label> <br />
4178: <label><input type="checkbox" name="scantron_options_ignore" value="ignore_corrections"/> Remove all exisiting corrections</label>
1.187 albertel 4179: </td>
4180: </tr>
4181: <tr bgcolor="#ffffe6">
1.174 albertel 4182: <td colspan="2">
1.265 www 4183: <input type="submit" value="Grading: Validate Scantron Records" />
1.162 albertel 4184: </td>
4185: </tr>
4186: </table>
1.226 albertel 4187: </td>
4188: </form>
1.162 albertel 4189: </tr>
4190: SCANTRONFORM
4191:
4192: $r->print($result);
4193:
1.257 albertel 4194: if (&Apache::lonnet::allowed('usc',$env{'request.role.domain'}) ||
4195: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 4196:
4197: $r->print(<<SCANTRONFORM);
4198: <tr>
4199: <td bgcolor="#777777">
4200: <table width="100%" border="0">
4201: <tr bgcolor="#e6ffff">
4202: <td>
1.174 albertel 4203: <b>Specify a Scantron data file to upload.</b>
1.162 albertel 4204: </td>
4205: </tr>
4206: <tr bgcolor="#ffffe6">
4207: <td>
4208: SCANTRONFORM
1.174 albertel 4209: my $default_form_data=&defaultFormData(&get_symb_and_url($r,1));
1.257 albertel 4210: my $cdom= $env{'course.'.$env{'request.course.id'}.'.domain'};
4211: my $cnum= $env{'course.'.$env{'request.course.id'}.'.num'};
1.174 albertel 4212: $r->print(<<UPLOAD);
4213: <script type="text/javascript" language="javascript">
4214: function checkUpload(formname) {
4215: if (formname.upfile.value == "") {
4216: alert("Please use the browse button to select a file from your local directory.");
4217: return false;
4218: }
4219: formname.submit();
4220: }
4221: </script>
4222:
4223: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
4224: $default_form_data
4225: <input name='courseid' type='hidden' value='$cnum' />
4226: <input name='domainid' type='hidden' value='$cdom' />
4227: <input name='command' value='scantronupload_save' type='hidden' />
4228: File to upload:<input type="file" name="upfile" size="50" />
4229: <br />
4230: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
4231: </form>
4232: UPLOAD
1.162 albertel 4233:
4234: $r->print(<<SCANTRONFORM);
4235: </td>
4236: </tr>
1.75 albertel 4237: </table>
4238: </td>
4239: </tr>
1.162 albertel 4240: SCANTRONFORM
4241: }
1.187 albertel 4242: $r->print(<<SCANTRONFORM);
4243: <tr>
1.226 albertel 4244: <form action='/adm/grades' name='scantron_download'>
4245: <td bgcolor="#777777">
1.187 albertel 4246: <input type="hidden" name="command" value="scantron_download" />
4247: <table width="100%" border="0">
4248: <tr bgcolor="#e6ffff">
4249: <td colspan="2">
4250: <b>Download a scoring office file</b>
4251: </td>
4252: </tr>
4253: <tr bgcolor="#ffffe6">
4254: <td> Filename of scoring office file: </td><td> $file_selector </td>
4255: </tr>
4256: <tr bgcolor="#ffffe6">
4257: <td colspan="2">
1.293 www 4258: <input type="submit" value="Download: Show List of Associated Files" />
1.187 albertel 4259: </td>
4260: </tr>
4261: </table>
1.226 albertel 4262: </td>
4263: </form>
1.187 albertel 4264: </tr>
4265: SCANTRONFORM
1.162 albertel 4266:
4267: $r->print(<<SCANTRONFORM);
1.75 albertel 4268: </table>
1.81 albertel 4269: $grading_menu_button
1.75 albertel 4270: SCANTRONFORM
4271:
1.162 albertel 4272: return
1.75 albertel 4273: }
4274:
1.82 albertel 4275: sub get_scantron_config {
4276: my ($which) = @_;
4277: my $fh=Apache::File->new($Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab');
4278: my %config;
1.157 albertel 4279: #FIXME probably should move to XML it has already gotten a bit much now
1.82 albertel 4280: foreach my $line (<$fh>) {
4281: my ($name,$descrip)=split(/:/,$line);
4282: if ($name ne $which ) { next; }
4283: chomp($line);
4284: my @config=split(/:/,$line);
4285: $config{'name'}=$config[0];
4286: $config{'description'}=$config[1];
4287: $config{'CODElocation'}=$config[2];
4288: $config{'CODEstart'}=$config[3];
4289: $config{'CODElength'}=$config[4];
4290: $config{'IDstart'}=$config[5];
4291: $config{'IDlength'}=$config[6];
4292: $config{'Qstart'}=$config[7];
4293: $config{'Qlength'}=$config[8];
4294: $config{'Qoff'}=$config[9];
4295: $config{'Qon'}=$config[10];
1.157 albertel 4296: $config{'PaperID'}=$config[11];
4297: $config{'PaperIDlength'}=$config[12];
4298: $config{'FirstName'}=$config[13];
4299: $config{'FirstNamelength'}=$config[14];
4300: $config{'LastName'}=$config[15];
4301: $config{'LastNamelength'}=$config[16];
1.82 albertel 4302: last;
4303: }
4304: return %config;
4305: }
4306:
4307: sub username_to_idmap {
4308: my ($classlist)= @_;
4309: my %idmap;
4310: foreach my $student (keys(%$classlist)) {
4311: $idmap{$classlist->{$student}->[&Apache::loncoursedata::CL_ID]}=
4312: $student;
4313: }
4314: return %idmap;
4315: }
4316:
1.157 albertel 4317: sub scantron_fixup_scanline {
4318: my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_;
4319: if ($field eq 'ID') {
4320: if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) {
1.186 albertel 4321: return ($line,1,'New value too large');
1.157 albertel 4322: }
4323: if (length($args->{'newid'}) < $$scantron_config{'IDlength'}) {
4324: $args->{'newid'}=sprintf('%-'.$$scantron_config{'IDlength'}.'s',
4325: $args->{'newid'});
4326: }
4327: substr($line,$$scantron_config{'IDstart'}-1,
4328: $$scantron_config{'IDlength'})=$args->{'newid'};
4329: if ($args->{'newid'}=~/^\s*$/) {
4330: &scan_data($scan_data,"$whichline.user",
4331: $args->{'username'}.':'.$args->{'domain'});
4332: }
1.186 albertel 4333: } elsif ($field eq 'CODE') {
1.192 albertel 4334: if ($args->{'CODE_ignore_dup'}) {
4335: &scan_data($scan_data,"$whichline.CODE_ignore_dup",'1');
4336: }
4337: &scan_data($scan_data,"$whichline.useCODE",'1');
4338: if ($args->{'CODE'} ne 'use_unfound') {
1.191 albertel 4339: if (length($args->{'CODE'}) > $$scantron_config{'CODElength'}) {
4340: return ($line,1,'New CODE value too large');
4341: }
4342: if (length($args->{'CODE'}) < $$scantron_config{'CODElength'}) {
4343: $args->{'CODE'}=sprintf('%-'.$$scantron_config{'CODElength'}.'s',$args->{'CODE'});
4344: }
4345: substr($line,$$scantron_config{'CODEstart'}-1,
4346: $$scantron_config{'CODElength'})=$args->{'CODE'};
1.186 albertel 4347: }
1.157 albertel 4348: } elsif ($field eq 'answer') {
4349: my $length=$scantron_config->{'Qlength'};
4350: my $off=$scantron_config->{'Qoff'};
4351: my $on=$scantron_config->{'Qon'};
4352: my $answer=${off}x$length;
4353: if ($args->{'response'} eq 'none') {
4354: &scan_data($scan_data,
4355: "$whichline.no_bubble.".$args->{'question'},'1');
4356: } else {
1.274 albertel 4357: if ($on eq 'letter') {
4358: my @alphabet=('A'..'Z');
4359: $answer=$alphabet[$args->{'response'}];
4360: } elsif ($on eq 'number') {
4361: $answer=$args->{'response'}+1;
4362: } else {
4363: substr($answer,$args->{'response'},1)=$on;
4364: }
1.157 albertel 4365: &scan_data($scan_data,
4366: "$whichline.no_bubble.".$args->{'question'},undef,'1');
4367: }
4368: my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'};
4369: substr($line,$where-1,$length)=$answer;
4370: }
4371: return $line;
4372: }
4373:
4374: sub scan_data {
4375: my ($scan_data,$key,$value,$delete)=@_;
1.257 albertel 4376: my $filename=$env{'form.scantron_selectfile'};
1.157 albertel 4377: if (defined($value)) {
4378: $scan_data->{$filename.'_'.$key} = $value;
4379: }
4380: if ($delete) { delete($scan_data->{$filename.'_'.$key}); }
4381: return $scan_data->{$filename.'_'.$key};
4382: }
4383:
1.82 albertel 4384: sub scantron_parse_scanline {
1.194 albertel 4385: my ($line,$whichline,$scantron_config,$scan_data,$justHeader)=@_;
1.82 albertel 4386: my %record;
4387: my $questions=substr($line,$$scantron_config{'Qstart'}-1);
4388: my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
1.278 albertel 4389: if (!($$scantron_config{'CODElocation'} eq 0 ||
4390: $$scantron_config{'CODElocation'} eq 'none')) {
4391: if ($$scantron_config{'CODElocation'} < 0 ||
4392: $$scantron_config{'CODElocation'} eq 'letter' ||
4393: $$scantron_config{'CODElocation'} eq 'number') {
1.191 albertel 4394: $record{'scantron.CODE'}=substr($data,
4395: $$scantron_config{'CODEstart'}-1,
1.83 albertel 4396: $$scantron_config{'CODElength'});
1.191 albertel 4397: if (&scan_data($scan_data,"$whichline.useCODE")) {
4398: $record{'scantron.useCODE'}=1;
4399: }
1.192 albertel 4400: if (&scan_data($scan_data,"$whichline.CODE_ignore_dup")) {
4401: $record{'scantron.CODE_ignore_dup'}=1;
4402: }
1.82 albertel 4403: } else {
4404: #FIXME interpret first N questions
4405: }
4406: }
1.83 albertel 4407: $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1,
4408: $$scantron_config{'IDlength'});
1.157 albertel 4409: $record{'scantron.PaperID'}=
4410: substr($data,$$scantron_config{'PaperID'}-1,
4411: $$scantron_config{'PaperIDlength'});
4412: $record{'scantron.FirstName'}=
4413: substr($data,$$scantron_config{'FirstName'}-1,
4414: $$scantron_config{'FirstNamelength'});
4415: $record{'scantron.LastName'}=
4416: substr($data,$$scantron_config{'LastName'}-1,
4417: $$scantron_config{'LastNamelength'});
1.194 albertel 4418: if ($justHeader) { return \%record; }
4419:
1.82 albertel 4420: my @alphabet=('A'..'Z');
4421: my $questnum=0;
4422: while ($questions) {
4423: $questnum++;
4424: my $currentquest=substr($questions,0,$$scantron_config{'Qlength'});
4425: substr($questions,0,$$scantron_config{'Qlength'})='';
1.83 albertel 4426: if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
1.239 albertel 4427: if ($$scantron_config{'Qon'} eq 'letter') {
1.274 albertel 4428: if ($currentquest eq '?') {
4429: push(@{$record{'scantron.doubleerror'}},$questnum);
4430: $record{"scantron.$questnum.answer"}='';
4431: } elsif (!$currentquest
4432: || $currentquest eq $$scantron_config{'Qoff'}
4433: || $currentquest !~ /^[A-Z]$/) {
1.239 albertel 4434: $record{"scantron.$questnum.answer"}='';
4435: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4436: push(@{$record{"scantron.missingerror"}},$questnum);
4437: }
4438: } else {
4439: $record{"scantron.$questnum.answer"}=$currentquest;
4440: }
4441: } elsif ($$scantron_config{'Qon'} eq 'number') {
1.274 albertel 4442: if ($currentquest eq '?') {
4443: push(@{$record{'scantron.doubleerror'}},$questnum);
4444: $record{"scantron.$questnum.answer"}='';
4445: } elsif (!$currentquest
4446: || $currentquest eq $$scantron_config{'Qoff'}
4447: || $currentquest !~ /^\d$/) {
1.239 albertel 4448: $record{"scantron.$questnum.answer"}='';
4449: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4450: push(@{$record{"scantron.missingerror"}},$questnum);
4451: }
4452: } else {
4453: $record{"scantron.$questnum.answer"}=
4454: $alphabet[$currentquest-1];
4455: }
1.82 albertel 4456: } else {
1.239 albertel 4457: my @array=split($$scantron_config{'Qon'},$currentquest,-1);
4458: if (length($array[0]) eq $$scantron_config{'Qlength'}) {
4459: $record{"scantron.$questnum.answer"}='';
4460: if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
4461: push(@{$record{"scantron.missingerror"}},$questnum);
4462: }
4463: } else {
4464: $record{"scantron.$questnum.answer"}=
4465: $alphabet[length($array[0])];
4466: }
4467: if (scalar(@array) gt 2) {
4468: push(@{$record{'scantron.doubleerror'}},$questnum);
4469: my @ans=@array;
4470: my $i=length($ans[0]);shift(@ans);
4471: while ($#ans) {
4472: $i+=length($ans[0])+1;
4473: $record{"scantron.$questnum.answer"}.=$alphabet[$i];
4474: shift(@ans);
4475: }
4476: }
1.82 albertel 4477: }
4478: }
1.83 albertel 4479: $record{'scantron.maxquest'}=$questnum;
4480: return \%record;
1.82 albertel 4481: }
4482:
4483: sub scantron_add_delay {
1.140 albertel 4484: my ($delayqueue,$scanline,$errormessage,$errorcode)=@_;
4485: push(@$delayqueue,
4486: {'line' => $scanline, 'emsg' => $errormessage,
4487: 'ecode' => $errorcode }
4488: );
1.82 albertel 4489: }
4490:
4491: sub scantron_find_student {
1.157 albertel 4492: my ($scantron_record,$scan_data,$idmap,$line)=@_;
1.83 albertel 4493: my $scanID=$$scantron_record{'scantron.ID'};
1.157 albertel 4494: if ($scanID =~ /^\s*$/) {
4495: return &scan_data($scan_data,"$line.user");
4496: }
1.83 albertel 4497: foreach my $id (keys(%$idmap)) {
1.157 albertel 4498: if (lc($id) eq lc($scanID)) {
4499: return $$idmap{$id};
4500: }
1.83 albertel 4501: }
4502: return undef;
4503: }
4504:
4505: sub scantron_filter {
4506: my ($curres)=@_;
1.215 albertel 4507: # randomout is dysfunctional at best for this purpose
4508: if (ref($curres) && $curres->is_problem()) { #&& !$curres->randomout) {
1.83 albertel 4509: return 1;
4510: }
4511: return 0;
1.82 albertel 4512: }
4513:
1.157 albertel 4514: sub scantron_process_corrections {
4515: my ($r) = @_;
1.257 albertel 4516: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 4517: my ($scanlines,$scan_data)=&scantron_getfile();
4518: my $classlist=&Apache::loncoursedata::get_classlist();
1.257 albertel 4519: my $which=$env{'form.scantron_line'};
1.200 albertel 4520: my $line=&scantron_get_line($scanlines,$scan_data,$which);
1.157 albertel 4521: my ($skip,$err,$errmsg);
1.257 albertel 4522: if ($env{'form.scantron_skip_record'}) {
1.157 albertel 4523: $skip=1;
1.257 albertel 4524: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) {
4525: my $newstudent=$env{'form.scantron_username'}.':'.
4526: $env{'form.scantron_domain'};
1.157 albertel 4527: my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID];
4528: ($line,$err,$errmsg)=
4529: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
4530: 'ID',{'newid'=>$newid,
1.257 albertel 4531: 'username'=>$env{'form.scantron_username'},
4532: 'domain'=>$env{'form.scantron_domain'}});
4533: } elsif ($env{'form.scantron_corrections'} =~ /^(duplicate|incorrect)CODE$/) {
4534: my $resolution=$env{'form.scantron_CODE_resolution'};
1.190 albertel 4535: my $newCODE;
1.192 albertel 4536: my %args;
1.190 albertel 4537: if ($resolution eq 'use_unfound') {
1.191 albertel 4538: $newCODE='use_unfound';
1.190 albertel 4539: } elsif ($resolution eq 'use_found') {
1.257 albertel 4540: $newCODE=$env{'form.scantron_CODE_selectedvalue'};
1.190 albertel 4541: } elsif ($resolution eq 'use_typed') {
1.257 albertel 4542: $newCODE=$env{'form.scantron_CODE_newvalue'};
1.194 albertel 4543: } elsif ($resolution =~ /^use_closest_(\d+)/) {
1.257 albertel 4544: $newCODE=$env{"form.scantron_CODE_closest_$1"};
1.190 albertel 4545: }
1.257 albertel 4546: if ($env{'form.scantron_corrections'} eq 'duplicateCODE') {
1.192 albertel 4547: $args{'CODE_ignore_dup'}=1;
4548: }
4549: $args{'CODE'}=$newCODE;
1.186 albertel 4550: ($line,$err,$errmsg)=
4551: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which,
1.192 albertel 4552: 'CODE',\%args);
1.257 albertel 4553: } elsif ($env{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) {
4554: foreach my $question (split(',',$env{'form.scantron_questions'})) {
1.157 albertel 4555: ($line,$err,$errmsg)=
4556: &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,
4557: $which,'answer',
4558: { 'question'=>$question,
1.257 albertel 4559: 'response'=>$env{"form.scantron_correct_Q_$question"}});
1.157 albertel 4560: if ($err) { last; }
4561: }
4562: }
4563: if ($err) {
1.287 albertel 4564: $r->print("<font color='red'>Unable to accept last correction, an error occurred :$errmsg:</font>");
1.157 albertel 4565: } else {
1.200 albertel 4566: &scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
1.157 albertel 4567: &scantron_putfile($scanlines,$scan_data);
4568: }
4569: }
4570:
1.200 albertel 4571: sub reset_skipping_status {
4572: my ($scanlines,$scan_data)=&scantron_getfile();
4573: &scan_data($scan_data,'remember_skipping',undef,1);
4574: &scantron_putfile(undef,$scan_data);
4575: }
4576:
4577: sub allow_skipping {
4578: my ($scan_data,$i)=@_;
4579: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
4580: delete($remembered{$i});
4581: &scan_data($scan_data,'remember_skipping',join(':',%remembered));
4582: }
4583:
4584: sub should_be_skipped {
4585: my ($scan_data,$i)=@_;
1.257 albertel 4586: if ($env{'form.scantron_options_redo'} !~ /^redo_/) {
1.200 albertel 4587: # not redoing old skips
4588: return 0;
4589: }
4590: my %remembered=split(':',&scan_data($scan_data,'remember_skipping'));
4591: if (exists($remembered{$i})) { return 0; }
4592: return 1;
4593: }
4594:
4595: sub remember_current_skipped {
4596: my ($scanlines,$scan_data)=&scantron_getfile();
4597: my %to_remember;
4598: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
4599: if ($scanlines->{'skipped'}[$i]) {
4600: $to_remember{$i}=1;
4601: }
4602: }
4603: &Apache::lonnet::logthis('remembering '.join(':',%to_remember));
4604: &scan_data($scan_data,'remember_skipping',join(':',%to_remember));
4605: &scantron_putfile(undef,$scan_data);
4606: }
4607:
4608: sub check_for_error {
4609: my ($r,$result)=@_;
4610: if ($result ne 'ok' && $result ne 'not_found' ) {
4611: $r->print("An error occured ($result) when trying to Remove the existing corrections.");
4612: }
4613: }
1.157 albertel 4614:
1.203 albertel 4615: sub scantron_warning_screen {
4616: my ($button_text)=@_;
1.257 albertel 4617: my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
1.284 albertel 4618: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
4619: my $CODElist="a";
4620: if ($scantron_config{'CODElocation'} &&
4621: $scantron_config{'CODEstart'} &&
4622: $scantron_config{'CODElength'}) {
4623: $CODElist=$env{'form.scantron_CODElist'};
4624: if ($CODElist eq '') { $CODElist='<font color="red">None</font>'; }
4625: $CODElist=
4626: '<tr><td><b>List of CODES to validate against:</b></td><td><tt>'.
4627: $CODElist.'</tt></td></tr>';
4628: }
1.203 albertel 4629: return (<<STUFF);
4630: <p>
4631: <font color="red">Please double check the information
4632: below before clicking on '$button_text'</font>
4633: </p>
4634: <table>
1.284 albertel 4635: <tr><td><b>Sequence to be Graded:</b></td><td>$title</td></tr>
1.257 albertel 4636: <tr><td><b>Data File that will be used:</b></td><td><tt>$env{'form.scantron_selectfile'}</tt></td></tr>
1.284 albertel 4637: $CODElist
1.203 albertel 4638: </table>
4639: </font>
4640: <br />
4641: <p> If this information is correct, please click on '$button_text'.</p>
4642: <p> If something is incorrect, please click the 'Grading Menu' button to start over.</p>
4643:
4644: <br />
4645: STUFF
4646: }
4647:
4648: sub scantron_do_warning {
4649: my ($r)=@_;
4650: my ($symb,$url)=&get_symb_and_url($r);
4651: if (!$symb) {return '';}
4652: my $default_form_data=&defaultFormData($symb,$url);
4653: $r->print(&scantron_form_start().$default_form_data);
1.257 albertel 4654: if ( $env{'form.selectpage'} eq '' ||
4655: $env{'form.scantron_selectfile'} eq '' ||
4656: $env{'form.scantron_format'} eq '' ) {
1.237 albertel 4657: $r->print("<p>You have forgetten to specify some information. Please go Back and try again.</p>");
1.257 albertel 4658: if ( $env{'form.selectpage'} eq '') {
1.237 albertel 4659: $r->print('<p><font color="red">You have not selected a Sequence to grade</font></p>');
4660: }
1.257 albertel 4661: if ( $env{'form.scantron_selectfile'} eq '') {
1.237 albertel 4662: $r->print('<p><font color="red">You have not selected a file that contains the student\'s response data.</font></p>');
4663: }
1.257 albertel 4664: if ( $env{'form.scantron_format'} eq '') {
1.237 albertel 4665: $r->print('<p><font color="red">You have not selected a the format of the student\'s response data.</font></p>');
4666: }
4667: } else {
1.265 www 4668: my $warning=&scantron_warning_screen('Grading: Validate Records');
1.237 albertel 4669: $r->print(<<STUFF);
1.203 albertel 4670: $warning
1.265 www 4671: <input type="submit" name="submit" value="Grading: Validate Records" />
1.203 albertel 4672: <input type="hidden" name="command" value="scantron_validate" />
4673: STUFF
1.237 albertel 4674: }
4675: $r->print("</form><br />".&show_grading_menu_form($symb,$url)."</body></html>");
1.203 albertel 4676: return '';
4677: }
4678:
4679: sub scantron_form_start {
4680: my ($max_bubble)=@_;
4681: my $result= <<SCANTRONFORM;
4682: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
1.257 albertel 4683: <input type="hidden" name="selectpage" value="$env{'form.selectpage'}" />
4684: <input type="hidden" name="scantron_format" value="$env{'form.scantron_format'}" />
4685: <input type="hidden" name="scantron_selectfile" value="$env{'form.scantron_selectfile'}" />
1.218 albertel 4686: <input type="hidden" name="scantron_maxbubble" value="$max_bubble" />
1.257 albertel 4687: <input type="hidden" name="scantron_CODElist" value="$env{'form.scantron_CODElist'}" />
4688: <input type="hidden" name="scantron_CODEunique" value="$env{'form.scantron_CODEunique'}" />
4689: <input type="hidden" name="scantron_options_redo" value="$env{'form.scantron_options_redo'}" />
4690: <input type="hidden" name="scantron_options_ignore" value="$env{'form.scantron_options_ignore'}" />
1.203 albertel 4691: SCANTRONFORM
4692: return $result;
4693: }
4694:
1.157 albertel 4695: sub scantron_validate_file {
4696: my ($r) = @_;
4697: my ($symb,$url)=&get_symb_and_url($r);
4698: if (!$symb) {return '';}
4699: my $default_form_data=&defaultFormData($symb,$url);
1.200 albertel 4700:
4701: # do the detection of only doing skipped records first befroe we delete
4702: # them when doing the corrections reset
1.257 albertel 4703: if ($env{'form.scantron_options_redo'} ne 'redo_skipped_ready') {
1.200 albertel 4704: &reset_skipping_status();
4705: }
1.257 albertel 4706: if ($env{'form.scantron_options_redo'} eq 'redo_skipped') {
1.200 albertel 4707: &remember_current_skipped();
4708: &scantron_remove_file('skipped');
1.257 albertel 4709: $env{'form.scantron_options_redo'}='redo_skipped_ready';
1.200 albertel 4710: }
4711:
1.257 albertel 4712: if ($env{'form.scantron_options_ignore'} eq 'ignore_corrections') {
1.200 albertel 4713: &check_for_error($r,&scantron_remove_file('corrected'));
4714: &check_for_error($r,&scantron_remove_file('skipped'));
4715: &check_for_error($r,&scantron_remove_scan_data());
1.257 albertel 4716: $env{'form.scantron_options_ignore'}='done';
1.192 albertel 4717: }
1.200 albertel 4718:
1.257 albertel 4719: if ($env{'form.scantron_corrections'}) {
1.157 albertel 4720: &scantron_process_corrections($r);
4721: }
1.191 albertel 4722: $r->print("<p>Gathering neccessary info.</p>");$r->rflush();
1.157 albertel 4723: #get the student pick code ready
4724: $r->print(&Apache::loncommon::studentbrowser_javascript());
1.203 albertel 4725: my $max_bubble=&scantron_get_maxbubble($r);
4726: my $result=&scantron_form_start($max_bubble).$default_form_data;
1.157 albertel 4727: $r->print($result);
4728:
4729: my @validate_phases=( 'ID',
4730: 'CODE',
4731: 'doublebubble',
4732: 'missingbubbles');
1.257 albertel 4733: if (!$env{'form.validatepass'}) {
4734: $env{'form.validatepass'} = 0;
1.157 albertel 4735: }
1.257 albertel 4736: my $currentphase=$env{'form.validatepass'};
1.157 albertel 4737:
4738: my $stop=0;
4739: while (!$stop && $currentphase < scalar(@validate_phases)) {
4740: $r->print("<p> Validating ".$validate_phases[$currentphase]."</p>");
4741: $r->rflush();
4742: my $which="scantron_validate_".$validate_phases[$currentphase];
4743: {
4744: no strict 'refs';
4745: ($stop,$currentphase)=&$which($r,$currentphase);
4746: }
4747: }
4748: if (!$stop) {
1.203 albertel 4749: my $warning=&scantron_warning_screen('Start Grading');
4750: $r->print(<<STUFF);
4751: Validation process complete.<br />
4752: $warning
4753: <input type="submit" name="submit" value="Start Grading" />
4754: <input type="hidden" name="command" value="scantron_process" />
4755: STUFF
4756:
1.157 albertel 4757: } else {
4758: $r->print('<input type="hidden" name="command" value="scantron_validate" />');
4759: $r->print("<input type='hidden' name='validatepass' value='".$currentphase."' />");
4760: }
4761: if ($stop) {
4762: $r->print('<input type="submit" name="submit" value="Continue ->" />');
4763: $r->print(' using corrected info <br />');
4764: $r->print("<input type='submit' value='Skip' name='scantron_skip_record' />");
4765: $r->print(" this scanline saving it for later.");
4766: }
4767: $r->print(" </form><br />".&show_grading_menu_form($symb,$url).
4768: "</body></html>");
4769: return '';
4770: }
4771:
1.200 albertel 4772: sub scantron_remove_file {
1.192 albertel 4773: my ($which)=@_;
1.257 albertel 4774: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4775: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 4776: my $file='scantron_';
1.200 albertel 4777: if ($which eq 'corrected' || $which eq 'skipped') {
4778: $file.=$which.'_';
1.192 albertel 4779: } else {
4780: return 'refused';
4781: }
1.257 albertel 4782: $file.=$env{'form.scantron_selectfile'};
1.200 albertel 4783: return &Apache::lonnet::removeuserfile($cname,$cdom,$file);
4784: }
4785:
4786: sub scantron_remove_scan_data {
1.257 albertel 4787: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4788: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.192 albertel 4789: my @keys=&Apache::lonnet::getkeys('nohist_scantrondata',$cdom,$cname);
4790: my @todelete;
1.257 albertel 4791: my $filename=$env{'form.scantron_selectfile'};
1.192 albertel 4792: foreach my $key (@keys) {
4793: if ($key=~/^\Q$filename\E_/) {
1.257 albertel 4794: if ($env{'form.scantron_options_redo'} eq 'redo_skipped_ready' &&
1.200 albertel 4795: $key=~/remember_skipping/) {
4796: next;
4797: }
1.192 albertel 4798: push(@todelete,$key);
4799: }
4800: }
1.200 albertel 4801: my $result;
1.192 albertel 4802: if (@todelete) {
1.200 albertel 4803: $result=&Apache::lonnet::del('nohist_scantrondata',\@todelete,$cdom,$cname);
1.192 albertel 4804: }
4805: return $result;
4806: }
4807:
1.157 albertel 4808: sub scantron_getfile {
1.200 albertel 4809: #FIXME really would prefer a scantron directory
1.257 albertel 4810: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4811: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.157 albertel 4812: my $lines;
4813: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4814: 'scantron_orig_'.$env{'form.scantron_selectfile'});
1.157 albertel 4815: my %scanlines;
4816: $scanlines{'orig'}=[(split("\n",$lines,-1))];
4817: my $temp=$scanlines{'orig'};
4818: $scanlines{'count'}=$#$temp;
4819:
4820: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4821: 'scantron_corrected_'.$env{'form.scantron_selectfile'});
1.157 albertel 4822: if ($lines eq '-1') {
4823: $scanlines{'corrected'}=[];
4824: } else {
4825: $scanlines{'corrected'}=[(split("\n",$lines,-1))];
4826: }
4827: $lines=&Apache::lonnet::getfile('/uploaded/'.$cdom.'/'.$cname.'/'.
1.257 albertel 4828: 'scantron_skipped_'.$env{'form.scantron_selectfile'});
1.157 albertel 4829: if ($lines eq '-1') {
4830: $scanlines{'skipped'}=[];
4831: } else {
4832: $scanlines{'skipped'}=[(split("\n",$lines,-1))];
4833: }
1.175 albertel 4834: my @tmp=&Apache::lonnet::dump('nohist_scantrondata',$cdom,$cname);
1.157 albertel 4835: if ($tmp[0] =~ /^(error:|no_such_host)/) { @tmp=(); }
4836: my %scan_data = @tmp;
4837: return (\%scanlines,\%scan_data);
4838: }
4839:
4840: sub lonnet_putfile {
4841: my ($contents,$filename)=@_;
1.257 albertel 4842: my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
4843: my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
4844: $env{'form.sillywaytopassafilearound'}=$contents;
1.275 albertel 4845: &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
1.157 albertel 4846:
4847: }
4848:
4849: sub scantron_putfile {
4850: my ($scanlines,$scan_data) = @_;
1.200 albertel 4851: #FIXME really would prefer a scantron directory
1.257 albertel 4852: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
4853: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
1.200 albertel 4854: if ($scanlines) {
4855: my $prefix='scantron_';
1.157 albertel 4856: # no need to update orig, shouldn't change
4857: # &lonnet_putfile(join("\n",@{$scanlines->{'orig'}}),$prefix.'orig_'.
1.257 albertel 4858: # $env{'form.scantron_selectfile'});
1.200 albertel 4859: &lonnet_putfile(join("\n",@{$scanlines->{'corrected'}}),
4860: $prefix.'corrected_'.
1.257 albertel 4861: $env{'form.scantron_selectfile'});
1.200 albertel 4862: &lonnet_putfile(join("\n",@{$scanlines->{'skipped'}}),
4863: $prefix.'skipped_'.
1.257 albertel 4864: $env{'form.scantron_selectfile'});
1.200 albertel 4865: }
1.175 albertel 4866: &Apache::lonnet::put('nohist_scantrondata',$scan_data,$cdom,$cname);
1.157 albertel 4867: }
4868:
4869: sub scantron_get_line {
1.200 albertel 4870: my ($scanlines,$scan_data,$i)=@_;
4871: if (&should_be_skipped($scan_data,$i)) { return undef; }
4872: if ($scanlines->{'skipped'}[$i]) { return undef; }
1.157 albertel 4873: if ($scanlines->{'corrected'}[$i]) {return $scanlines->{'corrected'}[$i];}
4874: return $scanlines->{'orig'}[$i];
4875: }
4876:
1.200 albertel 4877: sub get_todo_count {
4878: my ($scanlines,$scan_data)=@_;
4879: my $count=0;
4880: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
4881: my $line=&scantron_get_line($scanlines,$scan_data,$i);
4882: if ($line=~/^[\s\cz]*$/) { next; }
4883: $count++;
4884: }
4885: return $count;
4886: }
4887:
1.157 albertel 4888: sub scantron_put_line {
1.200 albertel 4889: my ($scanlines,$scan_data,$i,$newline,$skip)=@_;
1.157 albertel 4890: if ($skip) {
4891: $scanlines->{'skipped'}[$i]=$newline;
1.200 albertel 4892: &allow_skipping($scan_data,$i);
1.157 albertel 4893: return;
4894: }
4895: $scanlines->{'corrected'}[$i]=$newline;
4896: }
4897:
4898: sub scantron_validate_ID {
4899: my ($r,$currentphase) = @_;
4900:
4901: #get student info
4902: my $classlist=&Apache::loncoursedata::get_classlist();
4903: my %idmap=&username_to_idmap($classlist);
4904:
4905: #get scantron line setup
1.257 albertel 4906: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 4907: my ($scanlines,$scan_data)=&scantron_getfile();
4908:
4909: my %found=('ids'=>{},'usernames'=>{});
4910: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 4911: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 4912: if ($line=~/^[\s\cz]*$/) { next; }
4913: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
4914: $scan_data);
4915: my $id=$$scan_record{'scantron.ID'};
4916: my $found;
4917: foreach my $checkid (keys(%idmap)) {
4918: if (lc($checkid) eq lc($id)) { $found=$checkid;last; }
4919: }
4920: if ($found) {
4921: my $username=$idmap{$found};
4922: if ($found{'ids'}{$found}) {
4923: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
4924: $line,'duplicateID',$found);
1.194 albertel 4925: return(1,$currentphase);
1.157 albertel 4926: } elsif ($found{'usernames'}{$username}) {
4927: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
4928: $line,'duplicateID',$username);
1.194 albertel 4929: return(1,$currentphase);
1.157 albertel 4930: }
1.186 albertel 4931: #FIXME store away line we previously saw the ID on to use above
1.157 albertel 4932: $found{'ids'}{$found}++;
4933: $found{'usernames'}{$username}++;
4934: } else {
4935: if ($id =~ /^\s*$/) {
1.158 albertel 4936: my $username=&scan_data($scan_data,"$i.user");
1.157 albertel 4937: if (defined($username) && $found{'usernames'}{$username}) {
4938: &scantron_get_correction($r,$i,$scan_record,
4939: \%scantron_config,
4940: $line,'duplicateID',$username);
1.194 albertel 4941: return(1,$currentphase);
1.157 albertel 4942: } elsif (!defined($username)) {
4943: &scantron_get_correction($r,$i,$scan_record,
4944: \%scantron_config,
4945: $line,'incorrectID');
1.194 albertel 4946: return(1,$currentphase);
1.157 albertel 4947: }
4948: $found{'usernames'}{$username}++;
4949: } else {
4950: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
4951: $line,'incorrectID');
1.194 albertel 4952: return(1,$currentphase);
1.157 albertel 4953: }
4954: }
4955: }
4956:
4957: return (0,$currentphase+1);
4958: }
4959:
4960: sub scantron_get_correction {
4961: my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_;
4962:
4963: #FIXME in the case of a duplicated ID the previous line, probaly need
4964: #to show both the current line and the previous one and allow skipping
4965: #the previous one or the current one
4966:
1.161 albertel 4967: $r->print("<p><b>An error was detected ($error)</b>");
1.157 albertel 4968: if ( defined($$scan_record{'scantron.PaperID'}) ) {
4969: $r->print(" for PaperID <tt>".
4970: $$scan_record{'scantron.PaperID'}."</tt> \n");
4971: } else {
4972: $r->print(" in scanline $i <pre>".
4973: $line."</pre> \n");
4974: }
1.242 albertel 4975: my $message="<p>The ID on the form is <tt>".
4976: $$scan_record{'scantron.ID'}."</tt><br />\n".
4977: "The name on the paper is ".
4978: $$scan_record{'scantron.LastName'}.",".
4979: $$scan_record{'scantron.FirstName'}."</p>";
4980:
1.157 albertel 4981: $r->print('<input type="hidden" name="scantron_corrections" value="'.$error.'" />'."\n");
4982: $r->print('<input type="hidden" name="scantron_line" value="'.$i.'" />'."\n");
4983: if ($error =~ /ID$/) {
1.186 albertel 4984: if ($error eq 'incorrectID') {
1.157 albertel 4985: $r->print("The encoded ID is not in the classlist</p>\n");
4986: } elsif ($error eq 'duplicateID') {
4987: $r->print("The encoded ID has also been used by a previous paper $arg</p>\n");
4988: }
1.242 albertel 4989: $r->print($message);
1.157 albertel 4990: $r->print("<p>How should I handle this? <br /> \n");
4991: $r->print("\n<ul><li> ");
4992: #FIXME it would be nice if this sent back the user ID and
4993: #could do partial userID matches
4994: $r->print(&Apache::loncommon::selectstudent_link('scantronupload',
4995: 'scantron_username','scantron_domain'));
4996: $r->print(": <input type='text' name='scantron_username' value='' />");
4997: $r->print("\n@".
1.257 albertel 4998: &Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
1.157 albertel 4999:
5000: $r->print('</li>');
1.186 albertel 5001: } elsif ($error =~ /CODE$/) {
5002: if ($error eq 'incorrectCODE') {
1.187 albertel 5003: $r->print("</p><p>The encoded CODE is not in the list of possible CODEs</p>\n");
1.186 albertel 5004: } elsif ($error eq 'duplicateCODE') {
1.194 albertel 5005: $r->print("</p><p>The encoded CODE has also been used by a previous paper ".join(', ',@{$arg}).", and CODEs are supposed to be unique</p>\n");
1.186 albertel 5006: }
1.224 albertel 5007: $r->print("<p>The CODE on the form is <tt>'".
5008: $$scan_record{'scantron.CODE'}."'</tt><br />\n");
1.242 albertel 5009: $r->print($message);
1.186 albertel 5010: $r->print("<p>How should I handle this? <br /> \n");
1.187 albertel 5011: $r->print("\n<br /> ");
1.194 albertel 5012: my $i=0;
1.273 albertel 5013: if ($error eq 'incorrectCODE'
5014: && $$scan_record{'scantron.CODE'}=~/\S/ ) {
1.194 albertel 5015: my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
1.278 albertel 5016: if ($closest > 0) {
5017: foreach my $testcode (@{$closest}) {
5018: my $checked='';
5019: if (!$i) { $checked=' checked="on" '; }
5020: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_closest_$i' $checked /> Use the similar CODE <b><tt>".$testcode."</tt></b> instead.</label><input type='hidden' name='scantron_CODE_closest_$i' value='$testcode' />");
5021: $r->print("\n<br />");
5022: $i++;
5023: }
1.194 albertel 5024: }
5025: }
1.273 albertel 5026: if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
5027: my $checked; if (!$i) { $checked=' checked="on" '; }
5028: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_unfound' $checked /> Use the CODE <b><tt>".$$scan_record{'scantron.CODE'}."</tt></b> that is was on the paper, ignoring the error.</label>");
5029: $r->print("\n<br />");
5030: }
1.194 albertel 5031:
1.188 albertel 5032: $r->print(<<ENDSCRIPT);
5033: <script type="text/javascript">
5034: function change_radio(field) {
1.190 albertel 5035: var slct=document.scantronupload.scantron_CODE_resolution;
1.188 albertel 5036: var i;
5037: for (i=0;i<slct.length;i++) {
5038: if (slct[i].value==field) { slct[i].checked=true; }
5039: }
5040: }
5041: </script>
5042: ENDSCRIPT
1.187 albertel 5043: my $href="/adm/pickcode?".
5044: "form=".&Apache::lonnet::escape("scantronupload").
1.257 albertel 5045: "&scantron_format=".&Apache::lonnet::escape($env{'form.scantron_format'}).
5046: "&scantron_CODElist=".&Apache::lonnet::escape($env{'form.scantron_CODElist'}).
1.187 albertel 5047: "&curCODE=".&Apache::lonnet::escape($$scan_record{'scantron.CODE'}).
1.257 albertel 5048: "&scantron_selectfile=".&Apache::lonnet::escape($env{'form.scantron_selectfile'});
1.272 albertel 5049: $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')\" />");
1.187 albertel 5050: $r->print("\n<br />");
1.272 albertel 5051: $r->print("<label><input type='radio' name='scantron_CODE_resolution' value='use_typed' /> Use </label><input type='text' size='8' name='scantron_CODE_newvalue' onfocus=\"javascript:change_radio('use_typed')\" onkeypress=\"javascript:change_radio('use_typed')\" /> as the CODE.");
1.187 albertel 5052: $r->print("\n<br /><br />");
1.157 albertel 5053: } elsif ($error eq 'doublebubble') {
5054: $r->print("<p>There have been multiple bubbles scanned for a some question(s)</p>\n");
5055: $r->print('<input type="hidden" name="scantron_questions" value="'.
5056: join(',',@{$arg}).'" />');
1.242 albertel 5057: $r->print($message);
1.157 albertel 5058: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5059: foreach my $question (@{$arg}) {
5060: my $selected=$$scan_record{"scantron.$question.answer"};
5061: &scantron_bubble_selector($r,$scan_config,$question,split('',$selected));
5062: }
5063: } elsif ($error eq 'missingbubble') {
5064: $r->print("<p>There have been <b>no</b> bubbles scanned for some question(s)</p>\n");
1.242 albertel 5065: $r->print($message);
1.157 albertel 5066: $r->print("<p>Please indicate which bubble should be used for grading</p>");
5067: $r->print("Some questions have no scanned bubbles\n");
5068: $r->print('<input type="hidden" name="scantron_questions" value="'.
5069: join(',',@{$arg}).'" />');
5070: foreach my $question (@{$arg}) {
5071: my $selected=$$scan_record{"scantron.$question.answer"};
5072: &scantron_bubble_selector($r,$scan_config,$question);
5073: }
5074: } else {
5075: $r->print("\n<ul>");
5076: }
5077: $r->print("\n</li></ul>");
5078:
5079: }
5080:
5081: sub scantron_bubble_selector {
5082: my ($r,$scan_config,$quest,@selected)=@_;
5083: my $max=$$scan_config{'Qlength'};
1.274 albertel 5084:
5085: my $scmode=$$scan_config{'Qon'};
5086: if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; }
5087:
1.157 albertel 5088: my @alphabet=('A'..'Z');
5089: $r->print("<table border='1'><tr><td rowspan='2'>$quest</td>");
5090: for (my $i=0;$i<$max+1;$i++) {
1.274 albertel 5091: $r->print("\n".'<td align="center">');
1.157 albertel 5092: if ($selected[0] eq $alphabet[$i]) { $r->print('X'); shift(@selected) }
5093: else { $r->print(' '); }
5094: $r->print('</td>');
5095: }
1.274 albertel 5096: $r->print('</tr><tr>');
1.157 albertel 5097: for (my $i=0;$i<$max;$i++) {
1.274 albertel 5098: $r->print("\n".
5099: '<td><label><input type="radio" name="scantron_correct_Q_'.
1.272 albertel 5100: $quest.'" value="'.$i.'" />'.$alphabet[$i]."</label></td>");
1.157 albertel 5101: }
1.272 albertel 5102: $r->print('<td><label><input type="radio" name="scantron_correct_Q_'.
5103: $quest.'" value="none" /> No bubble </label></td>');
1.157 albertel 5104: $r->print('</tr></table>');
5105: }
5106:
1.194 albertel 5107: sub num_matches {
5108: my ($orig,$code) = @_;
5109: my @code=split(//,$code);
5110: my @orig=split(//,$orig);
5111: my $same=0;
5112: for (my $i=0;$i<scalar(@code);$i++) {
5113: if ($code[$i] eq $orig[$i]) { $same++; }
5114: }
5115: return $same;
5116: }
5117:
5118: sub scantron_get_closely_matching_CODEs {
5119: my ($allcodes,$CODE)=@_;
5120: my @CODEs;
5121: foreach my $testcode (sort(keys(%{$allcodes}))) {
5122: push(@{$CODEs[&num_matches($CODE,$testcode)]},$testcode);
5123: }
5124:
5125: return ($#CODEs,$CODEs[-1]);
5126: }
5127:
5128: sub get_codes {
1.280 foxr 5129: my ($old_name, $cdom, $cnum) = @_;
5130: if (!$old_name) {
5131: $old_name=$env{'form.scantron_CODElist'};
5132: }
5133: if (!$cdom) {
5134: $cdom =$env{'course.'.$env{'request.course.id'}.'.domain'};
5135: }
5136: if (!$cnum) {
5137: $cnum =$env{'course.'.$env{'request.course.id'}.'.num'};
5138: }
1.278 albertel 5139: my %result=&Apache::lonnet::get('CODEs',[$old_name,"type\0$old_name"],
5140: $cdom,$cnum);
5141: my %allcodes;
5142: if ($result{"type\0$old_name"} eq 'number') {
5143: %allcodes=map {($_,1)} split(',',$result{$old_name});
5144: } else {
5145: %allcodes=map {(&Apache::lonprintout::num_to_letters($_),1)} split(',',$result{$old_name});
5146: }
1.194 albertel 5147: return %allcodes;
5148: }
5149:
1.157 albertel 5150: sub scantron_validate_CODE {
5151: my ($r,$currentphase) = @_;
1.257 albertel 5152: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.186 albertel 5153: if ($scantron_config{'CODElocation'} &&
5154: $scantron_config{'CODEstart'} &&
5155: $scantron_config{'CODElength'}) {
1.257 albertel 5156: if (!defined($env{'form.scantron_CODElist'})) {
1.186 albertel 5157: &FIXME_blow_up()
5158: }
5159: } else {
5160: return (0,$currentphase+1);
5161: }
5162:
5163: my %usedCODEs;
5164:
1.194 albertel 5165: my %allcodes=&get_codes();
1.186 albertel 5166:
5167: my ($scanlines,$scan_data)=&scantron_getfile();
5168: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5169: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.186 albertel 5170: if ($line=~/^[\s\cz]*$/) { next; }
5171: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5172: $scan_data);
5173: my $CODE=$$scan_record{'scantron.CODE'};
5174: my $error=0;
1.224 albertel 5175: if (!&Apache::lonnet::validCODE($CODE)) {
5176: &scantron_get_correction($r,$i,$scan_record,
5177: \%scantron_config,
5178: $line,'incorrectCODE',\%allcodes);
5179: return(1,$currentphase);
5180: }
1.221 albertel 5181: if (%allcodes && !exists($allcodes{$CODE})
5182: && !$$scan_record{'scantron.useCODE'}) {
1.186 albertel 5183: &scantron_get_correction($r,$i,$scan_record,
5184: \%scantron_config,
1.194 albertel 5185: $line,'incorrectCODE',\%allcodes);
5186: return(1,$currentphase);
1.186 albertel 5187: }
1.214 albertel 5188: if (exists($usedCODEs{$CODE})
1.257 albertel 5189: && $env{'form.scantron_CODEunique'} eq 'yes'
1.192 albertel 5190: && !$$scan_record{'scantron.CODE_ignore_dup'}) {
1.186 albertel 5191: &scantron_get_correction($r,$i,$scan_record,
5192: \%scantron_config,
1.194 albertel 5193: $line,'duplicateCODE',$usedCODEs{$CODE});
5194: return(1,$currentphase);
1.186 albertel 5195: }
1.194 albertel 5196: push (@{$usedCODEs{$CODE}},$$scan_record{'scantron.PaperID'});
1.186 albertel 5197: }
1.157 albertel 5198: return (0,$currentphase+1);
5199: }
5200:
5201: sub scantron_validate_doublebubble {
5202: my ($r,$currentphase) = @_;
5203: #get student info
5204: my $classlist=&Apache::loncoursedata::get_classlist();
5205: my %idmap=&username_to_idmap($classlist);
5206:
5207: #get scantron line setup
1.257 albertel 5208: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5209: my ($scanlines,$scan_data)=&scantron_getfile();
5210: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5211: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5212: if ($line=~/^[\s\cz]*$/) { next; }
5213: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5214: $scan_data);
5215: if (!defined($$scan_record{'scantron.doubleerror'})) { next; }
5216: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line,
5217: 'doublebubble',
5218: $$scan_record{'scantron.doubleerror'});
5219: return (1,$currentphase);
5220: }
5221: return (0,$currentphase+1);
5222: }
5223:
1.191 albertel 5224: sub scantron_get_maxbubble {
5225: my ($r)=@_;
1.257 albertel 5226: if (defined($env{'form.scantron_maxbubble'}) &&
5227: $env{'form.scantron_maxbubble'}) {
5228: return $env{'form.scantron_maxbubble'};
1.191 albertel 5229: }
5230: my $navmap=Apache::lonnavmaps::navmap->new();
5231: my (undef,undef,$sequence)=
1.257 albertel 5232: &Apache::lonnet::decode_symb($env{'form.selectpage'});
1.191 albertel 5233: my $map=$navmap->getResourceByUrl($sequence);
5234: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
5235: &Apache::lonnet::delenv('form.counter');
5236: foreach my $resource (@resources) {
1.234 albertel 5237: my $result=&Apache::lonnet::ssi($resource->src().'?symb='.&Apache::lonnet::escape($resource->symb()));
1.191 albertel 5238: }
5239: &Apache::lonnet::delenv('scantron\.');
1.257 albertel 5240: my $envfile=$env{'user.environment'};
1.191 albertel 5241: $envfile=~/\/([^\/]+)\.id$/;
5242: $envfile=$1;
5243: &Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
5244: $envfile);
1.257 albertel 5245: $env{'form.scantron_maxbubble'}=$env{'form.counter'}-1;
5246: return $env{'form.scantron_maxbubble'};
1.191 albertel 5247: }
5248:
1.157 albertel 5249: sub scantron_validate_missingbubbles {
5250: my ($r,$currentphase) = @_;
5251: #get student info
5252: my $classlist=&Apache::loncoursedata::get_classlist();
5253: my %idmap=&username_to_idmap($classlist);
5254:
5255: #get scantron line setup
1.257 albertel 5256: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5257: my ($scanlines,$scan_data)=&scantron_getfile();
1.191 albertel 5258: my $max_bubble=&scantron_get_maxbubble();
1.157 albertel 5259: if (!$max_bubble) { $max_bubble=2**31; }
5260: for (my $i=0;$i<=$scanlines->{'count'};$i++) {
1.200 albertel 5261: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5262: if ($line=~/^[\s\cz]*$/) { next; }
5263: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5264: $scan_data);
5265: if (!defined($$scan_record{'scantron.missingerror'})) { next; }
5266: my @to_correct;
5267: foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) {
5268: if ($missing > $max_bubble) { next; }
5269: push(@to_correct,$missing);
5270: }
5271: if (@to_correct) {
5272: &scantron_get_correction($r,$i,$scan_record,\%scantron_config,
5273: $line,'missingbubble',\@to_correct);
5274: return (1,$currentphase);
5275: }
5276:
5277: }
5278: return (0,$currentphase+1);
5279: }
5280:
1.82 albertel 5281: sub scantron_process_students {
1.75 albertel 5282: my ($r) = @_;
1.257 albertel 5283: my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
1.81 albertel 5284: my ($symb,$url)=&get_symb_and_url($r);
5285: if (!$symb) {return '';}
5286: my $default_form_data=&defaultFormData($symb,$url);
1.82 albertel 5287:
1.257 albertel 5288: my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
1.157 albertel 5289: my ($scanlines,$scan_data)=&scantron_getfile();
1.82 albertel 5290: my $classlist=&Apache::loncoursedata::get_classlist();
5291: my %idmap=&username_to_idmap($classlist);
1.132 bowersj2 5292: my $navmap=Apache::lonnavmaps::navmap->new();
1.83 albertel 5293: my $map=$navmap->getResourceByUrl($sequence);
5294: my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
1.140 albertel 5295: # $r->print("geto ".scalar(@resources)."<br />");
1.82 albertel 5296: my $result= <<SCANTRONFORM;
1.81 albertel 5297: <form method="post" enctype="multipart/form-data" action="/adm/grades" name="scantronupload">
5298: <input type="hidden" name="command" value="scantron_configphase" />
5299: $default_form_data
5300: SCANTRONFORM
1.82 albertel 5301: $r->print($result);
5302:
5303: my @delayqueue;
1.140 albertel 5304: my %completedstudents;
5305:
1.200 albertel 5306: my $count=&get_todo_count($scanlines,$scan_data);
1.157 albertel 5307: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Scantron Status',
1.200 albertel 5308: 'Scantron Progress',$count,
1.195 albertel 5309: 'inline',undef,'scantronupload');
1.140 albertel 5310: &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
5311: 'Processing first student');
5312: my $start=&Time::HiRes::time();
1.158 albertel 5313: my $i=-1;
1.200 albertel 5314: my ($uname,$udom,$started);
1.157 albertel 5315: while ($i<$scanlines->{'count'}) {
5316: ($uname,$udom)=('','');
5317: $i++;
1.200 albertel 5318: my $line=&scantron_get_line($scanlines,$scan_data,$i);
1.157 albertel 5319: if ($line=~/^[\s\cz]*$/) { next; }
1.200 albertel 5320: if ($started) {
5321: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
5322: 'last student');
5323: }
5324: $started=1;
1.157 albertel 5325: my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config,
5326: $scan_data);
5327: unless ($uname=&scantron_find_student($scan_record,$scan_data,
5328: \%idmap,$i)) {
5329: &scantron_add_delay(\@delayqueue,$line,
5330: 'Unable to find a student that matches',1);
5331: next;
5332: }
5333: if (exists $completedstudents{$uname}) {
5334: &scantron_add_delay(\@delayqueue,$line,
5335: 'Student '.$uname.' has multiple sheets',2);
5336: next;
5337: }
5338: ($uname,$udom)=split(/:/,$uname);
5339: &Apache::lonnet::delenv('form.counter');
5340: &Apache::lonnet::appenv(%$scan_record);
1.161 albertel 5341:
5342: my $i=0;
1.83 albertel 5343: foreach my $resource (@resources) {
1.85 albertel 5344: $i++;
1.193 albertel 5345: my %form=('submitted' =>'scantron',
5346: 'grade_target' =>'grade',
5347: 'grade_username'=>$uname,
5348: 'grade_domain' =>$udom,
1.257 albertel 5349: 'grade_courseid'=>$env{'request.course.id'},
1.193 albertel 5350: 'grade_symb' =>$resource->symb());
5351: if (exists($scan_record->{'scantron.CODE'}) &&
5352: $scan_record->{'scantron.CODE'}) {
5353: $form{'CODE'}=$scan_record->{'scantron.CODE'};
1.224 albertel 5354: } else {
5355: $form{'CODE'}='';
1.193 albertel 5356: }
5357: my $result=&Apache::lonnet::ssi($resource->src(),%form);
1.227 albertel 5358: if ($result ne '') {
5359: &Apache::lonnet::logthis("scantron grading error -> $result");
1.257 albertel 5360: &Apache::lonnet::logthis("scantron grading error info name $uname domain $udom course $env{'request.course.id'} url ".$resource->src());
1.227 albertel 5361: }
1.213 albertel 5362: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.83 albertel 5363: }
1.140 albertel 5364: $completedstudents{$uname}={'line'=>$line};
1.213 albertel 5365: if (&Apache::loncommon::connection_aborted($r)) { last; }
1.140 albertel 5366: } continue {
1.85 albertel 5367: &Apache::lonnet::delenv('form.counter');
1.83 albertel 5368: &Apache::lonnet::delenv('scantron\.');
1.82 albertel 5369: }
1.140 albertel 5370: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
1.172 albertel 5371: # my $lasttime = &Time::HiRes::time()-$start;
5372: # $r->print("<p>took $lasttime</p>");
1.140 albertel 5373:
1.200 albertel 5374: $r->print("</form>");
1.157 albertel 5375: $r->print(&show_grading_menu_form($symb,$url));
5376: return '';
1.75 albertel 5377: }
1.157 albertel 5378:
5379: sub scantron_upload_scantron_data {
5380: my ($r)=@_;
1.257 albertel 5381: $r->print(&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'}));
1.157 albertel 5382: my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid',
1.181 albertel 5383: 'domainid',
5384: 'coursename');
1.257 albertel 5385: my $domsel=&Apache::loncommon::select_dom_form($env{'request.role.domain'},
1.157 albertel 5386: 'domainid');
1.173 albertel 5387: my $default_form_data=&defaultFormData(&get_symb_and_url($r,1));
1.157 albertel 5388: $r->print(<<UPLOAD);
5389: <script type="text/javascript" language="javascript">
5390: function checkUpload(formname) {
5391: if (formname.upfile.value == "") {
5392: alert("Please use the browse button to select a file from your local directory.");
5393: return false;
5394: }
5395: formname.submit();
5396: }
5397: </script>
5398:
5399: <form enctype='multipart/form-data' action='/adm/grades' name='rules' method='post'>
1.162 albertel 5400: $default_form_data
1.181 albertel 5401: <table>
5402: <tr><td>$select_link </td></tr>
5403: <tr><td>Course ID: </td><td><input name='courseid' type='text' /> </td></tr>
5404: <tr><td>Course Name: </td><td><input name='coursename' type='text' /></td></tr>
5405: <tr><td>Domain: </td><td>$domsel </td></tr>
5406: <tr><td>File to upload:</td><td><input type="file" name="upfile" size="50" /></td></tr>
5407: </table>
1.157 albertel 5408: <input name='command' value='scantronupload_save' type='hidden' />
5409: <input type="button" onClick="javascript:checkUpload(this.form);" value="Upload Scantron Data" />
5410: </form>
5411: UPLOAD
5412: return '';
5413: }
5414:
5415: sub scantron_upload_scantron_data_save {
5416: my($r)=@_;
1.182 albertel 5417: my ($symb,$url)=&get_symb_and_url($r,1);
5418: my $doanotherupload=
5419: '<br /><form action="/adm/grades" method="post">'."\n".
5420: '<input type="hidden" name="command" value="scantronupload" />'."\n".
5421: '<input type="submit" name="submit" value="Do Another Upload" />'."\n".
5422: '</form>'."\n";
1.257 albertel 5423: if (!&Apache::lonnet::allowed('usc',$env{'form.domainid'}) &&
1.162 albertel 5424: !&Apache::lonnet::allowed('usc',
1.257 albertel 5425: $env{'form.domainid'}.'_'.$env{'form.courseid'})) {
1.162 albertel 5426: $r->print("You are not allowed to upload Scantron data to the requested course.<br />");
1.182 albertel 5427: if ($symb) {
5428: $r->print(&show_grading_menu_form($symb,$url));
5429: } else {
5430: $r->print($doanotherupload);
5431: }
1.162 albertel 5432: return '';
5433: }
1.257 albertel 5434: my %coursedata=&Apache::lonnet::coursedescription($env{'form.domainid'}.'_'.$env{'form.courseid'});
1.211 ng 5435: $r->print("Doing upload to ".$coursedata{'description'}." <br />");
1.257 albertel 5436: my $fname=$env{'form.upfile.filename'};
1.157 albertel 5437: #FIXME
5438: #copied from lonnet::userfileupload()
5439: #make that function able to target a specified course
5440: # Replace Windows backslashes by forward slashes
5441: $fname=~s/\\/\//g;
5442: # Get rid of everything but the actual filename
5443: $fname=~s/^.*\/([^\/]+)$/$1/;
5444: # Replace spaces by underscores
5445: $fname=~s/\s+/\_/g;
5446: # Replace all other weird characters by nothing
5447: $fname=~s/[^\w\.\-]//g;
5448: # See if there is anything left
5449: unless ($fname) { return 'error: no uploaded file'; }
1.209 ng 5450: my $uploadedfile=$fname;
1.157 albertel 5451: $fname='scantron_orig_'.$fname;
1.257 albertel 5452: if (length($env{'form.upfile'}) < 2) {
5453: $r->print("<font color='red'>Error:</font> The file you attempted to upload, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>, contained no information. Please check that you entered the correct filename.");
1.183 albertel 5454: } else {
1.275 albertel 5455: my $result=&Apache::lonnet::finishuserfileupload($env{'form.courseid'},$env{'form.domainid'},'upfile',$fname);
1.210 albertel 5456: if ($result =~ m|^/uploaded/|) {
1.257 albertel 5457: $r->print("<font color='green'>Success:</font> Successfully uploaded ".(length($env{'form.upfile'})-1)." bytes of data into location <tt>".$result."</tt>");
1.210 albertel 5458: } else {
1.257 albertel 5459: $r->print("<font color='red'>Error:</font> An error (".$result.") occurred when attempting to upload the file, <tt>".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"')."</tt>");
1.183 albertel 5460: }
5461: }
1.174 albertel 5462: if ($symb) {
1.209 ng 5463: $r->print(&scantron_selectphase($r,$uploadedfile));
1.174 albertel 5464: } else {
1.182 albertel 5465: $r->print($doanotherupload);
1.174 albertel 5466: }
1.157 albertel 5467: return '';
5468: }
5469:
1.202 albertel 5470: sub valid_file {
5471: my ($requested_file)=@_;
5472: foreach my $filename (sort(&scantron_filenames())) {
5473: &Apache::lonnet::logthis("$requested_file $filename");
5474: if ($requested_file eq $filename) { return 1; }
5475: }
5476: return 0;
5477: }
5478:
5479: sub scantron_download_scantron_data {
5480: my ($r)=@_;
5481: my $default_form_data=&defaultFormData(&get_symb_and_url($r,1));
1.257 albertel 5482: my $cname=$env{'course.'.$env{'request.course.id'}.'.num'};
5483: my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
5484: my $file=$env{'form.scantron_selectfile'};
1.202 albertel 5485: if (! &valid_file($file)) {
5486: $r->print(<<ERROR);
5487: <p>
5488: The requested file name was invalid.
5489: </p>
5490: ERROR
5491: $r->print(&show_grading_menu_form(&get_symb_and_url($r,1)));
5492: return;
5493: }
5494: my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file;
5495: my $corrected='/uploaded/'.$cdom.'/'.$cname.'/scantron_corrected_'.$file;
5496: my $skipped='/uploaded/'.$cdom.'/'.$cname.'/scantron_skipped_'.$file;
5497: &Apache::lonnet::allowuploaded('/adm/grades',$orig);
5498: &Apache::lonnet::allowuploaded('/adm/grades',$corrected);
5499: &Apache::lonnet::allowuploaded('/adm/grades',$skipped);
5500: $r->print(<<DOWNLOAD);
5501: <p>
5502: <a href="$orig">Original</a> file as uploaded by the scantron office.
5503: </p>
5504: <p>
5505: <a href="$corrected">Corrections</a>, a file of corrected records that were used in grading.
5506: </p>
5507: <p>
5508: <a href="$skipped">Skipped</a>, a file of records that were skipped.
5509: </p>
5510: DOWNLOAD
5511: $r->print(&show_grading_menu_form(&get_symb_and_url($r,1)));
5512: return '';
5513: }
1.157 albertel 5514:
1.75 albertel 5515: #-------- end of section for handling grading scantron forms -------
5516: #
5517: #-------------------------------------------------------------------
5518:
1.72 ng 5519: #-------------------------- Menu interface -------------------------
5520: #
5521: #--- Show a Grading Menu button - Calls the next routine ---
5522: sub show_grading_menu_form {
5523: my ($symb,$url)=@_;
1.125 ng 5524: my $result.='<br /><form action="/adm/grades" method="post">'."\n".
1.72 ng 5525: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
5526: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
1.257 albertel 5527: '<input type="hidden" name="saveState" value="'.$env{'form.saveState'}.'" />'."\n".
1.72 ng 5528: '<input type="hidden" name="command" value="gradingmenu" />'."\n".
5529: '<input type="submit" name="submit" value="Grading Menu" />'."\n".
5530: '</form>'."\n";
5531: return $result;
5532: }
5533:
1.77 ng 5534: # -- Retrieve choices for grading form
5535: sub savedState {
5536: my %savedState = ();
1.257 albertel 5537: if ($env{'form.saveState'}) {
5538: foreach (split(/:/,$env{'form.saveState'})) {
1.77 ng 5539: my ($key,$value) = split(/=/,$_,2);
5540: $savedState{$key} = $value;
5541: }
5542: }
5543: return \%savedState;
5544: }
1.76 ng 5545:
1.72 ng 5546: #--- Displays the main menu page -------
5547: sub gradingmenu {
5548: my ($request) = @_;
5549: my ($symb,$url)=&get_symb_and_url($request);
5550: if (!$symb) {return '';}
1.76 ng 5551: my $probTitle = &Apache::lonnet::gettitle($symb);
1.72 ng 5552:
5553: $request->print(<<GRADINGMENUJS);
5554: <script type="text/javascript" language="javascript">
1.116 ng 5555: function checkChoice(formname,val,cmdx) {
5556: if (val <= 2) {
5557: var cmd = radioSelection(formname.radioChoice);
1.118 ng 5558: var cmdsave = cmd;
1.116 ng 5559: } else {
5560: cmd = cmdx;
1.118 ng 5561: cmdsave = 'submission';
1.116 ng 5562: }
5563: formname.command.value = cmd;
1.118 ng 5564: formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+
1.145 albertel 5565: ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status);
1.116 ng 5566: if (val < 5) formname.submit();
5567: if (val == 5) {
1.72 ng 5568: if (!checkReceiptNo(formname,'notOK')) { return false;}
5569: formname.submit();
5570: }
1.238 albertel 5571: if (val < 7) formname.submit();
1.72 ng 5572: }
5573:
5574: function checkReceiptNo(formname,nospace) {
5575: var receiptNo = formname.receipt.value;
5576: var checkOpt = false;
5577: if (nospace == "OK" && isNaN(receiptNo)) {checkOpt = true;}
5578: if (nospace == "notOK" && (isNaN(receiptNo) || receiptNo == "")) {checkOpt = true;}
5579: if (checkOpt) {
5580: alert("Please enter a receipt number given by a student in the receipt box.");
5581: formname.receipt.value = "";
5582: formname.receipt.focus();
5583: return false;
5584: }
5585: return true;
5586: }
5587: </script>
5588: GRADINGMENUJS
1.118 ng 5589: &commonJSfunctions($request);
5590: my $result='<h3> <font color="#339933">Manual Grading/View Submission</font></h3>';
1.122 ng 5591: my ($table,undef,$hdgrade) = &showResourceInfo($url,$probTitle);
1.118 ng 5592: $result.=$table;
1.76 ng 5593: my (undef,$sections) = &getclasslist('all','0');
1.77 ng 5594: my $savedState = &savedState();
1.118 ng 5595: my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'});
1.77 ng 5596: my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'});
1.118 ng 5597: my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'});
1.77 ng 5598: my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'});
1.72 ng 5599:
5600: $result.='<form action="/adm/grades" method="post" name="gradingMenu">'."\n".
5601: '<input type="hidden" name="symb" value="'.$symb.'" />'."\n".
5602: '<input type="hidden" name="url" value="'.$url.'" />'."\n".
5603: '<input type="hidden" name="handgrade" value="'.$hdgrade.'" />'."\n".
5604: '<input type="hidden" name="probTitle" value="'.$probTitle.'" />'."\n".
1.116 ng 5605: '<input type="hidden" name="command" value="" />'."\n".
1.77 ng 5606: '<input type="hidden" name="saveState" value="" />'."\n".
1.124 ng 5607: '<input type="hidden" name="gradingMenu" value="1" />'."\n".
1.72 ng 5608: '<input type="hidden" name="showgrading" value="yes" />'."\n";
5609:
1.116 ng 5610: $result.='<table width="100%" border=0><tr><td bgcolor=#777777>'."\n".
5611: '<table width=100% border=0><tr bgcolor="#e6ffff"><td colspan="2">'."\n".
1.72 ng 5612: ' <b>Select a Grading/Viewing Option</b></td></tr>'."\n".
1.116 ng 5613: '<tr bgcolor="#ffffe6" valign="top"><td>'."\n";
5614:
5615: $result.='<table width="100%" border=0>';
5616: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'."\n".
1.167 sakharuk 5617: ' '.&mt('Select Section').': <select name="section">'."\n";
1.116 ng 5618: if (ref($sections)) {
1.155 albertel 5619: foreach (sort (@$sections)) {
5620: $result.='<option value="'.$_.'" '.
5621: ($saveSec eq $_ ? 'selected="on"':'').'>'.$_.'</option>'."\n";
5622: }
1.116 ng 5623: }
1.238 albertel 5624: $result.= '<option value="all" '.($saveSec eq 'all' ? 'selected="on"' : ''). '>all</option></select> ';
1.116 ng 5625:
1.167 sakharuk 5626: $result.=&mt('Student Status').':</b>'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef);
1.72 ng 5627:
1.116 ng 5628: $result.='</td></tr>';
5629:
1.288 albertel 5630: $result.='<tr bgcolor="#ffffe6"valign="top"><td><label>'.
1.118 ng 5631: '<input type="radio" name="radioChoice" value="submission" '.
1.167 sakharuk 5632: ($saveCmd eq 'submission' ? 'checked' : '').'> '.'<b>'.&mt('Current Resource').':</b> '.&mt('For one or more students').
1.288 albertel 5633: '</label> <select name="submitonly">'.
1.145 albertel 5634: '<option value="yes" '.
1.301 albertel 5635: ($saveSub eq 'yes' ? 'selected="on"' : '').'>'.&mt('with submissions').'</option>'.
5636: '<option value="queued" '.
5637: ($saveSub eq 'queued' ? 'selected="on"' : '').'>'.&mt('in grading queue').'</option>'.
1.145 albertel 5638: '<option value="graded" '.
1.301 albertel 5639: ($saveSub eq 'graded' ? 'selected="on"' : '').'>'.&mt('with ungraded submissions').'</option>'.
1.156 albertel 5640: '<option value="incorrect" '.
1.301 albertel 5641: ($saveSub eq 'incorrect' ? 'selected="on"' : '').'>'.&mt('with incorrect submissions').'</option>'.
1.145 albertel 5642: '<option value="all" '.
1.301 albertel 5643: ($saveSub eq 'all' ? 'selected="on"' : '').'>'.&mt('with any status').'</option></select></td></tr>'."\n";
1.72 ng 5644:
1.116 ng 5645: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.288 albertel 5646: '<label><input type="radio" name="radioChoice" value="viewgrades" '.
1.76 ng 5647: ($saveCmd eq 'viewgrades' ? 'checked' : '').'> '.
1.288 albertel 5648: '<b>Current Resource:</b> For all students in selected section or course</label></td></tr>'."\n";
1.72 ng 5649:
1.118 ng 5650: $result.='<tr bgcolor="#ffffe6" valign="top"><td>'.
1.288 albertel 5651: '<label><input type="radio" name="radioChoice" value="pickStudentPage" '.
1.118 ng 5652: ($saveCmd eq 'pickStudentPage' ? 'checked' : '').'> '.
1.288 albertel 5653: 'The <b>complete</b> set/page/sequence: For one student</label></td></tr>'."\n";
1.46 ng 5654:
1.116 ng 5655: $result.='<tr bgcolor="#ffffe6"><td><br />'.
1.126 ng 5656: '<input type="button" onClick="javascript:checkChoice(this.form,\'2\');" value="Next->" />'.
1.116 ng 5657: '</td></tr></table>'."\n";
5658:
5659: $result.='</td><td valign="top">';
5660:
5661: $result.='<table width="100%" border=0>';
5662: $result.='<tr bgcolor="#ffffe6"><td>'.
1.184 www 5663: '<input type="button" onClick="javascript:checkChoice(this.form,\'3\',\'csvform\');" value="'.&mt('Upload').'" />'.
5664: ' '.&mt('scores from file').' </td></tr>'."\n";
1.72 ng 5665:
1.75 albertel 5666: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
1.116 ng 5667: '<input type="button" onClick="javascript:checkChoice(this.form,\'4\',\'scantron_selectphase\');'.
1.184 www 5668: '" value="'.&mt('Grade').'" /> scantron forms</td></tr>'."\n";
1.75 albertel 5669:
1.257 albertel 5670: if ((&Apache::lonnet::allowed('mgr',$env{'request.course.id'})) && ($symb)) {
1.72 ng 5671: $result.='<tr bgcolor="#ffffe6"valign="top"><td>'.
1.184 www 5672: '<input type="button" onClick="javascript:checkChoice(this.form,\'5\',\'verify\');" value="'.&mt('Verify').'" />'.
5673: ' '.&mt('receipt').': '.
1.257 albertel 5674: &Apache::lonnet::recprefix($env{'request.course.id'}).
1.72 ng 5675: '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')">'.
5676: '</td></tr>'."\n";
5677: }
1.238 albertel 5678: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
5679: '<input type="button" onClick="javascript:this.form.action=\'/adm/helper/resettimes.helper\';this.form.submit();'.
5680: '" value="'.&mt('Manage').'" /> access times.</td></tr>'."\n";
1.279 albertel 5681: $result.='<tr bgcolor="#ffffe6"valign="top"><td colspan="2">'.
5682: '<input type="button" onClick="javascript:this.form.command.value=\'codelist\';this.form.action=\'/adm/pickcode\';this.form.submit();'.
5683: '" value="'.&mt('View').'" /> saved CODEs.</td></tr>'."\n";
1.44 ng 5684:
1.116 ng 5685: $result.='</form></td></tr></table>'."\n".
1.72 ng 5686: '</td></tr></table>'."\n".
5687: '</td></tr></table>'."\n";
1.44 ng 5688: return $result;
1.2 albertel 5689: }
5690:
1.285 albertel 5691: sub reset_perm {
5692: undef(%perm);
5693: }
5694:
5695: sub init_perm {
5696: &reset_perm();
1.300 albertel 5697: foreach my $test_perm ('vgr','mgr','opa') {
5698:
5699: my $scope = $env{'request.course.id'};
5700: if (!($perm{$test_perm}=&Apache::lonnet::allowed($test_perm,$scope))) {
5701:
5702: $scope .= '/'.$env{'request.course.sec'};
5703: if ( $perm{$test_perm}=
5704: &Apache::lonnet::allowed($test_perm,$scope)) {
5705: $perm{$test_perm.'_section'}=$env{'request.course.sec'};
5706: } else {
5707: delete($perm{$test_perm});
5708: }
1.285 albertel 5709: }
5710: }
5711: }
5712:
1.1 albertel 5713: sub handler {
1.41 ng 5714: my $request=$_[0];
1.102 albertel 5715:
1.285 albertel 5716: &reset_perm();
1.257 albertel 5717: if ($env{'browser.mathml'}) {
1.141 www 5718: &Apache::loncommon::content_type($request,'text/xml');
1.41 ng 5719: } else {
1.141 www 5720: &Apache::loncommon::content_type($request,'text/html');
1.41 ng 5721: }
5722: $request->send_http_header;
1.44 ng 5723: return '' if $request->header_only;
1.41 ng 5724: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'});
1.257 albertel 5725: my $url=$env{'form.url'};
5726: my $symb=$env{'form.symb'};
1.160 albertel 5727: my @commands=&Apache::loncommon::get_env_multiple('form.command');
5728: my $command=$commands[0];
5729: if ($#commands > 0) {
5730: &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
5731: }
1.41 ng 5732: if (!$url) {
5733: my ($temp1,$temp2);
1.257 albertel 5734: ($temp1,$temp2,$env{'form.url'})=&Apache::lonnet::decode_symb($symb);
5735: $url = $env{'form.url'};
1.41 ng 5736: }
5737: &send_header($request);
1.157 albertel 5738: if ($url eq '' && $symb eq '' && $command eq '') {
1.257 albertel 5739: if ($env{'user.adv'}) {
5740: if (($env{'form.codeone'}) && ($env{'form.codetwo'}) &&
5741: ($env{'form.codethree'})) {
5742: my $token=$env{'form.codeone'}.'*'.$env{'form.codetwo'}.'*'.
5743: $env{'form.codethree'};
1.41 ng 5744: my ($tsymb,$tuname,$tudom,$tcrsid)=
5745: &Apache::lonnet::checkin($token);
5746: if ($tsymb) {
1.137 albertel 5747: my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
1.41 ng 5748: if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
1.99 albertel 5749: $request->print(&Apache::lonnet::ssi_body('/res/'.$url,
5750: ('grade_username' => $tuname,
5751: 'grade_domain' => $tudom,
5752: 'grade_courseid' => $tcrsid,
5753: 'grade_symb' => $tsymb)));
1.41 ng 5754: } else {
1.45 ng 5755: $request->print('<h3>Not authorized: '.$token.'</h3>');
1.99 albertel 5756: }
1.41 ng 5757: } else {
1.45 ng 5758: $request->print('<h3>Not a valid DocID: '.$token.'</h3>');
1.41 ng 5759: }
1.14 www 5760: } else {
1.41 ng 5761: $request->print(&Apache::lonxml::tokeninputfield());
5762: }
5763: }
5764: } else {
1.285 albertel 5765: &init_perm();
1.104 albertel 5766: if ($command eq 'submission' && $perm{'vgr'}) {
1.257 albertel 5767: ($env{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0));
1.103 albertel 5768: } elsif ($command eq 'pickStudentPage' && $perm{'vgr'}) {
1.68 ng 5769: &pickStudentPage($request);
1.103 albertel 5770: } elsif ($command eq 'displayPage' && $perm{'vgr'}) {
1.68 ng 5771: &displayPage($request);
1.104 albertel 5772: } elsif ($command eq 'gradeByPage' && $perm{'mgr'}) {
1.71 ng 5773: &updateGradeByPage($request);
1.104 albertel 5774: } elsif ($command eq 'processGroup' && $perm{'vgr'}) {
1.41 ng 5775: &processGroup($request);
1.104 albertel 5776: } elsif ($command eq 'gradingmenu' && $perm{'vgr'}) {
1.41 ng 5777: $request->print(&gradingmenu($request));
1.104 albertel 5778: } elsif ($command eq 'viewgrades' && $perm{'vgr'}) {
1.41 ng 5779: $request->print(&viewgrades($request));
1.104 albertel 5780: } elsif ($command eq 'handgrade' && $perm{'mgr'}) {
1.41 ng 5781: $request->print(&processHandGrade($request));
1.106 albertel 5782: } elsif ($command eq 'editgrades' && $perm{'mgr'}) {
1.41 ng 5783: $request->print(&editgrades($request));
1.106 albertel 5784: } elsif ($command eq 'verify' && $perm{'vgr'}) {
1.41 ng 5785: $request->print(&verifyreceipt($request));
1.106 albertel 5786: } elsif ($command eq 'csvform' && $perm{'mgr'}) {
1.72 ng 5787: $request->print(&upcsvScores_form($request));
1.106 albertel 5788: } elsif ($command eq 'csvupload' && $perm{'mgr'}) {
1.41 ng 5789: $request->print(&csvupload($request));
1.106 albertel 5790: } elsif ($command eq 'csvuploadmap' && $perm{'mgr'} ) {
1.41 ng 5791: $request->print(&csvuploadmap($request));
1.246 albertel 5792: } elsif ($command eq 'csvuploadoptions' && $perm{'mgr'}) {
1.257 albertel 5793: if ($env{'form.associate'} ne 'Reverse Association') {
1.246 albertel 5794: $request->print(&csvuploadoptions($request));
1.41 ng 5795: } else {
1.257 albertel 5796: if ( $env{'form.upfile_associate'} ne 'reverse' ) {
5797: $env{'form.upfile_associate'} = 'reverse';
1.41 ng 5798: } else {
1.257 albertel 5799: $env{'form.upfile_associate'} = 'forward';
1.41 ng 5800: }
5801: $request->print(&csvuploadmap($request));
5802: }
1.246 albertel 5803: } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) {
5804: $request->print(&csvuploadassign($request));
1.106 albertel 5805: } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) {
1.75 albertel 5806: $request->print(&scantron_selectphase($request));
1.203 albertel 5807: } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) {
5808: $request->print(&scantron_do_warning($request));
1.142 albertel 5809: } elsif ($command eq 'scantron_validate' && $perm{'mgr'}) {
5810: $request->print(&scantron_validate_file($request));
1.106 albertel 5811: } elsif ($command eq 'scantron_process' && $perm{'mgr'}) {
1.82 albertel 5812: $request->print(&scantron_process_students($request));
1.157 albertel 5813: } elsif ($command eq 'scantronupload' &&
1.257 albertel 5814: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
5815: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.162 albertel 5816: $request->print(&scantron_upload_scantron_data($request));
1.157 albertel 5817: } elsif ($command eq 'scantronupload_save' &&
1.257 albertel 5818: (&Apache::lonnet::allowed('usc',$env{'request.role.domain'})||
5819: &Apache::lonnet::allowed('usc',$env{'request.course.id'}))) {
1.157 albertel 5820: $request->print(&scantron_upload_scantron_data_save($request));
1.202 albertel 5821: } elsif ($command eq 'scantron_download' &&
1.257 albertel 5822: &Apache::lonnet::allowed('usc',$env{'request.course.id'})) {
1.162 albertel 5823: $request->print(&scantron_download_scantron_data($request));
1.106 albertel 5824: } elsif ($command) {
1.157 albertel 5825: $request->print("Access Denied ($command)");
1.26 albertel 5826: }
1.2 albertel 5827: }
1.41 ng 5828: &send_footer($request);
1.44 ng 5829: return '';
5830: }
5831:
5832: sub send_header {
5833: my ($request)= @_;
5834: $request->print(&Apache::lontexconvert::header());
5835: # $request->print("
5836: #<script>
5837: #remotewindow=open('','homeworkremote');
5838: #remotewindow.close();
5839: #</script>");
1.47 www 5840: $request->print(&Apache::loncommon::bodytag('Grading'));
1.157 albertel 5841: $request->rflush();
1.44 ng 5842: }
5843:
5844: sub send_footer {
5845: my ($request)= @_;
1.212 albertel 5846: $request->print('</body></html>');
1.1 albertel 5847: }
5848:
5849: 1;
5850:
1.13 albertel 5851: __END__;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>