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