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